@folo/forms
Version:
> React components combined of @folo/layout & @folo/values
3 lines (2 loc) • 8.63 kB
JavaScript
import e from"react";import t from"@folo/store/src";var n=new t;function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var i=function(t){var i,l,a,c,u=t.coreComponent,s=t.initValue,f=t.nameRef,p=t.groupName,y=t.valueRef,d=t.isInput,v=t.storeID,m=t.onBlur,g=t.onChange,b=t.children,h=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(t,["coreComponent","initValue","nameRef","groupName","valueRef","isInput","storeID","onBlur","onChange","children"]),O=function(e){if(Array.isArray(e))return e}(c=e.useState(s))||function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var n=[],r=!0,o=!1,i=void 0;try{for(var l,a=e[Symbol.iterator]();!(r=(l=a.next()).done)&&(n.push(l.value),2!==n.length);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}}(c)||function(e,t){if(e){if("string"==typeof e)return o(e,2);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(e,2):void 0}}(c)||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.")}(),w=O[0],j=O[1];function I(e){var t=e.target[y],r=e.type;"blur"===r&&"function"==typeof m?m(e):(j(t),"function"==typeof g&&g(e)),d&&"blur"!==r||n.updater({nameRef:f,newValue:t,groupName:p,storeID:v})}return e.useEffect(function(){n.subscribe({nameRef:f,initValue:s,groupName:p,storeID:v},j)},[s]),e.createElement(u,r({},(a=w,(l=y)in(i={})?Object.defineProperty(i,l,{value:a,enumerable:!0,configurable:!0,writable:!0}):i[l]=a,i),{onChange:I,onBlur:I},h),b)};function l(){return(l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var a=function(t){var n=t.component,r=t.valueKey,o=t.id,a=t.value,c=void 0===a?"":a,u=t.checked,s=void 0!==u&&u,f=t.type,p=void 0===f?"text":f,y=t.groupName,d=void 0===y?null:y,v=t.storeID,m=t.children,g=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(t,["component","valueKey","id","value","checked","type","groupName","storeID","children"]),b=function(e){var t=e.type,n=!1,r="input",o="value",i=e.value;return"select"===t||"list"===t?r="select":"checkbox"===t||"radio"===t?(o="checked",i=e.checked):n=!0,{isInput:n,valueRef:o,initValue:i,RecommendedComponent:r}}({type:p,checked:s,value:c}),h=b.valueRef,O=b.isInput,w=b.initValue,j=b.RecommendedComponent,I=r||o||"".concat((new Date).getTime());return e.createElement(i,l({valueRef:h,initValue:w,isInput:O,groupName:d,nameRef:I,coreComponent:n||j,type:p,id:o,storeID:v},g),m)};function c(){return(c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var u=function(t){var r=t.component,o=void 0===r?"form":r,i=t.onSubmit,l=t.storeID,a=t.children,u=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(t,["component","onSubmit","storeID","children"]);return e.useEffect(function(){return function(){n.clear(l)}}),e.createElement(o,c({onSubmit:function(e){e.preventDefault(),"function"==typeof i&&i(e,n.getDataByStoreID(l))}},u),a)},s=new(function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.cellPositions={},this.biggestRowItem=0}var t;return(t=[{key:"autoPosition",value:function(e){var t=e.key,n=e.row,r=e.toRow,o=parseInt(n,10),i=parseInt(r,10);if(i&&o){this.cellPositions[t]=o;var l=i>o?i:o;l>this.biggestRowItem&&(this.biggestRowItem=l)}else o?(this.cellPositions[t]=o,o>this.biggestRowItem&&(this.biggestRowItem=o)):(this.biggestRowItem+=1,this.cellPositions[t]=this.biggestRowItem,i>this.biggestRowItem&&(this.biggestRowItem=i));return this.cellPositions[t]}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(e.prototype,t),e}());function f(){return(f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function p(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function y(e,t){return null!==e&&null!==t?"".concat(e," / ").concat(t):"".concat(e)}var d=function(t){var n=t.component,r=void 0===n?"div":n,o=t.row,i=void 0===o?null:o,l=t.toRow,a=void 0===l?null:l,c=t.col,u=void 0===c?0:c,d=t.toCol,v=void 0===d?null:d,m=t.isCenter,g=void 0!==m&&m,b=t.isHorizontal,h=void 0===b||b,O=t.style,w=(O=void 0===O?{}:O).display,j=void 0===w?"flex":w,I=O.flexDirection,R=O.alignItems,x=p(O,["display","flexDirection","alignItems"]),P=t.id,C=t.children,S=p(t,["component","row","toRow","col","toCol","isCenter","isHorizontal","style","id","children"]),D=s.autoPosition({key:P||"".concat((new Date).getTime()),row:i,toRow:a}),k=Object.assign({display:j},h?{flexDirection:I||"row",alignItems:R||"center"}:{flexDirection:I||"column",alignItems:R||"stretch"},{justifyContent:g?"center":"space-between",gridRow:y(D,a),gridColumn:y(u,v)},x);return e.createElement(r,f({style:k},S),C)};function v(){return(v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function m(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function g(e,t,n,r){return"repeat(".concat(e,", ").concat(t||"minmax(".concat(n,", ").concat(r,")"),")")}var b=function(t){var n=t.component,r=void 0===n?"div":n,o=t.col,i=void 0===o?null:o,l=t.colWidth,a=t.colMinWidth,c=void 0===a?"auto":a,u=t.colMaxWidth,s=void 0===u?"1fr":u,f=t.row,p=void 0===f?null:f,y=t.rowWidth,d=t.rowMinWidth,b=void 0===d?"auto":d,h=t.rowMaxWidth,O=void 0===h?"1fr":h,w=t.isCenter,j=void 0!==w&&w,I=t.style,R=(I=void 0===I?{}:I).display,x=void 0===R?"grid":R,P=I.alignItems,C=void 0===P?j?"center":"stretch":P,S=I.justifyContent,D=void 0===S?i||l?"space-between":j?"center":"stretch":S,k=I.gap,E=void 0===k?"1em":k,W=m(I,["display","alignItems","justifyContent","gap"]),M=t.children,A=m(t,["component","col","colWidth","colMinWidth","colMaxWidth","row","rowWidth","rowMinWidth","rowMaxWidth","isCenter","style","children"]),N=Object.assign({display:x},p?{gridTemplateRows:g(p,y,b,O)}:y&&{gridAutoRows:y},l&&!i?{gridAutoColumns:l}:{gridTemplateColumns:g(i||"auto-fit",l,c,s)},{alignItems:C,justifyContent:D,gap:E},W);return e.createElement(r,v({style:N},A),M)};export{a as Field,u as Form,b as Grid,d as GridItem};
//# sourceMappingURL=foloForms.min.esm.js.map