@lobehub/editor 4.10.0 → 4.10.2

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 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");
@@ -2247,6 +2275,8 @@ init_helper();
2247
2275
  init_plugin();
2248
2276
  init_debug();
2249
2277
  const AUTO_COMPLETE_GUARD_LIMIT = 5e4;
2278
+ const CLEAR_PLACEHOLDER_BURST_LIMIT = 20;
2279
+ const CLEAR_PLACEHOLDER_BURST_WINDOW_MS = 1e3;
2250
2280
  const AutoCompletePlugin = class extends KernelPlugin {
2251
2281
  static {
2252
2282
  this.pluginName = "AutoCompletePlugin";
@@ -2263,6 +2293,7 @@ const AutoCompletePlugin = class extends KernelPlugin {
2263
2293
  this.currentSuggestion = null;
2264
2294
  this.markdownService = null;
2265
2295
  this.skipNextTextContentListener = false;
2296
+ this.clearPlaceholderCallTimestamps = [];
2266
2297
  this.delay = config?.delay ?? 1e3;
2267
2298
  kernel.registerNodes([PlaceholderNode, PlaceholderBlockNode]);
2268
2299
  if (config?.theme) kernel.registerThemes(config?.theme);
@@ -2500,6 +2531,10 @@ const AutoCompletePlugin = class extends KernelPlugin {
2500
2531
  });
2501
2532
  }
2502
2533
  clearPlaceholderNodes(editor) {
2534
+ const now = Date.now();
2535
+ this.clearPlaceholderCallTimestamps = this.clearPlaceholderCallTimestamps.filter((ts) => now - ts <= CLEAR_PLACEHOLDER_BURST_WINDOW_MS);
2536
+ if (this.clearPlaceholderCallTimestamps.length >= CLEAR_PLACEHOLDER_BURST_LIMIT) return;
2537
+ this.clearPlaceholderCallTimestamps.push(now);
2503
2538
  this.skipNextTextContentListener = true;
2504
2539
  this.currentSuggestion = null;
2505
2540
  this.placeholderNodes = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "4.10.0",
3
+ "version": "4.10.2",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",