@atlaskit/editor-tables 2.9.1 → 2.9.3
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 +14 -0
- package/afm-jira/tsconfig.json +3 -0
- package/afm-post-office/tsconfig.json +3 -0
- package/dist/cjs/pm-plugins/input.js +1 -5
- package/dist/cjs/utils/colspan.js +1 -1
- package/dist/cjs/utils/handle-paste.js +28 -4
- package/dist/cjs/utils/normalize-selection.js +2 -4
- package/dist/es2019/pm-plugins/input.js +1 -5
- package/dist/es2019/utils/colspan.js +1 -1
- package/dist/es2019/utils/handle-paste.js +28 -4
- package/dist/es2019/utils/normalize-selection.js +2 -4
- package/dist/esm/pm-plugins/input.js +1 -5
- package/dist/esm/utils/colspan.js +1 -1
- package/dist/esm/utils/handle-paste.js +28 -4
- package/dist/esm/utils/normalize-selection.js +2 -4
- package/dist/types/utils/handle-paste.d.ts +5 -1
- package/dist/types-ts4.5/utils/handle-paste.d.ts +5 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-tables
|
|
2
2
|
|
|
3
|
+
## 2.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#148184](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/148184)
|
|
8
|
+
[`cf70e8acad123`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cf70e8acad123) -
|
|
9
|
+
EDITOR-321 Cleaned up feature gate `platform_editor_cell_selection_with_nested_tables`
|
|
10
|
+
|
|
11
|
+
## 2.9.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 2.9.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/afm-jira/tsconfig.json
CHANGED
|
@@ -9,7 +9,6 @@ exports.handleTripleClick = handleTripleClick;
|
|
|
9
9
|
var _keymap = require("@atlaskit/editor-prosemirror/keymap");
|
|
10
10
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
12
|
var _cellSelection = require("../cell-selection");
|
|
14
13
|
var _utils = require("../utils");
|
|
15
14
|
var _cells = require("../utils/cells");
|
|
@@ -212,14 +211,11 @@ function handleMouseDown(view, event, dragAndDropEnabled) {
|
|
|
212
211
|
var isStartCellInsideNestedTable = isInsideNestedTable(view, startEvent);
|
|
213
212
|
var isBothCellsInSameTable = isCurrCellInsideNestedTable === isStartCellInsideNestedTable;
|
|
214
213
|
var $moveAnchor;
|
|
215
|
-
var oldIfStatement = currDOMCell !== startDOMCell;
|
|
216
|
-
var newIfStatement = currDOMCell !== startDOMCell && isBothCellsInSameTable;
|
|
217
|
-
var checkCellsAreDifferent = (0, _platformFeatureFlags.fg)('platform_editor_cell_selection_with_nested_tables') ? newIfStatement : oldIfStatement;
|
|
218
214
|
if (anchor != null) {
|
|
219
215
|
// Continuing an existing cross-cell selection
|
|
220
216
|
$moveAnchor = view.state.doc.resolve(anchor);
|
|
221
217
|
// Ignored via go/ees005
|
|
222
|
-
} else if (
|
|
218
|
+
} else if (currDOMCell !== startDOMCell && isBothCellsInSameTable) {
|
|
223
219
|
// Moving out of the initial cell -- start a new cell selection
|
|
224
220
|
$moveAnchor = cellUnderMouse(view, startEvent);
|
|
225
221
|
if (!$moveAnchor) {
|
|
@@ -38,7 +38,7 @@ function assertColspan(attrs) {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
// TODO: replace "addColSpan" from table plugin with this function
|
|
41
|
+
// TODO: ED-26961 - replace "addColSpan" from table plugin with this function
|
|
42
42
|
function addColSpan(attrs, pos) {
|
|
43
43
|
var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
44
44
|
assertColspan(attrs);
|
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.handlePaste = handlePaste;
|
|
7
7
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
9
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
10
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
8
11
|
var _cellSelection = require("../cell-selection");
|
|
9
12
|
var _tableMap2 = require("../table-map");
|
|
10
13
|
var _selectionCell = require("../utils/selection-cell");
|
|
@@ -14,13 +17,34 @@ var _copyPaste = require("./copy-paste");
|
|
|
14
17
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
15
18
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
16
19
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
17
|
-
|
|
20
|
+
var SKIP_NESTED_TABLE_PASTE_SOURCES = ['microsoft-excel', 'google-spreadsheets'];
|
|
21
|
+
function handlePaste(view, event, slice, options) {
|
|
22
|
+
var _slice$content$firstC;
|
|
18
23
|
if (!(0, _tables.isInTable)(view.state)) {
|
|
19
24
|
return false;
|
|
20
25
|
}
|
|
21
|
-
var
|
|
26
|
+
var schema = view.state.schema;
|
|
27
|
+
var isNestingAllowed = (0, _experiments.editorExperiment)('nested-tables-in-tables', true);
|
|
28
|
+
var isPasteFullTableInsideEmptyCellEnabled = (0, _platformFeatureFlags.fg)('platform_editor_paste_full_table_inside_empty_cell');
|
|
29
|
+
var isPartialTablePaste = slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === schema.nodes.table && slice.openStart !== 0 && slice.openEnd !== 0;
|
|
22
30
|
var sel = view.state.selection;
|
|
23
|
-
|
|
31
|
+
var isCellSelection = sel instanceof _cellSelection.CellSelection;
|
|
32
|
+
if (isPasteFullTableInsideEmptyCellEnabled && isNestingAllowed && !isPartialTablePaste &&
|
|
33
|
+
// If the selection is not a cell selection, and the selection is empty then we can insert a nested table
|
|
34
|
+
!isCellSelection && sel.empty && !(options && SKIP_NESTED_TABLE_PASTE_SOURCES.includes(options.pasteSource))) {
|
|
35
|
+
var cellRes = (0, _utils.findParentNode)(function (node) {
|
|
36
|
+
return node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
|
|
37
|
+
})(sel);
|
|
38
|
+
if (cellRes) {
|
|
39
|
+
var _cellRes$node$content;
|
|
40
|
+
var canInsertNestedTable = (_cellRes$node$content = cellRes.node.contentMatchAt(0).matchType(schema.nodes.table)) === null || _cellRes$node$content === void 0 ? void 0 : _cellRes$node$content.validEnd;
|
|
41
|
+
if (canInsertNestedTable) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
var cells = (0, _copyPaste.pastedCells)(slice);
|
|
47
|
+
if (isCellSelection) {
|
|
24
48
|
if (!cells) {
|
|
25
49
|
cells = {
|
|
26
50
|
width: 1,
|
|
@@ -80,7 +104,7 @@ var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, tabl
|
|
|
80
104
|
}
|
|
81
105
|
for (var _i = 0, _overlappingCells = overlappingCells; _i < _overlappingCells.length; _i++) {
|
|
82
106
|
var cell = _overlappingCells[_i];
|
|
83
|
-
// TODO: ED-13910 unblock Prosemirror bump
|
|
107
|
+
// TODO: ED-13910 - unblock Prosemirror bump
|
|
84
108
|
// @ts-ignore
|
|
85
109
|
cell.attrs.colwidth = null;
|
|
86
110
|
}
|
|
@@ -18,9 +18,7 @@ function normalizeSelection(state, transaction, allowTableNodeSelection) {
|
|
|
18
18
|
if (sel instanceof _state.NodeSelection) {
|
|
19
19
|
role = sel.node.type.spec.tableRole;
|
|
20
20
|
}
|
|
21
|
-
var isMultiSelect = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true
|
|
22
|
-
exposure: true
|
|
23
|
-
});
|
|
21
|
+
var isMultiSelect = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true);
|
|
24
22
|
if (sel instanceof _state.NodeSelection && role) {
|
|
25
23
|
if (role === 'cell' || role === 'header_cell') {
|
|
26
24
|
normalize = _cellSelection.CellSelection.create(doc, sel.from);
|
|
@@ -35,7 +33,7 @@ function normalizeSelection(state, transaction, allowTableNodeSelection) {
|
|
|
35
33
|
}
|
|
36
34
|
} else if (sel instanceof _state.TextSelection && isCellBoundarySelection(sel)) {
|
|
37
35
|
normalize = _state.TextSelection.create(doc, sel.from);
|
|
38
|
-
} else if (sel instanceof _state.TextSelection && isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel)) {
|
|
36
|
+
} else if (sel instanceof _state.TextSelection && (isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel))) {
|
|
39
37
|
normalize = _state.TextSelection.create(doc, sel.$from.start(), sel.$from.end());
|
|
40
38
|
}
|
|
41
39
|
if (normalize) {
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
5
5
|
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
6
6
|
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
8
7
|
import { CellSelection } from '../cell-selection';
|
|
9
8
|
import { findTableClosestToPos, tableNodeTypes } from '../utils';
|
|
10
9
|
import { cellAround, nextCell } from '../utils/cells';
|
|
@@ -211,14 +210,11 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
|
|
|
211
210
|
const isStartCellInsideNestedTable = isInsideNestedTable(view, startEvent);
|
|
212
211
|
const isBothCellsInSameTable = isCurrCellInsideNestedTable === isStartCellInsideNestedTable;
|
|
213
212
|
let $moveAnchor;
|
|
214
|
-
const oldIfStatement = currDOMCell !== startDOMCell;
|
|
215
|
-
const newIfStatement = currDOMCell !== startDOMCell && isBothCellsInSameTable;
|
|
216
|
-
const checkCellsAreDifferent = fg('platform_editor_cell_selection_with_nested_tables') ? newIfStatement : oldIfStatement;
|
|
217
213
|
if (anchor != null) {
|
|
218
214
|
// Continuing an existing cross-cell selection
|
|
219
215
|
$moveAnchor = view.state.doc.resolve(anchor);
|
|
220
216
|
// Ignored via go/ees005
|
|
221
|
-
} else if (
|
|
217
|
+
} else if (currDOMCell !== startDOMCell && isBothCellsInSameTable) {
|
|
222
218
|
// Moving out of the initial cell -- start a new cell selection
|
|
223
219
|
$moveAnchor = cellUnderMouse(view, startEvent);
|
|
224
220
|
if (!$moveAnchor) {
|
|
@@ -24,7 +24,7 @@ export function assertColspan(attrs) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
// TODO: replace "addColSpan" from table plugin with this function
|
|
27
|
+
// TODO: ED-26961 - replace "addColSpan" from table plugin with this function
|
|
28
28
|
export function addColSpan(attrs, pos, n = 1) {
|
|
29
29
|
assertColspan(attrs);
|
|
30
30
|
const result = {
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
2
5
|
import { CellSelection } from '../cell-selection';
|
|
3
6
|
import { TableMap } from '../table-map';
|
|
4
7
|
import { selectionCell } from '../utils/selection-cell';
|
|
5
8
|
import { tableNodeTypes } from '../utils/table-node-types';
|
|
6
9
|
import { isInTable } from '../utils/tables';
|
|
7
10
|
import { clipCells, fitSlice, insertCells, pastedCells } from './copy-paste';
|
|
8
|
-
|
|
11
|
+
const SKIP_NESTED_TABLE_PASTE_SOURCES = ['microsoft-excel', 'google-spreadsheets'];
|
|
12
|
+
export function handlePaste(view, event, slice, options) {
|
|
13
|
+
var _slice$content$firstC;
|
|
9
14
|
if (!isInTable(view.state)) {
|
|
10
15
|
return false;
|
|
11
16
|
}
|
|
12
|
-
|
|
17
|
+
const {
|
|
18
|
+
schema
|
|
19
|
+
} = view.state;
|
|
20
|
+
const isNestingAllowed = editorExperiment('nested-tables-in-tables', true);
|
|
21
|
+
const isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
|
|
22
|
+
const isPartialTablePaste = slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === schema.nodes.table && slice.openStart !== 0 && slice.openEnd !== 0;
|
|
13
23
|
const sel = view.state.selection;
|
|
14
|
-
|
|
24
|
+
const isCellSelection = sel instanceof CellSelection;
|
|
25
|
+
if (isPasteFullTableInsideEmptyCellEnabled && isNestingAllowed && !isPartialTablePaste &&
|
|
26
|
+
// If the selection is not a cell selection, and the selection is empty then we can insert a nested table
|
|
27
|
+
!isCellSelection && sel.empty && !(options && SKIP_NESTED_TABLE_PASTE_SOURCES.includes(options.pasteSource))) {
|
|
28
|
+
const cellRes = findParentNode(node => node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader)(sel);
|
|
29
|
+
if (cellRes) {
|
|
30
|
+
var _cellRes$node$content;
|
|
31
|
+
const canInsertNestedTable = (_cellRes$node$content = cellRes.node.contentMatchAt(0).matchType(schema.nodes.table)) === null || _cellRes$node$content === void 0 ? void 0 : _cellRes$node$content.validEnd;
|
|
32
|
+
if (canInsertNestedTable) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let cells = pastedCells(slice);
|
|
38
|
+
if (isCellSelection) {
|
|
15
39
|
if (!cells) {
|
|
16
40
|
cells = {
|
|
17
41
|
width: 1,
|
|
@@ -61,7 +85,7 @@ const clearColumnWidthOfCells = (cells, rect, table) => {
|
|
|
61
85
|
}
|
|
62
86
|
}
|
|
63
87
|
for (const cell of overlappingCells) {
|
|
64
|
-
// TODO: ED-13910 unblock Prosemirror bump
|
|
88
|
+
// TODO: ED-13910 - unblock Prosemirror bump
|
|
65
89
|
// @ts-ignore
|
|
66
90
|
cell.attrs.colwidth = null;
|
|
67
91
|
}
|
|
@@ -13,9 +13,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
|
|
|
13
13
|
if (sel instanceof NodeSelection) {
|
|
14
14
|
role = sel.node.type.spec.tableRole;
|
|
15
15
|
}
|
|
16
|
-
const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true
|
|
17
|
-
exposure: true
|
|
18
|
-
});
|
|
16
|
+
const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
|
|
19
17
|
if (sel instanceof NodeSelection && role) {
|
|
20
18
|
if (role === 'cell' || role === 'header_cell') {
|
|
21
19
|
normalize = CellSelection.create(doc, sel.from);
|
|
@@ -30,7 +28,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
|
|
|
30
28
|
}
|
|
31
29
|
} else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
|
|
32
30
|
normalize = TextSelection.create(doc, sel.from);
|
|
33
|
-
} else if (sel instanceof TextSelection && isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel)) {
|
|
31
|
+
} else if (sel instanceof TextSelection && (isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel))) {
|
|
34
32
|
normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
|
|
35
33
|
}
|
|
36
34
|
if (normalize) {
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
5
5
|
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
6
6
|
import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
8
7
|
import { CellSelection } from '../cell-selection';
|
|
9
8
|
import { findTableClosestToPos, tableNodeTypes } from '../utils';
|
|
10
9
|
import { cellAround, nextCell } from '../utils/cells';
|
|
@@ -204,14 +203,11 @@ export function handleMouseDown(view, event, dragAndDropEnabled) {
|
|
|
204
203
|
var isStartCellInsideNestedTable = isInsideNestedTable(view, startEvent);
|
|
205
204
|
var isBothCellsInSameTable = isCurrCellInsideNestedTable === isStartCellInsideNestedTable;
|
|
206
205
|
var $moveAnchor;
|
|
207
|
-
var oldIfStatement = currDOMCell !== startDOMCell;
|
|
208
|
-
var newIfStatement = currDOMCell !== startDOMCell && isBothCellsInSameTable;
|
|
209
|
-
var checkCellsAreDifferent = fg('platform_editor_cell_selection_with_nested_tables') ? newIfStatement : oldIfStatement;
|
|
210
206
|
if (anchor != null) {
|
|
211
207
|
// Continuing an existing cross-cell selection
|
|
212
208
|
$moveAnchor = view.state.doc.resolve(anchor);
|
|
213
209
|
// Ignored via go/ees005
|
|
214
|
-
} else if (
|
|
210
|
+
} else if (currDOMCell !== startDOMCell && isBothCellsInSameTable) {
|
|
215
211
|
// Moving out of the initial cell -- start a new cell selection
|
|
216
212
|
$moveAnchor = cellUnderMouse(view, startEvent);
|
|
217
213
|
if (!$moveAnchor) {
|
|
@@ -29,7 +29,7 @@ export function assertColspan(attrs) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// TODO: replace "addColSpan" from table plugin with this function
|
|
32
|
+
// TODO: ED-26961 - replace "addColSpan" from table plugin with this function
|
|
33
33
|
export function addColSpan(attrs, pos) {
|
|
34
34
|
var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
35
35
|
assertColspan(attrs);
|
|
@@ -2,19 +2,43 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
|
|
|
2
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
4
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
5
|
+
import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
5
8
|
import { CellSelection } from '../cell-selection';
|
|
6
9
|
import { TableMap } from '../table-map';
|
|
7
10
|
import { selectionCell } from '../utils/selection-cell';
|
|
8
11
|
import { tableNodeTypes } from '../utils/table-node-types';
|
|
9
12
|
import { isInTable } from '../utils/tables';
|
|
10
13
|
import { clipCells, fitSlice, insertCells, pastedCells } from './copy-paste';
|
|
11
|
-
|
|
14
|
+
var SKIP_NESTED_TABLE_PASTE_SOURCES = ['microsoft-excel', 'google-spreadsheets'];
|
|
15
|
+
export function handlePaste(view, event, slice, options) {
|
|
16
|
+
var _slice$content$firstC;
|
|
12
17
|
if (!isInTable(view.state)) {
|
|
13
18
|
return false;
|
|
14
19
|
}
|
|
15
|
-
var
|
|
20
|
+
var schema = view.state.schema;
|
|
21
|
+
var isNestingAllowed = editorExperiment('nested-tables-in-tables', true);
|
|
22
|
+
var isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
|
|
23
|
+
var isPartialTablePaste = slice.content.childCount === 1 && ((_slice$content$firstC = slice.content.firstChild) === null || _slice$content$firstC === void 0 ? void 0 : _slice$content$firstC.type) === schema.nodes.table && slice.openStart !== 0 && slice.openEnd !== 0;
|
|
16
24
|
var sel = view.state.selection;
|
|
17
|
-
|
|
25
|
+
var isCellSelection = sel instanceof CellSelection;
|
|
26
|
+
if (isPasteFullTableInsideEmptyCellEnabled && isNestingAllowed && !isPartialTablePaste &&
|
|
27
|
+
// If the selection is not a cell selection, and the selection is empty then we can insert a nested table
|
|
28
|
+
!isCellSelection && sel.empty && !(options && SKIP_NESTED_TABLE_PASTE_SOURCES.includes(options.pasteSource))) {
|
|
29
|
+
var cellRes = findParentNode(function (node) {
|
|
30
|
+
return node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
|
|
31
|
+
})(sel);
|
|
32
|
+
if (cellRes) {
|
|
33
|
+
var _cellRes$node$content;
|
|
34
|
+
var canInsertNestedTable = (_cellRes$node$content = cellRes.node.contentMatchAt(0).matchType(schema.nodes.table)) === null || _cellRes$node$content === void 0 ? void 0 : _cellRes$node$content.validEnd;
|
|
35
|
+
if (canInsertNestedTable) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var cells = pastedCells(slice);
|
|
41
|
+
if (isCellSelection) {
|
|
18
42
|
if (!cells) {
|
|
19
43
|
cells = {
|
|
20
44
|
width: 1,
|
|
@@ -74,7 +98,7 @@ var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, tabl
|
|
|
74
98
|
}
|
|
75
99
|
for (var _i = 0, _overlappingCells = overlappingCells; _i < _overlappingCells.length; _i++) {
|
|
76
100
|
var cell = _overlappingCells[_i];
|
|
77
|
-
// TODO: ED-13910 unblock Prosemirror bump
|
|
101
|
+
// TODO: ED-13910 - unblock Prosemirror bump
|
|
78
102
|
// @ts-ignore
|
|
79
103
|
cell.attrs.colwidth = null;
|
|
80
104
|
}
|
|
@@ -12,9 +12,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
|
|
|
12
12
|
if (sel instanceof NodeSelection) {
|
|
13
13
|
role = sel.node.type.spec.tableRole;
|
|
14
14
|
}
|
|
15
|
-
var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true
|
|
16
|
-
exposure: true
|
|
17
|
-
});
|
|
15
|
+
var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
|
|
18
16
|
if (sel instanceof NodeSelection && role) {
|
|
19
17
|
if (role === 'cell' || role === 'header_cell') {
|
|
20
18
|
normalize = CellSelection.create(doc, sel.from);
|
|
@@ -29,7 +27,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
|
|
|
29
27
|
}
|
|
30
28
|
} else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
|
|
31
29
|
normalize = TextSelection.create(doc, sel.from);
|
|
32
|
-
} else if (sel instanceof TextSelection && isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel)) {
|
|
30
|
+
} else if (sel instanceof TextSelection && (isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel))) {
|
|
33
31
|
normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
|
|
34
32
|
}
|
|
35
33
|
if (normalize) {
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { type EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
|
|
3
|
+
type PasteOptions = {
|
|
4
|
+
pasteSource: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function handlePaste(view: EditorView, event: ClipboardEvent, slice: Slice, options?: PasteOptions): boolean;
|
|
7
|
+
export {};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { type Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { type EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
|
|
3
|
+
type PasteOptions = {
|
|
4
|
+
pasteSource: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function handlePaste(view: EditorView, event: ClipboardEvent, slice: Slice, options?: PasteOptions): boolean;
|
|
7
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-tables",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.3",
|
|
4
4
|
"description": "A package that contains common classes and utility functions for editor tables",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
31
31
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
32
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
32
|
+
"@atlaskit/tmp-editor-statsig": "^4.15.0",
|
|
33
33
|
"@babel/runtime": "^7.0.0"
|
|
34
34
|
},
|
|
35
35
|
"techstack": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"platform_editor_table_fix_move_column": {
|
|
54
54
|
"type": "boolean"
|
|
55
55
|
},
|
|
56
|
-
"
|
|
56
|
+
"platform_editor_paste_full_table_inside_empty_cell": {
|
|
57
57
|
"type": "boolean"
|
|
58
58
|
}
|
|
59
59
|
},
|