@felte/core
Advanced tools
Comparing version 0.1.6 to 0.2.0
# @felte/core | ||
## 0.2.0 | ||
### Minor Changes | ||
- 2d3b213: BREAKING: Remove `reporter` configuration option in favor of `extend`. | ||
### Patch Changes | ||
- de71f43: Add `addValidator` utility for extenders | ||
- Updated dependencies [a7e7e35] | ||
- Updated dependencies [2d3b213] | ||
- Updated dependencies [de71f43] | ||
- @felte/common@0.5.0 | ||
## 0.1.6 | ||
@@ -4,0 +18,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Core={})}(this,(function(e){"use strict";function t(e,t){return Object.keys(e).some((n=>t(e[n])))}function n(e,t){return Object.keys(e).reduce(((n,r)=>Object.assign(Object.assign({},n),{[r]:t(e[r])})),{})}function r(e){return"[object Object]"===Object.prototype.toString.call(e)}function o(e){return Object.keys(e||{}).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:r(e[n])?o(e[n]):Array.isArray(e[n])?[...e[n]]:e[n]})),{})}function i(e,t){return n(e,(e=>r(e)?i(e,t):Array.isArray(e)?e.map(function(e){return function(t){return r(t)?i(t,e):e}}(t)):t))}function a(...e){const t=e.pop(),n=o(e.shift());if(0===e.length)return n;for(const u of e){if(!u)continue;const e=Object.keys(u);for(const l of e){const e=t(n[l],u[l]);if(void 0!==e)n[l]=e;else if(r(u[l])&&r(n[l]))n[l]=a(n[l],u[l],t);else if(Array.isArray(u[l])&&Array.isArray(n[l]))n[l]=u[l].map(((e,r)=>a(n[l][r],e,t)));else if(r(u[l])){const e=i(o(u[l]),void 0);n[l]=a(e,u[l],t)}else void 0!==u[l]&&(n[l]=u[l])}}return n}function u(e,t){if(!r(e)||!r(t)){if(Array.isArray(t)){if(t.some(r))return;const n=Array.isArray(e)?e:[];return t.map(((e,t)=>{var r;return null!==(r=n[t])&&void 0!==r?r:e}))}return void 0!==e?e:void 0}}function l(...e){return a(...e,u)}function s(...e){return a(...e,(()=>{}))}function c(e,t,n){const r=n=>String.prototype.split.call(t,n).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),o=r(/[,[\]]+?/)||r(/[,[\].]+?/);return void 0===o||o===e?n:o}function d(e,t,n){Object(e)!==e?e={}:void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n,e}function f(e,t){var n;if(Object(e)!==e)return;void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return null===(n=r.slice(0,-1).reduce(((e,t)=>Object(e[t])===e[t]?e[t]:void 0),e))||void 0===n||delete n[r[r.length-1]],e}function v(e,t,n){Object(e)!==e&&(e={});let r=t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n(c(e,t)),e}function m(e,n){return t(e,(e=>r(e)?m(e,n):n(e)))}function y(e){return e.hasAttribute("data-felte-index")?Number(e.dataset.felteIndex):void 0}function p(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function h(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function g(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function b(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function A(e){return p(e)||h(e)||g(e)}function E(e){return e.nodeType===Node.ELEMENT_NODE}function O(e,t){const n=y(e);let r="";t?r=t:A(e)&&(r=e.name),r=void 0===n?r:`${r}[${n}]`;let o=e.parentNode;if(!o)return r;for(;o&&"FORM"!==o.nodeName;){if(b(o)&&o.name){const e=y(o);r=`${void 0===e?o.name:`${o.name}[${e}]`}.${r}`}o=o.parentNode}return r}function S(e){const t=e.dataset.felteFieldset,n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;return t?`${t}.${r}`:r}function j(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function x(e){if(A(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const n of e.children){if(A(n)&&t.add(n),b(n))for(const e of n.elements)A(e)&&t.add(e);n.childElementCount>0&&x(n).forEach((e=>t.add(e)))}return Array.from(t)}function N(e){for(const t of e.elements)if(A(t)||b(t)){if(e.name&&t.name){const n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;t.dataset.felteFieldset=e.dataset.felteFieldset?`${e.dataset.felteFieldset}.${r}`:r}"true"!==e.dataset.felteUnsetOnRemove||t.hasAttribute("data-felte-unset-on-remove")||(t.dataset.felteUnsetOnRemove="true")}}function F(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function k(e){var t;let n={};for(const r of e.elements){if(b(r)&&N(r),!A(r)||!r.name)continue;const o=O(r),i=y(r);if(p(r)){if("checkbox"===r.type){if(void 0===c(n,o)){if(1===Array.from(e.querySelectorAll(`[name="${r.name}"]`)).filter((e=>!!A(e)&&(void 0!==i?Number(e.dataset.felteIndex)===i:o===O(e)))).length){n=d(n,o,r.checked);continue}n=d(n,o,r.checked?[r.value]:[]);continue}Array.isArray(c(n,o))&&r.checked&&v(n,o,(e=>(void 0===i||Array.isArray(e)||(e=[]),[...e,r.value])));continue}if("radio"===r.type){if(c(n,o))continue;n=d(n,o,r.checked?r.value:void 0);continue}if("file"===r.type){n=d(n,o,r.multiple?Array.from(r.files||[]):null===(t=r.files)||void 0===t?void 0:t[0]);continue}}const a=F(r);n=d(n,o,a)}return{defaultData:n}}function $(e,t){if(!A(e))return;const n=t;if(p(e)){if("checkbox"===e.type){const t=n;return void 0===t||"boolean"==typeof t?void(e.checked=!!t):void(Array.isArray(t)&&(t.includes(e.value)?e.checked=!0:e.checked=!1))}if("radio"===e.type){const t=n;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}e.value=String(null!=n?n:"")}function T(e,t){for(const n of e.elements){if(b(n)&&N(n),!A(n)||!n.name)continue;$(n,c(t,O(n)))}}function V(e,t){if(!r(e)&&!r(t)){if(null===e)return t;if(null===t)return e;if(e&&t)return Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]),[...e,...t]}}async function _(e,t){if(!t)return;if(!Array.isArray(t))return t(e);return a(...await Promise.all(t.map((t=>t(e)))),V)}function L(){}function D(e){let t;return function(e,...t){if(null==e)return L;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}(e,(e=>t=e))(),t}function M({stores:e,config:t,currentExtenders:n,extender:r}){var a;const{isSubmitting:u,data:v,touched:h,errors:b}=e;function N(e){var r,o,a;const l=null!==(r=null==e?void 0:e.onSubmit)&&void 0!==r?r:t.onSubmit,s=null!==(o=null==e?void 0:e.validate)&&void 0!==o?o:t.validate,c=null!==(a=null==e?void 0:e.onError)&&void 0!==a?a:t.onError;return async function(e){null==e||e.preventDefault(),u.set(!0);const t=D(v),r=await _(t,s);if(h.update((e=>i(e,!0))),r){b.set(r);if(m(r,(e=>!!e)))return n.forEach((e=>{var n;return null===(n=null==e?void 0:e.onSubmitError)||void 0===n?void 0:n.call(e,{data:t,errors:r})})),void u.set(!1)}try{await l(t)}catch(e){if(!c)throw e;const r=c(e);r&&(b.set(r),n.forEach((e=>{var n;return null===(n=null==e?void 0:e.onSubmitError)||void 0===n?void 0:n.call(e,{data:t,errors:r})})))}finally{u.set(!1)}}}function V(e,t){const n=void 0===t?e:`${e}[${t}]`;h.update((e=>d(e,n,!0)))}function L(e){v.set(o(e)),M&&T(M,e)}let M,I=null!==(a=t.initialValues)&&void 0!==a?a:{};const w=N();return{handleSubmit:w,createSubmitHandler:N,reset:function(){L(o(I)),h.update((e=>i(e,!1)))},setTouched:V,setError:function(e,t){b.update((n=>d(n,e,t)))},setField:function(e,t,n=!0){if(v.update((n=>d(n,e,t))),n&&V(e),M)for(const n of M.elements){if(!A(n)||!n.name)continue;const r=O(n);if(e===r)return void $(n,t)}},setFields:L,validate:async function(){const e=D(v);h.update((e=>i(e,!0)));const n=await _(e,t.validate);return b.set(n||{}),n},form:function(e){function a(n){return n({form:e,controls:Array.from(e.elements).filter(A),data:v,errors:b,touched:h,config:t})}n=r.map(a),e.noValidate=!!t.validate;const{defaultData:u}=k(e);function m(t){const n=y(t),r=O(t),o=Array.from(e.querySelectorAll(`[name="${t.name}"]`)).filter((e=>{if(!A(e))return!1;if(void 0!==n){return Number(e.dataset.felteIndex)===n}return r===O(e)}));return 1===o.length?v.update((e=>d(e,O(t),t.checked))):v.update((e=>d(e,O(t),o.filter(p).filter((e=>e.checked)).map((e=>e.value)))))}function N(e){var n;const r=e.target;if(!r||!A(r)||g(r)||j(r))return;if(["checkbox","radio","file"].includes(r.type))return;if(!r.name)return;(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.input)&&V(O(r));const o=F(r);v.update((e=>d(e,O(r),o)))}function $(n){var r;const o=n.target;o&&A(o)&&!j(o)&&o.name&&((null===(r=t.touchTriggerEvents)||void 0===r?void 0:r.change)&&V(O(o)),g(o)&&v.update((e=>d(e,O(o),o.value))),p(o)&&("checkbox"===o.type&&m(o),"radio"===o.type&&function(t){const n=e.querySelectorAll(`[name="${t.name}"]`),r=Array.from(n).find((e=>p(e)&&e.checked));v.update((e=>d(e,O(t),null==r?void 0:r.value)))}(o),"file"===o.type&&function(e){const t=e.files;v.update((n=>d(n,O(e),e.multiple?Array.from(null!=t?t:[]):null==t?void 0:t[0])))}(o)))}function T(e){var n;const r=e.target;r&&A(r)&&!j(r)&&r.name&&(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.blur)&&V(O(r))}function _(e){for(const t of e)"true"===t.dataset.felteUnsetOnRemove&&v.update((e=>f(e,S(t))))}M=e,I=s(o(u),I),L(I),h.set(i(I,!1));const D=new MutationObserver((function(t){for(const o of t)if("childList"===o.type){if(o.addedNodes.length>0){if(!Array.from(o.addedNodes).some((e=>{if(!E(e))return!1;if(A(e))return!0;return x(e).length>0})))continue;n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(a);const{defaultData:t}=k(e),u=i(t,!1);v.update((e=>l(e,t))),h.update((e=>l(e,u)))}if(o.removedNodes.length>0)for(const e of o.removedNodes){if(!E(e))continue;const t=x(e);0!==t.length&&(n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(a),_(t))}}}));D.observe(e,{childList:!0,subtree:!0}),e.addEventListener("input",N),e.addEventListener("change",$),e.addEventListener("focusout",T),e.addEventListener("submit",w);const C=b.subscribe((t=>{for(const n of e.elements){if(!A(n)||!n.name)continue;const e=c(t,O(n)),r=Array.isArray(e)?e.join("\n"):"string"==typeof e?e:void 0;r!==n.dataset.felteValidationMessage&&(r?n.dataset.felteValidationMessage=r:delete n.dataset.felteValidationMessage)}}));return{destroy(){D.disconnect(),e.removeEventListener("input",N),e.removeEventListener("change",$),e.removeEventListener("focusout",T),e.removeEventListener("submit",w),C(),n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)}))}}}}}e._cloneDeep=o,e._defaultsDeep=l,e._get=c,e._isPlainObject=r,e._mapValues=n,e._merge=s,e._mergeWith=a,e._set=d,e._some=t,e._unset=f,e._update=v,e.addAttrsFromFieldset=N,e.createForm=function(e,t){var n,i,u;null!==(n=e.reporter)&&void 0!==n||(e.reporter=[]),null!==(i=e.extend)&&void 0!==i||(e.extend=[]),null!==(u=e.touchTriggerEvents)&&void 0!==u||(e.touchTriggerEvents={change:!0,blur:!0}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]);const l=[...Array.isArray(e.reporter)?e.reporter:[e.reporter],...Array.isArray(e.extend)?e.extend:[e.extend]];let s=[];const{isSubmitting:c,data:d,errors:f,touched:v,isValid:m}=t.stores;s=l.map((t=>t({errors:f,touched:v,data:d,config:e})));const y=M({currentExtenders:s,extender:l,config:e,stores:{data:d,errors:f,touched:v,isValid:m,isSubmitting:c}});function p(e,t){if(!r(e))return e!==t}function h(e,t){if(!r(e))return t||e}return Object.assign({data:Object.assign(Object.assign({},d),{set:function(t){return v.update((n=>{const r=a(o(t),e.initialValues,p);return a(r,n,h)})),d.set(t)}}),errors:f,touched:v,isValid:m,isSubmitting:c},y)},e.deepSet=i,e.deepSome=m,e.executeValidation=_,e.getFormControls=x,e.getFormDefaultValues=k,e.getIndex=y,e.getInputTextOrNumber=F,e.getPath=O,e.getPathFromDataset=S,e.isElement=E,e.isFieldSetElement=b,e.isFieldValue=function(e){return Array.isArray(e)?0===e.length||e.some((e=>e instanceof File||"string"==typeof e)):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||e instanceof File},e.isFormControl=A,e.isInputElement=p,e.isSelectElement=g,e.isTextAreaElement=h,e.setControlValue=$,e.setForm=T,e.shouldIgnore=j,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Core={})}(this,(function(e){"use strict";function t(e,t){return Object.keys(e).some((n=>t(e[n])))}function n(e,t){return Object.keys(e).reduce(((n,r)=>Object.assign(Object.assign({},n),{[r]:t(e[r])})),{})}function r(e){return"[object Object]"===Object.prototype.toString.call(e)}function o(e){return Object.keys(e||{}).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:r(e[n])?o(e[n]):Array.isArray(e[n])?[...e[n]]:e[n]})),{})}function i(e,t){return n(e,(e=>r(e)?i(e,t):Array.isArray(e)?e.map(function(e){return function(t){return r(t)?i(t,e):e}}(t)):t))}function a(...e){const t=e.pop(),n=o(e.shift());if(0===e.length)return n;for(const u of e){if(!u)continue;const e=Object.keys(u);for(const l of e){const e=t(n[l],u[l]);if(void 0!==e)n[l]=e;else if(r(u[l])&&r(n[l]))n[l]=a(n[l],u[l],t);else if(Array.isArray(u[l]))n[l]=u[l].map(((e,o)=>r(e)?a(Array.isArray(n[l])?n[l][o]:n[l],e,t):e));else if(r(u[l])){const e=i(o(u[l]),void 0);n[l]=a(e,u[l],t)}else void 0!==u[l]&&(n[l]=u[l])}}return n}function u(e,t){if(!r(e)||!r(t)){if(Array.isArray(t)){if(t.some(r))return;const n=Array.isArray(e)?e:[];return t.map(((e,t)=>{var r;return null!==(r=n[t])&&void 0!==r?r:e}))}return void 0!==e?e:void 0}}function l(...e){return a(...e,u)}function d(...e){return a(...e,(()=>{}))}function s(e,t,n){const r=n=>String.prototype.split.call(t,n).filter(Boolean).reduce(((e,t)=>null!=e?e[t]:e),e),o=r(/[,[\]]+?/)||r(/[,[\].]+?/);return void 0===o||o===e?n:o}function c(e,t,n){Object(e)!==e?e={}:void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n,e}function f(e,t){var n;if(Object(e)!==e)return;void 0!==e&&(e=o(e));let r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g)||[];return null===(n=r.slice(0,-1).reduce(((e,t)=>Object(e[t])===e[t]?e[t]:void 0),e))||void 0===n||delete n[r[r.length-1]],e}function v(e,t,n){Object(e)!==e&&(e={});let r=t.toString().match(/[^.[\]]+/g)||[];return r.slice(0,-1).reduce(((e,t,n)=>Object(e[t])===e[t]?e[t]:e[t]=Math.abs(Number(r[n+1]))>>0==+r[n+1]?[]:{}),e)[r[r.length-1]]=n(s(e,t)),e}function m(e,n){return t(e,(e=>r(e)?m(e,n):n(e)))}function y(e){return e.hasAttribute("data-felte-index")?Number(e.dataset.felteIndex):void 0}function p(e){var t;return"INPUT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function h(e){var t;return"TEXTAREA"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function g(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function b(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function A(e){return p(e)||h(e)||g(e)}function E(e){return e.nodeType===Node.ELEMENT_NODE}function O(e,t){const n=y(e);let r="";t?r=t:A(e)&&(r=e.name),r=void 0===n?r:`${r}[${n}]`;let o=e.parentNode;if(!o)return r;for(;o&&"FORM"!==o.nodeName;){if(b(o)&&o.name){const e=y(o);r=`${void 0===e?o.name:`${o.name}[${e}]`}.${r}`}o=o.parentNode}return r}function S(e){const t=e.dataset.felteFieldset,n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;return t?`${t}.${r}`:r}function j(e){let t=e;for(;t&&"FORM"!==t.nodeName;){if(t.hasAttribute("data-felte-ignore"))return!0;t=t.parentElement}return!1}function x(e){if(A(e))return[e];if(0===e.childElementCount)return[];const t=new Set;for(const n of e.children){if(A(n)&&t.add(n),b(n))for(const e of n.elements)A(e)&&t.add(e);n.childElementCount>0&&x(n).forEach((e=>t.add(e)))}return Array.from(t)}function N(e){for(const t of e.elements)if(A(t)||b(t)){if(e.name&&t.name){const n=y(e),r=void 0===n?e.name:`${e.name}[${n}]`;t.dataset.felteFieldset=e.dataset.felteFieldset?`${e.dataset.felteFieldset}.${r}`:r}"true"!==e.dataset.felteUnsetOnRemove||t.hasAttribute("data-felte-unset-on-remove")||(t.dataset.felteUnsetOnRemove="true")}}function F(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function k(e){var t;let n={};for(const r of e.elements){if(b(r)&&N(r),!A(r)||!r.name)continue;const o=O(r),i=y(r);if(p(r)){if("checkbox"===r.type){if(void 0===s(n,o)){if(1===Array.from(e.querySelectorAll(`[name="${r.name}"]`)).filter((e=>!!A(e)&&(void 0!==i?Number(e.dataset.felteIndex)===i:o===O(e)))).length){n=c(n,o,r.checked);continue}n=c(n,o,r.checked?[r.value]:[]);continue}Array.isArray(s(n,o))&&r.checked&&v(n,o,(e=>(void 0===i||Array.isArray(e)||(e=[]),[...e,r.value])));continue}if("radio"===r.type){if(s(n,o))continue;n=c(n,o,r.checked?r.value:void 0);continue}if("file"===r.type){n=c(n,o,r.multiple?Array.from(r.files||[]):null===(t=r.files)||void 0===t?void 0:t[0]);continue}}const a=F(r);n=c(n,o,a)}return{defaultData:n}}function $(e,t){if(!A(e))return;const n=t;if(p(e)){if("checkbox"===e.type){const t=n;return void 0===t||"boolean"==typeof t?void(e.checked=!!t):void(Array.isArray(t)&&(t.includes(e.value)?e.checked=!0:e.checked=!1))}if("radio"===e.type){const t=n;return void(e.value===t?e.checked=!0:e.checked=!1)}if("file"===e.type)return e.files=null,void(e.value="")}e.value=String(null!=n?n:"")}function V(e,t){for(const n of e.elements){if(b(n)&&N(n),!A(n)||!n.name)continue;$(n,s(t,O(n)))}}function T(e,t){if(!r(e)&&!r(t)){if(null===e)return t;if(null===t)return e;if(e&&t)return Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]),[...e,...t]}}async function _(e,t){if(!t)return;if(!Array.isArray(t))return t(e);return a(...await Promise.all(t.map((t=>t(e)))),T)}function L(){}function D(e){let t;return function(e,...t){if(null==e)return L;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}(e,(e=>t=e))(),t}function M({stores:e,config:t,currentExtenders:n,extender:r,addValidator:a}){var u;const{isSubmitting:v,data:h,touched:b,errors:N}=e;function T(e){var r,o,a;const u=null!==(r=null==e?void 0:e.onSubmit)&&void 0!==r?r:t.onSubmit,l=null!==(o=null==e?void 0:e.validate)&&void 0!==o?o:t.validate,d=null!==(a=null==e?void 0:e.onError)&&void 0!==a?a:t.onError;return async function(e){null==e||e.preventDefault(),v.set(!0);const t=D(h),r=await _(t,l);if(b.update((e=>i(e,!0))),r){N.set(r);if(m(r,(e=>!!e)))return n.forEach((e=>{var n;return null===(n=null==e?void 0:e.onSubmitError)||void 0===n?void 0:n.call(e,{data:t,errors:r})})),void v.set(!1)}try{await u(t)}catch(e){if(!d)throw e;const r=d(e);r&&(N.set(r),n.forEach((e=>{var n;return null===(n=null==e?void 0:e.onSubmitError)||void 0===n?void 0:n.call(e,{data:t,errors:r})})))}finally{v.set(!1)}}}function L(e,t){const n=void 0===t?e:`${e}[${t}]`;b.update((e=>c(e,n,!0)))}function M(e){h.set(o(e)),I&&V(I,e)}let I,w=null!==(u=t.initialValues)&&void 0!==u?u:{};const C=T();return{handleSubmit:C,createSubmitHandler:T,reset:function(){M(o(w)),b.update((e=>i(e,!1)))},setTouched:L,setError:function(e,t){N.update((n=>c(n,e,t)))},setField:function(e,t,n=!0){if(h.update((n=>c(n,e,t))),n&&L(e),I)for(const n of I.elements){if(!A(n)||!n.name)continue;const r=O(n);if(e===r)return void $(n,t)}},setFields:M,validate:async function(){const e=D(h);b.update((e=>i(e,!0)));const n=await _(e,t.validate);return N.set(n||{}),n},form:function(e){function u(n){return n({form:e,controls:Array.from(e.elements).filter(A),data:h,errors:N,touched:b,config:t,addValidator:a})}n=r.map(u),e.noValidate=!!t.validate;const{defaultData:v}=k(e);function m(t){const n=y(t),r=O(t),o=Array.from(e.querySelectorAll(`[name="${t.name}"]`)).filter((e=>{if(!A(e))return!1;if(void 0!==n){return Number(e.dataset.felteIndex)===n}return r===O(e)}));return 1===o.length?h.update((e=>c(e,O(t),t.checked))):h.update((e=>c(e,O(t),o.filter(p).filter((e=>e.checked)).map((e=>e.value)))))}function $(e){var n;const r=e.target;if(!r||!A(r)||g(r)||j(r))return;if(["checkbox","radio","file"].includes(r.type))return;if(!r.name)return;(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.input)&&L(O(r));const o=F(r);h.update((e=>c(e,O(r),o)))}function V(n){var r;const o=n.target;o&&A(o)&&!j(o)&&o.name&&((null===(r=t.touchTriggerEvents)||void 0===r?void 0:r.change)&&L(O(o)),g(o)&&h.update((e=>c(e,O(o),o.value))),p(o)&&("checkbox"===o.type&&m(o),"radio"===o.type&&function(t){const n=e.querySelectorAll(`[name="${t.name}"]`),r=Array.from(n).find((e=>p(e)&&e.checked));h.update((e=>c(e,O(t),null==r?void 0:r.value)))}(o),"file"===o.type&&function(e){const t=e.files;h.update((n=>c(n,O(e),e.multiple?Array.from(null!=t?t:[]):null==t?void 0:t[0])))}(o)))}function T(e){var n;const r=e.target;r&&A(r)&&!j(r)&&r.name&&(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.blur)&&L(O(r))}function _(e){for(const t of e)"true"===t.dataset.felteUnsetOnRemove&&h.update((e=>f(e,S(t))))}I=e,w=d(o(v),w),M(w),b.set(i(w,!1));const D=new MutationObserver((function(t){for(const o of t)if("childList"===o.type){if(o.addedNodes.length>0){if(!Array.from(o.addedNodes).some((e=>{if(!E(e))return!1;if(A(e))return!0;return x(e).length>0})))continue;n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(u);const{defaultData:t}=k(e),a=i(t,!1);h.update((e=>l(e,t))),b.update((e=>l(e,a)))}if(o.removedNodes.length>0)for(const e of o.removedNodes){if(!E(e))continue;const t=x(e);0!==t.length&&(n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)})),n=r.map(u),_(t))}}}));D.observe(e,{childList:!0,subtree:!0}),e.addEventListener("input",$),e.addEventListener("change",V),e.addEventListener("focusout",T),e.addEventListener("submit",C);const P=N.subscribe((t=>{for(const n of e.elements){if(!A(n)||!n.name)continue;const e=s(t,O(n)),r=Array.isArray(e)?e.join("\n"):"string"==typeof e?e:void 0;r!==n.dataset.felteValidationMessage&&(r?n.dataset.felteValidationMessage=r:delete n.dataset.felteValidationMessage)}}));return{destroy(){D.disconnect(),e.removeEventListener("input",$),e.removeEventListener("change",V),e.removeEventListener("focusout",T),e.removeEventListener("submit",C),P(),n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)}))}}}}}e._cloneDeep=o,e._defaultsDeep=l,e._get=s,e._isPlainObject=r,e._mapValues=n,e._merge=d,e._mergeWith=a,e._set=c,e._some=t,e._unset=f,e._update=v,e.addAttrsFromFieldset=N,e.createForm=function(e,t){var n,i;function u(t){e.validate?e.validate=[...e.validate,t]:e.validate=[t]}null!==(n=e.extend)&&void 0!==n||(e.extend=[]),null!==(i=e.touchTriggerEvents)&&void 0!==i||(e.touchTriggerEvents={change:!0,blur:!0}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]);const l=Array.isArray(e.extend)?e.extend:[e.extend];let d=[];const{isSubmitting:s,data:c,errors:f,touched:v,isValid:m}=t.stores;d=l.map((t=>t({errors:f,touched:v,data:c,config:e,addValidator:u})));const y=M({currentExtenders:d,extender:l,config:e,addValidator:u,stores:{data:c,errors:f,touched:v,isValid:m,isSubmitting:s}});function p(e,t){if(!r(e))return e!==t}function h(e,t){if(!r(e))return t||e}return Object.assign({data:Object.assign(Object.assign({},c),{set:function(t){return v.update((n=>{const r=a(o(t),e.initialValues,p);return a(r,n,h)})),c.set(t)}}),errors:f,touched:v,isValid:m,isSubmitting:s},y)},e.deepSet=i,e.deepSome=m,e.executeValidation=_,e.getFormControls=x,e.getFormDefaultValues=k,e.getIndex=y,e.getInputTextOrNumber=F,e.getPath=O,e.getPathFromDataset=S,e.isElement=E,e.isFieldSetElement=b,e.isFieldValue=function(e){return Array.isArray(e)?0===e.length||e.some((e=>e instanceof File||"string"==typeof e)):"string"==typeof e||"number"==typeof e||"boolean"==typeof e||e instanceof File},e.isFormControl=A,e.isInputElement=p,e.isSelectElement=g,e.isTextAreaElement=h,e.setControlValue=$,e.setForm=V,e.shouldIgnore=j,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@felte/core", | ||
"version": "0.1.6", | ||
"version": "0.2.0", | ||
"description": "Core package for FelteJS", | ||
@@ -23,3 +23,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@felte/common": "0.4.10" | ||
"@felte/common": "0.5.0" | ||
}, | ||
@@ -26,0 +26,0 @@ "publishConfig": { |
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
224582
+ Added@felte/common@0.5.0(transitive)
- Removed@felte/common@0.4.10(transitive)
Updated@felte/common@0.5.0