UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

106 lines (103 loc) • 9.06 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.createDefaultPreset = createDefaultPreset; exports.useDefaultPreset = useDefaultPreset; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _preset = require("@atlaskit/editor-common/preset"); var _editorPluginUserPreferences = require("@atlaskit/editor-plugin-user-preferences"); var _analytics = require("@atlaskit/editor-plugins/analytics"); var _base = require("@atlaskit/editor-plugins/base"); var _betterTypeHistory = require("@atlaskit/editor-plugins/better-type-history"); var _blockMenu = require("@atlaskit/editor-plugins/block-menu"); var _blockType = require("@atlaskit/editor-plugins/block-type"); var _clearMarksOnEmptyDoc = require("@atlaskit/editor-plugins/clear-marks-on-empty-doc"); var _clipboard = require("@atlaskit/editor-plugins/clipboard"); var _codeBlock = require("@atlaskit/editor-plugins/code-block"); var _composition = require("@atlaskit/editor-plugins/composition"); var _contextIdentifier = require("@atlaskit/editor-plugins/context-identifier"); var _copyButton = require("@atlaskit/editor-plugins/copy-button"); var _decorations = require("@atlaskit/editor-plugins/decorations"); var _editorDisabled = require("@atlaskit/editor-plugins/editor-disabled"); var _featureFlags = require("@atlaskit/editor-plugins/feature-flags"); var _floatingToolbar = require("@atlaskit/editor-plugins/floating-toolbar"); var _focus = require("@atlaskit/editor-plugins/focus"); var _history = require("@atlaskit/editor-plugins/history"); var _hyperlink = require("@atlaskit/editor-plugins/hyperlink"); var _interaction = require("@atlaskit/editor-plugins/interaction"); var _paste = require("@atlaskit/editor-plugins/paste"); var _placeholder = require("@atlaskit/editor-plugins/placeholder"); var _primaryToolbar = require("@atlaskit/editor-plugins/primary-toolbar"); var _quickInsert = require("@atlaskit/editor-plugins/quick-insert"); var _selection = require("@atlaskit/editor-plugins/selection"); var _selectionToolbar = require("@atlaskit/editor-plugins/selection-toolbar"); var _submitEditor = require("@atlaskit/editor-plugins/submit-editor"); var _textFormatting = require("@atlaskit/editor-plugins/text-formatting"); var _toolbar = require("@atlaskit/editor-plugins/toolbar"); var _typeAhead = require("@atlaskit/editor-plugins/type-ahead"); var _uiControlRegistry = require("@atlaskit/editor-plugins/ui-control-registry"); var _undoRedo = require("@atlaskit/editor-plugins/undo-redo"); var _unsupportedContent = require("@atlaskit/editor-plugins/unsupported-content"); var _userIntent = require("@atlaskit/editor-plugins/user-intent"); var _width = require("@atlaskit/editor-plugins/width"); var _platformFeatureFlags = require("@atlaskit/platform-feature-flags"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure"); var _isFullPage = require("../utils/is-full-page"); function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // #region Imports // #endregion /** * Note: The order that presets are added determines * their placement in the editor toolbar * @param options * @example */ function createDefaultPreset(options) { var _options$toolbar, _options$featureFlags, _options$featureFlags2, _options$blockMenu$us, _options$blockMenu, _options$blockMenu2, _options$blockMenu3, _options$blockMenu$en, _options$blockMenu4; var isFullPage = (0, _isFullPage.isFullPage)(options.appearance); var preset = new _preset.EditorPresetBuilder().add([_featureFlags.featureFlagsPlugin, options.featureFlags || {}]).maybeAdd([_analytics.analyticsPlugin, { createAnalyticsEvent: options.createAnalyticsEvent, performanceTracking: options.performanceTracking }], Boolean(options.allowAnalyticsGASV3)).add(_betterTypeHistory.betterTypeHistoryPlugin).add([_paste.pastePlugin, _objectSpread(_objectSpread({}, options === null || options === void 0 ? void 0 : options.paste), {}, { isFullPage: isFullPage })]).add(_clipboard.clipboardPlugin).add(_focus.focusPlugin).maybeAdd([_editorPluginUserPreferences.userPreferencesPlugin, { initialUserPreferences: { toolbarDockingPosition: isFullPage ? 'none' : 'top' } }], function () { return (0, _platformFeatureFlags.fg)('platform_editor_use_preferences_plugin'); }).maybeAdd(_interaction.interactionPlugin, Boolean(options === null || options === void 0 ? void 0 : options.__livePage) || (0, _expValEquals.expValEquals)('platform_editor_no_cursor_on_edit_page_init', 'isEnabled', true)).add(_composition.compositionPlugin).add([_contextIdentifier.contextIdentifierPlugin, { contextIdentifierProvider: options.contextIdentifierProvider }]).add([_base.basePlugin, options.base]).add(_decorations.decorationsPlugin).add([_typeAhead.typeAheadPlugin, options.typeAhead]).maybeAdd(_history.historyPlugin, Boolean(options.allowUndoRedoButtons)).add(_userIntent.userIntentPlugin).maybeAdd([_toolbar.toolbarPlugin, options.toolbar || {}], Boolean((_options$toolbar = options.toolbar) === null || _options$toolbar === void 0 ? void 0 : _options$toolbar.enableNewToolbarExperience)).add([_primaryToolbar.primaryToolbarPlugin, { contextualFormattingEnabled: isFullPage }]).maybeAdd(_uiControlRegistry.uiControlRegistryPlugin, (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_table_menu_updates', 'isEnabled', true) || (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_layout_column_menu', 'isEnabled', true) || (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_paste_actions_menu', 'isEnabled', true)).maybeAdd(_undoRedo.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([_blockMenu.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([_blockType.blockTypePlugin, _objectSpread(_objectSpread({}, options.blockType), {}, { includeBlockQuoteAsTextstyleOption: isFullPage })]).add(_clearMarksOnEmptyDoc.clearMarksOnEmptyDocPlugin).add([_selectionToolbar.selectionToolbarPlugin, { preferenceToolbarAboveSelection: !!options.preferenceToolbarAboveSelection, contextualFormattingEnabled: isFullPage }]).add([_hyperlink.hyperlinkPlugin, _objectSpread(_objectSpread({}, options.hyperlinkOptions), {}, { // @ts-ignore Temporary solution to check for Live Page editor. __livePage: options.__livePage })]).add([_textFormatting.textFormattingPlugin, options.textFormatting]).add(_width.widthPlugin).add([_quickInsert.quickInsertPlugin, options.quickInsert]).add([_placeholder.placeholderPlugin, options.placeholder]).add(_unsupportedContent.unsupportedContentPlugin).add([_editorDisabled.editorDisabledPlugin, { initialDisabledState: options.disabled }]).add([_submitEditor.submitEditorPlugin, options.submitEditor]).add(_copyButton.copyButtonPlugin).add(_floatingToolbar.floatingToolbarPlugin).add([_selection.selectionPlugin, _objectSpread(_objectSpread({}, options.selection), {}, { __livePage: options.__livePage })]).add([_codeBlock.codeBlockPlugin, options.codeBlock]); return preset; } /** * * @param props * @example */ function useDefaultPreset(props) { var preset = createDefaultPreset(props); return [preset]; }