@atlaskit/editor-plugin-table 0.1.0 → 0.1.1
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/CHANGELOG.md +8 -0
- package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
- package/dist/esm/version.json +1 -1
- package/examples/99-testing.tsx +35 -30
- package/package.json +2 -11
- package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
- package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
- package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
- package/src/__tests__/integration/resize.ts +1 -2
- package/src/__tests__/unit/analytics.ts +33 -32
- package/src/__tests__/unit/collab.ts +12 -9
- package/src/__tests__/unit/commands/sort.ts +28 -28
- package/src/__tests__/unit/copy-paste.ts +6 -8
- package/src/__tests__/unit/event-handlers.ts +7 -10
- package/src/__tests__/unit/fix-tables.ts +17 -23
- package/src/__tests__/unit/get-toolbar-config.ts +0 -5
- package/src/__tests__/unit/hover-selection.ts +1 -66
- package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
- package/src/__tests__/unit/index.ts +5 -5
- package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
- package/src/__tests__/unit/nodeviews/cell.ts +12 -10
- package/src/__tests__/unit/nodeviews/table.ts +25 -26
- package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
- package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
- package/src/__tests__/unit/toolbar.ts +18 -5
- package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
- package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
- package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
- package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
- package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
- package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
- package/src/__tests__/unit/ui/RowControls.tsx +112 -141
- package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
- package/src/__tests__/unit/undo-redo.ts +10 -9
- package/src/__tests__/unit/utils/nodes.ts +8 -4
- package/src/__tests__/unit/utils/row-controls.ts +8 -4
- package/src/plugins/table/commands/clear.ts +30 -29
- package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
- package/src/plugins/table/commands/insert.ts +91 -91
- package/src/plugins/table/commands/misc.ts +123 -125
- package/src/plugins/table/commands/selection.ts +329 -319
- package/src/plugins/table/commands-with-analytics.ts +299 -294
- package/src/plugins/table/event-handlers.ts +111 -111
- package/src/plugins/table/handlers.ts +95 -94
- package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
- package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
- package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
- package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
- package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
- package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
- package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
- package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
- package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
- package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
- package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
- package/src/plugins/table/toolbar.tsx +116 -113
- package/src/plugins/table/transforms/column-width.ts +143 -146
- package/src/plugins/table/transforms/delete-columns.ts +144 -142
- package/src/plugins/table/transforms/delete-rows.ts +110 -111
- package/src/plugins/table/transforms/metadata.ts +9 -9
- package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
- package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
- package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
- package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
- package/src/plugins/table/ui/common-styles.ts +1 -3
- package/src/plugins/table/utils/analytics.ts +24 -25
- package/src/plugins/table/utils/dom.ts +3 -3
- package/src/plugins/table/utils/row-controls.ts +92 -93
- package/dist/types-ts4.0/index.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
- package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
- package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
- package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
- package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
- package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
- package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
- package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
- package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
- package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
- package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
- package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
- package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
- package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
- package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
- package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
- package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
- package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
- package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
- package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
- package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
- package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
- package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
- package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
- package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
- package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
- package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
- package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
- package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
- package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
- package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
|
@@ -15,42 +15,45 @@ import { insertRowWithAnalytics } from '../commands-with-analytics';
|
|
|
15
15
|
const TAB_FORWARD_DIRECTION = 1;
|
|
16
16
|
const TAB_BACKWARD_DIRECTION = -1;
|
|
17
17
|
|
|
18
|
-
export const goToNextCell =
|
|
19
|
-
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
18
|
+
export const goToNextCell =
|
|
19
|
+
(editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
|
|
20
|
+
(direction: Direction): Command =>
|
|
21
|
+
(state, dispatch) => {
|
|
22
|
+
const table = findTable(state.selection);
|
|
23
|
+
if (!table) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const map = TableMap.get(table.node);
|
|
28
|
+
const { tableCell, tableHeader } = state.schema.nodes;
|
|
29
|
+
const cell = findParentNodeOfType([tableCell, tableHeader])(
|
|
30
|
+
state.selection,
|
|
31
|
+
)!;
|
|
32
|
+
const firstCellPos = map.positionAt(0, 0, table.node) + table.start;
|
|
33
|
+
const lastCellPos =
|
|
34
|
+
map.positionAt(map.height - 1, map.width - 1, table.node) + table.start;
|
|
35
|
+
|
|
36
|
+
// when tabbing backwards at first cell (top left), insert row at the start of table
|
|
37
|
+
if (firstCellPos === cell.pos && direction === TAB_BACKWARD_DIRECTION) {
|
|
38
|
+
insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, {
|
|
39
|
+
index: 0,
|
|
40
|
+
moveCursorToInsertedRow: true,
|
|
41
|
+
})(state, dispatch);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// when tabbing forwards at last cell (bottom right), insert row at the end of table
|
|
46
|
+
if (lastCellPos === cell.pos && direction === TAB_FORWARD_DIRECTION) {
|
|
47
|
+
insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, {
|
|
48
|
+
index: map.height,
|
|
49
|
+
moveCursorToInsertedRow: true,
|
|
50
|
+
})(state, dispatch);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (dispatch) {
|
|
55
|
+
return baseGotoNextCell(direction)(state, dispatch);
|
|
56
|
+
}
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return true;
|
|
56
|
-
};
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
@@ -57,109 +57,109 @@ export function addColumnAt(getEditorContainerWidth: GetEditorContainerWidth) {
|
|
|
57
57
|
|
|
58
58
|
// :: (EditorState, dispatch: ?(tr: Transaction)) → bool
|
|
59
59
|
// Command to add a column before the column with the selection.
|
|
60
|
-
export const addColumnBefore =
|
|
61
|
-
getEditorContainerWidth: GetEditorContainerWidth
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
60
|
+
export const addColumnBefore =
|
|
61
|
+
(getEditorContainerWidth: GetEditorContainerWidth): Command =>
|
|
62
|
+
(state, dispatch, view) => {
|
|
63
|
+
const table = findTable(state.selection);
|
|
64
|
+
if (!table) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (dispatch) {
|
|
68
|
+
let rect = selectedRect(state);
|
|
69
|
+
dispatch(
|
|
70
|
+
addColumnAt(getEditorContainerWidth)(
|
|
71
|
+
rect.left,
|
|
72
|
+
getAllowAddColumnCustomStep(state),
|
|
73
|
+
view,
|
|
74
|
+
)(state.tr),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
79
|
|
|
80
80
|
// :: (EditorState, dispatch: ?(tr: Transaction)) → bool
|
|
81
81
|
// Command to add a column after the column with the selection.
|
|
82
|
-
export const addColumnAfter =
|
|
83
|
-
getEditorContainerWidth: GetEditorContainerWidth
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
82
|
+
export const addColumnAfter =
|
|
83
|
+
(getEditorContainerWidth: GetEditorContainerWidth): Command =>
|
|
84
|
+
(state, dispatch, view) => {
|
|
85
|
+
const table = findTable(state.selection);
|
|
86
|
+
if (!table) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (dispatch) {
|
|
90
|
+
let rect = selectedRect(state);
|
|
91
|
+
dispatch(
|
|
92
|
+
addColumnAt(getEditorContainerWidth)(
|
|
93
|
+
rect.right,
|
|
94
|
+
getAllowAddColumnCustomStep(state),
|
|
95
|
+
view,
|
|
96
|
+
)(state.tr),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
101
|
|
|
102
102
|
// #region Commands
|
|
103
|
-
export const insertColumn =
|
|
104
|
-
getEditorContainerWidth: GetEditorContainerWidth
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
103
|
+
export const insertColumn =
|
|
104
|
+
(getEditorContainerWidth: GetEditorContainerWidth) =>
|
|
105
|
+
(column: number): Command =>
|
|
106
|
+
(state, dispatch, view) => {
|
|
107
|
+
let tr = addColumnAt(getEditorContainerWidth)(
|
|
108
|
+
column,
|
|
109
|
+
getAllowAddColumnCustomStep(state),
|
|
110
|
+
view,
|
|
111
|
+
)(state.tr);
|
|
112
|
+
const table = findTable(tr.selection);
|
|
113
|
+
if (!table) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
// move the cursor to the newly created column
|
|
117
|
+
const pos = TableMap.get(table.node).positionAt(0, column, table.node);
|
|
117
118
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
119
|
+
if (dispatch) {
|
|
120
|
+
dispatch(
|
|
121
|
+
tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos))),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
};
|
|
125
126
|
|
|
126
|
-
export const insertRow =
|
|
127
|
-
row: number,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
(headerRowEnabled && row > 1) || (!headerRowEnabled && row > 0);
|
|
127
|
+
export const insertRow =
|
|
128
|
+
(row: number, moveCursorToTheNewRow: boolean): Command =>
|
|
129
|
+
(state, dispatch) => {
|
|
130
|
+
// Don't clone the header row
|
|
131
|
+
const headerRowEnabled = checkIfHeaderRowEnabled(state.selection);
|
|
132
|
+
const clonePreviousRow =
|
|
133
|
+
(headerRowEnabled && row > 1) || (!headerRowEnabled && row > 0);
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
// When the table have header row
|
|
136
|
+
// we should not add row on the position zero
|
|
137
|
+
if (row === 0 && headerRowEnabled) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
const tr = clonePreviousRow
|
|
142
|
+
? copyPreviousRow(state.schema)(row)(state.tr)
|
|
143
|
+
: addRowAt(row)(state.tr);
|
|
144
144
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
if (dispatch) {
|
|
150
|
-
const { selection } = state;
|
|
151
|
-
if (moveCursorToTheNewRow) {
|
|
152
|
-
// move the cursor to the newly created row
|
|
153
|
-
const pos = TableMap.get(table.node).positionAt(row, 0, table.node);
|
|
154
|
-
tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos)));
|
|
155
|
-
} else {
|
|
156
|
-
tr.setSelection(selection.map(tr.doc, tr.mapping));
|
|
145
|
+
const table = findTable(tr.selection);
|
|
146
|
+
if (!table) {
|
|
147
|
+
return false;
|
|
157
148
|
}
|
|
149
|
+
if (dispatch) {
|
|
150
|
+
const { selection } = state;
|
|
151
|
+
if (moveCursorToTheNewRow) {
|
|
152
|
+
// move the cursor to the newly created row
|
|
153
|
+
const pos = TableMap.get(table.node).positionAt(row, 0, table.node);
|
|
154
|
+
tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos)));
|
|
155
|
+
} else {
|
|
156
|
+
tr.setSelection(selection.map(tr.doc, tr.mapping));
|
|
157
|
+
}
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
};
|
|
159
|
+
dispatch(tr);
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
};
|
|
163
163
|
|
|
164
164
|
export const createTable = (): Command => (state, dispatch) => {
|
|
165
165
|
const table = createTableNode({
|
|
@@ -97,70 +97,67 @@ export const setTableRef = (ref?: HTMLTableElement) =>
|
|
|
97
97
|
(tr) => tr.setMeta('addToHistory', false),
|
|
98
98
|
);
|
|
99
99
|
|
|
100
|
-
export const setCellAttr =
|
|
101
|
-
|
|
102
|
-
dispatch
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
export const setCellAttr =
|
|
101
|
+
(name: string, value: any): Command =>
|
|
102
|
+
(state, dispatch) => {
|
|
103
|
+
const { tr, selection } = state;
|
|
104
|
+
if (selection instanceof CellSelection) {
|
|
105
|
+
let updated = false;
|
|
106
|
+
selection.forEachCell((cell, pos) => {
|
|
107
|
+
if (cell.attrs[name] !== value) {
|
|
108
|
+
tr.setNodeMarkup(pos, cell.type, { ...cell.attrs, [name]: value });
|
|
109
|
+
updated = true;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (updated) {
|
|
113
|
+
if (dispatch) {
|
|
114
|
+
dispatch(tr);
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
111
117
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
dispatch
|
|
118
|
+
} else {
|
|
119
|
+
const cell = selectionCell(state.selection);
|
|
120
|
+
if (cell) {
|
|
121
|
+
if (dispatch) {
|
|
122
|
+
dispatch(
|
|
123
|
+
tr.setNodeMarkup(cell.pos, cell.nodeAfter?.type, {
|
|
124
|
+
...cell.nodeAfter?.attrs,
|
|
125
|
+
[name]: value,
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
116
130
|
}
|
|
117
|
-
return true;
|
|
118
131
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const triggerUnlessTableHeader =
|
|
136
|
+
(command: Command): Command =>
|
|
137
|
+
(state, dispatch, view) => {
|
|
138
|
+
const {
|
|
139
|
+
selection,
|
|
140
|
+
schema: {
|
|
141
|
+
nodes: { tableHeader },
|
|
142
|
+
},
|
|
143
|
+
} = state;
|
|
144
|
+
|
|
145
|
+
if (selection instanceof TextSelection) {
|
|
146
|
+
const cell = findCellClosestToPos(selection.$from);
|
|
147
|
+
if (cell && cell.node.type !== tableHeader) {
|
|
148
|
+
return command(state, dispatch, view);
|
|
129
149
|
}
|
|
130
|
-
return true;
|
|
131
150
|
}
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
};
|
|
135
151
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const {
|
|
142
|
-
selection,
|
|
143
|
-
schema: {
|
|
144
|
-
nodes: { tableHeader },
|
|
145
|
-
},
|
|
146
|
-
} = state;
|
|
147
|
-
|
|
148
|
-
if (selection instanceof TextSelection) {
|
|
149
|
-
const cell = findCellClosestToPos(selection.$from);
|
|
150
|
-
if (cell && cell.node.type !== tableHeader) {
|
|
151
|
-
return command(state, dispatch, view);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (selection instanceof CellSelection) {
|
|
156
|
-
const rect = getSelectionRect(selection);
|
|
157
|
-
if (!checkIfHeaderRowEnabled(selection) || (rect && rect.top > 0)) {
|
|
158
|
-
return command(state, dispatch, view);
|
|
152
|
+
if (selection instanceof CellSelection) {
|
|
153
|
+
const rect = getSelectionRect(selection);
|
|
154
|
+
if (!checkIfHeaderRowEnabled(selection) || (rect && rect.top > 0)) {
|
|
155
|
+
return command(state, dispatch, view);
|
|
156
|
+
}
|
|
159
157
|
}
|
|
160
|
-
}
|
|
161
158
|
|
|
162
|
-
|
|
163
|
-
};
|
|
159
|
+
return false;
|
|
160
|
+
};
|
|
164
161
|
|
|
165
162
|
export const transformSliceRemoveCellBackgroundColor = (
|
|
166
163
|
slice: Slice,
|
|
@@ -248,21 +245,21 @@ export const deleteTableIfSelected: Command = (state, dispatch) => {
|
|
|
248
245
|
return false;
|
|
249
246
|
};
|
|
250
247
|
|
|
251
|
-
export const convertFirstRowToHeader =
|
|
252
|
-
|
|
253
|
-
): Transaction => {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
};
|
|
248
|
+
export const convertFirstRowToHeader =
|
|
249
|
+
(schema: Schema) =>
|
|
250
|
+
(tr: Transaction): Transaction => {
|
|
251
|
+
const table = findTable(tr.selection)!;
|
|
252
|
+
const map = TableMap.get(table.node);
|
|
253
|
+
for (let i = 0; i < map.width; i++) {
|
|
254
|
+
const cell = table.node.child(0).child(i);
|
|
255
|
+
tr.setNodeMarkup(
|
|
256
|
+
table.start + map.map[i],
|
|
257
|
+
schema.nodes.tableHeader,
|
|
258
|
+
cell.attrs,
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
return tr;
|
|
262
|
+
};
|
|
266
263
|
|
|
267
264
|
export const moveCursorBackward: Command = (state, dispatch) => {
|
|
268
265
|
const { $cursor } = state.selection as TextSelection;
|
|
@@ -332,36 +329,37 @@ export const moveCursorBackward: Command = (state, dispatch) => {
|
|
|
332
329
|
return true;
|
|
333
330
|
};
|
|
334
331
|
|
|
335
|
-
export const setMultipleCellAttrs =
|
|
336
|
-
attrs: Object,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
332
|
+
export const setMultipleCellAttrs =
|
|
333
|
+
(attrs: Object, targetCellPosition?: number): Command =>
|
|
334
|
+
(state, dispatch) => {
|
|
335
|
+
let cursorPos: number | undefined;
|
|
336
|
+
let { tr } = state;
|
|
337
|
+
|
|
338
|
+
if (isSelectionType(tr.selection, 'cell')) {
|
|
339
|
+
const selection = tr.selection as any as CellSelection;
|
|
340
|
+
selection.forEachCell((_cell, pos) => {
|
|
341
|
+
const $pos = tr.doc.resolve(tr.mapping.map(pos + 1));
|
|
342
|
+
tr = setCellAttrs(findCellClosestToPos($pos)!, attrs)(tr);
|
|
343
|
+
});
|
|
344
|
+
cursorPos = selection.$headCell.pos;
|
|
345
|
+
} else if (targetCellPosition) {
|
|
346
|
+
const cell = findCellClosestToPos(
|
|
347
|
+
tr.doc.resolve(targetCellPosition + 1),
|
|
348
|
+
)!;
|
|
349
|
+
tr = setCellAttrs(cell, attrs)(tr);
|
|
350
|
+
cursorPos = cell.pos;
|
|
351
|
+
}
|
|
354
352
|
|
|
355
|
-
|
|
356
|
-
|
|
353
|
+
if (tr.docChanged && cursorPos !== undefined) {
|
|
354
|
+
const $pos = tr.doc.resolve(tr.mapping.map(cursorPos!));
|
|
357
355
|
|
|
358
|
-
|
|
359
|
-
|
|
356
|
+
if (dispatch) {
|
|
357
|
+
dispatch(tr.setSelection(Selection.near($pos)));
|
|
358
|
+
}
|
|
359
|
+
return true;
|
|
360
360
|
}
|
|
361
|
-
return
|
|
362
|
-
}
|
|
363
|
-
return false;
|
|
364
|
-
};
|
|
361
|
+
return false;
|
|
362
|
+
};
|
|
365
363
|
|
|
366
364
|
export const selectColumn = (column: number, expand?: boolean) =>
|
|
367
365
|
createCommand(
|
|
@@ -473,34 +471,34 @@ export const autoSizeTable = (
|
|
|
473
471
|
return true;
|
|
474
472
|
};
|
|
475
473
|
|
|
476
|
-
export const addBoldInEmptyHeaderCells =
|
|
477
|
-
tableCellHeader: ContentNodeWithPos
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
474
|
+
export const addBoldInEmptyHeaderCells =
|
|
475
|
+
(tableCellHeader: ContentNodeWithPos): Command =>
|
|
476
|
+
(state, dispatch): boolean => {
|
|
477
|
+
const { tr } = state;
|
|
478
|
+
if (
|
|
479
|
+
// Avoid infinite loop when the current selection is not a TextSelection
|
|
480
|
+
isTextSelection(tr.selection) &&
|
|
481
|
+
tr.selection.$cursor &&
|
|
482
|
+
// When storedMark is null that means this is the initial state
|
|
483
|
+
// if the user press to remove the mark storedMark will be an empty array
|
|
484
|
+
// and we shouldn't apply the strong mark
|
|
485
|
+
tr.storedMarks == null &&
|
|
486
|
+
// Check if the current node is a direct child from paragraph
|
|
487
|
+
tr.selection.$from.depth === tableCellHeader.depth + 1 &&
|
|
488
|
+
// this logic is applied only for empty paragraph
|
|
489
|
+
tableCellHeader.node.nodeSize === 4 &&
|
|
490
|
+
isParagraph(tableCellHeader.node.firstChild, state.schema)
|
|
491
|
+
) {
|
|
492
|
+
const { strong } = state.schema.marks;
|
|
493
|
+
tr.setStoredMarks([strong.create()]).setMeta('addToHistory', false);
|
|
496
494
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
495
|
+
if (dispatch) {
|
|
496
|
+
dispatch(tr);
|
|
497
|
+
}
|
|
500
498
|
|
|
501
|
-
|
|
502
|
-
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
503
501
|
|
|
504
|
-
|
|
505
|
-
};
|
|
502
|
+
return false;
|
|
503
|
+
};
|
|
506
504
|
// #endregion
|