@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
@@ -31,6 +31,7 @@ import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
31
31
  import { ResizerBreakoutModeLabel } from '@atlaskit/editor-common/resizer';
32
32
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
33
33
  import type { Command, EditorPlugin, GetEditorContainerWidth } from '@atlaskit/editor-common/types';
34
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
34
35
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
35
36
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
36
37
  import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
@@ -873,8 +874,17 @@ const tablePlugin: TablePlugin = ({ config: options, api }) => {
873
874
  )(pluginConfig(options?.tableOptions)),
874
875
  },
875
876
  usePluginHook({ editorView }) {
876
- const { editorViewModeState } = useSharedPluginState(api, ['editorViewMode']);
877
- const mode = editorViewModeState?.mode;
877
+ const { editorViewModeState } = useSharedPluginState(api, ['editorViewMode'], {
878
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
879
+ });
880
+
881
+ // mode
882
+ const modeSelector = useSharedPluginStateSelector(api, 'editorViewMode.mode', {
883
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
884
+ });
885
+ const mode = editorExperiment('platform_editor_usesharedpluginstateselector', true)
886
+ ? modeSelector
887
+ : editorViewModeState?.mode;
878
888
 
879
889
  useEffect(() => {
880
890
  const { state, dispatch } = editorView;
@@ -11,11 +11,13 @@ import { browser } from '@atlaskit/editor-common/browser';
11
11
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
12
12
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
13
13
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
14
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
14
15
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
15
16
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
16
17
  import { findTable, TableMap } from '@atlaskit/editor-tables';
17
18
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
18
19
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
20
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
19
21
  import { token } from '@atlaskit/tokens';
20
22
 
21
23
  import { getPluginState as getDnDPluginState } from '../../pm-plugins/drag-and-drop/plugin-factory';
@@ -327,10 +329,32 @@ const DragHandleComponentWithSharedState = ({
327
329
  intl,
328
330
  api,
329
331
  }: DragHandleWithSharedStateProps & WrappedComponentProps) => {
330
- const { tableState } = useSharedPluginState(api, ['table']) as {
332
+ const { tableState } = useSharedPluginState(api, ['table'], {
333
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
334
+ }) as {
331
335
  tableState?: TableSharedStateInternal;
332
336
  };
333
337
 
338
+ // hoveredColumns
339
+ const hoveredColumnsSelector = useSharedPluginStateSelector(
340
+ api,
341
+ 'table.hoveredColumns' as never,
342
+ {
343
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
344
+ },
345
+ ) as TableSharedStateInternal['hoveredColumns'];
346
+ const hoveredColumns = editorExperiment('platform_editor_usesharedpluginstateselector', true)
347
+ ? hoveredColumnsSelector
348
+ : tableState?.hoveredColumns;
349
+
350
+ // hoveredRows
351
+ const hoveredRowsSelector = useSharedPluginStateSelector(api, 'table.hoveredRows' as never, {
352
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
353
+ }) as TableSharedStateInternal['hoveredRows'];
354
+ const hoveredRows = editorExperiment('platform_editor_usesharedpluginstateselector', true)
355
+ ? hoveredRowsSelector
356
+ : tableState?.hoveredRows;
357
+
334
358
  return (
335
359
  <DragHandleComponent
336
360
  isDragMenuTarget={isDragMenuTarget}
@@ -348,8 +372,8 @@ const DragHandleComponentWithSharedState = ({
348
372
  onClick={onClick}
349
373
  editorView={editorView}
350
374
  intl={intl}
351
- hoveredColumns={tableState?.hoveredColumns}
352
- hoveredRows={tableState?.hoveredRows}
375
+ hoveredColumns={hoveredColumns}
376
+ hoveredRows={hoveredRows}
353
377
  />
354
378
  );
355
379
  };
@@ -107,7 +107,7 @@ export const ColumnControls = ({
107
107
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
108
108
 
109
109
  const rowControlStickyTop = 45;
110
- const marginTop = hasHeaderRow && stickyTop !== undefined ? (rowControlStickyTop ?? 0) : 0;
110
+ const marginTop = hasHeaderRow && stickyTop !== undefined ? rowControlStickyTop ?? 0 : 0;
111
111
 
112
112
  const handleClick = useCallback(
113
113
  (event: MouseEvent) => {
@@ -103,10 +103,10 @@ export default class NumberColumn extends Component<Props, any> {
103
103
  const newPos =
104
104
  selection.head > pos
105
105
  ? // Selection is after table
106
- // nodeSize - 3 will move the position inside last table cell
107
- Selection.near(doc.resolve(pos + ($pos.parent.nodeSize - 3)), -1)
106
+ // nodeSize - 3 will move the position inside last table cell
107
+ Selection.near(doc.resolve(pos + ($pos.parent.nodeSize - 3)), -1)
108
108
  : // Selection is before table
109
- Selection.near($pos);
109
+ Selection.near($pos);
110
110
  editorView.dispatch(tr.setSelection(newPos));
111
111
  }
112
112
  selectRow(index, event.shiftKey);
@@ -7,6 +7,8 @@ import { Global, jsx } from '@emotion/react';
7
7
 
8
8
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
9
9
  import type { FeatureFlags } from '@atlaskit/editor-common/types';
10
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
11
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
12
 
11
13
  import type { PluginInjectionAPI } from '../types';
12
14
 
@@ -21,8 +23,18 @@ export const GlobalStylesWrapper = ({
21
23
  isDragAndDropEnabledOption?: boolean;
22
24
  api?: PluginInjectionAPI;
23
25
  }) => {
24
- const { editorViewModeState } = useSharedPluginState(api, ['editorViewMode']);
25
- const isLivePageViewMode = editorViewModeState?.mode === 'view';
26
+ // mode
27
+ const { editorViewModeState } = useSharedPluginState(api, ['editorViewMode'], {
28
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
29
+ });
30
+ const modeSelector = useSharedPluginStateSelector(api, 'editorViewMode.mode', {
31
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
32
+ });
33
+ const mode = editorExperiment('platform_editor_usesharedpluginstateselector', true)
34
+ ? modeSelector
35
+ : editorViewModeState?.mode;
36
+
37
+ const isLivePageViewMode = mode === 'view';
26
38
  return (
27
39
  <Global
28
40
  styles={tableStyles({