@atlaskit/editor-plugin-table 10.9.5 → 10.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +5 -0
  3. package/dist/cjs/nodeviews/TableContainer.js +63 -32
  4. package/dist/cjs/nodeviews/TableResizer.js +18 -10
  5. package/dist/cjs/pm-plugins/table-resizing/utils/scale-table.js +4 -3
  6. package/dist/cjs/tablePlugin.js +10 -2
  7. package/dist/cjs/ui/DragHandle/index.js +19 -3
  8. package/dist/cjs/ui/global-styles.js +11 -2
  9. package/dist/es2019/nodeviews/TableComponent.js +5 -0
  10. package/dist/es2019/nodeviews/TableContainer.js +41 -13
  11. package/dist/es2019/nodeviews/TableResizer.js +13 -6
  12. package/dist/es2019/pm-plugins/table-resizing/utils/scale-table.js +4 -3
  13. package/dist/es2019/tablePlugin.js +10 -2
  14. package/dist/es2019/ui/DragHandle/index.js +19 -3
  15. package/dist/es2019/ui/global-styles.js +11 -2
  16. package/dist/esm/nodeviews/TableComponent.js +5 -0
  17. package/dist/esm/nodeviews/TableContainer.js +63 -32
  18. package/dist/esm/nodeviews/TableResizer.js +18 -10
  19. package/dist/esm/pm-plugins/table-resizing/utils/scale-table.js +4 -3
  20. package/dist/esm/tablePlugin.js +10 -2
  21. package/dist/esm/ui/DragHandle/index.js +19 -3
  22. package/dist/esm/ui/global-styles.js +11 -2
  23. package/package.json +5 -2
  24. package/src/nodeviews/TableComponent.tsx +5 -0
  25. package/src/nodeviews/TableContainer.tsx +76 -9
  26. package/src/nodeviews/TableResizer.tsx +19 -4
  27. package/src/pm-plugins/table-resizing/utils/scale-table.ts +5 -3
  28. package/src/tablePlugin.tsx +12 -2
  29. package/src/ui/DragHandle/index.tsx +27 -3
  30. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +1 -1
  31. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +3 -3
  32. package/src/ui/global-styles.tsx +14 -2
@@ -5,16 +5,25 @@
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
6
  import { Global, jsx } from '@emotion/react';
7
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
8
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
9
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
8
10
  import { tableStyles } from './common-styles';
9
11
  export const GlobalStylesWrapper = ({
10
12
  featureFlags,
11
13
  isDragAndDropEnabledOption,
12
14
  api
13
15
  }) => {
16
+ // mode
14
17
  const {
15
18
  editorViewModeState
16
- } = useSharedPluginState(api, ['editorViewMode']);
17
- const isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
19
+ } = useSharedPluginState(api, ['editorViewMode'], {
20
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
21
+ });
22
+ const modeSelector = useSharedPluginStateSelector(api, 'editorViewMode.mode', {
23
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
24
+ });
25
+ const mode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? modeSelector : editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
26
+ const isLivePageViewMode = mode === 'view';
18
27
  return jsx(Global, {
19
28
  styles: tableStyles({
20
29
  featureFlags,
@@ -248,6 +248,11 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
248
248
  )(state.tr);
249
249
  if (!isUserTriggered) {
250
250
  tintDirtyTransaction(tr);
251
+ if (fg('platform_editor_fix_table_resizing_undo')) {
252
+ // Avoid adding this transaction separately to the history as these are automatic updates
253
+ // as a consequence of another action
254
+ tr.setMeta('addToHistory', false);
255
+ }
251
256
  }
252
257
  dispatch(tr);
253
258
  });
@@ -5,8 +5,10 @@ import classNames from 'classnames';
5
5
  import { CHANGE_ALIGNMENT_REASON, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
7
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
8
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
8
9
  import { akEditorDefaultLayoutWidth, akEditorGutterPaddingDynamic, akEditorMobileBreakoutPoint } from '@atlaskit/editor-shared-styles';
9
10
  import { fg } from '@atlaskit/platform-feature-flags';
11
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
12
  import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../pm-plugins/commands/commands-with-analytics';
11
13
  import { getPluginState } from '../pm-plugins/plugin-factory';
12
14
  import { TABLE_MAX_WIDTH, TABLE_OFFSET_IN_COMMENT_EDITOR } from '../pm-plugins/table-resizing/utils/consts';
@@ -39,12 +41,27 @@ var AlignmentTableContainer = function AlignmentTableContainer(_ref2) {
39
41
  getPos = _ref2.getPos,
40
42
  editorView = _ref2.editorView;
41
43
  var alignment = node.attrs.layout !== ALIGN_START ? ALIGN_CENTER : ALIGN_START;
42
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['table']),
44
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['table'], {
45
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
46
+ }),
43
47
  tableState = _useSharedPluginState.tableState;
48
+
49
+ // isFullWidthModeEnabled
50
+ var isTableFullWidthModeEnabledSelector = useSharedPluginStateSelector(pluginInjectionApi, 'table.isFullWidthModeEnabled', {
51
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
52
+ });
53
+ var isFullWidthModeEnabled = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isTableFullWidthModeEnabledSelector : tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled;
54
+
55
+ // wasFullWidthModeEnabled
56
+ var wasFullWidthModeEnabledSelector = useSharedPluginStateSelector(pluginInjectionApi, 'table.wasFullWidthModeEnabled', {
57
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
58
+ });
59
+ var wasFullWidthModeEnabled = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? wasFullWidthModeEnabledSelector : tableState === null || tableState === void 0 ? void 0 : tableState.wasFullWidthModeEnabled;
44
60
  useEffect(function () {
45
- if (tableState && editorView && getPos) {
46
- var wasFullWidthModeEnabled = tableState.wasFullWidthModeEnabled,
47
- isFullWidthModeEnabled = tableState.isFullWidthModeEnabled;
61
+ if (editorExperiment('platform_editor_usesharedpluginstateselector', false) && !tableState) {
62
+ return;
63
+ }
64
+ if (editorView && getPos) {
48
65
  var state = editorView.state,
49
66
  dispatch = editorView.dispatch;
50
67
  if (wasFullWidthModeEnabled && isFullWidthModeEnabled !== undefined && !isFullWidthModeEnabled && alignment !== ALIGN_CENTER && node.attrs.width > akEditorDefaultLayoutWidth) {
@@ -60,7 +77,7 @@ var AlignmentTableContainer = function AlignmentTableContainer(_ref2) {
60
77
  }
61
78
  }
62
79
  // eslint-disable-next-line react-hooks/exhaustive-deps
63
- }, [editorView, tableState, node]);
80
+ }, [editorView, tableState, isFullWidthModeEnabled, wasFullWidthModeEnabled, node]);
64
81
  var style = useMemo(function () {
65
82
  return getAlignmentStyle(alignment);
66
83
  }, [alignment]);
@@ -122,10 +139,16 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
122
139
  _useState2 = _slicedToArray(_useState, 2),
123
140
  resizing = _useState2[0],
124
141
  setIsResizing = _useState2[1];
125
- var _useSharedPluginState2 = useSharedPluginState(pluginInjectionApi, ['table']),
142
+ var _useSharedPluginState2 = useSharedPluginState(pluginInjectionApi, ['table'], {
143
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
144
+ }),
126
145
  tableState = _useSharedPluginState2.tableState;
127
- var _ref5 = tableState,
128
- isFullWidthModeEnabled = _ref5.isFullWidthModeEnabled;
146
+
147
+ // isFullWidthModeEnabled
148
+ var isFullWidthModeEnabledSelector = useSharedPluginStateSelector(pluginInjectionApi, 'table.isFullWidthModeEnabled', {
149
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
150
+ });
151
+ var isFullWidthModeEnabled = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isFullWidthModeEnabledSelector : tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled;
129
152
  var updateContainerHeight = useCallback(function (height) {
130
153
  var _containerRef$current;
131
154
  // current StickyHeader State is not stable to be fetch.
@@ -179,8 +202,16 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
179
202
  return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.core) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$s = pluginInjectionApi.selection) === null || _pluginInjectionApi$s === void 0 ? void 0 : _pluginInjectionApi$s.commands.displayGapCursor(toggle))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
180
203
  }, [pluginInjectionApi]);
181
204
  var tableWidth = getTableContainerWidth(node);
182
- var _useSharedPluginState3 = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
205
+ var _useSharedPluginState3 = useSharedPluginState(pluginInjectionApi, ['editorViewMode'], {
206
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
207
+ }),
183
208
  editorViewModeState = _useSharedPluginState3.editorViewModeState;
209
+
210
+ // mode
211
+ var modeSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode', {
212
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
213
+ });
214
+ var mode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? modeSelector : editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
184
215
  var responsiveContainerWidth = 0;
185
216
  var resizeHandleSpacing = 12;
186
217
  // When Full width editor enabled, a Mac OS user can change "ak-editor-content-area" width by
@@ -231,7 +262,7 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
231
262
  onResizeStop: onResizeStop,
232
263
  isCommentEditor: isCommentEditor
233
264
  };
234
- var isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
265
+ var isLivePageViewMode = (editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mode : editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
235
266
  return /*#__PURE__*/React.createElement(AlignmentTableContainerWrapper, {
236
267
  isTableAlignmentEnabled: isTableAlignmentEnabled,
237
268
  node: node,
@@ -276,28 +307,28 @@ export var ResizableTableContainer = /*#__PURE__*/React.memo(function (_ref4) {
276
307
  node: node
277
308
  }, children)) : null));
278
309
  });
279
- export var TableContainer = function TableContainer(_ref6) {
280
- var children = _ref6.children,
281
- node = _ref6.node,
282
- className = _ref6.className,
283
- _ref6$containerWidth = _ref6.containerWidth,
284
- editorWidth = _ref6$containerWidth.width,
285
- lineLength = _ref6$containerWidth.lineLength,
286
- editorView = _ref6.editorView,
287
- getPos = _ref6.getPos,
288
- tableRef = _ref6.tableRef,
289
- isNested = _ref6.isNested,
290
- tableWrapperHeight = _ref6.tableWrapperHeight,
291
- isResizing = _ref6.isResizing,
292
- pluginInjectionApi = _ref6.pluginInjectionApi,
293
- isWholeTableInDanger = _ref6.isWholeTableInDanger,
294
- isTableResizingEnabled = _ref6.isTableResizingEnabled,
295
- isTableScalingEnabled = _ref6.isTableScalingEnabled,
296
- isTableWithFixedColumnWidthsOptionEnabled = _ref6.isTableWithFixedColumnWidthsOptionEnabled,
297
- isTableAlignmentEnabled = _ref6.isTableAlignmentEnabled,
298
- shouldUseIncreasedScalingPercent = _ref6.shouldUseIncreasedScalingPercent,
299
- isCommentEditor = _ref6.isCommentEditor,
300
- isChromelessEditor = _ref6.isChromelessEditor;
310
+ export var TableContainer = function TableContainer(_ref5) {
311
+ var children = _ref5.children,
312
+ node = _ref5.node,
313
+ className = _ref5.className,
314
+ _ref5$containerWidth = _ref5.containerWidth,
315
+ editorWidth = _ref5$containerWidth.width,
316
+ lineLength = _ref5$containerWidth.lineLength,
317
+ editorView = _ref5.editorView,
318
+ getPos = _ref5.getPos,
319
+ tableRef = _ref5.tableRef,
320
+ isNested = _ref5.isNested,
321
+ tableWrapperHeight = _ref5.tableWrapperHeight,
322
+ isResizing = _ref5.isResizing,
323
+ pluginInjectionApi = _ref5.pluginInjectionApi,
324
+ isWholeTableInDanger = _ref5.isWholeTableInDanger,
325
+ isTableResizingEnabled = _ref5.isTableResizingEnabled,
326
+ isTableScalingEnabled = _ref5.isTableScalingEnabled,
327
+ isTableWithFixedColumnWidthsOptionEnabled = _ref5.isTableWithFixedColumnWidthsOptionEnabled,
328
+ isTableAlignmentEnabled = _ref5.isTableAlignmentEnabled,
329
+ shouldUseIncreasedScalingPercent = _ref5.shouldUseIncreasedScalingPercent,
330
+ isCommentEditor = _ref5.isCommentEditor,
331
+ isChromelessEditor = _ref5.isChromelessEditor;
301
332
  if (isTableResizingEnabled && !isNested) {
302
333
  return /*#__PURE__*/React.createElement(ResizableTableContainer
303
334
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -13,10 +13,12 @@ import { focusTableResizer, ToolTipContent } from '@atlaskit/editor-common/keyma
13
13
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
14
14
  import { logException } from '@atlaskit/editor-common/monitoring';
15
15
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
16
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
16
17
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
17
18
  import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
18
19
  import { findTable } from '@atlaskit/editor-tables/utils';
19
20
  import { fg } from '@atlaskit/platform-feature-flags';
21
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
20
22
  import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../pm-plugins/commands/commands-with-analytics';
21
23
  import { updateWidthToWidest } from '../pm-plugins/commands/misc';
22
24
  import { META_KEYS } from '../pm-plugins/table-analytics';
@@ -125,10 +127,16 @@ export var TableResizer = function TableResizer(_ref) {
125
127
  var isResizing = useRef(false);
126
128
  var areResizeMetaKeysPressed = useRef(false);
127
129
  var resizerRef = useRef(null);
128
- var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['table']),
130
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['table'], {
131
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
132
+ }),
129
133
  tableState = _useSharedPluginState.tableState;
130
- var _ref2 = tableState,
131
- widthToWidest = _ref2.widthToWidest;
134
+
135
+ // widthToWidest
136
+ var widthToWidestSelector = useSharedPluginStateSelector(pluginInjectionApi, 'table.widthToWidest', {
137
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
138
+ });
139
+ var widthToWidest = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? widthToWidestSelector : tableState.widthToWidest;
132
140
 
133
141
  // used to reposition tooltip when table is resizing via keyboard
134
142
  var updateTooltip = React.useRef();
@@ -170,12 +178,12 @@ export var TableResizer = function TableResizer(_ref) {
170
178
  var excludeGuidelineConfig = useMemo(function () {
171
179
  return {
172
180
  innerGuidelines: !!isTableAlignmentEnabled,
173
- breakoutPoints: !!(isTableAlignmentEnabled && tableState !== null && tableState !== void 0 && tableState.isFullWidthModeEnabled)
181
+ breakoutPoints: !!(isTableAlignmentEnabled && isFullWidthModeEnabled)
174
182
  };
175
- }, [tableState, isTableAlignmentEnabled]);
176
- var updateActiveGuidelines = useCallback(function (_ref3) {
177
- var gap = _ref3.gap,
178
- keys = _ref3.keys;
183
+ }, [isFullWidthModeEnabled, isTableAlignmentEnabled]);
184
+ var updateActiveGuidelines = useCallback(function (_ref2) {
185
+ var gap = _ref2.gap,
186
+ keys = _ref2.keys;
179
187
  if (gap !== currentGap.current) {
180
188
  currentGap.current = gap;
181
189
  var visibleGuidelines = getVisibleGuidelines(isTableScalingEnabled ? defaultGuidelinesForPreserveTable(PRESERVE_TABLE_GUIDELINES_LENGTH_OFFSET, isFullWidthModeEnabled ? lineLength + 2 * akEditorGutterPaddingDynamic() : containerWidth, excludeGuidelineConfig) : defaultGuidelines, containerWidth, lineLength, Boolean(isTableScalingEnabled), Boolean(isFullWidthModeEnabled));
@@ -477,8 +485,8 @@ export var TableResizer = function TableResizer(_ref) {
477
485
  needExtendedResizeZone: !isTableSelected,
478
486
  appearance: isTableSelected && isWholeTableInDanger ? 'danger' : undefined,
479
487
  handleHighlight: "shadow",
480
- handleTooltipContent: function handleTooltipContent(_ref4) {
481
- var update = _ref4.update;
488
+ handleTooltipContent: function handleTooltipContent(_ref3) {
489
+ var update = _ref3.update;
482
490
  updateTooltip.current = update;
483
491
  return /*#__PURE__*/React.createElement(ToolTipContent, {
484
492
  description: formatMessage(messages.resizeTable),
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
5
5
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
6
6
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
7
8
  import { updateColumnWidths } from '../../transforms/column-width';
8
9
  import { getTableWidth } from '../../utils/nodes';
9
10
  import { getLayoutSize } from '../utils/misc';
@@ -169,9 +170,9 @@ export var scaleTable = function scaleTable(tableRef, options, domAtPos, api) {
169
170
  }
170
171
  if (resizeState) {
171
172
  tr = updateColumnWidths(resizeState, node, start, api)(tr);
172
- // Avoid adding this transaction separately to the history as these are automatic updates
173
- // as a consequence of another action
174
- tr.setMeta('addToHistory', false);
173
+ if (!fg('platform_editor_fix_table_resizing_undo')) {
174
+ tr.setMeta('addToHistory', false);
175
+ }
175
176
  if (tr.docChanged) {
176
177
  tr.setMeta('scrollIntoView', false);
177
178
  // TODO: ED-8995 - We need to do this check to reduce the number of race conditions when working with tables.
@@ -15,6 +15,7 @@ import { getParentOfTypeCount, getPositionAfterTopParentNodeOfType } from '@atla
15
15
  import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
16
16
  import { ResizerBreakoutModeLabel } from '@atlaskit/editor-common/resizer';
17
17
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
18
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
18
19
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
19
20
  import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
20
21
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
@@ -677,9 +678,16 @@ var tablePlugin = function tablePlugin(_ref) {
677
678
  },
678
679
  usePluginHook: function usePluginHook(_ref24) {
679
680
  var editorView = _ref24.editorView;
680
- var _useSharedPluginState = useSharedPluginState(api, ['editorViewMode']),
681
+ var _useSharedPluginState = useSharedPluginState(api, ['editorViewMode'], {
682
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
683
+ }),
681
684
  editorViewModeState = _useSharedPluginState.editorViewModeState;
682
- var mode = editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
685
+
686
+ // mode
687
+ var modeSelector = useSharedPluginStateSelector(api, 'editorViewMode.mode', {
688
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
689
+ });
690
+ var mode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? modeSelector : editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
683
691
  useEffect(function () {
684
692
  var state = editorView.state,
685
693
  dispatch = editorView.dispatch;
@@ -9,10 +9,12 @@ import { injectIntl } from 'react-intl-next';
9
9
  import { browser } from '@atlaskit/editor-common/browser';
10
10
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
11
11
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
12
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
12
13
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
13
14
  import { findTable, TableMap } from '@atlaskit/editor-tables';
14
15
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
15
16
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
17
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
16
18
  import { getPluginState as getDnDPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
17
19
  import { getPluginState } from '../../pm-plugins/plugin-factory';
18
20
  import { findDuplicatePosition, hasMergedCellsInSelection } from '../../pm-plugins/utils/merged-cells';
@@ -260,8 +262,22 @@ var DragHandleComponentWithSharedState = function DragHandleComponentWithSharedS
260
262
  editorView = _ref5.editorView,
261
263
  intl = _ref5.intl,
262
264
  api = _ref5.api;
263
- var _ref6 = useSharedPluginState(api, ['table']),
265
+ var _ref6 = useSharedPluginState(api, ['table'], {
266
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
267
+ }),
264
268
  tableState = _ref6.tableState;
269
+
270
+ // hoveredColumns
271
+ var hoveredColumnsSelector = useSharedPluginStateSelector(api, 'table.hoveredColumns', {
272
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
273
+ });
274
+ var hoveredColumns = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? hoveredColumnsSelector : tableState === null || tableState === void 0 ? void 0 : tableState.hoveredColumns;
275
+
276
+ // hoveredRows
277
+ var hoveredRowsSelector = useSharedPluginStateSelector(api, 'table.hoveredRows', {
278
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
279
+ });
280
+ var hoveredRows = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? hoveredRowsSelector : tableState === null || tableState === void 0 ? void 0 : tableState.hoveredRows;
265
281
  return /*#__PURE__*/React.createElement(DragHandleComponent, {
266
282
  isDragMenuTarget: isDragMenuTarget,
267
283
  tableLocalId: tableLocalId,
@@ -278,8 +294,8 @@ var DragHandleComponentWithSharedState = function DragHandleComponentWithSharedS
278
294
  onClick: onClick,
279
295
  editorView: editorView,
280
296
  intl: intl,
281
- hoveredColumns: tableState === null || tableState === void 0 ? void 0 : tableState.hoveredColumns,
282
- hoveredRows: tableState === null || tableState === void 0 ? void 0 : tableState.hoveredRows
297
+ hoveredColumns: hoveredColumns,
298
+ hoveredRows: hoveredRows
283
299
  });
284
300
  };
285
301
  export var DragHandle = injectIntl(DragHandleComponent);
@@ -5,14 +5,23 @@
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
6
  import { Global, jsx } from '@emotion/react';
7
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
8
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
9
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
8
10
  import { tableStyles } from './common-styles';
9
11
  export var GlobalStylesWrapper = function GlobalStylesWrapper(_ref) {
10
12
  var featureFlags = _ref.featureFlags,
11
13
  isDragAndDropEnabledOption = _ref.isDragAndDropEnabledOption,
12
14
  api = _ref.api;
13
- var _useSharedPluginState = useSharedPluginState(api, ['editorViewMode']),
15
+ // mode
16
+ var _useSharedPluginState = useSharedPluginState(api, ['editorViewMode'], {
17
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
18
+ }),
14
19
  editorViewModeState = _useSharedPluginState.editorViewModeState;
15
- var isLivePageViewMode = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view';
20
+ var modeSelector = useSharedPluginStateSelector(api, 'editorViewMode.mode', {
21
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
22
+ });
23
+ var mode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? modeSelector : editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode;
24
+ var isLivePageViewMode = mode === 'view';
16
25
  return jsx(Global, {
17
26
  styles: tableStyles({
18
27
  featureFlags: featureFlags,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "10.9.5",
3
+ "version": "10.9.7",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -32,7 +32,7 @@
32
32
  "@atlaskit/adf-schema": "^47.6.0",
33
33
  "@atlaskit/button": "^23.0.0",
34
34
  "@atlaskit/custom-steps": "^0.11.0",
35
- "@atlaskit/editor-common": "^103.16.0",
35
+ "@atlaskit/editor-common": "^103.17.0",
36
36
  "@atlaskit/editor-palette": "^2.1.0",
37
37
  "@atlaskit/editor-plugin-accessibility-utils": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^2.2.0",
@@ -206,6 +206,9 @@
206
206
  },
207
207
  "platform_editor_controls_patch_6": {
208
208
  "type": "boolean"
209
+ },
210
+ "platform_editor_fix_table_resizing_undo": {
211
+ "type": "boolean"
209
212
  }
210
213
  }
211
214
  }
@@ -1308,6 +1308,11 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
1308
1308
 
1309
1309
  if (!isUserTriggered) {
1310
1310
  tintDirtyTransaction(tr);
1311
+ if (fg('platform_editor_fix_table_resizing_undo')) {
1312
+ // Avoid adding this transaction separately to the history as these are automatic updates
1313
+ // as a consequence of another action
1314
+ tr.setMeta('addToHistory', false);
1315
+ }
1311
1316
  }
1312
1317
 
1313
1318
  dispatch(tr);
@@ -12,6 +12,7 @@ import type { GuidelineConfig } from '@atlaskit/editor-common/guideline';
12
12
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
13
13
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
14
14
  import type { EditorContainerWidth } from '@atlaskit/editor-common/types';
15
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
15
16
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
16
17
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
17
18
  import {
@@ -20,6 +21,7 @@ import {
20
21
  akEditorMobileBreakoutPoint,
21
22
  } from '@atlaskit/editor-shared-styles';
22
23
  import { fg } from '@atlaskit/platform-feature-flags';
24
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
23
25
 
24
26
  import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../pm-plugins/commands/commands-with-analytics';
25
27
  import { getPluginState } from '../pm-plugins/plugin-factory';
@@ -28,7 +30,7 @@ import {
28
30
  TABLE_OFFSET_IN_COMMENT_EDITOR,
29
31
  } from '../pm-plugins/table-resizing/utils/consts';
30
32
  import { ALIGN_CENTER, ALIGN_START } from '../pm-plugins/utils/alignment';
31
- import type { PluginInjectionAPI, TableSharedState } from '../types';
33
+ import type { PluginInjectionAPI } from '../types';
32
34
  import { TableCssClassName as ClassName } from '../types';
33
35
 
34
36
  import { getAlignmentStyle } from './table-container-styles';
@@ -77,11 +79,46 @@ const AlignmentTableContainer = ({
77
79
  editorView,
78
80
  }: PropsWithChildren<AlignmentTableContainerProps>) => {
79
81
  const alignment = node.attrs.layout !== ALIGN_START ? ALIGN_CENTER : ALIGN_START;
80
- const { tableState } = useSharedPluginState(pluginInjectionApi, ['table']);
82
+ const { tableState } = useSharedPluginState(pluginInjectionApi, ['table'], {
83
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
84
+ });
85
+
86
+ // isFullWidthModeEnabled
87
+ const isTableFullWidthModeEnabledSelector = useSharedPluginStateSelector(
88
+ pluginInjectionApi,
89
+ 'table.isFullWidthModeEnabled',
90
+ {
91
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
92
+ },
93
+ );
94
+ const isFullWidthModeEnabled = editorExperiment(
95
+ 'platform_editor_usesharedpluginstateselector',
96
+ true,
97
+ )
98
+ ? isTableFullWidthModeEnabledSelector
99
+ : tableState?.isFullWidthModeEnabled;
100
+
101
+ // wasFullWidthModeEnabled
102
+ const wasFullWidthModeEnabledSelector = useSharedPluginStateSelector(
103
+ pluginInjectionApi,
104
+ 'table.wasFullWidthModeEnabled',
105
+ {
106
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
107
+ },
108
+ );
109
+ const wasFullWidthModeEnabled = editorExperiment(
110
+ 'platform_editor_usesharedpluginstateselector',
111
+ true,
112
+ )
113
+ ? wasFullWidthModeEnabledSelector
114
+ : tableState?.wasFullWidthModeEnabled;
81
115
 
82
116
  useEffect(() => {
83
- if (tableState && editorView && getPos) {
84
- const { wasFullWidthModeEnabled, isFullWidthModeEnabled } = tableState;
117
+ if (editorExperiment('platform_editor_usesharedpluginstateselector', false) && !tableState) {
118
+ return;
119
+ }
120
+
121
+ if (editorView && getPos) {
85
122
  const { state, dispatch } = editorView;
86
123
 
87
124
  if (
@@ -109,7 +146,7 @@ const AlignmentTableContainer = ({
109
146
  }
110
147
  }
111
148
  // eslint-disable-next-line react-hooks/exhaustive-deps
112
- }, [editorView, tableState, node]);
149
+ }, [editorView, tableState, isFullWidthModeEnabled, wasFullWidthModeEnabled, node]);
113
150
 
114
151
  const style = useMemo(() => {
115
152
  return getAlignmentStyle(alignment);
@@ -202,8 +239,25 @@ export const ResizableTableContainer = React.memo(
202
239
  const containerRef = useRef<HTMLDivElement | null>(null);
203
240
  const tableWidthRef = useRef<number>(akEditorDefaultLayoutWidth);
204
241
  const [resizing, setIsResizing] = useState(false);
205
- const { tableState } = useSharedPluginState(pluginInjectionApi, ['table']);
206
- const { isFullWidthModeEnabled } = tableState as TableSharedState;
242
+
243
+ const { tableState } = useSharedPluginState(pluginInjectionApi, ['table'], {
244
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
245
+ });
246
+
247
+ // isFullWidthModeEnabled
248
+ const isFullWidthModeEnabledSelector = useSharedPluginStateSelector(
249
+ pluginInjectionApi,
250
+ 'table.isFullWidthModeEnabled',
251
+ {
252
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
253
+ },
254
+ );
255
+ const isFullWidthModeEnabled = editorExperiment(
256
+ 'platform_editor_usesharedpluginstateselector',
257
+ true,
258
+ )
259
+ ? isFullWidthModeEnabledSelector
260
+ : tableState?.isFullWidthModeEnabled;
207
261
 
208
262
  const updateContainerHeight = useCallback((height: number | 'auto') => {
209
263
  // current StickyHeader State is not stable to be fetch.
@@ -277,7 +331,17 @@ export const ResizableTableContainer = React.memo(
277
331
  );
278
332
 
279
333
  const tableWidth = getTableContainerWidth(node);
280
- const { editorViewModeState } = useSharedPluginState(pluginInjectionApi, ['editorViewMode']);
334
+ const { editorViewModeState } = useSharedPluginState(pluginInjectionApi, ['editorViewMode'], {
335
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
336
+ });
337
+
338
+ // mode
339
+ const modeSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode', {
340
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
341
+ });
342
+ const mode = editorExperiment('platform_editor_usesharedpluginstateselector', true)
343
+ ? modeSelector
344
+ : editorViewModeState?.mode;
281
345
 
282
346
  let responsiveContainerWidth = 0;
283
347
  const resizeHandleSpacing = 12;
@@ -341,7 +405,10 @@ export const ResizableTableContainer = React.memo(
341
405
  isCommentEditor,
342
406
  };
343
407
 
344
- const isLivePageViewMode = editorViewModeState?.mode === 'view';
408
+ const isLivePageViewMode =
409
+ (editorExperiment('platform_editor_usesharedpluginstateselector', true)
410
+ ? mode
411
+ : editorViewModeState?.mode) === 'view';
345
412
 
346
413
  return (
347
414
  <AlignmentTableContainerWrapper
@@ -19,6 +19,7 @@ import { tableMessages as messages } from '@atlaskit/editor-common/messages';
19
19
  import { logException } from '@atlaskit/editor-common/monitoring';
20
20
  import type { HandleResize, HandleSize } from '@atlaskit/editor-common/resizer';
21
21
  import { ResizerNext } from '@atlaskit/editor-common/resizer';
22
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
22
23
  import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
23
24
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
24
25
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
@@ -26,6 +27,7 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
26
27
  import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
27
28
  import { findTable } from '@atlaskit/editor-tables/utils';
28
29
  import { fg } from '@atlaskit/platform-feature-flags';
30
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
29
31
  import { token } from '@atlaskit/tokens';
30
32
 
31
33
  import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../pm-plugins/commands/commands-with-analytics';
@@ -211,8 +213,21 @@ export const TableResizer = ({
211
213
  const isResizing = useRef(false);
212
214
  const areResizeMetaKeysPressed = useRef(false);
213
215
  const resizerRef = useRef<ResizerNextHandler>(null);
214
- const { tableState } = useSharedPluginState(pluginInjectionApi, ['table']);
215
- const { widthToWidest } = tableState as TableSharedStateInternal;
216
+ const { tableState } = useSharedPluginState(pluginInjectionApi, ['table'], {
217
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
218
+ });
219
+
220
+ // widthToWidest
221
+ const widthToWidestSelector = useSharedPluginStateSelector(
222
+ pluginInjectionApi,
223
+ 'table.widthToWidest' as never,
224
+ {
225
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
226
+ },
227
+ ) as TableSharedStateInternal['widthToWidest'];
228
+ const widthToWidest = editorExperiment('platform_editor_usesharedpluginstateselector', true)
229
+ ? widthToWidestSelector
230
+ : (tableState as TableSharedStateInternal).widthToWidest;
216
231
 
217
232
  // used to reposition tooltip when table is resizing via keyboard
218
233
  const updateTooltip = React.useRef<() => void>();
@@ -254,9 +269,9 @@ export const TableResizer = ({
254
269
  const excludeGuidelineConfig = useMemo(
255
270
  () => ({
256
271
  innerGuidelines: !!isTableAlignmentEnabled,
257
- breakoutPoints: !!(isTableAlignmentEnabled && tableState?.isFullWidthModeEnabled),
272
+ breakoutPoints: !!(isTableAlignmentEnabled && isFullWidthModeEnabled),
258
273
  }),
259
- [tableState, isTableAlignmentEnabled],
274
+ [isFullWidthModeEnabled, isTableAlignmentEnabled],
260
275
  );
261
276
 
262
277
  const updateActiveGuidelines = useCallback(
@@ -4,6 +4,7 @@ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
5
5
  import type { DomAtPos } from '@atlaskit/editor-prosemirror/utils';
6
6
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
7
8
 
8
9
  import type { PluginInjectionAPI } from '../../../types';
9
10
  import { updateColumnWidths } from '../../transforms/column-width';
@@ -267,9 +268,10 @@ export const scaleTable =
267
268
 
268
269
  if (resizeState) {
269
270
  tr = updateColumnWidths(resizeState, node, start, api)(tr);
270
- // Avoid adding this transaction separately to the history as these are automatic updates
271
- // as a consequence of another action
272
- tr.setMeta('addToHistory', false);
271
+
272
+ if (!fg('platform_editor_fix_table_resizing_undo')) {
273
+ tr.setMeta('addToHistory', false);
274
+ }
273
275
 
274
276
  if (tr.docChanged) {
275
277
  tr.setMeta('scrollIntoView', false);