dinocollab-core 2.1.33 → 2.1.34
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.
- package/dist/src/api-context/global-modal.js +1 -1
- package/dist/src/api-context/global-modal.js.map +1 -1
- package/dist/src/components/rich-tooltip.js +1 -1
- package/dist/src/components/rich-tooltip.js.map +1 -1
- package/dist/src/form/decorator.form.js +1 -1
- package/dist/src/form/decorator.form.js.map +1 -1
- package/dist/src/form/decorator.js.map +1 -1
- package/dist/types/components/rich-tooltip.d.ts +2 -1
- package/dist/types/form/decorator.d.ts +2 -0
- package/dist/types/form/decorator.form.d.ts +10 -3
- package/dist/types/form/dino-form.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{inherits as t,createClass as e,classCallCheck as n,callSuper as
|
|
1
|
+
import{inherits as t,createClass as e,classCallCheck as n,callSuper as r,defineProperty as o,objectSpread2 as s}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as a,jsxs as i,Fragment as l}from"react/jsx-runtime";import c,{Component as u}from"react";import{styled as d,Box as f,Modal as p,Backdrop as h}from"@mui/material";var C=c.createContext({close:function(){console.warn("GlobalModal provider not found!")},show:function(){console.warn("GlobalModal provider not found!")}}),m=function(t){return a(C.Consumer,{children:t})},b=function(){function s(t){var e;return n(this,s),e=r(this,s,[t]),o(e,"show",function(t){e.setState(t)}),o(e,"close",function(t,n){"backdropClick"===n&&!1===e.state.backdropActivated||(e.state.onClose&&e.state.onClose(n),e.setState({renderContent:void 0}))}),o(e,"renderContent",function(){return e.state.renderContent?e.state.renderContent():a(l,{})}),e.state={},e}return t(s,u),e(s,[{key:"render",value:function(){return i(C.Provider,{value:this,children:[this.props.children,a(p,{open:!!this.state.renderContent,onClose:this.close,slots:{backdrop:h},slotProps:{backdrop:{timeout:300}},sx:this.state.sx,children:a(v,{sx:this.state.sxWrap,children:this.renderContent()})})]})}}])}(),v=d(f)({position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",outline:"none"}),x=function(t){return function(e){return a(b,{children:m(function(n){return a(t,s(s({},e),{},{contextGlobalModal:n}))})})}},k=function(t){return function(e){return m(function(n){return a(t,s(s({},e),{},{contextGlobalModal:n}))})}};export{b as GlobalModal,C as GlobalModalContext,b as default,m as mapGlobalModalContext,k as withApiGlobalModalConsumerContext,x as withApiGlobalModalContext};
|
|
2
2
|
//# sourceMappingURL=global-modal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-modal.js","sources":["../../../src/api-context/global-modal.tsx"],"sourcesContent":["import React, { Component } from 'react'\r\nimport { Backdrop, Box, Modal, SxProps, styled } from '@mui/material'\r\n\r\nexport interface GlobalModalState {\r\n sx?: SxProps\r\n sxWrap?: SxProps\r\n /** @default true */\r\n backdropActivated?: boolean\r\n onClose?: (reason?: TModalReason) => void\r\n renderContent?: () => React.ReactNode\r\n}\r\n\r\nexport type TModalReason = 'backdropClick' | 'escapeKeyDown'\r\n\r\ninterface GlobalModalProps {}\r\n\r\nexport type TShowModal = (value: GlobalModalState) => void\r\n\r\nexport type TCloseModal = (event?: {}, reason?: TModalReason) => void\r\n\r\nexport interface IGlobalModalContext {\r\n show: TShowModal\r\n close: TCloseModal\r\n}\r\n\r\nexport const GlobalModalContext = React.createContext<IGlobalModalContext>({\r\n close: () => {\r\n console.warn('GlobalModal provider not found!')\r\n },\r\n show: () => {\r\n console.warn('GlobalModal provider not found!')\r\n }\r\n})\r\n\r\nexport interface IMapGlobalModal {\r\n context: IGlobalModalContext\r\n}\r\n\r\nexport const mapGlobalModalContext = (context: (state: IGlobalModalContext) => React.ReactNode) => (\r\n <GlobalModalContext.Consumer>{context}</GlobalModalContext.Consumer>\r\n)\r\n\r\nexport class GlobalModal extends Component<React.PropsWithChildren<GlobalModalProps>, GlobalModalState> implements IGlobalModalContext {\r\n constructor(props: any) {\r\n super(props)\r\n this.state = {}\r\n }\r\n\r\n show: TShowModal = (value) => {\r\n this.setState(value)\r\n }\r\n\r\n close: TCloseModal = (_, reason) => {\r\n if (reason === 'backdropClick' && this.state.backdropActivated === false) return\r\n
|
|
1
|
+
{"version":3,"file":"global-modal.js","sources":["../../../src/api-context/global-modal.tsx"],"sourcesContent":["import React, { Component } from 'react'\r\nimport { Backdrop, Box, Modal, SxProps, styled } from '@mui/material'\r\n\r\nexport interface GlobalModalState {\r\n sx?: SxProps\r\n sxWrap?: SxProps\r\n /** @default true */\r\n backdropActivated?: boolean\r\n onClose?: (reason?: TModalReason) => void\r\n renderContent?: () => React.ReactNode\r\n}\r\n\r\nexport type TModalReason = 'backdropClick' | 'escapeKeyDown'\r\n\r\ninterface GlobalModalProps {}\r\n\r\nexport type TShowModal = (value: GlobalModalState) => void\r\n\r\nexport type TCloseModal = (event?: {}, reason?: TModalReason) => void\r\n\r\nexport interface IGlobalModalContext {\r\n show: TShowModal\r\n close: TCloseModal\r\n}\r\n\r\nexport const GlobalModalContext = React.createContext<IGlobalModalContext>({\r\n close: () => {\r\n console.warn('GlobalModal provider not found!')\r\n },\r\n show: () => {\r\n console.warn('GlobalModal provider not found!')\r\n }\r\n})\r\n\r\nexport interface IMapGlobalModal {\r\n context: IGlobalModalContext\r\n}\r\n\r\nexport const mapGlobalModalContext = (context: (state: IGlobalModalContext) => React.ReactNode) => (\r\n <GlobalModalContext.Consumer>{context}</GlobalModalContext.Consumer>\r\n)\r\n\r\nexport class GlobalModal extends Component<React.PropsWithChildren<GlobalModalProps>, GlobalModalState> implements IGlobalModalContext {\r\n constructor(props: any) {\r\n super(props)\r\n this.state = {}\r\n }\r\n\r\n show: TShowModal = (value) => {\r\n this.setState(value)\r\n }\r\n\r\n close: TCloseModal = (_, reason) => {\r\n if (reason === 'backdropClick' && this.state.backdropActivated === false) return\r\n this.state.onClose && this.state.onClose(reason)\r\n this.setState({ renderContent: undefined })\r\n }\r\n\r\n render() {\r\n return (\r\n <GlobalModalContext.Provider value={this}>\r\n {this.props.children}\r\n <Modal\r\n open={!!this.state.renderContent}\r\n onClose={this.close}\r\n slots={{ backdrop: Backdrop }}\r\n slotProps={{ backdrop: { timeout: 300 } }}\r\n sx={this.state.sx}\r\n >\r\n <Wrapper sx={this.state.sxWrap}>{this.renderContent()}</Wrapper>\r\n </Modal>\r\n </GlobalModalContext.Provider>\r\n )\r\n }\r\n\r\n renderContent = (): React.ReactNode => {\r\n return this.state.renderContent ? this.state.renderContent() : <></>\r\n }\r\n}\r\nexport default GlobalModal\r\n\r\nconst Wrapper = styled(Box)({\r\n position: 'absolute',\r\n top: '50%',\r\n left: '50%',\r\n transform: 'translate(-50%, -50%)',\r\n outline: 'none'\r\n})\r\n\r\nexport interface IApiGlobalModalContextProps {\r\n contextGlobalModal: IGlobalModalContext\r\n}\r\n\r\nexport const withApiGlobalModalContext = <P extends IApiGlobalModalContextProps>(Component: React.ComponentType<P>) => {\r\n return (props: Omit<P, keyof IApiGlobalModalContextProps>) => {\r\n return (\r\n <GlobalModal>\r\n {mapGlobalModalContext((context) => (\r\n <Component {...(props as P)} contextGlobalModal={context} />\r\n ))}\r\n </GlobalModal>\r\n )\r\n }\r\n}\r\n\r\nexport const withApiGlobalModalConsumerContext = <P extends IApiGlobalModalContextProps>(Component: React.ComponentType<P>) => {\r\n return (props: Omit<P, keyof IApiGlobalModalContextProps>) => {\r\n return mapGlobalModalContext((context) => <Component {...(props as P)} contextGlobalModal={context} />)\r\n }\r\n}\r\n"],"names":["GlobalModalContext","React","createContext","close","console","warn","show","mapGlobalModalContext","context","_jsx","Consumer","GlobalModal","props","_this","_classCallCheck","_callSuper","_defineProperty","value","setState","_","reason","state","backdropActivated","onClose","renderContent","undefined","_inherits","Component","_createClass","key","_jsxs","Provider","this","children","Modal","open","slots","backdrop","Backdrop","slotProps","timeout","sx","Wrapper","sxWrap","styled","Box","position","top","left","transform","outline","withApiGlobalModalContext","_objectSpread","contextGlobalModal","withApiGlobalModalConsumerContext"],"mappings":"oVAyBaA,EAAqBC,EAAMC,cAAmC,CACzEC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7BC,EAACkB,EAASyB,EAAAA,KAAMxC,GAAW,GAAA,CAAEyC,mBAAoB7C,IAClD,IAGN,CACH,EAEa8C,EAAoC,SAAwC3B,GACvF,OAAO,SAACf,GACN,OAAOL,EAAsB,SAACC,GAAO,OAAKC,EAACkB,EAASyB,EAAAA,KAAMxC,GAAW,GAAA,CAAEyC,mBAAoB7C,MAC5F,CACH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineProperty as e,objectWithoutProperties as t,objectSpread2 as r,inherits as a,createClass as o,classCallCheck as n,callSuper as i}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,jsxs as p}from"react/jsx-runtime";import{Component as c}from"react";import{styled as s,Stack as d,Tooltip as u,tooltipClasses as m,
|
|
1
|
+
import{defineProperty as e,objectWithoutProperties as t,objectSpread2 as r,inherits as a,createClass as o,classCallCheck as n,callSuper as i}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as l,jsxs as p}from"react/jsx-runtime";import{Component as c}from"react";import{styled as s,Stack as d,Tooltip as u,tooltipClasses as m,Box as h,Typography as f,Divider as b}from"@mui/material";import x from"@mui/icons-material/HelpOutline";var g=["className"],v=function(){function t(){var r;n(this,t);for(var a=arguments.length,o=new Array(a),c=0;c<a;c++)o[c]=arguments[c];return r=i(this,t,[].concat(o)),e(r,"renderTitlePanel",function(){var e=r.props,t=e.panel,a=e.renderPanel;return a?a():t?p(k,{className:P.titlePanel,children:[r.renderTitle(t.title),l(b,{}),l(h,{className:P.content,children:r.renderContent(t.content)})]}):l(f,{variant:"body2",children:"Please provide a panel configuration"})}),e(r,"renderTitle",function(e){return e?"string"!=typeof e?e:l(f,{variant:"subtitle1",className:P.title,children:e}):null}),e(r,"renderContent",function(e){return e?"string"!=typeof e?e:l(f,{variant:"body2",children:e}):null}),r}return a(t,c),o(t,[{key:"render",value:function(){var e=this.props,t=e.children,a=e.slots;return l(w,r(r({arrow:!0,placement:"bottom",title:this.renderTitlePanel(),className:P.root},null==a?void 0:a.tooltipProps),{},{children:l(h,r(r({},null==a?void 0:a.wrapperProps),{},{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)||"")},k=s(d)(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})}),w=s(function(e){var a=e.className,o=t(e,g);return l(u,r(r({},o),{},{classes:{popper:a}}))})(function(t){var r=t.theme;return e(e({},"& .".concat(m.tooltip),{backgroundColor:r.palette.background.paper,color:r.palette.text.primary,padding:0,minWidth:"360px",maxWidth:"450px",borderRadius:r.shape.borderRadius,boxShadow:"dark"===r.palette.mode?"rgba(0, 0, 0, 0.4) 0px 6px 30px":"rgba(0, 0, 0, 0.08) 0px 6px 30px",border:"1px solid ".concat(r.palette.divider)}),"& .".concat(m.arrow),{color:r.palette.background.paper})}),T=s(x)(function(e){var t=e.theme;return{position:"relative",zIndex:1,color:t.palette.primary.main,borderRadius:"50%",cursor:"help",animation:"pulseGlow 1.5s infinite","@keyframes pulseGlow":{"0%":{boxShadow:"dark"===t.palette.mode?"0 0 0 0 rgba(144, 202, 249, 0.3)":"0 0 0 0 rgba(33, 150, 243, 0.3)"},"70%":{boxShadow:"dark"===t.palette.mode?"0 0 0 10px rgba(144, 202, 249, 0)":"0 0 0 10px rgba(33, 150, 243, 0)"},"100%":{boxShadow:"dark"===t.palette.mode?"0 0 0 0 rgba(144, 202, 249, 0)":"0 0 0 0 rgba(33, 150, 243, 0)"}}}});export{T as HelpOutlinePulseIcon,v as RichTooltip,v 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 <
|
|
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 { BoxProps, 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 wrapperProps?: BoxProps\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 <Box {...slots?.wrapperProps}>{children}</Box>\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: theme.palette.background.paper,\r\n color: theme.palette.text.primary,\r\n padding: 0,\r\n minWidth: '360px',\r\n maxWidth: '450px',\r\n borderRadius: theme.shape.borderRadius,\r\n boxShadow: theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.4) 0px 6px 30px' : 'rgba(0, 0, 0, 0.08) 0px 6px 30px',\r\n border: `1px solid ${theme.palette.divider}`\r\n },\r\n [`& .${tooltipClasses.arrow}`]: {\r\n color: theme.palette.background.paper\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: theme.palette.mode === 'dark' ? '0 0 0 0 rgba(144, 202, 249, 0.3)' : '0 0 0 0 rgba(33, 150, 243, 0.3)'\r\n },\r\n '70%': {\r\n boxShadow: theme.palette.mode === 'dark' ? '0 0 0 10px rgba(144, 202, 249, 0)' : '0 0 0 10px rgba(33, 150, 243, 0)'\r\n },\r\n '100%': {\r\n boxShadow: theme.palette.mode === 'dark' ? '0 0 0 0 rgba(144, 202, 249, 0)' : '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","wrapperProps","getRichTooltipClass","options","prefix","suffix","styled","Stack","_ref","theme","gap","color","palette","primary","main","fontWeight","padding","spacing","text","_ref3","_objectWithoutProperties","_excluded","Tooltip","classes","popper","_ref4","tooltipClasses","tooltip","backgroundColor","background","paper","minWidth","maxWidth","borderRadius","shape","boxShadow","mode","border","divider","HelpOutlinePulseIcon","HelpOutlineIcon","_ref6","position","zIndex","cursor","animation"],"mappings":"+cAqBaA,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,mBAUJ,WACjB,IAAAY,EAA+BZ,EAAKa,MAA5BC,EAAKF,EAALE,MAAOC,EAAWH,EAAXG,YACf,OAAIA,EAAoBA,IACnBD,EAEHE,EAACC,GAAwBC,UAAWC,EAAmBC,qBACpDpB,EAAKqB,YAAYP,EAAMQ,OACxBC,EAACC,MACDD,EAACE,EAAI,CAAAP,UAAWC,EAAmBO,QAAUC,SAAA3B,EAAK4B,cAAcd,EAAMY,cALvDH,EAACM,EAAU,CAACC,QAAQ,4DAQxCnB,EAAAX,EAEa,cAAA,SAAC+B,GACb,OAAKA,EACgB,iBAAVA,EAA2BA,EAEpCR,EAACM,EAAW,CAAAC,QAAQ,YAAYZ,UAAWC,EAAmBG,eAC3DS,IAJc,OAOpBpB,EAAAX,EAEe,gBAAA,SAAC+B,GACf,OAAKA,EACgB,iBAAVA,EAA2BA,EAC/BR,EAACM,EAAW,CAAAC,QAAQ,QAAOH,SAAEI,IAFjB,OAGpB/B,CAAA,CAAA,OAAAgC,EAAAjC,EArC8BkC,GAqC9BC,EAAAnC,EAAA,CAAA,CAAAoC,IAAA,SAAAJ,MApCD,WACE,IAAAK,EAA4B3B,KAAKI,MAAzBc,EAAQS,EAART,SAAUU,EAAKD,EAALC,MAClB,OACEd,EAACe,EAAaC,EAAAA,EAAA,CAACC,SAAMC,UAAU,SAASnB,MAAOb,K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QACVC,SAAU,QACVC,aAAcxB,EAAMyB,MAAMD,aAC1BE,UAAkC,SAAvB1B,EAAMG,QAAQwB,KAAkB,kCAAoC,mCAC/EC,oBAAMvE,OAAe2C,EAAMG,QAAQ0B,iBACpCxE,OACM4D,EAAe9B,OAAU,CAC9Be,MAAOF,EAAMG,QAAQiB,WAAWC,OACjC,GAGUS,EAAuBjC,EAAOkC,EAAPlC,CAAwB,SAAAmC,GAAA,IAAGhC,EAAKgC,EAALhC,MAAK,MAAQ,CAC1EiC,SAAU,WACVC,OAAQ,EACRhC,MAAOF,EAAMG,QAAQC,QAAQC,KAC7BmB,aAAc,MACdW,OAAQ,OACRC,UAAW,0BACX,uBAAwB,CACtB,KAAM,CACJV,UAAkC,SAAvB1B,EAAMG,QAAQwB,KAAkB,mCAAqC,mCAElF,MAAO,CACLD,UAAkC,SAAvB1B,EAAMG,QAAQwB,KAAkB,oCAAsC,oCAEnF,OAAQ,CACND,UAAkC,SAAvB1B,EAAMG,QAAQwB,KAAkB,iCAAmC,kCAGnF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{objectWithoutProperties as r,objectSpread2 as e,asyncToGenerator as n,regenerator as o}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as t,jsx as i}from"react/jsx-runtime";import{useRef as a,useEffect as l}from"react";import{Box as s,Typography as u,Grid as d,Button as c}from"@mui/material";import{getErrorMessage as f}from"./helpers.js";import{getFormFields as m,getFormValidators as p,getFormPreSubmit as v,isFormRegistered as b}from"./decorator.js";import g from"./validator.js";import h from"./create.input.js";import x from"./create.form-base.js";var y=["type","renderInput"],C=["disabled","visible"],S=x({}),j=h({}),B=function(n){var o,a,l=n.type,s=n.renderInput,u=r(n,y),d=(null===(o=u.name)||void 0===o?void 0:o.toString())||"",c=(null===(a=u.data)||void 0===a?void 0:a[d])||u.defaultValue;return S.mapContext(function(r){var n=r.messageErrors,o=r.onBlur,a=f(r.messageErrors,u.name);if(s)return i(s,e(e({},u),{},{messageErrors:n,onBlur:o,formContext:r}));switch(l){case String:return i(j,e(e({},u),{},{messageErrors:n,onBlur:o,formContext:r}));case Number:return i(j,e(e({},u),{},{slots:e({textFieldProps:{type:"number"}},u.slots),messageErrors:n,onBlur:o,formContext:r}));case Boolean:return t("div",{children:[t("label",{children:[u.label||d,": "]}),i("input",{name:d,type:"checkbox",defaultChecked:c}),i("span",{style:{color:"red"},children:a.error?a.message:""})]});default:return t("div",{children:["Unsupported field type for ",d]})}})},E=function(f){var h,x=f.slots,y=m(f.configClass),j=p(f.configClass),E=v(f.configClass),w=a(null);if(!b(f.configClass)){var k,F=(null===(k=f.configClass)||void 0===k?void 0:k.name)||"Unknown";return t(s,{sx:{border:"1px dashed #ccc",padding:12,borderRadius:4,color:"#333",background:"#fafafa"},children:[i(u,{variant:"subtitle1",sx:{fontWeight:600,marginBottom:6},children:"Form configuration not registered"}),t(u,{variant:"body1",children:['Configuration for "',F,'" was not found. Did you forget to add ',i("code",{children:"@registerForm"})," to the class?"]})]})}var P,I=function(){var r=n(o().m(function r(e){var n,t,i;return o().w(function(r){for(;;)switch(r.p=r.n){case 0:if(w.current=new AbortController,n=w.current.signal,t=e,r.p=1,null==E||!E.handler){r.n=3;break}return r.n=2,E.handler(e,f.data);case 2:null==(t=r.v)&&(t=e);case 3:if(!f.onSubmit){r.n=4;break}return r.n=4,f.onSubmit(t,n);case 4:r.n=6;break;case 5:throw r.p=5,i=r.v,f.onError&&f.onError(i),i;case 6:return r.a(2)}},r,null,[[1,5]])}));return function(e){return r.apply(this,arguments)}}();return l(function(){return function(){var r;null===(r=w.current)||void 0===r||r.abort()}},[]),t(S.Form,{onSubmit:I,validate:new g(j),onError:f.onSubmitError,slots:null==x?void 0:x.formBase,children:[i(d,{container:!0,spacing:2,children:y.map(function(n){var o=n.disabled,t=n.visible,a=r(n,C);if(!("function"==typeof t?t(f.data):!1!==t))return null;var l="function"==typeof o?o(f.data):!0===o;return i(d,e(e({item:!0,xs:12},n.size),{},{children:i(B,e(e({data:f.data},a),{},{disabled:l}))}),n.name.toString())})}),!1===(null==x?void 0:x.isFooter)?null:null!=x&&x.renderSubmitButton?x.renderSubmitButton():i(s,e(e({},null==x?void 0:x.footerProps),{},{sx:e({display:"flex",justifyContent:"flex-end"},(null==x||null===(P=x.footerProps)||void 0===P?void 0:P.sx)||{}),children:i(c,{variant:"contained",color:"primary",type:"submit",sx:{mt:2,flex:"0 0 auto"},children:"Submit"})})),null===(h=f.slots)||void 0===h?void 0:h.bottom]})},w=function(r,n){return function(o){return i(E,e(e({configClass:r},n),o))}};export{B as DecoratorField,E as DecoratorForm,w as createDecoratorForm,E as default};
|
|
2
2
|
//# sourceMappingURL=decorator.form.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorator.form.js","sources":["../../../src/form/decorator.form.tsx"],"sourcesContent":["import { ComponentType, FC } from 'react'\r\nimport { Box, Button, Grid, Typography } from '@mui/material'\r\nimport { IFormInputBase } from './types'\r\nimport { getErrorMessage } from './helpers'\r\nimport { getFormFields, getFormPreSubmit, getFormValidators, isFormRegistered } from './decorator'\r\nimport FormValidator, { IPartialError } from './validator'\r\nimport createInput from './create.input'\r\nimport createFormBase from './create.form-base'\r\n\r\nconst FormBase = createFormBase<any>({})\r\nconst InputInstance = createInput<any>({})\r\n\r\nexport interface IDecoratorFieldProps<T = any> extends IFormInputBase<T> {\r\n type?: any\r\n renderInput?: ComponentType<IFormInputBase<T>>\r\n}\r\n\r\nexport const DecoratorField: FC<IDecoratorFieldProps> = ({ type: inputType, renderInput, ...props }) => {\r\n const name = props.name?.toString() || ''\r\n const defaultValue = props.data?.[name] || props.defaultValue\r\n\r\n return FormBase.mapContext((context) => {\r\n const { messageErrors, onBlur } = context\r\n const err = getErrorMessage(context.messageErrors, props.name as any)\r\n if (renderInput) {\r\n const InputComp = renderInput\r\n return <InputComp {...props} messageErrors={messageErrors} onBlur={onBlur} formContext={context} />\r\n }\r\n switch (inputType) {\r\n case String:\r\n return <InputInstance {...props} messageErrors={messageErrors} onBlur={onBlur} formContext={context} />\r\n case Number:\r\n return (\r\n <InputInstance\r\n {...props}\r\n slots={{ textFieldProps: { type: 'number' }, ...props.slots }}\r\n messageErrors={messageErrors}\r\n onBlur={onBlur}\r\n formContext={context}\r\n />\r\n )\r\n case Boolean:\r\n return (\r\n <div>\r\n <label>{props.label || name}: </label>\r\n <input name={name} type='checkbox' defaultChecked={defaultValue} />\r\n <span style={{ color: 'red' }}>{err.error ? err.message : ''}</span>\r\n </div>\r\n )\r\n default:\r\n return <div>Unsupported field type for {name}</div>\r\n }\r\n })\r\n}\r\n\r\nexport interface IDecoratorFormSlots {\r\n bottom?: React.ReactNode\r\n isFooter?: React.ReactNode | boolean\r\n renderSubmitButton?: () => React.ReactNode\r\n}\r\n\r\nexport interface IDecoratorFormProps<T = any> {\r\n configClass: any\r\n data?: any\r\n onSubmit?: (data: any) => Promise<void>\r\n onError?: (error: any) => void\r\n onSubmitError?: (error: IPartialError<T>) => void\r\n slots?: IDecoratorFormSlots\r\n}\r\n\r\nexport const DecoratorForm: FC<IDecoratorFormProps> = (props) => {\r\n const fields = getFormFields(props.configClass)\r\n const validators = getFormValidators(props.configClass)\r\n const preSubmitConfig = getFormPreSubmit(props.configClass)\r\n\r\n // If the provided configClass isn't registered via @registerForm,\r\n // show a simple, friendly error UI instead of throwing.\r\n if (!isFormRegistered(props.configClass)) {\r\n const name = props.configClass?.name || 'Unknown'\r\n return (\r\n <Box sx={{ border: '1px dashed #ccc', padding: 12, borderRadius: 4, color: '#333', background: '#fafafa' }}>\r\n <Typography variant='subtitle1' sx={{ fontWeight: 600, marginBottom: 6 }}>\r\n Form configuration not registered\r\n </Typography>\r\n <Typography variant='body1'>\r\n Configuration for \"{name}\" was not found. Did you forget to add <code>@registerForm</code> to the class?\r\n </Typography>\r\n </Box>\r\n )\r\n }\r\n\r\n const handleSubmit = async (data: any) => {\r\n let processedData = data\r\n try {\r\n // Execute presubmit handler if exists\r\n if (preSubmitConfig?.handler) {\r\n processedData = await preSubmitConfig.handler(data, props.data)\r\n // If handler returns null/undefined, use original data\r\n if (processedData === null || processedData === undefined) {\r\n processedData = data\r\n }\r\n }\r\n\r\n // Call the original onSubmit with processed data\r\n if (props.onSubmit) {\r\n await props.onSubmit(processedData)\r\n }\r\n } catch (error) {\r\n if (props.onError) {\r\n props.onError(error)\r\n }\r\n throw error\r\n }\r\n }\r\n\r\n const renderFooter = () => {\r\n if (props.slots?.isFooter === false) return null\r\n if (props.slots?.renderSubmitButton) {\r\n return props.slots.renderSubmitButton()\r\n }\r\n return (\r\n <Button variant='contained' color='primary' type='submit' sx={{ mt: 2 }}>\r\n Submit\r\n </Button>\r\n )\r\n }\r\n\r\n return (\r\n <FormBase.Form onSubmit={handleSubmit} validate={new FormValidator(validators)} onError={props.onSubmitError}>\r\n <Grid container spacing={2}>\r\n {fields.map((field) => (\r\n <Grid item key={field.name.toString()} xs={12} {...field.size}>\r\n <DecoratorField data={props.data} {...field} />\r\n </Grid>\r\n ))}\r\n </Grid>\r\n {renderFooter()}\r\n {props.slots?.bottom}\r\n </FormBase.Form>\r\n )\r\n}\r\nexport default DecoratorForm\r\n\r\nexport const createDecoratorForm = function <T>(\r\n configClass: any,\r\n params?: Partial<Omit<IDecoratorFormProps, 'configClass'>>\r\n): ComponentType<Omit<IDecoratorFormProps, 'configClass'>> {\r\n const DecoratorFormComp: FC<Omit<IDecoratorFormProps, 'configClass'>> = (props) => {\r\n return <DecoratorForm configClass={configClass} {...params} {...props} />\r\n }\r\n return DecoratorFormComp\r\n}\r\n"],"names":["FormBase","createFormBase","InputInstance","createInput","DecoratorField","_ref","_props$name","_props$data","inputType","type","renderInput","props","_objectWithoutProperties","_excluded","name","toString","defaultValue","data","mapContext","context","messageErrors","onBlur","err","getErrorMessage","_jsx","_objectSpread","formContext","String","Number","slots","textFieldProps","Boolean","_jsxs","children","label","defaultChecked","style","color","error","message","DecoratorForm","_props$slots3","fields","getFormFields","configClass","validators","getFormValidators","preSubmitConfig","getFormPreSubmit","isFormRegistered","_props$configClass","Box","sx","border","padding","borderRadius","background","Typography","variant","fontWeight","marginBottom","_props$slots","_props$slots2","handleSubmit","_ref2","_asyncToGenerator","_regenerator","m","_callee","processedData","_t","w","_context","p","n","handler","v","onSubmit","onError","a","_x","apply","this","arguments","Form","validate","FormValidator","onSubmitError","Grid","container","spacing","map","field","item","xs","size","isFooter","renderSubmitButton","Button","mt","bottom","createDecoratorForm","params"],"mappings":"8iBASMA,EAAWC,EAAoB,IAC/BC,EAAgBC,EAAiB,IAO1BC,EAA2C,SAA7BC,GAA4E,IAAAC,EAAAC,EAAtCC,EAASH,EAAfI,KAAiBC,EAAWL,EAAXK,YAAgBC,EAAKC,EAAAP,EAAAQ,GACzFC,GAAiBR,QAAVA,EAAAK,EAAMG,gBAAIR,SAAVA,EAAYS,aAAc,GACjCC,GAAyB,QAAVT,EAAAI,EAAMM,YAAI,IAAAV,OAAA,EAAVA,EAAaO,KAASH,EAAMK,aAEjD,OAAOhB,EAASkB,WAAW,SAACC,GAC1B,IAAQC,EAA0BD,EAA1BC,cAAeC,EAAWF,EAAXE,OACjBC,EAAMC,EAAgBJ,EAAQC,cAAeT,EAAMG,MACzD,GAAIJ,EAEF,OAAOc,EADWd,EACDe,EAAAA,KAAKd,GAAK,GAAA,CAAES,cAAeA,EAAeC,OAAQA,EAAQK,YAAaP,KAE1F,OAAQX,GACN,KAAKmB,OACH,OAAOH,EAACtB,EAAauB,EAAAA,KAAKd,GAAK,GAAA,CAAES,cAAeA,EAAeC,OAAQA,EAAQK,YAAaP,KAC9F,KAAKS,OACH,OACEJ,EAACtB,EAAauB,EAAAA,KACRd,GAAK,GAAA,CACTkB,MAAKJ,EAAA,CAAIK,eAAgB,CAAErB,KAAM,WAAeE,EAAMkB,OACtDT,cAAeA,EACfC,OAAQA,EACRK,YAAaP,KAGnB,KAAKY,QACH,OACEC,mBACEA,EAAQ,QAAA,CAAAC,SAAA,CAAAtB,EAAMuB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E,SAAC3F,GACvE,OAAOa,EAACgB,EAAaf,EAAAA,EAAA,CAACmB,YAAaA,GAAiB0D,GAAY3F,GACjE,CAEH"}
|
|
1
|
+
{"version":3,"file":"decorator.form.js","sources":["../../../src/form/decorator.form.tsx"],"sourcesContent":["import { ComponentType, FC, useEffect, useRef } from 'react'\r\nimport { Box, BoxProps, Button, Grid, Typography } from '@mui/material'\r\nimport { IFormInputBase } from './types'\r\nimport { getErrorMessage } from './helpers'\r\nimport { getFormFields, getFormPreSubmit, getFormValidators, isFormRegistered } from './decorator'\r\nimport FormValidator, { IPartialError } from './validator'\r\nimport createInput from './create.input'\r\nimport createFormBase, { IFormBaseSlots } from './create.form-base'\r\n\r\nconst FormBase = createFormBase<any>({})\r\nconst InputInstance = createInput<any>({})\r\n\r\nexport interface IDecoratorFieldProps<T = any> extends IFormInputBase<T> {\r\n type?: any\r\n visible?: boolean | ((data: T) => boolean)\r\n renderInput?: ComponentType<IFormInputBase<T>>\r\n}\r\n\r\nexport const DecoratorField: FC<IDecoratorFieldProps> = ({ type: inputType, renderInput, ...props }) => {\r\n const name = props.name?.toString() || ''\r\n const defaultValue = props.data?.[name] || props.defaultValue\r\n\r\n return FormBase.mapContext((context) => {\r\n const { messageErrors, onBlur } = context\r\n const err = getErrorMessage(context.messageErrors, props.name as any)\r\n if (renderInput) {\r\n const InputComp = renderInput\r\n return <InputComp {...props} messageErrors={messageErrors} onBlur={onBlur} formContext={context} />\r\n }\r\n switch (inputType) {\r\n case String:\r\n return <InputInstance {...props} messageErrors={messageErrors} onBlur={onBlur} formContext={context} />\r\n case Number:\r\n return (\r\n <InputInstance\r\n {...props}\r\n slots={{ textFieldProps: { type: 'number' }, ...props.slots }}\r\n messageErrors={messageErrors}\r\n onBlur={onBlur}\r\n formContext={context}\r\n />\r\n )\r\n case Boolean:\r\n return (\r\n <div>\r\n <label>{props.label || name}: </label>\r\n <input name={name} type='checkbox' defaultChecked={defaultValue} />\r\n <span style={{ color: 'red' }}>{err.error ? err.message : ''}</span>\r\n </div>\r\n )\r\n default:\r\n return <div>Unsupported field type for {name}</div>\r\n }\r\n })\r\n}\r\n\r\nexport interface IDecoratorFormSlots {\r\n bottom?: React.ReactNode\r\n isFooter?: React.ReactNode | boolean\r\n renderSubmitButton?: () => React.ReactNode\r\n formBase?: IFormBaseSlots\r\n footerProps?: BoxProps & { [key: string]: any }\r\n}\r\n\r\nexport interface IDecoratorFormProps<T = any> {\r\n configClass: any\r\n data?: Partial<T>\r\n onSubmit?: (data: Partial<T>, signal?: AbortSignal) => Promise<void>\r\n onError?: (error: any) => void\r\n onSubmitError?: (error: IPartialError<T>) => void\r\n slots?: IDecoratorFormSlots\r\n}\r\n\r\nexport const DecoratorForm: FC<IDecoratorFormProps> = (props) => {\r\n const { slots } = props\r\n const fields = getFormFields(props.configClass)\r\n const validators = getFormValidators(props.configClass)\r\n const preSubmitConfig = getFormPreSubmit(props.configClass)\r\n const abortControllerRef = useRef<AbortController | null>(null)\r\n\r\n // If the provided configClass isn't registered via @registerForm,\r\n // show a simple, friendly error UI instead of throwing.\r\n if (!isFormRegistered(props.configClass)) {\r\n const name = props.configClass?.name || 'Unknown'\r\n return (\r\n <Box sx={{ border: '1px dashed #ccc', padding: 12, borderRadius: 4, color: '#333', background: '#fafafa' }}>\r\n <Typography variant='subtitle1' sx={{ fontWeight: 600, marginBottom: 6 }}>\r\n Form configuration not registered\r\n </Typography>\r\n <Typography variant='body1'>\r\n Configuration for \"{name}\" was not found. Did you forget to add <code>@registerForm</code> to the class?\r\n </Typography>\r\n </Box>\r\n )\r\n }\r\n\r\n const handleSubmit = async (data: any) => {\r\n // Create new AbortController for this submit\r\n abortControllerRef.current = new AbortController()\r\n const signal = abortControllerRef.current.signal\r\n\r\n let processedData = data\r\n try {\r\n // Execute presubmit handler if exists\r\n if (preSubmitConfig?.handler) {\r\n processedData = await preSubmitConfig.handler(data, props.data)\r\n // If handler returns null/undefined, use original data\r\n if (processedData === null || processedData === undefined) {\r\n processedData = data\r\n }\r\n }\r\n\r\n // Call the original onSubmit with processed data and abort signal\r\n if (props.onSubmit) {\r\n await props.onSubmit(processedData, signal)\r\n }\r\n } catch (error) {\r\n if (props.onError) {\r\n props.onError(error)\r\n }\r\n throw error\r\n }\r\n }\r\n\r\n const renderFooter = () => {\r\n if (slots?.isFooter === false) return null\r\n if (slots?.renderSubmitButton) {\r\n return slots.renderSubmitButton()\r\n }\r\n return (\r\n <Box {...slots?.footerProps} sx={{ display: 'flex', justifyContent: 'flex-end', ...(slots?.footerProps?.sx || {}) }}>\r\n <Button variant='contained' color='primary' type='submit' sx={{ mt: 2, flex: '0 0 auto' }}>\r\n Submit\r\n </Button>\r\n </Box>\r\n )\r\n }\r\n\r\n useEffect(() => {\r\n return () => {\r\n // Abort any pending request when component unmounts\r\n abortControllerRef.current?.abort()\r\n }\r\n }, [])\r\n\r\n return (\r\n <FormBase.Form onSubmit={handleSubmit} validate={new FormValidator(validators)} onError={props.onSubmitError} slots={slots?.formBase}>\r\n <Grid container spacing={2}>\r\n {fields.map((field) => {\r\n const { disabled, visible, ...fieldOther } = field\r\n // Check visibility, default is visible (true or undefined)\r\n const isVisible = typeof visible === 'function' ? visible(props.data) : visible !== false\r\n if (!isVisible) return null\r\n // Check disabled state, default is enabled (false or undefined)\r\n const isDisabled = typeof disabled === 'function' ? disabled(props.data) : disabled === true\r\n return (\r\n <Grid item key={field.name.toString()} xs={12} {...field.size}>\r\n <DecoratorField data={props.data} {...fieldOther} disabled={isDisabled} />\r\n </Grid>\r\n )\r\n })}\r\n </Grid>\r\n {renderFooter()}\r\n {props.slots?.bottom}\r\n </FormBase.Form>\r\n )\r\n}\r\nexport default DecoratorForm\r\n\r\nexport const createDecoratorForm = function <T>(\r\n configClass: any,\r\n params?: Partial<Omit<IDecoratorFormProps<T>, 'configClass'>>\r\n): ComponentType<Omit<IDecoratorFormProps<T>, 'configClass'>> {\r\n const DecoratorFormComp: FC<Omit<IDecoratorFormProps<T>, 'configClass'>> = (props) => {\r\n return <DecoratorForm configClass={configClass} {...params} {...props} />\r\n }\r\n return DecoratorFormComp\r\n}\r\n"],"names":["FormBase","createFormBase","InputInstance","createInput","DecoratorField","_ref","_props$name","_props$data","inputType","type","renderInput","props","_objectWithoutProperties","_excluded","name","toString","defaultValue","data","mapContext","context","messageErrors","onBlur","err","getErrorMessage","_jsx","_objectSpread","formContext","String","Number","slots","textFieldProps","Boolean","_jsxs","children","label","defaultChecked","style","color","error","message","DecoratorForm","_props$slots","fields","getFormFields","configClass","validators","getFormValidators","preSubmitConfig","getFormPreSubmit","abortControllerRef","useRef","isFormRegistered","_props$configClass","Box","sx","border","padding","borderRadius","background","Typography","variant","fontWeight","marginBottom","_slots$footerProps","handleSubmit","_ref2","_asyncToGenerator","_regenerator","m","_callee","signal","processedData","_t","w","_context","p","n","current","AbortController","handler","v","onSubmit","onError","a","_x","apply","this","arguments","useEffect","_abortControllerRef$c","abort","Form","validate","FormValidator","onSubmitError","formBase","Grid","container","spacing","map","field","disabled","visible","fieldOther","_excluded2","isDisabled","item","xs","size","isFooter","renderSubmitButton","footerProps","display","justifyContent","Button","mt","flex","bottom","createDecoratorForm","params"],"mappings":"qnBASMA,EAAWC,EAAoB,IAC/BC,EAAgBC,EAAiB,IAQ1BC,EAA2C,SAA7BC,GAA4E,IAAAC,EAAAC,EAAtCC,EAASH,EAAfI,KAAiBC,EAAWL,EAAXK,YAAgBC,EAAKC,EAAAP,EAAAQ,GACzFC,GAAiBR,QAAVA,EAAAK,EAAMG,gBAAIR,SAAVA,EAAYS,aAAc,GACjCC,GAAyB,QAAVT,EAAAI,EAAMM,YAAI,IAAAV,OAAA,EAAVA,EAAaO,KAASH,EAAMK,aAEjD,OAAOhB,EAASkB,WAAW,SAACC,GAC1B,IAAQC,EAA0BD,EAA1BC,cAAeC,EAAWF,EAAXE,OACjBC,EAAMC,EAAgBJ,EAAQC,cAAeT,EAAMG,MACzD,GAAIJ,EAEF,OAAOc,EADWd,EACDe,EAAAA,KAAKd,GAAK,GA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1 @@
|
|
|
1
|
-
{"version":3,"file":"decorator.js","sources":["../../../src/form/decorator.ts"],"sourcesContent":["import 'reflect-metadata'\r\nimport { ComponentType } from 'react'\r\nimport { IFormInputBase } from './types'\r\nimport { IConfigValue, IFormValidatorConfig } from './validator'\r\n\r\nconst ClassRegistry = new Map<string, any>()\r\n\r\nexport function registerForm(name?: string) {\r\n return function <T extends { new (...args: any[]): {} }>(constructor: T) {\r\n const key = name || constructor.name\r\n ClassRegistry.set(key, constructor)\r\n class RegisteredClass extends constructor {\r\n __class = key\r\n constructor(...args: any[]) {\r\n super(...args)\r\n this.__class = key\r\n }\r\n }\r\n Object.defineProperty(RegisteredClass, 'name', { value: constructor.name })\r\n Object.defineProperty(RegisteredClass, '__class', { value: key })\r\n return RegisteredClass\r\n }\r\n}\r\n\r\n/**\r\n * Check whether a class (constructor) or an instance has been registered\r\n * with the @registerForm decorator.\r\n *\r\n * Accepts:\r\n * - the decorated constructor (function)\r\n * - the original constructor (function)\r\n * - an instance of the class\r\n *\r\n * Returns true when the underlying registry contains an entry for the\r\n * class key (either the custom name provided to the decorator or the\r\n * constructor name).\r\n */\r\nexport function isFormRegistered(target: any): boolean {\r\n if (!target) return false\r\n const ctor = typeof target === 'function' ? target : target?.constructor\r\n if (!ctor) return false\r\n const key = (ctor as any).__class || (ctor as any).name\r\n if (!key) return false\r\n return ClassRegistry.has(key)\r\n}\r\n\r\nexport interface IPreSubmitMetadata<T = any> {\r\n handler: (data: T, oldData: T) => Promise<any> | any\r\n}\r\n\r\nexport function formPreSubmit<T = any>(handler: IPreSubmitMetadata<T>['handler']) {\r\n return function <T extends { new (...args: any[]): {} }>(constructor: T) {\r\n Reflect.defineMetadata('form:presubmit', { handler }, constructor)\r\n return constructor\r\n }\r\n}\r\n\r\nexport function getFormPreSubmit(targetClass: any): IPreSubmitMetadata | undefined {\r\n return Reflect.getMetadata('form:presubmit', targetClass)\r\n}\r\n\r\nexport interface IFieldMetadata<T = any> {\r\n name: keyof T | string\r\n label?: string\r\n placeholder?: string\r\n default?: any\r\n type?: any\r\n size?: Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>>\r\n renderInput?: ComponentType<IFormInputBase<T>>\r\n}\r\n\r\nexport function formField(options: Omit<IFieldMetadata, 'name'>) {\r\n return function (target: any, propertyKey: string) {\r\n const designType = Reflect.getMetadata('design:type', target, propertyKey)\r\n const actualType = options.type || designType\r\n const existing: IFieldMetadata[] = Reflect.getMetadata('form:fields', target.constructor) || []\r\n const fields = [...existing]\r\n fields.push({ name: propertyKey, type: actualType, label: options.label || propertyKey, ...options })\r\n Reflect.defineMetadata('form:fields', fields, target.constructor)\r\n }\r\n}\r\n\r\nexport const getFormFields = (targetClass: any): IFieldMetadata[] => {\r\n return Reflect.getMetadata('form:fields', targetClass) || []\r\n}\r\n\r\nexport interface IValidationMetadata extends IConfigValue {\r\n name: string\r\n}\r\n\r\nexport function formValidate(options: Omit<IValidationMetadata, 'name'>) {\r\n return function (target: any, propertyKey: string) {\r\n const existing: IValidationMetadata[] = Reflect.getMetadata('form:validators', target.constructor) || []\r\n const validators = [...existing]\r\n validators.push({ name: propertyKey, ...options })\r\n Reflect.defineMetadata('form:validators', validators, target.constructor)\r\n }\r\n}\r\n\r\nexport function getFormValidators<T = any>(targetClass: any): IFormValidatorConfig<T> {\r\n const metas: IValidationMetadata[] = Reflect.getMetadata('form:validators', targetClass) || []\r\n return metas.reduce<IFormValidatorConfig<T>>((acc, curr) => {\r\n acc[curr.name as keyof T] = { Rules: curr.Rules, label: curr.label }\r\n return acc\r\n }, {})\r\n}\r\n"],"names":["ClassRegistry","Map","registerForm","name","constructor","key","set","RegisteredClass","_constructor","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","this","concat","_defineProperty","__class","_inherits","_createClass","Object","defineProperty","value","isFormRegistered","target","ctor","has","formPreSubmit","handler","Reflect","defineMetadata","getFormPreSubmit","targetClass","getMetadata","formField","options","propertyKey","designType","actualType","type","existing","fields","_toConsumableArray","push","_objectSpread","label","getFormFields","formValidate","validators","getFormValidators","reduce","acc","curr","Rules"],"mappings":"2NAKA,IAAMA,EAAgB,IAAIC,IAEpB,SAAUC,EAAaC,GAC3B,OAAO,SAAkDC,GACvD,IAAMC,EAAMF,GAAQC,EAAYD,KAChCH,EAAcM,IAAID,EAAKD,GAAY,IAC7BG,WAAgBC,GAEpB,SAAAD,IAA0B,IAAAE,EAAAC,OAAAH,GAAA,IAAA,IAAAI,EAAAC,UAAAC,OAAXC,EAAWC,IAAAA,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAXF,EAAWE,GAAAJ,UAAAI,GAEN,OADlBP,EAAAQ,EAAAC,KAAAX,EAAAY,GAAAA,OAASL,IAAKM,EAAAX,EAAA,UAFNJ,GAGRI,EAAKY,QAAUhB,EAAGI,CACpB,CAAC,OAAAa,EAAAf,EAAAC,GAAAe,EAAAhB,EAAA,EAL2BH,GAS9B,OAFAoB,OAAOC,eAAelB,EAAiB,OAAQ,CAAEmB,MAAOtB,EAAYD,OACpEqB,OAAOC,eAAelB,EAAiB,UAAW,CAAEmB,MAAOrB,IACpDE,CACR,CACH,CAeM,SAAUoB,EAAiBC,GAC/B,IAAKA,EAAQ,OAAO,EACpB,IAAMC,EAAyB,mBAAXD,EAAwBA,EAASA,aAAAA,EAAAA,EAAQxB,YAC7D,IAAKyB,EAAM,OAAO,EAClB,IAAMxB,EAAOwB,EAAaR,SAAYQ,EAAa1B,KACnD,QAAKE,GACEL,EAAc8B,IAAIzB,EAC3B,CAMM,SAAU0B,EAAuBC,GACrC,OAAO,SAAkD5B,GAEvD,OADA6B,QAAQC,eAAe,iBAAkB,CAAEF,QAAAA,GAAW5B,GAC/CA,CACR,CACH,CAEM,SAAU+B,EAAiBC,GAC/B,OAAOH,QAAQI,YAAY,iBAAkBD,EAC/C,
|
|
1
|
+
{"version":3,"file":"decorator.js","sources":["../../../src/form/decorator.ts"],"sourcesContent":["import 'reflect-metadata'\r\nimport { ComponentType } from 'react'\r\nimport { IFormInputBase } from './types'\r\nimport { IConfigValue, IFormValidatorConfig } from './validator'\r\n\r\nconst ClassRegistry = new Map<string, any>()\r\n\r\nexport function registerForm(name?: string) {\r\n return function <T extends { new (...args: any[]): {} }>(constructor: T) {\r\n const key = name || constructor.name\r\n ClassRegistry.set(key, constructor)\r\n class RegisteredClass extends constructor {\r\n __class = key\r\n constructor(...args: any[]) {\r\n super(...args)\r\n this.__class = key\r\n }\r\n }\r\n Object.defineProperty(RegisteredClass, 'name', { value: constructor.name })\r\n Object.defineProperty(RegisteredClass, '__class', { value: key })\r\n return RegisteredClass\r\n }\r\n}\r\n\r\n/**\r\n * Check whether a class (constructor) or an instance has been registered\r\n * with the @registerForm decorator.\r\n *\r\n * Accepts:\r\n * - the decorated constructor (function)\r\n * - the original constructor (function)\r\n * - an instance of the class\r\n *\r\n * Returns true when the underlying registry contains an entry for the\r\n * class key (either the custom name provided to the decorator or the\r\n * constructor name).\r\n */\r\nexport function isFormRegistered(target: any): boolean {\r\n if (!target) return false\r\n const ctor = typeof target === 'function' ? target : target?.constructor\r\n if (!ctor) return false\r\n const key = (ctor as any).__class || (ctor as any).name\r\n if (!key) return false\r\n return ClassRegistry.has(key)\r\n}\r\n\r\nexport interface IPreSubmitMetadata<T = any> {\r\n handler: (data: T, oldData: T) => Promise<any> | any\r\n}\r\n\r\nexport function formPreSubmit<T = any>(handler: IPreSubmitMetadata<T>['handler']) {\r\n return function <T extends { new (...args: any[]): {} }>(constructor: T) {\r\n Reflect.defineMetadata('form:presubmit', { handler }, constructor)\r\n return constructor\r\n }\r\n}\r\n\r\nexport function getFormPreSubmit(targetClass: any): IPreSubmitMetadata | undefined {\r\n return Reflect.getMetadata('form:presubmit', targetClass)\r\n}\r\n\r\nexport interface IFieldMetadata<T = any> {\r\n name: keyof T | string\r\n label?: string\r\n placeholder?: string\r\n default?: any\r\n type?: any\r\n size?: Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>>\r\n visible?: boolean | ((data?: T) => boolean)\r\n disabled?: boolean | ((data?: T) => boolean)\r\n renderInput?: ComponentType<IFormInputBase<T>>\r\n}\r\n\r\nexport function formField(options: Omit<IFieldMetadata, 'name'>) {\r\n return function (target: any, propertyKey: string) {\r\n const designType = Reflect.getMetadata('design:type', target, propertyKey)\r\n const actualType = options.type || designType\r\n const existing: IFieldMetadata[] = Reflect.getMetadata('form:fields', target.constructor) || []\r\n const fields = [...existing]\r\n fields.push({ name: propertyKey, type: actualType, label: options.label || propertyKey, ...options })\r\n Reflect.defineMetadata('form:fields', fields, target.constructor)\r\n }\r\n}\r\n\r\nexport const getFormFields = (targetClass: any): IFieldMetadata[] => {\r\n return Reflect.getMetadata('form:fields', targetClass) || []\r\n}\r\n\r\nexport interface IValidationMetadata extends IConfigValue {\r\n name: string\r\n}\r\n\r\nexport function formValidate(options: Omit<IValidationMetadata, 'name'>) {\r\n return function (target: any, propertyKey: string) {\r\n const existing: IValidationMetadata[] = Reflect.getMetadata('form:validators', target.constructor) || []\r\n const validators = [...existing]\r\n validators.push({ name: propertyKey, ...options })\r\n Reflect.defineMetadata('form:validators', validators, target.constructor)\r\n }\r\n}\r\n\r\nexport function getFormValidators<T = any>(targetClass: any): IFormValidatorConfig<T> {\r\n const metas: IValidationMetadata[] = Reflect.getMetadata('form:validators', targetClass) || []\r\n return metas.reduce<IFormValidatorConfig<T>>((acc, curr) => {\r\n acc[curr.name as keyof T] = { Rules: curr.Rules, label: curr.label }\r\n return acc\r\n }, {})\r\n}\r\n"],"names":["ClassRegistry","Map","registerForm","name","constructor","key","set","RegisteredClass","_constructor","_this","_classCallCheck","_len","arguments","length","args","Array","_key","_callSuper","this","concat","_defineProperty","__class","_inherits","_createClass","Object","defineProperty","value","isFormRegistered","target","ctor","has","formPreSubmit","handler","Reflect","defineMetadata","getFormPreSubmit","targetClass","getMetadata","formField","options","propertyKey","designType","actualType","type","existing","fields","_toConsumableArray","push","_objectSpread","label","getFormFields","formValidate","validators","getFormValidators","reduce","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,QAAQI,YAAY,cAAeT,EAAOxB,cAAgB,GACvFyC,EAAMC,EAAOF,GACnBC,EAAOE,KAAIC,EAAA,CAAG7C,KAAMqC,EAAaG,KAAMD,EAAYO,MAAOV,EAAQU,OAAST,GAAgBD,IAC3FN,QAAQC,eAAe,cAAeW,EAAQjB,EAAOxB,YACtD,CACH,KAEa8C,EAAgB,SAACd,GAC5B,OAAOH,QAAQI,YAAY,cAAeD,IAAgB,EAC5D,EAMM,SAAUe,EAAaZ,GAC3B,OAAO,SAAUX,EAAaY,GAC5B,IAAMI,EAAkCX,QAAQI,YAAY,kBAAmBT,EAAOxB,cAAgB,GAChGgD,EAAUN,EAAOF,GACvBQ,EAAWL,KAAIC,EAAA,CAAG7C,KAAMqC,GAAgBD,IACxCN,QAAQC,eAAe,kBAAmBkB,EAAYxB,EAAOxB,YAC9D,CACH,CAEM,SAAUiD,EAA2BjB,GAEzC,OADqCH,QAAQI,YAAY,kBAAmBD,IAAgB,IAC/EkB,OAAgC,SAACC,EAAKC,GAEjD,OADAD,EAAIC,EAAKrD,MAAmB,CAAEsD,MAAOD,EAAKC,MAAOR,MAAOO,EAAKP,OACtDM,CACR,EAAE,GACL"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component } from 'react';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
|
-
import type { TooltipProps } from '@mui/material';
|
|
3
|
+
import type { BoxProps, TooltipProps } from '@mui/material';
|
|
4
4
|
export interface IRichTooltipPanelConfig {
|
|
5
5
|
title: ReactNode;
|
|
6
6
|
content: ReactNode;
|
|
@@ -11,6 +11,7 @@ export interface IRichTooltipProps {
|
|
|
11
11
|
children: React.ReactNode;
|
|
12
12
|
slots?: {
|
|
13
13
|
tooltipProps?: Partial<TooltipProps>;
|
|
14
|
+
wrapperProps?: BoxProps;
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
export declare class RichTooltip extends Component<IRichTooltipProps> {
|
|
@@ -33,6 +33,8 @@ export interface IFieldMetadata<T = any> {
|
|
|
33
33
|
default?: any;
|
|
34
34
|
type?: any;
|
|
35
35
|
size?: Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>>;
|
|
36
|
+
visible?: boolean | ((data?: T) => boolean);
|
|
37
|
+
disabled?: boolean | ((data?: T) => boolean);
|
|
36
38
|
renderInput?: ComponentType<IFormInputBase<T>>;
|
|
37
39
|
}
|
|
38
40
|
export declare function formField(options: Omit<IFieldMetadata, 'name'>): (target: any, propertyKey: string) => void;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ComponentType, FC } from 'react';
|
|
2
|
+
import { BoxProps } from '@mui/material';
|
|
2
3
|
import { IFormInputBase } from './types';
|
|
3
4
|
import { IPartialError } from './validator';
|
|
5
|
+
import { IFormBaseSlots } from './create.form-base';
|
|
4
6
|
export interface IDecoratorFieldProps<T = any> extends IFormInputBase<T> {
|
|
5
7
|
type?: any;
|
|
8
|
+
visible?: boolean | ((data: T) => boolean);
|
|
6
9
|
renderInput?: ComponentType<IFormInputBase<T>>;
|
|
7
10
|
}
|
|
8
11
|
export declare const DecoratorField: FC<IDecoratorFieldProps>;
|
|
@@ -10,15 +13,19 @@ export interface IDecoratorFormSlots {
|
|
|
10
13
|
bottom?: React.ReactNode;
|
|
11
14
|
isFooter?: React.ReactNode | boolean;
|
|
12
15
|
renderSubmitButton?: () => React.ReactNode;
|
|
16
|
+
formBase?: IFormBaseSlots;
|
|
17
|
+
footerProps?: BoxProps & {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
13
20
|
}
|
|
14
21
|
export interface IDecoratorFormProps<T = any> {
|
|
15
22
|
configClass: any;
|
|
16
|
-
data?:
|
|
17
|
-
onSubmit?: (data:
|
|
23
|
+
data?: Partial<T>;
|
|
24
|
+
onSubmit?: (data: Partial<T>, signal?: AbortSignal) => Promise<void>;
|
|
18
25
|
onError?: (error: any) => void;
|
|
19
26
|
onSubmitError?: (error: IPartialError<T>) => void;
|
|
20
27
|
slots?: IDecoratorFormSlots;
|
|
21
28
|
}
|
|
22
29
|
export declare const DecoratorForm: FC<IDecoratorFormProps>;
|
|
23
30
|
export default DecoratorForm;
|
|
24
|
-
export declare const createDecoratorForm: <T>(configClass: any, params?: Partial<Omit<IDecoratorFormProps
|
|
31
|
+
export declare const createDecoratorForm: <T>(configClass: any, params?: Partial<Omit<IDecoratorFormProps<T>, "configClass">> | undefined) => ComponentType<Omit<IDecoratorFormProps<T>, "configClass">>;
|
|
@@ -19,7 +19,7 @@ declare class DinoFormBase {
|
|
|
19
19
|
createFormComfirm: <T = any>(param?: import("./create.form-comfirm").IFormComfirmParam<T> | undefined) => import("react").ComponentType<import("react").PropsWithChildren<import("./create.form-comfirm").IFormComfirmProps<T>>>;
|
|
20
20
|
createFormGridLayout: <T>(params: import("./create.form-grid-layout").IFormGridLayoutParams<T>) => import("react").ComponentType<import("./create.form-grid-layout").IFormGridLayoutProps<T>>;
|
|
21
21
|
DecoratorForm: import("react").FC<import("./decorator.form").IDecoratorFormProps<any>>;
|
|
22
|
-
createDecoratorForm: <T>(configClass: any, params?: Partial<Omit<import("./decorator.form").IDecoratorFormProps<
|
|
22
|
+
createDecoratorForm: <T>(configClass: any, params?: Partial<Omit<import("./decorator.form").IDecoratorFormProps<T>, "configClass">> | undefined) => import("react").ComponentType<Omit<import("./decorator.form").IDecoratorFormProps<T>, "configClass">>;
|
|
23
23
|
createColorPicker: typeof createColorPicker;
|
|
24
24
|
createDateExpired: typeof CreateDateExpired;
|
|
25
25
|
createDatePicker: <T extends Object>(params?: import("./create.date-picker").IDatePickerSlots | undefined) => import("react").ComponentType<import("./create.date-picker").IDatePickerProps<T>>;
|