dinocollab-core 2.1.13 → 2.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{defineProperty as e,objectWithoutProperties as t,objectSpread2 as r,inherits as n,createClass as o,classCallCheck as i,callSuper as a}from"../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,jsxs as c}from"react/jsx-runtime";import{Component as p}from"react";import{styled as s,Stack as u,Tooltip as d,tooltipClasses as f,Typography as m,Divider as h,Box as v}from"@mui/material";import b from"@mui/icons-material/HelpOutline";var x=["className"],g=function(){function t(){var r;i(this,t);for(var n=arguments.length,o=new Array(n),p=0;p<n;p++)o[p]=arguments[p];return r=a(this,t,[].concat(o)),e(r,"renderTitlePanel",(function(){var e=r.props,t=e.panel,n=e.renderPanel;return n?n():t?c(w,{className:P.titlePanel,children:[r.renderTitle(null==t?void 0:t.title),l(h,{}),l(v,{className:P.content,children:r.renderContent(null==t?void 0:t.content)})]}):l(m,{variant:"body2",children:"Please provide a panel configuration"})})),e(r,"renderTitle",(function(e){return e?"string"!=typeof e?e:l(m,{variant:"subtitle1",className:P.title,children:e}):null})),e(r,"renderContent",(function(e){return e?"string"!=typeof e?e:l(m,{variant:"body2",children:e}):null})),r}return n(t,p),o(t,[{key:"render",value:function(){var e=this.props,t=e.children,n=e.slots;return l(T,r(r({arrow:!0,placement:"bottom",title:this.renderTitlePanel(),className:P.root},null==n?void 0:n.tooltipProps),{},{children:l(u,{children:t})}))}}])}(),P={root:"RichTooltip-root",titlePanel:"RichTooltip-titlePanel",title:"RichTooltip-title",content:"RichTooltip-content"},y=function(e,t){return"".concat((null==t?void 0:t.prefix)||"",".").concat(P[e]).concat((null==t?void 0:t.suffix)||"")},w=s(u)((function(t){var r=t.theme;return e(e(e({},y("titlePanel",{prefix:"&"}),{gap:"6px"}),y("title"),{color:r.palette.primary.main,fontWeight:700,padding:r.spacing(1,1.5,0)}),y("content"),{padding:r.spacing(1,1.5,1.5),color:r.palette.text.primary})})),T=s((function(e){var n=e.className,o=t(e,x);return l(d,r(r({},o),{},{classes:{popper:n}}))}))((function(t){var r=t.theme;return e(e({},"& .".concat(f.tooltip),{backgroundColor:"#fff",color:"#3c3c3c",padding:0,minWidth:"360px",maxWidth:"450px",borderRadius:r.shape.borderRadius,boxShadow:"rgba(0, 0, 0, 0.08) 0px 6px 30px"}),"& .".concat(f.arrow),{color:"#fff"})})),R=s(b)((function(e){return{position:"relative",zIndex:1,color:e.theme.palette.primary.main,animation:"pulseGlow 1.5s infinite",borderRadius:"50%",cursor:"help","@keyframes pulseGlow":{"0%":{boxShadow:"0 0 0 0 rgba(33,150,243, 0.3)"},"70%":{boxShadow:"0 0 0 10px rgba(33,150,243, 0)"},"100%":{boxShadow:"0 0 0 0 rgba(33,150,243, 0)"}}}}));export{R as HelpOutlinePulseIcon,g as RichTooltip,g as default};
1
+ import{defineProperty as e,objectWithoutProperties as t,objectSpread2 as r,inherits as n,createClass as o,classCallCheck as i,callSuper as a}from"../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,jsxs as c}from"react/jsx-runtime";import{Component as p}from"react";import{styled as s,Stack as u,Tooltip as d,tooltipClasses as f,Typography as m,Divider as h,Box as b}from"@mui/material";import x from"@mui/icons-material/HelpOutline";var v=["className"],g=function(){function t(){var r;i(this,t);for(var n=arguments.length,o=new Array(n),p=0;p<n;p++)o[p]=arguments[p];return r=a(this,t,[].concat(o)),e(r,"renderTitlePanel",(function(){var e=r.props,t=e.panel,n=e.renderPanel;return n?n():t?c(w,{className:P.titlePanel,children:[r.renderTitle(t.title),l(h,{}),l(b,{className:P.content,children:r.renderContent(t.content)})]}):l(m,{variant:"body2",children:"Please provide a panel configuration"})})),e(r,"renderTitle",(function(e){return e?"string"!=typeof e?e:l(m,{variant:"subtitle1",className:P.title,children:e}):null})),e(r,"renderContent",(function(e){return e?"string"!=typeof e?e:l(m,{variant:"body2",children:e}):null})),r}return n(t,p),o(t,[{key:"render",value:function(){var e=this.props,t=e.children,n=e.slots;return l(T,r(r({arrow:!0,placement:"bottom",title:this.renderTitlePanel(),className:P.root},null==n?void 0:n.tooltipProps),{},{children:l(u,{children:t})}))}}])}(),P={root:"RichTooltip-root",titlePanel:"RichTooltip-titlePanel",title:"RichTooltip-title",content:"RichTooltip-content"},y=function(e,t){return"".concat((null==t?void 0:t.prefix)||"",".").concat(P[e]).concat((null==t?void 0:t.suffix)||"")},w=s(u)((function(t){var r=t.theme;return e(e(e({},y("titlePanel",{prefix:"&"}),{gap:"6px"}),y("title"),{color:r.palette.primary.main,fontWeight:700,padding:r.spacing(1,1.5,0)}),y("content"),{padding:r.spacing(1,1.5,1.5),color:r.palette.text.primary})})),T=s((function(e){var n=e.className,o=t(e,v);return l(d,r(r({},o),{},{classes:{popper:n}}))}))((function(t){var r=t.theme;return e(e({},"& .".concat(f.tooltip),{backgroundColor:"#fff",color:"#3c3c3c",padding:0,minWidth:"360px",maxWidth:"450px",borderRadius:r.shape.borderRadius,boxShadow:"rgba(0, 0, 0, 0.08) 0px 6px 30px"}),"& .".concat(f.arrow),{color:"#fff"})})),R=s(x)((function(e){return{position:"relative",zIndex:1,color:e.theme.palette.primary.main,borderRadius:"50%",cursor:"help",animation:"pulseGlow 1.5s infinite","@keyframes pulseGlow":{"0%":{boxShadow:"0 0 0 0 rgba(33,150,243, 0.3)"},"70%":{boxShadow:"0 0 0 10px rgba(33,150,243, 0)"},"100%":{boxShadow:"0 0 0 0 rgba(33,150,243, 0)"}}}}));export{R as HelpOutlinePulseIcon,g as RichTooltip,g as default};
2
2
  //# sourceMappingURL=rich-tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rich-tooltip.js","sources":["../../src/components/rich-tooltip.tsx"],"sourcesContent":["import { Component } from 'react'\r\nimport { Box, Divider, Stack, Tooltip, Typography, styled, tooltipClasses } from '@mui/material'\r\nimport type { ReactNode } from 'react'\r\nimport type { TooltipProps } from '@mui/material'\r\nimport HelpOutlineIcon from '@mui/icons-material/HelpOutline'\r\n\r\nexport interface IRichTooltipPanelConfig {\r\n title: ReactNode\r\n content: ReactNode\r\n}\r\n\r\nexport interface IRichTooltipProps {\r\n panel?: IRichTooltipPanelConfig\r\n renderPanel?: () => ReactNode\r\n children: React.ReactNode\r\n slots?: {\r\n tooltipProps?: Partial<TooltipProps>\r\n }\r\n}\r\n\r\nexport class RichTooltip extends Component<IRichTooltipProps> {\r\n render() {\r\n const { children, slots } = this.props\r\n return (\r\n <TooltipStyled arrow placement='bottom' title={this.renderTitlePanel()} className={richTooltipClasses.root} {...slots?.tooltipProps}>\r\n <Stack>{children}</Stack>\r\n </TooltipStyled>\r\n )\r\n }\r\n\r\n renderTitlePanel = () => {\r\n const { panel: panel, renderPanel } = this.props\r\n if (renderPanel) return renderPanel()\r\n if (!panel) return <Typography variant='body2'>Please provide a panel configuration</Typography>\r\n return (\r\n <TooltipTitlePanelStyled className={richTooltipClasses.titlePanel}>\r\n {this.renderTitle(panel?.title)}\r\n <Divider />\r\n <Box className={richTooltipClasses.content}>{this.renderContent(panel?.content)}</Box>\r\n </TooltipTitlePanelStyled>\r\n )\r\n }\r\n\r\n renderTitle = (value: ReactNode) => {\r\n if (!value) return null\r\n if (typeof value !== 'string') return value\r\n return (\r\n <Typography variant='subtitle1' className={richTooltipClasses.title}>\r\n {value}\r\n </Typography>\r\n )\r\n }\r\n\r\n renderContent = (value: ReactNode) => {\r\n if (!value) return null\r\n if (typeof value !== 'string') return value\r\n return <Typography variant='body2'>{value}</Typography>\r\n }\r\n}\r\n\r\nexport default RichTooltip\r\n\r\nconst richTooltipClasses = {\r\n root: 'RichTooltip-root',\r\n titlePanel: 'RichTooltip-titlePanel',\r\n title: 'RichTooltip-title',\r\n content: 'RichTooltip-content'\r\n}\r\n\r\nconst getRichTooltipClass = (key: keyof typeof richTooltipClasses, options?: { prefix?: string; suffix?: string }) => {\r\n return `${options?.prefix || ''}.${richTooltipClasses[key]}${options?.suffix || ''}`\r\n}\r\n\r\nconst TooltipTitlePanelStyled = styled(Stack)(({ theme }) => ({\r\n [getRichTooltipClass('titlePanel', { prefix: '&' })]: {\r\n gap: '6px'\r\n },\r\n [getRichTooltipClass('title')]: {\r\n color: theme.palette.primary.main,\r\n fontWeight: 700,\r\n padding: theme.spacing(1, 1.5, 0)\r\n },\r\n [getRichTooltipClass('content')]: {\r\n padding: theme.spacing(1, 1.5, 1.5),\r\n color: theme.palette.text.primary\r\n }\r\n}))\r\n\r\nconst TooltipStyled = styled(({ className, ...props }: TooltipProps) => <Tooltip {...props} classes={{ popper: className }} />)(({ theme }) => ({\r\n [`& .${tooltipClasses.tooltip}`]: {\r\n backgroundColor: '#fff',\r\n color: '#3c3c3c',\r\n padding: 0,\r\n minWidth: '360px',\r\n maxWidth: '450px',\r\n borderRadius: theme.shape.borderRadius,\r\n boxShadow: 'rgba(0, 0, 0, 0.08) 0px 6px 30px'\r\n },\r\n [`& .${tooltipClasses.arrow}`]: {\r\n color: '#fff'\r\n }\r\n}))\r\n\r\nexport const HelpOutlinePulseIcon = styled(HelpOutlineIcon)(({ theme }) => ({\r\n position: 'relative',\r\n zIndex: 1,\r\n color: theme.palette.primary.main,\r\n animation: 'pulseGlow 1.5s infinite',\r\n borderRadius: '50%',\r\n cursor: 'help',\r\n '@keyframes pulseGlow': {\r\n '0%': {\r\n boxShadow: '0 0 0 0 rgba(33,150,243, 0.3)'\r\n },\r\n '70%': {\r\n boxShadow: '0 0 0 10px rgba(33,150,243, 0)'\r\n },\r\n '100%': {\r\n boxShadow: '0 0 0 0 rgba(33,150,243, 0)'\r\n }\r\n }\r\n}))\r\n"],"names":["RichTooltip","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","this","concat","_defineProperty","_this$props","props","panel","renderPanel","_jsxs","TooltipTitlePanelStyled","className","richTooltipClasses","titlePanel","renderTitle","title","_jsx","Divider","Box","content","children","renderContent","Typography","variant","value","_inherits","Component","_createClass","key","_this$props2","slots","TooltipStyled","_objectSpread","arrow","placement","renderTitlePanel","root","tooltipProps","Stack","getRichTooltipClass","options","prefix","suffix","styled","_ref","theme","gap","color","palette","primary","main","fontWeight","padding","spacing","text","_ref3","_objectWithoutProperties","_excluded","Tooltip","classes","popper","_ref4","tooltipClasses","tooltip","backgroundColor","minWidth","maxWidth","borderRadius","shape","boxShadow","HelpOutlinePulseIcon","HelpOutlineIcon","_ref6","position","zIndex","animation","cursor"],"mappings":"4cAoBaA,aAAY,SAAAA,IAAA,IAAAC,EAAAC,OAAAF,GAAA,IAAA,IAAAG,EAAAC,UAAAC,OAAAC,EAAAC,IAAAA,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAAF,EAAAE,GAAAJ,UAAAI,GAqCtB,OArCsBP,EAAAQ,EAAAC,KAAAV,EAAAW,GAAAA,OAAAL,IAAAM,EAAAX,EAAA,oBAUJ,WACjB,IAAAY,EAAsCZ,EAAKa,MAA5BC,EAAKF,EAAZE,MAAcC,EAAWH,EAAXG,YACtB,OAAIA,EAAoBA,IACnBD,EAEHE,EAACC,GAAwBC,UAAWC,EAAmBC,qBACpDpB,EAAKqB,YAAYP,aAAAA,EAAAA,EAAOQ,OACzBC,EAACC,MACDD,EAACE,EAAI,CAAAP,UAAWC,EAAmBO,QAAUC,SAAA3B,EAAK4B,cAAcd,aAAK,EAALA,EAAOY,cALxDH,EAACM,EAAU,CAACC,QAAQ,6DAQxCnB,EAAAX,EAEa,eAAA,SAAC+B,GACb,OAAKA,EACgB,iBAAVA,EAA2BA,EAEpCR,EAACM,EAAW,CAAAC,QAAQ,YAAYZ,UAAWC,EAAmBG,eAC3DS,IAJc,QAOpBpB,EAAAX,EAEe,iBAAA,SAAC+B,GACf,OAAKA,EACgB,iBAAVA,EAA2BA,EAC/BR,EAACM,EAAW,CAAAC,QAAQ,QAAOH,SAAEI,IAFjB,QAGpB/B,CAAA,CAAA,OAAAgC,EAAAjC,EArC8BkC,GAqC9BC,EAAAnC,EAAA,CAAA,CAAAoC,IAAA,SAAAJ,M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AiB,OACjBjB,MAAO,UACPK,QAAS,EACTa,SAAU,QACVC,SAAU,QACVC,aAActB,EAAMuB,MAAMD,aAC1BE,UAAW,2CACZlE,OACM2D,EAAe7B,OAAU,CAC9Bc,MAAO,QACR,IAGUuB,EAAuB3B,EAAO4B,EAAP5B,EAAwB,SAAA6B,GAAQ,MAAQ,CAC1EC,SAAU,WACVC,OAAQ,EACR3B,MAHkEyB,EAAL3B,MAGhDG,QAAQC,QAAQC,KAC7ByB,UAAW,0BACXR,aAAc,MACdS,OAAQ,OACR,uBAAwB,CACtB,KAAM,CACJP,UAAW,iCAEb,MAAO,CACLA,UAAW,kCAEb,OAAQ,CACNA,UAAW,gCAGhB"}
1
+ {"version":3,"file":"rich-tooltip.js","sources":["../../src/components/rich-tooltip.tsx"],"sourcesContent":["import { Component } from 'react'\r\nimport { Box, Divider, Stack, Tooltip, Typography, styled, tooltipClasses } from '@mui/material'\r\nimport type { ReactNode } from 'react'\r\nimport type { TooltipProps } from '@mui/material'\r\nimport HelpOutlineIcon from '@mui/icons-material/HelpOutline'\r\n\r\nexport interface IRichTooltipPanelConfig {\r\n title: ReactNode\r\n content: ReactNode\r\n}\r\n\r\nexport interface IRichTooltipProps {\r\n panel?: IRichTooltipPanelConfig\r\n renderPanel?: () => ReactNode\r\n children: React.ReactNode\r\n slots?: {\r\n tooltipProps?: Partial<TooltipProps>\r\n }\r\n}\r\n\r\nexport class RichTooltip extends Component<IRichTooltipProps> {\r\n render() {\r\n const { children, slots } = this.props\r\n return (\r\n <TooltipStyled arrow placement='bottom' title={this.renderTitlePanel()} className={richTooltipClasses.root} {...slots?.tooltipProps}>\r\n <Stack>{children}</Stack>\r\n </TooltipStyled>\r\n )\r\n }\r\n\r\n renderTitlePanel = () => {\r\n const { panel, renderPanel } = this.props\r\n if (renderPanel) return renderPanel()\r\n if (!panel) return <Typography variant='body2'>Please provide a panel configuration</Typography>\r\n return (\r\n <TooltipTitlePanelStyled className={richTooltipClasses.titlePanel}>\r\n {this.renderTitle(panel.title)}\r\n <Divider />\r\n <Box className={richTooltipClasses.content}>{this.renderContent(panel.content)}</Box>\r\n </TooltipTitlePanelStyled>\r\n )\r\n }\r\n\r\n renderTitle = (value: ReactNode) => {\r\n if (!value) return null\r\n if (typeof value !== 'string') return value\r\n return (\r\n <Typography variant='subtitle1' className={richTooltipClasses.title}>\r\n {value}\r\n </Typography>\r\n )\r\n }\r\n\r\n renderContent = (value: ReactNode) => {\r\n if (!value) return null\r\n if (typeof value !== 'string') return value\r\n return <Typography variant='body2'>{value}</Typography>\r\n }\r\n}\r\n\r\nexport default RichTooltip\r\n\r\nconst richTooltipClasses = {\r\n root: 'RichTooltip-root',\r\n titlePanel: 'RichTooltip-titlePanel',\r\n title: 'RichTooltip-title',\r\n content: 'RichTooltip-content'\r\n}\r\n\r\nconst getRichTooltipClass = (key: keyof typeof richTooltipClasses, options?: { prefix?: string; suffix?: string }) => {\r\n return `${options?.prefix || ''}.${richTooltipClasses[key]}${options?.suffix || ''}`\r\n}\r\n\r\nconst TooltipTitlePanelStyled = styled(Stack)(({ theme }) => ({\r\n [getRichTooltipClass('titlePanel', { prefix: '&' })]: {\r\n gap: '6px'\r\n },\r\n [getRichTooltipClass('title')]: {\r\n color: theme.palette.primary.main,\r\n fontWeight: 700,\r\n padding: theme.spacing(1, 1.5, 0)\r\n },\r\n [getRichTooltipClass('content')]: {\r\n padding: theme.spacing(1, 1.5, 1.5),\r\n color: theme.palette.text.primary\r\n }\r\n}))\r\n\r\nconst TooltipStyled = styled(({ className, ...props }: TooltipProps) => <Tooltip {...props} classes={{ popper: className }} />)(({ theme }) => ({\r\n [`& .${tooltipClasses.tooltip}`]: {\r\n backgroundColor: '#fff',\r\n color: '#3c3c3c',\r\n padding: 0,\r\n minWidth: '360px',\r\n maxWidth: '450px',\r\n borderRadius: theme.shape.borderRadius,\r\n boxShadow: 'rgba(0, 0, 0, 0.08) 0px 6px 30px'\r\n },\r\n [`& .${tooltipClasses.arrow}`]: {\r\n color: '#fff'\r\n }\r\n}))\r\n\r\nexport const HelpOutlinePulseIcon = styled(HelpOutlineIcon)(({ theme }) => ({\r\n position: 'relative',\r\n zIndex: 1,\r\n color: theme.palette.primary.main,\r\n borderRadius: '50%',\r\n cursor: 'help',\r\n animation: 'pulseGlow 1.5s infinite',\r\n '@keyframes pulseGlow': {\r\n '0%': {\r\n boxShadow: '0 0 0 0 rgba(33,150,243, 0.3)'\r\n },\r\n '70%': {\r\n boxShadow: '0 0 0 10px rgba(33,150,243, 0)'\r\n },\r\n '100%': {\r\n boxShadow: '0 0 0 0 rgba(33,150,243, 0)'\r\n }\r\n }\r\n}))\r\n"],"names":["RichTooltip","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","this","concat","_defineProperty","_this$props","props","panel","renderPanel","_jsxs","TooltipTitlePanelStyled","className","richTooltipClasses","titlePanel","renderTitle","title","_jsx","Divider","Box","content","children","renderContent","Typography","variant","value","_inherits","Component","_createClass","key","_this$props2","slots","TooltipStyled","_objectSpread","arrow","placement","renderTitlePanel","root","tooltipProps","Stack","getRichTooltipClass","options","prefix","suffix","styled","_ref","theme","gap","color","palette","primary","main","fontWeight","padding","spacing","text","_ref3","_objectWithoutProperties","_excluded","Tooltip","classes","popper","_ref4","tooltipClasses","tooltip","backgroundColor","minWidth","maxWidth","borderRadius","shape","boxShadow","HelpOutlinePulseIcon","HelpOutlineIcon","_ref6","position","zIndex","cursor","animation"],"mappings":"4cAoBaA,aAAY,SAAAA,IAAA,IAAAC,EAAAC,OAAAF,GAAA,IAAA,IAAAG,EAAAC,UAAAC,OAAAC,EAAAC,IAAAA,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAAF,EAAAE,GAAAJ,UAAAI,GAqCtB,OArCsBP,EAAAQ,EAAAC,KAAAV,EAAAW,GAAAA,OAAAL,IAAAM,EAAAX,EAAA,oBAUJ,WACjB,IAAAY,EAA+BZ,EAAKa,MAA5BC,EAAKF,EAALE,MAAOC,EAAWH,EAAXG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CAAAA,EAAAA,EAAoB,aAAc,CAAEE,OAAQ,MAAS,CACpDK,IAAK,QAENP,EAAoB,SAAW,CAC9BQ,MAAOF,EAAMG,QAAQC,QAAQC,KAC7BC,WAAY,IACZC,QAASP,EAAMQ,QAAQ,EAAG,IAAK,KAEhCd,EAAoB,WAAa,CAChCa,QAASP,EAAMQ,QAAQ,EAAG,IAAK,KAC/BN,MAAOF,EAAMG,QAAQM,KAAKL,SAC3B,IAGGlB,EAAgBY,GAAO,SAAAY,GAAA,IAAG5C,EAAS4C,EAAT5C,UAAcL,EAAKkD,EAAAD,EAAAE,GAAA,OAAqBzC,EAAC0C,EAAO1B,EAAAA,KAAK1B,GAAK,GAAA,CAAEqD,QAAS,CAAEC,OAAQjD,KAAe,GAAxGgC,EAA0G,SAAAkB,GAAA,IAAGhB,EAAKgB,EAALhB,MAAK,OAAAzC,EAAAA,EAAA,CAAA,EAAA,MAAAD,OAC/H2D,EAAeC,SAAY,CAChCC,gBAAiB,OACjBjB,MAAO,UACPK,QAAS,EACTa,SAAU,QACVC,SAAU,QACVC,aAActB,EAAMuB,MAAMD,aAC1BE,UAAW,2CACZlE,OACM2D,EAAe7B,OAAU,CAC9Bc,MAAO,QACR,IAGUuB,EAAuB3B,EAAO4B,EAAP5B,EAAwB,SAAA6B,GAAQ,MAAQ,CAC1EC,SAAU,WACVC,OAAQ,EACR3B,MAHkEyB,EAAL3B,MAGhDG,QAAQC,QAAQC,KAC7BiB,aAAc,MACdQ,OAAQ,OACRC,UAAW,0BACX,uBAAwB,CACtB,KAAM,CACJP,UAAW,iCAEb,MAAO,CACLA,UAAW,kCAEb,OAAQ,CACNA,UAAW,gCAGhB"}
@@ -1,2 +1,2 @@
1
- import{defineProperty as e,createClass as r,classCallCheck as i}from"../_virtual/_rollupPluginBabelHelpers.js";import{formatFileSize as u}from"../utils/helpers.js";import"../utils/dayjs-config.js";import"../utils/query-param.js";var t,n;!function(e){e.Required="Required",e.Regex="Regex",e.RequiredValue="RequiredValue",e.Array="Array",e.Number="Number",e.Email="Email",e.PhoneNumber="PhoneNumber",e.Url="Url",e.File="File",e.FileRequired="FileRequired",e.Custom="Custom"}(n||(n={}));var s={Required:"The {0} is required",Regex:"The {0} is not match {1}",RequiredValue:"the {0} is not equal {1}",Array:"The {0} is not valid",Number:"{0} must be a number",Email:"The {0} is not valid",PhoneNumber:"The {0} is not valid",Url:"The {0} is not valid",File:"File size must be less than {1}",FileRequired:"The {0} is required",Custom:"Error Custom"},a=function(e,r){return r},l=r((function r(t){var l=this;i(this,r),e(this,"AddRules",(function(e){var r,i=l.configs[e];i||(i={Rules:[]},l.configs[e]=i);for(var u=arguments.length,t=new Array(u>1?u-1:0),n=1;n<u;n++)t[n-1]=arguments[n];return(r=i.Rules).push.apply(r,t),l})),e(this,"Required",(function(e,r){return null==r||""===r})),e(this,"Regex",(function(e,r,i){return!!r&&!e.Value.test(r)})),e(this,"RequiredValue",(function(e,r){return!!r&&r!==e.Value})),e(this,"Custom",(function(e,r,i){return"function"!=typeof e.Value||e.Value(r,i)})),e(this,"Array",(function(e,r){return!!r&&("number"!=typeof e.Value||(!Array.isArray(r)||r.length<=e.Value))})),e(this,"Number",(function(e,r){return!!r&&isNaN(Number(r))})),e(this,"Email",(function(e,r){if(!r)return!1;return!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(r)})),e(this,"PhoneNumber",(function(e,r){if(!r)return!1;return!/^(\+?\d{1,4}[\s-]?)?((\(\d{1,4}\))|\d{1,4})[\s-]?\d{1,4}[\s-]?\d{1,9}$/.test((null!=r?r:"").trim())})),e(this,"Url",(function(e,r){if(!r)return!1;try{return new URL(r),!1}catch(e){return!0}})),e(this,"File",(function(e,r){if(!r)return!1;var i=a(0,e.options),u=Array.isArray(r)?r:[r];return!!i&&(!0===i.all?u.reduce((function(e,r){return e+=r.size}),0)>i.maxSize:u.some((function(e){return e.size>i.maxSize})))})),e(this,"FileRequired",(function(e,r){return!!(Array.isArray(r)?r:[r]).filter((function(e){return!!e})).some((function(e){return e.size<=0}))})),e(this,"RenderMessage",(function(e,r,i){if(!e.message)switch(e.message=s[e.rule].replace("{0}",null!=i?i:r),e.rule){case n.Regex:e.message=e.message.replace("{1}",e.Value.source);break;case n.RequiredValue:var t,l;e.message=e.message.replace("{1}",null!==(t=null===(l=e.Value)||void 0===l?void 0:l.toString())&&void 0!==t?t:"");break;case n.File:var o,c,f=a(0,e.options);if(!0===(null==f?void 0:f.all))e.message="Total file size must be less than ".concat(u((null!==(o=null==f?void 0:f.maxSize)&&void 0!==o?o:0)/1024));else e.message=e.message.replace("{1}",u((null!==(c=null==f?void 0:f.maxSize)&&void 0!==c?c:0)/1024))}return e.message=e.message.replace("{0}",r),e})),e(this,"run",(function(e){var r=Object.keys(l.configs),i={};return r.forEach((function(r){var u=l.configs[r];if(u){var t=l.Executed(u,e[r],e);t.length<1||(i[r]=t.map((function(e){return l.RenderMessage(e,r,u.label)})))}})),i})),e(this,"Executed",(function(e,r,i){return e.Rules.filter((function(e){var u=l[e.rule.toString()];return u&&u(e,r,i)}))})),this.configs=t}));t=l,e(l,"initial",(function(e){return new t(e)}));var o=function(){return new l({})};export{n as SingleRuleValidate,o as createFormValidator,l as default,a as mapRuleOptions};
1
+ import{defineProperty as e,createClass as r,classCallCheck as i}from"../_virtual/_rollupPluginBabelHelpers.js";import{formatFileSize as u}from"../utils/helpers.js";import"../utils/dayjs-config.js";import"../utils/query-param.js";var n,t;!function(e){e.Required="Required",e.Regex="Regex",e.RequiredValue="RequiredValue",e.Array="Array",e.Number="Number",e.Email="Email",e.PhoneNumber="PhoneNumber",e.Url="Url",e.File="File",e.FileRequired="FileRequired",e.Custom="Custom"}(t||(t={}));var s={Required:"The {0} is required",Regex:"The {0} is not match {1}",RequiredValue:"the {0} is not equal {1}",Array:"The {0} is not valid",Number:"{0} must be a number",Email:"The {0} is not valid",PhoneNumber:"The {0} is not valid",Url:"The {0} is not valid",File:"File size must be less than {1}",FileRequired:"The {0} is required",Custom:"Error Custom"},a=function(e,r){return r},l=r((function r(n){var l=this;i(this,r),e(this,"AddRules",(function(e){var r,i=l.configs[e];i||(i={Rules:[]},l.configs[e]=i);for(var u=arguments.length,n=new Array(u>1?u-1:0),t=1;t<u;t++)n[t-1]=arguments[t];return(r=i.Rules).push.apply(r,n),l})),e(this,"Required",(function(e,r){return null==r||""===r})),e(this,"Regex",(function(e,r,i){return!!r&&!e.Value.test(r)})),e(this,"RequiredValue",(function(e,r){return!!r&&r!==e.Value})),e(this,"Custom",(function(e,r,i){return"function"!=typeof e.Value||e.Value(r,i)})),e(this,"Array",(function(e,r){return!!r&&("number"!=typeof e.Value||(!Array.isArray(r)||r.length<=e.Value))})),e(this,"Number",(function(e,r){return!!r&&isNaN(Number(r))})),e(this,"Email",(function(e,r){if(!r)return!1;return!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(r)})),e(this,"PhoneNumber",(function(e,r){if(!r)return!1;return!/^(\+?\d{1,4}[\s-]?)?((\(\d{1,4}\))|\d{1,4})[\s-]?\d{1,4}[\s-]?\d{1,9}$/.test((null!=r?r:"").trim())})),e(this,"Url",(function(e,r){if(!r)return!1;try{return new URL(r),!1}catch(e){return!0}})),e(this,"File",(function(e,r){if(!r)return!1;var i=a(0,e.options),u=Array.isArray(r)?r:[r];return!!i&&(!0===i.all?u.reduce((function(e,r){return e+=r.size}),0)>i.maxSize:u.some((function(e){return e.size>i.maxSize})))})),e(this,"FileRequired",(function(e,r){return!!(Array.isArray(r)?r:[r]).filter((function(e){return!!e})).some((function(e){return e.size<=0}))})),e(this,"RenderMessage",(function(e,r,i,n){if(n)e.message=n;else if(!e.message)switch(e.message=s[e.rule].replace("{0}",null!=i?i:r),e.rule){case t.Regex:e.message=e.message.replace("{1}",e.Value.source);break;case t.RequiredValue:var l,o;e.message=e.message.replace("{1}",null!==(l=null===(o=e.Value)||void 0===o?void 0:o.toString())&&void 0!==l?l:"");break;case t.File:var c,f,m=a(0,e.options);if(!0===(null==m?void 0:m.all))e.message="Total file size must be less than ".concat(u((null!==(c=null==m?void 0:m.maxSize)&&void 0!==c?c:0)/1024));else e.message=e.message.replace("{1}",u((null!==(f=null==m?void 0:m.maxSize)&&void 0!==f?f:0)/1024))}return e.message=e.message.replace("{0}",r),e})),e(this,"run",(function(e){var r=Object.keys(l.configs),i={};return r.forEach((function(r){var u=l.configs[r];if(u){var n=l.Executed(u,e[r],e);n.length<1||(i[r]=n.map((function(e){return l.RenderMessage(e.rule,r,u.label,e.value)})))}})),i})),e(this,"Executed",(function(e,r,i){return e.Rules.map((function(e){var u=l[e.rule.toString()],n=u&&u(e,r,i);return{value:"boolean"==typeof n?void 0:n,rule:e}})).filter((function(e){return e.value}))})),this.configs=n}));n=l,e(l,"initial",(function(e){return new n(e)}));var o=function(){return new l({})};export{t as SingleRuleValidate,o as createFormValidator,l as default,a as mapRuleOptions};
2
2
  //# sourceMappingURL=validator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validator.js","sources":["../../src/form/validator.ts"],"sourcesContent":["import { formatFileSize } from '../utils'\r\n\r\nexport type IModelBase = { [key: string]: any }\r\n\r\nexport enum SingleRuleValidate {\r\n Required = 'Required',\r\n Regex = 'Regex',\r\n RequiredValue = 'RequiredValue',\r\n Array = 'Array',\r\n Number = 'Number',\r\n Email = 'Email',\r\n PhoneNumber = 'PhoneNumber',\r\n Url = 'Url',\r\n File = 'File',\r\n FileRequired = 'FileRequired',\r\n Custom = 'Custom'\r\n}\r\n\r\nconst MessageDefault = {\r\n Required: 'The {0} is required',\r\n Regex: 'The {0} is not match {1}',\r\n RequiredValue: 'the {0} is not equal {1}',\r\n Array: 'The {0} is not valid',\r\n Number: '{0} must be a number',\r\n Email: 'The {0} is not valid',\r\n PhoneNumber: 'The {0} is not valid',\r\n Url: 'The {0} is not valid',\r\n File: 'File size must be less than {1}',\r\n FileRequired: 'The {0} is required',\r\n Custom: 'Error Custom'\r\n}\r\n\r\nexport interface IRuleOptions {\r\n File: {\r\n maxSize: number\r\n // toal size of files\r\n all?: boolean\r\n }\r\n}\r\n\r\nexport const mapRuleOptions = <TK extends keyof IRuleOptions>(key: TK, options?: IRuleOptions[TK]) => options\r\n\r\nexport interface IRuleOption<TModel = any> {\r\n rule: SingleRuleValidate\r\n message?: string\r\n Value?: RegExp | ((value: any, model: TModel) => boolean) | number | Array<any> | boolean\r\n options?: any\r\n}\r\n\r\nexport interface IConfigValue<TModel = any> {\r\n Rules: IRuleOption<TModel>[]\r\n label?: string\r\n}\r\n\r\nexport interface IModelError {\r\n message: string\r\n error: boolean\r\n}\r\n\r\nexport type IFormValidatorConfig<TModel> = {\r\n [key in keyof Extract<TModel, IModelBase>]?: IConfigValue<TModel>\r\n}\r\n\r\nexport type IPartialError<TModel> = {\r\n [key in keyof TModel]?: IRuleOption<TModel>[]\r\n}\r\n\r\nexport default class FormValidator<TModel> {\r\n configs: IFormValidatorConfig<TModel>\r\n constructor(configs: IFormValidatorConfig<TModel>) {\r\n this.configs = configs\r\n }\r\n\r\n static initial = <T>(configs: IFormValidatorConfig<T>) => new FormValidator(configs)\r\n\r\n AddRules = (key: keyof TModel, ...rule: IRuleOption<TModel>[]) => {\r\n let fieldConfig = this.configs[key]\r\n if (!fieldConfig) {\r\n fieldConfig = { Rules: [] }\r\n this.configs[key] = fieldConfig\r\n }\r\n fieldConfig.Rules.push(...rule)\r\n return this\r\n }\r\n\r\n Required = (RuleOption: IRuleOption, value: any) => {\r\n return value === null || value === undefined || value === ''\r\n }\r\n Regex = (RuleOption: IRuleOption, value: string, Regex: RegExp) => {\r\n if (!value) return false\r\n return !(RuleOption.Value as RegExp).test(value)\r\n }\r\n RequiredValue = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n return value !== RuleOption.Value\r\n }\r\n Custom = (RuleOption: IRuleOption, value: any, model: any) => {\r\n if (typeof RuleOption.Value === 'function') {\r\n return RuleOption.Value(value, model)\r\n }\r\n return true\r\n }\r\n Array = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n if (typeof RuleOption.Value === 'number') {\r\n return Array.isArray(value) ? value.length <= RuleOption.Value : true\r\n }\r\n return true\r\n }\r\n Number = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n return isNaN(Number(value))\r\n }\r\n Email = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/\r\n return !regex.test(value)\r\n }\r\n PhoneNumber = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n const phoneRegex = /^(\\+?\\d{1,4}[\\s-]?)?((\\(\\d{1,4}\\))|\\d{1,4})[\\s-]?\\d{1,4}[\\s-]?\\d{1,9}$/\r\n return !phoneRegex.test((value ?? '').trim())\r\n }\r\n Url = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n try {\r\n new URL(value)\r\n return false\r\n } catch (err) {\r\n return true\r\n }\r\n }\r\n File = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n const options = mapRuleOptions('File', RuleOption.options)\r\n const files: File[] = Array.isArray(value) ? value : [value]\r\n if (!options) return false\r\n if (options.all === true) {\r\n const size = files.reduce((a, b) => {\r\n a += b.size\r\n return a\r\n }, 0)\r\n return size > options.maxSize\r\n } else {\r\n return files.some((x) => x.size > options.maxSize)\r\n }\r\n }\r\n FileRequired = (RuleOption: IRuleOption, value: any) => {\r\n const files: File[] = Array.isArray(value) ? value : [value]\r\n return !!files.filter((x) => !!x).some((x) => x.size <= 0)\r\n }\r\n RenderMessage = (RuleOption: IRuleOption, key: string, label?: string) => {\r\n if (!RuleOption.message) {\r\n RuleOption.message = MessageDefault[RuleOption.rule].replace('{0}', label ?? key)\r\n switch (RuleOption.rule) {\r\n case SingleRuleValidate.Regex: {\r\n RuleOption.message = RuleOption.message.replace('{1}', (RuleOption.Value as RegExp).source)\r\n break\r\n }\r\n case SingleRuleValidate.RequiredValue: {\r\n RuleOption.message = RuleOption.message.replace('{1}', RuleOption.Value?.toString() ?? '')\r\n break\r\n }\r\n case SingleRuleValidate.File: {\r\n const options = mapRuleOptions('File', RuleOption.options)\r\n if (options?.all === true) {\r\n RuleOption.message = `Total file size must be less than ${formatFileSize((options?.maxSize ?? 0) / 1024)}`\r\n } else {\r\n RuleOption.message = RuleOption.message.replace('{1}', formatFileSize((options?.maxSize ?? 0) / 1024))\r\n }\r\n break\r\n }\r\n default:\r\n break\r\n }\r\n }\r\n RuleOption.message = RuleOption.message.replace('{0}', key)\r\n return RuleOption\r\n }\r\n run = (model: TModel) => {\r\n const keys = Object.keys(this.configs)\r\n const data: IPartialError<TModel> = {}\r\n keys.forEach((key) => {\r\n const config = this.configs[key]\r\n if (!config) return\r\n const tmp = this.Executed(config, (model as any)[key], model)\r\n if (tmp.length < 1) return\r\n ;(data as any)[key] = tmp.map((x) => this.RenderMessage(x, key, config.label))\r\n })\r\n return data\r\n }\r\n Executed = (Config: IConfigValue, valueField: any, model: any) => {\r\n return Config.Rules.filter((Value) => {\r\n const action = (this as any)[Value.rule.toString()]\r\n return action && action(Value, valueField, model)\r\n })\r\n }\r\n}\r\n\r\nexport const createFormValidator = <TModel>() => {\r\n return new FormValidator<Partial<TModel>>({})\r\n}\r\n"],"names":["SingleRuleValidate","MessageDefault","Required","Regex","RequiredValue","Array","Number","Email","PhoneNumber","Url","File","FileRequired","Custom","mapRuleOptions","key","options","FormValidator","_createClass","configs","_this","this","_classCallCheck","_defineProperty","_fieldConfig$Rules","fieldConfig","Rules","_len","arguments","length","rule","_key","push","apply","RuleOption","value","Value","test","model","isArray","isNaN","trim","URL","err","files","all","reduce","a","b","size","maxSize","some","x","filter","label","message","replace","source","_RuleOption$Value$toS","_RuleOption$Value","toString","_options$maxSize","_options$maxSize2","concat","formatFileSize","keys","Object","data","forEach","config","tmp","Executed","map","RenderMessage","Config","valueField","action","_FormValidator","createFormValidator"],"mappings":"2OAIYA,GA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ACjB,GAC1B,IAAMwC,EAAUxD,EAAagB,EAAMN,KAAK8B,YACxC,OAAOgB,GAAUA,EAAOxC,EAAOuC,EAAYrC,EAC7C,OA7HAjB,KAAKF,QAAUA,CACjB,IAAC0D,EAJkB5D,EAAaM,EAAbN,EAMF,WAAA,SAAIE,GAAgC,OAAK,IAAIF,EAAcE,EAAQ,QA8HzE2D,EAAsB,WACjC,OAAO,IAAI7D,EAA+B,GAC5C"}
1
+ {"version":3,"file":"validator.js","sources":["../../src/form/validator.ts"],"sourcesContent":["import { formatFileSize } from '../utils'\r\n\r\nexport type IModelBase = { [key: string]: any }\r\n\r\nexport enum SingleRuleValidate {\r\n Required = 'Required',\r\n Regex = 'Regex',\r\n RequiredValue = 'RequiredValue',\r\n Array = 'Array',\r\n Number = 'Number',\r\n Email = 'Email',\r\n PhoneNumber = 'PhoneNumber',\r\n Url = 'Url',\r\n File = 'File',\r\n FileRequired = 'FileRequired',\r\n Custom = 'Custom'\r\n}\r\n\r\nconst MessageDefault = {\r\n Required: 'The {0} is required',\r\n Regex: 'The {0} is not match {1}',\r\n RequiredValue: 'the {0} is not equal {1}',\r\n Array: 'The {0} is not valid',\r\n Number: '{0} must be a number',\r\n Email: 'The {0} is not valid',\r\n PhoneNumber: 'The {0} is not valid',\r\n Url: 'The {0} is not valid',\r\n File: 'File size must be less than {1}',\r\n FileRequired: 'The {0} is required',\r\n Custom: 'Error Custom'\r\n}\r\n\r\nexport interface IRuleOptions {\r\n File: {\r\n maxSize: number\r\n // toal size of files\r\n all?: boolean\r\n }\r\n}\r\n\r\nexport const mapRuleOptions = <TK extends keyof IRuleOptions>(key: TK, options?: IRuleOptions[TK]) => options\r\n\r\nexport interface IRuleOption<TModel = any> {\r\n rule: SingleRuleValidate\r\n message?: string\r\n Value?: RegExp | ((value: any, model: TModel) => boolean | string) | number | Array<any> | boolean\r\n options?: any\r\n}\r\n\r\nexport interface IConfigValue<TModel = any> {\r\n Rules: IRuleOption<TModel>[]\r\n label?: string\r\n}\r\n\r\nexport interface IModelError {\r\n message: string\r\n error: boolean\r\n}\r\n\r\nexport type IFormValidatorConfig<TModel> = {\r\n [key in keyof Extract<TModel, IModelBase>]?: IConfigValue<TModel>\r\n}\r\n\r\nexport type IPartialError<TModel> = {\r\n [key in keyof TModel]?: IRuleOption<TModel>[]\r\n}\r\n\r\nexport default class FormValidator<TModel> {\r\n configs: IFormValidatorConfig<TModel>\r\n constructor(configs: IFormValidatorConfig<TModel>) {\r\n this.configs = configs\r\n }\r\n\r\n static initial = <T>(configs: IFormValidatorConfig<T>) => new FormValidator(configs)\r\n\r\n AddRules = (key: keyof TModel, ...rule: IRuleOption<TModel>[]) => {\r\n let fieldConfig = this.configs[key]\r\n if (!fieldConfig) {\r\n fieldConfig = { Rules: [] }\r\n this.configs[key] = fieldConfig\r\n }\r\n fieldConfig.Rules.push(...rule)\r\n return this\r\n }\r\n\r\n Required = (RuleOption: IRuleOption, value: any) => {\r\n return value === null || value === undefined || value === ''\r\n }\r\n Regex = (RuleOption: IRuleOption, value: string, Regex: RegExp) => {\r\n if (!value) return false\r\n return !(RuleOption.Value as RegExp).test(value)\r\n }\r\n RequiredValue = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n return value !== RuleOption.Value\r\n }\r\n Custom = (RuleOption: IRuleOption, value: any, model: any) => {\r\n if (typeof RuleOption.Value === 'function') {\r\n return RuleOption.Value(value, model)\r\n }\r\n return true\r\n }\r\n Array = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n if (typeof RuleOption.Value === 'number') {\r\n return Array.isArray(value) ? value.length <= RuleOption.Value : true\r\n }\r\n return true\r\n }\r\n Number = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n return isNaN(Number(value))\r\n }\r\n Email = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/\r\n return !regex.test(value)\r\n }\r\n PhoneNumber = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n const phoneRegex = /^(\\+?\\d{1,4}[\\s-]?)?((\\(\\d{1,4}\\))|\\d{1,4})[\\s-]?\\d{1,4}[\\s-]?\\d{1,9}$/\r\n return !phoneRegex.test((value ?? '').trim())\r\n }\r\n Url = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n try {\r\n new URL(value)\r\n return false\r\n } catch (err) {\r\n return true\r\n }\r\n }\r\n File = (RuleOption: IRuleOption, value: any) => {\r\n if (!value) return false\r\n const options = mapRuleOptions('File', RuleOption.options)\r\n const files: File[] = Array.isArray(value) ? value : [value]\r\n if (!options) return false\r\n if (options.all === true) {\r\n const size = files.reduce((a, b) => {\r\n a += b.size\r\n return a\r\n }, 0)\r\n return size > options.maxSize\r\n } else {\r\n return files.some((x) => x.size > options.maxSize)\r\n }\r\n }\r\n FileRequired = (RuleOption: IRuleOption, value: any) => {\r\n const files: File[] = Array.isArray(value) ? value : [value]\r\n return !!files.filter((x) => !!x).some((x) => x.size <= 0)\r\n }\r\n RenderMessage = (RuleOption: IRuleOption, key: string, label?: string, message?: string) => {\r\n if (message) {\r\n RuleOption.message = message\r\n } else if (!RuleOption.message) {\r\n RuleOption.message = MessageDefault[RuleOption.rule].replace('{0}', label ?? key)\r\n switch (RuleOption.rule) {\r\n case SingleRuleValidate.Regex: {\r\n RuleOption.message = RuleOption.message.replace('{1}', (RuleOption.Value as RegExp).source)\r\n break\r\n }\r\n case SingleRuleValidate.RequiredValue: {\r\n RuleOption.message = RuleOption.message.replace('{1}', RuleOption.Value?.toString() ?? '')\r\n break\r\n }\r\n case SingleRuleValidate.File: {\r\n const options = mapRuleOptions('File', RuleOption.options)\r\n if (options?.all === true) {\r\n RuleOption.message = `Total file size must be less than ${formatFileSize((options?.maxSize ?? 0) / 1024)}`\r\n } else {\r\n RuleOption.message = RuleOption.message.replace('{1}', formatFileSize((options?.maxSize ?? 0) / 1024))\r\n }\r\n break\r\n }\r\n default:\r\n break\r\n }\r\n }\r\n RuleOption.message = RuleOption.message.replace('{0}', key)\r\n return RuleOption\r\n }\r\n run = (model: TModel) => {\r\n const keys = Object.keys(this.configs)\r\n const data: IPartialError<TModel> = {}\r\n keys.forEach((key) => {\r\n const config = this.configs[key]\r\n if (!config) return\r\n const tmp = this.Executed(config, (model as any)[key], model)\r\n if (tmp.length < 1) return\r\n ;(data as any)[key] = tmp.map((x) => this.RenderMessage(x.rule, key, config.label, x.value))\r\n })\r\n return data\r\n }\r\n Executed = (Config: IConfigValue, valueField: any, model: any) => {\r\n return Config.Rules.map((Value) => {\r\n const action = (this as any)[Value.rule.toString()]\r\n const res = action && action(Value, valueField, model)\r\n return { value: typeof res === 'boolean' ? undefined : (res as string), rule: Value }\r\n }).filter((x) => x.value)\r\n }\r\n}\r\n\r\nexport const createFormValidator = <TModel>() => {\r\n return new FormValidator<Partial<TModel>>({})\r\n}\r\n"],"names":["SingleRuleValidate","MessageDefault","Required","Regex","RequiredValue","Array","Number","Email","PhoneNumber","Url","File","FileRequired","Custom","mapRuleOptions","key","options","FormValidator","_createClass","configs","_this","this","_classCallCheck","_defineProperty","_fieldConfig$Rules","fieldConfig","Rules","_len","arguments","length","rule","_key","push","apply","RuleOption","value","Value","test","model","isArray","isNaN","trim","URL","err","files","all","reduce","a","b","size","maxSize","some","x","filter","label","message","replace","source","_RuleOption$Value$toS","_RuleOption$Value","toString","_options$maxSize","_options$maxSize2","concat","formatFileSize","keys","Object","data","forEach","config","tmp","Executed","map","RenderMessage","Config","valueField","action","res","undefined","_FormValidator","createFormValidator"],"mappings":"2OAIYA,GAAZ,SAAYA,GACVA,EAAA,SAAA,WACAA,EAAA,MAAA,QACAA,EAAA,cAAA,gBACAA,EAAA,MAAA,QACAA,EAAA,OAAA,SACAA,EAAA,MAAA,QACAA,EAAA,YAAA,cACAA,EAAA,IAAA,MACAA,EAAA,KAAA,OACAA,EAAA,aAAA,eACAA,EAAA,OAAA,QACD,CAZD,CAAYA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aD,EAAgB/C,KAAMM,EAChF,IAAGiB,QAAO,SAACD,GAAC,OAAKA,EAAEjB,YAhInBd,KAAKF,QAAUA,CACjB,IAAC4D,EAJkB9D,EAAaM,EAAbN,EAMF,WAAA,SAAIE,GAAgC,OAAK,IAAIF,EAAcE,EAAQ,QAiIzE6D,EAAsB,WACjC,OAAO,IAAI/D,EAA+B,GAC5C"}
@@ -1,2 +1,2 @@
1
- import{objectSpread2 as r,inherits as t,createClass as e,classCallCheck as o,callSuper as i,defineProperty as n}from"../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,jsxs as a,Fragment as s}from"react/jsx-runtime";import{Component as p}from"react";import{styled as u,Typography as d,Box as c,Tooltip as f,Button as m}from"@mui/material";import v from"@mui/icons-material/AddCircleOutline";import{Breadcrumbs as h}from"../components/breadcrumbs.js";import{mapGlobalModalContext as b}from"../api-context/global-modal.js";var C=function(){function u(){var t;o(this,u);for(var e=arguments.length,a=new Array(e),p=0;p<e;p++)a[p]=arguments[p];return t=i(this,u,[].concat(a)),n(t,"renderButtonCreate",(function(){return t.props.formCreate?b((function(e){var o;return l(f,{title:"Create new",children:l(m,r(r({size:"small",onClick:function(){return e.show({renderContent:function(){return t.props.formCreate}})},startIcon:l(v,{fontSize:"small"}),sx:{fontWeight:600},variant:"contained"},null===(o=t.props.slots)||void 0===o?void 0:o.buttonCreateProps),{},{children:"Create"}))})})):l(s,{})})),n(t,"renderTitle",(function(){var r,e=null!==(r=t.props)&&void 0!==r?r:{},o=e.title,i=e.breadcrumbs;return i?l(h,{value:i}):l("string"==typeof o?g:s,{children:o})})),t}return t(u,p),e(u,[{key:"render",value:function(){var t,e,o,i,n;if(!1!==this.props.visible)return a(x,r(r({},null===(t=this.props.slots)||void 0===t?void 0:t.rootProps),{},{children:[null===(e=this.props.titleSlots)||void 0===e?void 0:e.before,this.renderTitle(),null===(o=this.props.titleSlots)||void 0===o?void 0:o.after,l(c,{sx:{flex:1}}),null===(i=this.props.actionSlots)||void 0===i?void 0:i.before,this.renderButtonCreate(),null===(n=this.props.actionSlots)||void 0===n?void 0:n.after]}))}}])}(),g=u((function(t){return l(d,r({noWrap:!0,variant:"subtitle1"},t))}))({fontWeight:700,flex:1}),x=u(c)({height:"var(--height-toolbar, 56px)",display:"flex",alignItems:"center",gap:"8px",padding:"0 6px"});export{C as default};
1
+ import{objectSpread2 as t,defineProperty as r,inherits as e,createClass as o,classCallCheck as i,callSuper as n}from"../_virtual/_rollupPluginBabelHelpers.js";import{jsx as a,jsxs as l,Fragment as s}from"react/jsx-runtime";import{Component as p}from"react";import{styled as u,Typography as d,Box as f,Tooltip as c,Button as m}from"@mui/material";import h from"@mui/icons-material/AddCircleOutline";import{Breadcrumbs as v}from"../components/breadcrumbs.js";import{mapGlobalModalContext as x}from"../api-context/global-modal.js";var b=function(){function u(){var e;i(this,u);for(var o=arguments.length,l=new Array(o),p=0;p<o;p++)l[p]=arguments[p];return e=n(this,u,[].concat(l)),r(e,"renderButtonCreate",(function(){return e.props.formCreate?x((function(r){var o;return a(c,{title:"Create new",children:a(m,t(t({size:"small",onClick:function(){return r.show({renderContent:function(){return e.props.formCreate}})},startIcon:a(h,{fontSize:"small"}),sx:{fontWeight:600},variant:"contained"},null===(o=e.props.slots)||void 0===o?void 0:o.buttonCreateProps),{},{children:"Create"}))})})):a(s,{})})),r(e,"renderTitle",(function(){var t,r=null!==(t=e.props)&&void 0!==t?t:{},o=r.title,i=r.breadcrumbs;return i?a(v,{value:i}):a("string"==typeof o?g:s,{children:o})})),e}return e(u,p),o(u,[{key:"render",value:function(){var r,e,o,i,n;if(!1!==this.props.visible)return l(C,t(t({},null===(r=this.props.slots)||void 0===r?void 0:r.rootProps),{},{children:[null===(e=this.props.titleSlots)||void 0===e?void 0:e.before,this.renderTitle(),null===(o=this.props.titleSlots)||void 0===o?void 0:o.after,a(f,{sx:{flex:{xs:"0 0 auto",md:1},width:{xs:"100%",md:"auto"}}}),null===(i=this.props.actionSlots)||void 0===i?void 0:i.before,this.renderButtonCreate(),null===(n=this.props.actionSlots)||void 0===n?void 0:n.after]}))}}])}(),g=u((function(r){return a(d,t({noWrap:!0,variant:"subtitle1"},r))}))({fontWeight:700,flex:1}),C=u(f)((function(t){var e=t.theme;return r({height:"var(--height-toolbar, 56px)",display:"flex",alignItems:"center",gap:"8px",padding:"0 6px",flexWrap:"wrap"},e.breakpoints.down("sm"),{height:"auto",padding:"12px 0",alignItems:"flex-start"})}));export{b as default};
2
2
  //# sourceMappingURL=toolbar-pannel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toolbar-pannel.js","sources":["../../src/table-grid/toolbar-pannel.tsx"],"sourcesContent":["import React, { Component } from 'react'\r\nimport { Box, BoxProps, Button, ButtonProps, styled, Tooltip, Typography, TypographyProps } from '@mui/material'\r\nimport AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'\r\nimport { mapGlobalModalContext } from '../api-context'\r\nimport { Breadcrumbs, IBreadcrumbConfig } from '../components'\r\n\r\nexport interface ISectionSlots {\r\n before?: React.ReactNode\r\n after?: React.ReactNode\r\n}\r\n\r\nexport interface IToolbarPannelProps {\r\n /** @default true */\r\n visible?: boolean\r\n searchInclude?: string[]\r\n breadcrumbs?: IBreadcrumbConfig[]\r\n title?: React.ReactNode\r\n titleSlots?: ISectionSlots\r\n formCreate?: React.ReactNode\r\n actionSlots?: ISectionSlots\r\n slots?: {\r\n rootProps?: BoxProps\r\n buttonCreateProps?: ButtonProps\r\n }\r\n}\r\n\r\nclass ToolbarPannel extends Component<IToolbarPannelProps> {\r\n render() {\r\n if (this.props.visible === false) return\r\n return (\r\n <Wrap {...this.props.slots?.rootProps}>\r\n {this.props.titleSlots?.before}\r\n {this.renderTitle()}\r\n {this.props.titleSlots?.after}\r\n <Box sx={{ flex: 1 }} />\r\n {this.props.actionSlots?.before}\r\n {this.renderButtonCreate()}\r\n {this.props.actionSlots?.after}\r\n </Wrap>\r\n )\r\n }\r\n\r\n renderButtonCreate = () => {\r\n if (!this.props.formCreate) return <></>\r\n return mapGlobalModalContext((context) => (\r\n <Tooltip title='Create new'>\r\n <Button\r\n size='small'\r\n onClick={() => context.show({ renderContent: () => this.props.formCreate })}\r\n startIcon={<AddCircleOutlineIcon fontSize='small' />}\r\n sx={{ fontWeight: 600 }}\r\n variant='contained'\r\n {...this.props.slots?.buttonCreateProps}\r\n >\r\n Create\r\n </Button>\r\n </Tooltip>\r\n ))\r\n }\r\n\r\n renderTitle = () => {\r\n const { title, breadcrumbs } = this.props ?? {}\r\n if (breadcrumbs) return <Breadcrumbs value={breadcrumbs} />\r\n if (typeof title === 'string') return <Title>{title}</Title>\r\n return <>{title}</>\r\n }\r\n}\r\n\r\nexport default ToolbarPannel\r\n\r\n// const SearchHelp = styled('ul')({\r\n// margin: '0 0 0 18px',\r\n// padding: 0,\r\n// li: {\r\n// position: 'relative'\r\n// },\r\n// 'li::after': {\r\n// content: '\"►\"',\r\n// display: 'inline-block',\r\n// top: '50%',\r\n// transform: 'translateY(-50%)',\r\n// position: 'absolute',\r\n// left: '-18px'\r\n// }\r\n// })\r\n\r\nconst Title = styled((props: TypographyProps) => <Typography noWrap variant='subtitle1' {...props} />)({\r\n fontWeight: 700,\r\n flex: 1\r\n})\r\n\r\nconst Wrap = styled(Box)({\r\n height: 'var(--height-toolbar, 56px)',\r\n display: 'flex',\r\n alignItems: 'center',\r\n gap: '8px',\r\n padding: '0 6px'\r\n})\r\n"],"names":["ToolbarPannel","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","this","concat","_defineProperty","props","formCreate","mapGlobalModalContext","context","_this$props$slots","_jsx","Tooltip","title","children","Button","_objectSpread","size","onClick","show","renderContent","startIcon","AddCircleOutlineIcon","fontSize","sx","fontWeight","variant","slots","buttonCreateProps","_this$props","_ref","breadcrumbs","Breadcrumbs","value","Title","_Fragment","_inherits","Component","_createClass","key","_this$props$slots2","_this$props$titleSlot","_this$props$titleSlot2","_this$props$actionSlo","_this$props$actionSlo2","visible","_jsxs","Wrap","rootProps","titleSlots","before","renderTitle","after","Box","flex","actionSlots","renderButtonCreate","styled","Typography","noWrap","height","display","alignItems","gap","padding"],"mappings":"ghBA0BMA,IAAAA,aAAc,SAAAA,IAAA,IAAAC,EAAAC,OAAAF,GAAA,IAAA,IAAAG,EAAAC,UAAAC,OAAAC,EAAAC,IAAAA,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAAF,EAAAE,GAAAJ,UAAAI,GAuCjB,OAvCiBP,EAAAQ,EAAAC,KAAAV,EAAAW,GAAAA,OAAAL,IAAAM,EAAAX,EAAA,sBAgBG,WACnB,OAAKA,EAAKY,MAAMC,WACTC,GAAsB,SAACC,GAAO,IAAAC,EAAA,OACnCC,EAACC,GAAQC,MAAM,aAAYC,SACzBH,EAACI,EAAMC,EAAAA,EAAA,CACLC,KAAK,QACLC,QAAS,WAAF,OAAQT,EAAQU,KAAK,CAAEC,cAAe,WAAF,OAAQ1B,EAAKY,MAAMC,UAAU,GAAG,EAC3Ec,UAAWV,EAACW,EAAqB,CAAAC,SAAS,UAC1CC,GAAI,CAAEC,WAAY,KAClBC,QAAQ,aACY,QADDhB,EACfhB,EAAKY,MAAMqB,aAAK,IAAAjB,OAAA,EAAhBA,EAAkBkB,mBAAiB,CAAA,EAAA,uBAIjC,IAbuBjB,WAepCN,EAAAX,EAAA,eAEa,WAAK,IAAAmC,EACjBC,EAAyC,QAAzCD,EAA+BnC,EAAKY,aAAK,IAAAuB,EAAAA,EAAI,CAAE,EAAvChB,EAAKiB,EAALjB,MAAOkB,EAAWD,EAAXC,YACf,OAAIA,EAAoBpB,EAACqB,EAAW,CAACC,MAAOF,IACNpB,EAAjB,iBAAVE,EAA4BqB,EAChCC,EADuC,CAAArB,SAAAD,OAE/CnB,CAAA,CAAA,OAAA0C,EAAA3C,EAvCyB4C,GAuCzBC,EAAA7C,EAAA,CAAA,CAAA8C,IAAA,SAAAN,MAtCD,WAAM,IAAAO,EAAAC,EAAAC,EAAAC,EAAAC,EACJ,IAA2B,IAAvBzC,KAAKG,MAAMuC,QACf,OACEC,EAACC,EAAI/B,EAAAA,KAAqB,QAArBwB,EAAKrC,KAAKG,MAAMqB,aAAXa,IAAgBA,OAAhBA,EAAAA,EAAkBQ,WAAS,GAAA,CAAAlC,SAAA,CACb,QADa2B,EAClCtC,KAAKG,MAAM2C,kBAAXR,IAAqBA,OAArBA,EAAAA,EAAuBS,OACvB/C,KAAKgD,cACgB,QADHT,EAClBvC,KAAKG,MAAM2C,kBAAU,IAAAP,OAAA,EAArBA,EAAuBU,MACxBzC,EAAC0C,EAAI,CAAA7B,GAAI,CAAE8B,KAAM,aAAOX,EACvBxC,KAAKG,MAAMiD,mBAAW,IAAAZ,OAAA,EAAtBA,EAAwBO,OACxB/C,KAAKqD,qBACiBZ,QADGA,EACzBzC,KAAKG,MAAMiD,mBAAXX,IAAsBA,OAAtBA,EAAAA,EAAwBQ,SAG/B,IAAC,IA8CGlB,EAAQuB,GAAO,SAACnD,GAAsB,OAAKK,EAAC+C,EAAU1C,EAAA,CAAC2C,UAAOjC,QAAQ,aAAgBpB,GAAS,GAAvFmD,CAAyF,CACrGhC,WAAY,IACZ6B,KAAM,IAGFP,EAAOU,EAAOJ,EAAPI,CAAY,CACvBG,OAAQ,8BACRC,QAAS,OACTC,WAAY,SACZC,IAAK,MACLC,QAAS"}
1
+ {"version":3,"file":"toolbar-pannel.js","sources":["../../src/table-grid/toolbar-pannel.tsx"],"sourcesContent":["import React, { Component } from 'react'\r\nimport { Box, BoxProps, Button, ButtonProps, styled, Tooltip, Typography, TypographyProps } from '@mui/material'\r\nimport AddCircleOutlineIcon from '@mui/icons-material/AddCircleOutline'\r\nimport { mapGlobalModalContext } from '../api-context'\r\nimport { Breadcrumbs, IBreadcrumbConfig } from '../components'\r\n\r\nexport interface ISectionSlots {\r\n before?: React.ReactNode\r\n after?: React.ReactNode\r\n}\r\n\r\nexport interface IToolbarPannelProps {\r\n /** @default true */\r\n visible?: boolean\r\n searchInclude?: string[]\r\n breadcrumbs?: IBreadcrumbConfig[]\r\n title?: React.ReactNode\r\n titleSlots?: ISectionSlots\r\n formCreate?: React.ReactNode\r\n actionSlots?: ISectionSlots\r\n slots?: {\r\n rootProps?: BoxProps\r\n buttonCreateProps?: ButtonProps\r\n }\r\n}\r\n\r\nclass ToolbarPannel extends Component<IToolbarPannelProps> {\r\n render() {\r\n if (this.props.visible === false) return\r\n return (\r\n <Wrap {...this.props.slots?.rootProps}>\r\n {this.props.titleSlots?.before}\r\n {this.renderTitle()}\r\n {this.props.titleSlots?.after}\r\n <Box sx={{ flex: { xs: '0 0 auto', md: 1 }, width: { xs: '100%', md: 'auto' } }} />\r\n {this.props.actionSlots?.before}\r\n {this.renderButtonCreate()}\r\n {this.props.actionSlots?.after}\r\n </Wrap>\r\n )\r\n }\r\n\r\n renderButtonCreate = () => {\r\n if (!this.props.formCreate) return <></>\r\n return mapGlobalModalContext((context) => (\r\n <Tooltip title='Create new'>\r\n <Button\r\n size='small'\r\n onClick={() => context.show({ renderContent: () => this.props.formCreate })}\r\n startIcon={<AddCircleOutlineIcon fontSize='small' />}\r\n sx={{ fontWeight: 600 }}\r\n variant='contained'\r\n {...this.props.slots?.buttonCreateProps}\r\n >\r\n Create\r\n </Button>\r\n </Tooltip>\r\n ))\r\n }\r\n\r\n renderTitle = () => {\r\n const { title, breadcrumbs } = this.props ?? {}\r\n if (breadcrumbs) return <Breadcrumbs value={breadcrumbs} />\r\n if (typeof title === 'string') return <Title>{title}</Title>\r\n return <>{title}</>\r\n }\r\n}\r\n\r\nexport default ToolbarPannel\r\n\r\n// const SearchHelp = styled('ul')({\r\n// margin: '0 0 0 18px',\r\n// padding: 0,\r\n// li: {\r\n// position: 'relative'\r\n// },\r\n// 'li::after': {\r\n// content: '\"►\"',\r\n// display: 'inline-block',\r\n// top: '50%',\r\n// transform: 'translateY(-50%)',\r\n// position: 'absolute',\r\n// left: '-18px'\r\n// }\r\n// })\r\n\r\nconst Title = styled((props: TypographyProps) => <Typography noWrap variant='subtitle1' {...props} />)({\r\n fontWeight: 700,\r\n flex: 1\r\n})\r\n\r\nconst Wrap = styled(Box)(({ theme }) => ({\r\n height: 'var(--height-toolbar, 56px)',\r\n display: 'flex',\r\n alignItems: 'center',\r\n gap: '8px',\r\n padding: '0 6px',\r\n flexWrap: 'wrap',\r\n [theme.breakpoints.down('sm')]: {\r\n height: 'auto',\r\n padding: '12px 0',\r\n alignItems: 'flex-start'\r\n }\r\n}))\r\n"],"names":["ToolbarPannel","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","this","concat","_defineProperty","props","formCreate","mapGlobalModalContext","context","_this$props$slots","_jsx","Tooltip","title","children","Button","_objectSpread","size","onClick","show","renderContent","startIcon","AddCircleOutlineIcon","fontSize","sx","fontWeight","variant","slots","buttonCreateProps","_this$props","_ref","breadcrumbs","Breadcrumbs","value","Title","_Fragment","_inherits","Component","_createClass","key","_this$props$slots2","_this$props$titleSlot","_this$props$titleSlot2","_this$props$actionSlo","_this$props$actionSlo2","visible","_jsxs","Wrap","rootProps","titleSlots","before","renderTitle","after","Box","flex","xs","md","width","actionSlots","renderButtonCreate","styled","Typography","noWrap","_ref2","theme","height","display","alignItems","gap","padding","flexWrap","breakpoints","down"],"mappings":"ghBA0BMA,IAAAA,aAAc,SAAAA,IAAA,IAAAC,EAAAC,OAAAF,GAAA,IAAA,IAAAG,EAAAC,UAAAC,OAAAC,EAAAC,IAAAA,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAAF,EAAAE,GAAAJ,UAAAI,GAuCjB,OAvCiBP,EAAAQ,EAAAC,KAAAV,EAAAW,GAAAA,OAAAL,IAAAM,EAAAX,EAAA,sBAgBG,WACnB,OAAKA,EAAKY,MAAMC,WACTC,GAAsB,SAACC,GAAO,IAAAC,EAAA,OACnCC,EAACC,GAAQC,MAAM,aAAYC,SACzBH,EAACI,EAAMC,EAAAA,EAAA,CACLC,KAAK,QACLC,QAAS,WAAF,OAAQT,EAAQU,KAAK,CAAEC,cAA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d,IAAsBA,OAAtBA,EAAAA,EAAwBQ,SAG/B,IAAC,IA8CGlB,EAAQ0B,GAAO,SAACtD,GAAsB,OAAKK,EAACkD,EAAU7C,EAAA,CAAC8C,UAAOpC,QAAQ,aAAgBpB,GAAS,GAAvFsD,CAAyF,CACrGnC,WAAY,IACZ6B,KAAM,IAGFP,EAAOa,EAAOP,EAAPO,EAAY,SAAAG,GAAA,IAAGC,EAAKD,EAALC,MAAK,OAAA3D,EAAA,CAC/B4D,OAAQ,8BACRC,QAAS,OACTC,WAAY,SACZC,IAAK,MACLC,QAAS,QACTC,SAAU,QACTN,EAAMO,YAAYC,KAAK,MAAQ,CAC9BP,OAAQ,OACRI,QAAS,SACTF,WAAY,cACb"}
@@ -24,7 +24,7 @@ export declare const mapRuleOptions: <TK extends "File">(key: TK, options?: IRul
24
24
  export interface IRuleOption<TModel = any> {
25
25
  rule: SingleRuleValidate;
26
26
  message?: string;
27
- Value?: RegExp | ((value: any, model: TModel) => boolean) | number | Array<any> | boolean;
27
+ Value?: RegExp | ((value: any, model: TModel) => boolean | string) | number | Array<any> | boolean;
28
28
  options?: any;
29
29
  }
30
30
  export interface IConfigValue<TModel = any> {
@@ -49,7 +49,7 @@ export default class FormValidator<TModel> {
49
49
  Required: (RuleOption: IRuleOption, value: any) => boolean;
50
50
  Regex: (RuleOption: IRuleOption, value: string, Regex: RegExp) => boolean;
51
51
  RequiredValue: (RuleOption: IRuleOption, value: any) => boolean;
52
- Custom: (RuleOption: IRuleOption, value: any, model: any) => boolean;
52
+ Custom: (RuleOption: IRuleOption, value: any, model: any) => string | boolean;
53
53
  Array: (RuleOption: IRuleOption, value: any) => boolean;
54
54
  Number: (RuleOption: IRuleOption, value: any) => boolean;
55
55
  Email: (RuleOption: IRuleOption, value: any) => boolean;
@@ -57,8 +57,11 @@ export default class FormValidator<TModel> {
57
57
  Url: (RuleOption: IRuleOption, value: any) => boolean;
58
58
  File: (RuleOption: IRuleOption, value: any) => boolean;
59
59
  FileRequired: (RuleOption: IRuleOption, value: any) => boolean;
60
- RenderMessage: (RuleOption: IRuleOption, key: string, label?: string) => IRuleOption<any>;
60
+ RenderMessage: (RuleOption: IRuleOption, key: string, label?: string, message?: string) => IRuleOption<any>;
61
61
  run: (model: TModel) => IPartialError<TModel>;
62
- Executed: (Config: IConfigValue, valueField: any, model: any) => IRuleOption<any>[];
62
+ Executed: (Config: IConfigValue, valueField: any, model: any) => {
63
+ value: string | undefined;
64
+ rule: IRuleOption<any>;
65
+ }[];
63
66
  }
64
67
  export declare const createFormValidator: <TModel>() => FormValidator<Partial<TModel>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinocollab-core",
3
- "version": "2.1.13",
3
+ "version": "2.1.15",
4
4
  "description": "Dinocollab core - libraries for building collaborative applications with React 18",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",