@zat-design/sisyphus-react 3.4.6 → 3.4.8

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 (109) hide show
  1. package/dist/index.esm.css +17 -1
  2. package/dist/less.esm.css +17 -1
  3. package/es/ProEditTable/components/RenderField/index.js +5 -8
  4. package/es/ProEditTable/style/index.less +5 -2
  5. package/es/ProForm/components/base/TextArea/index.d.ts +1 -0
  6. package/es/ProForm/components/base/TextArea/index.js +4 -2
  7. package/es/ProForm/components/combination/FormList/components/BlockFields.d.ts +1 -1
  8. package/es/ProForm/components/combination/FormList/index.js +2 -1
  9. package/es/ProForm/components/combination/FormList/propsType.d.ts +1 -1
  10. package/es/ProForm/components/combination/FormList/utils.js +2 -3
  11. package/es/ProForm/components/combination/{GroupCopy → Group}/component/ComRender.js +2 -2
  12. package/es/ProForm/components/combination/Group/index.d.ts +8 -2
  13. package/es/ProForm/components/combination/Group/index.js +58 -76
  14. package/es/ProForm/components/combination/Group/propsType.d.ts +27 -14
  15. package/es/ProForm/components/combination/Group/utils.d.ts +60 -7
  16. package/es/ProForm/components/combination/Group/utils.js +209 -19
  17. package/es/ProForm/components/combination/ProModalSelect/index.js +35 -29
  18. package/es/ProForm/components/combination/_Group/index.d.ts +4 -0
  19. package/es/ProForm/components/combination/_Group/index.js +109 -0
  20. package/es/ProForm/components/combination/_Group/propsType.d.ts +35 -0
  21. package/es/ProForm/components/combination/_Group/utils.d.ts +10 -0
  22. package/es/ProForm/components/combination/_Group/utils.js +46 -0
  23. package/es/ProForm/components/render/Render.js +8 -6
  24. package/es/ProForm/components/render/RenderFields.js +1 -0
  25. package/es/ProForm/components/render/propsType.d.ts +4 -3
  26. package/es/ProForm/propsType.d.ts +1 -0
  27. package/es/ProForm/style/index.less +7 -0
  28. package/es/ProForm/utils/diffOriginal.js +2 -1
  29. package/es/ProForm/utils/index.d.ts +6 -1
  30. package/es/ProForm/utils/index.js +5 -5
  31. package/es/ProForm/utils/transformNames.js +3 -10
  32. package/es/ProForm/utils/useDeepCompareMemo.d.ts +2 -0
  33. package/es/ProForm/utils/useDeepCompareMemo.js +14 -0
  34. package/es/ProForm/utils/useForm.js +2 -1
  35. package/es/ProForm/utils/useListChanged.js +2 -2
  36. package/es/ProForm/utils/useRules.js +2 -20
  37. package/es/ProSelect/index.js +14 -2
  38. package/es/ProSelect/propsType.d.ts +2 -0
  39. package/es/ProSelect/utils/index.d.ts +9 -0
  40. package/es/ProSelect/utils/index.js +60 -0
  41. package/es/ProTree/components/ProTreeSelect/index.js +3 -3
  42. package/es/ProTree/components/ProTreeSelect/style/index.less +6 -8
  43. package/es/ProTree/style/index.less +15 -0
  44. package/es/ProUpload/index.js +5 -6
  45. package/es/ProUpload/propsType.d.ts +1 -1
  46. package/es/global.less +40 -25
  47. package/es/locale/zh_CN.js +1 -1
  48. package/lib/ProEditTable/components/RenderField/index.js +5 -8
  49. package/lib/ProEditTable/style/index.less +5 -2
  50. package/lib/ProForm/components/base/TextArea/index.d.ts +1 -0
  51. package/lib/ProForm/components/base/TextArea/index.js +4 -2
  52. package/lib/ProForm/components/combination/FormList/components/BlockFields.d.ts +1 -1
  53. package/lib/ProForm/components/combination/FormList/index.js +2 -1
  54. package/lib/ProForm/components/combination/FormList/propsType.d.ts +1 -1
  55. package/lib/ProForm/components/combination/FormList/utils.js +2 -3
  56. package/lib/ProForm/components/combination/{GroupCopy → Group}/component/ComRender.js +2 -2
  57. package/lib/ProForm/components/combination/Group/index.d.ts +8 -2
  58. package/lib/ProForm/components/combination/Group/index.js +57 -72
  59. package/lib/ProForm/components/combination/Group/propsType.d.ts +27 -14
  60. package/lib/ProForm/components/combination/Group/utils.d.ts +60 -7
  61. package/lib/ProForm/components/combination/Group/utils.js +210 -20
  62. package/lib/ProForm/components/combination/ProModalSelect/index.js +35 -29
  63. package/lib/ProForm/components/combination/_Group/index.d.ts +4 -0
  64. package/lib/ProForm/components/combination/_Group/index.js +113 -0
  65. package/lib/ProForm/components/combination/_Group/propsType.d.ts +35 -0
  66. package/lib/ProForm/components/combination/_Group/utils.d.ts +10 -0
  67. package/lib/ProForm/components/combination/_Group/utils.js +53 -0
  68. package/lib/ProForm/components/render/Render.js +7 -5
  69. package/lib/ProForm/components/render/RenderFields.js +1 -0
  70. package/lib/ProForm/components/render/propsType.d.ts +4 -3
  71. package/lib/ProForm/propsType.d.ts +1 -0
  72. package/lib/ProForm/style/index.less +7 -0
  73. package/lib/ProForm/utils/diffOriginal.js +2 -1
  74. package/lib/ProForm/utils/index.d.ts +6 -1
  75. package/lib/ProForm/utils/index.js +5 -5
  76. package/lib/ProForm/utils/transformNames.js +2 -9
  77. package/lib/ProForm/utils/useDeepCompareMemo.d.ts +2 -0
  78. package/lib/ProForm/utils/useDeepCompareMemo.js +20 -0
  79. package/lib/ProForm/utils/useForm.js +2 -1
  80. package/lib/ProForm/utils/useListChanged.js +1 -1
  81. package/lib/ProForm/utils/useRules.js +2 -20
  82. package/lib/ProSelect/index.js +14 -2
  83. package/lib/ProSelect/propsType.d.ts +2 -0
  84. package/lib/ProSelect/utils/index.d.ts +9 -0
  85. package/lib/ProSelect/utils/index.js +68 -0
  86. package/lib/ProTree/components/ProTreeSelect/index.js +3 -3
  87. package/lib/ProTree/components/ProTreeSelect/style/index.less +6 -8
  88. package/lib/ProTree/style/index.less +15 -0
  89. package/lib/ProUpload/index.js +5 -6
  90. package/lib/ProUpload/propsType.d.ts +1 -1
  91. package/lib/global.less +40 -25
  92. package/lib/locale/zh_CN.js +1 -1
  93. package/package.json +1 -1
  94. package/es/ProForm/components/combination/GroupCopy/index.d.ts +0 -10
  95. package/es/ProForm/components/combination/GroupCopy/index.js +0 -84
  96. package/es/ProForm/components/combination/GroupCopy/propsType.d.ts +0 -47
  97. package/es/ProForm/components/combination/GroupCopy/utils.d.ts +0 -53
  98. package/es/ProForm/components/combination/GroupCopy/utils.js +0 -180
  99. package/lib/ProForm/components/combination/GroupCopy/index.d.ts +0 -10
  100. package/lib/ProForm/components/combination/GroupCopy/index.js +0 -91
  101. package/lib/ProForm/components/combination/GroupCopy/propsType.d.ts +0 -47
  102. package/lib/ProForm/components/combination/GroupCopy/utils.d.ts +0 -53
  103. package/lib/ProForm/components/combination/GroupCopy/utils.js +0 -187
  104. /package/es/ProForm/components/combination/{GroupCopy → Group}/component/ComRender.d.ts +0 -0
  105. /package/es/ProForm/components/combination/{GroupCopy → _Group}/propsType.js +0 -0
  106. /package/es/ProForm/components/combination/{GroupCopy → _Group}/style/index.less +0 -0
  107. /package/lib/ProForm/components/combination/{GroupCopy → Group}/component/ComRender.d.ts +0 -0
  108. /package/lib/ProForm/components/combination/{GroupCopy → _Group}/propsType.js +0 -0
  109. /package/lib/ProForm/components/combination/{GroupCopy → _Group}/style/index.less +0 -0
@@ -1,180 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _typeof from "@babel/runtime/helpers/esm/typeof";
3
- import "antd/es/button/style";
4
- import _Button from "antd/es/button";
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
- import { isFunction } from 'lodash';
7
- import valueTypeMap from '../../../utils/valueType';
8
- /**
9
- * 插入间隔符
10
- * @param columns 表单配置数组
11
- * @returns
12
- */
13
- export var insertSeparator = function insertSeparator(columns, space) {
14
- if (!(space === null || space === void 0 ? void 0 : space.separator)) {
15
- return columns;
16
- }
17
- return columns.reduce(function (result, current, index, array) {
18
- // 将当前元素添加到结果数组中
19
- result.push(current);
20
- // 如果当前元素不是最后一个元素,则添加间隔符
21
- if (index < array.length - 1) {
22
- result.push({
23
- component: _jsx(_Button, {
24
- className: "group-separator",
25
- children: space.separator
26
- }),
27
- fieldProps: {
28
- disabled: true
29
- }
30
- });
31
- }
32
- return result;
33
- }, []);
34
- };
35
- /** 带出event的组件默认取值方法 */
36
- export function defaultGetValueFromEvent(valuePropName) {
37
- var event = arguments.length <= 1 ? undefined : arguments[1];
38
- if (event && event.target && _typeof(event.target) === 'object' && valuePropName in event.target) {
39
- return event.target[valuePropName];
40
- }
41
- return event;
42
- }
43
- /** 转换names */
44
- export var transformNamesString = function transformNamesString(arr) {
45
- var result = arr.map(function (subArr) {
46
- if (Array.isArray(subArr)) {
47
- return subArr.join('_');
48
- }
49
- return subArr;
50
- });
51
- return result;
52
- };
53
- /** 计算响应式参数的值 */
54
- export var getReactiveProps = function getReactiveProps(params) {
55
- var form = params.form,
56
- index = params.index,
57
- namePath = params.namePath,
58
- disabled = params.disabled,
59
- show = params.show,
60
- component = params.component,
61
- fieldProps = params.fieldProps,
62
- name = params.name;
63
- var values = form.getFieldsValue(namePath || undefined);
64
- var _disabled = isFunction(disabled) ? disabled(values, {
65
- form: form,
66
- index: index,
67
- namePath: namePath
68
- }) : disabled;
69
- var _show = isFunction(show) ? show(values, {
70
- form: form,
71
- index: index,
72
- namePath: namePath
73
- }) : show;
74
- var _component = isFunction(component) ? component(values, {
75
- form: form,
76
- index: index,
77
- namePath: namePath
78
- }) : component;
79
- var _fieldProps = isFunction(fieldProps) ? fieldProps(values, {
80
- form: form,
81
- index: index,
82
- namePath: namePath
83
- }) : fieldProps;
84
- return {
85
- disabled: _disabled,
86
- show: _show,
87
- component: _component,
88
- fieldProps: _fieldProps
89
- };
90
- };
91
- /** 获取当前字段的转换函数 */
92
- export var getValueTypeTrans = function getValueTypeTrans(params) {
93
- var _valueTypeMap$valueTy;
94
- var valueType = params.valueType;
95
- var transform = (_valueTypeMap$valueTy = valueTypeMap[valueType]) === null || _valueTypeMap$valueTy === void 0 ? void 0 : _valueTypeMap$valueTy.call(valueTypeMap, params);
96
- return transform;
97
- };
98
- /** 转换columns */
99
- export var transformColumns = function transformColumns(params) {
100
- var form = params.form,
101
- columns = params.columns,
102
- name = params.name,
103
- names = params.names,
104
- outerIndex = params.index,
105
- namePath = params.namePath,
106
- value = params.value,
107
- internalChange = params.onChange;
108
- return columns === null || columns === void 0 ? void 0 : columns.flatMap(function (column, index) {
109
- var type = column.type,
110
- valueType = column.valueType,
111
- switchValue = column.switchValue,
112
- toISOString = column.toISOString,
113
- fieldProps = column.fieldProps,
114
- getValueFromEvent = column.getValueFromEvent,
115
- _column$valuePropName = column.valuePropName,
116
- valuePropName = _column$valuePropName === void 0 ? 'value' : _column$valuePropName,
117
- normalize = column.normalize,
118
- disabled = column.disabled,
119
- show = column.show,
120
- component = column.component;
121
- var _ref = fieldProps || {},
122
- mode = _ref.mode,
123
- onChange = _ref.onChange,
124
- onFieldChange = _ref.onFieldChange,
125
- comDisabled = _ref.disabled;
126
- var _disabled = disabled !== null && disabled !== void 0 ? disabled : comDisabled;
127
- var columnName = names ? names[index] : [].concat(name, index);
128
- // 响应式字段
129
- var reactiveProps = getReactiveProps({
130
- form: form,
131
- index: index,
132
- type: type,
133
- namePath: namePath,
134
- disabled: _disabled,
135
- show: show,
136
- component: component,
137
- fieldProps: fieldProps,
138
- name: columnName
139
- });
140
- if (reactiveProps.show === false) return [];
141
- var transform = getValueTypeTrans({
142
- type: type,
143
- valueType: valueType,
144
- switchValue: switchValue,
145
- toISOString: toISOString,
146
- mode: mode
147
- });
148
- var newValue;
149
- var handleChange = function handleChange() {
150
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
151
- args[_key] = arguments[_key];
152
- }
153
- if (getValueFromEvent) {
154
- newValue = getValueFromEvent.apply(void 0, args);
155
- } else {
156
- newValue = defaultGetValueFromEvent.apply(void 0, [valuePropName].concat(args));
157
- }
158
- if ((transform === null || transform === void 0 ? void 0 : transform.normalize) || normalize) {
159
- var _transform$normalize;
160
- // @ts-ignore
161
- newValue = ((_transform$normalize = transform.normalize) === null || _transform$normalize === void 0 ? void 0 : _transform$normalize.call(transform, newValue)) || (normalize === null || normalize === void 0 ? void 0 : normalize(newValue));
162
- }
163
- internalChange === null || internalChange === void 0 ? void 0 : internalChange(newValue, args[1], index);
164
- onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, args);
165
- onFieldChange === null || onFieldChange === void 0 ? void 0 : onFieldChange(newValue, form.getFieldValue(namePath), {
166
- index: outerIndex,
167
- namePath: namePath,
168
- form: form
169
- });
170
- };
171
- return _objectSpread(_objectSpread(_objectSpread({}, column), {}, {
172
- name: columnName
173
- }, reactiveProps), {}, {
174
- fieldProps: _objectSpread(_objectSpread({}, column === null || column === void 0 ? void 0 : column.fieldProps), {}, {
175
- onChange: handleChange,
176
- value: value === null || value === void 0 ? void 0 : value[index]
177
- })
178
- });
179
- });
180
- };
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import { GroupProps } from './propsType';
3
- /**
4
- * 1. 外层过滤FormItem相关属性, 但是子元素上的 required [disabled] [show] rules [fieldProps] [component] 需要取到并
5
- * 2.
6
- *
7
- * render内部能力 show, component, value, onChange, disabled, clearNotShow, fieldProps
8
- */
9
- declare const GroupCopy: React.FC<GroupProps>;
10
- export default GroupCopy;
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
- var _jsxRuntime = require("react/jsx-runtime");
13
- var _antd = require("antd");
14
- var _react = _interopRequireWildcard(require("react"));
15
- var _lodash = require("lodash");
16
- var _classnames2 = _interopRequireDefault(require("classnames"));
17
- var _utils = require("./utils");
18
- var _ProForm = _interopRequireDefault(require("../../../../ProForm"));
19
- var _ComRender = _interopRequireDefault(require("./component/ComRender"));
20
- /**
21
- * 1. 外层过滤FormItem相关属性, 但是子元素上的 required [disabled] [show] rules [fieldProps] [component] 需要取到并
22
- * 2.
23
- *
24
- * render内部能力 show, component, value, onChange, disabled, clearNotShow, fieldProps
25
- */
26
- var GroupCopy = function GroupCopy(props) {
27
- var children = props.children,
28
- className = props.className,
29
- _props$space = props.space,
30
- space = _props$space === void 0 ? {
31
- size: 12
32
- } : _props$space,
33
- value = props.value,
34
- onChange = props.onChange;
35
- var contextProps = _ProForm.default.useFieldProps() || {};
36
- var names = contextProps.names,
37
- name = contextProps.name,
38
- form = contextProps.form,
39
- namePath = contextProps.namePath,
40
- index = contextProps.index;
41
- var _value = value && (0, _toConsumableArray2.default)(value) || [];
42
- var _option = _react.default.useRef([]);
43
- // 组合onChange
44
- var handleChange = function handleChange(value, option, index) {
45
- _value[index] = value;
46
- _option.current[index] = option;
47
- onChange(_value, _option.current);
48
- };
49
- var columns = (0, _react.useMemo)(function () {
50
- var columnsProps = (0, _utils.transformColumns)({
51
- columns: children,
52
- name: name,
53
- names: names,
54
- onChange: handleChange,
55
- namePath: namePath,
56
- form: form,
57
- index: index,
58
- value: _value
59
- });
60
- return (0, _utils.insertSeparator)(columnsProps, space);
61
- }, [name, value, children, space, names, namePath, index]);
62
- var _className = (0, _classnames2.default)((0, _defineProperty2.default)({
63
- 'pro-group': true,
64
- 'pro-group-diy-width': columns.some(function (item) {
65
- var _item$fieldProps, _item$fieldProps$styl;
66
- return item === null || item === void 0 ? void 0 : (_item$fieldProps = item.fieldProps) === null || _item$fieldProps === void 0 ? void 0 : (_item$fieldProps$styl = _item$fieldProps.style) === null || _item$fieldProps$styl === void 0 ? void 0 : _item$fieldProps$styl.width;
67
- }),
68
- 'pro-group-width-auto': columns.some(function (item) {
69
- return ['Radio', 'Checkbox', 'Switch'].includes(item.type);
70
- })
71
- }, "".concat(className), className));
72
- return (0, _jsxRuntime.jsx)("div", {
73
- className: _className,
74
- children: space.compact || (space === null || space === void 0 ? void 0 : space.separator) ? (0, _jsxRuntime.jsx)(_antd.Space.Compact, {
75
- children: columns.map(function (column) {
76
- return (0, _jsxRuntime.jsx)(_ComRender.default, (0, _objectSpread2.default)({
77
- contextProps: contextProps
78
- }, column));
79
- })
80
- }) : (0, _jsxRuntime.jsx)(_antd.Space, (0, _objectSpread2.default)((0, _objectSpread2.default)({
81
- align: "start"
82
- }, (0, _lodash.omit)(space, ['separator', 'compact'])), {}, {
83
- children: columns.map(function (column, index) {
84
- return (0, _jsxRuntime.jsx)(_ComRender.default, (0, _objectSpread2.default)({
85
- contextProps: contextProps
86
- }, column));
87
- })
88
- }))
89
- });
90
- };
91
- var _default = exports.default = GroupCopy;
@@ -1,47 +0,0 @@
1
- import React from 'react';
2
- import { FormItemProps, ModalFuncProps, SpaceProps } from 'antd';
3
- import { FormInstance } from 'antd/es/form/Form';
4
- import { NamePath } from 'antd/lib/form/interface';
5
- import { ColumnPropsMap, FunctionArgs, ProFormValueType, ReactiveFunction, ViewType } from '../../../propsType';
6
- export interface SpaceType extends SpaceProps {
7
- /**
8
- * 是否紧凑合并
9
- */
10
- compact?: Boolean;
11
- /**
12
- * 分隔符
13
- */
14
- separator?: string | React.ReactNode;
15
- /** 间隔距离 */
16
- size?: number;
17
- }
18
- export interface GroupProps {
19
- children?: GroupColumnProps[];
20
- space?: SpaceType;
21
- className?: string;
22
- id?: string;
23
- disabled?: boolean;
24
- isView?: boolean;
25
- value?: any[];
26
- onChange?: (value: any[] | null, options?: any[]) => void;
27
- }
28
- export type GroupColumnProps<Values = any> = {
29
- component?: React.ReactNode | ReactiveFunction<Values, React.ReactNode>;
30
- names?: NamePath[];
31
- show?: boolean | ReactiveFunction<Values, boolean>;
32
- valueType?: ProFormValueType;
33
- switchValue?: [any, any];
34
- isView?: boolean;
35
- viewRender?: (value: any, record: Values, { form, index, namePath, }: {
36
- form: FormInstance<Values>;
37
- index?: number | undefined;
38
- [key: string]: any;
39
- }) => React.ReactElement<any, any> | string | undefined | null;
40
- viewType?: ViewType;
41
- disabled?: boolean | ReactiveFunction<Values, boolean>;
42
- trim?: boolean;
43
- upperCase?: boolean;
44
- toISOString?: boolean;
45
- clearNotShow?: boolean;
46
- confirm?: boolean | ModalFuncProps | FunctionArgs<Values, boolean | ModalFuncProps>;
47
- } & ColumnPropsMap & FormItemProps;
@@ -1,53 +0,0 @@
1
- /// <reference types="react" />
2
- import { InternalNamePath, NamePath } from 'antd/lib/form/interface';
3
- import { FormInstance } from 'antd';
4
- import { GroupColumnProps, SpaceType } from './propsType';
5
- import { ProFormColumnProps, ReactiveFunction } from '../../render/propsType';
6
- export type EventArgs = any[];
7
- /**
8
- * 插入间隔符
9
- * @param columns 表单配置数组
10
- * @returns
11
- */
12
- export declare const insertSeparator: (columns: GroupColumnProps[], space?: SpaceType) => any[];
13
- /** 带出event的组件默认取值方法 */
14
- export declare function defaultGetValueFromEvent(valuePropName: string, ...args: EventArgs): any;
15
- /** 转换names */
16
- export declare const transformNamesString: (arr: (string | string[])[]) => (string | string[])[];
17
- interface Params {
18
- form?: FormInstance;
19
- index?: number;
20
- type?: string;
21
- namePath?: InternalNamePath;
22
- disabled?: boolean | ReactiveFunction<any, boolean>;
23
- show?: boolean | ReactiveFunction<any, boolean>;
24
- component?: React.ReactNode | ReactiveFunction<any, React.ReactNode>;
25
- fieldProps?: boolean | ReactiveFunction<any, boolean>;
26
- name?: NamePath;
27
- }
28
- /** 计算响应式参数的值 */
29
- export declare const getReactiveProps: (params: Params) => {
30
- disabled: boolean;
31
- show: boolean;
32
- component: any;
33
- fieldProps: boolean;
34
- };
35
- type ValueTypeGetterParams = Pick<ProFormColumnProps, 'valueType' | 'switchValue' | 'toISOString'> & {
36
- type?: any;
37
- mode?: string;
38
- };
39
- /** 获取当前字段的转换函数 */
40
- export declare const getValueTypeTrans: (params: ValueTypeGetterParams) => any;
41
- interface ColumnsTransformerParams {
42
- columns: GroupColumnProps[];
43
- name?: NamePath;
44
- names?: NamePath[];
45
- value?: any[];
46
- onChange: any;
47
- namePath?: InternalNamePath;
48
- form: FormInstance;
49
- index?: number;
50
- }
51
- /** 转换columns */
52
- export declare const transformColumns: (params: ColumnsTransformerParams) => any[];
53
- export {};
@@ -1,187 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.defaultGetValueFromEvent = defaultGetValueFromEvent;
8
- exports.transformNamesString = exports.transformColumns = exports.insertSeparator = exports.getValueTypeTrans = exports.getReactiveProps = void 0;
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
- var _jsxRuntime = require("react/jsx-runtime");
12
- var _lodash = require("lodash");
13
- var _antd = require("antd");
14
- var _valueType = _interopRequireDefault(require("../../../utils/valueType"));
15
- /**
16
- * 插入间隔符
17
- * @param columns 表单配置数组
18
- * @returns
19
- */
20
- var insertSeparator = exports.insertSeparator = function insertSeparator(columns, space) {
21
- if (!(space === null || space === void 0 ? void 0 : space.separator)) {
22
- return columns;
23
- }
24
- return columns.reduce(function (result, current, index, array) {
25
- // 将当前元素添加到结果数组中
26
- result.push(current);
27
- // 如果当前元素不是最后一个元素,则添加间隔符
28
- if (index < array.length - 1) {
29
- result.push({
30
- component: (0, _jsxRuntime.jsx)(_antd.Button, {
31
- className: "group-separator",
32
- children: space.separator
33
- }),
34
- fieldProps: {
35
- disabled: true
36
- }
37
- });
38
- }
39
- return result;
40
- }, []);
41
- };
42
- /** 带出event的组件默认取值方法 */
43
- function defaultGetValueFromEvent(valuePropName) {
44
- var event = arguments.length <= 1 ? undefined : arguments[1];
45
- if (event && event.target && (0, _typeof2.default)(event.target) === 'object' && valuePropName in event.target) {
46
- return event.target[valuePropName];
47
- }
48
- return event;
49
- }
50
- /** 转换names */
51
- var transformNamesString = exports.transformNamesString = function transformNamesString(arr) {
52
- var result = arr.map(function (subArr) {
53
- if (Array.isArray(subArr)) {
54
- return subArr.join('_');
55
- }
56
- return subArr;
57
- });
58
- return result;
59
- };
60
- /** 计算响应式参数的值 */
61
- var getReactiveProps = exports.getReactiveProps = function getReactiveProps(params) {
62
- var form = params.form,
63
- index = params.index,
64
- namePath = params.namePath,
65
- disabled = params.disabled,
66
- show = params.show,
67
- component = params.component,
68
- fieldProps = params.fieldProps,
69
- name = params.name;
70
- var values = form.getFieldsValue(namePath || undefined);
71
- var _disabled = (0, _lodash.isFunction)(disabled) ? disabled(values, {
72
- form: form,
73
- index: index,
74
- namePath: namePath
75
- }) : disabled;
76
- var _show = (0, _lodash.isFunction)(show) ? show(values, {
77
- form: form,
78
- index: index,
79
- namePath: namePath
80
- }) : show;
81
- var _component = (0, _lodash.isFunction)(component) ? component(values, {
82
- form: form,
83
- index: index,
84
- namePath: namePath
85
- }) : component;
86
- var _fieldProps = (0, _lodash.isFunction)(fieldProps) ? fieldProps(values, {
87
- form: form,
88
- index: index,
89
- namePath: namePath
90
- }) : fieldProps;
91
- return {
92
- disabled: _disabled,
93
- show: _show,
94
- component: _component,
95
- fieldProps: _fieldProps
96
- };
97
- };
98
- /** 获取当前字段的转换函数 */
99
- var getValueTypeTrans = exports.getValueTypeTrans = function getValueTypeTrans(params) {
100
- var _valueTypeMap$valueTy;
101
- var valueType = params.valueType;
102
- var transform = (_valueTypeMap$valueTy = _valueType.default[valueType]) === null || _valueTypeMap$valueTy === void 0 ? void 0 : _valueTypeMap$valueTy.call(_valueType.default, params);
103
- return transform;
104
- };
105
- /** 转换columns */
106
- var transformColumns = exports.transformColumns = function transformColumns(params) {
107
- var form = params.form,
108
- columns = params.columns,
109
- name = params.name,
110
- names = params.names,
111
- outerIndex = params.index,
112
- namePath = params.namePath,
113
- value = params.value,
114
- internalChange = params.onChange;
115
- return columns === null || columns === void 0 ? void 0 : columns.flatMap(function (column, index) {
116
- var type = column.type,
117
- valueType = column.valueType,
118
- switchValue = column.switchValue,
119
- toISOString = column.toISOString,
120
- fieldProps = column.fieldProps,
121
- getValueFromEvent = column.getValueFromEvent,
122
- _column$valuePropName = column.valuePropName,
123
- valuePropName = _column$valuePropName === void 0 ? 'value' : _column$valuePropName,
124
- normalize = column.normalize,
125
- disabled = column.disabled,
126
- show = column.show,
127
- component = column.component;
128
- var _ref = fieldProps || {},
129
- mode = _ref.mode,
130
- onChange = _ref.onChange,
131
- onFieldChange = _ref.onFieldChange,
132
- comDisabled = _ref.disabled;
133
- var _disabled = disabled !== null && disabled !== void 0 ? disabled : comDisabled;
134
- var columnName = names ? names[index] : [].concat(name, index);
135
- // 响应式字段
136
- var reactiveProps = getReactiveProps({
137
- form: form,
138
- index: index,
139
- type: type,
140
- namePath: namePath,
141
- disabled: _disabled,
142
- show: show,
143
- component: component,
144
- fieldProps: fieldProps,
145
- name: columnName
146
- });
147
- if (reactiveProps.show === false) return [];
148
- var transform = getValueTypeTrans({
149
- type: type,
150
- valueType: valueType,
151
- switchValue: switchValue,
152
- toISOString: toISOString,
153
- mode: mode
154
- });
155
- var newValue;
156
- var handleChange = function handleChange() {
157
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
158
- args[_key] = arguments[_key];
159
- }
160
- if (getValueFromEvent) {
161
- newValue = getValueFromEvent.apply(void 0, args);
162
- } else {
163
- newValue = defaultGetValueFromEvent.apply(void 0, [valuePropName].concat(args));
164
- }
165
- if ((transform === null || transform === void 0 ? void 0 : transform.normalize) || normalize) {
166
- var _transform$normalize;
167
- // @ts-ignore
168
- newValue = ((_transform$normalize = transform.normalize) === null || _transform$normalize === void 0 ? void 0 : _transform$normalize.call(transform, newValue)) || (normalize === null || normalize === void 0 ? void 0 : normalize(newValue));
169
- }
170
- internalChange === null || internalChange === void 0 ? void 0 : internalChange(newValue, args[1], index);
171
- onChange === null || onChange === void 0 ? void 0 : onChange.apply(void 0, args);
172
- onFieldChange === null || onFieldChange === void 0 ? void 0 : onFieldChange(newValue, form.getFieldValue(namePath), {
173
- index: outerIndex,
174
- namePath: namePath,
175
- form: form
176
- });
177
- };
178
- return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, column), {}, {
179
- name: columnName
180
- }, reactiveProps), {}, {
181
- fieldProps: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, column === null || column === void 0 ? void 0 : column.fieldProps), {}, {
182
- onChange: handleChange,
183
- value: value === null || value === void 0 ? void 0 : value[index]
184
- })
185
- });
186
- });
187
- };