@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
@@ -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.16") {
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.16") {
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);
@@ -46343,7 +46418,6 @@
46343
46418
  const pm = editorContainer.querySelector(".ProseMirror");
46344
46419
  pm.style.maxHeight = "100%";
46345
46420
  pm.style.minHeight = "100%";
46346
- pm.style.overflow = "auto";
46347
46421
  pm.style.outline = "none";
46348
46422
  pm.style.border = "none";
46349
46423
  return headerFooterEditor;
@@ -46408,8 +46482,9 @@
46408
46482
  Object.keys(newXml).forEach((key) => {
46409
46483
  if (key.includes("header") || key.includes("footer")) {
46410
46484
  const fileIndex = docx.findIndex((item) => item.name === key);
46411
- if (fileIndex === -1) return;
46412
- docx.splice(fileIndex, 1);
46485
+ if (fileIndex > -1) {
46486
+ docx.splice(fileIndex, 1);
46487
+ }
46413
46488
  docx.push({
46414
46489
  name: key,
46415
46490
  content: newXml[key]
@@ -48191,7 +48266,7 @@
48191
48266
  * @returns {Object | void} Migration results
48192
48267
  */
48193
48268
  processCollaborationMigrations() {
48194
- console.debug("[checkVersionMigrations] Current editor version", "0.12.14");
48269
+ console.debug("[checkVersionMigrations] Current editor version", "0.12.16");
48195
48270
  if (!this.options.ydoc) return;
48196
48271
  const metaMap = this.options.ydoc.getMap("meta");
48197
48272
  let docVersion = metaMap.get("version");
@@ -59906,7 +59981,7 @@
59906
59981
  currentPageNumber++;
59907
59982
  const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor);
59908
59983
  header = createHeader(pageMargins, pageSize, sectionData, headerId2, editor);
59909
- footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor);
59984
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId2, editor, currentPageNumber - 1);
59910
59985
  const bufferHeight2 = pageHeightThreshold - actualBreakBottom;
59911
59986
  const { node: spacingNode2 } = createFinalPagePadding(bufferHeight2);
59912
59987
  const pageSpacer2 = Decoration.widget(breakPos, spacingNode2, { key: "stable-key" });
@@ -59921,7 +59996,7 @@
59921
59996
  const headerId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
59922
59997
  const footerId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
59923
59998
  header = createHeader(pageMargins, pageSize, sectionData, headerId, editor);
59924
- footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor);
59999
+ footer = createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber);
59925
60000
  const bufferHeight = pageHeightThreshold - lastNodeCoords.bottom;
59926
60001
  const { node: spacingNode } = createFinalPagePadding(bufferHeight);
59927
60002
  const pageSpacer = Decoration.widget(doc2.content.size, spacingNode, { key: "stable-key" });
@@ -59956,6 +60031,10 @@
59956
60031
  const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
59957
60032
  const availableHeight = headerHeight - headerMargin;
59958
60033
  const editorContainer = document.createElement("div");
60034
+ if (!headerId && !editor.converter.headerIds["default"]) {
60035
+ headerId = "rId" + generateDocxRandomId();
60036
+ editor.converter.headerIds["default"] = headerId;
60037
+ }
59959
60038
  if (!editor.converter.headers[headerId]) {
59960
60039
  editor.converter.headers[headerId] = {
59961
60040
  type: "doc",
@@ -59963,24 +60042,21 @@
59963
60042
  };
59964
60043
  }
59965
60044
  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
- }
60045
+ const editorSection = createHeaderFooterEditor({
60046
+ editor,
60047
+ data,
60048
+ editorContainer,
60049
+ appendToBody: false,
60050
+ sectionId: headerId,
60051
+ type: "header",
60052
+ availableHeight
60053
+ });
60054
+ editor.converter.headerEditors.push({
60055
+ id: headerId,
60056
+ editor: editorSection
60057
+ });
60058
+ editorSection.setEditable(false, false);
60059
+ broadcastEditorEvents(editor, editorSection);
59984
60060
  editorContainer.className = "pagination-section-header";
59985
60061
  editorContainer.style.paddingTop = headerMargin + "px";
59986
60062
  editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
@@ -59999,26 +60075,40 @@
59999
60075
  const minFooterHeight = pageMargins.bottom * 96;
60000
60076
  const footerPaddingFromEdge = pageMargins.footer * 96;
60001
60077
  const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
60078
+ const sectionContainer = footerDef?.sectionContainer?.cloneNode(true);
60079
+ const autoPageNumber = sectionContainer?.querySelector('span[data-id="auto-page-number"]');
60080
+ if (autoPageNumber) {
60081
+ const fontSize2 = autoPageNumber.previousElementSibling?.style?.fontSize || autoPageNumber.nextElementSibling?.style?.fontSize;
60082
+ if (fontSize2) autoPageNumber.style.fontSize = fontSize2;
60083
+ autoPageNumber.innerText = currentPageNumber;
60084
+ }
60002
60085
  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);
60086
+ if (!footerId && !editor.converter.footerIds["default"]) {
60087
+ footerId = "rId" + generateDocxRandomId();
60088
+ editor.converter.footerIds["default"] = footerId;
60089
+ }
60090
+ if (!editor.converter.footers[footerId]) {
60091
+ editor.converter.footers[footerId] = {
60092
+ type: "doc",
60093
+ content: [{ type: "paragraph", content: [] }]
60094
+ };
60021
60095
  }
60096
+ const data = editor.converter.footers[footerId];
60097
+ const editorSection = createHeaderFooterEditor({
60098
+ editor,
60099
+ data,
60100
+ editorContainer,
60101
+ appendToBody: false,
60102
+ sectionId: footerId,
60103
+ type: "footer",
60104
+ availableHeight: footerHeight
60105
+ });
60106
+ editor.converter.footerEditors.push({
60107
+ id: footerId,
60108
+ editor: editorSection
60109
+ });
60110
+ editorSection.setEditable(false, false);
60111
+ broadcastEditorEvents(editor, editorSection);
60022
60112
  editorContainer.className = "pagination-section-footer";
60023
60113
  editorContainer.style.height = footerHeight + "px";
60024
60114
  editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
@@ -89285,7 +89375,7 @@ ${style2}
89285
89375
  this.config.colors = shuffleArray(this.config.colors);
89286
89376
  this.userColorMap = /* @__PURE__ */ new Map();
89287
89377
  this.colorIndex = 0;
89288
- this.version = "0.12.14";
89378
+ this.version = "0.12.16";
89289
89379
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
89290
89380
  this.superdocId = config.superdocId || v4();
89291
89381
  this.colors = this.config.colors;