@atlaskit/editor-plugin-loom
Version:
Loom plugin for @atlaskit/editor-core
94 lines (92 loc) • 3.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.loomPlugin = void 0;
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
var _commands = require("./pm-plugins/commands");
var _main = require("./pm-plugins/main");
var _PrimaryToolbarButton = require("./ui/PrimaryToolbarButton");
var _quickInsert = require("./ui/quickInsert");
var _toolbarComponents = require("./ui/toolbar-components");
var loomPlugin = exports.loomPlugin = function loomPlugin(_ref) {
var _api$analytics;
var config = _ref.config,
api = _ref.api;
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
var isNewToolbarEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
// Workaround since we want to insert a loom via the `hyperlink` plugin for now.
// The hyperlink plugin (and the card plugin) are deeply tied into using the Prosemirror Command
// Ideally one day we refactor those and we can remove this.
var editorViewRef = {
current: null
};
var primaryToolbarComponent = (0, _PrimaryToolbarButton.loomPrimaryToolbarComponent)(config, api);
if (isNewToolbarEnabled) {
var _api$toolbar;
api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getToolbarComponents)(config, api));
} else {
var _api$primaryToolbar;
api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
name: 'loom',
component: primaryToolbarComponent
});
}
return {
name: 'loom',
actions: {
recordVideo: _commands.recordVideo,
insertLoom: function insertLoom(video, positionType) {
return (0, _commands.insertLoom)(editorViewRef.current, api, video, positionType);
},
initLoom: function initLoom(_ref2) {
var loomProvider = _ref2.loomProvider;
return (0, _commands.setupLoom)(loomProvider, api, editorViewRef.current, true);
}
},
pmPlugins: function pmPlugins() {
return [{
name: 'loom',
plugin: function plugin() {
return (0, _main.createPlugin)({
config: config,
api: api
});
}
}, {
name: 'loomViewRefWorkaround',
plugin: function plugin() {
return new _safePlugin.SafePlugin({
view: function view(editorView) {
// Do not cleanup the editorViewRef on destroy
// because some functions may point to a stale
// reference and this means we will return null.
// EditorView is assumed to be stable so we do not need to
// cleanup.
// See: #hot-106316
editorViewRef.current = editorView;
return {};
}
});
}
}];
},
getSharedState: function getSharedState(editorState) {
if (!editorState) {
return;
}
return _main.loomPluginKey.getState(editorState);
},
pluginsOptions: {
// Enable inserting Loom recordings through the slash command
quickInsert: function quickInsert(intl) {
if (config.loomProvider) {
return (0, _quickInsert.getQuickInsertItem)(editorAnalyticsAPI)(intl);
}
return [];
}
},
// Enable inserting Loom recordings through main toolbar
primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && !isNewToolbarEnabled ? primaryToolbarComponent : undefined
};
};