@atlaskit/editor-plugin-table 5.4.7 → 5.4.8

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 (50) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/plugins/table/commands/misc.js +14 -12
  3. package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -4
  4. package/dist/cjs/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  5. package/dist/cjs/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  6. package/dist/cjs/plugins/table/types.js +2 -1
  7. package/dist/cjs/plugins/table/ui/TableFloatingControls/index.js +4 -1
  8. package/dist/cjs/plugins/table/ui/common-styles.js +6 -9
  9. package/dist/cjs/plugins/table/ui/ui-styles.js +12 -16
  10. package/dist/cjs/plugins/table/utils/decoration.js +20 -25
  11. package/dist/es2019/plugins/table/commands/misc.js +5 -4
  12. package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -4
  13. package/dist/es2019/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  14. package/dist/es2019/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  15. package/dist/es2019/plugins/table/types.js +2 -1
  16. package/dist/es2019/plugins/table/ui/TableFloatingControls/index.js +4 -1
  17. package/dist/es2019/plugins/table/ui/common-styles.js +20 -20
  18. package/dist/es2019/plugins/table/ui/ui-styles.js +18 -21
  19. package/dist/es2019/plugins/table/utils/decoration.js +20 -25
  20. package/dist/esm/plugins/table/commands/misc.js +13 -13
  21. package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -4
  22. package/dist/esm/plugins/table/pm-plugins/decorations/plugin.js +9 -3
  23. package/dist/esm/plugins/table/pm-plugins/decorations/utils/column-controls.js +8 -3
  24. package/dist/esm/plugins/table/types.js +2 -1
  25. package/dist/esm/plugins/table/ui/TableFloatingControls/index.js +4 -1
  26. package/dist/esm/plugins/table/ui/common-styles.js +6 -9
  27. package/dist/esm/plugins/table/ui/ui-styles.js +12 -16
  28. package/dist/esm/plugins/table/utils/decoration.js +20 -25
  29. package/dist/types/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
  30. package/dist/types/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
  31. package/dist/types/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
  32. package/dist/types/plugins/table/types.d.ts +2 -1
  33. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/column-controls.d.ts +3 -2
  34. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/compose-decorations.d.ts +1 -1
  35. package/dist/types-ts4.5/plugins/table/pm-plugins/decorations/utils/types.d.ts +10 -4
  36. package/dist/types-ts4.5/plugins/table/types.d.ts +2 -1
  37. package/package.json +1 -1
  38. package/src/__tests__/unit/event-handlers.ts +37 -38
  39. package/src/__tests__/unit/pm-plugins/decorations/column-controls.ts +46 -36
  40. package/src/plugins/table/commands/misc.ts +9 -7
  41. package/src/plugins/table/nodeviews/TableComponent.tsx +20 -22
  42. package/src/plugins/table/pm-plugins/decorations/plugin.ts +7 -2
  43. package/src/plugins/table/pm-plugins/decorations/utils/column-controls.ts +20 -11
  44. package/src/plugins/table/pm-plugins/decorations/utils/compose-decorations.ts +2 -4
  45. package/src/plugins/table/pm-plugins/decorations/utils/types.ts +14 -7
  46. package/src/plugins/table/types.ts +2 -1
  47. package/src/plugins/table/ui/TableFloatingControls/index.tsx +73 -67
  48. package/src/plugins/table/ui/common-styles.ts +20 -23
  49. package/src/plugins/table/ui/ui-styles.ts +18 -21
  50. package/src/plugins/table/utils/decoration.ts +27 -32
@@ -13,7 +13,6 @@ var _utils = require("@atlaskit/editor-common/utils");
13
13
  var _view = require("@atlaskit/editor-prosemirror/view");
14
14
  var _tableMap = require("@atlaskit/editor-tables/table-map");
15
15
  var _utils2 = require("@atlaskit/editor-tables/utils");
16
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
16
  var _types = require("../types");
18
17
  var _ColumnResizeWidget = require("../ui/ColumnResizeWidget");
19
18
  // @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
@@ -163,32 +162,28 @@ var createColumnSelectedDecoration = exports.createColumnSelectedDecoration = fu
163
162
  };
164
163
  var createColumnControlsDecoration = exports.createColumnControlsDecoration = function createColumnControlsDecoration(selection) {
165
164
  var cells = (0, _utils2.getCellsInRow)(0)(selection) || [];
166
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.table.drag-and-drop')) {
167
- return [];
168
- } else {
169
- var index = 0;
170
- return cells.map(function (cell) {
171
- var colspan = cell.node.attrs.colspan || 1;
172
- // It's important these values are scoped locally as the widget callback could be executed anytime in the future
173
- // and we want to avoid value leak
174
- var startIndex = index;
175
- var endIndex = startIndex + colspan;
165
+ var index = 0;
166
+ return cells.map(function (cell) {
167
+ var colspan = cell.node.attrs.colspan || 1;
168
+ // It's important these values are scoped locally as the widget callback could be executed anytime in the future
169
+ // and we want to avoid value leak
170
+ var startIndex = index;
171
+ var endIndex = startIndex + colspan;
176
172
 
177
- // The next cell start index will commence from the current cell end index.
178
- index = endIndex;
179
- return _view.Decoration.widget(cell.pos + 1, function () {
180
- var element = document.createElement('div');
181
- element.classList.add(_types.TableCssClassName.COLUMN_CONTROLS_DECORATIONS);
182
- element.dataset.startIndex = "".concat(startIndex);
183
- element.dataset.endIndex = "".concat(endIndex);
184
- return element;
185
- }, {
186
- key: "".concat(_types.TableDecorations.COLUMN_CONTROLS_DECORATIONS, "_").concat(endIndex),
187
- // this decoration should be the first one, even before gap cursor.
188
- side: -100
189
- });
173
+ // The next cell start index will commence from the current cell end index.
174
+ index = endIndex;
175
+ return _view.Decoration.widget(cell.pos + 1, function () {
176
+ var element = document.createElement('div');
177
+ element.classList.add(_types.TableCssClassName.COLUMN_CONTROLS_DECORATIONS);
178
+ element.dataset.startIndex = "".concat(startIndex);
179
+ element.dataset.endIndex = "".concat(endIndex);
180
+ return element;
181
+ }, {
182
+ key: "".concat(_types.TableDecorations.COLUMN_CONTROLS_DECORATIONS, "_").concat(endIndex),
183
+ // this decoration should be the first one, even before gap cursor.
184
+ side: -100
190
185
  });
191
- }
186
+ });
192
187
  };
193
188
  var updateDecorations = exports.updateDecorations = function updateDecorations(node, decorationSet, decorations, key) {
194
189
  var filteredDecorations = filterDecorationByKey(key, decorationSet);
@@ -1,5 +1,3 @@
1
- // #region Imports
2
-
3
1
  import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaskit/editor-common/utils';
4
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
5
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -26,7 +24,9 @@ export const setTableRef = ref => createCommand(state => {
26
24
  const tablePos = ref && foundTable ? foundTable.pos : undefined;
27
25
  const tableWrapperTarget = closestElement(tableRef, `.${ClassName.TABLE_NODE_WRAPPER}`) || undefined;
28
26
  const layout = tableNode ? tableNode.attrs.layout : undefined;
29
- const decorationSet = updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
27
+ const {
28
+ isDragAndDropEnabled
29
+ } = getPluginState(state);
30
30
  return {
31
31
  type: 'SET_TABLE_REF',
32
32
  data: {
@@ -38,7 +38,8 @@ export const setTableRef = ref => createCommand(state => {
38
38
  isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
39
39
  isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
40
40
  isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
41
- decorationSet,
41
+ // decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
42
+ decorationSet: !isDragAndDropEnabled ? updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS) : undefined,
42
43
  resizeHandleRowIndex: undefined,
43
44
  resizeHandleColumnIndex: undefined
44
45
  }
@@ -533,9 +533,7 @@ class TableComponent extends React.Component {
533
533
  const tableRef = this.table || undefined;
534
534
  const headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
535
535
  const hasHeaderRow = containsHeaderRow(node);
536
- const rowControls = /*#__PURE__*/React.createElement("div", {
537
- className: ClassName.ROW_CONTROLS_WRAPPER
538
- }, /*#__PURE__*/React.createElement(TableFloatingControls, {
536
+ const rowControls = /*#__PURE__*/React.createElement(TableFloatingControls, {
539
537
  editorView: view,
540
538
  tableRef: tableRef,
541
539
  tableNode: node,
@@ -555,7 +553,7 @@ class TableComponent extends React.Component {
555
553
  selection: view.state.selection,
556
554
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
557
555
  stickyHeader: this.state.stickyHeader
558
- }));
556
+ });
559
557
  const colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
560
558
  editorView: view,
561
559
  tableRef: tableRef,
@@ -2,7 +2,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
5
  import { pluginKey as tablePluginKey } from '../plugin-key';
7
6
  import { pluginKey as tableWidthPluginKey } from '../table-width';
8
7
  import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
@@ -12,15 +11,21 @@ export const handleDocOrSelectionChanged = (tr, decorationSet, oldState, newStat
12
11
  var _tableWidthPluginKey$, _tableWidthPluginKey$2;
13
12
  const isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
14
13
  const wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
14
+ const {
15
+ isDragAndDropEnabled = false
16
+ } = tablePluginKey.getState(newState) || {};
15
17
  const changedResizing = isResizing !== wasResizing;
16
18
 
17
19
  // Remove column controls when resizing and don't add column decoration controls when DnD enabled
18
- if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
20
+ if (isResizing) {
19
21
  return DecorationSet.empty;
20
22
  } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
21
23
  return buildColumnControlsDecorations({
22
24
  decorationSet,
23
- tr
25
+ tr,
26
+ options: {
27
+ isDragAndDropEnabled
28
+ }
24
29
  });
25
30
  } else if (tr.selectionSet) {
26
31
  const isTransactionFromMouseClick = !tr.docChanged && tr.selectionSet && tr.getMeta('pointer');
@@ -39,6 +44,7 @@ export const createPlugin = () => {
39
44
  init: () => DecorationSet.empty,
40
45
  apply: (tr, decorationSet, oldState, newState) => {
41
46
  let pluginState = decorationSet;
47
+ // main table plugin --->
42
48
  const meta = tr.getMeta(tablePluginKey);
43
49
  if (meta && meta.data && meta.data.decorationSet) {
44
50
  pluginState = meta.data.decorationSet;
@@ -25,8 +25,6 @@ const maybeUpdateColumnControlsDecoration = ({
25
25
  tr
26
26
  }) => {
27
27
  const table = findTable(tr.selection);
28
-
29
- // avoid re-drawing state if dnd decorations don't need to be updated
30
28
  if (!table) {
31
29
  return decorationSet;
32
30
  }
@@ -52,8 +50,15 @@ export const maybeUpdateColumnControlsSelectedDecoration = ({
52
50
  };
53
51
  export const buildColumnControlsDecorations = ({
54
52
  decorationSet,
55
- tr
53
+ tr,
54
+ options
56
55
  }) => {
56
+ if (options.isDragAndDropEnabled) {
57
+ return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration])({
58
+ decorationSet,
59
+ tr
60
+ });
61
+ }
57
62
  return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
58
63
  decorationSet,
59
64
  tr
@@ -79,7 +79,8 @@ export const TableCssClassName = {
79
79
  CORNER_CONTROLS_INSERT_ROW_MARKER: `${tablePrefixSelector}-corner-controls__insert-row-marker`,
80
80
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: `${tablePrefixSelector}-corner-controls__insert-column-marker`,
81
81
  CONTROLS_CORNER_BUTTON: `${tablePrefixSelector}-corner-button`,
82
- /** Controls with drag handle */
82
+ /** drag and drop controls */
83
+ DRAG_ROW_CONTROLS_WRAPPER: `${tablePrefixSelector}-drag-row-controls-wrapper`,
83
84
  DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
84
85
  DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
85
86
  DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
@@ -128,7 +128,10 @@ export default class TableFloatingControls extends Component {
128
128
  return null;
129
129
  }
130
130
  const stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
131
+ const wrapperClassName = isDragAndDropEnabled ? ClassName.DRAG_ROW_CONTROLS_WRAPPER : ClassName.ROW_CONTROLS_WRAPPER;
131
132
  return /*#__PURE__*/React.createElement("div", {
133
+ className: wrapperClassName
134
+ }, /*#__PURE__*/React.createElement("div", {
132
135
  onMouseDown: e => !isDragAndDropEnabled && e.preventDefault()
133
136
  }, isNumberColumnEnabled ? /*#__PURE__*/React.createElement(NumberColumn, {
134
137
  editorView: editorView,
@@ -178,7 +181,7 @@ export default class TableFloatingControls extends Component {
178
181
  isResizing: isResizing,
179
182
  selectRow: this.selectRow,
180
183
  stickyTop: tableActive ? stickyTop : undefined
181
- }))));
184
+ })))));
182
185
  }
183
186
  }
184
187
  _defineProperty(TableFloatingControls, "displayName", 'TableFloatingControls');
@@ -173,23 +173,6 @@ const tableStickyHeaderFirefoxFixStyle = props => {
173
173
  `;
174
174
  }
175
175
  };
176
- const tableRowControlStyles = () => {
177
- return getBooleanFF('platform.editor.table.drag-and-drop') ? css`
178
- .${ClassName.ROW_CONTROLS_WRAPPER} {
179
- position: absolute;
180
- margin-top: ${tableMarginTop}px;
181
- left: -${tableToolbarSize + 1}px;
182
- z-index: ${rowControlsZIndex + 4};
183
- }
184
- ` : css`
185
- .${ClassName.ROW_CONTROLS_WRAPPER} {
186
- position: absolute;
187
- /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
188
- top: ${tableMarginTop - cornerControlHeight + 1}px;
189
- left: -${tableToolbarSize}px;
190
- }
191
- `;
192
- };
193
176
  const tableWrapperStyles = () => {
194
177
  if (getBooleanFF('platform.editor.custom-table-width')) {
195
178
  return css`
@@ -463,7 +446,8 @@ export const tableStyles = props => {
463
446
  .less-padding {
464
447
  padding: 0 ${tablePadding}px;
465
448
 
466
- .${ClassName.ROW_CONTROLS_WRAPPER} {
449
+ .${ClassName.DRAG_ROW_CONTROLS_WRAPPER},
450
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
467
451
  padding: 0 ${tablePadding}px;
468
452
 
469
453
  // https://product-fabric.atlassian.net/browse/ED-16386
@@ -935,8 +919,24 @@ export const tableStyles = props => {
935
919
  }
936
920
  }
937
921
  }
938
- ${tableRowControlStyles()}
939
- .${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
922
+
923
+ // override for DnD controls
924
+ .${ClassName.DRAG_ROW_CONTROLS_WRAPPER} {
925
+ position: absolute;
926
+ margin-top: ${tableMarginTop}px;
927
+ left: -${tableToolbarSize + 1}px;
928
+ z-index: ${rowControlsZIndex + 4};
929
+ }
930
+
931
+ .${ClassName.ROW_CONTROLS_WRAPPER} {
932
+ position: absolute;
933
+ /* top of corner control is table margin top - corner control height + 1 pixel of table border. */
934
+ top: ${tableMarginTop - cornerControlHeight + 1}px;
935
+ left: -${tableToolbarSize}px;
936
+ }
937
+
938
+ .${ClassName.DRAG_ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW},
939
+ .${ClassName.ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_LEFT_SHADOW} {
940
940
  z-index: ${akEditorUnitZIndex};
941
941
  }
942
942
 
@@ -400,27 +400,24 @@ export const floatingColumnControls = props => {
400
400
  `;
401
401
  };
402
402
  export const rowControlsWrapperDotStyle = props => {
403
- if (getBooleanFF('platform.editor.table.drag-and-drop')) {
404
- return css`
405
- div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
406
- display: none;
407
- }
408
- `;
409
- } else {
410
- return css`
411
- div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
412
- content: ' ';
413
- background-color: ${tableBorderColor(props)};
414
- position: absolute;
415
- height: ${lineMarkerSize}px;
416
- width: ${lineMarkerSize}px;
417
- border-radius: 50%;
418
- pointer-events: none;
419
- top: -${tableToolbarSize + tableCellBorderWidth}px;
420
- right: -1px;
421
- }
422
- `;
423
- }
403
+ return css`
404
+ // override for DnD controls
405
+ div.${ClassName.WITH_CONTROLS}>.${ClassName.DRAG_ROW_CONTROLS_WRAPPER}::after {
406
+ display: none;
407
+ }
408
+
409
+ div.${ClassName.WITH_CONTROLS}>.${ClassName.ROW_CONTROLS_WRAPPER}::after {
410
+ content: ' ';
411
+ background-color: ${tableBorderColor(props)};
412
+ position: absolute;
413
+ height: ${lineMarkerSize}px;
414
+ width: ${lineMarkerSize}px;
415
+ border-radius: 50%;
416
+ pointer-events: none;
417
+ top: -${tableToolbarSize + tableCellBorderWidth}px;
418
+ right: -1px;
419
+ }
420
+ `;
424
421
  };
425
422
  export const columnControlsDecoration = props => {
426
423
  if (getBooleanFF('platform.editor.table.column-controls-styles-updated')) {
@@ -8,7 +8,6 @@ import { nonNullable } from '@atlaskit/editor-common/utils';
8
8
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
9
9
  import { Rect, TableMap } from '@atlaskit/editor-tables/table-map';
10
10
  import { findTable, getCellsInRow, getSelectionRect } from '@atlaskit/editor-tables/utils';
11
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
11
  import { TableCssClassName as ClassName, TableDecorations } from '../types';
13
12
  import { ColumnResizeWidget } from '../ui/ColumnResizeWidget';
14
13
  const filterDecorationByKey = (key, decorationSet) => decorationSet.find(undefined, undefined, spec => spec.key.indexOf(key) > -1);
@@ -138,32 +137,28 @@ export const createColumnSelectedDecoration = tr => {
138
137
  };
139
138
  export const createColumnControlsDecoration = selection => {
140
139
  const cells = getCellsInRow(0)(selection) || [];
141
- if (getBooleanFF('platform.editor.table.drag-and-drop')) {
142
- return [];
143
- } else {
144
- let index = 0;
145
- return cells.map(cell => {
146
- const colspan = cell.node.attrs.colspan || 1;
147
- // It's important these values are scoped locally as the widget callback could be executed anytime in the future
148
- // and we want to avoid value leak
149
- const startIndex = index;
150
- const endIndex = startIndex + colspan;
140
+ let index = 0;
141
+ return cells.map(cell => {
142
+ const colspan = cell.node.attrs.colspan || 1;
143
+ // It's important these values are scoped locally as the widget callback could be executed anytime in the future
144
+ // and we want to avoid value leak
145
+ const startIndex = index;
146
+ const endIndex = startIndex + colspan;
151
147
 
152
- // The next cell start index will commence from the current cell end index.
153
- index = endIndex;
154
- return Decoration.widget(cell.pos + 1, () => {
155
- const element = document.createElement('div');
156
- element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
157
- element.dataset.startIndex = `${startIndex}`;
158
- element.dataset.endIndex = `${endIndex}`;
159
- return element;
160
- }, {
161
- key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
162
- // this decoration should be the first one, even before gap cursor.
163
- side: -100
164
- });
148
+ // The next cell start index will commence from the current cell end index.
149
+ index = endIndex;
150
+ return Decoration.widget(cell.pos + 1, () => {
151
+ const element = document.createElement('div');
152
+ element.classList.add(ClassName.COLUMN_CONTROLS_DECORATIONS);
153
+ element.dataset.startIndex = `${startIndex}`;
154
+ element.dataset.endIndex = `${endIndex}`;
155
+ return element;
156
+ }, {
157
+ key: `${TableDecorations.COLUMN_CONTROLS_DECORATIONS}_${endIndex}`,
158
+ // this decoration should be the first one, even before gap cursor.
159
+ side: -100
165
160
  });
166
- }
161
+ });
167
162
  };
168
163
  export const updateDecorations = (node, decorationSet, decorations, key) => {
169
164
  const filteredDecorations = filterDecorationByKey(key, decorationSet);
@@ -1,8 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- // #region Imports
5
-
6
4
  import { closestElement, isParagraph, isTextSelection, mapSlice } from '@atlaskit/editor-common/utils';
7
5
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
8
6
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
@@ -32,7 +30,8 @@ export var setTableRef = function setTableRef(ref) {
32
30
  var tablePos = ref && foundTable ? foundTable.pos : undefined;
33
31
  var tableWrapperTarget = closestElement(tableRef, ".".concat(ClassName.TABLE_NODE_WRAPPER)) || undefined;
34
32
  var layout = tableNode ? tableNode.attrs.layout : undefined;
35
- var decorationSet = updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS);
33
+ var _getPluginState = getPluginState(state),
34
+ isDragAndDropEnabled = _getPluginState.isDragAndDropEnabled;
36
35
  return {
37
36
  type: 'SET_TABLE_REF',
38
37
  data: {
@@ -44,7 +43,8 @@ export var setTableRef = function setTableRef(ref) {
44
43
  isNumberColumnEnabled: checkIfNumberColumnEnabled(state.selection),
45
44
  isHeaderRowEnabled: checkIfHeaderRowEnabled(state.selection),
46
45
  isHeaderColumnEnabled: checkIfHeaderColumnEnabled(state.selection),
47
- decorationSet: decorationSet,
46
+ // decoration set is drawn by the decoration plugin, skip this for DnD as all controls are floating
47
+ decorationSet: !isDragAndDropEnabled ? updatePluginStateDecorations(state, createColumnControlsDecoration(state.selection), TableDecorations.COLUMN_CONTROLS_DECORATIONS) : undefined,
48
48
  resizeHandleRowIndex: undefined,
49
49
  resizeHandleColumnIndex: undefined
50
50
  }
@@ -381,9 +381,9 @@ export var hideInsertColumnOrRowButton = function hideInsertColumnOrRowButton()
381
381
  export var addResizeHandleDecorations = function addResizeHandleDecorations(rowIndex, columnIndex, includeTooltip) {
382
382
  return createCommand(function (state) {
383
383
  var tableNode = findTable(state.selection);
384
- var _getPluginState = getPluginState(state),
385
- allowColumnResizing = _getPluginState.pluginConfig.allowColumnResizing,
386
- getIntl = _getPluginState.getIntl;
384
+ var _getPluginState2 = getPluginState(state),
385
+ allowColumnResizing = _getPluginState2.pluginConfig.allowColumnResizing,
386
+ getIntl = _getPluginState2.getIntl;
387
387
  if (!tableNode || !allowColumnResizing) {
388
388
  return false;
389
389
  }
@@ -406,12 +406,12 @@ export var addResizeHandleDecorations = function addResizeHandleDecorations(rowI
406
406
  export var updateResizeHandleDecorations = function updateResizeHandleDecorations(rowIndex, columnIndex, includeTooltip) {
407
407
  return createCommand(function (state) {
408
408
  var tableNode = findTable(state.selection);
409
- var _getPluginState2 = getPluginState(state),
410
- resizeHandleRowIndex = _getPluginState2.resizeHandleRowIndex,
411
- resizeHandleColumnIndex = _getPluginState2.resizeHandleColumnIndex,
412
- resizeHandleIncludeTooltip = _getPluginState2.resizeHandleIncludeTooltip,
413
- allowColumnResizing = _getPluginState2.pluginConfig.allowColumnResizing,
414
- getIntl = _getPluginState2.getIntl;
409
+ var _getPluginState3 = getPluginState(state),
410
+ resizeHandleRowIndex = _getPluginState3.resizeHandleRowIndex,
411
+ resizeHandleColumnIndex = _getPluginState3.resizeHandleColumnIndex,
412
+ resizeHandleIncludeTooltip = _getPluginState3.resizeHandleIncludeTooltip,
413
+ allowColumnResizing = _getPluginState3.pluginConfig.allowColumnResizing,
414
+ getIntl = _getPluginState3.getIntl;
415
415
  if (!tableNode || !allowColumnResizing) {
416
416
  return false;
417
417
  }
@@ -524,9 +524,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
524
524
  var tableRef = this.table || undefined;
525
525
  var headerRow = tableRef ? tableRef.querySelector('tr[data-header-row]') : undefined;
526
526
  var hasHeaderRow = containsHeaderRow(node);
527
- var rowControls = /*#__PURE__*/React.createElement("div", {
528
- className: ClassName.ROW_CONTROLS_WRAPPER
529
- }, /*#__PURE__*/React.createElement(TableFloatingControls, {
527
+ var rowControls = /*#__PURE__*/React.createElement(TableFloatingControls, {
530
528
  editorView: view,
531
529
  tableRef: tableRef,
532
530
  tableNode: node,
@@ -546,7 +544,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
546
544
  selection: view.state.selection,
547
545
  headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
548
546
  stickyHeader: this.state.stickyHeader
549
- }));
547
+ });
550
548
  var colControls = isDragAndDropEnabled ? /*#__PURE__*/React.createElement(TableFloatingColumnControls, {
551
549
  editorView: view,
552
550
  tableRef: tableRef,
@@ -2,7 +2,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
5
  import { pluginKey as tablePluginKey } from '../plugin-key';
7
6
  import { pluginKey as tableWidthPluginKey } from '../table-width';
8
7
  import { buildColumnControlsDecorations, maybeUpdateColumnControlsSelectedDecoration } from './utils';
@@ -14,15 +13,21 @@ export var handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr
14
13
  var _tableWidthPluginKey$, _tableWidthPluginKey$2;
15
14
  var isResizing = (_tableWidthPluginKey$ = tableWidthPluginKey.getState(newState)) === null || _tableWidthPluginKey$ === void 0 ? void 0 : _tableWidthPluginKey$.resizing;
16
15
  var wasResizing = (_tableWidthPluginKey$2 = tableWidthPluginKey.getState(oldState)) === null || _tableWidthPluginKey$2 === void 0 ? void 0 : _tableWidthPluginKey$2.resizing;
16
+ var _ref = tablePluginKey.getState(newState) || {},
17
+ _ref$isDragAndDropEna = _ref.isDragAndDropEnabled,
18
+ isDragAndDropEnabled = _ref$isDragAndDropEna === void 0 ? false : _ref$isDragAndDropEna;
17
19
  var changedResizing = isResizing !== wasResizing;
18
20
 
19
21
  // Remove column controls when resizing and don't add column decoration controls when DnD enabled
20
- if (isResizing || getBooleanFF('platform.editor.table.drag-and-drop')) {
22
+ if (isResizing) {
21
23
  return DecorationSet.empty;
22
24
  } else if (tr.docChanged || tr.selection instanceof CellSelection || changedResizing) {
23
25
  return buildColumnControlsDecorations({
24
26
  decorationSet: decorationSet,
25
- tr: tr
27
+ tr: tr,
28
+ options: {
29
+ isDragAndDropEnabled: isDragAndDropEnabled
30
+ }
26
31
  });
27
32
  } else if (tr.selectionSet) {
28
33
  var isTransactionFromMouseClick = !tr.docChanged && tr.selectionSet && tr.getMeta('pointer');
@@ -43,6 +48,7 @@ export var createPlugin = function createPlugin() {
43
48
  },
44
49
  apply: function apply(tr, decorationSet, oldState, newState) {
45
50
  var pluginState = decorationSet;
51
+ // main table plugin --->
46
52
  var meta = tr.getMeta(tablePluginKey);
47
53
  if (meta && meta.data && meta.data.decorationSet) {
48
54
  pluginState = meta.data.decorationSet;
@@ -26,8 +26,6 @@ var maybeUpdateColumnControlsDecoration = function maybeUpdateColumnControlsDeco
26
26
  var decorationSet = _ref3.decorationSet,
27
27
  tr = _ref3.tr;
28
28
  var table = findTable(tr.selection);
29
-
30
- // avoid re-drawing state if dnd decorations don't need to be updated
31
29
  if (!table) {
32
30
  return decorationSet;
33
31
  }
@@ -55,7 +53,14 @@ export var maybeUpdateColumnControlsSelectedDecoration = function maybeUpdateCol
55
53
  };
56
54
  export var buildColumnControlsDecorations = function buildColumnControlsDecorations(_ref6) {
57
55
  var decorationSet = _ref6.decorationSet,
58
- tr = _ref6.tr;
56
+ tr = _ref6.tr,
57
+ options = _ref6.options;
58
+ if (options.isDragAndDropEnabled) {
59
+ return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration])({
60
+ decorationSet: decorationSet,
61
+ tr: tr
62
+ });
63
+ }
59
64
  return composeDecorations([removeColumnControlsSelectedDecoration, removeControlsHoverDecoration, maybeUpdateColumnSelectedDecoration, maybeUpdateColumnControlsDecoration])({
60
65
  decorationSet: decorationSet,
61
66
  tr: tr
@@ -81,7 +81,8 @@ export var TableCssClassName = _objectSpread(_objectSpread({}, TableSharedCssCla
81
81
  CORNER_CONTROLS_INSERT_ROW_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-row-marker"),
82
82
  CORNER_CONTROLS_INSERT_COLUMN_MARKER: "".concat(tablePrefixSelector, "-corner-controls__insert-column-marker"),
83
83
  CONTROLS_CORNER_BUTTON: "".concat(tablePrefixSelector, "-corner-button"),
84
- /** Controls with drag handle */
84
+ /** drag and drop controls */
85
+ DRAG_ROW_CONTROLS_WRAPPER: "".concat(tablePrefixSelector, "-drag-row-controls-wrapper"),
85
86
  DRAG_ROW_CONTROLS: "".concat(tablePrefixSelector, "-drag-row-controls"),
86
87
  DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: "".concat(tablePrefixSelector, "-drag-row-floating-insert-dot-wrapper"),
87
88
  DRAG_ROW_FLOATING_INSERT_DOT: "".concat(tablePrefixSelector, "-drag-row-floating-insert-dot"),
@@ -156,7 +156,10 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
156
156
  return null;
157
157
  }
158
158
  var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
159
+ var wrapperClassName = isDragAndDropEnabled ? ClassName.DRAG_ROW_CONTROLS_WRAPPER : ClassName.ROW_CONTROLS_WRAPPER;
159
160
  return /*#__PURE__*/React.createElement("div", {
161
+ className: wrapperClassName
162
+ }, /*#__PURE__*/React.createElement("div", {
160
163
  onMouseDown: function onMouseDown(e) {
161
164
  return !isDragAndDropEnabled && e.preventDefault();
162
165
  }
@@ -208,7 +211,7 @@ var TableFloatingControls = /*#__PURE__*/function (_Component) {
208
211
  isResizing: isResizing,
209
212
  selectRow: this.selectRow,
210
213
  stickyTop: tableActive ? stickyTop : undefined
211
- }))));
214
+ })))));
212
215
  }
213
216
  }]);
214
217
  return TableFloatingControls;