@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
|
@@ -10,7 +10,7 @@ import { buildSections } from "../docx/documentParser.js";
|
|
|
10
10
|
import { rebindDrawingImageRelationship } from "../docx/drawingRelationships.js";
|
|
11
11
|
import { isSeparatorEndnote, isSeparatorFootnote } from "../docx/footnoteParser.js";
|
|
12
12
|
import { normalizeListModelRendering } from "../docx/listModelNormalization.js";
|
|
13
|
-
import { createNumberingIdAllocator } from "../docx/numberingIds.js";
|
|
13
|
+
import { createNumberingIdAllocator, numberingNumIdsTaken } from "../docx/numberingIds.js";
|
|
14
14
|
import { getCachedNumberingMap } from "../docx/numberingParser.js";
|
|
15
15
|
import { visitDocxParagraphs } from "../docx/paragraphTraversal.js";
|
|
16
16
|
import { parseDocx } from "../docx/parser.js";
|
|
@@ -599,7 +599,7 @@ var FolioDocxReviewer = class FolioDocxReviewer {
|
|
|
599
599
|
const targetNums = new Map(target.nums.map((entry) => [entry.numId, entry]));
|
|
600
600
|
const targetAbstracts = new Map(target.abstractNums.map((entry) => [entry.abstractNumId, entry]));
|
|
601
601
|
const levelsByNumId = referencedNumberingLevelsByNumId({ references });
|
|
602
|
-
const existingNumIds = [...
|
|
602
|
+
const existingNumIds = [...numberingNumIdsTaken(current), ...numberingNumIdsTaken(target)];
|
|
603
603
|
const numberingIds = createNumberingIdAllocator("num", existingNumIds);
|
|
604
604
|
const remapped = /* @__PURE__ */ new Map();
|
|
605
605
|
for (const numId of levelsByNumId.keys()) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
1
2
|
import { NumberingIdsInUse } from "../docx/numberingIds.js";
|
|
2
3
|
import { FolioContentStatedNumbering } from "../compare/content-types.js";
|
|
3
4
|
import { ListKind } from "../docx/listNumberingInstances.js";
|
|
4
|
-
import { FolioAIEditOperation, FolioAIListNumbering, FolioAINewListReference, FolioAIResolvedEditOperation } from "./types.js";
|
|
5
|
+
import { FolioAIEditOperation, FolioAIListKind, FolioAIListNumbering, FolioAINewListReference, FolioAIResolvedEditOperation } from "./types.js";
|
|
5
6
|
import { NumberingMap } from "../docx/numberingParser.js";
|
|
7
|
+
import { NewListInstance } from "@stll/docx-core/ops";
|
|
6
8
|
/** Whether `numbering` asks for a new list rather than naming an instance. */
|
|
7
9
|
export declare const isFolioAINewListReference: (numbering: FolioAIListNumbering) => numbering is FolioAINewListReference;
|
|
8
10
|
type ResolvedNewLists = {
|
|
@@ -28,4 +30,15 @@ export declare const stageNewListOperations: (operations: readonly FolioAIEditOp
|
|
|
28
30
|
* minted instance takes.
|
|
29
31
|
*/
|
|
30
32
|
export declare const resolveNewListOperations: (operations: readonly FolioAIStagedEditOperation[], numbering: NumberingMap | null, elsewhere: NumberingIdsInUse) => ResolvedNewLists;
|
|
33
|
+
/** A list one operation starts: its instance id and the definitions it adds. */
|
|
34
|
+
export type MintedList = {
|
|
35
|
+
numId: number;
|
|
36
|
+
newList: NewListInstance;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Mints new lists for one batch of a canonical session, each after the ones
|
|
40
|
+
* before it. The document is read at the first mint, so a batch that starts
|
|
41
|
+
* no list never reads it.
|
|
42
|
+
*/
|
|
43
|
+
export declare const createBatchListMinter: (document: () => document_d_exports.Document) => (format: FolioAIListKind) => MintedList;
|
|
31
44
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mintListInstance } from "../docx/listNumberingInstances.js";
|
|
2
|
+
import { NO_NUMBERING_IDS_IN_USE } from "../docx/numberingIds.js";
|
|
2
3
|
import { createNumberingMap } from "../docx/numberingParser.js";
|
|
3
4
|
import { paragraphNumberingReference } from "../docx/numberingReference.js";
|
|
4
5
|
import { panic } from "better-result";
|
|
@@ -150,4 +151,26 @@ const resolveNewListOperations = (operations, numbering, elsewhere) => {
|
|
|
150
151
|
numbering: minted && definitions ? createNumberingMap(definitions) : numbering
|
|
151
152
|
};
|
|
152
153
|
};
|
|
153
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Mints new lists for one batch of a canonical session, each after the ones
|
|
156
|
+
* before it. The document is read at the first mint, so a batch that starts
|
|
157
|
+
* no list never reads it.
|
|
158
|
+
*/
|
|
159
|
+
const createBatchListMinter = (document) => {
|
|
160
|
+
let definitions = null;
|
|
161
|
+
return (format) => {
|
|
162
|
+
definitions ??= document().package.numbering;
|
|
163
|
+
const minted = mintListInstance(definitions, { kind: format }, NO_NUMBERING_IDS_IN_USE);
|
|
164
|
+
definitions = minted.definitions;
|
|
165
|
+
const num = minted.definitions.nums.find(({ numId }) => numId === minted.numId) ?? panic("A minted list is missing its instance.");
|
|
166
|
+
const abstractNum = minted.definitions.abstractNums.find(({ abstractNumId }) => abstractNumId === num.abstractNumId);
|
|
167
|
+
return {
|
|
168
|
+
numId: minted.numId,
|
|
169
|
+
newList: {
|
|
170
|
+
num,
|
|
171
|
+
...abstractNum === void 0 ? {} : { abstractNum }
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
export { assertNewListsAllocated, createBatchListMinter, isFolioAINewListReference, resolveNewListOperations, stageNewListOperations };
|
|
@@ -82,7 +82,7 @@ const parseRecord = (value) => {
|
|
|
82
82
|
return null;
|
|
83
83
|
}
|
|
84
84
|
if (operationBlockId(operation) !== anchor["blockId"] || (operation.suggestionId ?? operation.id) !== value["suggestionId"] || getFolioParaIdFromBlockId(anchor["blockId"]) !== anchor["paraId"]) return null;
|
|
85
|
-
if (operation.type === "replaceRange" || operation.type === "formatRange") {
|
|
85
|
+
if (operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange") {
|
|
86
86
|
if (anchor["selectedTextHash"] !== operation.range.selectedTextHash || anchor["startOffset"] !== operation.range.startOffset || anchor["endOffset"] !== operation.range.endOffset) return null;
|
|
87
87
|
}
|
|
88
88
|
return {
|
|
@@ -126,7 +126,7 @@ var FolioPendingSuggestionRegistry = class {
|
|
|
126
126
|
const blockId = operationBlockId(operation);
|
|
127
127
|
const anchor = snapshot.anchors[blockId];
|
|
128
128
|
if (!anchor) continue;
|
|
129
|
-
const range = operation.type === "replaceRange" || operation.type === "formatRange" ? operation.range : null;
|
|
129
|
+
const range = operation.type === "replaceRange" || operation.type === "formatRange" || operation.type === "commentOnRange" ? operation.range : null;
|
|
130
130
|
const recorded = outcome.suggestionId === (operation.suggestionId ?? operation.id) ? operation : {
|
|
131
131
|
...operation,
|
|
132
132
|
suggestionId: outcome.suggestionId
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createNumberingIdAllocator } from "../docx/numberingIds.js";
|
|
1
|
+
import { createNumberingIdAllocator, numberingNumIdsTaken } from "../docx/numberingIds.js";
|
|
2
2
|
import { copyParagraphIndentationProjection } from "../docx/paragraphPropertySource.js";
|
|
3
3
|
import { visitInlineContentSlots, visitParagraphRuns } from "../docx/paragraphTraversal.js";
|
|
4
4
|
import { captureVerbatimXml } from "../docx/verbatimCapture.js";
|
|
@@ -97,7 +97,7 @@ const importNumbering = ({ destination, source, paragraphs, mode, sourceKind, ex
|
|
|
97
97
|
...rendering.markerHidden === void 0 ? {} : { hidden: rendering.markerHidden }
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
|
-
const numAllocator = createNumberingIdAllocator("num", (destination
|
|
100
|
+
const numAllocator = createNumberingIdAllocator("num", numberingNumIdsTaken(destination));
|
|
101
101
|
const abstractAllocator = createNumberingIdAllocator("abstract", (destination?.abstractNums ?? []).map(({ abstractNumId }) => abstractNumId));
|
|
102
102
|
const nums = new Map(source.nums.map(({ numId }) => [numId, numAllocator.next()]));
|
|
103
103
|
const abstracts = new Map(source.abstractNums.map(({ abstractNumId }) => [abstractNumId, abstractAllocator.next()]));
|
|
@@ -3,16 +3,40 @@ import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
|
3
3
|
import { setCanonicalInputTimer } from "./canonicalInputTimer.js";
|
|
4
4
|
import { CanonicalSessionError } from "./canonicalSession.js";
|
|
5
5
|
import { Result } from "better-result";
|
|
6
|
+
import { DOMParser, DOMSerializer, Fragment } from "prosemirror-model";
|
|
6
7
|
import { EditorState, TextSelection } from "prosemirror-state";
|
|
7
8
|
// src/controller/canonicalComposition.ts
|
|
8
9
|
const REVIEW_MARK_NAMES = /* @__PURE__ */ new Set(["insertion", "deletion"]);
|
|
10
|
+
const readBackCache = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
/**
|
|
12
|
+
* The mark a DOM read rebuilds from the mark's own rendering: `null` when no
|
|
13
|
+
* rule reads it back, `undefined` with no document to render into. A read
|
|
14
|
+
* keeps only what the rendering carries, so this is all a reread can say.
|
|
15
|
+
*/
|
|
16
|
+
const readBack = (mark) => {
|
|
17
|
+
const cached = readBackCache.get(mark);
|
|
18
|
+
if (cached !== void 0) return cached;
|
|
19
|
+
if (typeof document === "undefined") return void 0;
|
|
20
|
+
const { schema } = mark.type;
|
|
21
|
+
const container = document.createElement("div");
|
|
22
|
+
container.append(DOMSerializer.fromSchema(schema).serializeFragment(Fragment.from(schema.text("x", [mark])), { document }));
|
|
23
|
+
const texts = [];
|
|
24
|
+
DOMParser.fromSchema(schema).parseSlice(container).content.descendants((node) => {
|
|
25
|
+
if (node.isText) texts.push(node);
|
|
26
|
+
return texts.length === 0;
|
|
27
|
+
});
|
|
28
|
+
const read = mark.type.isInSet(texts.at(0)?.marks ?? []) ?? null;
|
|
29
|
+
readBackCache.set(mark, read);
|
|
30
|
+
return read;
|
|
31
|
+
};
|
|
9
32
|
/**
|
|
10
33
|
* Whether a native proposal is one plain replacement. The commit is a text
|
|
11
34
|
* replacement over the captured model, so this only has to tell DOM noise from a
|
|
12
|
-
* real change. Reading the DOM back can lose a mark
|
|
13
|
-
* `insertText`, a non-inclusive one. It rebuilds
|
|
14
|
-
* and composed text sits in the DOM
|
|
15
|
-
*
|
|
35
|
+
* real change. Reading the DOM back can lose a mark no rule reads back or, through
|
|
36
|
+
* `insertText`, a non-inclusive one. It rebuilds any mark from what its rendering
|
|
37
|
+
* carries, a review mark from fewer attributes, and composed text sits in the DOM
|
|
38
|
+
* wrapper of the tracked run beside it. Gaining any other mark, losing or changing
|
|
39
|
+
* one the rendering carries, or another revision is a real change.
|
|
16
40
|
* So is a selected paragraph boundary that does not disappear exactly.
|
|
17
41
|
*/
|
|
18
42
|
const matchesNativeReplacement = ({ baseline, proposed, from, to, text }) => {
|
|
@@ -48,7 +72,12 @@ const matchesNativeReplacement = ({ baseline, proposed, from, to, text }) => {
|
|
|
48
72
|
const held = type.isInSet(authored.marks);
|
|
49
73
|
const read = type.isInSet(node.marks);
|
|
50
74
|
if (held && !read) {
|
|
51
|
-
|
|
75
|
+
const rebuilt = readBack(held);
|
|
76
|
+
if (type.spec.inclusive === false || rebuilt === null || rebuilt === void 0 && (type.spec.parseDOM ?? []).length === 0) corrections.push(() => expected.removeMark(rangeFrom, rangeTo, type));
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (held && read && !held.eq(read) && !REVIEW_MARK_NAMES.has(type.name)) {
|
|
80
|
+
if (readBack(held)?.eq(read)) corrections.push(() => expected.addMark(rangeFrom, rangeTo, read));
|
|
52
81
|
continue;
|
|
53
82
|
}
|
|
54
83
|
if (!read || !REVIEW_MARK_NAMES.has(type.name)) continue;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { textCaretOf } from "../prosemirror/nativeSelection.js";
|
|
1
2
|
import { getEditorInputTargetRange, handleEditorBeforeInput } from "../prosemirror/textInput.js";
|
|
2
3
|
import { createCanonicalComposition } from "./canonicalComposition.js";
|
|
3
4
|
import { deletionRange, isCanonicalJoinBoundary } from "./canonicalSession.js";
|
|
@@ -20,14 +21,11 @@ const CANONICAL_COMPOSITION_INPUT_TYPES = [
|
|
|
20
21
|
* model's caret is: in the text before it, or at a paragraph's start in the first.
|
|
21
22
|
*/
|
|
22
23
|
const placeCompositionCaret = (view) => {
|
|
23
|
-
const { selection } = view.state;
|
|
24
24
|
const native = view.dom.ownerDocument.getSelection();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const { node, offset } = before.node.nodeType === before.node.TEXT_NODE ? before : view.domAtPos(selection.from, 1);
|
|
28
|
-
if (node.nodeType !== node.TEXT_NODE) return;
|
|
25
|
+
const caret = textCaretOf(view);
|
|
26
|
+
if (!native?.isCollapsed || caret === null) return;
|
|
29
27
|
native.removeAllRanges();
|
|
30
|
-
native.collapse(node, offset);
|
|
28
|
+
native.collapse(caret.node, caret.offset);
|
|
31
29
|
};
|
|
32
30
|
const createCanonicalInputBoundary = (options) => {
|
|
33
31
|
const composition = createCanonicalComposition({
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
-
import { LockedControlViolation } from "@stll/docx-core/model";
|
|
2
|
+
import { ContentControlLock, LockedControlViolation } from "@stll/docx-core/model";
|
|
3
|
+
type Control = {
|
|
4
|
+
lock: ContentControlLock | undefined;
|
|
5
|
+
signature: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Every content control in the document, keyed by its story and `w:id`, or by
|
|
9
|
+
* its order among the controls without one.
|
|
10
|
+
*/
|
|
11
|
+
export declare const controlsOf: (document: document_d_exports.Document) => Map<string, Control>;
|
|
12
|
+
/**
|
|
13
|
+
* The same map read from the whole document in one walk, with no reuse: the
|
|
14
|
+
* reference the block reads above must equal.
|
|
15
|
+
*/
|
|
16
|
+
export declare const controlsOfWholeDocument: (document: document_d_exports.Document) => Map<string, Control>;
|
|
3
17
|
/**
|
|
4
18
|
* What a change from `before` to `after` does to a locked content control,
|
|
5
19
|
* judged on the result rather than the steps that produced it, so every path
|
|
6
20
|
* into the session meets the same rule.
|
|
7
21
|
*/
|
|
8
|
-
export declare const lockViolationBetween: (before: document_d_exports.Document, after: document_d_exports.Document) => LockedControlViolation | null;
|
|
22
|
+
export declare const lockViolationBetween: (before: document_d_exports.Document, after: document_d_exports.Document) => LockedControlViolation | null;
|
|
23
|
+
export {};
|
|
@@ -21,11 +21,56 @@ const storyKey = (story) => {
|
|
|
21
21
|
if (story === "main") return "main";
|
|
22
22
|
return "rId" in story ? `${story.kind}:${story.rId}` : `${story.kind}:${String(story.id)}`;
|
|
23
23
|
};
|
|
24
|
+
/** The content controls inside one value, in document order. */
|
|
25
|
+
const collectControls = (value, into) => {
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
for (const item of value) collectControls(item, into);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (typeof value !== "object" || value === null) return;
|
|
31
|
+
const node = value;
|
|
32
|
+
if (node.type === "blockSdt" || node.type === "inlineSdt") into.push({
|
|
33
|
+
id: node.properties?.id,
|
|
34
|
+
control: {
|
|
35
|
+
lock: node.properties?.lock,
|
|
36
|
+
signature: signatureOf(node.content)
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
for (const child of Object.values(value)) collectControls(child, into);
|
|
40
|
+
};
|
|
41
|
+
const blockControls = /* @__PURE__ */ new WeakMap();
|
|
42
|
+
const controlsInBlock = (block) => {
|
|
43
|
+
let entries = blockControls.get(block);
|
|
44
|
+
if (entries === void 0) {
|
|
45
|
+
const collected = [];
|
|
46
|
+
collectControls(block, collected);
|
|
47
|
+
entries = collected;
|
|
48
|
+
blockControls.set(block, entries);
|
|
49
|
+
}
|
|
50
|
+
return entries;
|
|
51
|
+
};
|
|
24
52
|
/**
|
|
25
53
|
* Every content control in the document, keyed by its story and `w:id`, or by
|
|
26
54
|
* its order among the controls without one.
|
|
27
55
|
*/
|
|
28
56
|
const controlsOf = (document) => {
|
|
57
|
+
const controls = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const story of documentStories(document)) {
|
|
59
|
+
const body = findStoryBody(document, story);
|
|
60
|
+
if (body === void 0) continue;
|
|
61
|
+
let anonymous = 0;
|
|
62
|
+
for (const block of body.content) for (const { id, control } of controlsInBlock(block)) {
|
|
63
|
+
const key = `${storyKey(story)}#${id === void 0 ? `anonymous ${String(anonymous++)}` : String(id)}`;
|
|
64
|
+
controls.set(key, control);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return controls;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The same map read from the whole document in one walk, with no reuse: the
|
|
71
|
+
* reference the block reads above must equal.
|
|
72
|
+
*/
|
|
73
|
+
const controlsOfWholeDocument = (document) => {
|
|
29
74
|
const controls = /* @__PURE__ */ new Map();
|
|
30
75
|
for (const story of documentStories(document)) {
|
|
31
76
|
const body = findStoryBody(document, story);
|
|
@@ -85,4 +130,4 @@ const lockViolationBetween = (before, after) => {
|
|
|
85
130
|
}
|
|
86
131
|
return null;
|
|
87
132
|
};
|
|
88
|
-
export { lockViolationBetween };
|
|
133
|
+
export { controlsOf, controlsOfWholeDocument, lockViolationBetween };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { ParagraphCommentMarkers } from "../docx/commentAnchorIndex.js";
|
|
3
|
+
import { CanonicalInlineGap, CanonicalSeamExtent } from "./canonicalInlineProjection.js";
|
|
4
|
+
import { Node } from "prosemirror-model";
|
|
5
|
+
export type ParagraphAddress = {
|
|
6
|
+
blockId: string;
|
|
7
|
+
container: readonly document_d_exports.BlockContent[];
|
|
8
|
+
start: number;
|
|
9
|
+
text: string;
|
|
10
|
+
boundaries: readonly (readonly CanonicalInlineGap[])[];
|
|
11
|
+
seams: readonly (readonly CanonicalSeamExtent[])[];
|
|
12
|
+
node: Node;
|
|
13
|
+
source: document_d_exports.Paragraph;
|
|
14
|
+
};
|
|
15
|
+
/** A paragraph as the top-level block holding it projects it. */
|
|
16
|
+
export type BlockParagraph = {
|
|
17
|
+
blockId: string;
|
|
18
|
+
/** The blocks holding the paragraph, or undefined for the story's own. */
|
|
19
|
+
container: readonly document_d_exports.BlockContent[] | undefined;
|
|
20
|
+
/** From the start of the top-level node holding it. */
|
|
21
|
+
offset: number;
|
|
22
|
+
inline: Pick<ParagraphAddress, "text" | "boundaries" | "seams">;
|
|
23
|
+
node: Node;
|
|
24
|
+
source: document_d_exports.Paragraph;
|
|
25
|
+
};
|
|
26
|
+
/** What projecting one top-level node found. */
|
|
27
|
+
export type ProjectedBlock = {
|
|
28
|
+
/** The node the projection walked. */
|
|
29
|
+
node: Node;
|
|
30
|
+
/** The story block at the node's index, which the node was projected from when the projection is reusable. */
|
|
31
|
+
source: document_d_exports.BlockContent | undefined;
|
|
32
|
+
paragraphs: readonly BlockParagraph[];
|
|
33
|
+
/** The id of every source paragraph the block holds, addressed or not. */
|
|
34
|
+
sourceIds: readonly string[];
|
|
35
|
+
/** The comment ranges open at the block's start and after it, in their set's order. */
|
|
36
|
+
openBefore: readonly number[];
|
|
37
|
+
openAfter: readonly number[];
|
|
38
|
+
};
|
|
39
|
+
/** The story-wide facts every paragraph's gaps read. */
|
|
40
|
+
export type StoryProjectionFacts = {
|
|
41
|
+
pairedBookmarkIds: ReadonlySet<number>;
|
|
42
|
+
rangedIds: ReadonlySet<number>;
|
|
43
|
+
pointIds: ReadonlySet<number>;
|
|
44
|
+
};
|
|
45
|
+
/** Where a paragraph id stands: its block, and its paragraph there or -1 when it has no address. */
|
|
46
|
+
export type ParagraphSlot = {
|
|
47
|
+
block: number;
|
|
48
|
+
paragraph: number;
|
|
49
|
+
};
|
|
50
|
+
export declare class ParagraphIdIndex {
|
|
51
|
+
private readonly own;
|
|
52
|
+
private readonly base;
|
|
53
|
+
private readonly depth;
|
|
54
|
+
private constructor();
|
|
55
|
+
/** Every id of `blocks`; an addressed paragraph's slot over an unaddressed one of the same id. */
|
|
56
|
+
static of(blocks: readonly ProjectedBlock[]): ParagraphIdIndex;
|
|
57
|
+
get(id: string): ParagraphSlot | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* This index with its blocks from `start` up to `end` replaced by
|
|
60
|
+
* `window`, the blocks after them moved by the difference. `blocks` is the
|
|
61
|
+
* new projection's every block, read when the index is rebuilt flat.
|
|
62
|
+
*/
|
|
63
|
+
replaced({ start, end, removed, window, blocks }: {
|
|
64
|
+
start: number;
|
|
65
|
+
end: number;
|
|
66
|
+
removed: ReadonlySet<string>;
|
|
67
|
+
window: readonly ProjectedBlock[];
|
|
68
|
+
blocks: readonly ProjectedBlock[];
|
|
69
|
+
}): ParagraphIdIndex;
|
|
70
|
+
}
|
|
71
|
+
/** Whether two id lists hold the same ids in the same order. */
|
|
72
|
+
export declare const sameIdOrder: (left: readonly number[], right: readonly number[]) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The story-wide facts `blocks` contribute, in document order: each bookmark
|
|
75
|
+
* boundary, each comment range start and each comment reference. Two runs of
|
|
76
|
+
* blocks contributing the same sequence leave the story's facts as they were
|
|
77
|
+
* when one stands in for the other.
|
|
78
|
+
*/
|
|
79
|
+
export declare const storyFactContributions: (blocks: readonly document_d_exports.BlockContent[], markersOf: ParagraphCommentMarkers) => number[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { visitCommentMarkerItems } from "../docx/commentAnchorIndex.js";
|
|
2
|
+
import { visitBookmarkBoundaries } from "../prosemirror/conversion/toProseDoc.js";
|
|
3
|
+
// src/controller/canonicalProjectionBlocks.ts
|
|
4
|
+
/** Index levels a lookup passes before the index is rebuilt flat. */
|
|
5
|
+
const MAX_INDEX_DEPTH = 8;
|
|
6
|
+
var ParagraphIdIndex = class ParagraphIdIndex {
|
|
7
|
+
own;
|
|
8
|
+
base;
|
|
9
|
+
depth;
|
|
10
|
+
constructor(own, base, depth) {
|
|
11
|
+
this.own = own;
|
|
12
|
+
this.base = base;
|
|
13
|
+
this.depth = depth;
|
|
14
|
+
}
|
|
15
|
+
/** Every id of `blocks`; an addressed paragraph's slot over an unaddressed one of the same id. */
|
|
16
|
+
static of(blocks) {
|
|
17
|
+
return new ParagraphIdIndex(slotsOf(blocks, 0), void 0, 0);
|
|
18
|
+
}
|
|
19
|
+
get(id) {
|
|
20
|
+
const own = this.own.get(id);
|
|
21
|
+
if (own !== void 0) return own;
|
|
22
|
+
const base = this.base;
|
|
23
|
+
if (base === void 0 || base.removed.has(id)) return void 0;
|
|
24
|
+
const slot = base.index.get(id);
|
|
25
|
+
if (slot === void 0 || slot.block < base.end) return slot;
|
|
26
|
+
return {
|
|
27
|
+
block: slot.block + base.shift,
|
|
28
|
+
paragraph: slot.paragraph
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* This index with its blocks from `start` up to `end` replaced by
|
|
33
|
+
* `window`, the blocks after them moved by the difference. `blocks` is the
|
|
34
|
+
* new projection's every block, read when the index is rebuilt flat.
|
|
35
|
+
*/
|
|
36
|
+
replaced({ start, end, removed, window, blocks }) {
|
|
37
|
+
if (this.depth + 1 >= MAX_INDEX_DEPTH) return ParagraphIdIndex.of(blocks);
|
|
38
|
+
return new ParagraphIdIndex(slotsOf(window, start), {
|
|
39
|
+
index: this,
|
|
40
|
+
removed,
|
|
41
|
+
end,
|
|
42
|
+
shift: start + window.length - end
|
|
43
|
+
}, this.depth + 1);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const slotsOf = (blocks, first) => {
|
|
47
|
+
const slots = /* @__PURE__ */ new Map();
|
|
48
|
+
for (const [index, block] of blocks.entries()) for (const id of block.sourceIds) slots.set(id, {
|
|
49
|
+
block: first + index,
|
|
50
|
+
paragraph: -1
|
|
51
|
+
});
|
|
52
|
+
for (const [index, block] of blocks.entries()) for (const [paragraph, { blockId }] of block.paragraphs.entries()) slots.set(blockId, {
|
|
53
|
+
block: first + index,
|
|
54
|
+
paragraph
|
|
55
|
+
});
|
|
56
|
+
return slots;
|
|
57
|
+
};
|
|
58
|
+
/** Whether two id lists hold the same ids in the same order. */
|
|
59
|
+
const sameIdOrder = (left, right) => left.length === right.length && left.every((id, at) => right[at] === id);
|
|
60
|
+
/**
|
|
61
|
+
* The story-wide facts `blocks` contribute, in document order: each bookmark
|
|
62
|
+
* boundary, each comment range start and each comment reference. Two runs of
|
|
63
|
+
* blocks contributing the same sequence leave the story's facts as they were
|
|
64
|
+
* when one stands in for the other.
|
|
65
|
+
*/
|
|
66
|
+
const storyFactContributions = (blocks, markersOf) => {
|
|
67
|
+
const contributions = [];
|
|
68
|
+
visitBookmarkBoundaries(blocks, (id, type) => contributions.push(type === "start" ? 0 : 1, id));
|
|
69
|
+
visitCommentMarkerItems(blocks, markersOf, (item) => {
|
|
70
|
+
if (item.type === "commentRangeStart") contributions.push(2, item.id);
|
|
71
|
+
if (item.type === "commentReference") contributions.push(3, item.id);
|
|
72
|
+
});
|
|
73
|
+
return contributions;
|
|
74
|
+
};
|
|
75
|
+
export { ParagraphIdIndex, sameIdOrder, storyFactContributions };
|