@atlaskit/editor-plugin-insert-block 26.0.0 → 26.0.2

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,34 @@
1
1
  # @atlaskit/editor-plugin-insert-block
2
2
 
3
+ ## 26.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`685643d223f9d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/685643d223f9d) -
8
+ Complete cleanup of the `cc_fd_db_top_editor_toolbar` experiment. Always sort featured toolbar
9
+ insert items by provider priority across platforms, matching quick insert ordering. Remove
10
+ hardcoded whiteboard pinning and preserve provider descriptions, retaining the shipped
11
+ `new-description` behavior without product checks, preset options, or experiment setup.
12
+
13
+ Breaking change in `@atlaskit/tmp-editor-statsig`: remove `cc_fd_db_top_editor_toolbar` from
14
+ `editorExperimentsConfig` and `testMultivariateOverrides`. Consumers referencing
15
+ `editorExperimentsConfig.cc_fd_db_top_editor_toolbar` or calling
16
+ `expVal('cc_fd_db_top_editor_toolbar', ...)` (or other typed experiment helpers) will receive
17
+ TypeScript errors after upgrading. To migrate, remove those experiment queries and test overrides,
18
+ and retain the shipped `new-description` behavior instead of branching on the removed experiment.
19
+
20
+ - Updated dependencies
21
+
22
+ ## 26.0.1
23
+
24
+ ### Patch Changes
25
+
26
+ - [`5351e01090c9c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5351e01090c9c) -
27
+ Show the five strongest matches first, then remaining matches in category order without category
28
+ titles, in slash-command and toolbar insert search. Share the row projection across rendering and
29
+ keyboard selection under the platform_editor_slash_command experiment.
30
+ - Updated dependencies
31
+
3
32
  ## 26.0.0
4
33
 
5
34
  ### Patch Changes
@@ -7,12 +7,11 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.sortFeaturedItems = exports.default = exports.DEFAULT_HEIGHT = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
13
  var _react = require("react");
14
14
  var _react2 = require("@emotion/react");
15
- var _reactIntl = require("react-intl");
16
15
  var _CellMeasurer = require("react-virtualized/dist/commonjs/CellMeasurer");
17
16
  var _analytics = require("@atlaskit/editor-common/analytics");
18
17
  var _elementBrowser = require("@atlaskit/editor-common/element-browser");
@@ -20,7 +19,6 @@ var _hooks = require("@atlaskit/editor-common/hooks");
20
19
  var _quickInsert = require("@atlaskit/editor-common/quick-insert");
21
20
  var _uiReact = require("@atlaskit/editor-common/ui-react");
22
21
  var _editorPluginConnectivity = require("@atlaskit/editor-plugin-connectivity");
23
- var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
24
22
  var _excluded = ["children"];
25
23
  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; }
26
24
  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; } /**
@@ -30,45 +28,13 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
30
28
  var DEFAULT_HEIGHT = exports.DEFAULT_HEIGHT = 560;
31
29
 
32
30
  /**
33
- * Exported helper to allow testing of InsertMenu pinning logic.
34
- *
35
- * The `cc_fd_db_top_editor_toolbar` experiment adds new logic to sort elements by `priority`.
36
- * This newer implementation matches how the quick insert menu sorts elements.
31
+ * Sort featured elements by priority, matching the quick insert menu.
37
32
  */
38
- var sortFeaturedItems = exports.sortFeaturedItems = function sortFeaturedItems(featuredItems, formatMessage) {
39
- if (['new-description', 'orig-description'].includes((0, _expVal.expVal)('cc_fd_db_top_editor_toolbar', 'cohort', 'control')) || (0, _expVal.expValNoExposure)('cc_fd_wb_jira_quick_insert_experiment', 'isEnabled', false)) {
40
- // Sort by priority (lower first) on the concatenated list so items
41
- // with "priority" are at the top (e.g. Whiteboard before Database)
42
- return featuredItems.slice(0).sort(function (a, b) {
43
- return (a.priority || Number.POSITIVE_INFINITY) - (b.priority || Number.POSITIVE_INFINITY);
44
- });
45
- }
46
-
47
- // NOTE: this is *not* the ideal way to approach this. Old logic sort whiteboards to top
48
- var DIAGRAM_KEY = 'whiteboard-extension:create-diagram';
49
- var isDiagram = function isDiagram(item) {
50
- return item.key === DIAGRAM_KEY;
51
- };
52
- var featuredWhiteboardsPresent = featuredItems.some(isDiagram);
53
- if (featuredWhiteboardsPresent) {
54
- var pin = function pin(key) {
55
- var idx = featuredItems.findIndex(function (item) {
56
- return item.key === key;
57
- });
58
- var filtered = featuredItems.filter(function (item) {
59
- return !isDiagram(item);
60
- });
61
- if (idx === -1) {
62
- return filtered;
63
- }
64
- var picked = _objectSpread(_objectSpread({}, featuredItems[idx]), {}, {
65
- description: formatMessage(_quickInsert.messages.featuredWhiteboardDescription)
66
- });
67
- return [picked].concat((0, _toConsumableArray2.default)(filtered));
68
- };
69
- return pin(DIAGRAM_KEY);
70
- }
71
- return featuredItems;
33
+ var sortFeaturedItems = exports.sortFeaturedItems = function sortFeaturedItems(featuredItems) {
34
+ return featuredItems.slice(0).sort(function (a, b) {
35
+ var _a$priority, _b$priority;
36
+ return ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : Number.POSITIVE_INFINITY) - ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : Number.POSITIVE_INFINITY);
37
+ });
72
38
  };
73
39
  var selector = function selector(states) {
74
40
  var _states$connectivityS;
@@ -92,8 +58,6 @@ var InsertMenu = function InsertMenu(_ref) {
92
58
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
93
59
  height = _useState4[0],
94
60
  setHeight = _useState4[1];
95
- var _useIntl = (0, _reactIntl.useIntl)(),
96
- formatMessage = _useIntl.formatMessage;
97
61
  var cache = (0, _react.useMemo)(function () {
98
62
  return new _CellMeasurer.CellMeasurerCache({
99
63
  fixedWidth: true,
@@ -182,11 +146,11 @@ var InsertMenu = function InsertMenu(_ref) {
182
146
  })) !== null && _pluginInjectionApi$q4 !== void 0 ? _pluginInjectionApi$q4 : [];
183
147
  var unfilteredResult = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
184
148
  // need to sort on the concatenated list so desired elements are at the top
185
- result = sortFeaturedItems(unfilteredResult, formatMessage);
149
+ result = sortFeaturedItems(unfilteredResult);
186
150
  }
187
151
  setItemCount(result.length);
188
152
  return result;
189
- }, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems, connectivityMode, formatMessage]);
153
+ }, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems, connectivityMode]);
190
154
  var emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q7 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q7 === void 0 || (_pluginInjectionApi$q7 = _pluginInjectionApi$q7.sharedState.currentState()) === null || _pluginInjectionApi$q7 === void 0 ? void 0 : _pluginInjectionApi$q7.emptyStateHandler;
191
155
  var onViewMore = (0, _react.useCallback)(function () {
192
156
  var _pluginInjectionApi$c, _pluginInjectionApi$q8;
@@ -10,7 +10,6 @@ exports.RegisteredInsertMenu = void 0;
10
10
  require("./RegisteredInsertMenu.compiled.css");
11
11
  var _runtime = require("@compiled/react/runtime");
12
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
- var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
14
13
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
14
  var _react = _interopRequireWildcard(require("react"));
16
15
  var _reactIntl = require("react-intl");
@@ -25,7 +24,6 @@ var _compiled = require("@atlaskit/primitives/compiled");
25
24
  var _textField = _interopRequireDefault(require("@atlaskit/textfield/text-field"));
26
25
  var _RegisteredInsertMenuList = require("./RegisteredInsertMenuList");
27
26
  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); }
28
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29
27
  var DEFAULT_MENU_MAX_HEIGHT = 520;
30
28
  var styles = {
31
29
  menu: "_2rko1mok _1reo15vq _18m915vq _bfhk1bhr _16qs130s _1e0c1txw _2lx21bp4 _1bsb1edt",
@@ -94,27 +92,18 @@ var RegisteredInsertMenu = exports.RegisteredInsertMenu = function RegisteredIns
94
92
  surfaceContext: surfaceContext
95
93
  });
96
94
  }, [components, formatMessage, hasSectionOverflowItems, query, surfaceContext]);
97
- var itemCount = (0, _react.useMemo)(function () {
98
- var _model$fallbackItems$, _model$fallbackItems;
99
- return model.sections.reduce(function (count, _ref3) {
100
- var _ref4 = (0, _toArray2.default)(_ref3),
101
- items = _arrayLikeToArray(_ref4).slice(1);
102
- return count + items.length;
103
- }, 0) + ((_model$fallbackItems$ = (_model$fallbackItems = model.fallbackItems) === null || _model$fallbackItems === void 0 ? void 0 : _model$fallbackItems.length) !== null && _model$fallbackItems$ !== void 0 ? _model$fallbackItems$ : 0) + (model.footer ? 1 : 0);
104
- }, [model.fallbackItems, model.footer, model.sections]);
95
+ var selectableItems = (0, _react.useMemo)(function () {
96
+ return (0, _registeredMenuModel.getQuickInsertMenuRows)(model).filter(function (row) {
97
+ return row.type === 'menu-item';
98
+ });
99
+ }, [model]);
100
+ var itemCount = selectableItems.length + (model.footer ? 1 : 0);
105
101
  var selectableItemKeys = (0, _react.useMemo)(function () {
106
- var _model$fallbackItems2;
107
- return [].concat((0, _toConsumableArray2.default)(model.sections.flatMap(function (_ref5) {
108
- var _ref6 = (0, _toArray2.default)(_ref5),
109
- items = _arrayLikeToArray(_ref6).slice(1);
110
- return items;
111
- })), (0, _toConsumableArray2.default)((_model$fallbackItems2 = model.fallbackItems) !== null && _model$fallbackItems2 !== void 0 ? _model$fallbackItems2 : []), [model.footer]).filter(function (item) {
112
- return Boolean(item);
113
- }).map(function (_ref7) {
114
- var key = _ref7.key;
102
+ return [].concat((0, _toConsumableArray2.default)(selectableItems), (0, _toConsumableArray2.default)(model.footer ? [model.footer] : [])).map(function (_ref3) {
103
+ var key = _ref3.key;
115
104
  return key;
116
105
  }).join(',');
117
- }, [model.fallbackItems, model.footer, model.sections]);
106
+ }, [model.footer, selectableItems]);
118
107
  (0, _react.useLayoutEffect)(function () {
119
108
  setSelectedItemIndex(itemCount > 0 ? 0 : -1);
120
109
  }, [itemCount, query, selectableItemKeys]);
@@ -10,11 +10,12 @@ exports.RegisteredInsertMenuList = void 0;
10
10
  require("./RegisteredInsertMenuList.compiled.css");
11
11
  var _runtime = require("@compiled/react/runtime");
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
14
13
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
15
  var _react = _interopRequireWildcard(require("react"));
16
16
  var _CellMeasurer = require("react-virtualized/dist/commonjs/CellMeasurer");
17
17
  var _List = require("react-virtualized/dist/commonjs/List");
18
+ var _registeredMenuModel = require("@atlaskit/editor-common/quick-insert/registered-menu-model");
18
19
  var _useMenuListHeight2 = require("@atlaskit/editor-common/quick-insert/use-menu-list-height");
19
20
  var _compiled = require("@atlaskit/primitives/compiled");
20
21
  var _RegisteredInsertMenuItem = require("./RegisteredInsertMenuItem");
@@ -58,9 +59,8 @@ var RegisteredInsertMenuList = exports.RegisteredInsertMenuList = function Regis
58
59
  listRef.current = list;
59
60
  }, []);
60
61
  var rows = (0, _react.useMemo)(function () {
61
- var _model$fallbackItems;
62
- return [].concat((0, _toConsumableArray2.default)(model.sections.flat()), (0, _toConsumableArray2.default)((_model$fallbackItems = model.fallbackItems) !== null && _model$fallbackItems !== void 0 ? _model$fallbackItems : []));
63
- }, [model.fallbackItems, model.sections]);
62
+ return (0, _registeredMenuModel.getQuickInsertMenuRows)(model);
63
+ }, [model]);
64
64
  var cache = (0, _react.useMemo)(function () {
65
65
  return new _CellMeasurer.CellMeasurerCache({
66
66
  defaultHeight: ESTIMATED_ROW_HEIGHT,
@@ -8,50 +8,23 @@ import { useCallback, useContext, useLayoutEffect, useMemo, useState } from 'rea
8
8
 
9
9
  /* eslint-disable @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports, jsdoc/require-description -- Ignored via go/DSP-18766; jsdoc debt surfaced by this mechanical PR */
10
10
  import { css, jsx } from '@emotion/react';
11
- import { useIntl } from 'react-intl';
12
11
  import { CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
13
12
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
14
13
  import { ELEMENT_ITEM_HEIGHT, ElementBrowser } from '@atlaskit/editor-common/element-browser';
15
14
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
16
- import { messages, IconCode, IconDate, IconDecision, IconDivider, IconExpand, IconPanel, IconQuote, IconStatus } from '@atlaskit/editor-common/quick-insert';
15
+ import { IconCode, IconDate, IconDecision, IconDivider, IconExpand, IconPanel, IconQuote, IconStatus } from '@atlaskit/editor-common/quick-insert';
17
16
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
18
17
  import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
19
- import { expVal, expValNoExposure } from '@atlaskit/tmp-editor-statsig/expVal';
20
18
  export const DEFAULT_HEIGHT = 560;
21
19
 
22
20
  /**
23
- * Exported helper to allow testing of InsertMenu pinning logic.
24
- *
25
- * The `cc_fd_db_top_editor_toolbar` experiment adds new logic to sort elements by `priority`.
26
- * This newer implementation matches how the quick insert menu sorts elements.
21
+ * Sort featured elements by priority, matching the quick insert menu.
27
22
  */
28
- export const sortFeaturedItems = (featuredItems, formatMessage) => {
29
- if (['new-description', 'orig-description'].includes(expVal('cc_fd_db_top_editor_toolbar', 'cohort', 'control')) || expValNoExposure('cc_fd_wb_jira_quick_insert_experiment', 'isEnabled', false)) {
30
- // Sort by priority (lower first) on the concatenated list so items
31
- // with "priority" are at the top (e.g. Whiteboard before Database)
32
- return featuredItems.slice(0).sort((a, b) => (a.priority || Number.POSITIVE_INFINITY) - (b.priority || Number.POSITIVE_INFINITY));
33
- }
34
-
35
- // NOTE: this is *not* the ideal way to approach this. Old logic sort whiteboards to top
36
- const DIAGRAM_KEY = 'whiteboard-extension:create-diagram';
37
- const isDiagram = item => item.key === DIAGRAM_KEY;
38
- const featuredWhiteboardsPresent = featuredItems.some(isDiagram);
39
- if (featuredWhiteboardsPresent) {
40
- const pin = key => {
41
- const idx = featuredItems.findIndex(item => item.key === key);
42
- const filtered = featuredItems.filter(item => !isDiagram(item));
43
- if (idx === -1) {
44
- return filtered;
45
- }
46
- const picked = {
47
- ...featuredItems[idx],
48
- description: formatMessage(messages.featuredWhiteboardDescription)
49
- };
50
- return [picked, ...filtered];
51
- };
52
- return pin(DIAGRAM_KEY);
53
- }
54
- return featuredItems;
23
+ export const sortFeaturedItems = featuredItems => {
24
+ return featuredItems.slice(0).sort((a, b) => {
25
+ var _a$priority, _b$priority;
26
+ return ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : Number.POSITIVE_INFINITY) - ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : Number.POSITIVE_INFINITY);
27
+ });
55
28
  };
56
29
  const selector = states => {
57
30
  var _states$connectivityS;
@@ -70,9 +43,6 @@ const InsertMenu = ({
70
43
  var _pluginInjectionApi$q8, _pluginInjectionApi$q9, _pluginInjectionApi$q0;
71
44
  const [itemCount, setItemCount] = useState(0);
72
45
  const [height, setHeight] = useState(DEFAULT_HEIGHT);
73
- const {
74
- formatMessage
75
- } = useIntl();
76
46
  const cache = useMemo(() => {
77
47
  return new CellMeasurerCache({
78
48
  fixedWidth: true,
@@ -152,11 +122,11 @@ const InsertMenu = ({
152
122
  } : item)) !== null && _pluginInjectionApi$q5 !== void 0 ? _pluginInjectionApi$q5 : [];
153
123
  const unfilteredResult = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
154
124
  // need to sort on the concatenated list so desired elements are at the top
155
- result = sortFeaturedItems(unfilteredResult, formatMessage);
125
+ result = sortFeaturedItems(unfilteredResult);
156
126
  }
157
127
  setItemCount(result.length);
158
128
  return result;
159
- }, [pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q8 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q8 === void 0 ? void 0 : _pluginInjectionApi$q8.actions, quickInsertDropdownItems, connectivityMode, formatMessage]);
129
+ }, [pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q8 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q8 === void 0 ? void 0 : _pluginInjectionApi$q8.actions, quickInsertDropdownItems, connectivityMode]);
160
130
  const emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$q9 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q9 === void 0 ? void 0 : (_pluginInjectionApi$q0 = _pluginInjectionApi$q9.sharedState.currentState()) === null || _pluginInjectionApi$q0 === void 0 ? void 0 : _pluginInjectionApi$q0.emptyStateHandler;
161
131
  const onViewMore = useCallback(() => {
162
132
  var _pluginInjectionApi$c, _pluginInjectionApi$q1;
@@ -6,7 +6,7 @@ import { useIntl } from 'react-intl';
6
6
  import { getDocument } from '@atlaskit/browser-apis';
7
7
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
8
8
  import { MENU } from '@atlaskit/editor-common/quick-insert/keys';
9
- import { buildQuickInsertMenuModel, getMatchingQuickInsertComponents, selectQuickInsertCategoryItems } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
9
+ import { buildQuickInsertMenuModel, getMatchingQuickInsertComponents, getQuickInsertMenuRows, selectQuickInsertCategoryItems } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
10
10
  import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
11
11
  import { TYPE_AHEAD_SURFACE_CONTEXT } from '@atlaskit/editor-common/type-ahead-surface-context';
12
12
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
@@ -62,16 +62,11 @@ export const RegisteredInsertMenu = ({
62
62
  rootComponent: MENU,
63
63
  surfaceContext
64
64
  }), [components, formatMessage, hasSectionOverflowItems, query, surfaceContext]);
65
- const itemCount = useMemo(() => {
66
- var _model$fallbackItems$, _model$fallbackItems;
67
- return model.sections.reduce((count, [, ...items]) => count + items.length, 0) + ((_model$fallbackItems$ = (_model$fallbackItems = model.fallbackItems) === null || _model$fallbackItems === void 0 ? void 0 : _model$fallbackItems.length) !== null && _model$fallbackItems$ !== void 0 ? _model$fallbackItems$ : 0) + (model.footer ? 1 : 0);
68
- }, [model.fallbackItems, model.footer, model.sections]);
69
- const selectableItemKeys = useMemo(() => {
70
- var _model$fallbackItems2;
71
- return [...model.sections.flatMap(([, ...items]) => items), ...((_model$fallbackItems2 = model.fallbackItems) !== null && _model$fallbackItems2 !== void 0 ? _model$fallbackItems2 : []), model.footer].filter(item => Boolean(item)).map(({
72
- key
73
- }) => key).join(',');
74
- }, [model.fallbackItems, model.footer, model.sections]);
65
+ const selectableItems = useMemo(() => getQuickInsertMenuRows(model).filter(row => row.type === 'menu-item'), [model]);
66
+ const itemCount = selectableItems.length + (model.footer ? 1 : 0);
67
+ const selectableItemKeys = useMemo(() => [...selectableItems, ...(model.footer ? [model.footer] : [])].map(({
68
+ key
69
+ }) => key).join(','), [model.footer, selectableItems]);
75
70
  useLayoutEffect(() => {
76
71
  setSelectedItemIndex(itemCount > 0 ? 0 : -1);
77
72
  }, [itemCount, query, selectableItemKeys]);
@@ -5,6 +5,7 @@ import { ax, ix } from "@compiled/react/runtime";
5
5
  import React, { useCallback, useLayoutEffect, useMemo, useRef } from 'react';
6
6
  import { CellMeasurer, CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
7
7
  import { List } from 'react-virtualized/dist/commonjs/List';
8
+ import { getQuickInsertMenuRows } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
8
9
  import { useMenuListHeight } from '@atlaskit/editor-common/quick-insert/use-menu-list-height';
9
10
  import { Box } from '@atlaskit/primitives/compiled';
10
11
  import { RegisteredInsertMenuItem } from './RegisteredInsertMenuItem';
@@ -44,10 +45,7 @@ export const RegisteredInsertMenuList = ({
44
45
  const setListRef = useCallback(list => {
45
46
  listRef.current = list;
46
47
  }, []);
47
- const rows = useMemo(() => {
48
- var _model$fallbackItems;
49
- return [...model.sections.flat(), ...((_model$fallbackItems = model.fallbackItems) !== null && _model$fallbackItems !== void 0 ? _model$fallbackItems : [])];
50
- }, [model.fallbackItems, model.sections]);
48
+ const rows = useMemo(() => getQuickInsertMenuRows(model), [model]);
51
49
  const cache = useMemo(() => new CellMeasurerCache({
52
50
  defaultHeight: ESTIMATED_ROW_HEIGHT,
53
51
  fixedWidth: true
@@ -1,8 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
6
6
  var _excluded = ["children"];
7
7
  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; }
8
8
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -15,57 +15,23 @@ import { useCallback, useContext, useLayoutEffect, useMemo, useState } from 'rea
15
15
 
16
16
  /* eslint-disable @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports, jsdoc/require-description -- Ignored via go/DSP-18766; jsdoc debt surfaced by this mechanical PR */
17
17
  import { css, jsx } from '@emotion/react';
18
- import { useIntl } from 'react-intl';
19
18
  import { CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
20
19
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
21
20
  import { ELEMENT_ITEM_HEIGHT, ElementBrowser } from '@atlaskit/editor-common/element-browser';
22
21
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
23
- import { messages, IconCode, IconDate, IconDecision, IconDivider, IconExpand, IconPanel, IconQuote, IconStatus } from '@atlaskit/editor-common/quick-insert';
22
+ import { IconCode, IconDate, IconDecision, IconDivider, IconExpand, IconPanel, IconQuote, IconStatus } from '@atlaskit/editor-common/quick-insert';
24
23
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
25
24
  import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
26
- import { expVal, expValNoExposure } from '@atlaskit/tmp-editor-statsig/expVal';
27
25
  export var DEFAULT_HEIGHT = 560;
28
26
 
29
27
  /**
30
- * Exported helper to allow testing of InsertMenu pinning logic.
31
- *
32
- * The `cc_fd_db_top_editor_toolbar` experiment adds new logic to sort elements by `priority`.
33
- * This newer implementation matches how the quick insert menu sorts elements.
28
+ * Sort featured elements by priority, matching the quick insert menu.
34
29
  */
35
- export var sortFeaturedItems = function sortFeaturedItems(featuredItems, formatMessage) {
36
- if (['new-description', 'orig-description'].includes(expVal('cc_fd_db_top_editor_toolbar', 'cohort', 'control')) || expValNoExposure('cc_fd_wb_jira_quick_insert_experiment', 'isEnabled', false)) {
37
- // Sort by priority (lower first) on the concatenated list so items
38
- // with "priority" are at the top (e.g. Whiteboard before Database)
39
- return featuredItems.slice(0).sort(function (a, b) {
40
- return (a.priority || Number.POSITIVE_INFINITY) - (b.priority || Number.POSITIVE_INFINITY);
41
- });
42
- }
43
-
44
- // NOTE: this is *not* the ideal way to approach this. Old logic sort whiteboards to top
45
- var DIAGRAM_KEY = 'whiteboard-extension:create-diagram';
46
- var isDiagram = function isDiagram(item) {
47
- return item.key === DIAGRAM_KEY;
48
- };
49
- var featuredWhiteboardsPresent = featuredItems.some(isDiagram);
50
- if (featuredWhiteboardsPresent) {
51
- var pin = function pin(key) {
52
- var idx = featuredItems.findIndex(function (item) {
53
- return item.key === key;
54
- });
55
- var filtered = featuredItems.filter(function (item) {
56
- return !isDiagram(item);
57
- });
58
- if (idx === -1) {
59
- return filtered;
60
- }
61
- var picked = _objectSpread(_objectSpread({}, featuredItems[idx]), {}, {
62
- description: formatMessage(messages.featuredWhiteboardDescription)
63
- });
64
- return [picked].concat(_toConsumableArray(filtered));
65
- };
66
- return pin(DIAGRAM_KEY);
67
- }
68
- return featuredItems;
30
+ export var sortFeaturedItems = function sortFeaturedItems(featuredItems) {
31
+ return featuredItems.slice(0).sort(function (a, b) {
32
+ var _a$priority, _b$priority;
33
+ return ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : Number.POSITIVE_INFINITY) - ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : Number.POSITIVE_INFINITY);
34
+ });
69
35
  };
70
36
  var selector = function selector(states) {
71
37
  var _states$connectivityS;
@@ -89,8 +55,6 @@ var InsertMenu = function InsertMenu(_ref) {
89
55
  _useState4 = _slicedToArray(_useState3, 2),
90
56
  height = _useState4[0],
91
57
  setHeight = _useState4[1];
92
- var _useIntl = useIntl(),
93
- formatMessage = _useIntl.formatMessage;
94
58
  var cache = useMemo(function () {
95
59
  return new CellMeasurerCache({
96
60
  fixedWidth: true,
@@ -179,11 +143,11 @@ var InsertMenu = function InsertMenu(_ref) {
179
143
  })) !== null && _pluginInjectionApi$q4 !== void 0 ? _pluginInjectionApi$q4 : [];
180
144
  var unfilteredResult = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
181
145
  // need to sort on the concatenated list so desired elements are at the top
182
- result = sortFeaturedItems(unfilteredResult, formatMessage);
146
+ result = sortFeaturedItems(unfilteredResult);
183
147
  }
184
148
  setItemCount(result.length);
185
149
  return result;
186
- }, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems, connectivityMode, formatMessage]);
150
+ }, [pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q6 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q6 === void 0 ? void 0 : _pluginInjectionApi$q6.actions, quickInsertDropdownItems, connectivityMode]);
187
151
  var emptyStateHandler = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q7 = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q7 === void 0 || (_pluginInjectionApi$q7 = _pluginInjectionApi$q7.sharedState.currentState()) === null || _pluginInjectionApi$q7 === void 0 ? void 0 : _pluginInjectionApi$q7.emptyStateHandler;
188
152
  var onViewMore = useCallback(function () {
189
153
  var _pluginInjectionApi$c, _pluginInjectionApi$q8;
@@ -1,16 +1,14 @@
1
1
  /* RegisteredInsertMenu.tsx generated by @compiled/babel-plugin v3.0.2 */
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- import _toArray from "@babel/runtime/helpers/toArray";
4
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
4
  import "./RegisteredInsertMenu.compiled.css";
6
5
  import { ax, ix } from "@compiled/react/runtime";
7
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
6
  import React, { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
9
7
  import { useIntl } from 'react-intl';
10
8
  import { getDocument } from '@atlaskit/browser-apis';
11
9
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
12
10
  import { MENU } from '@atlaskit/editor-common/quick-insert/keys';
13
- import { buildQuickInsertMenuModel, getMatchingQuickInsertComponents, selectQuickInsertCategoryItems } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
11
+ import { buildQuickInsertMenuModel, getMatchingQuickInsertComponents, getQuickInsertMenuRows, selectQuickInsertCategoryItems } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
14
12
  import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
15
13
  import { TYPE_AHEAD_SURFACE_CONTEXT } from '@atlaskit/editor-common/type-ahead-surface-context';
16
14
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
@@ -85,27 +83,18 @@ export var RegisteredInsertMenu = function RegisteredInsertMenu(_ref) {
85
83
  surfaceContext: surfaceContext
86
84
  });
87
85
  }, [components, formatMessage, hasSectionOverflowItems, query, surfaceContext]);
88
- var itemCount = useMemo(function () {
89
- var _model$fallbackItems$, _model$fallbackItems;
90
- return model.sections.reduce(function (count, _ref3) {
91
- var _ref4 = _toArray(_ref3),
92
- items = _arrayLikeToArray(_ref4).slice(1);
93
- return count + items.length;
94
- }, 0) + ((_model$fallbackItems$ = (_model$fallbackItems = model.fallbackItems) === null || _model$fallbackItems === void 0 ? void 0 : _model$fallbackItems.length) !== null && _model$fallbackItems$ !== void 0 ? _model$fallbackItems$ : 0) + (model.footer ? 1 : 0);
95
- }, [model.fallbackItems, model.footer, model.sections]);
86
+ var selectableItems = useMemo(function () {
87
+ return getQuickInsertMenuRows(model).filter(function (row) {
88
+ return row.type === 'menu-item';
89
+ });
90
+ }, [model]);
91
+ var itemCount = selectableItems.length + (model.footer ? 1 : 0);
96
92
  var selectableItemKeys = useMemo(function () {
97
- var _model$fallbackItems2;
98
- return [].concat(_toConsumableArray(model.sections.flatMap(function (_ref5) {
99
- var _ref6 = _toArray(_ref5),
100
- items = _arrayLikeToArray(_ref6).slice(1);
101
- return items;
102
- })), _toConsumableArray((_model$fallbackItems2 = model.fallbackItems) !== null && _model$fallbackItems2 !== void 0 ? _model$fallbackItems2 : []), [model.footer]).filter(function (item) {
103
- return Boolean(item);
104
- }).map(function (_ref7) {
105
- var key = _ref7.key;
93
+ return [].concat(_toConsumableArray(selectableItems), _toConsumableArray(model.footer ? [model.footer] : [])).map(function (_ref3) {
94
+ var key = _ref3.key;
106
95
  return key;
107
96
  }).join(',');
108
- }, [model.fallbackItems, model.footer, model.sections]);
97
+ }, [model.footer, selectableItems]);
109
98
  useLayoutEffect(function () {
110
99
  setSelectedItemIndex(itemCount > 0 ? 0 : -1);
111
100
  }, [itemCount, query, selectableItemKeys]);
@@ -1,7 +1,7 @@
1
1
  /* RegisteredInsertMenuList.tsx generated by @compiled/babel-plugin v3.0.2 */
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  import "./RegisteredInsertMenuList.compiled.css";
6
6
  import { ax, ix } from "@compiled/react/runtime";
7
7
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
@@ -10,6 +10,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
10
10
  import React, { useCallback, useLayoutEffect, useMemo, useRef } from 'react';
11
11
  import { CellMeasurer, CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
12
12
  import { List } from 'react-virtualized/dist/commonjs/List';
13
+ import { getQuickInsertMenuRows } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
13
14
  import { useMenuListHeight } from '@atlaskit/editor-common/quick-insert/use-menu-list-height';
14
15
  import { Box } from '@atlaskit/primitives/compiled';
15
16
  import { RegisteredInsertMenuItem } from './RegisteredInsertMenuItem';
@@ -49,9 +50,8 @@ export var RegisteredInsertMenuList = function RegisteredInsertMenuList(_ref) {
49
50
  listRef.current = list;
50
51
  }, []);
51
52
  var rows = useMemo(function () {
52
- var _model$fallbackItems;
53
- return [].concat(_toConsumableArray(model.sections.flat()), _toConsumableArray((_model$fallbackItems = model.fallbackItems) !== null && _model$fallbackItems !== void 0 ? _model$fallbackItems : []));
54
- }, [model.fallbackItems, model.sections]);
53
+ return getQuickInsertMenuRows(model);
54
+ }, [model]);
55
55
  var cache = useMemo(function () {
56
56
  return new CellMeasurerCache({
57
57
  defaultHeight: ESTIMATED_ROW_HEIGHT,
@@ -1,14 +1,10 @@
1
1
  import { jsx } from '@emotion/react';
2
- import type { MessageDescriptor } from 'react-intl';
3
2
  import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
4
3
  import type { InsertMenuProps } from './types';
5
4
  export declare const DEFAULT_HEIGHT = 560;
6
5
  /**
7
- * Exported helper to allow testing of InsertMenu pinning logic.
8
- *
9
- * The `cc_fd_db_top_editor_toolbar` experiment adds new logic to sort elements by `priority`.
10
- * This newer implementation matches how the quick insert menu sorts elements.
6
+ * Sort featured elements by priority, matching the quick insert menu.
11
7
  */
12
- export declare const sortFeaturedItems: (featuredItems: QuickInsertItem[], formatMessage: (msg: MessageDescriptor) => string) => QuickInsertItem[];
8
+ export declare const sortFeaturedItems: (featuredItems: QuickInsertItem[]) => QuickInsertItem[];
13
9
  declare const InsertMenu: ({ editorView, dropdownItems, showElementBrowserLink, onInsert, toggleVisiblity, pluginInjectionApi, }: InsertMenuProps) => jsx.JSX.Element;
14
10
  export default InsertMenu;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { QuickInsertMenuModel } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
2
+ import { type QuickInsertMenuModel } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
3
3
  import type { EmptyStateHandler } from '@atlaskit/editor-common/types';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import type { SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-insert-block",
3
- "version": "26.0.0",
3
+ "version": "26.0.2",
4
4
  "description": "Insert block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -62,7 +62,7 @@
62
62
  "@atlaskit/platform-feature-flags": "^2.2.0",
63
63
  "@atlaskit/primitives": "^22.5.0",
64
64
  "@atlaskit/textfield": "^10.2.0",
65
- "@atlaskit/tmp-editor-statsig": "^224.0.0",
65
+ "@atlaskit/tmp-editor-statsig": "^226.0.0",
66
66
  "@atlaskit/tokens": "^20.3.0",
67
67
  "@babel/runtime": "^7.0.0",
68
68
  "@emotion/react": "^11.7.1",
@@ -72,7 +72,7 @@
72
72
  "react-virtualized": "^9.22.6"
73
73
  },
74
74
  "peerDependencies": {
75
- "@atlaskit/editor-common": "^129.0.0",
75
+ "@atlaskit/editor-common": "^129.1.0",
76
76
  "react": "^18.2.0 || ^19.2.0",
77
77
  "react-dom": "^18.2.0 || ^19.2.0",
78
78
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"