@rhi-zone/rainbow-ui 0.2.0-alpha.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/widget.js ADDED
@@ -0,0 +1,347 @@
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";
3
+ let k = null;
4
+ function i(e) {
5
+ k == null || k.push(e);
6
+ }
7
+ function b(e) {
8
+ const t = k, o = [];
9
+ k = o;
10
+ const n = e();
11
+ return k = t, [n, () => {
12
+ for (const c of o) c();
13
+ }];
14
+ }
15
+ function K(e) {
16
+ return b(e);
17
+ }
18
+ function w(e, t) {
19
+ i(e.subscribe(t));
20
+ }
21
+ function M(e) {
22
+ i(e);
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();
28
+ };
29
+ }
30
+ function T(e, t) {
31
+ return (o) => e(o.focus(t));
32
+ }
33
+ function H(e, t) {
34
+ return (o) => {
35
+ const n = document.createElement("div");
36
+ n.dataset.narrow = "";
37
+ let c = null, r = null;
38
+ const u = o, d = () => {
39
+ r = u.narrow(t);
40
+ const [s, p] = b(() => e(r));
41
+ c = p, n.appendChild(s.node);
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 };
47
+ };
48
+ }
49
+ function R(e) {
50
+ return (t) => {
51
+ const o = t, n = document.createElement("div");
52
+ n.dataset.each = "";
53
+ let c = [];
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;
63
+ }
64
+ ), m = o.focus(p), [g, v] = b(() => e(m));
65
+ c.push(v), n.appendChild(g.node);
66
+ }
67
+ };
68
+ r(t.get());
69
+ const u = t.map((d) => d.length);
70
+ return w(u, () => r(t.get())), i(() => {
71
+ for (const d of c) d();
72
+ }), { _tag: "div", node: n };
73
+ };
74
+ }
75
+ function U(e, t) {
76
+ return (o) => {
77
+ const n = o, c = document.createElement("div");
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 };
81
+ };
82
+ }
83
+ function V(e, t) {
84
+ return (o) => {
85
+ const n = o, c = document.createElement("div");
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 };
89
+ };
90
+ }
91
+ function z(e, t) {
92
+ return (o) => {
93
+ const n = S(e, o);
94
+ return t(n);
95
+ };
96
+ }
97
+ function D(e, t) {
98
+ return (o) => {
99
+ const n = o.narrow(t);
100
+ return e(n);
101
+ };
102
+ }
103
+ function G(e, t) {
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);
109
+ const u = (d) => {
110
+ n.style.display = t(d) ? "" : "none";
111
+ };
112
+ return u(o.get()), w(o, u), { _tag: "div", node: n };
113
+ };
114
+ }
115
+ function J(e, t) {
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 };
121
+ };
122
+ }
123
+ function Q(...e) {
124
+ return (t) => {
125
+ const o = document.createElement("div");
126
+ o.dataset.stack = "";
127
+ for (const n of e) {
128
+ const [c, r] = b(() => n(t));
129
+ o.appendChild(c.node), i(r);
130
+ }
131
+ return { _tag: "div", node: o };
132
+ };
133
+ }
134
+ function X(e, t, o) {
135
+ const n = document.createElement("template");
136
+ return n.innerHTML = e, (c) => {
137
+ const r = document.createElement("div");
138
+ r.dataset.templ = "", r.appendChild(n.content.cloneNode(!0));
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)
143
+ throw new Error(
144
+ `templ: ref "${d}" not found — expected <${a} data-ref="${d}"> in template`
145
+ );
146
+ u[d] = { _tag: a, node: s };
147
+ }
148
+ return o(c, u), { _tag: "div", node: r };
149
+ };
150
+ }
151
+ function Y(e, t, o, n) {
152
+ const c = (n == null ? void 0 : n.container) ?? "div", r = document.createElement(c);
153
+ r.dataset.eachKeyed = "";
154
+ const u = /* @__PURE__ */ new Map(), d = (s, p) => {
155
+ const m = W(p);
156
+ let g = !1, v = () => {
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);
164
+ }
165
+ }));
166
+ const [l, f] = b(() => o(m));
167
+ return {
168
+ itemSignal: m,
169
+ childNode: l.node,
170
+ cleanup: () => {
171
+ f(), v();
172
+ },
173
+ setFromParent: (h) => {
174
+ g = !0, m.set(h), g = !1;
175
+ }
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));
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;
190
+ }
191
+ };
192
+ return a(e.get()), w(e, a), i(() => {
193
+ for (const s of u.values()) s.cleanup();
194
+ }), { _tag: c, node: r };
195
+ }
196
+ function A(e, t, o) {
197
+ const n = o;
198
+ e.addEventListener(t, n), i(() => e.removeEventListener(t, n));
199
+ }
200
+ function _(e, t) {
201
+ e.value = t.get();
202
+ const o = () => t.set(e.value);
203
+ e.addEventListener("input", o);
204
+ const n = t.subscribe((r) => {
205
+ e.value !== r && (e.value = r);
206
+ }), c = () => {
207
+ e.removeEventListener("input", o), n();
208
+ };
209
+ return i(c), c;
210
+ }
211
+ function I(e, t) {
212
+ A(e, "change", () => t.set(e.value)), w(t, (o) => {
213
+ e.value !== o && (e.value = o);
214
+ });
215
+ }
216
+ function P(e, t) {
217
+ A(e, "change", () => t.set(e.checked)), w(t, (o) => {
218
+ e.checked !== o && (e.checked = o);
219
+ });
220
+ }
221
+ function Z(e, t) {
222
+ t(e.get()), i(e.subscribe(t));
223
+ }
224
+ function ee(e, t) {
225
+ e.textContent = t.get(), i(t.subscribe((o) => {
226
+ e.textContent = o;
227
+ }));
228
+ }
229
+ function ne(e, t, o) {
230
+ e.setAttribute(t, o.get()), i(o.subscribe((n) => {
231
+ e.setAttribute(t, n);
232
+ }));
233
+ }
234
+ function te(e, t, o) {
235
+ e.classList.toggle(t, o.get()), i(o.subscribe((n) => {
236
+ e.classList.toggle(t, n);
237
+ }));
238
+ }
239
+ function oe(e, t) {
240
+ t();
241
+ const o = e.map((n) => n.subscribe(t));
242
+ return () => {
243
+ for (const n of o) n();
244
+ };
245
+ }
246
+ function ce(e, t) {
247
+ return e.style.display = t.get() ? "" : "none", t.subscribe((o) => {
248
+ e.style.display = o ? "" : "none";
249
+ });
250
+ }
251
+ function re(e, t) {
252
+ const o = document.createElement("div");
253
+ o.dataset.foldWidget = "";
254
+ let n = null;
255
+ const c = (r) => {
256
+ n !== null && (n(), n = null), o.replaceChildren();
257
+ let u = null;
258
+ switch (r.status) {
259
+ case "notAsked":
260
+ u = t.notAsked ?? null;
261
+ break;
262
+ case "loading":
263
+ u = t.loading ?? null;
264
+ break;
265
+ case "failure":
266
+ u = t.failure ? () => t.failure(r.error) : null;
267
+ break;
268
+ case "success":
269
+ u = t.success ? () => t.success(r.value) : null;
270
+ break;
271
+ }
272
+ if (u !== null) {
273
+ let d;
274
+ [d, n] = b(u), o.appendChild(d.node);
275
+ }
276
+ };
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
+ };
284
+ }
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;
289
+ };
290
+ }
291
+ 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;
295
+ };
296
+ }
297
+ 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;
302
+ isNaN(c) || o.set(c);
303
+ }), w(t, (c) => {
304
+ n.node.valueAsNumber !== c && (n.node.value = String(c));
305
+ }), n;
306
+ };
307
+ }
308
+ function ae(e, t) {
309
+ 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;
312
+ };
313
+ }
314
+ export {
315
+ V as above,
316
+ U as beside,
317
+ 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,
327
+ 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,
334
+ 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
347
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Widget combinator tests.
3
+ *
4
+ * Uses happy-dom (via vitest) for a lightweight DOM environment.
5
+ * All tests share a single <div id="root"> that is cleared between tests.
6
+ */
7
+ export {};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@rhi-zone/rainbow-ui",
3
+ "version": "0.2.0-alpha.0",
4
+ "description": "Type-safe DOM factories and algebraic widget combinators for rainbow",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ },
12
+ "./html": {
13
+ "import": "./dist/html.js",
14
+ "types": "./dist/html.d.ts"
15
+ },
16
+ "./widget": {
17
+ "import": "./dist/widget.js",
18
+ "types": "./dist/widget.d.ts"
19
+ },
20
+ "./elements": {
21
+ "import": "./dist/elements.js",
22
+ "types": "./dist/elements.d.ts"
23
+ },
24
+ "./form-state": {
25
+ "import": "./dist/form-state.js",
26
+ "types": "./dist/form-state.d.ts"
27
+ }
28
+ },
29
+ "files": ["dist"],
30
+ "scripts": {
31
+ "dev": "vite build --watch",
32
+ "build": "vite build && tsgo --emitDeclarationOnly",
33
+ "typecheck": "tsgo --noEmit",
34
+ "test": "vitest run"
35
+ },
36
+ "dependencies": {
37
+ "@rhi-zone/rainbow": "workspace:*"
38
+ },
39
+ "devDependencies": {
40
+ "happy-dom": "^16.0.0",
41
+ "vite": "^6.0.0",
42
+ "vitest": "^2.0.0"
43
+ }
44
+ }