iglooform 2.4.30 → 2.4.33
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/filter/checkBox.js +5 -10
- package/es/filter/index.d.ts +1 -0
- package/es/filter/index.js +8 -2
- package/es/form/element/index.js +8 -5
- package/es/form/index.js +4 -2
- package/es/form-context.d.ts +1 -0
- package/es/free-form/addable-section/index.js +1 -1
- package/es/free-form/index.js +4 -2
- package/es/select/attached-select.d.ts +10 -2
- package/es/select/attached-select.js +188 -75
- package/es/types.d.ts +3 -1
- package/es/upload-photo/index.js +3 -4
- package/lib/filter/checkBox.js +5 -10
- package/lib/filter/index.d.ts +1 -0
- package/lib/filter/index.js +8 -2
- package/lib/form/element/index.js +8 -5
- package/lib/form/index.js +4 -2
- package/lib/form-context.d.ts +1 -0
- package/lib/free-form/addable-section/index.js +1 -1
- package/lib/free-form/index.js +4 -2
- package/lib/select/attached-select.d.ts +10 -2
- package/lib/select/attached-select.js +190 -75
- package/lib/types.d.ts +3 -1
- package/lib/upload-photo/index.js +3 -4
- package/package.json +1 -1
package/es/filter/checkBox.js
CHANGED
|
@@ -60,20 +60,15 @@ var CratetCheckBoxFilter = function CratetCheckBoxFilter(props) {
|
|
|
60
60
|
allChoose = _useState2[0],
|
|
61
61
|
setAllChoose = _useState2[1];
|
|
62
62
|
|
|
63
|
-
var
|
|
64
|
-
return handleFilterDisable(allSelected, disabled);
|
|
65
|
-
}),
|
|
66
|
-
_useState4 = _slicedToArray(_useState3, 1),
|
|
67
|
-
allCanChoose = _useState4[0];
|
|
68
|
-
|
|
63
|
+
var nowValidList = handleFilterDisable(allSelected, disabled);
|
|
69
64
|
useEffect(function () {
|
|
70
65
|
// 有可能用户配置的可选大于实际能选中的
|
|
71
|
-
if (chooseed.length >=
|
|
66
|
+
if (chooseed.length >= nowValidList.length) {
|
|
72
67
|
setAllChoose(true);
|
|
73
68
|
} else {
|
|
74
69
|
setAllChoose(false);
|
|
75
70
|
}
|
|
76
|
-
}, [chooseed.length,
|
|
71
|
+
}, [chooseed.length, allSelected]);
|
|
77
72
|
return _jsxs("div", {
|
|
78
73
|
className: "igloo-form-filter-drop-down-container-content-group",
|
|
79
74
|
children: [_jsxs("div", {
|
|
@@ -100,10 +95,10 @@ var CratetCheckBoxFilter = function CratetCheckBoxFilter(props) {
|
|
|
100
95
|
}) : _jsx("span", {
|
|
101
96
|
className: "igloo-form-filter-drop-down-container-content-group-title-action",
|
|
102
97
|
onClick: function onClick() {
|
|
103
|
-
typeof _onChange === 'function' && _onChange(
|
|
98
|
+
typeof _onChange === 'function' && _onChange(nowValidList);
|
|
104
99
|
valueConfirm({
|
|
105
100
|
type: optionKey,
|
|
106
|
-
value:
|
|
101
|
+
value: nowValidList
|
|
107
102
|
});
|
|
108
103
|
setAllChoose(true);
|
|
109
104
|
},
|
package/es/filter/index.d.ts
CHANGED
package/es/filter/index.js
CHANGED
|
@@ -356,7 +356,8 @@ var FilterComponent = function FilterComponent(props) {
|
|
|
356
356
|
searchInputDefault = props.searchInputDefault,
|
|
357
357
|
initValue = props.initValue,
|
|
358
358
|
inputOnly = props.inputOnly,
|
|
359
|
-
beforeOpenFilter = props.beforeOpenFilter
|
|
359
|
+
beforeOpenFilter = props.beforeOpenFilter,
|
|
360
|
+
resetCallBack = props.resetCallBack;
|
|
360
361
|
var filterTitle = props.filterTitle,
|
|
361
362
|
_props$filterItems = props.filterItems,
|
|
362
363
|
filterItems = _props$filterItems === void 0 ? [] : _props$filterItems; // id controller
|
|
@@ -710,6 +711,7 @@ var FilterComponent = function FilterComponent(props) {
|
|
|
710
711
|
},
|
|
711
712
|
children: [_jsx("span", {
|
|
712
713
|
onClick: function onClick() {
|
|
714
|
+
typeof resetCallBack === 'function' && resetCallBack(_objectSpread({}, defaultOptions));
|
|
713
715
|
setTimeout(function () {
|
|
714
716
|
setTimeRangeType(-1);
|
|
715
717
|
dispatchOptionsChange({
|
|
@@ -1050,9 +1052,13 @@ var FilterComponent = function FilterComponent(props) {
|
|
|
1050
1052
|
visible: dropVisible,
|
|
1051
1053
|
onVisibleChange: function onVisibleChange(visible) {
|
|
1052
1054
|
setDropVisible(visible);
|
|
1055
|
+
|
|
1056
|
+
if (visible) {
|
|
1057
|
+
typeof beforeOpenFilter === 'function' && beforeOpenFilter(_objectSpread({}, confirmed));
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1053
1060
|
setTimeout(function () {
|
|
1054
1061
|
if (dropVisible) {
|
|
1055
|
-
typeof beforeOpenFilter === 'function' && beforeOpenFilter(_objectSpread({}, confirmed));
|
|
1056
1062
|
setTimeRangeType(confirmedTimeRange);
|
|
1057
1063
|
dispatchOptionsChange({
|
|
1058
1064
|
type: 'default',
|
package/es/form/element/index.js
CHANGED
|
@@ -238,11 +238,7 @@ var Element = function Element(_ref) {
|
|
|
238
238
|
hideWhenEdit = elementProps.hideWhenEdit,
|
|
239
239
|
otherElementProps = _objectWithoutProperties(elementProps, _excluded2);
|
|
240
240
|
|
|
241
|
-
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return hideWhenEdit || !display ? null : _jsx(_Col, _objectSpread(_objectSpread({}, restColProps), {}, {
|
|
241
|
+
var component = _jsx(_Col, _objectSpread(_objectSpread({}, restColProps), {}, {
|
|
246
242
|
className: "igloo-form-item",
|
|
247
243
|
children: _jsx("div", {
|
|
248
244
|
style: {
|
|
@@ -261,6 +257,13 @@ var Element = function Element(_ref) {
|
|
|
261
257
|
}))
|
|
262
258
|
})
|
|
263
259
|
}));
|
|
260
|
+
|
|
261
|
+
if (preview) {
|
|
262
|
+
if (hideWhenPreview || !display) return null;
|
|
263
|
+
return component;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return hideWhenEdit || !display ? null : component;
|
|
264
267
|
}
|
|
265
268
|
|
|
266
269
|
if (!display) return null;
|
package/es/form/index.js
CHANGED
|
@@ -60,7 +60,8 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
60
60
|
} : _props$getScrollConta,
|
|
61
61
|
_props$onFirstModifie = props.onFirstModified,
|
|
62
62
|
onFirstModified = _props$onFirstModifie === void 0 ? function () {} : _props$onFirstModifie,
|
|
63
|
-
uploadApi = props.uploadApi
|
|
63
|
+
uploadApi = props.uploadApi,
|
|
64
|
+
selectDatasourceApi = props.selectDatasourceApi;
|
|
64
65
|
|
|
65
66
|
var _Form$useForm = _Form.useForm(),
|
|
66
67
|
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
|
@@ -239,7 +240,8 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
239
240
|
showSubmitButton: showSubmitButton,
|
|
240
241
|
getScrollContainer: getScrollContainer,
|
|
241
242
|
registerDependencies: registerDependencies,
|
|
242
|
-
uploadApi: uploadApi
|
|
243
|
+
uploadApi: uploadApi,
|
|
244
|
+
selectDatasourceApi: selectDatasourceApi
|
|
243
245
|
}, locales),
|
|
244
246
|
children: _jsxs(_Form, {
|
|
245
247
|
form: form,
|
package/es/form-context.d.ts
CHANGED
|
@@ -16,5 +16,6 @@ declare const _default: React.Context<{
|
|
|
16
16
|
getScrollContainer: () => HTMLElement | Window | null;
|
|
17
17
|
registerDependencies: (name: FormItemName | FormItemName[], updater: Function) => void;
|
|
18
18
|
uploadApi?: string | undefined;
|
|
19
|
+
selectDatasourceApi?: string | undefined;
|
|
19
20
|
}>;
|
|
20
21
|
export default _default;
|
|
@@ -201,7 +201,7 @@ var AddableSection = function AddableSection(props) {
|
|
|
201
201
|
return children.map(function (c, index) {
|
|
202
202
|
var _c$type;
|
|
203
203
|
|
|
204
|
-
if (['Igloo_Free_Form_Item', 'Igloo_Free_Form_Section', '
|
|
204
|
+
if (['Igloo_Free_Form_Item', 'Igloo_Free_Form_Section', 'Igloo_Free_Form_AddableSection'].includes(c === null || c === void 0 ? void 0 : (_c$type = c.type) === null || _c$type === void 0 ? void 0 : _c$type.displayName)) {
|
|
205
205
|
return /*#__PURE__*/cloneElement(c, _objectSpread(_objectSpread({
|
|
206
206
|
key: index
|
|
207
207
|
}, c.props), {}, {
|
package/es/free-form/index.js
CHANGED
|
@@ -55,7 +55,8 @@ var FreeForm = function FreeForm(props) {
|
|
|
55
55
|
} : _props$getScrollConta,
|
|
56
56
|
_props$onFirstModifie = props.onFirstModified,
|
|
57
57
|
onFirstModified = _props$onFirstModifie === void 0 ? function () {} : _props$onFirstModifie,
|
|
58
|
-
uploadApi = props.uploadApi
|
|
58
|
+
uploadApi = props.uploadApi,
|
|
59
|
+
selectDatasourceApi = props.selectDatasourceApi;
|
|
59
60
|
|
|
60
61
|
var _Form$useForm = _Form.useForm(),
|
|
61
62
|
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
|
@@ -196,7 +197,8 @@ var FreeForm = function FreeForm(props) {
|
|
|
196
197
|
showSubmitButton: showSubmitButton,
|
|
197
198
|
getScrollContainer: getScrollContainer,
|
|
198
199
|
registerDependencies: registerDependencies,
|
|
199
|
-
uploadApi: uploadApi
|
|
200
|
+
uploadApi: uploadApi,
|
|
201
|
+
selectDatasourceApi: selectDatasourceApi
|
|
200
202
|
}, locales),
|
|
201
203
|
children: _jsx(_Form, {
|
|
202
204
|
form: form,
|
|
@@ -2,11 +2,19 @@ import { SelectProps, SelectValue } from 'antd/es/select';
|
|
|
2
2
|
import { FC, IglooComponentProps } from '../types';
|
|
3
3
|
import { FormInstance } from 'antd/es/form';
|
|
4
4
|
import './style';
|
|
5
|
+
import { NamePath } from 'antd/es/form/interface';
|
|
5
6
|
export declare const Option: import("rc-select/lib/Option").OptionFC, OptGroup: import("rc-select/lib/OptGroup").OptionGroupFC;
|
|
6
7
|
declare type Props = SelectProps<SelectValue> & IglooComponentProps & {
|
|
7
8
|
getOptions?: (form: FormInstance) => any[];
|
|
8
9
|
multiple?: boolean;
|
|
9
10
|
clearWhenOptionsUpdated?: boolean;
|
|
11
|
+
optionGroups?: {
|
|
12
|
+
parentKey: string;
|
|
13
|
+
options: Props['options'];
|
|
14
|
+
}[];
|
|
15
|
+
datasourceKey?: string;
|
|
16
|
+
datasourceApi?: string;
|
|
17
|
+
dependField?: NamePath;
|
|
10
18
|
};
|
|
11
19
|
declare type OptionType = typeof Option;
|
|
12
20
|
declare type OptGroupType = typeof OptGroup;
|
|
@@ -14,5 +22,5 @@ interface IglooSelectType extends FC<Props> {
|
|
|
14
22
|
Option: OptionType;
|
|
15
23
|
OptGroup: OptGroupType;
|
|
16
24
|
}
|
|
17
|
-
declare const
|
|
18
|
-
export default
|
|
25
|
+
declare const AttachedSelect: IglooSelectType;
|
|
26
|
+
export default AttachedSelect;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import "antd/es/select/style";
|
|
2
2
|
import _Select from "antd/es/select";
|
|
3
|
-
var _excluded = ["
|
|
3
|
+
var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options"],
|
|
4
|
+
_excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children", "clearWhenOptionsUpdated"];
|
|
5
|
+
|
|
6
|
+
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); }
|
|
7
|
+
|
|
8
|
+
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); } }
|
|
9
|
+
|
|
10
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
11
|
|
|
5
12
|
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; }
|
|
6
13
|
|
|
@@ -40,28 +47,27 @@ import { ArrowDownOutlined, ArrowUpOutlined, SearchOutlined } from 'iglooicon';
|
|
|
40
47
|
import classnames from 'classnames';
|
|
41
48
|
import Checkbox from '../checkbox';
|
|
42
49
|
import LocaleContext from '../locale/locale-context';
|
|
50
|
+
import FormContext from '../form-context';
|
|
43
51
|
import Button from '../button';
|
|
44
52
|
import Input from '../input';
|
|
45
53
|
import './style';
|
|
54
|
+
import invariant from 'invariant';
|
|
46
55
|
var Option = _Select.Option,
|
|
47
56
|
OptGroup = _Select.OptGroup;
|
|
48
57
|
export { Option, OptGroup };
|
|
49
58
|
|
|
50
59
|
var IglooSelect = function IglooSelect(_ref) {
|
|
51
|
-
var
|
|
52
|
-
getOptionsProp = _ref.getOptions,
|
|
53
|
-
valueProp = _ref.value,
|
|
60
|
+
var valueProp = _ref.value,
|
|
54
61
|
className = _ref.className,
|
|
55
62
|
placeholder = _ref.placeholder,
|
|
56
63
|
_ref$onDropdownVisibl = _ref.onDropdownVisibleChange,
|
|
57
64
|
onDropdownVisibleChange = _ref$onDropdownVisibl === void 0 ? function () {} : _ref$onDropdownVisibl,
|
|
58
|
-
children = _ref.children,
|
|
59
65
|
showSearch = _ref.showSearch,
|
|
60
66
|
filterOption = _ref.filterOption,
|
|
61
67
|
optionFilterProp = _ref.optionFilterProp,
|
|
62
68
|
multiple = _ref.multiple,
|
|
63
|
-
_ref$
|
|
64
|
-
|
|
69
|
+
_ref$options = _ref.options,
|
|
70
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
65
71
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
66
72
|
|
|
67
73
|
var _useContext = useContext(LocaleContext),
|
|
@@ -77,86 +83,35 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
77
83
|
selectedOptions = _useState4[0],
|
|
78
84
|
setSelectedOptions = _useState4[1];
|
|
79
85
|
|
|
86
|
+
var _useState5 = useState(options),
|
|
87
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
88
|
+
displayOptions = _useState6[0],
|
|
89
|
+
setDisplay = _useState6[1];
|
|
90
|
+
|
|
80
91
|
useEffect(function () {
|
|
81
92
|
typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
|
|
82
93
|
}, [selected]);
|
|
83
94
|
useEffect(function () {
|
|
84
95
|
setSelected(valueProp);
|
|
85
96
|
}, [valueProp]);
|
|
86
|
-
|
|
87
|
-
var getOptions = function getOptions() {
|
|
88
|
-
var getFormInstance = rest.getFormInstance;
|
|
89
|
-
var form = typeof getFormInstance === 'function' && getFormInstance();
|
|
90
|
-
|
|
91
|
-
if (!form) {
|
|
92
|
-
if (!children || typeof children === 'string' || typeof children === 'number' || typeof children === 'boolean') return [];
|
|
93
|
-
return Array.isArray(children) ? children.map(function (child) {
|
|
94
|
-
return {
|
|
95
|
-
label: child.props.children,
|
|
96
|
-
value: child.props.value
|
|
97
|
-
};
|
|
98
|
-
}) : [{
|
|
99
|
-
label: children.props.children,
|
|
100
|
-
value: children.props.value
|
|
101
|
-
}];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
var options = typeof getOptionsProp === 'function' && getOptionsProp(form);
|
|
105
|
-
return options || [];
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
var options = optionsProp || getOptions();
|
|
109
|
-
|
|
110
|
-
var _useState5 = useState(options),
|
|
111
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
112
|
-
originOptions = _useState6[0],
|
|
113
|
-
setOriginOptions = _useState6[1];
|
|
114
|
-
|
|
115
|
-
var _useState7 = useState(options),
|
|
116
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
117
|
-
displayOptions = _useState8[0],
|
|
118
|
-
setDisplay = _useState8[1];
|
|
119
|
-
|
|
120
97
|
useEffect(function () {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (!updateOptions) {
|
|
124
|
-
for (var i = 0; i < options.length; i++) {
|
|
125
|
-
var newOption = options[i];
|
|
126
|
-
var originOption = originOptions[i];
|
|
127
|
-
|
|
128
|
-
if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
|
|
129
|
-
updateOptions = true;
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (updateOptions) {
|
|
136
|
-
setOriginOptions(options);
|
|
137
|
-
setDisplay(options);
|
|
138
|
-
var setFieldValue = rest.setFieldValue;
|
|
139
|
-
|
|
140
|
-
if (clearWhenOptionsUpdated) {
|
|
141
|
-
typeof setFieldValue === 'function' && setFieldValue();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
98
|
+
setDisplay(options);
|
|
144
99
|
}, [options]);
|
|
145
100
|
useEffect(function () {
|
|
146
101
|
var setFieldValue = rest.setFieldValue;
|
|
147
|
-
var foundValue =
|
|
102
|
+
var foundValue = options.find(function (option) {
|
|
148
103
|
return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
|
|
149
104
|
});
|
|
150
105
|
|
|
151
106
|
if (!foundValue) {
|
|
152
107
|
typeof setFieldValue === 'function' && setFieldValue();
|
|
153
108
|
}
|
|
154
|
-
}, [valueProp,
|
|
109
|
+
}, [valueProp, options]);
|
|
155
110
|
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
dropVisible =
|
|
159
|
-
setDropVisible =
|
|
111
|
+
var _useState7 = useState(false),
|
|
112
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
113
|
+
dropVisible = _useState8[0],
|
|
114
|
+
setDropVisible = _useState8[1];
|
|
160
115
|
|
|
161
116
|
var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
|
|
162
117
|
typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
|
|
@@ -165,7 +120,7 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
165
120
|
|
|
166
121
|
var handleSearch = function handleSearch(e) {
|
|
167
122
|
var value = e.target.value;
|
|
168
|
-
var filteredOptions =
|
|
123
|
+
var filteredOptions = options.filter(function (option) {
|
|
169
124
|
var _option$label, _option$label$toStrin;
|
|
170
125
|
|
|
171
126
|
return Boolean(option === null || option === void 0 ? void 0 : (_option$label = option.label) === null || _option$label === void 0 ? void 0 : (_option$label$toStrin = _option$label.toString()) === null || _option$label$toStrin === void 0 ? void 0 : _option$label$toStrin.includes(value));
|
|
@@ -347,10 +302,168 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
347
302
|
});
|
|
348
303
|
};
|
|
349
304
|
|
|
350
|
-
|
|
305
|
+
var AttachedSelect = function AttachedSelect(_ref11) {
|
|
306
|
+
var options = _ref11.options,
|
|
307
|
+
optionGroups = _ref11.optionGroups,
|
|
308
|
+
getOptions = _ref11.getOptions,
|
|
309
|
+
datasourceKey = _ref11.datasourceKey,
|
|
310
|
+
dependField = _ref11.dependField,
|
|
311
|
+
children = _ref11.children,
|
|
312
|
+
_ref11$clearWhenOptio = _ref11.clearWhenOptionsUpdated,
|
|
313
|
+
clearWhenOptionsUpdated = _ref11$clearWhenOptio === void 0 ? false : _ref11$clearWhenOptio,
|
|
314
|
+
rest = _objectWithoutProperties(_ref11, _excluded2);
|
|
315
|
+
|
|
316
|
+
var _useState9 = useState(options || []),
|
|
317
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
318
|
+
_options = _useState10[0],
|
|
319
|
+
setOptions = _useState10[1];
|
|
320
|
+
|
|
321
|
+
var _useContext2 = useContext(FormContext),
|
|
322
|
+
selectDatasourceApi = _useContext2.selectDatasourceApi;
|
|
323
|
+
|
|
324
|
+
var getFormInstance = rest.getFormInstance;
|
|
325
|
+
var form = typeof getFormInstance === 'function' && getFormInstance();
|
|
326
|
+
var dependFieldValue = form && dependField && form.getFieldValue(dependField);
|
|
327
|
+
var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
|
|
328
|
+
invariant(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
|
|
329
|
+
useEffect(function () {
|
|
330
|
+
var calcOptions = /*#__PURE__*/function () {
|
|
331
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
332
|
+
var group, query, api, rst, _yield$rst$json, data;
|
|
333
|
+
|
|
334
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
335
|
+
while (1) {
|
|
336
|
+
switch (_context.prev = _context.next) {
|
|
337
|
+
case 0:
|
|
338
|
+
if (!Array.isArray(options)) {
|
|
339
|
+
_context.next = 2;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return _context.abrupt("return", options);
|
|
344
|
+
|
|
345
|
+
case 2:
|
|
346
|
+
if (!(Array.isArray(children) || _typeof(children) === 'object')) {
|
|
347
|
+
_context.next = 4;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
|
|
352
|
+
return {
|
|
353
|
+
label: child.props.children,
|
|
354
|
+
value: child.props.value
|
|
355
|
+
};
|
|
356
|
+
}) : [{
|
|
357
|
+
label: children.props.children,
|
|
358
|
+
value: children.props.value
|
|
359
|
+
}]);
|
|
360
|
+
|
|
361
|
+
case 4:
|
|
362
|
+
if (!Array.isArray(optionsFromGetOptions)) {
|
|
363
|
+
_context.next = 6;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return _context.abrupt("return", optionsFromGetOptions);
|
|
368
|
+
|
|
369
|
+
case 6:
|
|
370
|
+
if (!optionGroups) {
|
|
371
|
+
_context.next = 10;
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (!dependFieldValue) {
|
|
376
|
+
_context.next = 10;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
group = optionGroups.find(function (_ref13) {
|
|
381
|
+
var parentKey = _ref13.parentKey;
|
|
382
|
+
return Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue;
|
|
383
|
+
});
|
|
384
|
+
return _context.abrupt("return", (group === null || group === void 0 ? void 0 : group.options) || []);
|
|
385
|
+
|
|
386
|
+
case 10:
|
|
387
|
+
if (!(selectDatasourceApi && datasourceKey)) {
|
|
388
|
+
_context.next = 27;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
|
|
393
|
+
return "parent=".concat(v);
|
|
394
|
+
}).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
|
|
395
|
+
api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
|
|
396
|
+
_context.prev = 13;
|
|
397
|
+
_context.next = 16;
|
|
398
|
+
return fetch(query ? "".concat(api, "?").concat(query) : api);
|
|
399
|
+
|
|
400
|
+
case 16:
|
|
401
|
+
rst = _context.sent;
|
|
402
|
+
_context.next = 19;
|
|
403
|
+
return rst.json();
|
|
404
|
+
|
|
405
|
+
case 19:
|
|
406
|
+
_yield$rst$json = _context.sent;
|
|
407
|
+
data = _yield$rst$json.data;
|
|
408
|
+
return _context.abrupt("return", data || []);
|
|
409
|
+
|
|
410
|
+
case 24:
|
|
411
|
+
_context.prev = 24;
|
|
412
|
+
_context.t0 = _context["catch"](13);
|
|
413
|
+
return _context.abrupt("return", []);
|
|
414
|
+
|
|
415
|
+
case 27:
|
|
416
|
+
return _context.abrupt("return", []);
|
|
417
|
+
|
|
418
|
+
case 28:
|
|
419
|
+
case "end":
|
|
420
|
+
return _context.stop();
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}, _callee, null, [[13, 24]]);
|
|
424
|
+
}));
|
|
425
|
+
|
|
426
|
+
return function calcOptions() {
|
|
427
|
+
return _ref12.apply(this, arguments);
|
|
428
|
+
};
|
|
429
|
+
}();
|
|
430
|
+
|
|
431
|
+
var compareOptions = function compareOptions(newOptions) {
|
|
432
|
+
var updateOptions = _options.length !== newOptions.length;
|
|
433
|
+
|
|
434
|
+
if (!updateOptions) {
|
|
435
|
+
for (var i = 0; i < _options.length; i++) {
|
|
436
|
+
var newOption = _options[i];
|
|
437
|
+
var originOption = newOptions[i];
|
|
438
|
+
|
|
439
|
+
if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
|
|
440
|
+
updateOptions = true;
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (updateOptions) {
|
|
447
|
+
setOptions(newOptions);
|
|
448
|
+
var setFieldValue = rest.setFieldValue;
|
|
449
|
+
|
|
450
|
+
if (clearWhenOptionsUpdated) {
|
|
451
|
+
typeof setFieldValue === 'function' && setFieldValue();
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
calcOptions().then(compareOptions);
|
|
457
|
+
}, [options, optionGroups, dependFieldValue, optionsFromGetOptions]);
|
|
458
|
+
return _jsx(IglooSelect, _objectSpread({
|
|
459
|
+
options: _options
|
|
460
|
+
}, rest));
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
AttachedSelect.formItemPropsHandler = function (config) {
|
|
351
464
|
return {};
|
|
352
465
|
};
|
|
353
466
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
export default
|
|
467
|
+
AttachedSelect.Option = Option;
|
|
468
|
+
AttachedSelect.OptGroup = OptGroup;
|
|
469
|
+
export default AttachedSelect;
|
package/es/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { FormItemProps, FormInstance } from 'antd/es/form';
|
|
4
4
|
import { NamePath } from 'rc-field-form/lib/interface';
|
|
5
5
|
import { CheckboxOptionType } from 'antd/es/checkbox';
|
|
6
|
+
import { SelectProps } from 'antd/es/select';
|
|
6
7
|
export declare type FormItemName = NamePath;
|
|
7
8
|
export interface FormBasicConfig {
|
|
8
9
|
className?: string;
|
|
@@ -25,6 +26,7 @@ export interface FormBasicConfig {
|
|
|
25
26
|
getScrollContainer?: () => HTMLElement | null;
|
|
26
27
|
onFirstModified?: () => any;
|
|
27
28
|
uploadApi?: string;
|
|
29
|
+
selectDatasourceApi?: string;
|
|
28
30
|
}
|
|
29
31
|
export declare type FormItemAssert = {
|
|
30
32
|
field: NamePath;
|
|
@@ -79,7 +81,7 @@ export interface FormItemExtraConfig extends FormItemProps {
|
|
|
79
81
|
content: any;
|
|
80
82
|
shownTrigger: 'unchecked' | 'checked' | 'all';
|
|
81
83
|
};
|
|
82
|
-
})[];
|
|
84
|
+
})[] | SelectProps['options'];
|
|
83
85
|
sendOtp?: (value: any) => any;
|
|
84
86
|
dependField?: FormItemName;
|
|
85
87
|
countDownSeconds?: number;
|
package/es/upload-photo/index.js
CHANGED
|
@@ -118,8 +118,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
118
118
|
|
|
119
119
|
invariant(typeof props.handleUpload === 'function' || uploadApi, '"handleUpload" should be a function. Or uploadApi should be set at Form/FreeForm');
|
|
120
120
|
invariant(!uploadApi || props.bizKey, '"bizKey" should be set if Upload is used with uploadApi');
|
|
121
|
-
var
|
|
122
|
-
value = _props$value === void 0 ? [] : _props$value,
|
|
121
|
+
var value = props.value,
|
|
123
122
|
limit = props.limit,
|
|
124
123
|
limitErrorMessage = props.limitErrorMessage,
|
|
125
124
|
descriptions = props.descriptions,
|
|
@@ -235,7 +234,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
235
234
|
};
|
|
236
235
|
|
|
237
236
|
useEffect(function () {
|
|
238
|
-
if (Array.isArray(value) && files.length === 0) {
|
|
237
|
+
if (Array.isArray(value) && value.length && files.length === 0) {
|
|
239
238
|
mapFilesFromValue(value);
|
|
240
239
|
}
|
|
241
240
|
}, [value]);
|
|
@@ -250,7 +249,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
250
249
|
URL.revokeObjectURL(dataUrl);
|
|
251
250
|
});
|
|
252
251
|
};
|
|
253
|
-
}, []);
|
|
252
|
+
}, [files]);
|
|
254
253
|
useEffect(function () {
|
|
255
254
|
var removeLimitMsg = function removeLimitMsg(e) {
|
|
256
255
|
if (DomRef.current && !DomRef.current.contains(e.target) && limitNumError.current) {
|
package/lib/filter/checkBox.js
CHANGED
|
@@ -79,20 +79,15 @@ var CratetCheckBoxFilter = function CratetCheckBoxFilter(props) {
|
|
|
79
79
|
allChoose = _useState2[0],
|
|
80
80
|
setAllChoose = _useState2[1];
|
|
81
81
|
|
|
82
|
-
var
|
|
83
|
-
return handleFilterDisable(allSelected, disabled);
|
|
84
|
-
}),
|
|
85
|
-
_useState4 = _slicedToArray(_useState3, 1),
|
|
86
|
-
allCanChoose = _useState4[0];
|
|
87
|
-
|
|
82
|
+
var nowValidList = handleFilterDisable(allSelected, disabled);
|
|
88
83
|
(0, _react.useEffect)(function () {
|
|
89
84
|
// 有可能用户配置的可选大于实际能选中的
|
|
90
|
-
if (chooseed.length >=
|
|
85
|
+
if (chooseed.length >= nowValidList.length) {
|
|
91
86
|
setAllChoose(true);
|
|
92
87
|
} else {
|
|
93
88
|
setAllChoose(false);
|
|
94
89
|
}
|
|
95
|
-
}, [chooseed.length,
|
|
90
|
+
}, [chooseed.length, allSelected]);
|
|
96
91
|
return (0, _jsxRuntime.jsxs)("div", {
|
|
97
92
|
className: "igloo-form-filter-drop-down-container-content-group",
|
|
98
93
|
children: [(0, _jsxRuntime.jsxs)("div", {
|
|
@@ -119,10 +114,10 @@ var CratetCheckBoxFilter = function CratetCheckBoxFilter(props) {
|
|
|
119
114
|
}) : (0, _jsxRuntime.jsx)("span", {
|
|
120
115
|
className: "igloo-form-filter-drop-down-container-content-group-title-action",
|
|
121
116
|
onClick: function onClick() {
|
|
122
|
-
typeof _onChange === 'function' && _onChange(
|
|
117
|
+
typeof _onChange === 'function' && _onChange(nowValidList);
|
|
123
118
|
valueConfirm({
|
|
124
119
|
type: optionKey,
|
|
125
|
-
value:
|
|
120
|
+
value: nowValidList
|
|
126
121
|
});
|
|
127
122
|
setAllChoose(true);
|
|
128
123
|
},
|
package/lib/filter/index.d.ts
CHANGED
package/lib/filter/index.js
CHANGED
|
@@ -390,7 +390,8 @@ var FilterComponent = function FilterComponent(props) {
|
|
|
390
390
|
searchInputDefault = props.searchInputDefault,
|
|
391
391
|
initValue = props.initValue,
|
|
392
392
|
inputOnly = props.inputOnly,
|
|
393
|
-
beforeOpenFilter = props.beforeOpenFilter
|
|
393
|
+
beforeOpenFilter = props.beforeOpenFilter,
|
|
394
|
+
resetCallBack = props.resetCallBack;
|
|
394
395
|
var filterTitle = props.filterTitle,
|
|
395
396
|
_props$filterItems = props.filterItems,
|
|
396
397
|
filterItems = _props$filterItems === void 0 ? [] : _props$filterItems; // id controller
|
|
@@ -743,6 +744,7 @@ var FilterComponent = function FilterComponent(props) {
|
|
|
743
744
|
},
|
|
744
745
|
children: [(0, _jsxRuntime.jsx)("span", {
|
|
745
746
|
onClick: function onClick() {
|
|
747
|
+
typeof resetCallBack === 'function' && resetCallBack(_objectSpread({}, defaultOptions));
|
|
746
748
|
setTimeout(function () {
|
|
747
749
|
setTimeRangeType(-1);
|
|
748
750
|
dispatchOptionsChange({
|
|
@@ -1082,9 +1084,13 @@ var FilterComponent = function FilterComponent(props) {
|
|
|
1082
1084
|
visible: dropVisible,
|
|
1083
1085
|
onVisibleChange: function onVisibleChange(visible) {
|
|
1084
1086
|
setDropVisible(visible);
|
|
1087
|
+
|
|
1088
|
+
if (visible) {
|
|
1089
|
+
typeof beforeOpenFilter === 'function' && beforeOpenFilter(_objectSpread({}, confirmed));
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1085
1092
|
setTimeout(function () {
|
|
1086
1093
|
if (dropVisible) {
|
|
1087
|
-
typeof beforeOpenFilter === 'function' && beforeOpenFilter(_objectSpread({}, confirmed));
|
|
1088
1094
|
setTimeRangeType(confirmedTimeRange);
|
|
1089
1095
|
dispatchOptionsChange({
|
|
1090
1096
|
type: 'default',
|
|
@@ -267,11 +267,7 @@ var Element = function Element(_ref) {
|
|
|
267
267
|
hideWhenEdit = elementProps.hideWhenEdit,
|
|
268
268
|
otherElementProps = _objectWithoutProperties(elementProps, _excluded2);
|
|
269
269
|
|
|
270
|
-
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return hideWhenEdit || !display ? null : (0, _jsxRuntime.jsx)(_col.default, _objectSpread(_objectSpread({}, restColProps), {}, {
|
|
270
|
+
var component = (0, _jsxRuntime.jsx)(_col.default, _objectSpread(_objectSpread({}, restColProps), {}, {
|
|
275
271
|
className: "igloo-form-item",
|
|
276
272
|
children: (0, _jsxRuntime.jsx)("div", {
|
|
277
273
|
style: {
|
|
@@ -290,6 +286,13 @@ var Element = function Element(_ref) {
|
|
|
290
286
|
}))
|
|
291
287
|
})
|
|
292
288
|
}));
|
|
289
|
+
|
|
290
|
+
if (preview) {
|
|
291
|
+
if (hideWhenPreview || !display) return null;
|
|
292
|
+
return component;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return hideWhenEdit || !display ? null : component;
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
if (!display) return null;
|
package/lib/form/index.js
CHANGED
|
@@ -81,7 +81,8 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
81
81
|
} : _props$getScrollConta,
|
|
82
82
|
_props$onFirstModifie = props.onFirstModified,
|
|
83
83
|
onFirstModified = _props$onFirstModifie === void 0 ? function () {} : _props$onFirstModifie,
|
|
84
|
-
uploadApi = props.uploadApi
|
|
84
|
+
uploadApi = props.uploadApi,
|
|
85
|
+
selectDatasourceApi = props.selectDatasourceApi;
|
|
85
86
|
|
|
86
87
|
var _Form$useForm = _form.default.useForm(),
|
|
87
88
|
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
|
@@ -260,7 +261,8 @@ var IglooForm = function IglooForm(props, ref) {
|
|
|
260
261
|
showSubmitButton: showSubmitButton,
|
|
261
262
|
getScrollContainer: getScrollContainer,
|
|
262
263
|
registerDependencies: registerDependencies,
|
|
263
|
-
uploadApi: uploadApi
|
|
264
|
+
uploadApi: uploadApi,
|
|
265
|
+
selectDatasourceApi: selectDatasourceApi
|
|
264
266
|
}, locales),
|
|
265
267
|
children: (0, _jsxRuntime.jsxs)(_form.default, {
|
|
266
268
|
form: form,
|
package/lib/form-context.d.ts
CHANGED
|
@@ -16,5 +16,6 @@ declare const _default: React.Context<{
|
|
|
16
16
|
getScrollContainer: () => HTMLElement | Window | null;
|
|
17
17
|
registerDependencies: (name: FormItemName | FormItemName[], updater: Function) => void;
|
|
18
18
|
uploadApi?: string | undefined;
|
|
19
|
+
selectDatasourceApi?: string | undefined;
|
|
19
20
|
}>;
|
|
20
21
|
export default _default;
|
|
@@ -225,7 +225,7 @@ var AddableSection = function AddableSection(props) {
|
|
|
225
225
|
return children.map(function (c, index) {
|
|
226
226
|
var _c$type;
|
|
227
227
|
|
|
228
|
-
if (['Igloo_Free_Form_Item', 'Igloo_Free_Form_Section', '
|
|
228
|
+
if (['Igloo_Free_Form_Item', 'Igloo_Free_Form_Section', 'Igloo_Free_Form_AddableSection'].includes(c === null || c === void 0 ? void 0 : (_c$type = c.type) === null || _c$type === void 0 ? void 0 : _c$type.displayName)) {
|
|
229
229
|
return /*#__PURE__*/(0, _react.cloneElement)(c, _objectSpread(_objectSpread({
|
|
230
230
|
key: index
|
|
231
231
|
}, c.props), {}, {
|
package/lib/free-form/index.js
CHANGED
|
@@ -71,7 +71,8 @@ var FreeForm = function FreeForm(props) {
|
|
|
71
71
|
} : _props$getScrollConta,
|
|
72
72
|
_props$onFirstModifie = props.onFirstModified,
|
|
73
73
|
onFirstModified = _props$onFirstModifie === void 0 ? function () {} : _props$onFirstModifie,
|
|
74
|
-
uploadApi = props.uploadApi
|
|
74
|
+
uploadApi = props.uploadApi,
|
|
75
|
+
selectDatasourceApi = props.selectDatasourceApi;
|
|
75
76
|
|
|
76
77
|
var _Form$useForm = _form.default.useForm(),
|
|
77
78
|
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
|
@@ -212,7 +213,8 @@ var FreeForm = function FreeForm(props) {
|
|
|
212
213
|
showSubmitButton: showSubmitButton,
|
|
213
214
|
getScrollContainer: getScrollContainer,
|
|
214
215
|
registerDependencies: registerDependencies,
|
|
215
|
-
uploadApi: uploadApi
|
|
216
|
+
uploadApi: uploadApi,
|
|
217
|
+
selectDatasourceApi: selectDatasourceApi
|
|
216
218
|
}, locales),
|
|
217
219
|
children: (0, _jsxRuntime.jsx)(_form.default, {
|
|
218
220
|
form: form,
|
|
@@ -2,11 +2,19 @@ import { SelectProps, SelectValue } from 'antd/es/select';
|
|
|
2
2
|
import { FC, IglooComponentProps } from '../types';
|
|
3
3
|
import { FormInstance } from 'antd/es/form';
|
|
4
4
|
import './style';
|
|
5
|
+
import { NamePath } from 'antd/es/form/interface';
|
|
5
6
|
export declare const Option: import("rc-select/lib/Option").OptionFC, OptGroup: import("rc-select/lib/OptGroup").OptionGroupFC;
|
|
6
7
|
declare type Props = SelectProps<SelectValue> & IglooComponentProps & {
|
|
7
8
|
getOptions?: (form: FormInstance) => any[];
|
|
8
9
|
multiple?: boolean;
|
|
9
10
|
clearWhenOptionsUpdated?: boolean;
|
|
11
|
+
optionGroups?: {
|
|
12
|
+
parentKey: string;
|
|
13
|
+
options: Props['options'];
|
|
14
|
+
}[];
|
|
15
|
+
datasourceKey?: string;
|
|
16
|
+
datasourceApi?: string;
|
|
17
|
+
dependField?: NamePath;
|
|
10
18
|
};
|
|
11
19
|
declare type OptionType = typeof Option;
|
|
12
20
|
declare type OptGroupType = typeof OptGroup;
|
|
@@ -14,5 +22,5 @@ interface IglooSelectType extends FC<Props> {
|
|
|
14
22
|
Option: OptionType;
|
|
15
23
|
OptGroup: OptGroupType;
|
|
16
24
|
}
|
|
17
|
-
declare const
|
|
18
|
-
export default
|
|
25
|
+
declare const AttachedSelect: IglooSelectType;
|
|
26
|
+
export default AttachedSelect;
|
|
@@ -25,16 +25,27 @@ var _checkbox = _interopRequireDefault(require("../checkbox"));
|
|
|
25
25
|
|
|
26
26
|
var _localeContext = _interopRequireDefault(require("../locale/locale-context"));
|
|
27
27
|
|
|
28
|
+
var _formContext = _interopRequireDefault(require("../form-context"));
|
|
29
|
+
|
|
28
30
|
var _button = _interopRequireDefault(require("../button"));
|
|
29
31
|
|
|
30
32
|
var _input = _interopRequireDefault(require("../input"));
|
|
31
33
|
|
|
32
34
|
require("./style");
|
|
33
35
|
|
|
34
|
-
var
|
|
36
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
37
|
+
|
|
38
|
+
var _excluded = ["value", "className", "placeholder", "onDropdownVisibleChange", "showSearch", "filterOption", "optionFilterProp", "multiple", "options"],
|
|
39
|
+
_excluded2 = ["options", "optionGroups", "getOptions", "datasourceKey", "dependField", "children", "clearWhenOptionsUpdated"];
|
|
35
40
|
|
|
36
41
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
42
|
|
|
43
|
+
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); }
|
|
44
|
+
|
|
45
|
+
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); } }
|
|
46
|
+
|
|
47
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
48
|
+
|
|
38
49
|
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; }
|
|
39
50
|
|
|
40
51
|
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; }
|
|
@@ -71,20 +82,17 @@ exports.OptGroup = OptGroup;
|
|
|
71
82
|
exports.Option = Option;
|
|
72
83
|
|
|
73
84
|
var IglooSelect = function IglooSelect(_ref) {
|
|
74
|
-
var
|
|
75
|
-
getOptionsProp = _ref.getOptions,
|
|
76
|
-
valueProp = _ref.value,
|
|
85
|
+
var valueProp = _ref.value,
|
|
77
86
|
className = _ref.className,
|
|
78
87
|
placeholder = _ref.placeholder,
|
|
79
88
|
_ref$onDropdownVisibl = _ref.onDropdownVisibleChange,
|
|
80
89
|
onDropdownVisibleChange = _ref$onDropdownVisibl === void 0 ? function () {} : _ref$onDropdownVisibl,
|
|
81
|
-
children = _ref.children,
|
|
82
90
|
showSearch = _ref.showSearch,
|
|
83
91
|
filterOption = _ref.filterOption,
|
|
84
92
|
optionFilterProp = _ref.optionFilterProp,
|
|
85
93
|
multiple = _ref.multiple,
|
|
86
|
-
_ref$
|
|
87
|
-
|
|
94
|
+
_ref$options = _ref.options,
|
|
95
|
+
options = _ref$options === void 0 ? [] : _ref$options,
|
|
88
96
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
89
97
|
|
|
90
98
|
var _useContext = (0, _react.useContext)(_localeContext.default),
|
|
@@ -100,86 +108,35 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
100
108
|
selectedOptions = _useState4[0],
|
|
101
109
|
setSelectedOptions = _useState4[1];
|
|
102
110
|
|
|
111
|
+
var _useState5 = (0, _react.useState)(options),
|
|
112
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
113
|
+
displayOptions = _useState6[0],
|
|
114
|
+
setDisplay = _useState6[1];
|
|
115
|
+
|
|
103
116
|
(0, _react.useEffect)(function () {
|
|
104
117
|
typeof rest.onChange === 'function' && valueProp !== selected && rest.onChange(selected, selectedOptions);
|
|
105
118
|
}, [selected]);
|
|
106
119
|
(0, _react.useEffect)(function () {
|
|
107
120
|
setSelected(valueProp);
|
|
108
121
|
}, [valueProp]);
|
|
109
|
-
|
|
110
|
-
var getOptions = function getOptions() {
|
|
111
|
-
var getFormInstance = rest.getFormInstance;
|
|
112
|
-
var form = typeof getFormInstance === 'function' && getFormInstance();
|
|
113
|
-
|
|
114
|
-
if (!form) {
|
|
115
|
-
if (!children || typeof children === 'string' || typeof children === 'number' || typeof children === 'boolean') return [];
|
|
116
|
-
return Array.isArray(children) ? children.map(function (child) {
|
|
117
|
-
return {
|
|
118
|
-
label: child.props.children,
|
|
119
|
-
value: child.props.value
|
|
120
|
-
};
|
|
121
|
-
}) : [{
|
|
122
|
-
label: children.props.children,
|
|
123
|
-
value: children.props.value
|
|
124
|
-
}];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
var options = typeof getOptionsProp === 'function' && getOptionsProp(form);
|
|
128
|
-
return options || [];
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
var options = optionsProp || getOptions();
|
|
132
|
-
|
|
133
|
-
var _useState5 = (0, _react.useState)(options),
|
|
134
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
135
|
-
originOptions = _useState6[0],
|
|
136
|
-
setOriginOptions = _useState6[1];
|
|
137
|
-
|
|
138
|
-
var _useState7 = (0, _react.useState)(options),
|
|
139
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
140
|
-
displayOptions = _useState8[0],
|
|
141
|
-
setDisplay = _useState8[1];
|
|
142
|
-
|
|
143
122
|
(0, _react.useEffect)(function () {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (!updateOptions) {
|
|
147
|
-
for (var i = 0; i < options.length; i++) {
|
|
148
|
-
var newOption = options[i];
|
|
149
|
-
var originOption = originOptions[i];
|
|
150
|
-
|
|
151
|
-
if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
|
|
152
|
-
updateOptions = true;
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (updateOptions) {
|
|
159
|
-
setOriginOptions(options);
|
|
160
|
-
setDisplay(options);
|
|
161
|
-
var setFieldValue = rest.setFieldValue;
|
|
162
|
-
|
|
163
|
-
if (clearWhenOptionsUpdated) {
|
|
164
|
-
typeof setFieldValue === 'function' && setFieldValue();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
123
|
+
setDisplay(options);
|
|
167
124
|
}, [options]);
|
|
168
125
|
(0, _react.useEffect)(function () {
|
|
169
126
|
var setFieldValue = rest.setFieldValue;
|
|
170
|
-
var foundValue =
|
|
127
|
+
var foundValue = options.find(function (option) {
|
|
171
128
|
return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
|
|
172
129
|
});
|
|
173
130
|
|
|
174
131
|
if (!foundValue) {
|
|
175
132
|
typeof setFieldValue === 'function' && setFieldValue();
|
|
176
133
|
}
|
|
177
|
-
}, [valueProp,
|
|
134
|
+
}, [valueProp, options]);
|
|
178
135
|
|
|
179
|
-
var
|
|
180
|
-
|
|
181
|
-
dropVisible =
|
|
182
|
-
setDropVisible =
|
|
136
|
+
var _useState7 = (0, _react.useState)(false),
|
|
137
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
138
|
+
dropVisible = _useState8[0],
|
|
139
|
+
setDropVisible = _useState8[1];
|
|
183
140
|
|
|
184
141
|
var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
|
|
185
142
|
typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
|
|
@@ -188,7 +145,7 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
188
145
|
|
|
189
146
|
var handleSearch = function handleSearch(e) {
|
|
190
147
|
var value = e.target.value;
|
|
191
|
-
var filteredOptions =
|
|
148
|
+
var filteredOptions = options.filter(function (option) {
|
|
192
149
|
var _option$label, _option$label$toStrin;
|
|
193
150
|
|
|
194
151
|
return Boolean(option === null || option === void 0 ? void 0 : (_option$label = option.label) === null || _option$label === void 0 ? void 0 : (_option$label$toStrin = _option$label.toString()) === null || _option$label$toStrin === void 0 ? void 0 : _option$label$toStrin.includes(value));
|
|
@@ -370,11 +327,169 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
370
327
|
});
|
|
371
328
|
};
|
|
372
329
|
|
|
373
|
-
|
|
330
|
+
var AttachedSelect = function AttachedSelect(_ref11) {
|
|
331
|
+
var options = _ref11.options,
|
|
332
|
+
optionGroups = _ref11.optionGroups,
|
|
333
|
+
getOptions = _ref11.getOptions,
|
|
334
|
+
datasourceKey = _ref11.datasourceKey,
|
|
335
|
+
dependField = _ref11.dependField,
|
|
336
|
+
children = _ref11.children,
|
|
337
|
+
_ref11$clearWhenOptio = _ref11.clearWhenOptionsUpdated,
|
|
338
|
+
clearWhenOptionsUpdated = _ref11$clearWhenOptio === void 0 ? false : _ref11$clearWhenOptio,
|
|
339
|
+
rest = _objectWithoutProperties(_ref11, _excluded2);
|
|
340
|
+
|
|
341
|
+
var _useState9 = (0, _react.useState)(options || []),
|
|
342
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
343
|
+
_options = _useState10[0],
|
|
344
|
+
setOptions = _useState10[1];
|
|
345
|
+
|
|
346
|
+
var _useContext2 = (0, _react.useContext)(_formContext.default),
|
|
347
|
+
selectDatasourceApi = _useContext2.selectDatasourceApi;
|
|
348
|
+
|
|
349
|
+
var getFormInstance = rest.getFormInstance;
|
|
350
|
+
var form = typeof getFormInstance === 'function' && getFormInstance();
|
|
351
|
+
var dependFieldValue = form && dependField && form.getFieldValue(dependField);
|
|
352
|
+
var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
|
|
353
|
+
(0, _invariant.default)(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
|
|
354
|
+
(0, _react.useEffect)(function () {
|
|
355
|
+
var calcOptions = /*#__PURE__*/function () {
|
|
356
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
357
|
+
var group, query, api, rst, _yield$rst$json, data;
|
|
358
|
+
|
|
359
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
360
|
+
while (1) {
|
|
361
|
+
switch (_context.prev = _context.next) {
|
|
362
|
+
case 0:
|
|
363
|
+
if (!Array.isArray(options)) {
|
|
364
|
+
_context.next = 2;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return _context.abrupt("return", options);
|
|
369
|
+
|
|
370
|
+
case 2:
|
|
371
|
+
if (!(Array.isArray(children) || _typeof(children) === 'object')) {
|
|
372
|
+
_context.next = 4;
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
|
|
377
|
+
return {
|
|
378
|
+
label: child.props.children,
|
|
379
|
+
value: child.props.value
|
|
380
|
+
};
|
|
381
|
+
}) : [{
|
|
382
|
+
label: children.props.children,
|
|
383
|
+
value: children.props.value
|
|
384
|
+
}]);
|
|
385
|
+
|
|
386
|
+
case 4:
|
|
387
|
+
if (!Array.isArray(optionsFromGetOptions)) {
|
|
388
|
+
_context.next = 6;
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return _context.abrupt("return", optionsFromGetOptions);
|
|
393
|
+
|
|
394
|
+
case 6:
|
|
395
|
+
if (!optionGroups) {
|
|
396
|
+
_context.next = 10;
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (!dependFieldValue) {
|
|
401
|
+
_context.next = 10;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
group = optionGroups.find(function (_ref13) {
|
|
406
|
+
var parentKey = _ref13.parentKey;
|
|
407
|
+
return Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue;
|
|
408
|
+
});
|
|
409
|
+
return _context.abrupt("return", (group === null || group === void 0 ? void 0 : group.options) || []);
|
|
410
|
+
|
|
411
|
+
case 10:
|
|
412
|
+
if (!(selectDatasourceApi && datasourceKey)) {
|
|
413
|
+
_context.next = 27;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
|
|
418
|
+
return "parent=".concat(v);
|
|
419
|
+
}).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
|
|
420
|
+
api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
|
|
421
|
+
_context.prev = 13;
|
|
422
|
+
_context.next = 16;
|
|
423
|
+
return fetch(query ? "".concat(api, "?").concat(query) : api);
|
|
424
|
+
|
|
425
|
+
case 16:
|
|
426
|
+
rst = _context.sent;
|
|
427
|
+
_context.next = 19;
|
|
428
|
+
return rst.json();
|
|
429
|
+
|
|
430
|
+
case 19:
|
|
431
|
+
_yield$rst$json = _context.sent;
|
|
432
|
+
data = _yield$rst$json.data;
|
|
433
|
+
return _context.abrupt("return", data || []);
|
|
434
|
+
|
|
435
|
+
case 24:
|
|
436
|
+
_context.prev = 24;
|
|
437
|
+
_context.t0 = _context["catch"](13);
|
|
438
|
+
return _context.abrupt("return", []);
|
|
439
|
+
|
|
440
|
+
case 27:
|
|
441
|
+
return _context.abrupt("return", []);
|
|
442
|
+
|
|
443
|
+
case 28:
|
|
444
|
+
case "end":
|
|
445
|
+
return _context.stop();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}, _callee, null, [[13, 24]]);
|
|
449
|
+
}));
|
|
450
|
+
|
|
451
|
+
return function calcOptions() {
|
|
452
|
+
return _ref12.apply(this, arguments);
|
|
453
|
+
};
|
|
454
|
+
}();
|
|
455
|
+
|
|
456
|
+
var compareOptions = function compareOptions(newOptions) {
|
|
457
|
+
var updateOptions = _options.length !== newOptions.length;
|
|
458
|
+
|
|
459
|
+
if (!updateOptions) {
|
|
460
|
+
for (var i = 0; i < _options.length; i++) {
|
|
461
|
+
var newOption = _options[i];
|
|
462
|
+
var originOption = newOptions[i];
|
|
463
|
+
|
|
464
|
+
if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
|
|
465
|
+
updateOptions = true;
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (updateOptions) {
|
|
472
|
+
setOptions(newOptions);
|
|
473
|
+
var setFieldValue = rest.setFieldValue;
|
|
474
|
+
|
|
475
|
+
if (clearWhenOptionsUpdated) {
|
|
476
|
+
typeof setFieldValue === 'function' && setFieldValue();
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
calcOptions().then(compareOptions);
|
|
482
|
+
}, [options, optionGroups, dependFieldValue, optionsFromGetOptions]);
|
|
483
|
+
return (0, _jsxRuntime.jsx)(IglooSelect, _objectSpread({
|
|
484
|
+
options: _options
|
|
485
|
+
}, rest));
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
AttachedSelect.formItemPropsHandler = function (config) {
|
|
374
489
|
return {};
|
|
375
490
|
};
|
|
376
491
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
var _default =
|
|
492
|
+
AttachedSelect.Option = Option;
|
|
493
|
+
AttachedSelect.OptGroup = OptGroup;
|
|
494
|
+
var _default = AttachedSelect;
|
|
380
495
|
exports.default = _default;
|
package/lib/types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { FormItemProps, FormInstance } from 'antd/es/form';
|
|
4
4
|
import { NamePath } from 'rc-field-form/lib/interface';
|
|
5
5
|
import { CheckboxOptionType } from 'antd/es/checkbox';
|
|
6
|
+
import { SelectProps } from 'antd/es/select';
|
|
6
7
|
export declare type FormItemName = NamePath;
|
|
7
8
|
export interface FormBasicConfig {
|
|
8
9
|
className?: string;
|
|
@@ -25,6 +26,7 @@ export interface FormBasicConfig {
|
|
|
25
26
|
getScrollContainer?: () => HTMLElement | null;
|
|
26
27
|
onFirstModified?: () => any;
|
|
27
28
|
uploadApi?: string;
|
|
29
|
+
selectDatasourceApi?: string;
|
|
28
30
|
}
|
|
29
31
|
export declare type FormItemAssert = {
|
|
30
32
|
field: NamePath;
|
|
@@ -79,7 +81,7 @@ export interface FormItemExtraConfig extends FormItemProps {
|
|
|
79
81
|
content: any;
|
|
80
82
|
shownTrigger: 'unchecked' | 'checked' | 'all';
|
|
81
83
|
};
|
|
82
|
-
})[];
|
|
84
|
+
})[] | SelectProps['options'];
|
|
83
85
|
sendOtp?: (value: any) => any;
|
|
84
86
|
dependField?: FormItemName;
|
|
85
87
|
countDownSeconds?: number;
|
|
@@ -151,8 +151,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
151
151
|
|
|
152
152
|
(0, _invariant.default)(typeof props.handleUpload === 'function' || uploadApi, '"handleUpload" should be a function. Or uploadApi should be set at Form/FreeForm');
|
|
153
153
|
(0, _invariant.default)(!uploadApi || props.bizKey, '"bizKey" should be set if Upload is used with uploadApi');
|
|
154
|
-
var
|
|
155
|
-
value = _props$value === void 0 ? [] : _props$value,
|
|
154
|
+
var value = props.value,
|
|
156
155
|
limit = props.limit,
|
|
157
156
|
limitErrorMessage = props.limitErrorMessage,
|
|
158
157
|
descriptions = props.descriptions,
|
|
@@ -268,7 +267,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
268
267
|
};
|
|
269
268
|
|
|
270
269
|
(0, _react.useEffect)(function () {
|
|
271
|
-
if (Array.isArray(value) && files.length === 0) {
|
|
270
|
+
if (Array.isArray(value) && value.length && files.length === 0) {
|
|
272
271
|
mapFilesFromValue(value);
|
|
273
272
|
}
|
|
274
273
|
}, [value]);
|
|
@@ -283,7 +282,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
283
282
|
URL.revokeObjectURL(dataUrl);
|
|
284
283
|
});
|
|
285
284
|
};
|
|
286
|
-
}, []);
|
|
285
|
+
}, [files]);
|
|
287
286
|
(0, _react.useEffect)(function () {
|
|
288
287
|
var removeLimitMsg = function removeLimitMsg(e) {
|
|
289
288
|
if (DomRef.current && !DomRef.current.contains(e.target) && limitNumError.current) {
|