@haklex/rich-renderer-katex 0.3.4 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KaTeXEditDecorator.d.ts","sourceRoot":"","sources":["../src/KaTeXEditDecorator.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"KaTeXEditDecorator.d.ts","sourceRoot":"","sources":["../src/KaTeXEditDecorator.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAO1C,UAAU,uBAAuB;IAC/B,eAAe,EAAE,OAAO,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,QAAQ,EACR,WAAW,EACX,eAAe,EACf,QAAQ,GACT,EAAE,uBAAuB,2CA4YzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type EditorHistoryShortcut = 'redo' | 'undo';
|
|
2
|
+
export interface EditorHistoryShortcutEvent {
|
|
3
|
+
altKey?: boolean;
|
|
4
|
+
ctrlKey: boolean;
|
|
5
|
+
key: string;
|
|
6
|
+
metaKey: boolean;
|
|
7
|
+
shiftKey: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface EditorHistoryShortcutOptions {
|
|
10
|
+
isDirty?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function getEditorHistoryShortcut(event: EditorHistoryShortcutEvent, options?: EditorHistoryShortcutOptions): EditorHistoryShortcut | null;
|
|
13
|
+
//# sourceMappingURL=history-shortcuts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-shortcuts.d.ts","sourceRoot":"","sources":["../src/history-shortcuts.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,0BAA0B;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,0BAA0B,EACjC,OAAO,GAAE,4BAAiC,GACzC,qBAAqB,GAAG,IAAI,CAgB9B"}
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { KaTeXRenderer, createRendererDecoration } from "@haklex/rich-editor/ren
|
|
|
3
3
|
import { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { ActionBar, ActionButton, AnimatedTabs, Popover, PopoverPanel, PopoverTrigger } from "@haklex/rich-editor-ui";
|
|
5
5
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
6
|
-
import { $getNodeByKey } from "lexical";
|
|
6
|
+
import { $getNodeByKey, REDO_COMMAND, UNDO_COMMAND } from "lexical";
|
|
7
7
|
import { Check, Copy, RotateCcw, Search, Terminal, Trash2 } from "lucide-react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
//#region src/styles.css.ts
|
|
@@ -57,6 +57,17 @@ var bodyScrollArea = "mkenhua";
|
|
|
57
57
|
var footer = "mkenhuw";
|
|
58
58
|
var charCount = "mkenhux";
|
|
59
59
|
//#endregion
|
|
60
|
+
//#region src/history-shortcuts.ts
|
|
61
|
+
function getEditorHistoryShortcut(event, options = {}) {
|
|
62
|
+
if (options.isDirty) return null;
|
|
63
|
+
if (event.altKey) return null;
|
|
64
|
+
if (!event.metaKey && !event.ctrlKey) return null;
|
|
65
|
+
const key = event.key.toLowerCase();
|
|
66
|
+
if (key === "z") return event.shiftKey ? "redo" : "undo";
|
|
67
|
+
if (key === "y" && event.ctrlKey && !event.metaKey && !event.shiftKey) return "redo";
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
60
71
|
//#region src/snippets.ts
|
|
61
72
|
var CURSOR_TOKEN = "__cursor__";
|
|
62
73
|
var katexSnippets = [
|
|
@@ -280,6 +291,18 @@ function KaTeXEditDecorator({ nodeKey, equation, displayMode, autoOpenOnMount, c
|
|
|
280
291
|
cancel,
|
|
281
292
|
displayMode
|
|
282
293
|
]);
|
|
294
|
+
const handlePanelKeyDown = useCallback((e) => {
|
|
295
|
+
const shortcut = getEditorHistoryShortcut(e, { isDirty: value !== equation || snippetQuery !== "" });
|
|
296
|
+
if (!shortcut) return;
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
e.stopPropagation();
|
|
299
|
+
editor.dispatchCommand(shortcut === "undo" ? UNDO_COMMAND : REDO_COMMAND, void 0);
|
|
300
|
+
}, [
|
|
301
|
+
editor,
|
|
302
|
+
equation,
|
|
303
|
+
snippetQuery,
|
|
304
|
+
value
|
|
305
|
+
]);
|
|
283
306
|
if (!editable) return children;
|
|
284
307
|
return /* @__PURE__ */ jsxs(Popover, {
|
|
285
308
|
open,
|
|
@@ -299,6 +322,7 @@ function KaTeXEditDecorator({ nodeKey, equation, displayMode, autoOpenOnMount, c
|
|
|
299
322
|
initialFocus: inputRef,
|
|
300
323
|
side: "bottom",
|
|
301
324
|
sideOffset: 8,
|
|
325
|
+
onKeyDown: handlePanelKeyDown,
|
|
302
326
|
children: [
|
|
303
327
|
/* @__PURE__ */ jsxs("div", {
|
|
304
328
|
className: `${header} ${semanticClassNames.header}`,
|