@atlaskit/editor-plugin-table 0.0.6 → 0.0.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +7 -6
  3. package/dist/cjs/plugins/table/nodeviews/tableCell.js +4 -4
  4. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  5. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  6. package/dist/cjs/plugins/table/utils/column-controls.js +1 -1
  7. package/dist/cjs/version.json +1 -1
  8. package/dist/es2019/plugins/table/event-handlers.js +8 -7
  9. package/dist/es2019/plugins/table/nodeviews/tableCell.js +3 -4
  10. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  11. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  12. package/dist/es2019/plugins/table/utils/column-controls.js +1 -1
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/esm/plugins/table/event-handlers.js +8 -7
  15. package/dist/esm/plugins/table/nodeviews/tableCell.js +3 -4
  16. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/column-state.js +1 -1
  17. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +8 -3
  18. package/dist/esm/plugins/table/utils/column-controls.js +1 -1
  19. package/dist/esm/version.json +1 -1
  20. package/package.json +4 -2
  21. package/src/__tests__/unit/analytics.ts +737 -0
  22. package/src/__tests__/unit/collab.ts +76 -0
  23. package/src/__tests__/unit/commands/sort.ts +230 -0
  24. package/src/__tests__/unit/copy-paste.ts +686 -0
  25. package/src/__tests__/unit/event-handlers/index.ts +106 -0
  26. package/src/__tests__/unit/event-handlers.ts +202 -0
  27. package/src/__tests__/unit/fix-tables.ts +156 -0
  28. package/src/__tests__/unit/floating-toolbar.ts +95 -0
  29. package/src/__tests__/unit/handlers.ts +81 -0
  30. package/src/__tests__/unit/hover-selection.ts +277 -0
  31. package/src/__tests__/unit/index-with-fake-timers.ts +106 -0
  32. package/src/__tests__/unit/index.ts +986 -0
  33. package/src/__tests__/unit/keymap.ts +602 -0
  34. package/src/__tests__/unit/layout.ts +196 -0
  35. package/src/__tests__/unit/nodeviews/cell.ts +167 -0
  36. package/src/__tests__/unit/pm-plugins/table-resizing/utils/resize-state.ts +33 -0
  37. package/src/__tests__/unit/sort-column.ts +512 -0
  38. package/src/__tests__/unit/transforms/delete-columns.ts +499 -0
  39. package/src/__tests__/unit/transforms/delete-rows.ts +557 -0
  40. package/src/__tests__/unit/transforms/merging.ts +374 -0
  41. package/src/__tests__/unit/ui/CornerControls.tsx +80 -0
  42. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +95 -0
  43. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +175 -0
  44. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +266 -0
  45. package/src/__tests__/unit/ui/RowControls.tsx +301 -0
  46. package/src/__tests__/unit/ui/TableFloatingControls.tsx +93 -0
  47. package/src/__tests__/unit/undo-redo.ts +202 -0
  48. package/src/__tests__/unit/utils/dom.ts +286 -0
  49. package/src/__tests__/unit/utils/nodes.ts +59 -0
  50. package/src/__tests__/unit/utils/row-controls.ts +176 -0
  51. package/src/__tests__/unit/utils/table.ts +93 -0
  52. package/src/__tests__/unit/utils.ts +652 -0
  53. package/src/plugins/table/event-handlers.ts +5 -6
  54. package/src/plugins/table/nodeviews/tableCell.tsx +5 -4
  55. package/src/plugins/table/pm-plugins/table-resizing/utils/column-state.ts +1 -1
  56. package/src/plugins/table/pm-plugins/table-resizing/utils/resize-logic.ts +6 -2
  57. package/src/plugins/table/utils/column-controls.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 0.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`3b93848ef7e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3b93848ef7e) - This changes addresses a bug that occurs when a user is resizing tables and receives a TypeError (found on Sentry). This change adds a null check on columns existing in the growColumn and shrinkColumn functions so that we do not try to access a column that doesn't exist.
8
+ - [`a1b80e72418`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a1b80e72418) - This change addresses a RangeError on `getRelativeDomCellWidths` found on Sentry. It sets the check for `colspan` to be strict equals to one as the value comes from the first table row's colspan DOM attribute and cannot be negative.
9
+
10
+ Reference: https://sentry.io/organizations/atlassian-2y/issues/3434914334/?project=5988900
11
+
12
+ - [`b63aa34e1fe`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b63aa34e1fe) - This change addresses a bug that occurs when a user is clicking into an element inside the table and receives a RangeError (found on Sentry). This change adds bounds, NaN, and type checks when reading a cellIndex from tableMap so that we don't pass NaN or undefined to the call to nodeAt.
13
+
3
14
  ## 0.0.6
4
15
 
5
16
  ### Patch Changes
@@ -37,11 +37,6 @@ var _utils3 = require("./utils");
37
37
 
38
38
  var _getAllowAddColumnCustomStep = require("./utils/get-allow-add-column-custom-step");
39
39
 
40
- // import {
41
- // isElementInTableCell,
42
- // isLastItemMediaGroup,
43
- // setNodeSelection,
44
- // } from '@atlaskit/editor-core/src/utils';
45
40
  // import { closestElement } from '@atlaskit/editor-core/src/utils/dom';
46
41
  var isFocusingCalendar = function isFocusingCalendar(event) {
47
42
  return event instanceof FocusEvent && event.relatedTarget instanceof HTMLElement && event.relatedTarget.getAttribute('aria-label') === 'calendar';
@@ -113,7 +108,13 @@ var handleClick = function handleClick(view, event) {
113
108
  _view$state = view.state,
114
109
  tr = _view$state.tr,
115
110
  paragraph = _view$state.schema.nodes.paragraph;
116
- var editorElement = table.node.nodeAt(map.map[cellIndex]);
111
+ var cellPos = map.map[cellIndex];
112
+
113
+ if (isNaN(cellPos) || cellPos === undefined || typeof cellPos !== 'number') {
114
+ return false;
115
+ }
116
+
117
+ var editorElement = table.node.nodeAt(cellPos);
117
118
  /** Only if the last item is media group, insert a paragraph */
118
119
 
119
120
  if ((0, _utils2.isLastItemMediaGroup)(editorElement)) {
@@ -19,6 +19,9 @@ var _prosemirrorModel = require("prosemirror-model");
19
19
 
20
20
  var _adfSchema = require("@atlaskit/adf-schema");
21
21
 
22
+ var DEFAULT_COL_SPAN = 1;
23
+ var DEFAULT_ROW_SPAN = 1;
24
+
22
25
  var TableCellNodeView = /*#__PURE__*/function () {
23
26
  function TableCellNodeView(node, view, getPos, getEditorFeatureFlags, observer) {
24
27
  (0, _classCallCheck2.default)(this, TableCellNodeView);
@@ -62,10 +65,7 @@ var TableCellNodeView = /*#__PURE__*/function () {
62
65
  // this can happen when undoing merge cells
63
66
 
64
67
 
65
- var defaultColspan = 1,
66
- defaultRowspan = 1;
67
-
68
- if (colspan !== (node.attrs.colspan || defaultColspan) || rowspan !== (node.attrs.rowspan || defaultRowspan)) {
68
+ if (colspan !== (node.attrs.colspan || DEFAULT_COL_SPAN) || rowspan !== (node.attrs.rowspan || DEFAULT_ROW_SPAN)) {
69
69
  return false;
70
70
  } // added + changed attributes
71
71
 
@@ -54,7 +54,7 @@ var getCellsRefsInColumn = function getCellsRefsInColumn(columnIndex, table, tab
54
54
  }
55
55
  });
56
56
  return cells;
57
- }; // calculates column withs based on `cells` DOM refs
57
+ }; // calculates column widths based on `cells` DOM refs
58
58
 
59
59
 
60
60
  exports.getCellsRefsInColumn = getCellsRefsInColumn;
@@ -24,8 +24,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
24
24
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
25
 
26
26
  var growColumn = function growColumn(state, colIndex, amount, selectedColumns) {
27
- // can't grow the last column
28
- if (!state.cols[colIndex + 1]) {
27
+ // can't grow if columns don't exist or it's the last column
28
+ if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
29
29
  return state;
30
30
  }
31
31
 
@@ -47,7 +47,12 @@ var growColumn = function growColumn(state, colIndex, amount, selectedColumns) {
47
47
  exports.growColumn = growColumn;
48
48
 
49
49
  var shrinkColumn = function shrinkColumn(state, colIndex, amount, selectedColumns) {
50
- // try to shrink dragging column by giving from the column to the right first
50
+ // can't shrink if columns don't exist
51
+ if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
52
+ return state;
53
+ } // try to shrink dragging column by giving from the column to the right first
54
+
55
+
51
56
  var res = moveSpaceFrom(state, colIndex, colIndex + 1, -amount);
52
57
  var newState = res.state;
53
58
  var isOverflownTable = (0, _resizeState.getTotalWidth)(newState) > newState.maxSize;
@@ -149,7 +149,7 @@ var getRelativeDomCellWidths = function getRelativeDomCellWidths(_ref) {
149
149
  // for cells in a table with unchanged column widths,
150
150
  // these are identified by the lack of colwidth data attribute,
151
151
  // return equally partitioned total cell width in DOM for each cell.
152
- if (colspan <= 1 || !colwidth) {
152
+ if (colspan === 1 || !colwidth) {
153
153
  return new Array(colspan).fill(width / colspan);
154
154
  } // For cells that have colSpan > 1 and
155
155
  // are part of a table with resized columns
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.6"
3
+ "version": "0.0.7"
4
4
  }
@@ -2,12 +2,7 @@ import { Selection, TextSelection } from 'prosemirror-state';
2
2
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
3
3
  import { TableMap } from '@atlaskit/editor-tables/table-map';
4
4
  import { cellAround, findCellRectClosestToPos, findTable, getSelectionRect, removeTable } from '@atlaskit/editor-tables/utils';
5
- import { browser } from '@atlaskit/editor-common/utils'; // import {
6
- // isElementInTableCell,
7
- // isLastItemMediaGroup,
8
- // setNodeSelection,
9
- // } from '@atlaskit/editor-core/src/utils';
10
-
5
+ import { browser } from '@atlaskit/editor-common/utils';
11
6
  import { isElementInTableCell, isLastItemMediaGroup, setNodeSelection } from '@atlaskit/editor-common/utils'; // import { closestElement } from '@atlaskit/editor-core/src/utils/dom';
12
7
 
13
8
  import { closestElement } from '@atlaskit/editor-common/utils';
@@ -89,7 +84,13 @@ export const handleClick = (view, event) => {
89
84
  }
90
85
  }
91
86
  } = view;
92
- const editorElement = table.node.nodeAt(map.map[cellIndex]);
87
+ const cellPos = map.map[cellIndex];
88
+
89
+ if (isNaN(cellPos) || cellPos === undefined || typeof cellPos !== 'number') {
90
+ return false;
91
+ }
92
+
93
+ const editorElement = table.node.nodeAt(cellPos);
93
94
  /** Only if the last item is media group, insert a paragraph */
94
95
 
95
96
  if (isLastItemMediaGroup(editorElement)) {
@@ -1,6 +1,8 @@
1
1
  import uuid from 'uuid';
2
2
  import { DOMSerializer } from 'prosemirror-model';
3
3
  import { getCellDomAttrs, getCellAttrs } from '@atlaskit/adf-schema';
4
+ const DEFAULT_COL_SPAN = 1;
5
+ const DEFAULT_ROW_SPAN = 1;
4
6
  export default class TableCellNodeView {
5
7
  constructor(node, view, getPos, getEditorFeatureFlags, observer) {
6
8
  this.view = view;
@@ -37,10 +39,7 @@ export default class TableCellNodeView {
37
39
  } = getCellAttrs(this.dom); // need to rerender when colspan/rowspan in dom are different from the node attrs
38
40
  // this can happen when undoing merge cells
39
41
 
40
- const defaultColspan = 1,
41
- defaultRowspan = 1;
42
-
43
- if (colspan !== (node.attrs.colspan || defaultColspan) || rowspan !== (node.attrs.rowspan || defaultRowspan)) {
42
+ if (colspan !== (node.attrs.colspan || DEFAULT_COL_SPAN) || rowspan !== (node.attrs.rowspan || DEFAULT_ROW_SPAN)) {
44
43
  return false;
45
44
  } // added + changed attributes
46
45
 
@@ -35,7 +35,7 @@ export const getCellsRefsInColumn = (columnIndex, table, tableStart, domAtPos) =
35
35
  }
36
36
  });
37
37
  return cells;
38
- }; // calculates column withs based on `cells` DOM refs
38
+ }; // calculates column widths based on `cells` DOM refs
39
39
 
40
40
  export const calculateColumnWidth = (cells, calculateColumnWidthCb) => {
41
41
  let maxColWidth = 0;
@@ -1,8 +1,8 @@
1
1
  import { getFreeSpace } from './column-state';
2
2
  import { bulkColumnsResize, getTotalWidth } from './resize-state';
3
3
  export const growColumn = (state, colIndex, amount, selectedColumns) => {
4
- // can't grow the last column
5
- if (!state.cols[colIndex + 1]) {
4
+ // can't grow if columns don't exist or it's the last column
5
+ if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
6
6
  return state;
7
7
  }
8
8
 
@@ -21,7 +21,12 @@ export const growColumn = (state, colIndex, amount, selectedColumns) => {
21
21
  return newState;
22
22
  };
23
23
  export const shrinkColumn = (state, colIndex, amount, selectedColumns) => {
24
- // try to shrink dragging column by giving from the column to the right first
24
+ // can't shrink if columns don't exist
25
+ if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
26
+ return state;
27
+ } // try to shrink dragging column by giving from the column to the right first
28
+
29
+
25
30
  const res = moveSpaceFrom(state, colIndex, colIndex + 1, -amount);
26
31
  let newState = res.state;
27
32
  const isOverflownTable = getTotalWidth(newState) > newState.maxSize;
@@ -115,7 +115,7 @@ const getRelativeDomCellWidths = ({
115
115
  // for cells in a table with unchanged column widths,
116
116
  // these are identified by the lack of colwidth data attribute,
117
117
  // return equally partitioned total cell width in DOM for each cell.
118
- if (colspan <= 1 || !colwidth) {
118
+ if (colspan === 1 || !colwidth) {
119
119
  return new Array(colspan).fill(width / colspan);
120
120
  } // For cells that have colSpan > 1 and
121
121
  // are part of a table with resized columns
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.6"
3
+ "version": "0.0.7"
4
4
  }
@@ -3,12 +3,7 @@ import { Selection, TextSelection } from 'prosemirror-state';
3
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { TableMap } from '@atlaskit/editor-tables/table-map';
5
5
  import { cellAround, findCellRectClosestToPos, findTable, getSelectionRect, removeTable } from '@atlaskit/editor-tables/utils';
6
- import { browser } from '@atlaskit/editor-common/utils'; // import {
7
- // isElementInTableCell,
8
- // isLastItemMediaGroup,
9
- // setNodeSelection,
10
- // } from '@atlaskit/editor-core/src/utils';
11
-
6
+ import { browser } from '@atlaskit/editor-common/utils';
12
7
  import { isElementInTableCell, isLastItemMediaGroup, setNodeSelection } from '@atlaskit/editor-common/utils'; // import { closestElement } from '@atlaskit/editor-core/src/utils/dom';
13
8
 
14
9
  import { closestElement } from '@atlaskit/editor-common/utils';
@@ -84,7 +79,13 @@ export var handleClick = function handleClick(view, event) {
84
79
  _view$state = view.state,
85
80
  tr = _view$state.tr,
86
81
  paragraph = _view$state.schema.nodes.paragraph;
87
- var editorElement = table.node.nodeAt(map.map[cellIndex]);
82
+ var cellPos = map.map[cellIndex];
83
+
84
+ if (isNaN(cellPos) || cellPos === undefined || typeof cellPos !== 'number') {
85
+ return false;
86
+ }
87
+
88
+ var editorElement = table.node.nodeAt(cellPos);
88
89
  /** Only if the last item is media group, insert a paragraph */
89
90
 
90
91
  if (isLastItemMediaGroup(editorElement)) {
@@ -4,6 +4,8 @@ import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import uuid from 'uuid';
5
5
  import { DOMSerializer } from 'prosemirror-model';
6
6
  import { getCellDomAttrs, getCellAttrs } from '@atlaskit/adf-schema';
7
+ var DEFAULT_COL_SPAN = 1;
8
+ var DEFAULT_ROW_SPAN = 1;
7
9
 
8
10
  var TableCellNodeView = /*#__PURE__*/function () {
9
11
  function TableCellNodeView(node, view, getPos, getEditorFeatureFlags, observer) {
@@ -49,10 +51,7 @@ var TableCellNodeView = /*#__PURE__*/function () {
49
51
  // this can happen when undoing merge cells
50
52
 
51
53
 
52
- var defaultColspan = 1,
53
- defaultRowspan = 1;
54
-
55
- if (colspan !== (node.attrs.colspan || defaultColspan) || rowspan !== (node.attrs.rowspan || defaultRowspan)) {
54
+ if (colspan !== (node.attrs.colspan || DEFAULT_COL_SPAN) || rowspan !== (node.attrs.rowspan || DEFAULT_ROW_SPAN)) {
56
55
  return false;
57
56
  } // added + changed attributes
58
57
 
@@ -35,7 +35,7 @@ export var getCellsRefsInColumn = function getCellsRefsInColumn(columnIndex, tab
35
35
  }
36
36
  });
37
37
  return cells;
38
- }; // calculates column withs based on `cells` DOM refs
38
+ }; // calculates column widths based on `cells` DOM refs
39
39
 
40
40
  export var calculateColumnWidth = function calculateColumnWidth(cells, calculateColumnWidthCb) {
41
41
  var maxColWidth = 0;
@@ -9,8 +9,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
9
9
  import { getFreeSpace } from './column-state';
10
10
  import { bulkColumnsResize, getTotalWidth } from './resize-state';
11
11
  export var growColumn = function growColumn(state, colIndex, amount, selectedColumns) {
12
- // can't grow the last column
13
- if (!state.cols[colIndex + 1]) {
12
+ // can't grow if columns don't exist or it's the last column
13
+ if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
14
14
  return state;
15
15
  }
16
16
 
@@ -29,7 +29,12 @@ export var growColumn = function growColumn(state, colIndex, amount, selectedCol
29
29
  return newState;
30
30
  };
31
31
  export var shrinkColumn = function shrinkColumn(state, colIndex, amount, selectedColumns) {
32
- // try to shrink dragging column by giving from the column to the right first
32
+ // can't shrink if columns don't exist
33
+ if (!state.cols[colIndex] || !state.cols[colIndex + 1]) {
34
+ return state;
35
+ } // try to shrink dragging column by giving from the column to the right first
36
+
37
+
33
38
  var res = moveSpaceFrom(state, colIndex, colIndex + 1, -amount);
34
39
  var newState = res.state;
35
40
  var isOverflownTable = getTotalWidth(newState) > newState.maxSize;
@@ -119,7 +119,7 @@ var getRelativeDomCellWidths = function getRelativeDomCellWidths(_ref) {
119
119
  // for cells in a table with unchanged column widths,
120
120
  // these are identified by the lack of colwidth data attribute,
121
121
  // return equally partitioned total cell width in DOM for each cell.
122
- if (colspan <= 1 || !colwidth) {
122
+ if (colspan === 1 || !colwidth) {
123
123
  return new Array(colspan).fill(width / colspan);
124
124
  } // For cells that have colSpan > 1 and
125
125
  // are part of a table with resized columns
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.6"
3
+ "version": "0.0.7"
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@atlaskit/adf-schema": "^24.0.0",
28
- "@atlaskit/editor-common": "^70.0.0",
28
+ "@atlaskit/editor-common": "^70.1.0",
29
29
  "@atlaskit/editor-shared-styles": "^2.2.0",
30
30
  "@atlaskit/editor-tables": "^2.2.0",
31
31
  "@atlaskit/icon": "^21.11.0",
@@ -56,6 +56,7 @@
56
56
  "styled-components": "^3.2.6"
57
57
  },
58
58
  "devDependencies": {
59
+ "@atlaskit/analytics-next": "^8.3.3",
59
60
  "@atlaskit/button": "^16.3.0",
60
61
  "@atlaskit/editor-core": "^173.0.0",
61
62
  "@atlaskit/editor-test-helpers": "^17.2.0",
@@ -63,6 +64,7 @@
63
64
  "@atlaskit/logo": "^13.10.0",
64
65
  "@atlaskit/media-integration-test-helpers": "^2.6.0",
65
66
  "@atlaskit/synchrony-test-helpers": "^2.3.0",
67
+ "@atlaskit/util-data-test": "^17.5.5",
66
68
  "@atlaskit/visual-regression": "*",
67
69
  "@atlaskit/webdriver-runner": "*",
68
70
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",