@sofereditor/core 0.1.0 → 0.2.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/index.cjs CHANGED
@@ -222,7 +222,9 @@ var EditorDocument = class _EditorDocument {
222
222
  marginTop: pick("marginTop") ?? DEFAULT_PAGE_SETTINGS.marginTop,
223
223
  marginBottom: pick("marginBottom") ?? DEFAULT_PAGE_SETTINGS.marginBottom,
224
224
  marginLeft: pick("marginLeft") ?? DEFAULT_PAGE_SETTINGS.marginLeft,
225
- marginRight: pick("marginRight") ?? DEFAULT_PAGE_SETTINGS.marginRight
225
+ marginRight: pick("marginRight") ?? DEFAULT_PAGE_SETTINGS.marginRight,
226
+ systemHeaderTitle: pick("systemHeaderTitle"),
227
+ systemHeaderAuthor: pick("systemHeaderAuthor")
226
228
  };
227
229
  merged.preset = detectPreset(merged.width, merged.height);
228
230
  return merged;
@@ -358,6 +360,17 @@ var EditorDocument = class _EditorDocument {
358
360
  */
359
361
  loadFromJSON(serialized) {
360
362
  const { blocks: sourceBlocks, pageSettings } = normalizeSerialized(serialized);
363
+ const LOCK_KEY = "__importLock";
364
+ const LOCK_TTL_MS = 5e3;
365
+ const existing = this.docSettings.get(LOCK_KEY);
366
+ if (typeof existing === "number" && Date.now() - existing < LOCK_TTL_MS) {
367
+ const ageMs = Date.now() - existing;
368
+ console.warn(
369
+ `[EditorDocument.loadFromJSON] import j\xE1 em andamento (${ageMs}ms atr\xE1s, TTL ${LOCK_TTL_MS}ms) \u2014 ignorando esta chamada para evitar duplica\xE7\xE3o de blocks.`
370
+ );
371
+ return;
372
+ }
373
+ this.docSettings.set(LOCK_KEY, Date.now());
361
374
  this.ydoc.transact(() => {
362
375
  if (this.blocks.length > 0) {
363
376
  this.blocks.delete(0, this.blocks.length);
@@ -377,6 +390,7 @@ var EditorDocument = class _EditorDocument {
377
390
  this.docSettings.set(k, v);
378
391
  }
379
392
  }
393
+ this.docSettings.delete(LOCK_KEY);
380
394
  }, "import");
381
395
  }
382
396
  /** Build a fresh `EditorDocument` from a `SerializedDocument`. */