@atlaskit/editor-plugin-block-controls 17.1.0 → 17.1.2
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 +15 -0
- package/dist/cjs/blockControlsPlugin.js +14 -6
- package/dist/cjs/pm-plugins/main.js +14 -6
- package/dist/cjs/ui/block-controls-surface-context.js +2 -1
- package/dist/cjs/ui/block-controls-surface-drag-handle-registration.js +37 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle-utils.js +45 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle.compiled.css +32 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle.js +296 -0
- package/dist/cjs/ui/block-controls-surface.compiled.css +2 -1
- package/dist/cjs/ui/block-controls-surface.js +49 -24
- package/dist/cjs/ui/consts.js +2 -1
- package/dist/cjs/ui/surface-editor-view-context.js +12 -0
- package/dist/cjs/ui/use-block-controls-surface-drag-source.js +172 -0
- package/dist/cjs/ui/utils/get-surface-placement.js +8 -1
- package/dist/es2019/blockControlsPlugin.js +13 -6
- package/dist/es2019/pm-plugins/main.js +14 -7
- package/dist/es2019/ui/block-controls-surface-context.js +2 -2
- package/dist/es2019/ui/block-controls-surface-drag-handle-registration.js +26 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle-utils.js +33 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle.compiled.css +32 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle.js +282 -0
- package/dist/es2019/ui/block-controls-surface.compiled.css +2 -1
- package/dist/es2019/ui/block-controls-surface.js +48 -22
- package/dist/es2019/ui/consts.js +1 -0
- package/dist/es2019/ui/surface-editor-view-context.js +4 -0
- package/dist/es2019/ui/use-block-controls-surface-drag-source.js +170 -0
- package/dist/es2019/ui/utils/get-surface-placement.js +15 -6
- package/dist/esm/blockControlsPlugin.js +14 -6
- package/dist/esm/pm-plugins/main.js +14 -6
- package/dist/esm/ui/block-controls-surface-context.js +2 -1
- package/dist/esm/ui/block-controls-surface-drag-handle-registration.js +30 -0
- package/dist/esm/ui/block-controls-surface-drag-handle-utils.js +38 -0
- package/dist/esm/ui/block-controls-surface-drag-handle.compiled.css +32 -0
- package/dist/esm/ui/block-controls-surface-drag-handle.js +290 -0
- package/dist/esm/ui/block-controls-surface.compiled.css +2 -1
- package/dist/esm/ui/block-controls-surface.js +49 -24
- package/dist/esm/ui/consts.js +1 -0
- package/dist/esm/ui/surface-editor-view-context.js +6 -0
- package/dist/esm/ui/use-block-controls-surface-drag-source.js +166 -0
- package/dist/esm/ui/utils/get-surface-placement.js +9 -2
- package/dist/types/pm-plugins/main.d.ts +6 -1
- package/dist/types/ui/block-controls-surface-context.d.ts +1 -1
- package/dist/types/ui/block-controls-surface-drag-handle-registration.d.ts +6 -0
- package/dist/types/ui/block-controls-surface-drag-handle-utils.d.ts +14 -0
- package/dist/types/ui/block-controls-surface-drag-handle.d.ts +10 -0
- package/dist/types/ui/block-controls-surface.d.ts +1 -0
- package/dist/types/ui/consts.d.ts +1 -0
- package/dist/types/ui/surface-editor-view-context.d.ts +5 -0
- package/dist/types/ui/use-block-controls-surface-drag-source.d.ts +19 -0
- package/dist/types/ui/utils/get-surface-placement.d.ts +1 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 17.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e62dacf4416fd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e62dacf4416fd) -
|
|
8
|
+
Add the shared popup-anchor contract, registry-backed drag handle, and menu integrations behind
|
|
9
|
+
`platform_editor_block_control_migration`.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 17.1.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 17.1.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.blockControlsPlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
10
|
var _react = _interopRequireDefault(require("react"));
|
|
10
11
|
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
11
12
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
@@ -31,7 +32,9 @@ var _pmPlugin2 = require("./pm-plugins/selection-preservation/pm-plugin");
|
|
|
31
32
|
var _expandAndUpdateSelection2 = require("./pm-plugins/utils/expand-and-update-selection");
|
|
32
33
|
var _getSelection = require("./pm-plugins/utils/getSelection");
|
|
33
34
|
var _blockControlsSurface = require("./ui/block-controls-surface");
|
|
35
|
+
var _blockControlsSurfaceDragHandleRegistration = require("./ui/block-controls-surface-drag-handle-registration");
|
|
34
36
|
var _globalStyles = require("./ui/global-styles");
|
|
37
|
+
var _surfaceEditorViewContext = require("./ui/surface-editor-view-context");
|
|
35
38
|
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; }
|
|
36
39
|
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; }
|
|
37
40
|
var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
@@ -41,8 +44,9 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
41
44
|
var nodeDecorationRegistry = [];
|
|
42
45
|
var rightSideControlsEnabled = (_config$rightSideCont = config === null || config === void 0 ? void 0 : config.rightSideControlsEnabled) !== null && _config$rightSideCont !== void 0 ? _config$rightSideCont : false;
|
|
43
46
|
var quickInsertButtonEnabled = (_config$quickInsertBu = config === null || config === void 0 ? void 0 : config.quickInsertButtonEnabled) !== null && _config$quickInsertBu !== void 0 ? _config$quickInsertBu : true;
|
|
44
|
-
var
|
|
45
|
-
|
|
47
|
+
var registryBlockControlsEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration');
|
|
48
|
+
var legacyBlockControlsEnabled = !registryBlockControlsEnabled;
|
|
49
|
+
if (registryBlockControlsEnabled) {
|
|
46
50
|
var _api$uiControlRegistr;
|
|
47
51
|
api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register([_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, _objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_LEFT_SECTION), {}, {
|
|
48
52
|
parents: [_objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE), {}, {
|
|
@@ -52,7 +56,9 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
52
56
|
parents: [_objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_LEFT_SECTION), {}, {
|
|
53
57
|
rank: 100
|
|
54
58
|
})]
|
|
55
|
-
})])
|
|
59
|
+
})].concat((0, _toConsumableArray2.default)((0, _blockControlsSurfaceDragHandleRegistration.getBlockControlsSurfaceDragHandleComponents)({
|
|
60
|
+
api: api
|
|
61
|
+
}))));
|
|
56
62
|
}
|
|
57
63
|
return {
|
|
58
64
|
name: 'blockControls',
|
|
@@ -122,7 +128,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
122
128
|
plugin: function plugin(_ref2) {
|
|
123
129
|
var getIntl = _ref2.getIntl,
|
|
124
130
|
nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
|
|
125
|
-
return (0, _main.createPlugin)(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled &&
|
|
131
|
+
return (0, _main.createPlugin)(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled && legacyBlockControlsEnabled, legacyBlockControlsEnabled);
|
|
126
132
|
}
|
|
127
133
|
}];
|
|
128
134
|
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
@@ -441,10 +447,12 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
441
447
|
var editorView = _ref0.editorView;
|
|
442
448
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_globalStyles.GlobalStylesWrapper, {
|
|
443
449
|
api: api
|
|
444
|
-
}),
|
|
450
|
+
}), registryBlockControlsEnabled && editorView && api ? /*#__PURE__*/_react.default.createElement(_surfaceEditorViewContext.SurfaceEditorViewContext.Provider, {
|
|
451
|
+
value: editorView
|
|
452
|
+
}, /*#__PURE__*/_react.default.createElement(_blockControlsSurface.BlockControlsSurface, {
|
|
445
453
|
api: api,
|
|
446
454
|
editorView: editorView
|
|
447
|
-
}) : null);
|
|
455
|
+
})) : null);
|
|
448
456
|
}
|
|
449
457
|
};
|
|
450
458
|
};
|
|
@@ -25,6 +25,7 @@ var _combine = require("@atlaskit/pragmatic-drag-and-drop/utils/combine");
|
|
|
25
25
|
var _elementAdapter = require("@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter");
|
|
26
26
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
27
27
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
28
|
+
var _consts = require("../ui/consts");
|
|
28
29
|
var _domAttrName = require("../ui/utils/dom-attr-name");
|
|
29
30
|
var _decorationsAnchor = require("./decorations-anchor");
|
|
30
31
|
var _decorationsDragHandle = require("./decorations-drag-handle");
|
|
@@ -508,7 +509,8 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
508
509
|
}
|
|
509
510
|
} else if (api) {
|
|
510
511
|
var _latestActiveNode5, _latestActiveNode10;
|
|
511
|
-
|
|
512
|
+
// The registry surface replaces the legacy drag-handle decorations during migration.
|
|
513
|
+
if (flags.legacyDragHandleEnabled && shouldRecreateHandle && (!rightSideControlsEnabled || !isViewMode)) {
|
|
512
514
|
var _activeNode11, _activeNode12, _latestActiveNode, _latestActiveNode2, _latestActiveNode3, _latestActiveNode4;
|
|
513
515
|
var _oldHandle = (0, _decorationsDragHandle.findHandleDec)(decorations, (_activeNode11 = activeNode) === null || _activeNode11 === void 0 ? void 0 : _activeNode11.pos, (_activeNode12 = activeNode) === null || _activeNode12 === void 0 ? void 0 : _activeNode12.pos);
|
|
514
516
|
decorations = decorations.remove(_oldHandle);
|
|
@@ -525,7 +527,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
525
527
|
});
|
|
526
528
|
decorations = decorations.add(newState.doc, [handleDec]);
|
|
527
529
|
}
|
|
528
|
-
if ((0, _expValEquals.expValEquals)('platform_editor_controls_reliable_anchor', 'isEnabled', true) && latestActiveNode) {
|
|
530
|
+
if (flags.legacyDragHandleEnabled && (0, _expValEquals.expValEquals)('platform_editor_controls_reliable_anchor', 'isEnabled', true) && latestActiveNode) {
|
|
529
531
|
// Recreate the drag handle node decoration when the active node changed,
|
|
530
532
|
// its content was modified, or the document changed (e.g. Enter splits a node).
|
|
531
533
|
// This runs independently of shouldRecreateHandle so that doc changes (like pressing
|
|
@@ -800,11 +802,13 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
800
802
|
// remove isEmptyDoc check and let decorations render and determine their own visibility
|
|
801
803
|
// In view mode with right-side controls we render node decorations (right-edge button), not the
|
|
802
804
|
// handle - so findHandleDec is always empty. Don't clear activeNode in that case.
|
|
803
|
-
var hasHandleOrViewModeControls = (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.pos, (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.pos).length > 0 || isViewMode && rightSideControlsEnabled;
|
|
804
|
-
|
|
805
|
+
var hasHandleOrViewModeControls = (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode11 = latestActiveNode) === null || _latestActiveNode11 === void 0 ? void 0 : _latestActiveNode11.pos, (_latestActiveNode12 = latestActiveNode) === null || _latestActiveNode12 === void 0 ? void 0 : _latestActiveNode12.pos).length > 0 || isViewMode && rightSideControlsEnabled || !flags.legacyDragHandleEnabled;
|
|
806
|
+
// Keep the registry surface mounted while its Block Menu owns focus.
|
|
807
|
+
var keepActiveNodeForOpenBlockMenu = !flags.legacyDragHandleEnabled && isMenuOpen && (0, _experiments.editorExperiment)('platform_editor_block_menu', true);
|
|
808
|
+
newActiveNode = meta !== null && meta !== void 0 && meta.editorBlurred && !keepActiveNodeForOpenBlockMenu || !(meta !== null && meta !== void 0 && meta.activeNode) && !hasHandleOrViewModeControls ? null : latestActiveNode;
|
|
805
809
|
} else {
|
|
806
810
|
var _latestActiveNode13, _latestActiveNode14;
|
|
807
|
-
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.pos, (_latestActiveNode14 = latestActiveNode) === null || _latestActiveNode14 === void 0 ? void 0 : _latestActiveNode14.pos).length === 0 ? null : latestActiveNode;
|
|
811
|
+
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && flags.legacyDragHandleEnabled && (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.pos, (_latestActiveNode14 = latestActiveNode) === null || _latestActiveNode14 === void 0 ? void 0 : _latestActiveNode14.pos).length === 0 ? null : latestActiveNode;
|
|
808
812
|
}
|
|
809
813
|
var isMenuOpenNew = isMenuOpen;
|
|
810
814
|
if ((0, _experiments.editorExperiment)('platform_editor_block_menu', true)) {
|
|
@@ -851,6 +855,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
851
855
|
var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
|
|
852
856
|
var rightSideControlsEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
853
857
|
var quickInsertButtonEnabled = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
|
|
858
|
+
var legacyDragHandleEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
|
|
854
859
|
var _getIntl = getIntl(),
|
|
855
860
|
formatMessage = _getIntl.formatMessage;
|
|
856
861
|
var isAdvancedLayoutEnabled = (0, _experiments.editorExperiment)('advanced_layouts', true, {
|
|
@@ -858,6 +863,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
858
863
|
});
|
|
859
864
|
var toolbarFlagsEnabled = (0, _toolbarFlagCheck.areToolbarFlagsEnabled)(Boolean(api === null || api === void 0 ? void 0 : api.toolbar));
|
|
860
865
|
var flags = {
|
|
866
|
+
legacyDragHandleEnabled: legacyDragHandleEnabled,
|
|
861
867
|
toolbarFlagsEnabled: toolbarFlagsEnabled
|
|
862
868
|
};
|
|
863
869
|
var anchorRectCache;
|
|
@@ -1103,11 +1109,13 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
1103
1109
|
}
|
|
1104
1110
|
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
1105
1111
|
var _api$core2;
|
|
1112
|
+
// Focus moving into the registry surface remains inside the editor experience.
|
|
1113
|
+
var isChildOfSurface = !flags.legacyDragHandleEnabled && event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest(_consts.BLOCK_CONTROLS_SURFACE_SELECTOR) !== null;
|
|
1106
1114
|
var isChildOfEditor = event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest("#".concat(_ui.EDIT_AREA_ID)) !== null;
|
|
1107
1115
|
|
|
1108
1116
|
// don't do anything if the event relatedTarget (the element receiving focus) is a child of the editor
|
|
1109
1117
|
// or if the editor has focus
|
|
1110
|
-
if (isChildOfEditor || view.hasFocus()) {
|
|
1118
|
+
if (isChildOfEditor || isChildOfSurface || view.hasFocus()) {
|
|
1111
1119
|
return false;
|
|
1112
1120
|
}
|
|
1113
1121
|
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref6) {
|
|
@@ -38,6 +38,7 @@ var getNodeContext = function getNodeContext(view, pos) {
|
|
|
38
38
|
};
|
|
39
39
|
var createBlockControlsSurfaceContext = exports.createBlockControlsSurfaceContext = function createBlockControlsSurfaceContext(view, activeNode) {
|
|
40
40
|
var _activeNode$rootPos, _activeNode$rootNodeT;
|
|
41
|
+
var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'root';
|
|
41
42
|
if (!activeNode) {
|
|
42
43
|
return undefined;
|
|
43
44
|
}
|
|
@@ -55,6 +56,6 @@ var createBlockControlsSurfaceContext = exports.createBlockControlsSurfaceContex
|
|
|
55
56
|
}
|
|
56
57
|
}),
|
|
57
58
|
rootNode: rootNodeContext,
|
|
58
|
-
targetNode: rootNodeContext
|
|
59
|
+
targetNode: target === 'active' ? activeNodeContext : rootNodeContext
|
|
59
60
|
};
|
|
60
61
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getBlockControlsSurfaceDragHandleComponents = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
|
|
11
|
+
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
12
|
+
var _blockControlsSurfaceDragHandle = require("./block-controls-surface-drag-handle");
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
var getBlockControlsSurfaceDragHandleComponents = exports.getBlockControlsSurfaceDragHandleComponents = function getBlockControlsSurfaceDragHandleComponents(_ref) {
|
|
16
|
+
var api = _ref.api;
|
|
17
|
+
return [{
|
|
18
|
+
component: function component(_ref2) {
|
|
19
|
+
var surfaceContext = _ref2.surfaceContext;
|
|
20
|
+
return /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceDragHandle.BlockControlsSurfaceDragHandle, {
|
|
21
|
+
api: api,
|
|
22
|
+
surfaceContext: surfaceContext
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
isHidden: function isHidden() {
|
|
26
|
+
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
27
|
+
surfaceContext = _ref3.surfaceContext;
|
|
28
|
+
var context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
|
|
29
|
+
return !(context !== null && context !== void 0 && context.activeNode) || context.targetNode.pos !== context.activeNode.pos;
|
|
30
|
+
},
|
|
31
|
+
key: 'block-controls-drag-handle',
|
|
32
|
+
parents: [_objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_LEFT_GROUP), {}, {
|
|
33
|
+
rank: 200
|
|
34
|
+
})],
|
|
35
|
+
type: 'button'
|
|
36
|
+
}];
|
|
37
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getNodeSpacingForDragPreview = exports.getNodeMarginsForDragPreview = exports.buildLayoutColumnMenuMeta = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
10
|
+
var _consts = require("./consts");
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
var buildLayoutColumnMenuMeta = exports.buildLayoutColumnMenuMeta = function buildLayoutColumnMenuMeta(anchorPos, openedViaKeyboard) {
|
|
14
|
+
return _objectSpread(_objectSpread({
|
|
15
|
+
anchorPos: anchorPos
|
|
16
|
+
}, (0, _fg.fg)('platform_editor_layout_column_menu_kill_switch_1') ? {
|
|
17
|
+
isOpen: true
|
|
18
|
+
} : {}), {}, {
|
|
19
|
+
openedViaKeyboard: openedViaKeyboard
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var getNodeSpacingForDragPreview = exports.getNodeSpacingForDragPreview = function getNodeSpacingForDragPreview(node) {
|
|
23
|
+
var _spacingBetweenNodesF2;
|
|
24
|
+
if (!node) {
|
|
25
|
+
return _consts.spacingBetweenNodesForPreview.default;
|
|
26
|
+
}
|
|
27
|
+
var nodeTypeName = node.type.name;
|
|
28
|
+
if (nodeTypeName === 'heading') {
|
|
29
|
+
var _spacingBetweenNodesF;
|
|
30
|
+
return (_spacingBetweenNodesF = _consts.spacingBetweenNodesForPreview["heading".concat(node.attrs.level)]) !== null && _spacingBetweenNodesF !== void 0 ? _spacingBetweenNodesF : _consts.spacingBetweenNodesForPreview.default;
|
|
31
|
+
}
|
|
32
|
+
return (_spacingBetweenNodesF2 = _consts.spacingBetweenNodesForPreview[nodeTypeName]) !== null && _spacingBetweenNodesF2 !== void 0 ? _spacingBetweenNodesF2 : _consts.spacingBetweenNodesForPreview.default;
|
|
33
|
+
};
|
|
34
|
+
var getNodeMarginsForDragPreview = exports.getNodeMarginsForDragPreview = function getNodeMarginsForDragPreview(node) {
|
|
35
|
+
var _nodeMargins$nodeType;
|
|
36
|
+
if (!node) {
|
|
37
|
+
return _consts.nodeMargins.default;
|
|
38
|
+
}
|
|
39
|
+
var nodeTypeName = node.type.name;
|
|
40
|
+
if (nodeTypeName === 'heading') {
|
|
41
|
+
var _nodeMargins;
|
|
42
|
+
return (_nodeMargins = _consts.nodeMargins["heading".concat(node.attrs.level)]) !== null && _nodeMargins !== void 0 ? _nodeMargins : _consts.nodeMargins.default;
|
|
43
|
+
}
|
|
44
|
+
return (_nodeMargins$nodeType = _consts.nodeMargins[nodeTypeName]) !== null && _nodeMargins$nodeType !== void 0 ? _nodeMargins$nodeType : _consts.nodeMargins.default;
|
|
45
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
._19itglyw{border:none}
|
|
2
|
+
._1a37dfik{outline:var(--ds-border-width-focused,2px) solid var(--ds-border-focused,#4688ec)}
|
|
3
|
+
._2rko1y44{border-radius:4px}._12ji1r31{outline-color:currentColor}
|
|
4
|
+
._12y31o36{outline-width:medium}
|
|
5
|
+
._19bvze3t{padding-left:var(--ds-space-0,0)}
|
|
6
|
+
._1bah1h6o{justify-content:center}
|
|
7
|
+
._1bsb1crf{width:9pt}
|
|
8
|
+
._1bsbx5ub{width:calc(var(--ak-editor-base-font-size)*12/16)}
|
|
9
|
+
._1e0c1txw{display:flex}
|
|
10
|
+
._1p1y1j28::selection{background-color:transparent}
|
|
11
|
+
._1pbyb4wl{z-index:100}
|
|
12
|
+
._1qu2glyw{outline-style:none}
|
|
13
|
+
._2lx21bp4{flex-direction:column}
|
|
14
|
+
._4cvr1h6o{align-items:center}
|
|
15
|
+
._4t3i1myc{height:calc(var(--ak-editor-base-font-size)*24/16)}
|
|
16
|
+
._4t3i1tcg{height:24px}
|
|
17
|
+
._80om1qgj{cursor:grab}
|
|
18
|
+
._bfhk15s3{background-color:var(--ds-background-selected,#e9f2fe)}
|
|
19
|
+
._bfhksm61{background-color:var(--ds-background-neutral-subtle,#00000000)}
|
|
20
|
+
._ca0qze3t{padding-top:var(--ds-space-0,0)}
|
|
21
|
+
._cun91j28:disabled{background-color:transparent}
|
|
22
|
+
._n3tdze3t{padding-bottom:var(--ds-space-0,0)}
|
|
23
|
+
._syazdgkc{color:var(--ds-icon-subtle,#505258)}
|
|
24
|
+
._syazxl6c{color:var(--ds-icon-selected,#1868db)}
|
|
25
|
+
._t9ec14w8{transform:rotate(90deg)}
|
|
26
|
+
._u5f3ze3t{padding-right:var(--ds-space-0,0)}
|
|
27
|
+
._vbqb2sac:disabled{color:var(--ds-icon-disabled,#080f214a)}
|
|
28
|
+
._vchhusvi{box-sizing:border-box}
|
|
29
|
+
._1ygbdfik:focus-visible{outline:var(--ds-border-width-focused,2px) solid var(--ds-border-focused,#4688ec)}
|
|
30
|
+
._6g80187o:disabled:hover{background-color:var(--ds-background-disabled,#0515240f)}
|
|
31
|
+
._irr31dpa:hover{background-color:var(--ds-background-neutral-subtle-hovered,#0515240f)}
|
|
32
|
+
._1di6fcek:active{background-color:var(--ds-background-neutral-subtle-pressed,#0b120e24)}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/* block-controls-surface-drag-handle.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.BlockControlsSurfaceDragHandle = void 0;
|
|
10
|
+
require("./block-controls-surface-drag-handle.compiled.css");
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var React = _react;
|
|
13
|
+
var _runtime = require("@compiled/react/runtime");
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
+
var _reactIntl = require("react-intl");
|
|
16
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
17
|
+
var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
|
|
18
|
+
var _surfaceDragHandleElement = require("@atlaskit/editor-common/block-controls/surface-drag-handle-element");
|
|
19
|
+
var _browser = require("@atlaskit/editor-common/browser");
|
|
20
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
21
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
22
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
23
|
+
var _dragHandleVertical = _interopRequireDefault(require("@atlaskit/icon/core/drag-handle-vertical"));
|
|
24
|
+
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
25
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
26
|
+
var _Tooltip = _interopRequireDefault(require("@atlaskit/tooltip/Tooltip"));
|
|
27
|
+
var _pluginKey = require("../pm-plugins/selection-preservation/plugin-key");
|
|
28
|
+
var _expandAndUpdateSelection = require("../pm-plugins/utils/expand-and-update-selection");
|
|
29
|
+
var _getSelection = require("../pm-plugins/utils/getSelection");
|
|
30
|
+
var _blockControlsSurfaceDragHandleUtils = require("./block-controls-surface-drag-handle-utils");
|
|
31
|
+
var _consts = require("./consts");
|
|
32
|
+
var _dragHandleNestedIcon = require("./drag-handle-nested-icon");
|
|
33
|
+
var _shouldUseNestedDragHandleIcon = require("./should-use-nested-drag-handle-icon");
|
|
34
|
+
var _surfaceEditorViewContext = require("./surface-editor-view-context");
|
|
35
|
+
var _useBlockControlsSurfaceDragSource = require("./use-block-controls-surface-drag-source");
|
|
36
|
+
var _domAttrName = require("./utils/dom-attr-name");
|
|
37
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
38
|
+
// oxlint-disable-next-line typescript/consistent-type-imports -- jsx is the runtime factory for the classic JSX pragma above.
|
|
39
|
+
// Keep style values co-located for Compiled while matching the legacy drag handle dimensions.
|
|
40
|
+
var SURFACE_DRAG_HANDLE_HEIGHT = 24;
|
|
41
|
+
var SURFACE_DRAG_HANDLE_WIDTH = 12;
|
|
42
|
+
var SURFACE_DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
43
|
+
var SURFACE_DRAG_HANDLE_Z_INDEX = 100;
|
|
44
|
+
var dragHandleStyles = {
|
|
45
|
+
root: "_19itglyw _2rko1y44 _12ji1r31 _1qu2glyw _12y31o36 _1e0c1txw _vchhusvi _2lx21bp4 _4cvr1h6o _1bah1h6o _4t3i1tcg _1bsb1crf _bfhksm61 _syazdgkc _80om1qgj _1pbyb4wl _ca0qze3t _u5f3ze3t _n3tdze3t _19bvze3t _cun91j28 _vbqb2sac _1ygbdfik _irr31dpa _6g80187o _1di6fcek",
|
|
46
|
+
scaled: "_4t3i1myc _1bsbx5ub",
|
|
47
|
+
selected: "_bfhk15s3 _syazxl6c",
|
|
48
|
+
keyboardFocused: "_1a37dfik",
|
|
49
|
+
firefoxSelection: "_1p1y1j28",
|
|
50
|
+
layoutColumn: "_t9ec14w8",
|
|
51
|
+
iconWrapper: "_1e0c1txw _4cvr1h6o _1bah1h6o"
|
|
52
|
+
};
|
|
53
|
+
var handleIconDragStart = function handleIconDragStart(event) {
|
|
54
|
+
var _event$currentTarget$;
|
|
55
|
+
if (!(0, _browser.getBrowserInfo)().chrome) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
event.stopPropagation();
|
|
59
|
+
(_event$currentTarget$ = event.currentTarget.parentElement) === null || _event$currentTarget$ === void 0 || _event$currentTarget$.dispatchEvent(new DragEvent('dragstart', {
|
|
60
|
+
bubbles: true,
|
|
61
|
+
cancelable: true,
|
|
62
|
+
dataTransfer: event.dataTransfer
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
var isSelected = function isSelected(selection, pos, view) {
|
|
66
|
+
if (typeof pos !== 'number' || !selection || !view) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return (0, _getSelection.isHandleCorrelatedToSelection)(view.state, selection, pos);
|
|
70
|
+
};
|
|
71
|
+
var BlockControlsSurfaceDragHandle = exports.BlockControlsSurfaceDragHandle = function BlockControlsSurfaceDragHandle(_ref) {
|
|
72
|
+
var _activeNode$type$name;
|
|
73
|
+
var api = _ref.api,
|
|
74
|
+
surfaceContext = _ref.surfaceContext;
|
|
75
|
+
var _useIntl = (0, _reactIntl.useIntl)(),
|
|
76
|
+
formatMessage = _useIntl.formatMessage;
|
|
77
|
+
var view = (0, _surfaceEditorViewContext.useSurfaceEditorView)();
|
|
78
|
+
var context = surfaceContext === null || surfaceContext === void 0 ? void 0 : surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
|
|
79
|
+
var activeNode = context === null || context === void 0 ? void 0 : context.activeNode;
|
|
80
|
+
var pos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
81
|
+
var nodeType = (_activeNode$type$name = activeNode === null || activeNode === void 0 ? void 0 : activeNode.type.name) !== null && _activeNode$type$name !== void 0 ? _activeNode$type$name : '';
|
|
82
|
+
var buttonRef = (0, _react.useRef)(null);
|
|
83
|
+
var posRef = (0, _react.useRef)(pos);
|
|
84
|
+
posRef.current = pos;
|
|
85
|
+
var getPos = (0, _react.useCallback)(function () {
|
|
86
|
+
return posRef.current;
|
|
87
|
+
}, []);
|
|
88
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls', 'interaction', 'selection'], function (states) {
|
|
89
|
+
var _states$blockControls, _states$blockControls2, _states$interactionSt, _states$blockControls3, _states$selectionStat;
|
|
90
|
+
return {
|
|
91
|
+
activeNodeAnchorName: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 || (_states$blockControls = _states$blockControls.activeNode) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.anchorName,
|
|
92
|
+
handleOptions: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 || (_states$blockControls2 = _states$blockControls2.activeNode) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.handleOptions,
|
|
93
|
+
interactionState: (_states$interactionSt = states.interactionState) === null || _states$interactionSt === void 0 ? void 0 : _states$interactionSt.interactionState,
|
|
94
|
+
isShiftDown: (_states$blockControls3 = states.blockControlsState) === null || _states$blockControls3 === void 0 ? void 0 : _states$blockControls3.isShiftDown,
|
|
95
|
+
selection: (_states$selectionStat = states.selectionState) === null || _states$selectionStat === void 0 ? void 0 : _states$selectionStat.selection
|
|
96
|
+
};
|
|
97
|
+
}),
|
|
98
|
+
activeNodeAnchorName = _useSharedPluginState.activeNodeAnchorName,
|
|
99
|
+
handleOptions = _useSharedPluginState.handleOptions,
|
|
100
|
+
interactionState = _useSharedPluginState.interactionState,
|
|
101
|
+
isShiftDown = _useSharedPluginState.isShiftDown,
|
|
102
|
+
selection = _useSharedPluginState.selection;
|
|
103
|
+
var _useState = (0, _react.useState)(false),
|
|
104
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
105
|
+
dragHandleSelected = _useState2[0],
|
|
106
|
+
setDragHandleSelected = _useState2[1];
|
|
107
|
+
(0, _react.useEffect)(function () {
|
|
108
|
+
setDragHandleSelected(isSelected(selection, pos, view));
|
|
109
|
+
}, [pos, selection, view]);
|
|
110
|
+
var isLayoutColumn = nodeType === 'layoutColumn';
|
|
111
|
+
var isTopLevelNode = (activeNode === null || activeNode === void 0 ? void 0 : activeNode.parentType) === 'doc';
|
|
112
|
+
var isDisabled = (0, _react.useMemo)(function () {
|
|
113
|
+
var _api$blockControls$sh;
|
|
114
|
+
if (!isShiftDown || !view || view.state.selection.empty || !(0, _fg.fg)('platform_editor_elements_dnd_shift_click_select')) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (isLayoutColumn && (0, _expValEquals.expValEquals)('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
var multiSelect = api === null || api === void 0 || (_api$blockControls$sh = api.blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.multiSelectDnD;
|
|
121
|
+
var $anchor = (multiSelect === null || multiSelect === void 0 ? void 0 : multiSelect.anchor) !== undefined ? view.state.doc.resolve(multiSelect.anchor) : view.state.selection.$anchor;
|
|
122
|
+
return !isTopLevelNode || $anchor.depth > _consts.DRAG_HANDLE_MAX_SHIFT_CLICK_DEPTH;
|
|
123
|
+
}, [api, isLayoutColumn, isShiftDown, isTopLevelNode, view]);
|
|
124
|
+
var getAnchorName = (0, _react.useCallback)(function () {
|
|
125
|
+
var _ref2, _ref3, _dom$getAttribute, _dom$closest;
|
|
126
|
+
if (activeNodeAnchorName) {
|
|
127
|
+
return activeNodeAnchorName;
|
|
128
|
+
}
|
|
129
|
+
var currentPos = posRef.current;
|
|
130
|
+
if (!view || currentPos === undefined) {
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
var dom = view.nodeDOM(currentPos);
|
|
134
|
+
if (!(dom instanceof HTMLElement)) {
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
var anchorAttrName = (0, _domAttrName.getAnchorAttrName)();
|
|
138
|
+
return (_ref2 = (_ref3 = (_dom$getAttribute = dom.getAttribute(anchorAttrName)) !== null && _dom$getAttribute !== void 0 ? _dom$getAttribute : dom.getAttribute(_domAttrName.NODE_ANCHOR_ATTR_NAME)) !== null && _ref3 !== void 0 ? _ref3 : (_dom$closest = dom.closest("[".concat(anchorAttrName, "]"))) === null || _dom$closest === void 0 ? void 0 : _dom$closest.getAttribute(anchorAttrName)) !== null && _ref2 !== void 0 ? _ref2 : '';
|
|
139
|
+
}, [activeNodeAnchorName, view]);
|
|
140
|
+
(0, _react.useLayoutEffect)(function () {
|
|
141
|
+
var element = buttonRef.current;
|
|
142
|
+
if (!view || !element) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
_surfaceDragHandleElement.surfaceDragHandleElementStore.set(view, element);
|
|
146
|
+
return function () {
|
|
147
|
+
return _surfaceDragHandleElement.surfaceDragHandleElementStore.release(view, element);
|
|
148
|
+
};
|
|
149
|
+
}, [view]);
|
|
150
|
+
(0, _react.useEffect)(function () {
|
|
151
|
+
if (!(handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused) || !buttonRef.current || !view) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
var animationFrameId;
|
|
155
|
+
var attempts = 0;
|
|
156
|
+
var _focusHandle = function focusHandle() {
|
|
157
|
+
var button = buttonRef.current;
|
|
158
|
+
if (!button) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
button.focus();
|
|
162
|
+
if (button.ownerDocument.activeElement !== button && attempts < 5) {
|
|
163
|
+
attempts++;
|
|
164
|
+
animationFrameId = requestAnimationFrame(_focusHandle);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
_focusHandle();
|
|
168
|
+
return function () {
|
|
169
|
+
if (animationFrameId !== undefined) {
|
|
170
|
+
cancelAnimationFrame(animationFrameId);
|
|
171
|
+
}
|
|
172
|
+
view.focus();
|
|
173
|
+
};
|
|
174
|
+
}, [handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
|
|
175
|
+
(0, _useBlockControlsSurfaceDragSource.useBlockControlsSurfaceDragSource)({
|
|
176
|
+
api: api,
|
|
177
|
+
elementRef: buttonRef,
|
|
178
|
+
getAnchorName: getAnchorName,
|
|
179
|
+
getPos: getPos,
|
|
180
|
+
nodeType: nodeType,
|
|
181
|
+
start: pos,
|
|
182
|
+
view: view
|
|
183
|
+
});
|
|
184
|
+
var handleMouseDown = (0, _react.useCallback)(function () {
|
|
185
|
+
var _api$core, _api$blockControls;
|
|
186
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.setSelectedViaDragHandle(true));
|
|
187
|
+
}, [api]);
|
|
188
|
+
var handleClick = (0, _react.useCallback)(function (event) {
|
|
189
|
+
var _api$core2;
|
|
190
|
+
if (!view || isDisabled) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
var openedViaKeyboard = event.detail === 0;
|
|
194
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref4) {
|
|
195
|
+
var _selectionPreservatio, _selectionPreservatio2, _api$analytics, _resolvedStartPos$nod, _api$blockControls2, _api$blockControls3, _activeNode$rootPos;
|
|
196
|
+
var tr = _ref4.tr;
|
|
197
|
+
var startPos = getPos();
|
|
198
|
+
if (startPos === undefined) {
|
|
199
|
+
return tr;
|
|
200
|
+
}
|
|
201
|
+
if (nodeType === 'layoutColumn' && (0, _expValEquals.expValEquals)('platform_editor_layout_column_menu', 'isEnabled', true)) {
|
|
202
|
+
tr.setMeta('toggleLayoutColumnMenu', (0, _blockControlsSurfaceDragHandleUtils.buildLayoutColumnMenuMeta)(startPos, openedViaKeyboard));
|
|
203
|
+
}
|
|
204
|
+
var selection = (_selectionPreservatio = (_selectionPreservatio2 = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) !== null && _selectionPreservatio !== void 0 ? _selectionPreservatio : tr.selection;
|
|
205
|
+
var resolvedStartPos = tr.doc.resolve(startPos);
|
|
206
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
207
|
+
action: _analytics.ACTION.CLICKED,
|
|
208
|
+
actionSubject: _analytics.ACTION_SUBJECT.BUTTON,
|
|
209
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
210
|
+
attributes: {
|
|
211
|
+
nodeDepth: resolvedStartPos.depth,
|
|
212
|
+
nodeTypes: ((_resolvedStartPos$nod = resolvedStartPos.nodeAfter) === null || _resolvedStartPos$nod === void 0 ? void 0 : _resolvedStartPos$nod.type.name) || ''
|
|
213
|
+
},
|
|
214
|
+
eventType: _analytics.EVENT_TYPE.UI
|
|
215
|
+
})(tr);
|
|
216
|
+
(0, _expandAndUpdateSelection.expandAndUpdateSelection)({
|
|
217
|
+
api: api,
|
|
218
|
+
isShiftPressed: event.shiftKey,
|
|
219
|
+
nodeType: nodeType,
|
|
220
|
+
selection: selection,
|
|
221
|
+
startPos: startPos,
|
|
222
|
+
tr: tr
|
|
223
|
+
});
|
|
224
|
+
api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.startPreservingSelection()({
|
|
225
|
+
tr: tr
|
|
226
|
+
});
|
|
227
|
+
api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.toggleBlockMenu({
|
|
228
|
+
anchorName: getAnchorName(),
|
|
229
|
+
openedViaKeyboard: openedViaKeyboard,
|
|
230
|
+
triggerByNode: {
|
|
231
|
+
nodeType: nodeType,
|
|
232
|
+
pos: startPos,
|
|
233
|
+
rootPos: (_activeNode$rootPos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : resolvedStartPos.before(1)
|
|
234
|
+
}
|
|
235
|
+
})({
|
|
236
|
+
tr: tr
|
|
237
|
+
});
|
|
238
|
+
tr.setMeta('scrollIntoView', false);
|
|
239
|
+
return tr;
|
|
240
|
+
});
|
|
241
|
+
view.focus();
|
|
242
|
+
}, [activeNode === null || activeNode === void 0 ? void 0 : activeNode.rootPos, api, getAnchorName, getPos, isDisabled, nodeType, view]);
|
|
243
|
+
var label = formatMessage(_messages.blockControlsMessages.dragToMoveClickToOpen, {
|
|
244
|
+
br: ' '
|
|
245
|
+
});
|
|
246
|
+
var helpDescriptors = (0, _react.useMemo)(function () {
|
|
247
|
+
return [{
|
|
248
|
+
description: formatMessage(_messages.blockControlsMessages.dragToMoveClickToOpen, {
|
|
249
|
+
br: /*#__PURE__*/React.createElement("br", null)
|
|
250
|
+
})
|
|
251
|
+
}];
|
|
252
|
+
}, [formatMessage]);
|
|
253
|
+
var handleTooltipShow = (0, _react.useCallback)(function () {
|
|
254
|
+
var _api$accessibilityUti;
|
|
255
|
+
api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 || _api$accessibilityUti.actions.ariaNotify(label, {
|
|
256
|
+
priority: 'important'
|
|
257
|
+
});
|
|
258
|
+
}, [api, label]);
|
|
259
|
+
if (!view || !activeNode || pos === undefined) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
var tooltipContent = /*#__PURE__*/React.createElement(_keymaps.TooltipContentWithMultipleShortcuts, {
|
|
263
|
+
helpDescriptors: helpDescriptors
|
|
264
|
+
});
|
|
265
|
+
var browser = (0, _browser.getBrowserInfo)();
|
|
266
|
+
var button = /*#__PURE__*/React.createElement("button", {
|
|
267
|
+
ref: buttonRef,
|
|
268
|
+
type: "button",
|
|
269
|
+
"aria-label": label,
|
|
270
|
+
disabled: isDisabled,
|
|
271
|
+
onClick: handleClick,
|
|
272
|
+
onMouseDown: handleMouseDown
|
|
273
|
+
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop -- Pragmatic DnD owns this native drag source.
|
|
274
|
+
,
|
|
275
|
+
onDrop: function onDrop(event) {
|
|
276
|
+
return event.stopPropagation();
|
|
277
|
+
},
|
|
278
|
+
"data-editor-block-ctrl-drag-handle": true,
|
|
279
|
+
"data-blocks-drag-handle": (0, _fg.fg)('confluence_remix_button_right_side_block_fg') || undefined,
|
|
280
|
+
"data-testid": "block-controls-surface-drag-handle",
|
|
281
|
+
className: (0, _runtime.ax)([dragHandleStyles.root, browser.gecko && dragHandleStyles.firefoxSelection, isLayoutColumn && dragHandleStyles.layoutColumn, dragHandleSelected && interactionState !== 'hasNotHadInteraction' && dragHandleStyles.selected, (handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused) && dragHandleStyles.keyboardFocused, dragHandleStyles.scaled])
|
|
282
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
283
|
+
onDragStart: handleIconDragStart,
|
|
284
|
+
className: (0, _runtime.ax)([dragHandleStyles.iconWrapper])
|
|
285
|
+
}, (0, _shouldUseNestedDragHandleIcon.shouldUseNestedDragHandleIcon)(Boolean(isTopLevelNode), isLayoutColumn) ? /*#__PURE__*/React.createElement(_dragHandleNestedIcon.DragHandleNestedIcon, null) : /*#__PURE__*/React.createElement(_dragHandleVertical.default, {
|
|
286
|
+
label: "",
|
|
287
|
+
size: "small",
|
|
288
|
+
spacing: "spacious"
|
|
289
|
+
})));
|
|
290
|
+
return /*#__PURE__*/React.createElement(_Tooltip.default, {
|
|
291
|
+
position: "top",
|
|
292
|
+
content: tooltipContent,
|
|
293
|
+
ignoreTooltipPointerEvents: true,
|
|
294
|
+
onShow: handleTooltipShow
|
|
295
|
+
}, button);
|
|
296
|
+
};
|