@atlaskit/editor-plugin-quick-insert 29.0.3 → 30.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/quickInsertPlugin.js +10 -5
  3. package/dist/cjs/ui/QuickInsertRecommendedSlot.js +11 -8
  4. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowser.js +31 -7
  5. package/dist/cjs/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.js +13 -7
  6. package/dist/cjs/ui/RegistryElementBrowser/model.js +14 -15
  7. package/dist/cjs/ui/getQuickInsertComponents.js +28 -16
  8. package/dist/cjs/ui/getRecommendedComponents.js +2 -2
  9. package/dist/cjs/ui/registered-menu/QuickInsertEmptyState.compiled.css +11 -0
  10. package/dist/cjs/ui/registered-menu/QuickInsertEmptyState.js +61 -0
  11. package/dist/cjs/ui/registered-menu/QuickInsertMenuRoot.js +220 -0
  12. package/dist/cjs/ui/registered-menu/QuickInsertMenuSection.js +23 -0
  13. package/dist/cjs/ui/registered-menu/QuickInsertSearchResultsSection.js +19 -0
  14. package/dist/cjs/ui/registered-menu/RegisteredQuickInsertMenuItem.js +42 -0
  15. package/dist/cjs/ui/registered-menu/ToolbarQuickInsertMenu.compiled.css +11 -0
  16. package/dist/cjs/ui/registered-menu/ToolbarQuickInsertMenu.js +128 -0
  17. package/dist/cjs/ui/registered-menu/TypeAheadQuickInsertMenu.compiled.css +3 -0
  18. package/dist/cjs/ui/registered-menu/TypeAheadQuickInsertMenu.js +90 -0
  19. package/dist/cjs/ui/registered-menu/assets/no-results.js +36 -0
  20. package/dist/cjs/ui/registered-menu/get-quick-insert-menu-model.js +237 -0
  21. package/dist/cjs/ui/registered-menu/getQuickInsertMenuItemId.js +9 -0
  22. package/dist/cjs/ui/registered-menu/selectQuickInsertCategoryItems.js +27 -0
  23. package/dist/cjs/ui/registered-menu/useQuickInsertSearchAnalytics.js +100 -0
  24. package/dist/es2019/quickInsertPlugin.js +10 -5
  25. package/dist/es2019/ui/QuickInsertRecommendedSlot.js +10 -5
  26. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowser.js +19 -2
  27. package/dist/es2019/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.js +12 -7
  28. package/dist/es2019/ui/RegistryElementBrowser/model.js +12 -13
  29. package/dist/es2019/ui/getQuickInsertComponents.js +24 -10
  30. package/dist/es2019/ui/getRecommendedComponents.js +2 -2
  31. package/dist/es2019/ui/registered-menu/QuickInsertEmptyState.compiled.css +11 -0
  32. package/dist/es2019/ui/registered-menu/QuickInsertEmptyState.js +47 -0
  33. package/dist/es2019/ui/registered-menu/QuickInsertMenuRoot.js +191 -0
  34. package/dist/es2019/ui/registered-menu/QuickInsertMenuSection.js +15 -0
  35. package/dist/es2019/ui/registered-menu/QuickInsertSearchResultsSection.js +14 -0
  36. package/dist/es2019/ui/registered-menu/RegisteredQuickInsertMenuItem.js +34 -0
  37. package/dist/es2019/ui/registered-menu/ToolbarQuickInsertMenu.compiled.css +11 -0
  38. package/dist/es2019/ui/registered-menu/ToolbarQuickInsertMenu.js +116 -0
  39. package/dist/es2019/ui/registered-menu/TypeAheadQuickInsertMenu.compiled.css +3 -0
  40. package/dist/es2019/ui/registered-menu/TypeAheadQuickInsertMenu.js +78 -0
  41. package/dist/es2019/ui/registered-menu/assets/no-results.js +30 -0
  42. package/dist/es2019/ui/registered-menu/get-quick-insert-menu-model.js +177 -0
  43. package/dist/es2019/ui/registered-menu/getQuickInsertMenuItemId.js +1 -0
  44. package/dist/es2019/ui/registered-menu/selectQuickInsertCategoryItems.js +19 -0
  45. package/dist/es2019/ui/registered-menu/useQuickInsertSearchAnalytics.js +91 -0
  46. package/dist/esm/quickInsertPlugin.js +10 -5
  47. package/dist/esm/ui/QuickInsertRecommendedSlot.js +11 -8
  48. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowser.js +30 -6
  49. package/dist/esm/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.js +12 -7
  50. package/dist/esm/ui/RegistryElementBrowser/model.js +14 -15
  51. package/dist/esm/ui/getQuickInsertComponents.js +27 -15
  52. package/dist/esm/ui/getRecommendedComponents.js +2 -2
  53. package/dist/esm/ui/registered-menu/QuickInsertEmptyState.compiled.css +11 -0
  54. package/dist/esm/ui/registered-menu/QuickInsertEmptyState.js +50 -0
  55. package/dist/esm/ui/registered-menu/QuickInsertMenuRoot.js +211 -0
  56. package/dist/esm/ui/registered-menu/QuickInsertMenuSection.js +16 -0
  57. package/dist/esm/ui/registered-menu/QuickInsertSearchResultsSection.js +12 -0
  58. package/dist/esm/ui/registered-menu/RegisteredQuickInsertMenuItem.js +34 -0
  59. package/dist/esm/ui/registered-menu/ToolbarQuickInsertMenu.compiled.css +11 -0
  60. package/dist/esm/ui/registered-menu/ToolbarQuickInsertMenu.js +120 -0
  61. package/dist/esm/ui/registered-menu/TypeAheadQuickInsertMenu.compiled.css +3 -0
  62. package/dist/esm/ui/registered-menu/TypeAheadQuickInsertMenu.js +82 -0
  63. package/dist/esm/ui/registered-menu/assets/no-results.js +29 -0
  64. package/dist/esm/ui/registered-menu/get-quick-insert-menu-model.js +230 -0
  65. package/dist/esm/ui/registered-menu/getQuickInsertMenuItemId.js +3 -0
  66. package/dist/esm/ui/registered-menu/selectQuickInsertCategoryItems.js +21 -0
  67. package/dist/esm/ui/registered-menu/useQuickInsertSearchAnalytics.js +93 -0
  68. package/dist/types/quickInsertPluginType.d.ts +1 -1
  69. package/dist/types/ui/QuickInsertRecommendedSlot.d.ts +3 -3
  70. package/dist/types/ui/RegistryElementBrowser/RegistryElementBrowserSearchResults.d.ts +5 -2
  71. package/dist/types/ui/RegistryElementBrowser/model.d.ts +3 -2
  72. package/dist/types/ui/getQuickInsertComponents.d.ts +8 -2
  73. package/dist/types/ui/registered-menu/QuickInsertEmptyState.d.ts +7 -0
  74. package/dist/types/ui/registered-menu/QuickInsertMenuRoot.d.ts +11 -0
  75. package/dist/types/ui/registered-menu/QuickInsertMenuSection.d.ts +4 -0
  76. package/dist/types/ui/registered-menu/QuickInsertSearchResultsSection.d.ts +2 -0
  77. package/dist/types/ui/registered-menu/RegisteredQuickInsertMenuItem.d.ts +3 -0
  78. package/dist/types/ui/registered-menu/ToolbarQuickInsertMenu.d.ts +28 -0
  79. package/dist/types/ui/registered-menu/TypeAheadQuickInsertMenu.d.ts +27 -0
  80. package/dist/types/ui/registered-menu/assets/no-results.d.ts +7 -0
  81. package/dist/types/ui/registered-menu/get-quick-insert-menu-model.d.ts +19 -0
  82. package/dist/types/ui/registered-menu/getQuickInsertMenuItemId.d.ts +1 -0
  83. package/dist/types/ui/registered-menu/selectQuickInsertCategoryItems.d.ts +7 -0
  84. package/dist/types/ui/registered-menu/useQuickInsertSearchAnalytics.d.ts +12 -0
  85. package/package.json +14 -11
  86. package/registered-menu/model/package.json +10 -0
  87. package/registered-menu/search-analytics/package.json +10 -0
@@ -0,0 +1,230 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ 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; }
4
+ 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; }
5
+ 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; } } }; }
6
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
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
+ import { ASK_ROVO_MENU_ITEM, MENU, SEARCH_RESULTS_SECTION } from '@atlaskit/editor-common/quick-insert/keys';
9
+ import { applyRegisteredItemRanks } from '@atlaskit/editor-common/registered-menu/item-rank';
10
+ import { isMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-is-menu-footer-section-key';
11
+ import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
12
+ import { getComponentIdentity, resolveSurface, willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
13
+ import { QuickInsertSearchResultsSection } from './QuickInsertSearchResultsSection';
14
+ var SEARCH_TOP_MATCH_LIMIT = 5;
15
+ var SEARCH_RESULTS_HEADING = {
16
+ key: SEARCH_RESULTS_SECTION.key,
17
+ type: SEARCH_RESULTS_SECTION.type,
18
+ component: QuickInsertSearchResultsSection,
19
+ parents: [{
20
+ key: MENU.key,
21
+ type: MENU.type,
22
+ rank: 0
23
+ }]
24
+ };
25
+ var getParentRank = function getParentRank(component, parentKey) {
26
+ var _component$parents$fi, _component$parents;
27
+ return (_component$parents$fi = (_component$parents = component.parents) === null || _component$parents === void 0 || (_component$parents = _component$parents.find(function (parent) {
28
+ return parent.key === parentKey;
29
+ })) === null || _component$parents === void 0 ? void 0 : _component$parents.rank) !== null && _component$parents$fi !== void 0 ? _component$parents$fi : Number.MAX_SAFE_INTEGER;
30
+ };
31
+ var compareMatchedItems = function compareMatchedItems(a, b) {
32
+ return a.sectionRank - b.sectionRank || a.score - b.score || a.itemRank - b.itemRank || a.sourceIndex - b.sourceIndex || a.identity.localeCompare(b.identity);
33
+ };
34
+ var compareSearchResults = function compareSearchResults(a, b) {
35
+ return a.score - b.score || a.sectionRank - b.sectionRank || a.itemRank - b.itemRank || a.sourceIndex - b.sourceIndex || a.identity.localeCompare(b.identity);
36
+ };
37
+ var getSearchResults = function getSearchResults(matches) {
38
+ var topMatches = Array.from(matches).sort(compareSearchResults).slice(0, SEARCH_TOP_MATCH_LIMIT);
39
+ var topMatchIdentities = new Set(topMatches.map(function (_ref) {
40
+ var identity = _ref.identity;
41
+ return identity;
42
+ }));
43
+ var tailMatches = matches.filter(function (_ref2) {
44
+ var identity = _ref2.identity;
45
+ return !topMatchIdentities.has(identity);
46
+ });
47
+ return [].concat(_toConsumableArray(topMatches), _toConsumableArray(tailMatches)).map(function (_ref3) {
48
+ var item = _ref3.item;
49
+ return item;
50
+ });
51
+ };
52
+ var getRenderedMenuItems = function getRenderedMenuItems(section, childrenMap, surfaceContext) {
53
+ var _childrenMap$get;
54
+ return ((_childrenMap$get = childrenMap.get(getComponentIdentity(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : []).filter(function (child) {
55
+ return child.type === 'menu-item' && willComponentRender(child, childrenMap, surfaceContext);
56
+ });
57
+ };
58
+ var buildBrowseSections = function buildBrowseSections(_ref4) {
59
+ var childrenMap = _ref4.childrenMap,
60
+ contentSections = _ref4.contentSections,
61
+ selectCategoryItems = _ref4.selectCategoryItems,
62
+ surfaceContext = _ref4.surfaceContext;
63
+ var sections = [];
64
+ var _iterator = _createForOfIteratorHelper(contentSections),
65
+ _step;
66
+ try {
67
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
68
+ var section = _step.value;
69
+ var children = getRenderedMenuItems(section, childrenMap, surfaceContext);
70
+ var overflowItems = children.filter(function (child) {
71
+ return isSectionOverflowItemKey(child.key);
72
+ });
73
+ var viewMoreItem = overflowItems[overflowItems.length - 1];
74
+ var items = children.filter(function (child) {
75
+ return !isSectionOverflowItemKey(child.key);
76
+ });
77
+ if (items.length === 0) {
78
+ continue;
79
+ }
80
+ var selectedItems = viewMoreItem !== undefined && selectCategoryItems !== undefined ? selectCategoryItems(items) : items;
81
+ if (selectedItems.length < items.length && viewMoreItem !== undefined) {
82
+ sections.push([section].concat(_toConsumableArray(selectedItems), [viewMoreItem]));
83
+ } else {
84
+ sections.push([section].concat(_toConsumableArray(selectedItems)));
85
+ }
86
+ }
87
+ } catch (err) {
88
+ _iterator.e(err);
89
+ } finally {
90
+ _iterator.f();
91
+ }
92
+ return {
93
+ fallbackItems: [],
94
+ sections: sections
95
+ };
96
+ };
97
+ var buildSearchSections = function buildSearchSections(_ref5) {
98
+ var childrenMap = _ref5.childrenMap,
99
+ components = _ref5.components,
100
+ contentSections = _ref5.contentSections,
101
+ formatMessage = _ref5.formatMessage,
102
+ query = _ref5.query,
103
+ root = _ref5.root,
104
+ surfaceContext = _ref5.surfaceContext;
105
+ var matches = new Map();
106
+ var sourceIndexByComponent = new Map(components.map(function (component, index) {
107
+ return [component, index];
108
+ }));
109
+ var _iterator2 = _createForOfIteratorHelper(contentSections),
110
+ _step2;
111
+ try {
112
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
113
+ var section = _step2.value;
114
+ var _iterator3 = _createForOfIteratorHelper(getRenderedMenuItems(section, childrenMap, surfaceContext)),
115
+ _step3;
116
+ try {
117
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
118
+ var _item$match, _match$score, _sourceIndexByCompone;
119
+ var item = _step3.value;
120
+ if (isSectionOverflowItemKey(item.key)) {
121
+ continue;
122
+ }
123
+ var match = (_item$match = item.match) === null || _item$match === void 0 ? void 0 : _item$match.call(item, {
124
+ formatMessage: formatMessage,
125
+ query: query
126
+ });
127
+ if (item.match && match === null) {
128
+ continue;
129
+ }
130
+ var candidate = {
131
+ identity: "".concat(item.type, ":").concat(item.key),
132
+ item: item,
133
+ itemRank: getParentRank(item, section.key),
134
+ score: Math.min(1, Math.max(0, (_match$score = match === null || match === void 0 ? void 0 : match.score) !== null && _match$score !== void 0 ? _match$score : 0)),
135
+ sourceIndex: (_sourceIndexByCompone = sourceIndexByComponent.get(item)) !== null && _sourceIndexByCompone !== void 0 ? _sourceIndexByCompone : Number.MAX_SAFE_INTEGER,
136
+ sectionRank: getParentRank(section, root.key)
137
+ };
138
+ var existing = matches.get(candidate.identity);
139
+ if (!existing || compareMatchedItems(candidate, existing) < 0) {
140
+ matches.set(candidate.identity, candidate);
141
+ }
142
+ }
143
+ } catch (err) {
144
+ _iterator3.e(err);
145
+ } finally {
146
+ _iterator3.f();
147
+ }
148
+ }
149
+ } catch (err) {
150
+ _iterator2.e(err);
151
+ } finally {
152
+ _iterator2.f();
153
+ }
154
+ var uniqueMatches = Array.from(matches.values()).sort(compareMatchedItems);
155
+ var searchResults = getSearchResults(uniqueMatches);
156
+ if (searchResults.length > 0) {
157
+ return {
158
+ fallbackItems: [],
159
+ sections: [[SEARCH_RESULTS_HEADING].concat(_toConsumableArray(searchResults))]
160
+ };
161
+ }
162
+ var fallbackItem = contentSections.flatMap(function (section) {
163
+ var _childrenMap$get2;
164
+ return (_childrenMap$get2 = childrenMap.get(getComponentIdentity(section))) !== null && _childrenMap$get2 !== void 0 ? _childrenMap$get2 : [];
165
+ }).find(function (component) {
166
+ return component.type === ASK_ROVO_MENU_ITEM.type && component.key === ASK_ROVO_MENU_ITEM.key && willComponentRender(component, childrenMap, surfaceContext);
167
+ });
168
+ return {
169
+ fallbackItems: fallbackItem ? [fallbackItem] : [],
170
+ sections: []
171
+ };
172
+ };
173
+
174
+ /**
175
+ * Builds the registered quick-insert menu model. An empty query browses every
176
+ * category; a non-empty query returns ranked matches. The footer is shared by both.
177
+ */
178
+ export var getQuickInsertMenuModel = function getQuickInsertMenuModel(_ref6) {
179
+ var components = _ref6.components,
180
+ formatMessage = _ref6.formatMessage,
181
+ getItemRank = _ref6.getItemRank,
182
+ query = _ref6.query,
183
+ rootComponent = _ref6.rootComponent,
184
+ selectCategoryItems = _ref6.selectCategoryItems,
185
+ surfaceContext = _ref6.surfaceContext;
186
+ var rankedComponents = applyRegisteredItemRanks(components, getItemRank);
187
+ var _resolveSurface = resolveSurface(rankedComponents, rootComponent),
188
+ childrenMap = _resolveSurface.childrenMap,
189
+ root = _resolveSurface.root,
190
+ _resolveSurface$topLe = _resolveSurface.topLevelChildren,
191
+ topLevelChildren = _resolveSurface$topLe === void 0 ? [] : _resolveSurface$topLe;
192
+ if (!root || !willComponentRender(root, childrenMap, surfaceContext)) {
193
+ return {
194
+ fallbackItems: [],
195
+ footer: undefined,
196
+ root: undefined,
197
+ sections: []
198
+ };
199
+ }
200
+ var renderedSections = topLevelChildren.filter(function (section) {
201
+ return section.type === 'menu-section' && willComponentRender(section, childrenMap, surfaceContext);
202
+ });
203
+ var footerSection = renderedSections.find(function (_ref7) {
204
+ var key = _ref7.key;
205
+ return isMenuFooterSectionKey(key);
206
+ });
207
+ var contentSections = renderedSections.filter(function (_ref8) {
208
+ var key = _ref8.key;
209
+ return !isMenuFooterSectionKey(key);
210
+ });
211
+ var content = query === '' ? buildBrowseSections({
212
+ childrenMap: childrenMap,
213
+ contentSections: contentSections,
214
+ selectCategoryItems: selectCategoryItems,
215
+ surfaceContext: surfaceContext
216
+ }) : buildSearchSections({
217
+ childrenMap: childrenMap,
218
+ components: rankedComponents,
219
+ contentSections: contentSections,
220
+ formatMessage: formatMessage,
221
+ query: query,
222
+ root: root,
223
+ surfaceContext: surfaceContext
224
+ });
225
+ var footer = footerSection ? getRenderedMenuItems(footerSection, childrenMap, surfaceContext)[0] : undefined;
226
+ return _objectSpread(_objectSpread({}, content), {}, {
227
+ footer: footer,
228
+ root: root
229
+ });
230
+ };
@@ -0,0 +1,3 @@
1
+ export var getQuickInsertMenuItemId = function getQuickInsertMenuItemId(listId, itemIndex) {
2
+ return "".concat(listId, "-").concat(itemIndex);
3
+ };
@@ -0,0 +1,21 @@
1
+ import { quickInsertProviderMenuItemKey } from '@atlaskit/editor-common/quick-insert/get-provider-menu-item-key';
2
+ var DEFAULT_ITEM_LIMIT = 30;
3
+ var ECOSYSTEM_ITEM_LIMIT = 10;
4
+ var isEcosystemQuickInsertItem = function isEcosystemQuickInsertItem(item) {
5
+ return quickInsertProviderMenuItemKey.isEcosystem(item.key);
6
+ };
7
+
8
+ /**
9
+ * Keeps the initial native and ecosystem results while ensuring ecosystem registrations
10
+ * remain discoverable beyond the default category item limit.
11
+ */
12
+ export var selectQuickInsertCategoryItems = function selectQuickInsertCategoryItems(items) {
13
+ var ecosystemItemCount = 0;
14
+ return items.filter(function (item, index) {
15
+ var isEcosystemItem = isEcosystemQuickInsertItem(item);
16
+ if (isEcosystemItem) {
17
+ ecosystemItemCount++;
18
+ }
19
+ return index < DEFAULT_ITEM_LIMIT || isEcosystemItem && ecosystemItemCount <= ECOSYSTEM_ITEM_LIMIT;
20
+ });
21
+ };
@@ -0,0 +1,93 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
4
+ import { useCallback, useEffect, useRef } from 'react';
5
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics/types/enums';
6
+ var SEARCH_DEBOUNCE_MS = 1000;
7
+ export var useQuickInsertSearchAnalytics = function useQuickInsertSearchAnalytics(_ref) {
8
+ var query = _ref.query,
9
+ resultCount = _ref.resultCount,
10
+ surface = _ref.surface,
11
+ category = _ref.category,
12
+ _ref$isOpen = _ref.isOpen,
13
+ isOpen = _ref$isOpen === void 0 ? true : _ref$isOpen,
14
+ fireAnalyticsEvent = _ref.fireAnalyticsEvent;
15
+ var latestOptions = useRef({
16
+ query: query,
17
+ resultCount: resultCount,
18
+ surface: surface,
19
+ category: category,
20
+ fireAnalyticsEvent: fireAnalyticsEvent
21
+ });
22
+ latestOptions.current = {
23
+ query: query,
24
+ resultCount: resultCount,
25
+ surface: surface,
26
+ category: category,
27
+ fireAnalyticsEvent: fireAnalyticsEvent
28
+ };
29
+ var pendingSearch = useRef(null);
30
+ var effectVersion = useRef(0);
31
+ var flush = useCallback(function () {
32
+ var pending = pendingSearch.current;
33
+ if (!pending) {
34
+ return;
35
+ }
36
+ clearTimeout(pending.timer);
37
+ pendingSearch.current = null;
38
+ var current = latestOptions.current;
39
+ if (current.query.trim() !== pending.query || !current.fireAnalyticsEvent) {
40
+ return;
41
+ }
42
+ var attributes = _objectSpread(_objectSpread({}, current.surface === 'element-browser' && current.category !== undefined ? {
43
+ category: current.category
44
+ } : {}), {}, {
45
+ isEmpty: current.resultCount === 0,
46
+ queryLength: current.query.trim().length,
47
+ resultCount: current.resultCount,
48
+ surface: current.surface
49
+ });
50
+ var payload = {
51
+ action: ACTION.SEARCHED,
52
+ actionSubject: ACTION_SUBJECT.QUICK_INSERT,
53
+ eventType: EVENT_TYPE.TRACK,
54
+ attributes: attributes
55
+ };
56
+ current.fireAnalyticsEvent(payload);
57
+ }, []);
58
+ useEffect(function () {
59
+ var currentVersion = ++effectVersion.current;
60
+ if (!isOpen) {
61
+ flush();
62
+ return;
63
+ }
64
+ var trimmedQuery = query.trim();
65
+ if (!trimmedQuery) {
66
+ if (pendingSearch.current) {
67
+ clearTimeout(pendingSearch.current.timer);
68
+ pendingSearch.current = null;
69
+ }
70
+ return;
71
+ }
72
+ if (pendingSearch.current) {
73
+ clearTimeout(pendingSearch.current.timer);
74
+ }
75
+ var timer = setTimeout(flush, SEARCH_DEBOUNCE_MS);
76
+ pendingSearch.current = {
77
+ query: trimmedQuery,
78
+ timer: timer
79
+ };
80
+ return function () {
81
+ if (pendingSearch.current) {
82
+ clearTimeout(pendingSearch.current.timer);
83
+ }
84
+ Promise.resolve().then(function () {
85
+ // oxlint-disable-next-line react-hooks/exhaustive-deps -- The live effect version distinguishes dependency cleanup from a real unmount.
86
+ if (effectVersion.current === currentVersion) {
87
+ flush();
88
+ }
89
+ });
90
+ };
91
+ }, [query, surface, category, isOpen, flush]);
92
+ return flush;
93
+ };
@@ -1,7 +1,7 @@
1
1
  import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics/types/enums';
2
2
  import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory/quick-insert-provider';
3
3
  import type { IsRecommendedItem } from '@atlaskit/editor-common/quick-insert/is-recommended-item';
4
- import type { RegisteredItemRankResolver } from '@atlaskit/editor-common/type-ahead/item-rank';
4
+ import type { RegisteredItemRankResolver } from '@atlaskit/editor-common/registered-menu/item-rank';
5
5
  import type { Command } from '@atlaskit/editor-common/types/command';
6
6
  import type { EditorCommand } from '@atlaskit/editor-common/types/editor-command';
7
7
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types/next-editor-plugin';
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
- import type { RegisterMenuItem, SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
3
- type Props = Record<string, unknown> & {
2
+ import type { CommonComponentProps, RegisterMenuItem, SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
3
+ type Props = CommonComponentProps & {
4
4
  getSnapshot: (surfaceContext?: SurfaceContext) => RegisterMenuItem[];
5
5
  index: number;
6
6
  };
7
- export declare const QuickInsertRecommendedSlot: ({ index, getSnapshot, ...props }: Props) => React.ReactNode;
7
+ export declare const QuickInsertRecommendedSlot: ({ children, parents, surfaceContext, index, getSnapshot, }: Props) => React.ReactNode;
8
8
  export {};
@@ -6,6 +6,7 @@ import React from 'react';
6
6
  import type { QuickInsertSelectionHandler } from '@atlaskit/editor-common/quick-insert/context';
7
7
  import type { EmptyStateHandler } from '@atlaskit/editor-common/types/empty-state-handler';
8
8
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
+ import type { SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
9
10
  import type { RegistryElementBrowserItem } from './model';
10
11
  type Props = {
11
12
  editorView: EditorView;
@@ -20,13 +21,15 @@ type Props = {
20
21
  resultsId: string;
21
22
  section?: string;
22
23
  selectedKey?: string;
24
+ surfaceContext: SurfaceContext;
23
25
  };
24
- declare const RegistryElementBrowserItem: ({ editorView, isOffline, isSelected, item, onSelect, }: {
26
+ declare const RegistryElementBrowserItem: ({ editorView, isOffline, isSelected, item, onSelect, surfaceContext, }: {
25
27
  editorView: EditorView;
26
28
  isOffline: boolean;
27
29
  isSelected: boolean;
28
30
  item: RegistryElementBrowserItem;
29
31
  onSelect: (key: string, handler: QuickInsertSelectionHandler) => void;
32
+ surfaceContext: SurfaceContext;
30
33
  }) => React.JSX.Element | null;
31
- export declare const RegistryElementBrowserSearchResults: ({ editorView, emptyStateHandler, fallbackItems, isLoading, isOffline, items, query, resultsId, section, selectedKey, onKeyDown, onSelect, }: Props) => React.JSX.Element;
34
+ export declare const RegistryElementBrowserSearchResults: ({ editorView, emptyStateHandler, fallbackItems, isLoading, isOffline, items, query, resultsId, section, selectedKey, surfaceContext, onKeyDown, onSelect, }: Props) => React.JSX.Element;
32
35
  export {};
@@ -1,4 +1,4 @@
1
- import type { MenuItemMatchContext, RegisterComponent, RegisterMenuItem } from '@atlaskit/editor-ui-control-model/types';
1
+ import type { MenuItemMatchContext, RegisterComponent, RegisterMenuItem, SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
2
2
  export type RegistryElementBrowserSection = {
3
3
  key: string;
4
4
  rank: number;
@@ -18,11 +18,12 @@ export type RegistryElementBrowserModel = {
18
18
  * Builds the Element Browser's view of the resolved Quick Insert registry.
19
19
  * The caller provides only components rooted at the Quick Insert menu surface.
20
20
  */
21
- export declare const createRegistryElementBrowserModel: (components: RegisterComponent[], { footerKey, overflowKeys, recommendedSectionKey, rootKey, }: {
21
+ export declare const createRegistryElementBrowserModel: (components: RegisterComponent[], { footerKey, overflowKeys, recommendedSectionKey, rootKey, surfaceContext, }: {
22
22
  footerKey: string;
23
23
  overflowKeys: Set<string>;
24
24
  recommendedSectionKey: string;
25
25
  rootKey: string;
26
+ surfaceContext?: SurfaceContext;
26
27
  }) => RegistryElementBrowserModel;
27
28
  export declare const getInitialRegistryElementBrowserSection: (model: RegistryElementBrowserModel, requestedSection?: string) => string | undefined;
28
29
  export declare const getRegistryElementBrowserItems: ({ formatMessage, model, query, section, }: {
@@ -1,12 +1,18 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics/api';
1
2
  import type { IsRecommendedItem } from '@atlaskit/editor-common/quick-insert/is-recommended-item';
3
+ import type { RegisteredItemRankResolver } from '@atlaskit/editor-common/registered-menu/item-rank';
4
+ import type { EmptyStateHandler } from '@atlaskit/editor-common/types/empty-state-handler';
2
5
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types/next-editor-plugin';
3
- import type { CommonComponentProps, RegisterComponent } from '@atlaskit/editor-ui-control-model/types';
6
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model/types';
4
7
  import type { QuickInsertPlugin } from '../quickInsertPluginType';
5
8
  type Params = {
6
9
  api: ExtractInjectionAPI<QuickInsertPlugin> | undefined;
10
+ emptyStateHandler?: EmptyStateHandler;
11
+ fireAnalyticsEvent?: EditorAnalyticsAPI['fireAnalyticsEvent'];
12
+ getItemRank?: RegisteredItemRankResolver;
7
13
  includeElementBrowserItems: boolean;
8
14
  isRecommendedItem?: IsRecommendedItem;
9
15
  maxRecommendedItems?: number;
10
16
  };
11
- export declare const getQuickInsertComponents: <TProps extends CommonComponentProps = CommonComponentProps>({ api, includeElementBrowserItems, isRecommendedItem, maxRecommendedItems, }: Params) => RegisterComponent<TProps>[];
17
+ export declare const getQuickInsertComponents: ({ api, includeElementBrowserItems, isRecommendedItem, maxRecommendedItems, getItemRank, emptyStateHandler, fireAnalyticsEvent, }: Params) => RegisterComponent[];
12
18
  export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ type Props = {
3
+ mode: 'inline' | 'full';
4
+ spacing?: 'compact' | 'spacious';
5
+ };
6
+ export declare const QuickInsertEmptyState: ({ mode, spacing, }: Props) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics/api';
3
+ import type { RegisteredItemRankResolver } from '@atlaskit/editor-common/registered-menu/item-rank';
4
+ import type { EmptyStateHandler } from '@atlaskit/editor-common/types/empty-state-handler';
5
+ type Props = {
6
+ emptyStateHandler?: EmptyStateHandler;
7
+ fireAnalyticsEvent?: EditorAnalyticsAPI['fireAnalyticsEvent'];
8
+ getItemRank?: RegisteredItemRankResolver;
9
+ };
10
+ declare const QuickInsertMenuRoot: ({ emptyStateHandler, fireAnalyticsEvent, getItemRank, }: React.PropsWithChildren<Props>) => React.JSX.Element | null;
11
+ export default QuickInsertMenuRoot;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const QuickInsertMenuSection: ({ children, title, }: React.PropsWithChildren<{
3
+ title: string;
4
+ }>) => React.JSX.Element;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const QuickInsertSearchResultsSection: ({ children, }: React.PropsWithChildren) => React.JSX.Element;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { RegisteredMenuItemProps } from '@atlaskit/editor-common/registered-menu';
3
+ export declare const RegisteredQuickInsertMenuItem: ({ id, isSelected, isActive, registration, }: RegisteredMenuItemProps) => React.JSX.Element;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import type { RegisteredMenuModel, RegisteredMenuItemProps } from '@atlaskit/editor-common/registered-menu';
3
+ import type { EmptyStateHandler } from '@atlaskit/editor-common/types/empty-state-handler';
4
+ import type { RegisterMenuItem, RegisterMenuSection } from '@atlaskit/editor-ui-control-model/types';
5
+ type Props = {
6
+ activePreviewItemKey?: string;
7
+ emptyStateHandler?: EmptyStateHandler;
8
+ Item: React.ComponentType<RegisteredMenuItemProps>;
9
+ itemCount: number;
10
+ listId: string;
11
+ listLabel: string;
12
+ maxHeight: number;
13
+ model: RegisteredMenuModel;
14
+ onItemBlur: (key: string) => void;
15
+ onItemFocus: (index: number, key?: string) => void;
16
+ onItemHover: (index: number, key?: string) => void;
17
+ onItemLeave: (key: string) => void;
18
+ onItemVisibilityChange: (key: string, isVisible: boolean) => void;
19
+ onRenderedItemsChange: (range: {
20
+ startIndex: number;
21
+ stopIndex: number;
22
+ }) => void;
23
+ query: string;
24
+ rows: Array<RegisterMenuItem | RegisterMenuSection>;
25
+ selectedItemIndex: number;
26
+ };
27
+ export declare const ToolbarQuickInsertMenu: ({ Item, model, emptyStateHandler, listLabel, activePreviewItemKey, itemCount, listId, maxHeight, rows, onItemBlur, onItemFocus, onItemHover, onItemLeave, onItemVisibilityChange, onRenderedItemsChange, query, selectedItemIndex, }: Props) => React.JSX.Element | null;
28
+ export {};
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import type { RegisteredMenuItemProps, RegisteredMenuModel } from '@atlaskit/editor-common/registered-menu';
3
+ import type { RegisterMenuItem, RegisterMenuSection } from '@atlaskit/editor-ui-control-model/types';
4
+ type Props = {
5
+ activeItemKey?: string;
6
+ hasScrollPadding?: boolean;
7
+ Item: React.ComponentType<RegisteredMenuItemProps>;
8
+ itemCount: number;
9
+ listId: string;
10
+ listLabel: string;
11
+ maxHeight: number;
12
+ model: RegisteredMenuModel;
13
+ onItemBlur: (itemKey: string) => void;
14
+ onItemFocus: (itemIndex: number, itemKey?: string) => void;
15
+ onItemHover: (itemIndex: number, itemKey?: string) => void;
16
+ onItemLeave: (itemKey: string) => void;
17
+ onItemVisibilityChange: (itemKey: string, isVisible: boolean) => void;
18
+ onRenderedItemsChange: (range: {
19
+ startIndex: number;
20
+ stopIndex: number;
21
+ }) => void;
22
+ query?: string;
23
+ rows: Array<RegisterMenuItem | RegisterMenuSection>;
24
+ selectedItemIndex: number;
25
+ };
26
+ export declare const TypeAheadQuickInsertMenu: ({ Item, rows, activeItemKey, itemCount, listId, listLabel, maxHeight, model, onItemFocus, onItemBlur, onItemHover, onItemLeave, onItemVisibilityChange, onRenderedItemsChange, query, selectedItemIndex, hasScrollPadding, }: Props) => React.JSX.Element | null;
27
+ export {};
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ type Props = {
3
+ height: number;
4
+ width: number;
5
+ };
6
+ export default function NoResultsIllustration({ height, width }: Props): React.JSX.Element;
7
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { IntlShape } from 'react-intl';
2
+ import type { RegisteredMenuModel } from '@atlaskit/editor-common/registered-menu';
3
+ import { type RegisteredItemRankResolver } from '@atlaskit/editor-common/registered-menu/item-rank';
4
+ import type { SurfaceIdentifier } from '@atlaskit/editor-ui-control-model/surface-renderer/types';
5
+ import type { RegisterComponent, SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
6
+ import type { QuickInsertCategoryItemSelectionPolicy } from './selectQuickInsertCategoryItems';
7
+ /**
8
+ * Builds the registered quick-insert menu model. An empty query browses every
9
+ * category; a non-empty query returns ranked matches. The footer is shared by both.
10
+ */
11
+ export declare const getQuickInsertMenuModel: ({ components, formatMessage, getItemRank, query, rootComponent, selectCategoryItems, surfaceContext, }: {
12
+ components: RegisterComponent[];
13
+ formatMessage: IntlShape['formatMessage'];
14
+ getItemRank?: RegisteredItemRankResolver;
15
+ query: string;
16
+ rootComponent: SurfaceIdentifier;
17
+ selectCategoryItems?: QuickInsertCategoryItemSelectionPolicy;
18
+ surfaceContext?: SurfaceContext;
19
+ }) => RegisteredMenuModel;
@@ -0,0 +1 @@
1
+ export declare const getQuickInsertMenuItemId: (listId: string, itemIndex: number) => string;
@@ -0,0 +1,7 @@
1
+ import type { RegisterMenuItem } from '@atlaskit/editor-ui-control-model/types';
2
+ export type QuickInsertCategoryItemSelectionPolicy = (items: RegisterMenuItem[]) => RegisterMenuItem[];
3
+ /**
4
+ * Keeps the initial native and ecosystem results while ensuring ecosystem registrations
5
+ * remain discoverable beyond the default category item limit.
6
+ */
7
+ export declare const selectQuickInsertCategoryItems: QuickInsertCategoryItemSelectionPolicy;
@@ -0,0 +1,12 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics/api';
2
+ import type { QuickInsertSearchSurface } from '@atlaskit/editor-common/analytics/types/quick-insert-events';
3
+ type Options = {
4
+ category?: string;
5
+ fireAnalyticsEvent?: EditorAnalyticsAPI['fireAnalyticsEvent'];
6
+ isOpen?: boolean;
7
+ query: string;
8
+ resultCount: number;
9
+ surface: QuickInsertSearchSurface;
10
+ };
11
+ export declare const useQuickInsertSearchAnalytics: ({ query, resultCount, surface, category, isOpen, fireAnalyticsEvent, }: Options) => (() => void);
12
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-quick-insert",
3
- "version": "29.0.3",
3
+ "version": "30.0.0",
4
4
  "description": "Quick insert plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,31 +29,34 @@
29
29
  "@atlaskit/button": "^25.6.0",
30
30
  "@atlaskit/css": "^1.1.0",
31
31
  "@atlaskit/docs": "^12.3.0",
32
- "@atlaskit/editor-plugin-analytics": "^29.0.0",
33
- "@atlaskit/editor-plugin-connectivity": "^29.0.0",
34
- "@atlaskit/editor-plugin-editor-viewmode": "^31.0.0",
35
- "@atlaskit/editor-plugin-metrics": "^30.0.0",
36
- "@atlaskit/editor-plugin-type-ahead": "^30.0.0",
37
- "@atlaskit/editor-plugin-ui-control-registry": "^23.0.0",
32
+ "@atlaskit/editor-plugin-analytics": "^30.0.0",
33
+ "@atlaskit/editor-plugin-connectivity": "^30.0.0",
34
+ "@atlaskit/editor-plugin-editor-viewmode": "^32.0.0",
35
+ "@atlaskit/editor-plugin-metrics": "^31.0.0",
36
+ "@atlaskit/editor-plugin-type-ahead": "^31.0.0",
37
+ "@atlaskit/editor-plugin-ui-control-registry": "^24.0.0",
38
38
  "@atlaskit/editor-prosemirror": "^9.0.0",
39
+ "@atlaskit/editor-shared-styles": "^4.6.0",
39
40
  "@atlaskit/editor-tables": "^3.2.0",
40
41
  "@atlaskit/editor-ui-control-model": "^2.10.0",
41
42
  "@atlaskit/heading": "^8.0.0",
42
43
  "@atlaskit/icon": "^38.0.0",
44
+ "@atlaskit/menu": "^11.0.0",
43
45
  "@atlaskit/modal-dialog": "^17.1.0",
44
46
  "@atlaskit/platform-feature-experiments": "^0.3.0",
45
47
  "@atlaskit/platform-feature-flags": "^2.2.0",
46
48
  "@atlaskit/primitives": "^22.6.0",
47
49
  "@atlaskit/textfield": "^10.2.0",
48
- "@atlaskit/tmp-editor-statsig": "^245.0.0",
49
- "@atlaskit/tokens": "^20.7.0",
50
+ "@atlaskit/tmp-editor-statsig": "^246.1.0",
51
+ "@atlaskit/tokens": "^20.8.0",
50
52
  "@atlaskit/tooltip": "^24.4.0",
51
53
  "@babel/runtime": "^7.0.0",
52
54
  "@compiled/react": "^1.0.2",
53
- "@emotion/react": "^11.7.1"
55
+ "@emotion/react": "^11.7.1",
56
+ "react-loosely-lazy": "^1.0.0"
54
57
  },
55
58
  "peerDependencies": {
56
- "@atlaskit/editor-common": "^133.5.0",
59
+ "@atlaskit/editor-common": "^134.0.0",
57
60
  "react": "^18.2.0 || ^19.2.0",
58
61
  "react-dom": "^18.2.0 || ^19.2.0",
59
62
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"