@atlaskit/editor-plugin-placeholder
Version:
Placeholder plugin for @atlaskit/editor-core.
97 lines (93 loc) • 4.59 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 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 === null || options === void 0 ? void 0 : options.isRovoLLMEnabled, api);
}
}];
},
contentComponent: expValEquals('confluence_load_editor_title_on_transition', 'contentPlaceholder', true) ? function (params) {
var _params$editorView, _params$editorView2;
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;
}
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 && !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
};
};
var spinnerContainerStyles = {
spinnerContainer: "_1e0c1txw _2lx21bp4 _1bah1h6o _4cvr1h6o _1bsb1osq"
};