@stll/folio-core 0.76.0 → 0.78.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 (92) hide show
  1. package/dist/ai-edits/headless.d.ts +6 -4
  2. package/dist/ai-edits/headless.js +32 -15
  3. package/dist/ai-edits/pending-suggestions.d.ts +9 -0
  4. package/dist/ai-edits/pending-suggestions.js +11 -0
  5. package/dist/ai-edits/read.js +24 -1
  6. package/dist/ai-edits/table-geometry.js +12 -4
  7. package/dist/canonical/canonicalBatchReview.js +7 -6
  8. package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
  9. package/dist/canonical/canonicalInlineProjection.js +2 -2
  10. package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
  11. package/dist/canonical/canonicalPublicOperations.js +19 -40
  12. package/dist/canonical/canonicalSeedContent.d.ts +18 -3
  13. package/dist/canonical/canonicalSeedContent.js +28 -15
  14. package/dist/canonical/canonicalSession.d.ts +22 -12
  15. package/dist/canonical/canonicalSession.js +190 -194
  16. package/dist/compare/inline-provenance.js +8 -1
  17. package/dist/controller/canonicalClipboard.d.ts +2 -1
  18. package/dist/controller/canonicalClipboard.js +312 -47
  19. package/dist/controller/canonicalComposition.js +67 -14
  20. package/dist/controller/canonicalStoryEditor.js +2 -0
  21. package/dist/controller/hiddenEditorManager.js +2 -0
  22. package/dist/docx/importedIdCollisions.js +29 -4
  23. package/dist/docx/paragraphParser.js +1 -1
  24. package/dist/docx/reviewResolutionProvenance.d.ts +2 -0
  25. package/dist/docx/reviewResolutionProvenance.js +22 -2
  26. package/dist/docx/server/templatePlan/apply.js +47 -2
  27. package/dist/docx/server/templatePlan/blocks.d.ts +34 -7
  28. package/dist/docx/server/templatePlan/blocks.js +190 -13
  29. package/dist/docx/server/templatePlan/builders.d.ts +8 -1
  30. package/dist/docx/server/templatePlan/builders.js +21 -5
  31. package/dist/docx/server/templatePlan/emit.d.ts +2 -0
  32. package/dist/docx/server/templatePlan/emit.js +108 -6
  33. package/dist/docx/server/templatePlan/plan.d.ts +26 -1
  34. package/dist/docx/server/templatePlan/plan.js +181 -21
  35. package/dist/docx/server/templatePlan/planShape.js +15 -3
  36. package/dist/docx/server/templatePlan/revisions.d.ts +55 -0
  37. package/dist/docx/server/templatePlan/revisions.js +276 -2
  38. package/dist/docx/server/templatePlan/story.d.ts +58 -1
  39. package/dist/docx/server/templatePlan/story.js +176 -12
  40. package/dist/docx/server/templatePlan/types.d.ts +153 -1
  41. package/dist/docx/server/templatePlan/verify.js +58 -15
  42. package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
  43. package/dist/docx/tableGridXml.d.ts +3 -7
  44. package/dist/docx/tableGridXml.js +23 -15
  45. package/dist/docx/tableParser.js +3 -1
  46. package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
  47. package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
  48. package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
  49. package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
  50. package/dist/prosemirror/canonicalTableCommands.js +7 -9
  51. package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
  52. package/dist/prosemirror/conversion/markupViewSource.js +11 -0
  53. package/dist/prosemirror/conversion/toProseDoc.d.ts +8 -0
  54. package/dist/prosemirror/conversion/toProseDoc.js +43 -19
  55. package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
  56. package/dist/prosemirror/independentMarkupProjection.js +147 -0
  57. package/dist/prosemirror/markupViewNotes.d.ts +1 -1
  58. package/dist/prosemirror/markupViewNotes.js +24 -27
  59. package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
  60. package/dist/prosemirror/markupViewPositionMap.js +316 -0
  61. package/dist/prosemirror/markupViewProjection.d.ts +3 -46
  62. package/dist/prosemirror/markupViewProjection.js +90 -17
  63. package/dist/prosemirror/replacedAnnotations.d.ts +4 -78
  64. package/dist/prosemirror/replacedAnnotations.js +11 -194
  65. package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
  66. package/dist/prosemirror/styles/styleResolver.js +4 -1
  67. package/dist/server.d.ts +2 -2
  68. package/dist/types/canonicalCapabilities.d.ts +3 -10
  69. package/dist/types/canonicalCapabilities.js +3 -10
  70. package/package.json +2 -2
  71. package/dist/internal/revisionResolutionEdits.d.ts +0 -11
  72. package/dist/internal/revisionResolutionEdits.js +0 -18
  73. package/dist/internal/revisionResolutionInline.d.ts +0 -24
  74. package/dist/internal/revisionResolutionInline.js +0 -302
  75. package/dist/internal/revisionResolutionStep.d.ts +0 -3
  76. package/dist/internal/revisionResolutionStep.js +0 -113
  77. package/dist/internal/revisionResolutionTracking.d.ts +0 -9
  78. package/dist/internal/revisionResolutionTracking.js +0 -124
  79. package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
  80. package/dist/internal/wholeStoryRevisionResolution.js +0 -783
  81. package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
  82. package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
  83. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
  84. package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
  85. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -8
  86. package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -56
  87. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
  88. package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
  89. package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
  90. package/dist/prosemirror/rejoinRunCarriers.js +0 -65
  91. package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
  92. package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
@@ -1,45 +0,0 @@
1
- import { nodePropertyRevisionSites, propertyRevisionMetadata, propertyRevisionRecords } from "../revisionCarriers.js";
2
- import { tableCellRejectAttrPatch, tablePropertyExceptionsRejectAttrPatch, tableRejectAttrPatch, tableRowRejectAttrPatch } from "./propertyChangeScope.js";
3
- // src/prosemirror/commands/resolveNodePropertyChangeAttrs.ts
4
- /** The old property set each node-attr revision restores on rejection. */
5
- const NODE_ATTRS_REJECT_PATCHES = {
6
- tablePropertyChange: (previousFormatting) => tableRejectAttrPatch(previousFormatting),
7
- tablePropertyExceptionChange: (previousFormatting) => tablePropertyExceptionsRejectAttrPatch(previousFormatting),
8
- tableRowPropertyChange: (previousFormatting) => tableRowRejectAttrPatch(previousFormatting),
9
- tableCellPropertyChange: (previousFormatting, node) => tableCellRejectAttrPatch(previousFormatting, node.attrs["_originalFormatting"])
10
- };
11
- const resolveNodePropertyChangeAttrs = ({ node, site, mode, revisionSet }) => {
12
- const changes = propertyRevisionRecords(node, site);
13
- if (changes.length === 0) return null;
14
- const matches = changes.filter((change) => {
15
- const metadata = propertyRevisionMetadata(change.info);
16
- return revisionSet === null || metadata !== null && revisionSet.has(metadata.id);
17
- });
18
- if (matches.length === 0) return null;
19
- const remaining = revisionSet === null ? [] : changes.filter((change) => !matches.includes(change));
20
- const nextAttrs = {
21
- ...node.attrs,
22
- [site.attr]: remaining.length > 0 ? remaining : null
23
- };
24
- if (mode === "reject") {
25
- const rejectPatch = NODE_ATTRS_REJECT_PATCHES[site.kind];
26
- for (const change of matches.toReversed()) Object.assign(nextAttrs, rejectPatch(change.previousFormatting, node));
27
- }
28
- return nextAttrs;
29
- };
30
- /** Resolve every node-attr site, including both independent sites on a row. */
31
- const resolveAllNodePropertyChangeAttrs = (node, mode) => {
32
- let current = node;
33
- for (const site of nodePropertyRevisionSites(node.type.name)) {
34
- if (site.resolution !== "node-attrs") continue;
35
- const attrs = resolveNodePropertyChangeAttrs({
36
- node: current,
37
- site,
38
- mode,
39
- revisionSet: null
40
- });
41
- if (attrs !== null) current = current.type.create(attrs, current.content, current.marks);
42
- }
43
- return current;
44
- };
45
- export { resolveAllNodePropertyChangeAttrs, resolveNodePropertyChangeAttrs };
@@ -1,8 +0,0 @@
1
- import { DecodedTableCellParagraphSourcePayload } from "../../docx/paragraphPropertySource.js";
2
- import { document_d_exports } from "../../types/document.js";
3
- import { Node } from "prosemirror-model";
4
- export declare const tableCellContinuationPayload: (node: Node) => DecodedTableCellParagraphSourcePayload | null;
5
- export declare const hasMatchingCollapsedTableCellMerge: (node: Node, revisionSet: Set<number> | null) => boolean;
6
- export declare const tableCellContinuationCells: (cell: Node, rowspan: number) => document_d_exports.TableCell[];
7
- export declare const tableCellContinuationFromNode: (cell: Node) => document_d_exports.TableCell;
8
- export declare const createRestoredTableCell: (origin: Node, source: document_d_exports.TableCell) => Node | null;
@@ -1,56 +0,0 @@
1
- import { decodeTableCellParagraphSourcePayload } from "../../docx/paragraphPropertySource.js";
2
- import { standaloneTableCellFromProseMirror } from "../conversion/fromProseDoc.js";
3
- import { standaloneTableCellToProseMirror } from "../conversion/toProseDoc.js";
4
- import { getTableCellMergeChange } from "../tableCellMergeRevision.js";
5
- import { Result } from "better-result";
6
- // src/prosemirror/commands/tableCellMergeResolution.ts
7
- const tableCellContinuationPayload = (node) => {
8
- const value = node.attrs["_docxVMergeContinuationCells"];
9
- return value === void 0 || value === null ? null : decodeTableCellParagraphSourcePayload(value);
10
- };
11
- const hasMatchingCollapsedTableCellMerge = (node, revisionSet) => {
12
- const payload = tableCellContinuationPayload(node);
13
- return payload !== null && payload.cells.some((cell) => {
14
- const change = getTableCellMergeChange(cell);
15
- return change !== null && (revisionSet === null || revisionSet.has(change.info.id));
16
- });
17
- };
18
- const tableCellContinuationCells = (cell, rowspan) => {
19
- const payload = tableCellContinuationPayload(cell);
20
- const cells = payload ? [...payload.cells] : [];
21
- while (cells.length < rowspan - 1) cells.push(emptyVerticalMergeContinuation());
22
- return cells;
23
- };
24
- const tableCellContinuationFromNode = (cell) => {
25
- const continuation = standaloneTableCellFromProseMirror(cell);
26
- const formatting = {
27
- ...continuation.formatting,
28
- vMerge: "continue"
29
- };
30
- const colspan = cell.attrs["colspan"];
31
- if (typeof colspan === "number" && colspan > 1) formatting.gridSpan = colspan;
32
- continuation.formatting = formatting;
33
- delete continuation.structuralChange;
34
- return continuation;
35
- };
36
- const emptyVerticalMergeContinuation = () => ({
37
- type: "tableCell",
38
- formatting: { vMerge: "continue" },
39
- content: [{
40
- type: "paragraph",
41
- content: []
42
- }]
43
- });
44
- const createRestoredTableCell = (origin, source) => {
45
- const formatting = source.formatting ? { ...source.formatting } : void 0;
46
- if (formatting) delete formatting.vMerge;
47
- const restoredSource = {
48
- type: "tableCell",
49
- ...formatting ? { formatting } : {},
50
- ...source.propertyChanges ? { propertyChanges: source.propertyChanges } : {},
51
- content: source.content
52
- };
53
- const restored = standaloneTableCellToProseMirror(restoredSource, origin.type.name === "tableHeader" ? "tableHeader" : "tableCell");
54
- return Result.try(() => origin.type.schema.nodeFromJSON(restored.toJSON())).unwrapOr(null);
55
- };
56
- export { createRestoredTableCell, hasMatchingCollapsedTableCellMerge, tableCellContinuationCells, tableCellContinuationFromNode, tableCellContinuationPayload };
@@ -1,60 +0,0 @@
1
- import { CellMargins, ConditionalFormatStyle, PreservedMarkup, ShadingProperties, TableCellBorders, TableMeasurement, TextDirection } from "@stll/docx-core/model";
2
- import { Node } from "prosemirror-model";
3
- type TableMergeFoldDecisionsOptions = {
4
- table: Node;
5
- mode: "accept" | "reject";
6
- revisionSet: ReadonlySet<number> | null;
7
- };
8
- /** Resolve raw merge states without converting unrelated table revisions. */
9
- export declare const tableMergeFoldDecisions: ({ table, mode, revisionSet }: TableMergeFoldDecisionsOptions) => {
10
- folds: Map<number, boolean>;
11
- origins: Set<number>;
12
- invalid: Set<number>;
13
- };
14
- /** Persist an implicit merge origin even when reader rules retain its continuation. */
15
- export declare const resolvedTableMergeOriginAttrs: (cell: Node) => {
16
- _originalFormatting: {
17
- vMerge: string;
18
- width?: TableMeasurement;
19
- borders?: TableCellBorders;
20
- margins?: CellMargins;
21
- shading?: ShadingProperties;
22
- verticalAlign?: "top" | "center" | "bottom";
23
- textDirection?: TextDirection;
24
- gridSpan?: number;
25
- fitText?: boolean;
26
- noWrap?: boolean;
27
- hideMark?: boolean;
28
- conditionalFormat?: ConditionalFormatStyle;
29
- preserved?: PreservedMarkup;
30
- sourceXml?: string;
31
- };
32
- _preserveVMergeRestart: boolean;
33
- };
34
- type ResolvedVisibleTableCellMergeOptions = {
35
- cell: Node;
36
- mode: "accept" | "reject";
37
- origin: boolean;
38
- };
39
- /** A retained continuation must save the merge state the reviewer resolved. */
40
- export declare const resolvedVisibleTableCellMergeAttrs: ({ cell, mode, origin }: ResolvedVisibleTableCellMergeOptions) => {
41
- cellMarker: null;
42
- _originalFormatting: {
43
- width?: TableMeasurement;
44
- borders?: TableCellBorders;
45
- margins?: CellMargins;
46
- shading?: ShadingProperties;
47
- verticalAlign?: "top" | "center" | "bottom";
48
- textDirection?: TextDirection;
49
- gridSpan?: number;
50
- vMerge?: "restart" | "continue";
51
- fitText?: boolean;
52
- noWrap?: boolean;
53
- hideMark?: boolean;
54
- conditionalFormat?: ConditionalFormatStyle;
55
- preserved?: PreservedMarkup;
56
- sourceXml?: string;
57
- };
58
- _preserveVMergeRestart: boolean;
59
- };
60
- export {};
@@ -1,78 +0,0 @@
1
- import { isCellMergeContinuation, isCellMergeStart, isTableCellMergeRevisionContinuation } from "../../docx/tableParser.js";
2
- import { tableCellHasMeaningfulContent } from "../../docx/verticalMergeProjection.js";
3
- import { expectTableCellAttrs } from "../attrs/index.js";
4
- import { standaloneTableCellFromProseMirror } from "../conversion/fromProseDoc.js";
5
- import { panic } from "better-result";
6
- import { TableMap } from "prosemirror-tables";
7
- // src/prosemirror/commands/tableMergeFoldDecisions.ts
8
- /** Resolve raw merge states without converting unrelated table revisions. */
9
- const tableMergeFoldDecisions = ({ table, mode, revisionSet }) => {
10
- const decisions = /* @__PURE__ */ new Map();
11
- const origins = /* @__PURE__ */ new Set();
12
- const invalid = /* @__PURE__ */ new Set();
13
- const map = TableMap.get(table);
14
- const visited = /* @__PURE__ */ new Set();
15
- for (const [index, position] of map.map.entries()) {
16
- if (visited.has(position)) continue;
17
- visited.add(position);
18
- const cell = table.nodeAt(position);
19
- if (cell?.attrs["cellMarker"]?.kind !== "merge") continue;
20
- const marker = expectTableCellAttrs(cell).cellMarker;
21
- if (marker?.kind !== "merge" || revisionSet !== null && !revisionSet.has(marker.info.revisionId)) continue;
22
- const continues = isTableCellMergeRevisionContinuation(mode === "accept" ? marker.verticalMerge : marker.verticalMergeOriginal);
23
- decisions.set(position, continues && (mode === "reject" || !tableCellHasMeaningfulContent(standaloneTableCellFromProseMirror(cell))));
24
- if (!continues) continue;
25
- if (Math.floor(index / map.width) === 0) {
26
- invalid.add(position);
27
- continue;
28
- }
29
- const abovePosition = map.map[index - map.width];
30
- if (abovePosition === void 0) return panic("Merge resolution lost its origin");
31
- const above = table.nodeAt(abovePosition);
32
- if (!above) return panic("Merge resolution lost its origin");
33
- const rectangle = map.findCell(position);
34
- const aboveRectangle = map.findCell(abovePosition);
35
- if (rectangle.left !== aboveRectangle.left || rectangle.right !== aboveRectangle.right || rectangle.top !== aboveRectangle.bottom) {
36
- invalid.add(position);
37
- continue;
38
- }
39
- const aboveMarker = expectTableCellAttrs(above).cellMarker;
40
- const aboveContinues = aboveMarker?.kind === "merge" && (revisionSet === null || revisionSet.has(aboveMarker.info.revisionId)) && isTableCellMergeRevisionContinuation(mode === "accept" ? aboveMarker.verticalMerge : aboveMarker.verticalMergeOriginal);
41
- const aboveModel = standaloneTableCellFromProseMirror(above);
42
- if (mode === "accept" && (aboveContinues && decisions.get(abovePosition) === false || isCellMergeContinuation(aboveModel) && tableCellHasMeaningfulContent(aboveModel))) decisions.set(position, false);
43
- if (aboveContinues || isCellMergeContinuation(aboveModel) || isCellMergeStart(aboveModel)) continue;
44
- origins.add(abovePosition);
45
- }
46
- return {
47
- folds: decisions,
48
- origins,
49
- invalid
50
- };
51
- };
52
- /** Persist an implicit merge origin even when reader rules retain its continuation. */
53
- const resolvedTableMergeOriginAttrs = (cell) => ({
54
- ...cell.attrs,
55
- _originalFormatting: {
56
- ...expectTableCellAttrs(cell)._originalFormatting,
57
- vMerge: "restart"
58
- },
59
- _preserveVMergeRestart: true
60
- });
61
- /** A retained continuation must save the merge state the reviewer resolved. */
62
- const resolvedVisibleTableCellMergeAttrs = ({ cell, mode, origin }) => {
63
- const attrs = expectTableCellAttrs(cell);
64
- const marker = attrs.cellMarker;
65
- if (marker?.kind !== "merge") return panic("Cell has no merge revision");
66
- const continuation = mode === "accept" ? marker.verticalMerge : marker.verticalMergeOriginal;
67
- const formatting = { ...attrs._originalFormatting };
68
- if (origin) formatting.vMerge = "restart";
69
- else if (isTableCellMergeRevisionContinuation(continuation)) formatting.vMerge = "continue";
70
- else delete formatting.vMerge;
71
- return {
72
- ...cell.attrs,
73
- cellMarker: null,
74
- _originalFormatting: formatting,
75
- _preserveVMergeRestart: origin
76
- };
77
- };
78
- export { resolvedTableMergeOriginAttrs, resolvedVisibleTableCellMergeAttrs, tableMergeFoldDecisions };
@@ -1,42 +0,0 @@
1
- /**
2
- * Rejoin a run that resolving a revision left split.
3
- *
4
- * A revision splits the run it cuts into (`w:r`, `w:del > w:r`, `w:r`), and a
5
- * run-property change rewrites the formatting marks of the piece it covers.
6
- * Once the revision is resolved the pieces write the same `w:rPr`, but the
7
- * editor can hold that formatting on different mark carriers (a restored
8
- * `w:rPrChange` is rebuilt from its `w:rPr`), and leaves with different marks
9
- * are written as different runs. At a resolved boundary, a leaf that writes
10
- * the same run as the leaf before it takes that leaf's marks, so the two are
11
- * one run again.
12
- *
13
- * Leaves the source wrote as separate runs keep them apart: a run identity
14
- * (`runIdentity`) differs between them, and it is compared, not rewritten.
15
- * The pieces of one run read back from a saved redline share an identity
16
- * (`runIdentityAcrossRevisions.ts`).
17
- */
18
- import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
19
- import { Transaction } from "prosemirror-state";
20
- import { Mark, Node } from "prosemirror-model";
21
- type ContinuedRunMarksOptions = {
22
- left: Node;
23
- right: Node;
24
- /** The paragraph's run style context, read only when the marks differ in formatting alone. */
25
- context: () => ParagraphRunStyleContext;
26
- styleResolver: RunStyleResolver | null;
27
- };
28
- /**
29
- * The marks `right` takes to continue `left`'s run, or `null` when the two
30
- * already share their marks or write different runs: another mark differs,
31
- * or the formatting they state does.
32
- */
33
- export declare const continuedRunMarks: ({ left, right, context, styleResolver }: ContinuedRunMarksOptions) => readonly Mark[] | null;
34
- type RejoinRunsAtOptions = {
35
- tr: Transaction;
36
- /** Positions in `tr.doc` where resolved content began or ended. */
37
- boundaries: Iterable<number>;
38
- styleResolver: RunStyleResolver | null;
39
- };
40
- /** Rejoin the runs meeting at each of `boundaries`, left to right. */
41
- export declare const rejoinRunsAt: ({ tr, boundaries, styleResolver }: RejoinRunsAtOptions) => void;
42
- export {};
@@ -1,65 +0,0 @@
1
- import { formattingEquals } from "../docx/runConsolidator.js";
2
- import { RUN_FORMATTING_MARK_NAMES } from "./runFormattingMarkNames.js";
3
- import { readAuthoredRunFormatting } from "./runFormattingReconciliation.js";
4
- import { paragraphRunStyleContextAt } from "./runStyleFormatting.js";
5
- import { Mark } from "prosemirror-model";
6
- // src/prosemirror/rejoinRunCarriers.ts
7
- /**
8
- * Rejoin a run that resolving a revision left split.
9
- *
10
- * A revision splits the run it cuts into (`w:r`, `w:del > w:r`, `w:r`), and a
11
- * run-property change rewrites the formatting marks of the piece it covers.
12
- * Once the revision is resolved the pieces write the same `w:rPr`, but the
13
- * editor can hold that formatting on different mark carriers (a restored
14
- * `w:rPrChange` is rebuilt from its `w:rPr`), and leaves with different marks
15
- * are written as different runs. At a resolved boundary, a leaf that writes
16
- * the same run as the leaf before it takes that leaf's marks, so the two are
17
- * one run again.
18
- *
19
- * Leaves the source wrote as separate runs keep them apart: a run identity
20
- * (`runIdentity`) differs between them, and it is compared, not rewritten.
21
- * The pieces of one run read back from a saved redline share an identity
22
- * (`runIdentityAcrossRevisions.ts`).
23
- */
24
- const isFormattingMark = (mark) => RUN_FORMATTING_MARK_NAMES.has(mark.type.name);
25
- /**
26
- * The marks `right` takes to continue `left`'s run, or `null` when the two
27
- * already share their marks or write different runs: another mark differs,
28
- * or the formatting they state does.
29
- */
30
- const continuedRunMarks = ({ left, right, context, styleResolver }) => {
31
- if (!left.isText || !right.isText || Mark.sameSet(left.marks, right.marks)) return null;
32
- const otherMarks = (node) => node.marks.filter((mark) => !isFormattingMark(mark));
33
- if (!Mark.sameSet(otherMarks(left), otherMarks(right))) return null;
34
- const paragraphContext = context();
35
- const stated = (node) => readAuthoredRunFormatting({
36
- context: paragraphContext,
37
- marks: node.marks,
38
- styleResolver
39
- });
40
- return formattingEquals(stated(left), stated(right)) ? left.marks : null;
41
- };
42
- /** Rejoin the runs meeting at each of `boundaries`, left to right. */
43
- const rejoinRunsAt = ({ tr, boundaries, styleResolver }) => {
44
- for (const boundary of [...new Set(boundaries)].toSorted((left, right) => left - right)) {
45
- if (boundary <= 0 || boundary >= tr.doc.content.size) continue;
46
- const at = tr.doc.resolve(boundary);
47
- const { nodeBefore: left, nodeAfter: right } = at;
48
- if (!left || !right || !at.parent.inlineContent) continue;
49
- const marks = continuedRunMarks({
50
- left,
51
- right,
52
- context: () => paragraphRunStyleContextAt({
53
- doc: tr.doc,
54
- pos: boundary,
55
- styleResolver
56
- }),
57
- styleResolver
58
- });
59
- if (marks === null) continue;
60
- const to = boundary + right.nodeSize;
61
- for (const mark of right.marks) if (!mark.isInSet(marks)) tr.removeMark(boundary, to, mark);
62
- for (const mark of marks) if (!mark.isInSet(right.marks)) tr.addMark(boundary, to, mark);
63
- }
64
- };
65
- export { continuedRunMarks, rejoinRunsAt };
@@ -1,15 +0,0 @@
1
- import { document_d_exports } from "../types/document.js";
2
- import { ParagraphRunStyleContext, RunStyleResolver } from "./runStyleFormatting.js";
3
- import { Mark, Node } from "prosemirror-model";
4
- type RejectedRunFormattingOptions = {
5
- node: Node;
6
- paragraphContext: ParagraphRunStyleContext;
7
- previousFormatting: document_d_exports.RunPropertyChange["previousFormatting"];
8
- styleResolver?: RunStyleResolver | null;
9
- };
10
- /** The one owner of what a reject restores: marks and an atom's run formatting. */
11
- export declare const rejectedRunFormatting: (options: RejectedRunFormattingOptions) => {
12
- marks: readonly Mark[] | null;
13
- atomRunFormatting: document_d_exports.TextFormatting | null;
14
- };
15
- export {};
@@ -1,34 +0,0 @@
1
- import { expectRunIdentityMarkAttrs } from "./attrs/index.js";
2
- import { RUN_FORMATTING_MARK_NAMES } from "./runFormattingMarkNames.js";
3
- import { reconcileRunFormattingMarks } from "./runFormattingReconciliation.js";
4
- import { RUN_IDENTITY_MARK_NAME, runIdentityAttrs } from "./runIdentity.js";
5
- // src/prosemirror/runPropertyChangeResolution.ts
6
- /** The one owner of what a reject restores: marks and an atom's run formatting. */
7
- const rejectedRunFormatting = (options) => {
8
- const { node, previousFormatting } = options;
9
- const keepsRunFormatting = Object.hasOwn(node.attrs, "_docxRunFormatting");
10
- return {
11
- marks: !keepsRunFormatting || node.marks.some(({ type }) => RUN_FORMATTING_MARK_NAMES.has(type.name)) ? rebuiltRunFormattingMarks(options) : null,
12
- atomRunFormatting: keepsRunFormatting ? { ...previousFormatting } : null
13
- };
14
- };
15
- /** The pre-change run marks, against the paragraph's live style cascade. */
16
- const rebuiltRunFormattingMarks = ({ node, paragraphContext, previousFormatting, styleResolver }) => {
17
- const formatting = reconcileRunFormattingMarks({
18
- authoredFormatting: previousFormatting ?? {},
19
- context: paragraphContext,
20
- node,
21
- ...styleResolver !== void 0 ? { styleResolver } : {}
22
- }).filter(({ type }) => RUN_FORMATTING_MARK_NAMES.has(type.name));
23
- if (previousFormatting === void 0 || Object.keys(previousFormatting).length > 0) return formatting;
24
- const identityType = node.type.schema.marks[RUN_IDENTITY_MARK_NAME];
25
- if (!identityType) return formatting;
26
- const identity = node.marks.find(({ type }) => type === identityType);
27
- const attrs = identity ? expectRunIdentityMarkAttrs(identity) : void 0;
28
- return [...formatting, identityType.create(runIdentityAttrs(attrs?.id ?? 0, {
29
- preservedAttributes: attrs?.preservedAttributes ?? void 0,
30
- preserved: attrs?.preserved ?? void 0,
31
- emptyFormatting: true
32
- }))];
33
- };
34
- export { rejectedRunFormatting };