@stll/folio-core 0.66.2 → 0.67.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.js +45 -10
- package/dist/ai-edits/batch-claims.js +5 -3
- package/dist/ai-edits/clean-text.js +4 -1
- package/dist/ai-edits/read.js +6 -4
- package/dist/ai-edits/snapshot.js +24 -14
- package/dist/ai-edits/table-cell-mutations.js +3 -2
- package/dist/ai-edits/table-row-column-mutations.js +20 -6
- package/dist/controller/canonicalComposition.d.ts +1 -1
- package/dist/controller/canonicalComposition.js +76 -18
- package/dist/controller/canonicalInput.d.ts +0 -1
- package/dist/controller/canonicalInput.js +19 -1
- package/dist/controller/canonicalSession.js +1 -2
- package/dist/controller/hiddenEditorManager.d.ts +6 -0
- package/dist/controller/hiddenEditorManager.js +3 -1
- package/dist/controller/layoutPipeline.d.ts +2 -0
- package/dist/controller/layoutPipeline.js +7 -3
- package/dist/controller/layoutSession.d.ts +1 -0
- package/dist/display-list/build/tablePrimitives.d.ts +3 -1
- package/dist/display-list/build/tablePrimitives.js +29 -13
- package/dist/docx/chartPreview.d.ts +4 -1
- package/dist/docx/chartPreview.js +26 -15
- package/dist/docx/mainDocumentPart.d.ts +6 -0
- package/dist/docx/mainDocumentPart.js +65 -0
- package/dist/docx/packageParts.d.ts +1 -1
- package/dist/docx/packageParts.js +10 -4
- package/dist/docx/previewBudget.d.ts +6 -0
- package/dist/docx/previewBudget.js +7 -1
- package/dist/docx/rezip.js +4 -4
- package/dist/docx/shapeAlternateContent.js +19 -0
- package/dist/docx/unzip.js +2 -0
- 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/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 +6 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
- package/dist/layout-bridge/engine/clickToPosition.js +5 -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 +7 -4
- package/dist/layout-engine/tableRowBreak.d.ts +10 -0
- package/dist/layout-engine/tableRowBreak.js +151 -36
- package/dist/layout-engine/types.d.ts +7 -2
- 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 +1 -0
- package/dist/layout-painter/renderPage.js +6 -3
- package/dist/layout-painter/renderParagraph.js +3 -2
- package/dist/layout-painter/renderTable.d.ts +5 -2
- package/dist/layout-painter/renderTable.js +33 -19
- package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
- package/dist/prosemirror/commands/comments.js +20 -7
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
- package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
- 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/commentReferenceIntegrity.d.ts +8 -2
- package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
- package/dist/prosemirror/conversion/fromProseDoc.js +39 -4
- package/dist/prosemirror/conversion/toProseDoc.js +6 -4
- 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.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/ListExtension.js +22 -1
- 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/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/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 +87 -7
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
- package/dist/prosemirror/plugins/suggestionMode.js +175 -21
- package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
- package/dist/prosemirror/rowGridOmissions.js +21 -0
- 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 +1 -1
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { applyTableColumnDeletion, applyTableColumnInsertion, applyTableRowDeletion } from "../../../ai-edits/table-row-column-mutations.js";
|
|
1
2
|
import { setTableLookFlags } from "../../../docx/tableLook.js";
|
|
2
3
|
import { TABLE_JUSTIFICATION_VALUES, TABLE_WIDTH_TYPE_VALUES, TEXT_DIRECTION_VALUES } from "../../../types/documentEnumValues.js";
|
|
3
4
|
import { cssBorderStyle } from "../../../utils/borderCss.js";
|
|
@@ -5,9 +6,11 @@ import { isValidHexColor, resolveColor } from "../../../utils/colorResolver.js";
|
|
|
5
6
|
import { resolveTablePlacementAlignment } from "../../../utils/tablePlacement.js";
|
|
6
7
|
import { textFlowCss } from "../../../utils/textDirectionFlow.js";
|
|
7
8
|
import { expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, mergeTableAttrs, mergeTableCellAttrs, mergeTableRowAttrs } from "../../attrs/index.js";
|
|
9
|
+
import { mintRevisionId } from "../../plugins/revisionIds.js";
|
|
8
10
|
import { makeRevisionInfo } from "../../plugins/suggestionMode.js";
|
|
9
11
|
import { pasteTableCells, pastedSliceWithNewTableCells } from "../../tableCellPaste.js";
|
|
10
12
|
import { insertTableColumn, removeTableColumns, removeTableRow } from "../../tableGridMutation.js";
|
|
13
|
+
import { tablePositionedBookmarksPlugin } from "../../tablePositionedBookmarks.js";
|
|
11
14
|
import { createExtension, createNodeExtension } from "../create.js";
|
|
12
15
|
import { panic } from "better-result";
|
|
13
16
|
import { statesNoBorder } from "@stll/docx-core/model";
|
|
@@ -37,9 +40,31 @@ const hasOmittedGridSlots = (table) => {
|
|
|
37
40
|
});
|
|
38
41
|
return found;
|
|
39
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* With Track Changes on, a revision for a structural table edit touching `count`
|
|
45
|
+
* cells or rows. Each takes the next id of a run reserved here, as the document
|
|
46
|
+
* operations do.
|
|
47
|
+
*/
|
|
48
|
+
const trackedTableRevision = (state, count) => {
|
|
49
|
+
const info = makeRevisionInfo(state);
|
|
50
|
+
if (!info) return null;
|
|
51
|
+
for (let reserved = 1; reserved < count; reserved += 1) mintRevisionId();
|
|
52
|
+
return {
|
|
53
|
+
revisionId: info.id,
|
|
54
|
+
author: info.author,
|
|
55
|
+
date: info.date
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* A merged cell cannot run through a position a row omits, nor is that position
|
|
60
|
+
* a cell to split: the file has nothing there to hold either.
|
|
61
|
+
*/
|
|
40
62
|
const preserveOmittedGridSlots = (command) => (state, dispatch, view) => {
|
|
41
63
|
const { table } = getTableContext(state);
|
|
42
|
-
if (table && hasOmittedGridSlots(table))
|
|
64
|
+
if (table && hasOmittedGridSlots(table)) {
|
|
65
|
+
const rect = selectedRect(state);
|
|
66
|
+
if (rect.map.cellsInRect(rect).some((position) => isOmittedGridSlot(expectTableCellAttrs(rect.table.nodeAt(position) ?? table)._omittedGridSlot))) return false;
|
|
67
|
+
}
|
|
43
68
|
return command(state, dispatch, view);
|
|
44
69
|
};
|
|
45
70
|
const preserveSourceCellIdentity = (command) => (state, dispatch, view) => {
|
|
@@ -827,7 +852,7 @@ const TablePluginExtension = createExtension({
|
|
|
827
852
|
*/
|
|
828
853
|
function insertTableRow(state, dispatch, boundaryOffset) {
|
|
829
854
|
const context = getTableContext(state);
|
|
830
|
-
if (!context.isInTable || context.rowIndex === void 0 || !context.table || context.tablePos === void 0
|
|
855
|
+
if (!context.isInTable || context.rowIndex === void 0 || !context.table || context.tablePos === void 0) return false;
|
|
831
856
|
if (!dispatch) return true;
|
|
832
857
|
const { table, tablePos } = context;
|
|
833
858
|
const rect = selectedRect(state);
|
|
@@ -854,9 +879,11 @@ const TablePluginExtension = createExtension({
|
|
|
854
879
|
continue;
|
|
855
880
|
}
|
|
856
881
|
const templatePos = below ?? above;
|
|
857
|
-
|
|
882
|
+
const templateCell = templatePos === void 0 ? null : table.nodeAt(templatePos);
|
|
883
|
+
const omitted = templateCell?.attrs["_omittedGridSlot"] != null;
|
|
884
|
+
if (templatePos === void 0 || !omitted && templatePos === lastTemplatePos) continue;
|
|
858
885
|
lastTemplatePos = templatePos;
|
|
859
|
-
const template =
|
|
886
|
+
const template = omitted ? null : templateCell;
|
|
860
887
|
cells.push((template?.type ?? tableNodeTypes(state.schema).cell).create(buildCellAttrsFromTemplate(template), paragraphType?.create() ?? null));
|
|
861
888
|
}
|
|
862
889
|
const rowNode = table.child(boundaryOffset === 0 ? rect.top : rect.bottom - 1);
|
|
@@ -879,7 +906,6 @@ const TablePluginExtension = createExtension({
|
|
|
879
906
|
function deleteRow(state, dispatch) {
|
|
880
907
|
const context = getTableContext(state);
|
|
881
908
|
if (!context.isInTable || context.rowIndex === void 0 || !context.table || context.tablePos === void 0) return false;
|
|
882
|
-
if (hasOmittedGridSlots(context.table)) return false;
|
|
883
909
|
const tablePos = context.tablePos;
|
|
884
910
|
const table = context.table;
|
|
885
911
|
const rowCount = context.rowCount ?? 0;
|
|
@@ -897,6 +923,30 @@ const TablePluginExtension = createExtension({
|
|
|
897
923
|
const coversAllRows = firstRow === 0 && lastRow >= rowCount - 1;
|
|
898
924
|
if (dispatch) {
|
|
899
925
|
const tr = state.tr;
|
|
926
|
+
const revision = trackedTableRevision(state, lastRow - firstRow + 1);
|
|
927
|
+
if (revision) {
|
|
928
|
+
const rows = [];
|
|
929
|
+
table.forEach((_row, offset, rowIndex) => {
|
|
930
|
+
if (rowIndex >= firstRow && rowIndex <= lastRow) rows.push({
|
|
931
|
+
rowIndex,
|
|
932
|
+
rowPosition: tablePos + 1 + offset
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
for (const [index, row] of rows.entries()) applyTableRowDeletion({
|
|
936
|
+
tr,
|
|
937
|
+
deletion: {
|
|
938
|
+
...row,
|
|
939
|
+
tablePosition: tablePos,
|
|
940
|
+
tableStart: tablePos + 1
|
|
941
|
+
},
|
|
942
|
+
revision: {
|
|
943
|
+
...revision,
|
|
944
|
+
revisionId: revision.revisionId + index
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
dispatch(tr.scrollIntoView());
|
|
948
|
+
return true;
|
|
949
|
+
}
|
|
900
950
|
if (coversAllRows) {
|
|
901
951
|
const tableEnd = tablePos + table.nodeSize;
|
|
902
952
|
const emptyParagraph = state.doc.resolve(tablePos).parent.childCount === 1 ? state.schema.nodes["paragraph"]?.createAndFill() : null;
|
|
@@ -931,7 +981,22 @@ const TablePluginExtension = createExtension({
|
|
|
931
981
|
*/
|
|
932
982
|
function insertColumnBeside(state, dispatch, side) {
|
|
933
983
|
const context = getTableContext(state);
|
|
934
|
-
if (!context.isInTable || context.columnIndex === void 0 || !context.table || context.tablePos === void 0
|
|
984
|
+
if (!context.isInTable || context.columnIndex === void 0 || !context.table || context.tablePos === void 0) return false;
|
|
985
|
+
if (makeRevisionInfo(state) !== null) {
|
|
986
|
+
const rect = selectedRect(state);
|
|
987
|
+
const tr = state.tr;
|
|
988
|
+
if (applyTableColumnInsertion({
|
|
989
|
+
tr,
|
|
990
|
+
insertion: {
|
|
991
|
+
tablePosition: rect.tableStart - 1,
|
|
992
|
+
columnIndex: side === "left" ? rect.left : rect.right
|
|
993
|
+
},
|
|
994
|
+
cellTexts: void 0,
|
|
995
|
+
revision: trackedTableRevision(state, rect.map.height)
|
|
996
|
+
}).type !== "applied") return false;
|
|
997
|
+
if (dispatch) dispatch(tr.scrollIntoView());
|
|
998
|
+
return true;
|
|
999
|
+
}
|
|
935
1000
|
if (dispatch) {
|
|
936
1001
|
const rect = selectedRect(state);
|
|
937
1002
|
const tr = state.tr;
|
|
@@ -968,9 +1033,23 @@ const TablePluginExtension = createExtension({
|
|
|
968
1033
|
*/
|
|
969
1034
|
function deleteColumn(state, dispatch) {
|
|
970
1035
|
const context = getTableContext(state);
|
|
971
|
-
if (!context.isInTable || context.columnIndex === void 0 || !context.table || context.tablePos === void 0 || (context.columnCount ?? 0) <= 1
|
|
1036
|
+
if (!context.isInTable || context.columnIndex === void 0 || !context.table || context.tablePos === void 0 || (context.columnCount ?? 0) <= 1) return false;
|
|
972
1037
|
const rect = selectedRect(state);
|
|
973
1038
|
if (rect.right - rect.left >= rect.map.width) return false;
|
|
1039
|
+
if (makeRevisionInfo(state) !== null) {
|
|
1040
|
+
const tr = state.tr;
|
|
1041
|
+
for (let column = rect.left; column < rect.right; column += 1) if (applyTableColumnDeletion({
|
|
1042
|
+
tr,
|
|
1043
|
+
deletion: {
|
|
1044
|
+
tablePosition: rect.tableStart - 1,
|
|
1045
|
+
columnIndex: column
|
|
1046
|
+
},
|
|
1047
|
+
insertedColumnCount: 0,
|
|
1048
|
+
revision: trackedTableRevision(state, rect.map.height)
|
|
1049
|
+
}).type !== "applied") return false;
|
|
1050
|
+
if (dispatch) dispatch(tr.scrollIntoView());
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
974
1053
|
if (dispatch) {
|
|
975
1054
|
const tr = state.tr;
|
|
976
1055
|
removeTableColumns(tr, rect.tableStart - 1, rect.left, rect.right);
|
|
@@ -1917,6 +1996,7 @@ const TablePluginExtension = createExtension({
|
|
|
1917
1996
|
}),
|
|
1918
1997
|
tableCellPastePlugin,
|
|
1919
1998
|
tableEditing(),
|
|
1999
|
+
tablePositionedBookmarksPlugin(),
|
|
1920
2000
|
activeCellPlugin
|
|
1921
2001
|
],
|
|
1922
2002
|
keyboardShortcuts: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
/**
|
|
3
|
+
* How an inline node with no visible content sits in the editor's DOM.
|
|
4
|
+
*
|
|
5
|
+
* It takes no space, but it keeps a box. A browser's editing commands skip what
|
|
6
|
+
* has no box, so replacing the composition text beside a `display: none` element
|
|
7
|
+
* also removed the element, and the next DOM read lost the node it stood for.
|
|
8
|
+
*/
|
|
9
|
+
export declare const INLINE_ANCHOR_DOM_STYLE = "display: inline-block; width: 0; height: 0; overflow: hidden;";
|
|
10
|
+
/** Whether a node is one of those, which the caret passes without stopping. */
|
|
11
|
+
export declare const isInlineAnchor: (node: Node) => boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/prosemirror/extensions/nodes/inlineAnchorDom.ts
|
|
2
|
+
/**
|
|
3
|
+
* How an inline node with no visible content sits in the editor's DOM.
|
|
4
|
+
*
|
|
5
|
+
* It takes no space, but it keeps a box. A browser's editing commands skip what
|
|
6
|
+
* has no box, so replacing the composition text beside a `display: none` element
|
|
7
|
+
* also removed the element, and the next DOM read lost the node it stood for.
|
|
8
|
+
*/
|
|
9
|
+
const INLINE_ANCHOR_DOM_STYLE = "display: inline-block; width: 0; height: 0; overflow: hidden;";
|
|
10
|
+
const INLINE_ANCHOR_NODE_NAMES = /* @__PURE__ */ new Set([
|
|
11
|
+
"bookmarkBoundary",
|
|
12
|
+
"commentRangeBoundary",
|
|
13
|
+
"commentReference",
|
|
14
|
+
"moveRangeBoundary",
|
|
15
|
+
"noteMarker",
|
|
16
|
+
"rangeAnchor",
|
|
17
|
+
"renderedPageBreak"
|
|
18
|
+
]);
|
|
19
|
+
/** Whether a node is one of those, which the caret passes without stopping. */
|
|
20
|
+
const isInlineAnchor = (node) => INLINE_ANCHOR_NODE_NAMES.has(node.type.name);
|
|
21
|
+
export { INLINE_ANCHOR_DOM_STYLE, isInlineAnchor };
|
|
@@ -35,14 +35,6 @@ export declare function makeRevisionInfo(state: EditorState): {
|
|
|
35
35
|
* (eigenpal/docx-editor#784).
|
|
36
36
|
*/
|
|
37
37
|
export declare function handleSuggestionPaste(view: Pick<EditorView, "dispatch" | "state">, slice: Slice, pluginState: SuggestionModeState): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* With track changes on, a paste into a table's cells (a cell selection, or a
|
|
40
|
-
* block of copied cells) replaces each cell's content the way a paste over a
|
|
41
|
-
* text selection does: the old content struck through, the pasted content
|
|
42
|
-
* after it as an insertion. When the pasted content is whole paragraphs, the
|
|
43
|
-
* last one ends the cell, so its paragraph mark is tracked as added too:
|
|
44
|
-
* rejecting then drops it and accepting joins the struck paragraphs into it.
|
|
45
|
-
*/
|
|
46
38
|
export declare function handleSuggestionTableCellPaste(view: EditorView, slice: Slice, pluginState: SuggestionModeState): boolean;
|
|
47
39
|
/**
|
|
48
40
|
* Remove `from`..`to` of `tr.doc` as a suggestion: text the current author
|
|
@@ -7,6 +7,7 @@ import { encloseWholeControls } from "../contentControlRevisions.js";
|
|
|
7
7
|
import { splitBlockClearBorders } from "../extensions/features/BaseKeymapExtension.js";
|
|
8
8
|
import { JOINED_RUNS_RESTYLED_META } from "../extensions/features/JoinedRunStyleExtension.js";
|
|
9
9
|
import { expandNoteReferenceDeletionRange } from "../extensions/marks/noteReferenceDeletion.js";
|
|
10
|
+
import { isInlineAnchor } from "../extensions/nodes/inlineAnchorDom.js";
|
|
10
11
|
import { carryParagraphProperties, paragraphLeftAfter, recordReplacedParagraphProperties } from "../paragraphPropertyCarry.js";
|
|
11
12
|
import { createPluginKeyOwner } from "../pluginKeyOwner.js";
|
|
12
13
|
import { rebaseParagraphRuns } from "../rebaseParagraphRunFormatting.js";
|
|
@@ -21,7 +22,7 @@ import { selectLockedInlineControl } from "./lockedControlKeyHandling.js";
|
|
|
21
22
|
import { mintRevisionId, seedRevisionIdsFromDoc } from "./revisionIds.js";
|
|
22
23
|
import { Slice } from "prosemirror-model";
|
|
23
24
|
import { CellSelection } from "prosemirror-tables";
|
|
24
|
-
import { Mapping, ReplaceStep } from "prosemirror-transform";
|
|
25
|
+
import { Mapping, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";
|
|
25
26
|
import { AllSelection, EditorState, Plugin, Selection, TextSelection } from "prosemirror-state";
|
|
26
27
|
import { isHistoryTransaction } from "prosemirror-history";
|
|
27
28
|
import { joinBackward, joinForward, selectNodeBackward, selectNodeForward } from "prosemirror-commands";
|
|
@@ -122,6 +123,7 @@ function findAdjacentRevisionForRange(doc, from, to, markTypeName, author) {
|
|
|
122
123
|
*/
|
|
123
124
|
function markRangeAsDeleted(tr, doc, from, to, deletionType, pluginState, joinState) {
|
|
124
125
|
let hasMarkableContent = false;
|
|
126
|
+
const stepsBeforeDoc = doc === tr.doc ? tr.mapping.maps.length : 0;
|
|
125
127
|
doc.nodesBetween(from, to, (node, pos) => {
|
|
126
128
|
if (!canCarryTrackedRunMark(node)) return;
|
|
127
129
|
if (Math.max(pos, from) >= Math.min(pos + node.nodeSize, to)) return;
|
|
@@ -149,7 +151,7 @@ function markRangeAsDeleted(tr, doc, from, to, deletionType, pluginState, joinSt
|
|
|
149
151
|
const $first = doc.resolve(from);
|
|
150
152
|
const $last = doc.resolve(to);
|
|
151
153
|
if (joinState && removedMark && $first.parent.type.name === "paragraph" && $last.parent.type.name === "paragraph" && $first.parent !== $last.parent && from > $first.start()) {
|
|
152
|
-
const lastPos =
|
|
154
|
+
const lastPos = tr.mapping.slice(stepsBeforeDoc).map($last.before());
|
|
153
155
|
const lastMark = tr.doc.nodeAt(lastPos)?.attrs["pPrMark"];
|
|
154
156
|
const survivorPos = lastMark?.kind === "del" || lastMark?.kind === "moveFrom" ? paragraphLeftAfter({
|
|
155
157
|
doc: tr.doc,
|
|
@@ -248,13 +250,17 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
248
250
|
if (!insertionType || !deletionType) return false;
|
|
249
251
|
if (selection.empty) {
|
|
250
252
|
const { $from } = selection;
|
|
251
|
-
const
|
|
253
|
+
const closedBlocks = slice.openStart === 0 && slice.openEnd === 0 && slice.content.firstChild?.isBlock === true;
|
|
252
254
|
const prefix = $from.parent.content.cut(0, $from.parentOffset);
|
|
253
|
-
let deletedPrefix =
|
|
255
|
+
let deletedPrefix = false;
|
|
256
|
+
let keptPrefix = false;
|
|
254
257
|
prefix.forEach((node) => {
|
|
255
|
-
if (
|
|
258
|
+
if (isInlineAnchor(node)) return;
|
|
259
|
+
if (node.marks.some((mark) => mark.type === deletionType)) deletedPrefix = true;
|
|
260
|
+
else keptPrefix = true;
|
|
256
261
|
});
|
|
257
|
-
|
|
262
|
+
deletedPrefix &&= !keptPrefix;
|
|
263
|
+
if (!closedBlocks || $from.parent.type.name !== "paragraph" || !deletedPrefix) return false;
|
|
258
264
|
const suffix = $from.parent.content.cut($from.parentOffset);
|
|
259
265
|
let deletedSuffix = true;
|
|
260
266
|
suffix.forEach((node) => {
|
|
@@ -271,6 +277,18 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
271
277
|
to: end,
|
|
272
278
|
revision
|
|
273
279
|
});
|
|
280
|
+
tr.doc.nodesBetween(at, end, (node, pos) => {
|
|
281
|
+
if (node.type.name !== "paragraph" || node.attrs["pPrMark"] != null) return false;
|
|
282
|
+
tr.setNodeAttribute(pos, "pPrMark", {
|
|
283
|
+
kind: "ins",
|
|
284
|
+
info: {
|
|
285
|
+
id: revision.revisionId,
|
|
286
|
+
author: revision.author,
|
|
287
|
+
date: revision.date
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
return false;
|
|
291
|
+
});
|
|
274
292
|
markRangeAsInserted(tr, tr.doc, at, end, insertionType, deletionType, revision);
|
|
275
293
|
if (deletedSuffix && $from.parent.attrs["pPrMark"] == null && !paragraphEndsItsContainer($from.doc.resolve($from.before()), "paragraph")) tr.setNodeAttribute(tr.mapping.map($from.before()), "pPrMark", {
|
|
276
294
|
kind: "del",
|
|
@@ -379,7 +397,8 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
379
397
|
insertFrom = Math.min(tr.mapping.slice(rotation).map(insertFrom, -1), joined);
|
|
380
398
|
insertTo = tr.mapping.slice(rotation).map(insertTo);
|
|
381
399
|
}
|
|
382
|
-
tr.
|
|
400
|
+
const caret = beforeStruck && !wholeBlocks ? tr.mapping.map(to) : insertTo;
|
|
401
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(caret)));
|
|
383
402
|
view.dispatch(tr.scrollIntoView());
|
|
384
403
|
return true;
|
|
385
404
|
}
|
|
@@ -391,6 +410,13 @@ function handleSuggestionPaste(view, slice, pluginState) {
|
|
|
391
410
|
* last one ends the cell, so its paragraph mark is tracked as added too:
|
|
392
411
|
* rejecting then drops it and accepting joins the struck paragraphs into it.
|
|
393
412
|
*/
|
|
413
|
+
const holdsOnlyStruckText = (paragraph, deletion) => {
|
|
414
|
+
let struck = true;
|
|
415
|
+
paragraph.forEach((node) => {
|
|
416
|
+
if (!node.marks.some((mark) => mark.type === deletion)) struck = false;
|
|
417
|
+
});
|
|
418
|
+
return struck;
|
|
419
|
+
};
|
|
394
420
|
function handleSuggestionTableCellPaste(view, slice, pluginState) {
|
|
395
421
|
const insertionType = view.state.schema.marks["insertion"];
|
|
396
422
|
const deletionType = view.state.schema.marks["deletion"];
|
|
@@ -434,15 +460,25 @@ function handleSuggestionTableCellPaste(view, slice, pluginState) {
|
|
|
434
460
|
});
|
|
435
461
|
}
|
|
436
462
|
const emptyInsertions = [];
|
|
437
|
-
|
|
463
|
+
const struckBreaks = [];
|
|
464
|
+
tr.doc.nodeAt(cellPos)?.forEach((node, offset, index) => {
|
|
438
465
|
const pos = cellPos + 1 + offset;
|
|
439
|
-
if (pos
|
|
466
|
+
if (pos >= pastedFrom || node.type.name !== "paragraph" || !isCurrentAuthorParagraphInsertion(node.attrs["pPrMark"], pluginState.author)) return;
|
|
467
|
+
if (node.content.size === 0) emptyInsertions.push({
|
|
440
468
|
from: pos,
|
|
441
469
|
to: pos + node.nodeSize
|
|
442
470
|
});
|
|
471
|
+
else if (holdsOnlyStruckText(node, deletionType) && isCurrentAuthorParagraphInsertion(cell.maybeChild(index)?.attrs["pPrMark"], pluginState.author)) struckBreaks.push(pos + node.nodeSize);
|
|
443
472
|
});
|
|
444
473
|
const retraction = tr.mapping.maps.length;
|
|
445
474
|
for (const range of emptyInsertions.toReversed()) tr.delete(range.from, range.to);
|
|
475
|
+
for (const boundary of struckBreaks.toReversed()) {
|
|
476
|
+
const at = tr.mapping.slice(retraction).map(boundary);
|
|
477
|
+
const { nodeBefore, nodeAfter } = tr.doc.resolve(at);
|
|
478
|
+
if (nodeBefore?.type.name !== "paragraph" || !nodeAfter) continue;
|
|
479
|
+
tr.setNodeMarkup(at - nodeBefore.nodeSize, void 0, nodeAfter.attrs);
|
|
480
|
+
tr.join(at);
|
|
481
|
+
}
|
|
446
482
|
const retracted = tr.mapping.slice(retraction);
|
|
447
483
|
pastedFrom = retracted.map(pastedFrom);
|
|
448
484
|
insertTo = retracted.map(insertTo);
|
|
@@ -686,7 +722,7 @@ function caretDeleteTarget(state, direction) {
|
|
|
686
722
|
while (cursor >= $from.start() && cursor <= $from.end()) {
|
|
687
723
|
const adjacent = backward ? state.doc.resolve(cursor).nodeBefore : state.doc.resolve(cursor).nodeAfter;
|
|
688
724
|
if (!adjacent) return { type: "paragraphEdge" };
|
|
689
|
-
if (adjacent
|
|
725
|
+
if (!isInlineAnchor(adjacent) && !adjacent.marks.some((mark) => mark.type === state.schema.marks["deletion"])) {
|
|
690
726
|
const size = adjacent.isAtom && !adjacent.isText ? adjacent.nodeSize : 1;
|
|
691
727
|
return {
|
|
692
728
|
type: "inlineUnit",
|
|
@@ -859,11 +895,34 @@ function handleSuggestionDelete(state, dispatch, direction) {
|
|
|
859
895
|
}
|
|
860
896
|
/** Apply the editor's selected-content deletion path for a host cut action. */
|
|
861
897
|
const deleteSelectionAsSuggestion = (state, dispatch) => state.selection.empty ? false : handleSuggestionDelete(state, dispatch, "forward");
|
|
862
|
-
|
|
898
|
+
/**
|
|
899
|
+
* PM reads the removal of cancelled text back from the DOM, which can take the
|
|
900
|
+
* text around it along and drop its revision marks. The same text was there when
|
|
901
|
+
* the composition started: put back what it was.
|
|
902
|
+
*/
|
|
903
|
+
function restoreAfterCancelledComposition(view, startDoc) {
|
|
904
|
+
const { doc } = view.state;
|
|
905
|
+
const start = startDoc.content.findDiffStart(doc.content);
|
|
906
|
+
const end = startDoc.content.findDiffEnd(doc.content);
|
|
907
|
+
if (start === null || end === null) return;
|
|
908
|
+
if (end.a !== end.b || end.a <= start || startDoc.textBetween(start, end.a, "\n", "\n") !== doc.textBetween(start, end.a, "\n", "\n")) return;
|
|
909
|
+
const tr = view.state.tr.replace(start, end.a, startDoc.slice(start, end.a));
|
|
910
|
+
tr.setMeta(SUGGESTION_META, true);
|
|
911
|
+
tr.setMeta("addToHistory", false);
|
|
912
|
+
view.dispatch(tr);
|
|
913
|
+
}
|
|
914
|
+
function markComposedAsInsertion({ view, from, startDoc, foreignSize, foreignEdit, pluginState, replaced, compositionId }) {
|
|
863
915
|
const insertionType = view.state.schema.marks["insertion"];
|
|
864
916
|
const deletionType = view.state.schema.marks["deletion"];
|
|
865
917
|
if (!insertionType || !deletionType) return;
|
|
866
|
-
const
|
|
918
|
+
const { doc } = view.state;
|
|
919
|
+
const composedSize = doc.content.size - startDoc.content.size - foreignSize + (replaced?.size ?? 0);
|
|
920
|
+
const to = Math.min(from + composedSize, view.state.selection.to);
|
|
921
|
+
if (doc.eq(startDoc)) return;
|
|
922
|
+
if (composedSize === 0 && !replaced) {
|
|
923
|
+
if (!foreignEdit) restoreAfterCancelledComposition(view, startDoc);
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
867
926
|
if (to <= from && !replaced) return;
|
|
868
927
|
const tr = view.state.tr;
|
|
869
928
|
tr.setMeta(SUGGESTION_META, true);
|
|
@@ -907,15 +966,24 @@ function recordSplitParagraph(tr, before, step, insertedFrom, insertedTo, attrs)
|
|
|
907
966
|
if ($last.parent.type.name === "paragraph") lastPos = $last.before();
|
|
908
967
|
else if ($last.nodeBefore?.type.name === "paragraph") lastPos = insertedTo - $last.nodeBefore.nodeSize;
|
|
909
968
|
if ($first.parent.type.name !== "paragraph" || lastPos === null || lastPos === $first.before()) return;
|
|
969
|
+
const revision = {
|
|
970
|
+
id: attrs.revisionId,
|
|
971
|
+
author: attrs.author,
|
|
972
|
+
date: attrs.date
|
|
973
|
+
};
|
|
974
|
+
const { pPrMark } = expectParagraphAttrs(split);
|
|
975
|
+
if (pPrMark) {
|
|
976
|
+
tr.setNodeAttribute(lastPos, "pPrMark", pPrMark);
|
|
977
|
+
tr.setNodeAttribute($first.before(), "pPrMark", {
|
|
978
|
+
kind: "ins",
|
|
979
|
+
info: revision
|
|
980
|
+
});
|
|
981
|
+
}
|
|
910
982
|
recordReplacedParagraphProperties({
|
|
911
983
|
tr,
|
|
912
984
|
position: lastPos,
|
|
913
985
|
replaced: split,
|
|
914
|
-
revision
|
|
915
|
-
id: attrs.revisionId,
|
|
916
|
-
author: attrs.author,
|
|
917
|
-
date: attrs.date
|
|
918
|
-
}
|
|
986
|
+
revision
|
|
919
987
|
});
|
|
920
988
|
}
|
|
921
989
|
/**
|
|
@@ -950,6 +1018,62 @@ function restoreReplacedInline({ tr, replaced, deletionType, pluginState }) {
|
|
|
950
1018
|
markRangeAsDeleted(tr, tr.doc, pos, pos + content.size, deletionType, pluginState);
|
|
951
1019
|
}
|
|
952
1020
|
}
|
|
1021
|
+
const readableContent = (content) => content.textBetween(0, content.size, "", "");
|
|
1022
|
+
/**
|
|
1023
|
+
* The inline content a step puts in place of a selection, or null for block
|
|
1024
|
+
* content. Between containers, the step also carries the text after the
|
|
1025
|
+
* selection over into the first one, and fills out what it cut with empty blocks.
|
|
1026
|
+
*/
|
|
1027
|
+
const insertedInline = (step, $to, to) => {
|
|
1028
|
+
const { content } = step.slice;
|
|
1029
|
+
let inline = content;
|
|
1030
|
+
while (inline.firstChild && !inline.firstChild.isInline) inline = inline.firstChild.content;
|
|
1031
|
+
if (readableContent(inline) !== readableContent(content)) return null;
|
|
1032
|
+
if (step.to === to || step instanceof ReplaceAroundStep) return inline;
|
|
1033
|
+
const tail = $to.parent.content.cut($to.parentOffset);
|
|
1034
|
+
const kept = inline.size - tail.size;
|
|
1035
|
+
return kept >= 0 && inline.cut(kept).eq(tail) ? inline.cut(0, kept) : null;
|
|
1036
|
+
};
|
|
1037
|
+
/**
|
|
1038
|
+
* A transaction the plugin did not build (a key binding, a command) replacing a
|
|
1039
|
+
* selection that spans textblocks. Null for anything else: table structure and
|
|
1040
|
+
* block content have their own paths, and a replacement inside one textblock
|
|
1041
|
+
* is `replacedInline`'s.
|
|
1042
|
+
*/
|
|
1043
|
+
function spanningReplacement(oldState, userTr) {
|
|
1044
|
+
const [step] = userTr.steps;
|
|
1045
|
+
const { doc, selection } = oldState;
|
|
1046
|
+
if (userTr.steps.length !== 1 || !(step instanceof ReplaceStep || step instanceof ReplaceAroundStep) || userTr.before !== doc || selection.empty) return null;
|
|
1047
|
+
const selectsAll = selection instanceof AllSelection;
|
|
1048
|
+
const from = selectsAll ? Selection.atStart(doc).from : selection.from;
|
|
1049
|
+
const to = selectsAll ? Selection.atEnd(doc).to : selection.to;
|
|
1050
|
+
const $from = doc.resolve(from);
|
|
1051
|
+
const $to = doc.resolve(to);
|
|
1052
|
+
if (!$from.parent.inlineContent || !$to.parent.inlineContent || $from.sameParent($to) || step.from > from || step.to < to || step instanceof ReplaceAroundStep && step.gapFrom < to) return null;
|
|
1053
|
+
const inserted = insertedInline(step, $to, to);
|
|
1054
|
+
return inserted && {
|
|
1055
|
+
step,
|
|
1056
|
+
from,
|
|
1057
|
+
to,
|
|
1058
|
+
inserted
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Put the document back and make the same replacement as typing over the
|
|
1063
|
+
* selection does: the selected text is struck and what replaced it follows, so
|
|
1064
|
+
* rejecting restores the source and accepting matches the direct edit.
|
|
1065
|
+
*/
|
|
1066
|
+
function trackSpanningReplacement({ tr, oldState, replacement: { step, from, to, inserted }, insertionType, deletionType, pluginState }) {
|
|
1067
|
+
tr.step(step.invert(oldState.doc));
|
|
1068
|
+
const restored = tr.mapping.maps.length;
|
|
1069
|
+
markRangeAsDeleted(tr, tr.doc, from, to, deletionType, pluginState, oldState);
|
|
1070
|
+
const at = tr.mapping.slice(restored).map(to);
|
|
1071
|
+
tr.insert(at, inserted);
|
|
1072
|
+
const end = at + inserted.size;
|
|
1073
|
+
tr.removeMark(at, end, deletionType);
|
|
1074
|
+
markRangeAsInserted(tr, tr.doc, at, end, insertionType, deletionType, makeMarkAttrs(pluginState));
|
|
1075
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(end), -1));
|
|
1076
|
+
}
|
|
953
1077
|
/**
|
|
954
1078
|
* Create the suggestion mode plugin.
|
|
955
1079
|
* When active, text edits become tracked changes.
|
|
@@ -957,6 +1081,9 @@ function restoreReplacedInline({ tr, replaced, deletionType, pluginState }) {
|
|
|
957
1081
|
function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
958
1082
|
let composing = false;
|
|
959
1083
|
let compositionFrom = null;
|
|
1084
|
+
let compositionStartDoc = null;
|
|
1085
|
+
let compositionForeignSize = 0;
|
|
1086
|
+
let compositionForeignEdit = false;
|
|
960
1087
|
let compositionReplaced = null;
|
|
961
1088
|
let compositionId = null;
|
|
962
1089
|
return new Plugin({
|
|
@@ -972,6 +1099,11 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
972
1099
|
apply(tr, state) {
|
|
973
1100
|
const nativeCompositionId = tr.getMeta("composition");
|
|
974
1101
|
if (composing && tr.docChanged && typeof nativeCompositionId === "number") compositionId = nativeCompositionId;
|
|
1102
|
+
if (composing && tr.docChanged && tr.getMeta("y-sync$") !== void 0) {
|
|
1103
|
+
compositionForeignEdit = true;
|
|
1104
|
+
compositionForeignSize += tr.doc.content.size - tr.before.content.size;
|
|
1105
|
+
if (compositionFrom !== null) compositionFrom = tr.mapping.map(compositionFrom);
|
|
1106
|
+
}
|
|
975
1107
|
const meta = tr.getMeta(suggestionModeKey);
|
|
976
1108
|
if (meta) return {
|
|
977
1109
|
...state,
|
|
@@ -1000,16 +1132,21 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1000
1132
|
compositionId = null;
|
|
1001
1133
|
const { from, to } = view.state.selection;
|
|
1002
1134
|
compositionFrom = from;
|
|
1135
|
+
compositionStartDoc = view.state.doc;
|
|
1136
|
+
compositionForeignSize = 0;
|
|
1137
|
+
compositionForeignEdit = false;
|
|
1003
1138
|
compositionReplaced = from === to ? null : view.state.doc.slice(from, to);
|
|
1004
1139
|
return false;
|
|
1005
1140
|
},
|
|
1006
1141
|
compositionend(view) {
|
|
1007
1142
|
const pluginState = suggestionModeKey.getState(view.state);
|
|
1008
1143
|
const from = compositionFrom;
|
|
1144
|
+
const startDoc = compositionStartDoc;
|
|
1009
1145
|
const replaced = compositionReplaced;
|
|
1010
1146
|
compositionFrom = null;
|
|
1147
|
+
compositionStartDoc = null;
|
|
1011
1148
|
compositionReplaced = null;
|
|
1012
|
-
if (!pluginState?.active || from == null) {
|
|
1149
|
+
if (!pluginState?.active || from == null || !startDoc) {
|
|
1013
1150
|
composing = false;
|
|
1014
1151
|
compositionId = null;
|
|
1015
1152
|
return false;
|
|
@@ -1021,6 +1158,9 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1021
1158
|
if (current?.active) markComposedAsInsertion({
|
|
1022
1159
|
view,
|
|
1023
1160
|
from,
|
|
1161
|
+
startDoc,
|
|
1162
|
+
foreignSize: compositionForeignSize,
|
|
1163
|
+
foreignEdit: compositionForeignEdit,
|
|
1024
1164
|
pluginState: current,
|
|
1025
1165
|
replaced,
|
|
1026
1166
|
compositionId: nativeCompositionId
|
|
@@ -1040,6 +1180,7 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1040
1180
|
handleKeyDown(view, event) {
|
|
1041
1181
|
const pluginState = suggestionModeKey.getState(view.state);
|
|
1042
1182
|
if (!pluginState?.active) return false;
|
|
1183
|
+
if (composing) return false;
|
|
1043
1184
|
if (selectLockedInlineControl(view, event)) return true;
|
|
1044
1185
|
if (event.key === "Enter" && !event.shiftKey && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
1045
1186
|
const { $from, empty } = view.state.selection;
|
|
@@ -1049,8 +1190,9 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1049
1190
|
if (event.key === "Backspace" && undoInputRule(view.state, view.dispatch)) return true;
|
|
1050
1191
|
if (event.key === "Backspace" || event.key === "Delete") {
|
|
1051
1192
|
const { $from, empty } = view.state.selection;
|
|
1052
|
-
|
|
1053
|
-
if (event.
|
|
1193
|
+
const atListItemStart = event.key === "Backspace" && empty && $from.parentOffset === 0 && $from.parent.type.name === "paragraph" && expectParagraphAttrs($from.parent).numPr?.kind === "reference";
|
|
1194
|
+
if (atListItemStart && !event.ctrlKey && !event.metaKey && !event.shiftKey) return false;
|
|
1195
|
+
if (event.key === "Backspace" && !atListItemStart && clearIndentOnBackspace(view.state, (tr) => {
|
|
1054
1196
|
const revision = makeMarkAttrs(pluginState);
|
|
1055
1197
|
recordReplacedParagraphProperties({
|
|
1056
1198
|
tr,
|
|
@@ -1083,7 +1225,7 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1083
1225
|
return handleSuggestionTableCellPaste(view, slice, pluginState) || handleSuggestionPaste(view, slice, pluginState);
|
|
1084
1226
|
}
|
|
1085
1227
|
},
|
|
1086
|
-
appendTransaction(transactions,
|
|
1228
|
+
appendTransaction(transactions, oldState, newState) {
|
|
1087
1229
|
const pluginState = suggestionModeKey.getState(newState);
|
|
1088
1230
|
if (!pluginState?.active) return null;
|
|
1089
1231
|
if (composing) return null;
|
|
@@ -1097,6 +1239,18 @@ function createSuggestionModePlugin(initialActive = false, author = "User") {
|
|
|
1097
1239
|
const deletionType = newState.schema.marks["deletion"];
|
|
1098
1240
|
const laterMaps = transactions.slice(transactions.indexOf(userTr) + 1).flatMap((transaction) => transaction.mapping.maps);
|
|
1099
1241
|
const restoresReplaced = userTr.getMeta("appendedTransaction") === void 0;
|
|
1242
|
+
const spanning = deletionType && restoresReplaced && newState.doc === userTr.doc ? spanningReplacement(oldState, userTr) : null;
|
|
1243
|
+
if (deletionType && spanning) {
|
|
1244
|
+
trackSpanningReplacement({
|
|
1245
|
+
tr,
|
|
1246
|
+
oldState,
|
|
1247
|
+
replacement: spanning,
|
|
1248
|
+
insertionType,
|
|
1249
|
+
deletionType,
|
|
1250
|
+
pluginState
|
|
1251
|
+
});
|
|
1252
|
+
return tr;
|
|
1253
|
+
}
|
|
1100
1254
|
const replaced = [];
|
|
1101
1255
|
for (const [stepIndex, step] of userTr.steps.entries()) {
|
|
1102
1256
|
const stepMap = step.getMap();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
/**
|
|
3
|
+
* What a row omits, as its placeholders hold it now: column edits move them, and
|
|
4
|
+
* the formatting the row was read with goes stale. Before its cells, this is
|
|
5
|
+
* what places them. After them it stays a statement of no more than the row
|
|
6
|
+
* omits: the row may stop short of the table by more than it states.
|
|
7
|
+
*/
|
|
8
|
+
export declare const rowGridOmissions: (row: Node, statedAfter: number) => {
|
|
9
|
+
gridBefore: number;
|
|
10
|
+
gridAfter: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/prosemirror/rowGridOmissions.ts
|
|
2
|
+
/**
|
|
3
|
+
* What a row omits, as its placeholders hold it now: column edits move them, and
|
|
4
|
+
* the formatting the row was read with goes stale. Before its cells, this is
|
|
5
|
+
* what places them. After them it stays a statement of no more than the row
|
|
6
|
+
* omits: the row may stop short of the table by more than it states.
|
|
7
|
+
*/
|
|
8
|
+
const rowGridOmissions = (row, statedAfter) => {
|
|
9
|
+
let before = 0;
|
|
10
|
+
let after = 0;
|
|
11
|
+
row.forEach((cell) => {
|
|
12
|
+
const colspan = Number(cell.attrs["colspan"]) || 1;
|
|
13
|
+
if (cell.attrs["_omittedGridSlot"] === "before") before += colspan;
|
|
14
|
+
if (cell.attrs["_omittedGridSlot"] === "after") after += colspan;
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
gridBefore: before,
|
|
18
|
+
gridAfter: Math.min(statedAfter, after)
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export { rowGridOmissions };
|
|
@@ -18,6 +18,20 @@ type RemoveTableRowOptions = {
|
|
|
18
18
|
* and the table is left one row shorter than that merge.
|
|
19
19
|
*/
|
|
20
20
|
export declare const removeTableRow: (tr: Transaction, { map, table, tableStart }: RemoveTableRowOptions, row: number) => void;
|
|
21
|
+
/** A placeholder for an absent grid position is not a cell a row can keep. */
|
|
22
|
+
export declare const rowHoldsNoCells: (row: Node, besides?: Node) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The placeholder a new column's place in a row falls to, if any. Nothing can
|
|
25
|
+
* stand after what a row omits at its end or before what it omits at its start:
|
|
26
|
+
* a cell there would move on save, so the omission grows instead.
|
|
27
|
+
*/
|
|
28
|
+
export declare const omittedSlotTakingColumn: (map: TableMap, table: Node, row: number, column: number) => number | null;
|
|
29
|
+
/**
|
|
30
|
+
* Size what rows omit to the width their cells now reach. A column whose cells
|
|
31
|
+
* went takes the same column out of a row that omits it; removing a tracked
|
|
32
|
+
* column's last cell does not otherwise reach such a row.
|
|
33
|
+
*/
|
|
34
|
+
export declare const reconcileOmittedGridSlots: (tr: Transaction, tablePosition: number, previousTable: Node, removedColumn: number) => void;
|
|
21
35
|
/** Whether a batch of structural deletions may have emptied rows. */
|
|
22
36
|
export type RowsEmptiedInBatch = {
|
|
23
37
|
pending: boolean;
|
|
@@ -46,8 +60,11 @@ type RemoveRowsWithoutCellsInRangeOptions = {
|
|
|
46
60
|
};
|
|
47
61
|
/** Close marked rows before their owning cell is captured into a continuation payload. */
|
|
48
62
|
export declare const removeRowsWithoutCellsInRange: ({ tr, from, to }: RemoveRowsWithoutCellsInRangeOptions) => void;
|
|
49
|
-
/**
|
|
50
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Close the rows an immediate structural edit left without cells. A row written
|
|
65
|
+
* with none is no row this edit emptied, and it stays.
|
|
66
|
+
*/
|
|
67
|
+
export declare const removeRowsWithoutCells: (tr: Transaction, tablePosition: number, previousTable: Node) => void;
|
|
51
68
|
type ReconcileTableGridAfterColumnRemovalOptions = {
|
|
52
69
|
tr: Transaction;
|
|
53
70
|
tablePosition: number;
|