@atlaskit/editor-plugin-table 10.9.4 → 10.9.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 (46) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/nodeviews/TableContainer.js +63 -32
  3. package/dist/cjs/nodeviews/TableResizer.js +18 -10
  4. package/dist/cjs/tablePlugin.js +10 -2
  5. package/dist/cjs/ui/DragHandle/index.js +19 -3
  6. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -2
  7. package/dist/cjs/ui/TableFloatingControls/CornerControls/DragCornerControls.js +14 -5
  8. package/dist/cjs/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -2
  9. package/dist/cjs/ui/TableFloatingControls/NumberColumn/index.js +1 -1
  10. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +11 -2
  11. package/dist/cjs/ui/global-styles.js +11 -2
  12. package/dist/cjs/ui/icons/SortingIconWrapper.js +12 -2
  13. package/dist/es2019/nodeviews/TableContainer.js +41 -13
  14. package/dist/es2019/nodeviews/TableResizer.js +13 -6
  15. package/dist/es2019/tablePlugin.js +10 -2
  16. package/dist/es2019/ui/DragHandle/index.js +19 -3
  17. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -2
  18. package/dist/es2019/ui/TableFloatingControls/CornerControls/DragCornerControls.js +14 -5
  19. package/dist/es2019/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -2
  20. package/dist/es2019/ui/TableFloatingControls/NumberColumn/index.js +1 -1
  21. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +11 -2
  22. package/dist/es2019/ui/global-styles.js +11 -2
  23. package/dist/es2019/ui/icons/SortingIconWrapper.js +12 -2
  24. package/dist/esm/nodeviews/TableContainer.js +63 -32
  25. package/dist/esm/nodeviews/TableResizer.js +18 -10
  26. package/dist/esm/tablePlugin.js +10 -2
  27. package/dist/esm/ui/DragHandle/index.js +19 -3
  28. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +12 -2
  29. package/dist/esm/ui/TableFloatingControls/CornerControls/DragCornerControls.js +14 -5
  30. package/dist/esm/ui/TableFloatingControls/FloatingControlsWithSelection.js +11 -2
  31. package/dist/esm/ui/TableFloatingControls/NumberColumn/index.js +1 -1
  32. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +11 -2
  33. package/dist/esm/ui/global-styles.js +11 -2
  34. package/dist/esm/ui/icons/SortingIconWrapper.js +12 -2
  35. package/package.json +1 -1
  36. package/src/nodeviews/TableContainer.tsx +76 -9
  37. package/src/nodeviews/TableResizer.tsx +19 -4
  38. package/src/tablePlugin.tsx +12 -2
  39. package/src/ui/DragHandle/index.tsx +27 -3
  40. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +15 -5
  41. package/src/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +16 -5
  42. package/src/ui/TableFloatingControls/FloatingControlsWithSelection.tsx +13 -2
  43. package/src/ui/TableFloatingControls/NumberColumn/index.tsx +4 -4
  44. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +13 -2
  45. package/src/ui/global-styles.tsx +14 -2
  46. package/src/ui/icons/SortingIconWrapper.tsx +15 -2
@@ -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
  };
@@ -5,12 +5,14 @@ import React, { useCallback, useMemo, useRef } from 'react';
5
5
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
6
  import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
7
7
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
8
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
8
9
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
9
10
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
11
  import { akEditorTableNumberColumnWidth } from '@atlaskit/editor-shared-styles';
11
12
  import { CellSelection } from '@atlaskit/editor-tables';
12
13
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
13
14
  import { fg } from '@atlaskit/platform-feature-flags';
15
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
16
 
15
17
  import {
16
18
  clearHoverSelection,
@@ -76,7 +78,17 @@ export const ColumnControls = ({
76
78
  api,
77
79
  }: ColumnControlsProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
78
80
  const columnControlsRef = useRef<HTMLDivElement>(null);
79
- const { selectionState } = useSharedPluginState(api, ['selection']);
81
+
82
+ // selection
83
+ const { selectionState } = useSharedPluginState(api, ['selection'], {
84
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
85
+ });
86
+ const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
87
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
88
+ });
89
+ const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
90
+ ? selectionsSelector
91
+ : selectionState?.selection;
80
92
 
81
93
  const widths =
82
94
  colWidths
@@ -89,15 +101,13 @@ export const ColumnControls = ({
89
101
  // TODO: ED-26961 - reusing getRowsParams here because it's generic enough to work for columns -> rename
90
102
  const columnParams = getRowsParams(colWidths ?? []);
91
103
  const colIndex = hoveredCell?.colIndex;
92
- const selectedColIndexes = getSelectedColumns(
93
- selectionState?.selection || editorView.state.selection,
94
- );
104
+ const selectedColIndexes = getSelectedColumns(selection || editorView.state.selection);
95
105
 
96
106
  const firstRow = tableRef.querySelector('tr');
97
107
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
98
108
 
99
109
  const rowControlStickyTop = 45;
100
- const marginTop = hasHeaderRow && stickyTop !== undefined ? rowControlStickyTop ?? 0 : 0;
110
+ const marginTop = hasHeaderRow && stickyTop !== undefined ? (rowControlStickyTop ?? 0) : 0;
101
111
 
102
112
  const handleClick = useCallback(
103
113
  (event: MouseEvent) => {
@@ -7,7 +7,9 @@ import { injectIntl } from 'react-intl-next';
7
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
8
8
  import { tableMessages as messages } from '@atlaskit/editor-common/messages';
9
9
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
10
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
10
11
  import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
12
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
11
13
 
12
14
  import { clearHoverSelection } from '../../../pm-plugins/commands';
13
15
  import type { TablePlugin } from '../../../tablePluginType';
@@ -71,7 +73,16 @@ const DragCornerControlsComponentWithSelection = ({
71
73
  intl: { formatMessage },
72
74
  api,
73
75
  }: CornerControlProps & WrappedComponentProps & { api?: ExtractInjectionAPI<TablePlugin> }) => {
74
- const { selectionState } = useSharedPluginState(api, ['selection']);
76
+ // selection
77
+ const { selectionState } = useSharedPluginState(api, ['selection'], {
78
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
79
+ });
80
+ const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
81
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
82
+ });
83
+ const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
84
+ ? selectionsSelector
85
+ : selectionState?.selection;
75
86
 
76
87
  const handleOnClick = () => {
77
88
  const { state, dispatch } = editorView;
@@ -83,15 +94,15 @@ const DragCornerControlsComponentWithSelection = ({
83
94
  clearHoverSelection()(state, dispatch);
84
95
  };
85
96
  const isActive = useMemo(() => {
86
- if (!selectionState?.selection) {
97
+ if (!selection) {
87
98
  return;
88
99
  }
89
- const table = findTable(selectionState.selection);
100
+ const table = findTable(selection);
90
101
  if (!table) {
91
102
  return false;
92
103
  }
93
- return isTableSelected(selectionState.selection);
94
- }, [selectionState]);
104
+ return isTableSelected(selection);
105
+ }, [selection]);
95
106
 
96
107
  if (isResizing) {
97
108
  return null;
@@ -2,7 +2,9 @@ import React from 'react';
2
2
 
3
3
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
4
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
5
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
8
 
7
9
  import type { TablePlugin } from '../../tablePluginType';
8
10
 
@@ -38,7 +40,16 @@ export const FloatingControlsWithSelection = ({
38
40
  tableActive,
39
41
  api,
40
42
  }: FloatingControlsWithSelectionProps) => {
41
- const { selectionState } = useSharedPluginState(api, ['selection']);
43
+ // selection
44
+ const { selectionState } = useSharedPluginState(api, ['selection'], {
45
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
46
+ });
47
+ const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
48
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
49
+ });
50
+ const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
51
+ ? selectionsSelector
52
+ : selectionState?.selection;
42
53
 
43
54
  return (
44
55
  <>
@@ -53,7 +64,7 @@ export const FloatingControlsWithSelection = ({
53
64
  stickyTop={tableActive ? stickyTop : undefined}
54
65
  />
55
66
  <RowControls
56
- selection={selectionState?.selection}
67
+ selection={selection}
57
68
  editorView={editorView}
58
69
  tableRef={tableRef}
59
70
  hoverRows={hoverRows}
@@ -66,7 +66,7 @@ export default class NumberColumn extends Component<Props, any> {
66
66
  {hasHeaderRow ? (index > 0 ? index : null) : index + 1}
67
67
  </div>
68
68
  ) : (
69
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
69
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions, @atlassian/a11y/interactive-element-not-keyboard-focusable
70
70
  <div
71
71
  // Ignored via go/ees005
72
72
  // eslint-disable-next-line react/no-array-index-key
@@ -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);
@@ -4,6 +4,7 @@ import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'reac
4
4
 
5
5
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
6
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
7
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
7
8
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
8
9
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
9
10
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -11,6 +12,7 @@ import { CellSelection } from '@atlaskit/editor-tables';
11
12
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
12
13
  import { fg } from '@atlaskit/platform-feature-flags';
13
14
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
15
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
16
  import { token } from '@atlaskit/tokens';
15
17
 
16
18
  import { clearHoverSelection } from '../../../pm-plugins/commands';
@@ -385,7 +387,16 @@ export const DragControlsWithSelection = ({
385
387
  updateCellHoverLocation,
386
388
  api,
387
389
  }: Exclude<DragControlsProps, 'selection'>) => {
388
- const { selectionState } = useSharedPluginState(api, ['selection']);
390
+ // selection
391
+ const { selectionState } = useSharedPluginState(api, ['selection'], {
392
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
393
+ });
394
+ const selectionsSelector = useSharedPluginStateSelector(api, 'selection.selection', {
395
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
396
+ });
397
+ const selection = editorExperiment('platform_editor_usesharedpluginstateselector', true)
398
+ ? selectionsSelector
399
+ : selectionState?.selection;
389
400
 
390
401
  return (
391
402
  <DragControls
@@ -403,7 +414,7 @@ export const DragControlsWithSelection = ({
403
414
  selectRows={selectRows}
404
415
  updateCellHoverLocation={updateCellHoverLocation}
405
416
  api={api}
406
- selection={selectionState?.selection}
417
+ selection={selection}
407
418
  />
408
419
  );
409
420
  };
@@ -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({
@@ -3,6 +3,8 @@ import React from 'react';
3
3
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
4
  import { SortingIcon } from '@atlaskit/editor-common/table';
5
5
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
+ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
7
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
8
 
7
9
  import type { TablePlugin } from '../../tablePluginType';
8
10
 
@@ -12,8 +14,19 @@ type SortingIconWrapperProps = SortingIconProps & {
12
14
  };
13
15
 
14
16
  export const SortingIconWrapper = (props: SortingIconWrapperProps) => {
15
- const { editorViewModeState } = useSharedPluginState(props.api, ['editorViewMode']);
16
- if (editorViewModeState?.mode === 'edit') {
17
+ const { editorViewModeState } = useSharedPluginState(props.api, ['editorViewMode'], {
18
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true),
19
+ });
20
+
21
+ // mode
22
+ const modeSelector = useSharedPluginStateSelector(props.api, 'editorViewMode.mode', {
23
+ disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false),
24
+ });
25
+ const mode = editorExperiment('platform_editor_usesharedpluginstateselector', true)
26
+ ? modeSelector
27
+ : editorViewModeState?.mode;
28
+
29
+ if (mode === 'edit') {
17
30
  return null;
18
31
  }
19
32
  // Ignored via go/ees005