react-solidlike 2.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/dist/For.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { type Key, type ReactNode } from "react";
2
+ export interface ForProps<T> {
3
+ /** Array to iterate over | 要遍历的数组 */
4
+ each: T[] | readonly T[] | null | undefined;
5
+ /** Render function for each element | 渲染每个元素的函数 */
6
+ children: (item: T, index: number) => ReactNode;
7
+ /** Function to extract key from element, defaults to index | 从元素中提取 key 的函数,默认使用索引 */
8
+ keyExtractor?: (item: T, index: number) => Key;
9
+ /** Fallback content when array is empty | 数组为空时渲染的备选内容 */
10
+ fallback?: ReactNode;
11
+ }
12
+ /**
13
+ * List rendering component, replaces array.map() in JSX
14
+ *
15
+ * 列表渲染组件,用于替代 JSX 中的 array.map()
16
+ *
17
+ * @example
18
+ * // Basic usage | 基础用法
19
+ * <For each={items}>
20
+ * {(item) => <ListItem {...item} />}
21
+ * </For>
22
+ *
23
+ * @example
24
+ * // With keyExtractor | 带 keyExtractor
25
+ * <For each={users} keyExtractor={(user) => user.id}>
26
+ * {(user) => <UserCard user={user} />}
27
+ * </For>
28
+ *
29
+ * @example
30
+ * // With fallback | 带 fallback
31
+ * <For each={items} fallback={<EmptyState />}>
32
+ * {(item, index) => <ListItem key={item.id} item={item} index={index} />}
33
+ * </For>
34
+ */
35
+ export declare function For<T>({ each, children, keyExtractor, fallback }: ForProps<T>): ReactNode;
36
+ //# sourceMappingURL=For.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"For.d.ts","sourceRoot":"","sources":["../src/For.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,GAAG,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE3D,MAAM,WAAW,QAAQ,CAAC,CAAC;IACvB,qCAAqC;IACrC,IAAI,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,mDAAmD;IACnD,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;IAChD,sFAAsF;IACtF,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;IAC/C,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAe,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAShG"}
package/dist/If.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { ReactNode } from "react";
2
+ export interface IfProps<T> {
3
+ /** 条件表达式,为真时渲染 children */
4
+ condition: T;
5
+ /** 条件为真时渲染的内容 */
6
+ children: ReactNode | ((value: NonNullable<T>) => ReactNode);
7
+ /** 条件为假时渲染的备选内容 */
8
+ fallback?: ReactNode;
9
+ }
10
+ /**
11
+ * 条件渲染组件,用于替代 JSX 中的三元表达式
12
+ *
13
+ * @example
14
+ * // 基础用法
15
+ * <If condition={isLoggedIn}>
16
+ * <UserProfile />
17
+ * </If>
18
+ *
19
+ * @example
20
+ * // 带 fallback
21
+ * <If condition={isLoggedIn} fallback={<LoginButton />}>
22
+ * <UserProfile />
23
+ * </If>
24
+ *
25
+ * @example
26
+ * // 使用 render props 获取类型安全的值
27
+ * <If condition={user}>
28
+ * {(user) => <UserProfile name={user.name} />}
29
+ * </If>
30
+ */
31
+ export declare function If<T>({ condition, children, fallback }: IfProps<T>): ReactNode;
32
+ //# sourceMappingURL=If.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"If.d.ts","sourceRoot":"","sources":["../src/If.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,OAAO,CAAC,CAAC;IACtB,2BAA2B;IAC3B,SAAS,EAAE,CAAC,CAAC;IACb,iBAAiB;IACjB,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAC7D,mBAAmB;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAe,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAUrF"}
@@ -0,0 +1,61 @@
1
+ import type { ReactNode } from "react";
2
+ /** Query result object type definition | 查询结果对象的类型定义 */
3
+ export interface QueryResult<T> {
4
+ /** Data returned by query | 查询返回的数据 */
5
+ data?: T;
6
+ /** Whether loading is in progress | 是否正在加载中 */
7
+ isPending?: boolean;
8
+ /** Whether an error occurred | 是否发生错误 */
9
+ isError?: boolean;
10
+ /** Whether data is empty (optional, for custom empty logic) | 数据是否为空(可选,用于自定义空判断逻辑) */
11
+ isEmpty?: boolean;
12
+ }
13
+ export interface QueryBoundaryProps<T> {
14
+ /** Query result object, usually from @tanstack/react-query's useQuery | 查询结果对象,通常来自 @tanstack/react-query 的 useQuery */
15
+ query: QueryResult<T> | null | undefined;
16
+ /** Content to show while loading | 加载中时显示的内容 */
17
+ loading?: ReactNode;
18
+ /** Content to show when error occurs | 发生错误时显示的内容 */
19
+ error?: ReactNode;
20
+ /** Content to show when data is empty | 数据为空时显示的内容 */
21
+ empty?: ReactNode;
22
+ /** Content to render on success, supports render props | 成功时渲染的内容,支持 render props 模式 */
23
+ children: ReactNode | ((data: T) => ReactNode);
24
+ /** Custom empty data check function, defaults to checking null/undefined or empty array | 自定义空数据判断函数,默认检查 data 是否为 null/undefined 或空数组 */
25
+ isEmptyFn?: (data: T | undefined) => boolean;
26
+ }
27
+ /**
28
+ * Query boundary component, handles various async query states
29
+ *
30
+ * 查询边界组件,用于处理异步查询的各种状态
31
+ *
32
+ * @example
33
+ * // Basic usage - with @tanstack/react-query | 基础用法 - 配合 @tanstack/react-query
34
+ * const query = useQuery({ queryKey: ['users'], queryFn: fetchUsers })
35
+ *
36
+ * <QueryBoundary
37
+ * query={query}
38
+ * loading={<Spinner />}
39
+ * error={<ErrorMessage />}
40
+ * empty={<NoData />}
41
+ * >
42
+ * {(users) => <UserList users={users} />}
43
+ * </QueryBoundary>
44
+ *
45
+ * @example
46
+ * // Static children usage | 静态 children 用法
47
+ * <QueryBoundary query={query} loading={<Spinner />}>
48
+ * <DataDisplay />
49
+ * </QueryBoundary>
50
+ *
51
+ * @example
52
+ * // Custom empty check logic | 自定义空判断逻辑
53
+ * <QueryBoundary
54
+ * query={query}
55
+ * isEmptyFn={(data) => !data?.items?.length}
56
+ * >
57
+ * {(data) => <ItemList items={data.items} />}
58
+ * </QueryBoundary>
59
+ */
60
+ export declare function QueryBoundary<T>({ query, loading, error, empty, children, isEmptyFn, }: QueryBoundaryProps<T>): ReactNode;
61
+ //# sourceMappingURL=QueryBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryBoundary.d.ts","sourceRoot":"","sources":["../src/QueryBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,wDAAwD;AACxD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC1B,uCAAuC;IACvC,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACjC,wHAAwH;IACxH,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,gDAAgD;IAChD,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,qDAAqD;IACrD,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,sDAAsD;IACtD,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,wFAAwF;IACxF,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,SAAS,CAAC,CAAC;IAC/C,0IAA0I;IAC1I,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,SAAS,KAAK,OAAO,CAAC;CAChD;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAC7B,KAAK,EACL,OAAc,EACd,KAAY,EACZ,KAAY,EACZ,QAAQ,EACR,SAA0B,GAC7B,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,SAAS,CA8BnC"}
@@ -0,0 +1,32 @@
1
+ import { type ReactNode } from "react";
2
+ export interface RepeatProps {
3
+ /** Number of times to repeat | 重复次数 */
4
+ times: number;
5
+ /** Render function, receives current index (starting from 0) | 渲染函数,接收当前索引(从 0 开始) */
6
+ children: (index: number) => ReactNode;
7
+ }
8
+ /**
9
+ * Repeat rendering component, replaces Array.from({ length: n }).map()
10
+ *
11
+ * 重复渲染组件,用于替代 Array.from({ length: n }).map()
12
+ *
13
+ * @example
14
+ * // Basic usage - render 5 stars | 基础用法 - 渲染 5 颗星
15
+ * <Repeat times={5}>
16
+ * {(i) => <Star key={i} />}
17
+ * </Repeat>
18
+ *
19
+ * @example
20
+ * // Render list with index | 渲染带索引的列表
21
+ * <Repeat times={3}>
22
+ * {(i) => <div key={i}>Item {i + 1}</div>}
23
+ * </Repeat>
24
+ *
25
+ * @example
26
+ * // Dynamic count | 动态次数
27
+ * <Repeat times={rating}>
28
+ * {(i) => <FilledStar key={i} />}
29
+ * </Repeat>
30
+ */
31
+ export declare function Repeat({ times, children }: RepeatProps): ReactNode;
32
+ //# sourceMappingURL=Repeat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Repeat.d.ts","sourceRoot":"","sources":["../src/Repeat.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjD,MAAM,WAAW,WAAW;IACxB,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,sFAAsF;IACtF,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,WAAW,GAAG,SAAS,CAWlE"}
package/dist/Show.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { ReactNode } from "react";
2
+ export interface ShowProps<T> {
3
+ /** Condition expression, renders children when truthy | 条件表达式,为真时渲染 children */
4
+ when: T;
5
+ /** Content to render when condition is truthy | 条件为真时渲染的内容 */
6
+ children: ReactNode | ((value: NonNullable<T>) => ReactNode);
7
+ /** Fallback content when condition is falsy | 条件为假时渲染的备选内容 */
8
+ fallback?: ReactNode;
9
+ }
10
+ /**
11
+ * Conditional rendering component, replaces ternary expressions in JSX
12
+ *
13
+ * 条件渲染组件,用于替代 JSX 中的三元表达式
14
+ *
15
+ * @example
16
+ * // Basic usage | 基础用法
17
+ * <Show when={isLoggedIn}>
18
+ * <UserProfile />
19
+ * </Show>
20
+ *
21
+ * @example
22
+ * // With fallback | 带 fallback
23
+ * <Show when={isLoggedIn} fallback={<LoginButton />}>
24
+ * <UserProfile />
25
+ * </Show>
26
+ *
27
+ * @example
28
+ * // Using render props for type-safe value access | 使用 render props 获取类型安全的值
29
+ * <Show when={user}>
30
+ * {(user) => <UserProfile name={user.name} />}
31
+ * </Show>
32
+ */
33
+ export declare function Show<T>({ when, children, fallback }: ShowProps<T>): ReactNode;
34
+ //# sourceMappingURL=Show.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Show.d.ts","sourceRoot":"","sources":["../src/Show.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,SAAS,CAAC,CAAC;IACxB,gFAAgF;IAChF,IAAI,EAAE,CAAC,CAAC;IACR,8DAA8D;IAC9D,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAC7D,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAe,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAUpF"}
@@ -0,0 +1,85 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ export interface MatchProps<T> {
3
+ /** Condition expression | 条件表达式 */
4
+ when: T;
5
+ /** Content to render when condition is truthy | 条件为真时渲染的内容 */
6
+ children: ReactNode | ((value: NonNullable<T>) => ReactNode);
7
+ }
8
+ export interface DefaultProps {
9
+ /** Content to render when no Match matches | 所有 Match 都不匹配时渲染的内容 */
10
+ children: ReactNode;
11
+ }
12
+ export interface SwitchProps {
13
+ /** Match and Default components | Match 和 Default 组件 */
14
+ children: ReactNode;
15
+ /** Fallback content when no conditions match (can also use Default component) | 所有条件都不匹配时的备选内容(也可用 Default 组件) */
16
+ fallback?: ReactNode;
17
+ }
18
+ /**
19
+ * Condition match component, used with Switch
20
+ *
21
+ * 条件匹配组件,配合 Switch 使用
22
+ *
23
+ * Note: Match component cannot be used alone, must be a child of Switch
24
+ *
25
+ * 注意:Match 组件不能单独使用,必须作为 Switch 的子组件
26
+ */
27
+ export declare function Match<T>(_props: MatchProps<T>): ReactElement | null;
28
+ export declare namespace Match {
29
+ var __isMatch: boolean;
30
+ }
31
+ /**
32
+ * Default match component, used with Switch
33
+ *
34
+ * 默认匹配组件,配合 Switch 使用
35
+ *
36
+ * Renders when no Match matches
37
+ *
38
+ * 当所有 Match 都不匹配时渲染
39
+ */
40
+ export declare function Default(_props: DefaultProps): ReactElement | null;
41
+ export declare namespace Default {
42
+ var __isDefault: boolean;
43
+ }
44
+ /**
45
+ * Multi-condition branch component, replaces nested if-else if-else
46
+ *
47
+ * 多条件分支组件,用于替代嵌套的 if-else if-else
48
+ *
49
+ * @example
50
+ * // Basic usage | 基础用法
51
+ * <Switch>
52
+ * <Match when={status === 'loading'}>
53
+ * <Loading />
54
+ * </Match>
55
+ * <Match when={status === 'error'}>
56
+ * <Error />
57
+ * </Match>
58
+ * <Match when={status === 'success'}>
59
+ * <Success />
60
+ * </Match>
61
+ * <Default>
62
+ * <Unknown />
63
+ * </Default>
64
+ * </Switch>
65
+ *
66
+ * @example
67
+ * // Using render props for type-safe value access | 使用 render props 获取类型安全的值
68
+ * <Switch>
69
+ * <Match when={user}>
70
+ * {(user) => <UserProfile name={user.name} />}
71
+ * </Match>
72
+ * <Match when={guest}>
73
+ * {(guest) => <GuestProfile id={guest.id} />}
74
+ * </Match>
75
+ * </Switch>
76
+ *
77
+ * @example
78
+ * // Using fallback prop | 使用 fallback 属性
79
+ * <Switch fallback={<NotFound />}>
80
+ * <Match when={page === 'home'}><Home /></Match>
81
+ * <Match when={page === 'about'}><About /></Match>
82
+ * </Switch>
83
+ */
84
+ export declare function Switch({ children, fallback }: SwitchProps): ReactNode;
85
+ //# sourceMappingURL=Switch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Switch.d.ts","sourceRoot":"","sources":["../src/Switch.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEpE,MAAM,WAAW,UAAU,CAAC,CAAC;IACzB,mCAAmC;IACnC,IAAI,EAAE,CAAC,CAAC;IACR,8DAA8D;IAC9D,QAAQ,EAAE,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,YAAY;IACzB,oEAAoE;IACpE,QAAQ,EAAE,SAAS,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IACxB,wDAAwD;IACxD,QAAQ,EAAE,SAAS,CAAC;IACpB,kHAAkH;IAClH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAInE;yBAJe,KAAK;;;AAMrB;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,CAIjE;yBAJe,OAAO;;;AAwCvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAe,EAAE,EAAE,WAAW,GAAG,SAAS,CA4B5E"}
package/dist/index.cjs ADDED
@@ -0,0 +1,241 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __moduleCache = /* @__PURE__ */ new WeakMap;
6
+ var __toCommonJS = (from) => {
7
+ var entry = __moduleCache.get(from), desc;
8
+ if (entry)
9
+ return entry;
10
+ entry = __defProp({}, "__esModule", { value: true });
11
+ if (from && typeof from === "object" || typeof from === "function")
12
+ __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ }));
16
+ __moduleCache.set(from, entry);
17
+ return entry;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+
29
+ // src/index.ts
30
+ var exports_src = {};
31
+ __export(exports_src, {
32
+ Switch: () => Switch,
33
+ Show: () => Show,
34
+ Repeat: () => Repeat,
35
+ QueryBoundary: () => QueryBoundary,
36
+ Match: () => Match,
37
+ For: () => For,
38
+ ErrorBoundary: () => ErrorBoundary,
39
+ Dynamic: () => Dynamic,
40
+ Default: () => Default,
41
+ Await: () => Await
42
+ });
43
+ module.exports = __toCommonJS(exports_src);
44
+
45
+ // src/Await.tsx
46
+ var import_react = require("react");
47
+ function Await({ promise, loading = null, error = null, children }) {
48
+ const [state, setState] = import_react.useState(() => {
49
+ if (!(promise instanceof Promise)) {
50
+ return { status: "fulfilled", value: promise };
51
+ }
52
+ return { status: "pending" };
53
+ });
54
+ import_react.useEffect(() => {
55
+ if (!(promise instanceof Promise)) {
56
+ setState({ status: "fulfilled", value: promise });
57
+ return;
58
+ }
59
+ setState({ status: "pending" });
60
+ let cancelled = false;
61
+ promise.then((value) => {
62
+ if (!cancelled) {
63
+ setState({ status: "fulfilled", value });
64
+ }
65
+ }).catch((err) => {
66
+ if (!cancelled) {
67
+ setState({ status: "rejected", error: err });
68
+ }
69
+ });
70
+ return () => {
71
+ cancelled = true;
72
+ };
73
+ }, [promise]);
74
+ if (state.status === "pending") {
75
+ return loading;
76
+ }
77
+ if (state.status === "rejected") {
78
+ if (typeof error === "function") {
79
+ return error(state.error);
80
+ }
81
+ return error;
82
+ }
83
+ if (typeof children === "function") {
84
+ return children(state.value);
85
+ }
86
+ return children;
87
+ }
88
+ // src/Dynamic.tsx
89
+ var import_react2 = require("react");
90
+ function Dynamic({ component, fallback = null, ...props }) {
91
+ if (!component) {
92
+ return fallback;
93
+ }
94
+ return import_react2.createElement(component, props);
95
+ }
96
+ // src/ErrorBoundary.tsx
97
+ var import_react3 = require("react");
98
+
99
+ class ErrorBoundary extends import_react3.Component {
100
+ constructor(props) {
101
+ super(props);
102
+ this.state = { error: null };
103
+ }
104
+ static getDerivedStateFromError(error) {
105
+ return { error };
106
+ }
107
+ componentDidCatch(error, errorInfo) {
108
+ this.props.onError?.(error, errorInfo);
109
+ }
110
+ componentDidUpdate(prevProps) {
111
+ if (this.state.error && prevProps.resetKey !== this.props.resetKey) {
112
+ this.reset();
113
+ }
114
+ }
115
+ reset = () => {
116
+ this.setState({ error: null });
117
+ };
118
+ render() {
119
+ const { error } = this.state;
120
+ const { fallback, children } = this.props;
121
+ if (error) {
122
+ if (typeof fallback === "function") {
123
+ return fallback(error, this.reset);
124
+ }
125
+ return fallback;
126
+ }
127
+ return children;
128
+ }
129
+ }
130
+ // src/For.tsx
131
+ var import_react4 = require("react");
132
+ var jsx_dev_runtime = require("react/jsx-dev-runtime");
133
+ function For({ each, children, keyExtractor, fallback = null }) {
134
+ if (!each || each.length === 0) {
135
+ return fallback;
136
+ }
137
+ return each.map((item, index) => {
138
+ const key = keyExtractor ? keyExtractor(item, index) : index;
139
+ return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(import_react4.Fragment, {
140
+ children: children(item, index)
141
+ }, key, false, undefined, this);
142
+ });
143
+ }
144
+ // src/QueryBoundary.tsx
145
+ function defaultIsEmpty(data) {
146
+ if (data == null)
147
+ return true;
148
+ if (Array.isArray(data))
149
+ return data.length === 0;
150
+ if (typeof data === "object")
151
+ return Object.keys(data).length === 0;
152
+ return false;
153
+ }
154
+ function QueryBoundary({
155
+ query,
156
+ loading = null,
157
+ error = null,
158
+ empty = null,
159
+ children,
160
+ isEmptyFn = defaultIsEmpty
161
+ }) {
162
+ if (!query) {
163
+ return null;
164
+ }
165
+ const { data, isPending, isError, isEmpty: queryIsEmpty } = query;
166
+ if (isPending) {
167
+ return loading;
168
+ }
169
+ if (isError && isEmptyFn(data)) {
170
+ return error;
171
+ }
172
+ const isEmpty = queryIsEmpty ?? isEmptyFn(data);
173
+ if (isEmpty) {
174
+ return empty;
175
+ }
176
+ if (typeof children === "function") {
177
+ return children(data);
178
+ }
179
+ return children;
180
+ }
181
+ // src/Repeat.tsx
182
+ var import_react5 = require("react");
183
+ var jsx_dev_runtime2 = require("react/jsx-dev-runtime");
184
+ function Repeat({ times, children }) {
185
+ if (times <= 0) {
186
+ return null;
187
+ }
188
+ const elements = [];
189
+ for (let i = 0;i < times; i++) {
190
+ elements.push(/* @__PURE__ */ jsx_dev_runtime2.jsxDEV(import_react5.Fragment, {
191
+ children: children(i)
192
+ }, i, false, undefined, this));
193
+ }
194
+ return elements;
195
+ }
196
+ // src/Show.tsx
197
+ function Show({ when, children, fallback = null }) {
198
+ if (!when) {
199
+ return fallback;
200
+ }
201
+ if (typeof children === "function") {
202
+ return children(when);
203
+ }
204
+ return children;
205
+ }
206
+ // src/Switch.tsx
207
+ var import_react6 = require("react");
208
+ function Match(_props) {
209
+ return null;
210
+ }
211
+ function Default(_props) {
212
+ return null;
213
+ }
214
+ Match.__isMatch = true;
215
+ Default.__isDefault = true;
216
+ function isMatchElement(child) {
217
+ return child !== null && typeof child === "object" && "type" in child && typeof child.type === "function" && "__isMatch" in child.type && child.type.__isMatch === true;
218
+ }
219
+ function isDefaultElement(child) {
220
+ return child !== null && typeof child === "object" && "type" in child && typeof child.type === "function" && "__isDefault" in child.type && child.type.__isDefault === true;
221
+ }
222
+ function Switch({ children, fallback = null }) {
223
+ const childArray = import_react6.Children.toArray(children);
224
+ let defaultContent = fallback;
225
+ for (const child of childArray) {
226
+ if (isDefaultElement(child)) {
227
+ defaultContent = child.props.children;
228
+ continue;
229
+ }
230
+ if (isMatchElement(child)) {
231
+ const { when, children: matchChildren } = child.props;
232
+ if (when) {
233
+ if (typeof matchChildren === "function") {
234
+ return matchChildren(when);
235
+ }
236
+ return matchChildren;
237
+ }
238
+ }
239
+ }
240
+ return defaultContent;
241
+ }
@@ -0,0 +1,9 @@
1
+ export { Await, type AwaitProps } from "./Await";
2
+ export { Dynamic, type DynamicProps } from "./Dynamic";
3
+ export { ErrorBoundary, type ErrorBoundaryProps } from "./ErrorBoundary";
4
+ export { For, type ForProps } from "./For";
5
+ export { QueryBoundary, type QueryBoundaryProps, type QueryResult } from "./QueryBoundary";
6
+ export { Repeat, type RepeatProps } from "./Repeat";
7
+ export { Show, type ShowProps } from "./Show";
8
+ export { Default, type DefaultProps, Match, type MatchProps, Switch, type SwitchProps } from "./Switch";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC"}