@folo/values
Version:
> A from store returns input values with zero config
3 lines (2 loc) • 4.65 kB
JavaScript
import e from"react";import t from"@folo/store/src";var r=new t;function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var u=function(t){var u,a,i,l,c=t.coreComponent,f=t.initValue,p=t.nameRef,y=t.groupName,s=t.valueRef,m=t.isInput,v=t.storeID,b=t.onBlur,d=t.onChange,h=t.children,g=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,["coreComponent","initValue","nameRef","groupName","valueRef","isInput","storeID","onBlur","onChange","children"]),O=function(e){if(Array.isArray(e))return e}(l=e.useState(f))||function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var r=[],n=!0,o=!1,u=void 0;try{for(var a,i=e[Symbol.iterator]();!(n=(a=i.next()).done)&&(r.push(a.value),2!==r.length);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==i.return||i.return()}finally{if(o)throw u}}return r}}(l)||function(e,t){if(e){if("string"==typeof e)return o(e,2);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,2):void 0}}(l)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),j=O[0],I=O[1];function w(e){var t=e.target[s],n=e.type;"blur"===n&&"function"==typeof b?b(e):(I(t),"function"==typeof d&&d(e)),m&&"blur"!==n||r.updater({nameRef:p,newValue:t,groupName:y,storeID:v})}return e.useEffect(function(){r.subscribe({nameRef:p,initValue:f,groupName:y,storeID:v},I)},[f]),e.createElement(c,n({},(i=j,(a=s)in(u={})?Object.defineProperty(u,a,{value:i,enumerable:!0,configurable:!0,writable:!0}):u[a]=i,u),{onChange:w,onBlur:w},g),h)};function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var i=function(t){var r=t.component,n=t.valueKey,o=t.id,i=t.value,l=void 0===i?"":i,c=t.checked,f=void 0!==c&&c,p=t.type,y=void 0===p?"text":p,s=t.groupName,m=void 0===s?null:s,v=t.storeID,b=t.children,d=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,["component","valueKey","id","value","checked","type","groupName","storeID","children"]),h=function(e){var t=e.type,r=!1,n="input",o="value",u=e.value;return"select"===t||"list"===t?n="select":"checkbox"===t||"radio"===t?(o="checked",u=e.checked):r=!0,{isInput:r,valueRef:o,initValue:u,RecommendedComponent:n}}({type:y,checked:f,value:l}),g=h.valueRef,O=h.isInput,j=h.initValue,I=h.RecommendedComponent,w=n||o||"".concat((new Date).getTime());return e.createElement(u,a({valueRef:g,initValue:j,isInput:O,groupName:m,nameRef:w,coreComponent:r||I,type:y,id:o,storeID:v},d),b)};function l(){return(l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var c=function(t){var n=t.component,o=void 0===n?"form":n,u=t.onSubmit,a=t.storeID,i=t.children,c=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,["component","onSubmit","storeID","children"]);return e.useEffect(function(){return function(){r.clear(a)}}),e.createElement(o,l({onSubmit:function(e){e.preventDefault(),"function"==typeof u&&u(e,r.getDataByStoreID(a))}},c),i)};export{i as Field,c as Form};
//# sourceMappingURL=foloValues.min.esm.js.map