@trackunit/react-components 3.8.2 → 3.8.3-alpha-e1e6a0f33ce.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.
@@ -1,55 +0,0 @@
1
- /**
2
- * Default maximum length of the resulting URL fragment after adding one
3
- * persisted entry. Oversized new entries are skipped; oversized replacements
4
- * remove the stale entry so localStorage remains authoritative.
5
- *
6
- * The fragment is never sent to the server, so it is not subject to the
7
- * AWS WAF managed-rule `SizeRestrictions_QUERYSTRING` cap that applies to
8
- * search params (5000 bytes). 64 KB stays well below typical browser URL
9
- * limits (Chromium ≳ 100 KB, Firefox ≳ 64 KB on the address bar) while
10
- * still leaving generous headroom for any realistic table state.
11
- */
12
- export declare const MAX_HASH_LENGTH: number;
13
- type UseHashParamSyncOptions = {
14
- readonly key: string;
15
- readonly enabled?: boolean;
16
- readonly onExternalChange?: () => void;
17
- readonly replace?: boolean;
18
- };
19
- type UseHashParamSyncReturn = {
20
- /**
21
- * Mirrors the field name on `useSearchParamSync` so this hook is a
22
- * drop-in replacement when only the URL location changes (search ↔ hash).
23
- * Despite the name, this value is read from `location.hash`.
24
- */
25
- readonly searchValue: string | undefined;
26
- /**
27
- * Mirrors the function name on `useSearchParamSync`. Writes to
28
- * `location.hash`, preserving any foreign fragment content untouched.
29
- */
30
- readonly updateSearchParam: (encodedValue: string | undefined, options?: {
31
- readonly replace?: boolean;
32
- }) => void;
33
- };
34
- /**
35
- * Syncs an encoded string value with a single named entry inside the URL
36
- * fragment (`location.hash`) via Tanstack Router.
37
- *
38
- * Behaviour mirrors `useSearchParamSync`, with two differences:
39
- * - Reads from and writes to `location.hash` instead of `location.search`.
40
- * - Oversized replacements remove stale values using
41
- * {@link MAX_HASH_LENGTH}, rather than the AWS-WAF-driven search-param cap.
42
- *
43
- * The fragment is treated as a sequence of `&`-separated tokens via the
44
- * pure utilities in `./hashFragment`. Foreign tokens (bare anchors, other
45
- * named entries) are preserved byte-for-byte on every write.
46
- *
47
- * @param options - Configuration for the hash entry sync.
48
- * @param options.key - The named entry inside the fragment.
49
- * @param options.enabled - Set to `false` to disable all URL interaction (default `true`).
50
- * @param options.onExternalChange - Called when the entry changes externally
51
- * (e.g. browser back/forward, pasted link, foreign router push).
52
- * @param options.replace - `true` to always use `replaceState` instead of pushState.
53
- */
54
- export declare const useHashParamSync: ({ key, enabled, onExternalChange, replace: replaceOption, }: UseHashParamSyncOptions) => UseHashParamSyncReturn;
55
- export {};
@@ -1,62 +0,0 @@
1
- type UseMigrateLegacySearchParamOptions<TState> = {
2
- readonly key: string;
3
- readonly enabled: boolean;
4
- /**
5
- * Pure decoder for the raw search-param string. Should not throw — return
6
- * `undefined` when the input can't be decoded.
7
- */
8
- readonly decode: (rawSearchValue: string) => unknown;
9
- /**
10
- * Optional transform applied to the decoded payload before validation
11
- * (mirrors `usePersistedState`'s `fromUrlValue`).
12
- */
13
- readonly fromUrlValue?: (decoded: unknown) => unknown;
14
- /**
15
- * Schema validator. Return the parsed state on success, `undefined`
16
- * otherwise.
17
- */
18
- readonly validate: (raw: unknown) => TState | undefined;
19
- /**
20
- * When `true`, the hash already carries a valid value for this key. The
21
- * hook still strips the legacy search param (so the URL is clean) but
22
- * does NOT fire `onMigrated` — the hash is canonical and we must not
23
- * stomp on it.
24
- */
25
- readonly hashAlreadyHasValue: boolean;
26
- /**
27
- * Called at most once when a valid legacy search-param value is found
28
- * and the hash is currently empty. Pipe through your normal
29
- * `persistState` so the value ends up in both the hash and localStorage.
30
- */
31
- readonly onMigrated: (state: TState) => void;
32
- };
33
- /**
34
- * One-shot migration: if the URL still carries a legacy `?<key>=...`
35
- * search param from before this hook moved table-style state to the
36
- * fragment, decode it, hand it to the caller via `onMigrated`, then strip
37
- * the search param via a `replace` navigation so back/forward history
38
- * isn't polluted.
39
- *
40
- * Invariants:
41
- * - The strip navigation fires at most once per mount (guarded by
42
- * `hasStrippedRef`) so we don't loop on the navigation we ourselves
43
- * triggered.
44
- * - `onMigrated` is also fired at most once per mount (guarded by
45
- * `hasMigratedRef`), but its gating is independent of the strip:
46
- * if `hashAlreadyHasValue` flips `true → false` after the strip
47
- * (e.g. an external actor clears the canonical hash mid-mount), the
48
- * next render still gets a chance to migrate the legacy value into
49
- * the hash. Conflating the two flags would have permanently lost
50
- * the legacy state in that race.
51
- * - Never throws — a decode/validate failure silently drops the value
52
- * and still strips the search param. The legacy key is owned by this
53
- * codebase's persistence convention (camelCase + `Tp` suffix), so
54
- * stripping unparseable values cannot destroy third-party data.
55
- * - When `hashAlreadyHasValue` is `true` the hash wins: the search
56
- * param is stripped but `onMigrated` is not fired.
57
- * - The `location.hash` is preserved verbatim across the strip
58
- * navigation so any concurrent hash content (including a freshly
59
- * written value) survives the cleanup.
60
- */
61
- export declare const useMigrateLegacySearchParam: <TState>({ key, enabled, decode, fromUrlValue, validate, hashAlreadyHasValue, onMigrated, }: UseMigrateLegacySearchParamOptions<TState>) => void;
62
- export {};