UNPKG

@folo/forms

Version:

> React components combined of @folo/layout & @folo/values

3 lines (2 loc) 8.6 kB
var e=require("react"),t=new(require("@folo/store/src"));function n(){return(n=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 r(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 o=function(o){var i,l,a,c,u=o.coreComponent,s=o.initValue,f=o.nameRef,p=o.groupName,d=o.valueRef,y=o.isInput,v=o.storeID,m=o.onBlur,g=o.onChange,b=o.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}(o,["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 r(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)?r(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 n=e.target[d],r=e.type;"blur"===r&&"function"==typeof m?m(e):(j(n),"function"==typeof g&&g(e)),y&&"blur"!==r||t.updater({nameRef:f,newValue:n,groupName:p,storeID:v})}return e.useEffect(function(){t.subscribe({nameRef:f,initValue:s,groupName:p,storeID:v},j)},[s]),e.createElement(u,n({},(a=w,(l=d)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 i(){return(i=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 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=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 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)}function u(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 s(e,t){return null!==e&&null!==t?"".concat(e," / ").concat(t):"".concat(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 d(e,t,n,r){return"repeat(".concat(e,", ").concat(t||"minmax(".concat(n,", ").concat(r,")"),")")}exports.Field=function(t){var n=t.component,r=t.valueKey,l=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,d=t.groupName,y=void 0===d?null:d,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||l||"".concat((new Date).getTime());return e.createElement(o,i({valueRef:h,initValue:w,isInput:O,groupName:y,nameRef:I,coreComponent:n||j,type:p,id:l,storeID:v},g),m)},exports.Form=function(n){var r=n.component,o=void 0===r?"form":r,i=n.onSubmit,a=n.storeID,c=n.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}(n,["component","onSubmit","storeID","children"]);return e.useEffect(function(){return function(){t.clear(a)}}),e.createElement(o,l({onSubmit:function(e){e.preventDefault(),"function"==typeof i&&i(e,t.getDataByStoreID(a))}},u),c)},exports.Grid=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,y=t.row,v=void 0===y?null:y,m=t.rowWidth,g=t.rowMinWidth,b=void 0===g?"auto":g,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=p(I,["display","alignItems","justifyContent","gap"]),M=t.children,A=p(t,["component","col","colWidth","colMinWidth","colMaxWidth","row","rowWidth","rowMinWidth","rowMaxWidth","isCenter","style","children"]),N=Object.assign({display:x},v?{gridTemplateRows:d(v,m,b,O)}:m&&{gridAutoRows:m},l&&!i?{gridAutoColumns:l}:{gridTemplateColumns:d(i||"auto-fit",l,c,s)},{alignItems:C,justifyContent:D,gap:E},W);return e.createElement(r,f({style:N},A),M)},exports.GridItem=function(t){var n=t.component,r=void 0===n?"div":n,o=t.row,i=void 0===o?null:o,l=t.toRow,f=void 0===l?null:l,p=t.col,d=void 0===p?0:p,y=t.toCol,v=void 0===y?null:y,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=u(O,["display","flexDirection","alignItems"]),P=t.id,C=t.children,S=u(t,["component","row","toRow","col","toCol","isCenter","isHorizontal","style","id","children"]),D=a.autoPosition({key:P||"".concat((new Date).getTime()),row:i,toRow:f}),k=Object.assign({display:j},h?{flexDirection:I||"row",alignItems:R||"center"}:{flexDirection:I||"column",alignItems:R||"stretch"},{justifyContent:g?"center":"space-between",gridRow:s(D,f),gridColumn:s(d,v)},x);return e.createElement(r,c({style:k},S),C)}; //# sourceMappingURL=foloForms.min.cjs.js.map