@atlaskit/editor-plugin-table 7.16.11 → 7.16.13
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.
- package/.eslintrc.js +3 -3
- package/CHANGELOG.md +16 -0
- package/dist/cjs/commands/misc.js +3 -3
- package/dist/cjs/nodeviews/TableCell.js +10 -10
- package/dist/cjs/nodeviews/TableContainer.js +83 -27
- package/dist/cjs/nodeviews/TableResizer.js +40 -19
- package/dist/cjs/nodeviews/TableRow.js +23 -23
- package/dist/cjs/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/cjs/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/cjs/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/cjs/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/cjs/ui/common-styles.js +13 -13
- package/dist/cjs/ui/ui-styles.js +25 -25
- package/dist/cjs/utils/guidelines.js +7 -4
- package/dist/cjs/utils/merged-cells.js +3 -3
- package/dist/cjs/utils/snapping.js +7 -8
- package/dist/es2019/commands/misc.js +3 -3
- package/dist/es2019/nodeviews/TableContainer.js +70 -9
- package/dist/es2019/nodeviews/TableResizer.js +42 -21
- package/dist/es2019/nodeviews/TableRow.js +21 -21
- package/dist/es2019/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/es2019/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/es2019/ui/FloatingContextualMenu/styles.js +47 -47
- package/dist/es2019/ui/FloatingDragMenu/styles.js +30 -30
- package/dist/es2019/ui/common-styles.js +802 -816
- package/dist/es2019/ui/ui-styles.js +665 -678
- package/dist/es2019/utils/guidelines.js +5 -2
- package/dist/es2019/utils/merged-cells.js +3 -3
- package/dist/es2019/utils/snapping.js +5 -6
- package/dist/esm/commands/misc.js +3 -3
- package/dist/esm/nodeviews/TableCell.js +10 -10
- package/dist/esm/nodeviews/TableContainer.js +85 -29
- package/dist/esm/nodeviews/TableResizer.js +42 -21
- package/dist/esm/nodeviews/TableRow.js +23 -23
- package/dist/esm/pm-plugins/table-resizing/plugin.js +3 -3
- package/dist/esm/pm-plugins/table-resizing/utils/resize-state.js +4 -4
- package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +3 -3
- package/dist/esm/ui/FloatingContextualMenu/styles.js +1 -1
- package/dist/esm/ui/FloatingDragMenu/styles.js +1 -1
- package/dist/esm/ui/common-styles.js +13 -13
- package/dist/esm/ui/ui-styles.js +25 -25
- package/dist/esm/utils/guidelines.js +6 -3
- package/dist/esm/utils/merged-cells.js +3 -3
- package/dist/esm/utils/snapping.js +6 -7
- package/dist/types/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types/utils/guidelines.d.ts +2 -1
- package/dist/types/utils/snapping.d.ts +3 -2
- package/dist/types-ts4.5/nodeviews/TableResizer.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/decorations/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/autoscrollers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/drag-and-drop/utils/getDragBehaviour.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-resizing/utils/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/ColumnResizeWidget/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.d.ts +1 -1
- package/dist/types-ts4.5/ui/FloatingToolbarLabel/FloatingToolbarLabel.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.d.ts +1 -1
- package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/index.d.ts +1 -1
- package/dist/types-ts4.5/ui/icons/DragHandleDisabledIcon.d.ts +1 -1
- package/dist/types-ts4.5/utils/guidelines.d.ts +2 -1
- package/dist/types-ts4.5/utils/snapping.d.ts +3 -2
- package/docs/0-intro.tsx +9 -7
- package/package.json +3 -3
- package/report.api.md +67 -66
- package/src/commands/clear.ts +36 -44
- package/src/commands/collapse.ts +8 -8
- package/src/commands/column-resize.ts +412 -452
- package/src/commands/delete.ts +14 -14
- package/src/commands/display-mode.ts +10 -11
- package/src/commands/go-to-next-cell.ts +48 -54
- package/src/commands/hover.ts +210 -227
- package/src/commands/index.ts +35 -35
- package/src/commands/insert.ts +208 -235
- package/src/commands/misc.ts +655 -748
- package/src/commands/referentiality.ts +9 -9
- package/src/commands/selection.ts +433 -563
- package/src/commands/sort.ts +68 -86
- package/src/commands/split-cell.ts +14 -14
- package/src/commands/toggle.ts +69 -67
- package/src/commands-with-analytics.ts +570 -639
- package/src/create-plugin-config.ts +13 -13
- package/src/event-handlers.ts +513 -612
- package/src/handlers.ts +120 -133
- package/src/nodeviews/ExternalDropTargets.tsx +68 -73
- package/src/nodeviews/OverflowShadowsObserver.ts +148 -157
- package/src/nodeviews/TableCell.ts +47 -54
- package/src/nodeviews/TableComponent.tsx +1018 -1112
- package/src/nodeviews/TableComponentWithSharedState.tsx +91 -94
- package/src/nodeviews/TableContainer.tsx +384 -340
- package/src/nodeviews/TableNodeViewBase.ts +19 -24
- package/src/nodeviews/TableResizer.tsx +642 -653
- package/src/nodeviews/TableRow.ts +580 -629
- package/src/nodeviews/TableStickyScrollbar.ts +173 -190
- package/src/nodeviews/__mocks__/OverflowShadowsObserver.ts +8 -8
- package/src/nodeviews/__mocks__/OverridableMock.ts +14 -15
- package/src/nodeviews/table.tsx +345 -375
- package/src/nodeviews/types.ts +21 -24
- package/src/nodeviews/update-overflow-shadows.ts +8 -14
- package/src/plugin.tsx +578 -603
- package/src/pm-plugins/analytics/actions.ts +10 -12
- package/src/pm-plugins/analytics/commands.ts +31 -37
- package/src/pm-plugins/analytics/plugin-factory.ts +4 -2
- package/src/pm-plugins/analytics/plugin-key.ts +1 -3
- package/src/pm-plugins/analytics/plugin.ts +60 -70
- package/src/pm-plugins/analytics/reducer.ts +19 -19
- package/src/pm-plugins/analytics/types.ts +10 -10
- package/src/pm-plugins/analytics/utils/moved-event.ts +38 -38
- package/src/pm-plugins/decorations/plugin.ts +58 -77
- package/src/pm-plugins/decorations/utils/column-controls.ts +59 -71
- package/src/pm-plugins/decorations/utils/column-resizing.ts +50 -57
- package/src/pm-plugins/decorations/utils/compose-decorations.ts +6 -6
- package/src/pm-plugins/decorations/utils/index.ts +3 -6
- package/src/pm-plugins/decorations/utils/types.ts +7 -12
- package/src/pm-plugins/default-table-selection.ts +3 -3
- package/src/pm-plugins/drag-and-drop/actions.ts +25 -25
- package/src/pm-plugins/drag-and-drop/commands-with-analytics.ts +158 -190
- package/src/pm-plugins/drag-and-drop/commands.ts +154 -170
- package/src/pm-plugins/drag-and-drop/consts.ts +4 -5
- package/src/pm-plugins/drag-and-drop/plugin-factory.ts +23 -20
- package/src/pm-plugins/drag-and-drop/plugin-key.ts +1 -3
- package/src/pm-plugins/drag-and-drop/plugin.ts +329 -383
- package/src/pm-plugins/drag-and-drop/reducer.ts +30 -30
- package/src/pm-plugins/drag-and-drop/types.ts +8 -8
- package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +38 -41
- package/src/pm-plugins/drag-and-drop/utils/getDragBehaviour.ts +3 -6
- package/src/pm-plugins/drag-and-drop/utils/monitor.ts +57 -70
- package/src/pm-plugins/keymap.ts +208 -220
- package/src/pm-plugins/main.ts +348 -400
- package/src/pm-plugins/plugin-factory.ts +32 -34
- package/src/pm-plugins/safari-delete-composition-text-issue-workaround.ts +83 -97
- package/src/pm-plugins/sticky-headers/commands.ts +2 -6
- package/src/pm-plugins/sticky-headers/plugin-key.ts +1 -3
- package/src/pm-plugins/sticky-headers/plugin-state.ts +41 -44
- package/src/pm-plugins/sticky-headers/plugin.ts +4 -4
- package/src/pm-plugins/sticky-headers/types.ts +8 -8
- package/src/pm-plugins/sticky-headers/util.ts +10 -10
- package/src/pm-plugins/table-analytics.ts +70 -72
- package/src/pm-plugins/table-local-id.ts +180 -184
- package/src/pm-plugins/table-resizing/commands.ts +72 -85
- package/src/pm-plugins/table-resizing/event-handlers.ts +298 -317
- package/src/pm-plugins/table-resizing/plugin-factory.ts +10 -10
- package/src/pm-plugins/table-resizing/plugin-key.ts +1 -3
- package/src/pm-plugins/table-resizing/plugin.ts +61 -68
- package/src/pm-plugins/table-resizing/reducer.ts +30 -33
- package/src/pm-plugins/table-resizing/utils/colgroup.ts +84 -84
- package/src/pm-plugins/table-resizing/utils/column-state.ts +78 -81
- package/src/pm-plugins/table-resizing/utils/content-width.ts +94 -114
- package/src/pm-plugins/table-resizing/utils/dom.ts +93 -110
- package/src/pm-plugins/table-resizing/utils/index.ts +29 -34
- package/src/pm-plugins/table-resizing/utils/misc.ts +94 -119
- package/src/pm-plugins/table-resizing/utils/resize-column.ts +93 -106
- package/src/pm-plugins/table-resizing/utils/resize-logic.ts +240 -257
- package/src/pm-plugins/table-resizing/utils/resize-state.ts +343 -372
- package/src/pm-plugins/table-resizing/utils/scale-table.ts +202 -207
- package/src/pm-plugins/table-resizing/utils/types.ts +17 -17
- package/src/pm-plugins/table-resizing/utils/unit-to-number.ts +1 -2
- package/src/pm-plugins/table-selection-keymap.ts +25 -51
- package/src/pm-plugins/table-width.ts +191 -204
- package/src/pm-plugins/view-mode-sort/index.ts +223 -227
- package/src/pm-plugins/view-mode-sort/plugin-key.ts +3 -2
- package/src/pm-plugins/view-mode-sort/types.ts +12 -12
- package/src/pm-plugins/view-mode-sort/utils.ts +108 -117
- package/src/reducer.ts +139 -155
- package/src/toolbar.tsx +815 -905
- package/src/transforms/column-width.ts +186 -213
- package/src/transforms/delete-columns.ts +208 -222
- package/src/transforms/delete-rows.ts +117 -121
- package/src/transforms/fix-tables.ts +190 -215
- package/src/transforms/merge.ts +263 -269
- package/src/transforms/replace-table.ts +27 -43
- package/src/transforms/split.ts +65 -75
- package/src/types.ts +421 -427
- package/src/ui/ColumnResizeWidget/index.tsx +40 -47
- package/src/ui/DragHandle/HandleIconComponent.tsx +9 -13
- package/src/ui/DragHandle/index.tsx +221 -250
- package/src/ui/DragPreview/index.tsx +35 -35
- package/src/ui/FloatingAlignmentButtons/FloatingAlignmentButtons.tsx +33 -41
- package/src/ui/FloatingContextualButton/FixedButton.tsx +154 -157
- package/src/ui/FloatingContextualButton/index.tsx +109 -115
- package/src/ui/FloatingContextualButton/styles.ts +43 -46
- package/src/ui/FloatingContextualMenu/ContextualMenu.tsx +634 -694
- package/src/ui/FloatingContextualMenu/index.tsx +83 -101
- package/src/ui/FloatingContextualMenu/styles.ts +57 -65
- package/src/ui/FloatingDeleteButton/DeleteButton.tsx +37 -37
- package/src/ui/FloatingDeleteButton/getPopUpOptions.ts +47 -57
- package/src/ui/FloatingDeleteButton/index.tsx +319 -350
- package/src/ui/FloatingDragMenu/DragMenu.tsx +555 -596
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +152 -162
- package/src/ui/FloatingDragMenu/index.tsx +88 -102
- package/src/ui/FloatingDragMenu/styles.ts +51 -54
- package/src/ui/FloatingInsertButton/InsertButton.tsx +204 -217
- package/src/ui/FloatingInsertButton/getPopupOptions.ts +100 -115
- package/src/ui/FloatingInsertButton/index.tsx +248 -292
- package/src/ui/FloatingToolbarLabel/FloatingToolbarLabel.tsx +24 -29
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +308 -329
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/ColumnDropTarget.tsx +85 -94
- package/src/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +46 -46
- package/src/ui/TableFloatingColumnControls/index.tsx +116 -136
- package/src/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +79 -91
- package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +95 -102
- package/src/ui/TableFloatingControls/CornerControls/index.tsx +1 -4
- package/src/ui/TableFloatingControls/CornerControls/types.ts +8 -8
- package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +50 -50
- package/src/ui/TableFloatingControls/NumberColumn/index.tsx +111 -124
- package/src/ui/TableFloatingControls/RowControls/ClassicControls.tsx +86 -105
- package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +305 -341
- package/src/ui/TableFloatingControls/RowDropTarget/index.tsx +72 -75
- package/src/ui/TableFloatingControls/index.tsx +191 -193
- package/src/ui/TableFullWidthLabel/index.tsx +20 -20
- package/src/ui/common-styles.ts +880 -912
- package/src/ui/consts.ts +29 -74
- package/src/ui/icons/AddColLeftIcon.tsx +33 -39
- package/src/ui/icons/AddColRightIcon.tsx +33 -39
- package/src/ui/icons/AddRowAboveIcon.tsx +16 -22
- package/src/ui/icons/AddRowBelowIcon.tsx +33 -39
- package/src/ui/icons/DisplayModeIcon.tsx +31 -31
- package/src/ui/icons/DragHandleDisabledIcon.tsx +19 -21
- package/src/ui/icons/DragHandleIcon.tsx +12 -12
- package/src/ui/icons/DragInMotionIcon.tsx +45 -52
- package/src/ui/icons/MergeCellsIcon.tsx +22 -28
- package/src/ui/icons/MinimisedHandle.tsx +9 -9
- package/src/ui/icons/SplitCellIcon.tsx +30 -36
- package/src/ui/ui-styles.ts +769 -798
- package/src/utils/alignment.ts +1 -1
- package/src/utils/analytics.ts +192 -208
- package/src/utils/collapse.ts +55 -64
- package/src/utils/column-controls.ts +237 -254
- package/src/utils/create.ts +30 -30
- package/src/utils/decoration.ts +482 -502
- package/src/utils/dom.ts +127 -134
- package/src/utils/drag-menu.ts +322 -373
- package/src/utils/get-allow-add-column-custom-step.ts +4 -5
- package/src/utils/guidelines.ts +16 -21
- package/src/utils/index.ts +68 -68
- package/src/utils/merged-cells.ts +245 -254
- package/src/utils/nodes.ts +91 -106
- package/src/utils/paste.ts +119 -135
- package/src/utils/row-controls.ts +199 -213
- package/src/utils/selection.ts +77 -87
- package/src/utils/snapping.ts +87 -100
- package/src/utils/table.ts +44 -44
- package/src/utils/transforms.ts +5 -5
- package/src/utils/update-plugin-state-decorations.ts +5 -9
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
51
|
+
clearHoverSelection,
|
|
52
|
+
hoverColumns,
|
|
53
|
+
hoverMergedCells,
|
|
54
|
+
hoverRows,
|
|
55
|
+
hoverTable,
|
|
56
|
+
removeDescendantNodes,
|
|
67
57
|
} from './commands';
|
|
68
58
|
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
config: ToolbarMenuConfig,
|
|
103
|
+
state: ToolbarMenuState,
|
|
104
|
+
{ formatMessage }: ToolbarMenuContext,
|
|
105
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
116
106
|
): FloatingToolbarItem<Command> => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
578
|
+
return {
|
|
579
|
+
type: 'separator',
|
|
580
|
+
hidden: hidden,
|
|
581
|
+
};
|
|
639
582
|
};
|
|
640
583
|
|
|
641
584
|
const getCellItems = (
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
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
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
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
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
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
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
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
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
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
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
const highlightRowsHandler = (
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
)
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
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
|
-
|
|
880
|
-
|
|
881
|
-
)
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
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
|
-
|
|
895
|
-
|
|
896
|
-
|
|
821
|
+
id?: string;
|
|
822
|
+
value: AlignmentOptions;
|
|
823
|
+
icon: React.ComponentClass<any>;
|
|
897
824
|
};
|
|
898
825
|
|
|
899
826
|
export const getAlignmentOptionsConfig = (
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
827
|
+
editorState: EditorState,
|
|
828
|
+
{ formatMessage }: ToolbarMenuContext,
|
|
829
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
830
|
+
getEditorContainerWidth: GetEditorContainerWidth,
|
|
904
831
|
): Array<FloatingToolbarDropdown<Command>> => {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
996
|
-
|
|
909
|
+
selectedNode: PMNode,
|
|
910
|
+
getEditorContainerWidth: GetEditorContainerWidth,
|
|
997
911
|
) => {
|
|
998
|
-
|
|
912
|
+
const lineLength = getEditorContainerWidth().lineLength;
|
|
999
913
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
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
|
-
|
|
918
|
+
return false;
|
|
1009
919
|
};
|