@haklex/rich-editor 0.0.80 → 0.0.82

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.
Files changed (35) hide show
  1. package/dist/AlertQuoteEditNode-BDoonB4u.js +267 -0
  2. package/dist/KaTeXRenderer-BsyRH5_t.js +214 -0
  3. package/dist/LinkCardRenderer-OEMBDUhD.js +45 -0
  4. package/dist/MermaidPlugin-Df2Cm2yX.js +67 -0
  5. package/dist/PresentDialogContext-DQw6MrNh.js +59 -0
  6. package/dist/RubyRenderer-BpDb_amz.js +14 -0
  7. package/dist/SubmitShortcutPlugin-6IvsbZD-.js +1463 -0
  8. package/dist/commands-entry.mjs +14 -23
  9. package/dist/config-tfg1FWhG.js +1149 -0
  10. package/dist/context/NestedContentRendererContext.d.ts +2 -1
  11. package/dist/context/NestedContentRendererContext.d.ts.map +1 -1
  12. package/dist/favicon-DIWusrrw.js +41 -0
  13. package/dist/index.mjs +259 -284
  14. package/dist/node-registry-CeVi2y9f.js +666 -0
  15. package/dist/nodes-entry.mjs +7 -47
  16. package/dist/plugins-entry.mjs +10 -27
  17. package/dist/renderers-entry.mjs +40 -57
  18. package/dist/rich-editor.css +2 -1
  19. package/dist/shared.css-wgGgtK_e.js +23 -0
  20. package/dist/static-entry.mjs +16 -45
  21. package/dist/styles-entry.mjs +3 -12
  22. package/dist/theme-DHOUKKSr.js +1034 -0
  23. package/package.json +4 -4
  24. package/dist/AlertQuoteEditNode-CHdvQnOr.js +0 -293
  25. package/dist/KaTeXRenderer-C8jv_5xr.js +0 -214
  26. package/dist/LinkCardRenderer-QmkOlyXb.js +0 -36
  27. package/dist/MermaidPlugin-DjLUVZvB.js +0 -97
  28. package/dist/PresentDialogContext-BpSB8tXC.js +0 -52
  29. package/dist/RubyRenderer-DbeobSoH.js +0 -13
  30. package/dist/SubmitShortcutPlugin-BFBAwTb1.js +0 -1627
  31. package/dist/config-DcR_yktp.js +0 -1236
  32. package/dist/favicon-BQgbXF_a.js +0 -43
  33. package/dist/node-registry-B2U2_LrI.js +0 -766
  34. package/dist/shared.css-DNuMYx6Q.js +0 -21
  35. package/dist/theme-CYsyGmCL.js +0 -1040
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haklex/rich-editor",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "description": "Core rich text editor based on Lexical",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,9 +49,9 @@
49
49
  "@lexical/code": "npm:lexical-code-no-prism@0.41.0",
50
50
  "nanoid": "^5.1.6",
51
51
  "thumbhash": "^0.1.1",
52
- "@haklex/rich-editor-ui": "0.0.80",
53
- "@haklex/rich-headless": "0.0.80",
54
- "@haklex/rich-style-token": "0.0.80"
52
+ "@haklex/rich-editor-ui": "0.0.82",
53
+ "@haklex/rich-style-token": "0.0.82",
54
+ "@haklex/rich-headless": "0.0.82"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@lexical/extension": "^0.41.0",
@@ -1,293 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { $getNodeByKey, KEY_ENTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, $getRoot, $createParagraphNode, $isParagraphNode, $getSelection, $isRangeSelection, $insertNodes, createEditor } from "lexical";
5
- import { Info, Lightbulb, TriangleAlert } from "lucide-react";
6
- import { useCallback, useEffect, createElement } from "react";
7
- import { jsxs, Fragment, jsx } from "react/jsx-runtime";
8
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
9
- import { ContentEditable } from "@lexical/react/LexicalContentEditable";
10
- import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
11
- import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
12
- import { ListPlugin } from "@lexical/react/LexicalListPlugin";
13
- import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
14
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
15
- import { q as $isAlertQuoteNode, r as AlertRenderer, S as SpoilerNode, M as MentionNode, F as FootnoteNode, k as KaTeXInlineNode, T as TagNode, s as AlertQuoteNode, n as editorTheme } from "./theme-CYsyGmCL.js";
16
- import { a as RendererWrapper } from "./KaTeXRenderer-C8jv_5xr.js";
17
- import { CodeNode } from "@lexical/code";
18
- import { HorizontalRuleNode } from "@lexical/extension";
19
- import { LinkNode, AutoLinkNode } from "@lexical/link";
20
- import { ListNode, ListItemNode } from "@lexical/list";
21
- import { HeadingNode, QuoteNode } from "@lexical/rich-text";
22
- import { TableNode, TableCellNode, TableRowNode } from "@lexical/table";
23
- function ExitBlockPlugin({
24
- parentEditor,
25
- nodeKey
26
- }) {
27
- const [editor] = useLexicalComposerContext();
28
- useEffect(() => {
29
- const focusParent = () => {
30
- parentEditor.focus(() => {
31
- parentEditor.update(() => {
32
- const alertNode = $getNodeByKey(nodeKey);
33
- if (alertNode) {
34
- const next = alertNode.getNextSibling();
35
- if (next) {
36
- next.selectStart();
37
- }
38
- }
39
- });
40
- });
41
- };
42
- const exitAlert = (removeEmpty) => {
43
- const root = $getRoot();
44
- const lastChild = root.getLastChild();
45
- const shouldRemoveAlert = removeEmpty && root.getChildrenSize() <= 1;
46
- if (removeEmpty && lastChild) {
47
- lastChild.remove();
48
- }
49
- if (shouldRemoveAlert) {
50
- parentEditor.update(
51
- () => {
52
- const alertNode = $getNodeByKey(nodeKey);
53
- if (alertNode) {
54
- const paragraph = $createParagraphNode();
55
- alertNode.insertAfter(paragraph);
56
- alertNode.remove();
57
- paragraph.selectStart();
58
- }
59
- },
60
- { onUpdate: focusParent }
61
- );
62
- } else {
63
- parentEditor.update(
64
- () => {
65
- const alertNode = $getNodeByKey(nodeKey);
66
- if (alertNode) {
67
- let next = alertNode.getNextSibling();
68
- if (!next || !$isParagraphNode(next)) {
69
- next = $createParagraphNode();
70
- alertNode.insertAfter(next);
71
- }
72
- next.selectStart();
73
- }
74
- },
75
- { onUpdate: focusParent }
76
- );
77
- }
78
- };
79
- const isAtLastEmptyParagraph = () => {
80
- const selection = $getSelection();
81
- if (!$isRangeSelection(selection) || !selection.isCollapsed()) return false;
82
- const anchorNode = selection.anchor.getNode();
83
- const topLevelElement = anchorNode.getTopLevelElement();
84
- return topLevelElement && $isParagraphNode(topLevelElement) && topLevelElement.getTextContent() === "" && topLevelElement.getNextSibling() === null;
85
- };
86
- const unregisterEnter = editor.registerCommand(
87
- KEY_ENTER_COMMAND,
88
- (event) => {
89
- if (event?.metaKey || event?.ctrlKey) {
90
- event.preventDefault();
91
- exitAlert(false);
92
- return true;
93
- }
94
- if (!isAtLastEmptyParagraph()) return false;
95
- event?.preventDefault();
96
- exitAlert(true);
97
- return true;
98
- },
99
- COMMAND_PRIORITY_CRITICAL
100
- );
101
- const unregisterArrowDown = editor.registerCommand(
102
- KEY_ARROW_DOWN_COMMAND,
103
- (event) => {
104
- if (!isAtLastEmptyParagraph()) return false;
105
- event?.preventDefault();
106
- exitAlert(false);
107
- return true;
108
- },
109
- COMMAND_PRIORITY_HIGH
110
- );
111
- return () => {
112
- unregisterEnter();
113
- unregisterArrowDown();
114
- };
115
- }, [editor, parentEditor, nodeKey]);
116
- return null;
117
- }
118
- function AlertEditDecorator({ nodeKey, alertType, contentEditor }) {
119
- const [editor] = useLexicalComposerContext();
120
- const editable = editor.isEditable();
121
- const handleTypeChange = useCallback(
122
- (newType) => {
123
- editor.update(() => {
124
- const node = $getNodeByKey(nodeKey);
125
- if ($isAlertQuoteNode(node)) {
126
- node.setAlertType(newType);
127
- }
128
- });
129
- },
130
- [editor, nodeKey]
131
- );
132
- return /* @__PURE__ */ jsxs(Fragment, { children: [
133
- /* @__PURE__ */ jsx(
134
- RendererWrapper,
135
- {
136
- defaultRenderer: AlertRenderer,
137
- rendererKey: "Alert",
138
- props: {
139
- type: alertType,
140
- editable,
141
- onTypeChange: editable ? handleTypeChange : void 0
142
- }
143
- }
144
- ),
145
- /* @__PURE__ */ jsx("div", { className: "rich-alert-content", children: /* @__PURE__ */ jsxs(LexicalNestedComposer, { initialEditor: contentEditor, children: [
146
- /* @__PURE__ */ jsx(
147
- RichTextPlugin,
148
- {
149
- ErrorBoundary: LexicalErrorBoundary,
150
- contentEditable: /* @__PURE__ */ jsx(
151
- ContentEditable,
152
- {
153
- "aria-placeholder": "",
154
- className: "rich-alert-content-editable",
155
- placeholder: /* @__PURE__ */ jsx("span", { style: { display: "none" } }),
156
- style: { outline: "none" }
157
- }
158
- )
159
- }
160
- ),
161
- /* @__PURE__ */ jsx(ListPlugin, {}),
162
- /* @__PURE__ */ jsx(LinkPlugin, {}),
163
- /* @__PURE__ */ jsx(ExitBlockPlugin, { nodeKey, parentEditor: editor })
164
- ] }) })
165
- ] });
166
- }
167
- const NESTED_EDITOR_NODES = [
168
- HeadingNode,
169
- QuoteNode,
170
- ListNode,
171
- ListItemNode,
172
- LinkNode,
173
- AutoLinkNode,
174
- HorizontalRuleNode,
175
- CodeNode,
176
- TableNode,
177
- TableCellNode,
178
- TableRowNode,
179
- SpoilerNode,
180
- MentionNode,
181
- FootnoteNode,
182
- KaTeXInlineNode,
183
- TagNode
184
- ];
185
- function createContentEditor() {
186
- return createEditor({
187
- namespace: "AlertContent",
188
- nodes: NESTED_EDITOR_NODES,
189
- theme: editorTheme,
190
- onError: (error) => {
191
- console.error("[AlertContent]", error);
192
- }
193
- });
194
- }
195
- const _AlertQuoteEditNode = class _AlertQuoteEditNode extends AlertQuoteNode {
196
- constructor(alertType, contentState, key) {
197
- super(alertType, contentState, key);
198
- __publicField(this, "__contentEditor");
199
- this.__contentEditor = createContentEditor();
200
- if (contentState) {
201
- const editorState = this.__contentEditor.parseEditorState(contentState);
202
- this.__contentEditor.setEditorState(editorState);
203
- }
204
- }
205
- static clone(node) {
206
- const cloned = new _AlertQuoteEditNode(
207
- node.__alertType,
208
- node.__contentState,
209
- node.__key
210
- );
211
- cloned.__contentEditor = node.__contentEditor;
212
- return cloned;
213
- }
214
- getContentEditor() {
215
- return this.__contentEditor;
216
- }
217
- static importJSON(serializedNode) {
218
- const node = new _AlertQuoteEditNode(
219
- serializedNode.alertType,
220
- serializedNode.content
221
- );
222
- return node;
223
- }
224
- exportJSON() {
225
- return {
226
- ...super.exportJSON(),
227
- type: "alert-quote",
228
- alertType: this.__alertType,
229
- content: this.__contentEditor.getEditorState().toJSON(),
230
- version: 1
231
- };
232
- }
233
- decorate(_editor, _config) {
234
- return createElement(AlertEditDecorator, {
235
- nodeKey: this.__key,
236
- alertType: this.__alertType,
237
- contentEditor: this.__contentEditor
238
- });
239
- }
240
- };
241
- __publicField(_AlertQuoteEditNode, "commandItems", [
242
- {
243
- title: "Callout",
244
- icon: createElement(Info, { size: 20 }),
245
- description: "Info callout block",
246
- keywords: ["alert", "note", "info", "callout"],
247
- section: "ADVANCED",
248
- placement: ["slash", "toolbar"],
249
- group: "insert",
250
- onSelect: (editor) => {
251
- editor.update(() => {
252
- $insertNodes([$createAlertQuoteEditNode("note")]);
253
- });
254
- }
255
- },
256
- {
257
- title: "Tip",
258
- icon: createElement(Lightbulb, { size: 20 }),
259
- description: "Highlight a useful tip",
260
- keywords: ["alert", "tip", "hint"],
261
- section: "ADVANCED",
262
- placement: ["slash", "toolbar"],
263
- group: "insert",
264
- onSelect: (editor) => {
265
- editor.update(() => {
266
- $insertNodes([$createAlertQuoteEditNode("tip")]);
267
- });
268
- }
269
- },
270
- {
271
- title: "Warning",
272
- icon: createElement(TriangleAlert, { size: 20 }),
273
- description: "Warn about something",
274
- keywords: ["alert", "warning", "caution"],
275
- section: "ADVANCED",
276
- placement: ["slash", "toolbar"],
277
- group: "insert",
278
- onSelect: (editor) => {
279
- editor.update(() => {
280
- $insertNodes([$createAlertQuoteEditNode("warning")]);
281
- });
282
- }
283
- }
284
- ]);
285
- let AlertQuoteEditNode = _AlertQuoteEditNode;
286
- function $createAlertQuoteEditNode(alertType, contentState) {
287
- return new AlertQuoteEditNode(alertType, contentState);
288
- }
289
- export {
290
- $createAlertQuoteEditNode as $,
291
- AlertQuoteEditNode as A,
292
- NESTED_EDITOR_NODES as N
293
- };
@@ -1,214 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { createContext, use, useMemo, createElement, useCallback, useState, useEffect } from "react";
3
- import { thumbHashToDataURL, rgbaToThumbHash } from "thumbhash";
4
- const RendererConfigContext = createContext({
5
- config: void 0,
6
- mode: "renderer",
7
- variant: "article"
8
- });
9
- function RendererConfigProvider({
10
- config,
11
- mode,
12
- variant,
13
- children
14
- }) {
15
- const value = useMemo(() => ({ config, mode, variant }), [config, mode, variant]);
16
- return /* @__PURE__ */ jsx(RendererConfigContext.Provider, { value, children });
17
- }
18
- function useRendererConfig() {
19
- return use(RendererConfigContext).config;
20
- }
21
- function useRendererMode() {
22
- return use(RendererConfigContext).mode;
23
- }
24
- function useVariant() {
25
- return use(RendererConfigContext).variant;
26
- }
27
- function RendererWrapper({
28
- rendererKey,
29
- defaultRenderer: DefaultRenderer,
30
- props
31
- }) {
32
- const config = useRendererConfig();
33
- const Renderer = config?.[rendererKey] ?? DefaultRenderer;
34
- return /* @__PURE__ */ jsx(Renderer, { ...props });
35
- }
36
- function createRendererDecoration(rendererKey, defaultRenderer, props) {
37
- return createElement(RendererWrapper, {
38
- rendererKey,
39
- defaultRenderer,
40
- props
41
- });
42
- }
43
- const FootnoteDefinitionsContext = createContext({
44
- definitions: {},
45
- displayNumberMap: {}
46
- });
47
- function FootnoteDefinitionsProvider({
48
- definitions,
49
- displayNumberMap,
50
- children
51
- }) {
52
- const value = useMemo(
53
- () => ({ definitions, displayNumberMap }),
54
- [definitions, displayNumberMap]
55
- );
56
- return /* @__PURE__ */ jsx(FootnoteDefinitionsContext, { value, children });
57
- }
58
- function useFootnoteDefinitions() {
59
- return use(FootnoteDefinitionsContext);
60
- }
61
- function useFootnoteContent(identifier) {
62
- const { definitions } = use(FootnoteDefinitionsContext);
63
- return definitions[identifier];
64
- }
65
- function useFootnoteDisplayNumber(identifier) {
66
- const { displayNumberMap } = use(FootnoteDefinitionsContext);
67
- return displayNumberMap[identifier];
68
- }
69
- function FootnoteStaticRenderer({ identifier }) {
70
- const content = useFootnoteContent(identifier);
71
- const displayNumber = useFootnoteDisplayNumber(identifier);
72
- const referenceId = `footnote-ref-${identifier}`;
73
- const targetId = `footnote-${identifier}`;
74
- const handleClick = useCallback(
75
- (e) => {
76
- const target = document.getElementById(targetId) || document.getElementById(`fn-${identifier}`);
77
- if (!target) return;
78
- e.preventDefault();
79
- target.scrollIntoView({ behavior: "smooth", block: "center" });
80
- target.classList.add("rich-footnote-highlight");
81
- window.setTimeout(() => {
82
- target.classList.remove("rich-footnote-highlight");
83
- }, 1200);
84
- },
85
- [identifier, targetId]
86
- );
87
- const label = displayNumber ?? identifier;
88
- return /* @__PURE__ */ jsx("span", { className: "rich-footnote-ref-wrapper", children: /* @__PURE__ */ jsx(
89
- "a",
90
- {
91
- "aria-label": content ? `Footnote ${label}: ${content}` : `Footnote ${label}`,
92
- className: "rich-footnote-ref",
93
- "data-footnote-ref": identifier,
94
- href: `#${targetId}`,
95
- id: referenceId,
96
- role: "doc-noteref",
97
- onClick: handleClick,
98
- children: label
99
- }
100
- ) });
101
- }
102
- const MAX_DIM = 100;
103
- async function computeImageMeta(file) {
104
- const url = URL.createObjectURL(file);
105
- try {
106
- const img = await loadImage(url);
107
- const { naturalWidth: w, naturalHeight: h } = img;
108
- const scale = Math.min(MAX_DIM / w, MAX_DIM / h, 1);
109
- const sw = Math.round(w * scale);
110
- const sh = Math.round(h * scale);
111
- const canvas = document.createElement("canvas");
112
- canvas.width = sw;
113
- canvas.height = sh;
114
- const ctx = canvas.getContext("2d");
115
- ctx.drawImage(img, 0, 0, sw, sh);
116
- const { data } = ctx.getImageData(0, 0, sw, sh);
117
- const hash = rgbaToThumbHash(sw, sh, data);
118
- const thumbhash = uint8ToBase64(hash);
119
- return { width: w, height: h, thumbhash };
120
- } finally {
121
- URL.revokeObjectURL(url);
122
- }
123
- }
124
- function decodeThumbHash(hash) {
125
- try {
126
- const bytes = base64ToUint8(hash);
127
- return thumbHashToDataURL(bytes);
128
- } catch {
129
- return void 0;
130
- }
131
- }
132
- function loadImage(src) {
133
- return new Promise((resolve, reject) => {
134
- const img = new Image();
135
- img.onload = () => resolve(img);
136
- img.onerror = reject;
137
- img.src = src;
138
- });
139
- }
140
- function uint8ToBase64(bytes) {
141
- let bin = "";
142
- for (const b of bytes) bin += String.fromCodePoint(b);
143
- return btoa(bin);
144
- }
145
- function base64ToUint8(str) {
146
- const bin = atob(str);
147
- const bytes = new Uint8Array(bin.length);
148
- for (let i = 0; i < bin.length; i++) bytes[i] = bin.codePointAt(i);
149
- return bytes;
150
- }
151
- let katexModule = null;
152
- let katexLoadPromise = null;
153
- function loadKaTeX() {
154
- if (katexModule) return Promise.resolve(katexModule);
155
- if (!katexLoadPromise) {
156
- katexLoadPromise = import("katex").then((mod) => {
157
- katexModule = mod;
158
- return katexModule;
159
- });
160
- }
161
- return katexLoadPromise;
162
- }
163
- function KaTeXRenderer({ equation, displayMode }) {
164
- const [html, setHtml] = useState(null);
165
- const [error, setError] = useState(null);
166
- useEffect(() => {
167
- let cancelled = false;
168
- loadKaTeX().then((katex) => {
169
- if (cancelled) return;
170
- const rendered = katex.default.renderToString(equation, {
171
- displayMode,
172
- throwOnError: false
173
- });
174
- setHtml(rendered);
175
- setError(null);
176
- }).catch(() => {
177
- if (cancelled) return;
178
- setHtml(null);
179
- setError("KaTeX is not available");
180
- });
181
- return () => {
182
- cancelled = true;
183
- };
184
- }, [equation, displayMode]);
185
- if (error) {
186
- return /* @__PURE__ */ jsx("code", { className: "rich-katex-fallback", children: equation });
187
- }
188
- if (html) {
189
- return /* @__PURE__ */ jsx(
190
- "span",
191
- {
192
- className: displayMode ? "rich-katex-block" : "rich-katex-inline",
193
- dangerouslySetInnerHTML: { __html: html }
194
- }
195
- );
196
- }
197
- return /* @__PURE__ */ jsx("code", { className: "rich-katex-fallback", children: equation });
198
- }
199
- export {
200
- FootnoteDefinitionsProvider as F,
201
- KaTeXRenderer as K,
202
- RendererConfigProvider as R,
203
- RendererWrapper as a,
204
- useFootnoteDefinitions as b,
205
- createRendererDecoration as c,
206
- useFootnoteDisplayNumber as d,
207
- useRendererConfig as e,
208
- useRendererMode as f,
209
- useVariant as g,
210
- FootnoteStaticRenderer as h,
211
- computeImageMeta as i,
212
- decodeThumbHash as j,
213
- useFootnoteContent as u
214
- };
@@ -1,36 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- function LinkCardRenderer({
3
- url,
4
- title,
5
- description,
6
- favicon,
7
- image
8
- }) {
9
- const displayTitle = title || url;
10
- return /* @__PURE__ */ jsxs("a", { className: "rich-link-card", href: url, rel: "noopener noreferrer", target: "_blank", children: [
11
- image && /* @__PURE__ */ jsx("span", { className: "rich-link-card-image", children: /* @__PURE__ */ jsx("img", { alt: "", loading: "lazy", src: image }) }),
12
- /* @__PURE__ */ jsxs("span", { className: "rich-link-card-content", children: [
13
- /* @__PURE__ */ jsxs("span", { className: "rich-link-card-title", children: [
14
- favicon && /* @__PURE__ */ jsx(
15
- "img",
16
- {
17
- alt: "",
18
- className: "rich-link-card-favicon",
19
- height: 16,
20
- src: favicon,
21
- width: 16,
22
- onError: (e) => {
23
- e.target.style.display = "none";
24
- }
25
- }
26
- ),
27
- displayTitle
28
- ] }),
29
- description && /* @__PURE__ */ jsx("span", { className: "rich-link-card-description", children: description }),
30
- /* @__PURE__ */ jsx("span", { className: "rich-link-card-url", children: url })
31
- ] })
32
- ] });
33
- }
34
- export {
35
- LinkCardRenderer as L
36
- };
@@ -1,97 +0,0 @@
1
- import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
2
- import { createCommand, $insertNodes, COMMAND_PRIORITY_EDITOR } from "lexical";
3
- import { useEffect } from "react";
4
- import { $ as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-CHdvQnOr.js";
5
- import { $ as $createImageNode, t as $createKaTeXInlineNode, v as $createKaTeXBlockNode, b as $createMermaidNode } from "./theme-CYsyGmCL.js";
6
- const INSERT_ALERT_COMMAND = createCommand("INSERT_ALERT");
7
- function AlertPlugin() {
8
- const [editor] = useLexicalComposerContext();
9
- useEffect(() => {
10
- return editor.registerCommand(
11
- INSERT_ALERT_COMMAND,
12
- (alertType) => {
13
- $insertNodes([$createAlertQuoteEditNode(alertType)]);
14
- return true;
15
- },
16
- COMMAND_PRIORITY_EDITOR
17
- );
18
- }, [editor]);
19
- return null;
20
- }
21
- const INSERT_IMAGE_COMMAND = createCommand(
22
- "INSERT_IMAGE_COMMAND"
23
- );
24
- function ImagePlugin() {
25
- const [editor] = useLexicalComposerContext();
26
- useEffect(() => {
27
- return editor.registerCommand(
28
- INSERT_IMAGE_COMMAND,
29
- (payload) => {
30
- const imageNode = $createImageNode(payload);
31
- $insertNodes([imageNode]);
32
- return true;
33
- },
34
- COMMAND_PRIORITY_EDITOR
35
- );
36
- }, [editor]);
37
- return null;
38
- }
39
- const INSERT_KATEX_INLINE_COMMAND = createCommand(
40
- "INSERT_KATEX_INLINE"
41
- );
42
- const INSERT_KATEX_BLOCK_COMMAND = createCommand("INSERT_KATEX_BLOCK");
43
- function KaTeXPlugin() {
44
- const [editor] = useLexicalComposerContext();
45
- useEffect(() => {
46
- const unregisterInline = editor.registerCommand(
47
- INSERT_KATEX_INLINE_COMMAND,
48
- (equation) => {
49
- const node = $createKaTeXInlineNode(equation);
50
- $insertNodes([node]);
51
- return true;
52
- },
53
- COMMAND_PRIORITY_EDITOR
54
- );
55
- const unregisterBlock = editor.registerCommand(
56
- INSERT_KATEX_BLOCK_COMMAND,
57
- (equation) => {
58
- const node = $createKaTeXBlockNode(equation);
59
- $insertNodes([node]);
60
- return true;
61
- },
62
- COMMAND_PRIORITY_EDITOR
63
- );
64
- return () => {
65
- unregisterInline();
66
- unregisterBlock();
67
- };
68
- }, [editor]);
69
- return null;
70
- }
71
- const INSERT_MERMAID_COMMAND = createCommand("INSERT_MERMAID");
72
- function MermaidPlugin() {
73
- const [editor] = useLexicalComposerContext();
74
- useEffect(() => {
75
- return editor.registerCommand(
76
- INSERT_MERMAID_COMMAND,
77
- (diagram) => {
78
- const node = $createMermaidNode(diagram);
79
- $insertNodes([node]);
80
- return true;
81
- },
82
- COMMAND_PRIORITY_EDITOR
83
- );
84
- }, [editor]);
85
- return null;
86
- }
87
- export {
88
- AlertPlugin as A,
89
- ImagePlugin as I,
90
- KaTeXPlugin as K,
91
- MermaidPlugin as M,
92
- INSERT_ALERT_COMMAND as a,
93
- INSERT_IMAGE_COMMAND as b,
94
- INSERT_KATEX_BLOCK_COMMAND as c,
95
- INSERT_KATEX_INLINE_COMMAND as d,
96
- INSERT_MERMAID_COMMAND as e
97
- };