react-antd-xform 1.0.5 → 1.0.7
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/LICENSE +1 -1
- package/dist/form/context/formEnvContext.js +2 -1
- package/dist/form/extend/form-layout.d.ts +1 -3
- package/dist/form/extend/form-layout.js +0 -10
- package/dist/form/form-item.js +11 -2
- package/dist/form/index.d.ts +1 -1
- package/dist/form/index.js +2 -1
- package/dist/form/type.d.ts +11 -12
- package/dist/form-ui/common-utils.d.ts +13 -0
- package/dist/form-ui/common-utils.js +31 -2
- package/dist/form-ui/default-component.d.ts +10 -2
- package/dist/form-ui/default-component.js +136 -80
- package/dist/form-ui/render-preview.d.ts +29 -0
- package/dist/form-ui/render-preview.js +55 -0
- package/package.json +9 -12
- package/README.md +0 -2
package/LICENSE
CHANGED
|
@@ -6,7 +6,8 @@ const FormEnvContext = createContext({
|
|
|
6
6
|
validateOnBlur: true,
|
|
7
7
|
validateOnChange: true,
|
|
8
8
|
writeDefaultValueToModel: false,
|
|
9
|
-
autoUnmount: false
|
|
9
|
+
autoUnmount: false,
|
|
10
|
+
variant: "outlined"
|
|
10
11
|
});
|
|
11
12
|
FormEnvContext.displayName = "FormEnvContext";
|
|
12
13
|
const useFormEnv = () => useContext(FormEnvContext);
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import { FormLayoutProps
|
|
1
|
+
import { FormLayoutProps } from '../type';
|
|
2
2
|
export declare function FormLayout({ children, className, style, labelPosition, labelWidth, formItemGap, controlWidth, defaultLabelTopPosition, inlineError, containerProps, }: FormLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
-
/** @deprecated 请使用 Form.ItemView 代替 ItemGroup */
|
|
4
|
-
export declare const FormItemGroup: ({ label, asterisk, tip, children, labelWidth, controlWidth, className, style, inline, }: FormItemGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -165,16 +165,6 @@ function FormLayout({
|
|
|
165
165
|
}
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
|
-
styled.div`
|
|
169
|
-
${FormLayoutContainer}.horizontal & {
|
|
170
|
-
display: flex;
|
|
171
|
-
}
|
|
172
|
-
&.inline {
|
|
173
|
-
.form-item-group-content {
|
|
174
|
-
display: flex;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
`;
|
|
178
168
|
export {
|
|
179
169
|
FormLayout
|
|
180
170
|
};
|
package/dist/form/form-item.js
CHANGED
|
@@ -88,6 +88,7 @@ function FormItemView({
|
|
|
88
88
|
}
|
|
89
89
|
function createFormItem(inputOptions) {
|
|
90
90
|
const options = processCreationOptions(inputOptions);
|
|
91
|
+
console.log(options, "options");
|
|
91
92
|
function FormItemComponent({
|
|
92
93
|
defaultValue: defaultValueProp,
|
|
93
94
|
isEmpty = options.isEmpty,
|
|
@@ -99,6 +100,7 @@ function createFormItem(inputOptions) {
|
|
|
99
100
|
}) {
|
|
100
101
|
const formEnv = useFormEnv();
|
|
101
102
|
const model = useModel();
|
|
103
|
+
const variant = formEnv.variant;
|
|
102
104
|
const field = resolveField(fieldProp, model, name, props.value);
|
|
103
105
|
const isPreview = composeValue(props.isPreview, formEnv.isPreview);
|
|
104
106
|
const error = composeValue(props.error, field.state.error);
|
|
@@ -107,6 +109,7 @@ function createFormItem(inputOptions) {
|
|
|
107
109
|
const htmlId = Field.getHtmlId(formEnv.htmlIdPrefix, field);
|
|
108
110
|
const componentProps = {
|
|
109
111
|
id: htmlId,
|
|
112
|
+
variant,
|
|
110
113
|
...isPreview ? { isPreview: true } : null,
|
|
111
114
|
// dataSource, readOnly, disabled,options 允许直接透传
|
|
112
115
|
...pick(props, ["dataSource", "readOnly", "disabled", "options"]),
|
|
@@ -176,6 +179,7 @@ function createFormItem(inputOptions) {
|
|
|
176
179
|
return null;
|
|
177
180
|
}
|
|
178
181
|
}
|
|
182
|
+
console.log(isPreview, "isPreviewisPreviewisPreview");
|
|
179
183
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
180
184
|
FormItemView,
|
|
181
185
|
{
|
|
@@ -253,6 +257,8 @@ const Hidden = createFormItem({
|
|
|
253
257
|
}
|
|
254
258
|
});
|
|
255
259
|
function FormItem({ use, component, ...props }) {
|
|
260
|
+
const formEnv = useFormEnv();
|
|
261
|
+
const variant = formEnv.variant;
|
|
256
262
|
if (use === false) {
|
|
257
263
|
return null;
|
|
258
264
|
}
|
|
@@ -266,13 +272,16 @@ function FormItem({ use, component, ...props }) {
|
|
|
266
272
|
if (Comp == null) {
|
|
267
273
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(NotFound, { ...props, componentProps: { $Component: component } });
|
|
268
274
|
}
|
|
269
|
-
return React.createElement(Comp,
|
|
275
|
+
return React.createElement(Comp, {
|
|
276
|
+
...props,
|
|
277
|
+
componentProps: { ...props.componentProps, variant }
|
|
278
|
+
});
|
|
270
279
|
} else {
|
|
271
280
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
272
281
|
AnonymousFormItem,
|
|
273
282
|
{
|
|
274
283
|
...props,
|
|
275
|
-
componentProps: { ...props.componentProps, $Component: component }
|
|
284
|
+
componentProps: { ...props.componentProps, variant, $Component: component }
|
|
276
285
|
}
|
|
277
286
|
);
|
|
278
287
|
}
|
package/dist/form/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { FormModel } from './model';
|
|
|
4
4
|
import { FormItemView } from './form-item';
|
|
5
5
|
import { FormLayout } from './extend/form-layout';
|
|
6
6
|
import { FormSubmit } from './extend/form-submit';
|
|
7
|
-
export declare function Form({ model: modelProp, defaultValue, children, className, style, layout, containerProps, htmlIdPrefix: htmlIdPrefixProp, ...restEnvProps }: FormProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function Form({ model: modelProp, defaultValue, children, className, style, layout, containerProps, htmlIdPrefix: htmlIdPrefixProp, variant, ...restEnvProps }: FormProps): import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
export declare namespace Form {
|
|
9
9
|
var Array: (<T extends unknown>({ name, children, layout, arrayModel: arrayModelProp, use, }: import("./extend/form-array").FormArrayProps<T>) => import("react/jsx-runtime").JSX.Element) & {
|
|
10
10
|
displayName: string;
|
package/dist/form/index.js
CHANGED
|
@@ -22,12 +22,13 @@ function Form({
|
|
|
22
22
|
layout,
|
|
23
23
|
containerProps,
|
|
24
24
|
htmlIdPrefix: htmlIdPrefixProp,
|
|
25
|
+
variant,
|
|
25
26
|
...restEnvProps
|
|
26
27
|
}) {
|
|
27
28
|
const [_model] = useState(() => new FormModel(defaultValue));
|
|
28
29
|
const model = composeValue(modelProp, _model);
|
|
29
30
|
const htmlIdPrefix = useHtmlIdPrefix(htmlIdPrefixProp);
|
|
30
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(FormEnvProvider, { htmlIdPrefix, ...restEnvProps, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ModelProvider, { value: model, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { style, className, containerProps, ...layout, children }) }) });
|
|
31
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(FormEnvProvider, { htmlIdPrefix, variant, ...restEnvProps, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ModelProvider, { value: model, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { style, className, containerProps, ...layout, children }) }) });
|
|
31
32
|
}
|
|
32
33
|
Form.Array = FormArray;
|
|
33
34
|
Form.Check = FormCheck;
|
package/dist/form/type.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
import { Field, FormModel } from './model';
|
|
3
3
|
import { FieldType, ModelType } from './enum';
|
|
4
4
|
import { AsyncValue } from './helpers/AsyncValue';
|
|
5
|
+
export declare const Variants: readonly ["outlined", "borderless", "filled", "underlined"];
|
|
6
|
+
export type Variant = (typeof Variants)[number];
|
|
5
7
|
type valueOf<T> = T[keyof T];
|
|
6
8
|
export type XName<D> = 0 extends D & 1 ? any : D extends (infer U)[] ? number | `${number}` | `${number}.${XName<U>}` : D extends object ? valueOf<{
|
|
7
9
|
[K in keyof D & string]: K | `${K}.${XName<D[K]>}`;
|
|
@@ -117,6 +119,10 @@ export interface FormEnvContextType {
|
|
|
117
119
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/label
|
|
118
120
|
* */
|
|
119
121
|
htmlIdPrefix?: string;
|
|
122
|
+
/**
|
|
123
|
+
* 表单样式参数 from antd
|
|
124
|
+
* */
|
|
125
|
+
variant?: Variant;
|
|
120
126
|
}
|
|
121
127
|
export interface FormLayoutParams {
|
|
122
128
|
/** 标签位置,可选 'left' 或 'top' */
|
|
@@ -150,6 +156,10 @@ export interface FormProps extends FormEnvContextType {
|
|
|
150
156
|
* */
|
|
151
157
|
layout?: FormLayoutParams;
|
|
152
158
|
children?: React.ReactNode;
|
|
159
|
+
/**
|
|
160
|
+
* 表单样式参数 from antd
|
|
161
|
+
* */
|
|
162
|
+
variant?: Variant;
|
|
153
163
|
}
|
|
154
164
|
export interface FormLayoutParams {
|
|
155
165
|
/** 标签位置,可选 'left' 或 'top' */
|
|
@@ -170,18 +180,6 @@ export interface FormLayoutProps extends Partial<FormLayoutParams> {
|
|
|
170
180
|
containerProps?: any;
|
|
171
181
|
defaultLabelTopPosition?: number | string;
|
|
172
182
|
}
|
|
173
|
-
export interface FormItemGroupProps {
|
|
174
|
-
label?: React.ReactNode;
|
|
175
|
-
tip?: React.ReactNode;
|
|
176
|
-
asterisk?: boolean;
|
|
177
|
-
children?: React.ReactNode;
|
|
178
|
-
labelWidth?: number | string;
|
|
179
|
-
labelTopPosition?: number | string;
|
|
180
|
-
controlWidth?: number | string;
|
|
181
|
-
className?: string;
|
|
182
|
-
style?: React.CSSProperties;
|
|
183
|
-
inline?: boolean;
|
|
184
|
-
}
|
|
185
183
|
export interface FormItemComponentProps {
|
|
186
184
|
value?: any;
|
|
187
185
|
onChange?(...args: any[]): void;
|
|
@@ -237,6 +235,7 @@ export interface FormItemProps extends Omit<FieldConfig<any>, 'defaultValueProp'
|
|
|
237
235
|
controlStyle?: React.CSSProperties;
|
|
238
236
|
rightNode?: React.ReactNode;
|
|
239
237
|
isPreview?: boolean;
|
|
238
|
+
variant?: Variant;
|
|
240
239
|
}
|
|
241
240
|
export interface FormItemViewProps {
|
|
242
241
|
/** `<label />` 的 id 属性 */
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
+
import { ColorPicker } from 'antd';
|
|
3
|
+
import { ColorPickerProps } from 'antd/es/color-picker';
|
|
2
4
|
export declare function isEmptyValue(value: any): boolean;
|
|
3
5
|
/**
|
|
4
6
|
* antd中某些组件的onChange并不是直接返回value,而是e.target.value
|
|
@@ -28,3 +30,14 @@ export declare const withDayjsTransformAntdTimeRange: (Component: React.Componen
|
|
|
28
30
|
* 向组件中注入props
|
|
29
31
|
*/
|
|
30
32
|
export declare const withInjectedProps: (injectedProps: Record<string, any>) => (Component: React.ComponentType<any>) => React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<any>>;
|
|
33
|
+
/**
|
|
34
|
+
* 用于处理Antd ColorPicker的onChange返回值格式
|
|
35
|
+
* 根据 returnType 返回指定格式的值(如 hex、rgb、hsb)
|
|
36
|
+
*/
|
|
37
|
+
type ColorReturnType = 'hex' | 'rgb' | 'hsv';
|
|
38
|
+
interface ColorPickerWrapperProps extends Omit<ColorPickerProps, 'onChange'> {
|
|
39
|
+
onChange?: (value: string) => void;
|
|
40
|
+
returnType?: ColorReturnType;
|
|
41
|
+
}
|
|
42
|
+
export declare const withColorPickerHandler: (Component: typeof ColorPicker) => ({ onChange, returnType, ...props }: ColorPickerWrapperProps) => import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { j as jsxRuntimeExports } from "../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js";
|
|
2
2
|
import React, { useMemo, useCallback } from "react";
|
|
3
3
|
import dayjs from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.js";
|
|
4
|
-
import weekOfYear from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/weekOfYear.js";
|
|
5
|
-
import weekYear from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/weekYear.js";
|
|
6
4
|
import isoweek from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/isoWeek.js";
|
|
5
|
+
import weekYear from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/weekYear.js";
|
|
6
|
+
import weekOfYear from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/weekOfYear.js";
|
|
7
7
|
dayjs.extend(weekOfYear);
|
|
8
8
|
dayjs.extend(weekYear);
|
|
9
9
|
dayjs.extend(isoweek);
|
|
@@ -248,8 +248,37 @@ const withInjectedProps = (injectedProps) => {
|
|
|
248
248
|
return WrappedComponent;
|
|
249
249
|
};
|
|
250
250
|
};
|
|
251
|
+
const withColorPickerHandler = (Component) => {
|
|
252
|
+
return ({
|
|
253
|
+
onChange,
|
|
254
|
+
returnType = "hex",
|
|
255
|
+
...props
|
|
256
|
+
}) => {
|
|
257
|
+
const handleChange = (color) => {
|
|
258
|
+
if (!onChange) return;
|
|
259
|
+
let value;
|
|
260
|
+
switch (returnType) {
|
|
261
|
+
case "hex":
|
|
262
|
+
value = color.toHexString();
|
|
263
|
+
break;
|
|
264
|
+
case "rgb":
|
|
265
|
+
value = color.toRgbString();
|
|
266
|
+
break;
|
|
267
|
+
case "hsv":
|
|
268
|
+
const hsv = color.toHsb();
|
|
269
|
+
value = `hsv(${hsv.h}, ${hsv.s * 100}%, ${hsv.b * 100}%)`;
|
|
270
|
+
break;
|
|
271
|
+
default:
|
|
272
|
+
value = color.toHexString();
|
|
273
|
+
}
|
|
274
|
+
onChange(value);
|
|
275
|
+
};
|
|
276
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Component, { ...props, onChange: handleChange });
|
|
277
|
+
};
|
|
278
|
+
};
|
|
251
279
|
export {
|
|
252
280
|
isEmptyValue,
|
|
281
|
+
withColorPickerHandler,
|
|
253
282
|
withDayjsTransformAntdDate,
|
|
254
283
|
withDayjsTransformAntdDateRangePicker,
|
|
255
284
|
withDayjsTransformAntdTime,
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { isEmptyValue } from './common-utils';
|
|
2
|
+
declare const ALL_COMPONENTS: {
|
|
3
|
+
name: "input" | "textArea" | "select" | "singleSelect" | "multiSelect" | "radio" | "checkbox" | "inputNumber" | "slider" | "switch" | "datePicker" | "dateRangePicker" | "timePicker" | "timeRangePicker" | "rate" | "colorPicker";
|
|
4
|
+
component: any;
|
|
5
|
+
defaultValue: any;
|
|
6
|
+
isEmpty: typeof isEmptyValue;
|
|
7
|
+
hasIntrinsicWidth: boolean;
|
|
8
|
+
renderPreview: (props: import('../form/type').FormItemComponentProps) => import('react').ReactNode;
|
|
9
|
+
}[];
|
|
10
|
+
export { ALL_COMPONENTS };
|
|
@@ -1,105 +1,161 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ColorPicker, Rate, TimePicker, DatePicker, Switch, Slider, InputNumber, Checkbox, Radio, Select, Input } from "antd";
|
|
2
|
+
import { withInjectedProps, withDayjsTransformAntdTimeRange, withDayjsTransformAntdTime, withDayjsTransformAntdDateRangePicker, withDayjsTransformAntdDate, withValueChangeHandler, isEmptyValue, withColorPickerHandler } from "./common-utils.js";
|
|
3
|
+
import { useColorPreview, useRatePreview, useTimeRangePreview, useTimePreview, useDateRangePreview, useDatePreview, useBooleanPreview, useValueToPreview, useMultiplePreview } from "./render-preview.js";
|
|
4
|
+
const COMPONENT_MAP = {
|
|
5
|
+
input: Input,
|
|
6
|
+
textArea: Input.TextArea,
|
|
7
|
+
select: Select,
|
|
8
|
+
singleSelect: Select,
|
|
9
|
+
multiSelect: Select,
|
|
10
|
+
radio: Radio.Group,
|
|
11
|
+
checkbox: Checkbox.Group,
|
|
12
|
+
inputNumber: InputNumber,
|
|
13
|
+
slider: Slider,
|
|
14
|
+
switch: Switch,
|
|
15
|
+
datePicker: DatePicker,
|
|
16
|
+
dateRangePicker: DatePicker.RangePicker,
|
|
17
|
+
timePicker: TimePicker,
|
|
18
|
+
timeRangePicker: TimePicker.RangePicker,
|
|
19
|
+
rate: Rate,
|
|
20
|
+
colorPicker: ColorPicker
|
|
21
|
+
};
|
|
22
|
+
const DEFAULT_VALUES = {
|
|
23
|
+
input: "",
|
|
24
|
+
textArea: "",
|
|
25
|
+
select: "",
|
|
26
|
+
singleSelect: "",
|
|
27
|
+
multiSelect: [],
|
|
28
|
+
radio: "",
|
|
29
|
+
checkbox: [],
|
|
30
|
+
inputNumber: null,
|
|
31
|
+
slider: null,
|
|
32
|
+
switch: false,
|
|
33
|
+
datePicker: null,
|
|
34
|
+
dateRangePicker: null,
|
|
35
|
+
timePicker: null,
|
|
36
|
+
timeRangePicker: null,
|
|
37
|
+
rate: 0,
|
|
38
|
+
colorPicker: ""
|
|
39
|
+
};
|
|
40
|
+
const COMPONENT_RULES = {
|
|
41
|
+
input: {
|
|
42
|
+
hocs: ["valueChange"],
|
|
43
|
+
renderPreview: useValueToPreview,
|
|
9
44
|
hasIntrinsicWidth: false
|
|
10
45
|
},
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
isEmpty: isEmptyValue,
|
|
16
|
-
hasIntrinsicWidth: false
|
|
46
|
+
textArea: {
|
|
47
|
+
hocs: ["valueChange"],
|
|
48
|
+
renderPreview: useValueToPreview,
|
|
49
|
+
hasIntrinsicWidth: true
|
|
17
50
|
},
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
isEmpty: isEmptyValue,
|
|
23
|
-
hasIntrinsicWidth: false
|
|
51
|
+
select: {
|
|
52
|
+
hocs: [],
|
|
53
|
+
renderPreview: useValueToPreview,
|
|
54
|
+
hasIntrinsicWidth: true
|
|
24
55
|
},
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
isEmpty: isEmptyValue,
|
|
30
|
-
hasIntrinsicWidth: false
|
|
56
|
+
singleSelect: {
|
|
57
|
+
hocs: [],
|
|
58
|
+
renderPreview: useValueToPreview,
|
|
59
|
+
hasIntrinsicWidth: true
|
|
31
60
|
},
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
isEmpty: isEmptyValue,
|
|
37
|
-
hasIntrinsicWidth: false
|
|
61
|
+
multiSelect: {
|
|
62
|
+
hocs: ["multiSelect"],
|
|
63
|
+
renderPreview: useMultiplePreview,
|
|
64
|
+
hasIntrinsicWidth: true
|
|
38
65
|
},
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
defaultValue: "",
|
|
43
|
-
isEmpty: isEmptyValue,
|
|
66
|
+
radio: {
|
|
67
|
+
hocs: ["valueChange"],
|
|
68
|
+
renderPreview: useValueToPreview,
|
|
44
69
|
hasIntrinsicWidth: false
|
|
45
70
|
},
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
defaultValue: "",
|
|
50
|
-
isEmpty: isEmptyValue,
|
|
71
|
+
checkbox: {
|
|
72
|
+
hocs: [],
|
|
73
|
+
renderPreview: useMultiplePreview,
|
|
51
74
|
hasIntrinsicWidth: false
|
|
52
75
|
},
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
defaultValue: "",
|
|
57
|
-
isEmpty: isEmptyValue,
|
|
76
|
+
inputNumber: {
|
|
77
|
+
hocs: ["valueChange"],
|
|
78
|
+
renderPreview: useValueToPreview,
|
|
58
79
|
hasIntrinsicWidth: false
|
|
59
80
|
},
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
defaultValue: "",
|
|
64
|
-
isEmpty: isEmptyValue,
|
|
81
|
+
slider: {
|
|
82
|
+
hocs: ["valueChange"],
|
|
83
|
+
renderPreview: useValueToPreview,
|
|
65
84
|
hasIntrinsicWidth: false
|
|
66
85
|
},
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
defaultValue: false,
|
|
71
|
-
isEmpty: isEmptyValue,
|
|
86
|
+
switch: {
|
|
87
|
+
hocs: ["valueChange"],
|
|
88
|
+
renderPreview: useBooleanPreview,
|
|
72
89
|
hasIntrinsicWidth: false
|
|
73
90
|
},
|
|
74
|
-
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
isEmpty: isEmptyValue,
|
|
79
|
-
hasIntrinsicWidth: false
|
|
91
|
+
datePicker: {
|
|
92
|
+
hocs: ["dayjsDate"],
|
|
93
|
+
renderPreview: useDatePreview,
|
|
94
|
+
hasIntrinsicWidth: true
|
|
80
95
|
},
|
|
81
|
-
{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
isEmpty: isEmptyValue,
|
|
86
|
-
hasIntrinsicWidth: false
|
|
96
|
+
dateRangePicker: {
|
|
97
|
+
hocs: ["dayjsDateRange"],
|
|
98
|
+
renderPreview: useDateRangePreview,
|
|
99
|
+
hasIntrinsicWidth: true
|
|
87
100
|
},
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
timePicker: {
|
|
102
|
+
hocs: ["dayjsTime"],
|
|
103
|
+
renderPreview: useTimePreview,
|
|
104
|
+
hasIntrinsicWidth: true
|
|
105
|
+
},
|
|
106
|
+
timeRangePicker: {
|
|
107
|
+
hocs: ["dayjsTimeRange"],
|
|
108
|
+
renderPreview: useTimeRangePreview,
|
|
109
|
+
hasIntrinsicWidth: true
|
|
110
|
+
},
|
|
111
|
+
rate: {
|
|
112
|
+
hocs: [],
|
|
113
|
+
renderPreview: useRatePreview,
|
|
93
114
|
hasIntrinsicWidth: false
|
|
94
115
|
},
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
defaultValue: false,
|
|
99
|
-
isEmpty: isEmptyValue,
|
|
116
|
+
colorPicker: {
|
|
117
|
+
hocs: ["colorPicker"],
|
|
118
|
+
renderPreview: useColorPreview,
|
|
100
119
|
hasIntrinsicWidth: false
|
|
101
120
|
}
|
|
102
|
-
|
|
121
|
+
};
|
|
122
|
+
const ALL_COMPONENTS = Object.keys(COMPONENT_MAP).map((name) => {
|
|
123
|
+
let component = COMPONENT_MAP[name];
|
|
124
|
+
const rule = COMPONENT_RULES[name];
|
|
125
|
+
rule.hocs.forEach((hoc) => {
|
|
126
|
+
switch (hoc) {
|
|
127
|
+
case "valueChange":
|
|
128
|
+
component = withValueChangeHandler(component);
|
|
129
|
+
break;
|
|
130
|
+
case "dayjsDate":
|
|
131
|
+
component = withDayjsTransformAntdDate(component);
|
|
132
|
+
break;
|
|
133
|
+
case "dayjsDateRange":
|
|
134
|
+
component = withDayjsTransformAntdDateRangePicker(component);
|
|
135
|
+
break;
|
|
136
|
+
case "dayjsTime":
|
|
137
|
+
component = withDayjsTransformAntdTime(component);
|
|
138
|
+
break;
|
|
139
|
+
case "dayjsTimeRange":
|
|
140
|
+
component = withDayjsTransformAntdTimeRange(component);
|
|
141
|
+
break;
|
|
142
|
+
case "multiSelect":
|
|
143
|
+
component = withInjectedProps({ mode: "multiple" })(component);
|
|
144
|
+
break;
|
|
145
|
+
case "colorPicker":
|
|
146
|
+
component = withColorPickerHandler(component);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
name,
|
|
152
|
+
component,
|
|
153
|
+
defaultValue: DEFAULT_VALUES[name],
|
|
154
|
+
isEmpty: isEmptyValue,
|
|
155
|
+
hasIntrinsicWidth: rule.hasIntrinsicWidth,
|
|
156
|
+
renderPreview: (props) => rule.renderPreview(props.value)
|
|
157
|
+
};
|
|
158
|
+
});
|
|
103
159
|
export {
|
|
104
160
|
ALL_COMPONENTS
|
|
105
161
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** 通用默认预览 */
|
|
2
|
+
export declare const useValueToPreview: (value: any) => React.ReactNode;
|
|
3
|
+
/** 日期预览 */
|
|
4
|
+
export declare const useDatePreview: (value: any) => React.ReactNode;
|
|
5
|
+
/** 日期范围预览 */
|
|
6
|
+
export declare const useDateRangePreview: (value: [any, any] | null | undefined) => React.ReactNode;
|
|
7
|
+
/** 时间预览 */
|
|
8
|
+
export declare const useTimePreview: (value: any) => React.ReactNode;
|
|
9
|
+
/** 时间范围预览 */
|
|
10
|
+
export declare const useTimeRangePreview: (value: [any, any] | null | undefined) => React.ReactNode;
|
|
11
|
+
/** 多选/标签类预览 */
|
|
12
|
+
export declare const useMultiplePreview: (value: any[]) => React.ReactNode;
|
|
13
|
+
/** 开关类预览 */
|
|
14
|
+
export declare const useBooleanPreview: (value: boolean) => React.ReactNode;
|
|
15
|
+
/** 评分预览 */
|
|
16
|
+
export declare const useRatePreview: (value: number) => React.ReactNode;
|
|
17
|
+
/** 颜色预览(返回色块) */
|
|
18
|
+
export declare const useColorPreview: (value: string) => React.ReactNode;
|
|
19
|
+
export declare const PREVIEW_RENDERERS: {
|
|
20
|
+
readonly useValueToPreview: (value: any) => React.ReactNode;
|
|
21
|
+
readonly useDatePreview: (value: any) => React.ReactNode;
|
|
22
|
+
readonly useDateRangePreview: (value: [any, any] | null | undefined) => React.ReactNode;
|
|
23
|
+
readonly useTimePreview: (value: any) => React.ReactNode;
|
|
24
|
+
readonly useTimeRangePreview: (value: [any, any] | null | undefined) => React.ReactNode;
|
|
25
|
+
readonly useMultiplePreview: (value: any[]) => React.ReactNode;
|
|
26
|
+
readonly useBooleanPreview: (value: boolean) => React.ReactNode;
|
|
27
|
+
readonly useRatePreview: (value: number) => React.ReactNode;
|
|
28
|
+
readonly useColorPreview: (value: string) => React.ReactNode;
|
|
29
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js";
|
|
2
|
+
import dayjs from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.js";
|
|
3
|
+
const useValueToPreview = (value) => {
|
|
4
|
+
return value != null && value !== "" ? `${value}` : "--";
|
|
5
|
+
};
|
|
6
|
+
const useDatePreview = (value) => {
|
|
7
|
+
return value ? dayjs(value).format("YYYY-MM-DD") : "--";
|
|
8
|
+
};
|
|
9
|
+
const useDateRangePreview = (value) => {
|
|
10
|
+
if (!Array.isArray(value) || !value[0] || !value[1]) return "--";
|
|
11
|
+
return `${dayjs(value[0]).format("YYYY-MM-DD")} ~ ${dayjs(value[1]).format("YYYY-MM-DD")}`;
|
|
12
|
+
};
|
|
13
|
+
const useTimePreview = (value) => {
|
|
14
|
+
return value ? dayjs(value).format("HH:mm:ss") : "--";
|
|
15
|
+
};
|
|
16
|
+
const useTimeRangePreview = (value) => {
|
|
17
|
+
if (!Array.isArray(value) || !value[0] || !value[1]) return "--";
|
|
18
|
+
return `${dayjs(value[0]).format("HH:mm")} ~ ${dayjs(value[1]).format("HH:mm")}`;
|
|
19
|
+
};
|
|
20
|
+
const useMultiplePreview = (value) => {
|
|
21
|
+
return Array.isArray(value) && value.length > 0 ? value.join(", ") : "--";
|
|
22
|
+
};
|
|
23
|
+
const useBooleanPreview = (value) => {
|
|
24
|
+
return typeof value === "boolean" ? value ? "是" : "否" : "--";
|
|
25
|
+
};
|
|
26
|
+
const useRatePreview = (value) => {
|
|
27
|
+
return typeof value === "number" ? "★".repeat(value) + "☆".repeat(5 - value) : "--";
|
|
28
|
+
};
|
|
29
|
+
const useColorPreview = (value) => {
|
|
30
|
+
if (!value) return "--";
|
|
31
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
32
|
+
"span",
|
|
33
|
+
{
|
|
34
|
+
style: {
|
|
35
|
+
display: "inline-block",
|
|
36
|
+
width: 16,
|
|
37
|
+
height: 16,
|
|
38
|
+
border: "1px solid #ddd",
|
|
39
|
+
backgroundColor: value,
|
|
40
|
+
borderRadius: 3
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
useBooleanPreview,
|
|
47
|
+
useColorPreview,
|
|
48
|
+
useDatePreview,
|
|
49
|
+
useDateRangePreview,
|
|
50
|
+
useMultiplePreview,
|
|
51
|
+
useRatePreview,
|
|
52
|
+
useTimePreview,
|
|
53
|
+
useTimeRangePreview,
|
|
54
|
+
useValueToPreview
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-antd-xform",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "基于mobx的form解决方案",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,24 +13,21 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "vite build",
|
|
15
15
|
"dev": "sb dev -p 6006",
|
|
16
|
-
"build-storybook": "sb build"
|
|
16
|
+
"build-storybook": "sb build",
|
|
17
|
+
"docs:dev": "dumi dev",
|
|
18
|
+
"docs:build": "dumi build",
|
|
19
|
+
"docs:serve": "dumi serve"
|
|
17
20
|
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"form",
|
|
20
|
-
"antd",
|
|
21
|
-
"react",
|
|
22
|
-
"mobx",
|
|
23
|
-
"react-antd-xform"
|
|
24
|
-
],
|
|
21
|
+
"keywords": [],
|
|
25
22
|
"author": "",
|
|
26
|
-
"license": "
|
|
23
|
+
"license": "ISC",
|
|
27
24
|
"packageManager": "pnpm@10.12.1",
|
|
28
25
|
"dependencies": {
|
|
29
26
|
"@types/invariant": "^2.2.37",
|
|
30
27
|
"@types/stringify-object": "^4.0.5",
|
|
31
28
|
"antd": "^5.26.2",
|
|
32
29
|
"classnames": "^2.5.1",
|
|
33
|
-
"dayjs": "^1.11.
|
|
30
|
+
"dayjs": "^1.11.15",
|
|
34
31
|
"invariant": "^2.2.4",
|
|
35
32
|
"mobx": "^6.13.7",
|
|
36
33
|
"mobx-react-lite": "^4.1.0",
|
|
@@ -48,10 +45,10 @@
|
|
|
48
45
|
"@types/react-dom": "^18.2.22",
|
|
49
46
|
"@types/react-syntax-highlighter": "^15.5.13",
|
|
50
47
|
"@vitejs/plugin-react": "^4.6.0",
|
|
48
|
+
"dumi": "^2.4.21",
|
|
51
49
|
"react": "^18.2.0",
|
|
52
50
|
"react-dom": "^18.2.0",
|
|
53
51
|
"react-json-view": "^1.21.3",
|
|
54
|
-
"react-syntax-highlighter": "^15.6.1",
|
|
55
52
|
"vite": "^5.2.0",
|
|
56
53
|
"vite-plugin-dts": "^4.5.4"
|
|
57
54
|
},
|
package/README.md
DELETED