@harbour-enterprises/superdoc 0.22.0-next.4 → 0.22.0-next.5

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 (28) hide show
  1. package/dist/chunks/{PdfViewer-CxIz7yf-.cjs → PdfViewer-Badqoc1e.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BBpGCmdE.es.js → PdfViewer-dsL5uHg1.es.js} +1 -1
  3. package/dist/chunks/{index-CYCctXm3.es.js → index-DBNzXf1D.es.js} +2 -2
  4. package/dist/chunks/{index-BE07bQaY.cjs → index-DVrbZM76.cjs} +2 -2
  5. package/dist/chunks/{super-editor.es-Ccu1wOj1.es.js → super-editor.es-DruRanWK.es.js} +157 -59
  6. package/dist/chunks/{super-editor.es-cZsHkhM6.cjs → super-editor.es-p3eqHXlj.cjs} +157 -59
  7. package/dist/core/types/index.d.ts.map +1 -1
  8. package/dist/super-editor/ai-writer.es.js +2 -2
  9. package/dist/super-editor/chunks/{converter-DBwwYo1I.js → converter-DujfV3Zn.js} +46 -34
  10. package/dist/super-editor/chunks/{docx-zipper-BCI-3XE9.js → docx-zipper-DccEqL60.js} +73 -12
  11. package/dist/super-editor/chunks/{editor-B2S-zXBF.js → editor-Dq3xPdti.js} +41 -16
  12. package/dist/super-editor/chunks/{toolbar-BX9nPPG0.js → toolbar-u5oyT_9K.js} +2 -2
  13. package/dist/super-editor/converter.es.js +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/file-zipper.es.js +1 -1
  17. package/dist/super-editor/src/core/DocxZipper.d.ts +1 -1
  18. package/dist/super-editor/src/core/super-converter/exporter.d.ts +1 -0
  19. package/dist/super-editor/src/extensions/custom-selection/custom-selection.d.ts +5 -0
  20. package/dist/super-editor/super-editor.es.js +6 -6
  21. package/dist/super-editor/toolbar.es.js +2 -2
  22. package/dist/super-editor.cjs +1 -1
  23. package/dist/super-editor.es.js +1 -1
  24. package/dist/superdoc.cjs +2 -2
  25. package/dist/superdoc.es.js +2 -2
  26. package/dist/superdoc.umd.js +157 -59
  27. package/dist/superdoc.umd.js.map +1 -1
  28. package/package.json +1 -1
@@ -38345,6 +38345,51 @@ Please report this to https://github.com/markedjs/marked.`, e) {
38345
38345
  gutter: "0"
38346
38346
  })
38347
38347
  });
38348
+ const ensureSectionLayoutDefaults = (sectPr, converter) => {
38349
+ if (!sectPr) {
38350
+ return {
38351
+ type: "element",
38352
+ name: "w:sectPr",
38353
+ elements: []
38354
+ };
38355
+ }
38356
+ if (!sectPr.elements) sectPr.elements = [];
38357
+ const ensureChild = (name) => {
38358
+ let child = sectPr.elements.find((n) => n.name === name);
38359
+ if (!child) {
38360
+ child = {
38361
+ type: "element",
38362
+ name,
38363
+ elements: [],
38364
+ attributes: {}
38365
+ };
38366
+ sectPr.elements.push(child);
38367
+ } else {
38368
+ if (!child.elements) child.elements = [];
38369
+ if (!child.attributes) child.attributes = {};
38370
+ }
38371
+ return child;
38372
+ };
38373
+ const pageSize = converter?.pageStyles?.pageSize;
38374
+ const pgSz = ensureChild("w:pgSz");
38375
+ if (pageSize?.width != null) pgSz.attributes["w:w"] = String(inchesToTwips(pageSize.width));
38376
+ if (pageSize?.height != null) pgSz.attributes["w:h"] = String(inchesToTwips(pageSize.height));
38377
+ if (pgSz.attributes["w:w"] == null) pgSz.attributes["w:w"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
38378
+ if (pgSz.attributes["w:h"] == null) pgSz.attributes["w:h"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
38379
+ const pageMargins = converter?.pageStyles?.pageMargins;
38380
+ const pgMar = ensureChild("w:pgMar");
38381
+ if (pageMargins) {
38382
+ Object.entries(pageMargins).forEach(([key2, value]) => {
38383
+ const converted = inchesToTwips(value);
38384
+ if (converted != null) pgMar.attributes[`w:${key2}`] = String(converted);
38385
+ });
38386
+ }
38387
+ Object.entries(DEFAULT_SECTION_PROPS_TWIPS.pageMargins).forEach(([key2, value]) => {
38388
+ const attrKey = `w:${key2}`;
38389
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
38390
+ });
38391
+ return sectPr;
38392
+ };
38348
38393
  const isLineBreakOnlyRun = (node) => {
38349
38394
  if (!node) return false;
38350
38395
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -38407,6 +38452,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
38407
38452
  } else if (!sectPr.elements) {
38408
38453
  sectPr = { ...sectPr, elements: [] };
38409
38454
  }
38455
+ sectPr = ensureSectionLayoutDefaults(sectPr, params2.converter);
38410
38456
  if (params2.converter) {
38411
38457
  const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
38412
38458
  const hasDefaultHeader = params2.converter.headerIds?.default;
@@ -38420,40 +38466,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
38420
38466
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
38421
38467
  sectPr.elements.push(defaultFooter);
38422
38468
  }
38423
- const newMargins = params2.converter.pageStyles?.pageMargins;
38424
- if (newMargins) {
38425
- let sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
38426
- if (!sectPrMargins) {
38427
- sectPrMargins = {
38428
- type: "element",
38429
- name: "w:pgMar",
38430
- attributes: {}
38431
- };
38432
- sectPr.elements.push(sectPrMargins);
38433
- } else if (!sectPrMargins.attributes) {
38434
- sectPrMargins.attributes = {};
38435
- }
38436
- Object.entries(newMargins).forEach(([key2, value]) => {
38437
- const convertedValue = inchesToTwips(value);
38438
- sectPrMargins.attributes[`w:${key2}`] = convertedValue;
38439
- });
38440
- }
38441
- let sectPrPgSz = sectPr.elements.find((n) => n.name === "w:pgSz");
38442
- if (!sectPrPgSz) {
38443
- sectPrPgSz = {
38444
- type: "element",
38445
- name: "w:pgSz",
38446
- attributes: {}
38447
- };
38448
- sectPr.elements.push(sectPrPgSz);
38449
- } else if (!sectPrPgSz.attributes) {
38450
- sectPrPgSz.attributes = {};
38451
- }
38452
- const pageSize = params2.converter.pageStyles?.pageSize;
38453
- const widthInches = pageSize?.width;
38454
- const heightInches = pageSize?.height;
38455
- sectPrPgSz.attributes["w:w"] = widthInches ? String(inchesToTwips(widthInches)) : sectPrPgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
38456
- sectPrPgSz.attributes["w:h"] = heightInches ? String(inchesToTwips(heightInches)) : sectPrPgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
38457
38469
  }
38458
38470
  const elements = translateChildNodes(params2);
38459
38471
  if (params2.isHeaderFooter) {
@@ -43982,14 +43994,19 @@ Please report this to https://github.com/markedjs/marked.`, e) {
43982
43994
  /**
43983
43995
  * Update [Content_Types].xml with extensions of new Image annotations
43984
43996
  */
43985
- async updateContentTypes(docx, media, fromJson) {
43997
+ async updateContentTypes(docx, media, fromJson, updatedDocs = {}) {
43998
+ const additionalPartNames = Object.keys(updatedDocs || {});
43986
43999
  const newMediaTypes = Object.keys(media).map((name) => {
43987
44000
  return this.getFileExtension(name);
43988
44001
  }).filter(Boolean);
43989
44002
  const contentTypesPath = "[Content_Types].xml";
43990
44003
  let contentTypesXml;
43991
44004
  if (fromJson) {
43992
- contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
44005
+ if (Array.isArray(docx.files)) {
44006
+ contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
44007
+ } else {
44008
+ contentTypesXml = docx.files?.[contentTypesPath] || "";
44009
+ }
43993
44010
  } else contentTypesXml = await docx.file(contentTypesPath).async("string");
43994
44011
  let typesString = "";
43995
44012
  const defaultMediaTypes = getContentTypesFromXml(contentTypesXml);
@@ -44015,24 +44032,39 @@ Please report this to https://github.com/markedjs/marked.`, e) {
44015
44032
  const hasCommentsExtensible = types2.elements?.some(
44016
44033
  (el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtensible.xml"
44017
44034
  );
44018
- if (docx.files["word/comments.xml"]) {
44035
+ const hasFile = (filename) => {
44036
+ if (!docx?.files) return false;
44037
+ if (!fromJson) return Boolean(docx.files[filename]);
44038
+ if (Array.isArray(docx.files)) return docx.files.some((file) => file.name === filename);
44039
+ return Boolean(docx.files[filename]);
44040
+ };
44041
+ if (hasFile("word/comments.xml")) {
44019
44042
  const commentsDef = `<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" />`;
44020
44043
  if (!hasComments) typesString += commentsDef;
44021
44044
  }
44022
- if (docx.files["word/commentsExtended.xml"]) {
44045
+ if (hasFile("word/commentsExtended.xml")) {
44023
44046
  const commentsExtendedDef = `<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml" />`;
44024
44047
  if (!hasCommentsExtended) typesString += commentsExtendedDef;
44025
44048
  }
44026
- if (docx.files["word/commentsIds.xml"]) {
44049
+ if (hasFile("word/commentsIds.xml")) {
44027
44050
  const commentsIdsDef = `<Override PartName="/word/commentsIds.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml" />`;
44028
44051
  if (!hasCommentsIds) typesString += commentsIdsDef;
44029
44052
  }
44030
- if (docx.files["word/commentsExtensible.xml"]) {
44053
+ if (hasFile("word/commentsExtensible.xml")) {
44031
44054
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
44032
44055
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
44033
44056
  }
44034
- Object.keys(docx.files).forEach((name) => {
44035
- if (name.includes(".rels") || !name.includes("header") && !name.includes("footer")) return;
44057
+ const partNames = new Set(additionalPartNames);
44058
+ if (docx?.files) {
44059
+ if (fromJson && Array.isArray(docx.files)) {
44060
+ docx.files.forEach((file) => partNames.add(file.name));
44061
+ } else {
44062
+ Object.keys(docx.files).forEach((key2) => partNames.add(key2));
44063
+ }
44064
+ }
44065
+ partNames.forEach((name) => {
44066
+ if (name.includes(".rels")) return;
44067
+ if (!name.includes("header") && !name.includes("footer")) return;
44036
44068
  const hasExtensible = types2.elements?.some(
44037
44069
  (el) => el.name === "Override" && el.attributes.PartName === `/${name}`
44038
44070
  );
@@ -44043,7 +44075,48 @@ Please report this to https://github.com/markedjs/marked.`, e) {
44043
44075
  }
44044
44076
  });
44045
44077
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
44046
- const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
44078
+ let updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
44079
+ let relationshipsXml = updatedDocs["word/_rels/document.xml.rels"];
44080
+ if (!relationshipsXml) {
44081
+ if (fromJson) {
44082
+ if (Array.isArray(docx.files)) {
44083
+ relationshipsXml = docx.files.find((file) => file.name === "word/_rels/document.xml.rels")?.content;
44084
+ } else {
44085
+ relationshipsXml = docx.files?.["word/_rels/document.xml.rels"];
44086
+ }
44087
+ } else {
44088
+ relationshipsXml = await docx.file("word/_rels/document.xml.rels")?.async("string");
44089
+ }
44090
+ }
44091
+ if (relationshipsXml) {
44092
+ try {
44093
+ const relJson = xmljs.xml2js(relationshipsXml, { compact: false });
44094
+ const relationships = relJson.elements?.find((el) => el.name === "Relationships");
44095
+ relationships?.elements?.forEach((rel) => {
44096
+ const type2 = rel.attributes?.Type;
44097
+ const target = rel.attributes?.Target;
44098
+ if (!type2 || !target) return;
44099
+ const isHeader = type2.includes("/header");
44100
+ const isFooter = type2.includes("/footer");
44101
+ if (!isHeader && !isFooter) return;
44102
+ let sanitizedTarget = target.replace(/^\.\//, "");
44103
+ if (sanitizedTarget.startsWith("../")) sanitizedTarget = sanitizedTarget.slice(3);
44104
+ if (sanitizedTarget.startsWith("/")) sanitizedTarget = sanitizedTarget.slice(1);
44105
+ const partName = sanitizedTarget.startsWith("word/") ? sanitizedTarget : `word/${sanitizedTarget}`;
44106
+ partNames.add(partName);
44107
+ });
44108
+ } catch (error) {
44109
+ console.warn("Failed to parse document relationships while updating content types", error);
44110
+ }
44111
+ }
44112
+ partNames.forEach((name) => {
44113
+ if (name.includes(".rels")) return;
44114
+ if (!name.includes("header") && !name.includes("footer")) return;
44115
+ if (updatedContentTypesXml.includes(`PartName="/${name}"`)) return;
44116
+ const type2 = name.includes("header") ? "header" : "footer";
44117
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type2}+xml"/>`;
44118
+ updatedContentTypesXml = updatedContentTypesXml.replace("</Types>", `${extendedDef}</Types>`);
44119
+ });
44047
44120
  if (fromJson) return updatedContentTypesXml;
44048
44121
  docx.file(contentTypesPath, updatedContentTypesXml);
44049
44122
  }
@@ -44084,7 +44157,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
44084
44157
  for (const [fontName, fontUintArray] of Object.entries(fonts)) {
44085
44158
  zip.file(fontName, fontUintArray);
44086
44159
  }
44087
- await this.updateContentTypes(zip, media);
44160
+ await this.updateContentTypes(zip, media, false, updatedDocs);
44088
44161
  return zip;
44089
44162
  }
44090
44163
  /**
@@ -44110,7 +44183,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
44110
44183
  Object.keys(media).forEach((path) => {
44111
44184
  unzippedOriginalDocx.file(path, media[path]);
44112
44185
  });
44113
- await this.updateContentTypes(unzippedOriginalDocx, media);
44186
+ await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs);
44114
44187
  return unzippedOriginalDocx;
44115
44188
  }
44116
44189
  }
@@ -58872,7 +58945,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
58872
58945
  files: this.options.content
58873
58946
  },
58874
58947
  media,
58875
- true
58948
+ true,
58949
+ updatedDocs
58876
58950
  );
58877
58951
  return updatedDocs;
58878
58952
  }
@@ -61431,6 +61505,16 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61431
61505
  return prefersNativeMenu(event);
61432
61506
  };
61433
61507
  const shouldBypassContextMenu = shouldAllowNativeContextMenu;
61508
+ const DEFAULT_SELECTION_STATE = Object.freeze({
61509
+ focused: false,
61510
+ preservedSelection: null,
61511
+ showVisualSelection: false,
61512
+ skipFocusReset: false
61513
+ });
61514
+ const normalizeSelectionState = (state2 = {}) => ({
61515
+ ...DEFAULT_SELECTION_STATE,
61516
+ ...state2
61517
+ });
61434
61518
  const CustomSelectionPluginKey = new PluginKey("CustomSelection");
61435
61519
  const handleClickOutside = (event, editor) => {
61436
61520
  const editorElem = editor?.options?.element;
@@ -61468,11 +61552,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61468
61552
  const customSelectionPlugin = new Plugin({
61469
61553
  key: CustomSelectionPluginKey,
61470
61554
  state: {
61471
- init: () => ({
61472
- focused: false,
61473
- preservedSelection: null,
61474
- showVisualSelection: false
61475
- }),
61555
+ init: () => ({ ...DEFAULT_SELECTION_STATE }),
61476
61556
  apply: (tr, value) => {
61477
61557
  const meta = getFocusMeta(tr);
61478
61558
  if (meta !== void 0) {
@@ -61503,7 +61583,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61503
61583
  setFocusMeta(view.state.tr, {
61504
61584
  focused: true,
61505
61585
  preservedSelection: selection,
61506
- showVisualSelection: true
61586
+ showVisualSelection: true,
61587
+ skipFocusReset: true
61507
61588
  })
61508
61589
  );
61509
61590
  }
@@ -61524,7 +61605,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61524
61605
  setFocusMeta(view.state.tr, {
61525
61606
  focused: true,
61526
61607
  preservedSelection: selection2,
61527
- showVisualSelection: true
61608
+ showVisualSelection: true,
61609
+ skipFocusReset: true
61528
61610
  })
61529
61611
  );
61530
61612
  this.editor.setOptions({
@@ -61547,7 +61629,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61547
61629
  setFocusMeta(view.state.tr, {
61548
61630
  focused: true,
61549
61631
  preservedSelection: selection,
61550
- showVisualSelection: true
61632
+ showVisualSelection: true,
61633
+ skipFocusReset: false
61551
61634
  })
61552
61635
  );
61553
61636
  this.editor.setOptions({
@@ -61565,7 +61648,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61565
61648
  setFocusMeta(view.state.tr, {
61566
61649
  focused: true,
61567
61650
  preservedSelection: selection,
61568
- showVisualSelection: true
61651
+ showVisualSelection: true,
61652
+ skipFocusReset: false
61569
61653
  })
61570
61654
  );
61571
61655
  }
@@ -61576,7 +61660,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61576
61660
  setFocusMeta(view.state.tr, {
61577
61661
  focused: false,
61578
61662
  preservedSelection: null,
61579
- showVisualSelection: false
61663
+ showVisualSelection: false,
61664
+ skipFocusReset: false
61580
61665
  })
61581
61666
  );
61582
61667
  if (!selection.empty && !this.editor.options.element?.contains(target)) {
@@ -61593,12 +61678,20 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61593
61678
  const isElement2 = target instanceof Element;
61594
61679
  const isToolbarBtn = isElement2 && isToolbarButton(target);
61595
61680
  const isToolbarInp = isElement2 && isToolbarInput(target);
61681
+ const focusState = getFocusState(view.state);
61682
+ if (focusState?.skipFocusReset) {
61683
+ view.dispatch(
61684
+ setFocusMeta(view.state.tr, normalizeSelectionState({ ...focusState, skipFocusReset: false }))
61685
+ );
61686
+ return false;
61687
+ }
61596
61688
  if (!isToolbarBtn && !isToolbarInp) {
61597
61689
  view.dispatch(
61598
61690
  setFocusMeta(view.state.tr, {
61599
61691
  focused: false,
61600
61692
  preservedSelection: null,
61601
- showVisualSelection: false
61693
+ showVisualSelection: false,
61694
+ skipFocusReset: false
61602
61695
  })
61603
61696
  );
61604
61697
  }
@@ -61609,12 +61702,16 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61609
61702
  const isToolbarBtn = isElement2 && isToolbarButton(target);
61610
61703
  const isToolbarInp = isElement2 && isToolbarInput(target);
61611
61704
  const state2 = getFocusState(view.state);
61705
+ if (state2?.skipFocusReset) {
61706
+ return false;
61707
+ }
61612
61708
  if (isToolbarBtn || isToolbarInp) {
61613
61709
  view.dispatch(
61614
61710
  setFocusMeta(view.state.tr, {
61615
61711
  focused: true,
61616
61712
  preservedSelection: state2.preservedSelection || view.state.selection,
61617
- showVisualSelection: true
61713
+ showVisualSelection: true,
61714
+ skipFocusReset: false
61618
61715
  })
61619
61716
  );
61620
61717
  } else {
@@ -61622,7 +61719,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61622
61719
  setFocusMeta(view.state.tr, {
61623
61720
  focused: false,
61624
61721
  preservedSelection: null,
61625
- showVisualSelection: false
61722
+ showVisualSelection: false,
61723
+ skipFocusReset: false
61626
61724
  })
61627
61725
  );
61628
61726
  }