@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
30 lines (29 loc) • 1.59 kB
JavaScript
import { useEffect } from 'react';
/**
*
* A wrapper for popups to signal popupOpen user intent
*/
export const UserIntentPopupWrapper = ({
userIntent = 'popupOpen',
children,
api
}) => {
useEffect(() => {
var _api$userIntent;
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.commands.setCurrentUserIntent(userIntent));
return () => {
var _api$userIntent2, _api$userIntent2$shar;
if (userIntent === (api === null || api === void 0 ? void 0 : (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : (_api$userIntent2$shar = _api$userIntent2.sharedState.currentState()) === null || _api$userIntent2$shar === void 0 ? void 0 : _api$userIntent2$shar.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(() => {
var _api$userIntent3;
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? 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;
};