sprae 2.10.0 → 2.10.1
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/package.json +1 -1
- package/sprae.js +59 -39
- package/sprae.min.js +1 -1
- package/src/directives.js +6 -4
- package/src/domdiff.js +68 -0
- package/test/index.html +2 -0
- package/test/test.js +13 -0
package/package.json
CHANGED
package/sprae.js
CHANGED
|
@@ -434,37 +434,57 @@ function isObject(v2) {
|
|
|
434
434
|
return v2 && v2.constructor === Object;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
-
//
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
437
|
+
// src/domdiff.js
|
|
438
|
+
function domdiff_default(parent, a2, b2, before) {
|
|
439
|
+
const aIdx = /* @__PURE__ */ new Map();
|
|
440
|
+
const bIdx = /* @__PURE__ */ new Map();
|
|
441
|
+
let i2;
|
|
442
|
+
let j;
|
|
443
|
+
for (i2 = 0; i2 < a2.length; i2++) {
|
|
444
|
+
aIdx.set(a2[i2], i2);
|
|
445
|
+
}
|
|
446
|
+
for (i2 = 0; i2 < b2.length; i2++) {
|
|
447
|
+
bIdx.set(b2[i2], i2);
|
|
448
|
+
}
|
|
449
|
+
for (i2 = j = 0; i2 !== a2.length || j !== b2.length; ) {
|
|
450
|
+
var aElm = a2[i2], bElm = b2[j];
|
|
451
|
+
if (aElm === null) {
|
|
452
|
+
i2++;
|
|
453
|
+
} else if (b2.length <= j) {
|
|
454
|
+
parent.removeChild(a2[i2]);
|
|
455
|
+
i2++;
|
|
456
|
+
} else if (a2.length <= i2) {
|
|
457
|
+
parent.insertBefore(bElm, a2[i2] || before);
|
|
458
|
+
j++;
|
|
459
|
+
} else if (aElm === bElm) {
|
|
460
|
+
i2++;
|
|
461
|
+
j++;
|
|
462
|
+
} else {
|
|
463
|
+
var curElmInNew = bIdx.get(aElm);
|
|
464
|
+
var wantedElmInOld = aIdx.get(bElm);
|
|
465
|
+
if (curElmInNew === void 0) {
|
|
466
|
+
parent.removeChild(a2[i2]);
|
|
467
|
+
i2++;
|
|
468
|
+
} else if (wantedElmInOld === void 0) {
|
|
469
|
+
parent.insertBefore(
|
|
470
|
+
bElm,
|
|
471
|
+
a2[i2] || before
|
|
472
|
+
);
|
|
473
|
+
j++;
|
|
474
|
+
} else {
|
|
475
|
+
parent.insertBefore(
|
|
476
|
+
a2[wantedElmInOld],
|
|
477
|
+
a2[i2] || before
|
|
478
|
+
);
|
|
479
|
+
a2[wantedElmInOld] = null;
|
|
480
|
+
if (wantedElmInOld > i2 + 1)
|
|
481
|
+
i2++;
|
|
482
|
+
j++;
|
|
483
|
+
}
|
|
457
484
|
}
|
|
458
|
-
while (!same(cur, end))
|
|
459
|
-
next = cur.nextSibling, remove(cur, parent), cur = next;
|
|
460
485
|
}
|
|
461
486
|
return b2;
|
|
462
|
-
}
|
|
463
|
-
swap.same = (a2, b2) => a2 == b2;
|
|
464
|
-
swap.replace = (a2, b2, parent) => parent.replaceChild(b2, a2);
|
|
465
|
-
swap.insert = (a2, b2, parent) => parent.insertBefore(b2, a2);
|
|
466
|
-
swap.remove = (a2, parent) => parent.removeChild(a2);
|
|
467
|
-
var swap_inflate_default = swap;
|
|
487
|
+
}
|
|
468
488
|
|
|
469
489
|
// node_modules/primitive-pool/index.js
|
|
470
490
|
var cache = {};
|
|
@@ -562,7 +582,7 @@ primary["each"] = (tpl, expr) => {
|
|
|
562
582
|
scope[each[0]] = item;
|
|
563
583
|
elScopes.push(scope);
|
|
564
584
|
}
|
|
565
|
-
|
|
585
|
+
domdiff_default(holder.parentNode, curEls, newEls, holder);
|
|
566
586
|
curEls = newEls;
|
|
567
587
|
for (let i2 = 0; i2 < newEls.length; i2++) {
|
|
568
588
|
sprae(newEls[i2], elScopes[i2]);
|
|
@@ -725,6 +745,16 @@ var removeListener = (el, evt, fn) => {
|
|
|
725
745
|
el.removeEventListener(evt, fn);
|
|
726
746
|
};
|
|
727
747
|
var mods = {
|
|
748
|
+
prevent({ hooks }) {
|
|
749
|
+
hooks.push((e3) => {
|
|
750
|
+
e3.preventDefault();
|
|
751
|
+
});
|
|
752
|
+
},
|
|
753
|
+
stop({ hooks }) {
|
|
754
|
+
hooks.push((e3) => {
|
|
755
|
+
e3.stopPropagation();
|
|
756
|
+
});
|
|
757
|
+
},
|
|
728
758
|
throttle(opts, limit) {
|
|
729
759
|
let { fn } = opts;
|
|
730
760
|
limit = Number(limit) || 108;
|
|
@@ -771,16 +801,6 @@ var mods = {
|
|
|
771
801
|
return false;
|
|
772
802
|
});
|
|
773
803
|
},
|
|
774
|
-
prevent({ hooks }) {
|
|
775
|
-
hooks.push((e3) => {
|
|
776
|
-
e3.preventDefault();
|
|
777
|
-
});
|
|
778
|
-
},
|
|
779
|
-
stop({ hooks }) {
|
|
780
|
-
hooks.push((e3) => {
|
|
781
|
-
e3.stopPropagation();
|
|
782
|
-
});
|
|
783
|
-
},
|
|
784
804
|
self({ target, hooks }) {
|
|
785
805
|
hooks.push((e3) => {
|
|
786
806
|
return e3.target === target;
|
package/sprae.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(){throw new Error("Cycle detected")}function r(){if(n>1)n--;else{for(var t,e=!1;void 0!==o;){var r=o;for(o=void 0,s++;void 0!==r;){var i=r.o;if(r.o=void 0,r.f&=-3,!(8&r.f)&&f(r))try{r.c()}catch(r){e||(t=r,e=!0)}r=i}}if(s=0,n--,e)throw t}}var i=void 0,o=void 0,n=0,s=0,l=0;function a(t){if(void 0!==i){var e=t.n;if(void 0===e||e.t!==i)return i.s=e={i:0,S:t,p:void 0,n:i.s,t:i,e:void 0,x:void 0,r:e},t.n=e,32&i.f&&t.S(e),e;if(-1===e.i)return e.i=0,void 0!==e.p&&(e.p.n=e.n,void 0!==e.n&&(e.n.p=e.p),e.p=void 0,e.n=i.s,i.s.p=e,i.s=e),e}}function u(t){this.v=t,this.i=0,this.n=void 0,this.t=void 0}function f(t){for(var e=t.s;void 0!==e;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function h(t){for(var e=t.s;void 0!==e;e=e.n){var r=e.S.n;void 0!==r&&(e.r=r),e.S.n=e,e.i=-1}}function c(t){for(var e=t.s,r=void 0;void 0!==e;){var i=e.n;-1===e.i?(e.S.U(e),e.n=void 0):(void 0!==r&&(r.p=e),e.p=void 0,e.n=r,r=e),e.S.n=e.r,void 0!==e.r&&(e.r=void 0),e=i}t.s=r}function v(t){u.call(this,void 0),this.x=t,this.s=void 0,this.g=l-1,this.f=4}function p(t){var e=t.u;if(t.u=void 0,"function"==typeof e){n++;var o=i;i=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,d(t),e}finally{i=o,r()}}}function d(t){for(var e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,p(t)}function y(t){if(i!==this)throw new Error("Out-of-order effect");c(this),i=t,this.f&=-2,8&this.f&&d(this),r()}function b(t){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}function g(t){var e=new b(t);return e.c(),e.d.bind(e)}u.prototype.h=function(){return!0},u.prototype.S=function(t){this.t!==t&&void 0===t.e&&(t.x=this.t,void 0!==this.t&&(this.t.e=t),this.t=t)},u.prototype.U=function(t){var e=t.e,r=t.x;void 0!==e&&(e.x=r,t.e=void 0),void 0!==r&&(r.e=e,t.x=void 0),t===this.t&&(this.t=r)},u.prototype.subscribe=function(t){var e=this;return g((function(){var r=e.value,i=32&this.f;this.f&=-33;try{t(r)}finally{this.f|=i}}))},u.prototype.valueOf=function(){return this.value},u.prototype.toString=function(){return this.value+""},u.prototype.peek=function(){return this.v},Object.defineProperty(u.prototype,"value",{get:function(){var t=a(this);return void 0!==t&&(t.i=this.i),this.v},set:function(e){if(e!==this.v){s>100&&t(),this.v=e,this.i++,l++,n++;try{for(var i=this.t;void 0!==i;i=i.x)i.t.N()}finally{r()}}}}),(v.prototype=new u).h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===l)return!0;if(this.g=l,this.f|=1,this.i>0&&!f(this))return this.f&=-2,!0;var t=i;try{h(this),i=this;var e=this.x();(16&this.f||this.v!==e||0===this.i)&&(this.v=e,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return i=t,c(this),this.f&=-2,!0},v.prototype.S=function(t){if(void 0===this.t){this.f|=36;for(var e=this.s;void 0!==e;e=e.n)e.S.S(e)}u.prototype.S.call(this,t)},v.prototype.U=function(t){if(u.prototype.U.call(this,t),void 0===this.t){this.f&=-33;for(var e=this.s;void 0!==e;e=e.n)e.S.U(e)}},v.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;void 0!==t;t=t.x)t.t.N()}},v.prototype.peek=function(){if(this.h()||t(),16&this.f)throw this.v;return this.v},Object.defineProperty(v.prototype,"value",{get:function(){1&this.f&&t();var e=a(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),b.prototype.c=function(){var t=this.S();try{8&this.f||void 0===this.x||(this.u=this.x())}finally{t()}},b.prototype.S=function(){1&this.f&&t(),this.f|=1,this.f&=-9,p(this),h(this),n++;var e=i;return i=this,y.bind(this,e)},b.prototype.N=function(){2&this.f||(this.f|=2,this.o=o,o=this)},b.prototype.d=function(){this.f|=8,1&this.f||d(this)},Symbol.observable||=Symbol("observable");var m=new FinalizationRegistry((t=>t.call?.())),k=(t,e,r,i,o,n)=>{return t&&(s=(t[Symbol.observable]?.()||t).subscribe?.(e,r,i),n=s&&(()=>s.unsubscribe?.())||t.set&&t.call?.(o,e)||(t.then?.((t=>(!o&&e(t),i?.())),r)||(async n=>{try{for await(n of t){if(o)return;e(n)}i?.()}catch(t){r?.(t)}})())&&(t=>o=1),m.register(t,n),n);var s},S=t=>t&&t[w],w=Symbol("signal-struct");function A(t,e){if(S(t)&&!e)return t;if(x(t)){const o=Object.create(e||Object.getPrototypeOf(t)),n={},s=Object.getOwnPropertyDescriptors(t);for(let t in s){let e=s[t];if(e.get){let r=n[t]=new v(e.get.bind(o));Object.defineProperty(o,t,{get:()=>r.value,set:e.set?.bind(o),configurable:!1,enumerable:!0})}else{let s=e.value,l=(i=s)&&!!(i[Symbol.observable]||i[Symbol.asyncIterator]||i.call&&i.set||i.subscribe||i.then),a=n[t]=(r=s)&&r.peek?s:new u(l?void 0:x(s)?Object.seal(A(s)):Array.isArray(s)?A(s):s);l&&k(s,(t=>a.value=t)),Object.defineProperty(o,t,{get:()=>a.value,set(t){if(x(t)){if(x(a.value))try{return void Object.assign(a.value,t)}catch(t){}a.value=Object.seal(A(t))}else Array.isArray(t)?a.value=A(t):a.value=t},enumerable:!0,configurable:!1})}}return Object.defineProperty(o,w,{configurable:!1,enumerable:!1,value:!0}),o}var r,i;if(Array.isArray(t)&&!S(t[0]))for(let e=0;e<t.length;e++)t[e]=A(t[e]);return t}function x(t){return t&&t.constructor===Object}A.isStruct=S;var O=(t,e,r,i=null)=>{let o,n,s,l=0,a=r.length,u=e.length,{remove:f,same:h,insert:c,replace:v}=O;for(;l<a&&l<u&&h(e[l],r[l]);)l++;for(;l<a&&l<u&&h(r[a-1],e[u-1]);)i=r[(--u,--a)];if(l==u)for(;l<a;)c(i,r[l++],t);else{for(o=e[l];l<a;)s=r[l++],n=o?o.nextSibling:i,h(o,s)?o=n:l<a&&h(r[l],n)?(v(o,s,t),o=n):c(o,s,t);for(;!h(o,i);)n=o.nextSibling,f(o,t),o=n}return r};O.same=(t,e)=>t==e,O.replace=(t,e,r)=>r.replaceChild(e,t),O.insert=(t,e,r)=>r.insertBefore(e,t),O.remove=(t,e)=>e.removeChild(t);var j=O,N={},E={},W={},C=t=>null===t?E:void 0===t?W:"number"==typeof t||t instanceof Number?N[t]||(N[t]=new Number(t)):"string"==typeof t||t instanceof String?N[t]||(N[t]=new String(t)):"boolean"==typeof t||t instanceof Boolean?N[t]||(N[t]=new Boolean(t)):t,T={},$={};T.if=(t,e)=>{let r=document.createTextNode(""),i=[z(t,e,":if")],o=[t],n=t;for(;(n=t.nextElementSibling)&&n.hasAttribute(":else");)n.removeAttribute(":else"),(e=n.getAttribute(":if"))?(n.removeAttribute(":if"),n.remove(),o.push(n),i.push(z(t,e,":else :if"))):(n.remove(),o.push(n),i.push((()=>1)));return t.replaceWith(n=r),t=>{let e=i.findIndex((e=>e(t)));o[e]!=n&&((n[P]||n).replaceWith(n=o[e]||r),H(n,t))}},T.with=(t,e,r)=>{H(t,A(z(t,e,"with")(r),r))};var P=Symbol(":each");T.each=(t,e)=>{let r=function(t){let e=/,([^,\}\]]*)(?:,([^,\}\]]*))?$/,r=t.match(/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/);if(!r)return;let i=r[2].trim(),o=r[1].replace(/^\s*\(|\)\s*$/g,"").trim(),n=o.match(e);return n?[o.replace(e,"").trim(),n[1].trim(),i]:[o,"",i]}(e);if(!r)return F(new Error,t,e);const i=t[P]=document.createTextNode("");t.replaceWith(i);const o=z(t,r[2],":each"),n=t.getAttribute(":key"),s=n?z(null,n):null;t.removeAttribute(":key");const l=new WeakMap,a=new WeakMap;let u=[];return n=>{let f=o(n);f?"number"==typeof f?f=Array.from({length:f},((t,e)=>[e,e+1])):Array.isArray(f)?f=f.map(((t,e)=>[e+1,t])):"object"==typeof f?f=Object.entries(f):F(Error("Bad list value"),t,e,":each"):f=[];let h=[],c=[];for(let[e,i]of f){let o,u,f=s?.({[r[0]]:i,[r[1]]:e});("string"==typeof(v=f)||"boolean"==typeof v||"number"==typeof v)&&(f=C(f)),null==f?o=t.cloneNode(!0):(o=a.get(f))||a.set(f,o=t.cloneNode(!0)),h.push(o),null!=f&&(u=l.get(f))?u[r[0]]=i:(u=A({[r[0]]:i,[r[1]]:e},n),null!=f&&l.set(f,u)),c.push(u)}var v;j(i.parentNode,u,h,i),u=h;for(let t=0;t<h.length;t++)H(h[t],c[t])}},$.ref=(t,e,r)=>{r[e]=t},$.id=(t,e)=>{let r=z(t,e,":id");return e=>{return i=r(e),t.id=i||0===i?i:"";var i}},$.class=(t,e)=>{let r=z(t,e,":class"),i=t.className;return e=>{let o=r(e);t.className=i+typeof o=="string"?o:(Array.isArray(o)?o:Object.entries(o).map((([t,e])=>e?t:""))).filter(Boolean).join(" ")}},$.style=(t,e)=>{let r=z(t,e,":style"),i=t.getAttribute("style")||"";return i.endsWith(";")||(i+="; "),e=>{let o=r(e);if("string"==typeof o)t.setAttribute("style",i+o);else for(let e in o)t.style[e]=o[e]}},$.text=(t,e)=>{let r=z(t,e,":text");return e=>{let i=r(e);t.textContent=null==i?"":i}},$.data=(t,e)=>{let r=z(t,e,":data");return e=>{let i=r(e);for(let e in i)t.dataset[e]=i[e]}},$.aria=(t,e)=>{let r=z(t,e,":aria");return e=>(e=>{for(let r in e)_(t,"aria-"+I(r),null==e[r]?null:e[r]+"")})(r(e))},$[""]=(t,e)=>{let r=z(t,e,":");if(r)return e=>{let i=r(e);for(let e in i)_(t,I(e),i[e])}},$.value=(t,e)=>{let r,i,o=z(t,e,":value"),n="text"===t.type||""===t.type?e=>t.setAttribute("value",t.value=null==e?"":e):"TEXTAREA"===t.tagName||"text"===t.type||""===t.type?e=>(r=t.selectionStart,i=t.selectionEnd,t.setAttribute("value",t.value=null==e?"":e),r&&t.setSelectionRange(r,i)):"checkbox"===t.type?e=>(t.value=e?"on":"",_(t,"checked",e)):"select-one"===t.type?e=>{for(let e in t.options)e.removeAttribute("selected");t.value=e,t.selectedOptions[0]?.setAttribute("selected","")}:e=>t.value=e;return t=>n(o(t))},$.on=(t,e)=>{let r=z(t,e,":on");return e=>{let i=r(e);for(let e in i)U(t,e,i[e]);return()=>{for(let e in i)L(t,e,i[e])}}};var B=(t,e,r,i)=>{let o=i.startsWith("on")&&i.slice(2),n=z(t,e,":"+i);if(n)return o?e=>{let r=n(e)||(()=>{});return U(t,o,r),()=>L(t,o,r)}:e=>_(t,i,n(e))},D=Symbol("stop"),U=(t,e,r)=>{let i=e.split("..").map((t=>t.startsWith("on")?t.slice(2):t)),o={target:t,hooks:[],fn:r};i[0]=i[0].replace(/\.(\w+)?-?([\w]+)?/g,((t,e,r)=>(M[e]?.(o,r),"")));let{target:n,hooks:s,fn:l,...a}=o;if(s.length){let t=l;l=e=>{for(let t of s)if(!1===t(e))return!1;return t(e)}}if(1==i.length)n.addEventListener(i[0],l,a);else{const t=(e,r=0)=>{let o=s=>{n.removeEventListener(i[r],o),"function"!=typeof(e=e.call(n,s))&&(e=()=>{}),++r<i.length?t(e,r):l[D]||t(l)};n.addEventListener(i[r],o,a)};t(l)}},L=(t,e,r)=>{e.indexOf("..")>=0&&(r[D]=!0),t.removeEventListener(e,r)},M={throttle(t,r){let{fn:i}=t;r=Number(r)||108;let o,n,s=()=>{o=!0,setTimeout((()=>{if(o=!1,n)return n=!1,s(),i(e)}))};t.fn=t=>o?n=!0:(s(),i(t))},debounce(t,e){let r,{fn:i}=t;e=Number(e)||108,t.fn=t=>{clearTimeout(r),r=setTimeout((()=>{r=null,i(t)}),e)}},window(t){t.target=window},document(t){t.target=document},outside({target:t,hooks:e}){e.push((e=>!t.contains(e.target)&&!1!==e.target.isConnected&&!(t.offsetWidth<1&&t.offsetHeight<1)&&void 0))},prevent({hooks:t}){t.push((t=>{t.preventDefault()}))},stop({hooks:t}){t.push((t=>{t.stopPropagation()}))},self({target:t,hooks:e}){e.push((e=>e.target===t))},once(t){t.once=!0},passive(t){t.passive=!0},capture(t){t.capture=!0},ctrl({hooks:t}){t.push((t=>"Control"===t.key||"Ctrl"===t.key))},shift({hooks:t}){t.push((t=>"Shift"===t.key))},alt({hooks:t}){t.push((t=>"Alt"===t.key))},meta({hooks:t}){t.push((t=>"Meta"===t.key))},arrow({hooks:t}){t.push((t=>t.key.startsWith("Arrow")))},enter({hooks:t}){t.push((t=>"Enter"===t.key))},escape({hooks:t}){t.push((t=>t.key.startsWith("Esc")))},tab({hooks:t}){t.push((t=>"Tab"===t.key))},space({hooks:t}){t.push((t=>"Space"===t.key||" "===t.key))},backspace({hooks:t}){t.push((t=>"Backspace"===t.key))},delete({hooks:t}){t.push((t=>"Delete"===t.key))},digit({hooks:t}){t.push((t=>/\d/.test(t.key)))},letter({hooks:t}){t.push((t=>/[a-zA-Z]/.test(t.key)))},character({hooks:t}){t.push((t=>/^\S$/.test(t.key)))}},_=(t,e,r)=>{null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,!0===r?"":"number"==typeof r||"string"==typeof r?r:"")},R={};function z(t,e,r){let i=R[e];if(!i){let o=/^[\n\s]*if.*\(.*\)/.test(e)||/^(let|const)\s/.test(e)?`(() => { ${e} })()`:e;try{i=R[e]=new Function("__scope",`with (__scope) { return ${o} };`)}catch(i){return F(i,t,e,r)}}return o=>{let n;try{n=i.call(t,o)}catch(i){return F(i,t,e,r)}return n}}function F(t,e,r,i){Object.assign(t,{element:e,expression:r}),console.warn(`∴ ${t.message}\n\n${i}=${r?`"${r}"\n\n`:""}`,e),setTimeout((()=>{throw t}),0)}function I(t){return t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()))}var Z=new WeakMap;function H(t,e){if(!t.children)return;if(Z.has(t)){let i=Z.get(t);return function(t){if(n>0)return t();n++;try{t()}finally{r()}}((()=>Object.assign(i,e))),i}const i=A(e||{}),o=[],s=(t,e=t.parentNode)=>{for(let r in T){let n=":"+r;if(t.hasAttribute?.(n)){let s=t.getAttribute(n);if(t.removeAttribute(n),o.push(T[r](t,s,i,r)),Z.has(t)||t.parentNode!==e)return!1}}if(t.attributes)for(let r=0;r<t.attributes.length;){let n=t.attributes[r];if(":"!==n.name[0]){r++;continue}t.removeAttribute(n.name);let s=n.value,l=n.name.slice(1).split(":");for(let r of l){let n=$[r]||B;if(o.push(n(t,s,i,r)),Z.has(t)||t.parentNode!==e)return!1}}for(let e,r=0;e=t.children[r];r++)!1===s(e,t)&&r--};s(t);for(let t of o)if(t){let e;g((()=>{"function"==typeof e&&e(),e=t(i)}))}return Object.seal(i),Z.set(t,i),i}var X=H;export{X as default};
|
|
1
|
+
function t(){throw new Error("Cycle detected")}function i(){if(n>1)n--;else{for(var t,e=!1;void 0!==o;){var i=o;for(o=void 0,s++;void 0!==i;){var r=i.o;if(i.o=void 0,i.f&=-3,!(8&i.f)&&f(i))try{i.c()}catch(i){e||(t=i,e=!0)}i=r}}if(s=0,n--,e)throw t}}var r=void 0,o=void 0,n=0,s=0,l=0;function u(t){if(void 0!==r){var e=t.n;if(void 0===e||e.t!==r)return r.s=e={i:0,S:t,p:void 0,n:r.s,t:r,e:void 0,x:void 0,r:e},t.n=e,32&r.f&&t.S(e),e;if(-1===e.i)return e.i=0,void 0!==e.p&&(e.p.n=e.n,void 0!==e.n&&(e.n.p=e.p),e.p=void 0,e.n=r.s,r.s.p=e,r.s=e),e}}function a(t){this.v=t,this.i=0,this.n=void 0,this.t=void 0}function f(t){for(var e=t.s;void 0!==e;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function h(t){for(var e=t.s;void 0!==e;e=e.n){var i=e.S.n;void 0!==i&&(e.r=i),e.S.n=e,e.i=-1}}function c(t){for(var e=t.s,i=void 0;void 0!==e;){var r=e.n;-1===e.i?(e.S.U(e),e.n=void 0):(void 0!==i&&(i.p=e),e.p=void 0,e.n=i,i=e),e.S.n=e.r,void 0!==e.r&&(e.r=void 0),e=r}t.s=i}function v(t){a.call(this,void 0),this.x=t,this.s=void 0,this.g=l-1,this.f=4}function p(t){var e=t.u;if(t.u=void 0,"function"==typeof e){n++;var o=r;r=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,d(t),e}finally{r=o,i()}}}function d(t){for(var e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,p(t)}function y(t){if(r!==this)throw new Error("Out-of-order effect");c(this),r=t,this.f&=-2,8&this.f&&d(this),i()}function b(t){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}function g(t){var e=new b(t);return e.c(),e.d.bind(e)}a.prototype.h=function(){return!0},a.prototype.S=function(t){this.t!==t&&void 0===t.e&&(t.x=this.t,void 0!==this.t&&(this.t.e=t),this.t=t)},a.prototype.U=function(t){var e=t.e,i=t.x;void 0!==e&&(e.x=i,t.e=void 0),void 0!==i&&(i.e=e,t.x=void 0),t===this.t&&(this.t=i)},a.prototype.subscribe=function(t){var e=this;return g((function(){var i=e.value,r=32&this.f;this.f&=-33;try{t(i)}finally{this.f|=r}}))},a.prototype.valueOf=function(){return this.value},a.prototype.toString=function(){return this.value+""},a.prototype.peek=function(){return this.v},Object.defineProperty(a.prototype,"value",{get:function(){var t=u(this);return void 0!==t&&(t.i=this.i),this.v},set:function(e){if(e!==this.v){s>100&&t(),this.v=e,this.i++,l++,n++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{i()}}}}),(v.prototype=new a).h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===l)return!0;if(this.g=l,this.f|=1,this.i>0&&!f(this))return this.f&=-2,!0;var t=r;try{h(this),r=this;var e=this.x();(16&this.f||this.v!==e||0===this.i)&&(this.v=e,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return r=t,c(this),this.f&=-2,!0},v.prototype.S=function(t){if(void 0===this.t){this.f|=36;for(var e=this.s;void 0!==e;e=e.n)e.S.S(e)}a.prototype.S.call(this,t)},v.prototype.U=function(t){if(a.prototype.U.call(this,t),void 0===this.t){this.f&=-33;for(var e=this.s;void 0!==e;e=e.n)e.S.U(e)}},v.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;void 0!==t;t=t.x)t.t.N()}},v.prototype.peek=function(){if(this.h()||t(),16&this.f)throw this.v;return this.v},Object.defineProperty(v.prototype,"value",{get:function(){1&this.f&&t();var e=u(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),b.prototype.c=function(){var t=this.S();try{8&this.f||void 0===this.x||(this.u=this.x())}finally{t()}},b.prototype.S=function(){1&this.f&&t(),this.f|=1,this.f&=-9,p(this),h(this),n++;var e=r;return r=this,y.bind(this,e)},b.prototype.N=function(){2&this.f||(this.f|=2,this.o=o,o=this)},b.prototype.d=function(){this.f|=8,1&this.f||d(this)},Symbol.observable||=Symbol("observable");var m=new FinalizationRegistry((t=>t.call?.())),k=(t,e,i,r,o,n)=>{return t&&(s=(t[Symbol.observable]?.()||t).subscribe?.(e,i,r),n=s&&(()=>s.unsubscribe?.())||t.set&&t.call?.(o,e)||(t.then?.((t=>(!o&&e(t),r?.())),i)||(async n=>{try{for await(n of t){if(o)return;e(n)}r?.()}catch(t){i?.(t)}})())&&(t=>o=1),m.register(t,n),n);var s},w=t=>t&&t[S],S=Symbol("signal-struct");function A(t,e){if(w(t)&&!e)return t;if(x(t)){const o=Object.create(e||Object.getPrototypeOf(t)),n={},s=Object.getOwnPropertyDescriptors(t);for(let t in s){let e=s[t];if(e.get){let i=n[t]=new v(e.get.bind(o));Object.defineProperty(o,t,{get:()=>i.value,set:e.set?.bind(o),configurable:!1,enumerable:!0})}else{let s=e.value,l=(r=s)&&!!(r[Symbol.observable]||r[Symbol.asyncIterator]||r.call&&r.set||r.subscribe||r.then),u=n[t]=(i=s)&&i.peek?s:new a(l?void 0:x(s)?Object.seal(A(s)):Array.isArray(s)?A(s):s);l&&k(s,(t=>u.value=t)),Object.defineProperty(o,t,{get:()=>u.value,set(t){if(x(t)){if(x(u.value))try{return void Object.assign(u.value,t)}catch(t){}u.value=Object.seal(A(t))}else Array.isArray(t)?u.value=A(t):u.value=t},enumerable:!0,configurable:!1})}}return Object.defineProperty(o,S,{configurable:!1,enumerable:!1,value:!0}),o}var i,r;if(Array.isArray(t)&&!w(t[0]))for(let e=0;e<t.length;e++)t[e]=A(t[e]);return t}function x(t){return t&&t.constructor===Object}A.isStruct=w;var O={},j={},N={},E=t=>null===t?j:void 0===t?N:"number"==typeof t||t instanceof Number?O[t]||(O[t]=new Number(t)):"string"==typeof t||t instanceof String?O[t]||(O[t]=new String(t)):"boolean"==typeof t||t instanceof Boolean?O[t]||(O[t]=new Boolean(t)):t,W={},C={};W.if=(t,e)=>{let i=document.createTextNode(""),r=[_(t,e,":if")],o=[t],n=t;for(;(n=t.nextElementSibling)&&n.hasAttribute(":else");)n.removeAttribute(":else"),(e=n.getAttribute(":if"))?(n.removeAttribute(":if"),n.remove(),o.push(n),r.push(_(t,e,":else :if"))):(n.remove(),o.push(n),r.push((()=>1)));return t.replaceWith(n=i),t=>{let e=r.findIndex((e=>e(t)));o[e]!=n&&((n[T]||n).replaceWith(n=o[e]||i),I(n,t))}},W.with=(t,e,i)=>{I(t,A(_(t,e,"with")(i),i))};var T=Symbol(":each");W.each=(t,e)=>{let i=function(t){let e=/,([^,\}\]]*)(?:,([^,\}\]]*))?$/,i=t.match(/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/);if(!i)return;let r=i[2].trim(),o=i[1].replace(/^\s*\(|\)\s*$/g,"").trim(),n=o.match(e);return n?[o.replace(e,"").trim(),n[1].trim(),r]:[o,"",r]}(e);if(!i)return R(new Error,t,e);const r=t[T]=document.createTextNode("");t.replaceWith(r);const o=_(t,i[2],":each"),n=t.getAttribute(":key"),s=n?_(null,n):null;t.removeAttribute(":key");const l=new WeakMap,u=new WeakMap;let a=[];return n=>{let f=o(n);f?"number"==typeof f?f=Array.from({length:f},((t,e)=>[e,e+1])):Array.isArray(f)?f=f.map(((t,e)=>[e+1,t])):"object"==typeof f?f=Object.entries(f):R(Error("Bad list value"),t,e,":each"):f=[];let h=[],c=[];for(let[e,r]of f){let o,a,f=s?.({[i[0]]:r,[i[1]]:e});("string"==typeof(v=f)||"boolean"==typeof v||"number"==typeof v)&&(f=E(f)),null==f?o=t.cloneNode(!0):(o=u.get(f))||u.set(f,o=t.cloneNode(!0)),h.push(o),null!=f&&(a=l.get(f))?a[i[0]]=r:(a=A({[i[0]]:r,[i[1]]:e},n),null!=f&&l.set(f,a)),c.push(a)}var v;!function(t,e,i,r){const o=new Map,n=new Map;let s,l;for(s=0;s<e.length;s++)o.set(e[s],s);for(s=0;s<i.length;s++)n.set(i[s],s);for(s=l=0;s!==e.length||l!==i.length;){var u=e[s],a=i[l];if(null===u)s++;else if(i.length<=l)t.removeChild(e[s]),s++;else if(e.length<=s)t.insertBefore(a,e[s]||r),l++;else if(u===a)s++,l++;else{var f=n.get(u),h=o.get(a);void 0===f?(t.removeChild(e[s]),s++):void 0===h?(t.insertBefore(a,e[s]||r),l++):(t.insertBefore(e[h],e[s]||r),e[h]=null,h>s+1&&s++,l++)}}}(r.parentNode,a,h,r),a=h;for(let t=0;t<h.length;t++)I(h[t],c[t])}},C.ref=(t,e,i)=>{i[e]=t},C.id=(t,e)=>{let i=_(t,e,":id");return e=>{return r=i(e),t.id=r||0===r?r:"";var r}},C.class=(t,e)=>{let i=_(t,e,":class"),r=t.className;return e=>{let o=i(e);t.className=r+typeof o=="string"?o:(Array.isArray(o)?o:Object.entries(o).map((([t,e])=>e?t:""))).filter(Boolean).join(" ")}},C.style=(t,e)=>{let i=_(t,e,":style"),r=t.getAttribute("style")||"";return r.endsWith(";")||(r+="; "),e=>{let o=i(e);if("string"==typeof o)t.setAttribute("style",r+o);else for(let e in o)t.style[e]=o[e]}},C.text=(t,e)=>{let i=_(t,e,":text");return e=>{let r=i(e);t.textContent=null==r?"":r}},C.data=(t,e)=>{let i=_(t,e,":data");return e=>{let r=i(e);for(let e in r)t.dataset[e]=r[e]}},C.aria=(t,e)=>{let i=_(t,e,":aria");return e=>(e=>{for(let i in e)U(t,"aria-"+z(i),null==e[i]?null:e[i]+"")})(i(e))},C[""]=(t,e)=>{let i=_(t,e,":");if(i)return e=>{let r=i(e);for(let e in r)U(t,z(e),r[e])}},C.value=(t,e)=>{let i,r,o=_(t,e,":value"),n="text"===t.type||""===t.type?e=>t.setAttribute("value",t.value=null==e?"":e):"TEXTAREA"===t.tagName||"text"===t.type||""===t.type?e=>(i=t.selectionStart,r=t.selectionEnd,t.setAttribute("value",t.value=null==e?"":e),i&&t.setSelectionRange(i,r)):"checkbox"===t.type?e=>(t.value=e?"on":"",U(t,"checked",e)):"select-one"===t.type?e=>{for(let e in t.options)e.removeAttribute("selected");t.value=e,t.selectedOptions[0]?.setAttribute("selected","")}:e=>t.value=e;return t=>n(o(t))},C.on=(t,e)=>{let i=_(t,e,":on");return e=>{let r=i(e);for(let e in r)P(t,e,r[e]);return()=>{for(let e in r)D(t,e,r[e])}}};var $=(t,e,i,r)=>{let o=r.startsWith("on")&&r.slice(2),n=_(t,e,":"+r);if(n)return o?e=>{let i=n(e)||(()=>{});return P(t,o,i),()=>D(t,o,i)}:e=>U(t,r,n(e))},B=Symbol("stop"),P=(t,e,i)=>{let r=e.split("..").map((t=>t.startsWith("on")?t.slice(2):t)),o={target:t,hooks:[],fn:i};r[0]=r[0].replace(/\.(\w+)?-?([\w]+)?/g,((t,e,i)=>(M[e]?.(o,i),"")));let{target:n,hooks:s,fn:l,...u}=o;if(s.length){let t=l;l=e=>{for(let t of s)if(!1===t(e))return!1;return t(e)}}if(1==r.length)n.addEventListener(r[0],l,u);else{const t=(e,i=0)=>{let o=s=>{n.removeEventListener(r[i],o),"function"!=typeof(e=e.call(n,s))&&(e=()=>{}),++i<r.length?t(e,i):l[B]||t(l)};n.addEventListener(r[i],o,u)};t(l)}},D=(t,e,i)=>{e.indexOf("..")>=0&&(i[B]=!0),t.removeEventListener(e,i)},M={prevent({hooks:t}){t.push((t=>{t.preventDefault()}))},stop({hooks:t}){t.push((t=>{t.stopPropagation()}))},throttle(t,i){let{fn:r}=t;i=Number(i)||108;let o,n,s=()=>{o=!0,setTimeout((()=>{if(o=!1,n)return n=!1,s(),r(e)}))};t.fn=t=>o?n=!0:(s(),r(t))},debounce(t,e){let i,{fn:r}=t;e=Number(e)||108,t.fn=t=>{clearTimeout(i),i=setTimeout((()=>{i=null,r(t)}),e)}},window(t){t.target=window},document(t){t.target=document},outside({target:t,hooks:e}){e.push((e=>!t.contains(e.target)&&!1!==e.target.isConnected&&!(t.offsetWidth<1&&t.offsetHeight<1)&&void 0))},self({target:t,hooks:e}){e.push((e=>e.target===t))},once(t){t.once=!0},passive(t){t.passive=!0},capture(t){t.capture=!0},ctrl({hooks:t}){t.push((t=>"Control"===t.key||"Ctrl"===t.key))},shift({hooks:t}){t.push((t=>"Shift"===t.key))},alt({hooks:t}){t.push((t=>"Alt"===t.key))},meta({hooks:t}){t.push((t=>"Meta"===t.key))},arrow({hooks:t}){t.push((t=>t.key.startsWith("Arrow")))},enter({hooks:t}){t.push((t=>"Enter"===t.key))},escape({hooks:t}){t.push((t=>t.key.startsWith("Esc")))},tab({hooks:t}){t.push((t=>"Tab"===t.key))},space({hooks:t}){t.push((t=>"Space"===t.key||" "===t.key))},backspace({hooks:t}){t.push((t=>"Backspace"===t.key))},delete({hooks:t}){t.push((t=>"Delete"===t.key))},digit({hooks:t}){t.push((t=>/\d/.test(t.key)))},letter({hooks:t}){t.push((t=>/[a-zA-Z]/.test(t.key)))},character({hooks:t}){t.push((t=>/^\S$/.test(t.key)))}},U=(t,e,i)=>{null==i||!1===i?t.removeAttribute(e):t.setAttribute(e,!0===i?"":"number"==typeof i||"string"==typeof i?i:"")},L={};function _(t,e,i){let r=L[e];if(!r){let o=/^[\n\s]*if.*\(.*\)/.test(e)||/^(let|const)\s/.test(e)?`(() => { ${e} })()`:e;try{r=L[e]=new Function("__scope",`with (__scope) { return ${o} };`)}catch(r){return R(r,t,e,i)}}return o=>{let n;try{n=r.call(t,o)}catch(r){return R(r,t,e,i)}return n}}function R(t,e,i,r){Object.assign(t,{element:e,expression:i}),console.warn(`∴ ${t.message}\n\n${r}=${i?`"${i}"\n\n`:""}`,e),setTimeout((()=>{throw t}),0)}function z(t){return t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()))}var F=new WeakMap;function I(t,e){if(!t.children)return;if(F.has(t)){let r=F.get(t);return function(t){if(n>0)return t();n++;try{t()}finally{i()}}((()=>Object.assign(r,e))),r}const r=A(e||{}),o=[],s=(t,e=t.parentNode)=>{for(let i in W){let n=":"+i;if(t.hasAttribute?.(n)){let s=t.getAttribute(n);if(t.removeAttribute(n),o.push(W[i](t,s,r,i)),F.has(t)||t.parentNode!==e)return!1}}if(t.attributes)for(let i=0;i<t.attributes.length;){let n=t.attributes[i];if(":"!==n.name[0]){i++;continue}t.removeAttribute(n.name);let s=n.value,l=n.name.slice(1).split(":");for(let i of l){let n=C[i]||$;if(o.push(n(t,s,r,i)),F.has(t)||t.parentNode!==e)return!1}}for(let e,i=0;e=t.children[i];i++)!1===s(e,t)&&i--};s(t);for(let t of o)if(t){let e;g((()=>{"function"==typeof e&&e(),e=t(r)}))}return Object.seal(r),F.set(t,r),r}var Z=I;export{Z as default};
|
package/src/directives.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// directives & parsing
|
|
2
2
|
import sprae from './core.js'
|
|
3
|
-
import swap from '
|
|
3
|
+
import swap from './domdiff.js'
|
|
4
4
|
import signalStruct from 'signal-struct'
|
|
5
5
|
import p from 'primitive-pool'
|
|
6
6
|
|
|
@@ -298,6 +298,8 @@ const removeListener = (el, evt, fn) => {
|
|
|
298
298
|
|
|
299
299
|
// event modifiers
|
|
300
300
|
const mods = {
|
|
301
|
+
prevent({hooks}) { hooks.push(e => { e.preventDefault(); })},
|
|
302
|
+
stop({hooks}) { hooks.push(e => { e.stopPropagation(); })},
|
|
301
303
|
throttle(opts, limit) {
|
|
302
304
|
let {fn} = opts
|
|
303
305
|
limit = Number(limit) || 108
|
|
@@ -315,7 +317,6 @@ const mods = {
|
|
|
315
317
|
return fn(e);
|
|
316
318
|
}
|
|
317
319
|
},
|
|
318
|
-
|
|
319
320
|
debounce(opts, wait) {
|
|
320
321
|
let {fn} = opts
|
|
321
322
|
wait = Number(wait) || 108;
|
|
@@ -326,6 +327,7 @@ const mods = {
|
|
|
326
327
|
}
|
|
327
328
|
},
|
|
328
329
|
|
|
330
|
+
// target
|
|
329
331
|
window(opts) { opts.target = window },
|
|
330
332
|
document(opts) { opts.target = document },
|
|
331
333
|
outside({target, hooks}) {
|
|
@@ -335,9 +337,9 @@ const mods = {
|
|
|
335
337
|
if (target.offsetWidth < 1 && target.offsetHeight < 1) return false
|
|
336
338
|
})
|
|
337
339
|
},
|
|
338
|
-
prevent({hooks}) { hooks.push(e => { e.preventDefault(); })},
|
|
339
|
-
stop({hooks}) { hooks.push(e => { e.stopPropagation(); })},
|
|
340
340
|
self({target, hooks}) { hooks.push(e => { return e.target === target })},
|
|
341
|
+
|
|
342
|
+
// options
|
|
341
343
|
once(opts) { opts.once = true; },
|
|
342
344
|
passive(opts) { opts.passive = true; },
|
|
343
345
|
capture(opts) { opts.capture = true; },
|
package/src/domdiff.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// https://github.com/luwes/js-diff-benchmark/blob/master/libs/list-difference.js
|
|
2
|
+
// this implementation is more persistent in terms of preserving in-between nodes
|
|
3
|
+
|
|
4
|
+
// a is old list, b is the new
|
|
5
|
+
export default function(parent, a, b, before) {
|
|
6
|
+
const aIdx = new Map();
|
|
7
|
+
const bIdx = new Map();
|
|
8
|
+
let i;
|
|
9
|
+
let j;
|
|
10
|
+
|
|
11
|
+
// Create a mapping from keys to their position in the old list
|
|
12
|
+
for (i = 0; i < a.length; i++) {
|
|
13
|
+
aIdx.set(a[i], i);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Create a mapping from keys to their position in the new list
|
|
17
|
+
for (i = 0; i < b.length; i++) {
|
|
18
|
+
bIdx.set(b[i], i);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (i = j = 0; i !== a.length || j !== b.length;) {
|
|
22
|
+
var aElm = a[i], bElm = b[j];
|
|
23
|
+
if (aElm === null) {
|
|
24
|
+
// This is a element that has been moved to earlier in the list
|
|
25
|
+
i++;
|
|
26
|
+
} else if (b.length <= j) {
|
|
27
|
+
// No more elements in new, this is a delete
|
|
28
|
+
parent.removeChild(a[i]);
|
|
29
|
+
i++;
|
|
30
|
+
} else if (a.length <= i) {
|
|
31
|
+
// No more elements in old, this is an addition
|
|
32
|
+
parent.insertBefore(bElm, a[i] || before);
|
|
33
|
+
j++;
|
|
34
|
+
} else if (aElm === bElm) {
|
|
35
|
+
// No difference, we move on
|
|
36
|
+
i++; j++;
|
|
37
|
+
} else {
|
|
38
|
+
// Look for the current element at this location in the new list
|
|
39
|
+
// This gives us the idx of where this element should be
|
|
40
|
+
var curElmInNew = bIdx.get(aElm);
|
|
41
|
+
// Look for the the wanted elment at this location in the old list
|
|
42
|
+
// This gives us the idx of where the wanted element is now
|
|
43
|
+
var wantedElmInOld = aIdx.get(bElm);
|
|
44
|
+
if (curElmInNew === undefined) {
|
|
45
|
+
// Current element is not in new list, it has been removed
|
|
46
|
+
parent.removeChild(a[i]);
|
|
47
|
+
i++;
|
|
48
|
+
} else if (wantedElmInOld === undefined) {
|
|
49
|
+
// New element is not in old list, it has been added
|
|
50
|
+
parent.insertBefore(
|
|
51
|
+
bElm,
|
|
52
|
+
a[i] || before
|
|
53
|
+
);
|
|
54
|
+
j++;
|
|
55
|
+
} else {
|
|
56
|
+
// Element is in both lists, it has been moved
|
|
57
|
+
parent.insertBefore(
|
|
58
|
+
a[wantedElmInOld],
|
|
59
|
+
a[i] || before
|
|
60
|
+
);
|
|
61
|
+
a[wantedElmInOld] = null;
|
|
62
|
+
if (wantedElmInOld > i + 1) i++;
|
|
63
|
+
j++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return b;
|
|
68
|
+
};
|
package/test/index.html
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"signal-struct" : "../node_modules/signal-struct/signal-struct.js",
|
|
16
16
|
"element-props" : "../node_modules/element-props/element-props.js",
|
|
17
17
|
"swapdom" : "../node_modules/swapdom/swap-inflate.js",
|
|
18
|
+
"swapdom/swap-deflate" : "../node_modules/swapdom/swap-deflate.js",
|
|
19
|
+
"swapdom/swap-inflate" : "../node_modules/swapdom/swap-inflate.js",
|
|
18
20
|
"primitive-pool" : "../node_modules/primitive-pool/index.js",
|
|
19
21
|
"preact": "../node_modules/preact/dist/preact.mjs",
|
|
20
22
|
"preact/hooks": "../node_modules/preact/hooks/dist/hooks.mjs",
|
package/test/test.js
CHANGED
|
@@ -443,6 +443,19 @@ test('each: :id and others must receive value from context', () => {
|
|
|
443
443
|
is(el.innerHTML,`<x id="1"></x><x id="2"></x><x id="3"></x>`)
|
|
444
444
|
})
|
|
445
445
|
|
|
446
|
+
test('each: key-based caching is in-sync with direct elements', () => {
|
|
447
|
+
let el = h`<ul><li :each="i in x" :key="i" :id="i"></li></ul>`
|
|
448
|
+
let el2 = h`<ul><li :each="i in x" :id="i"></li></ul>`
|
|
449
|
+
let state = sprae(el, {x:2})
|
|
450
|
+
let state2 = sprae(el2, {x:2})
|
|
451
|
+
is(el.outerHTML, el2.outerHTML)
|
|
452
|
+
el.firstChild.after(el.firstChild.cloneNode(true))
|
|
453
|
+
el2.firstChild.after(el2.firstChild.cloneNode(true))
|
|
454
|
+
state.x = 3
|
|
455
|
+
state2.x = 3
|
|
456
|
+
is(el.outerHTML, el2.outerHTML)
|
|
457
|
+
})
|
|
458
|
+
|
|
446
459
|
test('on: base', () => {
|
|
447
460
|
let el = h`<div :on="{click(e){log.push('click')},x}"></div>`
|
|
448
461
|
let log = signal([])
|