text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("babel-polyfill"),require("@plasma-js/hades")):"function"==typeof define&&define.amd?define(["exports","babel-polyfill","@plasma-js/hades"],t):t((e=e||self).index={},null,e.Hades)}(this,function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n,i=0;i<t.length;i++)(n=t[i]).enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}function r(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),e}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&a(e,t)}function u(e){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e,t){return(a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){return(c=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&a(o,n.prototype),o}).apply(null,arguments)}function l(e){var n="function"==typeof Map?new Map:void 0;return(l=function(e){function t(){return c(e,arguments,u(this).constructor)}if(null===e||!function(e){return-1!==Function.toString.call(e).indexOf("[native code]")}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(e))return n.get(e);n.set(e,t)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),a(t,e)})(e)}function f(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function d(e){return e===this}function h(e){return e===this}var p="default"in n?n.default:n,m=(r(j,[{key:"addComponent",value:function(e,t){if(!e||"string"!=typeof e)throw new Error("New component title is null or undefined.");if(!t)throw new Error("New component instance is null or undefined.");if(this._componentsKey.find(d,e))throw new Error("Component in key '".concat(e,"' already registered!"));this.components.push({title:e,instance:t}),this._componentsKey.push(e)}},{key:"addModule",value:function(e,t){if(!e||"string"==typeof e)throw new Error("New component title is null or undefined.");if(!t)throw new Error("New component instance is null or undefined.");if(this._modulesKey.find(d,e))throw new Error("Module in key '".concat(e,"' already registered!"));this.modules.push({title:e,instance:t}),this._modulesKey.push(e)}},{key:"getItens",value:function(){var t=[];return this.components.forEach(function(e){t.push(e)},this),this.modules.forEach(function(e){t.push(e)},this),t}}]),j),y=(s(O,n.Collection),O),v=(s(S,n.Collection),S),b=(s(k,l(Error)),k),w=(s(g,v),r(g,[{key:"setup",value:function(){var t=this;"function"==typeof this.validate&&(this._mapFields(),this.onSubmit?this.elm.addEventListener("submit",this.onSubmit.bind(this)):this.elm.addEventListener("submit",function(e){e.preventDefault(),t.validate(t.data).then(t.submit.bind(t)).catch(function(e){throw console.log(e),new b("Invalid form. Details bellow:")})}),console.info("Form setup runned with success!"))}},{key:"submit",value:function(e){console.log(e),this.elm.submit()}},{key:"_fieldSync",value:function(e,t){this.data[e]=t.srcElement.value}},{key:"_checkboxSync",value:function(e,t){if(t.srcElement.checked)this.data[e].push(t.srcElement.value);else if(this.data[e].length){var n=this.data[e].findIndex(h,t.srcElement.value);0<=n&&this.data[e].splice(n,1)}}},{key:"_radioSync",value:function(e,t){t.srcElement.checked&&(this.data[e]=t.srcElement.value)}},{key:"_mapFields",value:function(){this.elm.querySelectorAll("input, select").forEach(this._syncField.bind(this))}},{key:"_syncField",value:function(e){void 0===this.data[e.name]?console.error('Data field "'.concat(e.name,'" was not declared. The field will not be counted as one inside the form.')):"radio"===e.type?(e.checked&&(this.data[e.name]=e.value),e.addEventListener("input",this._radioSync.bind(this,e.name))):"checkbox"===e.type?(this.data[e.name]=[],e.checked&&this.data[e.name].push(e.value),e.addEventListener("input",this._checkboxSync.bind(this,e.name))):(e.addEventListener("input",this._fieldSync.bind(this,e.name)),this.data[e.name]=e.value)}}]),g),E=(r(_,[{key:"render",value:function(){var n=this;this.components.forEach(function(e){var t=n.root.querySelectorAll('[plasma="'.concat(e.title,'"]'));t.length&&t.forEach(n._newChild.bind(n,e.instance))})}},{key:"_newChild",value:function(e,t){t.removeAttribute("plasma"),new e(t)}}]),_);function _(e,t,n){if(i(this,_),this.root=e instanceof Node?e:document.querySelector("body"),this.db=new p,1!=t instanceof m)throw new Error("The second argument is not valid. It should be a valid Register instance.");this.components=t.getItens(),this.render(),n&&"function"==typeof n&&n.bind(this)}function g(e,t){var n;if(i(this,g),!e||!e instanceof Node)throw new Error("The first param 'element' is null, undefined or not a valid Node.");return(n=f(this,u(g).call(this,t))).elm=e,n.data=t,n.setup(),n}function k(e){var t;return i(this,k),(t=f(this,u(k).call(this,e.message))).errors=e.errors,t.params=e.params,t.value=e.value,t}function S(e){return i(this,S),f(this,u(S).call(this,e))}function O(e){return i(this,O),f(this,u(O).call(this,e))}function j(){i(this,j),this._componentsKey=[],this.components=[],this._modulesKey=[],this.modules=[]}e.Component=v,e.FormBase=w,e.Module=y,e.Register=m,e.default=E,Object.defineProperty(e,"__esModule",{value:!0})});
  