@atlaskit/editor-plugin-placeholder
Version:
Placeholder plugin for @atlaskit/editor-core.
66 lines (64 loc) • 2.44 kB
JavaScript
import React from 'react';
import { isSSR } from '@atlaskit/editor-common/is-ssr';
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
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 => {
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;
}
return /*#__PURE__*/React.createElement(PlaceholderLoadingSpinner, {
api: api,
editorView: params.editorView
});
}
};
};