@fairys/valtio-form-basic 0.0.12 → 0.0.13

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.
Files changed (48) hide show
  1. package/esm/{form → common}/hooks/index.d.ts +1 -0
  2. package/esm/{form → common}/hooks/index.js +9 -1
  3. package/esm/common/index.d.ts +4 -0
  4. package/esm/common/index.js +4 -0
  5. package/esm/{form → common}/instance/index.d.ts +9 -2
  6. package/esm/{form → common}/instance/index.js +19 -5
  7. package/esm/{form → common}/utils/index.d.ts +1 -0
  8. package/esm/{form → common}/utils/index.js +2 -1
  9. package/esm/form/form.d.ts +7 -7
  10. package/esm/form/form.item.d.ts +10 -3
  11. package/esm/form/form.item.js +50 -32
  12. package/esm/form/form.js +5 -3
  13. package/esm/form/layout.d.ts +4 -2591
  14. package/esm/form/layout.js +7 -4
  15. package/esm/index.d.ts +1 -2
  16. package/esm/index.js +1 -2
  17. package/esm/styles/index.css +20 -4
  18. package/lib/common/hooks/index.d.ts +35 -0
  19. package/lib/common/hooks/index.js +117 -0
  20. package/lib/common/index.d.ts +4 -0
  21. package/lib/common/index.js +87 -0
  22. package/lib/common/instance/index.d.ts +88 -0
  23. package/lib/common/instance/index.js +243 -0
  24. package/lib/common/interface.d.ts +4 -0
  25. package/lib/common/interface.js +18 -0
  26. package/lib/common/utils/index.d.ts +25 -0
  27. package/lib/common/utils/index.js +107 -0
  28. package/lib/form/form.d.ts +76 -0
  29. package/lib/form/form.item.d.ts +224 -0
  30. package/lib/form/form.item.js +321 -0
  31. package/lib/form/form.js +53 -0
  32. package/lib/form/layout.d.ts +153 -0
  33. package/lib/form/layout.js +196 -0
  34. package/lib/index.d.ts +4 -0
  35. package/lib/index.js +18 -27
  36. package/lib/styles/index.css +308 -0
  37. package/package.json +5 -5
  38. package/src/{form → common}/hooks/index.tsx +9 -1
  39. package/src/common/index.ts +4 -0
  40. package/src/{form → common}/instance/index.ts +51 -13
  41. package/src/{form → common}/utils/index.ts +2 -0
  42. package/src/form/form.item.tsx +59 -36
  43. package/src/form/form.tsx +12 -7
  44. package/src/form/layout.tsx +9 -3
  45. package/src/index.tsx +4 -5
  46. /package/esm/{interface.d.ts → common/interface.d.ts} +0 -0
  47. /package/esm/{interface.js → common/interface.js} +0 -0
  48. /package/src/{interface.ts → common/interface.ts} +0 -0
@@ -0,0 +1,224 @@
1
+ /**表单项*/
2
+ import { MObject } from '../common/interface';
3
+ import React from 'react';
4
+ import { FairysValtioFormInstance } from '../common/instance';
5
+ import { FairysValtioFormLayoutContextOptions } from './layout';
6
+ import { FairysValtioFormParentAttrs } from '../common/hooks';
7
+ import { RuleItem } from 'async-validator';
8
+ export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = object> {
9
+ /**平台*/
10
+ platform?: 'pc' | 'rn' | 'taro';
11
+ /**
12
+ * 表单项名称 ,字段需要和存储的字段路径一致
13
+ *
14
+ * @example
15
+ * 路径中的值为 number 类型时,会创建一个空数组。路径中的值为 string 类型时,会创建一个空对象。最后一个直接赋值
16
+ *
17
+ * 默认:"name"
18
+ * 嵌套字段:"name.a.doc" ===> { name: { a: { doc: undefined } } }
19
+ * 嵌套字段:"name[1].a.doc" ===> { name: [{}, { a: { doc: undefined } }] }
20
+ * 嵌套字段:"name.a[2].doc" ===> { name: { a: [{}, {}, { doc: undefined }] } }
21
+ */
22
+ name?: string;
23
+ /**表单项标签*/
24
+ label?: string;
25
+ /**传递组件字段*/
26
+ valuePropName?: string;
27
+ /**取值字段(默认 valuePropName字段值)*/
28
+ getValuePath?: string;
29
+ /**自定义获取值*/
30
+ getValueFromEvent?: (event: any, form: FairysValtioFormInstance<T>) => any;
31
+ /**值格式化*/
32
+ formatValue?: (value: any, form: FairysValtioFormInstance<T>, event: any) => any;
33
+ /**触发数据更新之后触发(用于数据联动之类的)*/
34
+ onAfterUpdate?: (value: any, form: FairysValtioFormInstance<T>, event: any) => void;
35
+ /**事件名称*/
36
+ trigger?: string;
37
+ className?: string;
38
+ style?: React.CSSProperties;
39
+ labelClassName?: string;
40
+ labelStyle?: React.CSSProperties;
41
+ bodyClassName?: string;
42
+ bodyStyle?: React.CSSProperties;
43
+ children?: React.ReactNode;
44
+ /**规则校验失败错误提示位置*/
45
+ errorLayout?: FairysValtioFormLayoutContextOptions['errorLayout'];
46
+ /**label显示模式*/
47
+ labelMode?: FairysValtioFormLayoutContextOptions['labelMode'];
48
+ /**额外内容*/
49
+ extra?: React.ReactNode;
50
+ /**底部提示内容*/
51
+ helpText?: React.ReactNode;
52
+ /**
53
+ * 表单项占据列数
54
+ * @default 1
55
+ */
56
+ colSpan?: number;
57
+ /**
58
+ * 表单项占据行数
59
+ * @default 1
60
+ */
61
+ rowSpan?: number;
62
+ /**是否必填*/
63
+ isRequired?: boolean;
64
+ /**是否显示冒号*/
65
+ showColon?: boolean;
66
+ /**底部显示边框*/
67
+ itemBorderType?: FairysValtioFormLayoutContextOptions['itemBorderType'];
68
+ /**边框颜色*/
69
+ itemBorderColor?: React.CSSProperties['borderColor'];
70
+ /**是否校验失败时显示红色边框*/
71
+ isInvalidBorderRed?: boolean;
72
+ /**是否校验失败时显示红色文本*/
73
+ isInvalidTextRed?: boolean;
74
+ /**输入框属性*/
75
+ attrs?: any;
76
+ /**是否拼接父级字段名*/
77
+ isJoinParentField?: boolean;
78
+ /**校验规则*/
79
+ rules?: RuleItem[];
80
+ }
81
+ /**
82
+ * 处理表单表单项属性
83
+ *
84
+ * @example
85
+ *
86
+ * ```tsx
87
+ import { Fragment } from 'react'
88
+ import { useFairysValtioFormItemAttrs , FairysValtioFormParentAttrsContext } from "@fairys/valtio-form"
89
+ import type { FairysValtioFormItemAttrsProps } from "@fairys/valtio-form"
90
+ export interface FormItemProps extends FairysValtioFormItemAttrsProps{}
91
+
92
+ export const FormItem = (props: FormItemProps) => {
93
+ const { label, extra, helpText } = props
94
+ const {
95
+ itemClassName, itemStyle, containerClassName, itemLabelClassName, itemLabelStyle,
96
+ itemBodyClassName, itemBodyStyle, itemInputClassName, itemExtraClassName, errorClassName, helpClassName,
97
+ isInvalid, itemBorderType, children, error,formAttrsNameInstance
98
+ } = useFairysValtioFormItemAttrs(props)
99
+
100
+ return (
101
+ <FairysValtioFormParentAttrsContext.Provider value={formAttrsNameInstance}>
102
+ <View className={itemClassName} style={itemStyle}>
103
+ <View className={containerClassName}>
104
+ <View className={itemLabelClassName} style={itemLabelStyle}>
105
+ {label}
106
+ </View>
107
+ <View className={itemBodyClassName} style={itemBodyStyle}>
108
+ <View className={itemInputClassName}>
109
+ {children}
110
+ </View>
111
+ {extra ? <View className={itemExtraClassName}>{extra}</View> : <Fragment />}
112
+ {itemBorderType === 'body' && isInvalid ? <View className={errorClassName}>{error}</View> : <Fragment />}
113
+ </View>
114
+ </View>
115
+ {helpText ? <View className={helpClassName}>{helpText}</View> : <Fragment />}
116
+ {isInvalid && itemBorderType !== 'body' ? <View className={errorClassName}>{error}</View> : <Fragment />}
117
+ </View>
118
+ </FairysValtioFormParentAttrsContext.Provider>
119
+ );
120
+ }
121
+ * ```
122
+ *
123
+ */
124
+ export declare function useFairysValtioFormItemAttrs<T extends MObject<T> = object>(props: FairysValtioFormItemAttrsProps<T>): FairysValtioFormItemAttrsReturn<T>;
125
+ export interface FairysValtioFormItemAttrsReturn<T extends MObject<T> = object> {
126
+ /**表单项值*/
127
+ value?: any;
128
+ /**是否校验错误*/
129
+ isInvalid: boolean;
130
+ /**边框类型*/
131
+ itemBorderType: FairysValtioFormLayoutContextOptions['itemBorderType'];
132
+ /**值改变事件*/
133
+ onValueChange: (event: any) => void;
134
+ /**当前表单项占据列数*/
135
+ colSpan: number;
136
+ /**当前表单项占据行数*/
137
+ rowSpan: number;
138
+ /**列数*/
139
+ colCount: number;
140
+ /**标签显示模式*/
141
+ labelMode: FairysValtioFormLayoutContextOptions['labelMode'];
142
+ /**错误提示位置*/
143
+ errorLayout: FairysValtioFormLayoutContextOptions['errorLayout'];
144
+ /**是否必填*/
145
+ isRequired: boolean;
146
+ /**表单状态*/
147
+ state: T;
148
+ /**错误状态*/
149
+ errorState: Record<PropertyKey, string[]>;
150
+ /**表单实例*/
151
+ formInstance: FairysValtioFormInstance<T>;
152
+ /**错误信息*/
153
+ error?: string[];
154
+ /**拼接父级字段名后得到的表单项名称*/
155
+ _name?: string;
156
+ /**表单项名称*/
157
+ name?: string;
158
+ /**表单项ID*/
159
+ id?: string;
160
+ /**表单项路径*/
161
+ paths?: (string | number)[];
162
+ /**父级字段名*/
163
+ parentName?: string;
164
+ /**表单属性名实例*/
165
+ formAttrsNameInstance: FairysValtioFormParentAttrs;
166
+ /**表单项类名*/
167
+ itemClassName: string;
168
+ /**表单项样式*/
169
+ itemStyle: React.CSSProperties;
170
+ /**容器类名*/
171
+ containerClassName: string;
172
+ /**标签类名*/
173
+ itemLabelClassName: string;
174
+ /**标签样式*/
175
+ itemLabelStyle: React.CSSProperties;
176
+ /**体类名*/
177
+ itemBodyClassName: string;
178
+ /**体样式*/
179
+ itemBodyStyle: React.CSSProperties;
180
+ /**输入框类名*/
181
+ itemInputClassName: string;
182
+ /**额外内容类名*/
183
+ itemExtraClassName: string;
184
+ /**错误提示类名*/
185
+ errorClassName: string;
186
+ /**帮助提示类名*/
187
+ helpClassName: string;
188
+ /**子元素*/
189
+ children?: React.ReactNode;
190
+ }
191
+ /**
192
+ * 没有样式的表单项属性,仅返回基础输入组件参数
193
+ *
194
+ * @example
195
+ *
196
+ *```tsx
197
+ import { Fragment } from 'react'
198
+ import { useFairysValtioFormItemAttrs, FairysValtioFormParentAttrsContext } from "@fairys/valtio-form"
199
+ import type { FairysValtioFormItemAttrsProps } from "@fairys/valtio-form"
200
+ export interface FormItemProps extends FairysValtioFormItemAttrsProps{}
201
+
202
+ export const FormItem = (props: FormItemProps) => {
203
+ const { children , formAttrsNameInstance } = useFairysValtioFormItemNoStyleAttrs(props)
204
+ return <FairysValtioFormParentAttrsContext.Provider value={formAttrsNameInstance}>
205
+ {children}
206
+ </FairysValtioFormParentAttrsContext.Provider>
207
+ }
208
+ * ```
209
+ */
210
+ export declare function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = object>(props: FairysValtioFormItemAttrsProps<T>): {
211
+ value: unknown;
212
+ error: string[];
213
+ onValueChange: (event: any) => void;
214
+ state: T;
215
+ errorState: Record<PropertyKey, string[]>;
216
+ formInstance: FairysValtioFormInstance<T>;
217
+ _name: string;
218
+ name: string;
219
+ id: string;
220
+ paths: (number | symbol)[] | (string | number)[];
221
+ parentName: string;
222
+ formAttrsNameInstance: FairysValtioFormParentAttrs;
223
+ children: string | number | boolean | React.ReactElement<any, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>;
224
+ };
@@ -0,0 +1,321 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ useFairysValtioFormItemNoStyleAttrs: ()=>useFairysValtioFormItemNoStyleAttrs,
37
+ useFairysValtioFormItemAttrs: ()=>useFairysValtioFormItemAttrs
38
+ });
39
+ const external_react_namespaceObject = require("react");
40
+ var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
41
+ const external_clsx_namespaceObject = require("clsx");
42
+ var external_clsx_default = /*#__PURE__*/ __webpack_require__.n(external_clsx_namespaceObject);
43
+ const index_js_namespaceObject = require("../common/instance/index.js");
44
+ const external_layout_js_namespaceObject = require("./layout.js");
45
+ const hooks_index_js_namespaceObject = require("../common/hooks/index.js");
46
+ const utils_index_js_namespaceObject = require("../common/utils/index.js");
47
+ function useFairysValtioFormItemAttrs(props) {
48
+ const [layoutAttrs] = (0, external_layout_js_namespaceObject.useFairysValtioFormLayoutContext)();
49
+ const colCount = layoutAttrs.colCount || 1;
50
+ const parent_borderedType = layoutAttrs.itemBorderType || 'bottom';
51
+ const parent_errorLayout = layoutAttrs.errorLayout || 'bottom-right';
52
+ const parent_formItemClassName = layoutAttrs.formItemClassName;
53
+ const parent_formItemLabelClassName = layoutAttrs.formItemLabelClassName;
54
+ const parent_formItemLabelStyle = layoutAttrs.formItemLabelStyle;
55
+ const parent_formItemStyle = layoutAttrs.formItemStyle;
56
+ const parent_formItemBodyClassName = layoutAttrs.formItemBodyClassName;
57
+ const parent_formItemBodyStyle = layoutAttrs.formItemBodyStyle;
58
+ const parent_labelMode = layoutAttrs.labelMode || 'between';
59
+ const parent_itemBorderColor = layoutAttrs.itemBorderColor;
60
+ const parent_isInvalidBorderRed = layoutAttrs.isInvalidBorderRed;
61
+ const parent_isInvalidTextRed = layoutAttrs.isInvalidTextRed;
62
+ const parent_showColon = layoutAttrs.showColon;
63
+ const parent_platform = layoutAttrs.platform;
64
+ const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', className, style, labelClassName, labelStyle, bodyClassName, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, colSpan = 1, rowSpan = 1, isRequired: _isRequired, itemBorderType = parent_borderedType, attrs = {}, showColon = parent_showColon, itemBorderColor = parent_itemBorderColor, isInvalidBorderRed = parent_isInvalidBorderRed, isInvalidTextRed = parent_isInvalidTextRed, isJoinParentField = true, rules, platform = parent_platform } = props;
65
+ const { name: _name, paths, parentName, formAttrsNameInstance } = (0, hooks_index_js_namespaceObject.useFairysValtioFormAttrsName)({
66
+ name,
67
+ isJoinParentField
68
+ });
69
+ const [state, errorState, formInstance] = (0, index_js_namespaceObject.useFairysValtioFormInstanceContextState)();
70
+ const value = (0, external_react_namespaceObject.useMemo)(()=>(0, utils_index_js_namespaceObject.get)(state, paths), [
71
+ state,
72
+ paths
73
+ ]);
74
+ const error = errorState[_name];
75
+ const _formItemRules = formInstance.rules?.[_name];
76
+ const id = (0, hooks_index_js_namespaceObject.useId)(_name);
77
+ formInstance.nameToPaths[_name] = paths;
78
+ (0, external_react_namespaceObject.useEffect)(()=>{
79
+ if (Array.isArray(rules) && rules.length) formInstance.mountRules[_name] = rules;
80
+ return ()=>{
81
+ formInstance.removeRules(_name);
82
+ };
83
+ }, [
84
+ _name,
85
+ rules
86
+ ]);
87
+ const onValueChange = (event)=>{
88
+ let _value = event;
89
+ const target = event?.detail || event?.target;
90
+ if ('function' == typeof getValueFromEvent) _value = getValueFromEvent(event, formInstance);
91
+ else if (event && target && 'object' == typeof target && getValuePath in target) _value = (0, utils_index_js_namespaceObject.get)(target, (0, utils_index_js_namespaceObject.formatePath)(getValuePath));
92
+ if ('function' == typeof formatValue) _value = formatValue(_value, formInstance, event);
93
+ if (value === _value) return;
94
+ formInstance.updatedValueByPaths(_name, _value);
95
+ if ('function' == typeof onAfterUpdate) onAfterUpdate(_value, formInstance, event);
96
+ };
97
+ const baseControl = {
98
+ ...attrs,
99
+ name,
100
+ id,
101
+ [valuePropName]: value,
102
+ [trigger]: onValueChange
103
+ };
104
+ const isRequired = (0, external_react_namespaceObject.useMemo)(()=>{
105
+ if (_isRequired) return _isRequired;
106
+ if (Array.isArray(rules) && rules.length) return rules.some((rule)=>rule.required);
107
+ if (_formItemRules && Array.isArray(_formItemRules) && _formItemRules.length) return _formItemRules.some((rule)=>rule.required);
108
+ return false;
109
+ }, [
110
+ rules,
111
+ formInstance,
112
+ _formItemRules
113
+ ]);
114
+ const isInvalid = (0, external_react_namespaceObject.useMemo)(()=>{
115
+ if (Array.isArray(error) && error.length) return true;
116
+ return false;
117
+ }, [
118
+ error
119
+ ]);
120
+ const item_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__p-_zkh1_4px_zhk2_ fairystaroform__text-_zkh1_12px_zhk2_ fairystaroform__relative fairystaroform__flex fairystaroform__flex-col fairystaroform__box-border fairystaroform__break-all', {
121
+ 'fairys-valtio-form-item-invalid': isInvalid,
122
+ 'fairys-valtio-form-item-invalid-text-red': isInvalid && isInvalidTextRed,
123
+ 'fairys-valtio-form-item-invalid-border-red': isInvalid && isInvalidBorderRed && 'bottom' === itemBorderType,
124
+ 'fairystaroform__border-b fairystaroform__border-b-solid fairystaroform__border-b-gray-200': 'bottom' === itemBorderType,
125
+ [labelMode]: labelMode
126
+ }, parent_formItemClassName, className), [
127
+ className,
128
+ parent_formItemClassName,
129
+ labelMode,
130
+ itemBorderType,
131
+ isInvalid,
132
+ isInvalidBorderRed
133
+ ]);
134
+ const itemContainer_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item-container fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__flex-1 fairystaroform__h-full fairystaroform__flex fairystaroform__box-border', {
135
+ 'fairystaroform__flex-row fairystaroform__items-center fairystaroform__justify-between fairystaroform__gap-_zkh1_8px_zhk2_': 'between' === labelMode,
136
+ 'fairystaroform__flex-col fairystaroform__gap-_zkh1_4px_zhk2_': 'top' === labelMode,
137
+ 'fairystaroform__flex-row fairystaroform__gap-_zkh1_8px_zhk2_': 'left' === labelMode
138
+ }, labelClassName), [
139
+ labelClassName,
140
+ labelMode
141
+ ]);
142
+ const itemLabel_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item-label fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__text-gray-800 fairystaroform__flex fairystaroform__items-center fairystaroform__relative fairystaroform__box-border', {
143
+ 'fairystaroform__justify-start': 'left' !== labelMode,
144
+ 'fairystaroform__justify-end': 'left' === labelMode,
145
+ required: isRequired,
146
+ 'show-colon': showColon
147
+ }, labelClassName, parent_formItemLabelClassName), [
148
+ labelClassName,
149
+ parent_formItemLabelClassName,
150
+ labelMode,
151
+ isRequired,
152
+ showColon
153
+ ]);
154
+ const itemBody_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item-body fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__relative fairystaroform__flex-1 fairystaroform__flex fairystaroform__box-border fairystaroform__items-start', {
155
+ 'fairystaroform__flex-row fairystaroform__justify-start': 'left' === labelMode,
156
+ 'fairystaroform__flex-row fairystaroform__justify-end': 'between' === labelMode || 'top' === labelMode,
157
+ 'fairystaroform__border-b fairystaroform__border-b-solid fairystaroform__border-b-gray-200 ': 'body' === itemBorderType,
158
+ 'fairys-valtio-form-item-invalid-border-red': isInvalid && isInvalidBorderRed && 'body' === itemBorderType
159
+ }, parent_formItemBodyClassName, bodyClassName), [
160
+ bodyClassName,
161
+ labelMode,
162
+ itemBorderType,
163
+ parent_formItemBodyClassName,
164
+ isInvalid,
165
+ isInvalidBorderRed
166
+ ]);
167
+ const itemInput_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item-body-input fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__min-h-_zkh1_32px_zhk2_ fairystaroform__flex fairystaroform__flex-row fairystaroform__items-center fairystaroform__flex-1 fairystaroform__box-border', {
168
+ 'fairystaroform__justify-end fairystaroform__text-right': 'between' === labelMode,
169
+ 'fairystaroform__justify-start fairystaroform__text-left fairystaroform__items-center': 'between' !== labelMode
170
+ }), [
171
+ labelMode
172
+ ]);
173
+ const itemExtra_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item-body-extra fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__box-border fairystaroform__flex fairystaroform__items-center fairystaroform__justify-center'), []);
174
+ const itemHelp_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item-body-help fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__text-_zkh1_10px_zhk2_ fairystaroform__w-full fairystaroform__box-border'), []);
175
+ const itemError_cls = (0, external_react_namespaceObject.useMemo)(()=>external_clsx_default()('fairys-valtio-form-item-body-error fairystaroform__transition-all fairystaroform__duration-300 fairystaroform__w-full fairystaroform__flex fairystaroform__flex-row fairystaroform__box-border fairystaroform__text-red fairystaroform__absolute fairystaroform__text-_zkh1_10px_zhk2_ fairystaroform__z-10', {
176
+ 'fairystaroform__bottom-_zkh1_-14px_zhk2_ fairystaroform__left-0 fairystaroform__justify-start': 'bottom-left' === errorLayout && 'pc' !== platform,
177
+ 'fairystaroform__bottom-_zkh1_-10px_zhk2_ fairystaroform__left-0 fairystaroform__justify-start': 'bottom-left' === errorLayout && 'pc' === platform,
178
+ 'fairystaroform__bottom-_zkh1_-14px_zhk2_ fairystaroform__right-0 fairystaroform__justify-end': 'bottom-right' === errorLayout && 'pc' !== platform,
179
+ 'fairystaroform__bottom-_zkh1_-10px_zhk2_ fairystaroform__right-0 fairystaroform__justify-end': 'bottom-right' === errorLayout && 'pc' === platform,
180
+ 'fairystaroform__top-_zkh1_-4px_zhk2_ fairystaroform__right-0 fairystaroform__justify-end': 'top-right' === errorLayout,
181
+ 'fairystaroform__top-_zkh1_-4px_zhk2_ fairystaroform__left-0 fairystaroform__justify-start': 'top-left' === errorLayout,
182
+ 'fairystaroform__left-0 fairystaroform__bottom-_zkh1_-2px_zhk2_ fairystaroform__justify-start': 'left-border-top' === errorLayout,
183
+ 'fairystaroform__right-0 fairystaroform__bottom-_zkh1_-2px_zhk2_ fairystaroform__justify-end': 'right-border-top' === errorLayout,
184
+ 'fairystaroform__px-_zkh1_4px_zhk2_': 'pc' === platform
185
+ }), [
186
+ errorLayout,
187
+ platform
188
+ ]);
189
+ const styleBase = (0, external_react_namespaceObject.useMemo)(()=>{
190
+ const css = {};
191
+ if (colSpan) {
192
+ const end = colCount > colSpan ? colSpan : colCount;
193
+ css.gridColumnEnd = `span ${end}`;
194
+ }
195
+ if (rowSpan) css.gridRowEnd = `span ${rowSpan}`;
196
+ return css;
197
+ }, [
198
+ colSpan,
199
+ rowSpan,
200
+ colCount
201
+ ]);
202
+ return {
203
+ value,
204
+ isInvalid,
205
+ itemBorderType,
206
+ onValueChange,
207
+ colSpan,
208
+ rowSpan,
209
+ colCount,
210
+ labelMode,
211
+ errorLayout,
212
+ isRequired,
213
+ state,
214
+ errorState,
215
+ formInstance,
216
+ error,
217
+ _name,
218
+ name,
219
+ id,
220
+ paths,
221
+ parentName,
222
+ formAttrsNameInstance,
223
+ itemClassName: item_cls,
224
+ itemStyle: {
225
+ ...itemBorderColor && 'bottom' === itemBorderType ? {
226
+ borderBottomColor: itemBorderColor
227
+ } : {},
228
+ ...parent_formItemStyle || {},
229
+ ...styleBase,
230
+ ...style || {}
231
+ },
232
+ containerClassName: itemContainer_cls,
233
+ itemLabelClassName: itemLabel_cls,
234
+ itemLabelStyle: {
235
+ ...parent_formItemLabelStyle || {},
236
+ ...labelStyle || {}
237
+ },
238
+ itemBodyClassName: itemBody_cls,
239
+ itemBodyStyle: {
240
+ ...itemBorderColor && 'body' === itemBorderType ? {
241
+ borderBottomColor: itemBorderColor
242
+ } : {},
243
+ ...parent_formItemBodyStyle || {},
244
+ ...bodyStyle || {}
245
+ },
246
+ itemInputClassName: itemInput_cls,
247
+ itemExtraClassName: itemExtra_cls,
248
+ errorClassName: itemError_cls,
249
+ helpClassName: itemHelp_cls,
250
+ children: /*#__PURE__*/ external_react_default().isValidElement(children) ? /*#__PURE__*/ external_react_default().cloneElement(children, {
251
+ ...baseControl
252
+ }) : children
253
+ };
254
+ }
255
+ function useFairysValtioFormItemNoStyleAttrs(props) {
256
+ const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', children, attrs = {}, isJoinParentField = true, rules } = props;
257
+ const [state, errorState, formInstance] = (0, index_js_namespaceObject.useFairysValtioFormInstanceContextState)();
258
+ const { name: _name, paths, parentName, formAttrsNameInstance } = (0, hooks_index_js_namespaceObject.useFairysValtioFormAttrsName)({
259
+ name,
260
+ isJoinParentField
261
+ });
262
+ const id = (0, hooks_index_js_namespaceObject.useId)(_name);
263
+ const value = (0, external_react_namespaceObject.useMemo)(()=>(0, utils_index_js_namespaceObject.get)(state, paths), [
264
+ state,
265
+ paths
266
+ ]);
267
+ const error = errorState[_name];
268
+ formInstance.nameToPaths[_name] = paths;
269
+ (0, external_react_namespaceObject.useEffect)(()=>{
270
+ if (Array.isArray(rules) && rules.length) formInstance.mountRules[_name] = rules;
271
+ return ()=>{
272
+ formInstance.removeRules(_name);
273
+ };
274
+ }, [
275
+ _name,
276
+ rules
277
+ ]);
278
+ const onValueChange = (event)=>{
279
+ let _value = event;
280
+ const target = event?.detail || event?.target;
281
+ if ('function' == typeof getValueFromEvent) _value = getValueFromEvent(event, formInstance);
282
+ else if (event && target && 'object' == typeof target && getValuePath in target) _value = (0, utils_index_js_namespaceObject.get)(target, (0, utils_index_js_namespaceObject.formatePath)(getValuePath));
283
+ if ('function' == typeof formatValue) _value = formatValue(_value, formInstance, event);
284
+ if (value === _value) return;
285
+ formInstance.updatedValueByPaths(_name, _value);
286
+ if ('function' == typeof onAfterUpdate) onAfterUpdate(_value, formInstance, event);
287
+ };
288
+ const baseControl = {
289
+ ...attrs,
290
+ name,
291
+ id,
292
+ [valuePropName]: value,
293
+ [trigger]: onValueChange
294
+ };
295
+ return {
296
+ value,
297
+ error,
298
+ onValueChange,
299
+ state,
300
+ errorState,
301
+ formInstance,
302
+ _name,
303
+ name,
304
+ id,
305
+ paths,
306
+ parentName,
307
+ formAttrsNameInstance,
308
+ children: /*#__PURE__*/ external_react_default().isValidElement(children) ? /*#__PURE__*/ external_react_default().cloneElement(children, {
309
+ ...baseControl
310
+ }) : children
311
+ };
312
+ }
313
+ exports.useFairysValtioFormItemAttrs = __webpack_exports__.useFairysValtioFormItemAttrs;
314
+ exports.useFairysValtioFormItemNoStyleAttrs = __webpack_exports__.useFairysValtioFormItemNoStyleAttrs;
315
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
316
+ "useFairysValtioFormItemAttrs",
317
+ "useFairysValtioFormItemNoStyleAttrs"
318
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
319
+ Object.defineProperty(exports, '__esModule', {
320
+ value: true
321
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ useFairysValtioForm: ()=>useFairysValtioForm
28
+ });
29
+ const index_js_namespaceObject = require("../common/instance/index.js");
30
+ const external_react_namespaceObject = require("react");
31
+ function useFairysValtioForm(props, ref) {
32
+ const { form, rules, formData, hideState, initFormDataType = 'deepCopy', ...rest } = props;
33
+ const formInstance = (0, index_js_namespaceObject.useFairysValtioFormInstance)(form);
34
+ formInstance.rules = rules;
35
+ (0, external_react_namespaceObject.useMemo)(()=>formInstance.ctor({
36
+ formData,
37
+ hideState,
38
+ initFormDataType
39
+ }), []);
40
+ (0, external_react_namespaceObject.useImperativeHandle)(ref, ()=>formInstance);
41
+ (0, external_react_namespaceObject.useEffect)(()=>()=>formInstance.clear(), []);
42
+ return {
43
+ ...rest,
44
+ formInstance
45
+ };
46
+ }
47
+ exports.useFairysValtioForm = __webpack_exports__.useFairysValtioForm;
48
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
49
+ "useFairysValtioForm"
50
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
51
+ Object.defineProperty(exports, '__esModule', {
52
+ value: true
53
+ });