@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,672 +0,0 @@
|
|
|
1
|
-
import { createElement } from 'react';
|
|
2
|
-
|
|
3
|
-
import { RawIntlProvider } from 'react-intl-next';
|
|
4
|
-
import type { IntlShape } from 'react-intl-next';
|
|
5
|
-
import uuid from 'uuid/v4';
|
|
6
|
-
|
|
7
|
-
import type { CellAttributes } from '@atlaskit/adf-schema';
|
|
8
|
-
import { type PortalProviderAPI } from '@atlaskit/editor-common/portal';
|
|
9
|
-
import { nonNullable } from '@atlaskit/editor-common/utils';
|
|
10
|
-
import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
|
|
11
|
-
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
12
|
-
import type {
|
|
13
|
-
ReadonlyTransaction,
|
|
14
|
-
Selection,
|
|
15
|
-
Transaction,
|
|
16
|
-
} from '@atlaskit/editor-prosemirror/state';
|
|
17
|
-
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
18
|
-
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
19
|
-
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
20
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
21
|
-
import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
|
|
22
|
-
|
|
23
|
-
import type { Cell, CellColumnPositioning } from '../../types';
|
|
24
|
-
import { TableCssClassName as ClassName, TableDecorations } from '../../types';
|
|
25
|
-
import { ColumnResizeWidget } from '../../ui/ColumnResizeWidget';
|
|
26
|
-
|
|
27
|
-
const filterDecorationByKey = (key: TableDecorations, decorationSet: DecorationSet): Decoration[] =>
|
|
28
|
-
decorationSet.find(undefined, undefined, (spec) => spec.key.indexOf(key) > -1);
|
|
29
|
-
|
|
30
|
-
export const findColumnControlSelectedDecoration = (decorationSet: DecorationSet): Decoration[] =>
|
|
31
|
-
filterDecorationByKey(TableDecorations.COLUMN_SELECTED, decorationSet);
|
|
32
|
-
|
|
33
|
-
export const findControlsHoverDecoration = (decorationSet: DecorationSet): Decoration[] =>
|
|
34
|
-
filterDecorationByKey(TableDecorations.ALL_CONTROLS_HOVER, decorationSet);
|
|
35
|
-
|
|
36
|
-
export const createCellHoverDecoration = (cells: Cell[]): Decoration[] =>
|
|
37
|
-
cells.map((cell) =>
|
|
38
|
-
Decoration.node(
|
|
39
|
-
cell.pos,
|
|
40
|
-
cell.pos + cell.node.nodeSize,
|
|
41
|
-
{
|
|
42
|
-
class: ClassName.HOVERED_CELL_WARNING,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
key: TableDecorations.CELL_CONTROLS_HOVER,
|
|
46
|
-
},
|
|
47
|
-
),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
export const createControlsHoverDecoration = (
|
|
51
|
-
cells: Cell[],
|
|
52
|
-
type: 'row' | 'column' | 'table',
|
|
53
|
-
tr: Transaction | ReadonlyTransaction,
|
|
54
|
-
isDragAndDropEnable: boolean | undefined,
|
|
55
|
-
hoveredIndexes: number[],
|
|
56
|
-
danger?: boolean,
|
|
57
|
-
selected?: boolean,
|
|
58
|
-
): Decoration[] => {
|
|
59
|
-
const table = findTable(tr.selection);
|
|
60
|
-
if (!table) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const map = TableMap.get(table.node);
|
|
65
|
-
const [min, max] = cells.reduce<[number | null, number | null]>(
|
|
66
|
-
([min, max], cell) => {
|
|
67
|
-
if (min === null || cell.pos < min) {
|
|
68
|
-
min = cell.pos;
|
|
69
|
-
}
|
|
70
|
-
if (max === null || cell.pos > max) {
|
|
71
|
-
max = cell.pos;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return [min, max];
|
|
75
|
-
},
|
|
76
|
-
[null, null],
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (min === null || max === null) {
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let updatedCells: number[] = cells.map((x) => x.pos);
|
|
84
|
-
|
|
85
|
-
// ED-15246 fixed trello card table overflow issue
|
|
86
|
-
// If columns / rows have been merged the hovered selection is different to the actual selection
|
|
87
|
-
// So If the table cells are in danger we want to create a "rectangle" selection
|
|
88
|
-
// to match the "clicked" selection
|
|
89
|
-
|
|
90
|
-
if (danger && type !== 'table') {
|
|
91
|
-
const { selection } = tr;
|
|
92
|
-
const table = findTable(selection);
|
|
93
|
-
const rect = getSelectionRect(selection);
|
|
94
|
-
|
|
95
|
-
if (table && rect) {
|
|
96
|
-
updatedCells = map.cellsInRect(rect).map((x) => x + table.start);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return updatedCells.map((pos) => {
|
|
101
|
-
const cell = tr.doc.nodeAt(pos);
|
|
102
|
-
|
|
103
|
-
const classes = [ClassName.HOVERED_CELL];
|
|
104
|
-
if (danger) {
|
|
105
|
-
classes.push(ClassName.HOVERED_CELL_IN_DANGER);
|
|
106
|
-
}
|
|
107
|
-
if (selected) {
|
|
108
|
-
classes.push(ClassName.SELECTED_CELL);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (isDragAndDropEnable) {
|
|
112
|
-
if (type === 'column' || type === 'row') {
|
|
113
|
-
classes.pop();
|
|
114
|
-
classes.push(ClassName.HOVERED_NO_HIGHLIGHT);
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
classes.push(
|
|
118
|
-
type === 'column'
|
|
119
|
-
? ClassName.HOVERED_COLUMN
|
|
120
|
-
: type === 'row'
|
|
121
|
-
? ClassName.HOVERED_ROW
|
|
122
|
-
: ClassName.HOVERED_TABLE,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let key: TableDecorations;
|
|
127
|
-
switch (type) {
|
|
128
|
-
case 'row':
|
|
129
|
-
key = TableDecorations.ROW_CONTROLS_HOVER;
|
|
130
|
-
break;
|
|
131
|
-
|
|
132
|
-
case 'column':
|
|
133
|
-
key = TableDecorations.COLUMN_CONTROLS_HOVER;
|
|
134
|
-
break;
|
|
135
|
-
|
|
136
|
-
default:
|
|
137
|
-
key = TableDecorations.TABLE_CONTROLS_HOVER;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return Decoration.node(
|
|
142
|
-
pos,
|
|
143
|
-
// Ignored via go/ees005
|
|
144
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
145
|
-
pos + cell!.nodeSize,
|
|
146
|
-
{
|
|
147
|
-
class: classes.join(' '),
|
|
148
|
-
},
|
|
149
|
-
{ key },
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
export const createColumnSelectedDecoration = (
|
|
155
|
-
tr: Transaction | ReadonlyTransaction,
|
|
156
|
-
): Decoration[] => {
|
|
157
|
-
const { selection, doc } = tr;
|
|
158
|
-
const table = findTable(selection);
|
|
159
|
-
const rect = getSelectionRect(selection);
|
|
160
|
-
|
|
161
|
-
if (!table || !rect) {
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const map = TableMap.get(table.node);
|
|
166
|
-
const cellPositions = map.cellsInRect(rect);
|
|
167
|
-
|
|
168
|
-
return cellPositions.map((pos, index) => {
|
|
169
|
-
const cell = doc.nodeAt(pos + table.start);
|
|
170
|
-
|
|
171
|
-
return Decoration.node(
|
|
172
|
-
pos + table.start,
|
|
173
|
-
// Ignored via go/ees005
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
175
|
-
pos + table.start + cell!.nodeSize,
|
|
176
|
-
{
|
|
177
|
-
class: ClassName.COLUMN_SELECTED,
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
key: `${TableDecorations.COLUMN_SELECTED}_${index}`,
|
|
181
|
-
},
|
|
182
|
-
);
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
export const createColumnControlsDecoration = (selection: Selection): Decoration[] => {
|
|
187
|
-
const cells: ContentNodeWithPos[] = getCellsInRow(0)(selection) || [];
|
|
188
|
-
|
|
189
|
-
let index = 0;
|
|
190
|
-
return cells.map((cell) => {
|
|
191
|
-
const colspan = (cell.node.attrs as CellAttributes).colspan || 1;
|
|
192
|
-
// It's important these values are scoped locally as the widget callback could be executed anytime in the future
|
|
193
|
-
// and we want to avoid value leak
|
|
194
|
-
const startIndex = index;
|
|
195
|
-
const endIndex = startIndex + colspan;
|
|
196
|
-
|
|
197
|
-
// The next cell start index will commence from the current cell end index.
|
|
198
|
-
index = endIndex;
|
|
199
|
-
|
|
200
|
-
return Decoration.widget(
|
|
201
|
-
cell.pos + 1,
|
|
202
|
-
() => {
|
|
203
|
-
const element = document.createElement('div');
|
|
204
|
-
element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
|
|
205
|
-
element.dataset.startIndex = `${startIndex}`;
|
|
206
|
-
element.dataset.endIndex = `${endIndex}`;
|
|
207
|
-
return element;
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
|
|
211
|
-
// this decoration should be the first one, even before gap cursor.
|
|
212
|
-
side: -100,
|
|
213
|
-
},
|
|
214
|
-
);
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export const updateDecorations = (
|
|
219
|
-
node: PmNode,
|
|
220
|
-
decorationSet: DecorationSet,
|
|
221
|
-
decorations: Decoration[],
|
|
222
|
-
key: TableDecorations,
|
|
223
|
-
): DecorationSet => {
|
|
224
|
-
const filteredDecorations = filterDecorationByKey(key, decorationSet);
|
|
225
|
-
const decorationSetFiltered = decorationSet.remove(filteredDecorations);
|
|
226
|
-
return decorationSetFiltered.add(node, decorations);
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const makeArray = (n: number) => Array.from(Array(n).keys());
|
|
230
|
-
|
|
231
|
-
/*
|
|
232
|
-
* This function will create two specific decorations for each cell in a column index target,
|
|
233
|
-
* for example given that table:
|
|
234
|
-
*
|
|
235
|
-
* ```
|
|
236
|
-
* 0 1 2 3
|
|
237
|
-
* _____________________ _______
|
|
238
|
-
* | | | |
|
|
239
|
-
* | B1 | C1 | A1 |
|
|
240
|
-
* |______|______ ______|______|
|
|
241
|
-
* | | | |
|
|
242
|
-
* | B2 | | A2 |
|
|
243
|
-
* |______ ______| |______|
|
|
244
|
-
* | | | D1 | |
|
|
245
|
-
* | B3 | C2 | | A3 |
|
|
246
|
-
* |______|______|______|______|
|
|
247
|
-
* ^ ^ ^ ^
|
|
248
|
-
* | | | |
|
|
249
|
-
* | | | |
|
|
250
|
-
* | | | |
|
|
251
|
-
* 0 1 3 4
|
|
252
|
-
* \ | | /
|
|
253
|
-
* \ | | /
|
|
254
|
-
* \ | | /
|
|
255
|
-
* \ | | /
|
|
256
|
-
* \ | | /
|
|
257
|
-
* columnEndIndexTarget === CellColumnPositioning.right
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
* When a user wants to resize a cell,
|
|
261
|
-
* they need to grab and hold the end of that column,
|
|
262
|
-
* and this will be the `columnEndIndexTarget` using
|
|
263
|
-
* the CellColumnPositioning interface.
|
|
264
|
-
*
|
|
265
|
-
* Let's say the `columnEndIndexTarget.right` is 3,
|
|
266
|
-
* so this function will return two types of decorations for each cell on that column,
|
|
267
|
-
* that means 2 `resizerHandle` and 2 `lastCellElement`,
|
|
268
|
-
* here is the explanation for each one of them :
|
|
269
|
-
*
|
|
270
|
-
* - resizerHandle:
|
|
271
|
-
*
|
|
272
|
-
* Given the cell C1, this decoration will add a div to create this area
|
|
273
|
-
* ```
|
|
274
|
-
* ▁▁▁▁▁▁▁▁▁▁▁▁▁
|
|
275
|
-
* | ▒▒|
|
|
276
|
-
* | C1 ▒▒|
|
|
277
|
-
* | ▒▒|
|
|
278
|
-
* ▔▔▔▔▔▔▔▔▔▔▔▔▔
|
|
279
|
-
* ```
|
|
280
|
-
* This ▒ represents the area where table resizing will start,
|
|
281
|
-
* and you can follow that using checking the class name `ClassName.RESIZE_HANDLE_DECORATION` on the code
|
|
282
|
-
*
|
|
283
|
-
* - lastCellElementDecoration
|
|
284
|
-
*
|
|
285
|
-
* Given the content of the cell C1
|
|
286
|
-
* ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
|
|
287
|
-
* | |
|
|
288
|
-
* | _____________ |
|
|
289
|
-
* | | | |
|
|
290
|
-
* | | <p> | |
|
|
291
|
-
* | |_____________| |
|
|
292
|
-
* | |
|
|
293
|
-
* | _____________ |
|
|
294
|
-
* | | | |
|
|
295
|
-
* | | <media> | |
|
|
296
|
-
* | |_____________| |
|
|
297
|
-
* | |
|
|
298
|
-
* | _____________ |
|
|
299
|
-
* | | | |
|
|
300
|
-
* | | <media> | |
|
|
301
|
-
* | |_____________| |
|
|
302
|
-
* | |
|
|
303
|
-
* ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
|
|
304
|
-
* Currently, we are removing the margin-bottom from the last media using this kind of CSS rule:
|
|
305
|
-
* `div:last-of-type`; This is quite unstable, and after we create the `resizerHandle` div,
|
|
306
|
-
* that logic will apply the margin in the wrong element, to avoid that,
|
|
307
|
-
* we will add a new class on the last item for each cell,
|
|
308
|
-
* hence the second media will receive this class `ClassName.LAST_ITEM_IN_CELL`
|
|
309
|
-
*/
|
|
310
|
-
export const createResizeHandleDecoration = (
|
|
311
|
-
tr: Transaction | ReadonlyTransaction,
|
|
312
|
-
rowIndexTarget: number,
|
|
313
|
-
columnEndIndexTarget: Omit<CellColumnPositioning, 'left'>,
|
|
314
|
-
includeTooltip: boolean = false,
|
|
315
|
-
getIntl: () => IntlShape,
|
|
316
|
-
nodeViewPortalProviderAPI: PortalProviderAPI,
|
|
317
|
-
): [Decoration[], Decoration[]] => {
|
|
318
|
-
const emptyResult: [Decoration[], Decoration[]] = [[], []];
|
|
319
|
-
const table = findTable(tr.selection);
|
|
320
|
-
if (!table || !table.node) {
|
|
321
|
-
return emptyResult;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
const map = TableMap.get(table.node);
|
|
325
|
-
if (!map.width) {
|
|
326
|
-
return emptyResult;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const createResizerHandleDecoration = (
|
|
330
|
-
cellColumnPositioning: CellColumnPositioning,
|
|
331
|
-
columnIndex: number,
|
|
332
|
-
rowIndex: number,
|
|
333
|
-
cellPos: number,
|
|
334
|
-
cellNode: PmNode,
|
|
335
|
-
): Decoration => {
|
|
336
|
-
const decorationRenderKey = uuid();
|
|
337
|
-
const position = cellPos + cellNode.nodeSize - 1;
|
|
338
|
-
return Decoration.widget(
|
|
339
|
-
position,
|
|
340
|
-
() => {
|
|
341
|
-
const element = document.createElement('div');
|
|
342
|
-
nodeViewPortalProviderAPI.render(
|
|
343
|
-
() =>
|
|
344
|
-
createElement(
|
|
345
|
-
RawIntlProvider,
|
|
346
|
-
{ value: getIntl() },
|
|
347
|
-
createElement(ColumnResizeWidget, {
|
|
348
|
-
startIndex: cellColumnPositioning.left,
|
|
349
|
-
endIndex: cellColumnPositioning.right,
|
|
350
|
-
includeTooltip,
|
|
351
|
-
}),
|
|
352
|
-
),
|
|
353
|
-
element,
|
|
354
|
-
decorationRenderKey,
|
|
355
|
-
);
|
|
356
|
-
return element;
|
|
357
|
-
},
|
|
358
|
-
{
|
|
359
|
-
key: `${
|
|
360
|
-
TableDecorations.COLUMN_RESIZING_HANDLE_WIDGET
|
|
361
|
-
}_${rowIndex}_${columnIndex}_${includeTooltip ? 'with' : 'no'}-tooltip`,
|
|
362
|
-
destroy: (node) => {
|
|
363
|
-
nodeViewPortalProviderAPI.remove(decorationRenderKey);
|
|
364
|
-
},
|
|
365
|
-
},
|
|
366
|
-
);
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const createLastCellElementDecoration = (
|
|
370
|
-
cellColumnPositioning: CellColumnPositioning,
|
|
371
|
-
cellPos: number,
|
|
372
|
-
cellNode: PmNode,
|
|
373
|
-
): Decoration | null => {
|
|
374
|
-
let lastItemPositions: { from: number; to: number } | undefined;
|
|
375
|
-
cellNode.forEach((childNode, offset, index) => {
|
|
376
|
-
if (index === cellNode.childCount - 1) {
|
|
377
|
-
const from = offset + cellPos + 1;
|
|
378
|
-
lastItemPositions = {
|
|
379
|
-
from,
|
|
380
|
-
to: from + childNode.nodeSize,
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
if (!lastItemPositions) {
|
|
386
|
-
return null;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return Decoration.node(
|
|
390
|
-
lastItemPositions.from,
|
|
391
|
-
lastItemPositions.to,
|
|
392
|
-
{
|
|
393
|
-
class: ClassName.LAST_ITEM_IN_CELL,
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
key: `${TableDecorations.LAST_CELL_ELEMENT}_${cellColumnPositioning.left}_${cellColumnPositioning.right}`,
|
|
397
|
-
},
|
|
398
|
-
);
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
const resizeHandleCellDecorations: Decoration[] = [];
|
|
402
|
-
const lastCellElementsDecorations: Array<Decoration | null> = [];
|
|
403
|
-
|
|
404
|
-
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
405
|
-
const seen: { [key: number]: boolean } = {};
|
|
406
|
-
|
|
407
|
-
if (rowIndex !== rowIndexTarget) {
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
412
|
-
const cellPosition = map.map[map.width * rowIndex + columnIndex];
|
|
413
|
-
if (seen[cellPosition]) {
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
seen[cellPosition] = true;
|
|
418
|
-
const cellPos = table.start + cellPosition;
|
|
419
|
-
const cell = tr.doc.nodeAt(cellPos);
|
|
420
|
-
if (!cell) {
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
const colspan = (cell.attrs as CellAttributes).colspan || 1;
|
|
424
|
-
const startIndex = columnIndex;
|
|
425
|
-
const endIndex = colspan + startIndex;
|
|
426
|
-
|
|
427
|
-
if (endIndex !== columnEndIndexTarget.right) {
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const resizerHandleDec = createResizerHandleDecoration(
|
|
432
|
-
{ left: startIndex, right: endIndex },
|
|
433
|
-
columnIndex,
|
|
434
|
-
rowIndex,
|
|
435
|
-
cellPos,
|
|
436
|
-
cell,
|
|
437
|
-
);
|
|
438
|
-
const lastCellDec = createLastCellElementDecoration(
|
|
439
|
-
{ left: startIndex, right: endIndex },
|
|
440
|
-
cellPos,
|
|
441
|
-
cell,
|
|
442
|
-
);
|
|
443
|
-
|
|
444
|
-
resizeHandleCellDecorations.push(resizerHandleDec);
|
|
445
|
-
lastCellElementsDecorations.push(lastCellDec);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
return [resizeHandleCellDecorations, lastCellElementsDecorations.filter(nonNullable)];
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
/*
|
|
453
|
-
* This function will create a decoration for each cell using the right position on the CellColumnPositioning
|
|
454
|
-
* for example given that table:
|
|
455
|
-
*
|
|
456
|
-
* ```
|
|
457
|
-
* 0 1 2 3 <--- column indexes
|
|
458
|
-
* _____________________ _______
|
|
459
|
-
* | | | |
|
|
460
|
-
* | B1 | C1 | A1 |
|
|
461
|
-
* |______|______ ______|______|
|
|
462
|
-
* | | | |
|
|
463
|
-
* | B2 | D1 | A2 |
|
|
464
|
-
* |______ ______|______|______|
|
|
465
|
-
* | | | |
|
|
466
|
-
* | B3 | C2 | D2 |
|
|
467
|
-
* |______|______|_____________|
|
|
468
|
-
* ```
|
|
469
|
-
*
|
|
470
|
-
* and given the left and right represents the C1 cell:
|
|
471
|
-
*
|
|
472
|
-
* ```
|
|
473
|
-
* left right
|
|
474
|
-
* 1 3
|
|
475
|
-
* | |
|
|
476
|
-
* | |
|
|
477
|
-
* | |
|
|
478
|
-
* _______∨_____________∨_______
|
|
479
|
-
* | | | |
|
|
480
|
-
* | B1 | C1 | A1 |
|
|
481
|
-
* |______|______ ______|______|
|
|
482
|
-
* | | | |
|
|
483
|
-
* | B2 | D1 | A2 |
|
|
484
|
-
* |______ ______|______|______|
|
|
485
|
-
* | | | |
|
|
486
|
-
* | B3 | C2 | D2 |
|
|
487
|
-
* |______|______|_____________|
|
|
488
|
-
* ```
|
|
489
|
-
*
|
|
490
|
-
* Taking that table, and the right as parameters,
|
|
491
|
-
* this function will return two decorations applying a new class `ClassName.WITH_RESIZE_LINE`
|
|
492
|
-
* only on the cells: `C1` and `D1`.
|
|
493
|
-
*/
|
|
494
|
-
export const createColumnLineResize = (
|
|
495
|
-
selection: Selection,
|
|
496
|
-
cellColumnPositioning: Omit<CellColumnPositioning, 'left'>,
|
|
497
|
-
isDragAndDropEnabled?: boolean,
|
|
498
|
-
): Decoration[] => {
|
|
499
|
-
const table = findTable(selection);
|
|
500
|
-
if (!table || cellColumnPositioning.right === null) {
|
|
501
|
-
return [];
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
let columnIndex = cellColumnPositioning.right;
|
|
505
|
-
const map = TableMap.get(table.node);
|
|
506
|
-
|
|
507
|
-
const isLastColumn = columnIndex === map.width;
|
|
508
|
-
if (isLastColumn) {
|
|
509
|
-
columnIndex -= 1;
|
|
510
|
-
}
|
|
511
|
-
const decorationClassName = isDragAndDropEnabled
|
|
512
|
-
? isLastColumn
|
|
513
|
-
? ClassName.WITH_DRAG_RESIZE_LINE_LAST_COLUMN
|
|
514
|
-
: ClassName.WITH_DRAG_RESIZE_LINE
|
|
515
|
-
: isLastColumn
|
|
516
|
-
? ClassName.WITH_RESIZE_LINE_LAST_COLUMN
|
|
517
|
-
: ClassName.WITH_RESIZE_LINE;
|
|
518
|
-
|
|
519
|
-
const cellPositions = makeArray(map.height)
|
|
520
|
-
.map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
|
|
521
|
-
.filter((cellPosition, rowIndex) => {
|
|
522
|
-
if (isLastColumn) {
|
|
523
|
-
return true; // If is the last column no filter applied
|
|
524
|
-
}
|
|
525
|
-
const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
|
|
526
|
-
return cellPosition !== nextPosition; // Removed it if next position is merged
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
const cells = cellPositions.map((pos) => ({
|
|
530
|
-
pos: pos + table.start,
|
|
531
|
-
node: table.node.nodeAt(pos),
|
|
532
|
-
}));
|
|
533
|
-
|
|
534
|
-
return cells
|
|
535
|
-
.map((cell, index) => {
|
|
536
|
-
if (!cell || !cell.node) {
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
return Decoration.node(
|
|
541
|
-
cell.pos,
|
|
542
|
-
cell.pos + cell.node.nodeSize,
|
|
543
|
-
{
|
|
544
|
-
class: decorationClassName,
|
|
545
|
-
},
|
|
546
|
-
{
|
|
547
|
-
key: `${TableDecorations.COLUMN_RESIZING_HANDLE_LINE}_${cellColumnPositioning.right}_${index}`,
|
|
548
|
-
},
|
|
549
|
-
);
|
|
550
|
-
})
|
|
551
|
-
.filter(nonNullable);
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
export const createColumnInsertLine = (
|
|
555
|
-
columnIndex: number,
|
|
556
|
-
selection: Selection,
|
|
557
|
-
hasMergedCells: boolean,
|
|
558
|
-
): Decoration[] => {
|
|
559
|
-
const table = findTable(selection);
|
|
560
|
-
if (!table) {
|
|
561
|
-
return [];
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
const map = TableMap.get(table.node);
|
|
565
|
-
|
|
566
|
-
const isFirstColumn = columnIndex === 0;
|
|
567
|
-
const isLastColumn = columnIndex === map.width;
|
|
568
|
-
if (isLastColumn) {
|
|
569
|
-
columnIndex -= 1;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
let decorationClassName: string;
|
|
573
|
-
if (hasMergedCells) {
|
|
574
|
-
decorationClassName = isFirstColumn
|
|
575
|
-
? ClassName.WITH_FIRST_COLUMN_INSERT_LINE_INACTIVE
|
|
576
|
-
: isLastColumn
|
|
577
|
-
? ClassName.WITH_LAST_COLUMN_INSERT_LINE_INACTIVE
|
|
578
|
-
: ClassName.WITH_COLUMN_INSERT_LINE_INACTIVE;
|
|
579
|
-
} else {
|
|
580
|
-
decorationClassName = isFirstColumn
|
|
581
|
-
? ClassName.WITH_FIRST_COLUMN_INSERT_LINE
|
|
582
|
-
: isLastColumn
|
|
583
|
-
? ClassName.WITH_LAST_COLUMN_INSERT_LINE
|
|
584
|
-
: ClassName.WITH_COLUMN_INSERT_LINE;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
const cellPositions = makeArray(map.height)
|
|
588
|
-
.map((rowIndex) => map.map[map.width * rowIndex + columnIndex])
|
|
589
|
-
.filter((cellPosition, rowIndex) => {
|
|
590
|
-
if (isLastColumn) {
|
|
591
|
-
return true; // If is the last column no filter applied
|
|
592
|
-
}
|
|
593
|
-
const nextPosition = map.map[map.width * rowIndex + columnIndex - 1];
|
|
594
|
-
return cellPosition !== nextPosition; // Removed it if next position is merged
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
const cells = cellPositions.map((pos) => ({
|
|
598
|
-
pos: pos + table.start,
|
|
599
|
-
node: table.node.nodeAt(pos),
|
|
600
|
-
}));
|
|
601
|
-
|
|
602
|
-
return cells
|
|
603
|
-
.map((cell, index) => {
|
|
604
|
-
if (!cell || !cell.node) {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
return Decoration.node(
|
|
609
|
-
cell.pos,
|
|
610
|
-
cell.pos + cell.node.nodeSize,
|
|
611
|
-
{
|
|
612
|
-
class: decorationClassName,
|
|
613
|
-
},
|
|
614
|
-
{
|
|
615
|
-
key: `${TableDecorations.COLUMN_INSERT_LINE}_${index}`,
|
|
616
|
-
},
|
|
617
|
-
);
|
|
618
|
-
})
|
|
619
|
-
.filter(nonNullable);
|
|
620
|
-
};
|
|
621
|
-
|
|
622
|
-
export const createRowInsertLine = (
|
|
623
|
-
rowIndex: number,
|
|
624
|
-
selection: Selection,
|
|
625
|
-
hasMergedCells: boolean,
|
|
626
|
-
): Decoration[] => {
|
|
627
|
-
const table = findTable(selection);
|
|
628
|
-
if (!table) {
|
|
629
|
-
return [];
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
const map = TableMap.get(table.node);
|
|
633
|
-
const isLastRow = rowIndex === map.height;
|
|
634
|
-
if (isLastRow) {
|
|
635
|
-
rowIndex -= 1;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
const cells = getCellsInRow(rowIndex)(selection);
|
|
639
|
-
if (!cells) {
|
|
640
|
-
return [];
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
let decorationClassName: string;
|
|
644
|
-
if (hasMergedCells) {
|
|
645
|
-
decorationClassName = isLastRow
|
|
646
|
-
? ClassName.WITH_LAST_ROW_INSERT_LINE_INACTIVE
|
|
647
|
-
: ClassName.WITH_ROW_INSERT_LINE_INACTIVE;
|
|
648
|
-
} else {
|
|
649
|
-
decorationClassName = isLastRow
|
|
650
|
-
? ClassName.WITH_LAST_ROW_INSERT_LINE
|
|
651
|
-
: ClassName.WITH_ROW_INSERT_LINE;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return cells
|
|
655
|
-
.map((cell, index) => {
|
|
656
|
-
if (!cell || !cell.node) {
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
return Decoration.node(
|
|
661
|
-
cell.pos,
|
|
662
|
-
cell.pos + cell.node.nodeSize,
|
|
663
|
-
{
|
|
664
|
-
class: decorationClassName,
|
|
665
|
-
},
|
|
666
|
-
{
|
|
667
|
-
key: `${TableDecorations.ROW_INSERT_LINE}_${index}`,
|
|
668
|
-
},
|
|
669
|
-
);
|
|
670
|
-
})
|
|
671
|
-
.filter(nonNullable);
|
|
672
|
-
};
|