@atlaskit/editor-plugin-table 1.2.5 → 1.2.6

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 (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/plugins/table/commands/selection.js +4 -4
  3. package/dist/cjs/plugins/table/event-handlers.js +3 -3
  4. package/dist/cjs/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -6
  5. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +9 -16
  6. package/dist/cjs/plugins/table/pm-plugins/table-local-id.js +65 -37
  7. package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
  8. package/dist/cjs/plugins/table/transforms/delete-rows.js +2 -2
  9. package/dist/cjs/plugins/table/types.js +8 -8
  10. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +6 -7
  11. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +1 -1
  12. package/dist/cjs/version.json +1 -1
  13. package/dist/es2019/plugins/table/commands/selection.js +3 -3
  14. package/dist/es2019/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -7
  15. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +8 -14
  16. package/dist/es2019/plugins/table/pm-plugins/table-local-id.js +47 -38
  17. package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
  18. package/dist/es2019/plugins/table/types.js +6 -6
  19. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +6 -8
  20. package/dist/es2019/version.json +1 -1
  21. package/dist/esm/plugins/table/commands/selection.js +3 -3
  22. package/dist/esm/plugins/table/event-handlers.js +3 -3
  23. package/dist/esm/plugins/table/nodeviews/OverflowShadowsObserver.js +5 -6
  24. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +9 -16
  25. package/dist/esm/plugins/table/pm-plugins/table-local-id.js +66 -38
  26. package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/resize-logic.js +4 -4
  27. package/dist/esm/plugins/table/transforms/delete-rows.js +2 -2
  28. package/dist/esm/plugins/table/types.js +6 -6
  29. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +6 -7
  30. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +1 -1
  31. package/dist/esm/version.json +1 -1
  32. package/package.json +4 -4
  33. package/src/__tests__/unit/pm-plugins/table-local-id.ts +2 -14
  34. package/src/plugins/table/pm-plugins/table-local-id.ts +57 -41
@@ -27,8 +27,7 @@ export const RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
27
27
  *
28
28
  */
29
29
 
30
- export let TableDecorations;
31
- (function (TableDecorations) {
30
+ export let TableDecorations = /*#__PURE__*/function (TableDecorations) {
32
31
  TableDecorations["ALL_CONTROLS_HOVER"] = "CONTROLS_HOVER";
33
32
  TableDecorations["ROW_CONTROLS_HOVER"] = "ROW_CONTROLS_HOVER";
34
33
  TableDecorations["COLUMN_CONTROLS_HOVER"] = "COLUMN_CONTROLS_HOVER";
@@ -39,7 +38,8 @@ export let TableDecorations;
39
38
  TableDecorations["COLUMN_RESIZING_HANDLE"] = "COLUMN_RESIZING_HANDLE";
40
39
  TableDecorations["COLUMN_RESIZING_HANDLE_LINE"] = "COLUMN_RESIZING_HANDLE_LINE";
41
40
  TableDecorations["LAST_CELL_ELEMENT"] = "LAST_CELL_ELEMENT";
42
- })(TableDecorations || (TableDecorations = {}));
41
+ return TableDecorations;
42
+ }({});
43
43
  export const TableCssClassName = {
44
44
  ...TableSharedCssClassName,
45
45
  COLUMN_CONTROLS: `${tablePrefixSelector}-column-controls`,
@@ -102,8 +102,8 @@ export const TableCssClassName = {
102
102
  WITH_RESIZE_LINE: `${tablePrefixSelector}-column-resize-line`,
103
103
  WITH_RESIZE_LINE_LAST_COLUMN: `${tablePrefixSelector}-column-resize-line-last-column`
104
104
  };
105
- export let ShadowEvent;
106
- (function (ShadowEvent) {
105
+ export let ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
107
106
  ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
108
107
  ShadowEvent["SHOW_AFTER_SHADOW"] = "showAfterShadow";
109
- })(ShadowEvent || (ShadowEvent = {}));
108
+ return ShadowEvent;
109
+ }({});
@@ -83,6 +83,12 @@ class FloatingDeleteButton extends Component {
83
83
  } = this.props.editorView;
84
84
  return clearHoverSelection()(state, dispatch);
85
85
  });
86
+ /**
87
+ *
88
+ *
89
+ * @private
90
+ * @memberof FloatingDeleteButton
91
+ */
86
92
  _defineProperty(this, "handleClick", event => {
87
93
  event.preventDefault();
88
94
  const {
@@ -207,14 +213,6 @@ class FloatingDeleteButton extends Component {
207
213
  // Do nothing if doesn't change anything
208
214
  return null;
209
215
  }
210
-
211
- /**
212
- *
213
- *
214
- * @private
215
- * @memberof FloatingDeleteButton
216
- */
217
-
218
216
  render() {
219
217
  const {
220
218
  mountPoint,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "sideEffects": false
5
5
  }
@@ -3,11 +3,11 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
3
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
4
4
  import { findTable, isTableSelected } from '@atlaskit/editor-tables/utils';
5
5
  import { RelativeSelectionPos, GapCursorSelection, Side, isSelectionAtStartOfNode, isSelectionAtEndOfNode } from '@atlaskit/editor-common/selection';
6
- export var TableSelectionDirection;
7
- (function (TableSelectionDirection) {
6
+ export var TableSelectionDirection = /*#__PURE__*/function (TableSelectionDirection) {
8
7
  TableSelectionDirection["TopToBottom"] = "TopToBottom";
9
8
  TableSelectionDirection["BottomToTop"] = "BottomToTop";
10
- })(TableSelectionDirection || (TableSelectionDirection = {}));
9
+ return TableSelectionDirection;
10
+ }({});
11
11
  export var arrowLeftFromTable = function arrowLeftFromTable(editorSelectionAPI) {
12
12
  return function () {
13
13
  return function (state, dispatch) {
@@ -213,8 +213,8 @@ export var handleMouseMove = function handleMouseMove(getEditorFeatureFlags) {
213
213
  var _getEditorFeatureFlag = getEditorFeatureFlags(),
214
214
  mouseMoveOptimization = _getEditorFeatureFlag.mouseMoveOptimization;
215
215
  if (!isResizeHandleDecoration(element) && isCell(element)) {
216
- var positionColumn = getMousePositionHorizontalRelativeByElement(event, mouseMoveOptimization, elementContentRects, RESIZE_HANDLE_AREA_DECORATION_GAP);
217
- if (positionColumn !== null) {
216
+ var _positionColumn = getMousePositionHorizontalRelativeByElement(event, mouseMoveOptimization, elementContentRects, RESIZE_HANDLE_AREA_DECORATION_GAP);
217
+ if (_positionColumn !== null) {
218
218
  var _state4 = view.state,
219
219
  _dispatch5 = view.dispatch;
220
220
  var _getPluginState5 = getPluginState(_state4),
@@ -224,7 +224,7 @@ export var handleMouseMove = function handleMouseMove(getEditorFeatureFlags) {
224
224
  var cellStartPosition = view.posAtDOM(tableCell, 0);
225
225
  var rect = findCellRectClosestToPos(_state4.doc.resolve(cellStartPosition));
226
226
  if (rect) {
227
- var columnEndIndexTarget = positionColumn === 'left' ? rect.left : rect.right;
227
+ var columnEndIndexTarget = _positionColumn === 'left' ? rect.left : rect.right;
228
228
  var rowIndexTarget = rect.top;
229
229
  if (columnEndIndexTarget !== resizeHandleColumnIndex || rowIndexTarget !== resizeHandleRowIndex || !hasResizeHandler({
230
230
  target: element,
@@ -69,6 +69,11 @@ export var OverflowShadowsObserver = /*#__PURE__*/function () {
69
69
  _this.shadowsObserved = true;
70
70
  }
71
71
  });
72
+ /**
73
+ * Takes a heightStyle if it can be computed in a less expensive manner,
74
+ * e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
75
+ * reading it from sticky cell
76
+ */
72
77
  _defineProperty(this, "updateStickyShadows", function (stickyRowHeight) {
73
78
  var _this$wrapper, _this$wrapper2, _this$wrapper2$parent, _this$wrapper3, _this$wrapper3$parent;
74
79
  if (!_this.isSticky) {
@@ -115,12 +120,6 @@ export var OverflowShadowsObserver = /*#__PURE__*/function () {
115
120
  var stickyCell = stickyRow && stickyRow.firstElementChild;
116
121
  return stickyCell;
117
122
  }
118
-
119
- /**
120
- * Takes a heightStyle if it can be computed in a less expensive manner,
121
- * e.g. bounds on an IntersectionObserverEntry, otherwise proceed with
122
- * reading it from sticky cell
123
- */
124
123
  }, {
125
124
  key: "dispose",
126
125
  value: function dispose() {
@@ -61,15 +61,20 @@ export var TableRowNodeView = /*#__PURE__*/function () {
61
61
  function TableRowNodeView(node, view, getPos, eventDispatcher, getEditorFeatureFlags) {
62
62
  var _this = this;
63
63
  _classCallCheck(this, TableRowNodeView);
64
+ // this is the sticky header table row
64
65
  _defineProperty(this, "colControlsOffset", 0);
65
66
  _defineProperty(this, "focused", false);
66
67
  _defineProperty(this, "topPosEditorElement", 0);
67
68
  _defineProperty(this, "stickyHeadersOptimization", false);
68
69
  _defineProperty(this, "sentinels", {});
70
+ /* external events */
69
71
  _defineProperty(this, "listening", false);
70
72
  _defineProperty(this, "headerRowMouseScrollEnd", debounce(function () {
71
73
  _this.dom.classList.remove('no-pointer-events');
72
74
  }, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT));
75
+ // When the header is sticky, the header row is set to position: fixed
76
+ // This prevents mouse wheel scrolling on the scroll-parent div when user's mouse is hovering the header row.
77
+ // This fix sets pointer-events: none on the header row briefly to avoid this behaviour
73
78
  _defineProperty(this, "headerRowMouseScroll", throttle(function () {
74
79
  if (_this.isSticky) {
75
80
  _this.dom.classList.add('no-pointer-events');
@@ -128,6 +133,7 @@ export var TableRowNodeView = /*#__PURE__*/function () {
128
133
  _this.dom.scrollLeft = wrapper.scrollLeft;
129
134
  _this.lastTimePainted = performance.now();
130
135
  });
136
+ /* receive external events */
131
137
  _defineProperty(this, "onTablePluginState", function (state) {
132
138
  var tableRef = state.tableRef;
133
139
  var focusChanged = false;
@@ -263,12 +269,14 @@ export var TableRowNodeView = /*#__PURE__*/function () {
263
269
  _defineProperty(this, "getWrapperRefTop", function (wrapper) {
264
270
  return Math.round(getTop(wrapper)) + _this.getWrapperoffset();
265
271
  });
272
+ // TODO: rename!
266
273
  _defineProperty(this, "getScrolledTableTop", function (wrapper) {
267
274
  return _this.getWrapperRefTop(wrapper) - _this.topPosEditorElement;
268
275
  });
269
276
  _defineProperty(this, "getCurrentTableTop", function (tree) {
270
277
  return _this.getScrolledTableTop(tree.wrapper) + tree.table.clientHeight;
271
278
  });
279
+ /* emit external events */
272
280
  _defineProperty(this, "padding", 0);
273
281
  _defineProperty(this, "top", 0);
274
282
  _defineProperty(this, "emitOn", function (top, padding) {
@@ -316,18 +324,9 @@ export var TableRowNodeView = /*#__PURE__*/function () {
316
324
  this.subscribe();
317
325
  }
318
326
  }
319
-
320
- /* external events */
321
-
322
- // When the header is sticky, the header row is set to position: fixed
323
- // This prevents mouse wheel scrolling on the scroll-parent div when user's mouse is hovering the header row.
324
- // This fix sets pointer-events: none on the header row briefly to avoid this behaviour
325
327
  _createClass(TableRowNodeView, [{
326
328
  key: "tree",
327
- get:
328
- // this is the sticky header table row
329
-
330
- function get() {
329
+ get: function get() {
331
330
  return getTree(this.dom);
332
331
  }
333
332
  }, {
@@ -556,12 +555,6 @@ export var TableRowNodeView = /*#__PURE__*/function () {
556
555
  }
557
556
  return true;
558
557
  }
559
-
560
- /* receive external events */
561
-
562
- // TODO: rename!
563
-
564
- /* emit external events */
565
558
  }]);
566
559
  return TableRowNodeView;
567
560
  }();
@@ -1,4 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
2
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
6
  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) { _defineProperty(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; }
4
7
  /**
@@ -18,21 +21,12 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
18
21
  import { PluginKey } from 'prosemirror-state';
19
22
  import rafSchedule from 'raf-schd';
20
23
  import { uuid } from '@atlaskit/adf-schema';
21
- import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
24
+ import { stepHasSlice } from '@atlaskit/editor-common/utils';
22
25
  var pluginKey = new PluginKey('tableLocalIdPlugin');
23
26
  var getPluginState = function getPluginState(state) {
24
27
  return state && pluginKey.getState(state);
25
28
  };
26
29
 
27
- /**
28
- * Traverses a transaction's steps to see if we're inserting any tables
29
- */
30
- var checkIsAddingTable = function checkIsAddingTable(transaction, nodeType) {
31
- return transaction.steps.some(function (step) {
32
- return stepAddsOneOf(step, new Set([nodeType]));
33
- });
34
- };
35
-
36
30
  /**
37
31
  * Ensures uniqueness of `localId`s on tables being created or edited
38
32
  */
@@ -125,7 +119,9 @@ var createPlugin = function createPlugin(dispatch) {
125
119
  var modified = false;
126
120
  var tr = newState.tr;
127
121
  var table = newState.schema.nodes.table;
128
- var idsObserved = new Set();
122
+ var addedTableNodes = new Set();
123
+ var addedTableNodePos = new Map();
124
+ var localIds = new Set();
129
125
  transactions.forEach(function (transaction) {
130
126
  if (!transaction.docChanged) {
131
127
  return;
@@ -138,38 +134,70 @@ var createPlugin = function createPlugin(dispatch) {
138
134
  return;
139
135
  }
140
136
 
141
- /** Check if we're actually inserting a table, otherwise we can ignore this tr */
142
- var isAddingTable = checkIsAddingTable(transaction, table);
143
- if (!isAddingTable) {
144
- return;
145
- }
146
-
147
- // Can't simply look at changed nodes, as we could be adding a table
148
- newState.doc.descendants(function (node, pos) {
149
- var isTable = node.type === table;
150
- var localId = node.attrs.localId;
151
-
152
- // Dealing with a table - make sure it's a unique ID
153
- if (isTable) {
154
- if (localId && !idsObserved.has(localId)) {
155
- idsObserved.add(localId);
156
- // Also add a localId if it happens to not have one,
157
- } else if (!localId || idsObserved.has(localId)) {
158
- modified = true;
159
- tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
160
- localId: uuid.generate()
161
- }));
137
+ /** Get the tables we are adding and their position */
138
+ var _iterator = _createForOfIteratorHelper(transaction.steps),
139
+ _step;
140
+ try {
141
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
142
+ var step = _step.value;
143
+ if (!stepHasSlice(step)) {
144
+ continue;
162
145
  }
163
- return false;
146
+ step.slice.content.descendants(function (node, pos) {
147
+ if (node.type === table) {
148
+ addedTableNodes.add(node);
149
+ }
150
+ return true;
151
+ });
164
152
  }
153
+ } catch (err) {
154
+ _iterator.e(err);
155
+ } finally {
156
+ _iterator.f();
157
+ }
158
+ });
159
+ if (!addedTableNodes.size) {
160
+ return;
161
+ }
165
162
 
166
- /**
167
- * Otherwise continue traversing, we can encounter tables nested in
168
- * expands/bodiedExtensions
169
- */
163
+ // Get the existing localIds on the page
164
+ newState.doc.descendants(function (node, pos) {
165
+ // Skip if this is position of added table
166
+ if (addedTableNodes.has(node)) {
167
+ addedTableNodePos.set(node, pos);
168
+ return false;
169
+ }
170
+ if (node.type !== table) {
170
171
  return true;
171
- });
172
+ }
173
+ localIds.add(node.attrs.localId);
174
+
175
+ // can't have table within a table
176
+ return false;
172
177
  });
178
+
179
+ // If the added nodes have duplicate id, generate a new one
180
+ var _iterator2 = _createForOfIteratorHelper(addedTableNodes),
181
+ _step2;
182
+ try {
183
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
184
+ var node = _step2.value;
185
+ if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
186
+ var pos = addedTableNodePos.get(node);
187
+ if (pos === undefined) {
188
+ continue;
189
+ }
190
+ tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, node.attrs), {}, {
191
+ localId: uuid.generate()
192
+ }));
193
+ modified = true;
194
+ }
195
+ }
196
+ } catch (err) {
197
+ _iterator2.e(err);
198
+ } finally {
199
+ _iterator2.f();
200
+ }
173
201
  if (modified) {
174
202
  return tr;
175
203
  }
@@ -87,12 +87,12 @@ export function reduceSpace(state, amount) {
87
87
  }
88
88
  return state;
89
89
  }
90
- var ColType; // TODO: should handle when destIdx:
91
- // - is beyond the range, and then not give it back
92
- (function (ColType) {
90
+ var ColType = /*#__PURE__*/function (ColType) {
93
91
  ColType["SOURCE"] = "src";
94
92
  ColType["DEST"] = "dest";
95
- })(ColType || (ColType = {}));
93
+ return ColType;
94
+ }(ColType || {}); // TODO: should handle when destIdx:
95
+ // - is beyond the range, and then not give it back
96
96
  function moveSpaceFrom(state, srcIdx, destIdx, amount) {
97
97
  var useFreeSpace = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
98
98
  var srcCol = state.cols[srcIdx];
@@ -36,7 +36,7 @@ export var deleteRows = function deleteRows(rect) {
36
36
  var _loop = function _loop(rowIndex) {
37
37
  var rowCells = [];
38
38
  var row = table.node.child(rowIndex);
39
- var _loop2 = function _loop2(colIndex) {
39
+ var _loop2 = function _loop2() {
40
40
  var cellPos = map.map[rowIndex * map.width + colIndex];
41
41
  var cell = table.node.nodeAt(cellPos);
42
42
  if (!cell) {
@@ -90,7 +90,7 @@ export var deleteRows = function deleteRows(rect) {
90
90
  }
91
91
  };
92
92
  for (var colIndex = 0; colIndex < map.width; colIndex++) {
93
- var _ret = _loop2(colIndex);
93
+ var _ret = _loop2();
94
94
  if (_ret === "continue") continue;
95
95
  }
96
96
  if (rowCells.length) {
@@ -30,8 +30,7 @@ export var RESIZE_HANDLE_AREA_DECORATION_GAP = 30;
30
30
  *
31
31
  */
32
32
 
33
- export var TableDecorations;
34
- (function (TableDecorations) {
33
+ export var TableDecorations = /*#__PURE__*/function (TableDecorations) {
35
34
  TableDecorations["ALL_CONTROLS_HOVER"] = "CONTROLS_HOVER";
36
35
  TableDecorations["ROW_CONTROLS_HOVER"] = "ROW_CONTROLS_HOVER";
37
36
  TableDecorations["COLUMN_CONTROLS_HOVER"] = "COLUMN_CONTROLS_HOVER";
@@ -42,7 +41,8 @@ export var TableDecorations;
42
41
  TableDecorations["COLUMN_RESIZING_HANDLE"] = "COLUMN_RESIZING_HANDLE";
43
42
  TableDecorations["COLUMN_RESIZING_HANDLE_LINE"] = "COLUMN_RESIZING_HANDLE_LINE";
44
43
  TableDecorations["LAST_CELL_ELEMENT"] = "LAST_CELL_ELEMENT";
45
- })(TableDecorations || (TableDecorations = {}));
44
+ return TableDecorations;
45
+ }({});
46
46
  export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssClassName), {}, {
47
47
  COLUMN_CONTROLS: "".concat(tablePrefixSelector, "-column-controls"),
48
48
  COLUMN_CONTROLS_DECORATIONS: "".concat(tablePrefixSelector, "-column-controls-decoration"),
@@ -104,8 +104,8 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
104
104
  WITH_RESIZE_LINE: "".concat(tablePrefixSelector, "-column-resize-line"),
105
105
  WITH_RESIZE_LINE_LAST_COLUMN: "".concat(tablePrefixSelector, "-column-resize-line-last-column")
106
106
  });
107
- export var ShadowEvent;
108
- (function (ShadowEvent) {
107
+ export var ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
109
108
  ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
110
109
  ShadowEvent["SHOW_AFTER_SHADOW"] = "showAfterShadow";
111
- })(ShadowEvent || (ShadowEvent = {}));
110
+ return ShadowEvent;
111
+ }({});
@@ -95,6 +95,12 @@ var FloatingDeleteButton = /*#__PURE__*/function (_Component) {
95
95
  dispatch = _this$props$editorVie2.dispatch;
96
96
  return clearHoverSelection()(state, dispatch);
97
97
  });
98
+ /**
99
+ *
100
+ *
101
+ * @private
102
+ * @memberof FloatingDeleteButton
103
+ */
98
104
  _defineProperty(_assertThisInitialized(_this), "handleClick", function (event) {
99
105
  event.preventDefault();
100
106
  var editorAnalyticsAPI = _this.props.editorAnalyticsAPI;
@@ -277,13 +283,6 @@ var FloatingDeleteButton = /*#__PURE__*/function (_Component) {
277
283
  // Do nothing if doesn't change anything
278
284
  return null;
279
285
  }
280
-
281
- /**
282
- *
283
- *
284
- * @private
285
- * @memberof FloatingDeleteButton
286
- */
287
286
  }]);
288
287
  return FloatingDeleteButton;
289
288
  }(Component);
@@ -7,7 +7,7 @@ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
8
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9
9
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
11
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
12
12
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
13
  import React, { Component } from 'react';
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "sideEffects": false
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@atlaskit/adf-schema": "^25.5.0",
22
- "@atlaskit/editor-common": "^72.9.0",
22
+ "@atlaskit/editor-common": "^73.0.0",
23
23
  "@atlaskit/editor-palette": "1.3.0",
24
24
  "@atlaskit/editor-shared-styles": "^2.3.0",
25
25
  "@atlaskit/editor-tables": "^2.2.0",
@@ -52,8 +52,8 @@
52
52
  "devDependencies": {
53
53
  "@atlaskit/analytics-next": "^9.0.0",
54
54
  "@atlaskit/button": "^16.6.0",
55
- "@atlaskit/editor-core": "^182.1.0",
56
- "@atlaskit/editor-plugin-feature-flags": "^0.0.3",
55
+ "@atlaskit/editor-core": "^182.2.0",
56
+ "@atlaskit/editor-plugin-feature-flags": "^0.0.4",
57
57
  "@atlaskit/editor-test-helpers": "^18.2.0",
58
58
  "@atlaskit/link-provider": "^1.5.0",
59
59
  "@atlaskit/logo": "^13.13.0",
@@ -347,23 +347,11 @@ describe('table local id plugin', () => {
347
347
  editorView.updateState(state3);
348
348
  dispatchPasteEvent(editorView, { html: dom.innerHTML, plain: text });
349
349
 
350
- /**
351
- * The end result order of IDs that we'll now observe is the following:
352
- * 1. flooFirst
353
- * 2. flooThird
354
- * 3. flooSecond
355
- *
356
- * This is because we had `flooFirst` in our clipboard. We've now pasted
357
- * it into the expand, so that becomes the first observed instance of
358
- * the table. The "third" ID (second unique regeneration) then gets
359
- * replaced in the first layout column.
360
- *
361
- */
362
350
  expect(editorView.state.doc).toEqualDocument(
363
351
  doc(
364
- expand({ title: '' })(generateTableWithLocalId(flooFirst)),
352
+ expand({ title: '' })(generateTableWithLocalId(flooThird)),
365
353
  layoutSection(
366
- layoutColumn({ width: 50 })(generateTableWithLocalId(flooThird)),
354
+ layoutColumn({ width: 50 })(generateTableWithLocalId(flooFirst)),
367
355
  layoutColumn({ width: 50 })(generateTableWithLocalId(flooSecond)),
368
356
  ),
369
357
  p(),
@@ -12,13 +12,13 @@
12
12
  */
13
13
  import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
14
14
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
15
- import { EditorState, PluginKey, Transaction } from 'prosemirror-state';
16
- import { NodeType } from 'prosemirror-model';
15
+ import { EditorState, PluginKey } from 'prosemirror-state';
16
+ import { Node as ProsemirrorNode } from 'prosemirror-model';
17
17
  import rafSchedule from 'raf-schd';
18
18
 
19
19
  import { uuid } from '@atlaskit/adf-schema';
20
20
 
21
- import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
21
+ import { stepHasSlice } from '@atlaskit/editor-common/utils';
22
22
 
23
23
  interface TableLocalIdPluginState {
24
24
  // One time parse for initial load with existing tables without localIds
@@ -31,15 +31,6 @@ const getPluginState = (
31
31
  ): TableLocalIdPluginState | undefined | null =>
32
32
  state && pluginKey.getState(state);
33
33
 
34
- /**
35
- * Traverses a transaction's steps to see if we're inserting any tables
36
- */
37
- const checkIsAddingTable = (transaction: Transaction, nodeType: NodeType) => {
38
- return transaction.steps.some((step) =>
39
- stepAddsOneOf(step, new Set([nodeType])),
40
- );
41
- };
42
-
43
34
  /**
44
35
  * Ensures uniqueness of `localId`s on tables being created or edited
45
36
  */
@@ -143,7 +134,9 @@ const createPlugin = (dispatch: Dispatch) =>
143
134
  const tr = newState.tr;
144
135
  const { table } = newState.schema.nodes;
145
136
 
146
- const idsObserved = new Set<string>();
137
+ const addedTableNodes: Set<ProsemirrorNode> = new Set();
138
+ const addedTableNodePos: Map<ProsemirrorNode, number> = new Map();
139
+ const localIds: Set<string> = new Set();
147
140
 
148
141
  transactions.forEach((transaction) => {
149
142
  if (!transaction.docChanged) {
@@ -157,43 +150,66 @@ const createPlugin = (dispatch: Dispatch) =>
157
150
  return;
158
151
  }
159
152
 
160
- /** Check if we're actually inserting a table, otherwise we can ignore this tr */
161
- const isAddingTable = checkIsAddingTable(transaction, table);
162
- if (!isAddingTable) {
163
- return;
164
- }
153
+ /** Get the tables we are adding and their position */
154
+ for (const step of transaction.steps) {
155
+ if (!stepHasSlice(step)) {
156
+ continue;
157
+ }
165
158
 
166
- // Can't simply look at changed nodes, as we could be adding a table
167
- newState.doc.descendants((node, pos) => {
168
- const isTable = node.type === table;
169
- const localId = node.attrs.localId;
170
-
171
- // Dealing with a table - make sure it's a unique ID
172
- if (isTable) {
173
- if (localId && !idsObserved.has(localId)) {
174
- idsObserved.add(localId);
175
- // Also add a localId if it happens to not have one,
176
- } else if (!localId || idsObserved.has(localId)) {
177
- modified = true;
178
- tr.setNodeMarkup(pos, undefined, {
179
- ...node.attrs,
180
- localId: uuid.generate(),
181
- });
159
+ step.slice.content.descendants((node, pos) => {
160
+ if (node.type === table) {
161
+ addedTableNodes.add(node);
182
162
  }
183
- return false;
184
- }
185
163
 
186
- /**
187
- * Otherwise continue traversing, we can encounter tables nested in
188
- * expands/bodiedExtensions
189
- */
164
+ return true;
165
+ });
166
+ }
167
+ });
168
+
169
+ if (!addedTableNodes.size) {
170
+ return;
171
+ }
172
+
173
+ // Get the existing localIds on the page
174
+ newState.doc.descendants((node, pos) => {
175
+ // Skip if this is position of added table
176
+ if (addedTableNodes.has(node)) {
177
+ addedTableNodePos.set(node, pos);
178
+ return false;
179
+ }
180
+
181
+ if (node.type !== table) {
190
182
  return true;
191
- });
183
+ }
184
+
185
+ localIds.add(node.attrs.localId);
186
+
187
+ // can't have table within a table
188
+ return false;
192
189
  });
193
190
 
191
+ // If the added nodes have duplicate id, generate a new one
192
+ for (const node of addedTableNodes) {
193
+ if (!node.attrs.localId || localIds.has(node.attrs.localId)) {
194
+ const pos = addedTableNodePos.get(node);
195
+
196
+ if (pos === undefined) {
197
+ continue;
198
+ }
199
+
200
+ tr.setNodeMarkup(pos, undefined, {
201
+ ...node.attrs,
202
+ localId: uuid.generate(),
203
+ });
204
+
205
+ modified = true;
206
+ }
207
+ }
208
+
194
209
  if (modified) {
195
210
  return tr;
196
211
  }
212
+
197
213
  return;
198
214
  },
199
215
  });