closures 0.7.9 → 0.7.10
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/closures.cjs +28 -11
- package/dist/closures.js +28 -11
- package/dist/closures.min.js +1 -1
- package/package.json +1 -1
package/dist/closures.cjs
CHANGED
@@ -37,15 +37,16 @@ let NIL = void 0,
|
|
37
37
|
REF_ARRAY = 4, // ref with array of nodes
|
38
38
|
REF_PARENT = 8, // ref with a child ref
|
39
39
|
RETAIN_KEY = '=',
|
40
|
-
|
41
|
-
|
40
|
+
exists = x => x !== null && x !== undefined,
|
41
|
+
hasKey = vnode => vnode && exists(vnode.key),
|
42
|
+
haveMatchingKeys = (x, y) => (!exists(x) ? NIL : x.key) === (!exists(y) ? NIL : y.key),
|
42
43
|
generateClosureId = _ => NUM++,
|
43
44
|
isFn = x => typeof x === 'function',
|
44
45
|
isStr = x => typeof x === 'string',
|
45
46
|
isObj = x => x !== null && typeof x === 'object',
|
46
47
|
isArr = x => Array.isArray(x),
|
47
48
|
toJson = v => JSON.stringify(v),
|
48
|
-
isEmpty = c => c
|
49
|
+
isEmpty = c => !exists(c) || c === false || (isArr(c) && c.length === 0) || (c && c._t === RETAIN_KEY),
|
49
50
|
isNonEmptyArray = c => isArr(c) && c.length > 0,
|
50
51
|
isLeaf = c => isStr(c) || typeof c === 'number',
|
51
52
|
isElement = c => c && c.vtype === VTYPE_ELEMENT,
|
@@ -93,8 +94,7 @@ let replaceDom = (parent, newRef, oldRef) => {
|
|
93
94
|
};
|
94
95
|
|
95
96
|
let setDomAttribute = (el, attr, value, isSVG) => {
|
96
|
-
if (
|
97
|
-
if (value === NIL) value = '';
|
97
|
+
if (!exists(value)) value = '';
|
98
98
|
if (value === true) el.setAttribute(attr, '');
|
99
99
|
else if (value === false) el.removeAttribute(attr);
|
100
100
|
else (isSVG && NS_ATTRS[attr])
|
@@ -515,13 +515,30 @@ function h(_t, ...children) {
|
|
515
515
|
? { ...props, children: children[0] }
|
516
516
|
: props;
|
517
517
|
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
518
|
+
if (isStr(_t)) {
|
519
|
+
if (props.className && !props.class) {
|
520
|
+
props.class = props.className;
|
521
|
+
delete props.className;
|
522
|
+
}
|
523
|
+
|
524
|
+
// class parsing
|
525
|
+
if (isObj(props.class)) {
|
526
|
+
let k, tmp = '';
|
527
|
+
|
528
|
+
for (k in props.class)
|
529
|
+
if (props.class[k]) {
|
530
|
+
tmp && (tmp += ' ');
|
531
|
+
tmp += k
|
532
|
+
}
|
522
533
|
|
523
|
-
|
524
|
-
|
534
|
+
props.class = tmp;
|
535
|
+
}
|
536
|
+
|
537
|
+
if (~(idx = _t.indexOf('.'))) {
|
538
|
+
let className = _t.slice(idx + 1).replace(/\./g, ' ') + (props.class ? ' ' + props.class : '');
|
539
|
+
if (className) props.class = className;
|
540
|
+
_t = _t.slice(0, idx);
|
541
|
+
}
|
525
542
|
}
|
526
543
|
|
527
544
|
if (props.key !== props.key) throw new Error("Invalid NaN key");
|
package/dist/closures.js
CHANGED
@@ -37,15 +37,16 @@ let NIL = void 0,
|
|
37
37
|
REF_ARRAY = 4, // ref with array of nodes
|
38
38
|
REF_PARENT = 8, // ref with a child ref
|
39
39
|
RETAIN_KEY = '=',
|
40
|
-
|
41
|
-
|
40
|
+
exists = x => x !== null && x !== undefined,
|
41
|
+
hasKey = vnode => vnode && exists(vnode.key),
|
42
|
+
haveMatchingKeys = (x, y) => (!exists(x) ? NIL : x.key) === (!exists(y) ? NIL : y.key),
|
42
43
|
generateClosureId = _ => NUM++,
|
43
44
|
isFn = x => typeof x === 'function',
|
44
45
|
isStr = x => typeof x === 'string',
|
45
46
|
isObj = x => x !== null && typeof x === 'object',
|
46
47
|
isArr = x => Array.isArray(x),
|
47
48
|
toJson = v => JSON.stringify(v),
|
48
|
-
isEmpty = c => c
|
49
|
+
isEmpty = c => !exists(c) || c === false || (isArr(c) && c.length === 0) || (c && c._t === RETAIN_KEY),
|
49
50
|
isNonEmptyArray = c => isArr(c) && c.length > 0,
|
50
51
|
isLeaf = c => isStr(c) || typeof c === 'number',
|
51
52
|
isElement = c => c && c.vtype === VTYPE_ELEMENT,
|
@@ -93,8 +94,7 @@ let replaceDom = (parent, newRef, oldRef) => {
|
|
93
94
|
};
|
94
95
|
|
95
96
|
let setDomAttribute = (el, attr, value, isSVG) => {
|
96
|
-
if (
|
97
|
-
if (value === NIL) value = '';
|
97
|
+
if (!exists(value)) value = '';
|
98
98
|
if (value === true) el.setAttribute(attr, '');
|
99
99
|
else if (value === false) el.removeAttribute(attr);
|
100
100
|
else (isSVG && NS_ATTRS[attr])
|
@@ -515,13 +515,30 @@ export function h(_t, ...children) {
|
|
515
515
|
? { ...props, children: children[0] }
|
516
516
|
: props;
|
517
517
|
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
518
|
+
if (isStr(_t)) {
|
519
|
+
if (props.className && !props.class) {
|
520
|
+
props.class = props.className;
|
521
|
+
delete props.className;
|
522
|
+
}
|
523
|
+
|
524
|
+
// class parsing
|
525
|
+
if (isObj(props.class)) {
|
526
|
+
let k, tmp = '';
|
527
|
+
|
528
|
+
for (k in props.class)
|
529
|
+
if (props.class[k]) {
|
530
|
+
tmp && (tmp += ' ');
|
531
|
+
tmp += k
|
532
|
+
}
|
522
533
|
|
523
|
-
|
524
|
-
|
534
|
+
props.class = tmp;
|
535
|
+
}
|
536
|
+
|
537
|
+
if (~(idx = _t.indexOf('.'))) {
|
538
|
+
let className = _t.slice(idx + 1).replace(/\./g, ' ') + (props.class ? ' ' + props.class : '');
|
539
|
+
if (className) props.class = className;
|
540
|
+
_t = _t.slice(0, idx);
|
541
|
+
}
|
525
542
|
}
|
526
543
|
|
527
544
|
if (props.key !== props.key) throw new Error("Invalid NaN key");
|
package/dist/closures.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.closures={})}(this,(function(e){let t=void 0,r=e=>{},n=e=>({mount(t,r=""){t[e]=r},patch(t,r="",n){r!==n&&(t[e]=r)},unmount(r){r[e]=t}}),i={isSVG:!1,redraw:r,directives:{selected:n("selected"),checked:n("checked"),value:n("value"),innerHTML:n("innerHTML")}},o=[],l=[],d=new WeakMap,c=1,s={},f="http://www.w3.org/1999/xlink",h={show:f,actuate:f,href:f},u=e=>e
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.closures={})}(this,(function(e){let t=void 0,r=e=>{},n=e=>({mount(t,r=""){t[e]=r},patch(t,r="",n){r!==n&&(t[e]=r)},unmount(r){r[e]=t}}),i={isSVG:!1,redraw:r,directives:{selected:n("selected"),checked:n("checked"),value:n("value"),innerHTML:n("innerHTML")}},o=[],l=[],d=new WeakMap,c=1,s={},f="http://www.w3.org/1999/xlink",h={show:f,actuate:f,href:f},u=e=>null!=e,a=e=>e&&u(e.key),p=(e,r)=>(u(e)?e.key:t)===(u(r)?r.key:t),y=e=>"function"==typeof e,v=e=>"string"==typeof e,w=e=>null!==e&&"object"==typeof e,m=e=>Array.isArray(e),g=e=>JSON.stringify(e),k=e=>!u(e)||!1===e||m(e)&&0===e.length||e&&"="===e._t,R=e=>m(e)&&e.length>0,_=e=>v(e)||"number"==typeof e,S=e=>e&&1===e.vtype,N=e=>e&&2===e.vtype,E=e=>{let t=e.type;if(1===t)return e.node;if(8===t)return E(e.childRef);if(4===t)return E(e.children[0]);throw Error("Unknown ref type "+g(e))},x=e=>{let t=e.type;if(1===t)return e.node.nextSibling;if(8===t)return x(e.childRef);if(4===t)return x(e.children[e.children.length-1]);throw Error("Unknown ref type "+g(e))},V=(e,t,r)=>{let n=t.type;if(1===n)e.insertBefore(t.node,r);else if(8===n)V(e,t.childRef,r);else{if(4!==n)throw Error("Unknown ref type "+g(t));for(let n=0;n<t.children.length;n++)V(e,t.children[n],r)}},b=(e,t)=>{let r=t.type;if(1===r)e.removeChild(t.node);else if(8===r)b(e,t.childRef);else{if(4!==r)throw Error("Unknown ref type "+g(t));for(let r=0;r<t.children.length;r++)b(e,t.children[r])}},A=(e,t,r,n)=>{u(r)||(r=""),!0===r?e.setAttribute(t,""):!1===r?e.removeAttribute(t):n&&h[t]?e.setAttributeNS(h[t],t,r):e.setAttribute(t,r)},G=(e,n,i,o,s=r)=>{let f={closureId:i,closure:o,onRemove:s};if(k(e))return{...f,type:1,node:document.createTextNode("")};if(_(e))return{...f,type:1,node:document.createTextNode(e)};if(S(e)){let r,{_t:i,props:o}=e;"svg"!==i||n.isSVG||(n={...n,isSVG:!0}),r=n.isSVG?document.createElementNS("http://www.w3.org/2000/svg",i):document.createElement(i),y(o.oncreate)&&o.oncreate(r),((e,t,r)=>{for(let n in t)"key"===n||"children"===n||"oncreate"===n||n in r.directives||(n.startsWith("on")?e[n.toLowerCase()]=e=>{t[n](e),!r.manualRedraw&&r.rerender()}:A(e,n,t[n],r.isSVG))})(r,o,n);let l=o.children===t?o.children:G(o.children,n);return l!==t&&V(r,l),((e,t,r)=>{for(let n in t)n in r.directives&&r.directives[n].mount(e,t[n])})(r,o,n),{...f,type:1,node:r,children:l}}if(R(e)){let t=0,r=[];for(;t<e.length;t++)r.push(G(e[t],n));return{...f,type:4,children:r}}if(N(e)){let t=e._t(e.props);if(y(t)){let i=c++,o=d.get(e._t)||new Map,s=l.pop()||r;o.set(i,t),d.set(e._t,o);let f=e._t;return e._t=t,G(e,n,i,f,s)}return{...f,type:8,childRef:G(t,n),childState:t}}if(e instanceof Node)return{...f,type:1,node:e};if(e===t)throw Error("mount: vnode is undefined");throw Error("mount: Invalid vnode")},C=(e,r,n)=>{if(S(e))((e,t,r)=>{for(let n in t)n in r.directives&&r.directives[n].unmount(e,t[n])})(r.node,e.props,n),e.props.children!==t&&C(e.props.children,r.children,n);else if(R(e))for(let t=0;t<e.length;t++)C(e[t],r.children[t],n);else if(N(e)){let e=r.closure,t=r.closureId,i=r.onRemove,o=d.get(e);o&&t&&o.get(t)&&(o.delete(t),!o.size&&d.delete(e),i()),C(r.childState,r.childRef,n)}},I=(e,t,r,n,i)=>{let o=L(e,t,r,n,i);return o!==n&&(((e,t,r)=>{V(e,t,E(r)),b(e,r)})(e,o,n),C(r,n,i)),o},L=(e,r,n,o,l={...i})=>{if(r&&"="===r._t)return o;let c,s;if(w(o)&&(c=o.closure,s=o.closureId),N(r)&&N(n)&&(r._t===n._t||c&&s)){let t,n=r._t,i=d.get(c);i&&s&&(t=i.get(s))&&(n=t);let f=n(r.props),h=L(e,f,o.childState,o.childRef,l);return h!==o.childRef?{type:8,childRef:h,childState:f}:(o.childState=f,o)}if(n===r||k(r)&&k(n))return o;if(_(r)&&_(n))return o.node.nodeValue=r,o;if(S(r)&&S(n)&&r._t===n._t){"svg"!==r._t||l.isSVG||(l={...l,isSVG:!0}),((e,r,n,i)=>{let o;for(o in r){if("key"===o||"children"===o||"oncreate"===o||o in i.directives)continue;let t=n[o],l=r[o];t!==l&&(o.startsWith("on")?e[o.toLowerCase()]=e=>{l(e),!i.manualRedraw&&i.rerender()}:A(e,o,l,i.isSVG))}for(o in n)"key"===o||"children"===o||o in r||o in i.directives||(o.startsWith("on")?e[o.toLowerCase()]=t:e.removeAttribute(o))})(o.node,r.props,n.props,l);let e=n.props.children,i=r.props.children;return e===t?i!==t&&(o.children=G(i,l),V(o.node,o.children)):i===t?(o.node.textContent="",C(e,o.children,l),o.children=t):o.children=I(o.node,i,e,o.children,l),((e,t,r,n)=>{let i;for(i in t)i in n.directives&&n.directives[i].patch(e,t[i],r[i]);for(i in r)i in n.directives&&!(i in t)&&n.directives[i].unmount(e,r[i])})(o.node,r.props,n.props,l),o}return R(r)&&R(n)?(((e,r,n,i,o)=>{let l,d,c,s,f,h=x(i),u=Array(r.length),y=i.children,v=0,w=0,m=r.length-1,g=n.length-1;for(;v<=m&&w<=g;){if(y[w]===t){w++;continue}if(y[g]===t){g--;continue}if(l=n[w],d=r[v],p(d,l)){c=y[w],s=u[v]=I(e,d,l,c,o),v++,w++;continue}if(l=n[g],d=r[m],p(d,l)){c=y[g],s=u[m]=I(e,d,l,c,o),m--,g--;continue}if(!f){f={};for(let e=w;e<=g;e++)l=n[e],a(l)&&(f[l.key]=e)}d=r[v];let i=a(d)?f[d.key]:t;i!==t?(l=n[i],c=y[i],s=u[v]=L(e,d,l,c,o),V(e,s,E(y[w])),s!==c&&(b(e,c),C(l,c,o)),y[i]=t):(s=u[v]=G(d,o),V(e,s,E(y[w]))),v++}let k=m<r.length-1?E(u[m+1]):h;for(;v<=m;){let t=G(r[v],o);u[v]=t,V(e,t,k),v++}for(;w<=g;)c=y[w],c!==t&&(b(e,c),C(n[w],c,o)),w++;i.children=u})(e,r,n,o,l),o):r instanceof Node&&n instanceof Node?(o.node=r,o):G(r,l)};function M(e,...r){let n,i=r[0];if(!i||!w(i)||m(i)||i._t||i.props?i=s:r.shift(),i=r.length>1?{...i,children:r}:1===r.length?{...i,children:r[0]}:i,v(e)){if(i.className&&!i.class&&(i.class=i.className,delete i.className),w(i.class)){let e,t="";for(e in i.class)i.class[e]&&(t&&(t+=" "),t+=e);i.class=t}if(~(n=e.indexOf("."))){let t=e.slice(n+1).replace(/\./g," ")+(i.class?" "+i.class:"");t&&(i.class=t),e=e.slice(0,n)}}if(i.key!=i.key)throw new Error("Invalid NaN key");let o=v(e)?1:y(e)?2:t;if(o===t)throw new Error("Invalid VNode type");return{vtype:o,_t:e,key:i.key,props:i}}M.retain=e=>M("=");const T=M;e.Fragment=e=>e.children,e.app=function(e,r,n={}){let l,d={...i,manualRedraw:n.manualRedraw},c=r.$_REF;if(d.directives={...d.directives,...n.directives||{}},c!==t)throw Error("App already mounted on this node");return l=G(e,d),c=r.$_REF={ref:l,vnode:e},r.textContent="",V(r,l,t),o.push(d.rerender=(t=e)=>{c.ref=I(r,t,c.vnode,c.ref,d),c.vnode=t})&&d.rerender},e.h=M,e.m=T,e.onRemove=e=>l.push(e),e.redraw=e=>{for(let e=0;e<o.length;e++)o[e]()}}));
|