react-solidlike 2.5.1 → 2.5.2

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/Await.d.ts CHANGED
@@ -3,7 +3,7 @@ export interface AwaitProps<T> {
3
3
  /** Promise to wait for | 要等待的 Promise */
4
4
  promise: Promise<T> | T;
5
5
  /** Content to show when Promise is pending | Promise pending 时显示的内容 */
6
- loading?: ReactNode;
6
+ loading?: ReactNode | (() => ReactNode);
7
7
  /** Content to show when Promise is rejected | Promise rejected 时显示的内容 */
8
8
  error?: ReactNode | ((error: unknown) => ReactNode);
9
9
  /** Content to render when Promise is fulfilled | Promise fulfilled 时渲染的内容 */
@@ -3,7 +3,7 @@ export interface ClientOnlyProps {
3
3
  /** Content to render only on client side | 仅在客户端渲染的内容 */
4
4
  children: ReactNode | (() => ReactNode);
5
5
  /** Fallback content during SSR | SSR 期间渲染的备选内容 */
6
- fallback?: ReactNode;
6
+ fallback?: ReactNode | (() => ReactNode);
7
7
  }
8
8
  /**
9
9
  * Component that renders children only on the client side (after hydration)
package/dist/Dynamic.d.ts CHANGED
@@ -5,7 +5,7 @@ export type DynamicProps<T extends ElementType> = {
5
5
  /** Component or element type to render | 要渲染的组件或元素类型 */
6
6
  component: T | null | undefined | false;
7
7
  /** Fallback content when component is falsy | 当 component 为 falsy 时渲染的备选内容 */
8
- fallback?: ReactNode;
8
+ fallback?: ReactNode | (() => ReactNode);
9
9
  } & PropsOf<T>;
10
10
  /**
11
11
  * Dynamic component rendering, selects component type based on conditions
@@ -14,11 +14,11 @@ export interface QueryBoundaryProps<T> {
14
14
  /** Query result object, usually from @tanstack/react-query's useQuery | 查询结果对象,通常来自 @tanstack/react-query 的 useQuery */
15
15
  query: QueryResult<T> | null | undefined;
16
16
  /** Content to show while loading | 加载中时显示的内容 */
17
- loading?: ReactNode;
17
+ loading?: ReactNode | (() => ReactNode);
18
18
  /** Content to show when error occurs | 发生错误时显示的内容 */
19
- error?: ReactNode;
19
+ error?: ReactNode | (() => ReactNode);
20
20
  /** Content to show when data is empty | 数据为空时显示的内容 */
21
- empty?: ReactNode;
21
+ empty?: ReactNode | (() => ReactNode);
22
22
  /** Content to render on success, supports render props | 成功时渲染的内容,支持 render props 模式 */
23
23
  children: ReactNode | ((data: T) => ReactNode);
24
24
  /** Custom empty data check function, defaults to checking null/undefined or empty array | 自定义空数据判断函数,默认检查 data 是否为 null/undefined 或空数组 */
package/dist/Show.d.ts CHANGED
@@ -5,7 +5,7 @@ export interface ShowProps<T> {
5
5
  /** Content to render when condition is truthy | 条件为真时渲染的内容 */
6
6
  children: ReactNode | ((value: NonNullable<T>) => ReactNode);
7
7
  /** Fallback content when condition is falsy | 条件为假时渲染的备选内容 */
8
- fallback?: ReactNode;
8
+ fallback?: ReactNode | (() => ReactNode);
9
9
  /** Callback when condition is falsy (called before rendering fallback) | 条件为假时的回调(在渲染 fallback 之前调用) */
10
10
  onFallback?: () => void;
11
11
  }
package/dist/Switch.d.ts CHANGED
@@ -13,7 +13,7 @@ export interface SwitchProps {
13
13
  /** Match and Default components | Match 和 Default 组件 */
14
14
  children: ReactNode;
15
15
  /** Fallback content when no conditions match (can also use Default component) | 所有条件都不匹配时的备选内容(也可用 Default 组件) */
16
- fallback?: ReactNode;
16
+ fallback?: ReactNode | (() => ReactNode);
17
17
  }
18
18
  /**
19
19
  * Condition match component, used with Switch
package/dist/Timeout.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface TimeoutProps {
9
9
  /** Display mode: 'after' = show after delay, 'before' = hide after delay | 显示模式:'after' = 延迟后显示,'before' = 延迟后隐藏 */
10
10
  mode?: TimeoutMode;
11
11
  /** Content to show when hidden (only for 'after' mode) | 隐藏时显示的内容(仅 'after' 模式) */
12
- fallback?: ReactNode;
12
+ fallback?: ReactNode | (() => ReactNode);
13
13
  /** Callback when timeout occurs | 超时发生时的回调 */
14
14
  onTimeout?: () => void;
15
15
  }
package/dist/Visible.d.ts CHANGED
@@ -3,7 +3,7 @@ export interface VisibleProps {
3
3
  /** Content to render when visible | 可见时渲染的内容 */
4
4
  children: ReactNode;
5
5
  /** Fallback content before entering viewport | 进入视口前渲染的备选内容 */
6
- fallback?: ReactNode;
6
+ fallback?: ReactNode | (() => ReactNode);
7
7
  /** Root margin for intersection observer (e.g., "100px") | 交叉观察器的根边距 */
8
8
  rootMargin?: string;
9
9
  /** Visibility threshold (0-1) | 可见性阈值 */
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ function Await({ promise, loading = null, error = null, children }) {
34
34
  cancelled = true;
35
35
  };
36
36
  }, [promise]);
37
- if (state.status === "pending") return loading;
37
+ if (state.status === "pending") return typeof loading === "function" ? loading() : loading;
38
38
  if (state.status === "rejected") {
39
39
  if (typeof error === "function") return error(state.error);
40
40
  return error;
@@ -44,7 +44,7 @@ function Await({ promise, loading = null, error = null, children }) {
44
44
  }
45
45
 
46
46
  function Dynamic({ component, fallback = null, ...props }) {
47
- if (!component) return fallback;
47
+ if (!component) return typeof fallback === "function" ? fallback() : fallback;
48
48
  return createElement(component, props);
49
49
  }
50
50
 
@@ -98,9 +98,9 @@ function defaultIsEmpty(data) {
98
98
  function QueryBoundary({ query, loading = null, error = null, empty = null, children, isEmptyFn = defaultIsEmpty }) {
99
99
  if (!query) return null;
100
100
  const { data, isPending, isError, isEmpty: queryIsEmpty } = query;
101
- if (isPending) return loading;
102
- if (isError && isEmptyFn(data)) return error;
103
- if (queryIsEmpty ?? isEmptyFn(data)) return empty;
101
+ if (isPending) return typeof loading === "function" ? loading() : loading;
102
+ if (isError && isEmptyFn(data)) return typeof error === "function" ? error() : error;
103
+ if (queryIsEmpty ?? isEmptyFn(data)) return typeof empty === "function" ? empty() : empty;
104
104
  if (typeof children === "function") return children(data);
105
105
  return children;
106
106
  }
@@ -117,7 +117,7 @@ function Repeat({ times, children, ...props }) {
117
117
  function Show({ when, children, fallback = null, onFallback }) {
118
118
  if (!when || isEmpty(when)) {
119
119
  onFallback?.();
120
- return fallback;
120
+ return typeof fallback === "function" ? fallback() : fallback;
121
121
  }
122
122
  if (typeof children === "function") return children(when);
123
123
  return children;
@@ -169,7 +169,7 @@ function isDefaultElement(child) {
169
169
 
170
170
  function Switch({ children, fallback = null }) {
171
171
  const childArray = Children.toArray(children);
172
- let defaultContent = fallback;
172
+ let defaultContent = typeof fallback === "function" ? fallback() : fallback;
173
173
  for (const child of childArray) {
174
174
  if (isDefaultElement(child)) {
175
175
  defaultContent = child.props.children;
@@ -195,7 +195,7 @@ function Timeout({ ms, children, mode = "after", fallback = null, onTimeout }) {
195
195
  }, ms);
196
196
  return () => clearTimeout(timer);
197
197
  }, [ms, onTimeout]);
198
- if (mode === "after") return ready ? children : fallback;
198
+ if (mode === "after") return ready ? children : typeof fallback === "function" ? fallback() : fallback;
199
199
  return ready ? children : null;
200
200
  }
201
201
 
@@ -246,7 +246,7 @@ function Visible({ children, fallback = null, rootMargin = "0px", threshold = 0,
246
246
  if (!isSupported) return children;
247
247
  return /* @__PURE__ */ jsx("div", {
248
248
  ref,
249
- children: (once ? hasBeenVisible : isVisible) ? children : fallback
249
+ children: (once ? hasBeenVisible : isVisible) ? children : typeof fallback === "function" ? fallback() : fallback
250
250
  });
251
251
  }
252
252
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-solidlike",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "Declarative React control flow components inspired by Solid.js, replacing ternary expressions and array.map() in JSX",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",