UNPKG

@atlaskit/editor-plugin-selection

Version:

Selection plugin for @atlaskit/editor-core

21 lines 1.82 kB
import { getFragmentsFromSelection, getLocalIdsFromSelection } from '@atlaskit/editor-common/selection'; export const getSelectionFragment = api => props => { var _props$selection, _api$selection$shared, _api$selection$shared2; const selection = (_props$selection = props === null || props === void 0 ? void 0 : props.selection) !== null && _props$selection !== void 0 ? _props$selection : api === null || api === void 0 ? void 0 : (_api$selection$shared = api.selection.sharedState) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection; return getFragmentsFromSelection(selection); }; export const getSelectionLocalIds = api => props => { var _props$selection2, _api$selection$shared3, _api$selection$shared4, _selection; let selection = (_props$selection2 = props === null || props === void 0 ? void 0 : props.selection) !== null && _props$selection2 !== void 0 ? _props$selection2 : api === null || api === void 0 ? void 0 : (_api$selection$shared3 = api.selection.sharedState) === null || _api$selection$shared3 === void 0 ? void 0 : (_api$selection$shared4 = _api$selection$shared3.currentState()) === null || _api$selection$shared4 === void 0 ? void 0 : _api$selection$shared4.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 ? void 0 : api.core.actions.execute(({ tr }) => { selection = tr.selection; return null; }); } return getLocalIdsFromSelection(selection); };