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

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,24 @@
1
1
  # @atlaskit/editor-plugin-type-ahead
2
2
 
3
+ ## 2.7.12
4
+
5
+ ### Patch Changes
6
+
7
+ - [#165113](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/165113)
8
+ [`867bcb05452bf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/867bcb05452bf) -
9
+ Cleaned up platform_editor_controls_patch_analytics and platform_editor_controls_patch_analytics_2
10
+ - Updated dependencies
11
+
12
+ ## 2.7.11
13
+
14
+ ### Patch Changes
15
+
16
+ - [#164625](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/164625)
17
+ [`aac10c2d4c08d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/aac10c2d4c08d) -
18
+ [ED-26900] Add a new config, getMoreOptionsButtonConfig, to TypeAheadHandler so that it can
19
+ support adding a more option button to typeahead list
20
+ - Updated dependencies
21
+
3
22
  ## 2.7.10
4
23
 
5
24
  ### Patch Changes
@@ -1,30 +1,23 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.fireTypeAheadClosedAnalyticsEvent = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
7
  var _analytics = require("@atlaskit/editor-common/analytics");
10
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
- 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; }
12
- 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) { (0, _defineProperty2.default)(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; }
13
8
  var fireTypeAheadClosedAnalyticsEvent = exports.fireTypeAheadClosedAnalyticsEvent = function fireTypeAheadClosedAnalyticsEvent(api, closeAction, hasQuery, inputMethod) {
14
9
  var _api$analytics;
15
10
  var invocationMethod = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
16
- var additionalAttributes = (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_analytics') ? {
17
- invocationMethod: invocationMethod
18
- } : {};
19
11
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
20
12
  action: _analytics.ACTION.CLOSED,
21
13
  actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
22
14
  actionSubjectId: _analytics.ACTION_SUBJECT_ID.TYPEAHEAD_QUICK_INSERT,
23
- attributes: _objectSpread({
15
+ attributes: {
24
16
  inputMethod: inputMethod,
25
17
  closeAction: closeAction,
26
- hasQuery: hasQuery
27
- }, additionalAttributes),
18
+ hasQuery: hasQuery,
19
+ invocationMethod: invocationMethod
20
+ },
28
21
  eventType: _analytics.EVENT_TYPE.TRACK
29
22
  });
30
23
  };
@@ -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;
@@ -1,10 +1,6 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
- import { fg } from '@atlaskit/platform-feature-flags';
3
2
  export const fireTypeAheadClosedAnalyticsEvent = (api, closeAction, hasQuery, inputMethod, invocationMethod = null) => {
4
3
  var _api$analytics;
5
- const additionalAttributes = fg('platform_editor_controls_patch_analytics') ? {
6
- invocationMethod
7
- } : {};
8
4
  api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
9
5
  action: ACTION.CLOSED,
10
6
  actionSubject: ACTION_SUBJECT.TYPEAHEAD,
@@ -13,7 +9,7 @@ export const fireTypeAheadClosedAnalyticsEvent = (api, closeAction, hasQuery, in
13
9
  inputMethod,
14
10
  closeAction,
15
11
  hasQuery,
16
- ...additionalAttributes
12
+ invocationMethod
17
13
  },
18
14
  eventType: EVENT_TYPE.TRACK
19
15
  });
@@ -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()