@stll/folio-core 0.66.2 → 0.68.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/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +138 -17
- package/dist/ai-edits/batch-claims.js +5 -3
- package/dist/ai-edits/clean-text.js +4 -1
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +104 -34
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/read.js +6 -4
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +32 -17
- package/dist/ai-edits/table-cell-mutations.js +3 -2
- package/dist/ai-edits/table-row-column-mutations.js +20 -6
- package/dist/ai-edits/types.d.ts +9 -1
- package/dist/ai-suggestions/apply.js +13 -4
- package/dist/compare/compare.js +2 -1
- package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
- package/dist/compare/inserted-resource-snapshot.js +7 -3
- package/dist/controller/canonicalClipboard.js +29 -12
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +77 -19
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -2
- package/dist/controller/canonicalInput.js +47 -2
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +8 -0
- package/dist/controller/canonicalLockGuard.js +88 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +274 -20
- package/dist/controller/canonicalSession.d.ts +87 -7
- package/dist/controller/canonicalSession.js +328 -75
- package/dist/controller/canonicalStoryEditor.d.ts +3 -2
- package/dist/controller/canonicalStoryEditor.js +4 -3
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +1 -0
- package/dist/controller/headerFooterEditorManager.d.ts +2 -2
- package/dist/controller/headerFooterEditorManager.js +5 -5
- package/dist/controller/hiddenEditorApi.d.ts +6 -0
- package/dist/controller/hiddenEditorApi.js +1 -0
- package/dist/controller/hiddenEditorManager.d.ts +10 -3
- package/dist/controller/hiddenEditorManager.js +94 -38
- package/dist/controller/layoutPipeline.d.ts +2 -0
- package/dist/controller/layoutPipeline.js +55 -18
- package/dist/controller/layoutSession.d.ts +1 -0
- package/dist/controller/noteEditorManager.d.ts +2 -2
- package/dist/controller/noteEditorManager.js +5 -5
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.d.ts +3 -1
- package/dist/display-list/build/tablePrimitives.js +49 -14
- package/dist/display-list/dom/renderDisplayListToDom.js +4 -4
- package/dist/document-operations.d.ts +8 -0
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +5 -1
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/chartPreview.d.ts +4 -1
- package/dist/docx/chartPreview.js +26 -15
- package/dist/docx/commentAnchorIndex.d.ts +21 -5
- package/dist/docx/commentAnchorIndex.js +39 -11
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +17 -0
- package/dist/docx/hostCommentThreads.js +49 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +227 -96
- package/dist/docx/mainDocumentPart.d.ts +6 -0
- package/dist/docx/mainDocumentPart.js +65 -0
- package/dist/docx/markupRangeMarker.d.ts +14 -0
- package/dist/docx/markupRangeMarker.js +15 -1
- package/dist/docx/metadataPrivacy.js +43 -22
- package/dist/docx/normalizeBaseDirection.js +3 -1
- package/dist/docx/packageParts.d.ts +1 -1
- package/dist/docx/packageParts.js +10 -4
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +7 -0
- package/dist/docx/paragraphPropertySource.js +22 -1
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +6 -0
- package/dist/docx/previewBudget.d.ts +6 -0
- package/dist/docx/previewBudget.js +7 -1
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +110 -25
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +42 -25
- package/dist/docx/selectiveSave.js +6 -10
- package/dist/docx/selectiveXmlPatch.d.ts +5 -4
- package/dist/docx/selectiveXmlPatch.js +11 -7
- package/dist/docx/serializer/documentSerializer.js +3 -1
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/shapeAlternateContent.js +19 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +4 -0
- package/dist/docx/structuralXmlPatch.js +19 -7
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/unzip.js +2 -0
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +3 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
- package/dist/i18n/messages/catalogs.gen.js +51 -0
- package/dist/i18n/messages/cs.gen.js +3 -0
- package/dist/i18n/messages/de.gen.js +3 -0
- package/dist/i18n/messages/en.gen.js +3 -0
- package/dist/i18n/messages/es.gen.js +3 -0
- package/dist/i18n/messages/et.gen.js +3 -0
- package/dist/i18n/messages/fr.gen.js +3 -0
- package/dist/i18n/messages/he.gen.js +3 -0
- package/dist/i18n/messages/hi.gen.js +3 -0
- package/dist/i18n/messages/hu.gen.js +3 -0
- package/dist/i18n/messages/lt.gen.js +3 -0
- package/dist/i18n/messages/lv.gen.js +3 -0
- package/dist/i18n/messages/messages.gen.d.ts +3 -0
- package/dist/i18n/messages/pl.gen.js +3 -0
- package/dist/i18n/messages/pt-BR.gen.js +3 -0
- package/dist/i18n/messages/sk.gen.js +3 -0
- package/dist/i18n/messages/tr.gen.js +3 -0
- package/dist/i18n/messages/zh-CN.gen.js +3 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/internal/wholeStoryRevisionResolution.js +57 -12
- package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
- package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
- package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
- package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
- package/dist/layout-bridge/convert/tableConversion.js +25 -10
- package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/clickToPosition.js +5 -1
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.js +10 -5
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +1 -0
- package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
- package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
- package/dist/layout-engine/tableLayout.js +34 -7
- package/dist/layout-engine/tableRowBreak.d.ts +46 -0
- package/dist/layout-engine/tableRowBreak.js +193 -36
- package/dist/layout-engine/types.d.ts +43 -3
- package/dist/layout-painter/previewSvg.d.ts +8 -0
- package/dist/layout-painter/previewSvg.js +47 -0
- package/dist/layout-painter/renderImage.js +2 -1
- package/dist/layout-painter/renderPage.d.ts +5 -4
- package/dist/layout-painter/renderPage.js +52 -20
- package/dist/layout-painter/renderParagraph.js +3 -2
- package/dist/layout-painter/renderTable.d.ts +5 -2
- package/dist/layout-painter/renderTable.js +39 -22
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
- package/dist/prosemirror/attrs/index.js +1 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +25 -0
- package/dist/prosemirror/commands/comments.js +122 -18
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
- package/dist/prosemirror/commands/pastePlainText.js +13 -3
- package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
- package/dist/prosemirror/commentIdAllocator.js +2 -2
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
- package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
- package/dist/prosemirror/commentReferenceIntegrity.js +22 -8
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +115 -35
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +128 -1
- package/dist/prosemirror/conversion/toProseDoc.js +325 -55
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +6 -3
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
- package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +119 -38
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
- package/dist/prosemirror/index.d.ts +2 -2
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +4 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
- package/dist/prosemirror/plugins/suggestionMode.js +195 -30
- package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
- package/dist/prosemirror/rowGridOmissions.js +21 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
- package/dist/prosemirror/runFormattingFromMarks.js +2 -4
- package/dist/prosemirror/runFormattingReconciliation.js +2 -2
- package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +6 -0
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/tableGridMutation.d.ts +19 -2
- package/dist/prosemirror/tableGridMutation.js +118 -15
- package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
- package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
- package/dist/prosemirror/validation.js +2 -1
- package/dist/redline.js +23 -9
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +29 -8
- package/dist/types/canonicalCapabilities.js +13 -9
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -2
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs } from "./attrs/index.js";
|
|
2
|
+
import { withCanonicalCommand } from "./canonicalCommands.js";
|
|
3
|
+
import { standaloneTableRowsFromProseMirror, tableAttrsToFormatting, tableCellAttrsToFormatting, tableRowAttrsToFormatting } from "./conversion/fromProseDoc.js";
|
|
4
|
+
import { isInTable, selectedRect } from "prosemirror-tables";
|
|
5
|
+
import { DOCUMENT_OP_TYPES } from "@stll/docx-core/ops";
|
|
6
|
+
// src/prosemirror/canonicalTableCommands.ts
|
|
7
|
+
const SCOPES = {
|
|
8
|
+
table: "table",
|
|
9
|
+
tableRow: "row",
|
|
10
|
+
tableCell: "cell",
|
|
11
|
+
tableHeader: "cell"
|
|
12
|
+
};
|
|
13
|
+
const isScoped = (name) => Object.hasOwn(SCOPES, name);
|
|
14
|
+
/** Keys whose saved value changed: the new value, or null where the key went. */
|
|
15
|
+
const patchBetween = (before, after) => {
|
|
16
|
+
const patch = {};
|
|
17
|
+
const keys = Object.keys({
|
|
18
|
+
...before,
|
|
19
|
+
...after
|
|
20
|
+
});
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
const was = before?.[key];
|
|
23
|
+
const is = after?.[key];
|
|
24
|
+
if (JSON.stringify(was) === JSON.stringify(is)) continue;
|
|
25
|
+
patch[key] = after !== void 0 && Object.hasOwn(after, key) ? is : null;
|
|
26
|
+
}
|
|
27
|
+
return patch;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The patch of the formatting the save writes for a table, row or cell node,
|
|
31
|
+
* between its attributes before and after the command, as a target at `at`.
|
|
32
|
+
*/
|
|
33
|
+
const targetBetween = (scope, before, after, at) => {
|
|
34
|
+
switch (scope) {
|
|
35
|
+
case "table": return {
|
|
36
|
+
scope,
|
|
37
|
+
at,
|
|
38
|
+
patch: patchBetween(tableAttrsToFormatting(expectTableAttrs(before)), tableAttrsToFormatting(expectTableAttrs(after)))
|
|
39
|
+
};
|
|
40
|
+
case "row": return {
|
|
41
|
+
scope,
|
|
42
|
+
at,
|
|
43
|
+
patch: patchBetween(tableRowAttrsToFormatting(expectTableRowAttrs(before)), tableRowAttrsToFormatting(expectTableRowAttrs(after)))
|
|
44
|
+
};
|
|
45
|
+
case "cell": return {
|
|
46
|
+
scope,
|
|
47
|
+
at,
|
|
48
|
+
patch: patchBetween(tableCellAttrsToFormatting(expectTableCellAttrs(before)), tableCellAttrsToFormatting(expectTableCellAttrs(after)))
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* A position inside the first paragraph that belongs to the node itself, which
|
|
54
|
+
* addresses it. A paragraph of a nested table would address the inner table.
|
|
55
|
+
*/
|
|
56
|
+
const firstParagraphPosition = (node, position) => {
|
|
57
|
+
let found;
|
|
58
|
+
node.descendants((child, offset) => {
|
|
59
|
+
if (found !== void 0 || child.type.name === "table") return false;
|
|
60
|
+
if (child.isTextblock) {
|
|
61
|
+
found = position + 1 + offset + 1;
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
return found;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* What an attribute-only table command does, as table formatting patches.
|
|
70
|
+
*
|
|
71
|
+
* The command runs against the state without dispatching to the view. Every
|
|
72
|
+
* table, row and cell whose attributes it changed lowers to a patch of the
|
|
73
|
+
* formatting the save would write for it, so the session applies exactly what
|
|
74
|
+
* the editor would have saved. A command that changes anything else (content,
|
|
75
|
+
* a node's type, a span) has no attribute lowering and stays refused.
|
|
76
|
+
*/
|
|
77
|
+
const lowerTableAttributeCommand = (command, state) => {
|
|
78
|
+
let transaction;
|
|
79
|
+
if (!command(state, (dispatched) => {
|
|
80
|
+
transaction = dispatched;
|
|
81
|
+
}) || transaction === void 0) return void 0;
|
|
82
|
+
const changed = transaction;
|
|
83
|
+
const targets = [];
|
|
84
|
+
const grids = [];
|
|
85
|
+
const expected = state.tr;
|
|
86
|
+
let lowerable = true;
|
|
87
|
+
state.doc.descendants((node, position) => {
|
|
88
|
+
if (!lowerable) return false;
|
|
89
|
+
if (!isScoped(node.type.name)) return true;
|
|
90
|
+
const after = changed.doc.nodeAt(changed.mapping.map(position, -1));
|
|
91
|
+
if (after === null || after.type !== node.type) {
|
|
92
|
+
lowerable = false;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (after.attrs["colspan"] !== node.attrs["colspan"] || after.attrs["rowspan"] !== node.attrs["rowspan"]) {
|
|
96
|
+
lowerable = false;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (JSON.stringify(after.attrs) === JSON.stringify(node.attrs)) return true;
|
|
100
|
+
expected.setNodeMarkup(position, void 0, after.attrs, node.marks);
|
|
101
|
+
const at = firstParagraphPosition(node, position);
|
|
102
|
+
if (node.type.name === "table") {
|
|
103
|
+
const grid = gridEdit(node, after, at);
|
|
104
|
+
if (grid === null) {
|
|
105
|
+
lowerable = false;
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (grid !== void 0) grids.push(grid);
|
|
109
|
+
}
|
|
110
|
+
const target = targetBetween(SCOPES[node.type.name], node, after, at ?? 0);
|
|
111
|
+
if (Object.keys(target.patch).length === 0) return true;
|
|
112
|
+
if (at === void 0) {
|
|
113
|
+
lowerable = false;
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
targets.push(target);
|
|
117
|
+
return true;
|
|
118
|
+
});
|
|
119
|
+
if (!lowerable || !expected.doc.eq(changed.doc)) return void 0;
|
|
120
|
+
return [...grids, ...targets.length === 0 ? [] : [{
|
|
121
|
+
type: "formatTable",
|
|
122
|
+
targets
|
|
123
|
+
}]];
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* The grid a command left on a table, as a grid edit: `undefined` when the
|
|
127
|
+
* grid is unchanged, `null` when the change cannot be written as a grid.
|
|
128
|
+
*/
|
|
129
|
+
const gridEdit = (before, after, at) => {
|
|
130
|
+
const was = expectTableAttrs(before).columnWidths;
|
|
131
|
+
const is = expectTableAttrs(after).columnWidths;
|
|
132
|
+
if (JSON.stringify(was) === JSON.stringify(is)) return void 0;
|
|
133
|
+
if (at === void 0 || is === void 0 || is.length === 0) return null;
|
|
134
|
+
return {
|
|
135
|
+
type: "editTable",
|
|
136
|
+
at,
|
|
137
|
+
edit: {
|
|
138
|
+
type: DOCUMENT_OP_TYPES.SET_TABLE_GRID,
|
|
139
|
+
columnWidths: [...is]
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
/** Register a command whose whole effect is table, row and cell attributes. */
|
|
144
|
+
const withCanonicalTableAttributeCommand = (command) => withCanonicalCommand(command, (state) => lowerTableAttributeCommand(command, state));
|
|
145
|
+
/** A paragraph of the table's own, outside the given columns, that addresses it. */
|
|
146
|
+
const tableAnchor = (rect, avoid = {
|
|
147
|
+
left: 0,
|
|
148
|
+
right: 0
|
|
149
|
+
}) => {
|
|
150
|
+
const { map, table, tableStart } = rect;
|
|
151
|
+
for (let row = 0; row < map.height; row += 1) for (let column = 0; column < map.width; column += 1) {
|
|
152
|
+
if (column >= avoid.left && column < avoid.right) continue;
|
|
153
|
+
const offset = map.map[row * map.width + column];
|
|
154
|
+
if (offset === void 0) continue;
|
|
155
|
+
const cell = table.nodeAt(offset);
|
|
156
|
+
if (cell === null || cell.attrs["_omittedGridSlot"] != null) continue;
|
|
157
|
+
const cellRect = map.findCell(offset);
|
|
158
|
+
if (cellRect.left < avoid.right && cellRect.right > avoid.left) continue;
|
|
159
|
+
const at = firstParagraphPosition(cell, tableStart + offset);
|
|
160
|
+
if (at !== void 0) return at;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Register a command that changes a table's columns or cells, lowered from the
|
|
165
|
+
* selection it acts on to the engine's table edit. The command still runs
|
|
166
|
+
* against the state first: one it would refuse has no lowering.
|
|
167
|
+
*/
|
|
168
|
+
const withCanonicalTableStructureCommand = (command, lower) => withCanonicalCommand(command, (state) => {
|
|
169
|
+
if (!isInTable(state)) return void 0;
|
|
170
|
+
let transaction;
|
|
171
|
+
if (!command(state, (dispatched) => {
|
|
172
|
+
transaction = dispatched;
|
|
173
|
+
}) || transaction === void 0) return void 0;
|
|
174
|
+
return lower(selectedRect(state), state, transaction);
|
|
175
|
+
});
|
|
176
|
+
/** The width the command gave the column it inserted, from the table it left. */
|
|
177
|
+
const insertedWidth = (rect, changed, column) => {
|
|
178
|
+
const after = changed.doc.nodeAt(changed.mapping.map(rect.tableStart - 1, -1));
|
|
179
|
+
if (after === null || after.type.name !== "table") return void 0;
|
|
180
|
+
return expectTableAttrs(after).columnWidths?.[column];
|
|
181
|
+
};
|
|
182
|
+
const insertColumn = (side) => (rect, _state, changed) => {
|
|
183
|
+
const column = side === "left" ? rect.left : rect.right;
|
|
184
|
+
const width = insertedWidth(rect, changed, column);
|
|
185
|
+
const at = tableAnchor(rect);
|
|
186
|
+
if (width === void 0 || at === void 0) return void 0;
|
|
187
|
+
return [{
|
|
188
|
+
type: "editTable",
|
|
189
|
+
at,
|
|
190
|
+
edit: {
|
|
191
|
+
type: DOCUMENT_OP_TYPES.INSERT_COLUMN,
|
|
192
|
+
column,
|
|
193
|
+
width
|
|
194
|
+
}
|
|
195
|
+
}];
|
|
196
|
+
};
|
|
197
|
+
/** Each selected column, from the right so the indices still hold. */
|
|
198
|
+
const deleteColumns = (rect) => {
|
|
199
|
+
const at = tableAnchor(rect, {
|
|
200
|
+
left: rect.left,
|
|
201
|
+
right: rect.right
|
|
202
|
+
});
|
|
203
|
+
if (at === void 0) return void 0;
|
|
204
|
+
const intents = [];
|
|
205
|
+
for (let column = rect.right - 1; column >= rect.left; column -= 1) intents.push({
|
|
206
|
+
type: "editTable",
|
|
207
|
+
at,
|
|
208
|
+
edit: {
|
|
209
|
+
type: DOCUMENT_OP_TYPES.DELETE_COLUMN,
|
|
210
|
+
column
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return intents;
|
|
214
|
+
};
|
|
215
|
+
const mergeCells$1 = (rect) => {
|
|
216
|
+
const at = tableAnchor(rect);
|
|
217
|
+
if (at === void 0) return void 0;
|
|
218
|
+
return [{
|
|
219
|
+
type: "editTable",
|
|
220
|
+
at,
|
|
221
|
+
edit: {
|
|
222
|
+
type: DOCUMENT_OP_TYPES.MERGE_CELLS,
|
|
223
|
+
top: rect.top,
|
|
224
|
+
bottom: rect.bottom,
|
|
225
|
+
left: rect.left,
|
|
226
|
+
right: rect.right
|
|
227
|
+
}
|
|
228
|
+
}];
|
|
229
|
+
};
|
|
230
|
+
/** The cell at the selection's top left, addressed by its own paragraph. */
|
|
231
|
+
const splitCell$1 = (rect) => {
|
|
232
|
+
const offset = rect.map.map[rect.top * rect.map.width + rect.left];
|
|
233
|
+
const cell = offset === void 0 ? null : rect.table.nodeAt(offset);
|
|
234
|
+
if (offset === void 0 || cell === null) return void 0;
|
|
235
|
+
const at = firstParagraphPosition(cell, rect.tableStart + offset);
|
|
236
|
+
if (at === void 0) return void 0;
|
|
237
|
+
return [{
|
|
238
|
+
type: "editTable",
|
|
239
|
+
at,
|
|
240
|
+
edit: { type: DOCUMENT_OP_TYPES.SPLIT_CELL }
|
|
241
|
+
}];
|
|
242
|
+
};
|
|
243
|
+
const withCanonicalColumnInsertion = (command, side) => withCanonicalTableStructureCommand(command, insertColumn(side));
|
|
244
|
+
const withCanonicalColumnDeletion = (command) => withCanonicalTableStructureCommand(command, deleteColumns);
|
|
245
|
+
const withCanonicalCellMerge = (command) => withCanonicalTableStructureCommand(command, mergeCells$1);
|
|
246
|
+
const withCanonicalCellSplit = (command) => withCanonicalTableStructureCommand(command, splitCell$1);
|
|
247
|
+
/** A paragraph of the table's own in the given row. */
|
|
248
|
+
const rowAnchor = (rect, row) => {
|
|
249
|
+
const { map, table, tableStart } = rect;
|
|
250
|
+
for (let column = 0; column < map.width; column += 1) {
|
|
251
|
+
const offset = map.map[row * map.width + column];
|
|
252
|
+
if (offset === void 0) continue;
|
|
253
|
+
const cell = table.nodeAt(offset);
|
|
254
|
+
if (cell === null || cell.attrs["_omittedGridSlot"] != null) continue;
|
|
255
|
+
if (map.findCell(offset).top !== row) continue;
|
|
256
|
+
const at = firstParagraphPosition(cell, tableStart + offset);
|
|
257
|
+
if (at !== void 0) return at;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* The row the command inserted, as the save would write it. Revision marks
|
|
262
|
+
* the command put on it are left to the engine, which records its own.
|
|
263
|
+
*/
|
|
264
|
+
const insertedRow = (rect, changed, index) => {
|
|
265
|
+
const after = changed.doc.nodeAt(changed.mapping.map(rect.tableStart - 1, -1));
|
|
266
|
+
if (after === null || after.type.name !== "table") return void 0;
|
|
267
|
+
const row = standaloneTableRowsFromProseMirror(after)[index];
|
|
268
|
+
if (row === void 0) return void 0;
|
|
269
|
+
const { structuralChange: _structuralChange, propertyChanges: _propertyChanges, ...plain } = row;
|
|
270
|
+
return plain;
|
|
271
|
+
};
|
|
272
|
+
const insertRow = (side) => (rect, _state, changed) => {
|
|
273
|
+
const index = side === "above" ? rect.top : rect.bottom;
|
|
274
|
+
const row = insertedRow(rect, changed, index);
|
|
275
|
+
const at = rowAnchor(rect, side === "above" ? rect.top : rect.bottom - 1);
|
|
276
|
+
if (row === void 0 || at === void 0) return void 0;
|
|
277
|
+
return [{
|
|
278
|
+
type: "editTableRow",
|
|
279
|
+
at,
|
|
280
|
+
edit: {
|
|
281
|
+
type: DOCUMENT_OP_TYPES.INSERT_ROW,
|
|
282
|
+
at: index,
|
|
283
|
+
row
|
|
284
|
+
}
|
|
285
|
+
}];
|
|
286
|
+
};
|
|
287
|
+
/** Each selected row from the bottom, addressed by a paragraph of its own. */
|
|
288
|
+
const deleteRows = (rect) => {
|
|
289
|
+
const intents = [];
|
|
290
|
+
for (let row = rect.bottom - 1; row >= rect.top; row -= 1) {
|
|
291
|
+
const at = rowAnchor(rect, row);
|
|
292
|
+
if (at === void 0) return void 0;
|
|
293
|
+
intents.push({
|
|
294
|
+
type: "editTableRow",
|
|
295
|
+
at,
|
|
296
|
+
edit: { type: DOCUMENT_OP_TYPES.DELETE_ROW }
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
return intents;
|
|
300
|
+
};
|
|
301
|
+
const withCanonicalRowInsertion = (command, side) => withCanonicalTableStructureCommand(command, insertRow(side));
|
|
302
|
+
const withCanonicalRowDeletion = (command) => withCanonicalTableStructureCommand(command, deleteRows);
|
|
303
|
+
/** The table the selection is in, addressed by a paragraph of its own. */
|
|
304
|
+
const deleteTable = (rect) => {
|
|
305
|
+
const at = tableAnchor(rect);
|
|
306
|
+
if (at === void 0) return void 0;
|
|
307
|
+
return [{
|
|
308
|
+
type: "editTableBlock",
|
|
309
|
+
at,
|
|
310
|
+
edit: { type: DOCUMENT_OP_TYPES.DELETE_TABLE }
|
|
311
|
+
}];
|
|
312
|
+
};
|
|
313
|
+
const withCanonicalTableDeletion = (command) => withCanonicalTableStructureCommand(command, deleteTable);
|
|
314
|
+
/**
|
|
315
|
+
* Register the insert table command, lowered to a table and an empty
|
|
316
|
+
* paragraph after the paragraph that holds the caret, as the command places
|
|
317
|
+
* them. The table is the one the command built, without the revision marks
|
|
318
|
+
* it put on its rows; in suggesting mode the engine records its own.
|
|
319
|
+
*/
|
|
320
|
+
const withCanonicalTableInsertion = (command) => withCanonicalCommand(command, (state) => {
|
|
321
|
+
const { $from } = state.selection;
|
|
322
|
+
let depth = $from.depth;
|
|
323
|
+
while (depth > 0 && $from.node(depth).type.name !== "paragraph" && $from.node(depth).type.name !== "table") depth -= 1;
|
|
324
|
+
const afterTable = depth > 0 && $from.node(depth).type.name === "table";
|
|
325
|
+
const atStart = depth === 0 && $from.pos === 0 && state.doc.firstChild?.type.name === "paragraph";
|
|
326
|
+
if (depth === 0 && !atStart) return void 0;
|
|
327
|
+
const following = afterTable ? state.doc.resolve($from.after(depth)).nodeAfter : null;
|
|
328
|
+
if (afterTable && following?.type.name !== "paragraph") return void 0;
|
|
329
|
+
let transaction;
|
|
330
|
+
if (!command(state, (dispatched) => {
|
|
331
|
+
transaction = dispatched;
|
|
332
|
+
}) || transaction === void 0) return void 0;
|
|
333
|
+
const at = atStart ? 0 : transaction.mapping.map($from.after(depth), -1);
|
|
334
|
+
const leading = afterTable ? transaction.doc.nodeAt(at) : null;
|
|
335
|
+
const inserted = transaction.doc.nodeAt(leading?.type.name === "paragraph" ? at + leading.nodeSize : at);
|
|
336
|
+
const before = atStart || afterTable;
|
|
337
|
+
const anchorPosition = () => {
|
|
338
|
+
if (atStart) return 1;
|
|
339
|
+
if (afterTable) return $from.after(depth) + 1;
|
|
340
|
+
return $from.start(depth);
|
|
341
|
+
};
|
|
342
|
+
if (inserted === null || inserted.type.name !== "table") return void 0;
|
|
343
|
+
const formatting = tableAttrsToFormatting(expectTableAttrs(inserted));
|
|
344
|
+
const columnWidths = expectTableAttrs(inserted).columnWidths;
|
|
345
|
+
const table = {
|
|
346
|
+
type: "table",
|
|
347
|
+
...formatting === void 0 ? {} : { formatting },
|
|
348
|
+
...columnWidths === void 0 ? {} : { columnWidths: [...columnWidths] },
|
|
349
|
+
rows: standaloneTableRowsFromProseMirror(inserted).map(({ structuralChange: _change, propertyChanges: _changes, ...row }) => row)
|
|
350
|
+
};
|
|
351
|
+
return [{
|
|
352
|
+
type: "editTableBlock",
|
|
353
|
+
at: anchorPosition(),
|
|
354
|
+
edit: {
|
|
355
|
+
type: DOCUMENT_OP_TYPES.INSERT_TABLE,
|
|
356
|
+
table,
|
|
357
|
+
...before ? { side: "before" } : {},
|
|
358
|
+
...afterTable ? { separated: true } : {}
|
|
359
|
+
}
|
|
360
|
+
}];
|
|
361
|
+
});
|
|
362
|
+
export { lowerTableAttributeCommand, withCanonicalCellMerge, withCanonicalCellSplit, withCanonicalColumnDeletion, withCanonicalColumnInsertion, withCanonicalRowDeletion, withCanonicalRowInsertion, withCanonicalTableAttributeCommand, withCanonicalTableDeletion, withCanonicalTableInsertion };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { TrackedChangeEntry } from "../utils/extractTrackedChanges.js";
|
|
1
2
|
import { Command, EditorState } from "prosemirror-state";
|
|
3
|
+
import { LockedControlViolation } from "@stll/docx-core/model";
|
|
2
4
|
import { Mapping } from "prosemirror-transform";
|
|
3
5
|
/**
|
|
4
6
|
* Add a comment mark to the current selection.
|
|
@@ -18,6 +20,21 @@ export type ParagraphBoundaryChange = {
|
|
|
18
20
|
revisionId?: number;
|
|
19
21
|
};
|
|
20
22
|
export declare function findParagraphBoundaryChangeAtPosition(state: EditorState, pos: number): ParagraphBoundaryChange | null;
|
|
23
|
+
/**
|
|
24
|
+
* What the content-control locks say about resolving the tracked changes
|
|
25
|
+
* between `from` and `to` (only those of `revisionIds`, when given): `null`
|
|
26
|
+
* when they allow it or there is nothing there to resolve. A revision whose
|
|
27
|
+
* resolution would change a content-locked control's content, or remove a
|
|
28
|
+
* control locked against removal, stays pending.
|
|
29
|
+
*/
|
|
30
|
+
export declare const changeResolutionLockViolation: (state: EditorState, { from, to, mode, revisionIds }: {
|
|
31
|
+
from: number;
|
|
32
|
+
to: number;
|
|
33
|
+
mode: "accept" | "reject";
|
|
34
|
+
revisionIds?: readonly number[];
|
|
35
|
+
}) => LockedControlViolation | null;
|
|
36
|
+
/** {@link changeResolutionLockViolation} for the revisions `revisionIds`, wherever they are. */
|
|
37
|
+
export declare const revisionResolutionLockViolation: (state: EditorState, revisionIds: number | readonly number[], mode: "accept" | "reject") => LockedControlViolation | null;
|
|
21
38
|
/**
|
|
22
39
|
* Accept a tracked change at the given range.
|
|
23
40
|
* - Insertion: remove mark, keep text
|
|
@@ -39,6 +56,14 @@ export declare function acceptAllChanges(): Command;
|
|
|
39
56
|
* Reject all tracked changes in the document.
|
|
40
57
|
*/
|
|
41
58
|
export declare function rejectAllChanges(): Command;
|
|
59
|
+
/**
|
|
60
|
+
* The revisions of `state` that a content control's lock keeps from being
|
|
61
|
+
* resolved in `mode`, each with the lock's verdict: see
|
|
62
|
+
* {@link changeResolutionLockViolation}. Empty without a locked control.
|
|
63
|
+
*/
|
|
64
|
+
export declare const lockHeldRevisions: (state: EditorState, mode: "accept" | "reject") => Map<number, LockedControlViolation>;
|
|
65
|
+
/** Every revision id one sidebar entry stands for. */
|
|
66
|
+
export declare const trackedChangeEntryRevisionIds: (entry: TrackedChangeEntry) => number[];
|
|
42
67
|
/**
|
|
43
68
|
* Resolve a complete state synchronously for a headless reader or writer.
|
|
44
69
|
*
|
|
@@ -4,7 +4,7 @@ import { RevisionResolutionStep } from "../../internal/revisionResolutionStep.js
|
|
|
4
4
|
import { finalRevisionParagraphRanges } from "../../internal/revisionResolutionTracking.js";
|
|
5
5
|
import { deleteTextBoxesAnchoredAt, droppedTextBoxAnchorIds, moveTextBoxesPastNextParagraph } from "../anchoredTextBoxes.js";
|
|
6
6
|
import { expectFieldAttrs, expectParagraphAttrs, expectRunPropertyChangeMarkAttrs, expectTrackedChangeMarkAttrs } from "../attrs/index.js";
|
|
7
|
-
import { readCommentRangeBoundaryAttrs } from "../commentRangeBoundaryAttrs.js";
|
|
7
|
+
import { isCommentRangeBoundaryNode, readCommentRangeBoundaryAttrs } from "../commentRangeBoundaryAttrs.js";
|
|
8
8
|
import { addedBreakCarrierBefore, finalParagraphsOf } from "../containerFinalParagraph.js";
|
|
9
9
|
import { enclosingRevisionIds, resolutionRemovesControl, withoutResolvedEnclosures } from "../contentControlRevisions.js";
|
|
10
10
|
import { copyOriginBoundaryAttrsAfterResolution } from "../copyOriginResolution.js";
|
|
@@ -15,6 +15,7 @@ import { markChangedParagraphRanges, markStructuralChange, markTrackedSectionEnd
|
|
|
15
15
|
import "../extensions/nodes/SdtExtension.js";
|
|
16
16
|
import { canonicalFieldNode } from "../fieldRepresentation.js";
|
|
17
17
|
import { isBlockBoundaryNode, normalizeKeptRangeBoundaries, paragraphRemainsOf, removeResolvedSubtree, revisionLayerRemovesContent } from "../keptRangeBoundaries.js";
|
|
18
|
+
import { lockedControlSpans, lockedControlViolationOfTransform } from "../lockedControls.js";
|
|
18
19
|
import { resolveStateStory } from "../markupViewProjection.js";
|
|
19
20
|
import { joinAtParagraphMark } from "../paragraphMarkJoin.js";
|
|
20
21
|
import { carryParagraphProperties, paragraphLeftAfter } from "../paragraphPropertyCarry.js";
|
|
@@ -32,7 +33,7 @@ import { paragraphRunStyleContextAt } from "../runStyleFormatting.js";
|
|
|
32
33
|
import { sectionRecordCopyPositions } from "../sectionCarrier.js";
|
|
33
34
|
import { getTableCellMergeChange } from "../tableCellMergeRevision.js";
|
|
34
35
|
import { isTableCellRetainedInReviewView } from "../tableCellRevisionVisibility.js";
|
|
35
|
-
import { markRowEmptiedInBatch, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCellsAfterBatch, removeTableRow } from "../tableGridMutation.js";
|
|
36
|
+
import { markRowEmptiedInBatch, reconcileOmittedGridSlots, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCellsAfterBatch, removeTableRow, rowHoldsNoCells } from "../tableGridMutation.js";
|
|
36
37
|
import { runInCellPending, runParagraphIntoTable } from "../tableRunIn.js";
|
|
37
38
|
import { retainedTrackedRevisionMark, trackedRevisionPathOf } from "../trackedRevisionPath.js";
|
|
38
39
|
import { extractTrackedChanges } from "../utils/extractTrackedChanges.js";
|
|
@@ -86,7 +87,7 @@ function removeCommentMark(commentId) {
|
|
|
86
87
|
};
|
|
87
88
|
}
|
|
88
89
|
const keptIn = (range) => range.removals.flatMap(({ kept }) => kept);
|
|
89
|
-
function
|
|
90
|
+
function resolveChangeUnguarded(from, to, mode, revisionIds) {
|
|
90
91
|
return (state, dispatch) => {
|
|
91
92
|
const insertionType = state.schema.marks["insertion"];
|
|
92
93
|
const deletionType = state.schema.marks["deletion"];
|
|
@@ -431,7 +432,7 @@ function resolveChange(from, to, mode, revisionIds) {
|
|
|
431
432
|
follows,
|
|
432
433
|
holdsContent: paragraphContentOf(paragraph),
|
|
433
434
|
markWasAdded: op.markWasAdded,
|
|
434
|
-
containerStillEndsWithParagraph: resolved.parent.
|
|
435
|
+
containerStillEndsWithParagraph: preceding?.type.name === "paragraph" || preceding !== void 0 && resolved.parent.type.name === "blockSdt",
|
|
435
436
|
followingTableCanReceiveRunIn: follows === "table" && boundaries.length === 0 && !pendingTables.some((position) => tr.mapping.map(position) === nextPos) && !ownsSectionEndpoint(paragraph),
|
|
436
437
|
needsFollowingCommentHost: follows === "table" && preceding?.type.name !== "paragraph" && retainedBoundaries.blocks.length === 0 && retainedBoundaries.comments.length > 0,
|
|
437
438
|
removedSectionProperties: op.markWasAdded && sectionProperties != null,
|
|
@@ -522,7 +523,7 @@ function resolveChange(from, to, mode, revisionIds) {
|
|
|
522
523
|
});
|
|
523
524
|
return false;
|
|
524
525
|
}
|
|
525
|
-
if (node
|
|
526
|
+
if (isCommentRangeBoundaryNode(node)) {
|
|
526
527
|
const attrs = readCommentRangeBoundaryAttrs(node);
|
|
527
528
|
if (attrs.ok && doomed.has(attrs.value.marker.id)) {
|
|
528
529
|
carriers.push({
|
|
@@ -576,10 +577,20 @@ const terminalTableDeletionIsPending = (tr) => {
|
|
|
576
577
|
};
|
|
577
578
|
/** Resolve the Folio-only receiver Word needs after a terminal deleted table. */
|
|
578
579
|
const resolveTerminalTableReviewCarrier = (tr, mode) => {
|
|
579
|
-
|
|
580
|
+
let position = tr.doc.content.size;
|
|
581
|
+
let carrier = null;
|
|
582
|
+
for (let index = tr.doc.childCount - 1; index >= 0; index--) {
|
|
583
|
+
carrier = tr.doc.child(index);
|
|
584
|
+
position -= carrier.nodeSize;
|
|
585
|
+
if (carrier.type.name !== "textBox") break;
|
|
586
|
+
}
|
|
580
587
|
if (carrier?.type.name !== "paragraph" || carrier.attrs["reviewCarrier"] !== REVIEW_CARRIERS.TERMINAL_TABLE) return;
|
|
581
|
-
|
|
582
|
-
|
|
588
|
+
let pending = carrier.attrs["pPrMark"] != null;
|
|
589
|
+
carrier.forEach((child) => {
|
|
590
|
+
pending ||= child.marks.some(({ type }) => ["insertion", "deletion"].includes(type.name));
|
|
591
|
+
});
|
|
592
|
+
if (pending) return;
|
|
593
|
+
if (mode === "accept" || carrier.content.size > 0) {
|
|
583
594
|
tr.setNodeAttribute(position, "reviewCarrier", void 0);
|
|
584
595
|
return;
|
|
585
596
|
}
|
|
@@ -739,13 +750,15 @@ function deleteTableCellAt(tr, cellPos, emptied) {
|
|
|
739
750
|
const cellOffset = cellPos - resolved.start(tableDepth);
|
|
740
751
|
const removedColumn = TableMap.get(table).findCell(cellOffset).left;
|
|
741
752
|
const spansDown = Number(cell.attrs["rowspan"]) > 1;
|
|
742
|
-
|
|
743
|
-
|
|
753
|
+
const holdsOtherCells = !rowHoldsNoCells(row, cell);
|
|
754
|
+
if (holdsOtherCells || spansDown) {
|
|
755
|
+
if (!holdsOtherCells) markRowEmptiedInBatch({
|
|
744
756
|
tr,
|
|
745
757
|
rowPosition: resolved.start() - 1,
|
|
746
758
|
emptied
|
|
747
759
|
});
|
|
748
760
|
tr.delete(cellPos, cellPos + cell.nodeSize);
|
|
761
|
+
reconcileOmittedGridSlots(tr, tablePosition, table, removedColumn);
|
|
749
762
|
reconcileTableGridAfterColumnRemoval({
|
|
750
763
|
tr,
|
|
751
764
|
tablePosition,
|
|
@@ -759,6 +772,7 @@ function deleteTableCellAt(tr, cellPos, emptied) {
|
|
|
759
772
|
return;
|
|
760
773
|
}
|
|
761
774
|
deleteTableRowAt(tr, resolved.start() - 1);
|
|
775
|
+
reconcileOmittedGridSlots(tr, tablePosition, table, removedColumn);
|
|
762
776
|
reconcileTableGridAfterColumnRemoval({
|
|
763
777
|
tr,
|
|
764
778
|
tablePosition,
|
|
@@ -881,6 +895,50 @@ function findParagraphBoundaryChangeAtPosition(state, pos) {
|
|
|
881
895
|
}
|
|
882
896
|
return null;
|
|
883
897
|
}
|
|
898
|
+
/** The transaction `command` would dispatch on `state`, or `null` when it would not apply. */
|
|
899
|
+
const attemptedTransaction = (command, state, view) => {
|
|
900
|
+
let attempted = null;
|
|
901
|
+
return command(state, (transaction) => {
|
|
902
|
+
attempted = transaction;
|
|
903
|
+
}, view) ? attempted : null;
|
|
904
|
+
};
|
|
905
|
+
/**
|
|
906
|
+
* `command`, refused when what it would do breaks a content control's lock
|
|
907
|
+
* (`lockedControlViolationOfTransform`). A document without a locked control
|
|
908
|
+
* runs it as it is.
|
|
909
|
+
*/
|
|
910
|
+
const honouringContentControlLocks = (command) => (state, dispatch, view) => {
|
|
911
|
+
if (lockedControlSpans(state.doc).length === 0) return command(state, dispatch, view);
|
|
912
|
+
const attempted = attemptedTransaction(command, state, view);
|
|
913
|
+
if (attempted === null) return false;
|
|
914
|
+
if (lockedControlViolationOfTransform(attempted) !== null) return false;
|
|
915
|
+
dispatch?.(attempted);
|
|
916
|
+
return true;
|
|
917
|
+
};
|
|
918
|
+
function resolveChange(from, to, mode, revisionIds) {
|
|
919
|
+
return honouringContentControlLocks(resolveChangeUnguarded(from, to, mode, revisionIds));
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* What the content-control locks say about resolving the tracked changes
|
|
923
|
+
* between `from` and `to` (only those of `revisionIds`, when given): `null`
|
|
924
|
+
* when they allow it or there is nothing there to resolve. A revision whose
|
|
925
|
+
* resolution would change a content-locked control's content, or remove a
|
|
926
|
+
* control locked against removal, stays pending.
|
|
927
|
+
*/
|
|
928
|
+
const changeResolutionLockViolation = (state, { from, to, mode, revisionIds }) => {
|
|
929
|
+
if (lockedControlSpans(state.doc).length === 0) return null;
|
|
930
|
+
const attempted = attemptedTransaction(resolveChangeUnguarded(from, to, mode, revisionIds), state);
|
|
931
|
+
return attempted === null ? null : lockedControlViolationOfTransform(attempted);
|
|
932
|
+
};
|
|
933
|
+
/** {@link changeResolutionLockViolation} for the revisions `revisionIds`, wherever they are. */
|
|
934
|
+
const revisionResolutionLockViolation = (state, revisionIds, mode) => {
|
|
935
|
+
const range = findAIEditRevisionRange(state, revisionIds);
|
|
936
|
+
return range === null ? null : changeResolutionLockViolation(state, {
|
|
937
|
+
...range,
|
|
938
|
+
mode,
|
|
939
|
+
revisionIds: typeof revisionIds === "number" ? [revisionIds] : revisionIds
|
|
940
|
+
});
|
|
941
|
+
};
|
|
884
942
|
/**
|
|
885
943
|
* Accept a tracked change at the given range.
|
|
886
944
|
* - Insertion: remove mark, keep text
|
|
@@ -931,19 +989,65 @@ const resolveAllChanges = (mode) => (state, dispatch) => {
|
|
|
931
989
|
* suggestions are present because this command cannot restage them.
|
|
932
990
|
*/
|
|
933
991
|
function acceptAllChanges() {
|
|
934
|
-
const resolve =
|
|
935
|
-
return (state, dispatch) => {
|
|
992
|
+
const resolve = resolveAllChangesHonouringLocks("accept");
|
|
993
|
+
return (state, dispatch, view) => {
|
|
936
994
|
if (getSuggestions(state).length > 0) return false;
|
|
937
|
-
return resolve(state, dispatch);
|
|
995
|
+
return resolve(state, dispatch, view);
|
|
938
996
|
};
|
|
939
997
|
}
|
|
940
998
|
/**
|
|
941
999
|
* Reject all tracked changes in the document.
|
|
942
1000
|
*/
|
|
943
1001
|
function rejectAllChanges() {
|
|
944
|
-
return
|
|
1002
|
+
return resolveAllChangesHonouringLocks("reject");
|
|
945
1003
|
}
|
|
946
1004
|
/**
|
|
1005
|
+
* The revisions of `state` that a content control's lock keeps from being
|
|
1006
|
+
* resolved in `mode`, each with the lock's verdict: see
|
|
1007
|
+
* {@link changeResolutionLockViolation}. Empty without a locked control.
|
|
1008
|
+
*/
|
|
1009
|
+
const lockHeldRevisions = (state, mode) => {
|
|
1010
|
+
const held = /* @__PURE__ */ new Map();
|
|
1011
|
+
if (lockedControlSpans(state.doc).length === 0) return held;
|
|
1012
|
+
for (const id of new Set(extractTrackedChanges(state).entries.flatMap(trackedChangeEntryRevisionIds))) {
|
|
1013
|
+
const violation = revisionResolutionLockViolation(state, id, mode);
|
|
1014
|
+
if (violation !== null) held.set(id, violation);
|
|
1015
|
+
}
|
|
1016
|
+
return held;
|
|
1017
|
+
};
|
|
1018
|
+
/** Every revision id one sidebar entry stands for. */
|
|
1019
|
+
const trackedChangeEntryRevisionIds = (entry) => [.../* @__PURE__ */ new Set([
|
|
1020
|
+
entry.revisionId,
|
|
1021
|
+
...entry.insertionRevisionId === void 0 ? [] : [entry.insertionRevisionId],
|
|
1022
|
+
...entry.coalescedRevisionIds ?? []
|
|
1023
|
+
])];
|
|
1024
|
+
/**
|
|
1025
|
+
* Resolve every tracked change a content control's lock allows. Without a
|
|
1026
|
+
* change the locks hold, the whole story resolves in one pass, as before;
|
|
1027
|
+
* otherwise each other change resolves on its own, in an editor view (a
|
|
1028
|
+
* transaction each), and the held ones stay pending as they are. Without a
|
|
1029
|
+
* view nothing resolves when any change is held.
|
|
1030
|
+
*/
|
|
1031
|
+
const resolveAllChangesHonouringLocks = (mode) => (state, dispatch, view) => {
|
|
1032
|
+
const resolveAll = resolveAllChanges(mode);
|
|
1033
|
+
if (lockedControlSpans(state.doc).length === 0) return resolveAll(state, dispatch, view);
|
|
1034
|
+
const attempted = attemptedTransaction(resolveAll, state, view);
|
|
1035
|
+
if (attempted === null) return false;
|
|
1036
|
+
if (lockedControlViolationOfTransform(attempted) === null) {
|
|
1037
|
+
dispatch?.(attempted);
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
if (!dispatch) return true;
|
|
1041
|
+
if (!view) return false;
|
|
1042
|
+
const held = lockHeldRevisions(state, mode);
|
|
1043
|
+
const ids = new Set(extractTrackedChanges(state).entries.flatMap(trackedChangeEntryRevisionIds));
|
|
1044
|
+
for (const id of [...ids].toReversed()) {
|
|
1045
|
+
if (held.has(id)) continue;
|
|
1046
|
+
(mode === "accept" ? acceptAIEditRevision(id) : rejectAIEditRevision(id))(view.state, view.dispatch, view);
|
|
1047
|
+
}
|
|
1048
|
+
return true;
|
|
1049
|
+
};
|
|
1050
|
+
/**
|
|
947
1051
|
* Resolve a complete state synchronously for a headless reader or writer.
|
|
948
1052
|
*
|
|
949
1053
|
* Uses the same single-step resolver as the interactive editor command.
|
|
@@ -1785,7 +1889,7 @@ function rejectSuggestion(suggestionId) {
|
|
|
1785
1889
|
if (entry.revisionIds.size > 0) {
|
|
1786
1890
|
const ranges = mergeSegments(entry.segments);
|
|
1787
1891
|
const from = ranges[0]?.from ?? 0;
|
|
1788
|
-
|
|
1892
|
+
resolveChangeUnguarded(from, ranges.at(-1)?.to ?? from, "reject", [...entry.revisionIds])(state, (resolved) => {
|
|
1789
1893
|
tr = resolved;
|
|
1790
1894
|
});
|
|
1791
1895
|
}
|
|
@@ -1825,7 +1929,7 @@ function rejectAllSuggestions() {
|
|
|
1825
1929
|
}
|
|
1826
1930
|
const rotationCandidates = removesWholeNode ? collectAddedBreakRotationCandidates(state.doc) : [];
|
|
1827
1931
|
let tr = null;
|
|
1828
|
-
if (revisionIds.size > 0)
|
|
1932
|
+
if (revisionIds.size > 0) resolveChangeUnguarded(0, state.doc.content.size, "reject", [...revisionIds])(state, (resolved) => {
|
|
1829
1933
|
tr = resolved;
|
|
1830
1934
|
});
|
|
1831
1935
|
const workingTr = tr ?? state.tr;
|
|
@@ -1896,7 +2000,7 @@ function findChangeAtPosition(state, from, to) {
|
|
|
1896
2000
|
};
|
|
1897
2001
|
const $pos = state.doc.resolve(from);
|
|
1898
2002
|
const node = $pos.parent;
|
|
1899
|
-
if (!node.
|
|
2003
|
+
if (!node.inlineContent) return {
|
|
1900
2004
|
from,
|
|
1901
2005
|
to
|
|
1902
2006
|
};
|
|
@@ -2057,4 +2161,4 @@ function findPreviousChange(state, startPos) {
|
|
|
2057
2161
|
if (result.value === null && startPos < state.doc.content.size) return findPreviousChange(state, state.doc.content.size);
|
|
2058
2162
|
return result.value;
|
|
2059
2163
|
}
|
|
2060
|
-
export { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, resolveAllChangesInHeadlessState, resolveAllChangesInHeadlessStateWithMapping, suggestionIdOfRevision };
|
|
2164
|
+
export { acceptAIEditRevision, acceptAllChanges, acceptAllSuggestions, acceptChange, acceptSuggestion, addCommentMark, changeResolutionLockViolation, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, lockHeldRevisions, rejectAIEditRevision, rejectAllChanges, rejectAllSuggestions, rejectChange, rejectSuggestion, removeCommentMark, resolveAllChangesInHeadlessState, resolveAllChangesInHeadlessStateWithMapping, revisionResolutionLockViolation, suggestionIdOfRevision, trackedChangeEntryRevisionIds };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "prosemirror-state";
|
|
2
|
+
/**
|
|
3
|
+
* Delete what the caret reaches past the inline anchors beside it.
|
|
4
|
+
*
|
|
5
|
+
* Left to the browser, the key removes the anchor's element, and the next DOM
|
|
6
|
+
* read loses the node: a bookmark or comment range, with the other half of its
|
|
7
|
+
* pair, while the text stays. Suggesting mode tracks the key before it gets here.
|
|
8
|
+
*/
|
|
9
|
+
export declare const deleteBesideInlineAnchor: (join: Command, direction: "backward" | "forward") => Command;
|