ajo 0.1.20 → 0.1.21
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/html.cjs +1 -1
- package/dist/html.js +32 -31
- package/dist/index.cjs +1 -1
- package/dist/index.js +46 -44
- package/package.json +5 -5
- package/readme.md +8 -8
- package/types.ts +24 -34
package/dist/html.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const{isArray
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const{isArray:m,from:$}=Array,p="",{create:v,assign:g,entries:x,prototype:{hasOwnProperty:w},hasOwn:k=(e,t)=>w.call(e,t)}=Object,c=e=>$(d(e)).join(""),d=function*(e){for(e of u(e))if(typeof e=="string")yield f(e);else{const{nodeName:t,skip:o,children:r=""}=e;let n="";for(const[l,i]of x(e))N.has(l)||l.startsWith("set:")||i==null||i===!1||(n+=i===!0?` ${l}`:` ${l}="${f(String(i))}"`);S.has(t)?yield`<${t}${n}>`:o?yield`<${t}${n}></${t}>`:(yield`<${t}${n}>`,typeof r=="string"&&r.startsWith(p)?yield r.slice(1):yield*d(r),yield`</${t}>`)}},u=function*(e,t={value:""},o=!0){for(e of m(e)?e:[e])if(!(e==null||typeof e=="boolean"))if(k(e,"nodeName")){const{value:r}=t,{nodeName:n}=e;if(r&&(yield r,t.value=""),typeof n=="function")if(n.constructor.name==="GeneratorFunction"){const l={},i=g({},n.attrs);for(const a in e){const y=e[a];a.startsWith("attr:")?i[a.slice(5)]=y:l[a]=y}i.nodeName=n.is??"div",i.children=O(n,l),yield i}else yield*u(n(e),t,!1);else yield e}else m(e)?yield*u(e,t,!1):t.value+=e;o&&t.value&&(yield t.value)},S=new Set("area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",")),N=new Set("nodeName,key,skip,memo,ref,children".split(",")),f=e=>e.replace(/[&<>"']/g,t=>`&#${t.charCodeAt(0)};`);let s=null;const O=(e,t)=>{let o,r;try{const n=e.call(o={$args:t,$context:v((s==null?void 0:s.$context)??null),render(){s!==o&&o.next()},next(){const l=s;s=o,r=c(n.next().value),s=l},throw(l){r=c(n.throw(l).value)},return(){n.return()}},t);o.next()}catch(n){o.throw(n)}finally{o.return()}return p+r},j=(e,t=Symbol())=>function(){const o=this??s;return o?arguments.length===0?t in o.$context?o.$context[t]:e:o.$context[t]=arguments[0]:e};exports.context=j;exports.html=d;exports.render=c;
|
package/dist/html.js
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
|
-
const { isArray: d, from:
|
|
1
|
+
const { isArray: d, from: $ } = Array, m = "", { create: v, assign: x, entries: g, prototype: { hasOwnProperty: w }, hasOwn: k = (e, t) => w.call(e, t) } = Object, y = (e) => $(p(e)).join(""), p = function* (e) {
|
|
2
2
|
for (e of c(e))
|
|
3
|
-
if (typeof e == "string") yield
|
|
3
|
+
if (typeof e == "string") yield f(e);
|
|
4
4
|
else {
|
|
5
|
-
const { nodeName: t, skip: o, children:
|
|
5
|
+
const { nodeName: t, skip: o, children: l = "" } = e;
|
|
6
6
|
let n = "";
|
|
7
|
-
for (const [
|
|
8
|
-
S.has(
|
|
9
|
-
|
|
7
|
+
for (const [r, i] of g(e))
|
|
8
|
+
S.has(r) || r.startsWith("set:") || i == null || i === !1 || (n += i === !0 ? ` ${r}` : ` ${r}="${f(String(i))}"`);
|
|
9
|
+
N.has(t) ? yield `<${t}${n}>` : o ? yield `<${t}${n}></${t}>` : (yield `<${t}${n}>`, typeof l == "string" && l.startsWith(m) ? yield l.slice(1) : yield* p(l), yield `</${t}>`);
|
|
10
10
|
}
|
|
11
11
|
}, c = function* (e, t = { value: "" }, o = !0) {
|
|
12
12
|
for (e of d(e) ? e : [e])
|
|
13
13
|
if (!(e == null || typeof e == "boolean"))
|
|
14
|
-
if (
|
|
15
|
-
const { value:
|
|
16
|
-
if (
|
|
14
|
+
if (k(e, "nodeName")) {
|
|
15
|
+
const { value: l } = t, { nodeName: n } = e;
|
|
16
|
+
if (l && (yield l, t.value = ""), typeof n == "function")
|
|
17
17
|
if (n.constructor.name === "GeneratorFunction") {
|
|
18
|
-
const
|
|
18
|
+
const r = {}, i = x({}, n.attrs);
|
|
19
19
|
for (const a in e) {
|
|
20
20
|
const u = e[a];
|
|
21
|
-
a.startsWith("attr:") ?
|
|
21
|
+
a.startsWith("attr:") ? i[a.slice(5)] = u : r[a] = u;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
i.nodeName = n.is ?? "div", i.children = A(n, r), yield i;
|
|
24
24
|
} else yield* c(n(e), t, !1);
|
|
25
25
|
else yield e;
|
|
26
26
|
} else d(e) ? yield* c(e, t, !1) : t.value += e;
|
|
27
27
|
o && t.value && (yield t.value);
|
|
28
|
-
},
|
|
29
|
-
let
|
|
28
|
+
}, N = new Set("area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",")), S = new Set("nodeName,key,skip,memo,ref,children".split(",")), f = (e) => e.replace(/[&<>"']/g, (t) => `&#${t.charCodeAt(0)};`);
|
|
29
|
+
let s = null;
|
|
30
30
|
const A = (e, t) => {
|
|
31
|
-
let o,
|
|
31
|
+
let o, l;
|
|
32
32
|
try {
|
|
33
33
|
const n = e.call(o = {
|
|
34
34
|
$args: t,
|
|
35
|
-
$context:
|
|
35
|
+
$context: v((s == null ? void 0 : s.$context) ?? null),
|
|
36
36
|
render() {
|
|
37
|
-
|
|
37
|
+
s !== o && o.next();
|
|
38
38
|
},
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
39
|
+
next() {
|
|
40
|
+
const r = s;
|
|
41
|
+
s = o, l = y(n.next().value), s = r;
|
|
42
42
|
},
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
throw(r) {
|
|
44
|
+
l = y(n.throw(r).value);
|
|
45
45
|
},
|
|
46
|
-
|
|
46
|
+
return() {
|
|
47
47
|
n.return();
|
|
48
48
|
}
|
|
49
49
|
}, t);
|
|
50
|
-
o
|
|
50
|
+
o.next();
|
|
51
51
|
} catch (n) {
|
|
52
|
-
o
|
|
52
|
+
o.throw(n);
|
|
53
53
|
} finally {
|
|
54
|
-
o
|
|
54
|
+
o.return();
|
|
55
55
|
}
|
|
56
|
-
return
|
|
57
|
-
}, O = (e, t = Symbol()) => function(
|
|
58
|
-
|
|
56
|
+
return m + l;
|
|
57
|
+
}, O = (e, t = Symbol()) => function() {
|
|
58
|
+
const o = this ?? s;
|
|
59
|
+
return o ? arguments.length === 0 ? t in o.$context ? o.$context[t] : e : o.$context[t] = arguments[0] : e;
|
|
59
60
|
};
|
|
60
61
|
export {
|
|
61
62
|
O as context,
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
p as html,
|
|
64
|
+
y as render
|
|
64
65
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=({children:t})=>t,N=function(t,n){
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=({children:t})=>t,N=function(t,n){return(n??(n=$(null))).nodeName=t,"children"in n||arguments.length<3||(n.children=arguments.length===3?arguments[2]:k.call(arguments,2)),n},d=(t,n)=>{let e=n.firstChild;for(t of h(t)){let o=e;if(typeof t=="string"){for(;o&&o.nodeType!=3;)o=o.nextSibling;o?o.data!=t&&(o.data=t):o=document.createTextNode(t)}else{const{nodeName:i,key:a,skip:c,memo:s,ref:f,children:w}=t;for(;o&&!(o.localName===i&&(o.$key??(o.$key=a))==a);)o=o.nextSibling;if(o??(o=m(document.createElementNS(t.xmlns??i==="svg"?O:n.namespaceURI,i),{$key:a})),s==null||F(o.$memo,o.$memo=s)){const{$props:y}=o,x={};for(const l of p(m({},y,t))){if(T.has(l))continue;const u=x[l]=t[l];u!==(y==null?void 0:y[l])&&(l.startsWith("set:")?o[l.slice(4)]=u:u==null||u===!1?o.removeAttribute(l):o.setAttribute(l,u===!0?"":u))}o.$props=x,c||d(w,o),typeof f=="function"&&(o.$ref=f)(o)}}o===e?e=e.nextSibling:C(n,o,e)}for(;e;){const o=e.nextSibling;e.nodeType===1&&v(e),n.removeChild(e),e=o}},{isArray:g,prototype:{slice:k}}=Array,{create:$,assign:m,keys:p,prototype:{hasOwnProperty:b},hasOwn:A=(t,n)=>b.call(t,n)}=Object,O="http://www.w3.org/2000/svg",T=new Set("nodeName,key,skip,memo,ref,children".split(",")),F=(t,n)=>g(t)&&g(n)?t.some((e,o)=>e!==n[o]):t!==n,h=function*(t,n={value:""},e=!0){for(t of g(t)?t:[t])if(!(t==null||typeof t=="boolean"))if(A(t,"nodeName")){const{value:o}=n,{nodeName:i}=t;if(o&&(yield o,n.value=""),typeof i=="function")if(i.constructor.name==="GeneratorFunction"){const a={},c=m({},i.attrs);for(const s of p(t)){const f=t[s];s.startsWith("attr:")?c[s.slice(5)]=f:s==="key"||s==="memo"?c[s]=f:a[s]=f}c.nodeName=i.is??"div",c.skip=!0,c.ref=j.bind(null,i,a),yield c}else yield*h(i(t),n,!1);else yield t}else g(t)?yield*h(t,n,!1):n.value+=t;e&&n.value&&(yield n.value)},j=(t,n,e)=>{if(!e)return;e.$generator??(e.$generator=(m(e,E),e.$context??(e.$context=$((r==null?void 0:r.$context)??null)),t));const{skip:o,ref:i,...a}=n;e.$ref=B.bind(null,i,e),m(e.$args??(e.$args={}),a),o||e.next()},B=(t,n,e)=>{typeof t=="function"&&t(e),e||n.return()},C=(t,n,e)=>{if(n.contains(document.activeElement)){const o=n.nextSibling;for(;e&&e!=n;){const i=e.nextSibling;t.insertBefore(e,o),e=i}}else t.insertBefore(n,e)},v=t=>{for(const e of t.children)v(e);const{$ref:n}=t;typeof n=="function"&&n(null)};let r=null;const E={render(){r!=null&&r.contains(this)||this.next()},next(){const t=r;r=this;try{d((this.$iterator??(this.$iterator=this.$generator.call(this,this.$args))).next().value,this),typeof this.$ref=="function"&&this.$ref(this)}catch(n){this.throw(n)}finally{r=t}},throw(t){var n;for(let e=this;e;e=e.parentNode)if(typeof((n=e.$iterator)==null?void 0:n.throw)=="function")try{return d(e.$iterator.throw(t).value,e)}catch{}throw t},return(){var t;try{(t=this.$iterator)==null||t.return()}catch(n){this.throw(n)}finally{this.$iterator=null}}},P=(t,n=Symbol())=>function(){const e=this??r;return e?arguments.length===0?n in e.$context?e.$context[n]:t:e.$context[n]=arguments[0]:t};exports.Fragment=S;exports.context=P;exports.h=N;exports.render=d;
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
const F = ({ children: t }) => t, W = function(t, n) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}, d = (t, n) => {
|
|
2
|
+
return (n ?? (n = h(null))).nodeName = t, "children" in n || arguments.length < 3 || (n.children = arguments.length === 3 ? arguments[2] : N.call(arguments, 2)), n;
|
|
3
|
+
}, g = (t, n) => {
|
|
5
4
|
let e = n.firstChild;
|
|
6
|
-
for (t of
|
|
5
|
+
for (t of x(t)) {
|
|
7
6
|
let i = e;
|
|
8
7
|
if (typeof t == "string") {
|
|
9
8
|
for (; i && i.nodeType != 3; ) i = i.nextSibling;
|
|
10
9
|
i ? i.data != t && (i.data = t) : i = document.createTextNode(t);
|
|
11
10
|
} else {
|
|
12
|
-
const { nodeName: o, key:
|
|
13
|
-
for (; i && !(i.localName === o && (i.$key ?? (i.$key =
|
|
14
|
-
if (i ?? (i = m(document.createElementNS(t.xmlns ?? o === "svg" ? b : n.namespaceURI, o), { $key:
|
|
15
|
-
const { $props:
|
|
16
|
-
for (const
|
|
17
|
-
if (A.has(
|
|
18
|
-
const u =
|
|
19
|
-
u !== (
|
|
11
|
+
const { nodeName: o, key: a, skip: c, memo: s, ref: f, children: w } = t;
|
|
12
|
+
for (; i && !(i.localName === o && (i.$key ?? (i.$key = a)) == a); ) i = i.nextSibling;
|
|
13
|
+
if (i ?? (i = m(document.createElementNS(t.xmlns ?? o === "svg" ? b : n.namespaceURI, o), { $key: a })), s == null || O(i.$memo, i.$memo = s)) {
|
|
14
|
+
const { $props: y } = i, $ = {};
|
|
15
|
+
for (const l of p(m({}, y, t))) {
|
|
16
|
+
if (A.has(l)) continue;
|
|
17
|
+
const u = $[l] = t[l];
|
|
18
|
+
u !== (y == null ? void 0 : y[l]) && (l.startsWith("set:") ? i[l.slice(4)] = u : u == null || u === !1 ? i.removeAttribute(l) : i.setAttribute(l, u === !0 ? "" : u));
|
|
20
19
|
}
|
|
21
|
-
i.$props =
|
|
20
|
+
i.$props = $, c || g(w, i), typeof f == "function" && (i.$ref = f)(i);
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
i === e ? e = e.nextSibling : C(n, i, e);
|
|
@@ -27,29 +26,31 @@ const F = ({ children: t }) => t, W = function(t, n) {
|
|
|
27
26
|
const i = e.nextSibling;
|
|
28
27
|
e.nodeType === 1 && v(e), n.removeChild(e), e = i;
|
|
29
28
|
}
|
|
30
|
-
}, { isArray:
|
|
31
|
-
for (t of
|
|
29
|
+
}, { isArray: d, prototype: { slice: N } } = Array, { create: h, assign: m, keys: p, prototype: { hasOwnProperty: S }, hasOwn: k = (t, n) => S.call(t, n) } = Object, b = "http://www.w3.org/2000/svg", A = new Set("nodeName,key,skip,memo,ref,children".split(",")), O = (t, n) => d(t) && d(n) ? t.some((e, i) => e !== n[i]) : t !== n, x = function* (t, n = { value: "" }, e = !0) {
|
|
30
|
+
for (t of d(t) ? t : [t])
|
|
32
31
|
if (!(t == null || typeof t == "boolean"))
|
|
33
32
|
if (k(t, "nodeName")) {
|
|
34
33
|
const { value: i } = n, { nodeName: o } = t;
|
|
35
34
|
if (i && (yield i, n.value = ""), typeof o == "function")
|
|
36
35
|
if (o.constructor.name === "GeneratorFunction") {
|
|
37
|
-
const
|
|
38
|
-
for (const
|
|
39
|
-
const f = t[
|
|
40
|
-
|
|
36
|
+
const a = {}, c = m({}, o.attrs);
|
|
37
|
+
for (const s of p(t)) {
|
|
38
|
+
const f = t[s];
|
|
39
|
+
s.startsWith("attr:") ? c[s.slice(5)] = f : s === "key" || s === "memo" ? c[s] = f : a[s] = f;
|
|
41
40
|
}
|
|
42
|
-
c.nodeName = o.is ?? "div", c.skip = !0, c.ref = T.bind(null, o,
|
|
43
|
-
} else yield*
|
|
41
|
+
c.nodeName = o.is ?? "div", c.skip = !0, c.ref = T.bind(null, o, a), yield c;
|
|
42
|
+
} else yield* x(o(t), n, !1);
|
|
44
43
|
else yield t;
|
|
45
|
-
} else
|
|
44
|
+
} else d(t) ? yield* x(t, n, !1) : n.value += t;
|
|
46
45
|
e && n.value && (yield n.value);
|
|
47
46
|
}, T = (t, n, e) => {
|
|
48
47
|
if (!e) return;
|
|
49
|
-
e.$
|
|
50
|
-
const { skip: i,
|
|
51
|
-
m(e.$args ?? (e.$args = {}),
|
|
52
|
-
}, B = (t, n
|
|
48
|
+
e.$generator ?? (e.$generator = (m(e, E), e.$context ?? (e.$context = h((r == null ? void 0 : r.$context) ?? null)), t));
|
|
49
|
+
const { skip: i, ref: o, ...a } = n;
|
|
50
|
+
e.$ref = B.bind(null, o, e), m(e.$args ?? (e.$args = {}), a), i || e.next();
|
|
51
|
+
}, B = (t, n, e) => {
|
|
52
|
+
typeof t == "function" && t(e), e || n.return();
|
|
53
|
+
}, C = (t, n, e) => {
|
|
53
54
|
if (n.contains(document.activeElement)) {
|
|
54
55
|
const i = n.nextSibling;
|
|
55
56
|
for (; e && e != n; ) {
|
|
@@ -62,46 +63,47 @@ const F = ({ children: t }) => t, W = function(t, n) {
|
|
|
62
63
|
const { $ref: n } = t;
|
|
63
64
|
typeof n == "function" && n(null);
|
|
64
65
|
};
|
|
65
|
-
let
|
|
66
|
+
let r = null;
|
|
66
67
|
const E = {
|
|
67
68
|
render() {
|
|
68
|
-
|
|
69
|
+
r != null && r.contains(this) || this.next();
|
|
69
70
|
},
|
|
70
|
-
|
|
71
|
-
const t =
|
|
72
|
-
|
|
71
|
+
next() {
|
|
72
|
+
const t = r;
|
|
73
|
+
r = this;
|
|
73
74
|
try {
|
|
74
|
-
|
|
75
|
+
g((this.$iterator ?? (this.$iterator = this.$generator.call(this, this.$args))).next().value, this), typeof this.$ref == "function" && this.$ref(this);
|
|
75
76
|
} catch (n) {
|
|
76
|
-
this
|
|
77
|
+
this.throw(n);
|
|
77
78
|
} finally {
|
|
78
|
-
|
|
79
|
+
r = t;
|
|
79
80
|
}
|
|
80
81
|
},
|
|
81
|
-
|
|
82
|
+
throw(t) {
|
|
82
83
|
var n;
|
|
83
|
-
for (let e = this; e; e = e.parentNode) if (typeof ((n = e.$
|
|
84
|
-
return
|
|
84
|
+
for (let e = this; e; e = e.parentNode) if (typeof ((n = e.$iterator) == null ? void 0 : n.throw) == "function") try {
|
|
85
|
+
return g(e.$iterator.throw(t).value, e);
|
|
85
86
|
} catch {
|
|
86
87
|
}
|
|
87
88
|
throw t;
|
|
88
89
|
},
|
|
89
|
-
|
|
90
|
+
return() {
|
|
90
91
|
var t;
|
|
91
92
|
try {
|
|
92
|
-
(t = this.$
|
|
93
|
+
(t = this.$iterator) == null || t.return();
|
|
93
94
|
} catch (n) {
|
|
94
|
-
this
|
|
95
|
+
this.throw(n);
|
|
95
96
|
} finally {
|
|
96
|
-
this.$
|
|
97
|
+
this.$iterator = null;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
}, j = (t, n = Symbol()) => function(
|
|
100
|
-
|
|
100
|
+
}, j = (t, n = Symbol()) => function() {
|
|
101
|
+
const e = this ?? r;
|
|
102
|
+
return e ? arguments.length === 0 ? n in e.$context ? e.$context[n] : t : e.$context[n] = arguments[0] : t;
|
|
101
103
|
};
|
|
102
104
|
export {
|
|
103
105
|
F as Fragment,
|
|
104
106
|
j as context,
|
|
105
107
|
W as h,
|
|
106
|
-
|
|
108
|
+
g as render
|
|
107
109
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ajo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "ajo is a JavaScript view library for building user interfaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"types.ts"
|
|
24
24
|
],
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/node": "^
|
|
27
|
-
"jsdom": "24.1.
|
|
28
|
-
"vite": "5.
|
|
29
|
-
"vitest": "2.0.
|
|
26
|
+
"@types/node": "^22.2.0",
|
|
27
|
+
"jsdom": "24.1.1",
|
|
28
|
+
"vite": "5.4.0",
|
|
29
|
+
"vitest": "2.0.5"
|
|
30
30
|
},
|
|
31
31
|
"keywords": [
|
|
32
32
|
"ui",
|
package/readme.md
CHANGED
|
@@ -264,14 +264,14 @@ const StatelessComponent = () => {
|
|
|
264
264
|
// In a stateful component:
|
|
265
265
|
function* StatefulComponent() {
|
|
266
266
|
while (true) {
|
|
267
|
-
const theme = ThemeContext(
|
|
267
|
+
const theme = ThemeContext()
|
|
268
268
|
yield <div>Current theme: {theme}</div>
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
// Setting context value:
|
|
273
273
|
function* App() {
|
|
274
|
-
ThemeContext(
|
|
274
|
+
ThemeContext('dark')
|
|
275
275
|
while (true) {
|
|
276
276
|
yield (
|
|
277
277
|
<>
|
|
@@ -313,9 +313,9 @@ Component methods:
|
|
|
313
313
|
}
|
|
314
314
|
```
|
|
315
315
|
|
|
316
|
-
- `this
|
|
316
|
+
- `this.next()`: Advances the generator to the next yield point. It's automatically called by `this.render()` and is rarely used directly.
|
|
317
317
|
|
|
318
|
-
- `this
|
|
318
|
+
- `this.throw(error)`: Throws an error in the generator. Useful for error propagation and creating error boundaries. Ajo automatically calls this method when an error occurs during rendering.
|
|
319
319
|
|
|
320
320
|
```javascript
|
|
321
321
|
function* ErrorBoundary(props) {
|
|
@@ -329,14 +329,14 @@ Component methods:
|
|
|
329
329
|
}
|
|
330
330
|
```
|
|
331
331
|
|
|
332
|
-
- `this
|
|
332
|
+
- `this.return()`: Completes the generator execution. It's automatically called by Ajo when a component is unmounted, but can be used manually to reset a component's state.
|
|
333
333
|
|
|
334
334
|
```javascript
|
|
335
335
|
function* ResetableComponent() {
|
|
336
336
|
let count = 0
|
|
337
337
|
const reset = () => {
|
|
338
|
-
this
|
|
339
|
-
this.render()
|
|
338
|
+
this.return() // Reset the generator
|
|
339
|
+
this.render() // Re-render from the beginning
|
|
340
340
|
}
|
|
341
341
|
while (true) {
|
|
342
342
|
yield (
|
|
@@ -360,7 +360,7 @@ Component methods:
|
|
|
360
360
|
}
|
|
361
361
|
```
|
|
362
362
|
|
|
363
|
-
These methods provide powerful control over the component's lifecycle and state management, allowing for efficient and flexible UI updates. Note that `this
|
|
363
|
+
These methods provide powerful control over the component's lifecycle and state management, allowing for efficient and flexible UI updates. Note that `this.throw()` and `this.return()` are often called automatically by Ajo in response to errors or component unmounting, respectively, but can also be used manually when needed.
|
|
364
364
|
|
|
365
365
|
### `ajo/html` module
|
|
366
366
|
|
package/types.ts
CHANGED
|
@@ -4,9 +4,9 @@ declare module 'ajo' {
|
|
|
4
4
|
|
|
5
5
|
type Type = Tag | Function | Component
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type Attrs = Record<string, unknown>
|
|
8
8
|
|
|
9
|
-
type VNode<TTag extends Type> = { nodeName: TTag } &
|
|
9
|
+
type VNode<TTag extends Type> = { nodeName: TTag } & Attrs
|
|
10
10
|
|
|
11
11
|
type Children = any
|
|
12
12
|
|
|
@@ -16,66 +16,56 @@ declare module 'ajo' {
|
|
|
16
16
|
? SVGElementTagNameMap[TTag]
|
|
17
17
|
: never
|
|
18
18
|
|
|
19
|
-
type
|
|
19
|
+
type AjoAttrs<TElement> = {
|
|
20
20
|
key: unknown
|
|
21
21
|
skip: boolean
|
|
22
22
|
memo: unknown
|
|
23
23
|
ref: (el: TElement | null) => void
|
|
24
24
|
} & ElementChildrenAttribute
|
|
25
25
|
|
|
26
|
-
type
|
|
26
|
+
type PropSetter<TTag = Tag> = {
|
|
27
27
|
[K in keyof ElementType<TTag> as `set:${Exclude<K, symbol>}`]: ElementType<TTag>[K]
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
type
|
|
31
|
-
[
|
|
30
|
+
type AttrSetter = {
|
|
31
|
+
[key: `attr:${string}`]: unknown
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
type
|
|
34
|
+
type Function<TArguments extends Attrs = Attrs> = (args: TArguments) => Children
|
|
35
|
+
|
|
36
|
+
type Component<TArguments extends Attrs = Attrs, TTag extends Tag = 'div'> = {
|
|
37
|
+
(this: ComponentElement<TArguments, TTag>, args: ComponentProps<TArguments, TTag>): Iterator<Children, unknown, unknown>
|
|
38
|
+
} & (TTag extends 'div' ? { is?: TTag } : { is: TTag })
|
|
39
|
+
|
|
40
|
+
type ComponentProps<TArguments extends Attrs = Attrs, TTag extends Tag = 'div'> =
|
|
41
|
+
Partial<PropSetter<TTag> & AjoAttrs<ComponentElement<TArguments, TTag>>> &
|
|
42
|
+
AttrSetter &
|
|
43
|
+
TArguments
|
|
44
|
+
|
|
45
|
+
type ComponentElement<TArguments extends Attrs = Attrs, TTag extends Tag = Tag> = ElementType<TTag> & {
|
|
35
46
|
$args: TArguments,
|
|
36
47
|
$context: { [key: symbol]: unknown },
|
|
37
48
|
render: () => void,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
next: () => void
|
|
50
|
+
throw: (value?: unknown) => void
|
|
51
|
+
return: () => void
|
|
41
52
|
}
|
|
42
53
|
|
|
43
|
-
type Function<TArguments = Props> = (args: TArguments) => Children
|
|
44
|
-
|
|
45
|
-
type Component<TArguments = Props, TTag extends Tag = 'div'> = {
|
|
46
|
-
(this: ElementType<TTag> & ComponentThis<TArguments>, args: TArguments): Iterator<Children, unknown, unknown>
|
|
47
|
-
} & (TTag extends 'div' ? { is?: TTag } : { is: TTag })
|
|
48
|
-
|
|
49
|
-
type Ref<TComponent> = TComponent extends Component<infer TArguments, infer TTag>
|
|
50
|
-
? Component<TArguments & { ref: (el: ThisParameterType<Ref<TComponent>> | null) => void }, TTag>
|
|
51
|
-
: never
|
|
52
|
-
|
|
53
54
|
type IntrinsicElements = {
|
|
54
|
-
[TTag in Tag]: Partial<
|
|
55
|
+
[TTag in Tag]: Partial<PropSetter<TTag> & AjoAttrs<ElementType<TTag>>> & Attrs
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
type IntrinsicAttributes = Partial<Omit<AjoProps<ElementType<Tag>>, 'skip' | 'ref'>> & AttrProps
|
|
58
|
-
|
|
59
58
|
type ElementChildrenAttribute = { children: Children }
|
|
60
59
|
|
|
61
|
-
type TagProps<TTag extends Type> = TTag extends Tag
|
|
62
|
-
? IntrinsicElements[TTag] & IntrinsicAttributes
|
|
63
|
-
: TTag extends Function<infer TArguments>
|
|
64
|
-
? TArguments
|
|
65
|
-
: TTag extends Component<infer TArguments>
|
|
66
|
-
? TArguments
|
|
67
|
-
: never
|
|
68
|
-
|
|
69
60
|
function Fragment({ children }: ElementChildrenAttribute): typeof children
|
|
70
|
-
function h<TTag extends Tag>(tag: TTag, props?:
|
|
61
|
+
function h<TTag extends Tag>(tag: TTag, props?: Attrs | null, ...children: Array<unknown>): VNode<TTag>
|
|
71
62
|
function render(h: Children, el: Element): void
|
|
72
|
-
function context<T>(fallback?: T): (
|
|
63
|
+
function context<T>(fallback?: T): (value?: T) => T
|
|
73
64
|
}
|
|
74
65
|
|
|
75
66
|
declare namespace JSX {
|
|
76
67
|
type ElementChildrenAttribute = import('ajo').ElementChildrenAttribute
|
|
77
68
|
type IntrinsicElements = import('ajo').IntrinsicElements
|
|
78
|
-
type IntrinsicAttributes = import('ajo').IntrinsicAttributes
|
|
79
69
|
}
|
|
80
70
|
|
|
81
71
|
declare namespace React {
|