@harbour-enterprises/superdoc 0.12.14 → 0.12.16

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 (27) hide show
  1. package/dist/chunks/{super-editor.es-BOH6x5Dh.es.js → super-editor.es-BB3W_xzz.es.js} +144 -54
  2. package/dist/chunks/{super-editor.es-DF_gWgh-.cjs → super-editor.es-C1sOUR_S.cjs} +144 -54
  3. package/dist/super-editor/ai-writer.es.js +2 -2
  4. package/dist/super-editor/chunks/{converter-D3CdG5M7.js → converter-CaX3dOo9.js} +78 -12
  5. package/dist/super-editor/chunks/{docx-zipper-DBFk7dLq.js → docx-zipper-C21KiTVk.js} +10 -1
  6. package/dist/super-editor/chunks/{editor-CdSN8S-8.js → editor-Ctzz2gCC.js} +59 -44
  7. package/dist/super-editor/chunks/{toolbar-C2Qr2ADq.js → toolbar-C0EZHJoI.js} +2 -2
  8. package/dist/super-editor/converter.es.js +1 -1
  9. package/dist/super-editor/core/DocxZipper.d.ts.map +1 -1
  10. package/dist/super-editor/core/super-converter/SuperConverter.d.ts.map +1 -1
  11. package/dist/super-editor/core/super-converter/constants.d.ts +2 -0
  12. package/dist/super-editor/core/super-converter/constants.d.ts.map +1 -1
  13. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  14. package/dist/super-editor/docx-zipper.es.js +2 -2
  15. package/dist/super-editor/editor.es.js +3 -3
  16. package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
  17. package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/super-editor.es.js +6 -6
  20. package/dist/super-editor/toolbar.es.js +2 -2
  21. package/dist/super-editor.cjs +1 -1
  22. package/dist/super-editor.es.js +1 -1
  23. package/dist/superdoc.cjs +2 -2
  24. package/dist/superdoc.es.js +3 -3
  25. package/dist/superdoc.umd.js +145 -55
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -18855,8 +18855,20 @@ function exportSchemaToJson(params2) {
18855
18855
  return router[type2](params2);
18856
18856
  }
18857
18857
  function translateBodyNode(params2) {
18858
- const sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
18858
+ let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
18859
18859
  if (params2.converter) {
18860
+ const hasHeader = sectPr.elements.some((n) => n.name === "w:headerReference");
18861
+ const hasDefaultHeader = params2.converter.headerIds?.default;
18862
+ if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
18863
+ const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
18864
+ sectPr.elements.push(defaultHeader);
18865
+ }
18866
+ const hasFooter = sectPr.elements.some((n) => n.name === "w:footerReference");
18867
+ const hasDefaultFooter = params2.converter.footerIds?.default;
18868
+ if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
18869
+ const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
18870
+ sectPr.elements.push(defaultFooter);
18871
+ }
18860
18872
  const newMargins = params2.converter.pageStyles.pageMargins;
18861
18873
  const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
18862
18874
  const { attributes } = sectPrMargins;
@@ -18878,6 +18890,16 @@ function translateBodyNode(params2) {
18878
18890
  elements: [...elements, sectPr]
18879
18891
  };
18880
18892
  }
18893
+ const generateDefaultHeaderFooter = (type2, id) => {
18894
+ return {
18895
+ "type": "element",
18896
+ "name": `w:${type2}Reference`,
18897
+ "attributes": {
18898
+ "w:type": "default",
18899
+ "r:id": id
18900
+ }
18901
+ };
18902
+ };
18881
18903
  function translateParagraphNode(params2) {
18882
18904
  const elements = translateChildNodes(params2);
18883
18905
  const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
@@ -23176,6 +23198,7 @@ const isAlternatingHeadersOddEven = (docx) => {
23176
23198
  return !!evenOdd;
23177
23199
  };
23178
23200
  const HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
23201
+ const HEADER_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
23179
23202
  const _SuperConverter = class _SuperConverter2 {
23180
23203
  constructor(params2 = null) {
23181
23204
  __privateAdd$2(this, _SuperConverter_instances);
@@ -23246,7 +23269,7 @@ const _SuperConverter = class _SuperConverter2 {
23246
23269
  return;
23247
23270
  }
23248
23271
  }
23249
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.14") {
23272
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.16") {
23250
23273
  const customLocation = "docProps/custom.xml";
23251
23274
  if (!docx[customLocation]) {
23252
23275
  docx[customLocation] = generateCustomXml();
@@ -23434,8 +23457,8 @@ const _SuperConverter = class _SuperConverter2 {
23434
23457
  commentsRels = relationships;
23435
23458
  }
23436
23459
  this.convertedXml = { ...this.convertedXml, ...updatedXml };
23437
- __privateMethod$2(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params2.relationships, ...commentsRels]);
23438
- __privateMethod$2(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
23460
+ const headFootRels = __privateMethod$2(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
23461
+ __privateMethod$2(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params2.relationships, ...commentsRels, ...headFootRels]);
23439
23462
  storeSuperdocVersion(this.convertedXml);
23440
23463
  __privateMethod$2(this, _SuperConverter_instances, exportNumberingFile_fn).call(this, params2);
23441
23464
  return xml;
@@ -23495,8 +23518,9 @@ prepareCommentsXmlFilesForExport_fn = function({ defs, exportType, commentsWithP
23495
23518
  exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23496
23519
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
23497
23520
  const relationships = relsData.elements.find((x) => x.name === "Relationships");
23498
- Object.entries(this.headers).forEach(([id, header]) => {
23499
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
23521
+ const newDocRels = [];
23522
+ Object.entries(this.headers).forEach(([id, header], index2) => {
23523
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `header${index2 + 1}.xml`;
23500
23524
  const headerEditor = this.headerEditors.find((item) => item.id === id);
23501
23525
  if (!headerEditor) return;
23502
23526
  const { result, params: params2 } = this.exportToXmlJson({
@@ -23510,7 +23534,27 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23510
23534
  });
23511
23535
  const bodyContent = result.elements[0].elements;
23512
23536
  const file = this.convertedXml[`word/${fileName}`];
23513
- file.elements[0].elements = bodyContent;
23537
+ if (!file) {
23538
+ this.convertedXml[`word/${fileName}`] = {
23539
+ declaration: this.initialJSON?.declaration,
23540
+ elements: [{
23541
+ attributes: DEFAULT_DOCX_DEFS,
23542
+ name: "w:hdr",
23543
+ type: "element",
23544
+ elements: []
23545
+ }]
23546
+ };
23547
+ newDocRels.push({
23548
+ type: "element",
23549
+ name: "Relationship",
23550
+ attributes: {
23551
+ Id: id,
23552
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
23553
+ Target: fileName
23554
+ }
23555
+ });
23556
+ }
23557
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
23514
23558
  if (params2.relationships.length) {
23515
23559
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
23516
23560
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -23528,8 +23572,8 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23528
23572
  };
23529
23573
  }
23530
23574
  });
23531
- Object.entries(this.footers).forEach(([id, footer]) => {
23532
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
23575
+ Object.entries(this.footers).forEach(([id, footer], index2) => {
23576
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `footer${index2 + 1}.xml`;
23533
23577
  const footerEditor = this.footerEditors.find((item) => item.id === id);
23534
23578
  if (!footerEditor) return;
23535
23579
  const { result, params: params2 } = this.exportToXmlJson({
@@ -23543,7 +23587,27 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23543
23587
  });
23544
23588
  const bodyContent = result.elements[0].elements;
23545
23589
  const file = this.convertedXml[`word/${fileName}`];
23546
- file.elements[0].elements = bodyContent;
23590
+ if (!file) {
23591
+ this.convertedXml[`word/${fileName}`] = {
23592
+ declaration: this.initialJSON?.declaration,
23593
+ elements: [{
23594
+ attributes: DEFAULT_DOCX_DEFS,
23595
+ name: "w:ftr",
23596
+ type: "element",
23597
+ elements: []
23598
+ }]
23599
+ };
23600
+ newDocRels.push({
23601
+ type: "element",
23602
+ name: "Relationship",
23603
+ attributes: {
23604
+ Id: id,
23605
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
23606
+ Target: fileName
23607
+ }
23608
+ });
23609
+ }
23610
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
23547
23611
  if (params2.relationships.length) {
23548
23612
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
23549
23613
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -23561,6 +23625,7 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23561
23625
  };
23562
23626
  }
23563
23627
  });
23628
+ return newDocRels;
23564
23629
  };
23565
23630
  exportProcessNewRelationships_fn = function(rels = []) {
23566
23631
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
@@ -23573,7 +23638,8 @@ exportProcessNewRelationships_fn = function(rels = []) {
23573
23638
  const existingTarget = relationships.elements.find((el) => el.attributes.Target === rel.attributes.Target);
23574
23639
  const isNewMedia = rel.attributes.Target?.startsWith("media/") && existingId.length > 6;
23575
23640
  const isNewHyperlink = rel.attributes.Type === HYPERLINK_RELATIONSHIP_TYPE && existingId.length > 6;
23576
- if (existingTarget && !isNewMedia && !isNewHyperlink) {
23641
+ const isNewHeadFoot = rel.attributes.Type === HEADER_RELATIONSHIP_TYPE && existingId.length > 6;
23642
+ if (existingTarget && !isNewMedia && !isNewHyperlink && !isNewHeadFoot) {
23577
23643
  return;
23578
23644
  }
23579
23645
  rel.attributes.Target = rel.attributes?.Target?.replace(/&/g, "&");
@@ -23669,7 +23735,7 @@ function storeSuperdocVersion(docx) {
23669
23735
  function generateCustomXml() {
23670
23736
  return DEFAULT_CUSTOM_XML;
23671
23737
  }
23672
- function generateSuperdocVersion(pid = 2, version2 = "0.12.14") {
23738
+ function generateSuperdocVersion(pid = 2, version2 = "0.12.16") {
23673
23739
  return {
23674
23740
  type: "element",
23675
23741
  name: "property",
@@ -26107,6 +26173,15 @@ class DocxZipper {
26107
26173
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
26108
26174
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
26109
26175
  }
26176
+ Object.keys(docx.files).forEach((name) => {
26177
+ if (!name.includes("header") && !name.includes("footer")) return;
26178
+ const hasExtensible = types2.elements?.some((el) => el.name === "Override" && el.attributes.PartName === `/${name}`);
26179
+ const type2 = name.includes("header") ? "header" : "footer";
26180
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type2}+xml"/>`;
26181
+ if (!hasExtensible) {
26182
+ typesString += extendedDef;
26183
+ }
26184
+ });
26110
26185
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
26111
26186
  const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
26112
26187
  docx.file(contentTypesPath, updatedContentTypesXml);
@@ -38966,7 +39041,6 @@ const createHeaderFooterEditor = ({
38966
39041
  const pm = editorContainer.querySelector(".ProseMirror");
38967
39042
  pm.style.maxHeight = "100%";
38968
39043
  pm.style.minHeight = "100%";
38969
- pm.style.overflow = "auto";
38970
39044
  pm.style.outline = "none";
38971
39045
  pm.style.border = "none";
38972
39046
  return headerFooterEditor;
@@ -39031,8 +39105,9 @@ const updateYdocDocxData = async (editor) => {
39031
39105
  Object.keys(newXml).forEach((key) => {
39032
39106
  if (key.includes("header") || key.includes("footer")) {
39033
39107
  const fileIndex = docx.findIndex((item) => item.name === key);
39034
- if (fileIndex === -1) return;
39035
- docx.splice(fileIndex, 1);
39108
+ if (fileIndex > -1) {
39109
+ docx.splice(fileIndex, 1);
39110
+ }
39036
39111
  docx.push({
39037
39112
  name: key,
39038
39113
  content: newXml[key]
@@ -40814,7 +40889,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40814
40889
  * @returns {Object | void} Migration results
40815
40890
  */
40816
40891
  processCollaborationMigrations() {
40817
- console.debug("[checkVersionMigrations] Current editor version", "0.12.14");
40892
+ console.debug("[checkVersionMigrations] Current editor version", "0.12.16");
40818
40893
  if (!this.options.ydoc) return;
40819
40894
  const metaMap = this.options.ydoc.getMap("meta");
40820
40895
  let docVersion = metaMap.get("version");
@@ -52529,7 +52604,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52529
52604
  currentPageNumber++;
52530
52605
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52531
52606
  header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
52532
- footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor);
52607
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor, currentPageNumber - 1);
52533
52608
  const bufferHeight2 = pageHeightThreshold - actualBreakBottom;
52534
52609
  const { node: spacingNode2 } = createFinalPagePadding(bufferHeight2);
52535
52610
  const pageSpacer2 = Decoration.widget(breakPos, spacingNode2, { key: "stable-key" });
@@ -52544,7 +52619,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52544
52619
  const headerId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52545
52620
  const footerId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
52546
52621
  header = createHeader(pageMargins, pageSize, sectionData, headerId, editor);
52547
- footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor);
52622
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber);
52548
52623
  const bufferHeight = pageHeightThreshold - lastNodeCoords.bottom;
52549
52624
  const { node: spacingNode } = createFinalPagePadding(bufferHeight);
52550
52625
  const pageSpacer = Decoration.widget(doc2.content.size, spacingNode, { key: "stable-key" });
@@ -52579,6 +52654,10 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
52579
52654
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
52580
52655
  const availableHeight = headerHeight - headerMargin;
52581
52656
  const editorContainer = document.createElement("div");
52657
+ if (!headerId && !editor.converter.headerIds["default"]) {
52658
+ headerId = "rId" + generateDocxRandomId();
52659
+ editor.converter.headerIds["default"] = headerId;
52660
+ }
52582
52661
  if (!editor.converter.headers[headerId]) {
52583
52662
  editor.converter.headers[headerId] = {
52584
52663
  type: "doc",
@@ -52586,24 +52665,21 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
52586
52665
  };
52587
52666
  }
52588
52667
  const data = editor.converter.headers[headerId];
52589
- let editorSection;
52590
- if (data) {
52591
- editorSection = createHeaderFooterEditor({
52592
- editor,
52593
- data,
52594
- editorContainer,
52595
- appendToBody: false,
52596
- sectionId: headerId,
52597
- type: "header",
52598
- availableHeight
52599
- });
52600
- editorSection.setEditable(false, false);
52601
- editor.converter.headerEditors.push({
52602
- id: headerId,
52603
- editor: editorSection
52604
- });
52605
- broadcastEditorEvents(editor, editorSection);
52606
- }
52668
+ const editorSection = createHeaderFooterEditor({
52669
+ editor,
52670
+ data,
52671
+ editorContainer,
52672
+ appendToBody: false,
52673
+ sectionId: headerId,
52674
+ type: "header",
52675
+ availableHeight
52676
+ });
52677
+ editor.converter.headerEditors.push({
52678
+ id: headerId,
52679
+ editor: editorSection
52680
+ });
52681
+ editorSection.setEditable(false, false);
52682
+ broadcastEditorEvents(editor, editorSection);
52607
52683
  editorContainer.className = "pagination-section-header";
52608
52684
  editorContainer.style.paddingTop = headerMargin + "px";
52609
52685
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -52622,26 +52698,40 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
52622
52698
  const minFooterHeight = pageMargins.bottom * 96;
52623
52699
  const footerPaddingFromEdge = pageMargins.footer * 96;
52624
52700
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
52701
+ const sectionContainer = footerDef?.sectionContainer?.cloneNode(true);
52702
+ const autoPageNumber = sectionContainer?.querySelector('span[data-id="auto-page-number"]');
52703
+ if (autoPageNumber) {
52704
+ const fontSize2 = autoPageNumber.previousElementSibling?.style?.fontSize || autoPageNumber.nextElementSibling?.style?.fontSize;
52705
+ if (fontSize2) autoPageNumber.style.fontSize = fontSize2;
52706
+ autoPageNumber.innerText = currentPageNumber;
52707
+ }
52625
52708
  const editorContainer = document.createElement("div");
52626
- const data = editor.converter.footers[footerId];
52627
- let editorSection;
52628
- if (data) {
52629
- editorSection = createHeaderFooterEditor({
52630
- editor,
52631
- data,
52632
- editorContainer,
52633
- appendToBody: false,
52634
- sectionId: footerId,
52635
- type: "footer",
52636
- availableHeight: footerHeight
52637
- });
52638
- editor.converter.footerEditors.push({
52639
- id: footerId,
52640
- editor: editorSection
52641
- });
52642
- editorSection.setEditable(false, false);
52643
- broadcastEditorEvents(editor, editorSection);
52709
+ if (!footerId && !editor.converter.footerIds["default"]) {
52710
+ footerId = "rId" + generateDocxRandomId();
52711
+ editor.converter.footerIds["default"] = footerId;
52644
52712
  }
52713
+ if (!editor.converter.footers[footerId]) {
52714
+ editor.converter.footers[footerId] = {
52715
+ type: "doc",
52716
+ content: [{ type: "paragraph", content: [] }]
52717
+ };
52718
+ }
52719
+ const data = editor.converter.footers[footerId];
52720
+ const editorSection = createHeaderFooterEditor({
52721
+ editor,
52722
+ data,
52723
+ editorContainer,
52724
+ appendToBody: false,
52725
+ sectionId: footerId,
52726
+ type: "footer",
52727
+ availableHeight: footerHeight
52728
+ });
52729
+ editor.converter.footerEditors.push({
52730
+ id: footerId,
52731
+ editor: editorSection
52732
+ });
52733
+ editorSection.setEditable(false, false);
52734
+ broadcastEditorEvents(editor, editorSection);
52645
52735
  editorContainer.className = "pagination-section-footer";
52646
52736
  editorContainer.style.height = footerHeight + "px";
52647
52737
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";