@cloudwick/astral-ui-cli 2.0.1 → 2.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/index.js +1377 -80
- package/dist/index.js.map +1 -1
- package/dist/templates/constants/index.ts +1 -0
- package/dist/templates/css/fonts.min.css +1 -1
- package/dist/templates/fonts/NotoSans-Bold.woff2 +0 -0
- package/dist/templates/fonts/NotoSans-BoldItalic.woff2 +0 -0
- package/dist/templates/fonts/NotoSans-Italic.woff2 +0 -0
- package/dist/templates/fonts/NotoSans-Medium.woff2 +0 -0
- package/dist/templates/fonts/NotoSans-MediumItalic.woff2 +0 -0
- package/dist/templates/fonts/NotoSans-Regular.woff2 +0 -0
- package/dist/templates/fonts/NotoSans-SemiBold.woff2 +0 -0
- package/dist/templates/fonts/NotoSans-SemiBoldItalic.woff2 +0 -0
- package/dist/templates/hooks/index.ts +5 -1
- package/dist/templates/hooks/useDebouncedCallback.ts +42 -0
- package/dist/templates/hooks/useInfiniteScroll.ts +52 -0
- package/dist/templates/hooks/useIsTruncated.ts +63 -0
- package/dist/templates/hooks/useListboxKeyboardNav.ts +120 -0
- package/dist/templates/tailwind/tailwind.config.js +8 -8
- package/dist/templates/utils/elementUtils.ts +26 -0
- package/dist/templates/utils/index.ts +3 -1
- package/dist/templates/utils/matchesQuery.test.tsx +32 -0
- package/dist/templates/utils/matchesQuery.ts +23 -0
- package/package.json +2 -2
- package/dist/templates/fonts/Inter_18pt-Bold.ttf +0 -0
- package/dist/templates/fonts/Inter_18pt-BoldItalic.ttf +0 -0
- package/dist/templates/fonts/Inter_18pt-Italic.ttf +0 -0
- package/dist/templates/fonts/Inter_18pt-Medium.ttf +0 -0
- package/dist/templates/fonts/Inter_18pt-MediumItalic.ttf +0 -0
- package/dist/templates/fonts/Inter_18pt-Regular.ttf +0 -0
- package/dist/templates/fonts/Inter_18pt-SemiBold.ttf +0 -0
- package/dist/templates/fonts/Inter_18pt-SemiBoldItalic.ttf +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
@font-face{font-family:
|
|
1
|
+
@font-face{font-family:noto-sans-regular;src:url(../fonts/NotoSans-Regular.woff2) format("woff2");font-display:swap}@font-face{font-family:noto-sans-italic;src:url(../fonts/NotoSans-Italic.woff2) format("woff2");font-display:swap}@font-face{font-family:noto-sans-medium;src:url(../fonts/NotoSans-Medium.woff2) format("woff2");font-display:swap}@font-face{font-family:noto-sans-medium-italic;src:url(../fonts/NotoSans-MediumItalic.woff2) format("woff2");font-display:swap}@font-face{font-family:noto-sans-semibold;src:url(../fonts/NotoSans-SemiBold.woff2) format("woff2");font-display:swap}@font-face{font-family:noto-sans-semibold-italic;src:url(../fonts/NotoSans-SemiBoldItalic.woff2) format("woff2");font-display:swap}@font-face{font-family:noto-sans-bold;src:url(../fonts/NotoSans-Bold.woff2) format("woff2");font-display:swap}@font-face{font-family:noto-sans-bold-italic;src:url(../fonts/NotoSans-BoldItalic.woff2) format("woff2");font-display:swap}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export { useWindowSize } from "./useWindowSize";
|
|
1
|
+
export { useWindowSize } from "./useWindowSize";
|
|
2
|
+
export { useInfiniteScroll } from "./useInfiniteScroll";
|
|
3
|
+
export { useDebouncedCallback } from "./useDebouncedCallback";
|
|
4
|
+
export { useIsTruncated } from "./useIsTruncated";
|
|
5
|
+
export { useListboxKeyboardNav } from "./useListboxKeyboardNav";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a debounced wrapper around `callback` plus a `cancel` handle. The latest `callback`
|
|
5
|
+
* is always invoked (read through a ref, so passing a fresh inline function each render is safe),
|
|
6
|
+
* and the pending timer is cleared on unmount. A `delay` of `0` (or less) invokes synchronously,
|
|
7
|
+
* which is handy for an "instant" mode without special-casing at the call site.
|
|
8
|
+
*/
|
|
9
|
+
export function useDebouncedCallback<Params extends unknown[]>(
|
|
10
|
+
callback: ( ...args: Params ) => void,
|
|
11
|
+
delay: number
|
|
12
|
+
): { call: ( ...args: Params ) => void; cancel: () => void } {
|
|
13
|
+
const callbackRef = useRef( callback );
|
|
14
|
+
callbackRef.current = callback;
|
|
15
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | null>( null );
|
|
16
|
+
|
|
17
|
+
const cancel = useCallback(() => {
|
|
18
|
+
if ( timerRef.current ) {
|
|
19
|
+
clearTimeout( timerRef.current );
|
|
20
|
+
timerRef.current = null;
|
|
21
|
+
}
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
const call = useCallback(
|
|
25
|
+
( ...args: Params ) => {
|
|
26
|
+
cancel();
|
|
27
|
+
if ( delay <= 0 ) {
|
|
28
|
+
callbackRef.current( ...args );
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
timerRef.current = setTimeout(() => {
|
|
32
|
+
timerRef.current = null;
|
|
33
|
+
callbackRef.current( ...args );
|
|
34
|
+
}, delay );
|
|
35
|
+
},
|
|
36
|
+
[ delay, cancel ]
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
useEffect(() => cancel, [cancel]);
|
|
40
|
+
|
|
41
|
+
return { call, cancel };
|
|
42
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
interface IUseInfiniteScrollArgs {
|
|
4
|
+
/** Whether more items can be loaded. The observer is inert when false. */
|
|
5
|
+
hasMore?: boolean;
|
|
6
|
+
/** In-flight load flag; while true an intersection will not re-trigger a load. */
|
|
7
|
+
isLoading?: boolean;
|
|
8
|
+
/** Called when the sentinel scrolls into view and no load is in flight. */
|
|
9
|
+
onLoadMore?: () => void;
|
|
10
|
+
/** Extra gate (e.g. an open dropdown). The observer is inert when false. @default true */
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Attaches an IntersectionObserver to a sentinel element and fires `onLoadMore` when it
|
|
16
|
+
* scrolls into view. Returns the ref to spread onto the sentinel element.
|
|
17
|
+
*
|
|
18
|
+
* `onLoadMore` is read through a ref so passing a fresh inline callback each render doesn't tear
|
|
19
|
+
* the observer down and recreate it. `isLoading`, by contrast, IS a dependency: no observer exists
|
|
20
|
+
* while a load is in flight, and finishing a load recreates the observer. That re-arm matters —
|
|
21
|
+
* IntersectionObserver only fires on a boundary *crossing*, so a sentinel that stayed in view after
|
|
22
|
+
* a page loaded (e.g. the new page didn't fill the container) would never re-trigger otherwise. A
|
|
23
|
+
* freshly-observed sentinel fires an initial callback with its current intersection, so the next
|
|
24
|
+
* page loads immediately instead of stalling until the user scrolls.
|
|
25
|
+
*/
|
|
26
|
+
export function useInfiniteScroll<T extends HTMLElement = HTMLDivElement>({
|
|
27
|
+
hasMore = false,
|
|
28
|
+
isLoading = false,
|
|
29
|
+
onLoadMore,
|
|
30
|
+
enabled = true
|
|
31
|
+
}: IUseInfiniteScrollArgs ) {
|
|
32
|
+
const sentinelRef = useRef<T>( null );
|
|
33
|
+
|
|
34
|
+
const onLoadMoreRef = useRef( onLoadMore );
|
|
35
|
+
onLoadMoreRef.current = onLoadMore;
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const el = sentinelRef.current;
|
|
39
|
+
if ( !el || !hasMore || !enabled || isLoading ) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
43
|
+
if ( entry.isIntersecting ) {
|
|
44
|
+
onLoadMoreRef.current?.();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
observer.observe( el );
|
|
48
|
+
return () => observer.disconnect();
|
|
49
|
+
}, [ hasMore, enabled, isLoading ]);
|
|
50
|
+
|
|
51
|
+
return sentinelRef;
|
|
52
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Detects whether a truncated (`overflow:hidden` + `white-space:nowrap`) element is actually
|
|
5
|
+
* clipping its content, by comparing `scrollWidth` to `clientWidth`. Re-measures on resize.
|
|
6
|
+
*
|
|
7
|
+
* Two things guard against a flicker feedback loop when the caller uses `isTruncated` to expand
|
|
8
|
+
* the element on hover/focus (nowrap -> normal, single line -> wrapped, often via
|
|
9
|
+
* `position:absolute`):
|
|
10
|
+
*
|
|
11
|
+
* 1. `measure()` bails while the element is expanded. Once expanded, the element is laid out to
|
|
12
|
+
* fit its container (`scrollWidth === clientWidth`), so a measurement then would wrongly read
|
|
13
|
+
* "not truncated", strip the expand styles, collapse the element, and re-trigger - forever.
|
|
14
|
+
* We only trust a reading taken in the base (non-expanded) layout, detected via
|
|
15
|
+
* `position !== "absolute"`.
|
|
16
|
+
* 2. Only a change in the measured *width* matters. Expanding the element also changes its
|
|
17
|
+
* *height* (and, through `self-stretch`, its wrapper's height), which would otherwise fire the
|
|
18
|
+
* ResizeObserver mid-hover; tracking the last width lets us ignore those height-only fires.
|
|
19
|
+
*
|
|
20
|
+
* `containerRef` (optional) attaches to an ancestor to observe instead of the element itself
|
|
21
|
+
* (e.g. the flex wrapper around a label); falls back to the measured element when unattached.
|
|
22
|
+
*/
|
|
23
|
+
export function useIsTruncated<T extends HTMLElement, C extends HTMLElement = T>(): {
|
|
24
|
+
ref: React.RefObject<T>;
|
|
25
|
+
containerRef: React.RefObject<C>;
|
|
26
|
+
isTruncated: boolean;
|
|
27
|
+
} {
|
|
28
|
+
const ref = useRef<T>( null );
|
|
29
|
+
const containerRef = useRef<C>( null );
|
|
30
|
+
const [ isTruncated, setIsTruncated ] = useState( false );
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const node = ref.current;
|
|
34
|
+
const observedNode = containerRef.current ?? node;
|
|
35
|
+
|
|
36
|
+
if ( !node || !observedNode ) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let lastWidth = -1;
|
|
41
|
+
|
|
42
|
+
const measure = () => {
|
|
43
|
+
// Ignore the element while it is expanded and any resize that did not change its width -
|
|
44
|
+
// both would otherwise feed a hover flicker loop (see the doc comment above).
|
|
45
|
+
if ( window.getComputedStyle( node ).position === "absolute" ) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const width = node.clientWidth;
|
|
49
|
+
if ( width === lastWidth ) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
lastWidth = width;
|
|
53
|
+
setIsTruncated( node.scrollWidth > width );
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
measure();
|
|
57
|
+
const observer = new ResizeObserver( measure );
|
|
58
|
+
observer.observe( observedNode );
|
|
59
|
+
return () => observer.disconnect();
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
return { ref, containerRef, isTruncated };
|
|
63
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useEffect, useState, type RefObject } from "react";
|
|
2
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
3
|
+
|
|
4
|
+
interface IUseListboxKeyboardNavArgs {
|
|
5
|
+
/** Number of navigable rows. */
|
|
6
|
+
itemCount: number;
|
|
7
|
+
/** Whether the row at `index` is disabled (skipped by arrow navigation). */
|
|
8
|
+
isItemDisabled: ( index: number ) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Stable string describing the current row SET. The active row resets to the first enabled row
|
|
11
|
+
* whenever this changes (e.g. after a search/filter) - not on every render, which would fight
|
|
12
|
+
* the user's arrow-key position. Callers that must survive a pure reorder (same set, new order)
|
|
13
|
+
* should build this from the values sorted, so a reorder does not change the key.
|
|
14
|
+
*/
|
|
15
|
+
resetKey: string;
|
|
16
|
+
/** Scroll container the virtualizer measures and (when windowed) scrolls the active row into. */
|
|
17
|
+
scrollElementRef: RefObject<HTMLDivElement | null>;
|
|
18
|
+
/**
|
|
19
|
+
* Element the active row is looked up inside (querySelector) for the non-windowed scrollIntoView.
|
|
20
|
+
* @default scrollElementRef
|
|
21
|
+
*/
|
|
22
|
+
queryElementRef?: RefObject<HTMLDivElement | null>;
|
|
23
|
+
/** Maps a row index to its DOM id, used to locate the active row for scrollIntoView. */
|
|
24
|
+
optionId: ( index: number ) => string;
|
|
25
|
+
/** Estimated row height (px) used before real rows are measured; measureElement corrects it. */
|
|
26
|
+
estimateSize: number;
|
|
27
|
+
/** Vertical gap between rows (px). @default 0 */
|
|
28
|
+
gap?: number;
|
|
29
|
+
/** Virtualizer overscan (rows rendered beyond the viewport). @default 12 */
|
|
30
|
+
overscan?: number;
|
|
31
|
+
/** Above this many rows the list windows (virtualizes) itself. @default 100 */
|
|
32
|
+
virtualizeThreshold?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The shared keyboard-navigation + optional-windowing engine for a single-tab-stop listbox driven
|
|
37
|
+
* by `aria-activedescendant`: arrow/Home/End walk an "active" row (skipping disabled rows, with
|
|
38
|
+
* wrap-around), the active row is kept scrolled into view, and the list virtualizes itself past
|
|
39
|
+
* `virtualizeThreshold`. Consumed by TransferListPanel and MultiSelectTransferDropdown, which keep
|
|
40
|
+
* only their own key-handler switch and row renderer.
|
|
41
|
+
*/
|
|
42
|
+
export function useListboxKeyboardNav({
|
|
43
|
+
itemCount,
|
|
44
|
+
isItemDisabled,
|
|
45
|
+
resetKey,
|
|
46
|
+
scrollElementRef,
|
|
47
|
+
queryElementRef,
|
|
48
|
+
optionId,
|
|
49
|
+
estimateSize,
|
|
50
|
+
gap,
|
|
51
|
+
overscan = 12,
|
|
52
|
+
virtualizeThreshold = 100
|
|
53
|
+
}: IUseListboxKeyboardNavArgs ) {
|
|
54
|
+
// Windowing only kicks in past the threshold. The virtualizer is always instantiated (hooks
|
|
55
|
+
// can't be conditional) but does no work while count is 0.
|
|
56
|
+
const shouldVirtualize = itemCount > virtualizeThreshold;
|
|
57
|
+
const virtualizer = useVirtualizer({
|
|
58
|
+
count: shouldVirtualize ? itemCount : 0,
|
|
59
|
+
getScrollElement: () => scrollElementRef.current,
|
|
60
|
+
estimateSize: () => estimateSize,
|
|
61
|
+
gap,
|
|
62
|
+
// Measure real row heights in the browser; skipped in jsdom where layout is unavailable.
|
|
63
|
+
measureElement:
|
|
64
|
+
typeof window !== "undefined" && typeof window.ResizeObserver !== "undefined"
|
|
65
|
+
? ( element ) => element?.getBoundingClientRect().height
|
|
66
|
+
: undefined,
|
|
67
|
+
overscan
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const firstEnabledIndex = ( from: number, dir: 1 | -1 ): number => {
|
|
71
|
+
for ( let step = 0, i = from; step < itemCount; step++, i = ( i + dir + itemCount ) % itemCount ) {
|
|
72
|
+
if ( !isItemDisabled( i )) {
|
|
73
|
+
return i;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return -1;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const [ activeIndex, setActiveIndex ] = useState( 0 );
|
|
80
|
+
|
|
81
|
+
// Reset the active row to the first enabled one whenever the visible SET changes - keyed on
|
|
82
|
+
// resetKey so a pure reorder (same set) or an unrelated re-render does not yank it to the top.
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
setActiveIndex( firstEnabledIndex( 0, 1 ));
|
|
85
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
86
|
+
}, [resetKey]);
|
|
87
|
+
|
|
88
|
+
// Keep the active row in view as the arrow keys walk it. When windowed the row may not be
|
|
89
|
+
// mounted, so drive the scroll through the virtualizer (which also renders it).
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if ( activeIndex < 0 ) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if ( shouldVirtualize ) {
|
|
95
|
+
virtualizer.scrollToIndex( activeIndex, { align: "auto" });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const queryEl = ( queryElementRef ?? scrollElementRef ).current;
|
|
99
|
+
const activeEl = queryEl?.querySelector<HTMLElement>( `#${CSS.escape( optionId( activeIndex ))}` );
|
|
100
|
+
// jsdom (test env) doesn't implement scrollIntoView.
|
|
101
|
+
if ( typeof activeEl?.scrollIntoView === "function" ) {
|
|
102
|
+
activeEl.scrollIntoView({ block: "nearest" });
|
|
103
|
+
}
|
|
104
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
+
}, [activeIndex]);
|
|
106
|
+
|
|
107
|
+
const moveActive = ( dir: 1 | -1 ) => {
|
|
108
|
+
if ( itemCount === 0 ) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
setActiveIndex(( prev ) => {
|
|
112
|
+
// Guard a -1 (nothing active) start so the first arrow press still lands on a real row.
|
|
113
|
+
const start = prev < 0 ? 0 : prev;
|
|
114
|
+
const next = firstEnabledIndex(( start + dir + itemCount ) % itemCount, dir );
|
|
115
|
+
return next === -1 ? prev : next;
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return { activeIndex, setActiveIndex, moveActive, firstEnabledIndex, virtualizer, shouldVirtualize };
|
|
120
|
+
}
|
|
@@ -132,14 +132,14 @@ export default {
|
|
|
132
132
|
}
|
|
133
133
|
},
|
|
134
134
|
fontFamily: {
|
|
135
|
-
"regular": [ "
|
|
136
|
-
"italic": [ "
|
|
137
|
-
"medium": [ "
|
|
138
|
-
"medium-italic": [ "
|
|
139
|
-
"semibold": [ "
|
|
140
|
-
"semibold-italic": [ "
|
|
141
|
-
"bold": [ "
|
|
142
|
-
"bold-italic": [ "
|
|
135
|
+
"regular": [ "noto-sans-regular", "sans-serif" ],
|
|
136
|
+
"italic": [ "noto-sans-italic", "sans-serif" ],
|
|
137
|
+
"medium": [ "noto-sans-medium", "sans-serif" ],
|
|
138
|
+
"medium-italic": [ "noto-sans-medium-italic", "sans-serif" ],
|
|
139
|
+
"semibold": [ "noto-sans-semibold", "sans-serif" ],
|
|
140
|
+
"semibold-italic": [ "noto-sans-semibold-italic", "sans-serif" ],
|
|
141
|
+
"bold": [ "noto-sans-bold", "sans-serif" ],
|
|
142
|
+
"bold-italic": [ "noto-sans-bold-italic", "sans-serif" ]
|
|
143
143
|
},
|
|
144
144
|
fontSize: {
|
|
145
145
|
xxs: [ "0.625rem", { lineHeight: "100%" }], // font-size: 10px
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { semanticInteractiveElements } from "@constants";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determines whether a trigger node is already a natively-interactive,
|
|
6
|
+
* keyboard-focusable element (e.g. `<button>`, `<a>`, `<input>`).
|
|
7
|
+
*
|
|
8
|
+
* Only intrinsic HTML elements from the {@link semanticInteractiveElements}
|
|
9
|
+
* allowlist are treated as semantic. Custom React components are intentionally
|
|
10
|
+
* excluded: their rendered output cannot be introspected at runtime, so a
|
|
11
|
+
* component that renders a non-interactive element (such as an icon or `<span>`)
|
|
12
|
+
* would otherwise be stripped of its supplied interactivity/focus affordances
|
|
13
|
+
* and become keyboard-inaccessible. Excluded triggers fall back to being wrapped
|
|
14
|
+
* with the appropriate role/tabindex, which keeps them keyboard accessible.
|
|
15
|
+
*
|
|
16
|
+
* If you need a custom component to be treated as the interactive trigger, have
|
|
17
|
+
* it render one of the allowlisted native elements as its root and forward props
|
|
18
|
+
* and ref to it.
|
|
19
|
+
*/
|
|
20
|
+
export const isSemanticTrigger = ( ctaContent: React.ReactNode ): boolean => {
|
|
21
|
+
return (
|
|
22
|
+
React.isValidElement( ctaContent ) &&
|
|
23
|
+
typeof ctaContent.type === "string" &&
|
|
24
|
+
semanticInteractiveElements.includes( ctaContent.type )
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { matchesQuery } from "./matchesQuery";
|
|
2
|
+
|
|
3
|
+
describe( "matchesQuery", () => {
|
|
4
|
+
test( "empty query matches everything", () => {
|
|
5
|
+
expect( matchesQuery({ label: "Anything", value: "x" }, "" )).toBe( true );
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test( "matches a string label case-insensitively", () => {
|
|
9
|
+
expect( matchesQuery({ label: "Chocolate", value: "c" }, "choc" )).toBe( true );
|
|
10
|
+
expect( matchesQuery({ label: "Chocolate", value: "c" }, "vanilla" )).toBe( false );
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test( "falls back to the stringified value when label is not a string", () => {
|
|
14
|
+
expect( matchesQuery({ label: <span>Icon</span>, value: "banana" }, "ban" )).toBe( true );
|
|
15
|
+
expect( matchesQuery({ label: <span>Icon</span>, value: "banana" }, "icon" )).toBe( false );
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test( "matches searchValue when provided", () => {
|
|
19
|
+
expect( matchesQuery({ label: <span>Icon</span>, value: "u1", searchValue: "Manage Users" }, "users" )).toBe( true );
|
|
20
|
+
expect( matchesQuery({ label: <span>Icon</span>, value: "u1", searchValue: "Manage Users" }, "sync" )).toBe( false );
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test( "searchValue takes precedence over label and value", () => {
|
|
24
|
+
// Query matches the label but not searchValue -> no match (searchValue wins).
|
|
25
|
+
expect( matchesQuery({ label: "Chocolate", value: "choc", searchValue: "Dessert" }, "choc" )).toBe( false );
|
|
26
|
+
expect( matchesQuery({ label: "Chocolate", value: "choc", searchValue: "Dessert" }, "dess" )).toBe( true );
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test( "an empty-string searchValue is ignored (falls back to label/value)", () => {
|
|
30
|
+
expect( matchesQuery({ label: "Chocolate", value: "choc", searchValue: "" }, "choc" )).toBe( true );
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Case-insensitive substring match used for the client-side search in TransferList,
|
|
5
|
+
* MultiSelectTransfer and Select. Match precedence: an explicit `searchValue` first (the way to
|
|
6
|
+
* make an item with a ReactNode `label` searchable by its visible text), then a string `label`,
|
|
7
|
+
* then the stringified `value`. An empty query matches everything. Kept internal (not re-exported
|
|
8
|
+
* from the package index).
|
|
9
|
+
*/
|
|
10
|
+
export function matchesQuery(
|
|
11
|
+
item: { label: ReactNode; value: unknown; searchValue?: string },
|
|
12
|
+
query: string
|
|
13
|
+
): boolean {
|
|
14
|
+
if ( !query ) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const needle = query.toLowerCase();
|
|
18
|
+
if ( typeof item.searchValue === "string" && item.searchValue.length > 0 ) {
|
|
19
|
+
return item.searchValue.toLowerCase().includes( needle );
|
|
20
|
+
}
|
|
21
|
+
const labelMatch = typeof item.label === "string" && item.label.toLowerCase().includes( needle );
|
|
22
|
+
return labelMatch || String( item.value ).toLowerCase().includes( needle );
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudwick/astral-ui-cli",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "CLI for installing Astral UI components in any codebase",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=18.0.0"
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|