@atlaskit/editor-plugin-table 0.1.0 → 0.1.1

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 (190) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/es2019/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  5. package/dist/es2019/version.json +1 -1
  6. package/dist/esm/plugins/table/ui/FloatingDeleteButton/index.js +2 -1
  7. package/dist/esm/version.json +1 -1
  8. package/examples/99-testing.tsx +35 -30
  9. package/package.json +2 -11
  10. package/src/__tests__/integration/__fixtures__/auto-size-documents.ts +5 -10
  11. package/src/__tests__/integration/__fixtures__/layout-documents.ts +1 -2
  12. package/src/__tests__/integration/__fixtures__/resize-documents.ts +5 -10
  13. package/src/__tests__/integration/resize.ts +1 -2
  14. package/src/__tests__/unit/analytics.ts +33 -32
  15. package/src/__tests__/unit/collab.ts +12 -9
  16. package/src/__tests__/unit/commands/sort.ts +28 -28
  17. package/src/__tests__/unit/copy-paste.ts +6 -8
  18. package/src/__tests__/unit/event-handlers.ts +7 -10
  19. package/src/__tests__/unit/fix-tables.ts +17 -23
  20. package/src/__tests__/unit/get-toolbar-config.ts +0 -5
  21. package/src/__tests__/unit/hover-selection.ts +1 -66
  22. package/src/__tests__/unit/index-with-fake-timers.ts +1 -1
  23. package/src/__tests__/unit/index.ts +5 -5
  24. package/src/__tests__/unit/nodeviews/TableComponent.tsx +11 -218
  25. package/src/__tests__/unit/nodeviews/cell.ts +12 -10
  26. package/src/__tests__/unit/nodeviews/table.ts +25 -26
  27. package/src/__tests__/unit/pm-plugins/safari-delete-composition-text-issue-workaround.ts +11 -8
  28. package/src/__tests__/unit/pm-plugins/sticky-headers/tableRow.tsx +11 -12
  29. package/src/__tests__/unit/toolbar.ts +18 -5
  30. package/src/__tests__/unit/ui/ContextualMenu.tsx +55 -0
  31. package/src/__tests__/unit/ui/CornerControls.tsx +7 -7
  32. package/src/__tests__/unit/ui/FloatingContextualButton.tsx +45 -49
  33. package/src/__tests__/unit/ui/FloatingContextualMenu.tsx +49 -0
  34. package/src/__tests__/unit/ui/FloatingDeleteButton.tsx +30 -2
  35. package/src/__tests__/unit/ui/FloatingInsertButton.tsx +143 -111
  36. package/src/__tests__/unit/ui/RowControls.tsx +112 -141
  37. package/src/__tests__/unit/ui/TableFloatingControls.tsx +18 -15
  38. package/src/__tests__/unit/undo-redo.ts +10 -9
  39. package/src/__tests__/unit/utils/nodes.ts +8 -4
  40. package/src/__tests__/unit/utils/row-controls.ts +8 -4
  41. package/src/plugins/table/commands/clear.ts +30 -29
  42. package/src/plugins/table/commands/go-to-next-cell.ts +41 -38
  43. package/src/plugins/table/commands/insert.ts +91 -91
  44. package/src/plugins/table/commands/misc.ts +123 -125
  45. package/src/plugins/table/commands/selection.ts +329 -319
  46. package/src/plugins/table/commands-with-analytics.ts +299 -294
  47. package/src/plugins/table/event-handlers.ts +111 -111
  48. package/src/plugins/table/handlers.ts +95 -94
  49. package/src/plugins/table/nodeviews/OverflowShadowsObserver.ts +4 -3
  50. package/src/plugins/table/nodeviews/TableComponent.tsx +6 -9
  51. package/src/plugins/table/nodeviews/update-overflow-shadows.ts +39 -39
  52. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +7 -9
  53. package/src/plugins/table/pm-plugins/decorations/utils/column-resizing.ts +30 -30
  54. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +7 -7
  55. package/src/plugins/table/pm-plugins/plugin-factory.ts +33 -33
  56. package/src/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.ts +6 -9
  57. package/src/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.ts +3 -2
  58. package/src/plugins/table/pm-plugins/table-resizing/commands.ts +98 -90
  59. package/src/plugins/table/pm-plugins/table-resizing/utils/dom.ts +46 -47
  60. package/src/plugins/table/toolbar.tsx +116 -113
  61. package/src/plugins/table/transforms/column-width.ts +143 -146
  62. package/src/plugins/table/transforms/delete-columns.ts +144 -142
  63. package/src/plugins/table/transforms/delete-rows.ts +110 -111
  64. package/src/plugins/table/transforms/metadata.ts +9 -9
  65. package/src/plugins/table/ui/FloatingContextualMenu/ContextualMenu.tsx +7 -6
  66. package/src/plugins/table/ui/FloatingDeleteButton/index.tsx +3 -2
  67. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +2 -5
  68. package/src/plugins/table/ui/LayoutButton/index.tsx +2 -6
  69. package/src/plugins/table/ui/common-styles.ts +1 -3
  70. package/src/plugins/table/utils/analytics.ts +24 -25
  71. package/src/plugins/table/utils/dom.ts +3 -3
  72. package/src/plugins/table/utils/row-controls.ts +92 -93
  73. package/dist/types-ts4.0/index.d.ts +0 -1
  74. package/dist/types-ts4.0/plugins/table/commands/clear.d.ts +0 -3
  75. package/dist/types-ts4.0/plugins/table/commands/collapse.d.ts +0 -2
  76. package/dist/types-ts4.0/plugins/table/commands/go-to-next-cell.d.ts +0 -4
  77. package/dist/types-ts4.0/plugins/table/commands/hover.d.ts +0 -8
  78. package/dist/types-ts4.0/plugins/table/commands/index.d.ts +0 -7
  79. package/dist/types-ts4.0/plugins/table/commands/insert.d.ts +0 -10
  80. package/dist/types-ts4.0/plugins/table/commands/misc.d.ts +0 -27
  81. package/dist/types-ts4.0/plugins/table/commands/selection.d.ts +0 -8
  82. package/dist/types-ts4.0/plugins/table/commands/sort.d.ts +0 -3
  83. package/dist/types-ts4.0/plugins/table/commands/split-cell.d.ts +0 -6
  84. package/dist/types-ts4.0/plugins/table/commands/toggle.d.ts +0 -12
  85. package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +0 -26
  86. package/dist/types-ts4.0/plugins/table/create-plugin-config.d.ts +0 -2
  87. package/dist/types-ts4.0/plugins/table/event-handlers.d.ts +0 -16
  88. package/dist/types-ts4.0/plugins/table/handlers.d.ts +0 -3
  89. package/dist/types-ts4.0/plugins/table/index.d.ts +0 -17
  90. package/dist/types-ts4.0/plugins/table/nodeviews/OverflowShadowsObserver.d.ts +0 -26
  91. package/dist/types-ts4.0/plugins/table/nodeviews/TableComponent.d.ts +0 -72
  92. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverflowShadowsObserver.d.ts +0 -9
  93. package/dist/types-ts4.0/plugins/table/nodeviews/__mocks__/OverridableMock.d.ts +0 -9
  94. package/dist/types-ts4.0/plugins/table/nodeviews/table.d.ts +0 -31
  95. package/dist/types-ts4.0/plugins/table/nodeviews/tableCell.d.ts +0 -19
  96. package/dist/types-ts4.0/plugins/table/nodeviews/types.d.ts +0 -24
  97. package/dist/types-ts4.0/plugins/table/nodeviews/update-overflow-shadows.d.ts +0 -8
  98. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/plugin.d.ts +0 -7
  99. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +0 -3
  100. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/column-resizing.d.ts +0 -2
  101. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +0 -2
  102. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/index.d.ts +0 -3
  103. package/dist/types-ts4.0/plugins/table/pm-plugins/decorations/utils/types.d.ts +0 -6
  104. package/dist/types-ts4.0/plugins/table/pm-plugins/default-table-selection.d.ts +0 -5
  105. package/dist/types-ts4.0/plugins/table/pm-plugins/keymap.d.ts +0 -5
  106. package/dist/types-ts4.0/plugins/table/pm-plugins/main.d.ts +0 -8
  107. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-factory.d.ts +0 -1
  108. package/dist/types-ts4.0/plugins/table/pm-plugins/plugin-key.d.ts +0 -3
  109. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delayed-dom-selection-syncing-workaround.d.ts +0 -4
  110. package/dist/types-ts4.0/plugins/table/pm-plugins/safari-delete-composition-text-issue-workaround.d.ts +0 -15
  111. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/commands.d.ts +0 -3
  112. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/index.d.ts +0 -6
  113. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/dom.d.ts +0 -6
  114. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.d.ts +0 -65
  115. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-key.d.ts +0 -3
  116. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin-state.d.ts +0 -3
  117. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/plugin.d.ts +0 -4
  118. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/types.d.ts +0 -16
  119. package/dist/types-ts4.0/plugins/table/pm-plugins/sticky-headers/util.d.ts +0 -2
  120. package/dist/types-ts4.0/plugins/table/pm-plugins/table-local-id.d.ts +0 -22
  121. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/commands.d.ts +0 -25
  122. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/event-handlers.d.ts +0 -4
  123. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/index.d.ts +0 -4
  124. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-factory.d.ts +0 -4
  125. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin-key.d.ts +0 -3
  126. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/plugin.d.ts +0 -6
  127. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/reducer.d.ts +0 -3
  128. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/colgroup.d.ts +0 -8
  129. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/column-state.d.ts +0 -14
  130. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/content-width.d.ts +0 -4
  131. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/dom.d.ts +0 -13
  132. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/index.d.ts +0 -12
  133. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/misc.d.ts +0 -22
  134. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-column.d.ts +0 -2
  135. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-logic.d.ts +0 -4
  136. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/resize-state.d.ts +0 -29
  137. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/scale-table.d.ts +0 -17
  138. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/types.d.ts +0 -22
  139. package/dist/types-ts4.0/plugins/table/pm-plugins/table-resizing/utils/unit-to-number.d.ts +0 -1
  140. package/dist/types-ts4.0/plugins/table/pm-plugins/table-selection-keymap.d.ts +0 -4
  141. package/dist/types-ts4.0/plugins/table/reducer.d.ts +0 -3
  142. package/dist/types-ts4.0/plugins/table/toolbar.d.ts +0 -36
  143. package/dist/types-ts4.0/plugins/table/transforms/column-width.d.ts +0 -18
  144. package/dist/types-ts4.0/plugins/table/transforms/delete-columns.d.ts +0 -3
  145. package/dist/types-ts4.0/plugins/table/transforms/delete-rows.d.ts +0 -3
  146. package/dist/types-ts4.0/plugins/table/transforms/fix-tables.d.ts +0 -10
  147. package/dist/types-ts4.0/plugins/table/transforms/index.d.ts +0 -7
  148. package/dist/types-ts4.0/plugins/table/transforms/merge.d.ts +0 -5
  149. package/dist/types-ts4.0/plugins/table/transforms/metadata.d.ts +0 -21
  150. package/dist/types-ts4.0/plugins/table/transforms/replace-table.d.ts +0 -5
  151. package/dist/types-ts4.0/plugins/table/transforms/split.d.ts +0 -9
  152. package/dist/types-ts4.0/plugins/table/types.d.ts +0 -328
  153. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/index.d.ts +0 -29
  154. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualButton/styles.d.ts +0 -1
  155. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/ContextualMenu.d.ts +0 -87
  156. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/index.d.ts +0 -22
  157. package/dist/types-ts4.0/plugins/table/ui/FloatingContextualMenu/styles.d.ts +0 -2
  158. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/DeleteButton.d.ts +0 -14
  159. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/getPopUpOptions.d.ts +0 -10
  160. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/index.d.ts +0 -54
  161. package/dist/types-ts4.0/plugins/table/ui/FloatingDeleteButton/types.d.ts +0 -1
  162. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/InsertButton.d.ts +0 -12
  163. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/getPopupOptions.d.ts +0 -3
  164. package/dist/types-ts4.0/plugins/table/ui/FloatingInsertButton/index.d.ts +0 -35
  165. package/dist/types-ts4.0/plugins/table/ui/LayoutButton/index.d.ts +0 -21
  166. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +0 -16
  167. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/NumberColumn/index.d.ts +0 -21
  168. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/RowControls/index.d.ts +0 -17
  169. package/dist/types-ts4.0/plugins/table/ui/TableFloatingControls/index.d.ts +0 -40
  170. package/dist/types-ts4.0/plugins/table/ui/common-styles.d.ts +0 -4
  171. package/dist/types-ts4.0/plugins/table/ui/consts.d.ts +0 -39
  172. package/dist/types-ts4.0/plugins/table/ui/messages.d.ts +0 -38
  173. package/dist/types-ts4.0/plugins/table/ui/ui-styles.d.ts +0 -15
  174. package/dist/types-ts4.0/plugins/table/utils/analytics.d.ts +0 -18
  175. package/dist/types-ts4.0/plugins/table/utils/collapse.d.ts +0 -29
  176. package/dist/types-ts4.0/plugins/table/utils/column-controls.d.ts +0 -10
  177. package/dist/types-ts4.0/plugins/table/utils/decoration.d.ts +0 -16
  178. package/dist/types-ts4.0/plugins/table/utils/dom.d.ts +0 -20
  179. package/dist/types-ts4.0/plugins/table/utils/get-allow-add-column-custom-step.d.ts +0 -2
  180. package/dist/types-ts4.0/plugins/table/utils/index.d.ts +0 -11
  181. package/dist/types-ts4.0/plugins/table/utils/nodes.d.ts +0 -12
  182. package/dist/types-ts4.0/plugins/table/utils/paste.d.ts +0 -14
  183. package/dist/types-ts4.0/plugins/table/utils/referentiality.d.ts +0 -2
  184. package/dist/types-ts4.0/plugins/table/utils/row-controls.d.ts +0 -16
  185. package/dist/types-ts4.0/plugins/table/utils/selection.d.ts +0 -6
  186. package/dist/types-ts4.0/plugins/table/utils/table.d.ts +0 -4
  187. package/dist/types-ts4.0/plugins/table/utils/update-plugin-state-decorations.d.ts +0 -4
  188. package/dist/types-ts4.0/plugins/table-plugin.d.ts +0 -2
  189. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/ContextualMenu.tsx +0 -56
  190. package/src/plugins/table/ui/FloatingContextualMenu/__tests__/FloatingContextualMenu.tsx +0 -50
@@ -370,126 +370,129 @@ const getClosestSelectionRect = (state: EditorState): Rect | undefined => {
370
370
  : findCellRectClosestToPos(selection.$from);
371
371
  };
372
372
 
373
- export const getToolbarConfig = (
374
- getEditorContainerWidth: GetEditorContainerWidth,
375
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
376
- getEditorFeatureFlags: GetEditorFeatureFlags,
377
- ) => (config: PluginConfig): FloatingToolbarHandler => (state, intl) => {
378
- const tableObject = findTable(state.selection);
379
- const pluginState = getPluginState(state);
380
- const resizeState:
381
- | ColumnResizingPluginState
382
- | undefined = tableResizingPluginKey.getState(state);
383
- if (tableObject && pluginState.editorHasFocus) {
384
- const nodeType = state.schema.nodes.table;
385
- const menu = getToolbarMenuConfig(
386
- config,
387
- pluginState,
388
- intl,
389
- editorAnalyticsAPI,
390
- );
373
+ export const getToolbarConfig =
374
+ (
375
+ getEditorContainerWidth: GetEditorContainerWidth,
376
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
377
+ getEditorFeatureFlags: GetEditorFeatureFlags,
378
+ ) =>
379
+ (config: PluginConfig): FloatingToolbarHandler =>
380
+ (state, intl) => {
381
+ const tableObject = findTable(state.selection);
382
+ const pluginState = getPluginState(state);
383
+ const resizeState: ColumnResizingPluginState | undefined =
384
+ tableResizingPluginKey.getState(state);
385
+ if (tableObject && pluginState.editorHasFocus) {
386
+ const nodeType = state.schema.nodes.table;
387
+ const menu = getToolbarMenuConfig(
388
+ config,
389
+ pluginState,
390
+ intl,
391
+ editorAnalyticsAPI,
392
+ );
391
393
 
392
- const { tableCellOptionsInFloatingToolbar } = getEditorFeatureFlags() || {};
393
- const cellItems = getCellItems(
394
- config,
395
- state,
396
- intl,
397
- getEditorContainerWidth,
398
- editorAnalyticsAPI,
399
- tableCellOptionsInFloatingToolbar,
400
- );
401
- const colorPicker = getColorPicker(
402
- state,
403
- menu,
404
- intl,
405
- getEditorContainerWidth,
406
- editorAnalyticsAPI,
407
- tableCellOptionsInFloatingToolbar,
408
- );
394
+ const { tableCellOptionsInFloatingToolbar } =
395
+ getEditorFeatureFlags() || {};
396
+ const cellItems = getCellItems(
397
+ config,
398
+ state,
399
+ intl,
400
+ getEditorContainerWidth,
401
+ editorAnalyticsAPI,
402
+ tableCellOptionsInFloatingToolbar,
403
+ );
404
+ const colorPicker = getColorPicker(
405
+ state,
406
+ menu,
407
+ intl,
408
+ getEditorContainerWidth,
409
+ editorAnalyticsAPI,
410
+ tableCellOptionsInFloatingToolbar,
411
+ );
409
412
 
410
- // Check if we need to show confirm dialog for delete button
411
- let confirmDialog;
412
- const localId: string | undefined = tableObject.node.attrs.localId;
413
+ // Check if we need to show confirm dialog for delete button
414
+ let confirmDialog;
415
+ const localId: string | undefined = tableObject.node.attrs.localId;
413
416
 
414
- if (localId && isReferencedSource(state, localId)) {
415
- confirmDialog = {
416
- okButtonLabel: intl.formatMessage(
417
- tableMessages.confirmDeleteLinkedModalOKButton,
418
- ),
419
- message: intl.formatMessage(
420
- tableMessages.confirmDeleteLinkedModalMessage,
421
- ),
422
- };
423
- }
417
+ if (localId && isReferencedSource(state, localId)) {
418
+ confirmDialog = {
419
+ okButtonLabel: intl.formatMessage(
420
+ tableMessages.confirmDeleteLinkedModalOKButton,
421
+ ),
422
+ message: intl.formatMessage(
423
+ tableMessages.confirmDeleteLinkedModalMessage,
424
+ ),
425
+ };
426
+ }
424
427
 
425
- const getDomRef = (editorView: EditorView) => {
426
- let element: HTMLElement | undefined;
427
- const domAtPos = editorView.domAtPos.bind(editorView);
428
- const parent = findParentDomRefOfType(
429
- nodeType,
430
- domAtPos,
431
- )(state.selection);
432
- if (parent) {
433
- const tableRef =
434
- (parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
435
- undefined;
436
- if (tableRef) {
437
- element =
438
- closestElement(
439
- tableRef,
440
- `.${TableCssClassName.TABLE_NODE_WRAPPER}`,
441
- ) || undefined;
428
+ const getDomRef = (editorView: EditorView) => {
429
+ let element: HTMLElement | undefined;
430
+ const domAtPos = editorView.domAtPos.bind(editorView);
431
+ const parent = findParentDomRefOfType(
432
+ nodeType,
433
+ domAtPos,
434
+ )(state.selection);
435
+ if (parent) {
436
+ const tableRef =
437
+ (parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
438
+ undefined;
439
+ if (tableRef) {
440
+ element =
441
+ closestElement(
442
+ tableRef,
443
+ `.${TableCssClassName.TABLE_NODE_WRAPPER}`,
444
+ ) || undefined;
445
+ }
442
446
  }
443
- }
444
447
 
445
- return element;
446
- };
448
+ return element;
449
+ };
447
450
 
448
- return {
449
- title: 'Table floating controls',
450
- getDomRef,
451
- nodeType,
452
- offset: [0, 3],
453
- items: [
454
- menu,
455
- separator(menu.hidden),
456
- ...cellItems,
457
- ...colorPicker,
458
- {
459
- type: 'extensions-placeholder',
460
- separator: 'end',
461
- },
462
- {
463
- type: 'copy-button',
464
- items: [
465
- {
466
- state,
467
- formatMessage: intl.formatMessage,
468
- nodeType,
469
- onMouseEnter: hoverTable(false, true),
470
- onMouseLeave: clearHoverSelection(),
471
- },
472
- { type: 'separator' },
473
- ],
474
- },
475
- {
476
- id: 'editor.table.delete',
477
- type: 'button',
478
- appearance: 'danger',
479
- icon: RemoveIcon,
480
- onClick: deleteTableWithAnalytics(editorAnalyticsAPI),
481
- disabled: !!resizeState && !!resizeState.dragging,
482
- onMouseEnter: hoverTable(true),
483
- onMouseLeave: clearHoverSelection(),
484
- title: intl.formatMessage(commonMessages.remove),
485
- confirmDialog,
486
- },
487
- ],
488
- scrollable: true,
489
- };
490
- }
491
- return;
492
- };
451
+ return {
452
+ title: 'Table floating controls',
453
+ getDomRef,
454
+ nodeType,
455
+ offset: [0, 3],
456
+ items: [
457
+ menu,
458
+ separator(menu.hidden),
459
+ ...cellItems,
460
+ ...colorPicker,
461
+ {
462
+ type: 'extensions-placeholder',
463
+ separator: 'end',
464
+ },
465
+ {
466
+ type: 'copy-button',
467
+ items: [
468
+ {
469
+ state,
470
+ formatMessage: intl.formatMessage,
471
+ nodeType,
472
+ onMouseEnter: hoverTable(false, true),
473
+ onMouseLeave: clearHoverSelection(),
474
+ },
475
+ { type: 'separator' },
476
+ ],
477
+ },
478
+ {
479
+ id: 'editor.table.delete',
480
+ type: 'button',
481
+ appearance: 'danger',
482
+ icon: RemoveIcon,
483
+ onClick: deleteTableWithAnalytics(editorAnalyticsAPI),
484
+ disabled: !!resizeState && !!resizeState.dragging,
485
+ onMouseEnter: hoverTable(true),
486
+ onMouseLeave: clearHoverSelection(),
487
+ title: intl.formatMessage(commonMessages.remove),
488
+ confirmDialog,
489
+ },
490
+ ],
491
+ scrollable: true,
492
+ };
493
+ }
494
+ return;
495
+ };
493
496
 
494
497
  const separator = (hidden?: boolean): FloatingToolbarItem<Command> => {
495
498
  return {
@@ -22,109 +22,107 @@ import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
22
22
  import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
23
23
  import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
24
24
 
25
- export const updateColumnWidths = (
26
- resizeState: ResizeState,
27
- table: PMNode,
28
- start: number,
29
- ) => (tr: Transaction): Transaction => {
30
- const map = TableMap.get(table);
31
- const updatedCellsAttrs: { [key: number]: CellAttributes } = {};
32
-
33
- // calculating new attributes for each cell
34
- for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
35
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
36
- const { width } = resizeState.cols[columnIndex];
37
- const mapIndex = rowIndex * map.width + columnIndex;
38
- const cellPos = map.map[mapIndex];
39
- const attrs = updatedCellsAttrs[cellPos] || {
40
- ...table.nodeAt(cellPos)!.attrs,
41
- };
42
- const colspan = attrs.colspan || 1;
43
-
44
- if (attrs.colwidth && attrs.colwidth.length > colspan) {
45
- tr = setMeta({
46
- type: 'UPDATE_COLUMN_WIDTHS',
47
- problem: 'COLWIDTHS_BEFORE_UPDATE',
48
- data: { colwidths: attrs.colwidth, colspan },
49
- })(tr);
50
- attrs.colwidth = attrs.colwidth.slice(0, colspan);
51
- }
52
-
53
- // Rowspanning cell that has already been handled
54
- if (rowIndex && map.map[mapIndex] === map.map[mapIndex - map.width]) {
55
- continue;
56
- }
57
- const colspanIndex =
58
- colspan === 1 ? 0 : columnIndex - map.colCount(cellPos);
59
- if (attrs.colwidth && attrs.colwidth[colspanIndex] === width) {
60
- continue;
61
- }
25
+ export const updateColumnWidths =
26
+ (resizeState: ResizeState, table: PMNode, start: number) =>
27
+ (tr: Transaction): Transaction => {
28
+ const map = TableMap.get(table);
29
+ const updatedCellsAttrs: { [key: number]: CellAttributes } = {};
62
30
 
63
- let colwidths = attrs.colwidth
64
- ? attrs.colwidth.slice()
65
- : Array.from({ length: colspan }, (_) => 0);
66
-
67
- colwidths[colspanIndex] = width;
68
- if (colwidths.length > colspan) {
69
- tr = setMeta({
70
- type: 'UPDATE_COLUMN_WIDTHS',
71
- problem: 'COLWIDTHS_AFTER_UPDATE',
72
- data: { colwidths, colspan },
73
- })(tr);
74
- colwidths = colwidths.slice(0, colspan);
31
+ // calculating new attributes for each cell
32
+ for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
33
+ for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
34
+ const { width } = resizeState.cols[columnIndex];
35
+ const mapIndex = rowIndex * map.width + columnIndex;
36
+ const cellPos = map.map[mapIndex];
37
+ const attrs = updatedCellsAttrs[cellPos] || {
38
+ ...table.nodeAt(cellPos)!.attrs,
39
+ };
40
+ const colspan = attrs.colspan || 1;
41
+
42
+ if (attrs.colwidth && attrs.colwidth.length > colspan) {
43
+ tr = setMeta({
44
+ type: 'UPDATE_COLUMN_WIDTHS',
45
+ problem: 'COLWIDTHS_BEFORE_UPDATE',
46
+ data: { colwidths: attrs.colwidth, colspan },
47
+ })(tr);
48
+ attrs.colwidth = attrs.colwidth.slice(0, colspan);
49
+ }
50
+
51
+ // Rowspanning cell that has already been handled
52
+ if (rowIndex && map.map[mapIndex] === map.map[mapIndex - map.width]) {
53
+ continue;
54
+ }
55
+ const colspanIndex =
56
+ colspan === 1 ? 0 : columnIndex - map.colCount(cellPos);
57
+ if (attrs.colwidth && attrs.colwidth[colspanIndex] === width) {
58
+ continue;
59
+ }
60
+
61
+ let colwidths = attrs.colwidth
62
+ ? attrs.colwidth.slice()
63
+ : Array.from({ length: colspan }, (_) => 0);
64
+
65
+ colwidths[colspanIndex] = width;
66
+ if (colwidths.length > colspan) {
67
+ tr = setMeta({
68
+ type: 'UPDATE_COLUMN_WIDTHS',
69
+ problem: 'COLWIDTHS_AFTER_UPDATE',
70
+ data: { colwidths, colspan },
71
+ })(tr);
72
+ colwidths = colwidths.slice(0, colspan);
73
+ }
74
+ updatedCellsAttrs[cellPos] = {
75
+ ...attrs,
76
+ colwidth: colwidths.includes(0) ? undefined : colwidths,
77
+ };
75
78
  }
76
- updatedCellsAttrs[cellPos] = {
77
- ...attrs,
78
- colwidth: colwidths.includes(0) ? undefined : colwidths,
79
- };
80
79
  }
81
- }
82
-
83
- // updating all cells with new attributes
84
- const rows: PMNode[] = [];
85
- const seen: { [key: number]: boolean } = {};
86
- for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
87
- const row = table.child(rowIndex);
88
- const cells: PMNode[] = [];
89
80
 
90
- for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
91
- const mapIndex = rowIndex * map.width + columnIndex;
92
- const pos = map.map[mapIndex];
93
- const cell = table.nodeAt(pos);
94
- if (!seen[pos] && cell) {
95
- cells.push(
96
- cell.type.createChecked(
97
- updatedCellsAttrs[pos] || cell.attrs,
98
- cell.content,
99
- cell.marks,
100
- ),
101
- );
102
- seen[pos] = true;
81
+ // updating all cells with new attributes
82
+ const rows: PMNode[] = [];
83
+ const seen: { [key: number]: boolean } = {};
84
+ for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
85
+ const row = table.child(rowIndex);
86
+ const cells: PMNode[] = [];
87
+
88
+ for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
89
+ const mapIndex = rowIndex * map.width + columnIndex;
90
+ const pos = map.map[mapIndex];
91
+ const cell = table.nodeAt(pos);
92
+ if (!seen[pos] && cell) {
93
+ cells.push(
94
+ cell.type.createChecked(
95
+ updatedCellsAttrs[pos] || cell.attrs,
96
+ cell.content,
97
+ cell.marks,
98
+ ),
99
+ );
100
+ seen[pos] = true;
101
+ }
103
102
  }
103
+ rows.push(row.type.createChecked(row.attrs, cells, row.marks));
104
104
  }
105
- rows.push(row.type.createChecked(row.attrs, cells, row.marks));
106
- }
107
-
108
- const tablePos = start - 1;
109
- const selectionBookmark = tr.selection.getBookmark();
110
-
111
- tr.replaceWith(
112
- tablePos,
113
- tablePos + table.nodeSize,
114
- table.type.createChecked(table.attrs, rows, table.marks),
115
- );
116
- /**
117
- * We want to restore to the original selection but w/o applying the mapping. Function
118
- * tr.replaceWith puts the selection after the inserted content. We need to manually
119
- * set the selection back to original state. Mapping in this case doesn't quite work
120
- * e.g. if we change the content before a selection. This is because mapping
121
- * means moving it if the content in front of it changed. Instead we can get
122
- * bookmark of selection.
123
- *
124
- * @see https://github.com/ProseMirror/prosemirror/issues/645
125
- */
126
- return tr.setSelection(selectionBookmark.resolve(tr.doc));
127
- };
105
+
106
+ const tablePos = start - 1;
107
+ const selectionBookmark = tr.selection.getBookmark();
108
+
109
+ tr.replaceWith(
110
+ tablePos,
111
+ tablePos + table.nodeSize,
112
+ table.type.createChecked(table.attrs, rows, table.marks),
113
+ );
114
+ /**
115
+ * We want to restore to the original selection but w/o applying the mapping. Function
116
+ * tr.replaceWith puts the selection after the inserted content. We need to manually
117
+ * set the selection back to original state. Mapping in this case doesn't quite work
118
+ * e.g. if we change the content before a selection. This is because mapping
119
+ * means moving it if the content in front of it changed. Instead we can get
120
+ * bookmark of selection.
121
+ *
122
+ * @see https://github.com/ProseMirror/prosemirror/issues/645
123
+ */
124
+ return tr.setSelection(selectionBookmark.resolve(tr.doc));
125
+ };
128
126
 
129
127
  /**
130
128
  * This function is called when user inserts/deletes a column in a table to;
@@ -136,52 +134,51 @@ export const updateColumnWidths = (
136
134
  * @param view
137
135
  * @returns Updated transaction with rescaled columns for a given table
138
136
  */
139
- export const rescaleColumns = (
140
- getEditorContainerWidth: GetEditorContainerWidth,
141
- ) => (table: ContentNodeWithPos, view: EditorView | undefined) => (
142
- tr: Transaction,
143
- ): Transaction => {
144
- // If the table has been not been resized we skip updating the size
145
- // of columns here.
146
- if (!view || !hasTableBeenResized(table.node)) {
147
- return tr;
148
- }
149
-
150
- const { state } = view;
151
- const domAtPos = view.domAtPos.bind(view);
152
-
153
- const maybeTable = domAtPos(table.start).node as HTMLElement;
154
- const tableRef = maybeTable.closest('table');
155
-
156
- if (!tableRef) {
157
- return tr;
158
- }
159
-
160
- const layout = normaliseTableLayout(tableRef?.dataset.layout);
161
- // The is the width the table can reach before overflowing
162
- const maxSize = getTableMaxWidth({
163
- table: table.node,
164
- tableStart: table.start,
165
- state,
166
- layout,
167
- getEditorContainerWidth,
168
- });
169
- let resizeState = getResizeState({
170
- minWidth: tableCellMinWidth,
171
- table: table.node,
172
- start: table.start,
173
- tableRef,
174
- domAtPos,
175
- maxSize,
176
- });
177
- const previousTableWidth = resizeState.tableWidth - tableNewColumnMinWidth;
178
- const tableDidntPreviouslyOverflow = previousTableWidth <= maxSize;
179
-
180
- // If the new table width will result in the table going into an overflow state
181
- // we resize the cells to avoid the overflow occuring
182
- if (tableDidntPreviouslyOverflow && resizeState.overflow) {
183
- resizeState = scaleTableTo(resizeState, maxSize);
184
- }
185
-
186
- return updateColumnWidths(resizeState, table.node, table.start)(tr);
187
- };
137
+ export const rescaleColumns =
138
+ (getEditorContainerWidth: GetEditorContainerWidth) =>
139
+ (table: ContentNodeWithPos, view: EditorView | undefined) =>
140
+ (tr: Transaction): Transaction => {
141
+ // If the table has been not been resized we skip updating the size
142
+ // of columns here.
143
+ if (!view || !hasTableBeenResized(table.node)) {
144
+ return tr;
145
+ }
146
+
147
+ const { state } = view;
148
+ const domAtPos = view.domAtPos.bind(view);
149
+
150
+ const maybeTable = domAtPos(table.start).node as HTMLElement;
151
+ const tableRef = maybeTable.closest('table');
152
+
153
+ if (!tableRef) {
154
+ return tr;
155
+ }
156
+
157
+ const layout = normaliseTableLayout(tableRef?.dataset.layout);
158
+ // The is the width the table can reach before overflowing
159
+ const maxSize = getTableMaxWidth({
160
+ table: table.node,
161
+ tableStart: table.start,
162
+ state,
163
+ layout,
164
+ getEditorContainerWidth,
165
+ });
166
+ let resizeState = getResizeState({
167
+ minWidth: tableCellMinWidth,
168
+ table: table.node,
169
+ start: table.start,
170
+ tableRef,
171
+ domAtPos,
172
+ maxSize,
173
+ });
174
+ const previousTableWidth = resizeState.tableWidth - tableNewColumnMinWidth;
175
+ const tableDidntPreviouslyOverflow = previousTableWidth <= maxSize;
176
+
177
+ // If the new table width will result in the table going into an overflow state
178
+ // we resize the cells to avoid the overflow occuring
179
+ if (tableDidntPreviouslyOverflow && resizeState.overflow) {
180
+ resizeState = scaleTableTo(resizeState, maxSize);
181
+ }
182
+
183
+ return updateColumnWidths(resizeState, table.node, table.start)(tr);
184
+ };