Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): let ref types hold null under Preact 11

Elian Doran9e4e485bbf1a
diff --git a/apps/client/src/widgets/EmbeddedNotePane.tsx b/apps/client/src/widgets/EmbeddedNotePane.tsx
index d5c9ace59a..aa3ada83a9 100644
--- a/apps/client/src/widgets/EmbeddedNotePane.tsx
+++ b/apps/client/src/widgets/EmbeddedNotePane.tsx
@@ -155,7 +155,7 @@ export function SelectTitleOnFirstOpen() {
* the document-level handler every link click otherwise lands in (see the delegated listeners in
* link.ts) — and of the editor's.
*/
-export function useFollowLinksWithin(paneRef: RefObject<HTMLElement>, onFollowLink: (noteId: string) => boolean) {
+export function useFollowLinksWithin(paneRef: RefObject<HTMLElement | null>, onFollowLink: (noteId: string) => boolean) {
useEffect(() => {
const pane = paneRef.current;
if (!pane) return;
diff --git a/apps/client/src/widgets/buttons/global_menu.tsx b/apps/client/src/widgets/buttons/global_menu.tsx
index 9e63a4a3b8..f5404a4c3b 100644
--- a/apps/client/src/widgets/buttons/global_menu.tsx
+++ b/apps/client/src/widgets/buttons/global_menu.tsx
@@ -161,7 +161,7 @@ function KeyboardActionMenuItem({ command, ...props }: MenuItemProps<KeyboardAct
return <MenuItem {...props} command={command} keyboardShortcut={command} />;
}
-export function VerticalLayoutIcon({ logoRef }: { logoRef?: RefObject<SVGSVGElement> }) {
+export function VerticalLayoutIcon({ logoRef }: { logoRef?: RefObject<SVGSVGElement | null> }) {
return (
<svg ref={logoRef} viewBox="0 0 256 256" title={t("global_menu.menu")}>
<g>
diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.ts
index 57d74627bc..c34688541e 100644
--- a/apps/client/src/widgets/collections/board/board_drag.ts
+++ b/apps/client/src/widgets/collections/board/board_drag.ts
@@ -129,7 +129,7 @@ export interface BoardDragCallbacks {
* @param disabled whether to leave presses alone.
*/
export function useBoardDrag(
- containerRef: RefObject<HTMLElement>,
+ containerRef: RefObject<HTMLElement | null>,
callbacks: BoardDragCallbacks,
disabled = false
) {
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 324349fffc..03991f82b2 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -274,7 +274,8 @@ export const BoardHighlightTokensContext = createContext<HighlightedTokenInfo[]
export const BoardKeptCardsContext = createContext<Set<string>>(new Set());
/** The board's own element, which what a card floats over the board is portaled into. */
-export const BoardOverlayHostContext = createContext<RefObject<HTMLElement>>({ current: null });
+export const BoardOverlayHostContext =
+ createContext<RefObject<HTMLElement | null>>({ current: null });
/** Whether a tap picks a card out instead of opening it, which the mobile header switches on. */
export const BoardSelectionModeContext = createContext(false);
@@ -1859,7 +1860,7 @@ export function TitleEditor({
* whose editor was opened by an insert passes its own element, so closing does not focus the
* card the insert was made from.
*/
- returnFocusTo?: RefObject<HTMLElement>;
+ returnFocusTo?: RefObject<HTMLElement | null>;
/**
* Whether opening the editor selects the text already in it, which is what a rename wants. An
* editor opened part-typed puts the caret after the text instead, so the next key continues it.
diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.ts
index 8b184a363e..1123c5fdf1 100644
--- a/apps/client/src/widgets/collections/board/keyboard.ts
+++ b/apps/client/src/widgets/collections/board/keyboard.ts
@@ -60,7 +60,7 @@ interface PendingFocus {
}
export interface BoardKeyboardOptions {
- containerRef: RefObject<HTMLDivElement>;
+ containerRef: RefObject<HTMLDivElement | null>;
/** The columns as shown, which is what the arrows count and what `moveColumn` is told about. */
columns: string[];
byColumn: ColumnMap | undefined;
diff --git a/apps/client/src/widgets/collections/board/reference.ts b/apps/client/src/widgets/collections/board/reference.ts
index ce81a61aa6..a6cd2d2a65 100644
--- a/apps/client/src/widgets/collections/board/reference.ts
+++ b/apps/client/src/widgets/collections/board/reference.ts
@@ -59,7 +59,7 @@ export interface BoardReferenceOptions {
/** Draws a collapsed column open, without storing it as open. */
selectColumn: (column: string) => void;
/** The board's own element, which what is revealed is looked for in. */
- containerRef: RefObject<HTMLElement>;
+ containerRef: RefObject<HTMLElement | null>;
}
/**
diff --git a/apps/client/src/widgets/collections/board/windowing.ts b/apps/client/src/widgets/collections/board/windowing.ts
index 47ee47f590..c305c98f2d 100644
--- a/apps/client/src/widgets/collections/board/windowing.ts
+++ b/apps/client/src/widgets/collections/board/windowing.ts
@@ -183,7 +183,7 @@ export function sameWindow(a: ColumnWindow, b: ColumnWindow) {
* @param enabled whether to window this column at all.
*/
export function useColumnWindow(
- areaRef: RefObject<HTMLElement>,
+ areaRef: RefObject<HTMLElement | null>,
noteIds: readonly string[],
enabled: boolean
) {
diff --git a/apps/client/src/widgets/collections/calendar/calendar.tsx b/apps/client/src/widgets/collections/calendar/calendar.tsx
index 3d8be8d0c3..f0163e757d 100644
--- a/apps/client/src/widgets/collections/calendar/calendar.tsx
+++ b/apps/client/src/widgets/collections/calendar/calendar.tsx
@@ -3,7 +3,7 @@ import { CalendarOptions, Calendar as FullCalendar } from "fullcalendar";
import { RefObject } from "preact";
export interface CalendarProps extends CalendarOptions {
- calendarRef?: RefObject<FullCalendar>;
+ calendarRef?: RefObject<FullCalendar | null>;
}
export default function Calendar({ calendarRef, ...options }: CalendarProps) {
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index b60f61cdd1..c1bbb45759 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -410,8 +410,8 @@ export default function CalendarView({ note, noteIds }: ViewModeProps<CalendarVi
function CalendarCollectionProperties({ note, calendarRef, containerRef }: {
note: FNote;
- calendarRef: RefObject<FullCalendar>;
- containerRef: RefObject<HTMLDivElement>;
+ calendarRef: RefObject<FullCalendar | null>;
+ containerRef: RefObject<HTMLDivElement | null>;
}) {
const { title, viewType: currentViewType } = useOnDatesSet(calendarRef);
const currentViewData = CALENDAR_VIEWS.find(v => calendarRef.current && v.type === currentViewType);
@@ -439,7 +439,7 @@ function CalendarCollectionProperties({ note, calendarRef, containerRef }: {
function PinDateButton({ note, calendarRef }: {
note: FNote;
- calendarRef: RefObject<FullCalendar>;
+ calendarRef: RefObject<FullCalendar | null>;
}) {
const [ initialDate, setInitialDate ] = useNoteLabel(note, "calendar:initialDate");
const isPinned = !!initialDate;
@@ -468,9 +468,9 @@ function PinDateButton({ note, calendarRef }: {
* a screen, which is why the fold is decided by the view's own width rather than by the device.
*/
function CalendarViewSwitcher({ calendarRef, containerRef }: {
- calendarRef: RefObject<FullCalendar>;
+ calendarRef: RefObject<FullCalendar | null>;
/** The view's own element, whose width the row of buttons is weighed against. */
- containerRef: RefObject<HTMLDivElement>;
+ containerRef: RefObject<HTMLDivElement | null>;
}) {
const { viewType: currentViewType } = useOnDatesSet(calendarRef);
const currentViewTypeData = CALENDAR_VIEWS.find(view => view.type === currentViewType);
@@ -778,7 +778,7 @@ export function eventInnerClass(e: EventDisplayInfo) {
&& "calendar-event-inner-wrapped");
}
-function useOnDatesSet(calendarRef: RefObject<FullCalendar>) {
+function useOnDatesSet(calendarRef: RefObject<FullCalendar | null>) {
const [ title, setTitle ] = useState<string>();
const [ viewType ,setViewType ] = useState<string>();
useEffect(() => {
diff --git a/apps/client/src/widgets/collections/dashboard/index.tsx b/apps/client/src/widgets/collections/dashboard/index.tsx
index f4376fd27c..0fbcbb7530 100644
--- a/apps/client/src/widgets/collections/dashboard/index.tsx
+++ b/apps/client/src/widgets/collections/dashboard/index.tsx
@@ -84,7 +84,7 @@ function useDashboardNotes(noteIds: string[]) {
/** Whether the dashboard is narrow enough to collapse to a single column, where dragging and
* resizing are disabled (the derived single-column layout isn't persisted). */
-function useIsCollapsed(containerRef: RefObject<HTMLElement>) {
+function useIsCollapsed(containerRef: RefObject<HTMLElement | null>) {
const containerSize = useElementSize(containerRef);
return (containerSize?.width ?? Number.POSITIVE_INFINITY) < SINGLE_COLUMN_BREAKPOINT;
}
@@ -98,7 +98,7 @@ function useDashboardLayoutPersistence({ note, viewConfig, saveConfig, gridRef,
viewConfig: DashboardViewConfig | undefined;
saveConfig: (config: DashboardViewConfig) => void;
gridRef: MutableRef<GridStack | null>;
- containerRef: RefObject<HTMLDivElement>;
+ containerRef: RefObject<HTMLDivElement | null>;
}) {
// Gridstack becomes the source of truth for geometry after init; capture the saved layout once
// since the viewConfig prop changes identity after every save.
@@ -184,7 +184,7 @@ function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, g
notes: FNote[];
viewConfig: DashboardViewConfig | undefined;
saveConfig: (config: DashboardViewConfig) => void;
- containerRef: RefObject<HTMLDivElement>;
+ containerRef: RefObject<HTMLDivElement | null>;
gridRef: MutableRef<GridStack | null>;
dropPositionsRef: MutableRef<WidgetLayouts>;
isCollapsed: boolean;
@@ -274,7 +274,7 @@ function useDashboardGrid({ note, notes, viewConfig, saveConfig, containerRef, g
* the dashboard and the first one is positioned under the cursor. Returns a ref holding the drop
* positions of the freshly cloned notes, which the reconcile effect consumes (once) when it
* promotes them to grid widgets — kept out of savedWidgetsRef so persistLayout still saves them. */
-function useNoteTreeDropToDashboard(note: FNote, includeArchived: boolean, dropAreaRef: RefObject<HTMLDivElement>, gridContainerRef: RefObject<HTMLDivElement>, gridRef: RefObject<GridStack | null>) {
+function useNoteTreeDropToDashboard(note: FNote, includeArchived: boolean, dropAreaRef: RefObject<HTMLDivElement | null>, gridContainerRef: RefObject<HTMLDivElement | null>, gridRef: RefObject<GridStack | null>) {
const dropPositionsRef = useRef<WidgetLayouts>({});
useCollectionTreeDrag(dropAreaRef, {
diff --git a/apps/client/src/widgets/collections/geomap/map.tsx b/apps/client/src/widgets/collections/geomap/map.tsx
index 101a2aea7f..490597f8ba 100644
--- a/apps/client/src/widgets/collections/geomap/map.tsx
+++ b/apps/client/src/widgets/collections/geomap/map.tsx
@@ -52,7 +52,7 @@ export const MapStyleLoaded = createContext(false);
interface MapProps {
apiRef?: RefObject<MapLibreGLMap | null>;
- containerRef?: RefObject<HTMLDivElement>;
+ containerRef?: RefObject<HTMLDivElement | null>;
coordinates: { lat: number; lng: number } | [number, number];
zoom: number;
layerData: MapLayer;
diff --git a/apps/client/src/widgets/collections/presentation/index.tsx b/apps/client/src/widgets/collections/presentation/index.tsx
index 3c7b236cab..f1c834753b 100644
--- a/apps/client/src/widgets/collections/presentation/index.tsx
+++ b/apps/client/src/widgets/collections/presentation/index.tsx
@@ -98,7 +98,7 @@ function usePresentationStylesheets(note: FNote, media: ViewModeMedia) {
return stylesheets;
}
-function ButtonOverlay({ containerRef, api }: { containerRef: RefObject<HTMLDivElement>, api: RevealApi | undefined }) {
+function ButtonOverlay({ containerRef, api }: { containerRef: RefObject<HTMLDivElement | null>, api: RevealApi | undefined }) {
const [ isOverviewActive, setIsOverviewActive ] = useState(false);
useEffect(() => {
if (!api) return;
diff --git a/apps/client/src/widgets/collections/table/col_editing.ts b/apps/client/src/widgets/collections/table/col_editing.ts
index 62a6f9d267..c54b300d1c 100644
--- a/apps/client/src/widgets/collections/table/col_editing.ts
+++ b/apps/client/src/widgets/collections/table/col_editing.ts
@@ -12,7 +12,7 @@ import dialog from "../../../services/dialog";
import { t } from "i18next";
import { executeBulkActions } from "../../../services/bulk_action";
-export default function useColTableEditing(api: RefObject<Tabulator>, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote) {
+export default function useColTableEditing(api: RefObject<Tabulator | null>, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote) {
const existingAttributeToEdit = useRef<Attribute>();
const newAttribute = useRef<Attribute>();
diff --git a/apps/client/src/widgets/collections/table/context_menu.ts b/apps/client/src/widgets/collections/table/context_menu.ts
index 3d27c41e74..ce0b8e82c0 100644
--- a/apps/client/src/widgets/collections/table/context_menu.ts
+++ b/apps/client/src/widgets/collections/table/context_menu.ts
@@ -11,7 +11,7 @@ import Component from "../../../components/component.js";
import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker.jsx";
import { RefObject } from "preact";
-export function useContextMenu(parentNote: FNote, parentComponent: Component | null | undefined, tabulator: RefObject<Tabulator>): Partial<EventCallBackMethods> {
+export function useContextMenu(parentNote: FNote, parentComponent: Component | null | undefined, tabulator: RefObject<Tabulator | null>): Partial<EventCallBackMethods> {
const events: Partial<EventCallBackMethods> = {};
if (!tabulator || !parentComponent) return events;
diff --git a/apps/client/src/widgets/collections/table/row_editing.ts b/apps/client/src/widgets/collections/table/row_editing.ts
index cc4396227f..a1e2f65a44 100644
--- a/apps/client/src/widgets/collections/table/row_editing.ts
+++ b/apps/client/src/widgets/collections/table/row_editing.ts
@@ -13,7 +13,7 @@ import AttributeDetailWidget from "../../attribute_widgets/attribute_detail";
import { useLegacyImperativeHandlers } from "../../react/hooks";
import { ParentComponent } from "../../react/react_utils";
-export default function useRowTableEditing(api: RefObject<Tabulator>, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote): Partial<EventCallBackMethods> {
+export default function useRowTableEditing(api: RefObject<Tabulator | null>, attributeDetailWidget: AttributeDetailWidget, parentNote: FNote): Partial<EventCallBackMethods> {
// Whose writes these are, so that useData can tell a cell this table edited itself from one
// changed elsewhere. Rebuilding the rows for its own edit replaces them wholesale in Tabulator,
// which cancels the editor Tab has just opened in the next cell.
diff --git a/apps/client/src/widgets/collections/table/tabulator.tsx b/apps/client/src/widgets/collections/table/tabulator.tsx
index bfe3ef9756..d923866657 100644
--- a/apps/client/src/widgets/collections/table/tabulator.tsx
+++ b/apps/client/src/widgets/collections/table/tabulator.tsx
@@ -9,7 +9,7 @@ import { EventCallBackMethods, Module, Options, Tabulator as VanillaTabulator }
import { ParentComponent, renderReactWidget } from "../../react/react_utils";
export interface TableProps<T extends {}> extends Omit<Options, "data" | "footerElement" | "index"> {
- tabulatorRef?: RefObject<VanillaTabulator>;
+ tabulatorRef?: RefObject<VanillaTabulator | null>;
className?: string;
data?: T[];
modules?: (new (table: VanillaTabulator) => Module)[];
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
index 8c40552d1f..aec4426e3a 100644
--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx
+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx
@@ -228,7 +228,7 @@ export function isOptionPageVisibleOnPlatform(page: FNote) {
* `.note-detail` pane in the mobile master-detail flow.
*/
function SettingsScrollReset(
- { modalRef, searching }: { modalRef: RefObject<HTMLDivElement>, searching: boolean }
+ { modalRef, searching }: { modalRef: RefObject<HTMLDivElement | null>, searching: boolean }
) {
const { noteId } = useNoteContext();
useLayoutEffect(() => {
diff --git a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx
index 009108cdf9..8294506dc5 100644
--- a/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx
+++ b/apps/client/src/widgets/dialogs/PopupEditor.spec.tsx
@@ -76,7 +76,7 @@ interface ModalStubProps {
children?: ComponentChildren;
show?: boolean;
customTitleBarButtons?: { onClick: () => void }[];
- modalRef?: RefObject<HTMLDivElement>;
+ modalRef?: RefObject<HTMLDivElement | null>;
onShown?: () => void;
onHidden?: () => void;
}
diff --git a/apps/client/src/widgets/dialogs/note_type_chooser.tsx b/apps/client/src/widgets/dialogs/note_type_chooser.tsx
index 2218e87222..a2ee1c0f03 100644
--- a/apps/client/src/widgets/dialogs/note_type_chooser.tsx
+++ b/apps/client/src/widgets/dialogs/note_type_chooser.tsx
@@ -130,7 +130,7 @@ export default function NoteTypeChooserDialogComponent() {
* Focuses the first note type so Enter creates a text note, until the user moves focus themselves.
* Both the arrival of the types and `onShown` apply it, since either can be the one that comes last.
*/
-function useFirstNoteTypeFocus(modalRef: RefObject<HTMLDivElement>, shown: boolean, noteTypeCount: number) {
+function useFirstNoteTypeFocus(modalRef: RefObject<HTMLDivElement | null>, shown: boolean, noteTypeCount: number) {
const userMovedFocus = useRef(false);
const tryFocusFirstNoteType = useCallback(() => {
diff --git a/apps/client/src/widgets/layout/StatusBar.tsx b/apps/client/src/widgets/layout/StatusBar.tsx
index 229bd32095..f2c2aac8ee 100644
--- a/apps/client/src/widgets/layout/StatusBar.tsx
+++ b/apps/client/src/widgets/layout/StatusBar.tsx
@@ -276,7 +276,7 @@ export function NoteInfoBadge(context: NoteInfoContext) {
}
export function NoteInfoContent({ note, noteType, dropdownRef, setSimilarNotesShown }: Pick<NoteInfoContext, "note" | "setSimilarNotesShown"> & {
- dropdownRef?: RefObject<DropdownHandle>;
+ dropdownRef?: RefObject<DropdownHandle | null>;
noteType: NoteType;
}) {
const { metadata, ...sizeProps } = useNoteMetadata(note);
diff --git a/apps/client/src/widgets/note_map/NoteMap.tsx b/apps/client/src/widgets/note_map/NoteMap.tsx
index 76f3ec9298..f82fe096ad 100644
--- a/apps/client/src/widgets/note_map/NoteMap.tsx
+++ b/apps/client/src/widgets/note_map/NoteMap.tsx
@@ -26,7 +26,7 @@ const MAX_NOTES_THRESHOLD = 1_000;
interface NoteMapProps {
note: FNote;
widgetMode: NoteMapWidgetMode;
- parentRef: RefObject<HTMLElement>;
+ parentRef: RefObject<HTMLElement | null>;
}
export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {
diff --git a/apps/client/src/widgets/quick_search.tsx b/apps/client/src/widgets/quick_search.tsx
index c3326dd101..12725fb3fc 100644
--- a/apps/client/src/widgets/quick_search.tsx
+++ b/apps/client/src/widgets/quick_search.tsx
@@ -210,7 +210,7 @@ export default function QuickSearch() {
* the field, and closes them on Escape. Captured at the window, as Bootstrap's handler for keys in
* a `.dropdown-menu` crashes on one with no toggle beside it.
*/
-function useResultNavigation(popupRef: RefObject<HTMLElement>, open: boolean, callbacks: {
+function useResultNavigation(popupRef: RefObject<HTMLElement | null>, open: boolean, callbacks: {
/** Runs for ArrowUp on the first result. */
focusField(): void;
/** Runs once the keys have moved focus to another result. */
diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx
index 63cc1d4eb5..303dc80523 100644
--- a/apps/client/src/widgets/react/Button.tsx
+++ b/apps/client/src/widgets/react/Button.tsx
@@ -18,7 +18,7 @@ const cachedIsMobile = isMobile();
export interface ButtonProps {
name?: string;
/** Reference to the button element. Mostly useful for requesting focus. */
- buttonRef?: RefObject<HTMLButtonElement>;
+ buttonRef?: RefObject<HTMLButtonElement | null>;
text: string | ComponentChildren;
className?: string;
icon?: string;
diff --git a/apps/client/src/widgets/react/CollapseOnOverflow.tsx b/apps/client/src/widgets/react/CollapseOnOverflow.tsx
index e0045a64fb..08e26bc851 100644
--- a/apps/client/src/widgets/react/CollapseOnOverflow.tsx
+++ b/apps/client/src/widgets/react/CollapseOnOverflow.tsx
@@ -105,7 +105,7 @@ export function nextCollapsedState(state: CollapseState, { wantedWidth, givenWid
}
/** Watches the control and its container, answering which rendering the width allows for. */
-function useCollapsed(ref: RefObject<HTMLDivElement>, container: RefObject<HTMLElement | null>, alwaysCollapsed?: boolean) {
+function useCollapsed(ref: RefObject<HTMLDivElement | null>, container: RefObject<HTMLElement | null>, alwaysCollapsed?: boolean) {
const [ collapsed, setCollapsed ] = useState(false);
// Held rather than read from the state: the measuring below happens outside of a render, and what
// it decides from is its own last answer along with the width it then found wanting.
diff --git a/apps/client/src/widgets/react/ContextualHelp.tsx b/apps/client/src/widgets/react/ContextualHelp.tsx
index eea4e6959d..945a4dcefc 100644
--- a/apps/client/src/widgets/react/ContextualHelp.tsx
+++ b/apps/client/src/widgets/react/ContextualHelp.tsx
@@ -100,7 +100,7 @@ function TappedHelp({ helpMessage }: ContextualHelpProps) {
}
interface HelpIconProps {
- iconRef?: RefObject<HTMLSpanElement>;
+ iconRef?: RefObject<HTMLSpanElement | null>;
helpMessage: string;
/** What activating the icon opens, for anything that is not simply revealed in place. */
popup?: "dialog";
@@ -148,7 +148,7 @@ function HelpIcon({ iconRef, helpMessage, popup, onActivate, onDismiss }: HelpIc
}
/** Shows the icon's explanation, or puts it away again if it is already up. */
-function toggleTooltip(iconRef: RefObject<HTMLSpanElement>) {
+function toggleTooltip(iconRef: RefObject<HTMLSpanElement | null>) {
const element = iconRef.current;
if (element) {
@@ -163,7 +163,7 @@ function toggleTooltip(iconRef: RefObject<HTMLSpanElement>) {
* takes it off again on hide, which is the only public sign of whether one is open — and asking
* matters, because the answer decides whether the key press is ours to keep.
*/
-function dismissTooltip(iconRef: RefObject<HTMLSpanElement>) {
+function dismissTooltip(iconRef: RefObject<HTMLSpanElement | null>) {
const element = iconRef.current;
if (!element?.hasAttribute("aria-describedby")) {
diff --git a/apps/client/src/widgets/react/FilesystemFriendlyName.tsx b/apps/client/src/widgets/react/FilesystemFriendlyName.tsx
index 9549343cda..292a77ebc3 100644
--- a/apps/client/src/widgets/react/FilesystemFriendlyName.tsx
+++ b/apps/client/src/widgets/react/FilesystemFriendlyName.tsx
@@ -24,7 +24,7 @@ export interface FilesystemFriendlyNameProps
*/
export default function FilesystemFriendlyName({ currentValue, onChange, inputRef, ...rest }: FilesystemFriendlyNameProps) {
const ownRef = useRef<HTMLInputElement | null>(null);
- const element = (inputRef ?? ownRef) as RefObject<HTMLInputElement>;
+ const element = (inputRef ?? ownRef) as RefObject<HTMLInputElement | null>;
/** Where to put the caret once the refused character is gone, or null when nothing was. */
const caret = useRef<number | null>(null);
diff --git a/apps/client/src/widgets/react/FormAutocomplete.tsx b/apps/client/src/widgets/react/FormAutocomplete.tsx
index f0f33d73fc..706c5e3e39 100644
--- a/apps/client/src/widgets/react/FormAutocomplete.tsx
+++ b/apps/client/src/widgets/react/FormAutocomplete.tsx
@@ -322,7 +322,7 @@ interface UseAutocompleteOptions<T> {
/** Called with the entry picked by click or Enter. */
onPick(item: T): void;
/** The field, which keeps the focus once an entry is picked. */
- inputRef: RefObject<HTMLInputElement>;
+ inputRef: RefObject<HTMLInputElement | null>;
/** Keeps the list closed, for a read-only or disabled field. */
disabled?: boolean;
/** See {@link FormAutocompleteProps.openOnFocus}. */
diff --git a/apps/client/src/widgets/react/FormGroup.tsx b/apps/client/src/widgets/react/FormGroup.tsx
index 7ecb24d545..7ba466cb11 100644
--- a/apps/client/src/widgets/react/FormGroup.tsx
+++ b/apps/client/src/widgets/react/FormGroup.tsx
@@ -5,7 +5,7 @@ import { useUniqueName } from "./hooks";
interface FormGroupProps {
name: string;
- labelRef?: RefObject<HTMLLabelElement>;
+ labelRef?: RefObject<HTMLLabelElement | null>;
label?: string;
title?: string;
className?: string;
diff --git a/apps/client/src/widgets/react/FormList.tsx b/apps/client/src/widgets/react/FormList.tsx
index e5cb781ebf..bb4ee83c29 100644
--- a/apps/client/src/widgets/react/FormList.tsx
+++ b/apps/client/src/widgets/react/FormList.tsx
@@ -151,7 +151,7 @@ export interface FormListItemOpts {
className?: string;
rtl?: boolean;
postContent?: ComponentChildren;
- itemRef?: RefObject<HTMLLIElement>;
+ itemRef?: RefObject<HTMLLIElement | null>;
/**
* Makes the row one that is checked or not, which a menu tells assistive technology;
* {@link checked} says which.
diff --git a/apps/client/src/widgets/react/FormPasswordWithConfirmation.tsx b/apps/client/src/widgets/react/FormPasswordWithConfirmation.tsx
index daaec9c7ee..cfb1a5c8d3 100644
--- a/apps/client/src/widgets/react/FormPasswordWithConfirmation.tsx
+++ b/apps/client/src/widgets/react/FormPasswordWithConfirmation.tsx
@@ -11,7 +11,7 @@ export interface FormPasswordWithConfirmationProps {
/** Label of the second field. Defaults to a plain "Repeat password". */
confirmationLabel?: string;
/** Focus target, for a host that wants the first field focused when it opens. */
- inputRef?: RefObject<HTMLInputElement>;
+ inputRef?: RefObject<HTMLInputElement | null>;
/**
* Whether leaving both fields empty is an answer in itself, for a password that is offered
* rather than required. It is reported as an empty string, which is a settled "no password" as
diff --git a/apps/client/src/widgets/react/FormTextArea.tsx b/apps/client/src/widgets/react/FormTextArea.tsx
index c3d58c45db..47fa66fe05 100644
--- a/apps/client/src/widgets/react/FormTextArea.tsx
+++ b/apps/client/src/widgets/react/FormTextArea.tsx
@@ -5,7 +5,7 @@ interface FormTextAreaProps extends Omit<TextareaHTMLAttributes, "onBlur" | "onC
currentValue: string;
onChange?(newValue: string): void;
onBlur?(newValue: string): void;
- inputRef?: RefObject<HTMLTextAreaElement>
+ inputRef?: RefObject<HTMLTextAreaElement | null>
}
export default function FormTextArea({ inputRef, id, onBlur, onChange, currentValue, className, ...restProps }: FormTextAreaProps) {
return (
diff --git a/apps/client/src/widgets/react/FormTextBox.tsx b/apps/client/src/widgets/react/FormTextBox.tsx
index 471c02213a..696e425249 100644
--- a/apps/client/src/widgets/react/FormTextBox.tsx
+++ b/apps/client/src/widgets/react/FormTextBox.tsx
@@ -5,7 +5,7 @@ export interface FormTextBoxProps extends Omit<InputHTMLAttributes<HTMLInputElem
currentValue?: string;
onChange?(newValue: string, validity: ValidityState): void;
onBlur?(newValue: string): void;
- inputRef?: RefObject<HTMLInputElement>;
+ inputRef?: RefObject<HTMLInputElement | null>;
}
export default function FormTextBox({ inputRef, className, type, currentValue, onChange, onBlur, autoFocus, ...rest}: FormTextBoxProps) {
diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsx
index 88dc3336d9..df6d5da42a 100644
--- a/apps/client/src/widgets/react/Modal.tsx
+++ b/apps/client/src/widgets/react/Modal.tsx
@@ -60,11 +60,11 @@ export interface ModalProps {
* Gives access to the underlying modal element. This is useful for manipulating the modal directly
* or for attaching event listeners.
*/
- modalRef?: RefObject<HTMLDivElement>;
+ modalRef?: RefObject<HTMLDivElement | null>;
/**
* Gives access to the underlying form element of the modal. This is only set if `onSubmit` is provided.
*/
- formRef?: RefObject<HTMLFormElement>;
+ formRef?: RefObject<HTMLFormElement | null>;
bodyStyle?: CSSProperties;
/**
* Controls whether the modal is shown. Setting it to `true` will trigger the modal to be displayed to the user, whereas setting it to `false` will hide the modal.
diff --git a/apps/client/src/widgets/react/NoteAutocomplete.tsx b/apps/client/src/widgets/react/NoteAutocomplete.tsx
index 6bf49496da..fa6cf01858 100644
--- a/apps/client/src/widgets/react/NoteAutocomplete.tsx
+++ b/apps/client/src/widgets/react/NoteAutocomplete.tsx
@@ -35,7 +35,7 @@ const MENTION_NOTE_LIMIT = 10;
export interface NoteAutocompleteProps {
id?: string;
- inputRef?: RefObject<HTMLInputElement>;
+ inputRef?: RefObject<HTMLInputElement | null>;
text?: string;
placeholder?: string;
container?: RefObject<HTMLElement | null | undefined>;
@@ -54,7 +54,7 @@ export interface NoteAutocompleteProps {
/** Receives the functions that drive the field from outside it. */
handleRef?: MutableRef<NoteAutocompleteHandle | null>;
/** The element the list hangs from and spans, in place of the field, for a host that frames it. */
- anchorRef?: RefObject<HTMLElement>;
+ anchorRef?: RefObject<HTMLElement | null>;
/**
* Offers the searches in a footer under a list in the host's container, with the shortcut hints
* button, rather than as rows: for a host that scrolls the list in a box of its own, as Jump to
diff --git a/apps/client/src/widgets/react/OverlayControlGroup.spec.tsx b/apps/client/src/widgets/react/OverlayControlGroup.spec.tsx
index c3db90eed0..3bbefb7fa0 100644
--- a/apps/client/src/widgets/react/OverlayControlGroup.spec.tsx
+++ b/apps/client/src/widgets/react/OverlayControlGroup.spec.tsx
@@ -27,7 +27,8 @@ function mount(children: ComponentChildren) {
/** The tooltip config the hook was handed for the button bearing the given accessible name. */
function tooltipFor(label: string) {
const call = staticTooltipSpy.mock.calls.find(
- (args) => (args[0] as RefObject<HTMLElement>).current?.getAttribute("aria-label") === label
+ (args) => (args[0] as RefObject<HTMLElement | null>)
+ .current?.getAttribute("aria-label") === label
);
return call?.[1] as { title: string; placement: string } | undefined;
}
diff --git a/apps/client/src/widgets/react/OverlayPanel.tsx b/apps/client/src/widgets/react/OverlayPanel.tsx
index a017e48514..dfb4e1032c 100644
--- a/apps/client/src/widgets/react/OverlayPanel.tsx
+++ b/apps/client/src/widgets/react/OverlayPanel.tsx
@@ -12,7 +12,7 @@ interface OverlayPanelProps {
className?: string;
/** The panel's own element, for a caller that has something to do with it — marking it as where
* its component is found, say (see `useLegacyComponentElement`). */
- containerRef?: RefObject<HTMLDivElement>;
+ containerRef?: RefObject<HTMLDivElement | null>;
/**
* What heads the panel: a {@link TabStrip} where it is divided into tabs, or an
* {@link OverlayPanelTitle} where there is only the one thing to show.
diff --git a/apps/client/src/widgets/react/PasswordField.tsx b/apps/client/src/widgets/react/PasswordField.tsx
index ea55e0e7cc..e1abe42842 100644
--- a/apps/client/src/widgets/react/PasswordField.tsx
+++ b/apps/client/src/widgets/react/PasswordField.tsx
@@ -15,7 +15,9 @@ import OptionsRow from "../type_widgets/options/components/OptionsRow";
* overwrites what the browser autofilled, so the first press would submit an empty password — the
* "incorrect password, press again" bug. Neither screen needs live validation.
*/
-export default function PasswordField({ inputRef }: { inputRef: RefObject<HTMLInputElement> }) {
+export default function PasswordField({ inputRef }: {
+ inputRef: RefObject<HTMLInputElement | null>;
+}) {
return (
<OptionsRow name="password" label={t("login.password")} stacked>
<FormTextBox
diff --git a/apps/client/src/widgets/react/RawHtml.tsx b/apps/client/src/widgets/react/RawHtml.tsx
index 93e6ca94a9..36d3872354 100644
--- a/apps/client/src/widgets/react/RawHtml.tsx
+++ b/apps/client/src/widgets/react/RawHtml.tsx
@@ -14,11 +14,11 @@ interface RawHtmlProps extends Pick<HTMLProps<HTMLElement>, "tabindex" | "dir">
onClick?: (e: MouseEvent) => void;
}
-export default function RawHtml({containerRef, ...props}: RawHtmlProps & { containerRef?: RefObject<HTMLSpanElement>}) {
+export default function RawHtml({containerRef, ...props}: RawHtmlProps & { containerRef?: RefObject<HTMLSpanElement | null>}) {
return <span ref={containerRef} {...getProps(props)} />;
}
-export function RawHtmlBlock({containerRef, ...props}: RawHtmlProps & { containerRef?: RefObject<HTMLDivElement>}) {
+export function RawHtmlBlock({containerRef, ...props}: RawHtmlProps & { containerRef?: RefObject<HTMLDivElement | null>}) {
return <div ref={containerRef} {...getProps(props)} />;
}
diff --git a/apps/client/src/widgets/react/ShadowDom.tsx b/apps/client/src/widgets/react/ShadowDom.tsx
index 7b98aba75e..564d689edb 100644
--- a/apps/client/src/widgets/react/ShadowDom.tsx
+++ b/apps/client/src/widgets/react/ShadowDom.tsx
@@ -4,7 +4,7 @@ import { useSyncedRef } from "./hooks";
interface ShadowDomProps extends Omit<HTMLAttributes<HTMLDivElement>, "ref"> {
children: ComponentChildren;
- containerRef?: RefObject<HTMLDivElement>;
+ containerRef?: RefObject<HTMLDivElement | null>;
}
export default function ShadowDom({ children, containerRef: externalContainerRef, ...containerProps }: ShadowDomProps) {
diff --git a/apps/client/src/widgets/react/drag_pan.ts b/apps/client/src/widgets/react/drag_pan.ts
index 148f216ded..bac4614928 100644
--- a/apps/client/src/widgets/react/drag_pan.ts
+++ b/apps/client/src/widgets/react/drag_pan.ts
@@ -39,7 +39,7 @@ export interface DragPanState {
* @param ref the scrolling container.
* @param options which presses start a pan, and whether to offer it at all.
*/
-export function useDragPan(ref: RefObject<HTMLElement>, options: DragPanOptions = {}): DragPanState {
+export function useDragPan(ref: RefObject<HTMLElement | null>, options: DragPanOptions = {}): DragPanState {
const { canStart, disabled } = options;
const [ isPannable, setPannable ] = useState(false);
const [ isPanning, setPanning ] = useState(false);
diff --git a/apps/client/src/widgets/react/flip.ts b/apps/client/src/widgets/react/flip.ts
index 57a596dd14..99e495df20 100644
--- a/apps/client/src/widgets/react/flip.ts
+++ b/apps/client/src/widgets/react/flip.ts
@@ -57,7 +57,7 @@ export interface FlipOptions {
* `offsetParent` reports a different number for the same place.
*/
export function useFlip(
- ref: RefObject<HTMLElement>,
+ ref: RefObject<HTMLElement | null>,
{ selector, axis = "vertical", grow, disabled, paused }: FlipOptions
) {
// Written after every commit, so it holds where the children stood at the previous one.
diff --git a/apps/client/src/widgets/react/grows_upwards.ts b/apps/client/src/widgets/react/grows_upwards.ts
index 9780928957..1137216d4f 100644
--- a/apps/client/src/widgets/react/grows_upwards.ts
+++ b/apps/client/src/widgets/react/grows_upwards.ts
@@ -18,7 +18,7 @@ import { useLayoutEffect, useState } from "preact/hooks";
* each time rather than held — an element may be built and handed to its host before being put in
* the document at all, which is how Tabulator hands out its editors.
*/
-export function useGrowsUpwards(ref: RefObject<HTMLElement>) {
+export function useGrowsUpwards(ref: RefObject<HTMLElement | null>) {
const [ growsUpwards, setGrowsUpwards ] = useState(false);
useLayoutEffect(() => {
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index a3266c4124..d617df400b 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -948,7 +948,7 @@ export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, {
* @param ref a ref to a {@link HTMLElement} to determine the size and observe the changes in size.
* @returns the size of the element, reacting to changes.
*/
-export function useElementSize(ref: RefObject<HTMLElement>) {
+export function useElementSize(ref: RefObject<HTMLElement | null>) {
const [ size, setSize ] = useState<DOMRect | undefined>(ref.current?.getBoundingClientRect());
useEffect(() => {
@@ -993,7 +993,7 @@ export function useElementSize(ref: RefObject<HTMLElement>) {
* Watched only while `enabled`, and true whenever it is not: an element that is not being watched
* is taken as on screen, and watching starts from that until the observer says otherwise.
*/
-export function useIsOnScreen(ref: RefObject<Element>, enabled: boolean) {
+export function useIsOnScreen(ref: RefObject<Element | null>, enabled: boolean) {
const [ isOnScreen, setIsOnScreen ] = useState(true);
useEffect(() => {
@@ -1016,7 +1016,7 @@ export function useIsOnScreen(ref: RefObject<Element>, enabled: boolean) {
* Whether the focus is in the element, including in an `<iframe>` or a `<webview>` inside it,
* which the document reports as its `activeElement`. Switching to another window keeps the value.
*/
-export function useFocusWithin(ref: RefObject<HTMLElement>) {
+export function useFocusWithin(ref: RefObject<HTMLElement | null>) {
const [ isFocusWithin, setIsFocusWithin ] = useState(false);
useEffect(() => {
@@ -1154,7 +1154,11 @@ TooltipProto.dispose = function () {
* to put in front of the user — see {@link Dropdown}, which silences its toggle's title
* for as long as the menu that title opened is on screen.
*/
-export function useTooltip(elRef: RefObject<HTMLElement>, config: Partial<Tooltip.Options>, enabled = true) {
+export function useTooltip(
+ elRef: RefObject<HTMLElement | null>,
+ config: Partial<Tooltip.Options>,
+ enabled = true
+) {
const tooltipRef = useRef<Tooltip | null>(null);
useEffect(() => {
@@ -1240,7 +1244,10 @@ const tooltips = new Set<Tooltip>();
* @param elRef the element to bind the tooltip to.
* @param config optionally, the tooltip configuration.
*/
-export function useStaticTooltip(elRef: RefObject<Element>, config?: Partial<Tooltip.Options>) {
+export function useStaticTooltip(
+ elRef: RefObject<Element | null>,
+ config?: Partial<Tooltip.Options>
+) {
useEffect(() => {
const hasTooltip = config?.title || elRef.current?.getAttribute("title");
if (!elRef?.current || !hasTooltip) return;
@@ -1364,7 +1371,12 @@ export function useStaticTooltip(elRef: RefObject<Element>, config?: Partial<Too
}, [ elRef, config ]);
}
-export function useStaticTooltipWithKeyboardShortcut(elRef: RefObject<Element>, title: string, actionName: KeyboardActionNames | undefined, opts?: Omit<Partial<Tooltip.Options>, "title">) {
+export function useStaticTooltipWithKeyboardShortcut(
+ elRef: RefObject<Element | null>,
+ title: string,
+ actionName: KeyboardActionNames | undefined,
+ opts?: Omit<Partial<Tooltip.Options>, "title">
+) {
const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>();
useStaticTooltip(elRef, {
title: keyboardShortcut?.length ? `${title} (${keyboardShortcut?.join(",")})` : title,
@@ -1402,7 +1414,7 @@ export function useLegacyImperativeHandlers(handlers: Record<string, Function>)
* marks its own element (see `BasicWidget.render`), and a React tree mounted under one answers to
* that same widget, so the two already agree everywhere else.
*/
-export function useLegacyComponentElement(elRef: RefObject<HTMLElement>) {
+export function useLegacyComponentElement(elRef: RefObject<HTMLElement | null>) {
const parentComponent = useContext(ParentComponent);
useEffect(() => {
@@ -1488,7 +1500,7 @@ export function useContextualShortcutHints(hints: ShortcutHintDefinition | (() =
* hears the element arrive. Containers drawn only once their content has loaded are the ordinary
* case for that.
*/
-export function useTrackedElement<T extends HTMLElement>(ref: RefObject<T>): T | null {
+export function useTrackedElement<T extends HTMLElement>(ref: RefObject<T | null>): T | null {
const [ element, setElement ] = useState<T | null>(null);
// Every render, and set only where it changed, so this settles in one further pass.
@@ -1501,7 +1513,10 @@ export function useTrackedElement<T extends HTMLElement>(ref: RefObject<T>): T |
return element;
}
-export function useSyncedRef<T>(externalRef?: Ref<T>, initialValue: T | null = null): RefObject<T> {
+export function useSyncedRef<T>(
+ externalRef?: Ref<T>,
+ initialValue: T | null = null
+): RefObject<T | null> {
const ref = useRef<T>(initialValue);
useEffect(() => {
@@ -1758,7 +1773,7 @@ export function useLongPressContextMenu(handler: (e: MouseEvent) => void, holdMs
};
}
-export function useResizeObserver(ref: RefObject<HTMLElement>, callback: () => void) {
+export function useResizeObserver(ref: RefObject<HTMLElement | null>, callback: () => void) {
const resizeObserver = useRef<ResizeObserver>(null);
useEffect(() => {
resizeObserver.current?.disconnect();
@@ -1773,7 +1788,12 @@ export function useResizeObserver(ref: RefObject<HTMLElement>, callback: () => v
}, [ callback, ref ]);
}
-export function useKeyboardShortcuts(scope: "code-detail" | "text-detail", containerRef: RefObject<HTMLElement>, parentComponent: Component | undefined, ntxId: string | null | undefined) {
+export function useKeyboardShortcuts(
+ scope: "code-detail" | "text-detail",
+ containerRef: RefObject<HTMLElement | null>,
+ parentComponent: Component | undefined,
+ ntxId: string | null | undefined
+) {
useEffect(() => {
if (!parentComponent) return;
const $container = refToJQuerySelector(containerRef);
@@ -2241,7 +2261,7 @@ export function useColorScheme() {
* @param containerRef - Ref to the container element that may contain math elements
* @param deps - Dependencies that trigger re-rendering (e.g., text content)
*/
-export function useMathRendering(containerRef: RefObject<HTMLElement>, deps: unknown[]) {
+export function useMathRendering(containerRef: RefObject<HTMLElement | null>, deps: unknown[]) {
useEffect(() => {
if (!containerRef.current) return;
const mathElements = containerRef.current.querySelectorAll(".math-tex");
@@ -2295,7 +2315,7 @@ export function useMathRendering(containerRef: RefObject<HTMLElement>, deps: unk
* runs first) can opt out entirely via a `data-no-contained-navigation` attribute.
*/
export function useContainedLinkNavigation(
- containerRef: RefObject<HTMLElement>,
+ containerRef: RefObject<HTMLElement | null>,
onNavigate: (notePath: string, viewScope: ViewScope | undefined) => void
) {
useEffect(() => {
diff --git a/apps/client/src/widgets/react/master_detail.spec.tsx b/apps/client/src/widgets/react/master_detail.spec.tsx
index aac0fdf6a5..7870225168 100644
--- a/apps/client/src/widgets/react/master_detail.spec.tsx
+++ b/apps/client/src/widgets/react/master_detail.spec.tsx
@@ -24,7 +24,7 @@ vi.mock("./hooks", async (importOriginal) => ({
interface ModalStubProps {
header?: ComponentChildren;
children?: ComponentChildren;
- modalRef?: RefObject<HTMLDivElement>;
+ modalRef?: RefObject<HTMLDivElement | null>;
}
vi.mock("./Modal", () => ({
diff --git a/apps/client/src/widgets/react/master_detail.tsx b/apps/client/src/widgets/react/master_detail.tsx
index 197a5630f6..c93dd77768 100644
--- a/apps/client/src/widgets/react/master_detail.tsx
+++ b/apps/client/src/widgets/react/master_detail.tsx
@@ -41,7 +41,7 @@ export interface MobileMasterDetail {
* `mobile-view-{list,page}`, `mobile-transition-to-{list,page}`), which master_detail.css lays out and
* slides. The dialog's own stylesheet is left with whatever is particular to its panes.
*/
-export function useMobileMasterDetail(modalRef: RefObject<HTMLElement>): MobileMasterDetail {
+export function useMobileMasterDetail(modalRef: RefObject<HTMLElement | null>): MobileMasterDetail {
const [ mobileView, setMobileView ] = useState<"list" | "page">("list");
// Direction of the in-flight slide between the two views, or null when at rest. While set, both
// panes stay rendered so the outgoing one can slide away as the incoming one slides in.
diff --git a/apps/client/src/widgets/react/react_utils.tsx b/apps/client/src/widgets/react/react_utils.tsx
index 11a90e4cb7..751561f719 100644
--- a/apps/client/src/widgets/react/react_utils.tsx
+++ b/apps/client/src/widgets/react/react_utils.tsx
@@ -19,7 +19,9 @@ export const ContainerVisibilityContext = createContext(true);
* @param ref the React ref from which to obtain the jQuery selector.
* @returns the corresponding jQuery selector.
*/
-export function refToJQuerySelector<T extends HTMLElement>(ref: RefObject<T> | null): JQuery<T> {
+export function refToJQuerySelector<T extends HTMLElement>(
+ ref: RefObject<T | null> | null
+): JQuery<T> {
if (ref?.current) {
return $(ref.current);
} else {
diff --git a/apps/client/src/widgets/react/scroll_fade.ts b/apps/client/src/widgets/react/scroll_fade.ts
index 5b16d7925e..5613ced480 100644
--- a/apps/client/src/widgets/react/scroll_fade.ts
+++ b/apps/client/src/widgets/react/scroll_fade.ts
@@ -48,7 +48,7 @@ export interface ScrollFade {
* @param ref the scroll container.
* @param options which way it scrolls, how far each fade reaches and how long it takes.
*/
-export function useScrollFade(ref: RefObject<HTMLElement>, options: ScrollFadeOptions = {}): ScrollFade {
+export function useScrollFade(ref: RefObject<HTMLElement | null>, options: ScrollFadeOptions = {}): ScrollFade {
const {
direction = "vertical", size, duration, minOverflow = size ?? DEFAULT_FADE_SIZE
} = options;
diff --git a/apps/client/src/widgets/react/zoom_pan.ts b/apps/client/src/widgets/react/zoom_pan.ts
index eab5514db8..e8eeaf9f41 100644
--- a/apps/client/src/widgets/react/zoom_pan.ts
+++ b/apps/client/src/widgets/react/zoom_pan.ts
@@ -64,7 +64,7 @@ export function useZoomPanPinch({ minScale, maxScale, resetOn, onScaleChange }:
* With `isFocusRequired`, the wheel scrolls the page until `element` has focus or is fullscreen.
*/
export function useZoomPanWheel(
- apiRef: RefObject<ReactZoomPanPinchRef>,
+ apiRef: RefObject<ReactZoomPanPinchRef | null>,
element: HTMLElement | null,
isFocusRequired = false
) {
@@ -183,6 +183,6 @@ export function zoomToPointPosition(scale0: number, posX0: number, posY0: number
}
/** The instance's live scale. Read at click time rather than render time, so the step is current. */
-function currentScale(ref: RefObject<ReactZoomPanPinchRef>) {
+function currentScale(ref: RefObject<ReactZoomPanPinchRef | null>) {
return ref.current?.instance?.state?.scale ?? 1;
}
diff --git a/apps/client/src/widgets/ribbon/NoteActions.tsx b/apps/client/src/widgets/ribbon/NoteActions.tsx
index d064f50f6a..4b943dc043 100644
--- a/apps/client/src/widgets/ribbon/NoteActions.tsx
+++ b/apps/client/src/widgets/ribbon/NoteActions.tsx
@@ -71,7 +71,7 @@ export function NoteContextMenu({ note, noteContext, itemsAtStart, itemsNearNote
noteContext?: NoteContext,
itemsAtStart?: ComponentChildren;
itemsNearNoteSettings?: ComponentChildren;
- dropdownRef?: RefObject<DropdownHandle>;
+ dropdownRef?: RefObject<DropdownHandle | null>;
}) {
const dropdownRef = useSyncedRef<DropdownHandle>(externalDropdownRef, null);
const parentComponent = useContext(ParentComponent);
@@ -242,7 +242,7 @@ function CodeProperties({ note }: { note: FNote }) {
function NoteBasicProperties({ note, focus }: {
note: FNote;
- focus: RefObject<ItemToFocus>;
+ focus: RefObject<ItemToFocus | null>;
}) {
const itemToFocusRef = useRef<HTMLLIElement>(null);
const [ isBookmarked, setIsBookmarked ] = useNoteBookmarkState(note);
diff --git a/apps/client/src/widgets/sidebar/AttributeEditorOverlay.tsx b/apps/client/src/widgets/sidebar/AttributeEditorOverlay.tsx
index 87e3c20fc1..80d2748231 100644
--- a/apps/client/src/widgets/sidebar/AttributeEditorOverlay.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeEditorOverlay.tsx
@@ -9,7 +9,7 @@ import { useGrowsUpwards } from "../react/grows_upwards";
interface AttributeEditorOverlayProps {
/** The host's own ref to the overlay element, through which it reaches the fields within. */
- overlayRef: RefObject<HTMLSpanElement>;
+ overlayRef: RefObject<HTMLSpanElement | null>;
/** Names the host's kind of overlay, for the styles of its own it adds to the shell's. */
className?: string;
children: ComponentChildren;
diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
index c24750f0da..33536facfe 100644
--- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx
@@ -31,7 +31,7 @@ interface RightPanelWidgetProps {
title: string;
children: ComponentChildren;
buttons?: ComponentChildren;
- containerRef?: RefObject<HTMLDivElement>;
+ containerRef?: RefObject<HTMLDivElement | null>;
contextMenuItems?: MenuItem<unknown>[];
/**
* Take the height the other widgets of the tab leave over, scrolling the body within it, instead of
diff --git a/apps/client/src/widgets/type_widgets/canvas/Canvas.spec.tsx b/apps/client/src/widgets/type_widgets/canvas/Canvas.spec.tsx
index 84908243bd..1e29f5a25b 100644
--- a/apps/client/src/widgets/type_widgets/canvas/Canvas.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/Canvas.spec.tsx
@@ -26,7 +26,7 @@ const { CanvasEditor } = await import("./Canvas");
describe("CanvasEditor", () => {
let container: HTMLElement;
let refresh: ReturnType<typeof vi.fn>;
- let apiRef: RefObject<ExcalidrawImperativeAPI>;
+ let apiRef: RefObject<ExcalidrawImperativeAPI | null>;
/** The position of the container as Excalidraw last read it; happy-dom places it at 0, 0. */
let offsets: { offsetLeft: number; offsetTop: number };
diff --git a/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx b/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx
index e22ca6b3ee..7139d5f6d5 100644
--- a/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx
@@ -41,7 +41,7 @@ export default function Canvas({ note, noteContext }: TypeWidgetProps) {
}
export interface CanvasEditorProps {
- apiRef: RefObject<ExcalidrawImperativeAPI>;
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>;
isReadOnly: boolean;
colorScheme: AppState["theme"];
persistence: Partial<ExcalidrawProps>;
diff --git a/apps/client/src/widgets/type_widgets/canvas/CanvasDrawing.tsx b/apps/client/src/widgets/type_widgets/canvas/CanvasDrawing.tsx
index 5fabb11a63..0c0fbd65c4 100644
--- a/apps/client/src/widgets/type_widgets/canvas/CanvasDrawing.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/CanvasDrawing.tsx
@@ -166,8 +166,8 @@ function DetailDrawing({ attachment, note, noteContext, editor }: DetailDrawingP
* whether the drawing is hidden for it: from the start of the change until it is drawn centered.
*/
function useRecenteringOnFullscreen(
- rootRef: RefObject<HTMLElement>,
- apiRef: RefObject<ExcalidrawImperativeAPI>
+ rootRef: RefObject<HTMLElement | null>,
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>
) {
const [ isRecentering, setIsRecentering ] = useState(false);
const frameRef = useRef(0);
@@ -195,7 +195,7 @@ function useRecenteringOnFullscreen(
* Moves the focus into Excalidraw when the embed box around the drawing holds it. Excalidraw
* renders its container only once its language loads, which can be after the box took the focus.
*/
-function useFocusFromEmbedBox(rootRef: RefObject<HTMLElement>) {
+function useFocusFromEmbedBox(rootRef: RefObject<HTMLElement | null>) {
useEffect(() => {
const root = rootRef.current;
if (!root) return;
@@ -224,7 +224,7 @@ function useFocusFromEmbedBox(rootRef: RefObject<HTMLElement>) {
* Whether Excalidraw's toolbar reaches over the column of the properties panel, which then starts
* below the toolbar instead of at the top of the canvas.
*/
-export function useIsToolbarOverPanel(rootRef: RefObject<HTMLElement>) {
+export function useIsToolbarOverPanel(rootRef: RefObject<HTMLElement | null>) {
const [ isOver, setIsOver ] = useState(false);
useEffect(() => {
@@ -276,7 +276,7 @@ type Side = "left" | "right";
* focus, in the top layer so that no clip or stacking of the note covers them. A panel there has
* `data-side-panel`, and its position in `--side-panel-*`.
*/
-export function useSidePanels(rootRef: RefObject<HTMLElement>, isEnabled: boolean) {
+export function useSidePanels(rootRef: RefObject<HTMLElement | null>, isEnabled: boolean) {
useEffect(() => {
const root = rootRef.current;
const viewport = root?.closest<HTMLElement>(".scrolling-container");
@@ -494,8 +494,8 @@ export const FITTED_MENU_STYLES = [
* in the window instead of the drawing. Closes it when the note scrolls.
*/
export function useTopLayerContextMenu(
- rootRef: RefObject<HTMLElement>,
- apiRef: RefObject<ExcalidrawImperativeAPI>
+ rootRef: RefObject<HTMLElement | null>,
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>
) {
useEffect(() => {
const root = rootRef.current;
diff --git a/apps/client/src/widgets/type_widgets/canvas/CanvasDrawingMenu.tsx b/apps/client/src/widgets/type_widgets/canvas/CanvasDrawingMenu.tsx
index c57121a4bc..7bb2493d0b 100644
--- a/apps/client/src/widgets/type_widgets/canvas/CanvasDrawingMenu.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/CanvasDrawingMenu.tsx
@@ -9,7 +9,7 @@ import { useExcalidrawTranslation } from "./CanvasEmbedTools";
export const LIBRARY_SIDEBAR = "default";
interface CanvasDrawingMenuProps {
- apiRef: RefObject<ExcalidrawImperativeAPI>;
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>;
isEditable: boolean;
}
diff --git a/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx b/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx
index bbdd51512c..688e72dca7 100644
--- a/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/CanvasEmbedTools.tsx
@@ -90,8 +90,8 @@ const ICONS: Partial<Record<Tool | typeof LOCK, string>> = {
interface CanvasEmbedToolsProps {
/** The element of the drawing, inside the embed whose toolbar shows the tools. */
- rootRef: RefObject<HTMLElement>;
- apiRef: RefObject<ExcalidrawImperativeAPI>;
+ rootRef: RefObject<HTMLElement | null>;
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>;
/** Whether the Editable toggle of the embed is on. A read-only drawing offers the zoom only. */
isEditable: boolean;
}
@@ -146,7 +146,7 @@ export class CanvasTools implements ContentEmbedToolProvider {
/** The tools as last notified, to notify the listeners only when they change. */
private shownTools = "";
- constructor(private readonly rootRef: RefObject<HTMLElement>) {}
+ constructor(private readonly rootRef: RefObject<HTMLElement | null>) {}
/** Follows `api` and its undo and redo buttons, until the returned function is called. */
connect(api: ExcalidrawImperativeAPI) {
diff --git a/apps/client/src/widgets/type_widgets/canvas/persistence.spec.tsx b/apps/client/src/widgets/type_widgets/canvas/persistence.spec.tsx
index 8cab928c3a..e5addf59d2 100644
--- a/apps/client/src/widgets/type_widgets/canvas/persistence.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/persistence.spec.tsx
@@ -43,7 +43,10 @@ type PersistenceProps = ReturnType<typeof useCanvasPersistence>;
let props: PersistenceProps | undefined;
-function Probe({ note, apiRef }: { note: FNote; apiRef: RefObject<ExcalidrawImperativeAPI> }) {
+function Probe({ note, apiRef }: {
+ note: FNote;
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>;
+}) {
props = useCanvasPersistence(note, null, apiRef, "light", false);
return null;
}
@@ -104,7 +107,7 @@ describe("useCanvasPersistence content loading (#10279)", () => {
vi.useRealTimers();
});
- async function mount(note: FNote, apiRef: RefObject<ExcalidrawImperativeAPI>) {
+ async function mount(note: FNote, apiRef: RefObject<ExcalidrawImperativeAPI | null>) {
await act(async () => {
render(<Probe note={note} apiRef={apiRef} />, container);
});
@@ -116,7 +119,7 @@ describe("useCanvasPersistence content loading (#10279)", () => {
it("routes the first content through initialData, never through updateScene", async () => {
const { note } = buildCanvasNote([ "a1", "a2" ]);
const { api, updateScene } = buildApi(() => []);
- const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI>;
+ const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI | null>;
await mount(note, apiRef);
@@ -130,7 +133,7 @@ describe("useCanvasPersistence content loading (#10279)", () => {
const { note, elements } = buildCanvasNote([ "a1", "a2" ]);
let sceneElements: FakeElement[] = [];
const { api } = buildApi(() => sceneElements);
- const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI>;
+ const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI | null>;
await mount(note, apiRef);
await resolvedInitialData();
@@ -168,7 +171,7 @@ describe("useCanvasPersistence content loading (#10279)", () => {
const { note: noteA } = buildCanvasNote([ "a1" ]);
const { note: noteB } = buildCanvasNote([ "b1" ]);
const { api, updateScene } = buildApi(() => []);
- const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI>;
+ const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI | null>;
await mount(noteA, apiRef);
await resolvedInitialData();
@@ -186,7 +189,7 @@ describe("useCanvasPersistence content loading (#10279)", () => {
const { note: noteA } = buildCanvasNote([ "a1" ]);
const { note: noteB } = buildCanvasNote([ "b1" ]);
const { api, updateScene } = buildApi(() => []);
- const apiRef = { current: null } as RefObject<ExcalidrawImperativeAPI>;
+ const apiRef = { current: null } as RefObject<ExcalidrawImperativeAPI | null>;
await mount(noteA, apiRef);
await resolvedInitialData();
@@ -215,7 +218,7 @@ describe("useCanvasDrawingPersistence", () => {
function DrawingProbe({ attachment, editor, apiRef }: {
attachment: FAttachment;
editor: AttachmentEditor | undefined;
- apiRef: RefObject<ExcalidrawImperativeAPI>;
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>;
}) {
drawingProps = useCanvasDrawingPersistence(attachment, editor, apiRef, "light");
return null;
@@ -257,7 +260,7 @@ describe("useCanvasDrawingPersistence", () => {
getAppState: () => appState,
getFiles: () => ({ f1: IMAGE, f2: UNUSED_IMAGE })
} as unknown as ExcalidrawImperativeAPI;
- const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI>;
+ const apiRef = { current: api } as RefObject<ExcalidrawImperativeAPI | null>;
await act(async () => {
render(
<DrawingProbe attachment={attachment} editor={editor} apiRef={apiRef} />,
diff --git a/apps/client/src/widgets/type_widgets/canvas/persistence.ts b/apps/client/src/widgets/type_widgets/canvas/persistence.ts
index ce87f24754..01513f9ae5 100644
--- a/apps/client/src/widgets/type_widgets/canvas/persistence.ts
+++ b/apps/client/src/widgets/type_widgets/canvas/persistence.ts
@@ -27,7 +27,7 @@ export interface CanvasContent {
/** Subset of the app state that should be persisted whenever they change. This explicitly excludes transient state like the current selection or zoom level. */
type ImportantAppState = Pick<AppState, "gridModeEnabled" | "viewBackgroundColor">;
-export default function useCanvasPersistence(note: FNote, noteContext: NoteContext | null | undefined, apiRef: RefObject<ExcalidrawImperativeAPI>, theme: AppState["theme"], isReadOnly: boolean): Partial<ExcalidrawProps> {
+export default function useCanvasPersistence(note: FNote, noteContext: NoteContext | null | undefined, apiRef: RefObject<ExcalidrawImperativeAPI | null>, theme: AppState["theme"], isReadOnly: boolean): Partial<ExcalidrawProps> {
const libraryChanged = useRef(false);
/**
@@ -350,7 +350,7 @@ export default function useCanvasPersistence(note: FNote, noteContext: NoteConte
export function useCanvasDrawingPersistence(
attachment: FAttachment,
editor: AttachmentEditor | undefined,
- apiRef: RefObject<ExcalidrawImperativeAPI>,
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>,
theme: AppState["theme"]
): Partial<ExcalidrawProps> {
const currentSceneVersion = useRef(0);
@@ -445,7 +445,7 @@ export function parseContent(newContent: string, entity: FNote | FAttachment): C
return content;
}
-async function getData(api: ExcalidrawImperativeAPI, appStateToCompare: RefObject<Partial<ImportantAppState>>) {
+async function getData(api: ExcalidrawImperativeAPI, appStateToCompare: RefObject<Partial<ImportantAppState> | null>) {
const elements = api.getSceneElements();
const appState = api.getAppState();
diff --git a/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.spec.tsx b/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.spec.tsx
index c06bca6ae7..84f4d635c4 100644
--- a/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.spec.tsx
@@ -18,7 +18,10 @@ type Handlers = ReturnType<typeof useCanvasNoteDrop>;
let handlers: Handlers | undefined;
-function Probe({ apiRef, isReadOnly }: { apiRef: RefObject<ExcalidrawImperativeAPI>; isReadOnly: boolean }) {
+function Probe({ apiRef, isReadOnly }: {
+ apiRef: RefObject<ExcalidrawImperativeAPI | null>;
+ isReadOnly: boolean;
+}) {
handlers = useCanvasNoteDrop(apiRef, isReadOnly);
return null;
}
@@ -49,8 +52,11 @@ describe("useCanvasNoteDrop", () => {
container.remove();
});
- async function mountHook(isReadOnly: boolean, apiRef?: RefObject<ExcalidrawImperativeAPI>) {
- const ref = apiRef ?? ({ current: api } as RefObject<ExcalidrawImperativeAPI>);
+ async function mountHook(
+ isReadOnly: boolean,
+ apiRef?: RefObject<ExcalidrawImperativeAPI | null>
+ ) {
+ const ref = apiRef ?? ({ current: api } as RefObject<ExcalidrawImperativeAPI | null>);
await act(async () => {
render(<Probe apiRef={ref} isReadOnly={isReadOnly} />, container);
});
@@ -126,7 +132,7 @@ describe("useCanvasNoteDrop", () => {
});
it("does nothing when the Excalidraw API is not ready", async () => {
- await mountHook(false, { current: null } as RefObject<ExcalidrawImperativeAPI>);
+ await mountHook(false, { current: null } as RefObject<ExcalidrawImperativeAPI | null>);
const e = dragEvent({ payload: JSON.stringify([{ noteId: "aaa" }]) });
handlers?.onDropCapture(e as never);
expect(e.preventDefault).not.toHaveBeenCalled();
diff --git a/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts b/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts
index b3a659d511..54ccd29672 100644
--- a/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts
+++ b/apps/client/src/widgets/type_widgets/canvas/useCanvasNoteDrop.ts
@@ -23,7 +23,7 @@ const STACK_OFFSET = 24;
* payload is readable: a recognized note payload is handled here and kept from Excalidraw, while any
* other `text/plain` drop falls through to Excalidraw's own handling.
*/
-export default function useCanvasNoteDrop(apiRef: RefObject<ExcalidrawImperativeAPI>, isReadOnly: boolean) {
+export default function useCanvasNoteDrop(apiRef: RefObject<ExcalidrawImperativeAPI | null>, isReadOnly: boolean) {
const onDragOverCapture = useCallback((e: JSX.TargetedDragEvent<HTMLElement>) => {
if (isReadOnly || !e.dataTransfer?.types.includes("text/plain")) {
return;
diff --git a/apps/client/src/widgets/type_widgets/file/AudioVisualizer.tsx b/apps/client/src/widgets/type_widgets/file/AudioVisualizer.tsx
index 3d46d156a4..b4195c42b1 100644
--- a/apps/client/src/widgets/type_widgets/file/AudioVisualizer.tsx
+++ b/apps/client/src/widgets/type_widgets/file/AudioVisualizer.tsx
@@ -29,7 +29,7 @@ const DEFAULT_HIGH_COLOR = "rgb(136, 136, 136)";
* lights up from the bottom and each cell takes a single colour from a low→high vertical gradient. Runs an rAF
* loop only while playing (and briefly after, to animate the decay); when not playing every column rests at zero.
*/
-export function AudioVisualizer({ mediaRef, isPlaying, compact }: { mediaRef: RefObject<HTMLAudioElement>; isPlaying: boolean; compact?: boolean }) {
+export function AudioVisualizer({ mediaRef, isPlaying, compact }: { mediaRef: RefObject<HTMLAudioElement | null>; isPlaying: boolean; compact?: boolean }) {
const cellSize = compact ? CELL_SIZE * COMPACT_SCALE : CELL_SIZE;
const cellGap = compact ? CELL_GAP * COMPACT_SCALE : CELL_GAP;
const canvasRef = useRef<HTMLCanvasElement>(null);
diff --git a/apps/client/src/widgets/type_widgets/file/MediaPlayer.spec.tsx b/apps/client/src/widgets/type_widgets/file/MediaPlayer.spec.tsx
index 7b39dcdf6b..72d48c4e03 100644
--- a/apps/client/src/widgets/type_widgets/file/MediaPlayer.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/file/MediaPlayer.spec.tsx
@@ -51,7 +51,7 @@ function fakeMedia({ duration = 100, currentTime = 0 } = {}) {
const media = document.createElement("audio");
Object.defineProperty(media, "duration", { value: duration, writable: true, configurable: true });
media.currentTime = currentTime;
- return { current: media } as RefObject<HTMLAudioElement>;
+ return { current: media } as RefObject<HTMLAudioElement | null>;
}
const click = (el: Element | null | undefined) =>
@@ -358,7 +358,7 @@ describe("useMediaPlayMode", () => {
async function renderHook({ notePath, playlistNoteId, mediaRef = fakeMedia() }: {
notePath?: string;
playlistNoteId?: string;
- mediaRef?: RefObject<HTMLAudioElement>;
+ mediaRef?: RefObject<HTMLAudioElement | null>;
}) {
const noteContext = { notePath } as NoteContext;
diff --git a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
index deac90e882..b872760b75 100644
--- a/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
+++ b/apps/client/src/widgets/type_widgets/file/MediaPlayer.tsx
@@ -95,7 +95,7 @@ export function claimsKeystroke(e: KeyboardEvent): boolean {
return isMinuteJump && e.ctrlKey && !e.altKey && !e.metaKey;
}
-export function SeekBar({ mediaRef }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement> }) {
+export function SeekBar({ mediaRef }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null> }) {
const [currentTime, setCurrentTime] = useState(0);
const [duration, setDuration] = useState(0);
@@ -164,7 +164,7 @@ export function PlayPauseButton({ playing, togglePlayback }: {
);
}
-export function VolumeControl({ mediaRef }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement> }) {
+export function VolumeControl({ mediaRef }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null> }) {
const [volume, setVolume] = useState(() => mediaRef.current?.volume ?? 1);
const [muted, setMuted] = useState(() => mediaRef.current?.muted ?? false);
@@ -261,7 +261,7 @@ const OWNED_MEDIA_ACTIONS: MediaSessionAction[] = [ "previoustrack", "nexttrack"
*/
export function useMediaSessionController({ source, entity, noteContext, ownerNote, viewScope, mimePrefix, mediaRef, isVisible = true, playMode, autoPlay }: MediaPlayerProps & {
mimePrefix: string;
- mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>;
+ mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null>;
playMode: MediaPlayMode;
}) {
// A note cycles the playable siblings in its folder; an attachment cycles the owner note's playable
@@ -480,18 +480,18 @@ function setActiveMediaPlayer(player: object | null) {
for (const notify of mediaPlayerSubscribers) notify();
}
-function seekBy(mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>, offset: number) {
+function seekBy(mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null>, offset: number) {
const media = mediaRef.current;
// duration is NaN until metadata loads; setting currentTime to NaN throws.
if (media && Number.isFinite(media.duration)) media.currentTime = Math.max(0, Math.min(media.duration, media.currentTime + offset));
}
-function seekTo(mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>, time: number) {
+function seekTo(mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null>, time: number) {
const media = mediaRef.current;
if (media && Number.isFinite(time)) media.currentTime = time;
}
-function stopMedia(mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>) {
+function stopMedia(mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null>) {
const media = mediaRef.current;
if (!media) return;
media.pause();
@@ -511,7 +511,7 @@ export function MediaSiblingButton({ navigation, direction, tooltipI18nKey }: {
);
}
-export function SkipButton({ mediaRef, seconds, icon, text }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>, seconds: number, icon: string, text: string }) {
+export function SkipButton({ mediaRef, seconds, icon, text }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null>, seconds: number, icon: string, text: string }) {
const skip = () => {
const media = mediaRef.current;
if (!media) return;
@@ -530,7 +530,7 @@ export function SkipButton({ mediaRef, seconds, icon, text }: { mediaRef: RefObj
* mode and persists changes back there; the `next` mode's actual auto-advance is handled by
* {@link useMediaSessionController} (which receives the resolved `mode`).
*/
-export function useMediaPlayMode(noteContext: NoteContext | undefined, mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>, playlistNoteId?: string): { mode: MediaPlayMode; setMode: (mode: MediaPlayMode) => void } {
+export function useMediaPlayMode(noteContext: NoteContext | undefined, mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null>, playlistNoteId?: string): { mode: MediaPlayMode; setMode: (mode: MediaPlayMode) => void } {
const parentNoteId = playlistNoteId ?? getParentFromNotePath(noteContext?.notePath)?.parentNoteId;
const [ mode, setLocalMode ] = useState<MediaPlayMode>("once");
const [ refreshCounter, setRefreshCounter ] = useState(0);
@@ -612,7 +612,7 @@ export function PlayModeButton({ mode, onSelectMode }: { mode: MediaPlayMode, on
const PLAYBACK_SPEEDS = [0.5, 1, 1.25, 1.5, 2];
-export function PlaybackSpeed({ mediaRef }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement> }) {
+export function PlaybackSpeed({ mediaRef }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null> }) {
const [speed, setSpeed] = useState(() => mediaRef.current?.playbackRate ?? 1);
useEffect(() => {
diff --git a/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx b/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx
index 68967f413f..697ad4273a 100644
--- a/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx
+++ b/apps/client/src/widgets/type_widgets/file/PdfViewer.tsx
@@ -15,7 +15,7 @@ const FONTS: FontDefinition[] = [
];
interface PdfViewerProps extends Pick<HTMLAttributes<HTMLIFrameElement>, "tabIndex"> {
- iframeRef?: RefObject<HTMLIFrameElement>;
+ iframeRef?: RefObject<HTMLIFrameElement | null>;
/** Relative URLs resolve against /pdfjs/web; build API paths with {@link getPdfUrl} instead. */
pdfUrl: string;
onLoad?(): void;
@@ -69,7 +69,10 @@ function getAddressParams(noteId: string, ntxId: string | null | undefined) {
return `&noteId=${encodeURIComponent(noteId)}${ntxId ? `&ntxId=${encodeURIComponent(ntxId)}` : ""}`;
}
-function useStyleInjection(iframeRef: RefObject<HTMLIFrameElement>, disableSelection?: boolean) {
+function useStyleInjection(
+ iframeRef: RefObject<HTMLIFrameElement | null>,
+ disableSelection?: boolean
+) {
const styleRef = useRef<HTMLStyleElement | null>(null);
// First load.
diff --git a/apps/client/src/widgets/type_widgets/file/Video.tsx b/apps/client/src/widgets/type_widgets/file/Video.tsx
index 2300fa129a..f43a2dedd9 100644
--- a/apps/client/src/widgets/type_widgets/file/Video.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Video.tsx
@@ -198,7 +198,7 @@ function useKeyboardShortcuts(videoRef: MutableRef<HTMLVideoElement | null>, wra
}, [ wrapperRef, videoRef, togglePlayback, flashControls ]);
}
-function useAutoHideControls(videoRef: RefObject<HTMLVideoElement>, playing: boolean) {
+function useAutoHideControls(videoRef: RefObject<HTMLVideoElement | null>, playing: boolean) {
const [visible, setVisible] = useState(true);
const hideTimerRef = useRef<ReturnType<typeof setTimeout>>();
@@ -239,7 +239,7 @@ function useAutoHideControls(videoRef: RefObject<HTMLVideoElement>, playing: boo
return { visible, flash: reveal, toggle };
}
-function RotateButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement> }) {
+function RotateButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement | null> }) {
const [rotation, setRotation] = useState(0);
const rotate = () => {
@@ -272,7 +272,7 @@ function RotateButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement> }) {
);
}
-function ZoomToFitButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement> }) {
+function ZoomToFitButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement | null> }) {
const [fitted, setFitted] = useState(false);
const toggle = () => {
@@ -293,7 +293,7 @@ function ZoomToFitButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement> }
);
}
-function PictureInPictureButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement> }) {
+function PictureInPictureButton({ videoRef }: { videoRef: RefObject<HTMLVideoElement | null> }) {
const [active, setActive] = useState(false);
// The standard PiP API is only supported in Chromium-based browsers.
// Firefox uses its own proprietary PiP implementation.
@@ -336,7 +336,7 @@ function PictureInPictureButton({ videoRef }: { videoRef: RefObject<HTMLVideoEle
);
}
-function FullscreenButton({ targetRef }: { targetRef: RefObject<HTMLElement> }) {
+function FullscreenButton({ targetRef }: { targetRef: RefObject<HTMLElement | null> }) {
// `useFullscreen` follows an element rather than a ref, a ref being filled after the render that
// asked for it and causing none of its own — so the wrapper is put into state once it is there.
const [ target, setTarget ] = useState<HTMLElement | null>(null);
diff --git a/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.spec.tsx b/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.spec.tsx
index bc26dff412..d1144f0fd1 100644
--- a/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.spec.tsx
@@ -24,7 +24,7 @@ describe("WaveformSeekBar", () => {
const media = document.createElement("audio");
Object.defineProperty(media, "duration", { value: duration, writable: true, configurable: true });
media.currentTime = currentTime;
- return { current: media } as RefObject<HTMLAudioElement>;
+ return { current: media } as RefObject<HTMLAudioElement | null>;
}
function renderSeekBar(mediaRef = fakeMedia(), peaks: number[] | null = null) {
diff --git a/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.tsx b/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.tsx
index 36b5b399f1..a5ac9711e1 100644
--- a/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.tsx
+++ b/apps/client/src/widgets/type_widgets/file/WaveformSeekBar.tsx
@@ -26,7 +26,7 @@ const KEYBOARD_STEP = 0.05;
* placeholder band; when {@link peaks} arrives the bars animate from flat to their real heights. Scrubbing works
* throughout (it only needs the media element's duration), by mouse, touch (Pointer Events), or keyboard.
*/
-export function WaveformSeekBar({ mediaRef, peaks }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement>; peaks: number[] | null }) {
+export function WaveformSeekBar({ mediaRef, peaks }: { mediaRef: RefObject<HTMLVideoElement | HTMLAudioElement | null>; peaks: number[] | null }) {
const canvasRef = useRef<HTMLCanvasElement>(null);
const [currentTime, setCurrentTime] = useState(0);
const [duration, setDuration] = useState(0);
diff --git a/apps/client/src/widgets/type_widgets/file/useAudioAnalyser.ts b/apps/client/src/widgets/type_widgets/file/useAudioAnalyser.ts
index c0d23912cf..ae2829ef7b 100644
--- a/apps/client/src/widgets/type_widgets/file/useAudioAnalyser.ts
+++ b/apps/client/src/widgets/type_widgets/file/useAudioAnalyser.ts
@@ -26,7 +26,9 @@ const SMOOTHING = 0.8;
* Caveat: once tapped, the element's audio flows through the AudioContext. On the desktop custom protocol the
* element is cross-origin, so the tap is blocked (tainted) — audio still plays, the spectrum just reads zero.
*/
-export function useAudioAnalyser(mediaRef: RefObject<HTMLMediaElement>): () => Uint8Array | null {
+export function useAudioAnalyser(
+ mediaRef: RefObject<HTMLMediaElement | null>
+): () => Uint8Array | null {
useEffect(() => {
const media = mediaRef.current;
if (!media) return;
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/chat_message_jump.ts b/apps/client/src/widgets/type_widgets/llm_chat/chat_message_jump.ts
index ce064a8a0e..e921095d1e 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/chat_message_jump.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/chat_message_jump.ts
@@ -14,7 +14,7 @@ const FLASH_DURATION_MS = 1200;
* message, so there's no per-message wiring. A missing target (the referenced message was deleted or
* regenerated) is a graceful no-op — mirroring how highlights drop orphaned anchors.
*/
-export function useChatMessageJumps(scrollContainerRef: RefObject<HTMLElement>) {
+export function useChatMessageJumps(scrollContainerRef: RefObject<HTMLElement | null>) {
useEffect(() => {
const container = scrollContainerRef.current;
if (!container) return;
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts b/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts
index aafa4d7208..6d96eb19d6 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/useChatAttachments.ts
@@ -121,7 +121,7 @@ async function uploadFileAsAttachment(noteId: string, file: File, kind: UploadKi
export interface UseChatAttachmentsReturn {
/** Ref to plug into the hidden `<input type="file">`. */
- fileInputRef: RefObject<HTMLInputElement>;
+ fileInputRef: RefObject<HTMLInputElement | null>;
/** Value for the `accept` attribute of the hidden file input. */
acceptAttr: string;
/**
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
index 4428605cdd..4017d4f5d1 100644
--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts
@@ -122,10 +122,10 @@ export interface UseLlmChatReturn {
lastCompletionTokens: number;
/** Coarse estimate of the unsent draft, quantized so typing rarely re-renders. */
draftTokens: number;
- messagesEndRef: RefObject<HTMLDivElement>;
- scrollContainerRef: RefObject<HTMLDivElement>;
+ messagesEndRef: RefObject<HTMLDivElement | null>;
+ scrollContainerRef: RefObject<HTMLDivElement | null>;
/** Trailing spacer below the last message; sized so the active turn can park near the top. */
- bottomSpacerRef: RefObject<HTMLDivElement>;
+ bottomSpacerRef: RefObject<HTMLDivElement | null>;
/** Whether the timeline is scrolled away from the bottom (drives the jump-to-bottom button). */
showScrollToBottom: boolean;
/** Jump the timeline to the latest content. */
diff --git a/apps/client/src/widgets/type_widgets/mind_map/MindMap.tsx b/apps/client/src/widgets/type_widgets/mind_map/MindMap.tsx
index d907cc8756..d5e76745c4 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/MindMap.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/MindMap.tsx
@@ -68,7 +68,7 @@ function sanitizeMindMapNode(value: unknown): void {
}
interface MindElixirProps {
- apiRef?: RefObject<MindElixirInstance>;
+ apiRef?: RefObject<MindElixirInstance | null>;
/**
* Rendered in an overlay on top of the map, outside of the DOM managed by Mind Elixir, and given
* the instance it stands over. Asked for rather than handed in, the instance being built after
@@ -77,7 +77,7 @@ interface MindElixirProps {
*/
children?: (mind: MindElixirInstance) => ComponentChildren;
containerProps?: Omit<HTMLAttributes<HTMLDivElement>, "ref">;
- containerRef?: RefObject<HTMLDivElement>;
+ containerRef?: RefObject<HTMLDivElement | null>;
editable: boolean;
onChange?: () => void;
onSelectionChange?: (selectedNodes: NodeObj[]) => void;
diff --git a/apps/client/src/widgets/type_widgets/options/components/SettingsSearch.tsx b/apps/client/src/widgets/type_widgets/options/components/SettingsSearch.tsx
index b5b687c411..2740a17582 100644
--- a/apps/client/src/widgets/type_widgets/options/components/SettingsSearch.tsx
+++ b/apps/client/src/widgets/type_widgets/options/components/SettingsSearch.tsx
@@ -14,7 +14,7 @@ interface SettingsSearchProps {
onFocus?(): void;
/** What the field looks through, where that is something other than the settings. */
placeholder?: string;
- inputRef?: RefObject<HTMLInputElement>;
+ inputRef?: RefObject<HTMLInputElement | null>;
}
/**
diff --git a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
index 59ed7c52be..fb9660875e 100644
--- a/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
+++ b/apps/client/src/widgets/type_widgets/options/shortcuts.tsx
@@ -595,7 +595,7 @@ export function ShortcutRecorder({ onCapture }: { onCapture: (shortcut: string)
* class so the tooltip renders above the options modal, and a focus trigger on mobile where hover
* is unavailable.
*/
-function useShortcutTooltip(elRef: RefObject<Element>, title: string) {
+function useShortcutTooltip(elRef: RefObject<Element | null>, title: string) {
useStaticTooltip(elRef, {
title,
placement: "top",
diff --git a/apps/client/src/widgets/type_widgets/options/totp.tsx b/apps/client/src/widgets/type_widgets/options/totp.tsx
index 5771295ba8..0223e68b5d 100644
--- a/apps/client/src/widgets/type_widgets/options/totp.tsx
+++ b/apps/client/src/widgets/type_widgets/options/totp.tsx
@@ -324,7 +324,7 @@ function TotpVerifyStep({ secret, secretUrl, code, setCode, codeRejected, codeRe
code: string,
setCode: (value: string) => void,
codeRejected: boolean,
- codeRef: RefObject<HTMLInputElement>
+ codeRef: RefObject<HTMLInputElement | null>
}) {
return (
<>
diff --git a/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx b/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx
index fa65926d08..efb566a4e2 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/NoteBox.tsx
@@ -27,7 +27,7 @@ const NOTE_BOX_TARGET_CONFIG = {
};
interface NoteBoxProps extends MapDataNoteEntry {
- mapApiRef: RefObject<RelationMapApi>;
+ mapApiRef: RefObject<RelationMapApi | null>;
}
export function NoteBox({ noteId, x, y, mapApiRef }: NoteBoxProps) {
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
index 17752143ac..ee27497f28 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
@@ -198,7 +198,7 @@ export default function RelationMap({ note, noteContext, ntxId, parentComponent
*/
function usePanZoom({ ntxId, containerRef, options, transformData, onTransform }: {
ntxId: string | null | undefined;
- containerRef: RefObject<HTMLDivElement>;
+ containerRef: RefObject<HTMLDivElement | null>;
options: PanZoomOptions;
transformData: MapData["transform"] | undefined;
onTransform: (pzInstance: PanZoom) => void
@@ -248,7 +248,7 @@ function usePanZoom({ ntxId, containerRef, options, transformData, onTransform }
return panZoom;
}
-async function useRelationData(noteId: string, mapData: MapData | undefined, mapApiRef: RefObject<RelationMapApi>, jsPlumbRef: RefObject<jsPlumbInstance>) {
+async function useRelationData(noteId: string, mapData: MapData | undefined, mapApiRef: RefObject<RelationMapApi | null>, jsPlumbRef: RefObject<jsPlumbInstance | null>) {
const noteIds = mapData?.notes.map((note) => note.noteId);
const [ relations, setRelations ] = useState<ClientRelation[]>();
const [ inverseRelations, setInverseRelations ] = useState<RelationMapPostResponse["inverseRelations"]>();
@@ -336,8 +336,8 @@ async function useRelationData(noteId: string, mapData: MapData | undefined, map
function useNoteCreation({ ntxId, note, containerRef, mapApiRef }: {
ntxId: string | null | undefined;
note: FNote;
- containerRef: RefObject<HTMLDivElement>;
- mapApiRef: RefObject<RelationMapApi>;
+ containerRef: RefObject<HTMLDivElement | null>;
+ mapApiRef: RefObject<RelationMapApi | null>;
}) {
const clipboardRef = useRef<Clipboard>(null);
useTriliumEvent("relationMapCreateChildNote", async ({ ntxId: eventNtxId }) => {
@@ -375,8 +375,8 @@ function useNoteCreation({ ntxId, note, containerRef, mapApiRef }: {
}
function useNoteDragging({ containerRef, mapApiRef }: {
- containerRef: RefObject<HTMLDivElement>;
- mapApiRef: RefObject<RelationMapApi>;
+ containerRef: RefObject<HTMLDivElement | null>;
+ mapApiRef: RefObject<RelationMapApi | null>;
}): Pick<HTMLProps<HTMLDivElement>, "onDrop" | "onDragOver"> {
const dragProps = useMemo(() => ({
onDrop(ev: DragEvent) {
@@ -415,8 +415,8 @@ function useNoteDragging({ containerRef, mapApiRef }: {
}
function useRelationCreation({ mapApiRef, jsPlumbApiRef, askRelationName }: {
- mapApiRef: RefObject<RelationMapApi>,
- jsPlumbApiRef: RefObject<jsPlumbInstance>,
+ mapApiRef: RefObject<RelationMapApi | null>,
+ jsPlumbApiRef: RefObject<jsPlumbInstance | null>,
askRelationName: AskRelationName
}) {
const connectionCallback = useCallback(async (info: OnConnectionBindInfo, originalEvent: Event) => {
diff --git a/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts b/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts
index 09e8146640..5bbf1891a2 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts
+++ b/apps/client/src/widgets/type_widgets/relation_map/context_menu.ts
@@ -12,7 +12,7 @@ import server from "../../../services/server";
import RelationMapApi from "./api";
import type { AskRelationName } from "./RelationNamePopover";
-export function buildNoteContextMenuHandler(note: FNote | null | undefined, mapApiRef: RefObject<RelationMapApi>) {
+export function buildNoteContextMenuHandler(note: FNote | null | undefined, mapApiRef: RefObject<RelationMapApi | null>) {
return (e: MouseEvent) => {
if (!note) return;
e.preventDefault();
@@ -69,7 +69,7 @@ export function buildNoteContextMenuHandler(note: FNote | null | undefined, mapA
};
}
-export function buildRelationContextMenuHandler(connection: Connection, mapApiRef: RefObject<RelationMapApi>, askRelationName: AskRelationName) {
+export function buildRelationContextMenuHandler(connection: Connection, mapApiRef: RefObject<RelationMapApi | null>, askRelationName: AskRelationName) {
return (_, event: MouseEvent) => {
if (connection.getType().includes("link")) {
// don't create context menu if it's a link since there's nothing to do with link from relation map
diff --git a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx
index ef531e9113..94cd944f1f 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/jsplumb.tsx
@@ -3,14 +3,14 @@ import { ComponentChildren, createContext, RefObject } from "preact";
import { HTMLProps } from "preact/compat";
import { useContext, useEffect, useRef } from "preact/hooks";
-const JsPlumbInstance = createContext<RefObject<jsPlumbInstance> | undefined>(undefined);
+const JsPlumbInstance = createContext<RefObject<jsPlumbInstance | null> | undefined>(undefined);
export function JsPlumb({ className, props, children, containerRef: externalContainerRef, apiRef, onInstanceCreated, onConnection }: {
className?: string;
props: Omit<Defaults, "container">;
children: ComponentChildren;
- containerRef?: RefObject<HTMLElement>;
- apiRef?: RefObject<jsPlumbInstance>;
+ containerRef?: RefObject<HTMLElement | null>;
+ apiRef?: RefObject<jsPlumbInstance | null>;
onInstanceCreated?: (jsPlumbInstance: jsPlumbInstance) => void;
onConnection?: (info: OnConnectionBindInfo, originalEvent: Event) => void;
}) {
diff --git a/apps/client/src/widgets/type_widgets/space_usage/selection.tsx b/apps/client/src/widgets/type_widgets/space_usage/selection.tsx
index 2c4d087b0b..b6837b83cf 100644
--- a/apps/client/src/widgets/type_widgets/space_usage/selection.tsx
+++ b/apps/client/src/widgets/type_widgets/space_usage/selection.tsx
@@ -49,7 +49,7 @@ export interface SpaceUsageSelection {
export default function SelectionStrip({ selection, containerRef }: {
selection: SpaceUsageSelection | null,
/** Held by the page, which measures the strip to leave the map room to scroll clear of it. */
- containerRef?: RefObject<HTMLDivElement>
+ containerRef?: RefObject<HTMLDivElement | null>
}) {
const titles = usePathTitles(selection?.notePath);
// The note's own title is the last of them; anything above it is where the note sits. A mark
diff --git a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
index 4129e1d345..36c209acea 100644
--- a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
+++ b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx
@@ -44,7 +44,7 @@ export interface NotificationEventData {
interface CKEditorWithWatchdogProps extends Pick<HTMLProps<HTMLDivElement>, "className" | "tabIndex"> {
contentLanguage: string | null | undefined;
isClassicEditor?: boolean;
- watchdogRef: RefObject<EditorWatchdog>;
+ watchdogRef: RefObject<EditorWatchdog | null>;
watchdogConfig?: WatchdogConfig;
onNotificationWarning?: (evt: NotificationEventInfo, data: NotificationEventData) => void;
onNotificationInfo?: (evt: NotificationEventInfo, data: NotificationEventData) => void;
@@ -52,9 +52,9 @@ interface CKEditorWithWatchdogProps extends Pick<HTMLProps<HTMLDivElement>, "cla
onChange: () => void;
/** Called upon whenever a new CKEditor instance is initialized, whether it's the first initialization, after a crash or after a config change that requires it (e.g. content language). */
onEditorInitialized?: (editor: CKTextEditor) => void;
- editorApi: RefObject<CKEditorApi>;
+ editorApi: RefObject<CKEditorApi | null>;
templates: SnippetDefinition[];
- containerRef?: RefObject<HTMLDivElement>;
+ containerRef?: RefObject<HTMLDivElement | null>;
}
export default function CKEditorWithWatchdog({ containerRef: externalContainerRef, contentLanguage, className, tabIndex, isClassicEditor, watchdogRef: externalWatchdogRef, watchdogConfig, onNotificationWarning, onNotificationInfo, onWatchdogStateChange, onChange, onEditorInitialized, editorApi, templates }: CKEditorWithWatchdogProps) {
diff --git a/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsx b/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsx
index 0d6dea68b6..250154760b 100644
--- a/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsx
+++ b/apps/client/src/widgets/type_widgets/text/ContentEmbed.tsx
@@ -254,7 +254,7 @@ function ContentEmbedActionButton({ className, action }: {
* Dispatches `fullscreenChangeStart` on the content box as it enters or leaves fullscreen, then
* `enterFullscreen` or `leaveFullscreen` once it has the size that fullscreen gives or takes back.
*/
-function useFullscreenEvents(contentRef: RefObject<HTMLElement>) {
+function useFullscreenEvents(contentRef: RefObject<HTMLElement | null>) {
useEffect(() => {
const content = contentRef.current;
if (!content) return;
diff --git a/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts b/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts
index 564789d015..b1c00faa72 100644
--- a/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts
+++ b/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts
@@ -104,7 +104,7 @@ export function showContentEmbedFullscreen(element: Element | null) {
* sets `hasEditableFlag`. Content outside an embed has no toggle, and is editable. `false` until
* the content is in the page.
*/
-export function useIsContentEmbedEditable(ref: RefObject<HTMLElement>) {
+export function useIsContentEmbedEditable(ref: RefObject<HTMLElement | null>) {
const [ isEditable, setIsEditable ] = useState(false);
useEffect(() => {
@@ -129,7 +129,7 @@ export function useIsContentEmbedEditable(ref: RefObject<HTMLElement>) {
* as content can mount before its embed box takes it in.
*/
export function useContentEmbedEvent(
- ref: RefObject<HTMLElement>,
+ ref: RefObject<HTMLElement | null>,
name: ContentEmbedEvent,
callback: () => void
) {