UNPKG

@atlaskit/editor-plugin-placeholder

Version:

Placeholder plugin for @atlaskit/editor-core.

95 lines (92 loc) • 4.04 kB
/* placeholderPlugin.tsx generated by @compiled/babel-plugin v3.0.2 */ import "./placeholderPlugin.compiled.css"; import { ax, ix } from "@compiled/react/runtime"; import React from 'react'; import { isSSR } from '@atlaskit/editor-common/is-ssr'; import { isEmptyDocument } from '@atlaskit/editor-common/utils/document'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; import { fg } from '@atlaskit/platform-feature-flags/fg'; import { Box } from '@atlaskit/primitives/compiled/box'; import Spinner from '@atlaskit/spinner/spinner'; import { PlaceholderLoadingSpinner } from './PlaceholderLoadingSpinner'; import createPlugin from './pm-plugins/main'; export const EMPTY_PARAGRAPH_TIMEOUT_DELAY = 2000; // Delay before showing placeholder on empty paragraph export const pluginKey = new PluginKey('placeholderPlugin'); export const placeholderPlugin = ({ config: options, api }) => { let currentPlaceholder = options === null || options === void 0 ? void 0 : options.placeholder; return { name: 'placeholder', commands: { setPlaceholder: placeholderText => ({ tr }) => { if (currentPlaceholder !== placeholderText) { currentPlaceholder = placeholderText; return tr.setMeta(pluginKey, { placeholderText: placeholderText }); } return null; }, setAnimatingPlaceholderPrompts: placeholderPrompts => ({ tr }) => { return tr.setMeta(pluginKey, { placeholderPrompts: placeholderPrompts }); }, setPlaceholderHidden: isPlaceholderHidden => ({ tr }) => { return tr.setMeta(pluginKey, { isPlaceholderHidden }); } }, pmPlugins() { return [{ name: 'placeholder', plugin: ({ getIntl }) => 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: params => { var _params$editorView, _params$editorView2, _params$editorView2$s; 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; } if (fg('platform_editor_placeholder_collab_spinner')) { return /*#__PURE__*/React.createElement(PlaceholderLoadingSpinner, { api: api, editorView: params.editorView }); } const 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 const collabEditPluginState = (_params$editorView2 = params.editorView) === null || _params$editorView2 === void 0 ? void 0 : (_params$editorView2$s = _params$editorView2.state) === null || _params$editorView2$s === void 0 ? void 0 : _params$editorView2$s.collabEditPlugin$; if (collabEditPluginState && collabEditPluginState.isReady !== true) { if (doc && !isEmptyDocument(doc)) { return null; } return /*#__PURE__*/React.createElement(Box, { xcss: spinnerContainerStyles.spinnerContainer }, /*#__PURE__*/React.createElement(Spinner, { interactionName: "live-pages-loading-spinner", size: "medium" })); } return null; } }; }; const spinnerContainerStyles = { spinnerContainer: "_1e0c1txw _2lx21bp4 _1bah1h6o _4cvr1h6o _1bsb1osq" };