@folo/forms
Version:
> React components combined of @folo/layout & @folo/values
3 lines (2 loc) • 8.81 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("@folo/store/src")):"function"==typeof define&&define.amd?define(["exports","react","@folo/store/src"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).foloForms={},e.react,e.Registry)}(this,function(e,t,n){var r=new n;function o(){return(o=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 i(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 l="blur",a=function(e){var n,a,c,u,s=e.coreComponent,f=e.initValue,p=e.nameRef,d=e.groupName,y=e.valueRef,m=e.isInput,v=e.storeID,g=e.onBlur,b=e.onChange,h=e.children,O=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}(e,["coreComponent","initValue","nameRef","groupName","valueRef","isInput","storeID","onBlur","onChange","children"]),w=function(e){if(Array.isArray(e))return e}(u=t.useState(f))||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}}(u)||function(e,t){if(e){if("string"==typeof e)return i(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)?i(e,2):void 0}}(u)||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=w[0],I=w[1];function R(e){var t=e.target[y],n=e.type;n===l&&"function"==typeof g?g(e):(I(t),"function"==typeof b&&b(e)),m&&n!==l||r.updater({nameRef:p,newValue:t,groupName:d,storeID:v})}return t.useEffect(function(){r.subscribe({nameRef:p,initValue:f,groupName:d,storeID:v},I)},[f]),t.createElement(s,o({},(c=j,(a=y)in(n={})?Object.defineProperty(n,a,{value:c,enumerable:!0,configurable:!0,writable:!0}):n[a]=c,n),{onChange:R,onBlur:R},O),h)},c="select";function u(){return(u=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 s(){return(s=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 f=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}()),p="stretch",d="center",y="space-between",m="auto";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 g(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 b(e,t){return null!==e&&null!==t?"".concat(e," / ").concat(t):"".concat(e)}function h(){return(h=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){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 w(e,t,n,r){return"repeat(".concat(e,", ").concat(t||"minmax(".concat(n,", ").concat(r,")"),")")}e.Field=function(e){var n=e.component,r=e.valueKey,o=e.id,i=e.value,l=void 0===i?"":i,s=e.checked,f=void 0!==s&&s,p=e.type,d=void 0===p?"text":p,y=e.groupName,m=void 0===y?null:y,v=e.storeID,g=e.children,b=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}(e,["component","valueKey","id","value","checked","type","groupName","storeID","children"]),h=function(e){var t=e.type,n=!1,r="input",o="value",i=e.value;return t===c||"list"===t?r=c:"checkbox"===t||"radio"===t?(o="checked",i=e.checked):n=!0,{isInput:n,valueRef:o,initValue:i,RecommendedComponent:r}}({type:d,checked:f,value:l}),O=h.valueRef,w=h.isInput,j=h.initValue,I=h.RecommendedComponent,R=r||o||"".concat((new Date).getTime());return t.createElement(a,u({valueRef:O,initValue:j,isInput:w,groupName:m,nameRef:R,coreComponent:n||I,type:d,id:o,storeID:v},b),g)},e.Form=function(e){var n=e.component,o=void 0===n?"form":n,i=e.onSubmit,l=e.storeID,a=e.children,c=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}(e,["component","onSubmit","storeID","children"]);return t.useEffect(function(){return function(){r.clear(l)}}),t.createElement(o,s({onSubmit:function(e){e.preventDefault(),"function"==typeof i&&i(e,r.getDataByStoreID(l))}},c),a)},e.Grid=function(e){var n=e.component,r=void 0===n?"div":n,o=e.col,i=void 0===o?null:o,l=e.colWidth,a=e.colMinWidth,c=void 0===a?m:a,u=e.colMaxWidth,s=void 0===u?"1fr":u,f=e.row,v=void 0===f?null:f,g=e.rowWidth,b=e.rowMinWidth,j=void 0===b?m:b,I=e.rowMaxWidth,R=void 0===I?"1fr":I,x=e.isCenter,P=void 0!==x&&x,C=e.style,S=(C=void 0===C?{}:C).display,D=void 0===S?"grid":S,k=C.alignItems,E=void 0===k?P?d:p:k,W=C.justifyContent,M=void 0===W?i||l?y:P?d:p:W,A=C.gap,T=void 0===A?"1em":A,N=O(C,["display","alignItems","justifyContent","gap"]),V=e.children,B=O(e,["component","col","colWidth","colMinWidth","colMaxWidth","row","rowWidth","rowMinWidth","rowMaxWidth","isCenter","style","children"]),F=Object.assign({display:D},v?{gridTemplateRows:w(v,g,j,R)}:g&&{gridAutoRows:g},l&&!i?{gridAutoColumns:l}:{gridTemplateColumns:w(i||"auto-fit",l,c,s)},{alignItems:E,justifyContent:M,gap:T},N);return t.createElement(r,h({style:F},B),V)},e.GridItem=function(e){var n=e.component,r=void 0===n?"div":n,o=e.row,i=void 0===o?null:o,l=e.toRow,a=void 0===l?null:l,c=e.col,u=void 0===c?0:c,s=e.toCol,m=void 0===s?null:s,h=e.isCenter,O=void 0!==h&&h,w=e.isHorizontal,j=void 0===w||w,I=e.style,R=(I=void 0===I?{}:I).display,x=void 0===R?"flex":R,P=I.flexDirection,C=I.alignItems,S=g(I,["display","flexDirection","alignItems"]),D=e.id,k=e.children,E=g(e,["component","row","toRow","col","toCol","isCenter","isHorizontal","style","id","children"]),W=f.autoPosition({key:D||"".concat((new Date).getTime()),row:i,toRow:a}),M=Object.assign({display:x},j?{flexDirection:P||"row",alignItems:C||d}:{flexDirection:P||"column",alignItems:C||p},{justifyContent:O?d:y,gridRow:b(W,a),gridColumn:b(u,m)},S);return t.createElement(r,v({style:M},E),k)}});
//# sourceMappingURL=foloForms.min.umd.js.map