UNPKG

944 BJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.notify = notify;
5exports.useFirstFocusedRender = useFirstFocusedRender;
6exports.useInstanceId = void 0;
7
8var _react = require("react");
9
10let idCount = 0;
11
12function uniqueId(prefix) {
13 return '' + ((prefix == null ? '' : prefix) + ++idCount);
14}
15
16function notify(handler, args) {
17 // eslint-disable-next-line prefer-spread
18 if (handler) handler.apply(null, args);
19}
20
21const useInstanceId = (otherId, suffix = '') => {
22 const id = (0, _react.useRef)();
23 if (!id.current) id.current = uniqueId('rw_');
24 return (otherId || id.current) + suffix;
25};
26/**
27 * Allows for defering popup rendering untill the widget is focused,
28 * or has been opened (in order to not remove it suddenly on close)
29 */
30
31
32exports.useInstanceId = useInstanceId;
33
34function useFirstFocusedRender(focused, open) {
35 const ref = (0, _react.useRef)(false);
36 return ref.current || (focused || !!open) && (ref.current = true);
37}
\No newline at end of file