@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
@@ -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.13") {
23272
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.15") {
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.13") {
23738
+ function generateSuperdocVersion(pid = 2, version2 = "0.12.15") {
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);
@@ -39031,8 +39106,9 @@ const updateYdocDocxData = async (editor) => {
39031
39106
  Object.keys(newXml).forEach((key) => {
39032
39107
  if (key.includes("header") || key.includes("footer")) {
39033
39108
  const fileIndex = docx.findIndex((item) => item.name === key);
39034
- if (fileIndex === -1) return;
39035
- docx.splice(fileIndex, 1);
39109
+ if (fileIndex > -1) {
39110
+ docx.splice(fileIndex, 1);
39111
+ }
39036
39112
  docx.push({
39037
39113
  name: key,
39038
39114
  content: newXml[key]
@@ -40814,7 +40890,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40814
40890
  * @returns {Object | void} Migration results
40815
40891
  */
40816
40892
  processCollaborationMigrations() {
40817
- console.debug("[checkVersionMigrations] Current editor version", "0.12.13");
40893
+ console.debug("[checkVersionMigrations] Current editor version", "0.12.15");
40818
40894
  if (!this.options.ydoc) return;
40819
40895
  const metaMap = this.options.ydoc.getMap("meta");
40820
40896
  let docVersion = metaMap.get("version");
@@ -40904,7 +40980,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
40904
40980
  prepareForAnnotations(annotationValues = []) {
40905
40981
  const { tr } = this.state;
40906
40982
  const { dispatch } = this.view;
40907
- const newTr = AnnotatorServices.processTables({ editor: this, tr, annotationValues });
40983
+ const newTr = AnnotatorServices.processTables({ state: this.state, tr, annotationValues });
40908
40984
  this.view.dispatch(newTr);
40909
40985
  AnnotatorServices.annotateHeadersAndFooters({ editor: this, annotationValues });
40910
40986
  }
@@ -52529,7 +52605,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52529
52605
  currentPageNumber++;
52530
52606
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52531
52607
  header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
52532
- footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor);
52608
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor, currentPageNumber - 1);
52533
52609
  const bufferHeight2 = pageHeightThreshold - actualBreakBottom;
52534
52610
  const { node: spacingNode2 } = createFinalPagePadding(bufferHeight2);
52535
52611
  const pageSpacer2 = Decoration.widget(breakPos, spacingNode2, { key: "stable-key" });
@@ -52544,7 +52620,7 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
52544
52620
  const headerId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
52545
52621
  const footerId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
52546
52622
  header = createHeader(pageMargins, pageSize, sectionData, headerId, editor);
52547
- footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor);
52623
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber);
52548
52624
  const bufferHeight = pageHeightThreshold - lastNodeCoords.bottom;
52549
52625
  const { node: spacingNode } = createFinalPagePadding(bufferHeight);
52550
52626
  const pageSpacer = Decoration.widget(doc2.content.size, spacingNode, { key: "stable-key" });
@@ -52579,6 +52655,10 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
52579
52655
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
52580
52656
  const availableHeight = headerHeight - headerMargin;
52581
52657
  const editorContainer = document.createElement("div");
52658
+ if (!headerId && !editor.converter.headerIds["default"]) {
52659
+ headerId = "rId" + generateDocxRandomId();
52660
+ editor.converter.headerIds["default"] = headerId;
52661
+ }
52582
52662
  if (!editor.converter.headers[headerId]) {
52583
52663
  editor.converter.headers[headerId] = {
52584
52664
  type: "doc",
@@ -52586,24 +52666,21 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor) {
52586
52666
  };
52587
52667
  }
52588
52668
  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
- }
52669
+ const editorSection = createHeaderFooterEditor({
52670
+ editor,
52671
+ data,
52672
+ editorContainer,
52673
+ appendToBody: false,
52674
+ sectionId: headerId,
52675
+ type: "header",
52676
+ availableHeight
52677
+ });
52678
+ editor.converter.headerEditors.push({
52679
+ id: headerId,
52680
+ editor: editorSection
52681
+ });
52682
+ editorSection.setEditable(false, false);
52683
+ broadcastEditorEvents(editor, editorSection);
52607
52684
  editorContainer.className = "pagination-section-header";
52608
52685
  editorContainer.style.paddingTop = headerMargin + "px";
52609
52686
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -52622,26 +52699,40 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
52622
52699
  const minFooterHeight = pageMargins.bottom * 96;
52623
52700
  const footerPaddingFromEdge = pageMargins.footer * 96;
52624
52701
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
52702
+ const sectionContainer = footerDef?.sectionContainer?.cloneNode(true);
52703
+ const autoPageNumber = sectionContainer?.querySelector('span[data-id="auto-page-number"]');
52704
+ if (autoPageNumber) {
52705
+ const fontSize2 = autoPageNumber.previousElementSibling?.style?.fontSize || autoPageNumber.nextElementSibling?.style?.fontSize;
52706
+ if (fontSize2) autoPageNumber.style.fontSize = fontSize2;
52707
+ autoPageNumber.innerText = currentPageNumber;
52708
+ }
52625
52709
  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);
52710
+ if (!footerId && !editor.converter.footerIds["default"]) {
52711
+ footerId = "rId" + generateDocxRandomId();
52712
+ editor.converter.footerIds["default"] = footerId;
52644
52713
  }
52714
+ if (!editor.converter.footers[footerId]) {
52715
+ editor.converter.footers[footerId] = {
52716
+ type: "doc",
52717
+ content: [{ type: "paragraph", content: [] }]
52718
+ };
52719
+ }
52720
+ const data = editor.converter.footers[footerId];
52721
+ const editorSection = createHeaderFooterEditor({
52722
+ editor,
52723
+ data,
52724
+ editorContainer,
52725
+ appendToBody: false,
52726
+ sectionId: footerId,
52727
+ type: "footer",
52728
+ availableHeight: footerHeight
52729
+ });
52730
+ editor.converter.footerEditors.push({
52731
+ id: footerId,
52732
+ editor: editorSection
52733
+ });
52734
+ editorSection.setEditable(false, false);
52735
+ broadcastEditorEvents(editor, editorSection);
52645
52736
  editorContainer.className = "pagination-section-footer";
52646
52737
  editorContainer.style.height = footerHeight + "px";
52647
52738
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";