@atlaskit/editor-plugin-paste-options-toolbar 9.1.6 → 9.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +79 -28
- package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +16 -13
- package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.js +45 -15
- package/dist/cjs/ui/on-paste-actions-menu/PasteOptionsDropdownButton.js +52 -0
- package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +78 -29
- package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +17 -14
- package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.js +45 -13
- package/dist/es2019/ui/on-paste-actions-menu/PasteOptionsDropdownButton.js +47 -0
- package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +79 -29
- package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +17 -14
- package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.js +45 -15
- package/dist/esm/ui/on-paste-actions-menu/PasteOptionsDropdownButton.js +46 -0
- package/dist/types/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +16 -0
- package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -1
- package/dist/types/ui/on-paste-actions-menu/PasteOptionsDropdownButton.d.ts +19 -0
- package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +16 -0
- package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -1
- package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteOptionsDropdownButton.d.ts +19 -0
- package/package.json +6 -5
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
/* PasteActionsMenuContent.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
2
|
import "./PasteActionsMenuContent.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
-
import React, { useContext } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import React, { useCallback, useContext } from 'react';
|
|
5
|
+
import { PASTE_MENU } from '@atlaskit/editor-common/toolbar';
|
|
7
6
|
import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
|
|
8
|
-
import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
|
|
9
7
|
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model';
|
|
10
8
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
11
9
|
const styles = {
|
|
12
10
|
container: "_2rko12b0 _bfhk1bhr _16qs130s"
|
|
13
11
|
};
|
|
12
|
+
const pasteMenuSurface = {
|
|
13
|
+
type: PASTE_MENU.type,
|
|
14
|
+
key: PASTE_MENU.key
|
|
15
|
+
};
|
|
14
16
|
export const PasteActionsMenuContent = ({
|
|
15
17
|
onMouseDown,
|
|
16
18
|
onMouseEnter,
|
|
17
|
-
components
|
|
19
|
+
components,
|
|
20
|
+
contentRef
|
|
18
21
|
}) => {
|
|
19
22
|
const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
|
|
20
|
-
const
|
|
23
|
+
const mergedRef = useCallback(node => {
|
|
24
|
+
setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 ? void 0 : setOutsideClickTargetRef(node);
|
|
25
|
+
if (contentRef) {
|
|
26
|
+
contentRef.current = node;
|
|
27
|
+
}
|
|
28
|
+
}, [setOutsideClickTargetRef, contentRef]);
|
|
21
29
|
return /*#__PURE__*/React.createElement(Box, {
|
|
22
|
-
ref:
|
|
30
|
+
ref: mergedRef,
|
|
23
31
|
xcss: styles.container,
|
|
24
32
|
onMouseDown: onMouseDown,
|
|
25
33
|
onMouseEnter: onMouseEnter
|
|
26
|
-
}, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
27
|
-
title: intl.formatMessage(messages.pasteMenuActionsTitle)
|
|
28
34
|
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
29
|
-
surface:
|
|
30
|
-
type: 'menu',
|
|
31
|
-
key: 'paste-menu'
|
|
32
|
-
},
|
|
35
|
+
surface: pasteMenuSurface,
|
|
33
36
|
components: components
|
|
34
|
-
}))
|
|
37
|
+
}));
|
|
35
38
|
};
|
|
@@ -8,12 +8,14 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
|
|
|
8
8
|
import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
|
|
9
9
|
import { useEditorToolbar, PASTE_MENU, PASTE_MENU_SECTION, PASTE_NESTED_MENU, PASTE_MENU_NESTED_SECTION, PASTE_RICH_TEXT_MENU_ITEM, PASTE_MARKDOWN_MENU_ITEM, PASTE_PLAIN_TEXT_MENU_ITEM, PASTE_MENU_RANK, PASTE_MENU_SECTION_RANK, PASTE_NESTED_MENU_RANK, PASTE_MENU_NESTED_SECTION_RANK, AI_PASTE_MENU_SECTION } from '@atlaskit/editor-common/toolbar';
|
|
10
10
|
import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
|
|
11
|
+
import ChevronDownIcon from '@atlaskit/icon/core/chevron-down';
|
|
11
12
|
import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
|
|
12
13
|
import ClipboardIcon from '@atlaskit/icon/core/clipboard';
|
|
13
14
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
14
15
|
import { changeToMarkdownWithAnalytics, changeToPlainTextWithAnalytics, changeToRichTextWithAnalytics } from '../../editor-commands/commands';
|
|
15
16
|
import { ToolbarDropdownOption } from '../../types/types';
|
|
16
17
|
import { getVisibleKeys } from './hasVisibleButton';
|
|
18
|
+
import { PasteOptionsDropdownButton } from './PasteOptionsDropdownButton';
|
|
17
19
|
const nestedMenuStyles = {
|
|
18
20
|
narrowSection: "_10gv1lit"
|
|
19
21
|
};
|
|
@@ -94,22 +96,48 @@ const PasteMenuItem = ({
|
|
|
94
96
|
}, displayLabel);
|
|
95
97
|
};
|
|
96
98
|
const PasteOptionsNestedMenu = ({
|
|
97
|
-
children
|
|
99
|
+
children,
|
|
100
|
+
hasVisibleAiActions
|
|
98
101
|
}) => {
|
|
99
102
|
const intl = useIntl();
|
|
103
|
+
const label = intl.formatMessage(messages.pasteMenuActionsPasteAs);
|
|
104
|
+
if (!hasVisibleAiActions) {
|
|
105
|
+
return /*#__PURE__*/React.createElement(PasteOptionsDropdownButton, {
|
|
106
|
+
elemBefore: /*#__PURE__*/React.createElement(ClipboardIcon, {
|
|
107
|
+
size: "small",
|
|
108
|
+
label: ""
|
|
109
|
+
}),
|
|
110
|
+
elemAfter: /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
111
|
+
size: "small",
|
|
112
|
+
label: ""
|
|
113
|
+
}),
|
|
114
|
+
label: label,
|
|
115
|
+
testId: "paste-options-nested-menu",
|
|
116
|
+
tooltipContent: label
|
|
117
|
+
}, children);
|
|
118
|
+
}
|
|
100
119
|
return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
|
|
101
120
|
elemBefore: /*#__PURE__*/React.createElement(ClipboardIcon, {
|
|
102
121
|
size: "small",
|
|
103
|
-
label:
|
|
122
|
+
label: label
|
|
104
123
|
}),
|
|
105
124
|
elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
|
|
106
125
|
size: "small",
|
|
107
|
-
label:
|
|
126
|
+
label: ""
|
|
108
127
|
}),
|
|
109
128
|
testId: "paste-options-nested-menu",
|
|
110
|
-
text:
|
|
129
|
+
text: label
|
|
111
130
|
}, children);
|
|
112
131
|
};
|
|
132
|
+
const getHasVisibleAiActions = api => {
|
|
133
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
134
|
+
const allComponents = (_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 : [];
|
|
135
|
+
const aiMenuItems = allComponents.filter(c => {
|
|
136
|
+
var _c$parents;
|
|
137
|
+
return c.type === 'menu-item' && ((_c$parents = c.parents) === null || _c$parents === void 0 ? void 0 : _c$parents.some(p => p.key === AI_PASTE_MENU_SECTION.key));
|
|
138
|
+
});
|
|
139
|
+
return getVisibleKeys(aiMenuItems, ['menu-item']).length > 0;
|
|
140
|
+
};
|
|
113
141
|
export const getPasteMenuComponents = ({
|
|
114
142
|
api
|
|
115
143
|
}) => [{
|
|
@@ -129,15 +157,14 @@ export const getPasteMenuComponents = ({
|
|
|
129
157
|
return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
|
|
130
158
|
},
|
|
131
159
|
component: props => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
const hasVisibleAiActions = getVisibleKeys(aiMenuItems, ['menu-item']).length > 0;
|
|
160
|
+
const hasVisibleAiActions = getHasVisibleAiActions(api);
|
|
161
|
+
if (!hasVisibleAiActions) {
|
|
162
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
163
|
+
padding: "space.050"
|
|
164
|
+
}, props.children);
|
|
165
|
+
}
|
|
139
166
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
140
|
-
hasSeparator:
|
|
167
|
+
hasSeparator: true
|
|
141
168
|
}, props.children);
|
|
142
169
|
}
|
|
143
170
|
}, {
|
|
@@ -148,7 +175,12 @@ export const getPasteMenuComponents = ({
|
|
|
148
175
|
key: PASTE_MENU_SECTION.key,
|
|
149
176
|
rank: PASTE_MENU_SECTION_RANK[PASTE_NESTED_MENU.key]
|
|
150
177
|
}],
|
|
151
|
-
component: props =>
|
|
178
|
+
component: props => {
|
|
179
|
+
const hasVisibleAiActions = getHasVisibleAiActions(api);
|
|
180
|
+
return /*#__PURE__*/React.createElement(PasteOptionsNestedMenu, {
|
|
181
|
+
hasVisibleAiActions: hasVisibleAiActions
|
|
182
|
+
}, props.children);
|
|
183
|
+
}
|
|
152
184
|
}, {
|
|
153
185
|
type: PASTE_MENU_NESTED_SECTION.type,
|
|
154
186
|
key: PASTE_MENU_NESTED_SECTION.key,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* PasteOptionsDropdownButton.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
3
|
+
import React, { useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
6
|
+
|
|
7
|
+
import DropdownMenu from '@atlaskit/dropdown-menu';
|
|
8
|
+
import { ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A compact dropdown button for paste options, styled like floating toolbar buttons.
|
|
12
|
+
* Renders as a ToolbarButton with an icon and dropdown caret that opens a
|
|
13
|
+
* dropdown menu below. Used when AI actions are not visible and the paste
|
|
14
|
+
* options menu is the only content.
|
|
15
|
+
*/
|
|
16
|
+
export const PasteOptionsDropdownButton = ({
|
|
17
|
+
children,
|
|
18
|
+
elemBefore,
|
|
19
|
+
elemAfter,
|
|
20
|
+
label,
|
|
21
|
+
testId,
|
|
22
|
+
tooltipContent
|
|
23
|
+
}) => {
|
|
24
|
+
const trigger = useCallback(triggerProps => {
|
|
25
|
+
const button = /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
26
|
+
ref: triggerProps.triggerRef,
|
|
27
|
+
isSelected: triggerProps.isSelected,
|
|
28
|
+
"aria-expanded": triggerProps['aria-expanded'],
|
|
29
|
+
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
30
|
+
onClick: triggerProps.onClick,
|
|
31
|
+
testId: testId,
|
|
32
|
+
iconBefore: elemBefore,
|
|
33
|
+
label: label
|
|
34
|
+
}, elemAfter);
|
|
35
|
+
if (tooltipContent) {
|
|
36
|
+
return /*#__PURE__*/React.createElement(ToolbarTooltip, {
|
|
37
|
+
content: tooltipContent,
|
|
38
|
+
position: "top"
|
|
39
|
+
}, button);
|
|
40
|
+
}
|
|
41
|
+
return button;
|
|
42
|
+
}, [testId, elemBefore, elemAfter, label, tooltipContent]);
|
|
43
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
44
|
+
placement: "bottom-start",
|
|
45
|
+
trigger: trigger
|
|
46
|
+
}, children);
|
|
47
|
+
};
|
|
@@ -4,7 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
5
5
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
6
6
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
7
|
-
import { EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
|
|
7
|
+
import { AI_PASTE_MENU_SECTION, EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
|
|
8
8
|
import { findOverflowScrollParent, Popup } from '@atlaskit/editor-common/ui';
|
|
9
9
|
import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
|
|
10
10
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
@@ -104,6 +104,35 @@ export function findBlockAncestorDOM(editorView, pos) {
|
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Positions the paste menu inline, immediately to the right of the cursor
|
|
109
|
+
* at the paste end position, vertically centered with the line.
|
|
110
|
+
* Used for short pastes without AI actions.
|
|
111
|
+
*/
|
|
112
|
+
export function onInlinePositionCalculated(editorView, pasteEndPos, targetElement, popupContentRef) {
|
|
113
|
+
return function (position) {
|
|
114
|
+
var _popupContentRef$curr, _popupContentRef$curr2, _position$top, _position$left;
|
|
115
|
+
var endCoords = editorView.coordsAtPos(pasteEndPos);
|
|
116
|
+
var targetRect = targetElement.getBoundingClientRect();
|
|
117
|
+
|
|
118
|
+
// Vertical: center the menu with the line at the paste end position.
|
|
119
|
+
var lineHeight = endCoords.bottom - endCoords.top;
|
|
120
|
+
var lineMidpoint = endCoords.top + lineHeight / 2;
|
|
121
|
+
var menuHeight = (_popupContentRef$curr = (_popupContentRef$curr2 = popupContentRef.current) === null || _popupContentRef$curr2 === void 0 ? void 0 : _popupContentRef$curr2.getBoundingClientRect().height) !== null && _popupContentRef$curr !== void 0 ? _popupContentRef$curr : lineHeight;
|
|
122
|
+
var menuTop = lineMidpoint - menuHeight / 2;
|
|
123
|
+
var topDelta = menuTop - (targetRect.top + targetRect.height);
|
|
124
|
+
var adjustedTop = ((_position$top = position.top) !== null && _position$top !== void 0 ? _position$top : 0) + topDelta;
|
|
125
|
+
|
|
126
|
+
// Horizontal: position to the right of the cursor
|
|
127
|
+
var leftDelta = endCoords.right - targetRect.right;
|
|
128
|
+
var adjustedLeft = ((_position$left = position.left) !== null && _position$left !== void 0 ? _position$left : 0) + leftDelta;
|
|
129
|
+
return _objectSpread(_objectSpread({}, position), {}, {
|
|
130
|
+
top: adjustedTop,
|
|
131
|
+
left: adjustedLeft
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
107
136
|
/**
|
|
108
137
|
* Adjusts the position of the paste menu so that:
|
|
109
138
|
*
|
|
@@ -134,7 +163,7 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
|
|
|
134
163
|
var tableAfterPos = resolveTableAfterPos(editorView, pasteEndPos);
|
|
135
164
|
var blockAncestorDOM = findBlockAncestorDOM(editorView, pasteStartPos);
|
|
136
165
|
return function (position) {
|
|
137
|
-
var _position$
|
|
166
|
+
var _position$top2;
|
|
138
167
|
var startCoords = editorView.coordsAtPos(pasteStartPos);
|
|
139
168
|
var endBottom = getVisualEndBottom(editorView, pasteEndPos, tableAfterPos);
|
|
140
169
|
var targetRect = targetElement.getBoundingClientRect();
|
|
@@ -144,7 +173,7 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
|
|
|
144
173
|
// We shift it up so it aligns with the paste start position.
|
|
145
174
|
// Both coordinates are in viewport space, so the delta is offset-parent agnostic.
|
|
146
175
|
var topDelta = startCoords.top - (targetRect.top + targetRect.height);
|
|
147
|
-
var adjustedTop = ((_position$
|
|
176
|
+
var adjustedTop = ((_position$top2 = position.top) !== null && _position$top2 !== void 0 ? _position$top2 : 0) + topDelta;
|
|
148
177
|
|
|
149
178
|
// Sticky-top: clamp to the scroll container's top edge when the paste
|
|
150
179
|
// start has scrolled above the visible area, but only while some pasted
|
|
@@ -166,13 +195,13 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
|
|
|
166
195
|
// re-anchoring to its right edge.
|
|
167
196
|
var adjustedLeft = position.left;
|
|
168
197
|
if (blockAncestorDOM && blockAncestorDOM !== targetElement) {
|
|
169
|
-
var _position$
|
|
198
|
+
var _position$left2;
|
|
170
199
|
var blockRect = blockAncestorDOM.getBoundingClientRect();
|
|
171
200
|
// Shift left by the difference between the block's right edge and
|
|
172
201
|
// the inline target's right edge. This mirrors what alignX="end"
|
|
173
202
|
// would have computed if the target were the block element.
|
|
174
203
|
var leftDelta = blockRect.right - targetRect.right;
|
|
175
|
-
adjustedLeft = ((_position$
|
|
204
|
+
adjustedLeft = ((_position$left2 = position.left) !== null && _position$left2 !== void 0 ? _position$left2 : 0) + leftDelta;
|
|
176
205
|
}
|
|
177
206
|
return _objectSpread(_objectSpread({}, position), {}, {
|
|
178
207
|
top: adjustedTop,
|
|
@@ -181,7 +210,7 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
|
|
|
181
210
|
};
|
|
182
211
|
}
|
|
183
212
|
export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
184
|
-
var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2
|
|
213
|
+
var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
185
214
|
var api = _ref.api,
|
|
186
215
|
editorView = _ref.editorView,
|
|
187
216
|
mountTo = _ref.mountTo,
|
|
@@ -196,8 +225,8 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
196
225
|
}),
|
|
197
226
|
lastContentPasted = _useSharedPluginState.lastContentPasted;
|
|
198
227
|
var prevShowToolbarRef = useRef(false);
|
|
228
|
+
var popupContentRef = useRef(null);
|
|
199
229
|
useEffect(function () {
|
|
200
|
-
var _lastContentPasted$te, _lastContentPasted$te2;
|
|
201
230
|
if (!lastContentPasted) {
|
|
202
231
|
hideToolbar()(editorView.state, editorView.dispatch);
|
|
203
232
|
return;
|
|
@@ -220,7 +249,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
220
249
|
pasteAncestorNodeNames.push($pos.node(depth).type.name);
|
|
221
250
|
}
|
|
222
251
|
}
|
|
223
|
-
var legacyVisible = isToolbarVisible(editorView.state, lastContentPasted)
|
|
252
|
+
var legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
|
|
224
253
|
showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
|
|
225
254
|
}, [lastContentPasted, editorView]);
|
|
226
255
|
var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
|
|
@@ -235,22 +264,6 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
235
264
|
isToolbarShown = _useSharedPluginState2.showToolbar,
|
|
236
265
|
pasteStartPos = _useSharedPluginState2.pasteStartPos,
|
|
237
266
|
pasteEndPos = _useSharedPluginState2.pasteEndPos;
|
|
238
|
-
var aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents('ai-paste-menu')) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
239
|
-
var visibleAiActionKeys = getVisibleKeys(aiSurfaceComponents, ['button', 'menu-item']);
|
|
240
|
-
useEffect(function () {
|
|
241
|
-
if (!prevShowToolbarRef.current && isToolbarShown) {
|
|
242
|
-
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
|
|
243
|
-
action: ACTION.OPENED,
|
|
244
|
-
actionSubject: ACTION_SUBJECT.PASTE_ACTIONS_MENU,
|
|
245
|
-
eventType: EVENT_TYPE.UI,
|
|
246
|
-
attributes: {
|
|
247
|
-
visibleAiActions: visibleAiActionKeys
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
prevShowToolbarRef.current = isToolbarShown;
|
|
252
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
253
|
-
}, [isToolbarShown, editorAnalyticsAPI]);
|
|
254
267
|
var preventEditorFocusLoss = useCallback(function (e) {
|
|
255
268
|
e.preventDefault();
|
|
256
269
|
}, []);
|
|
@@ -282,18 +295,54 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
282
295
|
// onPositionCalculated with fresh viewport coordinates.
|
|
283
296
|
var overflowScrollParent = isToolbarShown ? findOverflowScrollParent(editorView.dom) : false;
|
|
284
297
|
var effectiveScrollableElement = overflowScrollParent || scrollableElement;
|
|
285
|
-
var pasteMenuComponents = (_api$
|
|
298
|
+
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 : [];
|
|
286
299
|
var anyComponentVisible = hasVisibleButton(pasteMenuComponents);
|
|
300
|
+
|
|
301
|
+
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-computations-in-render -- pasteMenuComponents changes by reference each render; filter is small (< 10 items)
|
|
302
|
+
var aiMenuItems = pasteMenuComponents.filter(function (c) {
|
|
303
|
+
var _c$parents;
|
|
304
|
+
return c.type === 'menu-item' && ((_c$parents = c.parents) === null || _c$parents === void 0 ? void 0 : _c$parents.some(function (p) {
|
|
305
|
+
return p.key === AI_PASTE_MENU_SECTION.key;
|
|
306
|
+
}));
|
|
307
|
+
});
|
|
308
|
+
var visibleAiActionKeys = getVisibleKeys(aiMenuItems, ['menu-item']);
|
|
309
|
+
|
|
310
|
+
// Two positioning modes:
|
|
311
|
+
// 1. Inline: no AI actions visible — menu appears to the right of the cursor,
|
|
312
|
+
// vertically centered with the text line.
|
|
313
|
+
// 2. Block-anchored: AI actions are visible — menu appears at the right edge
|
|
314
|
+
// of the content block, aligned with paste start.
|
|
315
|
+
var hasVisibleAiActions = visibleAiActionKeys.length > 0;
|
|
316
|
+
useEffect(function () {
|
|
317
|
+
if (!prevShowToolbarRef.current && isToolbarShown) {
|
|
318
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
|
|
319
|
+
action: ACTION.OPENED,
|
|
320
|
+
actionSubject: ACTION_SUBJECT.PASTE_ACTIONS_MENU,
|
|
321
|
+
eventType: EVENT_TYPE.UI,
|
|
322
|
+
attributes: {
|
|
323
|
+
visibleAiActions: visibleAiActionKeys
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
prevShowToolbarRef.current = isToolbarShown;
|
|
328
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
329
|
+
}, [isToolbarShown, editorAnalyticsAPI]);
|
|
330
|
+
var useInlinePosition = !hasVisibleAiActions;
|
|
287
331
|
if (!isToolbarShown) {
|
|
288
332
|
return null;
|
|
289
333
|
}
|
|
290
334
|
if (!anyComponentVisible) {
|
|
291
335
|
return null;
|
|
292
336
|
}
|
|
293
|
-
var target = getTargetElement(editorView, pasteStartPos);
|
|
337
|
+
var target = getTargetElement(editorView, useInlinePosition ? pasteEndPos : pasteStartPos);
|
|
294
338
|
if (!target) {
|
|
295
339
|
return null;
|
|
296
340
|
}
|
|
341
|
+
|
|
342
|
+
// Choose positioning strategy based on whether the menu appears inline
|
|
343
|
+
// (right of cursor for short pastes) or anchored to the block ancestor
|
|
344
|
+
// (right side of content area for longer pastes / AI actions).
|
|
345
|
+
var positionCalculator = useInlinePosition ? onInlinePositionCalculated(editorView, pasteEndPos, target, popupContentRef) : onPositionCalculated(editorView, pasteStartPos, pasteEndPos, target, effectiveScrollableElement);
|
|
297
346
|
return /*#__PURE__*/React.createElement(PopupWithListeners, {
|
|
298
347
|
target: target,
|
|
299
348
|
mountTo: mountTo,
|
|
@@ -302,10 +351,10 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
302
351
|
minPopupMargin: PASTE_MENU_GAP_HORIZONTAL,
|
|
303
352
|
zIndex: akEditorFloatingPanelZIndex,
|
|
304
353
|
alignX: "end",
|
|
305
|
-
alignY:
|
|
354
|
+
alignY: useInlinePosition ? 'top' : 'bottom'
|
|
306
355
|
/* eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) */,
|
|
307
356
|
offset: [PASTE_MENU_GAP_HORIZONTAL, 0],
|
|
308
|
-
onPositionCalculated:
|
|
357
|
+
onPositionCalculated: positionCalculator,
|
|
309
358
|
handleClickOutside: handleClickOutside,
|
|
310
359
|
handleEscapeKeydown: handleDismiss
|
|
311
360
|
}, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
|
|
@@ -316,6 +365,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
316
365
|
}, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
|
|
317
366
|
onMouseDown: preventEditorFocusLoss,
|
|
318
367
|
onMouseEnter: handleMouseEnter,
|
|
319
|
-
components: pasteMenuComponents
|
|
368
|
+
components: pasteMenuComponents,
|
|
369
|
+
contentRef: popupContentRef
|
|
320
370
|
}))));
|
|
321
371
|
};
|
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
/* PasteActionsMenuContent.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
2
|
import "./PasteActionsMenuContent.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
-
import React, { useContext } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import React, { useCallback, useContext } from 'react';
|
|
5
|
+
import { PASTE_MENU } from '@atlaskit/editor-common/toolbar';
|
|
7
6
|
import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
|
|
8
|
-
import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
|
|
9
7
|
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model';
|
|
10
8
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
11
9
|
var styles = {
|
|
12
10
|
container: "_2rko12b0 _bfhk1bhr _16qs130s"
|
|
13
11
|
};
|
|
12
|
+
var pasteMenuSurface = {
|
|
13
|
+
type: PASTE_MENU.type,
|
|
14
|
+
key: PASTE_MENU.key
|
|
15
|
+
};
|
|
14
16
|
export var PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
|
|
15
17
|
var onMouseDown = _ref.onMouseDown,
|
|
16
18
|
onMouseEnter = _ref.onMouseEnter,
|
|
17
|
-
components = _ref.components
|
|
19
|
+
components = _ref.components,
|
|
20
|
+
contentRef = _ref.contentRef;
|
|
18
21
|
var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
|
|
19
|
-
var
|
|
22
|
+
var mergedRef = useCallback(function (node) {
|
|
23
|
+
setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 || setOutsideClickTargetRef(node);
|
|
24
|
+
if (contentRef) {
|
|
25
|
+
contentRef.current = node;
|
|
26
|
+
}
|
|
27
|
+
}, [setOutsideClickTargetRef, contentRef]);
|
|
20
28
|
return /*#__PURE__*/React.createElement(Box, {
|
|
21
|
-
ref:
|
|
29
|
+
ref: mergedRef,
|
|
22
30
|
xcss: styles.container,
|
|
23
31
|
onMouseDown: onMouseDown,
|
|
24
32
|
onMouseEnter: onMouseEnter
|
|
25
|
-
}, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
26
|
-
title: intl.formatMessage(messages.pasteMenuActionsTitle)
|
|
27
33
|
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
28
|
-
surface:
|
|
29
|
-
type: 'menu',
|
|
30
|
-
key: 'paste-menu'
|
|
31
|
-
},
|
|
34
|
+
surface: pasteMenuSurface,
|
|
32
35
|
components: components
|
|
33
|
-
}))
|
|
36
|
+
}));
|
|
34
37
|
};
|
|
@@ -8,12 +8,14 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
|
|
|
8
8
|
import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
|
|
9
9
|
import { useEditorToolbar, PASTE_MENU, PASTE_MENU_SECTION, PASTE_NESTED_MENU, PASTE_MENU_NESTED_SECTION, PASTE_RICH_TEXT_MENU_ITEM, PASTE_MARKDOWN_MENU_ITEM, PASTE_PLAIN_TEXT_MENU_ITEM, PASTE_MENU_RANK, PASTE_MENU_SECTION_RANK, PASTE_NESTED_MENU_RANK, PASTE_MENU_NESTED_SECTION_RANK, AI_PASTE_MENU_SECTION } from '@atlaskit/editor-common/toolbar';
|
|
10
10
|
import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
|
|
11
|
+
import ChevronDownIcon from '@atlaskit/icon/core/chevron-down';
|
|
11
12
|
import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
|
|
12
13
|
import ClipboardIcon from '@atlaskit/icon/core/clipboard';
|
|
13
14
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
14
15
|
import { changeToMarkdownWithAnalytics, changeToPlainTextWithAnalytics, changeToRichTextWithAnalytics } from '../../editor-commands/commands';
|
|
15
16
|
import { ToolbarDropdownOption } from '../../types/types';
|
|
16
17
|
import { getVisibleKeys } from './hasVisibleButton';
|
|
18
|
+
import { PasteOptionsDropdownButton } from './PasteOptionsDropdownButton';
|
|
17
19
|
var nestedMenuStyles = {
|
|
18
20
|
narrowSection: "_10gv1lit"
|
|
19
21
|
};
|
|
@@ -91,21 +93,49 @@ var PasteMenuItem = function PasteMenuItem(_ref) {
|
|
|
91
93
|
}, displayLabel);
|
|
92
94
|
};
|
|
93
95
|
var PasteOptionsNestedMenu = function PasteOptionsNestedMenu(_ref2) {
|
|
94
|
-
var children = _ref2.children
|
|
96
|
+
var children = _ref2.children,
|
|
97
|
+
hasVisibleAiActions = _ref2.hasVisibleAiActions;
|
|
95
98
|
var intl = useIntl();
|
|
99
|
+
var label = intl.formatMessage(messages.pasteMenuActionsPasteAs);
|
|
100
|
+
if (!hasVisibleAiActions) {
|
|
101
|
+
return /*#__PURE__*/React.createElement(PasteOptionsDropdownButton, {
|
|
102
|
+
elemBefore: /*#__PURE__*/React.createElement(ClipboardIcon, {
|
|
103
|
+
size: "small",
|
|
104
|
+
label: ""
|
|
105
|
+
}),
|
|
106
|
+
elemAfter: /*#__PURE__*/React.createElement(ChevronDownIcon, {
|
|
107
|
+
size: "small",
|
|
108
|
+
label: ""
|
|
109
|
+
}),
|
|
110
|
+
label: label,
|
|
111
|
+
testId: "paste-options-nested-menu",
|
|
112
|
+
tooltipContent: label
|
|
113
|
+
}, children);
|
|
114
|
+
}
|
|
96
115
|
return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
|
|
97
116
|
elemBefore: /*#__PURE__*/React.createElement(ClipboardIcon, {
|
|
98
117
|
size: "small",
|
|
99
|
-
label:
|
|
118
|
+
label: label
|
|
100
119
|
}),
|
|
101
120
|
elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
|
|
102
121
|
size: "small",
|
|
103
|
-
label:
|
|
122
|
+
label: ""
|
|
104
123
|
}),
|
|
105
124
|
testId: "paste-options-nested-menu",
|
|
106
|
-
text:
|
|
125
|
+
text: label
|
|
107
126
|
}, children);
|
|
108
127
|
};
|
|
128
|
+
var getHasVisibleAiActions = function getHasVisibleAiActions(api) {
|
|
129
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
130
|
+
var allComponents = (_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 : [];
|
|
131
|
+
var aiMenuItems = allComponents.filter(function (c) {
|
|
132
|
+
var _c$parents;
|
|
133
|
+
return c.type === 'menu-item' && ((_c$parents = c.parents) === null || _c$parents === void 0 ? void 0 : _c$parents.some(function (p) {
|
|
134
|
+
return p.key === AI_PASTE_MENU_SECTION.key;
|
|
135
|
+
}));
|
|
136
|
+
});
|
|
137
|
+
return getVisibleKeys(aiMenuItems, ['menu-item']).length > 0;
|
|
138
|
+
};
|
|
109
139
|
export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
|
|
110
140
|
var api = _ref3.api;
|
|
111
141
|
return [{
|
|
@@ -125,17 +155,14 @@ export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
|
|
|
125
155
|
return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
|
|
126
156
|
},
|
|
127
157
|
component: function component(props) {
|
|
128
|
-
var
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}));
|
|
135
|
-
});
|
|
136
|
-
var hasVisibleAiActions = getVisibleKeys(aiMenuItems, ['menu-item']).length > 0;
|
|
158
|
+
var hasVisibleAiActions = getHasVisibleAiActions(api);
|
|
159
|
+
if (!hasVisibleAiActions) {
|
|
160
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
161
|
+
padding: "space.050"
|
|
162
|
+
}, props.children);
|
|
163
|
+
}
|
|
137
164
|
return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
|
|
138
|
-
hasSeparator:
|
|
165
|
+
hasSeparator: true
|
|
139
166
|
}, props.children);
|
|
140
167
|
}
|
|
141
168
|
}, {
|
|
@@ -147,7 +174,10 @@ export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
|
|
|
147
174
|
rank: PASTE_MENU_SECTION_RANK[PASTE_NESTED_MENU.key]
|
|
148
175
|
}],
|
|
149
176
|
component: function component(props) {
|
|
150
|
-
|
|
177
|
+
var hasVisibleAiActions = getHasVisibleAiActions(api);
|
|
178
|
+
return /*#__PURE__*/React.createElement(PasteOptionsNestedMenu, {
|
|
179
|
+
hasVisibleAiActions: hasVisibleAiActions
|
|
180
|
+
}, props.children);
|
|
151
181
|
}
|
|
152
182
|
}, {
|
|
153
183
|
type: PASTE_MENU_NESTED_SECTION.type,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* PasteOptionsDropdownButton.tsx generated by @compiled/babel-plugin v0.39.1 */
|
|
2
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
3
|
+
import React, { useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
6
|
+
|
|
7
|
+
import DropdownMenu from '@atlaskit/dropdown-menu';
|
|
8
|
+
import { ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A compact dropdown button for paste options, styled like floating toolbar buttons.
|
|
12
|
+
* Renders as a ToolbarButton with an icon and dropdown caret that opens a
|
|
13
|
+
* dropdown menu below. Used when AI actions are not visible and the paste
|
|
14
|
+
* options menu is the only content.
|
|
15
|
+
*/
|
|
16
|
+
export var PasteOptionsDropdownButton = function PasteOptionsDropdownButton(_ref) {
|
|
17
|
+
var children = _ref.children,
|
|
18
|
+
elemBefore = _ref.elemBefore,
|
|
19
|
+
elemAfter = _ref.elemAfter,
|
|
20
|
+
label = _ref.label,
|
|
21
|
+
testId = _ref.testId,
|
|
22
|
+
tooltipContent = _ref.tooltipContent;
|
|
23
|
+
var trigger = useCallback(function (triggerProps) {
|
|
24
|
+
var button = /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
25
|
+
ref: triggerProps.triggerRef,
|
|
26
|
+
isSelected: triggerProps.isSelected,
|
|
27
|
+
"aria-expanded": triggerProps['aria-expanded'],
|
|
28
|
+
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
29
|
+
onClick: triggerProps.onClick,
|
|
30
|
+
testId: testId,
|
|
31
|
+
iconBefore: elemBefore,
|
|
32
|
+
label: label
|
|
33
|
+
}, elemAfter);
|
|
34
|
+
if (tooltipContent) {
|
|
35
|
+
return /*#__PURE__*/React.createElement(ToolbarTooltip, {
|
|
36
|
+
content: tooltipContent,
|
|
37
|
+
position: "top"
|
|
38
|
+
}, button);
|
|
39
|
+
}
|
|
40
|
+
return button;
|
|
41
|
+
}, [testId, elemBefore, elemAfter, label, tooltipContent]);
|
|
42
|
+
return /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
43
|
+
placement: "bottom-start",
|
|
44
|
+
trigger: trigger
|
|
45
|
+
}, children);
|
|
46
|
+
};
|
|
@@ -33,6 +33,22 @@ export declare function getVisualEndBottom(editorView: EditorView, pasteEndPos:
|
|
|
33
33
|
* Returns `null` if no block ancestor can be resolved to a DOM element.
|
|
34
34
|
*/
|
|
35
35
|
export declare function findBlockAncestorDOM(editorView: EditorView, pos: number): HTMLElement | null;
|
|
36
|
+
/**
|
|
37
|
+
* Positions the paste menu inline, immediately to the right of the cursor
|
|
38
|
+
* at the paste end position, vertically centered with the line.
|
|
39
|
+
* Used for short pastes without AI actions.
|
|
40
|
+
*/
|
|
41
|
+
export declare function onInlinePositionCalculated(editorView: EditorView, pasteEndPos: number, targetElement: HTMLElement, popupContentRef: React.RefObject<HTMLDivElement | null>): (position: {
|
|
42
|
+
bottom?: number;
|
|
43
|
+
left?: number;
|
|
44
|
+
right?: number;
|
|
45
|
+
top?: number;
|
|
46
|
+
}) => {
|
|
47
|
+
bottom?: number;
|
|
48
|
+
left?: number;
|
|
49
|
+
right?: number;
|
|
50
|
+
top: number;
|
|
51
|
+
};
|
|
36
52
|
/**
|
|
37
53
|
* Adjusts the position of the paste menu so that:
|
|
38
54
|
*
|
|
@@ -2,8 +2,9 @@ import React from 'react';
|
|
|
2
2
|
import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
|
|
3
3
|
interface PasteActionsMenuContentProps {
|
|
4
4
|
components: RegisterComponent[];
|
|
5
|
+
contentRef?: React.RefObject<HTMLDivElement | null>;
|
|
5
6
|
onMouseDown: (e: React.MouseEvent) => void;
|
|
6
7
|
onMouseEnter: () => void;
|
|
7
8
|
}
|
|
8
|
-
export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, components, }: PasteActionsMenuContentProps) => React.JSX.Element;
|
|
9
|
+
export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, components, contentRef, }: PasteActionsMenuContentProps) => React.JSX.Element;
|
|
9
10
|
export {};
|