@atlaskit/editor-plugin-quick-insert
Version:
Quick insert plugin for @atlaskit/editor-core
79 lines (74 loc) • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.openElementBrowserModal = exports.openElementBrowser = exports.createInsertItem = exports.closeElementBrowserModal = exports.closeElementBrowser = void 0;
var _insert = require("@atlaskit/editor-common/insert");
var _pluginKey = require("../plugin-key");
var openElementBrowser = exports.openElementBrowser = function openElementBrowser() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
category = _ref.category;
return function (_ref2) {
var tr = _ref2.tr;
return tr.setMeta(_pluginKey.pluginKey, {
elementBrowserInitialCategory: category,
isElementBrowserOpen: true
});
};
};
var closeElementBrowser = exports.closeElementBrowser = function closeElementBrowser() {
return function (state, dispatch) {
if (dispatch) {
dispatch(state.tr.setMeta(_pluginKey.pluginKey, {
elementBrowserInitialCategory: undefined,
isElementBrowserOpen: false
}));
}
return true;
};
};
/**
* @private
* @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-62138 Internal documentation for deprecation (no external access)} Tracked by EDITOR-8422. Use `openElementBrowser` instead.
*/
var openElementBrowserModal = exports.openElementBrowserModal = function openElementBrowserModal(_ref3) {
var tr = _ref3.tr;
return tr.setMeta(_pluginKey.pluginKey, {
isElementBrowserModalOpen: true
});
};
/**
* @private
* @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-62138 Internal documentation for deprecation (no external access)} Tracked by EDITOR-8422. Use `closeElementBrowser` instead.
*/
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;
};
};
};