@stll/folio-core 0.58.4 → 0.59.0

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 (101) hide show
  1. package/dist/ai-edits/apply.d.ts +11 -12
  2. package/dist/ai-edits/apply.js +179 -168
  3. package/dist/ai-edits/headless.d.ts +15 -13
  4. package/dist/ai-edits/headless.js +40 -13
  5. package/dist/ai-edits/index.d.ts +3 -3
  6. package/dist/ai-edits/newListNumbering.d.ts +3 -9
  7. package/dist/ai-edits/newListNumbering.js +36 -41
  8. package/dist/ai-edits/referenceClassification.d.ts +22 -0
  9. package/dist/ai-edits/referenceClassification.js +21 -0
  10. package/dist/ai-edits/snapshot.js +39 -40
  11. package/dist/ai-edits/types.d.ts +24 -32
  12. package/dist/compare/column-alignment.d.ts +4 -4
  13. package/dist/compare/compare.d.ts +3 -7
  14. package/dist/compare/compare.js +25 -27
  15. package/dist/compare/content-alignment.d.ts +9 -9
  16. package/dist/compare/content-types.d.ts +23 -10
  17. package/dist/compare/content-types.js +14 -0
  18. package/dist/compare/content.d.ts +16 -17
  19. package/dist/compare/content.js +30 -7
  20. package/dist/compare/formatting.d.ts +3 -3
  21. package/dist/compare/import-style-closure.d.ts +22 -0
  22. package/dist/compare/import-style-closure.js +33 -0
  23. package/dist/compare/inserted-resource-snapshot.d.ts +15 -0
  24. package/dist/compare/inserted-resource-snapshot.js +63 -0
  25. package/dist/compare/plan.js +20 -13
  26. package/dist/compare/scenario.js +12 -2
  27. package/dist/compare/style-resources.d.ts +8 -2
  28. package/dist/compare/style-resources.js +63 -14
  29. package/dist/compare/verification.d.ts +15 -3
  30. package/dist/compare/verification.js +47 -8
  31. package/dist/compat/eigenpal.d.ts +4 -4
  32. package/dist/controller/canonicalListRendering.js +13 -22
  33. package/dist/controller/canonicalPublicOperations.js +1 -1
  34. package/dist/controller/canonicalStructure.js +45 -21
  35. package/dist/document-operations.d.ts +4 -9
  36. package/dist/document-operations.js +45 -41
  37. package/dist/docx/attributeRemainder.d.ts +1 -1
  38. package/dist/docx/index.d.ts +1 -1
  39. package/dist/docx/listMarkerComputation.js +9 -14
  40. package/dist/docx/listTemplate.d.ts +22 -0
  41. package/dist/docx/listTemplate.js +40 -0
  42. package/dist/docx/numberingParser.js +2 -2
  43. package/dist/docx/numberingReferenceNormalization.js +3 -3
  44. package/dist/docx/paragraphParser.js +3 -4
  45. package/dist/docx/rezip.js +2 -2
  46. package/dist/docx/server/materializeYjsDocx.js +2 -2
  47. package/dist/docx/server/migrateYjsAttrSchema.js +5 -5
  48. package/dist/generated/text_shaper.js +8 -4
  49. package/dist/generated/text_shaper_bg.wasm +0 -0
  50. package/dist/index.d.ts +4 -4
  51. package/dist/internal/paragraphFormattingSerialization.d.ts +1 -8
  52. package/dist/internal/paragraphFormattingSerialization.js +6 -20
  53. package/dist/layout-bridge/convert/flowConversionShared.d.ts +1 -1
  54. package/dist/layout-bridge/convert/listMarkers.d.ts +1 -2
  55. package/dist/layout-bridge/convert/listMarkers.js +3 -11
  56. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +1 -1
  57. package/dist/layout-bridge/convert/paragraphAttrs.js +8 -4
  58. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +2 -1
  59. package/dist/layout-bridge/convert/toFlowBlocks.js +2 -1
  60. package/dist/markdown/renderParagraph.js +29 -3
  61. package/dist/prosemirror/commands/comments.js +5 -32
  62. package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +7 -1
  63. package/dist/prosemirror/commands/paragraphBookmarkJoin.js +35 -1
  64. package/dist/prosemirror/commands/propertyChangeScope.js +6 -0
  65. package/dist/prosemirror/commands/resolveParagraphProperties.js +10 -5
  66. package/dist/prosemirror/conversion/fromProseDoc.js +23 -9
  67. package/dist/prosemirror/conversion/toProseDoc.js +31 -7
  68. package/dist/prosemirror/extensions/core/ParagraphExtension.js +29 -14
  69. package/dist/prosemirror/extensions/features/ListExtension.js +51 -21
  70. package/dist/prosemirror/listInstanceReferences.js +21 -15
  71. package/dist/prosemirror/listLabels.d.ts +4 -3
  72. package/dist/prosemirror/listLabels.js +18 -51
  73. package/dist/prosemirror/listMarker.d.ts +2 -19
  74. package/dist/prosemirror/listMarker.js +28 -57
  75. package/dist/prosemirror/listNumbering.js +16 -6
  76. package/dist/prosemirror/listRendering.d.ts +4 -3
  77. package/dist/prosemirror/listRendering.js +22 -3
  78. package/dist/prosemirror/listRenderingAttrs.d.ts +2 -1
  79. package/dist/prosemirror/listRenderingAttrs.js +6 -11
  80. package/dist/prosemirror/numberedRefFields.js +9 -5
  81. package/dist/prosemirror/numberingAttr.d.ts +19 -1
  82. package/dist/prosemirror/numberingAttr.js +16 -2
  83. package/dist/prosemirror/paragraphIndentation.js +5 -2
  84. package/dist/prosemirror/paragraphMarkJoin.js +17 -3
  85. package/dist/prosemirror/paragraphPropertyCarry.js +5 -6
  86. package/dist/prosemirror/plugins/transactionInvariants.js +6 -2
  87. package/dist/prosemirror/schema/nodes.d.ts +2 -1
  88. package/dist/prosemirror/selectionState.js +5 -1
  89. package/dist/prosemirror/storyListNumbering.js +11 -12
  90. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -6
  91. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +11 -4
  92. package/dist/prosemirror/styles/resolvedStyleAttrs.js +28 -18
  93. package/dist/prosemirror/yjsDocumentMetadata.d.ts +9 -3
  94. package/dist/prosemirror/yjsDocumentMetadata.js +42 -10
  95. package/dist/redline.d.ts +17 -1
  96. package/dist/redline.js +118 -57
  97. package/dist/server.d.ts +3 -3
  98. package/dist/server.js +2 -2
  99. package/dist/version-comparison.d.ts +1 -2
  100. package/dist/version-comparison.js +1 -2
  101. package/package.json +4 -3
@@ -60,8 +60,8 @@ type ApplyFolioAIEditOperationsOptions = {
60
60
  tableTemplates?: FolioTableTemplates;
61
61
  /** What a replacement does with a background the text it replaces carries. */
62
62
  replacementBackground?: FolioReplacementBackground;
63
- /** What an operation naming a paragraph style the document does not define does. */
64
- undefinedStyles?: FolioUndefinedStylePolicy;
63
+ /** Policy for undefined style and numbering references; see FolioUndefinedReferencePolicy. */
64
+ undefinedReferences: FolioUndefinedReferencePolicy;
65
65
  };
66
66
  /**
67
67
  * How an apply batch cuts the redline for a replacement. Word-level by
@@ -88,17 +88,16 @@ type FolioWordDiffOptions = {
88
88
  */
89
89
  type FolioReplacementBackground = "clear" | "keep";
90
90
  /**
91
- * What an operation naming a paragraph style the document does not define —
92
- * no `w:style` with that id, or one of another type — does.
91
+ * How operations handle style and numbering references the document does not define.
93
92
  *
94
- * `refuse` is the default: such a `w:pStyle` confers no formatting, so the
95
- * paragraph would keep its body look while the operation reported a restyle;
96
- * the operation is skipped with `missingStyle`. `keep` is for a caller that
97
- * copies references another document already holds — a comparison or redline
98
- * reproducing the revised document, which may itself reference a style it
99
- * never defines — and writes them as given.
93
+ * Editing callers explicitly select `refuse`: an undefined reference would
94
+ * report a formatting edit without changing its appearance. Missing references are skipped with
95
+ * `missingStyle` or `missingNumbering`.
96
+ * Comparison and redline use `keep` for unknown source styles; their import
97
+ * boundary clears destination style collisions with warnings before application.
98
+ * The parser already normalizes undefined source numbering to none.
100
99
  */
101
- type FolioUndefinedStylePolicy = "refuse" | "keep";
100
+ type FolioUndefinedReferencePolicy = "refuse" | "keep";
102
101
  /**
103
102
  * An apply result plus where the batch left the revision-id counter.
104
103
  *
@@ -129,4 +128,4 @@ declare const previewFolioAIEditOperationsWithResult: (options: ApplyFolioAIEdit
129
128
  commentIds: readonly number[];
130
129
  };
131
130
  //#endregion
132
- export { FolioAIEditApplyOutcome, FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioUndefinedStylePolicy, FolioWordDiffOptions, applyFolioAIEditOperations, previewFolioAIEditOperations, previewFolioAIEditOperationsWithResult };
131
+ export { FolioAIEditApplyOutcome, FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioUndefinedReferencePolicy, FolioWordDiffOptions, applyFolioAIEditOperations, previewFolioAIEditOperations, previewFolioAIEditOperationsWithResult };
@@ -1,9 +1,9 @@
1
- import { paragraphNumberingReference, paragraphNumberingReferenceId } from "../docx/numberingReference.js";
2
1
  import { formattingEquals } from "../docx/runConsolidator.js";
3
2
  import { isStyleSourcedParagraphNumbering } from "../internal/paragraphFormattingSerialization.js";
4
3
  import { addTrackedDeletionMark } from "../prosemirror/addTrackedDeletionMark.js";
5
4
  import { deleteTextBoxesAnchoredAt, droppedTextBoxAnchorIds, endOfParagraphWithItsTextBoxes, gatherTextBoxesAfterParagraph, textBoxAnchorIdOf, textBoxAnchorIdsBetween } from "../prosemirror/anchoredTextBoxes.js";
6
5
  import { expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTableRowAttrs, mergeParagraphAttrs } from "../prosemirror/attrs/index.js";
6
+ import { paragraphJoinAfter } from "../prosemirror/commands/paragraphBookmarkJoin.js";
7
7
  import { hasSerializableParagraphPropertyChange, paragraphPropertiesSnapshot } from "../prosemirror/commands/propertyChangeScope.js";
8
8
  import { resolveParagraphChangeAttrs } from "../prosemirror/commands/resolveParagraphProperties.js";
9
9
  import { addedBreakCarrierBefore, finalParagraphsOf, paragraphEndsItsContainer } from "../prosemirror/containerFinalParagraph.js";
@@ -13,7 +13,7 @@ import { requestDeterministicParaIds } from "../prosemirror/extensions/features/
13
13
  import { markStructuralChange } from "../prosemirror/extensions/features/ParagraphChangeTrackerExtension.js";
14
14
  import "../prosemirror/extensions/nodes/TextBoxAnchorExtension.js";
15
15
  import { CLEARED_LIST_RENDERING_ATTRS } from "../prosemirror/listMarker.js";
16
- import { paragraphNumberingAttr, readParagraphNumberingAttr, removedNumberingAttr } from "../prosemirror/numberingAttr.js";
16
+ import { effectiveParagraphNumbering, paragraphNumberingAttr, paragraphNumberingSourcesFromBoundary, readParagraphNumberingAttr, removedNumberingAttr } from "../prosemirror/numberingAttr.js";
17
17
  import { directParagraphAlignment } from "../prosemirror/paragraphAlignment.js";
18
18
  import { styleResolvedParagraphFormatting } from "../prosemirror/paragraphFormattingProvenance.js";
19
19
  import { directParagraphIndentation, paragraphIndentationAttrPatch, paragraphIndentationEqual, paragraphIndentationFromFormatting, withDirectParagraphIndentation } from "../prosemirror/paragraphIndentation.js";
@@ -41,8 +41,9 @@ import { describeCharacterSplit } from "./character-boundaries.js";
41
41
  import { buildCleanBlockText, resolveCleanTextRange } from "./clean-text.js";
42
42
  import { hasInlineEmphasis, parseInlineEmphasisRuns, stripInlineEmphasisMarkers } from "./inline-emphasis.js";
43
43
  import { applyTextChanges, changesFromSegments, keepAtomicSpans, planTextChanges, widenChangesToAtomicSpans } from "./minimal-replacement.js";
44
- import { concreteListReference, resolveNewListOperations } from "./newListNumbering.js";
44
+ import { resolveNewListOperations } from "./newListNumbering.js";
45
45
  import { cutsIntoNoteReference, noteReferenceEditsAllowed, noteReferenceOf, noteReferenceSpansWithin, planChangesAroundNoteReferences, segmentsAroundNoteReferences } from "./note-references.js";
46
+ import { classifyResourceReference } from "./referenceClassification.js";
46
47
  import { separateRevisionStretches } from "./revisionStretches.js";
47
48
  import { collectNoteReferenceLabels, hashFolioAIBlockStructuralBoundaries, hashFolioAIBlockText, isHiddenTableRow, normalizeFolioAIBlockText } from "./snapshot.js";
48
49
  import { isEmptyTableCell, mergeTableRectangle, mergeTrackedVerticalTableCells, splitTableRectangle, splitTrackedVerticalTableCell } from "./table-cell-mutations.js";
@@ -54,7 +55,7 @@ import { wordDiffSessionFromOptions } from "./word-diff.js";
54
55
  import { panic } from "better-result";
55
56
  import { Fragment, Mark } from "prosemirror-model";
56
57
  import { TableMap } from "prosemirror-tables";
57
- import { canJoin, canSplit } from "prosemirror-transform";
58
+ import { canSplit } from "prosemirror-transform";
58
59
  //#region src/ai-edits/apply.ts
59
60
  const coarseWordDiff = (before, after) => {
60
61
  if (before === after) return before.length === 0 ? [] : [{
@@ -179,6 +180,28 @@ const resolveReplaceBlockImpact = ({ changesText, changesStyle }) => {
179
180
  if (changesStyle) return "style";
180
181
  return panic("Cannot resolve a replaceBlock that changes neither text nor style");
181
182
  };
183
+ /** Project exact authored numbering while deriving rendering from its inherited tier. */
184
+ const statedNumberingAttrPatch = ({ attrs, stated, fromStyle, numbering }) => {
185
+ const numPr = stated.kind === "inherit" ? void 0 : paragraphNumberingAttr(stated);
186
+ const numPrFromStyle = numPr?.kind === "reference" || numPr?.kind === "none" ? void 0 : fromStyle;
187
+ const projected = { ...attrs };
188
+ if (numPr === void 0) Reflect.deleteProperty(projected, "numPr");
189
+ else projected.numPr = numPr;
190
+ if (numPrFromStyle === void 0) Reflect.deleteProperty(projected, "numPrFromStyle");
191
+ else projected.numPrFromStyle = numPrFromStyle;
192
+ const effective = effectiveParagraphNumbering(paragraphNumberingSourcesFromBoundary({
193
+ numPr: projected.numPr,
194
+ numPrFromStyle: projected.numPrFromStyle
195
+ }));
196
+ return {
197
+ ...effective?.kind === "reference" ? listLevelAttrPatch(projected, effective.ilvl ?? 0, numbering) : {
198
+ ...listLevelIndentRemovalPatch(attrs, numbering),
199
+ ...CLEARED_LIST_RENDERING_ATTRS
200
+ },
201
+ numPr: numPr ?? null,
202
+ numPrFromStyle: numPrFromStyle ?? null
203
+ };
204
+ };
182
205
  const paragraphPropertiesPatch = ({ node, properties, resolvedFormattingFromStyle, numbering = null }) => {
183
206
  const attrs = expectParagraphAttrs(node);
184
207
  const currentDirectAlignment = directParagraphAlignment(attrs);
@@ -225,51 +248,19 @@ const paragraphPropertiesPatch = ({ node, properties, resolvedFormattingFromStyl
225
248
  patch["outlineLevel"] = directOutlineLevel ?? resolvedFormattingFromStyle?.outlineLevel ?? null;
226
249
  originalFormattingChanged = true;
227
250
  }
228
- const numPrFromStyle = styleChanged ? readParagraphNumberingAttr(patch["numPrFromStyle"]) : attrs.numPrFromStyle;
229
- if (properties.numbering !== void 0) if (properties.numbering === null) {
230
- Object.assign(patch, listLevelIndentRemovalPatch(mergeParagraphAttrs(node, {
231
- ...attrs,
232
- _styleResolvedFormatting: styleResolvedParagraphFormatting(resolvedFormattingFromStyle)
233
- }), numbering));
234
- patch["numPr"] = removedNumberingAttr(numPrFromStyle);
235
- Object.assign(patch, CLEARED_LIST_RENDERING_ATTRS);
236
- } else {
237
- const listReference = concreteListReference(properties.numbering);
238
- Object.assign(patch, listLevelAttrPatch(mergeParagraphAttrs(node, {
239
- ...attrs,
240
- _styleResolvedFormatting: styleResolvedParagraphFormatting(resolvedFormattingFromStyle)
241
- }), {
242
- numId: listReference.numId,
243
- ilvl: listReference.level
244
- }, numbering));
245
- if (properties.listLevel === null) {
246
- patch["numPr"] = paragraphNumberingAttr(paragraphNumberingReference({ numId: listReference.numId }));
247
- patch["numPrFromStyle"] = null;
248
- }
249
- }
250
- else if (properties.listLevel !== void 0) if (properties.listLevel === null) {
251
- Object.assign(patch, listLevelIndentRemovalPatch(mergeParagraphAttrs(node, {
252
- ...attrs,
253
- _styleResolvedFormatting: styleResolvedParagraphFormatting(resolvedFormattingFromStyle)
254
- }), numbering));
255
- patch["numPr"] = removedNumberingAttr(numPrFromStyle);
256
- Object.assign(patch, CLEARED_LIST_RENDERING_ATTRS);
257
- } else {
258
- const numId = paragraphNumberingReferenceId(readParagraphNumberingAttr(styleChanged ? patch["numPr"] : node.attrs["numPr"]) ?? void 0);
259
- if (numId === void 0) {
260
- patch["numPr"] = paragraphNumberingAttr({
261
- kind: "levelOnly",
262
- ilvl: properties.listLevel
263
- });
264
- Object.assign(patch, CLEARED_LIST_RENDERING_ATTRS);
265
- } else Object.assign(patch, listLevelAttrPatch(mergeParagraphAttrs(node, {
251
+ let numPrFromStyle = attrs.numPrFromStyle;
252
+ if (resolvedFormattingFromStyle?.numPr !== void 0) numPrFromStyle = paragraphNumberingAttr(resolvedFormattingFromStyle.numPr);
253
+ else if (styleChanged) numPrFromStyle = readParagraphNumberingAttr(patch["numPrFromStyle"]) ?? void 0;
254
+ if (properties.numbering !== void 0) Object.assign(patch, statedNumberingAttrPatch({
255
+ attrs: mergeParagraphAttrs(node, {
266
256
  ...attrs,
257
+ ...patch,
267
258
  _styleResolvedFormatting: styleResolvedParagraphFormatting(resolvedFormattingFromStyle)
268
- }), {
269
- numId,
270
- ilvl: properties.listLevel
271
- }, numbering));
272
- }
259
+ }),
260
+ stated: properties.numbering,
261
+ fromStyle: numPrFromStyle,
262
+ numbering
263
+ }));
273
264
  if (properties.alignment !== void 0 && (styleChanged || (currentDirectAlignment ?? null) !== properties.alignment)) {
274
265
  originalFormatting ??= {};
275
266
  if (properties.alignment === null) Reflect.deleteProperty(originalFormatting, "alignment");
@@ -297,14 +288,22 @@ const paragraphPropertiesPatch = ({ node, properties, resolvedFormattingFromStyl
297
288
  originalFormattingChanged = true;
298
289
  }
299
290
  if (originalFormattingChanged) patch["_originalFormatting"] = originalFormatting && Object.keys(originalFormatting).length > 0 ? originalFormatting : null;
300
- if (styleChanged || properties.numbering !== void 0 || properties.listLevel !== void 0 || properties.indentation !== void 0) {
291
+ if (styleChanged || properties.numbering !== void 0 || properties.indentation !== void 0) {
301
292
  const nextNumbering = patch["numPr"] === void 0 ? attrs.numPr : readParagraphNumberingAttr(patch["numPr"]);
302
- if (nextNumbering?.kind === "reference") {
293
+ const nextSources = {
294
+ numPr: nextNumbering,
295
+ numPrFromStyle: patch["numPrFromStyle"] === void 0 ? numPrFromStyle : readParagraphNumberingAttr(patch["numPrFromStyle"])
296
+ };
297
+ const effectiveNumbering = effectiveParagraphNumbering(paragraphNumberingSourcesFromBoundary({
298
+ numPr: nextSources.numPr,
299
+ numPrFromStyle: nextSources.numPrFromStyle
300
+ }));
301
+ if (effectiveNumbering?.kind === "reference") {
303
302
  const direct = properties.indentation === void 0 ? currentDirectIndentation : properties.indentation ?? void 0;
304
303
  Object.assign(patch, listLevelAttrPatch(mergeParagraphAttrs(node, {
305
- numPr: nextNumbering,
304
+ numPr: nextNumbering ?? void 0,
306
305
  _styleResolvedFormatting: styleResolvedParagraphFormatting(resolvedFormattingFromStyle),
307
- numPrFromStyle: numPrFromStyle ?? void 0,
306
+ numPrFromStyle: nextSources.numPrFromStyle ?? void 0,
308
307
  listImplicitChildLevelAdvances: attrs.listImplicitChildLevelAdvances,
309
308
  _originalFormatting: withDirectParagraphIndentation(originalFormatting, direct),
310
309
  _resolvedFormatting: withDirectParagraphIndentation(styleChanged ? styleResolvedParagraphFormatting(resolvedFormattingFromStyle) : attrs._resolvedFormatting, resolvedIndentationFromStyle),
@@ -312,11 +311,9 @@ const paragraphPropertiesPatch = ({ node, properties, resolvedFormattingFromStyl
312
311
  indentRight: direct?.indentRight ?? resolvedFormattingFromStyle?.indentRight ?? void 0,
313
312
  indentFirstLine: direct?.indentFirstLine ?? resolvedFormattingFromStyle?.indentFirstLine ?? void 0,
314
313
  hangingIndent: direct?.hangingIndent ?? resolvedFormattingFromStyle?.hangingIndent ?? false
315
- }), {
316
- numId: nextNumbering.numId,
317
- ilvl: nextNumbering.ilvl ?? 0
318
- }, numbering));
319
- patch["numPr"] = nextNumbering;
314
+ }), effectiveNumbering.ilvl ?? 0, numbering));
315
+ patch["numPr"] = nextNumbering ?? null;
316
+ patch["numPrFromStyle"] = nextSources.numPrFromStyle ?? null;
320
317
  }
321
318
  }
322
319
  return Object.keys(patch).length > 0 ? patch : null;
@@ -1976,12 +1973,16 @@ const restyledListAttrs = ({ attrs, styleNumbering, removesNumbering, numbering
1976
1973
  const stated = readParagraphNumberingAttr(attrs["numPr"]);
1977
1974
  const statedByOldStyle = isStyleSourcedParagraphNumbering(stated, readParagraphNumberingAttr(attrs["numPrFromStyle"]));
1978
1975
  const fromStyle = styleNumbering === void 0 ? null : paragraphNumberingAttr(styleNumbering);
1979
- const numPr = removesNumbering ? removedNumberingAttr(fromStyle) : stated !== null && !statedByOldStyle ? stated : fromStyle;
1976
+ const numPr = removesNumbering ? removedNumberingAttr(fromStyle) : statedByOldStyle ? null : stated;
1977
+ const effective = effectiveParagraphNumbering(paragraphNumberingSourcesFromBoundary({
1978
+ numPr,
1979
+ numPrFromStyle: fromStyle
1980
+ }));
1980
1981
  return {
1981
1982
  ...CLEARED_LIST_RENDERING_ATTRS,
1982
- ...numPr?.kind === "reference" && listAttrsFromNumbering({
1983
- numId: numPr.numId,
1984
- ilvl: numPr.ilvl ?? 0
1983
+ ...effective?.kind === "reference" && listAttrsFromNumbering({
1984
+ numId: effective.numId,
1985
+ ilvl: effective.ilvl ?? 0
1985
1986
  }, numbering),
1986
1987
  numPr,
1987
1988
  numPrFromStyle: fromStyle
@@ -2041,52 +2042,16 @@ const buildInsertedParagraphs = ({ item, schema, formattingFromStyle, mode, auth
2041
2042
  }) : buildEmphasisInlineContent(schema, text, marks);
2042
2043
  const attrs = formatsParagraph ? { ...baseAttrs } : {};
2043
2044
  if (isFirstParagraph && operation.pageBreakBefore === true) attrs["pageBreakBefore"] = true;
2044
- const explicitNumbering = operation.numbering === void 0 || operation.numbering === null ? operation.numbering : concreteListReference(operation.numbering);
2045
- const listLevel = operation.listLevel;
2046
- if (formatsParagraph) {
2047
- if (explicitNumbering === null) {
2048
- Object.assign(attrs, listLevelIndentRemovalPatch(mergeParagraphAttrs(schema.node("paragraph"), {
2049
- ...operation.inheritFormatting === false ? {} : expectParagraphAttrs(item.blockNode),
2050
- _styleResolvedFormatting: styleResolvedParagraphFormatting(formattingFromStyle)
2051
- }), numbering));
2052
- attrs["numPr"] = removedNumberingAttr(readParagraphNumberingAttr(attrs["numPrFromStyle"]));
2053
- Object.assign(attrs, CLEARED_LIST_RENDERING_ATTRS);
2054
- } else if (explicitNumbering !== void 0) {
2055
- Object.assign(attrs, listLevelAttrPatch(mergeParagraphAttrs(schema.node("paragraph"), {
2056
- ...operation.inheritFormatting === false ? {} : expectParagraphAttrs(item.blockNode),
2057
- _styleResolvedFormatting: styleResolvedParagraphFormatting(formattingFromStyle)
2058
- }), {
2059
- numId: explicitNumbering.numId,
2060
- ilvl: explicitNumbering.level
2061
- }, numbering));
2062
- if (listLevel === null) {
2063
- attrs["numPr"] = paragraphNumberingAttr(paragraphNumberingReference({ numId: explicitNumbering.numId }));
2064
- attrs["numPrFromStyle"] = null;
2065
- }
2066
- } else if (listLevel === null) {
2067
- Object.assign(attrs, listLevelIndentRemovalPatch(mergeParagraphAttrs(schema.node("paragraph"), {
2068
- ...operation.inheritFormatting === false ? {} : expectParagraphAttrs(item.blockNode),
2069
- _styleResolvedFormatting: styleResolvedParagraphFormatting(formattingFromStyle)
2070
- }), numbering));
2071
- attrs["numPr"] = removedNumberingAttr(readParagraphNumberingAttr(attrs["numPrFromStyle"]));
2072
- Object.assign(attrs, CLEARED_LIST_RENDERING_ATTRS);
2073
- } else if (typeof listLevel === "number") {
2074
- const numId = paragraphNumberingReferenceId(readParagraphNumberingAttr(Reflect.get(baseAttrs, "numPr")) ?? void 0);
2075
- if (numId === void 0) {
2076
- attrs["numPr"] = paragraphNumberingAttr({
2077
- kind: "levelOnly",
2078
- ilvl: listLevel
2079
- });
2080
- Object.assign(attrs, CLEARED_LIST_RENDERING_ATTRS);
2081
- } else Object.assign(attrs, listLevelAttrPatch(mergeParagraphAttrs(schema.node("paragraph"), {
2082
- ...operation.inheritFormatting === false ? {} : expectParagraphAttrs(item.blockNode),
2083
- _styleResolvedFormatting: styleResolvedParagraphFormatting(formattingFromStyle)
2084
- }), {
2085
- numId,
2086
- ilvl: listLevel
2087
- }, numbering));
2088
- }
2089
- }
2045
+ if (formatsParagraph && operation.numbering !== void 0) Object.assign(attrs, statedNumberingAttrPatch({
2046
+ attrs: mergeParagraphAttrs(schema.node("paragraph"), {
2047
+ ...operation.inheritFormatting === false ? {} : expectParagraphAttrs(item.blockNode),
2048
+ ...attrs,
2049
+ _styleResolvedFormatting: styleResolvedParagraphFormatting(formattingFromStyle)
2050
+ }),
2051
+ stated: operation.numbering,
2052
+ fromStyle: formattingFromStyle?.numPr === void 0 ? void 0 : paragraphNumberingAttr(formattingFromStyle.numPr),
2053
+ numbering
2054
+ }));
2090
2055
  if (formatsParagraph && operation.styleId !== void 0) {
2091
2056
  attrs["styleId"] = operation.styleId;
2092
2057
  attrs["_resolvedFormatting"] = styleResolvedParagraphFormatting(formattingFromStyle);
@@ -2099,7 +2064,7 @@ const buildInsertedParagraphs = ({ item, schema, formattingFromStyle, mode, auth
2099
2064
  Object.assign(attrs, restyledListAttrs({
2100
2065
  attrs,
2101
2066
  styleNumbering: formattingFromStyle?.numPr,
2102
- removesNumbering: explicitNumbering === null || explicitNumbering === void 0 && listLevel === null,
2067
+ removesNumbering: operation.numbering?.kind === "none",
2103
2068
  numbering
2104
2069
  }));
2105
2070
  attrs["outlineLevel"] = attrs["_originalFormatting"]?.outlineLevel ?? formattingFromStyle?.outlineLevel ?? null;
@@ -2144,9 +2109,14 @@ const buildInsertedParagraphs = ({ item, schema, formattingFromStyle, mode, auth
2144
2109
  }));
2145
2110
  attrs["_originalFormatting"] = originalFormatting && Object.keys(originalFormatting).length > 0 ? originalFormatting : null;
2146
2111
  const finalNumbering = readParagraphNumberingAttr(attrs["numPr"]);
2147
- if (finalNumbering?.kind === "reference") {
2112
+ const finalFromStyle = readParagraphNumberingAttr(attrs["numPrFromStyle"]);
2113
+ const effectiveNumbering = effectiveParagraphNumbering(paragraphNumberingSourcesFromBoundary({
2114
+ numPr: finalNumbering ?? void 0,
2115
+ numPrFromStyle: finalFromStyle
2116
+ }));
2117
+ if (effectiveNumbering?.kind === "reference") {
2148
2118
  Object.assign(attrs, listLevelAttrPatch(mergeParagraphAttrs(schema.node("paragraph"), {
2149
- numPr: finalNumbering,
2119
+ numPr: finalNumbering ?? void 0,
2150
2120
  _styleResolvedFormatting: styleResolvedParagraphFormatting(formattingFromStyle),
2151
2121
  numPrFromStyle: readParagraphNumberingAttr(attrs["numPrFromStyle"]) ?? void 0,
2152
2122
  listImplicitChildLevelAdvances: operation.inheritFormatting === false ? void 0 : expectParagraphAttrs(item.blockNode).listImplicitChildLevelAdvances,
@@ -2156,14 +2126,12 @@ const buildInsertedParagraphs = ({ item, schema, formattingFromStyle, mode, auth
2156
2126
  indentRight: directIndentation?.indentRight ?? formattingFromStyle?.indentRight ?? void 0,
2157
2127
  indentFirstLine: directIndentation?.indentFirstLine ?? formattingFromStyle?.indentFirstLine ?? void 0,
2158
2128
  hangingIndent: directIndentation?.hangingIndent ?? formattingFromStyle?.hangingIndent ?? false
2159
- }), {
2160
- numId: finalNumbering.numId,
2161
- ilvl: finalNumbering.ilvl ?? 0
2162
- }, numbering));
2129
+ }), effectiveNumbering.ilvl ?? 0, numbering));
2163
2130
  attrs["numPr"] = finalNumbering;
2131
+ attrs["numPrFromStyle"] = finalFromStyle;
2164
2132
  }
2165
2133
  }
2166
- if (formatsParagraph && operation.styleId !== void 0 && formattingFromStyle?.numPr?.kind === "reference" && operation.numbering === void 0 && operation.listLevel === void 0) {
2134
+ if (formatsParagraph && operation.styleId !== void 0 && formattingFromStyle?.numPr?.kind === "reference" && operation.numbering === void 0) {
2167
2135
  const { numId, ilvl = 0 } = formattingFromStyle.numPr;
2168
2136
  const levelIndentation = numbering?.getLevel(numId, ilvl)?.pPr;
2169
2137
  if (levelIndentation && operation.indentation === void 0) {
@@ -2226,7 +2194,7 @@ const buildInsertedParagraphs = ({ item, schema, formattingFromStyle, mode, auth
2226
2194
  nextRevisionId
2227
2195
  };
2228
2196
  };
2229
- const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: requestedOperations, mode = "tracked-changes", author = "AI", initials, createCommentId, revisionStamp, revisionIdSeed, wordDiff, wordDiffMode = "bounded", tableTemplates, replacementBackground = "clear", undefinedStyles = "refuse" }) => {
2197
+ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: requestedOperations, mode = "tracked-changes", author = "AI", initials, createCommentId, revisionStamp, revisionIdSeed, wordDiff, wordDiffMode = "bounded", tableTemplates, replacementBackground = "clear", undefinedReferences }) => {
2230
2198
  seedRevisionIdsFromDoc(view.state.doc);
2231
2199
  const applied = [];
2232
2200
  const skipped = [];
@@ -2259,7 +2227,7 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
2259
2227
  return id;
2260
2228
  };
2261
2229
  const styleResolver = getDocumentStyleResolver(view.state);
2262
- const styleDefinitions = undefinedStyles === "keep" ? null : getDocumentStyleDefinitions(view.state);
2230
+ const styleDefinitions = getDocumentStyleDefinitions(view.state);
2263
2231
  const { operations, numbering } = resolveNewListOperations(requestedOperations, getDocumentNumbering(view.state));
2264
2232
  const formattingFromStyleForInsertion = (item) => {
2265
2233
  if (item.operation.type !== "insertAfterBlock" && item.operation.type !== "insertBeforeBlock") return;
@@ -2323,7 +2291,11 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
2323
2291
  });
2324
2292
  continue;
2325
2293
  }
2326
- const undefinedStyle = findUndefinedParagraphStyleReference(operation, styleDefinitions);
2294
+ const undefinedStyle = findUndefinedParagraphStyleReference({
2295
+ operation,
2296
+ definitions: styleDefinitions,
2297
+ undefinedReferences
2298
+ });
2327
2299
  if (undefinedStyle !== void 0) {
2328
2300
  skipped.push({
2329
2301
  id: operation.id,
@@ -2332,7 +2304,11 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
2332
2304
  });
2333
2305
  continue;
2334
2306
  }
2335
- const undefinedNumbering = findUndefinedNumberingReference(operation, numberingInstanceIds);
2307
+ const undefinedNumbering = findUndefinedNumberingReference({
2308
+ operation,
2309
+ instanceIds: numberingInstanceIds,
2310
+ undefinedReferences
2311
+ });
2336
2312
  if (undefinedNumbering !== void 0) {
2337
2313
  skipped.push({
2338
2314
  id: operation.id,
@@ -3615,21 +3591,34 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
3615
3591
  break;
3616
3592
  }
3617
3593
  case "mergeBlockWithNext": {
3618
- if (mode === "direct" && !canJoin(tr.doc, item.blockTo)) {
3594
+ const mapped = tr.mapping.mapResult(item.blockFrom, 1);
3595
+ const live = mapped.deletedAcross ? null : tr.doc.nodeAt(mapped.pos);
3596
+ const paraId = item.blockNode.attrs["paraId"];
3597
+ if (!live || live.type !== item.blockNode.type || typeof paraId === "string" && live.attrs["paraId"] !== paraId) {
3598
+ skipped.push({
3599
+ id: item.operation.id,
3600
+ reason: "changedBlock"
3601
+ });
3602
+ continue;
3603
+ }
3604
+ const blockFrom = mapped.pos;
3605
+ const blockTo = blockFrom + live.nodeSize;
3606
+ const join = paragraphJoinAfter(tr.doc, blockTo);
3607
+ if (!join) {
3619
3608
  skipped.push({
3620
3609
  id: item.operation.id,
3621
3610
  reason: "unsupportedBlock"
3622
3611
  });
3623
3612
  continue;
3624
3613
  }
3625
- const separator = followedOnlyByDeletedParagraphs(tr.doc, item.blockTo) ? "" : item.operation.separator ?? "";
3626
- const insertAt = item.blockTo - 1;
3627
- let mergedPropertiesAt = item.blockFrom;
3614
+ const separator = followedOnlyByDeletedParagraphs(tr.doc, blockTo) ? "" : item.operation.separator ?? "";
3615
+ const insertAt = blockTo - 1;
3616
+ let mergedPropertiesAt = blockFrom;
3628
3617
  let mergedPropertiesRecorded = false;
3629
- const second = tr.doc.nodeAt(item.blockTo);
3630
- const spanningComments = commentsAcrossBlockBoundary(tr.doc, item.blockTo);
3618
+ const second = join.next;
3619
+ const spanningComments = commentsAcrossBlockBoundary(tr.doc, blockTo);
3631
3620
  const withSeparator = (transaction) => {
3632
- const paragraph = transaction.doc.nodeAt(item.blockFrom);
3621
+ const paragraph = transaction.doc.nodeAt(blockFrom);
3633
3622
  const sourceMarks = paragraph?.lastChild?.marks.filter(({ type }) => RUN_FORMATTING_MARK_NAMES.has(type.name)) ?? [];
3634
3623
  const sourceNode = view.state.schema.text(separator, sourceMarks);
3635
3624
  const context = paragraph && paragraphRunStyleContext(paragraph, styleResolver);
@@ -3649,9 +3638,9 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
3649
3638
  };
3650
3639
  if (mode === "direct") {
3651
3640
  if (separator.length > 0) tr = withSeparator(tr);
3652
- const nextPosition = item.blockTo + separator.length;
3641
+ const nextPosition = join.nextPosition + separator.length;
3653
3642
  const next = tr.doc.nodeAt(nextPosition);
3654
- const paragraph = tr.doc.nodeAt(item.blockFrom);
3643
+ const paragraph = tr.doc.nodeAt(blockFrom);
3655
3644
  if (next && paragraph) tr = rebaseParagraphRuns({
3656
3645
  tr,
3657
3646
  position: nextPosition,
@@ -3660,10 +3649,27 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
3660
3649
  styleResolver
3661
3650
  });
3662
3651
  tr.setMeta(JOINED_RUNS_RESTYLED_META, true);
3663
- tr = tr.join(item.blockTo + separator.length);
3652
+ if (join.inlineBookmarks.length > 0) tr = tr.replaceWith(blockTo + separator.length - 1, nextPosition + 1, join.inlineBookmarks);
3653
+ else tr = tr.join(blockTo + separator.length);
3664
3654
  const secondSection = second ? sectionPropertiesOf(second) : null;
3665
- const joined = tr.doc.nodeAt(item.blockFrom);
3666
- if (joined && sectionPropertiesOf(joined) !== secondSection) tr = tr.setNodeAttribute(item.blockFrom, "_sectionProperties", secondSection);
3655
+ const joined = tr.doc.nodeAt(blockFrom);
3656
+ if (joined && second) tr = tr.setNodeAttribute(blockFrom, "pPrMark", expectParagraphAttrs(second).pPrMark ?? null);
3657
+ if (joined && sectionPropertiesOf(joined) !== secondSection) tr = tr.setNodeAttribute(blockFrom, "_sectionProperties", secondSection);
3658
+ const endingMark = second ? expectParagraphAttrs(second).pPrMark : null;
3659
+ if (joined && (endingMark?.kind === "del" || endingMark?.kind === "moveFrom")) {
3660
+ const survivor = paragraphLeftAfter({
3661
+ doc: tr.doc,
3662
+ paragraphPos: blockFrom
3663
+ });
3664
+ if (survivor !== null) tr = carryParagraphProperties({
3665
+ tr,
3666
+ position: survivor,
3667
+ source: joined,
3668
+ styleResolver,
3669
+ numbering,
3670
+ revision: endingMark.info
3671
+ }).tr;
3672
+ }
3667
3673
  } else {
3668
3674
  const revisionIdMark = operationRevisionSeed++;
3669
3675
  appliedRevisionIds = [revisionIdMark];
@@ -3678,25 +3684,25 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
3678
3684
  }));
3679
3685
  appliedRevisionIds.push(revisionIdSeparator);
3680
3686
  }
3681
- const paragraph = tr.doc.nodeAt(item.blockFrom);
3682
- const joinPos = item.blockTo + separator.length;
3683
- const next = tr.doc.nodeAt(joinPos);
3687
+ const paragraph = tr.doc.nodeAt(blockFrom);
3688
+ const nextPosition = join.nextPosition + separator.length;
3689
+ const next = tr.doc.nodeAt(nextPosition);
3684
3690
  if (!paragraph || !next) panic("A resolved merge lost its paragraphs");
3685
3691
  if (isInsertedPPrMark(paragraph.attrs["pPrMark"])) {
3686
3692
  joinAtParagraphMark({
3687
3693
  tr,
3688
- paragraphPos: item.blockFrom,
3694
+ paragraphPos: blockFrom,
3689
3695
  paragraph,
3690
3696
  next,
3691
3697
  styleResolver
3692
3698
  });
3693
- const joinedMark = tr.doc.nodeAt(item.blockFrom)?.attrs["pPrMark"];
3699
+ const joinedMark = tr.doc.nodeAt(blockFrom)?.attrs["pPrMark"];
3694
3700
  const removedBreakPositions = pendingRemovedFinalBreakPositions(tr, deletedFinalParagraphs);
3695
- const carryPos = isDeletedPPrMark(joinedMark) || removedBreakPositions.has(item.blockFrom) ? paragraphLeftAfter({
3701
+ const carryPos = isDeletedPPrMark(joinedMark) || removedBreakPositions.has(blockFrom) ? paragraphLeftAfter({
3696
3702
  doc: tr.doc,
3697
- paragraphPos: item.blockFrom,
3703
+ paragraphPos: blockFrom,
3698
3704
  removedBreakPositions
3699
- }) ?? item.blockFrom : item.blockFrom;
3705
+ }) ?? blockFrom : blockFrom;
3700
3706
  const carried = carryParagraphProperties({
3701
3707
  tr,
3702
3708
  position: carryPos,
@@ -3715,7 +3721,7 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
3715
3721
  mergedPropertiesRecorded = carried.tracked;
3716
3722
  if (!carried.tracked) appliedRevisionIds = appliedRevisionIds.filter((id) => id !== revisionIdMark);
3717
3723
  } else {
3718
- tr = tr.setNodeAttribute(item.blockFrom, "pPrMark", {
3724
+ tr = tr.setNodeAttribute(blockFrom, "pPrMark", {
3719
3725
  kind: "del",
3720
3726
  info: {
3721
3727
  id: revisionIdMark,
@@ -3726,9 +3732,9 @@ const applyFolioAIEditOperationsInternal = ({ view, snapshot, operations: reques
3726
3732
  });
3727
3733
  const survivorPos = paragraphLeftAfter({
3728
3734
  doc: tr.doc,
3729
- paragraphPos: item.blockFrom,
3735
+ paragraphPos: blockFrom,
3730
3736
  removedBreakPositions: pendingRemovedFinalBreakPositions(tr, deletedFinalParagraphs)
3731
- }) ?? joinPos;
3737
+ }) ?? nextPosition;
3732
3738
  const carried = carryParagraphProperties({
3733
3739
  tr,
3734
3740
  position: survivorPos,
@@ -5169,7 +5175,7 @@ const resolveOperationTarget = ({ snapshot, operation, liveBlocks, liveBlocksByP
5169
5175
  };
5170
5176
  }
5171
5177
  if (operation.type === "mergeBlockWithNext") {
5172
- if (!canJoin(doc, blockTo)) return {
5178
+ if (!paragraphJoinAfter(doc, blockTo)) return {
5173
5179
  type: "skip",
5174
5180
  reason: "unsupportedBlock"
5175
5181
  };
@@ -5373,22 +5379,32 @@ const operationParagraphStyleReferences = (operation) => {
5373
5379
  }
5374
5380
  };
5375
5381
  /**
5376
- * The first paragraph style the operation names that the document does not
5377
- * define as a paragraph style. A `w:pStyle` naming no definition, or a table
5378
- * or character style, confers no formatting: the paragraph keeps its body
5379
- * look while the operation reports a restyle. Refused here, before anything
5380
- * is applied, the way an undefined block id is. `null` definitions (a state
5381
- * without the styles plugin) cannot say what is defined, and check nothing.
5382
+ * Explicit editing requests refuse unavailable paragraph styles before apply.
5383
+ * Source-preserving imports keep their references verbatim; closure import
5384
+ * validates every defined resource separately. A state without the styles
5385
+ * plugin cannot classify a reference and checks nothing.
5382
5386
  */
5383
- const findUndefinedParagraphStyleReference = (operation, definitions) => {
5387
+ const findUndefinedParagraphStyleReference = ({ operation, definitions, undefinedReferences }) => {
5384
5388
  if (definitions === null) return;
5385
5389
  for (const { path, styleId } of operationParagraphStyleReferences(operation)) {
5386
5390
  if (styleId === null || styleId === void 0) continue;
5387
- const definition = definitions.get(styleId);
5388
- if (definition?.type !== "paragraph") return {
5391
+ const reference = classifyResourceReference({
5392
+ kind: "style",
5393
+ id: styleId,
5394
+ sourceDefines: (id) => definitions.get(id) !== void 0,
5395
+ destinationDefines: (id) => definitions.get(id) !== void 0
5396
+ });
5397
+ if (undefinedReferences === "keep") continue;
5398
+ if (reference !== "sourceDefined") return {
5389
5399
  path,
5390
5400
  styleId,
5391
- definedAs: definition?.type
5401
+ definedAs: void 0
5402
+ };
5403
+ const definition = definitions.get(styleId) ?? panic("A classified style lost its definition");
5404
+ if (definition.type !== "paragraph") return {
5405
+ path,
5406
+ styleId,
5407
+ definedAs: definition.type
5392
5408
  };
5393
5409
  }
5394
5410
  };
@@ -5400,15 +5416,10 @@ const describeUndefinedParagraphStyle = ({ path, styleId, definedAs }, definitio
5400
5416
  return `${path} "${styleId}" ${definedAs === void 0 ? "names no style in this document" : `names a ${definedAs} style, not a paragraph style`} (${available}).`;
5401
5417
  };
5402
5418
  /** The `w:num` id a stated numbering names, when it names one. */
5403
- const statedNumberingInstance = (numbering) => {
5404
- if (numbering === null || numbering === void 0) return;
5405
- const numId = Reflect.get(numbering, "numId");
5406
- return typeof numId === "number" ? numId : void 0;
5407
- };
5419
+ const statedNumberingInstance = (numbering) => numbering?.kind === "reference" ? numbering.numId : void 0;
5408
5420
  /**
5409
5421
  * Every numbering instance an operation names, with the field that names it.
5410
- * `listLevel` is not among them: it keeps the instance the paragraph or its
5411
- * anchor already references, which the document holds by construction.
5422
+ * Only reference variants name an instance; inheritance, cancellation and level-only do not.
5412
5423
  */
5413
5424
  const operationNumberingReferences = (operation) => {
5414
5425
  switch (operation.type) {
@@ -5435,18 +5446,18 @@ const operationNumberingReferences = (operation) => {
5435
5446
  default: return [];
5436
5447
  }
5437
5448
  };
5438
- /**
5439
- * The first numbering instance the operation names that the document does not
5440
- * define. A paragraph referencing a missing `w:num` is a model no save can
5441
- * write, so it is refused here, before anything is applied, the way a block id
5442
- * naming no block is. `null` instance ids (a state without the numbering
5443
- * plugin) cannot say what is defined, and check nothing.
5444
- */
5445
- const findUndefinedNumberingReference = (operation, instanceIds) => {
5449
+ const findUndefinedNumberingReference = ({ operation, instanceIds, undefinedReferences }) => {
5446
5450
  if (instanceIds === null) return;
5447
5451
  for (const { path, numbering } of operationNumberingReferences(operation)) {
5448
5452
  const numId = statedNumberingInstance(numbering);
5449
- if (numId !== void 0 && !instanceIds.has(numId)) return {
5453
+ if (numId === void 0) continue;
5454
+ const reference = classifyResourceReference({
5455
+ kind: "numbering",
5456
+ id: numId,
5457
+ sourceDefines: (id) => instanceIds.has(id),
5458
+ destinationDefines: (id) => instanceIds.has(id)
5459
+ });
5460
+ if (undefinedReferences !== "keep" && reference !== "sourceDefined") return {
5450
5461
  path,
5451
5462
  numId
5452
5463
  };