@atlaskit/editor-plugin-table 7.16.10 → 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 (244) hide show
  1. package/.eslintrc.js +3 -3
  2. package/CHANGELOG.md +1836 -1831
  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 +19 -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 +808 -814
  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 +19 -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 +5 -4
  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 +881 -903
  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
  243. package/tsconfig.app.json +107 -107
  244. package/tsconfig.dev.json +47 -47
package/src/toolbar.tsx CHANGED
@@ -4,37 +4,27 @@ import { jsx } from '@emotion/react';
4
4
  import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
5
5
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
6
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
- import {
8
- addColumnAfter,
9
- addRowAfter,
10
- backspace,
11
- tooltip,
12
- } from '@atlaskit/editor-common/keymaps';
13
- import commonMessages, {
14
- tableMessages as messages,
15
- } from '@atlaskit/editor-common/messages';
7
+ import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
8
+ import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
16
9
  import type { typeOption } from '@atlaskit/editor-common/src/types/floating-toolbar';
17
10
  import type {
18
- Command,
19
- CommandDispatch,
20
- ConfirmDialogOptions,
21
- DropdownOptions,
22
- DropdownOptionT,
23
- FloatingToolbarDropdown,
24
- FloatingToolbarHandler,
25
- FloatingToolbarItem,
26
- GetEditorContainerWidth,
27
- GetEditorFeatureFlags,
11
+ Command,
12
+ CommandDispatch,
13
+ ConfirmDialogOptions,
14
+ DropdownOptions,
15
+ DropdownOptionT,
16
+ FloatingToolbarDropdown,
17
+ FloatingToolbarHandler,
18
+ FloatingToolbarItem,
19
+ GetEditorContainerWidth,
20
+ GetEditorFeatureFlags,
28
21
  } from '@atlaskit/editor-common/types';
22
+ import { cellBackgroundColorPalette, DEFAULT_BORDER_COLOR } from '@atlaskit/editor-common/ui-color';
29
23
  import {
30
- cellBackgroundColorPalette,
31
- DEFAULT_BORDER_COLOR,
32
- } from '@atlaskit/editor-common/ui-color';
33
- import {
34
- closestElement,
35
- getChildrenInfo,
36
- getNodeName,
37
- isReferencedSource,
24
+ closestElement,
25
+ getChildrenInfo,
26
+ getNodeName,
27
+ isReferencedSource,
38
28
  } from '@atlaskit/editor-common/utils';
39
29
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
40
30
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
@@ -44,11 +34,11 @@ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
44
34
  import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
45
35
  import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
46
36
  import {
47
- findCellRectClosestToPos,
48
- findTable,
49
- getSelectionRect,
50
- isSelectionType,
51
- splitCell,
37
+ findCellRectClosestToPos,
38
+ findTable,
39
+ getSelectionRect,
40
+ isSelectionType,
41
+ splitCell,
52
42
  } from '@atlaskit/editor-tables/utils';
53
43
  import EditorAlignImageCenter from '@atlaskit/icon/glyph/editor/align-image-center';
54
44
  import EditorAlignImageLeft from '@atlaskit/icon/glyph/editor/align-image-left';
@@ -58,31 +48,31 @@ import TableOptionsIcon from '@atlaskit/icon/glyph/preferences';
58
48
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
59
49
 
60
50
  import {
61
- clearHoverSelection,
62
- hoverColumns,
63
- hoverMergedCells,
64
- hoverRows,
65
- hoverTable,
66
- removeDescendantNodes,
51
+ clearHoverSelection,
52
+ hoverColumns,
53
+ hoverMergedCells,
54
+ hoverRows,
55
+ hoverTable,
56
+ removeDescendantNodes,
67
57
  } from './commands';
68
58
  import {
69
- deleteColumnsWithAnalytics,
70
- deleteRowsWithAnalytics,
71
- deleteTableWithAnalytics,
72
- distributeColumnsWidthsWithAnalytics,
73
- emptyMultipleCellsWithAnalytics,
74
- insertColumnWithAnalytics,
75
- insertRowWithAnalytics,
76
- mergeCellsWithAnalytics,
77
- setColorWithAnalytics,
78
- setTableAlignmentWithAnalytics,
79
- sortColumnWithAnalytics,
80
- splitCellWithAnalytics,
81
- toggleHeaderColumnWithAnalytics,
82
- toggleHeaderRowWithAnalytics,
83
- toggleNumberColumnWithAnalytics,
84
- toggleTableLockWithAnalytics,
85
- wrapTableInExpandWithAnalytics,
59
+ deleteColumnsWithAnalytics,
60
+ deleteRowsWithAnalytics,
61
+ deleteTableWithAnalytics,
62
+ distributeColumnsWidthsWithAnalytics,
63
+ emptyMultipleCellsWithAnalytics,
64
+ insertColumnWithAnalytics,
65
+ insertRowWithAnalytics,
66
+ mergeCellsWithAnalytics,
67
+ setColorWithAnalytics,
68
+ setTableAlignmentWithAnalytics,
69
+ sortColumnWithAnalytics,
70
+ splitCellWithAnalytics,
71
+ toggleHeaderColumnWithAnalytics,
72
+ toggleHeaderRowWithAnalytics,
73
+ toggleNumberColumnWithAnalytics,
74
+ toggleTableLockWithAnalytics,
75
+ wrapTableInExpandWithAnalytics,
86
76
  } from './commands-with-analytics';
87
77
  import type { TablePluginOptions } from './plugin';
88
78
  import { getPluginState } from './pm-plugins/plugin-factory';
@@ -91,919 +81,839 @@ import { getNewResizeStateFromSelectedColumns } from './pm-plugins/table-resizin
91
81
  import { pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
92
82
  import { canMergeCells } from './transforms';
93
83
  import type {
94
- AlignmentOptions,
95
- PluginConfig,
96
- ToolbarMenuConfig,
97
- ToolbarMenuContext,
98
- ToolbarMenuState,
84
+ AlignmentOptions,
85
+ PluginConfig,
86
+ ToolbarMenuConfig,
87
+ ToolbarMenuContext,
88
+ ToolbarMenuState,
99
89
  } from './types';
100
90
  import { TableCssClassName } from './types';
101
91
  import { FloatingAlignmentButtons } from './ui/FloatingAlignmentButtons/FloatingAlignmentButtons';
102
92
  import { DisplayModeIcon } from './ui/icons';
103
93
  import {
104
- getMergedCellsPositions,
105
- getSelectedColumnIndexes,
106
- getSelectedRowIndexes,
107
- isTableNested,
94
+ getMergedCellsPositions,
95
+ getSelectedColumnIndexes,
96
+ getSelectedRowIndexes,
97
+ isTableNested,
108
98
  } from './utils';
109
99
  import { normaliseAlignment } from './utils/alignment';
110
100
 
111
101
  export const getToolbarMenuConfig = (
112
- config: ToolbarMenuConfig,
113
- state: ToolbarMenuState,
114
- { formatMessage }: ToolbarMenuContext,
115
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
102
+ config: ToolbarMenuConfig,
103
+ state: ToolbarMenuState,
104
+ { formatMessage }: ToolbarMenuContext,
105
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
116
106
  ): FloatingToolbarItem<Command> => {
117
- const optionItem: typeOption = getBooleanFF(
118
- 'platform.editor.a11y-table-floating-toolbar-dropdown-menu_zkb33',
119
- )
120
- ? 'item-checkbox'
121
- : 'item';
122
-
123
- const options = [
124
- {
125
- id: 'editor.table.headerRow',
126
- title: formatMessage(messages.headerRow),
127
- onClick: toggleHeaderRowWithAnalytics(editorAnalyticsAPI),
128
- selected: state.isHeaderRowEnabled,
129
- hidden: !config.allowHeaderRow,
130
- domItemOptions: { type: optionItem },
131
- },
132
- {
133
- id: 'editor.table.headerColumn',
134
- title: formatMessage(messages.headerColumn),
135
- onClick: toggleHeaderColumnWithAnalytics(editorAnalyticsAPI),
136
- selected: state.isHeaderColumnEnabled,
137
- hidden: !config.allowHeaderColumn,
138
- domItemOptions: { type: optionItem },
139
- },
140
- {
141
- id: 'editor.table.numberedColumn',
142
- title: formatMessage(messages.numberedColumn),
143
- onClick: toggleNumberColumnWithAnalytics(editorAnalyticsAPI),
144
- selected: state.isNumberColumnEnabled,
145
- hidden: !config.allowNumberColumn,
146
- domItemOptions: { type: optionItem },
147
- },
148
- {
149
- id: 'editor.table.collapseTable',
150
- title: formatMessage(messages.collapseTable),
151
- onClick: wrapTableInExpandWithAnalytics(editorAnalyticsAPI),
152
- selected: !!state.isTableCollapsed,
153
- disabled: !state.canCollapseTable,
154
- hidden: !config.allowCollapse,
155
- domItemOptions: { type: optionItem },
156
- },
157
- ];
158
-
159
- if (state.isDragAndDropEnabled) {
160
- return {
161
- id: 'editor.table.tableOptions',
162
- type: 'dropdown',
163
- testId: 'table_options',
164
- icon: TableOptionsIcon,
165
- title: formatMessage(messages.tableOptions),
166
- hidden: options.every((option) => option.hidden),
167
- options,
168
- };
169
- } else {
170
- return {
171
- id: 'editor.table.tableOptions',
172
- type: 'dropdown',
173
- testId: 'table_options',
174
- title: formatMessage(messages.tableOptions),
175
- hidden: options.every((option) => option.hidden),
176
- options,
177
- };
178
- }
107
+ const optionItem: typeOption = getBooleanFF(
108
+ 'platform.editor.a11y-table-floating-toolbar-dropdown-menu_zkb33',
109
+ )
110
+ ? 'item-checkbox'
111
+ : 'item';
112
+
113
+ const options = [
114
+ {
115
+ id: 'editor.table.headerRow',
116
+ title: formatMessage(messages.headerRow),
117
+ onClick: toggleHeaderRowWithAnalytics(editorAnalyticsAPI),
118
+ selected: state.isHeaderRowEnabled,
119
+ hidden: !config.allowHeaderRow,
120
+ domItemOptions: { type: optionItem },
121
+ },
122
+ {
123
+ id: 'editor.table.headerColumn',
124
+ title: formatMessage(messages.headerColumn),
125
+ onClick: toggleHeaderColumnWithAnalytics(editorAnalyticsAPI),
126
+ selected: state.isHeaderColumnEnabled,
127
+ hidden: !config.allowHeaderColumn,
128
+ domItemOptions: { type: optionItem },
129
+ },
130
+ {
131
+ id: 'editor.table.numberedColumn',
132
+ title: formatMessage(messages.numberedColumn),
133
+ onClick: toggleNumberColumnWithAnalytics(editorAnalyticsAPI),
134
+ selected: state.isNumberColumnEnabled,
135
+ hidden: !config.allowNumberColumn,
136
+ domItemOptions: { type: optionItem },
137
+ },
138
+ {
139
+ id: 'editor.table.collapseTable',
140
+ title: formatMessage(messages.collapseTable),
141
+ onClick: wrapTableInExpandWithAnalytics(editorAnalyticsAPI),
142
+ selected: !!state.isTableCollapsed,
143
+ disabled: !state.canCollapseTable,
144
+ hidden: !config.allowCollapse,
145
+ domItemOptions: { type: optionItem },
146
+ },
147
+ ];
148
+
149
+ if (state.isDragAndDropEnabled) {
150
+ return {
151
+ id: 'editor.table.tableOptions',
152
+ type: 'dropdown',
153
+ testId: 'table_options',
154
+ icon: TableOptionsIcon,
155
+ title: formatMessage(messages.tableOptions),
156
+ hidden: options.every((option) => option.hidden),
157
+ options,
158
+ };
159
+ } else {
160
+ return {
161
+ id: 'editor.table.tableOptions',
162
+ type: 'dropdown',
163
+ testId: 'table_options',
164
+ title: formatMessage(messages.tableOptions),
165
+ hidden: options.every((option) => option.hidden),
166
+ options,
167
+ };
168
+ }
179
169
  };
180
170
 
181
171
  // Added these options for mobile. Mobile bridge translates this menu and
182
172
  // relay it to the native mobile. Native mobile displays the menu
183
173
  // with native widgets. It's enabled via a plugin config.
184
174
  export const getToolbarCellOptionsConfig = (
185
- editorState: EditorState,
186
- editorView: EditorView | undefined | null,
187
- initialSelectionRect: Rect,
188
- { formatMessage }: ToolbarMenuContext,
189
- getEditorContainerWidth: GetEditorContainerWidth,
190
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
191
- isTableScalingEnabled = false,
175
+ editorState: EditorState,
176
+ editorView: EditorView | undefined | null,
177
+ initialSelectionRect: Rect,
178
+ { formatMessage }: ToolbarMenuContext,
179
+ getEditorContainerWidth: GetEditorContainerWidth,
180
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
181
+ isTableScalingEnabled = false,
192
182
  ): FloatingToolbarDropdown<Command> => {
193
- const { top, bottom, right, left } = initialSelectionRect;
194
- const numberOfColumns = right - left;
195
- const numberOfRows = bottom - top;
196
- const pluginState = getPluginState(editorState);
197
-
198
- const options: DropdownOptionT<Command>[] = [
199
- {
200
- id: 'editor.table.insertColumn',
201
- title: formatMessage(messages.insertColumn),
202
- onClick: (
203
- state: EditorState,
204
- dispatch?: CommandDispatch,
205
- view?: EditorView,
206
- ) => {
207
- const selectionRect = getClosestSelectionRect(state);
208
- const index = selectionRect?.right;
209
- if (index) {
210
- insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(
211
- INPUT_METHOD.FLOATING_TB,
212
- index,
213
- )(state, dispatch, view);
214
- }
215
- return true;
216
- },
217
- selected: false,
218
- disabled: false,
219
- elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
220
- },
221
- {
222
- id: 'editor.table.insertRow',
223
- title: formatMessage(messages.insertRow),
224
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
225
- const selectionRect = getClosestSelectionRect(state);
226
- const index = selectionRect?.bottom;
227
- if (index) {
228
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, {
229
- index,
230
- moveCursorToInsertedRow: true,
231
- })(state, dispatch);
232
- }
233
- return true;
234
- },
235
- selected: false,
236
- disabled: false,
237
- elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
238
- },
239
- {
240
- id: 'editor.table.removeColumns',
241
- title: formatMessage(messages.removeColumns, {
242
- 0: numberOfColumns,
243
- }),
244
- onClick: (
245
- state: EditorState,
246
- dispatch?: CommandDispatch,
247
- view?: EditorView,
248
- ) => {
249
- const selectionRect = getClosestSelectionRect(state);
250
- if (selectionRect) {
251
- deleteColumnsWithAnalytics(editorAnalyticsAPI)(
252
- INPUT_METHOD.FLOATING_TB,
253
- selectionRect,
254
- )(state, dispatch, view);
255
- }
256
- return true;
257
- },
258
- onFocus: highlightColumnsHandler,
259
- onBlur: clearHoverSelection(),
260
- onMouseOver: highlightColumnsHandler,
261
- onMouseLeave: clearHoverSelection(),
262
- selected: false,
263
- disabled: false,
264
- },
265
- {
266
- id: 'editor.table.removeRows',
267
- title: formatMessage(messages.removeRows, {
268
- 0: numberOfRows,
269
- }),
270
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
271
- const selectionRect = getClosestSelectionRect(state);
272
- if (selectionRect) {
273
- deleteRowsWithAnalytics(editorAnalyticsAPI)(
274
- INPUT_METHOD.FLOATING_TB,
275
- selectionRect,
276
- false,
277
- )(state, dispatch);
278
- }
279
- return true;
280
- },
281
- onFocus: highlightRowsHandler,
282
- onBlur: clearHoverSelection(),
283
- onMouseOver: highlightRowsHandler,
284
- onMouseLeave: clearHoverSelection(),
285
- selected: false,
286
- disabled: false,
287
- },
288
- {
289
- id: 'editor.table.mergeCells',
290
- title: formatMessage(messages.mergeCells),
291
- onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(
292
- INPUT_METHOD.FLOATING_TB,
293
- ),
294
- selected: false,
295
- disabled: !canMergeCells(editorState.tr),
296
- },
297
- {
298
- id: 'editor.table.splitCell',
299
- title: formatMessage(messages.splitCell),
300
- onClick: splitCellWithAnalytics(editorAnalyticsAPI)(
301
- INPUT_METHOD.FLOATING_TB,
302
- ),
303
- selected: false,
304
- disabled: !splitCell(editorState),
305
- },
306
- ];
307
-
308
- if (pluginState?.pluginConfig?.allowDistributeColumns) {
309
- const newResizeStateWithAnalytics = editorView
310
- ? getNewResizeStateFromSelectedColumns(
311
- initialSelectionRect,
312
- editorState,
313
- editorView.domAtPos.bind(editorView),
314
- getEditorContainerWidth,
315
- isTableScalingEnabled,
316
- )
317
- : undefined;
318
- const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
319
-
320
- const distributeColumnWidths: Command = (state, dispatch) => {
321
- if (newResizeStateWithAnalytics) {
322
- distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
323
- INPUT_METHOD.FLOATING_TB,
324
- newResizeStateWithAnalytics,
325
- )(state, dispatch);
326
- return true;
327
- }
328
- return false;
329
- };
330
-
331
- options.push({
332
- id: 'editor.table.distributeColumns',
333
- title: formatMessage(messages.distributeColumns),
334
- onClick: distributeColumnWidths,
335
- selected: false,
336
- disabled: !wouldChange,
337
- });
338
- }
339
-
340
- if (pluginState?.pluginConfig?.allowColumnSorting) {
341
- const hasMergedCellsInTable =
342
- getMergedCellsPositions(editorState.tr).length > 0;
343
- const warning = hasMergedCellsInTable
344
- ? formatMessage(messages.canNotSortTable)
345
- : undefined;
346
-
347
- options.push({
348
- id: 'editor.table.sortColumnAsc',
349
- title: formatMessage(messages.sortColumnASC),
350
- onMouseOver: (state: EditorState, dispatch?: CommandDispatch) => {
351
- if (getMergedCellsPositions(state.tr).length !== 0) {
352
- hoverMergedCells()(state, dispatch);
353
- return true;
354
- }
355
- return false;
356
- },
357
- onMouseOut: (state: EditorState, dispatch?: CommandDispatch) => {
358
- clearHoverSelection()(state, dispatch);
359
- return true;
360
- },
361
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
362
- sortColumnWithAnalytics(editorAnalyticsAPI)(
363
- INPUT_METHOD.FLOATING_TB,
364
- initialSelectionRect.left,
365
- SortOrder.ASC,
366
- )(state, dispatch);
367
- return true;
368
- },
369
- selected: false,
370
- disabled: hasMergedCellsInTable,
371
- tooltip: warning,
372
- });
373
-
374
- options.push({
375
- id: 'editor.table.sortColumnDesc',
376
- title: formatMessage(messages.sortColumnDESC),
377
- onMouseOver: (state: EditorState, dispatch?: CommandDispatch) => {
378
- if (getMergedCellsPositions(state.tr).length !== 0) {
379
- hoverMergedCells()(state, dispatch);
380
- return true;
381
- }
382
- return false;
383
- },
384
- onMouseOut: (state: EditorState, dispatch?: CommandDispatch) => {
385
- clearHoverSelection()(state, dispatch);
386
- return true;
387
- },
388
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
389
- sortColumnWithAnalytics(editorAnalyticsAPI)(
390
- INPUT_METHOD.FLOATING_TB,
391
- initialSelectionRect.left,
392
- SortOrder.DESC,
393
- )(state, dispatch);
394
- return true;
395
- },
396
- selected: false,
397
- disabled: hasMergedCellsInTable,
398
- tooltip: warning,
399
- });
400
- }
401
-
402
- options.push({
403
- id: 'editor.table.clearCells',
404
- title: formatMessage(messages.clearCells, {
405
- 0: Math.max(numberOfColumns, numberOfRows),
406
- }),
407
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
408
- const { targetCellPosition } = getPluginState(state);
409
- emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(
410
- INPUT_METHOD.FLOATING_TB,
411
- targetCellPosition,
412
- )(state, dispatch);
413
- return true;
414
- },
415
- selected: false,
416
- disabled: false,
417
- elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
418
- });
419
-
420
- return {
421
- id: 'editor.table.cellOptions',
422
- testId: 'cell_options',
423
- type: 'dropdown',
424
- title: formatMessage(messages.cellOptions),
425
- options,
426
- // Increased dropdown item width to prevent labels from being truncated
427
- dropdownWidth: 230,
428
- showSelected: false,
429
- };
183
+ const { top, bottom, right, left } = initialSelectionRect;
184
+ const numberOfColumns = right - left;
185
+ const numberOfRows = bottom - top;
186
+ const pluginState = getPluginState(editorState);
187
+
188
+ const options: DropdownOptionT<Command>[] = [
189
+ {
190
+ id: 'editor.table.insertColumn',
191
+ title: formatMessage(messages.insertColumn),
192
+ onClick: (state: EditorState, dispatch?: CommandDispatch, view?: EditorView) => {
193
+ const selectionRect = getClosestSelectionRect(state);
194
+ const index = selectionRect?.right;
195
+ if (index) {
196
+ insertColumnWithAnalytics(editorAnalyticsAPI, isTableScalingEnabled)(
197
+ INPUT_METHOD.FLOATING_TB,
198
+ index,
199
+ )(state, dispatch, view);
200
+ }
201
+ return true;
202
+ },
203
+ selected: false,
204
+ disabled: false,
205
+ elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
206
+ },
207
+ {
208
+ id: 'editor.table.insertRow',
209
+ title: formatMessage(messages.insertRow),
210
+ onClick: (state: EditorState, dispatch?: CommandDispatch) => {
211
+ const selectionRect = getClosestSelectionRect(state);
212
+ const index = selectionRect?.bottom;
213
+ if (index) {
214
+ insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, {
215
+ index,
216
+ moveCursorToInsertedRow: true,
217
+ })(state, dispatch);
218
+ }
219
+ return true;
220
+ },
221
+ selected: false,
222
+ disabled: false,
223
+ elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
224
+ },
225
+ {
226
+ id: 'editor.table.removeColumns',
227
+ title: formatMessage(messages.removeColumns, {
228
+ 0: numberOfColumns,
229
+ }),
230
+ onClick: (state: EditorState, dispatch?: CommandDispatch, view?: EditorView) => {
231
+ const selectionRect = getClosestSelectionRect(state);
232
+ if (selectionRect) {
233
+ deleteColumnsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, selectionRect)(
234
+ state,
235
+ dispatch,
236
+ view,
237
+ );
238
+ }
239
+ return true;
240
+ },
241
+ onFocus: highlightColumnsHandler,
242
+ onBlur: clearHoverSelection(),
243
+ onMouseOver: highlightColumnsHandler,
244
+ onMouseLeave: clearHoverSelection(),
245
+ selected: false,
246
+ disabled: false,
247
+ },
248
+ {
249
+ id: 'editor.table.removeRows',
250
+ title: formatMessage(messages.removeRows, {
251
+ 0: numberOfRows,
252
+ }),
253
+ onClick: (state: EditorState, dispatch?: CommandDispatch) => {
254
+ const selectionRect = getClosestSelectionRect(state);
255
+ if (selectionRect) {
256
+ deleteRowsWithAnalytics(editorAnalyticsAPI)(
257
+ INPUT_METHOD.FLOATING_TB,
258
+ selectionRect,
259
+ false,
260
+ )(state, dispatch);
261
+ }
262
+ return true;
263
+ },
264
+ onFocus: highlightRowsHandler,
265
+ onBlur: clearHoverSelection(),
266
+ onMouseOver: highlightRowsHandler,
267
+ onMouseLeave: clearHoverSelection(),
268
+ selected: false,
269
+ disabled: false,
270
+ },
271
+ {
272
+ id: 'editor.table.mergeCells',
273
+ title: formatMessage(messages.mergeCells),
274
+ onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
275
+ selected: false,
276
+ disabled: !canMergeCells(editorState.tr),
277
+ },
278
+ {
279
+ id: 'editor.table.splitCell',
280
+ title: formatMessage(messages.splitCell),
281
+ onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
282
+ selected: false,
283
+ disabled: !splitCell(editorState),
284
+ },
285
+ ];
286
+
287
+ if (pluginState?.pluginConfig?.allowDistributeColumns) {
288
+ const newResizeStateWithAnalytics = editorView
289
+ ? getNewResizeStateFromSelectedColumns(
290
+ initialSelectionRect,
291
+ editorState,
292
+ editorView.domAtPos.bind(editorView),
293
+ getEditorContainerWidth,
294
+ isTableScalingEnabled,
295
+ )
296
+ : undefined;
297
+ const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
298
+
299
+ const distributeColumnWidths: Command = (state, dispatch) => {
300
+ if (newResizeStateWithAnalytics) {
301
+ distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
302
+ INPUT_METHOD.FLOATING_TB,
303
+ newResizeStateWithAnalytics,
304
+ )(state, dispatch);
305
+ return true;
306
+ }
307
+ return false;
308
+ };
309
+
310
+ options.push({
311
+ id: 'editor.table.distributeColumns',
312
+ title: formatMessage(messages.distributeColumns),
313
+ onClick: distributeColumnWidths,
314
+ selected: false,
315
+ disabled: !wouldChange,
316
+ });
317
+ }
318
+
319
+ if (pluginState?.pluginConfig?.allowColumnSorting) {
320
+ const hasMergedCellsInTable = getMergedCellsPositions(editorState.tr).length > 0;
321
+ const warning = hasMergedCellsInTable ? formatMessage(messages.canNotSortTable) : undefined;
322
+
323
+ options.push({
324
+ id: 'editor.table.sortColumnAsc',
325
+ title: formatMessage(messages.sortColumnASC),
326
+ onMouseOver: (state: EditorState, dispatch?: CommandDispatch) => {
327
+ if (getMergedCellsPositions(state.tr).length !== 0) {
328
+ hoverMergedCells()(state, dispatch);
329
+ return true;
330
+ }
331
+ return false;
332
+ },
333
+ onMouseOut: (state: EditorState, dispatch?: CommandDispatch) => {
334
+ clearHoverSelection()(state, dispatch);
335
+ return true;
336
+ },
337
+ onClick: (state: EditorState, dispatch?: CommandDispatch) => {
338
+ sortColumnWithAnalytics(editorAnalyticsAPI)(
339
+ INPUT_METHOD.FLOATING_TB,
340
+ initialSelectionRect.left,
341
+ SortOrder.ASC,
342
+ )(state, dispatch);
343
+ return true;
344
+ },
345
+ selected: false,
346
+ disabled: hasMergedCellsInTable,
347
+ tooltip: warning,
348
+ });
349
+
350
+ options.push({
351
+ id: 'editor.table.sortColumnDesc',
352
+ title: formatMessage(messages.sortColumnDESC),
353
+ onMouseOver: (state: EditorState, dispatch?: CommandDispatch) => {
354
+ if (getMergedCellsPositions(state.tr).length !== 0) {
355
+ hoverMergedCells()(state, dispatch);
356
+ return true;
357
+ }
358
+ return false;
359
+ },
360
+ onMouseOut: (state: EditorState, dispatch?: CommandDispatch) => {
361
+ clearHoverSelection()(state, dispatch);
362
+ return true;
363
+ },
364
+ onClick: (state: EditorState, dispatch?: CommandDispatch) => {
365
+ sortColumnWithAnalytics(editorAnalyticsAPI)(
366
+ INPUT_METHOD.FLOATING_TB,
367
+ initialSelectionRect.left,
368
+ SortOrder.DESC,
369
+ )(state, dispatch);
370
+ return true;
371
+ },
372
+ selected: false,
373
+ disabled: hasMergedCellsInTable,
374
+ tooltip: warning,
375
+ });
376
+ }
377
+
378
+ options.push({
379
+ id: 'editor.table.clearCells',
380
+ title: formatMessage(messages.clearCells, {
381
+ 0: Math.max(numberOfColumns, numberOfRows),
382
+ }),
383
+ onClick: (state: EditorState, dispatch?: CommandDispatch) => {
384
+ const { targetCellPosition } = getPluginState(state);
385
+ emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(
386
+ INPUT_METHOD.FLOATING_TB,
387
+ targetCellPosition,
388
+ )(state, dispatch);
389
+ return true;
390
+ },
391
+ selected: false,
392
+ disabled: false,
393
+ elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
394
+ });
395
+
396
+ return {
397
+ id: 'editor.table.cellOptions',
398
+ testId: 'cell_options',
399
+ type: 'dropdown',
400
+ title: formatMessage(messages.cellOptions),
401
+ options,
402
+ // Increased dropdown item width to prevent labels from being truncated
403
+ dropdownWidth: 230,
404
+ showSelected: false,
405
+ };
430
406
  };
431
407
 
432
- export const getClosestSelectionRect = (
433
- state: EditorState,
434
- ): Rect | undefined => {
435
- const selection = state.selection;
436
- return isSelectionType(selection, 'cell')
437
- ? getSelectionRect(selection)!
438
- : findCellRectClosestToPos(selection.$from);
408
+ export const getClosestSelectionRect = (state: EditorState): Rect | undefined => {
409
+ const selection = state.selection;
410
+ return isSelectionType(selection, 'cell')
411
+ ? getSelectionRect(selection)!
412
+ : findCellRectClosestToPos(selection.$from);
439
413
  };
440
414
 
441
- export const getClosestSelectionOrTableRect = (
442
- state: EditorState,
443
- ): Rect | undefined => {
444
- const selection = state.selection;
445
- const tableObject = findTable(state.selection);
446
- if (!tableObject) {
447
- return;
448
- }
449
- const map = TableMap.get(tableObject.node);
450
- const tableRect = new Rect(0, 0, map.width, map.height);
451
-
452
- return isSelectionType(selection, 'cell')
453
- ? getSelectionRect(selection)!
454
- : tableRect;
415
+ export const getClosestSelectionOrTableRect = (state: EditorState): Rect | undefined => {
416
+ const selection = state.selection;
417
+ const tableObject = findTable(state.selection);
418
+ if (!tableObject) {
419
+ return;
420
+ }
421
+ const map = TableMap.get(tableObject.node);
422
+ const tableRect = new Rect(0, 0, map.width, map.height);
423
+
424
+ return isSelectionType(selection, 'cell') ? getSelectionRect(selection)! : tableRect;
455
425
  };
456
426
 
457
427
  export const getToolbarConfig =
458
- (
459
- getEditorContainerWidth: GetEditorContainerWidth,
460
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
461
- getEditorFeatureFlags: GetEditorFeatureFlags,
462
- getEditorView: () => EditorView | null,
463
- options?: TablePluginOptions,
464
- ) =>
465
- (config: PluginConfig): FloatingToolbarHandler =>
466
- (state, intl) => {
467
- const tableObject = findTable(state.selection);
468
- const pluginState = getPluginState(state);
469
- const resizeState = tableResizingPluginKey.getState(state);
470
- const tableWidthState = tableWidthPluginKey.getState(state);
471
-
472
- // We don't want to show floating toolbar while resizing the table
473
- const isWidthResizing = tableWidthState?.resizing;
474
-
475
- if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
476
- const nodeType = state.schema.nodes.table;
477
- const menu = getToolbarMenuConfig(
478
- config,
479
- pluginState,
480
- intl,
481
- editorAnalyticsAPI,
482
- );
483
-
484
- let alignmentMenu: Array<FloatingToolbarItem<Command>>;
485
- const isNested =
486
- pluginState.tablePos && isTableNested(state, pluginState.tablePos);
487
-
488
- alignmentMenu =
489
- options?.isTableAlignmentEnabled && !isNested
490
- ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI, getEditorContainerWidth)
491
- : [];
492
-
493
- let cellItems: Array<FloatingToolbarItem<Command>>;
494
- cellItems = pluginState.isDragAndDropEnabled
495
- ? []
496
- : getCellItems(
497
- state,
498
- getEditorView(),
499
- intl,
500
- getEditorContainerWidth,
501
- editorAnalyticsAPI,
502
- options?.isTableScalingEnabled,
503
- );
504
-
505
- let columnSettingsItems;
506
- columnSettingsItems = pluginState.isDragAndDropEnabled
507
- ? getColumnSettingItems(
508
- state,
509
- getEditorView(),
510
- intl,
511
- getEditorContainerWidth,
512
- editorAnalyticsAPI,
513
- options?.isTableScalingEnabled,
514
- )
515
- : [];
516
- const colorPicker = getColorPicker(
517
- state,
518
- menu,
519
- intl,
520
- editorAnalyticsAPI,
521
- getEditorView,
522
- );
523
-
524
- // Check if we need to show confirm dialog for delete button
525
- let confirmDialog;
526
-
527
- if (isReferencedSource(state, tableObject.node)) {
528
- const localSourceName = intl.formatMessage(messages.unnamedSource);
529
-
530
- confirmDialog = (): ConfirmDialogOptions => ({
531
- title: intl.formatMessage(messages.deleteElementTitle),
532
- okButtonLabel: intl.formatMessage(
533
- messages.confirmDeleteLinkedModalOKButton,
534
- ),
535
- message: intl.formatMessage(
536
- messages.confirmDeleteLinkedModalMessage,
537
- {
538
- nodeName: getNodeName(state, tableObject.node) || localSourceName,
539
- },
540
- ),
541
- messagePrefix: intl.formatMessage(
542
- messages.confirmDeleteLinkedModalMessagePrefix,
543
- ),
544
- isReferentialityDialog: true,
545
- getChildrenInfo: () => getChildrenInfo(state, tableObject.node),
546
- checkboxLabel: intl.formatMessage(messages.confirmModalCheckboxLabel),
547
- onConfirm: (isChecked = false) =>
548
- clickWithCheckboxHandler(isChecked, tableObject.node),
549
- });
550
- }
551
-
552
- const getDomRef = (editorView: EditorView) => {
553
- let element: HTMLElement | undefined;
554
- const domAtPos = editorView.domAtPos.bind(editorView);
555
- const parent = findParentDomRefOfType(
556
- nodeType,
557
- domAtPos,
558
- )(state.selection);
559
- if (parent) {
560
- const tableRef =
561
- (parent as HTMLElement).querySelector<HTMLTableElement>('table') ||
562
- undefined;
563
- if (tableRef) {
564
- element =
565
- closestElement(
566
- tableRef,
567
- `.${TableCssClassName.TABLE_NODE_WRAPPER}`,
568
- ) || undefined;
569
- }
570
- }
571
-
572
- return element;
573
- };
574
-
575
- const { stickyScrollbar } = getEditorFeatureFlags();
576
-
577
- return {
578
- title: 'Table floating controls',
579
- getDomRef,
580
- nodeType,
581
- offset: [0, 18],
582
- absoluteOffset: stickyScrollbar ? { top: -6 } : { top: 0 },
583
- zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
584
- items: [
585
- menu,
586
- separator(menu.hidden),
587
- ...alignmentMenu,
588
- separator(alignmentMenu.length === 0),
589
- ...cellItems,
590
- ...columnSettingsItems,
591
- ...colorPicker,
592
- {
593
- type: 'extensions-placeholder',
594
- separator: 'end',
595
- },
596
- {
597
- type: 'copy-button',
598
- supportsViewMode: true,
599
- items: [
600
- {
601
- state,
602
- formatMessage: intl.formatMessage,
603
- nodeType,
604
- onMouseEnter: hoverTable(false, true),
605
- onMouseLeave: clearHoverSelection(),
606
- onFocus: hoverTable(false, true),
607
- onBlur: clearHoverSelection(),
608
- },
609
- ],
610
- },
611
- { type: 'separator' },
612
- {
613
- id: 'editor.table.delete',
614
- type: 'button',
615
- appearance: 'danger',
616
- icon: RemoveIcon,
617
- onClick: deleteTableWithAnalytics(editorAnalyticsAPI),
618
- disabled: !!resizeState && !!resizeState.dragging,
619
- onMouseEnter: hoverTable(true),
620
- onFocus: hoverTable(true),
621
- onBlur: clearHoverSelection(),
622
- onMouseLeave: clearHoverSelection(),
623
- title: intl.formatMessage(commonMessages.remove),
624
- focusEditoronEnter: true,
625
- confirmDialog,
626
- },
627
- ],
628
- scrollable: true,
629
- };
630
- }
631
- return;
632
- };
428
+ (
429
+ getEditorContainerWidth: GetEditorContainerWidth,
430
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
431
+ getEditorFeatureFlags: GetEditorFeatureFlags,
432
+ getEditorView: () => EditorView | null,
433
+ options?: TablePluginOptions,
434
+ ) =>
435
+ (config: PluginConfig): FloatingToolbarHandler =>
436
+ (state, intl) => {
437
+ const tableObject = findTable(state.selection);
438
+ const pluginState = getPluginState(state);
439
+ const resizeState = tableResizingPluginKey.getState(state);
440
+ const tableWidthState = tableWidthPluginKey.getState(state);
441
+
442
+ // We don't want to show floating toolbar while resizing the table
443
+ const isWidthResizing = tableWidthState?.resizing;
444
+
445
+ if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
446
+ const nodeType = state.schema.nodes.table;
447
+ const menu = getToolbarMenuConfig(config, pluginState, intl, editorAnalyticsAPI);
448
+
449
+ let alignmentMenu: Array<FloatingToolbarItem<Command>>;
450
+ const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
451
+
452
+ alignmentMenu =
453
+ options?.isTableAlignmentEnabled && !isNested
454
+ ? getAlignmentOptionsConfig(state, intl, editorAnalyticsAPI, getEditorContainerWidth)
455
+ : [];
456
+
457
+ let cellItems: Array<FloatingToolbarItem<Command>>;
458
+ cellItems = pluginState.isDragAndDropEnabled
459
+ ? []
460
+ : getCellItems(
461
+ state,
462
+ getEditorView(),
463
+ intl,
464
+ getEditorContainerWidth,
465
+ editorAnalyticsAPI,
466
+ options?.isTableScalingEnabled,
467
+ );
468
+
469
+ let columnSettingsItems;
470
+ columnSettingsItems = pluginState.isDragAndDropEnabled
471
+ ? getColumnSettingItems(
472
+ state,
473
+ getEditorView(),
474
+ intl,
475
+ getEditorContainerWidth,
476
+ editorAnalyticsAPI,
477
+ options?.isTableScalingEnabled,
478
+ )
479
+ : [];
480
+ const colorPicker = getColorPicker(state, menu, intl, editorAnalyticsAPI, getEditorView);
481
+
482
+ // Check if we need to show confirm dialog for delete button
483
+ let confirmDialog;
484
+
485
+ if (isReferencedSource(state, tableObject.node)) {
486
+ const localSourceName = intl.formatMessage(messages.unnamedSource);
487
+
488
+ confirmDialog = (): ConfirmDialogOptions => ({
489
+ title: intl.formatMessage(messages.deleteElementTitle),
490
+ okButtonLabel: intl.formatMessage(messages.confirmDeleteLinkedModalOKButton),
491
+ message: intl.formatMessage(messages.confirmDeleteLinkedModalMessage, {
492
+ nodeName: getNodeName(state, tableObject.node) || localSourceName,
493
+ }),
494
+ messagePrefix: intl.formatMessage(messages.confirmDeleteLinkedModalMessagePrefix),
495
+ isReferentialityDialog: true,
496
+ getChildrenInfo: () => getChildrenInfo(state, tableObject.node),
497
+ checkboxLabel: intl.formatMessage(messages.confirmModalCheckboxLabel),
498
+ onConfirm: (isChecked = false) => clickWithCheckboxHandler(isChecked, tableObject.node),
499
+ });
500
+ }
501
+
502
+ const getDomRef = (editorView: EditorView) => {
503
+ let element: HTMLElement | undefined;
504
+ const domAtPos = editorView.domAtPos.bind(editorView);
505
+ const parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
506
+ if (parent) {
507
+ const tableRef =
508
+ (parent as HTMLElement).querySelector<HTMLTableElement>('table') || undefined;
509
+ if (tableRef) {
510
+ element =
511
+ closestElement(tableRef, `.${TableCssClassName.TABLE_NODE_WRAPPER}`) || undefined;
512
+ }
513
+ }
514
+
515
+ return element;
516
+ };
517
+
518
+ const { stickyScrollbar } = getEditorFeatureFlags();
519
+
520
+ return {
521
+ title: 'Table floating controls',
522
+ getDomRef,
523
+ nodeType,
524
+ offset: [0, 18],
525
+ absoluteOffset: stickyScrollbar ? { top: -6 } : { top: 0 },
526
+ zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
527
+ items: [
528
+ menu,
529
+ separator(menu.hidden),
530
+ ...alignmentMenu,
531
+ separator(alignmentMenu.length === 0),
532
+ ...cellItems,
533
+ ...columnSettingsItems,
534
+ ...colorPicker,
535
+ {
536
+ type: 'extensions-placeholder',
537
+ separator: 'end',
538
+ },
539
+ {
540
+ type: 'copy-button',
541
+ supportsViewMode: true,
542
+ items: [
543
+ {
544
+ state,
545
+ formatMessage: intl.formatMessage,
546
+ nodeType,
547
+ onMouseEnter: hoverTable(false, true),
548
+ onMouseLeave: clearHoverSelection(),
549
+ onFocus: hoverTable(false, true),
550
+ onBlur: clearHoverSelection(),
551
+ },
552
+ ],
553
+ },
554
+ { type: 'separator' },
555
+ {
556
+ id: 'editor.table.delete',
557
+ type: 'button',
558
+ appearance: 'danger',
559
+ icon: RemoveIcon,
560
+ onClick: deleteTableWithAnalytics(editorAnalyticsAPI),
561
+ disabled: !!resizeState && !!resizeState.dragging,
562
+ onMouseEnter: hoverTable(true),
563
+ onFocus: hoverTable(true),
564
+ onBlur: clearHoverSelection(),
565
+ onMouseLeave: clearHoverSelection(),
566
+ title: intl.formatMessage(commonMessages.remove),
567
+ focusEditoronEnter: true,
568
+ confirmDialog,
569
+ },
570
+ ],
571
+ scrollable: true,
572
+ };
573
+ }
574
+ return;
575
+ };
633
576
 
634
577
  const separator = (hidden?: boolean): FloatingToolbarItem<Command> => {
635
- return {
636
- type: 'separator',
637
- hidden: hidden,
638
- };
578
+ return {
579
+ type: 'separator',
580
+ hidden: hidden,
581
+ };
639
582
  };
640
583
 
641
584
  const getCellItems = (
642
- state: EditorState,
643
- view: EditorView | null,
644
- { formatMessage }: ToolbarMenuContext,
645
- getEditorContainerWidth: GetEditorContainerWidth,
646
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
647
- isTableScalingEnabled = false,
585
+ state: EditorState,
586
+ view: EditorView | null,
587
+ { formatMessage }: ToolbarMenuContext,
588
+ getEditorContainerWidth: GetEditorContainerWidth,
589
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
590
+ isTableScalingEnabled = false,
648
591
  ): Array<FloatingToolbarItem<Command>> => {
649
- const initialSelectionRect = getClosestSelectionRect(state);
650
- if (initialSelectionRect) {
651
- const cellOptions = getToolbarCellOptionsConfig(
652
- state,
653
- view,
654
- initialSelectionRect,
655
- { formatMessage },
656
- getEditorContainerWidth,
657
- editorAnalyticsAPI,
658
- isTableScalingEnabled,
659
- );
660
- return [cellOptions, separator(cellOptions.hidden!)];
661
- }
662
- return [];
592
+ const initialSelectionRect = getClosestSelectionRect(state);
593
+ if (initialSelectionRect) {
594
+ const cellOptions = getToolbarCellOptionsConfig(
595
+ state,
596
+ view,
597
+ initialSelectionRect,
598
+ { formatMessage },
599
+ getEditorContainerWidth,
600
+ editorAnalyticsAPI,
601
+ isTableScalingEnabled,
602
+ );
603
+ return [cellOptions, separator(cellOptions.hidden!)];
604
+ }
605
+ return [];
663
606
  };
664
607
 
665
608
  export const getLockBtnConfig =
666
- (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null): Command =>
667
- (state, dispatch, editorView) => {
668
- const selectionOrTableRect = getClosestSelectionOrTableRect(state);
669
- if (!editorView || !selectionOrTableRect) {
670
- return false;
671
- }
672
-
673
- const { tr } = state;
674
- const table = findTable(tr.selection);
675
-
676
- if (!table) {
677
- return false;
678
- } else {
679
- const { displayMode } = table.node.attrs;
680
- toggleTableLockWithAnalytics(editorAnalyticsAPI)(
681
- displayMode,
682
- INPUT_METHOD.FLOATING_TB,
683
- )(state, dispatch);
684
- return true;
685
- }
686
- };
609
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null): Command =>
610
+ (state, dispatch, editorView) => {
611
+ const selectionOrTableRect = getClosestSelectionOrTableRect(state);
612
+ if (!editorView || !selectionOrTableRect) {
613
+ return false;
614
+ }
615
+
616
+ const { tr } = state;
617
+ const table = findTable(tr.selection);
618
+
619
+ if (!table) {
620
+ return false;
621
+ } else {
622
+ const { displayMode } = table.node.attrs;
623
+ toggleTableLockWithAnalytics(editorAnalyticsAPI)(displayMode, INPUT_METHOD.FLOATING_TB)(
624
+ state,
625
+ dispatch,
626
+ );
627
+ return true;
628
+ }
629
+ };
687
630
 
688
631
  export const getDistributeConfig =
689
- (
690
- getEditorContainerWidth: GetEditorContainerWidth,
691
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
692
- isTableScalingEnabled = false,
693
- ): Command =>
694
- (state, dispatch, editorView) => {
695
- const selectionOrTableRect = getClosestSelectionOrTableRect(state);
696
- if (!editorView || !selectionOrTableRect) {
697
- return false;
698
- }
699
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
700
- selectionOrTableRect,
701
- state,
702
- editorView.domAtPos.bind(editorView),
703
- getEditorContainerWidth,
704
- isTableScalingEnabled,
705
- );
706
-
707
- if (newResizeStateWithAnalytics) {
708
- distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
709
- INPUT_METHOD.FLOATING_TB,
710
- newResizeStateWithAnalytics,
711
- )(state, dispatch);
712
- return true;
713
- }
714
- return false;
715
- };
632
+ (
633
+ getEditorContainerWidth: GetEditorContainerWidth,
634
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
635
+ isTableScalingEnabled = false,
636
+ ): Command =>
637
+ (state, dispatch, editorView) => {
638
+ const selectionOrTableRect = getClosestSelectionOrTableRect(state);
639
+ if (!editorView || !selectionOrTableRect) {
640
+ return false;
641
+ }
642
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
643
+ selectionOrTableRect,
644
+ state,
645
+ editorView.domAtPos.bind(editorView),
646
+ getEditorContainerWidth,
647
+ isTableScalingEnabled,
648
+ );
649
+
650
+ if (newResizeStateWithAnalytics) {
651
+ distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI)(
652
+ INPUT_METHOD.FLOATING_TB,
653
+ newResizeStateWithAnalytics,
654
+ )(state, dispatch);
655
+ return true;
656
+ }
657
+ return false;
658
+ };
716
659
 
717
660
  // this create the button group for distribute column and also fixed column width
718
661
  // fixed column button should be in this function call in the future
719
662
  const getColumnSettingItems = (
720
- editorState: EditorState,
721
- editorView: EditorView | undefined | null,
722
- { formatMessage }: ToolbarMenuContext,
723
- getEditorContainerWidth: GetEditorContainerWidth,
724
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
725
- isTableScalingEnabled = false,
663
+ editorState: EditorState,
664
+ editorView: EditorView | undefined | null,
665
+ { formatMessage }: ToolbarMenuContext,
666
+ getEditorContainerWidth: GetEditorContainerWidth,
667
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
668
+ isTableScalingEnabled = false,
726
669
  ): Array<FloatingToolbarItem<Command>> => {
727
- const pluginState = getPluginState(editorState);
728
- const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
729
-
730
- if (!selectionOrTableRect || !editorView) {
731
- return [];
732
- }
733
-
734
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
735
- selectionOrTableRect,
736
- editorState,
737
- editorView.domAtPos.bind(editorView),
738
- getEditorContainerWidth,
739
- isTableScalingEnabled,
740
- );
741
-
742
- const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
743
-
744
- const items: Array<FloatingToolbarItem<Command>> = [];
745
-
746
- const isNested =
747
- pluginState.tablePos && isTableNested(editorState, pluginState.tablePos);
748
-
749
- const isTableScalingLockBtnEnabled =
750
- !isNested &&
751
- isTableScalingEnabled &&
752
- getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
753
-
754
- if (isTableScalingLockBtnEnabled) {
755
- const areColumnWidthsLocked =
756
- pluginState?.tableNode?.attrs.displayMode === 'fixed';
757
-
758
- const title = areColumnWidthsLocked
759
- ? formatMessage(messages.unlockColumnWidths)
760
- : formatMessage(messages.lockColumnWidths);
761
-
762
- items.push({
763
- id: 'editor.table.lockColumns',
764
- type: 'button',
765
- title,
766
- icon: () => <DisplayModeIcon size="medium" label={title} />,
767
- onClick: (state, dispatch, view) =>
768
- getLockBtnConfig(editorAnalyticsAPI)(state, dispatch, view),
769
- selected: areColumnWidthsLocked,
770
- testId: 'table-lock-column-widths-btn',
771
- });
772
- }
773
-
774
- if (
775
- pluginState?.pluginConfig?.allowDistributeColumns &&
776
- pluginState.isDragAndDropEnabled
777
- ) {
778
- items.push({
779
- id: 'editor.table.distributeColumns',
780
- type: 'button',
781
- title: formatMessage(messages.distributeColumns),
782
- icon: DistributeColumnIcon,
783
- onClick: (state, dispatch, view) =>
784
- getDistributeConfig(
785
- getEditorContainerWidth,
786
- editorAnalyticsAPI,
787
- isTableScalingEnabled,
788
- )(state, dispatch, view),
789
- disabled: !wouldChange,
790
- });
791
- }
792
-
793
- if (items.length !== 0) {
794
- items.push({
795
- type: 'separator',
796
- });
797
- }
798
-
799
- return items;
670
+ const pluginState = getPluginState(editorState);
671
+ const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
672
+
673
+ if (!selectionOrTableRect || !editorView) {
674
+ return [];
675
+ }
676
+
677
+ const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
678
+ selectionOrTableRect,
679
+ editorState,
680
+ editorView.domAtPos.bind(editorView),
681
+ getEditorContainerWidth,
682
+ isTableScalingEnabled,
683
+ );
684
+
685
+ const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
686
+
687
+ const items: Array<FloatingToolbarItem<Command>> = [];
688
+
689
+ const isNested = pluginState.tablePos && isTableNested(editorState, pluginState.tablePos);
690
+
691
+ const isTableScalingLockBtnEnabled =
692
+ !isNested &&
693
+ isTableScalingEnabled &&
694
+ getBooleanFF('platform.editor.table.preserve-widths-with-lock-button');
695
+
696
+ if (isTableScalingLockBtnEnabled) {
697
+ const areColumnWidthsLocked = pluginState?.tableNode?.attrs.displayMode === 'fixed';
698
+
699
+ const title = areColumnWidthsLocked
700
+ ? formatMessage(messages.unlockColumnWidths)
701
+ : formatMessage(messages.lockColumnWidths);
702
+
703
+ items.push({
704
+ id: 'editor.table.lockColumns',
705
+ type: 'button',
706
+ title,
707
+ icon: () => <DisplayModeIcon size="medium" label={title} />,
708
+ onClick: (state, dispatch, view) =>
709
+ getLockBtnConfig(editorAnalyticsAPI)(state, dispatch, view),
710
+ selected: areColumnWidthsLocked,
711
+ testId: 'table-lock-column-widths-btn',
712
+ });
713
+ }
714
+
715
+ if (pluginState?.pluginConfig?.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
716
+ items.push({
717
+ id: 'editor.table.distributeColumns',
718
+ type: 'button',
719
+ title: formatMessage(messages.distributeColumns),
720
+ icon: DistributeColumnIcon,
721
+ onClick: (state, dispatch, view) =>
722
+ getDistributeConfig(getEditorContainerWidth, editorAnalyticsAPI, isTableScalingEnabled)(
723
+ state,
724
+ dispatch,
725
+ view,
726
+ ),
727
+ disabled: !wouldChange,
728
+ });
729
+ }
730
+
731
+ if (items.length !== 0) {
732
+ items.push({
733
+ type: 'separator',
734
+ });
735
+ }
736
+
737
+ return items;
800
738
  };
801
739
 
802
740
  const getColorPicker = (
803
- state: EditorState,
804
- menu: FloatingToolbarItem<Command>,
805
- { formatMessage }: ToolbarMenuContext,
806
- editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined,
807
- getEditorView: () => EditorView | null,
741
+ state: EditorState,
742
+ menu: FloatingToolbarItem<Command>,
743
+ { formatMessage }: ToolbarMenuContext,
744
+ editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined,
745
+ getEditorView: () => EditorView | null,
808
746
  ): Array<FloatingToolbarItem<Command>> => {
809
- const { targetCellPosition, pluginConfig } = getPluginState(state);
810
- if (!pluginConfig.allowBackgroundColor) {
811
- return [];
812
- }
813
- const node = targetCellPosition
814
- ? state.doc.nodeAt(targetCellPosition)
815
- : undefined;
816
- const currentBackground = node?.attrs?.background || '#ffffff';
817
- const defaultPalette = cellBackgroundColorPalette.find(
818
- (item) => item.value === currentBackground,
819
- ) || {
820
- label: 'Custom',
821
- value: currentBackground,
822
- border: DEFAULT_BORDER_COLOR,
823
- };
824
-
825
- return [
826
- {
827
- id: 'editor.table.colorPicker',
828
- title: formatMessage(messages.cellBackground),
829
- type: 'select',
830
- isAriaExpanded: true,
831
- selectType: 'color',
832
- defaultValue: defaultPalette,
833
- options: cellBackgroundColorPalette,
834
- returnEscToButton: true,
835
- onChange: (option: any) =>
836
- setColorWithAnalytics(editorAnalyticsAPI)(
837
- INPUT_METHOD.FLOATING_TB,
838
- option.value,
839
- targetCellPosition,
840
- getEditorView(),
841
- ),
842
- },
843
- separator(menu.hidden),
844
- ];
747
+ const { targetCellPosition, pluginConfig } = getPluginState(state);
748
+ if (!pluginConfig.allowBackgroundColor) {
749
+ return [];
750
+ }
751
+ const node = targetCellPosition ? state.doc.nodeAt(targetCellPosition) : undefined;
752
+ const currentBackground = node?.attrs?.background || '#ffffff';
753
+ const defaultPalette = cellBackgroundColorPalette.find(
754
+ (item) => item.value === currentBackground,
755
+ ) || {
756
+ label: 'Custom',
757
+ value: currentBackground,
758
+ border: DEFAULT_BORDER_COLOR,
759
+ };
760
+
761
+ return [
762
+ {
763
+ id: 'editor.table.colorPicker',
764
+ title: formatMessage(messages.cellBackground),
765
+ type: 'select',
766
+ isAriaExpanded: true,
767
+ selectType: 'color',
768
+ defaultValue: defaultPalette,
769
+ options: cellBackgroundColorPalette,
770
+ returnEscToButton: true,
771
+ onChange: (option: any) =>
772
+ setColorWithAnalytics(editorAnalyticsAPI)(
773
+ INPUT_METHOD.FLOATING_TB,
774
+ option.value,
775
+ targetCellPosition,
776
+ getEditorView(),
777
+ ),
778
+ },
779
+ separator(menu.hidden),
780
+ ];
845
781
  };
846
782
 
847
783
  const clickWithCheckboxHandler =
848
- (
849
- isChecked: boolean,
850
- node?: PMNode,
851
- editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null,
852
- ): Command =>
853
- (state, dispatch) => {
854
- if (!node) {
855
- return false;
856
- }
857
-
858
- if (!isChecked) {
859
- return deleteTableWithAnalytics(editorAnalyticsAPI)(state, dispatch);
860
- } else {
861
- removeDescendantNodes(node)(state, dispatch);
862
- }
863
- return true;
864
- };
865
-
866
- const highlightRowsHandler = (
867
- state: EditorState,
868
- dispatch?: CommandDispatch,
869
- ) => {
870
- const selectionRect = getClosestSelectionRect(state);
871
- if (selectionRect) {
872
- hoverRows(getSelectedRowIndexes(selectionRect), true)(state, dispatch);
873
- return true;
874
- }
875
- return false;
784
+ (
785
+ isChecked: boolean,
786
+ node?: PMNode,
787
+ editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null,
788
+ ): Command =>
789
+ (state, dispatch) => {
790
+ if (!node) {
791
+ return false;
792
+ }
793
+
794
+ if (!isChecked) {
795
+ return deleteTableWithAnalytics(editorAnalyticsAPI)(state, dispatch);
796
+ } else {
797
+ removeDescendantNodes(node)(state, dispatch);
798
+ }
799
+ return true;
800
+ };
801
+
802
+ const highlightRowsHandler = (state: EditorState, dispatch?: CommandDispatch) => {
803
+ const selectionRect = getClosestSelectionRect(state);
804
+ if (selectionRect) {
805
+ hoverRows(getSelectedRowIndexes(selectionRect), true)(state, dispatch);
806
+ return true;
807
+ }
808
+ return false;
876
809
  };
877
810
 
878
- const highlightColumnsHandler = (
879
- state: EditorState,
880
- dispatch?: CommandDispatch,
881
- ) => {
882
- const selectionRect = getClosestSelectionRect(state);
883
- if (selectionRect) {
884
- hoverColumns(getSelectedColumnIndexes(selectionRect), true)(
885
- state,
886
- dispatch,
887
- );
888
- return true;
889
- }
890
- return false;
811
+ const highlightColumnsHandler = (state: EditorState, dispatch?: CommandDispatch) => {
812
+ const selectionRect = getClosestSelectionRect(state);
813
+ if (selectionRect) {
814
+ hoverColumns(getSelectedColumnIndexes(selectionRect), true)(state, dispatch);
815
+ return true;
816
+ }
817
+ return false;
891
818
  };
892
819
 
893
820
  type AlignmentIcon = {
894
- id?: string;
895
- value: AlignmentOptions;
896
- icon: React.ComponentClass<any>;
821
+ id?: string;
822
+ value: AlignmentOptions;
823
+ icon: React.ComponentClass<any>;
897
824
  };
898
825
 
899
826
  export const getAlignmentOptionsConfig = (
900
- editorState: EditorState,
901
- { formatMessage }: ToolbarMenuContext,
902
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
903
- getEditorContainerWidth: GetEditorContainerWidth
827
+ editorState: EditorState,
828
+ { formatMessage }: ToolbarMenuContext,
829
+ editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
830
+ getEditorContainerWidth: GetEditorContainerWidth,
904
831
  ): Array<FloatingToolbarDropdown<Command>> => {
905
- const tableObject = findTable(editorState.selection);
906
-
907
- if (!tableObject) {
908
- return [];
909
- }
910
-
911
- const alignmentIcons: AlignmentIcon[] = [
912
- {
913
- id: 'editor.table.alignLeft',
914
- value: 'align-start',
915
- icon: EditorAlignImageLeft,
916
- },
917
- {
918
- id: 'editor.table.alignCenter',
919
- value: 'center',
920
- icon: EditorAlignImageCenter,
921
- },
922
- ];
923
-
924
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
925
- const layoutToMessages: Record<AlignmentOptions, any> = {
926
- center: messages.alignTableCenter,
927
- 'align-start': messages.alignTableLeft,
928
- };
929
-
930
- const alignmentButtons = alignmentIcons.map<FloatingToolbarItem<Command>>(
931
- (alignmentIcon) => {
932
- const { id, value, icon } = alignmentIcon;
933
- const currentLayout = tableObject.node.attrs.layout;
934
-
935
- return {
936
- id: id,
937
- type: 'button',
938
- icon: icon,
939
- title: formatMessage(layoutToMessages[value]),
940
- selected: normaliseAlignment(currentLayout) === value,
941
- onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(
942
- value,
943
- currentLayout,
944
- INPUT_METHOD.FLOATING_TB
945
- ),
946
- ...(isLayoutOptionDisabled(tableObject.node, getEditorContainerWidth) && { disabled: value !== 'center' }),
947
- };
948
- },
949
- );
950
-
951
- const alignmentItemOptions: DropdownOptions<Command> = {
952
- render: (props) => {
953
- return (
954
- <FloatingAlignmentButtons
955
- alignmentButtons={alignmentButtons}
956
- {...props}
957
- />
958
- );
959
- },
960
- width: 60,
961
- height: 32,
962
- };
963
-
964
- const selectedAlignmentIcon = getSelectedAlignmentIcon(
965
- alignmentIcons,
966
- tableObject.node,
967
- );
968
-
969
- const alignmentToolbarItem: Array<FloatingToolbarDropdown<Command>> = [
970
- {
971
- id: 'table-layout',
972
- testId: 'table-layout-dropdown',
973
- type: 'dropdown',
974
- options: alignmentItemOptions,
975
- title: formatMessage(messages.tableAlignmentOptions),
976
- icon: selectedAlignmentIcon?.icon,
977
- },
978
- ];
979
-
980
- return alignmentToolbarItem;
832
+ const tableObject = findTable(editorState.selection);
833
+
834
+ if (!tableObject) {
835
+ return [];
836
+ }
837
+
838
+ const alignmentIcons: AlignmentIcon[] = [
839
+ {
840
+ id: 'editor.table.alignLeft',
841
+ value: 'align-start',
842
+ icon: EditorAlignImageLeft,
843
+ },
844
+ {
845
+ id: 'editor.table.alignCenter',
846
+ value: 'center',
847
+ icon: EditorAlignImageCenter,
848
+ },
849
+ ];
850
+
851
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
852
+ const layoutToMessages: Record<AlignmentOptions, any> = {
853
+ center: messages.alignTableCenter,
854
+ 'align-start': messages.alignTableLeft,
855
+ };
856
+
857
+ const alignmentButtons = alignmentIcons.map<FloatingToolbarItem<Command>>((alignmentIcon) => {
858
+ const { id, value, icon } = alignmentIcon;
859
+ const currentLayout = tableObject.node.attrs.layout;
860
+
861
+ return {
862
+ id: id,
863
+ type: 'button',
864
+ icon: icon,
865
+ title: formatMessage(layoutToMessages[value]),
866
+ selected: normaliseAlignment(currentLayout) === value,
867
+ onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(
868
+ value,
869
+ currentLayout,
870
+ INPUT_METHOD.FLOATING_TB,
871
+ ),
872
+ ...(isLayoutOptionDisabled(tableObject.node, getEditorContainerWidth) && {
873
+ disabled: value !== 'center',
874
+ }),
875
+ };
876
+ });
877
+
878
+ const alignmentItemOptions: DropdownOptions<Command> = {
879
+ render: (props) => {
880
+ return <FloatingAlignmentButtons alignmentButtons={alignmentButtons} {...props} />;
881
+ },
882
+ width: 60,
883
+ height: 32,
884
+ };
885
+
886
+ const selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
887
+
888
+ const alignmentToolbarItem: Array<FloatingToolbarDropdown<Command>> = [
889
+ {
890
+ id: 'table-layout',
891
+ testId: 'table-layout-dropdown',
892
+ type: 'dropdown',
893
+ options: alignmentItemOptions,
894
+ title: formatMessage(messages.tableAlignmentOptions),
895
+ icon: selectedAlignmentIcon?.icon,
896
+ },
897
+ ];
898
+
899
+ return alignmentToolbarItem;
981
900
  };
982
901
 
983
- export const getSelectedAlignmentIcon = (
984
- alignmentIcons: AlignmentIcon[],
985
- selectedNode: PMNode,
986
- ) => {
987
- const selectedAlignment = selectedNode.attrs.layout;
902
+ export const getSelectedAlignmentIcon = (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => {
903
+ const selectedAlignment = selectedNode.attrs.layout;
988
904
 
989
- return alignmentIcons.find(
990
- (icon) => icon.value === normaliseAlignment(selectedAlignment),
991
- );
905
+ return alignmentIcons.find((icon) => icon.value === normaliseAlignment(selectedAlignment));
992
906
  };
993
907
 
994
908
  export const isLayoutOptionDisabled = (
995
- selectedNode: PMNode,
996
- getEditorContainerWidth: GetEditorContainerWidth
909
+ selectedNode: PMNode,
910
+ getEditorContainerWidth: GetEditorContainerWidth,
997
911
  ) => {
998
- const lineLength = getEditorContainerWidth().lineLength;
912
+ const lineLength = getEditorContainerWidth().lineLength;
999
913
 
1000
- if (
1001
- selectedNode &&
1002
- lineLength &&
1003
- selectedNode.attrs.width > lineLength
1004
- ) {
1005
- return true;
1006
- }
914
+ if (selectedNode && lineLength && selectedNode.attrs.width > lineLength) {
915
+ return true;
916
+ }
1007
917
 
1008
- return false;
918
+ return false;
1009
919
  };