@stll/folio-core 0.76.0 → 0.77.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.
- package/dist/ai-edits/headless.d.ts +6 -4
- package/dist/ai-edits/headless.js +32 -15
- package/dist/ai-edits/pending-suggestions.d.ts +9 -0
- package/dist/ai-edits/pending-suggestions.js +11 -0
- package/dist/ai-edits/read.js +24 -1
- package/dist/ai-edits/table-geometry.js +12 -4
- package/dist/canonical/canonicalInlineProjection.d.ts +2 -2
- package/dist/canonical/canonicalInlineProjection.js +2 -2
- package/dist/canonical/canonicalProjectionBlocks.d.ts +10 -1
- package/dist/canonical/canonicalPublicOperations.js +13 -38
- package/dist/canonical/canonicalSeedContent.d.ts +18 -3
- package/dist/canonical/canonicalSeedContent.js +28 -15
- package/dist/canonical/canonicalSession.d.ts +22 -12
- package/dist/canonical/canonicalSession.js +178 -186
- package/dist/controller/canonicalClipboard.d.ts +2 -1
- package/dist/controller/canonicalClipboard.js +312 -47
- package/dist/controller/canonicalComposition.js +67 -14
- package/dist/controller/canonicalStoryEditor.js +2 -0
- package/dist/controller/hiddenEditorManager.js +2 -0
- package/dist/docx/importedIdCollisions.js +29 -4
- package/dist/docx/server/templatePlan/apply.js +47 -2
- package/dist/docx/server/templatePlan/blocks.d.ts +27 -7
- package/dist/docx/server/templatePlan/blocks.js +103 -12
- package/dist/docx/server/templatePlan/builders.d.ts +6 -0
- package/dist/docx/server/templatePlan/builders.js +7 -1
- package/dist/docx/server/templatePlan/emit.d.ts +2 -0
- package/dist/docx/server/templatePlan/emit.js +108 -6
- package/dist/docx/server/templatePlan/plan.d.ts +24 -1
- package/dist/docx/server/templatePlan/plan.js +165 -12
- package/dist/docx/server/templatePlan/planShape.js +13 -2
- package/dist/docx/server/templatePlan/revisions.d.ts +55 -0
- package/dist/docx/server/templatePlan/revisions.js +276 -2
- package/dist/docx/server/templatePlan/story.d.ts +46 -1
- package/dist/docx/server/templatePlan/story.js +125 -11
- package/dist/docx/server/templatePlan/types.d.ts +97 -1
- package/dist/docx/server/templatePlan/verify.js +63 -9
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +1 -1
- package/dist/docx/tableGridXml.d.ts +3 -7
- package/dist/docx/tableGridXml.js +5 -13
- package/dist/layout-bridge/convert/footnoteLayout.js +34 -8
- package/dist/prosemirror/canonicalMarkupDocument.d.ts +20 -0
- package/dist/prosemirror/canonicalMarkupDocument.js +73 -0
- package/dist/prosemirror/canonicalTableCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +1 -3
- package/dist/prosemirror/conversion/markupViewSource.d.ts +17 -0
- package/dist/prosemirror/conversion/markupViewSource.js +11 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +3 -0
- package/dist/prosemirror/conversion/toProseDoc.js +31 -14
- package/dist/prosemirror/independentMarkupProjection.d.ts +27 -0
- package/dist/prosemirror/independentMarkupProjection.js +147 -0
- package/dist/prosemirror/markupViewNotes.d.ts +1 -1
- package/dist/prosemirror/markupViewNotes.js +24 -27
- package/dist/prosemirror/markupViewPositionMap.d.ts +16 -0
- package/dist/prosemirror/markupViewPositionMap.js +316 -0
- package/dist/prosemirror/markupViewProjection.d.ts +3 -46
- package/dist/prosemirror/markupViewProjection.js +90 -17
- package/dist/prosemirror/replacedAnnotations.d.ts +4 -78
- package/dist/prosemirror/replacedAnnotations.js +11 -194
- package/dist/prosemirror/styles/styleResolver.d.ts +1 -0
- package/dist/prosemirror/styles/styleResolver.js +4 -1
- package/dist/server.d.ts +2 -2
- package/dist/types/canonicalCapabilities.d.ts +3 -10
- package/dist/types/canonicalCapabilities.js +3 -10
- package/package.json +2 -2
- package/dist/internal/revisionResolutionEdits.d.ts +0 -11
- package/dist/internal/revisionResolutionEdits.js +0 -18
- package/dist/internal/revisionResolutionInline.d.ts +0 -24
- package/dist/internal/revisionResolutionInline.js +0 -302
- package/dist/internal/revisionResolutionStep.d.ts +0 -3
- package/dist/internal/revisionResolutionStep.js +0 -113
- package/dist/internal/revisionResolutionTracking.d.ts +0 -9
- package/dist/internal/revisionResolutionTracking.js +0 -124
- package/dist/internal/wholeStoryRevisionResolution.d.ts +0 -56
- package/dist/internal/wholeStoryRevisionResolution.js +0 -783
- package/dist/prosemirror/commands/resolveAllTableChanges.d.ts +0 -38
- package/dist/prosemirror/commands/resolveAllTableChanges.js +0 -642
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.d.ts +0 -13
- package/dist/prosemirror/commands/resolveNodePropertyChangeAttrs.js +0 -45
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +0 -8
- package/dist/prosemirror/commands/tableCellMergeResolution.js +0 -56
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +0 -60
- package/dist/prosemirror/commands/tableMergeFoldDecisions.js +0 -78
- package/dist/prosemirror/rejoinRunCarriers.d.ts +0 -42
- package/dist/prosemirror/rejoinRunCarriers.js +0 -65
- package/dist/prosemirror/runPropertyChangeResolution.d.ts +0 -15
- package/dist/prosemirror/runPropertyChangeResolution.js +0 -34
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { document_d_exports } from "../../types/document.js";
|
|
2
|
+
import { ToProseDocOptions } from "./toProseDoc.js";
|
|
3
|
+
import { EditorState } from "prosemirror-state";
|
|
4
|
+
import { Node } from "prosemirror-model";
|
|
5
|
+
import { OpStory } from "@stll/docx-core/ops";
|
|
6
|
+
type MarkupViewSource = {
|
|
7
|
+
document: document_d_exports.Document;
|
|
8
|
+
story?: OpStory;
|
|
9
|
+
options?: ToProseDocOptions;
|
|
10
|
+
};
|
|
11
|
+
/** The model used to convert a story, keyed by the exact PM snapshot. */
|
|
12
|
+
export declare const markupViewSources: WeakMap<Node, MarkupViewSource>;
|
|
13
|
+
/** Two states can share a PM node while publishing different model snapshots. */
|
|
14
|
+
export declare const markupViewStateSources: WeakMap<EditorState, MarkupViewSource>;
|
|
15
|
+
/** Carry the published model through a transaction that preserves the story. */
|
|
16
|
+
export declare const retainMarkupViewSource: (before: EditorState, after: EditorState) => void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/prosemirror/conversion/markupViewSource.ts
|
|
2
|
+
/** The model used to convert a story, keyed by the exact PM snapshot. */
|
|
3
|
+
const markupViewSources = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
/** Two states can share a PM node while publishing different model snapshots. */
|
|
5
|
+
const markupViewStateSources = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
/** Carry the published model through a transaction that preserves the story. */
|
|
7
|
+
const retainMarkupViewSource = (before, after) => {
|
|
8
|
+
const source = markupViewStateSources.get(before) ?? markupViewSources.get(before.doc);
|
|
9
|
+
if (source !== void 0) markupViewStateSources.set(after, source);
|
|
10
|
+
};
|
|
11
|
+
export { markupViewSources, markupViewStateSources, retainMarkupViewSource };
|
|
@@ -81,6 +81,7 @@ declare const CONVERSION_CONTEXT_DEPENDENCY: {
|
|
|
81
81
|
readonly warnPageBreakProjection: "package";
|
|
82
82
|
readonly createMark: "package";
|
|
83
83
|
readonly nextTextBoxGroupId: "story";
|
|
84
|
+
readonly placedTextBoxGroup: "story";
|
|
84
85
|
readonly nextHyperlinkInstanceIndex: "story";
|
|
85
86
|
readonly nextNoteReferenceOccurrenceId: "story";
|
|
86
87
|
readonly pairedBookmarkIds: "story";
|
|
@@ -172,6 +173,8 @@ type TableConversionContext = {
|
|
|
172
173
|
numbering: NumberingMap | undefined;
|
|
173
174
|
theme: DeepReadonly<document_d_exports.Theme> | null | undefined;
|
|
174
175
|
nextTextBoxGroupId: () => string;
|
|
176
|
+
/** Told when a paragraph puts the group id it drew on what it converts. */
|
|
177
|
+
placedTextBoxGroup?: () => void;
|
|
175
178
|
nextHyperlinkInstanceIndex: HyperlinkInstanceIndexAllocator;
|
|
176
179
|
nextNoteReferenceOccurrenceId: () => string;
|
|
177
180
|
pairedBookmarkIds: IdMembership;
|
|
@@ -64,6 +64,7 @@ import { assertValidProseMirrorDocument, assertValidProseMirrorDocumentKeeping }
|
|
|
64
64
|
import { resolveEffectiveTableCellFormatting } from "./effectiveTableCellFormatting.js";
|
|
65
65
|
import { HYPHEN_ELEMENT_MARK_NAME, HYPHEN_TEXT_CARRIERS } from "./hyphenTextCarriers.js";
|
|
66
66
|
import { createMarkInterner } from "./markInterner.js";
|
|
67
|
+
import { markupViewSources } from "./markupViewSource.js";
|
|
67
68
|
import { hasSinkChildren } from "./preservedSinkCarriers.js";
|
|
68
69
|
import { sdtAttrsFromProperties } from "./sdtAttrs.js";
|
|
69
70
|
import { panic } from "better-result";
|
|
@@ -428,7 +429,8 @@ var ProjectionBlockCache = class {
|
|
|
428
429
|
const context = this.context ?? panic("A block cache converts after its package context");
|
|
429
430
|
const textBoxGroups = {
|
|
430
431
|
start: state.textBoxGroups.value,
|
|
431
|
-
taken: 0
|
|
432
|
+
taken: 0,
|
|
433
|
+
used: false
|
|
432
434
|
};
|
|
433
435
|
const hyperlinks = {
|
|
434
436
|
start: state.hyperlinks.value,
|
|
@@ -446,6 +448,9 @@ var ProjectionBlockCache = class {
|
|
|
446
448
|
textBoxGroups.taken += 1;
|
|
447
449
|
return `${this.salt}:${state.textBoxGroups.value++}`;
|
|
448
450
|
},
|
|
451
|
+
placedTextBoxGroup: () => {
|
|
452
|
+
textBoxGroups.used = true;
|
|
453
|
+
},
|
|
449
454
|
nextHyperlinkInstanceIndex: () => {
|
|
450
455
|
hyperlinks.taken += 1;
|
|
451
456
|
return state.hyperlinks.value++;
|
|
@@ -467,12 +472,8 @@ var ProjectionBlockCache = class {
|
|
|
467
472
|
createMark: context.createMark,
|
|
468
473
|
...story
|
|
469
474
|
});
|
|
470
|
-
const saltMark = `"${this.salt}:`;
|
|
471
475
|
const reads = {
|
|
472
|
-
textBoxGroups: {
|
|
473
|
-
...textBoxGroups,
|
|
474
|
-
used: nodes.some((node) => JSON.stringify(node.toJSON()).includes(saltMark))
|
|
475
|
-
},
|
|
476
|
+
textBoxGroups: { ...textBoxGroups },
|
|
476
477
|
hyperlinks,
|
|
477
478
|
noteOccurrences,
|
|
478
479
|
pairedBookmarkIds: setReadsOf(pairedBookmarkIds),
|
|
@@ -594,6 +595,15 @@ function toProseDoc(document, options) {
|
|
|
594
595
|
const invalid = "Document conversion produced an invalid ProseMirror document";
|
|
595
596
|
if (cache === void 0) assertValidProseMirrorDocument(pmDoc, invalid);
|
|
596
597
|
else cache.validated = assertValidProseMirrorDocumentKeeping(pmDoc, invalid, cache.validated);
|
|
598
|
+
markupViewSources.set(pmDoc, {
|
|
599
|
+
document,
|
|
600
|
+
options: {
|
|
601
|
+
...packageInputs.styles === void 0 ? {} : { styles: packageInputs.styles },
|
|
602
|
+
theme: packageInputs.theme,
|
|
603
|
+
...cache === void 0 ? {} : { blockCache: cache },
|
|
604
|
+
textBoxGroupSalt: salt
|
|
605
|
+
}
|
|
606
|
+
});
|
|
597
607
|
return pmDoc;
|
|
598
608
|
}
|
|
599
609
|
/** The comments pending suggestions propose, by comment id. */
|
|
@@ -808,7 +818,7 @@ function convertParagraph(paragraph, styleResolver, context, extraRunFormatting,
|
|
|
808
818
|
let bookmarksArr;
|
|
809
819
|
let emptyHyperlinks;
|
|
810
820
|
let wrapperStack = [];
|
|
811
|
-
let
|
|
821
|
+
let paragraphKeepsBoundaryNodes = false;
|
|
812
822
|
const emitInlineNodes = (nodes, commentsAlreadyApplied = false) => {
|
|
813
823
|
if (nodes.length === 0) return;
|
|
814
824
|
const wrappedNodes = withInlineWrapperMark(nodes, wrapperStack);
|
|
@@ -843,11 +853,11 @@ function convertParagraph(paragraph, styleResolver, context, extraRunFormatting,
|
|
|
843
853
|
historical: getHistoricalRunFormatting
|
|
844
854
|
};
|
|
845
855
|
const emitTrackedChange = (change, markType, moveKind) => {
|
|
846
|
-
emitInlineNodes(convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runScope, trackedRunFormattingResolvers, styleResolver, moveKind, textBoxAnchors, wrapperStack, openCommentIds, { preserveSdtBoundaryOccurrences:
|
|
856
|
+
emitInlineNodes(convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runScope, trackedRunFormattingResolvers, styleResolver, moveKind, textBoxAnchors, wrapperStack, openCommentIds, { preserveSdtBoundaryOccurrences: paragraphKeepsBoundaryNodes }), true);
|
|
847
857
|
};
|
|
848
858
|
const stacked = withInlineWrapperStacks(withFieldWrapperCaptures(withLinkedPiecesInWrappers(paragraph.content)));
|
|
849
859
|
visitInlineContentSlots(paragraph, ({ item }) => {
|
|
850
|
-
if (item
|
|
860
|
+
if (keepsCommentBoundaryNodes(item)) paragraphKeepsBoundaryNodes = true;
|
|
851
861
|
});
|
|
852
862
|
const emptyRanges = planEmptyRanges(stacked.map((item) => item.content), stacked.map(({ stack }) => stack));
|
|
853
863
|
for (const [index, { content, stack }] of stacked.entries()) {
|
|
@@ -861,11 +871,11 @@ function convertParagraph(paragraph, styleResolver, context, extraRunFormatting,
|
|
|
861
871
|
switch (content.type) {
|
|
862
872
|
case "commentRangeStart":
|
|
863
873
|
openCommentIds.add(content.id);
|
|
864
|
-
if (
|
|
874
|
+
if (paragraphKeepsBoundaryNodes) emitInlineNodes([schema.node(COMMENT_RANGE_BOUNDARY_NODE_NAME, { marker: content })], true);
|
|
865
875
|
break;
|
|
866
876
|
case "commentRangeEnd":
|
|
867
877
|
openCommentIds.delete(content.id);
|
|
868
|
-
if (
|
|
878
|
+
if (paragraphKeepsBoundaryNodes) emitInlineNodes([schema.node(COMMENT_RANGE_BOUNDARY_NODE_NAME, { marker: content })], true);
|
|
869
879
|
break;
|
|
870
880
|
case "commentReference":
|
|
871
881
|
if (!storyRangedCommentIds.has(content.id)) anchorPointComment(inlineNodes, content.id);
|
|
@@ -1050,6 +1060,12 @@ const runPropertyChangeMark = (changes) => {
|
|
|
1050
1060
|
} : {}
|
|
1051
1061
|
});
|
|
1052
1062
|
};
|
|
1063
|
+
/**
|
|
1064
|
+
* A content control, or a link holding a comment boundary, writes its comment
|
|
1065
|
+
* boundaries as nodes. Every comment boundary beside it does too, so a range
|
|
1066
|
+
* ending outside such an item still runs between two nodes.
|
|
1067
|
+
*/
|
|
1068
|
+
const keepsCommentBoundaryNodes = (item) => item.type === "inlineSdt" || item.type === "hyperlink" && withInlineWrapperStacks(item.children).some(({ content }) => content.type === "commentRangeStart" || content.type === "commentRangeEnd");
|
|
1053
1069
|
function convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runScope, runFormattingResolvers, styleResolver, moveKind, textBoxAnchors, wrappedBy, openCommentIds, options = {}) {
|
|
1054
1070
|
const nodes = [];
|
|
1055
1071
|
const preserveParentBoundaryOwnership = options.preserveParentBoundaryOwnership ?? true;
|
|
@@ -1069,11 +1085,11 @@ function convertTrackedChange(change, markType, nextHyperlinkInstanceIndex, runS
|
|
|
1069
1085
|
};
|
|
1070
1086
|
const getTrackedRunFormatting = markType === "deletion" ? runFormattingResolvers.historical : runFormattingResolvers.current;
|
|
1071
1087
|
const stacked = withInlineWrapperStacks(change.content);
|
|
1072
|
-
let
|
|
1088
|
+
let keepsBoundaryNodes = false;
|
|
1073
1089
|
if (options.preserveSdtBoundaryOccurrences === void 0) visitInlineContentSlotsInContent(change.content, ({ item }) => {
|
|
1074
|
-
if (item
|
|
1090
|
+
if (keepsCommentBoundaryNodes(item)) keepsBoundaryNodes = true;
|
|
1075
1091
|
});
|
|
1076
|
-
const preserveBoundaryOccurrences = options.preserveSdtBoundaryOccurrences ??
|
|
1092
|
+
const preserveBoundaryOccurrences = options.preserveSdtBoundaryOccurrences ?? keepsBoundaryNodes;
|
|
1077
1093
|
const emptyRanges = planEmptyRanges(stacked.map(({ content }) => content), stacked.map(({ stack }) => stack));
|
|
1078
1094
|
for (const [index, { content: item, stack }] of stacked.entries()) {
|
|
1079
1095
|
if (!isTrackedChangeWrapperChild(item)) continue;
|
|
@@ -2981,6 +2997,7 @@ function convertShape(shape, runFormatting) {
|
|
|
2981
2997
|
}
|
|
2982
2998
|
function convertParagraphWithTextBoxes(block, styleResolver, { textBoxGroupId, context, extraRunFormatting, preserveEmptyWrapper, tableParagraphOverlay }) {
|
|
2983
2999
|
const { textBoxes, textBoxAnchors } = extractTextBoxesFromParagraph(block, textBoxGroupId);
|
|
3000
|
+
if (textBoxes.length > 0) context.placedTextBoxGroup?.();
|
|
2984
3001
|
const pmParagraph = convertParagraph(block, styleResolver, context, extraRunFormatting, tableParagraphOverlay, textBoxAnchors);
|
|
2985
3002
|
const nodes = [];
|
|
2986
3003
|
const isEmptyAfterExtraction = textBoxes.length > 0 && !hasContentBesidesTextBoxAnchors(pmParagraph);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
import { ResolvedMarkupDocumentView, RevisionDecision } from "@stll/docx-core/ops";
|
|
3
|
+
import { StepMap } from "prosemirror-transform";
|
|
4
|
+
type InlineChanges = NonNullable<ResolvedMarkupDocumentView["independentInline"]>;
|
|
5
|
+
type PositionRange = {
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
};
|
|
9
|
+
export type IndependentMarkupProjection = {
|
|
10
|
+
doc: Node;
|
|
11
|
+
positionMap: StepMap;
|
|
12
|
+
changeBarRanges: readonly PositionRange[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The native resolver supplies exactly which text ranges disappeared. Keep the
|
|
16
|
+
* original formatting and addresses of the rest, without converting standing
|
|
17
|
+
* blocks or reconstructing their run styles.
|
|
18
|
+
*/
|
|
19
|
+
export declare const projectIndependentMarkup: ({ doc, changes, indices }: {
|
|
20
|
+
doc: Node;
|
|
21
|
+
changes: InlineChanges;
|
|
22
|
+
/** For a detached source, where the inspected paragraphs originally stood. */
|
|
23
|
+
indices?: readonly number[];
|
|
24
|
+
}) => IndependentMarkupProjection | undefined;
|
|
25
|
+
/** Project a detached text story after canonical resolution of its text carriers. */
|
|
26
|
+
export declare const projectDetachedText: (doc: Node, decision: RevisionDecision) => IndependentMarkupProjection | undefined;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { expectTrackedChangeMarkAttrs } from "./attrs/index.js";
|
|
2
|
+
import "./extensions/marks/InlineWrapperExtension.js";
|
|
3
|
+
import { getFolioNodeRevisionCarriers } from "./revisionCarriers.js";
|
|
4
|
+
import { resolvedMarkupDocumentView } from "@stll/docx-core/ops";
|
|
5
|
+
import { Fragment } from "prosemirror-model";
|
|
6
|
+
import { StepMap } from "prosemirror-transform";
|
|
7
|
+
// src/prosemirror/independentMarkupProjection.ts
|
|
8
|
+
const isInlineRevision = (name) => name === "insertion" || name === "deletion";
|
|
9
|
+
const projectedText = (paragraph, { omitted }) => {
|
|
10
|
+
const nodes = [];
|
|
11
|
+
let cutIndex = 0;
|
|
12
|
+
for (let index = 0, start = 0; index < paragraph.childCount; index += 1) {
|
|
13
|
+
const node = paragraph.child(index);
|
|
14
|
+
if (!node.isText) return void 0;
|
|
15
|
+
const end = start + node.nodeSize;
|
|
16
|
+
const marks = node.marks.filter(({ type }) => !isInlineRevision(type.name));
|
|
17
|
+
let at = start;
|
|
18
|
+
for (let cut = omitted[cutIndex]; cut !== void 0 && cut.from < end;) {
|
|
19
|
+
if (cut.from > at) nodes.push(node.cut(at - start, cut.from - start).mark(marks));
|
|
20
|
+
at = Math.max(at, cut.to);
|
|
21
|
+
if (cut.to > end) break;
|
|
22
|
+
cutIndex += 1;
|
|
23
|
+
cut = omitted[cutIndex];
|
|
24
|
+
}
|
|
25
|
+
if (at < end) nodes.push(node.cut(at - start).mark(marks));
|
|
26
|
+
start = end;
|
|
27
|
+
}
|
|
28
|
+
return Fragment.fromArray(nodes);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The native resolver supplies exactly which text ranges disappeared. Keep the
|
|
32
|
+
* original formatting and addresses of the rest, without converting standing
|
|
33
|
+
* blocks or reconstructing their run styles.
|
|
34
|
+
*/
|
|
35
|
+
const projectIndependentMarkup = ({ doc, changes, indices }) => {
|
|
36
|
+
if (changes.length === 0) return {
|
|
37
|
+
doc,
|
|
38
|
+
positionMap: StepMap.empty,
|
|
39
|
+
changeBarRanges: []
|
|
40
|
+
};
|
|
41
|
+
const children = [];
|
|
42
|
+
const ranges = [];
|
|
43
|
+
const changeBarRanges = [];
|
|
44
|
+
let previous = 0;
|
|
45
|
+
let changeIndex = 0;
|
|
46
|
+
let removed = 0;
|
|
47
|
+
let last = -1;
|
|
48
|
+
for (let index = 0, position = 0; index < doc.childCount; index += 1) {
|
|
49
|
+
const original = doc.child(index);
|
|
50
|
+
const change = changes[changeIndex];
|
|
51
|
+
const target = change === void 0 ? void 0 : indices?.[change.index] ?? change.index;
|
|
52
|
+
if (change === void 0 || target !== index) {
|
|
53
|
+
children.push(original);
|
|
54
|
+
position += original.nodeSize;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (original.type.name !== "paragraph" || original.content.size !== change.sourceLength) return void 0;
|
|
58
|
+
const content = projectedText(original, change);
|
|
59
|
+
if (content === void 0) return void 0;
|
|
60
|
+
const paragraph = original.copy(content);
|
|
61
|
+
const from = position - removed;
|
|
62
|
+
changeBarRanges.push({
|
|
63
|
+
from,
|
|
64
|
+
to: from + paragraph.nodeSize
|
|
65
|
+
});
|
|
66
|
+
children.push(paragraph);
|
|
67
|
+
for (const { from: first, to } of change.omitted) {
|
|
68
|
+
const start = position + 1 + first;
|
|
69
|
+
const width = to - first;
|
|
70
|
+
if (start === last) ranges[previous + 1] = (ranges[previous + 1] ?? 0) + width;
|
|
71
|
+
else {
|
|
72
|
+
previous = ranges.length;
|
|
73
|
+
ranges.push(start, width, 0);
|
|
74
|
+
}
|
|
75
|
+
last = start + width;
|
|
76
|
+
removed += width;
|
|
77
|
+
}
|
|
78
|
+
position += original.nodeSize;
|
|
79
|
+
changeIndex += 1;
|
|
80
|
+
}
|
|
81
|
+
if (changeIndex !== changes.length) return void 0;
|
|
82
|
+
return {
|
|
83
|
+
doc: doc.copy(Fragment.fromArray(children)),
|
|
84
|
+
positionMap: new StepMap(ranges),
|
|
85
|
+
changeBarRanges
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/** Project a detached text story after canonical resolution of its text carriers. */
|
|
89
|
+
const projectDetachedText = (doc, decision) => {
|
|
90
|
+
const changed = [];
|
|
91
|
+
const indices = [];
|
|
92
|
+
for (let index = 0, position = 0; index < doc.childCount; index += 1) {
|
|
93
|
+
const paragraph = doc.child(index);
|
|
94
|
+
if (paragraph.type.name !== "paragraph" || paragraph.attrs["_suggestedInsert"] != null || getFolioNodeRevisionCarriers(paragraph, position).length > 0) return void 0;
|
|
95
|
+
let revised = false;
|
|
96
|
+
const content = [];
|
|
97
|
+
for (let childIndex = 0; childIndex < paragraph.childCount; childIndex += 1) {
|
|
98
|
+
const child = paragraph.child(childIndex);
|
|
99
|
+
if (!child.isText || child.text === void 0) return void 0;
|
|
100
|
+
let wrapper;
|
|
101
|
+
const run = {
|
|
102
|
+
type: "run",
|
|
103
|
+
content: [{
|
|
104
|
+
type: "text",
|
|
105
|
+
text: child.text
|
|
106
|
+
}]
|
|
107
|
+
};
|
|
108
|
+
for (const mark of child.marks) {
|
|
109
|
+
const type = mark.type.name;
|
|
110
|
+
if (type === "comment" || type === "hyperlink" || type === "runPropertyChange" || type === "inlineWrapper") return void 0;
|
|
111
|
+
if (type !== "insertion" && type !== "deletion") continue;
|
|
112
|
+
const attrs = expectTrackedChangeMarkAttrs(mark);
|
|
113
|
+
if (wrapper !== void 0 || attrs.moveKind != null || attrs._docxResolutionJoins != null || (attrs._docxRevisionAncestors?.length ?? 0) > 0) return void 0;
|
|
114
|
+
wrapper = {
|
|
115
|
+
type,
|
|
116
|
+
info: {
|
|
117
|
+
id: attrs.revisionId,
|
|
118
|
+
author: attrs.author
|
|
119
|
+
},
|
|
120
|
+
content: [run]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
revised ||= wrapper !== void 0;
|
|
124
|
+
content.push(wrapper ?? run);
|
|
125
|
+
}
|
|
126
|
+
if (revised) {
|
|
127
|
+
changed.push({
|
|
128
|
+
type: "paragraph",
|
|
129
|
+
content
|
|
130
|
+
});
|
|
131
|
+
indices.push(index);
|
|
132
|
+
}
|
|
133
|
+
position += paragraph.nodeSize;
|
|
134
|
+
}
|
|
135
|
+
if (changed.length === 0) return {
|
|
136
|
+
doc,
|
|
137
|
+
positionMap: StepMap.empty,
|
|
138
|
+
changeBarRanges: []
|
|
139
|
+
};
|
|
140
|
+
const resolved = resolvedMarkupDocumentView({ package: { document: { content: changed } } }, decision);
|
|
141
|
+
return resolved.independentInline === void 0 ? void 0 : projectIndependentMarkup({
|
|
142
|
+
doc,
|
|
143
|
+
changes: resolved.independentInline,
|
|
144
|
+
indices
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
export { projectDetachedText, projectIndependentMarkup };
|
|
@@ -12,4 +12,4 @@ import { DisplayMode } from "../managers/EditorModeManager.js";
|
|
|
12
12
|
import { document_d_exports } from "../types/document.js";
|
|
13
13
|
import { EditorState } from "prosemirror-state";
|
|
14
14
|
/** The footnotes or endnotes as `view` shows them. */
|
|
15
|
-
export declare const markupViewNotes: <TNote extends document_d_exports.Footnote | document_d_exports.Endnote>(notes: TNote[] | undefined, view: DisplayMode,
|
|
15
|
+
export declare const markupViewNotes: <TNote extends document_d_exports.Footnote | document_d_exports.Endnote>(notes: TNote[] | undefined, view: DisplayMode, _state: EditorState, document: document_d_exports.Document | null) => TNote[] | undefined;
|
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
import { resolveWholeStory } from "../internal/wholeStoryRevisionResolution.js";
|
|
2
|
-
import { proseDocToBlocks } from "./conversion/fromProseDoc.js";
|
|
3
|
-
import { footnoteToProseDoc } from "./conversion/toProseDoc.js";
|
|
4
1
|
import { markupViewResolutionMode } from "./markupViewProjection.js";
|
|
5
|
-
import {
|
|
6
|
-
import { getDocumentStyleResolver } from "./plugins/documentStyleState.js";
|
|
2
|
+
import { findStoryBody, resolvedMarkupDocumentView } from "@stll/docx-core/ops";
|
|
7
3
|
// src/prosemirror/markupViewNotes.ts
|
|
8
4
|
const resolvedNotes = /* @__PURE__ */ new WeakMap();
|
|
9
|
-
const resolvedNote = (note,
|
|
10
|
-
const
|
|
11
|
-
const cached =
|
|
12
|
-
if (cached
|
|
13
|
-
const
|
|
14
|
-
|
|
5
|
+
const resolvedNote = (note, decision, { styles, theme, numbering }) => {
|
|
6
|
+
const byDecision = resolvedNotes.get(note) ?? /* @__PURE__ */ new Map();
|
|
7
|
+
const cached = byDecision.get(decision);
|
|
8
|
+
if (cached !== void 0 && cached.styles === styles && cached.theme === theme && cached.numbering === numbering) return cached.note;
|
|
9
|
+
const source = { package: {
|
|
10
|
+
document: { content: [] },
|
|
11
|
+
...note.type === "footnote" ? { footnotes: [note] } : { endnotes: [note] },
|
|
15
12
|
...styles !== void 0 && { styles },
|
|
16
13
|
...theme !== void 0 && { theme },
|
|
17
14
|
...numbering !== void 0 && { numbering }
|
|
15
|
+
} };
|
|
16
|
+
const view = resolvedMarkupDocumentView(source, decision);
|
|
17
|
+
const body = findStoryBody(view.document, {
|
|
18
|
+
kind: note.type,
|
|
19
|
+
id: note.id
|
|
18
20
|
});
|
|
19
|
-
const
|
|
20
|
-
doc,
|
|
21
|
-
mode,
|
|
22
|
-
styleResolver,
|
|
23
|
-
numbering: getDocumentNumbering(state)
|
|
24
|
-
});
|
|
25
|
-
const resolved = result.failed || result.resolved.eq(doc) ? note : {
|
|
21
|
+
const resolved = body === void 0 || body.content === note.content ? note : {
|
|
26
22
|
...note,
|
|
27
|
-
content:
|
|
23
|
+
content: body.content
|
|
28
24
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
byDecision.set(decision, {
|
|
26
|
+
...styles !== void 0 && { styles },
|
|
27
|
+
...theme !== void 0 && { theme },
|
|
28
|
+
...numbering !== void 0 && { numbering },
|
|
32
29
|
note: resolved
|
|
33
30
|
});
|
|
34
|
-
resolvedNotes.set(note,
|
|
31
|
+
resolvedNotes.set(note, byDecision);
|
|
35
32
|
return resolved;
|
|
36
33
|
};
|
|
37
34
|
/** The footnotes or endnotes as `view` shows them. */
|
|
38
|
-
const markupViewNotes = (notes, view,
|
|
39
|
-
const
|
|
40
|
-
if (!notes || !
|
|
35
|
+
const markupViewNotes = (notes, view, _state, document) => {
|
|
36
|
+
const decision = markupViewResolutionMode(view);
|
|
37
|
+
if (!notes || !decision || !document) return notes;
|
|
41
38
|
let changed = false;
|
|
42
39
|
const shown = notes.map((note) => {
|
|
43
|
-
const resolved = resolvedNote(note,
|
|
40
|
+
const resolved = resolvedNote(note, decision, document.package);
|
|
44
41
|
changed ||= resolved !== note;
|
|
45
42
|
return resolved;
|
|
46
43
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
import { RevisionDecision } from "@stll/docx-core/ops";
|
|
3
|
+
import { StepMap } from "prosemirror-transform";
|
|
4
|
+
type MarkupViewPositionMapOptions = {
|
|
5
|
+
before: Node;
|
|
6
|
+
after: Node;
|
|
7
|
+
decision: RevisionDecision;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Match positions between authored and resolved projections. A surviving
|
|
11
|
+
* paragraph's closing edge anchors the region: on a join, preceding content
|
|
12
|
+
* can move into that paragraph, before its original opening edge. PM
|
|
13
|
+
* positions outside monotone matches are replacement ranges.
|
|
14
|
+
*/
|
|
15
|
+
export declare const markupViewPositionMap: ({ before, after, decision }: MarkupViewPositionMapOptions) => StepMap;
|
|
16
|
+
export {};
|