@haklex/rich-editor 0.1.1 → 0.3.0
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.
- package/dist/AlertQuoteEditNode-C55sxsR3.js +267 -0
- package/dist/KaTeXRenderer-CQQT3BMw.js +215 -0
- package/dist/LinkCardRenderer-CigqFwCv.js +45 -0
- package/dist/MermaidPlugin-BrOr-wQi.js +67 -0
- package/dist/RubyRenderer-jOkydJHg.js +15 -0
- package/dist/SubmitShortcutPlugin-DhyVFzoj.js +2186 -0
- package/dist/commands-entry.mjs +54 -74
- package/dist/components/decorators/PollEditDecorator.d.ts +13 -0
- package/dist/components/decorators/PollEditDecorator.d.ts.map +1 -0
- package/dist/components/renderers/PollRenderer.d.ts +3 -0
- package/dist/components/renderers/PollRenderer.d.ts.map +1 -0
- package/dist/config-B5BuLljq.js +1633 -0
- package/dist/config-edit.d.ts.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/context/PollDataContext.d.ts +11 -0
- package/dist/context/PollDataContext.d.ts.map +1 -0
- package/dist/extractPolls-DO31LNrp.js +116 -0
- package/dist/grid.css-CJCkLTZc.js +44 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +121 -180
- package/dist/katex.css-CIOEOXyd.js +145 -0
- package/dist/node-registry-Dz5OTkh4.js +946 -0
- package/dist/nodes/PollEditNode.d.ts +14 -0
- package/dist/nodes/PollEditNode.d.ts.map +1 -0
- package/dist/nodes/PollNode.d.ts +52 -0
- package/dist/nodes/PollNode.d.ts.map +1 -0
- package/dist/nodes-entry.d.ts +3 -0
- package/dist/nodes-entry.d.ts.map +1 -1
- package/dist/nodes-entry.mjs +5 -50
- package/dist/normalizeSerializedEditorState-B-1wmGzd.js +78 -0
- package/dist/plugins-entry.mjs +3 -28
- package/dist/renderers-entry.mjs +41 -61
- package/dist/rich-editor.css +2 -1
- package/dist/static-entry.d.ts +5 -0
- package/dist/static-entry.d.ts.map +1 -1
- package/dist/static-entry.mjs +16 -66
- package/dist/styles/index.d.ts +2 -0
- package/dist/styles/index.d.ts.map +1 -1
- package/dist/styles/poll-edit.css.d.ts +35 -0
- package/dist/styles/poll-edit.css.d.ts.map +1 -0
- package/dist/styles/poll.css.d.ts +43 -0
- package/dist/styles/poll.css.d.ts.map +1 -0
- package/dist/styles-entry.mjs +3 -21
- package/dist/theme-B5B2EOWM.js +1099 -0
- package/dist/types/poll.d.ts +36 -0
- package/dist/types/poll.d.ts.map +1 -0
- package/dist/types/renderer-config.d.ts +3 -0
- package/dist/types/renderer-config.d.ts.map +1 -1
- package/dist/utils/extractPolls.d.ts +4 -0
- package/dist/utils/extractPolls.d.ts.map +1 -0
- package/package.json +30 -30
- package/dist/AlertQuoteEditNode-sPNf3_7P.js +0 -293
- package/dist/KaTeXRenderer-CQyQzNTJ.js +0 -218
- package/dist/LinkCardRenderer-QmkOlyXb.js +0 -36
- package/dist/MermaidPlugin-DKuGUcCG.js +0 -101
- package/dist/PresentDialogContext-DRroMIoK.js +0 -71
- package/dist/RubyRenderer-CJQmODir.js +0 -14
- package/dist/SubmitShortcutPlugin-D9uKYHda.js +0 -2427
- package/dist/config-Dl3ZkytB.js +0 -1362
- package/dist/grid.css-Md5-Cfx_.js +0 -11
- package/dist/katex.css-Csc-7N7u.js +0 -28
- package/dist/node-registry-CovhHUB6.js +0 -824
- package/dist/normalizeSerializedEditorState-k5G4xSi9.js +0 -85
- package/dist/theme-lEwScxEX.js +0 -1113
|
@@ -1,2427 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { CheckListPlugin } from "@lexical/react/LexicalCheckListPlugin";
|
|
3
|
-
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
|
|
4
|
-
import { ListPlugin } from "@lexical/react/LexicalListPlugin";
|
|
5
|
-
import { TabIndentationPlugin } from "@lexical/react/LexicalTabIndentationPlugin";
|
|
6
|
-
import { TablePlugin } from "@lexical/react/LexicalTablePlugin";
|
|
7
|
-
import { createLinkMatcherWithRegExp, registerAutoLink, LinkNode, AutoLinkNode } from "@lexical/link";
|
|
8
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
9
|
-
import { useEffect, createContext, use, useRef, useState, useMemo, useCallback, useSyncExternalStore } from "react";
|
|
10
|
-
import { $isQuoteNode, QuoteNode, $createQuoteNode, DRAG_DROP_PASTE } from "@lexical/rich-text";
|
|
11
|
-
import { KEY_ARROW_RIGHT_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_CRITICAL, KEY_ARROW_DOWN_COMMAND, $isDecoratorNode, $isElementNode, $isRootNode, $isParagraphNode, $createParagraphNode, KEY_ENTER_COMMAND, $isNodeSelection, KEY_BACKSPACE_COMMAND, COMMAND_PRIORITY_HIGH, KEY_DELETE_COMMAND, KEY_ARROW_UP_COMMAND, $isTextNode, IS_CODE, $createNodeSelection, $setSelection, $getRoot, $getNodeByKey, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, $createTextNode, $createLineBreakNode, PASTE_COMMAND, $insertNodes, createEditor, $parseSerializedNode, createState, $getState, $addUpdateTag, $setState, $isLineBreakNode, $createRangeSelection, SELECTION_CHANGE_COMMAND, $nodesOfType } from "lexical";
|
|
12
|
-
import { b as setCodeBlockCursorIntent, g as getResolvedEditNodes, $ as $createBannerEditNode, d as $createCodeBlockEditNode } from "./node-registry-CovhHUB6.js";
|
|
13
|
-
import { HorizontalRuleNode, $createHorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from "@lexical/extension";
|
|
14
|
-
import { HORIZONTAL_RULE_BLOCK_TRANSFORMER as HORIZONTAL_RULE_BLOCK_TRANSFORMER$1, GIT_ALERT_TRANSFORMER as GIT_ALERT_TRANSFORMER$1, COMMENT_TRANSFORMER as COMMENT_TRANSFORMER$1, CONTAINER_TRANSFORMER as CONTAINER_TRANSFORMER$1, FOOTNOTE_TRANSFORMER as FOOTNOTE_TRANSFORMER$1, FOOTNOTE_SECTION_TRANSFORMER as FOOTNOTE_SECTION_TRANSFORMER$1, KATEX_INLINE_TRANSFORMER as KATEX_INLINE_TRANSFORMER$1, KATEX_BLOCK_TRANSFORMER as KATEX_BLOCK_TRANSFORMER$1, MENTION_TRANSFORMER as MENTION_TRANSFORMER$1, RUBY_TRANSFORMER as RUBY_TRANSFORMER$1, SPOILER_TRANSFORMER as SPOILER_TRANSFORMER$1, INSERT_TRANSFORMER, SUPERSCRIPT_TRANSFORMER, SUBSCRIPT_TRANSFORMER, IMAGE_BLOCK_TRANSFORMER, VIDEO_BLOCK_TRANSFORMER, CODE_BLOCK_NODE_TRANSFORMER, LINK_CARD_BLOCK_TRANSFORMER, MERMAID_BLOCK_TRANSFORMER, TABLE_BLOCK_TRANSFORMER } from "@haklex/rich-headless/transformers";
|
|
15
|
-
import { CHECK_LIST, TRANSFORMERS, QUOTE, CODE, $convertFromMarkdownString } from "@lexical/markdown";
|
|
16
|
-
import { $ as $createAlertQuoteEditNode } from "./AlertQuoteEditNode-sPNf3_7P.js";
|
|
17
|
-
import { v as AlertQuoteNode, F as FootnoteNode, y as $createFootnoteNode, k as KaTeXInlineNode, K as KaTeXBlockNode, w as $createKaTeXInlineNode, x as $createKaTeXBlockNode, M as MentionNode, a as $createMentionNode, o as extractTextContent, S as SpoilerNode, q as $createSpoilerNode, $ as $createImageNode, O as OPEN_IMAGE_UPLOAD_DIALOG_COMMAND } from "./theme-lEwScxEX.js";
|
|
18
|
-
import { v as CodeBlockNode, C as CommentNode, w as $createCommentPlaceholderNode, $ as $createCommentNode, q as BannerNode, D as DetailsNode, x as $createDetailsNode, F as FootnoteSectionNode, f as $isFootnoteSectionNode, a as $createFootnoteSectionNode, g as $isGridContainerNode, R as RubyNode, d as $createRubyNode } from "./config-Dl3ZkytB.js";
|
|
19
|
-
import { $createTableNode, $createTableRowNode, $createTableCellNode, TableCellHeaderStates } from "@lexical/table";
|
|
20
|
-
import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin";
|
|
21
|
-
import { Dialog, DialogPopup, DialogTitle, SegmentedControl, ActionButton, ActionBar } from "@haklex/rich-editor-ui";
|
|
22
|
-
import { Check, Info, Upload, Link2 } from "lucide-react";
|
|
23
|
-
import { i as computeImageMeta, F as FootnoteDefinitionsProvider } from "./KaTeXRenderer-CQyQzNTJ.js";
|
|
24
|
-
import "./katex.css-Csc-7N7u.js";
|
|
25
|
-
import { g as getHostname, p as probeFavicon, n as normalizeSerializedEditorState } from "./normalizeSerializedEditorState-k5G4xSi9.js";
|
|
26
|
-
import { nanoid } from "nanoid";
|
|
27
|
-
const URL_REGEX = /https?:\/\/(?:www\.)?[\w#%+.:=@~-]{1,256}\.[A-Za-z]{2}[\w#%&()+./:=?@~-]*/;
|
|
28
|
-
const EMAIL_REGEX = /(?:[\w%+.-]+@[\d.a-z-]+\.[a-z]{2,})/i;
|
|
29
|
-
const URL_MATCHER = createLinkMatcherWithRegExp(URL_REGEX);
|
|
30
|
-
const EMAIL_MATCHER = createLinkMatcherWithRegExp(EMAIL_REGEX, (text) => `mailto:${text}`);
|
|
31
|
-
const DEFAULT_MATCHERS = [URL_MATCHER, EMAIL_MATCHER];
|
|
32
|
-
function AutoLinkPlugin({ matchers }) {
|
|
33
|
-
const [editor] = useLexicalComposerContext();
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
return registerAutoLink(editor, {
|
|
36
|
-
matchers: matchers ?? DEFAULT_MATCHERS,
|
|
37
|
-
changeHandlers: [],
|
|
38
|
-
excludeParents: []
|
|
39
|
-
});
|
|
40
|
-
}, [editor, matchers]);
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
function selectDecoratorNode(node, cursorPlacement = "start") {
|
|
44
|
-
if (node.getType() === "code-block") {
|
|
45
|
-
setCodeBlockCursorIntent(node.getKey(), cursorPlacement);
|
|
46
|
-
}
|
|
47
|
-
const selection = $createNodeSelection();
|
|
48
|
-
selection.add(node.getKey());
|
|
49
|
-
$setSelection(selection);
|
|
50
|
-
}
|
|
51
|
-
function isAtTopLevelBoundary(selection, direction) {
|
|
52
|
-
const point = selection.anchor;
|
|
53
|
-
const topLevel = point.getNode().getTopLevelElementOrThrow();
|
|
54
|
-
const pointNode = point.getNode();
|
|
55
|
-
if (point.type === "text") {
|
|
56
|
-
if (!$isTextNode(pointNode)) return false;
|
|
57
|
-
const expectedOffset = direction === "start" ? 0 : pointNode.getTextContentSize();
|
|
58
|
-
if (point.offset !== expectedOffset) return false;
|
|
59
|
-
} else {
|
|
60
|
-
if (!$isElementNode(pointNode)) return false;
|
|
61
|
-
const expectedOffset = direction === "start" ? 0 : pointNode.getChildrenSize();
|
|
62
|
-
if (point.offset !== expectedOffset) return false;
|
|
63
|
-
}
|
|
64
|
-
let current = pointNode;
|
|
65
|
-
while (current && current !== topLevel) {
|
|
66
|
-
const sibling = direction === "start" ? current.getPreviousSibling() : current.getNextSibling();
|
|
67
|
-
if (sibling !== null) return false;
|
|
68
|
-
current = current.getParent();
|
|
69
|
-
}
|
|
70
|
-
return current === topLevel;
|
|
71
|
-
}
|
|
72
|
-
function isSingleLineParagraph(node) {
|
|
73
|
-
return $isParagraphNode(node) && !node.getTextContent().includes("\n");
|
|
74
|
-
}
|
|
75
|
-
function getOutermostNodeWithinTopLevel(node, topLevel) {
|
|
76
|
-
let current = node;
|
|
77
|
-
while (current.getParent() !== topLevel) {
|
|
78
|
-
const parent = current.getParent();
|
|
79
|
-
if (!parent) break;
|
|
80
|
-
current = parent;
|
|
81
|
-
}
|
|
82
|
-
return current;
|
|
83
|
-
}
|
|
84
|
-
function isDeeplyEmptyElement(node) {
|
|
85
|
-
if (!$isElementNode(node)) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
if (node.getChildrenSize() === 0) {
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
for (const child of node.getChildren()) {
|
|
92
|
-
if ($isTextNode(child)) {
|
|
93
|
-
if (child.getTextContent().trim().length > 0) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (!$isElementNode(child) || !isDeeplyEmptyElement(child)) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
function isSelectionInsideTopLevel(selection, topLevelKey) {
|
|
105
|
-
return selection.anchor.getNode().getTopLevelElementOrThrow().getKey() === topLevelKey && selection.focus.getNode().getTopLevelElementOrThrow().getKey() === topLevelKey;
|
|
106
|
-
}
|
|
107
|
-
function exitInlineCodeAtLineEnd(selection) {
|
|
108
|
-
if (!selection.isCollapsed() || selection.anchor.type !== "text") {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
const anchorNode = selection.anchor.getNode();
|
|
112
|
-
if (!$isTextNode(anchorNode) || !anchorNode.hasFormat("code")) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
if (selection.anchor.offset !== anchorNode.getTextContentSize()) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
if (!isAtTopLevelBoundary(selection, "end")) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const topLevel = anchorNode.getTopLevelElementOrThrow();
|
|
122
|
-
const boundaryNode = getOutermostNodeWithinTopLevel(anchorNode, topLevel);
|
|
123
|
-
const exitOffset = boundaryNode.getIndexWithinParent() + 1;
|
|
124
|
-
selection.anchor.set(topLevel.getKey(), exitOffset, "element");
|
|
125
|
-
selection.focus.set(topLevel.getKey(), exitOffset, "element");
|
|
126
|
-
selection.setFormat(anchorNode.getFormat() & ~IS_CODE);
|
|
127
|
-
selection.setStyle(anchorNode.getStyle());
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
function BlockExitPlugin() {
|
|
131
|
-
const [editor] = useLexicalComposerContext();
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
return registerBlockExitCommands(editor);
|
|
134
|
-
}, [editor]);
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
function registerBlockExitCommands(editor) {
|
|
138
|
-
let virtualParagraphKey = null;
|
|
139
|
-
const clearVirtualParagraph = () => {
|
|
140
|
-
virtualParagraphKey = null;
|
|
141
|
-
};
|
|
142
|
-
const getVirtualParagraph = () => {
|
|
143
|
-
if (!virtualParagraphKey) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
const node = $getNodeByKey(virtualParagraphKey);
|
|
147
|
-
return $isParagraphNode(node) ? node : null;
|
|
148
|
-
};
|
|
149
|
-
const insertVirtualParagraph = (target, position, cursorPlacement = "start") => {
|
|
150
|
-
const paragraph = $createParagraphNode();
|
|
151
|
-
if (position === "before") {
|
|
152
|
-
target.insertBefore(paragraph);
|
|
153
|
-
} else {
|
|
154
|
-
target.insertAfter(paragraph);
|
|
155
|
-
}
|
|
156
|
-
virtualParagraphKey = paragraph.getKey();
|
|
157
|
-
if (cursorPlacement === "end") {
|
|
158
|
-
paragraph.selectEnd();
|
|
159
|
-
} else {
|
|
160
|
-
paragraph.selectStart();
|
|
161
|
-
}
|
|
162
|
-
return true;
|
|
163
|
-
};
|
|
164
|
-
const unregisterVirtualParagraphCleanup = editor.registerUpdateListener(({ editorState }) => {
|
|
165
|
-
if (!virtualParagraphKey) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
let shouldKeepTracking = false;
|
|
169
|
-
let shouldRemove = false;
|
|
170
|
-
editorState.read(() => {
|
|
171
|
-
const paragraph = getVirtualParagraph();
|
|
172
|
-
if (!paragraph) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
const selection = $getSelection();
|
|
176
|
-
if ($isRangeSelection(selection) && isSelectionInsideTopLevel(selection, paragraph.getKey())) {
|
|
177
|
-
shouldKeepTracking = true;
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
shouldRemove = isDeeplyEmptyElement(paragraph);
|
|
181
|
-
});
|
|
182
|
-
if (shouldKeepTracking) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
editor.update(() => {
|
|
186
|
-
const paragraph = getVirtualParagraph();
|
|
187
|
-
if (paragraph && shouldRemove && isDeeplyEmptyElement(paragraph)) {
|
|
188
|
-
paragraph.remove();
|
|
189
|
-
}
|
|
190
|
-
clearVirtualParagraph();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
const unregisterArrowRight = editor.registerCommand(
|
|
194
|
-
KEY_ARROW_RIGHT_COMMAND,
|
|
195
|
-
(event) => {
|
|
196
|
-
const selection = $getSelection();
|
|
197
|
-
if (!$isRangeSelection(selection)) return false;
|
|
198
|
-
if (!exitInlineCodeAtLineEnd(selection)) return false;
|
|
199
|
-
event?.preventDefault();
|
|
200
|
-
return true;
|
|
201
|
-
},
|
|
202
|
-
COMMAND_PRIORITY_CRITICAL
|
|
203
|
-
);
|
|
204
|
-
const unregisterArrowDown = editor.registerCommand(
|
|
205
|
-
KEY_ARROW_DOWN_COMMAND,
|
|
206
|
-
(event) => {
|
|
207
|
-
const selection = $getSelection();
|
|
208
|
-
if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
const anchorNode = selection.anchor.getNode();
|
|
212
|
-
const topLevelElement = anchorNode.getTopLevelElementOrThrow();
|
|
213
|
-
const shouldSelectNextDecorator = isAtTopLevelBoundary(selection, "end") || isSingleLineParagraph(topLevelElement);
|
|
214
|
-
if (!$isQuoteNode(topLevelElement) && shouldSelectNextDecorator) {
|
|
215
|
-
const next = topLevelElement.getNextSibling();
|
|
216
|
-
if (next && $isDecoratorNode(next) && next.isKeyboardSelectable()) {
|
|
217
|
-
event?.preventDefault();
|
|
218
|
-
selectDecoratorNode(next, "start");
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const element = $isElementNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
223
|
-
let quoteChild = element;
|
|
224
|
-
let quoteNode = null;
|
|
225
|
-
let current = element;
|
|
226
|
-
while (current) {
|
|
227
|
-
const parent = current.getParent();
|
|
228
|
-
if (!parent || $isRootNode(parent)) break;
|
|
229
|
-
if ($isQuoteNode(parent)) {
|
|
230
|
-
quoteNode = parent;
|
|
231
|
-
quoteChild = current;
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
current = parent;
|
|
235
|
-
}
|
|
236
|
-
if (quoteNode && quoteChild.getNextSibling() === null && $isParagraphNode(quoteChild) && quoteChild.getTextContent() === "") {
|
|
237
|
-
event?.preventDefault();
|
|
238
|
-
let next = quoteNode.getNextSibling();
|
|
239
|
-
if (!next) {
|
|
240
|
-
next = $createParagraphNode();
|
|
241
|
-
quoteNode.insertAfter(next);
|
|
242
|
-
}
|
|
243
|
-
next.selectStart();
|
|
244
|
-
return true;
|
|
245
|
-
}
|
|
246
|
-
if (!event?.shiftKey && topLevelElement.getNextSibling() === null && isAtTopLevelBoundary(selection, "end") && topLevelElement.getKey() !== virtualParagraphKey && !isDeeplyEmptyElement(topLevelElement)) {
|
|
247
|
-
event?.preventDefault();
|
|
248
|
-
return insertVirtualParagraph(topLevelElement, "after");
|
|
249
|
-
}
|
|
250
|
-
return false;
|
|
251
|
-
},
|
|
252
|
-
COMMAND_PRIORITY_CRITICAL
|
|
253
|
-
);
|
|
254
|
-
const unregisterCmdEnter = editor.registerCommand(
|
|
255
|
-
KEY_ENTER_COMMAND,
|
|
256
|
-
(event) => {
|
|
257
|
-
if (!event?.metaKey && !event?.ctrlKey) return false;
|
|
258
|
-
const selection = $getSelection();
|
|
259
|
-
if ($isNodeSelection(selection)) {
|
|
260
|
-
const nodes = selection.getNodes();
|
|
261
|
-
if (nodes.length !== 1) return false;
|
|
262
|
-
const node = nodes[0];
|
|
263
|
-
if (!$isDecoratorNode(node)) return false;
|
|
264
|
-
event.preventDefault();
|
|
265
|
-
let next2 = node.getNextSibling();
|
|
266
|
-
if (!next2) {
|
|
267
|
-
next2 = $createParagraphNode();
|
|
268
|
-
node.insertAfter(next2);
|
|
269
|
-
}
|
|
270
|
-
if ($isElementNode(next2)) {
|
|
271
|
-
next2.selectStart();
|
|
272
|
-
} else if ($isDecoratorNode(next2)) {
|
|
273
|
-
selectDecoratorNode(next2, "start");
|
|
274
|
-
}
|
|
275
|
-
return true;
|
|
276
|
-
}
|
|
277
|
-
if (!$isRangeSelection(selection)) return false;
|
|
278
|
-
const anchorNode = selection.anchor.getNode();
|
|
279
|
-
const topLevelElement = anchorNode.getTopLevelElementOrThrow();
|
|
280
|
-
if ($isParagraphNode(topLevelElement)) return false;
|
|
281
|
-
event.preventDefault();
|
|
282
|
-
let next = topLevelElement.getNextSibling();
|
|
283
|
-
if (!next || !$isParagraphNode(next)) {
|
|
284
|
-
next = $createParagraphNode();
|
|
285
|
-
topLevelElement.insertAfter(next);
|
|
286
|
-
}
|
|
287
|
-
next.selectStart();
|
|
288
|
-
return true;
|
|
289
|
-
},
|
|
290
|
-
COMMAND_PRIORITY_CRITICAL
|
|
291
|
-
);
|
|
292
|
-
function handleDeleteDecorator(event) {
|
|
293
|
-
const selection = $getSelection();
|
|
294
|
-
if (!$isNodeSelection(selection)) return false;
|
|
295
|
-
const nodes = selection.getNodes();
|
|
296
|
-
if (nodes.length !== 1) return false;
|
|
297
|
-
const node = nodes[0];
|
|
298
|
-
if (!$isDecoratorNode(node)) return false;
|
|
299
|
-
event?.preventDefault();
|
|
300
|
-
const prev = node.getPreviousSibling();
|
|
301
|
-
const next = node.getNextSibling();
|
|
302
|
-
node.remove();
|
|
303
|
-
if (prev && $isElementNode(prev)) {
|
|
304
|
-
prev.selectEnd();
|
|
305
|
-
} else if (prev && $isDecoratorNode(prev)) {
|
|
306
|
-
selectDecoratorNode(prev, "end");
|
|
307
|
-
} else if (next && $isElementNode(next)) {
|
|
308
|
-
next.selectStart();
|
|
309
|
-
} else if (next && $isDecoratorNode(next)) {
|
|
310
|
-
selectDecoratorNode(next, "start");
|
|
311
|
-
} else {
|
|
312
|
-
const root = $getRoot();
|
|
313
|
-
if (root && $isElementNode(root)) {
|
|
314
|
-
const p = $createParagraphNode();
|
|
315
|
-
root.append(p);
|
|
316
|
-
p.selectStart();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
const unregisterBackspace = editor.registerCommand(
|
|
322
|
-
KEY_BACKSPACE_COMMAND,
|
|
323
|
-
handleDeleteDecorator,
|
|
324
|
-
COMMAND_PRIORITY_HIGH
|
|
325
|
-
);
|
|
326
|
-
const unregisterDelete = editor.registerCommand(
|
|
327
|
-
KEY_DELETE_COMMAND,
|
|
328
|
-
handleDeleteDecorator,
|
|
329
|
-
COMMAND_PRIORITY_HIGH
|
|
330
|
-
);
|
|
331
|
-
const unregisterArrowUpDecorator = editor.registerCommand(
|
|
332
|
-
KEY_ARROW_UP_COMMAND,
|
|
333
|
-
(event) => {
|
|
334
|
-
const selection = $getSelection();
|
|
335
|
-
if ($isRangeSelection(selection) && selection.isCollapsed()) {
|
|
336
|
-
const anchorNode = selection.anchor.getNode();
|
|
337
|
-
const topLevelElement = anchorNode.getTopLevelElementOrThrow();
|
|
338
|
-
const shouldSelectPreviousDecorator = isAtTopLevelBoundary(selection, "start") || isSingleLineParagraph(topLevelElement);
|
|
339
|
-
if (!$isQuoteNode(topLevelElement) && shouldSelectPreviousDecorator) {
|
|
340
|
-
const prev2 = topLevelElement.getPreviousSibling();
|
|
341
|
-
if (prev2 && $isDecoratorNode(prev2) && prev2.isKeyboardSelectable()) {
|
|
342
|
-
event?.preventDefault();
|
|
343
|
-
selectDecoratorNode(prev2, "end");
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (!event?.shiftKey && topLevelElement.getPreviousSibling() === null && isAtTopLevelBoundary(selection, "start") && topLevelElement.getKey() !== virtualParagraphKey && !isDeeplyEmptyElement(topLevelElement)) {
|
|
348
|
-
event?.preventDefault();
|
|
349
|
-
return insertVirtualParagraph(topLevelElement, "before");
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
if (!$isNodeSelection(selection)) return false;
|
|
353
|
-
const nodes = selection.getNodes();
|
|
354
|
-
if (nodes.length !== 1) return false;
|
|
355
|
-
const node = nodes[0];
|
|
356
|
-
if (!$isDecoratorNode(node)) return false;
|
|
357
|
-
const prev = node.getPreviousSibling();
|
|
358
|
-
if (prev && $isElementNode(prev)) {
|
|
359
|
-
event?.preventDefault();
|
|
360
|
-
prev.selectEnd();
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
if (prev && $isDecoratorNode(prev)) {
|
|
364
|
-
event?.preventDefault();
|
|
365
|
-
selectDecoratorNode(prev, "end");
|
|
366
|
-
return true;
|
|
367
|
-
}
|
|
368
|
-
if (!event?.shiftKey && node.getTopLevelElementOrThrow().getPreviousSibling() === null && node.getKey() !== virtualParagraphKey) {
|
|
369
|
-
event?.preventDefault();
|
|
370
|
-
return insertVirtualParagraph(node, "before", "end");
|
|
371
|
-
}
|
|
372
|
-
return false;
|
|
373
|
-
},
|
|
374
|
-
COMMAND_PRIORITY_CRITICAL
|
|
375
|
-
);
|
|
376
|
-
const unregisterArrowDownDecorator = editor.registerCommand(
|
|
377
|
-
KEY_ARROW_DOWN_COMMAND,
|
|
378
|
-
(event) => {
|
|
379
|
-
const selection = $getSelection();
|
|
380
|
-
if (!$isNodeSelection(selection)) return false;
|
|
381
|
-
const nodes = selection.getNodes();
|
|
382
|
-
if (nodes.length !== 1) return false;
|
|
383
|
-
const node = nodes[0];
|
|
384
|
-
if (!$isDecoratorNode(node)) return false;
|
|
385
|
-
const next = node.getNextSibling();
|
|
386
|
-
if (next && $isElementNode(next)) {
|
|
387
|
-
event?.preventDefault();
|
|
388
|
-
next.selectStart();
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
if (next && $isDecoratorNode(next)) {
|
|
392
|
-
event?.preventDefault();
|
|
393
|
-
selectDecoratorNode(next, "start");
|
|
394
|
-
return true;
|
|
395
|
-
}
|
|
396
|
-
if (!event?.shiftKey && node.getTopLevelElementOrThrow().getNextSibling() === null && node.getKey() !== virtualParagraphKey) {
|
|
397
|
-
event?.preventDefault();
|
|
398
|
-
return insertVirtualParagraph(node, "after");
|
|
399
|
-
}
|
|
400
|
-
return false;
|
|
401
|
-
},
|
|
402
|
-
COMMAND_PRIORITY_CRITICAL
|
|
403
|
-
);
|
|
404
|
-
return () => {
|
|
405
|
-
unregisterVirtualParagraphCleanup();
|
|
406
|
-
unregisterArrowRight();
|
|
407
|
-
unregisterArrowDown();
|
|
408
|
-
unregisterCmdEnter();
|
|
409
|
-
unregisterBackspace();
|
|
410
|
-
unregisterDelete();
|
|
411
|
-
unregisterArrowUpDecorator();
|
|
412
|
-
unregisterArrowDownDecorator();
|
|
413
|
-
clearVirtualParagraph();
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
const HORIZONTAL_RULE_REGEX = /^(---|\*\*\*|___)\s?$/;
|
|
417
|
-
const HORIZONTAL_RULE_BLOCK_TRANSFORMER = {
|
|
418
|
-
...HORIZONTAL_RULE_BLOCK_TRANSFORMER$1,
|
|
419
|
-
dependencies: [HorizontalRuleNode],
|
|
420
|
-
regExp: HORIZONTAL_RULE_REGEX,
|
|
421
|
-
replace: (parentNode) => {
|
|
422
|
-
const hrNode = $createHorizontalRuleNode();
|
|
423
|
-
const paragraph = $createParagraphNode();
|
|
424
|
-
parentNode.replace(hrNode);
|
|
425
|
-
hrNode.insertAfter(paragraph);
|
|
426
|
-
paragraph.selectStart();
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
function HorizontalRulePlugin() {
|
|
430
|
-
const [editor] = useLexicalComposerContext();
|
|
431
|
-
useEffect(() => {
|
|
432
|
-
const unregisterInsert = editor.registerCommand(
|
|
433
|
-
INSERT_HORIZONTAL_RULE_COMMAND,
|
|
434
|
-
() => {
|
|
435
|
-
const selection = $getSelection();
|
|
436
|
-
if (!$isRangeSelection(selection)) return false;
|
|
437
|
-
const focusNode = selection.focus.getNode();
|
|
438
|
-
const topLevel = focusNode.getTopLevelElement();
|
|
439
|
-
if (!topLevel) return false;
|
|
440
|
-
const hrNode = $createHorizontalRuleNode();
|
|
441
|
-
const paragraph = $createParagraphNode();
|
|
442
|
-
topLevel.insertAfter(hrNode);
|
|
443
|
-
hrNode.insertAfter(paragraph);
|
|
444
|
-
paragraph.selectStart();
|
|
445
|
-
return true;
|
|
446
|
-
},
|
|
447
|
-
COMMAND_PRIORITY_EDITOR
|
|
448
|
-
);
|
|
449
|
-
const unregisterEnter = editor.registerCommand(
|
|
450
|
-
KEY_ENTER_COMMAND,
|
|
451
|
-
(event) => {
|
|
452
|
-
const selection = $getSelection();
|
|
453
|
-
if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
|
|
454
|
-
return false;
|
|
455
|
-
}
|
|
456
|
-
const anchorNode = selection.anchor.getNode();
|
|
457
|
-
if (!$isTextNode(anchorNode)) return false;
|
|
458
|
-
const textContent = anchorNode.getTextContent();
|
|
459
|
-
if (!HORIZONTAL_RULE_REGEX.test(textContent)) return false;
|
|
460
|
-
const parentNode = anchorNode.getParent();
|
|
461
|
-
if (!parentNode) return false;
|
|
462
|
-
event?.preventDefault();
|
|
463
|
-
const hrNode = $createHorizontalRuleNode();
|
|
464
|
-
const paragraph = $createParagraphNode();
|
|
465
|
-
parentNode.replace(hrNode);
|
|
466
|
-
hrNode.insertAfter(paragraph);
|
|
467
|
-
paragraph.selectStart();
|
|
468
|
-
return true;
|
|
469
|
-
},
|
|
470
|
-
COMMAND_PRIORITY_LOW
|
|
471
|
-
);
|
|
472
|
-
return () => {
|
|
473
|
-
unregisterInsert();
|
|
474
|
-
unregisterEnter();
|
|
475
|
-
};
|
|
476
|
-
}, [editor]);
|
|
477
|
-
return null;
|
|
478
|
-
}
|
|
479
|
-
const ALERT_TYPE_MAP = {
|
|
480
|
-
NOTE: "note",
|
|
481
|
-
TIP: "tip",
|
|
482
|
-
IMPORTANT: "important",
|
|
483
|
-
WARNING: "warning",
|
|
484
|
-
CAUTION: "caution"
|
|
485
|
-
};
|
|
486
|
-
const GIT_ALERT_TRANSFORMER = {
|
|
487
|
-
...GIT_ALERT_TRANSFORMER$1,
|
|
488
|
-
dependencies: [AlertQuoteNode],
|
|
489
|
-
regExp: /^>\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/,
|
|
490
|
-
replace: (parentNode, children, match) => {
|
|
491
|
-
const typeKey = match[1];
|
|
492
|
-
const alertType = ALERT_TYPE_MAP[typeKey] || "note";
|
|
493
|
-
const serializedChildren = children.map((child) => child.exportJSON());
|
|
494
|
-
const content = {
|
|
495
|
-
root: {
|
|
496
|
-
children: [
|
|
497
|
-
{
|
|
498
|
-
type: "paragraph",
|
|
499
|
-
children: serializedChildren,
|
|
500
|
-
direction: null,
|
|
501
|
-
format: "",
|
|
502
|
-
indent: 0,
|
|
503
|
-
textFormat: 0,
|
|
504
|
-
textStyle: "",
|
|
505
|
-
version: 1
|
|
506
|
-
}
|
|
507
|
-
],
|
|
508
|
-
direction: null,
|
|
509
|
-
format: "",
|
|
510
|
-
indent: 0,
|
|
511
|
-
type: "root",
|
|
512
|
-
version: 1
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
const alertNode = $createAlertQuoteEditNode(alertType, content);
|
|
516
|
-
parentNode.replace(alertNode);
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
function findCodeBlockKlass(nodes) {
|
|
520
|
-
return nodes.find((n) => n.getType?.() === "code-block") || CodeBlockNode;
|
|
521
|
-
}
|
|
522
|
-
const CODE_BLOCK_MULTILINE_TRANSFORMER = {
|
|
523
|
-
dependencies: [],
|
|
524
|
-
regExpEnd: {
|
|
525
|
-
optional: true,
|
|
526
|
-
regExp: /[\t ]*```$/
|
|
527
|
-
},
|
|
528
|
-
regExpStart: /^[\t ]*```([\w-]+)?/,
|
|
529
|
-
replace: (rootNode, _children, startMatch, _endMatch, linesInBetween, isImport) => {
|
|
530
|
-
const lang = startMatch[1] || "";
|
|
531
|
-
let code = "";
|
|
532
|
-
if (linesInBetween) {
|
|
533
|
-
const lines = [...linesInBetween];
|
|
534
|
-
while (lines.length > 0 && !lines[0].length) lines.shift();
|
|
535
|
-
while (lines.length > 0 && !lines.at(-1)?.length) lines.pop();
|
|
536
|
-
code = lines.join("\n");
|
|
537
|
-
}
|
|
538
|
-
const Klass = findCodeBlockKlass(getResolvedEditNodes());
|
|
539
|
-
const node = new Klass(code, lang);
|
|
540
|
-
if (isImport || $isRootNode(rootNode)) {
|
|
541
|
-
rootNode.append(node);
|
|
542
|
-
} else {
|
|
543
|
-
rootNode.replace(node);
|
|
544
|
-
}
|
|
545
|
-
const selection = $createNodeSelection();
|
|
546
|
-
selection.add(node.getKey());
|
|
547
|
-
$setSelection(selection);
|
|
548
|
-
},
|
|
549
|
-
type: "multiline-element"
|
|
550
|
-
};
|
|
551
|
-
const NEVER = /a^/;
|
|
552
|
-
const COMMENT_OPEN_TRANSFORMER = {
|
|
553
|
-
dependencies: [CommentNode],
|
|
554
|
-
export: () => null,
|
|
555
|
-
importRegExp: NEVER,
|
|
556
|
-
regExp: /<!--$/,
|
|
557
|
-
replace: (textNode) => {
|
|
558
|
-
const node = $createCommentPlaceholderNode();
|
|
559
|
-
textNode.replace(node);
|
|
560
|
-
node.select(0, node.getTextContentSize());
|
|
561
|
-
},
|
|
562
|
-
trigger: "-",
|
|
563
|
-
type: "text-match"
|
|
564
|
-
};
|
|
565
|
-
const COMMENT_TRANSFORMER = {
|
|
566
|
-
...COMMENT_TRANSFORMER$1,
|
|
567
|
-
dependencies: [CommentNode],
|
|
568
|
-
replace: (textNode, match) => {
|
|
569
|
-
textNode.replace($createCommentNode(match[1] ?? ""));
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
const BANNER_TYPE_MAP = {
|
|
573
|
-
note: "note",
|
|
574
|
-
info: "note",
|
|
575
|
-
tip: "tip",
|
|
576
|
-
success: "tip",
|
|
577
|
-
important: "important",
|
|
578
|
-
warning: "warning",
|
|
579
|
-
warn: "warning",
|
|
580
|
-
error: "caution",
|
|
581
|
-
danger: "caution",
|
|
582
|
-
caution: "caution"
|
|
583
|
-
};
|
|
584
|
-
const CONTAINER_TRANSFORMER = {
|
|
585
|
-
...CONTAINER_TRANSFORMER$1,
|
|
586
|
-
dependencies: [BannerNode, DetailsNode],
|
|
587
|
-
regExp: /^:::\s*(\w+)(?:\{([^}]*)\})?\s*$/,
|
|
588
|
-
replace: (parentNode, children, match) => {
|
|
589
|
-
const type = match[1];
|
|
590
|
-
const params = match[2];
|
|
591
|
-
if (type in BANNER_TYPE_MAP) {
|
|
592
|
-
const bannerType = BANNER_TYPE_MAP[type];
|
|
593
|
-
const serializedChildren = children.map(
|
|
594
|
-
(child) => child.exportJSON()
|
|
595
|
-
);
|
|
596
|
-
const content = {
|
|
597
|
-
root: {
|
|
598
|
-
children: [
|
|
599
|
-
{
|
|
600
|
-
type: "paragraph",
|
|
601
|
-
children: serializedChildren,
|
|
602
|
-
direction: null,
|
|
603
|
-
format: "",
|
|
604
|
-
indent: 0,
|
|
605
|
-
textFormat: 0,
|
|
606
|
-
textStyle: "",
|
|
607
|
-
version: 1
|
|
608
|
-
}
|
|
609
|
-
],
|
|
610
|
-
direction: null,
|
|
611
|
-
format: "",
|
|
612
|
-
indent: 0,
|
|
613
|
-
type: "root",
|
|
614
|
-
version: 1
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
const banner = $createBannerEditNode(bannerType, content);
|
|
618
|
-
parentNode.replace(banner);
|
|
619
|
-
return;
|
|
620
|
-
}
|
|
621
|
-
if (type === "details") {
|
|
622
|
-
const summaryMatch = params?.match(/summary="([^"]*)"/);
|
|
623
|
-
const summary = summaryMatch ? summaryMatch[1] : "Details";
|
|
624
|
-
const details = $createDetailsNode(summary);
|
|
625
|
-
children.forEach((child) => {
|
|
626
|
-
details.append(child);
|
|
627
|
-
});
|
|
628
|
-
parentNode.replace(details);
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
const paragraph = $createParagraphNode();
|
|
632
|
-
paragraph.append($createTextNode(`::: ${type}`));
|
|
633
|
-
children.forEach((child) => {
|
|
634
|
-
paragraph.append(child);
|
|
635
|
-
});
|
|
636
|
-
parentNode.replace(paragraph);
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
const FOOTNOTE_TRANSFORMER = {
|
|
640
|
-
...FOOTNOTE_TRANSFORMER$1,
|
|
641
|
-
dependencies: [FootnoteNode],
|
|
642
|
-
replace: (textNode, match) => {
|
|
643
|
-
const footnoteNode = $createFootnoteNode(match[1]);
|
|
644
|
-
textNode.replace(footnoteNode);
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
const FOOTNOTE_SECTION_TRANSFORMER = {
|
|
648
|
-
...FOOTNOTE_SECTION_TRANSFORMER$1,
|
|
649
|
-
dependencies: [FootnoteSectionNode],
|
|
650
|
-
regExp: /^\[\^(\w+)\]:[\t ]+(\S.*)$/,
|
|
651
|
-
replace: (parentNode, _children, match) => {
|
|
652
|
-
const identifier = match[1];
|
|
653
|
-
const content = match[2];
|
|
654
|
-
const root = parentNode.getParent();
|
|
655
|
-
if (root) {
|
|
656
|
-
const children = root.getChildren();
|
|
657
|
-
for (const child of children) {
|
|
658
|
-
if ($isFootnoteSectionNode(child)) {
|
|
659
|
-
child.setDefinition(identifier, content);
|
|
660
|
-
parentNode.remove();
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
const sectionNode = $createFootnoteSectionNode({ [identifier]: content });
|
|
666
|
-
parentNode.replace(sectionNode);
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
const KATEX_INLINE_TRANSFORMER = {
|
|
670
|
-
...KATEX_INLINE_TRANSFORMER$1,
|
|
671
|
-
dependencies: [KaTeXInlineNode],
|
|
672
|
-
replace: (textNode, match) => {
|
|
673
|
-
const katexNode = $createKaTeXInlineNode(match[1]);
|
|
674
|
-
textNode.replace(katexNode);
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
const KATEX_BLOCK_TRANSFORMER = {
|
|
678
|
-
...KATEX_BLOCK_TRANSFORMER$1,
|
|
679
|
-
dependencies: [KaTeXBlockNode],
|
|
680
|
-
replace: (textNode, match) => {
|
|
681
|
-
const katexNode = $createKaTeXBlockNode(match[1]);
|
|
682
|
-
textNode.replace(katexNode);
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
const MENTION_TRANSFORMER = {
|
|
686
|
-
...MENTION_TRANSFORMER$1,
|
|
687
|
-
dependencies: [MentionNode],
|
|
688
|
-
replace: (textNode, match) => {
|
|
689
|
-
const displayName = match[1] || void 0;
|
|
690
|
-
const mentionNode = $createMentionNode(match[2], match[3], displayName);
|
|
691
|
-
textNode.replace(mentionNode);
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
const QUOTE_TRANSFORMER = {
|
|
695
|
-
dependencies: [QuoteNode],
|
|
696
|
-
export: (node, exportChildren) => {
|
|
697
|
-
if (!$isQuoteNode(node)) {
|
|
698
|
-
return null;
|
|
699
|
-
}
|
|
700
|
-
const lines = exportChildren(node).split("\n");
|
|
701
|
-
return lines.map((line) => `> ${line}`).join("\n");
|
|
702
|
-
},
|
|
703
|
-
regExp: /^>\s/,
|
|
704
|
-
replace: (parentNode, children, _match, isImport) => {
|
|
705
|
-
if (isImport) {
|
|
706
|
-
const previousNode = parentNode.getPreviousSibling();
|
|
707
|
-
if ($isQuoteNode(previousNode)) {
|
|
708
|
-
previousNode.splice(previousNode.getChildrenSize(), 0, [
|
|
709
|
-
$createLineBreakNode(),
|
|
710
|
-
...children
|
|
711
|
-
]);
|
|
712
|
-
parentNode.remove();
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
const node = $createQuoteNode();
|
|
717
|
-
const paragraph = $createParagraphNode();
|
|
718
|
-
paragraph.append(...children);
|
|
719
|
-
node.append(paragraph);
|
|
720
|
-
parentNode.replace(node);
|
|
721
|
-
if (!isImport) {
|
|
722
|
-
paragraph.select(0, 0);
|
|
723
|
-
}
|
|
724
|
-
},
|
|
725
|
-
type: "element"
|
|
726
|
-
};
|
|
727
|
-
function quoteAttr(value) {
|
|
728
|
-
return value.replaceAll('"', '\\"');
|
|
729
|
-
}
|
|
730
|
-
const GRID_CONTAINER_BLOCK_TRANSFORMER = {
|
|
731
|
-
dependencies: [],
|
|
732
|
-
export: (node) => {
|
|
733
|
-
if (!$isGridContainerNode(node)) return null;
|
|
734
|
-
const cells = node.getCellStates().map((state) => extractTextContent(state));
|
|
735
|
-
const body = cells.map((content) => `::: cell
|
|
736
|
-
${content}
|
|
737
|
-
:::`).join("\n");
|
|
738
|
-
return `::: grid{cols=${node.getCols()} gap="${quoteAttr(node.getGap())}"}
|
|
739
|
-
${body}
|
|
740
|
-
:::`;
|
|
741
|
-
},
|
|
742
|
-
regExp: /\b\B/,
|
|
743
|
-
replace: () => {
|
|
744
|
-
},
|
|
745
|
-
type: "element"
|
|
746
|
-
};
|
|
747
|
-
const RUBY_TRANSFORMER = {
|
|
748
|
-
...RUBY_TRANSFORMER$1,
|
|
749
|
-
dependencies: [RubyNode],
|
|
750
|
-
replace: (textNode, match) => {
|
|
751
|
-
const rubyNode = $createRubyNode(match[2] ?? "");
|
|
752
|
-
const baseText = match[1] ?? "";
|
|
753
|
-
if (baseText) {
|
|
754
|
-
rubyNode.append($createTextNode(baseText));
|
|
755
|
-
}
|
|
756
|
-
textNode.replace(rubyNode);
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
const SPOILER_TRANSFORMER = {
|
|
760
|
-
...SPOILER_TRANSFORMER$1,
|
|
761
|
-
dependencies: [SpoilerNode],
|
|
762
|
-
replace: (textNode, match) => {
|
|
763
|
-
const spoilerNode = $createSpoilerNode();
|
|
764
|
-
spoilerNode.append($createTextNode(match[1]));
|
|
765
|
-
textNode.replace(spoilerNode);
|
|
766
|
-
}
|
|
767
|
-
};
|
|
768
|
-
const TABLE_ROW_REG_EXP = /^\|(.+)\|\s*$/;
|
|
769
|
-
const TABLE_DIVIDER_REG_EXP = /^\|(?:\s*:?-+:?\s*\|)+\s*$/;
|
|
770
|
-
function parseCells(row) {
|
|
771
|
-
const match = row.match(TABLE_ROW_REG_EXP);
|
|
772
|
-
if (!match) return [];
|
|
773
|
-
return match[1].split("|").map((c) => c.trim());
|
|
774
|
-
}
|
|
775
|
-
const TABLE_IMPORT_TRANSFORMER = {
|
|
776
|
-
dependencies: [],
|
|
777
|
-
export: () => null,
|
|
778
|
-
handleImportAfterStartMatch({ lines, rootNode, startLineIndex }) {
|
|
779
|
-
if (startLineIndex + 1 >= lines.length) return null;
|
|
780
|
-
const dividerLine = lines[startLineIndex + 1];
|
|
781
|
-
if (!TABLE_DIVIDER_REG_EXP.test(dividerLine)) return null;
|
|
782
|
-
const headerCells = parseCells(lines[startLineIndex]);
|
|
783
|
-
if (headerCells.length === 0) return null;
|
|
784
|
-
let endLineIndex = startLineIndex + 1;
|
|
785
|
-
const dataRows = [];
|
|
786
|
-
for (let i = startLineIndex + 2; i < lines.length; i++) {
|
|
787
|
-
if (!TABLE_ROW_REG_EXP.test(lines[i])) break;
|
|
788
|
-
dataRows.push(parseCells(lines[i]));
|
|
789
|
-
endLineIndex = i;
|
|
790
|
-
}
|
|
791
|
-
const tableNode = $createTableNode();
|
|
792
|
-
const headerRow = $createTableRowNode();
|
|
793
|
-
for (const cell of headerCells) {
|
|
794
|
-
const cellNode = $createTableCellNode(TableCellHeaderStates.ROW);
|
|
795
|
-
const p = $createParagraphNode();
|
|
796
|
-
p.append($createTextNode(cell));
|
|
797
|
-
cellNode.append(p);
|
|
798
|
-
headerRow.append(cellNode);
|
|
799
|
-
}
|
|
800
|
-
tableNode.append(headerRow);
|
|
801
|
-
for (const row of dataRows) {
|
|
802
|
-
const rowNode = $createTableRowNode();
|
|
803
|
-
for (let i = 0; i < headerCells.length; i++) {
|
|
804
|
-
const cellNode = $createTableCellNode(TableCellHeaderStates.NO_STATUS);
|
|
805
|
-
const p = $createParagraphNode();
|
|
806
|
-
p.append($createTextNode(row[i] ?? ""));
|
|
807
|
-
cellNode.append(p);
|
|
808
|
-
rowNode.append(cellNode);
|
|
809
|
-
}
|
|
810
|
-
tableNode.append(rowNode);
|
|
811
|
-
}
|
|
812
|
-
rootNode.append(tableNode);
|
|
813
|
-
return [true, endLineIndex];
|
|
814
|
-
},
|
|
815
|
-
regExpEnd: {
|
|
816
|
-
optional: true,
|
|
817
|
-
regExp: TABLE_ROW_REG_EXP
|
|
818
|
-
},
|
|
819
|
-
regExpStart: TABLE_ROW_REG_EXP,
|
|
820
|
-
replace: () => {
|
|
821
|
-
},
|
|
822
|
-
type: "multiline-element"
|
|
823
|
-
};
|
|
824
|
-
const ALL_TRANSFORMERS = [
|
|
825
|
-
// Inline transformers
|
|
826
|
-
SPOILER_TRANSFORMER,
|
|
827
|
-
MENTION_TRANSFORMER,
|
|
828
|
-
FOOTNOTE_TRANSFORMER,
|
|
829
|
-
INSERT_TRANSFORMER,
|
|
830
|
-
SUPERSCRIPT_TRANSFORMER,
|
|
831
|
-
SUBSCRIPT_TRANSFORMER,
|
|
832
|
-
RUBY_TRANSFORMER,
|
|
833
|
-
COMMENT_OPEN_TRANSFORMER,
|
|
834
|
-
COMMENT_TRANSFORMER,
|
|
835
|
-
KATEX_INLINE_TRANSFORMER,
|
|
836
|
-
// Block transformers (order matters - more specific first)
|
|
837
|
-
FOOTNOTE_SECTION_TRANSFORMER,
|
|
838
|
-
CONTAINER_TRANSFORMER,
|
|
839
|
-
GIT_ALERT_TRANSFORMER,
|
|
840
|
-
CHECK_LIST,
|
|
841
|
-
KATEX_BLOCK_TRANSFORMER,
|
|
842
|
-
IMAGE_BLOCK_TRANSFORMER,
|
|
843
|
-
VIDEO_BLOCK_TRANSFORMER,
|
|
844
|
-
CODE_BLOCK_NODE_TRANSFORMER,
|
|
845
|
-
CODE_BLOCK_MULTILINE_TRANSFORMER,
|
|
846
|
-
LINK_CARD_BLOCK_TRANSFORMER,
|
|
847
|
-
MERMAID_BLOCK_TRANSFORMER,
|
|
848
|
-
GRID_CONTAINER_BLOCK_TRANSFORMER,
|
|
849
|
-
HORIZONTAL_RULE_BLOCK_TRANSFORMER,
|
|
850
|
-
TABLE_IMPORT_TRANSFORMER,
|
|
851
|
-
TABLE_BLOCK_TRANSFORMER,
|
|
852
|
-
QUOTE_TRANSFORMER,
|
|
853
|
-
...TRANSFORMERS.filter((t) => t !== QUOTE && t !== CODE)
|
|
854
|
-
];
|
|
855
|
-
function getVSCodePasteData(clipboardData) {
|
|
856
|
-
const raw = clipboardData.getData("vscode-editor-data");
|
|
857
|
-
if (!raw) return null;
|
|
858
|
-
try {
|
|
859
|
-
const data = JSON.parse(raw);
|
|
860
|
-
return { language: data.mode || "text" };
|
|
861
|
-
} catch {
|
|
862
|
-
return null;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
function hasRichHTML(clipboardData) {
|
|
866
|
-
const html = clipboardData.getData("text/html");
|
|
867
|
-
if (!html) return false;
|
|
868
|
-
if (/data-vscode|vscode-/i.test(html)) return false;
|
|
869
|
-
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
870
|
-
const richTags = doc.body.querySelectorAll(
|
|
871
|
-
"strong,em,b,i,h1,h2,h3,h4,h5,h6,ul,ol,table,img,blockquote,pre>code,a[href]"
|
|
872
|
-
);
|
|
873
|
-
return richTags.length > 0;
|
|
874
|
-
}
|
|
875
|
-
function detectMarkdown(text) {
|
|
876
|
-
let score = 0;
|
|
877
|
-
if (/^#{1,6}\s+\S/m.test(text)) score += 5;
|
|
878
|
-
if (/^```[\w-]*$/m.test(text)) score += 5;
|
|
879
|
-
if (/\[[^\]]+\]\([^)]+\)/.test(text)) score += 4;
|
|
880
|
-
if (/!\[[^\]]*\]\([^)]+\)/.test(text)) score += 5;
|
|
881
|
-
if (/^\|.+\|$/m.test(text) && /^\|[\s:|-]+\|$/m.test(text)) score += 5;
|
|
882
|
-
if (/^>\s*\[!(?:note|tip|warning|caution|important)\]/im.test(text)) score += 5;
|
|
883
|
-
if (/^[*-]\s+\[[ x]\]/m.test(text)) score += 4;
|
|
884
|
-
if (/\*\*.+?\*\*/.test(text)) score += 2;
|
|
885
|
-
if (/(?<!\*)\*(?!\*)(?!\s).+?(?<!\s)(?<!\*)\*(?!\*)/.test(text)) score += 1;
|
|
886
|
-
if (/^[*+-]\s+\S/m.test(text)) score += 1;
|
|
887
|
-
if (/^\d+\.\s+\S/m.test(text)) score += 1;
|
|
888
|
-
if (/^>\s+\S/m.test(text)) score += 1;
|
|
889
|
-
if (/`.+?`/.test(text)) score += 1;
|
|
890
|
-
if (/^[*_-]{3,}$/m.test(text)) score += 2;
|
|
891
|
-
const paragraphs = text.split(/\n{2,}/).filter(Boolean);
|
|
892
|
-
if (paragraphs.length >= 2) score += 5;
|
|
893
|
-
if (text.length < 20) score -= 3;
|
|
894
|
-
if (!text.includes("\n")) score -= 2;
|
|
895
|
-
return score >= 5;
|
|
896
|
-
}
|
|
897
|
-
function convertAndInsert(markdown) {
|
|
898
|
-
let conversionError = null;
|
|
899
|
-
const tempEditor = createEditor({
|
|
900
|
-
namespace: "markdown-paste-temp",
|
|
901
|
-
nodes: getResolvedEditNodes(),
|
|
902
|
-
onError: (error) => {
|
|
903
|
-
conversionError = error;
|
|
904
|
-
}
|
|
905
|
-
});
|
|
906
|
-
tempEditor.update(
|
|
907
|
-
() => {
|
|
908
|
-
$convertFromMarkdownString(markdown, ALL_TRANSFORMERS);
|
|
909
|
-
},
|
|
910
|
-
{ discrete: true }
|
|
911
|
-
);
|
|
912
|
-
if (conversionError) {
|
|
913
|
-
console.error("MarkdownPastePlugin: convertAndInsert error", conversionError);
|
|
914
|
-
return false;
|
|
915
|
-
}
|
|
916
|
-
const serializedChildren = tempEditor.getEditorState().toJSON().root.children;
|
|
917
|
-
if (!serializedChildren.length) return false;
|
|
918
|
-
const nodes = serializedChildren.map((s) => $parseSerializedNode(s));
|
|
919
|
-
$insertNodes(nodes);
|
|
920
|
-
return true;
|
|
921
|
-
}
|
|
922
|
-
function MarkdownPastePlugin() {
|
|
923
|
-
const [editor] = useLexicalComposerContext();
|
|
924
|
-
useEffect(() => {
|
|
925
|
-
return editor.registerCommand(
|
|
926
|
-
PASTE_COMMAND,
|
|
927
|
-
(event) => {
|
|
928
|
-
const clipboardData = "clipboardData" in event ? event.clipboardData : null;
|
|
929
|
-
if (!clipboardData) return false;
|
|
930
|
-
if (clipboardData.getData("application/x-lexical-editor")) return false;
|
|
931
|
-
if (Array.from(clipboardData.files).some((f) => f.type.startsWith("image/"))) return false;
|
|
932
|
-
const vscodeData = getVSCodePasteData(clipboardData);
|
|
933
|
-
if (vscodeData) {
|
|
934
|
-
const code = clipboardData.getData("text/plain");
|
|
935
|
-
if (code) {
|
|
936
|
-
const segments = code.split(/\r?\n{3,}/).filter(Boolean);
|
|
937
|
-
const nodes = segments.map(
|
|
938
|
-
(s) => $createCodeBlockEditNode(
|
|
939
|
-
s.replace(/^\s*\n/, "").replace(/\n\s*$/, ""),
|
|
940
|
-
vscodeData.language
|
|
941
|
-
)
|
|
942
|
-
);
|
|
943
|
-
$insertNodes(nodes);
|
|
944
|
-
event.preventDefault();
|
|
945
|
-
return true;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
if (hasRichHTML(clipboardData)) return false;
|
|
949
|
-
const text = clipboardData.getData("text/plain");
|
|
950
|
-
if (!text || !detectMarkdown(text)) return false;
|
|
951
|
-
try {
|
|
952
|
-
if (!convertAndInsert(text)) {
|
|
953
|
-
return false;
|
|
954
|
-
}
|
|
955
|
-
event.preventDefault();
|
|
956
|
-
return true;
|
|
957
|
-
} catch (error) {
|
|
958
|
-
console.error("MarkdownPastePlugin: paste error", error);
|
|
959
|
-
return false;
|
|
960
|
-
}
|
|
961
|
-
},
|
|
962
|
-
COMMAND_PRIORITY_HIGH
|
|
963
|
-
);
|
|
964
|
-
}, [editor]);
|
|
965
|
-
return null;
|
|
966
|
-
}
|
|
967
|
-
function MarkdownShortcutsPlugin() {
|
|
968
|
-
return /* @__PURE__ */ jsx(MarkdownShortcutPlugin, { transformers: ALL_TRANSFORMERS });
|
|
969
|
-
}
|
|
970
|
-
function CorePlugins() {
|
|
971
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
972
|
-
/* @__PURE__ */ jsx(ListPlugin, {}),
|
|
973
|
-
/* @__PURE__ */ jsx(LinkPlugin, {}),
|
|
974
|
-
/* @__PURE__ */ jsx(TabIndentationPlugin, {}),
|
|
975
|
-
/* @__PURE__ */ jsx(TablePlugin, {}),
|
|
976
|
-
/* @__PURE__ */ jsx(CheckListPlugin, {}),
|
|
977
|
-
/* @__PURE__ */ jsx(MarkdownShortcutsPlugin, {}),
|
|
978
|
-
/* @__PURE__ */ jsx(MarkdownPastePlugin, {}),
|
|
979
|
-
/* @__PURE__ */ jsx(BlockExitPlugin, {}),
|
|
980
|
-
/* @__PURE__ */ jsx(HorizontalRulePlugin, {}),
|
|
981
|
-
/* @__PURE__ */ jsx(AutoLinkPlugin, {})
|
|
982
|
-
] });
|
|
983
|
-
}
|
|
984
|
-
const ImageUploadContext = createContext(null);
|
|
985
|
-
function ImageUploadProvider({
|
|
986
|
-
upload,
|
|
987
|
-
children
|
|
988
|
-
}) {
|
|
989
|
-
return /* @__PURE__ */ jsx(ImageUploadContext.Provider, { value: upload, children });
|
|
990
|
-
}
|
|
991
|
-
function useImageUpload() {
|
|
992
|
-
return use(ImageUploadContext);
|
|
993
|
-
}
|
|
994
|
-
const blockIdState = createState("blockId", {
|
|
995
|
-
parse: (v) => typeof v === "string" ? v : ""
|
|
996
|
-
});
|
|
997
|
-
const NORMALIZATION_TAG = "block-id-normalization";
|
|
998
|
-
function buildPreviousIdIndex(editorState) {
|
|
999
|
-
return editorState.read(() => {
|
|
1000
|
-
const map = /* @__PURE__ */ new Map();
|
|
1001
|
-
for (const child of $getRoot().getChildren()) {
|
|
1002
|
-
const id = $getState(child, blockIdState);
|
|
1003
|
-
if (!id) continue;
|
|
1004
|
-
const set = map.get(id) ?? /* @__PURE__ */ new Set();
|
|
1005
|
-
set.add(child.getKey());
|
|
1006
|
-
map.set(id, set);
|
|
1007
|
-
}
|
|
1008
|
-
return map;
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
function collectRootChildren(editorState) {
|
|
1012
|
-
return editorState.read(
|
|
1013
|
-
() => $getRoot().getChildren().map((child) => $getState(child, blockIdState))
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
function hasDuplicateOrMissingId(children) {
|
|
1017
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1018
|
-
for (const id of children) {
|
|
1019
|
-
if (!id || seen.has(id)) {
|
|
1020
|
-
return true;
|
|
1021
|
-
}
|
|
1022
|
-
seen.add(id);
|
|
1023
|
-
}
|
|
1024
|
-
return false;
|
|
1025
|
-
}
|
|
1026
|
-
function generateBlockId(used) {
|
|
1027
|
-
while (true) {
|
|
1028
|
-
const id = nanoid(8);
|
|
1029
|
-
if (!used.has(id)) {
|
|
1030
|
-
return id;
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
function pickKeeperKey(nodes, previousKeys) {
|
|
1035
|
-
if (!nodes.length) return null;
|
|
1036
|
-
if (previousKeys?.size) {
|
|
1037
|
-
for (const node of nodes) {
|
|
1038
|
-
if (previousKeys.has(node.getKey())) {
|
|
1039
|
-
return node.getKey();
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
return nodes[0]?.getKey() ?? null;
|
|
1044
|
-
}
|
|
1045
|
-
function normalizeRootBlockIds(editor, previousIdIndex) {
|
|
1046
|
-
editor.update(
|
|
1047
|
-
() => {
|
|
1048
|
-
$addUpdateTag("history-merge");
|
|
1049
|
-
const children = $getRoot().getChildren();
|
|
1050
|
-
const groupedById = /* @__PURE__ */ new Map();
|
|
1051
|
-
for (const child of children) {
|
|
1052
|
-
const id = $getState(child, blockIdState);
|
|
1053
|
-
if (!id) continue;
|
|
1054
|
-
const bucket = groupedById.get(id) ?? [];
|
|
1055
|
-
bucket.push(child);
|
|
1056
|
-
groupedById.set(id, bucket);
|
|
1057
|
-
}
|
|
1058
|
-
const keeperById = /* @__PURE__ */ new Map();
|
|
1059
|
-
for (const [id, nodes] of groupedById) {
|
|
1060
|
-
if (nodes.length <= 1) continue;
|
|
1061
|
-
const keeperKey = pickKeeperKey(nodes, previousIdIndex.get(id));
|
|
1062
|
-
if (keeperKey) {
|
|
1063
|
-
keeperById.set(id, keeperKey);
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
const used = /* @__PURE__ */ new Set();
|
|
1067
|
-
for (const child of children) {
|
|
1068
|
-
let id = $getState(child, blockIdState);
|
|
1069
|
-
const keeperKey = id ? keeperById.get(id) : null;
|
|
1070
|
-
const shouldRegenerate = !id || used.has(id) || keeperKey !== void 0 && child.getKey() !== keeperKey;
|
|
1071
|
-
if (shouldRegenerate) {
|
|
1072
|
-
id = generateBlockId(used);
|
|
1073
|
-
$setState(child, blockIdState, id);
|
|
1074
|
-
}
|
|
1075
|
-
used.add(id);
|
|
1076
|
-
}
|
|
1077
|
-
},
|
|
1078
|
-
{ tag: NORMALIZATION_TAG }
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
function syncBlockIdAttributes(editor) {
|
|
1082
|
-
editor.getEditorState().read(() => {
|
|
1083
|
-
for (const child of $getRoot().getChildren()) {
|
|
1084
|
-
const id = $getState(child, blockIdState);
|
|
1085
|
-
if (!id) continue;
|
|
1086
|
-
const dom = editor.getElementByKey(child.getKey());
|
|
1087
|
-
if (dom && dom.getAttribute("data-block-id") !== id) {
|
|
1088
|
-
dom.setAttribute("data-block-id", id);
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1093
|
-
function BlockIdPlugin() {
|
|
1094
|
-
const [editor] = useLexicalComposerContext();
|
|
1095
|
-
useEffect(() => {
|
|
1096
|
-
const initialChildren = collectRootChildren(editor.getEditorState());
|
|
1097
|
-
if (hasDuplicateOrMissingId(initialChildren)) {
|
|
1098
|
-
normalizeRootBlockIds(editor, /* @__PURE__ */ new Map());
|
|
1099
|
-
}
|
|
1100
|
-
syncBlockIdAttributes(editor);
|
|
1101
|
-
return editor.registerUpdateListener(({ tags, editorState, prevEditorState }) => {
|
|
1102
|
-
if (tags.has(NORMALIZATION_TAG)) {
|
|
1103
|
-
syncBlockIdAttributes(editor);
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
const children = collectRootChildren(editorState);
|
|
1107
|
-
if (!hasDuplicateOrMissingId(children)) {
|
|
1108
|
-
syncBlockIdAttributes(editor);
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
const previousIdIndex = buildPreviousIdIndex(prevEditorState);
|
|
1112
|
-
normalizeRootBlockIds(editor, previousIdIndex);
|
|
1113
|
-
});
|
|
1114
|
-
}, [editor]);
|
|
1115
|
-
return null;
|
|
1116
|
-
}
|
|
1117
|
-
var draggingWrapperClass = "rich-image-upload-dragging";
|
|
1118
|
-
var toastStack = "_1x58dbf1";
|
|
1119
|
-
var toast = "_1x58dbf2";
|
|
1120
|
-
var toastVariant = { info: "_1x58dbf3", success: "_1x58dbf4", error: "_1x58dbf5" };
|
|
1121
|
-
var spinner = "_1x58dbf7";
|
|
1122
|
-
var dialogPopup = "_1x58dbf8";
|
|
1123
|
-
var dialogHeader = "_1x58dbf9";
|
|
1124
|
-
var dialogTitle = "_1x58dbfa";
|
|
1125
|
-
var dialogBody = "_1x58dbfb";
|
|
1126
|
-
var tabWrap = "_1x58dbfc";
|
|
1127
|
-
var uploadDropzone = "_1x58dbfd";
|
|
1128
|
-
var uploadDropzoneState = { idle: "_1x58dbfe", active: "_1x58dbff", busy: "_1x58dbfg" };
|
|
1129
|
-
var uploadDropIcon = "_1x58dbfh";
|
|
1130
|
-
var uploadDropTitle = "_1x58dbfi";
|
|
1131
|
-
var uploadDropDesc = "_1x58dbfj";
|
|
1132
|
-
var hiddenInput = "_1x58dbfk";
|
|
1133
|
-
var uploadBusyWrap = "_1x58dbfl";
|
|
1134
|
-
var uploadProgress = "_1x58dbfm";
|
|
1135
|
-
var urlInputRow = "_1x58dbfn";
|
|
1136
|
-
var textInput = "_1x58dbfo";
|
|
1137
|
-
var urlPreview = "_1x58dbfp";
|
|
1138
|
-
var urlPreviewImage = "_1x58dbfq";
|
|
1139
|
-
var helperText = "_1x58dbfr";
|
|
1140
|
-
var dialogFooter = "_1x58dbfs";
|
|
1141
|
-
function isImageFile(file) {
|
|
1142
|
-
return file.type.startsWith("image/");
|
|
1143
|
-
}
|
|
1144
|
-
function hasImageData(dataTransfer) {
|
|
1145
|
-
if (!dataTransfer) return false;
|
|
1146
|
-
if ([...dataTransfer.files].some(isImageFile)) return true;
|
|
1147
|
-
return [...dataTransfer.items].some((item) => item.type.startsWith("image/"));
|
|
1148
|
-
}
|
|
1149
|
-
const UNSAFE_URL_RE = /^(?:javascript\s*:|vbscript\s*:|data\s*:(?!image\/))/i;
|
|
1150
|
-
function isSafeImageUrl(url) {
|
|
1151
|
-
return !UNSAFE_URL_RE.test(url);
|
|
1152
|
-
}
|
|
1153
|
-
function loadImageByUrl(src) {
|
|
1154
|
-
return new Promise((resolve, reject) => {
|
|
1155
|
-
const image = new Image();
|
|
1156
|
-
image.onload = () => {
|
|
1157
|
-
resolve({
|
|
1158
|
-
width: image.naturalWidth || image.width,
|
|
1159
|
-
height: image.naturalHeight || image.height
|
|
1160
|
-
});
|
|
1161
|
-
};
|
|
1162
|
-
image.onerror = () => reject(new Error("Failed to load image"));
|
|
1163
|
-
image.src = src;
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
function readAsDataUrl(file) {
|
|
1167
|
-
return new Promise((resolve, reject) => {
|
|
1168
|
-
const reader = new FileReader();
|
|
1169
|
-
reader.onload = () => resolve(String(reader.result));
|
|
1170
|
-
reader.onerror = () => reject(reader.error ?? new Error("File read failed"));
|
|
1171
|
-
reader.readAsDataURL(file);
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
|
-
async function defaultImageUpload(file) {
|
|
1175
|
-
return {
|
|
1176
|
-
src: await readAsDataUrl(file),
|
|
1177
|
-
altText: file.name
|
|
1178
|
-
};
|
|
1179
|
-
}
|
|
1180
|
-
function ImageUploadPlugin({ onUpload }) {
|
|
1181
|
-
const [editor] = useLexicalComposerContext();
|
|
1182
|
-
const uploadRef = useRef(onUpload);
|
|
1183
|
-
uploadRef.current = onUpload;
|
|
1184
|
-
const fileInputRef = useRef(null);
|
|
1185
|
-
const toastTimerRef = useRef(null);
|
|
1186
|
-
const [dialogOpen, setDialogOpen] = useState(false);
|
|
1187
|
-
const [tab, setTab] = useState("upload");
|
|
1188
|
-
const [rootDragActive, setRootDragActive] = useState(false);
|
|
1189
|
-
const [dialogDragActive, setDialogDragActive] = useState(false);
|
|
1190
|
-
const [pendingUploads, setPendingUploads] = useState(0);
|
|
1191
|
-
const [dialogUploading, setDialogUploading] = useState(false);
|
|
1192
|
-
const [toast$1, setToast] = useState(null);
|
|
1193
|
-
const [urlInput, setUrlInput] = useState("");
|
|
1194
|
-
const [urlPreview$1, setUrlPreview] = useState(null);
|
|
1195
|
-
const [urlMeta, setUrlMeta] = useState(null);
|
|
1196
|
-
const [urlLoading, setUrlLoading] = useState(false);
|
|
1197
|
-
const [urlError, setUrlError] = useState(null);
|
|
1198
|
-
const tabItems = useMemo(
|
|
1199
|
-
() => [
|
|
1200
|
-
{ value: "upload", label: "Upload" },
|
|
1201
|
-
{ value: "url", label: "URL" }
|
|
1202
|
-
],
|
|
1203
|
-
[]
|
|
1204
|
-
);
|
|
1205
|
-
const pushToast = useCallback((kind, message) => {
|
|
1206
|
-
setToast({ kind, message });
|
|
1207
|
-
if (toastTimerRef.current) {
|
|
1208
|
-
window.clearTimeout(toastTimerRef.current);
|
|
1209
|
-
}
|
|
1210
|
-
toastTimerRef.current = window.setTimeout(setToast, 2200, null);
|
|
1211
|
-
}, []);
|
|
1212
|
-
const insertByUpload = useCallback(
|
|
1213
|
-
async (file, options) => {
|
|
1214
|
-
if (!isImageFile(file)) return false;
|
|
1215
|
-
const closeDialog = Boolean(options?.closeDialog);
|
|
1216
|
-
setPendingUploads((value) => value + 1);
|
|
1217
|
-
if (closeDialog) setDialogUploading(true);
|
|
1218
|
-
try {
|
|
1219
|
-
const [result, meta] = await Promise.all([uploadRef.current(file), computeImageMeta(file)]);
|
|
1220
|
-
editor.update(() => {
|
|
1221
|
-
const node = $createImageNode({
|
|
1222
|
-
src: result.src,
|
|
1223
|
-
altText: result.altText ?? file.name,
|
|
1224
|
-
width: result.width ?? meta.width,
|
|
1225
|
-
height: result.height ?? meta.height,
|
|
1226
|
-
thumbhash: result.thumbhash ?? meta.thumbhash
|
|
1227
|
-
});
|
|
1228
|
-
$insertNodes([node]);
|
|
1229
|
-
});
|
|
1230
|
-
if (closeDialog) {
|
|
1231
|
-
setDialogOpen(false);
|
|
1232
|
-
setUrlInput("");
|
|
1233
|
-
setUrlPreview(null);
|
|
1234
|
-
setUrlMeta(null);
|
|
1235
|
-
setUrlError(null);
|
|
1236
|
-
}
|
|
1237
|
-
pushToast("success", "Image uploaded");
|
|
1238
|
-
return true;
|
|
1239
|
-
} catch (err) {
|
|
1240
|
-
console.error("[ImageUploadPlugin]", err);
|
|
1241
|
-
pushToast("error", "Image upload failed");
|
|
1242
|
-
return false;
|
|
1243
|
-
} finally {
|
|
1244
|
-
setPendingUploads((value) => Math.max(value - 1, 0));
|
|
1245
|
-
setDialogUploading(false);
|
|
1246
|
-
}
|
|
1247
|
-
},
|
|
1248
|
-
[editor, pushToast]
|
|
1249
|
-
);
|
|
1250
|
-
const handleFiles = useCallback(
|
|
1251
|
-
(files) => {
|
|
1252
|
-
const images = files.filter(isImageFile);
|
|
1253
|
-
if (images.length === 0) return false;
|
|
1254
|
-
for (const file of images) {
|
|
1255
|
-
void insertByUpload(file);
|
|
1256
|
-
}
|
|
1257
|
-
return true;
|
|
1258
|
-
},
|
|
1259
|
-
[insertByUpload]
|
|
1260
|
-
);
|
|
1261
|
-
useEffect(() => {
|
|
1262
|
-
const unregisterDragDrop = editor.registerCommand(
|
|
1263
|
-
DRAG_DROP_PASTE,
|
|
1264
|
-
(files) => handleFiles(files),
|
|
1265
|
-
COMMAND_PRIORITY_HIGH
|
|
1266
|
-
);
|
|
1267
|
-
const unregisterPaste = editor.registerCommand(
|
|
1268
|
-
PASTE_COMMAND,
|
|
1269
|
-
(event) => {
|
|
1270
|
-
const clipboardData = "clipboardData" in event ? event.clipboardData : null;
|
|
1271
|
-
if (!clipboardData) return false;
|
|
1272
|
-
const files = [...clipboardData.files];
|
|
1273
|
-
if (files.some(isImageFile)) {
|
|
1274
|
-
return handleFiles(files);
|
|
1275
|
-
}
|
|
1276
|
-
return false;
|
|
1277
|
-
},
|
|
1278
|
-
COMMAND_PRIORITY_HIGH
|
|
1279
|
-
);
|
|
1280
|
-
const unregisterOpenDialog = editor.registerCommand(
|
|
1281
|
-
OPEN_IMAGE_UPLOAD_DIALOG_COMMAND,
|
|
1282
|
-
() => {
|
|
1283
|
-
setDialogOpen(true);
|
|
1284
|
-
return true;
|
|
1285
|
-
},
|
|
1286
|
-
COMMAND_PRIORITY_EDITOR
|
|
1287
|
-
);
|
|
1288
|
-
const rootElement = editor.getRootElement();
|
|
1289
|
-
const wrapper = rootElement?.parentElement ?? null;
|
|
1290
|
-
if (!wrapper) {
|
|
1291
|
-
return () => {
|
|
1292
|
-
unregisterDragDrop();
|
|
1293
|
-
unregisterPaste();
|
|
1294
|
-
unregisterOpenDialog();
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
let dragCounter = 0;
|
|
1298
|
-
const setWrapperDragging = (next) => {
|
|
1299
|
-
setRootDragActive(next);
|
|
1300
|
-
wrapper.classList.toggle(draggingWrapperClass, next);
|
|
1301
|
-
};
|
|
1302
|
-
const onDragEnter = (event) => {
|
|
1303
|
-
if (!hasImageData(event.dataTransfer)) return;
|
|
1304
|
-
dragCounter += 1;
|
|
1305
|
-
setWrapperDragging(true);
|
|
1306
|
-
};
|
|
1307
|
-
const onDragOver = (event) => {
|
|
1308
|
-
if (!hasImageData(event.dataTransfer)) return;
|
|
1309
|
-
event.preventDefault();
|
|
1310
|
-
};
|
|
1311
|
-
const onDragLeave = () => {
|
|
1312
|
-
dragCounter = Math.max(dragCounter - 1, 0);
|
|
1313
|
-
if (dragCounter === 0) {
|
|
1314
|
-
setWrapperDragging(false);
|
|
1315
|
-
}
|
|
1316
|
-
};
|
|
1317
|
-
const onDrop = () => {
|
|
1318
|
-
dragCounter = 0;
|
|
1319
|
-
setWrapperDragging(false);
|
|
1320
|
-
};
|
|
1321
|
-
rootElement?.addEventListener("dragenter", onDragEnter);
|
|
1322
|
-
rootElement?.addEventListener("dragover", onDragOver);
|
|
1323
|
-
rootElement?.addEventListener("dragleave", onDragLeave);
|
|
1324
|
-
rootElement?.addEventListener("drop", onDrop);
|
|
1325
|
-
return () => {
|
|
1326
|
-
if (toastTimerRef.current) {
|
|
1327
|
-
window.clearTimeout(toastTimerRef.current);
|
|
1328
|
-
}
|
|
1329
|
-
unregisterDragDrop();
|
|
1330
|
-
unregisterPaste();
|
|
1331
|
-
unregisterOpenDialog();
|
|
1332
|
-
setWrapperDragging(false);
|
|
1333
|
-
rootElement?.removeEventListener("dragenter", onDragEnter);
|
|
1334
|
-
rootElement?.removeEventListener("dragover", onDragOver);
|
|
1335
|
-
rootElement?.removeEventListener("dragleave", onDragLeave);
|
|
1336
|
-
rootElement?.removeEventListener("drop", onDrop);
|
|
1337
|
-
};
|
|
1338
|
-
}, [editor, handleFiles]);
|
|
1339
|
-
const resetUrlState = useCallback(() => {
|
|
1340
|
-
setUrlInput("");
|
|
1341
|
-
setUrlPreview(null);
|
|
1342
|
-
setUrlMeta(null);
|
|
1343
|
-
setUrlError(null);
|
|
1344
|
-
setUrlLoading(false);
|
|
1345
|
-
}, []);
|
|
1346
|
-
const handleDialogFile = useCallback(
|
|
1347
|
-
async (file) => {
|
|
1348
|
-
if (!file) return;
|
|
1349
|
-
await insertByUpload(file, { closeDialog: true });
|
|
1350
|
-
},
|
|
1351
|
-
[insertByUpload]
|
|
1352
|
-
);
|
|
1353
|
-
const handleUrlPreview = useCallback(async () => {
|
|
1354
|
-
const nextUrl = urlInput.trim();
|
|
1355
|
-
if (!nextUrl) return;
|
|
1356
|
-
if (!isSafeImageUrl(nextUrl)) {
|
|
1357
|
-
setUrlError("Unsupported URL scheme");
|
|
1358
|
-
return;
|
|
1359
|
-
}
|
|
1360
|
-
setUrlLoading(true);
|
|
1361
|
-
setUrlError(null);
|
|
1362
|
-
try {
|
|
1363
|
-
const meta = await loadImageByUrl(nextUrl);
|
|
1364
|
-
setUrlMeta(meta);
|
|
1365
|
-
setUrlPreview(nextUrl);
|
|
1366
|
-
} catch {
|
|
1367
|
-
setUrlPreview(null);
|
|
1368
|
-
setUrlMeta(null);
|
|
1369
|
-
setUrlError("Could not load this image URL");
|
|
1370
|
-
} finally {
|
|
1371
|
-
setUrlLoading(false);
|
|
1372
|
-
}
|
|
1373
|
-
}, [urlInput]);
|
|
1374
|
-
const handleInsertByUrl = useCallback(() => {
|
|
1375
|
-
if (!urlPreview$1 || !isSafeImageUrl(urlPreview$1)) return;
|
|
1376
|
-
editor.update(() => {
|
|
1377
|
-
const node = $createImageNode({
|
|
1378
|
-
src: urlPreview$1,
|
|
1379
|
-
altText: "",
|
|
1380
|
-
width: urlMeta?.width,
|
|
1381
|
-
height: urlMeta?.height
|
|
1382
|
-
});
|
|
1383
|
-
$insertNodes([node]);
|
|
1384
|
-
});
|
|
1385
|
-
pushToast("success", "Image inserted");
|
|
1386
|
-
setDialogOpen(false);
|
|
1387
|
-
resetUrlState();
|
|
1388
|
-
}, [editor, pushToast, resetUrlState, urlMeta, urlPreview$1]);
|
|
1389
|
-
const helperMessage = pendingUploads > 0 ? `Uploading ${pendingUploads} image${pendingUploads > 1 ? "s" : ""}...` : rootDragActive ? "Drop image files to upload" : null;
|
|
1390
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1391
|
-
(helperMessage || toast$1) && /* @__PURE__ */ jsxs("div", { className: toastStack, children: [
|
|
1392
|
-
helperMessage && /* @__PURE__ */ jsxs("div", { className: `${toast} ${toastVariant.info}`, children: [
|
|
1393
|
-
/* @__PURE__ */ jsx("span", { className: spinner }),
|
|
1394
|
-
helperMessage
|
|
1395
|
-
] }),
|
|
1396
|
-
toast$1 && /* @__PURE__ */ jsxs("div", { className: `${toast} ${toastVariant[toast$1.kind]}`, children: [
|
|
1397
|
-
toast$1.kind === "success" ? /* @__PURE__ */ jsx(Check, { size: 12 }) : /* @__PURE__ */ jsx(Info, { size: 12 }),
|
|
1398
|
-
toast$1.message
|
|
1399
|
-
] })
|
|
1400
|
-
] }),
|
|
1401
|
-
/* @__PURE__ */ jsx(
|
|
1402
|
-
Dialog,
|
|
1403
|
-
{
|
|
1404
|
-
open: dialogOpen,
|
|
1405
|
-
onOpenChange: (nextOpen) => {
|
|
1406
|
-
if (!nextOpen && dialogUploading) return;
|
|
1407
|
-
setDialogOpen(nextOpen);
|
|
1408
|
-
if (!nextOpen) {
|
|
1409
|
-
resetUrlState();
|
|
1410
|
-
setDialogUploading(false);
|
|
1411
|
-
setDialogDragActive(false);
|
|
1412
|
-
}
|
|
1413
|
-
},
|
|
1414
|
-
children: /* @__PURE__ */ jsxs(DialogPopup, { className: dialogPopup, showCloseButton: !dialogUploading, children: [
|
|
1415
|
-
/* @__PURE__ */ jsx("div", { className: dialogHeader, children: /* @__PURE__ */ jsx(DialogTitle, { className: dialogTitle, children: "Insert image" }) }),
|
|
1416
|
-
/* @__PURE__ */ jsxs("div", { className: dialogBody, children: [
|
|
1417
|
-
/* @__PURE__ */ jsx("div", { className: tabWrap, children: /* @__PURE__ */ jsx(SegmentedControl, { fullWidth: true, items: tabItems, value: tab, onChange: setTab }) }),
|
|
1418
|
-
tab === "upload" ? /* @__PURE__ */ jsxs(
|
|
1419
|
-
"div",
|
|
1420
|
-
{
|
|
1421
|
-
className: `${uploadDropzone} ${uploadDropzoneState[dialogUploading ? "busy" : dialogDragActive ? "active" : "idle"]}`,
|
|
1422
|
-
role: "button",
|
|
1423
|
-
tabIndex: 0,
|
|
1424
|
-
onDragLeave: () => setDialogDragActive(false),
|
|
1425
|
-
onClick: () => {
|
|
1426
|
-
if (!dialogUploading) fileInputRef.current?.click();
|
|
1427
|
-
},
|
|
1428
|
-
onDragEnter: (event) => {
|
|
1429
|
-
if (hasImageData(event.dataTransfer)) {
|
|
1430
|
-
event.preventDefault();
|
|
1431
|
-
setDialogDragActive(true);
|
|
1432
|
-
}
|
|
1433
|
-
},
|
|
1434
|
-
onDragOver: (event) => {
|
|
1435
|
-
if (hasImageData(event.dataTransfer)) {
|
|
1436
|
-
event.preventDefault();
|
|
1437
|
-
}
|
|
1438
|
-
},
|
|
1439
|
-
onDrop: (event) => {
|
|
1440
|
-
event.preventDefault();
|
|
1441
|
-
setDialogDragActive(false);
|
|
1442
|
-
const file = [...event.dataTransfer.files].find(isImageFile);
|
|
1443
|
-
void handleDialogFile(file ?? null);
|
|
1444
|
-
},
|
|
1445
|
-
onKeyDown: (event) => {
|
|
1446
|
-
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1447
|
-
event.preventDefault();
|
|
1448
|
-
if (!dialogUploading) fileInputRef.current?.click();
|
|
1449
|
-
},
|
|
1450
|
-
children: [
|
|
1451
|
-
/* @__PURE__ */ jsx(
|
|
1452
|
-
"input",
|
|
1453
|
-
{
|
|
1454
|
-
accept: "image/*",
|
|
1455
|
-
className: hiddenInput,
|
|
1456
|
-
ref: fileInputRef,
|
|
1457
|
-
type: "file",
|
|
1458
|
-
onChange: (event) => {
|
|
1459
|
-
const file = event.currentTarget.files?.[0] ?? null;
|
|
1460
|
-
void handleDialogFile(file);
|
|
1461
|
-
event.currentTarget.value = "";
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
),
|
|
1465
|
-
dialogUploading ? /* @__PURE__ */ jsx("div", { className: uploadBusyWrap, children: /* @__PURE__ */ jsxs("div", { className: uploadProgress, children: [
|
|
1466
|
-
/* @__PURE__ */ jsx("span", { className: spinner }),
|
|
1467
|
-
"Uploading image..."
|
|
1468
|
-
] }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1469
|
-
/* @__PURE__ */ jsx("span", { className: uploadDropIcon, children: /* @__PURE__ */ jsx(Upload, { size: 18 }) }),
|
|
1470
|
-
/* @__PURE__ */ jsx("span", { className: uploadDropTitle, children: "Click to upload or drag and drop" }),
|
|
1471
|
-
/* @__PURE__ */ jsx("span", { className: uploadDropDesc, children: "PNG, JPG, GIF, WebP" })
|
|
1472
|
-
] })
|
|
1473
|
-
]
|
|
1474
|
-
}
|
|
1475
|
-
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1476
|
-
/* @__PURE__ */ jsxs("div", { className: urlInputRow, children: [
|
|
1477
|
-
/* @__PURE__ */ jsx(
|
|
1478
|
-
"input",
|
|
1479
|
-
{
|
|
1480
|
-
className: textInput,
|
|
1481
|
-
placeholder: "https://example.com/image.jpg",
|
|
1482
|
-
type: "url",
|
|
1483
|
-
value: urlInput,
|
|
1484
|
-
onChange: (event) => {
|
|
1485
|
-
setUrlInput(event.target.value);
|
|
1486
|
-
setUrlError(null);
|
|
1487
|
-
setUrlPreview(null);
|
|
1488
|
-
setUrlMeta(null);
|
|
1489
|
-
},
|
|
1490
|
-
onKeyDown: (event) => {
|
|
1491
|
-
if (event.key === "Enter") {
|
|
1492
|
-
event.preventDefault();
|
|
1493
|
-
if (urlPreview$1) {
|
|
1494
|
-
handleInsertByUrl();
|
|
1495
|
-
} else {
|
|
1496
|
-
void handleUrlPreview();
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
),
|
|
1502
|
-
/* @__PURE__ */ jsx(
|
|
1503
|
-
ActionButton,
|
|
1504
|
-
{
|
|
1505
|
-
disabled: urlLoading || !urlInput.trim(),
|
|
1506
|
-
size: "md",
|
|
1507
|
-
variant: "outline",
|
|
1508
|
-
onClick: () => void handleUrlPreview(),
|
|
1509
|
-
children: urlLoading ? "Loading" : "Preview"
|
|
1510
|
-
}
|
|
1511
|
-
),
|
|
1512
|
-
/* @__PURE__ */ jsx(
|
|
1513
|
-
ActionButton,
|
|
1514
|
-
{
|
|
1515
|
-
disabled: !urlPreview$1,
|
|
1516
|
-
size: "md",
|
|
1517
|
-
variant: "accent",
|
|
1518
|
-
onClick: handleInsertByUrl,
|
|
1519
|
-
children: "Insert"
|
|
1520
|
-
}
|
|
1521
|
-
)
|
|
1522
|
-
] }),
|
|
1523
|
-
urlError && /* @__PURE__ */ jsxs("span", { className: `${helperText} ${toastVariant.error}`, children: [
|
|
1524
|
-
/* @__PURE__ */ jsx(Info, { size: 12 }),
|
|
1525
|
-
urlError
|
|
1526
|
-
] }),
|
|
1527
|
-
urlPreview$1 && /* @__PURE__ */ jsx("div", { className: urlPreview, children: /* @__PURE__ */ jsx("img", { alt: "Preview", className: urlPreviewImage, src: urlPreview$1 }) })
|
|
1528
|
-
] })
|
|
1529
|
-
] }),
|
|
1530
|
-
/* @__PURE__ */ jsxs("div", { className: dialogFooter, children: [
|
|
1531
|
-
/* @__PURE__ */ jsxs("span", { className: helperText, children: [
|
|
1532
|
-
/* @__PURE__ */ jsx(Link2, { size: 12 }),
|
|
1533
|
-
"You can also paste images or drag files directly into the editor."
|
|
1534
|
-
] }),
|
|
1535
|
-
/* @__PURE__ */ jsx(ActionBar, { children: /* @__PURE__ */ jsx(
|
|
1536
|
-
ActionButton,
|
|
1537
|
-
{
|
|
1538
|
-
disabled: dialogUploading,
|
|
1539
|
-
size: "md",
|
|
1540
|
-
variant: "outline",
|
|
1541
|
-
onClick: () => setDialogOpen(false),
|
|
1542
|
-
children: "Close"
|
|
1543
|
-
}
|
|
1544
|
-
) })
|
|
1545
|
-
] })
|
|
1546
|
-
] })
|
|
1547
|
-
}
|
|
1548
|
-
)
|
|
1549
|
-
] });
|
|
1550
|
-
}
|
|
1551
|
-
function applyFavicon(dom, href) {
|
|
1552
|
-
if (dom.dataset.faviconHref === href) return;
|
|
1553
|
-
dom.dataset.faviconHref = href;
|
|
1554
|
-
const hostname = getHostname(href);
|
|
1555
|
-
if (!hostname) return;
|
|
1556
|
-
probeFavicon(hostname).then((faviconUrl) => {
|
|
1557
|
-
if (faviconUrl) {
|
|
1558
|
-
dom.style.setProperty("--rc-link-favicon", `url(${faviconUrl})`);
|
|
1559
|
-
dom.dataset.favicon = "loaded";
|
|
1560
|
-
}
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
function LinkFaviconPlugin() {
|
|
1564
|
-
const [editor] = useLexicalComposerContext();
|
|
1565
|
-
useEffect(() => {
|
|
1566
|
-
const handleMutations = (mutations) => {
|
|
1567
|
-
for (const [nodeKey, mutation] of mutations) {
|
|
1568
|
-
if (mutation === "destroyed") continue;
|
|
1569
|
-
const dom = editor.getElementByKey(nodeKey);
|
|
1570
|
-
if (!dom) continue;
|
|
1571
|
-
const href = dom.getAttribute("href");
|
|
1572
|
-
if (href) applyFavicon(dom, href);
|
|
1573
|
-
}
|
|
1574
|
-
};
|
|
1575
|
-
const unregisterLink = editor.registerMutationListener(
|
|
1576
|
-
LinkNode,
|
|
1577
|
-
handleMutations
|
|
1578
|
-
);
|
|
1579
|
-
const unregisterAutoLink = editor.registerMutationListener(
|
|
1580
|
-
AutoLinkNode,
|
|
1581
|
-
handleMutations
|
|
1582
|
-
);
|
|
1583
|
-
return () => {
|
|
1584
|
-
unregisterLink();
|
|
1585
|
-
unregisterAutoLink();
|
|
1586
|
-
};
|
|
1587
|
-
}, [editor]);
|
|
1588
|
-
return null;
|
|
1589
|
-
}
|
|
1590
|
-
function areSnapshotsEqual(a, b) {
|
|
1591
|
-
if (a === b) return true;
|
|
1592
|
-
if (!a || !b) return false;
|
|
1593
|
-
return a.text === b.text && a.anchorBlockId === b.anchorBlockId && a.anchorOffset === b.anchorOffset && a.focusBlockId === b.focusBlockId && a.focusOffset === b.focusOffset;
|
|
1594
|
-
}
|
|
1595
|
-
function createTextSelectionStore(initialState = { snapshot: null }) {
|
|
1596
|
-
let state = initialState;
|
|
1597
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
1598
|
-
const emit = () => {
|
|
1599
|
-
for (const listener of listeners) {
|
|
1600
|
-
listener();
|
|
1601
|
-
}
|
|
1602
|
-
};
|
|
1603
|
-
return {
|
|
1604
|
-
getState: () => state,
|
|
1605
|
-
subscribe: (listener) => {
|
|
1606
|
-
listeners.add(listener);
|
|
1607
|
-
return () => {
|
|
1608
|
-
listeners.delete(listener);
|
|
1609
|
-
};
|
|
1610
|
-
},
|
|
1611
|
-
setSnapshot: (snapshot) => {
|
|
1612
|
-
if (areSnapshotsEqual(state.snapshot, snapshot)) {
|
|
1613
|
-
return;
|
|
1614
|
-
}
|
|
1615
|
-
state = { ...state, snapshot };
|
|
1616
|
-
emit();
|
|
1617
|
-
},
|
|
1618
|
-
clearSnapshot: () => {
|
|
1619
|
-
if (state.snapshot === null) {
|
|
1620
|
-
return;
|
|
1621
|
-
}
|
|
1622
|
-
state = { ...state, snapshot: null };
|
|
1623
|
-
emit();
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
1627
|
-
const TextSelectionStoreContext = createContext(null);
|
|
1628
|
-
function TextSelectionStoreProvider({ children }) {
|
|
1629
|
-
const storeRef = useRef(null);
|
|
1630
|
-
if (!storeRef.current) {
|
|
1631
|
-
storeRef.current = createTextSelectionStore();
|
|
1632
|
-
}
|
|
1633
|
-
return /* @__PURE__ */ jsx(TextSelectionStoreContext.Provider, { value: storeRef.current, children });
|
|
1634
|
-
}
|
|
1635
|
-
function useTextSelectionStore() {
|
|
1636
|
-
const store = use(TextSelectionStoreContext);
|
|
1637
|
-
if (!store) {
|
|
1638
|
-
throw new Error("useTextSelectionStore must be used within TextSelectionStoreProvider");
|
|
1639
|
-
}
|
|
1640
|
-
return store;
|
|
1641
|
-
}
|
|
1642
|
-
function useTextSelectionSnapshot() {
|
|
1643
|
-
const store = useTextSelectionStore();
|
|
1644
|
-
return useSyncExternalStore(
|
|
1645
|
-
store.subscribe,
|
|
1646
|
-
() => store.getState().snapshot,
|
|
1647
|
-
() => store.getState().snapshot
|
|
1648
|
-
);
|
|
1649
|
-
}
|
|
1650
|
-
function computeBlockFingerprint(block) {
|
|
1651
|
-
const text = block.getTextContent();
|
|
1652
|
-
const input = text.slice(0, 200) + String(text.length);
|
|
1653
|
-
let hash = 5381;
|
|
1654
|
-
for (let i = 0; i < input.length; i++) {
|
|
1655
|
-
hash = (hash << 5) + hash + (input.codePointAt(i) ?? 0) | 0;
|
|
1656
|
-
}
|
|
1657
|
-
return (hash >>> 0).toString(16);
|
|
1658
|
-
}
|
|
1659
|
-
function $getRootBlock(node) {
|
|
1660
|
-
const root = $getRoot();
|
|
1661
|
-
let current = node;
|
|
1662
|
-
while (current) {
|
|
1663
|
-
const parent = current.getParent();
|
|
1664
|
-
if (parent === root && "getChildren" in current) {
|
|
1665
|
-
return current;
|
|
1666
|
-
}
|
|
1667
|
-
current = parent;
|
|
1668
|
-
}
|
|
1669
|
-
return null;
|
|
1670
|
-
}
|
|
1671
|
-
function $resolveSelectionPoint(selection, which) {
|
|
1672
|
-
const point = selection[which];
|
|
1673
|
-
const node = point.getNode();
|
|
1674
|
-
if ($isElementNode(node)) {
|
|
1675
|
-
const children = node.getChildren();
|
|
1676
|
-
if (point.offset < children.length) {
|
|
1677
|
-
return { node: children[point.offset], offset: 0 };
|
|
1678
|
-
}
|
|
1679
|
-
const last = children.at(-1);
|
|
1680
|
-
if (last && $isTextNode(last)) {
|
|
1681
|
-
return { node: last, offset: last.getTextContentSize() };
|
|
1682
|
-
}
|
|
1683
|
-
return { node, offset: 0 };
|
|
1684
|
-
}
|
|
1685
|
-
return { node, offset: point.offset };
|
|
1686
|
-
}
|
|
1687
|
-
function $getTextOffsetInBlock(block, targetNode, targetOffset) {
|
|
1688
|
-
let offset = 0;
|
|
1689
|
-
function walk(node) {
|
|
1690
|
-
if (node.is(targetNode)) {
|
|
1691
|
-
offset += targetOffset;
|
|
1692
|
-
return true;
|
|
1693
|
-
}
|
|
1694
|
-
if ($isTextNode(node)) {
|
|
1695
|
-
offset += node.getTextContentSize();
|
|
1696
|
-
} else if ($isLineBreakNode(node)) {
|
|
1697
|
-
offset += 1;
|
|
1698
|
-
} else if ($isElementNode(node)) {
|
|
1699
|
-
for (const child of node.getChildren()) {
|
|
1700
|
-
if (walk(child)) return true;
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
return false;
|
|
1704
|
-
}
|
|
1705
|
-
for (const child of block.getChildren()) {
|
|
1706
|
-
if (walk(child)) break;
|
|
1707
|
-
}
|
|
1708
|
-
return offset;
|
|
1709
|
-
}
|
|
1710
|
-
function $buildBlockAnchorData(block) {
|
|
1711
|
-
const blockId = $getState(block, blockIdState);
|
|
1712
|
-
if (!blockId) {
|
|
1713
|
-
return { ok: false, error: "no-block-id" };
|
|
1714
|
-
}
|
|
1715
|
-
return {
|
|
1716
|
-
ok: true,
|
|
1717
|
-
anchor: {
|
|
1718
|
-
mode: "block",
|
|
1719
|
-
blockId,
|
|
1720
|
-
blockType: block.getType(),
|
|
1721
|
-
blockFingerprint: computeBlockFingerprint(block),
|
|
1722
|
-
snapshotText: block.getTextContent().slice(0, 300)
|
|
1723
|
-
}
|
|
1724
|
-
};
|
|
1725
|
-
}
|
|
1726
|
-
function buildBlockAnchor(editor, blockKey) {
|
|
1727
|
-
return editor.read(() => {
|
|
1728
|
-
if (blockKey) {
|
|
1729
|
-
const node = $getRoot().getChildren().find((c) => c.getKey() === blockKey);
|
|
1730
|
-
if (!node || !("getChildren" in node)) {
|
|
1731
|
-
return { ok: false, error: "not-root-block" };
|
|
1732
|
-
}
|
|
1733
|
-
return $buildBlockAnchorData(node);
|
|
1734
|
-
}
|
|
1735
|
-
const selection = $getSelection();
|
|
1736
|
-
if (!$isRangeSelection(selection)) {
|
|
1737
|
-
return { ok: false, error: "no-selection" };
|
|
1738
|
-
}
|
|
1739
|
-
const anchorNode = selection.anchor.getNode();
|
|
1740
|
-
const block = $getRootBlock(anchorNode);
|
|
1741
|
-
if (!block) {
|
|
1742
|
-
return { ok: false, error: "not-root-block" };
|
|
1743
|
-
}
|
|
1744
|
-
return $buildBlockAnchorData(block);
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
function buildRangeAnchor(editor) {
|
|
1748
|
-
return editor.read(() => {
|
|
1749
|
-
const selection = $getSelection();
|
|
1750
|
-
if (!$isRangeSelection(selection)) {
|
|
1751
|
-
return { ok: false, error: "no-selection" };
|
|
1752
|
-
}
|
|
1753
|
-
if (selection.isCollapsed()) {
|
|
1754
|
-
return { ok: false, error: "collapsed" };
|
|
1755
|
-
}
|
|
1756
|
-
const anchorBlock = $getRootBlock(selection.anchor.getNode());
|
|
1757
|
-
const focusBlock = $getRootBlock(selection.focus.getNode());
|
|
1758
|
-
if (!anchorBlock || !focusBlock) {
|
|
1759
|
-
return { ok: false, error: "not-root-block" };
|
|
1760
|
-
}
|
|
1761
|
-
if (anchorBlock !== focusBlock) {
|
|
1762
|
-
return { ok: false, error: "cross-block" };
|
|
1763
|
-
}
|
|
1764
|
-
const block = anchorBlock;
|
|
1765
|
-
const blockId = $getState(block, blockIdState);
|
|
1766
|
-
if (!blockId) {
|
|
1767
|
-
return { ok: false, error: "no-block-id" };
|
|
1768
|
-
}
|
|
1769
|
-
const anchorPoint = $resolveSelectionPoint(selection, "anchor");
|
|
1770
|
-
const focusPoint = $resolveSelectionPoint(selection, "focus");
|
|
1771
|
-
let startOffset = $getTextOffsetInBlock(block, anchorPoint.node, anchorPoint.offset);
|
|
1772
|
-
let endOffset = $getTextOffsetInBlock(block, focusPoint.node, focusPoint.offset);
|
|
1773
|
-
if (startOffset > endOffset) {
|
|
1774
|
-
[startOffset, endOffset] = [endOffset, startOffset];
|
|
1775
|
-
}
|
|
1776
|
-
const text = block.getTextContent();
|
|
1777
|
-
const quote = text.slice(startOffset, endOffset);
|
|
1778
|
-
const prefix = text.slice(Math.max(0, startOffset - 50), startOffset);
|
|
1779
|
-
const suffix = text.slice(endOffset, endOffset + 50);
|
|
1780
|
-
return {
|
|
1781
|
-
ok: true,
|
|
1782
|
-
anchor: {
|
|
1783
|
-
mode: "range",
|
|
1784
|
-
blockId,
|
|
1785
|
-
blockType: block.getType(),
|
|
1786
|
-
blockFingerprint: computeBlockFingerprint(block),
|
|
1787
|
-
snapshotText: text.slice(0, 300),
|
|
1788
|
-
quote,
|
|
1789
|
-
prefix,
|
|
1790
|
-
suffix,
|
|
1791
|
-
startOffset,
|
|
1792
|
-
endOffset
|
|
1793
|
-
}
|
|
1794
|
-
};
|
|
1795
|
-
});
|
|
1796
|
-
}
|
|
1797
|
-
const TEXT_SELECTION_HIGHLIGHT_NAME = "rich-editor-text-selection";
|
|
1798
|
-
const TEXT_SELECTION_INACTIVE_HIGHLIGHT_NAME = "rich-editor-text-selection-inactive";
|
|
1799
|
-
function clampOffset(offset, max) {
|
|
1800
|
-
return Math.max(0, Math.min(offset, max));
|
|
1801
|
-
}
|
|
1802
|
-
function getTopLevelBlockById(blockId) {
|
|
1803
|
-
for (const child of $getRoot().getChildren()) {
|
|
1804
|
-
if ($getState(child, blockIdState) === blockId && $isElementNode(child)) {
|
|
1805
|
-
return child;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
return null;
|
|
1809
|
-
}
|
|
1810
|
-
function getTextLengthOfDomNode(node) {
|
|
1811
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
1812
|
-
return node.textContent?.length ?? 0;
|
|
1813
|
-
}
|
|
1814
|
-
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
1815
|
-
return 0;
|
|
1816
|
-
}
|
|
1817
|
-
const element = node;
|
|
1818
|
-
if (element.tagName === "BR") {
|
|
1819
|
-
return 1;
|
|
1820
|
-
}
|
|
1821
|
-
let length = 0;
|
|
1822
|
-
for (const child of node.childNodes) {
|
|
1823
|
-
length += getTextLengthOfDomNode(child);
|
|
1824
|
-
}
|
|
1825
|
-
return length;
|
|
1826
|
-
}
|
|
1827
|
-
function compareBlockElements(a, b) {
|
|
1828
|
-
if (a === b) return 0;
|
|
1829
|
-
const position = a.compareDocumentPosition(b);
|
|
1830
|
-
if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
1831
|
-
return -1;
|
|
1832
|
-
}
|
|
1833
|
-
if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
1834
|
-
return 1;
|
|
1835
|
-
}
|
|
1836
|
-
return 0;
|
|
1837
|
-
}
|
|
1838
|
-
function buildDomRectFromClientRects(rects) {
|
|
1839
|
-
if (!rects.length) return null;
|
|
1840
|
-
let left = rects[0].left;
|
|
1841
|
-
let top = rects[0].top;
|
|
1842
|
-
let right = rects[0].right;
|
|
1843
|
-
let bottom = rects[0].bottom;
|
|
1844
|
-
for (const rect of rects.slice(1)) {
|
|
1845
|
-
left = Math.min(left, rect.left);
|
|
1846
|
-
top = Math.min(top, rect.top);
|
|
1847
|
-
right = Math.max(right, rect.right);
|
|
1848
|
-
bottom = Math.max(bottom, rect.bottom);
|
|
1849
|
-
}
|
|
1850
|
-
return new DOMRect(left, top, right - left, bottom - top);
|
|
1851
|
-
}
|
|
1852
|
-
function resolveLexicalSelectionTarget(block, requestedOffset) {
|
|
1853
|
-
const offset = clampOffset(requestedOffset, block.getTextContent().length);
|
|
1854
|
-
let remaining = offset;
|
|
1855
|
-
let lastTarget = {
|
|
1856
|
-
key: block.getKey(),
|
|
1857
|
-
offset: block.getChildrenSize(),
|
|
1858
|
-
type: "element"
|
|
1859
|
-
};
|
|
1860
|
-
function walk(node) {
|
|
1861
|
-
if ($isTextNode(node)) {
|
|
1862
|
-
const length = node.getTextContentSize();
|
|
1863
|
-
lastTarget = { key: node.getKey(), offset: length, type: "text" };
|
|
1864
|
-
if (remaining <= length) {
|
|
1865
|
-
return { key: node.getKey(), offset: remaining, type: "text" };
|
|
1866
|
-
}
|
|
1867
|
-
remaining -= length;
|
|
1868
|
-
return null;
|
|
1869
|
-
}
|
|
1870
|
-
if ($isLineBreakNode(node)) {
|
|
1871
|
-
const parent = node.getParent();
|
|
1872
|
-
if (!parent) {
|
|
1873
|
-
return null;
|
|
1874
|
-
}
|
|
1875
|
-
const index = node.getIndexWithinParent();
|
|
1876
|
-
if (remaining === 0) {
|
|
1877
|
-
return { key: parent.getKey(), offset: index, type: "element" };
|
|
1878
|
-
}
|
|
1879
|
-
if (remaining === 1) {
|
|
1880
|
-
return { key: parent.getKey(), offset: index + 1, type: "element" };
|
|
1881
|
-
}
|
|
1882
|
-
remaining -= 1;
|
|
1883
|
-
lastTarget = { key: parent.getKey(), offset: index + 1, type: "element" };
|
|
1884
|
-
return null;
|
|
1885
|
-
}
|
|
1886
|
-
if (!$isElementNode(node)) {
|
|
1887
|
-
return null;
|
|
1888
|
-
}
|
|
1889
|
-
if (node.getChildrenSize() === 0) {
|
|
1890
|
-
lastTarget = { key: node.getKey(), offset: 0, type: "element" };
|
|
1891
|
-
return null;
|
|
1892
|
-
}
|
|
1893
|
-
for (const child of node.getChildren()) {
|
|
1894
|
-
const resolved = walk(child);
|
|
1895
|
-
if (resolved) {
|
|
1896
|
-
return resolved;
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
lastTarget = { key: node.getKey(), offset: node.getChildrenSize(), type: "element" };
|
|
1900
|
-
return null;
|
|
1901
|
-
}
|
|
1902
|
-
return walk(block) ?? lastTarget;
|
|
1903
|
-
}
|
|
1904
|
-
function $captureTextSelectionFromRangeSelection(selection) {
|
|
1905
|
-
if (selection.isCollapsed()) {
|
|
1906
|
-
return null;
|
|
1907
|
-
}
|
|
1908
|
-
const anchorBlock = $getRootBlock(selection.anchor.getNode());
|
|
1909
|
-
const focusBlock = $getRootBlock(selection.focus.getNode());
|
|
1910
|
-
if (!anchorBlock || !focusBlock) {
|
|
1911
|
-
return null;
|
|
1912
|
-
}
|
|
1913
|
-
const anchorBlockId = $getState(anchorBlock, blockIdState);
|
|
1914
|
-
const focusBlockId = $getState(focusBlock, blockIdState);
|
|
1915
|
-
if (!anchorBlockId || !focusBlockId) {
|
|
1916
|
-
return null;
|
|
1917
|
-
}
|
|
1918
|
-
const anchorPoint = $resolveSelectionPoint(selection, "anchor");
|
|
1919
|
-
const focusPoint = $resolveSelectionPoint(selection, "focus");
|
|
1920
|
-
return {
|
|
1921
|
-
text: selection.getTextContent(),
|
|
1922
|
-
anchorBlockId,
|
|
1923
|
-
anchorOffset: $getTextOffsetInBlock(anchorBlock, anchorPoint.node, anchorPoint.offset),
|
|
1924
|
-
focusBlockId,
|
|
1925
|
-
focusOffset: $getTextOffsetInBlock(focusBlock, focusPoint.node, focusPoint.offset)
|
|
1926
|
-
};
|
|
1927
|
-
}
|
|
1928
|
-
function $captureTextSelection() {
|
|
1929
|
-
const selection = $getSelection();
|
|
1930
|
-
if (!$isRangeSelection(selection)) {
|
|
1931
|
-
return null;
|
|
1932
|
-
}
|
|
1933
|
-
return $captureTextSelectionFromRangeSelection(selection);
|
|
1934
|
-
}
|
|
1935
|
-
function $restoreTextSelection(snapshot) {
|
|
1936
|
-
const anchorBlock = getTopLevelBlockById(snapshot.anchorBlockId);
|
|
1937
|
-
const focusBlock = getTopLevelBlockById(snapshot.focusBlockId);
|
|
1938
|
-
if (!anchorBlock || !focusBlock) {
|
|
1939
|
-
return false;
|
|
1940
|
-
}
|
|
1941
|
-
const anchor = resolveLexicalSelectionTarget(anchorBlock, snapshot.anchorOffset);
|
|
1942
|
-
const focus = resolveLexicalSelectionTarget(focusBlock, snapshot.focusOffset);
|
|
1943
|
-
const selection = $createRangeSelection();
|
|
1944
|
-
selection.anchor.set(anchor.key, anchor.offset, anchor.type);
|
|
1945
|
-
selection.focus.set(focus.key, focus.offset, focus.type);
|
|
1946
|
-
$setSelection(selection);
|
|
1947
|
-
return true;
|
|
1948
|
-
}
|
|
1949
|
-
function getTextOffsetFromDOMPoint(container, targetNode, targetOffset) {
|
|
1950
|
-
let offset = 0;
|
|
1951
|
-
function walk(node) {
|
|
1952
|
-
if (node === targetNode) {
|
|
1953
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
1954
|
-
offset += Math.min(targetOffset, node.textContent?.length ?? 0);
|
|
1955
|
-
return true;
|
|
1956
|
-
}
|
|
1957
|
-
const childNodes = Array.from(node.childNodes);
|
|
1958
|
-
const boundary = Math.min(targetOffset, childNodes.length);
|
|
1959
|
-
for (let i = 0; i < boundary; i++) {
|
|
1960
|
-
offset += getTextLengthOfDomNode(childNodes[i]);
|
|
1961
|
-
}
|
|
1962
|
-
return true;
|
|
1963
|
-
}
|
|
1964
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
1965
|
-
offset += node.textContent?.length ?? 0;
|
|
1966
|
-
return false;
|
|
1967
|
-
}
|
|
1968
|
-
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
1969
|
-
return false;
|
|
1970
|
-
}
|
|
1971
|
-
const element = node;
|
|
1972
|
-
if (element.tagName === "BR") {
|
|
1973
|
-
offset += 1;
|
|
1974
|
-
return false;
|
|
1975
|
-
}
|
|
1976
|
-
for (const child of node.childNodes) {
|
|
1977
|
-
if (walk(child)) {
|
|
1978
|
-
return true;
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
return false;
|
|
1982
|
-
}
|
|
1983
|
-
walk(container);
|
|
1984
|
-
return offset;
|
|
1985
|
-
}
|
|
1986
|
-
function findDOMPointByTextOffset(container, requestedOffset) {
|
|
1987
|
-
const targetOffset = clampOffset(requestedOffset, getTextLengthOfDomNode(container));
|
|
1988
|
-
let consumed = 0;
|
|
1989
|
-
function walk(node) {
|
|
1990
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
1991
|
-
const length = node.textContent?.length ?? 0;
|
|
1992
|
-
if (targetOffset <= consumed + length) {
|
|
1993
|
-
return { node, offset: targetOffset - consumed };
|
|
1994
|
-
}
|
|
1995
|
-
consumed += length;
|
|
1996
|
-
return null;
|
|
1997
|
-
}
|
|
1998
|
-
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
1999
|
-
return null;
|
|
2000
|
-
}
|
|
2001
|
-
const element = node;
|
|
2002
|
-
if (element.tagName === "BR") {
|
|
2003
|
-
const parent = element.parentNode;
|
|
2004
|
-
if (!parent) {
|
|
2005
|
-
return null;
|
|
2006
|
-
}
|
|
2007
|
-
const index = Array.from(parent.childNodes).indexOf(element);
|
|
2008
|
-
if (targetOffset === consumed) {
|
|
2009
|
-
return { node: parent, offset: index };
|
|
2010
|
-
}
|
|
2011
|
-
if (targetOffset === consumed + 1) {
|
|
2012
|
-
return { node: parent, offset: index + 1 };
|
|
2013
|
-
}
|
|
2014
|
-
consumed += 1;
|
|
2015
|
-
return null;
|
|
2016
|
-
}
|
|
2017
|
-
for (const child of node.childNodes) {
|
|
2018
|
-
const resolved = walk(child);
|
|
2019
|
-
if (resolved) {
|
|
2020
|
-
return resolved;
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
return null;
|
|
2024
|
-
}
|
|
2025
|
-
return walk(container) ?? { node: container, offset: container.childNodes.length };
|
|
2026
|
-
}
|
|
2027
|
-
function getBlockElementById(rootElement, blockId) {
|
|
2028
|
-
return rootElement.querySelector(`[data-block-id="${blockId}"]`);
|
|
2029
|
-
}
|
|
2030
|
-
function createDOMRangeFromTextSelection(rootElement, snapshot) {
|
|
2031
|
-
const anchorBlock = getBlockElementById(rootElement, snapshot.anchorBlockId);
|
|
2032
|
-
const focusBlock = getBlockElementById(rootElement, snapshot.focusBlockId);
|
|
2033
|
-
if (!anchorBlock || !focusBlock) {
|
|
2034
|
-
return null;
|
|
2035
|
-
}
|
|
2036
|
-
const anchor = findDOMPointByTextOffset(anchorBlock, snapshot.anchorOffset);
|
|
2037
|
-
const focus = findDOMPointByTextOffset(focusBlock, snapshot.focusOffset);
|
|
2038
|
-
if (!anchor || !focus) {
|
|
2039
|
-
return null;
|
|
2040
|
-
}
|
|
2041
|
-
const anchorComesFirst = anchorBlock === focusBlock ? snapshot.anchorOffset <= snapshot.focusOffset : compareBlockElements(anchorBlock, focusBlock) <= 0;
|
|
2042
|
-
const start = anchorComesFirst ? anchor : focus;
|
|
2043
|
-
const end = anchorComesFirst ? focus : anchor;
|
|
2044
|
-
try {
|
|
2045
|
-
const range = document.createRange();
|
|
2046
|
-
range.setStart(start.node, start.offset);
|
|
2047
|
-
range.setEnd(end.node, end.offset);
|
|
2048
|
-
return range;
|
|
2049
|
-
} catch {
|
|
2050
|
-
return null;
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
function getDOMRectFromTextSelection(rootElement, snapshot) {
|
|
2054
|
-
const range = createDOMRangeFromTextSelection(rootElement, snapshot);
|
|
2055
|
-
if (!range) {
|
|
2056
|
-
return null;
|
|
2057
|
-
}
|
|
2058
|
-
const rect = range.getBoundingClientRect();
|
|
2059
|
-
if (rect.width > 0 || rect.height > 0) {
|
|
2060
|
-
return rect;
|
|
2061
|
-
}
|
|
2062
|
-
return buildDomRectFromClientRects(Array.from(range.getClientRects()));
|
|
2063
|
-
}
|
|
2064
|
-
var nativeSelectionActive = "gr1ebt0";
|
|
2065
|
-
var nativeSelectionInactive = "gr1ebt1";
|
|
2066
|
-
let activeHighlightOwner = null;
|
|
2067
|
-
function getHighlightRegistry() {
|
|
2068
|
-
if (typeof CSS === "undefined" || !("highlights" in CSS) || typeof Highlight === "undefined") {
|
|
2069
|
-
return null;
|
|
2070
|
-
}
|
|
2071
|
-
return CSS.highlights;
|
|
2072
|
-
}
|
|
2073
|
-
function clearManagedHighlight(rootElement) {
|
|
2074
|
-
if (rootElement && rootElement !== activeHighlightOwner) {
|
|
2075
|
-
rootElement.classList.remove(nativeSelectionActive, nativeSelectionInactive);
|
|
2076
|
-
return;
|
|
2077
|
-
}
|
|
2078
|
-
const registry = getHighlightRegistry();
|
|
2079
|
-
registry?.delete(TEXT_SELECTION_HIGHLIGHT_NAME);
|
|
2080
|
-
registry?.delete(TEXT_SELECTION_INACTIVE_HIGHLIGHT_NAME);
|
|
2081
|
-
activeHighlightOwner?.classList.remove(nativeSelectionActive, nativeSelectionInactive);
|
|
2082
|
-
activeHighlightOwner = null;
|
|
2083
|
-
}
|
|
2084
|
-
function TextSelectionPlugin() {
|
|
2085
|
-
const [editor] = useLexicalComposerContext();
|
|
2086
|
-
const store = useTextSelectionStore();
|
|
2087
|
-
const snapshot = useTextSelectionSnapshot();
|
|
2088
|
-
const [isEditorFocused, setIsEditorFocused] = useState(false);
|
|
2089
|
-
const frameRef = useRef(null);
|
|
2090
|
-
const focusFrameRef = useRef(null);
|
|
2091
|
-
useEffect(() => {
|
|
2092
|
-
const syncSnapshot = () => {
|
|
2093
|
-
const rootElement2 = editor.getRootElement();
|
|
2094
|
-
if (!rootElement2) {
|
|
2095
|
-
store.clearSnapshot();
|
|
2096
|
-
return;
|
|
2097
|
-
}
|
|
2098
|
-
const nextSnapshot = editor.getEditorState().read(() => $captureTextSelection());
|
|
2099
|
-
store.setSnapshot(nextSnapshot);
|
|
2100
|
-
};
|
|
2101
|
-
const syncFocusState = () => {
|
|
2102
|
-
const rootElement2 = editor.getRootElement();
|
|
2103
|
-
const activeElement = rootElement2?.ownerDocument.activeElement;
|
|
2104
|
-
setIsEditorFocused(
|
|
2105
|
-
Boolean(rootElement2 && activeElement && rootElement2.contains(activeElement))
|
|
2106
|
-
);
|
|
2107
|
-
};
|
|
2108
|
-
const scheduleFocusStateSync = () => {
|
|
2109
|
-
if (focusFrameRef.current !== null) {
|
|
2110
|
-
cancelAnimationFrame(focusFrameRef.current);
|
|
2111
|
-
}
|
|
2112
|
-
focusFrameRef.current = requestAnimationFrame(() => {
|
|
2113
|
-
focusFrameRef.current = null;
|
|
2114
|
-
syncFocusState();
|
|
2115
|
-
});
|
|
2116
|
-
};
|
|
2117
|
-
const unregisterSelectionChange = editor.registerCommand(
|
|
2118
|
-
SELECTION_CHANGE_COMMAND,
|
|
2119
|
-
() => {
|
|
2120
|
-
syncSnapshot();
|
|
2121
|
-
return false;
|
|
2122
|
-
},
|
|
2123
|
-
COMMAND_PRIORITY_LOW
|
|
2124
|
-
);
|
|
2125
|
-
const unregisterUpdate = editor.registerUpdateListener(() => {
|
|
2126
|
-
syncSnapshot();
|
|
2127
|
-
});
|
|
2128
|
-
const rootElement = editor.getRootElement();
|
|
2129
|
-
if (rootElement) {
|
|
2130
|
-
const onFocusIn = (event) => {
|
|
2131
|
-
const target = event.target;
|
|
2132
|
-
if (!target) return;
|
|
2133
|
-
const nestedEditable = target.closest('[contenteditable="true"]');
|
|
2134
|
-
if (nestedEditable && nestedEditable !== rootElement) {
|
|
2135
|
-
store.clearSnapshot();
|
|
2136
|
-
scheduleFocusStateSync();
|
|
2137
|
-
return;
|
|
2138
|
-
}
|
|
2139
|
-
scheduleFocusStateSync();
|
|
2140
|
-
syncSnapshot();
|
|
2141
|
-
};
|
|
2142
|
-
const onFocusOut = () => {
|
|
2143
|
-
scheduleFocusStateSync();
|
|
2144
|
-
syncSnapshot();
|
|
2145
|
-
};
|
|
2146
|
-
rootElement.addEventListener("focusin", onFocusIn);
|
|
2147
|
-
rootElement.addEventListener("focusout", onFocusOut);
|
|
2148
|
-
syncFocusState();
|
|
2149
|
-
syncSnapshot();
|
|
2150
|
-
return () => {
|
|
2151
|
-
unregisterSelectionChange();
|
|
2152
|
-
unregisterUpdate();
|
|
2153
|
-
if (focusFrameRef.current !== null) {
|
|
2154
|
-
cancelAnimationFrame(focusFrameRef.current);
|
|
2155
|
-
focusFrameRef.current = null;
|
|
2156
|
-
}
|
|
2157
|
-
rootElement.removeEventListener("focusin", onFocusIn);
|
|
2158
|
-
rootElement.removeEventListener("focusout", onFocusOut);
|
|
2159
|
-
store.clearSnapshot();
|
|
2160
|
-
};
|
|
2161
|
-
}
|
|
2162
|
-
syncFocusState();
|
|
2163
|
-
syncSnapshot();
|
|
2164
|
-
return () => {
|
|
2165
|
-
unregisterSelectionChange();
|
|
2166
|
-
unregisterUpdate();
|
|
2167
|
-
if (focusFrameRef.current !== null) {
|
|
2168
|
-
cancelAnimationFrame(focusFrameRef.current);
|
|
2169
|
-
focusFrameRef.current = null;
|
|
2170
|
-
}
|
|
2171
|
-
store.clearSnapshot();
|
|
2172
|
-
};
|
|
2173
|
-
}, [editor, store]);
|
|
2174
|
-
useEffect(() => {
|
|
2175
|
-
const registry = getHighlightRegistry();
|
|
2176
|
-
const cancelScheduledSync = () => {
|
|
2177
|
-
if (frameRef.current !== null) {
|
|
2178
|
-
cancelAnimationFrame(frameRef.current);
|
|
2179
|
-
frameRef.current = null;
|
|
2180
|
-
}
|
|
2181
|
-
};
|
|
2182
|
-
const syncManagedHighlight = () => {
|
|
2183
|
-
cancelScheduledSync();
|
|
2184
|
-
frameRef.current = requestAnimationFrame(() => {
|
|
2185
|
-
frameRef.current = null;
|
|
2186
|
-
const rootElement = editor.getRootElement();
|
|
2187
|
-
if (!rootElement) {
|
|
2188
|
-
clearManagedHighlight();
|
|
2189
|
-
return;
|
|
2190
|
-
}
|
|
2191
|
-
if (!snapshot) {
|
|
2192
|
-
clearManagedHighlight(rootElement);
|
|
2193
|
-
return;
|
|
2194
|
-
}
|
|
2195
|
-
if (activeHighlightOwner && activeHighlightOwner !== rootElement) {
|
|
2196
|
-
activeHighlightOwner.classList.remove(
|
|
2197
|
-
nativeSelectionActive,
|
|
2198
|
-
nativeSelectionInactive
|
|
2199
|
-
);
|
|
2200
|
-
}
|
|
2201
|
-
const activeSelectionClass = isEditorFocused ? nativeSelectionActive : nativeSelectionInactive;
|
|
2202
|
-
const inactiveSelectionClass = isEditorFocused ? nativeSelectionInactive : nativeSelectionActive;
|
|
2203
|
-
const highlightName = isEditorFocused ? TEXT_SELECTION_HIGHLIGHT_NAME : TEXT_SELECTION_INACTIVE_HIGHLIGHT_NAME;
|
|
2204
|
-
const staleHighlightName = isEditorFocused ? TEXT_SELECTION_INACTIVE_HIGHLIGHT_NAME : TEXT_SELECTION_HIGHLIGHT_NAME;
|
|
2205
|
-
rootElement.classList.remove(inactiveSelectionClass);
|
|
2206
|
-
rootElement.classList.add(activeSelectionClass);
|
|
2207
|
-
activeHighlightOwner = rootElement;
|
|
2208
|
-
if (!registry) {
|
|
2209
|
-
return;
|
|
2210
|
-
}
|
|
2211
|
-
const range = createDOMRangeFromTextSelection(rootElement, snapshot);
|
|
2212
|
-
if (!range) {
|
|
2213
|
-
clearManagedHighlight(rootElement);
|
|
2214
|
-
return;
|
|
2215
|
-
}
|
|
2216
|
-
registry.delete(staleHighlightName);
|
|
2217
|
-
registry.set(highlightName, new Highlight(range));
|
|
2218
|
-
});
|
|
2219
|
-
};
|
|
2220
|
-
syncManagedHighlight();
|
|
2221
|
-
return () => {
|
|
2222
|
-
cancelScheduledSync();
|
|
2223
|
-
clearManagedHighlight(editor.getRootElement());
|
|
2224
|
-
};
|
|
2225
|
-
}, [editor, isEditorFocused, snapshot]);
|
|
2226
|
-
return null;
|
|
2227
|
-
}
|
|
2228
|
-
function AutoFocusPlugin() {
|
|
2229
|
-
const [editor] = useLexicalComposerContext();
|
|
2230
|
-
useEffect(() => {
|
|
2231
|
-
const root = editor.getRootElement();
|
|
2232
|
-
if (root) {
|
|
2233
|
-
root.focus({ preventScroll: true });
|
|
2234
|
-
} else {
|
|
2235
|
-
editor.focus();
|
|
2236
|
-
}
|
|
2237
|
-
}, [editor]);
|
|
2238
|
-
return null;
|
|
2239
|
-
}
|
|
2240
|
-
function EditorRefPlugin({ onEditorReady }) {
|
|
2241
|
-
const [editor] = useLexicalComposerContext();
|
|
2242
|
-
const callbackRef = useRef(onEditorReady);
|
|
2243
|
-
callbackRef.current = onEditorReady;
|
|
2244
|
-
useEffect(() => {
|
|
2245
|
-
callbackRef.current?.(editor);
|
|
2246
|
-
return () => callbackRef.current?.(null);
|
|
2247
|
-
}, [editor]);
|
|
2248
|
-
return null;
|
|
2249
|
-
}
|
|
2250
|
-
function FootnotePlugin({ children }) {
|
|
2251
|
-
const [editor] = useLexicalComposerContext();
|
|
2252
|
-
const [definitions, setDefinitions] = useState({});
|
|
2253
|
-
const [displayNumberMap, setDisplayNumberMap] = useState({});
|
|
2254
|
-
const pendingUpdateRef = useRef(false);
|
|
2255
|
-
useEffect(() => {
|
|
2256
|
-
return editor.registerUpdateListener(({ editorState }) => {
|
|
2257
|
-
editorState.read(() => {
|
|
2258
|
-
const footnoteNodes = $nodesOfType(FootnoteNode);
|
|
2259
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2260
|
-
const numberMap = {};
|
|
2261
|
-
let counter = 1;
|
|
2262
|
-
for (const node of footnoteNodes) {
|
|
2263
|
-
const id = node.getIdentifier();
|
|
2264
|
-
if (!seen.has(id)) {
|
|
2265
|
-
seen.add(id);
|
|
2266
|
-
numberMap[id] = counter++;
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
setDisplayNumberMap(numberMap);
|
|
2270
|
-
const sectionNodes = $nodesOfType(FootnoteSectionNode);
|
|
2271
|
-
if (sectionNodes.length > 0) {
|
|
2272
|
-
setDefinitions(sectionNodes[0].getDefinitions());
|
|
2273
|
-
} else {
|
|
2274
|
-
setDefinitions({});
|
|
2275
|
-
}
|
|
2276
|
-
if (!editor.isEditable() || pendingUpdateRef.current) return;
|
|
2277
|
-
if (footnoteNodes.length === 0 && sectionNodes.length > 0) {
|
|
2278
|
-
pendingUpdateRef.current = true;
|
|
2279
|
-
queueMicrotask(() => {
|
|
2280
|
-
editor.update(() => {
|
|
2281
|
-
const sections = $nodesOfType(FootnoteSectionNode);
|
|
2282
|
-
for (const s of sections) s.remove();
|
|
2283
|
-
});
|
|
2284
|
-
pendingUpdateRef.current = false;
|
|
2285
|
-
});
|
|
2286
|
-
return;
|
|
2287
|
-
}
|
|
2288
|
-
if (footnoteNodes.length > 0 && sectionNodes.length === 0) {
|
|
2289
|
-
const seenSnapshot = [...seen];
|
|
2290
|
-
pendingUpdateRef.current = true;
|
|
2291
|
-
queueMicrotask(() => {
|
|
2292
|
-
editor.update(() => {
|
|
2293
|
-
const root = $getRoot();
|
|
2294
|
-
const defs = {};
|
|
2295
|
-
for (const id of seenSnapshot) {
|
|
2296
|
-
defs[id] = "";
|
|
2297
|
-
}
|
|
2298
|
-
const section = $parseSerializedNode({
|
|
2299
|
-
type: "footnote-section",
|
|
2300
|
-
definitions: defs,
|
|
2301
|
-
version: 1
|
|
2302
|
-
});
|
|
2303
|
-
root.append(section);
|
|
2304
|
-
});
|
|
2305
|
-
pendingUpdateRef.current = false;
|
|
2306
|
-
});
|
|
2307
|
-
} else if (sectionNodes.length > 0) {
|
|
2308
|
-
const existingDefs = sectionNodes[0].getDefinitions();
|
|
2309
|
-
const missingIds = [...seen].filter((id) => !(id in existingDefs));
|
|
2310
|
-
const orphanIds = Object.keys(existingDefs).filter(
|
|
2311
|
-
(id) => !seen.has(id)
|
|
2312
|
-
);
|
|
2313
|
-
if (missingIds.length > 0 || orphanIds.length > 0) {
|
|
2314
|
-
pendingUpdateRef.current = true;
|
|
2315
|
-
queueMicrotask(() => {
|
|
2316
|
-
editor.update(() => {
|
|
2317
|
-
const freshSections = $nodesOfType(FootnoteSectionNode);
|
|
2318
|
-
if (freshSections.length > 0) {
|
|
2319
|
-
for (const id of missingIds) {
|
|
2320
|
-
freshSections[0].setDefinition(id, "");
|
|
2321
|
-
}
|
|
2322
|
-
for (const id of orphanIds) {
|
|
2323
|
-
freshSections[0].removeDefinition(id);
|
|
2324
|
-
}
|
|
2325
|
-
}
|
|
2326
|
-
});
|
|
2327
|
-
pendingUpdateRef.current = false;
|
|
2328
|
-
});
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
});
|
|
2332
|
-
});
|
|
2333
|
-
}, [editor]);
|
|
2334
|
-
return /* @__PURE__ */ jsx(
|
|
2335
|
-
FootnoteDefinitionsProvider,
|
|
2336
|
-
{
|
|
2337
|
-
definitions,
|
|
2338
|
-
displayNumberMap,
|
|
2339
|
-
children
|
|
2340
|
-
}
|
|
2341
|
-
);
|
|
2342
|
-
}
|
|
2343
|
-
function OnChangePlugin({ onChange, debounceMs }) {
|
|
2344
|
-
const [editor] = useLexicalComposerContext();
|
|
2345
|
-
const timerRef = useRef(void 0);
|
|
2346
|
-
const onChangeRef = useRef(onChange);
|
|
2347
|
-
onChangeRef.current = onChange;
|
|
2348
|
-
useEffect(() => {
|
|
2349
|
-
const unregister = editor.registerUpdateListener(({ editorState }) => {
|
|
2350
|
-
const fn = onChangeRef.current;
|
|
2351
|
-
if (!fn) return;
|
|
2352
|
-
const serializedState = normalizeSerializedEditorState(editorState.toJSON());
|
|
2353
|
-
if (debounceMs && debounceMs > 0) {
|
|
2354
|
-
clearTimeout(timerRef.current);
|
|
2355
|
-
timerRef.current = setTimeout(() => {
|
|
2356
|
-
fn(serializedState);
|
|
2357
|
-
}, debounceMs);
|
|
2358
|
-
} else {
|
|
2359
|
-
fn(serializedState);
|
|
2360
|
-
}
|
|
2361
|
-
});
|
|
2362
|
-
return () => {
|
|
2363
|
-
clearTimeout(timerRef.current);
|
|
2364
|
-
unregister();
|
|
2365
|
-
};
|
|
2366
|
-
}, [editor, debounceMs]);
|
|
2367
|
-
return null;
|
|
2368
|
-
}
|
|
2369
|
-
function SubmitShortcutPlugin({ onSubmit }) {
|
|
2370
|
-
const [editor] = useLexicalComposerContext();
|
|
2371
|
-
useEffect(() => {
|
|
2372
|
-
if (!onSubmit) return;
|
|
2373
|
-
return editor.registerCommand(
|
|
2374
|
-
KEY_ENTER_COMMAND,
|
|
2375
|
-
(event) => {
|
|
2376
|
-
if (event && (event.metaKey || event.ctrlKey)) {
|
|
2377
|
-
event.preventDefault();
|
|
2378
|
-
onSubmit();
|
|
2379
|
-
return true;
|
|
2380
|
-
}
|
|
2381
|
-
return false;
|
|
2382
|
-
},
|
|
2383
|
-
COMMAND_PRIORITY_HIGH
|
|
2384
|
-
);
|
|
2385
|
-
}, [editor, onSubmit]);
|
|
2386
|
-
return null;
|
|
2387
|
-
}
|
|
2388
|
-
export {
|
|
2389
|
-
$captureTextSelection as $,
|
|
2390
|
-
ALL_TRANSFORMERS as A,
|
|
2391
|
-
BlockExitPlugin as B,
|
|
2392
|
-
CorePlugins as C,
|
|
2393
|
-
EditorRefPlugin as E,
|
|
2394
|
-
FootnotePlugin as F,
|
|
2395
|
-
HorizontalRulePlugin as H,
|
|
2396
|
-
ImageUploadPlugin as I,
|
|
2397
|
-
LinkFaviconPlugin as L,
|
|
2398
|
-
MarkdownPastePlugin as M,
|
|
2399
|
-
OnChangePlugin as O,
|
|
2400
|
-
SubmitShortcutPlugin as S,
|
|
2401
|
-
TextSelectionPlugin as T,
|
|
2402
|
-
AutoFocusPlugin as a,
|
|
2403
|
-
AutoLinkPlugin as b,
|
|
2404
|
-
BlockIdPlugin as c,
|
|
2405
|
-
ImageUploadProvider as d,
|
|
2406
|
-
MarkdownShortcutsPlugin as e,
|
|
2407
|
-
blockIdState as f,
|
|
2408
|
-
defaultImageUpload as g,
|
|
2409
|
-
TextSelectionStoreProvider as h,
|
|
2410
|
-
$captureTextSelectionFromRangeSelection as i,
|
|
2411
|
-
$getRootBlock as j,
|
|
2412
|
-
$getTextOffsetInBlock as k,
|
|
2413
|
-
$resolveSelectionPoint as l,
|
|
2414
|
-
$restoreTextSelection as m,
|
|
2415
|
-
TEXT_SELECTION_HIGHLIGHT_NAME as n,
|
|
2416
|
-
buildBlockAnchor as o,
|
|
2417
|
-
buildRangeAnchor as p,
|
|
2418
|
-
createDOMRangeFromTextSelection as q,
|
|
2419
|
-
createTextSelectionStore as r,
|
|
2420
|
-
findDOMPointByTextOffset as s,
|
|
2421
|
-
getBlockElementById as t,
|
|
2422
|
-
useImageUpload as u,
|
|
2423
|
-
getDOMRectFromTextSelection as v,
|
|
2424
|
-
getTextOffsetFromDOMPoint as w,
|
|
2425
|
-
useTextSelectionSnapshot as x,
|
|
2426
|
-
useTextSelectionStore as y
|
|
2427
|
-
};
|