@mage-ui/components 1.0.103 → 1.0.104

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.
@@ -143,6 +143,7 @@ declare const Form: {
143
143
  name,
144
144
  error,
145
145
  defaultValue,
146
+ onChange,
146
147
  ...props
147
148
  }: FormAutocompleteProps): react_jsx_runtime0.JSX.Element;
148
149
  displayName: string;
@@ -6,6 +6,7 @@ type FormAutocompleteProps = Omit<AutocompleteProps, 'onChange' | 'defaultValue'
6
6
  error?: string;
7
7
  isSubmitting?: boolean;
8
8
  defaultValue?: DropdownValue;
9
+ onChange?: (value: DropdownValue) => void;
9
10
  };
10
11
  //#endregion
11
12
  export { FormAutocompleteProps };
@@ -1 +1 @@
1
- {"version":3,"file":"FormAutocomplete.d.mts","names":[],"sources":["../../../../src/components/forms/controls/FormAutocomplete.tsx"],"mappings":";;;KAQY,qBAAA,GAAwB,IAAA,CAClC,iBAAA;EAGA,KAAA;EACA,KAAA;EACA,YAAA;EACA,YAAA,GAAe,aAAA;AAAA"}
1
+ {"version":3,"file":"FormAutocomplete.d.mts","names":[],"sources":["../../../../src/components/forms/controls/FormAutocomplete.tsx"],"mappings":";;;KAQY,qBAAA,GAAwB,IAAA,CAClC,iBAAA;EAGA,KAAA;EACA,KAAA;EACA,YAAA;EACA,YAAA,GAAe,aAAA;EACf,QAAA,IAAY,KAAA,EAAO,aAAA;AAAA"}
@@ -1,2 +1,2 @@
1
- import{Autocomplete as e}from"../../controls/dropdown/autocomplete/Autocomplete.mjs";import{jsx as t}from"react/jsx-runtime";import{Controller as n}from"react-hook-form";const r=({$rule:r,isSubmitting:i,name:a,error:o,defaultValue:s,...c})=>t(n,{name:a,...s===void 0?{}:{defaultValue:s},render:({field:{onChange:n,value:r}})=>t(e,{name:a,error:o,value:r,...c,onChange:n})});r.displayName=`Form.Autocomplete`;export{r as FormAutocomplete};
1
+ import{Autocomplete as e}from"../../controls/dropdown/autocomplete/Autocomplete.mjs";import{jsx as t}from"react/jsx-runtime";import{Controller as n}from"react-hook-form";const r=({$rule:r,isSubmitting:i,name:a,error:o,defaultValue:s,onChange:c,...l})=>t(n,{name:a,...s===void 0?{}:{defaultValue:s},render:({field:{onChange:n,value:r}})=>t(e,{name:a,error:o,value:r,...l,onChange:e=>{n(e),c?.(e)}})});r.displayName=`Form.Autocomplete`;export{r as FormAutocomplete};
2
2
  //# sourceMappingURL=FormAutocomplete.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormAutocomplete.mjs","names":[],"sources":["../../../../src/components/forms/controls/FormAutocomplete.tsx"],"sourcesContent":["import { Controller } from 'react-hook-form';\n\nimport {\n Autocomplete,\n type AutocompleteProps,\n} from '@/components/controls/dropdown/autocomplete/Autocomplete';\nimport type { DropdownValue } from '@/components/controls/dropdown/DropdownContextProvider';\n\nexport type FormAutocompleteProps = Omit<\n AutocompleteProps,\n 'onChange' | 'defaultValue' | 'value'\n> & {\n $rule?: string;\n error?: string;\n isSubmitting?: boolean;\n defaultValue?: DropdownValue;\n};\n\nexport const FormAutocomplete = ({\n $rule,\n isSubmitting: _isSubmitting,\n name,\n error,\n defaultValue,\n ...props\n}: FormAutocompleteProps) => {\n const controllerProps = defaultValue === undefined ? {} : { defaultValue };\n\n return (\n <Controller\n name={name}\n {...controllerProps}\n render={({ field: { onChange, value } }) => (\n <Autocomplete\n name={name}\n error={error}\n value={value}\n {...props}\n onChange={onChange}\n />\n )}\n />\n );\n};\n\nFormAutocomplete.displayName = 'Form.Autocomplete';\n"],"mappings":"0KAkBA,MAAa,GAAoB,CAC/B,QACA,aAAc,EACd,OACA,QACA,eACA,GAAG,KAKD,EAAC,EAAD,CACQ,OACN,GALoB,IAAiB,IAAA,GAAY,EAAE,CAAG,CAAE,eAAc,CAMtE,QAAS,CAAE,MAAO,CAAE,WAAU,YAC5B,EAAC,EAAD,CACQ,OACC,QACA,QACP,GAAI,EACM,WACV,CAAA,CAEJ,CAAA,CAIN,EAAiB,YAAc"}
1
+ {"version":3,"file":"FormAutocomplete.mjs","names":[],"sources":["../../../../src/components/forms/controls/FormAutocomplete.tsx"],"sourcesContent":["import { Controller } from 'react-hook-form';\n\nimport {\n Autocomplete,\n type AutocompleteProps,\n} from '@/components/controls/dropdown/autocomplete/Autocomplete';\nimport type { DropdownValue } from '@/components/controls/dropdown/DropdownContextProvider';\n\nexport type FormAutocompleteProps = Omit<\n AutocompleteProps,\n 'onChange' | 'defaultValue' | 'value'\n> & {\n $rule?: string;\n error?: string;\n isSubmitting?: boolean;\n defaultValue?: DropdownValue;\n onChange?: (value: DropdownValue) => void;\n};\n\nexport const FormAutocomplete = ({\n $rule,\n isSubmitting: _isSubmitting,\n name,\n error,\n defaultValue,\n onChange,\n ...props\n}: FormAutocompleteProps) => {\n const controllerProps = defaultValue === undefined ? {} : { defaultValue };\n\n return (\n <Controller\n name={name}\n {...controllerProps}\n render={({ field: { onChange: fieldOnChange, value } }) => (\n <Autocomplete\n name={name}\n error={error}\n value={value}\n {...props}\n onChange={(val) => {\n fieldOnChange(val);\n onChange?.(val);\n }}\n />\n )}\n />\n );\n};\n\nFormAutocomplete.displayName = 'Form.Autocomplete';\n"],"mappings":"0KAmBA,MAAa,GAAoB,CAC/B,QACA,aAAc,EACd,OACA,QACA,eACA,WACA,GAAG,KAKD,EAAC,EAAD,CACQ,OACN,GALoB,IAAiB,IAAA,GAAY,EAAE,CAAG,CAAE,eAAc,CAMtE,QAAS,CAAE,MAAO,CAAE,SAAU,EAAe,YAC3C,EAAC,EAAD,CACQ,OACC,QACA,QACP,GAAI,EACJ,SAAW,GAAQ,CACjB,EAAc,EAAI,CAClB,IAAW,EAAI,EAEjB,CAAA,CAEJ,CAAA,CAIN,EAAiB,YAAc"}
@@ -1,2 +1,2 @@
1
- import{findFormComponents as e}from"../controls/find-form-components.mjs";import{PASSWORD_RULES as t}from"./password-rules.mjs";import n from"./password.mjs";import{parseRules as r}from"./zod.mjs";import{z as i}from"zod";const a=(e,t)=>{if(!e.name||!e.$rule?.includes(`confirmed`))return;let n=e.$rule.split(`|`).find(e=>e.startsWith(`confirmed`)),r=n?.includes(`:`)?n.split(`:`)[1]:`${e.name}_confirmation`;t.confirmedFields.push({field:e.name,target:r})},o=(e,t)=>{e.name&&(e.$rule?.includes(`required`)?(t.rules[e.name]=i.boolean().optional().or(i.literal(!1)),t.requiredBooleanFields.push(e.name)):t.rules[e.name]=i.boolean().optional())},s=(e,a)=>{if(!e.name)return;let o=i.string(),s=e.$rule?e.$rule.split(`|`).filter(e=>e.trim()!==`password`).join(`|`):``;s&&(o=r(s));let c=e.rules||(e.$rule?.includes(`password`)?t:[]);c.length>0&&(o=n(o,c));let l=!e.$rule||e.$rule.includes(`optional`)||s.includes(`optional`);a.rules[e.name]=l?o.optional():o},c=(e,t)=>{e.name&&(t.rules[e.name]=e.$rule?r(e.$rule):i.string().optional())},l=(e,t)=>{e.name&&(t.rules[e.name]=i.any().optional())},u=(e,t)=>t.confirmedFields.length===0&&t.requiredBooleanFields.length===0?e:e.superRefine((e,n)=>{t.confirmedFields.forEach(({field:t,target:r})=>{e[t]!==e[r]&&n.addIssue({code:i.ZodIssueCode.custom,message:JSON.stringify({key:`confirmed`,fallback:`La confirmación no coincide.`,bindings:{}}),path:[r]})}),t.requiredBooleanFields.forEach(t=>{e[t]!==!0&&n.addIssue({code:i.ZodIssueCode.custom,message:JSON.stringify({key:`required`,fallback:`El campo {attribute} es obligatorio.`,bindings:{}}),path:[t]})})}),d=(t,n)=>{let r={rules:{},confirmedFields:[],requiredBooleanFields:[]};return e(t,n).forEach(e=>{let t=e.props,n=e.type.displayName;t.name&&(a(t,r),n===`Form.Checkbox`?o(t,r):n===`Form.Password`?s(t,r):n===`Form.Select`||n===`Form.Combobox`||n===`Form.Autocomplete`?l(t,r):c(t,r))}),u(i.object(r.rules),r)};export{d as extractFormRules};
1
+ import{findFormComponents as e}from"../controls/find-form-components.mjs";import{PASSWORD_RULES as t}from"./password-rules.mjs";import n from"./password.mjs";import{parseRules as r}from"./zod.mjs";import{z as i}from"zod";const a=(e,t)=>{if(!e.name||!e.$rule?.includes(`confirmed`))return;let n=e.$rule.split(`|`).find(e=>e.startsWith(`confirmed`)),r=n?.includes(`:`)?n.split(`:`)[1]:`${e.name}_confirmation`;t.confirmedFields.push({field:e.name,target:r})},o=(e,t)=>{e.name&&(e.$rule?.includes(`required`)?(t.rules[e.name]=i.boolean().optional().or(i.literal(!1)),t.requiredBooleanFields.push(e.name)):t.rules[e.name]=i.boolean().optional())},s=(e,a)=>{if(!e.name)return;let o=i.string(),s=e.$rule?e.$rule.split(`|`).filter(e=>e.trim()!==`password`).join(`|`):``;s&&(o=r(s));let c=e.rules||(e.$rule?.includes(`password`)?t:[]);c.length>0&&(o=n(o,c));let l=!e.$rule||e.$rule.includes(`optional`)||s.includes(`optional`);a.rules[e.name]=l?o.optional():o},c=(e,t)=>{e.name&&(t.rules[e.name]=e.$rule?r(e.$rule):i.string().optional())},l=(e,t)=>{e.name&&(t.rules[e.name]=i.any().optional())},u=(e,t)=>t.confirmedFields.length===0&&t.requiredBooleanFields.length===0?e:e.superRefine((e,n)=>{t.confirmedFields.forEach(({field:t,target:r})=>{e[t]!==e[r]&&n.addIssue({code:i.ZodIssueCode.custom,message:JSON.stringify({key:`confirmed`,fallback:`La confirmación no coincide.`,bindings:{}}),path:[r]})}),t.requiredBooleanFields.forEach(t=>{e[t]!==!0&&n.addIssue({code:i.ZodIssueCode.custom,message:JSON.stringify({key:`required`,fallback:`El campo {attribute} es obligatorio.`,bindings:{}}),path:[t]})})}),d=(t,n)=>{let r={rules:{},confirmedFields:[],requiredBooleanFields:[]};return e(t,n).forEach(e=>{let t=e.props,n=e.type.displayName;t.name&&(a(t,r),n===`Form.Checkbox`?o(t,r):n===`Form.Password`?s(t,r):n===`Form.Select`||n===`Form.Combobox`||n===`Form.Autocomplete`?l(t,r):c(t,r))}),u(i.object(r.rules).loose(),r)};export{d as extractFormRules};
2
2
  //# sourceMappingURL=extract-form-rules.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-form-rules.mjs","names":["passwordRule"],"sources":["../../../../src/components/forms/rules/extract-form-rules.ts"],"sourcesContent":["import type React from 'react';\nimport type { FieldValues } from 'react-hook-form';\nimport { type ZodTypeAny, z } from 'zod';\n\nimport type { PasswordRuleDefinition } from '@/components/controls/password-input/usePasswordRules';\n\nimport { findFormComponents } from '../controls/find-form-components';\nimport passwordRule from './password';\nimport { PASSWORD_RULES } from './password-rules';\nimport { parseRules } from './zod';\n\ntype FormRuleContext = {\n rules: Record<string, ZodTypeAny>;\n confirmedFields: { field: string; target: string }[];\n requiredBooleanFields: string[];\n};\n\ntype ComponentProps = {\n name?: string;\n $rule?: string;\n rules?: PasswordRuleDefinition[];\n};\n\nconst processConfirmedRule = (\n props: ComponentProps,\n context: FormRuleContext,\n) => {\n if (!props.name || !props.$rule?.includes('confirmed')) return;\n\n const rulesList = props.$rule.split('|');\n const confirmedRule = rulesList.find((r) => r.startsWith('confirmed'));\n const target = confirmedRule?.includes(':')\n ? confirmedRule.split(':')[1]\n : `${props.name}_confirmation`;\n\n context.confirmedFields.push({ field: props.name, target });\n};\n\nconst processCheckbox = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n\n if (props.$rule?.includes('required')) {\n context.rules[props.name] = z.boolean().optional().or(z.literal(false));\n context.requiredBooleanFields.push(props.name);\n } else {\n context.rules[props.name] = z.boolean().optional();\n }\n};\n\nconst processPassword = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n\n let baseSchema: ZodTypeAny = z.string();\n const otherRules = props.$rule\n ? props.$rule\n .split('|')\n .filter((r) => r.trim() !== 'password')\n .join('|')\n : '';\n\n if (otherRules) {\n baseSchema = parseRules(otherRules);\n }\n\n const passwordRules =\n props.rules || (props.$rule?.includes('password') ? PASSWORD_RULES : []);\n\n if (passwordRules.length > 0) {\n baseSchema = passwordRule(baseSchema, passwordRules);\n }\n\n const isOptional =\n !props.$rule ||\n props.$rule.includes('optional') ||\n otherRules.includes('optional');\n\n context.rules[props.name] = isOptional ? baseSchema.optional() : baseSchema;\n};\n\nconst processDefault = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n context.rules[props.name] = props.$rule\n ? parseRules(props.$rule)\n : z.string().optional();\n};\n\nconst processDropdown = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n context.rules[props.name] = z.any().optional();\n};\n\nconst applyRefinements = (\n schema: z.ZodObject<FieldValues>,\n context: FormRuleContext,\n) => {\n if (\n context.confirmedFields.length === 0 &&\n context.requiredBooleanFields.length === 0\n ) {\n return schema;\n }\n\n return schema.superRefine((data, ctx) => {\n context.confirmedFields.forEach(({ field, target }) => {\n if (data[field] !== data[target]) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: JSON.stringify({\n key: 'confirmed',\n fallback: 'La confirmación no coincide.',\n bindings: {},\n }),\n path: [target],\n });\n }\n });\n\n context.requiredBooleanFields.forEach((field) => {\n if (data[field] !== true) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: JSON.stringify({\n key: 'required',\n fallback: 'El campo {attribute} es obligatorio.',\n bindings: {},\n }),\n path: [field],\n });\n }\n });\n });\n};\n\nexport const extractFormRules = (\n children: React.ReactNode,\n componentTypes: React.ComponentType[],\n): ZodTypeAny => {\n const context: FormRuleContext = {\n rules: {},\n confirmedFields: [],\n requiredBooleanFields: [],\n };\n\n const components = findFormComponents(children, componentTypes);\n\n components.forEach((component) => {\n const props = component.props as ComponentProps;\n const displayName = (component.type as { displayName?: string })\n .displayName;\n\n if (props.name) {\n processConfirmedRule(props, context);\n\n if (displayName === 'Form.Checkbox') {\n processCheckbox(props, context);\n } else if (displayName === 'Form.Password') {\n processPassword(props, context);\n } else if (\n displayName === 'Form.Select' ||\n displayName === 'Form.Combobox' ||\n displayName === 'Form.Autocomplete'\n ) {\n processDropdown(props, context);\n } else {\n processDefault(props, context);\n }\n }\n });\n\n return applyRefinements(z.object(context.rules), context);\n};\n"],"m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GAGrB,GAAmB,EAAuB,IAA6B,CACtE,EAAM,OACX,EAAQ,MAAM,EAAM,MAAQ,EAAE,KAAK,CAAC,UAAU,GAG1C,GACJ,EACA,IAGE,EAAQ,gBAAgB,SAAW,GACnC,EAAQ,sBAAsB,SAAW,EAElC,EAGF,EAAO,aAAa,EAAM,IAAQ,CACvC,EAAQ,gBAAgB,SAAS,CAAE,QAAO,YAAa,CACjD,EAAK,KAAW,EAAK,IACvB,EAAI,SAAS,CACX,KAAM,EAAE,aAAa,OACrB,QAAS,KAAK,UAAU,CACtB,IAAK,YACL,SAAU,+BACV,SAAU,EAAE,CACb,CAAC,CACF,KAAM,CAAC,EAAO,CACf,CAAC,EAEJ,CAEF,EAAQ,sBAAsB,QAAS,GAAU,CAC3C,EAAK,KAAW,IAClB,EAAI,SAAS,CACX,KAAM,EAAE,aAAa,OACrB,QAAS,KAAK,UAAU,CACtB,IAAK,WACL,SAAU,uCACV,SAAU,EAAE,CACb,CAAC,CACF,KAAM,CAAC,EAAM,CACd,CAAC,EAEJ,EACF,CAGS,GACX,EACA,IACe,CACf,IAAM,EAA2B,CAC/B,MAAO,EAAE,CACT,gBAAiB,EAAE,CACnB,sBAAuB,EAAE,CAC1B,CA4BD,OA1BmB,EAAmB,EAAU,EAAe,CAEpD,QAAS,GAAc,CAChC,IAAM,EAAQ,EAAU,MAClB,EAAe,EAAU,KAC5B,YAEC,EAAM,OACR,EAAqB,EAAO,EAAQ,CAEhC,IAAgB,gBAClB,EAAgB,EAAO,EAAQ,CACtB,IAAgB,gBACzB,EAAgB,EAAO,EAAQ,CAE/B,IAAgB,eAChB,IAAgB,iBAChB,IAAgB,oBAEhB,EAAgB,EAAO,EAAQ,CAE/B,EAAe,EAAO,EAAQ,GAGlC,CAEK,EAAiB,EAAE,OAAO,EAAQ,MAAM,CAAE,EAAQ"}
1
+ {"version":3,"file":"extract-form-rules.mjs","names":["passwordRule"],"sources":["../../../../src/components/forms/rules/extract-form-rules.ts"],"sourcesContent":["import type React from 'react';\nimport type { FieldValues } from 'react-hook-form';\nimport { type ZodTypeAny, z } from 'zod';\n\nimport type { PasswordRuleDefinition } from '@/components/controls/password-input/usePasswordRules';\n\nimport { findFormComponents } from '../controls/find-form-components';\nimport passwordRule from './password';\nimport { PASSWORD_RULES } from './password-rules';\nimport { parseRules } from './zod';\n\ntype FormRuleContext = {\n rules: Record<string, ZodTypeAny>;\n confirmedFields: { field: string; target: string }[];\n requiredBooleanFields: string[];\n};\n\ntype ComponentProps = {\n name?: string;\n $rule?: string;\n rules?: PasswordRuleDefinition[];\n};\n\nconst processConfirmedRule = (\n props: ComponentProps,\n context: FormRuleContext,\n) => {\n if (!props.name || !props.$rule?.includes('confirmed')) return;\n\n const rulesList = props.$rule.split('|');\n const confirmedRule = rulesList.find((r) => r.startsWith('confirmed'));\n const target = confirmedRule?.includes(':')\n ? confirmedRule.split(':')[1]\n : `${props.name}_confirmation`;\n\n context.confirmedFields.push({ field: props.name, target });\n};\n\nconst processCheckbox = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n\n if (props.$rule?.includes('required')) {\n context.rules[props.name] = z.boolean().optional().or(z.literal(false));\n context.requiredBooleanFields.push(props.name);\n } else {\n context.rules[props.name] = z.boolean().optional();\n }\n};\n\nconst processPassword = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n\n let baseSchema: ZodTypeAny = z.string();\n const otherRules = props.$rule\n ? props.$rule\n .split('|')\n .filter((r) => r.trim() !== 'password')\n .join('|')\n : '';\n\n if (otherRules) {\n baseSchema = parseRules(otherRules);\n }\n\n const passwordRules =\n props.rules || (props.$rule?.includes('password') ? PASSWORD_RULES : []);\n\n if (passwordRules.length > 0) {\n baseSchema = passwordRule(baseSchema, passwordRules);\n }\n\n const isOptional =\n !props.$rule ||\n props.$rule.includes('optional') ||\n otherRules.includes('optional');\n\n context.rules[props.name] = isOptional ? baseSchema.optional() : baseSchema;\n};\n\nconst processDefault = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n context.rules[props.name] = props.$rule\n ? parseRules(props.$rule)\n : z.string().optional();\n};\n\nconst processDropdown = (props: ComponentProps, context: FormRuleContext) => {\n if (!props.name) return;\n context.rules[props.name] = z.any().optional();\n};\n\nconst applyRefinements = (\n schema: z.ZodObject<FieldValues>,\n context: FormRuleContext,\n) => {\n if (\n context.confirmedFields.length === 0 &&\n context.requiredBooleanFields.length === 0\n ) {\n return schema;\n }\n\n return schema.superRefine((data, ctx) => {\n context.confirmedFields.forEach(({ field, target }) => {\n if (data[field] !== data[target]) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: JSON.stringify({\n key: 'confirmed',\n fallback: 'La confirmación no coincide.',\n bindings: {},\n }),\n path: [target],\n });\n }\n });\n\n context.requiredBooleanFields.forEach((field) => {\n if (data[field] !== true) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: JSON.stringify({\n key: 'required',\n fallback: 'El campo {attribute} es obligatorio.',\n bindings: {},\n }),\n path: [field],\n });\n }\n });\n });\n};\n\nexport const extractFormRules = (\n children: React.ReactNode,\n componentTypes: React.ComponentType[],\n): ZodTypeAny => {\n const context: FormRuleContext = {\n rules: {},\n confirmedFields: [],\n requiredBooleanFields: [],\n };\n\n const components = findFormComponents(children, componentTypes);\n\n components.forEach((component) => {\n const props = component.props as ComponentProps;\n const displayName = (component.type as { displayName?: string })\n .displayName;\n\n if (props.name) {\n processConfirmedRule(props, context);\n\n if (displayName === 'Form.Checkbox') {\n processCheckbox(props, context);\n } else if (displayName === 'Form.Password') {\n processPassword(props, context);\n } else if (\n displayName === 'Form.Select' ||\n displayName === 'Form.Combobox' ||\n displayName === 'Form.Autocomplete'\n ) {\n processDropdown(props, context);\n } else {\n processDefault(props, context);\n }\n }\n });\n\n return applyRefinements(z.object(context.rules).loose(), context);\n};\n"],"mappings":"6NAuBA,MAAM,GACJ,EACA,IACG,CACH,GAAI,CAAC,EAAM,MAAQ,CAAC,EAAM,OAAO,SAAS,YAAY,CAA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G1C,GACJ,EACA,IAGE,EAAQ,gBAAgB,SAAW,GACnC,EAAQ,sBAAsB,SAAW,EAElC,EAGF,EAAO,aAAa,EAAM,IAAQ,CACvC,EAAQ,gBAAgB,SAAS,CAAE,QAAO,YAAa,CACjD,EAAK,KAAW,EAAK,IACvB,EAAI,SAAS,CACX,KAAM,EAAE,aAAa,OACrB,QAAS,KAAK,UAAU,CACtB,IAAK,YACL,SAAU,+BACV,SAAU,EAAE,CACb,CAAC,CACF,KAAM,CAAC,EAAO,CACf,CAAC,EAEJ,CAEF,EAAQ,sBAAsB,QAAS,GAAU,CAC3C,EAAK,KAAW,IAClB,EAAI,SAAS,CACX,KAAM,EAAE,aAAa,OACrB,QAAS,KAAK,UAAU,CACtB,IAAK,WACL,SAAU,uCACV,SAAU,EAAE,CACb,CAAC,CACF,KAAM,CAAC,EAAM,CACd,CAAC,EAEJ,EACF,CAGS,GACX,EACA,IACe,CACf,IAAM,EAA2B,CAC/B,MAAO,EAAE,CACT,gBAAiB,EAAE,CACnB,sBAAuB,EAAE,CAC1B,CA4BD,OA1BmB,EAAmB,EAAU,EAAe,CAEpD,QAAS,GAAc,CAChC,IAAM,EAAQ,EAAU,MAClB,EAAe,EAAU,KAC5B,YAEC,EAAM,OACR,EAAqB,EAAO,EAAQ,CAEhC,IAAgB,gBAClB,EAAgB,EAAO,EAAQ,CACtB,IAAgB,gBACzB,EAAgB,EAAO,EAAQ,CAE/B,IAAgB,eAChB,IAAgB,iBAChB,IAAgB,oBAEhB,EAAgB,EAAO,EAAQ,CAE/B,EAAe,EAAO,EAAQ,GAGlC,CAEK,EAAiB,EAAE,OAAO,EAAQ,MAAM,CAAC,OAAO,CAAE,EAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mage-ui/components",
3
- "version": "1.0.103",
3
+ "version": "1.0.104",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,7 +25,7 @@
25
25
  "rimraf": "^6.1.3",
26
26
  "tsdown": "^0.21.4",
27
27
  "typescript": "^5.9.3",
28
- "@mage-ui/preset": "1.0.103",
28
+ "@mage-ui/preset": "1.0.104",
29
29
  "@mage-ui/styled-system": "1.0.8"
30
30
  },
31
31
  "peerDependencies": {