@stll/folio-core 0.68.0 → 0.69.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.js +2 -2
- package/dist/ai-edits/newListNumbering.d.ts +14 -1
- package/dist/ai-edits/newListNumbering.js +24 -1
- package/dist/ai-edits/pending-suggestions.js +2 -2
- package/dist/controller/canonicalClipboard.js +2 -2
- package/dist/controller/canonicalComposition.js +34 -5
- package/dist/controller/canonicalInput.js +4 -6
- package/dist/controller/canonicalLockGuard.d.ts +17 -2
- package/dist/controller/canonicalLockGuard.js +46 -1
- package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
- package/dist/controller/canonicalProjectionBlocks.js +75 -0
- package/dist/controller/canonicalPublicOperations.js +476 -100
- package/dist/controller/canonicalSeedContent.d.ts +12 -0
- package/dist/controller/canonicalSeedContent.js +131 -0
- package/dist/controller/canonicalSession.d.ts +53 -21
- package/dist/controller/canonicalSession.js +489 -210
- package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
- package/dist/controller/canonicalSourceNormalization.js +148 -0
- package/dist/controller/canonicalStoryEditor.d.ts +1 -1
- package/dist/controller/canonicalStoryEditor.js +16 -12
- package/dist/controller/folioEditor.js +3 -0
- package/dist/controller/headerFooterEditorManager.d.ts +5 -0
- package/dist/controller/headerFooterEditorManager.js +7 -2
- package/dist/controller/hiddenEditorApi.d.ts +11 -2
- package/dist/controller/hiddenEditorApi.js +3 -0
- package/dist/controller/hiddenEditorManager.d.ts +7 -0
- package/dist/controller/hiddenEditorManager.js +66 -11
- package/dist/controller/layoutPipeline.js +2 -1
- package/dist/controller/layoutSession.d.ts +3 -0
- package/dist/controller/layoutSession.js +3 -1
- package/dist/controller/noteEditorManager.d.ts +5 -0
- package/dist/controller/noteEditorManager.js +7 -2
- package/dist/display-list/dom/renderDisplayListToDom.js +9 -7
- package/dist/document-operations.d.ts +1 -1
- package/dist/docx/canonicalSave.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +19 -0
- package/dist/docx/commentAnchorIndex.js +55 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/contentTypeRegistry.js +1 -1
- package/dist/docx/hostCommentThreads.d.ts +11 -1
- package/dist/docx/hostCommentThreads.js +25 -2
- package/dist/docx/listModelNormalization.js +4 -5
- package/dist/docx/listNumberingInstances.d.ts +1 -1
- package/dist/docx/listNumberingInstances.js +2 -2
- package/dist/docx/numberingIds.d.ts +6 -0
- package/dist/docx/numberingIds.js +6 -1
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
- package/dist/docx/numberingReferenceNormalization.js +12 -2
- package/dist/docx/paragraphPropertySource.d.ts +22 -0
- package/dist/docx/paragraphPropertySource.js +85 -16
- package/dist/docx/parser.js +2 -0
- package/dist/docx/removeHeaderFooterParts.js +1 -1
- package/dist/docx/reviewResolutionProvenance.js +72 -19
- package/dist/docx/serializer/documentSerializer.js +2 -1
- package/dist/docx/serializer/partNamespaces.d.ts +1 -1
- package/dist/docx/serializer/partNamespaces.js +1 -1
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/storyBlockReplay.js +15 -2
- package/dist/docx/structuralXmlPatch.js +25 -4
- package/dist/docx/xmlParser.d.ts +1 -1
- package/dist/docx/xmlParser.js +2 -3
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
- package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
- package/dist/internal/subtreeHolds.d.ts +12 -0
- package/dist/internal/subtreeHolds.js +25 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
- package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
- package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
- package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
- package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
- package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
- package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
- package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
- package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
- package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
- package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
- package/dist/layout-bridge/dom/textStreamDom.js +3 -2
- package/dist/layout-bridge/headerFooterLayout.js +12 -11
- package/dist/layout-bridge/tableInsertHover.js +2 -1
- package/dist/layout-engine/measure/cache.d.ts +2 -0
- package/dist/layout-engine/measure/cache.js +6 -1
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
- package/dist/layout-engine/types.d.ts +6 -0
- package/dist/layout-painter/imageLayout.js +2 -1
- package/dist/layout-painter/pageShellStyles.d.ts +10 -0
- package/dist/layout-painter/pageShellStyles.js +32 -0
- package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
- package/dist/layout-painter/reconcileRenderedContent.js +117 -0
- package/dist/layout-painter/renderFragment.js +4 -6
- package/dist/layout-painter/renderImage.js +2 -2
- package/dist/layout-painter/renderPage.js +8 -29
- package/dist/layout-painter/renderParagraph.js +3 -3
- package/dist/layout-painter/renderTable.js +9 -12
- package/dist/layout-painter/renderTextBox.js +2 -2
- package/dist/layout-painter/sdtBoundary.js +3 -2
- package/dist/paged-layout/blockGeometry.js +3 -2
- package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
- package/dist/paged-layout/editorScrollRoot.js +10 -1
- package/dist/paged-layout/rangeProjection.js +5 -4
- package/dist/paged-layout/scrollToPmPosition.js +3 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
- package/dist/paged-layout/selectionViewportRect.js +8 -2
- package/dist/prosemirror/attrs/index.js +1 -0
- package/dist/prosemirror/commands/comments.d.ts +5 -2
- package/dist/prosemirror/commands/comments.js +88 -8
- package/dist/prosemirror/commentRecords.d.ts +137 -0
- package/dist/prosemirror/commentRecords.js +400 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +9 -3
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +13 -4
- package/dist/prosemirror/conversion/toProseDoc.js +126 -38
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
- package/dist/prosemirror/extensions/marks/CommentExtension.js +3 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
- package/dist/prosemirror/index.d.ts +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +33 -0
- package/dist/prosemirror/nativeSelection.js +74 -0
- package/dist/prosemirror/numberedRefFields.d.ts +2 -0
- package/dist/prosemirror/numberedRefFields.js +16 -5
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
- package/dist/prosemirror/paragraphMarkJoin.js +155 -16
- package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +33 -14
- package/dist/prosemirror/plugins/suggestionMode.js +13 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
- package/dist/prosemirror/schema/marks.d.ts +7 -1
- package/dist/prosemirror/storyListNumbering.js +7 -2
- package/dist/prosemirror/tableResize.d.ts +10 -9
- package/dist/prosemirror/tableResize.js +60 -49
- package/dist/prosemirror/textInput.d.ts +30 -1
- package/dist/prosemirror/textInput.js +144 -17
- package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
- package/dist/prosemirror/validation.d.ts +19 -0
- package/dist/prosemirror/validation.js +78 -5
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
- package/dist/render-dom/RenderedDomContext.js +7 -6
- package/dist/types/canonicalCapabilities.d.ts +12 -11
- package/dist/types/canonicalCapabilities.js +12 -13
- package/dist/utils/findMatchView.js +4 -3
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/dist/utils/mergeDocumentContent.js +2 -2
- package/dist/utils/paintedPositions.d.ts +60 -0
- package/dist/utils/paintedPositions.js +101 -0
- package/package.json +2 -3
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import "./commentIdAllocator.js";
|
|
2
|
+
import { isCommentRangeBoundaryNode, readCommentRangeBoundaryAttrs } from "./commentRangeBoundaryAttrs.js";
|
|
3
|
+
import { readCommentReferenceAttrs } from "./commentReferenceAttrs.js";
|
|
4
|
+
import "./commentReferenceIntegrity.js";
|
|
5
|
+
import "./extensions/nodes/RangeAnchorExtension.js";
|
|
6
|
+
import { createPluginKeyOwner } from "./pluginKeyOwner.js";
|
|
7
|
+
import { SUGGESTION_BYPASS_META } from "./plugins/suggestionMode.js";
|
|
8
|
+
import { readRangeAnchorAttrs } from "./rangeAnchorAttrs.js";
|
|
9
|
+
import { panic } from "better-result";
|
|
10
|
+
import { Step, StepMap, StepResult } from "prosemirror-transform";
|
|
11
|
+
import { Plugin, Selection } from "prosemirror-state";
|
|
12
|
+
import { closeHistory } from "prosemirror-history";
|
|
13
|
+
// src/prosemirror/commentRecords.ts
|
|
14
|
+
/**
|
|
15
|
+
* The comment threads of a ProseMirror session, held in its editor state.
|
|
16
|
+
*
|
|
17
|
+
* A thread's text, author, replies and resolution live beside the document,
|
|
18
|
+
* not in it, yet they are part of what the user edits: deleting a comment
|
|
19
|
+
* removes its record and its anchors together, and undoing that has to bring
|
|
20
|
+
* both back. Keeping the records in a host list outside the editor made every
|
|
21
|
+
* comment edit invisible to the editor's history, so undo restored the anchor
|
|
22
|
+
* at best and the save then lost the thread.
|
|
23
|
+
*
|
|
24
|
+
* Here the records change only through {@link CommentRecordsStep}, a step that
|
|
25
|
+
* leaves the document as it is and inverts to the records it replaced. Every
|
|
26
|
+
* comment edit is a transaction holding that step and, when the anchors
|
|
27
|
+
* change too, the mark and node steps beside it, so history undoes and redoes
|
|
28
|
+
* a comment edit as one. Hosts mirror the records from the state; saving, the
|
|
29
|
+
* controlled `comments` prop and document operations read the same records.
|
|
30
|
+
*/
|
|
31
|
+
const STEP_TYPE = "folioCommentRecords";
|
|
32
|
+
/**
|
|
33
|
+
* Replace the session's comment records. The document is unchanged, so the
|
|
34
|
+
* step maps nothing; its inverse puts back the records it replaced.
|
|
35
|
+
*/
|
|
36
|
+
var CommentRecordsStep = class CommentRecordsStep extends Step {
|
|
37
|
+
before;
|
|
38
|
+
after;
|
|
39
|
+
constructor(before, after) {
|
|
40
|
+
super();
|
|
41
|
+
this.before = before;
|
|
42
|
+
this.after = after;
|
|
43
|
+
}
|
|
44
|
+
apply(doc) {
|
|
45
|
+
return StepResult.ok(doc);
|
|
46
|
+
}
|
|
47
|
+
getMap() {
|
|
48
|
+
return StepMap.empty;
|
|
49
|
+
}
|
|
50
|
+
invert() {
|
|
51
|
+
return new CommentRecordsStep(this.after, this.before);
|
|
52
|
+
}
|
|
53
|
+
map() {
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
merge(other) {
|
|
57
|
+
return other instanceof CommentRecordsStep && other.before === this.after ? new CommentRecordsStep(this.before, other.after) : null;
|
|
58
|
+
}
|
|
59
|
+
toJSON() {
|
|
60
|
+
return {
|
|
61
|
+
stepType: STEP_TYPE,
|
|
62
|
+
before: this.before,
|
|
63
|
+
after: this.after
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
static fromJSON(_schema, json) {
|
|
67
|
+
if (typeof json !== "object" || json === null || !("before" in json) || !("after" in json) || !Array.isArray(json.before) || !Array.isArray(json.after)) throw new RangeError("Invalid comment records step JSON");
|
|
68
|
+
const { before, after } = json;
|
|
69
|
+
return new CommentRecordsStep(before, after);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
Step.jsonID(STEP_TYPE, CommentRecordsStep);
|
|
73
|
+
const commentRecordsOwner = createPluginKeyOwner("commentRecords");
|
|
74
|
+
const SYNC_META = `${commentRecordsOwner.key}.sync`;
|
|
75
|
+
const listeners = /* @__PURE__ */ new WeakMap();
|
|
76
|
+
/**
|
|
77
|
+
* The plugin that holds a session's comment records, starting from `initial`
|
|
78
|
+
* (the loaded document's comments).
|
|
79
|
+
*/
|
|
80
|
+
function createCommentRecordsPlugin(initial) {
|
|
81
|
+
return new Plugin({
|
|
82
|
+
key: commentRecordsOwner.createKey(),
|
|
83
|
+
state: {
|
|
84
|
+
init: () => ({
|
|
85
|
+
records: initial,
|
|
86
|
+
origin: "sync"
|
|
87
|
+
}),
|
|
88
|
+
apply: (transaction, value) => {
|
|
89
|
+
let records = value.records;
|
|
90
|
+
for (const step of transaction.steps) if (step instanceof CommentRecordsStep) records = step.after;
|
|
91
|
+
if (records === value.records) return value;
|
|
92
|
+
return {
|
|
93
|
+
records,
|
|
94
|
+
origin: transaction.getMeta(SYNC_META) === true ? "sync" : "edit"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
view: (created) => {
|
|
99
|
+
const current = commentRecordsOwner.getState(created.state);
|
|
100
|
+
if (current) for (const listener of listeners.get(created) ?? []) listener(current.records, "sync");
|
|
101
|
+
return {
|
|
102
|
+
update: (view, previous) => {
|
|
103
|
+
const next = commentRecordsOwner.getState(view.state);
|
|
104
|
+
if (!next || next === commentRecordsOwner.getState(previous)) return;
|
|
105
|
+
for (const listener of listeners.get(view) ?? []) listener(next.records, next.origin);
|
|
106
|
+
},
|
|
107
|
+
destroy: () => {
|
|
108
|
+
for (const listener of listeners.get(created) ?? []) listener(null, "sync");
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** The session's comment records, or `null` when the state holds none. */
|
|
115
|
+
function commentRecordsOf(state) {
|
|
116
|
+
return commentRecordsOwner.getState(state)?.records ?? null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Call `listener` whenever the view's comment records change, including a
|
|
120
|
+
* state the view is given for a newly loaded document. Returns the
|
|
121
|
+
* unsubscribe function.
|
|
122
|
+
*/
|
|
123
|
+
function subscribeCommentRecords(view, listener) {
|
|
124
|
+
let set = listeners.get(view);
|
|
125
|
+
if (!set) {
|
|
126
|
+
set = /* @__PURE__ */ new Set();
|
|
127
|
+
listeners.set(view, set);
|
|
128
|
+
}
|
|
129
|
+
set.add(listener);
|
|
130
|
+
return () => {
|
|
131
|
+
set.delete(listener);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** The records a transaction ends on, given the state it started from. */
|
|
135
|
+
function commentRecordsAfter(state, transaction) {
|
|
136
|
+
let records = commentRecordsOf(state);
|
|
137
|
+
if (records === null) return null;
|
|
138
|
+
for (const step of transaction.steps) if (step instanceof CommentRecordsStep) records = step.after;
|
|
139
|
+
return records;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Add the step replacing the records `transaction` ends on with `next`.
|
|
143
|
+
* Returns false when the state holds no records.
|
|
144
|
+
*/
|
|
145
|
+
function stepCommentRecords(state, transaction, next) {
|
|
146
|
+
const current = commentRecordsAfter(state, transaction);
|
|
147
|
+
if (current === null) return false;
|
|
148
|
+
if (current !== next) transaction.step(new CommentRecordsStep(current, next));
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A transaction writing a host's value into the records: kept out of the
|
|
153
|
+
* undo history and reported as `sync`, so it is not echoed back to the host.
|
|
154
|
+
*/
|
|
155
|
+
function syncCommentRecords(state, next) {
|
|
156
|
+
const current = commentRecordsOf(state);
|
|
157
|
+
if (current === null || current === next) return null;
|
|
158
|
+
return state.tr.step(new CommentRecordsStep(current, next)).setMeta("addToHistory", false).setMeta(SYNC_META, true);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Whether a transaction only writes a host's comment list in: no document
|
|
162
|
+
* content and no user edit changes, so it neither marks the document changed
|
|
163
|
+
* nor needs an editable document.
|
|
164
|
+
*/
|
|
165
|
+
function isCommentRecordsSync(transaction) {
|
|
166
|
+
return transaction.getMeta(SYNC_META) === true && transaction.steps.length > 0 && transaction.steps.every((step) => step instanceof CommentRecordsStep);
|
|
167
|
+
}
|
|
168
|
+
/** A comment and every reply whose parent chain reaches it. */
|
|
169
|
+
function commentThreadIds(records, id) {
|
|
170
|
+
const ids = /* @__PURE__ */ new Set([id]);
|
|
171
|
+
let added = true;
|
|
172
|
+
while (added) {
|
|
173
|
+
added = false;
|
|
174
|
+
for (const comment of records) if (!ids.has(comment.id) && comment.parentId !== void 0 && ids.has(comment.parentId)) {
|
|
175
|
+
ids.add(comment.id);
|
|
176
|
+
added = true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return ids;
|
|
180
|
+
}
|
|
181
|
+
const editTransaction = (state) => closeHistory(state.tr).setMeta(SUGGESTION_BYPASS_META, true);
|
|
182
|
+
/**
|
|
183
|
+
* An undoable edit replacing the records with `next`, for a host change that
|
|
184
|
+
* touches no anchor (a reply, a resolution, a list the host computed).
|
|
185
|
+
*/
|
|
186
|
+
function editCommentRecords(state, next) {
|
|
187
|
+
const records = commentRecordsOf(state);
|
|
188
|
+
if (records === null || records === next) return null;
|
|
189
|
+
const tr = editTransaction(state);
|
|
190
|
+
stepCommentRecords(state, tr, next);
|
|
191
|
+
return tr;
|
|
192
|
+
}
|
|
193
|
+
/** Append comments (new threads or replies) to the records. */
|
|
194
|
+
function appendCommentRecords(state, additions) {
|
|
195
|
+
const records = commentRecordsOf(state);
|
|
196
|
+
if (records === null || additions.length === 0) return null;
|
|
197
|
+
const tr = editTransaction(state);
|
|
198
|
+
stepCommentRecords(state, tr, [...records, ...additions]);
|
|
199
|
+
return tr;
|
|
200
|
+
}
|
|
201
|
+
/** Mark one comment resolved or open again. */
|
|
202
|
+
function setCommentResolved(state, id, done) {
|
|
203
|
+
const records = commentRecordsOf(state);
|
|
204
|
+
if (records === null) return null;
|
|
205
|
+
const index = records.findIndex((comment) => comment.id === id);
|
|
206
|
+
const comment = records[index];
|
|
207
|
+
if (!comment || (comment.done ?? false) === done) return null;
|
|
208
|
+
const next = records.with(index, {
|
|
209
|
+
...comment,
|
|
210
|
+
done
|
|
211
|
+
});
|
|
212
|
+
const tr = editTransaction(state);
|
|
213
|
+
stepCommentRecords(state, tr, next);
|
|
214
|
+
return tr;
|
|
215
|
+
}
|
|
216
|
+
const clampRange = (state, range) => {
|
|
217
|
+
const size = state.doc.content.size;
|
|
218
|
+
const from = Math.max(0, Math.min(range.from, size));
|
|
219
|
+
const to = Math.max(from, Math.min(range.to, size));
|
|
220
|
+
return from === to ? null : {
|
|
221
|
+
from,
|
|
222
|
+
to
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Anchor a new thread on `range` and add its record, in one transaction.
|
|
227
|
+
* Returns null when the range is empty or out of the document.
|
|
228
|
+
*/
|
|
229
|
+
function addCommentThread(state, range, comment) {
|
|
230
|
+
const records = commentRecordsOf(state);
|
|
231
|
+
const commentType = state.schema.marks["comment"];
|
|
232
|
+
const safe = clampRange(state, range);
|
|
233
|
+
if (records === null || !commentType || !safe) return null;
|
|
234
|
+
const tr = editTransaction(state).addMark(safe.from, safe.to, commentType.create({ commentId: comment.id }));
|
|
235
|
+
stepCommentRecords(state, tr, [...records, comment]);
|
|
236
|
+
return tr;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Show the add-comment flow's highlight on `range`. The highlight is not an
|
|
240
|
+
* edit: it stays out of the undo history, so undoing a comment never brings
|
|
241
|
+
* it back.
|
|
242
|
+
*/
|
|
243
|
+
function markPendingComment(view, range, options) {
|
|
244
|
+
const commentType = view.state.schema.marks["comment"];
|
|
245
|
+
const safe = clampRange(view.state, range);
|
|
246
|
+
if (!commentType || !safe) return false;
|
|
247
|
+
const tr = view.state.tr.addMark(safe.from, safe.to, commentType.create({ commentId: -1 })).setMeta("addToHistory", false).setMeta(SUGGESTION_BYPASS_META, true);
|
|
248
|
+
if (options?.selectEnd) tr.setSelection(Selection.near(tr.doc.resolve(safe.to), -1));
|
|
249
|
+
view.dispatch(tr);
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
/** Remove the add-comment flow's highlight from `range`. */
|
|
253
|
+
function clearPendingComment(view, range) {
|
|
254
|
+
const commentType = view.state.schema.marks["comment"];
|
|
255
|
+
const safe = clampRange(view.state, range);
|
|
256
|
+
if (!commentType || !safe) return;
|
|
257
|
+
const pending = commentType.create({ commentId: -1 });
|
|
258
|
+
if (!view.state.doc.rangeHasMark(safe.from, safe.to, pending)) return;
|
|
259
|
+
view.dispatch(view.state.tr.removeMark(safe.from, safe.to, pending).setMeta("addToHistory", false).setMeta(SUGGESTION_BYPASS_META, true));
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The add-comment flow's commit: the highlight on `range` gives way to the
|
|
263
|
+
* new thread's mark, and the thread joins the records, as one undoable edit.
|
|
264
|
+
*/
|
|
265
|
+
function commitCommentThread(view, range, comment) {
|
|
266
|
+
if (!addCommentThread(view.state, range, comment)) return false;
|
|
267
|
+
clearPendingComment(view, range);
|
|
268
|
+
const tr = addCommentThread(view.state, range, comment);
|
|
269
|
+
if (!tr) return false;
|
|
270
|
+
view.dispatch(tr);
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
const anchoredCommentId = (node) => {
|
|
274
|
+
if (node.type.name === "commentReference") {
|
|
275
|
+
const attrs = readCommentReferenceAttrs(node);
|
|
276
|
+
return attrs.ok ? attrs.value.commentId : void 0;
|
|
277
|
+
}
|
|
278
|
+
if (isCommentRangeBoundaryNode(node)) {
|
|
279
|
+
const attrs = readCommentRangeBoundaryAttrs(node);
|
|
280
|
+
return attrs.ok ? attrs.value.marker.id : void 0;
|
|
281
|
+
}
|
|
282
|
+
if (node.type.name === "rangeAnchor") {
|
|
283
|
+
const attrs = readRangeAnchorAttrs(node);
|
|
284
|
+
return attrs.ok && attrs.value.start.type === "commentRangeStart" ? attrs.value.start.id : void 0;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Remove every anchor of the comments in `ids` from the transaction's
|
|
289
|
+
* document: their `comment` marks, references and range boundaries.
|
|
290
|
+
*/
|
|
291
|
+
function removeCommentAnchors(transaction, ids) {
|
|
292
|
+
const marks = [];
|
|
293
|
+
const nodes = [];
|
|
294
|
+
transaction.doc.descendants((node, position) => {
|
|
295
|
+
for (const mark of node.marks) {
|
|
296
|
+
const commentId = mark.attrs["commentId"];
|
|
297
|
+
if (mark.type.name === "comment" && typeof commentId === "number" && ids.has(commentId)) marks.push({
|
|
298
|
+
from: position,
|
|
299
|
+
to: position + node.nodeSize,
|
|
300
|
+
mark
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
const anchored = anchoredCommentId(node);
|
|
304
|
+
if (anchored !== void 0 && ids.has(anchored)) {
|
|
305
|
+
nodes.push({
|
|
306
|
+
from: position,
|
|
307
|
+
to: position + node.nodeSize
|
|
308
|
+
});
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
return true;
|
|
312
|
+
});
|
|
313
|
+
for (const { from, to, mark } of marks) transaction.removeMark(from, to, mark);
|
|
314
|
+
for (const { from, to } of nodes.toReversed()) transaction.delete(from, to);
|
|
315
|
+
}
|
|
316
|
+
/** Delete a thread: its record, every reply under it, and its anchors. */
|
|
317
|
+
function deleteCommentThread(state, id) {
|
|
318
|
+
const records = commentRecordsOf(state);
|
|
319
|
+
if (records === null) return null;
|
|
320
|
+
const ids = commentThreadIds(records, id);
|
|
321
|
+
const next = records.filter((comment) => !ids.has(comment.id));
|
|
322
|
+
const tr = editTransaction(state);
|
|
323
|
+
removeCommentAnchors(tr, ids);
|
|
324
|
+
stepCommentRecords(state, tr, next);
|
|
325
|
+
return tr.steps.length > 0 ? tr : null;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* The comment ids a document names through a mark, reference or range
|
|
329
|
+
* boundary.
|
|
330
|
+
*/
|
|
331
|
+
function commentIdsNamedIn(doc) {
|
|
332
|
+
const ids = /* @__PURE__ */ new Set();
|
|
333
|
+
doc.descendants((node) => {
|
|
334
|
+
for (const mark of node.marks) {
|
|
335
|
+
const commentId = mark.attrs["commentId"];
|
|
336
|
+
if (mark.type.name === "comment" && typeof commentId === "number") ids.add(commentId);
|
|
337
|
+
}
|
|
338
|
+
const anchored = anchoredCommentId(node);
|
|
339
|
+
if (anchored !== void 0) ids.add(anchored);
|
|
340
|
+
return true;
|
|
341
|
+
});
|
|
342
|
+
return ids;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Remove the threads a review resolution left without any anchor: accepting
|
|
346
|
+
* the deletion of everything a comment covers, or rejecting the suggestion
|
|
347
|
+
* that inserted it, retires the comment with its replies, in the same
|
|
348
|
+
* transaction. Other edits keep records whose anchors are gone for now (a
|
|
349
|
+
* cut keeps the thread for the paste).
|
|
350
|
+
*/
|
|
351
|
+
function retireThreadsResolvedAway(state, transaction) {
|
|
352
|
+
if (transaction.doc === state.doc) return;
|
|
353
|
+
const records = commentRecordsAfter(state, transaction);
|
|
354
|
+
if (records === null || records.length === 0) return;
|
|
355
|
+
const before = commentIdsNamedIn(state.doc);
|
|
356
|
+
if (before.size === 0) return;
|
|
357
|
+
const after = commentIdsNamedIn(transaction.doc);
|
|
358
|
+
const retired = /* @__PURE__ */ new Set();
|
|
359
|
+
for (const id of before) {
|
|
360
|
+
if (after.has(id) || id === -1) continue;
|
|
361
|
+
for (const threadId of commentThreadIds(records, id)) retired.add(threadId);
|
|
362
|
+
}
|
|
363
|
+
if (retired.size === 0) return;
|
|
364
|
+
const next = records.filter(({ id }) => !retired.has(id));
|
|
365
|
+
if (next.length !== records.length) stepCommentRecords(state, transaction, next);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Add the records of `created` comments that `transaction`'s document names
|
|
369
|
+
* and the records lack, so comments a document operation anchors join the
|
|
370
|
+
* records in the operation's own transaction.
|
|
371
|
+
*/
|
|
372
|
+
function recordCreatedComments(state, transaction, created) {
|
|
373
|
+
if (created.length === 0) return;
|
|
374
|
+
const records = commentRecordsAfter(state, transaction);
|
|
375
|
+
if (records === null) return;
|
|
376
|
+
const known = new Set(records.map(({ id }) => id));
|
|
377
|
+
const named = commentIdsNamedIn(transaction.doc);
|
|
378
|
+
const additions = created.filter(({ id }) => named.has(id) && !known.has(id));
|
|
379
|
+
if (additions.length > 0) stepCommentRecords(state, transaction, [...records, ...additions]);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* `view` for a document operation: its dispatch adds the records of the
|
|
383
|
+
* `created` comments the operation anchors, in the operation's transaction.
|
|
384
|
+
*/
|
|
385
|
+
function recordingCommentsView(view, created) {
|
|
386
|
+
return {
|
|
387
|
+
get state() {
|
|
388
|
+
return view.state;
|
|
389
|
+
},
|
|
390
|
+
dispatch: (transaction) => {
|
|
391
|
+
recordCreatedComments(view.state, transaction, created);
|
|
392
|
+
view.dispatch(transaction);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
/** Panic unless the state holds records; for callers that require them. */
|
|
397
|
+
function expectCommentRecords(state) {
|
|
398
|
+
return commentRecordsOf(state) ?? panic("The editor state holds no comments.");
|
|
399
|
+
}
|
|
400
|
+
export { CommentRecordsStep, addCommentThread, appendCommentRecords, clearPendingComment, commentIdsNamedIn, commentRecordsAfter, commentRecordsOf, commentThreadIds, commitCommentThread, createCommentRecordsPlugin, deleteCommentThread, editCommentRecords, expectCommentRecords, isCommentRecordsSync, markPendingComment, recordCreatedComments, recordingCommentsView, removeCommentAnchors, retireThreadsResolvedAway, setCommentResolved, stepCommentRecords, subscribeCommentRecords, syncCommentRecords };
|
|
@@ -450,8 +450,13 @@ function fromProseDoc(pmDoc, baseDocument, { stylesheetSource, reuse = "none" })
|
|
|
450
450
|
const isSuggestedMark = (mark) => mark.attrs["provenance"] === "suggested";
|
|
451
451
|
const hasSuggestedInsertion = (marks) => marks.some((mark) => mark.type.name === "insertion" && isSuggestedMark(mark));
|
|
452
452
|
/**
|
|
453
|
+
* A comment a pending suggestion proposes: it has no range in the file until
|
|
454
|
+
* the suggestion is accepted, so the save's orphan pruning leaves it out too.
|
|
455
|
+
*/
|
|
456
|
+
const isSuggestedCommentMark = (mark) => mark.type.name === "comment" && typeof mark.attrs["suggestionId"] === "string";
|
|
457
|
+
/**
|
|
453
458
|
* Compute the mark set an inline node should keep once its suggested tracked
|
|
454
|
-
* changes are stripped. Suggested deletions are dropped so their text survives
|
|
459
|
+
* changes and proposed comments are stripped. Suggested deletions are dropped so their text survives
|
|
455
460
|
* as plain content; a suggested `runPropertyChange` is dropped and the run's
|
|
456
461
|
* live formatting is reverted to the recorded `previousFormatting`.
|
|
457
462
|
*
|
|
@@ -461,8 +466,9 @@ const hasSuggestedInsertion = (marks) => marks.some((mark) => mark.type.name ===
|
|
|
461
466
|
function stripSuggestedInlineMarks(marks, readFormattingContext) {
|
|
462
467
|
const hasSuggestedDeletion = marks.some((mark) => mark.type.name === "deletion" && isSuggestedMark(mark));
|
|
463
468
|
const suggestedRunPropertyChange = marks.find((mark) => mark.type.name === "runPropertyChange" && isSuggestedMark(mark));
|
|
464
|
-
|
|
465
|
-
|
|
469
|
+
const hasSuggestedComment = marks.some(isSuggestedCommentMark);
|
|
470
|
+
if (!hasSuggestedDeletion && !suggestedRunPropertyChange && !hasSuggestedComment) return marks;
|
|
471
|
+
let next = marks.filter((mark) => !((mark.type.name === "deletion" || mark.type.name === "runPropertyChange") && isSuggestedMark(mark) || isSuggestedCommentMark(mark)));
|
|
466
472
|
if (suggestedRunPropertyChange) {
|
|
467
473
|
const { baseParagraphFormatting, inheritedFormatting, paragraphMarkFormatting, styleResolver } = readFormattingContext();
|
|
468
474
|
const previousFormatting = expectRunPropertyChangeMarkAttrs(suggestedRunPropertyChange).changes.at(0)?.previousFormatting;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { ProseMirrorDocumentValidationIssue, ValidateProseMirrorDocumentResult, assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "../validation.js";
|
|
1
2
|
import { ToProseDocOptions, createEmptyDoc, headerFooterToProseDoc, toProseDoc } from "./toProseDoc.js";
|
|
2
3
|
import { FromProseDocOptions, ProjectionReuse, fromProseDoc, proseDocToBlocks, updateDocumentContent } from "./fromProseDoc.js";
|
|
3
|
-
import { ProseMirrorDocumentValidationIssue, ValidateProseMirrorDocumentResult, assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "../validation.js";
|
|
4
4
|
export { type FromProseDocOptions, type ProjectionReuse, type ProseMirrorDocumentValidationIssue, type ToProseDocOptions, type ValidateProseMirrorDocumentResult, assertValidProseMirrorDocument, createEmptyDoc, formatProseMirrorDocumentIssues, fromProseDoc, headerFooterToProseDoc, proseDocToBlocks, toProseDoc, updateDocumentContent, validateProseMirrorDocument };
|
|
@@ -7,6 +7,8 @@ import { ListRenderingDefinition } from "../../docx/listRendering.js";
|
|
|
7
7
|
import { ParseContext } from "../../docx/parseContext.js";
|
|
8
8
|
import { PageBreakRunSourceDescendantIndex } from "../../internal/pageBreakRunSourceDescendantIndex.js";
|
|
9
9
|
import { MarkFactory } from "../extensions/marks/markUtils.js";
|
|
10
|
+
import { CarrierContinuationCache } from "../runIdentityAcrossRevisions.js";
|
|
11
|
+
import { ValidatedStory } from "../validation.js";
|
|
10
12
|
import { Node } from "prosemirror-model";
|
|
11
13
|
/**
|
|
12
14
|
* Options for document conversion
|
|
@@ -41,10 +43,13 @@ export type ToProseDocOptions = {
|
|
|
41
43
|
type PageBreakProjectionWarn = (detail: string) => void;
|
|
42
44
|
type HyperlinkInstanceIndexAllocator = () => number;
|
|
43
45
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
46
|
+
* Every bookmark boundary of a story's blocks, in the document order the
|
|
47
|
+
* conversion meets them, across every editable inline wrapper. Each endpoint
|
|
48
|
+
* is converted at its own structural position, so a range may start outside
|
|
49
|
+
* a hyperlink and end inside it (or the inverse).
|
|
47
50
|
*/
|
|
51
|
+
export declare const visitBookmarkBoundaries: (blocks: readonly document_d_exports.BlockContent[], countBoundary: (id: number, type: "start" | "end") => void) => void;
|
|
52
|
+
/** The bookmarks of a story's blocks whose one start opens before their one end. */
|
|
48
53
|
export declare const collectPairedBookmarkIds: (blocks: readonly document_d_exports.BlockContent[]) => ReadonlySet<number>;
|
|
49
54
|
/**
|
|
50
55
|
* What each field of the conversion context depends on: the package alone,
|
|
@@ -105,6 +110,10 @@ type ProjectionPackageInputs = {
|
|
|
105
110
|
*/
|
|
106
111
|
export declare class ProjectionBlockCache {
|
|
107
112
|
readonly salt: string;
|
|
113
|
+
/** The story's top-level blocks as the last pass continued them. */
|
|
114
|
+
readonly carriers: CarrierContinuationCache;
|
|
115
|
+
/** The last story document that passed validation. */
|
|
116
|
+
validated: ValidatedStory | undefined;
|
|
108
117
|
private inputs;
|
|
109
118
|
private context;
|
|
110
119
|
private blocks;
|
|
@@ -116,7 +125,7 @@ export declare class ProjectionBlockCache {
|
|
|
116
125
|
* The nodes of `paragraph` from the story state it starts at, reused when
|
|
117
126
|
* every story fact its last conversion read still holds, else converted.
|
|
118
127
|
*/
|
|
119
|
-
|
|
128
|
+
block(block: document_d_exports.Paragraph | document_d_exports.Table, state: StoryState, convert: (context: TableConversionContext) => Node[]): readonly Node[];
|
|
120
129
|
}
|
|
121
130
|
/**
|
|
122
131
|
* Convert a Document to a ProseMirror document
|