@harbour-enterprises/superdoc 0.21.0-next.8 → 0.21.1

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 (35) hide show
  1. package/dist/chunks/{PdfViewer-BR9iwva-.cjs → PdfViewer-B507M2sz.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-CwVW7MVJ.es.js → PdfViewer-DCKxnML6.es.js} +1 -1
  3. package/dist/chunks/{index-CjQDYBP2.es.js → index-DWR8syta.es.js} +40 -20
  4. package/dist/chunks/{index-BNA5J__D.cjs → index-djqw1MEc.cjs} +40 -20
  5. package/dist/chunks/{super-editor.es-C5dhT0uU.es.js → super-editor.es-D__G4K0i.es.js} +429 -115
  6. package/dist/chunks/{super-editor.es-Ct59l8tt.cjs → super-editor.es-HekVJogH.cjs} +429 -115
  7. package/dist/core/SuperDoc.d.ts +5 -0
  8. package/dist/core/SuperDoc.d.ts.map +1 -1
  9. package/dist/core/types/index.d.ts +4 -4
  10. package/dist/core/types/index.d.ts.map +1 -1
  11. package/dist/super-editor/ai-writer.es.js +2 -2
  12. package/dist/super-editor/chunks/{converter-DYAHhSrg.js → converter-B_pO-5Ls.js} +291 -67
  13. package/dist/super-editor/chunks/{docx-zipper-BDbCmfbE.js → docx-zipper-WaO3WaIz.js} +73 -12
  14. package/dist/super-editor/chunks/{editor-B1W7AdgQ.js → editor-DInvq7gF.js} +68 -30
  15. package/dist/super-editor/chunks/{toolbar-CCvglB_X.js → toolbar-C15EomPB.js} +2 -2
  16. package/dist/super-editor/converter.es.js +1 -1
  17. package/dist/super-editor/docx-zipper.es.js +2 -2
  18. package/dist/super-editor/editor.es.js +3 -3
  19. package/dist/super-editor/file-zipper.es.js +1 -1
  20. package/dist/super-editor/src/core/DocxZipper.d.ts +1 -1
  21. package/dist/super-editor/src/core/super-converter/SuperConverter.d.ts +1 -13
  22. package/dist/super-editor/src/core/super-converter/exporter.d.ts +1 -0
  23. package/dist/super-editor/src/core/super-converter/helpers/tableFallbackHelpers.d.ts +24 -0
  24. package/dist/super-editor/src/extensions/custom-selection/custom-selection.d.ts +5 -1
  25. package/dist/super-editor/src/utils/contextmenu-helpers.d.ts +24 -0
  26. package/dist/super-editor/super-editor.es.js +7 -15
  27. package/dist/super-editor/toolbar.es.js +2 -2
  28. package/dist/super-editor.cjs +1 -1
  29. package/dist/super-editor.es.js +1 -1
  30. package/dist/superdoc.cjs +2 -2
  31. package/dist/superdoc.es.js +2 -2
  32. package/dist/superdoc.umd.js +467 -133
  33. package/dist/superdoc.umd.js.map +1 -1
  34. package/package.json +2 -5
  35. package/dist/super-editor/src/components/slash-menu/contextmenu-helpers.d.ts +0 -1
@@ -24839,17 +24839,16 @@ const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {})
24839
24839
  };
24840
24840
  const getDefaultParagraphStyle = (docx, styleId = "") => {
24841
24841
  const styles = docx["word/styles.xml"];
24842
- if (!styles) {
24842
+ const rootElements = styles?.elements?.[0]?.elements;
24843
+ if (!rootElements?.length) {
24843
24844
  return {};
24844
24845
  }
24845
- const defaults = styles.elements[0].elements?.find((el) => el.name === "w:docDefaults");
24846
- const pDefault = defaults.elements.find((el) => el.name === "w:pPrDefault");
24846
+ const defaults = rootElements.find((el) => el.name === "w:docDefaults");
24847
+ const pDefault = defaults?.elements?.find((el) => el.name === "w:pPrDefault") || {};
24847
24848
  const pPrDefault = pDefault?.elements?.find((el) => el.name === "w:pPr");
24848
24849
  const pPrDefaultSpacingTag = pPrDefault?.elements?.find((el) => el.name === "w:spacing") || {};
24849
24850
  const pPrDefaultIndentTag = pPrDefault?.elements?.find((el) => el.name === "w:ind") || {};
24850
- const stylesNormal = styles.elements[0].elements?.find(
24851
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal"
24852
- );
24851
+ const stylesNormal = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal");
24853
24852
  const pPrNormal = stylesNormal?.elements?.find((el) => el.name === "w:pPr");
24854
24853
  const pPrNormalSpacingTag = pPrNormal?.elements?.find((el) => el.name === "w:spacing") || {};
24855
24854
  const pPrNormalIndentTag = pPrNormal?.elements?.find((el) => el.name === "w:ind") || {};
@@ -24858,9 +24857,7 @@ const getDefaultParagraphStyle = (docx, styleId = "") => {
24858
24857
  let pPrStyleIdIndentTag = {};
24859
24858
  let pPrStyleJc = {};
24860
24859
  if (styleId) {
24861
- const stylesById = styles.elements[0].elements?.find(
24862
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId
24863
- );
24860
+ const stylesById = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId);
24864
24861
  const pPrById = stylesById?.elements?.find((el) => el.name === "w:pPr");
24865
24862
  pPrStyleIdSpacingTag = pPrById?.elements?.find((el) => el.name === "w:spacing") || {};
24866
24863
  pPrStyleIdIndentTag = pPrById?.elements?.find((el) => el.name === "w:ind") || {};
@@ -27163,6 +27160,68 @@ const config$a = {
27163
27160
  decode: decode$h
27164
27161
  };
27165
27162
  const translator$a = NodeTranslator.from(config$a);
27163
+ const DEFAULT_PAGE_WIDTH_TWIPS = 12240;
27164
+ const DEFAULT_PAGE_MARGIN_TWIPS = 1440;
27165
+ const DEFAULT_CONTENT_WIDTH_TWIPS = DEFAULT_PAGE_WIDTH_TWIPS - 2 * DEFAULT_PAGE_MARGIN_TWIPS;
27166
+ const MIN_COLUMN_WIDTH_TWIPS = pixelsToTwips(10);
27167
+ const pctToPercent = (value) => {
27168
+ if (value == null) return null;
27169
+ return value / 50;
27170
+ };
27171
+ const resolveContentWidthTwips = () => DEFAULT_CONTENT_WIDTH_TWIPS;
27172
+ const resolveMeasurementWidthPx = (measurement) => {
27173
+ if (!measurement || typeof measurement.value !== "number" || measurement.value <= 0) return null;
27174
+ const { value, type: type2 } = measurement;
27175
+ if (!type2 || type2 === "auto") return null;
27176
+ if (type2 === "dxa") return twipsToPixels(value);
27177
+ if (type2 === "pct") {
27178
+ const percent2 = pctToPercent(value);
27179
+ if (percent2 == null || percent2 <= 0) return null;
27180
+ const widthTwips = resolveContentWidthTwips() * percent2 / 100;
27181
+ return twipsToPixels(widthTwips);
27182
+ }
27183
+ return null;
27184
+ };
27185
+ const countColumnsInRow = (row) => {
27186
+ if (!row?.elements?.length) return 0;
27187
+ return row.elements.reduce((count, element) => {
27188
+ if (element.name !== "w:tc") return count;
27189
+ const tcPr = element.elements?.find((el) => el.name === "w:tcPr");
27190
+ const gridSpan = tcPr?.elements?.find((el) => el.name === "w:gridSpan");
27191
+ const spanValue = parseInt(gridSpan?.attributes?.["w:val"] || "1", 10);
27192
+ return count + (Number.isFinite(spanValue) && spanValue > 0 ? spanValue : 1);
27193
+ }, 0);
27194
+ };
27195
+ const clampColumnWidthTwips = (value) => Math.max(Math.round(value), MIN_COLUMN_WIDTH_TWIPS);
27196
+ const createFallbackGrid = (columnCount, columnWidthTwips) => Array.from({ length: columnCount }, () => ({ col: clampColumnWidthTwips(columnWidthTwips) }));
27197
+ const buildFallbackGridForTable = ({ params: params2, rows, tableWidth, tableWidthMeasurement }) => {
27198
+ const firstRow = rows.find((row) => row.elements?.some((el) => el.name === "w:tc"));
27199
+ const columnCount = countColumnsInRow(firstRow);
27200
+ if (!columnCount) return null;
27201
+ const schemaDefaultPx = getSchemaDefaultColumnWidthPx(
27202
+ /** @type {any} */
27203
+ params2
27204
+ );
27205
+ const minimumColumnWidthPx = Number.isFinite(schemaDefaultPx) && schemaDefaultPx > 0 ? schemaDefaultPx : DEFAULT_COLUMN_WIDTH_PX;
27206
+ let totalWidthPx;
27207
+ if (tableWidthMeasurement) {
27208
+ const resolved = resolveMeasurementWidthPx(tableWidthMeasurement);
27209
+ if (resolved != null) totalWidthPx = resolved;
27210
+ }
27211
+ if (totalWidthPx == null && tableWidth?.width && tableWidth.width > 0) {
27212
+ totalWidthPx = tableWidth.width;
27213
+ }
27214
+ if (totalWidthPx == null) {
27215
+ totalWidthPx = minimumColumnWidthPx * columnCount;
27216
+ }
27217
+ const rawColumnWidthPx = Math.max(totalWidthPx / columnCount, minimumColumnWidthPx);
27218
+ const columnWidthTwips = clampColumnWidthTwips(pixelsToTwips(rawColumnWidthPx));
27219
+ const fallbackColumnWidthPx = twipsToPixels(columnWidthTwips);
27220
+ return {
27221
+ grid: createFallbackGrid(columnCount, columnWidthTwips),
27222
+ columnWidths: Array(columnCount).fill(fallbackColumnWidthPx)
27223
+ };
27224
+ };
27166
27225
  const XML_NODE_NAME$9 = "w:tbl";
27167
27226
  const SD_NODE_NAME$9 = "table";
27168
27227
  const encode$g = (params2, encodedAttrs) => {
@@ -27182,7 +27241,6 @@ const encode$g = (params2, encodedAttrs) => {
27182
27241
  "justification",
27183
27242
  "tableLayout",
27184
27243
  ["tableIndent", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27185
- ["tableWidth", ({ value, type: type2 }) => ({ width: twipsToPixels(value), type: type2 })],
27186
27244
  ["tableCellSpacing", ({ value, type: type2 }) => ({ w: String(value), type: type2 })]
27187
27245
  ].forEach((prop) => {
27188
27246
  let key2;
@@ -27200,6 +27258,21 @@ const encode$g = (params2, encodedAttrs) => {
27200
27258
  if (encodedAttrs.tableCellSpacing) {
27201
27259
  encodedAttrs["borderCollapse"] = "separate";
27202
27260
  }
27261
+ if (encodedAttrs.tableProperties?.tableWidth) {
27262
+ const tableWidthMeasurement = encodedAttrs.tableProperties.tableWidth;
27263
+ const widthPx = twipsToPixels(tableWidthMeasurement.value);
27264
+ if (widthPx != null) {
27265
+ encodedAttrs.tableWidth = {
27266
+ width: widthPx,
27267
+ type: tableWidthMeasurement.type
27268
+ };
27269
+ } else if (tableWidthMeasurement.type === "auto") {
27270
+ encodedAttrs.tableWidth = {
27271
+ width: 0,
27272
+ type: tableWidthMeasurement.type
27273
+ };
27274
+ }
27275
+ }
27203
27276
  const { borders, rowBorders } = _processTableBorders(encodedAttrs.tableProperties?.borders || {});
27204
27277
  const referencedStyles = _getReferencedTableStyles(encodedAttrs.tableStyleId, params2);
27205
27278
  if (referencedStyles?.cellMargins && !encodedAttrs.tableProperties?.cellMargins) {
@@ -27213,7 +27286,19 @@ const encode$g = (params2, encodedAttrs) => {
27213
27286
  const borderRowData = Object.assign({}, referencedStyles?.rowBorders || {}, rowBorders || {});
27214
27287
  encodedAttrs["borders"] = borderData;
27215
27288
  const tblStyleTag = tblPr?.elements?.find((el) => el.name === "w:tblStyle");
27216
- const columnWidths = (encodedAttrs["grid"] ?? []).map((item) => twipsToPixels(item.col));
27289
+ let columnWidths = Array.isArray(encodedAttrs["grid"]) ? encodedAttrs["grid"].map((item) => twipsToPixels(item.col)) : [];
27290
+ if (!columnWidths.length) {
27291
+ const fallback = buildFallbackGridForTable({
27292
+ params: params2,
27293
+ rows,
27294
+ tableWidth: encodedAttrs.tableWidth,
27295
+ tableWidthMeasurement: encodedAttrs.tableProperties?.tableWidth
27296
+ });
27297
+ if (fallback) {
27298
+ encodedAttrs.grid = fallback.grid;
27299
+ columnWidths = fallback.columnWidths;
27300
+ }
27301
+ }
27217
27302
  const content = [];
27218
27303
  rows.forEach((row) => {
27219
27304
  const result = translator$G.encode({
@@ -30594,6 +30679,63 @@ const config = {
30594
30679
  attributes: validXmlAttributes
30595
30680
  };
30596
30681
  const translator = NodeTranslator.from(config);
30682
+ const DEFAULT_SECTION_PROPS_TWIPS = Object.freeze({
30683
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
30684
+ pageMargins: Object.freeze({
30685
+ top: "1440",
30686
+ right: "1440",
30687
+ bottom: "1440",
30688
+ left: "1440",
30689
+ header: "720",
30690
+ footer: "720",
30691
+ gutter: "0"
30692
+ })
30693
+ });
30694
+ const ensureSectionLayoutDefaults = (sectPr, converter) => {
30695
+ if (!sectPr) {
30696
+ return {
30697
+ type: "element",
30698
+ name: "w:sectPr",
30699
+ elements: []
30700
+ };
30701
+ }
30702
+ if (!sectPr.elements) sectPr.elements = [];
30703
+ const ensureChild = (name) => {
30704
+ let child = sectPr.elements.find((n) => n.name === name);
30705
+ if (!child) {
30706
+ child = {
30707
+ type: "element",
30708
+ name,
30709
+ elements: [],
30710
+ attributes: {}
30711
+ };
30712
+ sectPr.elements.push(child);
30713
+ } else {
30714
+ if (!child.elements) child.elements = [];
30715
+ if (!child.attributes) child.attributes = {};
30716
+ }
30717
+ return child;
30718
+ };
30719
+ const pageSize = converter?.pageStyles?.pageSize;
30720
+ const pgSz = ensureChild("w:pgSz");
30721
+ if (pageSize?.width != null) pgSz.attributes["w:w"] = String(inchesToTwips(pageSize.width));
30722
+ if (pageSize?.height != null) pgSz.attributes["w:h"] = String(inchesToTwips(pageSize.height));
30723
+ if (pgSz.attributes["w:w"] == null) pgSz.attributes["w:w"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30724
+ if (pgSz.attributes["w:h"] == null) pgSz.attributes["w:h"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30725
+ const pageMargins = converter?.pageStyles?.pageMargins;
30726
+ const pgMar = ensureChild("w:pgMar");
30727
+ if (pageMargins) {
30728
+ Object.entries(pageMargins).forEach(([key2, value]) => {
30729
+ const converted = inchesToTwips(value);
30730
+ if (converted != null) pgMar.attributes[`w:${key2}`] = String(converted);
30731
+ });
30732
+ }
30733
+ Object.entries(DEFAULT_SECTION_PROPS_TWIPS.pageMargins).forEach(([key2, value]) => {
30734
+ const attrKey = `w:${key2}`;
30735
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
30736
+ });
30737
+ return sectPr;
30738
+ };
30597
30739
  const isLineBreakOnlyRun = (node) => {
30598
30740
  if (!node) return false;
30599
30741
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -30646,28 +30788,30 @@ function exportSchemaToJson(params2) {
30646
30788
  return handler2(params2);
30647
30789
  }
30648
30790
  function translateBodyNode(params2) {
30649
- let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
30791
+ let sectPr = params2.bodyNode?.elements?.find((n) => n.name === "w:sectPr");
30792
+ if (!sectPr) {
30793
+ sectPr = {
30794
+ type: "element",
30795
+ name: "w:sectPr",
30796
+ elements: []
30797
+ };
30798
+ } else if (!sectPr.elements) {
30799
+ sectPr = { ...sectPr, elements: [] };
30800
+ }
30801
+ sectPr = ensureSectionLayoutDefaults(sectPr, params2.converter);
30650
30802
  if (params2.converter) {
30651
- const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
30803
+ const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
30652
30804
  const hasDefaultHeader = params2.converter.headerIds?.default;
30653
30805
  if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
30654
30806
  const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
30655
30807
  sectPr.elements.push(defaultHeader);
30656
30808
  }
30657
- const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
30809
+ const hasFooter = sectPr.elements?.some((n) => n.name === "w:footerReference");
30658
30810
  const hasDefaultFooter = params2.converter.footerIds?.default;
30659
30811
  if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
30660
30812
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
30661
30813
  sectPr.elements.push(defaultFooter);
30662
30814
  }
30663
- const newMargins = params2.converter.pageStyles.pageMargins;
30664
- const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
30665
- const { attributes } = sectPrMargins;
30666
- Object.entries(newMargins).forEach(([key2, value]) => {
30667
- const convertedValue = inchesToTwips(value);
30668
- attributes[`w:${key2}`] = convertedValue;
30669
- });
30670
- sectPrMargins.attributes = attributes;
30671
30815
  }
30672
30816
  const elements = translateChildNodes(params2);
30673
30817
  if (params2.isHeaderFooter) {
@@ -32682,6 +32826,7 @@ const createDocumentJson = (docx, converter, editor) => {
32682
32826
  const nodeListHandler = defaultNodeListHandler();
32683
32827
  const bodyNode = json.elements[0].elements.find((el) => el.name === "w:body");
32684
32828
  if (bodyNode) {
32829
+ ensureSectionProperties(bodyNode);
32685
32830
  const node = bodyNode;
32686
32831
  const contentElements = node.elements?.filter((n) => n.name !== "w:sectPr") ?? [];
32687
32832
  const content = pruneIgnoredNodes(contentElements);
@@ -32915,6 +33060,59 @@ function getDocumentStyles(node, docx, converter, editor) {
32915
33060
  styles.alternateHeaders = isAlternatingHeadersOddEven(docx);
32916
33061
  return styles;
32917
33062
  }
33063
+ const DEFAULT_SECTION_PROPS = Object.freeze({
33064
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
33065
+ pageMargins: Object.freeze({
33066
+ top: "1440",
33067
+ right: "1440",
33068
+ bottom: "1440",
33069
+ left: "1440",
33070
+ header: "720",
33071
+ footer: "720",
33072
+ gutter: "0"
33073
+ })
33074
+ });
33075
+ function ensureSectionProperties(bodyNode, converter) {
33076
+ if (!bodyNode.elements) bodyNode.elements = [];
33077
+ let sectPr = bodyNode.elements.find((el) => el.name === "w:sectPr");
33078
+ if (!sectPr) {
33079
+ sectPr = {
33080
+ type: "element",
33081
+ name: "w:sectPr",
33082
+ elements: []
33083
+ };
33084
+ bodyNode.elements.push(sectPr);
33085
+ } else if (!sectPr.elements) {
33086
+ sectPr.elements = [];
33087
+ }
33088
+ const ensureChild = (name, factory) => {
33089
+ let child = sectPr.elements.find((el) => el.name === name);
33090
+ if (!child) {
33091
+ child = factory();
33092
+ sectPr.elements.push(child);
33093
+ } else if (!child.attributes) {
33094
+ child.attributes = {};
33095
+ }
33096
+ return child;
33097
+ };
33098
+ const pgSz = ensureChild("w:pgSz", () => ({
33099
+ type: "element",
33100
+ name: "w:pgSz",
33101
+ attributes: {}
33102
+ }));
33103
+ pgSz.attributes["w:w"] = pgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS.pageSize.width;
33104
+ pgSz.attributes["w:h"] = pgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS.pageSize.height;
33105
+ const pgMar = ensureChild("w:pgMar", () => ({
33106
+ type: "element",
33107
+ name: "w:pgMar",
33108
+ attributes: {}
33109
+ }));
33110
+ Object.entries(DEFAULT_SECTION_PROPS.pageMargins).forEach(([key2, value]) => {
33111
+ const attrKey = `w:${key2}`;
33112
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
33113
+ });
33114
+ return sectPr;
33115
+ }
32918
33116
  function getStyleDefinitions(docx) {
32919
33117
  const styles = docx["word/styles.xml"];
32920
33118
  if (!styles) return [];
@@ -33107,6 +33305,36 @@ const FONT_FAMILY_FALLBACKS = Object.freeze({
33107
33305
  auto: "sans-serif"
33108
33306
  });
33109
33307
  const DEFAULT_GENERIC_FALLBACK = "sans-serif";
33308
+ const DEFAULT_FONT_SIZE_PT = 10;
33309
+ const collectRunDefaultProperties = (runProps, { allowOverrideTypeface = true, allowOverrideSize = true, themeResolver, state: state2 }) => {
33310
+ if (!runProps?.elements?.length || !state2) return;
33311
+ const fontsNode = runProps.elements.find((el) => el.name === "w:rFonts");
33312
+ if (fontsNode?.attributes) {
33313
+ const themeName = fontsNode.attributes["w:asciiTheme"];
33314
+ if (themeName) {
33315
+ const themeInfo = themeResolver?.(themeName) || {};
33316
+ if ((allowOverrideTypeface || !state2.typeface) && themeInfo.typeface) state2.typeface = themeInfo.typeface;
33317
+ if ((allowOverrideTypeface || !state2.panose) && themeInfo.panose) state2.panose = themeInfo.panose;
33318
+ }
33319
+ const ascii = fontsNode.attributes["w:ascii"];
33320
+ if ((allowOverrideTypeface || !state2.typeface) && ascii) {
33321
+ state2.typeface = ascii;
33322
+ }
33323
+ }
33324
+ const sizeNode = runProps.elements.find((el) => el.name === "w:sz");
33325
+ if (sizeNode?.attributes?.["w:val"]) {
33326
+ const sizeTwips = Number(sizeNode.attributes["w:val"]);
33327
+ if (Number.isFinite(sizeTwips)) {
33328
+ if (state2.fallbackSzTwips === void 0) state2.fallbackSzTwips = sizeTwips;
33329
+ const sizePt = sizeTwips / 2;
33330
+ if (allowOverrideSize || state2.fontSizePt === void 0) state2.fontSizePt = sizePt;
33331
+ }
33332
+ }
33333
+ const kernNode = runProps.elements.find((el) => el.name === "w:kern");
33334
+ if (kernNode?.attributes?.["w:val"]) {
33335
+ if (allowOverrideSize || state2.kern === void 0) state2.kern = kernNode.attributes["w:val"];
33336
+ }
33337
+ };
33110
33338
  const _SuperConverter = class _SuperConverter2 {
33111
33339
  constructor(params2 = null) {
33112
33340
  __privateAdd$2(this, _SuperConverter_instances);
@@ -33212,7 +33440,7 @@ const _SuperConverter = class _SuperConverter2 {
33212
33440
  return;
33213
33441
  }
33214
33442
  }
33215
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.20.2") {
33443
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.21.1") {
33216
33444
  const customLocation = "docProps/custom.xml";
33217
33445
  if (!docx[customLocation]) {
33218
33446
  docx[customLocation] = generateCustomXml();
@@ -33234,49 +33462,45 @@ const _SuperConverter = class _SuperConverter2 {
33234
33462
  }
33235
33463
  getDocumentDefaultStyles() {
33236
33464
  const styles = this.convertedXml["word/styles.xml"];
33237
- if (!styles) return {};
33238
- const defaults = styles.elements[0].elements.find((el) => el.name === "w:docDefaults");
33239
- const rDefault = defaults.elements.find((el) => el.name === "w:rPrDefault");
33240
- if (!rDefault.elements) return {};
33241
- const rElements = rDefault.elements[0].elements;
33242
- const rFonts = rElements?.find((el) => el.name === "w:rFonts");
33243
- if ("elements" in rDefault) {
33244
- const fontThemeName = rElements.find((el) => el.name === "w:rFonts")?.attributes["w:asciiTheme"];
33245
- let typeface, panose, fontSizeNormal;
33246
- if (fontThemeName) {
33247
- const fontInfo = this.getThemeInfo(fontThemeName);
33248
- typeface = fontInfo.typeface;
33249
- panose = fontInfo.panose;
33250
- } else if (rFonts) {
33251
- typeface = rFonts?.attributes["w:ascii"];
33252
- }
33253
- const paragraphDefaults = styles.elements[0].elements.filter((el) => {
33254
- return el.name === "w:style" && el.attributes["w:styleId"] === "Normal";
33255
- }) || [];
33256
- paragraphDefaults.forEach((el) => {
33257
- const rPr = el.elements.find((el2) => el2.name === "w:rPr");
33258
- const fonts = rPr?.elements?.find((el2) => el2.name === "w:rFonts");
33259
- typeface = fonts?.attributes["w:ascii"];
33260
- fontSizeNormal = Number(rPr?.elements?.find((el2) => el2.name === "w:sz")?.attributes["w:val"]) / 2;
33261
- });
33262
- const rPrDefaults = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
33263
- if (rPrDefaults) {
33264
- const rPr = rPrDefaults.elements?.find((el) => el.name === "w:rPr");
33265
- const fonts = rPr?.elements?.find((el) => el.name === "w:rFonts");
33266
- if (fonts?.attributes?.["w:ascii"]) {
33267
- typeface = fonts.attributes["w:ascii"];
33268
- }
33269
- const fontSizeRaw = rPr?.elements?.find((el) => el.name === "w:sz")?.attributes?.["w:val"];
33270
- if (!fontSizeNormal && fontSizeRaw) {
33271
- fontSizeNormal = Number(fontSizeRaw) / 2;
33272
- }
33273
- }
33274
- const fallbackSz = Number(rElements.find((el) => el.name === "w:sz")?.attributes?.["w:val"]);
33275
- const fontSizePt = fontSizeNormal ?? (Number.isFinite(fallbackSz) ? fallbackSz / 2 : void 0) ?? 10;
33276
- const kern = rElements.find((el) => el.name === "w:kern")?.attributes["w:val"];
33277
- const fontFamilyCss = _SuperConverter2.toCssFontFamily(typeface, this.convertedXml);
33278
- return { fontSizePt, kern, typeface, panose, fontFamilyCss };
33279
- }
33465
+ const styleRoot = styles?.elements?.[0];
33466
+ const styleElements = styleRoot?.elements || [];
33467
+ if (!styleElements.length) return {};
33468
+ const defaults = styleElements.find((el) => el.name === "w:docDefaults");
33469
+ const normalStyle = styleElements.find((el) => el.name === "w:style" && el.attributes?.["w:styleId"] === "Normal");
33470
+ const defaultsState = {
33471
+ typeface: void 0,
33472
+ panose: void 0,
33473
+ fontSizePt: void 0,
33474
+ kern: void 0,
33475
+ fallbackSzTwips: void 0
33476
+ };
33477
+ const docDefaultRun = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
33478
+ const docDefaultProps = docDefaultRun?.elements?.find((el) => el.name === "w:rPr") ?? docDefaultRun;
33479
+ collectRunDefaultProperties(docDefaultProps, {
33480
+ allowOverrideTypeface: true,
33481
+ allowOverrideSize: true,
33482
+ themeResolver: (theme) => this.getThemeInfo(theme),
33483
+ state: defaultsState
33484
+ });
33485
+ const normalRunProps = normalStyle?.elements?.find((el) => el.name === "w:rPr") ?? null;
33486
+ collectRunDefaultProperties(normalRunProps, {
33487
+ allowOverrideTypeface: true,
33488
+ allowOverrideSize: true,
33489
+ themeResolver: (theme) => this.getThemeInfo(theme),
33490
+ state: defaultsState
33491
+ });
33492
+ if (defaultsState.fontSizePt === void 0) {
33493
+ if (Number.isFinite(defaultsState.fallbackSzTwips)) defaultsState.fontSizePt = defaultsState.fallbackSzTwips / 2;
33494
+ else defaultsState.fontSizePt = DEFAULT_FONT_SIZE_PT;
33495
+ }
33496
+ const fontFamilyCss = defaultsState.typeface ? _SuperConverter2.toCssFontFamily(defaultsState.typeface, this.convertedXml) : void 0;
33497
+ const result = {};
33498
+ if (defaultsState.fontSizePt !== void 0) result.fontSizePt = defaultsState.fontSizePt;
33499
+ if (defaultsState.kern !== void 0) result.kern = defaultsState.kern;
33500
+ if (defaultsState.typeface) result.typeface = defaultsState.typeface;
33501
+ if (defaultsState.panose) result.panose = defaultsState.panose;
33502
+ if (fontFamilyCss) result.fontFamilyCss = fontFamilyCss;
33503
+ return result;
33280
33504
  }
33281
33505
  getDocumentFonts() {
33282
33506
  const fontTable = this.convertedXml["word/fontTable.xml"];
@@ -33705,7 +33929,7 @@ function storeSuperdocVersion(docx) {
33705
33929
  function generateCustomXml() {
33706
33930
  return DEFAULT_CUSTOM_XML;
33707
33931
  }
33708
- function generateSuperdocVersion(pid = 2, version2 = "0.20.2") {
33932
+ function generateSuperdocVersion(pid = 2, version2 = "0.21.1") {
33709
33933
  return {
33710
33934
  type: "element",
33711
33935
  name: "property",
@@ -36143,14 +36367,19 @@ class DocxZipper {
36143
36367
  /**
36144
36368
  * Update [Content_Types].xml with extensions of new Image annotations
36145
36369
  */
36146
- async updateContentTypes(docx, media, fromJson) {
36370
+ async updateContentTypes(docx, media, fromJson, updatedDocs = {}) {
36371
+ const additionalPartNames = Object.keys(updatedDocs || {});
36147
36372
  const newMediaTypes = Object.keys(media).map((name) => {
36148
36373
  return this.getFileExtension(name);
36149
36374
  }).filter(Boolean);
36150
36375
  const contentTypesPath = "[Content_Types].xml";
36151
36376
  let contentTypesXml;
36152
36377
  if (fromJson) {
36153
- contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
36378
+ if (Array.isArray(docx.files)) {
36379
+ contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
36380
+ } else {
36381
+ contentTypesXml = docx.files?.[contentTypesPath] || "";
36382
+ }
36154
36383
  } else contentTypesXml = await docx.file(contentTypesPath).async("string");
36155
36384
  let typesString = "";
36156
36385
  const defaultMediaTypes = getContentTypesFromXml(contentTypesXml);
@@ -36176,24 +36405,39 @@ class DocxZipper {
36176
36405
  const hasCommentsExtensible = types2.elements?.some(
36177
36406
  (el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtensible.xml"
36178
36407
  );
36179
- if (docx.files["word/comments.xml"]) {
36408
+ const hasFile = (filename) => {
36409
+ if (!docx?.files) return false;
36410
+ if (!fromJson) return Boolean(docx.files[filename]);
36411
+ if (Array.isArray(docx.files)) return docx.files.some((file) => file.name === filename);
36412
+ return Boolean(docx.files[filename]);
36413
+ };
36414
+ if (hasFile("word/comments.xml")) {
36180
36415
  const commentsDef = `<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" />`;
36181
36416
  if (!hasComments) typesString += commentsDef;
36182
36417
  }
36183
- if (docx.files["word/commentsExtended.xml"]) {
36418
+ if (hasFile("word/commentsExtended.xml")) {
36184
36419
  const commentsExtendedDef = `<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml" />`;
36185
36420
  if (!hasCommentsExtended) typesString += commentsExtendedDef;
36186
36421
  }
36187
- if (docx.files["word/commentsIds.xml"]) {
36422
+ if (hasFile("word/commentsIds.xml")) {
36188
36423
  const commentsIdsDef = `<Override PartName="/word/commentsIds.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml" />`;
36189
36424
  if (!hasCommentsIds) typesString += commentsIdsDef;
36190
36425
  }
36191
- if (docx.files["word/commentsExtensible.xml"]) {
36426
+ if (hasFile("word/commentsExtensible.xml")) {
36192
36427
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
36193
36428
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
36194
36429
  }
36195
- Object.keys(docx.files).forEach((name) => {
36196
- if (name.includes(".rels") || !name.includes("header") && !name.includes("footer")) return;
36430
+ const partNames = new Set(additionalPartNames);
36431
+ if (docx?.files) {
36432
+ if (fromJson && Array.isArray(docx.files)) {
36433
+ docx.files.forEach((file) => partNames.add(file.name));
36434
+ } else {
36435
+ Object.keys(docx.files).forEach((key2) => partNames.add(key2));
36436
+ }
36437
+ }
36438
+ partNames.forEach((name) => {
36439
+ if (name.includes(".rels")) return;
36440
+ if (!name.includes("header") && !name.includes("footer")) return;
36197
36441
  const hasExtensible = types2.elements?.some(
36198
36442
  (el) => el.name === "Override" && el.attributes.PartName === `/${name}`
36199
36443
  );
@@ -36204,7 +36448,48 @@ class DocxZipper {
36204
36448
  }
36205
36449
  });
36206
36450
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
36207
- const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
36451
+ let updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
36452
+ let relationshipsXml = updatedDocs["word/_rels/document.xml.rels"];
36453
+ if (!relationshipsXml) {
36454
+ if (fromJson) {
36455
+ if (Array.isArray(docx.files)) {
36456
+ relationshipsXml = docx.files.find((file) => file.name === "word/_rels/document.xml.rels")?.content;
36457
+ } else {
36458
+ relationshipsXml = docx.files?.["word/_rels/document.xml.rels"];
36459
+ }
36460
+ } else {
36461
+ relationshipsXml = await docx.file("word/_rels/document.xml.rels")?.async("string");
36462
+ }
36463
+ }
36464
+ if (relationshipsXml) {
36465
+ try {
36466
+ const relJson = xmljs.xml2js(relationshipsXml, { compact: false });
36467
+ const relationships = relJson.elements?.find((el) => el.name === "Relationships");
36468
+ relationships?.elements?.forEach((rel) => {
36469
+ const type2 = rel.attributes?.Type;
36470
+ const target = rel.attributes?.Target;
36471
+ if (!type2 || !target) return;
36472
+ const isHeader = type2.includes("/header");
36473
+ const isFooter = type2.includes("/footer");
36474
+ if (!isHeader && !isFooter) return;
36475
+ let sanitizedTarget = target.replace(/^\.\//, "");
36476
+ if (sanitizedTarget.startsWith("../")) sanitizedTarget = sanitizedTarget.slice(3);
36477
+ if (sanitizedTarget.startsWith("/")) sanitizedTarget = sanitizedTarget.slice(1);
36478
+ const partName = sanitizedTarget.startsWith("word/") ? sanitizedTarget : `word/${sanitizedTarget}`;
36479
+ partNames.add(partName);
36480
+ });
36481
+ } catch (error) {
36482
+ console.warn("Failed to parse document relationships while updating content types", error);
36483
+ }
36484
+ }
36485
+ partNames.forEach((name) => {
36486
+ if (name.includes(".rels")) return;
36487
+ if (!name.includes("header") && !name.includes("footer")) return;
36488
+ if (updatedContentTypesXml.includes(`PartName="/${name}"`)) return;
36489
+ const type2 = name.includes("header") ? "header" : "footer";
36490
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type2}+xml"/>`;
36491
+ updatedContentTypesXml = updatedContentTypesXml.replace("</Types>", `${extendedDef}</Types>`);
36492
+ });
36208
36493
  if (fromJson) return updatedContentTypesXml;
36209
36494
  docx.file(contentTypesPath, updatedContentTypesXml);
36210
36495
  }
@@ -36245,7 +36530,7 @@ class DocxZipper {
36245
36530
  for (const [fontName, fontUintArray] of Object.entries(fonts)) {
36246
36531
  zip.file(fontName, fontUintArray);
36247
36532
  }
36248
- await this.updateContentTypes(zip, media);
36533
+ await this.updateContentTypes(zip, media, false, updatedDocs);
36249
36534
  return zip;
36250
36535
  }
36251
36536
  /**
@@ -36271,7 +36556,7 @@ class DocxZipper {
36271
36556
  Object.keys(media).forEach((path) => {
36272
36557
  unzippedOriginalDocx.file(path, media[path]);
36273
36558
  });
36274
- await this.updateContentTypes(unzippedOriginalDocx, media);
36559
+ await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs);
36275
36560
  return unzippedOriginalDocx;
36276
36561
  }
36277
36562
  }
@@ -47929,9 +48214,11 @@ const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode,
47929
48214
  item.editor.view.dom.setAttribute("documentmode", documentMode);
47930
48215
  });
47931
48216
  if (isEditMode) {
47932
- const pm = document.querySelector(".ProseMirror");
47933
- pm.classList.add("header-footer-edit");
47934
- pm.setAttribute("aria-readonly", true);
48217
+ const pm = editor.view?.dom || editor.options.element?.querySelector?.(".ProseMirror");
48218
+ if (pm) {
48219
+ pm.classList.add("header-footer-edit");
48220
+ pm.setAttribute("aria-readonly", true);
48221
+ }
47935
48222
  }
47936
48223
  if (focusedSectionEditor) {
47937
48224
  focusedSectionEditor.view.focus();
@@ -48961,6 +49248,7 @@ const generateTableIfNecessary = ({ tableNode, annotationValues, tr, state: stat
48961
49248
  const mappedRowStart = tr.mapping.map(absoluteRowStart);
48962
49249
  const rowEnd = mappedRowStart + rowNode.nodeSize;
48963
49250
  tr.replaceWith(mappedRowStart, rowEnd, Fragment.from(newRows));
49251
+ tr.setMeta("tableGeneration", true);
48964
49252
  } catch (error) {
48965
49253
  console.error("Error during row generation:", error);
48966
49254
  throw error;
@@ -49365,7 +49653,7 @@ function findFieldAnnotationsBetween(from2, to, doc2) {
49365
49653
  }
49366
49654
  function findRemovedFieldAnnotations(tr) {
49367
49655
  let removedNodes = [];
49368
- if (!tr.steps.length || tr.meta && !Object.keys(tr.meta).every((meta) => ["inputType", "uiEvent", "paste"].includes(meta)) || ["historyUndo", "historyRedo"].includes(tr.getMeta("inputType")) || ["drop"].includes(tr.getMeta("uiEvent")) || tr.getMeta("fieldAnnotationUpdate") === true) {
49656
+ if (!tr.steps.length || tr.meta && !Object.keys(tr.meta).every((meta) => ["inputType", "uiEvent", "paste"].includes(meta)) || ["historyUndo", "historyRedo"].includes(tr.getMeta("inputType")) || ["drop"].includes(tr.getMeta("uiEvent")) || tr.getMeta("fieldAnnotationUpdate") === true || tr.getMeta("tableGeneration") === true) {
49369
49657
  return removedNodes;
49370
49658
  }
49371
49659
  const hasDeletion = transactionDeletedAnything(tr);
@@ -50543,7 +50831,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
50543
50831
  setDocumentMode(documentMode) {
50544
50832
  let cleanedMode = documentMode?.toLowerCase() || "editing";
50545
50833
  if (!this.extensionService || !this.state) return;
50546
- const pm = document.querySelector(".ProseMirror");
50834
+ const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
50547
50835
  if (this.options.role === "viewer") cleanedMode = "viewing";
50548
50836
  if (this.options.role === "suggester" && cleanedMode === "editing") cleanedMode = "suggesting";
50549
50837
  if (cleanedMode === "viewing") {
@@ -51031,7 +51319,8 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
51031
51319
  files: this.options.content
51032
51320
  },
51033
51321
  media,
51034
- true
51322
+ true,
51323
+ updatedDocs
51035
51324
  );
51036
51325
  return updatedDocs;
51037
51326
  }
@@ -51097,7 +51386,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
51097
51386
  * @returns {Object | void} Migration results
51098
51387
  */
51099
51388
  processCollaborationMigrations() {
51100
- console.debug("[checkVersionMigrations] Current editor version", "0.20.2");
51389
+ console.debug("[checkVersionMigrations] Current editor version", "0.21.1");
51101
51390
  if (!this.options.ydoc) return;
51102
51391
  const metaMap = this.options.ydoc.getMap("meta");
51103
51392
  let docVersion = metaMap.get("version");
@@ -51517,9 +51806,11 @@ createView_fn = function(element) {
51517
51806
  isEditMode: false,
51518
51807
  documentMode: this.options.documentMode
51519
51808
  });
51520
- const pm = document.querySelector(".ProseMirror");
51521
- pm.classList.remove("header-footer-edit");
51522
- pm.setAttribute("aria-readonly", false);
51809
+ const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
51810
+ if (pm) {
51811
+ pm.classList.remove("header-footer-edit");
51812
+ pm.setAttribute("aria-readonly", false);
51813
+ }
51523
51814
  }
51524
51815
  setWordSelection(view, pos);
51525
51816
  }
@@ -53574,15 +53865,31 @@ const intToJapaneseCounting = (num) => {
53574
53865
  }
53575
53866
  return result;
53576
53867
  };
53577
- const CustomSelectionPluginKey = new PluginKey("CustomSelection");
53578
- const shouldAllowNativeContextMenu = (event) => {
53868
+ const isKeyboardInvocation = (event) => {
53869
+ return event.type === "contextmenu" && typeof event.detail === "number" && event.detail === 0 && (event.button === 0 || event.button === void 0) && event.clientX === 0 && event.clientY === 0;
53870
+ };
53871
+ const prefersNativeMenu = (event) => {
53579
53872
  if (!event) return false;
53580
53873
  if (event.ctrlKey || event.metaKey) {
53581
53874
  return true;
53582
53875
  }
53583
- const isKeyboardInvocation = event.type === "contextmenu" && typeof event.detail === "number" && event.detail === 0 && (event.button === 0 || event.button === void 0) && event.clientX === 0 && event.clientY === 0;
53584
- return Boolean(isKeyboardInvocation);
53876
+ return isKeyboardInvocation(event);
53585
53877
  };
53878
+ const shouldAllowNativeContextMenu = (event) => {
53879
+ return prefersNativeMenu(event);
53880
+ };
53881
+ const shouldBypassContextMenu = shouldAllowNativeContextMenu;
53882
+ const DEFAULT_SELECTION_STATE = Object.freeze({
53883
+ focused: false,
53884
+ preservedSelection: null,
53885
+ showVisualSelection: false,
53886
+ skipFocusReset: false
53887
+ });
53888
+ const normalizeSelectionState = (state2 = {}) => ({
53889
+ ...DEFAULT_SELECTION_STATE,
53890
+ ...state2
53891
+ });
53892
+ const CustomSelectionPluginKey = new PluginKey("CustomSelection");
53586
53893
  const handleClickOutside = (event, editor) => {
53587
53894
  const editorElem = editor?.options?.element;
53588
53895
  if (!editorElem) return;
@@ -53619,11 +53926,7 @@ const CustomSelection = Extension.create({
53619
53926
  const customSelectionPlugin = new Plugin({
53620
53927
  key: CustomSelectionPluginKey,
53621
53928
  state: {
53622
- init: () => ({
53623
- focused: false,
53624
- preservedSelection: null,
53625
- showVisualSelection: false
53626
- }),
53929
+ init: () => ({ ...DEFAULT_SELECTION_STATE }),
53627
53930
  apply: (tr, value) => {
53628
53931
  const meta = getFocusMeta(tr);
53629
53932
  if (meta !== void 0) {
@@ -53654,7 +53957,8 @@ const CustomSelection = Extension.create({
53654
53957
  setFocusMeta(view.state.tr, {
53655
53958
  focused: true,
53656
53959
  preservedSelection: selection,
53657
- showVisualSelection: true
53960
+ showVisualSelection: true,
53961
+ skipFocusReset: true
53658
53962
  })
53659
53963
  );
53660
53964
  }
@@ -53675,7 +53979,8 @@ const CustomSelection = Extension.create({
53675
53979
  setFocusMeta(view.state.tr, {
53676
53980
  focused: true,
53677
53981
  preservedSelection: selection2,
53678
- showVisualSelection: true
53982
+ showVisualSelection: true,
53983
+ skipFocusReset: true
53679
53984
  })
53680
53985
  );
53681
53986
  this.editor.setOptions({
@@ -53698,7 +54003,8 @@ const CustomSelection = Extension.create({
53698
54003
  setFocusMeta(view.state.tr, {
53699
54004
  focused: true,
53700
54005
  preservedSelection: selection,
53701
- showVisualSelection: true
54006
+ showVisualSelection: true,
54007
+ skipFocusReset: false
53702
54008
  })
53703
54009
  );
53704
54010
  this.editor.setOptions({
@@ -53716,7 +54022,8 @@ const CustomSelection = Extension.create({
53716
54022
  setFocusMeta(view.state.tr, {
53717
54023
  focused: true,
53718
54024
  preservedSelection: selection,
53719
- showVisualSelection: true
54025
+ showVisualSelection: true,
54026
+ skipFocusReset: false
53720
54027
  })
53721
54028
  );
53722
54029
  }
@@ -53727,7 +54034,8 @@ const CustomSelection = Extension.create({
53727
54034
  setFocusMeta(view.state.tr, {
53728
54035
  focused: false,
53729
54036
  preservedSelection: null,
53730
- showVisualSelection: false
54037
+ showVisualSelection: false,
54038
+ skipFocusReset: false
53731
54039
  })
53732
54040
  );
53733
54041
  if (!selection.empty && !this.editor.options.element?.contains(target)) {
@@ -53744,12 +54052,20 @@ const CustomSelection = Extension.create({
53744
54052
  const isElement2 = target instanceof Element;
53745
54053
  const isToolbarBtn = isElement2 && isToolbarButton(target);
53746
54054
  const isToolbarInp = isElement2 && isToolbarInput(target);
54055
+ const focusState = getFocusState(view.state);
54056
+ if (focusState?.skipFocusReset) {
54057
+ view.dispatch(
54058
+ setFocusMeta(view.state.tr, normalizeSelectionState({ ...focusState, skipFocusReset: false }))
54059
+ );
54060
+ return false;
54061
+ }
53747
54062
  if (!isToolbarBtn && !isToolbarInp) {
53748
54063
  view.dispatch(
53749
54064
  setFocusMeta(view.state.tr, {
53750
54065
  focused: false,
53751
54066
  preservedSelection: null,
53752
- showVisualSelection: false
54067
+ showVisualSelection: false,
54068
+ skipFocusReset: false
53753
54069
  })
53754
54070
  );
53755
54071
  }
@@ -53760,12 +54076,16 @@ const CustomSelection = Extension.create({
53760
54076
  const isToolbarBtn = isElement2 && isToolbarButton(target);
53761
54077
  const isToolbarInp = isElement2 && isToolbarInput(target);
53762
54078
  const state2 = getFocusState(view.state);
54079
+ if (state2?.skipFocusReset) {
54080
+ return false;
54081
+ }
53763
54082
  if (isToolbarBtn || isToolbarInp) {
53764
54083
  view.dispatch(
53765
54084
  setFocusMeta(view.state.tr, {
53766
54085
  focused: true,
53767
54086
  preservedSelection: state2.preservedSelection || view.state.selection,
53768
- showVisualSelection: true
54087
+ showVisualSelection: true,
54088
+ skipFocusReset: false
53769
54089
  })
53770
54090
  );
53771
54091
  } else {
@@ -53773,7 +54093,8 @@ const CustomSelection = Extension.create({
53773
54093
  setFocusMeta(view.state.tr, {
53774
54094
  focused: false,
53775
54095
  preservedSelection: null,
53776
- showVisualSelection: false
54096
+ showVisualSelection: false,
54097
+ skipFocusReset: false
53777
54098
  })
53778
54099
  );
53779
54100
  }
@@ -69548,7 +69869,8 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
69548
69869
  const prevSelection = prevState.selection;
69549
69870
  if (selection.from !== prevSelection.from || selection.to !== prevSelection.to) {
69550
69871
  setTimeout(() => {
69551
- const selectedResizableWrapper = document.querySelector(".sd-editor-resizable-wrapper");
69872
+ const searchRoot = editorView?.dom;
69873
+ const selectedResizableWrapper = searchRoot?.querySelector(".sd-editor-resizable-wrapper");
69552
69874
  if (selectedResizableWrapper) {
69553
69875
  showResizeHandles(view2, selectedResizableWrapper);
69554
69876
  } else {
@@ -83084,7 +83406,7 @@ class SuperToolbar extends EventEmitter2 {
83084
83406
  if (!argument) return;
83085
83407
  item.onActivate({ zoom: argument });
83086
83408
  this.emit("superdoc-command", { item, argument });
83087
- const layers = document.querySelector(this.superdoc.config.selector)?.querySelector(".layers");
83409
+ const layers = this.superdoc.element?.querySelector(".layers");
83088
83410
  if (!layers) return;
83089
83411
  const isMobileDevice = typeof screen.orientation !== "undefined";
83090
83412
  const isSmallScreen = window.matchMedia("(max-width: 834px)").matches;
@@ -84146,14 +84468,6 @@ function getStructureFromResolvedPos(state2, pos) {
84146
84468
  return null;
84147
84469
  }
84148
84470
  }
84149
- const shouldBypassContextMenu = (event) => {
84150
- if (!event) return false;
84151
- if (event.ctrlKey || event.metaKey) {
84152
- return true;
84153
- }
84154
- const isKeyboardInvocation = event.type === "contextmenu" && typeof event.detail === "number" && event.detail === 0 && (event.button === 0 || event.button === void 0) && event.clientX === 0 && event.clientY === 0;
84155
- return Boolean(isKeyboardInvocation);
84156
- };
84157
84471
  const isModuleEnabled = (editorOptions, moduleName) => {
84158
84472
  switch (moduleName) {
84159
84473
  case "ai":