UNPKG

@atlaskit/editor-plugin-context-identifier

Version:

Context identifier plugin for @atlaskit/editor-core

38 lines 1.46 kB
import { createPlugin, pluginKey } from './pm-plugins/main'; export const contextIdentifierPlugin = ({ config, api }) => { return { name: 'contextIdentifier', commands: { setProvider: config => ({ tr }) => { var _api$contextIdentifie, _api$contextIdentifie2; // If no change, don't dispatch if ((config === null || config === void 0 ? void 0 : config.contextIdentifierProvider) === (api === null || api === void 0 ? void 0 : (_api$contextIdentifie = api.contextIdentifier) === null || _api$contextIdentifie === void 0 ? void 0 : (_api$contextIdentifie2 = _api$contextIdentifie.sharedState.currentState()) === null || _api$contextIdentifie2 === void 0 ? void 0 : _api$contextIdentifie2.contextIdentifierProvider)) { return null; } return tr.setMeta(pluginKey, { contextIdentifierProvider: config === null || config === void 0 ? void 0 : config.contextIdentifierProvider }); } }, getSharedState(state) { var _pluginKey$getState; if (!state) { return undefined; } return { contextIdentifierProvider: (_pluginKey$getState = pluginKey.getState(state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.contextIdentifierProvider }; }, pmPlugins: () => { return [{ name: 'contextIdentifier', plugin: createPlugin(config, api) }]; } }; };