iglooform 3.2.2 → 3.2.4
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/.dumi/tmp/core/defineApp.ts +1 -1
- package/.dumi/tmp/core/helmet.ts +1 -1
- package/.dumi/tmp/core/history.ts +1 -1
- package/.dumi/tmp/core/historyIntelli.ts +1 -1
- package/.dumi/tmp/core/plugin.ts +2 -2
- package/.dumi/tmp/core/polyfill.ts +197 -197
- package/.dumi/tmp/core/route.tsx +33 -33
- package/.dumi/tmp/dumi/exports.ts +1 -1
- package/.dumi/tmp/dumi/locales/runtime.tsx +2 -2
- package/.dumi/tmp/dumi/meta/index.ts +33 -33
- package/.dumi/tmp/dumi/meta/runtime.ts +1 -1
- package/.dumi/tmp/dumi/theme/ContextWrapper.tsx +2 -2
- package/.dumi/tmp/dumi/theme/builtins/API.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Badge.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Container.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Previewer.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/SourceCode.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Table.ts +1 -1
- package/.dumi/tmp/dumi/theme/builtins/Tree.ts +1 -1
- package/.dumi/tmp/dumi/theme/layouts/DocLayout.ts +1 -1
- package/.dumi/tmp/dumi/theme/loading.tsx +1 -1
- package/.dumi/tmp/dumi/theme/slots/ColorSwitch.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Content.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/ContentFooter.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/ContentTabs.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Features.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Footer.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Header.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/HeaderExtra.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Hero.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/HeroTitle.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/LangSwitch.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Logo.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Navbar.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/NavbarExtra.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/NotFound.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/PreviewerActions.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/PreviewerActionsExtra.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/RtlSwitch.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/SearchBar.ts +2 -2
- package/.dumi/tmp/dumi/theme/slots/SearchResult.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Sidebar.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/SocialIcon.ts +1 -1
- package/.dumi/tmp/dumi/theme/slots/Toc.ts +1 -1
- package/.dumi/tmp/exports.ts +5 -5
- package/.dumi/tmp/testBrowser.tsx +3 -3
- package/.dumi/tmp/umi.ts +4 -4
- package/es/date-picker/buddhist.d.ts +6 -0
- package/es/form/element/index.js +5 -3
- package/es/form/elements.d.ts +2 -1
- package/es/form/elements.js +33 -13
- package/es/free-form/element/index.js +4 -2
- package/es/hooks/useWrapperOnChangeForAutomaticCalc.d.ts +5 -0
- package/es/hooks/useWrapperOnChangeForAutomaticCalc.js +26 -0
- package/es/utils/form-utils.d.ts +1 -0
- package/es/utils/form-utils.js +31 -8
- package/lib/date-picker/buddhist.d.ts +6 -0
- package/lib/form/element/index.js +5 -3
- package/lib/form/elements.d.ts +2 -1
- package/lib/form/elements.js +32 -13
- package/lib/free-form/element/index.js +4 -2
- package/lib/hooks/useWrapperOnChangeForAutomaticCalc.d.ts +5 -0
- package/lib/hooks/useWrapperOnChangeForAutomaticCalc.js +34 -0
- package/lib/utils/form-utils.d.ts +1 -0
- package/lib/utils/form-utils.js +33 -9
- package/package.json +1 -1
- package/es/confirmation/style/index.d.ts +0 -1
- package/es/types.d.ts +0 -185
- package/lib/confirmation/style/index.d.ts +0 -1
- package/lib/types.d.ts +0 -185
package/es/form/element/index.js
CHANGED
|
@@ -69,7 +69,9 @@ var Element = function Element(_ref) {
|
|
|
69
69
|
extraLabel = config.extraLabel,
|
|
70
70
|
requiredAsserts = config.requiredAsserts,
|
|
71
71
|
shouldRenderCode = config.shouldRenderCode,
|
|
72
|
-
disabledCode = config.disabledCode
|
|
72
|
+
disabledCode = config.disabledCode,
|
|
73
|
+
automaticCalcCode = config.automaticCalcCode,
|
|
74
|
+
enableAutomaticCalc = config.enableAutomaticCalc;
|
|
73
75
|
var dependentField = dependencies || [];
|
|
74
76
|
if (Array.isArray(subscribedFields)) {
|
|
75
77
|
dependentField.push.apply(dependentField, _toConsumableArray(subscribedFields));
|
|
@@ -95,7 +97,7 @@ var Element = function Element(_ref) {
|
|
|
95
97
|
return dependentField.push(assert.field);
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
if ((shouldRender || shouldRenderCode || disabledCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
100
|
+
if ((shouldRender || shouldRenderCode || disabledCode || enableAutomaticCalc && automaticCalcCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
99
101
|
dependentField.push('SUBSCRIBE_ALL');
|
|
100
102
|
}
|
|
101
103
|
if (dependField) {
|
|
@@ -112,7 +114,7 @@ var Element = function Element(_ref) {
|
|
|
112
114
|
registerDependencies(dependentField, dispatch);
|
|
113
115
|
}, []);
|
|
114
116
|
invariant(type !== 'Pages' && type !== 'Page', "".concat(type, " should not be inner form item"));
|
|
115
|
-
var _useComponent = useComponent(config),
|
|
117
|
+
var _useComponent = useComponent(config, parentName),
|
|
116
118
|
Component = _useComponent.Component,
|
|
117
119
|
extraConfig = _useComponent.formItemProps,
|
|
118
120
|
withoutForm = _useComponent.withoutForm;
|
package/es/form/elements.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { NamePath } from 'antd/es/form/interface';
|
|
1
2
|
import { FormItemConfig, FormItemExtraConfig } from '../types';
|
|
2
|
-
type UseComponentHook = (config: FormItemConfig) => {
|
|
3
|
+
type UseComponentHook = (config: FormItemConfig, parentName: NamePath) => {
|
|
3
4
|
Component: any;
|
|
4
5
|
formItemProps: FormItemExtraConfig;
|
|
5
6
|
withoutForm: boolean;
|
package/es/form/elements.js
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
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; }
|
|
1
10
|
import { useMemo, useContext } from 'react';
|
|
2
11
|
import Button from "../button";
|
|
3
|
-
import
|
|
4
|
-
import Input, { PhoneNumber, Amount, Email, Password, InputNumber, TextArea, InputDate, CreditCard, Otp, ExpiryDate, InputId } from "../input";
|
|
5
|
-
import DatePicker, { IglooBuddhistDatePicker as BuddhistDatePicker, IglooRangePicker as RangePicker, IglooWeekPicker as WeekPicker, IglooMonthPicker as MonthPicker } from "../date-picker";
|
|
12
|
+
import Checkbox, { CheckboxGroup } from "../checkbox";
|
|
6
13
|
import Confirmation from "../confirmation";
|
|
14
|
+
import DatePicker, { IglooBuddhistDatePicker as BuddhistDatePicker, IglooRangePicker as RangePicker, IglooWeekPicker as WeekPicker, IglooMonthPicker as MonthPicker } from "../date-picker";
|
|
15
|
+
import Declaration from "../declaration";
|
|
16
|
+
import formContext from "../form-context";
|
|
17
|
+
import Input, { PhoneNumber, Amount, Email, Password, InputNumber, TextArea, InputDate, CreditCard, Otp, ExpiryDate, InputId } from "../input";
|
|
18
|
+
import OCR from "../ocr";
|
|
19
|
+
import Radio, { RadioGroup, RadioGroupWithOther } from "../radio";
|
|
20
|
+
import SearchBox from "../search-box";
|
|
7
21
|
import { AttachedSelect as Select, TimeSelect } from "../select";
|
|
8
|
-
import
|
|
22
|
+
import Typography from "../typography";
|
|
9
23
|
import Upload from "../upload";
|
|
10
|
-
import Declaration from "../declaration";
|
|
11
|
-
import Divider from "./divider";
|
|
12
24
|
import UploadPhoto from "../upload-photo";
|
|
25
|
+
import Divider from "./divider";
|
|
13
26
|
import RenderElement from "./render";
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import formContext from "../form-context";
|
|
17
|
-
import OCR from "../ocr";
|
|
27
|
+
import useWrapperOnChangeForAutomaticCalc from "../hooks/useWrapperOnChangeForAutomaticCalc";
|
|
28
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
29
|
var elementMap = {
|
|
19
30
|
Input: Input,
|
|
20
31
|
PhoneNumber: PhoneNumber,
|
|
@@ -53,12 +64,13 @@ var elementMap = {
|
|
|
53
64
|
var Unknown = function Unknown() {
|
|
54
65
|
return 'Unknown Form Item';
|
|
55
66
|
};
|
|
56
|
-
var useComponent = function useComponent(config) {
|
|
67
|
+
var useComponent = function useComponent(config, parentName) {
|
|
57
68
|
var _useContext = useContext(formContext),
|
|
58
69
|
_useContext$customize = _useContext.customizeComponents,
|
|
59
70
|
customizeComponents = _useContext$customize === void 0 ? {} : _useContext$customize;
|
|
60
71
|
var type = config.type,
|
|
61
|
-
render = config.render
|
|
72
|
+
render = config.render,
|
|
73
|
+
enableAutomaticCalc = config.enableAutomaticCalc;
|
|
62
74
|
if (!type && !render) {
|
|
63
75
|
return {
|
|
64
76
|
Component: Unknown,
|
|
@@ -69,8 +81,16 @@ var useComponent = function useComponent(config) {
|
|
|
69
81
|
return useMemo(function () {
|
|
70
82
|
var Component = type ? elementMap[type] || customizeComponents[type] || Unknown : RenderElement;
|
|
71
83
|
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
|
+
};
|
|
72
92
|
return {
|
|
73
|
-
Component: Component,
|
|
93
|
+
Component: enableAutomaticCalc ? WrapperComponent : Component,
|
|
74
94
|
formItemProps: formItemProps,
|
|
75
95
|
withoutForm: type === 'Divider' || Boolean(config.withoutForm) || config.name === undefined
|
|
76
96
|
};
|
|
@@ -63,7 +63,9 @@ var Element = function Element(props) {
|
|
|
63
63
|
disabled = props.disabled,
|
|
64
64
|
requiredAsserts = props.requiredAsserts,
|
|
65
65
|
shouldRenderCode = props.shouldRenderCode,
|
|
66
|
-
disabledCode = props.disabledCode
|
|
66
|
+
disabledCode = props.disabledCode,
|
|
67
|
+
automaticCalcCode = props.automaticCalcCode,
|
|
68
|
+
enableAutomaticCalc = props.enableAutomaticCalc;
|
|
67
69
|
var dependentField = dependencies || [];
|
|
68
70
|
if (Array.isArray(subscribedFields)) {
|
|
69
71
|
dependentField.push.apply(dependentField, _toConsumableArray(subscribedFields));
|
|
@@ -89,7 +91,7 @@ var Element = function Element(props) {
|
|
|
89
91
|
return dependentField.push(assert.field);
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
|
-
if ((shouldRender || shouldRenderCode || disabledCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
94
|
+
if ((shouldRender || shouldRenderCode || disabledCode || enableAutomaticCalc && automaticCalcCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
93
95
|
dependentField.push('SUBSCRIBE_ALL');
|
|
94
96
|
}
|
|
95
97
|
if (dependField) {
|
|
@@ -0,0 +1,5 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
package/es/utils/form-utils.d.ts
CHANGED
|
@@ -74,5 +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 calcAutomaticCalculate: (name: NamePath, parentName: NamePath, automaticCalcCode?: string, form?: FormInstance, onChange?: ((value: any, automaticCalc?: boolean) => any) | undefined) => undefined;
|
|
77
78
|
export declare const getRuleValidation: (url: string, rule: string | string[], values?: any, lang?: string) => Promise<any>;
|
|
78
79
|
export declare const calcAddableSectionAssertField: (name: any[], field: FormItemAssert['field'], index: number, elements: FormItemConfig[] | React.ReactElement[]) => any;
|
package/es/utils/form-utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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 = ["type", "name", "required", "requiredAsserts", "showOptional", "rules", "initialValue", "normalize", "mergeRules", "getValueFromEvent", "getValueProps", "extra", "help", "label", "previewLabel", "extraLabel", "copyValue", "selectValue", "span", "halfRow", "fullRow", "valuePropName", "dependencies", "asserts", "messageVariables", "requiredMessage", "previewFormater", "disabled", "ignore", "shouldRender", "valueFormater", "antdDependencies", "dateLimitationType", "absoluteRangeEnd", "absoluteRangeStart", "relativeRangeStart", "relativeRangeEnd", "validationCode", "shouldRenderCode", "disabledCode"],
|
|
2
|
+
var _excluded = ["type", "name", "required", "requiredAsserts", "showOptional", "rules", "initialValue", "normalize", "mergeRules", "getValueFromEvent", "getValueProps", "extra", "help", "label", "previewLabel", "extraLabel", "copyValue", "selectValue", "span", "halfRow", "fullRow", "valuePropName", "dependencies", "asserts", "messageVariables", "requiredMessage", "previewFormater", "disabled", "ignore", "shouldRender", "valueFormater", "antdDependencies", "dateLimitationType", "absoluteRangeEnd", "absoluteRangeStart", "relativeRangeStart", "relativeRangeEnd", "validationCode", "shouldRenderCode", "disabledCode", "automaticCalcCode", "enableAutomaticCalc"],
|
|
3
3
|
_excluded2 = ["initialValue", "normalize", "rules", "extra", "help", "getValueFromEvent", "span", "valuePropName", "fullRow", "halfRow", "messageVariables", "requiredMessage", "previewFormater", "valueFormater", "required", "requiredMark", "className"];
|
|
4
4
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
5
5
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
@@ -173,6 +173,8 @@ export var calcFormItemProps = function calcFormItemProps(config, extraProps, fo
|
|
|
173
173
|
validationCode = _config$validationCod === void 0 ? [] : _config$validationCod,
|
|
174
174
|
shouldRenderCode = config.shouldRenderCode,
|
|
175
175
|
disabledCode = config.disabledCode,
|
|
176
|
+
automaticCalcCode = config.automaticCalcCode,
|
|
177
|
+
enableAutomaticCalc = config.enableAutomaticCalc,
|
|
176
178
|
rest = _objectWithoutProperties(config, _excluded);
|
|
177
179
|
invariant(nameProp !== undefined || type === 'Divider' || type === 'Section' || type === 'Typography' || type === 'OCR' || !type, "name property is required for form item config (type: ".concat(type, ")"));
|
|
178
180
|
invariant(!previewFormater || typeof previewFormater === 'function', 'previewFormater property should be a function');
|
|
@@ -224,7 +226,7 @@ export var calcFormItemProps = function calcFormItemProps(config, extraProps, fo
|
|
|
224
226
|
Object.keys(_objectSpread(_objectSpread({}, extraRest), rest)).forEach(function (key) {
|
|
225
227
|
elementProps[key.replace('element-', '')] = rest[key];
|
|
226
228
|
});
|
|
227
|
-
elementProps.disabled = calcDisabled(disabled, form, disabledCode, name, parentName) || copiedValue.disabled || selectedValue.disabled;
|
|
229
|
+
elementProps.disabled = enableAutomaticCalc || calcDisabled(disabled, form, disabledCode, name, parentName) || copiedValue.disabled || selectedValue.disabled;
|
|
228
230
|
if (dateLimitationType) {
|
|
229
231
|
var rangeStart;
|
|
230
232
|
var rangeEnd;
|
|
@@ -382,9 +384,9 @@ export var calcDisabled = function calcDisabled(disabled, form, disabledCode, na
|
|
|
382
384
|
var fn = eval(disabledCode);
|
|
383
385
|
if (typeof fn === 'function') {
|
|
384
386
|
try {
|
|
385
|
-
var
|
|
387
|
+
var _value = form.getFieldValue(name);
|
|
386
388
|
var values = form.getFieldsValue(true);
|
|
387
|
-
return fn(
|
|
389
|
+
return fn(_value, values, {
|
|
388
390
|
moment: moment,
|
|
389
391
|
get: get
|
|
390
392
|
}, {
|
|
@@ -449,12 +451,12 @@ export var calcSelectValue = function calcSelectValue(selectValue, form) {
|
|
|
449
451
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
450
452
|
var select = _step2.value;
|
|
451
453
|
var assert = select.assert,
|
|
452
|
-
|
|
454
|
+
_value2 = select.value,
|
|
453
455
|
disabled = select.disabled;
|
|
454
456
|
if (testAssert(form, assert)) {
|
|
455
457
|
return {
|
|
456
458
|
selected: true,
|
|
457
|
-
value:
|
|
459
|
+
value: _value2,
|
|
458
460
|
disabled: disabled
|
|
459
461
|
};
|
|
460
462
|
}
|
|
@@ -496,9 +498,9 @@ export var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
|
496
498
|
var fn = eval(shouldRenderCode);
|
|
497
499
|
if (typeof fn === 'function') {
|
|
498
500
|
try {
|
|
499
|
-
var
|
|
501
|
+
var _value3 = form.getFieldValue(name);
|
|
500
502
|
var values = form.getFieldsValue(true);
|
|
501
|
-
return fn(
|
|
503
|
+
return fn(_value3, values, {
|
|
502
504
|
moment: moment,
|
|
503
505
|
get: get
|
|
504
506
|
}, {
|
|
@@ -525,6 +527,27 @@ export var calcShouldRender = function calcShouldRender(name, parentName) {
|
|
|
525
527
|
}
|
|
526
528
|
return true;
|
|
527
529
|
};
|
|
530
|
+
export var calcAutomaticCalculate = function calcAutomaticCalculate(name, parentName, automaticCalcCode, form, onChange) {
|
|
531
|
+
if (!form) return undefined;
|
|
532
|
+
if (automaticCalcCode) {
|
|
533
|
+
var calcValue = undefined;
|
|
534
|
+
var fn = eval(automaticCalcCode);
|
|
535
|
+
if (typeof fn === 'function') {
|
|
536
|
+
try {
|
|
537
|
+
var _value4 = form.getFieldValue(name);
|
|
538
|
+
var values = form.getFieldsValue(true);
|
|
539
|
+
calcValue = fn(_value4, values, {
|
|
540
|
+
moment: moment,
|
|
541
|
+
get: get
|
|
542
|
+
}, {
|
|
543
|
+
name: name,
|
|
544
|
+
parentName: parentName
|
|
545
|
+
});
|
|
546
|
+
} catch (_unused4) {}
|
|
547
|
+
}
|
|
548
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(calcValue, true);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
528
551
|
export var getRuleValidation = /*#__PURE__*/function () {
|
|
529
552
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, rule, values) {
|
|
530
553
|
var lang,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DatePickerProps } from 'antd/es/date-picker';
|
|
2
|
+
import { FC, IglooComponentProps } from '../types';
|
|
3
|
+
import './style';
|
|
4
|
+
type Props = DatePickerProps & IglooComponentProps;
|
|
5
|
+
declare const IglooBuddhistDatePicker: FC<Props>;
|
|
6
|
+
export default IglooBuddhistDatePicker;
|
|
@@ -75,7 +75,9 @@ var Element = function Element(_ref) {
|
|
|
75
75
|
extraLabel = config.extraLabel,
|
|
76
76
|
requiredAsserts = config.requiredAsserts,
|
|
77
77
|
shouldRenderCode = config.shouldRenderCode,
|
|
78
|
-
disabledCode = config.disabledCode
|
|
78
|
+
disabledCode = config.disabledCode,
|
|
79
|
+
automaticCalcCode = config.automaticCalcCode,
|
|
80
|
+
enableAutomaticCalc = config.enableAutomaticCalc;
|
|
79
81
|
var dependentField = dependencies || [];
|
|
80
82
|
if (Array.isArray(subscribedFields)) {
|
|
81
83
|
dependentField.push.apply(dependentField, _toConsumableArray(subscribedFields));
|
|
@@ -101,7 +103,7 @@ var Element = function Element(_ref) {
|
|
|
101
103
|
return dependentField.push(assert.field);
|
|
102
104
|
});
|
|
103
105
|
}
|
|
104
|
-
if ((shouldRender || shouldRenderCode || disabledCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
106
|
+
if ((shouldRender || shouldRenderCode || disabledCode || enableAutomaticCalc && automaticCalcCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
105
107
|
dependentField.push('SUBSCRIBE_ALL');
|
|
106
108
|
}
|
|
107
109
|
if (dependField) {
|
|
@@ -118,7 +120,7 @@ var Element = function Element(_ref) {
|
|
|
118
120
|
registerDependencies(dependentField, dispatch);
|
|
119
121
|
}, []);
|
|
120
122
|
(0, _invariant.default)(type !== 'Pages' && type !== 'Page', "".concat(type, " should not be inner form item"));
|
|
121
|
-
var _useComponent = (0, _elements.default)(config),
|
|
123
|
+
var _useComponent = (0, _elements.default)(config, parentName),
|
|
122
124
|
Component = _useComponent.Component,
|
|
123
125
|
extraConfig = _useComponent.formItemProps,
|
|
124
126
|
withoutForm = _useComponent.withoutForm;
|
package/lib/form/elements.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { NamePath } from 'antd/es/form/interface';
|
|
1
2
|
import { FormItemConfig, FormItemExtraConfig } from '../types';
|
|
2
|
-
type UseComponentHook = (config: FormItemConfig) => {
|
|
3
|
+
type UseComponentHook = (config: FormItemConfig, parentName: NamePath) => {
|
|
3
4
|
Component: any;
|
|
4
5
|
formItemProps: FormItemExtraConfig;
|
|
5
6
|
withoutForm: boolean;
|
package/lib/form/elements.js
CHANGED
|
@@ -7,24 +7,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _button = _interopRequireDefault(require("../button"));
|
|
10
|
-
var
|
|
11
|
-
var _input = _interopRequireWildcard(require("../input"));
|
|
12
|
-
var _datePicker = _interopRequireWildcard(require("../date-picker"));
|
|
10
|
+
var _checkbox = _interopRequireWildcard(require("../checkbox"));
|
|
13
11
|
var _confirmation = _interopRequireDefault(require("../confirmation"));
|
|
12
|
+
var _datePicker = _interopRequireWildcard(require("../date-picker"));
|
|
13
|
+
var _declaration = _interopRequireDefault(require("../declaration"));
|
|
14
|
+
var _formContext = _interopRequireDefault(require("../form-context"));
|
|
15
|
+
var _input = _interopRequireWildcard(require("../input"));
|
|
16
|
+
var _ocr = _interopRequireDefault(require("../ocr"));
|
|
17
|
+
var _radio = _interopRequireWildcard(require("../radio"));
|
|
18
|
+
var _searchBox = _interopRequireDefault(require("../search-box"));
|
|
14
19
|
var _select = require("../select");
|
|
15
|
-
var
|
|
20
|
+
var _typography = _interopRequireDefault(require("../typography"));
|
|
16
21
|
var _upload = _interopRequireDefault(require("../upload"));
|
|
17
|
-
var _declaration = _interopRequireDefault(require("../declaration"));
|
|
18
|
-
var _divider = _interopRequireDefault(require("./divider"));
|
|
19
22
|
var _uploadPhoto = _interopRequireDefault(require("../upload-photo"));
|
|
23
|
+
var _divider = _interopRequireDefault(require("./divider"));
|
|
20
24
|
var _render = _interopRequireDefault(require("./render"));
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var _ocr = _interopRequireDefault(require("../ocr"));
|
|
25
|
+
var _useWrapperOnChangeForAutomaticCalc = _interopRequireDefault(require("../hooks/useWrapperOnChangeForAutomaticCalc"));
|
|
26
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
+
var _excluded = ["onChange"];
|
|
25
28
|
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); }
|
|
26
29
|
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; }
|
|
27
30
|
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; }
|
|
28
38
|
var elementMap = {
|
|
29
39
|
Input: _input.default,
|
|
30
40
|
PhoneNumber: _input.PhoneNumber,
|
|
@@ -63,12 +73,13 @@ var elementMap = {
|
|
|
63
73
|
var Unknown = function Unknown() {
|
|
64
74
|
return 'Unknown Form Item';
|
|
65
75
|
};
|
|
66
|
-
var useComponent = function useComponent(config) {
|
|
76
|
+
var useComponent = function useComponent(config, parentName) {
|
|
67
77
|
var _useContext = (0, _react.useContext)(_formContext.default),
|
|
68
78
|
_useContext$customize = _useContext.customizeComponents,
|
|
69
79
|
customizeComponents = _useContext$customize === void 0 ? {} : _useContext$customize;
|
|
70
80
|
var type = config.type,
|
|
71
|
-
render = config.render
|
|
81
|
+
render = config.render,
|
|
82
|
+
enableAutomaticCalc = config.enableAutomaticCalc;
|
|
72
83
|
if (!type && !render) {
|
|
73
84
|
return {
|
|
74
85
|
Component: Unknown,
|
|
@@ -79,8 +90,16 @@ var useComponent = function useComponent(config) {
|
|
|
79
90
|
return (0, _react.useMemo)(function () {
|
|
80
91
|
var Component = type ? elementMap[type] || customizeComponents[type] || Unknown : _render.default;
|
|
81
92
|
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
|
+
};
|
|
82
101
|
return {
|
|
83
|
-
Component: Component,
|
|
102
|
+
Component: enableAutomaticCalc ? WrapperComponent : Component,
|
|
84
103
|
formItemProps: formItemProps,
|
|
85
104
|
withoutForm: type === 'Divider' || Boolean(config.withoutForm) || config.name === undefined
|
|
86
105
|
};
|
|
@@ -69,7 +69,9 @@ var Element = function Element(props) {
|
|
|
69
69
|
disabled = props.disabled,
|
|
70
70
|
requiredAsserts = props.requiredAsserts,
|
|
71
71
|
shouldRenderCode = props.shouldRenderCode,
|
|
72
|
-
disabledCode = props.disabledCode
|
|
72
|
+
disabledCode = props.disabledCode,
|
|
73
|
+
automaticCalcCode = props.automaticCalcCode,
|
|
74
|
+
enableAutomaticCalc = props.enableAutomaticCalc;
|
|
73
75
|
var dependentField = dependencies || [];
|
|
74
76
|
if (Array.isArray(subscribedFields)) {
|
|
75
77
|
dependentField.push.apply(dependentField, _toConsumableArray(subscribedFields));
|
|
@@ -95,7 +97,7 @@ var Element = function Element(props) {
|
|
|
95
97
|
return dependentField.push(assert.field);
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
if ((shouldRender || shouldRenderCode || disabledCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
100
|
+
if ((shouldRender || shouldRenderCode || disabledCode || enableAutomaticCalc && automaticCalcCode || getOptions || typeof extraLabel === 'function') && !Array.isArray(subscribedFields)) {
|
|
99
101
|
dependentField.push('SUBSCRIBE_ALL');
|
|
100
102
|
}
|
|
101
103
|
if (dependField) {
|
|
@@ -0,0 +1,5 @@
|
|
|
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;
|
|
@@ -0,0 +1,34 @@
|
|
|
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;
|
|
@@ -74,5 +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 calcAutomaticCalculate: (name: NamePath, parentName: NamePath, automaticCalcCode?: string, form?: FormInstance, onChange?: ((value: any, automaticCalc?: boolean) => any) | undefined) => undefined;
|
|
77
78
|
export declare const getRuleValidation: (url: string, rule: string | string[], values?: any, lang?: string) => Promise<any>;
|
|
78
79
|
export declare const calcAddableSectionAssertField: (name: any[], field: FormItemAssert['field'], index: number, elements: FormItemConfig[] | React.ReactElement[]) => any;
|