react-antd-xform 1.0.9 → 1.0.10

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.
@@ -1,6 +1,6 @@
1
1
  import { ComponentType } from 'react';
2
2
  type FormSubmitProps<T extends object = {}> = {
3
- /** 必须传入的按钮组件 */
3
+ /** 传入的按钮组件 */
4
4
  ButtonComponent: ComponentType<T>;
5
5
  /** 按钮内容 */
6
6
  children: React.ReactNode;
@@ -10,7 +10,11 @@ function FormReset({
10
10
  }) {
11
11
  const model = useModel();
12
12
  const formEnv = useFormEnv();
13
- return /* @__PURE__ */ jsxRuntimeExports.jsx(ButtonComponent, { ...props, onClick: action(() => modelUtils.reset(model, formEnv)), children, ...props });
13
+ if (ButtonComponent) {
14
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(ButtonComponent, { ...props, onClick: action(() => modelUtils.reset(model, formEnv)), children, ...props });
15
+ } else {
16
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("button", { ...props, onClick: action(() => modelUtils.reset(model, formEnv)), children, ...props });
17
+ }
14
18
  }
15
19
  export {
16
20
  FormReset
@@ -1,6 +1,6 @@
1
1
  import { ComponentType } from 'react';
2
2
  type FormSubmitProps<T extends object = {}> = {
3
- /** 必须传入的按钮组件 */
3
+ /** 传入的按钮组件 */
4
4
  ButtonComponent: ComponentType<T>;
5
5
  /** 按钮内容 */
6
6
  children: React.ReactNode;
@@ -16,7 +16,11 @@ function FormSubmit({
16
16
  onSubmit,
17
17
  onError
18
18
  };
19
- return /* @__PURE__ */ jsxRuntimeExports.jsx(ButtonComponent, { ...props, onClick: () => modelUtils.submit(model, submitOptions), children, ...props });
19
+ if (ButtonComponent) {
20
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(ButtonComponent, { ...props, onClick: () => modelUtils.submit(model, submitOptions), children, ...props });
21
+ } else {
22
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("button", { ...props, onClick: () => modelUtils.submit(model, submitOptions), children, ...props });
23
+ }
20
24
  }
21
25
  export {
22
26
  FormSubmit
@@ -1,12 +1,10 @@
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 isoweek from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/isoWeek.js";
5
4
  import weekYear from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/weekYear.js";
6
5
  import weekOfYear from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/plugin/weekOfYear.js";
7
6
  dayjs.extend(weekOfYear);
8
7
  dayjs.extend(weekYear);
9
- dayjs.extend(isoweek);
10
8
  if (!dayjs.__patchedForAntd__) {
11
9
  dayjs.__patchedForAntd__ = true;
12
10
  if (!dayjs.prototype.weekday) {
@@ -1,6 +1,6 @@
1
1
  import { ColorPicker, Rate, TimePicker, DatePicker, Switch, Slider, InputNumber, Checkbox, Radio, Select, Input } from "antd";
2
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";
3
+ import { useColorPreview, useRatePreview, useTimeRangePreview, useTimePreview, useDateRangePreview, useDatePreview, useBooleanPreview, useValueToPreview, useMultiplePreview, useSelectToPreview } from "./render-preview.js";
4
4
  const COMPONENT_MAP = {
5
5
  input: Input,
6
6
  textArea: Input.TextArea,
@@ -50,17 +50,17 @@ const COMPONENT_RULES = {
50
50
  },
51
51
  select: {
52
52
  hocs: [],
53
- renderPreview: useValueToPreview,
53
+ renderPreview: useSelectToPreview,
54
54
  hasIntrinsicWidth: true
55
55
  },
56
56
  singleSelect: {
57
57
  hocs: [],
58
- renderPreview: useValueToPreview,
58
+ renderPreview: useSelectToPreview,
59
59
  hasIntrinsicWidth: true
60
60
  },
61
61
  multiSelect: {
62
62
  hocs: ["multiSelect"],
63
- renderPreview: useMultiplePreview,
63
+ renderPreview: useSelectToPreview,
64
64
  hasIntrinsicWidth: true
65
65
  },
66
66
  radio: {
@@ -155,7 +155,7 @@ const ALL_COMPONENTS = Object.keys(COMPONENT_MAP).map((name) => {
155
155
  defaultValue: DEFAULT_VALUES[name],
156
156
  isEmpty: isEmptyValue,
157
157
  hasIntrinsicWidth: rule.hasIntrinsicWidth,
158
- renderPreview: (props) => rule.renderPreview(props.value)
158
+ renderPreview: (props) => rule.renderPreview(props)
159
159
  };
160
160
  });
161
161
  export {
@@ -1,29 +1,72 @@
1
- /** 通用默认预览 */
2
- export declare const useValueToPreview: (value: any) => React.ReactNode;
1
+ /** 通用默认预览,直接使用value进行设置 */
2
+ export declare const useValueToPreview: (props: {
3
+ value: string;
4
+ }) => React.ReactNode;
5
+ export declare const useSelectToPreview: (props: {
6
+ value: string | number | (string | number)[] | null | undefined;
7
+ options: {
8
+ label: string;
9
+ value: string | number;
10
+ }[];
11
+ }) => React.ReactNode;
3
12
  /** 日期预览 */
4
- export declare const useDatePreview: (value: any) => React.ReactNode;
13
+ export declare const useDatePreview: (props: {
14
+ value: any;
15
+ }) => React.ReactNode;
5
16
  /** 日期范围预览 */
6
- export declare const useDateRangePreview: (value: [any, any] | null | undefined) => React.ReactNode;
17
+ export declare const useDateRangePreview: (props: {
18
+ value: [any, any] | null | undefined;
19
+ }) => React.ReactNode;
7
20
  /** 时间预览 */
8
- export declare const useTimePreview: (value: any) => React.ReactNode;
21
+ export declare const useTimePreview: (props: {
22
+ value: any;
23
+ }) => React.ReactNode;
9
24
  /** 时间范围预览 */
10
- export declare const useTimeRangePreview: (value: [any, any] | null | undefined) => React.ReactNode;
25
+ export declare const useTimeRangePreview: (props: {
26
+ value: [any, any] | null | undefined;
27
+ }) => React.ReactNode;
11
28
  /** 多选/标签类预览 */
12
- export declare const useMultiplePreview: (value: any[]) => React.ReactNode;
29
+ export declare const useMultiplePreview: (props: {
30
+ value: any[];
31
+ }) => React.ReactNode;
13
32
  /** 开关类预览 */
14
- export declare const useBooleanPreview: (value: boolean) => React.ReactNode;
33
+ export declare const useBooleanPreview: (props: {
34
+ value: boolean;
35
+ }) => React.ReactNode;
15
36
  /** 评分预览 */
16
- export declare const useRatePreview: (value: number) => React.ReactNode;
37
+ export declare const useRatePreview: (props: {
38
+ value: number;
39
+ }) => React.ReactNode;
17
40
  /** 颜色预览(返回色块) */
18
- export declare const useColorPreview: (value: string) => React.ReactNode;
41
+ export declare const useColorPreview: (props: {
42
+ value: string;
43
+ }) => React.ReactNode;
19
44
  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;
45
+ readonly useValueToPreview: (props: {
46
+ value: string;
47
+ }) => React.ReactNode;
48
+ readonly useDatePreview: (props: {
49
+ value: any;
50
+ }) => React.ReactNode;
51
+ readonly useDateRangePreview: (props: {
52
+ value: [any, any] | null | undefined;
53
+ }) => React.ReactNode;
54
+ readonly useTimePreview: (props: {
55
+ value: any;
56
+ }) => React.ReactNode;
57
+ readonly useTimeRangePreview: (props: {
58
+ value: [any, any] | null | undefined;
59
+ }) => React.ReactNode;
60
+ readonly useMultiplePreview: (props: {
61
+ value: any[];
62
+ }) => React.ReactNode;
63
+ readonly useBooleanPreview: (props: {
64
+ value: boolean;
65
+ }) => React.ReactNode;
66
+ readonly useRatePreview: (props: {
67
+ value: number;
68
+ }) => React.ReactNode;
69
+ readonly useColorPreview: (props: {
70
+ value: string;
71
+ }) => React.ReactNode;
29
72
  };
@@ -1,41 +1,106 @@
1
1
  import { j as jsxRuntimeExports } from "../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js";
2
2
  import dayjs from "../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.js";
3
- const useValueToPreview = (value) => {
3
+ import { useMemo } from "react";
4
+ const useValueToPreview = (props) => {
5
+ const {
6
+ value
7
+ } = props;
4
8
  return value != null && value !== "" ? `${value}` : "--";
5
9
  };
6
- const useDatePreview = (value) => {
7
- return value ? dayjs(value).format("YYYY-MM-DD") : "--";
10
+ const useSelectToPreview = (props) => {
11
+ const {
12
+ value,
13
+ options
14
+ } = props;
15
+ return useMemo(() => {
16
+ if (value === null || value === void 0) {
17
+ return "--";
18
+ }
19
+ if (Array.isArray(value)) {
20
+ if (value.length === 0) return "--";
21
+ const labels = value.map((val) => {
22
+ const matched = options.find((item) => item.value === val);
23
+ return matched ? matched.label : null;
24
+ }).filter(Boolean);
25
+ return labels.length > 0 ? labels.join("、") : "--";
26
+ }
27
+ const matchedOption = options.find((item) => item.value === value);
28
+ return matchedOption ? matchedOption.label : "--";
29
+ }, [value, options]);
8
30
  };
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")}`;
31
+ const useDatePreview = (props) => {
32
+ const {
33
+ value
34
+ } = props;
35
+ return useMemo(() => {
36
+ return value ? dayjs(value).format("YYYY-MM-DD") : "--";
37
+ }, [value]);
12
38
  };
13
- const useTimePreview = (value) => {
14
- return value ? dayjs(value).format("HH:mm:ss") : "--";
39
+ const useDateRangePreview = (props) => {
40
+ const {
41
+ value
42
+ } = props;
43
+ return useMemo(() => {
44
+ if (!Array.isArray(value) || !value[0] || !value[1]) return "--";
45
+ return `${dayjs(value[0]).format("YYYY-MM-DD")} ~ ${dayjs(value[1]).format("YYYY-MM-DD")}`;
46
+ }, [value]);
15
47
  };
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")}`;
48
+ const useTimePreview = (props) => {
49
+ const {
50
+ value
51
+ } = props;
52
+ return useMemo(() => {
53
+ return value ? dayjs(value).format("HH:mm:ss") : "--";
54
+ }, [value]);
19
55
  };
20
- const useMultiplePreview = (value) => {
21
- return Array.isArray(value) && value.length > 0 ? value.join(", ") : "--";
56
+ const useTimeRangePreview = (props) => {
57
+ const {
58
+ value
59
+ } = props;
60
+ return useMemo(() => {
61
+ if (!Array.isArray(value) || !value[0] || !value[1]) return "--";
62
+ return `${dayjs(value[0]).format("HH:mm")} ~ ${dayjs(value[1]).format("HH:mm")}`;
63
+ }, [value]);
22
64
  };
23
- const useBooleanPreview = (value) => {
24
- return typeof value === "boolean" ? value ? "是" : "否" : "--";
65
+ const useMultiplePreview = (props) => {
66
+ const {
67
+ value
68
+ } = props;
69
+ return useMemo(() => {
70
+ return Array.isArray(value) && value.length > 0 ? value.join(", ") : "--";
71
+ }, [value]);
25
72
  };
26
- const useRatePreview = (value) => {
27
- return typeof value === "number" ? "★".repeat(value) + "☆".repeat(5 - value) : "--";
73
+ const useBooleanPreview = (props) => {
74
+ const {
75
+ value
76
+ } = props;
77
+ return useMemo(() => {
78
+ return typeof value === "boolean" ? value ? "是" : "否" : "--";
79
+ }, [value]);
28
80
  };
29
- const useColorPreview = (value) => {
30
- if (!value) return "--";
31
- return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style: {
32
- display: "inline-block",
33
- width: 16,
34
- height: 16,
35
- border: "1px solid #ddd",
36
- backgroundColor: value,
37
- borderRadius: 3
38
- } });
81
+ const useRatePreview = (props) => {
82
+ const {
83
+ value
84
+ } = props;
85
+ return useMemo(() => {
86
+ return typeof value === "number" ? "★".repeat(value) + "☆".repeat(5 - value) : "--";
87
+ }, [value]);
88
+ };
89
+ const useColorPreview = (props) => {
90
+ const {
91
+ value
92
+ } = props;
93
+ return useMemo(() => {
94
+ if (!value) return "--";
95
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { style: {
96
+ display: "inline-block",
97
+ width: 16,
98
+ height: 16,
99
+ border: "1px solid #ddd",
100
+ backgroundColor: value,
101
+ borderRadius: 3
102
+ } });
103
+ }, [value]);
39
104
  };
40
105
  export {
41
106
  useBooleanPreview,
@@ -44,6 +109,7 @@ export {
44
109
  useDateRangePreview,
45
110
  useMultiplePreview,
46
111
  useRatePreview,
112
+ useSelectToPreview,
47
113
  useTimePreview,
48
114
  useTimeRangePreview,
49
115
  useValueToPreview
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-antd-xform",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "基于mobx的form解决方案",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,14 +17,12 @@
17
17
  "docs:dev": "dumi dev",
18
18
  "docs:build-site": "dumi build",
19
19
  "docs:build": "cross-env DUMI_ENV=devbuild dumi build",
20
- "docs:serve": "dumi serve",
21
- "predeploy": "npm run docs:build",
20
+ "predeploy": "npm run docs:build-site",
22
21
  "deploy": "gh-pages -d docs-dist -b gh-pages"
23
22
  },
24
23
  "keywords": [],
25
24
  "author": "",
26
25
  "license": "ISC",
27
- "packageManager": "pnpm@10.12.1",
28
26
  "dependencies": {
29
27
  "@types/invariant": "^2.2.37",
30
28
  "@types/stringify-object": "^4.0.5",
@@ -54,6 +52,7 @@
54
52
  "dumi-theme-antd": "^0.4.4",
55
53
  "gh-pages": "^6.3.0",
56
54
  "react": "^18.2.0",
55
+ "react-antd-xform": "^1.0.9",
57
56
  "react-dom": "^18.2.0",
58
57
  "react-json-view": "^1.21.3",
59
58
  "vite": "^5.2.0",
@@ -1,4 +0,0 @@
1
- var isoWeek = { exports: {} };
2
- export {
3
- isoWeek as __module
4
- };
@@ -1,33 +0,0 @@
1
- import { commonjsGlobal, getDefaultExportFromCjs } from "../../../../../../_virtual/_commonjsHelpers.js";
2
- import { __module as isoWeek } from "../../../../../../_virtual/isoWeek.js";
3
- (function(module, exports) {
4
- !function(e, t) {
5
- module.exports = t();
6
- }(commonjsGlobal, function() {
7
- var e = "day";
8
- return function(t, i, s) {
9
- var a = function(t2) {
10
- return t2.add(4 - t2.isoWeekday(), e);
11
- }, d = i.prototype;
12
- d.isoWeekYear = function() {
13
- return a(this).year();
14
- }, d.isoWeek = function(t2) {
15
- if (!this.$utils().u(t2)) return this.add(7 * (t2 - this.isoWeek()), e);
16
- var i2, d2, n2, o, r = a(this), u = (i2 = this.isoWeekYear(), d2 = this.$u, n2 = (d2 ? s.utc : s)().year(i2).startOf("year"), o = 4 - n2.isoWeekday(), n2.isoWeekday() > 4 && (o += 7), n2.add(o, e));
17
- return r.diff(u, "week") + 1;
18
- }, d.isoWeekday = function(e2) {
19
- return this.$utils().u(e2) ? this.day() || 7 : this.day(this.day() % 7 ? e2 : e2 - 7);
20
- };
21
- var n = d.startOf;
22
- d.startOf = function(e2, t2) {
23
- var i2 = this.$utils(), s2 = !!i2.u(t2) || t2;
24
- return "isoweek" === i2.p(e2) ? s2 ? this.date(this.date() - (this.isoWeekday() - 1)).startOf("day") : this.date(this.date() - 1 - (this.isoWeekday() - 1) + 7).endOf("day") : n.bind(this)(e2, t2);
25
- };
26
- };
27
- });
28
- })(isoWeek);
29
- var isoWeekExports = isoWeek.exports;
30
- const isoweek = /* @__PURE__ */ getDefaultExportFromCjs(isoWeekExports);
31
- export {
32
- isoweek as default
33
- };