UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

36 lines (34 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserIntentPopupWrapper = void 0; var _react = require("react"); /** * * A wrapper for popups to signal popupOpen user intent */ var UserIntentPopupWrapper = exports.UserIntentPopupWrapper = function UserIntentPopupWrapper(_ref) { var _ref$userIntent = _ref.userIntent, userIntent = _ref$userIntent === void 0 ? 'popupOpen' : _ref$userIntent, children = _ref.children, api = _ref.api; (0, _react.useEffect)(function () { var _api$userIntent; api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.commands.setCurrentUserIntent(userIntent)); return function () { var _api$userIntent2; if (userIntent === (api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || (_api$userIntent2 = _api$userIntent2.sharedState.currentState()) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.currentUserIntent)) { // Defer the reset to avoid interfering with ongoing ProseMirror transactions // This fixes a race condition where cleanup happens during a transaction // (e.g., during drag handle mouse over -> unmountDecorations -> flushSync) setTimeout(function () { var _api$userIntent3; api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent3 = api.userIntent) === null || _api$userIntent3 === void 0 ? void 0 : _api$userIntent3.commands.setCurrentUserIntent('default')); }, 0); } }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return children; };