@rhi-zone/rainbow-ui 0.2.0-alpha.1 → 0.2.0-alpha.3

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.
@@ -18,15 +18,27 @@ import type { Optic } from "@rhi-zone/rainbow";
18
18
  import type { AnyEl } from "./html.js";
19
19
  import type { Widget } from "./widget.js";
20
20
  /**
21
- * Maps field names of `T` to optics that convert between `string | null`
22
- * (raw HTML attribute) and `T[K]` (typed signal field).
21
+ * An entry in `AttrSchema<T>`. Either a plain optic (attribute name = prop name)
22
+ * or a named entry `{ name, optic }` where `name` is the HTML attribute name
23
+ * (e.g. `"requires-review"`) and the TypeScript key remains the camelCase prop.
23
24
  *
24
25
  * - `optic.view(raw)` — parse attribute string into `T[K]`;
25
26
  * `undefined` means use `defaults[K]`
26
27
  * - `optic.review(v, _)` — serialise `T[K]` back to a string for reflection
28
+ *
29
+ * @example
30
+ * // Simple: attr name = prop name
31
+ * attrs: { label: attrString, score: attrNumber }
32
+ *
33
+ * // Alias: HTML "requires-review" → TS prop "requiresReview"
34
+ * attrs: { requiresReview: { name: "requires-review", optic: attrBoolean } }
27
35
  */
36
+ export type AttrEntry<V> = Optic<string | null, V> | {
37
+ name: string;
38
+ optic: Optic<string | null, V>;
39
+ };
28
40
  export type AttrSchema<T> = {
29
- [K in keyof T]?: Optic<string | null, T[K]>;
41
+ [K in keyof T]?: AttrEntry<T[K]>;
30
42
  };
31
43
  /**
32
44
  * Pass-through: `view` returns the raw string, or `undefined` when absent.
package/dist/elements.js CHANGED
@@ -1,16 +1,23 @@
1
- var y = Object.defineProperty;
2
- var m = (t, e, n) => e in t ? y(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var a = (t, e, n) => m(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { signal as v } from "@rhi-zone/rainbow";
5
- import { mount as S } from "./widget.js";
6
- const w = {
1
+ var v = Object.defineProperty;
2
+ var S = (t, e, n) => e in t ? v(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var f = (t, e, n) => S(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { signal as w } from "@rhi-zone/rainbow";
5
+ import { mount as k } from "./widget.js";
6
+ function N(t, e) {
7
+ if ("name" in e && typeof e.name == "string") {
8
+ const n = e;
9
+ return { attrName: n.name, optic: n.optic };
10
+ }
11
+ return { attrName: t, optic: e };
12
+ }
13
+ const O = {
7
14
  view(t) {
8
15
  return t ?? void 0;
9
16
  },
10
17
  review(t) {
11
18
  return t;
12
19
  }
13
- }, k = {
20
+ }, C = {
14
21
  view(t) {
15
22
  if (t == null) return;
16
23
  const e = Number(t);
@@ -19,7 +26,7 @@ const w = {
19
26
  review(t) {
20
27
  return String(t);
21
28
  }
22
- }, N = {
29
+ }, E = {
23
30
  view(t) {
24
31
  if (t != null)
25
32
  return t !== "false" && t !== "0";
@@ -28,7 +35,7 @@ const w = {
28
35
  return String(t);
29
36
  }
30
37
  };
31
- function A() {
38
+ function K() {
32
39
  return {
33
40
  view(t) {
34
41
  if (t != null)
@@ -43,15 +50,15 @@ function A() {
43
50
  }
44
51
  };
45
52
  }
46
- function J(t) {
53
+ function M(t) {
47
54
  const e = {};
48
55
  for (const n of Object.keys(t)) {
49
56
  const s = typeof t[n];
50
- s === "string" ? e[n] = w : s === "number" ? e[n] = k : s === "boolean" && (e[n] = N);
57
+ s === "string" ? e[n] = O : s === "number" ? e[n] = C : s === "boolean" && (e[n] = E);
51
58
  }
52
59
  return e;
53
60
  }
54
- function h(t) {
61
+ function m(t) {
55
62
  if (typeof t == "string") {
56
63
  const e = new CSSStyleSheet();
57
64
  return e.replaceSync(t), e;
@@ -62,57 +69,62 @@ function x(t, e) {
62
69
  const {
63
70
  widget: n,
64
71
  defaults: s,
65
- attrs: u = {},
66
- shadow: l = "open",
72
+ attrs: p = {},
73
+ shadow: c = "open",
67
74
  styles: i
68
- } = e, g = Object.keys(u), c = i == null ? [] : Array.isArray(i) ? i.map(h) : [h(i)];
69
- class f extends HTMLElement {
75
+ } = e, u = /* @__PURE__ */ new Map();
76
+ for (const o of Object.keys(p)) {
77
+ const a = p[o], { attrName: r, optic: g } = N(o, a);
78
+ u.set(r, { propKey: o, optic: g });
79
+ }
80
+ const h = [...u.keys()], b = i == null ? [] : Array.isArray(i) ? i.map(m) : [m(i)];
81
+ class d extends HTMLElement {
70
82
  constructor() {
71
83
  super(...arguments);
72
84
  // Use underscore prefix rather than # so Object.defineProperty below can
73
85
  // access instance state from outside the class body.
74
- a(this, "_rb_signal", v({ ...s }));
75
- a(this, "_rb_cleanup", null);
86
+ f(this, "_rb_signal", w({ ...s }));
87
+ f(this, "_rb_cleanup", null);
76
88
  }
77
89
  static get observedAttributes() {
78
- return g;
90
+ return h;
79
91
  }
80
92
  connectedCallback() {
81
- const r = l !== !1 ? this.shadowRoot ?? this.attachShadow({ mode: l }) : this;
82
- l !== !1 && c.length > 0 && (r.adoptedStyleSheets = c), this._rb_cleanup = S(n, this._rb_signal, r);
93
+ const r = c !== !1 ? this.shadowRoot ?? this.attachShadow({ mode: c }) : this;
94
+ c !== !1 && b.length > 0 && (r.adoptedStyleSheets = b), this._rb_cleanup = k(n, this._rb_signal, r);
83
95
  }
84
96
  disconnectedCallback() {
85
97
  var r;
86
98
  (r = this._rb_cleanup) == null || r.call(this), this._rb_cleanup = null;
87
99
  }
88
- attributeChangedCallback(r, O, _) {
89
- const d = u[r];
90
- if (d == null) return;
91
- const p = d.view(_) ?? s[r];
92
- this._rb_signal.set({ ...this._rb_signal.get(), [r]: p });
100
+ attributeChangedCallback(r, g, y) {
101
+ const l = u.get(r);
102
+ if (l == null) return;
103
+ const _ = l.optic.view(y) ?? s[l.propKey];
104
+ this._rb_signal.set({ ...this._rb_signal.get(), [l.propKey]: _ });
93
105
  }
94
106
  }
95
107
  for (const o of Object.keys(s))
96
- Object.defineProperty(f.prototype, o, {
108
+ Object.defineProperty(d.prototype, o, {
97
109
  get() {
98
110
  return this._rb_signal.get()[o];
99
111
  },
100
- set(b) {
112
+ set(a) {
101
113
  this._rb_signal.set({
102
114
  ...this._rb_signal.get(),
103
- [o]: b
115
+ [o]: a
104
116
  });
105
117
  },
106
118
  configurable: !0,
107
119
  enumerable: !0
108
120
  });
109
- customElements.define(t, f);
121
+ customElements.define(t, d);
110
122
  }
111
123
  export {
112
- N as attrBoolean,
113
- A as attrJson,
114
- k as attrNumber,
115
- w as attrString,
116
- J as attrsFrom,
124
+ E as attrBoolean,
125
+ K as attrJson,
126
+ C as attrNumber,
127
+ O as attrString,
128
+ M as attrsFrom,
117
129
  x as defineElement
118
130
  };
package/dist/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export * from "./widget.js";
3
3
  export * from "./form-state.js";
4
4
  export * from "./keybinds.js";
5
5
  export { attrString, attrNumber, attrBoolean, attrJson, attrsFrom, defineElement } from "./elements.js";
6
- export type { AttrSchema, PrimitiveAttrSchema } from "./elements.js";
6
+ export type { AttrEntry, AttrSchema, PrimitiveAttrSchema } from "./elements.js";
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { h as g } from "./html-C8SnQjvU.js";
2
- import { above as l, beside as p, bindAttr as f, bindCheckbox as x, bindClass as S, bindInput as w, bindSelect as W, bindShow as v, bindText as y, checkboxWidget as k, concat as C, dynamic as E, each as F, eachKeyed as A, focus as I, foldWidget as K, inputWidget as L, map as N, mount as B, narrow as D, numberInputWidget as J, on as T, register as V, selectWidget as j, show as q, stack as z, subscribe as G, subscribeNow as H, template as M, textareaWidget as O, watchAll as P, withScope as Q } from "./widget.js";
3
- import { createForm as U, createFormState as X, isDirty as Y, isFormValid as Z, shouldShowError as _ } from "./form-state.js";
2
+ import { above as l, beside as p, bindAttr as f, bindCheckbox as x, bindClass as S, bindInput as w, bindSelect as W, bindShow as v, bindText as y, checkboxWidget as k, concat as C, dynamic as E, each as F, eachKeyed as A, focus as I, foldWidget as K, inputWidget as L, map as N, match as B, mount as D, narrow as J, numberInputWidget as T, on as V, register as j, selectWidget as q, show as z, stack as G, subscribe as H, subscribeNow as M, template as O, textareaWidget as P, watchAll as Q, withScope as R } from "./widget.js";
3
+ import { createForm as X, createFormState as Y, isDirty as Z, isFormValid as _, shouldShowError as $ } from "./form-state.js";
4
4
  import { signal as a } from "@rhi-zone/rainbow";
5
- import { attrBoolean as ee, attrJson as te, attrNumber as ne, attrString as ie, attrsFrom as oe, defineElement as re } from "./elements.js";
6
- function c(e, n, t, r, i) {
5
+ import { attrBoolean as te, attrJson as ne, attrNumber as ie, attrString as oe, attrsFrom as re, defineElement as se } from "./elements.js";
6
+ function d(e, n, t, r, i) {
7
7
  const o = e(
8
8
  n,
9
9
  () => r(t.get()),
@@ -24,11 +24,11 @@ function b(e) {
24
24
  }
25
25
  export {
26
26
  l as above,
27
- ee as attrBoolean,
28
- te as attrJson,
29
- ne as attrNumber,
30
- ie as attrString,
31
- oe as attrsFrom,
27
+ te as attrBoolean,
28
+ ne as attrJson,
29
+ ie as attrNumber,
30
+ oe as attrString,
31
+ re as attrsFrom,
32
32
  p as beside,
33
33
  f as bindAttr,
34
34
  x as bindCheckbox,
@@ -40,9 +40,9 @@ export {
40
40
  b as bindingsStoreSignal,
41
41
  k as checkboxWidget,
42
42
  C as concat,
43
- U as createForm,
44
- X as createFormState,
45
- re as defineElement,
43
+ X as createForm,
44
+ Y as createFormState,
45
+ se as defineElement,
46
46
  E as dynamic,
47
47
  F as each,
48
48
  A as eachKeyed,
@@ -50,23 +50,24 @@ export {
50
50
  K as foldWidget,
51
51
  g as html,
52
52
  L as inputWidget,
53
- Y as isDirty,
54
- Z as isFormValid,
55
- c as keybindsContext,
53
+ Z as isDirty,
54
+ _ as isFormValid,
55
+ d as keybindsContext,
56
56
  N as map,
57
- B as mount,
58
- D as narrow,
59
- J as numberInputWidget,
60
- T as on,
61
- V as register,
62
- j as selectWidget,
63
- _ as shouldShowError,
64
- q as show,
65
- z as stack,
66
- G as subscribe,
67
- H as subscribeNow,
68
- M as template,
69
- O as textareaWidget,
70
- P as watchAll,
71
- Q as withScope
57
+ B as match,
58
+ D as mount,
59
+ J as narrow,
60
+ T as numberInputWidget,
61
+ V as on,
62
+ j as register,
63
+ q as selectWidget,
64
+ $ as shouldShowError,
65
+ z as show,
66
+ G as stack,
67
+ H as subscribe,
68
+ M as subscribeNow,
69
+ O as template,
70
+ P as textareaWidget,
71
+ Q as watchAll,
72
+ R as withScope
72
73
  };
package/dist/widget.d.ts CHANGED
@@ -379,6 +379,30 @@ export declare function bindShow(el: HTMLElement, s: ReadonlySignal<boolean>): (
379
379
  * success: (data) => renderData(data),
380
380
  * })
381
381
  */
382
+ /**
383
+ * Render a discriminated union by tag. Exhaustively maps each variant to a
384
+ * widget; swaps the rendered child when the tag changes.
385
+ *
386
+ * Compared to N `narrow` + `stack` calls:
387
+ * - Single container div (not N+1)
388
+ * - Exhaustiveness checked at compile time — missing variant = type error
389
+ * - No `tagged()` declarations at the call site
390
+ *
391
+ * Must be called during a widget call context.
392
+ *
393
+ * @example
394
+ * type Screen =
395
+ * | { screen: 'list'; items: Item[] }
396
+ * | { screen: 'detail'; item: Item }
397
+ *
398
+ * match('screen', {
399
+ * list: (s) => listWidget(s),
400
+ * detail: (s) => detailWidget(s),
401
+ * })
402
+ */
403
+ export declare function match<S extends Record<K, string>, K extends keyof S & string>(key: K, cases: {
404
+ [V in S[K] & string]: Widget<Extract<S, Record<K, V>>, FlowContent>;
405
+ }): Widget<S, DivEl>;
382
406
  export declare function foldWidget<T, E>(s: Signal<AsyncData<T, E>> | ReadonlySignal<AsyncData<T, E>>, cases: {
383
407
  notAsked?: () => AnyEl;
384
408
  loading?: () => AnyEl;
package/dist/widget.js CHANGED
@@ -1,347 +1,368 @@
1
- import { index as C, stateful as S, lens as L, signal as W } from "@rhi-zone/rainbow";
2
- import { i as N, s as B, o as $, t as F } from "./html-C8SnQjvU.js";
1
+ import { index as C, stateful as S, lens as L, tagged as W, signal as B } from "@rhi-zone/rainbow";
2
+ import { i as N, s as $, o as F, t as I } from "./html-C8SnQjvU.js";
3
3
  let k = null;
4
4
  function i(e) {
5
5
  k == null || k.push(e);
6
6
  }
7
- function b(e) {
8
- const t = k, o = [];
7
+ function h(e) {
8
+ const n = k, o = [];
9
9
  k = o;
10
- const n = e();
11
- return k = t, [n, () => {
10
+ const t = e();
11
+ return k = n, [t, () => {
12
12
  for (const c of o) c();
13
13
  }];
14
14
  }
15
- function K(e) {
16
- return b(e);
15
+ function M(e) {
16
+ return h(e);
17
17
  }
18
- function w(e, t) {
19
- i(e.subscribe(t));
18
+ function v(e, n) {
19
+ i(e.subscribe(n));
20
20
  }
21
- function M(e) {
21
+ function O(e) {
22
22
  i(e);
23
23
  }
24
- function O(e, t, o) {
25
- const [n, c] = b(() => e(t));
26
- return o.appendChild(n.node), () => {
27
- n.node.remove(), c();
24
+ function T(e, n, o) {
25
+ const [t, c] = h(() => e(n));
26
+ return o.appendChild(t.node), () => {
27
+ t.node.remove(), c();
28
28
  };
29
29
  }
30
- function T(e, t) {
31
- return (o) => e(o.focus(t));
30
+ function V(e, n) {
31
+ return (o) => e(o.focus(n));
32
32
  }
33
- function H(e, t) {
33
+ function H(e, n) {
34
34
  return (o) => {
35
- const n = document.createElement("div");
36
- n.dataset.narrow = "";
35
+ const t = document.createElement("div");
36
+ t.dataset.narrow = "";
37
37
  let c = null, r = null;
38
38
  const u = o, d = () => {
39
- r = u.narrow(t);
40
- const [s, p] = b(() => e(r));
41
- c = p, n.appendChild(s.node);
39
+ r = u.narrow(n);
40
+ const [a, l] = h(() => e(r));
41
+ c = l, t.appendChild(a.node);
42
42
  };
43
- return w(o, (s) => {
44
- const p = t.view(s);
45
- p !== void 0 && c === null ? d() : p === void 0 && c !== null && (c(), c = null, r = null, n.replaceChildren());
46
- }), t.view(o.get()) !== void 0 && d(), i(() => c == null ? void 0 : c()), { _tag: "div", node: n };
43
+ return v(o, (a) => {
44
+ const l = n.view(a);
45
+ l !== void 0 && c === null ? d() : l === void 0 && c !== null && (c(), c = null, r = null, t.replaceChildren());
46
+ }), n.view(o.get()) !== void 0 && d(), i(() => c == null ? void 0 : c()), { _tag: "div", node: t };
47
47
  };
48
48
  }
49
49
  function R(e) {
50
- return (t) => {
51
- const o = t, n = document.createElement("div");
52
- n.dataset.each = "";
50
+ return (n) => {
51
+ const o = n, t = document.createElement("div");
52
+ t.dataset.each = "";
53
53
  let c = [];
54
54
  const r = (d) => {
55
- for (const a of c) a();
56
- c = [], n.replaceChildren();
57
- for (let a = 0; a < d.length; a++) {
58
- const s = a, p = L(
59
- (l) => l[s],
60
- (l, f) => {
61
- const h = [...f];
62
- return h[s] = l, h;
55
+ for (const s of c) s();
56
+ c = [], t.replaceChildren();
57
+ for (let s = 0; s < d.length; s++) {
58
+ const a = s, l = L(
59
+ (f) => f[a],
60
+ (f, p) => {
61
+ const b = [...p];
62
+ return b[a] = f, b;
63
63
  }
64
- ), m = o.focus(p), [g, v] = b(() => e(m));
65
- c.push(v), n.appendChild(g.node);
64
+ ), g = o.focus(l), [m, w] = h(() => e(g));
65
+ c.push(w), t.appendChild(m.node);
66
66
  }
67
67
  };
68
- r(t.get());
69
- const u = t.map((d) => d.length);
70
- return w(u, () => r(t.get())), i(() => {
68
+ r(n.get());
69
+ const u = n.map((d) => d.length);
70
+ return v(u, () => r(n.get())), i(() => {
71
71
  for (const d of c) d();
72
- }), { _tag: "div", node: n };
72
+ }), { _tag: "div", node: t };
73
73
  };
74
74
  }
75
- function U(e, t) {
75
+ function U(e, n) {
76
76
  return (o) => {
77
- const n = o, c = document.createElement("div");
77
+ const t = o, c = document.createElement("div");
78
78
  c.dataset.beside = "";
79
- const r = n.focus(C(0)), u = n.focus(C(1)), [d, a] = b(() => e(r)), [s, p] = b(() => t(u));
80
- return c.appendChild(d.node), c.appendChild(s.node), i(a), i(p), { _tag: "div", node: c };
79
+ const r = t.focus(C(0)), u = t.focus(C(1)), [d, s] = h(() => e(r)), [a, l] = h(() => n(u));
80
+ return c.appendChild(d.node), c.appendChild(a.node), i(s), i(l), { _tag: "div", node: c };
81
81
  };
82
82
  }
83
- function V(e, t) {
83
+ function z(e, n) {
84
84
  return (o) => {
85
- const n = o, c = document.createElement("div");
85
+ const t = o, c = document.createElement("div");
86
86
  c.dataset.above = "";
87
- const r = n.focus(C(0)), u = n.focus(C(1)), [d, a] = b(() => e(r)), [s, p] = b(() => t(u));
88
- return c.appendChild(d.node), c.appendChild(s.node), i(a), i(p), { _tag: "div", node: c };
87
+ const r = t.focus(C(0)), u = t.focus(C(1)), [d, s] = h(() => e(r)), [a, l] = h(() => n(u));
88
+ return c.appendChild(d.node), c.appendChild(a.node), i(s), i(l), { _tag: "div", node: c };
89
89
  };
90
90
  }
91
- function z(e, t) {
91
+ function D(e, n) {
92
92
  return (o) => {
93
- const n = S(e, o);
94
- return t(n);
93
+ const t = S(e, o);
94
+ return n(t);
95
95
  };
96
96
  }
97
- function D(e, t) {
97
+ function G(e, n) {
98
98
  return (o) => {
99
- const n = o.narrow(t);
100
- return e(n);
99
+ const t = o.narrow(n);
100
+ return e(t);
101
101
  };
102
102
  }
103
- function G(e, t) {
103
+ function J(e, n) {
104
104
  return (o) => {
105
- const n = document.createElement("div");
106
- n.dataset.show = "";
107
- const [c, r] = b(() => e(o));
108
- n.appendChild(c.node), i(r);
105
+ const t = document.createElement("div");
106
+ t.dataset.show = "";
107
+ const [c, r] = h(() => e(o));
108
+ t.appendChild(c.node), i(r);
109
109
  const u = (d) => {
110
- n.style.display = t(d) ? "" : "none";
110
+ t.style.display = n(d) ? "" : "none";
111
111
  };
112
- return u(o.get()), w(o, u), { _tag: "div", node: n };
112
+ return u(o.get()), v(o, u), { _tag: "div", node: t };
113
113
  };
114
114
  }
115
- function J(e, t) {
115
+ function Q(e, n) {
116
116
  return (o) => {
117
- const n = document.createElement("div");
118
- n.dataset.concat = "";
119
- const [c, r] = b(() => e(o)), [u, d] = b(() => t(o));
120
- return n.appendChild(c.node), n.appendChild(u.node), i(r), i(d), { _tag: "div", node: n };
117
+ const t = document.createElement("div");
118
+ t.dataset.concat = "";
119
+ const [c, r] = h(() => e(o)), [u, d] = h(() => n(o));
120
+ return t.appendChild(c.node), t.appendChild(u.node), i(r), i(d), { _tag: "div", node: t };
121
121
  };
122
122
  }
123
- function Q(...e) {
124
- return (t) => {
123
+ function X(...e) {
124
+ return (n) => {
125
125
  const o = document.createElement("div");
126
126
  o.dataset.stack = "";
127
- for (const n of e) {
128
- const [c, r] = b(() => n(t));
127
+ for (const t of e) {
128
+ const [c, r] = h(() => t(n));
129
129
  o.appendChild(c.node), i(r);
130
130
  }
131
131
  return { _tag: "div", node: o };
132
132
  };
133
133
  }
134
- function X(e, t, o) {
135
- const n = document.createElement("template");
136
- return n.innerHTML = e, (c) => {
134
+ function Y(e, n, o) {
135
+ const t = document.createElement("template");
136
+ return t.innerHTML = e, (c) => {
137
137
  const r = document.createElement("div");
138
- r.dataset.templ = "", r.appendChild(n.content.cloneNode(!0));
138
+ r.dataset.templ = "", r.appendChild(t.content.cloneNode(!0));
139
139
  const u = {};
140
- for (const d of Object.keys(t)) {
141
- const a = t[d], s = r.querySelector(`${a}[data-ref="${d}"]`);
142
- if (s === null)
140
+ for (const d of Object.keys(n)) {
141
+ const s = n[d], a = r.querySelector(`${s}[data-ref="${d}"]`);
142
+ if (a === null)
143
143
  throw new Error(
144
- `templ: ref "${d}" not found — expected <${a} data-ref="${d}"> in template`
144
+ `templ: ref "${d}" not found — expected <${s} data-ref="${d}"> in template`
145
145
  );
146
- u[d] = { _tag: a, node: s };
146
+ u[d] = { _tag: s, node: a };
147
147
  }
148
148
  return o(c, u), { _tag: "div", node: r };
149
149
  };
150
150
  }
151
- function Y(e, t, o, n) {
152
- const c = (n == null ? void 0 : n.container) ?? "div", r = document.createElement(c);
151
+ function Z(e, n, o, t) {
152
+ const c = (t == null ? void 0 : t.container) ?? "div", r = document.createElement(c);
153
153
  r.dataset.eachKeyed = "";
154
- const u = /* @__PURE__ */ new Map(), d = (s, p) => {
155
- const m = W(p);
156
- let g = !1, v = () => {
154
+ const u = /* @__PURE__ */ new Map(), d = (a, l) => {
155
+ const g = B(l);
156
+ let m = !1, w = () => {
157
157
  };
158
- "set" in e && (v = m.subscribe((h) => {
159
- if (g) return;
160
- const x = e.get(), E = x.findIndex((y) => t(y) === s);
161
- if (E !== -1 && !Object.is(x[E], h)) {
162
- const y = [...x];
163
- y[E] = h, e.set(y);
158
+ "set" in e && (w = g.subscribe((b) => {
159
+ if (m) return;
160
+ const E = e.get(), x = E.findIndex((y) => n(y) === a);
161
+ if (x !== -1 && !Object.is(E[x], b)) {
162
+ const y = [...E];
163
+ y[x] = b, e.set(y);
164
164
  }
165
165
  }));
166
- const [l, f] = b(() => o(m));
166
+ const [f, p] = h(() => o(g));
167
167
  return {
168
- itemSignal: m,
169
- childNode: l.node,
168
+ itemSignal: g,
169
+ childNode: f.node,
170
170
  cleanup: () => {
171
- f(), v();
171
+ p(), w();
172
172
  },
173
- setFromParent: (h) => {
174
- g = !0, m.set(h), g = !1;
173
+ setFromParent: (b) => {
174
+ m = !0, g.set(b), m = !1;
175
175
  }
176
176
  };
177
- }, a = (s) => {
178
- var v;
179
- const p = s.map(t), m = new Set(p);
180
- for (const [l, f] of u)
181
- m.has(l) || (f.cleanup(), (v = f.childNode.parentNode) == null || v.removeChild(f.childNode), u.delete(l));
182
- for (let l = 0; l < s.length; l++) {
183
- const f = p[l], h = s[l];
184
- u.has(f) ? u.get(f).setFromParent(h) : u.set(f, d(f, h));
177
+ }, s = (a) => {
178
+ var w;
179
+ const l = a.map(n), g = new Set(l);
180
+ for (const [f, p] of u)
181
+ g.has(f) || (p.cleanup(), (w = p.childNode.parentNode) == null || w.removeChild(p.childNode), u.delete(f));
182
+ for (let f = 0; f < a.length; f++) {
183
+ const p = l[f], b = a[f];
184
+ u.has(p) ? u.get(p).setFromParent(b) : u.set(p, d(p, b));
185
185
  }
186
- let g = null;
187
- for (let l = s.length - 1; l >= 0; l--) {
188
- const f = u.get(p[l]);
189
- (f.childNode.parentNode !== r || f.childNode.nextSibling !== g) && r.insertBefore(f.childNode, g), g = f.childNode;
186
+ let m = null;
187
+ for (let f = a.length - 1; f >= 0; f--) {
188
+ const p = u.get(l[f]);
189
+ (p.childNode.parentNode !== r || p.childNode.nextSibling !== m) && r.insertBefore(p.childNode, m), m = p.childNode;
190
190
  }
191
191
  };
192
- return a(e.get()), w(e, a), i(() => {
193
- for (const s of u.values()) s.cleanup();
192
+ return s(e.get()), v(e, s), i(() => {
193
+ for (const a of u.values()) a.cleanup();
194
194
  }), { _tag: c, node: r };
195
195
  }
196
- function A(e, t, o) {
197
- const n = o;
198
- e.addEventListener(t, n), i(() => e.removeEventListener(t, n));
196
+ function _(e, n, o) {
197
+ const t = o;
198
+ e.addEventListener(n, t), i(() => e.removeEventListener(n, t));
199
199
  }
200
- function _(e, t) {
201
- e.value = t.get();
202
- const o = () => t.set(e.value);
200
+ function A(e, n) {
201
+ e.value = n.get();
202
+ const o = () => n.set(e.value);
203
203
  e.addEventListener("input", o);
204
- const n = t.subscribe((r) => {
204
+ const t = n.subscribe((r) => {
205
205
  e.value !== r && (e.value = r);
206
206
  }), c = () => {
207
- e.removeEventListener("input", o), n();
207
+ e.removeEventListener("input", o), t();
208
208
  };
209
209
  return i(c), c;
210
210
  }
211
- function I(e, t) {
212
- A(e, "change", () => t.set(e.value)), w(t, (o) => {
211
+ function P(e, n) {
212
+ _(e, "change", () => n.set(e.value)), v(n, (o) => {
213
213
  e.value !== o && (e.value = o);
214
214
  });
215
215
  }
216
- function P(e, t) {
217
- A(e, "change", () => t.set(e.checked)), w(t, (o) => {
216
+ function j(e, n) {
217
+ _(e, "change", () => n.set(e.checked)), v(n, (o) => {
218
218
  e.checked !== o && (e.checked = o);
219
219
  });
220
220
  }
221
- function Z(e, t) {
222
- t(e.get()), i(e.subscribe(t));
221
+ function ee(e, n) {
222
+ n(e.get()), i(e.subscribe(n));
223
223
  }
224
- function ee(e, t) {
225
- e.textContent = t.get(), i(t.subscribe((o) => {
224
+ function te(e, n) {
225
+ e.textContent = n.get(), i(n.subscribe((o) => {
226
226
  e.textContent = o;
227
227
  }));
228
228
  }
229
- function ne(e, t, o) {
230
- e.setAttribute(t, o.get()), i(o.subscribe((n) => {
231
- e.setAttribute(t, n);
229
+ function ne(e, n, o) {
230
+ e.setAttribute(n, o.get()), i(o.subscribe((t) => {
231
+ e.setAttribute(n, t);
232
232
  }));
233
233
  }
234
- function te(e, t, o) {
235
- e.classList.toggle(t, o.get()), i(o.subscribe((n) => {
236
- e.classList.toggle(t, n);
234
+ function oe(e, n, o) {
235
+ e.classList.toggle(n, o.get()), i(o.subscribe((t) => {
236
+ e.classList.toggle(n, t);
237
237
  }));
238
238
  }
239
- function oe(e, t) {
240
- t();
241
- const o = e.map((n) => n.subscribe(t));
239
+ function ce(e, n) {
240
+ n();
241
+ const o = e.map((t) => t.subscribe(n));
242
242
  return () => {
243
- for (const n of o) n();
243
+ for (const t of o) t();
244
244
  };
245
245
  }
246
- function ce(e, t) {
247
- return e.style.display = t.get() ? "" : "none", t.subscribe((o) => {
246
+ function re(e, n) {
247
+ return e.style.display = n.get() ? "" : "none", n.subscribe((o) => {
248
248
  e.style.display = o ? "" : "none";
249
249
  });
250
250
  }
251
- function re(e, t) {
251
+ function ue(e, n) {
252
+ return (o) => {
253
+ const t = document.createElement("div");
254
+ t.dataset.match = "";
255
+ let c = null, r = null;
256
+ const u = (d) => {
257
+ const s = d[e];
258
+ if (s === r) return;
259
+ c == null || c(), c = null, t.replaceChildren(), r = s;
260
+ const a = n[s];
261
+ if (a == null) return;
262
+ const l = o.narrow(W(e, s));
263
+ let g;
264
+ [g, c] = h(
265
+ () => a(l)
266
+ ), t.appendChild(g.node);
267
+ };
268
+ return v(o, u), u(o.get()), i(() => c == null ? void 0 : c()), { _tag: "div", node: t };
269
+ };
270
+ }
271
+ function de(e, n) {
252
272
  const o = document.createElement("div");
253
273
  o.dataset.foldWidget = "";
254
- let n = null;
274
+ let t = null;
255
275
  const c = (r) => {
256
- n !== null && (n(), n = null), o.replaceChildren();
276
+ t !== null && (t(), t = null), o.replaceChildren();
257
277
  let u = null;
258
278
  switch (r.status) {
259
279
  case "notAsked":
260
- u = t.notAsked ?? null;
280
+ u = n.notAsked ?? null;
261
281
  break;
262
282
  case "loading":
263
- u = t.loading ?? null;
283
+ u = n.loading ?? null;
264
284
  break;
265
285
  case "failure":
266
- u = t.failure ? () => t.failure(r.error) : null;
286
+ u = n.failure ? () => n.failure(r.error) : null;
267
287
  break;
268
288
  case "success":
269
- u = t.success ? () => t.success(r.value) : null;
289
+ u = n.success ? () => n.success(r.value) : null;
270
290
  break;
271
291
  }
272
292
  if (u !== null) {
273
293
  let d;
274
- [d, n] = b(u), o.appendChild(d.node);
294
+ [d, t] = h(u), o.appendChild(d.node);
275
295
  }
276
296
  };
277
- return c(e.get()), i(e.subscribe(c)), i(() => n == null ? void 0 : n()), { _tag: "div", node: o };
278
- }
279
- function ue(e) {
280
- return (t) => {
281
- const o = t, n = N(e ?? {});
282
- return n.node.value = o.get(), _(n.node, o), n;
283
- };
297
+ return c(e.get()), i(e.subscribe(c)), i(() => t == null ? void 0 : t()), { _tag: "div", node: o };
284
298
  }
285
- function de(e) {
286
- return (t) => {
287
- const o = t, n = F(e ?? {});
288
- return n.node.value = o.get(), _(n.node, o), n;
299
+ function ae(e) {
300
+ return (n) => {
301
+ const o = n, t = N(e ?? {});
302
+ return t.node.value = o.get(), A(t.node, o), t;
289
303
  };
290
304
  }
291
305
  function se(e) {
292
- return (t) => {
293
- const o = t, n = N({ ...e, type: "checkbox" });
294
- return n.node.checked = o.get(), P(n.node, o), n;
306
+ return (n) => {
307
+ const o = n, t = I(e ?? {});
308
+ return t.node.value = o.get(), A(t.node, o), t;
295
309
  };
296
310
  }
297
311
  function ie(e) {
298
- return (t) => {
299
- const o = t, n = N({ ...e, type: "number" });
300
- return n.node.value = String(o.get()), A(n.node, "input", () => {
301
- const c = n.node.valueAsNumber;
312
+ return (n) => {
313
+ const o = n, t = N({ ...e, type: "checkbox" });
314
+ return t.node.checked = o.get(), j(t.node, o), t;
315
+ };
316
+ }
317
+ function le(e) {
318
+ return (n) => {
319
+ const o = n, t = N({ ...e, type: "number" });
320
+ return t.node.value = String(o.get()), _(t.node, "input", () => {
321
+ const c = t.node.valueAsNumber;
302
322
  isNaN(c) || o.set(c);
303
- }), w(t, (c) => {
304
- n.node.valueAsNumber !== c && (n.node.value = String(c));
305
- }), n;
323
+ }), v(n, (c) => {
324
+ t.node.valueAsNumber !== c && (t.node.value = String(c));
325
+ }), t;
306
326
  };
307
327
  }
308
- function ae(e, t) {
328
+ function fe(e, n) {
309
329
  return (o) => {
310
- const n = o, c = B(t ?? {}, ...e.map((r) => $({ value: r.value }, r.label)));
311
- return c.node.value = n.get(), I(c.node, n), c;
330
+ const t = o, c = $(n ?? {}, ...e.map((r) => F({ value: r.value }, r.label)));
331
+ return c.node.value = t.get(), P(c.node, t), c;
312
332
  };
313
333
  }
314
334
  export {
315
- V as above,
335
+ z as above,
316
336
  U as beside,
317
337
  ne as bindAttr,
318
- P as bindCheckbox,
319
- te as bindClass,
320
- _ as bindInput,
321
- I as bindSelect,
322
- ce as bindShow,
323
- ee as bindText,
324
- se as checkboxWidget,
325
- J as concat,
326
- z as dynamic,
338
+ j as bindCheckbox,
339
+ oe as bindClass,
340
+ A as bindInput,
341
+ P as bindSelect,
342
+ re as bindShow,
343
+ te as bindText,
344
+ ie as checkboxWidget,
345
+ Q as concat,
346
+ D as dynamic,
327
347
  R as each,
328
- Y as eachKeyed,
329
- T as focus,
330
- re as foldWidget,
331
- ue as inputWidget,
332
- D as map,
333
- O as mount,
348
+ Z as eachKeyed,
349
+ V as focus,
350
+ de as foldWidget,
351
+ ae as inputWidget,
352
+ G as map,
353
+ ue as match,
354
+ T as mount,
334
355
  H as narrow,
335
- ie as numberInputWidget,
336
- A as on,
337
- M as register,
338
- ae as selectWidget,
339
- G as show,
340
- Q as stack,
341
- w as subscribe,
342
- Z as subscribeNow,
343
- X as template,
344
- de as textareaWidget,
345
- oe as watchAll,
346
- K as withScope
356
+ le as numberInputWidget,
357
+ _ as on,
358
+ O as register,
359
+ fe as selectWidget,
360
+ J as show,
361
+ X as stack,
362
+ v as subscribe,
363
+ ee as subscribeNow,
364
+ Y as template,
365
+ se as textareaWidget,
366
+ ce as watchAll,
367
+ M as withScope
347
368
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhi-zone/rainbow-ui",
3
- "version": "0.2.0-alpha.1",
3
+ "version": "0.2.0-alpha.3",
4
4
  "description": "Type-safe DOM factories and algebraic widget combinators for rainbow",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",