@harbour-enterprises/superdoc 0.12.36-next.6 → 0.12.36-next.8

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.
Files changed (31) hide show
  1. package/dist/chunks/{super-editor.es-H72UDWQx.cjs → super-editor.es-DO-kuhQq.cjs} +316 -32
  2. package/dist/chunks/{super-editor.es-C5YefmYN.es.js → super-editor.es-knUqfjv8.es.js} +316 -32
  3. package/dist/style.css +13 -0
  4. package/dist/super-editor/ai-writer.es.js +2 -2
  5. package/dist/super-editor/chunks/{converter-DY26Bu8a.js → converter-BCnMtqK6.js} +104 -7
  6. package/dist/super-editor/chunks/{docx-zipper-B4BvVBcx.js → docx-zipper-BEWaJso4.js} +1 -1
  7. package/dist/super-editor/chunks/{editor-w6HF4T0Y.js → editor-CTFQa4G4.js} +214 -27
  8. package/dist/super-editor/chunks/{toolbar-Ctfr_bH2.js → toolbar-CJt0mQxX.js} +2 -2
  9. package/dist/super-editor/converter.es.js +1 -1
  10. package/dist/super-editor/core/Attribute.d.ts +2 -2
  11. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  12. package/dist/super-editor/core/Schema.d.ts +2 -2
  13. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  14. package/dist/super-editor/core/super-converter/v2/importer/autoPageNumberImporter.d.ts.map +1 -1
  15. package/dist/super-editor/docx-zipper.es.js +2 -2
  16. package/dist/super-editor/editor.es.js +3 -3
  17. package/dist/super-editor/extensions/page-number/page-number.d.ts +10 -0
  18. package/dist/super-editor/extensions/page-number/page-number.d.ts.map +1 -1
  19. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +2 -1
  20. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  21. package/dist/super-editor/file-zipper.es.js +1 -1
  22. package/dist/super-editor/style.css +13 -0
  23. package/dist/super-editor/super-editor.es.js +6 -6
  24. package/dist/super-editor/toolbar.es.js +2 -2
  25. package/dist/super-editor.cjs +1 -1
  26. package/dist/super-editor.es.js +1 -1
  27. package/dist/superdoc.cjs +2 -2
  28. package/dist/superdoc.es.js +3 -3
  29. package/dist/superdoc.umd.js +317 -33
  30. package/dist/superdoc.umd.js.map +1 -1
  31. package/package.json +1 -1
@@ -18862,7 +18862,9 @@ function exportSchemaToJson(params2) {
18862
18862
  shapeContainer: translateShapeContainer,
18863
18863
  shapeTextbox: translateShapeTextbox,
18864
18864
  contentBlock: translateContentBlock,
18865
- structuredContent: translateStructuredContent
18865
+ structuredContent: translateStructuredContent,
18866
+ "page-number": translatePageNumberNode,
18867
+ "total-page-number": translateTotalPageNumberNode
18866
18868
  };
18867
18869
  if (!router[type2]) {
18868
18870
  console.error("No translation function found for node type:", type2);
@@ -20559,6 +20561,81 @@ function translateStructuredContent(params2) {
20559
20561
  elements: nodeElements
20560
20562
  };
20561
20563
  }
20564
+ const translatePageNumberNode = (params2) => {
20565
+ const outputMarks = processOutputMarks(params2.node.attrs?.marksAsAttrs || []);
20566
+ return getAutoPageJson("PAGE", outputMarks);
20567
+ };
20568
+ const translateTotalPageNumberNode = (params2) => {
20569
+ const outputMarks = processOutputMarks(params2.node.attrs?.marksAsAttrs || []);
20570
+ return getAutoPageJson("NUMPAGES", outputMarks);
20571
+ };
20572
+ const getAutoPageJson = (type2, outputMarks = []) => {
20573
+ return [
20574
+ {
20575
+ "name": "w:r",
20576
+ "elements": [
20577
+ {
20578
+ "name": "w:rPr",
20579
+ "elements": outputMarks
20580
+ },
20581
+ {
20582
+ "name": "w:fldChar",
20583
+ "attributes": {
20584
+ "w:fldCharType": "begin"
20585
+ }
20586
+ }
20587
+ ]
20588
+ },
20589
+ {
20590
+ "name": "w:r",
20591
+ "elements": [
20592
+ {
20593
+ "name": "w:rPr",
20594
+ "elements": outputMarks
20595
+ },
20596
+ {
20597
+ "name": "w:instrText",
20598
+ "elements": [
20599
+ {
20600
+ "type": "text",
20601
+ "text": ` ${type2}`
20602
+ }
20603
+ ]
20604
+ }
20605
+ ]
20606
+ },
20607
+ {
20608
+ "name": "w:r",
20609
+ "elements": [
20610
+ {
20611
+ "name": "w:rPr",
20612
+ "elements": outputMarks
20613
+ },
20614
+ {
20615
+ "name": "w:fldChar",
20616
+ "attributes": {
20617
+ "w:fldCharType": "separate"
20618
+ }
20619
+ }
20620
+ ]
20621
+ },
20622
+ {
20623
+ "name": "w:r",
20624
+ "elements": [
20625
+ {
20626
+ "name": "w:rPr",
20627
+ "elements": outputMarks
20628
+ },
20629
+ {
20630
+ "name": "w:fldChar",
20631
+ "attributes": {
20632
+ "w:fldCharType": "end"
20633
+ }
20634
+ }
20635
+ ]
20636
+ }
20637
+ ];
20638
+ };
20562
20639
  const defaultInitialXml = `<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:oel="http://schemas.microsoft.com/office/2019/extlst" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cex="http://schemas.microsoft.com/office/word/2018/wordml/cex" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16="http://schemas.microsoft.com/office/word/2018/wordml" xmlns:w16sdtdh="http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid w16 w16cex w16sdtdh wp14"><w:body></w:body></w:document>`;
20563
20640
  const parseXmlToJson = (xml) => {
20564
20641
  return JSON.parse(xmljs.xml2json(xml, null, 2));
@@ -22267,15 +22344,25 @@ const processCombinedNodesForFldChar = (nodesToCombine = []) => {
22267
22344
  if (!isNumPages) isNumPages = instrText?.trim().startsWith("NUMPAGES");
22268
22345
  const urlMatch = instrText?.match(/HYPERLINK\s+"([^"]+)"/);
22269
22346
  if (hasPageMarker) {
22270
- processedNodes.push({
22347
+ const pageNumNode = {
22271
22348
  name: "sd:autoPageNumber",
22272
22349
  type: "element"
22350
+ };
22351
+ nodesToCombine.forEach((n) => {
22352
+ const rPrNode = n.elements.find((el) => el.name === "w:rPr");
22353
+ if (rPrNode) pageNumNode.elements = [rPrNode];
22273
22354
  });
22355
+ processedNodes.push(pageNumNode);
22274
22356
  } else if (isNumPages) {
22275
- processedNodes.push({
22357
+ const totalPageNumNode = {
22276
22358
  name: "sd:totalPageNumber",
22277
22359
  type: "element"
22360
+ };
22361
+ nodesToCombine.forEach((n) => {
22362
+ const rPrNode = n.elements.find((el) => el.name === "w:rPr");
22363
+ if (rPrNode) totalPageNumNode.elements = [rPrNode];
22278
22364
  });
22365
+ processedNodes.push(totalPageNumNode);
22279
22366
  } else if (urlMatch && urlMatch?.length >= 2) {
22280
22367
  const url = urlMatch[1];
22281
22368
  const textMarks = [];
@@ -22611,8 +22698,13 @@ const handleAutoPageNumber = (params2) => {
22611
22698
  if (nodes.length === 0 || nodes[0].name !== "sd:autoPageNumber") {
22612
22699
  return { nodes: [], consumed: 0 };
22613
22700
  }
22701
+ const rPr = nodes[0].elements?.find((el) => el.name === "w:rPr");
22702
+ const marks = parseMarks(rPr || { elements: [] });
22614
22703
  const processedNode = {
22615
- type: "page-number"
22704
+ type: "page-number",
22705
+ attrs: {
22706
+ marksAsAttrs: marks
22707
+ }
22616
22708
  };
22617
22709
  return { nodes: [processedNode], consumed: 1 };
22618
22710
  };
@@ -22625,8 +22717,13 @@ const handleAutoTotalPageNumber = (params2) => {
22625
22717
  if (nodes.length === 0 || nodes[0].name !== "sd:totalPageNumber") {
22626
22718
  return { nodes: [], consumed: 0 };
22627
22719
  }
22720
+ const rPr = nodes[0].elements?.find((el) => el.name === "w:rPr");
22721
+ const marks = parseMarks(rPr || { elements: [] });
22628
22722
  const processedNode = {
22629
- type: "total-page-number"
22723
+ type: "total-page-number",
22724
+ attrs: {
22725
+ marksAsAttrs: marks
22726
+ }
22630
22727
  };
22631
22728
  return { nodes: [processedNode], consumed: 1 };
22632
22729
  };
@@ -23311,7 +23408,7 @@ const _SuperConverter = class _SuperConverter2 {
23311
23408
  return;
23312
23409
  }
23313
23410
  }
23314
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.36-next.6") {
23411
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.36-next.8") {
23315
23412
  const customLocation = "docProps/custom.xml";
23316
23413
  if (!docx[customLocation]) {
23317
23414
  docx[customLocation] = generateCustomXml();
@@ -23778,7 +23875,7 @@ function storeSuperdocVersion(docx) {
23778
23875
  function generateCustomXml() {
23779
23876
  return DEFAULT_CUSTOM_XML;
23780
23877
  }
23781
- function generateSuperdocVersion(pid = 2, version2 = "0.12.36-next.6") {
23878
+ function generateSuperdocVersion(pid = 2, version2 = "0.12.36-next.8") {
23782
23879
  return {
23783
23880
  type: "element",
23784
23881
  name: "property",
@@ -26311,7 +26408,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
26311
26408
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
26312
26409
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
26313
26410
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
26314
- var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn;
26411
+ var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
26315
26412
  function getMarksFromSelection(state2) {
26316
26413
  const { from: from2, to, empty: empty2 } = state2.selection;
26317
26414
  const marks = [];
@@ -39080,7 +39177,8 @@ const createHeaderFooterEditor = ({
39080
39177
  appendToBody = true,
39081
39178
  sectionId,
39082
39179
  type: type2,
39083
- availableHeight
39180
+ availableHeight,
39181
+ currentPageNumber
39084
39182
  }) => {
39085
39183
  const parentStyles = editor.converter.getDocumentDefaultStyles();
39086
39184
  const { fontSizePt, typeface } = parentStyles;
@@ -39121,6 +39219,8 @@ const createHeaderFooterEditor = ({
39121
39219
  fonts: editor.options.fonts,
39122
39220
  isHeaderOrFooter: true,
39123
39221
  annotations: true,
39222
+ currentPageNumber,
39223
+ parentEditor: editor,
39124
39224
  onCreate: (evt) => setEditorToolbar(evt, editor),
39125
39225
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type2)
39126
39226
  });
@@ -40264,9 +40364,9 @@ const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
40264
40364
  if (type2.name !== "paragraph" && type2.name !== "fieldAnnotation") return;
40265
40365
  child.children.forEach((inline) => {
40266
40366
  const isFieldToDelete = fieldsToDelete.includes(inline.attrs.fieldId);
40267
- const isMatchingField = inline.type.name === "fieldAnnotation" && isFieldToDelete;
40268
- const isEmpty2 = inline.childCount === 0;
40269
- if (!isEmpty2 && !isMatchingField) hasOtherNodes = true;
40367
+ const isFieldType = inline.type.name === "fieldAnnotation";
40368
+ const isMatchingField = isFieldType && isFieldToDelete;
40369
+ if (!isFieldType && !isMatchingField) hasOtherNodes = true;
40270
40370
  if (isMatchingField) matchingNodesFound += 1;
40271
40371
  });
40272
40372
  });
@@ -40711,6 +40811,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40711
40811
  __privateMethod$1(this, _Editor_instances, initMedia_fn).call(this);
40712
40812
  const doc2 = __privateMethod$1(this, _Editor_instances, generatePmData_fn).call(this);
40713
40813
  const tr = this.state.tr.replaceWith(0, this.state.doc.content.size, doc2);
40814
+ tr.setMeta("replaceContent", true);
40714
40815
  this.view.dispatch(tr);
40715
40816
  }
40716
40817
  /**
@@ -41118,7 +41219,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
41118
41219
  * @returns {Object | void} Migration results
41119
41220
  */
41120
41221
  processCollaborationMigrations() {
41121
- console.debug("[checkVersionMigrations] Current editor version", "0.12.36-next.6");
41222
+ console.debug("[checkVersionMigrations] Current editor version", "0.12.36-next.8");
41122
41223
  if (!this.options.ydoc) return;
41123
41224
  const metaMap = this.options.ydoc.getMap("meta");
41124
41225
  let docVersion = metaMap.get("version");
@@ -48766,32 +48867,89 @@ const PageNumber = Node$1.create({
48766
48867
  name: "page-number",
48767
48868
  group: "inline",
48768
48869
  inline: true,
48769
- content: "text*",
48870
+ atom: true,
48871
+ selectable: false,
48872
+ draggable: false,
48873
+ selectable: false,
48874
+ defining: true,
48875
+ content: "",
48770
48876
  addOptions() {
48771
48877
  return {
48772
48878
  htmlAttributes: {
48879
+ contenteditable: false,
48773
48880
  "data-id": "auto-page-number",
48774
48881
  "aria-label": "Page number node"
48775
48882
  }
48776
48883
  };
48777
48884
  },
48885
+ addAttributes() {
48886
+ return {
48887
+ marksAsAttrs: {
48888
+ default: null,
48889
+ rendered: false
48890
+ }
48891
+ };
48892
+ },
48893
+ addNodeView() {
48894
+ return ({ node: node2, editor, getPos, decorations }) => {
48895
+ const htmlAttributes = this.options.htmlAttributes;
48896
+ return new AutoPageNumberNodeView(node2, getPos, decorations, editor, htmlAttributes);
48897
+ };
48898
+ },
48778
48899
  parseDOM() {
48779
48900
  return [{ tag: 'span[data-id="auto-page-number"' }];
48780
48901
  },
48781
48902
  renderDOM({ htmlAttributes }) {
48782
- return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
48903
+ return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
48904
+ },
48905
+ addCommands() {
48906
+ return {
48907
+ addAutoPageNumber: () => ({ tr, dispatch, state: state2, editor }) => {
48908
+ const { options: options2 } = editor;
48909
+ if (!options2.isHeaderOrFooter) return false;
48910
+ const { schema } = state2;
48911
+ const pageNumberType = schema?.nodes?.["page-number"];
48912
+ if (!pageNumberType) return false;
48913
+ const pageNumberNodeJSON = { type: "page-number" };
48914
+ const pageNumberNode = schema.nodeFromJSON(pageNumberNodeJSON);
48915
+ if (dispatch) {
48916
+ tr.replaceSelectionWith(pageNumberNode, false);
48917
+ tr.setMeta("forceUpdatePagination", true);
48918
+ }
48919
+ return true;
48920
+ }
48921
+ };
48922
+ },
48923
+ addShortcuts() {
48924
+ return {
48925
+ "Mod-Shift-alt-p": () => this.editor.commands.addAutoPageNumber()
48926
+ };
48783
48927
  }
48784
48928
  });
48785
48929
  const TotalPageCount = Node$1.create({
48786
48930
  name: "total-page-number",
48787
48931
  group: "inline",
48788
48932
  inline: true,
48933
+ atom: true,
48934
+ selectable: false,
48935
+ draggable: false,
48936
+ selectable: false,
48789
48937
  content: "text*",
48790
48938
  addOptions() {
48791
48939
  return {
48792
48940
  htmlAttributes: {
48941
+ contenteditable: false,
48793
48942
  "data-id": "auto-total-pages",
48794
- "aria-label": "Total page count node"
48943
+ "aria-label": "Total page count node",
48944
+ "class": "sd-editor-auto-total-pages"
48945
+ }
48946
+ };
48947
+ },
48948
+ addAttributes() {
48949
+ return {
48950
+ marksAsAttrs: {
48951
+ default: null,
48952
+ rendered: false
48795
48953
  }
48796
48954
  };
48797
48955
  },
@@ -48800,8 +48958,139 @@ const TotalPageCount = Node$1.create({
48800
48958
  },
48801
48959
  renderDOM({ htmlAttributes }) {
48802
48960
  return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
48961
+ },
48962
+ addCommands() {
48963
+ return {
48964
+ addTotalPageCount: () => ({ tr, dispatch, state: state2, editor }) => {
48965
+ const { options: options2 } = editor;
48966
+ if (!options2.isHeaderOrFooter) return false;
48967
+ const { schema } = state2;
48968
+ const pageNumberType = schema.nodes?.["total-page-number"];
48969
+ if (!pageNumberType) return false;
48970
+ const currentPages = editor?.options?.parentEditor?.currentTotalPages || 1;
48971
+ const pageNumberNode = {
48972
+ type: "total-page-number",
48973
+ content: [{ type: "text", text: String(currentPages) }]
48974
+ };
48975
+ const pageNode = schema.nodeFromJSON(pageNumberNode);
48976
+ if (dispatch) {
48977
+ tr.replaceSelectionWith(pageNode, false);
48978
+ }
48979
+ return true;
48980
+ }
48981
+ };
48982
+ },
48983
+ addShortcuts() {
48984
+ return {
48985
+ "Mod-Shift-alt-c": () => this.editor.commands.addTotalPageCount()
48986
+ };
48803
48987
  }
48804
48988
  });
48989
+ class AutoPageNumberNodeView {
48990
+ constructor(node2, getPos, decorations, editor, htmlAttributes = {}) {
48991
+ __privateAdd$1(this, _AutoPageNumberNodeView_instances);
48992
+ this.node = node2;
48993
+ this.editor = editor;
48994
+ this.view = editor.view;
48995
+ this.getPos = getPos;
48996
+ this.editor = editor;
48997
+ this.dom = __privateMethod$1(this, _AutoPageNumberNodeView_instances, renderDom_fn).call(this, node2, htmlAttributes);
48998
+ }
48999
+ update(node2) {
49000
+ if (node2.type !== this.node.type) return false;
49001
+ this.node = node2;
49002
+ return true;
49003
+ }
49004
+ }
49005
+ _AutoPageNumberNodeView_instances = /* @__PURE__ */ new WeakSet();
49006
+ renderDom_fn = function(node2, htmlAttributes) {
49007
+ const pageText = this.editor.options.currentPageNumber || "1";
49008
+ const content = document.createTextNode(String(pageText));
49009
+ const nodeContent = document.createElement("span");
49010
+ nodeContent.className = "sd-editor-auto-page-number";
49011
+ nodeContent.setAttribute("data-id", "auto-page-number");
49012
+ nodeContent.setAttribute("aria-label", "Page number node");
49013
+ const currentPos = this.getPos();
49014
+ const { styles, marks } = getMarksFromNeighbors(currentPos, this.view);
49015
+ __privateMethod$1(this, _AutoPageNumberNodeView_instances, scheduleUpdateNodeStyle_fn).call(this, currentPos, marks);
49016
+ Object.assign(nodeContent.style, styles);
49017
+ nodeContent.appendChild(content);
49018
+ Object.entries(htmlAttributes).forEach(([key, value]) => {
49019
+ if (value) nodeContent.setAttribute(key, value);
49020
+ });
49021
+ return nodeContent;
49022
+ };
49023
+ scheduleUpdateNodeStyle_fn = function(pos, marks) {
49024
+ setTimeout(() => {
49025
+ const { state: state2 } = this.editor;
49026
+ const { dispatch } = this.view;
49027
+ const node2 = state2.doc.nodeAt(pos);
49028
+ if (!node2) return;
49029
+ const currentMarks = node2.attrs.marksAsAttrs || [];
49030
+ const newMarks = marks.map((m) => ({ type: m.type.name, attrs: m.attrs }));
49031
+ const isEqual = JSON.stringify(currentMarks) === JSON.stringify(newMarks);
49032
+ if (isEqual) return;
49033
+ const newAttrs = {
49034
+ ...node2.attrs,
49035
+ marksAsAttrs: newMarks
49036
+ };
49037
+ const tr = state2.tr.setNodeMarkup(pos, void 0, newAttrs);
49038
+ dispatch(tr);
49039
+ }, 0);
49040
+ };
49041
+ const getMarksFromNeighbors = (currentPos, view) => {
49042
+ const $pos = view.state.doc.resolve(currentPos);
49043
+ const styles = {};
49044
+ const marks = [];
49045
+ const before = $pos.nodeBefore;
49046
+ if (before) {
49047
+ Object.assign(styles, processMarks(before.marks));
49048
+ marks.push(...before.marks);
49049
+ }
49050
+ const after = $pos.nodeAfter;
49051
+ if (after) {
49052
+ Object.assign(styles, { ...styles, ...processMarks(after.marks) });
49053
+ marks.push(...after.marks);
49054
+ }
49055
+ return {
49056
+ styles,
49057
+ marks
49058
+ };
49059
+ };
49060
+ const processMarks = (marks) => {
49061
+ const styles = {};
49062
+ marks.forEach((mark) => {
49063
+ const { type: type2, attrs } = mark;
49064
+ switch (type2.name) {
49065
+ case "textStyle":
49066
+ if (attrs.fontFamily) styles["font-family"] = attrs.fontFamily;
49067
+ if (attrs.fontSize) styles["font-size"] = attrs.fontSize;
49068
+ if (attrs.color) styles["color"] = attrs.color;
49069
+ if (attrs.backgroundColor) styles["background-color"] = attrs.backgroundColor;
49070
+ break;
49071
+ case "bold":
49072
+ styles["font-weight"] = "bold";
49073
+ break;
49074
+ case "italic":
49075
+ styles["font-style"] = "italic";
49076
+ break;
49077
+ case "underline":
49078
+ styles["text-decoration"] = (styles["text-decoration"] || "") + " underline";
49079
+ break;
49080
+ case "strike":
49081
+ styles["text-decoration"] = (styles["text-decoration"] || "") + " line-through";
49082
+ break;
49083
+ default:
49084
+ if (attrs?.style) {
49085
+ Object.entries(attrs.style).forEach(([key, value]) => {
49086
+ styles[key] = value;
49087
+ });
49088
+ }
49089
+ break;
49090
+ }
49091
+ });
49092
+ return styles;
49093
+ };
48805
49094
  const ShapeContainer = Node$1.create({
48806
49095
  name: "shapeContainer",
48807
49096
  group: "block",
@@ -52839,16 +53128,15 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52839
53128
  const decorations = [];
52840
53129
  const { pageSize, pageMargins } = editor.converter.pageStyles;
52841
53130
  const pageHeight = pageSize.height * 96;
52842
- editor.options.scale;
52843
53131
  let currentPageNumber = 1;
52844
53132
  let pageHeightThreshold = pageHeight;
52845
53133
  let footer = null, header = null;
52846
53134
  const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52847
- const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor);
53135
+ const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber);
52848
53136
  const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
52849
53137
  decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
52850
53138
  const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
52851
- const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor);
53139
+ const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber);
52852
53140
  pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
52853
53141
  let coords = view?.coordsAtPos(doc2.content.size);
52854
53142
  if (!coords) return [];
@@ -52867,7 +53155,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52867
53155
  if (currentPageNumber === 1) {
52868
53156
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
52869
53157
  decorations.pop();
52870
- const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
53158
+ const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
52871
53159
  const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
52872
53160
  decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
52873
53161
  }
@@ -52896,7 +53184,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52896
53184
  const footerId2 = getHeaderFooterId(currentPageNumber, "footerIds", editor, currentNode);
52897
53185
  currentPageNumber++;
52898
53186
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52899
- header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
53187
+ header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber - 1);
52900
53188
  footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor, currentPageNumber - 1);
52901
53189
  const bufferHeight2 = pageHeightThreshold - actualBreakBottom;
52902
53190
  const { node: spacingNode2 } = createFinalPagePadding(bufferHeight2);
@@ -52911,7 +53199,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52911
53199
  const lastNodeCoords = view.coordsAtPos(finalPos);
52912
53200
  const headerId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52913
53201
  const footerId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
52914
- header = createHeader(pageMargins, pageSize, sectionData, headerId, editor);
53202
+ header = createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber);
52915
53203
  footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber);
52916
53204
  const bufferHeight = pageHeightThreshold - lastNodeCoords.bottom;
52917
53205
  const { node: spacingNode } = createFinalPagePadding(bufferHeight);
@@ -52928,6 +53216,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52928
53216
  totalPageNumber.innerText = currentPageNumber;
52929
53217
  }
52930
53218
  });
53219
+ editor.currentTotalPages = currentPageNumber;
52931
53220
  return decorations;
52932
53221
  }
52933
53222
  function createFinalPagePadding(bufferHeight) {
@@ -52938,7 +53227,7 @@ function createFinalPagePadding(bufferHeight) {
52938
53227
  div2.style.height = bufferHeight + "px";
52939
53228
  return { nodeHeight: bufferHeight, node: div2 };
52940
53229
  }
52941
- function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
53230
+ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
52942
53231
  const headerDef = sectionData.headers?.[headerId];
52943
53232
  const minHeaderHeight = pageMargins.top * 96;
52944
53233
  const headerMargin = pageMargins.header * 96;
@@ -52965,7 +53254,8 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
52965
53254
  appendToBody: false,
52966
53255
  sectionId: headerId,
52967
53256
  type: "header",
52968
- availableHeight
53257
+ availableHeight,
53258
+ currentPageNumber
52969
53259
  });
52970
53260
  editor.converter.headerEditors.push({
52971
53261
  id: headerId,
@@ -52991,13 +53281,6 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
52991
53281
  const minFooterHeight = pageMargins.bottom * 96;
52992
53282
  const footerPaddingFromEdge = pageMargins.footer * 96;
52993
53283
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
52994
- const sectionContainer = footerDef?.sectionContainer?.cloneNode(true);
52995
- const autoPageNumber = sectionContainer?.querySelector('span[data-id="auto-page-number"]');
52996
- if (autoPageNumber) {
52997
- const fontSize2 = autoPageNumber.previousElementSibling?.style?.fontSize || autoPageNumber.nextElementSibling?.style?.fontSize;
52998
- if (fontSize2) autoPageNumber.style.fontSize = fontSize2;
52999
- autoPageNumber.innerText = currentPageNumber;
53000
- }
53001
53284
  const editorContainer = document.createElement("div");
53002
53285
  if (!footerId && !editor.converter.footerIds["default"]) {
53003
53286
  footerId = "rId" + generateDocxRandomId();
@@ -53017,7 +53300,8 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
53017
53300
  appendToBody: false,
53018
53301
  sectionId: footerId,
53019
53302
  type: "footer",
53020
- availableHeight: footerHeight
53303
+ availableHeight: footerHeight,
53304
+ currentPageNumber
53021
53305
  });
53022
53306
  editor.converter.footerEditors.push({
53023
53307
  id: footerId,