@cajoa/core 0.19.0 → 0.20.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/index.cjs CHANGED
@@ -930,6 +930,10 @@ function For(props) {
930
930
  if (!next.has(k)) entry.dispose();
931
931
  });
932
932
  cache = next;
933
+ if (nodes2.length === 0 && props.fallback !== void 0) {
934
+ const fallback = props.fallback;
935
+ return untrack(() => typeof fallback === "function" ? fallback() : fallback);
936
+ }
933
937
  return nodes2;
934
938
  };
935
939
  }
package/dist/index.d.cts CHANGED
@@ -76,7 +76,9 @@ declare function For<T>(props: {
76
76
  each: T[] | (() => T[]);
77
77
  children: (item: T, index: number) => HostNode;
78
78
  key?: (item: T, index: number) => unknown;
79
- }): () => object[];
79
+ /** Shown when the list is empty. */
80
+ fallback?: Child | (() => Child);
81
+ }): () => Child;
80
82
 
81
83
  type Lazy$3<T> = T | (() => T);
82
84
  declare function ErrorBoundary(props: {
@@ -135,12 +137,31 @@ declare function getRenderer(): Renderer;
135
137
  declare function currentRenderer(): Renderer | null;
136
138
  declare function isServer(): boolean;
137
139
 
140
+ interface HeadMeta {
141
+ name?: string;
142
+ property?: string;
143
+ content: string;
144
+ }
145
+ /** The page title and meta tags that <Title> and <Meta> collect while rendering on the server. */
146
+ interface HeadData {
147
+ title?: string;
148
+ meta?: HeadMeta[];
149
+ }
150
+ /** What components can learn about the request that is being rendered on the server. */
138
151
  interface ServerRequest {
152
+ /** The URL of the request (path and query), for example "/users/42?tab=posts". */
139
153
  url: string;
154
+ /** Filled by <Title> and <Meta> while rendering. */
155
+ head: HeadData;
156
+ /** <Navigate> asks the server to redirect. */
140
157
  redirect(to: string, status: number): void;
158
+ /**
159
+ * Tell renderToStringAsync that there is async work (for example a resource) to wait for.
160
+ * Returns the function to call when the work is done.
161
+ */
141
162
  track(): () => void;
142
163
  }
143
164
  declare const ServerContext: Context<ServerRequest | null>;
144
165
 
145
166
  export { Dynamic, ErrorBoundary, For, Fragment, Match, Portal, ServerContext, Show, Suspense, Switch, batch, catchError, createContext, createEffect, createMemo, createResource, createRoot, createSelector, createSignal, createStore, currentRenderer, getRenderer, h, isServer, jsx, jsxDEV, jsxs, lazy, onCleanup, onMount, provide, render, setRenderer, untrack, unwrap, useContext };
146
- export type { Child, Context, HostNode, MatchDef, Renderer, Resource, ResourceActions, ServerRequest, SetStoreFunction };
167
+ export type { Child, Context, HeadData, HeadMeta, HostNode, MatchDef, Renderer, Resource, ResourceActions, ServerRequest, SetStoreFunction };
package/dist/index.d.ts CHANGED
@@ -76,7 +76,9 @@ declare function For<T>(props: {
76
76
  each: T[] | (() => T[]);
77
77
  children: (item: T, index: number) => HostNode;
78
78
  key?: (item: T, index: number) => unknown;
79
- }): () => object[];
79
+ /** Shown when the list is empty. */
80
+ fallback?: Child | (() => Child);
81
+ }): () => Child;
80
82
 
81
83
  type Lazy$3<T> = T | (() => T);
82
84
  declare function ErrorBoundary(props: {
@@ -135,12 +137,31 @@ declare function getRenderer(): Renderer;
135
137
  declare function currentRenderer(): Renderer | null;
136
138
  declare function isServer(): boolean;
137
139
 
140
+ interface HeadMeta {
141
+ name?: string;
142
+ property?: string;
143
+ content: string;
144
+ }
145
+ /** The page title and meta tags that <Title> and <Meta> collect while rendering on the server. */
146
+ interface HeadData {
147
+ title?: string;
148
+ meta?: HeadMeta[];
149
+ }
150
+ /** What components can learn about the request that is being rendered on the server. */
138
151
  interface ServerRequest {
152
+ /** The URL of the request (path and query), for example "/users/42?tab=posts". */
139
153
  url: string;
154
+ /** Filled by <Title> and <Meta> while rendering. */
155
+ head: HeadData;
156
+ /** <Navigate> asks the server to redirect. */
140
157
  redirect(to: string, status: number): void;
158
+ /**
159
+ * Tell renderToStringAsync that there is async work (for example a resource) to wait for.
160
+ * Returns the function to call when the work is done.
161
+ */
141
162
  track(): () => void;
142
163
  }
143
164
  declare const ServerContext: Context<ServerRequest | null>;
144
165
 
145
166
  export { Dynamic, ErrorBoundary, For, Fragment, Match, Portal, ServerContext, Show, Suspense, Switch, batch, catchError, createContext, createEffect, createMemo, createResource, createRoot, createSelector, createSignal, createStore, currentRenderer, getRenderer, h, isServer, jsx, jsxDEV, jsxs, lazy, onCleanup, onMount, provide, render, setRenderer, untrack, unwrap, useContext };
146
- export type { Child, Context, HostNode, MatchDef, Renderer, Resource, ResourceActions, ServerRequest, SetStoreFunction };
167
+ export type { Child, Context, HeadData, HeadMeta, HostNode, MatchDef, Renderer, Resource, ResourceActions, ServerRequest, SetStoreFunction };
package/dist/index.js CHANGED
@@ -869,6 +869,10 @@ function For(props) {
869
869
  if (!next.has(k)) entry.dispose();
870
870
  });
871
871
  cache = next;
872
+ if (nodes2.length === 0 && props.fallback !== void 0) {
873
+ const fallback = props.fallback;
874
+ return untrack(() => typeof fallback === "function" ? fallback() : fallback);
875
+ }
872
876
  return nodes2;
873
877
  };
874
878
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cajoa/core",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Cajoa core: signals, JSX runtime and the renderer interface.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",