@lobehub/editor 4.10.1 → 4.10.3
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/headless.js +29 -1
- package/es/index.js +33 -28
- package/package.json +1 -1
package/es/headless.js
CHANGED
|
@@ -26831,6 +26831,34 @@ const normalizeLegacyEditorData = (editorData) => {
|
|
|
26831
26831
|
root: normalizeLegacyEditorDataNode(data.root, context)
|
|
26832
26832
|
};
|
|
26833
26833
|
};
|
|
26834
|
+
const extractSerializedCodeText = (children) => children.map((child) => {
|
|
26835
|
+
if (!child || typeof child !== "object") return "";
|
|
26836
|
+
const record = child;
|
|
26837
|
+
if (record.type === "linebreak") return "\n";
|
|
26838
|
+
if (record.type === "tab") return " ";
|
|
26839
|
+
if (typeof record.text === "string") return record.text;
|
|
26840
|
+
if (Array.isArray(record.children)) return extractSerializedCodeText(record.children);
|
|
26841
|
+
return "";
|
|
26842
|
+
}).join("");
|
|
26843
|
+
const preserveSerializedCodeText = (node) => {
|
|
26844
|
+
if (!node || typeof node !== "object") return node;
|
|
26845
|
+
const record = node;
|
|
26846
|
+
const children = Array.isArray(record.children) ? record.children.map((child) => preserveSerializedCodeText(child)) : record.children;
|
|
26847
|
+
if (record.type === "code" && Array.isArray(children)) return {
|
|
26848
|
+
...record,
|
|
26849
|
+
children,
|
|
26850
|
+
code: extractSerializedCodeText(children)
|
|
26851
|
+
};
|
|
26852
|
+
if (Array.isArray(children)) return {
|
|
26853
|
+
...record,
|
|
26854
|
+
children
|
|
26855
|
+
};
|
|
26856
|
+
return record;
|
|
26857
|
+
};
|
|
26858
|
+
const preserveSerializedCodeTextInEditorData = (editorData) => ({
|
|
26859
|
+
...editorData,
|
|
26860
|
+
root: preserveSerializedCodeText(editorData.root)
|
|
26861
|
+
});
|
|
26834
26862
|
const DEFAULT_HEADLESS_EDITOR_PLUGINS = [
|
|
26835
26863
|
[CommonPlugin, { enableHotkey: false }],
|
|
26836
26864
|
MarkdownPlugin,
|
|
@@ -26879,7 +26907,7 @@ var HeadlessEditor = class {
|
|
|
26879
26907
|
}
|
|
26880
26908
|
export(options = {}) {
|
|
26881
26909
|
const snapshot = {
|
|
26882
|
-
editorData: this.kernel.getDocument("json"),
|
|
26910
|
+
editorData: preserveSerializedCodeTextInEditorData(this.kernel.getDocument("json")),
|
|
26883
26911
|
markdown: this.kernel.getDocument("markdown")
|
|
26884
26912
|
};
|
|
26885
26913
|
if (options.litexml) snapshot.litexml = this.kernel.getDocument("litexml");
|
package/es/index.js
CHANGED
|
@@ -2154,6 +2154,34 @@ const normalizeLegacyEditorData = (editorData) => {
|
|
|
2154
2154
|
root: normalizeLegacyEditorDataNode(data.root, context)
|
|
2155
2155
|
};
|
|
2156
2156
|
};
|
|
2157
|
+
const extractSerializedCodeText = (children) => children.map((child) => {
|
|
2158
|
+
if (!child || typeof child !== "object") return "";
|
|
2159
|
+
const record = child;
|
|
2160
|
+
if (record.type === "linebreak") return "\n";
|
|
2161
|
+
if (record.type === "tab") return " ";
|
|
2162
|
+
if (typeof record.text === "string") return record.text;
|
|
2163
|
+
if (Array.isArray(record.children)) return extractSerializedCodeText(record.children);
|
|
2164
|
+
return "";
|
|
2165
|
+
}).join("");
|
|
2166
|
+
const preserveSerializedCodeText = (node) => {
|
|
2167
|
+
if (!node || typeof node !== "object") return node;
|
|
2168
|
+
const record = node;
|
|
2169
|
+
const children = Array.isArray(record.children) ? record.children.map((child) => preserveSerializedCodeText(child)) : record.children;
|
|
2170
|
+
if (record.type === "code" && Array.isArray(children)) return {
|
|
2171
|
+
...record,
|
|
2172
|
+
children,
|
|
2173
|
+
code: extractSerializedCodeText(children)
|
|
2174
|
+
};
|
|
2175
|
+
if (Array.isArray(children)) return {
|
|
2176
|
+
...record,
|
|
2177
|
+
children
|
|
2178
|
+
};
|
|
2179
|
+
return record;
|
|
2180
|
+
};
|
|
2181
|
+
const preserveSerializedCodeTextInEditorData = (editorData) => ({
|
|
2182
|
+
...editorData,
|
|
2183
|
+
root: preserveSerializedCodeText(editorData.root)
|
|
2184
|
+
});
|
|
2157
2185
|
const DEFAULT_HEADLESS_EDITOR_PLUGINS = [
|
|
2158
2186
|
[CommonPlugin, { enableHotkey: false }],
|
|
2159
2187
|
MarkdownPlugin,
|
|
@@ -2202,7 +2230,7 @@ var HeadlessEditor = class {
|
|
|
2202
2230
|
}
|
|
2203
2231
|
export(options = {}) {
|
|
2204
2232
|
const snapshot = {
|
|
2205
|
-
editorData: this.kernel.getDocument("json"),
|
|
2233
|
+
editorData: preserveSerializedCodeTextInEditorData(this.kernel.getDocument("json")),
|
|
2206
2234
|
markdown: this.kernel.getDocument("markdown")
|
|
2207
2235
|
};
|
|
2208
2236
|
if (options.litexml) snapshot.litexml = this.kernel.getDocument("litexml");
|
|
@@ -2243,7 +2271,6 @@ function createHeadlessEditor(options) {
|
|
|
2243
2271
|
}
|
|
2244
2272
|
//#endregion
|
|
2245
2273
|
//#region src/plugins/auto-complete/plugin/index.ts
|
|
2246
|
-
init_helper();
|
|
2247
2274
|
init_plugin();
|
|
2248
2275
|
init_debug();
|
|
2249
2276
|
const AUTO_COMPLETE_GUARD_LIMIT = 5e4;
|
|
@@ -2491,12 +2518,6 @@ const AutoCompletePlugin = class extends KernelPlugin {
|
|
|
2491
2518
|
type: "PlaceholderBlock"
|
|
2492
2519
|
};
|
|
2493
2520
|
}
|
|
2494
|
-
const markerNode = INodeHelper.createTextNode("");
|
|
2495
|
-
nodes.children.push({
|
|
2496
|
-
children: [markerNode],
|
|
2497
|
-
name: "",
|
|
2498
|
-
type: "PlaceholderInline"
|
|
2499
|
-
});
|
|
2500
2521
|
const saveSel = selection.clone();
|
|
2501
2522
|
this.markdownService.insertIRootNode(editor, nodes, selection);
|
|
2502
2523
|
$setSelection(saveSel);
|
|
@@ -2511,31 +2532,15 @@ const AutoCompletePlugin = class extends KernelPlugin {
|
|
|
2511
2532
|
this.currentSuggestion = null;
|
|
2512
2533
|
this.placeholderNodes = [];
|
|
2513
2534
|
editor.update(() => {
|
|
2535
|
+
const selection = $getSelection();
|
|
2536
|
+
const clonedSelection = selection ? selection.clone() : null;
|
|
2514
2537
|
let iterCount = 0;
|
|
2515
2538
|
editor.getEditorState()._nodeMap.forEach((node) => {
|
|
2516
2539
|
iterCount++;
|
|
2517
2540
|
if (iterCount > AUTO_COMPLETE_GUARD_LIMIT) throw new Error(`clearPlaceholderNodes: forEach loop > ${AUTO_COMPLETE_GUARD_LIMIT} iterations`);
|
|
2518
|
-
|
|
2519
|
-
const clonedSelection = selection ? selection.clone() : null;
|
|
2520
|
-
if (node.isAttached() && ["PlaceholderBlock", "PlaceholderInline"].includes(node.getType())) {
|
|
2521
|
-
if (node.getType() === "PlaceholderInline" && node.getTextContent().includes("") && node.getPreviousSibling() === null) {
|
|
2522
|
-
const siblings = [];
|
|
2523
|
-
let sibling = node.getNextSibling();
|
|
2524
|
-
let siblingLoopCount = 0;
|
|
2525
|
-
while (sibling && siblingLoopCount < AUTO_COMPLETE_GUARD_LIMIT) {
|
|
2526
|
-
siblings.push(sibling);
|
|
2527
|
-
sibling = sibling.getNextSibling();
|
|
2528
|
-
siblingLoopCount++;
|
|
2529
|
-
}
|
|
2530
|
-
if (siblingLoopCount >= AUTO_COMPLETE_GUARD_LIMIT) throw new Error(`clearPlaceholderNodes: too many siblings (${siblingLoopCount}/${AUTO_COMPLETE_GUARD_LIMIT})`);
|
|
2531
|
-
node.getParent()?.remove();
|
|
2532
|
-
if (siblings.length > 0) $insertNodes(siblings);
|
|
2533
|
-
$setSelection(clonedSelection);
|
|
2534
|
-
return;
|
|
2535
|
-
}
|
|
2536
|
-
node.remove();
|
|
2537
|
-
}
|
|
2541
|
+
if (node.isAttached() && ["PlaceholderBlock", "PlaceholderInline"].includes(node.getType())) node.remove();
|
|
2538
2542
|
});
|
|
2543
|
+
if (clonedSelection) $setSelection(clonedSelection);
|
|
2539
2544
|
});
|
|
2540
2545
|
}
|
|
2541
2546
|
applySuggestion(editor) {
|
package/package.json
CHANGED