@atlaskit/editor-core 223.0.7 → 223.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/cjs/create-editor/ReactEditorView.js +1 -1
  3. package/dist/cjs/presets/default.js +2 -1
  4. package/dist/cjs/ui/quick-insert/ExtensionQuickInsertIcon.js +85 -0
  5. package/dist/cjs/ui/quick-insert/ExtensionQuickInsertMenuItem.js +47 -0
  6. package/dist/cjs/ui/quick-insert/executeExtensionQuickInsertItem.js +98 -0
  7. package/dist/cjs/ui/quick-insert/getExtensionQuickInsertComponents.js +44 -0
  8. package/dist/cjs/utils/combineQuickInsertProviders.js +5 -1
  9. package/dist/cjs/utils/extensions.js +30 -9
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/es2019/create-editor/ReactEditorView.js +1 -1
  12. package/dist/es2019/presets/default.js +2 -1
  13. package/dist/es2019/ui/quick-insert/ExtensionQuickInsertIcon.js +46 -0
  14. package/dist/es2019/ui/quick-insert/ExtensionQuickInsertMenuItem.js +42 -0
  15. package/dist/es2019/ui/quick-insert/executeExtensionQuickInsertItem.js +77 -0
  16. package/dist/es2019/ui/quick-insert/getExtensionQuickInsertComponents.js +34 -0
  17. package/dist/es2019/utils/combineQuickInsertProviders.js +5 -1
  18. package/dist/es2019/utils/extensions.js +25 -8
  19. package/dist/es2019/version-wrapper.js +1 -1
  20. package/dist/esm/create-editor/ReactEditorView.js +1 -1
  21. package/dist/esm/presets/default.js +2 -1
  22. package/dist/esm/ui/quick-insert/ExtensionQuickInsertIcon.js +78 -0
  23. package/dist/esm/ui/quick-insert/ExtensionQuickInsertMenuItem.js +39 -0
  24. package/dist/esm/ui/quick-insert/executeExtensionQuickInsertItem.js +91 -0
  25. package/dist/esm/ui/quick-insert/getExtensionQuickInsertComponents.js +37 -0
  26. package/dist/esm/utils/combineQuickInsertProviders.js +5 -1
  27. package/dist/esm/utils/extensions.js +30 -9
  28. package/dist/esm/version-wrapper.js +1 -1
  29. package/dist/types/ui/quick-insert/ExtensionQuickInsertIcon.d.ts +6 -0
  30. package/dist/types/ui/quick-insert/ExtensionQuickInsertMenuItem.d.ts +11 -0
  31. package/dist/types/ui/quick-insert/executeExtensionQuickInsertItem.d.ts +16 -0
  32. package/dist/types/ui/quick-insert/getExtensionQuickInsertComponents.d.ts +11 -0
  33. package/dist/types/utils/extensions.d.ts +1 -0
  34. package/package.json +5 -8
@@ -0,0 +1,77 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, fireAnalyticsEvent, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { resolveImport } from '@atlaskit/editor-common/extensions';
3
+ import { safeInsert } from '@atlaskit/editor-common/insert';
4
+ import { logException } from '@atlaskit/editor-common/monitoring';
5
+ import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
6
+ import { findInsertLocation } from '@atlaskit/editor-common/utils/analytics';
7
+ const sendAnalytics = (item, selection, createAnalyticsEvent, source) => {
8
+ if (createAnalyticsEvent) {
9
+ const insertLocation = findInsertLocation(selection);
10
+ fireAnalyticsEvent(createAnalyticsEvent)({
11
+ payload: {
12
+ action: ACTION.INSERTED,
13
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
14
+ actionSubjectId: ACTION_SUBJECT_ID.EXTENSION,
15
+ attributes: {
16
+ extensionType: item.extensionType,
17
+ extensionKey: item.extensionKey,
18
+ key: item.key,
19
+ inputMethod: source || INPUT_METHOD.QUICK_INSERT,
20
+ ...(insertLocation ? {
21
+ insertLocation
22
+ } : {})
23
+ },
24
+ eventType: EVENT_TYPE.TRACK
25
+ }
26
+ });
27
+ }
28
+ };
29
+ const warnDummyAPI = location => {
30
+ if (process.env.NODE_ENV !== 'production') {
31
+ // eslint-disable-next-line no-console
32
+ console.warn('Extension plugin not attached to editor - cannot use extension API in ' + location);
33
+ }
34
+ };
35
+ const dummyExtensionAPI = {
36
+ editInContextPanel: () => warnDummyAPI('editInContextPanel'),
37
+ _editInLegacyMacroBrowser: () => warnDummyAPI('_editInLegacyMacroBrowser'),
38
+ getNodeWithPosByLocalId: () => ({
39
+ node: null,
40
+ pos: null
41
+ }),
42
+ doc: {
43
+ insertAfter: () => warnDummyAPI('doc:insertAfter'),
44
+ scrollTo: () => warnDummyAPI('doc:scrollTo'),
45
+ update: () => warnDummyAPI('doc:update')
46
+ }
47
+ };
48
+ export const executeExtensionQuickInsertItem = ({
49
+ apiRef,
50
+ createAnalyticsEvent,
51
+ insert,
52
+ item,
53
+ source,
54
+ state
55
+ }) => {
56
+ if (typeof item.node === 'function') {
57
+ var _apiRef$current$exten, _apiRef$current, _apiRef$current$exten2, _apiRef$current$exten3;
58
+ const extensionAPI = (_apiRef$current$exten = (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : (_apiRef$current$exten2 = _apiRef$current.extension) === null || _apiRef$current$exten2 === void 0 ? void 0 : (_apiRef$current$exten3 = _apiRef$current$exten2.actions) === null || _apiRef$current$exten3 === void 0 ? void 0 : _apiRef$current$exten3.api()) !== null && _apiRef$current$exten !== void 0 ? _apiRef$current$exten : dummyExtensionAPI;
59
+ void resolveImport(item.node(extensionAPI)).then(node => {
60
+ sendAnalytics(item, state.selection, createAnalyticsEvent, source);
61
+ if (node && apiRef.current) {
62
+ apiRef.current.core.actions.execute(({
63
+ tr
64
+ }) => {
65
+ var _safeInsert$scrollInt, _safeInsert;
66
+ const content = processRawValue(tr.doc.type.schema, node);
67
+ return content ? (_safeInsert$scrollInt = (_safeInsert = safeInsert(content)(tr)) === null || _safeInsert === void 0 ? void 0 : _safeInsert.scrollIntoView()) !== null && _safeInsert$scrollInt !== void 0 ? _safeInsert$scrollInt : null : null;
68
+ });
69
+ }
70
+ }).catch(error => logException(error, {
71
+ location: 'editor-core/quick-insert'
72
+ }));
73
+ return insert('');
74
+ }
75
+ sendAnalytics(item, state.selection, createAnalyticsEvent, source);
76
+ return insert(item.node);
77
+ };
@@ -0,0 +1,34 @@
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 { EXTENSION_ITEM_RANK } from '@atlaskit/editor-common/quick-insert/rank';
5
+ import { ExtensionQuickInsertMenuItem } from './ExtensionQuickInsertMenuItem';
6
+ export const getExtensionQuickInsertComponents = ({
7
+ apiRef,
8
+ createAnalyticsEvent,
9
+ items
10
+ }) => items.map((item, index) => {
11
+ var _item$priority;
12
+ return {
13
+ type: 'menu-item',
14
+ key: item.key,
15
+ parents: getQuickInsertMenuItemParents({
16
+ categories: item.categories,
17
+ rank: EXTENSION_ITEM_RANK + ((_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index)
18
+ }),
19
+ match: createQuickInsertMatcher(() => ({
20
+ description: item.description,
21
+ keywords: item.keywords,
22
+ title: item.title
23
+ })),
24
+ component: props => {
25
+ const onInsert = typeof props.onInsert === 'function' ? props.onInsert : undefined;
26
+ return /*#__PURE__*/React.createElement(ExtensionQuickInsertMenuItem, {
27
+ apiRef: apiRef,
28
+ createAnalyticsEvent: createAnalyticsEvent,
29
+ item: item,
30
+ onInsert: onInsert
31
+ });
32
+ }
33
+ };
34
+ });
@@ -1,9 +1,13 @@
1
1
  import { combineProviders } from '@atlaskit/editor-common/provider-helpers';
2
2
  export function combineQuickInsertProviders(quickInsertProviders) {
3
3
  const {
4
- invokeList
4
+ invokeList,
5
+ invokeOptionalList
5
6
  } = combineProviders(quickInsertProviders);
6
7
  return {
8
+ getComponents() {
9
+ return invokeOptionalList('getComponents');
10
+ },
7
11
  getItems() {
8
12
  return invokeList('getItems');
9
13
  }
@@ -3,6 +3,8 @@ import Loadable from 'react-loadable';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, fireAnalyticsEvent, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
4
  import { getQuickInsertItemsFromModule, resolveImport } from '@atlaskit/editor-common/extensions';
5
5
  import { findInsertLocation } from '@atlaskit/editor-common/utils/analytics';
6
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
7
+ import { getExtensionQuickInsertComponents } from '../ui/quick-insert/getExtensionQuickInsertComponents';
6
8
 
7
9
  // Structural shape of the markdown-mode plugin's slice of the injection API.
8
10
  // Used to read `isMarkdownMode` without importing the `MarkdownModePlugin`
@@ -10,7 +12,7 @@ import { findInsertLocation } from '@atlaskit/editor-common/utils/analytics';
10
12
  // dependency graph and force every consuming product to rebuild.
11
13
 
12
14
  /**
13
- * Utils to send analytics event when a extension is inserted using quickInsert
15
+ * Utils to send analytics event when an extension is inserted using quickInsert
14
16
  */
15
17
  function sendExtensionQuickInsertAnalytics(item, selection, createAnalyticsEvent, source) {
16
18
  if (createAnalyticsEvent) {
@@ -24,7 +26,6 @@ function sendExtensionQuickInsertAnalytics(item, selection, createAnalyticsEvent
24
26
  extensionType: item.extensionType,
25
27
  extensionKey: item.extensionKey,
26
28
  key: item.key,
27
- // @note inputMethod defaults to QUICK_INSERT if not provided
28
29
  inputMethod: source || INPUT_METHOD.QUICK_INSERT,
29
30
  ...(insertLocation ? {
30
31
  insertLocation
@@ -54,16 +55,31 @@ const dummyExtensionAPI = {
54
55
  update: () => showDummyAPIWarning('doc:update')
55
56
  }
56
57
  };
58
+
59
+ /** Creates legacy and registered Quick Insert representations for extensions. */
57
60
  export async function extensionProviderToQuickInsertProvider(extensionProvider, editorActions, apiRef, createAnalyticsEvent) {
58
61
  const extensions = await extensionProvider.getExtensions();
62
+ const getMenuItems = () => getQuickInsertItemsFromModule(extensions, item => item);
59
63
  return {
60
- getItems: () => {
64
+ getComponents: () => {
61
65
  var _apiRef$current, _apiRef$current$markd, _apiRef$current$markd2;
66
+ const isMarkdownMode = (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : (_apiRef$current$markd = _apiRef$current.markdownMode) === null || _apiRef$current$markd === void 0 ? void 0 : (_apiRef$current$markd2 = _apiRef$current$markd.sharedState.currentState()) === null || _apiRef$current$markd2 === void 0 ? void 0 : _apiRef$current$markd2.isMarkdownMode;
67
+ if (!isExperimentEnabled('platform_editor_slash_command') || isMarkdownMode) {
68
+ return Promise.resolve([]);
69
+ }
70
+ return Promise.resolve(getExtensionQuickInsertComponents({
71
+ apiRef,
72
+ createAnalyticsEvent,
73
+ items: getMenuItems()
74
+ }));
75
+ },
76
+ getItems: () => {
77
+ var _apiRef$current2, _apiRef$current2$mark, _apiRef$current2$mark2;
62
78
  // `extensionProvider` is supplied independently of the preset, so
63
79
  // suppress its items in markdown mode where rich-only content cannot
64
80
  // be inserted. See `MarkdownModeReader` above for why this is read
65
81
  // via a structural cast rather than the typed plugin API.
66
- const isMarkdownMode = (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : (_apiRef$current$markd = _apiRef$current.markdownMode) === null || _apiRef$current$markd === void 0 ? void 0 : (_apiRef$current$markd2 = _apiRef$current$markd.sharedState.currentState()) === null || _apiRef$current$markd2 === void 0 ? void 0 : _apiRef$current$markd2.isMarkdownMode;
82
+ const isMarkdownMode = (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : (_apiRef$current2$mark = _apiRef$current2.markdownMode) === null || _apiRef$current2$mark === void 0 ? void 0 : (_apiRef$current2$mark2 = _apiRef$current2$mark.sharedState.currentState()) === null || _apiRef$current2$mark2 === void 0 ? void 0 : _apiRef$current2$mark2.isMarkdownMode;
67
83
  if (isMarkdownMode) {
68
84
  return Promise.resolve([]);
69
85
  }
@@ -90,10 +106,12 @@ export async function extensionProviderToQuickInsertProvider(extensionProvider,
90
106
  lozenge: item.lozenge
91
107
  }),
92
108
  isDisabledOffline: true,
109
+ // This legacy action intentionally mirrors executeExtensionQuickInsertItem,
110
+ // which serves the registered representation of the same item.
93
111
  action: (insert, state, source) => {
94
112
  if (typeof item.node === 'function') {
95
- var _apiRef$current2, _apiRef$current2$exte, _apiRef$current2$exte2;
96
- const extensionAPI = apiRef === null || apiRef === void 0 ? void 0 : (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : (_apiRef$current2$exte = _apiRef$current2.extension) === null || _apiRef$current2$exte === void 0 ? void 0 : (_apiRef$current2$exte2 = _apiRef$current2$exte.actions) === null || _apiRef$current2$exte2 === void 0 ? void 0 : _apiRef$current2$exte2.api();
113
+ var _apiRef$current3, _apiRef$current3$exte, _apiRef$current3$exte2;
114
+ const extensionAPI = apiRef === null || apiRef === void 0 ? void 0 : (_apiRef$current3 = apiRef.current) === null || _apiRef$current3 === void 0 ? void 0 : (_apiRef$current3$exte = _apiRef$current3.extension) === null || _apiRef$current3$exte === void 0 ? void 0 : (_apiRef$current3$exte2 = _apiRef$current3$exte.actions) === null || _apiRef$current3$exte2 === void 0 ? void 0 : _apiRef$current3$exte2.api();
97
115
  // While this should only run when the extension some setups of editor
98
116
  // may not have the extension API
99
117
  if (extensionAPI) {
@@ -106,8 +124,7 @@ export async function extensionProviderToQuickInsertProvider(extensionProvider,
106
124
  } else {
107
125
  // Originally it was understood we could only use this if we were using the extension plugin
108
126
  // However there are some edge cases where this is not true (ie. in jira)
109
- // Since making it optional now would be a breaking change - instead we can just pass a dummy
110
- // extension API to consumers that warns them of using the methods.
127
+ // Since making it optional now would be a breaking change - instead we can just pass a dummy extension API to consumers that warns them of using the methods.
111
128
  resolveImport(item.node(dummyExtensionAPI)).then(node => {
112
129
  sendExtensionQuickInsertAnalytics(item, state.selection, createAnalyticsEvent, source);
113
130
  if (node) {
@@ -1,3 +1,3 @@
1
1
  export const name = "@atlaskit/editor-core";
2
2
  // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
3
- export const version = "223.0.6";
3
+ export const version = "223.1.0";
@@ -469,7 +469,7 @@ export function ReactEditorView(props) {
469
469
  // (purpose 2). When NOT rebuilding, run both — even under the
470
470
  // `cc-markdown-mode` experiment, otherwise no-op preset identity
471
471
  // changes would silently leave a broken plugin/schema mismatch.
472
- if (presetChanged && fg('platform_editor_reconfigure_filter_plugins')) {
472
+ if (presetChanged) {
473
473
  var dropped = [];
474
474
  if (!shouldRebuildSchema) {
475
475
  var _result = filterPluginsForReconfigure(editorPlugins, viewRef.current.state.schema, previousPluginNames);
@@ -39,6 +39,7 @@ import { undoRedoPlugin } from '@atlaskit/editor-plugins/undo-redo';
39
39
  import { unsupportedContentPlugin } from '@atlaskit/editor-plugins/unsupported-content';
40
40
  import { userIntentPlugin } from '@atlaskit/editor-plugins/user-intent';
41
41
  import { widthPlugin } from '@atlaskit/editor-plugins/width';
42
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
42
43
  import { fg } from '@atlaskit/platform-feature-flags';
43
44
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
44
45
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
@@ -70,7 +71,7 @@ export function createDefaultPreset(options) {
70
71
  contextIdentifierProvider: options.contextIdentifierProvider
71
72
  }]).add([basePlugin, options.base]).add(decorationsPlugin).add([typeAheadPlugin, options.typeAhead]).maybeAdd(historyPlugin, Boolean(options.allowUndoRedoButtons)).add(userIntentPlugin).maybeAdd([toolbarPlugin, options.toolbar || {}], Boolean((_options$toolbar = options.toolbar) === null || _options$toolbar === void 0 ? void 0 : _options$toolbar.enableNewToolbarExperience)).add([primaryToolbarPlugin, {
72
73
  contextualFormattingEnabled: isFullPage
73
- }]).maybeAdd(uiControlRegistryPlugin, expValEqualsNoExposure('platform_editor_table_menu_updates', 'isEnabled', true) || expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true) || expValEqualsNoExposure('platform_editor_paste_actions_menu', 'isEnabled', true)).maybeAdd(undoRedoPlugin, Boolean((_options$featureFlags = (_options$featureFlags2 = options.featureFlags) === null || _options$featureFlags2 === void 0 ? void 0 : _options$featureFlags2.undoRedoButtons) !== null && _options$featureFlags !== void 0 ? _options$featureFlags : options.allowUndoRedoButtons)).maybeAdd([blockMenuPlugin, {
74
+ }]).maybeAdd(uiControlRegistryPlugin, expValEqualsNoExposure('platform_editor_table_menu_updates', 'isEnabled', true) || expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true) || expValEqualsNoExposure('platform_editor_paste_actions_menu', 'isEnabled', true) || isExperimentEnabled('platform_editor_slash_command')).maybeAdd(undoRedoPlugin, Boolean((_options$featureFlags = (_options$featureFlags2 = options.featureFlags) === null || _options$featureFlags2 === void 0 ? void 0 : _options$featureFlags2.undoRedoButtons) !== null && _options$featureFlags !== void 0 ? _options$featureFlags : options.allowUndoRedoButtons)).maybeAdd([blockMenuPlugin, {
74
75
  useStandardNodeWidth: (_options$blockMenu$us = (_options$blockMenu = options.blockMenu) === null || _options$blockMenu === void 0 ? void 0 : _options$blockMenu.useStandardNodeWidth) !== null && _options$blockMenu$us !== void 0 ? _options$blockMenu$us : false,
75
76
  blockLinkHashPrefix: (_options$blockMenu2 = options.blockMenu) === null || _options$blockMenu2 === void 0 ? void 0 : _options$blockMenu2.blockLinkHashPrefix,
76
77
  getLinkPath: (_options$blockMenu3 = options.blockMenu) === null || _options$blockMenu3 === void 0 ? void 0 : _options$blockMenu3.getLinkPath
@@ -0,0 +1,78 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import React from 'react';
4
+ import AppsIcon from '@atlaskit/icon/core/apps';
5
+ var lazyExtensionIconCache = new WeakMap();
6
+ var resolveExtensionIcon = /*#__PURE__*/function () {
7
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(getIcon) {
8
+ var maybeIcon, _default, _t;
9
+ return _regeneratorRuntime.wrap(function (_context) {
10
+ while (1) switch (_context.prev = _context.next) {
11
+ case 0:
12
+ _context.prev = 0;
13
+ _context.next = 1;
14
+ return getIcon === null || getIcon === void 0 ? void 0 : getIcon();
15
+ case 1:
16
+ maybeIcon = _context.sent;
17
+ if (maybeIcon) {
18
+ _context.next = 2;
19
+ break;
20
+ }
21
+ return _context.abrupt("return", AppsIcon);
22
+ case 2:
23
+ if (!Object.prototype.hasOwnProperty.call(maybeIcon, 'default')) {
24
+ _context.next = 3;
25
+ break;
26
+ }
27
+ return _context.abrupt("return", (_default = maybeIcon.default) !== null && _default !== void 0 ? _default : AppsIcon);
28
+ case 3:
29
+ return _context.abrupt("return", maybeIcon);
30
+ case 4:
31
+ _context.prev = 4;
32
+ _t = _context["catch"](0);
33
+ return _context.abrupt("return", AppsIcon);
34
+ case 5:
35
+ case "end":
36
+ return _context.stop();
37
+ }
38
+ }, _callee, null, [[0, 4]]);
39
+ }));
40
+ return function resolveExtensionIcon(_x) {
41
+ return _ref.apply(this, arguments);
42
+ };
43
+ }();
44
+ var createLazyExtensionIcon = function createLazyExtensionIcon(getIcon) {
45
+ var cachedIcon = lazyExtensionIconCache.get(getIcon);
46
+ if (cachedIcon) {
47
+ return cachedIcon;
48
+ }
49
+ var LazyIcon = /*#__PURE__*/React.lazy(function () {
50
+ return resolveExtensionIcon(getIcon).then(function (Icon) {
51
+ return {
52
+ default: Icon
53
+ };
54
+ });
55
+ });
56
+ LazyIcon.displayName = 'lazy(ExtensionIcon)';
57
+ var Icon = function Icon(props) {
58
+ return /*#__PURE__*/React.createElement(React.Suspense, {
59
+ fallback: /*#__PURE__*/React.createElement(AppsIcon, {
60
+ label: props.label
61
+ })
62
+ }, /*#__PURE__*/React.createElement(LazyIcon, {
63
+ label: props.label
64
+ }));
65
+ };
66
+ lazyExtensionIconCache.set(getIcon, Icon);
67
+ return Icon;
68
+ };
69
+ export var ExtensionQuickInsertIcon = function ExtensionQuickInsertIcon(_ref2) {
70
+ var getIcon = _ref2.getIcon,
71
+ label = _ref2.label;
72
+ var Icon = React.useMemo(function () {
73
+ return getIcon ? createLazyExtensionIcon(getIcon) : AppsIcon;
74
+ }, [getIcon]);
75
+ return /*#__PURE__*/React.createElement(Icon, {
76
+ label: label
77
+ });
78
+ };
@@ -0,0 +1,39 @@
1
+ import React, { useCallback } from 'react';
2
+ import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
3
+ import { useQuickInsertContext } from '@atlaskit/editor-common/quick-insert/use-quick-insert-context';
4
+ import { executeExtensionQuickInsertItem } from './executeExtensionQuickInsertItem';
5
+ import { ExtensionQuickInsertIcon } from './ExtensionQuickInsertIcon';
6
+ export var ExtensionQuickInsertMenuItem = function ExtensionQuickInsertMenuItem(_ref) {
7
+ var apiRef = _ref.apiRef,
8
+ createAnalyticsEvent = _ref.createAnalyticsEvent,
9
+ item = _ref.item,
10
+ onInsert = _ref.onInsert;
11
+ var _useQuickInsertContex = useQuickInsertContext(),
12
+ editorView = _useQuickInsertContex.editorView,
13
+ isOffline = _useQuickInsertContex.isOffline;
14
+ var onSelect = useCallback(function (_ref2) {
15
+ var insert = _ref2.insert,
16
+ source = _ref2.source;
17
+ var result = executeExtensionQuickInsertItem({
18
+ apiRef: apiRef,
19
+ createAnalyticsEvent: createAnalyticsEvent,
20
+ insert: insert,
21
+ item: item,
22
+ source: source,
23
+ state: editorView.state
24
+ });
25
+ if (result) {
26
+ onInsert === null || onInsert === void 0 || onInsert();
27
+ }
28
+ return result;
29
+ }, [apiRef, createAnalyticsEvent, editorView.state, item, onInsert]);
30
+ return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
31
+ iconBefore: /*#__PURE__*/React.createElement(ExtensionQuickInsertIcon, {
32
+ getIcon: item.icon,
33
+ label: ""
34
+ }),
35
+ isDisabled: isOffline,
36
+ onSelect: onSelect,
37
+ title: item.title
38
+ });
39
+ };
@@ -0,0 +1,91 @@
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 { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, fireAnalyticsEvent, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
+ import { resolveImport } from '@atlaskit/editor-common/extensions';
6
+ import { safeInsert } from '@atlaskit/editor-common/insert';
7
+ import { logException } from '@atlaskit/editor-common/monitoring';
8
+ import { processRawValue } from '@atlaskit/editor-common/process-raw-value';
9
+ import { findInsertLocation } from '@atlaskit/editor-common/utils/analytics';
10
+ var sendAnalytics = function sendAnalytics(item, selection, createAnalyticsEvent, source) {
11
+ if (createAnalyticsEvent) {
12
+ var insertLocation = findInsertLocation(selection);
13
+ fireAnalyticsEvent(createAnalyticsEvent)({
14
+ payload: {
15
+ action: ACTION.INSERTED,
16
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
17
+ actionSubjectId: ACTION_SUBJECT_ID.EXTENSION,
18
+ attributes: _objectSpread({
19
+ extensionType: item.extensionType,
20
+ extensionKey: item.extensionKey,
21
+ key: item.key,
22
+ inputMethod: source || INPUT_METHOD.QUICK_INSERT
23
+ }, insertLocation ? {
24
+ insertLocation: insertLocation
25
+ } : {}),
26
+ eventType: EVENT_TYPE.TRACK
27
+ }
28
+ });
29
+ }
30
+ };
31
+ var warnDummyAPI = function warnDummyAPI(location) {
32
+ if (process.env.NODE_ENV !== 'production') {
33
+ // eslint-disable-next-line no-console
34
+ console.warn('Extension plugin not attached to editor - cannot use extension API in ' + location);
35
+ }
36
+ };
37
+ var dummyExtensionAPI = {
38
+ editInContextPanel: function editInContextPanel() {
39
+ return warnDummyAPI('editInContextPanel');
40
+ },
41
+ _editInLegacyMacroBrowser: function _editInLegacyMacroBrowser() {
42
+ return warnDummyAPI('_editInLegacyMacroBrowser');
43
+ },
44
+ getNodeWithPosByLocalId: function getNodeWithPosByLocalId() {
45
+ return {
46
+ node: null,
47
+ pos: null
48
+ };
49
+ },
50
+ doc: {
51
+ insertAfter: function insertAfter() {
52
+ return warnDummyAPI('doc:insertAfter');
53
+ },
54
+ scrollTo: function scrollTo() {
55
+ return warnDummyAPI('doc:scrollTo');
56
+ },
57
+ update: function update() {
58
+ return warnDummyAPI('doc:update');
59
+ }
60
+ }
61
+ };
62
+ export var executeExtensionQuickInsertItem = function executeExtensionQuickInsertItem(_ref) {
63
+ var apiRef = _ref.apiRef,
64
+ createAnalyticsEvent = _ref.createAnalyticsEvent,
65
+ insert = _ref.insert,
66
+ item = _ref.item,
67
+ source = _ref.source,
68
+ state = _ref.state;
69
+ if (typeof item.node === 'function') {
70
+ var _apiRef$current$exten, _apiRef$current;
71
+ var extensionAPI = (_apiRef$current$exten = (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 || (_apiRef$current = _apiRef$current.extension) === null || _apiRef$current === void 0 || (_apiRef$current = _apiRef$current.actions) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.api()) !== null && _apiRef$current$exten !== void 0 ? _apiRef$current$exten : dummyExtensionAPI;
72
+ void resolveImport(item.node(extensionAPI)).then(function (node) {
73
+ sendAnalytics(item, state.selection, createAnalyticsEvent, source);
74
+ if (node && apiRef.current) {
75
+ apiRef.current.core.actions.execute(function (_ref2) {
76
+ var _safeInsert$scrollInt, _safeInsert;
77
+ var tr = _ref2.tr;
78
+ var content = processRawValue(tr.doc.type.schema, node);
79
+ return content ? (_safeInsert$scrollInt = (_safeInsert = safeInsert(content)(tr)) === null || _safeInsert === void 0 ? void 0 : _safeInsert.scrollIntoView()) !== null && _safeInsert$scrollInt !== void 0 ? _safeInsert$scrollInt : null : null;
80
+ });
81
+ }
82
+ }).catch(function (error) {
83
+ return logException(error, {
84
+ location: 'editor-core/quick-insert'
85
+ });
86
+ });
87
+ return insert('');
88
+ }
89
+ sendAnalytics(item, state.selection, createAnalyticsEvent, source);
90
+ return insert(item.node);
91
+ };
@@ -0,0 +1,37 @@
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 { EXTENSION_ITEM_RANK } from '@atlaskit/editor-common/quick-insert/rank';
5
+ import { ExtensionQuickInsertMenuItem } from './ExtensionQuickInsertMenuItem';
6
+ export var getExtensionQuickInsertComponents = function getExtensionQuickInsertComponents(_ref) {
7
+ var apiRef = _ref.apiRef,
8
+ createAnalyticsEvent = _ref.createAnalyticsEvent,
9
+ items = _ref.items;
10
+ return items.map(function (item, index) {
11
+ var _item$priority;
12
+ return {
13
+ type: 'menu-item',
14
+ key: item.key,
15
+ parents: getQuickInsertMenuItemParents({
16
+ categories: item.categories,
17
+ rank: EXTENSION_ITEM_RANK + ((_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index)
18
+ }),
19
+ match: createQuickInsertMatcher(function () {
20
+ return {
21
+ description: item.description,
22
+ keywords: item.keywords,
23
+ title: item.title
24
+ };
25
+ }),
26
+ component: function component(props) {
27
+ var onInsert = typeof props.onInsert === 'function' ? props.onInsert : undefined;
28
+ return /*#__PURE__*/React.createElement(ExtensionQuickInsertMenuItem, {
29
+ apiRef: apiRef,
30
+ createAnalyticsEvent: createAnalyticsEvent,
31
+ item: item,
32
+ onInsert: onInsert
33
+ });
34
+ }
35
+ };
36
+ });
37
+ };
@@ -1,8 +1,12 @@
1
1
  import { combineProviders } from '@atlaskit/editor-common/provider-helpers';
2
2
  export function combineQuickInsertProviders(quickInsertProviders) {
3
3
  var _combineProviders = combineProviders(quickInsertProviders),
4
- invokeList = _combineProviders.invokeList;
4
+ invokeList = _combineProviders.invokeList,
5
+ invokeOptionalList = _combineProviders.invokeOptionalList;
5
6
  return {
7
+ getComponents: function getComponents() {
8
+ return invokeOptionalList('getComponents');
9
+ },
6
10
  getItems: function getItems() {
7
11
  return invokeList('getItems');
8
12
  }
@@ -8,6 +8,8 @@ import Loadable from 'react-loadable';
8
8
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, fireAnalyticsEvent, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
9
9
  import { getQuickInsertItemsFromModule, resolveImport } from '@atlaskit/editor-common/extensions';
10
10
  import { findInsertLocation } from '@atlaskit/editor-common/utils/analytics';
11
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
12
+ import { getExtensionQuickInsertComponents } from '../ui/quick-insert/getExtensionQuickInsertComponents';
11
13
 
12
14
  // Structural shape of the markdown-mode plugin's slice of the injection API.
13
15
  // Used to read `isMarkdownMode` without importing the `MarkdownModePlugin`
@@ -15,7 +17,7 @@ import { findInsertLocation } from '@atlaskit/editor-common/utils/analytics';
15
17
  // dependency graph and force every consuming product to rebuild.
16
18
 
17
19
  /**
18
- * Utils to send analytics event when a extension is inserted using quickInsert
20
+ * Utils to send analytics event when an extension is inserted using quickInsert
19
21
  */
20
22
  function sendExtensionQuickInsertAnalytics(item, selection, createAnalyticsEvent, source) {
21
23
  if (createAnalyticsEvent) {
@@ -29,7 +31,6 @@ function sendExtensionQuickInsertAnalytics(item, selection, createAnalyticsEvent
29
31
  extensionType: item.extensionType,
30
32
  extensionKey: item.extensionKey,
31
33
  key: item.key,
32
- // @note inputMethod defaults to QUICK_INSERT if not provided
33
34
  inputMethod: source || INPUT_METHOD.QUICK_INSERT
34
35
  }, insertLocation ? {
35
36
  insertLocation: insertLocation
@@ -70,12 +71,14 @@ var dummyExtensionAPI = {
70
71
  }
71
72
  }
72
73
  };
74
+
75
+ /** Creates legacy and registered Quick Insert representations for extensions. */
73
76
  export function extensionProviderToQuickInsertProvider(_x, _x2, _x3, _x4) {
74
77
  return _extensionProviderToQuickInsertProvider.apply(this, arguments);
75
78
  }
76
79
  function _extensionProviderToQuickInsertProvider() {
77
80
  _extensionProviderToQuickInsertProvider = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(extensionProvider, editorActions, apiRef, createAnalyticsEvent) {
78
- var extensions;
81
+ var extensions, getMenuItems;
79
82
  return _regeneratorRuntime.wrap(function (_context) {
80
83
  while (1) switch (_context.prev = _context.next) {
81
84
  case 0:
@@ -83,14 +86,31 @@ function _extensionProviderToQuickInsertProvider() {
83
86
  return extensionProvider.getExtensions();
84
87
  case 1:
85
88
  extensions = _context.sent;
89
+ getMenuItems = function getMenuItems() {
90
+ return getQuickInsertItemsFromModule(extensions, function (item) {
91
+ return item;
92
+ });
93
+ };
86
94
  return _context.abrupt("return", {
87
- getItems: function getItems() {
95
+ getComponents: function getComponents() {
88
96
  var _apiRef$current;
97
+ var isMarkdownMode = (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 || (_apiRef$current = _apiRef$current.markdownMode) === null || _apiRef$current === void 0 || (_apiRef$current = _apiRef$current.sharedState.currentState()) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.isMarkdownMode;
98
+ if (!isExperimentEnabled('platform_editor_slash_command') || isMarkdownMode) {
99
+ return Promise.resolve([]);
100
+ }
101
+ return Promise.resolve(getExtensionQuickInsertComponents({
102
+ apiRef: apiRef,
103
+ createAnalyticsEvent: createAnalyticsEvent,
104
+ items: getMenuItems()
105
+ }));
106
+ },
107
+ getItems: function getItems() {
108
+ var _apiRef$current2;
89
109
  // `extensionProvider` is supplied independently of the preset, so
90
110
  // suppress its items in markdown mode where rich-only content cannot
91
111
  // be inserted. See `MarkdownModeReader` above for why this is read
92
112
  // via a structural cast rather than the typed plugin API.
93
- var isMarkdownMode = (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 || (_apiRef$current = _apiRef$current.markdownMode) === null || _apiRef$current === void 0 || (_apiRef$current = _apiRef$current.sharedState.currentState()) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.isMarkdownMode;
113
+ var isMarkdownMode = (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 || (_apiRef$current2 = _apiRef$current2.markdownMode) === null || _apiRef$current2 === void 0 || (_apiRef$current2 = _apiRef$current2.sharedState.currentState()) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.isMarkdownMode;
94
114
  if (isMarkdownMode) {
95
115
  return Promise.resolve([]);
96
116
  }
@@ -121,10 +141,12 @@ function _extensionProviderToQuickInsertProvider() {
121
141
  lozenge: item.lozenge
122
142
  }), {}, {
123
143
  isDisabledOffline: true,
144
+ // This legacy action intentionally mirrors executeExtensionQuickInsertItem,
145
+ // which serves the registered representation of the same item.
124
146
  action: function action(insert, state, source) {
125
147
  if (typeof item.node === 'function') {
126
- var _apiRef$current2;
127
- var extensionAPI = apiRef === null || apiRef === void 0 || (_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 || (_apiRef$current2 = _apiRef$current2.extension) === null || _apiRef$current2 === void 0 || (_apiRef$current2 = _apiRef$current2.actions) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.api();
148
+ var _apiRef$current3;
149
+ var extensionAPI = apiRef === null || apiRef === void 0 || (_apiRef$current3 = apiRef.current) === null || _apiRef$current3 === void 0 || (_apiRef$current3 = _apiRef$current3.extension) === null || _apiRef$current3 === void 0 || (_apiRef$current3 = _apiRef$current3.actions) === null || _apiRef$current3 === void 0 ? void 0 : _apiRef$current3.api();
128
150
  // While this should only run when the extension some setups of editor
129
151
  // may not have the extension API
130
152
  if (extensionAPI) {
@@ -137,8 +159,7 @@ function _extensionProviderToQuickInsertProvider() {
137
159
  } else {
138
160
  // Originally it was understood we could only use this if we were using the extension plugin
139
161
  // However there are some edge cases where this is not true (ie. in jira)
140
- // Since making it optional now would be a breaking change - instead we can just pass a dummy
141
- // extension API to consumers that warns them of using the methods.
162
+ // Since making it optional now would be a breaking change - instead we can just pass a dummy extension API to consumers that warns them of using the methods.
142
163
  resolveImport(item.node(dummyExtensionAPI)).then(function (node) {
143
164
  sendExtensionQuickInsertAnalytics(item, state.selection, createAnalyticsEvent, source);
144
165
  if (node) {
@@ -1,3 +1,3 @@
1
1
  export var name = "@atlaskit/editor-core";
2
2
  // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
3
- export var version = "223.0.6";
3
+ export var version = "223.1.0";
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { MenuItem } from '@atlaskit/editor-common/extensions';
3
+ export declare const ExtensionQuickInsertIcon: ({ getIcon, label, }: {
4
+ getIcon?: MenuItem['icon'];
5
+ label: string;
6
+ }) => React.JSX.Element;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next/types';
3
+ import type { MenuItem } from '@atlaskit/editor-common/extensions';
4
+ import type { PublicPluginAPI } from '@atlaskit/editor-common/types';
5
+ import type { ExtensionPlugin } from '@atlaskit/editor-plugins/extension';
6
+ export declare const ExtensionQuickInsertMenuItem: ({ apiRef, createAnalyticsEvent, item, onInsert, }: {
7
+ apiRef: React.MutableRefObject<PublicPluginAPI<[ExtensionPlugin]> | undefined>;
8
+ createAnalyticsEvent?: CreateUIAnalyticsEvent;
9
+ item: MenuItem;
10
+ onInsert?: () => void;
11
+ }) => React.JSX.Element;