chore(react): solve most type errors

This commit is contained in:
Elian Doran 2025-09-14 10:38:05 +03:00
parent 3ac0dfb2ad
commit 4040f8ba89
No known key found for this signature in database
9 changed files with 19 additions and 18 deletions

View File

@ -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. */
displayOnlyCollections?: boolean;
highlightedTokens?: string[] | null;
viewStorage: ViewModeStorage<T>;
viewStorage?: ViewModeStorage<T>;
}
export default function NoteList<T extends object>({ note: providedNote, highlightedTokens, displayOnlyCollections }: NoteListProps<T>) {

View File

@ -31,7 +31,7 @@ export default function Card({
index: number,
isDragging: boolean
}) {
const { branchIdToEdit, setBranchIdToEdit, setDraggedCard } = useContext(BoardViewContext);
const { branchIdToEdit, setBranchIdToEdit, setDraggedCard } = useContext(BoardViewContext)!;
const isEditing = branch.branchId === branchIdToEdit;
const colorClass = note.getColorClass() || '';
const editorRef = useRef<HTMLInputElement>(null);
@ -78,7 +78,7 @@ export default function Card({
return (
<div
className={`board-note ${colorClass} ${isDragging ? 'dragging' : ''} ${isEditing ? "editing" : ""} ${isArchived ? "archived" : ""}`}
draggable="true"
draggable
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
onContextMenu={handleContextMenu}

View File

@ -17,7 +17,6 @@ interface DragContext {
column: string;
columnIndex: number,
columnItems?: { note: FNote, branch: FBranch }[];
isEditing: boolean;
}
export default function Column({
@ -36,7 +35,7 @@ export default function Column({
isAnyColumnDragging?: boolean
} & DragContext) {
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 editorRef = useRef<HTMLInputElement>(null);
const { handleColumnDragStart, handleColumnDragEnd, handleDragOver, handleDragLeave, handleDrop } = useDragging({
@ -90,7 +89,7 @@ export default function Column({
>
<h3
className={`${isEditing ? "editing" : ""}`}
draggable="true"
draggable
onDragStart={handleColumnDragStart}
onDragEnd={handleColumnDragEnd}
onContextMenu={handleContextMenu}
@ -170,8 +169,8 @@ function AddNewItem({ column, api }: { column: string, api: BoardApi }) {
);
}
function useDragging({ column, columnIndex, columnItems, isEditing }: DragContext) {
const { api, parentNote, draggedColumn, setDraggedColumn, setDropTarget, setDropPosition, dropPosition } = useContext(BoardViewContext);
function useDragging({ column, columnIndex, columnItems, isEditing }: DragContext & { isEditing: boolean }) {
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. */
const isDraggingRef = useRef(false);
@ -192,13 +191,13 @@ function useDragging({ column, columnIndex, columnItems, isEditing }: DragContex
const handleDragOver = useCallback((e: DragEvent) => {
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();
setDropTarget(column);
// 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;
let newIndex = cards.length;

View File

@ -1,4 +1,4 @@
import { LatLng } from "leaflet";
import type { LatLng, LeafletMouseEvent } from "leaflet";
import { LOCATION_ATTRIBUTE } from ".";
import attributes from "../../../services/attributes";
import { prompt } from "../../../services/dialog";

View File

@ -1,4 +1,4 @@
import Map, { MapApi } from "./map";
import Map from "./map";
import "./index.css";
import { ViewModeProps } from "../interface";
import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTouchBar, useTriliumEvent } from "../../react/hooks";

View File

@ -8,7 +8,7 @@ import { useElementSize, useSyncedRef } from "../../react/hooks";
export const ParentMap = createContext<L.Map | null>(null);
interface MapProps {
apiRef?: RefObject<MapApi | null>;
apiRef?: RefObject<L.Map | null>;
containerRef?: RefObject<HTMLDivElement>;
coordinates: LatLng | [number, number];
zoom: number;

View File

@ -12,7 +12,7 @@ import link from "../../../services/link";
import { t } from "../../../services/i18n";
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 noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
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 { pageNotes, ...pagination } = usePagination(note, noteIds);

View File

@ -179,7 +179,6 @@ interface FormatterOpts {
interface EditorOpts {
cell: CellComponent,
onRendered: EmptyCallback,
success: ValueBooleanCallback,
cancel: ValueVoidCallback,
editorParams: {}
@ -194,6 +193,7 @@ function wrapFormatter(Component: (opts: FormatterOpts) => JSX.Element): ((cell:
function wrapEditor(Component: (opts: EditorOpts) => JSX.Element): ((
cell: CellComponent,
onRendered: EmptyCallback,
success: ValueBooleanCallback,
cancel: ValueVoidCallback,
editorParams: {},

View File

@ -2,7 +2,7 @@ import { useContext, useEffect, useLayoutEffect, useRef } from "preact/hooks";
import { EventCallBackMethods, Module, Options, Tabulator as VanillaTabulator } from "tabulator-tables";
import "tabulator-tables/dist/css/tabulator.css";
import "../../../../src/stylesheets/table.css";
import { RefObject } from "preact";
import { JSX, RefObject, VNode } from "preact";
import { ParentComponent, renderReactWidget } from "../../react/react_utils";
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)[];
events?: Partial<EventCallBackMethods>;
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 containerRef = useRef<HTMLDivElement>(null);
const tabulatorRef = useRef<VanillaTabulator>(null);
@ -33,6 +34,7 @@ export default function Tabulator<T>({ className, columns, data, modules, tabula
columns,
data,
footerElement: (parentComponent && footerElement ? renderReactWidget(parentComponent, footerElement)[0] : undefined),
index: index as string | number | undefined,
...restProps
});