@cajoa/core 0.12.0 → 0.12.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 CHANGED
@@ -294,11 +294,21 @@ function h(tag, props, ...children) {
294
294
  if (onRef) untrack(() => onRef(el));
295
295
  return el;
296
296
  }
297
+ function materialize(value) {
298
+ if (typeof value !== "function") return value;
299
+ const holder = getRenderer().createFragment();
300
+ appendChildren(holder, [value]);
301
+ return holder;
302
+ }
297
303
  function toNodes(value) {
298
304
  const r = getRenderer();
299
305
  const out = [];
300
306
  for (const v of [value].flat(Infinity)) {
301
307
  if (v == null || typeof v === "boolean") continue;
308
+ if (typeof v === "function") {
309
+ out.push(materialize(v));
310
+ continue;
311
+ }
302
312
  out.push(r.isNode(v) ? v : r.createText(String(v)));
303
313
  }
304
314
  return out;
@@ -400,11 +410,7 @@ function For(props) {
400
410
 
401
411
  // src/components/error-boundary.ts
402
412
  function resolve2(value) {
403
- let current2 = value;
404
- while (typeof current2 === "function") {
405
- current2 = current2();
406
- }
407
- return current2;
413
+ return typeof value === "function" ? value() : value;
408
414
  }
409
415
  function ErrorBoundary(props) {
410
416
  const [version, setVersion] = createSignal(0);
@@ -434,7 +440,7 @@ function ErrorBoundary(props) {
434
440
  let early = null;
435
441
  const content = untrack(
436
442
  () => catchError(
437
- () => resolve2(props.children ?? null),
443
+ () => materialize(resolve2(props.children ?? null)),
438
444
  (error) => {
439
445
  if (creating) early = { error };
440
446
  else fail(error);
package/dist/index.d.cts CHANGED
@@ -55,7 +55,7 @@ declare function ErrorBoundary(props: {
55
55
  fallback: Child | ((error: unknown, reset: () => void) => Child);
56
56
  children?: Lazy<Child>;
57
57
  onError?: (error: unknown) => void;
58
- }): () => Child;
58
+ }): () => unknown;
59
59
 
60
60
  declare function jsx(type: any, props: Record<string, any> | null): any;
61
61
  declare const jsxs: typeof jsx;
package/dist/index.d.ts CHANGED
@@ -55,7 +55,7 @@ declare function ErrorBoundary(props: {
55
55
  fallback: Child | ((error: unknown, reset: () => void) => Child);
56
56
  children?: Lazy<Child>;
57
57
  onError?: (error: unknown) => void;
58
- }): () => Child;
58
+ }): () => unknown;
59
59
 
60
60
  declare function jsx(type: any, props: Record<string, any> | null): any;
61
61
  declare const jsxs: typeof jsx;
package/dist/index.js CHANGED
@@ -246,11 +246,21 @@ function h(tag, props, ...children) {
246
246
  if (onRef) untrack(() => onRef(el));
247
247
  return el;
248
248
  }
249
+ function materialize(value) {
250
+ if (typeof value !== "function") return value;
251
+ const holder = getRenderer().createFragment();
252
+ appendChildren(holder, [value]);
253
+ return holder;
254
+ }
249
255
  function toNodes(value) {
250
256
  const r = getRenderer();
251
257
  const out = [];
252
258
  for (const v of [value].flat(Infinity)) {
253
259
  if (v == null || typeof v === "boolean") continue;
260
+ if (typeof v === "function") {
261
+ out.push(materialize(v));
262
+ continue;
263
+ }
254
264
  out.push(r.isNode(v) ? v : r.createText(String(v)));
255
265
  }
256
266
  return out;
@@ -352,11 +362,7 @@ function For(props) {
352
362
 
353
363
  // src/components/error-boundary.ts
354
364
  function resolve2(value) {
355
- let current2 = value;
356
- while (typeof current2 === "function") {
357
- current2 = current2();
358
- }
359
- return current2;
365
+ return typeof value === "function" ? value() : value;
360
366
  }
361
367
  function ErrorBoundary(props) {
362
368
  const [version, setVersion] = createSignal(0);
@@ -386,7 +392,7 @@ function ErrorBoundary(props) {
386
392
  let early = null;
387
393
  const content = untrack(
388
394
  () => catchError(
389
- () => resolve2(props.children ?? null),
395
+ () => materialize(resolve2(props.children ?? null)),
390
396
  (error) => {
391
397
  if (creating) early = { error };
392
398
  else fail(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cajoa/core",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Cajoa core: signals, JSX runtime and the renderer interface.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",