UNPKG

@atlaskit/editor-plugin-context-identifier

Version:

Context identifier plugin for @atlaskit/editor-core

56 lines (55 loc) 2.27 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.pluginKey = exports.createPlugin = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _safePlugin = require("@atlaskit/editor-common/safe-plugin"); var _state = require("@atlaskit/editor-prosemirror/state"); var pluginKey = exports.pluginKey = new _state.PluginKey('contextIdentiferPlugin'); function updateContextIdentifier(_x, _x2) { return _updateContextIdentifier.apply(this, arguments); } function _updateContextIdentifier() { _updateContextIdentifier = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(config, api) { var _api$core, _api$contextIdentifie; var provider; return _regenerator.default.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); } var createPlugin = exports.createPlugin = function createPlugin(initialConfig, api) { return function () { if (initialConfig) { updateContextIdentifier(initialConfig, api); } return new _safePlugin.SafePlugin({ key: pluginKey, state: { init: function init() { return initialConfig; }, apply: function apply(tr, pluginState) { var meta = tr.getMeta(pluginKey); return meta ? meta : pluginState; } } }); }; };