UNPKG

@atlaskit/editor-plugin-mentions

Version:

Mentions plugin for @atlaskit/editor-core

52 lines (51 loc) 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MENTION_PLACEHOLDER_ACTIONS = void 0; exports.createMentionPlaceholderPlugin = createMentionPlaceholderPlugin; exports.mentionPlaceholderPluginKey = void 0; var _safePlugin = require("@atlaskit/editor-common/safe-plugin"); var _state = require("@atlaskit/editor-prosemirror/state"); var _view = require("@atlaskit/editor-prosemirror/view"); var mentionPlaceholderPluginKey = exports.mentionPlaceholderPluginKey = new _state.PluginKey('mentionPlaceholderPlugin'); var MENTION_PLACEHOLDER_ACTIONS = exports.MENTION_PLACEHOLDER_ACTIONS = { SHOW_PLACEHOLDER: 'SHOW_PLACEHOLDER', HIDE_PLACEHOLDER: 'HIDE_PLACEHOLDER' }; // eslint-disable-next-line @typescript-eslint/no-empty-object-type function createMentionPlaceholderPlugin() { return new _safePlugin.SafePlugin({ key: mentionPlaceholderPluginKey, state: { init: function init() { return {}; }, apply: function apply(tr, pluginState) { var meta = tr.getMeta(mentionPlaceholderPluginKey); if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.SHOW_PLACEHOLDER) { return { placeholder: meta.placeholder }; } if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER) { return {}; } return pluginState; } }, props: { decorations: function decorations(state) { var pluginState = mentionPlaceholderPluginKey.getState(state); if (pluginState !== null && pluginState !== void 0 && pluginState.placeholder) { var selection = state.selection; var span = document.createElement('span'); span.textContent = pluginState.placeholder; span.style.setProperty('color', "var(--ds-text-accent-blue, #1558BC)"); return _view.DecorationSet.create(state.doc, [_view.Decoration.widget(selection.from, span)]); } return null; } } }); }