UNPKG

@atlaskit/editor-plugin-selection

Version:

Selection plugin for @atlaskit/editor-core

24 lines 1.88 kB
import { getFragmentsFromSelection, getLocalIdsFromSelection } from '@atlaskit/editor-common/selection'; export var getSelectionFragment = function getSelectionFragment(api) { return function (props) { var _props$selection, _api$selection$shared; var selection = (_props$selection = props === null || props === void 0 ? void 0 : props.selection) !== null && _props$selection !== void 0 ? _props$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 getFragmentsFromSelection(selection); }; }; export var getSelectionLocalIds = function getSelectionLocalIds(api) { return function (props) { var _props$selection2, _api$selection$shared2, _selection; var selection = (_props$selection2 = props === null || props === void 0 ? void 0 : props.selection) !== null && _props$selection2 !== void 0 ? _props$selection2 : 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 getLocalIdsFromSelection(selection); }; };