@atlaskit/editor-plugin-type-ahead 2.7.10 → 2.7.11

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,15 @@
1
1
  # @atlaskit/editor-plugin-type-ahead
2
2
 
3
+ ## 2.7.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#164625](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/164625)
8
+ [`aac10c2d4c08d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/aac10c2d4c08d) -
9
+ [ED-26900] Add a new config, getMoreOptionsButtonConfig, to TypeAheadHandler so that it can
10
+ support adding a more option button to typeahead list
11
+ - Updated dependencies
12
+
3
13
  ## 2.7.10
4
14
 
5
15
  ### Patch Changes
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MoreOptions = void 0;
7
+ var _react = require("react");
8
+ var _react2 = require("@emotion/react");
9
+ var _menu = require("@atlaskit/menu");
10
+ var _colors = require("@atlaskit/theme/colors");
11
+ /**
12
+ * @jsxRuntime classic
13
+ * @jsx jsx
14
+ */
15
+
16
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
17
+
18
+ var buttonStyles = (0, _react2.css)({
19
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
20
+ '& > button:hover': {
21
+ backgroundColor: "var(--ds-background-neutral-subtle-hovered, ".concat(_colors.N30, ")")
22
+ },
23
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
24
+ '& > button:focus': {
25
+ backgroundColor: "var(--ds-background-neutral-subtle-hovered, ".concat(_colors.N30, ")")
26
+ }
27
+ });
28
+ var MoreOptions = exports.MoreOptions = function MoreOptions(_ref) {
29
+ var onClick = _ref.onClick,
30
+ isFocused = _ref.isFocused,
31
+ title = _ref.title,
32
+ ariaLabel = _ref.ariaLabel,
33
+ iconBefore = _ref.iconBefore;
34
+ var ref = (0, _react.useRef)(null);
35
+ (0, _react.useEffect)(function () {
36
+ if (isFocused && ref.current) {
37
+ ref.current.focus();
38
+ }
39
+ }, [isFocused]);
40
+ (0, _react.useEffect)(function () {
41
+ if (!ref.current) {
42
+ return;
43
+ }
44
+ var element = ref.current;
45
+ var handleEnter = function handleEnter(e) {
46
+ if (e.key === 'Enter') {
47
+ onClick();
48
+ // Prevent keydown listener in TypeaheadList from handling Enter pressed
49
+ e.stopPropagation();
50
+ } else if (e.key === 'Tab') {
51
+ // TypeaheadList will try to insert selected item on Tab press
52
+ // hence stop propagation to prevent that and treat this as noop
53
+ e.stopPropagation();
54
+ e.preventDefault();
55
+ }
56
+ };
57
+
58
+ // Ignored via go/ees005
59
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
60
+ element === null || element === void 0 || element.addEventListener('keydown', handleEnter);
61
+ return function () {
62
+ // Ignored via go/ees005
63
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
64
+ element === null || element === void 0 || element.removeEventListener('keydown', handleEnter);
65
+ };
66
+ });
67
+ return (0, _react2.jsx)(_menu.Section, {
68
+ hasSeparator: true
69
+ }, (0, _react2.jsx)("span", {
70
+ css: buttonStyles
71
+ }, (0, _react2.jsx)(_menu.ButtonItem, {
72
+ ref: ref,
73
+ onClick: onClick,
74
+ iconBefore: iconBefore,
75
+ "aria-label": ariaLabel,
76
+ testId: "type-ahead-more-options-button"
77
+ }, title)));
78
+ };
@@ -19,10 +19,12 @@ var _ui = require("@atlaskit/editor-common/ui");
19
19
  var _menu = require("@atlaskit/menu");
20
20
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
21
21
  var _compiled = require("@atlaskit/primitives/compiled");
22
+ var _closeTypeAhead = require("../pm-plugins/commands/close-type-ahead");
22
23
  var _updateSelectedIndex = require("../pm-plugins/commands/update-selected-index");
23
24
  var _constants = require("../pm-plugins/constants");
24
25
  var _utils = require("../pm-plugins/utils");
25
26
  var _ListRow = require("./ListRow");
27
+ var _MoreOptions = require("./MoreOptions");
26
28
  var _TypeAheadListItem = require("./TypeAheadListItem");
27
29
  var _ViewMore = require("./ViewMore");
28
30
  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); }
@@ -55,7 +57,7 @@ var TypeaheadAssistiveTextPureComponent = /*#__PURE__*/_react.default.memo(funct
55
57
  });
56
58
  });
57
59
  var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
58
- var _decorationElement$qu2;
60
+ var _triggerHandler$getMo, _decorationElement$qu2;
59
61
  var items = _ref2.items,
60
62
  selectedIndex = _ref2.selectedIndex,
61
63
  editorView = _ref2.editorView,
@@ -66,8 +68,8 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
66
68
  triggerHandler = _ref2.triggerHandler,
67
69
  moreElementsInQuickInsertViewEnabled = _ref2.moreElementsInQuickInsertViewEnabled,
68
70
  api = _ref2.api,
69
- showViewMore = _ref2.showViewMore,
70
- onViewMoreClick = _ref2.onViewMoreClick;
71
+ showMoreOptionsButton = _ref2.showMoreOptionsButton,
72
+ onMoreOptionsClicked = _ref2.onMoreOptionsClicked;
71
73
  var listRef = (0, _react.useRef)();
72
74
  var listContainerRef = (0, _react.useRef)(null);
73
75
  var lastVisibleIndexes = (0, _react.useRef)({
@@ -78,7 +80,7 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
78
80
  });
79
81
 
80
82
  // Exclude view more item from the count
81
- var itemsLength = showViewMore ? items.length - 1 : items.length;
83
+ var itemsLength = showMoreOptionsButton ? Math.max(items.length - 1, 0) : items.length;
82
84
  var estimatedHeight = itemsLength * LIST_ITEM_ESTIMATED_HEIGHT;
83
85
  var _useState = (0, _react.useState)(Math.min(estimatedHeight, fitHeight)),
84
86
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -145,7 +147,7 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
145
147
  // to calculate each height. THen, we can schedule a new frame when this one finishs.
146
148
  requestAnimationFrame(function () {
147
149
  requestAnimationFrame(function () {
148
- var isViewMoreSelected = showViewMore && selectedIndex === itemsLength;
150
+ var isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
149
151
  var isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex ||
150
152
  // view more is always visible, hence no scrolling
151
153
  isViewMoreSelected;
@@ -158,7 +160,7 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
158
160
  }
159
161
  });
160
162
  });
161
- }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showViewMore]);
163
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
162
164
  var _onMouseMove = function onMouseMove(event, index) {
163
165
  event.preventDefault();
164
166
  event.stopPropagation();
@@ -171,7 +173,7 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
171
173
  if (!listRef.current) {
172
174
  return;
173
175
  }
174
- var isViewMoreSelected = showViewMore && selectedIndex === itemsLength;
176
+ var isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
175
177
  var isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex ||
176
178
  // view more is always visible, hence no scrolling
177
179
  isViewMoreSelected;
@@ -182,7 +184,7 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
182
184
  } else if (selectedIndex === -1) {
183
185
  listRef.current.scrollToRow(0);
184
186
  }
185
- }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showViewMore]);
187
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
186
188
  (0, _react.useLayoutEffect)(function () {
187
189
  setCache(new _CellMeasurer.CellMeasurerCache({
188
190
  fixedWidth: true,
@@ -201,14 +203,14 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
201
203
  }, [items]);
202
204
  (0, _react.useLayoutEffect)(function () {
203
205
  // Exclude view more item from the count
204
- var itemsToRender = showViewMore ? items.slice(0, -1) : items;
206
+ var itemsToRender = showMoreOptionsButton ? items.slice(0, -1) : items;
205
207
  var height = Math.min(itemsToRender.reduce(function (prevValue, currentValue, index) {
206
208
  return prevValue + cache.rowHeight({
207
209
  index: index
208
210
  });
209
211
  }, 0), fitHeight);
210
212
  setHeight(height);
211
- }, [items, cache, fitHeight, showViewMore]);
213
+ }, [items, cache, fitHeight, showMoreOptionsButton]);
212
214
  (0, _react.useLayoutEffect)(function () {
213
215
  if (!listContainerRef.current) {
214
216
  return;
@@ -268,13 +270,27 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
268
270
  return item.isDisabledOffline !== true;
269
271
  });
270
272
  }, [items]);
271
- var renderRow = function renderRow(_ref4) {
272
- var index = _ref4.index,
273
- key = _ref4.key,
274
- style = _ref4.style,
275
- parent = _ref4.parent,
276
- isScrolling = _ref4.isScrolling,
277
- isVisible = _ref4.isVisible;
273
+ var config = triggerHandler === null || triggerHandler === void 0 || (_triggerHandler$getMo = triggerHandler.getMoreOptionsButtonConfig) === null || _triggerHandler$getMo === void 0 ? void 0 : _triggerHandler$getMo.call(triggerHandler, intl);
274
+ var handleClick = function handleClick() {
275
+ if (onMoreOptionsClicked) {
276
+ onMoreOptionsClicked();
277
+ }
278
+ api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
279
+ var tr = _ref4.tr;
280
+ (0, _closeTypeAhead.closeTypeAhead)(tr);
281
+ config === null || config === void 0 || config.onClick({
282
+ tr: tr
283
+ });
284
+ return tr;
285
+ });
286
+ };
287
+ var renderRow = function renderRow(_ref5) {
288
+ var index = _ref5.index,
289
+ key = _ref5.key,
290
+ style = _ref5.style,
291
+ parent = _ref5.parent,
292
+ isScrolling = _ref5.isScrolling,
293
+ isVisible = _ref5.isVisible;
278
294
  var currentItem = items[index];
279
295
  return (0, _react2.jsx)(_CellMeasurer.CellMeasurer, {
280
296
  key: key,
@@ -282,9 +298,9 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
282
298
  parent: parent,
283
299
  columnIndex: 0,
284
300
  rowIndex: index
285
- }, (0, _platformFeatureFlags.fg)('platform_editor_typeahead_dynamic_height_fix') ? function (_ref5) {
286
- var measure = _ref5.measure,
287
- registerChild = _ref5.registerChild;
301
+ }, (0, _platformFeatureFlags.fg)('platform_editor_typeahead_dynamic_height_fix') ? function (_ref6) {
302
+ var measure = _ref6.measure,
303
+ registerChild = _ref6.registerChild;
288
304
  return (0, _react2.jsx)(_ListRow.ListRow, {
289
305
  registerChild: registerChild,
290
306
  measure: measure,
@@ -393,8 +409,14 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
393
409
  }, (0, _react2.jsx)("div", {
394
410
  id: menuGroupId,
395
411
  ref: listContainerRef
396
- }, !showViewMore || itemsLength ? ListContent : EmptyResultView, showViewMore && onViewMoreClick && (0, _react2.jsx)(_ViewMore.ViewMore, {
397
- onClick: onViewMoreClick,
412
+ }, !showMoreOptionsButton || itemsLength ? ListContent : EmptyResultView, (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_12') ? showMoreOptionsButton && config && (0, _react2.jsx)(_MoreOptions.MoreOptions, {
413
+ title: config.title,
414
+ ariaLabel: config.ariaLabel,
415
+ onClick: handleClick,
416
+ isFocused: selectedIndex === itemsLength,
417
+ iconBefore: config.iconBefore
418
+ }) : showMoreOptionsButton && onMoreOptionsClicked && (0, _react2.jsx)(_ViewMore.ViewMore, {
419
+ onClick: onMoreOptionsClicked,
398
420
  isFocused: selectedIndex === itemsLength
399
421
  }), (0, _react2.jsx)(TypeaheadAssistiveTextPureComponent, {
400
422
  numberOfResults: itemsLength.toString()
@@ -8,6 +8,7 @@ exports.TypeAheadMenu = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _typeAhead = require("@atlaskit/editor-common/type-ahead");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
13
  var _updateSelectedIndex = require("../pm-plugins/commands/update-selected-index");
13
14
  var _useItemInsert3 = require("./hooks/use-item-insert");
@@ -81,8 +82,15 @@ var TypeAheadMenu = exports.TypeAheadMenu = /*#__PURE__*/_react.default.memo(fun
81
82
 
82
83
  // @ts-ignore
83
84
  var openElementBrowserModal = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.openElementBrowserModal;
84
- var showViewMore = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === _typeAhead.TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1');
85
- if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || !showViewMore && items.length === 0 && !errorInfo) {
85
+ var showMoreOptionsButton = false;
86
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
87
+ if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_12')) {
88
+ showMoreOptionsButton = !!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getMoreOptionsButtonConfig);
89
+ } else {
90
+ showMoreOptionsButton = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === _typeAhead.TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal;
91
+ }
92
+ }
93
+ if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || !openElementBrowserModal && items.length === 0 && !errorInfo) {
86
94
  return null;
87
95
  }
88
96
  return /*#__PURE__*/_react.default.createElement(_TypeAheadPopup.TypeAheadPopup, {
@@ -101,6 +109,6 @@ var TypeAheadMenu = exports.TypeAheadMenu = /*#__PURE__*/_react.default.memo(fun
101
109
  isEmptyQuery: !query,
102
110
  cancel: cancel,
103
111
  api: api,
104
- showViewMore: showViewMore
112
+ showMoreOptionsButton: showMoreOptionsButton
105
113
  });
106
114
  });
@@ -91,7 +91,7 @@ var TypeAheadPopup = exports.TypeAheadPopup = /*#__PURE__*/_react.default.memo(f
91
91
  isEmptyQuery = props.isEmptyQuery,
92
92
  cancel = props.cancel,
93
93
  api = props.api,
94
- showViewMore = props.showViewMore;
94
+ showMoreOptionsButton = props.showMoreOptionsButton;
95
95
  var ref = (0, _react.useRef)(null);
96
96
  var _useSharedState = useSharedState(api),
97
97
  moreElementsInQuickInsertView = _useSharedState.moreElementsInQuickInsertView;
@@ -160,11 +160,11 @@ var TypeAheadPopup = exports.TypeAheadPopup = /*#__PURE__*/_react.default.memo(f
160
160
  fitHeight = _useState2[0],
161
161
  setFitHeight = _useState2[1];
162
162
  var fitHeightWithViewMore = (0, _react.useMemo)(function () {
163
- if (showViewMore) {
163
+ if (showMoreOptionsButton) {
164
164
  return fitHeight - VIEWMORE_BUTTON_HEIGHT;
165
165
  }
166
166
  return fitHeight;
167
- }, [fitHeight, showViewMore]);
167
+ }, [fitHeight, showMoreOptionsButton]);
168
168
  var getFitHeight = (0, _react.useCallback)(function () {
169
169
  if (!anchorElement || !popupsMountPoint) {
170
170
  return;
@@ -313,20 +313,21 @@ var TypeAheadPopup = exports.TypeAheadPopup = /*#__PURE__*/_react.default.memo(f
313
313
  (0, _closeTypeAhead.closeTypeAhead)(tr);
314
314
  editorView.dispatch(tr);
315
315
  };
316
- var onViewMoreClick = (0, _react.useCallback)(function () {
317
- close(editorView);
318
- if (openElementBrowserModal && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_4')) {
316
+ var onMoreOptionsClicked = (0, _react.useCallback)(function () {
317
+ if (
318
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
319
+ openElementBrowserModal && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_4') && (!(0, _platformFeatureFlags.fg)('platform_editor_controls_patch_12') || triggerHandler.id === _typeAhead.TypeAheadAvailableNodes.QUICK_INSERT)) {
319
320
  activityStateRef.current = {
320
321
  inputMethod: _analytics.INPUT_METHOD.MOUSE,
321
322
  closeAction: _analytics.ACTION.VIEW_MORE,
322
323
  invocationMethod: activityStateRef.current.invocationMethod
323
324
  };
324
325
  }
325
-
326
- // TODO: ED-26959 - when clean up, remove config in quick insert plugin
327
- // platform/packages/editor/editor-plugin-quick-insert/src/quickInsertPlugin.tsx (typeAhead.openElementBrowserModal)
328
- openElementBrowserModal === null || openElementBrowserModal === void 0 || openElementBrowserModal();
329
- }, [editorView, openElementBrowserModal]);
326
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_controls_patch_12')) {
327
+ close(editorView);
328
+ openElementBrowserModal === null || openElementBrowserModal === void 0 || openElementBrowserModal();
329
+ }
330
+ }, [editorView, openElementBrowserModal, triggerHandler.id]);
330
331
  return (0, _react2.jsx)(_ui.Popup, {
331
332
  zIndex: _editorSharedStyles.akEditorFloatingDialogZIndex,
332
333
  target: anchorElement,
@@ -353,7 +354,7 @@ var TypeAheadPopup = exports.TypeAheadPopup = /*#__PURE__*/_react.default.memo(f
353
354
  }
354
355
  }
355
356
  }, (0, _react2.jsx)("div", {
356
- css: [typeAheadContent, moreElementsInQuickInsertViewEnabled && typeAheadContentOverride, showViewMore && typeAheadWrapperWithViewMoreOverride]
357
+ css: [typeAheadContent, moreElementsInQuickInsertViewEnabled && typeAheadContentOverride, showMoreOptionsButton && typeAheadWrapperWithViewMoreOverride]
357
358
  // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
358
359
  ,
359
360
  tabIndex: 0
@@ -383,8 +384,8 @@ var TypeAheadPopup = exports.TypeAheadPopup = /*#__PURE__*/_react.default.memo(f
383
384
  triggerHandler: triggerHandler,
384
385
  moreElementsInQuickInsertViewEnabled: moreElementsInQuickInsertViewEnabled,
385
386
  api: api,
386
- showViewMore: showViewMore,
387
- onViewMoreClick: onViewMoreClick
387
+ showMoreOptionsButton: showMoreOptionsButton,
388
+ onMoreOptionsClicked: onMoreOptionsClicked
388
389
  }))));
389
390
  });
390
391
  TypeAheadPopup.displayName = 'TypeAheadPopup';
@@ -36,7 +36,14 @@ var WrapperTypeAhead = exports.WrapperTypeAhead = /*#__PURE__*/_react.default.me
36
36
  api = _ref.api;
37
37
  // @ts-ignore
38
38
  var openElementBrowserModal = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.openElementBrowserModal;
39
- var showViewMore = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === _typeAhead.TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1');
39
+ var showMoreOptionsButton = false;
40
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
41
+ if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_12')) {
42
+ showMoreOptionsButton = !!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getMoreOptionsButtonConfig);
43
+ } else {
44
+ showMoreOptionsButton = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === _typeAhead.TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal;
45
+ }
46
+ }
40
47
  var _useState = (0, _react.useState)(false),
41
48
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
49
  closed = _useState2[0],
@@ -47,7 +54,7 @@ var WrapperTypeAhead = exports.WrapperTypeAhead = /*#__PURE__*/_react.default.me
47
54
  setQuery = _useState4[1];
48
55
  var queryRef = (0, _react.useRef)(query);
49
56
  var editorViewRef = (0, _react.useRef)(editorView);
50
- var items = (0, _useLoadItems.useLoadItems)(triggerHandler, editorView, query, showViewMore);
57
+ var items = (0, _useLoadItems.useLoadItems)(triggerHandler, editorView, query, showMoreOptionsButton);
51
58
  (0, _react.useEffect)(function () {
52
59
  if (!closed && (0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
53
60
  var _api$metrics;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import { useEffect, useRef } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
+ import { css, jsx } from '@emotion/react';
9
+ import { ButtonItem, Section } from '@atlaskit/menu';
10
+ import { N30 } from '@atlaskit/theme/colors';
11
+ const buttonStyles = css({
12
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
13
+ '& > button:hover': {
14
+ backgroundColor: `var(--ds-background-neutral-subtle-hovered, ${N30})`
15
+ },
16
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
17
+ '& > button:focus': {
18
+ backgroundColor: `var(--ds-background-neutral-subtle-hovered, ${N30})`
19
+ }
20
+ });
21
+ export const MoreOptions = ({
22
+ onClick,
23
+ isFocused,
24
+ title,
25
+ ariaLabel,
26
+ iconBefore
27
+ }) => {
28
+ const ref = useRef(null);
29
+ useEffect(() => {
30
+ if (isFocused && ref.current) {
31
+ ref.current.focus();
32
+ }
33
+ }, [isFocused]);
34
+ useEffect(() => {
35
+ if (!ref.current) {
36
+ return;
37
+ }
38
+ const {
39
+ current: element
40
+ } = ref;
41
+ const handleEnter = e => {
42
+ if (e.key === 'Enter') {
43
+ onClick();
44
+ // Prevent keydown listener in TypeaheadList from handling Enter pressed
45
+ e.stopPropagation();
46
+ } else if (e.key === 'Tab') {
47
+ // TypeaheadList will try to insert selected item on Tab press
48
+ // hence stop propagation to prevent that and treat this as noop
49
+ e.stopPropagation();
50
+ e.preventDefault();
51
+ }
52
+ };
53
+
54
+ // Ignored via go/ees005
55
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
56
+ element === null || element === void 0 ? void 0 : element.addEventListener('keydown', handleEnter);
57
+ return () => {
58
+ // Ignored via go/ees005
59
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
60
+ element === null || element === void 0 ? void 0 : element.removeEventListener('keydown', handleEnter);
61
+ };
62
+ });
63
+ return jsx(Section, {
64
+ hasSeparator: true
65
+ }, jsx("span", {
66
+ css: buttonStyles
67
+ }, jsx(ButtonItem, {
68
+ ref: ref,
69
+ onClick: onClick,
70
+ iconBefore: iconBefore,
71
+ "aria-label": ariaLabel,
72
+ testId: "type-ahead-more-options-button"
73
+ }, title)));
74
+ };
@@ -17,10 +17,12 @@ import { AssistiveText } from '@atlaskit/editor-common/ui';
17
17
  import { MenuGroup } from '@atlaskit/menu';
18
18
  import { fg } from '@atlaskit/platform-feature-flags';
19
19
  import { Text, Box } from '@atlaskit/primitives/compiled';
20
+ import { closeTypeAhead } from '../pm-plugins/commands/close-type-ahead';
20
21
  import { updateSelectedIndex } from '../pm-plugins/commands/update-selected-index';
21
22
  import { TYPE_AHEAD_DECORATION_ELEMENT_ID } from '../pm-plugins/constants';
22
23
  import { getTypeAheadListAriaLabels, moveSelectedIndex } from '../pm-plugins/utils';
23
24
  import { ListRow } from './ListRow';
25
+ import { MoreOptions } from './MoreOptions';
24
26
  import { TypeAheadListItem } from './TypeAheadListItem';
25
27
  import { ViewMore } from './ViewMore';
26
28
  const LIST_ITEM_ESTIMATED_HEIGHT = 64;
@@ -56,10 +58,10 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
56
58
  triggerHandler,
57
59
  moreElementsInQuickInsertViewEnabled,
58
60
  api,
59
- showViewMore,
60
- onViewMoreClick
61
+ showMoreOptionsButton,
62
+ onMoreOptionsClicked
61
63
  }) => {
62
- var _decorationElement$qu2;
64
+ var _triggerHandler$getMo, _decorationElement$qu2;
63
65
  const listRef = useRef();
64
66
  const listContainerRef = useRef(null);
65
67
  const lastVisibleIndexes = useRef({
@@ -70,7 +72,7 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
70
72
  });
71
73
 
72
74
  // Exclude view more item from the count
73
- const itemsLength = showViewMore ? items.length - 1 : items.length;
75
+ const itemsLength = showMoreOptionsButton ? Math.max(items.length - 1, 0) : items.length;
74
76
  const estimatedHeight = itemsLength * LIST_ITEM_ESTIMATED_HEIGHT;
75
77
  const [height, setHeight] = useState(Math.min(estimatedHeight, fitHeight));
76
78
  const [cache, setCache] = useState(new CellMeasurerCache({
@@ -126,7 +128,7 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
126
128
  // to calculate each height. THen, we can schedule a new frame when this one finishs.
127
129
  requestAnimationFrame(() => {
128
130
  requestAnimationFrame(() => {
129
- const isViewMoreSelected = showViewMore && selectedIndex === itemsLength;
131
+ const isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
130
132
  const isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex ||
131
133
  // view more is always visible, hence no scrolling
132
134
  isViewMoreSelected;
@@ -139,7 +141,7 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
139
141
  }
140
142
  });
141
143
  });
142
- }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showViewMore]);
144
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
143
145
  const onMouseMove = (event, index) => {
144
146
  event.preventDefault();
145
147
  event.stopPropagation();
@@ -152,7 +154,7 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
152
154
  if (!listRef.current) {
153
155
  return;
154
156
  }
155
- const isViewMoreSelected = showViewMore && selectedIndex === itemsLength;
157
+ const isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
156
158
  const isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex ||
157
159
  // view more is always visible, hence no scrolling
158
160
  isViewMoreSelected;
@@ -163,7 +165,7 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
163
165
  } else if (selectedIndex === -1) {
164
166
  listRef.current.scrollToRow(0);
165
167
  }
166
- }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showViewMore]);
168
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
167
169
  useLayoutEffect(() => {
168
170
  setCache(new CellMeasurerCache({
169
171
  fixedWidth: true,
@@ -182,14 +184,14 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
182
184
  }, [items]);
183
185
  useLayoutEffect(() => {
184
186
  // Exclude view more item from the count
185
- const itemsToRender = showViewMore ? items.slice(0, -1) : items;
187
+ const itemsToRender = showMoreOptionsButton ? items.slice(0, -1) : items;
186
188
  const height = Math.min(itemsToRender.reduce((prevValue, currentValue, index) => {
187
189
  return prevValue + cache.rowHeight({
188
190
  index: index
189
191
  });
190
192
  }, 0), fitHeight);
191
193
  setHeight(height);
192
- }, [items, cache, fitHeight, showViewMore]);
194
+ }, [items, cache, fitHeight, showMoreOptionsButton]);
193
195
  useLayoutEffect(() => {
194
196
  if (!listContainerRef.current) {
195
197
  return;
@@ -249,6 +251,21 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
249
251
  const firstOnlineSupportedRow = useMemo(() => {
250
252
  return items.findIndex(item => item.isDisabledOffline !== true);
251
253
  }, [items]);
254
+ const config = triggerHandler === null || triggerHandler === void 0 ? void 0 : (_triggerHandler$getMo = triggerHandler.getMoreOptionsButtonConfig) === null || _triggerHandler$getMo === void 0 ? void 0 : _triggerHandler$getMo.call(triggerHandler, intl);
255
+ const handleClick = () => {
256
+ if (onMoreOptionsClicked) {
257
+ onMoreOptionsClicked();
258
+ }
259
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(({
260
+ tr
261
+ }) => {
262
+ closeTypeAhead(tr);
263
+ config === null || config === void 0 ? void 0 : config.onClick({
264
+ tr
265
+ });
266
+ return tr;
267
+ });
268
+ };
252
269
  const renderRow = ({
253
270
  index,
254
271
  key,
@@ -370,8 +387,14 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
370
387
  }, jsx("div", {
371
388
  id: menuGroupId,
372
389
  ref: listContainerRef
373
- }, !showViewMore || itemsLength ? ListContent : EmptyResultView, showViewMore && onViewMoreClick && jsx(ViewMore, {
374
- onClick: onViewMoreClick,
390
+ }, !showMoreOptionsButton || itemsLength ? ListContent : EmptyResultView, fg('platform_editor_controls_patch_12') ? showMoreOptionsButton && config && jsx(MoreOptions, {
391
+ title: config.title,
392
+ ariaLabel: config.ariaLabel,
393
+ onClick: handleClick,
394
+ isFocused: selectedIndex === itemsLength,
395
+ iconBefore: config.iconBefore
396
+ }) : showMoreOptionsButton && onMoreOptionsClicked && jsx(ViewMore, {
397
+ onClick: onMoreOptionsClicked,
375
398
  isFocused: selectedIndex === itemsLength
376
399
  }), jsx(TypeaheadAssistiveTextPureComponent, {
377
400
  numberOfResults: itemsLength.toString()
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { SelectItemMode, TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
5
  import { updateSelectedIndex } from '../pm-plugins/commands/update-selected-index';
5
6
  import { useItemInsert } from './hooks/use-item-insert';
@@ -72,8 +73,15 @@ export const TypeAheadMenu = /*#__PURE__*/React.memo(({
72
73
 
73
74
  // @ts-ignore
74
75
  const openElementBrowserModal = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.openElementBrowserModal;
75
- const showViewMore = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1');
76
- if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || !showViewMore && items.length === 0 && !errorInfo) {
76
+ let showMoreOptionsButton = false;
77
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
78
+ if (fg('platform_editor_controls_patch_12')) {
79
+ showMoreOptionsButton = !!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getMoreOptionsButtonConfig);
80
+ } else {
81
+ showMoreOptionsButton = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal;
82
+ }
83
+ }
84
+ if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || !openElementBrowserModal && items.length === 0 && !errorInfo) {
77
85
  return null;
78
86
  }
79
87
  return /*#__PURE__*/React.createElement(TypeAheadPopup, {
@@ -92,6 +100,6 @@ export const TypeAheadMenu = /*#__PURE__*/React.memo(({
92
100
  isEmptyQuery: !query,
93
101
  cancel: cancel,
94
102
  api: api,
95
- showViewMore: showViewMore
103
+ showMoreOptionsButton: showMoreOptionsButton
96
104
  });
97
105
  });
@@ -83,7 +83,7 @@ export const TypeAheadPopup = /*#__PURE__*/React.memo(props => {
83
83
  isEmptyQuery,
84
84
  cancel,
85
85
  api,
86
- showViewMore
86
+ showMoreOptionsButton
87
87
  } = props;
88
88
  const ref = useRef(null);
89
89
  const {
@@ -147,11 +147,11 @@ export const TypeAheadPopup = /*#__PURE__*/React.memo(props => {
147
147
  triggerHandler]);
148
148
  const [fitHeight, setFitHeight] = useState(defaultMenuHeight);
149
149
  const fitHeightWithViewMore = useMemo(() => {
150
- if (showViewMore) {
150
+ if (showMoreOptionsButton) {
151
151
  return fitHeight - VIEWMORE_BUTTON_HEIGHT;
152
152
  }
153
153
  return fitHeight;
154
- }, [fitHeight, showViewMore]);
154
+ }, [fitHeight, showMoreOptionsButton]);
155
155
  const getFitHeight = useCallback(() => {
156
156
  if (!anchorElement || !popupsMountPoint) {
157
157
  return;
@@ -314,20 +314,21 @@ export const TypeAheadPopup = /*#__PURE__*/React.memo(props => {
314
314
  closeTypeAhead(tr);
315
315
  editorView.dispatch(tr);
316
316
  };
317
- const onViewMoreClick = useCallback(() => {
318
- close(editorView);
319
- if (openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_4')) {
317
+ const onMoreOptionsClicked = useCallback(() => {
318
+ if (
319
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
320
+ openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_4') && (!fg('platform_editor_controls_patch_12') || triggerHandler.id === TypeAheadAvailableNodes.QUICK_INSERT)) {
320
321
  activityStateRef.current = {
321
322
  inputMethod: INPUT_METHOD.MOUSE,
322
323
  closeAction: ACTION.VIEW_MORE,
323
324
  invocationMethod: activityStateRef.current.invocationMethod
324
325
  };
325
326
  }
326
-
327
- // TODO: ED-26959 - when clean up, remove config in quick insert plugin
328
- // platform/packages/editor/editor-plugin-quick-insert/src/quickInsertPlugin.tsx (typeAhead.openElementBrowserModal)
329
- openElementBrowserModal === null || openElementBrowserModal === void 0 ? void 0 : openElementBrowserModal();
330
- }, [editorView, openElementBrowserModal]);
327
+ if (!fg('platform_editor_controls_patch_12')) {
328
+ close(editorView);
329
+ openElementBrowserModal === null || openElementBrowserModal === void 0 ? void 0 : openElementBrowserModal();
330
+ }
331
+ }, [editorView, openElementBrowserModal, triggerHandler.id]);
331
332
  return jsx(Popup, {
332
333
  zIndex: akEditorFloatingDialogZIndex,
333
334
  target: anchorElement,
@@ -354,7 +355,7 @@ export const TypeAheadPopup = /*#__PURE__*/React.memo(props => {
354
355
  }
355
356
  }
356
357
  }, jsx("div", {
357
- css: [typeAheadContent, moreElementsInQuickInsertViewEnabled && typeAheadContentOverride, showViewMore && typeAheadWrapperWithViewMoreOverride]
358
+ css: [typeAheadContent, moreElementsInQuickInsertViewEnabled && typeAheadContentOverride, showMoreOptionsButton && typeAheadWrapperWithViewMoreOverride]
358
359
  // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
359
360
  ,
360
361
  tabIndex: 0
@@ -384,8 +385,8 @@ export const TypeAheadPopup = /*#__PURE__*/React.memo(props => {
384
385
  triggerHandler: triggerHandler,
385
386
  moreElementsInQuickInsertViewEnabled: moreElementsInQuickInsertViewEnabled,
386
387
  api: api,
387
- showViewMore: showViewMore,
388
- onViewMoreClick: onViewMoreClick
388
+ showMoreOptionsButton: showMoreOptionsButton,
389
+ onMoreOptionsClicked: onMoreOptionsClicked
389
390
  }))));
390
391
  });
391
392
  TypeAheadPopup.displayName = 'TypeAheadPopup';
@@ -27,12 +27,19 @@ export const WrapperTypeAhead = /*#__PURE__*/React.memo(({
27
27
  }) => {
28
28
  // @ts-ignore
29
29
  const openElementBrowserModal = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.openElementBrowserModal;
30
- const showViewMore = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1');
30
+ let showMoreOptionsButton = false;
31
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
32
+ if (fg('platform_editor_controls_patch_12')) {
33
+ showMoreOptionsButton = !!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getMoreOptionsButtonConfig);
34
+ } else {
35
+ showMoreOptionsButton = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal;
36
+ }
37
+ }
31
38
  const [closed, setClosed] = useState(false);
32
39
  const [query, setQuery] = useState(reopenQuery || '');
33
40
  const queryRef = useRef(query);
34
41
  const editorViewRef = useRef(editorView);
35
- const items = useLoadItems(triggerHandler, editorView, query, showViewMore);
42
+ const items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton);
36
43
  useEffect(() => {
37
44
  if (!closed && fg('platform_editor_ease_of_use_metrics')) {
38
45
  var _api$metrics;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @jsxRuntime classic
3
+ * @jsx jsx
4
+ */
5
+ import { useEffect, useRef } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
8
+ import { css, jsx } from '@emotion/react';
9
+ import { ButtonItem, Section } from '@atlaskit/menu';
10
+ import { N30 } from '@atlaskit/theme/colors';
11
+ var buttonStyles = css({
12
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
13
+ '& > button:hover': {
14
+ backgroundColor: "var(--ds-background-neutral-subtle-hovered, ".concat(N30, ")")
15
+ },
16
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
17
+ '& > button:focus': {
18
+ backgroundColor: "var(--ds-background-neutral-subtle-hovered, ".concat(N30, ")")
19
+ }
20
+ });
21
+ export var MoreOptions = function MoreOptions(_ref) {
22
+ var onClick = _ref.onClick,
23
+ isFocused = _ref.isFocused,
24
+ title = _ref.title,
25
+ ariaLabel = _ref.ariaLabel,
26
+ iconBefore = _ref.iconBefore;
27
+ var ref = useRef(null);
28
+ useEffect(function () {
29
+ if (isFocused && ref.current) {
30
+ ref.current.focus();
31
+ }
32
+ }, [isFocused]);
33
+ useEffect(function () {
34
+ if (!ref.current) {
35
+ return;
36
+ }
37
+ var element = ref.current;
38
+ var handleEnter = function handleEnter(e) {
39
+ if (e.key === 'Enter') {
40
+ onClick();
41
+ // Prevent keydown listener in TypeaheadList from handling Enter pressed
42
+ e.stopPropagation();
43
+ } else if (e.key === 'Tab') {
44
+ // TypeaheadList will try to insert selected item on Tab press
45
+ // hence stop propagation to prevent that and treat this as noop
46
+ e.stopPropagation();
47
+ e.preventDefault();
48
+ }
49
+ };
50
+
51
+ // Ignored via go/ees005
52
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
53
+ element === null || element === void 0 || element.addEventListener('keydown', handleEnter);
54
+ return function () {
55
+ // Ignored via go/ees005
56
+ // eslint-disable-next-line @repo/internal/dom-events/no-unsafe-event-listeners
57
+ element === null || element === void 0 || element.removeEventListener('keydown', handleEnter);
58
+ };
59
+ });
60
+ return jsx(Section, {
61
+ hasSeparator: true
62
+ }, jsx("span", {
63
+ css: buttonStyles
64
+ }, jsx(ButtonItem, {
65
+ ref: ref,
66
+ onClick: onClick,
67
+ iconBefore: iconBefore,
68
+ "aria-label": ariaLabel,
69
+ testId: "type-ahead-more-options-button"
70
+ }, title)));
71
+ };
@@ -18,10 +18,12 @@ import { AssistiveText } from '@atlaskit/editor-common/ui';
18
18
  import { MenuGroup } from '@atlaskit/menu';
19
19
  import { fg } from '@atlaskit/platform-feature-flags';
20
20
  import { Text, Box } from '@atlaskit/primitives/compiled';
21
+ import { closeTypeAhead } from '../pm-plugins/commands/close-type-ahead';
21
22
  import { updateSelectedIndex } from '../pm-plugins/commands/update-selected-index';
22
23
  import { TYPE_AHEAD_DECORATION_ELEMENT_ID } from '../pm-plugins/constants';
23
24
  import { getTypeAheadListAriaLabels, moveSelectedIndex } from '../pm-plugins/utils';
24
25
  import { ListRow } from './ListRow';
26
+ import { MoreOptions } from './MoreOptions';
25
27
  import { TypeAheadListItem } from './TypeAheadListItem';
26
28
  import { ViewMore } from './ViewMore';
27
29
  var LIST_ITEM_ESTIMATED_HEIGHT = 64;
@@ -46,7 +48,7 @@ var TypeaheadAssistiveTextPureComponent = /*#__PURE__*/React.memo(function (_ref
46
48
  });
47
49
  });
48
50
  var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
49
- var _decorationElement$qu2;
51
+ var _triggerHandler$getMo, _decorationElement$qu2;
50
52
  var items = _ref2.items,
51
53
  selectedIndex = _ref2.selectedIndex,
52
54
  editorView = _ref2.editorView,
@@ -57,8 +59,8 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
57
59
  triggerHandler = _ref2.triggerHandler,
58
60
  moreElementsInQuickInsertViewEnabled = _ref2.moreElementsInQuickInsertViewEnabled,
59
61
  api = _ref2.api,
60
- showViewMore = _ref2.showViewMore,
61
- onViewMoreClick = _ref2.onViewMoreClick;
62
+ showMoreOptionsButton = _ref2.showMoreOptionsButton,
63
+ onMoreOptionsClicked = _ref2.onMoreOptionsClicked;
62
64
  var listRef = useRef();
63
65
  var listContainerRef = useRef(null);
64
66
  var lastVisibleIndexes = useRef({
@@ -69,7 +71,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
69
71
  });
70
72
 
71
73
  // Exclude view more item from the count
72
- var itemsLength = showViewMore ? items.length - 1 : items.length;
74
+ var itemsLength = showMoreOptionsButton ? Math.max(items.length - 1, 0) : items.length;
73
75
  var estimatedHeight = itemsLength * LIST_ITEM_ESTIMATED_HEIGHT;
74
76
  var _useState = useState(Math.min(estimatedHeight, fitHeight)),
75
77
  _useState2 = _slicedToArray(_useState, 2),
@@ -136,7 +138,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
136
138
  // to calculate each height. THen, we can schedule a new frame when this one finishs.
137
139
  requestAnimationFrame(function () {
138
140
  requestAnimationFrame(function () {
139
- var isViewMoreSelected = showViewMore && selectedIndex === itemsLength;
141
+ var isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
140
142
  var isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex ||
141
143
  // view more is always visible, hence no scrolling
142
144
  isViewMoreSelected;
@@ -149,7 +151,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
149
151
  }
150
152
  });
151
153
  });
152
- }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showViewMore]);
154
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
153
155
  var _onMouseMove = function onMouseMove(event, index) {
154
156
  event.preventDefault();
155
157
  event.stopPropagation();
@@ -162,7 +164,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
162
164
  if (!listRef.current) {
163
165
  return;
164
166
  }
165
- var isViewMoreSelected = showViewMore && selectedIndex === itemsLength;
167
+ var isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
166
168
  var isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex ||
167
169
  // view more is always visible, hence no scrolling
168
170
  isViewMoreSelected;
@@ -173,7 +175,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
173
175
  } else if (selectedIndex === -1) {
174
176
  listRef.current.scrollToRow(0);
175
177
  }
176
- }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showViewMore]);
178
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
177
179
  useLayoutEffect(function () {
178
180
  setCache(new CellMeasurerCache({
179
181
  fixedWidth: true,
@@ -192,14 +194,14 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
192
194
  }, [items]);
193
195
  useLayoutEffect(function () {
194
196
  // Exclude view more item from the count
195
- var itemsToRender = showViewMore ? items.slice(0, -1) : items;
197
+ var itemsToRender = showMoreOptionsButton ? items.slice(0, -1) : items;
196
198
  var height = Math.min(itemsToRender.reduce(function (prevValue, currentValue, index) {
197
199
  return prevValue + cache.rowHeight({
198
200
  index: index
199
201
  });
200
202
  }, 0), fitHeight);
201
203
  setHeight(height);
202
- }, [items, cache, fitHeight, showViewMore]);
204
+ }, [items, cache, fitHeight, showMoreOptionsButton]);
203
205
  useLayoutEffect(function () {
204
206
  if (!listContainerRef.current) {
205
207
  return;
@@ -259,13 +261,27 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
259
261
  return item.isDisabledOffline !== true;
260
262
  });
261
263
  }, [items]);
262
- var renderRow = function renderRow(_ref4) {
263
- var index = _ref4.index,
264
- key = _ref4.key,
265
- style = _ref4.style,
266
- parent = _ref4.parent,
267
- isScrolling = _ref4.isScrolling,
268
- isVisible = _ref4.isVisible;
264
+ var config = triggerHandler === null || triggerHandler === void 0 || (_triggerHandler$getMo = triggerHandler.getMoreOptionsButtonConfig) === null || _triggerHandler$getMo === void 0 ? void 0 : _triggerHandler$getMo.call(triggerHandler, intl);
265
+ var handleClick = function handleClick() {
266
+ if (onMoreOptionsClicked) {
267
+ onMoreOptionsClicked();
268
+ }
269
+ api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
270
+ var tr = _ref4.tr;
271
+ closeTypeAhead(tr);
272
+ config === null || config === void 0 || config.onClick({
273
+ tr: tr
274
+ });
275
+ return tr;
276
+ });
277
+ };
278
+ var renderRow = function renderRow(_ref5) {
279
+ var index = _ref5.index,
280
+ key = _ref5.key,
281
+ style = _ref5.style,
282
+ parent = _ref5.parent,
283
+ isScrolling = _ref5.isScrolling,
284
+ isVisible = _ref5.isVisible;
269
285
  var currentItem = items[index];
270
286
  return jsx(CellMeasurer, {
271
287
  key: key,
@@ -273,9 +289,9 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
273
289
  parent: parent,
274
290
  columnIndex: 0,
275
291
  rowIndex: index
276
- }, fg('platform_editor_typeahead_dynamic_height_fix') ? function (_ref5) {
277
- var measure = _ref5.measure,
278
- registerChild = _ref5.registerChild;
292
+ }, fg('platform_editor_typeahead_dynamic_height_fix') ? function (_ref6) {
293
+ var measure = _ref6.measure,
294
+ registerChild = _ref6.registerChild;
279
295
  return jsx(ListRow, {
280
296
  registerChild: registerChild,
281
297
  measure: measure,
@@ -384,8 +400,14 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
384
400
  }, jsx("div", {
385
401
  id: menuGroupId,
386
402
  ref: listContainerRef
387
- }, !showViewMore || itemsLength ? ListContent : EmptyResultView, showViewMore && onViewMoreClick && jsx(ViewMore, {
388
- onClick: onViewMoreClick,
403
+ }, !showMoreOptionsButton || itemsLength ? ListContent : EmptyResultView, fg('platform_editor_controls_patch_12') ? showMoreOptionsButton && config && jsx(MoreOptions, {
404
+ title: config.title,
405
+ ariaLabel: config.ariaLabel,
406
+ onClick: handleClick,
407
+ isFocused: selectedIndex === itemsLength,
408
+ iconBefore: config.iconBefore
409
+ }) : showMoreOptionsButton && onMoreOptionsClicked && jsx(ViewMore, {
410
+ onClick: onMoreOptionsClicked,
389
411
  isFocused: selectedIndex === itemsLength
390
412
  }), jsx(TypeaheadAssistiveTextPureComponent, {
391
413
  numberOfResults: itemsLength.toString()
@@ -1,6 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import React from 'react';
3
3
  import { SelectItemMode, TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
6
  import { updateSelectedIndex } from '../pm-plugins/commands/update-selected-index';
6
7
  import { useItemInsert } from './hooks/use-item-insert';
@@ -74,8 +75,15 @@ export var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
74
75
 
75
76
  // @ts-ignore
76
77
  var openElementBrowserModal = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.openElementBrowserModal;
77
- var showViewMore = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1');
78
- if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || !showViewMore && items.length === 0 && !errorInfo) {
78
+ var showMoreOptionsButton = false;
79
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
80
+ if (fg('platform_editor_controls_patch_12')) {
81
+ showMoreOptionsButton = !!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getMoreOptionsButtonConfig);
82
+ } else {
83
+ showMoreOptionsButton = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal;
84
+ }
85
+ }
86
+ if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || !openElementBrowserModal && items.length === 0 && !errorInfo) {
79
87
  return null;
80
88
  }
81
89
  return /*#__PURE__*/React.createElement(TypeAheadPopup, {
@@ -94,6 +102,6 @@ export var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
94
102
  isEmptyQuery: !query,
95
103
  cancel: cancel,
96
104
  api: api,
97
- showViewMore: showViewMore
105
+ showMoreOptionsButton: showMoreOptionsButton
98
106
  });
99
107
  });
@@ -81,7 +81,7 @@ export var TypeAheadPopup = /*#__PURE__*/React.memo(function (props) {
81
81
  isEmptyQuery = props.isEmptyQuery,
82
82
  cancel = props.cancel,
83
83
  api = props.api,
84
- showViewMore = props.showViewMore;
84
+ showMoreOptionsButton = props.showMoreOptionsButton;
85
85
  var ref = useRef(null);
86
86
  var _useSharedState = useSharedState(api),
87
87
  moreElementsInQuickInsertView = _useSharedState.moreElementsInQuickInsertView;
@@ -150,11 +150,11 @@ export var TypeAheadPopup = /*#__PURE__*/React.memo(function (props) {
150
150
  fitHeight = _useState2[0],
151
151
  setFitHeight = _useState2[1];
152
152
  var fitHeightWithViewMore = useMemo(function () {
153
- if (showViewMore) {
153
+ if (showMoreOptionsButton) {
154
154
  return fitHeight - VIEWMORE_BUTTON_HEIGHT;
155
155
  }
156
156
  return fitHeight;
157
- }, [fitHeight, showViewMore]);
157
+ }, [fitHeight, showMoreOptionsButton]);
158
158
  var getFitHeight = useCallback(function () {
159
159
  if (!anchorElement || !popupsMountPoint) {
160
160
  return;
@@ -303,20 +303,21 @@ export var TypeAheadPopup = /*#__PURE__*/React.memo(function (props) {
303
303
  closeTypeAhead(tr);
304
304
  editorView.dispatch(tr);
305
305
  };
306
- var onViewMoreClick = useCallback(function () {
307
- close(editorView);
308
- if (openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_4')) {
306
+ var onMoreOptionsClicked = useCallback(function () {
307
+ if (
308
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
309
+ openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_4') && (!fg('platform_editor_controls_patch_12') || triggerHandler.id === TypeAheadAvailableNodes.QUICK_INSERT)) {
309
310
  activityStateRef.current = {
310
311
  inputMethod: INPUT_METHOD.MOUSE,
311
312
  closeAction: ACTION.VIEW_MORE,
312
313
  invocationMethod: activityStateRef.current.invocationMethod
313
314
  };
314
315
  }
315
-
316
- // TODO: ED-26959 - when clean up, remove config in quick insert plugin
317
- // platform/packages/editor/editor-plugin-quick-insert/src/quickInsertPlugin.tsx (typeAhead.openElementBrowserModal)
318
- openElementBrowserModal === null || openElementBrowserModal === void 0 || openElementBrowserModal();
319
- }, [editorView, openElementBrowserModal]);
316
+ if (!fg('platform_editor_controls_patch_12')) {
317
+ close(editorView);
318
+ openElementBrowserModal === null || openElementBrowserModal === void 0 || openElementBrowserModal();
319
+ }
320
+ }, [editorView, openElementBrowserModal, triggerHandler.id]);
320
321
  return jsx(Popup, {
321
322
  zIndex: akEditorFloatingDialogZIndex,
322
323
  target: anchorElement,
@@ -343,7 +344,7 @@ export var TypeAheadPopup = /*#__PURE__*/React.memo(function (props) {
343
344
  }
344
345
  }
345
346
  }, jsx("div", {
346
- css: [typeAheadContent, moreElementsInQuickInsertViewEnabled && typeAheadContentOverride, showViewMore && typeAheadWrapperWithViewMoreOverride]
347
+ css: [typeAheadContent, moreElementsInQuickInsertViewEnabled && typeAheadContentOverride, showMoreOptionsButton && typeAheadWrapperWithViewMoreOverride]
347
348
  // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
348
349
  ,
349
350
  tabIndex: 0
@@ -373,8 +374,8 @@ export var TypeAheadPopup = /*#__PURE__*/React.memo(function (props) {
373
374
  triggerHandler: triggerHandler,
374
375
  moreElementsInQuickInsertViewEnabled: moreElementsInQuickInsertViewEnabled,
375
376
  api: api,
376
- showViewMore: showViewMore,
377
- onViewMoreClick: onViewMoreClick
377
+ showMoreOptionsButton: showMoreOptionsButton,
378
+ onMoreOptionsClicked: onMoreOptionsClicked
378
379
  }))));
379
380
  });
380
381
  TypeAheadPopup.displayName = 'TypeAheadPopup';
@@ -27,7 +27,14 @@ export var WrapperTypeAhead = /*#__PURE__*/React.memo(function (_ref) {
27
27
  api = _ref.api;
28
28
  // @ts-ignore
29
29
  var openElementBrowserModal = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.openElementBrowserModal;
30
- var showViewMore = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal && editorExperiment('platform_editor_controls', 'variant1');
30
+ var showMoreOptionsButton = false;
31
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
32
+ if (fg('platform_editor_controls_patch_12')) {
33
+ showMoreOptionsButton = !!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getMoreOptionsButtonConfig);
34
+ } else {
35
+ showMoreOptionsButton = (triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.id) === TypeAheadAvailableNodes.QUICK_INSERT && !!openElementBrowserModal;
36
+ }
37
+ }
31
38
  var _useState = useState(false),
32
39
  _useState2 = _slicedToArray(_useState, 2),
33
40
  closed = _useState2[0],
@@ -38,7 +45,7 @@ export var WrapperTypeAhead = /*#__PURE__*/React.memo(function (_ref) {
38
45
  setQuery = _useState4[1];
39
46
  var queryRef = useRef(query);
40
47
  var editorViewRef = useRef(editorView);
41
- var items = useLoadItems(triggerHandler, editorView, query, showViewMore);
48
+ var items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton);
42
49
  useEffect(function () {
43
50
  if (!closed && fg('platform_editor_ease_of_use_metrics')) {
44
51
  var _api$metrics;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { jsx } from '@emotion/react';
3
+ type Props = {
4
+ onClick: () => void;
5
+ isFocused: boolean;
6
+ title: string;
7
+ ariaLabel?: string;
8
+ iconBefore?: React.ReactNode;
9
+ };
10
+ export declare const MoreOptions: ({ onClick, isFocused, title, ariaLabel, iconBefore }: Props) => jsx.JSX.Element;
11
+ export {};
@@ -20,8 +20,8 @@ export declare const TypeAheadList: React.FC<import("react-intl-next").WithIntlP
20
20
  triggerHandler?: TypeAheadHandler | undefined;
21
21
  moreElementsInQuickInsertViewEnabled?: boolean | undefined;
22
22
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
23
- showViewMore?: boolean | undefined;
24
- onViewMoreClick?: (() => void) | undefined;
23
+ showMoreOptionsButton?: boolean | undefined;
24
+ onMoreOptionsClicked?: (() => void) | undefined;
25
25
  } & WrappedComponentProps>> & {
26
26
  WrappedComponent: React.ComponentType<{
27
27
  items: Array<TypeAheadItem>;
@@ -33,7 +33,7 @@ export declare const TypeAheadList: React.FC<import("react-intl-next").WithIntlP
33
33
  triggerHandler?: TypeAheadHandler | undefined;
34
34
  moreElementsInQuickInsertViewEnabled?: boolean | undefined;
35
35
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
36
- showViewMore?: boolean | undefined;
37
- onViewMoreClick?: (() => void) | undefined;
36
+ showMoreOptionsButton?: boolean | undefined;
37
+ onMoreOptionsClicked?: (() => void) | undefined;
38
38
  } & WrappedComponentProps>;
39
39
  };
@@ -30,7 +30,7 @@ type TypeAheadPopupProps = {
30
30
  forceFocusOnEditor: boolean;
31
31
  }) => void;
32
32
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
33
- showViewMore?: boolean;
33
+ showMoreOptionsButton?: boolean;
34
34
  };
35
35
  export declare const TypeAheadPopup: React.MemoExoticComponent<(props: TypeAheadPopupProps) => jsx.JSX.Element>;
36
36
  export {};
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { jsx } from '@emotion/react';
3
+ type Props = {
4
+ onClick: () => void;
5
+ isFocused: boolean;
6
+ title: string;
7
+ ariaLabel?: string;
8
+ iconBefore?: React.ReactNode;
9
+ };
10
+ export declare const MoreOptions: ({ onClick, isFocused, title, ariaLabel, iconBefore }: Props) => jsx.JSX.Element;
11
+ export {};
@@ -20,8 +20,8 @@ export declare const TypeAheadList: React.FC<import("react-intl-next").WithIntlP
20
20
  triggerHandler?: TypeAheadHandler | undefined;
21
21
  moreElementsInQuickInsertViewEnabled?: boolean | undefined;
22
22
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
23
- showViewMore?: boolean | undefined;
24
- onViewMoreClick?: (() => void) | undefined;
23
+ showMoreOptionsButton?: boolean | undefined;
24
+ onMoreOptionsClicked?: (() => void) | undefined;
25
25
  } & WrappedComponentProps>> & {
26
26
  WrappedComponent: React.ComponentType<{
27
27
  items: Array<TypeAheadItem>;
@@ -33,7 +33,7 @@ export declare const TypeAheadList: React.FC<import("react-intl-next").WithIntlP
33
33
  triggerHandler?: TypeAheadHandler | undefined;
34
34
  moreElementsInQuickInsertViewEnabled?: boolean | undefined;
35
35
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
36
- showViewMore?: boolean | undefined;
37
- onViewMoreClick?: (() => void) | undefined;
36
+ showMoreOptionsButton?: boolean | undefined;
37
+ onMoreOptionsClicked?: (() => void) | undefined;
38
38
  } & WrappedComponentProps>;
39
39
  };
@@ -30,7 +30,7 @@ type TypeAheadPopupProps = {
30
30
  forceFocusOnEditor: boolean;
31
31
  }) => void;
32
32
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
33
- showViewMore?: boolean;
33
+ showMoreOptionsButton?: boolean;
34
34
  };
35
35
  export declare const TypeAheadPopup: React.MemoExoticComponent<(props: TypeAheadPopupProps) => jsx.JSX.Element>;
36
36
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-type-ahead",
3
- "version": "2.7.10",
3
+ "version": "2.7.11",
4
4
  "description": "Type-ahead plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^47.6.0",
37
- "@atlaskit/editor-common": "^106.1.0",
37
+ "@atlaskit/editor-common": "^106.3.0",
38
38
  "@atlaskit/editor-element-browser": "^0.1.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^2.3.0",
40
40
  "@atlaskit/editor-plugin-connectivity": "^2.0.0",
@@ -49,7 +49,7 @@
49
49
  "@atlaskit/primitives": "^14.8.0",
50
50
  "@atlaskit/prosemirror-input-rules": "^3.3.0",
51
51
  "@atlaskit/theme": "^18.0.0",
52
- "@atlaskit/tmp-editor-statsig": "^5.7.0",
52
+ "@atlaskit/tmp-editor-statsig": "^5.13.0",
53
53
  "@atlaskit/tokens": "^5.0.0",
54
54
  "@babel/runtime": "^7.0.0",
55
55
  "@emotion/react": "^11.7.1",
@@ -125,6 +125,9 @@
125
125
  },
126
126
  "platform_editor_controls_patch_8": {
127
127
  "type": "boolean"
128
+ },
129
+ "platform_editor_controls_patch_12": {
130
+ "type": "boolean"
128
131
  }
129
132
  }
130
133
  }