@atlaskit/editor-core 223.0.7 → 223.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 +27 -0
- package/dist/cjs/create-editor/ReactEditorView.js +1 -1
- package/dist/cjs/presets/default.js +2 -1
- package/dist/cjs/ui/quick-insert/ExtensionQuickInsertIcon.js +85 -0
- package/dist/cjs/ui/quick-insert/ExtensionQuickInsertMenuItem.js +47 -0
- package/dist/cjs/ui/quick-insert/executeExtensionQuickInsertItem.js +98 -0
- package/dist/cjs/ui/quick-insert/getExtensionQuickInsertComponents.js +36 -0
- package/dist/cjs/utils/combineQuickInsertProviders.js +5 -1
- package/dist/cjs/utils/extensions.js +30 -9
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/create-editor/ReactEditorView.js +1 -1
- package/dist/es2019/presets/default.js +2 -1
- package/dist/es2019/ui/quick-insert/ExtensionQuickInsertIcon.js +46 -0
- package/dist/es2019/ui/quick-insert/ExtensionQuickInsertMenuItem.js +42 -0
- package/dist/es2019/ui/quick-insert/executeExtensionQuickInsertItem.js +77 -0
- package/dist/es2019/ui/quick-insert/getExtensionQuickInsertComponents.js +28 -0
- package/dist/es2019/utils/combineQuickInsertProviders.js +5 -1
- package/dist/es2019/utils/extensions.js +25 -8
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/create-editor/ReactEditorView.js +1 -1
- package/dist/esm/presets/default.js +2 -1
- package/dist/esm/ui/quick-insert/ExtensionQuickInsertIcon.js +78 -0
- package/dist/esm/ui/quick-insert/ExtensionQuickInsertMenuItem.js +39 -0
- package/dist/esm/ui/quick-insert/executeExtensionQuickInsertItem.js +91 -0
- package/dist/esm/ui/quick-insert/getExtensionQuickInsertComponents.js +29 -0
- package/dist/esm/utils/combineQuickInsertProviders.js +5 -1
- package/dist/esm/utils/extensions.js +30 -9
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/ui/quick-insert/ExtensionQuickInsertIcon.d.ts +6 -0
- package/dist/types/ui/quick-insert/ExtensionQuickInsertMenuItem.d.ts +11 -0
- package/dist/types/ui/quick-insert/executeExtensionQuickInsertItem.d.ts +16 -0
- package/dist/types/ui/quick-insert/getExtensionQuickInsertComponents.d.ts +11 -0
- package/dist/types/utils/extensions.d.ts +1 -0
- package/package.json +3 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @atlaskit/editor-core
|
|
2
2
|
|
|
3
|
+
## 223.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
|
+
- [`22be41a95d07e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/22be41a95d07e) -
|
|
25
|
+
Clean up feature gate `platform_editor_reconfigure_filter_plugins`. On preset reconfiguration,
|
|
26
|
+
plugins whose nodes/marks the current schema lacks are always filtered out, and stale plugin APIs
|
|
27
|
+
are always evicted from the plugin injection API.
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
|
|
3
30
|
## 223.0.7
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
|
@@ -478,7 +478,7 @@ function ReactEditorView(props) {
|
|
|
478
478
|
// (purpose 2). When NOT rebuilding, run both — even under the
|
|
479
479
|
// `cc-markdown-mode` experiment, otherwise no-op preset identity
|
|
480
480
|
// changes would silently leave a broken plugin/schema mismatch.
|
|
481
|
-
if (presetChanged
|
|
481
|
+
if (presetChanged) {
|
|
482
482
|
var dropped = [];
|
|
483
483
|
if (!shouldRebuildSchema) {
|
|
484
484
|
var _result = (0, _filterPluginsForReconfigure.filterPluginsForReconfigure)(editorPlugins, viewRef.current.state.schema, previousPluginNames);
|
|
@@ -43,6 +43,7 @@ var _undoRedo = require("@atlaskit/editor-plugins/undo-redo");
|
|
|
43
43
|
var _unsupportedContent = require("@atlaskit/editor-plugins/unsupported-content");
|
|
44
44
|
var _userIntent = require("@atlaskit/editor-plugins/user-intent");
|
|
45
45
|
var _width = require("@atlaskit/editor-plugins/width");
|
|
46
|
+
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
46
47
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
47
48
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
48
49
|
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
@@ -75,7 +76,7 @@ function createDefaultPreset(options) {
|
|
|
75
76
|
contextIdentifierProvider: options.contextIdentifierProvider
|
|
76
77
|
}]).add([_base.basePlugin, options.base]).add(_decorations.decorationsPlugin).add([_typeAhead.typeAheadPlugin, options.typeAhead]).maybeAdd(_history.historyPlugin, Boolean(options.allowUndoRedoButtons)).add(_userIntent.userIntentPlugin).maybeAdd([_toolbar.toolbarPlugin, options.toolbar || {}], Boolean((_options$toolbar = options.toolbar) === null || _options$toolbar === void 0 ? void 0 : _options$toolbar.enableNewToolbarExperience)).add([_primaryToolbar.primaryToolbarPlugin, {
|
|
77
78
|
contextualFormattingEnabled: isFullPage
|
|
78
|
-
}]).maybeAdd(_uiControlRegistry.uiControlRegistryPlugin, (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_table_menu_updates', 'isEnabled', true) || (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true) || (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_paste_actions_menu', 'isEnabled', true)).maybeAdd(_undoRedo.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([_blockMenu.blockMenuPlugin, {
|
|
79
|
+
}]).maybeAdd(_uiControlRegistry.uiControlRegistryPlugin, (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_table_menu_updates', 'isEnabled', true) || (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true) || (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_paste_actions_menu', 'isEnabled', true) || (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_slash_command')).maybeAdd(_undoRedo.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([_blockMenu.blockMenuPlugin, {
|
|
79
80
|
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,
|
|
80
81
|
blockLinkHashPrefix: (_options$blockMenu2 = options.blockMenu) === null || _options$blockMenu2 === void 0 ? void 0 : _options$blockMenu2.blockLinkHashPrefix,
|
|
81
82
|
getLinkPath: (_options$blockMenu3 = options.blockMenu) === null || _options$blockMenu3 === void 0 ? void 0 : _options$blockMenu3.getLinkPath
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ExtensionQuickInsertIcon = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
var _apps = _interopRequireDefault(require("@atlaskit/icon/core/apps"));
|
|
12
|
+
var lazyExtensionIconCache = new WeakMap();
|
|
13
|
+
var resolveExtensionIcon = /*#__PURE__*/function () {
|
|
14
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(getIcon) {
|
|
15
|
+
var maybeIcon, _default, _t;
|
|
16
|
+
return _regenerator.default.wrap(function (_context) {
|
|
17
|
+
while (1) switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
_context.prev = 0;
|
|
20
|
+
_context.next = 1;
|
|
21
|
+
return getIcon === null || getIcon === void 0 ? void 0 : getIcon();
|
|
22
|
+
case 1:
|
|
23
|
+
maybeIcon = _context.sent;
|
|
24
|
+
if (maybeIcon) {
|
|
25
|
+
_context.next = 2;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
return _context.abrupt("return", _apps.default);
|
|
29
|
+
case 2:
|
|
30
|
+
if (!Object.prototype.hasOwnProperty.call(maybeIcon, 'default')) {
|
|
31
|
+
_context.next = 3;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
return _context.abrupt("return", (_default = maybeIcon.default) !== null && _default !== void 0 ? _default : _apps.default);
|
|
35
|
+
case 3:
|
|
36
|
+
return _context.abrupt("return", maybeIcon);
|
|
37
|
+
case 4:
|
|
38
|
+
_context.prev = 4;
|
|
39
|
+
_t = _context["catch"](0);
|
|
40
|
+
return _context.abrupt("return", _apps.default);
|
|
41
|
+
case 5:
|
|
42
|
+
case "end":
|
|
43
|
+
return _context.stop();
|
|
44
|
+
}
|
|
45
|
+
}, _callee, null, [[0, 4]]);
|
|
46
|
+
}));
|
|
47
|
+
return function resolveExtensionIcon(_x) {
|
|
48
|
+
return _ref.apply(this, arguments);
|
|
49
|
+
};
|
|
50
|
+
}();
|
|
51
|
+
var createLazyExtensionIcon = function createLazyExtensionIcon(getIcon) {
|
|
52
|
+
var cachedIcon = lazyExtensionIconCache.get(getIcon);
|
|
53
|
+
if (cachedIcon) {
|
|
54
|
+
return cachedIcon;
|
|
55
|
+
}
|
|
56
|
+
var LazyIcon = /*#__PURE__*/_react.default.lazy(function () {
|
|
57
|
+
return resolveExtensionIcon(getIcon).then(function (Icon) {
|
|
58
|
+
return {
|
|
59
|
+
default: Icon
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
LazyIcon.displayName = 'lazy(ExtensionIcon)';
|
|
64
|
+
var Icon = function Icon(props) {
|
|
65
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Suspense, {
|
|
66
|
+
fallback: /*#__PURE__*/_react.default.createElement(_apps.default, {
|
|
67
|
+
label: props.label
|
|
68
|
+
})
|
|
69
|
+
}, /*#__PURE__*/_react.default.createElement(LazyIcon, {
|
|
70
|
+
label: props.label
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
lazyExtensionIconCache.set(getIcon, Icon);
|
|
74
|
+
return Icon;
|
|
75
|
+
};
|
|
76
|
+
var ExtensionQuickInsertIcon = exports.ExtensionQuickInsertIcon = function ExtensionQuickInsertIcon(_ref2) {
|
|
77
|
+
var getIcon = _ref2.getIcon,
|
|
78
|
+
label = _ref2.label;
|
|
79
|
+
var Icon = _react.default.useMemo(function () {
|
|
80
|
+
return getIcon ? createLazyExtensionIcon(getIcon) : _apps.default;
|
|
81
|
+
}, [getIcon]);
|
|
82
|
+
return /*#__PURE__*/_react.default.createElement(Icon, {
|
|
83
|
+
label: label
|
|
84
|
+
});
|
|
85
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ExtensionQuickInsertMenuItem = void 0;
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _menuItem = require("@atlaskit/editor-common/quick-insert/menu-item");
|
|
10
|
+
var _useQuickInsertContext = require("@atlaskit/editor-common/quick-insert/use-quick-insert-context");
|
|
11
|
+
var _executeExtensionQuickInsertItem = require("./executeExtensionQuickInsertItem");
|
|
12
|
+
var _ExtensionQuickInsertIcon = require("./ExtensionQuickInsertIcon");
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
14
|
+
var ExtensionQuickInsertMenuItem = exports.ExtensionQuickInsertMenuItem = function ExtensionQuickInsertMenuItem(_ref) {
|
|
15
|
+
var apiRef = _ref.apiRef,
|
|
16
|
+
createAnalyticsEvent = _ref.createAnalyticsEvent,
|
|
17
|
+
item = _ref.item,
|
|
18
|
+
onInsert = _ref.onInsert;
|
|
19
|
+
var _useQuickInsertContex = (0, _useQuickInsertContext.useQuickInsertContext)(),
|
|
20
|
+
editorView = _useQuickInsertContex.editorView,
|
|
21
|
+
isOffline = _useQuickInsertContex.isOffline;
|
|
22
|
+
var onSelect = (0, _react.useCallback)(function (_ref2) {
|
|
23
|
+
var insert = _ref2.insert,
|
|
24
|
+
source = _ref2.source;
|
|
25
|
+
var result = (0, _executeExtensionQuickInsertItem.executeExtensionQuickInsertItem)({
|
|
26
|
+
apiRef: apiRef,
|
|
27
|
+
createAnalyticsEvent: createAnalyticsEvent,
|
|
28
|
+
insert: insert,
|
|
29
|
+
item: item,
|
|
30
|
+
source: source,
|
|
31
|
+
state: editorView.state
|
|
32
|
+
});
|
|
33
|
+
if (result) {
|
|
34
|
+
onInsert === null || onInsert === void 0 || onInsert();
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}, [apiRef, createAnalyticsEvent, editorView.state, item, onInsert]);
|
|
38
|
+
return /*#__PURE__*/_react.default.createElement(_menuItem.QuickInsertMenuItem, {
|
|
39
|
+
iconBefore: /*#__PURE__*/_react.default.createElement(_ExtensionQuickInsertIcon.ExtensionQuickInsertIcon, {
|
|
40
|
+
getIcon: item.icon,
|
|
41
|
+
label: ""
|
|
42
|
+
}),
|
|
43
|
+
isDisabled: isOffline,
|
|
44
|
+
onSelect: onSelect,
|
|
45
|
+
title: item.title
|
|
46
|
+
});
|
|
47
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.executeExtensionQuickInsertItem = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _extensions = require("@atlaskit/editor-common/extensions");
|
|
11
|
+
var _insert = require("@atlaskit/editor-common/insert");
|
|
12
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
13
|
+
var _processRawValue = require("@atlaskit/editor-common/process-raw-value");
|
|
14
|
+
var _analytics2 = require("@atlaskit/editor-common/utils/analytics");
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
var sendAnalytics = function sendAnalytics(item, selection, createAnalyticsEvent, source) {
|
|
18
|
+
if (createAnalyticsEvent) {
|
|
19
|
+
var insertLocation = (0, _analytics2.findInsertLocation)(selection);
|
|
20
|
+
(0, _analytics.fireAnalyticsEvent)(createAnalyticsEvent)({
|
|
21
|
+
payload: {
|
|
22
|
+
action: _analytics.ACTION.INSERTED,
|
|
23
|
+
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
24
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.EXTENSION,
|
|
25
|
+
attributes: _objectSpread({
|
|
26
|
+
extensionType: item.extensionType,
|
|
27
|
+
extensionKey: item.extensionKey,
|
|
28
|
+
key: item.key,
|
|
29
|
+
inputMethod: source || _analytics.INPUT_METHOD.QUICK_INSERT
|
|
30
|
+
}, insertLocation ? {
|
|
31
|
+
insertLocation: insertLocation
|
|
32
|
+
} : {}),
|
|
33
|
+
eventType: _analytics.EVENT_TYPE.TRACK
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var warnDummyAPI = function warnDummyAPI(location) {
|
|
39
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
console.warn('Extension plugin not attached to editor - cannot use extension API in ' + location);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var dummyExtensionAPI = {
|
|
45
|
+
editInContextPanel: function editInContextPanel() {
|
|
46
|
+
return warnDummyAPI('editInContextPanel');
|
|
47
|
+
},
|
|
48
|
+
_editInLegacyMacroBrowser: function _editInLegacyMacroBrowser() {
|
|
49
|
+
return warnDummyAPI('_editInLegacyMacroBrowser');
|
|
50
|
+
},
|
|
51
|
+
getNodeWithPosByLocalId: function getNodeWithPosByLocalId() {
|
|
52
|
+
return {
|
|
53
|
+
node: null,
|
|
54
|
+
pos: null
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
doc: {
|
|
58
|
+
insertAfter: function insertAfter() {
|
|
59
|
+
return warnDummyAPI('doc:insertAfter');
|
|
60
|
+
},
|
|
61
|
+
scrollTo: function scrollTo() {
|
|
62
|
+
return warnDummyAPI('doc:scrollTo');
|
|
63
|
+
},
|
|
64
|
+
update: function update() {
|
|
65
|
+
return warnDummyAPI('doc:update');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var executeExtensionQuickInsertItem = exports.executeExtensionQuickInsertItem = function executeExtensionQuickInsertItem(_ref) {
|
|
70
|
+
var apiRef = _ref.apiRef,
|
|
71
|
+
createAnalyticsEvent = _ref.createAnalyticsEvent,
|
|
72
|
+
insert = _ref.insert,
|
|
73
|
+
item = _ref.item,
|
|
74
|
+
source = _ref.source,
|
|
75
|
+
state = _ref.state;
|
|
76
|
+
if (typeof item.node === 'function') {
|
|
77
|
+
var _apiRef$current$exten, _apiRef$current;
|
|
78
|
+
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;
|
|
79
|
+
void (0, _extensions.resolveImport)(item.node(extensionAPI)).then(function (node) {
|
|
80
|
+
sendAnalytics(item, state.selection, createAnalyticsEvent, source);
|
|
81
|
+
if (node && apiRef.current) {
|
|
82
|
+
apiRef.current.core.actions.execute(function (_ref2) {
|
|
83
|
+
var _safeInsert$scrollInt, _safeInsert;
|
|
84
|
+
var tr = _ref2.tr;
|
|
85
|
+
var content = (0, _processRawValue.processRawValue)(tr.doc.type.schema, node);
|
|
86
|
+
return content ? (_safeInsert$scrollInt = (_safeInsert = (0, _insert.safeInsert)(content)(tr)) === null || _safeInsert === void 0 ? void 0 : _safeInsert.scrollIntoView()) !== null && _safeInsert$scrollInt !== void 0 ? _safeInsert$scrollInt : null : null;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}).catch(function (error) {
|
|
90
|
+
return (0, _monitoring.logException)(error, {
|
|
91
|
+
location: 'editor-core/quick-insert'
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return insert('');
|
|
95
|
+
}
|
|
96
|
+
sendAnalytics(item, state.selection, createAnalyticsEvent, source);
|
|
97
|
+
return insert(item.node);
|
|
98
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getExtensionQuickInsertComponents = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _getMenuItemParents = require("@atlaskit/editor-common/quick-insert/get-menu-item-parents");
|
|
10
|
+
var _rank = require("@atlaskit/editor-common/quick-insert/rank");
|
|
11
|
+
var _ExtensionQuickInsertMenuItem = require("./ExtensionQuickInsertMenuItem");
|
|
12
|
+
var getExtensionQuickInsertComponents = exports.getExtensionQuickInsertComponents = function getExtensionQuickInsertComponents(_ref) {
|
|
13
|
+
var apiRef = _ref.apiRef,
|
|
14
|
+
createAnalyticsEvent = _ref.createAnalyticsEvent,
|
|
15
|
+
items = _ref.items;
|
|
16
|
+
return items.map(function (item, index) {
|
|
17
|
+
var _item$priority;
|
|
18
|
+
return {
|
|
19
|
+
type: 'menu-item',
|
|
20
|
+
key: item.key,
|
|
21
|
+
parents: (0, _getMenuItemParents.getQuickInsertMenuItemParents)({
|
|
22
|
+
categories: item.categories,
|
|
23
|
+
rank: _rank.EXTENSION_ITEM_RANK + ((_item$priority = item.priority) !== null && _item$priority !== void 0 ? _item$priority : index)
|
|
24
|
+
}),
|
|
25
|
+
component: function component(props) {
|
|
26
|
+
var onInsert = typeof props.onInsert === 'function' ? props.onInsert : undefined;
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement(_ExtensionQuickInsertMenuItem.ExtensionQuickInsertMenuItem, {
|
|
28
|
+
apiRef: apiRef,
|
|
29
|
+
createAnalyticsEvent: createAnalyticsEvent,
|
|
30
|
+
item: item,
|
|
31
|
+
onInsert: onInsert
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -7,8 +7,12 @@ exports.combineQuickInsertProviders = combineQuickInsertProviders;
|
|
|
7
7
|
var _providerHelpers = require("@atlaskit/editor-common/provider-helpers");
|
|
8
8
|
function combineQuickInsertProviders(quickInsertProviders) {
|
|
9
9
|
var _combineProviders = (0, _providerHelpers.combineProviders)(quickInsertProviders),
|
|
10
|
-
invokeList = _combineProviders.invokeList
|
|
10
|
+
invokeList = _combineProviders.invokeList,
|
|
11
|
+
invokeOptionalList = _combineProviders.invokeOptionalList;
|
|
11
12
|
return {
|
|
13
|
+
getComponents: function getComponents() {
|
|
14
|
+
return invokeOptionalList('getComponents');
|
|
15
|
+
},
|
|
12
16
|
getItems: function getItems() {
|
|
13
17
|
return invokeList('getItems');
|
|
14
18
|
}
|
|
@@ -13,6 +13,8 @@ var _reactLoadable = _interopRequireDefault(require("react-loadable"));
|
|
|
13
13
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
14
14
|
var _extensions = require("@atlaskit/editor-common/extensions");
|
|
15
15
|
var _analytics2 = require("@atlaskit/editor-common/utils/analytics");
|
|
16
|
+
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
17
|
+
var _getExtensionQuickInsertComponents = require("../ui/quick-insert/getExtensionQuickInsertComponents");
|
|
16
18
|
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
19
|
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
20
|
// Structural shape of the markdown-mode plugin's slice of the injection API.
|
|
@@ -21,7 +23,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
21
23
|
// dependency graph and force every consuming product to rebuild.
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
|
-
* Utils to send analytics event when
|
|
26
|
+
* Utils to send analytics event when an extension is inserted using quickInsert
|
|
25
27
|
*/
|
|
26
28
|
function sendExtensionQuickInsertAnalytics(item, selection, createAnalyticsEvent, source) {
|
|
27
29
|
if (createAnalyticsEvent) {
|
|
@@ -35,7 +37,6 @@ function sendExtensionQuickInsertAnalytics(item, selection, createAnalyticsEvent
|
|
|
35
37
|
extensionType: item.extensionType,
|
|
36
38
|
extensionKey: item.extensionKey,
|
|
37
39
|
key: item.key,
|
|
38
|
-
// @note inputMethod defaults to QUICK_INSERT if not provided
|
|
39
40
|
inputMethod: source || _analytics.INPUT_METHOD.QUICK_INSERT
|
|
40
41
|
}, insertLocation ? {
|
|
41
42
|
insertLocation: insertLocation
|
|
@@ -76,12 +77,14 @@ var dummyExtensionAPI = {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
};
|
|
80
|
+
|
|
81
|
+
/** Creates legacy and registered Quick Insert representations for extensions. */
|
|
79
82
|
function extensionProviderToQuickInsertProvider(_x, _x2, _x3, _x4) {
|
|
80
83
|
return _extensionProviderToQuickInsertProvider.apply(this, arguments);
|
|
81
84
|
}
|
|
82
85
|
function _extensionProviderToQuickInsertProvider() {
|
|
83
86
|
_extensionProviderToQuickInsertProvider = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(extensionProvider, editorActions, apiRef, createAnalyticsEvent) {
|
|
84
|
-
var extensions;
|
|
87
|
+
var extensions, getMenuItems;
|
|
85
88
|
return _regenerator.default.wrap(function (_context) {
|
|
86
89
|
while (1) switch (_context.prev = _context.next) {
|
|
87
90
|
case 0:
|
|
@@ -89,14 +92,31 @@ function _extensionProviderToQuickInsertProvider() {
|
|
|
89
92
|
return extensionProvider.getExtensions();
|
|
90
93
|
case 1:
|
|
91
94
|
extensions = _context.sent;
|
|
95
|
+
getMenuItems = function getMenuItems() {
|
|
96
|
+
return (0, _extensions.getQuickInsertItemsFromModule)(extensions, function (item) {
|
|
97
|
+
return item;
|
|
98
|
+
});
|
|
99
|
+
};
|
|
92
100
|
return _context.abrupt("return", {
|
|
93
|
-
|
|
101
|
+
getComponents: function getComponents() {
|
|
94
102
|
var _apiRef$current;
|
|
103
|
+
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;
|
|
104
|
+
if (!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_slash_command') || isMarkdownMode) {
|
|
105
|
+
return Promise.resolve([]);
|
|
106
|
+
}
|
|
107
|
+
return Promise.resolve((0, _getExtensionQuickInsertComponents.getExtensionQuickInsertComponents)({
|
|
108
|
+
apiRef: apiRef,
|
|
109
|
+
createAnalyticsEvent: createAnalyticsEvent,
|
|
110
|
+
items: getMenuItems()
|
|
111
|
+
}));
|
|
112
|
+
},
|
|
113
|
+
getItems: function getItems() {
|
|
114
|
+
var _apiRef$current2;
|
|
95
115
|
// `extensionProvider` is supplied independently of the preset, so
|
|
96
116
|
// suppress its items in markdown mode where rich-only content cannot
|
|
97
117
|
// be inserted. See `MarkdownModeReader` above for why this is read
|
|
98
118
|
// via a structural cast rather than the typed plugin API.
|
|
99
|
-
var isMarkdownMode = (_apiRef$
|
|
119
|
+
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;
|
|
100
120
|
if (isMarkdownMode) {
|
|
101
121
|
return Promise.resolve([]);
|
|
102
122
|
}
|
|
@@ -127,10 +147,12 @@ function _extensionProviderToQuickInsertProvider() {
|
|
|
127
147
|
lozenge: item.lozenge
|
|
128
148
|
}), {}, {
|
|
129
149
|
isDisabledOffline: true,
|
|
150
|
+
// This legacy action intentionally mirrors executeExtensionQuickInsertItem,
|
|
151
|
+
// which serves the registered representation of the same item.
|
|
130
152
|
action: function action(insert, state, source) {
|
|
131
153
|
if (typeof item.node === 'function') {
|
|
132
|
-
var _apiRef$
|
|
133
|
-
var extensionAPI = apiRef === null || apiRef === void 0 || (_apiRef$
|
|
154
|
+
var _apiRef$current3;
|
|
155
|
+
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();
|
|
134
156
|
// While this should only run when the extension some setups of editor
|
|
135
157
|
// may not have the extension API
|
|
136
158
|
if (extensionAPI) {
|
|
@@ -143,8 +165,7 @@ function _extensionProviderToQuickInsertProvider() {
|
|
|
143
165
|
} else {
|
|
144
166
|
// Originally it was understood we could only use this if we were using the extension plugin
|
|
145
167
|
// However there are some edge cases where this is not true (ie. in jira)
|
|
146
|
-
// Since making it optional now would be a breaking change - instead we can just pass a dummy
|
|
147
|
-
// extension API to consumers that warns them of using the methods.
|
|
168
|
+
// 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.
|
|
148
169
|
(0, _extensions.resolveImport)(item.node(dummyExtensionAPI)).then(function (node) {
|
|
149
170
|
sendExtensionQuickInsertAnalytics(item, state.selection, createAnalyticsEvent, source);
|
|
150
171
|
if (node) {
|
|
@@ -6,4 +6,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.version = exports.name = void 0;
|
|
7
7
|
var name = exports.name = "@atlaskit/editor-core";
|
|
8
8
|
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
9
|
-
var version = exports.version = "223.0.
|
|
9
|
+
var version = exports.version = "223.0.7";
|
|
@@ -438,7 +438,7 @@ export function ReactEditorView(props) {
|
|
|
438
438
|
// (purpose 2). When NOT rebuilding, run both — even under the
|
|
439
439
|
// `cc-markdown-mode` experiment, otherwise no-op preset identity
|
|
440
440
|
// changes would silently leave a broken plugin/schema mismatch.
|
|
441
|
-
if (presetChanged
|
|
441
|
+
if (presetChanged) {
|
|
442
442
|
let dropped = [];
|
|
443
443
|
if (!shouldRebuildSchema) {
|
|
444
444
|
const result = filterPluginsForReconfigure(editorPlugins, viewRef.current.state.schema, previousPluginNames);
|
|
@@ -36,6 +36,7 @@ import { undoRedoPlugin } from '@atlaskit/editor-plugins/undo-redo';
|
|
|
36
36
|
import { unsupportedContentPlugin } from '@atlaskit/editor-plugins/unsupported-content';
|
|
37
37
|
import { userIntentPlugin } from '@atlaskit/editor-plugins/user-intent';
|
|
38
38
|
import { widthPlugin } from '@atlaskit/editor-plugins/width';
|
|
39
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
39
40
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
40
41
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
41
42
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
@@ -66,7 +67,7 @@ export function createDefaultPreset(options) {
|
|
|
66
67
|
contextIdentifierProvider: options.contextIdentifierProvider
|
|
67
68
|
}]).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, {
|
|
68
69
|
contextualFormattingEnabled: isFullPage
|
|
69
|
-
}]).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, {
|
|
70
|
+
}]).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, {
|
|
70
71
|
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,
|
|
71
72
|
blockLinkHashPrefix: (_options$blockMenu2 = options.blockMenu) === null || _options$blockMenu2 === void 0 ? void 0 : _options$blockMenu2.blockLinkHashPrefix,
|
|
72
73
|
getLinkPath: (_options$blockMenu3 = options.blockMenu) === null || _options$blockMenu3 === void 0 ? void 0 : _options$blockMenu3.getLinkPath
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import AppsIcon from '@atlaskit/icon/core/apps';
|
|
3
|
+
const lazyExtensionIconCache = new WeakMap();
|
|
4
|
+
const resolveExtensionIcon = async getIcon => {
|
|
5
|
+
try {
|
|
6
|
+
const maybeIcon = await (getIcon === null || getIcon === void 0 ? void 0 : getIcon());
|
|
7
|
+
if (!maybeIcon) {
|
|
8
|
+
return AppsIcon;
|
|
9
|
+
}
|
|
10
|
+
if (Object.prototype.hasOwnProperty.call(maybeIcon, 'default')) {
|
|
11
|
+
var _default;
|
|
12
|
+
return (_default = maybeIcon.default) !== null && _default !== void 0 ? _default : AppsIcon;
|
|
13
|
+
}
|
|
14
|
+
return maybeIcon;
|
|
15
|
+
} catch {
|
|
16
|
+
return AppsIcon;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const createLazyExtensionIcon = getIcon => {
|
|
20
|
+
const cachedIcon = lazyExtensionIconCache.get(getIcon);
|
|
21
|
+
if (cachedIcon) {
|
|
22
|
+
return cachedIcon;
|
|
23
|
+
}
|
|
24
|
+
const LazyIcon = /*#__PURE__*/React.lazy(() => resolveExtensionIcon(getIcon).then(Icon => ({
|
|
25
|
+
default: Icon
|
|
26
|
+
})));
|
|
27
|
+
LazyIcon.displayName = 'lazy(ExtensionIcon)';
|
|
28
|
+
const Icon = props => /*#__PURE__*/React.createElement(React.Suspense, {
|
|
29
|
+
fallback: /*#__PURE__*/React.createElement(AppsIcon, {
|
|
30
|
+
label: props.label
|
|
31
|
+
})
|
|
32
|
+
}, /*#__PURE__*/React.createElement(LazyIcon, {
|
|
33
|
+
label: props.label
|
|
34
|
+
}));
|
|
35
|
+
lazyExtensionIconCache.set(getIcon, Icon);
|
|
36
|
+
return Icon;
|
|
37
|
+
};
|
|
38
|
+
export const ExtensionQuickInsertIcon = ({
|
|
39
|
+
getIcon,
|
|
40
|
+
label
|
|
41
|
+
}) => {
|
|
42
|
+
const Icon = React.useMemo(() => getIcon ? createLazyExtensionIcon(getIcon) : AppsIcon, [getIcon]);
|
|
43
|
+
return /*#__PURE__*/React.createElement(Icon, {
|
|
44
|
+
label: label
|
|
45
|
+
});
|
|
46
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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 const ExtensionQuickInsertMenuItem = ({
|
|
7
|
+
apiRef,
|
|
8
|
+
createAnalyticsEvent,
|
|
9
|
+
item,
|
|
10
|
+
onInsert
|
|
11
|
+
}) => {
|
|
12
|
+
const {
|
|
13
|
+
editorView,
|
|
14
|
+
isOffline
|
|
15
|
+
} = useQuickInsertContext();
|
|
16
|
+
const onSelect = useCallback(({
|
|
17
|
+
insert,
|
|
18
|
+
source
|
|
19
|
+
}) => {
|
|
20
|
+
const result = executeExtensionQuickInsertItem({
|
|
21
|
+
apiRef,
|
|
22
|
+
createAnalyticsEvent,
|
|
23
|
+
insert,
|
|
24
|
+
item,
|
|
25
|
+
source,
|
|
26
|
+
state: editorView.state
|
|
27
|
+
});
|
|
28
|
+
if (result) {
|
|
29
|
+
onInsert === null || onInsert === void 0 ? void 0 : onInsert();
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}, [apiRef, createAnalyticsEvent, editorView.state, item, onInsert]);
|
|
33
|
+
return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
|
|
34
|
+
iconBefore: /*#__PURE__*/React.createElement(ExtensionQuickInsertIcon, {
|
|
35
|
+
getIcon: item.icon,
|
|
36
|
+
label: ""
|
|
37
|
+
}),
|
|
38
|
+
isDisabled: isOffline,
|
|
39
|
+
onSelect: onSelect,
|
|
40
|
+
title: item.title
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -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
|
+
};
|