UNPKG

@atlaskit/editor-plugin-selection

Version:

Selection plugin for @atlaskit/editor-core

30 lines (29 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSelectionLocalIds = exports.getSelectionFragment = void 0; var _selection2 = require("@atlaskit/editor-common/selection"); var getSelectionFragment = exports.getSelectionFragment = function getSelectionFragment(api) { return function () { var _api$selection$shared; var selection = api === null || api === void 0 || (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 || (_api$selection$shared = _api$selection$shared.currentState()) === null || _api$selection$shared === void 0 ? void 0 : _api$selection$shared.selection; return (0, _selection2.getFragmentsFromSelection)(selection); }; }; var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionLocalIds(api) { return function () { var _api$selection$shared2, _selection; var selection = api === null || api === void 0 || (_api$selection$shared2 = api.selection.sharedState) === null || _api$selection$shared2 === void 0 || (_api$selection$shared2 = _api$selection$shared2.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection; if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) { // If we have an empty selection the current state might not be correct // We have a hack here to retrieve the current selection - but not dispatch a transaction api === null || api === void 0 || api.core.actions.execute(function (_ref) { var tr = _ref.tr; selection = tr.selection; return null; }); } return (0, _selection2.getLocalIdsFromSelection)(selection); }; };