@atlaskit/editor-plugin-table 5.3.14 → 5.3.16

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 (144) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/plugins/table/event-handlers.js +4 -3
  3. package/dist/cjs/plugins/table/index.js +2 -1
  4. package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +1 -0
  5. package/dist/cjs/plugins/table/types.js +5 -3
  6. package/dist/cjs/plugins/table/ui/FloatingDragMenu/DragMenu.js +49 -11
  7. package/dist/cjs/plugins/table/ui/FloatingDragMenu/index.js +5 -2
  8. package/dist/cjs/plugins/table/ui/FloatingInsertButton/index.js +5 -0
  9. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +3 -11
  10. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +2 -2
  11. package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +1 -1
  12. package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/ClassicCornerControls.js +114 -0
  13. package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.js +60 -0
  14. package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/index.js +11 -112
  15. package/dist/cjs/plugins/table/ui/TableFloatingControls/CornerControls/types.js +5 -0
  16. package/dist/cjs/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +1 -7
  17. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +7 -2
  18. package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
  19. package/dist/cjs/plugins/table/ui/icons/AddColLeftIcon.js +44 -0
  20. package/dist/cjs/plugins/table/ui/icons/AddColRightIcon.js +44 -0
  21. package/dist/cjs/plugins/table/ui/icons/AddRowAboveIcon.js +45 -0
  22. package/dist/cjs/plugins/table/ui/icons/AddRowBelowIcon.js +40 -0
  23. package/dist/cjs/plugins/table/ui/icons/index.js +29 -1
  24. package/dist/cjs/plugins/table/ui/messages.js +5 -0
  25. package/dist/cjs/plugins/table/ui/ui-styles.js +28 -25
  26. package/dist/cjs/plugins/table/utils/dom.js +16 -7
  27. package/dist/cjs/plugins/table/utils/drag-menu.js +122 -10
  28. package/dist/cjs/plugins/table/utils/index.js +12 -6
  29. package/dist/es2019/plugins/table/event-handlers.js +5 -4
  30. package/dist/es2019/plugins/table/index.js +2 -1
  31. package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +2 -1
  32. package/dist/es2019/plugins/table/types.js +5 -3
  33. package/dist/es2019/plugins/table/ui/FloatingDragMenu/DragMenu.js +52 -8
  34. package/dist/es2019/plugins/table/ui/FloatingDragMenu/index.js +5 -2
  35. package/dist/es2019/plugins/table/ui/FloatingInsertButton/index.js +5 -0
  36. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +3 -11
  37. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +2 -2
  38. package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +1 -1
  39. package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/ClassicCornerControls.js +93 -0
  40. package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.js +61 -0
  41. package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/index.js +2 -99
  42. package/dist/es2019/plugins/table/ui/TableFloatingControls/CornerControls/types.js +1 -0
  43. package/dist/es2019/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +1 -7
  44. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +8 -3
  45. package/dist/es2019/plugins/table/ui/common-styles.js +8 -6
  46. package/dist/es2019/plugins/table/ui/icons/AddColLeftIcon.js +35 -0
  47. package/dist/es2019/plugins/table/ui/icons/AddColRightIcon.js +35 -0
  48. package/dist/es2019/plugins/table/ui/icons/AddRowAboveIcon.js +36 -0
  49. package/dist/es2019/plugins/table/ui/icons/AddRowBelowIcon.js +31 -0
  50. package/dist/es2019/plugins/table/ui/icons/index.js +5 -1
  51. package/dist/es2019/plugins/table/ui/messages.js +5 -0
  52. package/dist/es2019/plugins/table/ui/ui-styles.js +44 -3
  53. package/dist/es2019/plugins/table/utils/dom.js +13 -6
  54. package/dist/es2019/plugins/table/utils/drag-menu.js +118 -8
  55. package/dist/es2019/plugins/table/utils/index.js +1 -1
  56. package/dist/esm/plugins/table/event-handlers.js +5 -4
  57. package/dist/esm/plugins/table/index.js +2 -1
  58. package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +2 -1
  59. package/dist/esm/plugins/table/types.js +5 -3
  60. package/dist/esm/plugins/table/ui/FloatingDragMenu/DragMenu.js +46 -8
  61. package/dist/esm/plugins/table/ui/FloatingDragMenu/index.js +5 -2
  62. package/dist/esm/plugins/table/ui/FloatingInsertButton/index.js +5 -0
  63. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.js +3 -11
  64. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +2 -2
  65. package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +1 -1
  66. package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/ClassicCornerControls.js +104 -0
  67. package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.js +50 -0
  68. package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/index.js +2 -110
  69. package/dist/esm/plugins/table/ui/TableFloatingControls/CornerControls/types.js +1 -0
  70. package/dist/esm/plugins/table/ui/TableFloatingControls/RowControls/DragControls.js +1 -7
  71. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +8 -3
  72. package/dist/esm/plugins/table/ui/common-styles.js +2 -2
  73. package/dist/esm/plugins/table/ui/icons/AddColLeftIcon.js +37 -0
  74. package/dist/esm/plugins/table/ui/icons/AddColRightIcon.js +37 -0
  75. package/dist/esm/plugins/table/ui/icons/AddRowAboveIcon.js +38 -0
  76. package/dist/esm/plugins/table/ui/icons/AddRowBelowIcon.js +33 -0
  77. package/dist/esm/plugins/table/ui/icons/index.js +5 -1
  78. package/dist/esm/plugins/table/ui/messages.js +5 -0
  79. package/dist/esm/plugins/table/ui/ui-styles.js +27 -24
  80. package/dist/esm/plugins/table/utils/dom.js +15 -6
  81. package/dist/esm/plugins/table/utils/drag-menu.js +120 -8
  82. package/dist/esm/plugins/table/utils/index.js +1 -1
  83. package/dist/types/plugins/table/types.d.ts +5 -3
  84. package/dist/types/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
  85. package/dist/types/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  86. package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/ClassicCornerControls.d.ts +6 -0
  87. package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +6 -0
  88. package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +2 -16
  89. package/dist/types/plugins/table/ui/TableFloatingControls/CornerControls/types.d.ts +11 -0
  90. package/dist/types/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
  91. package/dist/types/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
  92. package/dist/types/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
  93. package/dist/types/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
  94. package/dist/types/plugins/table/ui/icons/index.d.ts +4 -0
  95. package/dist/types/plugins/table/ui/messages.d.ts +5 -0
  96. package/dist/types/plugins/table/ui/ui-styles.d.ts +1 -0
  97. package/dist/types/plugins/table/utils/dom.d.ts +3 -2
  98. package/dist/types/plugins/table/utils/drag-menu.d.ts +6 -3
  99. package/dist/types/plugins/table/utils/index.d.ts +1 -1
  100. package/dist/types-ts4.5/plugins/table/types.d.ts +5 -3
  101. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/DragMenu.d.ts +5 -2
  102. package/dist/types-ts4.5/plugins/table/ui/FloatingDragMenu/index.d.ts +3 -1
  103. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/CornerControls/ClassicCornerControls.d.ts +6 -0
  104. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +6 -0
  105. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/CornerControls/index.d.ts +2 -16
  106. package/dist/types-ts4.5/plugins/table/ui/TableFloatingControls/CornerControls/types.d.ts +11 -0
  107. package/dist/types-ts4.5/plugins/table/ui/icons/AddColLeftIcon.d.ts +2 -0
  108. package/dist/types-ts4.5/plugins/table/ui/icons/AddColRightIcon.d.ts +2 -0
  109. package/dist/types-ts4.5/plugins/table/ui/icons/AddRowAboveIcon.d.ts +2 -0
  110. package/dist/types-ts4.5/plugins/table/ui/icons/AddRowBelowIcon.d.ts +2 -0
  111. package/dist/types-ts4.5/plugins/table/ui/icons/index.d.ts +4 -0
  112. package/dist/types-ts4.5/plugins/table/ui/messages.d.ts +5 -0
  113. package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +1 -0
  114. package/dist/types-ts4.5/plugins/table/utils/dom.d.ts +3 -2
  115. package/dist/types-ts4.5/plugins/table/utils/drag-menu.d.ts +6 -3
  116. package/dist/types-ts4.5/plugins/table/utils/index.d.ts +1 -1
  117. package/package.json +2 -2
  118. package/src/plugins/table/event-handlers.ts +7 -2
  119. package/src/plugins/table/index.tsx +1 -0
  120. package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +7 -1
  121. package/src/plugins/table/types.ts +7 -4
  122. package/src/plugins/table/ui/FloatingDragMenu/DragMenu.tsx +73 -6
  123. package/src/plugins/table/ui/FloatingDragMenu/index.tsx +5 -0
  124. package/src/plugins/table/ui/FloatingInsertButton/index.tsx +8 -0
  125. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnControls/index.tsx +5 -7
  126. package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +2 -2
  127. package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +1 -1
  128. package/src/plugins/table/ui/TableFloatingControls/CornerControls/ClassicCornerControls.tsx +107 -0
  129. package/src/plugins/table/ui/TableFloatingControls/CornerControls/DragCornerControls.tsx +66 -0
  130. package/src/plugins/table/ui/TableFloatingControls/CornerControls/index.tsx +2 -125
  131. package/src/plugins/table/ui/TableFloatingControls/CornerControls/types.ts +12 -0
  132. package/src/plugins/table/ui/TableFloatingControls/RowControls/DragControls.tsx +3 -3
  133. package/src/plugins/table/ui/TableFloatingControls/index.tsx +22 -14
  134. package/src/plugins/table/ui/common-styles.ts +8 -5
  135. package/src/plugins/table/ui/icons/AddColLeftIcon.tsx +43 -0
  136. package/src/plugins/table/ui/icons/AddColRightIcon.tsx +43 -0
  137. package/src/plugins/table/ui/icons/AddRowAboveIcon.tsx +42 -0
  138. package/src/plugins/table/ui/icons/AddRowBelowIcon.tsx +36 -0
  139. package/src/plugins/table/ui/icons/index.ts +4 -0
  140. package/src/plugins/table/ui/messages.ts +6 -0
  141. package/src/plugins/table/ui/ui-styles.ts +45 -3
  142. package/src/plugins/table/utils/dom.ts +16 -4
  143. package/src/plugins/table/utils/drag-menu.ts +158 -5
  144. package/src/plugins/table/utils/index.ts +2 -1
@@ -1,7 +1,12 @@
1
- import React from 'react';
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
2
3
  import { ArrowKeyNavigationType, DropdownMenu } from '@atlaskit/editor-common/ui-menu';
4
+ import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
3
5
  import { TableMap } from '@atlaskit/editor-tables/table-map';
6
+ import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@atlaskit/editor-tables/utils';
7
+ import { clearHoverSelection, hoverColumns, hoverRows } from '../../commands';
4
8
  import { toggleDragMenu } from '../../pm-plugins/drag-and-drop/commands';
9
+ import { getSelectedColumnIndexes, getSelectedRowIndexes } from '../../utils';
5
10
  import { getDragMenuConfig } from '../../utils/drag-menu';
6
11
  import { dragMenuDropdownWidth } from '../consts';
7
12
  const convertToDropdownItems = dragMenuConfig => {
@@ -14,7 +19,18 @@ const convertToDropdownItems = dragMenuConfig => {
14
19
  value: {
15
20
  name: item.id
16
21
  },
17
- isDisabled: item.disabled
22
+ isDisabled: item.disabled,
23
+ elemBefore: item.icon ? jsx("div", {
24
+ style: {
25
+ marginRight: "var(--ds-space-negative-075, -6px)",
26
+ display: 'flex'
27
+ }
28
+ }, jsx(item.icon, {
29
+ label: item.title
30
+ })) : undefined,
31
+ elemAfter: item.keymap ? jsx("div", {
32
+ css: shortcutStyle
33
+ }, item.keymap) : undefined
18
34
  });
19
35
  item.onClick && (menuCallback[item.id] = item.onClick);
20
36
  });
@@ -31,10 +47,20 @@ export const DragMenu = ({
31
47
  tableNode,
32
48
  mountPoint,
33
49
  boundariesElement,
34
- scrollableElement
50
+ scrollableElement,
51
+ targetCellPosition,
52
+ getEditorContainerWidth
35
53
  }) => {
36
54
  const tableMap = tableNode ? TableMap.get(tableNode) : undefined;
37
- const dragMenuConfig = getDragMenuConfig(direction, tableMap, index);
55
+ const {
56
+ state,
57
+ dispatch
58
+ } = editorView;
59
+ const {
60
+ selection
61
+ } = state;
62
+ const selectionRect = isSelectionType(selection, 'cell') ? getSelectionRect(selection) : findCellRectClosestToPos(selection.$from);
63
+ const dragMenuConfig = getDragMenuConfig(direction, getEditorContainerWidth, tableMap, index, targetCellPosition, selectionRect);
38
64
  const {
39
65
  menuItems,
40
66
  menuCallback
@@ -46,17 +72,33 @@ export const DragMenu = ({
46
72
  } = editorView;
47
73
  toggleDragMenu(false)(state, dispatch);
48
74
  };
49
- const onMenuItemActivated = ({
75
+ const handleMenuItemActivated = ({
50
76
  item
51
77
  }) => {
52
78
  var _menuCallback$item$va;
53
- (_menuCallback$item$va = menuCallback[item.value.name]) === null || _menuCallback$item$va === void 0 ? void 0 : _menuCallback$item$va.call(menuCallback, editorView.state, editorView.dispatch);
79
+ (_menuCallback$item$va = menuCallback[item.value.name]) === null || _menuCallback$item$va === void 0 ? void 0 : _menuCallback$item$va.call(menuCallback, state, dispatch);
54
80
  closeMenu();
55
81
  };
82
+ const handleItemMouseEnter = ({
83
+ item
84
+ }) => {
85
+ var _item$value$name;
86
+ if (!selectionRect || !((_item$value$name = item.value.name) !== null && _item$value$name !== void 0 && _item$value$name.startsWith('delete'))) {
87
+ return;
88
+ }
89
+ (item.value.name === 'delete_column' ? hoverColumns(getSelectedColumnIndexes(selectionRect), true) : hoverRows(getSelectedRowIndexes(selectionRect), true))(state, dispatch);
90
+ };
91
+ const handleItemMouseLeave = ({
92
+ item
93
+ }) => {
94
+ if (['sort_column_asc', 'sort_column_desc', 'delete_column', 'delete_row'].indexOf(item.value.name) > -1) {
95
+ clearHoverSelection()(state, dispatch);
96
+ }
97
+ };
56
98
  if (!menuItems) {
57
99
  return null;
58
100
  }
59
- return /*#__PURE__*/React.createElement(DropdownMenu, {
101
+ return jsx(DropdownMenu, {
60
102
  mountTo: mountPoint
61
103
  //This needs be removed when the a11y is completely handled
62
104
  //Disabling key navigation now as it works only partially
@@ -70,7 +112,9 @@ export const DragMenu = ({
70
112
  }],
71
113
  isOpen: isOpen,
72
114
  onOpenChange: closeMenu,
73
- onItemActivated: onMenuItemActivated,
115
+ onItemActivated: handleMenuItemActivated,
116
+ onMouseEnter: handleItemMouseEnter,
117
+ onMouseLeave: handleItemMouseLeave,
74
118
  fitWidth: dragMenuDropdownWidth,
75
119
  boundariesElement: boundariesElement
76
120
  });
@@ -15,7 +15,8 @@ const FloatingDragMenu = ({
15
15
  tableNode,
16
16
  direction,
17
17
  index,
18
- targetCellPosition
18
+ targetCellPosition,
19
+ getEditorContainerWidth
19
20
  }) => {
20
21
  if (!isOpen || !targetCellPosition || editorView.state.doc.nodeSize <= targetCellPosition) {
21
22
  return null;
@@ -49,7 +50,9 @@ const FloatingDragMenu = ({
49
50
  boundariesElement: boundariesElement,
50
51
  tableNode: tableNode,
51
52
  direction: direction,
52
- index: index
53
+ index: index,
54
+ targetCellPosition: targetCellPosition,
55
+ getEditorContainerWidth: getEditorContainerWidth
53
56
  }));
54
57
  };
55
58
  FloatingDragMenu.displayName = 'FloatingDragMenu';
@@ -35,6 +35,11 @@ export class FloatingInsertButton extends React.Component {
35
35
  isDragAndDropEnabled,
36
36
  dispatchAnalyticsEvent
37
37
  } = this.props;
38
+
39
+ // TODO: temporarily disable insert button for first column and row https://atlassian.slack.com/archives/C05U8HRQM50/p1698363744682219?thread_ts=1698209039.104909&cid=C05U8HRQM50
40
+ if (isDragAndDropEnabled && (insertColumnButtonIndex === 0 || insertRowButtonIndex === 0)) {
41
+ return null;
42
+ }
38
43
  const type = typeof insertColumnButtonIndex !== 'undefined' ? 'column' : typeof insertRowButtonIndex !== 'undefined' ? 'row' : null;
39
44
  if (!tableNode || !tableRef || !type) {
40
45
  return null;
@@ -78,7 +78,7 @@ export const ColumnControls = ({
78
78
  return /*#__PURE__*/React.createElement("div", {
79
79
  className: ClassName.DRAG_COLUMN_CONTROLS
80
80
  }, /*#__PURE__*/React.createElement("div", {
81
- className: ClassName.COLUMN_CONTROLS_INNER,
81
+ className: ClassName.DRAG_COLUMN_CONTROLS_INNER,
82
82
  "data-testid": "table-floating-column-controls",
83
83
  style: {
84
84
  gridTemplateColumns: widths,
@@ -96,13 +96,7 @@ export const ColumnControls = ({
96
96
  className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER,
97
97
  contentEditable: false,
98
98
  key: index
99
- }, !hasHeaderColumn && index === 0 && /*#__PURE__*/React.createElement("div", {
100
- style: {
101
- left: '0px',
102
- right: 'unset'
103
- },
104
- className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT
105
- }), /*#__PURE__*/React.createElement("div", {
99
+ }, /*#__PURE__*/React.createElement("div", {
106
100
  className: ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT,
107
101
  style: columnParams.length - 1 === index ? {
108
102
  right: '0'
@@ -110,12 +104,10 @@ export const ColumnControls = ({
110
104
  }))), tableActive && !isResizing && !!hoveredCell && Number.isFinite(hoveredCell.colIndex) && /*#__PURE__*/React.createElement("div", {
111
105
  style: {
112
106
  gridColumn: gridColumnPosition,
113
- zIndex: 99,
114
107
  display: 'flex',
115
- width: '100%',
116
108
  justifyContent: 'center',
117
109
  alignItems: 'center',
118
- marginTop: "var(--ds-space-negative-025, -2px)"
110
+ zIndex: 99
119
111
  },
120
112
  "data-column-control-index": hoveredCell.colIndex,
121
113
  "data-testid": "table-floating-column-control"
@@ -17,10 +17,10 @@ export const ColumnDropTargets = ({
17
17
  const hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
18
18
  const marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
19
19
  return /*#__PURE__*/React.createElement("div", {
20
- className: ClassName.COLUMN_DROP_TARGET_CONTROLS,
20
+ className: ClassName.DRAG_COLUMN_DROP_TARGET_CONTROLS,
21
21
  contentEditable: false
22
22
  }, /*#__PURE__*/React.createElement("div", {
23
- className: ClassName.COLUMN_CONTROLS_INNER,
23
+ className: ClassName.DRAG_COLUMN_CONTROLS_INNER,
24
24
  "data-testid": "table-floating-column-controls-drop-targets"
25
25
  }, colWidths === null || colWidths === void 0 ? void 0 : colWidths.map((width, index) => {
26
26
  return /*#__PURE__*/React.createElement(ColumnDropTarget, {
@@ -81,7 +81,7 @@ export const TableFloatingColumnControls = ({
81
81
  return null;
82
82
  }
83
83
  return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement("div", {
84
- className: ClassName.COLUMN_CONTROLS_WRAPPER,
84
+ className: ClassName.DRAG_COLUMN_CONTROLS_WRAPPER,
85
85
  "data-testid": "table-floating-column-controls-wrapper"
86
86
  }, /*#__PURE__*/React.createElement(ColumnControls, {
87
87
  editorView: editorView,
@@ -0,0 +1,93 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React, { Component } from 'react';
3
+ import classnames from 'classnames';
4
+ import { injectIntl } from 'react-intl-next';
5
+ import { TableMap } from '@atlaskit/editor-tables/table-map';
6
+ import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
7
+ import { clearHoverSelection, hoverTable } from '../../../commands';
8
+ import { TableCssClassName as ClassName } from '../../../types';
9
+ import messages from '../../messages';
10
+ class CornerControlComponent extends Component {
11
+ constructor(...args) {
12
+ super(...args);
13
+ _defineProperty(this, "isActive", () => {
14
+ const {
15
+ editorView,
16
+ hoveredRows,
17
+ isResizing
18
+ } = this.props;
19
+ const {
20
+ selection
21
+ } = editorView.state;
22
+ const table = findTable(selection);
23
+ if (!table) {
24
+ return false;
25
+ }
26
+ return isTableSelected(selection) || hoveredRows && hoveredRows.length === TableMap.get(table.node).height && !isResizing;
27
+ });
28
+ _defineProperty(this, "clearHoverSelection", () => {
29
+ const {
30
+ state,
31
+ dispatch
32
+ } = this.props.editorView;
33
+ clearHoverSelection()(state, dispatch);
34
+ });
35
+ _defineProperty(this, "selectTable", () => {
36
+ const {
37
+ state,
38
+ dispatch
39
+ } = this.props.editorView;
40
+ dispatch(selectTable(state.tr).setMeta('addToHistory', false));
41
+ });
42
+ _defineProperty(this, "hoverTable", () => {
43
+ const {
44
+ state,
45
+ dispatch
46
+ } = this.props.editorView;
47
+ hoverTable()(state, dispatch);
48
+ });
49
+ }
50
+ render() {
51
+ const {
52
+ isInDanger,
53
+ tableRef,
54
+ isHeaderColumnEnabled,
55
+ isHeaderRowEnabled,
56
+ intl: {
57
+ formatMessage
58
+ }
59
+ } = this.props;
60
+ if (!tableRef) {
61
+ return null;
62
+ }
63
+ const isActive = this.isActive();
64
+ return /*#__PURE__*/React.createElement("div", {
65
+ className: classnames(ClassName.CORNER_CONTROLS, {
66
+ active: isActive,
67
+ sticky: this.props.stickyTop !== undefined
68
+ }),
69
+ style: {
70
+ top: this.props.stickyTop !== undefined ? `${this.props.stickyTop}px` : undefined
71
+ },
72
+ contentEditable: false
73
+ }, /*#__PURE__*/React.createElement("button", {
74
+ "aria-label": formatMessage(messages.cornerControl),
75
+ type: "button",
76
+ className: classnames(ClassName.CONTROLS_CORNER_BUTTON, {
77
+ danger: isActive && isInDanger
78
+ }),
79
+ onClick: this.selectTable,
80
+ onMouseOver: this.hoverTable,
81
+ onMouseOut: this.clearHoverSelection
82
+ }), !isHeaderRowEnabled && /*#__PURE__*/React.createElement("div", {
83
+ className: ClassName.CORNER_CONTROLS_INSERT_ROW_MARKER
84
+ }, /*#__PURE__*/React.createElement("div", {
85
+ className: ClassName.CONTROLS_INSERT_MARKER
86
+ })), !isHeaderColumnEnabled && /*#__PURE__*/React.createElement("div", {
87
+ className: ClassName.CORNER_CONTROLS_INSERT_COLUMN_MARKER
88
+ }, /*#__PURE__*/React.createElement("div", {
89
+ className: ClassName.CONTROLS_INSERT_MARKER
90
+ })));
91
+ }
92
+ }
93
+ export const CornerControls = injectIntl(CornerControlComponent);
@@ -0,0 +1,61 @@
1
+ import React, { useMemo } from 'react';
2
+ import classnames from 'classnames';
3
+ import { injectIntl } from 'react-intl-next';
4
+ import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
5
+ import { clearHoverSelection, hoverTable } from '../../../commands';
6
+ import { TableCssClassName as ClassName } from '../../../types';
7
+ import messages from '../../messages';
8
+ const DragCornerControlsComponent = ({
9
+ editorView,
10
+ isInDanger,
11
+ intl: {
12
+ formatMessage
13
+ }
14
+ }) => {
15
+ const handleOnClick = () => {
16
+ const {
17
+ state,
18
+ dispatch
19
+ } = editorView;
20
+ dispatch(selectTable(state.tr).setMeta('addToHistory', false));
21
+ };
22
+ const handleMouseOver = () => {
23
+ const {
24
+ state,
25
+ dispatch
26
+ } = editorView;
27
+ hoverTable()(state, dispatch);
28
+ };
29
+ const handleMouseOut = () => {
30
+ const {
31
+ state,
32
+ dispatch
33
+ } = editorView;
34
+ clearHoverSelection()(state, dispatch);
35
+ };
36
+ const isActive = useMemo(() => {
37
+ const {
38
+ selection
39
+ } = editorView.state;
40
+ const table = findTable(selection);
41
+ if (!table) {
42
+ return false;
43
+ }
44
+ return isTableSelected(selection);
45
+ }, [editorView.state]);
46
+ return /*#__PURE__*/React.createElement("button", {
47
+ className: classnames(ClassName.DRAG_CORNER_BUTTON, {
48
+ active: isActive,
49
+ danger: isActive && isInDanger
50
+ }),
51
+ "aria-label": formatMessage(messages.cornerControl),
52
+ type: "button",
53
+ onClick: handleOnClick,
54
+ onMouseOver: handleMouseOver,
55
+ onMouseOut: handleMouseOut,
56
+ contentEditable: false
57
+ }, /*#__PURE__*/React.createElement("div", {
58
+ className: ClassName.DRAG_CORNER_BUTTON_INNER
59
+ }));
60
+ };
61
+ export const DragCornerControls = injectIntl(DragCornerControlsComponent);
@@ -1,99 +1,2 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React, { Component } from 'react';
3
- import classnames from 'classnames';
4
- import { defineMessages, injectIntl } from 'react-intl-next';
5
- import { TableMap } from '@atlaskit/editor-tables/table-map';
6
- import { findTable, isTableSelected, selectTable } from '@atlaskit/editor-tables/utils';
7
- import { clearHoverSelection, hoverTable } from '../../../commands';
8
- import { TableCssClassName as ClassName } from '../../../types';
9
- const messages = defineMessages({
10
- cornerControl: {
11
- id: 'fabric.editor.cornerControl',
12
- defaultMessage: 'Highlight table',
13
- description: 'A button on the upper left corner of the table that shows up when the table is in focus. Clicking on it will select the entire table.'
14
- }
15
- });
16
- class CornerControlComponent extends Component {
17
- constructor(...args) {
18
- super(...args);
19
- _defineProperty(this, "isActive", () => {
20
- const {
21
- editorView,
22
- hoveredRows,
23
- isResizing
24
- } = this.props;
25
- const {
26
- selection
27
- } = editorView.state;
28
- const table = findTable(selection);
29
- if (!table) {
30
- return false;
31
- }
32
- return isTableSelected(selection) || hoveredRows && hoveredRows.length === TableMap.get(table.node).height && !isResizing;
33
- });
34
- _defineProperty(this, "clearHoverSelection", () => {
35
- const {
36
- state,
37
- dispatch
38
- } = this.props.editorView;
39
- clearHoverSelection()(state, dispatch);
40
- });
41
- _defineProperty(this, "selectTable", () => {
42
- const {
43
- state,
44
- dispatch
45
- } = this.props.editorView;
46
- dispatch(selectTable(state.tr).setMeta('addToHistory', false));
47
- });
48
- _defineProperty(this, "hoverTable", () => {
49
- const {
50
- state,
51
- dispatch
52
- } = this.props.editorView;
53
- hoverTable()(state, dispatch);
54
- });
55
- }
56
- render() {
57
- const {
58
- isInDanger,
59
- tableRef,
60
- isHeaderColumnEnabled,
61
- isHeaderRowEnabled,
62
- intl: {
63
- formatMessage
64
- }
65
- } = this.props;
66
- if (!tableRef) {
67
- return null;
68
- }
69
- const isActive = this.isActive();
70
- return /*#__PURE__*/React.createElement("div", {
71
- className: classnames(ClassName.CORNER_CONTROLS, {
72
- active: isActive,
73
- sticky: this.props.stickyTop !== undefined
74
- }),
75
- style: {
76
- top: this.props.stickyTop !== undefined ? `${this.props.stickyTop}px` : undefined
77
- },
78
- contentEditable: false
79
- }, /*#__PURE__*/React.createElement("button", {
80
- "aria-label": formatMessage(messages.cornerControl),
81
- type: "button",
82
- className: classnames(ClassName.CONTROLS_CORNER_BUTTON, {
83
- danger: isActive && isInDanger
84
- }),
85
- onClick: this.selectTable,
86
- onMouseOver: this.hoverTable,
87
- onMouseOut: this.clearHoverSelection
88
- }), !isHeaderRowEnabled && /*#__PURE__*/React.createElement("div", {
89
- className: ClassName.CORNER_CONTROLS_INSERT_ROW_MARKER
90
- }, /*#__PURE__*/React.createElement("div", {
91
- className: ClassName.CONTROLS_INSERT_MARKER
92
- })), !isHeaderColumnEnabled && /*#__PURE__*/React.createElement("div", {
93
- className: ClassName.CORNER_CONTROLS_INSERT_COLUMN_MARKER
94
- }, /*#__PURE__*/React.createElement("div", {
95
- className: ClassName.CONTROLS_INSERT_MARKER
96
- })));
97
- }
98
- }
99
- export const CornerControls = injectIntl(CornerControlComponent);
1
+ export { CornerControls } from './ClassicCornerControls';
2
+ export { DragCornerControls } from './DragCornerControls';
@@ -90,13 +90,7 @@ const DragControlsComponent = ({
90
90
  className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER,
91
91
  contentEditable: false,
92
92
  key: index
93
- }, !hasHeaderRow && index === 0 && /*#__PURE__*/React.createElement("div", {
94
- style: {
95
- top: '0px',
96
- left: "var(--ds-space-075, 6px)"
97
- },
98
- className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
99
- }), /*#__PURE__*/React.createElement("div", {
93
+ }, /*#__PURE__*/React.createElement("div", {
100
94
  className: ClassName.DRAG_ROW_FLOATING_INSERT_DOT
101
95
  }))), !isResizing && Number.isFinite(rowIndex) && /*#__PURE__*/React.createElement("div", {
102
96
  style: {
@@ -4,7 +4,7 @@ import { browser } from '@atlaskit/editor-common/utils';
4
4
  import { hoverCell, hoverRows, selectRow } from '../../commands';
5
5
  import { getPluginState } from '../../pm-plugins/plugin-factory';
6
6
  import { isSelectionUpdated } from '../../utils';
7
- import { CornerControls } from './CornerControls';
7
+ import { CornerControls, DragCornerControls } from './CornerControls';
8
8
  import NumberColumn from './NumberColumn';
9
9
  import { DragControls, RowControls } from './RowControls';
10
10
  export default class TableFloatingControls extends Component {
@@ -137,7 +137,12 @@ export default class TableFloatingControls extends Component {
137
137
  updateCellHoverLocation: this.updateCellHoverLocation,
138
138
  stickyTop: stickyTop,
139
139
  isDragAndDropEnabled: isDragAndDropEnabled
140
- }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(DragControls, {
140
+ }) : null, tableActive && /*#__PURE__*/React.createElement(React.Fragment, null, isDragAndDropEnabled ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DragCornerControls, {
141
+ editorView: editorView,
142
+ tableRef: tableRef,
143
+ isInDanger: isInDanger,
144
+ isResizing: isResizing
145
+ }), /*#__PURE__*/React.createElement(DragControls, {
141
146
  tableRef: tableRef,
142
147
  tableNode: tableNode,
143
148
  hoveredCell: hoveredCell,
@@ -149,7 +154,7 @@ export default class TableFloatingControls extends Component {
149
154
  hoverRows: this.hoverRows,
150
155
  selectRow: this.selectRow,
151
156
  updateCellHoverLocation: this.updateCellHoverLocation
152
- }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
157
+ })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CornerControls, {
153
158
  editorView: editorView,
154
159
  tableRef: tableRef,
155
160
  isInDanger: isInDanger,
@@ -7,7 +7,7 @@ import { B300, N0, N20A, N300, N40A, R500 } from '@atlaskit/theme/colors';
7
7
  import { fontSize } from '@atlaskit/theme/constants';
8
8
  import { TableCssClassName as ClassName } from '../types';
9
9
  import { columnControlsDecorationHeight, resizeHandlerAreaWidth, resizeLineWidth, rowControlsZIndex, stickyHeaderBorderBottomWidth, stickyRowOffsetTop, tableBorderColor, tableBorderDeleteColor, tableBorderRadiusSize, tableBorderSelectedColor, tableCellBackgroundColor, tableCellDeleteColor, tableCellSelectedColor, tableControlsSpacing, tableHeaderCellBackgroundColor, tableInsertColumnButtonSize, tableOverflowShadowWidth, tablePadding, tableScrollbarOffset, tableTextColor, tableToolbarDeleteColor, tableToolbarSelectedColor, tableToolbarSize } from './consts';
10
- import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, dragInsertButtonWrapper, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle, rowControlsWrapperDotStyle } from './ui-styles';
10
+ import { columnControlsDecoration, columnControlsLineMarker, DeleteButton, dragCornerControlButton, dragInsertButtonWrapper, floatingColumnControls, HeaderButton, HeaderButtonDanger, HeaderButtonHover, hoveredCell, hoveredDeleteButton, hoveredWarningCell, insertColumnButtonWrapper, insertLine, InsertMarker, insertRowButtonWrapper, OverflowShadow, resizeHandle, rowControlsWrapperDotStyle } from './ui-styles';
11
11
  const cornerControlHeight = tableToolbarSize + 1;
12
12
 
13
13
  /*
@@ -272,6 +272,8 @@ export const tableStyles = props => {
272
272
 
273
273
  ${dragInsertButtonWrapper(props)}
274
274
 
275
+ ${dragCornerControlButton(props)}
276
+
275
277
  /* Delete button */
276
278
  ${DeleteButton(props)}
277
279
  /* Ends Delete button */
@@ -455,7 +457,7 @@ export const tableStyles = props => {
455
457
  }
456
458
  }
457
459
 
458
- .${ClassName.COLUMN_CONTROLS_WRAPPER} {
460
+ .${ClassName.DRAG_COLUMN_CONTROLS_WRAPPER} {
459
461
  padding: 0 ${tablePadding}px;
460
462
  }
461
463
 
@@ -630,11 +632,11 @@ export const tableStyles = props => {
630
632
  }
631
633
 
632
634
  .${ClassName.DRAG_COLUMN_CONTROLS} {
633
- .${ClassName.COLUMN_CONTROLS_INNER} {
635
+ .${ClassName.DRAG_COLUMN_CONTROLS_INNER} {
634
636
  height: 24px;
635
637
  position: absolute;
636
638
  top: ${"var(--ds-space-negative-150, -12px)"};
637
- z-index: ${akEditorUnitZIndex};
639
+ z-index: ${akEditorUnitZIndex * 13};
638
640
  }
639
641
 
640
642
  .${ClassName.DRAG_COLUMN_FLOATING_INSERT_DOT_WRAPPER} {
@@ -917,9 +919,9 @@ export const tableStyles = props => {
917
919
  z-index: ${akEditorUnitZIndex};
918
920
  }
919
921
 
920
- .${ClassName.COLUMN_CONTROLS_WRAPPER} {
922
+ .${ClassName.DRAG_COLUMN_CONTROLS_WRAPPER} {
921
923
  position: absolute;
922
- top: ${tableMarginTop + 1}px;
924
+ top: ${tableMarginTop}px;
923
925
  }
924
926
 
925
927
  ${tableWrapperStyles()}
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ export const AddColLeftIcon = () => /*#__PURE__*/React.createElement("svg", {
3
+ width: "24",
4
+ height: "24",
5
+ viewBox: "0 0 24 24",
6
+ fill: "currentColor",
7
+ xmlns: "http://www.w3.org/2000/svg"
8
+ }, /*#__PURE__*/React.createElement("rect", {
9
+ width: "24",
10
+ height: "24",
11
+ transform: "matrix(0 -1 1 0 0 24)",
12
+ fill: "none",
13
+ fillOpacity: "0.01"
14
+ }), /*#__PURE__*/React.createElement("rect", {
15
+ x: "12",
16
+ y: "18",
17
+ width: "12",
18
+ height: "3",
19
+ rx: "0.5",
20
+ transform: "rotate(-90 12 18)",
21
+ fill: "currentColor"
22
+ }), /*#__PURE__*/React.createElement("rect", {
23
+ x: "16",
24
+ y: "18",
25
+ width: "12",
26
+ height: "3",
27
+ rx: "0.5",
28
+ transform: "rotate(-90 16 18)",
29
+ fill: "currentColor"
30
+ }), /*#__PURE__*/React.createElement("path", {
31
+ fillRule: "evenodd",
32
+ clipRule: "evenodd",
33
+ d: "M7 11H5.99C5.72652 11.0026 5.47473 11.1092 5.28935 11.2964C5.10397 11.4837 4.99999 11.7365 5 12C5 12.556 5.444 13 5.99 13H7V14C7 14.2652 7.10536 14.5196 7.29289 14.7071C7.48043 14.8946 7.73478 15 8 15C8.26522 15 8.51957 14.8946 8.70711 14.7071C8.89464 14.5196 9 14.2652 9 14V13H10.01C10.2735 12.9974 10.5253 12.8908 10.7107 12.7036C10.896 12.5163 11 12.2635 11 12C11 11.444 10.556 11 10.01 11H9V10C9 9.73478 8.89464 9.48043 8.70711 9.29289C8.51957 9.10536 8.26522 9 8 9C7.73478 9 7.48043 9.10536 7.29289 9.29289C7.10536 9.48043 7 9.73478 7 10V11Z",
34
+ fill: "currentColor"
35
+ }));
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ export const AddColRightIcon = () => /*#__PURE__*/React.createElement("svg", {
3
+ width: "24",
4
+ height: "24",
5
+ viewBox: "0 0 24 24",
6
+ fill: "none",
7
+ xmlns: "http://www.w3.org/2000/svg"
8
+ }, /*#__PURE__*/React.createElement("rect", {
9
+ width: "24",
10
+ height: "24",
11
+ transform: "translate(0 24) rotate(-90)",
12
+ fill: "none",
13
+ fillOpacity: "0.01"
14
+ }), /*#__PURE__*/React.createElement("rect", {
15
+ x: "9",
16
+ y: "18",
17
+ width: "12",
18
+ height: "3",
19
+ rx: "0.5",
20
+ transform: "rotate(-90 9 18)",
21
+ fill: "currentColor"
22
+ }), /*#__PURE__*/React.createElement("rect", {
23
+ x: "5",
24
+ y: "18",
25
+ width: "12",
26
+ height: "3",
27
+ rx: "0.5",
28
+ transform: "rotate(-90 5 18)",
29
+ fill: "currentColor"
30
+ }), /*#__PURE__*/React.createElement("path", {
31
+ fillRule: "evenodd",
32
+ clipRule: "evenodd",
33
+ d: "M15 11L13.99 11C13.7265 11.0026 13.4747 11.1092 13.2893 11.2964C13.104 11.4837 13 11.7365 13 12C13 12.556 13.444 13 13.99 13L15 13L15 14C15 14.2652 15.1054 14.5196 15.2929 14.7071C15.4804 14.8946 15.7348 15 16 15C16.2652 15 16.5196 14.8946 16.7071 14.7071C16.8946 14.5196 17 14.2652 17 14L17 13L18.01 13C18.2735 12.9974 18.5253 12.8908 18.7107 12.7036C18.896 12.5163 19 12.2635 19 12C19 11.444 18.556 11 18.01 11L17 11L17 10C17 9.73478 16.8946 9.48043 16.7071 9.29289C16.5196 9.10536 16.2652 9 16 9C15.7348 9 15.4804 9.10536 15.2929 9.29289C15.1054 9.48043 15 9.73478 15 10L15 11Z",
34
+ fill: "currentColor"
35
+ }));