@atlaskit/editor-plugin-table 22.4.11 → 22.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/tablePlugin.js +4 -1
  3. package/dist/cjs/ui/TableMenu/row/getRowMenuComponents.js +23 -8
  4. package/dist/cjs/ui/TableMenu/row/items/AddRowAboveItem.js +24 -1
  5. package/dist/cjs/ui/TableMenu/row/items/AddRowBelowItem.js +24 -1
  6. package/dist/cjs/ui/TableMenu/row/items/DeleteRowItem.js +55 -3
  7. package/dist/cjs/ui/TableMenu/row/items/HeaderRowToggleItem.js +38 -5
  8. package/dist/cjs/ui/TableMenu/row/items/MoveRowDownItem.js +38 -13
  9. package/dist/cjs/ui/TableMenu/row/items/MoveRowUpItem.js +38 -13
  10. package/dist/cjs/ui/TableMenu/row/items/NumberedRowsToggleItem.js +29 -2
  11. package/dist/cjs/ui/TableMenu/shared/consts.js +4 -2
  12. package/dist/cjs/ui/TableMenu/shared/getSharedItems.js +5 -2
  13. package/dist/cjs/ui/TableMenu/shared/getTableMenuComponents.js +2 -2
  14. package/dist/cjs/ui/TableMenu/shared/items/ClearCellsItem.js +23 -3
  15. package/dist/cjs/ui/TableMenu/shared/types.js +5 -0
  16. package/dist/es2019/tablePlugin.js +4 -1
  17. package/dist/es2019/ui/TableMenu/row/getRowMenuComponents.js +24 -8
  18. package/dist/es2019/ui/TableMenu/row/items/AddRowAboveItem.js +27 -1
  19. package/dist/es2019/ui/TableMenu/row/items/AddRowBelowItem.js +27 -1
  20. package/dist/es2019/ui/TableMenu/row/items/DeleteRowItem.js +59 -3
  21. package/dist/es2019/ui/TableMenu/row/items/HeaderRowToggleItem.js +42 -5
  22. package/dist/es2019/ui/TableMenu/row/items/MoveRowDownItem.js +42 -11
  23. package/dist/es2019/ui/TableMenu/row/items/MoveRowUpItem.js +42 -11
  24. package/dist/es2019/ui/TableMenu/row/items/NumberedRowsToggleItem.js +33 -2
  25. package/dist/es2019/ui/TableMenu/shared/consts.js +3 -1
  26. package/dist/es2019/ui/TableMenu/shared/getSharedItems.js +6 -2
  27. package/dist/es2019/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
  28. package/dist/es2019/ui/TableMenu/shared/items/ClearCellsItem.js +26 -3
  29. package/dist/es2019/ui/TableMenu/shared/types.js +1 -0
  30. package/dist/esm/tablePlugin.js +4 -1
  31. package/dist/esm/ui/TableMenu/row/getRowMenuComponents.js +23 -8
  32. package/dist/esm/ui/TableMenu/row/items/AddRowAboveItem.js +24 -1
  33. package/dist/esm/ui/TableMenu/row/items/AddRowBelowItem.js +24 -1
  34. package/dist/esm/ui/TableMenu/row/items/DeleteRowItem.js +55 -3
  35. package/dist/esm/ui/TableMenu/row/items/HeaderRowToggleItem.js +38 -6
  36. package/dist/esm/ui/TableMenu/row/items/MoveRowDownItem.js +39 -14
  37. package/dist/esm/ui/TableMenu/row/items/MoveRowUpItem.js +39 -14
  38. package/dist/esm/ui/TableMenu/row/items/NumberedRowsToggleItem.js +29 -2
  39. package/dist/esm/ui/TableMenu/shared/consts.js +3 -1
  40. package/dist/esm/ui/TableMenu/shared/getSharedItems.js +5 -2
  41. package/dist/esm/ui/TableMenu/shared/getTableMenuComponents.js +2 -2
  42. package/dist/esm/ui/TableMenu/shared/items/ClearCellsItem.js +23 -3
  43. package/dist/esm/ui/TableMenu/shared/types.js +1 -0
  44. package/dist/types/types/index.d.ts +1 -1
  45. package/dist/types/ui/TableMenu/row/getRowMenuComponents.d.ts +2 -1
  46. package/dist/types/ui/TableMenu/row/items/AddRowAboveItem.d.ts +2 -1
  47. package/dist/types/ui/TableMenu/row/items/AddRowBelowItem.d.ts +2 -1
  48. package/dist/types/ui/TableMenu/row/items/DeleteRowItem.d.ts +2 -1
  49. package/dist/types/ui/TableMenu/row/items/HeaderRowToggleItem.d.ts +2 -1
  50. package/dist/types/ui/TableMenu/row/items/MoveRowDownItem.d.ts +2 -1
  51. package/dist/types/ui/TableMenu/row/items/MoveRowUpItem.d.ts +2 -1
  52. package/dist/types/ui/TableMenu/row/items/NumberedRowsToggleItem.d.ts +2 -1
  53. package/dist/types/ui/TableMenu/shared/consts.d.ts +2 -0
  54. package/dist/types/ui/TableMenu/shared/getSharedItems.d.ts +2 -1
  55. package/dist/types/ui/TableMenu/shared/getTableMenuComponents.d.ts +2 -1
  56. package/dist/types/ui/TableMenu/shared/items/ClearCellsItem.d.ts +2 -1
  57. package/dist/types/ui/TableMenu/shared/types.d.ts +4 -0
  58. package/dist/types-ts4.5/types/index.d.ts +1 -1
  59. package/dist/types-ts4.5/ui/TableMenu/row/getRowMenuComponents.d.ts +2 -1
  60. package/dist/types-ts4.5/ui/TableMenu/row/items/AddRowAboveItem.d.ts +2 -1
  61. package/dist/types-ts4.5/ui/TableMenu/row/items/AddRowBelowItem.d.ts +2 -1
  62. package/dist/types-ts4.5/ui/TableMenu/row/items/DeleteRowItem.d.ts +2 -1
  63. package/dist/types-ts4.5/ui/TableMenu/row/items/HeaderRowToggleItem.d.ts +2 -1
  64. package/dist/types-ts4.5/ui/TableMenu/row/items/MoveRowDownItem.d.ts +2 -1
  65. package/dist/types-ts4.5/ui/TableMenu/row/items/MoveRowUpItem.d.ts +2 -1
  66. package/dist/types-ts4.5/ui/TableMenu/row/items/NumberedRowsToggleItem.d.ts +2 -1
  67. package/dist/types-ts4.5/ui/TableMenu/shared/consts.d.ts +2 -0
  68. package/dist/types-ts4.5/ui/TableMenu/shared/getSharedItems.d.ts +2 -1
  69. package/dist/types-ts4.5/ui/TableMenu/shared/getTableMenuComponents.d.ts +2 -1
  70. package/dist/types-ts4.5/ui/TableMenu/shared/items/ClearCellsItem.d.ts +2 -1
  71. package/dist/types-ts4.5/ui/TableMenu/shared/types.d.ts +4 -0
  72. package/package.json +3 -3
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -82,7 +82,9 @@ const tablePlugin = ({
82
82
  !(options !== null && options !== void 0 && options.isChromelessEditor) && !(options !== null && options !== void 0 && options.isCommentEditor) && (options === null || options === void 0 ? void 0 : (_options$getEditorFea2 = options.getEditorFeatureFlags) === null || _options$getEditorFea2 === void 0 ? void 0 : _options$getEditorFea2.call(options).tableSelector) && editorExperiment('platform_editor_controls', 'variant1');
83
83
  if (expValEquals('platform_editor_table_menu_updates', 'isEnabled', true)) {
84
84
  var _api$uiControlRegistr;
85
- api === null || api === void 0 ? void 0 : (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 ? void 0 : _api$uiControlRegistr.actions.register(getTableMenuComponents());
85
+ api === null || api === void 0 ? void 0 : (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 ? void 0 : _api$uiControlRegistr.actions.register(getTableMenuComponents({
86
+ api
87
+ }));
86
88
  }
87
89
  return {
88
90
  name: 'table',
@@ -110,6 +112,7 @@ const tablePlugin = ({
110
112
  wasMaxWidthModeEnabled: !!(options !== null && options !== void 0 && options.wasMaxWidthEnabled),
111
113
  isHeaderRowEnabled: tablePluginState.isHeaderRowEnabled,
112
114
  isHeaderColumnEnabled: tablePluginState.isHeaderColumnEnabled,
115
+ isNumberColumnEnabled: tablePluginState.isNumberColumnEnabled,
113
116
  ordering: tablePluginState.ordering,
114
117
  isResizing: !!(tableResizingPluginState !== null && tableResizingPluginState !== void 0 && tableResizingPluginState.dragging || tableWidthResizingPluginState !== null && tableWidthResizingPluginState !== void 0 && tableWidthResizingPluginState.resizing),
115
118
  isTableResizing: tableWidthResizingPluginState === null || tableWidthResizingPluginState === void 0 ? void 0 : tableWidthResizingPluginState.resizing,
@@ -8,7 +8,9 @@ import { MoveRowDownItem } from './items/MoveRowDownItem';
8
8
  import { MoveRowUpItem } from './items/MoveRowUpItem';
9
9
  import { NumberedRowsToggleItem } from './items/NumberedRowsToggleItem';
10
10
  import { ROW_MENU, ROW_TOGGLE_SECTION, ROW_BACKGROUND_SECTION, ROW_ADD_SECTION, ROW_DANGER_SECTION, ROW_MENU_SECTION_RANK, HEADER_ROW_TOGGLE_ITEM, NUMBERED_ROWS_TOGGLE_ITEM, ADD_ROW_ABOVE_ITEM, ADD_ROW_BELOW_ITEM, MOVE_ROW_UP_ITEM, MOVE_ROW_DOWN_ITEM, DELETE_ROW_ITEM, ROW_TOGGLE_SECTION_RANK, ROW_ADD_SECTION_RANK, ROW_DANGER_SECTION_RANK } from './keys';
11
- export const getRowMenuComponents = () => [
11
+ export const getRowMenuComponents = ({
12
+ api
13
+ }) => [
12
14
  // --- Menu surface ---
13
15
  {
14
16
  type: ROW_MENU.type,
@@ -32,7 +34,9 @@ export const getRowMenuComponents = () => [
32
34
  key: ROW_TOGGLE_SECTION.key,
33
35
  rank: ROW_TOGGLE_SECTION_RANK[HEADER_ROW_TOGGLE_ITEM.key]
34
36
  }],
35
- component: () => /*#__PURE__*/React.createElement(HeaderRowToggleItem, null)
37
+ component: () => /*#__PURE__*/React.createElement(HeaderRowToggleItem, {
38
+ api: api
39
+ })
36
40
  }, {
37
41
  type: NUMBERED_ROWS_TOGGLE_ITEM.type,
38
42
  key: NUMBERED_ROWS_TOGGLE_ITEM.key,
@@ -41,7 +45,9 @@ export const getRowMenuComponents = () => [
41
45
  key: ROW_TOGGLE_SECTION.key,
42
46
  rank: ROW_TOGGLE_SECTION_RANK[NUMBERED_ROWS_TOGGLE_ITEM.key]
43
47
  }],
44
- component: () => /*#__PURE__*/React.createElement(NumberedRowsToggleItem, null)
48
+ component: () => /*#__PURE__*/React.createElement(NumberedRowsToggleItem, {
49
+ api: api
50
+ })
45
51
  },
46
52
  // --- Background color section ---
47
53
  {
@@ -76,7 +82,9 @@ export const getRowMenuComponents = () => [
76
82
  key: ROW_ADD_SECTION.key,
77
83
  rank: ROW_ADD_SECTION_RANK[ADD_ROW_ABOVE_ITEM.key]
78
84
  }],
79
- component: () => /*#__PURE__*/React.createElement(AddRowAboveItem, null)
85
+ component: () => /*#__PURE__*/React.createElement(AddRowAboveItem, {
86
+ api: api
87
+ })
80
88
  }, {
81
89
  type: ADD_ROW_BELOW_ITEM.type,
82
90
  key: ADD_ROW_BELOW_ITEM.key,
@@ -85,7 +93,9 @@ export const getRowMenuComponents = () => [
85
93
  key: ROW_ADD_SECTION.key,
86
94
  rank: ROW_ADD_SECTION_RANK[ADD_ROW_BELOW_ITEM.key]
87
95
  }],
88
- component: () => /*#__PURE__*/React.createElement(AddRowBelowItem, null)
96
+ component: () => /*#__PURE__*/React.createElement(AddRowBelowItem, {
97
+ api: api
98
+ })
89
99
  }, {
90
100
  type: MOVE_ROW_UP_ITEM.type,
91
101
  key: MOVE_ROW_UP_ITEM.key,
@@ -94,7 +104,9 @@ export const getRowMenuComponents = () => [
94
104
  key: ROW_ADD_SECTION.key,
95
105
  rank: ROW_ADD_SECTION_RANK[MOVE_ROW_UP_ITEM.key]
96
106
  }],
97
- component: () => /*#__PURE__*/React.createElement(MoveRowUpItem, null)
107
+ component: () => /*#__PURE__*/React.createElement(MoveRowUpItem, {
108
+ api: api
109
+ })
98
110
  }, {
99
111
  type: MOVE_ROW_DOWN_ITEM.type,
100
112
  key: MOVE_ROW_DOWN_ITEM.key,
@@ -103,7 +115,9 @@ export const getRowMenuComponents = () => [
103
115
  key: ROW_ADD_SECTION.key,
104
116
  rank: ROW_ADD_SECTION_RANK[MOVE_ROW_DOWN_ITEM.key]
105
117
  }],
106
- component: () => /*#__PURE__*/React.createElement(MoveRowDownItem, null)
118
+ component: () => /*#__PURE__*/React.createElement(MoveRowDownItem, {
119
+ api: api
120
+ })
107
121
  },
108
122
  // --- Danger section (Clear cells, Delete row) ---
109
123
  {
@@ -125,5 +139,7 @@ export const getRowMenuComponents = () => [
125
139
  key: ROW_DANGER_SECTION.key,
126
140
  rank: ROW_DANGER_SECTION_RANK[DELETE_ROW_ITEM.key]
127
141
  }],
128
- component: () => /*#__PURE__*/React.createElement(DeleteRowItem, null)
142
+ component: () => /*#__PURE__*/React.createElement(DeleteRowItem, {
143
+ api: api
144
+ })
129
145
  }];
@@ -1,14 +1,40 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
4
  import { addRowBefore, tooltip } from '@atlaskit/editor-common/keymaps';
4
5
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
7
+ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
8
  import { TableRowAddAboveIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- export const AddRowAboveItem = () => {
9
+ import { insertRowWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
10
+ export const AddRowAboveItem = props => {
7
11
  var _tooltip;
12
+ const {
13
+ api
14
+ } = props;
15
+ const {
16
+ editorView
17
+ } = useEditorToolbar();
8
18
  const {
9
19
  formatMessage
10
20
  } = useIntl();
21
+ const handleClick = () => {
22
+ var _api$analytics;
23
+ if (!editorView) {
24
+ return;
25
+ }
26
+ const selectionRect = getSelectionRect(editorView.state.selection);
27
+ const index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.top;
28
+ if (index === undefined) {
29
+ return;
30
+ }
31
+ insertRowWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
32
+ index,
33
+ moveCursorToInsertedRow: true
34
+ })(editorView.state, editorView.dispatch);
35
+ };
11
36
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
37
+ onClick: handleClick,
12
38
  elemBefore: /*#__PURE__*/React.createElement(TableRowAddAboveIcon, {
13
39
  color: "currentColor",
14
40
  label: "",
@@ -1,14 +1,40 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
4
  import { addRowAfter, tooltip } from '@atlaskit/editor-common/keymaps';
4
5
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
7
+ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
8
  import { TableRowAddBelowIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- export const AddRowBelowItem = () => {
9
+ import { insertRowWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
10
+ export const AddRowBelowItem = props => {
7
11
  var _tooltip;
12
+ const {
13
+ api
14
+ } = props;
15
+ const {
16
+ editorView
17
+ } = useEditorToolbar();
8
18
  const {
9
19
  formatMessage
10
20
  } = useIntl();
21
+ const handleClick = () => {
22
+ var _api$analytics;
23
+ if (!editorView) {
24
+ return;
25
+ }
26
+ const selectionRect = getSelectionRect(editorView.state.selection);
27
+ const index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.bottom;
28
+ if (index === undefined) {
29
+ return;
30
+ }
31
+ insertRowWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, {
32
+ index,
33
+ moveCursorToInsertedRow: true
34
+ })(editorView.state, editorView.dispatch);
35
+ };
11
36
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
37
+ onClick: handleClick,
12
38
  elemBefore: /*#__PURE__*/React.createElement(TableRowAddBelowIcon, {
13
39
  color: "currentColor",
14
40
  label: "",
@@ -1,14 +1,70 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
5
  import { deleteRow, tooltip } from '@atlaskit/editor-common/keymaps';
4
6
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
7
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
8
+ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
9
  import { DeleteIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- export const DeleteRowItem = () => {
7
- var _tooltip;
10
+ import { clearHoverSelection, hoverRows } from '../../../../pm-plugins/commands';
11
+ import { deleteRowsWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
12
+ import { getSelectedRowIndexes } from '../../../../pm-plugins/utils/selection';
13
+ import { useTableMenuContext } from '../../shared/TableMenuContext';
14
+ export const DeleteRowItem = props => {
15
+ var _tableMenuContext$sel, _tooltip;
16
+ const {
17
+ api
18
+ } = props;
19
+ const {
20
+ editorView
21
+ } = useEditorToolbar();
22
+ const tableMenuContext = useTableMenuContext();
23
+ const {
24
+ isHeaderRowRequired
25
+ } = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
26
+ var _states$tableState, _states$tableState$pl;
27
+ return {
28
+ isHeaderRowRequired: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : (_states$tableState$pl = _states$tableState.pluginConfig) === null || _states$tableState$pl === void 0 ? void 0 : _states$tableState$pl.isHeaderRowRequired
29
+ };
30
+ });
31
+ const selectedRowCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
8
32
  const {
9
33
  formatMessage
10
34
  } = useIntl();
35
+ const handleMouseEnter = () => {
36
+ if (!editorView) {
37
+ return;
38
+ }
39
+ const selectionRect = getSelectionRect(editorView.state.selection);
40
+ if (!selectionRect) {
41
+ return;
42
+ }
43
+ hoverRows(getSelectedRowIndexes(selectionRect), true)(editorView.state, editorView.dispatch);
44
+ };
45
+ const handleMouseLeave = () => {
46
+ if (!editorView) {
47
+ return;
48
+ }
49
+ clearHoverSelection()(editorView.state, editorView.dispatch);
50
+ };
51
+ const handleClick = () => {
52
+ var _api$analytics;
53
+ if (!editorView) {
54
+ return;
55
+ }
56
+ const selectionRect = getSelectionRect(editorView.state.selection);
57
+ if (!selectionRect) {
58
+ return;
59
+ }
60
+ deleteRowsWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, selectionRect, !!isHeaderRowRequired)(editorView.state, editorView.dispatch);
61
+ };
11
62
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
63
+ onClick: handleClick,
64
+ onFocus: handleMouseEnter,
65
+ onMouseEnter: handleMouseEnter,
66
+ onBlur: handleMouseLeave,
67
+ onMouseLeave: handleMouseLeave,
12
68
  elemBefore: /*#__PURE__*/React.createElement(DeleteIcon, {
13
69
  color: "currentColor",
14
70
  label: "",
@@ -18,6 +74,6 @@ export const DeleteRowItem = () => {
18
74
  shortcut: (_tooltip = tooltip(deleteRow)) !== null && _tooltip !== void 0 ? _tooltip : ''
19
75
  })
20
76
  }, formatMessage(messages.removeRows, {
21
- 0: 1
77
+ 0: selectedRowCount
22
78
  }));
23
79
  };
@@ -1,25 +1,62 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
4
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
4
6
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
5
7
  import Toggle from '@atlaskit/toggle';
8
+ import { toggleHeaderRowWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
6
9
  import { useTableMenuContext } from '../../shared/TableMenuContext';
7
-
8
10
  /** Header row toggle is only visible when the first row is the entire selection. */
9
- const shouldShowHeaderRowToggle = tableMenuContext => (tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstRow) === true && tableMenuContext.selectedRowCount === 1;
10
- export const HeaderRowToggleItem = () => {
11
+ const shouldShowHeaderRowToggle = ({
12
+ isFirstRow,
13
+ isHeaderRowAllowed,
14
+ selectedRowCount
15
+ }) => isHeaderRowAllowed === true && isFirstRow && selectedRowCount === 1;
16
+ export const HeaderRowToggleItem = props => {
17
+ var _tableMenuContext$sel;
18
+ const {
19
+ api
20
+ } = props;
21
+ const {
22
+ editorView
23
+ } = useEditorToolbar();
11
24
  const tableMenuContext = useTableMenuContext();
25
+ const {
26
+ isHeaderRowAllowed,
27
+ isHeaderRowEnabled
28
+ } = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
29
+ var _states$tableState, _states$tableState$pl, _states$tableState2;
30
+ return {
31
+ isHeaderRowAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : (_states$tableState$pl = _states$tableState.pluginConfig) === null || _states$tableState$pl === void 0 ? void 0 : _states$tableState$pl.allowHeaderRow,
32
+ isHeaderRowEnabled: (_states$tableState2 = states.tableState) === null || _states$tableState2 === void 0 ? void 0 : _states$tableState2.isHeaderRowEnabled
33
+ };
34
+ });
35
+ const selectedRowCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 0;
12
36
  const {
13
37
  formatMessage
14
38
  } = useIntl();
15
39
  const label = formatMessage(messages.headerRow);
16
- if (!shouldShowHeaderRowToggle(tableMenuContext)) {
40
+ const handleClick = () => {
41
+ var _api$analytics;
42
+ if (!editorView) {
43
+ return;
44
+ }
45
+ toggleHeaderRowWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(editorView.state, editorView.dispatch);
46
+ };
47
+ if (!shouldShowHeaderRowToggle({
48
+ isFirstRow: (tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstRow) === true,
49
+ isHeaderRowAllowed,
50
+ selectedRowCount
51
+ })) {
17
52
  return null;
18
53
  }
19
54
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
55
+ onClick: handleClick,
20
56
  elemAfter: /*#__PURE__*/React.createElement(Toggle, {
21
57
  label: label,
22
- isChecked: false
58
+ isChecked: !!isHeaderRowEnabled,
59
+ onChange: handleClick
23
60
  })
24
61
  }, label);
25
62
  };
@@ -1,33 +1,64 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
- import { moveRowDown, moveRowDownOld, tooltip } from '@atlaskit/editor-common/keymaps';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
+ import { moveRowDown, tooltip } from '@atlaskit/editor-common/keymaps';
4
6
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
7
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
8
+ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
9
  import { TableRowMoveDownIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
+ import { moveSourceWithAnalytics } from '../../../../pm-plugins/drag-and-drop/commands-with-analytics';
11
+ import { getPluginState } from '../../../../pm-plugins/plugin-factory';
12
+ import { getSelectedRowIndexes } from '../../../../pm-plugins/utils/selection';
13
+ import { TABLE_ROW } from '../../shared/consts';
7
14
  import { useTableMenuContext } from '../../shared/TableMenuContext';
8
- const getMoveRowDownShortcut = () => tooltip(expValEquals('editor-a11y-fy26-keyboard-move-row-column', 'isEnabled', true) ? moveRowDown : moveRowDownOld);
9
-
10
- /** Move row down is hidden when the selection includes the last row (cannot move further down). */
11
- const shouldShowMoveRowDown = tableMenuContext => !(tableMenuContext !== null && tableMenuContext !== void 0 && tableMenuContext.isLastRow);
12
- export const MoveRowDownItem = () => {
13
- var _getMoveRowDownShortc;
15
+ const shouldShowMoveRowDown = isLastRow => !isLastRow;
16
+ export const MoveRowDownItem = props => {
17
+ var _tableMenuContext$sel, _tooltip;
18
+ const {
19
+ api
20
+ } = props;
21
+ const {
22
+ editorView
23
+ } = useEditorToolbar();
14
24
  const tableMenuContext = useTableMenuContext();
25
+ const {
26
+ tableNode
27
+ } = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
28
+ var _states$tableState;
29
+ return {
30
+ tableNode: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.tableNode
31
+ };
32
+ });
33
+ const selectedRowCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
15
34
  const {
16
35
  formatMessage
17
36
  } = useIntl();
18
- if (!shouldShowMoveRowDown(tableMenuContext)) {
37
+ const handleClick = () => {
38
+ var _api$analytics, _api$accessibilityUti;
39
+ if (!editorView) {
40
+ return;
41
+ }
42
+ const selectionRect = getSelectionRect(editorView.state.selection);
43
+ if (!selectionRect) {
44
+ return;
45
+ }
46
+ moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? void 0 : (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_ROW, getSelectedRowIndexes(selectionRect), selectionRect.bottom)(editorView.state, editorView.dispatch);
47
+ };
48
+ if (!tableNode || !shouldShowMoveRowDown(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isLastRow)) {
19
49
  return null;
20
50
  }
21
51
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
52
+ onClick: handleClick,
22
53
  elemBefore: /*#__PURE__*/React.createElement(TableRowMoveDownIcon, {
23
54
  color: "currentColor",
24
55
  label: "",
25
56
  size: "small"
26
57
  }),
27
58
  elemAfter: /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
28
- shortcut: (_getMoveRowDownShortc = getMoveRowDownShortcut()) !== null && _getMoveRowDownShortc !== void 0 ? _getMoveRowDownShortc : ''
59
+ shortcut: (_tooltip = tooltip(moveRowDown)) !== null && _tooltip !== void 0 ? _tooltip : ''
29
60
  })
30
61
  }, formatMessage(messages.moveRowDown, {
31
- 0: 1
62
+ 0: selectedRowCount
32
63
  }));
33
64
  };
@@ -1,33 +1,64 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
- import { moveRowUp, moveRowUpOld, tooltip } from '@atlaskit/editor-common/keymaps';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
+ import { moveRowUp, tooltip } from '@atlaskit/editor-common/keymaps';
4
6
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
7
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
8
+ import { getSelectionRect } from '@atlaskit/editor-tables/utils';
5
9
  import { TableRowMoveUpIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
+ import { moveSourceWithAnalytics } from '../../../../pm-plugins/drag-and-drop/commands-with-analytics';
11
+ import { getPluginState } from '../../../../pm-plugins/plugin-factory';
12
+ import { getSelectedRowIndexes } from '../../../../pm-plugins/utils/selection';
13
+ import { TABLE_ROW } from '../../shared/consts';
7
14
  import { useTableMenuContext } from '../../shared/TableMenuContext';
8
- const getMoveRowUpShortcut = () => tooltip(expValEquals('editor-a11y-fy26-keyboard-move-row-column', 'isEnabled', true) ? moveRowUp : moveRowUpOld);
9
-
10
- /** Move row up is hidden when the selection includes row 0 (cannot move further up). */
11
- const shouldShowMoveRowUp = tableMenuContext => !(tableMenuContext !== null && tableMenuContext !== void 0 && tableMenuContext.isFirstRow);
12
- export const MoveRowUpItem = () => {
13
- var _getMoveRowUpShortcut;
15
+ const shouldShowMoveRowUp = isFirstRow => !isFirstRow;
16
+ export const MoveRowUpItem = props => {
17
+ var _tableMenuContext$sel, _tooltip;
18
+ const {
19
+ api
20
+ } = props;
21
+ const {
22
+ editorView
23
+ } = useEditorToolbar();
14
24
  const tableMenuContext = useTableMenuContext();
25
+ const {
26
+ tableNode
27
+ } = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
28
+ var _states$tableState;
29
+ return {
30
+ tableNode: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.tableNode
31
+ };
32
+ });
33
+ const selectedRowCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
15
34
  const {
16
35
  formatMessage
17
36
  } = useIntl();
18
- if (!shouldShowMoveRowUp(tableMenuContext)) {
37
+ const handleClick = () => {
38
+ var _api$analytics, _api$accessibilityUti;
39
+ if (!editorView) {
40
+ return;
41
+ }
42
+ const selectionRect = getSelectionRect(editorView.state.selection);
43
+ if (!selectionRect) {
44
+ return;
45
+ }
46
+ moveSourceWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, api === null || api === void 0 ? void 0 : (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify, getPluginState(editorView.state).getIntl)(INPUT_METHOD.TABLE_CONTEXT_MENU, TABLE_ROW, getSelectedRowIndexes(selectionRect), selectionRect.top - 1)(editorView.state, editorView.dispatch);
47
+ };
48
+ if (!tableNode || !shouldShowMoveRowUp(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstRow)) {
19
49
  return null;
20
50
  }
21
51
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
52
+ onClick: handleClick,
22
53
  elemBefore: /*#__PURE__*/React.createElement(TableRowMoveUpIcon, {
23
54
  color: "currentColor",
24
55
  label: "",
25
56
  size: "small"
26
57
  }),
27
58
  elemAfter: /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
28
- shortcut: (_getMoveRowUpShortcut = getMoveRowUpShortcut()) !== null && _getMoveRowUpShortcut !== void 0 ? _getMoveRowUpShortcut : ''
59
+ shortcut: (_tooltip = tooltip(moveRowUp)) !== null && _tooltip !== void 0 ? _tooltip : ''
29
60
  })
30
61
  }, formatMessage(messages.moveRowUp, {
31
- 0: 1
62
+ 0: selectedRowCount
32
63
  }));
33
64
  };
@@ -1,17 +1,48 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
4
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
4
6
  import { ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
5
7
  import Toggle from '@atlaskit/toggle';
6
- export const NumberedRowsToggleItem = () => {
8
+ import { toggleNumberColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
9
+ export const NumberedRowsToggleItem = props => {
10
+ const {
11
+ api
12
+ } = props;
13
+ const {
14
+ editorView
15
+ } = useEditorToolbar();
16
+ const {
17
+ isNumberColumnAllowed,
18
+ isNumberColumnEnabled
19
+ } = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
20
+ var _states$tableState, _states$tableState$pl, _states$tableState2;
21
+ return {
22
+ isNumberColumnAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : (_states$tableState$pl = _states$tableState.pluginConfig) === null || _states$tableState$pl === void 0 ? void 0 : _states$tableState$pl.allowNumberColumn,
23
+ isNumberColumnEnabled: (_states$tableState2 = states.tableState) === null || _states$tableState2 === void 0 ? void 0 : _states$tableState2.isNumberColumnEnabled
24
+ };
25
+ });
7
26
  const {
8
27
  formatMessage
9
28
  } = useIntl();
10
29
  const label = formatMessage(messages.numberedRows);
30
+ const handleClick = () => {
31
+ var _api$analytics;
32
+ if (!editorView) {
33
+ return;
34
+ }
35
+ toggleNumberColumnWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(editorView.state, editorView.dispatch);
36
+ };
37
+ if (!isNumberColumnAllowed) {
38
+ return null;
39
+ }
11
40
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
41
+ onClick: handleClick,
12
42
  elemAfter: /*#__PURE__*/React.createElement(Toggle, {
13
43
  label: label,
14
- isChecked: false
44
+ isChecked: !!isNumberColumnEnabled,
45
+ onChange: handleClick
15
46
  })
16
47
  }, label);
17
48
  };
@@ -1,2 +1,4 @@
1
1
  export const TABLE_MENU_WIDTH = 280;
2
- export const TABLE_MENU_SELECTOR = '[data-testid="column-handle-menu"], [data-testid="row-handle-menu"], [data-toolbar-nested-dropdown-menu]';
2
+ export const TABLE_MENU_SELECTOR = '[data-testid="column-handle-menu"], [data-testid="row-handle-menu"], [data-toolbar-nested-dropdown-menu]';
3
+ export const TABLE_ROW = 'table-row';
4
+ export const TABLE_COLUMN = 'table-column';
@@ -5,7 +5,9 @@ import { ROW_BACKGROUND_SECTION, ROW_DANGER_SECTION, ROW_BACKGROUND_SECTION_RANK
5
5
  import { BackgroundColorItem } from './items/BackgroundColorItem';
6
6
  import { ClearCellsItem } from './items/ClearCellsItem';
7
7
  import { BACKGROUND_COLOR_ITEM, CLEAR_CELLS_ITEM } from './keys';
8
- export const getSharedItems = () => [{
8
+ export const getSharedItems = ({
9
+ api
10
+ }) => [{
9
11
  type: BACKGROUND_COLOR_ITEM.type,
10
12
  key: BACKGROUND_COLOR_ITEM.key,
11
13
  parents: [{
@@ -38,5 +40,7 @@ export const getSharedItems = () => [{
38
40
  key: CELL_DANGER_SECTION.key,
39
41
  rank: CELL_DANGER_SECTION_RANK[CLEAR_CELLS_ITEM.key]
40
42
  }],
41
- component: () => /*#__PURE__*/React.createElement(ClearCellsItem, null)
43
+ component: () => /*#__PURE__*/React.createElement(ClearCellsItem, {
44
+ api: api
45
+ })
42
46
  }];
@@ -2,4 +2,4 @@ import { getCellMenuComponents } from '../cell/getCellMenuComponents';
2
2
  import { getColumnMenuComponents } from '../column/getColumnMenuComponents';
3
3
  import { getRowMenuComponents } from '../row/getRowMenuComponents';
4
4
  import { getSharedItems } from './getSharedItems';
5
- export const getTableMenuComponents = () => [...getRowMenuComponents(), ...getColumnMenuComponents(), ...getCellMenuComponents(), ...getSharedItems()];
5
+ export const getTableMenuComponents = params => [...getRowMenuComponents(params), ...getColumnMenuComponents(), ...getCellMenuComponents(), ...getSharedItems(params)];
@@ -1,14 +1,37 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
4
  import { backspace, tooltip } from '@atlaskit/editor-common/keymaps';
4
5
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
5
7
  import { CrossIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- export const ClearCellsItem = () => {
7
- var _tooltip;
8
+ import { emptyMultipleCellsWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
9
+ import { getPluginState } from '../../../../pm-plugins/plugin-factory';
10
+ import { useTableMenuContext } from '../TableMenuContext';
11
+ export const ClearCellsItem = ({
12
+ api
13
+ }) => {
14
+ var _tableMenuContext$sel, _tableMenuContext$sel2, _tooltip;
15
+ const {
16
+ editorView
17
+ } = useEditorToolbar();
18
+ const tableMenuContext = useTableMenuContext();
8
19
  const {
9
20
  formatMessage
10
21
  } = useIntl();
22
+ const selectedCellCount = Math.max((_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1, (_tableMenuContext$sel2 = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedRowCount) !== null && _tableMenuContext$sel2 !== void 0 ? _tableMenuContext$sel2 : 1);
23
+ const handleClick = () => {
24
+ var _api$analytics;
25
+ if (!editorView) {
26
+ return;
27
+ }
28
+ const {
29
+ targetCellPosition
30
+ } = getPluginState(editorView.state);
31
+ emptyMultipleCellsWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(INPUT_METHOD.TABLE_CONTEXT_MENU, targetCellPosition)(editorView.state, editorView.dispatch);
32
+ };
11
33
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
34
+ onClick: handleClick,
12
35
  elemBefore: /*#__PURE__*/React.createElement(CrossIcon, {
13
36
  color: "currentColor",
14
37
  label: "",
@@ -18,6 +41,6 @@ export const ClearCellsItem = () => {
18
41
  shortcut: (_tooltip = tooltip(backspace)) !== null && _tooltip !== void 0 ? _tooltip : ''
19
42
  })
20
43
  }, formatMessage(messages.clearCells, {
21
- 0: 1
44
+ 0: selectedCellCount
22
45
  }));
23
46
  };
@@ -0,0 +1 @@
1
+ export {};