@superdoc-dev/cli 0.2.0-next.121 → 0.2.0-next.123

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 +1338 -524
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -38237,7 +38237,7 @@ var init_remark_gfm_z_sDF4ss_es = __esm(() => {
38237
38237
  emptyOptions2 = {};
38238
38238
  });
38239
38239
 
38240
- // ../../packages/superdoc/dist/chunks/SuperConverter-BBGfKYpx.es.js
38240
+ // ../../packages/superdoc/dist/chunks/SuperConverter-BeR1rqZz.es.js
38241
38241
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
38242
38242
  const fieldValue = extension$1.config[field];
38243
38243
  if (typeof fieldValue === "function")
@@ -58454,19 +58454,18 @@ function importCommentData({ docx, editor, converter }) {
58454
58454
  }
58455
58455
  return extendedComments;
58456
58456
  }
58457
- function importFootnoteData({ docx, editor, converter, nodeListHandler, numbering } = {}) {
58457
+ function importNoteEntries({ partXml, childElementName, filename, docx, editor, converter, nodeListHandler, numbering }) {
58458
58458
  const handler$1 = nodeListHandler || defaultNodeListHandler();
58459
- const footnotes = docx?.["word/footnotes.xml"];
58460
- if (!footnotes?.elements?.length)
58459
+ if (!partXml?.elements?.length)
58461
58460
  return [];
58462
- const root2 = footnotes.elements[0];
58463
- const footnoteElements = (Array.isArray(root2?.elements) ? root2.elements : []).filter((el) => el?.name === "w:footnote");
58464
- if (footnoteElements.length === 0)
58461
+ const root2 = partXml.elements[0];
58462
+ const noteElements = (Array.isArray(root2?.elements) ? root2.elements : []).filter((el) => el?.name === childElementName);
58463
+ if (noteElements.length === 0)
58465
58464
  return [];
58466
58465
  const results = [];
58467
58466
  const lists = {};
58468
58467
  const inlineDocumentFonts = [];
58469
- footnoteElements.forEach((el) => {
58468
+ noteElements.forEach((el) => {
58470
58469
  const idRaw = el?.attributes?.["w:id"];
58471
58470
  if (idRaw === undefined || idRaw === null)
58472
58471
  return;
@@ -58495,7 +58494,7 @@ function importFootnoteData({ docx, editor, converter, nodeListHandler, numberin
58495
58494
  numbering,
58496
58495
  lists,
58497
58496
  inlineDocumentFonts,
58498
- filename: "footnotes.xml",
58497
+ filename,
58499
58498
  path: [el]
58500
58499
  }));
58501
58500
  results.push({
@@ -58507,6 +58506,30 @@ function importFootnoteData({ docx, editor, converter, nodeListHandler, numberin
58507
58506
  });
58508
58507
  return results;
58509
58508
  }
58509
+ function importFootnoteData({ docx, editor, converter, nodeListHandler, numbering } = {}) {
58510
+ return importNoteEntries({
58511
+ partXml: docx?.["word/footnotes.xml"],
58512
+ childElementName: "w:footnote",
58513
+ filename: "footnotes.xml",
58514
+ docx,
58515
+ editor,
58516
+ converter,
58517
+ nodeListHandler,
58518
+ numbering
58519
+ });
58520
+ }
58521
+ function importEndnoteData({ docx, editor, converter, nodeListHandler, numbering } = {}) {
58522
+ return importNoteEntries({
58523
+ partXml: docx?.["word/endnotes.xml"],
58524
+ childElementName: "w:endnote",
58525
+ filename: "endnotes.xml",
58526
+ docx,
58527
+ editor,
58528
+ converter,
58529
+ nodeListHandler,
58530
+ numbering
58531
+ });
58532
+ }
58510
58533
  function toIdentityValue(value) {
58511
58534
  if (typeof value === "string" && value.length > 0)
58512
58535
  return value;
@@ -73633,6 +73656,13 @@ var isRegExp = (value) => {
73633
73656
  editor,
73634
73657
  numbering
73635
73658
  });
73659
+ const endnotes = importEndnoteData({
73660
+ docx,
73661
+ nodeListHandler,
73662
+ converter,
73663
+ editor,
73664
+ numbering
73665
+ });
73636
73666
  const translatedLinkedStyles = translateStyleDefinitions(docx);
73637
73667
  const translatedNumbering = translateNumberingDefinitions(docx);
73638
73668
  const importDiagnosticsCollectionId = startCollection();
@@ -73668,6 +73698,7 @@ var isRegExp = (value) => {
73668
73698
  pageStyles: getDocumentStyles(node3, docx, converter, editor, numbering, translatedNumbering, translatedLinkedStyles),
73669
73699
  comments,
73670
73700
  footnotes,
73701
+ endnotes,
73671
73702
  inlineDocumentFonts,
73672
73703
  linkedStyles: getStyleDefinitions(docx, converter, editor),
73673
73704
  translatedLinkedStyles,
@@ -74570,7 +74601,7 @@ var isRegExp = (value) => {
74570
74601
  state.kern = kernNode.attributes["w:val"];
74571
74602
  }
74572
74603
  }, SuperConverter;
74573
- var init_SuperConverter_BBGfKYpx_es = __esm(() => {
74604
+ var init_SuperConverter_BeR1rqZz_es = __esm(() => {
74574
74605
  init_rolldown_runtime_B2q5OVn9_es();
74575
74606
  init_jszip_ChlR43oI_es();
74576
74607
  init_xml_js_DLE8mr0n_es();
@@ -107945,6 +107976,7 @@ var init_SuperConverter_BBGfKYpx_es = __esm(() => {
107945
107976
  this.numbering = result.numbering;
107946
107977
  this.comments = result.comments;
107947
107978
  this.footnotes = result.footnotes;
107979
+ this.endnotes = result.endnotes ?? [];
107948
107980
  this.linkedStyles = result.linkedStyles;
107949
107981
  this.translatedLinkedStyles = result.translatedLinkedStyles;
107950
107982
  this.translatedNumbering = result.translatedNumbering;
@@ -108247,6 +108279,16 @@ var init_SuperConverter_BBGfKYpx_es = __esm(() => {
108247
108279
  content: [...schema]
108248
108280
  };
108249
108281
  }
108282
+ reimportNotePart(partId) {
108283
+ if (!this.convertedXml?.[partId])
108284
+ return [];
108285
+ return (partId === "word/endnotes.xml" ? importEndnoteData : importFootnoteData)({
108286
+ docx: this.convertedXml,
108287
+ editor: {},
108288
+ converter: this,
108289
+ numbering: this.numbering
108290
+ });
108291
+ }
108250
108292
  createDefaultHeader(variant = "default") {
108251
108293
  if (typeof variant !== "string")
108252
108294
  throw new TypeError(`variant must be a string, received ${typeof variant}`);
@@ -134644,7 +134686,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
134644
134686
  init_remark_gfm_z_sDF4ss_es();
134645
134687
  });
134646
134688
 
134647
- // ../../packages/superdoc/dist/chunks/src-Mwv45g3M.es.js
134689
+ // ../../packages/superdoc/dist/chunks/src-BnjrN0Yi.es.js
134648
134690
  function deleteProps(obj, propOrProps) {
134649
134691
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
134650
134692
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -140516,7 +140558,7 @@ function createPartPublisher(editor, ydoc, options = {}) {
140516
140558
  destroy
140517
140559
  };
140518
140560
  }
140519
- function getConverter$10(editor) {
140561
+ function getConverter$12(editor) {
140520
140562
  return editor.converter;
140521
140563
  }
140522
140564
  function isHeaderPartId(partId) {
@@ -140551,7 +140593,7 @@ function ensureHeaderFooterDescriptor(partId, sectionId) {
140551
140593
  };
140552
140594
  },
140553
140595
  afterCommit(ctx$1) {
140554
- const converter = getConverter$10(ctx$1.editor);
140596
+ const converter = getConverter$12(ctx$1.editor);
140555
140597
  if (!converter)
140556
140598
  return;
140557
140599
  const resolvedSectionId = ctx$1.sectionId ?? sectionId;
@@ -140571,7 +140613,7 @@ function ensureHeaderFooterDescriptor(partId, sectionId) {
140571
140613
  refreshActiveSubEditors(converter, type, resolvedSectionId);
140572
140614
  },
140573
140615
  onDelete(ctx$1) {
140574
- const converter = getConverter$10(ctx$1.editor);
140616
+ const converter = getConverter$12(ctx$1.editor);
140575
140617
  if (!converter)
140576
140618
  return;
140577
140619
  const resolvedSectionId = ctx$1.sectionId ?? sectionId;
@@ -140618,11 +140660,11 @@ function registerHeaderFooterInvalidationHandler(partId) {
140618
140660
  } catch {}
140619
140661
  });
140620
140662
  }
140621
- function getConverter$9(editor) {
140663
+ function getConverter$11(editor) {
140622
140664
  return editor.converter;
140623
140665
  }
140624
140666
  function resolvePartIdFromSectionId(editor, sectionId) {
140625
- const relsRoot = getConverter$9(editor)?.convertedXml?.["word/_rels/document.xml.rels"]?.elements?.find((el) => el.name === "Relationships");
140667
+ const relsRoot = getConverter$11(editor)?.convertedXml?.["word/_rels/document.xml.rels"]?.elements?.find((el) => el.name === "Relationships");
140626
140668
  if (!relsRoot?.elements)
140627
140669
  return null;
140628
140670
  for (const el of relsRoot.elements) {
@@ -140664,14 +140706,14 @@ function resolveHeaderFooterRId(partId, relsData, editor) {
140664
140706
  return rId;
140665
140707
  }
140666
140708
  if (editor) {
140667
- const localRels = getConverter$9(editor)?.convertedXml?.["word/_rels/document.xml.rels"];
140709
+ const localRels = getConverter$11(editor)?.convertedXml?.["word/_rels/document.xml.rels"];
140668
140710
  if (localRels)
140669
140711
  return resolveRIdFromRelsData(localRels, partId);
140670
140712
  }
140671
140713
  return null;
140672
140714
  }
140673
140715
  function exportSubEditorToPart(mainEditor, subEditor, sectionId, type) {
140674
- const converter = getConverter$9(mainEditor);
140716
+ const converter = getConverter$11(mainEditor);
140675
140717
  if (!converter?.exportToXmlJson)
140676
140718
  return false;
140677
140719
  const partId = resolvePartIdFromSectionId(mainEditor, sectionId);
@@ -140734,7 +140776,7 @@ function exportSubEditorToPart(mainEditor, subEditor, sectionId, type) {
140734
140776
  }
140735
140777
  }
140736
140778
  function registerExistingHeaderFooterDescriptors(editor) {
140737
- const converter = getConverter$9(editor);
140779
+ const converter = getConverter$11(editor);
140738
140780
  if (!converter?.convertedXml)
140739
140781
  return;
140740
140782
  const relsRoot = converter.convertedXml["word/_rels/document.xml.rels"]?.elements?.find((el) => el.name === "Relationships");
@@ -143875,11 +143917,11 @@ function pxToInches$1(value) {
143875
143917
  function buildSectionId(index2) {
143876
143918
  return `section-${index2}`;
143877
143919
  }
143878
- function getConverter$8(editor) {
143920
+ function getConverter$10(editor) {
143879
143921
  return editor.converter;
143880
143922
  }
143881
143923
  function getBodySectPrFromEditor(editor) {
143882
- const converter = getConverter$8(editor);
143924
+ const converter = getConverter$10(editor);
143883
143925
  if (isSectPrElement$1(converter?.bodySectPr))
143884
143926
  return cloneXmlElement(converter.bodySectPr);
143885
143927
  const docAttrs = editor.state.doc.attrs ?? {};
@@ -143928,7 +143970,7 @@ function resolveAnalysisDoc(editor, paragraphs) {
143928
143970
  return buildAnalysisDocFromParagraphs(paragraphs);
143929
143971
  }
143930
143972
  function getSettingsRoot(editor) {
143931
- const settingsPart = getConverter$8(editor)?.convertedXml?.["word/settings.xml"];
143973
+ const settingsPart = getConverter$10(editor)?.convertedXml?.["word/settings.xml"];
143932
143974
  if (!settingsPart)
143933
143975
  return null;
143934
143976
  if (settingsPart.name === "w:settings")
@@ -143938,7 +143980,7 @@ function getSettingsRoot(editor) {
143938
143980
  return settingsPart.elements.find((entry) => entry.name === "w:settings") ?? null;
143939
143981
  }
143940
143982
  function readOddEvenHeadersFlag(editor) {
143941
- const converter = getConverter$8(editor);
143983
+ const converter = getConverter$10(editor);
143942
143984
  if (converter?.pageStyles?.alternateHeaders != null)
143943
143985
  return converter.pageStyles.alternateHeaders === true;
143944
143986
  const settingsRoot = getSettingsRoot(editor);
@@ -148983,11 +149025,11 @@ function executePlan(editor, input2) {
148983
149025
  expectedRevision: input2.expectedRevision
148984
149026
  });
148985
149027
  }
148986
- function getConverter$7(editor) {
149028
+ function getConverter$9(editor) {
148987
149029
  return editor.converter;
148988
149030
  }
148989
149031
  function takeSnapshot(editor, partIds) {
148990
- const converter = getConverter$7(editor);
149032
+ const converter = getConverter$9(editor);
148991
149033
  const partEntries = /* @__PURE__ */ new Map;
148992
149034
  if (converter?.convertedXml)
148993
149035
  for (const partId of partIds) {
@@ -149002,13 +149044,16 @@ function takeSnapshot(editor, partIds) {
149002
149044
  partEntries,
149003
149045
  numbering: converter?.numbering ? clonePart(converter.numbering) : undefined,
149004
149046
  translatedNumbering: converter?.translatedNumbering ? clonePart(converter.translatedNumbering) : undefined,
149047
+ footnotes: converter?.footnotes ? clonePart(converter.footnotes) : undefined,
149048
+ endnotes: converter?.endnotes ? clonePart(converter.endnotes) : undefined,
149049
+ footnoteProperties: converter?.footnoteProperties ? clonePart(converter.footnoteProperties) : undefined,
149005
149050
  revision: getRevision(editor),
149006
149051
  documentModified: converter?.documentModified ?? false,
149007
149052
  documentGuid: converter?.documentGuid ?? null
149008
149053
  };
149009
149054
  }
149010
149055
  function restoreFromSnapshot(editor, snapshot2) {
149011
- const converter = getConverter$7(editor);
149056
+ const converter = getConverter$9(editor);
149012
149057
  if (!converter)
149013
149058
  return;
149014
149059
  if (converter.convertedXml)
@@ -149023,6 +149068,12 @@ function restoreFromSnapshot(editor, snapshot2) {
149023
149068
  converter.numbering = snapshot2.numbering;
149024
149069
  if (snapshot2.translatedNumbering !== undefined)
149025
149070
  converter.translatedNumbering = snapshot2.translatedNumbering;
149071
+ if (snapshot2.footnotes !== undefined)
149072
+ converter.footnotes = snapshot2.footnotes;
149073
+ if (snapshot2.endnotes !== undefined)
149074
+ converter.endnotes = snapshot2.endnotes;
149075
+ if (snapshot2.footnoteProperties !== undefined)
149076
+ converter.footnoteProperties = snapshot2.footnoteProperties;
149026
149077
  converter.documentModified = snapshot2.documentModified;
149027
149078
  converter.documentGuid = snapshot2.documentGuid;
149028
149079
  restoreRevision(editor, snapshot2.revision);
@@ -154683,11 +154734,11 @@ function assertRunTilingInvariant(runs2, blockRange, blockId) {
154683
154734
  if (runs2[i$1].range.end !== runs2[i$1 + 1].range.start)
154684
154735
  throw planError("INTERNAL_ERROR", `run-tiling: gap or overlap between runs[${i$1}] and runs[${i$1 + 1}] in block ${blockId}`);
154685
154736
  }
154686
- function getConverter$6(editor) {
154737
+ function getConverter$8(editor) {
154687
154738
  return editor.converter;
154688
154739
  }
154689
154740
  function readTranslatedLinkedStyles(editor) {
154690
- return getConverter$6(editor)?.translatedLinkedStyles ?? null;
154741
+ return getConverter$8(editor)?.translatedLinkedStyles ?? null;
154691
154742
  }
154692
154743
  function encodeV3Ref(payload) {
154693
154744
  return `text:${btoa(JSON.stringify(payload))}`;
@@ -158220,10 +158271,10 @@ function registerBuiltInExecutors() {
158220
158271
  };
158221
158272
  } });
158222
158273
  }
158223
- function getConverter$5(editor) {
158274
+ function getConverter$7(editor) {
158224
158275
  return editor.converter;
158225
158276
  }
158226
- function getConverter$4(editor) {
158277
+ function getConverter$6(editor) {
158227
158278
  return editor.converter;
158228
158279
  }
158229
158280
  function createEmptyHeaderFooterJson() {
@@ -158236,7 +158287,7 @@ function createEmptyHeaderFooterJson() {
158236
158287
  };
158237
158288
  }
158238
158289
  function syncHeaderFooterCaches(editor, part) {
158239
- const converter = getConverter$4(editor);
158290
+ const converter = getConverter$6(editor);
158240
158291
  if (!converter)
158241
158292
  return;
158242
158293
  const relsRoot = part?.elements?.find((el) => el.name === "Relationships");
@@ -158311,9 +158362,18 @@ function handleHeaderFooterInvalidation(editor, _event) {
158311
158362
  editor.view?.dispatch?.(tr);
158312
158363
  } catch {}
158313
158364
  }
158365
+ function handleNotesInvalidation(editor, _event) {
158366
+ try {
158367
+ const tr = editor.state.tr;
158368
+ tr.setMeta("forceUpdatePagination", true);
158369
+ editor.view?.dispatch?.(tr);
158370
+ } catch {}
158371
+ }
158314
158372
  function registerStaticInvalidationHandlers() {
158315
158373
  registerInvalidationHandler("word/numbering.xml", handleNumberingInvalidation);
158316
158374
  registerInvalidationHandler("word/_rels/document.xml.rels", handleRelationshipsInvalidation);
158375
+ registerInvalidationHandler("word/footnotes.xml", handleNotesInvalidation);
158376
+ registerInvalidationHandler("word/endnotes.xml", handleNotesInvalidation);
158317
158377
  }
158318
158378
  function registerHeaderFooterInvalidation(partId) {
158319
158379
  registerInvalidationHandler(partId, handleHeaderFooterInvalidation);
@@ -158578,7 +158638,7 @@ function resolveEffectiveRef(editor, sections, startSectionIndex, kind, variant)
158578
158638
  }
158579
158639
  return null;
158580
158640
  }
158581
- function getConverter$3(editor) {
158641
+ function getConverter$5(editor) {
158582
158642
  return editor.converter;
158583
158643
  }
158584
158644
  function setHeaderFooterRefMutation(sectPr, kind, variant, refId, converter, operationName, dryRun = false) {
@@ -158639,7 +158699,7 @@ function setLinkedToPreviousMutation(sectPr, projection, sections, kind, variant
158639
158699
  }
158640
158700
  };
158641
158701
  if (!dryRun && clearedRef) {
158642
- const converter$1 = getConverter$3(editor);
158702
+ const converter$1 = getConverter$5(editor);
158643
158703
  if (converter$1)
158644
158704
  reconcileVariantPointerOnClear(converter$1, kind, clearedRef);
158645
158705
  }
@@ -158676,12 +158736,12 @@ function setLinkedToPreviousMutation(sectPr, projection, sections, kind, variant
158676
158736
  };
158677
158737
  }
158678
158738
  setSectPrHeaderFooterRef(sectPr, kind, variant, explicitRefId);
158679
- const converter = getConverter$3(editor);
158739
+ const converter = getConverter$5(editor);
158680
158740
  if (converter)
158681
158741
  reconcileVariantPointerOnSet(converter, kind, variant, explicitRefId);
158682
158742
  }
158683
158743
  function createExplicitHeaderFooterReference(editor, input2) {
158684
- if (!getConverter$3(editor))
158744
+ if (!getConverter$5(editor))
158685
158745
  return null;
158686
158746
  try {
158687
158747
  const { refId } = createHeaderFooterPart(editor, {
@@ -158719,7 +158779,7 @@ function reconcileVariantPointerOnClear(converter, kind, clearedRefId) {
158719
158779
  if (variantIds[key$1] === clearedRefId)
158720
158780
  variantIds[key$1] = null;
158721
158781
  }
158722
- function getConverter$2(editor) {
158782
+ function getConverter$4(editor) {
158723
158783
  return editor.converter;
158724
158784
  }
158725
158785
  function toSectionFailure$1(code$1, message) {
@@ -158787,7 +158847,7 @@ function buildSectionMarginsForAttrs$1(sectPr) {
158787
158847
  };
158788
158848
  }
158789
158849
  function syncConverterBodySection$1(editor, sectPr) {
158790
- const converter = getConverter$2(editor);
158850
+ const converter = getConverter$4(editor);
158791
158851
  if (!converter)
158792
158852
  return;
158793
158853
  converter.bodySectPr = cloneXmlElement(sectPr);
@@ -158907,7 +158967,7 @@ function createSectionBreakNode(editor, breakParagraphId, input2) {
158907
158967
  return paragraphNode;
158908
158968
  }
158909
158969
  function updateGlobalTitlePageFlag(editor) {
158910
- const converter = getConverter$2(editor);
158970
+ const converter = getConverter$4(editor);
158911
158971
  if (!converter)
158912
158972
  return;
158913
158973
  const anyTitlePage = resolveSectionProjections(editor).some((entry) => entry.domain.titlePage === true);
@@ -158991,7 +159051,7 @@ function sectionsSetTitlePageAdapter(editor, input2, options) {
158991
159051
  }
158992
159052
  function sectionsSetOddEvenHeadersFootersAdapter(editor, input2, options) {
158993
159053
  rejectTrackedMode("sections.setOddEvenHeadersFooters", options);
158994
- const converter = getConverter$2(editor);
159054
+ const converter = getConverter$4(editor);
158995
159055
  if (!converter)
158996
159056
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "sections.setOddEvenHeadersFooters requires an active document converter.");
158997
159057
  return mutatePart({
@@ -159027,13 +159087,13 @@ function sectionsSetSectionDirectionAdapter(editor, input2, options) {
159027
159087
  }
159028
159088
  function sectionsSetHeaderFooterRefAdapter(editor, input2, options) {
159029
159089
  return sectionMutationBySectPr$1(editor, input2, options, "sections.setHeaderFooterRef", (sectPr, _projection, _sections, dryRun) => {
159030
- const converter = getConverter$2(editor) ?? null;
159090
+ const converter = getConverter$4(editor) ?? null;
159031
159091
  return setHeaderFooterRefMutation(sectPr, input2.kind, input2.variant, input2.refId, converter, "sections.setHeaderFooterRef", dryRun);
159032
159092
  });
159033
159093
  }
159034
159094
  function sectionsClearHeaderFooterRefAdapter(editor, input2, options) {
159035
159095
  return sectionMutationBySectPr$1(editor, input2, options, "sections.clearHeaderFooterRef", (sectPr, _projection, _sections, dryRun) => {
159036
- const converter = getConverter$2(editor) ?? null;
159096
+ const converter = getConverter$4(editor) ?? null;
159037
159097
  clearHeaderFooterRefMutation(sectPr, input2.kind, input2.variant, converter, dryRun);
159038
159098
  });
159039
159099
  }
@@ -159623,7 +159683,7 @@ function dispatchEditorTransaction(editor, tr) {
159623
159683
  }
159624
159684
  throw new Error("No transaction dispatcher available.");
159625
159685
  }
159626
- function receiptApplied$10(receipt2) {
159686
+ function receiptApplied$9(receipt2) {
159627
159687
  return receipt2.steps[0]?.effect === "changed";
159628
159688
  }
159629
159689
  function isTocContentUnchanged(existingNode, newContent) {
@@ -159718,7 +159778,7 @@ function tocConfigureWrapper(editor, input2, options) {
159718
159778
  const shouldRefreshContent = !isTocContentUnchanged(resolved.node, nextContent);
159719
159779
  const command$1 = editor.commands?.setTableOfContentsInstructionById;
159720
159780
  const commandNodeId = resolved.commandNodeId ?? resolved.nodeId;
159721
- if (!receiptApplied$10(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159781
+ if (!receiptApplied$9(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159722
159782
  sdBlockId: commandNodeId,
159723
159783
  instruction,
159724
159784
  ...shouldRefreshContent ? { content: nextContent } : {},
@@ -159761,7 +159821,7 @@ function tocUpdateAll(editor, input2, options) {
159761
159821
  if (options?.dryRun)
159762
159822
  return tocSuccess(resolved.nodeId);
159763
159823
  const command$1 = editor.commands?.replaceTableOfContentsContentById;
159764
- return receiptApplied$10(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159824
+ return receiptApplied$9(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159765
159825
  sdBlockId: resolved.commandNodeId ?? resolved.nodeId,
159766
159826
  content: content3
159767
159827
  }, options?.expectedRevision) : runTocAction(editor, () => {
@@ -159804,7 +159864,7 @@ function tocUpdatePageNumbers(editor, input2, options) {
159804
159864
  if (options?.dryRun)
159805
159865
  return tocSuccess(resolved.nodeId);
159806
159866
  const command$1 = editor.commands?.replaceTableOfContentsContentById;
159807
- return receiptApplied$10(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159867
+ return receiptApplied$9(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159808
159868
  sdBlockId: resolved.commandNodeId ?? resolved.nodeId,
159809
159869
  content: updatedContent
159810
159870
  }, options?.expectedRevision) : runTocAction(editor, () => {
@@ -159871,7 +159931,7 @@ function tocRemoveWrapper(editor, input2, options) {
159871
159931
  if (options?.dryRun)
159872
159932
  return tocSuccess(resolved.nodeId);
159873
159933
  const command$1 = editor.commands?.deleteTableOfContentsById;
159874
- return receiptApplied$10(typeof command$1 === "function" ? runTocCommand(editor, command$1, { sdBlockId: resolved.commandNodeId ?? resolved.nodeId }, options?.expectedRevision) : runTocAction(editor, () => {
159934
+ return receiptApplied$9(typeof command$1 === "function" ? runTocCommand(editor, command$1, { sdBlockId: resolved.commandNodeId ?? resolved.nodeId }, options?.expectedRevision) : runTocAction(editor, () => {
159875
159935
  try {
159876
159936
  const { tr } = editor.state;
159877
159937
  tr.delete(resolved.pos, resolved.pos + resolved.node.nodeSize);
@@ -159902,7 +159962,7 @@ function createTableOfContentsWrapper(editor, input2, options) {
159902
159962
  toc: buildTocAddress("(dry-run)")
159903
159963
  };
159904
159964
  const command$1 = editor.commands?.insertTableOfContentsAt;
159905
- if (!receiptApplied$10(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159965
+ if (!receiptApplied$9(typeof command$1 === "function" ? runTocCommand(editor, command$1, {
159906
159966
  pos,
159907
159967
  instruction,
159908
159968
  sdBlockId,
@@ -160097,7 +160157,7 @@ function runEntryCommand(editor, command$1, args$1, expectedRevision) {
160097
160157
  const executeCommand = toEntryEditorCommand(command$1);
160098
160158
  return runEntryAction(editor, () => executeCommand(args$1), expectedRevision);
160099
160159
  }
160100
- function receiptApplied$9(receipt2) {
160160
+ function receiptApplied$8(receipt2) {
160101
160161
  return receipt2.steps[0]?.effect === "changed";
160102
160162
  }
160103
160163
  function tocListEntriesWrapper(editor, query2) {
@@ -160144,7 +160204,7 @@ function tocMarkEntryWrapper(editor, input2, options) {
160144
160204
  const pos = (input2.target.position ?? "end") === "start" ? paragraph2.pos + 1 : paragraph2.pos + paragraph2.node.nodeSize - 1;
160145
160205
  if (options?.dryRun)
160146
160206
  return entrySuccess$2("(dry-run)");
160147
- if (!receiptApplied$9(runEntryCommand(editor, command$1, {
160207
+ if (!receiptApplied$8(runEntryCommand(editor, command$1, {
160148
160208
  pos,
160149
160209
  instruction
160150
160210
  }, options?.expectedRevision)))
@@ -160166,7 +160226,7 @@ function tocUnmarkEntryWrapper(editor, input2, options) {
160166
160226
  const resolved = resolveTcEntryTarget(editor.state.doc, input2.target);
160167
160227
  if (options?.dryRun)
160168
160228
  return entrySuccess$2(resolved.nodeId);
160169
- return receiptApplied$9(runEntryCommand(editor, command$1, { pos: resolved.pos }, options?.expectedRevision)) ? entrySuccess$2(resolved.nodeId) : entryFailure$2("NO_OP", "TC entry removal produced no change.");
160229
+ return receiptApplied$8(runEntryCommand(editor, command$1, { pos: resolved.pos }, options?.expectedRevision)) ? entrySuccess$2(resolved.nodeId) : entryFailure$2("NO_OP", "TC entry removal produced no change.");
160170
160230
  }
160171
160231
  function tocEditEntryWrapper(editor, input2, options) {
160172
160232
  rejectTrackedMode("toc.editEntry", options);
@@ -160179,7 +160239,7 @@ function tocEditEntryWrapper(editor, input2, options) {
160179
160239
  return entryFailure$2("NO_OP", "Edit patch produced no change.");
160180
160240
  if (options?.dryRun)
160181
160241
  return entrySuccess$2(resolved.nodeId);
160182
- if (!receiptApplied$9(runEntryCommand(editor, command$1, {
160242
+ if (!receiptApplied$8(runEntryCommand(editor, command$1, {
160183
160243
  pos: resolved.pos,
160184
160244
  instruction: serializeTcInstruction(patched)
160185
160245
  }, options?.expectedRevision)))
@@ -161512,7 +161572,7 @@ function hyperlinkFailure(code$1, message) {
161512
161572
  }
161513
161573
  };
161514
161574
  }
161515
- function receiptApplied$8(receipt2) {
161575
+ function receiptApplied$7(receipt2) {
161516
161576
  return receipt2.steps[0]?.effect === "changed";
161517
161577
  }
161518
161578
  function matchesListQuery(candidate, query2, editor) {
@@ -161611,7 +161671,7 @@ function hyperlinksWrapWrapper(editor, input2, options) {
161611
161671
  }
161612
161672
  });
161613
161673
  const spec = specFromInput(input2.link);
161614
- if (!receiptApplied$8(executeDomainCommand(editor, () => {
161674
+ if (!receiptApplied$7(executeDomainCommand(editor, () => {
161615
161675
  const result = wrapWithLink(editor, resolved.from, resolved.to, spec);
161616
161676
  if (result)
161617
161677
  clearIndexCache(editor);
@@ -161681,7 +161741,7 @@ function hyperlinksInsertWrapper(editor, input2, options) {
161681
161741
  }
161682
161742
  });
161683
161743
  const spec = specFromInput(input2.link);
161684
- if (!receiptApplied$8(executeDomainCommand(editor, () => {
161744
+ if (!receiptApplied$7(executeDomainCommand(editor, () => {
161685
161745
  if (structuralEnd) {
161686
161746
  insertParagraphAtEnd(editor, insertPos, input2.text);
161687
161747
  clearIndexCache(editor);
@@ -161742,7 +161802,7 @@ function hyperlinksPatchWrapper(editor, input2, options) {
161742
161802
  return hyperlinkFailure("NO_OP", "Patch produces no change — all values already match.");
161743
161803
  if (options?.dryRun)
161744
161804
  return hyperlinkSuccess(candidateToTarget(candidate));
161745
- if (!receiptApplied$8(executeDomainCommand(editor, () => {
161805
+ if (!receiptApplied$7(executeDomainCommand(editor, () => {
161746
161806
  const result = patchLinkMark(editor, resolvedRange.from, resolvedRange.to, existingMark, input2.patch);
161747
161807
  if (result)
161748
161808
  clearIndexCache(editor);
@@ -161761,7 +161821,7 @@ function hyperlinksRemoveWrapper(editor, input2, options) {
161761
161821
  const targetAddress = candidateToTarget(candidate);
161762
161822
  if (options?.dryRun)
161763
161823
  return hyperlinkSuccess(targetAddress);
161764
- if (!receiptApplied$8(executeDomainCommand(editor, () => {
161824
+ if (!receiptApplied$7(executeDomainCommand(editor, () => {
161765
161825
  const result = mode === "unwrap" ? unwrapLink(editor, resolvedRange.from, resolvedRange.to) : deleteLinkedText(editor, resolvedRange.from, resolvedRange.to);
161766
161826
  if (result)
161767
161827
  clearIndexCache(editor);
@@ -163059,7 +163119,7 @@ function buildSectionMarginsForAttrs(sectPr) {
163059
163119
  };
163060
163120
  }
163061
163121
  function syncConverterBodySection(editor, sectPr) {
163062
- const converter = getConverter$12(editor);
163122
+ const converter = getConverter$3(editor);
163063
163123
  if (!converter)
163064
163124
  return;
163065
163125
  converter.bodySectPr = cloneXmlElement(sectPr);
@@ -163097,7 +163157,7 @@ function syncConverterBodySection(editor, sectPr) {
163097
163157
  if (margins.gutter !== undefined)
163098
163158
  pageMargins.gutter = margins.gutter;
163099
163159
  }
163100
- function getConverter$12(editor) {
163160
+ function getConverter$3(editor) {
163101
163161
  return editor.converter;
163102
163162
  }
163103
163163
  function applySectPrToProjection(editor, projection, sectPr) {
@@ -163147,11 +163207,11 @@ function sectionMutationBySectPr(editor, input2, options, operationName, mutate)
163147
163207
  clearIndexCache(editor);
163148
163208
  return toSectionSuccess(projection.address);
163149
163209
  }
163150
- function getConverter2(editor) {
163210
+ function getConverter$2(editor) {
163151
163211
  return editor.converter;
163152
163212
  }
163153
163213
  function requireConverter(editor, operationName) {
163154
- const converter = getConverter2(editor);
163214
+ const converter = getConverter$2(editor);
163155
163215
  if (!converter)
163156
163216
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `${operationName} requires an active document converter.`);
163157
163217
  return converter;
@@ -163250,14 +163310,14 @@ function headerFootersResolveAdapter(editor, input2) {
163250
163310
  function headerFootersRefsSetAdapter(editor, input2, options) {
163251
163311
  const { section, headerFooterKind, variant } = input2.target;
163252
163312
  return sectionMutationBySectPr(editor, { target: section }, options, "headerFooters.refs.set", (sectPr, _projection, _sections, dryRun) => {
163253
- const converter = getConverter2(editor) ?? null;
163313
+ const converter = getConverter$2(editor) ?? null;
163254
163314
  return setHeaderFooterRefMutation(sectPr, headerFooterKind, variant, input2.refId, converter, "headerFooters.refs.set", dryRun);
163255
163315
  });
163256
163316
  }
163257
163317
  function headerFootersRefsClearAdapter(editor, input2, options) {
163258
163318
  const { section, headerFooterKind, variant } = input2.target;
163259
163319
  return sectionMutationBySectPr(editor, { target: section }, options, "headerFooters.refs.clear", (sectPr, _projection, _sections, dryRun) => {
163260
- clearHeaderFooterRefMutation(sectPr, headerFooterKind, variant, getConverter2(editor) ?? null, dryRun);
163320
+ clearHeaderFooterRefMutation(sectPr, headerFooterKind, variant, getConverter$2(editor) ?? null, dryRun);
163261
163321
  });
163262
163322
  }
163263
163323
  function headerFootersRefsSetLinkedToPreviousAdapter(editor, input2, options) {
@@ -163611,7 +163671,7 @@ function bookmarkFailure(code$1, message) {
163611
163671
  }
163612
163672
  };
163613
163673
  }
163614
- function receiptApplied$7(receipt2) {
163674
+ function receiptApplied$6(receipt2) {
163615
163675
  return receipt2.steps[0]?.effect === "changed";
163616
163676
  }
163617
163677
  function parseBookmarkId(raw) {
@@ -163671,7 +163731,7 @@ function bookmarksInsertWrapper(editor, input2, options) {
163671
163731
  if (!bookmarkStartType || !bookmarkEndType)
163672
163732
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "bookmarks.insert requires bookmarkStart and bookmarkEnd node types in the schema.");
163673
163733
  const resolved = resolveInlineInsertPosition(editor, input2.at, "bookmarks.insert");
163674
- if (!receiptApplied$7(executeDomainCommand(editor, () => {
163734
+ if (!receiptApplied$6(executeDomainCommand(editor, () => {
163675
163735
  const bookmarkId = allocateBookmarkId(editor.state.doc);
163676
163736
  const startAttrs = {
163677
163737
  name: input2.name,
@@ -163707,7 +163767,7 @@ function bookmarksRenameWrapper(editor, input2, options) {
163707
163767
  };
163708
163768
  if (options?.dryRun)
163709
163769
  return bookmarkSuccess(newAddress);
163710
- if (!receiptApplied$7(executeDomainCommand(editor, () => {
163770
+ if (!receiptApplied$6(executeDomainCommand(editor, () => {
163711
163771
  const { tr } = editor.state;
163712
163772
  tr.setNodeMarkup(resolved.pos, undefined, {
163713
163773
  ...resolved.node.attrs,
@@ -163730,7 +163790,7 @@ function bookmarksRemoveWrapper(editor, input2, options) {
163730
163790
  };
163731
163791
  if (options?.dryRun)
163732
163792
  return bookmarkSuccess(address2);
163733
- if (!receiptApplied$7(executeDomainCommand(editor, () => {
163793
+ if (!receiptApplied$6(executeDomainCommand(editor, () => {
163734
163794
  const { tr } = editor.state;
163735
163795
  if (resolved.endPos !== null && resolved.endPos > resolved.pos) {
163736
163796
  const endNode = tr.doc.nodeAt(resolved.endPos);
@@ -163747,6 +163807,22 @@ function bookmarksRemoveWrapper(editor, input2, options) {
163747
163807
  return bookmarkFailure("NO_OP", "Remove operation produced no change.");
163748
163808
  return bookmarkSuccess(address2);
163749
163809
  }
163810
+ function isSpecialEntry(entry) {
163811
+ return SPECIAL_NOTE_TYPES.has(entry.type ?? "");
163812
+ }
163813
+ function findNoteEntryById(entries, noteId) {
163814
+ if (!Array.isArray(entries))
163815
+ return;
163816
+ let fallback;
163817
+ for (const entry of entries) {
163818
+ if (String(entry.id ?? "") !== noteId)
163819
+ continue;
163820
+ if (!isSpecialEntry(entry))
163821
+ return entry;
163822
+ fallback ??= entry;
163823
+ }
163824
+ return fallback;
163825
+ }
163750
163826
  function getConverterStore(editor) {
163751
163827
  return editor.converter ?? {};
163752
163828
  }
@@ -163779,7 +163855,7 @@ function resolveCollectionContent(collection, noteId) {
163779
163855
  if (!collection)
163780
163856
  return "";
163781
163857
  if (Array.isArray(collection))
163782
- return extractTextFromContent(collection.find((entry) => String(entry?.id ?? "") === noteId)?.content);
163858
+ return extractTextFromContent(findNoteEntryById(collection, noteId)?.content);
163783
163859
  if (isLegacyFootnoteMap(collection))
163784
163860
  return collection[noteId]?.content ?? "";
163785
163861
  return "";
@@ -163857,28 +163933,221 @@ function buildFootnoteDiscoveryItem(editor, resolved, evaluatedRevision) {
163857
163933
  const handle3 = buildResolvedHandle2(resolved.noteId, "stable", "node");
163858
163934
  return buildDiscoveryItem2(`footnote:${resolved.noteId}:${evaluatedRevision}`, handle3, domain2);
163859
163935
  }
163860
- function executeOutOfBandMutation(editor, mutateFn, options) {
163861
- if (!options.dryRun)
163862
- if (editor.options?.collaborationProvider && editor.options?.ydoc)
163863
- try {
163864
- yUndoPluginKey.getState(editor.state)?.undoManager?.stopCapturing();
163865
- } catch {}
163866
- else
163867
- try {
163868
- editor.view?.dispatch?.(closeHistory(editor.state.tr));
163869
- } catch {}
163870
- checkRevision(editor, options.expectedRevision);
163871
- const result = mutateFn(options.dryRun);
163872
- if (result.changed && !options.dryRun) {
163873
- const converter = editor.converter;
163874
- if (converter) {
163875
- converter.documentModified = true;
163876
- if (!converter.documentGuid && typeof converter.promoteToGuid === "function")
163877
- converter.promoteToGuid();
163936
+ function getConverter$13(editor) {
163937
+ return editor.converter;
163938
+ }
163939
+ function getRootElement(part) {
163940
+ return part?.elements?.[0];
163941
+ }
163942
+ function getNoteElements(part, childElementName) {
163943
+ const root3 = getRootElement(part);
163944
+ if (!root3?.elements)
163945
+ return [];
163946
+ return root3.elements.filter((el) => el.name === childElementName);
163947
+ }
163948
+ function textToNoteOoxmlParagraphs(text5) {
163949
+ return text5.split(/\r?\n/).map((line) => ({
163950
+ type: "element",
163951
+ name: "w:p",
163952
+ elements: line.length > 0 ? [{
163953
+ type: "element",
163954
+ name: "w:r",
163955
+ elements: [{
163956
+ type: "element",
163957
+ name: "w:t",
163958
+ attributes: { "xml:space": "preserve" },
163959
+ elements: [{
163960
+ type: "text",
163961
+ text: line
163962
+ }]
163963
+ }]
163964
+ }] : []
163965
+ }));
163966
+ }
163967
+ function ensureFootnoteRefRun(paragraphs, childElementName) {
163968
+ if (paragraphs.length === 0)
163969
+ return;
163970
+ const refName = childElementName === "w:footnote" ? "w:footnoteRef" : "w:endnoteRef";
163971
+ const styleName = childElementName === "w:footnote" ? "FootnoteReference" : "EndnoteReference";
163972
+ const firstParagraph = paragraphs[0];
163973
+ if (!firstParagraph.elements)
163974
+ firstParagraph.elements = [];
163975
+ const refRun = {
163976
+ type: "element",
163977
+ name: "w:r",
163978
+ elements: [{
163979
+ type: "element",
163980
+ name: "w:rPr",
163981
+ elements: [{
163982
+ type: "element",
163983
+ name: "w:rStyle",
163984
+ attributes: { "w:val": styleName }
163985
+ }, {
163986
+ type: "element",
163987
+ name: "w:vertAlign",
163988
+ attributes: { "w:val": "superscript" }
163989
+ }]
163990
+ }, {
163991
+ type: "element",
163992
+ name: refName,
163993
+ elements: []
163994
+ }]
163995
+ };
163996
+ const pPrIndex = firstParagraph.elements.findIndex((el) => el?.name === "w:pPr");
163997
+ firstParagraph.elements.splice(pPrIndex >= 0 ? pPrIndex + 1 : 0, 0, refRun);
163998
+ }
163999
+ function addNoteElement(part, config2, noteId, text5) {
164000
+ const root3 = getRootElement(part);
164001
+ if (!root3)
164002
+ throw new Error(`addNoteElement: missing root element in ${config2.partId}`);
164003
+ if (!root3.elements)
164004
+ root3.elements = [];
164005
+ if (root3.elements.find((el) => el.name === config2.childElementName && el.attributes?.["w:id"] === noteId))
164006
+ throw new Error(`addNoteElement: note id "${noteId}" already exists in ${config2.partId}`);
164007
+ const paragraphs = textToNoteOoxmlParagraphs(text5);
164008
+ ensureFootnoteRefRun(paragraphs, config2.childElementName);
164009
+ const noteElement = {
164010
+ type: "element",
164011
+ name: config2.childElementName,
164012
+ attributes: { "w:id": noteId },
164013
+ elements: paragraphs
164014
+ };
164015
+ root3.elements.push(noteElement);
164016
+ return noteElement;
164017
+ }
164018
+ function updateNoteElement(part, config2, noteId, text5) {
164019
+ const target = getNoteElements(part, config2.childElementName).find((el) => el.attributes?.["w:id"] === noteId);
164020
+ if (!target)
164021
+ return false;
164022
+ const paragraphs = textToNoteOoxmlParagraphs(text5);
164023
+ ensureFootnoteRefRun(paragraphs, config2.childElementName);
164024
+ target.elements = paragraphs;
164025
+ return true;
164026
+ }
164027
+ function removeNoteElement(part, config2, noteId) {
164028
+ const root3 = getRootElement(part);
164029
+ if (!root3?.elements)
164030
+ return false;
164031
+ const index2 = root3.elements.findIndex((el) => el.name === config2.childElementName && el.attributes?.["w:id"] === noteId);
164032
+ if (index2 < 0)
164033
+ return false;
164034
+ root3.elements.splice(index2, 1);
164035
+ return true;
164036
+ }
164037
+ function rebuildDerivedCache(editor, config2, part) {
164038
+ const converter = getConverter$13(editor);
164039
+ if (!converter)
164040
+ return;
164041
+ if (typeof converter.reimportNotePart === "function")
164042
+ try {
164043
+ converter[config2.converterKey] = converter.reimportNotePart(config2.partId);
164044
+ return;
164045
+ } catch (err) {
164046
+ console.warn(`[parts] reimportNotePart failed for ${config2.partId}, using fallback:`, err);
163878
164047
  }
163879
- incrementRevision(editor);
163880
- }
163881
- return result.payload;
164048
+ const entries = getNoteElements(part, config2.childElementName).map((el) => ({
164049
+ id: String(el.attributes?.["w:id"] ?? ""),
164050
+ type: el.attributes?.["w:type"] ?? null,
164051
+ content: [],
164052
+ originalXml: structuredClone(el)
164053
+ }));
164054
+ converter[config2.converterKey] = entries;
164055
+ }
164056
+ function createInitialNotesPart(config2) {
164057
+ return {
164058
+ declaration: { attributes: {
164059
+ version: "1.0",
164060
+ encoding: "UTF-8",
164061
+ standalone: "yes"
164062
+ } },
164063
+ elements: [{
164064
+ type: "element",
164065
+ name: config2.rootElementName,
164066
+ attributes: { ...NOTES_XMLNS },
164067
+ elements: [{
164068
+ type: "element",
164069
+ name: config2.childElementName,
164070
+ attributes: {
164071
+ "w:type": "separator",
164072
+ "w:id": "-1"
164073
+ },
164074
+ elements: [{
164075
+ type: "element",
164076
+ name: "w:p",
164077
+ elements: [{
164078
+ type: "element",
164079
+ name: "w:r",
164080
+ elements: [{
164081
+ type: "element",
164082
+ name: "w:separator",
164083
+ elements: []
164084
+ }]
164085
+ }]
164086
+ }]
164087
+ }, {
164088
+ type: "element",
164089
+ name: config2.childElementName,
164090
+ attributes: {
164091
+ "w:type": "continuationSeparator",
164092
+ "w:id": "0"
164093
+ },
164094
+ elements: [{
164095
+ type: "element",
164096
+ name: "w:p",
164097
+ elements: [{
164098
+ type: "element",
164099
+ name: "w:r",
164100
+ elements: [{
164101
+ type: "element",
164102
+ name: "w:continuationSeparator",
164103
+ elements: []
164104
+ }]
164105
+ }]
164106
+ }]
164107
+ }]
164108
+ }]
164109
+ };
164110
+ }
164111
+ function createNotePartDescriptor(config2) {
164112
+ return {
164113
+ id: config2.partId,
164114
+ ensurePart() {
164115
+ return createInitialNotesPart(config2);
164116
+ },
164117
+ normalizePart(part) {
164118
+ const root3 = getRootElement(part);
164119
+ if (!root3?.elements)
164120
+ return;
164121
+ root3.elements.sort((a2, b$1) => {
164122
+ const aType = a2.attributes?.["w:type"];
164123
+ const bType = b$1.attributes?.["w:type"];
164124
+ const aIsSpecial = aType === "separator" || aType === "continuationSeparator";
164125
+ if (aIsSpecial !== (bType === "separator" || bType === "continuationSeparator"))
164126
+ return aIsSpecial ? -1 : 1;
164127
+ return Number(a2.attributes?.["w:id"] ?? 0) - Number(b$1.attributes?.["w:id"] ?? 0);
164128
+ });
164129
+ },
164130
+ afterCommit({ editor, part, source }) {
164131
+ rebuildDerivedCache(editor, config2, part);
164132
+ clearPartCacheStale(editor, config2.partId);
164133
+ editor.emit("notes-part-changed", {
164134
+ partId: config2.partId,
164135
+ source
164136
+ });
164137
+ }
164138
+ };
164139
+ }
164140
+ function getNotesConfig(type) {
164141
+ return type === "endnote" ? ENDNOTES_CONFIG : FOOTNOTES_CONFIG;
164142
+ }
164143
+ function bootstrapNotesPart(editor, type) {
164144
+ const converter = editor.converter;
164145
+ if (!converter?.convertedXml)
164146
+ return;
164147
+ const config2 = getNotesConfig(type);
164148
+ if (converter.convertedXml[config2.partId] !== undefined)
164149
+ return;
164150
+ converter.convertedXml[config2.partId] = createInitialNotesPart(config2);
163882
164151
  }
163883
164152
  function footnoteSuccess(address2) {
163884
164153
  return {
@@ -163898,39 +164167,11 @@ function footnoteFailure(code$1, message) {
163898
164167
  function configSuccess$1() {
163899
164168
  return { success: true };
163900
164169
  }
163901
- function receiptApplied$6(receipt2) {
163902
- return receipt2.steps[0]?.effect === "changed";
163903
- }
163904
- function isLegacyNoteMap(value) {
163905
- return value != null && typeof value === "object" && !Array.isArray(value);
163906
- }
163907
- function textToFootnoteContentNodes(text5) {
163908
- return text5.split(/\r?\n/).map((line) => ({
163909
- type: "paragraph",
163910
- content: line.length > 0 ? [{
163911
- type: "text",
163912
- text: line
163913
- }] : []
163914
- }));
163915
- }
163916
- function normalizeLegacyNoteMap(map$12) {
163917
- return Object.entries(map$12).map(([id2, value]) => ({
163918
- id: String(id2),
163919
- content: textToFootnoteContentNodes(value?.content ?? "")
163920
- }));
163921
- }
163922
- function ensureNoteEntries(converter, kind) {
163923
- const current = converter[kind];
163924
- if (Array.isArray(current))
163925
- return current;
163926
- if (isLegacyNoteMap(current)) {
163927
- const normalized = normalizeLegacyNoteMap(current);
163928
- converter[kind] = normalized;
163929
- return normalized;
163930
- }
163931
- const initialized = [];
163932
- converter[kind] = initialized;
163933
- return initialized;
164170
+ function getConverter2(editor) {
164171
+ const converter = editor.converter;
164172
+ if (!converter)
164173
+ throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "converter not available.");
164174
+ return converter;
163934
164175
  }
163935
164176
  function toNonNegativeInteger(value) {
163936
164177
  const num = Number(value);
@@ -163938,35 +164179,36 @@ function toNonNegativeInteger(value) {
163938
164179
  return null;
163939
164180
  return num;
163940
164181
  }
163941
- function allocateNextNoteId(editor, type, entries) {
163942
- let maxId = 0;
164182
+ function collectUsedNoteIds(editor, converter, type) {
164183
+ const used = /* @__PURE__ */ new Set;
164184
+ const config2 = getNotesConfig(type);
163943
164185
  for (const ref$1 of findAllFootnotes(editor.state.doc, type)) {
163944
164186
  const parsed = toNonNegativeInteger(ref$1.noteId);
163945
164187
  if (parsed != null)
163946
- maxId = Math.max(maxId, parsed);
163947
- }
163948
- for (const entry of entries) {
163949
- const parsed = toNonNegativeInteger(entry.id);
163950
- if (parsed != null)
163951
- maxId = Math.max(maxId, parsed);
163952
- }
163953
- return String(maxId + 1);
163954
- }
163955
- function upsertNoteEntry(entries, noteId, content3) {
163956
- const existing = entries.find((entry) => String(entry.id) === noteId);
163957
- if (existing) {
163958
- existing.content = textToFootnoteContentNodes(content3);
163959
- return;
163960
- }
163961
- entries.push({
163962
- id: noteId,
163963
- content: textToFootnoteContentNodes(content3)
163964
- });
163965
- }
163966
- function removeNoteEntry(entries, noteId) {
163967
- const index2 = entries.findIndex((entry) => String(entry.id) === noteId);
163968
- if (index2 >= 0)
163969
- entries.splice(index2, 1);
164188
+ used.add(parsed);
164189
+ }
164190
+ const ooxmlPart = converter.convertedXml?.[config2.partId];
164191
+ if (ooxmlPart)
164192
+ for (const el of getNoteElements(ooxmlPart, config2.childElementName)) {
164193
+ const parsed = toNonNegativeInteger(el.attributes?.["w:id"]);
164194
+ if (parsed != null)
164195
+ used.add(parsed);
164196
+ }
164197
+ const cache$2 = converter[config2.converterKey];
164198
+ if (Array.isArray(cache$2))
164199
+ for (const entry of cache$2) {
164200
+ const parsed = toNonNegativeInteger(entry.id);
164201
+ if (parsed != null)
164202
+ used.add(parsed);
164203
+ }
164204
+ return used;
164205
+ }
164206
+ function allocateNextNoteId(editor, converter, type) {
164207
+ const used = collectUsedNoteIds(editor, converter, type);
164208
+ let candidate = 1;
164209
+ while (used.has(candidate))
164210
+ candidate += 1;
164211
+ return String(candidate);
163970
164212
  }
163971
164213
  function footnotesListWrapper(editor, query2) {
163972
164214
  const doc$2 = editor.state.doc;
@@ -163988,11 +164230,10 @@ function footnotesGetWrapper(editor, input2) {
163988
164230
  }
163989
164231
  function footnotesInsertWrapper(editor, input2, options) {
163990
164232
  rejectTrackedMode("footnotes.insert", options);
163991
- const converter = editor.converter;
163992
- if (!converter)
163993
- throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "footnotes.insert: converter not available.");
163994
- const noteEntries = ensureNoteEntries(converter, input2.type === "endnote" ? "endnotes" : "footnotes");
163995
- const noteId = allocateNextNoteId(editor, input2.type, noteEntries);
164233
+ checkRevision(editor, options?.expectedRevision);
164234
+ const converter = getConverter2(editor);
164235
+ const notesConfig = getNotesConfig(input2.type);
164236
+ const noteId = allocateNextNoteId(editor, converter, input2.type);
163996
164237
  const address2 = {
163997
164238
  kind: "entity",
163998
164239
  entityType: "footnote",
@@ -164005,15 +164246,30 @@ function footnotesInsertWrapper(editor, input2, options) {
164005
164246
  if (!nodeType)
164006
164247
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `footnotes.insert: node type "${nodeTypeName}" is not registered in the schema.`);
164007
164248
  const resolved = resolveInlineInsertPosition(editor, input2.at, "footnotes.insert");
164008
- if (!receiptApplied$6(executeDomainCommand(editor, () => {
164009
- const node3 = nodeType.create({ id: noteId });
164010
- const { tr } = editor.state;
164011
- tr.insert(resolved.from, node3);
164012
- editor.dispatch(tr);
164013
- upsertNoteEntry(noteEntries, noteId, input2.content);
164014
- clearIndexCache(editor);
164015
- return true;
164016
- }, { expectedRevision: options?.expectedRevision })))
164249
+ const { success } = compoundMutation({
164250
+ editor,
164251
+ source: `footnotes.insert:${input2.type}`,
164252
+ affectedParts: [notesConfig.partId],
164253
+ execute: () => {
164254
+ bootstrapNotesPart(editor, input2.type);
164255
+ mutatePart({
164256
+ editor,
164257
+ partId: notesConfig.partId,
164258
+ operation: "mutate",
164259
+ source: `footnotes.insert:${input2.type}`,
164260
+ mutate({ part }) {
164261
+ addNoteElement(part, notesConfig, noteId, input2.content);
164262
+ }
164263
+ });
164264
+ const node3 = nodeType.create({ id: noteId });
164265
+ const { tr } = editor.state;
164266
+ tr.insert(resolved.from, node3);
164267
+ editor.dispatch(tr);
164268
+ clearIndexCache(editor);
164269
+ return true;
164270
+ }
164271
+ });
164272
+ if (!success)
164017
164273
  return footnoteFailure("NO_OP", "Insert operation produced no change.");
164018
164274
  return footnoteSuccess(address2);
164019
164275
  }
@@ -164025,32 +164281,24 @@ function footnotesUpdateWrapper(editor, input2, options) {
164025
164281
  entityType: "footnote",
164026
164282
  noteId: resolved.noteId
164027
164283
  };
164028
- if (options?.dryRun)
164284
+ if (options?.dryRun || input2.patch.content === undefined)
164029
164285
  return footnoteSuccess(address2);
164030
- const converter = editor.converter;
164031
- if (!converter)
164032
- throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "footnotes.update: converter not available.");
164033
- const noteEntries = ensureNoteEntries(converter, resolved.type === "footnote" ? "footnotes" : "endnotes");
164034
- executeOutOfBandMutation(editor, (dryRun) => {
164035
- if (input2.patch.content === undefined)
164036
- return {
164037
- changed: false,
164038
- payload: undefined
164039
- };
164040
- if (!dryRun)
164041
- upsertNoteEntry(noteEntries, resolved.noteId, input2.patch.content);
164042
- return {
164043
- changed: true,
164044
- payload: undefined
164045
- };
164046
- }, {
164047
- dryRun: options?.dryRun ?? false,
164048
- expectedRevision: options?.expectedRevision
164286
+ const notesConfig = getNotesConfig(resolved.type);
164287
+ mutatePart({
164288
+ editor,
164289
+ partId: notesConfig.partId,
164290
+ operation: "mutate",
164291
+ source: `footnotes.update:${resolved.type}`,
164292
+ expectedRevision: options?.expectedRevision,
164293
+ mutate({ part }) {
164294
+ updateNoteElement(part, notesConfig, resolved.noteId, input2.patch.content);
164295
+ }
164049
164296
  });
164050
164297
  return footnoteSuccess(address2);
164051
164298
  }
164052
164299
  function footnotesRemoveWrapper(editor, input2, options) {
164053
164300
  rejectTrackedMode("footnotes.remove", options);
164301
+ checkRevision(editor, options?.expectedRevision);
164054
164302
  const resolved = resolveFootnoteTarget(editor.state.doc, input2.target);
164055
164303
  const address2 = {
164056
164304
  kind: "entity",
@@ -164059,63 +164307,102 @@ function footnotesRemoveWrapper(editor, input2, options) {
164059
164307
  };
164060
164308
  if (options?.dryRun)
164061
164309
  return footnoteSuccess(address2);
164062
- if (!receiptApplied$6(executeDomainCommand(editor, () => {
164063
- const { tr } = editor.state;
164064
- const node3 = tr.doc.nodeAt(resolved.pos);
164065
- if (node3) {
164310
+ const notesConfig = getNotesConfig(resolved.type);
164311
+ const { success } = compoundMutation({
164312
+ editor,
164313
+ source: `footnotes.remove:${resolved.type}`,
164314
+ affectedParts: [notesConfig.partId],
164315
+ execute: () => {
164316
+ const { tr } = editor.state;
164317
+ const node3 = tr.doc.nodeAt(resolved.pos);
164318
+ if (!node3)
164319
+ return false;
164066
164320
  tr.delete(resolved.pos, resolved.pos + node3.nodeSize);
164067
164321
  editor.dispatch(tr);
164068
- const converter = editor.converter;
164069
- if (converter) {
164070
- const noteEntries = ensureNoteEntries(converter, resolved.type === "footnote" ? "footnotes" : "endnotes");
164071
- if (!findAllFootnotes(editor.state.doc, resolved.type).some((f2) => f2.noteId === resolved.noteId))
164072
- removeNoteEntry(noteEntries, resolved.noteId);
164073
- }
164322
+ if (!findAllFootnotes(editor.state.doc, resolved.type).some((f2) => f2.noteId === resolved.noteId))
164323
+ mutatePart({
164324
+ editor,
164325
+ partId: notesConfig.partId,
164326
+ operation: "mutate",
164327
+ source: `footnotes.remove:${resolved.type}`,
164328
+ mutate({ part }) {
164329
+ removeNoteElement(part, notesConfig, resolved.noteId);
164330
+ }
164331
+ });
164074
164332
  clearIndexCache(editor);
164075
164333
  return true;
164076
164334
  }
164077
- return false;
164078
- }, { expectedRevision: options?.expectedRevision })))
164335
+ });
164336
+ if (!success)
164079
164337
  return footnoteFailure("NO_OP", "Remove operation produced no change.");
164080
164338
  return footnoteSuccess(address2);
164081
164339
  }
164082
164340
  function footnotesConfigureWrapper(editor, input2, options) {
164083
164341
  rejectTrackedMode("footnotes.configure", options);
164084
- const converter = editor.converter;
164085
- if (!converter)
164086
- throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", "footnotes.configure: converter not available.");
164087
- executeOutOfBandMutation(editor, (dryRun) => {
164088
- if (dryRun)
164089
- return {
164090
- changed: true,
164091
- payload: undefined
164092
- };
164093
- if (!converter.footnoteProperties)
164094
- converter.footnoteProperties = { source: "settings" };
164095
- const props = converter.footnoteProperties;
164096
- if (input2.numbering) {
164097
- if (input2.numbering.format !== undefined)
164098
- props.numFmt = input2.numbering.format;
164099
- if (input2.numbering.start !== undefined)
164100
- props.numStart = String(input2.numbering.start);
164342
+ const prElementName = input2.type === "endnote" ? "w:endnotePr" : "w:footnotePr";
164343
+ mutatePart({
164344
+ editor,
164345
+ partId: "word/settings.xml",
164346
+ operation: "mutate",
164347
+ source: `footnotes.configure:${input2.type}`,
164348
+ dryRun: options?.dryRun,
164349
+ expectedRevision: options?.expectedRevision,
164350
+ mutate({ part }) {
164351
+ const root3 = part?.elements?.[0];
164352
+ if (!root3)
164353
+ return;
164354
+ if (!root3.elements)
164355
+ root3.elements = [];
164356
+ const elements = root3.elements;
164357
+ let prElement = elements.find((el) => el.name === prElementName);
164358
+ if (!prElement) {
164359
+ prElement = {
164360
+ type: "element",
164361
+ name: prElementName,
164362
+ elements: []
164363
+ };
164364
+ elements.push(prElement);
164365
+ }
164366
+ if (!prElement.elements)
164367
+ prElement.elements = [];
164368
+ if (!input2.numbering)
164369
+ return;
164370
+ const setOrRemoveChild = (name, value) => {
164371
+ if (value === undefined)
164372
+ return;
164373
+ const children = prElement.elements;
164374
+ const existing = children.findIndex((el) => el.name === name);
164375
+ const newEl = {
164376
+ type: "element",
164377
+ name,
164378
+ attributes: { "w:val": value }
164379
+ };
164380
+ if (existing >= 0)
164381
+ children[existing] = newEl;
164382
+ else
164383
+ children.push(newEl);
164384
+ };
164385
+ setOrRemoveChild("w:numFmt", input2.numbering.format);
164386
+ setOrRemoveChild("w:numStart", input2.numbering.start !== undefined ? String(input2.numbering.start) : undefined);
164101
164387
  if (input2.numbering.restartPolicy !== undefined)
164102
- props.numRestart = RESTART_POLICY_TO_OOXML[input2.numbering.restartPolicy] ?? input2.numbering.restartPolicy;
164103
- if (input2.numbering.position !== undefined)
164104
- props.pos = input2.numbering.position;
164388
+ setOrRemoveChild("w:numRestart", RESTART_POLICY_TO_OOXML[input2.numbering.restartPolicy] ?? input2.numbering.restartPolicy);
164389
+ setOrRemoveChild("w:pos", input2.numbering.position);
164105
164390
  }
164106
- props.noteType = input2.type;
164107
- if (input2.scope)
164108
- props.scope = input2.scope;
164109
- return {
164110
- changed: true,
164111
- payload: undefined
164112
- };
164113
- }, {
164114
- dryRun: options?.dryRun ?? false,
164115
- expectedRevision: options?.expectedRevision
164116
164391
  });
164392
+ if (!options?.dryRun && prElementName === "w:footnotePr")
164393
+ syncFootnotePropertiesCache(editor);
164117
164394
  return configSuccess$1();
164118
164395
  }
164396
+ function syncFootnotePropertiesCache(editor) {
164397
+ const converter = getConverter2(editor);
164398
+ if (!converter?.footnoteProperties || converter.footnoteProperties.source !== "settings")
164399
+ return;
164400
+ const prElement = (converter.convertedXml?.["word/settings.xml"]?.elements?.[0]?.elements ?? []).find((el) => el.name === "w:footnotePr");
164401
+ if (prElement)
164402
+ converter.footnoteProperties.originalXml = structuredClone(prElement);
164403
+ else
164404
+ converter.footnoteProperties = null;
164405
+ }
164119
164406
  function findAllCrossRefs(doc$2) {
164120
164407
  const results = [];
164121
164408
  doc$2.descendants((node3, pos) => {
@@ -165662,6 +165949,29 @@ function buildCitationAddress(doc$2, resolved) {
165662
165949
  }
165663
165950
  };
165664
165951
  }
165952
+ function executeOutOfBandMutation(editor, mutateFn, options) {
165953
+ if (!options.dryRun)
165954
+ if (editor.options?.collaborationProvider && editor.options?.ydoc)
165955
+ try {
165956
+ yUndoPluginKey.getState(editor.state)?.undoManager?.stopCapturing();
165957
+ } catch {}
165958
+ else
165959
+ try {
165960
+ editor.view?.dispatch?.(closeHistory(editor.state.tr));
165961
+ } catch {}
165962
+ checkRevision(editor, options.expectedRevision);
165963
+ const result = mutateFn(options.dryRun);
165964
+ if (result.changed && !options.dryRun) {
165965
+ const converter = editor.converter;
165966
+ if (converter) {
165967
+ converter.documentModified = true;
165968
+ if (!converter.documentGuid && typeof converter.promoteToGuid === "function")
165969
+ converter.promoteToGuid();
165970
+ }
165971
+ incrementRevision(editor);
165972
+ }
165973
+ return result.payload;
165974
+ }
165665
165975
  function citationSuccess(address2) {
165666
165976
  return {
165667
165977
  success: true,
@@ -166943,6 +167253,8 @@ function initPartsRuntime(editor) {
166943
167253
  registerPartDescriptor(relsPartDescriptor);
166944
167254
  registerPartDescriptor(numberingPartDescriptor);
166945
167255
  registerPartDescriptor(contentTypesPartDescriptor);
167256
+ registerPartDescriptor(footnotesPartDescriptor);
167257
+ registerPartDescriptor(endnotesPartDescriptor);
166946
167258
  registerStaticInvalidationHandlers();
166947
167259
  initRevision(editor);
166948
167260
  trackRevisions(editor);
@@ -169616,76 +169928,86 @@ function applyAlphaToSVG$1(svg2, alphaData) {
169616
169928
  function generateGradientId(prefix2 = "gradient") {
169617
169929
  return `${prefix2}-${Date.now()}-${gradientIdCounter++}-${Math.random().toString(36).substring(2, 11)}`;
169618
169930
  }
169619
- function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
169931
+ function resolveListMarkerGeometry(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
169620
169932
  const marker = wordLayout?.marker;
169621
169933
  if (!marker)
169622
- return wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : undefined;
169623
- const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
169624
- let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : undefined;
169625
- if (markerTextWidth == null && marker.markerText)
169626
- markerTextWidth = measureMarkerText(marker.markerText, marker);
169627
- if (!Number.isFinite(markerTextWidth) || markerTextWidth !== undefined && markerTextWidth < 0)
169628
- markerTextWidth = markerBoxWidth;
169629
- const finalMarkerTextWidth = Math.max(0, markerTextWidth ?? 0);
169630
- let markerStartPos;
169631
- if (wordLayout?.firstLineIndentMode === true && typeof marker.markerX === "number" && Number.isFinite(marker.markerX))
169632
- markerStartPos = marker.markerX;
169633
- else
169634
- markerStartPos = indentLeft - hanging + firstLine;
169635
- if (!Number.isFinite(markerStartPos))
169636
- markerStartPos = 0;
169637
- const currentPos = markerStartPos + finalMarkerTextWidth;
169934
+ return;
169935
+ const markerTextWidthPx = getMarkerTextWidthPx(marker, measureMarkerText);
169936
+ const markerBoxWidthPx = getMarkerBoxWidthPx(marker, markerTextWidthPx);
169937
+ const justification = marker.justification ?? "left";
169938
+ const explicitFirstLineMarkerStartPx = getExplicitFirstLineMarkerStartPx(wordLayout, marker);
169939
+ const anchorPx = getMarkerAnchorPx(indentLeft, firstLine, hanging);
169940
+ const markerStartPx = explicitFirstLineMarkerStartPx ?? getMarkerStartPx(anchorPx, justification, markerTextWidthPx);
169941
+ const markerContentEndPx = markerStartPx + markerTextWidthPx;
169638
169942
  const suffix = marker.suffix ?? "tab";
169639
- if (suffix === "space")
169640
- return markerStartPos + finalMarkerTextWidth + 4;
169641
169943
  if (suffix === "nothing")
169642
- return markerStartPos + finalMarkerTextWidth;
169643
- const markerJustification = marker.justification ?? "left";
169644
- const markerWidthEffective = Math.max(typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0, finalMarkerTextWidth);
169645
- if (markerJustification !== "left") {
169646
- const gutterWidth$1 = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : 8;
169647
- return markerStartPos + finalMarkerTextWidth + Math.max(gutterWidth$1, 8);
169944
+ return {
169945
+ markerStartPx,
169946
+ markerTextWidthPx,
169947
+ textStartPx: markerContentEndPx,
169948
+ suffixWidthPx: 0
169949
+ };
169950
+ if (suffix === "space")
169951
+ return {
169952
+ markerStartPx,
169953
+ markerTextWidthPx,
169954
+ textStartPx: markerContentEndPx + 4,
169955
+ suffixWidthPx: 4
169956
+ };
169957
+ if (justification !== "left") {
169958
+ const gutterWidthPx$1 = Math.max(getNonNegativeFiniteNumber(marker.gutterWidthPx) ?? 0, 8);
169959
+ return {
169960
+ markerStartPx,
169961
+ markerTextWidthPx,
169962
+ textStartPx: markerContentEndPx + gutterWidthPx$1,
169963
+ suffixWidthPx: gutterWidthPx$1
169964
+ };
169648
169965
  }
169649
169966
  if (wordLayout?.firstLineIndentMode === true) {
169650
- let targetTabStop;
169651
- if (Array.isArray(wordLayout.tabsPx)) {
169652
- for (const tab of wordLayout.tabsPx)
169653
- if (typeof tab === "number" && tab > currentPos) {
169654
- targetTabStop = tab;
169655
- break;
169656
- }
169657
- }
169658
- const textStartTarget$1 = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
169659
- let tabWidth$1;
169660
- if (targetTabStop !== undefined)
169661
- tabWidth$1 = targetTabStop - currentPos;
169662
- else if (textStartTarget$1 !== undefined && Number.isFinite(textStartTarget$1) && textStartTarget$1 > currentPos)
169663
- tabWidth$1 = textStartTarget$1 - currentPos;
169967
+ const explicitTabStopPx = getNextExplicitTabStopPx(wordLayout.tabsPx, markerContentEndPx);
169968
+ const textStartTargetPx = getFirstLineTextStartTargetPx(wordLayout, marker);
169969
+ let textStartPx$1;
169970
+ if (explicitTabStopPx != null)
169971
+ textStartPx$1 = explicitTabStopPx;
169972
+ else if (textStartTargetPx != null && textStartTargetPx > markerContentEndPx)
169973
+ textStartPx$1 = textStartTargetPx;
169664
169974
  else
169665
- tabWidth$1 = 8;
169666
- if (tabWidth$1 < 8)
169667
- tabWidth$1 = 8;
169668
- return markerStartPos + finalMarkerTextWidth + tabWidth$1;
169669
- }
169670
- const textStartTarget = typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : undefined;
169671
- const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : 8;
169672
- const currentPosStandard = markerStartPos + markerWidthEffective;
169673
- let explicitTabStop;
169674
- if (Array.isArray(wordLayout?.tabsPx)) {
169675
- for (const tab of wordLayout.tabsPx)
169676
- if (typeof tab === "number" && tab > currentPosStandard) {
169677
- explicitTabStop = tab;
169678
- break;
169679
- }
169975
+ textStartPx$1 = markerContentEndPx + 8;
169976
+ if (textStartPx$1 - markerContentEndPx < 8)
169977
+ textStartPx$1 = markerContentEndPx + 8;
169978
+ return {
169979
+ markerStartPx,
169980
+ markerTextWidthPx,
169981
+ textStartPx: textStartPx$1,
169982
+ suffixWidthPx: textStartPx$1 - markerContentEndPx
169983
+ };
169680
169984
  }
169681
- if (explicitTabStop !== undefined)
169682
- return explicitTabStop;
169683
- if (textStartTarget !== undefined)
169684
- return currentPosStandard + Math.max(textStartTarget - currentPosStandard, gutterWidth);
169685
- let tabWidth = indentLeft + firstLine - currentPosStandard;
169686
- if (tabWidth <= 0)
169687
- tabWidth = currentPosStandard + 48 - currentPosStandard % 48 - currentPosStandard;
169688
- return currentPosStandard + tabWidth;
169985
+ const gutterWidthPx = Math.max(getNonNegativeFiniteNumber(marker.gutterWidthPx) ?? 0, 8);
169986
+ const explicitTextStartPx = resolveExplicitStandardTextStartPx(getFiniteNumber(wordLayout?.textStartPx), markerContentEndPx, gutterWidthPx);
169987
+ if (explicitTextStartPx != null)
169988
+ return {
169989
+ markerStartPx,
169990
+ markerTextWidthPx,
169991
+ textStartPx: explicitTextStartPx,
169992
+ suffixWidthPx: explicitTextStartPx - markerContentEndPx
169993
+ };
169994
+ const markerBoxEndPx = markerStartPx + markerBoxWidthPx;
169995
+ let textStartPx = indentLeft + firstLine;
169996
+ if (textStartPx <= markerBoxEndPx)
169997
+ textStartPx = getNextDefaultTabStopPx(markerBoxEndPx);
169998
+ return {
169999
+ markerStartPx,
170000
+ markerTextWidthPx,
170001
+ textStartPx,
170002
+ suffixWidthPx: textStartPx - markerContentEndPx
170003
+ };
170004
+ }
170005
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
170006
+ const geometry = resolveListMarkerGeometry(wordLayout, indentLeft, firstLine, hanging, measureMarkerText);
170007
+ if (geometry)
170008
+ return geometry.textStartPx;
170009
+ if (wordLayout?.firstLineIndentMode === true)
170010
+ return getFiniteNumber(wordLayout.textStartPx);
169689
170011
  }
169690
170012
  function calculateRotatedBounds(input2) {
169691
170013
  const width = Math.max(0, input2.width);
@@ -175760,7 +176082,14 @@ function computeCellVisibleHeight(cell2, cellFrom, cellTo) {
175760
176082
  return cellVisHeight;
175761
176083
  }
175762
176084
  function renderListMarker(params$1) {
175763
- const { doc: doc$2, lineEl, markerLayout, markerMeasure, indentLeftPx, hangingIndentPx, firstLineIndentPx, tabsPx } = params$1;
176085
+ const { doc: doc$2, lineEl, wordLayout, markerLayout, markerMeasure, indentLeftPx, hangingIndentPx, firstLineIndentPx, tabsPx } = params$1;
176086
+ const markerGeometry = markerLayout?.justification === "left" && wordLayout?.firstLineIndentMode !== true && typeof markerMeasure?.markerTextWidth === "number" && Number.isFinite(markerMeasure.markerTextWidth) && markerMeasure.markerTextWidth >= 0 ? resolvePainterListMarkerGeometry({
176087
+ wordLayout,
176088
+ indentLeftPx,
176089
+ hangingIndentPx,
176090
+ firstLineIndentPx,
176091
+ markerTextWidthPx: markerMeasure?.markerTextWidth
176092
+ }) : undefined;
175764
176093
  const anchorPoint = indentLeftPx - hangingIndentPx + firstLineIndentPx;
175765
176094
  const markerJustification = markerLayout?.justification ?? "left";
175766
176095
  const markerTextWidth = markerMeasure?.markerTextWidth ?? 0;
@@ -175777,7 +176106,9 @@ function renderListMarker(params$1) {
175777
176106
  }
175778
176107
  const suffix = markerLayout?.suffix ?? "tab";
175779
176108
  let listTabWidth = 0;
175780
- if (suffix === "tab")
176109
+ if (markerGeometry && (suffix === "tab" || suffix === "space"))
176110
+ listTabWidth = markerGeometry.suffixWidthPx;
176111
+ else if (suffix === "tab")
175781
176112
  listTabWidth = computeTabWidth(currentPos, markerJustification, tabsPx, hangingIndentPx, firstLineIndentPx, indentLeftPx);
175782
176113
  else if (suffix === "space")
175783
176114
  listTabWidth = 4;
@@ -176985,6 +177316,10 @@ function computeWordParagraphLayout(input2) {
176985
177316
  }
176986
177317
  layout.marker = {
176987
177318
  markerText: listRenderingAttrs.markerText,
177319
+ markerBoxWidthPx,
177320
+ markerX,
177321
+ textStartX: layout.textStartPx,
177322
+ gutterWidthPx: 8,
176988
177323
  justification: listRenderingAttrs.justification ?? "left",
176989
177324
  suffix: normalizeSuffix(listRenderingAttrs.suffix),
176990
177325
  run: markerRun
@@ -178776,7 +179111,7 @@ function paragraphToFlowBlocks({ para, nextBlockId, positions, trackedChangesCon
178776
179111
  kind: "paragraph",
178777
179112
  id: baseBlockId,
178778
179113
  runs: [emptyRun],
178779
- attrs: deepClone2(paragraphAttrs)
179114
+ attrs: emptyParagraphAttrs
178780
179115
  });
178781
179116
  return blocks2;
178782
179117
  }
@@ -179175,7 +179510,7 @@ function buildFootnotesInput(editorState, converter, converterContext, themeColo
179175
179510
  return null;
179176
179511
  const blocksById = /* @__PURE__ */ new Map;
179177
179512
  idsInUse.forEach((id2) => {
179178
- const content3 = importedFootnotes.find((f2) => String(f2?.id) === id2)?.content;
179513
+ const content3 = findNoteEntryById(importedFootnotes, id2)?.content;
179179
179514
  if (!Array.isArray(content3) || content3.length === 0)
179180
179515
  return;
179181
179516
  try {
@@ -190684,14 +191019,7 @@ var Node$13 = class Node$14 {
190684
191019
  typeOver = true;
190685
191020
  }
190686
191021
  }
190687
- if (added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46)) {
190688
- for (let node3 of added)
190689
- if (node3.nodeName == "BR" && node3.parentNode) {
190690
- let after = node3.nextSibling;
190691
- if (after && after.nodeType == 1 && after.contentEditable == "false")
190692
- node3.parentNode.removeChild(node3);
190693
- }
190694
- } else if (gecko && added.length) {
191022
+ if (gecko && added.length) {
190695
191023
  let brs = added.filter((n) => n.nodeName == "BR");
190696
191024
  if (brs.length == 2) {
190697
191025
  let [a2, b$1] = brs;
@@ -190707,6 +191035,13 @@ var Node$13 = class Node$14 {
190707
191035
  br2.remove();
190708
191036
  }
190709
191037
  }
191038
+ } else if ((chrome || safari) && added.some((n) => n.nodeName == "BR") && (view.input.lastKeyCode == 8 || view.input.lastKeyCode == 46)) {
191039
+ for (let node3 of added)
191040
+ if (node3.nodeName == "BR" && node3.parentNode) {
191041
+ let after = node3.nextSibling;
191042
+ if (after && after.nodeType == 1 && after.contentEditable == "false")
191043
+ node3.parentNode.removeChild(node3);
191044
+ }
190710
191045
  }
190711
191046
  let readSel = null;
190712
191047
  if (from$1 < 0 && newSel && view.input.lastFocus > Date.now() - 200 && Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && selectionCollapsed(sel) && (readSel = selectionFromDOM(view)) && readSel.eq(Selection.near(view.state.doc.resolve(0), 1))) {
@@ -198590,7 +198925,7 @@ var Node$13 = class Node$14 {
198590
198925
  candidate = String(parseInt(hex, 16));
198591
198926
  } while (!candidate || existingIds.has(candidate));
198592
198927
  return candidate;
198593
- }, ALLOWED_WRAP_ATTRS, WRAP_TYPES_SUPPORTING_SIDE, WRAP_TYPES_SUPPORTING_DISTANCES, RELATIVE_HEIGHT_MIN = 0, RELATIVE_HEIGHT_MAX = 4294967295, FORBIDDEN_RAW_PATCH_NAMES, CONTROL_TYPE_SDT_PR_ELEMENTS, DEFAULT_CHECKBOX_SYMBOL_FONT2 = "MS Gothic", DEFAULT_CHECKBOX_CHECKED_HEX2 = "2612", DEFAULT_CHECKBOX_UNCHECKED_HEX2 = "2610", VARIANT_ORDER, KIND_ORDER, HEADER_RELATIONSHIP_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", DOCUMENT_RELS_PATH = "word/_rels/document.xml.rels", HEADER_FILE_PATTERN, FOOTER_FILE_PATTERN, RESTART_POLICY_TO_OOXML, VALID_DISPLAYS, CAPTION_STYLE_NAMES, CAPTION_PARAGRAPH_STYLE_ID = "Caption", CAPTION_FORMAT_TO_OOXML, FIELD_NODE_TYPES, TOA_LEADER_REVERSE_MAP, CONTENT_TYPES_PART_ID = "[Content_Types].xml", CONTENT_TYPES_NS = "http://schemas.openxmlformats.org/package/2006/content-types", contentTypesPartDescriptor, empty_exports, init_empty, PIXELS_PER_INCH$1 = 96, MAX_HEIGHT_BUFFER_PX = 50, MAX_WIDTH_BUFFER_PX = 20, Editor, ContextMenuPluginKey, MENU_OFFSET_X = 0, MENU_OFFSET_Y = 28, CONTEXT_MENU_OFFSET_X = 10, CONTEXT_MENU_OFFSET_Y = 10, SLASH_COOLDOWN_MS = 5000, ContextMenu, SearchQuery = class {
198928
+ }, ALLOWED_WRAP_ATTRS, WRAP_TYPES_SUPPORTING_SIDE, WRAP_TYPES_SUPPORTING_DISTANCES, RELATIVE_HEIGHT_MIN = 0, RELATIVE_HEIGHT_MAX = 4294967295, FORBIDDEN_RAW_PATCH_NAMES, CONTROL_TYPE_SDT_PR_ELEMENTS, DEFAULT_CHECKBOX_SYMBOL_FONT2 = "MS Gothic", DEFAULT_CHECKBOX_CHECKED_HEX2 = "2612", DEFAULT_CHECKBOX_UNCHECKED_HEX2 = "2610", VARIANT_ORDER, KIND_ORDER, HEADER_RELATIONSHIP_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", DOCUMENT_RELS_PATH = "word/_rels/document.xml.rels", HEADER_FILE_PATTERN, FOOTER_FILE_PATTERN, SPECIAL_NOTE_TYPES, FOOTNOTES_PART_ID = "word/footnotes.xml", ENDNOTES_PART_ID = "word/endnotes.xml", FOOTNOTES_CONFIG, ENDNOTES_CONFIG, NOTES_XMLNS, footnotesPartDescriptor, endnotesPartDescriptor, RESTART_POLICY_TO_OOXML, VALID_DISPLAYS, CAPTION_STYLE_NAMES, CAPTION_PARAGRAPH_STYLE_ID = "Caption", CAPTION_FORMAT_TO_OOXML, FIELD_NODE_TYPES, TOA_LEADER_REVERSE_MAP, CONTENT_TYPES_PART_ID = "[Content_Types].xml", CONTENT_TYPES_NS = "http://schemas.openxmlformats.org/package/2006/content-types", contentTypesPartDescriptor, empty_exports, init_empty, PIXELS_PER_INCH$1 = 96, MAX_HEIGHT_BUFFER_PX = 50, MAX_WIDTH_BUFFER_PX = 20, Editor, ContextMenuPluginKey, MENU_OFFSET_X = 0, MENU_OFFSET_Y = 28, CONTEXT_MENU_OFFSET_X = 10, CONTEXT_MENU_OFFSET_Y = 10, SLASH_COOLDOWN_MS = 5000, ContextMenu, SearchQuery = class {
198594
198929
  constructor(config2) {
198595
198930
  this.search = config2.search;
198596
198931
  this.caseSensitive = !!config2.caseSensitive;
@@ -201014,7 +201349,56 @@ var Node$13 = class Node$14 {
201014
201349
  styleEl.textContent = NATIVE_SELECTION_STYLES;
201015
201350
  doc$2.head?.appendChild(styleEl);
201016
201351
  nativeSelectionStylesInjected = true;
201017
- }, gradientIdCounter = 0, EMUS_PER_INCH = 914400, maxSize = 5000, cache$1, makeKey = (text5, font, letterSpacing) => {
201352
+ }, gradientIdCounter = 0, getFiniteNumber = (value) => {
201353
+ if (typeof value !== "number" || !Number.isFinite(value))
201354
+ return;
201355
+ return value;
201356
+ }, getNonNegativeFiniteNumber = (value) => {
201357
+ const numericValue = getFiniteNumber(value);
201358
+ if (numericValue == null || numericValue < 0)
201359
+ return;
201360
+ return numericValue;
201361
+ }, getMarkerTextWidthPx = (marker, measureMarkerText) => {
201362
+ const glyphWidthPx = getNonNegativeFiniteNumber(marker.glyphWidthPx);
201363
+ if (glyphWidthPx != null)
201364
+ return glyphWidthPx;
201365
+ if (marker.markerText) {
201366
+ const safeMeasuredWidthPx = getNonNegativeFiniteNumber(measureMarkerText(marker.markerText, marker));
201367
+ if (safeMeasuredWidthPx != null)
201368
+ return safeMeasuredWidthPx;
201369
+ }
201370
+ return getNonNegativeFiniteNumber(marker.markerBoxWidthPx) ?? 0;
201371
+ }, getMarkerBoxWidthPx = (marker, markerTextWidthPx) => Math.max(getNonNegativeFiniteNumber(marker.markerBoxWidthPx) ?? 0, markerTextWidthPx), getExplicitFirstLineMarkerStartPx = (wordLayout, marker) => {
201372
+ if (wordLayout?.firstLineIndentMode !== true)
201373
+ return;
201374
+ return getFiniteNumber(marker.markerX);
201375
+ }, getMarkerAnchorPx = (indentLeft, firstLine, hanging) => indentLeft - hanging + firstLine, getMarkerStartPx = (anchorPx, justification, markerTextWidthPx) => {
201376
+ if (justification === "right")
201377
+ return anchorPx - markerTextWidthPx;
201378
+ if (justification === "center")
201379
+ return anchorPx - markerTextWidthPx / 2;
201380
+ return anchorPx;
201381
+ }, getNextExplicitTabStopPx = (tabsPx, currentPosPx) => {
201382
+ if (!Array.isArray(tabsPx))
201383
+ return;
201384
+ for (const tabPx of tabsPx)
201385
+ if (typeof tabPx === "number" && Number.isFinite(tabPx) && tabPx > currentPosPx)
201386
+ return tabPx;
201387
+ }, getFirstLineTextStartTargetPx = (wordLayout, marker) => {
201388
+ return getFiniteNumber(marker.textStartX) ?? getFiniteNumber(wordLayout?.textStartPx);
201389
+ }, getNextDefaultTabStopPx = (currentPosPx) => {
201390
+ const remainderPx = currentPosPx % 48;
201391
+ if (remainderPx === 0)
201392
+ return currentPosPx + 48;
201393
+ return currentPosPx + 48 - remainderPx;
201394
+ }, getMinimumReadableTextStartPx = (markerContentEndPx, gutterWidthPx) => markerContentEndPx + gutterWidthPx, resolveExplicitStandardTextStartPx = (explicitTextStartPx, markerContentEndPx, gutterWidthPx) => {
201395
+ if (explicitTextStartPx == null)
201396
+ return;
201397
+ if (explicitTextStartPx > markerContentEndPx)
201398
+ return explicitTextStartPx;
201399
+ if (explicitTextStartPx > 0)
201400
+ return getMinimumReadableTextStartPx(markerContentEndPx, gutterWidthPx);
201401
+ }, EMUS_PER_INCH = 914400, maxSize = 5000, cache$1, makeKey = (text5, font, letterSpacing) => {
201018
201402
  return `${text5}|${font}|${letterSpacing || 0}`;
201019
201403
  }, fontMetricsCache, MAX_CACHE_SIZE$1 = 1000, METRICS_TEST_STRING = "MHgypbdlÁÉÍ", computeTabStops, measurementConfig, canvasContext = null, DEFAULT_TAB_INTERVAL_TWIPS$2 = 720, TWIPS_PER_PX$1, twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1, pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1), DEFAULT_TAB_INTERVAL_PX$1, TAB_EPSILON$1 = 0.1, DEFAULT_CELL_PADDING$1, DEFAULT_DECIMAL_SEPARATOR$1 = ".", ALLOWED_TAB_VALS, FIELD_ANNOTATION_PILL_PADDING = 8, FIELD_ANNOTATION_LINE_HEIGHT_MULTIPLIER = 1.2, FIELD_ANNOTATION_VERTICAL_PADDING = 6, DEFAULT_FIELD_ANNOTATION_FONT_SIZE = 16, DEFAULT_PARAGRAPH_FONT_SIZE = 12, DEFAULT_PARAGRAPH_FONT_FAMILY = "Arial", isValidFontSize = (value) => typeof value === "number" && Number.isFinite(value) && value > 0, normalizeFontSize$1 = (value, fallback = DEFAULT_PARAGRAPH_FONT_SIZE) => {
201020
201404
  if (isValidFontSize(value))
@@ -201678,7 +202062,11 @@ var Node$13 = class Node$14 {
201678
202062
  line.el.style.marginLeft = `${marginLeft}px`;
201679
202063
  line.el.style.marginRight = `${marginRight}px`;
201680
202064
  });
201681
- }, DEFAULT_TAB_INTERVAL_PX = 48, computeTabWidth = (currentPos, justification, tabs, hangingIndent, firstLineIndent, leftIndent) => {
202065
+ }, DEFAULT_TAB_INTERVAL_PX = 48, getFiniteNonNegativeNumber = (value) => {
202066
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
202067
+ return;
202068
+ return value;
202069
+ }, resolvePainterMarkerTextWidth = (markerTextWidthPx, marker) => getFiniteNonNegativeNumber(markerTextWidthPx) ?? getFiniteNonNegativeNumber(marker.glyphWidthPx) ?? getFiniteNonNegativeNumber(marker.markerBoxWidthPx) ?? 0, resolvePainterListMarkerGeometry = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListMarkerGeometry(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), resolvePainterListTextStartPx = ({ wordLayout, indentLeftPx, hangingIndentPx, firstLineIndentPx, markerTextWidthPx }) => resolveListTextStartPx(wordLayout, indentLeftPx, firstLineIndentPx, hangingIndentPx, (_markerText, marker) => resolvePainterMarkerTextWidth(markerTextWidthPx, marker)), computeTabWidth = (currentPos, justification, tabs, hangingIndent, firstLineIndent, leftIndent) => {
201682
202070
  const nextDefaultTabStop = currentPos + DEFAULT_TAB_INTERVAL_PX - currentPos % DEFAULT_TAB_INTERVAL_PX;
201683
202071
  let tabWidth;
201684
202072
  if (justification === "left") {
@@ -202096,6 +202484,13 @@ var Node$13 = class Node$14 {
202096
202484
  const hangingIndentPx = block.attrs?.indent && typeof block.attrs.indent.hanging === "number" ? block.attrs.indent.hanging : 0;
202097
202485
  const firstLineIndentPx = block.attrs?.indent && typeof block.attrs.indent.firstLine === "number" ? block.attrs.indent.firstLine : 0;
202098
202486
  const suppressFirstLineIndent = block.attrs?.suppressFirstLineIndent === true;
202487
+ const listFirstLineTextStartPx = markerLayout && markerMeasure ? resolvePainterListTextStartPx({
202488
+ wordLayout: wordLayout ?? undefined,
202489
+ indentLeftPx,
202490
+ hangingIndentPx,
202491
+ firstLineIndentPx,
202492
+ markerTextWidthPx: markerMeasure.markerTextWidth
202493
+ }) : undefined;
202099
202494
  const blockStartGlobal = cumulativeLineCount;
202100
202495
  if (cumulativeLineCount + blockLineCount <= globalFromLine) {
202101
202496
  cumulativeLineCount += blockLineCount;
@@ -202135,7 +202530,7 @@ var Node$13 = class Node$14 {
202135
202530
  const lineEl = renderLine(block, line, {
202136
202531
  ...context,
202137
202532
  section: "body"
202138
- }, lineIdx, isLastLine);
202533
+ }, lineIdx, isLastLine, lineIdx === 0 && localStartLine === 0 ? listFirstLineTextStartPx : undefined);
202139
202534
  lineEl.style.paddingLeft = "";
202140
202535
  lineEl.style.paddingRight = "";
202141
202536
  lineEl.style.textIndent = "";
@@ -202143,6 +202538,7 @@ var Node$13 = class Node$14 {
202143
202538
  renderListMarker({
202144
202539
  doc: doc$2,
202145
202540
  lineEl,
202541
+ wordLayout: wordLayout ?? undefined,
202146
202542
  markerLayout,
202147
202543
  markerMeasure,
202148
202544
  indentLeftPx,
@@ -202752,7 +203148,7 @@ var Node$13 = class Node$14 {
202752
203148
  this.onMouseLeave = null;
202753
203149
  this.hoveredSdtId = null;
202754
203150
  }
202755
- }, LIST_MARKER_GAP = 8, DEFAULT_PAGE_HEIGHT_PX = 1056, DEFAULT_VIRTUALIZED_PAGE_GAP = 72, COMMENT_EXTERNAL_COLOR = "#B1124B", COMMENT_INTERNAL_COLOR = "#078383", COMMENT_INACTIVE_ALPHA = "40", COMMENT_ACTIVE_ALPHA = "66", COMMENT_FADED_ALPHA = "20", LINK_DATASET_KEYS, MAX_HREF_LENGTH = 2048, SAFE_ANCHOR_PATTERN, MAX_DATA_URL_LENGTH, VALID_IMAGE_DATA_URL, MAX_RESIZE_MULTIPLIER = 3, FALLBACK_MAX_DIMENSION = 1000, MIN_IMAGE_DIMENSION = 20, AMBIGUOUS_LINK_PATTERNS, linkMetrics, TRACK_CHANGE_BASE_CLASS, TRACK_CHANGE_FOCUSED_CLASS = "track-change-focused", TRACK_CHANGE_MODIFIER_CLASS, LINK_TARGET_SET, normalizeAnchor$1 = (value) => {
203151
+ }, LIST_MARKER_GAP$1 = 8, DEFAULT_PAGE_HEIGHT_PX = 1056, DEFAULT_VIRTUALIZED_PAGE_GAP = 72, COMMENT_EXTERNAL_COLOR = "#B1124B", COMMENT_INTERNAL_COLOR = "#078383", COMMENT_INACTIVE_ALPHA = "40", COMMENT_ACTIVE_ALPHA = "66", COMMENT_FADED_ALPHA = "20", LINK_DATASET_KEYS, MAX_HREF_LENGTH = 2048, SAFE_ANCHOR_PATTERN, MAX_DATA_URL_LENGTH, VALID_IMAGE_DATA_URL, MAX_RESIZE_MULTIPLIER = 3, FALLBACK_MAX_DIMENSION = 1000, MIN_IMAGE_DIMENSION = 20, AMBIGUOUS_LINK_PATTERNS, linkMetrics, TRACK_CHANGE_BASE_CLASS, TRACK_CHANGE_FOCUSED_CLASS = "track-change-focused", TRACK_CHANGE_MODIFIER_CLASS, LINK_TARGET_SET, normalizeAnchor$1 = (value) => {
202756
203152
  if (typeof value !== "string")
202757
203153
  return null;
202758
203154
  const trimmed = value.trim();
@@ -216742,9 +217138,9 @@ var Node$13 = class Node$14 {
216742
217138
  return false;
216743
217139
  return Boolean(checker(attrs));
216744
217140
  }, SuperToolbar, ICONS, TEXTS, tableActionsOptions;
216745
- var init_src_Mwv45g3M_es = __esm(() => {
217141
+ var init_src_BnjrN0Yi_es = __esm(() => {
216746
217142
  init_rolldown_runtime_B2q5OVn9_es();
216747
- init_SuperConverter_BBGfKYpx_es();
217143
+ init_SuperConverter_BeR1rqZz_es();
216748
217144
  init_jszip_ChlR43oI_es();
216749
217145
  init_uuid_qzgm05fK_es();
216750
217146
  init_constants_CMPtQbp7_es();
@@ -225578,7 +225974,7 @@ function print() { __p += __j.call(arguments, '') }
225578
225974
  stylesPartDescriptor = {
225579
225975
  id: STYLES_PART_ID,
225580
225976
  ensurePart(editor) {
225581
- const converter = getConverter$5(editor);
225977
+ const converter = getConverter$7(editor);
225582
225978
  if (converter?.convertedXml[STYLES_PART_ID])
225583
225979
  return converter.convertedXml[STYLES_PART_ID];
225584
225980
  return {
@@ -225593,7 +225989,7 @@ function print() { __p += __j.call(arguments, '') }
225593
225989
  },
225594
225990
  afterCommit(ctx$1) {
225595
225991
  if (ctx$1.source.startsWith("collab:remote:")) {
225596
- const converter = getConverter$5(ctx$1.editor);
225992
+ const converter = getConverter$7(ctx$1.editor);
225597
225993
  if (converter)
225598
225994
  try {
225599
225995
  converter.translatedLinkedStyles = translateStyleDefinitions(converter.convertedXml);
@@ -225718,6 +226114,38 @@ function print() { __p += __j.call(arguments, '') }
225718
226114
  KIND_ORDER = ["header", "footer"];
225719
226115
  HEADER_FILE_PATTERN = /header(\d+)\.xml$/;
225720
226116
  FOOTER_FILE_PATTERN = /footer(\d+)\.xml$/;
226117
+ SPECIAL_NOTE_TYPES = new Set(["separator", "continuationSeparator"]);
226118
+ FOOTNOTES_CONFIG = {
226119
+ partId: FOOTNOTES_PART_ID,
226120
+ rootElementName: "w:footnotes",
226121
+ childElementName: "w:footnote",
226122
+ converterKey: "footnotes"
226123
+ };
226124
+ ENDNOTES_CONFIG = {
226125
+ partId: ENDNOTES_PART_ID,
226126
+ rootElementName: "w:endnotes",
226127
+ childElementName: "w:endnote",
226128
+ converterKey: "endnotes"
226129
+ };
226130
+ NOTES_XMLNS = {
226131
+ "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
226132
+ "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
226133
+ "xmlns:o": "urn:schemas-microsoft-com:office:office",
226134
+ "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
226135
+ "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
226136
+ "xmlns:v": "urn:schemas-microsoft-com:vml",
226137
+ "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
226138
+ "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
226139
+ "xmlns:w10": "urn:schemas-microsoft-com:office:word",
226140
+ "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
226141
+ "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
226142
+ "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
226143
+ "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
226144
+ "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
226145
+ "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
226146
+ };
226147
+ footnotesPartDescriptor = createNotePartDescriptor(FOOTNOTES_CONFIG);
226148
+ endnotesPartDescriptor = createNotePartDescriptor(ENDNOTES_CONFIG);
225721
226149
  RESTART_POLICY_TO_OOXML = {
225722
226150
  continuous: "continuous",
225723
226151
  eachSection: "eachSect",
@@ -232314,9 +232742,22 @@ function print() { __p += __j.call(arguments, '') }
232314
232742
  const paraIndentRight = paraIndent?.right ?? 0;
232315
232743
  const firstLineOffset = block.attrs?.suppressFirstLineIndent === true ? 0 : (paraIndent?.firstLine ?? 0) - (paraIndent?.hanging ?? 0);
232316
232744
  const paragraphEndsWithLineBreak = (block.runs.length > 0 ? block.runs[block.runs.length - 1] : null)?.kind === "lineBreak";
232317
- let listFirstLineMarkerTabEndPx = null;
232745
+ const listFirstLineTextStartPx = !fragment2.continuesFromPrev && fragment2.markerWidth && wordLayout?.marker ? resolvePainterListTextStartPx({
232746
+ wordLayout,
232747
+ indentLeftPx: paraIndentLeft,
232748
+ hangingIndentPx: paraIndent?.hanging ?? 0,
232749
+ firstLineIndentPx: paraIndent?.firstLine ?? 0,
232750
+ markerTextWidthPx: fragment2.markerTextWidth
232751
+ }) : undefined;
232752
+ const listFirstLineMarkerGeometry = !fragment2.continuesFromPrev && fragment2.markerWidth && wordLayout?.marker?.justification === "left" && wordLayout.firstLineIndentMode !== true && typeof fragment2.markerTextWidth === "number" && Number.isFinite(fragment2.markerTextWidth) && fragment2.markerTextWidth >= 0 ? resolvePainterListMarkerGeometry({
232753
+ wordLayout,
232754
+ indentLeftPx: paraIndentLeft,
232755
+ hangingIndentPx: paraIndent?.hanging ?? 0,
232756
+ firstLineIndentPx: paraIndent?.firstLine ?? 0,
232757
+ markerTextWidthPx: fragment2.markerTextWidth
232758
+ }) : undefined;
232318
232759
  let listTabWidth = 0;
232319
- let markerStartPos;
232760
+ let markerStartPos = 0;
232320
232761
  if (!fragment2.continuesFromPrev && fragment2.markerWidth && wordLayout?.marker) {
232321
232762
  const markerTextWidth = fragment2.markerTextWidth;
232322
232763
  const anchorPoint = paraIndentLeft - (paraIndent?.hanging ?? 0) + (paraIndent?.firstLine ?? 0);
@@ -232333,22 +232774,25 @@ function print() { __p += __j.call(arguments, '') }
232333
232774
  currentPos = markerStartPos + markerTextWidth;
232334
232775
  }
232335
232776
  const suffix = wordLayout.marker.suffix ?? "tab";
232336
- if (suffix === "tab")
232777
+ if (listFirstLineMarkerGeometry && (suffix === "tab" || suffix === "space"))
232778
+ listTabWidth = listFirstLineMarkerGeometry.suffixWidthPx;
232779
+ else if (suffix === "tab")
232337
232780
  listTabWidth = computeTabWidth(currentPos, markerJustification, wordLayout.tabsPx, paraIndent?.hanging, paraIndent?.firstLine, paraIndentLeft);
232338
232781
  else if (suffix === "space")
232339
232782
  listTabWidth = 4;
232340
- listFirstLineMarkerTabEndPx = currentPos + listTabWidth;
232341
232783
  }
232342
232784
  lines.forEach((line, index2) => {
232785
+ const hasExplicitSegmentPositioning = line.segments?.some((segment) => segment.x !== undefined) === true;
232786
+ const hasListFirstLineMarker = index2 === 0 && !fragment2.continuesFromPrev && fragment2.markerWidth && wordLayout?.marker;
232787
+ const shouldUseResolvedListTextStart = hasListFirstLineMarker && hasExplicitSegmentPositioning && listFirstLineTextStartPx != null;
232343
232788
  const positiveIndentReduction = Math.max(0, paraIndentLeft) + Math.max(0, paraIndentRight);
232344
232789
  const fallbackAvailableWidth = Math.max(0, fragment2.width - positiveIndentReduction);
232345
232790
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
232346
- if (index2 === 0 && listFirstLineMarkerTabEndPx != null)
232347
- availableWidthOverride = fragment2.width - listFirstLineMarkerTabEndPx - Math.max(0, paraIndentRight);
232791
+ if (shouldUseResolvedListTextStart)
232792
+ availableWidthOverride = fragment2.width - listFirstLineTextStartPx - Math.max(0, paraIndentRight);
232348
232793
  const shouldSkipJustifyForLastLine = index2 === lines.length - 1 && !fragment2.continuesOnNext && !paragraphEndsWithLineBreak;
232349
- const lineEl = this.renderLine(block, line, context, availableWidthOverride, fragment2.fromLine + index2, shouldSkipJustifyForLastLine);
232350
- const isListFirstLine = index2 === 0 && !fragment2.continuesFromPrev && fragment2.markerWidth && fragment2.markerTextWidth && wordLayout?.marker;
232351
- const hasExplicitSegmentPositioning = line.segments?.some((seg) => seg.x !== undefined);
232794
+ const lineEl = this.renderLine(block, line, context, availableWidthOverride, fragment2.fromLine + index2, shouldSkipJustifyForLastLine, shouldUseResolvedListTextStart ? listFirstLineTextStartPx : undefined);
232795
+ const isListFirstLine = Boolean(hasListFirstLineMarker && fragment2.markerTextWidth);
232352
232796
  const isFirstLine = index2 === 0 && !fragment2.continuesFromPrev;
232353
232797
  if (!isListFirstLine) {
232354
232798
  if (hasExplicitSegmentPositioning) {
@@ -232370,7 +232814,9 @@ function print() { __p += __j.call(arguments, '') }
232370
232814
  } else if (firstLineOffset && !isListFirstLine)
232371
232815
  lineEl.style.textIndent = "0px";
232372
232816
  if (isListFirstLine) {
232373
- const marker = wordLayout.marker;
232817
+ const marker = wordLayout?.marker;
232818
+ if (!marker)
232819
+ return;
232374
232820
  lineEl.style.paddingLeft = `${paraIndentLeft + (paraIndent?.firstLine ?? 0) - (paraIndent?.hanging ?? 0)}px`;
232375
232821
  if (!marker.run.vanish) {
232376
232822
  const markerContainer = this.doc.createElement("span");
@@ -232517,8 +232963,8 @@ function print() { __p += __j.call(arguments, '') }
232517
232963
  if (marker) {
232518
232964
  markerEl.textContent = marker.markerText ?? null;
232519
232965
  markerEl.style.display = "inline-block";
232520
- markerEl.style.width = `${Math.max(0, fragment2.markerWidth - LIST_MARKER_GAP)}px`;
232521
- markerEl.style.paddingRight = `${LIST_MARKER_GAP}px`;
232966
+ markerEl.style.width = `${Math.max(0, fragment2.markerWidth - LIST_MARKER_GAP$1)}px`;
232967
+ markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
232522
232968
  markerEl.style.textAlign = marker.justification ?? "left";
232523
232969
  markerEl.style.fontFamily = toCssFontFamily(marker.run.fontFamily) ?? marker.run.fontFamily;
232524
232970
  markerEl.style.fontSize = `${marker.run.fontSize}px`;
@@ -232533,8 +232979,8 @@ function print() { __p += __j.call(arguments, '') }
232533
232979
  } else {
232534
232980
  markerEl.textContent = item.marker.text;
232535
232981
  markerEl.style.display = "inline-block";
232536
- markerEl.style.width = `${Math.max(0, fragment2.markerWidth - LIST_MARKER_GAP)}px`;
232537
- markerEl.style.paddingRight = `${LIST_MARKER_GAP}px`;
232982
+ markerEl.style.width = `${Math.max(0, fragment2.markerWidth - LIST_MARKER_GAP$1)}px`;
232983
+ markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
232538
232984
  if (item.marker.align)
232539
232985
  markerEl.style.textAlign = item.marker.align;
232540
232986
  }
@@ -233212,10 +233658,10 @@ function print() { __p += __j.call(arguments, '') }
233212
233658
  const applyFragmentFrameWithSection = (el, frag) => {
233213
233659
  this.applyFragmentFrame(el, frag, context.section);
233214
233660
  };
233215
- const renderLineForTableCell = (block, line, ctx$1, lineIndex, isLastLine) => {
233661
+ const renderLineForTableCell = (block, line, ctx$1, lineIndex, isLastLine, resolvedListTextStartPx) => {
233216
233662
  const paragraphEndsWithLineBreak = (block.runs.length > 0 ? block.runs[block.runs.length - 1] : null)?.kind === "lineBreak";
233217
233663
  const shouldSkipJustify = isLastLine && !paragraphEndsWithLineBreak;
233218
- return this.renderLine(block, line, ctx$1, undefined, lineIndex, shouldSkipJustify);
233664
+ return this.renderLine(block, line, ctx$1, undefined, lineIndex, shouldSkipJustify, resolvedListTextStartPx);
233219
233665
  };
233220
233666
  const renderDrawingContentForTableCell = (block) => {
233221
233667
  if (block.drawingKind === "image")
@@ -233797,7 +234243,7 @@ function print() { __p += __j.call(arguments, '') }
233797
234243
  annotation.style.position = "relative";
233798
234244
  annotation.appendChild(caretAnchor);
233799
234245
  }
233800
- renderLine(block, line, context, availableWidthOverride, lineIndex, skipJustify) {
234246
+ renderLine(block, line, context, availableWidthOverride, lineIndex, skipJustify, resolvedListTextStartPx) {
233801
234247
  if (!this.doc)
233802
234248
  throw new Error("DomPainter: document is not available");
233803
234249
  const lineRange = computeLinePmRange$1(block, line);
@@ -234021,8 +234467,8 @@ function print() { __p += __j.call(arguments, '') }
234021
234467
  const wordLayoutValue = block.attrs?.wordLayout;
234022
234468
  const wordLayout = isMinimalWordLayout(wordLayoutValue) ? wordLayoutValue : undefined;
234023
234469
  const isListParagraph = Boolean(wordLayout?.marker);
234024
- const rawTextStartPx = typeof wordLayout?.marker?.textStartX === "number" && Number.isFinite(wordLayout.marker.textStartX) ? wordLayout.marker.textStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : undefined;
234025
- const indentOffset = isListParagraph ? isFirstLineOfPara ? rawTextStartPx ?? indentLeft : indentLeft : indentLeft + firstLineOffsetForCumX;
234470
+ const fallbackListTextStartPx = typeof wordLayout?.marker?.textStartX === "number" && Number.isFinite(wordLayout.marker.textStartX) ? wordLayout.marker.textStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : undefined;
234471
+ const indentOffset = isListParagraph ? isFirstLineOfPara ? resolvedListTextStartPx ?? fallbackListTextStartPx ?? indentLeft : indentLeft : indentLeft + firstLineOffsetForCumX;
234026
234472
  let cumulativeX = 0;
234027
234473
  const segmentsByRun = /* @__PURE__ */ new Map;
234028
234474
  line.segments.forEach((segment) => {
@@ -236878,6 +237324,16 @@ function print() { __p += __j.call(arguments, '') }
236878
237324
  event: "stylesDefaultsChanged",
236879
237325
  handler: handleStylesDefaultsChanged
236880
237326
  });
237327
+ const handleNotesPartChanged = () => {
237328
+ this.#pendingDocChange = true;
237329
+ this.#selectionSync.onLayoutStart();
237330
+ this.#scheduleRerender();
237331
+ };
237332
+ this.#editor.on("notes-part-changed", handleNotesPartChanged);
237333
+ this.#editorListeners.push({
237334
+ event: "notes-part-changed",
237335
+ handler: handleNotesPartChanged
237336
+ });
236881
237337
  const handleCollaborationReady = (payload) => {
236882
237338
  this.emit("collaborationReady", payload);
236883
237339
  if (this.#options.collaborationProvider?.awareness && this.#layoutOptions.presence?.enabled !== false)
@@ -250352,8 +250808,8 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
250352
250808
 
250353
250809
  // ../../packages/superdoc/dist/super-editor.es.js
250354
250810
  var init_super_editor_es = __esm(() => {
250355
- init_src_Mwv45g3M_es();
250356
- init_SuperConverter_BBGfKYpx_es();
250811
+ init_src_BnjrN0Yi_es();
250812
+ init_SuperConverter_BeR1rqZz_es();
250357
250813
  init_jszip_ChlR43oI_es();
250358
250814
  init_xml_js_DLE8mr0n_es();
250359
250815
  init_constants_CMPtQbp7_es();
@@ -275776,7 +276232,7 @@ var init_awareness = __esm(() => {
275776
276232
  };
275777
276233
  });
275778
276234
 
275779
- // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_4cc29e23e769b0d152b4b8d1fb5406d2/node_modules/y-prosemirror/src/plugins/keys.js
276235
+ // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_bbc4954c3f565631ca331e4536595600/node_modules/y-prosemirror/src/plugins/keys.js
275780
276236
  var ySyncPluginKey2, yUndoPluginKey2, yCursorPluginKey2;
275781
276237
  var init_keys = __esm(() => {
275782
276238
  init_dist5();
@@ -275785,18 +276241,18 @@ var init_keys = __esm(() => {
275785
276241
  yCursorPluginKey2 = new PluginKey2("yjs-cursor");
275786
276242
  });
275787
276243
 
275788
- // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_4cc29e23e769b0d152b4b8d1fb5406d2/node_modules/y-prosemirror/src/plugins/cursor-plugin.js
276244
+ // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_bbc4954c3f565631ca331e4536595600/node_modules/y-prosemirror/src/plugins/cursor-plugin.js
275789
276245
  var init_cursor_plugin = __esm(() => {
275790
276246
  init_awareness();
275791
276247
  });
275792
276248
 
275793
- // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_4cc29e23e769b0d152b4b8d1fb5406d2/node_modules/y-prosemirror/src/plugins/undo-plugin.js
276249
+ // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_bbc4954c3f565631ca331e4536595600/node_modules/y-prosemirror/src/plugins/undo-plugin.js
275794
276250
  var defaultProtectedNodes2;
275795
276251
  var init_undo_plugin = __esm(() => {
275796
276252
  defaultProtectedNodes2 = new Set(["paragraph"]);
275797
276253
  });
275798
276254
 
275799
- // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_4cc29e23e769b0d152b4b8d1fb5406d2/node_modules/y-prosemirror/src/y-prosemirror.js
276255
+ // ../../node_modules/.pnpm/y-prosemirror@1.3.7_prosemirror-model@1.25.4_prosemirror-state@1.4.4_prosemirror-view@1_bbc4954c3f565631ca331e4536595600/node_modules/y-prosemirror/src/y-prosemirror.js
275800
276256
  var init_y_prosemirror = __esm(() => {
275801
276257
  init_cursor_plugin();
275802
276258
  init_undo_plugin();
@@ -307789,20 +308245,28 @@ var init_documentCommentsImporter = __esm(() => {
307789
308245
  });
307790
308246
 
307791
308247
  // ../../packages/super-editor/src/core/super-converter/v2/importer/documentFootnotesImporter.js
307792
- function importFootnoteData2({ docx, editor, converter, nodeListHandler, numbering } = {}) {
308248
+ function importNoteEntries2({
308249
+ partXml,
308250
+ childElementName,
308251
+ filename,
308252
+ docx,
308253
+ editor,
308254
+ converter,
308255
+ nodeListHandler,
308256
+ numbering
308257
+ }) {
307793
308258
  const handler3 = nodeListHandler || defaultNodeListHandler2();
307794
- const footnotes = docx?.["word/footnotes.xml"];
307795
- if (!footnotes?.elements?.length)
308259
+ if (!partXml?.elements?.length)
307796
308260
  return [];
307797
- const root4 = footnotes.elements[0];
308261
+ const root4 = partXml.elements[0];
307798
308262
  const elements = Array.isArray(root4?.elements) ? root4.elements : [];
307799
- const footnoteElements = elements.filter((el) => el?.name === "w:footnote");
307800
- if (footnoteElements.length === 0)
308263
+ const noteElements = elements.filter((el) => el?.name === childElementName);
308264
+ if (noteElements.length === 0)
307801
308265
  return [];
307802
308266
  const results = [];
307803
308267
  const lists = {};
307804
308268
  const inlineDocumentFonts = [];
307805
- footnoteElements.forEach((el) => {
308269
+ noteElements.forEach((el) => {
307806
308270
  const idRaw = el?.attributes?.["w:id"];
307807
308271
  if (idRaw === undefined || idRaw === null)
307808
308272
  return;
@@ -307831,7 +308295,7 @@ function importFootnoteData2({ docx, editor, converter, nodeListHandler, numberi
307831
308295
  numbering,
307832
308296
  lists,
307833
308297
  inlineDocumentFonts,
307834
- filename: "footnotes.xml",
308298
+ filename,
307835
308299
  path: [el]
307836
308300
  });
307837
308301
  const stripped = stripFootnoteMarkerNodes2(converted);
@@ -307844,6 +308308,30 @@ function importFootnoteData2({ docx, editor, converter, nodeListHandler, numberi
307844
308308
  });
307845
308309
  return results;
307846
308310
  }
308311
+ function importFootnoteData2({ docx, editor, converter, nodeListHandler, numbering } = {}) {
308312
+ return importNoteEntries2({
308313
+ partXml: docx?.["word/footnotes.xml"],
308314
+ childElementName: "w:footnote",
308315
+ filename: "footnotes.xml",
308316
+ docx,
308317
+ editor,
308318
+ converter,
308319
+ nodeListHandler,
308320
+ numbering
308321
+ });
308322
+ }
308323
+ function importEndnoteData2({ docx, editor, converter, nodeListHandler, numbering } = {}) {
308324
+ return importNoteEntries2({
308325
+ partXml: docx?.["word/endnotes.xml"],
308326
+ childElementName: "w:endnote",
308327
+ filename: "endnotes.xml",
308328
+ docx,
308329
+ editor,
308330
+ converter,
308331
+ nodeListHandler,
308332
+ numbering
308333
+ });
308334
+ }
307847
308335
  var stripFootnoteMarkerNodes2 = (nodes) => {
307848
308336
  if (!Array.isArray(nodes) || nodes.length === 0)
307849
308337
  return nodes;
@@ -308967,6 +309455,7 @@ var detectDocumentOrigin2 = (docx) => {
308967
309455
  const numbering = getNumberingDefinitions2(docx);
308968
309456
  const comments = importCommentData2({ docx, nodeListHandler, converter, editor });
308969
309457
  const footnotes = importFootnoteData2({ docx, nodeListHandler, converter, editor, numbering });
309458
+ const endnotes = importEndnoteData2({ docx, nodeListHandler, converter, editor, numbering });
308970
309459
  const translatedLinkedStyles = translateStyleDefinitions2(docx);
308971
309460
  const translatedNumbering = translateNumberingDefinitions2(docx);
308972
309461
  const importDiagnosticsCollectionId = startCollection2();
@@ -309003,6 +309492,7 @@ var detectDocumentOrigin2 = (docx) => {
309003
309492
  pageStyles: getDocumentStyles2(node4, docx, converter, editor, numbering, translatedNumbering, translatedLinkedStyles),
309004
309493
  comments,
309005
309494
  footnotes,
309495
+ endnotes,
309006
309496
  inlineDocumentFonts,
309007
309497
  linkedStyles: getStyleDefinitions2(docx, converter, editor),
309008
309498
  translatedLinkedStyles,
@@ -312071,6 +312561,7 @@ var init_SuperConverter = __esm(() => {
312071
312561
  init_exporter_docx_defs();
312072
312562
  init_commentsExporter();
312073
312563
  init_footnotesExporter();
312564
+ init_documentFootnotesImporter();
312074
312565
  init_docx_helpers2();
312075
312566
  init_relationship_helpers();
312076
312567
  init_constants2();
@@ -312698,6 +313189,7 @@ var init_SuperConverter = __esm(() => {
312698
313189
  this.numbering = result.numbering;
312699
313190
  this.comments = result.comments;
312700
313191
  this.footnotes = result.footnotes;
313192
+ this.endnotes = result.endnotes ?? [];
312701
313193
  this.linkedStyles = result.linkedStyles;
312702
313194
  this.translatedLinkedStyles = result.translatedLinkedStyles;
312703
313195
  this.translatedNumbering = result.translatedNumbering;
@@ -313034,6 +313526,17 @@ var init_SuperConverter = __esm(() => {
313034
313526
  schema = normalizeDuplicateBlockIdentitiesInContent2(schema);
313035
313527
  return { type: "doc", content: [...schema] };
313036
313528
  }
313529
+ reimportNotePart(partId) {
313530
+ if (!this.convertedXml?.[partId])
313531
+ return [];
313532
+ const importFn = partId === "word/endnotes.xml" ? importEndnoteData2 : importFootnoteData2;
313533
+ return importFn({
313534
+ docx: this.convertedXml,
313535
+ editor: {},
313536
+ converter: this,
313537
+ numbering: this.numbering
313538
+ });
313539
+ }
313037
313540
  createDefaultHeader(variant = "default") {
313038
313541
  if (typeof variant !== "string") {
313039
313542
  throw new TypeError(`variant must be a string, received ${typeof variant}`);
@@ -320309,6 +320812,9 @@ function takeSnapshot2(editor, partIds) {
320309
320812
  partEntries,
320310
320813
  numbering: converter?.numbering ? clonePart2(converter.numbering) : undefined,
320311
320814
  translatedNumbering: converter?.translatedNumbering ? clonePart2(converter.translatedNumbering) : undefined,
320815
+ footnotes: converter?.footnotes ? clonePart2(converter.footnotes) : undefined,
320816
+ endnotes: converter?.endnotes ? clonePart2(converter.endnotes) : undefined,
320817
+ footnoteProperties: converter?.footnoteProperties ? clonePart2(converter.footnoteProperties) : undefined,
320312
320818
  revision: getRevision2(editor),
320313
320819
  documentModified: converter?.documentModified ?? false,
320314
320820
  documentGuid: converter?.documentGuid ?? null
@@ -320332,6 +320838,12 @@ function restoreFromSnapshot2(editor, snapshot2) {
320332
320838
  converter.numbering = snapshot2.numbering;
320333
320839
  if (snapshot2.translatedNumbering !== undefined)
320334
320840
  converter.translatedNumbering = snapshot2.translatedNumbering;
320841
+ if (snapshot2.footnotes !== undefined)
320842
+ converter.footnotes = snapshot2.footnotes;
320843
+ if (snapshot2.endnotes !== undefined)
320844
+ converter.endnotes = snapshot2.endnotes;
320845
+ if (snapshot2.footnoteProperties !== undefined)
320846
+ converter.footnoteProperties = snapshot2.footnoteProperties;
320335
320847
  converter.documentModified = snapshot2.documentModified;
320336
320848
  converter.documentGuid = snapshot2.documentGuid;
320337
320849
  restoreRevision2(editor, snapshot2.revision);
@@ -336576,6 +337088,28 @@ var init_bookmark_wrappers = __esm(() => {
336576
337088
  init_errors3();
336577
337089
  });
336578
337090
 
337091
+ // ../../packages/super-editor/src/document-api-adapters/helpers/note-entry-lookup.ts
337092
+ function isSpecialEntry2(entry) {
337093
+ return SPECIAL_NOTE_TYPES2.has(entry.type ?? "");
337094
+ }
337095
+ function findNoteEntryById2(entries, noteId) {
337096
+ if (!Array.isArray(entries))
337097
+ return;
337098
+ let fallback;
337099
+ for (const entry of entries) {
337100
+ if (String(entry.id ?? "") !== noteId)
337101
+ continue;
337102
+ if (!isSpecialEntry2(entry))
337103
+ return entry;
337104
+ fallback ??= entry;
337105
+ }
337106
+ return fallback;
337107
+ }
337108
+ var SPECIAL_NOTE_TYPES2;
337109
+ var init_note_entry_lookup = __esm(() => {
337110
+ SPECIAL_NOTE_TYPES2 = new Set(["separator", "continuationSeparator"]);
337111
+ });
337112
+
336579
337113
  // ../../packages/super-editor/src/document-api-adapters/helpers/footnote-resolver.ts
336580
337114
  function getConverterStore2(editor) {
336581
337115
  return editor.converter ?? {};
@@ -336609,7 +337143,7 @@ function resolveCollectionContent2(collection, noteId) {
336609
337143
  if (!collection)
336610
337144
  return "";
336611
337145
  if (Array.isArray(collection)) {
336612
- const match2 = collection.find((entry) => String(entry?.id ?? "") === noteId);
337146
+ const match2 = findNoteEntryById2(collection, noteId);
336613
337147
  return extractTextFromContent2(match2?.content);
336614
337148
  }
336615
337149
  if (isLegacyFootnoteMap2(collection)) {
@@ -336681,39 +337215,257 @@ function buildFootnoteDiscoveryItem2(editor, resolved, evaluatedRevision) {
336681
337215
  var init_footnote_resolver = __esm(() => {
336682
337216
  init_src();
336683
337217
  init_errors3();
337218
+ init_note_entry_lookup();
336684
337219
  });
336685
337220
 
336686
- // ../../packages/super-editor/src/document-api-adapters/out-of-band-mutation.ts
336687
- function executeOutOfBandMutation2(editor, mutateFn, options) {
336688
- if (!options.dryRun) {
336689
- if (editor.options?.collaborationProvider && editor.options?.ydoc) {
336690
- try {
336691
- yUndoPluginKey2.getState(editor.state)?.undoManager?.stopCapturing();
336692
- } catch {}
336693
- } else {
336694
- try {
336695
- editor.view?.dispatch?.(closeHistory2(editor.state.tr));
336696
- } catch {}
337221
+ // ../../packages/super-editor/src/core/parts/adapters/notes-part-descriptor.ts
337222
+ function getConverter14(editor) {
337223
+ return editor.converter;
337224
+ }
337225
+ function getRootElement2(part) {
337226
+ return part?.elements?.[0];
337227
+ }
337228
+ function getNoteElements2(part, childElementName) {
337229
+ const root4 = getRootElement2(part);
337230
+ if (!root4?.elements)
337231
+ return [];
337232
+ return root4.elements.filter((el) => el.name === childElementName);
337233
+ }
337234
+ function textToNoteOoxmlParagraphs2(text9) {
337235
+ return text9.split(/\r?\n/).map((line) => ({
337236
+ type: "element",
337237
+ name: "w:p",
337238
+ elements: line.length > 0 ? [
337239
+ {
337240
+ type: "element",
337241
+ name: "w:r",
337242
+ elements: [
337243
+ {
337244
+ type: "element",
337245
+ name: "w:t",
337246
+ attributes: { "xml:space": "preserve" },
337247
+ elements: [{ type: "text", text: line }]
337248
+ }
337249
+ ]
337250
+ }
337251
+ ] : []
337252
+ }));
337253
+ }
337254
+ function ensureFootnoteRefRun2(paragraphs, childElementName) {
337255
+ if (paragraphs.length === 0)
337256
+ return;
337257
+ const refName = childElementName === "w:footnote" ? "w:footnoteRef" : "w:endnoteRef";
337258
+ const styleName = childElementName === "w:footnote" ? "FootnoteReference" : "EndnoteReference";
337259
+ const firstParagraph = paragraphs[0];
337260
+ if (!firstParagraph.elements)
337261
+ firstParagraph.elements = [];
337262
+ const refRun = {
337263
+ type: "element",
337264
+ name: "w:r",
337265
+ elements: [
337266
+ {
337267
+ type: "element",
337268
+ name: "w:rPr",
337269
+ elements: [
337270
+ { type: "element", name: "w:rStyle", attributes: { "w:val": styleName } },
337271
+ { type: "element", name: "w:vertAlign", attributes: { "w:val": "superscript" } }
337272
+ ]
337273
+ },
337274
+ { type: "element", name: refName, elements: [] }
337275
+ ]
337276
+ };
337277
+ const pPrIndex = firstParagraph.elements.findIndex((el) => el?.name === "w:pPr");
337278
+ firstParagraph.elements.splice(pPrIndex >= 0 ? pPrIndex + 1 : 0, 0, refRun);
337279
+ }
337280
+ function addNoteElement2(part, config41, noteId, text9) {
337281
+ const root4 = getRootElement2(part);
337282
+ if (!root4)
337283
+ throw new Error(`addNoteElement: missing root element in ${config41.partId}`);
337284
+ if (!root4.elements)
337285
+ root4.elements = [];
337286
+ const duplicate = root4.elements.find((el) => el.name === config41.childElementName && el.attributes?.["w:id"] === noteId);
337287
+ if (duplicate) {
337288
+ throw new Error(`addNoteElement: note id "${noteId}" already exists in ${config41.partId}`);
337289
+ }
337290
+ const paragraphs = textToNoteOoxmlParagraphs2(text9);
337291
+ ensureFootnoteRefRun2(paragraphs, config41.childElementName);
337292
+ const noteElement = {
337293
+ type: "element",
337294
+ name: config41.childElementName,
337295
+ attributes: { "w:id": noteId },
337296
+ elements: paragraphs
337297
+ };
337298
+ root4.elements.push(noteElement);
337299
+ return noteElement;
337300
+ }
337301
+ function updateNoteElement2(part, config41, noteId, text9) {
337302
+ const notes = getNoteElements2(part, config41.childElementName);
337303
+ const target = notes.find((el) => el.attributes?.["w:id"] === noteId);
337304
+ if (!target)
337305
+ return false;
337306
+ const paragraphs = textToNoteOoxmlParagraphs2(text9);
337307
+ ensureFootnoteRefRun2(paragraphs, config41.childElementName);
337308
+ target.elements = paragraphs;
337309
+ return true;
337310
+ }
337311
+ function removeNoteElement2(part, config41, noteId) {
337312
+ const root4 = getRootElement2(part);
337313
+ if (!root4?.elements)
337314
+ return false;
337315
+ const index3 = root4.elements.findIndex((el) => el.name === config41.childElementName && el.attributes?.["w:id"] === noteId);
337316
+ if (index3 < 0)
337317
+ return false;
337318
+ root4.elements.splice(index3, 1);
337319
+ return true;
337320
+ }
337321
+ function rebuildDerivedCache2(editor, config41, part) {
337322
+ const converter = getConverter14(editor);
337323
+ if (!converter)
337324
+ return;
337325
+ if (typeof converter.reimportNotePart === "function") {
337326
+ try {
337327
+ converter[config41.converterKey] = converter.reimportNotePart(config41.partId);
337328
+ return;
337329
+ } catch (err) {
337330
+ console.warn(`[parts] reimportNotePart failed for ${config41.partId}, using fallback:`, err);
336697
337331
  }
336698
337332
  }
336699
- checkRevision2(editor, options.expectedRevision);
336700
- const result = mutateFn(options.dryRun);
336701
- if (result.changed && !options.dryRun) {
336702
- const converter = editor.converter;
336703
- if (converter) {
336704
- converter.documentModified = true;
336705
- if (!converter.documentGuid && typeof converter.promoteToGuid === "function") {
336706
- converter.promoteToGuid();
337333
+ const notes = getNoteElements2(part, config41.childElementName);
337334
+ const entries = notes.map((el) => ({
337335
+ id: String(el.attributes?.["w:id"] ?? ""),
337336
+ type: el.attributes?.["w:type"] ?? null,
337337
+ content: [],
337338
+ originalXml: structuredClone(el)
337339
+ }));
337340
+ converter[config41.converterKey] = entries;
337341
+ }
337342
+ function createInitialNotesPart2(config41) {
337343
+ return {
337344
+ declaration: {
337345
+ attributes: { version: "1.0", encoding: "UTF-8", standalone: "yes" }
337346
+ },
337347
+ elements: [
337348
+ {
337349
+ type: "element",
337350
+ name: config41.rootElementName,
337351
+ attributes: { ...NOTES_XMLNS2 },
337352
+ elements: [
337353
+ {
337354
+ type: "element",
337355
+ name: config41.childElementName,
337356
+ attributes: { "w:type": "separator", "w:id": "-1" },
337357
+ elements: [
337358
+ {
337359
+ type: "element",
337360
+ name: "w:p",
337361
+ elements: [
337362
+ {
337363
+ type: "element",
337364
+ name: "w:r",
337365
+ elements: [{ type: "element", name: "w:separator", elements: [] }]
337366
+ }
337367
+ ]
337368
+ }
337369
+ ]
337370
+ },
337371
+ {
337372
+ type: "element",
337373
+ name: config41.childElementName,
337374
+ attributes: { "w:type": "continuationSeparator", "w:id": "0" },
337375
+ elements: [
337376
+ {
337377
+ type: "element",
337378
+ name: "w:p",
337379
+ elements: [
337380
+ {
337381
+ type: "element",
337382
+ name: "w:r",
337383
+ elements: [{ type: "element", name: "w:continuationSeparator", elements: [] }]
337384
+ }
337385
+ ]
337386
+ }
337387
+ ]
337388
+ }
337389
+ ]
336707
337390
  }
337391
+ ]
337392
+ };
337393
+ }
337394
+ function createNotePartDescriptor2(config41) {
337395
+ return {
337396
+ id: config41.partId,
337397
+ ensurePart() {
337398
+ return createInitialNotesPart2(config41);
337399
+ },
337400
+ normalizePart(part) {
337401
+ const root4 = getRootElement2(part);
337402
+ if (!root4?.elements)
337403
+ return;
337404
+ root4.elements.sort((a2, b2) => {
337405
+ const aType = a2.attributes?.["w:type"];
337406
+ const bType = b2.attributes?.["w:type"];
337407
+ const aIsSpecial = aType === "separator" || aType === "continuationSeparator";
337408
+ const bIsSpecial = bType === "separator" || bType === "continuationSeparator";
337409
+ if (aIsSpecial !== bIsSpecial)
337410
+ return aIsSpecial ? -1 : 1;
337411
+ const aId = Number(a2.attributes?.["w:id"] ?? 0);
337412
+ const bId = Number(b2.attributes?.["w:id"] ?? 0);
337413
+ return aId - bId;
337414
+ });
337415
+ },
337416
+ afterCommit({ editor, part, source }) {
337417
+ rebuildDerivedCache2(editor, config41, part);
337418
+ clearPartCacheStale2(editor, config41.partId);
337419
+ editor.emit("notes-part-changed", { partId: config41.partId, source });
336708
337420
  }
336709
- incrementRevision2(editor);
336710
- }
336711
- return result.payload;
337421
+ };
336712
337422
  }
336713
- var init_out_of_band_mutation = __esm(() => {
336714
- init_dist7();
336715
- init_y_prosemirror();
336716
- init_revision_tracker();
337423
+ function getNotesConfig2(type) {
337424
+ return type === "endnote" ? ENDNOTES_CONFIG2 : FOOTNOTES_CONFIG2;
337425
+ }
337426
+ function bootstrapNotesPart2(editor, type) {
337427
+ const converter = editor.converter;
337428
+ if (!converter?.convertedXml)
337429
+ return;
337430
+ const config41 = getNotesConfig2(type);
337431
+ if (converter.convertedXml[config41.partId] !== undefined)
337432
+ return;
337433
+ converter.convertedXml[config41.partId] = createInitialNotesPart2(config41);
337434
+ }
337435
+ var FOOTNOTES_PART_ID2 = "word/footnotes.xml", ENDNOTES_PART_ID2 = "word/endnotes.xml", FOOTNOTES_CONFIG2, ENDNOTES_CONFIG2, NOTES_XMLNS2, footnotesPartDescriptor2, endnotesPartDescriptor2;
337436
+ var init_notes_part_descriptor = __esm(() => {
337437
+ init_cache_staleness();
337438
+ FOOTNOTES_CONFIG2 = {
337439
+ partId: FOOTNOTES_PART_ID2,
337440
+ rootElementName: "w:footnotes",
337441
+ childElementName: "w:footnote",
337442
+ converterKey: "footnotes"
337443
+ };
337444
+ ENDNOTES_CONFIG2 = {
337445
+ partId: ENDNOTES_PART_ID2,
337446
+ rootElementName: "w:endnotes",
337447
+ childElementName: "w:endnote",
337448
+ converterKey: "endnotes"
337449
+ };
337450
+ NOTES_XMLNS2 = {
337451
+ "xmlns:wpc": "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas",
337452
+ "xmlns:mc": "http://schemas.openxmlformats.org/markup-compatibility/2006",
337453
+ "xmlns:o": "urn:schemas-microsoft-com:office:office",
337454
+ "xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
337455
+ "xmlns:m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
337456
+ "xmlns:v": "urn:schemas-microsoft-com:vml",
337457
+ "xmlns:wp14": "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing",
337458
+ "xmlns:wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
337459
+ "xmlns:w10": "urn:schemas-microsoft-com:office:word",
337460
+ "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
337461
+ "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
337462
+ "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
337463
+ "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
337464
+ "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
337465
+ "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
337466
+ };
337467
+ footnotesPartDescriptor2 = createNotePartDescriptor2(FOOTNOTES_CONFIG2);
337468
+ endnotesPartDescriptor2 = createNotePartDescriptor2(ENDNOTES_CONFIG2);
336717
337469
  });
336718
337470
 
336719
337471
  // ../../packages/super-editor/src/document-api-adapters/plan-engine/footnote-wrappers.ts
@@ -336726,37 +337478,12 @@ function footnoteFailure2(code10, message) {
336726
337478
  function configSuccess2() {
336727
337479
  return { success: true };
336728
337480
  }
336729
- function receiptApplied6(receipt2) {
336730
- return receipt2.steps[0]?.effect === "changed";
336731
- }
336732
- function isLegacyNoteMap2(value) {
336733
- return value != null && typeof value === "object" && !Array.isArray(value);
336734
- }
336735
- function textToFootnoteContentNodes2(text9) {
336736
- const lines = text9.split(/\r?\n/);
336737
- return lines.map((line) => ({
336738
- type: "paragraph",
336739
- content: line.length > 0 ? [{ type: "text", text: line }] : []
336740
- }));
336741
- }
336742
- function normalizeLegacyNoteMap2(map10) {
336743
- return Object.entries(map10).map(([id2, value]) => ({
336744
- id: String(id2),
336745
- content: textToFootnoteContentNodes2(value?.content ?? "")
336746
- }));
336747
- }
336748
- function ensureNoteEntries2(converter, kind) {
336749
- const current = converter[kind];
336750
- if (Array.isArray(current))
336751
- return current;
336752
- if (isLegacyNoteMap2(current)) {
336753
- const normalized = normalizeLegacyNoteMap2(current);
336754
- converter[kind] = normalized;
336755
- return normalized;
337481
+ function getConverter15(editor) {
337482
+ const converter = editor.converter;
337483
+ if (!converter) {
337484
+ throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", "converter not available.");
336756
337485
  }
336757
- const initialized = [];
336758
- converter[kind] = initialized;
336759
- return initialized;
337486
+ return converter;
336760
337487
  }
336761
337488
  function toNonNegativeInteger2(value) {
336762
337489
  const num = Number(value);
@@ -336764,35 +337491,38 @@ function toNonNegativeInteger2(value) {
336764
337491
  return null;
336765
337492
  return num;
336766
337493
  }
336767
- function allocateNextNoteId2(editor, type, entries) {
336768
- let maxId = 0;
337494
+ function collectUsedNoteIds2(editor, converter, type) {
337495
+ const used = new Set;
337496
+ const config41 = getNotesConfig2(type);
336769
337497
  for (const ref4 of findAllFootnotes2(editor.state.doc, type)) {
336770
337498
  const parsed = toNonNegativeInteger2(ref4.noteId);
336771
337499
  if (parsed != null)
336772
- maxId = Math.max(maxId, parsed);
337500
+ used.add(parsed);
336773
337501
  }
336774
- for (const entry of entries) {
336775
- const parsed = toNonNegativeInteger2(entry.id);
336776
- if (parsed != null)
336777
- maxId = Math.max(maxId, parsed);
337502
+ const ooxmlPart = converter.convertedXml?.[config41.partId];
337503
+ if (ooxmlPart) {
337504
+ for (const el of getNoteElements2(ooxmlPart, config41.childElementName)) {
337505
+ const parsed = toNonNegativeInteger2(el.attributes?.["w:id"]);
337506
+ if (parsed != null)
337507
+ used.add(parsed);
337508
+ }
336778
337509
  }
336779
- return String(maxId + 1);
336780
- }
336781
- function upsertNoteEntry2(entries, noteId, content5) {
336782
- const existing = entries.find((entry) => String(entry.id) === noteId);
336783
- if (existing) {
336784
- existing.content = textToFootnoteContentNodes2(content5);
336785
- return;
337510
+ const cache2 = converter[config41.converterKey];
337511
+ if (Array.isArray(cache2)) {
337512
+ for (const entry of cache2) {
337513
+ const parsed = toNonNegativeInteger2(entry.id);
337514
+ if (parsed != null)
337515
+ used.add(parsed);
337516
+ }
336786
337517
  }
336787
- entries.push({
336788
- id: noteId,
336789
- content: textToFootnoteContentNodes2(content5)
336790
- });
337518
+ return used;
336791
337519
  }
336792
- function removeNoteEntry2(entries, noteId) {
336793
- const index3 = entries.findIndex((entry) => String(entry.id) === noteId);
336794
- if (index3 >= 0)
336795
- entries.splice(index3, 1);
337520
+ function allocateNextNoteId2(editor, converter, type) {
337521
+ const used = collectUsedNoteIds2(editor, converter, type);
337522
+ let candidate = 1;
337523
+ while (used.has(candidate))
337524
+ candidate += 1;
337525
+ return String(candidate);
336796
337526
  }
336797
337527
  function footnotesListWrapper2(editor, query2) {
336798
337528
  const doc4 = editor.state.doc;
@@ -336814,13 +337544,10 @@ function footnotesGetWrapper2(editor, input2) {
336814
337544
  }
336815
337545
  function footnotesInsertWrapper2(editor, input2, options) {
336816
337546
  rejectTrackedMode2("footnotes.insert", options);
336817
- const converter = editor.converter;
336818
- if (!converter) {
336819
- throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", "footnotes.insert: converter not available.");
336820
- }
336821
- const noteStoreKey = input2.type === "endnote" ? "endnotes" : "footnotes";
336822
- const noteEntries = ensureNoteEntries2(converter, noteStoreKey);
336823
- const noteId = allocateNextNoteId2(editor, input2.type, noteEntries);
337547
+ checkRevision2(editor, options?.expectedRevision);
337548
+ const converter = getConverter15(editor);
337549
+ const notesConfig = getNotesConfig2(input2.type);
337550
+ const noteId = allocateNextNoteId2(editor, converter, input2.type);
336824
337551
  const address2 = { kind: "entity", entityType: "footnote", noteId };
336825
337552
  if (options?.dryRun) {
336826
337553
  return footnoteSuccess2(address2);
@@ -336831,16 +337558,30 @@ function footnotesInsertWrapper2(editor, input2, options) {
336831
337558
  throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", `footnotes.insert: node type "${nodeTypeName}" is not registered in the schema.`);
336832
337559
  }
336833
337560
  const resolved = resolveInlineInsertPosition2(editor, input2.at, "footnotes.insert");
336834
- const receipt2 = executeDomainCommand2(editor, () => {
336835
- const node4 = nodeType.create({ id: noteId });
336836
- const { tr } = editor.state;
336837
- tr.insert(resolved.from, node4);
336838
- editor.dispatch(tr);
336839
- upsertNoteEntry2(noteEntries, noteId, input2.content);
336840
- clearIndexCache2(editor);
336841
- return true;
336842
- }, { expectedRevision: options?.expectedRevision });
336843
- if (!receiptApplied6(receipt2)) {
337561
+ const { success } = compoundMutation2({
337562
+ editor,
337563
+ source: `footnotes.insert:${input2.type}`,
337564
+ affectedParts: [notesConfig.partId],
337565
+ execute: () => {
337566
+ bootstrapNotesPart2(editor, input2.type);
337567
+ mutatePart2({
337568
+ editor,
337569
+ partId: notesConfig.partId,
337570
+ operation: "mutate",
337571
+ source: `footnotes.insert:${input2.type}`,
337572
+ mutate({ part }) {
337573
+ addNoteElement2(part, notesConfig, noteId, input2.content);
337574
+ }
337575
+ });
337576
+ const node4 = nodeType.create({ id: noteId });
337577
+ const { tr } = editor.state;
337578
+ tr.insert(resolved.from, node4);
337579
+ editor.dispatch(tr);
337580
+ clearIndexCache2(editor);
337581
+ return true;
337582
+ }
337583
+ });
337584
+ if (!success) {
336844
337585
  return footnoteFailure2("NO_OP", "Insert operation produced no change.");
336845
337586
  }
336846
337587
  return footnoteSuccess2(address2);
@@ -336849,100 +337590,140 @@ function footnotesUpdateWrapper2(editor, input2, options) {
336849
337590
  rejectTrackedMode2("footnotes.update", options);
336850
337591
  const resolved = resolveFootnoteTarget2(editor.state.doc, input2.target);
336851
337592
  const address2 = { kind: "entity", entityType: "footnote", noteId: resolved.noteId };
336852
- if (options?.dryRun) {
337593
+ if (options?.dryRun || input2.patch.content === undefined) {
336853
337594
  return footnoteSuccess2(address2);
336854
337595
  }
336855
- const converter = editor.converter;
336856
- if (!converter) {
336857
- throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", "footnotes.update: converter not available.");
336858
- }
336859
- const noteStoreKey = resolved.type === "footnote" ? "footnotes" : "endnotes";
336860
- const noteEntries = ensureNoteEntries2(converter, noteStoreKey);
336861
- executeOutOfBandMutation2(editor, (dryRun) => {
336862
- if (input2.patch.content === undefined) {
336863
- return { changed: false, payload: undefined };
336864
- }
336865
- if (!dryRun) {
336866
- upsertNoteEntry2(noteEntries, resolved.noteId, input2.patch.content);
337596
+ const notesConfig = getNotesConfig2(resolved.type);
337597
+ mutatePart2({
337598
+ editor,
337599
+ partId: notesConfig.partId,
337600
+ operation: "mutate",
337601
+ source: `footnotes.update:${resolved.type}`,
337602
+ expectedRevision: options?.expectedRevision,
337603
+ mutate({ part }) {
337604
+ updateNoteElement2(part, notesConfig, resolved.noteId, input2.patch.content);
336867
337605
  }
336868
- return { changed: true, payload: undefined };
336869
- }, { dryRun: options?.dryRun ?? false, expectedRevision: options?.expectedRevision });
337606
+ });
336870
337607
  return footnoteSuccess2(address2);
336871
337608
  }
336872
337609
  function footnotesRemoveWrapper2(editor, input2, options) {
336873
337610
  rejectTrackedMode2("footnotes.remove", options);
337611
+ checkRevision2(editor, options?.expectedRevision);
336874
337612
  const resolved = resolveFootnoteTarget2(editor.state.doc, input2.target);
336875
337613
  const address2 = { kind: "entity", entityType: "footnote", noteId: resolved.noteId };
336876
337614
  if (options?.dryRun) {
336877
337615
  return footnoteSuccess2(address2);
336878
337616
  }
336879
- const receipt2 = executeDomainCommand2(editor, () => {
336880
- const { tr } = editor.state;
336881
- const node4 = tr.doc.nodeAt(resolved.pos);
336882
- if (node4) {
337617
+ const notesConfig = getNotesConfig2(resolved.type);
337618
+ const { success } = compoundMutation2({
337619
+ editor,
337620
+ source: `footnotes.remove:${resolved.type}`,
337621
+ affectedParts: [notesConfig.partId],
337622
+ execute: () => {
337623
+ const { tr } = editor.state;
337624
+ const node4 = tr.doc.nodeAt(resolved.pos);
337625
+ if (!node4)
337626
+ return false;
336883
337627
  tr.delete(resolved.pos, resolved.pos + node4.nodeSize);
336884
337628
  editor.dispatch(tr);
336885
- const converter = editor.converter;
336886
- if (converter) {
336887
- const noteStoreKey = resolved.type === "footnote" ? "footnotes" : "endnotes";
336888
- const noteEntries = ensureNoteEntries2(converter, noteStoreKey);
336889
- const stillReferenced = findAllFootnotes2(editor.state.doc, resolved.type).some((f2) => f2.noteId === resolved.noteId);
336890
- if (!stillReferenced) {
336891
- removeNoteEntry2(noteEntries, resolved.noteId);
336892
- }
337629
+ const stillReferenced = findAllFootnotes2(editor.state.doc, resolved.type).some((f2) => f2.noteId === resolved.noteId);
337630
+ if (!stillReferenced) {
337631
+ mutatePart2({
337632
+ editor,
337633
+ partId: notesConfig.partId,
337634
+ operation: "mutate",
337635
+ source: `footnotes.remove:${resolved.type}`,
337636
+ mutate({ part }) {
337637
+ removeNoteElement2(part, notesConfig, resolved.noteId);
337638
+ }
337639
+ });
336893
337640
  }
336894
337641
  clearIndexCache2(editor);
336895
337642
  return true;
336896
337643
  }
336897
- return false;
336898
- }, { expectedRevision: options?.expectedRevision });
336899
- if (!receiptApplied6(receipt2)) {
337644
+ });
337645
+ if (!success) {
336900
337646
  return footnoteFailure2("NO_OP", "Remove operation produced no change.");
336901
337647
  }
336902
337648
  return footnoteSuccess2(address2);
336903
337649
  }
336904
337650
  function footnotesConfigureWrapper2(editor, input2, options) {
336905
337651
  rejectTrackedMode2("footnotes.configure", options);
336906
- const converter = editor.converter;
336907
- if (!converter) {
336908
- throw new DocumentApiAdapterError3("CAPABILITY_UNAVAILABLE", "footnotes.configure: converter not available.");
336909
- }
336910
- executeOutOfBandMutation2(editor, (dryRun) => {
336911
- if (dryRun)
336912
- return { changed: true, payload: undefined };
336913
- if (!converter.footnoteProperties) {
336914
- converter.footnoteProperties = { source: "settings" };
336915
- }
336916
- const props = converter.footnoteProperties;
336917
- if (input2.numbering) {
336918
- if (input2.numbering.format !== undefined)
336919
- props.numFmt = input2.numbering.format;
336920
- if (input2.numbering.start !== undefined)
336921
- props.numStart = String(input2.numbering.start);
337652
+ const prElementName = input2.type === "endnote" ? "w:endnotePr" : "w:footnotePr";
337653
+ mutatePart2({
337654
+ editor,
337655
+ partId: "word/settings.xml",
337656
+ operation: "mutate",
337657
+ source: `footnotes.configure:${input2.type}`,
337658
+ dryRun: options?.dryRun,
337659
+ expectedRevision: options?.expectedRevision,
337660
+ mutate({ part }) {
337661
+ const root4 = part?.elements?.[0];
337662
+ if (!root4)
337663
+ return;
337664
+ if (!root4.elements)
337665
+ root4.elements = [];
337666
+ const elements = root4.elements;
337667
+ let prElement = elements.find((el) => el.name === prElementName);
337668
+ if (!prElement) {
337669
+ prElement = { type: "element", name: prElementName, elements: [] };
337670
+ elements.push(prElement);
337671
+ }
337672
+ if (!prElement.elements)
337673
+ prElement.elements = [];
337674
+ if (!input2.numbering)
337675
+ return;
337676
+ const setOrRemoveChild = (name, value) => {
337677
+ if (value === undefined)
337678
+ return;
337679
+ const children = prElement.elements;
337680
+ const existing = children.findIndex((el) => el.name === name);
337681
+ const newEl = { type: "element", name, attributes: { "w:val": value } };
337682
+ if (existing >= 0) {
337683
+ children[existing] = newEl;
337684
+ } else {
337685
+ children.push(newEl);
337686
+ }
337687
+ };
337688
+ setOrRemoveChild("w:numFmt", input2.numbering.format);
337689
+ setOrRemoveChild("w:numStart", input2.numbering.start !== undefined ? String(input2.numbering.start) : undefined);
336922
337690
  if (input2.numbering.restartPolicy !== undefined) {
336923
- props.numRestart = RESTART_POLICY_TO_OOXML2[input2.numbering.restartPolicy] ?? input2.numbering.restartPolicy;
337691
+ setOrRemoveChild("w:numRestart", RESTART_POLICY_TO_OOXML2[input2.numbering.restartPolicy] ?? input2.numbering.restartPolicy);
336924
337692
  }
336925
- if (input2.numbering.position !== undefined)
336926
- props.pos = input2.numbering.position;
337693
+ setOrRemoveChild("w:pos", input2.numbering.position);
336927
337694
  }
336928
- props.noteType = input2.type;
336929
- if (input2.scope)
336930
- props.scope = input2.scope;
336931
- return { changed: true, payload: undefined };
336932
- }, { dryRun: options?.dryRun ?? false, expectedRevision: options?.expectedRevision });
337695
+ });
337696
+ if (!options?.dryRun && prElementName === "w:footnotePr") {
337697
+ syncFootnotePropertiesCache2(editor);
337698
+ }
336933
337699
  return configSuccess2();
336934
337700
  }
337701
+ function syncFootnotePropertiesCache2(editor) {
337702
+ const converter = getConverter15(editor);
337703
+ if (!converter?.footnoteProperties || converter.footnoteProperties.source !== "settings")
337704
+ return;
337705
+ const settingsPart = converter.convertedXml?.["word/settings.xml"];
337706
+ const settingsRoot = settingsPart?.elements?.[0];
337707
+ const elements = settingsRoot?.elements ?? [];
337708
+ const prElement = elements.find((el) => el.name === "w:footnotePr");
337709
+ if (prElement) {
337710
+ converter.footnoteProperties.originalXml = structuredClone(prElement);
337711
+ } else {
337712
+ converter.footnoteProperties = null;
337713
+ }
337714
+ }
336935
337715
  var RESTART_POLICY_TO_OOXML2;
336936
337716
  var init_footnote_wrappers = __esm(() => {
336937
337717
  init_src();
336938
337718
  init_footnote_resolver();
336939
337719
  init_adapter_utils();
336940
337720
  init_revision_tracker();
336941
- init_plan_wrappers();
336942
337721
  init_mutation_helpers();
336943
337722
  init_index_cache();
336944
- init_out_of_band_mutation();
336945
337723
  init_errors3();
337724
+ init_mutate_part();
337725
+ init_compound_mutation();
337726
+ init_notes_part_descriptor();
336946
337727
  RESTART_POLICY_TO_OOXML2 = {
336947
337728
  continuous: "continuous",
336948
337729
  eachSection: "eachSect",
@@ -337071,7 +337852,7 @@ function crossRefSuccess2(address2) {
337071
337852
  function crossRefFailure2(code10, message) {
337072
337853
  return { success: false, failure: { code: code10, message } };
337073
337854
  }
337074
- function receiptApplied7(receipt2) {
337855
+ function receiptApplied6(receipt2) {
337075
337856
  return receipt2.steps[0]?.effect === "changed";
337076
337857
  }
337077
337858
  function crossRefsListWrapper2(editor, query2) {
@@ -337122,7 +337903,7 @@ function crossRefsInsertWrapper2(editor, input2, options) {
337122
337903
  clearIndexCache2(editor);
337123
337904
  return true;
337124
337905
  }, { expectedRevision: options?.expectedRevision });
337125
- if (!receiptApplied7(receipt2))
337906
+ if (!receiptApplied6(receipt2))
337126
337907
  return crossRefFailure2("NO_OP", "Insert produced no change.");
337127
337908
  return crossRefSuccess2(computeInlineAddress2(editor.state.doc, resolved.from));
337128
337909
  }
@@ -337147,7 +337928,7 @@ function crossRefsRemoveWrapper2(editor, input2, options) {
337147
337928
  clearIndexCache2(editor);
337148
337929
  return true;
337149
337930
  }, { expectedRevision: options?.expectedRevision });
337150
- if (!receiptApplied7(receipt2))
337931
+ if (!receiptApplied6(receipt2))
337151
337932
  return crossRefFailure2("NO_OP", "Remove produced no change.");
337152
337933
  return crossRefSuccess2(address2);
337153
337934
  }
@@ -337436,7 +338217,7 @@ function entrySuccess3(address2) {
337436
338217
  function entryFailure3(code10, message) {
337437
338218
  return { success: false, failure: { code: code10, message } };
337438
338219
  }
337439
- function receiptApplied8(receipt2) {
338220
+ function receiptApplied7(receipt2) {
337440
338221
  return receipt2.steps[0]?.effect === "changed";
337441
338222
  }
337442
338223
  function indexListWrapper2(editor, query2) {
@@ -337477,7 +338258,7 @@ function indexInsertWrapper2(editor, input2, options) {
337477
338258
  clearIndexCache2(editor);
337478
338259
  return true;
337479
338260
  }, { expectedRevision: options?.expectedRevision });
337480
- if (!receiptApplied8(receipt2))
338261
+ if (!receiptApplied7(receipt2))
337481
338262
  return indexFailure2("NO_OP", "Insert produced no change.");
337482
338263
  const insertedNode = editor.state.doc.nodeAt(pos);
337483
338264
  const resolvedNodeId = insertedNode?.attrs?.sdBlockId ?? `index-${pos}`;
@@ -337509,7 +338290,7 @@ function indexConfigureWrapper2(editor, input2, options) {
337509
338290
  clearIndexCache2(editor);
337510
338291
  return true;
337511
338292
  }, { expectedRevision: options?.expectedRevision });
337512
- if (!receiptApplied8(receipt2))
338293
+ if (!receiptApplied7(receipt2))
337513
338294
  return indexFailure2("NO_OP", "Configure produced no change.");
337514
338295
  return indexSuccess2(address2);
337515
338296
  }
@@ -337534,7 +338315,7 @@ function indexRemoveWrapper2(editor, input2, options) {
337534
338315
  clearIndexCache2(editor);
337535
338316
  return true;
337536
338317
  }, { expectedRevision: options?.expectedRevision });
337537
- if (!receiptApplied8(receipt2))
338318
+ if (!receiptApplied7(receipt2))
337538
338319
  return indexFailure2("NO_OP", "Remove produced no change.");
337539
338320
  return indexSuccess2(address2);
337540
338321
  }
@@ -337589,7 +338370,7 @@ function indexEntriesInsertWrapper2(editor, input2, options) {
337589
338370
  clearIndexCache2(editor);
337590
338371
  return true;
337591
338372
  }, { expectedRevision: options?.expectedRevision });
337592
- if (!receiptApplied8(receipt2))
338373
+ if (!receiptApplied7(receipt2))
337593
338374
  return entryFailure3("NO_OP", "Insert produced no change.");
337594
338375
  const insertedAddress = resolveInsertedIndexEntryAddress2(editor.state.doc, resolved.from, instruction);
337595
338376
  return entrySuccess3(insertedAddress);
@@ -337626,7 +338407,7 @@ function indexEntriesUpdateWrapper2(editor, input2, options) {
337626
338407
  clearIndexCache2(editor);
337627
338408
  return true;
337628
338409
  }, { expectedRevision: options?.expectedRevision });
337629
- if (!receiptApplied8(receipt2))
338410
+ if (!receiptApplied7(receipt2))
337630
338411
  return entryFailure3("NO_OP", "Update produced no change.");
337631
338412
  return entrySuccess3(address2);
337632
338413
  }
@@ -337643,7 +338424,7 @@ function indexEntriesRemoveWrapper2(editor, input2, options) {
337643
338424
  clearIndexCache2(editor);
337644
338425
  return true;
337645
338426
  }, { expectedRevision: options?.expectedRevision });
337646
- if (!receiptApplied8(receipt2))
338427
+ if (!receiptApplied7(receipt2))
337647
338428
  return entryFailure3("NO_OP", "Remove produced no change.");
337648
338429
  return entrySuccess3(address2);
337649
338430
  }
@@ -337919,7 +338700,7 @@ function configSuccess3() {
337919
338700
  function configFailure2(code10, message) {
337920
338701
  return { success: false, failure: { code: code10, message } };
337921
338702
  }
337922
- function receiptApplied9(receipt2) {
338703
+ function receiptApplied8(receipt2) {
337923
338704
  return receipt2.steps[0]?.effect === "changed";
337924
338705
  }
337925
338706
  function buildCaptionParagraphAttrs2(nodeId) {
@@ -337978,7 +338759,7 @@ function captionsInsertWrapper2(editor, input2, options) {
337978
338759
  clearIndexCache2(editor);
337979
338760
  return true;
337980
338761
  }, { expectedRevision: options?.expectedRevision });
337981
- if (!receiptApplied9(receipt2))
338762
+ if (!receiptApplied8(receipt2))
337982
338763
  return captionFailure2("NO_OP", "Insert produced no change.");
337983
338764
  return captionSuccess2(address2);
337984
338765
  }
@@ -338013,7 +338794,7 @@ function captionsUpdateWrapper2(editor, input2, options) {
338013
338794
  clearIndexCache2(editor);
338014
338795
  return true;
338015
338796
  }, { expectedRevision: options?.expectedRevision });
338016
- if (!receiptApplied9(receipt2))
338797
+ if (!receiptApplied8(receipt2))
338017
338798
  return captionFailure2("NO_OP", "Update produced no change.");
338018
338799
  return captionSuccess2(address2);
338019
338800
  }
@@ -338030,7 +338811,7 @@ function captionsRemoveWrapper2(editor, input2, options) {
338030
338811
  clearIndexCache2(editor);
338031
338812
  return true;
338032
338813
  }, { expectedRevision: options?.expectedRevision });
338033
- if (!receiptApplied9(receipt2))
338814
+ if (!receiptApplied8(receipt2))
338034
338815
  return captionFailure2("NO_OP", "Remove produced no change.");
338035
338816
  return captionSuccess2(address2);
338036
338817
  }
@@ -338062,7 +338843,7 @@ function captionsConfigureWrapper2(editor, input2, options) {
338062
338843
  clearIndexCache2(editor);
338063
338844
  return true;
338064
338845
  }, { expectedRevision: options?.expectedRevision });
338065
- if (!receiptApplied9(receipt2))
338846
+ if (!receiptApplied8(receipt2))
338066
338847
  return configFailure2("NO_OP", "Configure produced no change.");
338067
338848
  return configSuccess3();
338068
338849
  }
@@ -338194,7 +338975,7 @@ function fieldSuccess2(address2) {
338194
338975
  function fieldFailure2(code10, message) {
338195
338976
  return { success: false, failure: { code: code10, message } };
338196
338977
  }
338197
- function receiptApplied10(receipt2) {
338978
+ function receiptApplied9(receipt2) {
338198
338979
  return receipt2.steps[0]?.effect === "changed";
338199
338980
  }
338200
338981
  function fieldsListWrapper2(editor, query2) {
@@ -338248,7 +339029,7 @@ function fieldsInsertWrapper2(editor, input2, options) {
338248
339029
  clearIndexCache2(editor);
338249
339030
  return true;
338250
339031
  }, { expectedRevision: options?.expectedRevision });
338251
- if (!receiptApplied10(receipt2))
339032
+ if (!receiptApplied9(receipt2))
338252
339033
  return fieldFailure2("NO_OP", "Insert produced no change.");
338253
339034
  return fieldSuccess2(computeFieldAddress2(editor.state.doc, resolved.from));
338254
339035
  }
@@ -338276,7 +339057,7 @@ function fieldsRebuildWrapper2(editor, input2, options) {
338276
339057
  clearIndexCache2(editor);
338277
339058
  return true;
338278
339059
  }, { expectedRevision: options?.expectedRevision });
338279
- if (!receiptApplied10(receipt2))
339060
+ if (!receiptApplied9(receipt2))
338280
339061
  return fieldFailure2("NO_OP", "Rebuild produced no change.");
338281
339062
  return fieldSuccess2(address2);
338282
339063
  }
@@ -338304,7 +339085,7 @@ function fieldsRemoveWrapper2(editor, input2, options) {
338304
339085
  clearIndexCache2(editor);
338305
339086
  return true;
338306
339087
  }, { expectedRevision: options?.expectedRevision });
338307
- if (!receiptApplied10(receipt2))
339088
+ if (!receiptApplied9(receipt2))
338308
339089
  return fieldFailure2("NO_OP", "Remove produced no change.");
338309
339090
  return fieldSuccess2(address2);
338310
339091
  }
@@ -338479,6 +339260,39 @@ var init_citation_resolver = __esm(() => {
338479
339260
  init_errors3();
338480
339261
  });
338481
339262
 
339263
+ // ../../packages/super-editor/src/document-api-adapters/out-of-band-mutation.ts
339264
+ function executeOutOfBandMutation2(editor, mutateFn, options) {
339265
+ if (!options.dryRun) {
339266
+ if (editor.options?.collaborationProvider && editor.options?.ydoc) {
339267
+ try {
339268
+ yUndoPluginKey2.getState(editor.state)?.undoManager?.stopCapturing();
339269
+ } catch {}
339270
+ } else {
339271
+ try {
339272
+ editor.view?.dispatch?.(closeHistory2(editor.state.tr));
339273
+ } catch {}
339274
+ }
339275
+ }
339276
+ checkRevision2(editor, options.expectedRevision);
339277
+ const result = mutateFn(options.dryRun);
339278
+ if (result.changed && !options.dryRun) {
339279
+ const converter = editor.converter;
339280
+ if (converter) {
339281
+ converter.documentModified = true;
339282
+ if (!converter.documentGuid && typeof converter.promoteToGuid === "function") {
339283
+ converter.promoteToGuid();
339284
+ }
339285
+ }
339286
+ incrementRevision2(editor);
339287
+ }
339288
+ return result.payload;
339289
+ }
339290
+ var init_out_of_band_mutation = __esm(() => {
339291
+ init_dist7();
339292
+ init_y_prosemirror();
339293
+ init_revision_tracker();
339294
+ });
339295
+
338482
339296
  // ../../packages/super-editor/src/document-api-adapters/plan-engine/citation-wrappers.ts
338483
339297
  function citationSuccess2(address2) {
338484
339298
  return { success: true, citation: address2 };
@@ -338498,7 +339312,7 @@ function bibSuccess2(address2) {
338498
339312
  function bibFailure2(code10, message) {
338499
339313
  return { success: false, failure: { code: code10, message } };
338500
339314
  }
338501
- function receiptApplied11(receipt2) {
339315
+ function receiptApplied10(receipt2) {
338502
339316
  return receipt2.steps[0]?.effect === "changed";
338503
339317
  }
338504
339318
  function citationsListWrapper2(editor, query2) {
@@ -338546,7 +339360,7 @@ function citationsInsertWrapper2(editor, input2, options) {
338546
339360
  clearIndexCache2(editor);
338547
339361
  return true;
338548
339362
  }, { expectedRevision: options?.expectedRevision });
338549
- if (!receiptApplied11(receipt2))
339363
+ if (!receiptApplied10(receipt2))
338550
339364
  return citationFailure2("NO_OP", "Insert produced no change.");
338551
339365
  const insertedAddress = resolveInsertedCitationAddress2(editor.state.doc, resolved.from, input2.sourceIds);
338552
339366
  return citationSuccess2(insertedAddress);
@@ -338570,7 +339384,7 @@ function citationsUpdateWrapper2(editor, input2, options) {
338570
339384
  clearIndexCache2(editor);
338571
339385
  return true;
338572
339386
  }, { expectedRevision: options?.expectedRevision });
338573
- if (!receiptApplied11(receipt2))
339387
+ if (!receiptApplied10(receipt2))
338574
339388
  return citationFailure2("NO_OP", "Update produced no change.");
338575
339389
  return citationSuccess2(address2);
338576
339390
  }
@@ -338587,7 +339401,7 @@ function citationsRemoveWrapper2(editor, input2, options) {
338587
339401
  clearIndexCache2(editor);
338588
339402
  return true;
338589
339403
  }, { expectedRevision: options?.expectedRevision });
338590
- if (!receiptApplied11(receipt2))
339404
+ if (!receiptApplied10(receipt2))
338591
339405
  return citationFailure2("NO_OP", "Remove produced no change.");
338592
339406
  return citationSuccess2(address2);
338593
339407
  }
@@ -338696,7 +339510,7 @@ function bibliographyInsertWrapper2(editor, input2, options) {
338696
339510
  clearIndexCache2(editor);
338697
339511
  return true;
338698
339512
  }, { expectedRevision: options?.expectedRevision });
338699
- if (!receiptApplied11(receipt2))
339513
+ if (!receiptApplied10(receipt2))
338700
339514
  return bibFailure2("NO_OP", "Insert produced no change.");
338701
339515
  return bibSuccess2(address2);
338702
339516
  }
@@ -338728,7 +339542,7 @@ function bibliographyConfigureWrapper2(editor, input2, options) {
338728
339542
  clearIndexCache2(editor);
338729
339543
  return true;
338730
339544
  }, { expectedRevision: options?.expectedRevision });
338731
- if (!receiptApplied11(receipt2))
339545
+ if (!receiptApplied10(receipt2))
338732
339546
  return bibFailure2("NO_OP", "Configure produced no change.");
338733
339547
  return bibSuccess2(address2);
338734
339548
  }
@@ -338753,7 +339567,7 @@ function bibliographyRemoveWrapper2(editor, input2, options) {
338753
339567
  clearIndexCache2(editor);
338754
339568
  return true;
338755
339569
  }, { expectedRevision: options?.expectedRevision });
338756
- if (!receiptApplied11(receipt2))
339570
+ if (!receiptApplied10(receipt2))
338757
339571
  return bibFailure2("NO_OP", "Remove produced no change.");
338758
339572
  return bibSuccess2(address2);
338759
339573
  }
@@ -339016,7 +339830,7 @@ function entrySuccess4(address2) {
339016
339830
  function entryFailure4(code10, message) {
339017
339831
  return { success: false, failure: { code: code10, message } };
339018
339832
  }
339019
- function receiptApplied12(receipt2) {
339833
+ function receiptApplied11(receipt2) {
339020
339834
  return receipt2.steps[0]?.effect === "changed";
339021
339835
  }
339022
339836
  function authoritiesListWrapper2(editor, query2) {
@@ -339064,7 +339878,7 @@ function authoritiesInsertWrapper2(editor, input2, options) {
339064
339878
  clearIndexCache2(editor);
339065
339879
  return true;
339066
339880
  }, { expectedRevision: options?.expectedRevision });
339067
- if (!receiptApplied12(receipt2))
339881
+ if (!receiptApplied11(receipt2))
339068
339882
  return toaFailure2("NO_OP", "Insert produced no change.");
339069
339883
  const insertedNode = editor.state.doc.nodeAt(pos);
339070
339884
  const resolvedNodeId = insertedNode?.attrs?.sdBlockId ?? `toa-${pos}`;
@@ -339100,7 +339914,7 @@ function authoritiesConfigureWrapper2(editor, input2, options) {
339100
339914
  clearIndexCache2(editor);
339101
339915
  return true;
339102
339916
  }, { expectedRevision: options?.expectedRevision });
339103
- if (!receiptApplied12(receipt2))
339917
+ if (!receiptApplied11(receipt2))
339104
339918
  return toaFailure2("NO_OP", "Configure produced no change.");
339105
339919
  return toaSuccess2(address2);
339106
339920
  }
@@ -339125,7 +339939,7 @@ function authoritiesRemoveWrapper2(editor, input2, options) {
339125
339939
  clearIndexCache2(editor);
339126
339940
  return true;
339127
339941
  }, { expectedRevision: options?.expectedRevision });
339128
- if (!receiptApplied12(receipt2))
339942
+ if (!receiptApplied11(receipt2))
339129
339943
  return toaFailure2("NO_OP", "Remove produced no change.");
339130
339944
  return toaSuccess2(address2);
339131
339945
  }
@@ -339177,7 +339991,7 @@ function authorityEntriesInsertWrapper2(editor, input2, options) {
339177
339991
  clearIndexCache2(editor);
339178
339992
  return true;
339179
339993
  }, { expectedRevision: options?.expectedRevision });
339180
- if (!receiptApplied12(receipt2))
339994
+ if (!receiptApplied11(receipt2))
339181
339995
  return entryFailure4("NO_OP", "Insert produced no change.");
339182
339996
  return entrySuccess4(computeInlineEntryAddress3(editor.state.doc, resolved.from));
339183
339997
  }
@@ -339206,7 +340020,7 @@ function authorityEntriesUpdateWrapper2(editor, input2, options) {
339206
340020
  clearIndexCache2(editor);
339207
340021
  return true;
339208
340022
  }, { expectedRevision: options?.expectedRevision });
339209
- if (!receiptApplied12(receipt2))
340023
+ if (!receiptApplied11(receipt2))
339210
340024
  return entryFailure4("NO_OP", "Update produced no change.");
339211
340025
  return entrySuccess4(address2);
339212
340026
  }
@@ -339223,7 +340037,7 @@ function authorityEntriesRemoveWrapper2(editor, input2, options) {
339223
340037
  clearIndexCache2(editor);
339224
340038
  return true;
339225
340039
  }, { expectedRevision: options?.expectedRevision });
339226
- if (!receiptApplied12(receipt2))
340040
+ if (!receiptApplied11(receipt2))
339227
340041
  return entryFailure4("NO_OP", "Remove produced no change.");
339228
340042
  return entrySuccess4(address2);
339229
340043
  }