mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	chore(react): solve most type errors
This commit is contained in:
		| @@ -18,7 +18,7 @@ interface NoteListProps<T extends object> { | |||||||
|     /** if set to `true` then only collection-type views are displayed such as geo-map and the calendar. The original book types grid and list will be ignored. */ |     /** if set to `true` then only collection-type views are displayed such as geo-map and the calendar. The original book types grid and list will be ignored. */ | ||||||
|     displayOnlyCollections?: boolean; |     displayOnlyCollections?: boolean; | ||||||
|     highlightedTokens?: string[] | null; |     highlightedTokens?: string[] | null; | ||||||
|     viewStorage: ViewModeStorage<T>; |     viewStorage?: ViewModeStorage<T>; | ||||||
| } | } | ||||||
|  |  | ||||||
| export default function NoteList<T extends object>({ note: providedNote, highlightedTokens, displayOnlyCollections }: NoteListProps<T>) { | export default function NoteList<T extends object>({ note: providedNote, highlightedTokens, displayOnlyCollections }: NoteListProps<T>) { | ||||||
|   | |||||||
| @@ -31,7 +31,7 @@ export default function Card({ | |||||||
|     index: number, |     index: number, | ||||||
|     isDragging: boolean |     isDragging: boolean | ||||||
| }) { | }) { | ||||||
|     const { branchIdToEdit, setBranchIdToEdit, setDraggedCard } = useContext(BoardViewContext); |     const { branchIdToEdit, setBranchIdToEdit, setDraggedCard } = useContext(BoardViewContext)!; | ||||||
|     const isEditing = branch.branchId === branchIdToEdit; |     const isEditing = branch.branchId === branchIdToEdit; | ||||||
|     const colorClass = note.getColorClass() || ''; |     const colorClass = note.getColorClass() || ''; | ||||||
|     const editorRef = useRef<HTMLInputElement>(null); |     const editorRef = useRef<HTMLInputElement>(null); | ||||||
| @@ -78,7 +78,7 @@ export default function Card({ | |||||||
|     return ( |     return ( | ||||||
|         <div |         <div | ||||||
|             className={`board-note ${colorClass} ${isDragging ? 'dragging' : ''} ${isEditing ? "editing" : ""} ${isArchived ? "archived" : ""}`} |             className={`board-note ${colorClass} ${isDragging ? 'dragging' : ''} ${isEditing ? "editing" : ""} ${isArchived ? "archived" : ""}`} | ||||||
|             draggable="true" |             draggable | ||||||
|             onDragStart={handleDragStart} |             onDragStart={handleDragStart} | ||||||
|             onDragEnd={handleDragEnd} |             onDragEnd={handleDragEnd} | ||||||
|             onContextMenu={handleContextMenu} |             onContextMenu={handleContextMenu} | ||||||
|   | |||||||
| @@ -17,7 +17,6 @@ interface DragContext { | |||||||
|     column: string; |     column: string; | ||||||
|     columnIndex: number, |     columnIndex: number, | ||||||
|     columnItems?: { note: FNote, branch: FBranch }[]; |     columnItems?: { note: FNote, branch: FBranch }[]; | ||||||
|     isEditing: boolean; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| export default function Column({ | export default function Column({ | ||||||
| @@ -36,7 +35,7 @@ export default function Column({ | |||||||
|     isAnyColumnDragging?: boolean |     isAnyColumnDragging?: boolean | ||||||
| } & DragContext) { | } & DragContext) { | ||||||
|     const [ isVisible, setVisible ] = useState(true); |     const [ isVisible, setVisible ] = useState(true); | ||||||
|     const { columnNameToEdit, setColumnNameToEdit, dropTarget, draggedCard, dropPosition } = useContext(BoardViewContext); |     const { columnNameToEdit, setColumnNameToEdit, dropTarget, draggedCard, dropPosition } = useContext(BoardViewContext)!; | ||||||
|     const isEditing = (columnNameToEdit === column); |     const isEditing = (columnNameToEdit === column); | ||||||
|     const editorRef = useRef<HTMLInputElement>(null); |     const editorRef = useRef<HTMLInputElement>(null); | ||||||
|     const { handleColumnDragStart, handleColumnDragEnd, handleDragOver, handleDragLeave, handleDrop } = useDragging({ |     const { handleColumnDragStart, handleColumnDragEnd, handleDragOver, handleDragLeave, handleDrop } = useDragging({ | ||||||
| @@ -90,7 +89,7 @@ export default function Column({ | |||||||
|         > |         > | ||||||
|             <h3 |             <h3 | ||||||
|                 className={`${isEditing ? "editing" : ""}`} |                 className={`${isEditing ? "editing" : ""}`} | ||||||
|                 draggable="true" |                 draggable | ||||||
|                 onDragStart={handleColumnDragStart} |                 onDragStart={handleColumnDragStart} | ||||||
|                 onDragEnd={handleColumnDragEnd} |                 onDragEnd={handleColumnDragEnd} | ||||||
|                 onContextMenu={handleContextMenu} |                 onContextMenu={handleContextMenu} | ||||||
| @@ -170,8 +169,8 @@ function AddNewItem({ column, api }: { column: string, api: BoardApi }) { | |||||||
|     ); |     ); | ||||||
| } | } | ||||||
|  |  | ||||||
| function useDragging({ column, columnIndex, columnItems, isEditing }: DragContext) { | function useDragging({ column, columnIndex, columnItems, isEditing }: DragContext & { isEditing: boolean }) { | ||||||
|     const { api, parentNote, draggedColumn, setDraggedColumn, setDropTarget, setDropPosition, dropPosition } = useContext(BoardViewContext); |     const { api, parentNote, draggedColumn, setDraggedColumn, setDropTarget, setDropPosition, dropPosition } = useContext(BoardViewContext)!; | ||||||
|     /** Needed to track if current column is dragged in real-time, since {@link draggedColumn} is populated one render cycle later.  */ |     /** Needed to track if current column is dragged in real-time, since {@link draggedColumn} is populated one render cycle later.  */ | ||||||
|     const isDraggingRef = useRef(false); |     const isDraggingRef = useRef(false); | ||||||
|  |  | ||||||
| @@ -192,13 +191,13 @@ function useDragging({ column, columnIndex, columnItems, isEditing }: DragContex | |||||||
|  |  | ||||||
|     const handleDragOver = useCallback((e: DragEvent) => { |     const handleDragOver = useCallback((e: DragEvent) => { | ||||||
|         if (isEditing || draggedColumn || isDraggingRef.current) return; // Don't handle card drops when dragging columns |         if (isEditing || draggedColumn || isDraggingRef.current) return; // Don't handle card drops when dragging columns | ||||||
|         if (!e.dataTransfer?.types.includes(CARD_CLIPBOARD_TYPE) && !e.dataTransfer.types.includes(TREE_CLIPBOARD_TYPE)) return; |         if (!e.dataTransfer?.types.includes(CARD_CLIPBOARD_TYPE) && !e.dataTransfer?.types.includes(TREE_CLIPBOARD_TYPE)) return; | ||||||
|  |  | ||||||
|         e.preventDefault(); |         e.preventDefault(); | ||||||
|         setDropTarget(column); |         setDropTarget(column); | ||||||
|  |  | ||||||
|         // Calculate drop position based on mouse position |         // Calculate drop position based on mouse position | ||||||
|         const cards = Array.from(e.currentTarget.querySelectorAll('.board-note')); |         const cards = Array.from((e.currentTarget as HTMLElement)?.querySelectorAll('.board-note')); | ||||||
|         const mouseY = e.clientY; |         const mouseY = e.clientY; | ||||||
|  |  | ||||||
|         let newIndex = cards.length; |         let newIndex = cards.length; | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import { LatLng } from "leaflet"; | import type { LatLng, LeafletMouseEvent } from "leaflet"; | ||||||
| import { LOCATION_ATTRIBUTE } from "."; | import { LOCATION_ATTRIBUTE } from "."; | ||||||
| import attributes from "../../../services/attributes"; | import attributes from "../../../services/attributes"; | ||||||
| import { prompt } from "../../../services/dialog"; | import { prompt } from "../../../services/dialog"; | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import Map, { MapApi } from "./map"; | import Map from "./map"; | ||||||
| import "./index.css"; | import "./index.css"; | ||||||
| import { ViewModeProps } from "../interface"; | import { ViewModeProps } from "../interface"; | ||||||
| import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTouchBar, useTriliumEvent } from "../../react/hooks"; | import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTouchBar, useTriliumEvent } from "../../react/hooks"; | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ import { useElementSize, useSyncedRef } from "../../react/hooks"; | |||||||
| export const ParentMap = createContext<L.Map | null>(null); | export const ParentMap = createContext<L.Map | null>(null); | ||||||
|  |  | ||||||
| interface MapProps { | interface MapProps { | ||||||
|     apiRef?: RefObject<MapApi | null>; |     apiRef?: RefObject<L.Map | null>; | ||||||
|     containerRef?: RefObject<HTMLDivElement>; |     containerRef?: RefObject<HTMLDivElement>; | ||||||
|     coordinates: LatLng | [number, number]; |     coordinates: LatLng | [number, number]; | ||||||
|     zoom: number; |     zoom: number; | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ import link from "../../../services/link"; | |||||||
| import { t } from "../../../services/i18n"; | import { t } from "../../../services/i18n"; | ||||||
| import attribute_renderer from "../../../services/attribute_renderer"; | import attribute_renderer from "../../../services/attribute_renderer"; | ||||||
|  |  | ||||||
| export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps) { | export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) { | ||||||
|     const [ isExpanded ] = useNoteLabelBoolean(note, "expanded"); |     const [ isExpanded ] = useNoteLabelBoolean(note, "expanded"); | ||||||
|     const noteIds = useFilteredNoteIds(note, unfilteredNoteIds); |     const noteIds = useFilteredNoteIds(note, unfilteredNoteIds); | ||||||
|     const { pageNotes, ...pagination } = usePagination(note, noteIds); |     const { pageNotes, ...pagination } = usePagination(note, noteIds); | ||||||
| @@ -34,7 +34,7 @@ export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens } | |||||||
|     ); |     ); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function GridView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps) { | export function GridView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) { | ||||||
|     const noteIds = useFilteredNoteIds(note, unfilteredNoteIds); |     const noteIds = useFilteredNoteIds(note, unfilteredNoteIds); | ||||||
|     const { pageNotes, ...pagination } = usePagination(note, noteIds); |     const { pageNotes, ...pagination } = usePagination(note, noteIds); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -179,7 +179,6 @@ interface FormatterOpts { | |||||||
|  |  | ||||||
| interface EditorOpts { | interface EditorOpts { | ||||||
|     cell: CellComponent, |     cell: CellComponent, | ||||||
|     onRendered: EmptyCallback, |  | ||||||
|     success: ValueBooleanCallback, |     success: ValueBooleanCallback, | ||||||
|     cancel: ValueVoidCallback, |     cancel: ValueVoidCallback, | ||||||
|     editorParams: {} |     editorParams: {} | ||||||
| @@ -194,6 +193,7 @@ function wrapFormatter(Component: (opts: FormatterOpts) => JSX.Element): ((cell: | |||||||
|  |  | ||||||
| function wrapEditor(Component: (opts: EditorOpts) => JSX.Element): (( | function wrapEditor(Component: (opts: EditorOpts) => JSX.Element): (( | ||||||
|     cell: CellComponent, |     cell: CellComponent, | ||||||
|  |     onRendered: EmptyCallback, | ||||||
|     success: ValueBooleanCallback, |     success: ValueBooleanCallback, | ||||||
|     cancel: ValueVoidCallback, |     cancel: ValueVoidCallback, | ||||||
|     editorParams: {}, |     editorParams: {}, | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ import { useContext, useEffect, useLayoutEffect, useRef } from "preact/hooks"; | |||||||
| import { EventCallBackMethods, Module, Options, Tabulator as VanillaTabulator } from "tabulator-tables"; | import { EventCallBackMethods, Module, Options, Tabulator as VanillaTabulator } from "tabulator-tables"; | ||||||
| import "tabulator-tables/dist/css/tabulator.css"; | import "tabulator-tables/dist/css/tabulator.css"; | ||||||
| import "../../../../src/stylesheets/table.css"; | import "../../../../src/stylesheets/table.css"; | ||||||
| import { RefObject } from "preact"; | import { JSX, RefObject, VNode } from "preact"; | ||||||
| import { ParentComponent, renderReactWidget } from "../../react/react_utils"; | import { ParentComponent, renderReactWidget } from "../../react/react_utils"; | ||||||
|  |  | ||||||
| interface TableProps<T> extends Omit<Options, "data" | "footerElement" | "index"> { | interface TableProps<T> extends Omit<Options, "data" | "footerElement" | "index"> { | ||||||
| @@ -12,9 +12,10 @@ interface TableProps<T> extends Omit<Options, "data" | "footerElement" | "index" | |||||||
|     modules?: (new (table: VanillaTabulator) => Module)[]; |     modules?: (new (table: VanillaTabulator) => Module)[]; | ||||||
|     events?: Partial<EventCallBackMethods>; |     events?: Partial<EventCallBackMethods>; | ||||||
|     index: keyof T; |     index: keyof T; | ||||||
|  |     footerElement?: JSX.Element; | ||||||
| } | } | ||||||
|  |  | ||||||
| export default function Tabulator<T>({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, footerElement, events, ...restProps }: TableProps<T>) { | export default function Tabulator<T>({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, footerElement, events, index, ...restProps }: TableProps<T>) { | ||||||
|     const parentComponent = useContext(ParentComponent); |     const parentComponent = useContext(ParentComponent); | ||||||
|     const containerRef = useRef<HTMLDivElement>(null); |     const containerRef = useRef<HTMLDivElement>(null); | ||||||
|     const tabulatorRef = useRef<VanillaTabulator>(null); |     const tabulatorRef = useRef<VanillaTabulator>(null); | ||||||
| @@ -33,6 +34,7 @@ export default function Tabulator<T>({ className, columns, data, modules, tabula | |||||||
|             columns, |             columns, | ||||||
|             data, |             data, | ||||||
|             footerElement: (parentComponent && footerElement ? renderReactWidget(parentComponent, footerElement)[0] : undefined), |             footerElement: (parentComponent && footerElement ? renderReactWidget(parentComponent, footerElement)[0] : undefined), | ||||||
|  |             index: index as string | number | undefined, | ||||||
|             ...restProps |             ...restProps | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user