UNPKG

@atlaskit/editor-plugin-content-format

Version:

ContentFormat plugin for @atlaskit/editor-core

77 lines (76 loc) 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPlugin = exports.contentFormatPluginKey = exports.contentFormatPlugin = void 0; var _safePlugin = require("@atlaskit/editor-common/safe-plugin"); var _state = require("@atlaskit/editor-prosemirror/state"); var contentFormatPluginKey = exports.contentFormatPluginKey = new _state.PluginKey('contentFormat'); var createPlugin = exports.createPlugin = function createPlugin(_ref) { var initialContentMode = _ref.initialContentMode; return new _safePlugin.SafePlugin({ key: contentFormatPluginKey, state: { init: function init() { return { contentMode: initialContentMode !== null && initialContentMode !== void 0 ? initialContentMode : 'standard' }; }, apply: function apply(tr, currentPluginState) { var meta = tr.getMeta(contentFormatPluginKey); if (meta) { var contentMode = meta.contentMode; return { contentMode: contentMode !== null && contentMode !== void 0 ? contentMode : currentPluginState.contentMode }; } return currentPluginState; } } }); }; var contentFormatPlugin = exports.contentFormatPlugin = function contentFormatPlugin(_ref2) { var options = _ref2.config; var previousContentMode; return { name: 'contentFormat', getSharedState: function getSharedState(editorState) { var _pluginState$contentM; if (!editorState) { var _options$initialConte; return { contentMode: (_options$initialConte = options === null || options === void 0 ? void 0 : options.initialContentMode) !== null && _options$initialConte !== void 0 ? _options$initialConte : 'standard' }; } var pluginState = contentFormatPluginKey.getState(editorState); return { contentMode: (_pluginState$contentM = pluginState === null || pluginState === void 0 ? void 0 : pluginState.contentMode) !== null && _pluginState$contentM !== void 0 ? _pluginState$contentM : 'standard' }; }, commands: { updateContentMode: function updateContentMode(contentMode) { return function (_ref3) { var tr = _ref3.tr; if (contentMode === previousContentMode) { return null; } previousContentMode = contentMode; return tr.setMeta(contentFormatPluginKey, { contentMode: contentMode }); }; } }, pmPlugins: function pmPlugins() { return [{ name: 'contentFormat', plugin: function plugin() { var _options$initialConte2; return createPlugin({ initialContentMode: (_options$initialConte2 = options === null || options === void 0 ? void 0 : options.initialContentMode) !== null && _options$initialConte2 !== void 0 ? _options$initialConte2 : 'standard' }); } }]; } }; };