Comparing version 0.0.5 to 0.0.6
@@ -219,3 +219,3 @@ import { DataSource } from '../stream/data_source'; | ||
setInnerText(value) { | ||
if (this.node.firstChild) { | ||
if (this.node.firstChild instanceof HTMLElement) { | ||
throw new Error('Cannot combine text and child nodes into a single element'); | ||
@@ -222,0 +222,0 @@ } |
{ | ||
"name": "aurumjs", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Fast and concise declarative DOM rendering library for javascript", | ||
@@ -5,0 +5,0 @@ "main": "dist/aurumjs.js", |
@@ -1,2 +0,2 @@ | ||
var t=function(t){var e=this;this.subscribeChannel=[],this.subscribeOnceChannel=[],this.throttleCount=0,this.onAfterFire=[],t&&(t.observable&&this.makeObservable(),t.cancellationToken&&t.cancellationToken.addCancelable(function(){return e.cancelAll()}),t.throttled&&(this.throttle=t.throttled))},e={subscriptions:{configurable:!0},oneTimeSubscriptions:{configurable:!0}};e.subscriptions.get=function(){return this.subscribeChannel.length},e.oneTimeSubscriptions.get=function(){return this.subscribeOnceChannel.length},t.prototype.linkEvent=function(t){this.linkedEvents||(this.linkedEvents=[]),this.linkedEvents.push(t)},t.prototype.unlinkEvent=function(t){if(!this.linkedEvents||!this.linkedEvents.includes(t))throw new Error("Cannot unlink event that is not linked");this.linkedEvents.splice(this.linkedEvents.indexOf(t),1)},t.prototype.makeObservable=function(){this.onSubscribe||(this.onSubscribe=new t,this.onSubscribeOnce=new t,this.onCancelAll=new t,this.onCancel=new t)},t.prototype.swapSubscriptions=function(t){var e=this.subscribeChannel,n=this.subscribeOnceChannel;this.subscribeChannel=t.subscribeChannel,this.subscribeOnceChannel=t.subscribeOnceChannel,t.subscribeChannel=e,t.subscribeOnceChannel=n},t.prototype.subscribe=function(t,e){return this.onSubscribe&&this.onSubscribe.fire(),this.createSubscription(t,this.subscribeChannel,e).facade},t.prototype.hasSubscriptions=function(){return this.subscriptions>0||this.oneTimeSubscriptions>0},t.prototype.subscribeOnce=function(t){var e=this;return this.onSubscribeOnce&&this.onSubscribeOnce.fire(),new Promise(function(n){e.createSubscription(function(t){return n(t)},e.subscribeOnceChannel,t)})},t.prototype.cancelAll=function(){void 0!==this.onCancelAll&&this.onCancelAll.fire()},t.prototype.fire=function(t,e,n,i,o){if(!this.throttle||this.throttleCount++%this.throttle==0){this.isFiring=!0;for(var r=this.subscribeChannel.length,a=0;a<r;a++)this.subscribeChannel[a].callback(t);if(r=this.subscribeOnceChannel.length,this.subscribeOnceChannel.length>0){for(var s=0;s<r;s++)this.subscribeOnceChannel[s].callback(t);this.subscribeOnceChannel.length=0}if(this.linkedEvents)for(var c=0,l=this.linkedEvents;c<l.length;c+=1)l[c].fire(t,e,n,i,o);this.isFiring=!1,this.onAfterFire.length>0&&(this.onAfterFire.forEach(function(t){return t()}),this.onAfterFire.length=0)}},t.prototype.createSubscription=function(t,e,n){var i=this,o={callback:t},r={cancel:function(){i.cancel(o,e)}};return void 0!==n&&n.addCancelable(function(){return i.cancel(o,e)}),e.push(o),{subscription:o,facade:r}},t.prototype.cancel=function(t,e){var n=this,i=e.indexOf(t);i>=0&&(this.isFiring?this.onAfterFire.push(function(){return n.cancel(t,e)}):e.splice(i,1))},Object.defineProperties(t.prototype,e);var n=function(t){this.value=t,this.listeners=[]};n.prototype.update=function(t){this.value=t;for(var e=0,n=this.listeners;e<n.length;e+=1)(0,n[e])(t)},n.prototype.listen=function(t,e){var n,i=this;this.listeners.push(t);var o=function(){var e=i.listeners.indexOf(t);-1!==e&&i.listeners.splice(e,1)};return null===(n=e)||void 0===n||n.addCancelable(function(){o()}),o},n.prototype.filter=function(t,e){var i=new n;return this.listen(function(e){t(e)&&i.update(e)},e),i},n.prototype.pipe=function(t,e){this.listen(function(e){return t.update(e)},e)},n.prototype.map=function(t,e){var i=new n(t(this.value));return this.listen(function(e){i.update(t(e))},e),i},n.prototype.unique=function(t){var e=new n;return this.listen(function(t){t!==e.value&&e.update(t)},t),e},n.prototype.reduce=function(t,e){var i=new n;return this.listen(function(e){return i.update(t(i.value,e))},e),i},n.prototype.combine=function(t,e,i){var o=this,r=new n;return this.listen(function(){return r.update(e(o.value,t.value))},i),t.listen(function(){return r.update(e(o.value,t.value))},i),r},n.prototype.pick=function(t,e){var i=new n;return this.listen(function(e){i.update(e[t])},e),i},n.prototype.cancelAll=function(){this.listeners.length=0};var i=function(e){this.data=e?e.slice():[],this.onChange=new t},o={length:{configurable:!0}};o.length.get=function(){return this.data.length},i.prototype.getData=function(){return this.data.slice()},i.prototype.get=function(t){return this.data[t]},i.prototype.set=function(t,e){var n=this.data[t];n!==e&&(this.data[t]=e,this.onChange.fire({operation:"replace",target:n,count:1,index:t,items:[e],newState:this.data}))},i.prototype.push=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).push.apply(t,e),this.onChange.fire({operation:"append",count:e.length,index:this.data.length-e.length,items:e,newState:this.data})},i.prototype.unshift=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).unshift.apply(t,e),this.onChange.fire({operation:"prepend",count:e.length,items:e,index:0,newState:this.data})},i.prototype.pop=function(){var t=this.data.pop();return this.onChange.fire({operation:"removeRight",count:1,index:this.data.length,items:[t],newState:this.data}),t},i.prototype.merge=function(t){for(var e=0;e<t.length;e++)this.data[e]!==t[e]&&(this.length>e?this.set(e,t[e]):this.push(t[e]));this.length>t.length&&this.removeRight(this.length-t.length)},i.prototype.removeRight=function(t){var e=this.data.splice(this.length-t,t);this.onChange.fire({operation:"removeRight",count:t,index:this.length,items:e,newState:this.data})},i.prototype.removeLeft=function(t){var e=this.data.splice(0,t);this.onChange.fire({operation:"removeLeft",count:t,index:0,items:e,newState:this.data})},i.prototype.remove=function(t){var e=this.data.indexOf(t);-1!==e&&(this.data.splice(e,1),this.onChange.fire({operation:"remove",count:1,index:e,items:[t],newState:this.data}))},i.prototype.clear=function(){var t=this.data;this.data=[],this.onChange.fire({operation:"remove",count:t.length,index:0,items:t,newState:this.data})},i.prototype.shift=function(){var t=this.data.shift();return this.onChange.fire({operation:"removeLeft",items:[t],count:1,index:0,newState:this.data}),t},i.prototype.toArray=function(){return this.data.slice()},i.prototype.filter=function(t,e){return new r(this,t,e)},i.prototype.forEach=function(t,e){return this.data.forEach(t,e)},i.prototype.toDataSource=function(){var t=new n(this.data);return this.onChange.subscribe(function(e){t.update(e.newState)}),t},Object.defineProperties(i.prototype,o);var r=function(t){function e(e,n,i){var o=this,r=e.data.filter(n);t.call(this,r),this.parent=e,this.viewFilter=n,e.onChange.subscribe(function(t){var e,n,i;switch(t.operation){case"remove":case"removeLeft":case"removeRight":for(var r=0,a=t.items;r<a.length;r+=1)o.remove(a[r]);break;case"prepend":i=t.items.filter(o.viewFilter),(e=o).unshift.apply(e,i);break;case"append":i=t.items.filter(o.viewFilter),(n=o).push.apply(n,i);break;case"replace":var s=o.data.indexOf(t.target);if(-1!==s){o.viewFilter(t.items[0])?o.set(s,t.items[0]):o.remove(t.target);break}}},i)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.updateFilter=function(t){this.viewFilter!==t&&(this.viewFilter=t,this.refresh())},e.prototype.refresh=function(){var t;this.clear();var e=this.parent.data.filter(this.viewFilter);(t=this).push.apply(t,e)},e}(i),a=function(t){this.data=t};a.prototype.deleteNext=function(){if(this.next){var t=this.next.next;this.next.next=void 0,this.next.previous=void 0,this.next=t,this.next.previous=this}},a.prototype.deletePrevious=function(){this.previous&&(this.previous=this.previous.previous,this.previous.next=void 0,this.previous.previous=void 0)};var s=function(t){var e=this;void 0===t&&(t=[]),this.length=0,t.forEach(function(t){return e.append(t)})};s.prototype.find=function(t){for(var e=this.rootNode;e&&!t(e);)e=e.next;return e},s.prototype.append=function(t){return this.rootNode||this.lastNode?(this.lastNode.next=new a(t),this.lastNode.next.previous=this.lastNode,this.lastNode=this.lastNode.next):this.rootNode=this.lastNode=new a(t),this.length++,t},s.prototype.forEach=function(t){this.find(function(e){return t(e.data),!1})},s.prototype.prepend=function(t){return this.rootNode||this.lastNode?(this.rootNode.previous=new a(t),this.rootNode.previous.next=this.rootNode,this.rootNode=this.rootNode.previous):this.rootNode=this.lastNode=new a(t),this.length++,t},s.prototype.remove=function(t){if(t===this.rootNode.data)this.rootNode=this.rootNode.next,this.length--;else{var e=this.find(function(e){return e.next&&e.next.data===t});e&&(e.next===this.lastNode&&(this.lastNode=e),e.deleteNext(),this.length--)}};var c=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];this.cancelables=new s(t),this._isCancelled=!1},l={isCanceled:{configurable:!0}};l.isCanceled.get=function(){return this._isCancelled},c.prototype.addCancelable=function(t){return this.throwIfCancelled("attempting to add cancellable to token that is already cancelled"),this.cancelables.append(t),this.cancelables.length>200&&console.log("potential memory leak: cancellation token has over 200 clean up calls"),this},c.prototype.removeCancelable=function(t){return this.throwIfCancelled("attempting to remove cancellable from token that is already cancelled"),this.cancelables.remove(t),this},c.prototype.addDisposable=function(t){return this.addCancelable(function(){return t.dispose()}),this},c.prototype.callIfNotCancelled=function(t){this.isCanceled||t()},c.prototype.setTimeout=function(t,e){void 0===e&&(e=0);var n=setTimeout(t,e);this.addCancelable(function(){return clearTimeout(n)})},c.prototype.setInterval=function(t,e){var n=setInterval(t,e);this.addCancelable(function(){return clearInterval(n)})},c.prototype.requestAnimationFrame=function(t){var e=requestAnimationFrame(t);this.addCancelable(function(){return cancelAnimationFrame(e)})},c.prototype.animationLoop=function(t){var e=requestAnimationFrame(function n(i){t(i),e=requestAnimationFrame(n)});this.addCancelable(function(){return cancelAnimationFrame(e)})},c.prototype.throwIfCancelled=function(t){if(this.isCanceled)throw new Error(t||"cancellation token is cancelled")},c.prototype.chain=function(t,e){return void 0===e&&(e=!1),e&&t.chain(this,!1),this.addCancelable(function(){return t.cancel()}),this},c.prototype.registerDomEvent=function(t,e,n){return t.addEventListener(e,n),this.addCancelable(function(){return t.removeEventListener(e,n)}),this},c.prototype.cancel=function(){this.isCanceled||(this._isCancelled=!0,this.cancelables.forEach(function(t){return t()}),this.cancelables=void 0)},Object.defineProperties(c.prototype,l);var h=Symbol("owner"),u=function(t,e){this.domNodeName=e,this.template=t.template,this.cancellationToken=new c,this.node=this.create(t),this.initialize(t),t.onAttach&&t.onAttach(this)};u.prototype.initialize=function(t){this.node.owner=this,this.createEventHandlers(["blur","focus","click","dblclick","keydown","keyhit","keyup","mousedown, mouseup","mouseenter","mouseleave","mousewheel"],t),this.bindProps(["id","draggable","tabindex","style"],t),t.class&&this.handleClass(t.class),t.repeatModel&&(this.cachedChildren=[],this.handleRepeat(t.repeatModel))},u.prototype.bindProps=function(t,e){for(var n=0,i=t;n<i.length;n+=1){var o=i[n];e[o]&&this.assignStringSourceToAttribute(e[o],o)}},u.prototype.createEventHandlers=function(t,e){for(var i=this,o=function(){var t=a[r],o="on"+t[0].toUpperCase()+t.slice(1),s=void 0;Object.defineProperty(i,o,{get:function(){return s||(s=new n),s},set:function(){throw new Error(o+" is read only")}}),e[o]&&(e[o]instanceof n?i[o].listen(e[o].update.bind(e.onClick),i.cancellationToken):"function"==typeof e[o]&&i[o].listen(e[o],i.cancellationToken)),i.cancellationToken.registerDomEvent(i.node,t,function(t){return i[o].update(t)})},r=0,a=t;r<a.length;r+=1)o()},u.prototype.handleRepeat=function(t){var e,n=this;this.repeatData=t instanceof i?t:new i(t),this.repeatData.length&&((e=this.cachedChildren).push.apply(e,this.repeatData.toArray().map(function(t){return n.template.generate(t)})),this.renderRepeat()),this.repeatData.onChange.subscribe(function(t){var e,i;switch(t.operation){case"append":(e=n.cachedChildren).push.apply(e,t.items.map(function(t){return n.template.generate(t)}));break;case"removeLeft":n.cachedChildren.splice(0,t.count);break;case"removeRight":n.cachedChildren.splice(n.node.childElementCount-t.count,t.count);break;case"remove":n.cachedChildren.splice(t.index,t.count);break;default:n.cachedChildren.length=0,(i=n.cachedChildren).push.apply(i,n.repeatData.toArray().map(function(t){return n.template.generate(t)}))}n.renderRepeat()})},u.prototype.renderRepeat=function(){var t=this;this.rerenderPending||(setTimeout(function(){for(var e=0;e<t.cachedChildren.length;e++){if(t.node.childElementCount<=e){t.addChildren(t.cachedChildren.slice(e,t.cachedChildren.length));break}if(t.node.children[e].owner!==t.cachedChildren[e]){if(!t.cachedChildren.includes(t.node.children[e].owner)){t.node.children[e][h].remove(),e--;continue}var n=t.getChildIndex(t.cachedChildren[e].node);-1!==n?t.swapChildren(e,n):t.addChildAt(t.cachedChildren[e],e)}}for(;t.node.childElementCount>t.cachedChildren.length;)t.node[h].removeChild(t.node.lastChild[h]);t.rerenderPending=!1}),this.rerenderPending=!0)},u.prototype.assignStringSourceToAttribute=function(t,e){var n=this;"string"==typeof t?this.node[e]=t:(t.value&&(this.node[e]=t.value),t.unique(this.cancellationToken).listen(function(t){return n.node.id=t},this.cancellationToken))},u.prototype.handleClass=function(t){var e=this;if("string"==typeof t)this.node.className=t;else if(t instanceof n)t.value&&(Array.isArray(t.value)?(this.node.className=t.value.join(" "),t.unique(this.cancellationToken).listen(function(){e.node.className=t.value.join(" ")},this.cancellationToken)):(this.node.className=t.value,t.unique(this.cancellationToken).listen(function(){e.node.className=t.value},this.cancellationToken))),t.unique(this.cancellationToken).listen(function(t){return e.node.className=t},this.cancellationToken);else{var i=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");this.node.className=i;for(var o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof n&&a.unique(this.cancellationToken).listen(function(n){var i=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");e.node.className=i},this.cancellationToken)}}},u.prototype.create=function(t){var e=document.createElement(this.domNodeName);return e[h]=this,e},u.prototype.getChildIndex=function(t){for(var e=0,n=0,i=t.children;n<i.length;n+=1){if(i[n]===t)return e;e++}return-1},u.prototype.hasChild=function(t){for(var e=0,n=t.children;e<n.length;e+=1)if(n[e]===t)return!0;return!1},u.prototype.setInnerText=function(t){if(this.node.firstChild)throw new Error("Cannot combine text and child nodes into a single element");this.node.innerText=t},u.prototype.swapChildren=function(t,e){if(t!==e){var n=this.node.children[t],i=this.node.children[e];n.remove(),i.remove(),t<e?(this.addDomNodeAt(i,t),this.addDomNodeAt(n,e)):(this.addDomNodeAt(n,e),this.addDomNodeAt(i,t))}},u.prototype.addDomNodeAt=function(t,e){e>=this.node.childElementCount?this.node.appendChild(t):this.node.insertBefore(t,this.node.children[e])},u.prototype.remove=function(){this.hasParent()&&(this.node.parentElement.removeChild(this.node),this.dispose())},u.prototype.hasParent=function(){return!!this.node.parentElement},u.prototype.isConnected=function(){return this.node.isConnected},u.prototype.removeChild=function(t){t.dispose(),this.node.removeChild(t.node)},u.prototype.removeChildAt=function(t){var e=this.node.childNodes[t];if(e){var n=e[h];n.dispose(),this.node.removeChild(n.node)}},u.prototype.clearChildren=function(){for(;this.node.firstChild;)this.node.firstChild[h].dispose(),this.node.removeChild(this.node.firstChild)},u.prototype.addChild=function(t){if(!(t.node instanceof p))return this.node.appendChild(t.node)},u.prototype.addChildAt=function(t,e){if(!(t.node instanceof p))return this.addDomNodeAt(t.node,e)},u.prototype.addChildren=function(t){var e=this;if(0!==t.length){for(var i=[],o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof p||("string"==typeof a?i.push(a):a instanceof n?(i.push(a),this.setInnerText(a.value),a.listen(function(t){var o=i.reduce(function(t,e){var i;return t+(e instanceof n?(i=e.value,null!=i?i:"").toString():e)},"");e.setInnerText(o)},this.cancellationToken)):this.node.appendChild(a.node))}if(i.length){var s=i.reduce(function(t,e){var i;return t+(e instanceof n?(i=e.value,null!=i?i:"").toString():e)},"");this.setInnerText(s)}}},u.prototype.dispose=function(){this.cancellationToken.cancel()};var p=function(t){function e(e){t.call(this,e,"template"),this.ref=e.ref,this.generate=e.generator}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),d=function(){};d.attach=function(t,e){if(e[h])throw new Error("This node is already managed by aurum and cannot be used");e.appendChild(t.node),e[h]=t},d.detach=function(t){t[h]&&(t[h].dispose(),t[h]=void 0)},d.factory=function(t,e){for(var n,i=[],o=arguments.length-2;o-- >0;)i[o]=arguments[o+2];if("string"!=typeof t){for(var r,a,s=(n=[]).concat.apply(n,i).filter(function(t){return t}),c={},l=!1,h=0,u=s;h<u.length;h+=1){var d=u[h];"string"!=typeof d&&(d instanceof p&&(!d.ref||"default"===d.ref)&&(r=d),d.ref&&(c[d.ref]=d,l=!0))}return e=null!=e?e:{},r&&(e.template=r),l&&(e.templateMap=c),(a=t.prototype?new t(e||{}):t(e||{})).addChildren(s),a}};var f=function(t){function e(e){t.call(this,e,"button")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),v=function(t){function e(e){t.call(this,e,"div")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),b=function(t){function e(e){var n,i,o,r=this;t.call(this,e,"input"),e.inputValueSource?(this.node.value=null!=(i=null!=(n=e.initialValue)?n:e.inputValueSource.value)?i:"",e.inputValueSource.listen(function(t){return r.node.value=t},this.cancellationToken)):this.node.value=null!=(o=e.initialValue)?o:"",this.bindProps(["placeholder"],e),this.createEventHandlers(["input","change"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),y=function(t){function e(e){t.call(this,e,"li")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),m=function(t){function e(e){t.call(this,e,"span")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),g=function(t){function e(e){t.call(this,e,"style")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),C=function(t){function e(e){t.call(this,e,"ul")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),w=function(t){function e(e){t.call(this,e,"p")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),x=function(t){function e(e){t.call(this,e,"img"),this.bindProps(["src"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),k=function(t){function e(e){t.call(this,e,"link"),this.bindProps(["href","rel"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),_=function(t){function e(e){t.call(this,e,"canvas"),this.bindProps(["width","height"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),N=function(t){function e(e){var n=this;t.call(this,e,"switch"),this.firstRender=!0,this.templateMap=e.templateMap,this.render(e.state.value),e.state.listen(function(t){n.render(t)},this.cancellationToken)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.render=function(t){var e;if(t!==this.lastValue||this.firstRender)if(this.lastValue=t,this.firstRender=!1,this.clearChildren(),null!=t){var n=null!=(e=this.templateMap[t.toString()])?e:this.template;if(n){var i=n.generate();this.addChild(i)}}else if(this.template){var o=this.template.generate();this.addChild(o)}},e}(u);exports.ArrayDataSource=i,exports.FilteredArrayView=r,exports.DataSource=n,exports.EventEmitter=t,exports.CancellationToken=c,exports.Aurum=d,exports.AurumElement=u,exports.Template=p,exports.Button=f,exports.Div=v,exports.Input=b,exports.Li=y,exports.Span=m,exports.Style=g,exports.Ul=C,exports.P=w,exports.Img=x,exports.Link=k,exports.Canvas=_,exports.Switch=N; | ||
var t=function(t){var e=this;this.subscribeChannel=[],this.subscribeOnceChannel=[],this.throttleCount=0,this.onAfterFire=[],t&&(t.observable&&this.makeObservable(),t.cancellationToken&&t.cancellationToken.addCancelable(function(){return e.cancelAll()}),t.throttled&&(this.throttle=t.throttled))},e={subscriptions:{configurable:!0},oneTimeSubscriptions:{configurable:!0}};e.subscriptions.get=function(){return this.subscribeChannel.length},e.oneTimeSubscriptions.get=function(){return this.subscribeOnceChannel.length},t.prototype.linkEvent=function(t){this.linkedEvents||(this.linkedEvents=[]),this.linkedEvents.push(t)},t.prototype.unlinkEvent=function(t){if(!this.linkedEvents||!this.linkedEvents.includes(t))throw new Error("Cannot unlink event that is not linked");this.linkedEvents.splice(this.linkedEvents.indexOf(t),1)},t.prototype.makeObservable=function(){this.onSubscribe||(this.onSubscribe=new t,this.onSubscribeOnce=new t,this.onCancelAll=new t,this.onCancel=new t)},t.prototype.swapSubscriptions=function(t){var e=this.subscribeChannel,n=this.subscribeOnceChannel;this.subscribeChannel=t.subscribeChannel,this.subscribeOnceChannel=t.subscribeOnceChannel,t.subscribeChannel=e,t.subscribeOnceChannel=n},t.prototype.subscribe=function(t,e){return this.onSubscribe&&this.onSubscribe.fire(),this.createSubscription(t,this.subscribeChannel,e).facade},t.prototype.hasSubscriptions=function(){return this.subscriptions>0||this.oneTimeSubscriptions>0},t.prototype.subscribeOnce=function(t){var e=this;return this.onSubscribeOnce&&this.onSubscribeOnce.fire(),new Promise(function(n){e.createSubscription(function(t){return n(t)},e.subscribeOnceChannel,t)})},t.prototype.cancelAll=function(){void 0!==this.onCancelAll&&this.onCancelAll.fire()},t.prototype.fire=function(t,e,n,i,o){if(!this.throttle||this.throttleCount++%this.throttle==0){this.isFiring=!0;for(var r=this.subscribeChannel.length,a=0;a<r;a++)this.subscribeChannel[a].callback(t);if(r=this.subscribeOnceChannel.length,this.subscribeOnceChannel.length>0){for(var s=0;s<r;s++)this.subscribeOnceChannel[s].callback(t);this.subscribeOnceChannel.length=0}if(this.linkedEvents)for(var c=0,l=this.linkedEvents;c<l.length;c+=1)l[c].fire(t,e,n,i,o);this.isFiring=!1,this.onAfterFire.length>0&&(this.onAfterFire.forEach(function(t){return t()}),this.onAfterFire.length=0)}},t.prototype.createSubscription=function(t,e,n){var i=this,o={callback:t},r={cancel:function(){i.cancel(o,e)}};return void 0!==n&&n.addCancelable(function(){return i.cancel(o,e)}),e.push(o),{subscription:o,facade:r}},t.prototype.cancel=function(t,e){var n=this,i=e.indexOf(t);i>=0&&(this.isFiring?this.onAfterFire.push(function(){return n.cancel(t,e)}):e.splice(i,1))},Object.defineProperties(t.prototype,e);var n=function(t){this.value=t,this.listeners=[]};n.prototype.update=function(t){this.value=t;for(var e=0,n=this.listeners;e<n.length;e+=1)(0,n[e])(t)},n.prototype.listen=function(t,e){var n,i=this;this.listeners.push(t);var o=function(){var e=i.listeners.indexOf(t);-1!==e&&i.listeners.splice(e,1)};return null===(n=e)||void 0===n||n.addCancelable(function(){o()}),o},n.prototype.filter=function(t,e){var i=new n;return this.listen(function(e){t(e)&&i.update(e)},e),i},n.prototype.pipe=function(t,e){this.listen(function(e){return t.update(e)},e)},n.prototype.map=function(t,e){var i=new n(t(this.value));return this.listen(function(e){i.update(t(e))},e),i},n.prototype.unique=function(t){var e=new n;return this.listen(function(t){t!==e.value&&e.update(t)},t),e},n.prototype.reduce=function(t,e){var i=new n;return this.listen(function(e){return i.update(t(i.value,e))},e),i},n.prototype.combine=function(t,e,i){var o=this,r=new n;return this.listen(function(){return r.update(e(o.value,t.value))},i),t.listen(function(){return r.update(e(o.value,t.value))},i),r},n.prototype.pick=function(t,e){var i=new n;return this.listen(function(e){i.update(e[t])},e),i},n.prototype.cancelAll=function(){this.listeners.length=0};var i=function(e){this.data=e?e.slice():[],this.onChange=new t},o={length:{configurable:!0}};o.length.get=function(){return this.data.length},i.prototype.getData=function(){return this.data.slice()},i.prototype.get=function(t){return this.data[t]},i.prototype.set=function(t,e){var n=this.data[t];n!==e&&(this.data[t]=e,this.onChange.fire({operation:"replace",target:n,count:1,index:t,items:[e],newState:this.data}))},i.prototype.push=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).push.apply(t,e),this.onChange.fire({operation:"append",count:e.length,index:this.data.length-e.length,items:e,newState:this.data})},i.prototype.unshift=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).unshift.apply(t,e),this.onChange.fire({operation:"prepend",count:e.length,items:e,index:0,newState:this.data})},i.prototype.pop=function(){var t=this.data.pop();return this.onChange.fire({operation:"removeRight",count:1,index:this.data.length,items:[t],newState:this.data}),t},i.prototype.merge=function(t){for(var e=0;e<t.length;e++)this.data[e]!==t[e]&&(this.length>e?this.set(e,t[e]):this.push(t[e]));this.length>t.length&&this.removeRight(this.length-t.length)},i.prototype.removeRight=function(t){var e=this.data.splice(this.length-t,t);this.onChange.fire({operation:"removeRight",count:t,index:this.length,items:e,newState:this.data})},i.prototype.removeLeft=function(t){var e=this.data.splice(0,t);this.onChange.fire({operation:"removeLeft",count:t,index:0,items:e,newState:this.data})},i.prototype.remove=function(t){var e=this.data.indexOf(t);-1!==e&&(this.data.splice(e,1),this.onChange.fire({operation:"remove",count:1,index:e,items:[t],newState:this.data}))},i.prototype.clear=function(){var t=this.data;this.data=[],this.onChange.fire({operation:"remove",count:t.length,index:0,items:t,newState:this.data})},i.prototype.shift=function(){var t=this.data.shift();return this.onChange.fire({operation:"removeLeft",items:[t],count:1,index:0,newState:this.data}),t},i.prototype.toArray=function(){return this.data.slice()},i.prototype.filter=function(t,e){return new r(this,t,e)},i.prototype.forEach=function(t,e){return this.data.forEach(t,e)},i.prototype.toDataSource=function(){var t=new n(this.data);return this.onChange.subscribe(function(e){t.update(e.newState)}),t},Object.defineProperties(i.prototype,o);var r=function(t){function e(e,n,i){var o=this,r=e.data.filter(n);t.call(this,r),this.parent=e,this.viewFilter=n,e.onChange.subscribe(function(t){var e,n,i;switch(t.operation){case"remove":case"removeLeft":case"removeRight":for(var r=0,a=t.items;r<a.length;r+=1)o.remove(a[r]);break;case"prepend":i=t.items.filter(o.viewFilter),(e=o).unshift.apply(e,i);break;case"append":i=t.items.filter(o.viewFilter),(n=o).push.apply(n,i);break;case"replace":var s=o.data.indexOf(t.target);if(-1!==s){o.viewFilter(t.items[0])?o.set(s,t.items[0]):o.remove(t.target);break}}},i)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.updateFilter=function(t){this.viewFilter!==t&&(this.viewFilter=t,this.refresh())},e.prototype.refresh=function(){var t;this.clear();var e=this.parent.data.filter(this.viewFilter);(t=this).push.apply(t,e)},e}(i),a=function(t){this.data=t};a.prototype.deleteNext=function(){if(this.next){var t=this.next.next;this.next.next=void 0,this.next.previous=void 0,this.next=t,this.next.previous=this}},a.prototype.deletePrevious=function(){this.previous&&(this.previous=this.previous.previous,this.previous.next=void 0,this.previous.previous=void 0)};var s=function(t){var e=this;void 0===t&&(t=[]),this.length=0,t.forEach(function(t){return e.append(t)})};s.prototype.find=function(t){for(var e=this.rootNode;e&&!t(e);)e=e.next;return e},s.prototype.append=function(t){return this.rootNode||this.lastNode?(this.lastNode.next=new a(t),this.lastNode.next.previous=this.lastNode,this.lastNode=this.lastNode.next):this.rootNode=this.lastNode=new a(t),this.length++,t},s.prototype.forEach=function(t){this.find(function(e){return t(e.data),!1})},s.prototype.prepend=function(t){return this.rootNode||this.lastNode?(this.rootNode.previous=new a(t),this.rootNode.previous.next=this.rootNode,this.rootNode=this.rootNode.previous):this.rootNode=this.lastNode=new a(t),this.length++,t},s.prototype.remove=function(t){if(t===this.rootNode.data)this.rootNode=this.rootNode.next,this.length--;else{var e=this.find(function(e){return e.next&&e.next.data===t});e&&(e.next===this.lastNode&&(this.lastNode=e),e.deleteNext(),this.length--)}};var c=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];this.cancelables=new s(t),this._isCancelled=!1},l={isCanceled:{configurable:!0}};l.isCanceled.get=function(){return this._isCancelled},c.prototype.addCancelable=function(t){return this.throwIfCancelled("attempting to add cancellable to token that is already cancelled"),this.cancelables.append(t),this.cancelables.length>200&&console.log("potential memory leak: cancellation token has over 200 clean up calls"),this},c.prototype.removeCancelable=function(t){return this.throwIfCancelled("attempting to remove cancellable from token that is already cancelled"),this.cancelables.remove(t),this},c.prototype.addDisposable=function(t){return this.addCancelable(function(){return t.dispose()}),this},c.prototype.callIfNotCancelled=function(t){this.isCanceled||t()},c.prototype.setTimeout=function(t,e){void 0===e&&(e=0);var n=setTimeout(t,e);this.addCancelable(function(){return clearTimeout(n)})},c.prototype.setInterval=function(t,e){var n=setInterval(t,e);this.addCancelable(function(){return clearInterval(n)})},c.prototype.requestAnimationFrame=function(t){var e=requestAnimationFrame(t);this.addCancelable(function(){return cancelAnimationFrame(e)})},c.prototype.animationLoop=function(t){var e=requestAnimationFrame(function n(i){t(i),e=requestAnimationFrame(n)});this.addCancelable(function(){return cancelAnimationFrame(e)})},c.prototype.throwIfCancelled=function(t){if(this.isCanceled)throw new Error(t||"cancellation token is cancelled")},c.prototype.chain=function(t,e){return void 0===e&&(e=!1),e&&t.chain(this,!1),this.addCancelable(function(){return t.cancel()}),this},c.prototype.registerDomEvent=function(t,e,n){return t.addEventListener(e,n),this.addCancelable(function(){return t.removeEventListener(e,n)}),this},c.prototype.cancel=function(){this.isCanceled||(this._isCancelled=!0,this.cancelables.forEach(function(t){return t()}),this.cancelables=void 0)},Object.defineProperties(c.prototype,l);var h=Symbol("owner"),u=function(t,e){this.domNodeName=e,this.template=t.template,this.cancellationToken=new c,this.node=this.create(t),this.initialize(t),t.onAttach&&t.onAttach(this)};u.prototype.initialize=function(t){this.node.owner=this,this.createEventHandlers(["blur","focus","click","dblclick","keydown","keyhit","keyup","mousedown, mouseup","mouseenter","mouseleave","mousewheel"],t),this.bindProps(["id","draggable","tabindex","style"],t),t.class&&this.handleClass(t.class),t.repeatModel&&(this.cachedChildren=[],this.handleRepeat(t.repeatModel))},u.prototype.bindProps=function(t,e){for(var n=0,i=t;n<i.length;n+=1){var o=i[n];e[o]&&this.assignStringSourceToAttribute(e[o],o)}},u.prototype.createEventHandlers=function(t,e){for(var i=this,o=function(){var t=a[r],o="on"+t[0].toUpperCase()+t.slice(1),s=void 0;Object.defineProperty(i,o,{get:function(){return s||(s=new n),s},set:function(){throw new Error(o+" is read only")}}),e[o]&&(e[o]instanceof n?i[o].listen(e[o].update.bind(e.onClick),i.cancellationToken):"function"==typeof e[o]&&i[o].listen(e[o],i.cancellationToken)),i.cancellationToken.registerDomEvent(i.node,t,function(t){return i[o].update(t)})},r=0,a=t;r<a.length;r+=1)o()},u.prototype.handleRepeat=function(t){var e,n=this;this.repeatData=t instanceof i?t:new i(t),this.repeatData.length&&((e=this.cachedChildren).push.apply(e,this.repeatData.toArray().map(function(t){return n.template.generate(t)})),this.renderRepeat()),this.repeatData.onChange.subscribe(function(t){var e,i;switch(t.operation){case"append":(e=n.cachedChildren).push.apply(e,t.items.map(function(t){return n.template.generate(t)}));break;case"removeLeft":n.cachedChildren.splice(0,t.count);break;case"removeRight":n.cachedChildren.splice(n.node.childElementCount-t.count,t.count);break;case"remove":n.cachedChildren.splice(t.index,t.count);break;default:n.cachedChildren.length=0,(i=n.cachedChildren).push.apply(i,n.repeatData.toArray().map(function(t){return n.template.generate(t)}))}n.renderRepeat()})},u.prototype.renderRepeat=function(){var t=this;this.rerenderPending||(setTimeout(function(){for(var e=0;e<t.cachedChildren.length;e++){if(t.node.childElementCount<=e){t.addChildren(t.cachedChildren.slice(e,t.cachedChildren.length));break}if(t.node.children[e].owner!==t.cachedChildren[e]){if(!t.cachedChildren.includes(t.node.children[e].owner)){t.node.children[e][h].remove(),e--;continue}var n=t.getChildIndex(t.cachedChildren[e].node);-1!==n?t.swapChildren(e,n):t.addChildAt(t.cachedChildren[e],e)}}for(;t.node.childElementCount>t.cachedChildren.length;)t.node[h].removeChild(t.node.lastChild[h]);t.rerenderPending=!1}),this.rerenderPending=!0)},u.prototype.assignStringSourceToAttribute=function(t,e){var n=this;"string"==typeof t?this.node[e]=t:(t.value&&(this.node[e]=t.value),t.unique(this.cancellationToken).listen(function(t){return n.node.id=t},this.cancellationToken))},u.prototype.handleClass=function(t){var e=this;if("string"==typeof t)this.node.className=t;else if(t instanceof n)t.value&&(Array.isArray(t.value)?(this.node.className=t.value.join(" "),t.unique(this.cancellationToken).listen(function(){e.node.className=t.value.join(" ")},this.cancellationToken)):(this.node.className=t.value,t.unique(this.cancellationToken).listen(function(){e.node.className=t.value},this.cancellationToken))),t.unique(this.cancellationToken).listen(function(t){return e.node.className=t},this.cancellationToken);else{var i=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");this.node.className=i;for(var o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof n&&a.unique(this.cancellationToken).listen(function(n){var i=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");e.node.className=i},this.cancellationToken)}}},u.prototype.create=function(t){var e=document.createElement(this.domNodeName);return e[h]=this,e},u.prototype.getChildIndex=function(t){for(var e=0,n=0,i=t.children;n<i.length;n+=1){if(i[n]===t)return e;e++}return-1},u.prototype.hasChild=function(t){for(var e=0,n=t.children;e<n.length;e+=1)if(n[e]===t)return!0;return!1},u.prototype.setInnerText=function(t){if(this.node.firstChild instanceof HTMLElement)throw new Error("Cannot combine text and child nodes into a single element");this.node.innerText=t},u.prototype.swapChildren=function(t,e){if(t!==e){var n=this.node.children[t],i=this.node.children[e];n.remove(),i.remove(),t<e?(this.addDomNodeAt(i,t),this.addDomNodeAt(n,e)):(this.addDomNodeAt(n,e),this.addDomNodeAt(i,t))}},u.prototype.addDomNodeAt=function(t,e){e>=this.node.childElementCount?this.node.appendChild(t):this.node.insertBefore(t,this.node.children[e])},u.prototype.remove=function(){this.hasParent()&&(this.node.parentElement.removeChild(this.node),this.dispose())},u.prototype.hasParent=function(){return!!this.node.parentElement},u.prototype.isConnected=function(){return this.node.isConnected},u.prototype.removeChild=function(t){t.dispose(),this.node.removeChild(t.node)},u.prototype.removeChildAt=function(t){var e=this.node.childNodes[t];if(e){var n=e[h];n.dispose(),this.node.removeChild(n.node)}},u.prototype.clearChildren=function(){for(;this.node.firstChild;)this.node.firstChild[h].dispose(),this.node.removeChild(this.node.firstChild)},u.prototype.addChild=function(t){if(!(t.node instanceof p))return this.node.appendChild(t.node)},u.prototype.addChildAt=function(t,e){if(!(t.node instanceof p))return this.addDomNodeAt(t.node,e)},u.prototype.addChildren=function(t){var e=this;if(0!==t.length){for(var i=[],o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof p||("string"==typeof a?i.push(a):a instanceof n?(i.push(a),this.setInnerText(a.value),a.listen(function(t){var o=i.reduce(function(t,e){var i;return t+(e instanceof n?(i=e.value,null!=i?i:"").toString():e)},"");e.setInnerText(o)},this.cancellationToken)):this.node.appendChild(a.node))}if(i.length){var s=i.reduce(function(t,e){var i;return t+(e instanceof n?(i=e.value,null!=i?i:"").toString():e)},"");this.setInnerText(s)}}},u.prototype.dispose=function(){this.cancellationToken.cancel()};var p=function(t){function e(e){t.call(this,e,"template"),this.ref=e.ref,this.generate=e.generator}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),d=function(){};d.attach=function(t,e){if(e[h])throw new Error("This node is already managed by aurum and cannot be used");e.appendChild(t.node),e[h]=t},d.detach=function(t){t[h]&&(t[h].dispose(),t[h]=void 0)},d.factory=function(t,e){for(var n,i=[],o=arguments.length-2;o-- >0;)i[o]=arguments[o+2];if("string"!=typeof t){for(var r,a,s=(n=[]).concat.apply(n,i).filter(function(t){return t}),c={},l=!1,h=0,u=s;h<u.length;h+=1){var d=u[h];"string"!=typeof d&&(d instanceof p&&(!d.ref||"default"===d.ref)&&(r=d),d.ref&&(c[d.ref]=d,l=!0))}return e=null!=e?e:{},r&&(e.template=r),l&&(e.templateMap=c),(a=t.prototype?new t(e||{}):t(e||{})).addChildren(s),a}};var f=function(t){function e(e){t.call(this,e,"button")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),v=function(t){function e(e){t.call(this,e,"div")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),b=function(t){function e(e){var n,i,o,r=this;t.call(this,e,"input"),e.inputValueSource?(this.node.value=null!=(i=null!=(n=e.initialValue)?n:e.inputValueSource.value)?i:"",e.inputValueSource.listen(function(t){return r.node.value=t},this.cancellationToken)):this.node.value=null!=(o=e.initialValue)?o:"",this.bindProps(["placeholder"],e),this.createEventHandlers(["input","change"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),y=function(t){function e(e){t.call(this,e,"li")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),m=function(t){function e(e){t.call(this,e,"span")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),g=function(t){function e(e){t.call(this,e,"style")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),C=function(t){function e(e){t.call(this,e,"ul")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),w=function(t){function e(e){t.call(this,e,"p")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),x=function(t){function e(e){t.call(this,e,"img"),this.bindProps(["src"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),k=function(t){function e(e){t.call(this,e,"link"),this.bindProps(["href","rel"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),_=function(t){function e(e){t.call(this,e,"canvas"),this.bindProps(["width","height"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u),N=function(t){function e(e){var n=this;t.call(this,e,"switch"),this.firstRender=!0,this.templateMap=e.templateMap,this.render(e.state.value),e.state.listen(function(t){n.render(t)},this.cancellationToken)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.render=function(t){var e;if(t!==this.lastValue||this.firstRender)if(this.lastValue=t,this.firstRender=!1,this.clearChildren(),null!=t){var n=null!=(e=this.templateMap[t.toString()])?e:this.template;if(n){var i=n.generate();this.addChild(i)}}else if(this.template){var o=this.template.generate();this.addChild(o)}},e}(u);exports.ArrayDataSource=i,exports.FilteredArrayView=r,exports.DataSource=n,exports.EventEmitter=t,exports.CancellationToken=c,exports.Aurum=d,exports.AurumElement=u,exports.Template=p,exports.Button=f,exports.Div=v,exports.Input=b,exports.Li=y,exports.Span=m,exports.Style=g,exports.Ul=C,exports.P=w,exports.Img=x,exports.Link=k,exports.Canvas=_,exports.Switch=N; | ||
//# sourceMappingURL=aurumjs.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.aurumjs={})}(this,function(t){var e=function(t){var e=this;this.subscribeChannel=[],this.subscribeOnceChannel=[],this.throttleCount=0,this.onAfterFire=[],t&&(t.observable&&this.makeObservable(),t.cancellationToken&&t.cancellationToken.addCancelable(function(){return e.cancelAll()}),t.throttled&&(this.throttle=t.throttled))},n={subscriptions:{configurable:!0},oneTimeSubscriptions:{configurable:!0}};n.subscriptions.get=function(){return this.subscribeChannel.length},n.oneTimeSubscriptions.get=function(){return this.subscribeOnceChannel.length},e.prototype.linkEvent=function(t){this.linkedEvents||(this.linkedEvents=[]),this.linkedEvents.push(t)},e.prototype.unlinkEvent=function(t){if(!this.linkedEvents||!this.linkedEvents.includes(t))throw new Error("Cannot unlink event that is not linked");this.linkedEvents.splice(this.linkedEvents.indexOf(t),1)},e.prototype.makeObservable=function(){this.onSubscribe||(this.onSubscribe=new e,this.onSubscribeOnce=new e,this.onCancelAll=new e,this.onCancel=new e)},e.prototype.swapSubscriptions=function(t){var e=this.subscribeChannel,n=this.subscribeOnceChannel;this.subscribeChannel=t.subscribeChannel,this.subscribeOnceChannel=t.subscribeOnceChannel,t.subscribeChannel=e,t.subscribeOnceChannel=n},e.prototype.subscribe=function(t,e){return this.onSubscribe&&this.onSubscribe.fire(),this.createSubscription(t,this.subscribeChannel,e).facade},e.prototype.hasSubscriptions=function(){return this.subscriptions>0||this.oneTimeSubscriptions>0},e.prototype.subscribeOnce=function(t){var e=this;return this.onSubscribeOnce&&this.onSubscribeOnce.fire(),new Promise(function(n){e.createSubscription(function(t){return n(t)},e.subscribeOnceChannel,t)})},e.prototype.cancelAll=function(){void 0!==this.onCancelAll&&this.onCancelAll.fire()},e.prototype.fire=function(t,e,n,i,o){if(!this.throttle||this.throttleCount++%this.throttle==0){this.isFiring=!0;for(var r=this.subscribeChannel.length,a=0;a<r;a++)this.subscribeChannel[a].callback(t);if(r=this.subscribeOnceChannel.length,this.subscribeOnceChannel.length>0){for(var s=0;s<r;s++)this.subscribeOnceChannel[s].callback(t);this.subscribeOnceChannel.length=0}if(this.linkedEvents)for(var c=0,l=this.linkedEvents;c<l.length;c+=1)l[c].fire(t,e,n,i,o);this.isFiring=!1,this.onAfterFire.length>0&&(this.onAfterFire.forEach(function(t){return t()}),this.onAfterFire.length=0)}},e.prototype.createSubscription=function(t,e,n){var i=this,o={callback:t},r={cancel:function(){i.cancel(o,e)}};return void 0!==n&&n.addCancelable(function(){return i.cancel(o,e)}),e.push(o),{subscription:o,facade:r}},e.prototype.cancel=function(t,e){var n=this,i=e.indexOf(t);i>=0&&(this.isFiring?this.onAfterFire.push(function(){return n.cancel(t,e)}):e.splice(i,1))},Object.defineProperties(e.prototype,n);var i=function(t){this.value=t,this.listeners=[]};i.prototype.update=function(t){this.value=t;for(var e=0,n=this.listeners;e<n.length;e+=1)(0,n[e])(t)},i.prototype.listen=function(t,e){var n,i=this;this.listeners.push(t);var o=function(){var e=i.listeners.indexOf(t);-1!==e&&i.listeners.splice(e,1)};return null===(n=e)||void 0===n||n.addCancelable(function(){o()}),o},i.prototype.filter=function(t,e){var n=new i;return this.listen(function(e){t(e)&&n.update(e)},e),n},i.prototype.pipe=function(t,e){this.listen(function(e){return t.update(e)},e)},i.prototype.map=function(t,e){var n=new i(t(this.value));return this.listen(function(e){n.update(t(e))},e),n},i.prototype.unique=function(t){var e=new i;return this.listen(function(t){t!==e.value&&e.update(t)},t),e},i.prototype.reduce=function(t,e){var n=new i;return this.listen(function(e){return n.update(t(n.value,e))},e),n},i.prototype.combine=function(t,e,n){var o=this,r=new i;return this.listen(function(){return r.update(e(o.value,t.value))},n),t.listen(function(){return r.update(e(o.value,t.value))},n),r},i.prototype.pick=function(t,e){var n=new i;return this.listen(function(e){n.update(e[t])},e),n},i.prototype.cancelAll=function(){this.listeners.length=0};var o=function(t){this.data=t?t.slice():[],this.onChange=new e},r={length:{configurable:!0}};r.length.get=function(){return this.data.length},o.prototype.getData=function(){return this.data.slice()},o.prototype.get=function(t){return this.data[t]},o.prototype.set=function(t,e){var n=this.data[t];n!==e&&(this.data[t]=e,this.onChange.fire({operation:"replace",target:n,count:1,index:t,items:[e],newState:this.data}))},o.prototype.push=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).push.apply(t,e),this.onChange.fire({operation:"append",count:e.length,index:this.data.length-e.length,items:e,newState:this.data})},o.prototype.unshift=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).unshift.apply(t,e),this.onChange.fire({operation:"prepend",count:e.length,items:e,index:0,newState:this.data})},o.prototype.pop=function(){var t=this.data.pop();return this.onChange.fire({operation:"removeRight",count:1,index:this.data.length,items:[t],newState:this.data}),t},o.prototype.merge=function(t){for(var e=0;e<t.length;e++)this.data[e]!==t[e]&&(this.length>e?this.set(e,t[e]):this.push(t[e]));this.length>t.length&&this.removeRight(this.length-t.length)},o.prototype.removeRight=function(t){var e=this.data.splice(this.length-t,t);this.onChange.fire({operation:"removeRight",count:t,index:this.length,items:e,newState:this.data})},o.prototype.removeLeft=function(t){var e=this.data.splice(0,t);this.onChange.fire({operation:"removeLeft",count:t,index:0,items:e,newState:this.data})},o.prototype.remove=function(t){var e=this.data.indexOf(t);-1!==e&&(this.data.splice(e,1),this.onChange.fire({operation:"remove",count:1,index:e,items:[t],newState:this.data}))},o.prototype.clear=function(){var t=this.data;this.data=[],this.onChange.fire({operation:"remove",count:t.length,index:0,items:t,newState:this.data})},o.prototype.shift=function(){var t=this.data.shift();return this.onChange.fire({operation:"removeLeft",items:[t],count:1,index:0,newState:this.data}),t},o.prototype.toArray=function(){return this.data.slice()},o.prototype.filter=function(t,e){return new a(this,t,e)},o.prototype.forEach=function(t,e){return this.data.forEach(t,e)},o.prototype.toDataSource=function(){var t=new i(this.data);return this.onChange.subscribe(function(e){t.update(e.newState)}),t},Object.defineProperties(o.prototype,r);var a=function(t){function e(e,n,i){var o=this,r=e.data.filter(n);t.call(this,r),this.parent=e,this.viewFilter=n,e.onChange.subscribe(function(t){var e,n,i;switch(t.operation){case"remove":case"removeLeft":case"removeRight":for(var r=0,a=t.items;r<a.length;r+=1)o.remove(a[r]);break;case"prepend":i=t.items.filter(o.viewFilter),(e=o).unshift.apply(e,i);break;case"append":i=t.items.filter(o.viewFilter),(n=o).push.apply(n,i);break;case"replace":var s=o.data.indexOf(t.target);if(-1!==s){o.viewFilter(t.items[0])?o.set(s,t.items[0]):o.remove(t.target);break}}},i)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.updateFilter=function(t){this.viewFilter!==t&&(this.viewFilter=t,this.refresh())},e.prototype.refresh=function(){var t;this.clear();var e=this.parent.data.filter(this.viewFilter);(t=this).push.apply(t,e)},e}(o),s=function(t){this.data=t};s.prototype.deleteNext=function(){if(this.next){var t=this.next.next;this.next.next=void 0,this.next.previous=void 0,this.next=t,this.next.previous=this}},s.prototype.deletePrevious=function(){this.previous&&(this.previous=this.previous.previous,this.previous.next=void 0,this.previous.previous=void 0)};var c=function(t){var e=this;void 0===t&&(t=[]),this.length=0,t.forEach(function(t){return e.append(t)})};c.prototype.find=function(t){for(var e=this.rootNode;e&&!t(e);)e=e.next;return e},c.prototype.append=function(t){return this.rootNode||this.lastNode?(this.lastNode.next=new s(t),this.lastNode.next.previous=this.lastNode,this.lastNode=this.lastNode.next):this.rootNode=this.lastNode=new s(t),this.length++,t},c.prototype.forEach=function(t){this.find(function(e){return t(e.data),!1})},c.prototype.prepend=function(t){return this.rootNode||this.lastNode?(this.rootNode.previous=new s(t),this.rootNode.previous.next=this.rootNode,this.rootNode=this.rootNode.previous):this.rootNode=this.lastNode=new s(t),this.length++,t},c.prototype.remove=function(t){if(t===this.rootNode.data)this.rootNode=this.rootNode.next,this.length--;else{var e=this.find(function(e){return e.next&&e.next.data===t});e&&(e.next===this.lastNode&&(this.lastNode=e),e.deleteNext(),this.length--)}};var l=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];this.cancelables=new c(t),this._isCancelled=!1},h={isCanceled:{configurable:!0}};h.isCanceled.get=function(){return this._isCancelled},l.prototype.addCancelable=function(t){return this.throwIfCancelled("attempting to add cancellable to token that is already cancelled"),this.cancelables.append(t),this.cancelables.length>200&&console.log("potential memory leak: cancellation token has over 200 clean up calls"),this},l.prototype.removeCancelable=function(t){return this.throwIfCancelled("attempting to remove cancellable from token that is already cancelled"),this.cancelables.remove(t),this},l.prototype.addDisposable=function(t){return this.addCancelable(function(){return t.dispose()}),this},l.prototype.callIfNotCancelled=function(t){this.isCanceled||t()},l.prototype.setTimeout=function(t,e){void 0===e&&(e=0);var n=setTimeout(t,e);this.addCancelable(function(){return clearTimeout(n)})},l.prototype.setInterval=function(t,e){var n=setInterval(t,e);this.addCancelable(function(){return clearInterval(n)})},l.prototype.requestAnimationFrame=function(t){var e=requestAnimationFrame(t);this.addCancelable(function(){return cancelAnimationFrame(e)})},l.prototype.animationLoop=function(t){var e=requestAnimationFrame(function n(i){t(i),e=requestAnimationFrame(n)});this.addCancelable(function(){return cancelAnimationFrame(e)})},l.prototype.throwIfCancelled=function(t){if(this.isCanceled)throw new Error(t||"cancellation token is cancelled")},l.prototype.chain=function(t,e){return void 0===e&&(e=!1),e&&t.chain(this,!1),this.addCancelable(function(){return t.cancel()}),this},l.prototype.registerDomEvent=function(t,e,n){return t.addEventListener(e,n),this.addCancelable(function(){return t.removeEventListener(e,n)}),this},l.prototype.cancel=function(){this.isCanceled||(this._isCancelled=!0,this.cancelables.forEach(function(t){return t()}),this.cancelables=void 0)},Object.defineProperties(l.prototype,h);var u=Symbol("owner"),p=function(t,e){this.domNodeName=e,this.template=t.template,this.cancellationToken=new l,this.node=this.create(t),this.initialize(t),t.onAttach&&t.onAttach(this)};p.prototype.initialize=function(t){this.node.owner=this,this.createEventHandlers(["blur","focus","click","dblclick","keydown","keyhit","keyup","mousedown, mouseup","mouseenter","mouseleave","mousewheel"],t),this.bindProps(["id","draggable","tabindex","style"],t),t.class&&this.handleClass(t.class),t.repeatModel&&(this.cachedChildren=[],this.handleRepeat(t.repeatModel))},p.prototype.bindProps=function(t,e){for(var n=0,i=t;n<i.length;n+=1){var o=i[n];e[o]&&this.assignStringSourceToAttribute(e[o],o)}},p.prototype.createEventHandlers=function(t,e){for(var n=this,o=function(){var t=a[r],o="on"+t[0].toUpperCase()+t.slice(1),s=void 0;Object.defineProperty(n,o,{get:function(){return s||(s=new i),s},set:function(){throw new Error(o+" is read only")}}),e[o]&&(e[o]instanceof i?n[o].listen(e[o].update.bind(e.onClick),n.cancellationToken):"function"==typeof e[o]&&n[o].listen(e[o],n.cancellationToken)),n.cancellationToken.registerDomEvent(n.node,t,function(t){return n[o].update(t)})},r=0,a=t;r<a.length;r+=1)o()},p.prototype.handleRepeat=function(t){var e,n=this;this.repeatData=t instanceof o?t:new o(t),this.repeatData.length&&((e=this.cachedChildren).push.apply(e,this.repeatData.toArray().map(function(t){return n.template.generate(t)})),this.renderRepeat()),this.repeatData.onChange.subscribe(function(t){var e,i;switch(t.operation){case"append":(e=n.cachedChildren).push.apply(e,t.items.map(function(t){return n.template.generate(t)}));break;case"removeLeft":n.cachedChildren.splice(0,t.count);break;case"removeRight":n.cachedChildren.splice(n.node.childElementCount-t.count,t.count);break;case"remove":n.cachedChildren.splice(t.index,t.count);break;default:n.cachedChildren.length=0,(i=n.cachedChildren).push.apply(i,n.repeatData.toArray().map(function(t){return n.template.generate(t)}))}n.renderRepeat()})},p.prototype.renderRepeat=function(){var t=this;this.rerenderPending||(setTimeout(function(){for(var e=0;e<t.cachedChildren.length;e++){if(t.node.childElementCount<=e){t.addChildren(t.cachedChildren.slice(e,t.cachedChildren.length));break}if(t.node.children[e].owner!==t.cachedChildren[e]){if(!t.cachedChildren.includes(t.node.children[e].owner)){t.node.children[e][u].remove(),e--;continue}var n=t.getChildIndex(t.cachedChildren[e].node);-1!==n?t.swapChildren(e,n):t.addChildAt(t.cachedChildren[e],e)}}for(;t.node.childElementCount>t.cachedChildren.length;)t.node[u].removeChild(t.node.lastChild[u]);t.rerenderPending=!1}),this.rerenderPending=!0)},p.prototype.assignStringSourceToAttribute=function(t,e){var n=this;"string"==typeof t?this.node[e]=t:(t.value&&(this.node[e]=t.value),t.unique(this.cancellationToken).listen(function(t){return n.node.id=t},this.cancellationToken))},p.prototype.handleClass=function(t){var e=this;if("string"==typeof t)this.node.className=t;else if(t instanceof i)t.value&&(Array.isArray(t.value)?(this.node.className=t.value.join(" "),t.unique(this.cancellationToken).listen(function(){e.node.className=t.value.join(" ")},this.cancellationToken)):(this.node.className=t.value,t.unique(this.cancellationToken).listen(function(){e.node.className=t.value},this.cancellationToken))),t.unique(this.cancellationToken).listen(function(t){return e.node.className=t},this.cancellationToken);else{var n=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");this.node.className=n;for(var o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof i&&a.unique(this.cancellationToken).listen(function(n){var i=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");e.node.className=i},this.cancellationToken)}}},p.prototype.create=function(t){var e=document.createElement(this.domNodeName);return e[u]=this,e},p.prototype.getChildIndex=function(t){for(var e=0,n=0,i=t.children;n<i.length;n+=1){if(i[n]===t)return e;e++}return-1},p.prototype.hasChild=function(t){for(var e=0,n=t.children;e<n.length;e+=1)if(n[e]===t)return!0;return!1},p.prototype.setInnerText=function(t){if(this.node.firstChild)throw new Error("Cannot combine text and child nodes into a single element");this.node.innerText=t},p.prototype.swapChildren=function(t,e){if(t!==e){var n=this.node.children[t],i=this.node.children[e];n.remove(),i.remove(),t<e?(this.addDomNodeAt(i,t),this.addDomNodeAt(n,e)):(this.addDomNodeAt(n,e),this.addDomNodeAt(i,t))}},p.prototype.addDomNodeAt=function(t,e){e>=this.node.childElementCount?this.node.appendChild(t):this.node.insertBefore(t,this.node.children[e])},p.prototype.remove=function(){this.hasParent()&&(this.node.parentElement.removeChild(this.node),this.dispose())},p.prototype.hasParent=function(){return!!this.node.parentElement},p.prototype.isConnected=function(){return this.node.isConnected},p.prototype.removeChild=function(t){t.dispose(),this.node.removeChild(t.node)},p.prototype.removeChildAt=function(t){var e=this.node.childNodes[t];if(e){var n=e[u];n.dispose(),this.node.removeChild(n.node)}},p.prototype.clearChildren=function(){for(;this.node.firstChild;)this.node.firstChild[u].dispose(),this.node.removeChild(this.node.firstChild)},p.prototype.addChild=function(t){if(!(t.node instanceof d))return this.node.appendChild(t.node)},p.prototype.addChildAt=function(t,e){if(!(t.node instanceof d))return this.addDomNodeAt(t.node,e)},p.prototype.addChildren=function(t){var e=this;if(0!==t.length){for(var n=[],o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof d||("string"==typeof a?n.push(a):a instanceof i?(n.push(a),this.setInnerText(a.value),a.listen(function(t){var o=n.reduce(function(t,e){var n;return t+(e instanceof i?(n=e.value,null!=n?n:"").toString():e)},"");e.setInnerText(o)},this.cancellationToken)):this.node.appendChild(a.node))}if(n.length){var s=n.reduce(function(t,e){var n;return t+(e instanceof i?(n=e.value,null!=n?n:"").toString():e)},"");this.setInnerText(s)}}},p.prototype.dispose=function(){this.cancellationToken.cancel()};var d=function(t){function e(e){t.call(this,e,"template"),this.ref=e.ref,this.generate=e.generator}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),f=function(){};f.attach=function(t,e){if(e[u])throw new Error("This node is already managed by aurum and cannot be used");e.appendChild(t.node),e[u]=t},f.detach=function(t){t[u]&&(t[u].dispose(),t[u]=void 0)},f.factory=function(t,e){for(var n,i=[],o=arguments.length-2;o-- >0;)i[o]=arguments[o+2];if("string"!=typeof t){for(var r,a,s=(n=[]).concat.apply(n,i).filter(function(t){return t}),c={},l=!1,h=0,u=s;h<u.length;h+=1){var p=u[h];"string"!=typeof p&&(p instanceof d&&(!p.ref||"default"===p.ref)&&(r=p),p.ref&&(c[p.ref]=p,l=!0))}return e=null!=e?e:{},r&&(e.template=r),l&&(e.templateMap=c),(a=t.prototype?new t(e||{}):t(e||{})).addChildren(s),a}};var v=function(t){function e(e){t.call(this,e,"button")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),b=function(t){function e(e){t.call(this,e,"div")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),y=function(t){function e(e){var n,i,o,r=this;t.call(this,e,"input"),e.inputValueSource?(this.node.value=null!=(i=null!=(n=e.initialValue)?n:e.inputValueSource.value)?i:"",e.inputValueSource.listen(function(t){return r.node.value=t},this.cancellationToken)):this.node.value=null!=(o=e.initialValue)?o:"",this.bindProps(["placeholder"],e),this.createEventHandlers(["input","change"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),m=function(t){function e(e){t.call(this,e,"li")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),g=function(t){function e(e){t.call(this,e,"span")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),C=function(t){function e(e){t.call(this,e,"style")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),w=function(t){function e(e){t.call(this,e,"ul")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),k=function(t){function e(e){t.call(this,e,"p")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),_=function(t){function e(e){t.call(this,e,"img"),this.bindProps(["src"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),x=function(t){function e(e){t.call(this,e,"link"),this.bindProps(["href","rel"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),N=function(t){function e(e){t.call(this,e,"canvas"),this.bindProps(["width","height"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),S=function(t){function e(e){var n=this;t.call(this,e,"switch"),this.firstRender=!0,this.templateMap=e.templateMap,this.render(e.state.value),e.state.listen(function(t){n.render(t)},this.cancellationToken)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.render=function(t){var e;if(t!==this.lastValue||this.firstRender)if(this.lastValue=t,this.firstRender=!1,this.clearChildren(),null!=t){var n=null!=(e=this.templateMap[t.toString()])?e:this.template;if(n){var i=n.generate();this.addChild(i)}}else if(this.template){var o=this.template.generate();this.addChild(o)}},e}(p);t.ArrayDataSource=o,t.FilteredArrayView=a,t.DataSource=i,t.EventEmitter=e,t.CancellationToken=l,t.Aurum=f,t.AurumElement=p,t.Template=d,t.Button=v,t.Div=b,t.Input=y,t.Li=m,t.Span=g,t.Style=C,t.Ul=w,t.P=k,t.Img=_,t.Link=x,t.Canvas=N,t.Switch=S}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.aurumjs={})}(this,function(t){var e=function(t){var e=this;this.subscribeChannel=[],this.subscribeOnceChannel=[],this.throttleCount=0,this.onAfterFire=[],t&&(t.observable&&this.makeObservable(),t.cancellationToken&&t.cancellationToken.addCancelable(function(){return e.cancelAll()}),t.throttled&&(this.throttle=t.throttled))},n={subscriptions:{configurable:!0},oneTimeSubscriptions:{configurable:!0}};n.subscriptions.get=function(){return this.subscribeChannel.length},n.oneTimeSubscriptions.get=function(){return this.subscribeOnceChannel.length},e.prototype.linkEvent=function(t){this.linkedEvents||(this.linkedEvents=[]),this.linkedEvents.push(t)},e.prototype.unlinkEvent=function(t){if(!this.linkedEvents||!this.linkedEvents.includes(t))throw new Error("Cannot unlink event that is not linked");this.linkedEvents.splice(this.linkedEvents.indexOf(t),1)},e.prototype.makeObservable=function(){this.onSubscribe||(this.onSubscribe=new e,this.onSubscribeOnce=new e,this.onCancelAll=new e,this.onCancel=new e)},e.prototype.swapSubscriptions=function(t){var e=this.subscribeChannel,n=this.subscribeOnceChannel;this.subscribeChannel=t.subscribeChannel,this.subscribeOnceChannel=t.subscribeOnceChannel,t.subscribeChannel=e,t.subscribeOnceChannel=n},e.prototype.subscribe=function(t,e){return this.onSubscribe&&this.onSubscribe.fire(),this.createSubscription(t,this.subscribeChannel,e).facade},e.prototype.hasSubscriptions=function(){return this.subscriptions>0||this.oneTimeSubscriptions>0},e.prototype.subscribeOnce=function(t){var e=this;return this.onSubscribeOnce&&this.onSubscribeOnce.fire(),new Promise(function(n){e.createSubscription(function(t){return n(t)},e.subscribeOnceChannel,t)})},e.prototype.cancelAll=function(){void 0!==this.onCancelAll&&this.onCancelAll.fire()},e.prototype.fire=function(t,e,n,i,o){if(!this.throttle||this.throttleCount++%this.throttle==0){this.isFiring=!0;for(var r=this.subscribeChannel.length,a=0;a<r;a++)this.subscribeChannel[a].callback(t);if(r=this.subscribeOnceChannel.length,this.subscribeOnceChannel.length>0){for(var s=0;s<r;s++)this.subscribeOnceChannel[s].callback(t);this.subscribeOnceChannel.length=0}if(this.linkedEvents)for(var c=0,l=this.linkedEvents;c<l.length;c+=1)l[c].fire(t,e,n,i,o);this.isFiring=!1,this.onAfterFire.length>0&&(this.onAfterFire.forEach(function(t){return t()}),this.onAfterFire.length=0)}},e.prototype.createSubscription=function(t,e,n){var i=this,o={callback:t},r={cancel:function(){i.cancel(o,e)}};return void 0!==n&&n.addCancelable(function(){return i.cancel(o,e)}),e.push(o),{subscription:o,facade:r}},e.prototype.cancel=function(t,e){var n=this,i=e.indexOf(t);i>=0&&(this.isFiring?this.onAfterFire.push(function(){return n.cancel(t,e)}):e.splice(i,1))},Object.defineProperties(e.prototype,n);var i=function(t){this.value=t,this.listeners=[]};i.prototype.update=function(t){this.value=t;for(var e=0,n=this.listeners;e<n.length;e+=1)(0,n[e])(t)},i.prototype.listen=function(t,e){var n,i=this;this.listeners.push(t);var o=function(){var e=i.listeners.indexOf(t);-1!==e&&i.listeners.splice(e,1)};return null===(n=e)||void 0===n||n.addCancelable(function(){o()}),o},i.prototype.filter=function(t,e){var n=new i;return this.listen(function(e){t(e)&&n.update(e)},e),n},i.prototype.pipe=function(t,e){this.listen(function(e){return t.update(e)},e)},i.prototype.map=function(t,e){var n=new i(t(this.value));return this.listen(function(e){n.update(t(e))},e),n},i.prototype.unique=function(t){var e=new i;return this.listen(function(t){t!==e.value&&e.update(t)},t),e},i.prototype.reduce=function(t,e){var n=new i;return this.listen(function(e){return n.update(t(n.value,e))},e),n},i.prototype.combine=function(t,e,n){var o=this,r=new i;return this.listen(function(){return r.update(e(o.value,t.value))},n),t.listen(function(){return r.update(e(o.value,t.value))},n),r},i.prototype.pick=function(t,e){var n=new i;return this.listen(function(e){n.update(e[t])},e),n},i.prototype.cancelAll=function(){this.listeners.length=0};var o=function(t){this.data=t?t.slice():[],this.onChange=new e},r={length:{configurable:!0}};r.length.get=function(){return this.data.length},o.prototype.getData=function(){return this.data.slice()},o.prototype.get=function(t){return this.data[t]},o.prototype.set=function(t,e){var n=this.data[t];n!==e&&(this.data[t]=e,this.onChange.fire({operation:"replace",target:n,count:1,index:t,items:[e],newState:this.data}))},o.prototype.push=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).push.apply(t,e),this.onChange.fire({operation:"append",count:e.length,index:this.data.length-e.length,items:e,newState:this.data})},o.prototype.unshift=function(){for(var t,e=[],n=arguments.length;n--;)e[n]=arguments[n];(t=this.data).unshift.apply(t,e),this.onChange.fire({operation:"prepend",count:e.length,items:e,index:0,newState:this.data})},o.prototype.pop=function(){var t=this.data.pop();return this.onChange.fire({operation:"removeRight",count:1,index:this.data.length,items:[t],newState:this.data}),t},o.prototype.merge=function(t){for(var e=0;e<t.length;e++)this.data[e]!==t[e]&&(this.length>e?this.set(e,t[e]):this.push(t[e]));this.length>t.length&&this.removeRight(this.length-t.length)},o.prototype.removeRight=function(t){var e=this.data.splice(this.length-t,t);this.onChange.fire({operation:"removeRight",count:t,index:this.length,items:e,newState:this.data})},o.prototype.removeLeft=function(t){var e=this.data.splice(0,t);this.onChange.fire({operation:"removeLeft",count:t,index:0,items:e,newState:this.data})},o.prototype.remove=function(t){var e=this.data.indexOf(t);-1!==e&&(this.data.splice(e,1),this.onChange.fire({operation:"remove",count:1,index:e,items:[t],newState:this.data}))},o.prototype.clear=function(){var t=this.data;this.data=[],this.onChange.fire({operation:"remove",count:t.length,index:0,items:t,newState:this.data})},o.prototype.shift=function(){var t=this.data.shift();return this.onChange.fire({operation:"removeLeft",items:[t],count:1,index:0,newState:this.data}),t},o.prototype.toArray=function(){return this.data.slice()},o.prototype.filter=function(t,e){return new a(this,t,e)},o.prototype.forEach=function(t,e){return this.data.forEach(t,e)},o.prototype.toDataSource=function(){var t=new i(this.data);return this.onChange.subscribe(function(e){t.update(e.newState)}),t},Object.defineProperties(o.prototype,r);var a=function(t){function e(e,n,i){var o=this,r=e.data.filter(n);t.call(this,r),this.parent=e,this.viewFilter=n,e.onChange.subscribe(function(t){var e,n,i;switch(t.operation){case"remove":case"removeLeft":case"removeRight":for(var r=0,a=t.items;r<a.length;r+=1)o.remove(a[r]);break;case"prepend":i=t.items.filter(o.viewFilter),(e=o).unshift.apply(e,i);break;case"append":i=t.items.filter(o.viewFilter),(n=o).push.apply(n,i);break;case"replace":var s=o.data.indexOf(t.target);if(-1!==s){o.viewFilter(t.items[0])?o.set(s,t.items[0]):o.remove(t.target);break}}},i)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.updateFilter=function(t){this.viewFilter!==t&&(this.viewFilter=t,this.refresh())},e.prototype.refresh=function(){var t;this.clear();var e=this.parent.data.filter(this.viewFilter);(t=this).push.apply(t,e)},e}(o),s=function(t){this.data=t};s.prototype.deleteNext=function(){if(this.next){var t=this.next.next;this.next.next=void 0,this.next.previous=void 0,this.next=t,this.next.previous=this}},s.prototype.deletePrevious=function(){this.previous&&(this.previous=this.previous.previous,this.previous.next=void 0,this.previous.previous=void 0)};var c=function(t){var e=this;void 0===t&&(t=[]),this.length=0,t.forEach(function(t){return e.append(t)})};c.prototype.find=function(t){for(var e=this.rootNode;e&&!t(e);)e=e.next;return e},c.prototype.append=function(t){return this.rootNode||this.lastNode?(this.lastNode.next=new s(t),this.lastNode.next.previous=this.lastNode,this.lastNode=this.lastNode.next):this.rootNode=this.lastNode=new s(t),this.length++,t},c.prototype.forEach=function(t){this.find(function(e){return t(e.data),!1})},c.prototype.prepend=function(t){return this.rootNode||this.lastNode?(this.rootNode.previous=new s(t),this.rootNode.previous.next=this.rootNode,this.rootNode=this.rootNode.previous):this.rootNode=this.lastNode=new s(t),this.length++,t},c.prototype.remove=function(t){if(t===this.rootNode.data)this.rootNode=this.rootNode.next,this.length--;else{var e=this.find(function(e){return e.next&&e.next.data===t});e&&(e.next===this.lastNode&&(this.lastNode=e),e.deleteNext(),this.length--)}};var l=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];this.cancelables=new c(t),this._isCancelled=!1},h={isCanceled:{configurable:!0}};h.isCanceled.get=function(){return this._isCancelled},l.prototype.addCancelable=function(t){return this.throwIfCancelled("attempting to add cancellable to token that is already cancelled"),this.cancelables.append(t),this.cancelables.length>200&&console.log("potential memory leak: cancellation token has over 200 clean up calls"),this},l.prototype.removeCancelable=function(t){return this.throwIfCancelled("attempting to remove cancellable from token that is already cancelled"),this.cancelables.remove(t),this},l.prototype.addDisposable=function(t){return this.addCancelable(function(){return t.dispose()}),this},l.prototype.callIfNotCancelled=function(t){this.isCanceled||t()},l.prototype.setTimeout=function(t,e){void 0===e&&(e=0);var n=setTimeout(t,e);this.addCancelable(function(){return clearTimeout(n)})},l.prototype.setInterval=function(t,e){var n=setInterval(t,e);this.addCancelable(function(){return clearInterval(n)})},l.prototype.requestAnimationFrame=function(t){var e=requestAnimationFrame(t);this.addCancelable(function(){return cancelAnimationFrame(e)})},l.prototype.animationLoop=function(t){var e=requestAnimationFrame(function n(i){t(i),e=requestAnimationFrame(n)});this.addCancelable(function(){return cancelAnimationFrame(e)})},l.prototype.throwIfCancelled=function(t){if(this.isCanceled)throw new Error(t||"cancellation token is cancelled")},l.prototype.chain=function(t,e){return void 0===e&&(e=!1),e&&t.chain(this,!1),this.addCancelable(function(){return t.cancel()}),this},l.prototype.registerDomEvent=function(t,e,n){return t.addEventListener(e,n),this.addCancelable(function(){return t.removeEventListener(e,n)}),this},l.prototype.cancel=function(){this.isCanceled||(this._isCancelled=!0,this.cancelables.forEach(function(t){return t()}),this.cancelables=void 0)},Object.defineProperties(l.prototype,h);var u=Symbol("owner"),p=function(t,e){this.domNodeName=e,this.template=t.template,this.cancellationToken=new l,this.node=this.create(t),this.initialize(t),t.onAttach&&t.onAttach(this)};p.prototype.initialize=function(t){this.node.owner=this,this.createEventHandlers(["blur","focus","click","dblclick","keydown","keyhit","keyup","mousedown, mouseup","mouseenter","mouseleave","mousewheel"],t),this.bindProps(["id","draggable","tabindex","style"],t),t.class&&this.handleClass(t.class),t.repeatModel&&(this.cachedChildren=[],this.handleRepeat(t.repeatModel))},p.prototype.bindProps=function(t,e){for(var n=0,i=t;n<i.length;n+=1){var o=i[n];e[o]&&this.assignStringSourceToAttribute(e[o],o)}},p.prototype.createEventHandlers=function(t,e){for(var n=this,o=function(){var t=a[r],o="on"+t[0].toUpperCase()+t.slice(1),s=void 0;Object.defineProperty(n,o,{get:function(){return s||(s=new i),s},set:function(){throw new Error(o+" is read only")}}),e[o]&&(e[o]instanceof i?n[o].listen(e[o].update.bind(e.onClick),n.cancellationToken):"function"==typeof e[o]&&n[o].listen(e[o],n.cancellationToken)),n.cancellationToken.registerDomEvent(n.node,t,function(t){return n[o].update(t)})},r=0,a=t;r<a.length;r+=1)o()},p.prototype.handleRepeat=function(t){var e,n=this;this.repeatData=t instanceof o?t:new o(t),this.repeatData.length&&((e=this.cachedChildren).push.apply(e,this.repeatData.toArray().map(function(t){return n.template.generate(t)})),this.renderRepeat()),this.repeatData.onChange.subscribe(function(t){var e,i;switch(t.operation){case"append":(e=n.cachedChildren).push.apply(e,t.items.map(function(t){return n.template.generate(t)}));break;case"removeLeft":n.cachedChildren.splice(0,t.count);break;case"removeRight":n.cachedChildren.splice(n.node.childElementCount-t.count,t.count);break;case"remove":n.cachedChildren.splice(t.index,t.count);break;default:n.cachedChildren.length=0,(i=n.cachedChildren).push.apply(i,n.repeatData.toArray().map(function(t){return n.template.generate(t)}))}n.renderRepeat()})},p.prototype.renderRepeat=function(){var t=this;this.rerenderPending||(setTimeout(function(){for(var e=0;e<t.cachedChildren.length;e++){if(t.node.childElementCount<=e){t.addChildren(t.cachedChildren.slice(e,t.cachedChildren.length));break}if(t.node.children[e].owner!==t.cachedChildren[e]){if(!t.cachedChildren.includes(t.node.children[e].owner)){t.node.children[e][u].remove(),e--;continue}var n=t.getChildIndex(t.cachedChildren[e].node);-1!==n?t.swapChildren(e,n):t.addChildAt(t.cachedChildren[e],e)}}for(;t.node.childElementCount>t.cachedChildren.length;)t.node[u].removeChild(t.node.lastChild[u]);t.rerenderPending=!1}),this.rerenderPending=!0)},p.prototype.assignStringSourceToAttribute=function(t,e){var n=this;"string"==typeof t?this.node[e]=t:(t.value&&(this.node[e]=t.value),t.unique(this.cancellationToken).listen(function(t){return n.node.id=t},this.cancellationToken))},p.prototype.handleClass=function(t){var e=this;if("string"==typeof t)this.node.className=t;else if(t instanceof i)t.value&&(Array.isArray(t.value)?(this.node.className=t.value.join(" "),t.unique(this.cancellationToken).listen(function(){e.node.className=t.value.join(" ")},this.cancellationToken)):(this.node.className=t.value,t.unique(this.cancellationToken).listen(function(){e.node.className=t.value},this.cancellationToken))),t.unique(this.cancellationToken).listen(function(t){return e.node.className=t},this.cancellationToken);else{var n=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");this.node.className=n;for(var o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof i&&a.unique(this.cancellationToken).listen(function(n){var i=t.reduce(function(t,e){return"string"==typeof e?t+" "+e:e.value?t+" "+e.value:t},"");e.node.className=i},this.cancellationToken)}}},p.prototype.create=function(t){var e=document.createElement(this.domNodeName);return e[u]=this,e},p.prototype.getChildIndex=function(t){for(var e=0,n=0,i=t.children;n<i.length;n+=1){if(i[n]===t)return e;e++}return-1},p.prototype.hasChild=function(t){for(var e=0,n=t.children;e<n.length;e+=1)if(n[e]===t)return!0;return!1},p.prototype.setInnerText=function(t){if(this.node.firstChild instanceof HTMLElement)throw new Error("Cannot combine text and child nodes into a single element");this.node.innerText=t},p.prototype.swapChildren=function(t,e){if(t!==e){var n=this.node.children[t],i=this.node.children[e];n.remove(),i.remove(),t<e?(this.addDomNodeAt(i,t),this.addDomNodeAt(n,e)):(this.addDomNodeAt(n,e),this.addDomNodeAt(i,t))}},p.prototype.addDomNodeAt=function(t,e){e>=this.node.childElementCount?this.node.appendChild(t):this.node.insertBefore(t,this.node.children[e])},p.prototype.remove=function(){this.hasParent()&&(this.node.parentElement.removeChild(this.node),this.dispose())},p.prototype.hasParent=function(){return!!this.node.parentElement},p.prototype.isConnected=function(){return this.node.isConnected},p.prototype.removeChild=function(t){t.dispose(),this.node.removeChild(t.node)},p.prototype.removeChildAt=function(t){var e=this.node.childNodes[t];if(e){var n=e[u];n.dispose(),this.node.removeChild(n.node)}},p.prototype.clearChildren=function(){for(;this.node.firstChild;)this.node.firstChild[u].dispose(),this.node.removeChild(this.node.firstChild)},p.prototype.addChild=function(t){if(!(t.node instanceof d))return this.node.appendChild(t.node)},p.prototype.addChildAt=function(t,e){if(!(t.node instanceof d))return this.addDomNodeAt(t.node,e)},p.prototype.addChildren=function(t){var e=this;if(0!==t.length){for(var n=[],o=0,r=t;o<r.length;o+=1){var a=r[o];a instanceof d||("string"==typeof a?n.push(a):a instanceof i?(n.push(a),this.setInnerText(a.value),a.listen(function(t){var o=n.reduce(function(t,e){var n;return t+(e instanceof i?(n=e.value,null!=n?n:"").toString():e)},"");e.setInnerText(o)},this.cancellationToken)):this.node.appendChild(a.node))}if(n.length){var s=n.reduce(function(t,e){var n;return t+(e instanceof i?(n=e.value,null!=n?n:"").toString():e)},"");this.setInnerText(s)}}},p.prototype.dispose=function(){this.cancellationToken.cancel()};var d=function(t){function e(e){t.call(this,e,"template"),this.ref=e.ref,this.generate=e.generator}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),f=function(){};f.attach=function(t,e){if(e[u])throw new Error("This node is already managed by aurum and cannot be used");e.appendChild(t.node),e[u]=t},f.detach=function(t){t[u]&&(t[u].dispose(),t[u]=void 0)},f.factory=function(t,e){for(var n,i=[],o=arguments.length-2;o-- >0;)i[o]=arguments[o+2];if("string"!=typeof t){for(var r,a,s=(n=[]).concat.apply(n,i).filter(function(t){return t}),c={},l=!1,h=0,u=s;h<u.length;h+=1){var p=u[h];"string"!=typeof p&&(p instanceof d&&(!p.ref||"default"===p.ref)&&(r=p),p.ref&&(c[p.ref]=p,l=!0))}return e=null!=e?e:{},r&&(e.template=r),l&&(e.templateMap=c),(a=t.prototype?new t(e||{}):t(e||{})).addChildren(s),a}};var v=function(t){function e(e){t.call(this,e,"button")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),b=function(t){function e(e){t.call(this,e,"div")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),y=function(t){function e(e){var n,i,o,r=this;t.call(this,e,"input"),e.inputValueSource?(this.node.value=null!=(i=null!=(n=e.initialValue)?n:e.inputValueSource.value)?i:"",e.inputValueSource.listen(function(t){return r.node.value=t},this.cancellationToken)):this.node.value=null!=(o=e.initialValue)?o:"",this.bindProps(["placeholder"],e),this.createEventHandlers(["input","change"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),m=function(t){function e(e){t.call(this,e,"li")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),g=function(t){function e(e){t.call(this,e,"span")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),C=function(t){function e(e){t.call(this,e,"style")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),w=function(t){function e(e){t.call(this,e,"ul")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),k=function(t){function e(e){t.call(this,e,"p")}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),_=function(t){function e(e){t.call(this,e,"img"),this.bindProps(["src"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),x=function(t){function e(e){t.call(this,e,"link"),this.bindProps(["href","rel"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),N=function(t){function e(e){t.call(this,e,"canvas"),this.bindProps(["width","height"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(p),S=function(t){function e(e){var n=this;t.call(this,e,"switch"),this.firstRender=!0,this.templateMap=e.templateMap,this.render(e.state.value),e.state.listen(function(t){n.render(t)},this.cancellationToken)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.render=function(t){var e;if(t!==this.lastValue||this.firstRender)if(this.lastValue=t,this.firstRender=!1,this.clearChildren(),null!=t){var n=null!=(e=this.templateMap[t.toString()])?e:this.template;if(n){var i=n.generate();this.addChild(i)}}else if(this.template){var o=this.template.generate();this.addChild(o)}},e}(p);t.ArrayDataSource=o,t.FilteredArrayView=a,t.DataSource=i,t.EventEmitter=e,t.CancellationToken=l,t.Aurum=f,t.AurumElement=p,t.Template=d,t.Button=v,t.Div=b,t.Input=y,t.Li=m,t.Span=g,t.Style=C,t.Ul=w,t.P=k,t.Img=_,t.Link=x,t.Canvas=N,t.Switch=S}); | ||
//# sourceMappingURL=aurumjs.umd.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
375361
5