@harbour-enterprises/superdoc 1.0.0-beta.57 → 1.0.0-beta.59

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/{PdfViewer-DvAhx37Y.cjs → PdfViewer-Cqk3l90H.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BpJ5YJmq.es.js → PdfViewer-zpn99sVp.es.js} +1 -1
  3. package/dist/chunks/{index-BbXDEDIW.cjs → index-Cjipvbt7.cjs} +3 -3
  4. package/dist/chunks/{index-BE9w4viZ.es.js → index-DjmaOC4E.es.js} +3 -3
  5. package/dist/chunks/{index-D5IkZjf9-XnnWMFi7.cjs → index-p5nUefNA-BBn8gZoL.cjs} +1 -1
  6. package/dist/chunks/{index-D5IkZjf9-CPmfOXHq.es.js → index-p5nUefNA-uQGvl206.es.js} +1 -1
  7. package/dist/chunks/{super-editor.es-BY9i51n2.es.js → super-editor.es-B_aU9Ilo.es.js} +238 -98
  8. package/dist/chunks/{super-editor.es-BjELk3Xl.cjs → super-editor.es-jT-SK1Sx.cjs} +238 -98
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-Aoe_RSZD.js → converter-CGbieO55.js} +73 -12
  11. package/dist/super-editor/chunks/{docx-zipper-Ct68kitw.js → docx-zipper-BFro6vIZ.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-Dfqm3VkC.js → editor-D4VwHdPT.js} +236 -96
  13. package/dist/super-editor/chunks/{index-D5IkZjf9.js → index-p5nUefNA.js} +1 -1
  14. package/dist/super-editor/chunks/{toolbar-Dj_HCM6i.js → toolbar-CxnmhVxL.js} +2 -2
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  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 +2 -2
  25. package/dist/superdoc.umd.js +240 -100
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -40821,6 +40821,11 @@ const createDocumentJson = (docx, converter, editor) => {
40821
40821
  const { processedNodes } = preProcessNodesForFldChar(node.elements ?? [], docx);
40822
40822
  node.elements = processedNodes;
40823
40823
  const bodySectPr = node.elements?.find((n) => n.name === "w:sectPr");
40824
+ const bodySectPrElements = bodySectPr?.elements ?? [];
40825
+ if (converter) {
40826
+ converter.importedBodyHasHeaderRef = bodySectPrElements.some((el) => el?.name === "w:headerReference");
40827
+ converter.importedBodyHasFooterRef = bodySectPrElements.some((el) => el?.name === "w:footerReference");
40828
+ }
40824
40829
  const contentElements = node.elements?.filter((n) => n.name !== "w:sectPr") ?? [];
40825
40830
  const content = pruneIgnoredNodes(contentElements);
40826
40831
  const comments = importCommentData({ docx, converter, editor });
@@ -41757,15 +41762,17 @@ function translateBodyNode(params) {
41757
41762
  }
41758
41763
  sectPr = ensureSectionLayoutDefaults(sectPr, params.converter);
41759
41764
  if (params.converter) {
41765
+ const canExportHeaderRef = params.converter.importedBodyHasHeaderRef || params.converter.headerFooterModified;
41766
+ const canExportFooterRef = params.converter.importedBodyHasFooterRef || params.converter.headerFooterModified;
41760
41767
  const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
41761
41768
  const hasDefaultHeader = params.converter.headerIds?.default;
41762
- if (!hasHeader && hasDefaultHeader && !params.editor.options.isHeaderOrFooter) {
41769
+ if (!hasHeader && hasDefaultHeader && !params.editor.options.isHeaderOrFooter && canExportHeaderRef) {
41763
41770
  const defaultHeader = generateDefaultHeaderFooter("header", params.converter.headerIds?.default);
41764
41771
  sectPr.elements.push(defaultHeader);
41765
41772
  }
41766
41773
  const hasFooter = sectPr.elements?.some((n) => n.name === "w:footerReference");
41767
41774
  const hasDefaultFooter = params.converter.footerIds?.default;
41768
- if (!hasFooter && hasDefaultFooter && !params.editor.options.isHeaderOrFooter) {
41775
+ if (!hasFooter && hasDefaultFooter && !params.editor.options.isHeaderOrFooter && canExportFooterRef) {
41769
41776
  const defaultFooter = generateDefaultHeaderFooter("footer", params.converter.footerIds?.default);
41770
41777
  sectPr.elements.push(defaultFooter);
41771
41778
  }
@@ -41971,6 +41978,42 @@ replaceSpecialCharacters_fn = function(text) {
41971
41978
  if (text === void 0 || text === null) return text;
41972
41979
  return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
41973
41980
  };
41981
+ /**
41982
+ * Recursively generates XML string representation from a JSON node structure.
41983
+ * Handles special processing for different element types to maintain Word document integrity.
41984
+ *
41985
+ * Processing behavior by element type:
41986
+ * - Text nodes (type='text'): Escapes special XML characters (&, <, >, ", ')
41987
+ * - w:instrText: Joins child text nodes and escapes special characters; preserves field instruction syntax
41988
+ * - w:t, w:delText, wp:posOffset: Removes [[sdspace]] placeholders that were added during import to preserve
41989
+ * whitespace, then escapes special characters. These placeholders are temporary markers used internally.
41990
+ * - Other elements: Recursively processes child elements
41991
+ *
41992
+ * @param {Object} node - The JSON node to convert to XML
41993
+ * @param {string} node.name - The XML element name (e.g., 'w:t', 'w:p')
41994
+ * @param {Object} [node.attributes] - Key-value pairs of XML attributes
41995
+ * @param {Array} [node.elements] - Array of child nodes to process recursively
41996
+ * @param {string} [node.type] - Node type ('text' for text nodes, 'element' for XML elements)
41997
+ * @param {string} [node.text] - The text content (only present when type='text')
41998
+ * @returns {string[]|string|null} Array of XML string fragments for elements, string for text nodes, or null for invalid nodes
41999
+ * @throws {Error} Logs error to console if text element processing fails, then continues processing
42000
+ *
42001
+ * @example
42002
+ * // Simple text element
42003
+ * const node = {
42004
+ * name: 'w:t',
42005
+ * elements: [{ type: 'text', text: 'Hello World' }]
42006
+ * };
42007
+ * // Returns: ['<w:t>', 'Hello World', '</w:t>']
42008
+ *
42009
+ * @example
42010
+ * // Element with placeholder removal
42011
+ * const node = {
42012
+ * name: 'w:t',
42013
+ * elements: [{ type: 'text', text: 'Text[[sdspace]]content' }]
42014
+ * };
42015
+ * // Returns: ['<w:t>', 'Textcontent', '</w:t>']
42016
+ */
41974
42017
  generateXml_fn = function(node) {
41975
42018
  if (!node) return null;
41976
42019
  let { name } = node;
@@ -41992,26 +42035,36 @@ generateXml_fn = function(node) {
41992
42035
  const textContent = (elements || []).map((child) => typeof child?.text === "string" ? child.text : "").join("");
41993
42036
  tags.push(__privateMethod(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, textContent));
41994
42037
  } else if (name === "w:t" || name === "w:delText" || name === "wp:posOffset") {
41995
- try {
41996
- let text = String(elements[0].text);
42038
+ if (elements.length === 0) {
42039
+ console.error(`${name} element has no child elements. Expected text node. Element will be self-closing.`);
42040
+ } else if (elements[0] == null || typeof elements[0].text !== "string") {
42041
+ console.error(
42042
+ `${name} element's first child is missing or does not have a valid text property. Received: ${JSON.stringify(elements[0])}. Pushing empty string to maintain XML structure.`
42043
+ );
42044
+ tags.push("");
42045
+ } else {
42046
+ let text = elements[0].text.replace(/\[\[sdspace\]\]/g, "");
41997
42047
  text = __privateMethod(this, _DocxExporter_instances, replaceSpecialCharacters_fn).call(this, text);
41998
42048
  tags.push(text);
41999
- } catch (error) {
42000
- console.error("Text element does not contain valid string:", error);
42001
42049
  }
42002
42050
  } else {
42003
42051
  if (elements) {
42004
42052
  for (let child of elements) {
42005
42053
  const newElements = __privateMethod(this, _DocxExporter_instances, generateXml_fn).call(this, child);
42006
- if (!newElements) continue;
42054
+ if (!newElements) {
42055
+ continue;
42056
+ }
42007
42057
  if (typeof newElements === "string") {
42008
42058
  tags.push(newElements);
42009
42059
  continue;
42010
42060
  }
42011
42061
  const removeUndefined = newElements.filter((el) => {
42012
- return el !== "<undefined>" && el !== "</undefined>";
42062
+ const isUndefined = el === "<undefined>" || el === "</undefined>";
42063
+ return !isUndefined;
42013
42064
  });
42014
- tags.push(...removeUndefined);
42065
+ for (const element of removeUndefined) {
42066
+ tags.push(element);
42067
+ }
42015
42068
  }
42016
42069
  }
42017
42070
  }
@@ -42200,7 +42253,9 @@ const getLargestRelationshipId = (relationships = []) => {
42200
42253
  return numericIds.length ? Math.max(...numericIds) : 0;
42201
42254
  };
42202
42255
  const mergeRelationshipElements = (existingRelationships = [], newRelationships = []) => {
42203
- if (!newRelationships?.length) return existingRelationships;
42256
+ if (!newRelationships?.length) {
42257
+ return existingRelationships;
42258
+ }
42204
42259
  let largestId = getLargestRelationshipId(existingRelationships);
42205
42260
  const seenIds = new Set(existingRelationships.map((rel) => rel?.attributes?.Id).filter(Boolean));
42206
42261
  for (const rel of newRelationships) {
@@ -42234,7 +42289,8 @@ const mergeRelationshipElements = (existingRelationships = [], newRelationships
42234
42289
  seenIds.add(attributes.Id);
42235
42290
  additions.push(rel);
42236
42291
  });
42237
- return additions.length ? [...existingRelationships, ...additions] : existingRelationships;
42292
+ const result = additions.length ? [...existingRelationships, ...additions] : existingRelationships;
42293
+ return result;
42238
42294
  };
42239
42295
  const FONT_FAMILY_FALLBACKS = Object.freeze({
42240
42296
  swiss: "Arial, sans-serif",
@@ -42307,6 +42363,9 @@ const _SuperConverter = class _SuperConverter {
42307
42363
  this.footers = {};
42308
42364
  this.footerIds = { default: null, even: null, odd: null, first: null };
42309
42365
  this.footerEditors = [];
42366
+ this.importedBodyHasHeaderRef = false;
42367
+ this.importedBodyHasFooterRef = false;
42368
+ this.headerFooterModified = false;
42310
42369
  this.linkedStyles = [];
42311
42370
  this.json = params?.json;
42312
42371
  this.tagsNotInSchema = ["w:body"];
@@ -42449,7 +42508,7 @@ const _SuperConverter = class _SuperConverter {
42449
42508
  static getStoredSuperdocVersion(docx) {
42450
42509
  return _SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
42451
42510
  }
42452
- static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.0.0-beta.57") {
42511
+ static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.0.0-beta.59") {
42453
42512
  return _SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version, false);
42454
42513
  }
42455
42514
  /**
@@ -42840,6 +42899,7 @@ const _SuperConverter = class _SuperConverter {
42840
42899
  if (!this.headerIds.ids.includes(rId)) {
42841
42900
  this.headerIds.ids.push(rId);
42842
42901
  }
42902
+ this.headerFooterModified = true;
42843
42903
  this.documentModified = true;
42844
42904
  return rId;
42845
42905
  }
@@ -42893,6 +42953,7 @@ const _SuperConverter = class _SuperConverter {
42893
42953
  if (!this.footerIds.ids.includes(rId)) {
42894
42954
  this.footerIds.ids.push(rId);
42895
42955
  }
42956
+ this.headerFooterModified = true;
42896
42957
  this.documentModified = true;
42897
42958
  return rId;
42898
42959
  }
@@ -1,4 +1,4 @@
1
- import { p as process$1, aJ as commonjsGlobal, B as Buffer, aK as getDefaultExportFromCjs, aL as getContentTypesFromXml, aM as xmljs } from "./converter-Aoe_RSZD.js";
1
+ import { p as process$1, aJ as commonjsGlobal, B as Buffer, aK as getDefaultExportFromCjs, aL as getContentTypesFromXml, aM as xmljs } from "./converter-CGbieO55.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
  }