@harbour-enterprises/superdoc 0.12.13 → 0.12.15

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 (26) hide show
  1. package/dist/chunks/{super-editor.es-CmodrhS1.es.js → super-editor.es-B9tq7DUR.es.js} +145 -54
  2. package/dist/chunks/{super-editor.es-CTIoInER.cjs → super-editor.es-DeKTatca.cjs} +145 -54
  3. package/dist/super-editor/ai-writer.es.js +2 -2
  4. package/dist/super-editor/chunks/{converter-CBdzo5wX.js → converter-Cdyvf3TU.js} +78 -12
  5. package/dist/super-editor/chunks/{docx-zipper-BsYGIOmg.js → docx-zipper-BDrivuaF.js} +10 -1
  6. package/dist/super-editor/chunks/{editor-h9TerhsW.js → editor-CzT_ncye.js} +60 -44
  7. package/dist/super-editor/chunks/{toolbar-BPcsnrZP.js → toolbar-k0QAmXB2.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.d.ts.map +1 -1
  17. package/dist/super-editor/file-zipper.es.js +1 -1
  18. package/dist/super-editor/super-editor.es.js +6 -6
  19. package/dist/super-editor/toolbar.es.js +2 -2
  20. package/dist/super-editor.cjs +1 -1
  21. package/dist/super-editor.es.js +1 -1
  22. package/dist/superdoc.cjs +2 -2
  23. package/dist/superdoc.es.js +3 -3
  24. package/dist/superdoc.umd.js +146 -55
  25. package/dist/superdoc.umd.js.map +1 -1
  26. package/package.json +1 -1
@@ -18872,8 +18872,20 @@ function exportSchemaToJson(params2) {
18872
18872
  return router[type2](params2);
18873
18873
  }
18874
18874
  function translateBodyNode(params2) {
18875
- const sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
18875
+ let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
18876
18876
  if (params2.converter) {
18877
+ const hasHeader = sectPr.elements.some((n) => n.name === "w:headerReference");
18878
+ const hasDefaultHeader = params2.converter.headerIds?.default;
18879
+ if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
18880
+ const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
18881
+ sectPr.elements.push(defaultHeader);
18882
+ }
18883
+ const hasFooter = sectPr.elements.some((n) => n.name === "w:footerReference");
18884
+ const hasDefaultFooter = params2.converter.footerIds?.default;
18885
+ if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
18886
+ const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
18887
+ sectPr.elements.push(defaultFooter);
18888
+ }
18877
18889
  const newMargins = params2.converter.pageStyles.pageMargins;
18878
18890
  const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
18879
18891
  const { attributes } = sectPrMargins;
@@ -18895,6 +18907,16 @@ function translateBodyNode(params2) {
18895
18907
  elements: [...elements, sectPr]
18896
18908
  };
18897
18909
  }
18910
+ const generateDefaultHeaderFooter = (type2, id) => {
18911
+ return {
18912
+ "type": "element",
18913
+ "name": `w:${type2}Reference`,
18914
+ "attributes": {
18915
+ "w:type": "default",
18916
+ "r:id": id
18917
+ }
18918
+ };
18919
+ };
18898
18920
  function translateParagraphNode(params2) {
18899
18921
  const elements = translateChildNodes(params2);
18900
18922
  const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
@@ -23193,6 +23215,7 @@ const isAlternatingHeadersOddEven = (docx) => {
23193
23215
  return !!evenOdd;
23194
23216
  };
23195
23217
  const HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
23218
+ const HEADER_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
23196
23219
  const _SuperConverter = class _SuperConverter2 {
23197
23220
  constructor(params2 = null) {
23198
23221
  __privateAdd$2(this, _SuperConverter_instances);
@@ -23263,7 +23286,7 @@ const _SuperConverter = class _SuperConverter2 {
23263
23286
  return;
23264
23287
  }
23265
23288
  }
23266
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.13") {
23289
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.15") {
23267
23290
  const customLocation = "docProps/custom.xml";
23268
23291
  if (!docx[customLocation]) {
23269
23292
  docx[customLocation] = generateCustomXml();
@@ -23451,8 +23474,8 @@ const _SuperConverter = class _SuperConverter2 {
23451
23474
  commentsRels = relationships;
23452
23475
  }
23453
23476
  this.convertedXml = { ...this.convertedXml, ...updatedXml };
23454
- __privateMethod$2(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params2.relationships, ...commentsRels]);
23455
- __privateMethod$2(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
23477
+ const headFootRels = __privateMethod$2(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
23478
+ __privateMethod$2(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params2.relationships, ...commentsRels, ...headFootRels]);
23456
23479
  storeSuperdocVersion(this.convertedXml);
23457
23480
  __privateMethod$2(this, _SuperConverter_instances, exportNumberingFile_fn).call(this, params2);
23458
23481
  return xml;
@@ -23512,8 +23535,9 @@ prepareCommentsXmlFilesForExport_fn = function({ defs, exportType, commentsWithP
23512
23535
  exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23513
23536
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
23514
23537
  const relationships = relsData.elements.find((x) => x.name === "Relationships");
23515
- Object.entries(this.headers).forEach(([id, header]) => {
23516
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
23538
+ const newDocRels = [];
23539
+ Object.entries(this.headers).forEach(([id, header], index2) => {
23540
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `header${index2 + 1}.xml`;
23517
23541
  const headerEditor = this.headerEditors.find((item) => item.id === id);
23518
23542
  if (!headerEditor) return;
23519
23543
  const { result, params: params2 } = this.exportToXmlJson({
@@ -23527,7 +23551,27 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23527
23551
  });
23528
23552
  const bodyContent = result.elements[0].elements;
23529
23553
  const file = this.convertedXml[`word/${fileName}`];
23530
- file.elements[0].elements = bodyContent;
23554
+ if (!file) {
23555
+ this.convertedXml[`word/${fileName}`] = {
23556
+ declaration: this.initialJSON?.declaration,
23557
+ elements: [{
23558
+ attributes: DEFAULT_DOCX_DEFS,
23559
+ name: "w:hdr",
23560
+ type: "element",
23561
+ elements: []
23562
+ }]
23563
+ };
23564
+ newDocRels.push({
23565
+ type: "element",
23566
+ name: "Relationship",
23567
+ attributes: {
23568
+ Id: id,
23569
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
23570
+ Target: fileName
23571
+ }
23572
+ });
23573
+ }
23574
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
23531
23575
  if (params2.relationships.length) {
23532
23576
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
23533
23577
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -23545,8 +23589,8 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23545
23589
  };
23546
23590
  }
23547
23591
  });
23548
- Object.entries(this.footers).forEach(([id, footer]) => {
23549
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
23592
+ Object.entries(this.footers).forEach(([id, footer], index2) => {
23593
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `footer${index2 + 1}.xml`;
23550
23594
  const footerEditor = this.footerEditors.find((item) => item.id === id);
23551
23595
  if (!footerEditor) return;
23552
23596
  const { result, params: params2 } = this.exportToXmlJson({
@@ -23560,7 +23604,27 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23560
23604
  });
23561
23605
  const bodyContent = result.elements[0].elements;
23562
23606
  const file = this.convertedXml[`word/${fileName}`];
23563
- file.elements[0].elements = bodyContent;
23607
+ if (!file) {
23608
+ this.convertedXml[`word/${fileName}`] = {
23609
+ declaration: this.initialJSON?.declaration,
23610
+ elements: [{
23611
+ attributes: DEFAULT_DOCX_DEFS,
23612
+ name: "w:ftr",
23613
+ type: "element",
23614
+ elements: []
23615
+ }]
23616
+ };
23617
+ newDocRels.push({
23618
+ type: "element",
23619
+ name: "Relationship",
23620
+ attributes: {
23621
+ Id: id,
23622
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
23623
+ Target: fileName
23624
+ }
23625
+ });
23626
+ }
23627
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
23564
23628
  if (params2.relationships.length) {
23565
23629
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
23566
23630
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -23578,6 +23642,7 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23578
23642
  };
23579
23643
  }
23580
23644
  });
23645
+ return newDocRels;
23581
23646
  };
23582
23647
  exportProcessNewRelationships_fn = function(rels = []) {
23583
23648
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
@@ -23590,7 +23655,8 @@ exportProcessNewRelationships_fn = function(rels = []) {
23590
23655
  const existingTarget = relationships.elements.find((el) => el.attributes.Target === rel.attributes.Target);
23591
23656
  const isNewMedia = rel.attributes.Target?.startsWith("media/") && existingId.length > 6;
23592
23657
  const isNewHyperlink = rel.attributes.Type === HYPERLINK_RELATIONSHIP_TYPE && existingId.length > 6;
23593
- if (existingTarget && !isNewMedia && !isNewHyperlink) {
23658
+ const isNewHeadFoot = rel.attributes.Type === HEADER_RELATIONSHIP_TYPE && existingId.length > 6;
23659
+ if (existingTarget && !isNewMedia && !isNewHyperlink && !isNewHeadFoot) {
23594
23660
  return;
23595
23661
  }
23596
23662
  rel.attributes.Target = rel.attributes?.Target?.replace(/&/g, "&");
@@ -23686,7 +23752,7 @@ function storeSuperdocVersion(docx) {
23686
23752
  function generateCustomXml() {
23687
23753
  return DEFAULT_CUSTOM_XML;
23688
23754
  }
23689
- function generateSuperdocVersion(pid = 2, version2 = "0.12.13") {
23755
+ function generateSuperdocVersion(pid = 2, version2 = "0.12.15") {
23690
23756
  return {
23691
23757
  type: "element",
23692
23758
  name: "property",
@@ -26124,6 +26190,15 @@ class DocxZipper {
26124
26190
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
26125
26191
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
26126
26192
  }
26193
+ Object.keys(docx.files).forEach((name) => {
26194
+ if (!name.includes("header") && !name.includes("footer")) return;
26195
+ const hasExtensible = types2.elements?.some((el) => el.name === "Override" && el.attributes.PartName === `/${name}`);
26196
+ const type2 = name.includes("header") ? "header" : "footer";
26197
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type2}+xml"/>`;
26198
+ if (!hasExtensible) {
26199
+ typesString += extendedDef;
26200
+ }
26201
+ });
26127
26202
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
26128
26203
  const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
26129
26204
  docx.file(contentTypesPath, updatedContentTypesXml);
@@ -39048,8 +39123,9 @@ const updateYdocDocxData = async (editor) => {
39048
39123
  Object.keys(newXml).forEach((key) => {
39049
39124
  if (key.includes("header") || key.includes("footer")) {
39050
39125
  const fileIndex = docx.findIndex((item) => item.name === key);
39051
- if (fileIndex === -1) return;
39052
- docx.splice(fileIndex, 1);
39126
+ if (fileIndex > -1) {
39127
+ docx.splice(fileIndex, 1);
39128
+ }
39053
39129
  docx.push({
39054
39130
  name: key,
39055
39131
  content: newXml[key]
@@ -40831,7 +40907,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40831
40907
  * @returns {Object | void} Migration results
40832
40908
  */
40833
40909
  processCollaborationMigrations() {
40834
- console.debug("[checkVersionMigrations] Current editor version", "0.12.13");
40910
+ console.debug("[checkVersionMigrations] Current editor version", "0.12.15");
40835
40911
  if (!this.options.ydoc) return;
40836
40912
  const metaMap = this.options.ydoc.getMap("meta");
40837
40913
  let docVersion = metaMap.get("version");
@@ -40921,7 +40997,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40921
40997
  prepareForAnnotations(annotationValues = []) {
40922
40998
  const { tr } = this.state;
40923
40999
  const { dispatch } = this.view;
40924
- const newTr = AnnotatorServices.processTables({ editor: this, tr, annotationValues });
41000
+ const newTr = AnnotatorServices.processTables({ state: this.state, tr, annotationValues });
40925
41001
  this.view.dispatch(newTr);
40926
41002
  AnnotatorServices.annotateHeadersAndFooters({ editor: this, annotationValues });
40927
41003
  }
@@ -52546,7 +52622,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52546
52622
  currentPageNumber++;
52547
52623
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52548
52624
  header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
52549
- footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor);
52625
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor, currentPageNumber - 1);
52550
52626
  const bufferHeight2 = pageHeightThreshold - actualBreakBottom;
52551
52627
  const { node: spacingNode2 } = createFinalPagePadding(bufferHeight2);
52552
52628
  const pageSpacer2 = Decoration.widget(breakPos, spacingNode2, { key: "stable-key" });
@@ -52561,7 +52637,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52561
52637
  const headerId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52562
52638
  const footerId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
52563
52639
  header = createHeader(pageMargins, pageSize, sectionData, headerId, editor);
52564
- footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor);
52640
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber);
52565
52641
  const bufferHeight = pageHeightThreshold - lastNodeCoords.bottom;
52566
52642
  const { node: spacingNode } = createFinalPagePadding(bufferHeight);
52567
52643
  const pageSpacer = Decoration.widget(doc2.content.size, spacingNode, { key: "stable-key" });
@@ -52596,6 +52672,10 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
52596
52672
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
52597
52673
  const availableHeight = headerHeight - headerMargin;
52598
52674
  const editorContainer = document.createElement("div");
52675
+ if (!headerId && !editor.converter.headerIds["default"]) {
52676
+ headerId = "rId" + generateDocxRandomId();
52677
+ editor.converter.headerIds["default"] = headerId;
52678
+ }
52599
52679
  if (!editor.converter.headers[headerId]) {
52600
52680
  editor.converter.headers[headerId] = {
52601
52681
  type: "doc",
@@ -52603,24 +52683,21 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
52603
52683
  };
52604
52684
  }
52605
52685
  const data = editor.converter.headers[headerId];
52606
- let editorSection;
52607
- if (data) {
52608
- editorSection = createHeaderFooterEditor({
52609
- editor,
52610
- data,
52611
- editorContainer,
52612
- appendToBody: false,
52613
- sectionId: headerId,
52614
- type: "header",
52615
- availableHeight
52616
- });
52617
- editorSection.setEditable(false, false);
52618
- editor.converter.headerEditors.push({
52619
- id: headerId,
52620
- editor: editorSection
52621
- });
52622
- broadcastEditorEvents(editor, editorSection);
52623
- }
52686
+ const editorSection = createHeaderFooterEditor({
52687
+ editor,
52688
+ data,
52689
+ editorContainer,
52690
+ appendToBody: false,
52691
+ sectionId: headerId,
52692
+ type: "header",
52693
+ availableHeight
52694
+ });
52695
+ editor.converter.headerEditors.push({
52696
+ id: headerId,
52697
+ editor: editorSection
52698
+ });
52699
+ editorSection.setEditable(false, false);
52700
+ broadcastEditorEvents(editor, editorSection);
52624
52701
  editorContainer.className = "pagination-section-header";
52625
52702
  editorContainer.style.paddingTop = headerMargin + "px";
52626
52703
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -52639,26 +52716,40 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
52639
52716
  const minFooterHeight = pageMargins.bottom * 96;
52640
52717
  const footerPaddingFromEdge = pageMargins.footer * 96;
52641
52718
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
52719
+ const sectionContainer = footerDef?.sectionContainer?.cloneNode(true);
52720
+ const autoPageNumber = sectionContainer?.querySelector('span[data-id="auto-page-number"]');
52721
+ if (autoPageNumber) {
52722
+ const fontSize2 = autoPageNumber.previousElementSibling?.style?.fontSize || autoPageNumber.nextElementSibling?.style?.fontSize;
52723
+ if (fontSize2) autoPageNumber.style.fontSize = fontSize2;
52724
+ autoPageNumber.innerText = currentPageNumber;
52725
+ }
52642
52726
  const editorContainer = document.createElement("div");
52643
- const data = editor.converter.footers[footerId];
52644
- let editorSection;
52645
- if (data) {
52646
- editorSection = createHeaderFooterEditor({
52647
- editor,
52648
- data,
52649
- editorContainer,
52650
- appendToBody: false,
52651
- sectionId: footerId,
52652
- type: "footer",
52653
- availableHeight: footerHeight
52654
- });
52655
- editor.converter.footerEditors.push({
52656
- id: footerId,
52657
- editor: editorSection
52658
- });
52659
- editorSection.setEditable(false, false);
52660
- broadcastEditorEvents(editor, editorSection);
52727
+ if (!footerId && !editor.converter.footerIds["default"]) {
52728
+ footerId = "rId" + generateDocxRandomId();
52729
+ editor.converter.footerIds["default"] = footerId;
52661
52730
  }
52731
+ if (!editor.converter.footers[footerId]) {
52732
+ editor.converter.footers[footerId] = {
52733
+ type: "doc",
52734
+ content: [{ type: "paragraph", content: [] }]
52735
+ };
52736
+ }
52737
+ const data = editor.converter.footers[footerId];
52738
+ const editorSection = createHeaderFooterEditor({
52739
+ editor,
52740
+ data,
52741
+ editorContainer,
52742
+ appendToBody: false,
52743
+ sectionId: footerId,
52744
+ type: "footer",
52745
+ availableHeight: footerHeight
52746
+ });
52747
+ editor.converter.footerEditors.push({
52748
+ id: footerId,
52749
+ editor: editorSection
52750
+ });
52751
+ editorSection.setEditable(false, false);
52752
+ broadcastEditorEvents(editor, editorSection);
52662
52753
  editorContainer.className = "pagination-section-footer";
52663
52754
  editorContainer.style.height = footerHeight + "px";
52664
52755
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
@@ -1,6 +1,6 @@
1
1
  import { ref, onMounted, onUnmounted, computed, createElementBlock, openBlock, withModifiers, createElementVNode, withDirectives, unref, vModelText, createCommentVNode, nextTick } from "vue";
2
- import { T as TextSelection } from "./chunks/converter-CBdzo5wX.js";
3
- import { _ as _export_sfc } from "./chunks/editor-h9TerhsW.js";
2
+ import { T as TextSelection } from "./chunks/converter-Cdyvf3TU.js";
3
+ import { _ as _export_sfc } from "./chunks/editor-CzT_ncye.js";
4
4
  const DEFAULT_API_ENDPOINT = "https://sd-dev-express-gateway-i6xtm.ondigitalocean.app/insights";
5
5
  const SYSTEM_PROMPT = "You are an expert copywriter and you are immersed in a document editor. You are to provide document related text responses based on the user prompts. Only write what is asked for. Do not provide explanations. Try to keep placeholders as short as possible. Do not output your prompt. Your instructions are: ";
6
6
  async function baseInsightsFetch(payload, options = {}) {
@@ -18874,8 +18874,20 @@ function exportSchemaToJson(params) {
18874
18874
  return router[type2](params);
18875
18875
  }
18876
18876
  function translateBodyNode(params) {
18877
- const sectPr = params.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
18877
+ let sectPr = params.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
18878
18878
  if (params.converter) {
18879
+ const hasHeader = sectPr.elements.some((n) => n.name === "w:headerReference");
18880
+ const hasDefaultHeader = params.converter.headerIds?.default;
18881
+ if (!hasHeader && hasDefaultHeader && !params.editor.options.isHeaderOrFooter) {
18882
+ const defaultHeader = generateDefaultHeaderFooter("header", params.converter.headerIds?.default);
18883
+ sectPr.elements.push(defaultHeader);
18884
+ }
18885
+ const hasFooter = sectPr.elements.some((n) => n.name === "w:footerReference");
18886
+ const hasDefaultFooter = params.converter.footerIds?.default;
18887
+ if (!hasFooter && hasDefaultFooter && !params.editor.options.isHeaderOrFooter) {
18888
+ const defaultFooter = generateDefaultHeaderFooter("footer", params.converter.footerIds?.default);
18889
+ sectPr.elements.push(defaultFooter);
18890
+ }
18879
18891
  const newMargins = params.converter.pageStyles.pageMargins;
18880
18892
  const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
18881
18893
  const { attributes } = sectPrMargins;
@@ -18897,6 +18909,16 @@ function translateBodyNode(params) {
18897
18909
  elements: [...elements, sectPr]
18898
18910
  };
18899
18911
  }
18912
+ const generateDefaultHeaderFooter = (type2, id) => {
18913
+ return {
18914
+ "type": "element",
18915
+ "name": `w:${type2}Reference`,
18916
+ "attributes": {
18917
+ "w:type": "default",
18918
+ "r:id": id
18919
+ }
18920
+ };
18921
+ };
18900
18922
  function translateParagraphNode(params) {
18901
18923
  const elements = translateChildNodes(params);
18902
18924
  const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
@@ -23195,6 +23217,7 @@ const isAlternatingHeadersOddEven = (docx) => {
23195
23217
  return !!evenOdd;
23196
23218
  };
23197
23219
  const HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
23220
+ const HEADER_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
23198
23221
  const _SuperConverter = class _SuperConverter {
23199
23222
  constructor(params = null) {
23200
23223
  __privateAdd(this, _SuperConverter_instances);
@@ -23265,7 +23288,7 @@ const _SuperConverter = class _SuperConverter {
23265
23288
  return;
23266
23289
  }
23267
23290
  }
23268
- static updateDocumentVersion(docx = this.convertedXml, version = "0.12.13") {
23291
+ static updateDocumentVersion(docx = this.convertedXml, version = "0.12.15") {
23269
23292
  const customLocation = "docProps/custom.xml";
23270
23293
  if (!docx[customLocation]) {
23271
23294
  docx[customLocation] = generateCustomXml();
@@ -23453,8 +23476,8 @@ const _SuperConverter = class _SuperConverter {
23453
23476
  commentsRels = relationships;
23454
23477
  }
23455
23478
  this.convertedXml = { ...this.convertedXml, ...updatedXml };
23456
- __privateMethod(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params.relationships, ...commentsRels]);
23457
- __privateMethod(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
23479
+ const headFootRels = __privateMethod(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
23480
+ __privateMethod(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params.relationships, ...commentsRels, ...headFootRels]);
23458
23481
  storeSuperdocVersion(this.convertedXml);
23459
23482
  __privateMethod(this, _SuperConverter_instances, exportNumberingFile_fn).call(this, params);
23460
23483
  return xml;
@@ -23517,8 +23540,9 @@ prepareCommentsXmlFilesForExport_fn = function({ defs, exportType, commentsWithP
23517
23540
  exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23518
23541
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
23519
23542
  const relationships = relsData.elements.find((x) => x.name === "Relationships");
23520
- Object.entries(this.headers).forEach(([id, header]) => {
23521
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
23543
+ const newDocRels = [];
23544
+ Object.entries(this.headers).forEach(([id, header], index) => {
23545
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `header${index + 1}.xml`;
23522
23546
  const headerEditor = this.headerEditors.find((item) => item.id === id);
23523
23547
  if (!headerEditor) return;
23524
23548
  const { result, params } = this.exportToXmlJson({
@@ -23532,7 +23556,27 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23532
23556
  });
23533
23557
  const bodyContent = result.elements[0].elements;
23534
23558
  const file = this.convertedXml[`word/${fileName}`];
23535
- file.elements[0].elements = bodyContent;
23559
+ if (!file) {
23560
+ this.convertedXml[`word/${fileName}`] = {
23561
+ declaration: this.initialJSON?.declaration,
23562
+ elements: [{
23563
+ attributes: DEFAULT_DOCX_DEFS,
23564
+ name: "w:hdr",
23565
+ type: "element",
23566
+ elements: []
23567
+ }]
23568
+ };
23569
+ newDocRels.push({
23570
+ type: "element",
23571
+ name: "Relationship",
23572
+ attributes: {
23573
+ Id: id,
23574
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
23575
+ Target: fileName
23576
+ }
23577
+ });
23578
+ }
23579
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
23536
23580
  if (params.relationships.length) {
23537
23581
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
23538
23582
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -23550,8 +23594,8 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23550
23594
  };
23551
23595
  }
23552
23596
  });
23553
- Object.entries(this.footers).forEach(([id, footer]) => {
23554
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
23597
+ Object.entries(this.footers).forEach(([id, footer], index) => {
23598
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `footer${index + 1}.xml`;
23555
23599
  const footerEditor = this.footerEditors.find((item) => item.id === id);
23556
23600
  if (!footerEditor) return;
23557
23601
  const { result, params } = this.exportToXmlJson({
@@ -23565,7 +23609,27 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23565
23609
  });
23566
23610
  const bodyContent = result.elements[0].elements;
23567
23611
  const file = this.convertedXml[`word/${fileName}`];
23568
- file.elements[0].elements = bodyContent;
23612
+ if (!file) {
23613
+ this.convertedXml[`word/${fileName}`] = {
23614
+ declaration: this.initialJSON?.declaration,
23615
+ elements: [{
23616
+ attributes: DEFAULT_DOCX_DEFS,
23617
+ name: "w:ftr",
23618
+ type: "element",
23619
+ elements: []
23620
+ }]
23621
+ };
23622
+ newDocRels.push({
23623
+ type: "element",
23624
+ name: "Relationship",
23625
+ attributes: {
23626
+ Id: id,
23627
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
23628
+ Target: fileName
23629
+ }
23630
+ });
23631
+ }
23632
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
23569
23633
  if (params.relationships.length) {
23570
23634
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
23571
23635
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -23583,6 +23647,7 @@ exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
23583
23647
  };
23584
23648
  }
23585
23649
  });
23650
+ return newDocRels;
23586
23651
  };
23587
23652
  exportProcessNewRelationships_fn = function(rels = []) {
23588
23653
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
@@ -23595,7 +23660,8 @@ exportProcessNewRelationships_fn = function(rels = []) {
23595
23660
  const existingTarget = relationships.elements.find((el) => el.attributes.Target === rel.attributes.Target);
23596
23661
  const isNewMedia = rel.attributes.Target?.startsWith("media/") && existingId.length > 6;
23597
23662
  const isNewHyperlink = rel.attributes.Type === HYPERLINK_RELATIONSHIP_TYPE && existingId.length > 6;
23598
- if (existingTarget && !isNewMedia && !isNewHyperlink) {
23663
+ const isNewHeadFoot = rel.attributes.Type === HEADER_RELATIONSHIP_TYPE && existingId.length > 6;
23664
+ if (existingTarget && !isNewMedia && !isNewHyperlink && !isNewHeadFoot) {
23599
23665
  return;
23600
23666
  }
23601
23667
  rel.attributes.Target = rel.attributes?.Target?.replace(/&/g, "&amp;");
@@ -23691,7 +23757,7 @@ function storeSuperdocVersion(docx) {
23691
23757
  function generateCustomXml() {
23692
23758
  return DEFAULT_CUSTOM_XML;
23693
23759
  }
23694
- function generateSuperdocVersion(pid = 2, version = "0.12.13") {
23760
+ function generateSuperdocVersion(pid = 2, version = "0.12.15") {
23695
23761
  return {
23696
23762
  type: "element",
23697
23763
  name: "property",
@@ -1,4 +1,4 @@
1
- import { x as process$1, a1 as commonjsGlobal, B as Buffer, a2 as getDefaultExportFromCjs, a3 as getContentTypesFromXml, a4 as xmljs } from "./converter-CBdzo5wX.js";
1
+ import { x as process$1, a1 as commonjsGlobal, B as Buffer, a2 as getDefaultExportFromCjs, a3 as getContentTypesFromXml, a4 as xmljs } from "./converter-Cdyvf3TU.js";
2
2
  function commonjsRequire(path) {
3
3
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
4
4
  }
@@ -2414,6 +2414,15 @@ class DocxZipper {
2414
2414
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
2415
2415
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
2416
2416
  }
2417
+ Object.keys(docx.files).forEach((name) => {
2418
+ if (!name.includes("header") && !name.includes("footer")) return;
2419
+ const hasExtensible = types.elements?.some((el) => el.name === "Override" && el.attributes.PartName === `/${name}`);
2420
+ const type = name.includes("header") ? "header" : "footer";
2421
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type}+xml"/>`;
2422
+ if (!hasExtensible) {
2423
+ typesString += extendedDef;
2424
+ }
2425
+ });
2417
2426
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
2418
2427
  const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
2419
2428
  docx.file(contentTypesPath, updatedContentTypesXml);