@atlaskit/editor-plugin-table 5.2.2 → 5.3.1
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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +20 -2
- package/dist/cjs/plugins/table/nodeviews/table.js +1 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/handlers.js +24 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +29 -4
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/plugin.js +83 -9
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/index.js +12 -0
- package/dist/cjs/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +59 -0
- package/dist/cjs/plugins/table/types.js +12 -1
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +106 -0
- package/dist/cjs/plugins/table/ui/TableFloatingColumnControls/index.js +90 -0
- package/dist/cjs/plugins/table/ui/common-styles.js +1 -1
- package/dist/cjs/plugins/table/ui/consts.js +2 -1
- package/dist/cjs/plugins/table/ui/ui-styles.js +15 -9
- package/dist/cjs/plugins/table/utils/decoration.js +67 -1
- package/dist/cjs/plugins/table/utils/index.js +26 -1
- package/dist/cjs/plugins/table/utils/merged-cells.js +66 -0
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +20 -2
- package/dist/es2019/plugins/table/nodeviews/table.js +1 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/commands.js +35 -7
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/handlers.js +10 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +28 -4
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/plugin.js +82 -6
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/es2019/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +56 -0
- package/dist/es2019/plugins/table/types.js +12 -1
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +101 -0
- package/dist/es2019/plugins/table/ui/TableFloatingColumnControls/index.js +60 -0
- package/dist/es2019/plugins/table/ui/common-styles.js +14 -1
- package/dist/es2019/plugins/table/ui/consts.js +1 -0
- package/dist/es2019/plugins/table/ui/ui-styles.js +127 -1
- package/dist/es2019/plugins/table/utils/decoration.js +62 -0
- package/dist/es2019/plugins/table/utils/index.js +3 -2
- package/dist/es2019/plugins/table/utils/merged-cells.js +48 -0
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +20 -2
- package/dist/esm/plugins/table/nodeviews/table.js +1 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/commands.js +36 -7
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/handlers.js +18 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin-factory.js +28 -3
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/plugin.js +82 -9
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/reducer.js +2 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/index.js +1 -0
- package/dist/esm/plugins/table/pm-plugins/drag-and-drop/utils/monitor.js +53 -0
- package/dist/esm/plugins/table/types.js +12 -1
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.js +97 -0
- package/dist/esm/plugins/table/ui/TableFloatingColumnControls/index.js +80 -0
- package/dist/esm/plugins/table/ui/common-styles.js +2 -2
- package/dist/esm/plugins/table/ui/consts.js +1 -0
- package/dist/esm/plugins/table/ui/ui-styles.js +15 -9
- package/dist/esm/plugins/table/utils/decoration.js +66 -0
- package/dist/esm/plugins/table/utils/index.js +3 -2
- package/dist/esm/plugins/table/utils/merged-cells.js +60 -0
- package/dist/types/plugins/table/index.d.ts +1 -1
- package/dist/types/plugins/table/nodeviews/TableComponent.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +3 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/plugin-factory.d.ts +1 -2
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/types.d.ts +2 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
- package/dist/types/plugins/table/types.d.ts +23 -1
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +11 -0
- package/dist/types/plugins/table/ui/TableFloatingColumnControls/index.d.ts +20 -0
- package/dist/types/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types/plugins/table/ui/ui-styles.d.ts +2 -0
- package/dist/types/plugins/table/utils/decoration.d.ts +2 -0
- package/dist/types/plugins/table/utils/index.d.ts +2 -1
- package/dist/types/plugins/table/utils/merged-cells.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/table/nodeviews/TableComponent.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/actions.d.ts +5 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/commands.d.ts +6 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/handlers.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/plugin-factory.d.ts +1 -2
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/types.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/drag-and-drop/utils/monitor.d.ts +3 -0
- package/dist/types-ts4.5/plugins/table/types.d.ts +23 -1
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.d.ts +11 -0
- package/dist/types-ts4.5/plugins/table/ui/TableFloatingColumnControls/index.d.ts +20 -0
- package/dist/types-ts4.5/plugins/table/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/plugins/table/ui/ui-styles.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/decoration.d.ts +2 -0
- package/dist/types-ts4.5/plugins/table/utils/index.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/utils/merged-cells.d.ts +3 -0
- package/package.json +4 -1
- package/src/__tests__/unit/ui/TableFloatingColumnControls.tsx +139 -0
- package/src/plugins/table/index.tsx +1 -1
- package/src/plugins/table/nodeviews/TableComponent.tsx +25 -0
- package/src/plugins/table/nodeviews/table.tsx +1 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/actions.ts +6 -1
- package/src/plugins/table/pm-plugins/drag-and-drop/commands.ts +58 -8
- package/src/plugins/table/pm-plugins/drag-and-drop/handlers.ts +35 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin-factory.ts +27 -2
- package/src/plugins/table/pm-plugins/drag-and-drop/plugin.ts +88 -6
- package/src/plugins/table/pm-plugins/drag-and-drop/reducer.ts +2 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/types.ts +3 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/index.ts +1 -0
- package/src/plugins/table/pm-plugins/drag-and-drop/utils/monitor.ts +72 -0
- package/src/plugins/table/types.ts +28 -1
- package/src/plugins/table/ui/TableFloatingColumnControls/ColumnDropTargets/index.tsx +128 -0
- package/src/plugins/table/ui/TableFloatingColumnControls/index.tsx +101 -0
- package/src/plugins/table/ui/common-styles.ts +15 -0
- package/src/plugins/table/ui/consts.ts +1 -0
- package/src/plugins/table/ui/ui-styles.ts +129 -0
- package/src/plugins/table/utils/decoration.ts +101 -0
- package/src/plugins/table/utils/index.ts +3 -0
- package/src/plugins/table/utils/merged-cells.ts +67 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 5.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#41703](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41703) [`3631a9d9750`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3631a9d9750) - [ux] Added a command to show insert line decoration/ drop target when dragging a table column or a row.
|
|
8
|
+
- [#41640](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41640) [`c387b1bfcdd`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c387b1bfcdd) - Added a Pragmatic Drag and Drop montior to the DnD table plugin. This is responsible for triggering the row/column move when a drop operation occurs.
|
|
9
|
+
|
|
10
|
+
## 5.3.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [#41577](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41577) [`3d9daab8d32`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3d9daab8d32) - [ux] Added a new floating column control region to the table. This region now also contains Pragmatic DnD Drop targets so we can identify where draggable elements are dropped
|
|
15
|
+
|
|
3
16
|
## 5.2.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -33,6 +33,7 @@ var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
|
|
|
33
33
|
var _dom = require("../pm-plugins/table-resizing/utils/dom");
|
|
34
34
|
var _types = require("../types");
|
|
35
35
|
var _consts = require("../ui/consts");
|
|
36
|
+
var _TableFloatingColumnControls = _interopRequireDefault(require("../ui/TableFloatingColumnControls"));
|
|
36
37
|
var _TableFloatingControls = _interopRequireDefault(require("../ui/TableFloatingControls"));
|
|
37
38
|
var _utils4 = require("../utils");
|
|
38
39
|
var _OverflowShadowsObserver = require("./OverflowShadowsObserver");
|
|
@@ -459,7 +460,8 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
459
460
|
containerWidth = _this$props10.containerWidth,
|
|
460
461
|
options = _this$props10.options,
|
|
461
462
|
getPos = _this$props10.getPos,
|
|
462
|
-
pluginInjectionApi = _this$props10.pluginInjectionApi
|
|
463
|
+
pluginInjectionApi = _this$props10.pluginInjectionApi,
|
|
464
|
+
isDragAndDropEnabled = _this$props10.isDragAndDropEnabled;
|
|
463
465
|
var _this$state3 = this.state,
|
|
464
466
|
showBeforeShadow = _this$state3.showBeforeShadow,
|
|
465
467
|
showAfterShadow = _this$state3.showAfterShadow;
|
|
@@ -492,6 +494,22 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
492
494
|
stickyHeader: this.state.stickyHeader,
|
|
493
495
|
getEditorFeatureFlags: this.props.getEditorFeatureFlags
|
|
494
496
|
}));
|
|
497
|
+
var colControls = /*#__PURE__*/_react.default.createElement("div", {
|
|
498
|
+
className: _types.TableCssClassName.COLUMN_CONTROLS_WRAPPER
|
|
499
|
+
}, /*#__PURE__*/_react.default.createElement(_TableFloatingColumnControls.default, {
|
|
500
|
+
editorView: view,
|
|
501
|
+
tableRef: tableRef,
|
|
502
|
+
tableActive: tableActive,
|
|
503
|
+
hoveredRows: hoveredRows,
|
|
504
|
+
ordering: ordering,
|
|
505
|
+
hasHeaderRow: hasHeaderRow
|
|
506
|
+
// pass `selection` and `tableHeight` to control re-render
|
|
507
|
+
,
|
|
508
|
+
selection: view.state.selection,
|
|
509
|
+
headerRowHeight: headerRow ? headerRow.offsetHeight : undefined,
|
|
510
|
+
stickyHeader: this.state.stickyHeader,
|
|
511
|
+
getEditorFeatureFlags: this.props.getEditorFeatureFlags
|
|
512
|
+
}));
|
|
495
513
|
var shadowPadding = allowControls && tableActive ? -_editorSharedStyles.akEditorTableToolbarSize : _styles.tableMarginSides;
|
|
496
514
|
var shadowStyle = (0, _memoizeOne.default)(function (visible) {
|
|
497
515
|
return {
|
|
@@ -529,7 +547,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
529
547
|
}), (0, _platformFeatureFlags.getBooleanFF)('platform.editor.table-sticky-scrollbar') && /*#__PURE__*/_react.default.createElement("div", {
|
|
530
548
|
className: _types.TableCssClassName.TABLE_STICKY_SCROLLBAR_SENTINEL_TOP,
|
|
531
549
|
"data-testid": "sticky-scrollbar-sentinel-top"
|
|
532
|
-
}), allowControls && rowControls, /*#__PURE__*/_react.default.createElement("div", {
|
|
550
|
+
}), allowControls && rowControls, isDragAndDropEnabled && allowControls && colControls, /*#__PURE__*/_react.default.createElement("div", {
|
|
533
551
|
style: shadowStyle(showBeforeShadow),
|
|
534
552
|
className: _types.TableCssClassName.TABLE_LEFT_SHADOW
|
|
535
553
|
}), this.state.stickyHeader && /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -176,6 +176,7 @@ var TableView = exports.default = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
176
176
|
allowControls: pluginState.pluginConfig.allowControls,
|
|
177
177
|
isHeaderRowEnabled: pluginState.isHeaderRowEnabled,
|
|
178
178
|
isHeaderColumnEnabled: pluginState.isHeaderColumnEnabled,
|
|
179
|
+
isDragAndDropEnabled: pluginState.isDragAndDropEnabled,
|
|
179
180
|
tableActive: tableActive,
|
|
180
181
|
ordering: pluginState.ordering,
|
|
181
182
|
isResizing: isResizing,
|
|
@@ -3,24 +3,53 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setDropTarget = exports.clearDropTarget = void 0;
|
|
6
|
+
exports.updatePluginStateDecorations = exports.setDropTarget = exports.getDecorations = exports.clearDropTarget = void 0;
|
|
7
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
8
|
+
var _types = require("../../types");
|
|
9
|
+
var _utils = require("../../utils");
|
|
7
10
|
var _actions = require("./actions");
|
|
8
11
|
var _pluginFactory = require("./plugin-factory");
|
|
12
|
+
var _pluginKey = require("./plugin-key");
|
|
9
13
|
// TODO: This command is a placeholder example. Please replace this if required.
|
|
14
|
+
var getDecorations = exports.getDecorations = function getDecorations(state) {
|
|
15
|
+
var _pluginKey$getState;
|
|
16
|
+
return ((_pluginKey$getState = _pluginKey.pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.decorationSet) || _view.DecorationSet.empty;
|
|
17
|
+
};
|
|
18
|
+
var updatePluginStateDecorations = exports.updatePluginStateDecorations = function updatePluginStateDecorations(state, decorations, key) {
|
|
19
|
+
return (0, _utils.updateDecorations)(state.doc, getDecorations(state), decorations, key);
|
|
20
|
+
};
|
|
10
21
|
var setDropTarget = exports.setDropTarget = function setDropTarget(type, index, tr) {
|
|
11
|
-
return (0, _pluginFactory.createCommand)({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
return (0, _pluginFactory.createCommand)(function (state) {
|
|
23
|
+
var _getPluginState = (0, _pluginFactory.getPluginState)(state),
|
|
24
|
+
dropTargetType = _getPluginState.dropTargetType,
|
|
25
|
+
dropTargetIndex = _getPluginState.dropTargetIndex;
|
|
26
|
+
if (dropTargetType === type && dropTargetIndex === index) {
|
|
27
|
+
return false;
|
|
16
28
|
}
|
|
29
|
+
var decorationSet = _view.DecorationSet.empty;
|
|
30
|
+
if (type === 'column') {
|
|
31
|
+
decorationSet = updatePluginStateDecorations(state, (0, _utils.createColumnInsertLine)(index, state.selection), _types.TableDecorations.COLUMN_INSERT_LINE);
|
|
32
|
+
} else if (type === 'row') {
|
|
33
|
+
decorationSet = updatePluginStateDecorations(state, (0, _utils.createRowInsertLine)(index, state.selection), _types.TableDecorations.ROW_INSERT_LINE);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
type: _actions.DragAndDropActionType.SET_DROP_TARGET,
|
|
37
|
+
data: {
|
|
38
|
+
decorationSet: decorationSet,
|
|
39
|
+
type: type,
|
|
40
|
+
index: index
|
|
41
|
+
}
|
|
42
|
+
};
|
|
17
43
|
}, function (originalTr) {
|
|
18
44
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
19
45
|
});
|
|
20
46
|
};
|
|
21
47
|
var clearDropTarget = exports.clearDropTarget = function clearDropTarget(tr) {
|
|
22
48
|
return (0, _pluginFactory.createCommand)({
|
|
23
|
-
type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET
|
|
49
|
+
type: _actions.DragAndDropActionType.CLEAR_DROP_TARGET,
|
|
50
|
+
data: {
|
|
51
|
+
decorationSet: _view.DecorationSet.empty
|
|
52
|
+
}
|
|
24
53
|
}, function (originalTr) {
|
|
25
54
|
return (tr || originalTr).setMeta('addToHistory', false);
|
|
26
55
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.handleDocOrSelectionChanged = void 0;
|
|
7
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
8
|
+
// @ts-ignore -- ReadonlyTransaction is a local declaration and will cause a TS2305 error in CCFE typecheck
|
|
9
|
+
|
|
10
|
+
var buildPluginState = function buildPluginState(builders) {
|
|
11
|
+
return function (props) {
|
|
12
|
+
return function (pluginState) {
|
|
13
|
+
return builders.reduce(function (_pluginState, transform) {
|
|
14
|
+
return transform(props)(_pluginState);
|
|
15
|
+
}, pluginState);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
var handleDocOrSelectionChanged = exports.handleDocOrSelectionChanged = function handleDocOrSelectionChanged(tr, pluginState) {
|
|
20
|
+
return buildPluginState([])({
|
|
21
|
+
tr: tr,
|
|
22
|
+
table: (0, _utils.findTable)(tr.selection)
|
|
23
|
+
})(pluginState);
|
|
24
|
+
};
|
|
@@ -4,10 +4,35 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.createPluginState = exports.createCommand = void 0;
|
|
7
|
+
exports.getPluginState = exports.createPluginState = exports.createCommand = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
9
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
|
-
var _pluginKey = require("
|
|
10
|
+
var _pluginKey = require("../plugin-key");
|
|
11
|
+
var _handlers = require("./handlers");
|
|
12
|
+
var _pluginKey2 = require("./plugin-key");
|
|
10
13
|
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
11
|
-
var
|
|
14
|
+
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; }
|
|
15
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
16
|
+
var _pluginFactory = (0, _utils.pluginFactory)(_pluginKey2.pluginKey, _reducer.default, {
|
|
17
|
+
mapping: function mapping(tr, pluginState) {
|
|
18
|
+
if (tr.docChanged) {
|
|
19
|
+
var decorationSet = pluginState.decorationSet;
|
|
20
|
+
var meta = tr.getMeta(_pluginKey.pluginKey);
|
|
21
|
+
if (meta && meta.data && meta.data.decorationSet) {
|
|
22
|
+
decorationSet = meta.data.decorationSet;
|
|
23
|
+
}
|
|
24
|
+
if (decorationSet) {
|
|
25
|
+
decorationSet = decorationSet.map(tr.mapping, tr.doc);
|
|
26
|
+
}
|
|
27
|
+
return _objectSpread(_objectSpread({}, pluginState), {
|
|
28
|
+
decorationSet: decorationSet
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return pluginState;
|
|
32
|
+
},
|
|
33
|
+
onDocChanged: _handlers.handleDocOrSelectionChanged,
|
|
34
|
+
onSelectionChanged: _handlers.handleDocOrSelectionChanged
|
|
35
|
+
}),
|
|
12
36
|
createPluginState = exports.createPluginState = _pluginFactory.createPluginState,
|
|
13
|
-
createCommand = exports.createCommand = _pluginFactory.createCommand
|
|
37
|
+
createCommand = exports.createCommand = _pluginFactory.createCommand,
|
|
38
|
+
getPluginState = exports.getPluginState = _pluginFactory.getPluginState;
|
|
@@ -1,28 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.createPlugin = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
7
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
11
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
12
|
+
var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
|
|
13
|
+
var _mergedCells = require("../../utils/merged-cells");
|
|
14
|
+
var _pluginFactory = require("../plugin-factory");
|
|
8
15
|
var _consts = require("./consts");
|
|
9
|
-
var
|
|
16
|
+
var _pluginFactory2 = require("./plugin-factory");
|
|
10
17
|
var _pluginKey = require("./plugin-key");
|
|
18
|
+
var _monitor = require("./utils/monitor");
|
|
11
19
|
var createPlugin = exports.createPlugin = function createPlugin(dispatch, eventDispatcher) {
|
|
12
20
|
return new _safePlugin.SafePlugin({
|
|
13
|
-
state: (0,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
state: (0, _pluginFactory2.createPluginState)(dispatch, function (state) {
|
|
22
|
+
return {
|
|
23
|
+
decorationSet: _view.DecorationSet.empty,
|
|
24
|
+
// TODO: This is example placeholder state. We could use this to track which row/col is currently set as the drop target
|
|
25
|
+
// This would result in a blue highlight being displayed on the corrisponding row/column to single the drop target location.
|
|
26
|
+
dropTargetType: _consts.DropTargetType.NONE,
|
|
27
|
+
dropTargetIndex: 0
|
|
28
|
+
};
|
|
18
29
|
}),
|
|
19
30
|
key: _pluginKey.pluginKey,
|
|
20
31
|
view: function view(editorView) {
|
|
21
|
-
// TODO: Add Pragmatic DnD monitor when the view is constructed.
|
|
22
32
|
return {
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
destroy: (0, _element.monitorForElements)({
|
|
34
|
+
canMonitor: function canMonitor(_ref) {
|
|
35
|
+
var source = _ref.source;
|
|
36
|
+
var _ref2 = source.data,
|
|
37
|
+
type = _ref2.type,
|
|
38
|
+
localId = _ref2.localId,
|
|
39
|
+
indexes = _ref2.indexes;
|
|
40
|
+
|
|
41
|
+
// First; Perform any quick checks so we can abort early.
|
|
42
|
+
if (!indexes || !localId ||
|
|
43
|
+
// FIXME: We currently don't support DragNDrop of multiple elements. For now we will not bother to monitor drags
|
|
44
|
+
// of more then 1 item.
|
|
45
|
+
indexes.length !== 1 || !(type === 'table-row' || type === 'table-column')) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
var _getTablePluginState = (0, _pluginFactory.getPluginState)(editorView.state),
|
|
49
|
+
tableNode = _getTablePluginState.tableNode;
|
|
50
|
+
// If the draggable localId is the same as the current selected table localId then we will allow the monitor
|
|
51
|
+
// watch for changes
|
|
52
|
+
return localId === (tableNode === null || tableNode === void 0 ? void 0 : tableNode.attrs.localId);
|
|
53
|
+
},
|
|
54
|
+
onDrag: function onDrag(event) {
|
|
55
|
+
var data = (0, _monitor.getDraggableDataFromEvent)(event);
|
|
56
|
+
|
|
57
|
+
// If no data can be found then it's most like we do not want to perform any drag actions
|
|
58
|
+
if (!data) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// TODO: as we drag an element around we are going to want to update the state to acurately reflect the current
|
|
63
|
+
// insert location as to where the draggable will most likely be go. For example;
|
|
64
|
+
// const { sourceType, targetAdjustedIndex } = data;
|
|
65
|
+
// const highlight = sourceType === 'table-row' ? highlightRow : highlightColumn;
|
|
66
|
+
// return editorView.dispatch(
|
|
67
|
+
// highlight(targetAdjustedIndex)(editorView.state.tr),
|
|
68
|
+
// );
|
|
69
|
+
},
|
|
70
|
+
onDrop: function onDrop(event) {
|
|
71
|
+
var data = (0, _monitor.getDraggableDataFromEvent)(event);
|
|
72
|
+
|
|
73
|
+
// If no data can be found then it's most like we do not want to perform any drop action
|
|
74
|
+
if (!data) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
var sourceType = data.sourceType,
|
|
78
|
+
sourceIndexes = data.sourceIndexes,
|
|
79
|
+
targetAdjustedIndex = data.targetAdjustedIndex;
|
|
80
|
+
|
|
81
|
+
// If the drop target index contains merged cells then we should not allow the drop to occur.
|
|
82
|
+
var hasMergedCells = sourceType === 'table-row' ? _mergedCells.hasMergedCellsInRow : _mergedCells.hasMergedCellsInColumn;
|
|
83
|
+
if (hasMergedCells(targetAdjustedIndex)(editorView.state.selection)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
var move = sourceType === 'table-row' ? _utils.moveRow : _utils.moveColumn;
|
|
87
|
+
var _sourceIndexes = (0, _slicedToArray2.default)(sourceIndexes, 1),
|
|
88
|
+
sourceIndex = _sourceIndexes[0];
|
|
89
|
+
return editorView.dispatch(move(sourceIndex, targetAdjustedIndex)(editorView.state.tr));
|
|
90
|
+
}
|
|
91
|
+
})
|
|
25
92
|
};
|
|
93
|
+
},
|
|
94
|
+
props: {
|
|
95
|
+
decorations: function decorations(state) {
|
|
96
|
+
var _getPluginState = (0, _pluginFactory2.getPluginState)(state),
|
|
97
|
+
decorationSet = _getPluginState.decorationSet;
|
|
98
|
+
return decorationSet;
|
|
99
|
+
}
|
|
26
100
|
}
|
|
27
101
|
});
|
|
28
102
|
};
|
|
@@ -14,11 +14,13 @@ var _default = exports.default = function _default(pluginState, action) {
|
|
|
14
14
|
switch (action.type) {
|
|
15
15
|
case _actions.DragAndDropActionType.SET_DROP_TARGET:
|
|
16
16
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
17
|
+
decorationSet: action.data.decorationSet,
|
|
17
18
|
dropTargetType: action.data.type,
|
|
18
19
|
dropTargetIndex: action.data.index
|
|
19
20
|
});
|
|
20
21
|
case _actions.DragAndDropActionType.CLEAR_DROP_TARGET:
|
|
21
22
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
23
|
+
decorationSet: action.data.decorationSet,
|
|
22
24
|
dropTargetType: _consts.DropTargetType.NONE,
|
|
23
25
|
dropTargetIndex: 0
|
|
24
26
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "getDraggableDataFromEvent", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _monitor.getDraggableDataFromEvent;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _monitor = require("./monitor");
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDraggableDataFromEvent = void 0;
|
|
7
|
+
var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge");
|
|
8
|
+
var getDraggableDataFromEvent = exports.getDraggableDataFromEvent = function getDraggableDataFromEvent(_ref) {
|
|
9
|
+
var _extractClosestEdge;
|
|
10
|
+
var location = _ref.location,
|
|
11
|
+
source = _ref.source;
|
|
12
|
+
var destination = location.current.dropTargets.at(0);
|
|
13
|
+
// If no target exists at the current location, then the current draggable is not over a target or the target doesn't support
|
|
14
|
+
// the current draggable.
|
|
15
|
+
if (!destination) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// This is the draggable elements data
|
|
20
|
+
var _ref2 = source.data,
|
|
21
|
+
sourceIndexes = _ref2.indexes,
|
|
22
|
+
sourceType = _ref2.type,
|
|
23
|
+
sourceLocalId = _ref2.localId;
|
|
24
|
+
|
|
25
|
+
// This is the drop target's data
|
|
26
|
+
var _ref3 = destination.data,
|
|
27
|
+
targetIndex = _ref3.targetIndex,
|
|
28
|
+
targetType = _ref3.type,
|
|
29
|
+
targetLocalId = _ref3.localId;
|
|
30
|
+
|
|
31
|
+
// Some basic check to abort early with...
|
|
32
|
+
if (!sourceIndexes || targetIndex < 0 ||
|
|
33
|
+
// abort if the type of the draggable is different to the target, for eg. rows cannot be dropped onto column targets.
|
|
34
|
+
sourceType !== targetType ||
|
|
35
|
+
// abort if the draggable is coming from a different table that the target is on.
|
|
36
|
+
sourceLocalId !== targetLocalId) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// FIXME: currently we only support a single row/col index being moved, remove this clause when this is no longer the case.
|
|
41
|
+
if (sourceIndexes.length > 1) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
var targetClosestEdge = (_extractClosestEdge = (0, _closestEdge.extractClosestEdge)(destination.data)) !== null && _extractClosestEdge !== void 0 ? _extractClosestEdge : targetType === 'table-row' ? 'top' : 'left';
|
|
45
|
+
// NOTE: By default we always insert row/cols at the target index to the top/left (retrospectively of row/cols).
|
|
46
|
+
// This introduces an offset in the event the drop occured closer to the bottom/right of the target. We want
|
|
47
|
+
// the new target index to be 1 index higher.
|
|
48
|
+
var targetOffset = targetClosestEdge === 'right' || targetClosestEdge === 'bottom' ? 1 : 0;
|
|
49
|
+
return {
|
|
50
|
+
sourceType: sourceType,
|
|
51
|
+
sourceLocalId: sourceLocalId,
|
|
52
|
+
sourceIndexes: sourceIndexes,
|
|
53
|
+
targetType: targetType,
|
|
54
|
+
targetLocalId: targetLocalId,
|
|
55
|
+
targetIndex: targetIndex,
|
|
56
|
+
targetAdjustedIndex: targetIndex + targetOffset,
|
|
57
|
+
targetClosestEdge: targetClosestEdge
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -43,10 +43,13 @@ var TableDecorations = exports.TableDecorations = /*#__PURE__*/function (TableDe
|
|
|
43
43
|
TableDecorations["TABLE_CONTROLS_HOVER"] = "TABLE_CONTROLS_HOVER";
|
|
44
44
|
TableDecorations["CELL_CONTROLS_HOVER"] = "CELL_CONTROLS_HOVER";
|
|
45
45
|
TableDecorations["COLUMN_CONTROLS_DECORATIONS"] = "COLUMN_CONTROLS_DECORATIONS";
|
|
46
|
+
TableDecorations["COLUMN_DROP_TARGET_DECORATIONS"] = "COLUMN_DROP_TARGET_DECORATIONS";
|
|
46
47
|
TableDecorations["COLUMN_SELECTED"] = "COLUMN_SELECTED";
|
|
47
48
|
TableDecorations["COLUMN_RESIZING_HANDLE"] = "COLUMN_RESIZING_HANDLE";
|
|
48
49
|
TableDecorations["COLUMN_RESIZING_HANDLE_WIDGET"] = "COLUMN_RESIZING_HANDLE_WIDGET";
|
|
49
50
|
TableDecorations["COLUMN_RESIZING_HANDLE_LINE"] = "COLUMN_RESIZING_HANDLE_LINE";
|
|
51
|
+
TableDecorations["COLUMN_INSERT_LINE"] = "COLUMN_INSERT_LINE";
|
|
52
|
+
TableDecorations["ROW_INSERT_LINE"] = "ROW_INSERT_LINE";
|
|
50
53
|
TableDecorations["LAST_CELL_ELEMENT"] = "LAST_CELL_ELEMENT";
|
|
51
54
|
return TableDecorations;
|
|
52
55
|
}({});
|
|
@@ -54,6 +57,9 @@ var TableCssClassName = exports.TableCssClassName = _objectSpread(_objectSpread(
|
|
|
54
57
|
COLUMN_CONTROLS: "".concat(_adfSchema.tablePrefixSelector, "-column-controls"),
|
|
55
58
|
COLUMN_CONTROLS_DECORATIONS: "".concat(_adfSchema.tablePrefixSelector, "-column-controls-decoration"),
|
|
56
59
|
COLUMN_SELECTED: "".concat(_adfSchema.tablePrefixSelector, "-column__selected"),
|
|
60
|
+
COLUMN_CONTROLS_WRAPPER: "".concat(_adfSchema.tablePrefixSelector, "-col-controls-wrapper"),
|
|
61
|
+
COLUMN_DROP_TARGET_CONTROLS: "".concat(_adfSchema.tablePrefixSelector, "-col-drop-target-controls"),
|
|
62
|
+
COLUMN_CONTROLS_INNER: "".concat(_adfSchema.tablePrefixSelector, "-col-controls__inner"),
|
|
57
63
|
ROW_CONTROLS_WRAPPER: "".concat(_adfSchema.tablePrefixSelector, "-row-controls-wrapper"),
|
|
58
64
|
ROW_CONTROLS: "".concat(_adfSchema.tablePrefixSelector, "-row-controls"),
|
|
59
65
|
ROW_CONTROLS_INNER: "".concat(_adfSchema.tablePrefixSelector, "-row-controls__inner"),
|
|
@@ -110,8 +116,13 @@ var TableCssClassName = exports.TableCssClassName = _objectSpread(_objectSpread(
|
|
|
110
116
|
TABLE_STICKY: "".concat(_adfSchema.tablePrefixSelector, "-sticky"),
|
|
111
117
|
TOP_LEFT_CELL: 'table > tbody > tr:nth-child(2) > td:nth-child(1)',
|
|
112
118
|
LAST_ITEM_IN_CELL: "".concat(_adfSchema.tablePrefixSelector, "-last-item-in-cell"),
|
|
119
|
+
WITH_COLUMN_INSERT_LINE: "".concat(_adfSchema.tablePrefixSelector, "-column-insert-line"),
|
|
120
|
+
WITH_FIRST_COLUMN_INSERT_LINE: "".concat(_adfSchema.tablePrefixSelector, "-first-column-insert-line"),
|
|
121
|
+
WITH_LAST_COLUMN_INSERT_LINE: "".concat(_adfSchema.tablePrefixSelector, "-last-column-insert-line"),
|
|
113
122
|
WITH_RESIZE_LINE: "".concat(_adfSchema.tablePrefixSelector, "-column-resize-line"),
|
|
114
|
-
WITH_RESIZE_LINE_LAST_COLUMN: "".concat(_adfSchema.tablePrefixSelector, "-column-resize-line-last-column")
|
|
123
|
+
WITH_RESIZE_LINE_LAST_COLUMN: "".concat(_adfSchema.tablePrefixSelector, "-column-resize-line-last-column"),
|
|
124
|
+
WITH_ROW_INSERT_LINE: "".concat(_adfSchema.tablePrefixSelector, "-row-insert-line"),
|
|
125
|
+
WITH_LAST_ROW_INSERT_LINE: "".concat(_adfSchema.tablePrefixSelector, "-last-row-insert-line")
|
|
115
126
|
});
|
|
116
127
|
var ShadowEvent = exports.ShadowEvent = /*#__PURE__*/function (ShadowEvent) {
|
|
117
128
|
ShadowEvent["SHOW_BEFORE_SHADOW"] = "showBeforeShadow";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.ColumnDropTargets = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _closestEdge = require("@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge");
|
|
10
|
+
var _element = require("@atlaskit/pragmatic-drag-and-drop/adapter/element");
|
|
11
|
+
var _types = require("../../../types");
|
|
12
|
+
var _utils = require("../../../utils");
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
var ColumnDropTargets = exports.ColumnDropTargets = function ColumnDropTargets(_ref) {
|
|
16
|
+
var _rowHeights$;
|
|
17
|
+
var editorView = _ref.editorView,
|
|
18
|
+
tableRef = _ref.tableRef,
|
|
19
|
+
tableHeight = _ref.tableHeight,
|
|
20
|
+
stickyTop = _ref.stickyTop,
|
|
21
|
+
localId = _ref.localId;
|
|
22
|
+
var colWidths = (0, _utils.getColumnsWidths)(editorView);
|
|
23
|
+
var rowHeights = (0, _react.useMemo)(function () {
|
|
24
|
+
// NOTE: we don't care so much as to what tableHeight is, we only care that it changed and is a sane value.
|
|
25
|
+
if (tableRef && !!tableHeight) {
|
|
26
|
+
return (0, _utils.getRowHeights)(tableRef);
|
|
27
|
+
}
|
|
28
|
+
return [0];
|
|
29
|
+
}, [tableRef, tableHeight]);
|
|
30
|
+
if (!tableRef) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
var firstRow = tableRef.querySelector('tr');
|
|
34
|
+
var hasHeaderRow = firstRow ? firstRow.getAttribute('data-header-row') : false;
|
|
35
|
+
var marginTop = hasHeaderRow && stickyTop !== undefined ? (_rowHeights$ = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights[0]) !== null && _rowHeights$ !== void 0 ? _rowHeights$ : 0 : 0;
|
|
36
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
37
|
+
className: _types.TableCssClassName.COLUMN_DROP_TARGET_CONTROLS
|
|
38
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
39
|
+
className: _types.TableCssClassName.COLUMN_CONTROLS_INNER,
|
|
40
|
+
"data-testid": "table-floating-column-controls-drop-targets"
|
|
41
|
+
}, colWidths.map(function (width, index) {
|
|
42
|
+
return /*#__PURE__*/_react.default.createElement(ColumnDropTarget, {
|
|
43
|
+
key: index,
|
|
44
|
+
index: index,
|
|
45
|
+
localId: localId,
|
|
46
|
+
width: width,
|
|
47
|
+
height: tableHeight,
|
|
48
|
+
marginTop: marginTop
|
|
49
|
+
});
|
|
50
|
+
})));
|
|
51
|
+
};
|
|
52
|
+
var _default = exports.default = ColumnDropTargets;
|
|
53
|
+
var ColumnDropTarget = function ColumnDropTarget(_ref2) {
|
|
54
|
+
var index = _ref2.index,
|
|
55
|
+
localId = _ref2.localId,
|
|
56
|
+
width = _ref2.width,
|
|
57
|
+
height = _ref2.height,
|
|
58
|
+
marginTop = _ref2.marginTop;
|
|
59
|
+
var dropTargetRef = (0, _react.useRef)(null);
|
|
60
|
+
(0, _react.useEffect)(function () {
|
|
61
|
+
if (!dropTargetRef.current) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return (0, _element.dropTargetForElements)({
|
|
65
|
+
element: dropTargetRef.current,
|
|
66
|
+
canDrop: function canDrop(_ref3) {
|
|
67
|
+
var _data$indexes, _data$indexes2;
|
|
68
|
+
var source = _ref3.source;
|
|
69
|
+
var data = source.data;
|
|
70
|
+
return (
|
|
71
|
+
// Only draggables of row type can be dropped on this target
|
|
72
|
+
data.type === 'table-column' &&
|
|
73
|
+
// Only draggables which came from the same table can be dropped on this target
|
|
74
|
+
data.localId === localId &&
|
|
75
|
+
// Only draggables which DO NOT include this drop targets index can be dropped
|
|
76
|
+
!!((_data$indexes = data.indexes) !== null && _data$indexes !== void 0 && _data$indexes.length) && ((_data$indexes2 = data.indexes) === null || _data$indexes2 === void 0 ? void 0 : _data$indexes2.indexOf(index)) === -1
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
getData: function getData(_ref4) {
|
|
80
|
+
var input = _ref4.input,
|
|
81
|
+
element = _ref4.element;
|
|
82
|
+
var data = {
|
|
83
|
+
localId: localId,
|
|
84
|
+
type: 'table-column',
|
|
85
|
+
targetIndex: index
|
|
86
|
+
};
|
|
87
|
+
return (0, _closestEdge.attachClosestEdge)(data, {
|
|
88
|
+
input: input,
|
|
89
|
+
element: element,
|
|
90
|
+
allowedEdges: ['left', 'right']
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}, [index, localId]);
|
|
95
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
96
|
+
ref: dropTargetRef,
|
|
97
|
+
style: {
|
|
98
|
+
width: width && "".concat(width - 1, "px"),
|
|
99
|
+
height: height && "".concat(height, "px"),
|
|
100
|
+
marginTop: marginTop && "".concat(marginTop, "px")
|
|
101
|
+
},
|
|
102
|
+
"data-drop-target-index": index,
|
|
103
|
+
"data-drop-target-localid": localId,
|
|
104
|
+
"data-testid": "table-floating-column-controls-drop-target"
|
|
105
|
+
});
|
|
106
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = exports.TableFloatingColumnControls = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _editorTables = require("@atlaskit/editor-tables");
|
|
12
|
+
var _ColumnDropTargets = require("./ColumnDropTargets");
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
18
|
+
var TableFloatingColumnControls = exports.TableFloatingColumnControls = function TableFloatingColumnControls(_ref) {
|
|
19
|
+
var editorView = _ref.editorView,
|
|
20
|
+
tableRef = _ref.tableRef,
|
|
21
|
+
tableActive = _ref.tableActive,
|
|
22
|
+
hasHeaderRow = _ref.hasHeaderRow,
|
|
23
|
+
stickyHeader = _ref.stickyHeader,
|
|
24
|
+
selection = _ref.selection;
|
|
25
|
+
var _useState = (0, _react.useState)({
|
|
26
|
+
width: 0,
|
|
27
|
+
height: 0
|
|
28
|
+
}),
|
|
29
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
30
|
+
tableRect = _useState2[0],
|
|
31
|
+
setTableRect = _useState2[1];
|
|
32
|
+
(0, _react.useEffect)(function () {
|
|
33
|
+
var _window;
|
|
34
|
+
if (tableRef && (_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
|
|
35
|
+
var resizeObserver = new ResizeObserver(function (entries) {
|
|
36
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
37
|
+
_step;
|
|
38
|
+
try {
|
|
39
|
+
var _loop = function _loop() {
|
|
40
|
+
var entry = _step.value;
|
|
41
|
+
setTableRect(function (prev) {
|
|
42
|
+
if (prev.width !== entry.contentRect.width || prev.height !== entry.contentRect.height) {
|
|
43
|
+
return entry.contentRect;
|
|
44
|
+
}
|
|
45
|
+
return prev;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
49
|
+
_loop();
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
_iterator.e(err);
|
|
53
|
+
} finally {
|
|
54
|
+
_iterator.f();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
resizeObserver.observe(tableRef);
|
|
58
|
+
return function () {
|
|
59
|
+
resizeObserver.disconnect();
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}, [tableRef]);
|
|
63
|
+
var selectedLocalId = (0, _react.useMemo)(function () {
|
|
64
|
+
if (!selection) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
var tableNode = (0, _editorTables.findTable)(selection);
|
|
68
|
+
if (!tableNode) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return tableNode.node.attrs.localId;
|
|
72
|
+
}, [selection]);
|
|
73
|
+
if (!tableRef) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
var stickyTop = stickyHeader && stickyHeader.sticky && hasHeaderRow ? stickyHeader.top : undefined;
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
78
|
+
onMouseDown: function onMouseDown(e) {
|
|
79
|
+
return e.preventDefault();
|
|
80
|
+
},
|
|
81
|
+
"data-testid": "table-floating-column-controls-wrapper"
|
|
82
|
+
}, tableActive && /*#__PURE__*/_react.default.createElement(_ColumnDropTargets.ColumnDropTargets, {
|
|
83
|
+
editorView: editorView,
|
|
84
|
+
tableRef: tableRef,
|
|
85
|
+
stickyTop: tableActive ? stickyTop : undefined,
|
|
86
|
+
tableHeight: tableRect.height,
|
|
87
|
+
localId: selectedLocalId
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
var _default = exports.default = TableFloatingColumnControls;
|