UNPKG

@atlaskit/editor-plugin-quick-insert

Version:

Quick insert plugin for @atlaskit/editor-core

47 lines (44 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.openElementBrowserModal = exports.createInsertItem = exports.closeElementBrowserModal = void 0; var _insert = require("@atlaskit/editor-common/insert"); var _pluginKey = require("../plugin-key"); var openElementBrowserModal = exports.openElementBrowserModal = function openElementBrowserModal(_ref) { var tr = _ref.tr; return tr.setMeta(_pluginKey.pluginKey, { isElementBrowserModalOpen: true }); }; var closeElementBrowserModal = exports.closeElementBrowserModal = function closeElementBrowserModal() { return function (state, dispatch) { if (dispatch) { dispatch(state.tr.setMeta(_pluginKey.pluginKey, { isElementBrowserModalOpen: false })); } return true; }; }; var createInsertItem = exports.createInsertItem = function createInsertItem(onInsert) { return insertItem(onInsert); }; // this method was adapted from the typeahead plugin so we respect the API for quick insert items var insertItem = function insertItem(onInsert) { return function (item, source) { return function (state, dispatch) { var insert = function insert(maybeNode) { var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return (0, _insert.insertSelectedItem)(maybeNode, opts)(state, state.tr, state.selection.head); }; var 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 || onInsert(item); return true; }; }; };