@rhi-zone/rainbow-ui 0.2.0-alpha.0 → 0.2.0-alpha.2
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/elements.d.ts +15 -3
- package/dist/elements.js +47 -35
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
package/dist/elements.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
22
|
-
*
|
|
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]?:
|
|
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
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { signal as
|
|
5
|
-
import { mount as
|
|
6
|
-
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
|
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
|
|
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] =
|
|
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
|
|
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:
|
|
66
|
-
shadow:
|
|
72
|
+
attrs: p = {},
|
|
73
|
+
shadow: c = "open",
|
|
67
74
|
styles: i
|
|
68
|
-
} = e,
|
|
69
|
-
|
|
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
|
-
|
|
75
|
-
|
|
86
|
+
f(this, "_rb_signal", w({ ...s }));
|
|
87
|
+
f(this, "_rb_cleanup", null);
|
|
76
88
|
}
|
|
77
89
|
static get observedAttributes() {
|
|
78
|
-
return
|
|
90
|
+
return h;
|
|
79
91
|
}
|
|
80
92
|
connectedCallback() {
|
|
81
|
-
const r =
|
|
82
|
-
|
|
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,
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
const
|
|
92
|
-
this._rb_signal.set({ ...this._rb_signal.get(), [
|
|
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(
|
|
108
|
+
Object.defineProperty(d.prototype, o, {
|
|
97
109
|
get() {
|
|
98
110
|
return this._rb_signal.get()[o];
|
|
99
111
|
},
|
|
100
|
-
set(
|
|
112
|
+
set(a) {
|
|
101
113
|
this._rb_signal.set({
|
|
102
114
|
...this._rb_signal.get(),
|
|
103
|
-
[o]:
|
|
115
|
+
[o]: a
|
|
104
116
|
});
|
|
105
117
|
},
|
|
106
118
|
configurable: !0,
|
|
107
119
|
enumerable: !0
|
|
108
120
|
});
|
|
109
|
-
customElements.define(t,
|
|
121
|
+
customElements.define(t, d);
|
|
110
122
|
}
|
|
111
123
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhi-zone/rainbow-ui",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.2",
|
|
4
4
|
"description": "Type-safe DOM factories and algebraic widget combinators for rainbow",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"test": "vitest run"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@rhi-zone/rainbow": "
|
|
37
|
+
"@rhi-zone/rainbow": "0.2.0-alpha.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"happy-dom": "^16.0.0",
|