@cloudwick/astral-ui 8.0.0 → 8.1.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/README.md +1 -1
- package/dist/components/button/reloadButton.d.ts +20 -0
- package/dist/components/emptyState/emptyStateVariants.d.ts +3 -3
- package/dist/components/multiSelectTransfer/index.d.ts +1 -1
- package/dist/components/multiSelectTransfer/multiSelectTransfer.d.ts +5 -4
- package/dist/components/multiSelectTransfer/multiSelectTransferDropdown.d.ts +21 -3
- package/dist/components/multiSelectTransfer/multiSelectTransferModal.d.ts +16 -4
- package/dist/components/multiSelectTransfer/multiSelectTransferTrigger.d.ts +26 -0
- package/dist/components/multiSelectTransfer/multiSelectTransferVariants.d.ts +18 -0
- package/dist/components/multiSelectTransfer/types.d.ts +84 -2
- package/dist/components/multiSelectTransfer/useMultiSelectTransferDraft.d.ts +24 -0
- package/dist/components/multiSelectTransfer/useMultiSelectTransferOptionSource.d.ts +56 -0
- package/dist/components/select/index.d.ts +1 -1
- package/dist/components/select/select.d.ts +5 -6
- package/dist/components/select/selectComponents.d.ts +2 -18
- package/dist/components/select/selectMenu.d.ts +12 -0
- package/dist/components/select/selectVariants.d.ts +6 -0
- package/dist/components/select/types.d.ts +129 -15
- package/dist/components/select/useSelectOptionSource.d.ts +39 -0
- package/dist/components/select/useSelectOutsideClose.d.ts +16 -0
- package/dist/components/select/utils.d.ts +2 -1
- package/dist/components/transferList/index.d.ts +1 -1
- package/dist/components/transferList/transferList.d.ts +2 -5
- package/dist/components/transferList/transferListPanel.d.ts +14 -1
- package/dist/components/transferList/transferListPanelHeader.d.ts +29 -0
- package/dist/components/transferList/transferListVariants.d.ts +9 -0
- package/dist/components/transferList/types.d.ts +86 -10
- package/dist/components/transferList/useTransferList.d.ts +1 -1
- package/dist/components/transferList/useTransferListPanelKeys.d.ts +28 -0
- package/dist/components/transferList/useTransferListSource.d.ts +49 -0
- package/dist/css/index.min.css +1 -1
- package/dist/hooks/index.d.ts +7 -1
- package/dist/hooks/useAsyncOptions.d.ts +85 -0
- package/dist/hooks/useAsyncOptionsReducer.d.ts +75 -0
- package/dist/hooks/useAvailableProjection.d.ts +20 -0
- package/dist/hooks/useFilterQuery.d.ts +28 -0
- package/dist/hooks/useIgnoredPropWarning.d.ts +5 -0
- package/dist/hooks/useInfiniteScroll.d.ts +11 -2
- package/dist/hooks/useOnValueChange.d.ts +6 -0
- package/dist/hooks/usePrefetchBaseline.d.ts +22 -0
- package/dist/index.cjs.js +5 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +5 -5
- package/dist/utils/devWarn.d.ts +5 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/mergeUnique.d.ts +6 -0
- package/dist/utils/resolveLoadErrors.d.ts +20 -0
- package/dist/utils/resolveReloadControls.d.ts +23 -0
- package/package.json +2 -2
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Why the hook is calling `loadOptions`. A `T`-union, not an `E`-enum: it never crosses a public prop surface. */
|
|
2
|
+
export type TAsyncRequest = "defaults" | "search" | "more" | "reload";
|
|
3
|
+
/**
|
|
4
|
+
* When a server-sourced list fetches its unfiltered baseline. The component decides which trigger the
|
|
5
|
+
* value maps to and passes `prefetchDefaults: prefetch !== "never"` here; a surface with no open/close
|
|
6
|
+
* narrows the union rather than redefining it.
|
|
7
|
+
*/
|
|
8
|
+
export type TPrefetch = "mount" | "open" | "never";
|
|
9
|
+
export interface ILoadOptionsMeta {
|
|
10
|
+
/** Aborts superseded requests. Honouring it is optional — the ticket guard is independent. */
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
/** undefined for the first page of a bucket; else the cursor the previous page returned. */
|
|
13
|
+
cursor: unknown;
|
|
14
|
+
/** Zero-based page index within the current bucket. Convenience for offset/limit APIs. */
|
|
15
|
+
page: number;
|
|
16
|
+
/** Why the hook is calling. */
|
|
17
|
+
reason: TAsyncRequest;
|
|
18
|
+
}
|
|
19
|
+
export interface IOptionPage<TOptionType> {
|
|
20
|
+
options: readonly TOptionType[];
|
|
21
|
+
/** Opaque, handed back on the next call for this bucket. Absent/null ⇒ no further pages. */
|
|
22
|
+
cursor?: unknown;
|
|
23
|
+
/** Explicit override; defaults to `cursor` being present. */
|
|
24
|
+
hasMore?: boolean;
|
|
25
|
+
/** Total matching rows on the server, if known. Rendered as "(loaded of total)". */
|
|
26
|
+
total?: number;
|
|
27
|
+
}
|
|
28
|
+
export type TLoadOptions<TOptionType> = (query: string, meta: ILoadOptionsMeta) => Promise<readonly TOptionType[] | IOptionPage<TOptionType>>;
|
|
29
|
+
export interface IUseAsyncOptionsArgs<TOptionType> {
|
|
30
|
+
/** Option source. Without it every returned callback is inert and no state is ever written. */
|
|
31
|
+
loadOptions?: TLoadOptions<TOptionType>;
|
|
32
|
+
/**
|
|
33
|
+
* Shown before the first fetch and whenever no bucket is loaded. Never blocks the baseline fetch,
|
|
34
|
+
* and is not hidden by it either — but a search replaces it, since it is not a result for a query.
|
|
35
|
+
*/
|
|
36
|
+
initialOptions?: readonly TOptionType[];
|
|
37
|
+
/** Fetch the empty-query baseline when `ensureDefaults()` is first called. @default true */
|
|
38
|
+
prefetchDefaults?: boolean;
|
|
39
|
+
/** Clearing the query revalidates the cached baseline instead of only restoring it. @default false */
|
|
40
|
+
refetchOnClear?: boolean;
|
|
41
|
+
/** Identity of the option set. A change drops both buckets and rejects in-flight landings. */
|
|
42
|
+
optionsKey?: string | number;
|
|
43
|
+
/** Identity for append dedupe. Without it a paged append is blind. */
|
|
44
|
+
getOptionKey?: (option: TOptionType) => string | number;
|
|
45
|
+
/** Notified with the raw cause of every genuine (non-aborted, non-superseded) failure. */
|
|
46
|
+
onLoadError?: (error: unknown) => void;
|
|
47
|
+
}
|
|
48
|
+
export interface IUseAsyncOptionsResult<TOptionType> {
|
|
49
|
+
/** Active bucket, pages concatenated. Exactly the objects `loadOptions` returned — never re-materialised. */
|
|
50
|
+
options: readonly TOptionType[];
|
|
51
|
+
/** Any request in flight. Feeds aria-busy. */
|
|
52
|
+
isBusy: boolean;
|
|
53
|
+
/** Loader INSTEAD of rows. Gates nav keys and aria-activedescendant. */
|
|
54
|
+
isReplacing: boolean;
|
|
55
|
+
/** Loader BELOW rows. Feeds useInfiniteScroll's in-flight gate. */
|
|
56
|
+
isLoadingMore: boolean;
|
|
57
|
+
/** Only the reload button spins. Overlaps isReplacing; neither implies the other. */
|
|
58
|
+
isReloading: boolean;
|
|
59
|
+
hasError: boolean;
|
|
60
|
+
/** Which request failed; a failed "more" must not blank the list. */
|
|
61
|
+
errorKind: TAsyncRequest | null;
|
|
62
|
+
/** False while a failed page is blocking, so a sentinel still in view cannot retry-loop. */
|
|
63
|
+
hasMore: boolean;
|
|
64
|
+
/** Server total for the active bucket, when the loader reported one. */
|
|
65
|
+
total: number | undefined;
|
|
66
|
+
/** Wire to useFilterQuery — already debounced upstream. Stable identity. */
|
|
67
|
+
onFilterChange: (query: string) => void;
|
|
68
|
+
/** Idempotent; joins an in-flight base request. Call on open (or mount). Stable identity. */
|
|
69
|
+
ensureDefaults: () => void;
|
|
70
|
+
/** Re-run the query the list currently reflects, from page one. Stable identity. */
|
|
71
|
+
reload: () => void;
|
|
72
|
+
/** Next page of the active bucket. Safe to call from an IntersectionObserver. Stable identity. */
|
|
73
|
+
loadMore: () => void;
|
|
74
|
+
/** Clears the failed-page block and retries that page. Only ever called from a user gesture. */
|
|
75
|
+
retryMore: () => void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Owns an async option source: request ordering, the empty-query baseline, paging with dedupe, and
|
|
79
|
+
* the loading/error kinds the surfaces render. The monotonic ticket per slot — not the upstream
|
|
80
|
+
* debounce — is what makes out-of-order responses impossible.
|
|
81
|
+
*
|
|
82
|
+
* Every returned callback has a permanently stable identity (config and callbacks are read through
|
|
83
|
+
* refs), so an inline arrow `loadOptions` at the call site costs nothing and needs no `useMemo`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function useAsyncOptions<TOptionType>({ loadOptions, initialOptions, prefetchDefaults, refetchOnClear, optionsKey, getOptionKey, onLoadError }: IUseAsyncOptionsArgs<TOptionType>): IUseAsyncOptionsResult<TOptionType>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { IOptionPage, TAsyncRequest } from "./useAsyncOptions";
|
|
2
|
+
/**
|
|
3
|
+
* One request slot. `base` (the empty-query baseline) and `view` (the current query) write disjoint
|
|
4
|
+
* state, so making them cancel each other would be pure loss — and is exactly what would let a menu
|
|
5
|
+
* close destroy the baseline it is meant to restore.
|
|
6
|
+
*/
|
|
7
|
+
export type TRequestSlot = "base" | "view";
|
|
8
|
+
export interface IOptionBucket<TOptionType> {
|
|
9
|
+
options: readonly TOptionType[];
|
|
10
|
+
cursor: unknown;
|
|
11
|
+
/** Pages landed so far; the next request for this bucket gets `meta.page = page`. */
|
|
12
|
+
page: number;
|
|
13
|
+
hasMore: boolean;
|
|
14
|
+
total: number | undefined;
|
|
15
|
+
}
|
|
16
|
+
export interface IPendingKinds {
|
|
17
|
+
base: TAsyncRequest | null;
|
|
18
|
+
view: TAsyncRequest | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Two buckets, never sharing storage: the empty-query result and the current-query result are
|
|
22
|
+
* different things, so clearing the query can *restore* rather than destroy. `pending` holds the
|
|
23
|
+
* request *kind* per slot rather than a boolean, because "which loader do I render" is a question
|
|
24
|
+
* about the kind — and parallel booleans are how loading state and error state drift out of step.
|
|
25
|
+
*/
|
|
26
|
+
export interface IAsyncOptionsState<TOptionType> {
|
|
27
|
+
base: IOptionBucket<TOptionType> | null;
|
|
28
|
+
search: (IOptionBucket<TOptionType> & {
|
|
29
|
+
query: string;
|
|
30
|
+
}) | null;
|
|
31
|
+
pending: IPendingKinds;
|
|
32
|
+
/** Only the kind: the raw cause goes straight to `onLoadError`, and nothing renders it. */
|
|
33
|
+
error: {
|
|
34
|
+
kind: TAsyncRequest;
|
|
35
|
+
} | null;
|
|
36
|
+
/** Set by a failed page append; disarms `hasMore` until `retryMore()`. */
|
|
37
|
+
moreBlocked: boolean;
|
|
38
|
+
query: string;
|
|
39
|
+
key: string | number | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The `optionsKey` a request was issued under. See the guard at the top of the reducer. */
|
|
42
|
+
type TKeyed = {
|
|
43
|
+
key: string | number | undefined;
|
|
44
|
+
};
|
|
45
|
+
export type TAsyncOptionsAction<TOptionType> = {
|
|
46
|
+
type: "set-query";
|
|
47
|
+
query: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: "invalidate";
|
|
50
|
+
key: string | number | undefined;
|
|
51
|
+
} | ({
|
|
52
|
+
type: "start";
|
|
53
|
+
slot: TRequestSlot;
|
|
54
|
+
kind: TAsyncRequest;
|
|
55
|
+
} & TKeyed) | ({
|
|
56
|
+
type: "land";
|
|
57
|
+
slot: TRequestSlot;
|
|
58
|
+
kind: TAsyncRequest;
|
|
59
|
+
query: string;
|
|
60
|
+
page: IOptionPage<TOptionType>;
|
|
61
|
+
getOptionKey?: (option: TOptionType) => string | number;
|
|
62
|
+
} & TKeyed) | ({
|
|
63
|
+
type: "fail";
|
|
64
|
+
slot: TRequestSlot;
|
|
65
|
+
kind: TAsyncRequest;
|
|
66
|
+
} & TKeyed) | {
|
|
67
|
+
type: "restore-base";
|
|
68
|
+
} | {
|
|
69
|
+
type: "unblock-more";
|
|
70
|
+
};
|
|
71
|
+
/** A bare array return normalises to a single, final page, so the simple case stays a one-liner. */
|
|
72
|
+
export declare const normalisePage: <TOptionType>(result: readonly TOptionType[] | IOptionPage<TOptionType>) => IOptionPage<TOptionType>;
|
|
73
|
+
export declare function createInitialState<TOptionType>(key: string | number | undefined): IAsyncOptionsState<TOptionType>;
|
|
74
|
+
export declare function asyncOptionsReducer<TOptionType>(state: IAsyncOptionsState<TOptionType>, action: TAsyncOptionsAction<TOptionType>): IAsyncOptionsState<TOptionType>;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/** The shape both transfer surfaces project: anything `matchesQuery` can search and `value` can key. */
|
|
3
|
+
interface IProjectableItem {
|
|
4
|
+
value: string | number;
|
|
5
|
+
label: ReactNode;
|
|
6
|
+
searchValue?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The Available panel of a server-sourced transfer surface: the loaded pool, plus items the pool may
|
|
10
|
+
* not contain, minus whatever is already selected.
|
|
11
|
+
*
|
|
12
|
+
* The pool is the server's answer for the active query, so it needs no local matching — but
|
|
13
|
+
* `remembered` (items the surface is carrying itself: a deselected row, a committed-but-never-fetched
|
|
14
|
+
* option) is not, and would otherwise render as a result for a query it does not match. Splitting the
|
|
15
|
+
* two halves is also what keeps a keystroke cheap: only the second memo depends on `query`, and it
|
|
16
|
+
* hands back the first one **by identity** when nothing was remembered — the common case, and the one
|
|
17
|
+
* that would otherwise re-run every pass the panel memoises over this array.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useAvailableProjection<TItem extends IProjectableItem>(enabled: boolean, pool: readonly TItem[], remembered: readonly TItem[], selected: readonly TItem[], query: string): TItem[];
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ChangeEvent, type FocusEvent, type KeyboardEvent } from "react";
|
|
2
|
+
interface IUseFilterQueryArgs {
|
|
3
|
+
/** Seeds/re-syncs the search box on change; not fully controlled — pair with onFilterChange. */
|
|
4
|
+
filterValue?: string;
|
|
5
|
+
/** Server-side filter handler; its presence is the client/server mode switch. */
|
|
6
|
+
onFilterChange?: (query: string) => void;
|
|
7
|
+
/** Debounce delay in ms for `onFilterChange`. */
|
|
8
|
+
filterDebounceMs: number;
|
|
9
|
+
}
|
|
10
|
+
interface IUseFilterQueryResult {
|
|
11
|
+
/** Current search text. */
|
|
12
|
+
filterQuery: string;
|
|
13
|
+
/** Change handler for the search input. */
|
|
14
|
+
handleFilterInput: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
15
|
+
/** The same path as `handleFilterInput` for surfaces that report their search as a plain string. */
|
|
16
|
+
setFilterQuery: (query: string) => void;
|
|
17
|
+
/** Marks Backspace/Delete held so debounce waits for release (see handleFilterKeyUp). */
|
|
18
|
+
handleFilterKeyDown: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
19
|
+
/** On Backspace/Delete release, starts the deferred debounce. */
|
|
20
|
+
handleFilterKeyUp: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
21
|
+
/** On blur during a Backspace/Delete hold, release and start the deferred debounce. */
|
|
22
|
+
handleFilterBlur: (e: FocusEvent<HTMLInputElement>) => void;
|
|
23
|
+
/** Clear the query, drop any pending debounce, and notify a server-side consumer. */
|
|
24
|
+
resetFilter: () => void;
|
|
25
|
+
}
|
|
26
|
+
/** Owns a search query and the debounced bridge to a server-side `onFilterChange`. */
|
|
27
|
+
export declare function useFilterQuery({ filterValue, onFilterChange, filterDebounceMs }: IUseFilterQueryArgs): IUseFilterQueryResult;
|
|
28
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Callback ref for the sentinel element. Assign it with `ref={...}`; it takes no `.current`. */
|
|
2
|
+
export type TSentinelRef<T extends HTMLElement = HTMLDivElement> = (node: T | null) => void;
|
|
1
3
|
interface IUseInfiniteScrollArgs {
|
|
2
4
|
/** Whether more items can be loaded. The observer is inert when false. */
|
|
3
5
|
hasMore?: boolean;
|
|
@@ -10,7 +12,14 @@ interface IUseInfiniteScrollArgs {
|
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* Attaches an IntersectionObserver to a sentinel element and fires `onLoadMore` when it
|
|
13
|
-
* scrolls into view. Returns the ref to
|
|
15
|
+
* scrolls into view. Returns the callback ref to put on the sentinel element.
|
|
16
|
+
*
|
|
17
|
+
* A **callback ref backed by state**, not a `RefObject`, because the sentinel's identity has to be
|
|
18
|
+
* one of the effect's dependencies. The surfaces here unmount the rows — and the sentinel with them —
|
|
19
|
+
* while a search fetch replaces the list, and none of the other dependencies change across that round
|
|
20
|
+
* trip: the observer would stay bound to the detached node and paging would be silently dead for
|
|
21
|
+
* every search result set. A callback ref re-runs the effect on each detach/attach, so the observer
|
|
22
|
+
* always watches the node that is actually in the document.
|
|
14
23
|
*
|
|
15
24
|
* `onLoadMore` is read through a ref so passing a fresh inline callback each render doesn't tear
|
|
16
25
|
* the observer down and recreate it. `isLoading`, by contrast, IS a dependency: no observer exists
|
|
@@ -20,5 +29,5 @@ interface IUseInfiniteScrollArgs {
|
|
|
20
29
|
* freshly-observed sentinel fires an initial callback with its current intersection, so the next
|
|
21
30
|
* page loads immediately instead of stalling until the user scrolls.
|
|
22
31
|
*/
|
|
23
|
-
export declare function useInfiniteScroll<T extends HTMLElement = HTMLDivElement>({ hasMore, isLoading, onLoadMore, enabled }: IUseInfiniteScrollArgs):
|
|
32
|
+
export declare function useInfiniteScroll<T extends HTMLElement = HTMLDivElement>({ hasMore, isLoading, onLoadMore, enabled }: IUseInfiniteScrollArgs): TSentinelRef<T>;
|
|
24
33
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs `onChange` when `value` CHANGES, never on mount. The ref comparison is the whole point: a
|
|
3
|
+
* plain effect on `[value]` also fires on paint, and the callers here route the change into a reset
|
|
4
|
+
* path that would clobber consumer-seeded state if it ran before the user had touched anything.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useOnValueChange<TValue>(value: TValue, onChange: () => void): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TPrefetch } from "./useAsyncOptions";
|
|
2
|
+
interface IUsePrefetchBaselineArgs {
|
|
3
|
+
/** Which trigger arms the baseline fetch. A surface with no open/close narrows the union. */
|
|
4
|
+
prefetch: TPrefetch;
|
|
5
|
+
/** Whether the surface is currently open. Omit on a surface that is always visible. */
|
|
6
|
+
isOpen?: boolean;
|
|
7
|
+
/** Identity of the option set — a change re-arms an already-armed prefetch. */
|
|
8
|
+
optionsKey?: string | number;
|
|
9
|
+
/** `useAsyncOptions().ensureDefaults`. Idempotent and latch-guarded. */
|
|
10
|
+
ensureDefaults: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Translates a `prefetch` trigger into the one effect that calls `ensureDefaults`. Shared so the
|
|
14
|
+
* three option surfaces cannot answer "when is the baseline fetched" differently.
|
|
15
|
+
*
|
|
16
|
+
* `armed` — not the raw flags — is the dependency, which is what keeps `"mount"` from re-firing when
|
|
17
|
+
* the surface opens (it is already true) while still letting `"open"` fire on the false→true edge.
|
|
18
|
+
* `optionsKey` is a dependency (and only a dependency) so a dependent surface whose parent changes
|
|
19
|
+
* while armed repopulates immediately.
|
|
20
|
+
*/
|
|
21
|
+
export declare function usePrefetchBaseline({ prefetch, isOpen, optionsKey, ensureDefaults }: IUsePrefetchBaselineArgs): void;
|
|
22
|
+
export {};
|