UNPKG

@atlaskit/editor-plugin-block-controls

Version:

Block controls plugin for @atlaskit/editor-core

49 lines (47 loc) 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sparseSurfacesKey = exports.createSparseSurfacesPlugin = void 0; var _surfaceCandidateInvalidation = require("@atlaskit/editor-common/block-controls/surface-candidate-invalidation"); var _safePlugin = require("@atlaskit/editor-common/safe-plugin"); var _state = require("@atlaskit/editor-prosemirror/state"); var _view2 = require("@atlaskit/editor-prosemirror/view"); var _main = require("./main"); var _sparseSurfaceCandidates = require("./utils/sparse-surface-candidates"); var _sparseSurfacesState = require("./utils/sparse-surfaces-state"); var _sparseSurfacesView = require("./utils/sparse-surfaces-view"); var sparseSurfacesKey = exports.sparseSurfacesKey = new _state.PluginKey('blockControlsSparseSurfaces'); /** Owns sparse anchors independently of drag/drop decorations and their lifecycle. */ var createSparseSurfacesPlugin = exports.createSparseSurfacesPlugin = function createSparseSurfacesPlugin(api) { return new _safePlugin.SafePlugin({ key: sparseSurfacesKey, state: { init: function init() { return (0, _sparseSurfacesState.createInitialSparseSurfacesState)(_sparseSurfaceCandidates.emptySparseSurfaceCandidateState); }, apply: function apply(tr, previous, _oldState, newState) { return (0, _sparseSurfacesState.applySparseSurfacesTransaction)({ invalidation: tr.getMeta(_surfaceCandidateInvalidation.BLOCK_CONTROLS_SURFACE_INVALIDATION), meta: tr.getMeta(sparseSurfacesKey), newState: newState, previous: previous, tr: tr }); } }, props: { decorations: function decorations(state) { var _api$limitedMode, _blockControlsKey$get, _sparseSurfacesKey$ge; return api !== null && api !== void 0 && (_api$limitedMode = api.limitedMode) !== null && _api$limitedMode !== void 0 && (_api$limitedMode = _api$limitedMode.sharedState.currentState()) !== null && _api$limitedMode !== void 0 && _api$limitedMode.enabled || (_blockControlsKey$get = _main.key.getState(state)) !== null && _blockControlsKey$get !== void 0 && _blockControlsKey$get.isDragging ? _view2.DecorationSet.empty : (_sparseSurfacesKey$ge = sparseSurfacesKey.getState(state)) === null || _sparseSurfacesKey$ge === void 0 ? void 0 : _sparseSurfacesKey$ge.decorations; } }, view: function view(_view) { return (0, _sparseSurfacesView.createSparseSurfacesView)({ api: api, pluginKey: sparseSurfacesKey, view: _view }); } }); };