@atlaskit/editor-plugin-placeholder
Version:
Placeholder plugin for @atlaskit/editor-core.
94 lines (90 loc) • 4.23 kB
JavaScript
/* placeholderPlugin.tsx generated by @compiled/babel-plugin v0.39.1 */
import "./placeholderPlugin.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
import { isSSR } from '@atlaskit/editor-common/core-utils';
import { isEmptyDocument } from '@atlaskit/editor-common/utils/document';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
import { Box } from '@atlaskit/primitives/compiled';
import Spinner from '@atlaskit/spinner/spinner';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
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 === null || options === void 0 ? void 0 : options.isRovoLLMEnabled, api)
}];
},
contentComponent: expValEquals('confluence_load_editor_title_on_transition', 'contentPlaceholder', true) ? params => {
var _params$editorView, _params$editorView2, _params$editorView2$s;
if (expValEquals('platform_editor_hydratable_ui', 'isEnabled', true) && 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;
}
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)) {
// 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.createElement(Box, {
xcss: spinnerContainerStyles.spinnerContainer
}, /*#__PURE__*/React.createElement(Spinner, {
interactionName: "live-pages-loading-spinner",
size: "medium"
}));
}
return null;
} : undefined
};
};
const spinnerContainerStyles = {
spinnerContainer: "_1e0c1txw _2lx21bp4 _1bah1h6o _4cvr1h6o _1bsb1osq"
};