UNPKG

@atlaskit/editor-plugin-context-identifier

Version:

Context identifier plugin for @atlaskit/editor-core

25 lines 1.1 kB
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; export const pluginKey = new PluginKey('contextIdentiferPlugin'); async function updateContextIdentifier(config, api) { var _api$core, _api$contextIdentifie; const provider = await config.contextIdentifierProvider; api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$contextIdentifie = api.contextIdentifier) === null || _api$contextIdentifie === void 0 ? void 0 : _api$contextIdentifie.commands.setProvider({ contextIdentifierProvider: provider })); } export const createPlugin = (initialConfig, api) => () => { if (initialConfig) { updateContextIdentifier(initialConfig, api); } return new SafePlugin({ key: pluginKey, state: { init: () => initialConfig, apply: (tr, pluginState) => { const meta = tr.getMeta(pluginKey); return meta ? meta : pluginState; } } }); };