@superdoc-dev/cli 0.2.0-next.130 → 0.2.0-next.131

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 (2) hide show
  1. package/dist/index.js +326 -88
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -38443,7 +38443,7 @@ var init_remark_gfm_z_sDF4ss_es = __esm(() => {
38443
38443
  emptyOptions2 = {};
38444
38444
  });
38445
38445
 
38446
- // ../../packages/superdoc/dist/chunks/SuperConverter-Cw5CEerM.es.js
38446
+ // ../../packages/superdoc/dist/chunks/SuperConverter-C9IFvZwR.es.js
38447
38447
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
38448
38448
  const fieldValue = extension$1.config[field];
38449
38449
  if (typeof fieldValue === "function")
@@ -57998,24 +57998,34 @@ function translateDocumentPartObj(params) {
57998
57998
  }]
57999
57999
  };
58000
58000
  }
58001
+ function sanitizeId(id) {
58002
+ if (typeof id === "string" && id.trim() !== "")
58003
+ return id.trim();
58004
+ }
58001
58005
  function generateSdtPrForDocPartObj(attrs) {
58002
58006
  const existingDocPartObj = attrs.sdtPr?.elements?.find((el) => el.name === "w:docPartObj");
58003
58007
  const existingDocPartGallery = existingDocPartObj?.elements?.find((el) => el.name === "w:docPartGallery")?.attributes?.["w:val"];
58004
58008
  const docPartGallery = attrs.docPartGallery ?? existingDocPartGallery ?? null;
58005
- const id = attrs.id ?? attrs.sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes?.["w:val"] ?? "";
58009
+ const id = sanitizeId(attrs.id ?? attrs.sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes?.["w:val"]);
58006
58010
  const docPartUnique = attrs.docPartUnique ?? existingDocPartObj?.elements?.some((el) => el.name === "w:docPartUnique") ?? false;
58007
58011
  if (docPartGallery === null) {
58008
58012
  if (attrs.sdtPr)
58009
- return attrs.sdtPr;
58010
- return {
58011
- name: "w:sdtPr",
58012
- elements: [{
58013
+ return {
58014
+ ...attrs.sdtPr,
58015
+ elements: Array.isArray(attrs.sdtPr.elements) ? attrs.sdtPr.elements.filter((el) => !(el.name === "w:id" && el.attributes?.["w:val"]?.trim() === "")) : attrs.sdtPr.elements
58016
+ };
58017
+ const elements = [{
58018
+ name: "w:docPartObj",
58019
+ elements: []
58020
+ }];
58021
+ if (id != null)
58022
+ elements.unshift({
58013
58023
  name: "w:id",
58014
58024
  attributes: { "w:val": id }
58015
- }, {
58016
- name: "w:docPartObj",
58017
- elements: []
58018
- }]
58025
+ });
58026
+ return {
58027
+ name: "w:sdtPr",
58028
+ elements
58019
58029
  };
58020
58030
  }
58021
58031
  const docPartObjElements = [{
@@ -58025,12 +58035,14 @@ function generateSdtPrForDocPartObj(attrs) {
58025
58035
  if (docPartUnique)
58026
58036
  docPartObjElements.push({ name: "w:docPartUnique" });
58027
58037
  const sdtPrElements = [{
58028
- name: "w:id",
58029
- attributes: { "w:val": id }
58030
- }, {
58031
58038
  name: "w:docPartObj",
58032
58039
  elements: docPartObjElements
58033
58040
  }];
58041
+ if (id != null)
58042
+ sdtPrElements.unshift({
58043
+ name: "w:id",
58044
+ attributes: { "w:val": id }
58045
+ });
58034
58046
  if (attrs.sdtPr?.elements && Array.isArray(attrs.sdtPr.elements)) {
58035
58047
  const elementsToExclude = ["w:id", "w:docPartObj"];
58036
58048
  const passthroughElements = attrs.sdtPr.elements.filter((el) => el && el.name && !elementsToExclude.includes(el.name));
@@ -64076,11 +64088,7 @@ var isRegExp = (value) => {
64076
64088
  };
64077
64089
  }, tableOfContentsHandler = (params) => {
64078
64090
  const node3 = params.nodes[0];
64079
- const normalizedContent = normalizeDocPartContent(params.nodeListHandler.handler({
64080
- ...params,
64081
- nodes: node3.elements,
64082
- path: [...params.path || [], node3]
64083
- }));
64091
+ const normalizedContent = normalizeDocPartContent(translateTocSdtContent(node3, params));
64084
64092
  const sdtPr = params.extraParams.sdtPr;
64085
64093
  return {
64086
64094
  type: "documentPartObject",
@@ -64113,10 +64121,35 @@ var isRegExp = (value) => {
64113
64121
  sdtPr
64114
64122
  }
64115
64123
  };
64116
- }, validGalleryTypeMap, inlineNodeTypes, wrapInlineNode = (node3) => ({
64124
+ }, validGalleryTypeMap, inlineNodeTypes, SD_TOC_XML_NAME = "sd:tableOfContents", PARAGRAPH_XML_NAME = "w:p", PARAGRAPH_PROPERTIES_XML_NAME = "w:pPr", wrapInlineNode = (node3) => ({
64117
64125
  type: "paragraph",
64118
64126
  content: [node3]
64119
- }), normalizeDocPartContent = (nodes = []) => {
64127
+ }), hasMeaningfulParagraphContent = (elements = []) => elements.some((element) => element?.name && element.name !== PARAGRAPH_PROPERTIES_XML_NAME), translateNodes = (params, nodes, pathTail = []) => params.nodeListHandler.handler({
64128
+ ...params,
64129
+ nodes,
64130
+ path: [...params.path || [], ...pathTail]
64131
+ }), translateTocSdtContent = (sdtContent, params) => {
64132
+ const translatedContent = [];
64133
+ const parentPath = [sdtContent];
64134
+ (sdtContent?.elements || []).forEach((child) => {
64135
+ const childElements = Array.isArray(child?.elements) ? child.elements : [];
64136
+ const tocElements = child?.name === PARAGRAPH_XML_NAME ? childElements.filter((el) => el?.name === SD_TOC_XML_NAME) : [];
64137
+ if (tocElements.length === 0) {
64138
+ translatedContent.push(...translateNodes(params, [child], parentPath));
64139
+ return;
64140
+ }
64141
+ const remainingElements = childElements.filter((el) => el?.name !== SD_TOC_XML_NAME);
64142
+ if (hasMeaningfulParagraphContent(remainingElements))
64143
+ translatedContent.push(...translateNodes(params, [{
64144
+ ...child,
64145
+ elements: remainingElements
64146
+ }], parentPath));
64147
+ tocElements.forEach((tocElement) => {
64148
+ translatedContent.push(...translateNodes(params, [tocElement], [...parentPath, child]));
64149
+ });
64150
+ });
64151
+ return translatedContent;
64152
+ }, normalizeDocPartContent = (nodes = []) => {
64120
64153
  const normalized = [];
64121
64154
  nodes.forEach((node3) => {
64122
64155
  if (inlineNodeTypes.has(node3?.type))
@@ -68546,6 +68579,7 @@ var isRegExp = (value) => {
68546
68579
  let currentFieldStack = [];
68547
68580
  let unpairedEnd = null;
68548
68581
  let collecting = false;
68582
+ const rawNodeSourceTokens = /* @__PURE__ */ new WeakMap;
68549
68583
  const finalizeField = () => {
68550
68584
  if (collecting) {
68551
68585
  const collectedNodes = collectedNodesStack.pop().filter((n) => n !== null);
@@ -68562,16 +68596,30 @@ var isRegExp = (value) => {
68562
68596
  } else
68563
68597
  unpairedEnd = true;
68564
68598
  };
68565
- for (const node3 of nodes) {
68566
- const rawNode = carbonCopy(node3);
68599
+ const captureRawNodeForCurrentField = (rawNode, capturedRawNodes, rawSourceToken) => {
68600
+ if (rawCollectedNodesStack.length === 0)
68601
+ return;
68602
+ if (capturedRawNodes.has(rawNode))
68603
+ return;
68604
+ const currentRawStack = rawCollectedNodesStack[rawCollectedNodesStack.length - 1];
68605
+ const lastRawNode = currentRawStack[currentRawStack.length - 1];
68606
+ if (lastRawNode?.name === "w:r" && rawNode?.name === "w:r" && rawNodeSourceTokens.get(lastRawNode) === rawSourceToken && Array.isArray(lastRawNode.elements) && Array.isArray(rawNode.elements))
68607
+ lastRawNode.elements.push(...carbonCopy(rawNode.elements));
68608
+ else {
68609
+ currentRawStack.push(rawNode);
68610
+ rawNodeSourceTokens.set(rawNode, rawSourceToken);
68611
+ }
68612
+ capturedRawNodes.add(rawNode);
68613
+ };
68614
+ const processNode = (node3, rawNode, capturedRawNodes, rawSourceToken) => {
68567
68615
  collecting = collectedNodesStack.length > 0;
68568
68616
  if (shouldSkipFieldProcessing$1(node3)) {
68569
68617
  if (collecting) {
68570
68618
  collectedNodesStack[collectedNodesStack.length - 1].push(node3);
68571
- rawCollectedNodesStack[collectedNodesStack.length - 1].push(rawNode);
68619
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
68572
68620
  } else
68573
68621
  processedNodes.push(node3);
68574
- continue;
68622
+ return;
68575
68623
  }
68576
68624
  const fldType = node3.elements?.find((el) => el.name === "w:fldChar")?.attributes?.["w:fldCharType"];
68577
68625
  const instrTextEl = node3.elements?.find((el) => el.name === "w:instrText");
@@ -68587,49 +68635,52 @@ var isRegExp = (value) => {
68587
68635
  rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(...processed);
68588
68636
  } else
68589
68637
  processedNodes.push(...processed);
68590
- continue;
68638
+ return;
68591
68639
  }
68592
68640
  }
68593
68641
  }
68594
68642
  if (fldType === "begin") {
68595
68643
  collectedNodesStack.push([]);
68596
- rawCollectedNodesStack.push([rawNode]);
68644
+ const rawStack = [rawNode];
68645
+ rawCollectedNodesStack.push(rawStack);
68646
+ rawNodeSourceTokens.set(rawNode, rawSourceToken);
68647
+ capturedRawNodes.add(rawNode);
68597
68648
  currentFieldStack.push({
68598
68649
  instrText: "",
68599
68650
  instructionTokens: [],
68600
68651
  afterSeparate: false
68601
68652
  });
68602
- continue;
68653
+ return;
68603
68654
  }
68604
68655
  if (collecting && currentFieldStack.length > 0) {
68605
68656
  const currentField = currentFieldStack[currentFieldStack.length - 1];
68606
68657
  if (!currentField.afterSeparate) {
68607
68658
  const instructionTokens = extractInstructionTokensFromNode(node3);
68608
68659
  if (instructionTokens.length > 0) {
68609
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
68660
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
68610
68661
  currentField.instructionTokens.push(...instructionTokens);
68611
68662
  const instrTextValue = instrTextEl?.elements?.[0]?.text;
68612
68663
  if (instrTextValue != null)
68613
68664
  currentField.instrText += `${instrTextValue} `;
68614
68665
  if (instructionTokens.some((token) => token.type === "tab"))
68615
68666
  currentField.instrText += "\t";
68616
- continue;
68667
+ return;
68617
68668
  }
68618
68669
  }
68619
68670
  }
68620
68671
  if (fldType === "end") {
68621
68672
  if (collecting)
68622
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
68673
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
68623
68674
  finalizeField();
68624
- continue;
68675
+ return;
68625
68676
  } else if (fldType === "separate") {
68626
68677
  if (collecting) {
68627
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
68678
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
68628
68679
  const currentField = currentFieldStack[currentFieldStack.length - 1];
68629
68680
  if (currentField)
68630
68681
  currentField.afterSeparate = true;
68631
68682
  }
68632
- continue;
68683
+ return;
68633
68684
  }
68634
68685
  if (Array.isArray(node3.elements)) {
68635
68686
  const childResult = preProcessNodesForFldChar(node3.elements, docx);
@@ -68638,22 +68689,35 @@ var isRegExp = (value) => {
68638
68689
  childResult.unpairedBegin.forEach((pendingField) => {
68639
68690
  currentFieldStack.push(pendingField.fieldInfo);
68640
68691
  collectedNodesStack.push([node3]);
68641
- rawCollectedNodesStack.push([rawNode]);
68692
+ const rawStack = [rawNode];
68693
+ rawCollectedNodesStack.push(rawStack);
68694
+ rawNodeSourceTokens.set(rawNode, rawSourceToken);
68695
+ capturedRawNodes.add(rawNode);
68642
68696
  });
68643
68697
  else if (childResult.unpairedEnd) {
68644
68698
  collectedNodesStack[collectedNodesStack.length - 1].push(node3);
68645
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
68699
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
68646
68700
  finalizeField();
68647
68701
  } else if (collecting) {
68648
68702
  collectedNodesStack[collectedNodesStack.length - 1].push(node3);
68649
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
68703
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
68650
68704
  } else
68651
68705
  processedNodes.push(node3);
68652
68706
  } else if (collecting) {
68653
68707
  collectedNodesStack[collectedNodesStack.length - 1].push(node3);
68654
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
68708
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
68655
68709
  } else
68656
68710
  processedNodes.push(node3);
68711
+ };
68712
+ for (const node3 of nodes) {
68713
+ const rawNode = carbonCopy(node3);
68714
+ const logicalNodes = expandNodeForFieldProcessing(node3);
68715
+ const rawLogicalNodes = expandNodeForFieldProcessing(rawNode);
68716
+ const capturedRawNodes = /* @__PURE__ */ new Set;
68717
+ const rawSourceToken = {};
68718
+ logicalNodes.forEach((logicalNode, index2) => {
68719
+ processNode(logicalNode, rawLogicalNodes[index2] ?? rawNode, capturedRawNodes, rawSourceToken);
68720
+ });
68657
68721
  }
68658
68722
  let unpairedBegin = null;
68659
68723
  if (collectedNodesStack.length > 0) {
@@ -68698,6 +68762,55 @@ var isRegExp = (value) => {
68698
68762
  tokens.push({ type: "tab" });
68699
68763
  });
68700
68764
  return tokens;
68765
+ }, FIELD_CONTROL_ELEMENT_NAMES, INSTRUCTION_ELEMENT_NAMES, cloneNodeWithElements = (node3, elements) => ({
68766
+ ...node3,
68767
+ elements: carbonCopy(elements)
68768
+ }), expandNodeForFieldProcessing = (node3) => {
68769
+ const elements = Array.isArray(node3?.elements) ? node3.elements : null;
68770
+ if (node3?.name !== "w:r" || !elements || elements.length === 0)
68771
+ return [node3];
68772
+ const runProperties = elements.filter((el) => el?.name === "w:rPr");
68773
+ const contentElements = elements.filter((el) => el?.name !== "w:rPr");
68774
+ const logicalNodes = [];
68775
+ let currentKind = null;
68776
+ let currentElements = [];
68777
+ const flushCurrentGroup = () => {
68778
+ if (currentElements.length === 0)
68779
+ return;
68780
+ logicalNodes.push(cloneNodeWithElements(node3, [...runProperties, ...currentElements]));
68781
+ currentElements = [];
68782
+ currentKind = null;
68783
+ };
68784
+ contentElements.forEach((element) => {
68785
+ if (!element?.name) {
68786
+ if (currentKind !== "content") {
68787
+ flushCurrentGroup();
68788
+ currentKind = "content";
68789
+ }
68790
+ currentElements.push(element);
68791
+ return;
68792
+ }
68793
+ if (FIELD_CONTROL_ELEMENT_NAMES.has(element.name)) {
68794
+ flushCurrentGroup();
68795
+ logicalNodes.push(cloneNodeWithElements(node3, [...runProperties, element]));
68796
+ return;
68797
+ }
68798
+ if (INSTRUCTION_ELEMENT_NAMES.has(element.name)) {
68799
+ if (currentKind !== "instruction") {
68800
+ flushCurrentGroup();
68801
+ currentKind = "instruction";
68802
+ }
68803
+ currentElements.push(element);
68804
+ return;
68805
+ }
68806
+ if (currentKind !== "content") {
68807
+ flushCurrentGroup();
68808
+ currentKind = "content";
68809
+ }
68810
+ currentElements.push(element);
68811
+ });
68812
+ flushCurrentGroup();
68813
+ return logicalNodes.length > 1 ? logicalNodes : [node3];
68701
68814
  }, SKIP_FIELD_PROCESSING_NODE_NAMES, shouldSkipFieldProcessing = (node3) => SKIP_FIELD_PROCESSING_NODE_NAMES.has(node3?.name), preProcessPageFieldsOnly = (nodes = [], depth = 0) => {
68702
68815
  const processedNodes = [];
68703
68816
  let i2 = 0;
@@ -74860,7 +74973,7 @@ var isRegExp = (value) => {
74860
74973
  state.kern = kernNode.attributes["w:val"];
74861
74974
  }
74862
74975
  }, SuperConverter;
74863
- var init_SuperConverter_Cw5CEerM_es = __esm(() => {
74976
+ var init_SuperConverter_C9IFvZwR_es = __esm(() => {
74864
74977
  init_rolldown_runtime_B2q5OVn9_es();
74865
74978
  init_jszip_ChlR43oI_es();
74866
74979
  init_xml_js_DLE8mr0n_es();
@@ -100489,6 +100602,8 @@ var init_SuperConverter_Cw5CEerM_es = __esm(() => {
100489
100602
  })();
100490
100603
  }))(), 1);
100491
100604
  SKIP_FIELD_PROCESSING_NODE_NAMES$1 = new Set(["w:drawing", "w:pict"]);
100605
+ FIELD_CONTROL_ELEMENT_NAMES = new Set(["w:fldChar"]);
100606
+ INSTRUCTION_ELEMENT_NAMES = new Set(["w:instrText", "w:tab"]);
100492
100607
  SKIP_FIELD_PROCESSING_NODE_NAMES = new Set(["w:drawing", "w:pict"]);
100493
100608
  HEADER_FOOTER_FILENAME_PATTERN = /^(header|footer)\d*\.xml$/i;
100494
100609
  CHART_TYPE_MAP = {
@@ -135072,7 +135187,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
135072
135187
  init_remark_gfm_z_sDF4ss_es();
135073
135188
  });
135074
135189
 
135075
- // ../../packages/superdoc/dist/chunks/src-BNoEv7Gv.es.js
135190
+ // ../../packages/superdoc/dist/chunks/src-BTrBP-Dc.es.js
135076
135191
  function deleteProps(obj, propOrProps) {
135077
135192
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
135078
135193
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -217807,9 +217922,9 @@ var Node$13 = class Node$14 {
217807
217922
  return false;
217808
217923
  return Boolean(checker(attrs));
217809
217924
  }, SuperToolbar, ICONS, TEXTS, tableActionsOptions;
217810
- var init_src_BNoEv7Gv_es = __esm(() => {
217925
+ var init_src_BTrBP_Dc_es = __esm(() => {
217811
217926
  init_rolldown_runtime_B2q5OVn9_es();
217812
- init_SuperConverter_Cw5CEerM_es();
217927
+ init_SuperConverter_C9IFvZwR_es();
217813
217928
  init_jszip_ChlR43oI_es();
217814
217929
  init_uuid_qzgm05fK_es();
217815
217930
  init_constants_CMPtQbp7_es();
@@ -244930,7 +245045,7 @@ function print() { __p += __j.call(arguments, '') }
244930
245045
  TableOfContents = Node$13.create({
244931
245046
  name: "tableOfContents",
244932
245047
  group: "block",
244933
- content: "paragraph+",
245048
+ content: "paragraph*",
244934
245049
  inline: false,
244935
245050
  addStorage() {
244936
245051
  return { pageMap: null };
@@ -251418,8 +251533,8 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
251418
251533
 
251419
251534
  // ../../packages/superdoc/dist/super-editor.es.js
251420
251535
  var init_super_editor_es = __esm(() => {
251421
- init_src_BNoEv7Gv_es();
251422
- init_SuperConverter_Cw5CEerM_es();
251536
+ init_src_BTrBP_Dc_es();
251537
+ init_SuperConverter_C9IFvZwR_es();
251423
251538
  init_jszip_ChlR43oI_es();
251424
251539
  init_xml_js_DLE8mr0n_es();
251425
251540
  init_constants_CMPtQbp7_es();
@@ -284518,11 +284633,7 @@ function handleDocPartObj2(params3) {
284518
284633
  }
284519
284634
  var tableOfContentsHandler2 = (params3) => {
284520
284635
  const node4 = params3.nodes[0];
284521
- const translatedContent = params3.nodeListHandler.handler({
284522
- ...params3,
284523
- nodes: node4.elements,
284524
- path: [...params3.path || [], node4]
284525
- });
284636
+ const translatedContent = translateTocSdtContent2(node4, params3);
284526
284637
  const normalizedContent = normalizeDocPartContent2(translatedContent);
284527
284638
  const sdtPr = params3.extraParams.sdtPr;
284528
284639
  const id2 = sdtPr.elements?.find((el) => el.name === "w:id")?.attributes["w:val"] || "";
@@ -284563,10 +284674,38 @@ var tableOfContentsHandler2 = (params3) => {
284563
284674
  }
284564
284675
  };
284565
284676
  return result;
284566
- }, validGalleryTypeMap2, inlineNodeTypes2, wrapInlineNode2 = (node4) => ({
284677
+ }, validGalleryTypeMap2, inlineNodeTypes2, SD_TOC_XML_NAME2 = "sd:tableOfContents", PARAGRAPH_XML_NAME2 = "w:p", PARAGRAPH_PROPERTIES_XML_NAME2 = "w:pPr", wrapInlineNode2 = (node4) => ({
284567
284678
  type: "paragraph",
284568
284679
  content: [node4]
284569
- }), normalizeDocPartContent2 = (nodes = []) => {
284680
+ }), hasMeaningfulParagraphContent2 = (elements = []) => elements.some((element3) => element3?.name && element3.name !== PARAGRAPH_PROPERTIES_XML_NAME2), translateNodes2 = (params3, nodes, pathTail = []) => params3.nodeListHandler.handler({
284681
+ ...params3,
284682
+ nodes,
284683
+ path: [...params3.path || [], ...pathTail]
284684
+ }), translateTocSdtContent2 = (sdtContent, params3) => {
284685
+ const translatedContent = [];
284686
+ const parentPath = [sdtContent];
284687
+ (sdtContent?.elements || []).forEach((child) => {
284688
+ const childElements = Array.isArray(child?.elements) ? child.elements : [];
284689
+ const tocElements = child?.name === PARAGRAPH_XML_NAME2 ? childElements.filter((el) => el?.name === SD_TOC_XML_NAME2) : [];
284690
+ if (tocElements.length === 0) {
284691
+ translatedContent.push(...translateNodes2(params3, [child], parentPath));
284692
+ return;
284693
+ }
284694
+ const remainingElements = childElements.filter((el) => el?.name !== SD_TOC_XML_NAME2);
284695
+ if (hasMeaningfulParagraphContent2(remainingElements)) {
284696
+ translatedContent.push(...translateNodes2(params3, [
284697
+ {
284698
+ ...child,
284699
+ elements: remainingElements
284700
+ }
284701
+ ], parentPath));
284702
+ }
284703
+ tocElements.forEach((tocElement) => {
284704
+ translatedContent.push(...translateNodes2(params3, [tocElement], [...parentPath, child]));
284705
+ });
284706
+ });
284707
+ return translatedContent;
284708
+ }, normalizeDocPartContent2 = (nodes = []) => {
284570
284709
  const normalized = [];
284571
284710
  nodes.forEach((node4) => {
284572
284711
  if (inlineNodeTypes2.has(node4?.type)) {
@@ -299235,6 +299374,7 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES2, shouldSkipFieldProcessing2 = (node4) => S
299235
299374
  let currentFieldStack = [];
299236
299375
  let unpairedEnd = null;
299237
299376
  let collecting = false;
299377
+ const rawNodeSourceTokens = new WeakMap;
299238
299378
  const finalizeField = () => {
299239
299379
  if (collecting) {
299240
299380
  const collectedNodes = collectedNodesStack.pop().filter((n) => n !== null);
@@ -299252,17 +299392,32 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES2, shouldSkipFieldProcessing2 = (node4) => S
299252
299392
  unpairedEnd = true;
299253
299393
  }
299254
299394
  };
299255
- for (const node4 of nodes) {
299256
- const rawNode = carbonCopy2(node4);
299395
+ const captureRawNodeForCurrentField = (rawNode, capturedRawNodes, rawSourceToken) => {
299396
+ if (rawCollectedNodesStack.length === 0)
299397
+ return;
299398
+ if (capturedRawNodes.has(rawNode))
299399
+ return;
299400
+ const currentRawStack = rawCollectedNodesStack[rawCollectedNodesStack.length - 1];
299401
+ const lastRawNode = currentRawStack[currentRawStack.length - 1];
299402
+ const canMergeIntoLastNode = lastRawNode?.name === "w:r" && rawNode?.name === "w:r" && rawNodeSourceTokens.get(lastRawNode) === rawSourceToken && Array.isArray(lastRawNode.elements) && Array.isArray(rawNode.elements);
299403
+ if (canMergeIntoLastNode) {
299404
+ lastRawNode.elements.push(...carbonCopy2(rawNode.elements));
299405
+ } else {
299406
+ currentRawStack.push(rawNode);
299407
+ rawNodeSourceTokens.set(rawNode, rawSourceToken);
299408
+ }
299409
+ capturedRawNodes.add(rawNode);
299410
+ };
299411
+ const processNode = (node4, rawNode, capturedRawNodes, rawSourceToken) => {
299257
299412
  collecting = collectedNodesStack.length > 0;
299258
299413
  if (shouldSkipFieldProcessing2(node4)) {
299259
299414
  if (collecting) {
299260
299415
  collectedNodesStack[collectedNodesStack.length - 1].push(node4);
299261
- rawCollectedNodesStack[collectedNodesStack.length - 1].push(rawNode);
299416
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
299262
299417
  } else {
299263
299418
  processedNodes.push(node4);
299264
299419
  }
299265
- continue;
299420
+ return;
299266
299421
  }
299267
299422
  const fldCharEl = node4.elements?.find((el) => el.name === "w:fldChar");
299268
299423
  const fldType = fldCharEl?.attributes?.["w:fldCharType"];
@@ -299280,22 +299435,25 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES2, shouldSkipFieldProcessing2 = (node4) => S
299280
299435
  } else {
299281
299436
  processedNodes.push(...processed);
299282
299437
  }
299283
- continue;
299438
+ return;
299284
299439
  }
299285
299440
  }
299286
299441
  }
299287
299442
  if (fldType === "begin") {
299288
299443
  collectedNodesStack.push([]);
299289
- rawCollectedNodesStack.push([rawNode]);
299444
+ const rawStack = [rawNode];
299445
+ rawCollectedNodesStack.push(rawStack);
299446
+ rawNodeSourceTokens.set(rawNode, rawSourceToken);
299447
+ capturedRawNodes.add(rawNode);
299290
299448
  currentFieldStack.push({ instrText: "", instructionTokens: [], afterSeparate: false });
299291
- continue;
299449
+ return;
299292
299450
  }
299293
299451
  if (collecting && currentFieldStack.length > 0) {
299294
299452
  const currentField = currentFieldStack[currentFieldStack.length - 1];
299295
299453
  if (!currentField.afterSeparate) {
299296
299454
  const instructionTokens = extractInstructionTokensFromNode2(node4);
299297
299455
  if (instructionTokens.length > 0) {
299298
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
299456
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
299299
299457
  currentField.instructionTokens.push(...instructionTokens);
299300
299458
  const instrTextValue = instrTextEl?.elements?.[0]?.text;
299301
299459
  if (instrTextValue != null) {
@@ -299304,25 +299462,25 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES2, shouldSkipFieldProcessing2 = (node4) => S
299304
299462
  if (instructionTokens.some((token) => token.type === "tab")) {
299305
299463
  currentField.instrText += "\t";
299306
299464
  }
299307
- continue;
299465
+ return;
299308
299466
  }
299309
299467
  }
299310
299468
  }
299311
299469
  if (fldType === "end") {
299312
299470
  if (collecting) {
299313
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
299471
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
299314
299472
  }
299315
299473
  finalizeField();
299316
- continue;
299474
+ return;
299317
299475
  } else if (fldType === "separate") {
299318
299476
  if (collecting) {
299319
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
299477
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
299320
299478
  const currentField = currentFieldStack[currentFieldStack.length - 1];
299321
299479
  if (currentField) {
299322
299480
  currentField.afterSeparate = true;
299323
299481
  }
299324
299482
  }
299325
- continue;
299483
+ return;
299326
299484
  }
299327
299485
  if (Array.isArray(node4.elements)) {
299328
299486
  const childResult = preProcessNodesForFldChar2(node4.elements, docx);
@@ -299331,24 +299489,37 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES2, shouldSkipFieldProcessing2 = (node4) => S
299331
299489
  childResult.unpairedBegin.forEach((pendingField) => {
299332
299490
  currentFieldStack.push(pendingField.fieldInfo);
299333
299491
  collectedNodesStack.push([node4]);
299334
- rawCollectedNodesStack.push([rawNode]);
299492
+ const rawStack = [rawNode];
299493
+ rawCollectedNodesStack.push(rawStack);
299494
+ rawNodeSourceTokens.set(rawNode, rawSourceToken);
299495
+ capturedRawNodes.add(rawNode);
299335
299496
  });
299336
299497
  } else if (childResult.unpairedEnd) {
299337
299498
  collectedNodesStack[collectedNodesStack.length - 1].push(node4);
299338
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
299499
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
299339
299500
  finalizeField();
299340
299501
  } else if (collecting) {
299341
299502
  collectedNodesStack[collectedNodesStack.length - 1].push(node4);
299342
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
299503
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
299343
299504
  } else {
299344
299505
  processedNodes.push(node4);
299345
299506
  }
299346
299507
  } else if (collecting) {
299347
299508
  collectedNodesStack[collectedNodesStack.length - 1].push(node4);
299348
- rawCollectedNodesStack[rawCollectedNodesStack.length - 1].push(rawNode);
299509
+ captureRawNodeForCurrentField(rawNode, capturedRawNodes, rawSourceToken);
299349
299510
  } else {
299350
299511
  processedNodes.push(node4);
299351
299512
  }
299513
+ };
299514
+ for (const node4 of nodes) {
299515
+ const rawNode = carbonCopy2(node4);
299516
+ const logicalNodes = expandNodeForFieldProcessing2(node4);
299517
+ const rawLogicalNodes = expandNodeForFieldProcessing2(rawNode);
299518
+ const capturedRawNodes = new Set;
299519
+ const rawSourceToken = {};
299520
+ logicalNodes.forEach((logicalNode, index3) => {
299521
+ processNode(logicalNode, rawLogicalNodes[index3] ?? rawNode, capturedRawNodes, rawSourceToken);
299522
+ });
299352
299523
  }
299353
299524
  let unpairedBegin = null;
299354
299525
  if (collectedNodesStack.length > 0) {
@@ -299382,10 +299553,62 @@ var SKIP_FIELD_PROCESSING_NODE_NAMES2, shouldSkipFieldProcessing2 = (node4) => S
299382
299553
  }
299383
299554
  });
299384
299555
  return tokens;
299556
+ }, FIELD_CONTROL_ELEMENT_NAMES2, INSTRUCTION_ELEMENT_NAMES2, cloneNodeWithElements2 = (node4, elements) => ({
299557
+ ...node4,
299558
+ elements: carbonCopy2(elements)
299559
+ }), expandNodeForFieldProcessing2 = (node4) => {
299560
+ const elements = Array.isArray(node4?.elements) ? node4.elements : null;
299561
+ if (node4?.name !== "w:r" || !elements || elements.length === 0) {
299562
+ return [node4];
299563
+ }
299564
+ const runProperties = elements.filter((el) => el?.name === "w:rPr");
299565
+ const contentElements = elements.filter((el) => el?.name !== "w:rPr");
299566
+ const logicalNodes = [];
299567
+ let currentKind = null;
299568
+ let currentElements = [];
299569
+ const flushCurrentGroup = () => {
299570
+ if (currentElements.length === 0)
299571
+ return;
299572
+ logicalNodes.push(cloneNodeWithElements2(node4, [...runProperties, ...currentElements]));
299573
+ currentElements = [];
299574
+ currentKind = null;
299575
+ };
299576
+ contentElements.forEach((element3) => {
299577
+ if (!element3?.name) {
299578
+ if (currentKind !== "content") {
299579
+ flushCurrentGroup();
299580
+ currentKind = "content";
299581
+ }
299582
+ currentElements.push(element3);
299583
+ return;
299584
+ }
299585
+ if (FIELD_CONTROL_ELEMENT_NAMES2.has(element3.name)) {
299586
+ flushCurrentGroup();
299587
+ logicalNodes.push(cloneNodeWithElements2(node4, [...runProperties, element3]));
299588
+ return;
299589
+ }
299590
+ if (INSTRUCTION_ELEMENT_NAMES2.has(element3.name)) {
299591
+ if (currentKind !== "instruction") {
299592
+ flushCurrentGroup();
299593
+ currentKind = "instruction";
299594
+ }
299595
+ currentElements.push(element3);
299596
+ return;
299597
+ }
299598
+ if (currentKind !== "content") {
299599
+ flushCurrentGroup();
299600
+ currentKind = "content";
299601
+ }
299602
+ currentElements.push(element3);
299603
+ });
299604
+ flushCurrentGroup();
299605
+ return logicalNodes.length > 1 ? logicalNodes : [node4];
299385
299606
  };
299386
299607
  var init_preProcessNodesForFldChar = __esm(() => {
299387
299608
  init_fld_preprocessors();
299388
299609
  SKIP_FIELD_PROCESSING_NODE_NAMES2 = new Set(["w:drawing", "w:pict"]);
299610
+ FIELD_CONTROL_ELEMENT_NAMES2 = new Set(["w:fldChar"]);
299611
+ INSTRUCTION_ELEMENT_NAMES2 = new Set(["w:instrText", "w:tab"]);
299389
299612
  });
299390
299613
 
299391
299614
  // ../../packages/super-editor/src/core/super-converter/field-references/preProcessPageFieldsOnly.js
@@ -303014,30 +303237,43 @@ function translateDocumentPartObj2(params3) {
303014
303237
  };
303015
303238
  return result;
303016
303239
  }
303240
+ function sanitizeId2(id2) {
303241
+ if (typeof id2 === "string" && id2.trim() !== "") {
303242
+ return id2.trim();
303243
+ }
303244
+ return;
303245
+ }
303017
303246
  function generateSdtPrForDocPartObj2(attrs) {
303018
303247
  const existingDocPartObj = attrs.sdtPr?.elements?.find((el) => el.name === "w:docPartObj");
303019
303248
  const existingDocPartGallery = existingDocPartObj?.elements?.find((el) => el.name === "w:docPartGallery")?.attributes?.["w:val"];
303020
303249
  const docPartGallery = attrs.docPartGallery ?? existingDocPartGallery ?? null;
303021
- const id2 = attrs.id ?? attrs.sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes?.["w:val"] ?? "";
303250
+ const id2 = sanitizeId2(attrs.id ?? attrs.sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes?.["w:val"]);
303022
303251
  const docPartUnique = attrs.docPartUnique ?? existingDocPartObj?.elements?.some((el) => el.name === "w:docPartUnique") ?? false;
303023
303252
  if (docPartGallery === null) {
303024
303253
  if (attrs.sdtPr) {
303025
- return attrs.sdtPr;
303254
+ const filteredSdtPr = {
303255
+ ...attrs.sdtPr,
303256
+ elements: Array.isArray(attrs.sdtPr.elements) ? attrs.sdtPr.elements.filter((el) => !(el.name === "w:id" && el.attributes?.["w:val"]?.trim() === "")) : attrs.sdtPr.elements
303257
+ };
303258
+ return filteredSdtPr;
303259
+ }
303260
+ const elements = [
303261
+ {
303262
+ name: "w:docPartObj",
303263
+ elements: []
303264
+ }
303265
+ ];
303266
+ if (id2 != null) {
303267
+ elements.unshift({
303268
+ name: "w:id",
303269
+ attributes: {
303270
+ "w:val": id2
303271
+ }
303272
+ });
303026
303273
  }
303027
303274
  return {
303028
303275
  name: "w:sdtPr",
303029
- elements: [
303030
- {
303031
- name: "w:id",
303032
- attributes: {
303033
- "w:val": id2
303034
- }
303035
- },
303036
- {
303037
- name: "w:docPartObj",
303038
- elements: []
303039
- }
303040
- ]
303276
+ elements
303041
303277
  };
303042
303278
  }
303043
303279
  const docPartObjElements = [
@@ -303052,17 +303288,19 @@ function generateSdtPrForDocPartObj2(attrs) {
303052
303288
  docPartObjElements.push({ name: "w:docPartUnique" });
303053
303289
  }
303054
303290
  const sdtPrElements = [
303055
- {
303056
- name: "w:id",
303057
- attributes: {
303058
- "w:val": id2
303059
- }
303060
- },
303061
303291
  {
303062
303292
  name: "w:docPartObj",
303063
303293
  elements: docPartObjElements
303064
303294
  }
303065
303295
  ];
303296
+ if (id2 != null) {
303297
+ sdtPrElements.unshift({
303298
+ name: "w:id",
303299
+ attributes: {
303300
+ "w:val": id2
303301
+ }
303302
+ });
303303
+ }
303066
303304
  if (attrs.sdtPr?.elements && Array.isArray(attrs.sdtPr.elements)) {
303067
303305
  const elementsToExclude = ["w:id", "w:docPartObj"];
303068
303306
  const passthroughElements = attrs.sdtPr.elements.filter((el) => el && el.name && !elementsToExclude.includes(el.name));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.2.0-next.130",
3
+ "version": "0.2.0-next.131",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -22,19 +22,19 @@
22
22
  "typescript": "^5.9.2",
23
23
  "@superdoc/pm-adapter": "0.0.0",
24
24
  "@superdoc/super-editor": "0.0.1",
25
- "superdoc": "1.18.0",
26
- "@superdoc/document-api": "0.0.1"
25
+ "@superdoc/document-api": "0.0.1",
26
+ "superdoc": "1.18.0"
27
27
  },
28
28
  "module": "src/index.ts",
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
32
  "optionalDependencies": {
33
- "@superdoc-dev/cli-darwin-arm64": "0.2.0-next.130",
34
- "@superdoc-dev/cli-darwin-x64": "0.2.0-next.130",
35
- "@superdoc-dev/cli-linux-x64": "0.2.0-next.130",
36
- "@superdoc-dev/cli-linux-arm64": "0.2.0-next.130",
37
- "@superdoc-dev/cli-windows-x64": "0.2.0-next.130"
33
+ "@superdoc-dev/cli-darwin-arm64": "0.2.0-next.131",
34
+ "@superdoc-dev/cli-darwin-x64": "0.2.0-next.131",
35
+ "@superdoc-dev/cli-linux-x64": "0.2.0-next.131",
36
+ "@superdoc-dev/cli-linux-arm64": "0.2.0-next.131",
37
+ "@superdoc-dev/cli-windows-x64": "0.2.0-next.131"
38
38
  },
39
39
  "scripts": {
40
40
  "dev": "bun run src/index.ts",