@harbour-enterprises/superdoc 0.25.0-next.4 → 0.25.0-next.5

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.
@@ -60282,7 +60282,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60282
60282
  isHeaderFooterChanged: false,
60283
60283
  isCustomXmlChanged: false,
60284
60284
  focusTarget: null,
60285
- permissionResolver: null
60285
+ permissionResolver: null,
60286
+ // header/footer editors may have parent(main) editor set
60287
+ parentEditor: null
60286
60288
  });
60287
60289
  __privateMethod$1(this, _Editor_instances, initContainerElement_fn).call(this, options);
60288
60290
  __privateMethod$1(this, _Editor_instances, checkHeadless_fn).call(this, options);
@@ -72490,58 +72492,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72490
72492
  }
72491
72493
  });
72492
72494
  };
72493
- const normalizeWrap = (attrs = {}) => {
72494
- const wrap2 = attrs.wrap;
72495
- if (wrap2?.type && wrap2.type !== "Inline") {
72496
- return {
72497
- type: wrap2.type,
72498
- attrs: wrap2.attrs ?? {}
72499
- };
72500
- }
72501
- if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
72502
- return {
72503
- type: "Inline",
72504
- attrs: wrap2.attrs
72505
- };
72506
- }
72507
- if (!wrap2 && attrs.wrapText) {
72508
- return {
72509
- type: "Square",
72510
- attrs: {
72511
- wrapText: attrs.wrapText
72512
- }
72513
- };
72514
- }
72515
- if (!wrap2 && attrs.wrapTopAndBottom) {
72516
- return {
72517
- type: "TopAndBottom",
72518
- attrs: {}
72519
- };
72520
- }
72521
- if (wrap2?.type === "Inline") {
72522
- return {
72523
- type: "Inline",
72524
- attrs: wrap2.attrs ?? {}
72525
- };
72526
- }
72527
- return {
72528
- type: "Inline",
72529
- attrs: {}
72530
- };
72531
- };
72532
- const normalizeMarginOffset = (marginOffset = {}) => {
72533
- const { left: left2, horizontal, ...rest } = marginOffset;
72534
- return {
72535
- ...rest,
72536
- horizontal: horizontal ?? left2
72537
- };
72538
- };
72539
- const getNormalizedImageAttrs = (attrs = {}) => {
72540
- return {
72541
- wrap: normalizeWrap(attrs),
72542
- marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
72543
- };
72544
- };
72545
72495
  const ImagePositionPluginKey = new PluginKey("ImagePosition");
72546
72496
  const ImagePositionPlugin = ({ editor }) => {
72547
72497
  const { view } = editor;
@@ -72554,8 +72504,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72554
72504
  return DecorationSet.empty;
72555
72505
  },
72556
72506
  apply(tr, oldDecorationSet, oldState, newState) {
72557
- if (!tr.docChanged) return oldDecorationSet;
72507
+ if (!tr.docChanged && !shouldUpdate) return oldDecorationSet;
72558
72508
  const decorations = getImagePositionDecorations(newState, view);
72509
+ shouldUpdate = false;
72559
72510
  return DecorationSet.create(newState.doc, decorations);
72560
72511
  }
72561
72512
  },
@@ -72564,7 +72515,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72564
72515
  update: (view2, lastState) => {
72565
72516
  const pagination = PaginationPluginKey.getState(lastState);
72566
72517
  if (shouldUpdate) {
72567
- shouldUpdate = false;
72568
72518
  const decorations = getImagePositionDecorations(lastState, view2);
72569
72519
  const updateTransaction = view2.state.tr.setMeta(ImagePositionPluginKey, { decorations });
72570
72520
  view2.dispatch(updateTransaction);
@@ -72590,41 +72540,35 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72590
72540
  let className = "";
72591
72541
  const { vRelativeFrom, alignH } = node.attrs.anchorData;
72592
72542
  const { size: size2, padding } = node.attrs;
72593
- const { marginOffset } = getNormalizedImageAttrs(node.attrs);
72594
72543
  const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
72595
- if (pageBreak) {
72596
- switch (alignH) {
72597
- case "left":
72598
- style2 += "float: left; left: 0; margin-left: 0; ";
72599
- break;
72600
- case "right":
72601
- style2 += "float: right; right: 0; margin-right: 0; ";
72602
- break;
72603
- case "center":
72604
- style2 += "display: block; margin-left: auto; margin-right: auto; ";
72605
- break;
72544
+ if (pageBreak && vRelativeFrom === "margin" && alignH) {
72545
+ const topPos = pageBreak?.offsetTop + pageBreak?.offsetHeight;
72546
+ let horizontalAlignment = `${alignH}: 0;`;
72547
+ if (alignH === "center") horizontalAlignment = "left: 50%; transform: translateX(-50%);";
72548
+ style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ${horizontalAlignment}` : "";
72549
+ const nextPos = view.posAtDOM(pageBreak, 1);
72550
+ if (nextPos < 0) {
72551
+ const $pos = view.state.doc.resolve(pos);
72552
+ decorations.push(
72553
+ Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
72554
+ style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
72555
+ })
72556
+ );
72606
72557
  }
72607
- const topPos = marginOffset.top !== void 0 ? marginOffset.top : pageBreak?.offsetTop + pageBreak?.offsetHeight;
72608
- style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ` : "";
72609
- if (vRelativeFrom === "margin") {
72610
- const nextPos = view.posAtDOM(pageBreak, 1);
72611
- if (nextPos < 0) {
72612
- const $pos = view.state.doc.resolve(pos);
72613
- decorations.push(
72614
- Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
72615
- style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
72616
- })
72617
- );
72618
- }
72619
- const imageBlock = document.createElement("div");
72620
- imageBlock.className = "anchor-image-placeholder";
72621
- imageBlock.style.float = alignH;
72622
- imageBlock.style.width = size2.width + parseInt(padding[alignH]) + "px";
72623
- imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
72624
- decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
72558
+ const imageBlock = document.createElement("div");
72559
+ imageBlock.className = "anchor-image-placeholder";
72560
+ imageBlock.style.float = alignH === "left" || alignH === "right" ? alignH : "none";
72561
+ let paddingHorizontal;
72562
+ if (alignH === "center") {
72563
+ paddingHorizontal = (parseInt(padding.left) || 0) + (parseInt(padding.right) || 0);
72564
+ } else {
72565
+ paddingHorizontal = parseInt(padding[alignH]) || 0;
72625
72566
  }
72567
+ imageBlock.style.width = size2.width + paddingHorizontal + "px";
72568
+ imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
72569
+ decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
72570
+ decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
72626
72571
  }
72627
- decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
72628
72572
  }
72629
72573
  });
72630
72574
  return decorations;
@@ -72649,6 +72593,58 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72649
72593
  }
72650
72594
  return null;
72651
72595
  };
72596
+ const normalizeWrap = (attrs = {}) => {
72597
+ const wrap2 = attrs.wrap;
72598
+ if (wrap2?.type && wrap2.type !== "Inline") {
72599
+ return {
72600
+ type: wrap2.type,
72601
+ attrs: wrap2.attrs ?? {}
72602
+ };
72603
+ }
72604
+ if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
72605
+ return {
72606
+ type: "Inline",
72607
+ attrs: wrap2.attrs
72608
+ };
72609
+ }
72610
+ if (!wrap2 && attrs.wrapText) {
72611
+ return {
72612
+ type: "Square",
72613
+ attrs: {
72614
+ wrapText: attrs.wrapText
72615
+ }
72616
+ };
72617
+ }
72618
+ if (!wrap2 && attrs.wrapTopAndBottom) {
72619
+ return {
72620
+ type: "TopAndBottom",
72621
+ attrs: {}
72622
+ };
72623
+ }
72624
+ if (wrap2?.type === "Inline") {
72625
+ return {
72626
+ type: "Inline",
72627
+ attrs: wrap2.attrs ?? {}
72628
+ };
72629
+ }
72630
+ return {
72631
+ type: "Inline",
72632
+ attrs: {}
72633
+ };
72634
+ };
72635
+ const normalizeMarginOffset = (marginOffset = {}) => {
72636
+ const { left: left2, horizontal, ...rest } = marginOffset;
72637
+ return {
72638
+ ...rest,
72639
+ horizontal: horizontal ?? left2
72640
+ };
72641
+ };
72642
+ const getNormalizedImageAttrs = (attrs = {}) => {
72643
+ return {
72644
+ wrap: normalizeWrap(attrs),
72645
+ marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
72646
+ };
72647
+ };
72652
72648
  const getRotationMargins = (w2, h2, angleDegrees) => {
72653
72649
  const rad = angleDegrees * (Math.PI / 180);
72654
72650
  const cos = Math.abs(Math.cos(rad));
@@ -72857,27 +72853,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72857
72853
  style2 += "float: right;";
72858
72854
  floatRight = true;
72859
72855
  } else if (["largest", "bothSides"].includes(attrs.wrapText)) {
72860
- const pageStyles2 = this.editor?.converter?.pageStyles;
72861
- if (pageStyles2?.pageSize && pageStyles2?.pageMargins && size2.width) {
72862
- const pageWidth = inchesToPixels(pageStyles2.pageSize.width);
72863
- const leftMargin = inchesToPixels(pageStyles2.pageMargins.left);
72864
- const rightMargin = inchesToPixels(pageStyles2.pageMargins.right);
72865
- const contentWidth = pageWidth - leftMargin - rightMargin;
72866
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
72867
- const leftSpace = marginOffset.horizontal;
72868
- const rightSpace = contentWidth - leftSpace - imageWidth;
72869
- if (rightSpace < 0) {
72870
- style2 += "float: left;";
72871
- } else if (rightSpace > leftSpace) {
72872
- style2 += "float: left;";
72873
- } else {
72874
- style2 += "float: right;";
72875
- floatRight = true;
72876
- baseHorizontal = rightSpace;
72877
- }
72878
- } else {
72879
- style2 += "float: left;";
72880
- }
72856
+ const pageStylesData2 = getDataFromPageStyles({
72857
+ editor: this.editor,
72858
+ marginOffset,
72859
+ size: size2,
72860
+ attrs
72861
+ });
72862
+ style2 += pageStylesData2.style;
72863
+ floatRight = pageStylesData2.floatRight;
72864
+ baseHorizontal = pageStylesData2.baseHorizontal;
72881
72865
  }
72882
72866
  if (attrs.distTop) margin.top += attrs.distTop;
72883
72867
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
@@ -72887,27 +72871,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72887
72871
  case "Through":
72888
72872
  case "Tight":
72889
72873
  style2 += "clear: both;";
72890
- const pageStyles = this.editor?.converter?.pageStyles;
72891
- if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
72892
- const pageWidth = inchesToPixels(pageStyles.pageSize.width);
72893
- const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
72894
- const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
72895
- const contentWidth = pageWidth - leftMargin - rightMargin;
72896
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
72897
- const leftSpace = marginOffset.horizontal;
72898
- const rightSpace = contentWidth - leftSpace - imageWidth;
72899
- if (rightSpace < 0) {
72900
- style2 += "float: left;";
72901
- } else if (rightSpace > leftSpace) {
72902
- style2 += "float: left;";
72903
- } else {
72904
- style2 += "float: right;";
72905
- floatRight = true;
72906
- baseHorizontal = rightSpace;
72907
- }
72908
- } else {
72909
- style2 += "float: left;";
72910
- }
72874
+ const pageStylesData = getDataFromPageStyles({
72875
+ editor: this.editor,
72876
+ marginOffset,
72877
+ size: size2,
72878
+ attrs
72879
+ });
72880
+ style2 += pageStylesData.style;
72881
+ floatRight = pageStylesData.floatRight;
72882
+ baseHorizontal = pageStylesData.baseHorizontal;
72911
72883
  if (attrs.distTop) margin.top += attrs.distTop;
72912
72884
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
72913
72885
  if (attrs.distLeft) margin.left += attrs.distLeft;
@@ -72944,6 +72916,22 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72944
72916
  }
72945
72917
  const hasAnchorData = Boolean(anchorData);
72946
72918
  const hasMarginOffsets = marginOffset?.horizontal != null || marginOffset?.top != null;
72919
+ if (hasAnchorData) {
72920
+ switch (anchorData.hRelativeFrom) {
72921
+ case "page":
72922
+ const pageStyles = this.editor?.converter?.pageStyles || this.editor?.options.parentEditor?.converter?.pageStyles;
72923
+ margin.left -= inchesToPixels(pageStyles?.pageMargins?.left) || 0;
72924
+ break;
72925
+ case "margin":
72926
+ if (anchorData.alignH === "center") {
72927
+ style2 += "position: absolute; left: 50%; transform: translateX(-50%);";
72928
+ }
72929
+ if (anchorData.alignH === "left" || anchorData.alignH === "right") {
72930
+ style2 += `position: absolute; ${anchorData.alignH}: 0;`;
72931
+ }
72932
+ break;
72933
+ }
72934
+ }
72947
72935
  if (hasAnchorData || hasMarginOffsets) {
72948
72936
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
72949
72937
  const maxMarginV = 500;
@@ -73092,6 +73080,37 @@ Please report this to https://github.com/markedjs/marked.`, e) {
73092
73080
  return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
73093
73081
  }
73094
73082
  });
73083
+ const getDataFromPageStyles = ({ editor, marginOffset, size: size2, attrs }) => {
73084
+ let style2 = "";
73085
+ let floatRight = false;
73086
+ let baseHorizontal = marginOffset?.horizontal || 0;
73087
+ const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
73088
+ if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
73089
+ const pageWidth = inchesToPixels(pageStyles.pageSize.width);
73090
+ const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
73091
+ const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
73092
+ const contentWidth = pageWidth - leftMargin - rightMargin;
73093
+ const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
73094
+ const leftSpace = marginOffset.horizontal;
73095
+ const rightSpace = contentWidth - leftSpace - imageWidth;
73096
+ if (rightSpace < 0) {
73097
+ style2 += "float: left;";
73098
+ } else if (rightSpace > leftSpace) {
73099
+ style2 += "float: left;";
73100
+ } else {
73101
+ style2 += "float: right;";
73102
+ floatRight = true;
73103
+ baseHorizontal = rightSpace;
73104
+ }
73105
+ } else {
73106
+ style2 += "float: left;";
73107
+ }
73108
+ return {
73109
+ style: style2,
73110
+ floatRight,
73111
+ baseHorizontal
73112
+ };
73113
+ };
73095
73114
  const ACCEPT_IMAGE_TYPES = [".jpg", ".jpeg", ".png", "image/jpeg", "image/png"];
73096
73115
  const getFileOpener = () => {
73097
73116
  let fileInput = document.createElement("input");
@@ -80534,7 +80553,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
80534
80553
  return oldState;
80535
80554
  }
80536
80555
  if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
80537
- if (editor.options.documentMode === "viewing" || !editor.isEditable) {
80556
+ if (!editor.options.isHeaderOrFooter && (editor.options.documentMode === "viewing" || !editor.isEditable)) {
80538
80557
  return DecorationSet.empty;
80539
80558
  }
80540
80559
  const { selection } = newState;