@atlaskit/editor-plugin-table 12.2.6 → 12.2.7

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 (204) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +4 -4
  3. package/afm-cc/tsconfig.json +0 -123
  4. package/afm-dev-agents/tsconfig.json +0 -123
  5. package/afm-jira/tsconfig.json +0 -123
  6. package/afm-passionfruit/tsconfig.json +0 -123
  7. package/afm-post-office/tsconfig.json +0 -123
  8. package/afm-rovo-extension/tsconfig.json +0 -123
  9. package/afm-townsquare/tsconfig.json +0 -123
  10. package/afm-volt/tsconfig.json +0 -114
  11. package/build/tsconfig.json +0 -23
  12. package/docs/0-intro.tsx +0 -57
  13. package/src/index.ts +0 -21
  14. package/src/nodeviews/ExternalDropTargets.tsx +0 -91
  15. package/src/nodeviews/OverflowShadowsObserver.ts +0 -156
  16. package/src/nodeviews/TableCell.ts +0 -134
  17. package/src/nodeviews/TableComponent.tsx +0 -1590
  18. package/src/nodeviews/TableComponentWithSharedState.tsx +0 -278
  19. package/src/nodeviews/TableContainer.tsx +0 -926
  20. package/src/nodeviews/TableNodeViewBase.ts +0 -29
  21. package/src/nodeviews/TableResizer.tsx +0 -884
  22. package/src/nodeviews/TableRow.ts +0 -830
  23. package/src/nodeviews/TableStickyScrollbar.ts +0 -211
  24. package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +0 -15
  25. package/src/nodeviews/__mocks__/OverridableMock.ts +0 -26
  26. package/src/nodeviews/table-container-styles.ts +0 -9
  27. package/src/nodeviews/table-node-views.ts +0 -76
  28. package/src/nodeviews/table.tsx +0 -530
  29. package/src/nodeviews/toDOM.ts +0 -244
  30. package/src/nodeviews/types.ts +0 -36
  31. package/src/nodeviews/update-overflow-shadows.ts +0 -11
  32. package/src/pm-plugins/analytics/actions.ts +0 -21
  33. package/src/pm-plugins/analytics/commands.ts +0 -47
  34. package/src/pm-plugins/analytics/plugin-factory.ts +0 -9
  35. package/src/pm-plugins/analytics/plugin-key.ts +0 -5
  36. package/src/pm-plugins/analytics/plugin.ts +0 -80
  37. package/src/pm-plugins/analytics/reducer.ts +0 -27
  38. package/src/pm-plugins/analytics/types.ts +0 -20
  39. package/src/pm-plugins/analytics/utils/moved-event.ts +0 -51
  40. package/src/pm-plugins/commands/clear.ts +0 -43
  41. package/src/pm-plugins/commands/collapse.ts +0 -17
  42. package/src/pm-plugins/commands/column-resize.ts +0 -478
  43. package/src/pm-plugins/commands/commands-with-analytics.ts +0 -715
  44. package/src/pm-plugins/commands/delete.ts +0 -42
  45. package/src/pm-plugins/commands/display-mode.ts +0 -18
  46. package/src/pm-plugins/commands/go-to-next-cell.ts +0 -198
  47. package/src/pm-plugins/commands/hover.ts +0 -242
  48. package/src/pm-plugins/commands/index.ts +0 -51
  49. package/src/pm-plugins/commands/insert.ts +0 -438
  50. package/src/pm-plugins/commands/misc.ts +0 -811
  51. package/src/pm-plugins/commands/referentiality.ts +0 -15
  52. package/src/pm-plugins/commands/selection.ts +0 -537
  53. package/src/pm-plugins/commands/sort.ts +0 -102
  54. package/src/pm-plugins/commands/split-cell.ts +0 -28
  55. package/src/pm-plugins/commands/toggle.ts +0 -109
  56. package/src/pm-plugins/create-plugin-config.ts +0 -17
  57. package/src/pm-plugins/decorations/plugin.ts +0 -107
  58. package/src/pm-plugins/decorations/utils/column-controls.ts +0 -91
  59. package/src/pm-plugins/decorations/utils/column-resizing.ts +0 -71
  60. package/src/pm-plugins/decorations/utils/compose-decorations.ts +0 -9
  61. package/src/pm-plugins/decorations/utils/types.ts +0 -16
  62. package/src/pm-plugins/default-table-selection.ts +0 -14
  63. package/src/pm-plugins/drag-and-drop/actions.ts +0 -48
  64. package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +0 -222
  65. package/src/pm-plugins/drag-and-drop/commands.ts +0 -194
  66. package/src/pm-plugins/drag-and-drop/consts.ts +0 -7
  67. package/src/pm-plugins/drag-and-drop/plugin-factory.ts +0 -33
  68. package/src/pm-plugins/drag-and-drop/plugin-key.ts +0 -5
  69. package/src/pm-plugins/drag-and-drop/plugin.ts +0 -398
  70. package/src/pm-plugins/drag-and-drop/reducer.ts +0 -38
  71. package/src/pm-plugins/drag-and-drop/types.ts +0 -18
  72. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +0 -49
  73. package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +0 -9
  74. package/src/pm-plugins/drag-and-drop/utils/monitor.ts +0 -73
  75. package/src/pm-plugins/handlers.ts +0 -161
  76. package/src/pm-plugins/keymap.ts +0 -436
  77. package/src/pm-plugins/main.ts +0 -433
  78. package/src/pm-plugins/plugin-factory.ts +0 -42
  79. package/src/pm-plugins/plugin-key.ts +0 -8
  80. package/src/pm-plugins/reducer.ts +0 -145
  81. package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +0 -102
  82. package/src/pm-plugins/sticky-headers/commands.ts +0 -8
  83. package/src/pm-plugins/sticky-headers/plugin-key.ts +0 -5
  84. package/src/pm-plugins/sticky-headers/plugin-state.ts +0 -52
  85. package/src/pm-plugins/sticky-headers/plugin.ts +0 -12
  86. package/src/pm-plugins/sticky-headers/types.ts +0 -20
  87. package/src/pm-plugins/sticky-headers/util.ts +0 -18
  88. package/src/pm-plugins/table-analytics.ts +0 -100
  89. package/src/pm-plugins/table-local-id.ts +0 -213
  90. package/src/pm-plugins/table-resizing/commands.ts +0 -116
  91. package/src/pm-plugins/table-resizing/event-handlers.ts +0 -352
  92. package/src/pm-plugins/table-resizing/plugin-factory.ts +0 -29
  93. package/src/pm-plugins/table-resizing/plugin-key.ts +0 -5
  94. package/src/pm-plugins/table-resizing/plugin.ts +0 -94
  95. package/src/pm-plugins/table-resizing/reducer.ts +0 -37
  96. package/src/pm-plugins/table-resizing/utils/colgroup.ts +0 -306
  97. package/src/pm-plugins/table-resizing/utils/column-state.ts +0 -120
  98. package/src/pm-plugins/table-resizing/utils/consts.ts +0 -11
  99. package/src/pm-plugins/table-resizing/utils/content-width.ts +0 -118
  100. package/src/pm-plugins/table-resizing/utils/dom.ts +0 -132
  101. package/src/pm-plugins/table-resizing/utils/misc.ts +0 -282
  102. package/src/pm-plugins/table-resizing/utils/resize-column.ts +0 -34
  103. package/src/pm-plugins/table-resizing/utils/resize-logic.ts +0 -289
  104. package/src/pm-plugins/table-resizing/utils/resize-state.ts +0 -417
  105. package/src/pm-plugins/table-resizing/utils/scale-table.ts +0 -290
  106. package/src/pm-plugins/table-resizing/utils/types.ts +0 -25
  107. package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +0 -1
  108. package/src/pm-plugins/table-selection-keymap.ts +0 -64
  109. package/src/pm-plugins/table-size-selector.ts +0 -39
  110. package/src/pm-plugins/table-width-in-comment-fix.ts +0 -113
  111. package/src/pm-plugins/table-width.ts +0 -153
  112. package/src/pm-plugins/transforms/column-width.ts +0 -249
  113. package/src/pm-plugins/transforms/delete-columns.ts +0 -281
  114. package/src/pm-plugins/transforms/delete-rows.ts +0 -154
  115. package/src/pm-plugins/transforms/fix-tables.ts +0 -249
  116. package/src/pm-plugins/transforms/merge.ts +0 -301
  117. package/src/pm-plugins/transforms/replace-table.ts +0 -38
  118. package/src/pm-plugins/transforms/split.ts +0 -90
  119. package/src/pm-plugins/utils/alignment.ts +0 -33
  120. package/src/pm-plugins/utils/analytics.ts +0 -238
  121. package/src/pm-plugins/utils/collapse.ts +0 -93
  122. package/src/pm-plugins/utils/column-controls.ts +0 -250
  123. package/src/pm-plugins/utils/create.ts +0 -64
  124. package/src/pm-plugins/utils/decoration.ts +0 -672
  125. package/src/pm-plugins/utils/dom.ts +0 -251
  126. package/src/pm-plugins/utils/drag-menu.tsx +0 -491
  127. package/src/pm-plugins/utils/get-allow-add-column-custom-step.ts +0 -10
  128. package/src/pm-plugins/utils/guidelines.ts +0 -30
  129. package/src/pm-plugins/utils/merged-cells.ts +0 -239
  130. package/src/pm-plugins/utils/nodes.ts +0 -162
  131. package/src/pm-plugins/utils/paste.ts +0 -386
  132. package/src/pm-plugins/utils/row-controls.ts +0 -211
  133. package/src/pm-plugins/utils/selection.ts +0 -17
  134. package/src/pm-plugins/utils/snapping.ts +0 -136
  135. package/src/pm-plugins/utils/table.ts +0 -60
  136. package/src/pm-plugins/utils/update-plugin-state-decorations.ts +0 -13
  137. package/src/pm-plugins/view-mode-sort/consts.ts +0 -3
  138. package/src/pm-plugins/view-mode-sort/index.ts +0 -291
  139. package/src/pm-plugins/view-mode-sort/plugin-key.ts +0 -7
  140. package/src/pm-plugins/view-mode-sort/types.ts +0 -23
  141. package/src/pm-plugins/view-mode-sort/utils.ts +0 -136
  142. package/src/tablePlugin.tsx +0 -971
  143. package/src/tablePluginType.ts +0 -102
  144. package/src/types/index.ts +0 -592
  145. package/src/ui/ColumnResizeWidget/index.tsx +0 -61
  146. package/src/ui/ContentComponent.tsx +0 -311
  147. package/src/ui/DragHandle/HandleIconComponent.tsx +0 -21
  148. package/src/ui/DragHandle/index.tsx +0 -391
  149. package/src/ui/DragPreview/index.tsx +0 -51
  150. package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +0 -59
  151. package/src/ui/FloatingContextualButton/FixedButton.tsx +0 -203
  152. package/src/ui/FloatingContextualButton/index.tsx +0 -168
  153. package/src/ui/FloatingContextualButton/styles.ts +0 -69
  154. package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +0 -931
  155. package/src/ui/FloatingContextualMenu/index.tsx +0 -141
  156. package/src/ui/FloatingContextualMenu/styles.ts +0 -77
  157. package/src/ui/FloatingDeleteButton/DeleteButton.tsx +0 -54
  158. package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +0 -65
  159. package/src/ui/FloatingDeleteButton/index.tsx +0 -383
  160. package/src/ui/FloatingDeleteButton/types.ts +0 -3
  161. package/src/ui/FloatingDragMenu/DragMenu.tsx +0 -668
  162. package/src/ui/FloatingDragMenu/DropdownMenu.tsx +0 -221
  163. package/src/ui/FloatingDragMenu/index.tsx +0 -136
  164. package/src/ui/FloatingDragMenu/styles.ts +0 -83
  165. package/src/ui/FloatingInsertButton/InsertButton.tsx +0 -263
  166. package/src/ui/FloatingInsertButton/getPopupOptions.ts +0 -131
  167. package/src/ui/FloatingInsertButton/index.tsx +0 -314
  168. package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +0 -31
  169. package/src/ui/SizeSelector/index.tsx +0 -74
  170. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +0 -397
  171. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +0 -105
  172. package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +0 -63
  173. package/src/ui/TableFloatingColumnControls/index.tsx +0 -151
  174. package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +0 -106
  175. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +0 -143
  176. package/src/ui/TableFloatingControls/CornerControls/types.ts +0 -12
  177. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +0 -88
  178. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +0 -175
  179. package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +0 -131
  180. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +0 -429
  181. package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +0 -96
  182. package/src/ui/TableFloatingControls/index.tsx +0 -275
  183. package/src/ui/TableFullWidthLabel/index.tsx +0 -38
  184. package/src/ui/common-styles.ts +0 -1218
  185. package/src/ui/consts.ts +0 -109
  186. package/src/ui/event-handlers.ts +0 -662
  187. package/src/ui/global-styles.tsx +0 -55
  188. package/src/ui/hooks/useInternalTablePluginStateSelector.ts +0 -38
  189. package/src/ui/icons/AddColLeftIcon.tsx +0 -37
  190. package/src/ui/icons/AddColRightIcon.tsx +0 -37
  191. package/src/ui/icons/AddRowAboveIcon.tsx +0 -22
  192. package/src/ui/icons/AddRowBelowIcon.tsx +0 -39
  193. package/src/ui/icons/DragHandleDisabledIcon.tsx +0 -25
  194. package/src/ui/icons/DragHandleIcon.tsx +0 -16
  195. package/src/ui/icons/DragInMotionIcon.tsx +0 -54
  196. package/src/ui/icons/MergeCellsIcon.tsx +0 -26
  197. package/src/ui/icons/MinimisedHandle.tsx +0 -15
  198. package/src/ui/icons/SortingIconWrapper.tsx +0 -43
  199. package/src/ui/icons/SplitCellIcon.tsx +0 -34
  200. package/src/ui/toolbar.tsx +0 -1153
  201. package/src/ui/ui-styles.ts +0 -960
  202. package/tsconfig.app.json +0 -135
  203. package/tsconfig.dev.json +0 -54
  204. package/tsconfig.json +0 -18
@@ -1,1153 +0,0 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
5
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
- import { jsx } from '@emotion/react';
7
-
8
- import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
9
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
10
- import { CHANGE_ALIGNMENT_REASON, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
11
- import { DropdownMenuExtensionItems } from '@atlaskit/editor-common/floating-toolbar';
12
- import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
13
- import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
14
- import { isSelectionTableNestedInTable } from '@atlaskit/editor-common/nesting';
15
- import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
16
- import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-check';
17
- import type {
18
- Command,
19
- CommandDispatch,
20
- ConfirmDialogOptions,
21
- DropdownOptionT,
22
- DropdownOptions,
23
- FloatingToolbarDropdown,
24
- FloatingToolbarHandler,
25
- FloatingToolbarItem,
26
- GetEditorContainerWidth,
27
- Icon,
28
- typeOption,
29
- } from '@atlaskit/editor-common/types';
30
- import { DEFAULT_BORDER_COLOR, cellBackgroundColorPalette } from '@atlaskit/editor-common/ui-color';
31
- import {
32
- closestElement,
33
- getChildrenInfo,
34
- getNodeName,
35
- isReferencedSource,
36
- } from '@atlaskit/editor-common/utils';
37
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
38
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
39
- import { findParentDomRefOfType } from '@atlaskit/editor-prosemirror/utils';
40
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
41
- import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
42
- import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
43
- import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
44
- import {
45
- findCellRectClosestToPos,
46
- findTable,
47
- getSelectionRect,
48
- isSelectionType,
49
- splitCell,
50
- } from '@atlaskit/editor-tables/utils';
51
- import AlignImageCenterIcon from '@atlaskit/icon/core/align-image-center';
52
- import AlignImageLeftIcon from '@atlaskit/icon/core/align-image-left';
53
- import CopyIcon from '@atlaskit/icon/core/copy';
54
- import CustomizeIcon from '@atlaskit/icon/core/migration/customize--preferences';
55
- import DeleteIcon from '@atlaskit/icon/core/migration/delete--editor-remove';
56
- import TableColumnsDistributeIcon from '@atlaskit/icon/core/table-columns-distribute';
57
- import EditorAlignImageCenter from '@atlaskit/icon/glyph/editor/align-image-center';
58
- import EditorAlignImageLeft from '@atlaskit/icon/glyph/editor/align-image-left';
59
- import DistributeColumnIcon from '@atlaskit/icon/glyph/editor/layout-three-equal';
60
- import { fg } from '@atlaskit/platform-feature-flags';
61
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
62
-
63
- import {
64
- clearHoverSelection,
65
- hoverColumns,
66
- hoverMergedCells,
67
- hoverRows,
68
- hoverTable,
69
- removeDescendantNodes,
70
- } from '../pm-plugins/commands';
71
- import {
72
- deleteColumnsWithAnalytics,
73
- deleteRowsWithAnalytics,
74
- deleteTableWithAnalytics,
75
- distributeColumnsWidthsWithAnalytics,
76
- emptyMultipleCellsWithAnalytics,
77
- insertColumnWithAnalytics,
78
- insertRowWithAnalytics,
79
- mergeCellsWithAnalytics,
80
- setColorWithAnalytics,
81
- setTableAlignmentWithAnalytics,
82
- sortColumnWithAnalytics,
83
- splitCellWithAnalytics,
84
- toggleFixedColumnWidthsOptionAnalytics,
85
- toggleHeaderColumnWithAnalytics,
86
- toggleHeaderRowWithAnalytics,
87
- toggleNumberColumnWithAnalytics,
88
- wrapTableInExpandWithAnalytics,
89
- } from '../pm-plugins/commands/commands-with-analytics';
90
- import { getPluginState as getDragDropPluginState } from '../pm-plugins/drag-and-drop/plugin-factory';
91
- import { getPluginState } from '../pm-plugins/plugin-factory';
92
- import { pluginKey as tableResizingPluginKey } from '../pm-plugins/table-resizing/plugin-key';
93
- import { getStaticTableScalingPercent } from '../pm-plugins/table-resizing/utils/misc';
94
- import { getNewResizeStateFromSelectedColumns } from '../pm-plugins/table-resizing/utils/resize-state';
95
- import { pluginKey as tableWidthPluginKey } from '../pm-plugins/table-width';
96
- import { canMergeCells } from '../pm-plugins/transforms/merge';
97
- import { normaliseAlignment } from '../pm-plugins/utils/alignment';
98
- import { isTableNested } from '../pm-plugins/utils/nodes';
99
- import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../pm-plugins/utils/selection';
100
- import { getMergedCellsPositions } from '../pm-plugins/utils/table';
101
- import type { TablePluginOptions } from '../tablePluginType';
102
- import type {
103
- AlignmentOptions,
104
- PluginConfig,
105
- PluginInjectionAPI,
106
- ToolbarMenuConfig,
107
- ToolbarMenuContext,
108
- ToolbarMenuState,
109
- } from '../types';
110
- import { TableCssClassName } from '../types';
111
-
112
- import { FloatingAlignmentButtons } from './FloatingAlignmentButtons/FloatingAlignmentButtons';
113
-
114
- export const getToolbarMenuConfig = (
115
- config: ToolbarMenuConfig,
116
- state: ToolbarMenuState,
117
- { formatMessage }: ToolbarMenuContext,
118
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
119
- isTableScalingWithFixedColumnWidthsOptionShown = false,
120
- areTableColumnWidthsFixed = false,
121
- ): FloatingToolbarItem<Command> => {
122
- const optionItem: typeOption = 'item-checkbox';
123
-
124
- const options = [
125
- {
126
- id: 'editor.table.lockColumnWidths',
127
- title: formatMessage(messages.lockColumnWidths),
128
- onClick: toggleFixedColumnWidthsOptionAnalytics(editorAnalyticsAPI, INPUT_METHOD.FLOATING_TB),
129
- selected: areTableColumnWidthsFixed,
130
- hidden: !isTableScalingWithFixedColumnWidthsOptionShown,
131
- domItemOptions: { type: optionItem },
132
- },
133
- {
134
- id: 'editor.table.headerRow',
135
- title: formatMessage(messages.headerRow),
136
- onClick: toggleHeaderRowWithAnalytics(editorAnalyticsAPI),
137
- selected: state.isHeaderRowEnabled,
138
- hidden: !config.allowHeaderRow,
139
- domItemOptions: { type: optionItem },
140
- },
141
- {
142
- id: 'editor.table.headerColumn',
143
- title: formatMessage(messages.headerColumn),
144
- onClick: toggleHeaderColumnWithAnalytics(editorAnalyticsAPI),
145
- selected: state.isHeaderColumnEnabled,
146
- hidden: !config.allowHeaderColumn,
147
- domItemOptions: { type: optionItem },
148
- },
149
- {
150
- id: 'editor.table.numberedColumn',
151
- title: formatMessage(messages.numberedColumn),
152
- onClick: toggleNumberColumnWithAnalytics(editorAnalyticsAPI),
153
- selected: state.isNumberColumnEnabled,
154
- hidden: !config.allowNumberColumn,
155
- domItemOptions: { type: optionItem },
156
- },
157
- {
158
- id: 'editor.table.collapseTable',
159
- title: formatMessage(messages.collapseTable),
160
- onClick: wrapTableInExpandWithAnalytics(editorAnalyticsAPI),
161
- selected: !!state.isTableCollapsed,
162
- disabled: !state.canCollapseTable,
163
- hidden: !config.allowCollapse,
164
- domItemOptions: { type: optionItem },
165
- },
166
- ];
167
-
168
- const tableOptionsDropdownWidth = isTableScalingWithFixedColumnWidthsOptionShown
169
- ? 192
170
- : undefined;
171
- if (state.isDragAndDropEnabled) {
172
- return {
173
- id: 'editor.table.tableOptions',
174
- type: 'dropdown',
175
- testId: 'table_options',
176
- // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
177
- icon: fg('platform-visual-refresh-icons') ? undefined : CustomizeIcon,
178
- iconBefore: fg('platform-visual-refresh-icons') ? CustomizeIcon : undefined,
179
- title: formatMessage(messages.tableOptions),
180
- hidden: options.every((option) => option.hidden),
181
- options,
182
- dropdownWidth: tableOptionsDropdownWidth,
183
- };
184
- } else {
185
- return {
186
- id: 'editor.table.tableOptions',
187
- type: 'dropdown',
188
- testId: 'table_options',
189
- title: formatMessage(messages.tableOptions),
190
- hidden: options.every((option) => option.hidden),
191
- options,
192
- dropdownWidth: tableOptionsDropdownWidth,
193
- };
194
- }
195
- };
196
-
197
- // Added these options for mobile. Mobile bridge translates this menu and
198
- // relay it to the native mobile. Native mobile displays the menu
199
- // with native widgets. It's enabled via a plugin config.
200
- export const getToolbarCellOptionsConfig = (
201
- editorState: EditorState,
202
- editorView: EditorView | undefined | null,
203
- initialSelectionRect: Rect,
204
- { formatMessage }: ToolbarMenuContext,
205
- getEditorContainerWidth: GetEditorContainerWidth,
206
- api: PluginInjectionAPI | undefined | null,
207
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
208
- isTableScalingEnabled = false,
209
- isTableFixedColumnWidthsOptionEnabled = false,
210
- shouldUseIncreasedScalingPercent = false,
211
- isCommentEditor = false,
212
- ): FloatingToolbarDropdown<Command> => {
213
- const { top, bottom, right, left } = initialSelectionRect;
214
- const numberOfColumns = right - left;
215
- const numberOfRows = bottom - top;
216
- const pluginState = getPluginState(editorState);
217
-
218
- const options: DropdownOptionT<Command>[] = [
219
- {
220
- id: 'editor.table.insertColumn',
221
- title: formatMessage(messages.insertColumn),
222
- onClick: (state: EditorState, dispatch?: CommandDispatch, view?: EditorView) => {
223
- const selectionRect = getClosestSelectionRect(state);
224
- const index = selectionRect?.right;
225
- if (index) {
226
- insertColumnWithAnalytics(
227
- api,
228
- editorAnalyticsAPI,
229
- isTableScalingEnabled,
230
- isTableFixedColumnWidthsOptionEnabled,
231
- shouldUseIncreasedScalingPercent,
232
- isCommentEditor,
233
- )(INPUT_METHOD.FLOATING_TB, index)(state, dispatch, view);
234
- }
235
- return true;
236
- },
237
- selected: false,
238
- disabled: false,
239
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
240
- elemAfter: <div css={shortcutStyle}>{tooltip(addColumnAfter)}</div>,
241
- },
242
- {
243
- id: 'editor.table.insertRow',
244
- title: formatMessage(messages.insertRow),
245
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
246
- const selectionRect = getClosestSelectionRect(state);
247
- const index = selectionRect?.bottom;
248
- if (index) {
249
- insertRowWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB, {
250
- index,
251
- moveCursorToInsertedRow: true,
252
- })(state, dispatch);
253
- }
254
- return true;
255
- },
256
- selected: false,
257
- disabled: false,
258
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
259
- elemAfter: <div css={shortcutStyle}>{tooltip(addRowAfter)}</div>,
260
- },
261
- {
262
- id: 'editor.table.removeColumns',
263
- title: formatMessage(messages.removeColumns, {
264
- 0: numberOfColumns,
265
- }),
266
- onClick: (state: EditorState, dispatch?: CommandDispatch, view?: EditorView) => {
267
- const selectionRect = getClosestSelectionRect(state);
268
- if (selectionRect) {
269
- deleteColumnsWithAnalytics(
270
- editorAnalyticsAPI,
271
- api,
272
- isTableScalingEnabled,
273
- isTableFixedColumnWidthsOptionEnabled,
274
- shouldUseIncreasedScalingPercent,
275
- isCommentEditor,
276
- )(INPUT_METHOD.FLOATING_TB, selectionRect)(state, dispatch, view);
277
- }
278
- return true;
279
- },
280
- onFocus: highlightColumnsHandler,
281
- onBlur: clearHoverSelection(),
282
- onMouseOver: highlightColumnsHandler,
283
- onMouseLeave: clearHoverSelection(),
284
- selected: false,
285
- disabled: false,
286
- },
287
- {
288
- id: 'editor.table.removeRows',
289
- title: formatMessage(messages.removeRows, {
290
- 0: numberOfRows,
291
- }),
292
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
293
- const selectionRect = getClosestSelectionRect(state);
294
- if (selectionRect) {
295
- deleteRowsWithAnalytics(editorAnalyticsAPI)(
296
- INPUT_METHOD.FLOATING_TB,
297
- selectionRect,
298
- false,
299
- )(state, dispatch);
300
- }
301
- return true;
302
- },
303
- onFocus: highlightRowsHandler,
304
- onBlur: clearHoverSelection(),
305
- onMouseOver: highlightRowsHandler,
306
- onMouseLeave: clearHoverSelection(),
307
- selected: false,
308
- disabled: false,
309
- },
310
- ];
311
-
312
- if (pluginState.pluginConfig.allowMergeCells) {
313
- options.push(
314
- {
315
- id: 'editor.table.mergeCells',
316
- title: formatMessage(messages.mergeCells),
317
- onClick: mergeCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
318
- selected: false,
319
- disabled: !canMergeCells(editorState.tr),
320
- },
321
- {
322
- id: 'editor.table.splitCell',
323
- title: formatMessage(messages.splitCell),
324
- onClick: splitCellWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.FLOATING_TB),
325
- selected: false,
326
- disabled: !splitCell(editorState),
327
- },
328
- );
329
- }
330
-
331
- if (pluginState?.pluginConfig?.allowDistributeColumns) {
332
- const newResizeStateWithAnalytics = editorView
333
- ? getNewResizeStateFromSelectedColumns(
334
- initialSelectionRect,
335
- editorState,
336
- editorView.domAtPos.bind(editorView),
337
- getEditorContainerWidth,
338
- isTableScalingEnabled,
339
- isTableFixedColumnWidthsOptionEnabled,
340
- isCommentEditor,
341
- )
342
- : undefined;
343
- const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
344
-
345
- const distributeColumnWidths: Command = (state, dispatch) => {
346
- if (newResizeStateWithAnalytics) {
347
- distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI, api)(
348
- INPUT_METHOD.FLOATING_TB,
349
- newResizeStateWithAnalytics,
350
- )(state, dispatch);
351
- return true;
352
- }
353
- return false;
354
- };
355
-
356
- options.push({
357
- id: 'editor.table.distributeColumns',
358
- title: formatMessage(messages.distributeColumns),
359
- onClick: distributeColumnWidths,
360
- selected: false,
361
- disabled: !wouldChange,
362
- });
363
- }
364
-
365
- if (pluginState?.pluginConfig?.allowColumnSorting) {
366
- const hasMergedCellsInTable = getMergedCellsPositions(editorState.tr).length > 0;
367
- const warning = hasMergedCellsInTable ? formatMessage(messages.canNotSortTable) : undefined;
368
-
369
- options.push({
370
- id: 'editor.table.sortColumnAsc',
371
- title: formatMessage(messages.sortColumnASC),
372
- onMouseOver: (state: EditorState, dispatch?: CommandDispatch) => {
373
- if (getMergedCellsPositions(state.tr).length !== 0) {
374
- hoverMergedCells()(state, dispatch);
375
- return true;
376
- }
377
- return false;
378
- },
379
- onMouseOut: (state: EditorState, dispatch?: CommandDispatch) => {
380
- clearHoverSelection()(state, dispatch);
381
- return true;
382
- },
383
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
384
- sortColumnWithAnalytics(editorAnalyticsAPI)(
385
- INPUT_METHOD.FLOATING_TB,
386
- initialSelectionRect.left,
387
- SortOrder.ASC,
388
- )(state, dispatch);
389
- return true;
390
- },
391
- selected: false,
392
- disabled: hasMergedCellsInTable,
393
- tooltip: warning,
394
- });
395
-
396
- options.push({
397
- id: 'editor.table.sortColumnDesc',
398
- title: formatMessage(messages.sortColumnDESC),
399
- onMouseOver: (state: EditorState, dispatch?: CommandDispatch) => {
400
- if (getMergedCellsPositions(state.tr).length !== 0) {
401
- hoverMergedCells()(state, dispatch);
402
- return true;
403
- }
404
- return false;
405
- },
406
- onMouseOut: (state: EditorState, dispatch?: CommandDispatch) => {
407
- clearHoverSelection()(state, dispatch);
408
- return true;
409
- },
410
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
411
- sortColumnWithAnalytics(editorAnalyticsAPI)(
412
- INPUT_METHOD.FLOATING_TB,
413
- initialSelectionRect.left,
414
- SortOrder.DESC,
415
- )(state, dispatch);
416
- return true;
417
- },
418
- selected: false,
419
- disabled: hasMergedCellsInTable,
420
- tooltip: warning,
421
- });
422
- }
423
-
424
- options.push({
425
- id: 'editor.table.clearCells',
426
- title: formatMessage(messages.clearCells, {
427
- 0: Math.max(numberOfColumns, numberOfRows),
428
- }),
429
- onClick: (state: EditorState, dispatch?: CommandDispatch) => {
430
- const { targetCellPosition } = getPluginState(state);
431
- emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(
432
- INPUT_METHOD.FLOATING_TB,
433
- targetCellPosition,
434
- )(state, dispatch);
435
- return true;
436
- },
437
- selected: false,
438
- disabled: false,
439
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
440
- elemAfter: <div css={shortcutStyle}>{tooltip(backspace)}</div>,
441
- });
442
-
443
- return {
444
- id: 'editor.table.cellOptions',
445
- testId: 'cell_options',
446
- type: 'dropdown',
447
- title: formatMessage(messages.cellOptions),
448
- options,
449
- // Increased dropdown item width to prevent labels from being truncated
450
- dropdownWidth: 230,
451
- showSelected: false,
452
- };
453
- };
454
-
455
- export const getClosestSelectionRect = (state: EditorState): Rect | undefined => {
456
- const selection = state.selection;
457
- return isSelectionType(selection, 'cell')
458
- ? // Ignored via go/ees005
459
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
460
- getSelectionRect(selection)!
461
- : findCellRectClosestToPos(selection.$from);
462
- };
463
-
464
- const getClosestSelectionOrTableRect = (state: EditorState): Rect | undefined => {
465
- const selection = state.selection;
466
- const tableObject = findTable(state.selection);
467
- if (!tableObject) {
468
- return;
469
- }
470
- const map = TableMap.get(tableObject.node);
471
- const tableRect = new Rect(0, 0, map.width, map.height);
472
-
473
- // Ignored via go/ees005
474
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
475
- return isSelectionType(selection, 'cell') ? getSelectionRect(selection)! : tableRect;
476
- };
477
-
478
- export const getToolbarConfig =
479
- (
480
- getEditorContainerWidth: GetEditorContainerWidth,
481
- api: PluginInjectionAPI | undefined | null,
482
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
483
- getEditorView: () => EditorView | null,
484
- options?: TablePluginOptions,
485
- isTableFixedColumnWidthsOptionEnabled = false,
486
- shouldUseIncreasedScalingPercent = false,
487
- ) =>
488
- (config: PluginConfig): FloatingToolbarHandler =>
489
- (state, intl) => {
490
- const tableObject = findTable(state.selection);
491
- const pluginState = getPluginState(state);
492
- const resizeState = tableResizingPluginKey.getState(state);
493
- const tableWidthState = tableWidthPluginKey.getState(state);
494
- const isTableScalingEnabled = options?.isTableScalingEnabled || false;
495
- const nodeType = state.schema.nodes.table;
496
- const toolbarTitle = 'Table floating controls';
497
- const isNewEditorToolbarEnabled = areToolbarFlagsEnabled();
498
-
499
- if (editorExperiment('platform_editor_controls', 'variant1')) {
500
- let isDragHandleMenuOpened = false;
501
- let isTableRowOrColumnDragged = false;
502
- if (options?.dragAndDropEnabled) {
503
- const { isDragMenuOpen = false, isDragging = false } = getDragDropPluginState(state);
504
- isDragHandleMenuOpened = isDragMenuOpen;
505
- isTableRowOrColumnDragged = isDragging;
506
- }
507
-
508
- const isTableOrColumnResizing = !!(resizeState?.dragging || tableWidthState?.resizing);
509
- const isTableMenuOpened = pluginState.isContextualMenuOpen || isDragHandleMenuOpened;
510
- const isTableState =
511
- isTableRowOrColumnDragged || isTableOrColumnResizing || isTableMenuOpened;
512
- const isViewMode = api?.editorViewMode?.sharedState.currentState()?.mode === 'view';
513
-
514
- // Note: when focus is in codeblocks, pluginState.editorHasFocus is false, so the codeblocks toolbar
515
- // won't be suppressed.
516
- const shouldSuppressAllToolbars = isTableState && pluginState.editorHasFocus && !isViewMode;
517
- if (shouldSuppressAllToolbars) {
518
- return {
519
- title: toolbarTitle,
520
- items: [],
521
- nodeType,
522
- __suppressAllToolbars: true,
523
- };
524
- }
525
- }
526
-
527
- // We don't want to show floating toolbar while resizing the table
528
- const isWidthResizing = tableWidthState?.resizing;
529
-
530
- if (tableObject && pluginState.editorHasFocus && !isWidthResizing) {
531
- const isNested = pluginState.tablePos && isTableNested(state, pluginState.tablePos);
532
- const isTableScalingWithFixedColumnWidthsOptionShown =
533
- isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && !isNested;
534
- const areTableColumWidthsFixed = tableObject.node.attrs.displayMode === 'fixed';
535
- const editorView = getEditorView();
536
-
537
- const getDomRef = (editorView: EditorView) => {
538
- let element: HTMLElement | undefined;
539
- const domAtPos = editorView.domAtPos.bind(editorView);
540
- const parent = findParentDomRefOfType(nodeType, domAtPos)(state.selection);
541
- if (parent) {
542
- const tableRef =
543
- // Ignored via go/ees005
544
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
545
- (parent as HTMLElement).querySelector<HTMLTableElement>('table') || undefined;
546
- if (tableRef) {
547
- element =
548
- closestElement(tableRef, `.${TableCssClassName.TABLE_NODE_WRAPPER}`) || undefined;
549
- }
550
- }
551
-
552
- return element;
553
- };
554
-
555
- const menu = getToolbarMenuConfig(
556
- config,
557
- pluginState,
558
- intl,
559
- editorAnalyticsAPI,
560
- isTableScalingWithFixedColumnWidthsOptionShown,
561
- areTableColumWidthsFixed,
562
- );
563
-
564
- const alignmentMenu =
565
- config.allowTableAlignment && !isNested
566
- ? getAlignmentOptionsConfig(
567
- state,
568
- intl,
569
- editorAnalyticsAPI,
570
- getEditorContainerWidth,
571
- editorView,
572
- shouldUseIncreasedScalingPercent,
573
- options?.fullWidthEnabled,
574
- options?.isCommentEditor,
575
- )
576
- : [];
577
-
578
- const cellItems = pluginState.isDragAndDropEnabled
579
- ? []
580
- : getCellItems(
581
- state,
582
- editorView,
583
- intl,
584
- getEditorContainerWidth,
585
- api,
586
- editorAnalyticsAPI,
587
- isTableScalingEnabled,
588
- isTableFixedColumnWidthsOptionEnabled,
589
- shouldUseIncreasedScalingPercent,
590
- options?.isCommentEditor,
591
- );
592
-
593
- const columnSettingsItems = pluginState.isDragAndDropEnabled
594
- ? getColumnSettingItems(
595
- state,
596
- editorView,
597
- intl,
598
- getEditorContainerWidth,
599
- api,
600
- editorAnalyticsAPI,
601
- isTableScalingEnabled,
602
- isTableFixedColumnWidthsOptionEnabled,
603
- options?.isCommentEditor,
604
- )
605
- : [];
606
-
607
- const colorPicker = !isNewEditorToolbarEnabled
608
- ? getColorPicker(state, menu, intl, editorAnalyticsAPI, getEditorView)
609
- : [];
610
-
611
- // Check if we need to show confirm dialog for delete button
612
- let confirmDialog;
613
-
614
- if (isReferencedSource(state, tableObject.node)) {
615
- const localSourceName = intl.formatMessage(messages.unnamedSource);
616
-
617
- confirmDialog = (): ConfirmDialogOptions => ({
618
- title: intl.formatMessage(messages.deleteElementTitle),
619
- okButtonLabel: intl.formatMessage(messages.confirmDeleteLinkedModalOKButton),
620
- message: intl.formatMessage(messages.confirmDeleteLinkedModalMessage, {
621
- nodeName: getNodeName(state, tableObject.node) || localSourceName,
622
- }),
623
- messagePrefix: intl.formatMessage(messages.confirmDeleteLinkedModalMessagePrefix),
624
- isReferentialityDialog: true,
625
- getChildrenInfo: () => getChildrenInfo(state, tableObject.node),
626
- checkboxLabel: intl.formatMessage(messages.confirmModalCheckboxLabel),
627
- onConfirm: (isChecked = false) => clickWithCheckboxHandler(isChecked, tableObject.node),
628
- });
629
- }
630
-
631
- const deleteButton = {
632
- id: 'editor.table.delete',
633
- type: 'button' as const,
634
- appearance: 'danger',
635
- icon: DeleteIcon,
636
- onClick: deleteTableWithAnalytics(editorAnalyticsAPI),
637
- disabled: !!resizeState && !!resizeState.dragging,
638
- onMouseEnter: hoverTable(true),
639
- onFocus: hoverTable(true),
640
- onBlur: clearHoverSelection(),
641
- onMouseLeave: clearHoverSelection(),
642
- title: intl.formatMessage(commonMessages.remove),
643
- focusEditoronEnter: true,
644
- confirmDialog,
645
- };
646
-
647
- const copyButton = {
648
- type: 'copy-button',
649
- supportsViewMode: true,
650
- items: [
651
- {
652
- state,
653
- formatMessage: intl.formatMessage,
654
- nodeType,
655
- onMouseEnter: hoverTable(false, true),
656
- onMouseLeave: clearHoverSelection(),
657
- onFocus: hoverTable(false, true),
658
- onBlur: clearHoverSelection(),
659
- },
660
- ],
661
- };
662
-
663
- const isNestedTable =
664
- fg('platform_editor_use_nested_table_pm_nodes') && isSelectionTableNestedInTable(state);
665
-
666
- const hoverTableProps = (isInDanger?: boolean, isSelected?: boolean) => ({
667
- onMouseEnter: hoverTable(isInDanger, isSelected),
668
- onMouseLeave: clearHoverSelection(),
669
- onFocus: hoverTable(isInDanger, isSelected),
670
- onBlur: clearHoverSelection(),
671
- });
672
-
673
- // testId is required to show focus on trigger button on ESC key press
674
- // see hideOnEsc in platform/packages/editor/editor-plugin-floating-toolbar/src/ui/Dropdown.tsx
675
- const overflowDropdownTestId = 'table-overflow-dropdown-trigger';
676
-
677
- const extensionState = api?.extension?.sharedState?.currentState();
678
- const extensionApi = api?.extension?.actions.api();
679
-
680
- return {
681
- title: toolbarTitle,
682
- getDomRef,
683
- nodeType,
684
- offset: [0, 18],
685
- absoluteOffset: { top: -6 },
686
- zIndex: akEditorFloatingPanelZIndex + 1, // Place the context menu slightly above the others
687
- items: [
688
- menu,
689
- ...(!isNewEditorToolbarEnabled ? [separator(menu.hidden)] : []),
690
- ...alignmentMenu,
691
- ...(!isNewEditorToolbarEnabled ? [separator(alignmentMenu.length === 0)] : []),
692
- ...cellItems,
693
- ...columnSettingsItems,
694
- ...colorPicker,
695
- ...((!isNewEditorToolbarEnabled
696
- ? ([
697
- {
698
- type: 'extensions-placeholder',
699
- separator: 'end',
700
- },
701
- copyButton,
702
- { type: 'separator' },
703
- deleteButton,
704
- ] as Array<FloatingToolbarItem<Command>>)
705
- : [
706
- isNewEditorToolbarEnabled && { type: 'separator', fullHeight: true },
707
- {
708
- type: 'overflow-dropdown',
709
- testId: overflowDropdownTestId,
710
- dropdownWidth: 220,
711
- options: [
712
- {
713
- type: 'custom',
714
- fallback: [],
715
- render: (editorView, dropdownOptions) => {
716
- if (!editorView) {
717
- return null;
718
- }
719
-
720
- if (!extensionApi || !extensionState?.extensionProvider) {
721
- return null;
722
- }
723
-
724
- return (
725
- <DropdownMenuExtensionItems
726
- node={tableObject.node}
727
- editorView={editorView}
728
- extension={{
729
- extensionProvider: extensionState?.extensionProvider
730
- ? Promise.resolve(extensionState.extensionProvider)
731
- : undefined,
732
- extensionApi: extensionApi,
733
- }}
734
- dropdownOptions={dropdownOptions}
735
- disabled={(key: string) => {
736
- return (
737
- isNestedTable &&
738
- ['referentiality:connections', 'chart:insert-chart'].includes(key)
739
- );
740
- }}
741
- />
742
- );
743
- },
744
- },
745
- ...(extensionApi &&
746
- extensionState?.extensionProvider &&
747
- !areToolbarFlagsEnabled()
748
- ? [{ type: 'separator' }]
749
- : []),
750
- {
751
- title: intl.formatMessage(commonMessages.copyToClipboard),
752
- onClick: () => {
753
- api?.core?.actions.execute(
754
- // @ts-ignore
755
- api?.floatingToolbar?.commands.copyNode(
756
- nodeType,
757
- INPUT_METHOD.FLOATING_TB,
758
- ),
759
- );
760
- return true;
761
- },
762
- icon: <CopyIcon label={intl.formatMessage(commonMessages.copyToClipboard)} />,
763
- ...hoverTableProps(false, true),
764
- },
765
- {
766
- title: intl.formatMessage(commonMessages.delete),
767
- onClick: deleteTableWithAnalytics(editorAnalyticsAPI),
768
- icon: <DeleteIcon label={intl.formatMessage(commonMessages.delete)} />,
769
- ...hoverTableProps(true),
770
- },
771
- ],
772
- },
773
- ]) as Array<FloatingToolbarItem<Command>>),
774
- ],
775
- scrollable: true,
776
- };
777
- }
778
-
779
- return;
780
- };
781
-
782
- const separator = (hidden?: boolean): FloatingToolbarItem<Command> => {
783
- return {
784
- type: 'separator',
785
- hidden: hidden,
786
- };
787
- };
788
-
789
- const getCellItems = (
790
- state: EditorState,
791
- view: EditorView | null,
792
- { formatMessage }: ToolbarMenuContext,
793
- getEditorContainerWidth: GetEditorContainerWidth,
794
- api: PluginInjectionAPI | undefined | null,
795
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
796
- isTableScalingEnabled = false,
797
- isTableFixedColumnWidthsOptionEnabled = false,
798
- shouldUseIncreasedScalingPercent = false,
799
- isCommentEditor = false,
800
- ): Array<FloatingToolbarItem<Command>> => {
801
- const initialSelectionRect = getClosestSelectionRect(state);
802
- if (initialSelectionRect) {
803
- const cellOptions = getToolbarCellOptionsConfig(
804
- state,
805
- view,
806
- initialSelectionRect,
807
- { formatMessage },
808
- getEditorContainerWidth,
809
- api,
810
- editorAnalyticsAPI,
811
- isTableScalingEnabled,
812
- isTableFixedColumnWidthsOptionEnabled,
813
- shouldUseIncreasedScalingPercent,
814
- isCommentEditor,
815
- );
816
- // Ignored via go/ees005
817
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
818
- return [cellOptions, separator(cellOptions.hidden!)];
819
- }
820
- return [];
821
- };
822
-
823
- const getDistributeConfig =
824
- (
825
- getEditorContainerWidth: GetEditorContainerWidth,
826
- api: PluginInjectionAPI | undefined | null,
827
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
828
- isTableScalingEnabled = false,
829
- isTableFixedColumnWidthsOptionEnabled = false,
830
- isCommentEditor = false,
831
- ): Command =>
832
- (state, dispatch, editorView) => {
833
- const selectionOrTableRect = getClosestSelectionOrTableRect(state);
834
- if (!editorView || !selectionOrTableRect) {
835
- return false;
836
- }
837
-
838
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
839
- selectionOrTableRect,
840
- state,
841
- editorView.domAtPos.bind(editorView),
842
- getEditorContainerWidth,
843
- isTableScalingEnabled,
844
- isTableFixedColumnWidthsOptionEnabled,
845
- isCommentEditor,
846
- );
847
-
848
- if (newResizeStateWithAnalytics) {
849
- distributeColumnsWidthsWithAnalytics(editorAnalyticsAPI, api)(
850
- INPUT_METHOD.FLOATING_TB,
851
- newResizeStateWithAnalytics,
852
- )(state, dispatch);
853
- return true;
854
- }
855
- return false;
856
- };
857
-
858
- // this create the button group for distribute column and also fixed column width
859
- // fixed column button should be in this function call in the future
860
- const getColumnSettingItems = (
861
- editorState: EditorState,
862
- editorView: EditorView | undefined | null,
863
- { formatMessage }: ToolbarMenuContext,
864
- getEditorContainerWidth: GetEditorContainerWidth,
865
- api: PluginInjectionAPI | undefined | null,
866
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
867
- isTableScalingEnabled = false,
868
- isTableFixedColumnWidthsOptionEnabled = false,
869
- isCommentEditor = false,
870
- ): Array<FloatingToolbarItem<Command>> => {
871
- const pluginState = getPluginState(editorState);
872
- const selectionOrTableRect = getClosestSelectionOrTableRect(editorState);
873
- if (!selectionOrTableRect || !editorView) {
874
- return [];
875
- }
876
- const newResizeStateWithAnalytics = getNewResizeStateFromSelectedColumns(
877
- selectionOrTableRect,
878
- editorState,
879
- editorView.domAtPos.bind(editorView),
880
- getEditorContainerWidth,
881
- isTableScalingEnabled,
882
- isTableFixedColumnWidthsOptionEnabled,
883
- isCommentEditor,
884
- );
885
-
886
- const wouldChange = newResizeStateWithAnalytics?.changed ?? false;
887
-
888
- const items: Array<FloatingToolbarItem<Command>> = [];
889
-
890
- if (pluginState?.pluginConfig?.allowDistributeColumns && pluginState.isDragAndDropEnabled) {
891
- items.push({
892
- id: 'editor.table.distributeColumns',
893
- type: 'button',
894
- title: formatMessage(messages.distributeColumns),
895
- icon: () => (
896
- <TableColumnsDistributeIcon
897
- LEGACY_fallbackIcon={DistributeColumnIcon}
898
- spacing={'spacious'}
899
- label={''}
900
- />
901
- ),
902
- onClick: (state, dispatch, view) =>
903
- getDistributeConfig(
904
- getEditorContainerWidth,
905
- api,
906
- editorAnalyticsAPI,
907
- isTableScalingEnabled,
908
- isTableFixedColumnWidthsOptionEnabled,
909
- isCommentEditor,
910
- )(state, dispatch, view),
911
- disabled: !wouldChange,
912
- });
913
- }
914
-
915
- if (items.length !== 0 && !areToolbarFlagsEnabled()) {
916
- items.push({
917
- type: 'separator',
918
- });
919
- }
920
-
921
- return items;
922
- };
923
-
924
- const getColorPicker = (
925
- state: EditorState,
926
- menu: FloatingToolbarItem<Command>,
927
- { formatMessage }: ToolbarMenuContext,
928
- editorAnalyticsAPI: EditorAnalyticsAPI | null | undefined,
929
- getEditorView: () => EditorView | null,
930
- ): Array<FloatingToolbarItem<Command>> => {
931
- const { targetCellPosition, pluginConfig } = getPluginState(state);
932
- if (!pluginConfig.allowBackgroundColor) {
933
- return [];
934
- }
935
- const node = targetCellPosition ? state.doc.nodeAt(targetCellPosition) : undefined;
936
- const currentBackground = node?.attrs?.background || '#ffffff';
937
- const defaultPalette = cellBackgroundColorPalette.find(
938
- (item) => item.value === currentBackground,
939
- ) || {
940
- label: 'Custom',
941
- value: currentBackground,
942
- border: DEFAULT_BORDER_COLOR,
943
- };
944
-
945
- return [
946
- {
947
- id: 'editor.table.colorPicker',
948
- title: formatMessage(messages.cellBackground),
949
- type: 'select',
950
- isAriaExpanded: true,
951
- selectType: 'color',
952
- defaultValue: defaultPalette,
953
- options: cellBackgroundColorPalette,
954
- returnEscToButton: true,
955
- // Ignored via go/ees005
956
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
957
- onChange: (option: any) =>
958
- setColorWithAnalytics(editorAnalyticsAPI)(
959
- INPUT_METHOD.FLOATING_TB,
960
- option.value,
961
- getEditorView(),
962
- ),
963
- },
964
- separator(menu.hidden),
965
- ];
966
- };
967
-
968
- const clickWithCheckboxHandler =
969
- (
970
- isChecked: boolean,
971
- node?: PMNode,
972
- editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null,
973
- ): Command =>
974
- (state, dispatch) => {
975
- if (!node) {
976
- return false;
977
- }
978
-
979
- if (!isChecked) {
980
- return deleteTableWithAnalytics(editorAnalyticsAPI)(state, dispatch);
981
- } else {
982
- removeDescendantNodes(node)(state, dispatch);
983
- }
984
- return true;
985
- };
986
-
987
- const highlightRowsHandler = (state: EditorState, dispatch?: CommandDispatch) => {
988
- const selectionRect = getClosestSelectionRect(state);
989
- if (selectionRect) {
990
- hoverRows(getSelectedRowIndexes(selectionRect), true)(state, dispatch);
991
- return true;
992
- }
993
- return false;
994
- };
995
-
996
- const highlightColumnsHandler = (state: EditorState, dispatch?: CommandDispatch) => {
997
- const selectionRect = getClosestSelectionRect(state);
998
- if (selectionRect) {
999
- hoverColumns(getSelectedColumnIndexes(selectionRect), true)(state, dispatch);
1000
- return true;
1001
- }
1002
- return false;
1003
- };
1004
-
1005
- type AlignmentIcon = {
1006
- id?: string;
1007
- value: AlignmentOptions;
1008
- icon: Icon;
1009
- };
1010
-
1011
- const getAlignmentOptionsConfig = (
1012
- editorState: EditorState,
1013
- { formatMessage }: ToolbarMenuContext,
1014
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
1015
- getEditorContainerWidth: GetEditorContainerWidth,
1016
- editorView: EditorView | null,
1017
- shouldUseIncreasedScalingPercent: boolean,
1018
- isFullWidthEditor?: boolean,
1019
- isCommentEditor?: boolean,
1020
- ): Array<FloatingToolbarDropdown<Command>> => {
1021
- const tableObject = findTable(editorState.selection);
1022
-
1023
- if (!tableObject) {
1024
- return [];
1025
- }
1026
-
1027
- const alignmentIcons: AlignmentIcon[] = [
1028
- {
1029
- id: 'editor.table.alignLeft',
1030
- value: 'align-start',
1031
- icon: () => (
1032
- <AlignImageLeftIcon
1033
- color="currentColor"
1034
- spacing="spacious"
1035
- label="table-align-start-icon"
1036
- LEGACY_fallbackIcon={EditorAlignImageLeft}
1037
- />
1038
- ),
1039
- },
1040
- {
1041
- id: 'editor.table.alignCenter',
1042
- value: 'center',
1043
- icon: () => (
1044
- <AlignImageCenterIcon
1045
- color="currentColor"
1046
- spacing="spacious"
1047
- label="table-align-center-icon"
1048
- LEGACY_fallbackIcon={EditorAlignImageCenter}
1049
- />
1050
- ),
1051
- },
1052
- ];
1053
-
1054
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1055
- const layoutToMessages: Record<AlignmentOptions, any> = {
1056
- center: messages.alignTableCenter,
1057
- 'align-start': messages.alignTableLeft,
1058
- };
1059
-
1060
- const alignmentButtons = alignmentIcons.map<FloatingToolbarItem<Command>>((alignmentIcon) => {
1061
- const { id, value, icon } = alignmentIcon;
1062
- const currentLayout = tableObject.node.attrs.layout;
1063
-
1064
- return {
1065
- id: id,
1066
- type: 'button',
1067
- icon: icon,
1068
- title: formatMessage(layoutToMessages[value]),
1069
- selected: normaliseAlignment(currentLayout) === value,
1070
- onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI, isCommentEditor || false)(
1071
- value,
1072
- currentLayout,
1073
- INPUT_METHOD.FLOATING_TB,
1074
- CHANGE_ALIGNMENT_REASON.TOOLBAR_OPTION_CHANGED,
1075
- ),
1076
- ...(isLayoutOptionDisabled(
1077
- tableObject.node,
1078
- getEditorContainerWidth,
1079
- editorView,
1080
- shouldUseIncreasedScalingPercent,
1081
- isFullWidthEditor,
1082
- ) && {
1083
- disabled: value !== 'center',
1084
- }),
1085
- };
1086
- });
1087
-
1088
- const alignmentItemOptions: DropdownOptions<Command> = {
1089
- render: (props) => {
1090
- return (
1091
- <FloatingAlignmentButtons
1092
- alignmentButtons={alignmentButtons}
1093
- // Ignored via go/ees005
1094
- // eslint-disable-next-line react/jsx-props-no-spreading
1095
- {...props}
1096
- />
1097
- );
1098
- },
1099
- width: 74,
1100
- height: 32,
1101
- };
1102
-
1103
- const selectedAlignmentIcon = getSelectedAlignmentIcon(alignmentIcons, tableObject.node);
1104
-
1105
- const alignmentToolbarItem: Array<FloatingToolbarDropdown<Command>> = [
1106
- {
1107
- id: 'table-layout',
1108
- testId: 'table-layout-dropdown',
1109
- type: 'dropdown',
1110
- options: alignmentItemOptions,
1111
- title: formatMessage(messages.tableAlignmentOptions),
1112
- icon: selectedAlignmentIcon?.icon,
1113
- },
1114
- ];
1115
-
1116
- return alignmentToolbarItem;
1117
- };
1118
-
1119
- const getSelectedAlignmentIcon = (alignmentIcons: AlignmentIcon[], selectedNode: PMNode) => {
1120
- const selectedAlignment = selectedNode.attrs.layout;
1121
-
1122
- return alignmentIcons.find((icon) => icon.value === normaliseAlignment(selectedAlignment));
1123
- };
1124
-
1125
- const isLayoutOptionDisabled = (
1126
- selectedNode: PMNode,
1127
- getEditorContainerWidth: GetEditorContainerWidth,
1128
- editorView: EditorView | null,
1129
- shouldUseIncreasedScalingPercent: boolean,
1130
- isFullWidthEditor: boolean | undefined,
1131
- ) => {
1132
- const { lineLength } = getEditorContainerWidth();
1133
- let tableContainerWidth = getTableContainerWidth(selectedNode);
1134
-
1135
- // table may be scaled, use the scale percent to calculate the table width
1136
- if (editorView) {
1137
- const tableWrapperWidth = tableContainerWidth;
1138
- const scalePercent = getStaticTableScalingPercent(
1139
- selectedNode,
1140
- tableWrapperWidth,
1141
- shouldUseIncreasedScalingPercent,
1142
- );
1143
- tableContainerWidth = tableContainerWidth * scalePercent;
1144
- }
1145
-
1146
- // If fixed-width editor, we disable 'left-alignment' when table width is 760px.
1147
- // tableContainerWidth +1 here because tableContainerWidth is 759 in fixed-width editor
1148
- if (selectedNode && !isFullWidthEditor && lineLength && tableContainerWidth + 1 >= lineLength) {
1149
- return true;
1150
- }
1151
-
1152
- return false;
1153
- };