UNPKG

@atlaskit/editor-plugin-selection

Version:

Selection plugin for @atlaskit/editor-core

21 lines 1.49 kB
import { getFragmentsFromSelection, getLocalIdsFromSelection } from '@atlaskit/editor-common/selection'; export const getSelectionFragment = api => () => { var _api$selection$shared, _api$selection$shared2; const 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 => () => { var _api$selection$shared3, _api$selection$shared4, _selection; let selection = 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); };