Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@felte/core

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@felte/core - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

9

CHANGELOG.md
# @felte/core
## 0.1.1
### Patch Changes
- Fix issues due to mutability of common functions
- Updated dependencies [undefined]
- @felte/common@0.4.4
## 0.1.0
### Minor Changes
- 809f9af: Refactor to use a common core

2

dist/index.js

@@ -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]):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 u(...e){const t=e.pop(),n=o(e.shift());if(0===e.length)return n;for(const a of e){if(!a)continue;const e=Object.keys(a);for(const s of e){const e=t(n[s],a[s]);if(void 0!==e)n[s]=e;else if(r(a[s])&&r(n[s]))n[s]=u(n[s],a[s],t);else if(Array.isArray(a[s])&&Array.isArray(n[s]))n[s]=a[s].map(((e,r)=>u(n[s][r],e,t)));else if(r(a[s])){const e=i(o(a[s]),void 0);n[s]=u(e,a[s],t)}else void 0!==a[s]&&(n[s]=a[s])}}return n}function a(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 s(...e){return u(...e,a)}function c(...e){return u(...e,(()=>{}))}function l(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={});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;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(l(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 b(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function g(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function A(e){return p(e)||h(e)||b(e)}function E(e){return e.nodeType===Node.ELEMENT_NODE}function O(e){const t=e.dataset.felteFieldset,n=function(e){return e.hasAttribute("data-felte-index")?Number(e.dataset.felteIndex):void 0}(e),r=void 0===n?e.name:`${e.name}[${n}]`;return t?`${t}.${r}`:r}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),g(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 S(e){for(const t of e.elements)if(A(t)||g(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 j(e){return e.type.match(/^(number|range)$/)?e.value?+e.value:void 0:e.value}function k(e){var t;const n={};for(const r of e.elements){if(g(r)&&S(r),!A(r)||!r.name)continue;const o=O(r),i=y(r);if(p(r)){if("checkbox"===r.type){if(void 0===l(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){d(n,o,r.checked);continue}d(n,o,r.checked?[r.value]:[]);continue}Array.isArray(l(n,o))&&r.checked&&v(n,o,(e=>(void 0===i||Array.isArray(e)||(e=[]),[...e,r.value])));continue}if("radio"===r.type){if(l(n,o))continue;d(n,o,r.checked?r.value:void 0);continue}if("file"===r.type){d(n,o,r.multiple?Array.from(r.files||[]):null===(t=r.files)||void 0===t?void 0:t[0]);continue}}const u=j(r);d(n,o,u)}return{defaultData:n}}function N(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(n||"")}function F(e,t){for(const n of e.elements){if(g(n)&&S(n),!A(n)||!n.name)continue;N(n,l(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 V(e,t){if(!t)return;if(!Array.isArray(t))return t(e);return u(...await Promise.all(t.map((t=>t(e)))),T)}function $(){}function _(e){let t;return function(e,...t){if(null==e)return $;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}(e,(e=>t=e))(),t}function L({stores:e,config:t,currentExtenders:n,extender:r}){var u;const{isSubmitting:a,data:v,touched:h,errors:g}=e;function S(e){var r,o,u;const s=null!==(r=null==e?void 0:e.onSubmit)&&void 0!==r?r:t.onSubmit,c=null!==(o=null==e?void 0:e.validate)&&void 0!==o?o:t.validate,l=null!==(u=null==e?void 0:e.onError)&&void 0!==u?u:t.onError;return async function(e){null==e||e.preventDefault(),a.set(!0);const t=_(v),r=await V(t,c);if(h.update((e=>i(e,!0))),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 a.set(!1)}try{await s(t)}catch(e){if(!l)throw e;const r=l(e);r&&(g.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{a.set(!1)}}}function T(e,t){const n=void 0===t?e:`${e}[${t}]`;h.update((e=>d(e,n,!0)))}function $(e){v.set(o(e)),L&&F(L,e)}let L,D=null!==(u=t.initialValues)&&void 0!==u?u:{};const I=S();return{handleSubmit:I,createSubmitHandler:S,reset:function(){$(o(D)),h.update((e=>i(e,!1)))},setTouched:T,setError:function(e,t){g.update((n=>d(n,e,t)))},setField:function(e,t,n=!0){if(v.update((n=>d(n,e,t))),n&&T(e),L)for(const n of L.elements){if(!A(n)||!n.name)continue;const r=O(n);if(e===r)return void N(n,t)}},setFields:$,validate:async function(){const e=_(v);h.update((e=>i(e,!0)));const n=await V(e,t.validate);return g.set(n||{}),n},form:function(e){function u(n){return n({form:e,controls:Array.from(e.elements).filter(A),data:v,errors:g,touched:h,config:t})}n=r.map(u),e.noValidate=!!t.validate;const{defaultData:a}=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 S(e){var n;const r=e.target;if(!r||!A(r)||b(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)&&T(O(r));const o=j(r);v.update((e=>d(e,O(r),o)))}function N(n){var r;const o=n.target;o&&A(o)&&o.name&&((null===(r=t.touchTriggerEvents)||void 0===r?void 0:r.change)&&T(O(o)),b(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 F(e){var n;const r=e.target;r&&A(r)&&r.name&&(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.blur)&&T(O(r))}function V(e){for(const t of e)"true"===t.dataset.felteUnsetOnRemove&&v.update((e=>f(e,O(t))))}L=e,D=c(o(a),D),$(D),h.set(i(D,!1));const _=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),c=s(i(a,!1));v.update((e=>s(e,t))),h.update((e=>s(e,c)))}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),V(t))}}}));_.observe(e,{childList:!0,subtree:!0}),e.addEventListener("input",S),e.addEventListener("change",N),e.addEventListener("focusout",F),e.addEventListener("submit",I);const M=g.subscribe((t=>{for(const n of e.elements){if(!A(n)||!n.name)continue;const e=l(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(){_.disconnect(),e.removeEventListener("input",S),e.removeEventListener("change",N),e.removeEventListener("focusout",F),e.removeEventListener("submit",I),M(),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=s,e._get=l,e._isPlainObject=r,e._mapValues=n,e._merge=c,e._mergeWith=u,e._set=d,e._some=t,e._unset=f,e._update=v,e.addAttrsFromFieldset=S,e.createForm=function(e,t){var n,i,a;null!==(n=e.reporter)&&void 0!==n||(e.reporter=[]),null!==(i=e.extend)&&void 0!==i||(e.extend=[]),null!==(a=e.touchTriggerEvents)&&void 0!==a||(e.touchTriggerEvents={change:!0,blur:!0}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]);const s=[...Array.isArray(e.reporter)?e.reporter:[e.reporter],...Array.isArray(e.extend)?e.extend:[e.extend]];let c=[];const{isSubmitting:l,data:d,errors:f,touched:v,isValid:m}=t.stores;c=s.map((t=>t({errors:f,touched:v,data:d,config:e})));const y=L({currentExtenders:c,extender:s,config:e,stores:{data:d,errors:f,touched:v,isValid:m,isSubmitting:l}});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=u(o(t),e.initialValues,p);return u(r,n,h)})),d.set(t)}}),errors:f,touched:v,isValid:m,isSubmitting:l},y)},e.deepSet=i,e.deepSome=m,e.executeValidation=V,e.getFormControls=x,e.getFormDefaultValues=k,e.getIndex=y,e.getInputTextOrNumber=j,e.getPath=O,e.isElement=E,e.isFieldSetElement=g,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=b,e.isTextAreaElement=h,e.setControlValue=N,e.setForm=F,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 i(e){return Object.keys(e||{}).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:r(e[n])?i(e[n]):Array.isArray(e[n])?[...e[n]]:e[n]})),{})}function o(e,t){return n(e,(e=>r(e)?o(e,t):Array.isArray(e)?e.map(function(e){return function(t){return r(t)?o(t,e):e}}(t)):t))}function u(...e){const t=e.pop(),n=i(e.shift());if(0===e.length)return n;for(const a of e){if(!a)continue;const e=Object.keys(a);for(const s of e){const e=t(n[s],a[s]);if(void 0!==e)n[s]=e;else if(r(a[s])&&r(n[s]))n[s]=u(n[s],a[s],t);else if(Array.isArray(a[s])&&Array.isArray(n[s]))n[s]=a[s].map(((e,r)=>u(n[s][r],e,t)));else if(r(a[s])){const e=o(i(a[s]),void 0);n[s]=u(e,a[s],t)}else void 0!==a[s]&&(n[s]=a[s])}}return n}function a(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 s(...e){return u(...e,a)}function l(...e){return u(...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),i=r(/[,[\]]+?/)||r(/[,[\].]+?/);return void 0===i||i===e?n:i}function d(e,t,n){Object(e)!==e?e={}:void 0!==e&&(e=i(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=i(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 b(e){var t;return"SELECT"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function g(e){var t;return"FIELDSET"===(null===(t=e)||void 0===t?void 0:t.nodeName)}function A(e){return p(e)||h(e)||b(e)}function E(e){return e.nodeType===Node.ELEMENT_NODE}function O(e){const t=e.dataset.felteFieldset,n=function(e){return e.hasAttribute("data-felte-index")?Number(e.dataset.felteIndex):void 0}(e),r=void 0===n?e.name:`${e.name}[${n}]`;return t?`${t}.${r}`:r}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),g(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 S(e){for(const t of e.elements)if(A(t)||g(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 j(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(g(r)&&S(r),!A(r)||!r.name)continue;const i=O(r),o=y(r);if(p(r)){if("checkbox"===r.type){if(void 0===c(n,i)){if(1===Array.from(e.querySelectorAll(`[name="${r.name}"]`)).filter((e=>!!A(e)&&(void 0!==o?Number(e.dataset.felteIndex)===o:i===O(e)))).length){n=d(n,i,r.checked);continue}n=d(n,i,r.checked?[r.value]:[]);continue}Array.isArray(c(n,i))&&r.checked&&v(n,i,(e=>(void 0===o||Array.isArray(e)||(e=[]),[...e,r.value])));continue}if("radio"===r.type){if(c(n,i))continue;n=d(n,i,r.checked?r.value:void 0);continue}if("file"===r.type){n=d(n,i,r.multiple?Array.from(r.files||[]):null===(t=r.files)||void 0===t?void 0:t[0]);continue}}const u=j(r);n=d(n,i,u)}return{defaultData:n}}function N(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(n||"")}function F(e,t){for(const n of e.elements){if(g(n)&&S(n),!A(n)||!n.name)continue;N(n,c(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 V(e,t){if(!t)return;if(!Array.isArray(t))return t(e);return u(...await Promise.all(t.map((t=>t(e)))),T)}function $(){}function _(e){let t;return function(e,...t){if(null==e)return $;const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}(e,(e=>t=e))(),t}function L({stores:e,config:t,currentExtenders:n,extender:r}){var u;const{isSubmitting:a,data:v,touched:h,errors:g}=e;function S(e){var r,i,u;const s=null!==(r=null==e?void 0:e.onSubmit)&&void 0!==r?r:t.onSubmit,l=null!==(i=null==e?void 0:e.validate)&&void 0!==i?i:t.validate,c=null!==(u=null==e?void 0:e.onError)&&void 0!==u?u:t.onError;return async function(e){null==e||e.preventDefault(),a.set(!0);const t=_(v),r=await V(t,l);if(h.update((e=>o(e,!0))),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 a.set(!1)}try{await s(t)}catch(e){if(!c)throw e;const r=c(e);r&&(g.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{a.set(!1)}}}function T(e,t){const n=void 0===t?e:`${e}[${t}]`;h.update((e=>d(e,n,!0)))}function $(e){v.set(i(e)),L&&F(L,e)}let L,D=null!==(u=t.initialValues)&&void 0!==u?u:{};const I=S();return{handleSubmit:I,createSubmitHandler:S,reset:function(){$(i(D)),h.update((e=>o(e,!1)))},setTouched:T,setError:function(e,t){g.update((n=>d(n,e,t)))},setField:function(e,t,n=!0){if(v.update((n=>d(n,e,t))),n&&T(e),L)for(const n of L.elements){if(!A(n)||!n.name)continue;const r=O(n);if(e===r)return void N(n,t)}},setFields:$,validate:async function(){const e=_(v);h.update((e=>o(e,!0)));const n=await V(e,t.validate);return g.set(n||{}),n},form:function(e){function u(n){return n({form:e,controls:Array.from(e.elements).filter(A),data:v,errors:g,touched:h,config:t})}n=r.map(u),e.noValidate=!!t.validate;const{defaultData:a}=k(e);function m(t){const n=y(t),r=O(t),i=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===i.length?v.update((e=>d(e,O(t),t.checked))):v.update((e=>d(e,O(t),i.filter(p).filter((e=>e.checked)).map((e=>e.value)))))}function S(e){var n;const r=e.target;if(!r||!A(r)||b(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)&&T(O(r));const i=j(r);v.update((e=>d(e,O(r),i)))}function N(n){var r;const i=n.target;i&&A(i)&&i.name&&((null===(r=t.touchTriggerEvents)||void 0===r?void 0:r.change)&&T(O(i)),b(i)&&v.update((e=>d(e,O(i),i.value))),p(i)&&("checkbox"===i.type&&m(i),"radio"===i.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)))}(i),"file"===i.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])))}(i)))}function F(e){var n;const r=e.target;r&&A(r)&&r.name&&(null===(n=t.touchTriggerEvents)||void 0===n?void 0:n.blur)&&T(O(r))}function V(e){for(const t of e)"true"===t.dataset.felteUnsetOnRemove&&v.update((e=>f(e,O(t))))}L=e,D=l(i(a),D),$(D),h.set(o(D,!1));const _=new MutationObserver((function(t){for(const i of t)if("childList"===i.type){if(i.addedNodes.length>0){if(!Array.from(i.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=o(t,!1);v.update((e=>s(e,t))),h.update((e=>s(e,a)))}if(i.removedNodes.length>0)for(const e of i.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),V(t))}}}));_.observe(e,{childList:!0,subtree:!0}),e.addEventListener("input",S),e.addEventListener("change",N),e.addEventListener("focusout",F),e.addEventListener("submit",I);const M=g.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(){_.disconnect(),e.removeEventListener("input",S),e.removeEventListener("change",N),e.removeEventListener("focusout",F),e.removeEventListener("submit",I),M(),n.forEach((e=>{var t;return null===(t=null==e?void 0:e.destroy)||void 0===t?void 0:t.call(e)}))}}}}}e._cloneDeep=i,e._defaultsDeep=s,e._get=c,e._isPlainObject=r,e._mapValues=n,e._merge=l,e._mergeWith=u,e._set=d,e._some=t,e._unset=f,e._update=v,e.addAttrsFromFieldset=S,e.createForm=function(e,t){var n,o,a;null!==(n=e.reporter)&&void 0!==n||(e.reporter=[]),null!==(o=e.extend)&&void 0!==o||(e.extend=[]),null!==(a=e.touchTriggerEvents)&&void 0!==a||(e.touchTriggerEvents={change:!0,blur:!0}),e.validate&&!Array.isArray(e.validate)&&(e.validate=[e.validate]);const s=[...Array.isArray(e.reporter)?e.reporter:[e.reporter],...Array.isArray(e.extend)?e.extend:[e.extend]];let l=[];const{isSubmitting:c,data:d,errors:f,touched:v,isValid:m}=t.stores;l=s.map((t=>t({errors:f,touched:v,data:d,config:e})));const y=L({currentExtenders:l,extender:s,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=u(i(t),e.initialValues,p);return u(r,n,h)})),d.set(t)}}),errors:f,touched:v,isValid:m,isSubmitting:c},y)},e.deepSet=o,e.deepSome=m,e.executeValidation=V,e.getFormControls=x,e.getFormDefaultValues=k,e.getIndex=y,e.getInputTextOrNumber=j,e.getPath=O,e.isElement=E,e.isFieldSetElement=g,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=b,e.isTextAreaElement=h,e.setControlValue=N,e.setForm=F,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map
{
"name": "@felte/core",
"version": "0.1.0",
"version": "0.1.1",
"description": "Core package for FelteJS",

@@ -23,3 +23,3 @@ "main": "dist/index.js",

"dependencies": {
"@felte/common": "^0.4.3"
"@felte/common": "^0.4.4"
},

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc