@atlaskit/editor-plugin-table 9.1.3 → 9.2.0

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 (49) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/nodeviews/TableComponent.js +5 -5
  3. package/dist/cjs/nodeviews/TableComponentWithSharedState.js +6 -4
  4. package/dist/cjs/nodeviews/table.js +1 -2
  5. package/dist/cjs/tablePlugin.js +1 -0
  6. package/dist/cjs/ui/DragHandle/index.js +55 -6
  7. package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +17 -2
  8. package/dist/cjs/ui/TableFloatingColumnControls/index.js +1 -2
  9. package/dist/cjs/ui/TableFloatingControls/RowControls/DragControls.js +60 -7
  10. package/dist/cjs/ui/TableFloatingControls/index.js +24 -4
  11. package/dist/es2019/nodeviews/TableComponent.js +5 -5
  12. package/dist/es2019/nodeviews/TableComponentWithSharedState.js +6 -4
  13. package/dist/es2019/nodeviews/table.js +1 -2
  14. package/dist/es2019/tablePlugin.js +1 -0
  15. package/dist/es2019/ui/DragHandle/index.js +57 -6
  16. package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +18 -3
  17. package/dist/es2019/ui/TableFloatingColumnControls/index.js +1 -2
  18. package/dist/es2019/ui/TableFloatingControls/RowControls/DragControls.js +62 -7
  19. package/dist/es2019/ui/TableFloatingControls/index.js +25 -5
  20. package/dist/esm/nodeviews/TableComponent.js +5 -5
  21. package/dist/esm/nodeviews/TableComponentWithSharedState.js +6 -4
  22. package/dist/esm/nodeviews/table.js +1 -2
  23. package/dist/esm/tablePlugin.js +1 -0
  24. package/dist/esm/ui/DragHandle/index.js +54 -5
  25. package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +18 -3
  26. package/dist/esm/ui/TableFloatingColumnControls/index.js +1 -2
  27. package/dist/esm/ui/TableFloatingControls/RowControls/DragControls.js +60 -7
  28. package/dist/esm/ui/TableFloatingControls/index.js +25 -5
  29. package/dist/types/nodeviews/TableComponent.d.ts +3 -1
  30. package/dist/types/types/index.d.ts +1 -1
  31. package/dist/types/ui/DragHandle/index.d.ts +21 -0
  32. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -1
  33. package/dist/types/ui/TableFloatingControls/RowControls/DragControls.d.ts +8 -5
  34. package/dist/types-ts4.5/nodeviews/TableComponent.d.ts +3 -1
  35. package/dist/types-ts4.5/types/index.d.ts +1 -1
  36. package/dist/types-ts4.5/ui/DragHandle/index.d.ts +21 -0
  37. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -1
  38. package/dist/types-ts4.5/ui/TableFloatingControls/RowControls/DragControls.d.ts +8 -5
  39. package/package.json +8 -5
  40. package/src/nodeviews/TableComponent.tsx +9 -7
  41. package/src/nodeviews/TableComponentWithSharedState.tsx +4 -2
  42. package/src/nodeviews/table.tsx +1 -2
  43. package/src/tablePlugin.tsx +1 -0
  44. package/src/types/index.ts +1 -0
  45. package/src/ui/DragHandle/index.tsx +67 -2
  46. package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +38 -19
  47. package/src/ui/TableFloatingColumnControls/index.tsx +2 -5
  48. package/src/ui/TableFloatingControls/RowControls/DragControls.tsx +86 -25
  49. package/src/ui/TableFloatingControls/index.tsx +54 -27
@@ -27,7 +27,7 @@ import type { TablePlugin } from '../../../tablePluginType';
27
27
  import type { CellHoverMeta, HandleTypes } from '../../../types';
28
28
  import { TableCssClassName as ClassName } from '../../../types';
29
29
  import type { DragHandleAppearance } from '../../DragHandle';
30
- import { DragHandle } from '../../DragHandle';
30
+ import { DragHandle, DragHandleWithSharedState } from '../../DragHandle';
31
31
 
32
32
  interface ColumnControlsProps {
33
33
  editorView: EditorView;
@@ -68,7 +68,6 @@ export const ColumnControls = ({
68
68
  isInDanger,
69
69
  rowHeights,
70
70
  colWidths,
71
- hasHeaderColumn,
72
71
  isTableHovered,
73
72
  tableContainerWidth,
74
73
  isNumberColumnEnabled,
@@ -98,7 +97,7 @@ export const ColumnControls = ({
98
97
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
99
98
 
100
99
  const rowControlStickyTop = fg('platform_editor_breakout_use_css') ? 45 : rowHeights?.[0];
101
- const marginTop = hasHeaderRow && stickyTop !== undefined ? rowControlStickyTop ?? 0 : 0;
100
+ const marginTop = hasHeaderRow && stickyTop !== undefined ? (rowControlStickyTop ?? 0) : 0;
102
101
 
103
102
  const handleClick = useCallback(
104
103
  (event: MouseEvent) => {
@@ -238,22 +237,42 @@ export const ColumnControls = ({
238
237
  isHover ? colIndex : isPlaceholder ? appearance : selectedColIndexes[0]
239
238
  }-drag-handle`}
240
239
  >
241
- <DragHandle
242
- isDragMenuTarget={!isHover}
243
- direction="column"
244
- tableLocalId={localId || ''}
245
- indexes={indexes}
246
- hoveredCell={hoveredCell}
247
- previewWidth={previewWidth}
248
- forceDefaultHandle={!isHover}
249
- previewHeight={previewHeight}
250
- appearance={appearance}
251
- onClick={handleClick}
252
- onMouseOver={handleMouseOver}
253
- onMouseOut={handleMouseOut}
254
- toggleDragMenu={toggleDragMenuHandler}
255
- editorView={editorView}
256
- />
240
+ {fg('platform_editor_table_use_shared_state_hook_fg') ? (
241
+ <DragHandleWithSharedState
242
+ isDragMenuTarget={!isHover}
243
+ direction="column"
244
+ tableLocalId={localId || ''}
245
+ indexes={indexes}
246
+ hoveredCell={hoveredCell}
247
+ previewWidth={previewWidth}
248
+ forceDefaultHandle={!isHover}
249
+ previewHeight={previewHeight}
250
+ appearance={appearance}
251
+ onClick={handleClick}
252
+ onMouseOver={handleMouseOver}
253
+ onMouseOut={handleMouseOut}
254
+ toggleDragMenu={toggleDragMenuHandler}
255
+ editorView={editorView}
256
+ api={api}
257
+ />
258
+ ) : (
259
+ <DragHandle
260
+ isDragMenuTarget={!isHover}
261
+ direction="column"
262
+ tableLocalId={localId || ''}
263
+ indexes={indexes}
264
+ hoveredCell={hoveredCell}
265
+ previewWidth={previewWidth}
266
+ forceDefaultHandle={!isHover}
267
+ previewHeight={previewHeight}
268
+ appearance={appearance}
269
+ onClick={handleClick}
270
+ onMouseOver={handleMouseOver}
271
+ onMouseOut={handleMouseOut}
272
+ toggleDragMenu={toggleDragMenuHandler}
273
+ editorView={editorView}
274
+ />
275
+ )}
257
276
  </div>
258
277
  );
259
278
  };
@@ -7,7 +7,6 @@ import type { Selection } from '@atlaskit/editor-prosemirror/state';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
10
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
11
10
 
12
11
  import type { RowStickyState } from '../../pm-plugins/sticky-headers/types';
13
12
  import { getColumnsWidths } from '../../pm-plugins/utils/column-controls';
@@ -102,7 +101,7 @@ const TableFloatingColumnControls = ({
102
101
 
103
102
  if (stickyTop) {
104
103
  const columnControlTopOffsetFromParent = '-12px';
105
- const headerRowHeight = hasHeaderRow && stickyTop !== undefined ? rowHeights?.[0] ?? 0 : 0;
104
+ const headerRowHeight = hasHeaderRow && stickyTop !== undefined ? (rowHeights?.[0] ?? 0) : 0;
106
105
  containerRef?.current?.style.setProperty(
107
106
  'top',
108
107
  fg('platform_editor_breakout_use_css')
@@ -141,9 +140,7 @@ const TableFloatingColumnControls = ({
141
140
  isNumberColumnEnabled={isNumberColumnEnabled}
142
141
  isDragging={isDragging}
143
142
  getScrollOffset={getScrollOffset}
144
- api={
145
- editorExperiment('platform_editor_table_use_shared_state_hook', true) ? api : undefined
146
- }
143
+ api={fg('platform_editor_table_use_shared_state_hook_fg') ? api : undefined}
147
144
  />
148
145
  {isDragging && (
149
146
  <ColumnDropTargets
@@ -2,14 +2,14 @@
2
2
  import type { MouseEvent } from 'react';
3
3
  import React, { Fragment, useCallback, useEffect, useMemo, useState } from 'react';
4
4
 
5
- import { injectIntl } from 'react-intl-next';
6
- import type { WrappedComponentProps } from 'react-intl-next';
7
-
5
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
8
7
  import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
9
8
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
10
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
11
10
  import { CellSelection } from '@atlaskit/editor-tables';
12
11
  import { getSelectionRect } from '@atlaskit/editor-tables/utils';
12
+ import { fg } from '@atlaskit/platform-feature-flags';
13
13
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
14
14
  import { token } from '@atlaskit/tokens';
15
15
 
@@ -19,11 +19,12 @@ import type { TriggerType } from '../../../pm-plugins/drag-and-drop/types';
19
19
  import { getPluginState as getTablePluginState } from '../../../pm-plugins/plugin-factory';
20
20
  import { getRowHeights, getRowsParams } from '../../../pm-plugins/utils/row-controls';
21
21
  import { getSelectedRowIndexes } from '../../../pm-plugins/utils/selection';
22
+ import type { TablePlugin } from '../../../tablePluginType';
22
23
  import { TableCssClassName as ClassName } from '../../../types';
23
24
  import type { CellHoverMeta, DraggableSourceData, HandleTypes } from '../../../types';
24
25
  import { dropTargetExtendedWidth } from '../../consts';
25
26
  import type { DragHandleAppearance } from '../../DragHandle';
26
- import { DragHandle } from '../../DragHandle';
27
+ import { DragHandle, DragHandleWithSharedState } from '../../DragHandle';
27
28
  import RowDropTarget from '../RowDropTarget';
28
29
 
29
30
  type DragControlsProps = {
@@ -40,6 +41,8 @@ type DragControlsProps = {
40
41
  selectRow: (row: number, expand: boolean) => void;
41
42
  selectRows: (rowIndexes: number[]) => void;
42
43
  updateCellHoverLocation: (rowIndex: number) => void;
44
+ api?: ExtractInjectionAPI<TablePlugin>;
45
+ selection?: Selection;
43
46
  };
44
47
 
45
48
  const getSelectedRows = (selection: Selection) => {
@@ -53,7 +56,7 @@ const getSelectedRows = (selection: Selection) => {
53
56
  return [];
54
57
  };
55
58
 
56
- const DragControlsComponent = ({
59
+ export const DragControls = ({
57
60
  tableRef,
58
61
  tableNode,
59
62
  tableWidth,
@@ -67,13 +70,14 @@ const DragControlsComponent = ({
67
70
  selectRow,
68
71
  selectRows,
69
72
  updateCellHoverLocation,
70
- }: DragControlsProps & WrappedComponentProps) => {
73
+ api,
74
+ selection,
75
+ }: DragControlsProps) => {
71
76
  const [isDragging, setIsDragging] = useState(false);
72
-
73
77
  const rowHeights = getRowHeights(tableRef);
74
78
  const rowsParams = getRowsParams(rowHeights);
75
79
  const heights = rowHeights.map((height) => `${height - 1}px`).join(' ');
76
- const selectedRowIndexes = getSelectedRows(editorView.state.selection);
80
+ const selectedRowIndexes = getSelectedRows(selection ?? editorView.state.selection);
77
81
  const currentNodeLocalId = tableNode?.attrs?.localId ?? '';
78
82
 
79
83
  useEffect(() => {
@@ -213,22 +217,42 @@ const DragControlsComponent = ({
213
217
  }}
214
218
  data-testid={`table-floating-row-${isHover ? rowIndex : selectedRowIndexes[0]}-drag-handle`}
215
219
  >
216
- <DragHandle
217
- isDragMenuTarget={!isHover}
218
- direction="row"
219
- tableLocalId={currentNodeLocalId}
220
- indexes={indexes}
221
- forceDefaultHandle={!isHover}
222
- previewWidth={tableWidth}
223
- previewHeight={previewHeight}
224
- appearance={appearance}
225
- hoveredCell={hoveredCell}
226
- onClick={handleClick}
227
- onMouseOver={handleMouseOver}
228
- onMouseOut={handleMouseOut}
229
- toggleDragMenu={toggleDragMenuHandler}
230
- editorView={editorView}
231
- />
220
+ {fg('platform_editor_table_use_shared_state_hook_fg') ? (
221
+ <DragHandleWithSharedState
222
+ isDragMenuTarget={!isHover}
223
+ direction="row"
224
+ tableLocalId={currentNodeLocalId}
225
+ indexes={indexes}
226
+ forceDefaultHandle={!isHover}
227
+ previewWidth={tableWidth}
228
+ previewHeight={previewHeight}
229
+ appearance={appearance}
230
+ hoveredCell={hoveredCell}
231
+ onClick={handleClick}
232
+ onMouseOver={handleMouseOver}
233
+ onMouseOut={handleMouseOut}
234
+ toggleDragMenu={toggleDragMenuHandler}
235
+ editorView={editorView}
236
+ api={api}
237
+ />
238
+ ) : (
239
+ <DragHandle
240
+ isDragMenuTarget={!isHover}
241
+ direction="row"
242
+ tableLocalId={currentNodeLocalId}
243
+ indexes={indexes}
244
+ forceDefaultHandle={!isHover}
245
+ previewWidth={tableWidth}
246
+ previewHeight={previewHeight}
247
+ appearance={appearance}
248
+ hoveredCell={hoveredCell}
249
+ onClick={handleClick}
250
+ onMouseOver={handleMouseOver}
251
+ onMouseOut={handleMouseOut}
252
+ toggleDragMenu={toggleDragMenuHandler}
253
+ editorView={editorView}
254
+ />
255
+ )}
232
256
  </div>
233
257
  );
234
258
  };
@@ -347,4 +371,41 @@ const DragControlsComponent = ({
347
371
  );
348
372
  };
349
373
 
350
- export const DragControls = injectIntl(DragControlsComponent);
374
+ export const DragControlsWithSelection = ({
375
+ editorView,
376
+ tableRef,
377
+ tableNode,
378
+ tableWidth,
379
+ tableActive,
380
+ hoveredCell,
381
+ isInDanger,
382
+ isTableHovered,
383
+ isResizing,
384
+ hoverRows,
385
+ selectRow,
386
+ selectRows,
387
+ updateCellHoverLocation,
388
+ api,
389
+ }: Exclude<DragControlsProps, 'selection'>) => {
390
+ const { selectionState } = useSharedPluginState(api, ['selection']);
391
+
392
+ return (
393
+ <DragControls
394
+ editorView={editorView}
395
+ tableRef={tableRef}
396
+ tableNode={tableNode}
397
+ tableWidth={tableWidth}
398
+ tableActive={tableActive}
399
+ hoveredCell={hoveredCell}
400
+ isInDanger={isInDanger}
401
+ isTableHovered={isTableHovered}
402
+ isResizing={isResizing}
403
+ hoverRows={hoverRows}
404
+ selectRow={selectRow}
405
+ selectRows={selectRows}
406
+ updateCellHoverLocation={updateCellHoverLocation}
407
+ api={api}
408
+ selection={selectionState?.selection}
409
+ />
410
+ );
411
+ };
@@ -8,6 +8,7 @@ import type { Node as PmNode } from '@atlaskit/editor-prosemirror/model';
8
8
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
9
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
10
  import { findTable } from '@atlaskit/editor-tables/utils';
11
+ import { fg } from '@atlaskit/platform-feature-flags';
11
12
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
12
13
 
13
14
  import { hoverCell, hoverRows, selectRow, selectRows } from '../../pm-plugins/commands';
@@ -25,7 +26,7 @@ import {
25
26
  import { FloatingControlsWithSelection } from './FloatingControlsWithSelection';
26
27
  import NumberColumn from './NumberColumn';
27
28
  import { RowControls } from './RowControls/ClassicControls';
28
- import { DragControls } from './RowControls/DragControls';
29
+ import { DragControls, DragControlsWithSelection } from './RowControls/DragControls';
29
30
 
30
31
  interface TableFloatingControlsProps {
31
32
  editorView: EditorView;
@@ -51,6 +52,7 @@ interface TableFloatingControlsProps {
51
52
  isChromelessEditor?: boolean;
52
53
  }
53
54
 
55
+ // Row controls
54
56
  export const TableFloatingControls = ({
55
57
  editorView,
56
58
  tableRef,
@@ -171,42 +173,67 @@ export const TableFloatingControls = ({
171
173
  <>
172
174
  {isDragAndDropEnabled ? (
173
175
  <>
174
- {shouldShowCornerControls &&
175
- (editorExperiment('platform_editor_table_use_shared_state_hook', true) ? (
176
- <DragCornerControlsWithSelection
177
- editorView={editorView}
176
+ {fg('platform_editor_table_use_shared_state_hook_fg') ? (
177
+ <>
178
+ {shouldShowCornerControls && (
179
+ <DragCornerControlsWithSelection
180
+ editorView={editorView}
181
+ tableRef={tableRef}
182
+ isInDanger={isInDanger}
183
+ isResizing={isResizing}
184
+ api={api}
185
+ />
186
+ )}
187
+ <DragControlsWithSelection
178
188
  tableRef={tableRef}
189
+ tableNode={tableNode}
190
+ hoveredCell={hoveredCell}
191
+ isTableHovered={isTableHovered}
192
+ editorView={editorView}
193
+ tableActive={tableActive}
179
194
  isInDanger={isInDanger}
180
195
  isResizing={isResizing}
196
+ // Ignored via go/ees005
197
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
198
+ tableWidth={tableWrapperWidth!}
199
+ hoverRows={_hoverRows}
200
+ selectRow={_selectRow}
201
+ selectRows={_selectRows}
202
+ updateCellHoverLocation={updateCellHoverLocation}
181
203
  api={api}
182
204
  />
183
- ) : (
184
- <DragCornerControls
185
- editorView={editorView}
205
+ </>
206
+ ) : (
207
+ <>
208
+ {shouldShowCornerControls && (
209
+ <DragCornerControls
210
+ editorView={editorView}
211
+ tableRef={tableRef}
212
+ isInDanger={isInDanger}
213
+ isResizing={isResizing}
214
+ />
215
+ )}
216
+ <DragControls
186
217
  tableRef={tableRef}
218
+ tableNode={tableNode}
219
+ hoveredCell={hoveredCell}
220
+ isTableHovered={isTableHovered}
221
+ editorView={editorView}
222
+ tableActive={tableActive}
187
223
  isInDanger={isInDanger}
188
224
  isResizing={isResizing}
225
+ // Ignored via go/ees005
226
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
227
+ tableWidth={tableWrapperWidth!}
228
+ hoverRows={_hoverRows}
229
+ selectRow={_selectRow}
230
+ selectRows={_selectRows}
231
+ updateCellHoverLocation={updateCellHoverLocation}
189
232
  />
190
- ))}
191
- <DragControls
192
- tableRef={tableRef}
193
- tableNode={tableNode}
194
- hoveredCell={hoveredCell}
195
- isTableHovered={isTableHovered}
196
- editorView={editorView}
197
- tableActive={tableActive}
198
- isInDanger={isInDanger}
199
- isResizing={isResizing}
200
- // Ignored via go/ees005
201
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
202
- tableWidth={tableWrapperWidth!}
203
- hoverRows={_hoverRows}
204
- selectRow={_selectRow}
205
- selectRows={_selectRows}
206
- updateCellHoverLocation={updateCellHoverLocation}
207
- />
233
+ </>
234
+ )}
208
235
  </>
209
- ) : editorExperiment('platform_editor_table_use_shared_state_hook', true) ? (
236
+ ) : fg('platform_editor_table_use_shared_state_hook_fg') ? (
210
237
  <FloatingControlsWithSelection
211
238
  editorView={editorView}
212
239
  tableRef={tableRef}