@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,386 +0,0 @@
|
|
|
1
|
-
import { getParentOfTypeCount } from '@atlaskit/editor-common/nesting';
|
|
2
|
-
import { flatmap, mapChildren, mapSlice } from '@atlaskit/editor-common/utils';
|
|
3
|
-
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
import { Slice, Fragment, type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
-
import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
-
import { flatten, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
7
|
-
import { CellSelection } from '@atlaskit/editor-tables';
|
|
8
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
10
|
-
|
|
11
|
-
import { getPluginState } from '../plugin-factory';
|
|
12
|
-
|
|
13
|
-
// lifts up the content of each cell, returning an array of nodes
|
|
14
|
-
export const unwrapContentFromTable = (maybeTable: PMNode): PMNode | PMNode[] => {
|
|
15
|
-
const { schema } = maybeTable.type;
|
|
16
|
-
if (maybeTable.type === schema.nodes.table) {
|
|
17
|
-
const content: PMNode[] = [];
|
|
18
|
-
const { tableCell, tableHeader } = schema.nodes;
|
|
19
|
-
maybeTable.descendants((maybeCell) => {
|
|
20
|
-
if (maybeCell.type === tableCell || maybeCell.type === tableHeader) {
|
|
21
|
-
content.push(...flatten(maybeCell, false).map((child) => child.node));
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
});
|
|
26
|
-
return content;
|
|
27
|
-
}
|
|
28
|
-
return maybeTable;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// Flattens nested tables after a given nesting depth
|
|
32
|
-
// If this looks familiar, it's a heavily modified version of `mapFragment` which has been
|
|
33
|
-
// adjusted to support tracking nesting depth. This wasn't possible by using `mapFragment` directly
|
|
34
|
-
const unwrapNestedTables = (
|
|
35
|
-
content: Fragment,
|
|
36
|
-
schema: Schema,
|
|
37
|
-
unwrapNestDepth: number,
|
|
38
|
-
currentNestDepth = 0,
|
|
39
|
-
): PMNode[] => {
|
|
40
|
-
const flattenNested = (node: PMNode, tableDepth: number) => {
|
|
41
|
-
if (node.type === schema.nodes.table) {
|
|
42
|
-
if (tableDepth >= unwrapNestDepth) {
|
|
43
|
-
return unwrapContentFromTable(node);
|
|
44
|
-
}
|
|
45
|
-
return node;
|
|
46
|
-
}
|
|
47
|
-
return node;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const children = [] as PMNode[];
|
|
51
|
-
for (let i = 0, size = content.childCount; i < size; i++) {
|
|
52
|
-
const node = content.child(i);
|
|
53
|
-
const transformed = node.isLeaf
|
|
54
|
-
? flattenNested(node, currentNestDepth)
|
|
55
|
-
: flattenNested(
|
|
56
|
-
node.copy(
|
|
57
|
-
Fragment.fromArray(
|
|
58
|
-
unwrapNestedTables(
|
|
59
|
-
node.content,
|
|
60
|
-
schema,
|
|
61
|
-
unwrapNestDepth,
|
|
62
|
-
node.type === schema.nodes.table ? currentNestDepth + 1 : currentNestDepth,
|
|
63
|
-
),
|
|
64
|
-
),
|
|
65
|
-
),
|
|
66
|
-
currentNestDepth,
|
|
67
|
-
);
|
|
68
|
-
if (transformed) {
|
|
69
|
-
if (Array.isArray(transformed)) {
|
|
70
|
-
children.push(...transformed);
|
|
71
|
-
} else {
|
|
72
|
-
children.push(transformed);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return children;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const removeTableFromFirstChild = (node: PMNode, i: number): PMNode | PMNode[] => {
|
|
80
|
-
return i === 0 ? unwrapContentFromTable(node) : node;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const removeTableFromLastChild = (
|
|
84
|
-
node: PMNode,
|
|
85
|
-
i: number,
|
|
86
|
-
fragment: Fragment,
|
|
87
|
-
): PMNode | PMNode[] => {
|
|
88
|
-
return i === fragment.childCount - 1 ? unwrapContentFromTable(node) : node;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const transformSliceToRemoveNestedTables = (
|
|
92
|
-
slice: Slice,
|
|
93
|
-
schema: Schema,
|
|
94
|
-
selection: Selection,
|
|
95
|
-
): Slice => {
|
|
96
|
-
const isNestingAllowed = editorExperiment('nested-tables-in-tables', true);
|
|
97
|
-
const { table, tableCell, tableHeader } = schema.nodes;
|
|
98
|
-
let openEnd = slice.openEnd;
|
|
99
|
-
|
|
100
|
-
const newFragment = flatmap(slice.content, (node, i, fragment) => {
|
|
101
|
-
// if pasted content is a node that supports nesting a table
|
|
102
|
-
// such as layoutSection or expand allow 1 level by default
|
|
103
|
-
let allowedTableNesting = 1;
|
|
104
|
-
const isCellSelection = selection instanceof CellSelection;
|
|
105
|
-
const isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
|
|
106
|
-
const isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
|
|
107
|
-
const isPasteFullTableInsideEmptyCellEnabled = fg(
|
|
108
|
-
'platform_editor_paste_full_table_inside_empty_cell',
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
// Pasted content only contains a table and no other content
|
|
112
|
-
const isCellPaste =
|
|
113
|
-
isPasteInTable &&
|
|
114
|
-
slice.content.childCount === 1 &&
|
|
115
|
-
slice.content.firstChild?.type === table &&
|
|
116
|
-
(!isPasteFullTableInsideEmptyCellEnabled || (slice.openStart !== 0 && slice.openEnd !== 0));
|
|
117
|
-
|
|
118
|
-
if (isNestingAllowed) {
|
|
119
|
-
// if nesting is allowed we bump up the default nesting allowance to 2 to support
|
|
120
|
-
// two levels of nesting in nodes that support table nesting already such as layoutSection and expands
|
|
121
|
-
allowedTableNesting = 2;
|
|
122
|
-
|
|
123
|
-
// however if pasted content is a table, allow just one level
|
|
124
|
-
if (node.type === schema.nodes.table) {
|
|
125
|
-
allowedTableNesting = 1;
|
|
126
|
-
|
|
127
|
-
// if paste is inside a table, allow no further nesting
|
|
128
|
-
if (isPasteInTable) {
|
|
129
|
-
allowedTableNesting = 0;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// unless we are pasting inside a nested table, then bounce back to 1 level
|
|
133
|
-
// because editor-plugin-paste will lift the table to the parent table (just below it)
|
|
134
|
-
if (isPasteInNestedTable) {
|
|
135
|
-
allowedTableNesting = 1;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// paste of table cells into a table cell - content is spread across multiple cells
|
|
139
|
-
// by editor-tables so needs to be treated a little differently
|
|
140
|
-
if (
|
|
141
|
-
isCellPaste ||
|
|
142
|
-
(isCellSelection && fg('platform_editor_nested_tables_cellselection_paste'))
|
|
143
|
-
) {
|
|
144
|
-
allowedTableNesting = 1;
|
|
145
|
-
if (isPasteInNestedTable) {
|
|
146
|
-
allowedTableNesting = 0;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Prevent invalid openEnd after pasting tables with a selection that ends inside a nested table cell.
|
|
152
|
-
// If the slice ends with a selection that ends inside a nested table, and we paste inside a table we
|
|
153
|
-
// need to adjust the openEnd because it is no longer correct. If we don't, Prosemirror fires an exception
|
|
154
|
-
// because it iterates to a non-existent depth and the transform will not be applied
|
|
155
|
-
if (
|
|
156
|
-
slice.openEnd >= 7 && // depth of a nested table cell
|
|
157
|
-
slice.content.childCount > 1 &&
|
|
158
|
-
slice.content.lastChild?.type === table &&
|
|
159
|
-
isPasteInTable
|
|
160
|
-
) {
|
|
161
|
-
// re-point the slice's openEnd to non-nested table cell depth
|
|
162
|
-
openEnd = 4;
|
|
163
|
-
}
|
|
164
|
-
} else {
|
|
165
|
-
// for layouts and expands, we start with 1 level of nesting as set above
|
|
166
|
-
|
|
167
|
-
// if pasted content is a table, don't allow further nesting
|
|
168
|
-
if (node.type === schema.nodes.table) {
|
|
169
|
-
allowedTableNesting = 0;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (
|
|
174
|
-
isCellSelection &&
|
|
175
|
-
!isCellPaste &&
|
|
176
|
-
fg('platform_editor_nested_tables_cellselection_paste')
|
|
177
|
-
) {
|
|
178
|
-
// if pasting into a cell selection, we need to flatten the parent table as well
|
|
179
|
-
return unwrapNestedTables(Fragment.fromArray([node]), schema, allowedTableNesting);
|
|
180
|
-
} else {
|
|
181
|
-
// after we've worked out what the allowed nesting depth is, unwrap nested tables
|
|
182
|
-
const newChildren = unwrapNestedTables(node.content, schema, allowedTableNesting);
|
|
183
|
-
return node.copy(Fragment.fromArray(newChildren));
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
return new Slice(newFragment, slice.openStart, openEnd);
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* When we copy from a table cell with a hardBreak at the end,
|
|
192
|
-
* the slice generated will come with a hardBreak outside of the table.
|
|
193
|
-
* This code will look for that pattern and fix it.
|
|
194
|
-
*/
|
|
195
|
-
export const transformSliceToFixHardBreakProblemOnCopyFromCell = (
|
|
196
|
-
slice: Slice,
|
|
197
|
-
schema: Schema,
|
|
198
|
-
): Slice => {
|
|
199
|
-
const { paragraph, table, hardBreak } = schema.nodes;
|
|
200
|
-
const emptyParagraphNode = paragraph.createAndFill();
|
|
201
|
-
|
|
202
|
-
const hardBreakNode = hardBreak?.createAndFill();
|
|
203
|
-
const paragraphNodeSize = emptyParagraphNode ? emptyParagraphNode.nodeSize : 0;
|
|
204
|
-
const hardBreakNodeSize = hardBreakNode ? hardBreakNode.nodeSize : 0;
|
|
205
|
-
const paragraphWithHardBreakSize = paragraphNodeSize + hardBreakNodeSize;
|
|
206
|
-
|
|
207
|
-
if (
|
|
208
|
-
slice.content.childCount === 2 &&
|
|
209
|
-
slice.content.firstChild &&
|
|
210
|
-
slice.content.lastChild &&
|
|
211
|
-
slice.content.firstChild.type === table &&
|
|
212
|
-
slice.content.lastChild.type === paragraph &&
|
|
213
|
-
slice.content.lastChild.nodeSize === paragraphWithHardBreakSize
|
|
214
|
-
) {
|
|
215
|
-
const nodes = unwrapContentFromTable(slice.content.firstChild);
|
|
216
|
-
if (nodes instanceof Array) {
|
|
217
|
-
return new Slice(
|
|
218
|
-
Fragment.from(
|
|
219
|
-
// keep only the content and discard the hardBreak
|
|
220
|
-
nodes[0],
|
|
221
|
-
),
|
|
222
|
-
slice.openStart,
|
|
223
|
-
slice.openEnd,
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return slice;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const isNodeSingleCellTable = (node: PMNode, schema: Schema): boolean => {
|
|
232
|
-
return (
|
|
233
|
-
node.childCount === 1 &&
|
|
234
|
-
node.firstChild?.type === schema.nodes.tableRow &&
|
|
235
|
-
node.firstChild.childCount === 1 &&
|
|
236
|
-
(node.firstChild.firstChild?.type === schema.nodes.tableCell ||
|
|
237
|
-
node.firstChild.firstChild?.type === schema.nodes.tableHeader)
|
|
238
|
-
);
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
const isFragmentSingleCellTable = (fragment: Fragment, schema: Schema): boolean => {
|
|
242
|
-
return (
|
|
243
|
-
fragment.childCount === 1 &&
|
|
244
|
-
fragment.firstChild !== null &&
|
|
245
|
-
isNodeSingleCellTable(fragment.firstChild, schema)
|
|
246
|
-
);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const containsNonTableBlockChildren = (fragment: Fragment, schema: Schema): boolean => {
|
|
250
|
-
let containsNonTableBlock = false;
|
|
251
|
-
const { table, tableCell, tableHeader } = schema.nodes;
|
|
252
|
-
|
|
253
|
-
fragment.forEach((node) => {
|
|
254
|
-
if (node.isBlock && ![table, tableCell, tableHeader].includes(node.type)) {
|
|
255
|
-
containsNonTableBlock = true;
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
return containsNonTableBlock;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
export const transformSliceToRemoveOpenTable = (slice: Slice, schema: Schema): Slice => {
|
|
263
|
-
// Case 1: A slice of a block selection inside a nested table
|
|
264
|
-
// Prosemirror wraps nested block selections in their respective tables
|
|
265
|
-
// We are using `safeInsert` to paste nested tables, so we do not want to preserve this wrapping
|
|
266
|
-
|
|
267
|
-
// slice starts and ends inside a nested table at the same depth
|
|
268
|
-
if (slice.openStart >= 7 && slice.openEnd >= 7) {
|
|
269
|
-
let cleaned = slice;
|
|
270
|
-
let descendedDepth = 0;
|
|
271
|
-
const tableDepthDecrement = 2;
|
|
272
|
-
|
|
273
|
-
// if the slice is a single cell table and contains cells with single cell tables, descend into it until we find textblock children
|
|
274
|
-
if (isFragmentSingleCellTable(slice.content, schema)) {
|
|
275
|
-
slice.content.firstChild?.descendants((node) => {
|
|
276
|
-
if (isNodeSingleCellTable(node, schema)) {
|
|
277
|
-
descendedDepth += tableDepthDecrement;
|
|
278
|
-
} else if (node.type === schema.nodes.table) {
|
|
279
|
-
return false;
|
|
280
|
-
} else if (containsNonTableBlockChildren(node.content, schema)) {
|
|
281
|
-
descendedDepth += tableDepthDecrement;
|
|
282
|
-
// create a new slice with the content of non-table block children and the depth of the nested tables subtracted
|
|
283
|
-
cleaned = new Slice(
|
|
284
|
-
node.content,
|
|
285
|
-
slice.openStart - descendedDepth - tableDepthDecrement,
|
|
286
|
-
slice.openEnd - descendedDepth - tableDepthDecrement,
|
|
287
|
-
);
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (!cleaned.eq(slice)) {
|
|
294
|
-
return cleaned;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Case 2: A slice entirely within a single CELL
|
|
299
|
-
if (
|
|
300
|
-
// starts and ends inside of a cell
|
|
301
|
-
slice.openStart >= 4 &&
|
|
302
|
-
slice.openEnd >= 4 &&
|
|
303
|
-
// slice is a table node
|
|
304
|
-
slice.content.childCount === 1 &&
|
|
305
|
-
// Ignored via go/ees005
|
|
306
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
307
|
-
slice.content.firstChild!.type === schema.nodes.table
|
|
308
|
-
) {
|
|
309
|
-
// we're removing the table, tableRow and tableCell reducing the open depth by 3
|
|
310
|
-
const depthDecrement = 3;
|
|
311
|
-
|
|
312
|
-
// prosemirror-view has a bug that it duplicates table entry when selecting multiple paragraphs in a table cell.
|
|
313
|
-
// https://github.com/ProseMirror/prosemirror/issues/1270
|
|
314
|
-
// The structure becomes
|
|
315
|
-
// table(genuine) > tableRow(genuine) > table(duplicated) > tableRow(duplicated) > tableCell/tableHeader(genuine) > contents(genuine)
|
|
316
|
-
// As we are removing wrapping table anyway, we keep duplicated table and tableRow for simplicity
|
|
317
|
-
let cleaned = slice;
|
|
318
|
-
if (
|
|
319
|
-
slice.content.firstChild?.content?.firstChild?.content?.firstChild?.type ===
|
|
320
|
-
schema.nodes.table
|
|
321
|
-
) {
|
|
322
|
-
cleaned = new Slice(
|
|
323
|
-
slice.content.firstChild.content.firstChild.content,
|
|
324
|
-
slice.openStart - 2,
|
|
325
|
-
slice.openEnd - 2,
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return new Slice(
|
|
330
|
-
flatmap(cleaned.content, unwrapContentFromTable),
|
|
331
|
-
cleaned.openStart - depthDecrement,
|
|
332
|
-
cleaned.openEnd - depthDecrement,
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// Case 3: A slice starting within a CELL and ending outside the table
|
|
337
|
-
if (
|
|
338
|
-
// starts inside of a cell but ends outside of the starting table
|
|
339
|
-
slice.openStart >= 4 &&
|
|
340
|
-
// slice starts from a table node (and spans across more than one node)
|
|
341
|
-
slice.content.childCount > 1 &&
|
|
342
|
-
slice.content.firstChild?.type === schema.nodes.table
|
|
343
|
-
) {
|
|
344
|
-
// repoint the slice's cutting depth so that cell content where the slice starts
|
|
345
|
-
// does not get lifted out of the cell on paste
|
|
346
|
-
return new Slice(slice.content, 1, slice.openEnd);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return slice;
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
export const transformSliceToCorrectEmptyTableCells = (slice: Slice, schema: Schema): Slice => {
|
|
353
|
-
const { tableCell, tableHeader } = schema.nodes;
|
|
354
|
-
return mapSlice(slice, (node) => {
|
|
355
|
-
if (
|
|
356
|
-
node &&
|
|
357
|
-
(node.type === tableCell || node.type === tableHeader) &&
|
|
358
|
-
!node.content.childCount
|
|
359
|
-
) {
|
|
360
|
-
return node.type.createAndFill(node.attrs) || node;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
return node;
|
|
364
|
-
});
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
export function isHeaderRowRequired(state: EditorState) {
|
|
368
|
-
const tableState = getPluginState(state);
|
|
369
|
-
return tableState && tableState.pluginConfig.isHeaderRowRequired;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
export const transformSliceTableLayoutDefaultToCenter = (slice: Slice, schema: Schema): Slice => {
|
|
373
|
-
const { table } = schema.nodes;
|
|
374
|
-
const children = [] as PMNode[];
|
|
375
|
-
mapChildren(slice.content, (node: PMNode) => {
|
|
376
|
-
if (node.type === table && node.attrs.layout === 'default') {
|
|
377
|
-
children.push(
|
|
378
|
-
table.createChecked({ ...node.attrs, layout: 'center' }, node.content, node.marks),
|
|
379
|
-
);
|
|
380
|
-
} else {
|
|
381
|
-
children.push(node);
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
return new Slice(Fragment.fromArray(children), slice.openStart, slice.openEnd);
|
|
386
|
-
};
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { parsePx } from '@atlaskit/editor-common/utils';
|
|
2
|
-
import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
-
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
|
-
import { findTable, getSelectionRect, isRowSelected } from '@atlaskit/editor-tables/utils';
|
|
7
|
-
|
|
8
|
-
import { TableCssClassName as ClassName } from '../../types';
|
|
9
|
-
import { tableDeleteButtonSize } from '../../ui/consts';
|
|
10
|
-
|
|
11
|
-
export interface RowParams {
|
|
12
|
-
startIndex: number;
|
|
13
|
-
endIndex: number;
|
|
14
|
-
height: number;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const getRowHeights = (tableRef: HTMLTableElement): number[] => {
|
|
18
|
-
const heights: number[] = [];
|
|
19
|
-
const tableBody = tableRef.querySelector('tbody');
|
|
20
|
-
if (tableBody) {
|
|
21
|
-
const rows = tableBody.childNodes;
|
|
22
|
-
for (let i = 0, count = rows.length; i < count; i++) {
|
|
23
|
-
const row = rows[i] as HTMLTableRowElement;
|
|
24
|
-
heights[i] = row.getBoundingClientRect().height + 1;
|
|
25
|
-
|
|
26
|
-
// padding only gets applied when the container has sticky
|
|
27
|
-
if (row.classList.contains('sticky') && i === 0) {
|
|
28
|
-
const styles = window.getComputedStyle(row);
|
|
29
|
-
const paddingTop = parsePx(styles.paddingTop || '');
|
|
30
|
-
heights[i] -= paddingTop ? paddingTop + 1 : +1;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return heights;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const getRowDeleteButtonParams = (
|
|
39
|
-
rowsHeights: Array<number | undefined>,
|
|
40
|
-
selection: Selection,
|
|
41
|
-
offsetTop = 0,
|
|
42
|
-
): { top: number; indexes: number[] } | null => {
|
|
43
|
-
const rect = getSelectionRect(selection);
|
|
44
|
-
if (!rect) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
let height = 0;
|
|
48
|
-
let offset = offsetTop;
|
|
49
|
-
// find the rows before the selection
|
|
50
|
-
for (let i = 0; i < rect.top; i++) {
|
|
51
|
-
const rowHeight = rowsHeights[i];
|
|
52
|
-
if (rowHeight) {
|
|
53
|
-
offset += rowHeight - 1;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// these are the selected rows widths
|
|
57
|
-
const indexes: number[] = [];
|
|
58
|
-
for (let i = rect.top; i < rect.bottom; i++) {
|
|
59
|
-
const rowHeight = rowsHeights[i];
|
|
60
|
-
if (rowHeight) {
|
|
61
|
-
height += rowHeight - 1;
|
|
62
|
-
indexes.push(i);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const top = offset + height / 2 - tableDeleteButtonSize / 2;
|
|
67
|
-
return { top, indexes };
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const getRowsParams = (rowsHeights: Array<number | undefined>): RowParams[] => {
|
|
71
|
-
const rows: RowParams[] = [];
|
|
72
|
-
for (let i = 0, count = rowsHeights.length; i < count; i++) {
|
|
73
|
-
const height = rowsHeights[i];
|
|
74
|
-
if (!height) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
let endIndex = rowsHeights.length;
|
|
78
|
-
for (let k = i + 1, count = rowsHeights.length; k < count; k++) {
|
|
79
|
-
if (rowsHeights[k]) {
|
|
80
|
-
endIndex = k;
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
rows.push({ startIndex: i, endIndex, height });
|
|
85
|
-
}
|
|
86
|
-
return rows;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const getRowClassNames = (
|
|
90
|
-
index: number,
|
|
91
|
-
selection: Selection,
|
|
92
|
-
hoveredRows: number[] = [],
|
|
93
|
-
isInDanger?: boolean,
|
|
94
|
-
isResizing?: boolean,
|
|
95
|
-
): string => {
|
|
96
|
-
const classNames: string[] = [];
|
|
97
|
-
if (isRowSelected(index)(selection) || (hoveredRows.indexOf(index) > -1 && !isResizing)) {
|
|
98
|
-
classNames.push(ClassName.HOVERED_CELL_ACTIVE);
|
|
99
|
-
if (isInDanger) {
|
|
100
|
-
classNames.push(ClassName.HOVERED_CELL_IN_DANGER);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return classNames.join(' ');
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const copyPreviousRow =
|
|
107
|
-
(schema: Schema) => (insertNewRowIndex: number) => (tr: Transaction) => {
|
|
108
|
-
const table = findTable(tr.selection);
|
|
109
|
-
if (!table) {
|
|
110
|
-
return tr;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const map = TableMap.get(table.node);
|
|
114
|
-
const copyPreviousRowIndex = insertNewRowIndex - 1;
|
|
115
|
-
|
|
116
|
-
if (insertNewRowIndex <= 0) {
|
|
117
|
-
throw Error(
|
|
118
|
-
`Row Index less or equal 0 isn't not allowed since there is not a previous to copy`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (insertNewRowIndex > map.height) {
|
|
123
|
-
return tr;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const tableNode = table.node;
|
|
127
|
-
const {
|
|
128
|
-
nodes: { tableRow },
|
|
129
|
-
} = schema;
|
|
130
|
-
|
|
131
|
-
const cellsInRow = map.cellsInRect({
|
|
132
|
-
left: 0,
|
|
133
|
-
right: map.width,
|
|
134
|
-
top: copyPreviousRowIndex,
|
|
135
|
-
bottom: copyPreviousRowIndex + 1,
|
|
136
|
-
});
|
|
137
|
-
const offsetIndexPosition = copyPreviousRowIndex * map.width;
|
|
138
|
-
const offsetNextLineIndexPosition = insertNewRowIndex * map.width;
|
|
139
|
-
const cellsPositionsInOriginalRow = map.map.slice(
|
|
140
|
-
offsetIndexPosition,
|
|
141
|
-
offsetIndexPosition + map.width,
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const cellsPositionsInNextRow = map.map.slice(
|
|
145
|
-
offsetNextLineIndexPosition,
|
|
146
|
-
offsetNextLineIndexPosition + map.width,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const cells = [] as PMNode[];
|
|
150
|
-
const fixRowspans: { pos: number; node: PMNode }[] = [];
|
|
151
|
-
for (let i = 0; i < cellsPositionsInOriginalRow.length; ) {
|
|
152
|
-
const pos = cellsPositionsInOriginalRow[i];
|
|
153
|
-
const documentCellPos = pos + table.start;
|
|
154
|
-
const node = tr.doc.nodeAt(documentCellPos);
|
|
155
|
-
if (!node) {
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const attributes = {
|
|
160
|
-
...node.attrs,
|
|
161
|
-
colspan: 1,
|
|
162
|
-
rowspan: 1,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const newCell = node.type.createAndFill(attributes);
|
|
166
|
-
|
|
167
|
-
if (!newCell) {
|
|
168
|
-
return tr;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (cellsPositionsInNextRow.indexOf(pos) > -1) {
|
|
172
|
-
fixRowspans.push({ pos: documentCellPos, node });
|
|
173
|
-
} else if (cellsInRow.indexOf(pos) > -1) {
|
|
174
|
-
if (node.attrs.colspan > 1) {
|
|
175
|
-
const newCellWithColspanFixed = node.type.createAndFill({
|
|
176
|
-
...attributes,
|
|
177
|
-
colspan: node.attrs.colspan,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
if (!newCellWithColspanFixed) {
|
|
181
|
-
return tr;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
cells.push(newCellWithColspanFixed);
|
|
185
|
-
i = i + node.attrs.colspan;
|
|
186
|
-
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
cells.push(newCell);
|
|
190
|
-
} else {
|
|
191
|
-
cells.push(newCell);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
i++;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
fixRowspans.forEach((cell) => {
|
|
198
|
-
tr.setNodeMarkup(cell.pos, undefined, {
|
|
199
|
-
...cell.node.attrs,
|
|
200
|
-
rowspan: cell.node.attrs.rowspan + 1,
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const cloneRow = tableNode.child(copyPreviousRowIndex);
|
|
205
|
-
let rowPos = table.start;
|
|
206
|
-
for (let i = 0; i < insertNewRowIndex; i++) {
|
|
207
|
-
rowPos += tableNode.child(i).nodeSize;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return safeInsert(tableRow.createChecked(cloneRow.attrs, cells, cloneRow.marks), rowPos)(tr);
|
|
211
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Rect } from '@atlaskit/editor-tables/table-map';
|
|
2
|
-
|
|
3
|
-
export const getSelectedColumnIndexes = (selectionRect: Rect): number[] => {
|
|
4
|
-
const columnIndexes: number[] = [];
|
|
5
|
-
for (let i = selectionRect.left; i < selectionRect.right; i++) {
|
|
6
|
-
columnIndexes.push(i);
|
|
7
|
-
}
|
|
8
|
-
return columnIndexes;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const getSelectedRowIndexes = (selectionRect: Rect): number[] => {
|
|
12
|
-
const rowIndexes: number[] = [];
|
|
13
|
-
for (let i = selectionRect.top; i < selectionRect.bottom; i++) {
|
|
14
|
-
rowIndexes.push(i);
|
|
15
|
-
}
|
|
16
|
-
return rowIndexes;
|
|
17
|
-
};
|