@harbour-enterprises/superdoc 0.12.34-next.3 → 0.13.0-RC2

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 (48) hide show
  1. package/dist/chunks/{super-editor.es-B9igwxv-.es.js → super-editor.es-B6M3d3ew.es.js} +1020 -1010
  2. package/dist/chunks/{super-editor.es-BbaXC2pT.cjs → super-editor.es-CG_E8Uh1.cjs} +1020 -1010
  3. package/dist/style.css +67 -54
  4. package/dist/super-editor/ai-writer.es.js +2 -2
  5. package/dist/super-editor/chunks/{converter-DzsjYmnd.js → converter-DdMoUfYl.js} +310 -441
  6. package/dist/super-editor/chunks/{docx-zipper-DQONSIAh.js → docx-zipper-CaPhHWh0.js} +1 -1
  7. package/dist/super-editor/chunks/{editor-CO-n6iZ8.js → editor-DfrK7LO9.js} +1653 -1507
  8. package/dist/super-editor/chunks/{toolbar-CNeu8BVd.js → toolbar-h35AzYvu.js} +2 -2
  9. package/dist/super-editor/converter.es.js +1 -1
  10. package/dist/super-editor/core/Attribute.d.ts +2 -2
  11. package/dist/super-editor/core/Editor.d.ts +8 -1
  12. package/dist/super-editor/core/Editor.d.ts.map +1 -1
  13. package/dist/super-editor/core/Schema.d.ts +2 -2
  14. package/dist/super-editor/core/commands/splitListItem.d.ts +1 -1
  15. package/dist/super-editor/core/commands/splitListItem.d.ts.map +1 -1
  16. package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts +235 -0
  17. package/dist/super-editor/core/helpers/list-numbering-helpers.d.ts.map +1 -0
  18. package/dist/super-editor/core/super-converter/SuperConverter.d.ts +1 -1
  19. package/dist/super-editor/core/super-converter/SuperConverter.d.ts.map +1 -1
  20. package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
  21. package/dist/super-editor/core/super-converter/v2/importer/listImporter.d.ts +32 -5
  22. package/dist/super-editor/core/super-converter/v2/importer/listImporter.d.ts.map +1 -1
  23. package/dist/super-editor/core/super-converter/v2/importer/paragraphNodeImporter.d.ts.map +1 -1
  24. package/dist/super-editor/docx-zipper.es.js +2 -2
  25. package/dist/super-editor/editor.es.js +3 -3
  26. package/dist/super-editor/extensions/linked-styles/linked-styles.d.ts.map +1 -1
  27. package/dist/super-editor/extensions/list-item/ListItemNodeView.d.ts +56 -0
  28. package/dist/super-editor/extensions/list-item/ListItemNodeView.d.ts.map +1 -0
  29. package/dist/super-editor/extensions/list-item/list-item.d.ts.map +1 -1
  30. package/dist/super-editor/extensions/ordered-list/ordered-list.d.ts.map +1 -1
  31. package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
  32. package/dist/super-editor/file-zipper.es.js +1 -1
  33. package/dist/super-editor/style.css +40 -27
  34. package/dist/super-editor/super-editor.es.js +6 -6
  35. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts +3 -0
  36. package/dist/super-editor/tests/e2e/test-app/dist/assets/index-BTMvkUyI.d.ts.map +1 -0
  37. package/dist/super-editor/tests/e2e/test-app/vite.config.d.ts +1 -1
  38. package/dist/super-editor/tests/editor/listItemHelpers.test.d.ts +2 -0
  39. package/dist/super-editor/tests/editor/listItemHelpers.test.d.ts.map +1 -0
  40. package/dist/super-editor/tests/export/export-helpers/export-helpers.d.ts.map +1 -1
  41. package/dist/super-editor/toolbar.es.js +2 -2
  42. package/dist/super-editor.cjs +1 -1
  43. package/dist/super-editor.es.js +1 -1
  44. package/dist/superdoc.cjs +3 -5
  45. package/dist/superdoc.es.js +4 -6
  46. package/dist/superdoc.umd.js +1024 -1016
  47. package/dist/superdoc.umd.js.map +1 -1
  48. package/package.json +1 -1
@@ -24699,16 +24699,6 @@
24699
24699
  return void 0;
24700
24700
  }
24701
24701
  };
24702
- const baseOrderedListDef$1 = {
24703
- "attributes": {
24704
- "w:abstractNumId": "1"
24705
- }
24706
- };
24707
- const baseBulletList$1 = {
24708
- "attributes": {
24709
- "w:abstractNumId": "0"
24710
- }
24711
- };
24712
24702
  const baseNumbering = {
24713
24703
  "declaration": {
24714
24704
  "attributes": {
@@ -26327,7 +26317,7 @@
26327
26317
  };
26328
26318
  pPrElements.push(spacingElement);
26329
26319
  }
26330
- if (indent) {
26320
+ if (indent && Object.values(indent).some((v) => v !== 0)) {
26331
26321
  const { left: left2, right: right2, firstLine, hanging } = indent;
26332
26322
  const attributes = {};
26333
26323
  if (left2 || left2 === 0) attributes["w:left"] = pixelsToTwips(left2);
@@ -26342,7 +26332,7 @@
26342
26332
  attributes
26343
26333
  };
26344
26334
  pPrElements.push(indentElement);
26345
- } else if (textIndent) {
26335
+ } else if (textIndent && textIndent !== "0in") {
26346
26336
  const indentElement = {
26347
26337
  name: "w:ind",
26348
26338
  attributes: {
@@ -26391,6 +26381,9 @@
26391
26381
  if (sectPr) {
26392
26382
  pPrElements.push(sectPr);
26393
26383
  }
26384
+ const numPr = node2.attrs?.paragraphProperties?.elements?.find((n) => n.name === "w:numPr");
26385
+ const hasNumPr = pPrElements.some((n) => n.name === "w:numPr");
26386
+ if (numPr && !hasNumPr) pPrElements.push(numPr);
26394
26387
  if (!pPrElements.length) return null;
26395
26388
  return {
26396
26389
  name: "w:pPr",
@@ -26639,157 +26632,68 @@
26639
26632
  return newId;
26640
26633
  }
26641
26634
  function translateList(params2) {
26642
- const { type: type2 } = params2.node;
26643
- const flatContent = flattenContent(params2);
26644
- const listNodes = [];
26645
- flatContent.forEach((listNode) => {
26646
- const { level, listType, pPrs: additionalPprs, content, attrs = {} } = listNode;
26647
- const attrsNumId = listNode.attrs.numId;
26648
- const actualNumId = attrsNumId || listNode.listId;
26649
- const listId = actualNumId ?? generateNewListDefinition$1(params2, listType);
26650
- const pPr = getListParagraphProperties(level, listId, additionalPprs);
26651
- content.forEach((contentNode, index2) => {
26652
- const paragraphNode = Object.assign({}, contentNode);
26653
- paragraphNode.attrs = {
26654
- ...paragraphNode.attrs,
26655
- ...listNode.attrs
26656
- };
26657
- const outputNode = exportSchemaToJson({ ...params2, node: paragraphNode });
26658
- if (!outputNode.elements) {
26659
- outputNode.elements = [];
26660
- }
26661
- if (Array.isArray(outputNode)) {
26662
- const mapped = [];
26663
- outputNode.forEach((el, index22) => {
26664
- mapped.push(...el.elements);
26665
- if (index22 < outputNode.length - 1) mapped.push({ name: "w:br", type: "element" });
26666
- });
26667
- mapped.unshift(carbonCopy(pPr));
26668
- return listNodes.push({ name: "w:p", elements: mapped });
26669
- }
26670
- const propsElementIndex = outputNode.elements.findIndex((e) => e.name === "w:pPr");
26671
- const content2 = outputNode.elements.filter((e) => e.name !== "w:pPr");
26672
- if (!content2.length && !Array.isArray(outputNode)) {
26673
- const elements = contentNode.attrs.paragraphProperties ? [contentNode.attrs.paragraphProperties] : [];
26674
- const spacer = {
26675
- name: "w:p",
26676
- type: "element",
26677
- elements
26678
- };
26679
- return listNodes.push(spacer);
26680
- }
26681
- outputNode.elements = outputNode.elements.map((el, index22) => {
26682
- if (el.name === "w:sdt") {
26683
- const contentIndex = el.elements.findIndex((e) => e.name === "w:sdtContent");
26684
- const content3 = el.elements[contentIndex];
26685
- const innerContent = content3.elements[0];
26686
- if (innerContent.name === "w:p") {
26687
- content3.elements = innerContent.elements;
26688
- }
26689
- return {
26690
- name: "w:r",
26691
- type: "element",
26692
- elements: [el]
26693
- };
26694
- } else {
26695
- return el;
26696
- }
26697
- });
26698
- const { attributes: generalAttributes } = attrs;
26699
- const { originalInlineRunProps } = generalAttributes || {};
26700
- if (originalInlineRunProps) pPr.elements.push(originalInlineRunProps);
26701
- if (propsElementIndex === -1) {
26702
- outputNode.elements.unshift(carbonCopy(pPr));
26703
- } else {
26704
- const resultProps = carbonCopy(pPr).elements.map((item) => {
26705
- const isChanged = outputNode.elements[propsElementIndex].elements.find((e) => e.name === item.name);
26706
- return isChanged ? isChanged : item;
26707
- });
26708
- outputNode.elements[propsElementIndex].elements = resultProps;
26709
- }
26710
- let importedFontSize;
26711
- if (listNode.attrs?.importedFontSize) {
26712
- const fontNoUnit = parseInt(listNode.attrs.importedFontSize.split("pt")[0]);
26713
- importedFontSize = {
26714
- name: "w:sz",
26715
- attributes: { "w:val": fontNoUnit * 2 }
26716
- };
26717
- }
26718
- let importedFontFamily;
26719
- if (listNode.attrs?.importedFontFamily) {
26720
- importedFontFamily = {
26721
- name: "w:rFonts",
26722
- attributes: { "w:ascii": listNode.attrs?.importedFontFamily, "w:hAnsi": listNode.attrs?.importedFontFamily }
26723
- };
26724
- }
26725
- const rPrElement = outputNode.elements.find((e) => e.name === "w:rPr");
26726
- if (rPrElement) {
26727
- rPrElement.elements.push(fontSize);
26728
- } else if (importedFontSize || importedFontFamily) {
26729
- const elements = [];
26730
- if (importedFontSize) elements.push(importedFontSize);
26731
- if (importedFontFamily) elements.push(importedFontFamily);
26732
- outputNode.elements.unshift({ name: "w:rPr", elements });
26733
- }
26734
- if (index2 !== 0) {
26735
- const currentpPr = outputNode.elements.find((e) => e.name === "w:pPr");
26736
- const numPrIndex = currentpPr.elements.findIndex((e) => e.name === "w:numPr");
26737
- if (numPrIndex !== -1) currentpPr.elements.splice(numPrIndex, 1);
26738
- }
26739
- listNodes.push(outputNode);
26740
- });
26741
- });
26742
- return listNodes;
26743
- }
26744
- function generateNewListDefinition$1(params2, listType) {
26745
- const nextNumbering = getLargestListDefinitionIndex(params2.converter?.numbering?.definitions);
26746
- const definition = listType === "bullet" ? baseBulletList$1 : baseOrderedListDef$1;
26747
- const listId = nextNumbering;
26748
- const abstractId = definition.attributes["w:abstractNumId"];
26749
- const newNumDef = {
26635
+ const { node: node2 } = params2;
26636
+ const { attrs = {} } = node2;
26637
+ if (node2.content.length > 1) {
26638
+ flattenContent(params2);
26639
+ throw new Error("Multi list not supported yet");
26640
+ }
26641
+ const listItem = node2.content[0];
26642
+ const { numId, level } = listItem.attrs;
26643
+ let numPrTag;
26644
+ if (numId) {
26645
+ numPrTag = generateNumPrTag(numId, level);
26646
+ }
26647
+ const paragraphNode = node2.content[0]?.content[0];
26648
+ const outputNode = exportSchemaToJson({ ...params2, node: paragraphNode });
26649
+ const pPr = outputNode.elements.find((n) => n.name === "w:pPr");
26650
+ if (pPr && pPr.elements) pPr.elements.unshift(numPrTag);
26651
+ const indentTag = restoreIndent(listItem.attrs.indent);
26652
+ indentTag && pPr?.elements?.push(indentTag);
26653
+ const runNode = outputNode.elements?.find((n) => n.name === "w:r");
26654
+ const rPr = runNode?.elements?.find((n) => n.name === "w:rPr");
26655
+ if (rPr) pPr.elements.push(rPr);
26656
+ if (listItem.attrs.numPrType !== "inline") {
26657
+ const numPrIndex = pPr?.elements?.findIndex((e) => e.name === "w:numPr");
26658
+ if (numPrIndex !== -1) {
26659
+ pPr?.elements?.splice(numPrIndex, 1);
26660
+ }
26661
+ }
26662
+ return [outputNode];
26663
+ }
26664
+ const restoreIndent = (indent) => {
26665
+ const attributes = {};
26666
+ if (!indent) indent = {};
26667
+ if (indent.left || indent.left === 0) attributes["w:left"] = pixelsToTwips(indent.left);
26668
+ if (indent.right || indent.right === 0) attributes["w:right"] = pixelsToTwips(indent.right);
26669
+ if (indent.firstLine || indent.firstLine === 0) attributes["w:firstLine"] = pixelsToTwips(indent.firstLine);
26670
+ if (indent.hanging || indent.hanging === 0) attributes["w:hanging"] = pixelsToTwips(indent.hanging);
26671
+ if (indent.leftChars || indent.leftChars === 0) attributes["w:leftChars"] = pixelsToTwips(indent.leftChars);
26672
+ if (!Object.keys(attributes).length) return;
26673
+ return {
26674
+ name: "w:ind",
26750
26675
  type: "element",
26751
- name: "w:num",
26752
- attributes: {
26753
- "w:numId": String(listId),
26754
- "w16cid:durableId": "485517411"
26755
- },
26756
- elements: [
26757
- { name: "w:abstractNumId", attributes: { "w:val": String(abstractId) } }
26758
- ]
26676
+ attributes
26759
26677
  };
26760
- params2.converter.numbering.definitions[listId] = newNumDef;
26761
- return listId;
26762
- }
26763
- const getLargestListDefinitionIndex = (definitions) => {
26764
- if (!definitions || !Object.keys(definitions).length) return 0;
26765
- const maxKey = Math.max(...Object.keys(definitions).map((key) => parseInt(key, 10)));
26766
- return maxKey + 1;
26767
26678
  };
26768
- function getListParagraphProperties(level, numId, additionalPprs = []) {
26679
+ const generateNumPrTag = (numId, level) => {
26769
26680
  return {
26770
- name: "w:pPr",
26681
+ name: "w:numPr",
26771
26682
  type: "element",
26772
26683
  elements: [
26773
26684
  {
26774
- name: "w:numPr",
26685
+ name: "w:numId",
26775
26686
  type: "element",
26776
- elements: [
26777
- {
26778
- name: "w:ilvl",
26779
- type: "element",
26780
- attributes: { "w:val": level }
26781
- },
26782
- {
26783
- name: "w:numId",
26784
- type: "element",
26785
- attributes: { "w:val": numId }
26786
- }
26787
- ]
26687
+ attributes: { "w:val": numId }
26788
26688
  },
26789
- ...additionalPprs
26689
+ {
26690
+ name: "w:ilvl",
26691
+ type: "element",
26692
+ attributes: { "w:val": level }
26693
+ }
26790
26694
  ]
26791
26695
  };
26792
- }
26696
+ };
26793
26697
  function flattenContent({ node: node2 }) {
26794
26698
  const { content, attrs = {} } = node2;
26795
26699
  const { listId, syncId } = node2.attrs || {};
@@ -26860,10 +26764,7 @@
26860
26764
  if (!row.content) continue;
26861
26765
  for (let cellIndex = 0; cellIndex < row.content?.length; cellIndex++) {
26862
26766
  const cell = row.content[cellIndex];
26863
- if (!cell) {
26864
- console.log("no cell");
26865
- continue;
26866
- }
26767
+ if (!cell) continue;
26867
26768
  const { attrs } = cell;
26868
26769
  if (attrs.rowspan > 1) {
26869
26770
  const rowsToChange = content.slice(rowIndex + 1, rowIndex + attrs.rowspan);
@@ -28592,11 +28493,6 @@
28592
28493
  const isPropertiesElement = (element) => {
28593
28494
  return !!SuperConverter.propertyTypes[element.name || element.type];
28594
28495
  };
28595
- function hasTextNode(elements) {
28596
- const runs = elements.filter((el) => el.name === "w:r");
28597
- const runsHaveText = runs.some((run2) => run2.elements.some((el) => el.name === "w:t"));
28598
- return runsHaveText;
28599
- }
28600
28496
  const handleTrackChangeNode = (params2) => {
28601
28497
  const { nodes, nodeListHandler: nodeListHandler2 } = params2;
28602
28498
  if (nodes.length === 0 || !(nodes[0].name === "w:del" || nodes[0].name === "w:ins" || nodes[0].name === "w:sdt")) {
@@ -28798,219 +28694,118 @@
28798
28694
  };
28799
28695
  const handleListNode = (params2) => {
28800
28696
  const { nodes, lists, docx } = params2;
28801
- if (nodes.length === 0 || nodes[0].name !== "w:p") {
28697
+ if (nodes.length === 0 || nodes[0].name !== "w:p" || nodes[0].isList) {
28802
28698
  return { nodes: [], consumed: 0 };
28803
28699
  }
28804
28700
  const node2 = carbonCopy(nodes[0]);
28805
- const processedElements = preProcessNodesForFldChar(node2.elements);
28806
- node2.elements = processedElements;
28807
- const originalPpr = node2.elements.find((el) => el.name === "w:pPr");
28808
- if (testForList(node2, docx)) {
28809
- const siblings = carbonCopy(nodes);
28810
- const listItems = [];
28811
- let possibleList = siblings.shift();
28812
- while (possibleList && testForList(possibleList, docx)) {
28813
- listItems.push(possibleList);
28814
- possibleList = siblings.shift();
28815
- if (possibleList?.elements && !hasTextNode(possibleList.elements)) {
28816
- listItems.push(possibleList);
28817
- possibleList = siblings.shift();
28818
- }
28819
- }
28820
- const listNodes = handleListNodes({ listItems, params: params2, originalPpr });
28701
+ const isList2 = testForList(node2, docx);
28702
+ if (isList2) {
28703
+ node2.isList = true;
28704
+ const result = handleListNodes(params2, node2);
28821
28705
  return {
28822
- nodes: [listNodes],
28823
- consumed: listItems.filter((i2) => i2.seen).length,
28824
- lists
28706
+ nodes: [result],
28707
+ consumed: 1
28825
28708
  };
28826
28709
  } else {
28827
- return { nodes: [], consumed: 0, lists };
28710
+ return { nodes: [], consumed: 0 };
28828
28711
  }
28829
28712
  };
28830
28713
  const listHandlerEntity = {
28831
28714
  handlerName: "listHandler",
28832
28715
  handler: handleListNode
28833
28716
  };
28834
- function handleListNodes({
28835
- listItems,
28836
- originalPpr,
28837
- params: params2,
28838
- listLevel = 0,
28839
- actualListLevel = 0,
28840
- currentListNumId = null,
28841
- path = "",
28842
- isNested = false
28843
- }) {
28717
+ function handleListNodes(params2, node2) {
28844
28718
  const { docx, nodeListHandler: nodeListHandler2, lists } = params2;
28845
- const parsedListItems = [];
28846
- let overallListType;
28847
- let listStyleType;
28848
- const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
28849
- (e) => e.handlerName === "standardNodeHandler"
28850
- )?.handler;
28851
- if (!handleStandardNode2) {
28852
- console.error("Standard node handler not found");
28853
- return { nodes: [], consumed: 0 };
28854
- }
28855
- const initialpPr = listItems[0].elements.find((el) => el.name === "w:pPr");
28719
+ const initialpPr = node2.elements.find((el) => el.name === "w:pPr");
28856
28720
  const styleTag = initialpPr?.elements?.find((el) => el.name === "w:pStyle");
28857
28721
  const styleId = styleTag?.attributes["w:val"];
28858
- const numPrTag = getNumPrRecursive({ node: listItems[0], styleId, docx });
28859
- currentListNumId = getNumIdFromTag(numPrTag);
28860
- actualListLevel = parseInt(numPrTag?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"]) || 0;
28861
- if (actualListLevel === void 0) actualListLevel = getOutlineLevelFromStyleTag(styleId, docx);
28862
- let lastNestedListLevel = 0;
28863
- for (let [index2, item] of listItems.entries()) {
28864
- if (item.seen) continue;
28865
- const { attributes, elements, marks = [] } = parseProperties(item);
28866
- const matchedStyle = getStyleTagFromStyleId(styleId, docx) || {};
28867
- const { marks: styleIdMarks } = parseProperties(matchedStyle);
28868
- const textStyle = marks.find((mark) => mark.type === "textStyle");
28869
- const textStyleFromStyles = styleIdMarks?.find((mark) => mark.type === "textStyle");
28870
- const {
28871
- listType,
28872
- listOrderingType,
28873
- ilvl,
28874
- listrPrs,
28875
- listpPrs,
28876
- start: start2,
28877
- lvlText,
28878
- lvlJc,
28879
- numId
28880
- } = getNodeNumberingDefinition(item, listLevel, docx);
28881
- listStyleType = listOrderingType;
28882
- const intLevel = parseInt(ilvl);
28883
- const isRoot = actualListLevel === intLevel && numId === currentListNumId;
28884
- const isSameListLevelDef = isSameListLevelDefsExceptStart({
28885
- firstListId: numId,
28886
- secondListId: currentListNumId,
28887
- level: intLevel,
28888
- pStyleId: null,
28889
- docx
28890
- });
28891
- const isDifferentList = numId !== currentListNumId && !isSameListLevelDef;
28892
- const isNested2 = listLevel < intLevel || listLevel === intLevel && isDifferentList && lastNestedListLevel === listLevel;
28893
- if (!lists[currentListNumId]) lists[currentListNumId] = {};
28894
- if (!lists[currentListNumId][listLevel]) {
28895
- lists[currentListNumId][listLevel] = Number(start2);
28896
- }
28897
- const nodeAttributes = {};
28898
- if (isRoot && !isNested2) {
28899
- overallListType = listType;
28900
- item.seen = true;
28901
- const schemaElements = [];
28902
- const nodeContents = nodeListHandler2.handler({ ...params2, nodes: [attributes.paragraphProperties, ...elements] })?.filter((n) => n) || [];
28903
- let parNode = {
28904
- type: "paragraph",
28905
- content: nodeContents
28906
- };
28907
- if (parNode.content) {
28908
- parNode = {
28909
- ...parNode,
28910
- attrs: {
28911
- textAlign: textStyle?.attrs.textAlign || textStyleFromStyles?.attrs.textAlign || null,
28912
- rsidRDefault: attributes?.["w:rsidRDefault"] || null,
28913
- styleId
28914
- },
28915
- content: mergeTextNodes(parNode.content)
28916
- };
28917
- }
28918
- schemaElements.push(parNode);
28919
- lastNestedListLevel = listLevel;
28920
- let thisItemPath = [];
28921
- if (listStyleType !== "bullet") {
28922
- thisItemPath = [...path, lists[currentListNumId][listLevel]];
28923
- lists[currentListNumId][actualListLevel]++;
28924
- }
28925
- if (!path.length && actualListLevel > 0) {
28926
- const currentDef = lists[currentListNumId];
28927
- if (currentDef) {
28928
- const newPath = [];
28929
- Object.keys(currentDef).forEach((key) => {
28930
- newPath.push(currentDef[key]);
28931
- });
28932
- thisItemPath = newPath;
28933
- }
28934
- }
28935
- const pPr = item.elements.find((el) => el.name === "w:pPr");
28936
- let indent = pPr?.elements.find((el) => el.name === "w:ind");
28937
- const pPrFromStyles = matchedStyle?.elements?.find((style2) => style2.name === "w:pPr");
28938
- const stylesIndent = pPrFromStyles?.elements?.find((el) => el.name === "w:ind");
28939
- if (!indent) indent = stylesIndent;
28940
- if (indent) {
28941
- const indentAttrs = {};
28942
- if (!indent.attributes) indent.attributes = {};
28943
- if (indent.attributes["w:left"] !== void 0) indentAttrs.left = twipsToPixels(indent.attributes["w:left"]);
28944
- if (indent.attributes["w:right"] !== void 0) indentAttrs.right = twipsToPixels(indent.attributes["w:right"]);
28945
- if (indent.attributes["w:firstLine"] !== void 0) indentAttrs.firstLine = twipsToPixels(indent.attributes["w:firstLine"]);
28946
- if (indent.attributes["w:hanging"] !== void 0) indentAttrs.hanging = twipsToPixels(indent.attributes["w:hanging"]);
28947
- nodeAttributes["indent"] = indentAttrs;
28948
- }
28949
- if (listpPrs) nodeAttributes["listParagraphProperties"] = listpPrs;
28950
- if (listrPrs) nodeAttributes["listRunProperties"] = listrPrs;
28951
- nodeAttributes["textStyle"] = textStyle;
28952
- nodeAttributes["order"] = start2;
28953
- nodeAttributes["lvlText"] = lvlText;
28954
- nodeAttributes["lvlJc"] = textStyle?.attrs.textAlign;
28955
- nodeAttributes["listLevel"] = thisItemPath;
28956
- nodeAttributes["listNumberingType"] = listOrderingType;
28957
- nodeAttributes["attributes"] = {
28958
- parentAttributes: item?.attributes || null
28959
- };
28960
- const originalRunProps = originalPpr?.elements?.find((el) => el.name === "w:rPr");
28961
- if (originalRunProps) {
28962
- nodeAttributes.attributes["originalInlineRunProps"] = originalRunProps;
28963
- }
28964
- nodeAttributes["numId"] = numId;
28965
- if (docx) {
28966
- nodeAttributes["spacing"] = getParagraphSpacing(item, docx, styleId);
28967
- }
28968
- const newListItem = createListItem(schemaElements, nodeAttributes, []);
28969
- parsedListItems.push(newListItem);
28970
- } else if (isNested2) {
28971
- const newPath = [...path, lists[currentListNumId][listLevel]];
28972
- const sublist = handleListNodes({
28973
- listItems: listItems.slice(index2),
28974
- originalPpr,
28975
- params: params2,
28976
- listLevel: listLevel + 1,
28977
- actualListLevel: listLevel,
28978
- currentListNumId: numId,
28979
- path: newPath,
28980
- isNested: true
28981
- });
28982
- lastNestedListLevel = sublist.lastNestedListLevel;
28983
- delete sublist.lastNestedListLevel;
28984
- const lastItem = parsedListItems[parsedListItems.length - 1];
28985
- if (!lastItem) {
28986
- parsedListItems.push(createListItem([sublist], nodeAttributes, []));
28987
- } else {
28988
- lastItem.content.push(sublist);
28989
- }
28990
- } else if (!numId) {
28991
- item.seen = true;
28992
- const n = handleStandardNode2({ ...params2, nodes: [item] }).nodes[0];
28993
- parsedListItems[parsedListItems.length - 1]?.content.push(n);
28994
- } else {
28995
- lastNestedListLevel = listLevel;
28996
- if (listLevel > 0 && item.elements[0].elements.find((el) => el.name === "w:numPr")) {
28997
- lists[currentListNumId][listLevel] = 0;
28722
+ const { numPr: numPrTag, type: numPrType } = getNumPrRecursive({ node: node2, styleId, docx });
28723
+ const currentListNumId = getNumIdFromTag(numPrTag);
28724
+ const iLvlTag = numPrTag?.elements?.find((el) => el.name === "w:ilvl");
28725
+ let iLvl = Number(iLvlTag?.attributes["w:val"]);
28726
+ if (!iLvl && iLvl !== 0) iLvl = getOutlineLevelFromStyleTag(styleId, docx);
28727
+ const {
28728
+ listType,
28729
+ listOrderingType,
28730
+ listrPrs,
28731
+ listpPrs,
28732
+ start: start2,
28733
+ lvlText,
28734
+ lvlJc
28735
+ } = getNodeNumberingDefinition(node2, iLvl, docx);
28736
+ if (!listType) {
28737
+ const pPrIndex = node2.elements.findIndex((el) => el.name === "w:pPr");
28738
+ const pPr = node2.elements[pPrIndex];
28739
+ const numPrIndex2 = pPr?.elements?.findIndex((el) => el.name === "w:numPr");
28740
+ if (numPrIndex2 >= 0) {
28741
+ pPr?.elements?.splice(numPrIndex2, 1);
28742
+ node2.elements[pPrIndex] = pPr;
28743
+ }
28744
+ const styleIdIndex = pPr?.elements?.findIndex((el) => el.name === "w:pStyle");
28745
+ if (styleIdIndex >= 0) pPr?.elements?.splice(styleIdIndex, 1);
28746
+ const fallBack = nodeListHandler2.handler({ ...params2, nodes: [node2] })?.filter((n) => n);
28747
+ return fallBack[0];
28748
+ }
28749
+ if (!lists[currentListNumId]) lists[currentListNumId] = { levels: {} };
28750
+ const currentListByNumId = lists[currentListNumId];
28751
+ if (!currentListByNumId.levels[iLvl]) currentListByNumId.levels[iLvl] = Number(start2) || 1;
28752
+ else currentListByNumId.levels[iLvl]++;
28753
+ Object.keys(currentListByNumId.levels).forEach((key) => {
28754
+ const level = Number(key);
28755
+ if (level > iLvl) {
28756
+ delete currentListByNumId.levels[level];
28757
+ }
28758
+ });
28759
+ const path = [];
28760
+ if (iLvl > 0) {
28761
+ for (let i2 = iLvl; i2 >= 0; i2--) {
28762
+ const { start: lvlStart } = getNodeNumberingDefinition(node2, i2, docx);
28763
+ if (!currentListByNumId.levels[i2]) {
28764
+ currentListByNumId.levels[i2] = Number(lvlStart);
28998
28765
  }
28999
- break;
28766
+ path.unshift(currentListByNumId.levels[i2]);
29000
28767
  }
29001
28768
  }
28769
+ if (!path.length) path.push(currentListByNumId.levels[iLvl]);
28770
+ const attrs = {};
28771
+ attrs.lvlText = lvlText;
28772
+ attrs.listLevel = path;
28773
+ attrs.listNumberingType = listOrderingType;
28774
+ attrs.numId = currentListNumId;
28775
+ attrs.level = iLvl;
28776
+ attrs.numPrType = numPrType;
28777
+ attrs.styleId = styleId;
28778
+ node2.isList = true;
28779
+ const nodePpr = node2.attrs?.paragraphProperties?.elements?.find((el) => el.name === "w:pPr");
28780
+ const numPrIndex = node2.attrs?.paragraphProperties?.elements?.findIndex((el) => el.name === "w:numPr");
28781
+ nodePpr?.elements?.splice(numPrIndex, 1);
28782
+ const listContents = nodeListHandler2.handler({ ...params2, nodes: [node2] });
28783
+ const innerParagraph = listContents.find((el) => el.type === "paragraph");
28784
+ const firstElement = innerParagraph.content[0];
28785
+ firstElement?.marks?.find((mark) => mark.type === "textStyle");
28786
+ attrs.indent = listpPrs?.indent;
28787
+ const processedContents = listContents.map((el, index2) => {
28788
+ const { attrs: elementAttrs } = el;
28789
+ const { indent, textIndent, paragraphProperties, ...rest } = elementAttrs;
28790
+ if (index2 === 0 && !attrs.indent) attrs.indent = indent;
28791
+ return {
28792
+ ...el,
28793
+ attrs: rest
28794
+ };
28795
+ });
28796
+ const listItem = {
28797
+ type: "listItem",
28798
+ content: processedContents || [],
28799
+ attrs
28800
+ };
29002
28801
  const resultingList = {
29003
- type: overallListType || "bulletList",
29004
- content: parsedListItems,
28802
+ type: listType,
28803
+ content: [listItem],
29005
28804
  attrs: {
29006
- "list-style-type": listStyleType,
29007
- listId: currentListNumId,
29008
- attributes: {
29009
- parentAttributes: listItems[0]?.attributes || null
29010
- }
28805
+ "list-style-type": listOrderingType,
28806
+ listId: currentListNumId
29011
28807
  }
29012
28808
  };
29013
- if (isNested) resultingList.lastNestedListLevel = lastNestedListLevel;
29014
28809
  return resultingList;
29015
28810
  }
29016
28811
  const getOutlineLevelFromStyleTag = (styleTag, docx) => {
@@ -29029,11 +28824,27 @@
29029
28824
  const paragraphStyle = pPr.elements?.find((el) => el.name === "w:pStyle");
29030
28825
  let numPr = pPr.elements?.find((el) => el.name === "w:numPr");
29031
28826
  let numId = getNumIdFromTag(numPr);
28827
+ const ilvlTag = numPr?.elements?.find((el) => el.name === "w:ilvl");
28828
+ let ilvl = ilvlTag?.attributes["w:val"];
28829
+ let outlinelvl;
29032
28830
  const styleId = paragraphStyle?.attributes["w:val"];
29033
- if (styleId && !numId) {
29034
- numPr = getNumPrRecursive({ node: node2, styleId, docx });
28831
+ const styleTag = getStyleTagFromStyleId(styleId, docx);
28832
+ if (styleTag && !numId) {
28833
+ const { numPr: numPrRecursve, type: type2 } = getNumPrRecursive({ node: node2, styleId, docx });
28834
+ numPr = numPrRecursve;
29035
28835
  numId = getNumIdFromTag(numPr);
29036
- }
28836
+ const stylePpr = styleTag?.elements?.find((el) => el.name === "w:pPr");
28837
+ stylePpr?.elements?.find((el) => el.name === "w:numPr");
28838
+ ilvl = stylePpr?.elements?.find((el) => el.name === "w:ilvl")?.attributes["w:val"];
28839
+ outlinelvl = stylePpr?.elements?.find((el) => el.name === "w:outlineLvl")?.attributes["w:val"];
28840
+ ilvl = outlinelvl || ilvl;
28841
+ }
28842
+ const numbering = docx["word/numbering.xml"] || {};
28843
+ const numDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:numId"] == numId);
28844
+ const abstractNumId = numDefinition?.elements?.find((el) => el.name === "w:abstractNumId")?.attributes["w:val"];
28845
+ const abstractNumDefinition = numbering?.elements?.[0].elements?.find((el) => el.attributes?.["w:abstractNumId"] == abstractNumId);
28846
+ const levelDefinition = abstractNumDefinition?.elements?.find((el) => el.name === "w:lvl" && el.attributes?.["w:ilvl"] == ilvl);
28847
+ if (!levelDefinition) return false;
29037
28848
  return !!numId;
29038
28849
  }
29039
28850
  const getNumIdFromTag = (tag) => {
@@ -29041,20 +28852,19 @@
29041
28852
  };
29042
28853
  function getStyleTagFromStyleId(styleId, docx) {
29043
28854
  const styles = docx["word/styles.xml"];
29044
- if (!styles) {
29045
- return {};
29046
- }
28855
+ if (!styles) return {};
29047
28856
  const styleEls = styles.elements;
29048
28857
  const wStyles = styleEls.find((el) => el.name === "w:styles");
29049
28858
  const styleTags = wStyles.elements.filter((style2) => style2.name === "w:style");
29050
- return styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
28859
+ const styleDef = styleTags.find((tag) => tag.attributes["w:styleId"] === styleId);
28860
+ return styleDef;
29051
28861
  }
29052
28862
  function getNumPrRecursive({ node: node2, styleId, docx, seenStyleIds = /* @__PURE__ */ new Set() }) {
29053
28863
  const initialPpr = node2?.elements?.find((el) => el.name === "w:pPr");
29054
28864
  const initialNumPr = initialPpr?.elements?.find((el) => el.name === "w:numPr");
29055
28865
  let numPr = initialNumPr;
29056
28866
  let numId = getNumIdFromTag(numPr);
29057
- if (numId) return numPr;
28867
+ if (numId) return { numPr, type: "inline" };
29058
28868
  const matchedStyle = getStyleTagFromStyleId(styleId, docx);
29059
28869
  const pPr = matchedStyle?.elements?.find((style2) => style2.name === "w:pPr");
29060
28870
  numPr = pPr?.elements?.find((style2) => style2.name === "w:numPr");
@@ -29063,18 +28873,10 @@
29063
28873
  if (!numId && !seenStyleIds.has(styleId)) {
29064
28874
  const basedOnStyleId = basedOn?.attributes["w:val"];
29065
28875
  seenStyleIds.add(styleId);
29066
- if (!basedOnStyleId) return null;
28876
+ if (!basedOnStyleId) return {};
29067
28877
  return getNumPrRecursive({ styleId: basedOnStyleId, docx, seenStyleIds });
29068
28878
  }
29069
- return numPr;
29070
- }
29071
- function createListItem(content, attrs, marks) {
29072
- return {
29073
- type: "listItem",
29074
- content,
29075
- attrs,
29076
- marks
29077
- };
28879
+ return { numPr, type: "numbering" };
29078
28880
  }
29079
28881
  const orderedListTypes = [
29080
28882
  "decimal",
@@ -29112,18 +28914,6 @@
29112
28914
  "disc"
29113
28915
  // Disc bullets (●)
29114
28916
  ];
29115
- const isSameListLevelDefsExceptStart = ({ firstListId, secondListId, level, pStyleId, docx }) => {
29116
- const { numFmt, lvlText, lvlJc } = getListLevelDefinitionTag(firstListId, level, pStyleId, docx);
29117
- const {
29118
- numFmt: numFmt2,
29119
- lvlText: lvlText2,
29120
- lvlJc: lvlJc2
29121
- } = getListLevelDefinitionTag(secondListId, level, pStyleId, docx);
29122
- const sameNumFmt = numFmt === numFmt2;
29123
- const sameLvlText = lvlText === lvlText2;
29124
- const sameLvlJc = lvlJc === lvlJc2;
29125
- return sameNumFmt && sameLvlText && sameLvlJc;
29126
- };
29127
28917
  const getListNumIdFromStyleRef = (styleId, docx) => {
29128
28918
  const styles = docx["word/styles.xml"];
29129
28919
  if (!styles) return null;
@@ -29155,24 +28945,28 @@
29155
28945
  }
29156
28946
  return { numId, ilvl };
29157
28947
  };
29158
- const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
28948
+ const getAbstractDefinition = (numId, docx) => {
29159
28949
  const def2 = docx["word/numbering.xml"];
29160
28950
  if (!def2) return {};
29161
28951
  const { elements } = def2;
29162
28952
  const listData = elements[0];
29163
- if (pStyleId) {
29164
- const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
29165
- if (!numId && numIdFromStyles) numId = numIdFromStyles;
29166
- if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
29167
- }
29168
28953
  const numberingElements = listData.elements;
29169
28954
  const abstractDefinitions = numberingElements.filter((style2) => style2.name === "w:abstractNum");
29170
28955
  const numDefinitions = numberingElements.filter((style2) => style2.name === "w:num");
29171
- const numDefinition = numDefinitions.find((style2) => style2.attributes["w:numId"] === numId);
28956
+ const numDefinition = numDefinitions.find((style2) => style2.attributes["w:numId"] == numId);
29172
28957
  const abstractNumId = numDefinition?.elements[0].attributes["w:val"];
29173
28958
  const listDefinitionForThisNumId = abstractDefinitions?.find(
29174
28959
  (style2) => style2.attributes["w:abstractNumId"] === abstractNumId
29175
28960
  );
28961
+ return listDefinitionForThisNumId;
28962
+ };
28963
+ const getListLevelDefinitionTag = (numId, level, pStyleId, docx) => {
28964
+ if (pStyleId) {
28965
+ const { numId: numIdFromStyles, ilvl: iLvlFromStyles } = getListNumIdFromStyleRef(pStyleId, docx) || {};
28966
+ if (!numId && numIdFromStyles) numId = numIdFromStyles;
28967
+ if (!level && iLvlFromStyles) level = iLvlFromStyles ? parseInt(iLvlFromStyles) : null;
28968
+ }
28969
+ const listDefinitionForThisNumId = getAbstractDefinition(numId, docx);
29176
28970
  const currentLevel = getDefinitionForLevel(listDefinitionForThisNumId, level);
29177
28971
  const numStyleLink = listDefinitionForThisNumId?.elements?.find((style2) => style2.name === "w:numStyleLink");
29178
28972
  const numStyleLinkId = numStyleLink?.attributes["w:val"];
@@ -29181,7 +28975,15 @@
29181
28975
  return getListLevelDefinitionTag(current.numId, level, null, docx);
29182
28976
  }
29183
28977
  const start2 = currentLevel?.elements?.find((style2) => style2.name === "w:start")?.attributes["w:val"];
29184
- const numFmt = currentLevel?.elements?.find((style2) => style2.name === "w:numFmt")?.attributes["w:val"];
28978
+ let numFmt = currentLevel?.elements?.find((style2) => style2.name === "w:numFmt")?.attributes["w:val"];
28979
+ if (!numFmt) {
28980
+ const altChoice = currentLevel?.elements.find((style2) => style2.name === "mc:AlternateContent");
28981
+ const choice = altChoice?.elements.find((style2) => style2.name === "mc:Choice");
28982
+ const choiceNumFmt = choice?.elements.find((style2) => style2.name === "w:numFmt")?.attributes["w:val"];
28983
+ if (choiceNumFmt) {
28984
+ numFmt = choiceNumFmt;
28985
+ }
28986
+ }
29185
28987
  const lvlText = currentLevel?.elements?.find((style2) => style2.name === "w:lvlText").attributes["w:val"];
29186
28988
  const lvlJc = currentLevel?.elements?.find((style2) => style2.name === "w:lvlJc").attributes["w:val"];
29187
28989
  const pPr = currentLevel?.elements?.find((style2) => style2.name === "w:pPr");
@@ -29196,12 +28998,10 @@
29196
28998
  const initialPpr = item.elements.find((el) => el.name === "w:pPr");
29197
28999
  const styleTag = initialPpr?.elements?.find((el) => el.name === "w:pStyle");
29198
29000
  const styleId = styleTag?.attributes["w:val"];
29199
- const numPrTag = getNumPrRecursive({ node: item, styleId, docx });
29001
+ const { numPr: numPrTag, type: type2 } = getNumPrRecursive({ node: item, styleId, docx });
29200
29002
  if (!numPrTag) return {};
29201
29003
  const numIdTag = numPrTag?.elements.find((style2) => style2.name === "w:numId");
29202
29004
  const numId = numIdTag?.attributes["w:val"];
29203
- const ilvlTag = numPrTag?.elements.find((style2) => style2.name === "w:ilvl");
29204
- const ilvl = ilvlTag?.attributes["w:val"] || getOutlineLevelFromStyleTag(styleId, docx);
29205
29005
  const pStyle = listStyles.find((style2) => style2.name === "w:pStyle");
29206
29006
  const pStyleId = pStyle?.attributes["w:val"];
29207
29007
  const {
@@ -29213,29 +29013,84 @@
29213
29013
  rPr
29214
29014
  } = getListLevelDefinitionTag(numId, level, pStyleId, docx);
29215
29015
  let listpPrs, listrPrs;
29216
- if (pPr) listpPrs = _processListParagraphProperties(pPr);
29016
+ if (pPr) listpPrs = _processListParagraphProperties(pPr, initialPpr);
29217
29017
  if (rPr) listrPrs = _processListRunProperties(rPr);
29218
29018
  let listType;
29219
29019
  if (unorderedListTypes.includes(listTypeDef?.toLowerCase())) listType = "bulletList";
29220
29020
  else if (orderedListTypes.includes(listTypeDef)) listType = "orderedList";
29221
- else return {};
29222
- return { listType, listOrderingType: listTypeDef, ilvl, numId, listrPrs, listpPrs, start: start2, lvlText, lvlJc };
29021
+ else if (listTypeDef === "custom") {
29022
+ listType = "orderedList";
29023
+ } else {
29024
+ return {};
29025
+ }
29026
+ return { listType, listOrderingType: listTypeDef, listrPrs, listpPrs, start: start2, lvlText, lvlJc };
29223
29027
  }
29224
29028
  function getDefinitionForLevel(data, level) {
29225
29029
  return data?.elements?.find((item) => Number(item.attributes["w:ilvl"]) === level);
29226
29030
  }
29227
- function _processListParagraphProperties(data) {
29031
+ function parseIndentElement(indElem) {
29032
+ if (!indElem || !indElem.attributes) return {};
29033
+ const out = {};
29034
+ if (indElem.attributes["w:left"] != null) out.left = twipsToPixels(indElem.attributes["w:left"]);
29035
+ if (indElem.attributes["w:right"] != null) out.right = twipsToPixels(indElem.attributes["w:right"]);
29036
+ if (indElem.attributes["w:firstLine"] != null) out.firstLine = twipsToPixels(indElem.attributes["w:firstLine"]);
29037
+ if (indElem.attributes["w:hanging"] != null) out.hanging = twipsToPixels(indElem.attributes["w:hanging"]);
29038
+ if (indElem.attributes["w:leftChars"] != null) out.leftChars = twipsToPixels(indElem.attributes["w:leftChars"]);
29039
+ return out;
29040
+ }
29041
+ function combineIndents(ind1, ind2) {
29042
+ ind1 = ind1 && typeof ind1 === "object" ? ind1 : {};
29043
+ ind2 = ind2 && typeof ind2 === "object" ? ind2 : {};
29044
+ const indent = {};
29045
+ ["left", "right", "firstLine", "hanging"].forEach((prop) => {
29046
+ const v1 = ind1[prop] !== void 0 ? Number(ind1[prop]) : null;
29047
+ const v2 = ind2[prop] !== void 0 ? Number(ind2[prop]) : null;
29048
+ if (v1 != null && v2 != null) {
29049
+ indent[prop] = prop === "left" || prop === "hanging" ? Math.max(v1, v2) : v1;
29050
+ } else if (v1 != null) {
29051
+ indent[prop] = v1;
29052
+ } else if (v2 != null) {
29053
+ indent[prop] = v2;
29054
+ }
29055
+ });
29056
+ return indent;
29057
+ }
29058
+ function _processListParagraphProperties(data, inlinePpr) {
29228
29059
  const { elements } = data;
29229
29060
  const expectedTypes = ["w:ind", "w:jc", "w:tabs"];
29230
29061
  const paragraphProperties = {};
29231
29062
  if (!elements) return paragraphProperties;
29232
29063
  elements.forEach((item) => {
29233
- if (!expectedTypes.includes(item.name)) ;
29234
- const { attributes = {} } = item;
29235
- Object.keys(attributes).forEach((key) => {
29236
- paragraphProperties[key] = attributes[key];
29237
- });
29064
+ if (!expectedTypes.includes(item.name)) {
29065
+ console.warn(`[numbering.xml] Unexpected list paragraph prop found: ${item.name}`);
29066
+ }
29238
29067
  });
29068
+ const inlineIndent = inlinePpr?.elements?.find((item) => item.name === "w:ind");
29069
+ const parsedInlineIndent = parseIndentElement(inlineIndent);
29070
+ const styleIndent = elements.find((item) => item.name === "w:ind");
29071
+ parseIndentElement(styleIndent);
29072
+ paragraphProperties.indent = parsedInlineIndent;
29073
+ const justify = elements.find((item) => item.name === "w:jc");
29074
+ if (justify) {
29075
+ const justifyAttrs = {};
29076
+ if (!justify.attributes) justify.attributes = {};
29077
+ if (justify.attributes["w:val"] !== void 0) justifyAttrs.val = justify.attributes["w:val"];
29078
+ paragraphProperties.justify = justifyAttrs;
29079
+ }
29080
+ const tabs = elements.find((item) => item.name === "w:tabs");
29081
+ if (tabs) {
29082
+ const tabElements = tabs.elements.filter((item) => item.name === "w:tab");
29083
+ const tabStops = [];
29084
+ tabElements.forEach((tab) => {
29085
+ const tabStop = {};
29086
+ if (!tab.attributes) tab.attributes = {};
29087
+ if (tab.attributes["w:val"] !== void 0) tabStop.val = tab.attributes["w:val"];
29088
+ if (tab.attributes["w:leader"] !== void 0) tabStop.leader = tab.attributes["w:leader"];
29089
+ if (tab.attributes["w:pos"] !== void 0) tabStop.pos = twipsToPixels(tab.attributes["w:pos"]);
29090
+ tabStops.push(tabStop);
29091
+ });
29092
+ paragraphProperties.tabStops = tabStops;
29093
+ }
29239
29094
  return paragraphProperties;
29240
29095
  }
29241
29096
  function _processListRunProperties(data) {
@@ -29282,9 +29137,6 @@
29282
29137
  let schemaNode;
29283
29138
  let processedElements = preProcessNodesForFldChar(node2.elements);
29284
29139
  node2.elements = processedElements;
29285
- if (testForList(node2, docx)) {
29286
- return { nodes: [], consumed: 0 };
29287
- }
29288
29140
  const handleStandardNode2 = nodeListHandler2.handlerEntities.find(
29289
29141
  (e) => e.handlerName === "standardNodeHandler"
29290
29142
  )?.handler;
@@ -29354,6 +29206,14 @@
29354
29206
  schemaNode.attrs["spacing"] = getParagraphSpacing(node2, docx, styleId, schemaNode.attrs.marksAttrs);
29355
29207
  schemaNode.attrs["rsidRDefault"] = defaultStyleId;
29356
29208
  }
29209
+ if (docx) {
29210
+ const { justify: justify2 } = getDefaultParagraphStyle(docx, styleId);
29211
+ if (justify2) {
29212
+ schemaNode.attrs.justify = {
29213
+ val: justify2["w:val"]
29214
+ };
29215
+ }
29216
+ }
29357
29217
  if (framePr && framePr.attributes["w:dropCap"]) {
29358
29218
  schemaNode.attrs.dropcap = {
29359
29219
  type: framePr.attributes["w:dropCap"],
@@ -29376,6 +29236,7 @@
29376
29236
  schemaNode.attrs.paragraphProperties.sectPr = sectPr;
29377
29237
  schemaNode.attrs.pageBreakSource = "sectPr";
29378
29238
  }
29239
+ console.debug("paragraphNodeHandler", schemaNode);
29379
29240
  return { nodes: schemaNode ? [schemaNode] : [], consumed: 1 };
29380
29241
  };
29381
29242
  const getParagraphIndent = (node2, docx, styleId = "") => {
@@ -30280,8 +30141,8 @@
30280
30141
  alternateChoiceHandler,
30281
30142
  runNodeHandlerEntity,
30282
30143
  pictNodeHandlerEntity,
30283
- paragraphNodeHandlerEntity,
30284
30144
  listHandlerEntity,
30145
+ paragraphNodeHandlerEntity,
30285
30146
  textNodeHandlerEntity,
30286
30147
  lineBreakNodeHandlerEntity,
30287
30148
  annotationNodeHandlerEntity,
@@ -30295,7 +30156,7 @@
30295
30156
  autoPageHandlerEntity,
30296
30157
  autoTotalPageCountEntity,
30297
30158
  standardNodeHandlerEntity
30298
- //this should be the last one, bcs this parses everything!!!
30159
+ // This is the last one as it can handle everything
30299
30160
  ];
30300
30161
  const handler = createNodeListHandler(entities);
30301
30162
  return {
@@ -30527,6 +30388,8 @@
30527
30388
  converter.headers[rId] = { type: "doc", content: [...schema] };
30528
30389
  sectionType && (converter.headerIds[sectionType] = rId);
30529
30390
  });
30391
+ const titlePg = allSectPrElements?.find((el) => el.name === "w:titlePg");
30392
+ if (titlePg) converter.headerIds.titlePg = true;
30530
30393
  footers.forEach((footer) => {
30531
30394
  const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(footer, docx);
30532
30395
  const sectPrFooter = allSectPrElements.find((el) => el.name === "w:footerReference" && el.attributes["r:id"] === rId);
@@ -30667,7 +30530,7 @@
30667
30530
  return;
30668
30531
  }
30669
30532
  }
30670
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.12.34-next.3") {
30533
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.0-RC2") {
30671
30534
  const customLocation = "docProps/custom.xml";
30672
30535
  if (!docx[customLocation]) {
30673
30536
  docx[customLocation] = generateCustomXml();
@@ -30824,7 +30687,7 @@
30824
30687
  const exporter = new DocxExporter(this);
30825
30688
  return exporter.schemaToXml(data, debug);
30826
30689
  }
30827
- async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor) {
30690
+ async exportToDocx(jsonData, editorSchema, documentMedia, isFinalDoc = false, commentsExportType, comments = [], editor, exportJsonOnly = false) {
30828
30691
  const commentsWithParaIds = comments.map((c2) => prepareCommentParaIds(c2));
30829
30692
  const commentDefinitions = commentsWithParaIds.map((c2, index2) => getCommentDefinition(c2, index2, commentsWithParaIds, editor));
30830
30693
  const { result, params: params2 } = this.exportToXmlJson({
@@ -30836,6 +30699,7 @@
30836
30699
  isFinalDoc,
30837
30700
  editor
30838
30701
  });
30702
+ if (exportJsonOnly) return result;
30839
30703
  const exporter = new DocxExporter(this);
30840
30704
  const xml = exporter.schemaToXml(result);
30841
30705
  await __privateMethod$2(this, _SuperConverter_instances, exportProcessMediaFiles_fn).call(this, {
@@ -31133,7 +30997,7 @@
31133
30997
  function generateCustomXml() {
31134
30998
  return DEFAULT_CUSTOM_XML;
31135
30999
  }
31136
- function generateSuperdocVersion(pid = 2, version2 = "0.12.34-next.3") {
31000
+ function generateSuperdocVersion(pid = 2, version2 = "0.13.0-RC2") {
31137
31001
  return {
31138
31002
  type: "element",
31139
31003
  name: "property",
@@ -33666,7 +33530,7 @@
33666
33530
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
33667
33531
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
33668
33532
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
33669
- var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn;
33533
+ var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _ListItemNodeView_instances, init_fn2, _FieldAnnotationView_instances, createAnnotation_fn;
33670
33534
  function getMarksFromSelection(state2) {
33671
33535
  const { from: from2, to, empty: empty2 } = state2.selection;
33672
33536
  const marks = [];
@@ -34638,8 +34502,8 @@
34638
34502
  const type2 = getNodeType(typeOrName, state2.schema);
34639
34503
  const { from: from2, to } = state2.selection;
34640
34504
  const nodes = [];
34641
- state2.doc.nodesBetween(from2, to, (node22) => {
34642
- nodes.push(node22);
34505
+ state2.doc.nodesBetween(from2, to, (node3) => {
34506
+ nodes.push(node3);
34643
34507
  });
34644
34508
  const node2 = nodes.reverse().find((nodeItem) => nodeItem.type.name === type2.name);
34645
34509
  if (!node2) return {};
@@ -37388,6 +37252,377 @@
37388
37252
  }
37389
37253
  ]
37390
37254
  };
37255
+ function createDocument(converter, schema, editor, { check = false } = {}) {
37256
+ const documentData = converter.getSchema(editor);
37257
+ if (documentData) {
37258
+ const documentNode = schema.nodeFromJSON(documentData);
37259
+ if (check) {
37260
+ documentNode.check();
37261
+ }
37262
+ return documentNode;
37263
+ }
37264
+ return schema.topNodeType.createAndFill();
37265
+ }
37266
+ function getSchemaTypeByName(name, schema) {
37267
+ return schema.nodes[name] || schema.marks[name] || null;
37268
+ }
37269
+ function generateDocxListAttributes(listType) {
37270
+ const listTypesMap = {
37271
+ bulletList: 1,
37272
+ orderedList: 2
37273
+ };
37274
+ return {
37275
+ attributes: {
37276
+ parentAttributes: {
37277
+ "w14:paraId": generateDocxRandomId(),
37278
+ "w14:textId": generateDocxRandomId(),
37279
+ "w:rsidR": generateDocxRandomId(),
37280
+ "w:rsidRDefault": generateDocxRandomId(),
37281
+ "w:rsidP": generateDocxRandomId(),
37282
+ paragraphProperties: {
37283
+ type: "element",
37284
+ name: "w:pPr",
37285
+ elements: [
37286
+ {
37287
+ type: "element",
37288
+ name: "w:pStyle",
37289
+ attributes: {
37290
+ "w:val": "ListParagraph"
37291
+ }
37292
+ },
37293
+ {
37294
+ type: "element",
37295
+ name: "w:numPr",
37296
+ elements: [
37297
+ {
37298
+ type: "element",
37299
+ name: "w:ilvl",
37300
+ attributes: {
37301
+ "w:val": "0"
37302
+ }
37303
+ },
37304
+ {
37305
+ type: "element",
37306
+ name: "w:numId",
37307
+ attributes: {
37308
+ "w:val": listTypesMap[listType] || 0
37309
+ }
37310
+ }
37311
+ ]
37312
+ }
37313
+ ]
37314
+ }
37315
+ }
37316
+ }
37317
+ };
37318
+ }
37319
+ function getMarksBetween(from2, to, doc2) {
37320
+ const marks = [];
37321
+ if (from2 === to) {
37322
+ doc2.resolve(from2).marks().forEach((mark) => {
37323
+ const $pos = doc2.resolve(from2 - 1);
37324
+ const range2 = getMarkRange($pos, mark.type);
37325
+ if (!range2) {
37326
+ return;
37327
+ }
37328
+ marks.push({
37329
+ mark,
37330
+ ...range2
37331
+ });
37332
+ });
37333
+ } else {
37334
+ doc2.nodesBetween(from2, to, (node2, pos) => {
37335
+ if (!node2 || node2?.nodeSize === void 0) {
37336
+ return;
37337
+ }
37338
+ marks.push(
37339
+ ...node2.marks.map((mark) => ({
37340
+ from: pos,
37341
+ to: pos + node2.nodeSize,
37342
+ mark
37343
+ }))
37344
+ );
37345
+ });
37346
+ }
37347
+ return marks;
37348
+ }
37349
+ function isActive(state2, name, attrs = {}) {
37350
+ if (!name) {
37351
+ return isNodeActive(state2, null, attrs) || isMarkActive(state2, null, attrs);
37352
+ }
37353
+ const schemaType = getSchemaTypeNameByName(name, state2.schema);
37354
+ if (schemaType === "node") {
37355
+ return isNodeActive(state2, name, attrs);
37356
+ }
37357
+ if (schemaType === "mark") {
37358
+ return isMarkActive(state2, name, attrs);
37359
+ }
37360
+ return false;
37361
+ }
37362
+ function findChildren$3(node2, predicate) {
37363
+ const nodesWithPos = [];
37364
+ node2.descendants((child, pos) => {
37365
+ if (predicate(child)) {
37366
+ nodesWithPos.push({
37367
+ node: child,
37368
+ pos
37369
+ });
37370
+ }
37371
+ });
37372
+ return nodesWithPos;
37373
+ }
37374
+ function posToDOMRect(view, from2, to) {
37375
+ const minPos = 0;
37376
+ const maxPos = view.state.doc.content.size;
37377
+ const resolvedFrom = minMax(from2, minPos, maxPos);
37378
+ const resolvedEnd = minMax(to, minPos, maxPos);
37379
+ const start2 = view.coordsAtPos(resolvedFrom);
37380
+ const end2 = view.coordsAtPos(resolvedEnd, -1);
37381
+ const top2 = Math.min(start2.top, end2.top);
37382
+ const bottom2 = Math.max(start2.bottom, end2.bottom);
37383
+ const left2 = Math.min(start2.left, end2.left);
37384
+ const right2 = Math.max(start2.right, end2.right);
37385
+ const width = right2 - left2;
37386
+ const height = bottom2 - top2;
37387
+ const x = left2;
37388
+ const y = top2;
37389
+ const data = {
37390
+ top: top2,
37391
+ bottom: bottom2,
37392
+ left: left2,
37393
+ right: right2,
37394
+ width,
37395
+ height,
37396
+ x,
37397
+ y
37398
+ };
37399
+ return {
37400
+ ...data,
37401
+ toJSON: () => data
37402
+ };
37403
+ }
37404
+ const isInTable$1 = (state2) => {
37405
+ const { $head } = state2.selection;
37406
+ for (let d = $head.depth; d > 0; d -= 1) {
37407
+ if ($head.node(d).type?.spec?.tableRole === "row") {
37408
+ return true;
37409
+ }
37410
+ }
37411
+ return false;
37412
+ };
37413
+ const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
37414
+ __proto__: null,
37415
+ chainableEditorState,
37416
+ cleanSchemaItem,
37417
+ createDocument,
37418
+ defaultBlockAt,
37419
+ findChildren: findChildren$3,
37420
+ findMark,
37421
+ findParentNode,
37422
+ findParentNodeClosestToPos,
37423
+ generateDocxListAttributes,
37424
+ generateDocxRandomId,
37425
+ generateRandom32BitHex,
37426
+ getActiveFormatting,
37427
+ getExtensionConfigField,
37428
+ getMarkRange,
37429
+ getMarkType,
37430
+ getMarksBetween,
37431
+ getMarksFromSelection,
37432
+ getNodeType,
37433
+ getSchemaTypeByName,
37434
+ getSchemaTypeNameByName,
37435
+ isActive,
37436
+ isInTable: isInTable$1,
37437
+ isList,
37438
+ isMarkActive,
37439
+ isNodeActive,
37440
+ isTextSelection,
37441
+ posToDOMRect
37442
+ }, Symbol.toStringTag, { value: "Module" }));
37443
+ const generateNewListDefinition = ({ numId, listType, editor }) => {
37444
+ const definition = listType.name === "orderedList" ? baseOrderedListDef : baseBulletList;
37445
+ const numbering = editor.converter.numbering;
37446
+ const newNumbering = { ...numbering };
37447
+ const newAbstractId = getNewListId(editor);
37448
+ const newAbstractDef = {
37449
+ ...definition,
37450
+ attributes: {
37451
+ ...definition.attributes,
37452
+ "w:abstractNumId": String(newAbstractId)
37453
+ }
37454
+ };
37455
+ newNumbering.abstracts[newAbstractId] = newAbstractDef;
37456
+ const newNumDef = {
37457
+ type: "element",
37458
+ name: "w:num",
37459
+ attributes: {
37460
+ "w:numId": String(numId),
37461
+ "w16cid:durableId": "485517411"
37462
+ },
37463
+ elements: [
37464
+ { name: "w:abstractNumId", attributes: { "w:val": String(newAbstractId) } }
37465
+ ]
37466
+ };
37467
+ newNumbering.definitions[numId] = newNumDef;
37468
+ editor.converter.numbering = newNumbering;
37469
+ return { abstract: newAbstractDef, definition: newNumDef };
37470
+ };
37471
+ const getNewListId = (editor) => Math.max(...Object.keys(editor.converter.numbering.definitions).map(Number)) + 1;
37472
+ const getListDefinitionDetails = ({ numId, level, editor }) => {
37473
+ const { definitions, abstracts } = editor.converter.numbering;
37474
+ const abstractId = definitions[numId]?.elements?.find((item) => item.name === "w:abstractNumId")?.attributes?.["w:val"];
37475
+ const abstract = abstracts[abstractId];
37476
+ const listDefinition = abstract?.elements?.find((item) => item.name === "w:lvl" && item.attributes["w:ilvl"] == level);
37477
+ const start2 = listDefinition?.elements?.find((item) => item.name === "w:start")?.attributes["w:val"];
37478
+ const numFmt = listDefinition?.elements?.find((item) => item.name === "w:numFmt")?.attributes["w:val"];
37479
+ const lvlText = listDefinition?.elements?.find((item) => item.name === "w:lvlText")?.attributes["w:val"];
37480
+ return { start: start2, numFmt, lvlText };
37481
+ };
37482
+ const removeListDefinitions = (listId, editor) => {
37483
+ const { numbering } = editor.converter;
37484
+ if (!numbering) return;
37485
+ const { definitions, abstracts } = numbering;
37486
+ const abstractId = definitions[listId].elements[0].attributes["w:val"];
37487
+ delete definitions[listId];
37488
+ delete abstracts[abstractId];
37489
+ editor.converter.numbering = {
37490
+ definitions,
37491
+ abstracts
37492
+ };
37493
+ };
37494
+ const createListItemNodeJSON = ({ level, lvlText, numId, numFmt, start: start2, contentNode }) => {
37495
+ start2 = Number(start2);
37496
+ if (!contentNode) {
37497
+ contentNode = {
37498
+ type: "paragraph",
37499
+ content: []
37500
+ };
37501
+ }
37502
+ const listLevel = new Array(level).fill(start2).map((_, i2) => i2);
37503
+ listLevel.push(start2);
37504
+ return {
37505
+ type: "listItem",
37506
+ attrs: {
37507
+ lvlText,
37508
+ listLevel,
37509
+ level,
37510
+ numId,
37511
+ numPrType: "inline",
37512
+ listNumberingType: numFmt
37513
+ },
37514
+ content: [contentNode]
37515
+ };
37516
+ };
37517
+ const createSchemaOrderedListNode = ({ level, numId, editor, contentNode }) => {
37518
+ level = Number(level);
37519
+ numId = Number(numId);
37520
+ const { start: start2, lvlText, numFmt } = ListHelpers.getListDefinitionDetails({ numId, level, editor });
37521
+ const listNodeJSON = createListItemNodeJSON({ level, lvlText, numFmt, numId, start: start2, contentNode });
37522
+ const node2 = {
37523
+ type: "orderedList",
37524
+ attrs: {
37525
+ "list-style-type": numFmt,
37526
+ listId: numId,
37527
+ order: level
37528
+ },
37529
+ content: [listNodeJSON]
37530
+ };
37531
+ return editor.schema.nodeFromJSON(node2);
37532
+ };
37533
+ const createNewList = ({ listType, editor, chain }) => {
37534
+ const numId = ListHelpers.getNewListId(editor);
37535
+ if (typeof node === "string") listType = editor.schema.nodes[listType];
37536
+ ListHelpers.generateNewListDefinition({ numId, listType, editor });
37537
+ const { state: state2 } = editor;
37538
+ const { $from } = state2.selection;
37539
+ const content = $from.parent;
37540
+ const level = 0;
37541
+ const listNode = ListHelpers.createSchemaOrderedListNode({
37542
+ level,
37543
+ numId,
37544
+ editor,
37545
+ contentNode: content?.toJSON()
37546
+ });
37547
+ const parentDepth = $from.depth;
37548
+ const replaceFrom = $from.before(parentDepth);
37549
+ const replaceTo = $from.after(parentDepth);
37550
+ return insertNewList(chain, replaceFrom, replaceTo, listNode);
37551
+ };
37552
+ const indentListItem = ({ chain, editor, node: currentNode }) => {
37553
+ const { state: state2 } = editor;
37554
+ const { $from } = state2.selection;
37555
+ const content = $from.parent;
37556
+ const numId = currentNode.node.attrs.numId;
37557
+ const level = currentNode.node.attrs.level + 1;
37558
+ const listNode = ListHelpers.createSchemaOrderedListNode({
37559
+ level,
37560
+ numId,
37561
+ editor,
37562
+ contentNode: content?.toJSON()
37563
+ });
37564
+ const parentList = findParentNode((node2) => node2.type.name === "orderedList")(state2.selection);
37565
+ const replaceFrom = parentList.pos;
37566
+ const replaceTo = parentList.node.nodeSize + parentList.pos;
37567
+ const newMarks = addInlineTextMarks(currentNode.node, []);
37568
+ return insertNewList(chain, replaceFrom, replaceTo, listNode, newMarks);
37569
+ };
37570
+ const outdentListItem = ({ chain, editor, node: currentNode }) => {
37571
+ const { state: state2 } = editor;
37572
+ const { $from } = state2.selection;
37573
+ const content = $from.parent;
37574
+ const numId = currentNode.node.attrs.numId;
37575
+ const level = currentNode.node.attrs.level - 1;
37576
+ const parentList = findParentNode((node2) => node2.type.name === "orderedList")(state2.selection);
37577
+ const replaceFrom = parentList.pos;
37578
+ const replaceTo = parentList.node.nodeSize + parentList.pos;
37579
+ if (level < 0) {
37580
+ return insertNewList(chain, replaceFrom, replaceTo, content);
37581
+ }
37582
+ const listNode = ListHelpers.createSchemaOrderedListNode({
37583
+ level,
37584
+ numId,
37585
+ editor,
37586
+ contentNode: content?.toJSON()
37587
+ });
37588
+ const newMarks = addInlineTextMarks(currentNode.node, []);
37589
+ return insertNewList(chain, replaceFrom, replaceTo, listNode, newMarks);
37590
+ };
37591
+ const insertNewList = (chain, replaceFrom, replaceTo, listNode, marks = []) => {
37592
+ return chain().command(({ tr, dispatch }) => {
37593
+ tr.replaceWith(replaceFrom, replaceTo, listNode);
37594
+ tr.ensureMarks(marks);
37595
+ dispatch(tr);
37596
+ return true;
37597
+ }).run();
37598
+ };
37599
+ const addInlineTextMarks = (currentNode, filteredMarks) => {
37600
+ const newMarks = [...filteredMarks];
37601
+ try {
37602
+ const textMarks = currentNode.children[0].children[0].marks;
37603
+ const inlineTextStyleFromSplitBlock = textMarks.find((m) => m.type.name === "textStyle");
37604
+ inlineTextStyleFromSplitBlock && newMarks.push(inlineTextStyleFromSplitBlock);
37605
+ } catch (e) {
37606
+ }
37607
+ return newMarks;
37608
+ };
37609
+ const ListHelpers = {
37610
+ // DOCX helpers
37611
+ getListDefinitionDetails,
37612
+ generateNewListDefinition,
37613
+ getNewListId,
37614
+ removeListDefinitions,
37615
+ // Schema helpers
37616
+ createNewList,
37617
+ createSchemaOrderedListNode,
37618
+ createListItemNodeJSON,
37619
+ indentListItem,
37620
+ outdentListItem,
37621
+ addInlineTextMarks,
37622
+ // Base list definitions
37623
+ baseOrderedListDef,
37624
+ baseBulletList
37625
+ };
37391
37626
  const joinListBackwards = (tr, listType) => {
37392
37627
  const list = findParentNode((node2) => node2.type === listType)(tr.selection);
37393
37628
  if (!list) return true;
@@ -37425,7 +37660,7 @@
37425
37660
  if (range2.depth >= 1 && parentList && range2.depth - parentList.depth <= 1) {
37426
37661
  if (parentList.node.type === listType) {
37427
37662
  const { listId } = parentList.node.attrs;
37428
- if (editor.converter) editor.converter.numbering = removeListDefinitions(listId, numbering);
37663
+ if (editor.converter) ListHelpers.removeListDefinitions(listId, editor);
37429
37664
  return commands2.liftListItem(itemType);
37430
37665
  }
37431
37666
  if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {
@@ -37447,8 +37682,8 @@
37447
37682
  return commands2.clearNodes();
37448
37683
  };
37449
37684
  };
37450
- const newListId = numbering?.definitions ? getNewListId(numbering.definitions) : null;
37451
- if (editor.converter) editor.converter.numbering = generateNewListDefinition(newListId, numbering, listType);
37685
+ const newListId = numbering?.definitions ? ListHelpers.getNewListId(editor) : null;
37686
+ if (editor.converter) ListHelpers.generateNewListDefinition(newListId, numbering, listType);
37452
37687
  attributes.listId = newListId;
37453
37688
  if (!keepMarks || !marks || !dispatch) {
37454
37689
  const result2 = chain().command(createTryConvertNodeToDefault({ ensureMarks: false })).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
@@ -37457,41 +37692,7 @@
37457
37692
  const result = chain().command(createTryConvertNodeToDefault({ ensureMarks: true })).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
37458
37693
  return result;
37459
37694
  };
37460
- const getNewListId = (definitions) => Math.max(...Object.keys(definitions).map(Number)) + 1;
37461
- const generateNewListDefinition = (newListId, numbering, listType) => {
37462
- const definition = listType.name === "orderedList" ? baseOrderedListDef : baseBulletList;
37463
- const newNumbering = { ...numbering };
37464
- const newAbstractId = getNewListId(newNumbering.abstracts);
37465
- const newAbstractDef = {
37466
- ...definition,
37467
- attributes: {
37468
- ...definition.attributes,
37469
- "w:abstractNumId": String(newAbstractId)
37470
- }
37471
- };
37472
- newNumbering.abstracts[newAbstractId] = newAbstractDef;
37473
- const newNumDef = {
37474
- type: "element",
37475
- name: "w:num",
37476
- attributes: {
37477
- "w:numId": String(newListId),
37478
- "w16cid:durableId": "485517411"
37479
- },
37480
- elements: [
37481
- { name: "w:abstractNumId", attributes: { "w:val": String(newAbstractId) } }
37482
- ]
37483
- };
37484
- newNumbering.definitions[newListId] = newNumDef;
37485
- return newNumbering;
37486
- };
37487
- const removeListDefinitions = (listId, numbering) => {
37488
- const { definitions, abstracts } = numbering;
37489
- const abstractId = definitions[listId].elements[0].attributes["w:val"];
37490
- delete definitions[listId];
37491
- delete abstracts[abstractId];
37492
- return numbering;
37493
- };
37494
- const splitListItem = (typeOrName) => (props) => {
37695
+ const splitListItem = (typeOrName, currentNode) => (props) => {
37495
37696
  const { tr, state: state2, dispatch, editor } = props;
37496
37697
  const type2 = getNodeType(typeOrName, state2.schema);
37497
37698
  const { $from, $to, node: node2 } = state2.selection;
@@ -37520,8 +37721,8 @@
37520
37721
  $from.node().type.name,
37521
37722
  $from.node().attrs
37522
37723
  );
37523
- const nextType2 = type2.contentMatch.defaultType?.createAndFill(newNextTypeAttrs) || void 0;
37524
- wrap2 = wrap2.append(Fragment.from(type2.createAndFill(null, nextType2) || void 0));
37724
+ const nextType = type2.contentMatch.defaultType?.createAndFill(newNextTypeAttrs) || void 0;
37725
+ wrap2 = wrap2.append(Fragment.from(type2.createAndFill(null, nextType) || void 0));
37525
37726
  const start2 = $from.before($from.depth - (depthBefore - 1));
37526
37727
  tr.replace(start2, $from.after(-depthAfter), new Slice(wrap2, 4 - depthBefore, 0));
37527
37728
  let sel = -1;
@@ -37534,30 +37735,18 @@
37534
37735
  }
37535
37736
  return true;
37536
37737
  }
37537
- const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
37538
- const newTypeAttributes = Attribute.getSplittedAttributes(extensionAttrs, grandParent.type.name, grandParent.attrs);
37539
- const newNextTypeAttributes = Attribute.getSplittedAttributes(
37540
- extensionAttrs,
37541
- $from.node().type.name,
37542
- $from.node().attrs
37543
- );
37544
37738
  tr.delete($from.pos, $to.pos);
37545
- const types2 = nextType ? [
37546
- { type: type2, attrs: newTypeAttributes },
37547
- { type: nextType, attrs: newNextTypeAttributes }
37548
- ] : [{ type: type2, attrs: newTypeAttributes }];
37549
- if (!canSplit(tr.doc, $from.pos, 2)) {
37550
- return false;
37551
- }
37739
+ if (!canSplit(tr.doc, $from.pos, 3)) return false;
37552
37740
  if (dispatch) {
37553
37741
  const { selection, storedMarks } = state2;
37554
37742
  const { splittableMarks } = editor.extensionService;
37555
37743
  const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
37556
- tr.split($from.pos, 2, types2).scrollIntoView();
37744
+ tr.split($from.pos, 3).scrollIntoView();
37557
37745
  if (!marks || !dispatch) return true;
37558
37746
  const filteredMarks = marks.filter((m) => splittableMarks.includes(m.type.name));
37559
- tr.ensureMarks(filteredMarks);
37560
- tr.setMeta("splitListItem", filteredMarks);
37747
+ const updatedMarks = ListHelpers.addInlineTextMarks(currentNode.node, filteredMarks);
37748
+ tr.ensureMarks(updatedMarks);
37749
+ tr.setMeta("splitListItem", updatedMarks);
37561
37750
  }
37562
37751
  return true;
37563
37752
  };
@@ -37718,194 +37907,6 @@
37718
37907
  return [editorFocusPlugin];
37719
37908
  }
37720
37909
  });
37721
- function createDocument(converter, schema, editor, { check = false } = {}) {
37722
- const documentData = converter.getSchema(editor);
37723
- if (documentData) {
37724
- const documentNode = schema.nodeFromJSON(documentData);
37725
- if (check) {
37726
- documentNode.check();
37727
- }
37728
- return documentNode;
37729
- }
37730
- return schema.topNodeType.createAndFill();
37731
- }
37732
- function getSchemaTypeByName(name, schema) {
37733
- return schema.nodes[name] || schema.marks[name] || null;
37734
- }
37735
- function generateDocxListAttributes(listType) {
37736
- const listTypesMap = {
37737
- bulletList: 1,
37738
- orderedList: 2
37739
- };
37740
- return {
37741
- attributes: {
37742
- parentAttributes: {
37743
- "w14:paraId": generateDocxRandomId(),
37744
- "w14:textId": generateDocxRandomId(),
37745
- "w:rsidR": generateDocxRandomId(),
37746
- "w:rsidRDefault": generateDocxRandomId(),
37747
- "w:rsidP": generateDocxRandomId(),
37748
- paragraphProperties: {
37749
- type: "element",
37750
- name: "w:pPr",
37751
- elements: [
37752
- {
37753
- type: "element",
37754
- name: "w:pStyle",
37755
- attributes: {
37756
- "w:val": "ListParagraph"
37757
- }
37758
- },
37759
- {
37760
- type: "element",
37761
- name: "w:numPr",
37762
- elements: [
37763
- {
37764
- type: "element",
37765
- name: "w:ilvl",
37766
- attributes: {
37767
- "w:val": "0"
37768
- }
37769
- },
37770
- {
37771
- type: "element",
37772
- name: "w:numId",
37773
- attributes: {
37774
- "w:val": listTypesMap[listType] || 0
37775
- }
37776
- }
37777
- ]
37778
- }
37779
- ]
37780
- }
37781
- }
37782
- }
37783
- };
37784
- }
37785
- function getMarksBetween(from2, to, doc2) {
37786
- const marks = [];
37787
- if (from2 === to) {
37788
- doc2.resolve(from2).marks().forEach((mark) => {
37789
- const $pos = doc2.resolve(from2 - 1);
37790
- const range2 = getMarkRange($pos, mark.type);
37791
- if (!range2) {
37792
- return;
37793
- }
37794
- marks.push({
37795
- mark,
37796
- ...range2
37797
- });
37798
- });
37799
- } else {
37800
- doc2.nodesBetween(from2, to, (node2, pos) => {
37801
- if (!node2 || node2?.nodeSize === void 0) {
37802
- return;
37803
- }
37804
- marks.push(
37805
- ...node2.marks.map((mark) => ({
37806
- from: pos,
37807
- to: pos + node2.nodeSize,
37808
- mark
37809
- }))
37810
- );
37811
- });
37812
- }
37813
- return marks;
37814
- }
37815
- function isActive(state2, name, attrs = {}) {
37816
- if (!name) {
37817
- return isNodeActive(state2, null, attrs) || isMarkActive(state2, null, attrs);
37818
- }
37819
- const schemaType = getSchemaTypeNameByName(name, state2.schema);
37820
- if (schemaType === "node") {
37821
- return isNodeActive(state2, name, attrs);
37822
- }
37823
- if (schemaType === "mark") {
37824
- return isMarkActive(state2, name, attrs);
37825
- }
37826
- return false;
37827
- }
37828
- function findChildren$3(node2, predicate) {
37829
- const nodesWithPos = [];
37830
- node2.descendants((child, pos) => {
37831
- if (predicate(child)) {
37832
- nodesWithPos.push({
37833
- node: child,
37834
- pos
37835
- });
37836
- }
37837
- });
37838
- return nodesWithPos;
37839
- }
37840
- function posToDOMRect(view, from2, to) {
37841
- const minPos = 0;
37842
- const maxPos = view.state.doc.content.size;
37843
- const resolvedFrom = minMax(from2, minPos, maxPos);
37844
- const resolvedEnd = minMax(to, minPos, maxPos);
37845
- const start2 = view.coordsAtPos(resolvedFrom);
37846
- const end2 = view.coordsAtPos(resolvedEnd, -1);
37847
- const top2 = Math.min(start2.top, end2.top);
37848
- const bottom2 = Math.max(start2.bottom, end2.bottom);
37849
- const left2 = Math.min(start2.left, end2.left);
37850
- const right2 = Math.max(start2.right, end2.right);
37851
- const width = right2 - left2;
37852
- const height = bottom2 - top2;
37853
- const x = left2;
37854
- const y = top2;
37855
- const data = {
37856
- top: top2,
37857
- bottom: bottom2,
37858
- left: left2,
37859
- right: right2,
37860
- width,
37861
- height,
37862
- x,
37863
- y
37864
- };
37865
- return {
37866
- ...data,
37867
- toJSON: () => data
37868
- };
37869
- }
37870
- const isInTable$1 = (state2) => {
37871
- const { $head } = state2.selection;
37872
- for (let d = $head.depth; d > 0; d -= 1) {
37873
- if ($head.node(d).type?.spec?.tableRole === "row") {
37874
- return true;
37875
- }
37876
- }
37877
- return false;
37878
- };
37879
- const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
37880
- __proto__: null,
37881
- chainableEditorState,
37882
- cleanSchemaItem,
37883
- createDocument,
37884
- defaultBlockAt,
37885
- findChildren: findChildren$3,
37886
- findMark,
37887
- findParentNode,
37888
- findParentNodeClosestToPos,
37889
- generateDocxListAttributes,
37890
- generateDocxRandomId,
37891
- generateRandom32BitHex,
37892
- getActiveFormatting,
37893
- getExtensionConfigField,
37894
- getMarkRange,
37895
- getMarkType,
37896
- getMarksBetween,
37897
- getMarksFromSelection,
37898
- getNodeType,
37899
- getSchemaTypeByName,
37900
- getSchemaTypeNameByName,
37901
- isActive,
37902
- isInTable: isInTable$1,
37903
- isList,
37904
- isMarkActive,
37905
- isNodeActive,
37906
- isTextSelection,
37907
- posToDOMRect
37908
- }, Symbol.toStringTag, { value: "Module" }));
37909
37910
  const global$3 = globalThis || void 0 || self;
37910
37911
  const domIndex = function(node2) {
37911
37912
  for (var index2 = 0; ; index2++) {
@@ -46937,8 +46938,8 @@
46937
46938
  deletionText = node2?.text ?? "";
46938
46939
  if (isDeletionInsertion) {
46939
46940
  let { id } = marks.deletionMark.attrs;
46940
- let deletionNode = findNode$1(state2.doc, (node22) => {
46941
- const { marks: marks2 = [] } = node22;
46941
+ let deletionNode = findNode$1(state2.doc, (node3) => {
46942
+ const { marks: marks2 = [] } = node3;
46942
46943
  const changeMarks = marks2.filter((mark2) => TRACK_CHANGE_MARKS.includes(mark2.type.name));
46943
46944
  if (!changeMarks.length) return false;
46944
46945
  const hasMatchingId = changeMarks.find((mark2) => mark2.attrs.id === id);
@@ -46961,12 +46962,12 @@
46961
46962
  const node2 = nodes[0];
46962
46963
  const isDeletionInsertion = !!(marks.insertedMark && marks.deletionMark);
46963
46964
  let existingNode;
46964
- newEditorState.doc.descendants((node22, pos) => {
46965
- const { marks: marks2 = [] } = node22;
46965
+ newEditorState.doc.descendants((node3, pos) => {
46966
+ const { marks: marks2 = [] } = node3;
46966
46967
  const changeMarks = marks2.filter((mark) => TRACK_CHANGE_MARKS.includes(mark.type.name));
46967
46968
  if (!changeMarks.length) return;
46968
46969
  const hasMatchingId = changeMarks.find((mark) => mark.attrs.id === id);
46969
- if (hasMatchingId) existingNode = node22;
46970
+ if (hasMatchingId) existingNode = node3;
46970
46971
  if (existingNode) return false;
46971
46972
  });
46972
46973
  const { deletionText, trackedChangeText } = getTrackedChangeText({
@@ -46999,8 +47000,8 @@
46999
47000
  };
47000
47001
  function findNode$1(node2, predicate) {
47001
47002
  let found2 = null;
47002
- node2.descendants((node22, pos) => {
47003
- if (predicate(node22)) found2 = { node: node22, pos };
47003
+ node2.descendants((node3, pos) => {
47004
+ if (predicate(node3)) found2 = { node: node3, pos };
47004
47005
  if (found2) return false;
47005
47006
  });
47006
47007
  return found2;
@@ -48317,7 +48318,14 @@
48317
48318
  * @param {boolean} [options.getUpdatedDocs=false] - When set to true return only updated docx files
48318
48319
  * @returns {Promise<Blob|ArrayBuffer|Object>} The exported DOCX file or updated docx files
48319
48320
  */
48320
- async exportDocx({ isFinalDoc = false, commentsType = "external", comments = [], getUpdatedDocs = false } = {}) {
48321
+ async exportDocx({
48322
+ isFinalDoc = false,
48323
+ commentsType = "external",
48324
+ exportJsonOnly = false,
48325
+ exportXmlOnly = false,
48326
+ comments = [],
48327
+ getUpdatedDocs = false
48328
+ } = {}) {
48321
48329
  const json = __privateMethod$1(this, _Editor_instances, prepareDocumentForExport_fn).call(this, comments);
48322
48330
  const documentXml = await this.converter.exportToDocx(
48323
48331
  json,
@@ -48326,8 +48334,10 @@
48326
48334
  isFinalDoc,
48327
48335
  commentsType,
48328
48336
  comments,
48329
- this
48337
+ this,
48338
+ exportJsonOnly
48330
48339
  );
48340
+ if (exportXmlOnly || exportJsonOnly) return documentXml;
48331
48341
  const customXml = this.converter.schemaToXml(this.converter.convertedXml["docProps/custom.xml"].elements[0]);
48332
48342
  const styles = this.converter.schemaToXml(this.converter.convertedXml["word/styles.xml"].elements[0]);
48333
48343
  const customSettings = this.converter.schemaToXml(this.converter.convertedXml["word/settings.xml"].elements[0]);
@@ -48410,7 +48420,7 @@
48410
48420
  * @returns {Object | void} Migration results
48411
48421
  */
48412
48422
  processCollaborationMigrations() {
48413
- console.debug("[checkVersionMigrations] Current editor version", "0.12.34-next.3");
48423
+ console.debug("[checkVersionMigrations] Current editor version", "0.13.0-RC2");
48414
48424
  if (!this.options.ydoc) return;
48415
48425
  const metaMap = this.options.ydoc.getMap("meta");
48416
48426
  let docVersion = metaMap.get("version");
@@ -48813,7 +48823,6 @@
48813
48823
  if (this.options.isHeadless || !this.extensionService) return;
48814
48824
  const pagination = this.options.extensions.find((e) => e.name === "pagination");
48815
48825
  if (pagination && this.options.pagination) {
48816
- console.debug("🔗 [super-editor] Initializing pagination");
48817
48826
  const sectionData = await initPaginationData(this);
48818
48827
  this.storage.pagination.sectionData = sectionData;
48819
48828
  const { state: state2, dispatch } = this.view;
@@ -50348,7 +50357,7 @@
50348
50357
  // rendered: false,
50349
50358
  },
50350
50359
  listId: {
50351
- default: null,
50360
+ keepOnSplit: true,
50352
50361
  parseDOM: (elem) => elem.getAttribute("data-list-id"),
50353
50362
  renderDOM: (attrs) => {
50354
50363
  if (!attrs.listId) return {};
@@ -50385,8 +50394,8 @@
50385
50394
  },
50386
50395
  addCommands() {
50387
50396
  return {
50388
- toggleOrderedList: () => ({ commands: commands2 }) => {
50389
- return commands2.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
50397
+ toggleOrderedList: () => ({ tr, editor, chain }) => {
50398
+ return ListHelpers.createNewList({ listType: this, editor, chain });
50390
50399
  },
50391
50400
  getCurrentList: () => ({ state: state2 }) => {
50392
50401
  return findParentNode((node2) => node2.type.name === this.name)(state2.selection);
@@ -50530,6 +50539,164 @@
50530
50539
  ];
50531
50540
  }
50532
50541
  });
50542
+ const LinkedStylesPluginKey = new PluginKey("linkedStyles");
50543
+ const LinkedStyles = Extension.create({
50544
+ name: "linkedStyles",
50545
+ priority: 1,
50546
+ // We need this plugin to run before the list plugins
50547
+ addPmPlugins() {
50548
+ return [createLinkedStylesPlugin(this.editor)];
50549
+ },
50550
+ addCommands() {
50551
+ return {
50552
+ setLinkedStyle: (style2) => (params2) => {
50553
+ if (!style2) return;
50554
+ const { tr } = params2;
50555
+ const selection = tr.selection;
50556
+ const { from: from2, to } = selection;
50557
+ if (from2 === to) return;
50558
+ let pos = from2;
50559
+ let paragraphNode = tr.doc.nodeAt(from2);
50560
+ if (paragraphNode.type.name !== "paragraph") {
50561
+ const parentNode2 = findParentNode((node2) => node2.type.name === "paragraph")(tr.selection) || {};
50562
+ pos = parentNode2.pos;
50563
+ paragraphNode = parentNode2.node;
50564
+ }
50565
+ tr.setNodeMarkup(pos, void 0, {
50566
+ ...paragraphNode.attrs,
50567
+ styleId: style2.id
50568
+ });
50569
+ }
50570
+ };
50571
+ }
50572
+ });
50573
+ const createLinkedStylesPlugin = (editor) => {
50574
+ return new Plugin({
50575
+ key: LinkedStylesPluginKey,
50576
+ state: {
50577
+ init(_, { doc: doc2, selection }) {
50578
+ if (!editor.converter || editor.options.mode !== "docx") return {};
50579
+ const styles = editor.converter?.linkedStyles || [];
50580
+ return {
50581
+ styles,
50582
+ decorations: generateDecorations(editor.state, styles)
50583
+ };
50584
+ },
50585
+ apply(tr, prev, oldEditorState, newEditorState) {
50586
+ if (!editor.converter || editor.options.mode !== "docx") return { ...prev };
50587
+ let decorations = prev.decorations || DecorationSet.empty;
50588
+ if (tr.docChanged) {
50589
+ const styles = LinkedStylesPluginKey.getState(editor.state).styles;
50590
+ decorations = generateDecorations(newEditorState, styles);
50591
+ }
50592
+ return { ...prev, decorations };
50593
+ }
50594
+ },
50595
+ props: {
50596
+ decorations(state2) {
50597
+ return LinkedStylesPluginKey.getState(state2)?.decorations;
50598
+ }
50599
+ }
50600
+ });
50601
+ };
50602
+ const generateDecorations = (state2, styles) => {
50603
+ const decorations = [];
50604
+ let lastStyleId = null;
50605
+ const doc2 = state2?.doc;
50606
+ doc2.descendants((node2, pos) => {
50607
+ const { name } = node2.type;
50608
+ if (node2?.attrs?.styleId) lastStyleId = node2.attrs.styleId;
50609
+ if (name === "paragraph" && !node2.attrs?.styleId) lastStyleId = null;
50610
+ if (name !== "text") return;
50611
+ const linkedStyle = getLinkedStyle(lastStyleId, styles);
50612
+ if (!linkedStyle) return;
50613
+ const $pos = state2.doc.resolve(pos);
50614
+ const parent = $pos.parent;
50615
+ const styleString = generateLinkedStyleString(linkedStyle, node2, parent);
50616
+ if (!styleString) return;
50617
+ const decoration = Decoration.inline(pos, pos + node2.nodeSize, { style: styleString });
50618
+ decorations.push(decoration);
50619
+ });
50620
+ return DecorationSet.create(doc2, decorations);
50621
+ };
50622
+ const generateLinkedStyleString = (linkedStyle, node2, parent, includeSpacing = true) => {
50623
+ if (!linkedStyle?.definition?.styles) return "";
50624
+ const markValue = {};
50625
+ Object.entries(linkedStyle.definition.styles).forEach(([k, value]) => {
50626
+ const key = kebabCase$2(k);
50627
+ const flattenedMarks = [];
50628
+ node2?.marks?.forEach((n) => {
50629
+ if (n.type.name === "textStyle") {
50630
+ Object.entries(n.attrs).forEach(([styleKey, value2]) => {
50631
+ const parsedKey = kebabCase$2(styleKey);
50632
+ if (!value2) return;
50633
+ flattenedMarks.push({ key: parsedKey, value: value2 });
50634
+ });
50635
+ return;
50636
+ }
50637
+ flattenedMarks.push({ key: n.type.name, value: n.attrs[key] });
50638
+ });
50639
+ const mark = flattenedMarks.find((n) => n.key === key);
50640
+ const hasParentIndent = Object.keys(parent?.attrs?.indent || {});
50641
+ const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {});
50642
+ if (!mark) {
50643
+ if (key === "spacing" && includeSpacing && !hasParentSpacing) ;
50644
+ else if (key === "indent" && includeSpacing && !hasParentIndent) {
50645
+ const { leftIndent, rightIndent, firstLine } = value;
50646
+ if (leftIndent) markValue["margin-left"] = leftIndent + "px";
50647
+ if (rightIndent) markValue["margin-right"] = rightIndent + "px";
50648
+ if (firstLine) markValue["text-indent"] = firstLine + "px";
50649
+ } else if (key === "bold") {
50650
+ markValue["font-weight"] = "bold";
50651
+ } else if (typeof value === "string") markValue[key] = value;
50652
+ }
50653
+ });
50654
+ const final = Object.entries(markValue).map(([key, value]) => `${key}: ${value}`).join(";");
50655
+ return final;
50656
+ };
50657
+ const getLinkedStyle = (styleId, styles = []) => {
50658
+ return styles.find((style2) => style2.id === styleId);
50659
+ };
50660
+ const getSpacingStyleString = (spacing) => {
50661
+ const { lineSpaceBefore, lineSpaceAfter, line } = spacing;
50662
+ return `
50663
+ ${lineSpaceBefore ? `margin-top: ${lineSpaceBefore}px;` : ""}
50664
+ ${lineSpaceAfter ? `margin-bottom: ${lineSpaceAfter}px;` : ""}
50665
+ ${line ? getLineHeightValueString(line, "") : ""}
50666
+ `.trim();
50667
+ };
50668
+ const getMarksStyle = (attrs) => {
50669
+ let styles = "";
50670
+ for (const attr of attrs) {
50671
+ switch (attr.type) {
50672
+ case "bold":
50673
+ styles += `font-weight: bold; `;
50674
+ break;
50675
+ case "italic":
50676
+ styles += `font-style: italic; `;
50677
+ break;
50678
+ case "underline":
50679
+ styles += `text-decoration: underline; `;
50680
+ break;
50681
+ case "highlight":
50682
+ styles += `background-color: ${attr.attrs.color}; `;
50683
+ break;
50684
+ case "textStyle":
50685
+ const { fontFamily: fontFamily2, fontSize: fontSize2 } = attr.attrs;
50686
+ styles += `${fontFamily2 ? `font-family: ${fontFamily2};` : ""} ${fontSize2 ? `font-size: ${fontSize2};` : ""}`;
50687
+ }
50688
+ }
50689
+ return styles.trim();
50690
+ };
50691
+ const getQuickFormatList = (editor) => {
50692
+ if (!editor?.converter) return [];
50693
+ const styles = editor.converter.linkedStyles || [];
50694
+ return styles.filter((style2) => {
50695
+ return style2.type === "paragraph" && style2.definition.attrs;
50696
+ }).sort((a, b) => {
50697
+ return a.definition.attrs?.name.localeCompare(b.definition.attrs?.name);
50698
+ });
50699
+ };
50533
50700
  const generateOrderedListIndex = ({ listLevel, lvlText, listNumberingType }) => {
50534
50701
  const handler = listIndexMap[listNumberingType];
50535
50702
  return handler ? handler(listLevel, lvlText) : null;
@@ -50590,108 +50757,73 @@
50590
50757
  }
50591
50758
  return result;
50592
50759
  };
50593
- function styledListMarker(options2 = {}) {
50594
- return new Plugin({
50595
- key: new PluginKey("styledListMarker"),
50596
- state: {
50597
- init(_, state2) {
50598
- const decorations = [
50599
- ...getListMarkerDecorations(state2),
50600
- ...getListItemStylingFromParagraphProps(state2)
50601
- ];
50602
- return DecorationSet.create(state2.doc, decorations);
50603
- },
50604
- apply(tr, oldDecorationSet, oldState, newState) {
50605
- if (!tr.docChanged) return oldDecorationSet;
50606
- const isOrderedListPlugin = tr.getMeta("orderedListMarker");
50607
- if (isOrderedListPlugin) return oldDecorationSet;
50608
- const marks = tr.getMeta("splitListItem");
50609
- const decorations = [
50610
- ...getListMarkerDecorations(newState, marks),
50611
- ...getListItemStylingFromParagraphProps(newState)
50612
- ];
50613
- return DecorationSet.create(newState.doc, decorations);
50614
- }
50615
- },
50616
- props: {
50617
- decorations(state2) {
50618
- return this.getState(state2);
50619
- }
50620
- }
50621
- });
50622
- }
50623
- function getListMarkerDecorations(state2, marks = []) {
50624
- let { doc: doc2, storedMarks } = state2;
50625
- let decorations = [];
50626
- if (Array.isArray(storedMarks)) marks.push(...storedMarks);
50627
- let listItems = findChildren$3(doc2, (node2) => node2.type.name === "listItem");
50628
- if (!listItems.length) {
50629
- return decorations;
50630
- }
50631
- listItems.forEach(({ node: node2, pos }) => {
50632
- let textStyleType = getMarkType("textStyle", doc2.type.schema);
50633
- let textStyleMarks = [...marks.filter((m) => m.type === textStyleType)];
50634
- let isEmptyListItem = checkListItemEmpty(node2);
50635
- if (isEmptyListItem && marks.length) {
50636
- const textMarks = marks.filter((mark) => mark.type === textStyleType);
50637
- textStyleMarks.push(...textMarks);
50638
- } else {
50639
- const itemMarks = getListItemTextStyleMarks(node2, doc2, textStyleType);
50640
- textStyleMarks.push(...itemMarks);
50641
- }
50642
- let fontSize2 = null;
50643
- let fontFamily2 = null;
50644
- textStyleMarks.forEach((mark) => {
50645
- let { attrs: attrs2 } = mark;
50646
- if (attrs2.fontSize && !fontSize2) {
50647
- let [value, unit] = parseSizeUnit(attrs2.fontSize);
50648
- if (!Number.isNaN(value)) {
50649
- unit = unit ?? "pt";
50650
- fontSize2 = `${value}${unit}`;
50651
- }
50652
- }
50653
- if (attrs2.fontFamily && !fontFamily2) {
50654
- fontFamily2 = attrs2.fontFamily;
50655
- }
50760
+ class ListItemNodeView {
50761
+ constructor(node2, getPos, decorations, editor) {
50762
+ __privateAdd$1(this, _ListItemNodeView_instances);
50763
+ __publicField$1(this, "handleNumberingClick", (event) => {
50656
50764
  });
50657
- let fontSizeAttrs = {
50658
- style: `--marker-font-size: ${fontSize2 ?? "initial"}`
50659
- };
50660
- let fontFamilyAttrs = {
50661
- style: `--marker-font-family: ${fontFamily2 ?? "initial"}`
50662
- };
50663
- let attrs = Attribute.mergeAttributes(fontSizeAttrs, fontFamilyAttrs);
50664
- let dec = Decoration.node(pos, pos + node2.nodeSize, attrs);
50665
- decorations.push(dec);
50666
- });
50667
- return decorations;
50765
+ this.node = node2;
50766
+ this.editor = editor;
50767
+ this.decorations = decorations;
50768
+ this.view = editor.view;
50769
+ this.getPos = getPos;
50770
+ this.editor = editor;
50771
+ __privateMethod$1(this, _ListItemNodeView_instances, init_fn2).call(this);
50772
+ }
50773
+ update(node2) {
50774
+ if (node2.type !== this.node.type) return false;
50775
+ this.node = node2;
50776
+ return true;
50777
+ }
50778
+ destroy() {
50779
+ this.numberingDOM.removeEventListener("click", this.handleNumberingClick);
50780
+ }
50668
50781
  }
50669
- function getListItemStylingFromParagraphProps(state2) {
50670
- let { doc: doc2 } = state2;
50671
- let decorations = [];
50672
- let listItems = findChildren$3(doc2, (node2) => node2.type.name === "listItem");
50673
- if (!listItems.length) {
50674
- return decorations;
50675
- }
50676
- listItems.forEach(({ node: node2, pos }) => {
50677
- let spacingAttrs = {};
50678
- if (node2.attrs.spacing) {
50679
- const { lineSpaceBefore, lineSpaceAfter, line } = node2.attrs.spacing;
50680
- const style2 = `
50681
- ${lineSpaceBefore ? `margin-top: ${lineSpaceBefore}px;` : ""}
50682
- ${lineSpaceAfter ? `margin-bottom: ${lineSpaceAfter}px;` : ""}
50683
- ${line ? getLineHeightValueString(line, "") : ""}
50684
- `.trim();
50685
- spacingAttrs = {
50686
- style: style2
50687
- };
50688
- }
50689
- let dec = Decoration.node(pos, pos + node2.nodeSize, spacingAttrs);
50690
- decorations.push(dec);
50782
+ _ListItemNodeView_instances = /* @__PURE__ */ new WeakSet();
50783
+ init_fn2 = function() {
50784
+ const { attrs } = this.node;
50785
+ const { styleId, listLevel, listNumberingType, lvlText, numId, level, indent: inlineIndent } = attrs;
50786
+ let orderMarker = "";
50787
+ if (listLevel) {
50788
+ orderMarker = generateOrderedListIndex({
50789
+ listLevel,
50790
+ lvlText,
50791
+ listNumberingType
50792
+ });
50793
+ }
50794
+ const pos = this.getPos();
50795
+ const { fontSize: fontSize2, fontFamily: fontFamily2 } = getTextStyleMarksFromLinkedStyles({
50796
+ node: this.node,
50797
+ pos,
50798
+ editor: this.editor
50691
50799
  });
50692
- return decorations;
50693
- }
50694
- function getListItemTextStyleMarks(listItem, doc2, markType) {
50800
+ const defs = getListItemStyleDefinitions({ styleId, node: this.node, numId, level, editor: this.editor });
50801
+ const visibleIndent = getVisibleIndent(defs.stylePpr, defs.numDefPpr, inlineIndent);
50802
+ console.debug("VISIBLEINDENT", visibleIndent, "\n\n\n\n");
50803
+ let absoluteLeft = visibleIndent.left - (visibleIndent.hanging || 0);
50804
+ if (!absoluteLeft && absoluteLeft !== 0) absoluteLeft = 0;
50805
+ this.dom = document.createElement("li");
50806
+ this.dom.className = "sd-editor-list-item-node-view";
50807
+ this.dom.style.fontSize = fontSize2;
50808
+ this.dom.style.fontFamily = fontFamily2;
50809
+ this.dom.setAttribute("data-marker-type", orderMarker);
50810
+ this.numberingDOM = document.createElement("span");
50811
+ this.numberingDOM.className = "sd-editor-list-item-numbering";
50812
+ this.numberingDOM.textContent = orderMarker;
50813
+ this.numberingDOM.setAttribute("contenteditable", "false");
50814
+ this.numberingDOM.addEventListener("click", this.handleNumberingClick);
50815
+ this.contentDOM = document.createElement("p");
50816
+ this.contentDOM.className = "sd-editor-list-item-content-dom";
50817
+ let contentLeft = visibleIndent.left;
50818
+ if (visibleIndent.left === absoluteLeft) {
50819
+ contentLeft = 48;
50820
+ }
50821
+ this.contentDOM.style.marginLeft = `${contentLeft}px`;
50822
+ this.numberingDOM.style.left = `${absoluteLeft}px`;
50823
+ this.dom.appendChild(this.numberingDOM);
50824
+ this.dom.appendChild(this.contentDOM);
50825
+ };
50826
+ function getListItemTextStyleMarks(listItem, markType) {
50695
50827
  let textStyleMarks = [];
50696
50828
  listItem.forEach((childNode) => {
50697
50829
  if (childNode.type.name !== "paragraph") return;
@@ -50706,9 +50838,57 @@
50706
50838
  });
50707
50839
  return textStyleMarks;
50708
50840
  }
50709
- function checkListItemEmpty(listItem) {
50710
- return listItem.childCount === 1 && listItem.firstChild?.type.name === "paragraph" && listItem.firstChild?.content.size === 0;
50711
- }
50841
+ function getTextStyleMarksFromLinkedStyles({ node: node2, pos, editor }) {
50842
+ const { font: defaultFont, size: defaultSize } = getStylesFromLinkedStyles({ node: node2, pos, editor });
50843
+ const textStyleType = getMarkType("textStyle", editor.schema);
50844
+ const allMarks = getListItemTextStyleMarks(node2, textStyleType);
50845
+ const styleMarks = allMarks.filter((m) => m.type === textStyleType);
50846
+ const sizeMark = styleMarks.find((m) => m.attrs.fontSize);
50847
+ const familyMark = styleMarks.find((m) => m.attrs.fontFamily);
50848
+ const fontSize2 = sizeMark ? (() => {
50849
+ const [value, unit = "pt"] = parseSizeUnit(sizeMark.attrs.fontSize);
50850
+ return Number.isNaN(value) ? defaultSize : `${value}${unit}`;
50851
+ })() : defaultSize;
50852
+ const fontFamily2 = familyMark?.attrs.fontFamily ?? defaultFont;
50853
+ return { fontSize: fontSize2, fontFamily: fontFamily2 };
50854
+ }
50855
+ const getStylesFromLinkedStyles = ({ node: node2, pos, editor }) => {
50856
+ const { state: state2 } = editor.view;
50857
+ const linkedStyles = LinkedStylesPluginKey.getState(state2)?.decorations;
50858
+ const decorationsInPlace = linkedStyles?.find(pos, pos + node2.nodeSize);
50859
+ const styleDeco = decorationsInPlace?.find((dec) => dec.type.attrs?.style);
50860
+ const style2 = styleDeco?.type.attrs?.style;
50861
+ const stylesArray = style2?.split(";") || [];
50862
+ const fontSizeFromStyles = stylesArray.find((s) => s.includes("font-size"))?.split(":")[1].trim();
50863
+ const fontFamilyFromStyles = stylesArray.find((s) => s.includes("font-family"))?.split(":")[1].trim();
50864
+ return {
50865
+ font: fontFamilyFromStyles,
50866
+ size: fontSizeFromStyles
50867
+ };
50868
+ };
50869
+ const getVisibleIndent = (stylePpr, numDefPpr, inlineIndent) => {
50870
+ console.debug("[getVisibleIndent] inlineIndent", inlineIndent);
50871
+ const styleIndentTag = stylePpr?.elements?.find((el) => el.name === "w:ind") || {};
50872
+ const styleIndent = parseIndentElement(styleIndentTag);
50873
+ console.debug("[getVisibleIndent] styleIndent", styleIndent, styleIndentTag);
50874
+ const numDefIndentTag = numDefPpr?.elements?.find((el) => el.name === "w:ind") || {};
50875
+ const numDefIndent = parseIndentElement(numDefIndentTag);
50876
+ console.debug("[getVisibleIndent] numDefIndent", numDefIndent, numDefIndentTag, "\n\n");
50877
+ const indent = combineIndents(styleIndent, numDefIndent);
50878
+ return combineIndents(indent, inlineIndent);
50879
+ };
50880
+ const getListItemStyleDefinitions = ({ styleId, numId, level, editor }) => {
50881
+ const docx = editor?.converter?.convertedXml;
50882
+ const styleDefinition = getStyleTagFromStyleId(styleId, docx);
50883
+ const stylePpr = styleDefinition?.elements.find((el) => el.name === "w:pPr");
50884
+ const abstractDefinition = getAbstractDefinition(numId, docx);
50885
+ const numDefinition = getDefinitionForLevel(abstractDefinition, level);
50886
+ const numDefPpr = numDefinition?.elements.find((el) => el.name === "w:pPr");
50887
+ return {
50888
+ stylePpr,
50889
+ numDefPpr
50890
+ };
50891
+ };
50712
50892
  const ListItem = Node$1.create({
50713
50893
  name: "listItem",
50714
50894
  content: "paragraph* block*",
@@ -50730,6 +50910,15 @@
50730
50910
  renderDOM({ htmlAttributes }) {
50731
50911
  return ["li", Attribute.mergeAttributes(this.options.htmlAttributes, htmlAttributes), 0];
50732
50912
  },
50913
+ /**
50914
+ * Important: The listItem node uses a custom node view.
50915
+ * @returns {import('@core/NodeView.js').NodeView}
50916
+ */
50917
+ addNodeView() {
50918
+ return ({ node: node2, editor, getPos, decorations }) => {
50919
+ return new ListItemNodeView(node2, getPos, decorations, editor);
50920
+ };
50921
+ },
50733
50922
  addAttributes() {
50734
50923
  return {
50735
50924
  // Virtual attribute.
@@ -50754,6 +50943,7 @@
50754
50943
  },
50755
50944
  lvlText: {
50756
50945
  default: null,
50946
+ keepOnSplit: true,
50757
50947
  parseDOM: (elem) => elem.getAttribute("data-lvl-text"),
50758
50948
  renderDOM: (attrs) => {
50759
50949
  if (!attrs.lvlText) return {};
@@ -50764,6 +50954,7 @@
50764
50954
  },
50765
50955
  listNumberingType: {
50766
50956
  default: null,
50957
+ keepOnSplit: true,
50767
50958
  parseDOM: (elem) => elem.getAttribute("data-num-fmt"),
50768
50959
  renderDOM: (attrs) => {
50769
50960
  if (!attrs.listNumberingType) return {};
@@ -50774,6 +50965,7 @@
50774
50965
  },
50775
50966
  listLevel: {
50776
50967
  default: null,
50968
+ keepOnSplit: true,
50777
50969
  parseDOM: (elem) => {
50778
50970
  let listLevel = elem.getAttribute("data-list-level");
50779
50971
  try {
@@ -50791,52 +50983,61 @@
50791
50983
  },
50792
50984
  // JC = justification. Expect left, right, center
50793
50985
  lvlJc: {
50986
+ keepOnSplit: true,
50794
50987
  default: null,
50795
50988
  rendered: false
50796
50989
  },
50797
50990
  // This will contain indentation and space info.
50798
50991
  // ie: w:left (left indent), w:hanging (hanging indent)
50799
50992
  listParagraphProperties: {
50993
+ keepOnSplit: true,
50800
50994
  default: null,
50801
50995
  rendered: false
50802
50996
  },
50803
50997
  // This will contain run properties for the list item
50804
50998
  listRunProperties: {
50999
+ keepOnSplit: true,
50805
51000
  default: null,
50806
51001
  rendered: false
50807
51002
  },
50808
51003
  numId: {
51004
+ keepOnSplit: true,
50809
51005
  default: null,
50810
- parseDOM: (elem) => elem.getAttribute("data-num-id")
50811
- },
50812
- attributes: {
50813
51006
  rendered: false
50814
51007
  },
50815
- importedFontSize: {
50816
- parseDOM: (elem) => elem.getAttribute("data-font-size"),
50817
- renderDOM: (attrs) => {
50818
- if (!attrs.importedFontSize) return {};
50819
- return {
50820
- "data-font-size": attrs.importedFontSize
50821
- };
50822
- }
51008
+ numPrType: {
51009
+ rendered: false,
51010
+ default: null,
51011
+ keepOnSplit: true
50823
51012
  },
50824
- importedFontFamily: {
50825
- parseDOM: (elem) => elem.getAttribute("data-font-family"),
50826
- renderDOM: (attrs) => {
50827
- if (!attrs.importedFontFamily) return {};
50828
- return {
50829
- "data-font-family": attrs.importedFontFamily
50830
- };
50831
- }
51013
+ level: {
51014
+ default: null,
51015
+ rendered: false,
51016
+ keepOnSplit: true
51017
+ },
51018
+ attributes: {
51019
+ keepOnSplit: true,
51020
+ rendered: false
50832
51021
  },
50833
51022
  spacing: {
51023
+ keepOnSplit: true,
50834
51024
  default: null,
50835
51025
  rendered: false
50836
51026
  },
50837
51027
  indent: {
51028
+ keepOnSplit: true,
50838
51029
  default: null,
50839
51030
  rendered: false
51031
+ },
51032
+ markerStyle: {
51033
+ default: null,
51034
+ rendered: false,
51035
+ keepOnSplit: true
51036
+ },
51037
+ styleId: {
51038
+ rendered: false,
51039
+ keepOnSplit: true,
51040
+ keepOnSplit: true
50840
51041
  }
50841
51042
  };
50842
51043
  },
@@ -50845,49 +51046,21 @@
50845
51046
  getCurrentListNode: () => ({ state: state2 }) => {
50846
51047
  return findParentNode((node2) => node2.type.name === this.name)(state2.selection);
50847
51048
  },
50848
- increaseListIndent: () => ({ commands: commands2 }) => {
50849
- if (!commands2.sinkListItem(this.name)) {
50850
- return false;
50851
- }
50852
- commands2.updateNodeStyle();
50853
- commands2.updateOrderedListStyleType();
50854
- return true;
50855
- },
50856
- decreaseListIndent: () => ({ commands: commands2 }) => {
50857
- const currentList = commands2.getCurrentList();
50858
- const depth = currentList?.depth;
50859
- if (depth === 1) return false;
50860
- if (!commands2.liftListItem(this.name)) {
50861
- return true;
50862
- }
50863
- if (!commands2.updateNodeStyle()) {
50864
- return false;
50865
- }
50866
- const currentNode = commands2.getCurrentListNode();
50867
- const currentNodeIndex = currentList?.node?.children.findIndex((child) => child === currentNode.node);
50868
- const nextNodePos = currentNode?.pos + currentNode?.node.nodeSize;
50869
- const followingNodes = currentList?.node?.children.slice(currentNodeIndex + 1) || [];
50870
- commands2.updateOrderedListStyleType();
50871
- commands2.restartListNodes(followingNodes, nextNodePos);
50872
- return true;
51049
+ increaseListIndent: () => ({ commands: commands2, chain, editor }) => {
51050
+ const node2 = commands2.getCurrentListNode();
51051
+ return ListHelpers.indentListItem({ editor, chain, node: node2 });
50873
51052
  },
50874
- updateNodeStyle: () => ({ tr, state: state2 }) => {
50875
- let list = findParentNode((node2) => node2.type.name === "orderedList")(tr.selection);
50876
- const current = findParentNode((node2) => node2.type.name === this.name)(state2.selection);
50877
- if (!list) return false;
50878
- const firstNodeAttrs = list?.node.children[0]?.attrs;
50879
- const newPos = tr.mapping.map(current.pos);
50880
- tr.setNodeMarkup(newPos, void 0, {
50881
- ...firstNodeAttrs
50882
- });
50883
- return true;
51053
+ decreaseListIndent: () => ({ commands: commands2, chain, editor }) => {
51054
+ const node2 = commands2.getCurrentListNode();
51055
+ return ListHelpers.outdentListItem({ editor, chain, node: node2 });
50884
51056
  }
50885
51057
  };
50886
51058
  },
50887
51059
  addShortcuts() {
50888
51060
  return {
50889
51061
  Enter: () => {
50890
- return this.editor.commands.splitListItem(this.name);
51062
+ const node2 = this.editor.commands.getCurrentListNode();
51063
+ return this.editor.commands.splitListItem(this.name, node2);
50891
51064
  },
50892
51065
  "Shift-Enter": () => {
50893
51066
  return this.editor.commands.first(({ commands: commands2 }) => [
@@ -50902,180 +51075,8 @@
50902
51075
  return this.editor.commands.decreaseListIndent();
50903
51076
  }
50904
51077
  };
50905
- },
50906
- addPmPlugins() {
50907
- return [styledListMarker()];
50908
- }
50909
- });
50910
- const LinkedStylesPluginKey = new PluginKey("linkedStyles");
50911
- const LinkedStyles = Extension.create({
50912
- name: "linkedStyles",
50913
- addPmPlugins() {
50914
- return [createLinkedStylesPlugin(this.editor)];
50915
- },
50916
- addCommands() {
50917
- return {
50918
- setLinkedStyle: (style2) => (params2) => {
50919
- if (!style2) return;
50920
- const { tr } = params2;
50921
- const selection = tr.selection;
50922
- const { from: from2, to } = selection;
50923
- if (from2 === to) return;
50924
- let pos = from2;
50925
- let paragraphNode = tr.doc.nodeAt(from2);
50926
- if (paragraphNode.type.name !== "paragraph") {
50927
- const parentNode2 = findParentNode((node2) => node2.type.name === "paragraph")(tr.selection) || {};
50928
- pos = parentNode2.pos;
50929
- paragraphNode = parentNode2.node;
50930
- }
50931
- tr.setNodeMarkup(pos, void 0, {
50932
- ...paragraphNode.attrs,
50933
- styleId: style2.id
50934
- });
50935
- }
50936
- };
50937
51078
  }
50938
51079
  });
50939
- const createLinkedStylesPlugin = (editor) => {
50940
- return new Plugin({
50941
- key: LinkedStylesPluginKey,
50942
- state: {
50943
- init(_, { doc: doc2, selection }) {
50944
- if (!editor.converter || editor.options.mode !== "docx") return {};
50945
- const styles = editor.converter?.linkedStyles || [];
50946
- return {
50947
- styles,
50948
- decorations: generateDecorations(editor.state, styles)
50949
- };
50950
- },
50951
- apply(tr, prev, oldEditorState, newEditorState) {
50952
- if (!editor.converter || editor.options.mode !== "docx") return { ...prev };
50953
- let decorations = prev.decorations || DecorationSet.empty;
50954
- if (tr.docChanged) {
50955
- const styles = LinkedStylesPluginKey.getState(editor.state).styles;
50956
- decorations = generateDecorations(newEditorState, styles);
50957
- }
50958
- return { ...prev, decorations };
50959
- }
50960
- },
50961
- props: {
50962
- decorations(state2) {
50963
- return LinkedStylesPluginKey.getState(state2)?.decorations;
50964
- }
50965
- }
50966
- });
50967
- };
50968
- const generateDecorations = (state2, styles) => {
50969
- const decorations = [];
50970
- let lastStyleId = null;
50971
- const doc2 = state2?.doc;
50972
- doc2.descendants((node2, pos) => {
50973
- const { name } = node2.type;
50974
- if (node2?.attrs?.styleId) lastStyleId = node2.attrs.styleId;
50975
- if (name === "paragraph" && !node2.attrs?.styleId) lastStyleId = null;
50976
- if (name !== "text") return;
50977
- const linkedStyle = getLinkedStyle(lastStyleId, styles);
50978
- if (!linkedStyle) return;
50979
- const $pos = state2.doc.resolve(pos);
50980
- const parent = $pos.parent;
50981
- const styleString = generateLinkedStyleString(linkedStyle, node2, parent);
50982
- if (!styleString) return;
50983
- const decoration = Decoration.inline(pos, pos + node2.nodeSize, { style: styleString });
50984
- decorations.push(decoration);
50985
- });
50986
- return DecorationSet.create(doc2, decorations);
50987
- };
50988
- const generateLinkedStyleString = (linkedStyle, node2, parent, includeSpacing = true) => {
50989
- if (!linkedStyle?.definition?.styles) return "";
50990
- const markValue = {};
50991
- Object.entries(linkedStyle.definition.styles).forEach(([k, value]) => {
50992
- const key = kebabCase$2(k);
50993
- const flattenedMarks = [];
50994
- node2?.marks?.forEach((n) => {
50995
- if (n.type.name === "textStyle") {
50996
- Object.entries(n.attrs).forEach(([styleKey, value2]) => {
50997
- const parsedKey = kebabCase$2(styleKey);
50998
- if (!value2) return;
50999
- flattenedMarks.push({ key: parsedKey, value: value2 });
51000
- });
51001
- return;
51002
- }
51003
- flattenedMarks.push({ key: n.type.name, value: n.attrs[key] });
51004
- });
51005
- const mark = flattenedMarks.find((n) => n.key === key);
51006
- const hasParentIndent = Object.keys(parent?.attrs?.indent || {});
51007
- const hasParentSpacing = Object.keys(parent?.attrs?.spacing || {});
51008
- if (!mark) {
51009
- if (key === "spacing" && includeSpacing && !hasParentSpacing) {
51010
- const space = getSpacingStyle(value);
51011
- Object.entries(space).forEach(([k2, v]) => {
51012
- markValue[k2] = v;
51013
- });
51014
- } else if (key === "indent" && includeSpacing && !hasParentIndent) {
51015
- const { leftIndent, rightIndent, firstLine } = value;
51016
- if (leftIndent) markValue["margin-left"] = leftIndent + "px";
51017
- if (rightIndent) markValue["margin-right"] = rightIndent + "px";
51018
- if (firstLine) markValue["text-indent"] = firstLine + "px";
51019
- } else if (key === "bold") {
51020
- markValue["font-weight"] = "bold";
51021
- } else {
51022
- markValue[key] = value;
51023
- }
51024
- }
51025
- });
51026
- return Object.entries(markValue).map(([key, value]) => `${key}: ${value}`).join(";");
51027
- };
51028
- const getLinkedStyle = (styleId, styles = []) => {
51029
- return styles.find((style2) => style2.id === styleId);
51030
- };
51031
- const getSpacingStyle = (spacing) => {
51032
- const { lineSpaceBefore, lineSpaceAfter, line, lineRule } = spacing;
51033
- return {
51034
- "margin-top": lineSpaceBefore + "px",
51035
- "margin-bottom": lineSpaceAfter + "px",
51036
- ...getLineHeightValueString(line, "", lineRule, true)
51037
- };
51038
- };
51039
- const getSpacingStyleString = (spacing) => {
51040
- const { lineSpaceBefore, lineSpaceAfter, line } = spacing;
51041
- return `
51042
- ${lineSpaceBefore ? `margin-top: ${lineSpaceBefore}px;` : ""}
51043
- ${lineSpaceAfter ? `margin-bottom: ${lineSpaceAfter}px;` : ""}
51044
- ${line ? getLineHeightValueString(line, "") : ""}
51045
- `.trim();
51046
- };
51047
- const getMarksStyle = (attrs) => {
51048
- let styles = "";
51049
- for (const attr of attrs) {
51050
- switch (attr.type) {
51051
- case "bold":
51052
- styles += `font-weight: bold; `;
51053
- break;
51054
- case "italic":
51055
- styles += `font-style: italic; `;
51056
- break;
51057
- case "underline":
51058
- styles += `text-decoration: underline; `;
51059
- break;
51060
- case "highlight":
51061
- styles += `background-color: ${attr.attrs.color}; `;
51062
- break;
51063
- case "textStyle":
51064
- const { fontFamily: fontFamily2, fontSize: fontSize2 } = attr.attrs;
51065
- styles += `${fontFamily2 ? `font-family: ${fontFamily2};` : ""} ${fontSize2 ? `font-size: ${fontSize2};` : ""}`;
51066
- }
51067
- }
51068
- return styles.trim();
51069
- };
51070
- const getQuickFormatList = (editor) => {
51071
- if (!editor?.converter) return [];
51072
- const styles = editor.converter.linkedStyles || [];
51073
- return styles.filter((style2) => {
51074
- return style2.type === "paragraph" && style2.definition.attrs;
51075
- }).sort((a, b) => {
51076
- return a.definition.attrs?.name.localeCompare(b.definition.attrs?.name);
51077
- });
51078
- };
51079
51080
  const getDefaultSpacing = () => ({
51080
51081
  lineSpaceAfter: 0,
51081
51082
  lineSpaceBefore: 0,
@@ -51128,9 +51129,13 @@
51128
51129
  }
51129
51130
  },
51130
51131
  indent: {
51132
+ default: null,
51131
51133
  renderDOM: ({ indent }) => {
51132
51134
  if (!indent) return {};
51133
51135
  const { left: left2, right: right2, firstLine, hanging } = indent;
51136
+ if (indent && Object.values(indent).every((v) => v === 0)) {
51137
+ return {};
51138
+ }
51134
51139
  let style2 = "";
51135
51140
  if (left2) style2 += `margin-left: ${left2}px;`;
51136
51141
  if (right2) style2 += `margin-right: ${right2}px;`;
@@ -51477,8 +51482,8 @@
51477
51482
  const prevNodeSize = $pos.nodeBefore?.nodeSize || 0;
51478
51483
  let textWidth = 0;
51479
51484
  try {
51480
- state2.doc.nodesBetween(pos - prevNodeSize - 1, pos - 1, (node22, nodePos) => {
51481
- if (node22.isText && node22.textContent !== " ") {
51485
+ state2.doc.nodesBetween(pos - prevNodeSize - 1, pos - 1, (node3, nodePos) => {
51486
+ if (node3.isText && node3.textContent !== " ") {
51482
51487
  const textWidthForNode = calcTextWidth(view, nodePos);
51483
51488
  textWidth += textWidthForNode;
51484
51489
  }
@@ -54746,8 +54751,8 @@
54746
54751
  }
54747
54752
  function findNode(node2, predicate) {
54748
54753
  let found2 = null;
54749
- node2.descendants((node22, pos) => {
54750
- if (predicate(node22)) found2 = { node: node22, pos };
54754
+ node2.descendants((node3, pos) => {
54755
+ if (predicate(node3)) found2 = { node: node3, pos };
54751
54756
  if (found2) return false;
54752
54757
  });
54753
54758
  return found2;
@@ -60058,12 +60063,17 @@
60058
60063
  }
60059
60064
  }
60060
60065
  }
60061
- if (sectionIds?.titlePg && !sectionIds.first && currentPageNumber === 1) return null;
60066
+ const { titlePg } = editor.converter.headerIds;
60067
+ if (sectionType === "headerIds" && titlePg && !sectionIds.first && currentPageNumber === 1) {
60068
+ return null;
60069
+ }
60062
60070
  const even = sectionIds.even;
60063
60071
  const odd = sectionIds.odd;
60064
60072
  const first2 = sectionIds.first;
60065
60073
  const defaultHeader = sectionIds.default;
60066
- if (sectionIds?.titlePg && first2 && currentPageNumber === 1) return first2;
60074
+ if (titlePg && sectionIds.first && currentPageNumber === 1) {
60075
+ return first2;
60076
+ }
60067
60077
  let sectionId = sectionIds.default;
60068
60078
  if (currentPageNumber === 1) sectionId = defaultHeader;
60069
60079
  if (alternateHeaders) {
@@ -60166,7 +60176,7 @@
60166
60176
  }
60167
60177
  if (isHardBreakNode || shouldAddPageBreak) {
60168
60178
  const $currentPos = view.state.doc.resolve(currentPos);
60169
- const tableRow = findParentNodeClosestToPos($currentPos, (node22) => node22.type.name === "tableRow");
60179
+ const tableRow = findParentNodeClosestToPos($currentPos, (node3) => node3.type.name === "tableRow");
60170
60180
  if (tableRow) {
60171
60181
  currentNode = tableRow.node;
60172
60182
  currentPos = tableRow.pos;
@@ -66362,13 +66372,13 @@ ${style2}
66362
66372
  heightHuge: "46px"
66363
66373
  };
66364
66374
  const {
66365
- fontSize: fontSize$2,
66375
+ fontSize: fontSize$1,
66366
66376
  fontFamily: fontFamily$1,
66367
66377
  lineHeight: lineHeight$1
66368
66378
  } = commonVariables$2$1;
66369
66379
  const globalStyle$1 = c$1$1("body", `
66370
66380
  margin: 0;
66371
- font-size: ${fontSize$2};
66381
+ font-size: ${fontSize$1};
66372
66382
  font-family: ${fontFamily$1};
66373
66383
  line-height: ${lineHeight$1};
66374
66384
  -webkit-text-size-adjust: 100%;
@@ -82276,13 +82286,13 @@ ${style2}
82276
82286
  heightHuge: "46px"
82277
82287
  };
82278
82288
  const {
82279
- fontSize: fontSize$1,
82289
+ fontSize,
82280
82290
  fontFamily,
82281
82291
  lineHeight
82282
82292
  } = commonVariables$3;
82283
82293
  const globalStyle = c$1("body", `
82284
82294
  margin: 0;
82285
- font-size: ${fontSize$1};
82295
+ font-size: ${fontSize};
82286
82296
  font-family: ${fontFamily};
82287
82297
  line-height: ${lineHeight};
82288
82298
  -webkit-text-size-adjust: 100%;
@@ -89344,8 +89354,6 @@ ${style2}
89344
89354
  doc2.setEditor(editor);
89345
89355
  proxy.$superdoc.setActiveEditor(editor);
89346
89356
  proxy.$superdoc.broadcastEditorCreate(editor);
89347
- proxy.$superdoc.log("[SuperDoc] Editor created", proxy.$superdoc.activeEditor);
89348
- proxy.$superdoc.log("[SuperDoc] Page styles (pixels)", editor.getPageStyles());
89349
89357
  initAiLayer(true);
89350
89358
  };
89351
89359
  const onEditorDestroy = () => {
@@ -89770,7 +89778,7 @@ ${style2}
89770
89778
  };
89771
89779
  }
89772
89780
  };
89773
- const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-fc218ba5"]]);
89781
+ const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-cce6555f"]]);
89774
89782
  const createSuperdocVueApp = () => {
89775
89783
  const app = createApp(App);
89776
89784
  const pinia = createPinia();
@@ -89869,7 +89877,7 @@ ${style2}
89869
89877
  this.config.colors = shuffleArray(this.config.colors);
89870
89878
  this.userColorMap = /* @__PURE__ */ new Map();
89871
89879
  this.colorIndex = 0;
89872
- this.version = "0.12.34-next.3";
89880
+ this.version = "0.13.0-RC2";
89873
89881
  console.debug("🦋 [superdoc] Using SuperDoc version:", this.version);
89874
89882
  this.superdocId = config.superdocId || v4();
89875
89883
  this.colors = this.config.colors;