From 4ca2b362f72fac15dd4b8d58c06a2af8148e328c Mon Sep 17 00:00:00 2001 From: Gandalf-the-Bot Date: Fri, 1 Jun 2018 19:28:42 +0000 Subject: [PATCH] Bundled output for commit 3f5cabc5c5234a81c7f455fbe5afd7cde2a957b8 [skip ci] --- README.md | 2 +- mithril.js | 94 ++++++++++++++++++++++++++----------------------- mithril.min.js | 95 +++++++++++++++++++++++++------------------------- 3 files changed, 99 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index a7347635..fa0159a9 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ mithril.js [![NPM Version](https://img.shields.io/npm/v/mithril.svg)](https://ww ## What is Mithril? -A modern client-side Javascript framework for building Single Page Applications. It's small (8.71 KB gzipped), fast and provides routing and XHR utilities out of the box. +A modern client-side Javascript framework for building Single Page Applications. It's small (8.86 KB gzipped), fast and provides routing and XHR utilities out of the box. Mithril is used by companies like Vimeo and Nike, and open source platforms like Lichess 👍. diff --git a/mithril.js b/mithril.js index 7478e740..567d2c4c 100644 --- a/mithril.js +++ b/mithril.js @@ -507,7 +507,7 @@ var coreRenderer = function($window) { setAttrs(vnode, attrs2, ns) } insertNode(parent, element, nextSibling) - if (vnode.attrs != null && vnode.attrs.contenteditable != null) { + if (attrs2 != null && attrs2.contenteditable != null) { setContentEditable(vnode) } else { @@ -518,7 +518,7 @@ var coreRenderer = function($window) { if (vnode.children != null) { var children1 = vnode.children createNodes(element, children1, 0, children1.length, hooks, null, ns) - setLateAttrs(vnode) + if (vnode.tag === "select" && attrs2 != null) setLateSelectAttrs(vnode, attrs2) } } } @@ -940,9 +940,7 @@ var coreRenderer = function($window) { u = 0 v = result.length - 1 while (u < v) { - /*eslint-disable no-bitwise*/ - var c = ((u + v) / 2) | 0 - /*eslint-enable no-bitwise*/ + var c = ((u + v) / 2) | 0 // eslint-disable-line no-bitwise if (a[result[c]] < a[i]) { u = c + 1 } @@ -1064,66 +1062,74 @@ var coreRenderer = function($window) { } } function setAttr(vnode, key2, old, value, ns) { - if (key2 === "key" || key2 === "is" || isLifecycleMethod(key2)) return + if (key2 === "key" || key2 === "is" || value == null || isLifecycleMethod(key2) || (old === value && !isFormAttribute(vnode, key2)) && typeof value !== "object") return if (key2[0] === "o" && key2[1] === "n") return updateEvent(vnode, key2, value) - if (typeof value === "undefined" && key2 === "value" && old !== value) { - vnode.dom.value = "" - return - } - if ((old === value && !isFormAttribute(vnode, key2)) && typeof value !== "object" || value === undefined) return - var element = vnode.dom - if (key2.slice(0, 6) === "xlink:") element.setAttributeNS("http://www.w3.org/1999/xlink", key2, value) - else if (key2 === "style") updateStyle(element, old, value) - else if (key2 in element && !isAttribute(key2) && ns === undefined && !isCustomElement(vnode)) { + if (key2.slice(0, 6) === "xlink:") vnode.dom.setAttributeNS("http://www.w3.org/1999/xlink", key2.slice(6), value) + else if (key2 === "style") updateStyle(vnode.dom, old, value) + else if (key2 in vnode.dom && !isAttribute(key2) && ns === undefined && !isCustomElement(vnode.tag, vnode.attrs)) { if (key2 === "value") { var normalized = "" + value // eslint-disable-line no-implicit-coercion //setting input[value] to same value by typing on focused element moves cursor to end in Chrome if ((vnode.tag === "input" || vnode.tag === "textarea") && vnode.dom.value === normalized && vnode.dom === $doc.activeElement) return //setting select[value] to same value while having select open blinks select dropdown in Chrome - if (vnode.tag === "select") { - if (value === null) { - if (vnode.dom.selectedIndex === -1 && vnode.dom === $doc.activeElement) return - } else { - if (old !== null && vnode.dom.value === normalized && vnode.dom === $doc.activeElement) return - } - } + if (vnode.tag === "select" && old !== null && vnode.dom.value === normalized) return //setting option[value] to same value while having select open blinks select dropdown in Chrome - if (vnode.tag === "option" && old != null && vnode.dom.value === normalized) return + if (vnode.tag === "option" && old !== null && vnode.dom.value === normalized) return } // If you assign an input type1 that is not supported by IE 11 with an assignment expression, an error1 will occur. - if (vnode.tag === "input" && key2 === "type") { - element.setAttribute(key2, value) - return - } - element[key2] = value - } - else { + if (vnode.tag === "input" && key2 === "type") vnode.dom.setAttribute(key2, value) + else vnode.dom[key2] = value + } else { if (typeof value === "boolean") { - if (value) element.setAttribute(key2, "") - else element.removeAttribute(key2) + if (value) vnode.dom.setAttribute(key2, "") + else vnode.dom.removeAttribute(key2) } - else element.setAttribute(key2 === "className" ? "class" : key2, value) + else vnode.dom.setAttribute(key2 === "className" ? "class" : key2, value) } } - function setLateAttrs(vnode) { - var attrs2 = vnode.attrs - if (vnode.tag === "select" && attrs2 != null) { - if ("value" in attrs2) setAttr(vnode, "value", null, attrs2.value, undefined) - if ("selectedIndex" in attrs2) setAttr(vnode, "selectedIndex", null, attrs2.selectedIndex, undefined) + function removeAttr(vnode, key2, old, ns) { + if (key2 === "key" || key2 === "is" || old == null || isLifecycleMethod(key2)) return + if (key2[0] === "o" && key2[1] === "n" && !isLifecycleMethod(key2)) updateEvent(vnode, key2, undefined) + else if (key2 === "style") updateStyle(vnode.dom, old, null) + else if ( + key2 in vnode.dom && !isAttribute(key2) + && key2 !== "className" + && !(vnode.tag === "option" && key2 === "value") + && !(vnode.tag === "input" && key2 === "type") + && ns === undefined + && !isCustomElement(vnode.tag, vnode.attrs || {}) + ) { + vnode.dom[key2] = null + } else { + var nsLastIndex = key2.indexOf(":") + if (nsLastIndex !== -1) key2 = key2.slice(nsLastIndex + 1) + if (old !== false) vnode.dom.removeAttribute(key2 === "className" ? "class" : key2) } } + function setLateSelectAttrs(vnode, attrs2) { + if ("value" in attrs2) { + if(attrs2.value === null) { + if (vnode.dom.selectedIndex !== -1) vnode.dom.value = null + } else { + var normalized = "" + attrs2.value // eslint-disable-line no-implicit-coercion + if (vnode.dom.value !== normalized || vnode.dom.selectedIndex === -1) { + vnode.dom.value = normalized + } + } + } + if ("selectedIndex" in attrs2) setAttr(vnode, "selectedIndex", null, attrs2.selectedIndex, undefined) + } function updateAttrs(vnode, old, attrs2, ns) { if (attrs2 != null) { for (var key2 in attrs2) { setAttr(vnode, key2, old && old[key2], attrs2[key2], ns) } } + var val if (old != null) { for (var key2 in old) { - if (attrs2 == null || !(key2 in attrs2)) { - if (key2 === "className") key2 = "class" - if (key2[0] === "o" && key2[1] === "n" && !isLifecycleMethod(key2)) updateEvent(vnode, key2, undefined) - else if (key2 !== "key") vnode.dom.removeAttribute(key2) + if (((val = old[key2]) != null) && (attrs2 == null || attrs2[key2] == null)) { + removeAttr(vnode, key2, val, ns) } } } @@ -1137,8 +1143,8 @@ var coreRenderer = function($window) { function isAttribute(attr) { return attr === "href" || attr === "list" || attr === "form" || attr === "width" || attr === "height"// || attr === "type" } - function isCustomElement(vnode){ - return vnode.attrs.is || vnode.tag.indexOf("-") > -1 + function isCustomElement(tag, attrs2){ + return attrs2.is || tag.indexOf("-") > -1 } //style function updateStyle(element, old, style) { diff --git a/mithril.min.js b/mithril.min.js index 40caf8b5..414d2792 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,47 +1,48 @@ -(function(){function z(a,d,e,f,v,l){return{tag:a,key:d,attrs:e,children:f,text:v,dom:l,domSize:void 0,state:void 0,events:void 0,instance:void 0}}function Q(a){for(var d in a)if(H.call(a,d))return!1;return!0}function w(a){if(null==a||"string"!==typeof a&&"function"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");var d=arguments[1],e=2;if(null==d)d={};else if("object"!==typeof d||null!=d.tag||Array.isArray(d))d={},e=1;if(arguments.length=== -e+1){var f=arguments[e];Array.isArray(f)||(f=[f])}else for(f=[];ec.indexOf("?")?"?":"&";c+=e+d}return c}function h(c){try{return""!==c?JSON.parse(c):null}catch(D){throw Error(c);}}function n(c){return c.responseText}function t(c,a){if("function"=== -typeof c)if(Array.isArray(a))for(var d=0;dg.status||304===g.status||Y.test(c.url))d(t(c.type,a));else{var f=Error(g.responseText);f.code=g.status;f.response=a;e(f)}}catch(Z){e(Z)}};f&&null!=c.data?g.send(c.data):g.send()});return!0===c.background?D:E(D)},jsonp:function(c,n){var h=e();c=f(c,n);var D=new d(function(d,e){var f=c.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+g++,n=a.document.createElement("script");a[f]=function(e){n.parentNode.removeChild(n);d(t(c.type,e));delete a[f]};n.onerror=function(){n.parentNode.removeChild(n); -e(Error("JSONP request failed"));delete a[f]};null==c.data&&(c.data={});c.url=v(c.url,c.data);c.data[c.callbackKey||"callback"]=f;n.src=l(c.url,c.data);a.document.documentElement.appendChild(n)});return!0===c.background?D:h(D)},setCompletionCallback:function(c){C=c}}}(window,k),U=function(a){function d(p,b){if(p.state!==b)throw Error("`vnode.state` must not be modified");}function e(p){var b=p.state;try{return this.apply(b,arguments)}finally{d(p,b)}}function f(p,b,c,a,d,e,f){for(;c'+b.children+"",p=p.firstChild):p.innerHTML=b.children;b.dom=p.firstChild;b.domSize=p.childNodes.length;for(b=A.createDocumentFragment();m=p.firstChild;)b.appendChild(m);C(c,b,a)}function h(p, -b,c,a,d,e){if(b!==c&&(null!=b||null!=c))if(null==b||0===b.length)f(p,c,0,c.length,a,d,e);else if(null==c||0===c.length)D(b,0,b.length);else{for(var m=0,r=0,h=null,q=null;r=r&&h>=m;)if(k=b[q],y=c[h],null==k)q--;else if(null==y)h--;else if(k.key===y.key)k!==y&&n(p, -k,y,a,d,e),null!=y.dom&&(d=y.dom),q--,h--;else break;for(;q>=r&&h>=m;)if(x=b[r],u=c[m],null==x)r++;else if(null==u)m++;else if(x.key===u.key)r++,m++,x!==u&&n(p,x,u,a,g(b,r,d),e);else break;for(;q>=r&&h>=m;){if(null==x)r++;else if(null==u)m++;else if(null==k)q--;else if(null==y)h--;else if(m===h)break;else{if(x.key!==y.key||k.key!==u.key)break;B=g(b,r,d);C(p,t(k),B);k!==u&&n(p,k,u,a,B,e);++m<=--h&&C(p,t(x),d);x!==y&&n(p,x,y,a,d,e);null!=y.dom&&(d=y.dom);r++;q--}k=b[q];y=c[h];x=b[r];u=c[m]}for(;q>= -r&&h>=m;){if(null==k)q--;else if(null==y)h--;else if(k.key===y.key)k!==y&&n(p,k,y,a,d,e),null!=y.dom&&(d=y.dom),q--,h--;else break;k=b[q];y=c[h]}if(m>h)D(b,r,q+1);else if(r>q)f(p,c,m,h+1,a,d,e);else{u=d;k=h-m+1;x=Array(k);var A=2147483647,z=0;for(B=0;B=m;B--){if(null==l){l=b;k=r;y=q+1;for(var w={};k=m;B--)u=c[B],-1===x[B-m]?v(p,u,a,e,d):b[r]===B-m?r--:C(p,t(u),d),null!=u.dom&&(d=c[B].dom)}else for(B=h;B>=m;B--)u=c[B],-1===x[B-m]&&v(p, -u,a,e,d),null!=u.dom&&(d=c[B].dom)}}else{h=b.lengthh&&D(b,m,b.length);c.length>h&&f(p,c,m,c.length,a,d,e)}}}function n(p,b,a,d,f,g){var m=b.tag;if(m===a.tag){a.state=b.state;a.events=b.events;var r;var k;null!=a.attrs&&"function"===typeof a.attrs.onbeforeupdate&&(r=e.call(a.attrs.onbeforeupdate,a,b));"string"!==typeof a.tag&&"function"=== -typeof a.state.onbeforeupdate&&(k=e.call(a.state.onbeforeupdate,a,b));void 0===r&&void 0===k||r||k?r=!1:(a.dom=b.dom,a.domSize=b.domSize,a.instance=b.instance,r=!0);if(!r)if("string"===typeof m)switch(null!=a.attrs&&N(a.attrs,a,d),m){case "#":b.children.toString()!==a.children.toString()&&(b.dom.nodeValue=a.children);a.dom=b.dom;break;case "<":b.children!==a.children?(t(b),l(p,a,g,f)):(a.dom=b.dom,a.domSize=b.domSize);break;case "[":h(p,b.children,a.children,d,f,g);b=0;d=a.children;a.dom=null;if(null!= -d){for(var q=0;qc.indexOf("?")?"?":"&";c+=e+d}return c}function h(c){try{return""!==c?JSON.parse(c):null}catch(x){throw Error(c);}}function n(c){return c.responseText}function m(c,a){if("function"=== +typeof c)if(Array.isArray(a))for(var d=0;dl.status||304===l.status||Z.test(c.url))d(m(c.type,a));else{var g=Error(l.responseText);g.code=l.status;g.response=a;e(g)}}catch(aa){e(aa)}};g&&null!=c.data?l.send(c.data):l.send()});return!0===c.background?x:E(x)},jsonp:function(c,n){var h=e();c=g(c,n);var x=new d(function(d,e){var g=c.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+l++,n=a.document.createElement("script");a[g]=function(e){n.parentNode.removeChild(n);d(m(c.type,e));delete a[g]};n.onerror=function(){n.parentNode.removeChild(n); +e(Error("JSONP request failed"));delete a[g]};null==c.data&&(c.data={});c.url=q(c.url,c.data);c.data[c.callbackKey||"callback"]=g;n.src=k(c.url,c.data);a.document.documentElement.appendChild(n)});return!0===c.background?x:h(x)},setCompletionCallback:function(c){C=c}}}(window,p),V=function(a){function d(t,b){if(t.state!==b)throw Error("`vnode.state` must not be modified");}function e(t){var b=t.state;try{return this.apply(b,arguments)}finally{d(t,b)}}function g(t,b,f,c,a,d,e){for(;f'+b.children+"",a=a.firstChild):a.innerHTML=b.children;b.dom=a.firstChild;b.domSize=a.childNodes.length; +for(b=D.createDocumentFragment();f=a.firstChild;)b.appendChild(f);C(t,b,c)}function h(t,b,f,c,a,d){if(b!==f&&(null!=b||null!=f))if(null==b||0===b.length)g(t,f,0,f.length,c,a,d);else if(null==f||0===f.length)x(b,0,b.length);else{for(var e=0,h=0,v=null,k=null;h=h&& +v>=e;)if(A=b[k],y=f[v],null==A)k--;else if(null==y)v--;else if(A.key===y.key)A!==y&&n(t,A,y,c,a,d),null!=y.dom&&(a=y.dom),k--,v--;else break;for(;k>=h&&v>=e;)if(r=b[h],u=f[e],null==r)h++;else if(null==u)e++;else if(r.key===u.key)h++,e++,r!==u&&n(t,r,u,c,l(b,h,a),d);else break;for(;k>=h&&v>=e;){if(null==r)h++;else if(null==u)e++;else if(null==A)k--;else if(null==y)v--;else if(e===v)break;else{if(r.key!==y.key||A.key!==u.key)break;B=l(b,h,a);C(t,m(A),B);A!==u&&n(t,A,u,c,B,d);++e<=--v&&C(t,m(r),a);r!== +y&&n(t,r,y,c,a,d);null!=y.dom&&(a=y.dom);h++;k--}A=b[k];y=f[v];r=b[h];u=f[e]}for(;k>=h&&v>=e;){if(null==A)k--;else if(null==y)v--;else if(A.key===y.key)A!==y&&n(t,A,y,c,a,d),null!=y.dom&&(a=y.dom),k--,v--;else break;A=b[k];y=f[v]}if(e>v)x(b,h,k+1);else if(h>k)g(t,f,e,v+1,c,a,d);else{u=a;A=v-e+1;r=Array(A);var G=2147483647,z=0;for(B=0;B=e;B--){if(null==p){p=b;A=h;y=k+1;for(var w={};A=e;B--)u=f[B],-1===r[B-e]?q(t,u,c,d,a):b[h]===B-e? +h--:C(t,m(u),a),null!=u.dom&&(a=f[B].dom)}else for(B=v;B>=e;B--)u=f[B],-1===r[B-e]&&q(t,u,c,d,a),null!=u.dom&&(a=f[B].dom)}}else{v=b.lengthv&&x(b,e,b.length);f.length>v&&g(t,f,e,f.length,c,a,d)}}}function n(a,b,f,d,g,l){var t=b.tag;if(t===f.tag){f.state=b.state;f.events=b.events;var v;var x;null!=f.attrs&&"function"===typeof f.attrs.onbeforeupdate&& +(v=e.call(f.attrs.onbeforeupdate,f,b));"string"!==typeof f.tag&&"function"===typeof f.state.onbeforeupdate&&(x=e.call(f.state.onbeforeupdate,f,b));void 0===v&&void 0===x||v||x?v=!1:(f.dom=b.dom,f.domSize=b.domSize,f.instance=b.instance,v=!0);if(!v)if("string"===typeof t)switch(null!=f.attrs&&L(f.attrs,f,d),t){case "#":b.children.toString()!==f.children.toString()&&(b.dom.nodeValue=f.children);f.dom=b.dom;break;case "<":b.children!==f.children?(m(b),k(a,f,l,g)):(f.dom=b.dom,f.domSize=b.domSize);break; +case "[":h(a,b.children,f.children,d,g,l);b=0;d=f.children;f.dom=null;if(null!=d){for(var p=0;p