dinocollab-core 2.1.22 → 2.1.23
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/form/index.js +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 +1 -1
- package/dist/src/form/decorator.js.map +1 -1
- package/dist/types/form/decorator.d.ts +14 -0
- package/dist/types/form/decorator.form.d.ts +5 -1
- package/dist/types/form/dino-form.d.ts +2 -2
- package/package.json +1 -1
package/dist/form/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{default as FormValidator,SingleRuleValidate,createFormValidator,mapRuleOptions}from"../src/form/validator.js";export{default as DinoForm}from"../src/form/dino-form.js";export{convertFormDataToJson,getErrorMessage,validateCsvModel}from"../src/form/helpers.js";export{formField,formPreSubmit,formValidate,getFormFields,getFormPreSubmit,getFormValidators,registerForm}from"../src/form/decorator.js";export{DecoratorField,DecoratorForm,createDecoratorForm}from"../src/form/decorator.form.js";
|
|
1
|
+
export{default as FormValidator,SingleRuleValidate,createFormValidator,mapRuleOptions}from"../src/form/validator.js";export{default as DinoForm}from"../src/form/dino-form.js";export{convertFormDataToJson,getErrorMessage,validateCsvModel}from"../src/form/helpers.js";export{formField,formPreSubmit,formValidate,getFormFields,getFormPreSubmit,getFormValidators,isFormRegistered,registerForm}from"../src/form/decorator.js";export{DecoratorField,DecoratorForm,createDecoratorForm}from"../src/form/decorator.form.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{objectSpread2 as r,asyncToGenerator as e,objectWithoutProperties as
|
|
1
|
+
import{objectSpread2 as r,asyncToGenerator as e,objectWithoutProperties as n,regenerator as o}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as t,jsx as a}from"react/jsx-runtime";import{Box as i,Typography as s,Grid as l,Button as u}from"@mui/material";import{getErrorMessage as d}from"./helpers.js";import{getFormFields as c,getFormValidators as m,getFormPreSubmit as f,isFormRegistered as p}from"./decorator.js";import v from"./validator.js";import b from"./create.input.js";import g from"./create.form-base.js";var h=["type","renderInput"],y=g({}),S=b({}),x=function(e){var o,i,s=e.type,l=e.renderInput,u=n(e,h),c=(null===(o=u.name)||void 0===o?void 0:o.toString())||"",m=(null===(i=u.data)||void 0===i?void 0:i[c])||u.defaultValue;return l?a(l,r({},u)):y.mapContext((function(e){var n=e.messageErrors,o=e.onBlur,i=d(e.messageErrors,u.name);switch(s){case String:return a(S,r(r({},u),{},{messageErrors:n,onBlur:o}));case Number:return a(S,r({slots:{textFieldProps:{type:"number"}},messageErrors:n,onBlur:o},u));case Boolean:return t("div",{children:[t("label",{children:[u.label||c,": "]}),a("input",{name:c,type:"checkbox",defaultChecked:m}),a("span",{style:{color:"red"},children:i.error?i.message:""})]});default:return t("div",{children:["Unsupported field type for ",c]})}}))},j=function(n){var d,b=c(n.configClass),g=m(n.configClass),h=f(n.configClass);if(!p(n.configClass)){var S,j=(null===(S=n.configClass)||void 0===S?void 0:S.name)||"Unknown";return t(i,{sx:{border:"1px dashed #ccc",padding:12,borderRadius:4,color:"#333",background:"#fafafa"},children:[a(s,{variant:"subtitle1",sx:{fontWeight:600,marginBottom:6},children:"Form configuration not registered"}),t(s,{variant:"body1",children:['Configuration for "',j,'" was not found. Did you forget to add ',a("code",{children:"@registerForm"})," to the class?"]})]})}var C,B,E=function(){var r=e(o().m((function r(e){var t,a;return o().w((function(r){for(;;)switch(r.n){case 0:if(t=e,r.p=1,null==h||!h.handler){r.n=3;break}return r.n=2,h.handler(e,n.data);case 2:null==(t=r.v)&&(t=e);case 3:if(!n.onSubmit){r.n=4;break}return r.n=4,n.onSubmit(t);case 4:r.n=6;break;case 5:throw r.p=5,a=r.v,n.onError&&n.onError(a),a;case 6:return r.a(2)}}),r,null,[[1,5]])})));return function(e){return r.apply(this,arguments)}}();return t(y.Form,{onSubmit:E,validate:new v(g),onError:n.onSubmitError,children:[a(l,{container:!0,spacing:2,children:b.map((function(e){return a(l,r(r({item:!0,xs:12},e.size),{},{children:a(x,r({data:n.data},e))}),e.name.toString())}))}),!1===(null===(C=n.slots)||void 0===C?void 0:C.isFooter)?null:null!==(B=n.slots)&&void 0!==B&&B.renderSubmitButton?n.slots.renderSubmitButton():a(u,{variant:"contained",color:"primary",type:"submit",sx:{mt:2},children:"Submit"}),null===(d=n.slots)||void 0===d?void 0:d.bottom]})},C=function(e,n){return function(o){return a(j,r(r({configClass:e},n),o))}};export{x as DecoratorField,j as DecoratorForm,C as createDecoratorForm,j 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 { Button, Grid } from '@mui/material'\r\nimport { IFormInputBase } from './types'\r\nimport { getErrorMessage } from './helpers'\r\nimport { getFormFields, getFormPreSubmit, getFormValidators } from './decorator'\r\nimport FormValidator 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 if (renderInput) {\r\n const InputComp = renderInput\r\n return <InputComp {...props} />\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 switch (inputType) {\r\n case String:\r\n return <InputInstance {...props} messageErrors={messageErrors} onBlur={onBlur} />\r\n case Number:\r\n return <InputInstance slots={{ textFieldProps: { type: 'number' } }} messageErrors={messageErrors} onBlur={onBlur} {...props} />\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 renderSubmitButton?: () => React.ReactNode\r\n}\r\n\r\nexport interface IDecoratorFormProps {\r\n configClass: any\r\n data?: any\r\n onSubmit?: (data: any) => Promise<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 const handleSubmit = async (data: any) => {\r\n let processedData = data\r\n\r\n
|
|
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 if (renderInput) {\r\n const InputComp = renderInput\r\n return <InputComp {...props} />\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 switch (inputType) {\r\n case String:\r\n return <InputInstance {...props} messageErrors={messageErrors} onBlur={onBlur} />\r\n case Number:\r\n return <InputInstance slots={{ textFieldProps: { type: 'number' } }} messageErrors={messageErrors} onBlur={onBlur} {...props} />\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","_jsx","_objectSpread","mapContext","context","messageErrors","onBlur","err","getErrorMessage","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","n","p","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,aACjD,OAAIN,EAEKQ,EADWR,EACDS,EAAKR,CAAAA,EAAAA,IAEjBX,EAASoB,YAAW,SAACC,GAC1B,IAAQC,EAA0BD,EAA1BC,cAAeC,EAAWF,EAAXE,OACjBC,EAAMC,EAAgBJ,EAAQC,cAAeX,EAAMG,MACzD,OAAQN,GACN,KAAKkB,OACH,OAAOR,EAAChB,EAAaiB,EAAAA,KAAKR,GAAK,GAAA,CAAEW,cAAeA,EAAeC,OAAQA,KACzE,KAAKI,OACH,OAAOT,EAAChB,EAAaiB,EAAA,CAACS,MAAO,CAAEC,eAAgB,CAAEpB,KAAM,WAAca,cAAeA,EAAeC,OAAQA,GAAYZ,IACzH,KAAKmB,QACH,OACEC,mBACEA,EAAQ,QAAA,CAAAC,SAAA,CAAArB,EAAMsB,OAASnB,EAAI,QAC3BI,EAAA,QAAA,CAAOJ,KAAMA,EAAML,KAAK,WAAWyB,eAAgBlB,IACnDE,UAAMiB,MAAO,CA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
|
|
1
|
-
import{toConsumableArray as e,objectSpread2 as t,inherits as
|
|
1
|
+
import{toConsumableArray as e,objectSpread2 as t,inherits as r,createClass as a,classCallCheck as n,callSuper as o,defineProperty as u}from"../../_virtual/_rollupPluginBabelHelpers.js";import"../../_virtual/Reflect.js";var c=new Map;function l(e){return function(t){var l=e||t.name;c.set(l,t);var f=function(e){function t(){var e;n(this,t);for(var r=arguments.length,a=new Array(r),c=0;c<r;c++)a[c]=arguments[c];return e=o(this,t,[].concat(a)),u(e,"__class",l),e.__class=l,e}return r(t,e),a(t)}(t);return Object.defineProperty(f,"name",{value:t.name}),Object.defineProperty(f,"__class",{value:l}),f}}function f(e){if(!e)return!1;var t="function"==typeof e?e:null==e?void 0:e.constructor;if(!t)return!1;var r=t.__class||t.name;return!!r&&c.has(r)}function s(e){return function(t){return Reflect.defineMetadata("form:presubmit",{handler:e},t),t}}function i(e){return Reflect.getMetadata("form:presubmit",e)}function d(r){return function(a,n){var o=Reflect.getMetadata("design:type",a,n),u=r.type||o,c=Reflect.getMetadata("form:fields",a.constructor)||[],l=e(c);l.push(t({name:n,type:u,label:r.label||n},r)),Reflect.defineMetadata("form:fields",l,a.constructor)}}var m=function(e){return Reflect.getMetadata("form:fields",e)||[]};function p(r){return function(a,n){var o=Reflect.getMetadata("form:validators",a.constructor)||[],u=e(o);u.push(t({name:n},r)),Reflect.defineMetadata("form:validators",u,a.constructor)}}function v(e){return(Reflect.getMetadata("form:validators",e)||[]).reduce((function(e,t){return e[t.name]={Rules:t.Rules,label:t.label},e}),{})}export{d as formField,s as formPreSubmit,p as formValidate,m as getFormFields,i as getFormPreSubmit,v as getFormValidators,f as isFormRegistered,l as registerForm};
|
|
2
2
|
//# sourceMappingURL=decorator.js.map
|
|
@@ -1 +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\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","formPreSubmit","handler","Reflect","defineMetadata","getFormPreSubmit","targetClass","getMetadata","formField","options","
|
|
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,EAL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,CACH,CAEM,SAAUiD,EAA2BjB,GAEzC,OADqCH,QAAQI,YAAY,kBAAmBD,IAAgB,IAC/EkB,QAAgC,SAACC,EAAKC,GAEjD,OADAD,EAAIC,EAAKrD,MAAmB,CAAEsD,MAAOD,EAAKC,MAAOR,MAAOO,EAAKP,OACtDM,CACR,GAAE,GACL"}
|
|
@@ -7,6 +7,20 @@ export declare function registerForm(name?: string): <T extends new (...args: an
|
|
|
7
7
|
__class: string;
|
|
8
8
|
};
|
|
9
9
|
} & T;
|
|
10
|
+
/**
|
|
11
|
+
* Check whether a class (constructor) or an instance has been registered
|
|
12
|
+
* with the @registerForm decorator.
|
|
13
|
+
*
|
|
14
|
+
* Accepts:
|
|
15
|
+
* - the decorated constructor (function)
|
|
16
|
+
* - the original constructor (function)
|
|
17
|
+
* - an instance of the class
|
|
18
|
+
*
|
|
19
|
+
* Returns true when the underlying registry contains an entry for the
|
|
20
|
+
* class key (either the custom name provided to the decorator or the
|
|
21
|
+
* constructor name).
|
|
22
|
+
*/
|
|
23
|
+
export declare function isFormRegistered(target: any): boolean;
|
|
10
24
|
export interface IPreSubmitMetadata<T = any> {
|
|
11
25
|
handler: (data: T, oldData: T) => Promise<any> | any;
|
|
12
26
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentType, FC } from 'react';
|
|
2
2
|
import { IFormInputBase } from './types';
|
|
3
|
+
import { IPartialError } from './validator';
|
|
3
4
|
export interface IDecoratorFieldProps<T = any> extends IFormInputBase<T> {
|
|
4
5
|
type?: any;
|
|
5
6
|
renderInput?: ComponentType<IFormInputBase<T>>;
|
|
@@ -7,12 +8,15 @@ export interface IDecoratorFieldProps<T = any> extends IFormInputBase<T> {
|
|
|
7
8
|
export declare const DecoratorField: FC<IDecoratorFieldProps>;
|
|
8
9
|
export interface IDecoratorFormSlots {
|
|
9
10
|
bottom?: React.ReactNode;
|
|
11
|
+
isFooter?: React.ReactNode | boolean;
|
|
10
12
|
renderSubmitButton?: () => React.ReactNode;
|
|
11
13
|
}
|
|
12
|
-
export interface IDecoratorFormProps {
|
|
14
|
+
export interface IDecoratorFormProps<T = any> {
|
|
13
15
|
configClass: any;
|
|
14
16
|
data?: any;
|
|
15
17
|
onSubmit?: (data: any) => Promise<void>;
|
|
18
|
+
onError?: (error: any) => void;
|
|
19
|
+
onSubmitError?: (error: IPartialError<T>) => void;
|
|
16
20
|
slots?: IDecoratorFormSlots;
|
|
17
21
|
}
|
|
18
22
|
export declare const DecoratorForm: FC<IDecoratorFormProps>;
|
|
@@ -18,8 +18,8 @@ declare class DinoFormBase {
|
|
|
18
18
|
createFormBase: <T>(params?: import("./create.form-base").IFormBaseParams<T> | undefined) => import("./create.form-base").IFormBaseResult<T>;
|
|
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
|
-
DecoratorForm: import("react").FC<import("./decorator.form").IDecoratorFormProps
|
|
22
|
-
createDecoratorForm: <T>(configClass: any, params?: Partial<Omit<import("./decorator.form").IDecoratorFormProps
|
|
21
|
+
DecoratorForm: import("react").FC<import("./decorator.form").IDecoratorFormProps<any>>;
|
|
22
|
+
createDecoratorForm: <T>(configClass: any, params?: Partial<Omit<import("./decorator.form").IDecoratorFormProps<any>, "configClass">> | undefined) => import("react").ComponentType<Omit<import("./decorator.form").IDecoratorFormProps<any>, "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>>;
|