@atlaskit/editor-plugin-paste-options-toolbar 8.4.0 → 8.4.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 +9 -0
- package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +9 -30
- package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
- package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.js +5 -0
- package/dist/cjs/ui/on-paste-actions-menu/hasVisibleButton.js +31 -0
- package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +9 -28
- package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
- package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.js +5 -0
- package/dist/es2019/ui/on-paste-actions-menu/hasVisibleButton.js +19 -0
- package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +9 -30
- package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
- package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.js +5 -0
- package/dist/esm/ui/on-paste-actions-menu/hasVisibleButton.js +25 -0
- package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +3 -5
- package/dist/types/ui/on-paste-actions-menu/hasVisibleButton.d.ts +6 -0
- package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +3 -5
- package/dist/types-ts4.5/ui/on-paste-actions-menu/hasVisibleButton.d.ts +6 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-paste-options-toolbar
|
|
2
2
|
|
|
3
|
+
## 8.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`1a9b3a0f8a1c1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1a9b3a0f8a1c1) -
|
|
8
|
+
[ux] EDITOR-5892 Refactor Paste actions menu to use a single ui controls registry entry and single
|
|
9
|
+
SurfaceRenderer. Tweaked visibility rules and increased test coverage.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
3
12
|
## 8.4.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -13,10 +13,10 @@ var _uiReact = require("@atlaskit/editor-common/ui-react");
|
|
|
13
13
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
14
14
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
15
15
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
16
|
-
var _editorUiControlModel = require("@atlaskit/editor-ui-control-model");
|
|
17
16
|
var _commands = require("../../editor-commands/commands");
|
|
18
17
|
var _types = require("../../types/types");
|
|
19
18
|
var _toolbar2 = require("../toolbar");
|
|
19
|
+
var _hasVisibleButton = require("./hasVisibleButton");
|
|
20
20
|
var _PasteActionsMenuContent = require("./PasteActionsMenuContent");
|
|
21
21
|
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); }
|
|
22
22
|
var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
|
|
@@ -39,20 +39,8 @@ function getPopupOffset(dom) {
|
|
|
39
39
|
var rightEdge = dom.getBoundingClientRect().right;
|
|
40
40
|
return [-(window.innerWidth - rightEdge - 50), 20];
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Returns true when at least one component in the given list would produce
|
|
45
|
-
* visible output (i.e. is not hidden and, for containers, has at least one
|
|
46
|
-
* visible descendant).
|
|
47
|
-
*/
|
|
48
|
-
var hasVisibleComponent = function hasVisibleComponent(components) {
|
|
49
|
-
var childrenMap = (0, _editorUiControlModel.buildChildrenMap)(components);
|
|
50
|
-
return components.some(function (c) {
|
|
51
|
-
return (0, _editorUiControlModel.willComponentRender)(c, childrenMap);
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
42
|
var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
55
|
-
var _api$uiControlRegistr, _api$uiControlRegistr2
|
|
43
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
56
44
|
var api = _ref.api,
|
|
57
45
|
editorView = _ref.editorView,
|
|
58
46
|
mountTo = _ref.mountTo,
|
|
@@ -87,15 +75,13 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
87
75
|
(0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
|
|
88
76
|
}, [lastContentPasted, editorView]);
|
|
89
77
|
var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
|
|
90
|
-
var _pluginState$showTool
|
|
78
|
+
var _pluginState$showTool;
|
|
91
79
|
var pluginState = states.pasteOptionsToolbarPluginState;
|
|
92
80
|
return {
|
|
93
|
-
showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
|
|
94
|
-
showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
|
|
81
|
+
showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
|
|
95
82
|
};
|
|
96
83
|
}),
|
|
97
|
-
isToolbarShown = _useSharedPluginState2.showToolbar
|
|
98
|
-
showLegacyOptions = _useSharedPluginState2.showLegacyOptions;
|
|
84
|
+
isToolbarShown = _useSharedPluginState2.showToolbar;
|
|
99
85
|
var preventEditorFocusLoss = (0, _react.useCallback)(function (e) {
|
|
100
86
|
e.preventDefault();
|
|
101
87
|
}, []);
|
|
@@ -119,17 +105,12 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
119
105
|
handleDismiss();
|
|
120
106
|
}
|
|
121
107
|
}, [handleDismiss]);
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
key: 'ai-paste-menu'
|
|
125
|
-
};
|
|
126
|
-
var aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
127
|
-
var pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(_toolbar.PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
|
|
128
|
-
var anyAiComponentVisible = hasVisibleComponent(aiSurfaceComponents);
|
|
108
|
+
var pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_toolbar.PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
109
|
+
var anyComponentVisible = (0, _hasVisibleButton.hasVisibleButton)(pasteMenuComponents);
|
|
129
110
|
if (!isToolbarShown) {
|
|
130
111
|
return null;
|
|
131
112
|
}
|
|
132
|
-
if (!
|
|
113
|
+
if (!anyComponentVisible) {
|
|
133
114
|
return null;
|
|
134
115
|
}
|
|
135
116
|
var target = getTargetElement(editorView);
|
|
@@ -155,8 +136,6 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
155
136
|
}, /*#__PURE__*/_react.default.createElement(_PasteActionsMenuContent.PasteActionsMenuContent, {
|
|
156
137
|
onMouseDown: preventEditorFocusLoss,
|
|
157
138
|
onMouseEnter: handleMouseEnter,
|
|
158
|
-
|
|
159
|
-
aiSurfaceComponents: aiSurfaceComponents,
|
|
160
|
-
pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
|
|
139
|
+
components: pasteMenuComponents
|
|
161
140
|
}))));
|
|
162
141
|
};
|
|
@@ -9,7 +9,10 @@ exports.PasteActionsMenuContent = void 0;
|
|
|
9
9
|
require("./PasteActionsMenuContent.compiled.css");
|
|
10
10
|
var _runtime = require("@compiled/react/runtime");
|
|
11
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _reactIntlNext = require("react-intl-next");
|
|
13
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
12
14
|
var _uiReact = require("@atlaskit/editor-common/ui-react");
|
|
15
|
+
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
13
16
|
var _editorUiControlModel = require("@atlaskit/editor-ui-control-model");
|
|
14
17
|
var _compiled = require("@atlaskit/primitives/compiled");
|
|
15
18
|
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); }
|
|
@@ -19,23 +22,21 @@ var styles = {
|
|
|
19
22
|
var PasteActionsMenuContent = exports.PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
|
|
20
23
|
var onMouseDown = _ref.onMouseDown,
|
|
21
24
|
onMouseEnter = _ref.onMouseEnter,
|
|
22
|
-
|
|
23
|
-
aiSurfaceComponents = _ref.aiSurfaceComponents,
|
|
24
|
-
pasteSurfaceComponents = _ref.pasteSurfaceComponents;
|
|
25
|
+
components = _ref.components;
|
|
25
26
|
var setOutsideClickTargetRef = (0, _react.useContext)(_uiReact.OutsideClickTargetRefContext);
|
|
27
|
+
var intl = (0, _reactIntlNext.useIntl)();
|
|
26
28
|
return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
|
|
27
29
|
ref: setOutsideClickTargetRef,
|
|
28
30
|
xcss: styles.container,
|
|
29
31
|
onMouseDown: onMouseDown,
|
|
30
32
|
onMouseEnter: onMouseEnter
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
|
|
33
|
+
}, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
34
|
+
title: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteMenuActionsTitle)
|
|
35
|
+
}, /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
|
|
35
36
|
surface: {
|
|
36
37
|
type: 'menu',
|
|
37
38
|
key: 'paste-menu'
|
|
38
39
|
},
|
|
39
|
-
components:
|
|
40
|
-
}));
|
|
40
|
+
components: components
|
|
41
|
+
})));
|
|
41
42
|
};
|
|
@@ -127,6 +127,11 @@ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteM
|
|
|
127
127
|
key: _toolbar.PASTE_MENU.key,
|
|
128
128
|
rank: _toolbar.PASTE_MENU_RANK[_toolbar.PASTE_MENU_SECTION.key]
|
|
129
129
|
}],
|
|
130
|
+
isHidden: function isHidden() {
|
|
131
|
+
var _api$pasteOptionsTool, _pluginState$showLega;
|
|
132
|
+
var pluginState = api === null || api === void 0 || (_api$pasteOptionsTool = api.pasteOptionsToolbarPlugin) === null || _api$pasteOptionsTool === void 0 ? void 0 : _api$pasteOptionsTool.sharedState.currentState();
|
|
133
|
+
return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
|
|
134
|
+
},
|
|
130
135
|
component: function component(props) {
|
|
131
136
|
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
|
|
132
137
|
hasSeparator: true
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasVisibleButton = void 0;
|
|
7
|
+
var _isComponentOrAncestorHidden = function isComponentOrAncestorHidden(component, componentsByKey) {
|
|
8
|
+
var _component$isHidden, _component$parents;
|
|
9
|
+
if ((_component$isHidden = component.isHidden) !== null && _component$isHidden !== void 0 && _component$isHidden.call(component)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return ((_component$parents = component.parents) !== null && _component$parents !== void 0 ? _component$parents : []).some(function (parent) {
|
|
13
|
+
var parentComponent = componentsByKey.get(parent.key);
|
|
14
|
+
return parentComponent ? _isComponentOrAncestorHidden(parentComponent, componentsByKey) : false;
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns true when at least one menu-item button in the list is visible.
|
|
20
|
+
* A button is visible when neither it nor any of its ancestors are hidden.
|
|
21
|
+
*/
|
|
22
|
+
var hasVisibleButton = exports.hasVisibleButton = function hasVisibleButton(components) {
|
|
23
|
+
var componentsByKey = new Map(components.map(function (c) {
|
|
24
|
+
return [c.key, c];
|
|
25
|
+
}));
|
|
26
|
+
return components.filter(function (c) {
|
|
27
|
+
return c.type === 'menu-item';
|
|
28
|
+
}).some(function (c) {
|
|
29
|
+
return !_isComponentOrAncestorHidden(c, componentsByKey);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -6,10 +6,10 @@ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-re
|
|
|
6
6
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
7
7
|
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
8
8
|
import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
|
|
9
|
-
import { buildChildrenMap, willComponentRender } from '@atlaskit/editor-ui-control-model';
|
|
10
9
|
import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
|
|
11
10
|
import { ToolbarDropdownOption } from '../../types/types';
|
|
12
11
|
import { isToolbarVisible } from '../toolbar';
|
|
12
|
+
import { hasVisibleButton } from './hasVisibleButton';
|
|
13
13
|
import { PasteActionsMenuContent } from './PasteActionsMenuContent';
|
|
14
14
|
const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
|
|
15
15
|
function getTargetElement(editorView) {
|
|
@@ -33,16 +33,6 @@ function getPopupOffset(dom) {
|
|
|
33
33
|
const rightEdge = dom.getBoundingClientRect().right;
|
|
34
34
|
return [-(window.innerWidth - rightEdge - 50), 20];
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Returns true when at least one component in the given list would produce
|
|
39
|
-
* visible output (i.e. is not hidden and, for containers, has at least one
|
|
40
|
-
* visible descendant).
|
|
41
|
-
*/
|
|
42
|
-
const hasVisibleComponent = components => {
|
|
43
|
-
const childrenMap = buildChildrenMap(components);
|
|
44
|
-
return components.some(c => willComponentRender(c, childrenMap));
|
|
45
|
-
};
|
|
46
36
|
export const PasteActionsMenu = ({
|
|
47
37
|
api,
|
|
48
38
|
editorView,
|
|
@@ -50,7 +40,7 @@ export const PasteActionsMenu = ({
|
|
|
50
40
|
boundariesElement,
|
|
51
41
|
scrollableElement
|
|
52
42
|
}) => {
|
|
53
|
-
var _api$uiControlRegistr, _api$uiControlRegistr2
|
|
43
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
54
44
|
const {
|
|
55
45
|
lastContentPasted
|
|
56
46
|
} = useSharedPluginStateWithSelector(api, ['paste'], states => {
|
|
@@ -81,14 +71,12 @@ export const PasteActionsMenu = ({
|
|
|
81
71
|
showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
|
|
82
72
|
}, [lastContentPasted, editorView]);
|
|
83
73
|
const {
|
|
84
|
-
showToolbar: isToolbarShown
|
|
85
|
-
showLegacyOptions
|
|
74
|
+
showToolbar: isToolbarShown
|
|
86
75
|
} = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], states => {
|
|
87
|
-
var _pluginState$showTool
|
|
76
|
+
var _pluginState$showTool;
|
|
88
77
|
const pluginState = states.pasteOptionsToolbarPluginState;
|
|
89
78
|
return {
|
|
90
|
-
showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
|
|
91
|
-
showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
|
|
79
|
+
showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
|
|
92
80
|
};
|
|
93
81
|
});
|
|
94
82
|
const preventEditorFocusLoss = useCallback(e => {
|
|
@@ -114,17 +102,12 @@ export const PasteActionsMenu = ({
|
|
|
114
102
|
handleDismiss();
|
|
115
103
|
}
|
|
116
104
|
}, [handleDismiss]);
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
key: 'ai-paste-menu'
|
|
120
|
-
};
|
|
121
|
-
const aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
122
|
-
const pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
|
|
123
|
-
const anyAiComponentVisible = hasVisibleComponent(aiSurfaceComponents);
|
|
105
|
+
const pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
106
|
+
const anyComponentVisible = hasVisibleButton(pasteMenuComponents);
|
|
124
107
|
if (!isToolbarShown) {
|
|
125
108
|
return null;
|
|
126
109
|
}
|
|
127
|
-
if (!
|
|
110
|
+
if (!anyComponentVisible) {
|
|
128
111
|
return null;
|
|
129
112
|
}
|
|
130
113
|
const target = getTargetElement(editorView);
|
|
@@ -150,8 +133,6 @@ export const PasteActionsMenu = ({
|
|
|
150
133
|
}, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
|
|
151
134
|
onMouseDown: preventEditorFocusLoss,
|
|
152
135
|
onMouseEnter: handleMouseEnter,
|
|
153
|
-
|
|
154
|
-
aiSurfaceComponents: aiSurfaceComponents,
|
|
155
|
-
pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
|
|
136
|
+
components: pasteMenuComponents
|
|
156
137
|
}))));
|
|
157
138
|
};
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import "./PasteActionsMenuContent.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
4
|
import React, { useContext } from 'react';
|
|
5
|
+
import { useIntl } from 'react-intl-next';
|
|
6
|
+
import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
7
|
import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
|
|
8
|
+
import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
|
|
6
9
|
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model';
|
|
7
10
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
8
11
|
const styles = {
|
|
@@ -11,24 +14,22 @@ const styles = {
|
|
|
11
14
|
export const PasteActionsMenuContent = ({
|
|
12
15
|
onMouseDown,
|
|
13
16
|
onMouseEnter,
|
|
14
|
-
|
|
15
|
-
aiSurfaceComponents,
|
|
16
|
-
pasteSurfaceComponents
|
|
17
|
+
components
|
|
17
18
|
}) => {
|
|
18
19
|
const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
|
|
20
|
+
const intl = useIntl();
|
|
19
21
|
return /*#__PURE__*/React.createElement(Box, {
|
|
20
22
|
ref: setOutsideClickTargetRef,
|
|
21
23
|
xcss: styles.container,
|
|
22
24
|
onMouseDown: onMouseDown,
|
|
23
25
|
onMouseEnter: onMouseEnter
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
26
|
+
}, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
27
|
+
title: intl.formatMessage(messages.pasteMenuActionsTitle)
|
|
28
|
+
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
28
29
|
surface: {
|
|
29
30
|
type: 'menu',
|
|
30
31
|
key: 'paste-menu'
|
|
31
32
|
},
|
|
32
|
-
components:
|
|
33
|
-
}));
|
|
33
|
+
components: components
|
|
34
|
+
})));
|
|
34
35
|
};
|
|
@@ -122,6 +122,11 @@ export const getPasteMenuComponents = ({
|
|
|
122
122
|
key: PASTE_MENU.key,
|
|
123
123
|
rank: PASTE_MENU_RANK[PASTE_MENU_SECTION.key]
|
|
124
124
|
}],
|
|
125
|
+
isHidden: () => {
|
|
126
|
+
var _api$pasteOptionsTool, _pluginState$showLega;
|
|
127
|
+
const pluginState = api === null || api === void 0 ? void 0 : (_api$pasteOptionsTool = api.pasteOptionsToolbarPlugin) === null || _api$pasteOptionsTool === void 0 ? void 0 : _api$pasteOptionsTool.sharedState.currentState();
|
|
128
|
+
return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
|
|
129
|
+
},
|
|
125
130
|
component: props => /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
126
131
|
hasSeparator: true
|
|
127
132
|
}, props.children)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const isComponentOrAncestorHidden = (component, componentsByKey) => {
|
|
2
|
+
var _component$isHidden, _component$parents;
|
|
3
|
+
if ((_component$isHidden = component.isHidden) !== null && _component$isHidden !== void 0 && _component$isHidden.call(component)) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
return ((_component$parents = component.parents) !== null && _component$parents !== void 0 ? _component$parents : []).some(parent => {
|
|
7
|
+
const parentComponent = componentsByKey.get(parent.key);
|
|
8
|
+
return parentComponent ? isComponentOrAncestorHidden(parentComponent, componentsByKey) : false;
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns true when at least one menu-item button in the list is visible.
|
|
14
|
+
* A button is visible when neither it nor any of its ancestors are hidden.
|
|
15
|
+
*/
|
|
16
|
+
export const hasVisibleButton = components => {
|
|
17
|
+
const componentsByKey = new Map(components.map(c => [c.key, c]));
|
|
18
|
+
return components.filter(c => c.type === 'menu-item').some(c => !isComponentOrAncestorHidden(c, componentsByKey));
|
|
19
|
+
};
|
|
@@ -6,10 +6,10 @@ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-re
|
|
|
6
6
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
7
7
|
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
8
8
|
import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
|
|
9
|
-
import { buildChildrenMap, willComponentRender } from '@atlaskit/editor-ui-control-model';
|
|
10
9
|
import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
|
|
11
10
|
import { ToolbarDropdownOption } from '../../types/types';
|
|
12
11
|
import { isToolbarVisible } from '../toolbar';
|
|
12
|
+
import { hasVisibleButton } from './hasVisibleButton';
|
|
13
13
|
import { PasteActionsMenuContent } from './PasteActionsMenuContent';
|
|
14
14
|
var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
|
|
15
15
|
function getTargetElement(editorView) {
|
|
@@ -31,20 +31,8 @@ function getPopupOffset(dom) {
|
|
|
31
31
|
var rightEdge = dom.getBoundingClientRect().right;
|
|
32
32
|
return [-(window.innerWidth - rightEdge - 50), 20];
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Returns true when at least one component in the given list would produce
|
|
37
|
-
* visible output (i.e. is not hidden and, for containers, has at least one
|
|
38
|
-
* visible descendant).
|
|
39
|
-
*/
|
|
40
|
-
var hasVisibleComponent = function hasVisibleComponent(components) {
|
|
41
|
-
var childrenMap = buildChildrenMap(components);
|
|
42
|
-
return components.some(function (c) {
|
|
43
|
-
return willComponentRender(c, childrenMap);
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
34
|
export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
47
|
-
var _api$uiControlRegistr, _api$uiControlRegistr2
|
|
35
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
48
36
|
var api = _ref.api,
|
|
49
37
|
editorView = _ref.editorView,
|
|
50
38
|
mountTo = _ref.mountTo,
|
|
@@ -79,15 +67,13 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
79
67
|
showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
|
|
80
68
|
}, [lastContentPasted, editorView]);
|
|
81
69
|
var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
|
|
82
|
-
var _pluginState$showTool
|
|
70
|
+
var _pluginState$showTool;
|
|
83
71
|
var pluginState = states.pasteOptionsToolbarPluginState;
|
|
84
72
|
return {
|
|
85
|
-
showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
|
|
86
|
-
showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
|
|
73
|
+
showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
|
|
87
74
|
};
|
|
88
75
|
}),
|
|
89
|
-
isToolbarShown = _useSharedPluginState2.showToolbar
|
|
90
|
-
showLegacyOptions = _useSharedPluginState2.showLegacyOptions;
|
|
76
|
+
isToolbarShown = _useSharedPluginState2.showToolbar;
|
|
91
77
|
var preventEditorFocusLoss = useCallback(function (e) {
|
|
92
78
|
e.preventDefault();
|
|
93
79
|
}, []);
|
|
@@ -111,17 +97,12 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
111
97
|
handleDismiss();
|
|
112
98
|
}
|
|
113
99
|
}, [handleDismiss]);
|
|
114
|
-
var
|
|
115
|
-
|
|
116
|
-
key: 'ai-paste-menu'
|
|
117
|
-
};
|
|
118
|
-
var aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
119
|
-
var pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
|
|
120
|
-
var anyAiComponentVisible = hasVisibleComponent(aiSurfaceComponents);
|
|
100
|
+
var pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
101
|
+
var anyComponentVisible = hasVisibleButton(pasteMenuComponents);
|
|
121
102
|
if (!isToolbarShown) {
|
|
122
103
|
return null;
|
|
123
104
|
}
|
|
124
|
-
if (!
|
|
105
|
+
if (!anyComponentVisible) {
|
|
125
106
|
return null;
|
|
126
107
|
}
|
|
127
108
|
var target = getTargetElement(editorView);
|
|
@@ -147,8 +128,6 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
147
128
|
}, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
|
|
148
129
|
onMouseDown: preventEditorFocusLoss,
|
|
149
130
|
onMouseEnter: handleMouseEnter,
|
|
150
|
-
|
|
151
|
-
aiSurfaceComponents: aiSurfaceComponents,
|
|
152
|
-
pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
|
|
131
|
+
components: pasteMenuComponents
|
|
153
132
|
}))));
|
|
154
133
|
};
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import "./PasteActionsMenuContent.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
4
|
import React, { useContext } from 'react';
|
|
5
|
+
import { useIntl } from 'react-intl-next';
|
|
6
|
+
import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
7
|
import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
|
|
8
|
+
import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
|
|
6
9
|
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model';
|
|
7
10
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
8
11
|
var styles = {
|
|
@@ -11,23 +14,21 @@ var styles = {
|
|
|
11
14
|
export var PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
|
|
12
15
|
var onMouseDown = _ref.onMouseDown,
|
|
13
16
|
onMouseEnter = _ref.onMouseEnter,
|
|
14
|
-
|
|
15
|
-
aiSurfaceComponents = _ref.aiSurfaceComponents,
|
|
16
|
-
pasteSurfaceComponents = _ref.pasteSurfaceComponents;
|
|
17
|
+
components = _ref.components;
|
|
17
18
|
var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
|
|
19
|
+
var intl = useIntl();
|
|
18
20
|
return /*#__PURE__*/React.createElement(Box, {
|
|
19
21
|
ref: setOutsideClickTargetRef,
|
|
20
22
|
xcss: styles.container,
|
|
21
23
|
onMouseDown: onMouseDown,
|
|
22
24
|
onMouseEnter: onMouseEnter
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
25
|
+
}, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
26
|
+
title: intl.formatMessage(messages.pasteMenuActionsTitle)
|
|
27
|
+
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
27
28
|
surface: {
|
|
28
29
|
type: 'menu',
|
|
29
30
|
key: 'paste-menu'
|
|
30
31
|
},
|
|
31
|
-
components:
|
|
32
|
-
}));
|
|
32
|
+
components: components
|
|
33
|
+
})));
|
|
33
34
|
};
|
|
@@ -118,6 +118,11 @@ export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
|
|
|
118
118
|
key: PASTE_MENU.key,
|
|
119
119
|
rank: PASTE_MENU_RANK[PASTE_MENU_SECTION.key]
|
|
120
120
|
}],
|
|
121
|
+
isHidden: function isHidden() {
|
|
122
|
+
var _api$pasteOptionsTool, _pluginState$showLega;
|
|
123
|
+
var pluginState = api === null || api === void 0 || (_api$pasteOptionsTool = api.pasteOptionsToolbarPlugin) === null || _api$pasteOptionsTool === void 0 ? void 0 : _api$pasteOptionsTool.sharedState.currentState();
|
|
124
|
+
return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
|
|
125
|
+
},
|
|
121
126
|
component: function component(props) {
|
|
122
127
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
123
128
|
hasSeparator: true
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var _isComponentOrAncestorHidden = function isComponentOrAncestorHidden(component, componentsByKey) {
|
|
2
|
+
var _component$isHidden, _component$parents;
|
|
3
|
+
if ((_component$isHidden = component.isHidden) !== null && _component$isHidden !== void 0 && _component$isHidden.call(component)) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
return ((_component$parents = component.parents) !== null && _component$parents !== void 0 ? _component$parents : []).some(function (parent) {
|
|
7
|
+
var parentComponent = componentsByKey.get(parent.key);
|
|
8
|
+
return parentComponent ? _isComponentOrAncestorHidden(parentComponent, componentsByKey) : false;
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns true when at least one menu-item button in the list is visible.
|
|
14
|
+
* A button is visible when neither it nor any of its ancestors are hidden.
|
|
15
|
+
*/
|
|
16
|
+
export var hasVisibleButton = function hasVisibleButton(components) {
|
|
17
|
+
var componentsByKey = new Map(components.map(function (c) {
|
|
18
|
+
return [c.key, c];
|
|
19
|
+
}));
|
|
20
|
+
return components.filter(function (c) {
|
|
21
|
+
return c.type === 'menu-item';
|
|
22
|
+
}).some(function (c) {
|
|
23
|
+
return !_isComponentOrAncestorHidden(c, componentsByKey);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { RegisterComponent
|
|
2
|
+
import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
|
|
3
3
|
interface PasteActionsMenuContentProps {
|
|
4
|
-
|
|
5
|
-
aiSurfaceComponents?: RegisterComponent[];
|
|
4
|
+
components: RegisterComponent[];
|
|
6
5
|
onMouseDown: (e: React.MouseEvent) => void;
|
|
7
6
|
onMouseEnter: () => void;
|
|
8
|
-
pasteSurfaceComponents?: RegisterComponent[];
|
|
9
7
|
}
|
|
10
|
-
export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter,
|
|
8
|
+
export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, components, }: PasteActionsMenuContentProps) => React.JSX.Element;
|
|
11
9
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true when at least one menu-item button in the list is visible.
|
|
4
|
+
* A button is visible when neither it nor any of its ancestors are hidden.
|
|
5
|
+
*/
|
|
6
|
+
export declare const hasVisibleButton: (components: RegisterComponent[]) => boolean;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { RegisterComponent
|
|
2
|
+
import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
|
|
3
3
|
interface PasteActionsMenuContentProps {
|
|
4
|
-
|
|
5
|
-
aiSurfaceComponents?: RegisterComponent[];
|
|
4
|
+
components: RegisterComponent[];
|
|
6
5
|
onMouseDown: (e: React.MouseEvent) => void;
|
|
7
6
|
onMouseEnter: () => void;
|
|
8
|
-
pasteSurfaceComponents?: RegisterComponent[];
|
|
9
7
|
}
|
|
10
|
-
export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter,
|
|
8
|
+
export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, components, }: PasteActionsMenuContentProps) => React.JSX.Element;
|
|
11
9
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true when at least one menu-item button in the list is visible.
|
|
4
|
+
* A button is visible when neither it nor any of its ancestors are hidden.
|
|
5
|
+
*/
|
|
6
|
+
export declare const hasVisibleButton: (components: RegisterComponent[]) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-paste-options-toolbar",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.1",
|
|
4
4
|
"description": "Paste options toolbar for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -41,15 +41,15 @@
|
|
|
41
41
|
"@atlaskit/icon": "^32.0.0",
|
|
42
42
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
43
43
|
"@atlaskit/primitives": "^18.0.0",
|
|
44
|
-
"@atlaskit/tmp-editor-statsig": "^35.
|
|
45
|
-
"@atlaskit/tokens": "^11.
|
|
44
|
+
"@atlaskit/tmp-editor-statsig": "^35.5.0",
|
|
45
|
+
"@atlaskit/tokens": "^11.1.0",
|
|
46
46
|
"@babel/runtime": "^7.0.0",
|
|
47
47
|
"@compiled/react": "^0.20.0",
|
|
48
48
|
"@emotion/react": "^11.7.1",
|
|
49
49
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@atlaskit/editor-common": "^111.
|
|
52
|
+
"@atlaskit/editor-common": "^111.32.0",
|
|
53
53
|
"react": "^18.2.0",
|
|
54
54
|
"react-dom": "^18.2.0"
|
|
55
55
|
},
|