ajo 0.0.20 → 0.0.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/index.cjs +25 -21
- package/index.js +20 -22
- package/index.min.js +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -33,10 +33,12 @@ __export(ajo_exports, {
|
|
|
33
33
|
stx: () => stx
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(ajo_exports);
|
|
36
|
-
const Fragment = ({ children }) => children, For = ({ is, each, by, children, ref, ...props }) => h(is ?? "div", {
|
|
36
|
+
const Fragment = ({ children }) => children, For = ({ is, key, block, each, by, children, ref, ...props }) => h(is ?? "div", {
|
|
37
37
|
...props,
|
|
38
|
+
key,
|
|
39
|
+
block,
|
|
38
40
|
skip: true,
|
|
39
|
-
ref:
|
|
41
|
+
ref: iterate.bind(null, each, by, children, ref)
|
|
40
42
|
}), h = (nodeName, props, ...children) => {
|
|
41
43
|
const { length } = children;
|
|
42
44
|
children = length == 0 ? null : length == 1 ? children[0] : children;
|
|
@@ -66,14 +68,16 @@ const Fragment = ({ children }) => children, For = ({ is, each, by, children, re
|
|
|
66
68
|
}
|
|
67
69
|
while (child) {
|
|
68
70
|
const next = child.nextSibling;
|
|
69
|
-
host.removeChild(child);
|
|
71
|
+
dispose(host.removeChild(child));
|
|
70
72
|
child = next;
|
|
71
73
|
}
|
|
72
|
-
}, component = (setup) => ({ is, props, ref, ...params }) => h(is ?? setup.is ?? "div", {
|
|
74
|
+
}, component = (setup) => ({ is, props, key, block, ref, ...params }) => h(is ?? setup.is ?? "div", {
|
|
73
75
|
...setup.props,
|
|
74
76
|
...props,
|
|
77
|
+
key,
|
|
78
|
+
block,
|
|
75
79
|
skip: true,
|
|
76
|
-
ref:
|
|
80
|
+
ref: run.bind(null, setup, params, ref)
|
|
77
81
|
}), refresh = (host) => {
|
|
78
82
|
try {
|
|
79
83
|
render((host.$render ??= host.$setup(host))(host.$params), host);
|
|
@@ -138,11 +142,14 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
|
|
|
138
142
|
}
|
|
139
143
|
} else
|
|
140
144
|
host.insertBefore(node, child);
|
|
141
|
-
}, iterate = (
|
|
145
|
+
}, iterate = (each, by, fn, ref, host) => {
|
|
142
146
|
each = isArray(each) ? each : [];
|
|
143
147
|
by = isFunction(by) ? by : (v) => v;
|
|
144
148
|
fn = isFunction(fn) ? fn : noop;
|
|
145
|
-
const map2 = host.$for ??= /* @__PURE__ */ new Map(), del = (node) =>
|
|
149
|
+
const map2 = host.$for ??= /* @__PURE__ */ new Map(), del = (node) => {
|
|
150
|
+
map2.delete(node.$by);
|
|
151
|
+
dispose(node);
|
|
152
|
+
}, clr = each !== host.$each, len = (host.$each = each).length, a = from(host.childNodes), b = new Array(len);
|
|
146
153
|
clr && map2.clear();
|
|
147
154
|
for (let child, index = 0; index < len; index++) {
|
|
148
155
|
const item = each[index], key = by(item, index);
|
|
@@ -182,22 +189,19 @@ const { isArray, from } = Array, { keys, entries } = Object, isFunction = (v) =>
|
|
|
182
189
|
}
|
|
183
190
|
}
|
|
184
191
|
}
|
|
185
|
-
}, run = (
|
|
186
|
-
host.$setup ??=
|
|
192
|
+
}, run = (setup, params, ref, host) => {
|
|
193
|
+
host.$setup ??= isFunction(setup) ? setup : noop;
|
|
187
194
|
host.$params = { ...setup.params, ...params };
|
|
188
195
|
refresh(host);
|
|
189
196
|
isFunction(ref) && ref(host);
|
|
190
|
-
}, dispose = (
|
|
191
|
-
(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
target.$cleanups.clear();
|
|
200
|
-
}
|
|
197
|
+
}, dispose = (host) => {
|
|
198
|
+
if (host.nodeType != 1)
|
|
199
|
+
return;
|
|
200
|
+
for (const child of host.children)
|
|
201
|
+
dispose(child);
|
|
202
|
+
if ("$cleanups" in host)
|
|
203
|
+
for (const fn of host.$cleanups) {
|
|
204
|
+
host.$cleanups.delete(fn);
|
|
205
|
+
fn(host);
|
|
201
206
|
}
|
|
202
|
-
});
|
|
203
207
|
};
|
package/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const
|
|
2
2
|
Fragment = ({ children }) => children,
|
|
3
3
|
|
|
4
|
-
For = ({ is, each, by, children, ref, ...props }) => h(is ?? 'div', {
|
|
5
|
-
...props, skip: true, ref:
|
|
4
|
+
For = ({ is, key, block, each, by, children, ref, ...props }) => h(is ?? 'div', {
|
|
5
|
+
...props, key, block, skip: true, ref: iterate.bind(null, each, by, children, ref)
|
|
6
6
|
}),
|
|
7
7
|
|
|
8
8
|
h = (nodeName, props, ...children) => {
|
|
@@ -45,13 +45,13 @@ export const
|
|
|
45
45
|
|
|
46
46
|
while (child) {
|
|
47
47
|
const next = child.nextSibling
|
|
48
|
-
host.removeChild(child)
|
|
48
|
+
dispose(host.removeChild(child))
|
|
49
49
|
child = next
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
|
|
53
|
-
component = setup => ({ is, props, ref, ...params }) => h(is ?? setup.is ?? 'div', {
|
|
54
|
-
...setup.props, ...props, skip: true, ref:
|
|
53
|
+
component = setup => ({ is, props, key, block, ref, ...params }) => h(is ?? setup.is ?? 'div', {
|
|
54
|
+
...setup.props, ...props, key, block, skip: true, ref: run.bind(null, setup, params, ref)
|
|
55
55
|
}),
|
|
56
56
|
|
|
57
57
|
refresh = host => {
|
|
@@ -97,7 +97,7 @@ const
|
|
|
97
97
|
|
|
98
98
|
create = (ns, name, key) => {
|
|
99
99
|
const node = ns ? document.createElementNS(ns, name) : document.createElement(name)
|
|
100
|
-
return node.$key = key, node
|
|
100
|
+
return ((node.$key = key), node)
|
|
101
101
|
},
|
|
102
102
|
|
|
103
103
|
proxy = { firstChild: null, insertBefore: node => proxy.firstChild ??= node }, handler = {
|
|
@@ -155,7 +155,7 @@ const
|
|
|
155
155
|
} else host.insertBefore(node, child)
|
|
156
156
|
},
|
|
157
157
|
|
|
158
|
-
iterate = (
|
|
158
|
+
iterate = (each, by, fn, ref, host) => {
|
|
159
159
|
|
|
160
160
|
each = isArray(each) ? each : []
|
|
161
161
|
by = isFunction(by) ? by : v => v
|
|
@@ -163,7 +163,10 @@ const
|
|
|
163
163
|
|
|
164
164
|
const
|
|
165
165
|
map = host.$for ??= new Map,
|
|
166
|
-
del = node =>
|
|
166
|
+
del = node => {
|
|
167
|
+
map.delete(node.$by)
|
|
168
|
+
dispose(node)
|
|
169
|
+
},
|
|
167
170
|
clr = each !== host.$each,
|
|
168
171
|
len = (host.$each = each).length,
|
|
169
172
|
a = from(host.childNodes),
|
|
@@ -222,25 +225,20 @@ const
|
|
|
222
225
|
}
|
|
223
226
|
},
|
|
224
227
|
|
|
225
|
-
run = (
|
|
228
|
+
run = (setup, params, ref, host) => {
|
|
226
229
|
|
|
227
|
-
host.$setup ??=
|
|
230
|
+
host.$setup ??= isFunction(setup) ? setup : noop
|
|
228
231
|
host.$params = { ...setup.params, ...params }
|
|
229
232
|
|
|
230
233
|
refresh(host)
|
|
231
234
|
isFunction(ref) && ref(host)
|
|
232
235
|
},
|
|
233
236
|
|
|
234
|
-
dispose =
|
|
235
|
-
(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
} finally {
|
|
242
|
-
target.$cleanups.clear()
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
})
|
|
237
|
+
dispose = host => {
|
|
238
|
+
if (host.nodeType != 1) return
|
|
239
|
+
for (const child of host.children) dispose(child)
|
|
240
|
+
if ('$cleanups' in host) for (const fn of host.$cleanups) {
|
|
241
|
+
host.$cleanups.delete(fn)
|
|
242
|
+
fn(host)
|
|
243
|
+
}
|
|
246
244
|
}
|
package/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ajo=(()=>{var
|
|
1
|
+
var ajo=(()=>{var x=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var L=(e,n)=>{for(var l in n)x(e,l,{get:n[l],enumerable:!0})},T=(e,n,l,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of E(n))!F.call(e,t)&&t!==l&&x(e,t,{get:()=>n[t],enumerable:!(i=B(n,t))||i.enumerable});return e};var z=e=>T(x({},"__esModule",{value:!0}),e);var re={};L(re,{For:()=>R,Fragment:()=>I,cleanup:()=>Z,clx:()=>q,component:()=>V,consume:()=>P,h:()=>b,intercept:()=>W,keb:()=>G,propagate:()=>A,provide:()=>O,refresh:()=>k,render:()=>g,stx:()=>D});const I=({children:e})=>e,R=({is:e,key:n,block:l,each:i,by:t,children:s,ref:r,...o})=>b(e??"div",{...o,key:n,block:l,skip:!0,ref:le.bind(null,i,t,s,r)}),b=(e,n,...l)=>{const{length:i}=l;return l=i==0?null:i==1?l[0]:l,{children:l,...n,nodeName:e}},g=(e,n,l)=>{let i=n.firstChild;for(e of y(e)){let t=i;if(e instanceof Node)t=e;else if(typeof e=="string"){for(;t&&t.nodeType!=3;)t=t.nextSibling;t?t.data!=e&&(t.data=e):t=document.createTextNode(e)}else{const{xmlns:s=l,nodeName:r,key:o,block:c,skip:f,children:u,ref:a,...d}=e;for(;t&&!(t.localName==r&&(t.$key??=o)==o);)t=t.nextSibling;t??=X(s,r,o),(c==null||K(t.$deps,t.$deps=c))&&(ee(d,t),f||g(u,t,s),p(a)&&a(t))}t==i?i=i.nextSibling:ne(n,t,i)}for(;i;){const t=i.nextSibling;v(n.removeChild(i)),i=t}},V=e=>({is:n,props:l,key:i,block:t,ref:s,...r})=>b(n??e.is??"div",{...e.props,...l,key:i,block:t,skip:!0,ref:te.bind(null,e,r,s)}),k=e=>{try{g((e.$render??=e.$setup(e))(e.$params),e)}catch(n){A(e,n)}},O=(e,n,l)=>(e.$provisions??=new Map).set(n,l),P=(e,n,l)=>{for(let i;e;e=e.parentNode)if((i=e.$provisions)&&i.has(n))return i.get(n);return l},W=(e,n)=>p(n)&&(e.$interceptor=n),A=(e,n)=>{for(let l;e;e=e.parentNode)if(p(l=e.$interceptor))return g(l(n),e);throw n},Z=(e,n)=>p(n)&&(e.$cleanups??=new Set).add(n),q=e=>j(e).filter(n=>e[n]).join(" ")||null,D=e=>H(e).map(n=>n.join(":")).join(";")||null,G=e=>j(e).reduce((n,l)=>(n[l.replace(_,h).toLowerCase()]=e[l],n),{}),{isArray:$,from:M}=Array,{keys:j,entries:H}=Object,p=e=>typeof e=="function",w=()=>{},S=e=>e.reduce(J,new Map),J=(e,n,l)=>(e.set(n,l),e),K=(e,n)=>$(e)&&$(n)?e.some((l,i)=>l!==n[i]):e!==n,Q=e=>M(e).reduce(U,{}),U=(e,{name:n,value:l})=>(e[n]=l,e),X=(e,n,l)=>{const i=e?document.createElementNS(e,n):document.createElement(n);return i.$key=l,i},m={firstChild:null,insertBefore:e=>m.firstChild??=e},Y={get(e,n){const l=n=="nextSibling"?null:Reflect.get(e,n);return p(l)?l.bind(e):l},set(e,n,l){return Reflect.set(e,n,l)}},_=/([a-z0-9])([A-Z])/g,h="$1-$2",y=function*(e,n={t:""},l=!0){let i;for(e of $(e)?e:[e])e==null||typeof e=="boolean"||(typeof e.nodeName=="string"?((i=n.t)&&(n.t="",yield i),yield e):p(e.nodeName)?yield*y(e.nodeName(e),n,!1):$(e)?yield*y(e,n,!1):n.t+=e);l&&(i=n.t)&&(yield i)},ee=(e,n)=>{const l=n.$props??=n.hasAttributes()?Q(n.attributes):{};for(const i in{...l,...n.$props=e}){let t=e[i];t!==l[i]&&(i.startsWith("set:")?n[i.slice(4)]=t:t==null||t===!1?n.removeAttribute(i):n.setAttribute(i,t===!0?"":t))}},ne=(e,n,l)=>{if(n.contains?.(document.activeElement)){const i=n.nextSibling;for(;l&&l!=n;){const t=l.nextSibling;e.insertBefore(l,i),l=t}}else e.insertBefore(n,l)},le=(e,n,l,i,t)=>{e=$(e)?e:[],n=p(n)?n:a=>a,l=p(l)?l:w;const s=t.$for??=new Map,r=a=>{s.delete(a.$by),v(a)},o=e!==t.$each,c=(t.$each=e).length,f=M(t.childNodes),u=new Array(c);o&&s.clear();for(let a,d=0;d<c;d++){const C=e[d],N=n(C,d);a=o?f[d]:s.get(N),m.firstChild=a?new Proxy(a,Y):null,g(l(C,d),m),a??=m.firstChild,m.firstChild=null,s.set(a.$by=N,u[d]=a)}ie(t,f,u,r),p(i)&&i(t)},ie=(e,n,l,i=w)=>{const t=n.length,s=l.length;let r=0,o=0,c,f,u,a,d;for(;r!==t||o!==s;)c=n[r],f=l[o],c===null?r++:s<=o?(r++,i(e.removeChild(c))):t<=r?(o++,e.appendChild(f)):c===f?(r++,o++):(u??=S(n),a??=S(l),a.get(c)==null?(r++,i(e.removeChild(c))):(e.insertBefore(f,c),o++,(d=u.get(f))!=null&&(d>r+1&&r++,n[d]=null)))},te=(e,n,l,i)=>{i.$setup??=p(e)?e:w,i.$params={...e.params,...n},k(i),p(l)&&l(i)},v=e=>{if(e.nodeType==1){for(const n of e.children)v(n);if("$cleanups"in e)for(const n of e.$cleanups)e.$cleanups.delete(n),n(e)}};return z(re);})();
|