@atlaskit/editor-plugin-table 13.0.5 → 13.0.6

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 (37) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +19 -98
  3. package/dist/cjs/nodeviews/TableContainer.js +14 -53
  4. package/dist/cjs/nodeviews/TableResizer.js +2 -15
  5. package/dist/cjs/tablePlugin.js +30 -213
  6. package/dist/cjs/ui/DragHandle/index.js +9 -26
  7. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -20
  8. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +6 -19
  9. package/dist/cjs/ui/TableFloatingControls/FloatingControlsWithSelection.js +7 -20
  10. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +7 -20
  11. package/dist/cjs/ui/global-styles.js +4 -17
  12. package/dist/cjs/ui/icons/SortingIconWrapper.js +2 -15
  13. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +21 -102
  14. package/dist/es2019/nodeviews/TableContainer.js +11 -54
  15. package/dist/es2019/nodeviews/TableResizer.js +2 -17
  16. package/dist/es2019/tablePlugin.js +19 -211
  17. package/dist/es2019/ui/DragHandle/index.js +8 -27
  18. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +7 -22
  19. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +7 -22
  20. package/dist/es2019/ui/TableFloatingControls/FloatingControlsWithSelection.js +7 -22
  21. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +7 -22
  22. package/dist/es2019/ui/global-styles.js +6 -21
  23. package/dist/es2019/ui/icons/SortingIconWrapper.js +3 -18
  24. package/dist/esm/nodeviews/TableComponentWithSharedState.js +20 -99
  25. package/dist/esm/nodeviews/TableContainer.js +15 -54
  26. package/dist/esm/nodeviews/TableResizer.js +3 -16
  27. package/dist/esm/tablePlugin.js +24 -208
  28. package/dist/esm/ui/DragHandle/index.js +10 -27
  29. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +8 -21
  30. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +7 -20
  31. package/dist/esm/ui/TableFloatingControls/FloatingControlsWithSelection.js +8 -21
  32. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +8 -21
  33. package/dist/esm/ui/global-styles.js +5 -18
  34. package/dist/esm/ui/icons/SortingIconWrapper.js +3 -16
  35. package/dist/types/nodeviews/TableComponentWithSharedState.d.ts +1 -1
  36. package/dist/types-ts4.5/nodeviews/TableComponentWithSharedState.d.ts +1 -1
  37. package/package.json +2 -2
@@ -1,14 +1,28 @@
1
1
  import React from 'react';
2
- import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
2
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
3
  import { findTable } from '@atlaskit/editor-tables';
4
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
5
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
4
  import TableComponent from './TableComponent';
7
5
 
8
6
  // Ignored via go/ees005
9
7
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
8
 
11
- var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
9
+ /**
10
+ * Use useSharedPluginState to control re-renders from plugin dependencies
11
+ */
12
+ export var TableComponentWithSharedState = function TableComponentWithSharedState(_ref) {
13
+ var view = _ref.view,
14
+ options = _ref.options,
15
+ getNode = _ref.getNode,
16
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
17
+ api = _ref.api,
18
+ getEditorFeatureFlags = _ref.getEditorFeatureFlags,
19
+ eventDispatcher = _ref.eventDispatcher,
20
+ allowColumnResizing = _ref.allowColumnResizing,
21
+ allowControls = _ref.allowControls,
22
+ getPos = _ref.getPos,
23
+ forwardRef = _ref.forwardRef,
24
+ allowTableAlignment = _ref.allowTableAlignment,
25
+ allowTableResizing = _ref.allowTableResizing;
12
26
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['table', 'width', 'media', 'selection', 'editorViewMode', 'interaction'], function (states) {
13
27
  var _states$tableState, _states$tableState2, _states$tableState3, _states$tableState4, _states$tableState5, _states$tableState6, _states$tableState7, _states$tableState8, _states$tableState9, _states$tableState0, _states$tableState1, _states$mediaState, _states$selectionStat, _states$editorViewMod, _states$widthState, _states$widthState2, _states$interactionSt;
14
28
  return {
@@ -54,97 +68,7 @@ var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
54
68
  mode = _useSharedPluginState.mode,
55
69
  selection = _useSharedPluginState.selection,
56
70
  width = _useSharedPluginState.width;
57
- return {
58
- tableState: undefined,
59
- widthState: undefined,
60
- isTableResizing: isTableResizing,
61
- isHeaderColumnEnabled: isHeaderColumnEnabled,
62
- isHeaderRowEnabled: isHeaderRowEnabled,
63
- ordering: ordering,
64
- isResizing: isResizing,
65
- isInDanger: isInDanger,
66
- hoveredCell: hoveredCell,
67
- hoveredRows: hoveredRows,
68
- isTableHovered: isTableHovered,
69
- isWholeTableInDanger: isWholeTableInDanger,
70
- isFullscreen: isFullscreen,
71
- selection: selection,
72
- mode: mode,
73
- width: width,
74
- lineLength: lineLength,
75
- interaction: interaction
76
- };
77
- }, function (api) {
78
- var _useSharedPluginState2 = useSharedPluginState(api, ['width', 'table', 'media', 'selection', 'editorViewMode', 'interaction']),
79
- widthState = _useSharedPluginState2.widthState,
80
- tableState = _useSharedPluginState2.tableState,
81
- mediaState = _useSharedPluginState2.mediaState,
82
- selectionState = _useSharedPluginState2.selectionState,
83
- editorViewModeState = _useSharedPluginState2.editorViewModeState,
84
- interactionState = _useSharedPluginState2.interactionState;
85
- var tableStateInternal = tableState;
86
- return {
87
- tableState: tableState,
88
- widthState: widthState,
89
- isTableResizing: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.isTableResizing,
90
- isHeaderColumnEnabled: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.isHeaderColumnEnabled,
91
- isHeaderRowEnabled: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.isHeaderRowEnabled,
92
- ordering: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.ordering,
93
- isResizing: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.isResizing,
94
- isInDanger: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.isInDanger,
95
- hoveredCell: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.hoveredCell,
96
- hoveredRows: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.hoveredRows,
97
- isTableHovered: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.isTableHovered,
98
- isWholeTableInDanger: tableStateInternal === null || tableStateInternal === void 0 ? void 0 : tableStateInternal.isWholeTableInDanger,
99
- isFullscreen: mediaState === null || mediaState === void 0 ? void 0 : mediaState.isFullscreen,
100
- selection: selectionState === null || selectionState === void 0 ? void 0 : selectionState.selection,
101
- mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode,
102
- width: widthState === null || widthState === void 0 ? void 0 : widthState.width,
103
- lineLength: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
104
- interaction: interactionState === null || interactionState === void 0 ? void 0 : interactionState.interactionState
105
- };
106
- });
107
-
108
- /**
109
- * Use useSharedPluginState to control re-renders from plugin dependencies
110
- */
111
- export var TableComponentWithSharedState = function TableComponentWithSharedState(_ref) {
112
- var view = _ref.view,
113
- options = _ref.options,
114
- getNode = _ref.getNode,
115
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
116
- api = _ref.api,
117
- getEditorFeatureFlags = _ref.getEditorFeatureFlags,
118
- eventDispatcher = _ref.eventDispatcher,
119
- allowColumnResizing = _ref.allowColumnResizing,
120
- allowControls = _ref.allowControls,
121
- getPos = _ref.getPos,
122
- forwardRef = _ref.forwardRef,
123
- allowTableAlignment = _ref.allowTableAlignment,
124
- allowTableResizing = _ref.allowTableResizing;
125
- var _useSharedState = useSharedState(api),
126
- tableState = _useSharedState.tableState,
127
- widthState = _useSharedState.widthState,
128
- mode = _useSharedState.mode,
129
- hoveredCell = _useSharedState.hoveredCell,
130
- hoveredRows = _useSharedState.hoveredRows,
131
- isFullscreen = _useSharedState.isFullscreen,
132
- isHeaderColumnEnabled = _useSharedState.isHeaderColumnEnabled,
133
- isHeaderRowEnabled = _useSharedState.isHeaderRowEnabled,
134
- isInDanger = _useSharedState.isInDanger,
135
- isResizing = _useSharedState.isResizing,
136
- isTableHovered = _useSharedState.isTableHovered,
137
- isTableResizing = _useSharedState.isTableResizing,
138
- isWholeTableInDanger = _useSharedState.isWholeTableInDanger,
139
- lineLength = _useSharedState.lineLength,
140
- ordering = _useSharedState.ordering,
141
- selection = _useSharedState.selection,
142
- width = _useSharedState.width,
143
- interaction = _useSharedState.interaction;
144
71
  var isLivePageViewMode = mode === 'view';
145
- if (expValEquals('platform_editor_usesharedpluginstatewithselector', 'isEnabled', false) && !tableState) {
146
- return null;
147
- }
148
72
 
149
73
  /**
150
74
  * ED-19810
@@ -178,13 +102,10 @@ export var TableComponentWithSharedState = function TableComponentWithSharedStat
178
102
  ordering: ordering,
179
103
  isResizing: isResizing,
180
104
  getNode: getNode,
181
- containerWidth: editorExperiment('platform_editor_usesharedpluginstatewithselector', true) ? {
105
+ containerWidth: {
182
106
  width: width !== null && width !== void 0 ? width : 0,
183
107
  lineLength: lineLength
184
- } :
185
- // Ignored via go/ees005
186
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
187
- widthState,
108
+ },
188
109
  contentDOM: forwardRef,
189
110
  getEditorFeatureFlags: getEditorFeatureFlags,
190
111
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
@@ -4,7 +4,7 @@ import React, { forwardRef, useCallback, useEffect, useMemo, useRef, useState }
4
4
  import classNames from 'classnames';
5
5
  import { CHANGE_ALIGNMENT_REASON, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { isSSR } from '@atlaskit/editor-common/core-utils';
7
- import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
7
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
8
8
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
9
9
  import { akEditorDefaultLayoutWidth, akEditorGutterPaddingDynamic, akEditorGutterPaddingReduced, akEditorFullPageNarrowBreakout, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
10
10
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -36,7 +36,13 @@ var InnerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
36
36
  "data-testid": "table-container"
37
37
  }, children);
38
38
  });
39
- var useAlignmentTableContainerSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
39
+ var AlignmentTableContainer = function AlignmentTableContainer(_ref2) {
40
+ var node = _ref2.node,
41
+ children = _ref2.children,
42
+ pluginInjectionApi = _ref2.pluginInjectionApi,
43
+ getPos = _ref2.getPos,
44
+ editorView = _ref2.editorView;
45
+ var alignment = node.attrs.layout !== ALIGN_START ? ALIGN_CENTER : ALIGN_START;
40
46
  var _useSharedPluginState = useSharedPluginStateWithSelector(pluginInjectionApi, ['table'], function (states) {
41
47
  var _states$tableState, _states$tableState2;
42
48
  return {
@@ -46,35 +52,7 @@ var useAlignmentTableContainerSharedState = sharedPluginStateHookMigratorFactory
46
52
  }),
47
53
  isFullWidthModeEnabled = _useSharedPluginState.isFullWidthModeEnabled,
48
54
  wasFullWidthModeEnabled = _useSharedPluginState.wasFullWidthModeEnabled;
49
- return {
50
- tableState: undefined,
51
- isFullWidthModeEnabled: isFullWidthModeEnabled,
52
- wasFullWidthModeEnabled: wasFullWidthModeEnabled
53
- };
54
- }, function (pluginInjectionApi) {
55
- var _useSharedPluginState2 = useSharedPluginState(pluginInjectionApi, ['table']),
56
- tableState = _useSharedPluginState2.tableState;
57
- return {
58
- tableState: tableState,
59
- isFullWidthModeEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled,
60
- wasFullWidthModeEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.wasFullWidthModeEnabled
61
- };
62
- });
63
- var AlignmentTableContainer = function AlignmentTableContainer(_ref2) {
64
- var node = _ref2.node,
65
- children = _ref2.children,
66
- pluginInjectionApi = _ref2.pluginInjectionApi,
67
- getPos = _ref2.getPos,
68
- editorView = _ref2.editorView;
69
- var alignment = node.attrs.layout !== ALIGN_START ? ALIGN_CENTER : ALIGN_START;
70
- var _useAlignmentTableCon = useAlignmentTableContainerSharedState(pluginInjectionApi),
71
- tableState = _useAlignmentTableCon.tableState,
72
- isFullWidthModeEnabled = _useAlignmentTableCon.isFullWidthModeEnabled,
73
- wasFullWidthModeEnabled = _useAlignmentTableCon.wasFullWidthModeEnabled;
74
55
  useEffect(function () {
75
- if (!tableState && expValEquals('platform_editor_usesharedpluginstatewithselector', 'isEnabled', false)) {
76
- return;
77
- }
78
56
  if (editorView && getPos) {
79
57
  var state = editorView.state,
80
58
  dispatch = editorView.dispatch;
@@ -91,7 +69,7 @@ var AlignmentTableContainer = function AlignmentTableContainer(_ref2) {
91
69
  }
92
70
  }
93
71
  // eslint-disable-next-line react-hooks/exhaustive-deps
94
- }, [editorView, tableState, isFullWidthModeEnabled, wasFullWidthModeEnabled, node]);
72
+ }, [editorView, isFullWidthModeEnabled, wasFullWidthModeEnabled, node]);
95
73
  var style = useMemo(function () {
96
74
  return getAlignmentStyle(alignment);
97
75
  }, [alignment]);
@@ -137,23 +115,6 @@ var selector = function selector(states) {
137
115
  editorViewModeState: states.editorViewModeState
138
116
  };
139
117
  };
140
- var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
141
- var _useSharedPluginState3 = useSharedPluginStateWithSelector(api, ['table', 'editorViewMode'], selector),
142
- tableState = _useSharedPluginState3.tableState,
143
- editorViewModeState = _useSharedPluginState3.editorViewModeState;
144
- return {
145
- tableState: tableState,
146
- editorViewModeState: editorViewModeState
147
- };
148
- }, function (api) {
149
- var _useSharedPluginState4 = useSharedPluginState(api, ['table', 'editorViewMode']),
150
- tableState = _useSharedPluginState4.tableState,
151
- editorViewModeState = _useSharedPluginState4.editorViewModeState;
152
- return {
153
- tableState: tableState,
154
- editorViewModeState: editorViewModeState
155
- };
156
- });
157
118
  var getPadding = function getPadding(containerWidth) {
158
119
  return containerWidth <= akEditorFullPageNarrowBreakout && expValEquals('platform_editor_preview_panel_responsiveness', 'isEnabled', true) ? akEditorGutterPaddingReduced : akEditorGutterPaddingDynamic();
159
120
  };
@@ -181,9 +142,9 @@ var ResizableTableContainerLegacy = /*#__PURE__*/React.memo(function (_ref4) {
181
142
  _useState2 = _slicedToArray(_useState, 2),
182
143
  resizing = _useState2[0],
183
144
  setIsResizing = _useState2[1];
184
- var _useSharedState = useSharedState(pluginInjectionApi),
185
- tableState = _useSharedState.tableState,
186
- editorViewModeState = _useSharedState.editorViewModeState;
145
+ var _useSharedPluginState2 = useSharedPluginStateWithSelector(pluginInjectionApi, ['table', 'editorViewMode'], selector),
146
+ tableState = _useSharedPluginState2.tableState,
147
+ editorViewModeState = _useSharedPluginState2.editorViewModeState;
187
148
  var isFullWidthModeEnabled = tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled;
188
149
  var mode = editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
189
150
  var updateContainerHeight = useCallback(function (height) {
@@ -382,9 +343,9 @@ var ResizableTableContainerNext = /*#__PURE__*/React.memo(function (_ref5) {
382
343
  _useState6 = _slicedToArray(_useState5, 2),
383
344
  tableMaxWidthForFullPageOnLoad = _useState6[0],
384
345
  setTableMaxWidthForFullPageOnLoad = _useState6[1];
385
- var _useSharedState2 = useSharedState(pluginInjectionApi),
386
- tableState = _useSharedState2.tableState,
387
- editorViewModeState = _useSharedState2.editorViewModeState;
346
+ var _useSharedPluginState3 = useSharedPluginStateWithSelector(pluginInjectionApi, ['table', 'editorViewMode'], selector),
347
+ tableState = _useSharedPluginState3.tableState,
348
+ editorViewModeState = _useSharedPluginState3.editorViewModeState;
388
349
  var isFullWidthModeEnabled = tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled;
389
350
  var mode = editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
390
351
  var updateContainerHeight = useCallback(function (height) {
@@ -8,7 +8,7 @@ import { useIntl } from 'react-intl-next';
8
8
  import { CHANGE_ALIGNMENT_REASON, INPUT_METHOD, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
9
9
  import { browser } from '@atlaskit/editor-common/browser';
10
10
  import { getGuidelinesWithHighlights } from '@atlaskit/editor-common/guideline';
11
- import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
11
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
12
12
  import { focusTableResizer, ToolTipContent } from '@atlaskit/editor-common/keymaps';
13
13
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
14
14
  import { logException } from '@atlaskit/editor-common/monitoring';
@@ -107,19 +107,6 @@ var selector = function selector(states) {
107
107
  widthToWidest: (_states$tableState = states.tableState) === null || _states$tableState === void 0 ? void 0 : _states$tableState.widthToWidest
108
108
  };
109
109
  };
110
- var useSharedState = sharedPluginStateHookMigratorFactory(function (api) {
111
- var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['table'], selector),
112
- widthToWidest = _useSharedPluginState.widthToWidest;
113
- return {
114
- widthToWidest: widthToWidest
115
- };
116
- }, function (api) {
117
- var _useSharedPluginState2 = useSharedPluginState(api, ['table']),
118
- tableState = _useSharedPluginState2.tableState;
119
- return {
120
- widthToWidest: tableState === null || tableState === void 0 ? void 0 : tableState.widthToWidest
121
- };
122
- });
123
110
  export var TableResizer = function TableResizer(_ref) {
124
111
  var _editorView$state, _pluginInjectionApi$a2;
125
112
  var children = _ref.children,
@@ -152,8 +139,8 @@ export var TableResizer = function TableResizer(_ref) {
152
139
  var areResizeMetaKeysPressed = useRef(false);
153
140
  var resizerRef = useRef(null);
154
141
  var interactionState = useSharedPluginStateSelector(pluginInjectionApi, 'interaction.interactionState');
155
- var _useSharedState = useSharedState(pluginInjectionApi),
156
- widthToWidest = _useSharedState.widthToWidest;
142
+ var _useSharedPluginState = useSharedPluginStateWithSelector(pluginInjectionApi, ['table'], selector),
143
+ widthToWidest = _useSharedPluginState.widthToWidest;
157
144
 
158
145
  // used to reposition tooltip when table is resizing via keyboard
159
146
  var updateTooltip = React.useRef();
@@ -5,26 +5,19 @@ import React, { useEffect } from 'react';
5
5
  import { tableCell, tableCellWithNestedTable, tableHeader, tableHeaderWithLocalId, tableHeaderWithNestedTable, tableRow, tableRowWithNestedTable, tableRowWithLocalId, tableCellWithLocalId, tableCellWithNestedTableWithLocalId, tableRowWithNestedTableWithLocalId, tableHeaderWithNestedTableWithLocalId } from '@atlaskit/adf-schema';
6
6
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_ACTION } from '@atlaskit/editor-common/analytics';
7
7
  import { browser } from '@atlaskit/editor-common/browser';
8
- import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
9
- import { getDomRefFromSelection } from '@atlaskit/editor-common/get-dom-ref-from-selection';
10
- import { sharedPluginStateHookMigratorFactory, useSharedPluginState, useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
8
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
11
9
  import { IconTable } from '@atlaskit/editor-common/icons';
12
10
  import { toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
13
11
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
14
12
  import { getParentOfTypeCount, getPositionAfterTopParentNodeOfType } from '@atlaskit/editor-common/nesting';
15
13
  import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
16
- import { ResizerBreakoutModeLabel } from '@atlaskit/editor-common/resizer';
17
14
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
18
- import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
19
15
  import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
20
- import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
21
16
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
22
17
  import { fg } from '@atlaskit/platform-feature-flags';
23
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
24
18
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
25
19
  import { tableNodeSpecWithFixedToDOM } from './nodeviews/toDOM';
26
20
  import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
27
- import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
28
21
  import { insertTableWithNestingSupport, insertTableWithSize } from './pm-plugins/commands/insert';
29
22
  import { pluginConfig } from './pm-plugins/create-plugin-config';
30
23
  import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
@@ -41,7 +34,6 @@ import { createPlugin as createTableOverflowAnalyticsPlugin } from './pm-plugins
41
34
  import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
42
35
  import { createPlugin as createFlexiResizingPlugin } from './pm-plugins/table-resizing/plugin';
43
36
  import { getPluginState as getFlexiResizingPlugin } from './pm-plugins/table-resizing/plugin-factory';
44
- import { pluginKey as tableResizingPluginKey } from './pm-plugins/table-resizing/plugin-key';
45
37
  import { tableSelectionKeymapPlugin } from './pm-plugins/table-selection-keymap';
46
38
  import { createPlugin as createSizeSelectorPlugin, pluginKey as sizeSelectorPluginKey } from './pm-plugins/table-size-selector';
47
39
  import { createPlugin as createTableWidthPlugin, pluginKey as tableWidthPluginKey } from './pm-plugins/table-width';
@@ -49,46 +41,17 @@ import { createPlugin as createTableWidthInCommentFixPlugin } from './pm-plugins
49
41
  import { createTableWithWidth } from './pm-plugins/utils/create';
50
42
  import { createPlugin as createViewModeSortPlugin } from './pm-plugins/view-mode-sort';
51
43
  import { ContentComponent } from './ui/ContentComponent';
52
- import FloatingContextualButton from './ui/FloatingContextualButton';
53
- import FloatingContextualMenu from './ui/FloatingContextualMenu';
54
- import FloatingDeleteButton from './ui/FloatingDeleteButton';
55
- import FloatingDragMenu from './ui/FloatingDragMenu';
56
- // Ignored via go/ees005
57
- // eslint-disable-next-line import/no-named-as-default
58
- import FloatingInsertButton from './ui/FloatingInsertButton';
59
- import { FloatingToolbarLabel } from './ui/FloatingToolbarLabel/FloatingToolbarLabel';
60
- import { GlobalStylesWrapper } from './ui/global-styles';
61
- import { SizeSelector } from './ui/SizeSelector';
62
- import { FullWidthDisplay } from './ui/TableFullWidthLabel';
63
44
  import { getToolbarConfig } from './ui/toolbar';
64
45
  var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
65
46
  return {};
66
47
  };
67
- var useTableSharedState = sharedPluginStateHookMigratorFactory(function (api) {
68
- var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['editorViewMode'], function (states) {
69
- var _states$editorViewMod;
70
- return {
71
- mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
72
- };
73
- }),
74
- mode = _useSharedPluginState.mode;
75
- return {
76
- mode: mode
77
- };
78
- }, function (api) {
79
- var _useSharedPluginState2 = useSharedPluginState(api, ['editorViewMode']),
80
- editorViewModeState = _useSharedPluginState2.editorViewModeState;
81
- return {
82
- mode: editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode
83
- };
84
- });
85
48
 
86
49
  /**
87
50
  * Table plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
88
51
  * from `@atlaskit/editor-core`.
89
52
  */
90
53
  var tablePlugin = function tablePlugin(_ref) {
91
- var _api$analytics, _api$accessibilityUti, _options$getEditorFea, _options$getEditorFea2, _api$analytics2;
54
+ var _api$analytics, _options$getEditorFea, _options$getEditorFea2, _api$analytics2;
92
55
  var options = _ref.config,
93
56
  api = _ref.api;
94
57
  var editorViewRef = {
@@ -101,7 +64,6 @@ var tablePlugin = function tablePlugin(_ref) {
101
64
  };
102
65
  };
103
66
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
104
- var ariaNotifyPlugin = api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 ? void 0 : _api$accessibilityUti.actions.ariaNotify;
105
67
  var isTableFixedColumnWidthsOptionEnabled = (options === null || options === void 0 || (_options$getEditorFea = options.getEditorFeatureFlags) === null || _options$getEditorFea === void 0 ? void 0 : _options$getEditorFea.call(options).tableWithFixedColumnWidthsOption) || false;
106
68
  var shouldUseIncreasedScalingPercent = (options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) && (isTableFixedColumnWidthsOptionEnabled || ( // When in comment editor, we need the scaling percent to be 40% while tableWithFixedColumnWidthsOption is not visible
107
69
  options === null || options === void 0 ? void 0 : options.isCommentEditor));
@@ -472,178 +434,27 @@ var tablePlugin = function tablePlugin(_ref) {
472
434
  return plugins;
473
435
  },
474
436
  contentComponent: function contentComponent(_ref18) {
475
- var _api$featureFlags;
476
437
  var editorView = _ref18.editorView,
477
438
  popupsMountPoint = _ref18.popupsMountPoint,
478
439
  popupsBoundariesElement = _ref18.popupsBoundariesElement,
479
440
  popupsScrollableElement = _ref18.popupsScrollableElement,
480
441
  dispatchAnalyticsEvent = _ref18.dispatchAnalyticsEvent;
481
- if (expValEquals('platform_editor_usesharedpluginstatewithselector', 'isEnabled', true)) {
482
- return /*#__PURE__*/React.createElement(ContentComponent, {
483
- api: api,
484
- editorView: editorView,
485
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
486
- options: options,
487
- popupsMountPoint: popupsMountPoint,
488
- popupsBoundariesElement: popupsBoundariesElement,
489
- popupsScrollableElement: popupsScrollableElement,
490
- defaultGetEditorContainerWidth: defaultGetEditorContainerWidth,
491
- defaultGetEditorFeatureFlags: defaultGetEditorFeatureFlags,
492
- isTableSelectorEnabled: isTableSelectorEnabled
493
- });
494
- }
495
- return /*#__PURE__*/React.createElement(ErrorBoundary, {
496
- component: ACTION_SUBJECT.TABLES_PLUGIN,
442
+ return /*#__PURE__*/React.createElement(ContentComponent, {
443
+ api: api,
444
+ editorView: editorView,
497
445
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
498
- fallbackComponent: null
499
- }, /*#__PURE__*/React.createElement(GlobalStylesWrapper, {
500
- featureFlags: api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState(),
501
- isDragAndDropEnabledOption: options === null || options === void 0 ? void 0 : options.dragAndDropEnabled,
502
- api: api
503
- }), /*#__PURE__*/React.createElement(WithPluginState, {
504
- plugins: {
505
- tableAnalyticsPluginState: tableAnalyticsPluginKey,
506
- tablePluginState: pluginKey,
507
- tableWidthPluginState: tableWidthPluginKey,
508
- tableResizingPluginState: tableResizingPluginKey,
509
- stickyHeadersState: stickyHeadersPluginKey,
510
- dragAndDropState: dragAndDropPluginKey,
511
- sizeSelectorPluginState: sizeSelectorPluginKey
512
- },
513
- render: function render(_ref19) {
514
- var _sizeSelectorPluginSt, _api$analytics3;
515
- var resizingPluginState = _ref19.tableResizingPluginState,
516
- stickyHeadersState = _ref19.stickyHeadersState,
517
- tablePluginState = _ref19.tablePluginState,
518
- tableWidthPluginState = _ref19.tableWidthPluginState,
519
- dragAndDropState = _ref19.dragAndDropState,
520
- sizeSelectorPluginState = _ref19.sizeSelectorPluginState;
521
- // Any changes made inside `<WithPluginState>` need to be reflected in the
522
- // `<ContentComponent>` as well.
523
- var isColumnResizing = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
524
- var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
525
- var resizingTableLocalId = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableLocalId;
526
- var resizingTableRef = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.tableRef;
527
- var isResizing = isColumnResizing || isTableResizing;
528
- var widthToWidest = tablePluginState === null || tablePluginState === void 0 ? void 0 : tablePluginState.widthToWidest;
529
- var isSizeSelectorOpen = sizeSelectorPluginState === null || sizeSelectorPluginState === void 0 ? void 0 : sizeSelectorPluginState.isSelectorOpen;
530
- var _ref20 = tablePluginState,
531
- tableNode = _ref20.tableNode,
532
- tablePos = _ref20.tablePos,
533
- targetCellPosition = _ref20.targetCellPosition,
534
- isContextualMenuOpen = _ref20.isContextualMenuOpen,
535
- tableRef = _ref20.tableRef,
536
- pluginConfig = _ref20.pluginConfig,
537
- insertColumnButtonIndex = _ref20.insertColumnButtonIndex,
538
- insertRowButtonIndex = _ref20.insertRowButtonIndex,
539
- isHeaderColumnEnabled = _ref20.isHeaderColumnEnabled,
540
- isHeaderRowEnabled = _ref20.isHeaderRowEnabled,
541
- isDragAndDropEnabled = _ref20.isDragAndDropEnabled,
542
- tableWrapperTarget = _ref20.tableWrapperTarget,
543
- isCellMenuOpenByKeyboard = _ref20.isCellMenuOpenByKeyboard;
544
- var allowControls = pluginConfig.allowControls;
545
- var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
546
- return /*#__PURE__*/React.createElement(React.Fragment, null, targetCellPosition && (tableRef || isCellMenuOpenByKeyboard) && !isResizing && options && options.allowContextualMenu && /*#__PURE__*/React.createElement(FloatingContextualButton, {
547
- isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
548
- editorView: editorView,
549
- tableNode: tableNode,
550
- mountPoint: popupsMountPoint,
551
- targetCellPosition: targetCellPosition,
552
- scrollableElement: popupsScrollableElement,
553
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
554
- isContextualMenuOpen: isContextualMenuOpen,
555
- stickyHeader: stickyHeader,
556
- tableWrapper: tableWrapperTarget,
557
- isCellMenuOpenByKeyboard: isCellMenuOpenByKeyboard
558
- }), allowControls && /*#__PURE__*/React.createElement(FloatingInsertButton, {
559
- tableNode: tableNode,
560
- tableRef: tableRef,
561
- insertColumnButtonIndex: insertColumnButtonIndex,
562
- insertRowButtonIndex: insertRowButtonIndex,
563
- isHeaderColumnEnabled: isHeaderColumnEnabled,
564
- isHeaderRowEnabled: isHeaderRowEnabled,
565
- isDragAndDropEnabled: isDragAndDropEnabled,
566
- isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
567
- editorView: editorView,
568
- mountPoint: popupsMountPoint,
569
- boundariesElement: popupsBoundariesElement,
570
- scrollableElement: popupsScrollableElement,
571
- hasStickyHeaders: stickyHeader && stickyHeader.sticky,
572
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
573
- editorAnalyticsAPI: editorAnalyticsAPI,
574
- getEditorContainerWidth: defaultGetEditorContainerWidth,
575
- getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags,
576
- isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
577
- api: api,
578
- isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor
579
- }), (options === null || options === void 0 ? void 0 : options.allowContextualMenu) && /*#__PURE__*/React.createElement(FloatingContextualMenu, {
580
- editorView: editorView,
581
- mountPoint: popupsMountPoint,
582
- boundariesElement: popupsBoundariesElement,
583
- targetCellPosition: targetCellPosition,
584
- isOpen: Boolean(isContextualMenuOpen) && !isResizing,
585
- pluginConfig: pluginConfig,
586
- editorAnalyticsAPI: editorAnalyticsAPI,
587
- getEditorContainerWidth: defaultGetEditorContainerWidth,
588
- getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags,
589
- isCellMenuOpenByKeyboard: isCellMenuOpenByKeyboard,
590
- isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
591
- api: api
592
- }), isDragAndDropEnabled && /*#__PURE__*/React.createElement(FloatingDragMenu, {
593
- editorView: editorView,
594
- mountPoint: popupsMountPoint,
595
- boundariesElement: popupsBoundariesElement,
596
- tableRef: tableRef,
597
- tableNode: tableNode,
598
- targetCellPosition: targetCellPosition,
599
- direction: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuDirection,
600
- index: dragAndDropState === null || dragAndDropState === void 0 ? void 0 : dragAndDropState.dragMenuIndex,
601
- isOpen: !!(dragAndDropState !== null && dragAndDropState !== void 0 && dragAndDropState.isDragMenuOpen) && !isResizing,
602
- getEditorContainerWidth: defaultGetEditorContainerWidth,
603
- editorAnalyticsAPI: editorAnalyticsAPI,
604
- stickyHeaders: stickyHeader,
605
- pluginConfig: pluginConfig,
606
- isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
607
- getEditorFeatureFlags: (options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) || defaultGetEditorFeatureFlags,
608
- ariaNotifyPlugin: ariaNotifyPlugin,
609
- api: api,
610
- isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor
611
- }), allowControls && !isDragAndDropEnabled && !isResizing && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
612
- editorView: editorView,
613
- selection: editorView.state.selection,
614
- tableRef: tableRef,
615
- mountPoint: popupsMountPoint,
616
- boundariesElement: popupsBoundariesElement,
617
- scrollableElement: popupsScrollableElement,
618
- stickyHeaders: stickyHeader,
619
- isNumberColumnEnabled: tableNode && tableNode.attrs.isNumberColumnEnabled,
620
- editorAnalyticsAPI: editorAnalyticsAPI,
621
- api: api
622
- }), ((options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) || (options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing) && options.isCommentEditor) && isTableResizing && widthToWidest && resizingTableLocalId && resizingTableRef && widthToWidest[resizingTableLocalId] && /*#__PURE__*/React.createElement(FloatingToolbarLabel, {
623
- target: resizingTableRef,
624
- content: editorExperiment('single_column_layouts', true) ? /*#__PURE__*/React.createElement(ResizerBreakoutModeLabel, {
625
- layout: "full-width"
626
- }) : /*#__PURE__*/React.createElement(FullWidthDisplay, null),
627
- alignX: 'center',
628
- alignY: 'bottom',
629
- stick: true,
630
- forcePlacement: true,
631
- zIndex: akEditorFloatingPanelZIndex,
632
- offset: [0, 10]
633
- }), isTableSelectorEnabled && isSizeSelectorOpen && /*#__PURE__*/React.createElement(SizeSelector, {
634
- api: api,
635
- isOpenedByKeyboard: false,
636
- popupsMountPoint: popupsMountPoint,
637
- target: (_sizeSelectorPluginSt = sizeSelectorPluginState === null || sizeSelectorPluginState === void 0 ? void 0 : sizeSelectorPluginState.targetRef) !== null && _sizeSelectorPluginSt !== void 0 ? _sizeSelectorPluginSt : getDomRefFromSelection(editorView, ACTION_SUBJECT_ID.PICKER_TABLE_SIZE, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions),
638
- popupsBoundariesElement: popupsBoundariesElement,
639
- popupsScrollableElement: popupsScrollableElement
640
- }));
641
- }
642
- }));
446
+ options: options,
447
+ popupsMountPoint: popupsMountPoint,
448
+ popupsBoundariesElement: popupsBoundariesElement,
449
+ popupsScrollableElement: popupsScrollableElement,
450
+ defaultGetEditorContainerWidth: defaultGetEditorContainerWidth,
451
+ defaultGetEditorFeatureFlags: defaultGetEditorFeatureFlags,
452
+ isTableSelectorEnabled: isTableSelectorEnabled
453
+ });
643
454
  },
644
455
  pluginsOptions: {
645
- quickInsert: function quickInsert(_ref21) {
646
- var formatMessage = _ref21.formatMessage;
456
+ quickInsert: function quickInsert(_ref19) {
457
+ var formatMessage = _ref19.formatMessage;
647
458
  return [{
648
459
  id: 'table',
649
460
  title: formatMessage(messages.table),
@@ -714,10 +525,15 @@ var tablePlugin = function tablePlugin(_ref) {
714
525
  return editorViewRef.current;
715
526
  }, options, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent)(pluginConfig(options === null || options === void 0 ? void 0 : options.tableOptions))
716
527
  },
717
- usePluginHook: function usePluginHook(_ref22) {
718
- var editorView = _ref22.editorView;
719
- var _useTableSharedState = useTableSharedState(api),
720
- mode = _useTableSharedState.mode;
528
+ usePluginHook: function usePluginHook(_ref20) {
529
+ var editorView = _ref20.editorView;
530
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['editorViewMode'], function (states) {
531
+ var _states$editorViewMod;
532
+ return {
533
+ mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode
534
+ };
535
+ }),
536
+ mode = _useSharedPluginState.mode;
721
537
  useEffect(function () {
722
538
  var state = editorView.state,
723
539
  dispatch = editorView.dispatch;