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

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 (29) hide show
  1. package/dist/chunks/{PdfViewer-BBpGCmdE.es.js → PdfViewer-BMfm6DSP.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-CxIz7yf-.cjs → PdfViewer-XMDxj-2m.cjs} +1 -1
  3. package/dist/chunks/{index-BE07bQaY.cjs → index-BlNiELtW.cjs} +2 -2
  4. package/dist/chunks/{index-CYCctXm3.es.js → index-Cvi1utmk.es.js} +2 -2
  5. package/dist/chunks/{super-editor.es-cZsHkhM6.cjs → super-editor.es-BDsfLrnI.cjs} +247 -61
  6. package/dist/chunks/{super-editor.es-Ccu1wOj1.es.js → super-editor.es-CmQ5GChv.es.js} +247 -61
  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-D9kK7Smo.js} +136 -36
  10. package/dist/super-editor/chunks/{docx-zipper-BCI-3XE9.js → docx-zipper-D8HnWWpv.js} +73 -12
  11. package/dist/super-editor/chunks/{editor-B2S-zXBF.js → editor-Ddkz97dH.js} +41 -16
  12. package/dist/super-editor/chunks/{toolbar-BX9nPPG0.js → toolbar-BxjdbiUf.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/core/super-converter/helpers/tableFallbackHelpers.d.ts +24 -0
  20. package/dist/super-editor/src/extensions/custom-selection/custom-selection.d.ts +5 -0
  21. package/dist/super-editor/super-editor.es.js +6 -6
  22. package/dist/super-editor/toolbar.es.js +2 -2
  23. package/dist/super-editor.cjs +1 -1
  24. package/dist/super-editor.es.js +1 -1
  25. package/dist/superdoc.cjs +2 -2
  26. package/dist/superdoc.es.js +2 -2
  27. package/dist/superdoc.umd.js +247 -61
  28. package/dist/superdoc.umd.js.map +1 -1
  29. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { m as defineComponent, B as h, O as Transition, $ as process$1, I as watchEffect, d as computed, r as ref, j as onMounted, W as onUnmounted, c as createElementBlock, o as openBlock, a as createBaseVNode, f as createCommentVNode, v as createVNode, x as unref } from "./vue-CXxsqYcP.es.js";
2
- import { d as derived, c, a as cB, f as fadeInTransition, b as cM, N as NBaseLoading, w as warnOnce, u as useConfig, e as useTheme, p as pxfy, g as createKey, h as useThemeClass, i as useCompitable, _ as _export_sfc, j as useSuperdocStore, s as storeToRefs, k as useSelection } from "./index-CYCctXm3.es.js";
2
+ import { d as derived, c, a as cB, f as fadeInTransition, b as cM, N as NBaseLoading, w as warnOnce, u as useConfig, e as useTheme, p as pxfy, g as createKey, h as useThemeClass, i as useCompitable, _ as _export_sfc, j as useSuperdocStore, s as storeToRefs, k as useSelection } from "./index-Cvi1utmk.es.js";
3
3
  function self(vars) {
4
4
  const {
5
5
  opacityDisabled,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const vue = require("./vue-DWle4Cai.cjs");
4
- const superdoc = require("./index-BE07bQaY.cjs");
4
+ const superdoc = require("./index-BlNiELtW.cjs");
5
5
  function self(vars) {
6
6
  const {
7
7
  opacityDisabled,
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const superEditor_es = require("./super-editor.es-cZsHkhM6.cjs");
2
+ const superEditor_es = require("./super-editor.es-BDsfLrnI.cjs");
3
3
  const vue = require("./vue-DWle4Cai.cjs");
4
4
  const jszip = require("./jszip-b7l8QkfH.cjs");
5
5
  const blankDocx = require("./blank-docx-CPqX9RF5.cjs");
@@ -17409,7 +17409,7 @@ const _sfc_main = {
17409
17409
  __name: "SuperDoc",
17410
17410
  emits: ["selection-update"],
17411
17411
  setup(__props, { emit: __emit }) {
17412
- const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-CxIz7yf-.cjs")));
17412
+ const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-XMDxj-2m.cjs")));
17413
17413
  const superdocStore = useSuperdocStore();
17414
17414
  const commentsStore = useCommentsStore();
17415
17415
  const {
@@ -1,4 +1,4 @@
1
- import { q as index$1, C as CommentsPluginKey, h as TrackChangesBasePluginKey, E as Editor, n as getRichTextExtensions, f as SuperInput, e as SuperEditor, A as AIWriter, g as SuperToolbar, i as createZip } from "./super-editor.es-Ccu1wOj1.es.js";
1
+ import { q as index$1, C as CommentsPluginKey, h as TrackChangesBasePluginKey, E as Editor, n as getRichTextExtensions, f as SuperInput, e as SuperEditor, A as AIWriter, g as SuperToolbar, i as createZip } from "./super-editor.es-CmQ5GChv.es.js";
2
2
  import { a0 as effectScope, r as ref, _ as markRaw, $ as process$1, a1 as toRaw, d as computed, a2 as isRef, a3 as isReactive, C as toRef, i as inject, p as getCurrentInstance, l as watch, x as unref, a4 as hasInjectionContext, M as reactive, s as nextTick, a5 as getCurrentScope, a6 as onScopeDispose, a7 as toRefs, g as global$1, J as shallowRef, N as readonly, j as onMounted, k as onBeforeUnmount, h as onBeforeMount, S as onActivated, q as onDeactivated, z as createTextVNode, F as Fragment, Q as Comment, m as defineComponent, D as provide, H as withDirectives, B as h, U as Teleport, R as renderSlot, V as isVNode, I as watchEffect, O as Transition, a8 as TransitionGroup, E as mergeProps, P as vShow, G as cloneVNode, T as Text, c as createElementBlock, o as openBlock, t as toDisplayString, v as createVNode, y as withCtx, a as createBaseVNode, A as normalizeStyle, f as createCommentVNode, u as createBlock, w as withModifiers, n as normalizeClass, a9 as resolveDirective, e as renderList, b as createApp, X as resolveDynamicComponent, aa as defineAsyncComponent } from "./vue-CXxsqYcP.es.js";
3
3
  import { B as Buffer$2 } from "./jszip-B8KIZSNe.es.js";
4
4
  import { B as BlankDOCX } from "./blank-docx-iwdyG9RH.es.js";
@@ -17392,7 +17392,7 @@ const _sfc_main = {
17392
17392
  __name: "SuperDoc",
17393
17393
  emits: ["selection-update"],
17394
17394
  setup(__props, { emit: __emit }) {
17395
- const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-BBpGCmdE.es.js"));
17395
+ const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-BMfm6DSP.es.js"));
17396
17396
  const superdocStore = useSuperdocStore();
17397
17397
  const commentsStore = useCommentsStore();
17398
17398
  const {
@@ -27177,6 +27177,68 @@ const config$a = {
27177
27177
  decode: decode$h
27178
27178
  };
27179
27179
  const translator$a = NodeTranslator.from(config$a);
27180
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27181
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27182
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27183
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27184
+ const pctToPercent = (value) => {
27185
+ if (value == null) return null;
27186
+ return value / 50;
27187
+ };
27188
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27189
+ const resolveMeasurementWidthPx = (measurement) => {
27190
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27191
+ const { value, type: type2 } = measurement;
27192
+ if (!type2 || type2 === "auto") return null;
27193
+ if (type2 === "dxa") return twipsToPixels(value);
27194
+ if (type2 === "pct") {
27195
+ const percent2 = pctToPercent(value);
27196
+ if (percent2 == null || percent2 <= 0) return null;
27197
+ const widthTwips = resolveContentWidthTwips() * percent2 / 100;
27198
+ return twipsToPixels(widthTwips);
27199
+ }
27200
+ return null;
27201
+ };
27202
+ const countColumnsInRow = (row) => {
27203
+ if (!row?.elements?.length) return 0;
27204
+ return row.elements.reduce((count, element) => {
27205
+ if (element.name !== "w:tc") return count;
27206
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
27207
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27208
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27209
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27210
+ }, 0);
27211
+ };
27212
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27213
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27214
+ const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
27215
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
27216
+ const columnCount = countColumnsInRow(firstRow);
27217
+ if (!columnCount) return null;
27218
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
27219
+ /** @type {any} */
27220
+ params2
27221
+ );
27222
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
27223
+ let totalWidthPx;
27224
+ if (tableWidthMeasurement) {
27225
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27226
+ if (resolved != null) totalWidthPx = resolved;
27227
+ }
27228
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
27229
+ totalWidthPx = tableWidth.width;
27230
+ }
27231
+ if (totalWidthPx == null) {
27232
+ totalWidthPx = minimumColumnWidthPx * columnCount;
27233
+ }
27234
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
27235
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
27236
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27237
+ return {
27238
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
27239
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27240
+ };
27241
+ };
27180
27242
  const XML_NODE_NAME$9 = "w:tbl";
27181
27243
  const SD_NODE_NAME$9 = "table";
27182
27244
  const encode$g = (params2, encodedAttrs) => {
@@ -27196,7 +27258,6 @@ const encode$g = (params2, encodedAttrs) => {
27196
27258
  "justification",
27197
27259
  "tableLayout",
27198
27260
  ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27199
- ["tableWidth", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27200
27261
  ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
27201
27262
  ].forEach((prop) => {
27202
27263
  let key2;
@@ -27214,6 +27275,21 @@ const encode$g = (params2, encodedAttrs) => {
27214
27275
  if (encodedAttrs.tableCellSpacing) {
27215
27276
  encodedAttrs["borderCollapse"] = "separate";
27216
27277
  }
27278
+ if (encodedAttrs.tableProperties?.tableWidth) {
27279
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
27280
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
27281
+ if (widthPx != null) {
27282
+ encodedAttrs.tableWidth = {
27283
+ width: widthPx,
27284
+ type: tableWidthMeasurement.type
27285
+ };
27286
+ } else if (tableWidthMeasurement.type === "auto") {
27287
+ encodedAttrs.tableWidth = {
27288
+ width: 0,
27289
+ type: tableWidthMeasurement.type
27290
+ };
27291
+ }
27292
+ }
27217
27293
  const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
27218
27294
  const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
27219
27295
  if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
@@ -27227,7 +27303,19 @@ const encode$g = (params2, encodedAttrs) => {
27227
27303
  const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
27228
27304
  encodedAttrs["borders"] = borderData;
27229
27305
  const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
27230
- const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
27306
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
27307
+ if (!columnWidths.length) {
27308
+ const fallback = buildFallbackGridForTable({
27309
+ params: params2,
27310
+ rows,
27311
+ tableWidth: encodedAttrs.tableWidth,
27312
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
27313
+ });
27314
+ if (fallback) {
27315
+ encodedAttrs.grid = fallback.grid;
27316
+ columnWidths = fallback.columnWidths;
27317
+ }
27318
+ }
27231
27319
  const content = [];
27232
27320
  rows.forEach((row) => {
27233
27321
  const result = translator$G.encode({
@@ -30620,6 +30708,51 @@ const DEFAULT_SECTION_PROPS_TWIPS = Object.freeze({
30620
30708
  gutter: "0"
30621
30709
  })
30622
30710
  });
30711
+ const ensureSectionLayoutDefaults = (sectPr, converter) => {
30712
+ if (!sectPr) {
30713
+ return {
30714
+ type: "element",
30715
+ name: "w:sectPr",
30716
+ elements: []
30717
+ };
30718
+ }
30719
+ if (!sectPr.elements) sectPr.elements = [];
30720
+ const ensureChild = (name) => {
30721
+ let child = sectPr.elements.find((n) => n.name === name);
30722
+ if (!child) {
30723
+ child = {
30724
+ type: "element",
30725
+ name,
30726
+ elements: [],
30727
+ attributes: {}
30728
+ };
30729
+ sectPr.elements.push(child);
30730
+ } else {
30731
+ if (!child.elements) child.elements = [];
30732
+ if (!child.attributes) child.attributes = {};
30733
+ }
30734
+ return child;
30735
+ };
30736
+ const pageSize = converter?.pageStyles?.pageSize;
30737
+ const pgSz = ensureChild("w:pgSz");
30738
+ if (pageSize?.width != null) pgSz.attributes["w:w"] = String(inchesToTwips(pageSize.width));
30739
+ if (pageSize?.height != null) pgSz.attributes["w:h"] = String(inchesToTwips(pageSize.height));
30740
+ if (pgSz.attributes["w:w"] == null) pgSz.attributes["w:w"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30741
+ if (pgSz.attributes["w:h"] == null) pgSz.attributes["w:h"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30742
+ const pageMargins = converter?.pageStyles?.pageMargins;
30743
+ const pgMar = ensureChild("w:pgMar");
30744
+ if (pageMargins) {
30745
+ Object.entries(pageMargins).forEach(([key2, value]) => {
30746
+ const converted = inchesToTwips(value);
30747
+ if (converted != null) pgMar.attributes[`w:${key2}`] = String(converted);
30748
+ });
30749
+ }
30750
+ Object.entries(DEFAULT_SECTION_PROPS_TWIPS.pageMargins).forEach(([key2, value]) => {
30751
+ const attrKey = `w:${key2}`;
30752
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
30753
+ });
30754
+ return sectPr;
30755
+ };
30623
30756
  const isLineBreakOnlyRun = (node) => {
30624
30757
  if (!node) return false;
30625
30758
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -30682,6 +30815,7 @@ function translateBodyNode(params2) {
30682
30815
  } else if (!sectPr.elements) {
30683
30816
  sectPr = { ...sectPr, elements: [] };
30684
30817
  }
30818
+ sectPr = ensureSectionLayoutDefaults(sectPr, params2.converter);
30685
30819
  if (params2.converter) {
30686
30820
  const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
30687
30821
  const hasDefaultHeader = params2.converter.headerIds?.default;
@@ -30695,40 +30829,6 @@ function translateBodyNode(params2) {
30695
30829
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
30696
30830
  sectPr.elements.push(defaultFooter);
30697
30831
  }
30698
- const newMargins = params2.converter.pageStyles?.pageMargins;
30699
- if (newMargins) {
30700
- let sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
30701
- if (!sectPrMargins) {
30702
- sectPrMargins = {
30703
- type: "element",
30704
- name: "w:pgMar",
30705
- attributes: {}
30706
- };
30707
- sectPr.elements.push(sectPrMargins);
30708
- } else if (!sectPrMargins.attributes) {
30709
- sectPrMargins.attributes = {};
30710
- }
30711
- Object.entries(newMargins).forEach(([key2, value]) => {
30712
- const convertedValue = inchesToTwips(value);
30713
- sectPrMargins.attributes[`w:${key2}`] = convertedValue;
30714
- });
30715
- }
30716
- let sectPrPgSz = sectPr.elements.find((n) => n.name === "w:pgSz");
30717
- if (!sectPrPgSz) {
30718
- sectPrPgSz = {
30719
- type: "element",
30720
- name: "w:pgSz",
30721
- attributes: {}
30722
- };
30723
- sectPr.elements.push(sectPrPgSz);
30724
- } else if (!sectPrPgSz.attributes) {
30725
- sectPrPgSz.attributes = {};
30726
- }
30727
- const pageSize = params2.converter.pageStyles?.pageSize;
30728
- const widthInches = pageSize?.width;
30729
- const heightInches = pageSize?.height;
30730
- sectPrPgSz.attributes["w:w"] = widthInches ? String(inchesToTwips(widthInches)) : sectPrPgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30731
- sectPrPgSz.attributes["w:h"] = heightInches ? String(inchesToTwips(heightInches)) : sectPrPgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30732
30832
  }
30733
30833
  const elements = translateChildNodes(params2);
30734
30834
  if (params2.isHeaderFooter) {
@@ -36284,14 +36384,19 @@ class DocxZipper {
36284
36384
  /**
36285
36385
  * Update [Content_Types].xml with extensions of new Image annotations
36286
36386
  */
36287
- async updateContentTypes(docx, media, fromJson) {
36387
+ async updateContentTypes(docx, media, fromJson, updatedDocs = {}) {
36388
+ const additionalPartNames = Object.keys(updatedDocs || {});
36288
36389
  const newMediaTypes = Object.keys(media).map((name) => {
36289
36390
  return this.getFileExtension(name);
36290
36391
  }).filter(Boolean);
36291
36392
  const contentTypesPath = "[Content_Types].xml";
36292
36393
  let contentTypesXml;
36293
36394
  if (fromJson) {
36294
- contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
36395
+ if (Array.isArray(docx.files)) {
36396
+ contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
36397
+ } else {
36398
+ contentTypesXml = docx.files?.[contentTypesPath] || "";
36399
+ }
36295
36400
  } else contentTypesXml = await docx.file(contentTypesPath).async("string");
36296
36401
  let typesString = "";
36297
36402
  const defaultMediaTypes = getContentTypesFromXml(contentTypesXml);
@@ -36317,24 +36422,39 @@ class DocxZipper {
36317
36422
  const hasCommentsExtensible = types2.elements?.some(
36318
36423
  (el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtensible.xml"
36319
36424
  );
36320
- if (docx.files["word/comments.xml"]) {
36425
+ const hasFile = (filename) => {
36426
+ if (!docx?.files) return false;
36427
+ if (!fromJson) return Boolean(docx.files[filename]);
36428
+ if (Array.isArray(docx.files)) return docx.files.some((file) => file.name === filename);
36429
+ return Boolean(docx.files[filename]);
36430
+ };
36431
+ if (hasFile("word/comments.xml")) {
36321
36432
  const commentsDef = `<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" />`;
36322
36433
  if (!hasComments) typesString += commentsDef;
36323
36434
  }
36324
- if (docx.files["word/commentsExtended.xml"]) {
36435
+ if (hasFile("word/commentsExtended.xml")) {
36325
36436
  const commentsExtendedDef = `<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml" />`;
36326
36437
  if (!hasCommentsExtended) typesString += commentsExtendedDef;
36327
36438
  }
36328
- if (docx.files["word/commentsIds.xml"]) {
36439
+ if (hasFile("word/commentsIds.xml")) {
36329
36440
  const commentsIdsDef = `<Override PartName="/word/commentsIds.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml" />`;
36330
36441
  if (!hasCommentsIds) typesString += commentsIdsDef;
36331
36442
  }
36332
- if (docx.files["word/commentsExtensible.xml"]) {
36443
+ if (hasFile("word/commentsExtensible.xml")) {
36333
36444
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
36334
36445
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
36335
36446
  }
36336
- Object.keys(docx.files).forEach((name) => {
36337
- if (name.includes(".rels") || !name.includes("header") && !name.includes("footer")) return;
36447
+ const partNames = new Set(additionalPartNames);
36448
+ if (docx?.files) {
36449
+ if (fromJson && Array.isArray(docx.files)) {
36450
+ docx.files.forEach((file) => partNames.add(file.name));
36451
+ } else {
36452
+ Object.keys(docx.files).forEach((key2) => partNames.add(key2));
36453
+ }
36454
+ }
36455
+ partNames.forEach((name) => {
36456
+ if (name.includes(".rels")) return;
36457
+ if (!name.includes("header") && !name.includes("footer")) return;
36338
36458
  const hasExtensible = types2.elements?.some(
36339
36459
  (el) => el.name === "Override" && el.attributes.PartName === `/${name}`
36340
36460
  );
@@ -36345,7 +36465,48 @@ class DocxZipper {
36345
36465
  }
36346
36466
  });
36347
36467
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
36348
- const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
36468
+ let updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
36469
+ let relationshipsXml = updatedDocs["word/_rels/document.xml.rels"];
36470
+ if (!relationshipsXml) {
36471
+ if (fromJson) {
36472
+ if (Array.isArray(docx.files)) {
36473
+ relationshipsXml = docx.files.find((file) => file.name === "word/_rels/document.xml.rels")?.content;
36474
+ } else {
36475
+ relationshipsXml = docx.files?.["word/_rels/document.xml.rels"];
36476
+ }
36477
+ } else {
36478
+ relationshipsXml = await docx.file("word/_rels/document.xml.rels")?.async("string");
36479
+ }
36480
+ }
36481
+ if (relationshipsXml) {
36482
+ try {
36483
+ const relJson = xmljs.xml2js(relationshipsXml, { compact: false });
36484
+ const relationships = relJson.elements?.find((el) => el.name === "Relationships");
36485
+ relationships?.elements?.forEach((rel) => {
36486
+ const type2 = rel.attributes?.Type;
36487
+ const target = rel.attributes?.Target;
36488
+ if (!type2 || !target) return;
36489
+ const isHeader = type2.includes("/header");
36490
+ const isFooter = type2.includes("/footer");
36491
+ if (!isHeader && !isFooter) return;
36492
+ let sanitizedTarget = target.replace(/^\.\//, "");
36493
+ if (sanitizedTarget.startsWith("../")) sanitizedTarget = sanitizedTarget.slice(3);
36494
+ if (sanitizedTarget.startsWith("/")) sanitizedTarget = sanitizedTarget.slice(1);
36495
+ const partName = sanitizedTarget.startsWith("word/") ? sanitizedTarget : `word/${sanitizedTarget}`;
36496
+ partNames.add(partName);
36497
+ });
36498
+ } catch (error) {
36499
+ console.warn("Failed to parse document relationships while updating content types", error);
36500
+ }
36501
+ }
36502
+ partNames.forEach((name) => {
36503
+ if (name.includes(".rels")) return;
36504
+ if (!name.includes("header") && !name.includes("footer")) return;
36505
+ if (updatedContentTypesXml.includes(`PartName="/${name}"`)) return;
36506
+ const type2 = name.includes("header") ? "header" : "footer";
36507
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type2}+xml"/>`;
36508
+ updatedContentTypesXml = updatedContentTypesXml.replace("</Types>", `${extendedDef}</Types>`);
36509
+ });
36349
36510
  if (fromJson) return updatedContentTypesXml;
36350
36511
  docx.file(contentTypesPath, updatedContentTypesXml);
36351
36512
  }
@@ -36386,7 +36547,7 @@ class DocxZipper {
36386
36547
  for (const [fontName, fontUintArray] of Object.entries(fonts)) {
36387
36548
  zip.file(fontName, fontUintArray);
36388
36549
  }
36389
- await this.updateContentTypes(zip, media);
36550
+ await this.updateContentTypes(zip, media, false, updatedDocs);
36390
36551
  return zip;
36391
36552
  }
36392
36553
  /**
@@ -36412,7 +36573,7 @@ class DocxZipper {
36412
36573
  Object.keys(media).forEach((path) => {
36413
36574
  unzippedOriginalDocx.file(path, media[path]);
36414
36575
  });
36415
- await this.updateContentTypes(unzippedOriginalDocx, media);
36576
+ await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs);
36416
36577
  return unzippedOriginalDocx;
36417
36578
  }
36418
36579
  }
@@ -51174,7 +51335,8 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
51174
51335
  files: this.options.content
51175
51336
  },
51176
51337
  media,
51177
- true
51338
+ true,
51339
+ updatedDocs
51178
51340
  );
51179
51341
  return updatedDocs;
51180
51342
  }
@@ -53733,6 +53895,16 @@ const shouldAllowNativeContextMenu = (event) => {
53733
53895
  return prefersNativeMenu(event);
53734
53896
  };
53735
53897
  const shouldBypassContextMenu = shouldAllowNativeContextMenu;
53898
+ const DEFAULT_SELECTION_STATE = Object.freeze({
53899
+ focused: false,
53900
+ preservedSelection: null,
53901
+ showVisualSelection: false,
53902
+ skipFocusReset: false
53903
+ });
53904
+ const normalizeSelectionState = (state2 = {}) => ({
53905
+ ...DEFAULT_SELECTION_STATE,
53906
+ ...state2
53907
+ });
53736
53908
  const CustomSelectionPluginKey = new PluginKey("CustomSelection");
53737
53909
  const handleClickOutside = (event, editor) => {
53738
53910
  const editorElem = editor?.options?.element;
@@ -53770,11 +53942,7 @@ const CustomSelection = Extension.create({
53770
53942
  const customSelectionPlugin = new Plugin({
53771
53943
  key: CustomSelectionPluginKey,
53772
53944
  state: {
53773
- init: () => ({
53774
- focused: false,
53775
- preservedSelection: null,
53776
- showVisualSelection: false
53777
- }),
53945
+ init: () => ({ ...DEFAULT_SELECTION_STATE }),
53778
53946
  apply: (tr, value) => {
53779
53947
  const meta = getFocusMeta(tr);
53780
53948
  if (meta !== void 0) {
@@ -53805,7 +53973,8 @@ const CustomSelection = Extension.create({
53805
53973
  setFocusMeta(view.state.tr, {
53806
53974
  focused: true,
53807
53975
  preservedSelection: selection,
53808
- showVisualSelection: true
53976
+ showVisualSelection: true,
53977
+ skipFocusReset: true
53809
53978
  })
53810
53979
  );
53811
53980
  }
@@ -53826,7 +53995,8 @@ const CustomSelection = Extension.create({
53826
53995
  setFocusMeta(view.state.tr, {
53827
53996
  focused: true,
53828
53997
  preservedSelection: selection2,
53829
- showVisualSelection: true
53998
+ showVisualSelection: true,
53999
+ skipFocusReset: true
53830
54000
  })
53831
54001
  );
53832
54002
  this.editor.setOptions({
@@ -53849,7 +54019,8 @@ const CustomSelection = Extension.create({
53849
54019
  setFocusMeta(view.state.tr, {
53850
54020
  focused: true,
53851
54021
  preservedSelection: selection,
53852
- showVisualSelection: true
54022
+ showVisualSelection: true,
54023
+ skipFocusReset: false
53853
54024
  })
53854
54025
  );
53855
54026
  this.editor.setOptions({
@@ -53867,7 +54038,8 @@ const CustomSelection = Extension.create({
53867
54038
  setFocusMeta(view.state.tr, {
53868
54039
  focused: true,
53869
54040
  preservedSelection: selection,
53870
- showVisualSelection: true
54041
+ showVisualSelection: true,
54042
+ skipFocusReset: false
53871
54043
  })
53872
54044
  );
53873
54045
  }
@@ -53878,7 +54050,8 @@ const CustomSelection = Extension.create({
53878
54050
  setFocusMeta(view.state.tr, {
53879
54051
  focused: false,
53880
54052
  preservedSelection: null,
53881
- showVisualSelection: false
54053
+ showVisualSelection: false,
54054
+ skipFocusReset: false
53882
54055
  })
53883
54056
  );
53884
54057
  if (!selection.empty && !this.editor.options.element?.contains(target)) {
@@ -53895,12 +54068,20 @@ const CustomSelection = Extension.create({
53895
54068
  const isElement2 = target instanceof Element;
53896
54069
  const isToolbarBtn = isElement2 && isToolbarButton(target);
53897
54070
  const isToolbarInp = isElement2 && isToolbarInput(target);
54071
+ const focusState = getFocusState(view.state);
54072
+ if (focusState?.skipFocusReset) {
54073
+ view.dispatch(
54074
+ setFocusMeta(view.state.tr, normalizeSelectionState({ ...focusState, skipFocusReset: false }))
54075
+ );
54076
+ return false;
54077
+ }
53898
54078
  if (!isToolbarBtn && !isToolbarInp) {
53899
54079
  view.dispatch(
53900
54080
  setFocusMeta(view.state.tr, {
53901
54081
  focused: false,
53902
54082
  preservedSelection: null,
53903
- showVisualSelection: false
54083
+ showVisualSelection: false,
54084
+ skipFocusReset: false
53904
54085
  })
53905
54086
  );
53906
54087
  }
@@ -53911,12 +54092,16 @@ const CustomSelection = Extension.create({
53911
54092
  const isToolbarBtn = isElement2 && isToolbarButton(target);
53912
54093
  const isToolbarInp = isElement2 && isToolbarInput(target);
53913
54094
  const state2 = getFocusState(view.state);
54095
+ if (state2?.skipFocusReset) {
54096
+ return false;
54097
+ }
53914
54098
  if (isToolbarBtn || isToolbarInp) {
53915
54099
  view.dispatch(
53916
54100
  setFocusMeta(view.state.tr, {
53917
54101
  focused: true,
53918
54102
  preservedSelection: state2.preservedSelection || view.state.selection,
53919
- showVisualSelection: true
54103
+ showVisualSelection: true,
54104
+ skipFocusReset: false
53920
54105
  })
53921
54106
  );
53922
54107
  } else {
@@ -53924,7 +54109,8 @@ const CustomSelection = Extension.create({
53924
54109
  setFocusMeta(view.state.tr, {
53925
54110
  focused: false,
53926
54111
  preservedSelection: null,
53927
- showVisualSelection: false
54112
+ showVisualSelection: false,
54113
+ skipFocusReset: false
53928
54114
  })
53929
54115
  );
53930
54116
  }