@atlaskit/editor-plugin-toolbar
Version:
Toolbar plugin for @atlaskit/editor-core
39 lines (38 loc) • 2.34 kB
JavaScript
;
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ConfirmDialog = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ConfirmationModal = require("../ConfirmationModal");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/**
* Renders the dialog opened with `store.show`. Render it where it outlives the toolbar, e.g. in a
* plugin `contentComponent`: menus close and the toolbar hides when the dialog takes focus.
*/
var ConfirmDialog = exports.ConfirmDialog = function ConfirmDialog(_ref) {
var editorView = _ref.editorView,
store = _ref.store,
testId = _ref.testId;
var options = (0, _react.useSyncExternalStore)(store.subscribe, store.getOptions, store.getOptions);
var onConfirm = (0, _react.useCallback)(function () {
var _options$onConfirm;
var isChecked = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var command = options === null || options === void 0 || (_options$onConfirm = options.onConfirm) === null || _options$onConfirm === void 0 ? void 0 : _options$onConfirm.call(options, isChecked);
command === null || command === void 0 || command(editorView.state, editorView.dispatch, editorView);
}, [options, editorView]);
var onClose = (0, _react.useCallback)(function () {
store.hide();
// The dialog takes focus from the editor; restore it so the cursor does not jump.
if (!editorView.hasFocus()) {
editorView.focus();
}
}, [store, editorView]);
return /*#__PURE__*/_react.default.createElement(_ConfirmationModal.ConfirmationModal, {
testId: testId,
options: options,
onConfirm: onConfirm,
onClose: onClose
});
};