@atlaskit/editor-common 135.0.0 → 135.1.0

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/ai-messages/ai-suggestions.js +1 -1
  3. package/dist/cjs/credit-guard/CreditCheckedPopup.js +69 -15
  4. package/dist/cjs/monitoring/error.js +1 -1
  5. package/dist/cjs/quick-insert/CompactQuickInsertMenuItem.js +16 -2
  6. package/dist/cjs/quick-insert/ElementBrowserQuickInsertMenuItem.js +15 -1
  7. package/dist/cjs/quick-insert/QuickInsertMenuItem.js +9 -0
  8. package/dist/cjs/quick-insert/quickInsertMenuItemUtils.js +6 -3
  9. package/dist/cjs/ui/DropList/index.js +1 -1
  10. package/dist/es2019/ai-messages/ai-suggestions.js +1 -1
  11. package/dist/es2019/credit-guard/CreditCheckedPopup.js +66 -16
  12. package/dist/es2019/monitoring/error.js +1 -1
  13. package/dist/es2019/quick-insert/CompactQuickInsertMenuItem.js +17 -3
  14. package/dist/es2019/quick-insert/ElementBrowserQuickInsertMenuItem.js +16 -2
  15. package/dist/es2019/quick-insert/QuickInsertMenuItem.js +9 -0
  16. package/dist/es2019/quick-insert/quickInsertMenuItemUtils.js +11 -6
  17. package/dist/es2019/ui/DropList/index.js +1 -1
  18. package/dist/esm/ai-messages/ai-suggestions.js +1 -1
  19. package/dist/esm/credit-guard/CreditCheckedPopup.js +70 -16
  20. package/dist/esm/monitoring/error.js +1 -1
  21. package/dist/esm/quick-insert/CompactQuickInsertMenuItem.js +17 -3
  22. package/dist/esm/quick-insert/ElementBrowserQuickInsertMenuItem.js +16 -2
  23. package/dist/esm/quick-insert/QuickInsertMenuItem.js +9 -0
  24. package/dist/esm/quick-insert/quickInsertMenuItemUtils.js +6 -3
  25. package/dist/esm/ui/DropList/index.js +1 -1
  26. package/dist/types/quick-insert/CompactQuickInsertMenuItem.d.ts +1 -1
  27. package/dist/types/quick-insert/ElementBrowserQuickInsertMenuItem.d.ts +1 -1
  28. package/dist/types/quick-insert/QuickInsertMenuItem.d.ts +5 -1
  29. package/dist/types/quick-insert/quickInsertMenuItemUtils.d.ts +1 -1
  30. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 135.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`381ba99e12072`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/381ba99e12072) -
8
+ Add selection-preflight, item-ref, and popup relationship props to the exported
9
+ QuickInsertMenuItem. Forward Jira's optional cached credit-status callback for
10
+ jira_ai_ubp_enforcement_messaging and block depleted Ask Rovo slash-menu selection before the host
11
+ closes the menu. Keep Escape dismissal of blocked feedback inside the popup, preserve the editor
12
+ draft, and restore focus to the control that had focus before the popup opened after popup content
13
+ exits. Keep owned credit popups inside the registered menu focus boundary. Keep credit feedback
14
+ above the containing modal. Guard Remix in the More Rovo options menu with the same cached
15
+ callback, keeping blocked feedback mounted and preserving the original action when credits are
16
+ available.
17
+
18
+ ### Patch Changes
19
+
20
+ - [`627dd84c1342a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/627dd84c1342a) -
21
+ Correct the review prompt localisation guidance to reference the current
22
+ add-suggestions-to-content skill.
23
+ - Updated dependencies
24
+
3
25
  ## 135.0.0
4
26
 
5
27
  ### Major Changes
@@ -19,7 +19,7 @@ var aiSuggestionsMessages = exports.aiSuggestionsMessages = (0, _reactIntl.defin
19
19
  suggestEditsPromptPrefix: {
20
20
  id: 'fabric.editor.ai.suggestions.suggestEditsPromptPrefix.non-final',
21
21
  defaultMessage: 'Review my content with ',
22
- description: 'Localised text that precedes the suggest-edits skill tag in the prompt sent to the AI service. The trailing space is intentional — it separates this text from the skill tag that follows. Localise it in a way where the prompt ends with the skill tag. (With the skill tag it will look like e.g. "Review my content with /suggest-edits")'
22
+ description: 'Localised text that precedes the add-suggestions-to-content skill tag in the prompt sent to the AI service. The trailing space is intentional — it separates this text from the skill tag that follows. Localise it in a way where the prompt ends with the skill tag. (With the skill tag it will look like e.g. "Review my content with /add-suggestions-to-content")'
23
23
  },
24
24
  contentReviewAgentPrompt: {
25
25
  id: 'fabric.editor.ai.suggestions.contentReviewAgentPrompt.non-final',
@@ -47,6 +47,13 @@ var styles = {
47
47
  var stopPropagation = function stopPropagation(event) {
48
48
  return event.stopPropagation();
49
49
  };
50
+ var focusReturnTarget = function focusReturnTarget(preferredTarget, fallbackTarget) {
51
+ var isUsableTarget = function isUsableTarget(target) {
52
+ return Boolean((target === null || target === void 0 ? void 0 : target.isConnected) && target !== target.ownerDocument.body && target !== target.ownerDocument.documentElement);
53
+ };
54
+ var target = isUsableTarget(preferredTarget) ? preferredTarget : isUsableTarget(fallbackTarget) ? fallbackTarget : null;
55
+ target === null || target === void 0 || target.focus();
56
+ };
50
57
 
51
58
  /** Editor owns popup behavior; products supply content through getAICreditStatus. */
52
59
  var CreditPopup = function CreditPopup(_ref2) {
@@ -68,15 +75,60 @@ var CreditPopup = function CreditPopup(_ref2) {
68
75
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
69
76
  triggerElement = _useState4[0],
70
77
  setTriggerElement = _useState4[1];
78
+ // Menu search and editor inputs can keep focus when feedback opens.
79
+ // Remember that element so Escape returns focus there instead of to the trigger.
71
80
  var returnFocus = (0, _react.useRef)(null);
72
- var wasOpen = (0, _react.useRef)(false);
81
+ var isOpen = (0, _react.useRef)(feedback !== null);
82
+ isOpen.current = feedback !== null;
83
+ var restoreFocusAfterClose = (0, _react.useRef)(false);
84
+ (0, _react.useEffect)(function () {
85
+ if (!triggerElement) {
86
+ return;
87
+ }
88
+ var ownerDocument = triggerElement.ownerDocument;
89
+ var rememberFocus = function rememberFocus(target) {
90
+ if (!isOpen.current && !restoreFocusAfterClose.current && target instanceof HTMLElement && target !== ownerDocument.body && target !== ownerDocument.documentElement) {
91
+ returnFocus.current = target;
92
+ }
93
+ };
94
+ rememberFocus(ownerDocument.activeElement);
95
+ return (0, _bindEventListener.bind)(ownerDocument, {
96
+ type: 'focusin',
97
+ options: {
98
+ capture: true
99
+ },
100
+ listener: function listener(event) {
101
+ return rememberFocus(event.target);
102
+ }
103
+ });
104
+ }, [triggerElement]);
73
105
  (0, _react.useEffect)(function () {
74
- if (feedback && !wasOpen.current) {
75
- var active = triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.ownerDocument.activeElement;
76
- returnFocus.current = active instanceof HTMLElement ? active : null;
106
+ var _returnFocus$current;
107
+ if (feedback || contentElement || !restoreFocusAfterClose.current) {
108
+ return;
77
109
  }
78
- wasOpen.current = feedback !== null;
79
- }, [feedback, triggerElement]);
110
+ restoreFocusAfterClose.current = false;
111
+ var previousFocus = (_returnFocus$current = returnFocus.current) !== null && _returnFocus$current !== void 0 && _returnFocus$current.isConnected ? returnFocus.current : triggerElement;
112
+ focusReturnTarget(previousFocus, triggerElement);
113
+ }, [feedback, contentElement, triggerElement]);
114
+ (0, _react.useLayoutEffect)(function () {
115
+ if (!feedback || !contentElement) return;
116
+ var ownerDocument = contentElement.ownerDocument;
117
+ return (0, _bindEventListener.bind)(ownerDocument, {
118
+ type: 'keydown',
119
+ options: {
120
+ capture: true
121
+ },
122
+ listener: function listener(event) {
123
+ if (event.key !== 'Escape') return;
124
+ // The popup can leave focus in the editor, whose Escape handler cancels its draft.
125
+ event.preventDefault();
126
+ event.stopPropagation();
127
+ restoreFocusAfterClose.current = true;
128
+ close();
129
+ }
130
+ });
131
+ }, [feedback, contentElement, close]);
80
132
  (0, _react.useEffect)(function () {
81
133
  if (!feedback || !contentElement || !isNestedMenu) {
82
134
  return;
@@ -98,13 +150,10 @@ var CreditPopup = function CreditPopup(_ref2) {
98
150
  event.stopPropagation();
99
151
  if (event.key === 'Escape') {
100
152
  event.preventDefault();
153
+ restoreFocusAfterClose.current = true;
101
154
  close();
102
- if (isNestedMenu) {
103
- var _returnFocus$current;
104
- (_returnFocus$current = returnFocus.current) === null || _returnFocus$current === void 0 || _returnFocus$current.focus();
105
- }
106
155
  }
107
- }, [close, isNestedMenu]);
156
+ }, [close]);
108
157
  var content = (0, _react.useCallback)(function () {
109
158
  return /*#__PURE__*/_react.default.createElement(_box.Box, {
110
159
  ref: setContentElement,
@@ -129,10 +178,15 @@ var CreditPopup = function CreditPopup(_ref2) {
129
178
  titleId: (triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.id) || id,
130
179
  placement: placement,
131
180
  shouldFitViewport: true,
132
- shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false,
133
- zIndex: isNestedMenu ? _constants.akEditorFloatingDialogZIndex : undefined,
134
- strategy: isNestedMenu ? 'fixed' : undefined,
135
- shouldReturnFocus: !isNestedMenu,
181
+ shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false
182
+ // Credit feedback must share the modal layer when opened from a modal editor surface.
183
+ ,
184
+ zIndex: _constants.akEditorFloatingDialogZIndex,
185
+ strategy: isNestedMenu ? 'fixed' : undefined
186
+ // Our Escape handler restores focus after the popup unmounts.
187
+ // Disable automatic restoration so outside clicks keep focus on their target.
188
+ ,
189
+ shouldReturnFocus: false,
136
190
  shouldUseCaptureOnOutsideClick: true,
137
191
  content: content,
138
192
  trigger: trigger
@@ -27,7 +27,7 @@ var NETWORK_FAILURE_REGEX = /^network failure/i;
27
27
  var RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
28
28
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
29
29
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
30
- var packageVersion = "134.20.1";
30
+ var packageVersion = "135.0.0";
31
31
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
32
32
  // Remove URL as it has UGC
33
33
  // Ignored via go/ees007
@@ -95,11 +95,14 @@ var disabledItemStyles = (0, _xcss.xcss)({
95
95
  var CompactQuickInsertMenuItem = exports.CompactQuickInsertMenuItem = function CompactQuickInsertMenuItem(_ref) {
96
96
  var _resolvedPreview$attr, _ref3, _resolvedPreview$imag, _resolvedPreview$imag2;
97
97
  var ariaLabel = _ref.ariaLabel,
98
+ ariaControls = _ref['aria-controls'],
98
99
  description = _ref.description,
99
100
  iconBefore = _ref.iconBefore,
101
+ itemRef = _ref.itemRef,
100
102
  isDisabled = _ref.isDisabled,
101
103
  lozenge = _ref.lozenge,
102
104
  onSelect = _ref.onSelect,
105
+ onBeforeSelect = _ref.onBeforeSelect,
103
106
  preview = _ref.preview,
104
107
  previewIcon = _ref.previewIcon,
105
108
  previewImageUrls = _ref.previewImageUrls,
@@ -124,11 +127,21 @@ var CompactQuickInsertMenuItem = exports.CompactQuickInsertMenuItem = function C
124
127
  isSelected = _ref2.isSelected;
125
128
  var resolvedDescription = description !== null && description !== void 0 ? description : item === null || item === void 0 ? void 0 : item.description;
126
129
  var previewId = (0, _react.useId)();
127
- var handleClick = (0, _quickInsertMenuItemUtils.useQuickInsertMenuItemSelection)(onSelect);
130
+ var handleClick = (0, _quickInsertMenuItemUtils.useQuickInsertMenuItemSelection)(onSelect, onBeforeSelect);
128
131
  var _useState = (0, _react.useState)(null),
129
132
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
130
133
  referenceElement = _useState2[0],
131
134
  setReferenceElement = _useState2[1];
135
+ var setItemElement = (0, _react.useCallback)(function (element) {
136
+ setReferenceElement(element);
137
+ if (typeof itemRef === 'function') {
138
+ itemRef(element);
139
+ } else if (itemRef) {
140
+ Object.assign(itemRef, {
141
+ current: element
142
+ });
143
+ }
144
+ }, [itemRef]);
132
145
  var resolvedPreview = (0, _react.useMemo)(function () {
133
146
  return preview !== null && preview !== void 0 ? preview : previewImageUrls ? {
134
147
  image: previewImageUrls
@@ -145,8 +158,9 @@ var CompactQuickInsertMenuItem = exports.CompactQuickInsertMenuItem = function C
145
158
  xcss: styles.iconLarge
146
159
  }, iconBefore) : iconBefore;
147
160
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_pressable.Pressable, {
148
- ref: setReferenceElement,
161
+ ref: setItemElement,
149
162
  "aria-label": ariaLabel,
163
+ "aria-controls": ariaControls,
150
164
  "aria-describedby": shouldRenderPreview && hasAccessiblePreview ? previewId : undefined,
151
165
  "aria-selected": isSelected,
152
166
  id: id,
@@ -111,10 +111,13 @@ var pinnedIconColorResetStyles = null;
111
111
  */
112
112
  var ElementBrowserQuickInsertMenuItem = exports.ElementBrowserQuickInsertMenuItem = function ElementBrowserQuickInsertMenuItem(_ref) {
113
113
  var ariaLabel = _ref.ariaLabel,
114
+ ariaControls = _ref['aria-controls'],
115
+ itemRef = _ref.itemRef,
114
116
  description = _ref.description,
115
117
  iconBefore = _ref.iconBefore,
116
118
  _ref$isDisabled = _ref.isDisabled,
117
119
  isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
120
+ onBeforeSelect = _ref.onBeforeSelect,
118
121
  lozenge = _ref.lozenge,
119
122
  onSelect = _ref.onSelect,
120
123
  preview = _ref.preview,
@@ -131,7 +134,16 @@ var ElementBrowserQuickInsertMenuItem = exports.ElementBrowserQuickInsertMenuIte
131
134
  id = _ref2.id,
132
135
  isSelected = _ref2.isSelected;
133
136
  var itemDescription = description !== null && description !== void 0 ? description : item === null || item === void 0 ? void 0 : item.description;
134
- var handleClick = (0, _quickInsertMenuItemUtils.useQuickInsertMenuItemSelection)(onSelect);
137
+ var handleClick = (0, _quickInsertMenuItemUtils.useQuickInsertMenuItemSelection)(onSelect, onBeforeSelect);
138
+ var setItemElement = (0, _react.useCallback)(function (element) {
139
+ if (typeof itemRef === 'function') {
140
+ itemRef(element);
141
+ } else if (itemRef) {
142
+ Object.assign(itemRef, {
143
+ current: element
144
+ });
145
+ }
146
+ }, [itemRef]);
135
147
  var descriptionId = (0, _react.useId)();
136
148
  var resolvedPreview = (0, _react.useMemo)(function () {
137
149
  return preview !== null && preview !== void 0 ? preview : previewImageUrls ? {
@@ -143,6 +155,8 @@ var ElementBrowserQuickInsertMenuItem = exports.ElementBrowserQuickInsertMenuIte
143
155
  className: (0, _runtime.ax)(["_rpzpjdj5 _1pgcjdj5", !isDisabled && "_syaz1q3r"])
144
156
  }, iconBefore) : undefined;
145
157
  return /*#__PURE__*/_react.default.createElement(_pressable.Pressable, {
158
+ ref: setItemElement,
159
+ "aria-controls": ariaControls,
146
160
  "aria-describedby": hasDescription ? descriptionId : undefined,
147
161
  "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : title,
148
162
  "aria-selected": isSelected,
@@ -13,9 +13,12 @@ var _useQuickInsertContext = require("./useQuickInsertContext");
13
13
  var QuickInsertMenuItem = exports.QuickInsertMenuItem = function QuickInsertMenuItem(_ref) {
14
14
  var _surfaceContext$get;
15
15
  var ariaLabel = _ref.ariaLabel,
16
+ ariaControls = _ref['aria-controls'],
17
+ itemRef = _ref.itemRef,
16
18
  description = _ref.description,
17
19
  iconBefore = _ref.iconBefore,
18
20
  isDisabled = _ref.isDisabled,
21
+ onBeforeSelect = _ref.onBeforeSelect,
19
22
  lozenge = _ref.lozenge,
20
23
  onSelect = _ref.onSelect,
21
24
  preview = _ref.preview,
@@ -32,9 +35,12 @@ var QuickInsertMenuItem = exports.QuickInsertMenuItem = function QuickInsertMenu
32
35
  var surface = surfaceContext === null || surfaceContext === void 0 || (_surfaceContext$get = surfaceContext.get(_RegisteredMenuSurfaceContext.REGISTERED_MENU_SURFACE_CONTEXT)) === null || _surfaceContext$get === void 0 ? void 0 : _surfaceContext$get.surface;
33
36
  return surface === 'element-browser' ? /*#__PURE__*/_react.default.createElement(_ElementBrowserQuickInsertMenuItem.ElementBrowserQuickInsertMenuItem, {
34
37
  ariaLabel: ariaLabel,
38
+ "aria-controls": ariaControls,
39
+ itemRef: itemRef,
35
40
  description: description,
36
41
  iconBefore: iconBefore,
37
42
  isDisabled: isDisabled,
43
+ onBeforeSelect: onBeforeSelect,
38
44
  lozenge: lozenge,
39
45
  onSelect: onSelect,
40
46
  preview: preview,
@@ -44,9 +50,12 @@ var QuickInsertMenuItem = exports.QuickInsertMenuItem = function QuickInsertMenu
44
50
  title: title
45
51
  }) : /*#__PURE__*/_react.default.createElement(_CompactQuickInsertMenuItem.CompactQuickInsertMenuItem, {
46
52
  ariaLabel: ariaLabel,
53
+ "aria-controls": ariaControls,
54
+ itemRef: itemRef,
47
55
  description: description,
48
56
  iconBefore: iconBefore,
49
57
  isDisabled: isDisabled,
58
+ onBeforeSelect: onBeforeSelect,
50
59
  lozenge: lozenge,
51
60
  onSelect: onSelect,
52
61
  preview: preview,
@@ -6,17 +6,20 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useQuickInsertMenuItemSelection = void 0;
7
7
  var _react = require("react");
8
8
  var _useQuickInsertContext = require("./useQuickInsertContext");
9
- var useQuickInsertMenuItemSelection = exports.useQuickInsertMenuItemSelection = function useQuickInsertMenuItemSelection(onSelect) {
9
+ var useQuickInsertMenuItemSelection = exports.useQuickInsertMenuItemSelection = function useQuickInsertMenuItemSelection(onSelect, onBeforeSelect) {
10
10
  var _useQuickInsertContex = (0, _useQuickInsertContext.useQuickInsertContext)(),
11
11
  editorView = _useQuickInsertContex.editorView,
12
12
  select = _useQuickInsertContex.select;
13
13
  return (0, _react.useCallback)(function () {
14
- return select(function (selectionContext) {
14
+ if ((onBeforeSelect === null || onBeforeSelect === void 0 ? void 0 : onBeforeSelect()) === false) {
15
+ return;
16
+ }
17
+ select(function (selectionContext) {
15
18
  return onSelect({
16
19
  editorView: editorView,
17
20
  insert: selectionContext.insert,
18
21
  source: selectionContext.source
19
22
  });
20
23
  });
21
- }, [editorView, onSelect, select]);
24
+ }, [editorView, onBeforeSelect, onSelect, select]);
22
25
  };
@@ -23,7 +23,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
23
23
  * @jsx jsx
24
24
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
25
25
  var packageName = "@atlaskit/editor-common";
26
- var packageVersion = "134.20.1";
26
+ var packageVersion = "135.0.0";
27
27
  var halfFocusRing = 1;
28
28
  var dropOffset = '0, 8';
29
29
  // Ignored via go/ees005
@@ -13,7 +13,7 @@ export const aiSuggestionsMessages = defineMessages({
13
13
  suggestEditsPromptPrefix: {
14
14
  id: 'fabric.editor.ai.suggestions.suggestEditsPromptPrefix.non-final',
15
15
  defaultMessage: 'Review my content with ',
16
- description: 'Localised text that precedes the suggest-edits skill tag in the prompt sent to the AI service. The trailing space is intentional — it separates this text from the skill tag that follows. Localise it in a way where the prompt ends with the skill tag. (With the skill tag it will look like e.g. "Review my content with /suggest-edits")'
16
+ description: 'Localised text that precedes the add-suggestions-to-content skill tag in the prompt sent to the AI service. The trailing space is intentional — it separates this text from the skill tag that follows. Localise it in a way where the prompt ends with the skill tag. (With the skill tag it will look like e.g. "Review my content with /add-suggestions-to-content")'
17
17
  },
18
18
  contentReviewAgentPrompt: {
19
19
  id: 'fabric.editor.ai.suggestions.contentReviewAgentPrompt.non-final',
@@ -1,7 +1,7 @@
1
1
  /* CreditCheckedPopup.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./CreditCheckedPopup.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React, { useCallback, useEffect, useId, useRef, useState } from 'react';
4
+ import React, { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
5
5
  import { bind } from 'bind-event-listener';
6
6
  import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles/constants';
7
7
  import { Popup } from '@atlaskit/popup/popup';
@@ -34,6 +34,11 @@ const styles = {
34
34
  content: "_1bsb5jys _p12f1osq _vchhusvi _ca0qpxbi _u5f3pxbi _n3tdpxbi _19bvpxbi"
35
35
  };
36
36
  const stopPropagation = event => event.stopPropagation();
37
+ const focusReturnTarget = (preferredTarget, fallbackTarget) => {
38
+ const isUsableTarget = target => Boolean((target === null || target === void 0 ? void 0 : target.isConnected) && target !== target.ownerDocument.body && target !== target.ownerDocument.documentElement);
39
+ const target = isUsableTarget(preferredTarget) ? preferredTarget : isUsableTarget(fallbackTarget) ? fallbackTarget : null;
40
+ target === null || target === void 0 ? void 0 : target.focus();
41
+ };
37
42
 
38
43
  /** Editor owns popup behavior; products supply content through getAICreditStatus. */
39
44
  const CreditPopup = ({
@@ -49,15 +54,58 @@ const CreditPopup = ({
49
54
  const id = useId();
50
55
  const [contentElement, setContentElement] = useState(null);
51
56
  const [triggerElement, setTriggerElement] = useState(null);
57
+ // Menu search and editor inputs can keep focus when feedback opens.
58
+ // Remember that element so Escape returns focus there instead of to the trigger.
52
59
  const returnFocus = useRef(null);
53
- const wasOpen = useRef(false);
60
+ const isOpen = useRef(feedback !== null);
61
+ isOpen.current = feedback !== null;
62
+ const restoreFocusAfterClose = useRef(false);
63
+ useEffect(() => {
64
+ if (!triggerElement) {
65
+ return;
66
+ }
67
+ const ownerDocument = triggerElement.ownerDocument;
68
+ const rememberFocus = target => {
69
+ if (!isOpen.current && !restoreFocusAfterClose.current && target instanceof HTMLElement && target !== ownerDocument.body && target !== ownerDocument.documentElement) {
70
+ returnFocus.current = target;
71
+ }
72
+ };
73
+ rememberFocus(ownerDocument.activeElement);
74
+ return bind(ownerDocument, {
75
+ type: 'focusin',
76
+ options: {
77
+ capture: true
78
+ },
79
+ listener: event => rememberFocus(event.target)
80
+ });
81
+ }, [triggerElement]);
54
82
  useEffect(() => {
55
- if (feedback && !wasOpen.current) {
56
- const active = triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.ownerDocument.activeElement;
57
- returnFocus.current = active instanceof HTMLElement ? active : null;
83
+ var _returnFocus$current;
84
+ if (feedback || contentElement || !restoreFocusAfterClose.current) {
85
+ return;
58
86
  }
59
- wasOpen.current = feedback !== null;
60
- }, [feedback, triggerElement]);
87
+ restoreFocusAfterClose.current = false;
88
+ const previousFocus = (_returnFocus$current = returnFocus.current) !== null && _returnFocus$current !== void 0 && _returnFocus$current.isConnected ? returnFocus.current : triggerElement;
89
+ focusReturnTarget(previousFocus, triggerElement);
90
+ }, [feedback, contentElement, triggerElement]);
91
+ useLayoutEffect(() => {
92
+ if (!feedback || !contentElement) return;
93
+ const ownerDocument = contentElement.ownerDocument;
94
+ return bind(ownerDocument, {
95
+ type: 'keydown',
96
+ options: {
97
+ capture: true
98
+ },
99
+ listener: event => {
100
+ if (event.key !== 'Escape') return;
101
+ // The popup can leave focus in the editor, whose Escape handler cancels its draft.
102
+ event.preventDefault();
103
+ event.stopPropagation();
104
+ restoreFocusAfterClose.current = true;
105
+ close();
106
+ }
107
+ });
108
+ }, [feedback, contentElement, close]);
61
109
  useEffect(() => {
62
110
  if (!feedback || !contentElement || !isNestedMenu) {
63
111
  return;
@@ -79,13 +127,10 @@ const CreditPopup = ({
79
127
  event.stopPropagation();
80
128
  if (event.key === 'Escape') {
81
129
  event.preventDefault();
130
+ restoreFocusAfterClose.current = true;
82
131
  close();
83
- if (isNestedMenu) {
84
- var _returnFocus$current;
85
- (_returnFocus$current = returnFocus.current) === null || _returnFocus$current === void 0 ? void 0 : _returnFocus$current.focus();
86
- }
87
132
  }
88
- }, [close, isNestedMenu]);
133
+ }, [close]);
89
134
  const content = useCallback(() => /*#__PURE__*/React.createElement(Box, {
90
135
  ref: setContentElement,
91
136
  xcss: styles.content,
@@ -106,10 +151,15 @@ const CreditPopup = ({
106
151
  titleId: (triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.id) || id,
107
152
  placement: placement,
108
153
  shouldFitViewport: true,
109
- shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false,
110
- zIndex: isNestedMenu ? akEditorFloatingDialogZIndex : undefined,
111
- strategy: isNestedMenu ? 'fixed' : undefined,
112
- shouldReturnFocus: !isNestedMenu,
154
+ shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false
155
+ // Credit feedback must share the modal layer when opened from a modal editor surface.
156
+ ,
157
+ zIndex: akEditorFloatingDialogZIndex,
158
+ strategy: isNestedMenu ? 'fixed' : undefined
159
+ // Our Escape handler restores focus after the popup unmounts.
160
+ // Disable automatic restoration so outside clicks keep focus on their target.
161
+ ,
162
+ shouldReturnFocus: false,
113
163
  shouldUseCaptureOnOutsideClick: true,
114
164
  content: content,
115
165
  trigger: trigger
@@ -13,7 +13,7 @@ const NETWORK_FAILURE_REGEX = /^network failure/i;
13
13
  const RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
14
14
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
15
15
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
16
- const packageVersion = "134.20.1";
16
+ const packageVersion = "135.0.0";
17
17
  const sanitiseSentryEvents = (data, _hint) => {
18
18
  // Remove URL as it has UGC
19
19
  // Ignored via go/ees007
@@ -1,7 +1,7 @@
1
1
  /* CompactQuickInsertMenuItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./CompactQuickInsertMenuItem.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React, { useId, useMemo, useState } from 'react';
4
+ import React, { useCallback, useId, useMemo, useState } from 'react';
5
5
  import { Box } from '@atlaskit/primitives/compiled/box';
6
6
  import { Inline } from '@atlaskit/primitives/compiled/inline';
7
7
  import { Text } from '@atlaskit/primitives/compiled/text';
@@ -84,11 +84,14 @@ const disabledItemStyles = xcss({
84
84
  });
85
85
  export const CompactQuickInsertMenuItem = ({
86
86
  ariaLabel,
87
+ 'aria-controls': ariaControls,
87
88
  description,
88
89
  iconBefore,
90
+ itemRef,
89
91
  isDisabled,
90
92
  lozenge,
91
93
  onSelect,
94
+ onBeforeSelect,
92
95
  preview,
93
96
  previewIcon,
94
97
  previewImageUrls,
@@ -115,8 +118,18 @@ export const CompactQuickInsertMenuItem = ({
115
118
  };
116
119
  const resolvedDescription = description !== null && description !== void 0 ? description : item === null || item === void 0 ? void 0 : item.description;
117
120
  const previewId = useId();
118
- const handleClick = useQuickInsertMenuItemSelection(onSelect);
121
+ const handleClick = useQuickInsertMenuItemSelection(onSelect, onBeforeSelect);
119
122
  const [referenceElement, setReferenceElement] = useState(null);
123
+ const setItemElement = useCallback(element => {
124
+ setReferenceElement(element);
125
+ if (typeof itemRef === 'function') {
126
+ itemRef(element);
127
+ } else if (itemRef) {
128
+ Object.assign(itemRef, {
129
+ current: element
130
+ });
131
+ }
132
+ }, [itemRef]);
120
133
  const resolvedPreview = useMemo(() => preview !== null && preview !== void 0 ? preview : previewImageUrls ? {
121
134
  image: previewImageUrls
122
135
  } : {}, [preview, previewImageUrls]);
@@ -131,8 +144,9 @@ export const CompactQuickInsertMenuItem = ({
131
144
  xcss: styles.iconLarge
132
145
  }, iconBefore) : iconBefore;
133
146
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Pressable, {
134
- ref: setReferenceElement,
147
+ ref: setItemElement,
135
148
  "aria-label": ariaLabel,
149
+ "aria-controls": ariaControls,
136
150
  "aria-describedby": shouldRenderPreview && hasAccessiblePreview ? previewId : undefined,
137
151
  "aria-selected": isSelected,
138
152
  id: id,
@@ -1,7 +1,7 @@
1
1
  /* ElementBrowserQuickInsertMenuItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./ElementBrowserQuickInsertMenuItem.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React, { useId, useMemo } from 'react';
4
+ import React, { useCallback, useId, useMemo } from 'react';
5
5
  /* eslint-disable @atlaskit/design-system/no-emotion-primitives -- Compiled primitives do not provide Pressable. */
6
6
  import { Box } from '@atlaskit/primitives/box';
7
7
  import { Pressable } from '@atlaskit/primitives/pressable';
@@ -103,9 +103,12 @@ const pinnedIconColorResetStyles = null;
103
103
  */
104
104
  export const ElementBrowserQuickInsertMenuItem = ({
105
105
  ariaLabel,
106
+ 'aria-controls': ariaControls,
107
+ itemRef,
106
108
  description,
107
109
  iconBefore,
108
110
  isDisabled = false,
111
+ onBeforeSelect,
109
112
  lozenge,
110
113
  onSelect,
111
114
  preview,
@@ -125,7 +128,16 @@ export const ElementBrowserQuickInsertMenuItem = ({
125
128
  isSelected: false
126
129
  };
127
130
  const itemDescription = description !== null && description !== void 0 ? description : item === null || item === void 0 ? void 0 : item.description;
128
- const handleClick = useQuickInsertMenuItemSelection(onSelect);
131
+ const handleClick = useQuickInsertMenuItemSelection(onSelect, onBeforeSelect);
132
+ const setItemElement = useCallback(element => {
133
+ if (typeof itemRef === 'function') {
134
+ itemRef(element);
135
+ } else if (itemRef) {
136
+ Object.assign(itemRef, {
137
+ current: element
138
+ });
139
+ }
140
+ }, [itemRef]);
129
141
  const descriptionId = useId();
130
142
  const resolvedPreview = useMemo(() => preview !== null && preview !== void 0 ? preview : previewImageUrls ? {
131
143
  image: previewImageUrls
@@ -135,6 +147,8 @@ export const ElementBrowserQuickInsertMenuItem = ({
135
147
  className: ax(["_rpzpjdj5 _1pgcjdj5", !isDisabled && "_syaz1q3r"])
136
148
  }, iconBefore) : undefined;
137
149
  return /*#__PURE__*/React.createElement(Pressable, {
150
+ ref: setItemElement,
151
+ "aria-controls": ariaControls,
138
152
  "aria-describedby": hasDescription ? descriptionId : undefined,
139
153
  "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : title,
140
154
  "aria-selected": isSelected,
@@ -5,9 +5,12 @@ import { ElementBrowserQuickInsertMenuItem } from './ElementBrowserQuickInsertMe
5
5
  import { useQuickInsertContext } from './useQuickInsertContext';
6
6
  export const QuickInsertMenuItem = ({
7
7
  ariaLabel,
8
+ 'aria-controls': ariaControls,
9
+ itemRef,
8
10
  description,
9
11
  iconBefore,
10
12
  isDisabled,
13
+ onBeforeSelect,
11
14
  lozenge,
12
15
  onSelect,
13
16
  preview,
@@ -27,9 +30,12 @@ export const QuickInsertMenuItem = ({
27
30
  const surface = surfaceContext === null || surfaceContext === void 0 ? void 0 : (_surfaceContext$get = surfaceContext.get(REGISTERED_MENU_SURFACE_CONTEXT)) === null || _surfaceContext$get === void 0 ? void 0 : _surfaceContext$get.surface;
28
31
  return surface === 'element-browser' ? /*#__PURE__*/React.createElement(ElementBrowserQuickInsertMenuItem, {
29
32
  ariaLabel: ariaLabel,
33
+ "aria-controls": ariaControls,
34
+ itemRef: itemRef,
30
35
  description: description,
31
36
  iconBefore: iconBefore,
32
37
  isDisabled: isDisabled,
38
+ onBeforeSelect: onBeforeSelect,
33
39
  lozenge: lozenge,
34
40
  onSelect: onSelect,
35
41
  preview: preview,
@@ -39,9 +45,12 @@ export const QuickInsertMenuItem = ({
39
45
  title: title
40
46
  }) : /*#__PURE__*/React.createElement(CompactQuickInsertMenuItem, {
41
47
  ariaLabel: ariaLabel,
48
+ "aria-controls": ariaControls,
49
+ itemRef: itemRef,
42
50
  description: description,
43
51
  iconBefore: iconBefore,
44
52
  isDisabled: isDisabled,
53
+ onBeforeSelect: onBeforeSelect,
45
54
  lozenge: lozenge,
46
55
  onSelect: onSelect,
47
56
  preview: preview,
@@ -1,13 +1,18 @@
1
1
  import { useCallback } from 'react';
2
2
  import { useQuickInsertContext } from './useQuickInsertContext';
3
- export const useQuickInsertMenuItemSelection = onSelect => {
3
+ export const useQuickInsertMenuItemSelection = (onSelect, onBeforeSelect) => {
4
4
  const {
5
5
  editorView,
6
6
  select
7
7
  } = useQuickInsertContext();
8
- return useCallback(() => select(selectionContext => onSelect({
9
- editorView,
10
- insert: selectionContext.insert,
11
- source: selectionContext.source
12
- })), [editorView, onSelect, select]);
8
+ return useCallback(() => {
9
+ if ((onBeforeSelect === null || onBeforeSelect === void 0 ? void 0 : onBeforeSelect()) === false) {
10
+ return;
11
+ }
12
+ select(selectionContext => onSelect({
13
+ editorView,
14
+ insert: selectionContext.insert,
15
+ source: selectionContext.source
16
+ }));
17
+ }, [editorView, onBeforeSelect, onSelect, select]);
13
18
  };
@@ -13,7 +13,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
13
13
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
14
14
  import Layer from '../Layer';
15
15
  const packageName = "@atlaskit/editor-common";
16
- const packageVersion = "134.20.1";
16
+ const packageVersion = "135.0.0";
17
17
  const halfFocusRing = 1;
18
18
  const dropOffset = '0, 8';
19
19
  // Ignored via go/ees005
@@ -13,7 +13,7 @@ export var aiSuggestionsMessages = defineMessages({
13
13
  suggestEditsPromptPrefix: {
14
14
  id: 'fabric.editor.ai.suggestions.suggestEditsPromptPrefix.non-final',
15
15
  defaultMessage: 'Review my content with ',
16
- description: 'Localised text that precedes the suggest-edits skill tag in the prompt sent to the AI service. The trailing space is intentional — it separates this text from the skill tag that follows. Localise it in a way where the prompt ends with the skill tag. (With the skill tag it will look like e.g. "Review my content with /suggest-edits")'
16
+ description: 'Localised text that precedes the add-suggestions-to-content skill tag in the prompt sent to the AI service. The trailing space is intentional — it separates this text from the skill tag that follows. Localise it in a way where the prompt ends with the skill tag. (With the skill tag it will look like e.g. "Review my content with /add-suggestions-to-content")'
17
17
  },
18
18
  contentReviewAgentPrompt: {
19
19
  id: 'fabric.editor.ai.suggestions.contentReviewAgentPrompt.non-final',
@@ -5,7 +5,7 @@ import "./CreditCheckedPopup.compiled.css";
5
5
  import { ax, ix } from "@compiled/react/runtime";
6
6
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
7
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
- import React, { useCallback, useEffect, useId, useRef, useState } from 'react';
8
+ import React, { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
9
9
  import { bind } from 'bind-event-listener';
10
10
  import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles/constants';
11
11
  import { Popup } from '@atlaskit/popup/popup';
@@ -38,6 +38,13 @@ var styles = {
38
38
  var stopPropagation = function stopPropagation(event) {
39
39
  return event.stopPropagation();
40
40
  };
41
+ var focusReturnTarget = function focusReturnTarget(preferredTarget, fallbackTarget) {
42
+ var isUsableTarget = function isUsableTarget(target) {
43
+ return Boolean((target === null || target === void 0 ? void 0 : target.isConnected) && target !== target.ownerDocument.body && target !== target.ownerDocument.documentElement);
44
+ };
45
+ var target = isUsableTarget(preferredTarget) ? preferredTarget : isUsableTarget(fallbackTarget) ? fallbackTarget : null;
46
+ target === null || target === void 0 || target.focus();
47
+ };
41
48
 
42
49
  /** Editor owns popup behavior; products supply content through getAICreditStatus. */
43
50
  var CreditPopup = function CreditPopup(_ref2) {
@@ -59,15 +66,60 @@ var CreditPopup = function CreditPopup(_ref2) {
59
66
  _useState4 = _slicedToArray(_useState3, 2),
60
67
  triggerElement = _useState4[0],
61
68
  setTriggerElement = _useState4[1];
69
+ // Menu search and editor inputs can keep focus when feedback opens.
70
+ // Remember that element so Escape returns focus there instead of to the trigger.
62
71
  var returnFocus = useRef(null);
63
- var wasOpen = useRef(false);
72
+ var isOpen = useRef(feedback !== null);
73
+ isOpen.current = feedback !== null;
74
+ var restoreFocusAfterClose = useRef(false);
75
+ useEffect(function () {
76
+ if (!triggerElement) {
77
+ return;
78
+ }
79
+ var ownerDocument = triggerElement.ownerDocument;
80
+ var rememberFocus = function rememberFocus(target) {
81
+ if (!isOpen.current && !restoreFocusAfterClose.current && target instanceof HTMLElement && target !== ownerDocument.body && target !== ownerDocument.documentElement) {
82
+ returnFocus.current = target;
83
+ }
84
+ };
85
+ rememberFocus(ownerDocument.activeElement);
86
+ return bind(ownerDocument, {
87
+ type: 'focusin',
88
+ options: {
89
+ capture: true
90
+ },
91
+ listener: function listener(event) {
92
+ return rememberFocus(event.target);
93
+ }
94
+ });
95
+ }, [triggerElement]);
64
96
  useEffect(function () {
65
- if (feedback && !wasOpen.current) {
66
- var active = triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.ownerDocument.activeElement;
67
- returnFocus.current = active instanceof HTMLElement ? active : null;
97
+ var _returnFocus$current;
98
+ if (feedback || contentElement || !restoreFocusAfterClose.current) {
99
+ return;
68
100
  }
69
- wasOpen.current = feedback !== null;
70
- }, [feedback, triggerElement]);
101
+ restoreFocusAfterClose.current = false;
102
+ var previousFocus = (_returnFocus$current = returnFocus.current) !== null && _returnFocus$current !== void 0 && _returnFocus$current.isConnected ? returnFocus.current : triggerElement;
103
+ focusReturnTarget(previousFocus, triggerElement);
104
+ }, [feedback, contentElement, triggerElement]);
105
+ useLayoutEffect(function () {
106
+ if (!feedback || !contentElement) return;
107
+ var ownerDocument = contentElement.ownerDocument;
108
+ return bind(ownerDocument, {
109
+ type: 'keydown',
110
+ options: {
111
+ capture: true
112
+ },
113
+ listener: function listener(event) {
114
+ if (event.key !== 'Escape') return;
115
+ // The popup can leave focus in the editor, whose Escape handler cancels its draft.
116
+ event.preventDefault();
117
+ event.stopPropagation();
118
+ restoreFocusAfterClose.current = true;
119
+ close();
120
+ }
121
+ });
122
+ }, [feedback, contentElement, close]);
71
123
  useEffect(function () {
72
124
  if (!feedback || !contentElement || !isNestedMenu) {
73
125
  return;
@@ -89,13 +141,10 @@ var CreditPopup = function CreditPopup(_ref2) {
89
141
  event.stopPropagation();
90
142
  if (event.key === 'Escape') {
91
143
  event.preventDefault();
144
+ restoreFocusAfterClose.current = true;
92
145
  close();
93
- if (isNestedMenu) {
94
- var _returnFocus$current;
95
- (_returnFocus$current = returnFocus.current) === null || _returnFocus$current === void 0 || _returnFocus$current.focus();
96
- }
97
146
  }
98
- }, [close, isNestedMenu]);
147
+ }, [close]);
99
148
  var content = useCallback(function () {
100
149
  return /*#__PURE__*/React.createElement(Box, {
101
150
  ref: setContentElement,
@@ -120,10 +169,15 @@ var CreditPopup = function CreditPopup(_ref2) {
120
169
  titleId: (triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.id) || id,
121
170
  placement: placement,
122
171
  shouldFitViewport: true,
123
- shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false,
124
- zIndex: isNestedMenu ? akEditorFloatingDialogZIndex : undefined,
125
- strategy: isNestedMenu ? 'fixed' : undefined,
126
- shouldReturnFocus: !isNestedMenu,
172
+ shouldRenderToParent: shouldRenderToParent !== null && shouldRenderToParent !== void 0 ? shouldRenderToParent : false
173
+ // Credit feedback must share the modal layer when opened from a modal editor surface.
174
+ ,
175
+ zIndex: akEditorFloatingDialogZIndex,
176
+ strategy: isNestedMenu ? 'fixed' : undefined
177
+ // Our Escape handler restores focus after the popup unmounts.
178
+ // Disable automatic restoration so outside clicks keep focus on their target.
179
+ ,
180
+ shouldReturnFocus: false,
127
181
  shouldUseCaptureOnOutsideClick: true,
128
182
  content: content,
129
183
  trigger: trigger
@@ -19,7 +19,7 @@ var NETWORK_FAILURE_REGEX = /^network failure/i;
19
19
  var RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
20
20
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
21
21
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
22
- var packageVersion = "134.20.1";
22
+ var packageVersion = "135.0.0";
23
23
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
24
24
  // Remove URL as it has UGC
25
25
  // Ignored via go/ees007
@@ -2,7 +2,7 @@
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import "./CompactQuickInsertMenuItem.compiled.css";
4
4
  import { ax, ix } from "@compiled/react/runtime";
5
- import React, { useId, useMemo, useState } from 'react';
5
+ import React, { useCallback, useId, useMemo, useState } from 'react';
6
6
  import { Box } from '@atlaskit/primitives/compiled/box';
7
7
  import { Inline } from '@atlaskit/primitives/compiled/inline';
8
8
  import { Text } from '@atlaskit/primitives/compiled/text';
@@ -86,11 +86,14 @@ var disabledItemStyles = xcss({
86
86
  export var CompactQuickInsertMenuItem = function CompactQuickInsertMenuItem(_ref) {
87
87
  var _resolvedPreview$attr, _ref3, _resolvedPreview$imag, _resolvedPreview$imag2;
88
88
  var ariaLabel = _ref.ariaLabel,
89
+ ariaControls = _ref['aria-controls'],
89
90
  description = _ref.description,
90
91
  iconBefore = _ref.iconBefore,
92
+ itemRef = _ref.itemRef,
91
93
  isDisabled = _ref.isDisabled,
92
94
  lozenge = _ref.lozenge,
93
95
  onSelect = _ref.onSelect,
96
+ onBeforeSelect = _ref.onBeforeSelect,
94
97
  preview = _ref.preview,
95
98
  previewIcon = _ref.previewIcon,
96
99
  previewImageUrls = _ref.previewImageUrls,
@@ -115,11 +118,21 @@ export var CompactQuickInsertMenuItem = function CompactQuickInsertMenuItem(_ref
115
118
  isSelected = _ref2.isSelected;
116
119
  var resolvedDescription = description !== null && description !== void 0 ? description : item === null || item === void 0 ? void 0 : item.description;
117
120
  var previewId = useId();
118
- var handleClick = useQuickInsertMenuItemSelection(onSelect);
121
+ var handleClick = useQuickInsertMenuItemSelection(onSelect, onBeforeSelect);
119
122
  var _useState = useState(null),
120
123
  _useState2 = _slicedToArray(_useState, 2),
121
124
  referenceElement = _useState2[0],
122
125
  setReferenceElement = _useState2[1];
126
+ var setItemElement = useCallback(function (element) {
127
+ setReferenceElement(element);
128
+ if (typeof itemRef === 'function') {
129
+ itemRef(element);
130
+ } else if (itemRef) {
131
+ Object.assign(itemRef, {
132
+ current: element
133
+ });
134
+ }
135
+ }, [itemRef]);
123
136
  var resolvedPreview = useMemo(function () {
124
137
  return preview !== null && preview !== void 0 ? preview : previewImageUrls ? {
125
138
  image: previewImageUrls
@@ -136,8 +149,9 @@ export var CompactQuickInsertMenuItem = function CompactQuickInsertMenuItem(_ref
136
149
  xcss: styles.iconLarge
137
150
  }, iconBefore) : iconBefore;
138
151
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Pressable, {
139
- ref: setReferenceElement,
152
+ ref: setItemElement,
140
153
  "aria-label": ariaLabel,
154
+ "aria-controls": ariaControls,
141
155
  "aria-describedby": shouldRenderPreview && hasAccessiblePreview ? previewId : undefined,
142
156
  "aria-selected": isSelected,
143
157
  id: id,
@@ -1,7 +1,7 @@
1
1
  /* ElementBrowserQuickInsertMenuItem.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./ElementBrowserQuickInsertMenuItem.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React, { useId, useMemo } from 'react';
4
+ import React, { useCallback, useId, useMemo } from 'react';
5
5
  /* eslint-disable @atlaskit/design-system/no-emotion-primitives -- Compiled primitives do not provide Pressable. */
6
6
  import { Box } from '@atlaskit/primitives/box';
7
7
  import { Pressable } from '@atlaskit/primitives/pressable';
@@ -103,10 +103,13 @@ var pinnedIconColorResetStyles = null;
103
103
  */
104
104
  export var ElementBrowserQuickInsertMenuItem = function ElementBrowserQuickInsertMenuItem(_ref) {
105
105
  var ariaLabel = _ref.ariaLabel,
106
+ ariaControls = _ref['aria-controls'],
107
+ itemRef = _ref.itemRef,
106
108
  description = _ref.description,
107
109
  iconBefore = _ref.iconBefore,
108
110
  _ref$isDisabled = _ref.isDisabled,
109
111
  isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
112
+ onBeforeSelect = _ref.onBeforeSelect,
110
113
  lozenge = _ref.lozenge,
111
114
  onSelect = _ref.onSelect,
112
115
  preview = _ref.preview,
@@ -123,7 +126,16 @@ export var ElementBrowserQuickInsertMenuItem = function ElementBrowserQuickInser
123
126
  id = _ref2.id,
124
127
  isSelected = _ref2.isSelected;
125
128
  var itemDescription = description !== null && description !== void 0 ? description : item === null || item === void 0 ? void 0 : item.description;
126
- var handleClick = useQuickInsertMenuItemSelection(onSelect);
129
+ var handleClick = useQuickInsertMenuItemSelection(onSelect, onBeforeSelect);
130
+ var setItemElement = useCallback(function (element) {
131
+ if (typeof itemRef === 'function') {
132
+ itemRef(element);
133
+ } else if (itemRef) {
134
+ Object.assign(itemRef, {
135
+ current: element
136
+ });
137
+ }
138
+ }, [itemRef]);
127
139
  var descriptionId = useId();
128
140
  var resolvedPreview = useMemo(function () {
129
141
  return preview !== null && preview !== void 0 ? preview : previewImageUrls ? {
@@ -135,6 +147,8 @@ export var ElementBrowserQuickInsertMenuItem = function ElementBrowserQuickInser
135
147
  className: ax(["_rpzpjdj5 _1pgcjdj5", !isDisabled && "_syaz1q3r"])
136
148
  }, iconBefore) : undefined;
137
149
  return /*#__PURE__*/React.createElement(Pressable, {
150
+ ref: setItemElement,
151
+ "aria-controls": ariaControls,
138
152
  "aria-describedby": hasDescription ? descriptionId : undefined,
139
153
  "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : title,
140
154
  "aria-selected": isSelected,
@@ -6,9 +6,12 @@ import { useQuickInsertContext } from './useQuickInsertContext';
6
6
  export var QuickInsertMenuItem = function QuickInsertMenuItem(_ref) {
7
7
  var _surfaceContext$get;
8
8
  var ariaLabel = _ref.ariaLabel,
9
+ ariaControls = _ref['aria-controls'],
10
+ itemRef = _ref.itemRef,
9
11
  description = _ref.description,
10
12
  iconBefore = _ref.iconBefore,
11
13
  isDisabled = _ref.isDisabled,
14
+ onBeforeSelect = _ref.onBeforeSelect,
12
15
  lozenge = _ref.lozenge,
13
16
  onSelect = _ref.onSelect,
14
17
  preview = _ref.preview,
@@ -25,9 +28,12 @@ export var QuickInsertMenuItem = function QuickInsertMenuItem(_ref) {
25
28
  var surface = surfaceContext === null || surfaceContext === void 0 || (_surfaceContext$get = surfaceContext.get(REGISTERED_MENU_SURFACE_CONTEXT)) === null || _surfaceContext$get === void 0 ? void 0 : _surfaceContext$get.surface;
26
29
  return surface === 'element-browser' ? /*#__PURE__*/React.createElement(ElementBrowserQuickInsertMenuItem, {
27
30
  ariaLabel: ariaLabel,
31
+ "aria-controls": ariaControls,
32
+ itemRef: itemRef,
28
33
  description: description,
29
34
  iconBefore: iconBefore,
30
35
  isDisabled: isDisabled,
36
+ onBeforeSelect: onBeforeSelect,
31
37
  lozenge: lozenge,
32
38
  onSelect: onSelect,
33
39
  preview: preview,
@@ -37,9 +43,12 @@ export var QuickInsertMenuItem = function QuickInsertMenuItem(_ref) {
37
43
  title: title
38
44
  }) : /*#__PURE__*/React.createElement(CompactQuickInsertMenuItem, {
39
45
  ariaLabel: ariaLabel,
46
+ "aria-controls": ariaControls,
47
+ itemRef: itemRef,
40
48
  description: description,
41
49
  iconBefore: iconBefore,
42
50
  isDisabled: isDisabled,
51
+ onBeforeSelect: onBeforeSelect,
43
52
  lozenge: lozenge,
44
53
  onSelect: onSelect,
45
54
  preview: preview,
@@ -1,16 +1,19 @@
1
1
  import { useCallback } from 'react';
2
2
  import { useQuickInsertContext } from './useQuickInsertContext';
3
- export var useQuickInsertMenuItemSelection = function useQuickInsertMenuItemSelection(onSelect) {
3
+ export var useQuickInsertMenuItemSelection = function useQuickInsertMenuItemSelection(onSelect, onBeforeSelect) {
4
4
  var _useQuickInsertContex = useQuickInsertContext(),
5
5
  editorView = _useQuickInsertContex.editorView,
6
6
  select = _useQuickInsertContex.select;
7
7
  return useCallback(function () {
8
- return select(function (selectionContext) {
8
+ if ((onBeforeSelect === null || onBeforeSelect === void 0 ? void 0 : onBeforeSelect()) === false) {
9
+ return;
10
+ }
11
+ select(function (selectionContext) {
9
12
  return onSelect({
10
13
  editorView: editorView,
11
14
  insert: selectionContext.insert,
12
15
  source: selectionContext.source
13
16
  });
14
17
  });
15
- }, [editorView, onSelect, select]);
18
+ }, [editorView, onBeforeSelect, onSelect, select]);
16
19
  };
@@ -20,7 +20,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
20
20
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
21
21
  import Layer from '../Layer';
22
22
  var packageName = "@atlaskit/editor-common";
23
- var packageVersion = "134.20.1";
23
+ var packageVersion = "135.0.0";
24
24
  var halfFocusRing = 1;
25
25
  var dropOffset = '0, 8';
26
26
  // Ignored via go/ees005
@@ -4,4 +4,4 @@
4
4
  */
5
5
  import React from 'react';
6
6
  import type { QuickInsertMenuItemProps } from './QuickInsertMenuItem';
7
- export declare const CompactQuickInsertMenuItem: ({ ariaLabel, description, iconBefore, isDisabled, lozenge, onSelect, preview, previewIcon, previewImageUrls, shortcut, titleContent, shouldShowPreview, shouldClampPreview, shouldWrapIcon, title, }: QuickInsertMenuItemProps) => React.JSX.Element;
7
+ export declare const CompactQuickInsertMenuItem: ({ ariaLabel, 'aria-controls': ariaControls, description, iconBefore, itemRef, isDisabled, lozenge, onSelect, onBeforeSelect, preview, previewIcon, previewImageUrls, shortcut, titleContent, shouldShowPreview, shouldClampPreview, shouldWrapIcon, title, }: QuickInsertMenuItemProps) => React.JSX.Element;
@@ -10,4 +10,4 @@ import type { QuickInsertMenuItemProps } from './QuickInsertMenuItem';
10
10
  * always in a bordered box, above the title instead. The hover card's small title icon
11
11
  * (`previewIcon`) is not shown, so a tile never repeats its icon.
12
12
  */
13
- export declare const ElementBrowserQuickInsertMenuItem: ({ ariaLabel, description, iconBefore, isDisabled, lozenge, onSelect, preview, previewImageUrls, shortcut, titleContent, title, }: QuickInsertMenuItemProps) => React.JSX.Element;
13
+ export declare const ElementBrowserQuickInsertMenuItem: ({ ariaLabel, 'aria-controls': ariaControls, itemRef, description, iconBefore, isDisabled, onBeforeSelect, lozenge, onSelect, preview, previewImageUrls, shortcut, titleContent, title, }: QuickInsertMenuItemProps) => React.JSX.Element;
@@ -10,12 +10,16 @@ export type OnSelectContext = {
10
10
  source: INPUT_METHOD.ELEMENT_BROWSER | INPUT_METHOD.INSERT_MENU | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR;
11
11
  };
12
12
  export type QuickInsertMenuItemProps = {
13
+ 'aria-controls'?: string;
13
14
  ariaLabel?: string;
14
15
  description?: string;
15
16
  iconBefore?: React.ReactNode;
16
17
  isDisabled?: boolean;
18
+ itemRef?: React.Ref<HTMLElement>;
17
19
  /** Shown after the title in the menu row only, not in the preview. */
18
20
  lozenge?: React.ReactNode;
21
+ /** Return false to keep the registered menu open without selecting this item. */
22
+ onBeforeSelect?: () => boolean;
19
23
  onSelect: (context: OnSelectContext) => Transaction | false | void;
20
24
  /** Structured preview content for the selected item. */
21
25
  preview?: QuickInsertPreview;
@@ -36,4 +40,4 @@ export type QuickInsertMenuItemProps = {
36
40
  /** Rich content rendered in place of the title in the menu row and preview. `title` is still used for accessibility. */
37
41
  titleContent?: React.ReactNode;
38
42
  };
39
- export declare const QuickInsertMenuItem: ({ ariaLabel, description, iconBefore, isDisabled, lozenge, onSelect, preview, previewIcon, previewImageUrls, shortcut, titleContent, shouldShowPreview, shouldClampPreview, shouldWrapIcon, title, }: QuickInsertMenuItemProps) => React.JSX.Element;
43
+ export declare const QuickInsertMenuItem: ({ ariaLabel, 'aria-controls': ariaControls, itemRef, description, iconBefore, isDisabled, onBeforeSelect, lozenge, onSelect, preview, previewIcon, previewImageUrls, shortcut, titleContent, shouldShowPreview, shouldClampPreview, shouldWrapIcon, title, }: QuickInsertMenuItemProps) => React.JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import type { QuickInsertMenuItemProps } from './QuickInsertMenuItem';
2
- export declare const useQuickInsertMenuItemSelection: (onSelect: QuickInsertMenuItemProps['onSelect']) => (() => void);
2
+ export declare const useQuickInsertMenuItemSelection: (onSelect: QuickInsertMenuItemProps['onSelect'], onBeforeSelect?: QuickInsertMenuItemProps['onBeforeSelect']) => (() => void);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "135.0.0",
3
+ "version": "135.1.0",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"