@atlaskit/editor-plugin-table 17.3.21 → 17.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/pm-plugins/commands/insert.js +2 -5
- package/dist/cjs/pm-plugins/utils/paste.js +32 -47
- package/dist/cjs/tablePlugin.js +2 -4
- package/dist/es2019/pm-plugins/commands/insert.js +2 -5
- package/dist/es2019/pm-plugins/utils/paste.js +32 -47
- package/dist/es2019/tablePlugin.js +2 -4
- package/dist/esm/pm-plugins/commands/insert.js +2 -5
- package/dist/esm/pm-plugins/utils/paste.js +32 -47
- package/dist/esm/tablePlugin.js +2 -4
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 17.3.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`a040c03082274`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a040c03082274) -
|
|
8
|
+
[ux] EDITOR-507 Clean up main nested tables experiment `platform_editor_nested_tables`
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 17.3.21
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -15,7 +15,6 @@ var _state = require("@atlaskit/editor-prosemirror/state");
|
|
|
15
15
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
16
16
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
17
17
|
var _utils2 = require("@atlaskit/editor-tables/utils");
|
|
18
|
-
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
19
18
|
var _commands = require("../analytics/commands");
|
|
20
19
|
var _tableAnalytics = require("../table-analytics");
|
|
21
20
|
var _columnWidth = require("../transforms/column-width");
|
|
@@ -274,10 +273,8 @@ var insertTableWithNestingSupport = exports.insertTableWithNestingSupport = func
|
|
|
274
273
|
var insertAt;
|
|
275
274
|
var isNestedTable = false;
|
|
276
275
|
if ((0, _utils.hasParentNodeOfType)(schema.nodes.table)(tr.selection) && (0, _nesting.isNestedTablesSupported)(schema)) {
|
|
277
|
-
// If
|
|
278
|
-
if ((0,
|
|
279
|
-
exposure: true
|
|
280
|
-
}) || (0, _nesting.getParentOfTypeCount)(schema.nodes.table)(tr.selection.$from) > 1) {
|
|
276
|
+
// If trying to nest deeper than one level, we insert the table after the top table
|
|
277
|
+
if ((0, _nesting.getParentOfTypeCount)(schema.nodes.table)(tr.selection.$from) > 1) {
|
|
281
278
|
var positionAfterTopTable = (0, _nesting.getPositionAfterTopParentNodeOfType)(schema.nodes.table)(tr.selection.$from);
|
|
282
279
|
if (!positionAfterTopTable) {
|
|
283
280
|
return tr;
|
|
@@ -14,7 +14,6 @@ var _model = require("@atlaskit/editor-prosemirror/model");
|
|
|
14
14
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
15
15
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
16
16
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
|
-
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
18
17
|
var _pluginFactory = require("../plugin-factory");
|
|
19
18
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
19
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -75,17 +74,16 @@ var removeTableFromLastChild = exports.removeTableFromLastChild = function remov
|
|
|
75
74
|
return i === fragment.childCount - 1 ? unwrapContentFromTable(node) : node;
|
|
76
75
|
};
|
|
77
76
|
var transformSliceToRemoveNestedTables = exports.transformSliceToRemoveNestedTables = function transformSliceToRemoveNestedTables(slice, schema, selection) {
|
|
78
|
-
var isNestingAllowed = (0, _experiments.editorExperiment)('nested-tables-in-tables', true);
|
|
79
77
|
var _schema$nodes2 = schema.nodes,
|
|
80
78
|
table = _schema$nodes2.table,
|
|
81
79
|
tableCell = _schema$nodes2.tableCell,
|
|
82
80
|
tableHeader = _schema$nodes2.tableHeader;
|
|
83
81
|
var openEnd = slice.openEnd;
|
|
84
82
|
var newFragment = (0, _utils.flatmap)(slice.content, function (node, i, fragment) {
|
|
85
|
-
var _slice$content$firstC;
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
var allowedTableNesting =
|
|
83
|
+
var _slice$content$firstC, _slice$content$lastCh;
|
|
84
|
+
// We allow default nesting of 2 to support
|
|
85
|
+
// two levels of nesting in nodes that support table nesting already such as layoutSection and expands
|
|
86
|
+
var allowedTableNesting = 2;
|
|
89
87
|
var isCellSelection = selection instanceof _editorTables.CellSelection;
|
|
90
88
|
var isPasteInTable = (0, _utils2.hasParentNodeOfType)([table, tableCell, tableHeader])(selection);
|
|
91
89
|
var isPasteInNestedTable = (0, _nesting.getParentOfTypeCount)(schema.nodes.table)(selection.$from) > 1;
|
|
@@ -93,55 +91,42 @@ var transformSliceToRemoveNestedTables = exports.transformSliceToRemoveNestedTab
|
|
|
93
91
|
|
|
94
92
|
// Pasted content only contains a table and no other content
|
|
95
93
|
var isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
|
|
96
|
-
if (isNestingAllowed) {
|
|
97
|
-
var _slice$content$lastCh;
|
|
98
|
-
// if nesting is allowed we bump up the default nesting allowance to 2 to support
|
|
99
|
-
// two levels of nesting in nodes that support table nesting already such as layoutSection and expands
|
|
100
|
-
allowedTableNesting = 2;
|
|
101
94
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// if paste is inside a table, allow no further nesting
|
|
107
|
-
if (isPasteInTable) {
|
|
108
|
-
allowedTableNesting = 0;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// unless we are pasting inside a nested table, then bounce back to 1 level
|
|
112
|
-
// because editor-plugin-paste will lift the table to the parent table (just below it)
|
|
113
|
-
if (isPasteInNestedTable) {
|
|
114
|
-
allowedTableNesting = 1;
|
|
115
|
-
}
|
|
95
|
+
// however if pasted content is a table, allow just one level
|
|
96
|
+
if (node.type === schema.nodes.table) {
|
|
97
|
+
allowedTableNesting = 1;
|
|
116
98
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
allowedTableNesting = 1;
|
|
121
|
-
if (isPasteInNestedTable) {
|
|
122
|
-
allowedTableNesting = 0;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
99
|
+
// if paste is inside a table, allow no further nesting
|
|
100
|
+
if (isPasteInTable) {
|
|
101
|
+
allowedTableNesting = 0;
|
|
125
102
|
}
|
|
126
103
|
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (slice.openEnd >= 7 &&
|
|
132
|
-
// depth of a nested table cell
|
|
133
|
-
slice.content.childCount > 1 && ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === table && isPasteInTable) {
|
|
134
|
-
// re-point the slice's openEnd to non-nested table cell depth
|
|
135
|
-
openEnd = 4;
|
|
104
|
+
// unless we are pasting inside a nested table, then bounce back to 1 level
|
|
105
|
+
// because editor-plugin-paste will lift the table to the parent table (just below it)
|
|
106
|
+
if (isPasteInNestedTable) {
|
|
107
|
+
allowedTableNesting = 1;
|
|
136
108
|
}
|
|
137
|
-
} else {
|
|
138
|
-
// for layouts and expands, we start with 1 level of nesting as set above
|
|
139
109
|
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
110
|
+
// paste of table cells into a table cell - content is spread across multiple cells
|
|
111
|
+
// by editor-tables so needs to be treated a little differently
|
|
112
|
+
if (isCellPaste || isCellSelection) {
|
|
113
|
+
allowedTableNesting = 1;
|
|
114
|
+
if (isPasteInNestedTable) {
|
|
115
|
+
allowedTableNesting = 0;
|
|
116
|
+
}
|
|
143
117
|
}
|
|
144
118
|
}
|
|
119
|
+
|
|
120
|
+
// Prevent invalid openEnd after pasting tables with a selection that ends inside a nested table cell.
|
|
121
|
+
// If the slice ends with a selection that ends inside a nested table, and we paste inside a table we
|
|
122
|
+
// need to adjust the openEnd because it is no longer correct. If we don't, Prosemirror fires an exception
|
|
123
|
+
// because it iterates to a non-existent depth and the transform will not be applied
|
|
124
|
+
if (slice.openEnd >= 7 &&
|
|
125
|
+
// depth of a nested table cell
|
|
126
|
+
slice.content.childCount > 1 && ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === table && isPasteInTable) {
|
|
127
|
+
// re-point the slice's openEnd to non-nested table cell depth
|
|
128
|
+
openEnd = 4;
|
|
129
|
+
}
|
|
145
130
|
if (isCellSelection && !isCellPaste) {
|
|
146
131
|
// if pasting into a cell selection, we need to flatten the parent table as well
|
|
147
132
|
return _unwrapNestedTables(_model.Fragment.fromArray([node]), schema, allowedTableNesting);
|
package/dist/cjs/tablePlugin.js
CHANGED
|
@@ -574,10 +574,8 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
574
574
|
var tr = state.tr;
|
|
575
575
|
// If the cursor is inside a table
|
|
576
576
|
if ((0, _utils.hasParentNodeOfType)(state.schema.nodes.table)(state.selection) && options !== null && options !== void 0 && (_options$tableOptions6 = options.tableOptions) !== null && _options$tableOptions6 !== void 0 && _options$tableOptions6.allowNestedTables) {
|
|
577
|
-
// If
|
|
578
|
-
if ((0,
|
|
579
|
-
exposure: true
|
|
580
|
-
}) || (0, _nesting.getParentOfTypeCount)(state.schema.nodes.table)(state.selection.$from) > 1) {
|
|
577
|
+
// If trying to nest deeper than one level, we insert the table after the top table
|
|
578
|
+
if ((0, _nesting.getParentOfTypeCount)(state.schema.nodes.table)(state.selection.$from) > 1) {
|
|
581
579
|
// Nesting is too deep insert table after the top parent table
|
|
582
580
|
var positionAfterTopTable = (0, _nesting.getPositionAfterTopParentNodeOfType)(state.schema.nodes.table)(state.selection.$from);
|
|
583
581
|
tr = (0, _utils.safeInsert)(tableNode, positionAfterTopTable)(tr);
|
|
@@ -6,7 +6,6 @@ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
|
6
6
|
import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
7
7
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
8
8
|
import { addColumnAt as addColumnAtPMUtils, addRowAt, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
|
|
9
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
10
9
|
import { updateRowOrColumnMovedTransform } from '../analytics/commands';
|
|
11
10
|
import { META_KEYS } from '../table-analytics';
|
|
12
11
|
import { rescaleColumns } from '../transforms/column-width';
|
|
@@ -233,10 +232,8 @@ export const insertTableWithNestingSupport = ({
|
|
|
233
232
|
let insertAt;
|
|
234
233
|
let isNestedTable = false;
|
|
235
234
|
if (hasParentNodeOfType(schema.nodes.table)(tr.selection) && isNestedTablesSupported(schema)) {
|
|
236
|
-
// If
|
|
237
|
-
if (
|
|
238
|
-
exposure: true
|
|
239
|
-
}) || getParentOfTypeCount(schema.nodes.table)(tr.selection.$from) > 1) {
|
|
235
|
+
// If trying to nest deeper than one level, we insert the table after the top table
|
|
236
|
+
if (getParentOfTypeCount(schema.nodes.table)(tr.selection.$from) > 1) {
|
|
240
237
|
const positionAfterTopTable = getPositionAfterTopParentNodeOfType(schema.nodes.table)(tr.selection.$from);
|
|
241
238
|
if (!positionAfterTopTable) {
|
|
242
239
|
return tr;
|
|
@@ -4,7 +4,6 @@ import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
|
4
4
|
import { flatten, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
5
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
6
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
8
7
|
import { getPluginState } from '../plugin-factory';
|
|
9
8
|
|
|
10
9
|
// lifts up the content of each cell, returning an array of nodes
|
|
@@ -64,7 +63,6 @@ export const removeTableFromLastChild = (node, i, fragment) => {
|
|
|
64
63
|
return i === fragment.childCount - 1 ? unwrapContentFromTable(node) : node;
|
|
65
64
|
};
|
|
66
65
|
export const transformSliceToRemoveNestedTables = (slice, schema, selection) => {
|
|
67
|
-
const isNestingAllowed = editorExperiment('nested-tables-in-tables', true);
|
|
68
66
|
const {
|
|
69
67
|
table,
|
|
70
68
|
tableCell,
|
|
@@ -72,10 +70,10 @@ export const transformSliceToRemoveNestedTables = (slice, schema, selection) =>
|
|
|
72
70
|
} = schema.nodes;
|
|
73
71
|
let openEnd = slice.openEnd;
|
|
74
72
|
const newFragment = flatmap(slice.content, (node, i, fragment) => {
|
|
75
|
-
var _slice$content$firstC;
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
let allowedTableNesting =
|
|
73
|
+
var _slice$content$firstC, _slice$content$lastCh;
|
|
74
|
+
// We allow default nesting of 2 to support
|
|
75
|
+
// two levels of nesting in nodes that support table nesting already such as layoutSection and expands
|
|
76
|
+
let allowedTableNesting = 2;
|
|
79
77
|
const isCellSelection = selection instanceof CellSelection;
|
|
80
78
|
const isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
|
|
81
79
|
const isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
|
|
@@ -83,55 +81,42 @@ export const transformSliceToRemoveNestedTables = (slice, schema, selection) =>
|
|
|
83
81
|
|
|
84
82
|
// Pasted content only contains a table and no other content
|
|
85
83
|
const isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
|
|
86
|
-
if (isNestingAllowed) {
|
|
87
|
-
var _slice$content$lastCh;
|
|
88
|
-
// if nesting is allowed we bump up the default nesting allowance to 2 to support
|
|
89
|
-
// two levels of nesting in nodes that support table nesting already such as layoutSection and expands
|
|
90
|
-
allowedTableNesting = 2;
|
|
91
84
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// if paste is inside a table, allow no further nesting
|
|
97
|
-
if (isPasteInTable) {
|
|
98
|
-
allowedTableNesting = 0;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// unless we are pasting inside a nested table, then bounce back to 1 level
|
|
102
|
-
// because editor-plugin-paste will lift the table to the parent table (just below it)
|
|
103
|
-
if (isPasteInNestedTable) {
|
|
104
|
-
allowedTableNesting = 1;
|
|
105
|
-
}
|
|
85
|
+
// however if pasted content is a table, allow just one level
|
|
86
|
+
if (node.type === schema.nodes.table) {
|
|
87
|
+
allowedTableNesting = 1;
|
|
106
88
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
allowedTableNesting = 1;
|
|
111
|
-
if (isPasteInNestedTable) {
|
|
112
|
-
allowedTableNesting = 0;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
89
|
+
// if paste is inside a table, allow no further nesting
|
|
90
|
+
if (isPasteInTable) {
|
|
91
|
+
allowedTableNesting = 0;
|
|
115
92
|
}
|
|
116
93
|
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (slice.openEnd >= 7 &&
|
|
122
|
-
// depth of a nested table cell
|
|
123
|
-
slice.content.childCount > 1 && ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === table && isPasteInTable) {
|
|
124
|
-
// re-point the slice's openEnd to non-nested table cell depth
|
|
125
|
-
openEnd = 4;
|
|
94
|
+
// unless we are pasting inside a nested table, then bounce back to 1 level
|
|
95
|
+
// because editor-plugin-paste will lift the table to the parent table (just below it)
|
|
96
|
+
if (isPasteInNestedTable) {
|
|
97
|
+
allowedTableNesting = 1;
|
|
126
98
|
}
|
|
127
|
-
} else {
|
|
128
|
-
// for layouts and expands, we start with 1 level of nesting as set above
|
|
129
99
|
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
100
|
+
// paste of table cells into a table cell - content is spread across multiple cells
|
|
101
|
+
// by editor-tables so needs to be treated a little differently
|
|
102
|
+
if (isCellPaste || isCellSelection) {
|
|
103
|
+
allowedTableNesting = 1;
|
|
104
|
+
if (isPasteInNestedTable) {
|
|
105
|
+
allowedTableNesting = 0;
|
|
106
|
+
}
|
|
133
107
|
}
|
|
134
108
|
}
|
|
109
|
+
|
|
110
|
+
// Prevent invalid openEnd after pasting tables with a selection that ends inside a nested table cell.
|
|
111
|
+
// If the slice ends with a selection that ends inside a nested table, and we paste inside a table we
|
|
112
|
+
// need to adjust the openEnd because it is no longer correct. If we don't, Prosemirror fires an exception
|
|
113
|
+
// because it iterates to a non-existent depth and the transform will not be applied
|
|
114
|
+
if (slice.openEnd >= 7 &&
|
|
115
|
+
// depth of a nested table cell
|
|
116
|
+
slice.content.childCount > 1 && ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === table && isPasteInTable) {
|
|
117
|
+
// re-point the slice's openEnd to non-nested table cell depth
|
|
118
|
+
openEnd = 4;
|
|
119
|
+
}
|
|
135
120
|
if (isCellSelection && !isCellPaste) {
|
|
136
121
|
// if pasting into a cell selection, we need to flatten the parent table as well
|
|
137
122
|
return unwrapNestedTables(Fragment.fromArray([node]), schema, allowedTableNesting);
|
|
@@ -560,10 +560,8 @@ const tablePlugin = ({
|
|
|
560
560
|
} = state;
|
|
561
561
|
// If the cursor is inside a table
|
|
562
562
|
if (hasParentNodeOfType(state.schema.nodes.table)(state.selection) && options !== null && options !== void 0 && (_options$tableOptions6 = options.tableOptions) !== null && _options$tableOptions6 !== void 0 && _options$tableOptions6.allowNestedTables) {
|
|
563
|
-
// If
|
|
564
|
-
if (
|
|
565
|
-
exposure: true
|
|
566
|
-
}) || getParentOfTypeCount(state.schema.nodes.table)(state.selection.$from) > 1) {
|
|
563
|
+
// If trying to nest deeper than one level, we insert the table after the top table
|
|
564
|
+
if (getParentOfTypeCount(state.schema.nodes.table)(state.selection.$from) > 1) {
|
|
567
565
|
// Nesting is too deep insert table after the top parent table
|
|
568
566
|
const positionAfterTopTable = getPositionAfterTopParentNodeOfType(state.schema.nodes.table)(state.selection.$from);
|
|
569
567
|
tr = safeInsert(tableNode, positionAfterTopTable)(tr);
|
|
@@ -9,7 +9,6 @@ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
|
9
9
|
import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
10
10
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
11
11
|
import { addColumnAt as addColumnAtPMUtils, addRowAt, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
|
|
12
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
13
12
|
import { updateRowOrColumnMovedTransform } from '../analytics/commands';
|
|
14
13
|
import { META_KEYS } from '../table-analytics';
|
|
15
14
|
import { rescaleColumns } from '../transforms/column-width';
|
|
@@ -266,10 +265,8 @@ export var insertTableWithNestingSupport = function insertTableWithNestingSuppor
|
|
|
266
265
|
var insertAt;
|
|
267
266
|
var isNestedTable = false;
|
|
268
267
|
if (hasParentNodeOfType(schema.nodes.table)(tr.selection) && isNestedTablesSupported(schema)) {
|
|
269
|
-
// If
|
|
270
|
-
if (
|
|
271
|
-
exposure: true
|
|
272
|
-
}) || getParentOfTypeCount(schema.nodes.table)(tr.selection.$from) > 1) {
|
|
268
|
+
// If trying to nest deeper than one level, we insert the table after the top table
|
|
269
|
+
if (getParentOfTypeCount(schema.nodes.table)(tr.selection.$from) > 1) {
|
|
273
270
|
var positionAfterTopTable = getPositionAfterTopParentNodeOfType(schema.nodes.table)(tr.selection.$from);
|
|
274
271
|
if (!positionAfterTopTable) {
|
|
275
272
|
return tr;
|
|
@@ -8,7 +8,6 @@ import { Slice, Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
|
8
8
|
import { flatten, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
9
9
|
import { CellSelection } from '@atlaskit/editor-tables';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
12
11
|
import { getPluginState } from '../plugin-factory';
|
|
13
12
|
|
|
14
13
|
// lifts up the content of each cell, returning an array of nodes
|
|
@@ -68,17 +67,16 @@ export var removeTableFromLastChild = function removeTableFromLastChild(node, i,
|
|
|
68
67
|
return i === fragment.childCount - 1 ? unwrapContentFromTable(node) : node;
|
|
69
68
|
};
|
|
70
69
|
export var transformSliceToRemoveNestedTables = function transformSliceToRemoveNestedTables(slice, schema, selection) {
|
|
71
|
-
var isNestingAllowed = editorExperiment('nested-tables-in-tables', true);
|
|
72
70
|
var _schema$nodes2 = schema.nodes,
|
|
73
71
|
table = _schema$nodes2.table,
|
|
74
72
|
tableCell = _schema$nodes2.tableCell,
|
|
75
73
|
tableHeader = _schema$nodes2.tableHeader;
|
|
76
74
|
var openEnd = slice.openEnd;
|
|
77
75
|
var newFragment = flatmap(slice.content, function (node, i, fragment) {
|
|
78
|
-
var _slice$content$firstC;
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
var allowedTableNesting =
|
|
76
|
+
var _slice$content$firstC, _slice$content$lastCh;
|
|
77
|
+
// We allow default nesting of 2 to support
|
|
78
|
+
// two levels of nesting in nodes that support table nesting already such as layoutSection and expands
|
|
79
|
+
var allowedTableNesting = 2;
|
|
82
80
|
var isCellSelection = selection instanceof CellSelection;
|
|
83
81
|
var isPasteInTable = hasParentNodeOfType([table, tableCell, tableHeader])(selection);
|
|
84
82
|
var isPasteInNestedTable = getParentOfTypeCount(schema.nodes.table)(selection.$from) > 1;
|
|
@@ -86,55 +84,42 @@ export var transformSliceToRemoveNestedTables = function transformSliceToRemoveN
|
|
|
86
84
|
|
|
87
85
|
// Pasted content only contains a table and no other content
|
|
88
86
|
var isCellPaste = isPasteInTable && slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === table && (!isPasteFullTableInsideEmptyCellEnabled || slice.openStart !== 0 && slice.openEnd !== 0);
|
|
89
|
-
if (isNestingAllowed) {
|
|
90
|
-
var _slice$content$lastCh;
|
|
91
|
-
// if nesting is allowed we bump up the default nesting allowance to 2 to support
|
|
92
|
-
// two levels of nesting in nodes that support table nesting already such as layoutSection and expands
|
|
93
|
-
allowedTableNesting = 2;
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// if paste is inside a table, allow no further nesting
|
|
100
|
-
if (isPasteInTable) {
|
|
101
|
-
allowedTableNesting = 0;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// unless we are pasting inside a nested table, then bounce back to 1 level
|
|
105
|
-
// because editor-plugin-paste will lift the table to the parent table (just below it)
|
|
106
|
-
if (isPasteInNestedTable) {
|
|
107
|
-
allowedTableNesting = 1;
|
|
108
|
-
}
|
|
88
|
+
// however if pasted content is a table, allow just one level
|
|
89
|
+
if (node.type === schema.nodes.table) {
|
|
90
|
+
allowedTableNesting = 1;
|
|
109
91
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
allowedTableNesting = 1;
|
|
114
|
-
if (isPasteInNestedTable) {
|
|
115
|
-
allowedTableNesting = 0;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
92
|
+
// if paste is inside a table, allow no further nesting
|
|
93
|
+
if (isPasteInTable) {
|
|
94
|
+
allowedTableNesting = 0;
|
|
118
95
|
}
|
|
119
96
|
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (slice.openEnd >= 7 &&
|
|
125
|
-
// depth of a nested table cell
|
|
126
|
-
slice.content.childCount > 1 && ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === table && isPasteInTable) {
|
|
127
|
-
// re-point the slice's openEnd to non-nested table cell depth
|
|
128
|
-
openEnd = 4;
|
|
97
|
+
// unless we are pasting inside a nested table, then bounce back to 1 level
|
|
98
|
+
// because editor-plugin-paste will lift the table to the parent table (just below it)
|
|
99
|
+
if (isPasteInNestedTable) {
|
|
100
|
+
allowedTableNesting = 1;
|
|
129
101
|
}
|
|
130
|
-
} else {
|
|
131
|
-
// for layouts and expands, we start with 1 level of nesting as set above
|
|
132
102
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
103
|
+
// paste of table cells into a table cell - content is spread across multiple cells
|
|
104
|
+
// by editor-tables so needs to be treated a little differently
|
|
105
|
+
if (isCellPaste || isCellSelection) {
|
|
106
|
+
allowedTableNesting = 1;
|
|
107
|
+
if (isPasteInNestedTable) {
|
|
108
|
+
allowedTableNesting = 0;
|
|
109
|
+
}
|
|
136
110
|
}
|
|
137
111
|
}
|
|
112
|
+
|
|
113
|
+
// Prevent invalid openEnd after pasting tables with a selection that ends inside a nested table cell.
|
|
114
|
+
// If the slice ends with a selection that ends inside a nested table, and we paste inside a table we
|
|
115
|
+
// need to adjust the openEnd because it is no longer correct. If we don't, Prosemirror fires an exception
|
|
116
|
+
// because it iterates to a non-existent depth and the transform will not be applied
|
|
117
|
+
if (slice.openEnd >= 7 &&
|
|
118
|
+
// depth of a nested table cell
|
|
119
|
+
slice.content.childCount > 1 && ((_slice$content$lastCh = slice.content.lastChild) === null || _slice$content$lastCh === void 0 ? void 0 : _slice$content$lastCh.type) === table && isPasteInTable) {
|
|
120
|
+
// re-point the slice's openEnd to non-nested table cell depth
|
|
121
|
+
openEnd = 4;
|
|
122
|
+
}
|
|
138
123
|
if (isCellSelection && !isCellPaste) {
|
|
139
124
|
// if pasting into a cell selection, we need to flatten the parent table as well
|
|
140
125
|
return _unwrapNestedTables(Fragment.fromArray([node]), schema, allowedTableNesting);
|
package/dist/esm/tablePlugin.js
CHANGED
|
@@ -565,10 +565,8 @@ var tablePlugin = function tablePlugin(_ref) {
|
|
|
565
565
|
var tr = state.tr;
|
|
566
566
|
// If the cursor is inside a table
|
|
567
567
|
if (hasParentNodeOfType(state.schema.nodes.table)(state.selection) && options !== null && options !== void 0 && (_options$tableOptions6 = options.tableOptions) !== null && _options$tableOptions6 !== void 0 && _options$tableOptions6.allowNestedTables) {
|
|
568
|
-
// If
|
|
569
|
-
if (
|
|
570
|
-
exposure: true
|
|
571
|
-
}) || getParentOfTypeCount(state.schema.nodes.table)(state.selection.$from) > 1) {
|
|
568
|
+
// If trying to nest deeper than one level, we insert the table after the top table
|
|
569
|
+
if (getParentOfTypeCount(state.schema.nodes.table)(state.selection.$from) > 1) {
|
|
572
570
|
// Nesting is too deep insert table after the top parent table
|
|
573
571
|
var positionAfterTopTable = getPositionAfterTopParentNodeOfType(state.schema.nodes.table)(state.selection.$from);
|
|
574
572
|
tr = safeInsert(tableNode, positionAfterTopTable)(tr);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "17.3.
|
|
3
|
+
"version": "17.3.22",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@atlaskit/editor-plugin-batch-attribute-updates": "^7.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-content-insertion": "^7.0.0",
|
|
39
39
|
"@atlaskit/editor-plugin-editor-viewmode": "^9.0.0",
|
|
40
|
-
"@atlaskit/editor-plugin-extension": "10.1.
|
|
40
|
+
"@atlaskit/editor-plugin-extension": "10.1.4",
|
|
41
41
|
"@atlaskit/editor-plugin-guideline": "^7.0.0",
|
|
42
42
|
"@atlaskit/editor-plugin-interaction": "^14.0.0",
|
|
43
43
|
"@atlaskit/editor-plugin-limited-mode": "^4.0.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.1.0",
|
|
58
58
|
"@atlaskit/primitives": "^18.0.0",
|
|
59
59
|
"@atlaskit/theme": "^21.0.0",
|
|
60
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
60
|
+
"@atlaskit/tmp-editor-statsig": "^28.0.0",
|
|
61
61
|
"@atlaskit/toggle": "^15.2.0",
|
|
62
62
|
"@atlaskit/tokens": "^11.0.0",
|
|
63
63
|
"@atlaskit/tooltip": "^20.14.0",
|