@atlaskit/editor-plugin-table 7.16.11 → 7.16.13
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/.eslintrc.js +3 -3
- package/CHANGELOG.md +16 -0
- package/dist/cjs/commands/misc.js +3 -3
- package/dist/cjs/nodeviews/TableCell.js +10 -10
- package/dist/cjs/nodeviews/TableContainer.js +83 -27
- package/dist/cjs/nodeviews/TableResizer.js +40 -19
- package/dist/cjs/nodeviews/TableRow.js +23 -23
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/cjs/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/cjs/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/cjs/ui/common-styles.js +13 -13
- package/dist/cjs/ui/ui-styles.js +25 -25
- package/dist/cjs/utils/guidelines.js +7 -4
- package/dist/cjs/utils/merged-cells.js +3 -3
- package/dist/cjs/utils/snapping.js +7 -8
- package/dist/es2019/commands/misc.js +3 -3
- package/dist/es2019/nodeviews/TableContainer.js +70 -9
- package/dist/es2019/nodeviews/TableResizer.js +42 -21
- package/dist/es2019/nodeviews/TableRow.js +21 -21
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/es2019/ui/FloatingContextualMenu/styles.js +47 -47
- package/dist/es2019/ui/FloatingDragMenu/styles.js +30 -30
- package/dist/es2019/ui/common-styles.js +802 -816
- package/dist/es2019/ui/ui-styles.js +665 -678
- package/dist/es2019/utils/guidelines.js +5 -2
- package/dist/es2019/utils/merged-cells.js +3 -3
- package/dist/es2019/utils/snapping.js +5 -6
- package/dist/esm/commands/misc.js +3 -3
- package/dist/esm/nodeviews/TableCell.js +10 -10
- package/dist/esm/nodeviews/TableContainer.js +85 -29
- package/dist/esm/nodeviews/TableResizer.js +42 -21
- package/dist/esm/nodeviews/TableRow.js +23 -23
- package/dist/esm/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/esm/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/esm/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/esm/ui/common-styles.js +13 -13
- package/dist/esm/ui/ui-styles.js +25 -25
- package/dist/esm/utils/guidelines.js +6 -3
- package/dist/esm/utils/merged-cells.js +3 -3
- package/dist/esm/utils/snapping.js +6 -7
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types/utils/guidelines.d.ts +2 -1
- package/dist/types/utils/snapping.d.ts +3 -2
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types-ts4.5/utils/guidelines.d.ts +2 -1
- package/dist/types-ts4.5/utils/snapping.d.ts +3 -2
- package/docs/0-intro.tsx +9 -7
- package/package.json +3 -3
- package/report.api.md +67 -66
- package/src/commands/clear.ts +36 -44
- package/src/commands/collapse.ts +8 -8
- package/src/commands/column-resize.ts +412 -452
- package/src/commands/delete.ts +14 -14
- package/src/commands/display-mode.ts +10 -11
- package/src/commands/go-to-next-cell.ts +48 -54
- package/src/commands/hover.ts +210 -227
- package/src/commands/index.ts +35 -35
- package/src/commands/insert.ts +208 -235
- package/src/commands/misc.ts +655 -748
- package/src/commands/referentiality.ts +9 -9
- package/src/commands/selection.ts +433 -563
- package/src/commands/sort.ts +68 -86
- package/src/commands/split-cell.ts +14 -14
- package/src/commands/toggle.ts +69 -67
- package/src/commands-with-analytics.ts +570 -639
- package/src/create-plugin-config.ts +13 -13
- package/src/event-handlers.ts +513 -612
- package/src/handlers.ts +120 -133
- package/src/nodeviews/ExternalDropTargets.tsx +68 -73
- package/src/nodeviews/OverflowShadowsObserver.ts +148 -157
- package/src/nodeviews/TableCell.ts +47 -54
- package/src/nodeviews/TableComponent.tsx +1018 -1112
- package/src/nodeviews/TableComponentWithSharedState.tsx +91 -94
- package/src/nodeviews/TableContainer.tsx +384 -340
- package/src/nodeviews/TableNodeViewBase.ts +19 -24
- package/src/nodeviews/TableResizer.tsx +642 -653
- package/src/nodeviews/TableRow.ts +580 -629
- package/src/nodeviews/TableStickyScrollbar.ts +173 -190
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +8 -8
- package/src/nodeviews/__mocks__/OverridableMock.ts +14 -15
- package/src/nodeviews/table.tsx +345 -375
- package/src/nodeviews/types.ts +21 -24
- package/src/nodeviews/update-overflow-shadows.ts +8 -14
- package/src/plugin.tsx +578 -603
- package/src/pm-plugins/analytics/actions.ts +10 -12
- package/src/pm-plugins/analytics/commands.ts +31 -37
- package/src/pm-plugins/analytics/plugin-factory.ts +4 -2
- package/src/pm-plugins/analytics/plugin-key.ts +1 -3
- package/src/pm-plugins/analytics/plugin.ts +60 -70
- package/src/pm-plugins/analytics/reducer.ts +19 -19
- package/src/pm-plugins/analytics/types.ts +10 -10
- package/src/pm-plugins/analytics/utils/moved-event.ts +38 -38
- package/src/pm-plugins/decorations/plugin.ts +58 -77
- package/src/pm-plugins/decorations/utils/column-controls.ts +59 -71
- package/src/pm-plugins/decorations/utils/column-resizing.ts +50 -57
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +6 -6
- package/src/pm-plugins/decorations/utils/index.ts +3 -6
- package/src/pm-plugins/decorations/utils/types.ts +7 -12
- package/src/pm-plugins/default-table-selection.ts +3 -3
- package/src/pm-plugins/drag-and-drop/actions.ts +25 -25
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +158 -190
- package/src/pm-plugins/drag-and-drop/commands.ts +154 -170
- package/src/pm-plugins/drag-and-drop/consts.ts +4 -5
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +23 -20
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +1 -3
- package/src/pm-plugins/drag-and-drop/plugin.ts +329 -383
- package/src/pm-plugins/drag-and-drop/reducer.ts +30 -30
- package/src/pm-plugins/drag-and-drop/types.ts +8 -8
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +38 -41
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +3 -6
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +57 -70
- package/src/pm-plugins/keymap.ts +208 -220
- package/src/pm-plugins/main.ts +348 -400
- package/src/pm-plugins/plugin-factory.ts +32 -34
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +83 -97
- package/src/pm-plugins/sticky-headers/commands.ts +2 -6
- package/src/pm-plugins/sticky-headers/plugin-key.ts +1 -3
- package/src/pm-plugins/sticky-headers/plugin-state.ts +41 -44
- package/src/pm-plugins/sticky-headers/plugin.ts +4 -4
- package/src/pm-plugins/sticky-headers/types.ts +8 -8
- package/src/pm-plugins/sticky-headers/util.ts +10 -10
- package/src/pm-plugins/table-analytics.ts +70 -72
- package/src/pm-plugins/table-local-id.ts +180 -184
- package/src/pm-plugins/table-resizing/commands.ts +72 -85
- package/src/pm-plugins/table-resizing/event-handlers.ts +298 -317
- package/src/pm-plugins/table-resizing/plugin-factory.ts +10 -10
- package/src/pm-plugins/table-resizing/plugin-key.ts +1 -3
- package/src/pm-plugins/table-resizing/plugin.ts +61 -68
- package/src/pm-plugins/table-resizing/reducer.ts +30 -33
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +84 -84
- package/src/pm-plugins/table-resizing/utils/column-state.ts +78 -81
- package/src/pm-plugins/table-resizing/utils/content-width.ts +94 -114
- package/src/pm-plugins/table-resizing/utils/dom.ts +93 -110
- package/src/pm-plugins/table-resizing/utils/index.ts +29 -34
- package/src/pm-plugins/table-resizing/utils/misc.ts +94 -119
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +93 -106
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +240 -257
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +343 -372
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +202 -207
- package/src/pm-plugins/table-resizing/utils/types.ts +17 -17
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +1 -2
- package/src/pm-plugins/table-selection-keymap.ts +25 -51
- package/src/pm-plugins/table-width.ts +191 -204
- package/src/pm-plugins/view-mode-sort/index.ts +223 -227
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +3 -2
- package/src/pm-plugins/view-mode-sort/types.ts +12 -12
- package/src/pm-plugins/view-mode-sort/utils.ts +108 -117
- package/src/reducer.ts +139 -155
- package/src/toolbar.tsx +815 -905
- package/src/transforms/column-width.ts +186 -213
- package/src/transforms/delete-columns.ts +208 -222
- package/src/transforms/delete-rows.ts +117 -121
- package/src/transforms/fix-tables.ts +190 -215
- package/src/transforms/merge.ts +263 -269
- package/src/transforms/replace-table.ts +27 -43
- package/src/transforms/split.ts +65 -75
- package/src/types.ts +421 -427
- package/src/ui/ColumnResizeWidget/index.tsx +40 -47
- package/src/ui/DragHandle/HandleIconComponent.tsx +9 -13
- package/src/ui/DragHandle/index.tsx +221 -250
- package/src/ui/DragPreview/index.tsx +35 -35
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +33 -41
- package/src/ui/FloatingContextualButton/FixedButton.tsx +154 -157
- package/src/ui/FloatingContextualButton/index.tsx +109 -115
- package/src/ui/FloatingContextualButton/styles.ts +43 -46
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +634 -694
- package/src/ui/FloatingContextualMenu/index.tsx +83 -101
- package/src/ui/FloatingContextualMenu/styles.ts +57 -65
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +37 -37
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +47 -57
- package/src/ui/FloatingDeleteButton/index.tsx +319 -350
- package/src/ui/FloatingDragMenu/DragMenu.tsx +555 -596
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +152 -162
- package/src/ui/FloatingDragMenu/index.tsx +88 -102
- package/src/ui/FloatingDragMenu/styles.ts +51 -54
- package/src/ui/FloatingInsertButton/InsertButton.tsx +204 -217
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +100 -115
- package/src/ui/FloatingInsertButton/index.tsx +248 -292
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +24 -29
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +308 -329
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +85 -94
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +46 -46
- package/src/ui/TableFloatingColumnControls/index.tsx +116 -136
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +79 -91
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +95 -102
- package/src/ui/TableFloatingControls/CornerControls/index.tsx +1 -4
- package/src/ui/TableFloatingControls/CornerControls/types.ts +8 -8
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +50 -50
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +111 -124
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +86 -105
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +305 -341
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +72 -75
- package/src/ui/TableFloatingControls/index.tsx +191 -193
- package/src/ui/TableFullWidthLabel/index.tsx +20 -20
- package/src/ui/common-styles.ts +880 -912
- package/src/ui/consts.ts +29 -74
- package/src/ui/icons/AddColLeftIcon.tsx +33 -39
- package/src/ui/icons/AddColRightIcon.tsx +33 -39
- package/src/ui/icons/AddRowAboveIcon.tsx +16 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +33 -39
- package/src/ui/icons/DisplayModeIcon.tsx +31 -31
- package/src/ui/icons/DragHandleDisabledIcon.tsx +19 -21
- package/src/ui/icons/DragHandleIcon.tsx +12 -12
- package/src/ui/icons/DragInMotionIcon.tsx +45 -52
- package/src/ui/icons/MergeCellsIcon.tsx +22 -28
- package/src/ui/icons/MinimisedHandle.tsx +9 -9
- package/src/ui/icons/SplitCellIcon.tsx +30 -36
- package/src/ui/ui-styles.ts +769 -798
- package/src/utils/alignment.ts +1 -1
- package/src/utils/analytics.ts +192 -208
- package/src/utils/collapse.ts +55 -64
- package/src/utils/column-controls.ts +237 -254
- package/src/utils/create.ts +30 -30
- package/src/utils/decoration.ts +482 -502
- package/src/utils/dom.ts +127 -134
- package/src/utils/drag-menu.ts +322 -373
- package/src/utils/get-allow-add-column-custom-step.ts +4 -5
- package/src/utils/guidelines.ts +16 -21
- package/src/utils/index.ts +68 -68
- package/src/utils/merged-cells.ts +245 -254
- package/src/utils/nodes.ts +91 -106
- package/src/utils/paste.ts +119 -135
- package/src/utils/row-controls.ts +199 -213
- package/src/utils/selection.ts +77 -87
- package/src/utils/snapping.ts +87 -100
- package/src/utils/table.ts +44 -44
- package/src/utils/transforms.ts +5 -5
- package/src/utils/update-plugin-state-decorations.ts +5 -9
package/src/utils/decoration.ts
CHANGED
|
@@ -9,233 +9,216 @@ import { nonNullable } from '@atlaskit/editor-common/utils';
|
|
|
9
9
|
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
10
10
|
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
11
11
|
import type {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
ReadonlyTransaction,
|
|
13
|
+
Selection,
|
|
14
|
+
Transaction,
|
|
15
15
|
} from '@atlaskit/editor-prosemirror/state';
|
|
16
16
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
17
17
|
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
18
18
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
19
19
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
20
|
-
import {
|
|
21
|
-
findTable,
|
|
22
|
-
getCellsInRow,
|
|
23
|
-
getSelectionRect,
|
|
24
|
-
} from '@atlaskit/editor-tables/utils';
|
|
20
|
+
import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
25
21
|
|
|
26
22
|
import type { Cell, CellColumnPositioning } from '../types';
|
|
27
23
|
import { TableCssClassName as ClassName, TableDecorations } from '../types';
|
|
28
24
|
import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
|
|
29
25
|
|
|
30
|
-
const filterDecorationByKey = (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
): Decoration[] =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
export const findColumnControlSelectedDecoration = (
|
|
41
|
-
decorationSet: DecorationSet,
|
|
42
|
-
): Decoration[] =>
|
|
43
|
-
filterDecorationByKey(TableDecorations.COLUMN_SELECTED, decorationSet);
|
|
44
|
-
|
|
45
|
-
export const findControlsHoverDecoration = (
|
|
46
|
-
decorationSet: DecorationSet,
|
|
47
|
-
): Decoration[] =>
|
|
48
|
-
filterDecorationByKey(TableDecorations.ALL_CONTROLS_HOVER, decorationSet);
|
|
26
|
+
const filterDecorationByKey = (key: TableDecorations, decorationSet: DecorationSet): Decoration[] =>
|
|
27
|
+
decorationSet.find(undefined, undefined, (spec) => spec.key.indexOf(key) > -1);
|
|
28
|
+
|
|
29
|
+
export const findColumnControlSelectedDecoration = (decorationSet: DecorationSet): Decoration[] =>
|
|
30
|
+
filterDecorationByKey(TableDecorations.COLUMN_SELECTED, decorationSet);
|
|
31
|
+
|
|
32
|
+
export const findControlsHoverDecoration = (decorationSet: DecorationSet): Decoration[] =>
|
|
33
|
+
filterDecorationByKey(TableDecorations.ALL_CONTROLS_HOVER, decorationSet);
|
|
49
34
|
|
|
50
35
|
export const createCellHoverDecoration = (cells: Cell[]): Decoration[] =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
36
|
+
cells.map((cell) =>
|
|
37
|
+
Decoration.node(
|
|
38
|
+
cell.pos,
|
|
39
|
+
cell.pos + cell.node.nodeSize,
|
|
40
|
+
{
|
|
41
|
+
class: ClassName.HOVERED_CELL_WARNING,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: TableDecorations.CELL_CONTROLS_HOVER,
|
|
45
|
+
},
|
|
46
|
+
),
|
|
47
|
+
);
|
|
63
48
|
|
|
64
49
|
export const createControlsHoverDecoration = (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
50
|
+
cells: Cell[],
|
|
51
|
+
type: 'row' | 'column' | 'table',
|
|
52
|
+
tr: Transaction | ReadonlyTransaction,
|
|
53
|
+
isDragAndDropEnable: boolean | undefined,
|
|
54
|
+
hoveredIndexes: number[],
|
|
55
|
+
danger?: boolean,
|
|
56
|
+
selected?: boolean,
|
|
72
57
|
): Decoration[] => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
58
|
+
const table = findTable(tr.selection);
|
|
59
|
+
if (!table) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const map = TableMap.get(table.node);
|
|
64
|
+
const [min, max] = cells.reduce<[number | null, number | null]>(
|
|
65
|
+
([min, max], cell) => {
|
|
66
|
+
if (min === null || cell.pos < min) {
|
|
67
|
+
min = cell.pos;
|
|
68
|
+
}
|
|
69
|
+
if (max === null || cell.pos > max) {
|
|
70
|
+
max = cell.pos;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return [min, max];
|
|
74
|
+
},
|
|
75
|
+
[null, null],
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
if (min === null || max === null) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let updatedCells: number[] = cells.map((x) => x.pos);
|
|
83
|
+
|
|
84
|
+
// ED-15246 fixed trello card table overflow issue
|
|
85
|
+
// If columns / rows have been merged the hovered selection is different to the actual selection
|
|
86
|
+
// So If the table cells are in danger we want to create a "rectangle" selection
|
|
87
|
+
// to match the "clicked" selection
|
|
88
|
+
|
|
89
|
+
if (danger && type !== 'table') {
|
|
90
|
+
const { selection } = tr;
|
|
91
|
+
const table = findTable(selection);
|
|
92
|
+
const rect = getSelectionRect(selection);
|
|
93
|
+
|
|
94
|
+
if (table && rect) {
|
|
95
|
+
updatedCells = map.cellsInRect(rect).map((x) => x + table.start);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return updatedCells.map((pos) => {
|
|
100
|
+
const cell = tr.doc.nodeAt(pos);
|
|
101
|
+
|
|
102
|
+
const classes = [ClassName.HOVERED_CELL];
|
|
103
|
+
if (danger) {
|
|
104
|
+
classes.push(ClassName.HOVERED_CELL_IN_DANGER);
|
|
105
|
+
}
|
|
106
|
+
if (selected) {
|
|
107
|
+
classes.push(ClassName.SELECTED_CELL);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (isDragAndDropEnable) {
|
|
111
|
+
if (type === 'column' || type === 'row') {
|
|
112
|
+
classes.pop();
|
|
113
|
+
classes.push(ClassName.HOVERED_NO_HIGHLIGHT);
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
classes.push(
|
|
117
|
+
type === 'column'
|
|
118
|
+
? ClassName.HOVERED_COLUMN
|
|
119
|
+
: type === 'row'
|
|
120
|
+
? ClassName.HOVERED_ROW
|
|
121
|
+
: ClassName.HOVERED_TABLE,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let key: TableDecorations;
|
|
126
|
+
switch (type) {
|
|
127
|
+
case 'row':
|
|
128
|
+
key = TableDecorations.ROW_CONTROLS_HOVER;
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
case 'column':
|
|
132
|
+
key = TableDecorations.COLUMN_CONTROLS_HOVER;
|
|
133
|
+
break;
|
|
134
|
+
|
|
135
|
+
default:
|
|
136
|
+
key = TableDecorations.TABLE_CONTROLS_HOVER;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return Decoration.node(
|
|
141
|
+
pos,
|
|
142
|
+
pos + cell!.nodeSize,
|
|
143
|
+
{
|
|
144
|
+
class: classes.join(' '),
|
|
145
|
+
},
|
|
146
|
+
{ key },
|
|
147
|
+
);
|
|
148
|
+
});
|
|
164
149
|
};
|
|
165
150
|
|
|
166
151
|
export const createColumnSelectedDecoration = (
|
|
167
|
-
|
|
152
|
+
tr: Transaction | ReadonlyTransaction,
|
|
168
153
|
): Decoration[] => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
154
|
+
const { selection, doc } = tr;
|
|
155
|
+
const table = findTable(selection);
|
|
156
|
+
const rect = getSelectionRect(selection);
|
|
157
|
+
|
|
158
|
+
if (!table || !rect) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const map = TableMap.get(table.node);
|
|
163
|
+
const cellPositions = map.cellsInRect(rect);
|
|
164
|
+
|
|
165
|
+
return cellPositions.map((pos, index) => {
|
|
166
|
+
const cell = doc.nodeAt(pos + table.start);
|
|
167
|
+
|
|
168
|
+
return Decoration.node(
|
|
169
|
+
pos + table.start,
|
|
170
|
+
pos + table.start + cell!.nodeSize,
|
|
171
|
+
{
|
|
172
|
+
class: ClassName.COLUMN_SELECTED,
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
key: `${TableDecorations.COLUMN_SELECTED}_${index}`,
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
});
|
|
194
179
|
};
|
|
195
180
|
|
|
196
|
-
export const createColumnControlsDecoration = (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
);
|
|
227
|
-
});
|
|
181
|
+
export const createColumnControlsDecoration = (selection: Selection): Decoration[] => {
|
|
182
|
+
const cells: ContentNodeWithPos[] = getCellsInRow(0)(selection) || [];
|
|
183
|
+
|
|
184
|
+
let index = 0;
|
|
185
|
+
return cells.map((cell) => {
|
|
186
|
+
const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
|
|
187
|
+
// It's important these values are scoped locally as the widget callback could be executed anytime in the future
|
|
188
|
+
// and we want to avoid value leak
|
|
189
|
+
const startIndex = index;
|
|
190
|
+
const endIndex = startIndex + colspan;
|
|
191
|
+
|
|
192
|
+
// The next cell start index will commence from the current cell end index.
|
|
193
|
+
index = endIndex;
|
|
194
|
+
|
|
195
|
+
return Decoration.widget(
|
|
196
|
+
cell.pos + 1,
|
|
197
|
+
() => {
|
|
198
|
+
const element = document.createElement('div');
|
|
199
|
+
element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
|
|
200
|
+
element.dataset.startIndex = `${startIndex}`;
|
|
201
|
+
element.dataset.endIndex = `${endIndex}`;
|
|
202
|
+
return element;
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
|
|
206
|
+
// this decoration should be the first one, even before gap cursor.
|
|
207
|
+
side: -100,
|
|
208
|
+
},
|
|
209
|
+
);
|
|
210
|
+
});
|
|
228
211
|
};
|
|
229
212
|
|
|
230
213
|
export const updateDecorations = (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
214
|
+
node: PmNode,
|
|
215
|
+
decorationSet: DecorationSet,
|
|
216
|
+
decorations: Decoration[],
|
|
217
|
+
key: TableDecorations,
|
|
235
218
|
): DecorationSet => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
219
|
+
const filteredDecorations = filterDecorationByKey(key, decorationSet);
|
|
220
|
+
const decorationSetFiltered = decorationSet.remove(filteredDecorations);
|
|
221
|
+
return decorationSetFiltered.add(node, decorations);
|
|
239
222
|
};
|
|
240
223
|
|
|
241
224
|
const makeArray = (n: number) => Array.from(Array(n).keys());
|
|
@@ -320,144 +303,141 @@ const makeArray = (n: number) => Array.from(Array(n).keys());
|
|
|
320
303
|
* hence the second media will receive this class `ClassName.LAST_ITEM_IN_CELL`
|
|
321
304
|
*/
|
|
322
305
|
export const createResizeHandleDecoration = (
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
306
|
+
tr: Transaction | ReadonlyTransaction,
|
|
307
|
+
rowIndexTarget: number,
|
|
308
|
+
columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>,
|
|
309
|
+
includeTooltip: boolean = false,
|
|
310
|
+
getIntl: () => IntlShape,
|
|
328
311
|
): [Decoration[], Decoration[]] => {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
resizeHandleCellDecorations,
|
|
459
|
-
lastCellElementsDecorations.filter(nonNullable),
|
|
460
|
-
];
|
|
312
|
+
const emptyResult: [Decoration[], Decoration[]] = [[], []];
|
|
313
|
+
const table = findTable(tr.selection);
|
|
314
|
+
if (!table || !table.node) {
|
|
315
|
+
return emptyResult;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const map = TableMap.get(table.node);
|
|
319
|
+
if (!map.width) {
|
|
320
|
+
return emptyResult;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const createResizerHandleDecoration = (
|
|
324
|
+
cellColumnPositioning: CellColumnPositioning,
|
|
325
|
+
columnIndex: number,
|
|
326
|
+
rowIndex: number,
|
|
327
|
+
cellPos: number,
|
|
328
|
+
cellNode: PmNode,
|
|
329
|
+
): Decoration => {
|
|
330
|
+
const position = cellPos + cellNode.nodeSize - 1;
|
|
331
|
+
return Decoration.widget(
|
|
332
|
+
position,
|
|
333
|
+
() => {
|
|
334
|
+
const element = document.createElement('div');
|
|
335
|
+
ReactDOM.render(
|
|
336
|
+
createElement(
|
|
337
|
+
RawIntlProvider,
|
|
338
|
+
{ value: getIntl() },
|
|
339
|
+
createElement(ColumnResizeWidget, {
|
|
340
|
+
startIndex: cellColumnPositioning.left,
|
|
341
|
+
endIndex: cellColumnPositioning.right,
|
|
342
|
+
includeTooltip,
|
|
343
|
+
}),
|
|
344
|
+
),
|
|
345
|
+
element,
|
|
346
|
+
);
|
|
347
|
+
return element;
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
key: `${
|
|
351
|
+
TableDecorations.COLUMN_RESIZING_HANDLE_WIDGET
|
|
352
|
+
}_${rowIndex}_${columnIndex}_${includeTooltip ? 'with' : 'no'}-tooltip`,
|
|
353
|
+
destroy: (node) => {
|
|
354
|
+
ReactDOM.unmountComponentAtNode(node as HTMLDivElement);
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
);
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const createLastCellElementDecoration = (
|
|
361
|
+
cellColumnPositioning: CellColumnPositioning,
|
|
362
|
+
cellPos: number,
|
|
363
|
+
cellNode: PmNode,
|
|
364
|
+
): Decoration | null => {
|
|
365
|
+
let lastItemPositions: { from: number; to: number } | undefined;
|
|
366
|
+
cellNode.forEach((childNode, offset, index) => {
|
|
367
|
+
if (index === cellNode.childCount - 1) {
|
|
368
|
+
const from = offset + cellPos + 1;
|
|
369
|
+
lastItemPositions = {
|
|
370
|
+
from,
|
|
371
|
+
to: from + childNode.nodeSize,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
if (!lastItemPositions) {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return Decoration.node(
|
|
381
|
+
lastItemPositions.from,
|
|
382
|
+
lastItemPositions.to,
|
|
383
|
+
{
|
|
384
|
+
class: ClassName.LAST_ITEM_IN_CELL,
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
key: `${TableDecorations.LAST_CELL_ELEMENT}_${cellColumnPositioning.left}_${cellColumnPositioning.right}`,
|
|
388
|
+
},
|
|
389
|
+
);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const resizeHandleCellDecorations: Decoration[] = [];
|
|
393
|
+
const lastCellElementsDecorations: Array<Decoration | null> = [];
|
|
394
|
+
|
|
395
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
396
|
+
const seen: { [key: number]: boolean } = {};
|
|
397
|
+
|
|
398
|
+
if (rowIndex !== rowIndexTarget) {
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
403
|
+
const cellPosition = map.map[map.width * rowIndex + columnIndex];
|
|
404
|
+
if (seen[cellPosition]) {
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
seen[cellPosition] = true;
|
|
409
|
+
const cellPos = table.start + cellPosition;
|
|
410
|
+
const cell = tr.doc.nodeAt(cellPos);
|
|
411
|
+
if (!cell) {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
const colspan = (cell.attrs as CellAttributes).colspan || 1;
|
|
415
|
+
const startIndex = columnIndex;
|
|
416
|
+
const endIndex = colspan + startIndex;
|
|
417
|
+
|
|
418
|
+
if (endIndex !== columnEndIndexTarget.right) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const resizerHandleDec = createResizerHandleDecoration(
|
|
423
|
+
{ left: startIndex, right: endIndex },
|
|
424
|
+
columnIndex,
|
|
425
|
+
rowIndex,
|
|
426
|
+
cellPos,
|
|
427
|
+
cell,
|
|
428
|
+
);
|
|
429
|
+
const lastCellDec = createLastCellElementDecoration(
|
|
430
|
+
{ left: startIndex, right: endIndex },
|
|
431
|
+
cellPos,
|
|
432
|
+
cell,
|
|
433
|
+
);
|
|
434
|
+
|
|
435
|
+
resizeHandleCellDecorations.push(resizerHandleDec);
|
|
436
|
+
lastCellElementsDecorations.push(lastCellDec);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return [resizeHandleCellDecorations, lastCellElementsDecorations.filter(nonNullable)];
|
|
461
441
|
};
|
|
462
442
|
|
|
463
443
|
/*
|
|
@@ -503,176 +483,176 @@ export const createResizeHandleDecoration = (
|
|
|
503
483
|
* only on the cells: `C1` and `D1`.
|
|
504
484
|
*/
|
|
505
485
|
export const createColumnLineResize = (
|
|
506
|
-
|
|
507
|
-
|
|
486
|
+
selection: Selection,
|
|
487
|
+
cellColumnPositioning: Omit<CellColumnPositioning, 'left'>,
|
|
508
488
|
): Decoration[] => {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
489
|
+
const table = findTable(selection);
|
|
490
|
+
if (!table || cellColumnPositioning.right === null) {
|
|
491
|
+
return [];
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
let columnIndex = cellColumnPositioning.right;
|
|
495
|
+
const map = TableMap.get(table.node);
|
|
496
|
+
|
|
497
|
+
const isLastColumn = columnIndex === map.width;
|
|
498
|
+
if (isLastColumn) {
|
|
499
|
+
columnIndex -= 1;
|
|
500
|
+
}
|
|
501
|
+
const decorationClassName = isLastColumn
|
|
502
|
+
? ClassName.WITH_RESIZE_LINE_LAST_COLUMN
|
|
503
|
+
: ClassName.WITH_RESIZE_LINE;
|
|
504
|
+
|
|
505
|
+
const cellPositions = makeArray(map.height)
|
|
506
|
+
.map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
|
|
507
|
+
.filter((cellPosition, rowIndex) => {
|
|
508
|
+
if (isLastColumn) {
|
|
509
|
+
return true; // If is the last column no filter applied
|
|
510
|
+
}
|
|
511
|
+
const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
|
|
512
|
+
return cellPosition !== nextPosition; // Removed it if next position is merged
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const cells = cellPositions.map((pos) => ({
|
|
516
|
+
pos: pos + table.start,
|
|
517
|
+
node: table.node.nodeAt(pos),
|
|
518
|
+
}));
|
|
519
|
+
|
|
520
|
+
return cells
|
|
521
|
+
.map((cell, index) => {
|
|
522
|
+
if (!cell || !cell.node) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return Decoration.node(
|
|
527
|
+
cell.pos,
|
|
528
|
+
cell.pos + cell.node.nodeSize,
|
|
529
|
+
{
|
|
530
|
+
class: decorationClassName,
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
key: `${TableDecorations.COLUMN_RESIZING_HANDLE_LINE}_${cellColumnPositioning.right}_${index}`,
|
|
534
|
+
},
|
|
535
|
+
);
|
|
536
|
+
})
|
|
537
|
+
.filter(nonNullable);
|
|
558
538
|
};
|
|
559
539
|
|
|
560
540
|
export const createColumnInsertLine = (
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
541
|
+
columnIndex: number,
|
|
542
|
+
selection: Selection,
|
|
543
|
+
hasMergedCells: boolean,
|
|
564
544
|
): Decoration[] => {
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
545
|
+
const table = findTable(selection);
|
|
546
|
+
if (!table) {
|
|
547
|
+
return [];
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const map = TableMap.get(table.node);
|
|
551
|
+
|
|
552
|
+
const isFirstColumn = columnIndex === 0;
|
|
553
|
+
const isLastColumn = columnIndex === map.width;
|
|
554
|
+
if (isLastColumn) {
|
|
555
|
+
columnIndex -= 1;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
let decorationClassName: string;
|
|
559
|
+
if (hasMergedCells) {
|
|
560
|
+
decorationClassName = isFirstColumn
|
|
561
|
+
? ClassName.WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE
|
|
562
|
+
: isLastColumn
|
|
563
|
+
? ClassName.WITH_LAST_COLUMN_INSERT_LINE_INACTIVE
|
|
564
|
+
: ClassName.WITH_COLUMN_INSERT_LINE_INACTIVE;
|
|
565
|
+
} else {
|
|
566
|
+
decorationClassName = isFirstColumn
|
|
567
|
+
? ClassName.WITH_FIRST_COLUMN_INSERT_LINE
|
|
568
|
+
: isLastColumn
|
|
569
|
+
? ClassName.WITH_LAST_COLUMN_INSERT_LINE
|
|
570
|
+
: ClassName.WITH_COLUMN_INSERT_LINE;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const cellPositions = makeArray(map.height)
|
|
574
|
+
.map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
|
|
575
|
+
.filter((cellPosition, rowIndex) => {
|
|
576
|
+
if (isLastColumn) {
|
|
577
|
+
return true; // If is the last column no filter applied
|
|
578
|
+
}
|
|
579
|
+
const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
|
|
580
|
+
return cellPosition !== nextPosition; // Removed it if next position is merged
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
const cells = cellPositions.map((pos) => ({
|
|
584
|
+
pos: pos + table.start,
|
|
585
|
+
node: table.node.nodeAt(pos),
|
|
586
|
+
}));
|
|
587
|
+
|
|
588
|
+
return cells
|
|
589
|
+
.map((cell, index) => {
|
|
590
|
+
if (!cell || !cell.node) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return Decoration.node(
|
|
595
|
+
cell.pos,
|
|
596
|
+
cell.pos + cell.node.nodeSize,
|
|
597
|
+
{
|
|
598
|
+
class: decorationClassName,
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
key: `${TableDecorations.COLUMN_INSERT_LINE}_${index}`,
|
|
602
|
+
},
|
|
603
|
+
);
|
|
604
|
+
})
|
|
605
|
+
.filter(nonNullable);
|
|
626
606
|
};
|
|
627
607
|
|
|
628
608
|
export const createRowInsertLine = (
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
609
|
+
rowIndex: number,
|
|
610
|
+
selection: Selection,
|
|
611
|
+
hasMergedCells: boolean,
|
|
632
612
|
): Decoration[] => {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
613
|
+
const table = findTable(selection);
|
|
614
|
+
if (!table) {
|
|
615
|
+
return [];
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const map = TableMap.get(table.node);
|
|
619
|
+
const isLastRow = rowIndex === map.height;
|
|
620
|
+
if (isLastRow) {
|
|
621
|
+
rowIndex -= 1;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const cells = getCellsInRow(rowIndex)(selection);
|
|
625
|
+
if (!cells) {
|
|
626
|
+
return [];
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
let decorationClassName: string;
|
|
630
|
+
if (hasMergedCells) {
|
|
631
|
+
decorationClassName = isLastRow
|
|
632
|
+
? ClassName.WITH_LAST_ROW_INSERT_LINE_INACTIVE
|
|
633
|
+
: ClassName.WITH_ROW_INSERT_LINE_INACTIVE;
|
|
634
|
+
} else {
|
|
635
|
+
decorationClassName = isLastRow
|
|
636
|
+
? ClassName.WITH_LAST_ROW_INSERT_LINE
|
|
637
|
+
: ClassName.WITH_ROW_INSERT_LINE;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
return cells
|
|
641
|
+
.map((cell, index) => {
|
|
642
|
+
if (!cell || !cell.node) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
return Decoration.node(
|
|
647
|
+
cell.pos,
|
|
648
|
+
cell.pos + cell.node.nodeSize,
|
|
649
|
+
{
|
|
650
|
+
class: decorationClassName,
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
key: `${TableDecorations.ROW_INSERT_LINE}_${index}`,
|
|
654
|
+
},
|
|
655
|
+
);
|
|
656
|
+
})
|
|
657
|
+
.filter(nonNullable);
|
|
678
658
|
};
|