Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): import event and style types from `preact` under Preact 11

Elian Doranafdcb28c8753
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 3371359688..3e13e6870e 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -1,10 +1,9 @@
import clsx from "clsx";
-import { Fragment } from "preact";
+import { Fragment, TargetedMouseEvent, TargetedWheelEvent } from "preact";
import { flushSync } from "preact/compat";
import {
useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState
} from "preact/hooks";
-import { JSX } from "preact/jsx-runtime";
import FBranch from "../../../entities/fbranch";
import FNote from "../../../entities/fnote";
@@ -581,7 +580,7 @@ export default function Column({
const isRailDrawn = useLingeringTrue(isRailShown, RAIL_EXIT_MS);
/** Allow using mouse wheel to scroll inside card, while also maintaining column horizontal scrolling. */
- const handleScroll = useCallback((event: JSX.TargetedWheelEvent<HTMLDivElement>) => {
+ const handleScroll = useCallback((event: TargetedWheelEvent<HTMLDivElement>) => {
const el = event.currentTarget;
if (!el) return;
@@ -903,7 +902,7 @@ export default function Column({
* Where a menu opened from a button stands: at the pointer for a press, and below the button for a
* keyboard, which reports no position of its own.
*/
-function menuOrigin(e: JSX.TargetedMouseEvent<HTMLElement>): [ number, number ] {
+function menuOrigin(e: TargetedMouseEvent<HTMLElement>): [ number, number ] {
if (e.detail) {
return [ e.pageX, e.pageY ];
}
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 9bea19c056..576474544b 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -2,8 +2,10 @@ import "./index.css";
import clsx from "clsx";
-import { ComponentChildren, createContext, Fragment, TargetedKeyboardEvent } from "preact";
-import { JSX } from "preact/jsx-runtime";
+import {
+ ComponentChildren, createContext, Fragment, TargetedFocusEvent, TargetedKeyboardEvent,
+ TargetedMouseEvent, TargetedPointerEvent
+} from "preact";
import { createPortal, RefObject, useSyncExternalStore } from "preact/compat";
import {
Dispatch, StateUpdater, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState
@@ -2021,7 +2023,7 @@ export function TitleEditor({
}
/** Offers both ends, saving what the field held when the menu was opened. */
- function openPlacementMenu(e: JSX.TargetedMouseEvent<HTMLElement>) {
+ function openPlacementMenu(e: TargetedMouseEvent<HTMLElement>) {
e.preventDefault();
e.stopPropagation();
cancelHold();
@@ -2031,7 +2033,7 @@ export function TitleEditor({
}
/** Opens the same menu for a finger, which has no second button to open it with. */
- function holdToPlace(e: JSX.TargetedPointerEvent<HTMLElement>) {
+ function holdToPlace(e: TargetedPointerEvent<HTMLElement>) {
if (e.pointerType === "mouse") {
return;
}
@@ -2052,14 +2054,14 @@ export function TitleEditor({
}
/** Gives up on a hold the finger has walked away from, which is a scroll and not a press. */
- function holdMoved(e: JSX.TargetedPointerEvent<HTMLElement>) {
+ function holdMoved(e: TargetedPointerEvent<HTMLElement>) {
const from = heldFrom.current;
if (from && Math.hypot(e.clientX - from.x, e.clientY - from.y) > HOLD_SLACK_PX) {
cancelHold();
}
}
- function pressed(e: JSX.TargetedMouseEvent<HTMLElement>) {
+ function pressed(e: TargetedMouseEvent<HTMLElement>) {
cancelHold();
// A hold ends in a click, which would reach the page and close the menu it just opened.
@@ -2100,7 +2102,7 @@ export function TitleEditor({
* Ends the edit when focus moves outside `fieldRef`. A `relatedTarget` inside it is the field
* itself; `isHoldingOpen` covers the picker's menu, which is drawn outside `fieldRef`.
*/
- function iconFocusOut(e: JSX.TargetedFocusEvent<HTMLSpanElement>) {
+ function iconFocusOut(e: TargetedFocusEvent<HTMLSpanElement>) {
isIconFocused.current = false;
const next = e.relatedTarget;
@@ -2112,7 +2114,7 @@ export function TitleEditor({
}
/** Leaves the editor from the picker, which Escape does from the field itself. */
- function iconKeyDown(e: JSX.TargetedKeyboardEvent<HTMLSpanElement>) {
+ function iconKeyDown(e: TargetedKeyboardEvent<HTMLSpanElement>) {
if (e.key !== "Escape" || isHoldingOpen.current) {
return;
}
diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx
index 303dc80523..a8edcc4db6 100644
--- a/apps/client/src/widgets/react/Button.tsx
+++ b/apps/client/src/widgets/react/Button.tsx
@@ -1,7 +1,7 @@
import "./Button.css";
import type { Tooltip } from "bootstrap";
-import type { ComponentChildren, CSSProperties, JSX, RefObject } from "preact";
+import type { ComponentChildren, CSSProperties, MouseEventHandler, RefObject } from "preact";
import { useMemo, useRef } from "preact/hooks";
import { CommandNames } from "../../components/app_context";
@@ -30,7 +30,7 @@ export interface ButtonProps {
* the press's own target to know where to act — opening a note in the tab the button stands in,
* for one (see `openInCurrentNoteContext`).
*/
- onClick?: JSX.MouseEventHandler<HTMLButtonElement>;
+ onClick?: MouseEventHandler<HTMLButtonElement>;
kind?: "primary" | "secondary" | "lowProfile";
disabled?: boolean;
size?: "normal" | "small" | "micro";
diff --git a/apps/client/src/widgets/sidebar/pdf/PdfPages.tsx b/apps/client/src/widgets/sidebar/pdf/PdfPages.tsx
index 7f71007117..f11604fc03 100644
--- a/apps/client/src/widgets/sidebar/pdf/PdfPages.tsx
+++ b/apps/client/src/widgets/sidebar/pdf/PdfPages.tsx
@@ -1,5 +1,6 @@
import "./PdfPages.css";
+import type { CSSProperties } from "preact";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import type React from "react";
import { List, type RowComponentProps } from "react-window";
@@ -106,7 +107,7 @@ function PdfPageRow({ index, style, ...data }: RowComponentProps<PdfPageRowData>
const pages = Array.from({ length: COLUMNS }, (_, i) => startPage + i).filter(p => p <= totalPages);
return (
- <div style={style as preact.JSX.CSSProperties} className="pdf-page-row">
+ <div style={style as CSSProperties} className="pdf-page-row">
{pages.map(pageNumber => (
<PdfPageCell
key={pageNumber}
diff --git a/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts b/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts
index 54ccd29672..56ddf7ce63 100644
--- a/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts
+++ b/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts
@@ -1,8 +1,7 @@
import { CaptureUpdateAction, restoreElements, viewportCoordsToSceneCoords } from "@excalidraw/excalidraw";
import { ExcalidrawEmbeddableElement } from "@excalidraw/excalidraw/element/types";
import { ExcalidrawImperativeAPI } from "@excalidraw/excalidraw/types";
-import { RefObject } from "preact";
-import { JSX } from "preact";
+import { RefObject, TargetedDragEvent } from "preact";
import { useCallback } from "preact/hooks";
/** Default size of an embeddable created by dropping a note onto the canvas. */
@@ -24,7 +23,7 @@ const STACK_OFFSET = 24;
* other `text/plain` drop falls through to Excalidraw's own handling.
*/
export default function useCanvasNoteDrop(apiRef: RefObject<ExcalidrawImperativeAPI | null>, isReadOnly: boolean) {
- const onDragOverCapture = useCallback((e: JSX.TargetedDragEvent<HTMLElement>) => {
+ const onDragOverCapture = useCallback((e: TargetedDragEvent<HTMLElement>) => {
if (isReadOnly || !e.dataTransfer?.types.includes("text/plain")) {
return;
}
@@ -33,7 +32,7 @@ export default function useCanvasNoteDrop(apiRef: RefObject<ExcalidrawImperative
e.stopPropagation();
}, [isReadOnly]);
- const onDropCapture = useCallback((e: JSX.TargetedDragEvent<HTMLElement>) => {
+ const onDropCapture = useCallback((e: TargetedDragEvent<HTMLElement>) => {
const api = apiRef.current;
if (isReadOnly || !api) {
return;