@harbour-enterprises/superdoc 0.12.14 → 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-BOH6x5Dh.es.js → super-editor.es-B9tq7DUR.es.js} +144 -53
  2. package/dist/chunks/{super-editor.es-DF_gWgh-.cjs → super-editor.es-DeKTatca.cjs} +144 -53
  3. package/dist/super-editor/ai-writer.es.js +2 -2
  4. package/dist/super-editor/chunks/{converter-D3CdG5M7.js → converter-Cdyvf3TU.js} +78 -12
  5. package/dist/super-editor/chunks/{docx-zipper-DBFk7dLq.js → docx-zipper-BDrivuaF.js} +10 -1
  6. package/dist/super-editor/chunks/{editor-CdSN8S-8.js → editor-CzT_ncye.js} +59 -43
  7. package/dist/super-editor/chunks/{toolbar-C2Qr2ADq.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 +145 -54
  25. package/dist/superdoc.umd.js.map +1 -1
  26. package/package.json +1 -1
@@ -26232,8 +26232,20 @@
26232
26232
  return router[type2](params2);
26233
26233
  }
26234
26234
  function translateBodyNode(params2) {
26235
- const sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
26235
+ let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
26236
26236
  if (params2.converter) {
26237
+ const hasHeader = sectPr.elements.some((n) => n.name === "w:headerReference");
26238
+ const hasDefaultHeader = params2.converter.headerIds?.default;
26239
+ if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
26240
+ const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
26241
+ sectPr.elements.push(defaultHeader);
26242
+ }
26243
+ const hasFooter = sectPr.elements.some((n) => n.name === "w:footerReference");
26244
+ const hasDefaultFooter = params2.converter.footerIds?.default;
26245
+ if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
26246
+ const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
26247
+ sectPr.elements.push(defaultFooter);
26248
+ }
26237
26249
  const newMargins = params2.converter.pageStyles.pageMargins;
26238
26250
  const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
26239
26251
  const { attributes } = sectPrMargins;
@@ -26255,6 +26267,16 @@
26255
26267
  elements: [...elements, sectPr]
26256
26268
  };
26257
26269
  }
26270
+ const generateDefaultHeaderFooter = (type2, id) => {
26271
+ return {
26272
+ "type": "element",
26273
+ "name": `w:${type2}Reference`,
26274
+ "attributes": {
26275
+ "w:type": "default",
26276
+ "r:id": id
26277
+ }
26278
+ };
26279
+ };
26258
26280
  function translateParagraphNode(params2) {
26259
26281
  const elements = translateChildNodes(params2);
26260
26282
  const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
@@ -30553,6 +30575,7 @@
30553
30575
  return !!evenOdd;
30554
30576
  };
30555
30577
  const HYPERLINK_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
30578
+ const HEADER_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
30556
30579
  const _SuperConverter = class _SuperConverter2 {
30557
30580
  constructor(params2 = null) {
30558
30581
  __privateAdd$2(this, _SuperConverter_instances);
@@ -30623,7 +30646,7 @@
30623
30646
  return;
30624
30647
  }
30625
30648
  }
30626
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.14") {
30649
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.15") {
30627
30650
  const customLocation = "docProps/custom.xml";
30628
30651
  if (!docx[customLocation]) {
30629
30652
  docx[customLocation] = generateCustomXml();
@@ -30811,8 +30834,8 @@
30811
30834
  commentsRels = relationships;
30812
30835
  }
30813
30836
  this.convertedXml = { ...this.convertedXml, ...updatedXml };
30814
- __privateMethod$2(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params2.relationships, ...commentsRels]);
30815
- __privateMethod$2(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
30837
+ const headFootRels = __privateMethod$2(this, _SuperConverter_instances, exportProcessHeadersFooters_fn).call(this, { isFinalDoc });
30838
+ __privateMethod$2(this, _SuperConverter_instances, exportProcessNewRelationships_fn).call(this, [...params2.relationships, ...commentsRels, ...headFootRels]);
30816
30839
  storeSuperdocVersion(this.convertedXml);
30817
30840
  __privateMethod$2(this, _SuperConverter_instances, exportNumberingFile_fn).call(this, params2);
30818
30841
  return xml;
@@ -30872,8 +30895,9 @@
30872
30895
  exportProcessHeadersFooters_fn = function({ isFinalDoc = false }) {
30873
30896
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
30874
30897
  const relationships = relsData.elements.find((x) => x.name === "Relationships");
30875
- Object.entries(this.headers).forEach(([id, header]) => {
30876
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
30898
+ const newDocRels = [];
30899
+ Object.entries(this.headers).forEach(([id, header], index2) => {
30900
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `header${index2 + 1}.xml`;
30877
30901
  const headerEditor = this.headerEditors.find((item) => item.id === id);
30878
30902
  if (!headerEditor) return;
30879
30903
  const { result, params: params2 } = this.exportToXmlJson({
@@ -30887,7 +30911,27 @@
30887
30911
  });
30888
30912
  const bodyContent = result.elements[0].elements;
30889
30913
  const file = this.convertedXml[`word/${fileName}`];
30890
- file.elements[0].elements = bodyContent;
30914
+ if (!file) {
30915
+ this.convertedXml[`word/${fileName}`] = {
30916
+ declaration: this.initialJSON?.declaration,
30917
+ elements: [{
30918
+ attributes: DEFAULT_DOCX_DEFS,
30919
+ name: "w:hdr",
30920
+ type: "element",
30921
+ elements: []
30922
+ }]
30923
+ };
30924
+ newDocRels.push({
30925
+ type: "element",
30926
+ name: "Relationship",
30927
+ attributes: {
30928
+ Id: id,
30929
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
30930
+ Target: fileName
30931
+ }
30932
+ });
30933
+ }
30934
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
30891
30935
  if (params2.relationships.length) {
30892
30936
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
30893
30937
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -30905,8 +30949,8 @@
30905
30949
  };
30906
30950
  }
30907
30951
  });
30908
- Object.entries(this.footers).forEach(([id, footer]) => {
30909
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target;
30952
+ Object.entries(this.footers).forEach(([id, footer], index2) => {
30953
+ const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `footer${index2 + 1}.xml`;
30910
30954
  const footerEditor = this.footerEditors.find((item) => item.id === id);
30911
30955
  if (!footerEditor) return;
30912
30956
  const { result, params: params2 } = this.exportToXmlJson({
@@ -30920,7 +30964,27 @@
30920
30964
  });
30921
30965
  const bodyContent = result.elements[0].elements;
30922
30966
  const file = this.convertedXml[`word/${fileName}`];
30923
- file.elements[0].elements = bodyContent;
30967
+ if (!file) {
30968
+ this.convertedXml[`word/${fileName}`] = {
30969
+ declaration: this.initialJSON?.declaration,
30970
+ elements: [{
30971
+ attributes: DEFAULT_DOCX_DEFS,
30972
+ name: "w:ftr",
30973
+ type: "element",
30974
+ elements: []
30975
+ }]
30976
+ };
30977
+ newDocRels.push({
30978
+ type: "element",
30979
+ name: "Relationship",
30980
+ attributes: {
30981
+ Id: id,
30982
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
30983
+ Target: fileName
30984
+ }
30985
+ });
30986
+ }
30987
+ this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
30924
30988
  if (params2.relationships.length) {
30925
30989
  const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
30926
30990
  this.convertedXml[`word/_rels/${fileName}.rels`] = {
@@ -30938,6 +31002,7 @@
30938
31002
  };
30939
31003
  }
30940
31004
  });
31005
+ return newDocRels;
30941
31006
  };
30942
31007
  exportProcessNewRelationships_fn = function(rels = []) {
30943
31008
  const relsData = this.convertedXml["word/_rels/document.xml.rels"];
@@ -30950,7 +31015,8 @@
30950
31015
  const existingTarget = relationships.elements.find((el) => el.attributes.Target === rel.attributes.Target);
30951
31016
  const isNewMedia = rel.attributes.Target?.startsWith("media/") && existingId.length > 6;
30952
31017
  const isNewHyperlink = rel.attributes.Type === HYPERLINK_RELATIONSHIP_TYPE && existingId.length > 6;
30953
- if (existingTarget && !isNewMedia && !isNewHyperlink) {
31018
+ const isNewHeadFoot = rel.attributes.Type === HEADER_RELATIONSHIP_TYPE && existingId.length > 6;
31019
+ if (existingTarget && !isNewMedia && !isNewHyperlink && !isNewHeadFoot) {
30954
31020
  return;
30955
31021
  }
30956
31022
  rel.attributes.Target = rel.attributes?.Target?.replace(/&/g, "&");
@@ -31046,7 +31112,7 @@
31046
31112
  function generateCustomXml() {
31047
31113
  return DEFAULT_CUSTOM_XML;
31048
31114
  }
31049
- function generateSuperdocVersion(pid = 2, version2 = "0.12.14") {
31115
+ function generateSuperdocVersion(pid = 2, version2 = "0.12.15") {
31050
31116
  return {
31051
31117
  type: "element",
31052
31118
  name: "property",
@@ -33484,6 +33550,15 @@
33484
33550
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
33485
33551
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
33486
33552
  }
33553
+ Object.keys(docx.files).forEach((name) => {
33554
+ if (!name.includes("header") && !name.includes("footer")) return;
33555
+ const hasExtensible = types2.elements?.some((el) => el.name === "Override" && el.attributes.PartName === `/${name}`);
33556
+ const type2 = name.includes("header") ? "header" : "footer";
33557
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type2}+xml"/>`;
33558
+ if (!hasExtensible) {
33559
+ typesString += extendedDef;
33560
+ }
33561
+ });
33487
33562
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
33488
33563
  const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
33489
33564
  docx.file(contentTypesPath, updatedContentTypesXml);
@@ -46408,8 +46483,9 @@
46408
46483
  Object.keys(newXml).forEach((key) => {
46409
46484
  if (key.includes("header") || key.includes("footer")) {
46410
46485
  const fileIndex = docx.findIndex((item) => item.name === key);
46411
- if (fileIndex === -1) return;
46412
- docx.splice(fileIndex, 1);
46486
+ if (fileIndex > -1) {
46487
+ docx.splice(fileIndex, 1);
46488
+ }
46413
46489
  docx.push({
46414
46490
  name: key,
46415
46491
  content: newXml[key]
@@ -48191,7 +48267,7 @@
48191
48267
  * @returns {Object | void} Migration results
48192
48268
  */
48193
48269
  processCollaborationMigrations() {
48194
- console.debug("[checkVersionMigrations] Current editor version", "0.12.14");
48270
+ console.debug("[checkVersionMigrations] Current editor version", "0.12.15");
48195
48271
  if (!this.options.ydoc) return;
48196
48272
  const metaMap = this.options.ydoc.getMap("meta");
48197
48273
  let docVersion = metaMap.get("version");
@@ -59906,7 +59982,7 @@
59906
59982
  currentPageNumber++;
59907
59983
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor);
59908
59984
  header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
59909
- footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor);
59985
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor, currentPageNumber - 1);
59910
59986
  const bufferHeight2 = pageHeightThreshold - actualBreakBottom;
59911
59987
  const { node: spacingNode2 } = createFinalPagePadding(bufferHeight2);
59912
59988
  const pageSpacer2 = Decoration.widget(breakPos, spacingNode2, { key: "stable-key" });
@@ -59921,7 +59997,7 @@
59921
59997
  const headerId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
59922
59998
  const footerId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
59923
59999
  header = createHeader(pageMargins, pageSize, sectionData, headerId, editor);
59924
- footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor);
60000
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber);
59925
60001
  const bufferHeight = pageHeightThreshold - lastNodeCoords.bottom;
59926
60002
  const { node: spacingNode } = createFinalPagePadding(bufferHeight);
59927
60003
  const pageSpacer = Decoration.widget(doc2.content.size, spacingNode, { key: "stable-key" });
@@ -59956,6 +60032,10 @@
59956
60032
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
59957
60033
  const availableHeight = headerHeight - headerMargin;
59958
60034
  const editorContainer = document.createElement("div");
60035
+ if (!headerId && !editor.converter.headerIds["default"]) {
60036
+ headerId = "rId" + generateDocxRandomId();
60037
+ editor.converter.headerIds["default"] = headerId;
60038
+ }
59959
60039
  if (!editor.converter.headers[headerId]) {
59960
60040
  editor.converter.headers[headerId] = {
59961
60041
  type: "doc",
@@ -59963,24 +60043,21 @@
59963
60043
  };
59964
60044
  }
59965
60045
  const data = editor.converter.headers[headerId];
59966
- let editorSection;
59967
- if (data) {
59968
- editorSection = createHeaderFooterEditor({
59969
- editor,
59970
- data,
59971
- editorContainer,
59972
- appendToBody: false,
59973
- sectionId: headerId,
59974
- type: "header",
59975
- availableHeight
59976
- });
59977
- editorSection.setEditable(false, false);
59978
- editor.converter.headerEditors.push({
59979
- id: headerId,
59980
- editor: editorSection
59981
- });
59982
- broadcastEditorEvents(editor, editorSection);
59983
- }
60046
+ const editorSection = createHeaderFooterEditor({
60047
+ editor,
60048
+ data,
60049
+ editorContainer,
60050
+ appendToBody: false,
60051
+ sectionId: headerId,
60052
+ type: "header",
60053
+ availableHeight
60054
+ });
60055
+ editor.converter.headerEditors.push({
60056
+ id: headerId,
60057
+ editor: editorSection
60058
+ });
60059
+ editorSection.setEditable(false, false);
60060
+ broadcastEditorEvents(editor, editorSection);
59984
60061
  editorContainer.className = "pagination-section-header";
59985
60062
  editorContainer.style.paddingTop = headerMargin + "px";
59986
60063
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -59999,26 +60076,40 @@
59999
60076
  const minFooterHeight = pageMargins.bottom * 96;
60000
60077
  const footerPaddingFromEdge = pageMargins.footer * 96;
60001
60078
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
60079
+ const sectionContainer = footerDef?.sectionContainer?.cloneNode(true);
60080
+ const autoPageNumber = sectionContainer?.querySelector('span[data-id="auto-page-number"]');
60081
+ if (autoPageNumber) {
60082
+ const fontSize2 = autoPageNumber.previousElementSibling?.style?.fontSize || autoPageNumber.nextElementSibling?.style?.fontSize;
60083
+ if (fontSize2) autoPageNumber.style.fontSize = fontSize2;
60084
+ autoPageNumber.innerText = currentPageNumber;
60085
+ }
60002
60086
  const editorContainer = document.createElement("div");
60003
- const data = editor.converter.footers[footerId];
60004
- let editorSection;
60005
- if (data) {
60006
- editorSection = createHeaderFooterEditor({
60007
- editor,
60008
- data,
60009
- editorContainer,
60010
- appendToBody: false,
60011
- sectionId: footerId,
60012
- type: "footer",
60013
- availableHeight: footerHeight
60014
- });
60015
- editor.converter.footerEditors.push({
60016
- id: footerId,
60017
- editor: editorSection
60018
- });
60019
- editorSection.setEditable(false, false);
60020
- broadcastEditorEvents(editor, editorSection);
60087
+ if (!footerId && !editor.converter.footerIds["default"]) {
60088
+ footerId = "rId" + generateDocxRandomId();
60089
+ editor.converter.footerIds["default"] = footerId;
60090
+ }
60091
+ if (!editor.converter.footers[footerId]) {
60092
+ editor.converter.footers[footerId] = {
60093
+ type: "doc",
60094
+ content: [{ type: "paragraph", content: [] }]
60095
+ };
60021
60096
  }
60097
+ const data = editor.converter.footers[footerId];
60098
+ const editorSection = createHeaderFooterEditor({
60099
+ editor,
60100
+ data,
60101
+ editorContainer,
60102
+ appendToBody: false,
60103
+ sectionId: footerId,
60104
+ type: "footer",
60105
+ availableHeight: footerHeight
60106
+ });
60107
+ editor.converter.footerEditors.push({
60108
+ id: footerId,
60109
+ editor: editorSection
60110
+ });
60111
+ editorSection.setEditable(false, false);
60112
+ broadcastEditorEvents(editor, editorSection);
60022
60113
  editorContainer.className = "pagination-section-footer";
60023
60114
  editorContainer.style.height = footerHeight + "px";
60024
60115
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
@@ -89285,7 +89376,7 @@ ${style2}
89285
89376
  this.config.colors = shuffleArray(this.config.colors);
89286
89377
  this.userColorMap = /* @__PURE__ */ new Map();
89287
89378
  this.colorIndex = 0;
89288
- this.version = "0.12.14";
89379
+ this.version = "0.12.15";
89289
89380
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
89290
89381
  this.superdocId = config.superdocId || v4();
89291
89382
  this.colors = this.config.colors;