@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/commands/misc.ts
CHANGED
|
@@ -3,850 +3,757 @@ import isEqual from 'lodash/isEqual';
|
|
|
3
3
|
import type { CellAttributes, TableLayout } from '@atlaskit/adf-schema';
|
|
4
4
|
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
closestElement,
|
|
7
|
+
isParagraph,
|
|
8
|
+
isTextSelection,
|
|
9
|
+
mapSlice,
|
|
10
10
|
} from '@atlaskit/editor-common/utils';
|
|
11
|
-
import type {
|
|
12
|
-
Node as PMNode,
|
|
13
|
-
Schema,
|
|
14
|
-
Slice,
|
|
15
|
-
} from '@atlaskit/editor-prosemirror/model';
|
|
11
|
+
import type { Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
16
12
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
17
|
-
import type {
|
|
18
|
-
|
|
19
|
-
Selection,
|
|
20
|
-
Transaction,
|
|
21
|
-
} from '@atlaskit/editor-prosemirror/state';
|
|
22
|
-
import type {
|
|
23
|
-
ContentNodeWithPos,
|
|
24
|
-
NodeWithPos,
|
|
25
|
-
} from '@atlaskit/editor-prosemirror/utils';
|
|
13
|
+
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
14
|
+
import type { ContentNodeWithPos, NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
26
15
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
27
16
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
28
17
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
29
18
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
findCellClosestToPos,
|
|
20
|
+
findTable,
|
|
21
|
+
getCellsInColumn,
|
|
22
|
+
getCellsInRow,
|
|
23
|
+
getSelectionRect,
|
|
24
|
+
isSelectionType,
|
|
25
|
+
isTableSelected,
|
|
26
|
+
removeTable,
|
|
27
|
+
selectColumns as selectColumnsTransform,
|
|
28
|
+
selectColumn as selectColumnTransform,
|
|
29
|
+
selectionCell,
|
|
30
|
+
selectRows as selectRowsTransform,
|
|
31
|
+
selectRow as selectRowTransform,
|
|
32
|
+
setCellAttrs,
|
|
44
33
|
} from '@atlaskit/editor-tables/utils';
|
|
45
34
|
|
|
46
35
|
import { getDecorations } from '../pm-plugins/decorations/plugin';
|
|
47
36
|
import {
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
buildColumnResizingDecorations,
|
|
38
|
+
clearColumnResizingDecorations,
|
|
50
39
|
} from '../pm-plugins/decorations/utils';
|
|
51
40
|
import { createCommand, getPluginState } from '../pm-plugins/plugin-factory';
|
|
52
41
|
import { fixAutoSizedTable } from '../transforms';
|
|
53
42
|
import type { WidthToWidest } from '../types';
|
|
54
43
|
import { TableCssClassName as ClassName, TableDecorations } from '../types';
|
|
55
44
|
import {
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
createColumnControlsDecoration,
|
|
46
|
+
createColumnSelectedDecoration,
|
|
58
47
|
} from '../utils/decoration';
|
|
59
48
|
import {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
checkIfHeaderColumnEnabled,
|
|
50
|
+
checkIfHeaderRowEnabled,
|
|
51
|
+
checkIfNumberColumnEnabled,
|
|
52
|
+
isIsolating,
|
|
64
53
|
} from '../utils/nodes';
|
|
65
54
|
import { updatePluginStateDecorations } from '../utils/update-plugin-state-decorations';
|
|
66
55
|
|
|
67
56
|
export const setEditorFocus = (editorHasFocus: boolean) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
createCommand({
|
|
58
|
+
type: 'SET_EDITOR_FOCUS',
|
|
59
|
+
data: {
|
|
60
|
+
editorHasFocus,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
74
63
|
|
|
75
64
|
export const setTableRef = (ref?: HTMLTableElement) =>
|
|
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
|
-
);
|
|
65
|
+
createCommand(
|
|
66
|
+
(state) => {
|
|
67
|
+
const tableRef = ref;
|
|
68
|
+
const foundTable = findTable(state.selection);
|
|
69
|
+
const tableNode = ref && foundTable ? foundTable.node : undefined;
|
|
70
|
+
const tablePos = ref && foundTable ? foundTable.pos : undefined;
|
|
71
|
+
const tableWrapperTarget =
|
|
72
|
+
closestElement(tableRef, `.${ClassName.TABLE_NODE_WRAPPER}`) || undefined;
|
|
73
|
+
const { isDragAndDropEnabled } = getPluginState(state);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
type: 'SET_TABLE_REF',
|
|
77
|
+
data: {
|
|
78
|
+
tableRef,
|
|
79
|
+
tableNode,
|
|
80
|
+
tablePos,
|
|
81
|
+
tableWrapperTarget,
|
|
82
|
+
isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
|
|
83
|
+
isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
|
|
84
|
+
isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
|
|
85
|
+
// decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
|
|
86
|
+
decorationSet: !isDragAndDropEnabled
|
|
87
|
+
? updatePluginStateDecorations(
|
|
88
|
+
state,
|
|
89
|
+
createColumnControlsDecoration(state.selection),
|
|
90
|
+
TableDecorations.COLUMN_CONTROLS_DECORATIONS,
|
|
91
|
+
)
|
|
92
|
+
: undefined,
|
|
93
|
+
resizeHandleRowIndex: undefined,
|
|
94
|
+
resizeHandleColumnIndex: undefined,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
(tr) => tr.setMeta('addToHistory', false),
|
|
99
|
+
);
|
|
112
100
|
|
|
113
101
|
export const setCellAttr =
|
|
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
|
-
|
|
102
|
+
(name: string, value: any): Command =>
|
|
103
|
+
(state, dispatch) => {
|
|
104
|
+
const { tr, selection } = state;
|
|
105
|
+
if (selection instanceof CellSelection) {
|
|
106
|
+
let updated = false;
|
|
107
|
+
selection.forEachCell((cell, pos) => {
|
|
108
|
+
if (cell.attrs[name] !== value) {
|
|
109
|
+
tr.setNodeMarkup(pos, cell.type, { ...cell.attrs, [name]: value });
|
|
110
|
+
updated = true;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
if (updated) {
|
|
114
|
+
if (dispatch) {
|
|
115
|
+
dispatch(tr);
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
const cell = selectionCell(state.selection);
|
|
121
|
+
if (cell) {
|
|
122
|
+
if (dispatch) {
|
|
123
|
+
dispatch(
|
|
124
|
+
tr.setNodeMarkup(cell.pos, cell.nodeAfter?.type, {
|
|
125
|
+
...cell.nodeAfter?.attrs,
|
|
126
|
+
[name]: value,
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
};
|
|
147
135
|
|
|
148
136
|
export const triggerUnlessTableHeader =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
export const transformSliceRemoveCellBackgroundColor = (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
cellAttrs,
|
|
186
|
-
maybeCell.content,
|
|
187
|
-
maybeCell.marks,
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
return maybeCell;
|
|
191
|
-
});
|
|
137
|
+
(command: Command): Command =>
|
|
138
|
+
(state, dispatch, view) => {
|
|
139
|
+
const {
|
|
140
|
+
selection,
|
|
141
|
+
schema: {
|
|
142
|
+
nodes: { tableHeader },
|
|
143
|
+
},
|
|
144
|
+
} = state;
|
|
145
|
+
|
|
146
|
+
if (selection instanceof TextSelection) {
|
|
147
|
+
const cell = findCellClosestToPos(selection.$from);
|
|
148
|
+
if (cell && cell.node.type !== tableHeader) {
|
|
149
|
+
return command(state, dispatch, view);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (selection instanceof CellSelection) {
|
|
154
|
+
const rect = getSelectionRect(selection);
|
|
155
|
+
if (!checkIfHeaderRowEnabled(selection) || (rect && rect.top > 0)) {
|
|
156
|
+
return command(state, dispatch, view);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return false;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const transformSliceRemoveCellBackgroundColor = (slice: Slice, schema: Schema): Slice => {
|
|
164
|
+
const { tableCell, tableHeader } = schema.nodes;
|
|
165
|
+
return mapSlice(slice, (maybeCell) => {
|
|
166
|
+
if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
|
|
167
|
+
const cellAttrs: CellAttributes = { ...maybeCell.attrs };
|
|
168
|
+
cellAttrs.background = undefined;
|
|
169
|
+
return maybeCell.type.createChecked(cellAttrs, maybeCell.content, maybeCell.marks);
|
|
170
|
+
}
|
|
171
|
+
return maybeCell;
|
|
172
|
+
});
|
|
192
173
|
};
|
|
193
174
|
|
|
194
|
-
export const transformSliceToAddTableHeaders = (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
),
|
|
212
|
-
);
|
|
213
|
-
});
|
|
214
|
-
const headerRow = tableRow.createChecked(
|
|
215
|
-
firstRow.attrs,
|
|
216
|
-
headerCols,
|
|
217
|
-
firstRow.marks,
|
|
218
|
-
);
|
|
219
|
-
return maybeTable.copy(maybeTable.content.replaceChild(0, headerRow));
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return maybeTable;
|
|
223
|
-
});
|
|
175
|
+
export const transformSliceToAddTableHeaders = (slice: Slice, schema: Schema): Slice => {
|
|
176
|
+
const { table, tableHeader, tableRow } = schema.nodes;
|
|
177
|
+
|
|
178
|
+
return mapSlice(slice, (maybeTable) => {
|
|
179
|
+
if (maybeTable.type === table) {
|
|
180
|
+
const firstRow = maybeTable.firstChild;
|
|
181
|
+
if (firstRow) {
|
|
182
|
+
const headerCols = [] as PMNode[];
|
|
183
|
+
firstRow.forEach((oldCol) => {
|
|
184
|
+
headerCols.push(tableHeader.createChecked(oldCol.attrs, oldCol.content, oldCol.marks));
|
|
185
|
+
});
|
|
186
|
+
const headerRow = tableRow.createChecked(firstRow.attrs, headerCols, firstRow.marks);
|
|
187
|
+
return maybeTable.copy(maybeTable.content.replaceChild(0, headerRow));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return maybeTable;
|
|
191
|
+
});
|
|
224
192
|
};
|
|
225
193
|
|
|
226
|
-
export const transformSliceToRemoveColumnsWidths = (
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
return maybeCell;
|
|
244
|
-
});
|
|
194
|
+
export const transformSliceToRemoveColumnsWidths = (slice: Slice, schema: Schema): Slice => {
|
|
195
|
+
const { tableHeader, tableCell } = schema.nodes;
|
|
196
|
+
|
|
197
|
+
return mapSlice(slice, (maybeCell) => {
|
|
198
|
+
if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
|
|
199
|
+
if (!maybeCell.attrs.colwidth) {
|
|
200
|
+
return maybeCell;
|
|
201
|
+
}
|
|
202
|
+
return maybeCell.type.createChecked(
|
|
203
|
+
{ ...maybeCell.attrs, colwidth: undefined },
|
|
204
|
+
maybeCell.content,
|
|
205
|
+
maybeCell.marks,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return maybeCell;
|
|
209
|
+
});
|
|
245
210
|
};
|
|
246
211
|
|
|
247
|
-
export const countCellsInSlice = (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
type?: 'row' | 'column',
|
|
251
|
-
) => {
|
|
252
|
-
const { tableHeader, tableCell } = schema.nodes;
|
|
253
|
-
let count = 0;
|
|
212
|
+
export const countCellsInSlice = (slice: Slice, schema: Schema, type?: 'row' | 'column') => {
|
|
213
|
+
const { tableHeader, tableCell } = schema.nodes;
|
|
214
|
+
let count = 0;
|
|
254
215
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
216
|
+
if (!type) {
|
|
217
|
+
return count;
|
|
218
|
+
}
|
|
258
219
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
type === 'row' ? maybeCell.attrs.colspan : maybeCell.attrs.rowspan;
|
|
220
|
+
slice.content.descendants((maybeCell) => {
|
|
221
|
+
if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
|
|
222
|
+
count += type === 'row' ? maybeCell.attrs.colspan : maybeCell.attrs.rowspan;
|
|
263
223
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
267
227
|
|
|
268
|
-
|
|
228
|
+
return count;
|
|
269
229
|
};
|
|
270
230
|
|
|
271
231
|
export const getTableSelectionType = (selection: Selection) => {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
: selection.isColSelection()
|
|
276
|
-
? 'column'
|
|
277
|
-
: undefined;
|
|
278
|
-
}
|
|
232
|
+
if (selection instanceof CellSelection) {
|
|
233
|
+
return selection.isRowSelection() ? 'row' : selection.isColSelection() ? 'column' : undefined;
|
|
234
|
+
}
|
|
279
235
|
};
|
|
280
236
|
|
|
281
|
-
export const getTableElementMoveTypeBySlice = (
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
? 'row'
|
|
318
|
-
: map.height === slicedMap.height
|
|
319
|
-
? 'column'
|
|
320
|
-
: undefined;
|
|
321
|
-
} catch (e) {
|
|
322
|
-
return undefined;
|
|
323
|
-
}
|
|
237
|
+
export const getTableElementMoveTypeBySlice = (slice: Slice, state: EditorState) => {
|
|
238
|
+
const {
|
|
239
|
+
schema: {
|
|
240
|
+
nodes: { tableRow, table },
|
|
241
|
+
},
|
|
242
|
+
} = state;
|
|
243
|
+
const currentTable = findTable(state.tr.selection);
|
|
244
|
+
|
|
245
|
+
// check if copied slice is a table or table row
|
|
246
|
+
if (
|
|
247
|
+
!slice.content.firstChild ||
|
|
248
|
+
(slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) ||
|
|
249
|
+
!currentTable
|
|
250
|
+
) {
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// if the slice only contains one table row, assume it's a row
|
|
255
|
+
if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
|
|
256
|
+
return 'row';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// `TableMap.get` can throw if the content is invalid - in which case we should just
|
|
260
|
+
// return undefined
|
|
261
|
+
try {
|
|
262
|
+
const map = TableMap.get(currentTable.node);
|
|
263
|
+
const slicedMap = TableMap.get(slice.content.firstChild);
|
|
264
|
+
|
|
265
|
+
return map.width === slicedMap.width
|
|
266
|
+
? 'row'
|
|
267
|
+
: map.height === slicedMap.height
|
|
268
|
+
? 'column'
|
|
269
|
+
: undefined;
|
|
270
|
+
} catch (e) {
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
324
273
|
};
|
|
325
274
|
|
|
326
|
-
export const isInsideFirstCellOfRowOrColumn = (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
)
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const index = map.map.findIndex((value) => value === pos);
|
|
344
|
-
|
|
345
|
-
return type === 'row' ? index % map.width === 0 : index < map.width;
|
|
275
|
+
export const isInsideFirstCellOfRowOrColumn = (selection: Selection, type?: 'row' | 'column') => {
|
|
276
|
+
const table = findTable(selection);
|
|
277
|
+
|
|
278
|
+
if (!table || !type) {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const map = TableMap.get(table.node!);
|
|
283
|
+
const cell = findCellClosestToPos(selection.$anchor);
|
|
284
|
+
if (!cell) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
const pos = cell.pos - table.pos - 1;
|
|
288
|
+
// cell positions in table map always start at 1, as they're offsets not positions
|
|
289
|
+
const index = map.map.findIndex((value) => value === pos);
|
|
290
|
+
|
|
291
|
+
return type === 'row' ? index % map.width === 0 : index < map.width;
|
|
346
292
|
};
|
|
347
293
|
|
|
348
294
|
export const deleteTable: Command = (state, dispatch) => {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
295
|
+
if (dispatch) {
|
|
296
|
+
dispatch(removeTable(state.tr));
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
353
299
|
};
|
|
354
300
|
|
|
355
301
|
export const deleteTableIfSelected: Command = (state, dispatch) => {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
302
|
+
if (isTableSelected(state.selection)) {
|
|
303
|
+
return deleteTable(state, dispatch);
|
|
304
|
+
}
|
|
305
|
+
return false;
|
|
360
306
|
};
|
|
361
307
|
|
|
362
308
|
export const convertFirstRowToHeader =
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
);
|
|
374
|
-
}
|
|
375
|
-
return tr;
|
|
376
|
-
};
|
|
309
|
+
(schema: Schema) =>
|
|
310
|
+
(tr: Transaction): Transaction => {
|
|
311
|
+
const table = findTable(tr.selection)!;
|
|
312
|
+
const map = TableMap.get(table.node);
|
|
313
|
+
for (let i = 0; i < map.width; i++) {
|
|
314
|
+
const cell = table.node.child(0).child(i);
|
|
315
|
+
tr.setNodeMarkup(table.start + map.map[i], schema.nodes.tableHeader, cell.attrs);
|
|
316
|
+
}
|
|
317
|
+
return tr;
|
|
318
|
+
};
|
|
377
319
|
|
|
378
320
|
export const moveCursorBackward: Command = (state, dispatch) => {
|
|
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
|
-
|
|
321
|
+
const { $cursor } = state.selection as TextSelection;
|
|
322
|
+
// if cursor is in the middle of a text node, do nothing
|
|
323
|
+
if (!$cursor || $cursor.parentOffset > 0) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// find the node before the cursor
|
|
328
|
+
let before;
|
|
329
|
+
let cut: number | undefined;
|
|
330
|
+
if (!isIsolating($cursor.parent)) {
|
|
331
|
+
for (let i = $cursor.depth - 1; !before && i >= 0; i--) {
|
|
332
|
+
if ($cursor.index(i) > 0) {
|
|
333
|
+
cut = $cursor.before(i + 1);
|
|
334
|
+
before = $cursor.node(i).child($cursor.index(i) - 1);
|
|
335
|
+
}
|
|
336
|
+
if (isIsolating($cursor.node(i))) {
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// if the node before is not a table node - do nothing
|
|
343
|
+
if (!before || before.type !== state.schema.nodes.table) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/*
|
|
406
348
|
ensure we're just at a top level paragraph
|
|
407
349
|
otherwise, perform regular backspace behaviour
|
|
408
350
|
*/
|
|
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
|
-
|
|
351
|
+
const grandparent = $cursor.node($cursor.depth - 1);
|
|
352
|
+
if (
|
|
353
|
+
$cursor.parent.type !== state.schema.nodes.paragraph ||
|
|
354
|
+
(grandparent && grandparent.type !== state.schema.nodes.doc)
|
|
355
|
+
) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const { tr } = state;
|
|
360
|
+
const lastCellPos = (cut || 0) - 4;
|
|
361
|
+
// need to move cursor inside the table to be able to calculate table's offset
|
|
362
|
+
tr.setSelection(new TextSelection(state.doc.resolve(lastCellPos)));
|
|
363
|
+
const { $from } = tr.selection;
|
|
364
|
+
const start = $from.start(-1);
|
|
365
|
+
const pos = start + $from.parent.nodeSize - 1;
|
|
366
|
+
|
|
367
|
+
// move cursor to the last cell
|
|
368
|
+
// it doesn't join node before (last cell) with node after (content after the cursor)
|
|
369
|
+
// due to ridiculous amount of PM code that would have been required to overwrite
|
|
370
|
+
tr.setSelection(new TextSelection(state.doc.resolve(pos)));
|
|
371
|
+
|
|
372
|
+
// if we are inside an empty paragraph not at the end of the doc we delete it
|
|
373
|
+
const cursorNode = $cursor.node();
|
|
374
|
+
const docEnd = state.doc.content.size;
|
|
375
|
+
const paragraphWrapStart = $cursor.pos - 1;
|
|
376
|
+
const paragraphWrapEnd = $cursor.pos + 1;
|
|
377
|
+
if (cursorNode.content.size === 0 && $cursor.pos + 1 !== docEnd) {
|
|
378
|
+
tr.delete(paragraphWrapStart, paragraphWrapEnd);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (dispatch) {
|
|
382
|
+
dispatch(tr);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return true;
|
|
444
386
|
};
|
|
445
387
|
|
|
446
388
|
export const setMultipleCellAttrs =
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
)
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
return {
|
|
507
|
-
type: 'SELECT_COLUMN',
|
|
508
|
-
data: { targetCellPosition, decorationSet },
|
|
509
|
-
};
|
|
510
|
-
},
|
|
511
|
-
(tr: Transaction) =>
|
|
512
|
-
selectColumnTransform(column, expand)(tr)
|
|
513
|
-
.setMeta('addToHistory', false)
|
|
514
|
-
.setMeta('selectedColumnViaKeyboard', triggeredByKeyboard),
|
|
515
|
-
);
|
|
389
|
+
(attrs: Object, targetCellPosition?: number, editorView?: EditorView | null): Command =>
|
|
390
|
+
(state, dispatch) => {
|
|
391
|
+
let cursorPos: number | undefined;
|
|
392
|
+
let { tr } = state;
|
|
393
|
+
|
|
394
|
+
if (isSelectionType(tr.selection, 'cell')) {
|
|
395
|
+
const selection = tr.selection as any as CellSelection;
|
|
396
|
+
selection.forEachCell((_cell, pos) => {
|
|
397
|
+
const $pos = tr.doc.resolve(tr.mapping.map(pos + 1));
|
|
398
|
+
tr = setCellAttrs(findCellClosestToPos($pos)!, attrs)(tr);
|
|
399
|
+
});
|
|
400
|
+
cursorPos = selection.$headCell.pos;
|
|
401
|
+
} else if (targetCellPosition) {
|
|
402
|
+
const cell = findCellClosestToPos(tr.doc.resolve(targetCellPosition + 1))!;
|
|
403
|
+
tr = setCellAttrs(cell, attrs)(tr);
|
|
404
|
+
cursorPos = cell.pos;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (tr.docChanged && cursorPos !== undefined) {
|
|
408
|
+
if (dispatch) {
|
|
409
|
+
if (cursorPos !== undefined) {
|
|
410
|
+
editorView?.focus();
|
|
411
|
+
tr.setSelection(new TextSelection(tr.doc.resolve(cursorPos)));
|
|
412
|
+
}
|
|
413
|
+
dispatch(tr);
|
|
414
|
+
}
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
return false;
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
export const selectColumn = (column: number, expand?: boolean, triggeredByKeyboard = false) =>
|
|
421
|
+
createCommand(
|
|
422
|
+
(state) => {
|
|
423
|
+
const cells = getCellsInColumn(column)(state.tr.selection);
|
|
424
|
+
if (!cells || !cells.length || typeof cells[0].pos !== 'number') {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const decorations = createColumnSelectedDecoration(
|
|
429
|
+
selectColumnTransform(column, expand)(state.tr),
|
|
430
|
+
);
|
|
431
|
+
const decorationSet = updatePluginStateDecorations(
|
|
432
|
+
state,
|
|
433
|
+
decorations,
|
|
434
|
+
TableDecorations.COLUMN_SELECTED,
|
|
435
|
+
);
|
|
436
|
+
const targetCellPosition = cells[0].pos;
|
|
437
|
+
|
|
438
|
+
return {
|
|
439
|
+
type: 'SELECT_COLUMN',
|
|
440
|
+
data: { targetCellPosition, decorationSet },
|
|
441
|
+
};
|
|
442
|
+
},
|
|
443
|
+
(tr: Transaction) =>
|
|
444
|
+
selectColumnTransform(column, expand)(tr)
|
|
445
|
+
.setMeta('addToHistory', false)
|
|
446
|
+
.setMeta('selectedColumnViaKeyboard', triggeredByKeyboard),
|
|
447
|
+
);
|
|
516
448
|
|
|
517
449
|
export const selectColumns = (columnIndexes: number[]) =>
|
|
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
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
)
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
let targetCellPosition;
|
|
572
|
-
const cells = getCellsInRow(row)(state.tr.selection);
|
|
573
|
-
if (cells && cells.length) {
|
|
574
|
-
targetCellPosition = cells[0].pos;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
return { type: 'SET_TARGET_CELL_POSITION', data: { targetCellPosition } };
|
|
578
|
-
},
|
|
579
|
-
(tr) =>
|
|
580
|
-
selectRowTransform(row, expand)(tr)
|
|
581
|
-
.setMeta('addToHistory', false)
|
|
582
|
-
.setMeta('selectedRowViaKeyboard', triggeredByKeyboard),
|
|
583
|
-
);
|
|
450
|
+
createCommand(
|
|
451
|
+
(state) => {
|
|
452
|
+
if (!columnIndexes) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
const cells = columnIndexes
|
|
456
|
+
.map((column) => getCellsInColumn(column)(state.tr.selection))
|
|
457
|
+
.flat();
|
|
458
|
+
if (!cells || !cells.length || cells.some((cell) => cell && typeof cell.pos !== 'number')) {
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
const decorations = createColumnSelectedDecoration(
|
|
462
|
+
selectColumnsTransform(columnIndexes)(state.tr),
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
const decorationSet = updatePluginStateDecorations(
|
|
466
|
+
state,
|
|
467
|
+
decorations,
|
|
468
|
+
TableDecorations.COLUMN_SELECTED,
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
const cellsInFirstColumn = getCellsInColumn(Math.min(...columnIndexes))(state.tr.selection);
|
|
472
|
+
if (!cellsInFirstColumn || cellsInFirstColumn.length === 0) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
const targetCellPosition = cellsInFirstColumn[0].pos;
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
type: 'SELECT_COLUMN',
|
|
479
|
+
data: { targetCellPosition, decorationSet },
|
|
480
|
+
};
|
|
481
|
+
},
|
|
482
|
+
(tr: Transaction) => {
|
|
483
|
+
return selectColumnsTransform(columnIndexes)(tr).setMeta('addToHistory', false);
|
|
484
|
+
},
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
export const selectRow = (row: number, expand?: boolean, triggeredByKeyboard = false) =>
|
|
488
|
+
createCommand(
|
|
489
|
+
(state) => {
|
|
490
|
+
let targetCellPosition;
|
|
491
|
+
const cells = getCellsInRow(row)(state.tr.selection);
|
|
492
|
+
if (cells && cells.length) {
|
|
493
|
+
targetCellPosition = cells[0].pos;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return { type: 'SET_TARGET_CELL_POSITION', data: { targetCellPosition } };
|
|
497
|
+
},
|
|
498
|
+
(tr) =>
|
|
499
|
+
selectRowTransform(row, expand)(tr)
|
|
500
|
+
.setMeta('addToHistory', false)
|
|
501
|
+
.setMeta('selectedRowViaKeyboard', triggeredByKeyboard),
|
|
502
|
+
);
|
|
584
503
|
|
|
585
504
|
export const selectRows = (rowIndexes: number[]) =>
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
return false;
|
|
606
|
-
}
|
|
607
|
-
const targetCellPosition = cellsInFirstRow[0].pos;
|
|
608
|
-
|
|
609
|
-
return { type: 'SET_TARGET_CELL_POSITION', data: { targetCellPosition } };
|
|
610
|
-
},
|
|
611
|
-
(tr) => selectRowsTransform(rowIndexes)(tr).setMeta('addToHistory', false),
|
|
612
|
-
);
|
|
505
|
+
createCommand(
|
|
506
|
+
(state) => {
|
|
507
|
+
if (rowIndexes.length === 0) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
const cells = rowIndexes.map((row) => getCellsInRow(row)(state.tr.selection)).flat();
|
|
511
|
+
if (!cells || !cells.length || cells.some((cell) => cell && typeof cell.pos !== 'number')) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
const cellsInFirstRow = getCellsInRow(Math.min(...rowIndexes))(state.tr.selection);
|
|
515
|
+
if (!cellsInFirstRow || cellsInFirstRow.length === 0) {
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
const targetCellPosition = cellsInFirstRow[0].pos;
|
|
519
|
+
|
|
520
|
+
return { type: 'SET_TARGET_CELL_POSITION', data: { targetCellPosition } };
|
|
521
|
+
},
|
|
522
|
+
(tr) => selectRowsTransform(rowIndexes)(tr).setMeta('addToHistory', false),
|
|
523
|
+
);
|
|
613
524
|
|
|
614
525
|
export const showInsertColumnButton = (columnIndex: number) =>
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
526
|
+
createCommand(
|
|
527
|
+
(_) =>
|
|
528
|
+
columnIndex > -1
|
|
529
|
+
? {
|
|
530
|
+
type: 'SHOW_INSERT_COLUMN_BUTTON',
|
|
531
|
+
data: { insertColumnButtonIndex: columnIndex },
|
|
532
|
+
}
|
|
533
|
+
: false,
|
|
534
|
+
(tr) => tr.setMeta('addToHistory', false),
|
|
535
|
+
);
|
|
625
536
|
|
|
626
537
|
export const showInsertRowButton = (rowIndex: number) =>
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
538
|
+
createCommand(
|
|
539
|
+
(_) =>
|
|
540
|
+
rowIndex > -1
|
|
541
|
+
? {
|
|
542
|
+
type: 'SHOW_INSERT_ROW_BUTTON',
|
|
543
|
+
data: { insertRowButtonIndex: rowIndex },
|
|
544
|
+
}
|
|
545
|
+
: false,
|
|
546
|
+
(tr) => tr.setMeta('addToHistory', false),
|
|
547
|
+
);
|
|
637
548
|
|
|
638
549
|
export const hideInsertColumnOrRowButton = () =>
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
550
|
+
createCommand(
|
|
551
|
+
{
|
|
552
|
+
type: 'HIDE_INSERT_COLUMN_OR_ROW_BUTTON',
|
|
553
|
+
},
|
|
554
|
+
(tr) => tr.setMeta('addToHistory', false),
|
|
555
|
+
);
|
|
645
556
|
|
|
646
557
|
export const addResizeHandleDecorations = (
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
558
|
+
rowIndex: number,
|
|
559
|
+
columnIndex: number,
|
|
560
|
+
includeTooltip: boolean,
|
|
561
|
+
isKeyboardResize?: boolean,
|
|
651
562
|
) =>
|
|
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
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
563
|
+
createCommand(
|
|
564
|
+
(state) => {
|
|
565
|
+
const tableNode = findTable(state.selection);
|
|
566
|
+
const {
|
|
567
|
+
pluginConfig: { allowColumnResizing },
|
|
568
|
+
getIntl,
|
|
569
|
+
} = getPluginState(state);
|
|
570
|
+
|
|
571
|
+
if (!tableNode || !allowColumnResizing) {
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return {
|
|
576
|
+
type: 'ADD_RESIZE_HANDLE_DECORATIONS',
|
|
577
|
+
data: {
|
|
578
|
+
decorationSet: buildColumnResizingDecorations(
|
|
579
|
+
rowIndex,
|
|
580
|
+
columnIndex,
|
|
581
|
+
includeTooltip,
|
|
582
|
+
getIntl,
|
|
583
|
+
)({
|
|
584
|
+
tr: state.tr,
|
|
585
|
+
decorationSet: getDecorations(state),
|
|
586
|
+
}),
|
|
587
|
+
resizeHandleRowIndex: rowIndex,
|
|
588
|
+
resizeHandleColumnIndex: columnIndex,
|
|
589
|
+
resizeHandleIncludeTooltip: includeTooltip,
|
|
590
|
+
isKeyboardResize: isKeyboardResize || false,
|
|
591
|
+
},
|
|
592
|
+
};
|
|
593
|
+
},
|
|
594
|
+
(tr: Transaction) => tr.setMeta('addToHistory', false),
|
|
595
|
+
);
|
|
685
596
|
|
|
686
597
|
export const updateResizeHandleDecorations = (
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
598
|
+
rowIndex?: number,
|
|
599
|
+
columnIndex?: number,
|
|
600
|
+
includeTooltip?: boolean,
|
|
690
601
|
) =>
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
);
|
|
602
|
+
createCommand(
|
|
603
|
+
(state) => {
|
|
604
|
+
const tableNode = findTable(state.selection);
|
|
605
|
+
const {
|
|
606
|
+
resizeHandleRowIndex,
|
|
607
|
+
resizeHandleColumnIndex,
|
|
608
|
+
resizeHandleIncludeTooltip,
|
|
609
|
+
pluginConfig: { allowColumnResizing },
|
|
610
|
+
getIntl,
|
|
611
|
+
} = getPluginState(state);
|
|
612
|
+
|
|
613
|
+
if (!tableNode || !allowColumnResizing) {
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const resolvedRowIndex = rowIndex ?? resizeHandleRowIndex;
|
|
618
|
+
const resolvedColumnIndex = columnIndex ?? resizeHandleColumnIndex;
|
|
619
|
+
const resolvedIncludeTooltip = includeTooltip ?? resizeHandleIncludeTooltip;
|
|
620
|
+
|
|
621
|
+
if (
|
|
622
|
+
resolvedRowIndex === undefined ||
|
|
623
|
+
resolvedColumnIndex === undefined ||
|
|
624
|
+
resolvedIncludeTooltip === undefined
|
|
625
|
+
) {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
return {
|
|
630
|
+
type: 'UPDATE_RESIZE_HANDLE_DECORATIONS',
|
|
631
|
+
data: {
|
|
632
|
+
decorationSet: buildColumnResizingDecorations(
|
|
633
|
+
resolvedRowIndex,
|
|
634
|
+
resolvedColumnIndex,
|
|
635
|
+
resolvedIncludeTooltip,
|
|
636
|
+
getIntl,
|
|
637
|
+
)({
|
|
638
|
+
tr: state.tr,
|
|
639
|
+
decorationSet: getDecorations(state),
|
|
640
|
+
}),
|
|
641
|
+
resizeHandleRowIndex: rowIndex,
|
|
642
|
+
resizeHandleColumnIndex: columnIndex,
|
|
643
|
+
resizeHandleIncludeTooltip: includeTooltip,
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
},
|
|
647
|
+
(tr: Transaction) => tr.setMeta('addToHistory', false),
|
|
648
|
+
);
|
|
739
649
|
|
|
740
650
|
export const removeResizeHandleDecorations = () =>
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
651
|
+
createCommand(
|
|
652
|
+
(state) => ({
|
|
653
|
+
type: 'REMOVE_RESIZE_HANDLE_DECORATIONS',
|
|
654
|
+
data: {
|
|
655
|
+
decorationSet: clearColumnResizingDecorations()({
|
|
656
|
+
tr: state.tr,
|
|
657
|
+
decorationSet: getDecorations(state),
|
|
658
|
+
}),
|
|
659
|
+
},
|
|
660
|
+
}),
|
|
661
|
+
(tr) => tr.setMeta('addToHistory', false),
|
|
662
|
+
);
|
|
753
663
|
|
|
754
664
|
export const autoSizeTable = (
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
665
|
+
view: EditorView,
|
|
666
|
+
node: PMNode,
|
|
667
|
+
table: HTMLTableElement,
|
|
668
|
+
basePos: number | undefined,
|
|
669
|
+
opts: { containerWidth: number },
|
|
760
670
|
) => {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
671
|
+
if (typeof basePos !== 'number') {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
764
674
|
|
|
765
|
-
|
|
766
|
-
|
|
675
|
+
view.dispatch(fixAutoSizedTable(view, node, table, basePos, opts));
|
|
676
|
+
return true;
|
|
767
677
|
};
|
|
768
678
|
|
|
769
679
|
export const addBoldInEmptyHeaderCells =
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
680
|
+
(tableCellHeader: ContentNodeWithPos): Command =>
|
|
681
|
+
(state, dispatch): boolean => {
|
|
682
|
+
const { tr } = state;
|
|
683
|
+
if (
|
|
684
|
+
// Avoid infinite loop when the current selection is not a TextSelection
|
|
685
|
+
isTextSelection(tr.selection) &&
|
|
686
|
+
tr.selection.$cursor &&
|
|
687
|
+
// When storedMark is null that means this is the initial state
|
|
688
|
+
// if the user press to remove the mark storedMark will be an empty array
|
|
689
|
+
// and we shouldn't apply the strong mark
|
|
690
|
+
tr.storedMarks == null &&
|
|
691
|
+
// Check if the current node is a direct child from paragraph
|
|
692
|
+
tr.selection.$from.depth === tableCellHeader.depth + 1 &&
|
|
693
|
+
// this logic is applied only for empty paragraph
|
|
694
|
+
tableCellHeader.node.nodeSize === 4 &&
|
|
695
|
+
isParagraph(tableCellHeader.node.firstChild, state.schema)
|
|
696
|
+
) {
|
|
697
|
+
const { strong } = state.schema.marks;
|
|
698
|
+
tr.setStoredMarks([strong.create()]).setMeta('addToHistory', false);
|
|
699
|
+
|
|
700
|
+
if (dispatch) {
|
|
701
|
+
dispatch(tr);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
return false;
|
|
708
|
+
};
|
|
799
709
|
|
|
800
710
|
export const updateWidthToWidest = (widthToWidest: WidthToWidest) =>
|
|
801
|
-
|
|
802
|
-
|
|
711
|
+
createCommand((state) => {
|
|
712
|
+
let { widthToWidest: prevWidthToWidest } = getPluginState(state);
|
|
803
713
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
714
|
+
if (isEqual(widthToWidest, prevWidthToWidest)) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
807
717
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
718
|
+
return {
|
|
719
|
+
type: 'UPDATE_TABLE_WIDTH_TO_WIDEST',
|
|
720
|
+
data: {
|
|
721
|
+
widthToWidest: { ...prevWidthToWidest, ...widthToWidest },
|
|
722
|
+
},
|
|
723
|
+
};
|
|
724
|
+
});
|
|
815
725
|
|
|
816
726
|
export const setTableAlignment =
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
727
|
+
(newAlignment: TableLayout): EditorCommand =>
|
|
728
|
+
({ tr }) => {
|
|
729
|
+
const tableObject = findTable(tr.selection);
|
|
820
730
|
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
731
|
+
if (!tableObject) {
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
824
734
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
735
|
+
const nextTableAttrs = {
|
|
736
|
+
...tableObject.node.attrs,
|
|
737
|
+
layout: newAlignment,
|
|
738
|
+
};
|
|
829
739
|
|
|
830
|
-
|
|
831
|
-
'scrollIntoView',
|
|
832
|
-
false,
|
|
833
|
-
);
|
|
740
|
+
tr.setNodeMarkup(tableObject.pos, undefined, nextTableAttrs).setMeta('scrollIntoView', false);
|
|
834
741
|
|
|
835
|
-
|
|
836
|
-
|
|
742
|
+
return tr;
|
|
743
|
+
};
|
|
837
744
|
|
|
838
745
|
export const setTableAlignmentWithTableContentWithPos =
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
746
|
+
(newAlignment: TableLayout, tableNodeWithPos: NodeWithPos): EditorCommand =>
|
|
747
|
+
({ tr }) => {
|
|
748
|
+
const nextTableAttrs = {
|
|
749
|
+
...tableNodeWithPos.node.attrs,
|
|
750
|
+
layout: newAlignment,
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
tr.setNodeMarkup(tableNodeWithPos.pos, undefined, nextTableAttrs).setMeta(
|
|
754
|
+
'scrollIntoView',
|
|
755
|
+
false,
|
|
756
|
+
);
|
|
757
|
+
|
|
758
|
+
return tr;
|
|
759
|
+
};
|