@harbour-enterprises/superdoc 1.3.0-next.10 → 1.3.0-next.12

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.
@@ -36435,7 +36435,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
36435
36435
  static getStoredSuperdocVersion(docx) {
36436
36436
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
36437
36437
  }
36438
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.10") {
36438
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.12") {
36439
36439
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36440
36440
  }
36441
36441
  /**
@@ -47282,6 +47282,105 @@ Please report this to https://github.com/markedjs/marked.`, e) {
47282
47282
  tr.setNodeMarkup(pos, void 0, nextAttrs, node2.marks);
47283
47283
  return true;
47284
47284
  };
47285
+ function findGoverningSectPrParagraph(doc2, selectionPos) {
47286
+ const candidates = [];
47287
+ doc2.descendants((node2, nodePos) => {
47288
+ if (node2.type?.name === "paragraph" && node2.attrs?.paragraphProperties?.sectPr) {
47289
+ candidates.push({ node: node2, pos: nodePos });
47290
+ }
47291
+ });
47292
+ if (!candidates.length) return null;
47293
+ const inside = candidates.find((c2) => selectionPos >= c2.pos && selectionPos < c2.pos + c2.node.nodeSize);
47294
+ if (inside) return inside;
47295
+ const atOrAfter = candidates.find((c2) => c2.pos >= selectionPos);
47296
+ return atOrAfter ?? candidates[candidates.length - 1];
47297
+ }
47298
+ const setSectionPageMarginsAtSelection = ({ topInches, rightInches, bottomInches, leftInches } = {}) => ({ tr, state, editor }) => {
47299
+ if (!state || !editor) {
47300
+ console.warn("[setSectionPageMarginsAtSelection] Missing state or editor");
47301
+ return false;
47302
+ }
47303
+ const hasTop = typeof topInches === "number";
47304
+ const hasRight = typeof rightInches === "number";
47305
+ const hasBottom = typeof bottomInches === "number";
47306
+ const hasLeft = typeof leftInches === "number";
47307
+ if (!hasTop && !hasRight && !hasBottom && !hasLeft) {
47308
+ console.warn("[setSectionPageMarginsAtSelection] No margin values provided");
47309
+ return false;
47310
+ }
47311
+ if (hasTop && topInches < 0 || hasRight && rightInches < 0 || hasBottom && bottomInches < 0 || hasLeft && leftInches < 0) {
47312
+ console.warn("[setSectionPageMarginsAtSelection] Margin values must be >= 0");
47313
+ return false;
47314
+ }
47315
+ const updates = {};
47316
+ if (hasTop) updates.topInches = topInches;
47317
+ if (hasRight) updates.rightInches = rightInches;
47318
+ if (hasBottom) updates.bottomInches = bottomInches;
47319
+ if (hasLeft) updates.leftInches = leftInches;
47320
+ const { from: from2 } = state.selection;
47321
+ const governing = findGoverningSectPrParagraph(state.doc, from2);
47322
+ if (governing) {
47323
+ const { node: node2, pos } = governing;
47324
+ const paraProps = node2.attrs?.paragraphProperties || null;
47325
+ const existingSectPr = paraProps?.sectPr || null;
47326
+ if (!existingSectPr) {
47327
+ console.warn("[setSectionPageMarginsAtSelection] Paragraph found but has no sectPr");
47328
+ return false;
47329
+ }
47330
+ const sectPr2 = JSON.parse(JSON.stringify(existingSectPr));
47331
+ try {
47332
+ updateSectionMargins({ type: "sectPr", sectPr: sectPr2 }, updates);
47333
+ } catch (err) {
47334
+ console.error("[setSectionPageMarginsAtSelection] Failed to update sectPr:", err);
47335
+ return false;
47336
+ }
47337
+ const resolved = getSectPrMargins(sectPr2);
47338
+ const normalizedSectionMargins = {
47339
+ top: resolved.top ?? null,
47340
+ right: resolved.right ?? null,
47341
+ bottom: resolved.bottom ?? null,
47342
+ left: resolved.left ?? null,
47343
+ header: resolved.header ?? null,
47344
+ footer: resolved.footer ?? null
47345
+ };
47346
+ const newParagraphProperties = { ...paraProps || {}, sectPr: sectPr2 };
47347
+ const nextAttrs = {
47348
+ ...node2.attrs,
47349
+ paragraphProperties: newParagraphProperties,
47350
+ sectionMargins: normalizedSectionMargins
47351
+ };
47352
+ tr.setNodeMarkup(pos, void 0, nextAttrs, node2.marks);
47353
+ tr.setMeta("forceUpdatePagination", true);
47354
+ return true;
47355
+ }
47356
+ const docAttrs = state.doc.attrs ?? {};
47357
+ const converter = editor.converter ?? null;
47358
+ const baseBodySectPr = docAttrs.bodySectPr || converter?.bodySectPr || null;
47359
+ const sectPr = baseBodySectPr != null ? JSON.parse(JSON.stringify(baseBodySectPr)) : { type: "element", name: "w:sectPr", elements: [] };
47360
+ try {
47361
+ updateSectionMargins({ type: "sectPr", sectPr }, updates);
47362
+ } catch (err) {
47363
+ console.error("[setSectionPageMarginsAtSelection] Failed to update sectPr:", err);
47364
+ return false;
47365
+ }
47366
+ if (converter) {
47367
+ converter.bodySectPr = sectPr;
47368
+ if (!converter.pageStyles) converter.pageStyles = {};
47369
+ if (!converter.pageStyles.pageMargins) converter.pageStyles.pageMargins = {};
47370
+ const pageMargins = converter.pageStyles.pageMargins;
47371
+ const resolved = getSectPrMargins(sectPr);
47372
+ if (resolved.top != null) pageMargins.top = resolved.top;
47373
+ if (resolved.right != null) pageMargins.right = resolved.right;
47374
+ if (resolved.bottom != null) pageMargins.bottom = resolved.bottom;
47375
+ if (resolved.left != null) pageMargins.left = resolved.left;
47376
+ if (resolved.header != null) pageMargins.header = resolved.header;
47377
+ if (resolved.footer != null) pageMargins.footer = resolved.footer;
47378
+ }
47379
+ const nextDocAttrs = { ...docAttrs, bodySectPr: sectPr };
47380
+ tr.setNodeMarkup(0, void 0, nextDocAttrs);
47381
+ tr.setMeta("forceUpdatePagination", true);
47382
+ return true;
47383
+ };
47285
47384
  const insertSectionBreakAtSelection = ({ headerInches, footerInches } = {}) => ({ tr, state, editor }) => {
47286
47385
  if (!state || !editor) {
47287
47386
  console.warn("[insertSectionBreakAtSelection] Missing state or editor");
@@ -47813,6 +47912,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
47813
47912
  setMeta,
47814
47913
  setNode,
47815
47914
  setSectionHeaderFooterAtSelection,
47915
+ setSectionPageMarginsAtSelection,
47816
47916
  setTextIndentation,
47817
47917
  setTextSelection,
47818
47918
  skipTab,
@@ -62145,7 +62245,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
62145
62245
  return false;
62146
62246
  }
62147
62247
  };
62148
- const summaryVersion = "1.3.0-next.10";
62248
+ const summaryVersion = "1.3.0-next.12";
62149
62249
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
62150
62250
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
62151
62251
  function mapAttributes(attrs) {
@@ -64148,9 +64248,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64148
64248
  try {
64149
64249
  const jsonObj = json;
64150
64250
  const attrs = jsonObj.attrs;
64151
- const hasBody = attrs && "bodySectPr" in attrs;
64152
64251
  const converter = this.converter;
64153
- if (!hasBody && converter && converter.bodySectPr) {
64252
+ if (converter && converter.bodySectPr) {
64154
64253
  jsonObj.attrs = attrs || {};
64155
64254
  jsonObj.attrs.bodySectPr = converter.bodySectPr;
64156
64255
  }
@@ -64779,7 +64878,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64779
64878
  * Process collaboration migrations
64780
64879
  */
64781
64880
  processCollaborationMigrations() {
64782
- console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.10");
64881
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.12");
64783
64882
  if (!this.options.ydoc) return;
64784
64883
  const metaMap = this.options.ydoc.getMap("meta");
64785
64884
  let docVersion = metaMap.get("version");
@@ -87066,6 +87165,13 @@ ${l}
87066
87165
  );
87067
87166
  }
87068
87167
  });
87168
+ if ((config2.mode === "original" || config2.mode === "final") && config2.enabled) {
87169
+ filtered.forEach((run2) => {
87170
+ if (isTextRun$1(run2) && run2.trackedChange && (run2.trackedChange.kind === "insert" || run2.trackedChange.kind === "delete")) {
87171
+ delete run2.trackedChange;
87172
+ }
87173
+ });
87174
+ }
87069
87175
  }
87070
87176
  return filtered;
87071
87177
  };
@@ -90091,7 +90197,16 @@ ${l}
90091
90197
  if (!value || typeof value !== "object") return;
90092
90198
  return normalizePxIndent(value) ?? convertIndentTwipsToPx(value);
90093
90199
  };
90094
- const normalizedIndent = normalizeIndentObject(attrs.indent) ?? convertIndentTwipsToPx(paragraphProps.indent) ?? convertIndentTwipsToPx(hydrated?.indent) ?? normalizeParagraphIndent(attrs.textIndent);
90200
+ const hydratedIndentPx = convertIndentTwipsToPx(hydrated?.indent);
90201
+ const paragraphIndentPx = convertIndentTwipsToPx(paragraphProps.indent);
90202
+ const textIndentPx = normalizeParagraphIndent(attrs.textIndent);
90203
+ const attrsIndentPx = normalizeIndentObject(attrs.indent);
90204
+ const indentChain = [];
90205
+ if (hydratedIndentPx) indentChain.push({ indent: hydratedIndentPx });
90206
+ if (paragraphIndentPx) indentChain.push({ indent: paragraphIndentPx });
90207
+ if (textIndentPx) indentChain.push({ indent: textIndentPx });
90208
+ if (attrsIndentPx) indentChain.push({ indent: attrsIndentPx });
90209
+ const normalizedIndent = indentChain.length ? combineIndentProperties(indentChain).indent : void 0;
90095
90210
  const unwrapTabStops = (tabStops) => {
90096
90211
  if (!Array.isArray(tabStops)) {
90097
90212
  return void 0;
@@ -96347,7 +96462,11 @@ ${l}
96347
96462
  }
96348
96463
  async function measureImageBlock(block, constraints) {
96349
96464
  const intrinsic = getIntrinsicImageSize(block, constraints.maxWidth);
96350
- const maxWidth = constraints.maxWidth > 0 ? constraints.maxWidth : intrinsic.width;
96465
+ const isBlockBehindDoc = block.anchor?.behindDoc;
96466
+ const isBlockWrapBehindDoc = block.wrap?.type === "None" && block.wrap?.behindDoc;
96467
+ const bypassWidthConstraint = isBlockBehindDoc || isBlockWrapBehindDoc;
96468
+ const isWidthConstraintBypassed = bypassWidthConstraint || constraints.maxWidth <= 0;
96469
+ const maxWidth = isWidthConstraintBypassed ? intrinsic.width : constraints.maxWidth;
96351
96470
  const hasNegativeVerticalPosition = block.anchor?.isAnchored && (typeof block.anchor?.offsetV === "number" && block.anchor.offsetV < 0 || typeof block.margin?.top === "number" && block.margin.top < 0);
96352
96471
  const maxHeight = hasNegativeVerticalPosition || !constraints.maxHeight || constraints.maxHeight <= 0 ? Infinity : constraints.maxHeight;
96353
96472
  const widthScale = maxWidth / intrinsic.width;
@@ -97514,9 +97633,10 @@ ${l}
97514
97633
  throw new TypeError("[PresentationEditor] setTrackedChangesOverrides expects an object or undefined");
97515
97634
  }
97516
97635
  if (overrides !== void 0) {
97517
- if (overrides.mode !== void 0 && !["review", "simple", "original"].includes(overrides.mode)) {
97636
+ const validModes = ["review", "original", "final", "off"];
97637
+ if (overrides.mode !== void 0 && !validModes.includes(overrides.mode)) {
97518
97638
  throw new TypeError(
97519
- `[PresentationEditor] Invalid tracked changes mode "${overrides.mode}". Must be one of: review, simple, original`
97639
+ `[PresentationEditor] Invalid tracked changes mode "${overrides.mode}". Must be one of: ${validModes.join(", ")}`
97520
97640
  );
97521
97641
  }
97522
97642
  if (overrides.enabled !== void 0 && typeof overrides.enabled !== "boolean") {
@@ -104531,7 +104651,11 @@ ${l}
104531
104651
  */
104532
104652
  clearDocument: () => ({ commands: commands2 }) => {
104533
104653
  return commands2.setContent("<p></p>");
104534
- }
104654
+ },
104655
+ /**
104656
+ * Set section page margins (top/right/bottom/left) for the section at the current selection.
104657
+ */
104658
+ setSectionPageMarginsAtSelection
104535
104659
  };
104536
104660
  }
104537
104661
  });
@@ -111040,6 +111164,10 @@ ${l}
111040
111164
  }
111041
111165
  const hasAnchorData = Boolean(anchorData);
111042
111166
  const hasMarginOffsets = marginOffset?.horizontal != null || marginOffset?.top != null;
111167
+ const isWrapBehindDoc = wrap2?.attrs?.behindDoc;
111168
+ const isAnchorBehindDoc = anchorData?.behindDoc;
111169
+ const isBehindDocAnchor = wrap2?.type === "None" && (isWrapBehindDoc || isAnchorBehindDoc);
111170
+ const isAbsolutelyPositioned = style2.includes("position: absolute;");
111043
111171
  if (hasAnchorData) {
111044
111172
  switch (anchorData.hRelativeFrom) {
111045
111173
  case "page":
@@ -111067,7 +111195,6 @@ ${l}
111067
111195
  style2 += "float: left;";
111068
111196
  }
111069
111197
  } else if (!anchorData.alignH && marginOffset?.horizontal != null) {
111070
- const isAbsolutelyPositioned = style2.includes("position: absolute;");
111071
111198
  if (isAbsolutelyPositioned) {
111072
111199
  style2 += `left: ${baseHorizontal}px;`;
111073
111200
  style2 += "max-width: none;";
@@ -111081,7 +111208,8 @@ ${l}
111081
111208
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
111082
111209
  const relativeFromMarginV = anchorData?.vRelativeFrom === "margin";
111083
111210
  const maxMarginV = 500;
111084
- const baseTop = Math.max(0, marginOffset?.top ?? 0);
111211
+ const allowNegativeTopOffset = isBehindDocAnchor;
111212
+ const baseTop = allowNegativeTopOffset ? marginOffset?.top ?? 0 : Math.max(0, marginOffset?.top ?? 0);
111085
111213
  let rotationHorizontal = 0;
111086
111214
  let rotationTop = 0;
111087
111215
  const { rotation: rotation2 } = transformData ?? {};
@@ -111100,7 +111228,10 @@ ${l}
111100
111228
  margin.left += horizontal;
111101
111229
  }
111102
111230
  }
111103
- if (top2 && !relativeFromMarginV) {
111231
+ const appliedTopViaStyle = isAbsolutelyPositioned && allowNegativeTopOffset && !relativeFromMarginV;
111232
+ if (appliedTopViaStyle) {
111233
+ style2 += `top: ${top2}px;`;
111234
+ } else if (top2 && !relativeFromMarginV) {
111104
111235
  if (relativeFromPageV && top2 >= maxMarginV) margin.top += maxMarginV;
111105
111236
  else margin.top += top2;
111106
111237
  }
@@ -111113,6 +111244,9 @@ ${l}
111113
111244
  }
111114
111245
  if (margin.top) style2 += `margin-top: ${margin.top}px;`;
111115
111246
  if (margin.bottom) style2 += `margin-bottom: ${margin.bottom}px;`;
111247
+ if (isBehindDocAnchor) {
111248
+ style2 += "max-width: none;";
111249
+ }
111116
111250
  const finalAttributes = { ...htmlAttributes };
111117
111251
  if (style2) {
111118
111252
  const existingStyle = finalAttributes.style || "";
@@ -139001,10 +139135,14 @@ ${style2}
139001
139135
  const handleMarginChange = ({ side, value }) => {
139002
139136
  const base2 = activeEditor.value;
139003
139137
  if (!base2) return;
139004
- const pageStyles2 = base2.getPageStyles();
139005
- const { pageMargins } = pageStyles2;
139006
- const update = { ...pageMargins, [side]: value };
139007
- base2?.updatePageStyle({ pageMargins: update });
139138
+ const payload = side === "left" ? { leftInches: value } : side === "right" ? { rightInches: value } : side === "top" ? { topInches: value } : side === "bottom" ? { bottomInches: value } : {};
139139
+ const didUpdateSection = typeof base2.commands?.setSectionPageMarginsAtSelection === "function" ? base2.commands.setSectionPageMarginsAtSelection(payload) : false;
139140
+ if (!didUpdateSection) {
139141
+ const pageStyles2 = base2.getPageStyles();
139142
+ const { pageMargins } = pageStyles2;
139143
+ const update = { ...pageMargins, [side]: value };
139144
+ base2?.updatePageStyle({ pageMargins: update });
139145
+ }
139008
139146
  };
139009
139147
  onBeforeUnmount(() => {
139010
139148
  stopPolling();
@@ -139140,7 +139278,7 @@ ${style2}
139140
139278
  };
139141
139279
  }
139142
139280
  });
139143
- const SuperEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["__scopeId", "data-v-8dd4cf59"]]);
139281
+ const SuperEditor = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["__scopeId", "data-v-3e9da07c"]]);
139144
139282
  const _hoisted_1$h = ["innerHTML"];
139145
139283
  const _sfc_main$i = {
139146
139284
  __name: "SuperInput",
@@ -144178,7 +144316,7 @@ ${reason}`);
144178
144316
  this.config.colors = shuffleArray(this.config.colors);
144179
144317
  this.userColorMap = /* @__PURE__ */ new Map();
144180
144318
  this.colorIndex = 0;
144181
- this.version = "1.3.0-next.10";
144319
+ this.version = "1.3.0-next.12";
144182
144320
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
144183
144321
  this.superdocId = config2.superdocId || v4();
144184
144322
  this.colors = this.config.colors;