@atlaskit/editor-plugin-placeholder
Version:
Placeholder plugin for @atlaskit/editor-core.
98 lines (95 loc) • 4.42 kB
JavaScript
/* 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 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) {
var _params$editorView, _params$editorView2;
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
});
}
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)) {
return null;
}
return /*#__PURE__*/React.createElement(Box, {
xcss: spinnerContainerStyles.spinnerContainer
}, /*#__PURE__*/React.createElement(Spinner, {
interactionName: "live-pages-loading-spinner",
size: "medium"
}));
}
return null;
}
};
};
var spinnerContainerStyles = {
spinnerContainer: "_1e0c1txw _2lx21bp4 _1bah1h6o _4cvr1h6o _1bsb1osq"
};