@atlaskit/editor-plugin-table 5.4.9 → 5.4.10

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,11 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 5.4.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#58174](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/58174) [`b409282ab2b8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b409282ab2b8) - Check pasted slice is a table element before trying to access table map
8
+
3
9
  ## 5.4.9
4
10
 
5
11
  ### Patch Changes
@@ -181,17 +181,21 @@ var getTableSelectionType = exports.getTableSelectionType = function getTableSel
181
181
  }
182
182
  };
183
183
  var getTableElementMoveTypeBySlice = exports.getTableElementMoveTypeBySlice = function getTableElementMoveTypeBySlice(slice, state) {
184
- if (!slice.content.firstChild) {
184
+ var _state$schema$nodes = state.schema.nodes,
185
+ tableRow = _state$schema$nodes.tableRow,
186
+ table = _state$schema$nodes.table;
187
+
188
+ // check if copied slice is a table or table row
189
+ if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
185
190
  return;
186
191
  }
187
- var schema = state.schema;
188
192
 
189
193
  // if the slice only contains one table row, assume it's a row
190
- if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
194
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
191
195
  return 'row';
192
196
  }
193
- var table = (0, _utils2.findTable)(state.tr.selection);
194
- var map = _tableMap.TableMap.get(table.node);
197
+ var currentTable = (0, _utils2.findTable)(state.tr.selection);
198
+ var map = _tableMap.TableMap.get(currentTable.node);
195
199
  var slicedMap = _tableMap.TableMap.get(slice.content.firstChild);
196
200
  return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
197
201
  };
@@ -183,19 +183,26 @@ export const getTableSelectionType = selection => {
183
183
  }
184
184
  };
185
185
  export const getTableElementMoveTypeBySlice = (slice, state) => {
186
- if (!slice.content.firstChild) {
187
- return;
188
- }
189
186
  const {
190
- schema
187
+ schema: {
188
+ nodes: {
189
+ tableRow,
190
+ table
191
+ }
192
+ }
191
193
  } = state;
192
194
 
195
+ // check if copied slice is a table or table row
196
+ if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
197
+ return;
198
+ }
199
+
193
200
  // if the slice only contains one table row, assume it's a row
194
- if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
201
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
195
202
  return 'row';
196
203
  }
197
- const table = findTable(state.tr.selection);
198
- const map = TableMap.get(table.node);
204
+ const currentTable = findTable(state.tr.selection);
205
+ const map = TableMap.get(currentTable.node);
199
206
  const slicedMap = TableMap.get(slice.content.firstChild);
200
207
  return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
201
208
  };
@@ -174,17 +174,21 @@ export var getTableSelectionType = function getTableSelectionType(selection) {
174
174
  }
175
175
  };
176
176
  export var getTableElementMoveTypeBySlice = function getTableElementMoveTypeBySlice(slice, state) {
177
- if (!slice.content.firstChild) {
177
+ var _state$schema$nodes = state.schema.nodes,
178
+ tableRow = _state$schema$nodes.tableRow,
179
+ table = _state$schema$nodes.table;
180
+
181
+ // check if copied slice is a table or table row
182
+ if (!slice.content.firstChild || slice.content.firstChild.type !== table && slice.content.firstChild.type !== tableRow) {
178
183
  return;
179
184
  }
180
- var schema = state.schema;
181
185
 
182
186
  // if the slice only contains one table row, assume it's a row
183
- if (slice.content.childCount === 1 && slice.content.firstChild.type === schema.nodes.tableRow) {
187
+ if (slice.content.childCount === 1 && slice.content.firstChild.type === tableRow) {
184
188
  return 'row';
185
189
  }
186
- var table = findTable(state.tr.selection);
187
- var map = TableMap.get(table.node);
190
+ var currentTable = findTable(state.tr.selection);
191
+ var map = TableMap.get(currentTable.node);
188
192
  var slicedMap = TableMap.get(slice.content.firstChild);
189
193
  return map.width === slicedMap.width ? 'row' : map.height === slicedMap.height ? 'column' : undefined;
190
194
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.4.9",
3
+ "version": "5.4.10",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -276,22 +276,31 @@ export const getTableElementMoveTypeBySlice = (
276
276
  slice: Slice,
277
277
  state: EditorState,
278
278
  ) => {
279
- if (!slice.content.firstChild) {
279
+ const {
280
+ schema: {
281
+ nodes: { tableRow, table },
282
+ },
283
+ } = state;
284
+
285
+ // check if copied slice is a table or table row
286
+ if (
287
+ !slice.content.firstChild ||
288
+ (slice.content.firstChild.type !== table &&
289
+ slice.content.firstChild.type !== tableRow)
290
+ ) {
280
291
  return;
281
292
  }
282
293
 
283
- const { schema } = state;
284
-
285
294
  // if the slice only contains one table row, assume it's a row
286
295
  if (
287
296
  slice.content.childCount === 1 &&
288
- slice.content.firstChild.type === schema.nodes.tableRow
297
+ slice.content.firstChild.type === tableRow
289
298
  ) {
290
299
  return 'row';
291
300
  }
292
301
 
293
- const table = findTable(state.tr.selection)!;
294
- const map = TableMap.get(table.node);
302
+ const currentTable = findTable(state.tr.selection)!;
303
+ const map = TableMap.get(currentTable.node);
295
304
  const slicedMap = TableMap.get(slice.content.firstChild);
296
305
 
297
306
  return map.width === slicedMap.width