nuclo 0.3.26 → 0.3.27

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.
Files changed (2) hide show
  1. package/README.md +83 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -507,6 +507,89 @@ shows them again.
507
507
  closes, or its `list()` row goes, the content leaves the region too — a closed
508
508
  layer does not stay on screen, and re-opening it adds one copy, not two.
509
509
 
510
+ **Examples.** A dialog opened from deep in the tree — the overlay region sits
511
+ at the root, and closing the `when()` removes the dialog:
512
+
513
+ ```ts
514
+ let confirming = false
515
+
516
+ const App = () => div(Page(), div({ className: "overlay" }, region({ id: "overlay" })))
517
+
518
+ // deep inside Page()
519
+ const DeleteButton = () =>
520
+ div(
521
+ button("Delete", { onClick: () => { confirming = true; update() } }),
522
+ when(() => confirming,
523
+ into("overlay", dialog({ open: true },
524
+ p("Delete this item?"),
525
+ button("Cancel", { onClick: () => { confirming = false; update() } }),
526
+ )),
527
+ ),
528
+ )
529
+ ```
530
+
531
+ Toasts from `list()` rows — each row is a view, a stacked region shows them in
532
+ order, and removing the item removes its toast:
533
+
534
+ ```ts
535
+ const toasts: { text: string }[] = []
536
+
537
+ div(
538
+ div({ className: "toasts" }, region({ id: "toasts", type: "stack" })),
539
+ list(() => toasts, (toast) =>
540
+ into("toasts", div(toast.text, button("×", { onClick: () => {
541
+ toasts.splice(toasts.indexOf(toast), 1); update()
542
+ } }))),
543
+ ),
544
+ )
545
+ ```
546
+
547
+ A heading owned by the layout and named by the page — with `"latest"` the
548
+ newest view wins, and a page without an `into("title", …)` leaves the `empty`
549
+ text:
550
+
551
+ ```ts
552
+ const Layout = () =>
553
+ div(
554
+ h1(region({ id: "title", empty: "My app" })),
555
+ when(() => page === "home", Home()).else(Settings()),
556
+ )
557
+
558
+ const Settings = () => div(into("title", "Settings"), form(/* … */))
559
+ ```
560
+
561
+ Dynamic values inside a view — `into()` content is ordinary Nuclo content, so
562
+ its functions refresh on `update()` wherever the region is:
563
+
564
+ ```ts
565
+ header(region({ id: "status" }))
566
+ // …
567
+ into("status", () => `${selected.size} selected`)
568
+ ```
569
+
570
+ A region that comes and goes — the view is written once; it waits while the
571
+ user is signed out, shows when the region is built, and waits again when it
572
+ goes:
573
+
574
+ ```ts
575
+ div(
576
+ when(() => user !== null, main(region({ id: "main" }))).else(LoginForm()),
577
+ into("main", Dashboard()),
578
+ )
579
+ ```
580
+
581
+ A view with its own region — the editor brings a `tabs` region with it, each
582
+ tab fills it, and the region leaves with the editor:
583
+
584
+ ```ts
585
+ const Editor = () =>
586
+ into("main",
587
+ div(nav(/* tab buttons */), section(region({ id: "tabs" }))),
588
+ when(() => tab === "code", into("tabs", textarea()))
589
+ .else(into("tabs", iframe({ src: "/preview" }))),
590
+ )
591
+ ```
592
+
510
593
  Regions survive SSR — each view claims the server's nodes on hydration rather
511
594
  than rebuilding them.
512
595
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuclo",
3
3
  "private": false,
4
- "version": "0.3.26",
4
+ "version": "0.3.27",
5
5
  "description": "Lightweight, type-safe DOM library with plain mutable state and explicit updates — global tag builders, SSR, hydration, and typed CSS, no virtual DOM, no compiler.",
6
6
  "license": "MIT",
7
7
  "author": "Danilo Celestino de Castro (https://github.com/dan2dev)",