@cajoa/core 0.9.0 → 0.10.1
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 +6 -3
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -283,9 +283,12 @@ function render(component, container) {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
// src/components/show.ts
|
|
286
|
+
function resolve(value) {
|
|
287
|
+
return typeof value === "function" ? value() : value;
|
|
288
|
+
}
|
|
286
289
|
function Show(props) {
|
|
287
|
-
const visible = createMemo(() => !!props.when
|
|
288
|
-
return () => visible() ? untrack(() => props.children
|
|
290
|
+
const visible = createMemo(() => !!resolve(props.when));
|
|
291
|
+
return () => visible() ? untrack(() => resolve(props.children ?? null)) : untrack(() => resolve(props.fallback ?? null));
|
|
289
292
|
}
|
|
290
293
|
|
|
291
294
|
// src/components/for.ts
|
|
@@ -296,7 +299,7 @@ function For(props) {
|
|
|
296
299
|
cache.clear();
|
|
297
300
|
});
|
|
298
301
|
return () => {
|
|
299
|
-
const items = props.each();
|
|
302
|
+
const items = typeof props.each === "function" ? props.each() : props.each;
|
|
300
303
|
const next = /* @__PURE__ */ new Map();
|
|
301
304
|
const nodes = [];
|
|
302
305
|
items.forEach((item, i) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -36,14 +36,15 @@ declare function h(tag: string, props: Record<string, any> | null, ...children:
|
|
|
36
36
|
|
|
37
37
|
declare function render(component: () => HostNode, container: HostNode): () => void;
|
|
38
38
|
|
|
39
|
+
type Lazy<T> = T | (() => T);
|
|
39
40
|
declare function Show<T>(props: {
|
|
40
|
-
when:
|
|
41
|
-
children
|
|
42
|
-
fallback?:
|
|
43
|
-
}): () =>
|
|
41
|
+
when: Lazy<T>;
|
|
42
|
+
children?: Lazy<Child>;
|
|
43
|
+
fallback?: Lazy<Child>;
|
|
44
|
+
}): () => string | number | boolean | object | null;
|
|
44
45
|
|
|
45
46
|
declare function For<T>(props: {
|
|
46
|
-
each: () => T[];
|
|
47
|
+
each: T[] | (() => T[]);
|
|
47
48
|
children: (item: T, index: number) => HostNode;
|
|
48
49
|
key?: (item: T, index: number) => unknown;
|
|
49
50
|
}): () => object[];
|
package/dist/index.d.ts
CHANGED
|
@@ -36,14 +36,15 @@ declare function h(tag: string, props: Record<string, any> | null, ...children:
|
|
|
36
36
|
|
|
37
37
|
declare function render(component: () => HostNode, container: HostNode): () => void;
|
|
38
38
|
|
|
39
|
+
type Lazy<T> = T | (() => T);
|
|
39
40
|
declare function Show<T>(props: {
|
|
40
|
-
when:
|
|
41
|
-
children
|
|
42
|
-
fallback?:
|
|
43
|
-
}): () =>
|
|
41
|
+
when: Lazy<T>;
|
|
42
|
+
children?: Lazy<Child>;
|
|
43
|
+
fallback?: Lazy<Child>;
|
|
44
|
+
}): () => string | number | boolean | object | null;
|
|
44
45
|
|
|
45
46
|
declare function For<T>(props: {
|
|
46
|
-
each: () => T[];
|
|
47
|
+
each: T[] | (() => T[]);
|
|
47
48
|
children: (item: T, index: number) => HostNode;
|
|
48
49
|
key?: (item: T, index: number) => unknown;
|
|
49
50
|
}): () => object[];
|
package/dist/index.js
CHANGED
|
@@ -237,9 +237,12 @@ function render(component, container) {
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
// src/components/show.ts
|
|
240
|
+
function resolve(value) {
|
|
241
|
+
return typeof value === "function" ? value() : value;
|
|
242
|
+
}
|
|
240
243
|
function Show(props) {
|
|
241
|
-
const visible = createMemo(() => !!props.when
|
|
242
|
-
return () => visible() ? untrack(() => props.children
|
|
244
|
+
const visible = createMemo(() => !!resolve(props.when));
|
|
245
|
+
return () => visible() ? untrack(() => resolve(props.children ?? null)) : untrack(() => resolve(props.fallback ?? null));
|
|
243
246
|
}
|
|
244
247
|
|
|
245
248
|
// src/components/for.ts
|
|
@@ -250,7 +253,7 @@ function For(props) {
|
|
|
250
253
|
cache.clear();
|
|
251
254
|
});
|
|
252
255
|
return () => {
|
|
253
|
-
const items = props.each();
|
|
256
|
+
const items = typeof props.each === "function" ? props.each() : props.each;
|
|
254
257
|
const next = /* @__PURE__ */ new Map();
|
|
255
258
|
const nodes = [];
|
|
256
259
|
items.forEach((item, i) => {
|