@atlaskit/editor-plugin-table 22.4.12 → 22.4.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/tablePlugin.js +3 -0
  3. package/dist/cjs/ui/TableMenu/column/getColumnMenuComponents.js +46 -11
  4. package/dist/cjs/ui/TableMenu/column/items/AddColumnLeftItem.js +34 -1
  5. package/dist/cjs/ui/TableMenu/column/items/AddColumnRightItem.js +34 -1
  6. package/dist/cjs/ui/TableMenu/column/items/ColumnBackgroundSection.js +15 -2
  7. package/dist/cjs/ui/TableMenu/column/items/ColumnToggleSection.js +15 -2
  8. package/dist/cjs/ui/TableMenu/column/items/DeleteColumnItem.js +60 -3
  9. package/dist/cjs/ui/TableMenu/column/items/DistributeColumnsItem.js +43 -5
  10. package/dist/cjs/ui/TableMenu/column/items/HeaderColumnToggleItem.js +36 -5
  11. package/dist/cjs/ui/TableMenu/column/items/MoveColumnLeftItem.js +69 -0
  12. package/dist/cjs/ui/TableMenu/column/items/MoveColumnRightItem.js +42 -3
  13. package/dist/cjs/ui/TableMenu/column/items/SortDecreasingItem.js +22 -1
  14. package/dist/cjs/ui/TableMenu/column/items/SortIncreasingItem.js +22 -1
  15. package/dist/cjs/ui/TableMenu/column/keys.js +6 -2
  16. package/dist/cjs/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
  17. package/dist/es2019/tablePlugin.js +3 -0
  18. package/dist/es2019/ui/TableMenu/column/getColumnMenuComponents.js +46 -12
  19. package/dist/es2019/ui/TableMenu/column/items/AddColumnLeftItem.js +37 -1
  20. package/dist/es2019/ui/TableMenu/column/items/AddColumnRightItem.js +37 -1
  21. package/dist/es2019/ui/TableMenu/column/items/ColumnBackgroundSection.js +15 -1
  22. package/dist/es2019/ui/TableMenu/column/items/ColumnToggleSection.js +15 -1
  23. package/dist/es2019/ui/TableMenu/column/items/DeleteColumnItem.js +63 -3
  24. package/dist/es2019/ui/TableMenu/column/items/DistributeColumnsItem.js +43 -7
  25. package/dist/es2019/ui/TableMenu/column/items/HeaderColumnToggleItem.js +40 -5
  26. package/dist/es2019/ui/TableMenu/column/items/MoveColumnLeftItem.js +65 -0
  27. package/dist/es2019/ui/TableMenu/column/items/MoveColumnRightItem.js +44 -3
  28. package/dist/es2019/ui/TableMenu/column/items/SortDecreasingItem.js +24 -1
  29. package/dist/es2019/ui/TableMenu/column/items/SortIncreasingItem.js +24 -1
  30. package/dist/es2019/ui/TableMenu/column/keys.js +7 -2
  31. package/dist/es2019/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
  32. package/dist/esm/tablePlugin.js +3 -0
  33. package/dist/esm/ui/TableMenu/column/getColumnMenuComponents.js +47 -12
  34. package/dist/esm/ui/TableMenu/column/items/AddColumnLeftItem.js +34 -1
  35. package/dist/esm/ui/TableMenu/column/items/AddColumnRightItem.js +34 -1
  36. package/dist/esm/ui/TableMenu/column/items/ColumnBackgroundSection.js +15 -2
  37. package/dist/esm/ui/TableMenu/column/items/ColumnToggleSection.js +15 -2
  38. package/dist/esm/ui/TableMenu/column/items/DeleteColumnItem.js +60 -3
  39. package/dist/esm/ui/TableMenu/column/items/DistributeColumnsItem.js +43 -6
  40. package/dist/esm/ui/TableMenu/column/items/HeaderColumnToggleItem.js +36 -6
  41. package/dist/esm/ui/TableMenu/column/items/MoveColumnLeftItem.js +62 -0
  42. package/dist/esm/ui/TableMenu/column/items/MoveColumnRightItem.js +42 -3
  43. package/dist/esm/ui/TableMenu/column/items/SortDecreasingItem.js +22 -1
  44. package/dist/esm/ui/TableMenu/column/items/SortIncreasingItem.js +22 -1
  45. package/dist/esm/ui/TableMenu/column/keys.js +5 -1
  46. package/dist/esm/ui/TableMenu/shared/getTableMenuComponents.js +1 -1
  47. package/dist/types/types/index.d.ts +2 -1
  48. package/dist/types/ui/TableMenu/column/getColumnMenuComponents.d.ts +2 -1
  49. package/dist/types/ui/TableMenu/column/items/AddColumnLeftItem.d.ts +2 -1
  50. package/dist/types/ui/TableMenu/column/items/AddColumnRightItem.d.ts +2 -1
  51. package/dist/types/ui/TableMenu/column/items/ColumnBackgroundSection.d.ts +2 -1
  52. package/dist/types/ui/TableMenu/column/items/ColumnToggleSection.d.ts +2 -1
  53. package/dist/types/ui/TableMenu/column/items/DeleteColumnItem.d.ts +2 -1
  54. package/dist/types/ui/TableMenu/column/items/DistributeColumnsItem.d.ts +2 -1
  55. package/dist/types/ui/TableMenu/column/items/HeaderColumnToggleItem.d.ts +7 -3
  56. package/dist/types/ui/TableMenu/column/items/MoveColumnLeftItem.d.ts +3 -0
  57. package/dist/types/ui/TableMenu/column/items/MoveColumnRightItem.d.ts +2 -1
  58. package/dist/types/ui/TableMenu/column/items/SortDecreasingItem.d.ts +2 -1
  59. package/dist/types/ui/TableMenu/column/items/SortIncreasingItem.d.ts +2 -1
  60. package/dist/types/ui/TableMenu/column/keys.d.ts +1 -0
  61. package/dist/types-ts4.5/types/index.d.ts +2 -1
  62. package/dist/types-ts4.5/ui/TableMenu/column/getColumnMenuComponents.d.ts +2 -1
  63. package/dist/types-ts4.5/ui/TableMenu/column/items/AddColumnLeftItem.d.ts +2 -1
  64. package/dist/types-ts4.5/ui/TableMenu/column/items/AddColumnRightItem.d.ts +2 -1
  65. package/dist/types-ts4.5/ui/TableMenu/column/items/ColumnBackgroundSection.d.ts +2 -1
  66. package/dist/types-ts4.5/ui/TableMenu/column/items/ColumnToggleSection.d.ts +2 -1
  67. package/dist/types-ts4.5/ui/TableMenu/column/items/DeleteColumnItem.d.ts +2 -1
  68. package/dist/types-ts4.5/ui/TableMenu/column/items/DistributeColumnsItem.d.ts +2 -1
  69. package/dist/types-ts4.5/ui/TableMenu/column/items/HeaderColumnToggleItem.d.ts +7 -3
  70. package/dist/types-ts4.5/ui/TableMenu/column/items/MoveColumnLeftItem.d.ts +3 -0
  71. package/dist/types-ts4.5/ui/TableMenu/column/items/MoveColumnRightItem.d.ts +2 -1
  72. package/dist/types-ts4.5/ui/TableMenu/column/items/SortDecreasingItem.d.ts +2 -1
  73. package/dist/types-ts4.5/ui/TableMenu/column/items/SortIncreasingItem.d.ts +2 -1
  74. package/dist/types-ts4.5/ui/TableMenu/column/keys.d.ts +1 -0
  75. package/package.json +3 -3
@@ -1,10 +1,12 @@
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 { toggleHeaderColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
6
9
  import { useTableMenuContext } from '../../shared/TableMenuContext';
7
-
8
10
  /**
9
11
  * Header column toggle is only visible when the first column is the entire
10
12
  * selection.
@@ -13,20 +15,53 @@ import { useTableMenuContext } from '../../shared/TableMenuContext';
13
15
  * `ColumnBackgroundSection` (which drops its leading separator alongside)
14
16
  * can stay in lockstep with this rule without redefining it.
15
17
  */
16
- export const shouldShowHeaderColumnToggle = tableMenuContext => (tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn) === true && tableMenuContext.selectedColumnCount === 1;
17
- export const HeaderColumnToggleItem = () => {
18
+ export const shouldShowHeaderColumnToggle = ({
19
+ isFirstColumn,
20
+ isHeaderColumnAllowed,
21
+ selectedColumnCount
22
+ }) => isHeaderColumnAllowed === true && isFirstColumn === true && selectedColumnCount === 1;
23
+ export const HeaderColumnToggleItem = props => {
24
+ const {
25
+ api
26
+ } = props;
27
+ const {
28
+ editorView
29
+ } = useEditorToolbar();
18
30
  const tableMenuContext = useTableMenuContext();
31
+ const {
32
+ isHeaderColumnAllowed,
33
+ isHeaderColumnEnabled
34
+ } = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
35
+ var _states$tableState, _states$tableState$pl, _states$tableState2;
36
+ return {
37
+ isHeaderColumnAllowed: (_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.allowHeaderColumn,
38
+ isHeaderColumnEnabled: (_states$tableState2 = states.tableState) === null || _states$tableState2 === void 0 ? void 0 : _states$tableState2.isHeaderColumnEnabled
39
+ };
40
+ });
19
41
  const {
20
42
  formatMessage
21
43
  } = useIntl();
22
44
  const label = formatMessage(messages.headerColumn);
23
- if (!shouldShowHeaderColumnToggle(tableMenuContext)) {
45
+ const handleClick = () => {
46
+ var _api$analytics;
47
+ if (!editorView) {
48
+ return;
49
+ }
50
+ toggleHeaderColumnWithAnalytics(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);
51
+ };
52
+ if (!shouldShowHeaderColumnToggle({
53
+ isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn,
54
+ isHeaderColumnAllowed,
55
+ selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount
56
+ })) {
24
57
  return null;
25
58
  }
26
59
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
60
+ onClick: handleClick,
27
61
  elemAfter: /*#__PURE__*/React.createElement(Toggle, {
28
62
  label: label,
29
- isChecked: false
63
+ isChecked: !!isHeaderColumnEnabled,
64
+ onChange: handleClick
30
65
  })
31
66
  }, label);
32
67
  };
@@ -0,0 +1,65 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
5
+ import { moveColumnLeft, tooltip } from '@atlaskit/editor-common/keymaps';
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';
9
+ import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
10
+ import TableColumnMoveLeftIcon from '@atlaskit/icon/core/table-column-move-left';
11
+ import { moveSourceWithAnalytics } from '../../../../pm-plugins/drag-and-drop/commands-with-analytics';
12
+ import { getPluginState } from '../../../../pm-plugins/plugin-factory';
13
+ import { getSelectedColumnIndexes } from '../../../../pm-plugins/utils/selection';
14
+ import { TABLE_COLUMN } from '../../shared/consts';
15
+ import { useTableMenuContext } from '../../shared/TableMenuContext';
16
+ const shouldShowMoveColumnLeft = isFirstColumn => !isFirstColumn;
17
+ export const MoveColumnLeftItem = props => {
18
+ var _tableMenuContext$sel, _tooltip;
19
+ const {
20
+ api
21
+ } = props;
22
+ const {
23
+ editorView
24
+ } = useEditorToolbar();
25
+ const tableMenuContext = useTableMenuContext();
26
+ const {
27
+ tableNode
28
+ } = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], states => {
29
+ var _states$tableState;
30
+ return {
31
+ tableNode: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.tableNode
32
+ };
33
+ });
34
+ const selectedColumnCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
35
+ const {
36
+ formatMessage
37
+ } = useIntl();
38
+ const handleClick = () => {
39
+ var _api$analytics, _api$accessibilityUti;
40
+ if (!editorView) {
41
+ return;
42
+ }
43
+ const selectionRect = getSelectionRect(editorView.state.selection);
44
+ if (!selectionRect) {
45
+ return;
46
+ }
47
+ 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_COLUMN, getSelectedColumnIndexes(selectionRect), selectionRect.left - 1)(editorView.state, editorView.dispatch);
48
+ };
49
+ if (!tableNode || !shouldShowMoveColumnLeft(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn)) {
50
+ return null;
51
+ }
52
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
53
+ onClick: handleClick,
54
+ elemBefore: /*#__PURE__*/React.createElement(TableColumnMoveLeftIcon, {
55
+ color: "currentColor",
56
+ label: "",
57
+ size: "small"
58
+ }),
59
+ elemAfter: /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
60
+ shortcut: (_tooltip = tooltip(moveColumnLeft)) !== null && _tooltip !== void 0 ? _tooltip : ''
61
+ })
62
+ }, formatMessage(messages.moveColumnLeft, {
63
+ 0: selectedColumnCount
64
+ }));
65
+ };
@@ -1,14 +1,55 @@
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 { moveColumnRight, 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 { TableColumnMoveRightIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- export const MoveColumnRightItem = () => {
7
- var _tooltip;
10
+ import { moveSourceWithAnalytics } from '../../../../pm-plugins/drag-and-drop/commands-with-analytics';
11
+ import { getPluginState } from '../../../../pm-plugins/plugin-factory';
12
+ import { getSelectedColumnIndexes } from '../../../../pm-plugins/utils/selection';
13
+ import { TABLE_COLUMN } from '../../shared/consts';
14
+ import { useTableMenuContext } from '../../shared/TableMenuContext';
15
+ const shouldShowMoveColumnRight = isLastColumn => !isLastColumn;
16
+ export const MoveColumnRightItem = props => {
17
+ var _tableMenuContext$sel, _tooltip;
18
+ const {
19
+ api
20
+ } = props;
21
+ const {
22
+ editorView
23
+ } = useEditorToolbar();
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 selectedColumnCount = (_tableMenuContext$sel = tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount) !== null && _tableMenuContext$sel !== void 0 ? _tableMenuContext$sel : 1;
8
34
  const {
9
35
  formatMessage
10
36
  } = useIntl();
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_COLUMN, getSelectedColumnIndexes(selectionRect), selectionRect.right)(editorView.state, editorView.dispatch);
47
+ };
48
+ if (!tableNode || !shouldShowMoveColumnRight(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isLastColumn)) {
49
+ return null;
50
+ }
11
51
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
52
+ onClick: handleClick,
12
53
  elemBefore: /*#__PURE__*/React.createElement(TableColumnMoveRightIcon, {
13
54
  color: "currentColor",
14
55
  label: "",
@@ -18,6 +59,6 @@ export const MoveColumnRightItem = () => {
18
59
  shortcut: (_tooltip = tooltip(moveColumnRight)) !== null && _tooltip !== void 0 ? _tooltip : ''
19
60
  })
20
61
  }, formatMessage(messages.moveColumnRight, {
21
- 0: 1
62
+ 0: selectedColumnCount
22
63
  }));
23
64
  };
@@ -1,14 +1,37 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
4
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
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';
4
8
  import { ArrowDownIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
9
+ import { sortColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
5
10
  import { useTableMenuContext } from '../../shared/TableMenuContext';
6
- export const SortDecreasingItem = () => {
11
+ export const SortDecreasingItem = ({
12
+ api
13
+ }) => {
14
+ const {
15
+ editorView
16
+ } = useEditorToolbar();
7
17
  const tableMenuContext = useTableMenuContext();
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 columnIndex = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left;
28
+ if (columnIndex === undefined) {
29
+ return;
30
+ }
31
+ sortColumnWithAnalytics(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, columnIndex, SortOrder.DESC)(editorView.state, editorView.dispatch);
32
+ };
11
33
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
34
+ onClick: handleClick,
12
35
  isDisabled: Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable),
13
36
  elemBefore: /*#__PURE__*/React.createElement(ArrowDownIcon, {
14
37
  color: "currentColor",
@@ -1,14 +1,37 @@
1
1
  import React from 'react';
2
2
  import { useIntl } from 'react-intl';
3
+ import { TableSortOrder as SortOrder } from '@atlaskit/custom-steps';
4
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
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';
4
8
  import { ArrowUpIcon, ToolbarDropdownItem } from '@atlaskit/editor-toolbar';
9
+ import { sortColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
5
10
  import { useTableMenuContext } from '../../shared/TableMenuContext';
6
- export const SortIncreasingItem = () => {
11
+ export const SortIncreasingItem = ({
12
+ api
13
+ }) => {
14
+ const {
15
+ editorView
16
+ } = useEditorToolbar();
7
17
  const tableMenuContext = useTableMenuContext();
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 columnIndex = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left;
28
+ if (columnIndex === undefined) {
29
+ return;
30
+ }
31
+ sortColumnWithAnalytics(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, columnIndex, SortOrder.ASC)(editorView.state, editorView.dispatch);
32
+ };
11
33
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
34
+ onClick: handleClick,
12
35
  isDisabled: Boolean(tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.hasMergedCellsInTable),
13
36
  elemBefore: /*#__PURE__*/React.createElement(ArrowUpIcon, {
14
37
  color: "currentColor",
@@ -56,6 +56,10 @@ export const ADD_COLUMN_RIGHT_ITEM = {
56
56
  type: 'menu-item',
57
57
  key: 'add-column-right'
58
58
  };
59
+ export const MOVE_COLUMN_LEFT_ITEM = {
60
+ type: 'menu-item',
61
+ key: 'move-column-left'
62
+ };
59
63
  export const MOVE_COLUMN_RIGHT_ITEM = {
60
64
  type: 'menu-item',
61
65
  key: 'move-column-right'
@@ -84,8 +88,9 @@ export const COLUMN_SORT_SECTION_RANK = {
84
88
  export const COLUMN_ADD_SECTION_RANK = {
85
89
  [ADD_COLUMN_LEFT_ITEM.key]: 100,
86
90
  [ADD_COLUMN_RIGHT_ITEM.key]: 200,
87
- [MOVE_COLUMN_RIGHT_ITEM.key]: 300,
88
- [DISTRIBUTE_COLUMNS_ITEM.key]: 400
91
+ [MOVE_COLUMN_LEFT_ITEM.key]: 300,
92
+ [MOVE_COLUMN_RIGHT_ITEM.key]: 400,
93
+ [DISTRIBUTE_COLUMNS_ITEM.key]: 500
89
94
  };
90
95
  export const COLUMN_DANGER_SECTION_RANK = {
91
96
  [CLEAR_CELLS_ITEM.key]: 100,
@@ -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 = params => [...getRowMenuComponents(params), ...getColumnMenuComponents(), ...getCellMenuComponents(), ...getSharedItems(params)];
5
+ export const getTableMenuComponents = params => [...getRowMenuComponents(params), ...getColumnMenuComponents(params), ...getCellMenuComponents(), ...getSharedItems(params)];
@@ -116,6 +116,9 @@ var tablePlugin = function tablePlugin(_ref) {
116
116
  isHeaderRowEnabled: tablePluginState.isHeaderRowEnabled,
117
117
  isHeaderColumnEnabled: tablePluginState.isHeaderColumnEnabled,
118
118
  isNumberColumnEnabled: tablePluginState.isNumberColumnEnabled,
119
+ isCommentEditor: tablePluginState.isCommentEditor,
120
+ isTableScalingEnabled: tablePluginState.isTableScalingEnabled,
121
+ isTableFixedColumnWidthsOptionEnabled: isTableFixedColumnWidthsOptionEnabled,
119
122
  ordering: tablePluginState.ordering,
120
123
  isResizing: !!(tableResizingPluginState !== null && tableResizingPluginState !== void 0 && tableResizingPluginState.dragging || tableWidthResizingPluginState !== null && tableWidthResizingPluginState !== void 0 && tableWidthResizingPluginState.resizing),
121
124
  isTableResizing: tableWidthResizingPluginState === null || tableWidthResizingPluginState === void 0 ? void 0 : tableWidthResizingPluginState.resizing,
@@ -7,11 +7,13 @@ import { ColumnToggleSection } from './items/ColumnToggleSection';
7
7
  import { DeleteColumnItem } from './items/DeleteColumnItem';
8
8
  import { DistributeColumnsItem } from './items/DistributeColumnsItem';
9
9
  import { HeaderColumnToggleItem } from './items/HeaderColumnToggleItem';
10
+ import { MoveColumnLeftItem } from './items/MoveColumnLeftItem';
10
11
  import { MoveColumnRightItem } from './items/MoveColumnRightItem';
11
12
  import { SortDecreasingItem } from './items/SortDecreasingItem';
12
13
  import { SortIncreasingItem } from './items/SortIncreasingItem';
13
- import { COLUMN_MENU, COLUMN_TOGGLE_SECTION, COLUMN_BACKGROUND_SECTION, COLUMN_SORT_SECTION, COLUMN_ADD_SECTION, COLUMN_DANGER_SECTION, COLUMN_SECTION_RANK, HEADER_COLUMN_TOGGLE_ITEM, SORT_INCREASING_ITEM, SORT_DECREASING_ITEM, ADD_COLUMN_LEFT_ITEM, ADD_COLUMN_RIGHT_ITEM, MOVE_COLUMN_RIGHT_ITEM, DISTRIBUTE_COLUMNS_ITEM, DELETE_COLUMN_ITEM, COLUMN_TOGGLE_SECTION_RANK, COLUMN_SORT_SECTION_RANK, COLUMN_ADD_SECTION_RANK, COLUMN_DANGER_SECTION_RANK } from './keys';
14
- export var getColumnMenuComponents = function getColumnMenuComponents() {
14
+ import { COLUMN_MENU, COLUMN_TOGGLE_SECTION, COLUMN_BACKGROUND_SECTION, COLUMN_SORT_SECTION, COLUMN_ADD_SECTION, COLUMN_DANGER_SECTION, COLUMN_SECTION_RANK, HEADER_COLUMN_TOGGLE_ITEM, SORT_INCREASING_ITEM, SORT_DECREASING_ITEM, ADD_COLUMN_LEFT_ITEM, ADD_COLUMN_RIGHT_ITEM, MOVE_COLUMN_LEFT_ITEM, MOVE_COLUMN_RIGHT_ITEM, DISTRIBUTE_COLUMNS_ITEM, DELETE_COLUMN_ITEM, COLUMN_TOGGLE_SECTION_RANK, COLUMN_SORT_SECTION_RANK, COLUMN_ADD_SECTION_RANK, COLUMN_DANGER_SECTION_RANK } from './keys';
15
+ export var getColumnMenuComponents = function getColumnMenuComponents(_ref) {
16
+ var api = _ref.api;
15
17
  return [
16
18
  // --- Menu surface ---
17
19
  {
@@ -28,7 +30,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
28
30
  rank: COLUMN_SECTION_RANK[COLUMN_TOGGLE_SECTION.key]
29
31
  }],
30
32
  component: function component(props) {
31
- return /*#__PURE__*/React.createElement(ColumnToggleSection, null, props.children);
33
+ return /*#__PURE__*/React.createElement(ColumnToggleSection, {
34
+ api: api
35
+ }, props.children);
32
36
  }
33
37
  }, {
34
38
  type: HEADER_COLUMN_TOGGLE_ITEM.type,
@@ -39,7 +43,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
39
43
  rank: COLUMN_TOGGLE_SECTION_RANK[HEADER_COLUMN_TOGGLE_ITEM.key]
40
44
  }],
41
45
  component: function component() {
42
- return /*#__PURE__*/React.createElement(HeaderColumnToggleItem, null);
46
+ return /*#__PURE__*/React.createElement(HeaderColumnToggleItem, {
47
+ api: api
48
+ });
43
49
  }
44
50
  },
45
51
  // --- Background color section ---
@@ -52,7 +58,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
52
58
  rank: COLUMN_SECTION_RANK[COLUMN_BACKGROUND_SECTION.key]
53
59
  }],
54
60
  component: function component(props) {
55
- return /*#__PURE__*/React.createElement(ColumnBackgroundSection, null, props.children);
61
+ return /*#__PURE__*/React.createElement(ColumnBackgroundSection, {
62
+ api: api
63
+ }, props.children);
56
64
  }
57
65
  },
58
66
  // --- Sort section ---
@@ -78,7 +86,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
78
86
  rank: COLUMN_SORT_SECTION_RANK[SORT_INCREASING_ITEM.key]
79
87
  }],
80
88
  component: function component() {
81
- return /*#__PURE__*/React.createElement(SortIncreasingItem, null);
89
+ return /*#__PURE__*/React.createElement(SortIncreasingItem, {
90
+ api: api
91
+ });
82
92
  }
83
93
  }, {
84
94
  type: SORT_DECREASING_ITEM.type,
@@ -89,7 +99,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
89
99
  rank: COLUMN_SORT_SECTION_RANK[SORT_DECREASING_ITEM.key]
90
100
  }],
91
101
  component: function component() {
92
- return /*#__PURE__*/React.createElement(SortDecreasingItem, null);
102
+ return /*#__PURE__*/React.createElement(SortDecreasingItem, {
103
+ api: api
104
+ });
93
105
  }
94
106
  },
95
107
  // --- Add / Move section ---
@@ -115,7 +127,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
115
127
  rank: COLUMN_ADD_SECTION_RANK[ADD_COLUMN_LEFT_ITEM.key]
116
128
  }],
117
129
  component: function component() {
118
- return /*#__PURE__*/React.createElement(AddColumnLeftItem, null);
130
+ return /*#__PURE__*/React.createElement(AddColumnLeftItem, {
131
+ api: api
132
+ });
119
133
  }
120
134
  }, {
121
135
  type: ADD_COLUMN_RIGHT_ITEM.type,
@@ -126,7 +140,22 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
126
140
  rank: COLUMN_ADD_SECTION_RANK[ADD_COLUMN_RIGHT_ITEM.key]
127
141
  }],
128
142
  component: function component() {
129
- return /*#__PURE__*/React.createElement(AddColumnRightItem, null);
143
+ return /*#__PURE__*/React.createElement(AddColumnRightItem, {
144
+ api: api
145
+ });
146
+ }
147
+ }, {
148
+ type: MOVE_COLUMN_LEFT_ITEM.type,
149
+ key: MOVE_COLUMN_LEFT_ITEM.key,
150
+ parents: [{
151
+ type: COLUMN_ADD_SECTION.type,
152
+ key: COLUMN_ADD_SECTION.key,
153
+ rank: COLUMN_ADD_SECTION_RANK[MOVE_COLUMN_LEFT_ITEM.key]
154
+ }],
155
+ component: function component() {
156
+ return /*#__PURE__*/React.createElement(MoveColumnLeftItem, {
157
+ api: api
158
+ });
130
159
  }
131
160
  }, {
132
161
  type: MOVE_COLUMN_RIGHT_ITEM.type,
@@ -137,7 +166,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
137
166
  rank: COLUMN_ADD_SECTION_RANK[MOVE_COLUMN_RIGHT_ITEM.key]
138
167
  }],
139
168
  component: function component() {
140
- return /*#__PURE__*/React.createElement(MoveColumnRightItem, null);
169
+ return /*#__PURE__*/React.createElement(MoveColumnRightItem, {
170
+ api: api
171
+ });
141
172
  }
142
173
  }, {
143
174
  type: DISTRIBUTE_COLUMNS_ITEM.type,
@@ -148,7 +179,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
148
179
  rank: COLUMN_ADD_SECTION_RANK[DISTRIBUTE_COLUMNS_ITEM.key]
149
180
  }],
150
181
  component: function component() {
151
- return /*#__PURE__*/React.createElement(DistributeColumnsItem, null);
182
+ return /*#__PURE__*/React.createElement(DistributeColumnsItem, {
183
+ api: api
184
+ });
152
185
  }
153
186
  },
154
187
  // --- Danger section (Clear cells, Delete column) ---
@@ -174,7 +207,9 @@ export var getColumnMenuComponents = function getColumnMenuComponents() {
174
207
  rank: COLUMN_DANGER_SECTION_RANK[DELETE_COLUMN_ITEM.key]
175
208
  }],
176
209
  component: function component() {
177
- return /*#__PURE__*/React.createElement(DeleteColumnItem, null);
210
+ return /*#__PURE__*/React.createElement(DeleteColumnItem, {
211
+ api: api
212
+ });
178
213
  }
179
214
  }];
180
215
  };
@@ -1,13 +1,46 @@
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 { addColumnBefore, 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 { TableColumnAddLeftIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- export var AddColumnLeftItem = function AddColumnLeftItem() {
10
+ import { insertColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
11
+ export var AddColumnLeftItem = function AddColumnLeftItem(_ref) {
7
12
  var _tooltip;
13
+ var api = _ref.api;
14
+ var _useEditorToolbar = useEditorToolbar(),
15
+ editorView = _useEditorToolbar.editorView;
8
16
  var _useIntl = useIntl(),
9
17
  formatMessage = _useIntl.formatMessage;
18
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], function (states) {
19
+ var tableState = states.tableState;
20
+ return {
21
+ isCommentEditor: tableState === null || tableState === void 0 ? void 0 : tableState.isCommentEditor,
22
+ isTableFixedColumnWidthsOptionEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isTableFixedColumnWidthsOptionEnabled,
23
+ isTableScalingEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isTableScalingEnabled
24
+ };
25
+ }),
26
+ isCommentEditor = _useSharedPluginState.isCommentEditor,
27
+ isTableFixedColumnWidthsOptionEnabled = _useSharedPluginState.isTableFixedColumnWidthsOptionEnabled,
28
+ isTableScalingEnabled = _useSharedPluginState.isTableScalingEnabled;
29
+ var handleClick = function handleClick() {
30
+ var _api$analytics;
31
+ if (!editorView) {
32
+ return;
33
+ }
34
+ var selectionRect = getSelectionRect(editorView.state.selection);
35
+ var index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.left;
36
+ if (index === undefined) {
37
+ return;
38
+ }
39
+ var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
40
+ insertColumnWithAnalytics(api, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, isCommentEditor)(INPUT_METHOD.TABLE_CONTEXT_MENU, index)(editorView.state, editorView.dispatch, editorView);
41
+ };
10
42
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
43
+ onClick: handleClick,
11
44
  elemBefore: /*#__PURE__*/React.createElement(TableColumnAddLeftIcon, {
12
45
  color: "currentColor",
13
46
  label: "",
@@ -1,13 +1,46 @@
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 { addColumnAfter, 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 { TableColumnAddRightIcon, ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
6
- export var AddColumnRightItem = function AddColumnRightItem() {
10
+ import { insertColumnWithAnalytics } from '../../../../pm-plugins/commands/commands-with-analytics';
11
+ export var AddColumnRightItem = function AddColumnRightItem(_ref) {
7
12
  var _tooltip;
13
+ var api = _ref.api;
14
+ var _useEditorToolbar = useEditorToolbar(),
15
+ editorView = _useEditorToolbar.editorView;
8
16
  var _useIntl = useIntl(),
9
17
  formatMessage = _useIntl.formatMessage;
18
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], function (states) {
19
+ var tableState = states.tableState;
20
+ return {
21
+ isCommentEditor: tableState === null || tableState === void 0 ? void 0 : tableState.isCommentEditor,
22
+ isTableFixedColumnWidthsOptionEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isTableFixedColumnWidthsOptionEnabled,
23
+ isTableScalingEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isTableScalingEnabled
24
+ };
25
+ }),
26
+ isCommentEditor = _useSharedPluginState.isCommentEditor,
27
+ isTableFixedColumnWidthsOptionEnabled = _useSharedPluginState.isTableFixedColumnWidthsOptionEnabled,
28
+ isTableScalingEnabled = _useSharedPluginState.isTableScalingEnabled;
29
+ var handleClick = function handleClick() {
30
+ var _api$analytics;
31
+ if (!editorView) {
32
+ return;
33
+ }
34
+ var selectionRect = getSelectionRect(editorView.state.selection);
35
+ var index = selectionRect === null || selectionRect === void 0 ? void 0 : selectionRect.right;
36
+ if (index === undefined) {
37
+ return;
38
+ }
39
+ var shouldUseIncreasedScalingPercent = isTableScalingEnabled && (isTableFixedColumnWidthsOptionEnabled || isCommentEditor);
40
+ insertColumnWithAnalytics(api, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent, isCommentEditor)(INPUT_METHOD.TABLE_CONTEXT_MENU, index)(editorView.state, editorView.dispatch, editorView);
41
+ };
10
42
  return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
43
+ onClick: handleClick,
11
44
  elemBefore: /*#__PURE__*/React.createElement(TableColumnAddRightIcon, {
12
45
  color: "currentColor",
13
46
  label: "",
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
2
3
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
4
  import { useTableMenuContext } from '../../shared/TableMenuContext';
4
5
  import { shouldShowHeaderColumnToggle } from './HeaderColumnToggleItem';
@@ -10,9 +11,21 @@ import { shouldShowHeaderColumnToggle } from './HeaderColumnToggleItem';
10
11
  * the very top of the menu.
11
12
  */
12
13
  export var ColumnBackgroundSection = function ColumnBackgroundSection(_ref) {
13
- var children = _ref.children;
14
+ var api = _ref.api,
15
+ children = _ref.children;
14
16
  var tableMenuContext = useTableMenuContext();
15
- var hasSeparator = shouldShowHeaderColumnToggle(tableMenuContext);
17
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], function (states) {
18
+ var _states$tableState;
19
+ return {
20
+ isHeaderColumnAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 || (_states$tableState = _states$tableState.pluginConfig) === null || _states$tableState === void 0 ? void 0 : _states$tableState.allowHeaderColumn
21
+ };
22
+ }),
23
+ isHeaderColumnAllowed = _useSharedPluginState.isHeaderColumnAllowed;
24
+ var hasSeparator = shouldShowHeaderColumnToggle({
25
+ isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn,
26
+ isHeaderColumnAllowed: isHeaderColumnAllowed,
27
+ selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount
28
+ });
16
29
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
17
30
  hasSeparator: hasSeparator
18
31
  }, children);
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
2
3
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
4
  import { useTableMenuContext } from '../../shared/TableMenuContext';
4
5
  import { shouldShowHeaderColumnToggle } from './HeaderColumnToggleItem';
@@ -9,9 +10,21 @@ import { shouldShowHeaderColumnToggle } from './HeaderColumnToggleItem';
9
10
  * empty wrapper (and so the section below can drop its leading separator).
10
11
  */
11
12
  export var ColumnToggleSection = function ColumnToggleSection(_ref) {
12
- var children = _ref.children;
13
+ var api = _ref.api,
14
+ children = _ref.children;
13
15
  var tableMenuContext = useTableMenuContext();
14
- if (!shouldShowHeaderColumnToggle(tableMenuContext)) {
16
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api !== null && api !== void 0 ? api : undefined, ['table'], function (states) {
17
+ var _states$tableState;
18
+ return {
19
+ isHeaderColumnAllowed: (_states$tableState = states.tableState) === null || _states$tableState === void 0 || (_states$tableState = _states$tableState.pluginConfig) === null || _states$tableState === void 0 ? void 0 : _states$tableState.allowHeaderColumn
20
+ };
21
+ }),
22
+ isHeaderColumnAllowed = _useSharedPluginState.isHeaderColumnAllowed;
23
+ if (!shouldShowHeaderColumnToggle({
24
+ isFirstColumn: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.isFirstColumn,
25
+ isHeaderColumnAllowed: isHeaderColumnAllowed,
26
+ selectedColumnCount: tableMenuContext === null || tableMenuContext === void 0 ? void 0 : tableMenuContext.selectedColumnCount
27
+ })) {
15
28
  return null;
16
29
  }
17
30
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, children);