UNPKG

@atlaskit/editor-plugin-toolbar

Version:

Toolbar plugin for @atlaskit/editor-core

31 lines • 1.46 kB
import React, { useCallback, useSyncExternalStore } from 'react'; import { ConfirmationModal } from '../ConfirmationModal'; /** * 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. */ export var ConfirmDialog = function ConfirmDialog(_ref) { var editorView = _ref.editorView, store = _ref.store, testId = _ref.testId; var options = useSyncExternalStore(store.subscribe, store.getOptions, store.getOptions); var onConfirm = 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 = 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.createElement(ConfirmationModal, { testId: testId, options: options, onConfirm: onConfirm, onClose: onClose }); };