@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
100 lines (96 loc) • 7.44 kB
JavaScript
// #region Imports
import { EditorPresetBuilder } from '@atlaskit/editor-common/preset';
import { userPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
import { analyticsPlugin } from '@atlaskit/editor-plugins/analytics';
import { basePlugin } from '@atlaskit/editor-plugins/base';
import { betterTypeHistoryPlugin } from '@atlaskit/editor-plugins/better-type-history';
import { blockMenuPlugin } from '@atlaskit/editor-plugins/block-menu';
import { blockTypePlugin } from '@atlaskit/editor-plugins/block-type';
import { clearMarksOnEmptyDocPlugin } from '@atlaskit/editor-plugins/clear-marks-on-empty-doc';
import { clipboardPlugin } from '@atlaskit/editor-plugins/clipboard';
import { codeBlockPlugin } from '@atlaskit/editor-plugins/code-block';
import { compositionPlugin } from '@atlaskit/editor-plugins/composition';
import { contextIdentifierPlugin } from '@atlaskit/editor-plugins/context-identifier';
import { copyButtonPlugin } from '@atlaskit/editor-plugins/copy-button';
import { decorationsPlugin } from '@atlaskit/editor-plugins/decorations';
import { editorDisabledPlugin } from '@atlaskit/editor-plugins/editor-disabled';
import { featureFlagsPlugin } from '@atlaskit/editor-plugins/feature-flags';
import { floatingToolbarPlugin } from '@atlaskit/editor-plugins/floating-toolbar';
import { focusPlugin } from '@atlaskit/editor-plugins/focus';
import { historyPlugin } from '@atlaskit/editor-plugins/history';
import { hyperlinkPlugin } from '@atlaskit/editor-plugins/hyperlink';
import { interactionPlugin } from '@atlaskit/editor-plugins/interaction';
import { pastePlugin } from '@atlaskit/editor-plugins/paste';
import { placeholderPlugin } from '@atlaskit/editor-plugins/placeholder';
import { primaryToolbarPlugin } from '@atlaskit/editor-plugins/primary-toolbar';
import { quickInsertPlugin } from '@atlaskit/editor-plugins/quick-insert';
import { selectionPlugin } from '@atlaskit/editor-plugins/selection';
import { selectionToolbarPlugin } from '@atlaskit/editor-plugins/selection-toolbar';
import { submitEditorPlugin } from '@atlaskit/editor-plugins/submit-editor';
import { textFormattingPlugin } from '@atlaskit/editor-plugins/text-formatting';
import { toolbarPlugin } from '@atlaskit/editor-plugins/toolbar';
import { typeAheadPlugin } from '@atlaskit/editor-plugins/type-ahead';
import { uiControlRegistryPlugin } from '@atlaskit/editor-plugins/ui-control-registry';
import { undoRedoPlugin } from '@atlaskit/editor-plugins/undo-redo';
import { unsupportedContentPlugin } from '@atlaskit/editor-plugins/unsupported-content';
import { userIntentPlugin } from '@atlaskit/editor-plugins/user-intent';
import { widthPlugin } from '@atlaskit/editor-plugins/width';
import { fg } from '@atlaskit/platform-feature-flags';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
import { isFullPage as fullPageCheck } from '../utils/is-full-page';
// #endregion
/**
* Note: The order that presets are added determines
* their placement in the editor toolbar
* @param options
* @example
*/
export function createDefaultPreset(options) {
var _options$toolbar, _options$featureFlags, _options$featureFlags2, _options$blockMenu$us, _options$blockMenu, _options$blockMenu2, _options$blockMenu3, _options$blockMenu$en, _options$blockMenu4;
const isFullPage = fullPageCheck(options.appearance);
const preset = new EditorPresetBuilder().add([featureFlagsPlugin, options.featureFlags || {}]).maybeAdd([analyticsPlugin, {
createAnalyticsEvent: options.createAnalyticsEvent,
performanceTracking: options.performanceTracking
}], Boolean(options.allowAnalyticsGASV3)).add(betterTypeHistoryPlugin).add([pastePlugin, {
...(options === null || options === void 0 ? void 0 : options.paste),
isFullPage
}]).add(clipboardPlugin).add(focusPlugin).maybeAdd([userPreferencesPlugin, {
initialUserPreferences: {
toolbarDockingPosition: isFullPage ? 'none' : 'top'
}
}], () => fg('platform_editor_use_preferences_plugin')).maybeAdd(interactionPlugin, Boolean(options === null || options === void 0 ? void 0 : options.__livePage) || expValEquals('platform_editor_no_cursor_on_edit_page_init', 'isEnabled', true)).add(compositionPlugin).add([contextIdentifierPlugin, {
contextIdentifierProvider: options.contextIdentifierProvider
}]).add([basePlugin, options.base]).add(decorationsPlugin).add([typeAheadPlugin, options.typeAhead]).maybeAdd(historyPlugin, Boolean(options.allowUndoRedoButtons)).add(userIntentPlugin).maybeAdd([toolbarPlugin, options.toolbar || {}], Boolean((_options$toolbar = options.toolbar) === null || _options$toolbar === void 0 ? void 0 : _options$toolbar.enableNewToolbarExperience)).add([primaryToolbarPlugin, {
contextualFormattingEnabled: isFullPage
}]).maybeAdd(uiControlRegistryPlugin, expValEqualsNoExposure('platform_editor_table_menu_updates', 'isEnabled', true) || expValEqualsNoExposure('platform_editor_layout_column_menu', 'isEnabled', true) || expValEqualsNoExposure('platform_editor_paste_actions_menu', 'isEnabled', true)).maybeAdd(undoRedoPlugin, Boolean((_options$featureFlags = (_options$featureFlags2 = options.featureFlags) === null || _options$featureFlags2 === void 0 ? void 0 : _options$featureFlags2.undoRedoButtons) !== null && _options$featureFlags !== void 0 ? _options$featureFlags : options.allowUndoRedoButtons)).maybeAdd([blockMenuPlugin, {
useStandardNodeWidth: (_options$blockMenu$us = (_options$blockMenu = options.blockMenu) === null || _options$blockMenu === void 0 ? void 0 : _options$blockMenu.useStandardNodeWidth) !== null && _options$blockMenu$us !== void 0 ? _options$blockMenu$us : false,
blockLinkHashPrefix: (_options$blockMenu2 = options.blockMenu) === null || _options$blockMenu2 === void 0 ? void 0 : _options$blockMenu2.blockLinkHashPrefix,
getLinkPath: (_options$blockMenu3 = options.blockMenu) === null || _options$blockMenu3 === void 0 ? void 0 : _options$blockMenu3.getLinkPath
}], Boolean((_options$blockMenu$en = (_options$blockMenu4 = options.blockMenu) === null || _options$blockMenu4 === void 0 ? void 0 : _options$blockMenu4.enabled) !== null && _options$blockMenu$en !== void 0 ? _options$blockMenu$en : false)).add([blockTypePlugin, {
...options.blockType,
includeBlockQuoteAsTextstyleOption: isFullPage
}]).add(clearMarksOnEmptyDocPlugin).add([selectionToolbarPlugin, {
preferenceToolbarAboveSelection: !!options.preferenceToolbarAboveSelection,
contextualFormattingEnabled: isFullPage
}]).add([hyperlinkPlugin, {
...options.hyperlinkOptions,
// @ts-ignore Temporary solution to check for Live Page editor.
__livePage: options.__livePage
}]).add([textFormattingPlugin, options.textFormatting]).add(widthPlugin).add([quickInsertPlugin, options.quickInsert]).add([placeholderPlugin, options.placeholder]).add(unsupportedContentPlugin).add([editorDisabledPlugin, {
initialDisabledState: options.disabled
}]).add([submitEditorPlugin, options.submitEditor]).add(copyButtonPlugin).add(floatingToolbarPlugin).add([selectionPlugin, {
...options.selection,
__livePage: options.__livePage
}]).add([codeBlockPlugin, options.codeBlock]);
return preset;
}
/**
*
* @param props
* @example
*/
export function useDefaultPreset(props) {
const preset = createDefaultPreset(props);
return [preset];
}