chore(ckeditor/watchdog): fix typecheck issues

This commit is contained in:
Elian Doran 2025-12-07 22:09:30 +02:00
parent 9ddf4a1308
commit cd27160905
No known key found for this signature in database
4 changed files with 12 additions and 10 deletions

View File

@ -4,11 +4,12 @@ import { t } from "../../services/i18n";
import { useState } from "preact/hooks"; import { useState } from "preact/hooks";
import FormCheckbox from "../react/FormCheckbox"; import FormCheckbox from "../react/FormCheckbox";
import { useTriliumEvent } from "../react/hooks"; import { useTriliumEvent } from "../react/hooks";
import type { VNode } from "preact"; import { isValidElement, type VNode } from "preact";
import { RawHtmlBlock } from "../react/RawHtml";
interface ConfirmDialogProps { interface ConfirmDialogProps {
title?: string; title?: string;
message?: string | HTMLElement; message?: MessageType;
callback?: ConfirmDialogCallback; callback?: ConfirmDialogCallback;
isConfirmDeleteNoteBox?: boolean; isConfirmDeleteNoteBox?: boolean;
} }
@ -21,7 +22,7 @@ export default function ConfirmDialog() {
function showDialog(title: string | null, message: MessageType, callback: ConfirmDialogCallback, isConfirmDeleteNoteBox: boolean) { function showDialog(title: string | null, message: MessageType, callback: ConfirmDialogCallback, isConfirmDeleteNoteBox: boolean) {
setOpts({ setOpts({
title: title ?? undefined, title: title ?? undefined,
message: (typeof message === "object" && "length" in message ? message[0] : message), message,
callback, callback,
isConfirmDeleteNoteBox isConfirmDeleteNoteBox
}); });
@ -58,9 +59,10 @@ export default function ConfirmDialog() {
show={shown} show={shown}
stackable stackable
> >
{!opts?.message || typeof opts?.message === "string" {isValidElement(opts?.message)
? <div>{(opts?.message as string) ?? ""}</div> ? opts?.message
: <div dangerouslySetInnerHTML={{ __html: opts?.message.outerHTML ?? "" }} />} : <RawHtmlBlock html={opts?.message} />
}
{opts?.isConfirmDeleteNoteBox && ( {opts?.isConfirmDeleteNoteBox && (
<FormCheckbox <FormCheckbox

View File

@ -67,7 +67,7 @@ export default function InfoDialog() {
> >
{isValidElement(opts?.message) {isValidElement(opts?.message)
? opts?.message ? opts?.message
: <RawHtmlBlock className="info-dialog-content" html={opts?.message ?? ""} /> : <RawHtmlBlock className="info-dialog-content" html={opts?.message} />
} }
</Modal>); </Modal>);
} }

View File

@ -77,7 +77,7 @@ export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentC
const spacedUpdate = useEditorSpacedUpdate({ const spacedUpdate = useEditorSpacedUpdate({
note, note,
noteContext, noteContext,
getData: () => ({ content: editorRef.current?.getText() }), getData: () => ({ content: editorRef.current?.getText() ?? "" }),
onContentChange: (content) => { onContentChange: (content) => {
const codeEditor = editorRef.current; const codeEditor = editorRef.current;
if (!codeEditor) return; if (!codeEditor) return;

View File

@ -25,7 +25,7 @@ interface CKEditorWithWatchdogProps extends Pick<HTMLProps<HTMLDivElement>, "cla
watchdogRef: RefObject<EditorWatchdog>; watchdogRef: RefObject<EditorWatchdog>;
watchdogConfig?: WatchdogConfig; watchdogConfig?: WatchdogConfig;
onNotificationWarning?: (evt: any, data: any) => void; onNotificationWarning?: (evt: any, data: any) => void;
onWatchdogStateChange?: (watchdog: EditorWatchdog<any>) => void; onWatchdogStateChange?: (watchdog: EditorWatchdog) => void;
onChange: () => void; 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). */ /** 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; onEditorInitialized?: (editor: CKTextEditor) => void;
@ -204,7 +204,7 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe
); );
} }
function buildWatchdog(isClassicEditor: boolean, watchdogConfig?: WatchdogConfig): EditorWatchdog<CKTextEditor> { function buildWatchdog(isClassicEditor: boolean, watchdogConfig?: WatchdogConfig): EditorWatchdog {
if (isClassicEditor) { if (isClassicEditor) {
return new EditorWatchdog(ClassicEditor, watchdogConfig); return new EditorWatchdog(ClassicEditor, watchdogConfig);
} else { } else {