@harbour-enterprises/superdoc 1.3.0-next.3 → 1.3.0-next.4

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.
@@ -30890,8 +30890,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
30890
30890
  hash: attrs.hash
30891
30891
  };
30892
30892
  const annotationAttrsJson = JSON.stringify(annotationAttrs);
30893
+ const sanitizedDisplayLabel = attrs.displayLabel === "undefined" || attrs.displayLabel === void 0 ? "" : attrs.displayLabel;
30893
30894
  const sdtPrElements = [
30894
- { name: "w:alias", attributes: { "w:val": attrs.displayLabel } },
30895
+ { name: "w:alias", attributes: { "w:val": sanitizedDisplayLabel } },
30895
30896
  { name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
30896
30897
  { name: "w:id", attributes: { "w:val": id } }
30897
30898
  ];
@@ -36365,7 +36366,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36365
36366
  static getStoredSuperdocVersion(docx) {
36366
36367
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
36367
36368
  }
36368
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.3") {
36369
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.4") {
36369
36370
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36370
36371
  }
36371
36372
  /**
@@ -49668,8 +49669,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
49668
49669
  const hasMatchingId = changeMarks.find((mark2) => mark2.attrs.id === id);
49669
49670
  if (hasMatchingId) nodesWithMark.push(node3);
49670
49671
  });
49672
+ const nodesToProcess = nodesWithMark.length ? nodesWithMark : node2 ? [node2] : [];
49673
+ if (!nodesToProcess.length) {
49674
+ return;
49675
+ }
49671
49676
  const { deletionText, trackedChangeText } = getTrackedChangeText({
49672
- nodes: nodesWithMark.length ? nodesWithMark : [node2],
49677
+ nodes: nodesToProcess,
49673
49678
  mark: trackedMark,
49674
49679
  trackedChangeType,
49675
49680
  isDeletionInsertion
@@ -52998,6 +53003,45 @@ Please report this to https://github.com/markedjs/marked.`, e) {
52998
53003
  console.warn("[collaboration] Failed to update Ydoc docx data", error);
52999
53004
  }
53000
53005
  };
53006
+ let isApplyingRemoteChanges = false;
53007
+ const isApplyingRemoteHeaderFooterChanges = () => isApplyingRemoteChanges;
53008
+ const pushHeaderFooterToYjs = (editor, type, sectionId, content2) => {
53009
+ if (isApplyingRemoteChanges) return;
53010
+ const ydoc = editor?.options?.ydoc;
53011
+ if (!ydoc) return;
53012
+ const headerFooterMap = ydoc.getMap("headerFooterJson");
53013
+ const key2 = `${type}:${sectionId}`;
53014
+ const existing = headerFooterMap.get(key2)?.content;
53015
+ if (existing && JSON.stringify(existing) === JSON.stringify(content2)) {
53016
+ return;
53017
+ }
53018
+ ydoc.transact(() => headerFooterMap.set(key2, { type, sectionId, content: content2 }), {
53019
+ event: "header-footer-update",
53020
+ user: editor.options.user
53021
+ });
53022
+ };
53023
+ const applyRemoteHeaderFooterChanges = (editor, key2, data) => {
53024
+ if (!editor || editor.isDestroyed || !editor.converter) return;
53025
+ const { type, sectionId, content: content2 } = data;
53026
+ if (!type || !sectionId || !content2) return;
53027
+ isApplyingRemoteChanges = true;
53028
+ try {
53029
+ const storage = editor.converter[`${type}s`];
53030
+ if (storage) storage[sectionId] = content2;
53031
+ editor.converter.headerFooterModified = true;
53032
+ const editors = editor.converter[`${type}Editors`];
53033
+ editors?.forEach((item) => {
53034
+ if (item.id === sectionId && item.editor) {
53035
+ item.editor.replaceContent(content2);
53036
+ }
53037
+ });
53038
+ editor.emit("remoteHeaderFooterChanged", { type, sectionId, content: content2 });
53039
+ } finally {
53040
+ setTimeout(() => {
53041
+ isApplyingRemoteChanges = false;
53042
+ }, 0);
53043
+ }
53044
+ };
53001
53045
  new PluginKey("collaboration");
53002
53046
  const Collaboration = Extension.create({
53003
53047
  name: "collaboration",
@@ -53026,6 +53070,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
53026
53070
  }
53027
53071
  });
53028
53072
  });
53073
+ const headerFooterMap = this.options.ydoc.getMap("headerFooterJson");
53074
+ headerFooterMap.observe((event) => {
53075
+ if (event.transaction.local) return;
53076
+ event.changes.keys.forEach((change, key2) => {
53077
+ if (change.action === "add" || change.action === "update") {
53078
+ const data = headerFooterMap.get(key2);
53079
+ if (data) {
53080
+ applyRemoteHeaderFooterChanges(this.editor, key2, data);
53081
+ }
53082
+ }
53083
+ });
53084
+ });
53029
53085
  return [syncPlugin];
53030
53086
  },
53031
53087
  addCommands() {
@@ -62020,7 +62076,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62020
62076
  return false;
62021
62077
  }
62022
62078
  };
62023
- const summaryVersion = "1.3.0-next.3";
62079
+ const summaryVersion = "1.3.0-next.4";
62024
62080
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
62025
62081
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
62026
62082
  function mapAttributes(attrs) {
@@ -64654,7 +64710,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64654
64710
  * Process collaboration migrations
64655
64711
  */
64656
64712
  processCollaborationMigrations() {
64657
- console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.3");
64713
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.4");
64658
64714
  if (!this.options.ydoc) return;
64659
64715
  const metaMap = this.options.ydoc.getMap("meta");
64660
64716
  let docVersion = metaMap.get("version");
@@ -74233,7 +74289,12 @@ ${l}
74233
74289
  const hanging = paraIndent?.hanging ?? 0;
74234
74290
  const isFirstLineOfPara = lineIndex === 0 || lineIndex === void 0;
74235
74291
  const firstLineOffsetForCumX = isFirstLineOfPara ? firstLine - hanging : 0;
74236
- const indentOffset = indentLeft + firstLineOffsetForCumX;
74292
+ const wordLayoutValue = block.attrs?.wordLayout;
74293
+ const wordLayout = isMinimalWordLayout(wordLayoutValue) ? wordLayoutValue : void 0;
74294
+ const isListParagraph = Boolean(wordLayout?.marker);
74295
+ const rawTextStartPx = typeof wordLayout?.marker?.textStartX === "number" && Number.isFinite(wordLayout.marker.textStartX) ? wordLayout.marker.textStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
74296
+ const listIndentOffset = isFirstLineOfPara ? rawTextStartPx ?? indentLeft : indentLeft;
74297
+ const indentOffset = isListParagraph ? listIndentOffset : indentLeft + firstLineOffsetForCumX;
74237
74298
  let cumulativeX = 0;
74238
74299
  const segmentsByRun = /* @__PURE__ */ new Map();
74239
74300
  line.segments.forEach((segment) => {
@@ -86780,6 +86841,15 @@ ${l}
86780
86841
  if (px == null || !Number.isFinite(px)) return void 0;
86781
86842
  return px / PX_PER_PT;
86782
86843
  };
86844
+ const convertIndentTwipsToPx$1 = (indent2) => {
86845
+ if (!indent2) return void 0;
86846
+ const result = {};
86847
+ if (isFiniteNumber(indent2.left)) result.left = twipsToPx$1(indent2.left);
86848
+ if (isFiniteNumber(indent2.right)) result.right = twipsToPx$1(indent2.right);
86849
+ if (isFiniteNumber(indent2.firstLine)) result.firstLine = twipsToPx$1(indent2.firstLine);
86850
+ if (isFiniteNumber(indent2.hanging)) result.hanging = twipsToPx$1(indent2.hanging);
86851
+ return Object.keys(result).length ? result : void 0;
86852
+ };
86783
86853
  const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
86784
86854
  const isPlainObject$4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
86785
86855
  const normalizePrefix = (value) => {
@@ -89764,8 +89834,11 @@ ${l}
89764
89834
  const hydrated = hydrationOverride ?? hydrateParagraphStyleAttrs(para, converterContext);
89765
89835
  const mergedSpacing = mergeSpacingSources(hydrated?.spacing, paragraphProps.spacing, attrs.spacing);
89766
89836
  const normalizedSpacing = normalizeParagraphSpacing(mergedSpacing);
89767
- const indentSource = attrs.indent ?? paragraphProps.indent ?? hydrated?.indent;
89768
- const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? attrs.textIndent);
89837
+ const normalizeIndentObject = (value) => {
89838
+ if (!value || typeof value !== "object") return;
89839
+ return normalizePxIndent(value) ?? convertIndentTwipsToPx(value);
89840
+ };
89841
+ const normalizedIndent = normalizeIndentObject(attrs.indent) ?? convertIndentTwipsToPx(paragraphProps.indent) ?? convertIndentTwipsToPx(hydrated?.indent) ?? normalizeParagraphIndent(attrs.textIndent);
89769
89842
  const unwrapTabStops = (tabStops) => {
89770
89843
  if (!Array.isArray(tabStops)) {
89771
89844
  return void 0;
@@ -91335,9 +91408,12 @@ ${l}
91335
91408
  };
91336
91409
  } else {
91337
91410
  const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
91338
- const indentSource = para.attrs?.indent ?? paragraphProps.indent ?? paragraphHydration?.indent;
91411
+ const normalizeIndentObject = (value) => {
91412
+ if (!value || typeof value !== "object") return;
91413
+ return normalizePxIndent(value) ?? convertIndentTwipsToPx$1(value);
91414
+ };
91339
91415
  const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
91340
- const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? para.attrs?.textIndent);
91416
+ const normalizedIndent = normalizeIndentObject(para.attrs?.indent) ?? convertIndentTwipsToPx$1(paragraphProps.indent) ?? convertIndentTwipsToPx$1(paragraphHydration?.indent) ?? normalizeParagraphIndent(para.attrs?.textIndent);
91341
91417
  const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
91342
91418
  const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
91343
91419
  if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
@@ -93058,6 +93134,9 @@ ${l}
93058
93134
  };
93059
93135
  const onHeaderFooterDataUpdate = async ({ editor, transaction }, mainEditor, sectionId, type) => {
93060
93136
  if (!type || !sectionId) return;
93137
+ if (isApplyingRemoteHeaderFooterChanges()) {
93138
+ return;
93139
+ }
93061
93140
  const updatedData = editor.getUpdatedJson();
93062
93141
  const editorsList = mainEditor.converter[`${type}Editors`];
93063
93142
  if (Array.isArray(editorsList)) {
@@ -93081,6 +93160,7 @@ ${l}
93081
93160
  if (editor.docChanged && mainEditor.converter) {
93082
93161
  mainEditor.converter.headerFooterModified = true;
93083
93162
  }
93163
+ pushHeaderFooterToYjs(mainEditor, type, sectionId, updatedData);
93084
93164
  await updateYdocDocxData(mainEditor);
93085
93165
  };
93086
93166
  const setEditorToolbar = ({ editor }, mainEditor) => {
@@ -97929,6 +98009,17 @@ ${l}
97929
98009
  event: "collaborationReady",
97930
98010
  handler: handleCollaborationReady
97931
98011
  });
98012
+ const handleRemoteHeaderFooterChanged = (payload) => {
98013
+ this.#headerFooterAdapter?.invalidate(payload.sectionId);
98014
+ this.#headerFooterManager?.refresh();
98015
+ this.#pendingDocChange = true;
98016
+ this.#scheduleRerender();
98017
+ };
98018
+ this.#editor.on("remoteHeaderFooterChanged", handleRemoteHeaderFooterChanged);
98019
+ this.#editorListeners.push({
98020
+ event: "remoteHeaderFooterChanged",
98021
+ handler: handleRemoteHeaderFooterChanged
98022
+ });
97932
98023
  }
97933
98024
  /**
97934
98025
  * Setup awareness event subscriptions for remote cursor tracking.
@@ -143604,7 +143695,7 @@ ${reason}`);
143604
143695
  this.config.colors = shuffleArray(this.config.colors);
143605
143696
  this.userColorMap = /* @__PURE__ */ new Map();
143606
143697
  this.colorIndex = 0;
143607
- this.version = "1.3.0-next.3";
143698
+ this.version = "1.3.0-next.4";
143608
143699
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
143609
143700
  this.superdocId = config2.superdocId || v4();
143610
143701
  this.colors = this.config.colors;