@lobehub/editor 4.9.8 → 4.10.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/es/{ReactSlashPlugin-BZ0TZ1oy.js → ReactSlashPlugin-CBLFF1e6.js} +72 -50
- package/es/headless.js +761 -39
- package/es/index.js +259 -225
- package/es/react.js +1 -1
- package/package.json +1 -1
|
@@ -18537,8 +18537,9 @@ const selfClosingHtmlTags = new Set([
|
|
|
18537
18537
|
"wbr"
|
|
18538
18538
|
]);
|
|
18539
18539
|
var MarkdownContext = class {
|
|
18540
|
-
constructor(root) {
|
|
18540
|
+
constructor(root, markdown) {
|
|
18541
18541
|
this.root = root;
|
|
18542
|
+
this.markdown = markdown;
|
|
18542
18543
|
this.stack = [];
|
|
18543
18544
|
}
|
|
18544
18545
|
push(html) {
|
|
@@ -18554,15 +18555,36 @@ var MarkdownContext = class {
|
|
|
18554
18555
|
return this.stack.pop();
|
|
18555
18556
|
}
|
|
18556
18557
|
};
|
|
18557
|
-
|
|
18558
|
+
const getNodeRawMarkdown = (node, markdown) => {
|
|
18559
|
+
const start = node.position?.start.offset;
|
|
18560
|
+
const end = node.position?.end.offset;
|
|
18561
|
+
if (typeof start === "number" && typeof end === "number") return markdown.slice(start, end);
|
|
18562
|
+
if ("value" in node && typeof node.value === "string") return node.value;
|
|
18563
|
+
return "";
|
|
18564
|
+
};
|
|
18565
|
+
const createFallbackRawNode = (node, ctx, parentType) => {
|
|
18566
|
+
const raw = getNodeRawMarkdown(node, ctx.markdown);
|
|
18567
|
+
if (!raw) return null;
|
|
18568
|
+
if (parentType === null || parentType === "root") return {
|
|
18569
|
+
...INodeHelper.createParagraph(),
|
|
18570
|
+
children: [INodeHelper.createTextNode(raw)]
|
|
18571
|
+
};
|
|
18572
|
+
return INodeHelper.createTextNode(raw);
|
|
18573
|
+
};
|
|
18574
|
+
function convertMdastToLexical(node, index, ctx, markdownReaders = {}, parentType = null) {
|
|
18558
18575
|
switch (node.type) {
|
|
18559
18576
|
case "text": return INodeHelper.createTextNode(node.value);
|
|
18560
18577
|
default: {
|
|
18578
|
+
if (!markdownReaders[node.type]) return createFallbackRawNode(node, ctx, parentType);
|
|
18561
18579
|
let children = [];
|
|
18562
18580
|
if ("children" in node && Array.isArray(node.children)) {
|
|
18563
18581
|
let htmlStack = [];
|
|
18564
18582
|
children = node.children.reduce((ret, child, index) => {
|
|
18565
18583
|
if (child.type === "html") {
|
|
18584
|
+
if (!markdownReaders["html"]) {
|
|
18585
|
+
ret.push(INodeHelper.createTextNode(child.value));
|
|
18586
|
+
return ret;
|
|
18587
|
+
}
|
|
18566
18588
|
if (child.value.startsWith("<!--") && child.value.endsWith("-->")) return ret;
|
|
18567
18589
|
const tag = child.value.replaceAll(/^<\/?|>$/g, "");
|
|
18568
18590
|
const isEndTag = child.value.startsWith("</");
|
|
@@ -18624,10 +18646,10 @@ function convertMdastToLexical(node, index, ctx, markdownReaders = {}) {
|
|
|
18624
18646
|
}
|
|
18625
18647
|
if (htmlStack.length > 0) {
|
|
18626
18648
|
const top = ctx.last;
|
|
18627
|
-
if (top) top.children.push(convertMdastToLexical(child, index, ctx, markdownReaders));
|
|
18649
|
+
if (top) top.children.push(convertMdastToLexical(child, index, ctx, markdownReaders, node.type));
|
|
18628
18650
|
return ret;
|
|
18629
18651
|
}
|
|
18630
|
-
ret.push(convertMdastToLexical(child, index, ctx, markdownReaders));
|
|
18652
|
+
ret.push(convertMdastToLexical(child, index, ctx, markdownReaders, node.type));
|
|
18631
18653
|
return ret;
|
|
18632
18654
|
}, []).filter(Boolean).flat();
|
|
18633
18655
|
while (htmlStack.length > 0) {
|
|
@@ -18679,7 +18701,7 @@ function registerDefaultReaders(markdownReaders) {
|
|
|
18679
18701
|
function parseMarkdownToLexical(markdown, markdownReaders = {}) {
|
|
18680
18702
|
const ast = remark().use(remarkCjkFriendly).use(remarkMath).use([[remarkGfm, { singleTilde: false }]]).parse(markdown);
|
|
18681
18703
|
logger$2.debug("Parsed MDAST:", ast);
|
|
18682
|
-
const ctx = new MarkdownContext(ast);
|
|
18704
|
+
const ctx = new MarkdownContext(ast, markdown);
|
|
18683
18705
|
registerDefaultReaders(markdownReaders);
|
|
18684
18706
|
return convertMdastToLexical(ast, 0, ctx, markdownReaders);
|
|
18685
18707
|
}
|
|
@@ -20493,7 +20515,7 @@ const CommonPlugin = class extends KernelPlugin {
|
|
|
20493
20515
|
const breakMark = (this.config?.markdownOption ?? true) !== false ? "\n\n" : "\n";
|
|
20494
20516
|
const formats = this.formats;
|
|
20495
20517
|
if (formats.quote) markdownService.registerMarkdownShortCut({
|
|
20496
|
-
regExp:
|
|
20518
|
+
regExp: /^(>|》)\s/,
|
|
20497
20519
|
replace: (parentNode, children, _match, isImport) => {
|
|
20498
20520
|
if (isImport) {
|
|
20499
20521
|
const previousNode = parentNode.getPreviousSibling();
|
|
@@ -21078,6 +21100,49 @@ function registerCodeInlineCommand(editor) {
|
|
|
21078
21100
|
}, COMMAND_PRIORITY_EDITOR);
|
|
21079
21101
|
}
|
|
21080
21102
|
//#endregion
|
|
21103
|
+
//#region src/plugins/link/utils/index.ts
|
|
21104
|
+
const SUPPORTED_URL_PROTOCOLS = new Set([
|
|
21105
|
+
"http:",
|
|
21106
|
+
"https:",
|
|
21107
|
+
"mailto:",
|
|
21108
|
+
"sms:",
|
|
21109
|
+
"tel:"
|
|
21110
|
+
]);
|
|
21111
|
+
function sanitizeUrl(url) {
|
|
21112
|
+
try {
|
|
21113
|
+
const parsedUrl = new URL(url);
|
|
21114
|
+
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) return "about:blank";
|
|
21115
|
+
} catch {
|
|
21116
|
+
return url;
|
|
21117
|
+
}
|
|
21118
|
+
return url;
|
|
21119
|
+
}
|
|
21120
|
+
const urlRegExp = /* @__PURE__ */ new RegExp(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\w$&+,:;=-]+@)?[\d.A-Za-z-]+|(?:www.|[\w$&+,:;=-]+@)[\d.A-Za-z-]+)((?:\/[%+./~\w-_]*)?\??[\w%&+.;=@-]*#?\w*)?)/);
|
|
21121
|
+
function validateUrl(url) {
|
|
21122
|
+
return url === "https://" || urlRegExp.test(url);
|
|
21123
|
+
}
|
|
21124
|
+
function extractUrlFromText(text) {
|
|
21125
|
+
const match = urlRegExp.exec(text);
|
|
21126
|
+
if (!match) return null;
|
|
21127
|
+
const raw = match[0];
|
|
21128
|
+
const start = match.index ?? text.indexOf(raw);
|
|
21129
|
+
const trimmed = raw.replace(/[)\],.;:]+$/u, "");
|
|
21130
|
+
return {
|
|
21131
|
+
index: start,
|
|
21132
|
+
length: trimmed.length,
|
|
21133
|
+
url: trimmed
|
|
21134
|
+
};
|
|
21135
|
+
}
|
|
21136
|
+
function getSelectedNode(selection) {
|
|
21137
|
+
const anchor = selection.anchor;
|
|
21138
|
+
const focus = selection.focus;
|
|
21139
|
+
const anchorNode = selection.anchor.getNode();
|
|
21140
|
+
const focusNode = selection.focus.getNode();
|
|
21141
|
+
if (anchorNode === focusNode) return anchorNode;
|
|
21142
|
+
if (selection.isBackward()) return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
21143
|
+
else return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
|
|
21144
|
+
}
|
|
21145
|
+
//#endregion
|
|
21081
21146
|
//#region src/plugins/list/plugin/checkList.ts
|
|
21082
21147
|
/**
|
|
21083
21148
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -22091,49 +22156,6 @@ function useLexicalNodeSelection(key) {
|
|
|
22091
22156
|
];
|
|
22092
22157
|
}
|
|
22093
22158
|
//#endregion
|
|
22094
|
-
//#region src/plugins/link/utils/index.ts
|
|
22095
|
-
const SUPPORTED_URL_PROTOCOLS = new Set([
|
|
22096
|
-
"http:",
|
|
22097
|
-
"https:",
|
|
22098
|
-
"mailto:",
|
|
22099
|
-
"sms:",
|
|
22100
|
-
"tel:"
|
|
22101
|
-
]);
|
|
22102
|
-
function sanitizeUrl(url) {
|
|
22103
|
-
try {
|
|
22104
|
-
const parsedUrl = new URL(url);
|
|
22105
|
-
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) return "about:blank";
|
|
22106
|
-
} catch {
|
|
22107
|
-
return url;
|
|
22108
|
-
}
|
|
22109
|
-
return url;
|
|
22110
|
-
}
|
|
22111
|
-
const urlRegExp = /* @__PURE__ */ new RegExp(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\w$&+,:;=-]+@)?[\d.A-Za-z-]+|(?:www.|[\w$&+,:;=-]+@)[\d.A-Za-z-]+)((?:\/[%+./~\w-_]*)?\??[\w%&+.;=@-]*#?\w*)?)/);
|
|
22112
|
-
function validateUrl(url) {
|
|
22113
|
-
return url === "https://" || urlRegExp.test(url);
|
|
22114
|
-
}
|
|
22115
|
-
function extractUrlFromText(text) {
|
|
22116
|
-
const match = urlRegExp.exec(text);
|
|
22117
|
-
if (!match) return null;
|
|
22118
|
-
const raw = match[0];
|
|
22119
|
-
const start = match.index ?? text.indexOf(raw);
|
|
22120
|
-
const trimmed = raw.replace(/[)\],.;:]+$/u, "");
|
|
22121
|
-
return {
|
|
22122
|
-
index: start,
|
|
22123
|
-
length: trimmed.length,
|
|
22124
|
-
url: trimmed
|
|
22125
|
-
};
|
|
22126
|
-
}
|
|
22127
|
-
function getSelectedNode(selection) {
|
|
22128
|
-
const anchor = selection.anchor;
|
|
22129
|
-
const focus = selection.focus;
|
|
22130
|
-
const anchorNode = selection.anchor.getNode();
|
|
22131
|
-
const focusNode = selection.focus.getNode();
|
|
22132
|
-
if (anchorNode === focusNode) return anchorNode;
|
|
22133
|
-
if (selection.isBackward()) return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
22134
|
-
else return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
|
|
22135
|
-
}
|
|
22136
|
-
//#endregion
|
|
22137
22159
|
//#region src/plugins/link-highlight/command/index.ts
|
|
22138
22160
|
const INSERT_LINK_HIGHLIGHT_COMMAND = createCommand("INSERT_LINK_HIGHLIGHT_COMMAND");
|
|
22139
22161
|
function registerLinkHighlightCommand(editor) {
|
|
@@ -22947,4 +22969,4 @@ const ReactSlashPlugin = ({ children, anchorClassName, getPopupContainer, placem
|
|
|
22947
22969
|
};
|
|
22948
22970
|
ReactSlashPlugin.displayName = "ReactSlashPlugin";
|
|
22949
22971
|
//#endregion
|
|
22950
|
-
export { detectLanguage as A, INodePlugin as B, ReactPlainText as C, useTranslation as D, ReactMarkdownPlugin as E, GET_MARKDOWN_SELECTION_COMMAND as F, idToChar as G, $cloneNode as H, INSERT_MARKDOWN_COMMAND as I, useLexicalEditor as J, INSERT_HEADING_COMMAND as K, isPunctuationChar as L, MARKDOWN_READER_LEVEL_HIGH as M, MARKDOWN_READER_LEVEL_NORMAL as N, MarkdownPlugin as O, MARKDOWN_WRITER_LEVEL_MAX as P, ILitexmlService as R, registerCodeInlineCommand as S, CommonPlugin as T, $parseSerializedNodeImpl as U, INodeService as V, charToId as W, useLexicalComposerContext as X, ReactEditor as Y, LexicalErrorBoundary as Z,
|
|
22972
|
+
export { detectLanguage as A, INodePlugin as B, ReactPlainText as C, useTranslation as D, ReactMarkdownPlugin as E, GET_MARKDOWN_SELECTION_COMMAND as F, idToChar as G, $cloneNode as H, INSERT_MARKDOWN_COMMAND as I, useLexicalEditor as J, INSERT_HEADING_COMMAND as K, isPunctuationChar as L, MARKDOWN_READER_LEVEL_HIGH as M, MARKDOWN_READER_LEVEL_NORMAL as N, MarkdownPlugin as O, MARKDOWN_WRITER_LEVEL_MAX as P, ILitexmlService as R, registerCodeInlineCommand as S, CommonPlugin as T, $parseSerializedNodeImpl as U, INodeService as V, charToId as W, useLexicalComposerContext as X, ReactEditor as Y, LexicalErrorBoundary as Z, extractUrlFromText as _, ReactMentionPlugin as a, validateUrl as b, INSERT_LINK_HIGHLIGHT_COMMAND as c, bundledLanguagesInfo$1 as d, CodeblockPlugin as f, registerCheckList as g, INSERT_CHECK_LIST_COMMAND as h, SlashPlugin as i, IMarkdownShortCutService as j, detectCodeLanguage as k, registerLinkHighlightCommand as l, getCodeLanguageByInput as m, ReactSlashOption as n, MentionPlugin as o, UPDATE_CODEBLOCK_LANG as p, INSERT_QUOTE_COMMAND as q, SlashMenu as r, INSERT_MENTION_COMMAND as s, ReactSlashPlugin as t, useLexicalNodeSelection as u, getSelectedNode as v, ReactEditorContent as w, INSERT_CODEINLINE_COMMAND as x, sanitizeUrl as y, LitexmlService as z };
|