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

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-OEs-MC5j.es.js → PdfViewer-BBpGCmdE.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-Ck3Syakz.cjs → PdfViewer-CxIz7yf-.cjs} +1 -1
  3. package/dist/chunks/{index-BM732Zfw.cjs → index-BE07bQaY.cjs} +39 -19
  4. package/dist/chunks/{index-B4aklZ4_.es.js → index-CYCctXm3.es.js} +39 -19
  5. package/dist/chunks/{super-editor.es-Bokezk1E.es.js → super-editor.es-Ccu1wOj1.es.js} +201 -72
  6. package/dist/chunks/{super-editor.es-DwGNbrZq.cjs → super-editor.es-cZsHkhM6.cjs} +201 -72
  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-BcqEfCTg.js → converter-DBwwYo1I.js} +187 -63
  13. package/dist/super-editor/chunks/{docx-zipper-DZ9ph0iQ.js → docx-zipper-BCI-3XE9.js} +1 -1
  14. package/dist/super-editor/chunks/{editor-CTHD3ziL.js → editor-B2S-zXBF.js} +15 -10
  15. package/dist/super-editor/chunks/{toolbar-DLQeMuoQ.js → toolbar-BX9nPPG0.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/super-converter/SuperConverter.d.ts +1 -13
  21. package/dist/super-editor/super-editor.es.js +7 -7
  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 +238 -89
  28. package/dist/superdoc.umd.js.map +1 -1
  29. package/package.json +1 -1
@@ -32581,17 +32581,16 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32581
32581
  };
32582
32582
  const getDefaultParagraphStyle = (docx, styleId = "") => {
32583
32583
  const styles = docx["word/styles.xml"];
32584
- if (!styles) {
32584
+ const rootElements = styles?.elements?.[0]?.elements;
32585
+ if (!rootElements?.length) {
32585
32586
  return {};
32586
32587
  }
32587
- const defaults = styles.elements[0].elements?.find((el) => el.name === "w:docDefaults");
32588
- const pDefault = defaults.elements.find((el) => el.name === "w:pPrDefault");
32588
+ const defaults = rootElements.find((el) => el.name === "w:docDefaults");
32589
+ const pDefault = defaults?.elements?.find((el) => el.name === "w:pPrDefault") || {};
32589
32590
  const pPrDefault = pDefault?.elements?.find((el) => el.name === "w:pPr");
32590
32591
  const pPrDefaultSpacingTag = pPrDefault?.elements?.find((el) => el.name === "w:spacing") || {};
32591
32592
  const pPrDefaultIndentTag = pPrDefault?.elements?.find((el) => el.name === "w:ind") || {};
32592
- const stylesNormal = styles.elements[0].elements?.find(
32593
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal"
32594
- );
32593
+ const stylesNormal = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal");
32595
32594
  const pPrNormal = stylesNormal?.elements?.find((el) => el.name === "w:pPr");
32596
32595
  const pPrNormalSpacingTag = pPrNormal?.elements?.find((el) => el.name === "w:spacing") || {};
32597
32596
  const pPrNormalIndentTag = pPrNormal?.elements?.find((el) => el.name === "w:ind") || {};
@@ -32600,9 +32599,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32600
32599
  let pPrStyleIdIndentTag = {};
32601
32600
  let pPrStyleJc = {};
32602
32601
  if (styleId) {
32603
- const stylesById = styles.elements[0].elements?.find(
32604
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId
32605
- );
32602
+ const stylesById = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId);
32606
32603
  const pPrById = stylesById?.elements?.find((el) => el.name === "w:pPr");
32607
32604
  pPrStyleIdSpacingTag = pPrById?.elements?.find((el) => el.name === "w:spacing") || {};
32608
32605
  pPrStyleIdIndentTag = pPrById?.elements?.find((el) => el.name === "w:ind") || {};
@@ -38336,6 +38333,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
38336
38333
  attributes: validXmlAttributes
38337
38334
  };
38338
38335
  const translator = NodeTranslator.from(config);
38336
+ const DEFAULT_SECTION_PROPS_TWIPS = Object.freeze({
38337
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
38338
+ pageMargins: Object.freeze({
38339
+ top: "1440",
38340
+ right: "1440",
38341
+ bottom: "1440",
38342
+ left: "1440",
38343
+ header: "720",
38344
+ footer: "720",
38345
+ gutter: "0"
38346
+ })
38347
+ });
38339
38348
  const isLineBreakOnlyRun = (node) => {
38340
38349
  if (!node) return false;
38341
38350
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -38388,28 +38397,63 @@ Please report this to https://github.com/markedjs/marked.`, e) {
38388
38397
  return handler2(params2);
38389
38398
  }
38390
38399
  function translateBodyNode(params2) {
38391
- let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
38400
+ let sectPr = params2.bodyNode?.elements?.find((n) => n.name === "w:sectPr");
38401
+ if (!sectPr) {
38402
+ sectPr = {
38403
+ type: "element",
38404
+ name: "w:sectPr",
38405
+ elements: []
38406
+ };
38407
+ } else if (!sectPr.elements) {
38408
+ sectPr = { ...sectPr, elements: [] };
38409
+ }
38392
38410
  if (params2.converter) {
38393
- const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
38411
+ const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
38394
38412
  const hasDefaultHeader = params2.converter.headerIds?.default;
38395
38413
  if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
38396
38414
  const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
38397
38415
  sectPr.elements.push(defaultHeader);
38398
38416
  }
38399
- const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
38417
+ const hasFooter = sectPr.elements?.some((n) => n.name === "w:footerReference");
38400
38418
  const hasDefaultFooter = params2.converter.footerIds?.default;
38401
38419
  if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
38402
38420
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
38403
38421
  sectPr.elements.push(defaultFooter);
38404
38422
  }
38405
- const newMargins = params2.converter.pageStyles.pageMargins;
38406
- const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
38407
- const { attributes } = sectPrMargins;
38408
- Object.entries(newMargins).forEach(([key2, value]) => {
38409
- const convertedValue = inchesToTwips(value);
38410
- attributes[`w:${key2}`] = convertedValue;
38411
- });
38412
- sectPrMargins.attributes = attributes;
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;
38413
38457
  }
38414
38458
  const elements = translateChildNodes(params2);
38415
38459
  if (params2.isHeaderFooter) {
@@ -40397,6 +40441,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40397
40441
  const nodeListHandler = defaultNodeListHandler();
40398
40442
  const bodyNode = json.elements[0].elements.find((el) => el.name === "w:body");
40399
40443
  if (bodyNode) {
40444
+ ensureSectionProperties(bodyNode);
40400
40445
  const node = bodyNode;
40401
40446
  const contentElements = node.elements?.filter((n) => n.name !== "w:sectPr") ?? [];
40402
40447
  const content = pruneIgnoredNodes(contentElements);
@@ -40630,6 +40675,59 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40630
40675
  styles.alternateHeaders = isAlternatingHeadersOddEven(docx);
40631
40676
  return styles;
40632
40677
  }
40678
+ const DEFAULT_SECTION_PROPS = Object.freeze({
40679
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
40680
+ pageMargins: Object.freeze({
40681
+ top: "1440",
40682
+ right: "1440",
40683
+ bottom: "1440",
40684
+ left: "1440",
40685
+ header: "720",
40686
+ footer: "720",
40687
+ gutter: "0"
40688
+ })
40689
+ });
40690
+ function ensureSectionProperties(bodyNode, converter) {
40691
+ if (!bodyNode.elements) bodyNode.elements = [];
40692
+ let sectPr = bodyNode.elements.find((el) => el.name === "w:sectPr");
40693
+ if (!sectPr) {
40694
+ sectPr = {
40695
+ type: "element",
40696
+ name: "w:sectPr",
40697
+ elements: []
40698
+ };
40699
+ bodyNode.elements.push(sectPr);
40700
+ } else if (!sectPr.elements) {
40701
+ sectPr.elements = [];
40702
+ }
40703
+ const ensureChild = (name, factory) => {
40704
+ let child = sectPr.elements.find((el) => el.name === name);
40705
+ if (!child) {
40706
+ child = factory();
40707
+ sectPr.elements.push(child);
40708
+ } else if (!child.attributes) {
40709
+ child.attributes = {};
40710
+ }
40711
+ return child;
40712
+ };
40713
+ const pgSz = ensureChild("w:pgSz", () => ({
40714
+ type: "element",
40715
+ name: "w:pgSz",
40716
+ attributes: {}
40717
+ }));
40718
+ pgSz.attributes["w:w"] = pgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS.pageSize.width;
40719
+ pgSz.attributes["w:h"] = pgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS.pageSize.height;
40720
+ const pgMar = ensureChild("w:pgMar", () => ({
40721
+ type: "element",
40722
+ name: "w:pgMar",
40723
+ attributes: {}
40724
+ }));
40725
+ Object.entries(DEFAULT_SECTION_PROPS.pageMargins).forEach(([key2, value]) => {
40726
+ const attrKey = `w:${key2}`;
40727
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
40728
+ });
40729
+ return sectPr;
40730
+ }
40633
40731
  function getStyleDefinitions(docx) {
40634
40732
  const styles = docx["word/styles.xml"];
40635
40733
  if (!styles) return [];
@@ -40822,6 +40920,36 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40822
40920
  auto: "sans-serif"
40823
40921
  });
40824
40922
  const DEFAULT_GENERIC_FALLBACK = "sans-serif";
40923
+ const DEFAULT_FONT_SIZE_PT = 10;
40924
+ const collectRunDefaultProperties = (runProps, { allowOverrideTypeface = true, allowOverrideSize = true, themeResolver, state: state2 }) => {
40925
+ if (!runProps?.elements?.length || !state2) return;
40926
+ const fontsNode = runProps.elements.find((el) => el.name === "w:rFonts");
40927
+ if (fontsNode?.attributes) {
40928
+ const themeName = fontsNode.attributes["w:asciiTheme"];
40929
+ if (themeName) {
40930
+ const themeInfo = themeResolver?.(themeName) || {};
40931
+ if ((allowOverrideTypeface || !state2.typeface) && themeInfo.typeface) state2.typeface = themeInfo.typeface;
40932
+ if ((allowOverrideTypeface || !state2.panose) && themeInfo.panose) state2.panose = themeInfo.panose;
40933
+ }
40934
+ const ascii = fontsNode.attributes["w:ascii"];
40935
+ if ((allowOverrideTypeface || !state2.typeface) && ascii) {
40936
+ state2.typeface = ascii;
40937
+ }
40938
+ }
40939
+ const sizeNode = runProps.elements.find((el) => el.name === "w:sz");
40940
+ if (sizeNode?.attributes?.["w:val"]) {
40941
+ const sizeTwips = Number(sizeNode.attributes["w:val"]);
40942
+ if (Number.isFinite(sizeTwips)) {
40943
+ if (state2.fallbackSzTwips === void 0) state2.fallbackSzTwips = sizeTwips;
40944
+ const sizePt = sizeTwips / 2;
40945
+ if (allowOverrideSize || state2.fontSizePt === void 0) state2.fontSizePt = sizePt;
40946
+ }
40947
+ }
40948
+ const kernNode = runProps.elements.find((el) => el.name === "w:kern");
40949
+ if (kernNode?.attributes?.["w:val"]) {
40950
+ if (allowOverrideSize || state2.kern === void 0) state2.kern = kernNode.attributes["w:val"];
40951
+ }
40952
+ };
40825
40953
  const _SuperConverter = class _SuperConverter2 {
40826
40954
  constructor(params2 = null) {
40827
40955
  __privateAdd$2(this, _SuperConverter_instances);
@@ -40949,49 +41077,45 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40949
41077
  }
40950
41078
  getDocumentDefaultStyles() {
40951
41079
  const styles = this.convertedXml["word/styles.xml"];
40952
- if (!styles) return {};
40953
- const defaults = styles.elements[0].elements.find((el) => el.name === "w:docDefaults");
40954
- const rDefault = defaults.elements.find((el) => el.name === "w:rPrDefault");
40955
- if (!rDefault.elements) return {};
40956
- const rElements = rDefault.elements[0].elements;
40957
- const rFonts = rElements?.find((el) => el.name === "w:rFonts");
40958
- if ("elements" in rDefault) {
40959
- const fontThemeName = rElements.find((el) => el.name === "w:rFonts")?.attributes["w:asciiTheme"];
40960
- let typeface, panose, fontSizeNormal;
40961
- if (fontThemeName) {
40962
- const fontInfo = this.getThemeInfo(fontThemeName);
40963
- typeface = fontInfo.typeface;
40964
- panose = fontInfo.panose;
40965
- } else if (rFonts) {
40966
- typeface = rFonts?.attributes["w:ascii"];
40967
- }
40968
- const paragraphDefaults = styles.elements[0].elements.filter((el) => {
40969
- return el.name === "w:style" && el.attributes["w:styleId"] === "Normal";
40970
- }) || [];
40971
- paragraphDefaults.forEach((el) => {
40972
- const rPr = el.elements.find((el2) => el2.name === "w:rPr");
40973
- const fonts = rPr?.elements?.find((el2) => el2.name === "w:rFonts");
40974
- typeface = fonts?.attributes["w:ascii"];
40975
- fontSizeNormal = Number(rPr?.elements?.find((el2) => el2.name === "w:sz")?.attributes["w:val"]) / 2;
40976
- });
40977
- const rPrDefaults = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
40978
- if (rPrDefaults) {
40979
- const rPr = rPrDefaults.elements?.find((el) => el.name === "w:rPr");
40980
- const fonts = rPr?.elements?.find((el) => el.name === "w:rFonts");
40981
- if (fonts?.attributes?.["w:ascii"]) {
40982
- typeface = fonts.attributes["w:ascii"];
40983
- }
40984
- const fontSizeRaw = rPr?.elements?.find((el) => el.name === "w:sz")?.attributes?.["w:val"];
40985
- if (!fontSizeNormal && fontSizeRaw) {
40986
- fontSizeNormal = Number(fontSizeRaw) / 2;
40987
- }
40988
- }
40989
- const fallbackSz = Number(rElements.find((el) => el.name === "w:sz")?.attributes?.["w:val"]);
40990
- const fontSizePt = fontSizeNormal ?? (Number.isFinite(fallbackSz) ? fallbackSz / 2 : void 0) ?? 10;
40991
- const kern = rElements.find((el) => el.name === "w:kern")?.attributes["w:val"];
40992
- const fontFamilyCss = _SuperConverter2.toCssFontFamily(typeface, this.convertedXml);
40993
- return { fontSizePt, kern, typeface, panose, fontFamilyCss };
40994
- }
41080
+ const styleRoot = styles?.elements?.[0];
41081
+ const styleElements = styleRoot?.elements || [];
41082
+ if (!styleElements.length) return {};
41083
+ const defaults = styleElements.find((el) => el.name === "w:docDefaults");
41084
+ const normalStyle = styleElements.find((el) => el.name === "w:style" && el.attributes?.["w:styleId"] === "Normal");
41085
+ const defaultsState = {
41086
+ typeface: void 0,
41087
+ panose: void 0,
41088
+ fontSizePt: void 0,
41089
+ kern: void 0,
41090
+ fallbackSzTwips: void 0
41091
+ };
41092
+ const docDefaultRun = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
41093
+ const docDefaultProps = docDefaultRun?.elements?.find((el) => el.name === "w:rPr") ?? docDefaultRun;
41094
+ collectRunDefaultProperties(docDefaultProps, {
41095
+ allowOverrideTypeface: true,
41096
+ allowOverrideSize: true,
41097
+ themeResolver: (theme) => this.getThemeInfo(theme),
41098
+ state: defaultsState
41099
+ });
41100
+ const normalRunProps = normalStyle?.elements?.find((el) => el.name === "w:rPr") ?? null;
41101
+ collectRunDefaultProperties(normalRunProps, {
41102
+ allowOverrideTypeface: true,
41103
+ allowOverrideSize: true,
41104
+ themeResolver: (theme) => this.getThemeInfo(theme),
41105
+ state: defaultsState
41106
+ });
41107
+ if (defaultsState.fontSizePt === void 0) {
41108
+ if (Number.isFinite(defaultsState.fallbackSzTwips)) defaultsState.fontSizePt = defaultsState.fallbackSzTwips / 2;
41109
+ else defaultsState.fontSizePt = DEFAULT_FONT_SIZE_PT;
41110
+ }
41111
+ const fontFamilyCss = defaultsState.typeface ? _SuperConverter2.toCssFontFamily(defaultsState.typeface, this.convertedXml) : void 0;
41112
+ const result = {};
41113
+ if (defaultsState.fontSizePt !== void 0) result.fontSizePt = defaultsState.fontSizePt;
41114
+ if (defaultsState.kern !== void 0) result.kern = defaultsState.kern;
41115
+ if (defaultsState.typeface) result.typeface = defaultsState.typeface;
41116
+ if (defaultsState.panose) result.panose = defaultsState.panose;
41117
+ if (fontFamilyCss) result.fontFamilyCss = fontFamilyCss;
41118
+ return result;
40995
41119
  }
40996
41120
  getDocumentFonts() {
40997
41121
  const fontTable = this.convertedXml["word/fontTable.xml"];
@@ -55644,9 +55768,11 @@ Please report this to https://github.com/markedjs/marked.`, e) {
55644
55768
  item.editor.view.dom.setAttribute("documentmode", documentMode);
55645
55769
  });
55646
55770
  if (isEditMode) {
55647
- const pm = document.querySelector(".ProseMirror");
55648
- pm.classList.add("header-footer-edit");
55649
- pm.setAttribute("aria-readonly", true);
55771
+ const pm = editor.view?.dom || editor.options.element?.querySelector?.(".ProseMirror");
55772
+ if (pm) {
55773
+ pm.classList.add("header-footer-edit");
55774
+ pm.setAttribute("aria-readonly", true);
55775
+ }
55650
55776
  }
55651
55777
  if (focusedSectionEditor) {
55652
55778
  focusedSectionEditor.view.focus();
@@ -58258,7 +58384,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
58258
58384
  setDocumentMode(documentMode) {
58259
58385
  let cleanedMode = documentMode?.toLowerCase() || "editing";
58260
58386
  if (!this.extensionService || !this.state) return;
58261
- const pm = document.querySelector(".ProseMirror");
58387
+ const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
58262
58388
  if (this.options.role === "viewer") cleanedMode = "viewing";
58263
58389
  if (this.options.role === "suggester" && cleanedMode === "editing") cleanedMode = "suggesting";
58264
58390
  if (cleanedMode === "viewing") {
@@ -59232,9 +59358,11 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59232
59358
  isEditMode: false,
59233
59359
  documentMode: this.options.documentMode
59234
59360
  });
59235
- const pm = document.querySelector(".ProseMirror");
59236
- pm.classList.remove("header-footer-edit");
59237
- pm.setAttribute("aria-readonly", false);
59361
+ const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
59362
+ if (pm) {
59363
+ pm.classList.remove("header-footer-edit");
59364
+ pm.setAttribute("aria-readonly", false);
59365
+ }
59238
59366
  }
59239
59367
  setWordSelection(view, pos);
59240
59368
  }
@@ -77269,7 +77397,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
77269
77397
  const prevSelection = prevState.selection;
77270
77398
  if (selection.from !== prevSelection.from || selection.to !== prevSelection.to) {
77271
77399
  setTimeout(() => {
77272
- const selectedResizableWrapper = document.querySelector(".sd-editor-resizable-wrapper");
77400
+ const searchRoot = editorView?.dom;
77401
+ const selectedResizableWrapper = searchRoot?.querySelector(".sd-editor-resizable-wrapper");
77273
77402
  if (selectedResizableWrapper) {
77274
77403
  showResizeHandles(view2, selectedResizableWrapper);
77275
77404
  } else {
@@ -90805,7 +90934,7 @@ ${style2}
90805
90934
  if (!argument) return;
90806
90935
  item.onActivate({ zoom: argument });
90807
90936
  this.emit("superdoc-command", { item, argument });
90808
- const layers = document.querySelector(this.superdoc.config.selector)?.querySelector(".layers");
90937
+ const layers = this.superdoc.element?.querySelector(".layers");
90809
90938
  if (!layers) return;
90810
90939
  const isMobileDevice = typeof screen.orientation !== "undefined";
90811
90940
  const isSmallScreen = window.matchMedia("(max-width: 834px)").matches;
@@ -110474,6 +110603,9 @@ ${style2}
110474
110603
  this.isDev = this.config.isDev || false;
110475
110604
  this.activeEditor = null;
110476
110605
  this.comments = [];
110606
+ if (!this.config.selector) {
110607
+ throw new Error("SuperDoc: selector is required");
110608
+ }
110477
110609
  this.app.mount(this.config.selector);
110478
110610
  this.readyEditors = 0;
110479
110611
  this.isLocked = this.config.isLocked || false;
@@ -110493,6 +110625,16 @@ ${style2}
110493
110625
  users: this.users
110494
110626
  };
110495
110627
  }
110628
+ /**
110629
+ * Get the SuperDoc container element
110630
+ * @returns {HTMLElement | null}
110631
+ */
110632
+ get element() {
110633
+ if (typeof this.config.selector === "string") {
110634
+ return document.querySelector(this.config.selector);
110635
+ }
110636
+ return this.config.selector;
110637
+ }
110496
110638
  #patchNaiveUIStyles() {
110497
110639
  const cspNonce = this.config.cspNonce;
110498
110640
  const originalCreateElement = document.createElement;
@@ -110516,10 +110658,16 @@ ${style2}
110516
110658
  }
110517
110659
  if (hasDocumentConfig) {
110518
110660
  const normalized = normalizeDocumentEntry(this.config.document);
110519
- this.config.documents = [normalized];
110661
+ this.config.documents = [
110662
+ {
110663
+ id: v4(),
110664
+ ...normalized
110665
+ }
110666
+ ];
110520
110667
  } else if (hasDocumentUrl) {
110521
110668
  this.config.documents = [
110522
110669
  {
110670
+ id: v4(),
110523
110671
  type: DOCX,
110524
110672
  url: this.config.document,
110525
110673
  name: "document.docx",
@@ -110527,33 +110675,34 @@ ${style2}
110527
110675
  }
110528
110676
  ];
110529
110677
  } else if (hasDocumentFile) {
110678
+ const normalized = normalizeDocumentEntry(this.config.document);
110530
110679
  this.config.documents = [
110531
110680
  {
110532
- type: this.config.document.type,
110533
- data: this.config.document,
110534
- name: this.config.document.name,
110535
- isNewFile: true
110681
+ id: v4(),
110682
+ ...normalized
110536
110683
  }
110537
110684
  ];
110538
110685
  } else if (hasDocumentBlob) {
110539
- const docType = this.config.document.type || DOCX;
110540
- let extension = ".docx";
110541
- if (docType === PDF) {
110542
- extension = ".pdf";
110543
- } else if (docType === HTML) {
110544
- extension = ".html";
110545
- }
110686
+ const normalized = normalizeDocumentEntry(this.config.document);
110546
110687
  this.config.documents = [
110547
110688
  {
110548
- type: docType,
110549
- data: this.config.document,
110550
- name: `document${extension}`,
110551
- isNewFile: true
110689
+ id: v4(),
110690
+ ...normalized
110552
110691
  }
110553
110692
  ];
110554
110693
  }
110555
110694
  if (Array.isArray(this.config.documents) && this.config.documents.length > 0) {
110556
- this.config.documents = this.config.documents.map((d2) => normalizeDocumentEntry(d2));
110695
+ this.config.documents = this.config.documents.map((d2) => {
110696
+ const normalized = normalizeDocumentEntry(d2);
110697
+ if (!normalized || typeof normalized !== "object") {
110698
+ return normalized;
110699
+ }
110700
+ const existingId = typeof normalized === "object" && "id" in normalized && normalized.id || d2 && typeof d2 === "object" && "id" in d2 && d2.id;
110701
+ return {
110702
+ ...normalized,
110703
+ id: existingId || v4()
110704
+ };
110705
+ });
110557
110706
  }
110558
110707
  }
110559
110708
  #initVueApp() {