@trackunit/react-components 3.12.3-alpha-4632fb37afe.0 → 4.0.0
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 +104 -959
- package/index.esm.js +102 -952
- package/migrations/assets/react-router-components/package.json +23 -0
- package/migrations/utils/move-named-imports.js +409 -0
- package/migrations/utils/package-json-utils.js +73 -0
- package/migrations/v4-0-0/move-to-router-components.js +71 -0
- package/migrations.json +5 -0
- package/package.json +6 -7
- package/src/components/ExternalLink/ExternalLink.d.ts +2 -2
- package/src/index.d.ts +0 -4
- package/translation.cjs.js +0 -1
- package/translation.esm.js +0 -1
- package/translation10.cjs.js +0 -1
- package/translation10.esm.js +0 -1
- package/translation11.cjs.js +0 -1
- package/translation11.esm.js +0 -1
- package/translation12.cjs.js +0 -1
- package/translation12.esm.js +0 -1
- package/translation13.cjs.js +0 -1
- package/translation13.esm.js +0 -1
- package/translation14.cjs.js +0 -1
- package/translation14.esm.js +0 -1
- package/translation15.cjs.js +0 -1
- package/translation15.esm.js +0 -1
- package/translation16.cjs.js +0 -1
- package/translation16.esm.js +0 -1
- package/translation17.cjs.js +0 -1
- package/translation17.esm.js +0 -1
- package/translation2.cjs.js +0 -1
- package/translation2.esm.js +0 -1
- package/translation3.cjs.js +0 -1
- package/translation3.esm.js +0 -1
- package/translation4.cjs.js +0 -1
- package/translation4.esm.js +0 -1
- package/translation5.cjs.js +0 -1
- package/translation5.esm.js +0 -1
- package/translation6.cjs.js +0 -1
- package/translation6.esm.js +0 -1
- package/translation7.cjs.js +0 -1
- package/translation7.esm.js +0 -1
- package/translation8.cjs.js +0 -1
- package/translation8.esm.js +0 -1
- package/translation9.cjs.js +0 -1
- package/translation9.esm.js +0 -1
- package/src/components/Breadcrumb/Breadcrumb.d.ts +0 -39
- package/src/components/Breadcrumb/Breadcrumb.variant.d.ts +0 -45
- package/src/components/Breadcrumb/BreadcrumbContainer.d.ts +0 -8
- package/src/components/Breadcrumb/BreadcrumbForLargeScreen.d.ts +0 -6
- package/src/components/Breadcrumb/BreadcrumbForMediumScreen.d.ts +0 -6
- package/src/components/Breadcrumb/BreadcrumbForSmallScreen.d.ts +0 -6
- package/src/components/Breadcrumb/BreadcrumbItem.d.ts +0 -6
- package/src/components/Breadcrumb/utils/types.d.ts +0 -28
- package/src/components/Breadcrumb/utils/useBreadcrumbItemsToRender.d.ts +0 -6
- package/src/hooks/persistence/hashFragment.d.ts +0 -70
- package/src/hooks/persistence/readPrimitiveSearchParam.d.ts +0 -8
- package/src/hooks/persistence/urlIdentity.d.ts +0 -64
- package/src/hooks/persistence/usePersistedState.d.ts +0 -117
- package/src/hooks/persistence/useSearchParamSync.d.ts +0 -17
- package/src/hooks/persistence/useUrlParamSync.d.ts +0 -71
- package/src/hooks/useCursorUrlSync.d.ts +0 -23
package/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { twMerge } from 'tailwind-merge';
|
|
4
|
-
import { objectKeys, uuidv4, parseTailwindArbitraryValue,
|
|
4
|
+
import { objectKeys, uuidv4, parseTailwindArbitraryValue, nonNullable, objectValues, validateState, writeToStorage, readFromStorage, identityFingerprint, listHashKeys, readHashKey, unwrapUrlOwner, writeHashKey, objectEntries, filterByMultiple } from '@trackunit/shared-utils';
|
|
5
5
|
export { storageSerializer } from '@trackunit/shared-utils';
|
|
6
6
|
import { useRef, useMemo, useEffect, useSyncExternalStore, useState, useLayoutEffect, createContext, useContext, isValidElement, cloneElement, createElement, useId, useCallback, Fragment as Fragment$1, memo, forwardRef, useReducer, Children } from 'react';
|
|
7
|
-
import { rentalStatusPalette, sitesPalette, utilizationPalette, activityPalette, criticalityPalette, trackunitBrandingPalette, generalPalette, intentPalette,
|
|
7
|
+
import { rentalStatusPalette, sitesPalette, utilizationPalette, activityPalette, criticalityPalette, trackunitBrandingPalette, generalPalette, intentPalette, themeContainerSize, color, themeScreenSizeAsNumber } from '@trackunit/ui-design-tokens';
|
|
8
8
|
import { iconNames } from '@trackunit/ui-icons';
|
|
9
9
|
import IconSpriteMicro from '@trackunit/ui-icons/icons-sprite-micro.svg';
|
|
10
10
|
import IconSpriteMini from '@trackunit/ui-icons/icons-sprite-mini.svg';
|
|
@@ -15,18 +15,15 @@ import { cva } from '@trackunit/css-class-variance-utilities';
|
|
|
15
15
|
import { FloatingTree, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, offset, flip, shift, size, useFloating, autoUpdate, useClick, useDismiss, useHover as useHover$1, safePolygon, useRole, useInteractions, FloatingNode, FloatingPortal, useMergeRefs as useMergeRefs$1, FloatingFocusManager, arrow, useTransitionStatus, FloatingArrow, useListNavigation, useTypeahead, FloatingList, useListItem } from '@floating-ui/react';
|
|
16
16
|
import { Slot, Slottable } from '@radix-ui/react-slot';
|
|
17
17
|
import { omit, isEqual } from 'es-toolkit';
|
|
18
|
-
import { Link, useBlocker
|
|
18
|
+
import { Link, useBlocker } from '@tanstack/react-router';
|
|
19
19
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
20
20
|
import { isTypeableElement } from '@floating-ui/react/utils';
|
|
21
21
|
import { HelmetProvider, Helmet } from 'react-helmet-async';
|
|
22
22
|
import { Trigger, Content, List as List$1, Root } from '@radix-ui/react-tabs';
|
|
23
23
|
import { gzipSync, gunzipSync } from 'fflate';
|
|
24
|
-
import { dequal } from 'dequal';
|
|
25
|
-
import { z } from 'zod';
|
|
26
24
|
|
|
27
25
|
var defaultTranslations = {
|
|
28
26
|
"breadcrumb.backButton": "Back",
|
|
29
|
-
"breadcrumb.expandButton": "expand",
|
|
30
27
|
"copyableValue.copyValue": "Copy {{value}}",
|
|
31
28
|
"copyButton.copied": "Copied!",
|
|
32
29
|
"copyButton.copy": "Copy",
|
|
@@ -3878,235 +3875,6 @@ const Badge = ({ color = "primary", size = "default", compact = false, className
|
|
|
3878
3875
|
return (jsx("span", { className: cvaBadge({ color, size, className, compact, isSingleChar }), "data-testid": dataTestId, ref: ref, style: style, children: compact ? null : displayedCount }));
|
|
3879
3876
|
};
|
|
3880
3877
|
|
|
3881
|
-
const cvaBreadcrumb = cva({ base: ["my-4", "flex", "place-items-center"] });
|
|
3882
|
-
const cvaBreadcrumbItem = cva({ base: ["flex", "items-center"] });
|
|
3883
|
-
const cvaBreadcrumbForLargeScreen = cva({ base: ["flex", "flex-nowrap", "items-center"] });
|
|
3884
|
-
const cvaBreadcrumbForMediumScreen = cva({
|
|
3885
|
-
base: ["flex", "items-center"],
|
|
3886
|
-
variants: {
|
|
3887
|
-
expanded: {
|
|
3888
|
-
true: "flex-wrap",
|
|
3889
|
-
false: "flex-nowrap",
|
|
3890
|
-
},
|
|
3891
|
-
},
|
|
3892
|
-
defaultVariants: { expanded: false },
|
|
3893
|
-
});
|
|
3894
|
-
|
|
3895
|
-
/**
|
|
3896
|
-
* Maps size keys to their corresponding state property names.
|
|
3897
|
-
*/
|
|
3898
|
-
const breakpointPropsMap = {
|
|
3899
|
-
xs: "isXs",
|
|
3900
|
-
sm: "isSm",
|
|
3901
|
-
md: "isMd",
|
|
3902
|
-
lg: "isLg",
|
|
3903
|
-
xl: "isXl",
|
|
3904
|
-
"2xl": "is2xl",
|
|
3905
|
-
"3xl": "is3xl",
|
|
3906
|
-
};
|
|
3907
|
-
/**
|
|
3908
|
-
* The default state for sizes, with all values set to false.
|
|
3909
|
-
*/
|
|
3910
|
-
const defaultBreakpointState = {
|
|
3911
|
-
isXs: false,
|
|
3912
|
-
isSm: false,
|
|
3913
|
-
isMd: false,
|
|
3914
|
-
isLg: false,
|
|
3915
|
-
isXl: false,
|
|
3916
|
-
is2xl: false,
|
|
3917
|
-
is3xl: false,
|
|
3918
|
-
};
|
|
3919
|
-
/**
|
|
3920
|
-
* Creates a breakpoint state object based on a width value
|
|
3921
|
-
*/
|
|
3922
|
-
const createBreakpointState = ({ width }) => {
|
|
3923
|
-
return objectEntries(themeScreenSizeAsNumber).reduce((acc, [size, minWidth]) => ({
|
|
3924
|
-
...acc,
|
|
3925
|
-
[breakpointPropsMap[size]]: width >= minWidth,
|
|
3926
|
-
}), { ...defaultBreakpointState });
|
|
3927
|
-
};
|
|
3928
|
-
|
|
3929
|
-
const canUseMatchMedia = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
3930
|
-
const getViewportBreakpointState = () => {
|
|
3931
|
-
if (!canUseMatchMedia())
|
|
3932
|
-
return { ...defaultBreakpointState };
|
|
3933
|
-
return objectEntries(themeScreenSizeAsNumber).reduce((acc, [size, minWidth]) => ({
|
|
3934
|
-
...acc,
|
|
3935
|
-
[breakpointPropsMap[size]]: window.matchMedia(`(min-width: ${minWidth}px)`).matches,
|
|
3936
|
-
}), { ...defaultBreakpointState });
|
|
3937
|
-
};
|
|
3938
|
-
/**
|
|
3939
|
-
* Returns real-time boolean flags for each design-token breakpoint based on viewport width.
|
|
3940
|
-
*
|
|
3941
|
-
* **When to use:**
|
|
3942
|
-
* - Use `useViewportBreakpoints` when you need to respond to the **full viewport width**
|
|
3943
|
-
* — for example, toggling a mobile navigation drawer or switching a global layout shell.
|
|
3944
|
-
* - **Prefer `useContainerBreakpoints`** for component-level responsiveness, as it
|
|
3945
|
-
* responds to the parent container's width and works correctly when a component appears
|
|
3946
|
-
* in different layout contexts (sidebar, main content, widget).
|
|
3947
|
-
* - Pass `{ skip: true }` when you only need the initial value and don't want ongoing
|
|
3948
|
-
* `matchMedia` listeners.
|
|
3949
|
-
*
|
|
3950
|
-
* @param {object} [options] - Configuration options
|
|
3951
|
-
* @param {boolean} [options.skip] - Whether to skip observing for viewport changes (default: false)
|
|
3952
|
-
* @returns {BreakpointState} An object containing boolean values for each viewport size breakpoint.
|
|
3953
|
-
* @example
|
|
3954
|
-
* const MyComponent = () => {
|
|
3955
|
-
* const viewportSize = useViewportBreakpoints();
|
|
3956
|
-
*
|
|
3957
|
-
* if (viewportSize.isLg) {
|
|
3958
|
-
* return <LargeScreenLayout />;
|
|
3959
|
-
* }
|
|
3960
|
-
*
|
|
3961
|
-
* return viewportSize.isMd ? <MediumScreenLayout /> : <SmallLayout />;
|
|
3962
|
-
* }
|
|
3963
|
-
*/
|
|
3964
|
-
const useViewportBreakpoints = (options = {}) => {
|
|
3965
|
-
const { skip = false } = options;
|
|
3966
|
-
const [viewportSize, setViewportSize] = useState(getViewportBreakpointState);
|
|
3967
|
-
const updateViewportSize = useCallback(() => {
|
|
3968
|
-
setViewportSize(getViewportBreakpointState());
|
|
3969
|
-
}, []);
|
|
3970
|
-
const updateViewportSizeRef = useRef(updateViewportSize);
|
|
3971
|
-
useEffect(() => {
|
|
3972
|
-
updateViewportSizeRef.current = updateViewportSize;
|
|
3973
|
-
}, [updateViewportSize]);
|
|
3974
|
-
useEffect(() => {
|
|
3975
|
-
if (skip || !canUseMatchMedia()) {
|
|
3976
|
-
return;
|
|
3977
|
-
}
|
|
3978
|
-
updateViewportSizeRef.current();
|
|
3979
|
-
const mediaQueryLists = objectEntries(themeScreenSizeAsNumber).map(([_, minWidth]) => window.matchMedia(`(min-width: ${minWidth}px)`));
|
|
3980
|
-
mediaQueryLists.forEach(mql => {
|
|
3981
|
-
mql.addEventListener("change", updateViewportSizeRef.current);
|
|
3982
|
-
});
|
|
3983
|
-
return () => {
|
|
3984
|
-
mediaQueryLists.forEach(mql => {
|
|
3985
|
-
mql.removeEventListener("change", updateViewportSizeRef.current);
|
|
3986
|
-
});
|
|
3987
|
-
};
|
|
3988
|
-
}, [skip]);
|
|
3989
|
-
return viewportSize;
|
|
3990
|
-
};
|
|
3991
|
-
|
|
3992
|
-
/**
|
|
3993
|
-
* BreadcrumbItem is a helper component that renders the individual breadcrumb item.
|
|
3994
|
-
*/
|
|
3995
|
-
const BreadcrumbItem = ({ item, "data-testid": dataTestId, className, style, }) => {
|
|
3996
|
-
const id = uuidv4();
|
|
3997
|
-
return (jsx("div", { className: cvaBreadcrumbItem({ className }), "data-testid": dataTestId, id: `${item.props.label}-${id}`, style: style, children: item }));
|
|
3998
|
-
};
|
|
3999
|
-
|
|
4000
|
-
/**
|
|
4001
|
-
* BreadcrumbForLargeScreen is a helper component that renders the breadcrumb items for large screens.
|
|
4002
|
-
*/
|
|
4003
|
-
const BreadcrumbForLargeScreen = ({ "data-testid": dataTestId, breadcrumbItems, className, style, }) => {
|
|
4004
|
-
return (jsx("div", { className: cvaBreadcrumbForLargeScreen({ className }), "data-testid": dataTestId, style: style, children: breadcrumbItems.map((item, index) => (jsx(BreadcrumbItem, { "data-testid": `BreadcrumbItem-${dataTestId}`, item: item }, `breadcrumbItem-${index}`))) }));
|
|
4005
|
-
};
|
|
4006
|
-
|
|
4007
|
-
/**
|
|
4008
|
-
* BreadcrumbForMediumScreen is a helper component that renders the breadcrumb items for medium screens.
|
|
4009
|
-
*/
|
|
4010
|
-
const BreadcrumbForMediumScreen = ({ "data-testid": dataTestId, breadcrumbItems, className, style, }) => {
|
|
4011
|
-
const [t] = useTranslation();
|
|
4012
|
-
const [expanded, setExpanded] = useState(false);
|
|
4013
|
-
const getReducedArray = useCallback(() => {
|
|
4014
|
-
let reducedArrayElements = [];
|
|
4015
|
-
const collapsibleButton = (jsxs("div", { className: cvaBreadcrumbItem(), children: [jsx(IconButton, { "data-testid": `collapsibleButton-${dataTestId}`, icon: jsx(Icon, { name: "EllipsisHorizontal" }), onClick: () => setExpanded(true), size: "small", title: t("breadcrumb.expandButton"), variant: "ghost-neutral" }), jsx(Icon, { className: "text-neutral-300", name: "Slash", size: "small" })] }));
|
|
4016
|
-
const firstBreadcrumbItem = breadcrumbItems[0];
|
|
4017
|
-
if (firstBreadcrumbItem && breadcrumbItems.length > 3) {
|
|
4018
|
-
const lastTwoBreadcrumbItem = breadcrumbItems.slice(-2);
|
|
4019
|
-
reducedArrayElements = [firstBreadcrumbItem, collapsibleButton, ...lastTwoBreadcrumbItem];
|
|
4020
|
-
}
|
|
4021
|
-
return reducedArrayElements;
|
|
4022
|
-
}, [breadcrumbItems, dataTestId, t]);
|
|
4023
|
-
const reducedArray = getReducedArray();
|
|
4024
|
-
return (jsx("div", { className: cvaBreadcrumbForMediumScreen({ className, expanded }), "data-testid": dataTestId, style: style, children: (!expanded && reducedArray.length !== 0 ? reducedArray : breadcrumbItems).map(item => (jsx(BreadcrumbItem, { "data-testid": `breadcrumbItem-${dataTestId}`, item: item }, `${item.props.label}-${uuidv4()}`))) }));
|
|
4025
|
-
};
|
|
4026
|
-
|
|
4027
|
-
/**
|
|
4028
|
-
* BreadcrumbForSmallScreen is a helper component that renders the breadcrumb items for small screens.
|
|
4029
|
-
*/
|
|
4030
|
-
const BreadcrumbForSmallScreen = ({ "data-testid": dataTestId, breadcrumbItems, className, style, }) => {
|
|
4031
|
-
const lastBreadcrumbItem = breadcrumbItems.slice(-1);
|
|
4032
|
-
return (jsx("div", { className: className, "data-testid": dataTestId, style: style, children: lastBreadcrumbItem.map((item, index) => (jsx(BreadcrumbItem, { "data-testid": `breadcrumbItem-${dataTestId}`, item: item }, `breadcrumbItem-${index}`))) }));
|
|
4033
|
-
};
|
|
4034
|
-
|
|
4035
|
-
/**
|
|
4036
|
-
* BreadcrumbContainer is a helper component that renders the breadcrumb items based on the screen size.
|
|
4037
|
-
*
|
|
4038
|
-
* @param {BreadcrumbContainerProps} props - The props for the BreadcrumbContainer component
|
|
4039
|
-
*/
|
|
4040
|
-
const BreadcrumbContainer = ({ className, "data-testid": dataTestId, breadcrumbItems, style, ref, }) => {
|
|
4041
|
-
const { isLg: isLargeScreen, isMd: isMediumScreen, isXs: isSmallScreen } = useViewportBreakpoints();
|
|
4042
|
-
const sharedContainerProps = { className, "data-testid": dataTestId, ref, style };
|
|
4043
|
-
if (isLargeScreen) {
|
|
4044
|
-
return (jsx("div", { ...sharedContainerProps, children: jsx(BreadcrumbForLargeScreen, { breadcrumbItems: breadcrumbItems, "data-testid": `largeScreen-${dataTestId}` }) }));
|
|
4045
|
-
}
|
|
4046
|
-
if (isMediumScreen) {
|
|
4047
|
-
return (jsx("div", { ...sharedContainerProps, children: jsx(BreadcrumbForMediumScreen, { breadcrumbItems: breadcrumbItems, "data-testid": `mediumScreen-${dataTestId}` }) }));
|
|
4048
|
-
}
|
|
4049
|
-
if (isSmallScreen) {
|
|
4050
|
-
return (jsx("div", { ...sharedContainerProps, children: jsx(BreadcrumbForSmallScreen, { breadcrumbItems: breadcrumbItems, "data-testid": `smallScreen-${dataTestId}` }) }));
|
|
4051
|
-
}
|
|
4052
|
-
return (jsx("div", { ...sharedContainerProps, children: jsx(BreadcrumbForLargeScreen, { breadcrumbItems: breadcrumbItems, "data-testid": `largeScreen-${dataTestId}` }) }));
|
|
4053
|
-
};
|
|
4054
|
-
|
|
4055
|
-
/**
|
|
4056
|
-
* useBreadcrumbItemsToRender is a custom hook that takes an array of BreadcrumbItemProps and returns an array of React.ReactElement
|
|
4057
|
-
*/
|
|
4058
|
-
const useBreadcrumbItemsToRender = (breadcrumbItems) => {
|
|
4059
|
-
return useMemo(() => breadcrumbItems.map((item, index, array) => {
|
|
4060
|
-
const isLast = index === array.length - 1;
|
|
4061
|
-
if (!isLast) {
|
|
4062
|
-
return (jsxs("div", { className: "flex items-center", children: [jsx(Button, { asChild: true, size: "small", variant: "ghost-neutral", children: jsx(Link, { to: item.to, children: item.label }) }), jsx(Icon, { className: "text-neutral-300", name: "Slash", size: "small" })] }, index));
|
|
4063
|
-
}
|
|
4064
|
-
return (jsx(Text, { className: "text-nowrap pl-2 font-medium", size: "small", children: item.label }, index));
|
|
4065
|
-
}), [breadcrumbItems]);
|
|
4066
|
-
};
|
|
4067
|
-
|
|
4068
|
-
/**
|
|
4069
|
-
* The breadcrumb component shows a user's location in a website or application. Breadcrumbs are particularly useful when a large amount of content is organized in a hierarchical manner. They streamline navigation, minimize the steps required to revisit previous pages, and offer contextual insights to the users.
|
|
4070
|
-
*
|
|
4071
|
-
* All items except the last are rendered as clickable links. The last item is rendered as plain text representing the current page.
|
|
4072
|
-
* The component automatically adapts to the screen size: on large screens all items are visible, on medium screens middle items collapse behind an ellipsis button, and on small screens only the current page is shown.
|
|
4073
|
-
*
|
|
4074
|
-
* ### When to use
|
|
4075
|
-
* Use breadcrumbs when deep navigation is available, on apps or pages where users might dive into content and could benefit from a quick way to return to higher levels. Breadcrumbs display the current screen as the final item in the list to make it clear where the user is.
|
|
4076
|
-
*
|
|
4077
|
-
* ### When not to use
|
|
4078
|
-
* Do not use on the first hierarchal level, such as a home page or a main page, as there is no previous step the user can get to.
|
|
4079
|
-
* Avoid using breadcrumbs to indicate forthcoming steps. For processes with sequential steps, use a wizard flow instead.
|
|
4080
|
-
*
|
|
4081
|
-
* @example Basic breadcrumb navigation
|
|
4082
|
-
* ```tsx
|
|
4083
|
-
* import { Breadcrumb } from "@trackunit/react-components";
|
|
4084
|
-
* import { useNavigate } from "@tanstack/react-router";
|
|
4085
|
-
*
|
|
4086
|
-
* const AssetDetailBreadcrumb = () => {
|
|
4087
|
-
* const navigate = useNavigate();
|
|
4088
|
-
*
|
|
4089
|
-
* return (
|
|
4090
|
-
* <Breadcrumb
|
|
4091
|
-
* breadcrumbItems={[
|
|
4092
|
-
* { label: "Fleet", to: "/fleet" },
|
|
4093
|
-
* { label: "Assets", to: "/fleet/assets" },
|
|
4094
|
-
* { label: "Excavator 001", to: "/fleet/assets/123" },
|
|
4095
|
-
* ]}
|
|
4096
|
-
* onClickBack={() => navigate({ to: "/fleet/assets" })}
|
|
4097
|
-
* />
|
|
4098
|
-
* );
|
|
4099
|
-
* };
|
|
4100
|
-
* ```
|
|
4101
|
-
* @param {BreadcrumbProps} props - The props for the Breadcrumb component
|
|
4102
|
-
* @returns {ReactElement} Breadcrumb component
|
|
4103
|
-
*/
|
|
4104
|
-
const Breadcrumb = ({ className, "data-testid": dataTestId, breadcrumbItems, onClickBack, style, ref, }) => {
|
|
4105
|
-
const [t] = useTranslation();
|
|
4106
|
-
const breadCrumbItemsToJSX = useBreadcrumbItemsToRender(breadcrumbItems);
|
|
4107
|
-
return (jsxs("div", { className: cvaBreadcrumb({ className }), "data-testid": dataTestId, ref: ref, style: style, children: [jsx(IconButton, { "data-testid": `backButton-${dataTestId}`, icon: jsx(Icon, { name: "ArrowLeft", size: "small" }), onClick: onClickBack, size: "small", title: t("breadcrumb.backButton"), variant: "ghost-neutral" }), jsx("div", { children: jsx(BreadcrumbContainer, { breadcrumbItems: breadCrumbItemsToJSX, "data-testid": dataTestId }) })] }));
|
|
4108
|
-
};
|
|
4109
|
-
|
|
4110
3878
|
/**
|
|
4111
3879
|
* StarButton renders a clickable star icon for toggling favorite/starred state.
|
|
4112
3880
|
* The star appears in the primary color when starred and neutral when unstarred.
|
|
@@ -5137,7 +4905,7 @@ const cvaExternalLink = cva({
|
|
|
5137
4905
|
* Use ExternalLink for any links that navigate to external resources outside the application (e.g., documentation, support pages, vendor sites).
|
|
5138
4906
|
*
|
|
5139
4907
|
* ### When not to use
|
|
5140
|
-
* Do not use ExternalLink for in-app navigation. Use `
|
|
4908
|
+
* Do not use ExternalLink for in-app navigation. Use `RouteLink` from `@trackunit/react-router-components` for in-app routes.
|
|
5141
4909
|
*
|
|
5142
4910
|
* @example Basic external link
|
|
5143
4911
|
* ```tsx
|
|
@@ -13525,76 +13293,6 @@ const useSessionStorage = (options) => useWebStorage(globalThis.sessionStorage,
|
|
|
13525
13293
|
*/
|
|
13526
13294
|
const useSessionStorageReducer = (options) => useWebStorageReducer(globalThis.sessionStorage, options);
|
|
13527
13295
|
|
|
13528
|
-
/**
|
|
13529
|
-
* Pure utilities for stamping a URL-persisted value with the identity that
|
|
13530
|
-
* wrote it.
|
|
13531
|
-
*
|
|
13532
|
-
* A URL (hash or search param) is shared by every account that uses the same
|
|
13533
|
-
* browser: it survives login redirects, history and bookmarks, and it takes
|
|
13534
|
-
* precedence over per-user localStorage when a page loads. Without a stamp
|
|
13535
|
-
* there is no way to tell "a colleague shared this link" from "the previous
|
|
13536
|
-
* account on this PC left its layout in the address bar" — and the second
|
|
13537
|
-
* case silently replaces the current user's saved state (GLU-2396).
|
|
13538
|
-
*
|
|
13539
|
-
* The stamp is a short, non-reversible fingerprint of `clientSideUserId`.
|
|
13540
|
-
* It is not a secret and not a security boundary; it only lets a reader
|
|
13541
|
-
* recognise a value written by a *different* identity on the same device.
|
|
13542
|
-
*/
|
|
13543
|
-
/**
|
|
13544
|
-
* Wire shape of a stamped URL value: `{ o: <fingerprint>, v: <payload> }`.
|
|
13545
|
-
* Values written before stamping existed are bare payloads and decode as
|
|
13546
|
-
* unowned (see {@link unwrapUrlOwner}).
|
|
13547
|
-
*/
|
|
13548
|
-
const stampedUrlValueSchema = z.object({
|
|
13549
|
-
o: z.string(),
|
|
13550
|
-
v: z.unknown(),
|
|
13551
|
-
});
|
|
13552
|
-
const FNV_OFFSET_BASIS = 0x811c9dc5;
|
|
13553
|
-
const FNV_PRIME = 0x01000193;
|
|
13554
|
-
/**
|
|
13555
|
-
* 32-bit FNV-1a of `identity`, rendered in base36 (≤ 7 chars).
|
|
13556
|
-
*
|
|
13557
|
-
* Synchronous and dependency-free so it can run inside a `useState`
|
|
13558
|
-
* initializer. Collisions are possible in theory but irrelevant here: a
|
|
13559
|
-
* collision can only make a foreign value look like the reader's own, which
|
|
13560
|
-
* is today's behaviour for every value.
|
|
13561
|
-
*
|
|
13562
|
-
* @param identity - The client-side user id to fingerprint.
|
|
13563
|
-
* @returns {string} A short stable fingerprint of `identity`.
|
|
13564
|
-
*/
|
|
13565
|
-
const identityFingerprint = (identity) => {
|
|
13566
|
-
let hash = FNV_OFFSET_BASIS;
|
|
13567
|
-
for (let index = 0; index < identity.length; index++) {
|
|
13568
|
-
hash ^= identity.charCodeAt(index);
|
|
13569
|
-
hash = Math.imul(hash, FNV_PRIME) >>> 0;
|
|
13570
|
-
}
|
|
13571
|
-
return hash.toString(36);
|
|
13572
|
-
};
|
|
13573
|
-
/**
|
|
13574
|
-
* Wraps a URL payload with the fingerprint of the identity writing it.
|
|
13575
|
-
*
|
|
13576
|
-
* @param value - The payload that would otherwise be encoded into the URL.
|
|
13577
|
-
* @param owner - Fingerprint of the writing identity (see {@link identityFingerprint}).
|
|
13578
|
-
* @returns {StampedUrlValue} The payload wrapped in its ownership envelope.
|
|
13579
|
-
*/
|
|
13580
|
-
const wrapUrlOwner = (value, owner) => ({ o: owner, v: value });
|
|
13581
|
-
/**
|
|
13582
|
-
* Splits a decoded URL value into its owner fingerprint and payload.
|
|
13583
|
-
* Bare (pre-stamping) payloads come back with `owner: undefined`.
|
|
13584
|
-
*
|
|
13585
|
-
* @param decoded - The decoded URL value, stamped or bare.
|
|
13586
|
-
* @returns {{ owner: string | undefined; value: unknown }} The owner fingerprint (if any) and the payload.
|
|
13587
|
-
*/
|
|
13588
|
-
const unwrapUrlOwner = (decoded) => {
|
|
13589
|
-
const stamped = stampedUrlValueSchema.safeParse(decoded);
|
|
13590
|
-
// `z.unknown()` accepts a missing key, so `{ o: "x" }` parses without `v`.
|
|
13591
|
-
// Such an object is a payload of its own, not an envelope; the `in` check
|
|
13592
|
-
// is what keeps it unowned. Do not remove it as redundant.
|
|
13593
|
-
return stamped.success && "v" in stamped.data
|
|
13594
|
-
? { owner: stamped.data.o, value: stamped.data.v }
|
|
13595
|
-
: { owner: undefined, value: decoded };
|
|
13596
|
-
};
|
|
13597
|
-
|
|
13598
13296
|
/**
|
|
13599
13297
|
* Generates a localStorage key, optionally scoped to a specific user.
|
|
13600
13298
|
*
|
|
@@ -13609,580 +13307,6 @@ const useStorageKey = (key, userId) => {
|
|
|
13609
13307
|
return useMemo(() => (userId ? `${key}-${userId}` : key), [key, userId]);
|
|
13610
13308
|
};
|
|
13611
13309
|
|
|
13612
|
-
/**
|
|
13613
|
-
* Pure utilities for reading and writing single named entries inside a URL
|
|
13614
|
-
* fragment (the part after `#`).
|
|
13615
|
-
*
|
|
13616
|
-
* # Format contract
|
|
13617
|
-
*
|
|
13618
|
-
* The fragment body (after the leading `#`) is treated as a sequence of
|
|
13619
|
-
* `&`-separated tokens. A token may be:
|
|
13620
|
-
* - **A named entry** — `<key>=<value>` (the first `=` separates key from
|
|
13621
|
-
* value; later `=` chars are part of the value).
|
|
13622
|
-
* - **Foreign content** — anything else (bare scroll anchors like
|
|
13623
|
-
* `section`, hash routes, third-party data, malformed tokens). Foreign
|
|
13624
|
-
* tokens are preserved byte-for-byte, in their original positions.
|
|
13625
|
-
*
|
|
13626
|
-
* # Single-key ownership
|
|
13627
|
-
*
|
|
13628
|
-
* Callers operate on **one** named key per invocation. Every token whose
|
|
13629
|
-
* key does not match the supplied key is foreign — the utility never
|
|
13630
|
-
* categorises or rewrites it. This mirrors how `useSearchParamSync`
|
|
13631
|
-
* treats a single named search param.
|
|
13632
|
-
*
|
|
13633
|
-
* # Value-encoding invariant
|
|
13634
|
-
*
|
|
13635
|
-
* Values passed to {@link writeHashKey} must not contain `&`, `=`, or `#`.
|
|
13636
|
-
* The standard producer for this codebase is `useCustomEncoding`, whose
|
|
13637
|
-
* base64url alphabet (`[A-Za-z0-9_-]`) satisfies the invariant by
|
|
13638
|
-
* construction. Keys are restricted by the existing persistence-key
|
|
13639
|
-
* schema (camelCase, ≤15 chars), so they are likewise safe.
|
|
13640
|
-
*
|
|
13641
|
-
* # Anchor-scroll caveat
|
|
13642
|
-
*
|
|
13643
|
-
* Browsers locate scroll targets by matching the entire fragment string
|
|
13644
|
-
* against element IDs. Appending a named entry to a fragment containing
|
|
13645
|
-
* a bare anchor (e.g. `#section` becoming `#section&userTableTp=...`)
|
|
13646
|
-
* therefore breaks anchor scrolling on that page. This is unavoidable
|
|
13647
|
-
* for any hash-backed shared state. Consumers that rely on scroll
|
|
13648
|
-
* anchors should not also persist state to the hash on the same route.
|
|
13649
|
-
*/
|
|
13650
|
-
const TOKEN_SEPARATOR = "&";
|
|
13651
|
-
const KEY_VALUE_SEPARATOR = "=";
|
|
13652
|
-
const stripLeadingHash = (hash) => (hash.startsWith("#") ? hash.slice(1) : hash);
|
|
13653
|
-
const formatHash = (body) => (body.length === 0 ? "" : `#${body}`);
|
|
13654
|
-
/**
|
|
13655
|
-
* Reads the value of a single named entry from a URL fragment.
|
|
13656
|
-
*
|
|
13657
|
-
* @param hash - The fragment string, with or without the leading `#`.
|
|
13658
|
-
* @param key - The entry key to look up.
|
|
13659
|
-
* @returns {string | undefined} The raw value (everything after the first
|
|
13660
|
-
* `=` in the matching token), or `undefined` when the key is absent. An
|
|
13661
|
-
* entry whose token has no `=` is treated as foreign content and ignored.
|
|
13662
|
-
*/
|
|
13663
|
-
const readHashKey = (hash, key) => {
|
|
13664
|
-
const body = stripLeadingHash(hash);
|
|
13665
|
-
if (body.length === 0) {
|
|
13666
|
-
return undefined;
|
|
13667
|
-
}
|
|
13668
|
-
for (const token of body.split(TOKEN_SEPARATOR)) {
|
|
13669
|
-
const eqIndex = token.indexOf(KEY_VALUE_SEPARATOR);
|
|
13670
|
-
if (eqIndex > 0 && token.slice(0, eqIndex) === key) {
|
|
13671
|
-
return token.slice(eqIndex + 1);
|
|
13672
|
-
}
|
|
13673
|
-
}
|
|
13674
|
-
return undefined;
|
|
13675
|
-
};
|
|
13676
|
-
/**
|
|
13677
|
-
* Lists the key of every named entry in a URL fragment, in order of first
|
|
13678
|
-
* appearance. Foreign tokens (no `=`) are skipped and duplicates collapse.
|
|
13679
|
-
*
|
|
13680
|
-
* @param hash - The fragment string, with or without the leading `#`.
|
|
13681
|
-
* @returns {Array<string>} The distinct entry keys.
|
|
13682
|
-
*/
|
|
13683
|
-
const listHashKeys = (hash) => {
|
|
13684
|
-
const body = stripLeadingHash(hash);
|
|
13685
|
-
if (body.length === 0) {
|
|
13686
|
-
return [];
|
|
13687
|
-
}
|
|
13688
|
-
const keys = [];
|
|
13689
|
-
for (const token of body.split(TOKEN_SEPARATOR)) {
|
|
13690
|
-
const eqIndex = token.indexOf(KEY_VALUE_SEPARATOR);
|
|
13691
|
-
if (eqIndex > 0) {
|
|
13692
|
-
const key = token.slice(0, eqIndex);
|
|
13693
|
-
if (!keys.includes(key)) {
|
|
13694
|
-
keys.push(key);
|
|
13695
|
-
}
|
|
13696
|
-
}
|
|
13697
|
-
}
|
|
13698
|
-
return keys;
|
|
13699
|
-
};
|
|
13700
|
-
/**
|
|
13701
|
-
* Returns a new fragment string with the named entry written, replaced,
|
|
13702
|
-
* or removed. Foreign tokens are preserved in their original order; the
|
|
13703
|
-
* named entry retains its position if it already exists, and is appended
|
|
13704
|
-
* to the end when newly inserted. Empty tokens (e.g. produced by
|
|
13705
|
-
* consecutive `&`) are dropped on the way out.
|
|
13706
|
-
*
|
|
13707
|
-
* @param hash - The current fragment string, with or without the leading `#`.
|
|
13708
|
-
* @param key - The entry key to write.
|
|
13709
|
-
* @param value - The value to set, or `undefined` to remove the entry.
|
|
13710
|
-
* @returns {string} The new fragment string, including a leading `#` when
|
|
13711
|
-
* non-empty, or an empty string when the result has no tokens left.
|
|
13712
|
-
*/
|
|
13713
|
-
const writeHashKey = (hash, key, value) => {
|
|
13714
|
-
const body = stripLeadingHash(hash);
|
|
13715
|
-
const tokens = body.length === 0 ? [] : body.split(TOKEN_SEPARATOR);
|
|
13716
|
-
const next = [];
|
|
13717
|
-
let replaced = false;
|
|
13718
|
-
for (const token of tokens) {
|
|
13719
|
-
if (token.length === 0) {
|
|
13720
|
-
continue;
|
|
13721
|
-
}
|
|
13722
|
-
const eqIndex = token.indexOf(KEY_VALUE_SEPARATOR);
|
|
13723
|
-
if (eqIndex > 0 && token.slice(0, eqIndex) === key) {
|
|
13724
|
-
if (value !== undefined && !replaced) {
|
|
13725
|
-
next.push(`${key}${KEY_VALUE_SEPARATOR}${value}`);
|
|
13726
|
-
replaced = true;
|
|
13727
|
-
}
|
|
13728
|
-
// Else: drop the token (either removing the key or dropping a
|
|
13729
|
-
// duplicate occurrence after we already wrote the replacement).
|
|
13730
|
-
continue;
|
|
13731
|
-
}
|
|
13732
|
-
next.push(token);
|
|
13733
|
-
}
|
|
13734
|
-
if (value !== undefined && !replaced) {
|
|
13735
|
-
next.push(`${key}${KEY_VALUE_SEPARATOR}${value}`);
|
|
13736
|
-
}
|
|
13737
|
-
return formatHash(next.join(TOKEN_SEPARATOR));
|
|
13738
|
-
};
|
|
13739
|
-
|
|
13740
|
-
const searchRecordSchema = z.record(z.string(), z.unknown());
|
|
13741
|
-
const primitiveSearchValueSchema = z.union([z.string(), z.number(), z.boolean()]);
|
|
13742
|
-
/**
|
|
13743
|
-
* Reads one search param from a TanStack `useSearch({ strict: false })` result.
|
|
13744
|
-
*
|
|
13745
|
-
* The registered route tree often has an empty or closed search schema, so a
|
|
13746
|
-
* string key cannot index that type. Parsing to a string record keeps the
|
|
13747
|
-
* lookup valid for every app router.
|
|
13748
|
-
*/
|
|
13749
|
-
const readPrimitiveSearchParam = (search, key) => {
|
|
13750
|
-
const parsedSearch = searchRecordSchema.safeParse(search);
|
|
13751
|
-
if (!parsedSearch.success) {
|
|
13752
|
-
return undefined;
|
|
13753
|
-
}
|
|
13754
|
-
const parsedValue = primitiveSearchValueSchema.safeParse(parsedSearch.data[key]);
|
|
13755
|
-
if (!parsedValue.success) {
|
|
13756
|
-
return undefined;
|
|
13757
|
-
}
|
|
13758
|
-
return String(parsedValue.data);
|
|
13759
|
-
};
|
|
13760
|
-
|
|
13761
|
-
/**
|
|
13762
|
-
* Maximum full URL length after adding one persisted search param before the
|
|
13763
|
-
* URL write is skipped (localStorage still persists the full state).
|
|
13764
|
-
*
|
|
13765
|
-
* Sized to stay safely below the AWS WAF managed-rule default
|
|
13766
|
-
* `SizeRestrictions_QUERYSTRING` cap of 5000 bytes for the entire
|
|
13767
|
-
* host + path + query + hash string.
|
|
13768
|
-
*/
|
|
13769
|
-
const MAX_URL_LENGTH = 5000;
|
|
13770
|
-
/**
|
|
13771
|
-
* Maximum length of the URL fragment after adding one persisted entry.
|
|
13772
|
-
* Oversized new entries are skipped; oversized replacements remove the stale
|
|
13773
|
-
* entry so localStorage remains authoritative.
|
|
13774
|
-
*
|
|
13775
|
-
* The fragment is never sent to the server, so the WAF cap above does not
|
|
13776
|
-
* apply. 64 KB stays well below typical browser URL limits (Chromium ≳ 100 KB,
|
|
13777
|
-
* Firefox ≳ 64 KB on the address bar) while leaving generous headroom for any
|
|
13778
|
-
* realistic table state.
|
|
13779
|
-
*/
|
|
13780
|
-
const MAX_HASH_LENGTH = 64 * 1024;
|
|
13781
|
-
/**
|
|
13782
|
-
* Syncs an encoded string value with a single named entry in the URL — either
|
|
13783
|
-
* a search param or an entry inside the hash fragment — via Tanstack Router.
|
|
13784
|
-
*
|
|
13785
|
-
* Writes go through the application router so other search params and
|
|
13786
|
-
* foreign fragment content are preserved. Each slot has a size guard
|
|
13787
|
-
* ({@link MAX_URL_LENGTH} for search, {@link MAX_HASH_LENGTH} for hash); an
|
|
13788
|
-
* oversized value is dropped from the URL and localStorage stays
|
|
13789
|
-
* authoritative. External changes to the entry (browser back/forward, a
|
|
13790
|
-
* pasted link, a foreign router push) fire `onExternalChange`.
|
|
13791
|
-
*
|
|
13792
|
-
* Writes are dispatched via a pending-write queue rather than calling
|
|
13793
|
-
* `navigate` directly. Tanstack Router's `router.state.status === "pending"`
|
|
13794
|
-
* is common during the first paint of a route (loaders, suspense), and an
|
|
13795
|
-
* implementation that simply returned in that case lost the write outright.
|
|
13796
|
-
* `updateSearchParam` stores the latest attempted write and schedules an rAF
|
|
13797
|
-
* flush; the flush only navigates when the router is idle, and an effect
|
|
13798
|
-
* retries whenever the router settles. A queued write is dropped on unmount so
|
|
13799
|
-
* it cannot drain onto the next route.
|
|
13800
|
-
*
|
|
13801
|
-
* @param options - Configuration for the URL entry sync.
|
|
13802
|
-
* @param options.key - The search param name or fragment entry name.
|
|
13803
|
-
* @param options.location - `"search"` or `"hash"`.
|
|
13804
|
-
* @param options.enabled - Set to `false` to disable all URL interaction (default `true`).
|
|
13805
|
-
* @param options.onExternalChange - Called when the entry changes externally.
|
|
13806
|
-
* @param options.replace - `true` to always use `replaceState`; `false` to always push.
|
|
13807
|
-
* Default: replace when the entry is being added, push when it already has a value.
|
|
13808
|
-
*/
|
|
13809
|
-
const useUrlParamSync = ({ key, location: urlLocation, enabled = true, onExternalChange, replace: replaceOption, }) => {
|
|
13810
|
-
const navigate = useNavigate();
|
|
13811
|
-
const location = useLocation();
|
|
13812
|
-
const router = useRouter();
|
|
13813
|
-
const search = useSearch({ strict: false, shouldThrow: false });
|
|
13814
|
-
const isHash = urlLocation === "hash";
|
|
13815
|
-
const lastWrittenRef = useRef(undefined);
|
|
13816
|
-
const pendingWriteRef = useRef(null);
|
|
13817
|
-
const onExternalChangeRef = useRef(onExternalChange);
|
|
13818
|
-
useEffect(() => {
|
|
13819
|
-
onExternalChangeRef.current = onExternalChange;
|
|
13820
|
-
}, [onExternalChange]);
|
|
13821
|
-
const currentValue = useMemo(() => {
|
|
13822
|
-
if (!enabled) {
|
|
13823
|
-
return undefined;
|
|
13824
|
-
}
|
|
13825
|
-
return isHash ? readHashKey(location.hash, key) : readPrimitiveSearchParam(search, key);
|
|
13826
|
-
}, [enabled, isHash, location.hash, search, key]);
|
|
13827
|
-
useEffect(() => {
|
|
13828
|
-
if (!enabled || currentValue === undefined) {
|
|
13829
|
-
return;
|
|
13830
|
-
}
|
|
13831
|
-
if (currentValue === lastWrittenRef.current || lastWrittenRef.current === undefined) {
|
|
13832
|
-
return;
|
|
13833
|
-
}
|
|
13834
|
-
// A caller may have primed `lastWrittenRef` via `updateSearchParam` while
|
|
13835
|
-
// the URL still carries the previous value (queued rAF / router pending).
|
|
13836
|
-
// Treating that stale URL as an external change would reload state from
|
|
13837
|
-
// persistence before the write lands.
|
|
13838
|
-
if (pendingWriteRef.current !== null) {
|
|
13839
|
-
return;
|
|
13840
|
-
}
|
|
13841
|
-
requestAnimationFrame(() => {
|
|
13842
|
-
onExternalChangeRef.current?.();
|
|
13843
|
-
});
|
|
13844
|
-
}, [currentValue, enabled]);
|
|
13845
|
-
// Read through refs so the write path does not change identity on every
|
|
13846
|
-
// navigation; it only needs the location and current value at the moment it
|
|
13847
|
-
// flushes, which may be an animation frame after it was queued.
|
|
13848
|
-
const locationRef = useRef(location);
|
|
13849
|
-
const currentValueRef = useRef(currentValue);
|
|
13850
|
-
useEffect(() => {
|
|
13851
|
-
locationRef.current = location;
|
|
13852
|
-
currentValueRef.current = currentValue;
|
|
13853
|
-
}, [location, currentValue]);
|
|
13854
|
-
const getUrlLengthWithSearchParam = useCallback((paramValue, params) => {
|
|
13855
|
-
const { href, searchStr, hash } = locationRef.current;
|
|
13856
|
-
const otherParamsLength = objectKeys(params)
|
|
13857
|
-
.filter(k => k !== key)
|
|
13858
|
-
.reduce((totalLength, k) => {
|
|
13859
|
-
const kLen = encodeURIComponent(String(k)).length;
|
|
13860
|
-
const v = params[k];
|
|
13861
|
-
const vLen = v !== null && v !== undefined ? encodeURIComponent(String(v)).length : 0;
|
|
13862
|
-
return totalLength + kLen + vLen + (totalLength > 0 ? 2 : 1);
|
|
13863
|
-
}, 0);
|
|
13864
|
-
const urlBase = href.length - (searchStr.length || 0) + (hash.length || 0);
|
|
13865
|
-
return urlBase + otherParamsLength + 1 + key.length + 1 + paramValue.length;
|
|
13866
|
-
}, [key]);
|
|
13867
|
-
const flushPendingWrite = useCallback(() => {
|
|
13868
|
-
const pending = pendingWriteRef.current;
|
|
13869
|
-
if (pending === null) {
|
|
13870
|
-
return;
|
|
13871
|
-
}
|
|
13872
|
-
if (router.state.status === "pending") {
|
|
13873
|
-
// Keep the write queued; the status-watcher effect retries once idle.
|
|
13874
|
-
return;
|
|
13875
|
-
}
|
|
13876
|
-
pendingWriteRef.current = null;
|
|
13877
|
-
const { encodedValue } = pending;
|
|
13878
|
-
const { hash } = locationRef.current;
|
|
13879
|
-
const valueInUrl = currentValueRef.current;
|
|
13880
|
-
const shouldReplace = replaceOption ?? !Boolean(valueInUrl);
|
|
13881
|
-
if (!isHash) {
|
|
13882
|
-
void navigate({
|
|
13883
|
-
to: ".",
|
|
13884
|
-
search: (prev) => getUrlLengthWithSearchParam(encodedValue ?? "", prev) <= MAX_URL_LENGTH
|
|
13885
|
-
? { ...prev, [key]: encodedValue }
|
|
13886
|
-
: { ...prev, [key]: undefined },
|
|
13887
|
-
hash,
|
|
13888
|
-
replace: shouldReplace,
|
|
13889
|
-
});
|
|
13890
|
-
return;
|
|
13891
|
-
}
|
|
13892
|
-
let nextHash = writeHashKey(hash, key, encodedValue);
|
|
13893
|
-
let removedOversizedValue = false;
|
|
13894
|
-
if (nextHash.length > MAX_HASH_LENGTH) {
|
|
13895
|
-
if (valueInUrl === undefined) {
|
|
13896
|
-
return;
|
|
13897
|
-
}
|
|
13898
|
-
nextHash = writeHashKey(hash, key, undefined);
|
|
13899
|
-
removedOversizedValue = true;
|
|
13900
|
-
}
|
|
13901
|
-
void navigate({
|
|
13902
|
-
to: ".",
|
|
13903
|
-
// Returning the same `prev` reference leaves the search params
|
|
13904
|
-
// unchanged; `search` must still be passed for the router types.
|
|
13905
|
-
search: (prev) => prev,
|
|
13906
|
-
// The router adds the `#` itself; forwarding it would double it.
|
|
13907
|
-
hash: nextHash.startsWith("#") ? nextHash.slice(1) : nextHash,
|
|
13908
|
-
replace: removedOversizedValue ? true : shouldReplace,
|
|
13909
|
-
});
|
|
13910
|
-
}, [router.state.status, replaceOption, isHash, navigate, getUrlLengthWithSearchParam, key]);
|
|
13911
|
-
useEffect(() => {
|
|
13912
|
-
if (router.state.status === "pending" || pendingWriteRef.current === null) {
|
|
13913
|
-
return;
|
|
13914
|
-
}
|
|
13915
|
-
flushPendingWrite();
|
|
13916
|
-
}, [router.state.status, flushPendingWrite]);
|
|
13917
|
-
useEffect(() => () => {
|
|
13918
|
-
pendingWriteRef.current = null;
|
|
13919
|
-
}, []);
|
|
13920
|
-
const updateSearchParam = useCallback((encodedValue) => {
|
|
13921
|
-
if (!enabled) {
|
|
13922
|
-
return;
|
|
13923
|
-
}
|
|
13924
|
-
// Dedupe against the last committed write or the value already queued;
|
|
13925
|
-
// both represent the caller's intent.
|
|
13926
|
-
const inFlightOrLastWritten = pendingWriteRef.current?.encodedValue ?? lastWrittenRef.current;
|
|
13927
|
-
if (encodedValue !== undefined && encodedValue === inFlightOrLastWritten) {
|
|
13928
|
-
return;
|
|
13929
|
-
}
|
|
13930
|
-
// Prime here (not in the flush) so the external-change detector treats
|
|
13931
|
-
// this value as the caller's state even when the flush is a no-op or
|
|
13932
|
-
// stays queued during a pending router phase.
|
|
13933
|
-
lastWrittenRef.current = encodedValue;
|
|
13934
|
-
if (currentValueRef.current === encodedValue) {
|
|
13935
|
-
return;
|
|
13936
|
-
}
|
|
13937
|
-
pendingWriteRef.current = { encodedValue };
|
|
13938
|
-
requestAnimationFrame(() => {
|
|
13939
|
-
flushPendingWrite();
|
|
13940
|
-
});
|
|
13941
|
-
}, [enabled, flushPendingWrite]);
|
|
13942
|
-
return useMemo(() => ({ searchValue: currentValue, updateSearchParam }), [currentValue, updateSearchParam]);
|
|
13943
|
-
};
|
|
13944
|
-
|
|
13945
|
-
/**
|
|
13946
|
-
* Raw localStorage access, kept in one place so this file's exemption from the
|
|
13947
|
-
* no-direct-storage-access rule is centralised rather than repeated at each call site.
|
|
13948
|
-
*
|
|
13949
|
-
* TODO: migrate to the useLocalStorage hook — this file was exempted when the
|
|
13950
|
-
* no-direct-storage-access rule was introduced.
|
|
13951
|
-
*/
|
|
13952
|
-
/* eslint-disable no-restricted-globals */
|
|
13953
|
-
const rawLocalStorage = {
|
|
13954
|
-
read: (key) => localStorage.getItem(key),
|
|
13955
|
-
write: (key, value) => localStorage.setItem(key, value),
|
|
13956
|
-
remove: (key) => localStorage.removeItem(key),
|
|
13957
|
-
};
|
|
13958
|
-
/**
|
|
13959
|
-
* Generic persistence hook that loads state from a URL slot (search param
|
|
13960
|
-
* or hash fragment, depending on `urlLocation`) with localStorage fallback,
|
|
13961
|
-
* and writes changes to both.
|
|
13962
|
-
*
|
|
13963
|
-
* On mount the hook resolves the initial state as follows:
|
|
13964
|
-
* - If the URL slot holds a value, decode it and pass through `validate`.
|
|
13965
|
-
* - If localStorage is enabled, read and validate its value.
|
|
13966
|
-
* - When `mergeWithStorageOnRead` is `false` (default): URL state wins
|
|
13967
|
-
* entirely when present, otherwise fall back to localStorage.
|
|
13968
|
-
* - When `mergeWithStorageOnRead` is `true`: shallow-merge URL fields over
|
|
13969
|
-
* localStorage so fields stripped by `toUrlValue` survive via storage.
|
|
13970
|
-
*
|
|
13971
|
-
* A value that comes only from localStorage is never written to the URL on
|
|
13972
|
-
* load. Copying it left a layout in history, bookmarks, and login redirects,
|
|
13973
|
-
* which then replayed an older layout over the saved one (GLU-2396). The URL
|
|
13974
|
-
* is written when the consumer persists a change.
|
|
13975
|
-
*
|
|
13976
|
-
* `persistState` writes to localStorage (`storageSerializer`) and to the URL
|
|
13977
|
-
* (via `toUrlValue` + encoding).
|
|
13978
|
-
* Each slot skips a value equal to its last write. The URL side compares what
|
|
13979
|
-
* would land in the URL (the `toUrlValue` projection and the identity stamp),
|
|
13980
|
-
* starting from the projection of the hydrated state and the stamp the URL
|
|
13981
|
-
* carries: echoing `initialState`, or changing only a field the projection
|
|
13982
|
-
* strips, writes no URL entry, while an equal state persisted after the
|
|
13983
|
-
* identity resolves rewrites the URL with its stamp. The storage side starts
|
|
13984
|
-
* from what localStorage held, so a consumer that persists `initialState`
|
|
13985
|
-
* after opening a link saves that link's state for the account that opened
|
|
13986
|
-
* it, and a reload of the account's own link writes nothing.
|
|
13987
|
-
* `persistToStorage` and `persistToUrl` are the same two halves exposed
|
|
13988
|
-
* separately for consumers that schedule them differently; passing `undefined`
|
|
13989
|
-
* removes the entry rather than writing an empty value.
|
|
13990
|
-
*
|
|
13991
|
-
* The snapshot is re-read when the storage key or the storage/merge options
|
|
13992
|
-
* change, in the same render, so a write in that commit already sees the
|
|
13993
|
-
* state for the new key.
|
|
13994
|
-
*
|
|
13995
|
-
* @param options - Configuration for the persisted state.
|
|
13996
|
-
* @param options.key - Unique identifier used for both the URL slot and the localStorage key.
|
|
13997
|
-
* @param options.validate - Called with the decoded/parsed value; must return `TState` or `undefined`.
|
|
13998
|
-
* @param options.toUrlValue - Transform applied before URL encoding (default: encode state as-is).
|
|
13999
|
-
* @param options.fromUrlValue - Transform applied after URL decoding, before validation (default: identity).
|
|
14000
|
-
* @param options.localStorageEnabled - When `false` localStorage is neither read nor written (default `true`).
|
|
14001
|
-
* @param options.replace - Forwarded to the underlying URL sync hook.
|
|
14002
|
-
* @param options.clientSideUserId - The user ID to use for the localStorage key.
|
|
14003
|
-
* @param options.mergeWithStorageOnRead - Merge URL state on top of localStorage
|
|
14004
|
-
* state on read (URL wins on shared keys). Use when `toUrlValue` deliberately
|
|
14005
|
-
* omits fields so they still survive via localStorage. Default `false`.
|
|
14006
|
-
* @param options.urlLocation - Which URL slot backs the value (`"search"` or `"hash"`). Default `"search"`.
|
|
14007
|
-
* @param options.stampUrlWithIdentity - Stamp URL writes with the current identity so the login
|
|
14008
|
-
* redirect can drop entries left by another account on this browser. Default `false`.
|
|
14009
|
-
*/
|
|
14010
|
-
const usePersistedState = ({ key, validate, toUrlValue, fromUrlValue, localStorageEnabled = true, replace, clientSideUserId, mergeWithStorageOnRead = false, urlLocation = "search", stampUrlWithIdentity = false, }) => {
|
|
14011
|
-
const { encode, decode } = useCustomEncoding();
|
|
14012
|
-
// Fingerprint of the identity this hook writes URL values for. `undefined`
|
|
14013
|
-
// while the identity is unresolved (or when stamping is off): writes are
|
|
14014
|
-
// then unstamped.
|
|
14015
|
-
const currentUrlOwner = useMemo(() => (stampUrlWithIdentity && clientSideUserId !== undefined ? identityFingerprint(clientSideUserId) : undefined), [stampUrlWithIdentity, clientSideUserId]);
|
|
14016
|
-
const { searchValue: urlValue, updateSearchParam: updateUrlValue } = useUrlParamSync({
|
|
14017
|
-
key,
|
|
14018
|
-
location: urlLocation,
|
|
14019
|
-
replace,
|
|
14020
|
-
});
|
|
14021
|
-
const storageKey = useStorageKey(key, clientSideUserId);
|
|
14022
|
-
// `toUrlValue` is read through a ref so the write callbacks stay stable
|
|
14023
|
-
// when a consumer passes an inline function.
|
|
14024
|
-
const toUrlValueRef = useRef(toUrlValue);
|
|
14025
|
-
useEffect(() => {
|
|
14026
|
-
toUrlValueRef.current = toUrlValue;
|
|
14027
|
-
}, [toUrlValue]);
|
|
14028
|
-
const readStoredState = useCallback((validateState) => {
|
|
14029
|
-
if (!localStorageEnabled) {
|
|
14030
|
-
return undefined;
|
|
14031
|
-
}
|
|
14032
|
-
try {
|
|
14033
|
-
const raw = rawLocalStorage.read(storageKey);
|
|
14034
|
-
if (!raw) {
|
|
14035
|
-
return undefined;
|
|
14036
|
-
}
|
|
14037
|
-
return validateState(storageSerializer.deserialize(raw));
|
|
14038
|
-
}
|
|
14039
|
-
catch {
|
|
14040
|
-
return undefined;
|
|
14041
|
-
}
|
|
14042
|
-
}, [localStorageEnabled, storageKey]);
|
|
14043
|
-
const readPersistedState = useCallback(({ valueFromUrl, validateState, transformFromUrlValue, }) => {
|
|
14044
|
-
let urlState;
|
|
14045
|
-
let urlStamp;
|
|
14046
|
-
if (valueFromUrl) {
|
|
14047
|
-
try {
|
|
14048
|
-
// The ownership stamp decides nothing on read (the login redirect
|
|
14049
|
-
// does that, see `useStripForeignIdentityHash`); it is kept only to
|
|
14050
|
-
// seed the URL dedupe with what the URL is currently stamped with.
|
|
14051
|
-
const { value, owner } = unwrapUrlOwner(decode(valueFromUrl));
|
|
14052
|
-
urlState = validateState(transformFromUrlValue ? transformFromUrlValue(value) : value);
|
|
14053
|
-
urlStamp = urlState === undefined ? undefined : { owner };
|
|
14054
|
-
}
|
|
14055
|
-
catch {
|
|
14056
|
-
urlState = undefined;
|
|
14057
|
-
}
|
|
14058
|
-
}
|
|
14059
|
-
// Storage is read even when the URL wins outright: it seeds the storage
|
|
14060
|
-
// dedupe, so persisting the hydrated state writes only when the URL
|
|
14061
|
-
// changed something.
|
|
14062
|
-
const stored = readStoredState(validateState);
|
|
14063
|
-
let hydrated;
|
|
14064
|
-
if (urlState === undefined) {
|
|
14065
|
-
hydrated = stored;
|
|
14066
|
-
}
|
|
14067
|
-
else if (mergeWithStorageOnRead && stored !== undefined) {
|
|
14068
|
-
// URL fields take precedence; storage fills in whatever the URL
|
|
14069
|
-
// omits (e.g. fields stripped by `toUrlValue`).
|
|
14070
|
-
hydrated = { ...stored, ...urlState };
|
|
14071
|
-
}
|
|
14072
|
-
else {
|
|
14073
|
-
hydrated = urlState;
|
|
14074
|
-
}
|
|
14075
|
-
return { initialState: hydrated, storedState: stored, urlValue: urlStamp };
|
|
14076
|
-
}, [decode, mergeWithStorageOnRead, readStoredState]);
|
|
14077
|
-
// The shareable projection of `state`: what a URL write carries before
|
|
14078
|
-
// encoding. The URL dedupe compares this, not the whole state, so a change
|
|
14079
|
-
// confined to a field `toUrlValue` strips is not a URL change.
|
|
14080
|
-
const projectForUrl = useCallback((state) => (toUrlValueRef.current ? toUrlValueRef.current(state) : state), []);
|
|
14081
|
-
// Every URL write goes through here so the ownership stamp is applied uniformly.
|
|
14082
|
-
const encodeUrlWrite = useCallback(({ projected, owner }) => encode(owner === undefined ? projected : wrapUrlOwner(projected, owner)), [encode]);
|
|
14083
|
-
// `readPersistedState` changes identity exactly when an input that changes
|
|
14084
|
-
// what a read returns does (storage key, storage/merge options), so the
|
|
14085
|
-
// snapshot is re-read then and only then — synchronously, in the render
|
|
14086
|
-
// where the input changed, by deriving state from the changed input. A URL
|
|
14087
|
-
// change after mount or an inline `validate` deliberately does not
|
|
14088
|
-
// re-hydrate `initialState`: `useUrlParamSync` owns URL changes.
|
|
14089
|
-
const readSnapshot = () => ({
|
|
14090
|
-
readWith: readPersistedState,
|
|
14091
|
-
...readPersistedState({ valueFromUrl: urlValue, validateState: validate, transformFromUrlValue: fromUrlValue }),
|
|
14092
|
-
});
|
|
14093
|
-
const [snapshot, setSnapshot] = useState(readSnapshot);
|
|
14094
|
-
if (snapshot.readWith !== readPersistedState) {
|
|
14095
|
-
setSnapshot(readSnapshot());
|
|
14096
|
-
}
|
|
14097
|
-
const { initialState, storedState } = snapshot;
|
|
14098
|
-
// Last value written to each slot, for deduping. Two refs, not one, because
|
|
14099
|
-
// a consumer may schedule the two writes differently (storage at once, URL
|
|
14100
|
-
// debounced). Both are re-seeded whenever the snapshot is re-read so the
|
|
14101
|
-
// first write to a newly scoped key is never skipped.
|
|
14102
|
-
//
|
|
14103
|
-
// The storage side starts as what storage held, so persisting the hydrated
|
|
14104
|
-
// state after opening a link writes only when the URL changed something.
|
|
14105
|
-
//
|
|
14106
|
-
// The URL side holds what a write would put in the URL: the shareable
|
|
14107
|
-
// projection plus the owner stamp. It starts as the projection of the
|
|
14108
|
-
// hydrated value, so a consumer that echoes `initialState` on mount, or
|
|
14109
|
-
// changes only a field the projection strips, writes nothing: a layout read
|
|
14110
|
-
// from storage must not grow a URL entry (GLU-2396). Its owner starts as the
|
|
14111
|
-
// stamp the URL carries (or the current owner when the URL is empty), so an
|
|
14112
|
-
// equal state persisted after the identity resolves still rewrites the URL
|
|
14113
|
-
// with its stamp.
|
|
14114
|
-
const urlOwnerSeed = snapshot.urlValue ? snapshot.urlValue.owner : currentUrlOwner;
|
|
14115
|
-
const seedUrlWrite = useCallback((project) => initialState === undefined ? undefined : { projected: project(initialState), owner: urlOwnerSeed }, [initialState, urlOwnerSeed]);
|
|
14116
|
-
const lastStoredRef = useRef(storedState);
|
|
14117
|
-
// The first seed is computed during render, so it projects with the
|
|
14118
|
-
// `toUrlValue` prop rather than reading `toUrlValueRef` (refs are not read
|
|
14119
|
-
// in render); the projection is cheap, and later seeds come from the effect.
|
|
14120
|
-
const lastUrlRef = useRef(seedUrlWrite(state => (toUrlValue ? toUrlValue(state) : state)));
|
|
14121
|
-
useEffect(() => {
|
|
14122
|
-
lastStoredRef.current = storedState;
|
|
14123
|
-
lastUrlRef.current = seedUrlWrite(projectForUrl);
|
|
14124
|
-
}, [seedUrlWrite, projectForUrl, storedState]);
|
|
14125
|
-
const persistToStorage = useCallback((state) => {
|
|
14126
|
-
if (!localStorageEnabled) {
|
|
14127
|
-
return;
|
|
14128
|
-
}
|
|
14129
|
-
if (state === undefined) {
|
|
14130
|
-
lastStoredRef.current = undefined;
|
|
14131
|
-
rawLocalStorage.remove(storageKey);
|
|
14132
|
-
return;
|
|
14133
|
-
}
|
|
14134
|
-
if (dequal(lastStoredRef.current, state)) {
|
|
14135
|
-
return;
|
|
14136
|
-
}
|
|
14137
|
-
try {
|
|
14138
|
-
rawLocalStorage.write(storageKey, storageSerializer.serialize(state));
|
|
14139
|
-
lastStoredRef.current = state;
|
|
14140
|
-
}
|
|
14141
|
-
catch {
|
|
14142
|
-
// Quota or a disabled store: the next write retries; the URL is unaffected.
|
|
14143
|
-
}
|
|
14144
|
-
}, [localStorageEnabled, storageKey]);
|
|
14145
|
-
const persistToUrl = useCallback((state) => {
|
|
14146
|
-
if (state === undefined) {
|
|
14147
|
-
lastUrlRef.current = undefined;
|
|
14148
|
-
updateUrlValue(undefined);
|
|
14149
|
-
return;
|
|
14150
|
-
}
|
|
14151
|
-
const write = { projected: projectForUrl(state), owner: currentUrlOwner };
|
|
14152
|
-
const last = lastUrlRef.current;
|
|
14153
|
-
// Same projection: write only to add or change a stamp. An unresolved
|
|
14154
|
-
// identity never rewrites a stamped URL just to strip the stamp; it is
|
|
14155
|
-
// re-stamped once the identity resolves.
|
|
14156
|
-
if (last !== undefined &&
|
|
14157
|
-
dequal(last.projected, write.projected) &&
|
|
14158
|
-
(last.owner === write.owner || write.owner === undefined)) {
|
|
14159
|
-
return;
|
|
14160
|
-
}
|
|
14161
|
-
lastUrlRef.current = write;
|
|
14162
|
-
updateUrlValue(encodeUrlWrite(write));
|
|
14163
|
-
}, [currentUrlOwner, encodeUrlWrite, projectForUrl, updateUrlValue]);
|
|
14164
|
-
const persistState = useCallback((state) => {
|
|
14165
|
-
persistToStorage(state);
|
|
14166
|
-
persistToUrl(state);
|
|
14167
|
-
}, [persistToStorage, persistToUrl]);
|
|
14168
|
-
return useMemo(() => ({ initialState, persistState, persistToStorage, persistToUrl }), [initialState, persistState, persistToStorage, persistToUrl]);
|
|
14169
|
-
};
|
|
14170
|
-
|
|
14171
|
-
/**
|
|
14172
|
-
* Syncs an encoded string value with a URL search parameter via Tanstack Router.
|
|
14173
|
-
*
|
|
14174
|
-
* Thin wrapper over {@link useUrlParamSync} with `location: "search"`; see it
|
|
14175
|
-
* for the write queue, the size guard (`MAX_URL_LENGTH`), and external-change
|
|
14176
|
-
* detection.
|
|
14177
|
-
*
|
|
14178
|
-
* @param options - Configuration for the search param sync.
|
|
14179
|
-
* @param options.key - The URL search parameter name.
|
|
14180
|
-
* @param options.enabled - Set to `false` to disable all URL interaction (default `true`).
|
|
14181
|
-
* @param options.onExternalChange - Called when the param changes externally.
|
|
14182
|
-
* @param options.replace - `true` to always use `replaceState`.
|
|
14183
|
-
*/
|
|
14184
|
-
const useSearchParamSync = (options) => useUrlParamSync({ ...options, location: "search" });
|
|
14185
|
-
|
|
14186
13310
|
/**
|
|
14187
13311
|
* Enumerates localStorage keys. Kept local so this file's exemption from the
|
|
14188
13312
|
* no-direct-storage-access rule is centralised, as in `usePersistedState`.
|
|
@@ -14422,6 +13546,40 @@ const useClickOutside = (el, options) => {
|
|
|
14422
13546
|
});
|
|
14423
13547
|
};
|
|
14424
13548
|
|
|
13549
|
+
/**
|
|
13550
|
+
* Maps size keys to their corresponding state property names.
|
|
13551
|
+
*/
|
|
13552
|
+
const breakpointPropsMap = {
|
|
13553
|
+
xs: "isXs",
|
|
13554
|
+
sm: "isSm",
|
|
13555
|
+
md: "isMd",
|
|
13556
|
+
lg: "isLg",
|
|
13557
|
+
xl: "isXl",
|
|
13558
|
+
"2xl": "is2xl",
|
|
13559
|
+
"3xl": "is3xl",
|
|
13560
|
+
};
|
|
13561
|
+
/**
|
|
13562
|
+
* The default state for sizes, with all values set to false.
|
|
13563
|
+
*/
|
|
13564
|
+
const defaultBreakpointState = {
|
|
13565
|
+
isXs: false,
|
|
13566
|
+
isSm: false,
|
|
13567
|
+
isMd: false,
|
|
13568
|
+
isLg: false,
|
|
13569
|
+
isXl: false,
|
|
13570
|
+
is2xl: false,
|
|
13571
|
+
is3xl: false,
|
|
13572
|
+
};
|
|
13573
|
+
/**
|
|
13574
|
+
* Creates a breakpoint state object based on a width value
|
|
13575
|
+
*/
|
|
13576
|
+
const createBreakpointState = ({ width }) => {
|
|
13577
|
+
return objectEntries(themeScreenSizeAsNumber).reduce((acc, [size, minWidth]) => ({
|
|
13578
|
+
...acc,
|
|
13579
|
+
[breakpointPropsMap[size]]: width >= minWidth,
|
|
13580
|
+
}), { ...defaultBreakpointState });
|
|
13581
|
+
};
|
|
13582
|
+
|
|
14425
13583
|
/**
|
|
14426
13584
|
* A custom React hook that provides real-time information about a container's size.
|
|
14427
13585
|
*
|
|
@@ -14583,77 +13741,6 @@ const useContinuousTimeout = ({ onTimeout, onMaxRetries, duration, maxRetries, }
|
|
|
14583
13741
|
}), [startTimeouts, stopTimeouts, isRunning]);
|
|
14584
13742
|
};
|
|
14585
13743
|
|
|
14586
|
-
const DEFAULT_PARAM_NAME = "c";
|
|
14587
|
-
const DEFAULT_DEBOUNCE_MS = 300;
|
|
14588
|
-
/**
|
|
14589
|
-
* Reads a cursor from the URL search params on mount and provides a debounced
|
|
14590
|
-
* updater for writing it back. Uses `replace: true` to avoid polluting browser
|
|
14591
|
-
* history with every scroll position change.
|
|
14592
|
-
*
|
|
14593
|
-
* Wire `initialCursor` into `usePaginationQuery` and `updateCursor` into
|
|
14594
|
-
* `useBidirectionalScroll`'s `onTopItemChange` callback (mapping index to cursor).
|
|
14595
|
-
*
|
|
14596
|
-
* A pending write is dropped whenever a path-changing navigation starts or the
|
|
14597
|
-
* location has moved on: the write targets `to: "."`, so landing it after the
|
|
14598
|
-
* user opened a row would replace their destination with the list they came
|
|
14599
|
-
* from.
|
|
14600
|
-
*/
|
|
14601
|
-
const useCursorUrlSync = ({ paramName = DEFAULT_PARAM_NAME, debounceMs = DEFAULT_DEBOUNCE_MS, } = {}) => {
|
|
14602
|
-
const router = useRouter();
|
|
14603
|
-
const navigate = useNavigate();
|
|
14604
|
-
// Read the cursor off the router rather than `useSearch`, which would
|
|
14605
|
-
// subscribe the table to its own writes and re-render every row mid-scroll.
|
|
14606
|
-
const [initialCursor] = useState(() => {
|
|
14607
|
-
const entry = Object.entries(router.latestLocation.search).find(([key]) => key === paramName);
|
|
14608
|
-
return typeof entry?.[1] === "string" ? entry[1] : undefined;
|
|
14609
|
-
});
|
|
14610
|
-
const timerRef = useRef(undefined);
|
|
14611
|
-
const cancelPendingUpdate = useCallback(() => {
|
|
14612
|
-
if (timerRef.current !== undefined) {
|
|
14613
|
-
clearTimeout(timerRef.current);
|
|
14614
|
-
timerRef.current = undefined;
|
|
14615
|
-
}
|
|
14616
|
-
}, []);
|
|
14617
|
-
const paramNameRef = useRef(paramName);
|
|
14618
|
-
useEffect(() => {
|
|
14619
|
-
paramNameRef.current = paramName;
|
|
14620
|
-
}, [paramName]);
|
|
14621
|
-
const updateCursor = useCallback((cursor) => {
|
|
14622
|
-
cancelPendingUpdate();
|
|
14623
|
-
const scheduledAtPathname = router.latestLocation.pathname;
|
|
14624
|
-
timerRef.current = setTimeout(() => {
|
|
14625
|
-
timerRef.current = undefined;
|
|
14626
|
-
if (router.latestLocation.pathname !== scheduledAtPathname) {
|
|
14627
|
-
return;
|
|
14628
|
-
}
|
|
14629
|
-
void navigate({
|
|
14630
|
-
to: ".",
|
|
14631
|
-
search: (prev) => ({
|
|
14632
|
-
...prev,
|
|
14633
|
-
[paramNameRef.current]: cursor,
|
|
14634
|
-
}),
|
|
14635
|
-
// Without this the router drops the fragment, and with it the table layout.
|
|
14636
|
-
hash: true,
|
|
14637
|
-
replace: true,
|
|
14638
|
-
});
|
|
14639
|
-
}, debounceMs);
|
|
14640
|
-
}, [cancelPendingUpdate, debounceMs, navigate, router]);
|
|
14641
|
-
// Only path-changing navigations invalidate a pending write. Same-pathname
|
|
14642
|
-
// navigations (filter bar, table persistence, map viewBox) share this URL and
|
|
14643
|
-
// their writes must not cancel ours. Cancelling here rather than relying on
|
|
14644
|
-
// the pathname check alone also covers navigating away and back within the
|
|
14645
|
-
// debounce window, which would otherwise land a stale cursor on a fresh list.
|
|
14646
|
-
useEffect(() => router.subscribe("onBeforeNavigate", event => {
|
|
14647
|
-
if (event.pathChanged) {
|
|
14648
|
-
cancelPendingUpdate();
|
|
14649
|
-
}
|
|
14650
|
-
}), [cancelPendingUpdate, router]);
|
|
14651
|
-
useEffect(() => {
|
|
14652
|
-
return cancelPendingUpdate;
|
|
14653
|
-
}, [cancelPendingUpdate]);
|
|
14654
|
-
return useMemo(() => ({ initialCursor, updateCursor }), [initialCursor, updateCursor]);
|
|
14655
|
-
};
|
|
14656
|
-
|
|
14657
13744
|
// Copied from https://github.com/rexxars/use-device-pixel-ratio
|
|
14658
13745
|
/**
|
|
14659
13746
|
* Get the device pixel ratio, potentially rounded and capped.
|
|
@@ -15468,6 +14555,69 @@ function useTextSearch(items, props) {
|
|
|
15468
14555
|
return useMemo(() => [result, searchText, setSearchText], [result, searchText, setSearchText]);
|
|
15469
14556
|
}
|
|
15470
14557
|
|
|
14558
|
+
const canUseMatchMedia = () => typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
14559
|
+
const getViewportBreakpointState = () => {
|
|
14560
|
+
if (!canUseMatchMedia())
|
|
14561
|
+
return { ...defaultBreakpointState };
|
|
14562
|
+
return objectEntries(themeScreenSizeAsNumber).reduce((acc, [size, minWidth]) => ({
|
|
14563
|
+
...acc,
|
|
14564
|
+
[breakpointPropsMap[size]]: window.matchMedia(`(min-width: ${minWidth}px)`).matches,
|
|
14565
|
+
}), { ...defaultBreakpointState });
|
|
14566
|
+
};
|
|
14567
|
+
/**
|
|
14568
|
+
* Returns real-time boolean flags for each design-token breakpoint based on viewport width.
|
|
14569
|
+
*
|
|
14570
|
+
* **When to use:**
|
|
14571
|
+
* - Use `useViewportBreakpoints` when you need to respond to the **full viewport width**
|
|
14572
|
+
* — for example, toggling a mobile navigation drawer or switching a global layout shell.
|
|
14573
|
+
* - **Prefer `useContainerBreakpoints`** for component-level responsiveness, as it
|
|
14574
|
+
* responds to the parent container's width and works correctly when a component appears
|
|
14575
|
+
* in different layout contexts (sidebar, main content, widget).
|
|
14576
|
+
* - Pass `{ skip: true }` when you only need the initial value and don't want ongoing
|
|
14577
|
+
* `matchMedia` listeners.
|
|
14578
|
+
*
|
|
14579
|
+
* @param {object} [options] - Configuration options
|
|
14580
|
+
* @param {boolean} [options.skip] - Whether to skip observing for viewport changes (default: false)
|
|
14581
|
+
* @returns {BreakpointState} An object containing boolean values for each viewport size breakpoint.
|
|
14582
|
+
* @example
|
|
14583
|
+
* const MyComponent = () => {
|
|
14584
|
+
* const viewportSize = useViewportBreakpoints();
|
|
14585
|
+
*
|
|
14586
|
+
* if (viewportSize.isLg) {
|
|
14587
|
+
* return <LargeScreenLayout />;
|
|
14588
|
+
* }
|
|
14589
|
+
*
|
|
14590
|
+
* return viewportSize.isMd ? <MediumScreenLayout /> : <SmallLayout />;
|
|
14591
|
+
* }
|
|
14592
|
+
*/
|
|
14593
|
+
const useViewportBreakpoints = (options = {}) => {
|
|
14594
|
+
const { skip = false } = options;
|
|
14595
|
+
const [viewportSize, setViewportSize] = useState(getViewportBreakpointState);
|
|
14596
|
+
const updateViewportSize = useCallback(() => {
|
|
14597
|
+
setViewportSize(getViewportBreakpointState());
|
|
14598
|
+
}, []);
|
|
14599
|
+
const updateViewportSizeRef = useRef(updateViewportSize);
|
|
14600
|
+
useEffect(() => {
|
|
14601
|
+
updateViewportSizeRef.current = updateViewportSize;
|
|
14602
|
+
}, [updateViewportSize]);
|
|
14603
|
+
useEffect(() => {
|
|
14604
|
+
if (skip || !canUseMatchMedia()) {
|
|
14605
|
+
return;
|
|
14606
|
+
}
|
|
14607
|
+
updateViewportSizeRef.current();
|
|
14608
|
+
const mediaQueryLists = objectEntries(themeScreenSizeAsNumber).map(([_, minWidth]) => window.matchMedia(`(min-width: ${minWidth}px)`));
|
|
14609
|
+
mediaQueryLists.forEach(mql => {
|
|
14610
|
+
mql.addEventListener("change", updateViewportSizeRef.current);
|
|
14611
|
+
});
|
|
14612
|
+
return () => {
|
|
14613
|
+
mediaQueryLists.forEach(mql => {
|
|
14614
|
+
mql.removeEventListener("change", updateViewportSizeRef.current);
|
|
14615
|
+
});
|
|
14616
|
+
};
|
|
14617
|
+
}, [skip]);
|
|
14618
|
+
return viewportSize;
|
|
14619
|
+
};
|
|
14620
|
+
|
|
15471
14621
|
const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
|
|
15472
14622
|
/**
|
|
15473
14623
|
* Use this hook to disable functionality while the tab is hidden within the browser or to react to focus or blur events
|
|
@@ -15510,4 +14660,4 @@ const useWindowActivity = ({ onFocus, onBlur, skip = false } = { onBlur: undefin
|
|
|
15510
14660
|
*/
|
|
15511
14661
|
setupLibraryTranslations();
|
|
15512
14662
|
|
|
15513
|
-
export { Alert, Badge,
|
|
14663
|
+
export { Alert, Badge, Button, Card, CardBody, CardFooter, CardHeader, Collapse, CompletionStatusIndicator, CopyButton, CopyableValue, DEFAULT_SKELETON_PREFERENCE_CARD_PROPS, DetailsList, EmptyState, EmptyValue, ExternalLink, GridAreas, Heading, Highlight, HorizontalOverflowScroller, Icon, IconButton, IdentityCard, IdentityCardSkeleton, Indicator, KPI, KPICard, KPICardSkeleton, KPISkeleton, LabeledValue, LabeledValueList, List, ListItem, MenuContent, MenuDivider, MenuItem, MenuTree, MoreMenu, Notice, PackageNameStoryComponent, Page, PageContent, PageHeader, PageHeaderKpiMetrics, PageHeaderSecondaryActions, PageHeaderTitle, Pagination, Polygon, Popover, PopoverContent, PopoverTitle, PopoverTrigger, Portal, PreferenceCard, PreferenceCardSkeleton, Prompt, ROLE_CARD, SHEET_TRANSITION_DURATION, SHEET_TRANSITION_DURATION_MS, SHEET_TRANSITION_EASING, SectionHeader, SegmentedValueBar, Sheet, Sidebar, SidebarContentLayout, SkeletonBlock, SkeletonLabel, SkeletonLines, Spacer, Spinner, StarButton, Tab, TabContent, TabList, Tabs, Tag, Text, ToggleGroup, Tooltip, TrendIndicator, TrendIndicators, ValueBar, ZStack, createGrid, cvaButton, cvaButtonPrefixSuffix, cvaButtonSpinner, cvaButtonSpinnerContainer, cvaClickable, cvaContainerStyles, cvaContentContainer, cvaContentWrapper, cvaDescriptionCard, cvaIconBackground, cvaIconButton, cvaImgStyles, cvaIndicator, cvaIndicatorIcon, cvaIndicatorIconBackground, cvaIndicatorLabel, cvaIndicatorPing, cvaInputContainer, cvaInteractableItem, cvaList, cvaListContainer, cvaListItem$1 as cvaListItem, cvaMenu, cvaMenuItem, cvaMenuItemLabel, cvaMenuItemPrefix, cvaMenuItemStyle, cvaMenuItemSuffix, cvaMenuList, cvaMenuListDivider, cvaMenuListItem, cvaMenuListMultiSelect, cvaPageHeader, cvaPageHeaderContainer, cvaPageHeaderHeading, cvaPreferenceCard, cvaTitleCard, cvaToggleGroup, cvaToggleGroupWithSlidingBackground, cvaToggleItem, cvaToggleItemContent, cvaToggleItemText, cvaZStackContainer, cvaZStackItem, defaultPageSize, docs, getDevicePixelRatio, getValueBarColorByValue, iconColorNames, iconPalette, noPagination, preferenceCardGrid, useBidirectionalScroll, useClickOutside, useContainerBreakpoints, useContinuousTimeout, useCopyToClipboard, useCustomEncoding, useDebounce, useDevicePixelRatio, useElevatedReducer, useElevatedState, useGridAreas, useHold, useHover, useInfiniteScroll, useIsFirstRender, useIsFullscreen, useIsTextTruncated, useKeyboardShortcut, useList, useListItemHeight, useLocalStorage, useLocalStorageReducer, useMeasure, useMenuSearchField, useMenuTree, useMergeRefs, useModifierKey, useOptionalPopoverContext, useOverflowBorder, useOverflowItems, usePopoverContext, usePrevious, usePrompt, useRandomCSSLengths, useRelayPagination, useResize, useScrollBlock, useScrollDetection, useSelfUpdatingRef, useSessionStorage, useSessionStorageReducer, useSheet, useSheetSnap, useStorageKey, useStripForeignIdentityHash, useTextSearch, useTimeout, useViewportBreakpoints, useWatch, useWindowActivity };
|