@atlaskit/editor-plugin-quick-insert 14.0.4 → 14.1.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.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/quickInsertPlugin.js +40 -10
- package/dist/cjs/ui/ModalElementBrowser/index.js +2 -2
- package/dist/cjs/ui/getLegacyCompatibleComponents.js +105 -0
- package/dist/es2019/quickInsertPlugin.js +14 -2
- package/dist/es2019/ui/ModalElementBrowser/index.js +1 -1
- package/dist/es2019/ui/getLegacyCompatibleComponents.js +80 -0
- package/dist/esm/quickInsertPlugin.js +40 -10
- package/dist/esm/ui/ModalElementBrowser/index.js +1 -1
- package/dist/esm/ui/getLegacyCompatibleComponents.js +98 -0
- package/dist/types/ui/getLegacyCompatibleComponents.d.ts +10 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-quick-insert
|
|
2
2
|
|
|
3
|
+
## 14.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`c0cf420333ef1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c0cf420333ef1) -
|
|
8
|
+
Add public registration APIs for provider-backed Quick Insert components.
|
|
9
|
+
|
|
10
|
+
Providers can expose registered items directly:
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
const getComponents = async () => [
|
|
14
|
+
{
|
|
15
|
+
key: 'insert-table',
|
|
16
|
+
component: TableItem,
|
|
17
|
+
parents: [{ type: 'menu-section', key: 'quick-insert', rank: 1 }],
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
|
|
3
26
|
## 14.0.4
|
|
4
27
|
|
|
5
28
|
### 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 =
|
|
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 =
|
|
415
|
+
_context.next = 9;
|
|
386
416
|
break;
|
|
387
|
-
case
|
|
388
|
-
_context.prev =
|
|
389
|
-
|
|
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',
|
|
392
|
-
case
|
|
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,
|
|
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,
|
|
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,105 @@
|
|
|
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 _getMenuItemParents = require("@atlaskit/editor-common/quick-insert/get-menu-item-parents");
|
|
12
|
+
var _getProviderMenuItemKey = require("@atlaskit/editor-common/quick-insert/get-provider-menu-item-key");
|
|
13
|
+
var _menuItem = require("@atlaskit/editor-common/quick-insert/menu-item");
|
|
14
|
+
var _useQuickInsertContext = require("@atlaskit/editor-common/quick-insert/use-quick-insert-context");
|
|
15
|
+
var _apps = _interopRequireDefault(require("@atlaskit/icon/core/apps"));
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
var LegacyQuickInsertProviderMenuItem = function LegacyQuickInsertProviderMenuItem(_ref) {
|
|
19
|
+
var item = _ref.item,
|
|
20
|
+
onInsert = _ref.onInsert;
|
|
21
|
+
var _useQuickInsertContex = (0, _useQuickInsertContext.useQuickInsertContext)(),
|
|
22
|
+
editorView = _useQuickInsertContex.editorView,
|
|
23
|
+
isOffline = _useQuickInsertContex.isOffline;
|
|
24
|
+
var isDisabled = item.isDisabledOffline === true && isOffline;
|
|
25
|
+
var onSelect = function onSelect(_ref2) {
|
|
26
|
+
var insert = _ref2.insert,
|
|
27
|
+
source = _ref2.source;
|
|
28
|
+
var result = item.action(insert, editorView.state, source);
|
|
29
|
+
if (result) {
|
|
30
|
+
onInsert(item);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
var Icon = item.icon;
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement(_menuItem.QuickInsertMenuItem, {
|
|
36
|
+
iconBefore: Icon ? /*#__PURE__*/_react.default.createElement(Icon, null) : /*#__PURE__*/_react.default.createElement(_apps.default, {
|
|
37
|
+
label: ""
|
|
38
|
+
}),
|
|
39
|
+
isDisabled: isDisabled,
|
|
40
|
+
onSelect: onSelect,
|
|
41
|
+
shortcut: item.keyshortcut,
|
|
42
|
+
title: item.title
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var getItemIdentity = function getItemIdentity(item, index) {
|
|
46
|
+
var _ref3, _item$key;
|
|
47
|
+
return String((_ref3 = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.id) !== null && _ref3 !== void 0 ? _ref3 : index);
|
|
48
|
+
};
|
|
49
|
+
var getComponentsFromLegacyItems = function getComponentsFromLegacyItems(items, onInsert) {
|
|
50
|
+
return items.map(function (item, index) {
|
|
51
|
+
var _item$priority;
|
|
52
|
+
var identity = getItemIdentity(item, index);
|
|
53
|
+
return {
|
|
54
|
+
type: 'menu-item',
|
|
55
|
+
key: (0, _getProviderMenuItemKey.getQuickInsertProviderMenuItemKey)(identity),
|
|
56
|
+
parents: (0, _getMenuItemParents.getQuickInsertMenuItemParents)({
|
|
57
|
+
categories: item.categories,
|
|
58
|
+
rank: (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index
|
|
59
|
+
}),
|
|
60
|
+
component: function component() {
|
|
61
|
+
return /*#__PURE__*/_react.default.createElement(LegacyQuickInsertProviderMenuItem, {
|
|
62
|
+
item: item,
|
|
63
|
+
onInsert: onInsert
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
var getLegacyCompatibleComponents = exports.getLegacyCompatibleComponents = function getLegacyCompatibleComponents(_ref4) {
|
|
70
|
+
var directComponents = _ref4.directComponents,
|
|
71
|
+
itemFilter = _ref4.itemFilter,
|
|
72
|
+
_onInsert = _ref4.onInsert,
|
|
73
|
+
providedItems = _ref4.providedItems;
|
|
74
|
+
var filteredItems = itemFilter ? providedItems.filter(itemFilter) : providedItems;
|
|
75
|
+
var allowedKeys = new Set(filteredItems.map(function (item, index) {
|
|
76
|
+
return getItemIdentity(item, index);
|
|
77
|
+
}));
|
|
78
|
+
var directComponentsWithRenderer = directComponents.filter(function (component) {
|
|
79
|
+
return typeof component.component === 'function';
|
|
80
|
+
});
|
|
81
|
+
var namespacedDirectComponents = directComponentsWithRenderer.filter(function (component) {
|
|
82
|
+
return !itemFilter || allowedKeys.has(component.key);
|
|
83
|
+
}).map(function (component) {
|
|
84
|
+
var item = filteredItems.find(function (candidate, index) {
|
|
85
|
+
return getItemIdentity(candidate, index) === component.key;
|
|
86
|
+
});
|
|
87
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
88
|
+
key: (0, _getProviderMenuItemKey.getQuickInsertProviderMenuItemKey)(component.key),
|
|
89
|
+
component: item ? function (props) {
|
|
90
|
+
return component.component(_objectSpread(_objectSpread({}, props), {}, {
|
|
91
|
+
onInsert: function onInsert() {
|
|
92
|
+
return _onInsert(item);
|
|
93
|
+
}
|
|
94
|
+
}));
|
|
95
|
+
} : component.component
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
var directComponentKeys = new Set(directComponentsWithRenderer.map(function (component) {
|
|
99
|
+
return component.key;
|
|
100
|
+
}));
|
|
101
|
+
var fallbackComponents = getComponentsFromLegacyItems(filteredItems.filter(function (item, index) {
|
|
102
|
+
return !directComponentKeys.has(getItemIdentity(item, index));
|
|
103
|
+
}), _onInsert);
|
|
104
|
+
return [].concat((0, _toConsumableArray2.default)(fallbackComponents), (0, _toConsumableArray2.default)(namespacedDirectComponents));
|
|
105
|
+
};
|
|
@@ -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,80 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { getQuickInsertMenuItemParents } from '@atlaskit/editor-common/quick-insert/get-menu-item-parents';
|
|
3
|
+
import { getQuickInsertProviderMenuItemKey } from '@atlaskit/editor-common/quick-insert/get-provider-menu-item-key';
|
|
4
|
+
import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
|
|
5
|
+
import { useQuickInsertContext } from '@atlaskit/editor-common/quick-insert/use-quick-insert-context';
|
|
6
|
+
import AppsIcon from '@atlaskit/icon/core/apps';
|
|
7
|
+
const LegacyQuickInsertProviderMenuItem = ({
|
|
8
|
+
item,
|
|
9
|
+
onInsert
|
|
10
|
+
}) => {
|
|
11
|
+
const {
|
|
12
|
+
editorView,
|
|
13
|
+
isOffline
|
|
14
|
+
} = useQuickInsertContext();
|
|
15
|
+
const isDisabled = item.isDisabledOffline === true && isOffline;
|
|
16
|
+
const onSelect = ({
|
|
17
|
+
insert,
|
|
18
|
+
source
|
|
19
|
+
}) => {
|
|
20
|
+
const result = item.action(insert, editorView.state, source);
|
|
21
|
+
if (result) {
|
|
22
|
+
onInsert(item);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
const Icon = item.icon;
|
|
27
|
+
return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
|
|
28
|
+
iconBefore: Icon ? /*#__PURE__*/React.createElement(Icon, null) : /*#__PURE__*/React.createElement(AppsIcon, {
|
|
29
|
+
label: ""
|
|
30
|
+
}),
|
|
31
|
+
isDisabled: isDisabled,
|
|
32
|
+
onSelect: onSelect,
|
|
33
|
+
shortcut: item.keyshortcut,
|
|
34
|
+
title: item.title
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const getItemIdentity = (item, index) => {
|
|
38
|
+
var _ref, _item$key;
|
|
39
|
+
return String((_ref = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.id) !== null && _ref !== void 0 ? _ref : index);
|
|
40
|
+
};
|
|
41
|
+
const getComponentsFromLegacyItems = (items, onInsert) => items.map((item, index) => {
|
|
42
|
+
var _item$priority;
|
|
43
|
+
const identity = getItemIdentity(item, index);
|
|
44
|
+
return {
|
|
45
|
+
type: 'menu-item',
|
|
46
|
+
key: getQuickInsertProviderMenuItemKey(identity),
|
|
47
|
+
parents: getQuickInsertMenuItemParents({
|
|
48
|
+
categories: item.categories,
|
|
49
|
+
rank: (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index
|
|
50
|
+
}),
|
|
51
|
+
component: () => /*#__PURE__*/React.createElement(LegacyQuickInsertProviderMenuItem, {
|
|
52
|
+
item: item,
|
|
53
|
+
onInsert: onInsert
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
export const getLegacyCompatibleComponents = ({
|
|
58
|
+
directComponents,
|
|
59
|
+
itemFilter,
|
|
60
|
+
onInsert,
|
|
61
|
+
providedItems
|
|
62
|
+
}) => {
|
|
63
|
+
const filteredItems = itemFilter ? providedItems.filter(itemFilter) : providedItems;
|
|
64
|
+
const allowedKeys = new Set(filteredItems.map((item, index) => getItemIdentity(item, index)));
|
|
65
|
+
const directComponentsWithRenderer = directComponents.filter(component => typeof component.component === 'function');
|
|
66
|
+
const namespacedDirectComponents = directComponentsWithRenderer.filter(component => !itemFilter || allowedKeys.has(component.key)).map(component => {
|
|
67
|
+
const item = filteredItems.find((candidate, index) => getItemIdentity(candidate, index) === component.key);
|
|
68
|
+
return {
|
|
69
|
+
...component,
|
|
70
|
+
key: getQuickInsertProviderMenuItemKey(component.key),
|
|
71
|
+
component: item ? props => component.component({
|
|
72
|
+
...props,
|
|
73
|
+
onInsert: () => onInsert(item)
|
|
74
|
+
}) : component.component
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
const directComponentKeys = new Set(directComponentsWithRenderer.map(component => component.key));
|
|
78
|
+
const fallbackComponents = getComponentsFromLegacyItems(filteredItems.filter((item, index) => !directComponentKeys.has(getItemIdentity(item, index))), onInsert);
|
|
79
|
+
return [...fallbackComponents, ...namespacedDirectComponents];
|
|
80
|
+
};
|
|
@@ -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 =
|
|
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 =
|
|
408
|
+
_context.next = 9;
|
|
379
409
|
break;
|
|
380
|
-
case
|
|
381
|
-
_context.prev =
|
|
382
|
-
|
|
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',
|
|
385
|
-
case
|
|
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,
|
|
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,98 @@
|
|
|
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 { getQuickInsertMenuItemParents } from '@atlaskit/editor-common/quick-insert/get-menu-item-parents';
|
|
7
|
+
import { getQuickInsertProviderMenuItemKey } from '@atlaskit/editor-common/quick-insert/get-provider-menu-item-key';
|
|
8
|
+
import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
|
|
9
|
+
import { useQuickInsertContext } from '@atlaskit/editor-common/quick-insert/use-quick-insert-context';
|
|
10
|
+
import AppsIcon from '@atlaskit/icon/core/apps';
|
|
11
|
+
var LegacyQuickInsertProviderMenuItem = function LegacyQuickInsertProviderMenuItem(_ref) {
|
|
12
|
+
var item = _ref.item,
|
|
13
|
+
onInsert = _ref.onInsert;
|
|
14
|
+
var _useQuickInsertContex = useQuickInsertContext(),
|
|
15
|
+
editorView = _useQuickInsertContex.editorView,
|
|
16
|
+
isOffline = _useQuickInsertContex.isOffline;
|
|
17
|
+
var isDisabled = item.isDisabledOffline === true && isOffline;
|
|
18
|
+
var onSelect = function onSelect(_ref2) {
|
|
19
|
+
var insert = _ref2.insert,
|
|
20
|
+
source = _ref2.source;
|
|
21
|
+
var result = item.action(insert, editorView.state, source);
|
|
22
|
+
if (result) {
|
|
23
|
+
onInsert(item);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var 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
|
+
var getItemIdentity = function getItemIdentity(item, index) {
|
|
39
|
+
var _ref3, _item$key;
|
|
40
|
+
return String((_ref3 = (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.id) !== null && _ref3 !== void 0 ? _ref3 : index);
|
|
41
|
+
};
|
|
42
|
+
var getComponentsFromLegacyItems = function getComponentsFromLegacyItems(items, onInsert) {
|
|
43
|
+
return items.map(function (item, index) {
|
|
44
|
+
var _item$priority;
|
|
45
|
+
var identity = getItemIdentity(item, index);
|
|
46
|
+
return {
|
|
47
|
+
type: 'menu-item',
|
|
48
|
+
key: getQuickInsertProviderMenuItemKey(identity),
|
|
49
|
+
parents: getQuickInsertMenuItemParents({
|
|
50
|
+
categories: item.categories,
|
|
51
|
+
rank: (_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index
|
|
52
|
+
}),
|
|
53
|
+
component: function component() {
|
|
54
|
+
return /*#__PURE__*/React.createElement(LegacyQuickInsertProviderMenuItem, {
|
|
55
|
+
item: item,
|
|
56
|
+
onInsert: onInsert
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
export var getLegacyCompatibleComponents = function getLegacyCompatibleComponents(_ref4) {
|
|
63
|
+
var directComponents = _ref4.directComponents,
|
|
64
|
+
itemFilter = _ref4.itemFilter,
|
|
65
|
+
_onInsert = _ref4.onInsert,
|
|
66
|
+
providedItems = _ref4.providedItems;
|
|
67
|
+
var filteredItems = itemFilter ? providedItems.filter(itemFilter) : providedItems;
|
|
68
|
+
var allowedKeys = new Set(filteredItems.map(function (item, index) {
|
|
69
|
+
return getItemIdentity(item, index);
|
|
70
|
+
}));
|
|
71
|
+
var directComponentsWithRenderer = directComponents.filter(function (component) {
|
|
72
|
+
return typeof component.component === 'function';
|
|
73
|
+
});
|
|
74
|
+
var namespacedDirectComponents = directComponentsWithRenderer.filter(function (component) {
|
|
75
|
+
return !itemFilter || allowedKeys.has(component.key);
|
|
76
|
+
}).map(function (component) {
|
|
77
|
+
var item = filteredItems.find(function (candidate, index) {
|
|
78
|
+
return getItemIdentity(candidate, index) === component.key;
|
|
79
|
+
});
|
|
80
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
81
|
+
key: getQuickInsertProviderMenuItemKey(component.key),
|
|
82
|
+
component: item ? function (props) {
|
|
83
|
+
return component.component(_objectSpread(_objectSpread({}, props), {}, {
|
|
84
|
+
onInsert: function onInsert() {
|
|
85
|
+
return _onInsert(item);
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
} : component.component
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
var directComponentKeys = new Set(directComponentsWithRenderer.map(function (component) {
|
|
92
|
+
return component.key;
|
|
93
|
+
}));
|
|
94
|
+
var fallbackComponents = getComponentsFromLegacyItems(filteredItems.filter(function (item, index) {
|
|
95
|
+
return !directComponentKeys.has(getItemIdentity(item, index));
|
|
96
|
+
}), _onInsert);
|
|
97
|
+
return [].concat(_toConsumableArray(fallbackComponents), _toConsumableArray(namespacedDirectComponents));
|
|
98
|
+
};
|
|
@@ -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
|
|
3
|
+
"version": "14.1.0",
|
|
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.
|
|
29
|
-
"@atlaskit/editor-plugin-ui-control-registry": "^8.
|
|
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.
|
|
31
|
+
"@atlaskit/editor-ui-control-model": "^2.5.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.
|
|
42
|
+
"@atlaskit/editor-common": "^118.8.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"
|