@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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 9.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [`fb9bbd5719238`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fb9bbd5719238) -
8
+ EDITOR-6193 Correcting `visibleAiActions` attribute of paste actions menu which was not being
9
+ populated.
10
+
11
+ ## 9.1.7
12
+
13
+ ### Patch Changes
14
+
15
+ - [`3b007c601e102`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3b007c601e102) -
16
+ EDITOR-6092 Remove 100 character limit on legacy paste actions for new editor AI paste actions
17
+ menu. Also redesigns the legacy paste actions to more closely resemble the legacy paste floating
18
+ toolbar when there are no AI actions present.
19
+ - Updated dependencies
20
+
3
21
  ## 9.1.6
4
22
 
5
23
  ### Patch Changes
@@ -9,6 +9,7 @@ exports.PasteActionsMenu = void 0;
9
9
  exports.findBlockAncestorDOM = findBlockAncestorDOM;
10
10
  exports.getTargetElement = getTargetElement;
11
11
  exports.getVisualEndBottom = getVisualEndBottom;
12
+ exports.onInlinePositionCalculated = onInlinePositionCalculated;
12
13
  exports.onPositionCalculated = onPositionCalculated;
13
14
  exports.resolveTableAfterPos = resolveTableAfterPos;
14
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -118,6 +119,35 @@ function findBlockAncestorDOM(editorView, pos) {
118
119
  return null;
119
120
  }
120
121
 
122
+ /**
123
+ * Positions the paste menu inline, immediately to the right of the cursor
124
+ * at the paste end position, vertically centered with the line.
125
+ * Used for short pastes without AI actions.
126
+ */
127
+ function onInlinePositionCalculated(editorView, pasteEndPos, targetElement, popupContentRef) {
128
+ return function (position) {
129
+ var _popupContentRef$curr, _popupContentRef$curr2, _position$top, _position$left;
130
+ var endCoords = editorView.coordsAtPos(pasteEndPos);
131
+ var targetRect = targetElement.getBoundingClientRect();
132
+
133
+ // Vertical: center the menu with the line at the paste end position.
134
+ var lineHeight = endCoords.bottom - endCoords.top;
135
+ var lineMidpoint = endCoords.top + lineHeight / 2;
136
+ 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;
137
+ var menuTop = lineMidpoint - menuHeight / 2;
138
+ var topDelta = menuTop - (targetRect.top + targetRect.height);
139
+ var adjustedTop = ((_position$top = position.top) !== null && _position$top !== void 0 ? _position$top : 0) + topDelta;
140
+
141
+ // Horizontal: position to the right of the cursor
142
+ var leftDelta = endCoords.right - targetRect.right;
143
+ var adjustedLeft = ((_position$left = position.left) !== null && _position$left !== void 0 ? _position$left : 0) + leftDelta;
144
+ return _objectSpread(_objectSpread({}, position), {}, {
145
+ top: adjustedTop,
146
+ left: adjustedLeft
147
+ });
148
+ };
149
+ }
150
+
121
151
  /**
122
152
  * Adjusts the position of the paste menu so that:
123
153
  *
@@ -148,7 +178,7 @@ function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElem
148
178
  var tableAfterPos = resolveTableAfterPos(editorView, pasteEndPos);
149
179
  var blockAncestorDOM = findBlockAncestorDOM(editorView, pasteStartPos);
150
180
  return function (position) {
151
- var _position$top;
181
+ var _position$top2;
152
182
  var startCoords = editorView.coordsAtPos(pasteStartPos);
153
183
  var endBottom = getVisualEndBottom(editorView, pasteEndPos, tableAfterPos);
154
184
  var targetRect = targetElement.getBoundingClientRect();
@@ -158,7 +188,7 @@ function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElem
158
188
  // We shift it up so it aligns with the paste start position.
159
189
  // Both coordinates are in viewport space, so the delta is offset-parent agnostic.
160
190
  var topDelta = startCoords.top - (targetRect.top + targetRect.height);
161
- var adjustedTop = ((_position$top = position.top) !== null && _position$top !== void 0 ? _position$top : 0) + topDelta;
191
+ var adjustedTop = ((_position$top2 = position.top) !== null && _position$top2 !== void 0 ? _position$top2 : 0) + topDelta;
162
192
 
163
193
  // Sticky-top: clamp to the scroll container's top edge when the paste
164
194
  // start has scrolled above the visible area, but only while some pasted
@@ -180,13 +210,13 @@ function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElem
180
210
  // re-anchoring to its right edge.
181
211
  var adjustedLeft = position.left;
182
212
  if (blockAncestorDOM && blockAncestorDOM !== targetElement) {
183
- var _position$left;
213
+ var _position$left2;
184
214
  var blockRect = blockAncestorDOM.getBoundingClientRect();
185
215
  // Shift left by the difference between the block's right edge and
186
216
  // the inline target's right edge. This mirrors what alignX="end"
187
217
  // would have computed if the target were the block element.
188
218
  var leftDelta = blockRect.right - targetRect.right;
189
- adjustedLeft = ((_position$left = position.left) !== null && _position$left !== void 0 ? _position$left : 0) + leftDelta;
219
+ adjustedLeft = ((_position$left2 = position.left) !== null && _position$left2 !== void 0 ? _position$left2 : 0) + leftDelta;
190
220
  }
191
221
  return _objectSpread(_objectSpread({}, position), {}, {
192
222
  top: adjustedTop,
@@ -195,7 +225,7 @@ function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, targetElem
195
225
  };
196
226
  }
197
227
  var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref) {
198
- var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
228
+ var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2;
199
229
  var api = _ref.api,
200
230
  editorView = _ref.editorView,
201
231
  mountTo = _ref.mountTo,
@@ -210,8 +240,8 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
210
240
  }),
211
241
  lastContentPasted = _useSharedPluginState.lastContentPasted;
212
242
  var prevShowToolbarRef = (0, _react.useRef)(false);
243
+ var popupContentRef = (0, _react.useRef)(null);
213
244
  (0, _react.useEffect)(function () {
214
- var _lastContentPasted$te, _lastContentPasted$te2;
215
245
  if (!lastContentPasted) {
216
246
  (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
217
247
  return;
@@ -234,7 +264,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
234
264
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
235
265
  }
236
266
  }
237
- var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
267
+ var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted);
238
268
  (0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
239
269
  }, [lastContentPasted, editorView]);
240
270
  var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
@@ -249,22 +279,6 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
249
279
  isToolbarShown = _useSharedPluginState2.showToolbar,
250
280
  pasteStartPos = _useSharedPluginState2.pasteStartPos,
251
281
  pasteEndPos = _useSharedPluginState2.pasteEndPos;
252
- 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 : [];
253
- var visibleAiActionKeys = (0, _hasVisibleButton.getVisibleKeys)(aiSurfaceComponents, ['button', 'menu-item']);
254
- (0, _react.useEffect)(function () {
255
- if (!prevShowToolbarRef.current && isToolbarShown) {
256
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
257
- action: _analytics.ACTION.OPENED,
258
- actionSubject: _analytics.ACTION_SUBJECT.PASTE_ACTIONS_MENU,
259
- eventType: _analytics.EVENT_TYPE.UI,
260
- attributes: {
261
- visibleAiActions: visibleAiActionKeys
262
- }
263
- });
264
- }
265
- prevShowToolbarRef.current = isToolbarShown;
266
- // eslint-disable-next-line react-hooks/exhaustive-deps
267
- }, [isToolbarShown, editorAnalyticsAPI]);
268
282
  var preventEditorFocusLoss = (0, _react.useCallback)(function (e) {
269
283
  e.preventDefault();
270
284
  }, []);
@@ -296,18 +310,54 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
296
310
  // onPositionCalculated with fresh viewport coordinates.
297
311
  var overflowScrollParent = isToolbarShown ? (0, _ui.findOverflowScrollParent)(editorView.dom) : false;
298
312
  var effectiveScrollableElement = overflowScrollParent || scrollableElement;
299
- var pasteMenuComponents = (_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 : [];
313
+ 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 : [];
300
314
  var anyComponentVisible = (0, _hasVisibleButton.hasVisibleButton)(pasteMenuComponents);
315
+
316
+ // eslint-disable-next-line @atlassian/perf-linting/no-expensive-computations-in-render -- pasteMenuComponents changes by reference each render; filter is small (< 10 items)
317
+ var aiMenuItems = pasteMenuComponents.filter(function (c) {
318
+ var _c$parents;
319
+ return c.type === 'menu-item' && ((_c$parents = c.parents) === null || _c$parents === void 0 ? void 0 : _c$parents.some(function (p) {
320
+ return p.key === _toolbar.AI_PASTE_MENU_SECTION.key;
321
+ }));
322
+ });
323
+ var visibleAiActionKeys = (0, _hasVisibleButton.getVisibleKeys)(aiMenuItems, ['menu-item']);
324
+
325
+ // Two positioning modes:
326
+ // 1. Inline: no AI actions visible — menu appears to the right of the cursor,
327
+ // vertically centered with the text line.
328
+ // 2. Block-anchored: AI actions are visible — menu appears at the right edge
329
+ // of the content block, aligned with paste start.
330
+ var hasVisibleAiActions = visibleAiActionKeys.length > 0;
331
+ (0, _react.useEffect)(function () {
332
+ if (!prevShowToolbarRef.current && isToolbarShown) {
333
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
334
+ action: _analytics.ACTION.OPENED,
335
+ actionSubject: _analytics.ACTION_SUBJECT.PASTE_ACTIONS_MENU,
336
+ eventType: _analytics.EVENT_TYPE.UI,
337
+ attributes: {
338
+ visibleAiActions: visibleAiActionKeys
339
+ }
340
+ });
341
+ }
342
+ prevShowToolbarRef.current = isToolbarShown;
343
+ // eslint-disable-next-line react-hooks/exhaustive-deps
344
+ }, [isToolbarShown, editorAnalyticsAPI]);
345
+ var useInlinePosition = !hasVisibleAiActions;
301
346
  if (!isToolbarShown) {
302
347
  return null;
303
348
  }
304
349
  if (!anyComponentVisible) {
305
350
  return null;
306
351
  }
307
- var target = getTargetElement(editorView, pasteStartPos);
352
+ var target = getTargetElement(editorView, useInlinePosition ? pasteEndPos : pasteStartPos);
308
353
  if (!target) {
309
354
  return null;
310
355
  }
356
+
357
+ // Choose positioning strategy based on whether the menu appears inline
358
+ // (right of cursor for short pastes) or anchored to the block ancestor
359
+ // (right side of content area for longer pastes / AI actions).
360
+ var positionCalculator = useInlinePosition ? onInlinePositionCalculated(editorView, pasteEndPos, target, popupContentRef) : onPositionCalculated(editorView, pasteStartPos, pasteEndPos, target, effectiveScrollableElement);
311
361
  return /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
312
362
  target: target,
313
363
  mountTo: mountTo,
@@ -316,10 +366,10 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
316
366
  minPopupMargin: _constants.PASTE_MENU_GAP_HORIZONTAL,
317
367
  zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex,
318
368
  alignX: "end",
319
- alignY: "bottom"
369
+ alignY: useInlinePosition ? 'top' : 'bottom'
320
370
  /* eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) */,
321
371
  offset: [_constants.PASTE_MENU_GAP_HORIZONTAL, 0],
322
- onPositionCalculated: onPositionCalculated(editorView, pasteStartPos, pasteEndPos, target, effectiveScrollableElement),
372
+ onPositionCalculated: positionCalculator,
323
373
  handleClickOutside: handleClickOutside,
324
374
  handleEscapeKeydown: handleDismiss
325
375
  }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarProvider, {
@@ -330,6 +380,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
330
380
  }, /*#__PURE__*/_react.default.createElement(_PasteActionsMenuContent.PasteActionsMenuContent, {
331
381
  onMouseDown: preventEditorFocusLoss,
332
382
  onMouseEnter: handleMouseEnter,
333
- components: pasteMenuComponents
383
+ components: pasteMenuComponents,
384
+ contentRef: popupContentRef
334
385
  }))));
335
386
  };
@@ -9,34 +9,37 @@ 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
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
14
13
  var _uiReact = require("@atlaskit/editor-common/ui-react");
15
- var _editorToolbar = require("@atlaskit/editor-toolbar");
16
14
  var _editorUiControlModel = require("@atlaskit/editor-ui-control-model");
17
15
  var _compiled = require("@atlaskit/primitives/compiled");
18
16
  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
17
  var styles = {
20
18
  container: "_2rko12b0 _bfhk1bhr _16qs130s"
21
19
  };
20
+ var pasteMenuSurface = {
21
+ type: _toolbar.PASTE_MENU.type,
22
+ key: _toolbar.PASTE_MENU.key
23
+ };
22
24
  var PasteActionsMenuContent = exports.PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
23
25
  var onMouseDown = _ref.onMouseDown,
24
26
  onMouseEnter = _ref.onMouseEnter,
25
- components = _ref.components;
27
+ components = _ref.components,
28
+ contentRef = _ref.contentRef;
26
29
  var setOutsideClickTargetRef = (0, _react.useContext)(_uiReact.OutsideClickTargetRefContext);
27
- var intl = (0, _reactIntlNext.useIntl)();
30
+ var mergedRef = (0, _react.useCallback)(function (node) {
31
+ setOutsideClickTargetRef === null || setOutsideClickTargetRef === void 0 || setOutsideClickTargetRef(node);
32
+ if (contentRef) {
33
+ contentRef.current = node;
34
+ }
35
+ }, [setOutsideClickTargetRef, contentRef]);
28
36
  return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
29
- ref: setOutsideClickTargetRef,
37
+ ref: mergedRef,
30
38
  xcss: styles.container,
31
39
  onMouseDown: onMouseDown,
32
40
  onMouseEnter: onMouseEnter
33
- }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
34
- title: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteMenuActionsTitle)
35
41
  }, /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
36
- surface: {
37
- type: 'menu',
38
- key: 'paste-menu'
39
- },
42
+ surface: pasteMenuSurface,
40
43
  components: components
41
- })));
44
+ }));
42
45
  };
@@ -16,12 +16,14 @@ var _hooks = require("@atlaskit/editor-common/hooks");
16
16
  var _messages = require("@atlaskit/editor-common/messages");
17
17
  var _toolbar = require("@atlaskit/editor-common/toolbar");
18
18
  var _editorToolbar = require("@atlaskit/editor-toolbar");
19
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/core/chevron-down"));
19
20
  var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
20
21
  var _clipboard = _interopRequireDefault(require("@atlaskit/icon/core/clipboard"));
21
22
  var _compiled = require("@atlaskit/primitives/compiled");
22
23
  var _commands = require("../../editor-commands/commands");
23
24
  var _types = require("../../types/types");
24
25
  var _hasVisibleButton = require("./hasVisibleButton");
26
+ var _PasteOptionsDropdownButton = require("./PasteOptionsDropdownButton");
25
27
  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); }
26
28
  var nestedMenuStyles = {
27
29
  narrowSection: "_10gv1lit"
@@ -100,21 +102,49 @@ var PasteMenuItem = function PasteMenuItem(_ref) {
100
102
  }, displayLabel);
101
103
  };
102
104
  var PasteOptionsNestedMenu = function PasteOptionsNestedMenu(_ref2) {
103
- var children = _ref2.children;
105
+ var children = _ref2.children,
106
+ hasVisibleAiActions = _ref2.hasVisibleAiActions;
104
107
  var intl = (0, _reactIntlNext.useIntl)();
108
+ var label = intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteMenuActionsPasteAs);
109
+ if (!hasVisibleAiActions) {
110
+ return /*#__PURE__*/_react.default.createElement(_PasteOptionsDropdownButton.PasteOptionsDropdownButton, {
111
+ elemBefore: /*#__PURE__*/_react.default.createElement(_clipboard.default, {
112
+ size: "small",
113
+ label: ""
114
+ }),
115
+ elemAfter: /*#__PURE__*/_react.default.createElement(_chevronDown.default, {
116
+ size: "small",
117
+ label: ""
118
+ }),
119
+ label: label,
120
+ testId: "paste-options-nested-menu",
121
+ tooltipContent: label
122
+ }, children);
123
+ }
105
124
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarNestedDropdownMenu, {
106
125
  elemBefore: /*#__PURE__*/_react.default.createElement(_clipboard.default, {
107
126
  size: "small",
108
- label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteOptions)
127
+ label: label
109
128
  }),
110
129
  elemAfter: /*#__PURE__*/_react.default.createElement(_chevronRight.default, {
111
130
  size: "small",
112
- label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteOptions)
131
+ label: ""
113
132
  }),
114
133
  testId: "paste-options-nested-menu",
115
- text: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteOptions)
134
+ text: label
116
135
  }, children);
117
136
  };
137
+ var getHasVisibleAiActions = function getHasVisibleAiActions(api) {
138
+ var _api$uiControlRegistr, _api$uiControlRegistr2;
139
+ var allComponents = (_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 : [];
140
+ var aiMenuItems = allComponents.filter(function (c) {
141
+ var _c$parents;
142
+ return c.type === 'menu-item' && ((_c$parents = c.parents) === null || _c$parents === void 0 ? void 0 : _c$parents.some(function (p) {
143
+ return p.key === _toolbar.AI_PASTE_MENU_SECTION.key;
144
+ }));
145
+ });
146
+ return (0, _hasVisibleButton.getVisibleKeys)(aiMenuItems, ['menu-item']).length > 0;
147
+ };
118
148
  var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
119
149
  var api = _ref3.api;
120
150
  return [{
@@ -134,17 +164,14 @@ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteM
134
164
  return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
135
165
  },
136
166
  component: function component(props) {
137
- var _api$uiControlRegistr, _api$uiControlRegistr2;
138
- var allComponents = (_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 : [];
139
- var aiMenuItems = allComponents.filter(function (c) {
140
- var _c$parents;
141
- return c.type === 'menu-item' && ((_c$parents = c.parents) === null || _c$parents === void 0 ? void 0 : _c$parents.some(function (p) {
142
- return p.key === _toolbar.AI_PASTE_MENU_SECTION.key;
143
- }));
144
- });
145
- var hasVisibleAiActions = (0, _hasVisibleButton.getVisibleKeys)(aiMenuItems, ['menu-item']).length > 0;
167
+ var hasVisibleAiActions = getHasVisibleAiActions(api);
168
+ if (!hasVisibleAiActions) {
169
+ return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
170
+ padding: "space.050"
171
+ }, props.children);
172
+ }
146
173
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
147
- hasSeparator: hasVisibleAiActions
174
+ hasSeparator: true
148
175
  }, props.children);
149
176
  }
150
177
  }, {
@@ -156,7 +183,10 @@ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteM
156
183
  rank: _toolbar.PASTE_MENU_SECTION_RANK[_toolbar.PASTE_NESTED_MENU.key]
157
184
  }],
158
185
  component: function component(props) {
159
- return /*#__PURE__*/_react.default.createElement(PasteOptionsNestedMenu, null, props.children);
186
+ var hasVisibleAiActions = getHasVisibleAiActions(api);
187
+ return /*#__PURE__*/_react.default.createElement(PasteOptionsNestedMenu, {
188
+ hasVisibleAiActions: hasVisibleAiActions
189
+ }, props.children);
160
190
  }
161
191
  }, {
162
192
  type: _toolbar.PASTE_MENU_NESTED_SECTION.type,
@@ -0,0 +1,52 @@
1
+ /* PasteOptionsDropdownButton.tsx generated by @compiled/babel-plugin v0.39.1 */
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.PasteOptionsDropdownButton = void 0;
10
+ var _runtime = require("@compiled/react/runtime");
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var _dropdownMenu = _interopRequireDefault(require("@atlaskit/dropdown-menu"));
13
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
14
+ 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); }
15
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
16
+ /**
17
+ * A compact dropdown button for paste options, styled like floating toolbar buttons.
18
+ * Renders as a ToolbarButton with an icon and dropdown caret that opens a
19
+ * dropdown menu below. Used when AI actions are not visible and the paste
20
+ * options menu is the only content.
21
+ */
22
+ var PasteOptionsDropdownButton = exports.PasteOptionsDropdownButton = function PasteOptionsDropdownButton(_ref) {
23
+ var children = _ref.children,
24
+ elemBefore = _ref.elemBefore,
25
+ elemAfter = _ref.elemAfter,
26
+ label = _ref.label,
27
+ testId = _ref.testId,
28
+ tooltipContent = _ref.tooltipContent;
29
+ var trigger = (0, _react.useCallback)(function (triggerProps) {
30
+ var button = /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
31
+ ref: triggerProps.triggerRef,
32
+ isSelected: triggerProps.isSelected,
33
+ "aria-expanded": triggerProps['aria-expanded'],
34
+ "aria-haspopup": triggerProps['aria-haspopup'],
35
+ onClick: triggerProps.onClick,
36
+ testId: testId,
37
+ iconBefore: elemBefore,
38
+ label: label
39
+ }, elemAfter);
40
+ if (tooltipContent) {
41
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, {
42
+ content: tooltipContent,
43
+ position: "top"
44
+ }, button);
45
+ }
46
+ return button;
47
+ }, [testId, elemBefore, elemAfter, label, tooltipContent]);
48
+ return /*#__PURE__*/_react.default.createElement(_dropdownMenu.default, {
49
+ placement: "bottom-start",
50
+ trigger: trigger
51
+ }, children);
52
+ };
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback, useEffect, useRef } from 'react';
2
2
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
3
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
- import { EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
4
+ import { AI_PASTE_MENU_SECTION, EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
5
5
  import { findOverflowScrollParent, Popup } from '@atlaskit/editor-common/ui';
6
6
  import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
7
7
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
@@ -101,6 +101,36 @@ export function findBlockAncestorDOM(editorView, pos) {
101
101
  return null;
102
102
  }
103
103
 
104
+ /**
105
+ * Positions the paste menu inline, immediately to the right of the cursor
106
+ * at the paste end position, vertically centered with the line.
107
+ * Used for short pastes without AI actions.
108
+ */
109
+ export function onInlinePositionCalculated(editorView, pasteEndPos, targetElement, popupContentRef) {
110
+ return position => {
111
+ var _popupContentRef$curr, _popupContentRef$curr2, _position$top, _position$left;
112
+ const endCoords = editorView.coordsAtPos(pasteEndPos);
113
+ const targetRect = targetElement.getBoundingClientRect();
114
+
115
+ // Vertical: center the menu with the line at the paste end position.
116
+ const lineHeight = endCoords.bottom - endCoords.top;
117
+ const lineMidpoint = endCoords.top + lineHeight / 2;
118
+ const 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;
119
+ const menuTop = lineMidpoint - menuHeight / 2;
120
+ const topDelta = menuTop - (targetRect.top + targetRect.height);
121
+ const adjustedTop = ((_position$top = position.top) !== null && _position$top !== void 0 ? _position$top : 0) + topDelta;
122
+
123
+ // Horizontal: position to the right of the cursor
124
+ const leftDelta = endCoords.right - targetRect.right;
125
+ const adjustedLeft = ((_position$left = position.left) !== null && _position$left !== void 0 ? _position$left : 0) + leftDelta;
126
+ return {
127
+ ...position,
128
+ top: adjustedTop,
129
+ left: adjustedLeft
130
+ };
131
+ };
132
+ }
133
+
104
134
  /**
105
135
  * Adjusts the position of the paste menu so that:
106
136
  *
@@ -131,7 +161,7 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
131
161
  const tableAfterPos = resolveTableAfterPos(editorView, pasteEndPos);
132
162
  const blockAncestorDOM = findBlockAncestorDOM(editorView, pasteStartPos);
133
163
  return position => {
134
- var _position$top;
164
+ var _position$top2;
135
165
  const startCoords = editorView.coordsAtPos(pasteStartPos);
136
166
  const endBottom = getVisualEndBottom(editorView, pasteEndPos, tableAfterPos);
137
167
  const targetRect = targetElement.getBoundingClientRect();
@@ -141,7 +171,7 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
141
171
  // We shift it up so it aligns with the paste start position.
142
172
  // Both coordinates are in viewport space, so the delta is offset-parent agnostic.
143
173
  const topDelta = startCoords.top - (targetRect.top + targetRect.height);
144
- let adjustedTop = ((_position$top = position.top) !== null && _position$top !== void 0 ? _position$top : 0) + topDelta;
174
+ let adjustedTop = ((_position$top2 = position.top) !== null && _position$top2 !== void 0 ? _position$top2 : 0) + topDelta;
145
175
 
146
176
  // Sticky-top: clamp to the scroll container's top edge when the paste
147
177
  // start has scrolled above the visible area, but only while some pasted
@@ -163,13 +193,13 @@ export function onPositionCalculated(editorView, pasteStartPos, pasteEndPos, tar
163
193
  // re-anchoring to its right edge.
164
194
  let adjustedLeft = position.left;
165
195
  if (blockAncestorDOM && blockAncestorDOM !== targetElement) {
166
- var _position$left;
196
+ var _position$left2;
167
197
  const blockRect = blockAncestorDOM.getBoundingClientRect();
168
198
  // Shift left by the difference between the block's right edge and
169
199
  // the inline target's right edge. This mirrors what alignX="end"
170
200
  // would have computed if the target were the block element.
171
201
  const leftDelta = blockRect.right - targetRect.right;
172
- adjustedLeft = ((_position$left = position.left) !== null && _position$left !== void 0 ? _position$left : 0) + leftDelta;
202
+ adjustedLeft = ((_position$left2 = position.left) !== null && _position$left2 !== void 0 ? _position$left2 : 0) + leftDelta;
173
203
  }
174
204
  return {
175
205
  ...position,
@@ -185,7 +215,7 @@ export const PasteActionsMenu = ({
185
215
  boundariesElement,
186
216
  scrollableElement
187
217
  }) => {
188
- var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
218
+ var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2;
189
219
  const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
190
220
  const {
191
221
  lastContentPasted
@@ -196,8 +226,8 @@ export const PasteActionsMenu = ({
196
226
  };
197
227
  });
198
228
  const prevShowToolbarRef = useRef(false);
229
+ const popupContentRef = useRef(null);
199
230
  useEffect(() => {
200
- var _lastContentPasted$te, _lastContentPasted$te2;
201
231
  if (!lastContentPasted) {
202
232
  hideToolbar()(editorView.state, editorView.dispatch);
203
233
  return;
@@ -220,7 +250,7 @@ export const PasteActionsMenu = ({
220
250
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
221
251
  }
222
252
  }
223
- const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
253
+ const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
224
254
  showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
225
255
  }, [lastContentPasted, editorView]);
226
256
  const {
@@ -236,22 +266,6 @@ export const PasteActionsMenu = ({
236
266
  pasteEndPos: (_pluginState$pasteEnd = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteEndPos) !== null && _pluginState$pasteEnd !== void 0 ? _pluginState$pasteEnd : 0
237
267
  };
238
268
  });
239
- 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('ai-paste-menu')) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
240
- const visibleAiActionKeys = getVisibleKeys(aiSurfaceComponents, ['button', 'menu-item']);
241
- useEffect(() => {
242
- if (!prevShowToolbarRef.current && isToolbarShown) {
243
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
244
- action: ACTION.OPENED,
245
- actionSubject: ACTION_SUBJECT.PASTE_ACTIONS_MENU,
246
- eventType: EVENT_TYPE.UI,
247
- attributes: {
248
- visibleAiActions: visibleAiActionKeys
249
- }
250
- });
251
- }
252
- prevShowToolbarRef.current = isToolbarShown;
253
- // eslint-disable-next-line react-hooks/exhaustive-deps
254
- }, [isToolbarShown, editorAnalyticsAPI]);
255
269
  const preventEditorFocusLoss = useCallback(e => {
256
270
  e.preventDefault();
257
271
  }, []);
@@ -283,18 +297,52 @@ export const PasteActionsMenu = ({
283
297
  // onPositionCalculated with fresh viewport coordinates.
284
298
  const overflowScrollParent = isToolbarShown ? findOverflowScrollParent(editorView.dom) : false;
285
299
  const effectiveScrollableElement = overflowScrollParent || scrollableElement;
286
- const pasteMenuComponents = (_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 : [];
300
+ 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 : [];
287
301
  const anyComponentVisible = hasVisibleButton(pasteMenuComponents);
302
+
303
+ // eslint-disable-next-line @atlassian/perf-linting/no-expensive-computations-in-render -- pasteMenuComponents changes by reference each render; filter is small (< 10 items)
304
+ const aiMenuItems = pasteMenuComponents.filter(c => {
305
+ var _c$parents;
306
+ 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));
307
+ });
308
+ const 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
+ const hasVisibleAiActions = visibleAiActionKeys.length > 0;
316
+ useEffect(() => {
317
+ if (!prevShowToolbarRef.current && isToolbarShown) {
318
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? 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
+ const useInlinePosition = !hasVisibleAiActions;
288
331
  if (!isToolbarShown) {
289
332
  return null;
290
333
  }
291
334
  if (!anyComponentVisible) {
292
335
  return null;
293
336
  }
294
- const target = getTargetElement(editorView, pasteStartPos);
337
+ const target = getTargetElement(editorView, useInlinePosition ? pasteEndPos : pasteStartPos);
295
338
  if (!target) {
296
339
  return null;
297
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
+ const positionCalculator = useInlinePosition ? onInlinePositionCalculated(editorView, pasteEndPos, target, popupContentRef) : onPositionCalculated(editorView, pasteStartPos, pasteEndPos, target, effectiveScrollableElement);
298
346
  return /*#__PURE__*/React.createElement(PopupWithListeners, {
299
347
  target: target,
300
348
  mountTo: mountTo,
@@ -303,10 +351,10 @@ export const PasteActionsMenu = ({
303
351
  minPopupMargin: PASTE_MENU_GAP_HORIZONTAL,
304
352
  zIndex: akEditorFloatingPanelZIndex,
305
353
  alignX: "end",
306
- alignY: "bottom"
354
+ alignY: useInlinePosition ? 'top' : 'bottom'
307
355
  /* eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) */,
308
356
  offset: [PASTE_MENU_GAP_HORIZONTAL, 0],
309
- onPositionCalculated: onPositionCalculated(editorView, pasteStartPos, pasteEndPos, target, effectiveScrollableElement),
357
+ onPositionCalculated: positionCalculator,
310
358
  handleClickOutside: handleClickOutside,
311
359
  handleEscapeKeydown: handleDismiss
312
360
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
@@ -317,6 +365,7 @@ export const PasteActionsMenu = ({
317
365
  }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
318
366
  onMouseDown: preventEditorFocusLoss,
319
367
  onMouseEnter: handleMouseEnter,
320
- components: pasteMenuComponents
368
+ components: pasteMenuComponents,
369
+ contentRef: popupContentRef
321
370
  }))));
322
371
  };