@atlaskit/editor-plugin-context-identifier
Version:
Context identifier plugin for @atlaskit/editor-core
49 lines • 1.94 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
export var pluginKey = new PluginKey('contextIdentiferPlugin');
function updateContextIdentifier(_x, _x2) {
return _updateContextIdentifier.apply(this, arguments);
}
function _updateContextIdentifier() {
_updateContextIdentifier = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(config, api) {
var _api$core, _api$contextIdentifie;
var provider;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return config.contextIdentifierProvider;
case 2:
provider = _context.sent;
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$contextIdentifie = api.contextIdentifier) === null || _api$contextIdentifie === void 0 ? void 0 : _api$contextIdentifie.commands.setProvider({
contextIdentifierProvider: provider
}));
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
return _updateContextIdentifier.apply(this, arguments);
}
export var createPlugin = function createPlugin(initialConfig, api) {
return function () {
if (initialConfig) {
updateContextIdentifier(initialConfig, api);
}
return new SafePlugin({
key: pluginKey,
state: {
init: function init() {
return initialConfig;
},
apply: function apply(tr, pluginState) {
var meta = tr.getMeta(pluginKey);
return meta ? meta : pluginState;
}
}
});
};
};