UNPKG

@atlaskit/editor-plugin-placeholder

Version:

Placeholder plugin for @atlaskit/editor-core.

69 lines (67 loc) • 2.86 kB
import React from 'react'; import { isSSR } from '@atlaskit/editor-common/is-ssr'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; import { PlaceholderLoadingSpinner } from './PlaceholderLoadingSpinner'; import createPlugin from './pm-plugins/main'; export var EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000; // Delay before showing placeholder on empty paragraph export var pluginKey = new PluginKey('placeholderPlugin'); export var placeholderPlugin = function placeholderPlugin(_ref) { var options = _ref.config, api = _ref.api; var currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder; return { name: 'placeholder', commands: { setPlaceholder: function setPlaceholder(placeholderText) { return function (_ref2) { var tr = _ref2.tr; if (currentPlaceholder !== placeholderText) { currentPlaceholder = placeholderText; return tr.setMeta(pluginKey, { placeholderText: placeholderText }); } return null; }; }, setAnimatingPlaceholderPrompts: function setAnimatingPlaceholderPrompts(placeholderPrompts) { return function (_ref3) { var tr = _ref3.tr; return tr.setMeta(pluginKey, { placeholderPrompts: placeholderPrompts }); }; }, setPlaceholderHidden: function setPlaceholderHidden(isPlaceholderHidden) { return function (_ref4) { var tr = _ref4.tr; return tr.setMeta(pluginKey, { isPlaceholderHidden: isPlaceholderHidden }); }; } }, pmPlugins: function pmPlugins() { return [{ name: 'placeholder', plugin: function plugin(_ref5) { var getIntl = _ref5.getIntl; return createPlugin(getIntl(), options && options.placeholder, options && options.placeholderBracketHint, options && options.emptyLinePlaceholder, options && options.placeholderPrompts, options === null || options === void 0 ? void 0 : options.withEmptyParagraph, options === null || options === void 0 ? void 0 : options.isPlaceholderHidden, options && options.placeholderADF, options && options.placeholderPromptAnimationOptions, options === null || options === void 0 ? void 0 : options.isRovoLLMEnabled, api); } }]; }, contentComponent: function contentComponent(params) { if (isSSR()) { return null; } // If loading spinner is explicitly disabled (e.g., for DiffEditor/version history), skip if ((options === null || options === void 0 ? void 0 : options.enableLoadingSpinner) === false) { return null; } return /*#__PURE__*/React.createElement(PlaceholderLoadingSpinner, { api: api, editorView: params.editorView }); } }; };