@atlaskit/editor-tables 2.9.0 → 2.9.2

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-tables
2
2
 
3
+ ## 2.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.9.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#117917](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/117917)
14
+ [`feeb187f3871c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/feeb187f3871c) -
15
+ Fix selections between cells across tables, and cells to content outside tables
16
+ - Updated dependencies
17
+
3
18
  ## 2.9.0
4
19
 
5
20
  ### Minor Changes
@@ -19,6 +19,9 @@
19
19
  "references": [
20
20
  {
21
21
  "path": "../../../platform/feature-flags/afm-cc/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../tmp-editor-statsig/afm-cc/tsconfig.json"
22
25
  }
23
26
  ]
24
27
  }
@@ -19,6 +19,9 @@
19
19
  "references": [
20
20
  {
21
21
  "path": "../../../platform/feature-flags/afm-jira/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../tmp-editor-statsig/afm-jira/tsconfig.json"
22
25
  }
23
26
  ]
24
27
  }
@@ -19,6 +19,9 @@
19
19
  "references": [
20
20
  {
21
21
  "path": "../../../platform/feature-flags/afm-post-office/tsconfig.json"
22
+ },
23
+ {
24
+ "path": "../../tmp-editor-statsig/afm-post-office/tsconfig.json"
22
25
  }
23
26
  ]
24
27
  }
@@ -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,8 @@ 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 _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
8
10
  var _cellSelection = require("../cell-selection");
9
11
  var _tableMap2 = require("../table-map");
10
12
  var _selectionCell = require("../utils/selection-cell");
@@ -15,11 +17,32 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
15
17
  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
18
  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
19
  function handlePaste(view, event, slice) {
20
+ var _slice$content$firstC;
18
21
  if (!(0, _tables.isInTable)(view.state)) {
19
22
  return false;
20
23
  }
21
- var cells = (0, _copyPaste.pastedCells)(slice);
24
+ var schema = view.state.schema;
25
+ var isNestingAllowed = (0, _experiments.editorExperiment)('nested-tables-in-tables', true);
26
+ /**
27
+ * TODO: There can be multiple variations.
28
+ * 1. The last cell is selected with content outside of the table
29
+ * 2. The first cell is selected with content outside of the table
30
+ */
31
+ 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
32
  var sel = view.state.selection;
33
+ if (isNestingAllowed && !isPartialTablePaste) {
34
+ var cellRes = (0, _utils.findParentNode)(function (node) {
35
+ return node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
36
+ })(sel);
37
+ if (cellRes) {
38
+ var _cellRes$node$content;
39
+ 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;
40
+ if (canInsertNestedTable) {
41
+ return false;
42
+ }
43
+ }
44
+ }
45
+ var cells = (0, _copyPaste.pastedCells)(slice);
23
46
  if (sel instanceof _cellSelection.CellSelection) {
24
47
  if (!cells) {
25
48
  cells = {
@@ -80,7 +103,7 @@ var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, tabl
80
103
  }
81
104
  for (var _i = 0, _overlappingCells = overlappingCells; _i < _overlappingCells.length; _i++) {
82
105
  var cell = _overlappingCells[_i];
83
- // TODO: ED-13910 unblock Prosemirror bump
106
+ // TODO: ED-13910 - unblock Prosemirror bump
84
107
  // @ts-ignore
85
108
  cell.attrs.colwidth = null;
86
109
  }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.normalizeSelection = normalizeSelection;
7
7
  var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
8
9
  var _cellSelection = require("../cell-selection");
9
10
  var _tableMap = require("../table-map");
10
11
  function normalizeSelection(state, transaction, allowTableNodeSelection) {
@@ -17,6 +18,7 @@ function normalizeSelection(state, transaction, allowTableNodeSelection) {
17
18
  if (sel instanceof _state.NodeSelection) {
18
19
  role = sel.node.type.spec.tableRole;
19
20
  }
21
+ var isMultiSelect = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true);
20
22
  if (sel instanceof _state.NodeSelection && role) {
21
23
  if (role === 'cell' || role === 'header_cell') {
22
24
  normalize = _cellSelection.CellSelection.create(doc, sel.from);
@@ -31,7 +33,7 @@ function normalizeSelection(state, transaction, allowTableNodeSelection) {
31
33
  }
32
34
  } else if (sel instanceof _state.TextSelection && isCellBoundarySelection(sel)) {
33
35
  normalize = _state.TextSelection.create(doc, sel.from);
34
- } else if (sel instanceof _state.TextSelection && isTextSelectionAcrossCells(sel)) {
36
+ } else if (sel instanceof _state.TextSelection && (isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel))) {
35
37
  normalize = _state.TextSelection.create(doc, sel.$from.start(), sel.$from.end());
36
38
  }
37
39
  if (normalize) {
@@ -82,4 +84,33 @@ function isTextSelectionAcrossCells(_ref3) {
82
84
  }
83
85
  }
84
86
  return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
87
+ }
88
+ function isTextSelectionAcrossSameTableCells(_ref4) {
89
+ var $from = _ref4.$from,
90
+ $to = _ref4.$to;
91
+ var fromCellBoundaryNode;
92
+ var toCellBoundaryNode;
93
+ var fromCellTableNode;
94
+ var toCellTableNode;
95
+ for (var i = $from.depth; i > 0; i--) {
96
+ var node = $from.node(i);
97
+ if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') {
98
+ fromCellBoundaryNode = node;
99
+ }
100
+ if (node.type.name === 'table') {
101
+ fromCellTableNode = node;
102
+ break;
103
+ }
104
+ }
105
+ for (var _i2 = $to.depth; _i2 > 0; _i2--) {
106
+ var _node2 = $to.node(_i2);
107
+ if (_node2.type.spec.tableRole === 'cell' || _node2.type.spec.tableRole === 'header_cell') {
108
+ toCellBoundaryNode = _node2;
109
+ }
110
+ if (_node2.type.name === 'table') {
111
+ toCellTableNode = _node2;
112
+ break;
113
+ }
114
+ }
115
+ return fromCellBoundaryNode !== undefined && toCellBoundaryNode !== undefined && fromCellBoundaryNode !== toCellBoundaryNode && toCellTableNode === fromCellTableNode && $to.parentOffset === 0;
85
116
  }
@@ -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,4 +1,6 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
2
4
  import { CellSelection } from '../cell-selection';
3
5
  import { TableMap } from '../table-map';
4
6
  import { selectionCell } from '../utils/selection-cell';
@@ -6,11 +8,32 @@ import { tableNodeTypes } from '../utils/table-node-types';
6
8
  import { isInTable } from '../utils/tables';
7
9
  import { clipCells, fitSlice, insertCells, pastedCells } from './copy-paste';
8
10
  export function handlePaste(view, event, slice) {
11
+ var _slice$content$firstC;
9
12
  if (!isInTable(view.state)) {
10
13
  return false;
11
14
  }
12
- let cells = pastedCells(slice);
15
+ const {
16
+ schema
17
+ } = view.state;
18
+ const isNestingAllowed = editorExperiment('nested-tables-in-tables', true);
19
+ /**
20
+ * TODO: There can be multiple variations.
21
+ * 1. The last cell is selected with content outside of the table
22
+ * 2. The first cell is selected with content outside of the table
23
+ */
24
+ 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
25
  const sel = view.state.selection;
26
+ if (isNestingAllowed && !isPartialTablePaste) {
27
+ const cellRes = findParentNode(node => node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader)(sel);
28
+ if (cellRes) {
29
+ var _cellRes$node$content;
30
+ 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;
31
+ if (canInsertNestedTable) {
32
+ return false;
33
+ }
34
+ }
35
+ }
36
+ let cells = pastedCells(slice);
14
37
  if (sel instanceof CellSelection) {
15
38
  if (!cells) {
16
39
  cells = {
@@ -61,7 +84,7 @@ const clearColumnWidthOfCells = (cells, rect, table) => {
61
84
  }
62
85
  }
63
86
  for (const cell of overlappingCells) {
64
- // TODO: ED-13910 unblock Prosemirror bump
87
+ // TODO: ED-13910 - unblock Prosemirror bump
65
88
  // @ts-ignore
66
89
  cell.attrs.colwidth = null;
67
90
  }
@@ -1,4 +1,5 @@
1
1
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
2
3
  import { CellSelection } from '../cell-selection';
3
4
  import { TableMap } from '../table-map';
4
5
  export function normalizeSelection(state, transaction, allowTableNodeSelection) {
@@ -12,6 +13,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
12
13
  if (sel instanceof NodeSelection) {
13
14
  role = sel.node.type.spec.tableRole;
14
15
  }
16
+ const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
15
17
  if (sel instanceof NodeSelection && role) {
16
18
  if (role === 'cell' || role === 'header_cell') {
17
19
  normalize = CellSelection.create(doc, sel.from);
@@ -26,7 +28,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
26
28
  }
27
29
  } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
28
30
  normalize = TextSelection.create(doc, sel.from);
29
- } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
31
+ } else if (sel instanceof TextSelection && (isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel))) {
30
32
  normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
31
33
  }
32
34
  if (normalize) {
@@ -81,4 +83,34 @@ function isTextSelectionAcrossCells({
81
83
  }
82
84
  }
83
85
  return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
86
+ }
87
+ function isTextSelectionAcrossSameTableCells({
88
+ $from,
89
+ $to
90
+ }) {
91
+ let fromCellBoundaryNode;
92
+ let toCellBoundaryNode;
93
+ let fromCellTableNode;
94
+ let toCellTableNode;
95
+ for (let i = $from.depth; i > 0; i--) {
96
+ const node = $from.node(i);
97
+ if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') {
98
+ fromCellBoundaryNode = node;
99
+ }
100
+ if (node.type.name === 'table') {
101
+ fromCellTableNode = node;
102
+ break;
103
+ }
104
+ }
105
+ for (let i = $to.depth; i > 0; i--) {
106
+ const node = $to.node(i);
107
+ if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') {
108
+ toCellBoundaryNode = node;
109
+ }
110
+ if (node.type.name === 'table') {
111
+ toCellTableNode = node;
112
+ break;
113
+ }
114
+ }
115
+ return fromCellBoundaryNode !== undefined && toCellBoundaryNode !== undefined && fromCellBoundaryNode !== toCellBoundaryNode && toCellTableNode === fromCellTableNode && $to.parentOffset === 0;
84
116
  }
@@ -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,6 +2,8 @@ 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 { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
7
  import { CellSelection } from '../cell-selection';
6
8
  import { TableMap } from '../table-map';
7
9
  import { selectionCell } from '../utils/selection-cell';
@@ -9,11 +11,32 @@ import { tableNodeTypes } from '../utils/table-node-types';
9
11
  import { isInTable } from '../utils/tables';
10
12
  import { clipCells, fitSlice, insertCells, pastedCells } from './copy-paste';
11
13
  export function handlePaste(view, event, slice) {
14
+ var _slice$content$firstC;
12
15
  if (!isInTable(view.state)) {
13
16
  return false;
14
17
  }
15
- var cells = pastedCells(slice);
18
+ var schema = view.state.schema;
19
+ var isNestingAllowed = editorExperiment('nested-tables-in-tables', true);
20
+ /**
21
+ * TODO: There can be multiple variations.
22
+ * 1. The last cell is selected with content outside of the table
23
+ * 2. The first cell is selected with content outside of the table
24
+ */
25
+ 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
26
  var sel = view.state.selection;
27
+ if (isNestingAllowed && !isPartialTablePaste) {
28
+ var cellRes = findParentNode(function (node) {
29
+ return node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
30
+ })(sel);
31
+ if (cellRes) {
32
+ var _cellRes$node$content;
33
+ 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;
34
+ if (canInsertNestedTable) {
35
+ return false;
36
+ }
37
+ }
38
+ }
39
+ var cells = pastedCells(slice);
17
40
  if (sel instanceof CellSelection) {
18
41
  if (!cells) {
19
42
  cells = {
@@ -74,7 +97,7 @@ var clearColumnWidthOfCells = function clearColumnWidthOfCells(cells, rect, tabl
74
97
  }
75
98
  for (var _i = 0, _overlappingCells = overlappingCells; _i < _overlappingCells.length; _i++) {
76
99
  var cell = _overlappingCells[_i];
77
- // TODO: ED-13910 unblock Prosemirror bump
100
+ // TODO: ED-13910 - unblock Prosemirror bump
78
101
  // @ts-ignore
79
102
  cell.attrs.colwidth = null;
80
103
  }
@@ -1,4 +1,5 @@
1
1
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
2
3
  import { CellSelection } from '../cell-selection';
3
4
  import { TableMap } from '../table-map';
4
5
  export function normalizeSelection(state, transaction, allowTableNodeSelection) {
@@ -11,6 +12,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
11
12
  if (sel instanceof NodeSelection) {
12
13
  role = sel.node.type.spec.tableRole;
13
14
  }
15
+ var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
14
16
  if (sel instanceof NodeSelection && role) {
15
17
  if (role === 'cell' || role === 'header_cell') {
16
18
  normalize = CellSelection.create(doc, sel.from);
@@ -25,7 +27,7 @@ export function normalizeSelection(state, transaction, allowTableNodeSelection)
25
27
  }
26
28
  } else if (sel instanceof TextSelection && isCellBoundarySelection(sel)) {
27
29
  normalize = TextSelection.create(doc, sel.from);
28
- } else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) {
30
+ } else if (sel instanceof TextSelection && (isMultiSelect ? isTextSelectionAcrossSameTableCells(sel) : isTextSelectionAcrossCells(sel))) {
29
31
  normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end());
30
32
  }
31
33
  if (normalize) {
@@ -76,4 +78,33 @@ function isTextSelectionAcrossCells(_ref3) {
76
78
  }
77
79
  }
78
80
  return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0;
81
+ }
82
+ function isTextSelectionAcrossSameTableCells(_ref4) {
83
+ var $from = _ref4.$from,
84
+ $to = _ref4.$to;
85
+ var fromCellBoundaryNode;
86
+ var toCellBoundaryNode;
87
+ var fromCellTableNode;
88
+ var toCellTableNode;
89
+ for (var i = $from.depth; i > 0; i--) {
90
+ var node = $from.node(i);
91
+ if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') {
92
+ fromCellBoundaryNode = node;
93
+ }
94
+ if (node.type.name === 'table') {
95
+ fromCellTableNode = node;
96
+ break;
97
+ }
98
+ }
99
+ for (var _i2 = $to.depth; _i2 > 0; _i2--) {
100
+ var _node2 = $to.node(_i2);
101
+ if (_node2.type.spec.tableRole === 'cell' || _node2.type.spec.tableRole === 'header_cell') {
102
+ toCellBoundaryNode = _node2;
103
+ }
104
+ if (_node2.type.name === 'table') {
105
+ toCellTableNode = _node2;
106
+ break;
107
+ }
108
+ }
109
+ return fromCellBoundaryNode !== undefined && toCellBoundaryNode !== undefined && fromCellBoundaryNode !== toCellBoundaryNode && toCellTableNode === fromCellTableNode && $to.parentOffset === 0;
79
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-tables",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
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/"
@@ -28,7 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@atlaskit/editor-prosemirror": "7.0.0",
31
- "@atlaskit/platform-feature-flags": "^1.0.0",
31
+ "@atlaskit/platform-feature-flags": "^1.1.0",
32
+ "@atlaskit/tmp-editor-statsig": "^4.0.0",
32
33
  "@babel/runtime": "^7.0.0"
33
34
  },
34
35
  "techstack": {