@lobehub/editor 4.8.5 → 4.9.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,4 +1,4 @@
1
- import { A as $createCodeMirrorNode, At as createDebugLogger, B as Editor, C as $createCodeNode$1, D as getCodeInlineNode, Ft as init_debug, Gt as INodeHelper, H as DataSource, Ht as exportNodeToJSON$1, Jt as __exportAll, K as $closest, Kt as init_helper, L as CursorNode, Lt as $canShowPlaceholderCurry, N as $createCursorNode, O as styles$2, Ot as init_hotkey, R as cursorNodeSerialized, Rt as $isCursorInQuote, Tt as HotkeyEnum, Ut as init_utils$1, Vt as createBlockNode, Wt as sampleReader, Xt as __toESM, Y as $getNodeFromDOMNode, d as $isLinkHighlightNode, i as MentionNode, it as genServiceId, k as themeStyles, mt as noop, n as $createMentionNode, p as getLinkHighlightNode, q as $closestNodeType, qt as __commonJSMin, r as $isMentionNode, t as styles$3, tt as assert, u as $createLinkHighlightNode, ut as init_utils, vt as KernelPlugin, w as $isCodeInlineNode, yt as init_plugin, z as registerCursorNode, zt as $isCursorInTable } from "./style-Tlcvrhqp.js";
1
+ import { A as $createCodeMirrorNode, At as createDebugLogger, B as Editor, C as $createCodeNode$1, D as getCodeInlineNode, Ft as init_debug, Gt as INodeHelper, H as DataSource, Ht as exportNodeToJSON$1, Jt as __exportAll, K as $closest, Kt as init_helper, L as CursorNode, Lt as $canShowPlaceholderCurry, N as $createCursorNode, O as styles$2, Ot as init_hotkey, R as cursorNodeSerialized, Rt as $isCursorInQuote, Tt as HotkeyEnum, Ut as init_utils$1, Vt as createBlockNode, Wt as sampleReader, Xt as __toESM, Y as $getNodeFromDOMNode, d as $isLinkHighlightNode, i as MentionNode, it as genServiceId, k as themeStyles, mt as noop, n as $createMentionNode, p as getLinkHighlightNode, q as $closestNodeType, qt as __commonJSMin, r as $isMentionNode, t as styles$3, tt as assert, u as $createLinkHighlightNode, ut as init_utils, vt as KernelPlugin, w as $isCodeInlineNode, yt as init_plugin, z as registerCursorNode, zt as $isCursorInTable } from "./style-DAKdXzC4.js";
2
2
  import { registerHistory } from "@lexical/history";
3
3
  import { $isTableSelection } from "@lexical/table";
4
4
  import { $caretFromPoint, $createLineBreakNode, $createNodeSelection, $createParagraphNode, $createPoint, $createRangeSelection, $createTabNode, $createTextNode, $getCaretRange, $getCaretRangeInDirection, $getCharacterOffsets, $getChildCaret, $getNearestNodeFromDOMNode, $getNodeByKey, $getRoot, $getSelection, $getSiblingCaret, $getTextPointCaret, $insertNodes, $isBlockElementNode, $isDecoratorNode, $isElementNode, $isLineBreakNode, $isNodeSelection, $isRangeSelection, $isRootOrShadowRoot, $isTabNode, $isTextNode, $isTextPointCaret, $normalizeCaret, $parseSerializedNode, $setSelection, $setSelectionFromCaretRange, CLICK_COMMAND, COLLABORATION_TAG, COMMAND_PRIORITY_CRITICAL, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_NORMAL, CONTROLLED_TEXT_INSERTION_COMMAND, COPY_COMMAND, FORMAT_TEXT_COMMAND, HISTORIC_TAG, HISTORY_PUSH_TAG, INDENT_CONTENT_COMMAND, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, IS_BOLD, IS_CODE, IS_ITALIC, IS_STRIKETHROUGH, IS_SUBSCRIPT, IS_SUPERSCRIPT, IS_UNDERLINE, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DOWN_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, MOVE_TO_END, MOVE_TO_START, OUTDENT_CONTENT_COMMAND, PASTE_COMMAND, ParagraphNode, REDO_COMMAND, SELECTION_CHANGE_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, TEXT_TYPE_TO_FORMAT, TabNode, TextNode, UNDO_COMMAND, createCommand, getDOMSelection, getNearestEditorFromDOMNode, resetRandomKey } from "lexical";
@@ -7,18 +7,18 @@ import { $findMatchingParent, $wrapNodeInElement, CAN_USE_DOM, calculateZoomLeve
7
7
  import { ErrorBoundary } from "react-error-boundary";
8
8
  import { jsx, jsxs } from "react/jsx-runtime";
9
9
  import { Children, Suspense, createContext, memo, use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
10
- import { Menu, ShikiLobeTheme, preprocessMarkdownContent, toast } from "@lobehub/ui";
10
+ import { $isAtNodeEnd, $setBlocksType } from "@lexical/selection";
11
+ import { registerDragonSupport } from "@lexical/dragon";
12
+ import { $insertList, $isListItemNode, $isListNode } from "@lexical/list";
11
13
  import remarkCjkFriendly from "remark-cjk-friendly";
12
14
  import { $getClipboardDataFromSelection, setLexicalClipboardDataTransfer } from "@lexical/clipboard";
13
15
  import { $createCodeHighlightNode, $createCodeNode, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, $isCodeHighlightNode, $isCodeNode, CodeHighlightNode, CodeNode, DEFAULT_CODE_LANGUAGE } from "@lexical/code-core";
16
+ import { Menu, ShikiLobeTheme, toast } from "@lobehub/ui";
14
17
  import { createStaticStyles, cx } from "antd-style";
15
- import { $isAtNodeEnd, $setBlocksType } from "@lexical/selection";
16
- import { registerDragonSupport } from "@lexical/dragon";
17
- import { $insertList, $isListItemNode, $isListNode } from "@lexical/list";
18
18
  import { createPortal, flushSync } from "react-dom";
19
+ import { bundledLanguagesInfo, bundledLanguagesInfo as bundledLanguagesInfo$1, bundledThemesInfo } from "shiki";
19
20
  import { createHighlighterCoreSync, isSpecialLang, isSpecialTheme, stringifyTokenStyle } from "@shikijs/core";
20
21
  import { createJavaScriptRegexEngine } from "@shikijs/engine-javascript";
21
- import { bundledLanguagesInfo, bundledLanguagesInfo as bundledLanguagesInfo$1, bundledThemesInfo } from "shiki";
22
22
  import Fuse from "fuse.js";
23
23
  import { flip, offset, shift, useFloating } from "@floating-ui/react";
24
24
  //#region src/editor-kernel/react/LexicalErrorBoundary.tsx
@@ -103,6 +103,153 @@ function useLexicalEditor(handleEditor, deps = []) {
103
103
  }, deps);
104
104
  }
105
105
  //#endregion
106
+ //#region src/plugins/common/command/index.ts
107
+ const INSERT_QUOTE_COMMAND = createCommand("INSERT_QUOTE_COMMAND");
108
+ const INSERT_HEADING_COMMAND = createCommand("INSERT_HEADING_COMMAND");
109
+ function registerCommands(editor) {
110
+ return mergeRegister(editor.registerCommand(INSERT_QUOTE_COMMAND, () => {
111
+ editor.update(() => {
112
+ const selection = $getSelection();
113
+ if ($isRangeSelection(selection)) $setBlocksType(selection, () => $createQuoteNode());
114
+ });
115
+ return true;
116
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_HEADING_COMMAND, (payload) => {
117
+ editor.update(() => {
118
+ const selection = $getSelection();
119
+ if ($isRangeSelection(selection)) $setBlocksType(selection, () => $createHeadingNode(payload.tag));
120
+ });
121
+ return true;
122
+ }, COMMAND_PRIORITY_EDITOR));
123
+ }
124
+ //#endregion
125
+ //#region src/plugins/litexml/utils/index.ts
126
+ function $parseSerializedNodeImpl(serializedNode, editor, keepId = false, state = null) {
127
+ const type = serializedNode.type;
128
+ const registeredNode = editor._nodes.get(type);
129
+ if (registeredNode === void 0) throw new Error(`parseEditorState: type "${type}" not found`);
130
+ const nodeClass = registeredNode.klass;
131
+ if (serializedNode.type !== nodeClass.getType()) throw new Error(`LexicalNode: Node ${nodeClass.name} does not implement .importJSON().`);
132
+ if (keepId && serializedNode.id) resetRandomKey(Number(serializedNode.id));
133
+ const node = nodeClass.importJSON(serializedNode);
134
+ const children = serializedNode.children;
135
+ if ($isElementNode(node) && Array.isArray(children)) {
136
+ const childNodes = [];
137
+ for (const serializedJSONChildNode of children) {
138
+ const childNode = $parseSerializedNodeImpl(serializedJSONChildNode, editor, keepId, state);
139
+ childNodes.push(childNode);
140
+ }
141
+ node.append(...childNodes);
142
+ }
143
+ return node;
144
+ }
145
+ function exportNodeToJSON(node) {
146
+ const serializedNode = node.exportJSON();
147
+ const nodeClass = node.constructor;
148
+ if (serializedNode.type !== nodeClass.getType()) throw new Error(`LexicalNode: Node ${nodeClass.name} does not match the serialized type. Check if .exportJSON() is implemented and it is returning the correct type.`);
149
+ if ($isElementNode(node)) {
150
+ const serializedChildren = serializedNode.children;
151
+ if (!Array.isArray(serializedChildren)) throw new Error(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
152
+ const children = node.getChildren();
153
+ for (const child of children) {
154
+ const serializedChildNode = exportNodeToJSON(child);
155
+ serializedChildren.push(serializedChildNode);
156
+ }
157
+ }
158
+ return serializedNode;
159
+ }
160
+ function $cloneNode(node, editor) {
161
+ return $parseSerializedNodeImpl(exportNodeToJSON(node), editor);
162
+ }
163
+ const maxId = 1679616;
164
+ const startId = 1e6;
165
+ const step = 7211;
166
+ const modInverse = 1394051;
167
+ function idToChar(id) {
168
+ return ((Number(id) * step + startId) % maxId).toString(36).padStart(4, "0");
169
+ }
170
+ function charToId(char) {
171
+ return String((parseInt(char, 36) - startId + maxId) * modInverse % maxId);
172
+ }
173
+ //#endregion
174
+ //#region src/plugins/inode/service/index.ts
175
+ /**
176
+ * Service ID for Node service
177
+ */
178
+ const INodeService = genServiceId("INodeService");
179
+ /**
180
+ * Default implementation of INodeService
181
+ */
182
+ var NodeService = class {
183
+ constructor() {
184
+ this.processNodeTreeHandlers = [];
185
+ }
186
+ registerProcessNodeTree(process) {
187
+ this.processNodeTreeHandlers.push(process);
188
+ }
189
+ processNodeTree(inode) {
190
+ for (const handler of this.processNodeTreeHandlers) handler(inode);
191
+ }
192
+ };
193
+ //#endregion
194
+ //#region src/plugins/inode/plugin/index.ts
195
+ /**
196
+ * LitexmlPlugin - A plugin that provides XML-based data source support
197
+ * Allows converting between Lexical editor state and XML format
198
+ */
199
+ const INodePlugin = class extends KernelPlugin {
200
+ static {
201
+ this.pluginName = "INodePlugin";
202
+ }
203
+ constructor(kernel, config) {
204
+ super();
205
+ this.kernel = kernel;
206
+ this.config = config;
207
+ const nodeService = new NodeService();
208
+ kernel.registerService(INodeService, nodeService);
209
+ }
210
+ onInit() {}
211
+ };
212
+ //#endregion
213
+ //#region src/plugins/litexml/service/litexml-service.ts
214
+ /**
215
+ * Service ID for Litexml service
216
+ */
217
+ const ILitexmlService = genServiceId("ILitexmlService");
218
+ /**
219
+ * Default implementation of ILitexmlService
220
+ */
221
+ var LitexmlService = class {
222
+ constructor() {
223
+ this.readers = {};
224
+ this.writers = {};
225
+ }
226
+ registerXMLReader(tagName, reader) {
227
+ const key = tagName.toLowerCase();
228
+ if (this.readers[key]) {
229
+ const existing = this.readers[key];
230
+ this.readers[key] = Array.isArray(existing) ? [...existing, reader] : [existing, reader];
231
+ } else this.readers[key] = reader;
232
+ }
233
+ registerXMLWriter(nodeType, writer) {
234
+ if (this.writers[nodeType]) {
235
+ const existing = this.writers[nodeType];
236
+ this.writers[nodeType] = Array.isArray(existing) ? [...existing, writer] : [existing, writer];
237
+ } else this.writers[nodeType] = writer;
238
+ }
239
+ getXMLReaders() {
240
+ return { ...this.readers };
241
+ }
242
+ getXMLWriters() {
243
+ return { ...this.writers };
244
+ }
245
+ hasXMLReader(tagName) {
246
+ return !!this.readers[tagName.toLowerCase()];
247
+ }
248
+ hasXMLWriter(nodeType) {
249
+ return !!this.writers[nodeType];
250
+ }
251
+ };
252
+ //#endregion
106
253
  //#region node_modules/.pnpm/mdast-util-to-string@4.0.0/node_modules/mdast-util-to-string/lib/index.js
107
254
  /**
108
255
  * @typedef {import('mdast').Nodes} Nodes
@@ -18524,7 +18671,7 @@ function registerDefaultReaders(markdownReaders) {
18524
18671
  };
18525
18672
  }
18526
18673
  function parseMarkdownToLexical(markdown, markdownReaders = {}) {
18527
- const ast = remark().use(remarkCjkFriendly).use(remarkMath).use([[remarkGfm, { singleTilde: false }]]).parse(preprocessMarkdownContent(markdown));
18674
+ const ast = remark().use(remarkCjkFriendly).use(remarkMath).use([[remarkGfm, { singleTilde: false }]]).parse(markdown);
18528
18675
  logger$2.debug("Parsed MDAST:", ast);
18529
18676
  const ctx = new MarkdownContext(ast);
18530
18677
  registerDefaultReaders(markdownReaders);
@@ -18740,45 +18887,6 @@ function registerMarkdownCommand(editor, kernel, service) {
18740
18887
  }, COMMAND_PRIORITY_HIGH));
18741
18888
  }
18742
18889
  //#endregion
18743
- //#region src/plugins/inode/service/index.ts
18744
- /**
18745
- * Service ID for Node service
18746
- */
18747
- const INodeService = genServiceId("INodeService");
18748
- /**
18749
- * Default implementation of INodeService
18750
- */
18751
- var NodeService = class {
18752
- constructor() {
18753
- this.processNodeTreeHandlers = [];
18754
- }
18755
- registerProcessNodeTree(process) {
18756
- this.processNodeTreeHandlers.push(process);
18757
- }
18758
- processNodeTree(inode) {
18759
- for (const handler of this.processNodeTreeHandlers) handler(inode);
18760
- }
18761
- };
18762
- //#endregion
18763
- //#region src/plugins/inode/plugin/index.ts
18764
- /**
18765
- * LitexmlPlugin - A plugin that provides XML-based data source support
18766
- * Allows converting between Lexical editor state and XML format
18767
- */
18768
- const INodePlugin = class extends KernelPlugin {
18769
- static {
18770
- this.pluginName = "INodePlugin";
18771
- }
18772
- constructor(kernel, config) {
18773
- super();
18774
- this.kernel = kernel;
18775
- this.config = config;
18776
- const nodeService = new NodeService();
18777
- kernel.registerService(INodeService, nodeService);
18778
- }
18779
- onInit() {}
18780
- };
18781
- //#endregion
18782
18890
  //#region src/plugins/markdown/data-source/markdown-writer-context.ts
18783
18891
  var MarkdownWriterContext = class MarkdownWriterContext {
18784
18892
  constructor(markdownService) {
@@ -19718,163 +19826,55 @@ const ReactMarkdownPlugin = () => {
19718
19826
  };
19719
19827
  ReactMarkdownPlugin.displayName = "ReactMarkdownPlugin";
19720
19828
  //#endregion
19721
- //#region src/plugins/common/command/index.ts
19722
- const INSERT_QUOTE_COMMAND = createCommand("INSERT_QUOTE_COMMAND");
19723
- const INSERT_HEADING_COMMAND = createCommand("INSERT_HEADING_COMMAND");
19724
- function registerCommands(editor) {
19725
- return mergeRegister(editor.registerCommand(INSERT_QUOTE_COMMAND, () => {
19726
- editor.update(() => {
19727
- const selection = $getSelection();
19728
- if ($isRangeSelection(selection)) $setBlocksType(selection, () => $createQuoteNode());
19729
- });
19730
- return true;
19731
- }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_HEADING_COMMAND, (payload) => {
19732
- editor.update(() => {
19733
- const selection = $getSelection();
19734
- if ($isRangeSelection(selection)) $setBlocksType(selection, () => $createHeadingNode(payload.tag));
19735
- });
19736
- return true;
19737
- }, COMMAND_PRIORITY_EDITOR));
19738
- }
19739
- //#endregion
19740
- //#region src/plugins/litexml/utils/index.ts
19741
- function $parseSerializedNodeImpl(serializedNode, editor, keepId = false, state = null) {
19742
- const type = serializedNode.type;
19743
- const registeredNode = editor._nodes.get(type);
19744
- if (registeredNode === void 0) throw new Error(`parseEditorState: type "${type}" not found`);
19745
- const nodeClass = registeredNode.klass;
19746
- if (serializedNode.type !== nodeClass.getType()) throw new Error(`LexicalNode: Node ${nodeClass.name} does not implement .importJSON().`);
19747
- if (keepId && serializedNode.id) resetRandomKey(Number(serializedNode.id));
19748
- const node = nodeClass.importJSON(serializedNode);
19749
- const children = serializedNode.children;
19750
- if ($isElementNode(node) && Array.isArray(children)) {
19751
- const childNodes = [];
19752
- for (const serializedJSONChildNode of children) {
19753
- const childNode = $parseSerializedNodeImpl(serializedJSONChildNode, editor, keepId, state);
19754
- childNodes.push(childNode);
19755
- }
19756
- node.append(...childNodes);
19757
- }
19758
- return node;
19759
- }
19760
- function exportNodeToJSON(node) {
19761
- const serializedNode = node.exportJSON();
19762
- const nodeClass = node.constructor;
19763
- if (serializedNode.type !== nodeClass.getType()) throw new Error(`LexicalNode: Node ${nodeClass.name} does not match the serialized type. Check if .exportJSON() is implemented and it is returning the correct type.`);
19764
- if ($isElementNode(node)) {
19765
- const serializedChildren = serializedNode.children;
19766
- if (!Array.isArray(serializedChildren)) throw new Error(`LexicalNode: Node ${nodeClass.name} is an element but .exportJSON() does not have a children array.`);
19767
- const children = node.getChildren();
19768
- for (const child of children) {
19769
- const serializedChildNode = exportNodeToJSON(child);
19770
- serializedChildren.push(serializedChildNode);
19771
- }
19772
- }
19773
- return serializedNode;
19774
- }
19775
- function $cloneNode(node, editor) {
19776
- return $parseSerializedNodeImpl(exportNodeToJSON(node), editor);
19777
- }
19778
- const maxId = 1679616;
19779
- const startId = 1e6;
19780
- const step = 7211;
19781
- const modInverse = 1394051;
19782
- function idToChar(id) {
19783
- return ((Number(id) * step + startId) % maxId).toString(36).padStart(4, "0");
19784
- }
19785
- function charToId(char) {
19786
- return String((parseInt(char, 36) - startId + maxId) * modInverse % maxId);
19787
- }
19788
- //#endregion
19789
- //#region src/plugins/litexml/service/litexml-service.ts
19790
- /**
19791
- * Service ID for Litexml service
19792
- */
19793
- const ILitexmlService = genServiceId("ILitexmlService");
19794
- /**
19795
- * Default implementation of ILitexmlService
19796
- */
19797
- var LitexmlService = class {
19798
- constructor() {
19799
- this.readers = {};
19800
- this.writers = {};
19801
- }
19802
- registerXMLReader(tagName, reader) {
19803
- const key = tagName.toLowerCase();
19804
- if (this.readers[key]) {
19805
- const existing = this.readers[key];
19806
- this.readers[key] = Array.isArray(existing) ? [...existing, reader] : [existing, reader];
19807
- } else this.readers[key] = reader;
19808
- }
19809
- registerXMLWriter(nodeType, writer) {
19810
- if (this.writers[nodeType]) {
19811
- const existing = this.writers[nodeType];
19812
- this.writers[nodeType] = Array.isArray(existing) ? [...existing, writer] : [existing, writer];
19813
- } else this.writers[nodeType] = writer;
19814
- }
19815
- getXMLReaders() {
19816
- return { ...this.readers };
19817
- }
19818
- getXMLWriters() {
19819
- return { ...this.writers };
19820
- }
19821
- hasXMLReader(tagName) {
19822
- return !!this.readers[tagName.toLowerCase()];
19823
- }
19824
- hasXMLWriter(nodeType) {
19825
- return !!this.writers[nodeType];
19826
- }
19827
- };
19828
- //#endregion
19829
- //#region src/plugins/common/data-source/json-data-source.ts
19830
- init_helper();
19831
- init_utils$1();
19832
- var JSONDataSource = class extends DataSource {
19833
- read(editor, data, options = {}) {
19834
- let dataObj;
19835
- if (typeof data === "string") dataObj = JSON.parse(data);
19836
- else dataObj = data;
19837
- const process = (node) => {
19838
- for (let i = 0; i < node.children.length; i++) {
19839
- const child = node.children[i];
19840
- if ("children" in child && Array.isArray(child.children)) process(child);
19841
- if (child.type === "text" && "format" in child && typeof child.format === "number" && (child.format & IS_CODE) > 0) {
19842
- node.children[i] = {
19843
- children: [{
19844
- ...child,
19845
- format: child.format & ~IS_CODE
19846
- }],
19847
- direction: "ltr",
19848
- format: "",
19849
- indent: 0,
19850
- type: "codeInline",
19851
- version: 1
19852
- };
19853
- node.children.splice(i + 1, 0, cursorNodeSerialized);
19854
- }
19855
- }
19856
- };
19857
- process(dataObj.root);
19858
- if (dataObj.keepId || options.keepId) {
19859
- const state = editor.parseEditorState({ root: INodeHelper.createRootNode() }, (state) => {
19860
- try {
19861
- const root = $parseSerializedNodeImpl(dataObj.root, editor, true, state);
19862
- let maxId = -1;
19863
- Array.from(state._nodeMap.keys()).forEach((key) => {
19864
- if (key === "root") return;
19865
- maxId = Math.max(maxId, Number(key));
19866
- });
19867
- resetRandomKey(maxId + 1);
19868
- state._nodeMap.set(root.getKey(), root);
19869
- } catch (error) {
19870
- console.error(error);
19871
- }
19872
- });
19873
- editor.setEditorState(state);
19874
- } else editor.setEditorState(editor.parseEditorState({ root: dataObj.root }));
19875
- }
19876
- write(editor, options) {
19877
- if (options?.selection) return editor.getEditorState().read(() => {
19829
+ //#region src/plugins/common/data-source/json-data-source.ts
19830
+ init_helper();
19831
+ init_utils$1();
19832
+ var JSONDataSource = class extends DataSource {
19833
+ read(editor, data, options = {}) {
19834
+ let dataObj;
19835
+ if (typeof data === "string") dataObj = JSON.parse(data);
19836
+ else dataObj = data;
19837
+ const process = (node) => {
19838
+ for (let i = 0; i < node.children.length; i++) {
19839
+ const child = node.children[i];
19840
+ if ("children" in child && Array.isArray(child.children)) process(child);
19841
+ if (child.type === "text" && "format" in child && typeof child.format === "number" && (child.format & IS_CODE) > 0) {
19842
+ node.children[i] = {
19843
+ children: [{
19844
+ ...child,
19845
+ format: child.format & ~IS_CODE
19846
+ }],
19847
+ direction: "ltr",
19848
+ format: "",
19849
+ indent: 0,
19850
+ type: "codeInline",
19851
+ version: 1
19852
+ };
19853
+ node.children.splice(i + 1, 0, cursorNodeSerialized);
19854
+ }
19855
+ }
19856
+ };
19857
+ process(dataObj.root);
19858
+ if (dataObj.keepId || options.keepId) {
19859
+ const state = editor.parseEditorState({ root: INodeHelper.createRootNode() }, (state) => {
19860
+ try {
19861
+ const root = $parseSerializedNodeImpl(dataObj.root, editor, true, state);
19862
+ let maxId = -1;
19863
+ Array.from(state._nodeMap.keys()).forEach((key) => {
19864
+ if (key === "root") return;
19865
+ maxId = Math.max(maxId, Number(key));
19866
+ });
19867
+ resetRandomKey(maxId + 1);
19868
+ state._nodeMap.set(root.getKey(), root);
19869
+ } catch (error) {
19870
+ console.error(error);
19871
+ }
19872
+ });
19873
+ editor.setEditorState(state);
19874
+ } else editor.setEditorState(editor.parseEditorState({ root: dataObj.root }));
19875
+ }
19876
+ write(editor, options) {
19877
+ if (options?.selection) return editor.getEditorState().read(() => {
19878
19878
  const selection = $getSelection();
19879
19879
  if (!selection) return null;
19880
19880
  if ($isRangeSelection(selection)) {
@@ -21071,6 +21071,149 @@ function registerCodeInlineCommand(editor) {
21071
21071
  }, COMMAND_PRIORITY_EDITOR);
21072
21072
  }
21073
21073
  //#endregion
21074
+ //#region src/plugins/list/plugin/checkList.ts
21075
+ /**
21076
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
21077
+ *
21078
+ * This source code is licensed under the MIT license found in the
21079
+ * LICENSE file in the root directory of this source tree.
21080
+ *
21081
+ */
21082
+ const INSERT_CHECK_LIST_COMMAND = createCommand("INSERT_CHECK_LIST_COMMAND");
21083
+ function isHeadlessEditor$1(editor) {
21084
+ return editor._headless === true;
21085
+ }
21086
+ function handleCheckItemEvent(event, callback) {
21087
+ const target = event.target;
21088
+ if (!isHTMLElement$1(target)) return;
21089
+ const firstChild = target.firstChild;
21090
+ if (isHTMLElement$1(firstChild) && (firstChild.tagName === "UL" || firstChild.tagName === "OL")) return;
21091
+ const parentNode = target.parentNode;
21092
+ if (!parentNode || parentNode.__lexicalListType !== "check") return;
21093
+ const rect = target.getBoundingClientRect();
21094
+ const zoom = calculateZoomLevel(target);
21095
+ const clientX = event.clientX / zoom;
21096
+ const beforeStyles = window.getComputedStyle ? window.getComputedStyle(target, "::before") : { width: "0px" };
21097
+ const beforeWidthInPixels = parseFloat(beforeStyles.width);
21098
+ const beforeMargin = parseFloat(beforeStyles.marginLeft);
21099
+ const clickAreaPadding = event.pointerType === "touch" ? 32 : 0;
21100
+ if (target.dir === "rtl" ? clientX < rect.right + clickAreaPadding && clientX > rect.right - beforeWidthInPixels - clickAreaPadding : clientX > rect.left + beforeMargin - clickAreaPadding && clientX < rect.left + beforeMargin + beforeWidthInPixels + clickAreaPadding) callback();
21101
+ }
21102
+ function handleClick(event) {
21103
+ handleCheckItemEvent(event, () => {
21104
+ if (isHTMLElement$1(event.target)) {
21105
+ const domNode = event.target;
21106
+ const editor = getNearestEditorFromDOMNode(domNode);
21107
+ if (editor && editor.isEditable()) editor.update(() => {
21108
+ const node = $getNearestNodeFromDOMNode(domNode);
21109
+ if ($isListItemNode(node)) {
21110
+ domNode.focus();
21111
+ node.toggleChecked();
21112
+ }
21113
+ });
21114
+ }
21115
+ });
21116
+ }
21117
+ function handlePointerDown(event) {
21118
+ handleCheckItemEvent(event, () => {
21119
+ event.preventDefault();
21120
+ });
21121
+ }
21122
+ function getActiveCheckListItem() {
21123
+ const activeElement = document.activeElement;
21124
+ return isHTMLElement$1(activeElement) && activeElement.tagName === "LI" && activeElement.parentNode && activeElement.parentNode.__lexicalListType === "check" ? activeElement : null;
21125
+ }
21126
+ function findCheckListItemSibling(node, backward) {
21127
+ let sibling = backward ? node.getPreviousSibling() : node.getNextSibling();
21128
+ let parent = node;
21129
+ while (!sibling && $isListItemNode(parent)) {
21130
+ parent = parent.getParentOrThrow().getParent();
21131
+ if (parent) sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling();
21132
+ }
21133
+ while ($isListItemNode(sibling)) {
21134
+ const firstChild = backward ? sibling.getLastChild() : sibling.getFirstChild();
21135
+ if (!$isListNode(firstChild)) return sibling;
21136
+ sibling = backward ? firstChild.getLastChild() : firstChild.getFirstChild();
21137
+ }
21138
+ return null;
21139
+ }
21140
+ function handleArrowUpOrDown(event, editor, backward) {
21141
+ const activeItem = getActiveCheckListItem();
21142
+ if (activeItem) editor.update(() => {
21143
+ const listItem = $getNearestNodeFromDOMNode(activeItem);
21144
+ if (!$isListItemNode(listItem)) return;
21145
+ const nextListItem = findCheckListItemSibling(listItem, backward);
21146
+ if (nextListItem) {
21147
+ nextListItem.selectStart();
21148
+ const dom = editor.getElementByKey(nextListItem.__key);
21149
+ if (dom) {
21150
+ event.preventDefault();
21151
+ setTimeout(() => {
21152
+ dom.focus();
21153
+ }, 0);
21154
+ }
21155
+ }
21156
+ });
21157
+ return false;
21158
+ }
21159
+ function registerCheckList(editor) {
21160
+ const registrations = [
21161
+ editor.registerCommand(INSERT_CHECK_LIST_COMMAND, () => {
21162
+ $insertList("check");
21163
+ return true;
21164
+ }, COMMAND_PRIORITY_LOW),
21165
+ editor.registerCommand(KEY_ARROW_DOWN_COMMAND, (event) => {
21166
+ return handleArrowUpOrDown(event, editor, false);
21167
+ }, COMMAND_PRIORITY_LOW),
21168
+ editor.registerCommand(KEY_ARROW_UP_COMMAND, (event) => {
21169
+ return handleArrowUpOrDown(event, editor, true);
21170
+ }, COMMAND_PRIORITY_LOW),
21171
+ editor.registerCommand(KEY_ARROW_LEFT_COMMAND, (event) => {
21172
+ return editor.getEditorState().read(() => {
21173
+ const selection = $getSelection();
21174
+ if ($isRangeSelection(selection) && selection.isCollapsed()) {
21175
+ const { anchor } = selection;
21176
+ const isElement = anchor.type === "element";
21177
+ if (isElement || anchor.offset === 0) {
21178
+ const anchorNode = anchor.getNode();
21179
+ const elementNode = $findMatchingParent(anchorNode, (node) => $isElementNode(node) && !node.isInline());
21180
+ if ($isListItemNode(elementNode)) {
21181
+ const parent = elementNode.getParent();
21182
+ if ($isListNode(parent) && parent.getListType() === "check" && (isElement || elementNode.getFirstDescendant() === anchorNode)) {
21183
+ const domNode = editor.getElementByKey(elementNode.__key);
21184
+ if (domNode && document.activeElement !== domNode) {
21185
+ domNode.focus();
21186
+ event.preventDefault();
21187
+ return true;
21188
+ }
21189
+ }
21190
+ }
21191
+ }
21192
+ }
21193
+ return false;
21194
+ });
21195
+ }, COMMAND_PRIORITY_LOW)
21196
+ ];
21197
+ if (!isHeadlessEditor$1(editor)) registrations.push(editor.registerRootListener((rootElement, prevElement) => {
21198
+ if (rootElement !== null) {
21199
+ rootElement.addEventListener("click", handleClick);
21200
+ rootElement.addEventListener("pointerdown", handlePointerDown);
21201
+ }
21202
+ if (prevElement !== null) {
21203
+ prevElement.removeEventListener("click", handleClick);
21204
+ prevElement.removeEventListener("pointerdown", handlePointerDown);
21205
+ }
21206
+ }));
21207
+ return mergeRegister(...registrations);
21208
+ }
21209
+ //#endregion
21210
+ //#region src/plugins/codeblock/utils/language.ts
21211
+ function getCodeLanguageByInput(input) {
21212
+ if (!input) return "plaintext";
21213
+ const inputLang = input.toLocaleLowerCase();
21214
+ return bundledLanguagesInfo.find((lang) => lang.id === inputLang || lang.aliases?.includes(inputLang))?.id || "plaintext";
21215
+ }
21216
+ //#endregion
21074
21217
  //#region src/plugins/codeblock/plugin/FacadeShiki.ts
21075
21218
  init_helper();
21076
21219
  const shiki = createHighlighterCoreSync({
@@ -21712,13 +21855,6 @@ function registerCodeCommand(editor) {
21712
21855
  };
21713
21856
  }
21714
21857
  //#endregion
21715
- //#region src/plugins/codeblock/utils/language.ts
21716
- function getCodeLanguageByInput(input) {
21717
- if (!input) return "plaintext";
21718
- const inputLang = input.toLocaleLowerCase();
21719
- return bundledLanguagesInfo.find((lang) => lang.id === inputLang || lang.aliases?.includes(inputLang))?.id || "plaintext";
21720
- }
21721
- //#endregion
21722
21858
  //#region src/plugins/codeblock/plugin/index.ts
21723
21859
  init_helper();
21724
21860
  init_plugin();
@@ -21743,6 +21879,9 @@ function toMarkdownTheme(theme) {
21743
21879
  if (typeof theme === "string") return theme;
21744
21880
  return `${theme.light} ${theme.dark}`;
21745
21881
  }
21882
+ function isHeadlessEditor(editor) {
21883
+ return editor._headless === true;
21884
+ }
21746
21885
  const CodeblockPlugin = class extends KernelPlugin {
21747
21886
  static {
21748
21887
  this.pluginName = "CodeblockPlugin";
@@ -21756,10 +21895,10 @@ const CodeblockPlugin = class extends KernelPlugin {
21756
21895
  if (this.config?.shikiTheme) CustomShikiTokenizer.defaultTheme = this.config?.shikiTheme;
21757
21896
  }
21758
21897
  onInit(editor) {
21759
- if (this.config?.shikiTheme) this.register(registerCodeHighlighting(editor, CustomShikiTokenizer));
21898
+ if (!isHeadlessEditor(editor)) if (this.config?.shikiTheme) this.register(registerCodeHighlighting(editor, CustomShikiTokenizer));
21760
21899
  else this.register(registerCodeHighlighting(editor));
21761
21900
  this.register(registerCodeCommand(editor));
21762
- this.register(editor.registerCommand(PASTE_COMMAND, (event) => {
21901
+ if (!isHeadlessEditor(editor)) this.register(editor.registerCommand(PASTE_COMMAND, (event) => {
21763
21902
  if (!(event instanceof ClipboardEvent)) return false;
21764
21903
  const clipboardData = event.clipboardData;
21765
21904
  if (!clipboardData) return false;
@@ -22015,132 +22154,6 @@ function registerLinkHighlightCommand(editor) {
22015
22154
  }, COMMAND_PRIORITY_EDITOR);
22016
22155
  }
22017
22156
  //#endregion
22018
- //#region src/plugins/list/plugin/checkList.ts
22019
- /**
22020
- * Copyright (c) Meta Platforms, Inc. and affiliates.
22021
- *
22022
- * This source code is licensed under the MIT license found in the
22023
- * LICENSE file in the root directory of this source tree.
22024
- *
22025
- */
22026
- const INSERT_CHECK_LIST_COMMAND = createCommand("INSERT_CHECK_LIST_COMMAND");
22027
- function handleCheckItemEvent(event, callback) {
22028
- const target = event.target;
22029
- if (!isHTMLElement$1(target)) return;
22030
- const firstChild = target.firstChild;
22031
- if (isHTMLElement$1(firstChild) && (firstChild.tagName === "UL" || firstChild.tagName === "OL")) return;
22032
- const parentNode = target.parentNode;
22033
- if (!parentNode || parentNode.__lexicalListType !== "check") return;
22034
- const rect = target.getBoundingClientRect();
22035
- const zoom = calculateZoomLevel(target);
22036
- const clientX = event.clientX / zoom;
22037
- const beforeStyles = window.getComputedStyle ? window.getComputedStyle(target, "::before") : { width: "0px" };
22038
- const beforeWidthInPixels = parseFloat(beforeStyles.width);
22039
- const beforeMargin = parseFloat(beforeStyles.marginLeft);
22040
- const clickAreaPadding = event.pointerType === "touch" ? 32 : 0;
22041
- if (target.dir === "rtl" ? clientX < rect.right + clickAreaPadding && clientX > rect.right - beforeWidthInPixels - clickAreaPadding : clientX > rect.left + beforeMargin - clickAreaPadding && clientX < rect.left + beforeMargin + beforeWidthInPixels + clickAreaPadding) callback();
22042
- }
22043
- function handleClick(event) {
22044
- handleCheckItemEvent(event, () => {
22045
- if (isHTMLElement$1(event.target)) {
22046
- const domNode = event.target;
22047
- const editor = getNearestEditorFromDOMNode(domNode);
22048
- if (editor && editor.isEditable()) editor.update(() => {
22049
- const node = $getNearestNodeFromDOMNode(domNode);
22050
- if ($isListItemNode(node)) {
22051
- domNode.focus();
22052
- node.toggleChecked();
22053
- }
22054
- });
22055
- }
22056
- });
22057
- }
22058
- function handlePointerDown(event) {
22059
- handleCheckItemEvent(event, () => {
22060
- event.preventDefault();
22061
- });
22062
- }
22063
- function getActiveCheckListItem() {
22064
- const activeElement = document.activeElement;
22065
- return isHTMLElement$1(activeElement) && activeElement.tagName === "LI" && activeElement.parentNode && activeElement.parentNode.__lexicalListType === "check" ? activeElement : null;
22066
- }
22067
- function findCheckListItemSibling(node, backward) {
22068
- let sibling = backward ? node.getPreviousSibling() : node.getNextSibling();
22069
- let parent = node;
22070
- while (!sibling && $isListItemNode(parent)) {
22071
- parent = parent.getParentOrThrow().getParent();
22072
- if (parent) sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling();
22073
- }
22074
- while ($isListItemNode(sibling)) {
22075
- const firstChild = backward ? sibling.getLastChild() : sibling.getFirstChild();
22076
- if (!$isListNode(firstChild)) return sibling;
22077
- sibling = backward ? firstChild.getLastChild() : firstChild.getFirstChild();
22078
- }
22079
- return null;
22080
- }
22081
- function handleArrowUpOrDown(event, editor, backward) {
22082
- const activeItem = getActiveCheckListItem();
22083
- if (activeItem) editor.update(() => {
22084
- const listItem = $getNearestNodeFromDOMNode(activeItem);
22085
- if (!$isListItemNode(listItem)) return;
22086
- const nextListItem = findCheckListItemSibling(listItem, backward);
22087
- if (nextListItem) {
22088
- nextListItem.selectStart();
22089
- const dom = editor.getElementByKey(nextListItem.__key);
22090
- if (dom) {
22091
- event.preventDefault();
22092
- setTimeout(() => {
22093
- dom.focus();
22094
- }, 0);
22095
- }
22096
- }
22097
- });
22098
- return false;
22099
- }
22100
- function registerCheckList(editor) {
22101
- return mergeRegister(editor.registerCommand(INSERT_CHECK_LIST_COMMAND, () => {
22102
- $insertList("check");
22103
- return true;
22104
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, (event) => {
22105
- return handleArrowUpOrDown(event, editor, false);
22106
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_UP_COMMAND, (event) => {
22107
- return handleArrowUpOrDown(event, editor, true);
22108
- }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, (event) => {
22109
- return editor.getEditorState().read(() => {
22110
- const selection = $getSelection();
22111
- if ($isRangeSelection(selection) && selection.isCollapsed()) {
22112
- const { anchor } = selection;
22113
- const isElement = anchor.type === "element";
22114
- if (isElement || anchor.offset === 0) {
22115
- const anchorNode = anchor.getNode();
22116
- const elementNode = $findMatchingParent(anchorNode, (node) => $isElementNode(node) && !node.isInline());
22117
- if ($isListItemNode(elementNode)) {
22118
- const parent = elementNode.getParent();
22119
- if ($isListNode(parent) && parent.getListType() === "check" && (isElement || elementNode.getFirstDescendant() === anchorNode)) {
22120
- const domNode = editor.getElementByKey(elementNode.__key);
22121
- if (domNode && document.activeElement !== domNode) {
22122
- domNode.focus();
22123
- event.preventDefault();
22124
- return true;
22125
- }
22126
- }
22127
- }
22128
- }
22129
- }
22130
- return false;
22131
- });
22132
- }, COMMAND_PRIORITY_LOW), editor.registerRootListener((rootElement, prevElement) => {
22133
- if (rootElement !== null) {
22134
- rootElement.addEventListener("click", handleClick);
22135
- rootElement.addEventListener("pointerdown", handlePointerDown);
22136
- }
22137
- if (prevElement !== null) {
22138
- prevElement.removeEventListener("click", handleClick);
22139
- prevElement.removeEventListener("pointerdown", handlePointerDown);
22140
- }
22141
- }));
22142
- }
22143
- //#endregion
22144
22157
  //#region src/plugins/mention/command/index.ts
22145
22158
  const INSERT_MENTION_COMMAND = createCommand("INSERT_MENTION_COMMAND");
22146
22159
  function registerMentionCommand(editor) {
@@ -22927,4 +22940,4 @@ const ReactSlashPlugin = ({ children, anchorClassName, getPopupContainer, placem
22927
22940
  };
22928
22941
  ReactSlashPlugin.displayName = "ReactSlashPlugin";
22929
22942
  //#endregion
22930
- export { idToChar as A, MARKDOWN_READER_LEVEL_NORMAL as B, ReactEditorContent as C, $cloneNode as D, LitexmlService as E, MarkdownPlugin as F, INSERT_MARKDOWN_COMMAND as G, INodePlugin as H, detectCodeLanguage as I, ReactEditor as J, isPunctuationChar as K, detectLanguage as L, INSERT_QUOTE_COMMAND as M, ReactMarkdownPlugin as N, $parseSerializedNodeImpl as O, useTranslation as P, IMarkdownShortCutService as R, ReactPlainText as S, ILitexmlService as T, INodeService as U, MARKDOWN_WRITER_LEVEL_MAX as V, GET_MARKDOWN_SELECTION_COMMAND as W, LexicalErrorBoundary as X, useLexicalComposerContext as Y, bundledLanguagesInfo$1 as _, ReactMentionPlugin as a, INSERT_CODEINLINE_COMMAND as b, INSERT_CHECK_LIST_COMMAND as c, registerLinkHighlightCommand as d, extractUrlFromText as f, useLexicalNodeSelection as g, validateUrl as h, SlashPlugin as i, INSERT_HEADING_COMMAND as j, charToId as k, registerCheckList as l, sanitizeUrl as m, ReactSlashOption as n, MentionPlugin as o, getSelectedNode as p, useLexicalEditor as q, SlashMenu as r, INSERT_MENTION_COMMAND as s, ReactSlashPlugin as t, INSERT_LINK_HIGHLIGHT_COMMAND as u, CodeblockPlugin as v, CommonPlugin as w, registerCodeInlineCommand as x, UPDATE_CODEBLOCK_LANG as y, MARKDOWN_READER_LEVEL_HIGH as z };
22943
+ export { detectLanguage as A, INodePlugin as B, ReactPlainText as C, useTranslation as D, ReactMarkdownPlugin as E, GET_MARKDOWN_SELECTION_COMMAND as F, idToChar as G, $cloneNode as H, INSERT_MARKDOWN_COMMAND as I, useLexicalEditor as J, INSERT_HEADING_COMMAND as K, isPunctuationChar as L, MARKDOWN_READER_LEVEL_HIGH as M, MARKDOWN_READER_LEVEL_NORMAL as N, MarkdownPlugin as O, MARKDOWN_WRITER_LEVEL_MAX as P, ILitexmlService as R, registerCodeInlineCommand as S, CommonPlugin as T, $parseSerializedNodeImpl as U, INodeService as V, charToId as W, useLexicalComposerContext as X, ReactEditor as Y, LexicalErrorBoundary as Z, UPDATE_CODEBLOCK_LANG as _, ReactMentionPlugin as a, registerCheckList as b, INSERT_LINK_HIGHLIGHT_COMMAND as c, getSelectedNode as d, sanitizeUrl as f, CodeblockPlugin as g, bundledLanguagesInfo$1 as h, SlashPlugin as i, IMarkdownShortCutService as j, detectCodeLanguage as k, registerLinkHighlightCommand as l, useLexicalNodeSelection as m, ReactSlashOption as n, MentionPlugin as o, validateUrl as p, INSERT_QUOTE_COMMAND as q, SlashMenu as r, INSERT_MENTION_COMMAND as s, ReactSlashPlugin as t, extractUrlFromText as u, getCodeLanguageByInput as v, ReactEditorContent as w, INSERT_CODEINLINE_COMMAND as x, INSERT_CHECK_LIST_COMMAND as y, LitexmlService as z };