iglooform 2.4.30 → 2.4.31
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/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 +186 -83
- package/es/types.d.ts +3 -1
- package/es/upload-photo/index.js +3 -4
- 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 +188 -83
- package/lib/types.d.ts +3 -1
- package/lib/upload-photo/index.js +3 -4
- package/package.json +1 -1
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) 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,25 @@ 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
|
-
useEffect(function () {
|
|
146
|
-
var setFieldValue = rest.setFieldValue;
|
|
147
|
-
var foundValue = originOptions.find(function (option) {
|
|
148
|
-
return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
|
|
149
|
-
});
|
|
150
100
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
var _useState9 = useState(false),
|
|
157
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
158
|
-
dropVisible = _useState10[0],
|
|
159
|
-
setDropVisible = _useState10[1];
|
|
101
|
+
var _useState7 = useState(false),
|
|
102
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
103
|
+
dropVisible = _useState8[0],
|
|
104
|
+
setDropVisible = _useState8[1];
|
|
160
105
|
|
|
161
106
|
var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
|
|
162
107
|
typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
|
|
@@ -165,7 +110,7 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
165
110
|
|
|
166
111
|
var handleSearch = function handleSearch(e) {
|
|
167
112
|
var value = e.target.value;
|
|
168
|
-
var filteredOptions =
|
|
113
|
+
var filteredOptions = options.filter(function (option) {
|
|
169
114
|
var _option$label, _option$label$toStrin;
|
|
170
115
|
|
|
171
116
|
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 +292,168 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
347
292
|
});
|
|
348
293
|
};
|
|
349
294
|
|
|
350
|
-
|
|
295
|
+
var AttachedSelect = function AttachedSelect(_ref11) {
|
|
296
|
+
var options = _ref11.options,
|
|
297
|
+
optionGroups = _ref11.optionGroups,
|
|
298
|
+
getOptions = _ref11.getOptions,
|
|
299
|
+
datasourceKey = _ref11.datasourceKey,
|
|
300
|
+
dependField = _ref11.dependField,
|
|
301
|
+
children = _ref11.children,
|
|
302
|
+
_ref11$clearWhenOptio = _ref11.clearWhenOptionsUpdated,
|
|
303
|
+
clearWhenOptionsUpdated = _ref11$clearWhenOptio === void 0 ? false : _ref11$clearWhenOptio,
|
|
304
|
+
rest = _objectWithoutProperties(_ref11, _excluded2);
|
|
305
|
+
|
|
306
|
+
var _useState9 = useState(options || []),
|
|
307
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
308
|
+
_options = _useState10[0],
|
|
309
|
+
setOptions = _useState10[1];
|
|
310
|
+
|
|
311
|
+
var _useContext2 = useContext(FormContext),
|
|
312
|
+
selectDatasourceApi = _useContext2.selectDatasourceApi;
|
|
313
|
+
|
|
314
|
+
var getFormInstance = rest.getFormInstance;
|
|
315
|
+
var form = typeof getFormInstance === 'function' && getFormInstance();
|
|
316
|
+
var dependFieldValue = form && dependField && form.getFieldValue(dependField);
|
|
317
|
+
var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
|
|
318
|
+
invariant(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
|
|
319
|
+
useEffect(function () {
|
|
320
|
+
var calcOptions = /*#__PURE__*/function () {
|
|
321
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
322
|
+
var group, query, api, rst, _yield$rst$json, data;
|
|
323
|
+
|
|
324
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
325
|
+
while (1) {
|
|
326
|
+
switch (_context.prev = _context.next) {
|
|
327
|
+
case 0:
|
|
328
|
+
if (!Array.isArray(options)) {
|
|
329
|
+
_context.next = 2;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return _context.abrupt("return", options);
|
|
334
|
+
|
|
335
|
+
case 2:
|
|
336
|
+
if (!(Array.isArray(children) || _typeof(children) === 'object')) {
|
|
337
|
+
_context.next = 4;
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
|
|
342
|
+
return {
|
|
343
|
+
label: child.props.children,
|
|
344
|
+
value: child.props.value
|
|
345
|
+
};
|
|
346
|
+
}) : [{
|
|
347
|
+
label: children.props.children,
|
|
348
|
+
value: children.props.value
|
|
349
|
+
}]);
|
|
350
|
+
|
|
351
|
+
case 4:
|
|
352
|
+
if (!Array.isArray(optionsFromGetOptions)) {
|
|
353
|
+
_context.next = 6;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return _context.abrupt("return", optionsFromGetOptions);
|
|
358
|
+
|
|
359
|
+
case 6:
|
|
360
|
+
if (!optionGroups) {
|
|
361
|
+
_context.next = 10;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (!dependFieldValue) {
|
|
366
|
+
_context.next = 10;
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
group = optionGroups.find(function (_ref13) {
|
|
371
|
+
var parentKey = _ref13.parentKey;
|
|
372
|
+
return Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue;
|
|
373
|
+
});
|
|
374
|
+
return _context.abrupt("return", (group === null || group === void 0 ? void 0 : group.options) || []);
|
|
375
|
+
|
|
376
|
+
case 10:
|
|
377
|
+
if (!(selectDatasourceApi && datasourceKey)) {
|
|
378
|
+
_context.next = 27;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
|
|
383
|
+
return "parent=".concat(v);
|
|
384
|
+
}).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
|
|
385
|
+
api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
|
|
386
|
+
_context.prev = 13;
|
|
387
|
+
_context.next = 16;
|
|
388
|
+
return fetch(query ? "".concat(api, "?").concat(query) : api);
|
|
389
|
+
|
|
390
|
+
case 16:
|
|
391
|
+
rst = _context.sent;
|
|
392
|
+
_context.next = 19;
|
|
393
|
+
return rst.json();
|
|
394
|
+
|
|
395
|
+
case 19:
|
|
396
|
+
_yield$rst$json = _context.sent;
|
|
397
|
+
data = _yield$rst$json.data;
|
|
398
|
+
return _context.abrupt("return", data || []);
|
|
399
|
+
|
|
400
|
+
case 24:
|
|
401
|
+
_context.prev = 24;
|
|
402
|
+
_context.t0 = _context["catch"](13);
|
|
403
|
+
return _context.abrupt("return", []);
|
|
404
|
+
|
|
405
|
+
case 27:
|
|
406
|
+
return _context.abrupt("return", []);
|
|
407
|
+
|
|
408
|
+
case 28:
|
|
409
|
+
case "end":
|
|
410
|
+
return _context.stop();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}, _callee, null, [[13, 24]]);
|
|
414
|
+
}));
|
|
415
|
+
|
|
416
|
+
return function calcOptions() {
|
|
417
|
+
return _ref12.apply(this, arguments);
|
|
418
|
+
};
|
|
419
|
+
}();
|
|
420
|
+
|
|
421
|
+
var compareOptions = function compareOptions(newOptions) {
|
|
422
|
+
var updateOptions = _options.length !== newOptions.length;
|
|
423
|
+
|
|
424
|
+
if (!updateOptions) {
|
|
425
|
+
for (var i = 0; i < _options.length; i++) {
|
|
426
|
+
var newOption = _options[i];
|
|
427
|
+
var originOption = newOptions[i];
|
|
428
|
+
|
|
429
|
+
if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
|
|
430
|
+
updateOptions = true;
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (updateOptions) {
|
|
437
|
+
setOptions(newOptions);
|
|
438
|
+
var setFieldValue = rest.setFieldValue;
|
|
439
|
+
|
|
440
|
+
if (clearWhenOptionsUpdated) {
|
|
441
|
+
typeof setFieldValue === 'function' && setFieldValue();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
calcOptions().then(compareOptions);
|
|
447
|
+
}, [options, optionGroups, dependFieldValue, optionsFromGetOptions]);
|
|
448
|
+
return _jsx(IglooSelect, _objectSpread({
|
|
449
|
+
options: _options
|
|
450
|
+
}, rest));
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
AttachedSelect.formItemPropsHandler = function (config) {
|
|
351
454
|
return {};
|
|
352
455
|
};
|
|
353
456
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
export default
|
|
457
|
+
AttachedSelect.Option = Option;
|
|
458
|
+
AttachedSelect.OptGroup = OptGroup;
|
|
459
|
+
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,
|
|
@@ -238,7 +237,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
238
237
|
if (Array.isArray(value) && files.length === 0) {
|
|
239
238
|
mapFilesFromValue(value);
|
|
240
239
|
}
|
|
241
|
-
}, [value]);
|
|
240
|
+
}, [value, files]);
|
|
242
241
|
var uploadId = useMemo(function () {
|
|
243
242
|
return "igloo-upload-photo-input-".concat(Math.random());
|
|
244
243
|
}, []);
|
|
@@ -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/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) 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,25 @@ 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
|
-
(0, _react.useEffect)(function () {
|
|
169
|
-
var setFieldValue = rest.setFieldValue;
|
|
170
|
-
var foundValue = originOptions.find(function (option) {
|
|
171
|
-
return Array.isArray(valueProp) ? valueProp.includes(option.value) : option.value === valueProp;
|
|
172
|
-
});
|
|
173
125
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
var _useState9 = (0, _react.useState)(false),
|
|
180
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
|
181
|
-
dropVisible = _useState10[0],
|
|
182
|
-
setDropVisible = _useState10[1];
|
|
126
|
+
var _useState7 = (0, _react.useState)(false),
|
|
127
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
128
|
+
dropVisible = _useState8[0],
|
|
129
|
+
setDropVisible = _useState8[1];
|
|
183
130
|
|
|
184
131
|
var handleDropDownVisibleChange = function handleDropDownVisibleChange(open) {
|
|
185
132
|
typeof onDropdownVisibleChange === 'function' && onDropdownVisibleChange(open);
|
|
@@ -188,7 +135,7 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
188
135
|
|
|
189
136
|
var handleSearch = function handleSearch(e) {
|
|
190
137
|
var value = e.target.value;
|
|
191
|
-
var filteredOptions =
|
|
138
|
+
var filteredOptions = options.filter(function (option) {
|
|
192
139
|
var _option$label, _option$label$toStrin;
|
|
193
140
|
|
|
194
141
|
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 +317,169 @@ var IglooSelect = function IglooSelect(_ref) {
|
|
|
370
317
|
});
|
|
371
318
|
};
|
|
372
319
|
|
|
373
|
-
|
|
320
|
+
var AttachedSelect = function AttachedSelect(_ref11) {
|
|
321
|
+
var options = _ref11.options,
|
|
322
|
+
optionGroups = _ref11.optionGroups,
|
|
323
|
+
getOptions = _ref11.getOptions,
|
|
324
|
+
datasourceKey = _ref11.datasourceKey,
|
|
325
|
+
dependField = _ref11.dependField,
|
|
326
|
+
children = _ref11.children,
|
|
327
|
+
_ref11$clearWhenOptio = _ref11.clearWhenOptionsUpdated,
|
|
328
|
+
clearWhenOptionsUpdated = _ref11$clearWhenOptio === void 0 ? false : _ref11$clearWhenOptio,
|
|
329
|
+
rest = _objectWithoutProperties(_ref11, _excluded2);
|
|
330
|
+
|
|
331
|
+
var _useState9 = (0, _react.useState)(options || []),
|
|
332
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
333
|
+
_options = _useState10[0],
|
|
334
|
+
setOptions = _useState10[1];
|
|
335
|
+
|
|
336
|
+
var _useContext2 = (0, _react.useContext)(_formContext.default),
|
|
337
|
+
selectDatasourceApi = _useContext2.selectDatasourceApi;
|
|
338
|
+
|
|
339
|
+
var getFormInstance = rest.getFormInstance;
|
|
340
|
+
var form = typeof getFormInstance === 'function' && getFormInstance();
|
|
341
|
+
var dependFieldValue = form && dependField && form.getFieldValue(dependField);
|
|
342
|
+
var optionsFromGetOptions = typeof getOptions === 'function' && form && getOptions(form);
|
|
343
|
+
(0, _invariant.default)(datasourceKey && selectDatasourceApi || !datasourceKey, 'Please provide selectDatasourceApi in Form props');
|
|
344
|
+
(0, _react.useEffect)(function () {
|
|
345
|
+
var calcOptions = /*#__PURE__*/function () {
|
|
346
|
+
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
347
|
+
var group, query, api, rst, _yield$rst$json, data;
|
|
348
|
+
|
|
349
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
350
|
+
while (1) {
|
|
351
|
+
switch (_context.prev = _context.next) {
|
|
352
|
+
case 0:
|
|
353
|
+
if (!Array.isArray(options)) {
|
|
354
|
+
_context.next = 2;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return _context.abrupt("return", options);
|
|
359
|
+
|
|
360
|
+
case 2:
|
|
361
|
+
if (!(Array.isArray(children) || _typeof(children) === 'object')) {
|
|
362
|
+
_context.next = 4;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return _context.abrupt("return", Array.isArray(children) ? children.map(function (child) {
|
|
367
|
+
return {
|
|
368
|
+
label: child.props.children,
|
|
369
|
+
value: child.props.value
|
|
370
|
+
};
|
|
371
|
+
}) : [{
|
|
372
|
+
label: children.props.children,
|
|
373
|
+
value: children.props.value
|
|
374
|
+
}]);
|
|
375
|
+
|
|
376
|
+
case 4:
|
|
377
|
+
if (!Array.isArray(optionsFromGetOptions)) {
|
|
378
|
+
_context.next = 6;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return _context.abrupt("return", optionsFromGetOptions);
|
|
383
|
+
|
|
384
|
+
case 6:
|
|
385
|
+
if (!optionGroups) {
|
|
386
|
+
_context.next = 10;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (!dependFieldValue) {
|
|
391
|
+
_context.next = 10;
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
group = optionGroups.find(function (_ref13) {
|
|
396
|
+
var parentKey = _ref13.parentKey;
|
|
397
|
+
return Array.isArray(dependFieldValue) ? dependFieldValue.includes(parentKey) : parentKey === dependFieldValue;
|
|
398
|
+
});
|
|
399
|
+
return _context.abrupt("return", (group === null || group === void 0 ? void 0 : group.options) || []);
|
|
400
|
+
|
|
401
|
+
case 10:
|
|
402
|
+
if (!(selectDatasourceApi && datasourceKey)) {
|
|
403
|
+
_context.next = 27;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
query = Array.isArray(dependFieldValue) ? dependFieldValue.map(function (v) {
|
|
408
|
+
return "parent=".concat(v);
|
|
409
|
+
}).join('&') : dependFieldValue ? "parent=".concat(dependFieldValue) : '';
|
|
410
|
+
api = "".concat(selectDatasourceApi, "/").concat(datasourceKey);
|
|
411
|
+
_context.prev = 13;
|
|
412
|
+
_context.next = 16;
|
|
413
|
+
return fetch(query ? "".concat(api, "?").concat(query) : api);
|
|
414
|
+
|
|
415
|
+
case 16:
|
|
416
|
+
rst = _context.sent;
|
|
417
|
+
_context.next = 19;
|
|
418
|
+
return rst.json();
|
|
419
|
+
|
|
420
|
+
case 19:
|
|
421
|
+
_yield$rst$json = _context.sent;
|
|
422
|
+
data = _yield$rst$json.data;
|
|
423
|
+
return _context.abrupt("return", data || []);
|
|
424
|
+
|
|
425
|
+
case 24:
|
|
426
|
+
_context.prev = 24;
|
|
427
|
+
_context.t0 = _context["catch"](13);
|
|
428
|
+
return _context.abrupt("return", []);
|
|
429
|
+
|
|
430
|
+
case 27:
|
|
431
|
+
return _context.abrupt("return", []);
|
|
432
|
+
|
|
433
|
+
case 28:
|
|
434
|
+
case "end":
|
|
435
|
+
return _context.stop();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}, _callee, null, [[13, 24]]);
|
|
439
|
+
}));
|
|
440
|
+
|
|
441
|
+
return function calcOptions() {
|
|
442
|
+
return _ref12.apply(this, arguments);
|
|
443
|
+
};
|
|
444
|
+
}();
|
|
445
|
+
|
|
446
|
+
var compareOptions = function compareOptions(newOptions) {
|
|
447
|
+
var updateOptions = _options.length !== newOptions.length;
|
|
448
|
+
|
|
449
|
+
if (!updateOptions) {
|
|
450
|
+
for (var i = 0; i < _options.length; i++) {
|
|
451
|
+
var newOption = _options[i];
|
|
452
|
+
var originOption = newOptions[i];
|
|
453
|
+
|
|
454
|
+
if (newOption.label !== originOption.label || newOption.value !== originOption.value) {
|
|
455
|
+
updateOptions = true;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (updateOptions) {
|
|
462
|
+
setOptions(newOptions);
|
|
463
|
+
var setFieldValue = rest.setFieldValue;
|
|
464
|
+
|
|
465
|
+
if (clearWhenOptionsUpdated) {
|
|
466
|
+
typeof setFieldValue === 'function' && setFieldValue();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
calcOptions().then(compareOptions);
|
|
472
|
+
}, [options, optionGroups, dependFieldValue, optionsFromGetOptions]);
|
|
473
|
+
return (0, _jsxRuntime.jsx)(IglooSelect, _objectSpread({
|
|
474
|
+
options: _options
|
|
475
|
+
}, rest));
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
AttachedSelect.formItemPropsHandler = function (config) {
|
|
374
479
|
return {};
|
|
375
480
|
};
|
|
376
481
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
var _default =
|
|
482
|
+
AttachedSelect.Option = Option;
|
|
483
|
+
AttachedSelect.OptGroup = OptGroup;
|
|
484
|
+
var _default = AttachedSelect;
|
|
380
485
|
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,
|
|
@@ -271,7 +270,7 @@ var UploadPhoto = function UploadPhoto(props) {
|
|
|
271
270
|
if (Array.isArray(value) && files.length === 0) {
|
|
272
271
|
mapFilesFromValue(value);
|
|
273
272
|
}
|
|
274
|
-
}, [value]);
|
|
273
|
+
}, [value, files]);
|
|
275
274
|
var uploadId = (0, _react.useMemo)(function () {
|
|
276
275
|
return "igloo-upload-photo-input-".concat(Math.random());
|
|
277
276
|
}, []);
|
|
@@ -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) {
|