@atlaskit/editor-plugin-quick-insert
Version:
Quick insert plugin for @atlaskit/editor-core
31 lines (29 loc) • 1.08 kB
JavaScript
import { insertSelectedItem } from '@atlaskit/editor-common/insert';
import { pluginKey } from '../plugin-key';
export const openElementBrowserModal = ({
tr
}) => tr.setMeta(pluginKey, {
isElementBrowserModalOpen: true
});
export const closeElementBrowserModal = () => (state, dispatch) => {
if (dispatch) {
dispatch(state.tr.setMeta(pluginKey, {
isElementBrowserModalOpen: false
}));
}
return true;
};
export const createInsertItem = onInsert => insertItem(onInsert);
// this method was adapted from the typeahead plugin so we respect the API for quick insert items
const insertItem = onInsert => (item, source) => (state, dispatch) => {
const insert = (maybeNode, opts = {}) => {
return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
};
const tr = item.action(insert, state, source);
/** @note There is no transaction when called without a search currently (different insert) */
if (tr && dispatch) {
dispatch(tr);
}
onInsert === null || onInsert === void 0 ? void 0 : onInsert(item);
return true;
};