@atlaskit/editor-plugin-table 9.3.3 → 9.3.5

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 (76) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/nodeviews/toDOM.js +2 -1
  3. package/dist/cjs/pm-plugins/utils/paste.js +60 -11
  4. package/dist/es2019/nodeviews/toDOM.js +2 -1
  5. package/dist/es2019/pm-plugins/utils/paste.js +57 -8
  6. package/dist/esm/nodeviews/toDOM.js +2 -1
  7. package/dist/esm/pm-plugins/utils/paste.js +60 -11
  8. package/dist/types/nodeviews/ExternalDropTargets.d.ts +2 -2
  9. package/dist/types/nodeviews/TableComponentWithSharedState.d.ts +2 -2
  10. package/dist/types/nodeviews/TableContainer.d.ts +2 -2
  11. package/dist/types/nodeviews/TableResizer.d.ts +2 -1
  12. package/dist/types/nodeviews/table.d.ts +2 -2
  13. package/dist/types/ui/DragHandle/HandleIconComponent.d.ts +2 -2
  14. package/dist/types/ui/DragPreview/index.d.ts +2 -2
  15. package/dist/types/ui/FloatingDeleteButton/index.d.ts +2 -2
  16. package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +2 -2
  17. package/dist/types/ui/FloatingDragMenu/index.d.ts +2 -2
  18. package/dist/types/ui/FloatingInsertButton/index.d.ts +1 -1
  19. package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
  20. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -2
  21. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +2 -2
  22. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -2
  23. package/dist/types/ui/TableFloatingColumnControls/index.d.ts +2 -2
  24. package/dist/types/ui/TableFloatingControls/FloatingControlsWithSelection.d.ts +2 -2
  25. package/dist/types/ui/TableFloatingControls/NumberColumn/index.d.ts +2 -2
  26. package/dist/types/ui/TableFloatingControls/RowControls/DragControls.d.ts +3 -3
  27. package/dist/types/ui/TableFloatingControls/RowDropTarget/index.d.ts +1 -1
  28. package/dist/types/ui/TableFloatingControls/index.d.ts +2 -2
  29. package/dist/types/ui/TableFullWidthLabel/index.d.ts +2 -2
  30. package/dist/types/ui/icons/AddColLeftIcon.d.ts +2 -2
  31. package/dist/types/ui/icons/AddColRightIcon.d.ts +2 -2
  32. package/dist/types/ui/icons/AddRowAboveIcon.d.ts +2 -2
  33. package/dist/types/ui/icons/AddRowBelowIcon.d.ts +2 -2
  34. package/dist/types/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
  35. package/dist/types/ui/icons/DragHandleIcon.d.ts +2 -2
  36. package/dist/types/ui/icons/DragInMotionIcon.d.ts +1 -1
  37. package/dist/types/ui/icons/MergeCellsIcon.d.ts +2 -2
  38. package/dist/types/ui/icons/MinimisedHandle.d.ts +2 -2
  39. package/dist/types/ui/icons/SortingIconWrapper.d.ts +1 -1
  40. package/dist/types/ui/icons/SplitCellIcon.d.ts +2 -2
  41. package/dist/types-ts4.5/nodeviews/ExternalDropTargets.d.ts +2 -2
  42. package/dist/types-ts4.5/nodeviews/TableComponentWithSharedState.d.ts +2 -2
  43. package/dist/types-ts4.5/nodeviews/TableContainer.d.ts +2 -2
  44. package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
  45. package/dist/types-ts4.5/nodeviews/table.d.ts +2 -2
  46. package/dist/types-ts4.5/ui/DragHandle/HandleIconComponent.d.ts +2 -2
  47. package/dist/types-ts4.5/ui/DragPreview/index.d.ts +2 -2
  48. package/dist/types-ts4.5/ui/FloatingDeleteButton/index.d.ts +2 -2
  49. package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +2 -2
  50. package/dist/types-ts4.5/ui/FloatingDragMenu/index.d.ts +2 -2
  51. package/dist/types-ts4.5/ui/FloatingInsertButton/index.d.ts +1 -1
  52. package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
  53. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +2 -2
  54. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +2 -2
  55. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +2 -2
  56. package/dist/types-ts4.5/ui/TableFloatingColumnControls/index.d.ts +2 -2
  57. package/dist/types-ts4.5/ui/TableFloatingControls/FloatingControlsWithSelection.d.ts +2 -2
  58. package/dist/types-ts4.5/ui/TableFloatingControls/NumberColumn/index.d.ts +2 -2
  59. package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/DragControls.d.ts +3 -3
  60. package/dist/types-ts4.5/ui/TableFloatingControls/RowDropTarget/index.d.ts +1 -1
  61. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +2 -2
  62. package/dist/types-ts4.5/ui/TableFullWidthLabel/index.d.ts +2 -2
  63. package/dist/types-ts4.5/ui/icons/AddColLeftIcon.d.ts +2 -2
  64. package/dist/types-ts4.5/ui/icons/AddColRightIcon.d.ts +2 -2
  65. package/dist/types-ts4.5/ui/icons/AddRowAboveIcon.d.ts +2 -2
  66. package/dist/types-ts4.5/ui/icons/AddRowBelowIcon.d.ts +2 -2
  67. package/dist/types-ts4.5/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
  68. package/dist/types-ts4.5/ui/icons/DragHandleIcon.d.ts +2 -2
  69. package/dist/types-ts4.5/ui/icons/DragInMotionIcon.d.ts +1 -1
  70. package/dist/types-ts4.5/ui/icons/MergeCellsIcon.d.ts +2 -2
  71. package/dist/types-ts4.5/ui/icons/MinimisedHandle.d.ts +2 -2
  72. package/dist/types-ts4.5/ui/icons/SortingIconWrapper.d.ts +1 -1
  73. package/dist/types-ts4.5/ui/icons/SplitCellIcon.d.ts +2 -2
  74. package/package.json +11 -5
  75. package/src/nodeviews/toDOM.ts +4 -1
  76. package/src/pm-plugins/utils/paste.ts +71 -4
@@ -211,11 +211,75 @@ export const transformSliceToFixHardBreakProblemOnCopyFromCell = (
211
211
  return slice;
212
212
  };
213
213
 
214
+ const isNodeSingleCellTable = (node: PMNode, schema: Schema): boolean => {
215
+ return (
216
+ node.childCount === 1 &&
217
+ node.firstChild?.type === schema.nodes.tableRow &&
218
+ node.firstChild.childCount === 1 &&
219
+ (node.firstChild.firstChild?.type === schema.nodes.tableCell ||
220
+ node.firstChild.firstChild?.type === schema.nodes.tableHeader)
221
+ );
222
+ };
223
+
224
+ const isFragmentSingleCellTable = (fragment: Fragment, schema: Schema): boolean => {
225
+ return (
226
+ fragment.childCount === 1 &&
227
+ fragment.firstChild !== null &&
228
+ isNodeSingleCellTable(fragment.firstChild, schema)
229
+ );
230
+ };
231
+
232
+ const containsTextBlockChildren = (fragment: Fragment, schema: Schema): boolean => {
233
+ let containsTextBlock = false;
234
+
235
+ fragment.forEach((node) => {
236
+ if (node.isTextblock) {
237
+ containsTextBlock = true;
238
+ }
239
+ });
240
+
241
+ return containsTextBlock;
242
+ };
243
+
214
244
  export const transformSliceToRemoveOpenTable = (slice: Slice, schema: Schema): Slice => {
215
- // we're removing the table, tableRow and tableCell reducing the open depth by 3
216
- const depthDecrement = 3;
245
+ if (fg('platform_editor_nested_tables_paste_wrap_fix')) {
246
+ // Case 1: A slice of a textblock selection inside a nested table
247
+ // Prosemirror wraps nested textblock selections in their respective tables
248
+ // We are using `safeInsert` to paste nested tables, so we do not want to preserve this wrapping
249
+
250
+ // slice starts and ends inside a nested table at the same depth
251
+ if (slice.openStart >= 7 && slice.openEnd >= 7 && slice.openStart === slice.openEnd) {
252
+ let cleaned = slice;
253
+ let descendedDepth = 0;
254
+ const tableDepthDecrement = 2;
255
+
256
+ // if the slice is a single cell table and contains cells with single cell tables, descend into it until we find textblock children
257
+ if (isFragmentSingleCellTable(slice.content, schema)) {
258
+ slice.content.firstChild?.descendants((node, _pos, parent) => {
259
+ if (isNodeSingleCellTable(node, schema)) {
260
+ descendedDepth += tableDepthDecrement;
261
+ } else if (node.type === schema.nodes.table) {
262
+ return false;
263
+ } else if (containsTextBlockChildren(node.content, schema)) {
264
+ descendedDepth += tableDepthDecrement;
265
+ // create a new slice with the content of the textblock children and the depth of the nested tables subtracted
266
+ cleaned = new Slice(
267
+ node.content,
268
+ slice.openStart - descendedDepth - tableDepthDecrement,
269
+ slice.openEnd - descendedDepth - tableDepthDecrement,
270
+ );
271
+ return false;
272
+ }
273
+ });
274
+ }
275
+
276
+ if (!cleaned.eq(slice)) {
277
+ return cleaned;
278
+ }
279
+ }
280
+ }
217
281
 
218
- // Case 1: A slice entirely within a single CELL
282
+ // Case 2: A slice entirely within a single CELL
219
283
  if (
220
284
  // starts and ends inside of a cell
221
285
  slice.openStart >= 4 &&
@@ -226,6 +290,9 @@ export const transformSliceToRemoveOpenTable = (slice: Slice, schema: Schema): S
226
290
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
227
291
  slice.content.firstChild!.type === schema.nodes.table
228
292
  ) {
293
+ // we're removing the table, tableRow and tableCell reducing the open depth by 3
294
+ const depthDecrement = 3;
295
+
229
296
  // prosemirror-view has a bug that it duplicates table entry when selecting multiple paragraphs in a table cell.
230
297
  // https://github.com/ProseMirror/prosemirror/issues/1270
231
298
  // The structure becomes
@@ -250,7 +317,7 @@ export const transformSliceToRemoveOpenTable = (slice: Slice, schema: Schema): S
250
317
  );
251
318
  }
252
319
 
253
- // Case 2: A slice starting within a CELL and ending outside the table
320
+ // Case 3: A slice starting within a CELL and ending outside the table
254
321
  if (
255
322
  // starts inside of a cell but ends outside of the starting table
256
323
  slice.openStart >= 4 &&