@atlaskit/editor-plugin-table 12.2.6 → 12.2.7
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/package.json +4 -4
- package/afm-cc/tsconfig.json +0 -123
- package/afm-dev-agents/tsconfig.json +0 -123
- package/afm-jira/tsconfig.json +0 -123
- package/afm-passionfruit/tsconfig.json +0 -123
- package/afm-post-office/tsconfig.json +0 -123
- package/afm-rovo-extension/tsconfig.json +0 -123
- package/afm-townsquare/tsconfig.json +0 -123
- package/afm-volt/tsconfig.json +0 -114
- package/build/tsconfig.json +0 -23
- package/docs/0-intro.tsx +0 -57
- package/src/index.ts +0 -21
- package/src/nodeviews/ExternalDropTargets.tsx +0 -91
- package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
- package/src/nodeviews/TableCell.ts +0 -134
- package/src/nodeviews/TableComponent.tsx +0 -1590
- package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
- package/src/nodeviews/TableContainer.tsx +0 -926
- package/src/nodeviews/TableNodeViewBase.ts +0 -29
- package/src/nodeviews/TableResizer.tsx +0 -884
- package/src/nodeviews/TableRow.ts +0 -830
- package/src/nodeviews/TableStickyScrollbar.ts +0 -211
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
- package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
- package/src/nodeviews/table-container-styles.ts +0 -9
- package/src/nodeviews/table-node-views.ts +0 -76
- package/src/nodeviews/table.tsx +0 -530
- package/src/nodeviews/toDOM.ts +0 -244
- package/src/nodeviews/types.ts +0 -36
- package/src/nodeviews/update-overflow-shadows.ts +0 -11
- package/src/pm-plugins/analytics/actions.ts +0 -21
- package/src/pm-plugins/analytics/commands.ts +0 -47
- package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
- package/src/pm-plugins/analytics/plugin-key.ts +0 -5
- package/src/pm-plugins/analytics/plugin.ts +0 -80
- package/src/pm-plugins/analytics/reducer.ts +0 -27
- package/src/pm-plugins/analytics/types.ts +0 -20
- package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
- package/src/pm-plugins/commands/clear.ts +0 -43
- package/src/pm-plugins/commands/collapse.ts +0 -17
- package/src/pm-plugins/commands/column-resize.ts +0 -478
- package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
- package/src/pm-plugins/commands/delete.ts +0 -42
- package/src/pm-plugins/commands/display-mode.ts +0 -18
- package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
- package/src/pm-plugins/commands/hover.ts +0 -242
- package/src/pm-plugins/commands/index.ts +0 -51
- package/src/pm-plugins/commands/insert.ts +0 -438
- package/src/pm-plugins/commands/misc.ts +0 -811
- package/src/pm-plugins/commands/referentiality.ts +0 -15
- package/src/pm-plugins/commands/selection.ts +0 -537
- package/src/pm-plugins/commands/sort.ts +0 -102
- package/src/pm-plugins/commands/split-cell.ts +0 -28
- package/src/pm-plugins/commands/toggle.ts +0 -109
- package/src/pm-plugins/create-plugin-config.ts +0 -17
- package/src/pm-plugins/decorations/plugin.ts +0 -107
- package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
- package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
- package/src/pm-plugins/decorations/utils/types.ts +0 -16
- package/src/pm-plugins/default-table-selection.ts +0 -14
- package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
- package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
- package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
- package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
- package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
- package/src/pm-plugins/drag-and-drop/types.ts +0 -18
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
- package/src/pm-plugins/handlers.ts +0 -161
- package/src/pm-plugins/keymap.ts +0 -436
- package/src/pm-plugins/main.ts +0 -433
- package/src/pm-plugins/plugin-factory.ts +0 -42
- package/src/pm-plugins/plugin-key.ts +0 -8
- package/src/pm-plugins/reducer.ts +0 -145
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
- package/src/pm-plugins/sticky-headers/commands.ts +0 -8
- package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
- package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
- package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
- package/src/pm-plugins/sticky-headers/types.ts +0 -20
- package/src/pm-plugins/sticky-headers/util.ts +0 -18
- package/src/pm-plugins/table-analytics.ts +0 -100
- package/src/pm-plugins/table-local-id.ts +0 -213
- package/src/pm-plugins/table-resizing/commands.ts +0 -116
- package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
- package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
- package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
- package/src/pm-plugins/table-resizing/plugin.ts +0 -94
- package/src/pm-plugins/table-resizing/reducer.ts +0 -37
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
- package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
- package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
- package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
- package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
- package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
- package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
- package/src/pm-plugins/table-selection-keymap.ts +0 -64
- package/src/pm-plugins/table-size-selector.ts +0 -39
- package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
- package/src/pm-plugins/table-width.ts +0 -153
- package/src/pm-plugins/transforms/column-width.ts +0 -249
- package/src/pm-plugins/transforms/delete-columns.ts +0 -281
- package/src/pm-plugins/transforms/delete-rows.ts +0 -154
- package/src/pm-plugins/transforms/fix-tables.ts +0 -249
- package/src/pm-plugins/transforms/merge.ts +0 -301
- package/src/pm-plugins/transforms/replace-table.ts +0 -38
- package/src/pm-plugins/transforms/split.ts +0 -90
- package/src/pm-plugins/utils/alignment.ts +0 -33
- package/src/pm-plugins/utils/analytics.ts +0 -238
- package/src/pm-plugins/utils/collapse.ts +0 -93
- package/src/pm-plugins/utils/column-controls.ts +0 -250
- package/src/pm-plugins/utils/create.ts +0 -64
- package/src/pm-plugins/utils/decoration.ts +0 -672
- package/src/pm-plugins/utils/dom.ts +0 -251
- package/src/pm-plugins/utils/drag-menu.tsx +0 -491
- package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
- package/src/pm-plugins/utils/guidelines.ts +0 -30
- package/src/pm-plugins/utils/merged-cells.ts +0 -239
- package/src/pm-plugins/utils/nodes.ts +0 -162
- package/src/pm-plugins/utils/paste.ts +0 -386
- package/src/pm-plugins/utils/row-controls.ts +0 -211
- package/src/pm-plugins/utils/selection.ts +0 -17
- package/src/pm-plugins/utils/snapping.ts +0 -136
- package/src/pm-plugins/utils/table.ts +0 -60
- package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
- package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
- package/src/pm-plugins/view-mode-sort/index.ts +0 -291
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
- package/src/pm-plugins/view-mode-sort/types.ts +0 -23
- package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
- package/src/tablePlugin.tsx +0 -971
- package/src/tablePluginType.ts +0 -102
- package/src/types/index.ts +0 -592
- package/src/ui/ColumnResizeWidget/index.tsx +0 -61
- package/src/ui/ContentComponent.tsx +0 -311
- package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
- package/src/ui/DragHandle/index.tsx +0 -391
- package/src/ui/DragPreview/index.tsx +0 -51
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
- package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
- package/src/ui/FloatingContextualButton/index.tsx +0 -168
- package/src/ui/FloatingContextualButton/styles.ts +0 -69
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
- package/src/ui/FloatingContextualMenu/index.tsx +0 -141
- package/src/ui/FloatingContextualMenu/styles.ts +0 -77
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
- package/src/ui/FloatingDeleteButton/index.tsx +0 -383
- package/src/ui/FloatingDeleteButton/types.ts +0 -3
- package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
- package/src/ui/FloatingDragMenu/index.tsx +0 -136
- package/src/ui/FloatingDragMenu/styles.ts +0 -83
- package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
- package/src/ui/FloatingInsertButton/index.tsx +0 -314
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
- package/src/ui/SizeSelector/index.tsx +0 -74
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
- package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
- package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -175
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
- package/src/ui/TableFloatingControls/index.tsx +0 -275
- package/src/ui/TableFullWidthLabel/index.tsx +0 -38
- package/src/ui/common-styles.ts +0 -1218
- package/src/ui/consts.ts +0 -109
- package/src/ui/event-handlers.ts +0 -662
- package/src/ui/global-styles.tsx +0 -55
- package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
- package/src/ui/icons/AddColLeftIcon.tsx +0 -37
- package/src/ui/icons/AddColRightIcon.tsx +0 -37
- package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
- package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
- package/src/ui/icons/DragHandleIcon.tsx +0 -16
- package/src/ui/icons/DragInMotionIcon.tsx +0 -54
- package/src/ui/icons/MergeCellsIcon.tsx +0 -26
- package/src/ui/icons/MinimisedHandle.tsx +0 -15
- package/src/ui/icons/SortingIconWrapper.tsx +0 -43
- package/src/ui/icons/SplitCellIcon.tsx +0 -34
- package/src/ui/toolbar.tsx +0 -1153
- package/src/ui/ui-styles.ts +0 -960
- package/tsconfig.app.json +0 -135
- package/tsconfig.dev.json +0 -54
- package/tsconfig.json +0 -18
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { removeConnectedNodes } from '@atlaskit/editor-common/utils';
|
|
2
|
-
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
|
|
4
|
-
import { createCommand } from '../plugin-factory';
|
|
5
|
-
|
|
6
|
-
export const removeDescendantNodes = (sourceNode: PMNode) =>
|
|
7
|
-
createCommand(
|
|
8
|
-
{
|
|
9
|
-
type: 'UPDATE_STATE',
|
|
10
|
-
data: { element: undefined },
|
|
11
|
-
},
|
|
12
|
-
(tr, state) => {
|
|
13
|
-
return sourceNode ? removeConnectedNodes(state, sourceNode) : tr;
|
|
14
|
-
},
|
|
15
|
-
);
|
|
@@ -1,537 +0,0 @@
|
|
|
1
|
-
import { type IntlShape } from 'react-intl-next/src/types';
|
|
2
|
-
|
|
3
|
-
import { tableMessages as messages } from '@atlaskit/editor-common/messages';
|
|
4
|
-
import type { SelectionSharedState } from '@atlaskit/editor-common/selection';
|
|
5
|
-
import {
|
|
6
|
-
GapCursorSelection,
|
|
7
|
-
isSelectionAtEndOfNode,
|
|
8
|
-
isSelectionAtStartOfNode,
|
|
9
|
-
RelativeSelectionPos,
|
|
10
|
-
Side,
|
|
11
|
-
} from '@atlaskit/editor-common/selection';
|
|
12
|
-
import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
13
|
-
import type { AriaLiveElementAttributes } from '@atlaskit/editor-plugin-accessibility-utils';
|
|
14
|
-
import type { Node as PmNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
15
|
-
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
16
|
-
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
17
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
18
|
-
import {
|
|
19
|
-
findTable,
|
|
20
|
-
isColumnSelected,
|
|
21
|
-
isRowSelected,
|
|
22
|
-
isTableSelected,
|
|
23
|
-
selectedRect,
|
|
24
|
-
} from '@atlaskit/editor-tables/utils';
|
|
25
|
-
|
|
26
|
-
import type tablePlugin from '../../tablePlugin';
|
|
27
|
-
import { getClosestSelectionRect } from '../../ui/toolbar';
|
|
28
|
-
import { getPluginState } from '../plugin-factory';
|
|
29
|
-
|
|
30
|
-
import { selectColumn, selectRow } from './misc';
|
|
31
|
-
|
|
32
|
-
enum TableSelectionDirection {
|
|
33
|
-
TopToBottom = 'TopToBottom',
|
|
34
|
-
BottomToTop = 'BottomToTop',
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const arrowLeftFromTable =
|
|
38
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
39
|
-
(): Command =>
|
|
40
|
-
(state, dispatch) => {
|
|
41
|
-
const { selection } = state;
|
|
42
|
-
if (selection instanceof CellSelection) {
|
|
43
|
-
return arrowLeftFromCellSelection(editorSelectionAPI)(selection)(state, dispatch);
|
|
44
|
-
} else if (selection instanceof GapCursorSelection) {
|
|
45
|
-
return arrowLeftFromGapCursor(editorSelectionAPI)(selection)(state, dispatch);
|
|
46
|
-
} else if (selection instanceof TextSelection) {
|
|
47
|
-
return arrowLeftFromText(editorSelectionAPI)(selection)(state, dispatch);
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const arrowRightFromTable =
|
|
53
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
54
|
-
(): Command =>
|
|
55
|
-
(state, dispatch) => {
|
|
56
|
-
const { selection } = state;
|
|
57
|
-
|
|
58
|
-
if (selection instanceof CellSelection) {
|
|
59
|
-
return arrowRightFromCellSelection(editorSelectionAPI)(selection)(state, dispatch);
|
|
60
|
-
} else if (selection instanceof GapCursorSelection) {
|
|
61
|
-
return arrowRightFromGapCursor(editorSelectionAPI)(selection)(state, dispatch);
|
|
62
|
-
} else if (selection instanceof TextSelection) {
|
|
63
|
-
return arrowRightFromText(editorSelectionAPI)(selection)(state, dispatch);
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const arrowLeftFromCellSelection =
|
|
69
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
70
|
-
(selection: CellSelection): Command =>
|
|
71
|
-
(state, dispatch) => {
|
|
72
|
-
if (isTableSelected(state.selection) && editorSelectionAPI) {
|
|
73
|
-
const selectionState: SelectionSharedState =
|
|
74
|
-
editorSelectionAPI.sharedState.currentState() || {};
|
|
75
|
-
if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.Start) {
|
|
76
|
-
// we have full table cell selection and want to set gap cursor selection before table
|
|
77
|
-
return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
|
|
78
|
-
} else if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.End) {
|
|
79
|
-
// we have full table cell selection and want to set selection at end of last cell
|
|
80
|
-
return setSelectionAtEndOfLastCell(editorSelectionAPI)(selection)(state, dispatch);
|
|
81
|
-
} else if (selectionState?.selectionRelativeToNode === undefined) {
|
|
82
|
-
// we have full table cell selection and want to set selection at start of first cell
|
|
83
|
-
return setSelectionAtStartOfFirstCell(editorSelectionAPI)(
|
|
84
|
-
selection,
|
|
85
|
-
RelativeSelectionPos.Before,
|
|
86
|
-
)(state, dispatch);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const arrowRightFromCellSelection =
|
|
93
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
94
|
-
(selection: CellSelection): Command =>
|
|
95
|
-
(state, dispatch) => {
|
|
96
|
-
if (isTableSelected(state.selection) && editorSelectionAPI) {
|
|
97
|
-
const { selectionRelativeToNode } = editorSelectionAPI.sharedState.currentState() || {};
|
|
98
|
-
|
|
99
|
-
if (selectionRelativeToNode === RelativeSelectionPos.Start) {
|
|
100
|
-
// we have full table cell selection and want to set selection at start of first cell
|
|
101
|
-
return setSelectionAtStartOfFirstCell(editorSelectionAPI)(selection)(state, dispatch);
|
|
102
|
-
} else if (
|
|
103
|
-
selectionRelativeToNode === RelativeSelectionPos.End ||
|
|
104
|
-
selectionRelativeToNode === undefined
|
|
105
|
-
) {
|
|
106
|
-
// we have full table cell selection and want to set gap cursor selection after table
|
|
107
|
-
return setGapCursorAfterTable(editorSelectionAPI)()(state, dispatch);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return false;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export const selectColumns =
|
|
114
|
-
(
|
|
115
|
-
editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined,
|
|
116
|
-
ariaNotify?: (message: string, ariaLiveElementAttributes?: AriaLiveElementAttributes) => void,
|
|
117
|
-
getIntl?: () => IntlShape,
|
|
118
|
-
) =>
|
|
119
|
-
(triggeredByKeyboard = false): Command =>
|
|
120
|
-
(state, dispatch) => {
|
|
121
|
-
const { selection } = state;
|
|
122
|
-
const table = findTable(selection);
|
|
123
|
-
const rect = selectedRect(state);
|
|
124
|
-
if (table && isRowSelected(rect.top)(selection)) {
|
|
125
|
-
return selectFullTable(editorSelectionAPI)({
|
|
126
|
-
node: table.node,
|
|
127
|
-
startPos: table.start,
|
|
128
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
129
|
-
})(state, dispatch);
|
|
130
|
-
}
|
|
131
|
-
if (table && rect) {
|
|
132
|
-
const selectColumnCommand = selectColumn(
|
|
133
|
-
rect.left,
|
|
134
|
-
undefined,
|
|
135
|
-
triggeredByKeyboard,
|
|
136
|
-
)(state, dispatch);
|
|
137
|
-
const map = TableMap.get(table.node);
|
|
138
|
-
|
|
139
|
-
if (ariaNotify && getIntl) {
|
|
140
|
-
ariaNotify(
|
|
141
|
-
getIntl().formatMessage(messages.columnSelected, {
|
|
142
|
-
index: rect.left + 1,
|
|
143
|
-
total: map.width,
|
|
144
|
-
}),
|
|
145
|
-
{
|
|
146
|
-
priority: 'important',
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return selectColumnCommand;
|
|
152
|
-
}
|
|
153
|
-
return false;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export const selectRows =
|
|
157
|
-
(
|
|
158
|
-
editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined,
|
|
159
|
-
ariaNotify?: (message: string, ariaLiveElementAttributes?: AriaLiveElementAttributes) => void,
|
|
160
|
-
getIntl?: () => IntlShape,
|
|
161
|
-
) =>
|
|
162
|
-
(triggeredByKeyboard = false): Command =>
|
|
163
|
-
(state, dispatch) => {
|
|
164
|
-
const { selection } = state;
|
|
165
|
-
const table = findTable(selection);
|
|
166
|
-
const rect = selectedRect(state);
|
|
167
|
-
if (table && isColumnSelected(rect.left)(selection)) {
|
|
168
|
-
return selectFullTable(editorSelectionAPI)({
|
|
169
|
-
node: table.node,
|
|
170
|
-
startPos: table.start,
|
|
171
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
172
|
-
})(state, dispatch);
|
|
173
|
-
}
|
|
174
|
-
if (table && rect) {
|
|
175
|
-
const selectRowCommand = selectRow(rect.top, undefined, triggeredByKeyboard)(state, dispatch);
|
|
176
|
-
const map = TableMap.get(table.node);
|
|
177
|
-
|
|
178
|
-
if (ariaNotify && getIntl) {
|
|
179
|
-
ariaNotify(
|
|
180
|
-
getIntl().formatMessage(messages.rowSelected, {
|
|
181
|
-
index: rect.top + 1,
|
|
182
|
-
total: map.height,
|
|
183
|
-
}),
|
|
184
|
-
{
|
|
185
|
-
priority: 'important',
|
|
186
|
-
},
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
return selectRowCommand;
|
|
190
|
-
}
|
|
191
|
-
return false;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
const arrowLeftFromGapCursor =
|
|
195
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
196
|
-
(selection: GapCursorSelection): Command =>
|
|
197
|
-
(state, dispatch) => {
|
|
198
|
-
const { doc } = state;
|
|
199
|
-
const { $from, from, side } = selection;
|
|
200
|
-
|
|
201
|
-
if (side === Side.RIGHT) {
|
|
202
|
-
if ($from.nodeBefore && $from.nodeBefore.type.name === 'table') {
|
|
203
|
-
// we have a gap cursor after a table node and want to set a full table cell selection
|
|
204
|
-
return selectFullTable(editorSelectionAPI)({
|
|
205
|
-
node: $from.nodeBefore,
|
|
206
|
-
startPos: doc.resolve(from - 1).start($from.depth + 1),
|
|
207
|
-
dir: TableSelectionDirection.TopToBottom,
|
|
208
|
-
})(state, dispatch);
|
|
209
|
-
}
|
|
210
|
-
} else if (side === Side.LEFT) {
|
|
211
|
-
const table = findTable(selection);
|
|
212
|
-
if (table && isSelectionAtStartOfTable($from, selection) && editorSelectionAPI) {
|
|
213
|
-
const selectionState: SelectionSharedState =
|
|
214
|
-
editorSelectionAPI.sharedState.currentState() || {};
|
|
215
|
-
if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.Before) {
|
|
216
|
-
// we have a gap cursor at start of first table cell and want to set a gap cursor selection before table
|
|
217
|
-
return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
|
|
218
|
-
} else {
|
|
219
|
-
// we have a gap cursor at start of first table cell and want to set a full table cell selection
|
|
220
|
-
return selectFullTable(editorSelectionAPI)({
|
|
221
|
-
node: table.node,
|
|
222
|
-
startPos: table.start,
|
|
223
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
224
|
-
})(state, dispatch);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return false;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const arrowRightFromGapCursor =
|
|
232
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
233
|
-
(selection: GapCursorSelection): Command =>
|
|
234
|
-
(state, dispatch) => {
|
|
235
|
-
const { $from, from, $to, side } = selection;
|
|
236
|
-
|
|
237
|
-
if (side === Side.LEFT) {
|
|
238
|
-
if ($from.nodeAfter && $from.nodeAfter.type.name === 'table') {
|
|
239
|
-
// we have a gap cursor before a table node and want to set a full table cell selection
|
|
240
|
-
return selectFullTable(editorSelectionAPI)({
|
|
241
|
-
node: $from.nodeAfter,
|
|
242
|
-
startPos: from + 1,
|
|
243
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
244
|
-
})(state, dispatch);
|
|
245
|
-
}
|
|
246
|
-
} else if (side === Side.RIGHT) {
|
|
247
|
-
const table = findTable(selection);
|
|
248
|
-
if (table && isSelectionAtEndOfTable($to, selection)) {
|
|
249
|
-
// we have a gap cursor at end of last table cell and want to set a full table cell selection
|
|
250
|
-
return selectFullTable(editorSelectionAPI)({
|
|
251
|
-
node: table.node,
|
|
252
|
-
startPos: table.start,
|
|
253
|
-
dir: TableSelectionDirection.TopToBottom,
|
|
254
|
-
})(state, dispatch);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return false;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const arrowLeftFromText =
|
|
261
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
262
|
-
(selection: TextSelection): Command =>
|
|
263
|
-
(state, dispatch) => {
|
|
264
|
-
const table = findTable(selection);
|
|
265
|
-
if (table) {
|
|
266
|
-
const { $from } = selection;
|
|
267
|
-
|
|
268
|
-
const columResizePluginState = getPluginState(state) || {};
|
|
269
|
-
const isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
|
|
270
|
-
|
|
271
|
-
if (
|
|
272
|
-
isSelectionAtStartOfTable($from, selection) &&
|
|
273
|
-
$from.parent.type.name === 'paragraph' &&
|
|
274
|
-
$from.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
|
|
275
|
-
editorSelectionAPI &&
|
|
276
|
-
!isColumnResizing
|
|
277
|
-
) {
|
|
278
|
-
const selectionState: SelectionSharedState =
|
|
279
|
-
editorSelectionAPI.sharedState.currentState() || {};
|
|
280
|
-
|
|
281
|
-
if (selectionState?.selectionRelativeToNode === RelativeSelectionPos.Before) {
|
|
282
|
-
// we have a text selection at start of first table cell, directly inside a top level paragraph,
|
|
283
|
-
// and want to set gap cursor selection before table
|
|
284
|
-
return setGapCursorBeforeTable(editorSelectionAPI)()(state, dispatch);
|
|
285
|
-
} else {
|
|
286
|
-
// we have a text selection at start of first table cell, directly inside a top level paragraph,
|
|
287
|
-
// and want to set a full table cell selection
|
|
288
|
-
return selectFullTable(editorSelectionAPI)({
|
|
289
|
-
node: table.node,
|
|
290
|
-
startPos: table.start,
|
|
291
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
292
|
-
})(state, dispatch);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return false;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
const arrowRightFromText =
|
|
300
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
301
|
-
(selection: TextSelection): Command =>
|
|
302
|
-
(state, dispatch) => {
|
|
303
|
-
const table = findTable(selection);
|
|
304
|
-
if (table) {
|
|
305
|
-
const { $to } = selection;
|
|
306
|
-
|
|
307
|
-
const columResizePluginState = getPluginState(state) || {};
|
|
308
|
-
const isColumnResizing = Boolean(columResizePluginState?.isKeyboardResize);
|
|
309
|
-
if (
|
|
310
|
-
isSelectionAtEndOfTable($to, selection) &&
|
|
311
|
-
$to.parent.type.name === 'paragraph' &&
|
|
312
|
-
$to.depth === table.depth + 3 && // + 3 for: row, cell & paragraph nodes
|
|
313
|
-
!isColumnResizing
|
|
314
|
-
) {
|
|
315
|
-
// we have a text selection at end of last table cell, directly inside a top level paragraph,
|
|
316
|
-
// and want to set a full table cell selection
|
|
317
|
-
return selectFullTable(editorSelectionAPI)({
|
|
318
|
-
node: table.node,
|
|
319
|
-
startPos: table.start,
|
|
320
|
-
dir: TableSelectionDirection.TopToBottom,
|
|
321
|
-
})(state, dispatch);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return false;
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Sets a cell selection over all the cells in the table node
|
|
329
|
-
* We use this instead of selectTable from prosemirror-utils so we can control which
|
|
330
|
-
* cell is the anchor and which is the head, and also so we can set the relative selection
|
|
331
|
-
* pos in the selection plugin
|
|
332
|
-
*/
|
|
333
|
-
const selectFullTable =
|
|
334
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
335
|
-
({
|
|
336
|
-
node,
|
|
337
|
-
startPos,
|
|
338
|
-
dir,
|
|
339
|
-
}: {
|
|
340
|
-
node: PmNode;
|
|
341
|
-
startPos: number;
|
|
342
|
-
dir: TableSelectionDirection;
|
|
343
|
-
}): Command =>
|
|
344
|
-
(state, dispatch) => {
|
|
345
|
-
const { doc } = state;
|
|
346
|
-
const { map } = TableMap.get(node);
|
|
347
|
-
const $firstCell = doc.resolve(startPos + map[0]);
|
|
348
|
-
const $lastCell = doc.resolve(startPos + map[map.length - 1]);
|
|
349
|
-
|
|
350
|
-
let fullTableSelection: Selection;
|
|
351
|
-
let selectionRelativeToNode: RelativeSelectionPos;
|
|
352
|
-
if (dir === TableSelectionDirection.TopToBottom) {
|
|
353
|
-
// Ignored via go/ees005
|
|
354
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
355
|
-
fullTableSelection = new CellSelection($firstCell, $lastCell) as any;
|
|
356
|
-
selectionRelativeToNode = RelativeSelectionPos.End;
|
|
357
|
-
} else {
|
|
358
|
-
// Ignored via go/ees005
|
|
359
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
360
|
-
fullTableSelection = new CellSelection($lastCell, $firstCell) as any;
|
|
361
|
-
selectionRelativeToNode = RelativeSelectionPos.Start;
|
|
362
|
-
}
|
|
363
|
-
if (editorSelectionAPI) {
|
|
364
|
-
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
365
|
-
selectionRelativeToNode,
|
|
366
|
-
selection: fullTableSelection,
|
|
367
|
-
})(state);
|
|
368
|
-
|
|
369
|
-
if (dispatch) {
|
|
370
|
-
dispatch(tr);
|
|
371
|
-
return true;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
return false;
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
const setSelectionAtStartOfFirstCell =
|
|
378
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
379
|
-
(selection: CellSelection, selectionRelativeToNode?: RelativeSelectionPos): Command =>
|
|
380
|
-
(state, dispatch) => {
|
|
381
|
-
const { $anchorCell, $headCell } = selection;
|
|
382
|
-
const $firstCell = $anchorCell.pos < $headCell.pos ? $anchorCell : $headCell;
|
|
383
|
-
const $firstPosInsideCell = state.doc.resolve($firstCell.pos + 1);
|
|
384
|
-
|
|
385
|
-
// check if first pos should have a gap cursor, otherwise find closest text selection
|
|
386
|
-
const selectionAtStartOfCell = GapCursorSelection.valid($firstPosInsideCell)
|
|
387
|
-
? new GapCursorSelection($firstPosInsideCell, Side.LEFT)
|
|
388
|
-
: Selection.findFrom($firstPosInsideCell, 1);
|
|
389
|
-
|
|
390
|
-
if (editorSelectionAPI) {
|
|
391
|
-
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
392
|
-
selectionRelativeToNode,
|
|
393
|
-
selection: selectionAtStartOfCell,
|
|
394
|
-
})(state);
|
|
395
|
-
|
|
396
|
-
if (dispatch) {
|
|
397
|
-
dispatch(tr);
|
|
398
|
-
return true;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return false;
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
const setSelectionAtEndOfLastCell =
|
|
405
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
406
|
-
(selection: CellSelection, selectionRelativeToNode?: RelativeSelectionPos): Command =>
|
|
407
|
-
(state, dispatch) => {
|
|
408
|
-
const { $anchorCell, $headCell } = selection;
|
|
409
|
-
const $lastCell = $anchorCell.pos > $headCell.pos ? $anchorCell : $headCell;
|
|
410
|
-
const lastPosInsideCell =
|
|
411
|
-
$lastCell.pos + ($lastCell.nodeAfter ? $lastCell.nodeAfter.content.size : 0) + 1;
|
|
412
|
-
const $lastPosInsideCell = state.doc.resolve(lastPosInsideCell);
|
|
413
|
-
|
|
414
|
-
// check if last pos should have a gap cursor, otherwise find closest text selection
|
|
415
|
-
const selectionAtEndOfCell = GapCursorSelection.valid($lastPosInsideCell)
|
|
416
|
-
? new GapCursorSelection($lastPosInsideCell, Side.RIGHT)
|
|
417
|
-
: Selection.findFrom($lastPosInsideCell, -1);
|
|
418
|
-
|
|
419
|
-
if (editorSelectionAPI) {
|
|
420
|
-
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
421
|
-
selectionRelativeToNode,
|
|
422
|
-
selection: selectionAtEndOfCell,
|
|
423
|
-
})(state);
|
|
424
|
-
|
|
425
|
-
if (dispatch) {
|
|
426
|
-
dispatch(tr);
|
|
427
|
-
return true;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
return false;
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
const setGapCursorBeforeTable =
|
|
434
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
435
|
-
(): Command =>
|
|
436
|
-
(state, dispatch) => {
|
|
437
|
-
const table = findTable(state.selection);
|
|
438
|
-
if (table) {
|
|
439
|
-
const $beforeTablePos = state.doc.resolve(table.pos);
|
|
440
|
-
if (GapCursorSelection.valid($beforeTablePos)) {
|
|
441
|
-
const selectionBeforeTable = new GapCursorSelection($beforeTablePos, Side.LEFT);
|
|
442
|
-
if (editorSelectionAPI) {
|
|
443
|
-
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
444
|
-
selectionRelativeToNode: undefined,
|
|
445
|
-
selection: selectionBeforeTable,
|
|
446
|
-
})(state);
|
|
447
|
-
|
|
448
|
-
if (dispatch) {
|
|
449
|
-
dispatch(tr);
|
|
450
|
-
return true;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return false;
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
const setGapCursorAfterTable =
|
|
459
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
460
|
-
(): Command =>
|
|
461
|
-
(state, dispatch) => {
|
|
462
|
-
const table = findTable(state.selection);
|
|
463
|
-
if (table) {
|
|
464
|
-
const $afterTablePos = state.doc.resolve(table.pos + table.node.nodeSize);
|
|
465
|
-
if (GapCursorSelection.valid($afterTablePos)) {
|
|
466
|
-
const selectionAfterTable = new GapCursorSelection($afterTablePos, Side.RIGHT);
|
|
467
|
-
|
|
468
|
-
if (editorSelectionAPI) {
|
|
469
|
-
const tr = editorSelectionAPI.actions.selectNearNode({
|
|
470
|
-
selectionRelativeToNode: undefined,
|
|
471
|
-
selection: selectionAfterTable,
|
|
472
|
-
})(state);
|
|
473
|
-
|
|
474
|
-
if (dispatch) {
|
|
475
|
-
dispatch(tr);
|
|
476
|
-
return true;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
return false;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return false;
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
const isSelectionAtStartOfTable = ($pos: ResolvedPos, selection: Selection) =>
|
|
486
|
-
isSelectionAtStartOfNode($pos, findTable(selection)?.node);
|
|
487
|
-
|
|
488
|
-
const isSelectionAtEndOfTable = ($pos: ResolvedPos, selection: Selection) =>
|
|
489
|
-
isSelectionAtEndOfNode($pos, findTable(selection)?.node);
|
|
490
|
-
|
|
491
|
-
export const shiftArrowUpFromTable =
|
|
492
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
493
|
-
(): Command =>
|
|
494
|
-
(state, dispatch) => {
|
|
495
|
-
const { selection } = state;
|
|
496
|
-
const table = findTable(selection);
|
|
497
|
-
const selectionRect = getClosestSelectionRect(state);
|
|
498
|
-
const index = selectionRect?.top;
|
|
499
|
-
if (table && index === 0) {
|
|
500
|
-
return selectFullTable(editorSelectionAPI)({
|
|
501
|
-
node: table.node,
|
|
502
|
-
startPos: table.start,
|
|
503
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
504
|
-
})(state, dispatch);
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return false;
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
export const modASelectTable =
|
|
511
|
-
(editorSelectionAPI: ExtractInjectionAPI<typeof tablePlugin>['selection'] | undefined) =>
|
|
512
|
-
(): Command =>
|
|
513
|
-
(state, dispatch) => {
|
|
514
|
-
const { selection } = state;
|
|
515
|
-
const table = findTable(selection);
|
|
516
|
-
|
|
517
|
-
if (!table) {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
const { $from, $to } = selection;
|
|
521
|
-
|
|
522
|
-
const tableSelected = isTableSelected(selection);
|
|
523
|
-
|
|
524
|
-
if (
|
|
525
|
-
!tableSelected &&
|
|
526
|
-
$from.pos > table.start + 1 &&
|
|
527
|
-
$to.pos < table.start + table.node.nodeSize
|
|
528
|
-
) {
|
|
529
|
-
return selectFullTable(editorSelectionAPI)({
|
|
530
|
-
node: table.node,
|
|
531
|
-
startPos: table.start,
|
|
532
|
-
dir: TableSelectionDirection.BottomToTop,
|
|
533
|
-
})(state, dispatch);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
return false;
|
|
537
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type { CardAttributes, DataType, UrlType } from '@atlaskit/adf-schema';
|
|
2
|
-
import { TableSortOrder as SortOrder, TableSortStep } from '@atlaskit/custom-steps';
|
|
3
|
-
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
|
-
import { createCompareNodes } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
6
|
-
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
9
|
-
import {
|
|
10
|
-
convertArrayOfRowsToTableNode,
|
|
11
|
-
convertTableNodeToArrayOfRows,
|
|
12
|
-
findCellRectClosestToPos,
|
|
13
|
-
findTable,
|
|
14
|
-
getSelectionRect,
|
|
15
|
-
isSelectionType,
|
|
16
|
-
} from '@atlaskit/editor-tables/utils';
|
|
17
|
-
|
|
18
|
-
import type { TablePluginState } from '../../types';
|
|
19
|
-
import { createCommand, getPluginState } from '../plugin-factory';
|
|
20
|
-
|
|
21
|
-
const createGetInlineCardTextFromStore = (attrs: CardAttributes): string | null => {
|
|
22
|
-
const { data } = attrs as DataType;
|
|
23
|
-
// Ignored via go/ees005
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
if (data && ((data as any).name || (data as any).title)) {
|
|
26
|
-
// Ignored via go/ees005
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
-
return (data as any).name || (data as any).title;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { url: cardUrl } = attrs as UrlType;
|
|
32
|
-
return cardUrl;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const sortByColumn = (columnIndex: number, order: SortOrder = SortOrder.DESC): Command =>
|
|
36
|
-
createCommand(
|
|
37
|
-
() => ({
|
|
38
|
-
type: 'SORT_TABLE',
|
|
39
|
-
data: {
|
|
40
|
-
ordering: {
|
|
41
|
-
columnIndex,
|
|
42
|
-
order,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}),
|
|
46
|
-
(tr: Transaction, state: EditorState) => {
|
|
47
|
-
// Ignored via go/ees005
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
49
|
-
const table = findTable(tr.selection)!;
|
|
50
|
-
if (!table || !table.node) {
|
|
51
|
-
return tr;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const selectionRect = isSelectionType(tr.selection, 'cell')
|
|
55
|
-
? // Ignored via go/ees005
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
57
|
-
getSelectionRect(tr.selection)!
|
|
58
|
-
: findCellRectClosestToPos(tr.selection.$from);
|
|
59
|
-
|
|
60
|
-
if (!selectionRect) {
|
|
61
|
-
return tr;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const tablePluginState: TablePluginState = getPluginState(state);
|
|
65
|
-
const tableArray = convertTableNodeToArrayOfRows(table.node);
|
|
66
|
-
|
|
67
|
-
let headerRow;
|
|
68
|
-
if (tablePluginState.isHeaderRowEnabled) {
|
|
69
|
-
headerRow = tableArray.shift();
|
|
70
|
-
}
|
|
71
|
-
const compareNodesInOrder = createCompareNodes(
|
|
72
|
-
{
|
|
73
|
-
getInlineCardTextFromStore: createGetInlineCardTextFromStore,
|
|
74
|
-
},
|
|
75
|
-
order,
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const sortedTable = tableArray.sort(
|
|
79
|
-
(rowA: Array<PMNode | null>, rowB: Array<PMNode | null>) =>
|
|
80
|
-
compareNodesInOrder(rowA[columnIndex], rowB[columnIndex]),
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
if (headerRow) {
|
|
84
|
-
sortedTable.unshift(headerRow);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const newTableNode = convertArrayOfRowsToTableNode(table.node, sortedTable);
|
|
88
|
-
|
|
89
|
-
tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTableNode);
|
|
90
|
-
|
|
91
|
-
const pos = TableMap.get(table.node).positionAt(selectionRect.top, columnIndex, table.node);
|
|
92
|
-
|
|
93
|
-
const prev = tablePluginState.ordering;
|
|
94
|
-
const next = {
|
|
95
|
-
columnIndex,
|
|
96
|
-
order,
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
tr.step(new TableSortStep(table.pos, prev, next));
|
|
100
|
-
return tr.setSelection(Selection.near(tr.doc.resolve(table.start + pos)));
|
|
101
|
-
},
|
|
102
|
-
);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { splitCellWithType } from '@atlaskit/editor-tables/utils';
|
|
3
|
-
|
|
4
|
-
import type { TablePluginState } from '../../types';
|
|
5
|
-
import { getPluginState } from '../plugin-factory';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* We need to split cell keeping the right type of cell given current table configuration.
|
|
9
|
-
* We are using editor-tables splitCellWithType that allows you to choose what cell type should be.
|
|
10
|
-
*/
|
|
11
|
-
export const splitCell: Command = (state, dispatch) => {
|
|
12
|
-
const tableState: TablePluginState = getPluginState(state);
|
|
13
|
-
const { tableHeader, tableCell } = state.schema.nodes;
|
|
14
|
-
if (dispatch) {
|
|
15
|
-
return splitCellWithType(({ row, col }: { row: number; col: number }) => {
|
|
16
|
-
if (
|
|
17
|
-
(row === 0 && tableState.isHeaderRowEnabled) ||
|
|
18
|
-
(col === 0 && tableState.isHeaderColumnEnabled)
|
|
19
|
-
) {
|
|
20
|
-
return tableHeader;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return tableCell;
|
|
24
|
-
})(state, dispatch);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return true;
|
|
28
|
-
};
|