@atlaskit/editor-plugin-table 7.16.11 → 7.16.12

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 (242) hide show
  1. package/.eslintrc.js +3 -3
  2. package/CHANGELOG.md +8 -0
  3. package/dist/cjs/commands/misc.js +3 -3
  4. package/dist/cjs/nodeviews/TableCell.js +10 -10
  5. package/dist/cjs/nodeviews/TableContainer.js +41 -6
  6. package/dist/cjs/nodeviews/TableResizer.js +7 -7
  7. package/dist/cjs/nodeviews/TableRow.js +23 -23
  8. package/dist/cjs/pm-plugins/table-resizing/plugin.js +3 -3
  9. package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -4
  10. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +3 -3
  11. package/dist/cjs/ui/FloatingContextualMenu/styles.js +1 -1
  12. package/dist/cjs/ui/FloatingDragMenu/styles.js +1 -1
  13. package/dist/cjs/ui/common-styles.js +13 -13
  14. package/dist/cjs/ui/ui-styles.js +25 -25
  15. package/dist/cjs/utils/merged-cells.js +3 -3
  16. package/dist/es2019/commands/misc.js +3 -3
  17. package/dist/es2019/nodeviews/TableContainer.js +43 -5
  18. package/dist/es2019/nodeviews/TableResizer.js +7 -7
  19. package/dist/es2019/nodeviews/TableRow.js +21 -21
  20. package/dist/es2019/pm-plugins/table-resizing/plugin.js +3 -3
  21. package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -4
  22. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +3 -3
  23. package/dist/es2019/ui/FloatingContextualMenu/styles.js +47 -47
  24. package/dist/es2019/ui/FloatingDragMenu/styles.js +30 -30
  25. package/dist/es2019/ui/common-styles.js +802 -816
  26. package/dist/es2019/ui/ui-styles.js +665 -678
  27. package/dist/es2019/utils/merged-cells.js +3 -3
  28. package/dist/esm/commands/misc.js +3 -3
  29. package/dist/esm/nodeviews/TableCell.js +10 -10
  30. package/dist/esm/nodeviews/TableContainer.js +42 -7
  31. package/dist/esm/nodeviews/TableResizer.js +7 -7
  32. package/dist/esm/nodeviews/TableRow.js +23 -23
  33. package/dist/esm/pm-plugins/table-resizing/plugin.js +3 -3
  34. package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -4
  35. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +3 -3
  36. package/dist/esm/ui/FloatingContextualMenu/styles.js +1 -1
  37. package/dist/esm/ui/FloatingDragMenu/styles.js +1 -1
  38. package/dist/esm/ui/common-styles.js +13 -13
  39. package/dist/esm/ui/ui-styles.js +25 -25
  40. package/dist/esm/utils/merged-cells.js +3 -3
  41. package/dist/types/pm-plugins/decorations/utils/index.d.ts +1 -1
  42. package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
  43. package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
  44. package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  45. package/dist/types/ui/ColumnResizeWidget/index.d.ts +1 -1
  46. package/dist/types/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
  47. package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
  48. package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
  49. package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  50. package/dist/types/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
  51. package/dist/types-ts4.5/pm-plugins/decorations/utils/index.d.ts +1 -1
  52. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
  53. package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
  54. package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
  55. package/dist/types-ts4.5/ui/ColumnResizeWidget/index.d.ts +1 -1
  56. package/dist/types-ts4.5/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
  57. package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
  58. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
  59. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
  60. package/dist/types-ts4.5/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
  61. package/docs/0-intro.tsx +9 -7
  62. package/package.json +2 -2
  63. package/report.api.md +67 -66
  64. package/src/commands/clear.ts +36 -44
  65. package/src/commands/collapse.ts +8 -8
  66. package/src/commands/column-resize.ts +412 -452
  67. package/src/commands/delete.ts +14 -14
  68. package/src/commands/display-mode.ts +10 -11
  69. package/src/commands/go-to-next-cell.ts +48 -54
  70. package/src/commands/hover.ts +210 -227
  71. package/src/commands/index.ts +35 -35
  72. package/src/commands/insert.ts +208 -235
  73. package/src/commands/misc.ts +655 -748
  74. package/src/commands/referentiality.ts +9 -9
  75. package/src/commands/selection.ts +433 -563
  76. package/src/commands/sort.ts +68 -86
  77. package/src/commands/split-cell.ts +14 -14
  78. package/src/commands/toggle.ts +69 -67
  79. package/src/commands-with-analytics.ts +570 -639
  80. package/src/create-plugin-config.ts +13 -13
  81. package/src/event-handlers.ts +513 -612
  82. package/src/handlers.ts +120 -133
  83. package/src/nodeviews/ExternalDropTargets.tsx +68 -73
  84. package/src/nodeviews/OverflowShadowsObserver.ts +148 -157
  85. package/src/nodeviews/TableCell.ts +47 -54
  86. package/src/nodeviews/TableComponent.tsx +1018 -1112
  87. package/src/nodeviews/TableComponentWithSharedState.tsx +91 -94
  88. package/src/nodeviews/TableContainer.tsx +363 -339
  89. package/src/nodeviews/TableNodeViewBase.ts +19 -24
  90. package/src/nodeviews/TableResizer.tsx +565 -657
  91. package/src/nodeviews/TableRow.ts +580 -629
  92. package/src/nodeviews/TableStickyScrollbar.ts +173 -190
  93. package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +8 -8
  94. package/src/nodeviews/__mocks__/OverridableMock.ts +14 -15
  95. package/src/nodeviews/table.tsx +345 -375
  96. package/src/nodeviews/types.ts +21 -24
  97. package/src/nodeviews/update-overflow-shadows.ts +8 -14
  98. package/src/plugin.tsx +578 -603
  99. package/src/pm-plugins/analytics/actions.ts +10 -12
  100. package/src/pm-plugins/analytics/commands.ts +31 -37
  101. package/src/pm-plugins/analytics/plugin-factory.ts +4 -2
  102. package/src/pm-plugins/analytics/plugin-key.ts +1 -3
  103. package/src/pm-plugins/analytics/plugin.ts +60 -70
  104. package/src/pm-plugins/analytics/reducer.ts +19 -19
  105. package/src/pm-plugins/analytics/types.ts +10 -10
  106. package/src/pm-plugins/analytics/utils/moved-event.ts +38 -38
  107. package/src/pm-plugins/decorations/plugin.ts +58 -77
  108. package/src/pm-plugins/decorations/utils/column-controls.ts +59 -71
  109. package/src/pm-plugins/decorations/utils/column-resizing.ts +50 -57
  110. package/src/pm-plugins/decorations/utils/compose-decorations.ts +6 -6
  111. package/src/pm-plugins/decorations/utils/index.ts +3 -6
  112. package/src/pm-plugins/decorations/utils/types.ts +7 -12
  113. package/src/pm-plugins/default-table-selection.ts +3 -3
  114. package/src/pm-plugins/drag-and-drop/actions.ts +25 -25
  115. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +158 -190
  116. package/src/pm-plugins/drag-and-drop/commands.ts +154 -170
  117. package/src/pm-plugins/drag-and-drop/consts.ts +4 -5
  118. package/src/pm-plugins/drag-and-drop/plugin-factory.ts +23 -20
  119. package/src/pm-plugins/drag-and-drop/plugin-key.ts +1 -3
  120. package/src/pm-plugins/drag-and-drop/plugin.ts +329 -383
  121. package/src/pm-plugins/drag-and-drop/reducer.ts +30 -30
  122. package/src/pm-plugins/drag-and-drop/types.ts +8 -8
  123. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +38 -41
  124. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +3 -6
  125. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +57 -70
  126. package/src/pm-plugins/keymap.ts +208 -220
  127. package/src/pm-plugins/main.ts +348 -400
  128. package/src/pm-plugins/plugin-factory.ts +32 -34
  129. package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +83 -97
  130. package/src/pm-plugins/sticky-headers/commands.ts +2 -6
  131. package/src/pm-plugins/sticky-headers/plugin-key.ts +1 -3
  132. package/src/pm-plugins/sticky-headers/plugin-state.ts +41 -44
  133. package/src/pm-plugins/sticky-headers/plugin.ts +4 -4
  134. package/src/pm-plugins/sticky-headers/types.ts +8 -8
  135. package/src/pm-plugins/sticky-headers/util.ts +10 -10
  136. package/src/pm-plugins/table-analytics.ts +70 -72
  137. package/src/pm-plugins/table-local-id.ts +180 -184
  138. package/src/pm-plugins/table-resizing/commands.ts +72 -85
  139. package/src/pm-plugins/table-resizing/event-handlers.ts +298 -317
  140. package/src/pm-plugins/table-resizing/plugin-factory.ts +10 -10
  141. package/src/pm-plugins/table-resizing/plugin-key.ts +1 -3
  142. package/src/pm-plugins/table-resizing/plugin.ts +61 -68
  143. package/src/pm-plugins/table-resizing/reducer.ts +30 -33
  144. package/src/pm-plugins/table-resizing/utils/colgroup.ts +84 -84
  145. package/src/pm-plugins/table-resizing/utils/column-state.ts +78 -81
  146. package/src/pm-plugins/table-resizing/utils/content-width.ts +94 -114
  147. package/src/pm-plugins/table-resizing/utils/dom.ts +93 -110
  148. package/src/pm-plugins/table-resizing/utils/index.ts +29 -34
  149. package/src/pm-plugins/table-resizing/utils/misc.ts +94 -119
  150. package/src/pm-plugins/table-resizing/utils/resize-column.ts +93 -106
  151. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +240 -257
  152. package/src/pm-plugins/table-resizing/utils/resize-state.ts +343 -372
  153. package/src/pm-plugins/table-resizing/utils/scale-table.ts +202 -207
  154. package/src/pm-plugins/table-resizing/utils/types.ts +17 -17
  155. package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +1 -2
  156. package/src/pm-plugins/table-selection-keymap.ts +25 -51
  157. package/src/pm-plugins/table-width.ts +191 -204
  158. package/src/pm-plugins/view-mode-sort/index.ts +223 -227
  159. package/src/pm-plugins/view-mode-sort/plugin-key.ts +3 -2
  160. package/src/pm-plugins/view-mode-sort/types.ts +12 -12
  161. package/src/pm-plugins/view-mode-sort/utils.ts +108 -117
  162. package/src/reducer.ts +139 -155
  163. package/src/toolbar.tsx +815 -905
  164. package/src/transforms/column-width.ts +186 -213
  165. package/src/transforms/delete-columns.ts +208 -222
  166. package/src/transforms/delete-rows.ts +117 -121
  167. package/src/transforms/fix-tables.ts +190 -215
  168. package/src/transforms/merge.ts +263 -269
  169. package/src/transforms/replace-table.ts +27 -43
  170. package/src/transforms/split.ts +65 -75
  171. package/src/types.ts +421 -427
  172. package/src/ui/ColumnResizeWidget/index.tsx +40 -47
  173. package/src/ui/DragHandle/HandleIconComponent.tsx +9 -13
  174. package/src/ui/DragHandle/index.tsx +221 -250
  175. package/src/ui/DragPreview/index.tsx +35 -35
  176. package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +33 -41
  177. package/src/ui/FloatingContextualButton/FixedButton.tsx +154 -157
  178. package/src/ui/FloatingContextualButton/index.tsx +109 -115
  179. package/src/ui/FloatingContextualButton/styles.ts +43 -46
  180. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +634 -694
  181. package/src/ui/FloatingContextualMenu/index.tsx +83 -101
  182. package/src/ui/FloatingContextualMenu/styles.ts +57 -65
  183. package/src/ui/FloatingDeleteButton/DeleteButton.tsx +37 -37
  184. package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +47 -57
  185. package/src/ui/FloatingDeleteButton/index.tsx +319 -350
  186. package/src/ui/FloatingDragMenu/DragMenu.tsx +555 -596
  187. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +152 -162
  188. package/src/ui/FloatingDragMenu/index.tsx +88 -102
  189. package/src/ui/FloatingDragMenu/styles.ts +51 -54
  190. package/src/ui/FloatingInsertButton/InsertButton.tsx +204 -217
  191. package/src/ui/FloatingInsertButton/getPopupOptions.ts +100 -115
  192. package/src/ui/FloatingInsertButton/index.tsx +248 -292
  193. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +24 -29
  194. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +308 -329
  195. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +85 -94
  196. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +46 -46
  197. package/src/ui/TableFloatingColumnControls/index.tsx +116 -136
  198. package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +79 -91
  199. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +95 -102
  200. package/src/ui/TableFloatingControls/CornerControls/index.tsx +1 -4
  201. package/src/ui/TableFloatingControls/CornerControls/types.ts +8 -8
  202. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +50 -50
  203. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +111 -124
  204. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +86 -105
  205. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +305 -341
  206. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +72 -75
  207. package/src/ui/TableFloatingControls/index.tsx +191 -193
  208. package/src/ui/TableFullWidthLabel/index.tsx +20 -20
  209. package/src/ui/common-styles.ts +880 -912
  210. package/src/ui/consts.ts +29 -74
  211. package/src/ui/icons/AddColLeftIcon.tsx +33 -39
  212. package/src/ui/icons/AddColRightIcon.tsx +33 -39
  213. package/src/ui/icons/AddRowAboveIcon.tsx +16 -22
  214. package/src/ui/icons/AddRowBelowIcon.tsx +33 -39
  215. package/src/ui/icons/DisplayModeIcon.tsx +31 -31
  216. package/src/ui/icons/DragHandleDisabledIcon.tsx +19 -21
  217. package/src/ui/icons/DragHandleIcon.tsx +12 -12
  218. package/src/ui/icons/DragInMotionIcon.tsx +45 -52
  219. package/src/ui/icons/MergeCellsIcon.tsx +22 -28
  220. package/src/ui/icons/MinimisedHandle.tsx +9 -9
  221. package/src/ui/icons/SplitCellIcon.tsx +30 -36
  222. package/src/ui/ui-styles.ts +769 -798
  223. package/src/utils/alignment.ts +1 -1
  224. package/src/utils/analytics.ts +192 -208
  225. package/src/utils/collapse.ts +55 -64
  226. package/src/utils/column-controls.ts +237 -254
  227. package/src/utils/create.ts +30 -30
  228. package/src/utils/decoration.ts +482 -502
  229. package/src/utils/dom.ts +127 -134
  230. package/src/utils/drag-menu.ts +322 -373
  231. package/src/utils/get-allow-add-column-custom-step.ts +4 -5
  232. package/src/utils/guidelines.ts +10 -21
  233. package/src/utils/index.ts +68 -68
  234. package/src/utils/merged-cells.ts +245 -254
  235. package/src/utils/nodes.ts +91 -106
  236. package/src/utils/paste.ts +119 -135
  237. package/src/utils/row-controls.ts +199 -213
  238. package/src/utils/selection.ts +77 -87
  239. package/src/utils/snapping.ts +84 -97
  240. package/src/utils/table.ts +44 -44
  241. package/src/utils/transforms.ts +5 -5
  242. package/src/utils/update-plugin-state-decorations.ts +5 -9
package/src/plugin.tsx CHANGED
@@ -3,12 +3,12 @@ import React from 'react';
3
3
  import { table, tableCell, tableHeader, tableRow } from '@atlaskit/adf-schema';
4
4
  import type { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
5
5
  import {
6
- ACTION,
7
- ACTION_SUBJECT,
8
- ACTION_SUBJECT_ID,
9
- EVENT_TYPE,
10
- INPUT_METHOD,
11
- TABLE_ACTION,
6
+ ACTION,
7
+ ACTION_SUBJECT,
8
+ ACTION_SUBJECT_ID,
9
+ EVENT_TYPE,
10
+ INPUT_METHOD,
11
+ TABLE_ACTION,
12
12
  } from '@atlaskit/editor-common/analytics';
13
13
  import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
14
14
  import { IconTable } from '@atlaskit/editor-common/icons';
@@ -16,13 +16,13 @@ import { toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
16
16
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
17
17
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
18
18
  import type {
19
- Command,
20
- EditorCommand,
21
- EditorPlugin,
22
- GetEditorContainerWidth,
23
- GetEditorFeatureFlags,
24
- NextEditorPlugin,
25
- OptionalPlugin,
19
+ Command,
20
+ EditorCommand,
21
+ EditorPlugin,
22
+ GetEditorContainerWidth,
23
+ GetEditorFeatureFlags,
24
+ NextEditorPlugin,
25
+ OptionalPlugin,
26
26
  } from '@atlaskit/editor-common/types';
27
27
  import { browser } from '@atlaskit/editor-common/utils';
28
28
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
@@ -45,8 +45,8 @@ import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analyti
45
45
  import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
46
46
  import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
47
47
  import {
48
- createPlugin as createDragAndDropPlugin,
49
- pluginKey as dragAndDropPluginKey,
48
+ createPlugin as createDragAndDropPlugin,
49
+ pluginKey as dragAndDropPluginKey,
50
50
  } from './pm-plugins/drag-and-drop';
51
51
  import { keymapPlugin } from './pm-plugins/keymap';
52
52
  import { createPlugin } from './pm-plugins/main';
@@ -54,29 +54,25 @@ import { getPluginState } from './pm-plugins/plugin-factory';
54
54
  import { pluginKey } from './pm-plugins/plugin-key';
55
55
  import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
56
56
  import {
57
- createPlugin as createStickyHeadersPlugin,
58
- findStickyHeaderForTable,
59
- pluginKey as stickyHeadersPluginKey,
57
+ createPlugin as createStickyHeadersPlugin,
58
+ findStickyHeaderForTable,
59
+ pluginKey as stickyHeadersPluginKey,
60
60
  } from './pm-plugins/sticky-headers';
61
61
  import { createPlugin as createTableOverflowAnalyticsPlugin } from './pm-plugins/table-analytics';
62
62
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
63
63
  import {
64
- createPlugin as createFlexiResizingPlugin,
65
- getPluginState as getFlexiResizingPlugin,
66
- pluginKey as tableResizingPluginKey,
64
+ createPlugin as createFlexiResizingPlugin,
65
+ getPluginState as getFlexiResizingPlugin,
66
+ pluginKey as tableResizingPluginKey,
67
67
  } from './pm-plugins/table-resizing';
68
68
  import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
69
69
  import {
70
- createPlugin as createTableWidthPlugin,
71
- pluginKey as tableWidthPluginKey,
70
+ createPlugin as createTableWidthPlugin,
71
+ pluginKey as tableWidthPluginKey,
72
72
  } from './pm-plugins/table-width';
73
73
  import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
74
74
  import { getToolbarConfig } from './toolbar';
75
- import type {
76
- ColumnResizingPluginState,
77
- PluginConfig,
78
- TableSharedState,
79
- } from './types';
75
+ import type { ColumnResizingPluginState, PluginConfig, TableSharedState } from './types';
80
76
  import FloatingContextualButton from './ui/FloatingContextualButton';
81
77
  import FloatingContextualMenu from './ui/FloatingContextualMenu';
82
78
  import FloatingDeleteButton from './ui/FloatingDeleteButton';
@@ -87,16 +83,16 @@ import { FullWidthDisplay } from './ui/TableFullWidthLabel';
87
83
  import { createTableWithWidth } from './utils';
88
84
 
89
85
  export interface TablePluginOptions {
90
- tableOptions: PluginConfig;
91
- tableResizingEnabled?: boolean;
92
- dragAndDropEnabled?: boolean;
93
- allowContextualMenu?: boolean;
94
- // TODO these two need to be rethought
95
- fullWidthEnabled?: boolean;
96
- wasFullWidthEnabled?: boolean;
97
- getEditorFeatureFlags?: GetEditorFeatureFlags;
98
- isTableScalingEnabled?: boolean;
99
- isTableAlignmentEnabled?: boolean;
86
+ tableOptions: PluginConfig;
87
+ tableResizingEnabled?: boolean;
88
+ dragAndDropEnabled?: boolean;
89
+ allowContextualMenu?: boolean;
90
+ // TODO these two need to be rethought
91
+ fullWidthEnabled?: boolean;
92
+ wasFullWidthEnabled?: boolean;
93
+ getEditorFeatureFlags?: GetEditorFeatureFlags;
94
+ isTableScalingEnabled?: boolean;
95
+ isTableAlignmentEnabled?: boolean;
100
96
  }
101
97
 
102
98
  type InsertTableAction = (analyticsPayload: AnalyticsEventPayload) => Command;
@@ -105,41 +101,41 @@ const defaultGetEditorFeatureFlags = () => ({});
105
101
 
106
102
  // TODO: duplicating type instead of importing media plugin causing a circular dependency
107
103
  type MediaPlugin = NextEditorPlugin<
108
- 'media',
109
- {
110
- pluginConfiguration: any;
111
- dependencies: any;
112
- sharedState: any;
113
- actions: any;
114
- }
104
+ 'media',
105
+ {
106
+ pluginConfiguration: any;
107
+ dependencies: any;
108
+ sharedState: any;
109
+ actions: any;
110
+ }
115
111
  >;
116
112
 
117
113
  export type TablePlugin = NextEditorPlugin<
118
- 'table',
119
- {
120
- pluginConfiguration: TablePluginOptions | undefined;
121
- actions: {
122
- insertTable: InsertTableAction;
123
- };
124
- sharedState?: TableSharedState;
125
- commands: {
126
- insertTableWithSize: (
127
- rowsCount: number,
128
- colsCount: number,
129
- inputMethod?: INPUT_METHOD.PICKER,
130
- ) => EditorCommand;
131
- };
132
- dependencies: [
133
- AnalyticsPlugin,
134
- ContentInsertionPlugin,
135
- WidthPlugin,
136
- GuidelinePlugin,
137
- SelectionPlugin,
138
- OptionalPlugin<AccessibilityUtilsPlugin>,
139
- OptionalPlugin<MediaPlugin>,
140
- OptionalPlugin<EditorViewModePlugin>,
141
- ];
142
- }
114
+ 'table',
115
+ {
116
+ pluginConfiguration: TablePluginOptions | undefined;
117
+ actions: {
118
+ insertTable: InsertTableAction;
119
+ };
120
+ sharedState?: TableSharedState;
121
+ commands: {
122
+ insertTableWithSize: (
123
+ rowsCount: number,
124
+ colsCount: number,
125
+ inputMethod?: INPUT_METHOD.PICKER,
126
+ ) => EditorCommand;
127
+ };
128
+ dependencies: [
129
+ AnalyticsPlugin,
130
+ ContentInsertionPlugin,
131
+ WidthPlugin,
132
+ GuidelinePlugin,
133
+ SelectionPlugin,
134
+ OptionalPlugin<AccessibilityUtilsPlugin>,
135
+ OptionalPlugin<MediaPlugin>,
136
+ OptionalPlugin<EditorViewModePlugin>,
137
+ ];
138
+ }
143
139
  >;
144
140
 
145
141
  /**
@@ -147,539 +143,518 @@ export type TablePlugin = NextEditorPlugin<
147
143
  * from `@atlaskit/editor-core`.
148
144
  */
149
145
  const tablesPlugin: TablePlugin = ({ config: options, api }) => {
150
- const editorViewRef: Record<'current', EditorView | null> = { current: null };
151
- const defaultGetEditorContainerWidth: GetEditorContainerWidth = () => {
152
- return (
153
- api?.width?.sharedState.currentState() ?? {
154
- width: document?.body?.offsetWidth ?? 500,
155
- }
156
- );
157
- };
158
- const editorAnalyticsAPI = api?.analytics?.actions;
159
-
160
- return {
161
- name: 'table',
162
-
163
- // Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
164
- // to most up to date values - passing to createPluginState will not re-initialise the state
165
- getSharedState: (editorState) => {
166
- if (!editorState) {
167
- return undefined;
168
- }
169
-
170
- const tablePluginState = getPluginState(editorState);
171
- const tableResizingPluginState = getFlexiResizingPlugin(editorState);
172
- const tableWidthResizingPluginState =
173
- tableWidthPluginKey.getState(editorState);
174
-
175
- return {
176
- isFullWidthModeEnabled: !!options?.fullWidthEnabled,
177
- wasFullWidthModeEnabled: !!options?.wasFullWidthEnabled,
178
- isHeaderRowEnabled: tablePluginState.isHeaderRowEnabled,
179
- isHeaderColumnEnabled: tablePluginState.isHeaderColumnEnabled,
180
- ordering: tablePluginState.ordering,
181
- isResizing: !!(
182
- tableResizingPluginState?.dragging ||
183
- tableWidthResizingPluginState?.resizing
184
- ),
185
- isTableResizing: tableWidthResizingPluginState?.resizing,
186
- isInDanger: tablePluginState.isInDanger,
187
- hoveredRows: tablePluginState.hoveredRows,
188
- hoveredCell: tablePluginState.hoveredCell,
189
- isTableHovered: tablePluginState.isTableHovered,
190
- isWholeTableInDanger: tablePluginState.isWholeTableInDanger,
191
- // IMPORTANT: Need to continue to pass tableNode to control re-renders
192
- // TableComponent listens for node attribute changes to update colgroups
193
- tableNode: tablePluginState.tableNode,
194
- widthToWidest: tablePluginState.widthToWidest,
195
- };
196
- },
197
-
198
- actions: {
199
- insertTable:
200
- (analyticsPayload): Command =>
201
- (state, dispatch) => {
202
- const node = createTableWithWidth({
203
- isTableScalingEnabled: options?.isTableScalingEnabled,
204
- isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
205
- isFullWidthModeEnabled: options?.fullWidthEnabled,
206
- })(state.schema);
207
-
208
- return (
209
- api?.contentInsertion?.actions?.insert({
210
- state,
211
- dispatch,
212
- node,
213
-
214
- options: {
215
- selectNodeInserted: false,
216
- analyticsPayload: {
217
- ...analyticsPayload,
218
- attributes: {
219
- ...analyticsPayload.attributes,
220
- localId: node.attrs.localId,
221
- },
222
- },
223
- },
224
- }) ?? false
225
- );
226
- },
227
- },
228
-
229
- commands: {
230
- insertTableWithSize: insertTableWithSize(
231
- options?.fullWidthEnabled,
232
- options?.isTableScalingEnabled,
233
- options?.isTableAlignmentEnabled,
234
- api?.analytics?.actions,
235
- ),
236
- },
237
-
238
- nodes() {
239
- return [
240
- { name: 'table', node: table },
241
- { name: 'tableHeader', node: tableHeader },
242
- { name: 'tableRow', node: tableRow },
243
- { name: 'tableCell', node: tableCell },
244
- ];
245
- },
246
-
247
- pmPlugins() {
248
- const plugins: ReturnType<NonNullable<EditorPlugin['pmPlugins']>> = [
249
- {
250
- name: 'table',
251
- plugin: ({
252
- dispatchAnalyticsEvent,
253
- dispatch,
254
- portalProviderAPI,
255
- eventDispatcher,
256
- getIntl,
257
- }) => {
258
- const {
259
- fullWidthEnabled,
260
- wasFullWidthEnabled,
261
- tableResizingEnabled,
262
-
263
- tableOptions,
264
- getEditorFeatureFlags,
265
- dragAndDropEnabled,
266
- isTableScalingEnabled,
267
- isTableAlignmentEnabled,
268
- } = options || ({} as TablePluginOptions);
269
-
270
- return createPlugin(
271
- dispatchAnalyticsEvent,
272
- dispatch,
273
- portalProviderAPI,
274
- eventDispatcher,
275
- pluginConfig(tableOptions),
276
- defaultGetEditorContainerWidth,
277
- getEditorFeatureFlags || defaultGetEditorFeatureFlags,
278
- getIntl,
279
- tableResizingEnabled,
280
- fullWidthEnabled,
281
- wasFullWidthEnabled,
282
- dragAndDropEnabled,
283
- editorAnalyticsAPI,
284
- api,
285
- isTableScalingEnabled,
286
- isTableAlignmentEnabled,
287
- );
288
- },
289
- },
290
- {
291
- name: 'tablePMColResizing',
292
- plugin: ({ dispatch }) => {
293
- const {
294
- fullWidthEnabled,
295
- tableOptions,
296
- getEditorFeatureFlags,
297
- isTableScalingEnabled,
298
- } = options || ({} as TablePluginOptions);
299
- const { allowColumnResizing } = pluginConfig(tableOptions);
300
- return allowColumnResizing
301
- ? createFlexiResizingPlugin(
302
- dispatch,
303
- {
304
- lastColumnResizable: !fullWidthEnabled,
305
- } as ColumnResizingPluginState,
306
- defaultGetEditorContainerWidth,
307
- getEditorFeatureFlags || defaultGetEditorFeatureFlags,
308
- editorAnalyticsAPI,
309
- isTableScalingEnabled || false,
310
- )
311
- : undefined;
312
- },
313
- },
314
- { name: 'tableEditing', plugin: () => createDecorationsPlugin() },
315
- // Needs to be lower priority than editor-tables.tableEditing
316
- // plugin as it is currently swallowing backspace events inside tables
317
- {
318
- name: 'tableKeymap',
319
- plugin: ({ getIntl }) => {
320
- const {
321
- dragAndDropEnabled,
322
- isTableScalingEnabled = false,
323
- isTableAlignmentEnabled = false,
324
- fullWidthEnabled = false,
325
- } = options || ({} as TablePluginOptions);
326
- return keymapPlugin(
327
- defaultGetEditorContainerWidth,
328
- editorAnalyticsAPI,
329
- dragAndDropEnabled,
330
- isTableScalingEnabled,
331
- isTableAlignmentEnabled,
332
- fullWidthEnabled,
333
- api,
334
- getIntl,
335
- );
336
- },
337
- },
338
- {
339
- name: 'tableSelectionKeymap',
340
- plugin: () => tableSelectionKeymapPlugin(api?.selection),
341
- },
342
- {
343
- name: 'tableEditing',
344
- plugin: () => {
345
- const { dragAndDropEnabled } =
346
- options || ({} as TablePluginOptions);
347
-
348
- return tableEditing({
349
- reportFixedTable: ({
350
- tr,
351
- reason,
352
- }: {
353
- tr: Transaction;
354
- reason: string;
355
- }) => {
356
- editorAnalyticsAPI?.attachAnalyticsEvent({
357
- action: TABLE_ACTION.FIXED,
358
- actionSubject: ACTION_SUBJECT.TABLE,
359
- actionSubjectId: null,
360
- attributes: {
361
- reason,
362
- },
363
- eventType: EVENT_TYPE.TRACK,
364
- })(tr);
365
- },
366
- dragAndDropEnabled,
367
- }) as SafePlugin;
368
- },
369
- },
370
- {
371
- name: 'tableStickyHeaders',
372
- plugin: ({ dispatch, eventDispatcher }) =>
373
- options && options.tableOptions.stickyHeaders
374
- ? createStickyHeadersPlugin(dispatch, () => [])
375
- : undefined,
376
- },
377
- {
378
- name: 'tableDragAndDrop',
379
- plugin: ({ dispatch }) => {
380
- return options?.dragAndDropEnabled
381
- ? createDragAndDropPlugin(dispatch, editorAnalyticsAPI)
382
- : undefined;
383
- },
384
- },
385
- {
386
- name: 'tableViewModeSort',
387
- plugin: () => {
388
- return getBooleanFF(
389
- 'platform.editor.table.live-pages-sorting_4malx',
390
- ) && api?.editorViewMode
391
- ? createViewModeSortPlugin(api.editorViewMode)
392
- : undefined;
393
- },
394
- },
395
- {
396
- name: 'tableLocalId',
397
- plugin: ({ dispatch }) => createTableLocalIdPlugin(dispatch),
398
- },
399
- {
400
- name: 'tableWidth',
401
- plugin: ({ dispatchAnalyticsEvent, dispatch }) =>
402
- options?.tableResizingEnabled
403
- ? createTableWidthPlugin(
404
- dispatch,
405
- dispatchAnalyticsEvent,
406
- options?.fullWidthEnabled ?? false,
407
- options?.isTableScalingEnabled ?? false,
408
- options?.isTableAlignmentEnabled ?? false,
409
- )
410
- : undefined,
411
- },
412
- // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
413
- {
414
- name: 'tableOverflowAnalyticsPlugin',
415
- plugin: ({ dispatch, dispatchAnalyticsEvent }) =>
416
- createTableOverflowAnalyticsPlugin(
417
- dispatch,
418
- dispatchAnalyticsEvent,
419
- options?.tableResizingEnabled ?? false,
420
- ),
421
- },
422
- {
423
- name: 'tableAnalyticsPlugin',
424
- plugin: ({ dispatch, dispatchAnalyticsEvent }) =>
425
- createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent),
426
- },
427
- {
428
- name: 'tableGetEditorViewReferencePlugin',
429
- plugin: () => {
430
- return new SafePlugin({
431
- view: (editorView) => {
432
- editorViewRef.current = editorView;
433
- return {
434
- destroy: () => {
435
- editorViewRef.current = null;
436
- },
437
- };
438
- },
439
- });
440
- },
441
- },
442
- ];
443
-
444
- // Workaround for table element breaking issue caused by composition event with an inputType of deleteCompositionText.
445
- // https://github.com/ProseMirror/prosemirror/issues/934
446
- if (browser.safari) {
447
- plugins.push({
448
- name: 'tableSafariDeleteCompositionTextIssueWorkaround',
449
- plugin: () => {
450
- return createTableSafariDeleteCompositionTextIssueWorkaroundPlugin();
451
- },
452
- });
453
- }
454
-
455
- return plugins;
456
- },
457
-
458
- contentComponent({
459
- editorView,
460
- popupsMountPoint,
461
- popupsBoundariesElement,
462
- popupsScrollableElement,
463
- dispatchAnalyticsEvent,
464
- }) {
465
- return (
466
- <ErrorBoundary
467
- component={ACTION_SUBJECT.TABLES_PLUGIN}
468
- dispatchAnalyticsEvent={dispatchAnalyticsEvent}
469
- fallbackComponent={null}
470
- >
471
- <WithPluginState
472
- plugins={{
473
- tableAnalyticsPluginState: tableAnalyticsPluginKey,
474
- tablePluginState: pluginKey,
475
- tableWidthPluginState: tableWidthPluginKey,
476
- tableResizingPluginState: tableResizingPluginKey,
477
- stickyHeadersState: stickyHeadersPluginKey,
478
- dragAndDropState: dragAndDropPluginKey,
479
- }}
480
- render={({
481
- tableResizingPluginState: resizingPluginState,
482
- stickyHeadersState,
483
- tablePluginState,
484
- tableWidthPluginState,
485
- dragAndDropState,
486
- }) => {
487
- const isColumnResizing = resizingPluginState?.dragging;
488
- const isTableResizing = tableWidthPluginState?.resizing;
489
- const resizingTableLocalId = tableWidthPluginState?.tableLocalId;
490
- const resizingTableRef = tableWidthPluginState?.tableRef;
491
- const isResizing = isColumnResizing || isTableResizing;
492
- const widthToWidest = tablePluginState?.widthToWidest;
493
-
494
- const {
495
- tableNode,
496
- tablePos,
497
- targetCellPosition,
498
- isContextualMenuOpen,
499
- tableRef,
500
- pluginConfig,
501
- insertColumnButtonIndex,
502
- insertRowButtonIndex,
503
- isHeaderColumnEnabled,
504
- isHeaderRowEnabled,
505
- isDragAndDropEnabled,
506
- tableWrapperTarget,
507
- } = tablePluginState!;
508
-
509
- const { allowControls } = pluginConfig;
510
-
511
- const stickyHeader = stickyHeadersState
512
- ? findStickyHeaderForTable(stickyHeadersState, tablePos)
513
- : undefined;
514
-
515
- return (
516
- <>
517
- {targetCellPosition &&
518
- tableRef &&
519
- !isResizing &&
520
- options &&
521
- options.allowContextualMenu && (
522
- <FloatingContextualButton
523
- isNumberColumnEnabled={
524
- tableNode && tableNode.attrs.isNumberColumnEnabled
525
- }
526
- editorView={editorView}
527
- tableNode={tableNode}
528
- mountPoint={popupsMountPoint}
529
- targetCellPosition={targetCellPosition}
530
- scrollableElement={popupsScrollableElement}
531
- dispatchAnalyticsEvent={dispatchAnalyticsEvent}
532
- isContextualMenuOpen={isContextualMenuOpen}
533
- stickyHeader={stickyHeader}
534
- tableWrapper={tableWrapperTarget}
535
- />
536
- )}
537
- {allowControls && (
538
- <FloatingInsertButton
539
- tableNode={tableNode}
540
- tableRef={tableRef}
541
- insertColumnButtonIndex={insertColumnButtonIndex}
542
- insertRowButtonIndex={insertRowButtonIndex}
543
- isHeaderColumnEnabled={isHeaderColumnEnabled}
544
- isHeaderRowEnabled={isHeaderRowEnabled}
545
- isDragAndDropEnabled={isDragAndDropEnabled}
546
- editorView={editorView}
547
- mountPoint={popupsMountPoint}
548
- boundariesElement={popupsBoundariesElement}
549
- scrollableElement={popupsScrollableElement}
550
- hasStickyHeaders={stickyHeader && stickyHeader.sticky}
551
- dispatchAnalyticsEvent={dispatchAnalyticsEvent}
552
- editorAnalyticsAPI={editorAnalyticsAPI}
553
- getEditorContainerWidth={defaultGetEditorContainerWidth}
554
- getEditorFeatureFlags={
555
- options?.getEditorFeatureFlags ||
556
- defaultGetEditorFeatureFlags
557
- }
558
- />
559
- )}
560
- {options?.allowContextualMenu && (
561
- <FloatingContextualMenu
562
- editorView={editorView}
563
- mountPoint={popupsMountPoint}
564
- boundariesElement={popupsBoundariesElement}
565
- targetCellPosition={targetCellPosition}
566
- isOpen={Boolean(isContextualMenuOpen) && !isResizing}
567
- pluginConfig={pluginConfig}
568
- editorAnalyticsAPI={editorAnalyticsAPI}
569
- getEditorContainerWidth={defaultGetEditorContainerWidth}
570
- getEditorFeatureFlags={
571
- options?.getEditorFeatureFlags ||
572
- defaultGetEditorFeatureFlags
573
- }
574
- />
575
- )}
576
- {isDragAndDropEnabled && (
577
- <FloatingDragMenu
578
- editorView={editorView}
579
- mountPoint={popupsMountPoint}
580
- boundariesElement={popupsBoundariesElement}
581
- tableRef={tableRef as HTMLTableElement}
582
- tableNode={tableNode}
583
- targetCellPosition={targetCellPosition}
584
- direction={dragAndDropState?.dragMenuDirection}
585
- index={dragAndDropState?.dragMenuIndex}
586
- isOpen={!!dragAndDropState?.isDragMenuOpen && !isResizing}
587
- getEditorContainerWidth={defaultGetEditorContainerWidth}
588
- editorAnalyticsAPI={editorAnalyticsAPI}
589
- stickyHeaders={stickyHeader}
590
- pluginConfig={pluginConfig}
591
- isTableScalingEnabled={options?.isTableScalingEnabled}
592
- getEditorFeatureFlags={
593
- options?.getEditorFeatureFlags ||
594
- defaultGetEditorFeatureFlags
595
- }
596
- />
597
- )}
598
- {allowControls && !isDragAndDropEnabled && !isResizing && (
599
- <FloatingDeleteButton
600
- editorView={editorView}
601
- selection={editorView.state.selection}
602
- tableRef={tableRef as HTMLTableElement}
603
- mountPoint={popupsMountPoint}
604
- boundariesElement={popupsBoundariesElement}
605
- scrollableElement={popupsScrollableElement}
606
- stickyHeaders={stickyHeader}
607
- isNumberColumnEnabled={
608
- tableNode && tableNode.attrs.isNumberColumnEnabled
609
- }
610
- editorAnalyticsAPI={editorAnalyticsAPI}
611
- />
612
- )}
613
- {options?.isTableScalingEnabled &&
614
- isTableResizing &&
615
- widthToWidest &&
616
- resizingTableLocalId &&
617
- resizingTableRef &&
618
- widthToWidest[resizingTableLocalId] && (
619
- <FloatingToolbarLabel
620
- target={resizingTableRef}
621
- content={<FullWidthDisplay />}
622
- alignX={'center'}
623
- alignY={'bottom'}
624
- stick={true}
625
- forcePlacement={true}
626
- zIndex={akEditorFloatingPanelZIndex}
627
- offset={[0, 10]}
628
- />
629
- )}
630
- </>
631
- );
632
- }}
633
- />
634
- </ErrorBoundary>
635
- );
636
- },
637
-
638
- pluginsOptions: {
639
- quickInsert: ({ formatMessage }) => [
640
- {
641
- id: 'table',
642
- title: formatMessage(messages.table),
643
- description: formatMessage(messages.tableDescription),
644
- keywords: ['cell', 'table'],
645
- priority: 600,
646
- keyshortcut: tooltip(toggleTable),
647
- icon: () => <IconTable />,
648
- action(insert, state) {
649
- // see comment on tablesPlugin.getSharedState on usage
650
- const tableState = api?.table?.sharedState.currentState();
651
-
652
- const tableNode = createTableWithWidth({
653
- isTableScalingEnabled: options?.isTableScalingEnabled,
654
- isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
655
- isFullWidthModeEnabled: tableState?.isFullWidthModeEnabled,
656
- })(state.schema);
657
-
658
- const tr = insert(tableNode);
659
-
660
- editorAnalyticsAPI?.attachAnalyticsEvent({
661
- action: ACTION.INSERTED,
662
- actionSubject: ACTION_SUBJECT.DOCUMENT,
663
- actionSubjectId: ACTION_SUBJECT_ID.TABLE,
664
- attributes: {
665
- inputMethod: INPUT_METHOD.QUICK_INSERT,
666
- localId: tableNode.attrs.localId,
667
- },
668
- eventType: EVENT_TYPE.TRACK,
669
- })(tr);
670
- return tr;
671
- },
672
- },
673
- ],
674
- floatingToolbar: getToolbarConfig(
675
- defaultGetEditorContainerWidth,
676
- editorAnalyticsAPI,
677
- options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags,
678
- () => editorViewRef.current,
679
- options,
680
- )(pluginConfig(options?.tableOptions)),
681
- },
682
- };
146
+ const editorViewRef: Record<'current', EditorView | null> = { current: null };
147
+ const defaultGetEditorContainerWidth: GetEditorContainerWidth = () => {
148
+ return (
149
+ api?.width?.sharedState.currentState() ?? {
150
+ width: document?.body?.offsetWidth ?? 500,
151
+ }
152
+ );
153
+ };
154
+ const editorAnalyticsAPI = api?.analytics?.actions;
155
+
156
+ return {
157
+ name: 'table',
158
+
159
+ // Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
160
+ // to most up to date values - passing to createPluginState will not re-initialise the state
161
+ getSharedState: (editorState) => {
162
+ if (!editorState) {
163
+ return undefined;
164
+ }
165
+
166
+ const tablePluginState = getPluginState(editorState);
167
+ const tableResizingPluginState = getFlexiResizingPlugin(editorState);
168
+ const tableWidthResizingPluginState = tableWidthPluginKey.getState(editorState);
169
+
170
+ return {
171
+ isFullWidthModeEnabled: !!options?.fullWidthEnabled,
172
+ wasFullWidthModeEnabled: !!options?.wasFullWidthEnabled,
173
+ isHeaderRowEnabled: tablePluginState.isHeaderRowEnabled,
174
+ isHeaderColumnEnabled: tablePluginState.isHeaderColumnEnabled,
175
+ ordering: tablePluginState.ordering,
176
+ isResizing: !!(
177
+ tableResizingPluginState?.dragging || tableWidthResizingPluginState?.resizing
178
+ ),
179
+ isTableResizing: tableWidthResizingPluginState?.resizing,
180
+ isInDanger: tablePluginState.isInDanger,
181
+ hoveredRows: tablePluginState.hoveredRows,
182
+ hoveredCell: tablePluginState.hoveredCell,
183
+ isTableHovered: tablePluginState.isTableHovered,
184
+ isWholeTableInDanger: tablePluginState.isWholeTableInDanger,
185
+ // IMPORTANT: Need to continue to pass tableNode to control re-renders
186
+ // TableComponent listens for node attribute changes to update colgroups
187
+ tableNode: tablePluginState.tableNode,
188
+ widthToWidest: tablePluginState.widthToWidest,
189
+ };
190
+ },
191
+
192
+ actions: {
193
+ insertTable:
194
+ (analyticsPayload): Command =>
195
+ (state, dispatch) => {
196
+ const node = createTableWithWidth({
197
+ isTableScalingEnabled: options?.isTableScalingEnabled,
198
+ isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
199
+ isFullWidthModeEnabled: options?.fullWidthEnabled,
200
+ })(state.schema);
201
+
202
+ return (
203
+ api?.contentInsertion?.actions?.insert({
204
+ state,
205
+ dispatch,
206
+ node,
207
+
208
+ options: {
209
+ selectNodeInserted: false,
210
+ analyticsPayload: {
211
+ ...analyticsPayload,
212
+ attributes: {
213
+ ...analyticsPayload.attributes,
214
+ localId: node.attrs.localId,
215
+ },
216
+ },
217
+ },
218
+ }) ?? false
219
+ );
220
+ },
221
+ },
222
+
223
+ commands: {
224
+ insertTableWithSize: insertTableWithSize(
225
+ options?.fullWidthEnabled,
226
+ options?.isTableScalingEnabled,
227
+ options?.isTableAlignmentEnabled,
228
+ api?.analytics?.actions,
229
+ ),
230
+ },
231
+
232
+ nodes() {
233
+ return [
234
+ { name: 'table', node: table },
235
+ { name: 'tableHeader', node: tableHeader },
236
+ { name: 'tableRow', node: tableRow },
237
+ { name: 'tableCell', node: tableCell },
238
+ ];
239
+ },
240
+
241
+ pmPlugins() {
242
+ const plugins: ReturnType<NonNullable<EditorPlugin['pmPlugins']>> = [
243
+ {
244
+ name: 'table',
245
+ plugin: ({
246
+ dispatchAnalyticsEvent,
247
+ dispatch,
248
+ portalProviderAPI,
249
+ eventDispatcher,
250
+ getIntl,
251
+ }) => {
252
+ const {
253
+ fullWidthEnabled,
254
+ wasFullWidthEnabled,
255
+ tableResizingEnabled,
256
+
257
+ tableOptions,
258
+ getEditorFeatureFlags,
259
+ dragAndDropEnabled,
260
+ isTableScalingEnabled,
261
+ isTableAlignmentEnabled,
262
+ } = options || ({} as TablePluginOptions);
263
+
264
+ return createPlugin(
265
+ dispatchAnalyticsEvent,
266
+ dispatch,
267
+ portalProviderAPI,
268
+ eventDispatcher,
269
+ pluginConfig(tableOptions),
270
+ defaultGetEditorContainerWidth,
271
+ getEditorFeatureFlags || defaultGetEditorFeatureFlags,
272
+ getIntl,
273
+ tableResizingEnabled,
274
+ fullWidthEnabled,
275
+ wasFullWidthEnabled,
276
+ dragAndDropEnabled,
277
+ editorAnalyticsAPI,
278
+ api,
279
+ isTableScalingEnabled,
280
+ isTableAlignmentEnabled,
281
+ );
282
+ },
283
+ },
284
+ {
285
+ name: 'tablePMColResizing',
286
+ plugin: ({ dispatch }) => {
287
+ const { fullWidthEnabled, tableOptions, getEditorFeatureFlags, isTableScalingEnabled } =
288
+ options || ({} as TablePluginOptions);
289
+ const { allowColumnResizing } = pluginConfig(tableOptions);
290
+ return allowColumnResizing
291
+ ? createFlexiResizingPlugin(
292
+ dispatch,
293
+ {
294
+ lastColumnResizable: !fullWidthEnabled,
295
+ } as ColumnResizingPluginState,
296
+ defaultGetEditorContainerWidth,
297
+ getEditorFeatureFlags || defaultGetEditorFeatureFlags,
298
+ editorAnalyticsAPI,
299
+ isTableScalingEnabled || false,
300
+ )
301
+ : undefined;
302
+ },
303
+ },
304
+ { name: 'tableEditing', plugin: () => createDecorationsPlugin() },
305
+ // Needs to be lower priority than editor-tables.tableEditing
306
+ // plugin as it is currently swallowing backspace events inside tables
307
+ {
308
+ name: 'tableKeymap',
309
+ plugin: ({ getIntl }) => {
310
+ const {
311
+ dragAndDropEnabled,
312
+ isTableScalingEnabled = false,
313
+ isTableAlignmentEnabled = false,
314
+ fullWidthEnabled = false,
315
+ } = options || ({} as TablePluginOptions);
316
+ return keymapPlugin(
317
+ defaultGetEditorContainerWidth,
318
+ editorAnalyticsAPI,
319
+ dragAndDropEnabled,
320
+ isTableScalingEnabled,
321
+ isTableAlignmentEnabled,
322
+ fullWidthEnabled,
323
+ api,
324
+ getIntl,
325
+ );
326
+ },
327
+ },
328
+ {
329
+ name: 'tableSelectionKeymap',
330
+ plugin: () => tableSelectionKeymapPlugin(api?.selection),
331
+ },
332
+ {
333
+ name: 'tableEditing',
334
+ plugin: () => {
335
+ const { dragAndDropEnabled } = options || ({} as TablePluginOptions);
336
+
337
+ return tableEditing({
338
+ reportFixedTable: ({ tr, reason }: { tr: Transaction; reason: string }) => {
339
+ editorAnalyticsAPI?.attachAnalyticsEvent({
340
+ action: TABLE_ACTION.FIXED,
341
+ actionSubject: ACTION_SUBJECT.TABLE,
342
+ actionSubjectId: null,
343
+ attributes: {
344
+ reason,
345
+ },
346
+ eventType: EVENT_TYPE.TRACK,
347
+ })(tr);
348
+ },
349
+ dragAndDropEnabled,
350
+ }) as SafePlugin;
351
+ },
352
+ },
353
+ {
354
+ name: 'tableStickyHeaders',
355
+ plugin: ({ dispatch, eventDispatcher }) =>
356
+ options && options.tableOptions.stickyHeaders
357
+ ? createStickyHeadersPlugin(dispatch, () => [])
358
+ : undefined,
359
+ },
360
+ {
361
+ name: 'tableDragAndDrop',
362
+ plugin: ({ dispatch }) => {
363
+ return options?.dragAndDropEnabled
364
+ ? createDragAndDropPlugin(dispatch, editorAnalyticsAPI)
365
+ : undefined;
366
+ },
367
+ },
368
+ {
369
+ name: 'tableViewModeSort',
370
+ plugin: () => {
371
+ return getBooleanFF('platform.editor.table.live-pages-sorting_4malx') &&
372
+ api?.editorViewMode
373
+ ? createViewModeSortPlugin(api.editorViewMode)
374
+ : undefined;
375
+ },
376
+ },
377
+ {
378
+ name: 'tableLocalId',
379
+ plugin: ({ dispatch }) => createTableLocalIdPlugin(dispatch),
380
+ },
381
+ {
382
+ name: 'tableWidth',
383
+ plugin: ({ dispatchAnalyticsEvent, dispatch }) =>
384
+ options?.tableResizingEnabled
385
+ ? createTableWidthPlugin(
386
+ dispatch,
387
+ dispatchAnalyticsEvent,
388
+ options?.fullWidthEnabled ?? false,
389
+ options?.isTableScalingEnabled ?? false,
390
+ options?.isTableAlignmentEnabled ?? false,
391
+ )
392
+ : undefined,
393
+ },
394
+ // TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
395
+ {
396
+ name: 'tableOverflowAnalyticsPlugin',
397
+ plugin: ({ dispatch, dispatchAnalyticsEvent }) =>
398
+ createTableOverflowAnalyticsPlugin(
399
+ dispatch,
400
+ dispatchAnalyticsEvent,
401
+ options?.tableResizingEnabled ?? false,
402
+ ),
403
+ },
404
+ {
405
+ name: 'tableAnalyticsPlugin',
406
+ plugin: ({ dispatch, dispatchAnalyticsEvent }) =>
407
+ createTableAnalyticsPlugin(dispatch, dispatchAnalyticsEvent),
408
+ },
409
+ {
410
+ name: 'tableGetEditorViewReferencePlugin',
411
+ plugin: () => {
412
+ return new SafePlugin({
413
+ view: (editorView) => {
414
+ editorViewRef.current = editorView;
415
+ return {
416
+ destroy: () => {
417
+ editorViewRef.current = null;
418
+ },
419
+ };
420
+ },
421
+ });
422
+ },
423
+ },
424
+ ];
425
+
426
+ // Workaround for table element breaking issue caused by composition event with an inputType of deleteCompositionText.
427
+ // https://github.com/ProseMirror/prosemirror/issues/934
428
+ if (browser.safari) {
429
+ plugins.push({
430
+ name: 'tableSafariDeleteCompositionTextIssueWorkaround',
431
+ plugin: () => {
432
+ return createTableSafariDeleteCompositionTextIssueWorkaroundPlugin();
433
+ },
434
+ });
435
+ }
436
+
437
+ return plugins;
438
+ },
439
+
440
+ contentComponent({
441
+ editorView,
442
+ popupsMountPoint,
443
+ popupsBoundariesElement,
444
+ popupsScrollableElement,
445
+ dispatchAnalyticsEvent,
446
+ }) {
447
+ return (
448
+ <ErrorBoundary
449
+ component={ACTION_SUBJECT.TABLES_PLUGIN}
450
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
451
+ fallbackComponent={null}
452
+ >
453
+ <WithPluginState
454
+ plugins={{
455
+ tableAnalyticsPluginState: tableAnalyticsPluginKey,
456
+ tablePluginState: pluginKey,
457
+ tableWidthPluginState: tableWidthPluginKey,
458
+ tableResizingPluginState: tableResizingPluginKey,
459
+ stickyHeadersState: stickyHeadersPluginKey,
460
+ dragAndDropState: dragAndDropPluginKey,
461
+ }}
462
+ render={({
463
+ tableResizingPluginState: resizingPluginState,
464
+ stickyHeadersState,
465
+ tablePluginState,
466
+ tableWidthPluginState,
467
+ dragAndDropState,
468
+ }) => {
469
+ const isColumnResizing = resizingPluginState?.dragging;
470
+ const isTableResizing = tableWidthPluginState?.resizing;
471
+ const resizingTableLocalId = tableWidthPluginState?.tableLocalId;
472
+ const resizingTableRef = tableWidthPluginState?.tableRef;
473
+ const isResizing = isColumnResizing || isTableResizing;
474
+ const widthToWidest = tablePluginState?.widthToWidest;
475
+
476
+ const {
477
+ tableNode,
478
+ tablePos,
479
+ targetCellPosition,
480
+ isContextualMenuOpen,
481
+ tableRef,
482
+ pluginConfig,
483
+ insertColumnButtonIndex,
484
+ insertRowButtonIndex,
485
+ isHeaderColumnEnabled,
486
+ isHeaderRowEnabled,
487
+ isDragAndDropEnabled,
488
+ tableWrapperTarget,
489
+ } = tablePluginState!;
490
+
491
+ const { allowControls } = pluginConfig;
492
+
493
+ const stickyHeader = stickyHeadersState
494
+ ? findStickyHeaderForTable(stickyHeadersState, tablePos)
495
+ : undefined;
496
+
497
+ return (
498
+ <>
499
+ {targetCellPosition &&
500
+ tableRef &&
501
+ !isResizing &&
502
+ options &&
503
+ options.allowContextualMenu && (
504
+ <FloatingContextualButton
505
+ isNumberColumnEnabled={tableNode && tableNode.attrs.isNumberColumnEnabled}
506
+ editorView={editorView}
507
+ tableNode={tableNode}
508
+ mountPoint={popupsMountPoint}
509
+ targetCellPosition={targetCellPosition}
510
+ scrollableElement={popupsScrollableElement}
511
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
512
+ isContextualMenuOpen={isContextualMenuOpen}
513
+ stickyHeader={stickyHeader}
514
+ tableWrapper={tableWrapperTarget}
515
+ />
516
+ )}
517
+ {allowControls && (
518
+ <FloatingInsertButton
519
+ tableNode={tableNode}
520
+ tableRef={tableRef}
521
+ insertColumnButtonIndex={insertColumnButtonIndex}
522
+ insertRowButtonIndex={insertRowButtonIndex}
523
+ isHeaderColumnEnabled={isHeaderColumnEnabled}
524
+ isHeaderRowEnabled={isHeaderRowEnabled}
525
+ isDragAndDropEnabled={isDragAndDropEnabled}
526
+ editorView={editorView}
527
+ mountPoint={popupsMountPoint}
528
+ boundariesElement={popupsBoundariesElement}
529
+ scrollableElement={popupsScrollableElement}
530
+ hasStickyHeaders={stickyHeader && stickyHeader.sticky}
531
+ dispatchAnalyticsEvent={dispatchAnalyticsEvent}
532
+ editorAnalyticsAPI={editorAnalyticsAPI}
533
+ getEditorContainerWidth={defaultGetEditorContainerWidth}
534
+ getEditorFeatureFlags={
535
+ options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags
536
+ }
537
+ />
538
+ )}
539
+ {options?.allowContextualMenu && (
540
+ <FloatingContextualMenu
541
+ editorView={editorView}
542
+ mountPoint={popupsMountPoint}
543
+ boundariesElement={popupsBoundariesElement}
544
+ targetCellPosition={targetCellPosition}
545
+ isOpen={Boolean(isContextualMenuOpen) && !isResizing}
546
+ pluginConfig={pluginConfig}
547
+ editorAnalyticsAPI={editorAnalyticsAPI}
548
+ getEditorContainerWidth={defaultGetEditorContainerWidth}
549
+ getEditorFeatureFlags={
550
+ options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags
551
+ }
552
+ />
553
+ )}
554
+ {isDragAndDropEnabled && (
555
+ <FloatingDragMenu
556
+ editorView={editorView}
557
+ mountPoint={popupsMountPoint}
558
+ boundariesElement={popupsBoundariesElement}
559
+ tableRef={tableRef as HTMLTableElement}
560
+ tableNode={tableNode}
561
+ targetCellPosition={targetCellPosition}
562
+ direction={dragAndDropState?.dragMenuDirection}
563
+ index={dragAndDropState?.dragMenuIndex}
564
+ isOpen={!!dragAndDropState?.isDragMenuOpen && !isResizing}
565
+ getEditorContainerWidth={defaultGetEditorContainerWidth}
566
+ editorAnalyticsAPI={editorAnalyticsAPI}
567
+ stickyHeaders={stickyHeader}
568
+ pluginConfig={pluginConfig}
569
+ isTableScalingEnabled={options?.isTableScalingEnabled}
570
+ getEditorFeatureFlags={
571
+ options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags
572
+ }
573
+ />
574
+ )}
575
+ {allowControls && !isDragAndDropEnabled && !isResizing && (
576
+ <FloatingDeleteButton
577
+ editorView={editorView}
578
+ selection={editorView.state.selection}
579
+ tableRef={tableRef as HTMLTableElement}
580
+ mountPoint={popupsMountPoint}
581
+ boundariesElement={popupsBoundariesElement}
582
+ scrollableElement={popupsScrollableElement}
583
+ stickyHeaders={stickyHeader}
584
+ isNumberColumnEnabled={tableNode && tableNode.attrs.isNumberColumnEnabled}
585
+ editorAnalyticsAPI={editorAnalyticsAPI}
586
+ />
587
+ )}
588
+ {options?.isTableScalingEnabled &&
589
+ isTableResizing &&
590
+ widthToWidest &&
591
+ resizingTableLocalId &&
592
+ resizingTableRef &&
593
+ widthToWidest[resizingTableLocalId] && (
594
+ <FloatingToolbarLabel
595
+ target={resizingTableRef}
596
+ content={<FullWidthDisplay />}
597
+ alignX={'center'}
598
+ alignY={'bottom'}
599
+ stick={true}
600
+ forcePlacement={true}
601
+ zIndex={akEditorFloatingPanelZIndex}
602
+ offset={[0, 10]}
603
+ />
604
+ )}
605
+ </>
606
+ );
607
+ }}
608
+ />
609
+ </ErrorBoundary>
610
+ );
611
+ },
612
+
613
+ pluginsOptions: {
614
+ quickInsert: ({ formatMessage }) => [
615
+ {
616
+ id: 'table',
617
+ title: formatMessage(messages.table),
618
+ description: formatMessage(messages.tableDescription),
619
+ keywords: ['cell', 'table'],
620
+ priority: 600,
621
+ keyshortcut: tooltip(toggleTable),
622
+ icon: () => <IconTable />,
623
+ action(insert, state) {
624
+ // see comment on tablesPlugin.getSharedState on usage
625
+ const tableState = api?.table?.sharedState.currentState();
626
+
627
+ const tableNode = createTableWithWidth({
628
+ isTableScalingEnabled: options?.isTableScalingEnabled,
629
+ isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
630
+ isFullWidthModeEnabled: tableState?.isFullWidthModeEnabled,
631
+ })(state.schema);
632
+
633
+ const tr = insert(tableNode);
634
+
635
+ editorAnalyticsAPI?.attachAnalyticsEvent({
636
+ action: ACTION.INSERTED,
637
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
638
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
639
+ attributes: {
640
+ inputMethod: INPUT_METHOD.QUICK_INSERT,
641
+ localId: tableNode.attrs.localId,
642
+ },
643
+ eventType: EVENT_TYPE.TRACK,
644
+ })(tr);
645
+ return tr;
646
+ },
647
+ },
648
+ ],
649
+ floatingToolbar: getToolbarConfig(
650
+ defaultGetEditorContainerWidth,
651
+ editorAnalyticsAPI,
652
+ options?.getEditorFeatureFlags || defaultGetEditorFeatureFlags,
653
+ () => editorViewRef.current,
654
+ options,
655
+ )(pluginConfig(options?.tableOptions)),
656
+ },
657
+ };
683
658
  };
684
659
 
685
660
  export default tablesPlugin;