@harbour-enterprises/superdoc 1.3.0-next.11 → 1.3.0-next.13

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.11") {
36438
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.13") {
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.11";
62248
+ const summaryVersion = "1.3.0-next.13";
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.11");
64881
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.13");
64783
64882
  if (!this.options.ydoc) return;
64784
64883
  const metaMap = this.options.ydoc.getMap("meta");
64785
64884
  let docVersion = metaMap.get("version");
@@ -90098,7 +90197,16 @@ ${l}
90098
90197
  if (!value || typeof value !== "object") return;
90099
90198
  return normalizePxIndent(value) ?? convertIndentTwipsToPx(value);
90100
90199
  };
90101
- 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;
90102
90210
  const unwrapTabStops = (tabStops) => {
90103
90211
  if (!Array.isArray(tabStops)) {
90104
90212
  return void 0;
@@ -96354,7 +96462,11 @@ ${l}
96354
96462
  }
96355
96463
  async function measureImageBlock(block, constraints) {
96356
96464
  const intrinsic = getIntrinsicImageSize(block, constraints.maxWidth);
96357
- 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;
96358
96470
  const hasNegativeVerticalPosition = block.anchor?.isAnchored && (typeof block.anchor?.offsetV === "number" && block.anchor.offsetV < 0 || typeof block.margin?.top === "number" && block.margin.top < 0);
96359
96471
  const maxHeight = hasNegativeVerticalPosition || !constraints.maxHeight || constraints.maxHeight <= 0 ? Infinity : constraints.maxHeight;
96360
96472
  const widthScale = maxWidth / intrinsic.width;
@@ -101431,7 +101543,7 @@ ${l}
101431
101543
  const zoom = this.#layoutOptions.zoom ?? 1;
101432
101544
  const layoutMode = this.#layoutOptions.layoutMode ?? "vertical";
101433
101545
  const pages = this.#layoutState.layout?.pages;
101434
- const pageGap = this.#layoutState.layout?.pageGap ?? this.#getEffectivePageGap();
101546
+ const pageGap = this.#getEffectivePageGap();
101435
101547
  const defaultWidth = this.#layoutOptions.pageSize?.w ?? DEFAULT_PAGE_SIZE.w;
101436
101548
  const defaultHeight = this.#layoutOptions.pageSize?.h ?? DEFAULT_PAGE_SIZE.h;
101437
101549
  let maxWidth = defaultWidth;
@@ -104539,7 +104651,11 @@ ${l}
104539
104651
  */
104540
104652
  clearDocument: () => ({ commands: commands2 }) => {
104541
104653
  return commands2.setContent("<p></p>");
104542
- }
104654
+ },
104655
+ /**
104656
+ * Set section page margins (top/right/bottom/left) for the section at the current selection.
104657
+ */
104658
+ setSectionPageMarginsAtSelection
104543
104659
  };
104544
104660
  }
104545
104661
  });
@@ -111048,6 +111164,10 @@ ${l}
111048
111164
  }
111049
111165
  const hasAnchorData = Boolean(anchorData);
111050
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;");
111051
111171
  if (hasAnchorData) {
111052
111172
  switch (anchorData.hRelativeFrom) {
111053
111173
  case "page":
@@ -111075,7 +111195,6 @@ ${l}
111075
111195
  style2 += "float: left;";
111076
111196
  }
111077
111197
  } else if (!anchorData.alignH && marginOffset?.horizontal != null) {
111078
- const isAbsolutelyPositioned = style2.includes("position: absolute;");
111079
111198
  if (isAbsolutelyPositioned) {
111080
111199
  style2 += `left: ${baseHorizontal}px;`;
111081
111200
  style2 += "max-width: none;";
@@ -111089,7 +111208,8 @@ ${l}
111089
111208
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
111090
111209
  const relativeFromMarginV = anchorData?.vRelativeFrom === "margin";
111091
111210
  const maxMarginV = 500;
111092
- 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);
111093
111213
  let rotationHorizontal = 0;
111094
111214
  let rotationTop = 0;
111095
111215
  const { rotation: rotation2 } = transformData ?? {};
@@ -111108,7 +111228,10 @@ ${l}
111108
111228
  margin.left += horizontal;
111109
111229
  }
111110
111230
  }
111111
- if (top2 && !relativeFromMarginV) {
111231
+ const appliedTopViaStyle = isAbsolutelyPositioned && allowNegativeTopOffset && !relativeFromMarginV;
111232
+ if (appliedTopViaStyle) {
111233
+ style2 += `top: ${top2}px;`;
111234
+ } else if (top2 && !relativeFromMarginV) {
111112
111235
  if (relativeFromPageV && top2 >= maxMarginV) margin.top += maxMarginV;
111113
111236
  else margin.top += top2;
111114
111237
  }
@@ -111121,6 +111244,9 @@ ${l}
111121
111244
  }
111122
111245
  if (margin.top) style2 += `margin-top: ${margin.top}px;`;
111123
111246
  if (margin.bottom) style2 += `margin-bottom: ${margin.bottom}px;`;
111247
+ if (isBehindDocAnchor) {
111248
+ style2 += "max-width: none;";
111249
+ }
111124
111250
  const finalAttributes = { ...htmlAttributes };
111125
111251
  if (style2) {
111126
111252
  const existingStyle = finalAttributes.style || "";
@@ -139009,10 +139135,14 @@ ${style2}
139009
139135
  const handleMarginChange = ({ side, value }) => {
139010
139136
  const base2 = activeEditor.value;
139011
139137
  if (!base2) return;
139012
- const pageStyles2 = base2.getPageStyles();
139013
- const { pageMargins } = pageStyles2;
139014
- const update = { ...pageMargins, [side]: value };
139015
- 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
+ }
139016
139146
  };
139017
139147
  onBeforeUnmount(() => {
139018
139148
  stopPolling();
@@ -139148,7 +139278,7 @@ ${style2}
139148
139278
  };
139149
139279
  }
139150
139280
  });
139151
- 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"]]);
139152
139282
  const _hoisted_1$h = ["innerHTML"];
139153
139283
  const _sfc_main$i = {
139154
139284
  __name: "SuperInput",
@@ -143321,6 +143451,7 @@ ${reason}`);
143321
143451
  commentsStore.proxy = proxy;
143322
143452
  const { isHighContrastMode: isHighContrastMode2 } = useHighContrastMode();
143323
143453
  const { uiFontFamily } = useUiFontFamily();
143454
+ const isViewingMode = () => proxy?.$superdoc?.config?.documentMode === "viewing";
143324
143455
  const commentsModuleConfig = computed(() => {
143325
143456
  const config2 = modules.comments;
143326
143457
  if (config2 === false || config2 == null) return null;
@@ -143415,6 +143546,10 @@ ${reason}`);
143415
143546
  const commentsConfig = proxy.$superdoc.config.modules?.comments;
143416
143547
  if (!commentsConfig || commentsConfig === false) return;
143417
143548
  if (!positions || Object.keys(positions).length === 0) return;
143549
+ if (isViewingMode()) {
143550
+ commentsStore.clearEditorCommentPositions?.();
143551
+ return;
143552
+ }
143418
143553
  const mappedPositions = presentationEditor.getCommentBounds(positions, layers.value);
143419
143554
  handleEditorLocationsUpdate(mappedPositions);
143420
143555
  });
@@ -143434,6 +143569,13 @@ ${reason}`);
143434
143569
  const onEditorSelectionChange = ({ editor, transaction }) => {
143435
143570
  if (skipSelectionUpdate.value) {
143436
143571
  skipSelectionUpdate.value = false;
143572
+ if (isViewingMode()) {
143573
+ resetSelection();
143574
+ }
143575
+ return;
143576
+ }
143577
+ if (isViewingMode()) {
143578
+ resetSelection();
143437
143579
  return;
143438
143580
  }
143439
143581
  const { documentId } = editor.options;
@@ -143612,6 +143754,10 @@ ${reason}`);
143612
143754
  const onEditorCommentLocationsUpdate = (doc2, { allCommentIds: activeThreadId, allCommentPositions } = {}) => {
143613
143755
  const commentsConfig = proxy.$superdoc.config.modules?.comments;
143614
143756
  if (!commentsConfig || commentsConfig === false) return;
143757
+ if (isViewingMode()) {
143758
+ commentsStore.clearEditorCommentPositions?.();
143759
+ return;
143760
+ }
143615
143761
  const presentation = PresentationEditor.getInstance(doc2.id);
143616
143762
  if (!presentation) {
143617
143763
  handleEditorLocationsUpdate(allCommentPositions, activeThreadId);
@@ -143667,11 +143813,12 @@ ${reason}`);
143667
143813
  };
143668
143814
  const isCommentsEnabled = computed(() => Boolean(commentsModuleConfig.value));
143669
143815
  const showCommentsSidebar = computed(() => {
143816
+ if (isViewingMode()) return false;
143670
143817
  return pendingComment.value || getFloatingComments.value?.length > 0 && isReady.value && layers.value && isCommentsEnabled.value && !isCommentsListVisible.value;
143671
143818
  });
143672
143819
  const showToolsFloatingMenu = computed(() => {
143673
143820
  if (!isCommentsEnabled.value) return false;
143674
- return toolsMenuPosition.top && !getConfig2.value?.readOnly;
143821
+ return selectionPosition.value && toolsMenuPosition.top && !getConfig2.value?.readOnly;
143675
143822
  });
143676
143823
  computed(() => {
143677
143824
  if (!isCommentsEnabled.value) return false;
@@ -143719,6 +143866,10 @@ ${reason}`);
143719
143866
  return style2;
143720
143867
  });
143721
143868
  const handleSelectionChange = (selection) => {
143869
+ if (isViewingMode()) {
143870
+ resetSelection();
143871
+ return;
143872
+ }
143722
143873
  if (!selection.selectionBounds || !isCommentsEnabled.value) return;
143723
143874
  resetSelection();
143724
143875
  const isMobileView = window.matchMedia("(max-width: 768px)").matches;
@@ -143744,12 +143895,14 @@ ${reason}`);
143744
143895
  };
143745
143896
  const resetSelection = () => {
143746
143897
  selectionPosition.value = null;
143898
+ toolsMenuPosition.top = null;
143747
143899
  };
143748
143900
  const updateSelection2 = ({ startX, startY, x: x2, y: y2, source }) => {
143749
143901
  const hasStartCoords = typeof startX === "number" || typeof startY === "number";
143750
143902
  const hasEndCoords = typeof x2 === "number" || typeof y2 === "number";
143751
143903
  if (!hasStartCoords && !hasEndCoords) {
143752
- return selectionPosition.value = null;
143904
+ resetSelection();
143905
+ return;
143753
143906
  }
143754
143907
  if (!selectionPosition.value) {
143755
143908
  if (startY == null || startX == null) return;
@@ -144002,7 +144155,7 @@ ${reason}`);
144002
144155
  };
144003
144156
  }
144004
144157
  };
144005
- const App = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-1e96f708"]]);
144158
+ const App = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-5196811d"]]);
144006
144159
  const createSuperdocVueApp = () => {
144007
144160
  const app = createApp(App);
144008
144161
  const pinia = createPinia();
@@ -144186,7 +144339,7 @@ ${reason}`);
144186
144339
  this.config.colors = shuffleArray(this.config.colors);
144187
144340
  this.userColorMap = /* @__PURE__ */ new Map();
144188
144341
  this.colorIndex = 0;
144189
- this.version = "1.3.0-next.11";
144342
+ this.version = "1.3.0-next.13";
144190
144343
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
144191
144344
  this.superdocId = config2.superdocId || v4();
144192
144345
  this.colors = this.config.colors;