blob: 0be6c32dd127d037115ec741c648bbf9e380df74 [file] [log] [blame]
!function(){"use strict";function e(){}function t(t,n){var o,r,i,l,a=J;for(l=arguments.length;l-- >2;)G.push(arguments[l]);for(n&&null!=n.children&&(G.length||G.push(n.children),delete n.children);G.length;)if((r=G.pop())&&void 0!==r.pop)for(l=r.length;l--;)G.push(r[l]);else"boolean"==typeof r&&(r=null),(i="function"!=typeof t)&&(null==r?r="":"number"==typeof r?r+="":"string"!=typeof r&&(i=!1)),i&&o?a[a.length-1]+=r:a===J?a=[r]:a.push(r),o=i;var s=new e;return s.nodeName=t,s.children=a,s.attributes=null==n?void 0:n,s.key=null==n?void 0:n.key,void 0!==F.vnode&&F.vnode(s),s}function n(e,t){for(var n in t)e[n]=t[n];return e}function o(e){!e._dirty&&(e._dirty=!0)&&1==Y.push(e)&&(F.debounceRendering||Q)(r)}function r(){var e,t=Y;for(Y=[];e=t.pop();)e._dirty&&S(e)}function i(e,t,n){return"string"==typeof t||"number"==typeof t?void 0!==e.splitText:"string"==typeof t.nodeName?!e._componentConstructor&&l(e,t.nodeName):n||e._componentConstructor===t.nodeName}function l(e,t){return e.normalizedNodeName===t||e.nodeName.toLowerCase()===t.toLowerCase()}function a(e){var t=n({},e.attributes);t.children=e.children;var o=e.nodeName.defaultProps;if(void 0!==o)for(var r in o)void 0===t[r]&&(t[r]=o[r]);return t}function s(e,t){var n=t?document.createElementNS("http://www.w3.org/2000/svg",e):document.createElement(e);return n.normalizedNodeName=e,n}function c(e){var t=e.parentNode;t&&t.removeChild(e)}function u(e,t,n,o,r){if("className"===t&&(t="class"),"key"===t);else if("ref"===t)n&&n(null),o&&o(e);else if("class"!==t||r)if("style"===t){if(o&&"string"!=typeof o&&"string"!=typeof n||(e.style.cssText=o||""),o&&"object"===(void 0===o?"undefined":$(o))){if("string"!=typeof n)for(var i in n)i in o||(e.style[i]="");for(var i in o)e.style[i]="number"==typeof o[i]&&X.test(i)===!1?o[i]+"px":o[i]}}else if("dangerouslySetInnerHTML"===t)o&&(e.innerHTML=o.__html||"");else if("o"==t[0]&&"n"==t[1]){var l=t!==(t=t.replace(/Capture$/,""));t=t.toLowerCase().substring(2),o?n||e.addEventListener(t,f,l):e.removeEventListener(t,f,l),(e._listeners||(e._listeners={}))[t]=o}else if("list"!==t&&"type"!==t&&!r&&t in e)p(e,t,null==o?"":o),null!=o&&o!==!1||e.removeAttribute(t);else{var a=r&&t!==(t=t.replace(/^xlink\:?/,""));null==o||o===!1?a?e.removeAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase()):e.removeAttribute(t):"function"!=typeof o&&(a?e.setAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase(),o):e.setAttribute(t,o))}else e.className=o||""}function p(e,t,n){try{e[t]=n}catch(e){}}function f(e){return this._listeners[e.type](F.event&&F.event(e)||e)}function d(){for(var e;e=Z.pop();)F.afterMount&&F.afterMount(e),e.componentDidMount&&e.componentDidMount()}function h(e,t,n,o,r,i){ee++||(te=null!=r&&void 0!==r.ownerSVGElement,ne=null!=e&&!("__preactattr_"in e));var l=m(e,t,n,o,i);return r&&l.parentNode!==r&&r.appendChild(l),--ee||(ne=!1,i||d()),l}function m(e,t,n,o,r){var i=e,a=te;if(null!=t&&"boolean"!=typeof t||(t=""),"string"==typeof t||"number"==typeof t)return e&&void 0!==e.splitText&&e.parentNode&&(!e._component||r)?e.nodeValue!=t&&(e.nodeValue=t):(i=document.createTextNode(t),e&&(e.parentNode&&e.parentNode.replaceChild(i,e),v(e,!0))),i.__preactattr_=!0,i;var c=t.nodeName;if("function"==typeof c)return k(e,t,n,o);if(te="svg"===c||"foreignObject"!==c&&te,c+="",(!e||!l(e,c))&&(i=s(c,te),e)){for(;e.firstChild;)i.appendChild(e.firstChild);e.parentNode&&e.parentNode.replaceChild(i,e),v(e,!0)}var u=i.firstChild,p=i.__preactattr_,f=t.children;if(null==p){p=i.__preactattr_={};for(var d=i.attributes,h=d.length;h--;)p[d[h].name]=d[h].value}return!ne&&f&&1===f.length&&"string"==typeof f[0]&&null!=u&&void 0!==u.splitText&&null==u.nextSibling?u.nodeValue!=f[0]&&(u.nodeValue=f[0]):(f&&f.length||null!=u)&&y(i,f,n,o,ne||null!=p.dangerouslySetInnerHTML),_(i,t.attributes,p),te=a,i}function y(e,t,n,o,r){var l,a,s,u,p,f=e.childNodes,d=[],h={},y=0,b=0,_=f.length,g=0,w=t?t.length:0;if(0!==_)for(var C=0;C<_;C++){var x=f[C],S=x.__preactattr_,k=w&&S?x._component?x._component.__key:S.key:null;null!=k?(y++,h[k]=x):(S||(void 0!==x.splitText?!r||x.nodeValue.trim():r))&&(d[g++]=x)}if(0!==w)for(var C=0;C<w;C++){u=t[C],p=null;var k=u.key;if(null!=k)y&&void 0!==h[k]&&(p=h[k],h[k]=void 0,y--);else if(!p&&b<g)for(l=b;l<g;l++)if(void 0!==d[l]&&i(a=d[l],u,r)){p=a,d[l]=void 0,l===g-1&&g--,l===b&&b++;break}p=m(p,u,n,o),s=f[C],p&&p!==e&&p!==s&&(null==s?e.appendChild(p):p===s.nextSibling?c(s):e.insertBefore(p,s))}if(y)for(var C in h)void 0!==h[C]&&v(h[C],!1);for(;b<=g;)void 0!==(p=d[g--])&&v(p,!1)}function v(e,t){var n=e._component;n?N(n):(null!=e.__preactattr_&&e.__preactattr_.ref&&e.__preactattr_.ref(null),t!==!1&&null!=e.__preactattr_||c(e),b(e))}function b(e){for(e=e.lastChild;e;){var t=e.previousSibling;v(e,!0),e=t}}function _(e,t,n){var o;for(o in n)t&&null!=t[o]||null==n[o]||u(e,o,n[o],n[o]=void 0,te);for(o in t)"children"===o||"innerHTML"===o||o in n&&t[o]===("value"===o||"checked"===o?e[o]:n[o])||u(e,o,n[o],n[o]=t[o],te)}function g(e){var t=e.constructor.name;(oe[t]||(oe[t]=[])).push(e)}function w(e,t,n){var o,r=oe[e.name];if(e.prototype&&e.prototype.render?(o=new e(t,n),T.call(o,t,n)):(o=new T(t,n),o.constructor=e,o.render=C),r)for(var i=r.length;i--;)if(r[i].constructor===e){o.nextBase=r[i].nextBase,r.splice(i,1);break}return o}function C(e,t,n){return this.constructor(e,n)}function x(e,t,n,r,i){e._disable||(e._disable=!0,(e.__ref=t.ref)&&delete t.ref,(e.__key=t.key)&&delete t.key,!e.base||i?e.componentWillMount&&e.componentWillMount():e.componentWillReceiveProps&&e.componentWillReceiveProps(t,r),r&&r!==e.context&&(e.prevContext||(e.prevContext=e.context),e.context=r),e.prevProps||(e.prevProps=e.props),e.props=t,e._disable=!1,0!==n&&(1!==n&&F.syncComponentUpdates===!1&&e.base?o(e):S(e,1,i)),e.__ref&&e.__ref(e))}function S(e,t,o,r){if(!e._disable){var i,l,s,c=e.props,u=e.state,p=e.context,f=e.prevProps||c,m=e.prevState||u,y=e.prevContext||p,b=e.base,_=e.nextBase,g=b||_,C=e._component,k=!1;if(b&&(e.props=f,e.state=m,e.context=y,2!==t&&e.shouldComponentUpdate&&e.shouldComponentUpdate(c,u,p)===!1?k=!0:e.componentWillUpdate&&e.componentWillUpdate(c,u,p),e.props=c,e.state=u,e.context=p),e.prevProps=e.prevState=e.prevContext=e.nextBase=null,e._dirty=!1,!k){i=e.render(c,u,p),e.getChildContext&&(p=n(n({},p),e.getChildContext()));var T,E,O=i&&i.nodeName;if("function"==typeof O){var D=a(i);l=C,l&&l.constructor===O&&D.key==l.__key?x(l,D,1,p,!1):(T=l,e._component=l=w(O,D,p),l.nextBase=l.nextBase||_,l._parentComponent=e,x(l,D,0,p,!1),S(l,1,o,!0)),E=l.base}else s=g,T=C,T&&(s=e._component=null),(g||1===t)&&(s&&(s._component=null),E=h(s,i,p,o||!b,g&&g.parentNode,!0));if(g&&E!==g&&l!==C){var j=g.parentNode;j&&E!==j&&(j.replaceChild(E,g),T||(g._component=null,v(g,!1)))}if(T&&N(T),e.base=E,E&&!r){for(var P=e,A=e;A=A._parentComponent;)(P=A).base=E;E._component=P,E._componentConstructor=P.constructor}}if(!b||o?Z.unshift(e):k||(e.componentDidUpdate&&e.componentDidUpdate(f,m,y),F.afterUpdate&&F.afterUpdate(e)),null!=e._renderCallbacks)for(;e._renderCallbacks.length;)e._renderCallbacks.pop().call(e);ee||r||d()}}function k(e,t,n,o){for(var r=e&&e._component,i=r,l=e,s=r&&e._componentConstructor===t.nodeName,c=s,u=a(t);r&&!c&&(r=r._parentComponent);)c=r.constructor===t.nodeName;return r&&c&&(!o||r._component)?(x(r,u,3,n,o),e=r.base):(i&&!s&&(N(i),e=l=null),r=w(t.nodeName,u,n),e&&!r.nextBase&&(r.nextBase=e,l=null),x(r,u,1,n,o),e=r.base,l&&e!==l&&(l._component=null,v(l,!1))),e}function N(e){F.beforeUnmount&&F.beforeUnmount(e);var t=e.base;e._disable=!0,e.componentWillUnmount&&e.componentWillUnmount(),e.base=null;var n=e._component;n?N(n):t&&(t.__preactattr_&&t.__preactattr_.ref&&t.__preactattr_.ref(null),e.nextBase=t,c(t),g(e),b(t)),e.__ref&&e.__ref(null)}function T(e,t){this._dirty=!0,this.context=t,this.props=e,this.state=this.state||{}}function E(e,t,n){return h(n,e,{},!1,t,!1)}function O(e,t,n,o){for(o=0,t=t.split?t.split("."):t;e&&o<t.length;)e=e[t[o++]];return void 0===e?n:e}function D(e,t,n){var o=t.split(".");return function(t){for(var r=t&&t.target||this,i={},l=i,a="string"==typeof n?O(t,n):r.nodeName?r.type.match(/^che|rad/)?r.checked:r.value:t,s=0;s<o.length-1;s++)l=l[o[s]]||(l[o[s]]=!s&&e.state[o[s]]||{});l[o[s]]=a,e.setState(i)}}function j(){for(var e="",t=0;t<32;t++){var n=16*Math.random()|0;8!==t&&12!==t&&16!==t&&20!==t||(e+="-"),e+=(12===t?4:16===t?3&n|8:n).toString(16)}return e}function P(e,t){return 1===e?t:t+"s"}function A(){return[]}function U(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function L(e,t){return t={exports:{}},e(t,t.exports),t.exports}function B(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function M(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function R(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function W(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function K(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function V(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function H(e){if(null==e)throw new TypeError("Cannot destructure undefined")}function I(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function z(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function q(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var $="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},F={},G=[],J=[],Q="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout,X=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,Y=[],Z=[],ee=0,te=!1,ne=!1,oe={};n(T.prototype,{setState:function(e,t){var r=this.state;this.prevState||(this.prevState=n({},r)),n(r,"function"==typeof e?e(r,this.props):e),t&&(this._renderCallbacks=this._renderCallbacks||[]).push(t),o(this)},forceUpdate:function(e){e&&(this._renderCallbacks=this._renderCallbacks||[]).push(e),S(this,2)},render:function(){}});var re=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},ie=function(){function e(t,n){U(this,e),this.key=t,this.todos=A(t)||[],this.onChanges=[n]}return e.prototype.inform=function(){A(this.key,this.todos),this.onChanges.forEach(function(e){return e()})},e.prototype.addTodo=function(e){this.todos=this.todos.concat({id:j(),title:e,completed:!1}),this.inform()},e.prototype.toggleAll=function(e){this.todos=this.todos.map(function(t){return re({},t,{completed:e})}),this.inform()},e.prototype.toggle=function(e){this.todos=this.todos.map(function(t){return t!==e?t:re({},t,{completed:!t.completed})}),this.inform()},e.prototype.destroy=function(e){this.todos=this.todos.filter(function(t){return t!==e}),this.inform()},e.prototype.save=function(e,t){this.todos=this.todos.map(function(n){return n!==e?n:re({},n,{title:t})}),this.inform()},e.prototype.clearCompleted=function(){this.todos=this.todos.filter(function(e){return!e.completed}),this.inform()},e}(),le=L(function(e){var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function(){function n(){for(var e=[],r=0;r<arguments.length;r++){var i=arguments[r];if(i){var l=void 0===i?"undefined":t(i);if("string"===l||"number"===l)e.push(i);else if(Array.isArray(i))e.push(n.apply(null,i));else if("object"===l)for(var a in i)o.call(i,a)&&i[a]&&e.push(a)}}return e.join(" ")}var o={}.hasOwnProperty;void 0!==e&&e.exports?e.exports=n:"function"==typeof define&&"object"===t(define.amd)&&define.amd?define("classnames",[],function(){return n}):window.classNames=n}()}),ae=function(e){function n(){return B(this,n),M(this,e.apply(this,arguments))}return R(n,e),n.prototype.render=function(e){var n=e.nowShowing,o=e.count,r=e.completedCount,i=e.onClearCompleted;return t("footer",{class:"footer"},t("span",{class:"todo-count"},t("strong",null,o)," ",P(o,"item")," left"),t("ul",{class:"filters"},t("li",null,t("a",{href:"#/",class:le({selected:"all"==n})},"All"))," ",t("li",null,t("a",{href:"#/active",class:le({selected:"active"==n})},"Active"))," ",t("li",null,t("a",{href:"#/completed",class:le({selected:"completed"==n})},"Completed"))),r>0&&t("button",{class:"clear-completed",onClick:i},"Clear completed"))},n}(T),se=27,ce=13,ue=function(e){function n(){var t,o,r;W(this,n);for(var i=arguments.length,l=Array(i),a=0;a<i;a++)l[a]=arguments[a];return t=o=K(this,e.call.apply(e,[this].concat(l))),o.handleSubmit=function(){var e=o.props,t=e.onSave,n=e.onDestroy,r=e.todo,i=o.state.editText.trim();i?(t(r,i),o.setState({editText:i})):n(r)},o.handleEdit=function(){var e=o.props,t=e.onEdit,n=e.todo;t(n),o.setState({editText:n.title})},o.toggle=function(e){var t=o.props;(0,t.onToggle)(t.todo),e.preventDefault()},o.handleKeyDown=function(e){if(e.which===se){var t=o.props.todo;o.setState({editText:t.title}),o.props.onCancel(t)}else e.which===ce&&o.handleSubmit()},o.handleDestroy=function(){o.props.onDestroy(o.props.todo)},r=t,K(o,r)}return V(n,e),n.prototype.componentDidUpdate=function(){var e=this.base&&this.base.querySelector(".edit");e&&e.focus()},n.prototype.render=function(e,n){var o=e.todo,r=o.title,i=o.completed,l=e.editing,a=n.editText;return t("li",{class:le({completed:i,editing:l})},t("div",{class:"view"},t("input",{class:"toggle",type:"checkbox",checked:i,onChange:this.toggle}),t("label",{onDblClick:this.handleEdit},r),t("button",{class:"destroy",onClick:this.handleDestroy})),l&&t("input",{class:"edit",value:a,onBlur:this.handleSubmit,onInput:this.linkState("editText"),onKeyDown:this.handleKeyDown}))},n}(T),pe={all:function(){return!0},active:function(e){return!e.completed},completed:function(e){return e.completed}};E(t(function(e){function n(){I(this,n);var t=z(this,e.call(this));return t.handleNewTodoKeyDown=function(e){if(13===e.keyCode){e.preventDefault();var n=e.target.value.trim();n&&(t.model.addTodo(n),t.setState({newTodo:""}))}},t.toggleAll=function(e){t.model.toggleAll(e.target.checked)},t.toggle=function(e){t.model.toggle(e)},t.destroy=function(e){t.model.destroy(e)},t.edit=function(e){t.setState({editing:e.id})},t.save=function(e,n){t.model.save(e,n),t.setState({editing:null})},t.cancel=function(){t.setState({editing:null})},t.clearCompleted=function(){t.model.clearCompleted()},t.model=new ie("preact-todos",function(){return t.setState({})}),addEventListener("hashchange",t.handleRoute.bind(t)),t.handleRoute(),t}return q(n,e),n.prototype.handleRoute=function(){var e=((location.hash||"")+"").split("/").pop();pe[e]||(e="all"),this.setState({nowShowing:e})},n.prototype.render=function(e,n){var o=this,r=n.nowShowing,i=void 0===r?ALL_TODOS:r,l=n.newTodo,a=n.editing;H(e);var s=this.model.todos,c=s.filter(pe[i]),u=s.reduce(function(e,t){return e+(t.completed?0:1)},0),p=s.length-u;return t("div",null,t("header",{class:"header"},t("h1",null,"todos"),t("input",{class:"new-todo",placeholder:"What needs to be done?",value:l,onKeyDown:this.handleNewTodoKeyDown,onInput:D(this,"newTodo"),autoFocus:!0})),s.length?t("section",{class:"main"},t("input",{class:"toggle-all",type:"checkbox",onChange:this.toggleAll,checked:0===u}),t("ul",{class:"todo-list"},c.map(function(e){return t(ue,{todo:e,onToggle:o.toggle,onDestroy:o.destroy,onEdit:o.edit,editing:a===e.id,onSave:o.save,onCancel:o.cancel})}))):null,u||p?t(ae,{count:u,completedCount:p,nowShowing:i,onClearCompleted:this.clearCompleted}):null)},n}(T),null),document.querySelector(".todoapp"))}();
//# sourceMappingURL=app.js.map