@atlaskit/editor-plugin-table 5.3.4 → 5.3.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 (35) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/table/nodeviews/TableRow.js +53 -35
  3. package/dist/cjs/plugins/table/types.js +1 -0
  4. package/dist/cjs/plugins/table/ui/DragHandle/index.js +25 -13
  5. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +3 -2
  6. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  7. package/dist/cjs/plugins/table/ui/icons/DragHandleIcon.js +63 -0
  8. package/dist/es2019/plugins/table/nodeviews/TableRow.js +22 -7
  9. package/dist/es2019/plugins/table/types.js +1 -0
  10. package/dist/es2019/plugins/table/ui/DragHandle/index.js +24 -13
  11. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +3 -2
  12. package/dist/es2019/plugins/table/ui/common-styles.js +9 -0
  13. package/dist/es2019/plugins/table/ui/icons/DragHandleIcon.js +54 -0
  14. package/dist/esm/plugins/table/nodeviews/TableRow.js +53 -35
  15. package/dist/esm/plugins/table/types.js +1 -0
  16. package/dist/esm/plugins/table/ui/DragHandle/index.js +25 -13
  17. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +3 -2
  18. package/dist/esm/plugins/table/ui/common-styles.js +1 -1
  19. package/dist/esm/plugins/table/ui/icons/DragHandleIcon.js +55 -0
  20. package/dist/types/plugins/table/nodeviews/TableRow.d.ts +1 -0
  21. package/dist/types/plugins/table/types.d.ts +1 -0
  22. package/dist/types/plugins/table/ui/DragHandle/index.d.ts +3 -1
  23. package/dist/types/plugins/table/ui/icons/DragHandleIcon.d.ts +7 -0
  24. package/dist/types-ts4.5/plugins/table/nodeviews/TableRow.d.ts +1 -0
  25. package/dist/types-ts4.5/plugins/table/types.d.ts +1 -0
  26. package/dist/types-ts4.5/plugins/table/ui/DragHandle/index.d.ts +3 -1
  27. package/dist/types-ts4.5/plugins/table/ui/icons/DragHandleIcon.d.ts +7 -0
  28. package/package.json +1 -2
  29. package/src/plugins/table/nodeviews/TableRow.ts +12 -6
  30. package/src/plugins/table/types.ts +1 -1
  31. package/src/plugins/table/ui/DragHandle/index.tsx +31 -12
  32. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +4 -1
  33. package/src/plugins/table/ui/common-styles.ts +9 -0
  34. package/src/plugins/table/ui/icons/DragHandleIcon.tsx +74 -0
  35. package/tsconfig.app.json +0 -3
@@ -279,6 +279,7 @@ export declare const TableCssClassName: {
279
279
  /** Controls with drag handle */
280
280
  COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: string;
281
281
  ROW_CONTROLS_WITH_DRAG: string;
282
+ DRAG_HANDLE_BUTTON_CONTAINER: string;
282
283
  /** Other classes */
283
284
  NUMBERED_COLUMN: string;
284
285
  NUMBERED_COLUMN_BUTTON: string;
@@ -1,11 +1,13 @@
1
1
  import type { MouseEventHandler } from 'react';
2
+ type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
2
3
  type DragHandleProps = {
3
4
  tableLocalId: string;
4
5
  indexes: number[];
5
6
  direction?: 'column' | 'row';
7
+ state?: DragHandleState;
6
8
  onClick?: MouseEventHandler;
7
9
  onMouseOver?: MouseEventHandler;
8
10
  onMouseOut?: MouseEventHandler;
9
11
  };
10
- export declare const DragHandle: ({ tableLocalId, direction, indexes, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
12
+ export declare const DragHandle: ({ tableLocalId, direction, state, indexes, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
11
13
  export {};
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ interface DragHandleIconProps {
3
+ backgroundColor?: string;
4
+ foregroundColor?: string;
5
+ }
6
+ export declare const DragHandleIcon: ({ backgroundColor, foregroundColor, }: DragHandleIconProps) => JSX.Element;
7
+ export {};
@@ -37,6 +37,7 @@ export default class TableRow extends TableNodeView<HTMLTableRowElement> impleme
37
37
  * Methods
38
38
  */
39
39
  private addDropTarget;
40
+ private getCurrentData;
40
41
  private headerRowMouseScrollEnd;
41
42
  private headerRowMouseScroll;
42
43
  private subscribe;
@@ -279,6 +279,7 @@ export declare const TableCssClassName: {
279
279
  /** Controls with drag handle */
280
280
  COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: string;
281
281
  ROW_CONTROLS_WITH_DRAG: string;
282
+ DRAG_HANDLE_BUTTON_CONTAINER: string;
282
283
  /** Other classes */
283
284
  NUMBERED_COLUMN: string;
284
285
  NUMBERED_COLUMN_BUTTON: string;
@@ -1,11 +1,13 @@
1
1
  import type { MouseEventHandler } from 'react';
2
+ type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
2
3
  type DragHandleProps = {
3
4
  tableLocalId: string;
4
5
  indexes: number[];
5
6
  direction?: 'column' | 'row';
7
+ state?: DragHandleState;
6
8
  onClick?: MouseEventHandler;
7
9
  onMouseOver?: MouseEventHandler;
8
10
  onMouseOut?: MouseEventHandler;
9
11
  };
10
- export declare const DragHandle: ({ tableLocalId, direction, indexes, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
12
+ export declare const DragHandle: ({ tableLocalId, direction, state, indexes, onClick, onMouseOver, onMouseOut, }: DragHandleProps) => JSX.Element;
11
13
  export {};
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ interface DragHandleIconProps {
3
+ backgroundColor?: string;
4
+ foregroundColor?: string;
5
+ }
6
+ export declare const DragHandleIcon: ({ backgroundColor, foregroundColor, }: DragHandleIconProps) => JSX.Element;
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "5.3.4",
3
+ "version": "5.3.6",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -40,7 +40,6 @@
40
40
  "@atlaskit/platform-feature-flags": "^0.2.1",
41
41
  "@atlaskit/pragmatic-drag-and-drop": "^0.23.0",
42
42
  "@atlaskit/pragmatic-drag-and-drop-hitbox": "^0.11.8",
43
- "@atlaskit/pragmatic-drag-and-drop-react-accessibility": "^0.4.0",
44
43
  "@atlaskit/primitives": "^1.6.7",
45
44
  "@atlaskit/theme": "^12.6.0",
46
45
  "@atlaskit/tokens": "^1.28.0",
@@ -192,14 +192,11 @@ export default class TableRow
192
192
  this.dropTargetCleanup();
193
193
  }
194
194
 
195
- const resolvedPos = this.view.state.doc.resolve(pos);
196
- const targetIndex = resolvedPos.index();
197
- const localId = resolvedPos.parent.attrs.localId;
198
-
199
195
  this.dropTargetCleanup = dropTargetForElements({
200
196
  element: element,
201
- canDrop({ source }) {
197
+ canDrop: ({ source }) => {
202
198
  const data = source.data as DraggableSourceData;
199
+ const { localId, targetIndex } = this.getCurrentData();
203
200
  return (
204
201
  // Only draggables of row type can be dropped on this target
205
202
  data.type === 'table-row' &&
@@ -210,7 +207,9 @@ export default class TableRow
210
207
  data.indexes?.indexOf(targetIndex) === -1
211
208
  );
212
209
  },
213
- getData({ input, element }) {
210
+ getIsSticky: () => true,
211
+ getData: ({ input, element }) => {
212
+ const { localId, targetIndex } = this.getCurrentData();
214
213
  const data = {
215
214
  localId,
216
215
  type: 'table-row',
@@ -225,6 +224,13 @@ export default class TableRow
225
224
  });
226
225
  }
227
226
 
227
+ private getCurrentData() {
228
+ const resolvedPos = this.view.state.doc.resolve(this.getPos()!);
229
+ const targetIndex = resolvedPos.index();
230
+ const localId = resolvedPos.parent.attrs.localId;
231
+ return { targetIndex, localId };
232
+ }
233
+
228
234
  private headerRowMouseScrollEnd = debounce(() => {
229
235
  this.dom.classList.remove('no-pointer-events');
230
236
  }, HEADER_ROW_SCROLL_RESET_DEBOUNCE_TIMEOUT);
@@ -300,8 +300,8 @@ export const TableCssClassName = {
300
300
 
301
301
  /** Controls with drag handle */
302
302
  COLUMN_CONTROLS_DECORATIONS_WITH_DRAG: `${tablePrefixSelector}-column-controls-decoration-with-drag`,
303
-
304
303
  ROW_CONTROLS_WITH_DRAG: `${tablePrefixSelector}-row-controls-with-drag`,
304
+ DRAG_HANDLE_BUTTON_CONTAINER: `${tablePrefixSelector}-drag-handle-button-container`,
305
305
 
306
306
  /** Other classes */
307
307
  NUMBERED_COLUMN: `${tablePrefixSelector}-numbered-column`,
@@ -1,30 +1,50 @@
1
1
  import type { MouseEventHandler } from 'react';
2
2
  import React, { useEffect, useRef } from 'react';
3
3
 
4
- import { DragHandleButton } from '@atlaskit/pragmatic-drag-and-drop-react-accessibility/drag-handle-button';
5
4
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element';
5
+ import { N200, N700 } from '@atlaskit/theme/colors';
6
6
  import { token } from '@atlaskit/tokens';
7
7
 
8
+ import { TableCssClassName as ClassName } from '../../types';
9
+ import { DragHandleIcon } from '../icons/DragHandleIcon';
10
+
11
+ type DragHandleState = 'default' | 'selected' | 'disabled' | 'danger';
12
+
8
13
  type DragHandleProps = {
9
14
  tableLocalId: string;
10
15
  indexes: number[];
11
16
  direction?: 'column' | 'row';
17
+ state?: DragHandleState;
12
18
  onClick?: MouseEventHandler;
13
19
  onMouseOver?: MouseEventHandler;
14
20
  onMouseOut?: MouseEventHandler;
15
21
  };
16
22
 
17
- // TODO: use for now, in future replace with custom @atlaskit/icon/glyph/drag-handler
18
- // width is too large (24px), should be 16px
23
+ const mapStateToProps = (state: DragHandleState) => {
24
+ switch (state) {
25
+ case 'danger':
26
+ case 'disabled':
27
+ case 'selected':
28
+ case 'default':
29
+ default:
30
+ return {
31
+ backgroundColor: token('color.background.accent.gray.subtlest', N200),
32
+ foregroundColor: token('color.icon.subtle', N700),
33
+ };
34
+ }
35
+ };
36
+
19
37
  export const DragHandle = ({
20
38
  tableLocalId,
21
39
  direction = 'row',
40
+ state = 'default',
22
41
  indexes,
23
42
  onClick,
24
43
  onMouseOver,
25
44
  onMouseOut,
26
45
  }: DragHandleProps) => {
27
- const dragHandleDivRef = useRef<HTMLDivElement>(null);
46
+ const dragHandleDivRef = useRef<HTMLButtonElement>(null);
47
+ const iconProps = mapStateToProps(state);
28
48
 
29
49
  useEffect(() => {
30
50
  const dragHandleDivRefCurrent = dragHandleDivRef.current;
@@ -41,17 +61,16 @@ export const DragHandle = ({
41
61
  });
42
62
  }
43
63
  }, [tableLocalId, direction, indexes]);
64
+
44
65
  return (
45
- <div
46
- ref={dragHandleDivRef}
66
+ <button
67
+ className={ClassName.DRAG_HANDLE_BUTTON_CONTAINER}
47
68
  style={{
48
- backgroundColor: `${token('elevation.surface', 'white')}`,
49
- borderRadius: '4px',
50
- border: `2px solid ${token('elevation.surface', 'white')}`,
51
- transform: direction === 'column' ? 'rotate(90deg)' : 'none',
69
+ transform: direction === 'column' ? 'none' : 'rotate(90deg)',
52
70
  }}
71
+ ref={dragHandleDivRef}
53
72
  >
54
- <DragHandleButton label="blah" />
55
- </div>
73
+ <DragHandleIcon {...iconProps} />
74
+ </button>
56
75
  );
57
76
  };
@@ -29,7 +29,9 @@ const DragControlsComponent = ({
29
29
  editorView,
30
30
  }: DragControlsProps & WrappedComponentProps) => {
31
31
  const rowHeights = getRowHeights(tableRef);
32
- const heights = rowHeights.map((height) => `${height - 1}px`).join(' ');
32
+ const heights = rowHeights
33
+ .map((height, index) => `${height - 1}px`)
34
+ .join(' ');
33
35
 
34
36
  const onClick = (
35
37
  index: number,
@@ -57,6 +59,7 @@ const DragControlsComponent = ({
57
59
  <div
58
60
  style={{
59
61
  gridRow: `${(rowIndex as number) + 1} / span 1`,
62
+ display: 'flex',
60
63
  }}
61
64
  >
62
65
  <DragHandle
@@ -702,6 +702,15 @@ export const tableStyles = (
702
702
  display: grid;
703
703
  align-items: center;
704
704
  position: absolute;
705
+ left: -4px;
706
+ }
707
+
708
+ .${ClassName.DRAG_HANDLE_BUTTON_CONTAINER} {
709
+ cursor: grab;
710
+ width: max-content;
711
+ padding: 0;
712
+ border: none;
713
+ background: none;
705
714
  }
706
715
 
707
716
  ${floatingColumnControls(props)}
@@ -0,0 +1,74 @@
1
+ /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
2
+ import React from 'react';
3
+
4
+ interface DragHandleIconProps {
5
+ backgroundColor?: string;
6
+ foregroundColor?: string;
7
+ }
8
+
9
+ export const DragHandleIcon = ({
10
+ backgroundColor,
11
+ foregroundColor,
12
+ }: DragHandleIconProps) => (
13
+ <svg
14
+ width="28"
15
+ height="20"
16
+ viewBox="0 0 28 20"
17
+ fill="none"
18
+ xmlns="http://www.w3.org/2000/svg"
19
+ >
20
+ <rect
21
+ x="1"
22
+ y="1"
23
+ width="26"
24
+ height="18"
25
+ rx="5"
26
+ fill={backgroundColor || '#F1F2F4'}
27
+ />
28
+ <g clipPath="url(#clip0_125_45007)">
29
+ <path
30
+ d="M11 12C11 11.4477 10.5523 11 10 11C9.44772 11 9 11.4477 9 12C9 12.5523 9.44772 13 10 13C10.5523 13 11 12.5523 11 12Z"
31
+ fill={foregroundColor || '#626F86'}
32
+ />
33
+ <path
34
+ d="M11 8C11 7.44772 10.5523 7 10 7C9.44772 7 9 7.44772 9 8C9 8.55228 9.44772 9 10 9C10.5523 9 11 8.55228 11 8Z"
35
+ fill={foregroundColor || '#626F86'}
36
+ />
37
+ <path
38
+ d="M19 12C19 11.4477 18.5523 11 18 11C17.4477 11 17 11.4477 17 12C17 12.5523 17.4477 13 18 13C18.5523 13 19 12.5523 19 12Z"
39
+ fill={foregroundColor || '#626F86'}
40
+ />
41
+ <path
42
+ d="M19 8C19 7.44772 18.5523 7 18 7C17.4477 7 17 7.44772 17 8C17 8.55228 17.4477 9 18 9C18.5523 9 19 8.55228 19 8Z"
43
+ fill={foregroundColor || '#626F86'}
44
+ />
45
+ <path
46
+ d="M15 12C15 11.4477 14.5523 11 14 11C13.4477 11 13 11.4477 13 12C13 12.5523 13.4477 13 14 13C14.5523 13 15 12.5523 15 12Z"
47
+ fill={foregroundColor || '#626F86'}
48
+ />
49
+ <path
50
+ d="M15 8C15 7.44772 14.5523 7 14 7C13.4477 7 13 7.44772 13 8C13 8.55228 13.4477 9 14 9C14.5523 9 15 8.55228 15 8Z"
51
+ fill={foregroundColor || '#626F86'}
52
+ />
53
+ </g>
54
+ <rect
55
+ x="1"
56
+ y="1"
57
+ width="26"
58
+ height="18"
59
+ rx="5"
60
+ stroke="white"
61
+ strokeWidth="2"
62
+ />
63
+ <defs>
64
+ <clipPath id="clip0_125_45007">
65
+ <rect
66
+ width="16"
67
+ height="24"
68
+ fill="white"
69
+ transform="matrix(0 -1 1 0 2 18)"
70
+ />
71
+ </clipPath>
72
+ </defs>
73
+ </svg>
74
+ );
package/tsconfig.app.json CHANGED
@@ -75,9 +75,6 @@
75
75
  {
76
76
  "path": "../../pragmatic-drag-and-drop/hitbox/tsconfig.app.json"
77
77
  },
78
- {
79
- "path": "../../pragmatic-drag-and-drop/react-accessibility/tsconfig.app.json"
80
- },
81
78
  {
82
79
  "path": "../../design-system/primitives/tsconfig.app.json"
83
80
  },