@atlaskit/editor-plugin-quick-insert 14.0.4 → 14.1.1

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,38 @@
1
1
  # @atlaskit/editor-plugin-quick-insert
2
2
 
3
+ ## 14.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`3a4c286fdb8c1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3a4c286fdb8c1) -
8
+ Add registry-backed Quick Insert search matching under the existing
9
+ `platform_editor_slash_command` experiment. Make native, provider, and extension registered Quick
10
+ Insert items searchable.
11
+ - Updated dependencies
12
+
13
+ ## 14.1.0
14
+
15
+ ### Minor Changes
16
+
17
+ - [`c0cf420333ef1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c0cf420333ef1) -
18
+ Add public registration APIs for provider-backed Quick Insert components.
19
+
20
+ Providers can expose registered items directly:
21
+
22
+ ```tsx
23
+ const getComponents = async () => [
24
+ {
25
+ key: 'insert-table',
26
+ component: TableItem,
27
+ parents: [{ type: 'menu-section', key: 'quick-insert', rank: 1 }],
28
+ },
29
+ ];
30
+ ```
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies
35
+
3
36
  ## 14.0.4
4
37
 
5
38
  ### Patch Changes
@@ -24,6 +24,7 @@ var _appCategoryAnalytics = require("./app-category-analytics");
24
24
  var _commands = require("./pm-plugins/commands");
25
25
  var _quickInsertOpenExperience = require("./pm-plugins/experiences/quick-insert-open-experience");
26
26
  var _pluginKey = require("./pm-plugins/plugin-key");
27
+ var _getLegacyCompatibleComponents = require("./ui/getLegacyCompatibleComponents");
27
28
  var _getQuickInsertComponents = require("./ui/getQuickInsertComponents");
28
29
  var _ModalElementBrowser = _interopRequireDefault(require("./ui/ModalElementBrowser"));
29
30
  var _search = require("./ui/search");
@@ -130,7 +131,7 @@ var quickInsertPlugin = exports.quickInsertPlugin = function quickInsertPlugin(_
130
131
  getIntl = _ref6.getIntl,
131
132
  dispatch = _ref6.dispatch,
132
133
  dispatchAnalyticsEvent = _ref6.dispatchAnalyticsEvent;
133
- return quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, options === null || options === void 0 ? void 0 : options.emptyStateHandler);
134
+ return quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, options === null || options === void 0 ? void 0 : options.emptyStateHandler, onInsert, options === null || options === void 0 ? void 0 : options.itemFilter, api);
134
135
  }
135
136
  }, {
136
137
  name: 'quickInsertOpenExperience',
@@ -320,6 +321,9 @@ var setProviderState = function setProviderState(providerState) {
320
321
  };
321
322
  };
322
323
  function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, emptyStateHandler) {
324
+ var onInsert = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function () {};
325
+ var itemFilter = arguments.length > 7 ? arguments[7] : undefined;
326
+ var api = arguments.length > 8 ? arguments[8] : undefined;
323
327
  return new _safePlugin.SafePlugin({
324
328
  key: _pluginKey.pluginKey,
325
329
  state: {
@@ -357,12 +361,12 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
357
361
  var isDestroyed = false;
358
362
  var providerHandler = /*#__PURE__*/function () {
359
363
  var _ref14 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_name, providerPromise) {
360
- var provider, providedItems, _t;
364
+ var provider, providedItems, _api$uiControlRegistr2, directComponents, components, _t, _t2;
361
365
  return _regenerator.default.wrap(function (_context) {
362
366
  while (1) switch (_context.prev = _context.next) {
363
367
  case 0:
364
368
  if (!providerPromise) {
365
- _context.next = 5;
369
+ _context.next = 9;
366
370
  break;
367
371
  }
368
372
  _context.prev = 1;
@@ -374,6 +378,32 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
374
378
  return provider.getItems();
375
379
  case 3:
376
380
  providedItems = _context.sent;
381
+ if (!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_slash_command')) {
382
+ _context.next = 7;
383
+ break;
384
+ }
385
+ if (!provider.getComponents) {
386
+ _context.next = 5;
387
+ break;
388
+ }
389
+ _context.next = 4;
390
+ return provider.getComponents();
391
+ case 4:
392
+ _t = _context.sent;
393
+ _context.next = 6;
394
+ break;
395
+ case 5:
396
+ _t = [];
397
+ case 6:
398
+ directComponents = _t;
399
+ components = (0, _getLegacyCompatibleComponents.getLegacyCompatibleComponents)({
400
+ directComponents: directComponents,
401
+ itemFilter: itemFilter,
402
+ onInsert: onInsert,
403
+ providedItems: providedItems
404
+ });
405
+ api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 || _api$uiControlRegistr2.actions.register(components);
406
+ case 7:
377
407
  setProviderState({
378
408
  provider: provider,
379
409
  providedItems: providedItems
@@ -382,18 +412,18 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
382
412
  quickInsertItemsAnalyticsScheduler = (0, _appCategoryAnalytics.createQuickInsertItemsAnalyticsScheduler)(dispatchAnalyticsEvent);
383
413
  quickInsertItemsAnalyticsScheduler.schedule(providedItems);
384
414
  }
385
- _context.next = 5;
415
+ _context.next = 9;
386
416
  break;
387
- case 4:
388
- _context.prev = 4;
389
- _t = _context["catch"](1);
417
+ case 8:
418
+ _context.prev = 8;
419
+ _t2 = _context["catch"](1);
390
420
  // eslint-disable-next-line no-console
391
- console.error('Error getting items from quick insert provider', _t);
392
- case 5:
421
+ console.error('Error getting items from quick insert provider', _t2);
422
+ case 9:
393
423
  case "end":
394
424
  return _context.stop();
395
425
  }
396
- }, _callee, null, [[1, 4]]);
426
+ }, _callee, null, [[1, 8]]);
397
427
  }));
398
428
  return function providerHandler(_x, _x2) {
399
429
  return _ref14.apply(this, arguments);
@@ -9,8 +9,8 @@ exports.default = void 0;
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _react = _interopRequireWildcard(require("react"));
11
11
  var _analytics = require("@atlaskit/editor-common/analytics");
12
+ var _isOfflineMode = require("@atlaskit/editor-common/connectivity/isOfflineMode");
12
13
  var _hooks = require("@atlaskit/editor-common/hooks");
13
- var _editorPluginConnectivity = require("@atlaskit/editor-plugin-connectivity");
14
14
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
15
15
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
16
  var _commands = require("../../pm-plugins/commands");
@@ -126,7 +126,7 @@ var _default = exports.default = function _default(_ref2) {
126
126
  },
127
127
  editorView: editorView,
128
128
  helpUrl: helpUrl,
129
- isOffline: (0, _editorPluginConnectivity.isOfflineMode)(mode),
129
+ isOffline: (0, _isOfflineMode.isOfflineMode)(mode),
130
130
  insertItem: pluginInjectionAPI === null || pluginInjectionAPI === void 0 || (_pluginInjectionAPI$q = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q === void 0 || (_pluginInjectionAPI$q = _pluginInjectionAPI$q.actions) === null || _pluginInjectionAPI$q === void 0 ? void 0 : _pluginInjectionAPI$q.insertItem,
131
131
  getSuggestions: pluginInjectionAPI === null || pluginInjectionAPI === void 0 || (_pluginInjectionAPI$q2 = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q2 === void 0 || (_pluginInjectionAPI$q2 = _pluginInjectionAPI$q2.actions) === null || _pluginInjectionAPI$q2 === void 0 ? void 0 : _pluginInjectionAPI$q2.getSuggestions,
132
132
  api: pluginInjectionAPI
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getLegacyCompatibleComponents = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _createQuickInsertMatcher = require("@atlaskit/editor-common/quick-insert/create-quick-insert-matcher");
12
+ var _getMenuItemParents = require("@atlaskit/editor-common/quick-insert/get-menu-item-parents");
13
+ var _getProviderMenuItemKey = require("@atlaskit/editor-common/quick-insert/get-provider-menu-item-key");
14
+ var _menuItem = require("@atlaskit/editor-common/quick-insert/menu-item");
15
+ var _useQuickInsertContext = require("@atlaskit/editor-common/quick-insert/use-quick-insert-context");
16
+ var _apps = _interopRequireDefault(require("@atlaskit/icon/core/apps"));
17
+ 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; }
18
+ 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; }
19
+ var LegacyQuickInsertProviderMenuItem = function LegacyQuickInsertProviderMenuItem(_ref) {
20
+ var item = _ref.item,
21
+ onInsert = _ref.onInsert;
22
+ var _useQuickInsertContex = (0, _useQuickInsertContext.useQuickInsertContext)(),
23
+ editorView = _useQuickInsertContex.editorView,
24
+ isOffline = _useQuickInsertContex.isOffline;
25
+ var isDisabled = item.isDisabledOffline === true && isOffline;
26
+ var onSelect = function onSelect(_ref2) {
27
+ var insert = _ref2.insert,
28
+ source = _ref2.source;
29
+ var result = item.action(insert, editorView.state, source);
30
+ if (result) {
31
+ onInsert(item);
32
+ }
33
+ return result;
34
+ };
35
+ var Icon = item.icon;
36
+ return /*#__PURE__*/_react.default.createElement(_menuItem.QuickInsertMenuItem, {
37
+ iconBefore: Icon ? /*#__PURE__*/_react.default.createElement(Icon, null) : /*#__PURE__*/_react.default.createElement(_apps.default, {
38
+ label: ""
39
+ }),
40
+ isDisabled: isDisabled,
41
+ onSelect: onSelect,
42
+ shortcut: item.keyshortcut,
43
+ title: item.title
44
+ });
45
+ };
46
+ var getItemIdentity = function getItemIdentity(item, index) {
47
+ var _ref3, _item$key;
48
+ return String((_ref3 = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.id) !== null && _ref3 !== void 0 ? _ref3 : index);
49
+ };
50
+ var getComponentsFromLegacyItems = function getComponentsFromLegacyItems(items, onInsert) {
51
+ return items.map(function (item, index) {
52
+ var _item$priority;
53
+ var identity = getItemIdentity(item, index);
54
+ return {
55
+ type: 'menu-item',
56
+ key: (0, _getProviderMenuItemKey.getQuickInsertProviderMenuItemKey)(identity),
57
+ parents: (0, _getMenuItemParents.getQuickInsertMenuItemParents)({
58
+ categories: item.categories,
59
+ rank: (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index
60
+ }),
61
+ component: function component() {
62
+ return /*#__PURE__*/_react.default.createElement(LegacyQuickInsertProviderMenuItem, {
63
+ item: item,
64
+ onInsert: onInsert
65
+ });
66
+ },
67
+ match: (0, _createQuickInsertMatcher.createQuickInsertMatcher)(function () {
68
+ return {
69
+ description: item.description,
70
+ keywords: item.keywords,
71
+ shortcut: item.keyshortcut,
72
+ title: item.title
73
+ };
74
+ })
75
+ };
76
+ });
77
+ };
78
+ var getLegacyCompatibleComponents = exports.getLegacyCompatibleComponents = function getLegacyCompatibleComponents(_ref4) {
79
+ var directComponents = _ref4.directComponents,
80
+ itemFilter = _ref4.itemFilter,
81
+ _onInsert = _ref4.onInsert,
82
+ providedItems = _ref4.providedItems;
83
+ var filteredItems = itemFilter ? providedItems.filter(itemFilter) : providedItems;
84
+ var allowedKeys = new Set(filteredItems.map(function (item, index) {
85
+ return getItemIdentity(item, index);
86
+ }));
87
+ var directComponentsWithRenderer = directComponents.filter(function (component) {
88
+ return typeof component.component === 'function';
89
+ });
90
+ var namespacedDirectComponents = directComponentsWithRenderer.filter(function (component) {
91
+ return !itemFilter || allowedKeys.has(component.key);
92
+ }).map(function (component) {
93
+ var _component$match;
94
+ var item = filteredItems.find(function (candidate, index) {
95
+ return getItemIdentity(candidate, index) === component.key;
96
+ });
97
+ return _objectSpread(_objectSpread({}, component), {}, {
98
+ key: (0, _getProviderMenuItemKey.getQuickInsertProviderMenuItemKey)(component.key),
99
+ component: item ? function (props) {
100
+ return component.component(_objectSpread(_objectSpread({}, props), {}, {
101
+ onInsert: function onInsert() {
102
+ return _onInsert(item);
103
+ }
104
+ }));
105
+ } : component.component,
106
+ match: (_component$match = component.match) !== null && _component$match !== void 0 ? _component$match : item ? (0, _createQuickInsertMatcher.createQuickInsertMatcher)(function () {
107
+ return {
108
+ description: item.description,
109
+ keywords: item.keywords,
110
+ shortcut: item.keyshortcut,
111
+ title: item.title
112
+ };
113
+ }) : undefined
114
+ });
115
+ });
116
+ var directComponentKeys = new Set(directComponentsWithRenderer.map(function (component) {
117
+ return component.key;
118
+ }));
119
+ var fallbackComponents = getComponentsFromLegacyItems(filteredItems.filter(function (item, index) {
120
+ return !directComponentKeys.has(getItemIdentity(item, index));
121
+ }), _onInsert);
122
+ return [].concat((0, _toConsumableArray2.default)(fallbackComponents), (0, _toConsumableArray2.default)(namespacedDirectComponents));
123
+ };
@@ -13,6 +13,7 @@ import { createQuickInsertItemsAnalyticsScheduler } from './app-category-analyti
13
13
  import { createInsertItem, openElementBrowser as openElementBrowserCommand, openElementBrowserModal } from './pm-plugins/commands';
14
14
  import { getQuickInsertOpenExperiencePlugin } from './pm-plugins/experiences/quick-insert-open-experience';
15
15
  import { pluginKey } from './pm-plugins/plugin-key';
16
+ import { getLegacyCompatibleComponents } from './ui/getLegacyCompatibleComponents';
16
17
  import { getQuickInsertComponents } from './ui/getQuickInsertComponents';
17
18
  import ModalElementBrowser from './ui/ModalElementBrowser';
18
19
  import { getQuickInsertSuggestions, withLayoutQuickInsertPrioritySorting } from './ui/search';
@@ -120,7 +121,7 @@ export const quickInsertPlugin = ({
120
121
  getIntl,
121
122
  dispatch,
122
123
  dispatchAnalyticsEvent
123
- }) => quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, options === null || options === void 0 ? void 0 : options.emptyStateHandler)
124
+ }) => quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, options === null || options === void 0 ? void 0 : options.emptyStateHandler, onInsert, options === null || options === void 0 ? void 0 : options.itemFilter, api)
124
125
  }, {
125
126
  name: 'quickInsertOpenExperience',
126
127
  plugin: () => getQuickInsertOpenExperiencePlugin({
@@ -290,7 +291,7 @@ const setProviderState = providerState => (state, dispatch) => {
290
291
  }
291
292
  return true;
292
293
  };
293
- function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, emptyStateHandler) {
294
+ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, emptyStateHandler, onInsert = () => {}, itemFilter, api) {
294
295
  return new SafePlugin({
295
296
  key: pluginKey,
296
297
  state: {
@@ -332,6 +333,17 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
332
333
  try {
333
334
  const provider = await providerPromise;
334
335
  const providedItems = await provider.getItems();
336
+ if (isExperimentEnabled('platform_editor_slash_command')) {
337
+ var _api$uiControlRegistr2;
338
+ const directComponents = provider.getComponents ? await provider.getComponents() : [];
339
+ const components = getLegacyCompatibleComponents({
340
+ directComponents,
341
+ itemFilter,
342
+ onInsert,
343
+ providedItems
344
+ });
345
+ api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.register(components);
346
+ }
335
347
  setProviderState({
336
348
  provider,
337
349
  providedItems
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { isOfflineMode } from '@atlaskit/editor-common/connectivity/isOfflineMode';
3
4
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
- import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
5
5
  import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
6
6
  import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { closeElementBrowser, closeElementBrowserModal } from '../../pm-plugins/commands';
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import { createQuickInsertMatcher } from '@atlaskit/editor-common/quick-insert/create-quick-insert-matcher';
3
+ import { getQuickInsertMenuItemParents } from '@atlaskit/editor-common/quick-insert/get-menu-item-parents';
4
+ import { getQuickInsertProviderMenuItemKey } from '@atlaskit/editor-common/quick-insert/get-provider-menu-item-key';
5
+ import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
6
+ import { useQuickInsertContext } from '@atlaskit/editor-common/quick-insert/use-quick-insert-context';
7
+ import AppsIcon from '@atlaskit/icon/core/apps';
8
+ const LegacyQuickInsertProviderMenuItem = ({
9
+ item,
10
+ onInsert
11
+ }) => {
12
+ const {
13
+ editorView,
14
+ isOffline
15
+ } = useQuickInsertContext();
16
+ const isDisabled = item.isDisabledOffline === true && isOffline;
17
+ const onSelect = ({
18
+ insert,
19
+ source
20
+ }) => {
21
+ const result = item.action(insert, editorView.state, source);
22
+ if (result) {
23
+ onInsert(item);
24
+ }
25
+ return result;
26
+ };
27
+ const Icon = item.icon;
28
+ return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
29
+ iconBefore: Icon ? /*#__PURE__*/React.createElement(Icon, null) : /*#__PURE__*/React.createElement(AppsIcon, {
30
+ label: ""
31
+ }),
32
+ isDisabled: isDisabled,
33
+ onSelect: onSelect,
34
+ shortcut: item.keyshortcut,
35
+ title: item.title
36
+ });
37
+ };
38
+ const getItemIdentity = (item, index) => {
39
+ var _ref, _item$key;
40
+ return String((_ref = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.id) !== null && _ref !== void 0 ? _ref : index);
41
+ };
42
+ const getComponentsFromLegacyItems = (items, onInsert) => items.map((item, index) => {
43
+ var _item$priority;
44
+ const identity = getItemIdentity(item, index);
45
+ return {
46
+ type: 'menu-item',
47
+ key: getQuickInsertProviderMenuItemKey(identity),
48
+ parents: getQuickInsertMenuItemParents({
49
+ categories: item.categories,
50
+ rank: (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index
51
+ }),
52
+ component: () => /*#__PURE__*/React.createElement(LegacyQuickInsertProviderMenuItem, {
53
+ item: item,
54
+ onInsert: onInsert
55
+ }),
56
+ match: createQuickInsertMatcher(() => ({
57
+ description: item.description,
58
+ keywords: item.keywords,
59
+ shortcut: item.keyshortcut,
60
+ title: item.title
61
+ }))
62
+ };
63
+ });
64
+ export const getLegacyCompatibleComponents = ({
65
+ directComponents,
66
+ itemFilter,
67
+ onInsert,
68
+ providedItems
69
+ }) => {
70
+ const filteredItems = itemFilter ? providedItems.filter(itemFilter) : providedItems;
71
+ const allowedKeys = new Set(filteredItems.map((item, index) => getItemIdentity(item, index)));
72
+ const directComponentsWithRenderer = directComponents.filter(component => typeof component.component === 'function');
73
+ const namespacedDirectComponents = directComponentsWithRenderer.filter(component => !itemFilter || allowedKeys.has(component.key)).map(component => {
74
+ var _component$match;
75
+ const item = filteredItems.find((candidate, index) => getItemIdentity(candidate, index) === component.key);
76
+ return {
77
+ ...component,
78
+ key: getQuickInsertProviderMenuItemKey(component.key),
79
+ component: item ? props => component.component({
80
+ ...props,
81
+ onInsert: () => onInsert(item)
82
+ }) : component.component,
83
+ match: (_component$match = component.match) !== null && _component$match !== void 0 ? _component$match : item ? createQuickInsertMatcher(() => ({
84
+ description: item.description,
85
+ keywords: item.keywords,
86
+ shortcut: item.keyshortcut,
87
+ title: item.title
88
+ })) : undefined
89
+ };
90
+ });
91
+ const directComponentKeys = new Set(directComponentsWithRenderer.map(component => component.key));
92
+ const fallbackComponents = getComponentsFromLegacyItems(filteredItems.filter((item, index) => !directComponentKeys.has(getItemIdentity(item, index))), onInsert);
93
+ return [...fallbackComponents, ...namespacedDirectComponents];
94
+ };
@@ -19,6 +19,7 @@ import { createQuickInsertItemsAnalyticsScheduler } from './app-category-analyti
19
19
  import { createInsertItem, openElementBrowser as openElementBrowserCommand, openElementBrowserModal as _openElementBrowserModal } from './pm-plugins/commands';
20
20
  import { getQuickInsertOpenExperiencePlugin } from './pm-plugins/experiences/quick-insert-open-experience';
21
21
  import { pluginKey } from './pm-plugins/plugin-key';
22
+ import { getLegacyCompatibleComponents } from './ui/getLegacyCompatibleComponents';
22
23
  import { getQuickInsertComponents } from './ui/getQuickInsertComponents';
23
24
  import ModalElementBrowser from './ui/ModalElementBrowser';
24
25
  import { getQuickInsertSuggestions, withLayoutQuickInsertPrioritySorting } from './ui/search';
@@ -123,7 +124,7 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
123
124
  getIntl = _ref6.getIntl,
124
125
  dispatch = _ref6.dispatch,
125
126
  dispatchAnalyticsEvent = _ref6.dispatchAnalyticsEvent;
126
- return quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, options === null || options === void 0 ? void 0 : options.emptyStateHandler);
127
+ return quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, options === null || options === void 0 ? void 0 : options.emptyStateHandler, onInsert, options === null || options === void 0 ? void 0 : options.itemFilter, api);
127
128
  }
128
129
  }, {
129
130
  name: 'quickInsertOpenExperience',
@@ -313,6 +314,9 @@ var setProviderState = function setProviderState(providerState) {
313
314
  };
314
315
  };
315
316
  function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, dispatchAnalyticsEvent, emptyStateHandler) {
317
+ var onInsert = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : function () {};
318
+ var itemFilter = arguments.length > 7 ? arguments[7] : undefined;
319
+ var api = arguments.length > 8 ? arguments[8] : undefined;
316
320
  return new SafePlugin({
317
321
  key: pluginKey,
318
322
  state: {
@@ -350,12 +354,12 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
350
354
  var isDestroyed = false;
351
355
  var providerHandler = /*#__PURE__*/function () {
352
356
  var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_name, providerPromise) {
353
- var provider, providedItems, _t;
357
+ var provider, providedItems, _api$uiControlRegistr2, directComponents, components, _t, _t2;
354
358
  return _regeneratorRuntime.wrap(function (_context) {
355
359
  while (1) switch (_context.prev = _context.next) {
356
360
  case 0:
357
361
  if (!providerPromise) {
358
- _context.next = 5;
362
+ _context.next = 9;
359
363
  break;
360
364
  }
361
365
  _context.prev = 1;
@@ -367,6 +371,32 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
367
371
  return provider.getItems();
368
372
  case 3:
369
373
  providedItems = _context.sent;
374
+ if (!isExperimentEnabled('platform_editor_slash_command')) {
375
+ _context.next = 7;
376
+ break;
377
+ }
378
+ if (!provider.getComponents) {
379
+ _context.next = 5;
380
+ break;
381
+ }
382
+ _context.next = 4;
383
+ return provider.getComponents();
384
+ case 4:
385
+ _t = _context.sent;
386
+ _context.next = 6;
387
+ break;
388
+ case 5:
389
+ _t = [];
390
+ case 6:
391
+ directComponents = _t;
392
+ components = getLegacyCompatibleComponents({
393
+ directComponents: directComponents,
394
+ itemFilter: itemFilter,
395
+ onInsert: onInsert,
396
+ providedItems: providedItems
397
+ });
398
+ api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 || _api$uiControlRegistr2.actions.register(components);
399
+ case 7:
370
400
  setProviderState({
371
401
  provider: provider,
372
402
  providedItems: providedItems
@@ -375,18 +405,18 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
375
405
  quickInsertItemsAnalyticsScheduler = createQuickInsertItemsAnalyticsScheduler(dispatchAnalyticsEvent);
376
406
  quickInsertItemsAnalyticsScheduler.schedule(providedItems);
377
407
  }
378
- _context.next = 5;
408
+ _context.next = 9;
379
409
  break;
380
- case 4:
381
- _context.prev = 4;
382
- _t = _context["catch"](1);
410
+ case 8:
411
+ _context.prev = 8;
412
+ _t2 = _context["catch"](1);
383
413
  // eslint-disable-next-line no-console
384
- console.error('Error getting items from quick insert provider', _t);
385
- case 5:
414
+ console.error('Error getting items from quick insert provider', _t2);
415
+ case 9:
386
416
  case "end":
387
417
  return _context.stop();
388
418
  }
389
- }, _callee, null, [[1, 4]]);
419
+ }, _callee, null, [[1, 8]]);
390
420
  }));
391
421
  return function providerHandler(_x, _x2) {
392
422
  return _ref14.apply(this, arguments);
@@ -3,8 +3,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
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
4
  import React, { useCallback } from 'react';
5
5
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
+ import { isOfflineMode } from '@atlaskit/editor-common/connectivity/isOfflineMode';
6
7
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
7
- import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
8
8
  import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
9
9
  import { fg } from '@atlaskit/platform-feature-flags';
10
10
  import { closeElementBrowser, closeElementBrowserModal } from '../../pm-plugins/commands';
@@ -0,0 +1,116 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
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
+ import React from 'react';
6
+ import { createQuickInsertMatcher } from '@atlaskit/editor-common/quick-insert/create-quick-insert-matcher';
7
+ import { getQuickInsertMenuItemParents } from '@atlaskit/editor-common/quick-insert/get-menu-item-parents';
8
+ import { getQuickInsertProviderMenuItemKey } from '@atlaskit/editor-common/quick-insert/get-provider-menu-item-key';
9
+ import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
10
+ import { useQuickInsertContext } from '@atlaskit/editor-common/quick-insert/use-quick-insert-context';
11
+ import AppsIcon from '@atlaskit/icon/core/apps';
12
+ var LegacyQuickInsertProviderMenuItem = function LegacyQuickInsertProviderMenuItem(_ref) {
13
+ var item = _ref.item,
14
+ onInsert = _ref.onInsert;
15
+ var _useQuickInsertContex = useQuickInsertContext(),
16
+ editorView = _useQuickInsertContex.editorView,
17
+ isOffline = _useQuickInsertContex.isOffline;
18
+ var isDisabled = item.isDisabledOffline === true && isOffline;
19
+ var onSelect = function onSelect(_ref2) {
20
+ var insert = _ref2.insert,
21
+ source = _ref2.source;
22
+ var result = item.action(insert, editorView.state, source);
23
+ if (result) {
24
+ onInsert(item);
25
+ }
26
+ return result;
27
+ };
28
+ var Icon = item.icon;
29
+ return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
30
+ iconBefore: Icon ? /*#__PURE__*/React.createElement(Icon, null) : /*#__PURE__*/React.createElement(AppsIcon, {
31
+ label: ""
32
+ }),
33
+ isDisabled: isDisabled,
34
+ onSelect: onSelect,
35
+ shortcut: item.keyshortcut,
36
+ title: item.title
37
+ });
38
+ };
39
+ var getItemIdentity = function getItemIdentity(item, index) {
40
+ var _ref3, _item$key;
41
+ return String((_ref3 = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.id) !== null && _ref3 !== void 0 ? _ref3 : index);
42
+ };
43
+ var getComponentsFromLegacyItems = function getComponentsFromLegacyItems(items, onInsert) {
44
+ return items.map(function (item, index) {
45
+ var _item$priority;
46
+ var identity = getItemIdentity(item, index);
47
+ return {
48
+ type: 'menu-item',
49
+ key: getQuickInsertProviderMenuItemKey(identity),
50
+ parents: getQuickInsertMenuItemParents({
51
+ categories: item.categories,
52
+ rank: (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index
53
+ }),
54
+ component: function component() {
55
+ return /*#__PURE__*/React.createElement(LegacyQuickInsertProviderMenuItem, {
56
+ item: item,
57
+ onInsert: onInsert
58
+ });
59
+ },
60
+ match: createQuickInsertMatcher(function () {
61
+ return {
62
+ description: item.description,
63
+ keywords: item.keywords,
64
+ shortcut: item.keyshortcut,
65
+ title: item.title
66
+ };
67
+ })
68
+ };
69
+ });
70
+ };
71
+ export var getLegacyCompatibleComponents = function getLegacyCompatibleComponents(_ref4) {
72
+ var directComponents = _ref4.directComponents,
73
+ itemFilter = _ref4.itemFilter,
74
+ _onInsert = _ref4.onInsert,
75
+ providedItems = _ref4.providedItems;
76
+ var filteredItems = itemFilter ? providedItems.filter(itemFilter) : providedItems;
77
+ var allowedKeys = new Set(filteredItems.map(function (item, index) {
78
+ return getItemIdentity(item, index);
79
+ }));
80
+ var directComponentsWithRenderer = directComponents.filter(function (component) {
81
+ return typeof component.component === 'function';
82
+ });
83
+ var namespacedDirectComponents = directComponentsWithRenderer.filter(function (component) {
84
+ return !itemFilter || allowedKeys.has(component.key);
85
+ }).map(function (component) {
86
+ var _component$match;
87
+ var item = filteredItems.find(function (candidate, index) {
88
+ return getItemIdentity(candidate, index) === component.key;
89
+ });
90
+ return _objectSpread(_objectSpread({}, component), {}, {
91
+ key: getQuickInsertProviderMenuItemKey(component.key),
92
+ component: item ? function (props) {
93
+ return component.component(_objectSpread(_objectSpread({}, props), {}, {
94
+ onInsert: function onInsert() {
95
+ return _onInsert(item);
96
+ }
97
+ }));
98
+ } : component.component,
99
+ match: (_component$match = component.match) !== null && _component$match !== void 0 ? _component$match : item ? createQuickInsertMatcher(function () {
100
+ return {
101
+ description: item.description,
102
+ keywords: item.keywords,
103
+ shortcut: item.keyshortcut,
104
+ title: item.title
105
+ };
106
+ }) : undefined
107
+ });
108
+ });
109
+ var directComponentKeys = new Set(directComponentsWithRenderer.map(function (component) {
110
+ return component.key;
111
+ }));
112
+ var fallbackComponents = getComponentsFromLegacyItems(filteredItems.filter(function (item, index) {
113
+ return !directComponentKeys.has(getItemIdentity(item, index));
114
+ }), _onInsert);
115
+ return [].concat(_toConsumableArray(fallbackComponents), _toConsumableArray(namespacedDirectComponents));
116
+ };
@@ -0,0 +1,10 @@
1
+ import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
2
+ import type { RegisterMenuItem } from '@atlaskit/editor-ui-control-model/types';
3
+ type Options = {
4
+ directComponents: RegisterMenuItem[];
5
+ itemFilter?: (item: QuickInsertItem) => boolean;
6
+ onInsert: (item: QuickInsertItem) => void;
7
+ providedItems: QuickInsertItem[];
8
+ };
9
+ export declare const getLegacyCompatibleComponents: ({ directComponents, itemFilter, onInsert, providedItems, }: Options) => RegisterMenuItem[];
10
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-quick-insert",
3
- "version": "14.0.4",
3
+ "version": "14.1.1",
4
4
  "description": "Quick insert plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -25,10 +25,10 @@
25
25
  "@atlaskit/editor-plugin-analytics": "^14.0.0",
26
26
  "@atlaskit/editor-plugin-connectivity": "^14.0.0",
27
27
  "@atlaskit/editor-plugin-metrics": "^15.0.0",
28
- "@atlaskit/editor-plugin-type-ahead": "^15.0.0",
29
- "@atlaskit/editor-plugin-ui-control-registry": "^8.0.0",
28
+ "@atlaskit/editor-plugin-type-ahead": "^15.1.0",
29
+ "@atlaskit/editor-plugin-ui-control-registry": "^8.1.0",
30
30
  "@atlaskit/editor-prosemirror": "^8.0.0",
31
- "@atlaskit/editor-ui-control-model": "^2.4.0",
31
+ "@atlaskit/editor-ui-control-model": "^2.6.0",
32
32
  "@atlaskit/icon": "^37.3.0",
33
33
  "@atlaskit/modal-dialog": "^16.3.0",
34
34
  "@atlaskit/platform-feature-experiments": "^0.3.0",
@@ -39,7 +39,7 @@
39
39
  "@emotion/react": "^11.7.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "@atlaskit/editor-common": "^118.4.0",
42
+ "@atlaskit/editor-common": "^118.10.0",
43
43
  "react": "^18.2.0 || ^19.2.0",
44
44
  "react-dom": "^18.2.0 || ^19.2.0",
45
45
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"