@trackunit/react-components 0.1.391 → 0.1.393
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +18 -42
- package/index.esm.js +19 -42
- package/package.json +1 -1
- package/src/hooks/index.d.ts +0 -1
- package/src/hooks/useVisibilityChange.d.ts +0 -10
package/index.cjs.js
CHANGED
|
@@ -1037,6 +1037,9 @@ const useContinuousTimeout = ({ onTimeout, onMaxRetries, duration, maxRetries })
|
|
|
1037
1037
|
setIsRunning(false); // Update the status when stopped
|
|
1038
1038
|
};
|
|
1039
1039
|
const startTimeouts = () => {
|
|
1040
|
+
if (isRunning) {
|
|
1041
|
+
return; // Prevent multiple timeouts from running
|
|
1042
|
+
}
|
|
1040
1043
|
startTimeout();
|
|
1041
1044
|
setIsRunning(true); // Update the status when started
|
|
1042
1045
|
};
|
|
@@ -1312,55 +1315,29 @@ const useSelfUpdatingRef = (initialState) => {
|
|
|
1312
1315
|
return stateRef;
|
|
1313
1316
|
};
|
|
1314
1317
|
|
|
1315
|
-
/**
|
|
1316
|
-
* Returns a callback that will be called when the visibility state of the document changes.
|
|
1317
|
-
*/
|
|
1318
|
-
const useVisibilityChange = ({ onChange, targetState = "hidden" }) => {
|
|
1319
|
-
React.useEffect(() => {
|
|
1320
|
-
const handleVisibilityChange = () => {
|
|
1321
|
-
if (document.visibilityState === targetState) {
|
|
1322
|
-
onChange();
|
|
1323
|
-
}
|
|
1324
|
-
};
|
|
1325
|
-
window.addEventListener("visibilitychange", handleVisibilityChange);
|
|
1326
|
-
return () => {
|
|
1327
|
-
window.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
1328
|
-
};
|
|
1329
|
-
}, [onChange, targetState]);
|
|
1330
|
-
};
|
|
1331
|
-
|
|
1332
1318
|
const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
|
|
1333
1319
|
/**
|
|
1334
1320
|
* Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
|
|
1335
1321
|
*/
|
|
1336
|
-
const useWindowActivity = ({ onFocus, onBlur } = {}) => {
|
|
1322
|
+
const useWindowActivity = ({ onFocus, onBlur } = { onBlur: undefined, onFocus: undefined }) => {
|
|
1337
1323
|
const [focused, setFocused] = React.useState(hasFocus());
|
|
1324
|
+
const onFocusInternal = React.useCallback(() => {
|
|
1325
|
+
setFocused(hasFocus());
|
|
1326
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
1327
|
+
}, [onFocus]);
|
|
1328
|
+
const onBlurInternal = React.useCallback(() => {
|
|
1329
|
+
setFocused(hasFocus());
|
|
1330
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
1331
|
+
}, [onBlur]);
|
|
1338
1332
|
React.useEffect(() => {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
};
|
|
1343
|
-
const onBlurInternal = () => {
|
|
1344
|
-
setFocused(false);
|
|
1345
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
1346
|
-
};
|
|
1347
|
-
const handleVisibilityChange = () => {
|
|
1348
|
-
if (!document.hasFocus()) {
|
|
1349
|
-
onBlurInternal();
|
|
1350
|
-
}
|
|
1351
|
-
else {
|
|
1352
|
-
onFocusInternal();
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
window.addEventListener("visibilitychange", handleVisibilityChange);
|
|
1356
|
-
window.addEventListener("focus", handleVisibilityChange);
|
|
1357
|
-
window.addEventListener("blur", handleVisibilityChange);
|
|
1333
|
+
setFocused(hasFocus()); // Focus for additional renders
|
|
1334
|
+
window.addEventListener("focus", onFocusInternal);
|
|
1335
|
+
window.addEventListener("blur", onBlurInternal);
|
|
1358
1336
|
return () => {
|
|
1359
|
-
window.removeEventListener("
|
|
1360
|
-
window.removeEventListener("
|
|
1361
|
-
window.removeEventListener("blur", handleVisibilityChange);
|
|
1337
|
+
window.removeEventListener("focus", onFocusInternal);
|
|
1338
|
+
window.removeEventListener("blur", onBlurInternal);
|
|
1362
1339
|
};
|
|
1363
|
-
}, [
|
|
1340
|
+
}, [onBlurInternal, onFocusInternal]);
|
|
1364
1341
|
return { focused };
|
|
1365
1342
|
};
|
|
1366
1343
|
|
|
@@ -4945,5 +4922,4 @@ exports.usePrompt = usePrompt;
|
|
|
4945
4922
|
exports.useResize = useResize;
|
|
4946
4923
|
exports.useSelfUpdatingRef = useSelfUpdatingRef;
|
|
4947
4924
|
exports.useTimeout = useTimeout;
|
|
4948
|
-
exports.useVisibilityChange = useVisibilityChange;
|
|
4949
4925
|
exports.useWindowActivity = useWindowActivity;
|
package/index.esm.js
CHANGED
|
@@ -1017,6 +1017,9 @@ const useContinuousTimeout = ({ onTimeout, onMaxRetries, duration, maxRetries })
|
|
|
1017
1017
|
setIsRunning(false); // Update the status when stopped
|
|
1018
1018
|
};
|
|
1019
1019
|
const startTimeouts = () => {
|
|
1020
|
+
if (isRunning) {
|
|
1021
|
+
return; // Prevent multiple timeouts from running
|
|
1022
|
+
}
|
|
1020
1023
|
startTimeout();
|
|
1021
1024
|
setIsRunning(true); // Update the status when started
|
|
1022
1025
|
};
|
|
@@ -1292,55 +1295,29 @@ const useSelfUpdatingRef = (initialState) => {
|
|
|
1292
1295
|
return stateRef;
|
|
1293
1296
|
};
|
|
1294
1297
|
|
|
1295
|
-
/**
|
|
1296
|
-
* Returns a callback that will be called when the visibility state of the document changes.
|
|
1297
|
-
*/
|
|
1298
|
-
const useVisibilityChange = ({ onChange, targetState = "hidden" }) => {
|
|
1299
|
-
useEffect(() => {
|
|
1300
|
-
const handleVisibilityChange = () => {
|
|
1301
|
-
if (document.visibilityState === targetState) {
|
|
1302
|
-
onChange();
|
|
1303
|
-
}
|
|
1304
|
-
};
|
|
1305
|
-
window.addEventListener("visibilitychange", handleVisibilityChange);
|
|
1306
|
-
return () => {
|
|
1307
|
-
window.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
1308
|
-
};
|
|
1309
|
-
}, [onChange, targetState]);
|
|
1310
|
-
};
|
|
1311
|
-
|
|
1312
1298
|
const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
|
|
1313
1299
|
/**
|
|
1314
1300
|
* Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
|
|
1315
1301
|
*/
|
|
1316
|
-
const useWindowActivity = ({ onFocus, onBlur } = {}) => {
|
|
1302
|
+
const useWindowActivity = ({ onFocus, onBlur } = { onBlur: undefined, onFocus: undefined }) => {
|
|
1317
1303
|
const [focused, setFocused] = useState(hasFocus());
|
|
1304
|
+
const onFocusInternal = useCallback(() => {
|
|
1305
|
+
setFocused(hasFocus());
|
|
1306
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
1307
|
+
}, [onFocus]);
|
|
1308
|
+
const onBlurInternal = useCallback(() => {
|
|
1309
|
+
setFocused(hasFocus());
|
|
1310
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
1311
|
+
}, [onBlur]);
|
|
1318
1312
|
useEffect(() => {
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
};
|
|
1323
|
-
const onBlurInternal = () => {
|
|
1324
|
-
setFocused(false);
|
|
1325
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
1326
|
-
};
|
|
1327
|
-
const handleVisibilityChange = () => {
|
|
1328
|
-
if (!document.hasFocus()) {
|
|
1329
|
-
onBlurInternal();
|
|
1330
|
-
}
|
|
1331
|
-
else {
|
|
1332
|
-
onFocusInternal();
|
|
1333
|
-
}
|
|
1334
|
-
};
|
|
1335
|
-
window.addEventListener("visibilitychange", handleVisibilityChange);
|
|
1336
|
-
window.addEventListener("focus", handleVisibilityChange);
|
|
1337
|
-
window.addEventListener("blur", handleVisibilityChange);
|
|
1313
|
+
setFocused(hasFocus()); // Focus for additional renders
|
|
1314
|
+
window.addEventListener("focus", onFocusInternal);
|
|
1315
|
+
window.addEventListener("blur", onBlurInternal);
|
|
1338
1316
|
return () => {
|
|
1339
|
-
window.removeEventListener("
|
|
1340
|
-
window.removeEventListener("
|
|
1341
|
-
window.removeEventListener("blur", handleVisibilityChange);
|
|
1317
|
+
window.removeEventListener("focus", onFocusInternal);
|
|
1318
|
+
window.removeEventListener("blur", onBlurInternal);
|
|
1342
1319
|
};
|
|
1343
|
-
}, [
|
|
1320
|
+
}, [onBlurInternal, onFocusInternal]);
|
|
1344
1321
|
return { focused };
|
|
1345
1322
|
};
|
|
1346
1323
|
|
|
@@ -4829,4 +4806,4 @@ const cvaClickable = cvaMerge([
|
|
|
4829
4806
|
},
|
|
4830
4807
|
});
|
|
4831
4808
|
|
|
4832
|
-
export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, ToggleGroup, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout,
|
|
4809
|
+
export { Alert, Badge, Breadcrumb, BreadcrumbContainer, BreadcrumbItem, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyableText, Drawer, EmptyState, EmptyValue, ExternalLink, Heading, Icon, IconButton, Indicator, KPICard, MenuItem, MenuList, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, Pagination, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Prompt, ROLE_CARD, SectionHeader, Sidebar, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, Timeline, TimelineElement, ToggleGroup, Tooltip, ValueBar, VirtualizedList, WidgetBody, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaIconButton, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemSuffix, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, setLocalStorage, useClickOutside, useContainerProps, useContinuousTimeout, useDebounce, useDevicePixelRatio, useGeometry, useHover, useIsFirstRender, useIsFullscreen, useIsTextCutOff, useLocalStorage, useLocalStorageReducer, useOptionallyElevatedState, useOverflowItems, usePopoverContext, usePrompt, useResize, useSelfUpdatingRef, useTimeout, useWindowActivity };
|
package/package.json
CHANGED
package/src/hooks/index.d.ts
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type VisibilityState = "hidden" | "visible";
|
|
2
|
-
interface VisibilityChangeOptions {
|
|
3
|
-
onChange: () => void;
|
|
4
|
-
targetState: VisibilityState;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Returns a callback that will be called when the visibility state of the document changes.
|
|
8
|
-
*/
|
|
9
|
-
export declare const useVisibilityChange: ({ onChange, targetState }: VisibilityChangeOptions) => void;
|
|
10
|
-
export default useVisibilityChange;
|