iglooform 3.2.4 → 3.2.5
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/es/form/element/index.js +1 -1
- package/es/form/elements.d.ts +1 -2
- package/es/form/elements.js +3 -23
- package/es/utils/form-utils.d.ts +1 -1
- package/es/utils/form-utils.js +25 -17
- package/lib/form/element/index.js +1 -1
- package/lib/form/elements.d.ts +1 -2
- package/lib/form/elements.js +3 -22
- package/lib/utils/form-utils.d.ts +1 -1
- package/lib/utils/form-utils.js +26 -18
- package/package.json +1 -1
- package/es/hooks/useWrapperOnChangeForAutomaticCalc.d.ts +0 -5
- package/es/hooks/useWrapperOnChangeForAutomaticCalc.js +0 -26
- package/es/utils/form-methods.d.ts +0 -3
- package/lib/hooks/useWrapperOnChangeForAutomaticCalc.d.ts +0 -5
- package/lib/hooks/useWrapperOnChangeForAutomaticCalc.js +0 -34
- package/lib/utils/form-methods.d.ts +0 -3
package/es/form/element/index.js
CHANGED
|
@@ -114,7 +114,7 @@ var Element = function Element(_ref) {
|
|
|
114
114
|
registerDependencies(dependentField, dispatch);
|
|
115
115
|
}, []);
|
|
116
116
|
invariant(type !== 'Pages' && type !== 'Page', "".concat(type, " should not be inner form item"));
|
|
117
|
-
var _useComponent = useComponent(config
|
|
117
|
+
var _useComponent = useComponent(config),
|
|
118
118
|
Component = _useComponent.Component,
|
|
119
119
|
extraConfig = _useComponent.formItemProps,
|
|
120
120
|
withoutForm = _useComponent.withoutForm;
|
package/es/form/elements.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NamePath } from 'antd/es/form/interface';
|
|
2
1
|
import { FormItemConfig, FormItemExtraConfig } from '../types';
|
|
3
|
-
type UseComponentHook = (config: FormItemConfig
|
|
2
|
+
type UseComponentHook = (config: FormItemConfig) => {
|
|
4
3
|
Component: any;
|
|
5
4
|
formItemProps: FormItemExtraConfig;
|
|
6
5
|
withoutForm: boolean;
|
package/es/form/elements.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
var _excluded = ["onChange"];
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
1
|
import { useMemo, useContext } from 'react';
|
|
11
2
|
import Button from "../button";
|
|
12
3
|
import Checkbox, { CheckboxGroup } from "../checkbox";
|
|
@@ -24,8 +15,6 @@ import Upload from "../upload";
|
|
|
24
15
|
import UploadPhoto from "../upload-photo";
|
|
25
16
|
import Divider from "./divider";
|
|
26
17
|
import RenderElement from "./render";
|
|
27
|
-
import useWrapperOnChangeForAutomaticCalc from "../hooks/useWrapperOnChangeForAutomaticCalc";
|
|
28
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
18
|
var elementMap = {
|
|
30
19
|
Input: Input,
|
|
31
20
|
PhoneNumber: PhoneNumber,
|
|
@@ -64,13 +53,12 @@ var elementMap = {
|
|
|
64
53
|
var Unknown = function Unknown() {
|
|
65
54
|
return 'Unknown Form Item';
|
|
66
55
|
};
|
|
67
|
-
var useComponent = function useComponent(config
|
|
56
|
+
var useComponent = function useComponent(config) {
|
|
68
57
|
var _useContext = useContext(formContext),
|
|
69
58
|
_useContext$customize = _useContext.customizeComponents,
|
|
70
59
|
customizeComponents = _useContext$customize === void 0 ? {} : _useContext$customize;
|
|
71
60
|
var type = config.type,
|
|
72
|
-
render = config.render
|
|
73
|
-
enableAutomaticCalc = config.enableAutomaticCalc;
|
|
61
|
+
render = config.render;
|
|
74
62
|
if (!type && !render) {
|
|
75
63
|
return {
|
|
76
64
|
Component: Unknown,
|
|
@@ -81,16 +69,8 @@ var useComponent = function useComponent(config, parentName) {
|
|
|
81
69
|
return useMemo(function () {
|
|
82
70
|
var Component = type ? elementMap[type] || customizeComponents[type] || Unknown : RenderElement;
|
|
83
71
|
var formItemProps = typeof Component.formItemPropsHandler === 'function' ? Component.formItemPropsHandler(config) : {};
|
|
84
|
-
var WrapperComponent = function WrapperComponent(_ref) {
|
|
85
|
-
var onChange = _ref.onChange,
|
|
86
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
87
|
-
var handleOnChange = useWrapperOnChangeForAutomaticCalc(config, parentName, onChange);
|
|
88
|
-
return /*#__PURE__*/_jsx(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
89
|
-
onChange: handleOnChange
|
|
90
|
-
}));
|
|
91
|
-
};
|
|
92
72
|
return {
|
|
93
|
-
Component:
|
|
73
|
+
Component: Component,
|
|
94
74
|
formItemProps: formItemProps,
|
|
95
75
|
withoutForm: type === 'Divider' || Boolean(config.withoutForm) || config.name === undefined
|
|
96
76
|
};
|
package/es/utils/form-utils.d.ts
CHANGED
|
@@ -74,6 +74,6 @@ export declare const calcSelectValue: (selectValue?: FormItemSelectValue[], form
|
|
|
74
74
|
disabled: boolean | undefined;
|
|
75
75
|
};
|
|
76
76
|
export declare const calcShouldRender: (name: NamePath, parentName: NamePath, dependencies?: NamePath[], asserts?: FormItemAssert[], shouldRender?: ((form?: FormInstance) => boolean) | undefined, shouldRenderCode?: string, form?: FormInstance) => any;
|
|
77
|
-
export declare const
|
|
77
|
+
export declare const automaticCalculate: (name: NamePath, parentName: NamePath, automaticCalcCode?: string, form?: FormInstance) => void;
|
|
78
78
|
export declare const getRuleValidation: (url: string, rule: string | string[], values?: any, lang?: string) => Promise<any>;
|
|
79
79
|
export declare const calcAddableSectionAssertField: (name: any[], field: FormItemAssert['field'], index: number, elements: FormItemConfig[] | React.ReactElement[]) => any;
|
package/es/utils/form-utils.js
CHANGED
|
@@ -23,7 +23,7 @@ import invariant from 'invariant';
|
|
|
23
23
|
import Typography from "../typography";
|
|
24
24
|
import FormattedMessage from "../locale/formatted-message";
|
|
25
25
|
import moment from 'dayjs';
|
|
26
|
-
import { get } from 'lodash';
|
|
26
|
+
import { get, isEqual } from 'lodash';
|
|
27
27
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
28
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
29
|
export var calcNamePath = function calcNamePath(parentName, name) {
|
|
@@ -322,6 +322,9 @@ export var calcFormItemProps = function calcFormItemProps(config, extraProps, fo
|
|
|
322
322
|
};
|
|
323
323
|
})));
|
|
324
324
|
}
|
|
325
|
+
if (enableAutomaticCalc) {
|
|
326
|
+
automaticCalculate(name, parentName, automaticCalcCode, form);
|
|
327
|
+
}
|
|
325
328
|
return {
|
|
326
329
|
colProps: {
|
|
327
330
|
span: extraFullRow && fullRow === undefined || fullRow || extraHalfRow && halfRow === undefined || halfRow ? 24 : span || extraSpan || 12,
|
|
@@ -384,9 +387,9 @@ export var calcDisabled = function calcDisabled(disabled, form, disabledCode, na
|
|
|
384
387
|
var fn = eval(disabledCode);
|
|
385
388
|
if (typeof fn === 'function') {
|
|
386
389
|
try {
|
|
387
|
-
var
|
|
390
|
+
var value = form.getFieldValue(name);
|
|
388
391
|
var values = form.getFieldsValue(true);
|
|
389
|
-
return fn(
|
|
392
|
+
return fn(value, values, {
|
|
390
393
|
moment: moment,
|
|
391
394
|
get: get
|
|
392
395
|
}, {
|
|
@@ -451,12 +454,12 @@ export var calcSelectValue = function calcSelectValue(selectValue, form) {
|
|
|
451
454
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
452
455
|
var select = _step2.value;
|
|
453
456
|
var assert = select.assert,
|
|
454
|
-
|
|
457
|
+
value = select.value,
|
|
455
458
|
disabled = select.disabled;
|
|
456
459
|
if (testAssert(form, assert)) {
|
|
457
460
|
return {
|
|
458
461
|
selected: true,
|
|
459
|
-
value:
|
|
462
|
+
value: value,
|
|
460
463
|
disabled: disabled
|
|
461
464
|
};
|
|
462
465
|
}
|
|
@@ -498,9 +501,9 @@ export var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
|
498
501
|
var fn = eval(shouldRenderCode);
|
|
499
502
|
if (typeof fn === 'function') {
|
|
500
503
|
try {
|
|
501
|
-
var
|
|
504
|
+
var value = form.getFieldValue(name);
|
|
502
505
|
var values = form.getFieldsValue(true);
|
|
503
|
-
return fn(
|
|
506
|
+
return fn(value, values, {
|
|
504
507
|
moment: moment,
|
|
505
508
|
get: get
|
|
506
509
|
}, {
|
|
@@ -527,25 +530,30 @@ export var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
|
527
530
|
}
|
|
528
531
|
return true;
|
|
529
532
|
};
|
|
530
|
-
export var
|
|
531
|
-
if (
|
|
532
|
-
if (automaticCalcCode) {
|
|
533
|
+
export var automaticCalculate = function automaticCalculate(name, parentName, automaticCalcCode, form) {
|
|
534
|
+
if (form && automaticCalcCode) {
|
|
533
535
|
var calcValue = undefined;
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
var
|
|
536
|
+
try {
|
|
537
|
+
var fn = eval(automaticCalcCode);
|
|
538
|
+
if (typeof fn === 'function') {
|
|
539
|
+
var value = form.getFieldValue(name);
|
|
538
540
|
var values = form.getFieldsValue(true);
|
|
539
|
-
calcValue = fn(
|
|
541
|
+
calcValue = fn(value, values, {
|
|
540
542
|
moment: moment,
|
|
541
543
|
get: get
|
|
542
544
|
}, {
|
|
543
545
|
name: name,
|
|
544
546
|
parentName: parentName
|
|
545
547
|
});
|
|
546
|
-
}
|
|
548
|
+
}
|
|
549
|
+
} catch (_unused4) {}
|
|
550
|
+
if (form && !isEqual(form === null || form === void 0 ? void 0 : form.getFieldValue(name), calcValue)) {
|
|
551
|
+
form.setFields([{
|
|
552
|
+
name: name,
|
|
553
|
+
value: calcValue
|
|
554
|
+
}]);
|
|
555
|
+
form.validateFields([name]);
|
|
547
556
|
}
|
|
548
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(calcValue, true);
|
|
549
557
|
}
|
|
550
558
|
};
|
|
551
559
|
export var getRuleValidation = /*#__PURE__*/function () {
|
|
@@ -120,7 +120,7 @@ var Element = function Element(_ref) {
|
|
|
120
120
|
registerDependencies(dependentField, dispatch);
|
|
121
121
|
}, []);
|
|
122
122
|
(0, _invariant.default)(type !== 'Pages' && type !== 'Page', "".concat(type, " should not be inner form item"));
|
|
123
|
-
var _useComponent = (0, _elements.default)(config
|
|
123
|
+
var _useComponent = (0, _elements.default)(config),
|
|
124
124
|
Component = _useComponent.Component,
|
|
125
125
|
extraConfig = _useComponent.formItemProps,
|
|
126
126
|
withoutForm = _useComponent.withoutForm;
|
package/lib/form/elements.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { NamePath } from 'antd/es/form/interface';
|
|
2
1
|
import { FormItemConfig, FormItemExtraConfig } from '../types';
|
|
3
|
-
type UseComponentHook = (config: FormItemConfig
|
|
2
|
+
type UseComponentHook = (config: FormItemConfig) => {
|
|
4
3
|
Component: any;
|
|
5
4
|
formItemProps: FormItemExtraConfig;
|
|
6
5
|
withoutForm: boolean;
|
package/lib/form/elements.js
CHANGED
|
@@ -22,19 +22,9 @@ var _upload = _interopRequireDefault(require("../upload"));
|
|
|
22
22
|
var _uploadPhoto = _interopRequireDefault(require("../upload-photo"));
|
|
23
23
|
var _divider = _interopRequireDefault(require("./divider"));
|
|
24
24
|
var _render = _interopRequireDefault(require("./render"));
|
|
25
|
-
var _useWrapperOnChangeForAutomaticCalc = _interopRequireDefault(require("../hooks/useWrapperOnChangeForAutomaticCalc"));
|
|
26
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
-
var _excluded = ["onChange"];
|
|
28
25
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
26
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
30
27
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
34
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
35
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
36
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
37
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
38
28
|
var elementMap = {
|
|
39
29
|
Input: _input.default,
|
|
40
30
|
PhoneNumber: _input.PhoneNumber,
|
|
@@ -73,13 +63,12 @@ var elementMap = {
|
|
|
73
63
|
var Unknown = function Unknown() {
|
|
74
64
|
return 'Unknown Form Item';
|
|
75
65
|
};
|
|
76
|
-
var useComponent = function useComponent(config
|
|
66
|
+
var useComponent = function useComponent(config) {
|
|
77
67
|
var _useContext = (0, _react.useContext)(_formContext.default),
|
|
78
68
|
_useContext$customize = _useContext.customizeComponents,
|
|
79
69
|
customizeComponents = _useContext$customize === void 0 ? {} : _useContext$customize;
|
|
80
70
|
var type = config.type,
|
|
81
|
-
render = config.render
|
|
82
|
-
enableAutomaticCalc = config.enableAutomaticCalc;
|
|
71
|
+
render = config.render;
|
|
83
72
|
if (!type && !render) {
|
|
84
73
|
return {
|
|
85
74
|
Component: Unknown,
|
|
@@ -90,16 +79,8 @@ var useComponent = function useComponent(config, parentName) {
|
|
|
90
79
|
return (0, _react.useMemo)(function () {
|
|
91
80
|
var Component = type ? elementMap[type] || customizeComponents[type] || Unknown : _render.default;
|
|
92
81
|
var formItemProps = typeof Component.formItemPropsHandler === 'function' ? Component.formItemPropsHandler(config) : {};
|
|
93
|
-
var WrapperComponent = function WrapperComponent(_ref) {
|
|
94
|
-
var onChange = _ref.onChange,
|
|
95
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
96
|
-
var handleOnChange = (0, _useWrapperOnChangeForAutomaticCalc.default)(config, parentName, onChange);
|
|
97
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
98
|
-
onChange: handleOnChange
|
|
99
|
-
}));
|
|
100
|
-
};
|
|
101
82
|
return {
|
|
102
|
-
Component:
|
|
83
|
+
Component: Component,
|
|
103
84
|
formItemProps: formItemProps,
|
|
104
85
|
withoutForm: type === 'Divider' || Boolean(config.withoutForm) || config.name === undefined
|
|
105
86
|
};
|
|
@@ -74,6 +74,6 @@ export declare const calcSelectValue: (selectValue?: FormItemSelectValue[], form
|
|
|
74
74
|
disabled: boolean | undefined;
|
|
75
75
|
};
|
|
76
76
|
export declare const calcShouldRender: (name: NamePath, parentName: NamePath, dependencies?: NamePath[], asserts?: FormItemAssert[], shouldRender?: ((form?: FormInstance) => boolean) | undefined, shouldRenderCode?: string, form?: FormInstance) => any;
|
|
77
|
-
export declare const
|
|
77
|
+
export declare const automaticCalculate: (name: NamePath, parentName: NamePath, automaticCalcCode?: string, form?: FormInstance) => void;
|
|
78
78
|
export declare const getRuleValidation: (url: string, rule: string | string[], values?: any, lang?: string) => Promise<any>;
|
|
79
79
|
export declare const calcAddableSectionAssertField: (name: any[], field: FormItemAssert['field'], index: number, elements: FormItemConfig[] | React.ReactElement[]) => any;
|
package/lib/utils/form-utils.js
CHANGED
|
@@ -4,7 +4,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.testAssert = exports.getRuleValidation = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = exports.
|
|
7
|
+
exports.testAssert = exports.getRuleValidation = exports.calcShouldRender = exports.calcSelectValue = exports.calcNamePath = exports.calcFormItemProps = exports.calcDisabled = exports.calcCopyValue = exports.calcAddableSectionAssertField = exports.automaticCalculate = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
10
10
|
var _typography = _interopRequireDefault(require("../typography"));
|
|
@@ -330,6 +330,9 @@ var calcFormItemProps = function calcFormItemProps(config, extraProps, form, par
|
|
|
330
330
|
};
|
|
331
331
|
})));
|
|
332
332
|
}
|
|
333
|
+
if (enableAutomaticCalc) {
|
|
334
|
+
automaticCalculate(name, parentName, automaticCalcCode, form);
|
|
335
|
+
}
|
|
333
336
|
return {
|
|
334
337
|
colProps: {
|
|
335
338
|
span: extraFullRow && fullRow === undefined || fullRow || extraHalfRow && halfRow === undefined || halfRow ? 24 : span || extraSpan || 12,
|
|
@@ -393,9 +396,9 @@ var calcDisabled = function calcDisabled(disabled, form, disabledCode, name, par
|
|
|
393
396
|
var fn = eval(disabledCode);
|
|
394
397
|
if (typeof fn === 'function') {
|
|
395
398
|
try {
|
|
396
|
-
var
|
|
399
|
+
var value = form.getFieldValue(name);
|
|
397
400
|
var values = form.getFieldsValue(true);
|
|
398
|
-
return fn(
|
|
401
|
+
return fn(value, values, {
|
|
399
402
|
moment: _dayjs.default,
|
|
400
403
|
get: _lodash.get
|
|
401
404
|
}, {
|
|
@@ -462,12 +465,12 @@ var calcSelectValue = function calcSelectValue(selectValue, form) {
|
|
|
462
465
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
463
466
|
var select = _step2.value;
|
|
464
467
|
var assert = select.assert,
|
|
465
|
-
|
|
468
|
+
value = select.value,
|
|
466
469
|
disabled = select.disabled;
|
|
467
470
|
if (testAssert(form, assert)) {
|
|
468
471
|
return {
|
|
469
472
|
selected: true,
|
|
470
|
-
value:
|
|
473
|
+
value: value,
|
|
471
474
|
disabled: disabled
|
|
472
475
|
};
|
|
473
476
|
}
|
|
@@ -510,9 +513,9 @@ var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
|
510
513
|
var fn = eval(shouldRenderCode);
|
|
511
514
|
if (typeof fn === 'function') {
|
|
512
515
|
try {
|
|
513
|
-
var
|
|
516
|
+
var value = form.getFieldValue(name);
|
|
514
517
|
var values = form.getFieldsValue(true);
|
|
515
|
-
return fn(
|
|
518
|
+
return fn(value, values, {
|
|
516
519
|
moment: _dayjs.default,
|
|
517
520
|
get: _lodash.get
|
|
518
521
|
}, {
|
|
@@ -540,28 +543,33 @@ var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
|
540
543
|
return true;
|
|
541
544
|
};
|
|
542
545
|
exports.calcShouldRender = calcShouldRender;
|
|
543
|
-
var
|
|
544
|
-
if (
|
|
545
|
-
if (automaticCalcCode) {
|
|
546
|
+
var automaticCalculate = function automaticCalculate(name, parentName, automaticCalcCode, form) {
|
|
547
|
+
if (form && automaticCalcCode) {
|
|
546
548
|
var calcValue = undefined;
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
var
|
|
549
|
+
try {
|
|
550
|
+
var fn = eval(automaticCalcCode);
|
|
551
|
+
if (typeof fn === 'function') {
|
|
552
|
+
var value = form.getFieldValue(name);
|
|
551
553
|
var values = form.getFieldsValue(true);
|
|
552
|
-
calcValue = fn(
|
|
554
|
+
calcValue = fn(value, values, {
|
|
553
555
|
moment: _dayjs.default,
|
|
554
556
|
get: _lodash.get
|
|
555
557
|
}, {
|
|
556
558
|
name: name,
|
|
557
559
|
parentName: parentName
|
|
558
560
|
});
|
|
559
|
-
}
|
|
561
|
+
}
|
|
562
|
+
} catch (_unused4) {}
|
|
563
|
+
if (form && !(0, _lodash.isEqual)(form === null || form === void 0 ? void 0 : form.getFieldValue(name), calcValue)) {
|
|
564
|
+
form.setFields([{
|
|
565
|
+
name: name,
|
|
566
|
+
value: calcValue
|
|
567
|
+
}]);
|
|
568
|
+
form.validateFields([name]);
|
|
560
569
|
}
|
|
561
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(calcValue, true);
|
|
562
570
|
}
|
|
563
571
|
};
|
|
564
|
-
exports.
|
|
572
|
+
exports.automaticCalculate = automaticCalculate;
|
|
565
573
|
var getRuleValidation = /*#__PURE__*/function () {
|
|
566
574
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, rule, values) {
|
|
567
575
|
var lang,
|
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { FormItemConfig } from '../types';
|
|
2
|
-
import { NamePath } from 'antd/es/form/interface';
|
|
3
|
-
type UseWrapperOnChangeForAutomaticCalcHook = (config: FormItemConfig, parentName: NamePath, onChange: any) => (value: any, automaticCalc?: boolean) => void;
|
|
4
|
-
declare const useWrapperOnChangeForAutomaticCalc: UseWrapperOnChangeForAutomaticCalcHook;
|
|
5
|
-
export default useWrapperOnChangeForAutomaticCalc;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useUpdateEffect } from '@umijs/hooks';
|
|
2
|
-
import { useContext } from 'react';
|
|
3
|
-
import { isEqual } from 'lodash';
|
|
4
|
-
import { calcAutomaticCalculate } from "../utils/form-utils";
|
|
5
|
-
import formContext from "../form-context";
|
|
6
|
-
var useWrapperOnChangeForAutomaticCalc = function useWrapperOnChangeForAutomaticCalc(config, parentName, onChange) {
|
|
7
|
-
var _useContext = useContext(formContext),
|
|
8
|
-
form = _useContext.form;
|
|
9
|
-
var name = config.name,
|
|
10
|
-
enableAutomaticCalc = config.enableAutomaticCalc,
|
|
11
|
-
automaticCalcCode = config.automaticCalcCode;
|
|
12
|
-
var handleOnChange = function handleOnChange(value) {
|
|
13
|
-
var automaticCalc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
14
|
-
if (automaticCalc && isEqual(form === null || form === void 0 ? void 0 : form.getFieldValue(name), value)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
onChange(value);
|
|
18
|
-
};
|
|
19
|
-
useUpdateEffect(function () {
|
|
20
|
-
if (form && enableAutomaticCalc && automaticCalcCode) {
|
|
21
|
-
calcAutomaticCalculate(name, parentName, automaticCalcCode, form, handleOnChange);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return handleOnChange;
|
|
25
|
-
};
|
|
26
|
-
export default useWrapperOnChangeForAutomaticCalc;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { FormItemConfig } from '../types';
|
|
2
|
-
import { NamePath } from 'antd/es/form/interface';
|
|
3
|
-
type UseWrapperOnChangeForAutomaticCalcHook = (config: FormItemConfig, parentName: NamePath, onChange: any) => (value: any, automaticCalc?: boolean) => void;
|
|
4
|
-
declare const useWrapperOnChangeForAutomaticCalc: UseWrapperOnChangeForAutomaticCalcHook;
|
|
5
|
-
export default useWrapperOnChangeForAutomaticCalc;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _hooks = require("@umijs/hooks");
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _lodash = require("lodash");
|
|
10
|
-
var _formUtils = require("../utils/form-utils");
|
|
11
|
-
var _formContext = _interopRequireDefault(require("../form-context"));
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
var useWrapperOnChangeForAutomaticCalc = function useWrapperOnChangeForAutomaticCalc(config, parentName, onChange) {
|
|
14
|
-
var _useContext = (0, _react.useContext)(_formContext.default),
|
|
15
|
-
form = _useContext.form;
|
|
16
|
-
var name = config.name,
|
|
17
|
-
enableAutomaticCalc = config.enableAutomaticCalc,
|
|
18
|
-
automaticCalcCode = config.automaticCalcCode;
|
|
19
|
-
var handleOnChange = function handleOnChange(value) {
|
|
20
|
-
var automaticCalc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
21
|
-
if (automaticCalc && (0, _lodash.isEqual)(form === null || form === void 0 ? void 0 : form.getFieldValue(name), value)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
onChange(value);
|
|
25
|
-
};
|
|
26
|
-
(0, _hooks.useUpdateEffect)(function () {
|
|
27
|
-
if (form && enableAutomaticCalc && automaticCalcCode) {
|
|
28
|
-
(0, _formUtils.calcAutomaticCalculate)(name, parentName, automaticCalcCode, form, handleOnChange);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
return handleOnChange;
|
|
32
|
-
};
|
|
33
|
-
var _default = useWrapperOnChangeForAutomaticCalc;
|
|
34
|
-
exports.default = _default;
|