UNPKG

@atlaskit/editor-plugin-placeholder

Version:

Placeholder plugin for @atlaskit/editor-core.

104 lines (99 loc) 5.12 kB
/* placeholderPlugin.tsx generated by @compiled/babel-plugin v0.39.1 */ "use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.pluginKey = exports.placeholderPlugin = exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = void 0; require("./placeholderPlugin.compiled.css"); var _runtime = require("@compiled/react/runtime"); var _react = _interopRequireDefault(require("react")); var _coreUtils = require("@atlaskit/editor-common/core-utils"); var _document = require("@atlaskit/editor-common/utils/document"); var _state = require("@atlaskit/editor-prosemirror/state"); var _compiled = require("@atlaskit/primitives/compiled"); var _spinner = _interopRequireDefault(require("@atlaskit/spinner/spinner")); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _main = _interopRequireDefault(require("./pm-plugins/main")); var EMPTY_PARAGRAPH_TIMEOUT_DELAY = exports.EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000; // Delay before showing placeholder on empty paragraph var pluginKey = exports.pluginKey = new _state.PluginKey('placeholderPlugin'); var placeholderPlugin = exports.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 (0, _main.default)(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 === null || options === void 0 ? void 0 : options.isRovoLLMEnabled, api); } }]; }, contentComponent: (0, _expValEquals.expValEquals)('confluence_load_editor_title_on_transition', 'contentPlaceholder', true) ? function (params) { var _params$editorView, _params$editorView2; if ((0, _expValEquals.expValEquals)('platform_editor_hydratable_ui', 'isEnabled', true) && (0, _coreUtils.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; } var doc = (_params$editorView = params.editorView) === null || _params$editorView === void 0 ? void 0 : _params$editorView.state.doc; // @ts-ignore fix which needs follow up to use standard apis var collabEditPluginState = (_params$editorView2 = params.editorView) === null || _params$editorView2 === void 0 || (_params$editorView2 = _params$editorView2.state) === null || _params$editorView2 === void 0 ? void 0 : _params$editorView2.collabEditPlugin$; if (collabEditPluginState && collabEditPluginState.isReady !== true) { if (doc && !(0, _document.isEmptyDocument)(doc)) { // If we have a document, and it's not empty - we should not show a loading component return null; } // In this scenario // - the collab plugin exists - but we don't have a "initial/placeholder" document // - and the collab plugin is not yet ready // So we show a placeholder spinner to indicate the content is still loading return /*#__PURE__*/_react.default.createElement(_compiled.Box, { xcss: spinnerContainerStyles.spinnerContainer }, /*#__PURE__*/_react.default.createElement(_spinner.default, { interactionName: "live-pages-loading-spinner", size: "medium" })); } return null; } : undefined }; }; var spinnerContainerStyles = { spinnerContainer: "_1e0c1txw _2lx21bp4 _1bah1h6o _4cvr1h6o _1bsb1osq" };