amis-core 3.1.1 → 3.3.0
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/esm/Root.js +1 -1
- package/esm/RootRenderer.d.ts +1 -1
- package/esm/RootRenderer.js +3 -3
- package/esm/SchemaRenderer.js +6 -2
- package/esm/Scoped.d.ts +4 -1
- package/esm/Scoped.js +9 -5
- package/esm/StatusScoped.js +1 -1
- package/esm/WithRootStore.d.ts +4 -24
- package/esm/WithRootStore.js +12 -4
- package/esm/WithStore.js +23 -16
- package/esm/actions/Action.d.ts +1 -0
- package/esm/actions/Action.js +70 -45
- package/esm/actions/AjaxAction.d.ts +6 -8
- package/esm/actions/AjaxAction.js +20 -18
- package/esm/actions/BreakAction.js +1 -1
- package/esm/actions/BroadcastAction.js +1 -1
- package/esm/actions/CmptAction.d.ts +1 -2
- package/esm/actions/CmptAction.js +47 -32
- package/esm/actions/ContinueAction.js +1 -1
- package/esm/actions/CopyAction.js +1 -1
- package/esm/actions/CustomAction.js +3 -2
- package/esm/actions/DialogAction.d.ts +2 -0
- package/esm/actions/DialogAction.js +39 -23
- package/esm/actions/DrawerAction.js +4 -4
- package/esm/actions/EmailAction.js +1 -1
- package/esm/actions/LinkAction.js +1 -1
- package/esm/actions/LoopAction.js +1 -1
- package/esm/actions/PageAction.js +1 -1
- package/esm/actions/ParallelAction.js +1 -1
- package/esm/actions/StatusAction.d.ts +15 -0
- package/esm/actions/StatusAction.js +49 -0
- package/esm/actions/SwitchAction.js +1 -1
- package/esm/actions/ToastAction.js +1 -1
- package/esm/actions/index.d.ts +1 -0
- package/esm/components/CustomStyle.js +1 -1
- package/esm/components/LazyComponent.js +1 -1
- package/esm/components/Overlay.js +3 -2
- package/esm/components/PopOver.js +3 -2
- package/esm/env.js +1 -1
- package/esm/envOverwrite.js +1 -1
- package/esm/factory.js +2 -2
- package/esm/index.d.ts +3 -1
- package/esm/index.js +16 -14
- package/esm/locale.js +1 -1
- package/esm/polyfills.d.ts +3 -0
- package/esm/polyfills.js +18 -0
- package/esm/renderers/Form.d.ts +7 -7
- package/esm/renderers/Form.js +182 -128
- package/esm/renderers/Item.d.ts +82 -77
- package/esm/renderers/Item.js +90 -74
- package/esm/renderers/Options.js +1 -2
- package/esm/renderers/Placeholder.js +1 -1
- package/esm/renderers/builtin.js +1 -1
- package/esm/renderers/register.js +1 -1
- package/esm/renderers/wrapControl.d.ts +4 -24
- package/esm/renderers/wrapControl.js +140 -88
- package/esm/store/app.js +42 -4
- package/esm/store/combo.d.ts +564 -1892
- package/esm/store/combo.js +9 -2
- package/esm/store/crud.d.ts +4 -2
- package/esm/store/crud.js +17 -4
- package/esm/store/form.d.ts +182 -882
- package/esm/store/form.js +83 -81
- package/esm/store/formItem.d.ts +6 -2
- package/esm/store/formItem.js +19 -3
- package/esm/store/iRenderer.js +3 -2
- package/esm/store/index.js +1 -1
- package/esm/store/list.d.ts +1 -0
- package/esm/store/list.js +8 -2
- package/esm/store/manager.js +1 -1
- package/esm/store/modal.js +1 -1
- package/esm/store/node.js +1 -1
- package/esm/store/pagination.js +1 -1
- package/esm/store/root.js +3 -2
- package/esm/store/service.js +17 -12
- package/esm/store/status.js +1 -1
- package/esm/store/table.d.ts +604 -2020
- package/esm/store/table.js +86 -56
- package/esm/store/table2.d.ts +49 -0
- package/esm/store/table2.js +37 -4
- package/esm/theme.js +1 -1
- package/esm/types.d.ts +22 -5
- package/esm/utils/Animation.js +1 -1
- package/esm/utils/ColorScale.js +1 -1
- package/esm/utils/DataSchema.d.ts +3 -2
- package/esm/utils/DataSchema.js +27 -7
- package/esm/utils/DataScope.d.ts +10 -3
- package/esm/utils/DataScope.js +50 -12
- package/esm/utils/RootClose.js +1 -1
- package/esm/utils/SimpleMap.js +1 -1
- package/esm/utils/api.d.ts +2 -2
- package/esm/utils/api.js +152 -112
- package/esm/utils/arraySlice.d.ts +1 -0
- package/esm/utils/arraySlice.js +76 -0
- package/esm/utils/attachmentAdpator.js +1 -1
- package/esm/utils/autobind.js +1 -1
- package/esm/utils/columnsSplit.js +1 -1
- package/esm/utils/dataMapping.js +29 -19
- package/esm/utils/date.js +1 -1
- package/esm/utils/debug.d.ts +2 -0
- package/esm/utils/debug.js +34 -7
- package/esm/utils/decodeEntity.js +1 -1
- package/esm/utils/dom.js +4 -1
- package/esm/utils/errors.js +1 -1
- package/esm/utils/escapeHtml.js +1 -1
- package/esm/utils/filter-schema.js +1 -1
- package/esm/utils/filter.js +1 -1
- package/esm/utils/formatDuration.js +1 -1
- package/esm/utils/formula.d.ts +0 -1
- package/esm/utils/formula.js +6 -9
- package/esm/utils/getVariable.js +1 -1
- package/esm/utils/grammar.js +1 -1
- package/esm/utils/handleAction.js +1 -1
- package/esm/utils/helper.d.ts +19 -2
- package/esm/utils/helper.js +69 -10
- package/esm/utils/highlight.js +1 -1
- package/esm/utils/icon.d.ts +4 -2
- package/esm/utils/icon.js +3 -2
- package/esm/utils/image.js +1 -1
- package/esm/utils/index.d.ts +2 -0
- package/esm/utils/isPureVariable.js +1 -1
- package/esm/utils/json-schema-2-amis-schema.js +1 -1
- package/esm/utils/keyToPath.js +1 -1
- package/esm/utils/makeSorter.js +1 -1
- package/esm/utils/math.d.ts +3 -0
- package/esm/utils/math.js +52 -0
- package/esm/utils/memoryParse.js +1 -1
- package/esm/utils/normalizeLink.js +18 -9
- package/esm/utils/normalizeOptions.js +1 -1
- package/esm/utils/object.d.ts +7 -0
- package/esm/utils/object.js +13 -2
- package/esm/utils/offset.js +1 -1
- package/esm/utils/offsetParent.js +1 -1
- package/esm/utils/optionValueCompare.js +2 -2
- package/esm/utils/position.js +1 -1
- package/esm/utils/prettyBytes.js +1 -1
- package/esm/utils/renderer-event.d.ts +1 -1
- package/esm/utils/renderer-event.js +14 -6
- package/esm/utils/replaceText.js +1 -1
- package/esm/utils/resize-sensor.js +1 -1
- package/esm/utils/resolveCondition.js +1 -1
- package/esm/utils/resolveVariable.js +1 -1
- package/esm/utils/resolveVariableAndFilter.js +1 -1
- package/esm/utils/resolveVariableAndFilterForAsync.js +1 -1
- package/esm/utils/scrollPosition.js +1 -1
- package/esm/utils/string2regExp.js +1 -1
- package/esm/utils/stripNumber.js +1 -1
- package/esm/utils/style-helper.js +1 -1
- package/esm/utils/style.js +1 -1
- package/esm/utils/toNumber.js +1 -1
- package/esm/utils/tokenize.js +1 -1
- package/esm/utils/tpl-builtin.js +1 -1
- package/esm/utils/tpl-lodash.js +1 -1
- package/esm/utils/tpl.js +1 -1
- package/esm/utils/uncontrollable.js +1 -1
- package/esm/utils/validations.js +1 -1
- package/lib/Root.js +10 -7
- package/lib/RootRenderer.d.ts +1 -1
- package/lib/RootRenderer.js +11 -8
- package/lib/SchemaRenderer.js +13 -6
- package/lib/Scoped.d.ts +4 -1
- package/lib/Scoped.js +19 -13
- package/lib/StatusScoped.js +5 -2
- package/lib/WithRootStore.d.ts +4 -24
- package/lib/WithRootStore.js +15 -4
- package/lib/WithStore.js +27 -17
- package/lib/actions/Action.d.ts +1 -0
- package/lib/actions/Action.js +70 -45
- package/lib/actions/AjaxAction.d.ts +6 -8
- package/lib/actions/AjaxAction.js +20 -18
- package/lib/actions/BreakAction.js +1 -1
- package/lib/actions/BroadcastAction.js +1 -1
- package/lib/actions/CmptAction.d.ts +1 -2
- package/lib/actions/CmptAction.js +47 -32
- package/lib/actions/ContinueAction.js +1 -1
- package/lib/actions/CopyAction.js +1 -1
- package/lib/actions/CustomAction.js +9 -5
- package/lib/actions/DialogAction.d.ts +2 -0
- package/lib/actions/DialogAction.js +39 -23
- package/lib/actions/DrawerAction.js +4 -4
- package/lib/actions/EmailAction.js +1 -1
- package/lib/actions/LinkAction.js +1 -1
- package/lib/actions/LoopAction.js +1 -1
- package/lib/actions/PageAction.js +1 -1
- package/lib/actions/ParallelAction.js +1 -1
- package/lib/actions/StatusAction.d.ts +15 -0
- package/lib/actions/StatusAction.js +53 -0
- package/lib/actions/SwitchAction.js +1 -1
- package/lib/actions/ToastAction.js +1 -1
- package/lib/actions/index.d.ts +1 -0
- package/lib/components/CustomStyle.js +1 -1
- package/lib/components/LazyComponent.js +12 -14
- package/lib/components/Overlay.js +15 -14
- package/lib/components/PopOver.js +12 -10
- package/lib/env.js +4 -1
- package/lib/envOverwrite.js +1 -1
- package/lib/factory.js +11 -9
- package/lib/index.d.ts +3 -1
- package/lib/index.js +26 -19
- package/lib/locale.js +6 -3
- package/lib/polyfills.d.ts +3 -0
- package/lib/polyfills.js +20 -0
- package/lib/renderers/Form.d.ts +7 -7
- package/lib/renderers/Form.js +194 -135
- package/lib/renderers/Item.d.ts +82 -77
- package/lib/renderers/Item.js +126 -104
- package/lib/renderers/Options.js +10 -5
- package/lib/renderers/Placeholder.js +1 -1
- package/lib/renderers/builtin.js +1 -1
- package/lib/renderers/register.js +1 -1
- package/lib/renderers/wrapControl.d.ts +4 -24
- package/lib/renderers/wrapControl.js +143 -88
- package/lib/store/app.js +44 -3
- package/lib/store/combo.d.ts +564 -1892
- package/lib/store/combo.js +9 -2
- package/lib/store/crud.d.ts +4 -2
- package/lib/store/crud.js +17 -4
- package/lib/store/form.d.ts +182 -882
- package/lib/store/form.js +81 -79
- package/lib/store/formItem.d.ts +6 -2
- package/lib/store/formItem.js +19 -3
- package/lib/store/iRenderer.js +9 -5
- package/lib/store/index.js +1 -1
- package/lib/store/list.d.ts +1 -0
- package/lib/store/list.js +8 -2
- package/lib/store/manager.js +1 -1
- package/lib/store/modal.js +1 -1
- package/lib/store/node.js +1 -1
- package/lib/store/pagination.js +1 -1
- package/lib/store/root.js +9 -5
- package/lib/store/service.js +17 -12
- package/lib/store/status.js +1 -1
- package/lib/store/table.d.ts +604 -2020
- package/lib/store/table.js +85 -55
- package/lib/store/table2.d.ts +49 -0
- package/lib/store/table2.js +36 -3
- package/lib/theme.js +6 -3
- package/lib/types.d.ts +22 -5
- package/lib/utils/Animation.js +1 -1
- package/lib/utils/ColorScale.js +1 -1
- package/lib/utils/DataSchema.d.ts +3 -2
- package/lib/utils/DataSchema.js +27 -7
- package/lib/utils/DataScope.d.ts +10 -3
- package/lib/utils/DataScope.js +50 -11
- package/lib/utils/RootClose.js +1 -1
- package/lib/utils/SimpleMap.js +1 -1
- package/lib/utils/api.d.ts +2 -2
- package/lib/utils/api.js +151 -111
- package/lib/utils/arraySlice.d.ts +1 -0
- package/lib/utils/arraySlice.js +80 -0
- package/lib/utils/attachmentAdpator.js +1 -1
- package/lib/utils/autobind.js +1 -1
- package/lib/utils/columnsSplit.js +8 -6
- package/lib/utils/dataMapping.js +29 -19
- package/lib/utils/date.js +1 -1
- package/lib/utils/debug.d.ts +2 -0
- package/lib/utils/debug.js +61 -33
- package/lib/utils/decodeEntity.js +1 -1
- package/lib/utils/dom.js +10 -5
- package/lib/utils/errors.js +1 -1
- package/lib/utils/escapeHtml.js +1 -1
- package/lib/utils/filter-schema.js +1 -1
- package/lib/utils/filter.js +1 -1
- package/lib/utils/formatDuration.js +1 -1
- package/lib/utils/formula.d.ts +0 -1
- package/lib/utils/formula.js +6 -10
- package/lib/utils/getVariable.js +1 -1
- package/lib/utils/grammar.js +1 -1
- package/lib/utils/handleAction.js +1 -1
- package/lib/utils/helper.d.ts +19 -2
- package/lib/utils/helper.js +70 -9
- package/lib/utils/highlight.js +8 -9
- package/lib/utils/icon.d.ts +4 -2
- package/lib/utils/icon.js +12 -10
- package/lib/utils/image.js +1 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/isPureVariable.js +1 -1
- package/lib/utils/json-schema-2-amis-schema.js +1 -1
- package/lib/utils/keyToPath.js +1 -1
- package/lib/utils/makeSorter.js +1 -1
- package/lib/utils/math.d.ts +3 -0
- package/lib/utils/math.js +58 -0
- package/lib/utils/memoryParse.js +1 -1
- package/lib/utils/normalizeLink.js +18 -9
- package/lib/utils/normalizeOptions.js +1 -1
- package/lib/utils/object.d.ts +7 -0
- package/lib/utils/object.js +13 -1
- package/lib/utils/offset.js +1 -1
- package/lib/utils/offsetParent.js +1 -1
- package/lib/utils/optionValueCompare.js +7 -3
- package/lib/utils/position.js +1 -1
- package/lib/utils/prettyBytes.js +1 -1
- package/lib/utils/renderer-event.d.ts +1 -1
- package/lib/utils/renderer-event.js +13 -5
- package/lib/utils/replaceText.js +1 -1
- package/lib/utils/resize-sensor.js +1 -1
- package/lib/utils/resolveCondition.js +1 -1
- package/lib/utils/resolveVariable.js +1 -1
- package/lib/utils/resolveVariableAndFilter.js +1 -1
- package/lib/utils/resolveVariableAndFilterForAsync.js +1 -1
- package/lib/utils/scrollPosition.js +1 -1
- package/lib/utils/string2regExp.js +1 -1
- package/lib/utils/stripNumber.js +1 -1
- package/lib/utils/style-helper.js +1 -1
- package/lib/utils/style.js +1 -1
- package/lib/utils/toNumber.js +1 -1
- package/lib/utils/tokenize.js +1 -1
- package/lib/utils/tpl-builtin.js +1 -1
- package/lib/utils/tpl-lodash.js +1 -1
- package/lib/utils/tpl.js +1 -1
- package/lib/utils/uncontrollable.js +1 -1
- package/lib/utils/validations.js +1 -1
- package/package.json +9 -4
package/esm/utils/DataScope.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core v3.
|
|
2
|
+
* amis-core v3.3.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -7,6 +7,14 @@ import { __values, __assign, __spreadArray, __read } from 'tslib';
|
|
|
7
7
|
import { guid, mapTree } from './helper.js';
|
|
8
8
|
import { keyToPath } from './keyToPath.js';
|
|
9
9
|
|
|
10
|
+
var DATASCHEMA_TYPE_MAP = {
|
|
11
|
+
boolean: '布尔',
|
|
12
|
+
integer: '整数',
|
|
13
|
+
number: '数字',
|
|
14
|
+
string: '文本',
|
|
15
|
+
array: '数组',
|
|
16
|
+
object: '对象'
|
|
17
|
+
};
|
|
10
18
|
var DataScope = /** @class */ (function () {
|
|
11
19
|
function DataScope(schemas, id) {
|
|
12
20
|
this.children = [];
|
|
@@ -167,31 +175,61 @@ var DataScope = /** @class */ (function () {
|
|
|
167
175
|
});
|
|
168
176
|
return mergedSchema;
|
|
169
177
|
};
|
|
170
|
-
DataScope.prototype.buildOptions = function (options, schema, path, key
|
|
178
|
+
DataScope.prototype.buildOptions = function (options, schema, path, key, isMember // 是否是数组成员
|
|
179
|
+
) {
|
|
171
180
|
var _this = this;
|
|
172
|
-
var _a;
|
|
173
|
-
if (path === void 0) { path = ''; }
|
|
181
|
+
var _a, _b, _c;
|
|
182
|
+
if (path === void 0) { path = { label: '', value: '' }; }
|
|
174
183
|
if (key === void 0) { key = ''; }
|
|
175
184
|
// todo 支持 oneOf, anyOf
|
|
176
185
|
var option = {
|
|
177
186
|
label: schema.title || key,
|
|
178
|
-
value: path,
|
|
187
|
+
value: schema.title === '成员' ? '' : path.value,
|
|
188
|
+
path: schema.title === '成员' ? '' : path.label,
|
|
179
189
|
type: schema.type,
|
|
180
|
-
tag: (_a = schema.
|
|
190
|
+
tag: (_b = (_a = schema.typeLabel) !== null && _a !== void 0 ? _a : DATASCHEMA_TYPE_MAP[schema.type]) !== null && _b !== void 0 ? _b : schema.type,
|
|
191
|
+
description: schema.description,
|
|
192
|
+
isMember: isMember,
|
|
193
|
+
disabled: schema.title === '成员'
|
|
181
194
|
};
|
|
182
|
-
|
|
195
|
+
// 处理option分组
|
|
196
|
+
if (schema.group) {
|
|
197
|
+
var index = options.findIndex(function (item) { return item.label === schema.group; });
|
|
198
|
+
if (~index) {
|
|
199
|
+
options[index].children.push(option);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
options.push({
|
|
203
|
+
label: schema.group,
|
|
204
|
+
value: '',
|
|
205
|
+
children: [option]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
options.push(option);
|
|
211
|
+
}
|
|
183
212
|
if (schema.type === 'object' && schema.properties) {
|
|
184
213
|
option.children = [];
|
|
185
214
|
var keys = Object.keys(schema.properties);
|
|
186
215
|
keys.forEach(function (key) {
|
|
216
|
+
var _a;
|
|
187
217
|
var child = schema.properties[key];
|
|
188
|
-
_this.buildOptions(option.children, child,
|
|
218
|
+
_this.buildOptions(option.children, child, {
|
|
219
|
+
label: path.label + (path.label ? '.' : '') + ((_a = child.title) !== null && _a !== void 0 ? _a : key),
|
|
220
|
+
value: path.value + (path.value ? '.' : '') + key
|
|
221
|
+
}, key, schema.title === '成员');
|
|
189
222
|
});
|
|
190
223
|
}
|
|
191
|
-
else if (schema.type === 'array' && schema.items) {
|
|
224
|
+
else if (schema.type === 'array' && ((_c = schema.items) === null || _c === void 0 ? void 0 : _c.properties)) {
|
|
192
225
|
option.children = [];
|
|
193
|
-
this.buildOptions(option.children, __assign(__assign({ title: '成员' }, schema.items), { disabled: true }),
|
|
194
|
-
|
|
226
|
+
this.buildOptions(option.children, __assign(__assign({ title: '成员' }, schema.items), { disabled: true }), {
|
|
227
|
+
label: path.label,
|
|
228
|
+
value: path.value
|
|
229
|
+
}, 'items', schema.title === '成员');
|
|
230
|
+
option.children = mapTree(option.children, function (item) { return (__assign({}, item
|
|
231
|
+
// disabled: true
|
|
232
|
+
)); });
|
|
195
233
|
}
|
|
196
234
|
};
|
|
197
235
|
DataScope.prototype.getDataPropsAsOptions = function () {
|
|
@@ -232,4 +270,4 @@ var DataScope = /** @class */ (function () {
|
|
|
232
270
|
return DataScope;
|
|
233
271
|
}());
|
|
234
272
|
|
|
235
|
-
export { DataScope };
|
|
273
|
+
export { DATASCHEMA_TYPE_MAP, DataScope };
|
package/esm/utils/RootClose.js
CHANGED
package/esm/utils/SimpleMap.js
CHANGED
package/esm/utils/api.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare function str2function(contents: string, ...args: Array<string>):
|
|
|
14
14
|
export declare function str2AsyncFunction(contents: string, ...args: Array<string>): Function | null;
|
|
15
15
|
export declare function responseAdaptor(ret: fetcherResult, api: ApiObject): Payload;
|
|
16
16
|
export declare function wrapFetcher(fn: (config: fetcherConfig) => Promise<fetcherResult>, tracker?: (eventTrack: EventTrack, data: any) => void): any;
|
|
17
|
-
export declare function wrapAdaptor(promise: Promise<fetcherResult>, api: ApiObject): Promise<Payload>;
|
|
17
|
+
export declare function wrapAdaptor(promise: Promise<fetcherResult>, api: ApiObject, context: any): Promise<Payload>;
|
|
18
18
|
/**
|
|
19
19
|
* 请求远程 js 文件然后 new Function 执行,用于 schemaApi 支持 JavaScript
|
|
20
20
|
* @param api
|
|
@@ -24,7 +24,7 @@ export declare function jsFetcher(fetcher: (config: fetcherConfig) => Promise<fe
|
|
|
24
24
|
export declare function jsonpFetcher(api: ApiObject): Promise<fetcherResult>;
|
|
25
25
|
export declare function isApiOutdatedWithData(prevApi: Api | undefined, nextApi: Api | undefined, prevData: any, nextData: any): nextApi is Api;
|
|
26
26
|
export declare function isApiOutdated(prevApi: Api | undefined, nextApi: Api | undefined, prevData: any, nextData: any): nextApi is Api;
|
|
27
|
-
export declare function isValidApi(api: string): boolean
|
|
27
|
+
export declare function isValidApi(api: string): boolean;
|
|
28
28
|
export declare function isEffectiveApi(api?: Api, data?: any, initFetch?: boolean, initFetchOn?: string): api is Api;
|
|
29
29
|
export declare function isSameApi(apiA: ApiObject | ApiCacheConfig, apiB: ApiObject | ApiCacheConfig): boolean;
|
|
30
30
|
export declare function getApiCache(api: ApiObject): ApiCacheConfig | undefined;
|
package/esm/utils/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* amis-core v3.
|
|
2
|
+
* amis-core v3.3.0
|
|
3
3
|
* Copyright 2018-2023 fex
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ import omit from 'lodash/omit';
|
|
|
8
8
|
import { evaluate } from 'amis-formula';
|
|
9
9
|
import { escapeHtml } from './escapeHtml.js';
|
|
10
10
|
import 'moment';
|
|
11
|
-
import { cloneObject, createObject, isObject } from './object.js';
|
|
11
|
+
import { cloneObject, extendObject, createObject, isObject } from './object.js';
|
|
12
12
|
import { tokenize } from './tokenize.js';
|
|
13
13
|
import { memoryParse } from './memoryParse.js';
|
|
14
14
|
import { dataMapping } from './dataMapping.js';
|
|
@@ -47,10 +47,10 @@ function buildApi(api, data, options) {
|
|
|
47
47
|
api.headers = dataMapping(api.headers, data, undefined, false);
|
|
48
48
|
}
|
|
49
49
|
if (api.requestAdaptor && typeof api.requestAdaptor === 'string') {
|
|
50
|
-
api.requestAdaptor =
|
|
50
|
+
api.requestAdaptor = str2AsyncFunction(api.requestAdaptor, 'api', 'context');
|
|
51
51
|
}
|
|
52
52
|
if (api.adaptor && typeof api.adaptor === 'string') {
|
|
53
|
-
api.adaptor =
|
|
53
|
+
api.adaptor = str2AsyncFunction(api.adaptor, 'payload', 'response', 'api', 'context');
|
|
54
54
|
}
|
|
55
55
|
if (!data) {
|
|
56
56
|
return api;
|
|
@@ -96,6 +96,23 @@ function buildApi(api, data, options) {
|
|
|
96
96
|
}
|
|
97
97
|
: undefined);
|
|
98
98
|
};
|
|
99
|
+
/** 追加data到请求的Query中 */
|
|
100
|
+
var attachDataToQuery = function (apiObject, ctx, merge) {
|
|
101
|
+
var idx = apiObject.url.indexOf('?');
|
|
102
|
+
if (~idx) {
|
|
103
|
+
var params = (apiObject.query = __assign(__assign(__assign({}, qsparse(apiObject.url.substring(idx + 1))), apiObject.query), ctx));
|
|
104
|
+
apiObject.url =
|
|
105
|
+
apiObject.url.substring(0, idx) + '?' + queryStringify(params);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
apiObject.query = __assign(__assign({}, apiObject.query), ctx);
|
|
109
|
+
var query = queryStringify(merge ? apiObject.query : ctx);
|
|
110
|
+
if (query) {
|
|
111
|
+
apiObject.url = "".concat(apiObject.url, "?").concat(query);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return apiObject;
|
|
115
|
+
};
|
|
99
116
|
if (~idx) {
|
|
100
117
|
var hashIdx = url.indexOf('#');
|
|
101
118
|
var params = qsparse(url.substring(idx + 1, ~hashIdx && hashIdx > idx ? hashIdx : undefined));
|
|
@@ -149,41 +166,19 @@ function buildApi(api, data, options) {
|
|
|
149
166
|
else if (api.attachDataToQuery === false &&
|
|
150
167
|
api.data &&
|
|
151
168
|
((!~raw.indexOf('$') && autoAppend) || api.forceAppendDataToQuery)) {
|
|
152
|
-
|
|
153
|
-
if (~idx_1) {
|
|
154
|
-
var params = (api.query = __assign(__assign(__assign({}, qsparse(api.url.substring(idx_1 + 1))), api.query), data));
|
|
155
|
-
api.url = api.url.substring(0, idx_1) + '?' + queryStringify(params);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
api.query = __assign(__assign({}, api.query), data);
|
|
159
|
-
var query = queryStringify(data);
|
|
160
|
-
if (query) {
|
|
161
|
-
api.url = "".concat(api.url, "?").concat(query);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
169
|
+
api = attachDataToQuery(api, data, false);
|
|
164
170
|
}
|
|
165
171
|
if (api.data && api.attachDataToQuery !== false) {
|
|
166
|
-
|
|
167
|
-
if (~idx_2) {
|
|
168
|
-
var params = (api.query = __assign(__assign(__assign({}, qsparse(api.url.substring(idx_2 + 1))), api.query), api.data));
|
|
169
|
-
api.url = api.url.substring(0, idx_2) + '?' + queryStringify(params);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
api.query = __assign(__assign({}, api.query), api.data);
|
|
173
|
-
var query = queryStringify(api.query);
|
|
174
|
-
if (query) {
|
|
175
|
-
api.url = "".concat(api.url, "?").concat(query);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
172
|
+
api = attachDataToQuery(api, api.data, true);
|
|
178
173
|
delete api.data;
|
|
179
174
|
}
|
|
180
175
|
}
|
|
181
176
|
// 非 get 类请求也可以携带参数到 url,只要 query 有值
|
|
182
177
|
else if (api.method) {
|
|
183
|
-
var
|
|
184
|
-
if (~
|
|
185
|
-
var params = (api.query = __assign(__assign({}, qsparse(api.url.substring(
|
|
186
|
-
api.url = api.url.substring(0,
|
|
178
|
+
var idx_1 = api.url.indexOf('?');
|
|
179
|
+
if (~idx_1) {
|
|
180
|
+
var params = (api.query = __assign(__assign({}, qsparse(api.url.substring(idx_1 + 1))), api.query));
|
|
181
|
+
api.url = api.url.substring(0, idx_1) + '?' + queryStringify(params);
|
|
187
182
|
}
|
|
188
183
|
else {
|
|
189
184
|
var query = queryStringify(api.query);
|
|
@@ -208,8 +203,21 @@ function buildApi(api, data, options) {
|
|
|
208
203
|
}
|
|
209
204
|
else if (api.jsonql) {
|
|
210
205
|
api.method = 'post';
|
|
211
|
-
api.jsonql = dataMapping(api.jsonql,
|
|
212
|
-
|
|
206
|
+
api.jsonql = dataMapping(api.jsonql,
|
|
207
|
+
/** 需要上层数据域的内容 */
|
|
208
|
+
extendObject(data, __assign(__assign({}, api.query), data), false), undefined, false, true);
|
|
209
|
+
/** 同时设置了JSONQL和data时走兼容场景 */
|
|
210
|
+
api.body = api.data =
|
|
211
|
+
api.data && api.jsonql
|
|
212
|
+
? {
|
|
213
|
+
data: api.data,
|
|
214
|
+
jsonql: api.jsonql
|
|
215
|
+
}
|
|
216
|
+
: api.jsonql;
|
|
217
|
+
/** JSONQL所有method需要追加data中的变量到query中 */
|
|
218
|
+
if (api.forceAppendDataToQuery) {
|
|
219
|
+
api = attachDataToQuery(api, data, true);
|
|
220
|
+
}
|
|
213
221
|
}
|
|
214
222
|
return api;
|
|
215
223
|
}
|
|
@@ -346,68 +354,84 @@ function wrapFetcher(fn, tracker) {
|
|
|
346
354
|
}
|
|
347
355
|
var wrappedFetcher = function (api, data, options) {
|
|
348
356
|
var _a, _b, _c;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
:
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
357
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
+
var apiCache, timeStamp;
|
|
359
|
+
return __generator(this, function (_d) {
|
|
360
|
+
switch (_d.label) {
|
|
361
|
+
case 0:
|
|
362
|
+
api = buildApi(api, data, options);
|
|
363
|
+
if (!api.requestAdaptor) return [3 /*break*/, 2];
|
|
364
|
+
debug('api', 'before requestAdaptor', api);
|
|
365
|
+
return [4 /*yield*/, api.requestAdaptor(api, data)];
|
|
366
|
+
case 1:
|
|
367
|
+
api = (_d.sent()) || api;
|
|
368
|
+
debug('api', 'after requestAdaptor', api);
|
|
369
|
+
_d.label = 2;
|
|
370
|
+
case 2:
|
|
371
|
+
if (api.data &&
|
|
372
|
+
(api.data instanceof FormData ||
|
|
373
|
+
hasFile(api.data) ||
|
|
374
|
+
api.dataType === 'form-data')) {
|
|
375
|
+
api.data =
|
|
376
|
+
api.data instanceof FormData
|
|
377
|
+
? api.data
|
|
378
|
+
: object2formData(api.data, api.qsOptions);
|
|
379
|
+
}
|
|
380
|
+
else if (api.data &&
|
|
381
|
+
typeof api.data !== 'string' &&
|
|
382
|
+
api.dataType === 'form') {
|
|
383
|
+
api.data = qsstringify(api.data, api.qsOptions);
|
|
384
|
+
api.headers = api.headers || (api.headers = {});
|
|
385
|
+
api.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
386
|
+
}
|
|
387
|
+
else if (api.data &&
|
|
388
|
+
typeof api.data !== 'string' &&
|
|
389
|
+
api.dataType === 'json') {
|
|
390
|
+
api.data = JSON.stringify(api.data);
|
|
391
|
+
api.headers = api.headers || (api.headers = {});
|
|
392
|
+
api.headers['Content-Type'] = 'application/json';
|
|
393
|
+
}
|
|
394
|
+
// 如果发送适配器中设置了 mockResponse
|
|
395
|
+
// 则直接跳过请求发送
|
|
396
|
+
if (api.mockResponse) {
|
|
397
|
+
return [2 /*return*/, wrapAdaptor(Promise.resolve(api.mockResponse), api, data)];
|
|
398
|
+
}
|
|
399
|
+
if (!isValidApi(api.url)) {
|
|
400
|
+
throw new Error("invalid api url:".concat(api.url));
|
|
401
|
+
}
|
|
402
|
+
debug('api', 'request api', api);
|
|
403
|
+
tracker === null || tracker === void 0 ? void 0 : tracker({ eventType: 'api', eventData: omit(api, ['config', 'data', 'body']) }, api.data);
|
|
404
|
+
if (((_a = api.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === 'jsonp') {
|
|
405
|
+
return [2 /*return*/, wrapAdaptor(jsonpFetcher(api), api, data)];
|
|
406
|
+
}
|
|
407
|
+
if (((_b = api.method) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) === 'js') {
|
|
408
|
+
return [2 /*return*/, wrapAdaptor(jsFetcher(fn, api), api, data)];
|
|
409
|
+
}
|
|
410
|
+
if (typeof api.cache === 'number' && api.cache > 0) {
|
|
411
|
+
apiCache = getApiCache(api);
|
|
412
|
+
return [2 /*return*/, wrapAdaptor(apiCache
|
|
413
|
+
? apiCache.cachedPromise
|
|
414
|
+
: setApiCache(api, fn(api)), api, data)];
|
|
415
|
+
}
|
|
416
|
+
// IE 下 get 请求会被缓存,所以自动加个时间戳
|
|
417
|
+
if (isIE && api && ((_c = api.method) === null || _c === void 0 ? void 0 : _c.toLocaleLowerCase()) === 'get') {
|
|
418
|
+
timeStamp = "_t=".concat(Date.now());
|
|
419
|
+
if (api.url.indexOf('?') === -1) {
|
|
420
|
+
api.url = api.url + "?".concat(timeStamp);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
api.url = api.url + "&".concat(timeStamp);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return [2 /*return*/, wrapAdaptor(fn(api), api, data)];
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
});
|
|
406
430
|
};
|
|
407
431
|
wrappedFetcher._wrappedFetcher = true;
|
|
408
432
|
return wrappedFetcher;
|
|
409
433
|
}
|
|
410
|
-
function wrapAdaptor(promise, api) {
|
|
434
|
+
function wrapAdaptor(promise, api, context) {
|
|
411
435
|
var _this = this;
|
|
412
436
|
var adaptor = api.adaptor;
|
|
413
437
|
return adaptor
|
|
@@ -418,7 +442,7 @@ function wrapAdaptor(promise, api) {
|
|
|
418
442
|
switch (_a.label) {
|
|
419
443
|
case 0:
|
|
420
444
|
debug('api', 'before adaptor data', response.data);
|
|
421
|
-
result = adaptor(response.data, response, api);
|
|
445
|
+
result = adaptor(response.data, response, api, context);
|
|
422
446
|
if (!(result === null || result === void 0 ? void 0 : result.then)) return [3 /*break*/, 2];
|
|
423
447
|
return [4 /*yield*/, result];
|
|
424
448
|
case 1:
|
|
@@ -532,41 +556,57 @@ function isApiOutdated(prevApi, nextApi, prevData, nextData) {
|
|
|
532
556
|
return true;
|
|
533
557
|
}
|
|
534
558
|
nextApi = normalizeApi(nextApi);
|
|
559
|
+
prevApi = (prevApi ? normalizeApi(prevApi) : prevApi);
|
|
535
560
|
if (nextApi.autoRefresh === false) {
|
|
536
561
|
return false;
|
|
537
562
|
}
|
|
563
|
+
// api 本身有变化
|
|
564
|
+
if ((prevApi && prevApi.url !== nextApi.url) || !prevApi) {
|
|
565
|
+
return !!(isValidApi(nextApi.url) &&
|
|
566
|
+
(!nextApi.sendOn || evalExpression(nextApi.sendOn, nextData)));
|
|
567
|
+
}
|
|
538
568
|
var trackExpression = (_a = nextApi.trackExpression) !== null && _a !== void 0 ? _a : nextApi.url;
|
|
539
569
|
if (typeof trackExpression !== 'string' || !~trackExpression.indexOf('$')) {
|
|
540
570
|
return false;
|
|
541
571
|
}
|
|
542
572
|
var isModified = false;
|
|
543
|
-
if (prevApi) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
tokenize(prevApi.trackExpression || '', prevData) !==
|
|
548
|
-
tokenize(nextApi.trackExpression || '', nextData);
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
prevApi = buildApi(prevApi, prevData, {
|
|
552
|
-
ignoreData: true
|
|
553
|
-
});
|
|
554
|
-
nextApi = buildApi(nextApi, nextData, {
|
|
555
|
-
ignoreData: true
|
|
556
|
-
});
|
|
557
|
-
isModified = prevApi.url !== nextApi.url;
|
|
558
|
-
}
|
|
573
|
+
if (nextApi.trackExpression || prevApi.trackExpression) {
|
|
574
|
+
isModified =
|
|
575
|
+
tokenize(prevApi.trackExpression || '', prevData) !==
|
|
576
|
+
tokenize(nextApi.trackExpression || '', nextData);
|
|
559
577
|
}
|
|
560
578
|
else {
|
|
561
|
-
|
|
579
|
+
prevApi = buildApi(prevApi, prevData, {
|
|
580
|
+
ignoreData: true
|
|
581
|
+
});
|
|
582
|
+
nextApi = buildApi(nextApi, nextData, {
|
|
583
|
+
ignoreData: true
|
|
584
|
+
});
|
|
585
|
+
isModified = prevApi.url !== nextApi.url;
|
|
562
586
|
}
|
|
563
587
|
return !!(isModified &&
|
|
564
588
|
isValidApi(nextApi.url) &&
|
|
565
589
|
(!nextApi.sendOn || evalExpression(nextApi.sendOn, nextData)));
|
|
566
590
|
}
|
|
567
591
|
function isValidApi(api) {
|
|
568
|
-
|
|
569
|
-
|
|
592
|
+
if (!api || typeof api !== 'string') {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
var idx = api.indexOf('://');
|
|
596
|
+
// 不允许直接相对路径写 api
|
|
597
|
+
// 不允许 :// 结尾
|
|
598
|
+
if ((!~idx && api[0] !== '/') || (~idx && idx + 3 === api.length)) {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
try {
|
|
602
|
+
// 不补一个协议,URL 判断为 false
|
|
603
|
+
api = (~idx ? '' : 'schema://domain') + api;
|
|
604
|
+
new URL(api);
|
|
605
|
+
}
|
|
606
|
+
catch (error) {
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
return true;
|
|
570
610
|
}
|
|
571
611
|
function isEffectiveApi(api, data, initFetch, initFetchOn) {
|
|
572
612
|
if (!api) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function arraySlice(array: any[], slice: string): any[];
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* amis-core v3.3.0
|
|
3
|
+
* Copyright 2018-2023 fex
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { __values, __read, __spreadArray } from 'tslib';
|
|
7
|
+
import { isObservableArray, toJS } from 'mobx';
|
|
8
|
+
|
|
9
|
+
function arraySlice(array, slice) {
|
|
10
|
+
var e_1, _a;
|
|
11
|
+
if (typeof slice !== 'string') {
|
|
12
|
+
return array;
|
|
13
|
+
}
|
|
14
|
+
if (isObservableArray(array)) {
|
|
15
|
+
array = toJS(array);
|
|
16
|
+
}
|
|
17
|
+
slice = slice.trim();
|
|
18
|
+
if (!slice || !Array.isArray(array)) {
|
|
19
|
+
return array;
|
|
20
|
+
}
|
|
21
|
+
var parts = slice.split(',');
|
|
22
|
+
var ret = [];
|
|
23
|
+
var arrayLength = array.length;
|
|
24
|
+
if (!arrayLength) {
|
|
25
|
+
return array;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
|
|
29
|
+
var part = parts_1_1.value;
|
|
30
|
+
// 普通的场景
|
|
31
|
+
if (part.indexOf(':') === -1) {
|
|
32
|
+
var index = parseInt(part, 10);
|
|
33
|
+
if (!isNaN(index) && index < arrayLength) {
|
|
34
|
+
ret.push(array[index]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
var _b = __read(part.split(':'), 2), start = _b[0], end = _b[1];
|
|
39
|
+
var startIndex = parseInt(start || '0', 10);
|
|
40
|
+
if (isNaN(startIndex) || startIndex < 0) {
|
|
41
|
+
startIndex = 0;
|
|
42
|
+
}
|
|
43
|
+
// 大于就没意义了
|
|
44
|
+
if (startIndex >= arrayLength) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
var endIndex = parseInt(end, 10);
|
|
48
|
+
if (isNaN(endIndex)) {
|
|
49
|
+
endIndex = arrayLength;
|
|
50
|
+
}
|
|
51
|
+
// 负数就从后面开始取
|
|
52
|
+
if (endIndex < 0) {
|
|
53
|
+
endIndex = arrayLength + endIndex;
|
|
54
|
+
}
|
|
55
|
+
// 小于没有意义
|
|
56
|
+
if (endIndex < startIndex) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (endIndex > arrayLength) {
|
|
60
|
+
endIndex = arrayLength;
|
|
61
|
+
}
|
|
62
|
+
ret.push.apply(ret, __spreadArray([], __read(array.slice(startIndex, endIndex)), false));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
67
|
+
finally {
|
|
68
|
+
try {
|
|
69
|
+
if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
|
|
70
|
+
}
|
|
71
|
+
finally { if (e_1) throw e_1.error; }
|
|
72
|
+
}
|
|
73
|
+
return ret;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { arraySlice };
|
package/esm/utils/autobind.js
CHANGED