@atlaskit/editor-tables 2.9.2 → 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 CHANGED
@@ -1,5 +1,13 @@
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
+
3
11
  ## 2.9.2
4
12
 
5
13
  ### Patch Changes
@@ -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 (checkCellsAreDifferent) {
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) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.handlePaste = handlePaste;
7
7
  var _model = require("@atlaskit/editor-prosemirror/model");
8
8
  var _utils = require("@atlaskit/editor-prosemirror/utils");
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
10
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
10
11
  var _cellSelection = require("../cell-selection");
11
12
  var _tableMap2 = require("../table-map");
@@ -16,21 +17,21 @@ var _copyPaste = require("./copy-paste");
16
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; } } }; }
17
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; } }
18
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; }
19
- function handlePaste(view, event, slice) {
20
+ var SKIP_NESTED_TABLE_PASTE_SOURCES = ['microsoft-excel', 'google-spreadsheets'];
21
+ function handlePaste(view, event, slice, options) {
20
22
  var _slice$content$firstC;
21
23
  if (!(0, _tables.isInTable)(view.state)) {
22
24
  return false;
23
25
  }
24
26
  var schema = view.state.schema;
25
27
  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
- */
28
+ var isPasteFullTableInsideEmptyCellEnabled = (0, _platformFeatureFlags.fg)('platform_editor_paste_full_table_inside_empty_cell');
31
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;
32
30
  var sel = view.state.selection;
33
- if (isNestingAllowed && !isPartialTablePaste) {
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))) {
34
35
  var cellRes = (0, _utils.findParentNode)(function (node) {
35
36
  return node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
36
37
  })(sel);
@@ -43,7 +44,7 @@ function handlePaste(view, event, slice) {
43
44
  }
44
45
  }
45
46
  var cells = (0, _copyPaste.pastedCells)(slice);
46
- if (sel instanceof _cellSelection.CellSelection) {
47
+ if (isCellSelection) {
47
48
  if (!cells) {
48
49
  cells = {
49
50
  width: 1,
@@ -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 (checkCellsAreDifferent) {
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) {
@@ -1,5 +1,6 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
2
  import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
5
  import { CellSelection } from '../cell-selection';
5
6
  import { TableMap } from '../table-map';
@@ -7,7 +8,8 @@ import { selectionCell } from '../utils/selection-cell';
7
8
  import { tableNodeTypes } from '../utils/table-node-types';
8
9
  import { isInTable } from '../utils/tables';
9
10
  import { clipCells, fitSlice, insertCells, pastedCells } from './copy-paste';
10
- export function handlePaste(view, event, slice) {
11
+ const SKIP_NESTED_TABLE_PASTE_SOURCES = ['microsoft-excel', 'google-spreadsheets'];
12
+ export function handlePaste(view, event, slice, options) {
11
13
  var _slice$content$firstC;
12
14
  if (!isInTable(view.state)) {
13
15
  return false;
@@ -16,14 +18,13 @@ export function handlePaste(view, event, slice) {
16
18
  schema
17
19
  } = view.state;
18
20
  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
- */
21
+ const isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
24
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;
25
23
  const sel = view.state.selection;
26
- if (isNestingAllowed && !isPartialTablePaste) {
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))) {
27
28
  const cellRes = findParentNode(node => node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader)(sel);
28
29
  if (cellRes) {
29
30
  var _cellRes$node$content;
@@ -34,7 +35,7 @@ export function handlePaste(view, event, slice) {
34
35
  }
35
36
  }
36
37
  let cells = pastedCells(slice);
37
- if (sel instanceof CellSelection) {
38
+ if (isCellSelection) {
38
39
  if (!cells) {
39
40
  cells = {
40
41
  width: 1,
@@ -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 (checkCellsAreDifferent) {
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) {
@@ -3,6 +3,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
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
5
  import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
7
8
  import { CellSelection } from '../cell-selection';
8
9
  import { TableMap } from '../table-map';
@@ -10,21 +11,21 @@ import { selectionCell } from '../utils/selection-cell';
10
11
  import { tableNodeTypes } from '../utils/table-node-types';
11
12
  import { isInTable } from '../utils/tables';
12
13
  import { clipCells, fitSlice, insertCells, pastedCells } from './copy-paste';
13
- export function handlePaste(view, event, slice) {
14
+ var SKIP_NESTED_TABLE_PASTE_SOURCES = ['microsoft-excel', 'google-spreadsheets'];
15
+ export function handlePaste(view, event, slice, options) {
14
16
  var _slice$content$firstC;
15
17
  if (!isInTable(view.state)) {
16
18
  return false;
17
19
  }
18
20
  var schema = view.state.schema;
19
21
  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
- */
22
+ var isPasteFullTableInsideEmptyCellEnabled = fg('platform_editor_paste_full_table_inside_empty_cell');
25
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;
26
24
  var sel = view.state.selection;
27
- if (isNestingAllowed && !isPartialTablePaste) {
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))) {
28
29
  var cellRes = findParentNode(function (node) {
29
30
  return node.type === schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
30
31
  })(sel);
@@ -37,7 +38,7 @@ export function handlePaste(view, event, slice) {
37
38
  }
38
39
  }
39
40
  var cells = pastedCells(slice);
40
- if (sel instanceof CellSelection) {
41
+ if (isCellSelection) {
41
42
  if (!cells) {
42
43
  cells = {
43
44
  width: 1,
@@ -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
- export declare function handlePaste(view: EditorView, event: Event | null, slice: Slice): boolean;
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
- export declare function handlePaste(view: EditorView, event: Event | null, slice: Slice): boolean;
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.2",
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": "^4.0.0",
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
- "platform_editor_cell_selection_with_nested_tables": {
56
+ "platform_editor_paste_full_table_inside_empty_cell": {
57
57
  "type": "boolean"
58
58
  }
59
59
  },