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.
Files changed (313) hide show
  1. package/esm/Root.js +1 -1
  2. package/esm/RootRenderer.d.ts +1 -1
  3. package/esm/RootRenderer.js +3 -3
  4. package/esm/SchemaRenderer.js +6 -2
  5. package/esm/Scoped.d.ts +4 -1
  6. package/esm/Scoped.js +9 -5
  7. package/esm/StatusScoped.js +1 -1
  8. package/esm/WithRootStore.d.ts +4 -24
  9. package/esm/WithRootStore.js +12 -4
  10. package/esm/WithStore.js +23 -16
  11. package/esm/actions/Action.d.ts +1 -0
  12. package/esm/actions/Action.js +70 -45
  13. package/esm/actions/AjaxAction.d.ts +6 -8
  14. package/esm/actions/AjaxAction.js +20 -18
  15. package/esm/actions/BreakAction.js +1 -1
  16. package/esm/actions/BroadcastAction.js +1 -1
  17. package/esm/actions/CmptAction.d.ts +1 -2
  18. package/esm/actions/CmptAction.js +47 -32
  19. package/esm/actions/ContinueAction.js +1 -1
  20. package/esm/actions/CopyAction.js +1 -1
  21. package/esm/actions/CustomAction.js +3 -2
  22. package/esm/actions/DialogAction.d.ts +2 -0
  23. package/esm/actions/DialogAction.js +39 -23
  24. package/esm/actions/DrawerAction.js +4 -4
  25. package/esm/actions/EmailAction.js +1 -1
  26. package/esm/actions/LinkAction.js +1 -1
  27. package/esm/actions/LoopAction.js +1 -1
  28. package/esm/actions/PageAction.js +1 -1
  29. package/esm/actions/ParallelAction.js +1 -1
  30. package/esm/actions/StatusAction.d.ts +15 -0
  31. package/esm/actions/StatusAction.js +49 -0
  32. package/esm/actions/SwitchAction.js +1 -1
  33. package/esm/actions/ToastAction.js +1 -1
  34. package/esm/actions/index.d.ts +1 -0
  35. package/esm/components/CustomStyle.js +1 -1
  36. package/esm/components/LazyComponent.js +1 -1
  37. package/esm/components/Overlay.js +3 -2
  38. package/esm/components/PopOver.js +3 -2
  39. package/esm/env.js +1 -1
  40. package/esm/envOverwrite.js +1 -1
  41. package/esm/factory.js +2 -2
  42. package/esm/index.d.ts +3 -1
  43. package/esm/index.js +16 -14
  44. package/esm/locale.js +1 -1
  45. package/esm/polyfills.d.ts +3 -0
  46. package/esm/polyfills.js +18 -0
  47. package/esm/renderers/Form.d.ts +7 -7
  48. package/esm/renderers/Form.js +182 -128
  49. package/esm/renderers/Item.d.ts +82 -77
  50. package/esm/renderers/Item.js +90 -74
  51. package/esm/renderers/Options.js +1 -2
  52. package/esm/renderers/Placeholder.js +1 -1
  53. package/esm/renderers/builtin.js +1 -1
  54. package/esm/renderers/register.js +1 -1
  55. package/esm/renderers/wrapControl.d.ts +4 -24
  56. package/esm/renderers/wrapControl.js +140 -88
  57. package/esm/store/app.js +42 -4
  58. package/esm/store/combo.d.ts +564 -1892
  59. package/esm/store/combo.js +9 -2
  60. package/esm/store/crud.d.ts +4 -2
  61. package/esm/store/crud.js +17 -4
  62. package/esm/store/form.d.ts +182 -882
  63. package/esm/store/form.js +83 -81
  64. package/esm/store/formItem.d.ts +6 -2
  65. package/esm/store/formItem.js +19 -3
  66. package/esm/store/iRenderer.js +3 -2
  67. package/esm/store/index.js +1 -1
  68. package/esm/store/list.d.ts +1 -0
  69. package/esm/store/list.js +8 -2
  70. package/esm/store/manager.js +1 -1
  71. package/esm/store/modal.js +1 -1
  72. package/esm/store/node.js +1 -1
  73. package/esm/store/pagination.js +1 -1
  74. package/esm/store/root.js +3 -2
  75. package/esm/store/service.js +17 -12
  76. package/esm/store/status.js +1 -1
  77. package/esm/store/table.d.ts +604 -2020
  78. package/esm/store/table.js +86 -56
  79. package/esm/store/table2.d.ts +49 -0
  80. package/esm/store/table2.js +37 -4
  81. package/esm/theme.js +1 -1
  82. package/esm/types.d.ts +22 -5
  83. package/esm/utils/Animation.js +1 -1
  84. package/esm/utils/ColorScale.js +1 -1
  85. package/esm/utils/DataSchema.d.ts +3 -2
  86. package/esm/utils/DataSchema.js +27 -7
  87. package/esm/utils/DataScope.d.ts +10 -3
  88. package/esm/utils/DataScope.js +50 -12
  89. package/esm/utils/RootClose.js +1 -1
  90. package/esm/utils/SimpleMap.js +1 -1
  91. package/esm/utils/api.d.ts +2 -2
  92. package/esm/utils/api.js +152 -112
  93. package/esm/utils/arraySlice.d.ts +1 -0
  94. package/esm/utils/arraySlice.js +76 -0
  95. package/esm/utils/attachmentAdpator.js +1 -1
  96. package/esm/utils/autobind.js +1 -1
  97. package/esm/utils/columnsSplit.js +1 -1
  98. package/esm/utils/dataMapping.js +29 -19
  99. package/esm/utils/date.js +1 -1
  100. package/esm/utils/debug.d.ts +2 -0
  101. package/esm/utils/debug.js +34 -7
  102. package/esm/utils/decodeEntity.js +1 -1
  103. package/esm/utils/dom.js +4 -1
  104. package/esm/utils/errors.js +1 -1
  105. package/esm/utils/escapeHtml.js +1 -1
  106. package/esm/utils/filter-schema.js +1 -1
  107. package/esm/utils/filter.js +1 -1
  108. package/esm/utils/formatDuration.js +1 -1
  109. package/esm/utils/formula.d.ts +0 -1
  110. package/esm/utils/formula.js +6 -9
  111. package/esm/utils/getVariable.js +1 -1
  112. package/esm/utils/grammar.js +1 -1
  113. package/esm/utils/handleAction.js +1 -1
  114. package/esm/utils/helper.d.ts +19 -2
  115. package/esm/utils/helper.js +69 -10
  116. package/esm/utils/highlight.js +1 -1
  117. package/esm/utils/icon.d.ts +4 -2
  118. package/esm/utils/icon.js +3 -2
  119. package/esm/utils/image.js +1 -1
  120. package/esm/utils/index.d.ts +2 -0
  121. package/esm/utils/isPureVariable.js +1 -1
  122. package/esm/utils/json-schema-2-amis-schema.js +1 -1
  123. package/esm/utils/keyToPath.js +1 -1
  124. package/esm/utils/makeSorter.js +1 -1
  125. package/esm/utils/math.d.ts +3 -0
  126. package/esm/utils/math.js +52 -0
  127. package/esm/utils/memoryParse.js +1 -1
  128. package/esm/utils/normalizeLink.js +18 -9
  129. package/esm/utils/normalizeOptions.js +1 -1
  130. package/esm/utils/object.d.ts +7 -0
  131. package/esm/utils/object.js +13 -2
  132. package/esm/utils/offset.js +1 -1
  133. package/esm/utils/offsetParent.js +1 -1
  134. package/esm/utils/optionValueCompare.js +2 -2
  135. package/esm/utils/position.js +1 -1
  136. package/esm/utils/prettyBytes.js +1 -1
  137. package/esm/utils/renderer-event.d.ts +1 -1
  138. package/esm/utils/renderer-event.js +14 -6
  139. package/esm/utils/replaceText.js +1 -1
  140. package/esm/utils/resize-sensor.js +1 -1
  141. package/esm/utils/resolveCondition.js +1 -1
  142. package/esm/utils/resolveVariable.js +1 -1
  143. package/esm/utils/resolveVariableAndFilter.js +1 -1
  144. package/esm/utils/resolveVariableAndFilterForAsync.js +1 -1
  145. package/esm/utils/scrollPosition.js +1 -1
  146. package/esm/utils/string2regExp.js +1 -1
  147. package/esm/utils/stripNumber.js +1 -1
  148. package/esm/utils/style-helper.js +1 -1
  149. package/esm/utils/style.js +1 -1
  150. package/esm/utils/toNumber.js +1 -1
  151. package/esm/utils/tokenize.js +1 -1
  152. package/esm/utils/tpl-builtin.js +1 -1
  153. package/esm/utils/tpl-lodash.js +1 -1
  154. package/esm/utils/tpl.js +1 -1
  155. package/esm/utils/uncontrollable.js +1 -1
  156. package/esm/utils/validations.js +1 -1
  157. package/lib/Root.js +10 -7
  158. package/lib/RootRenderer.d.ts +1 -1
  159. package/lib/RootRenderer.js +11 -8
  160. package/lib/SchemaRenderer.js +13 -6
  161. package/lib/Scoped.d.ts +4 -1
  162. package/lib/Scoped.js +19 -13
  163. package/lib/StatusScoped.js +5 -2
  164. package/lib/WithRootStore.d.ts +4 -24
  165. package/lib/WithRootStore.js +15 -4
  166. package/lib/WithStore.js +27 -17
  167. package/lib/actions/Action.d.ts +1 -0
  168. package/lib/actions/Action.js +70 -45
  169. package/lib/actions/AjaxAction.d.ts +6 -8
  170. package/lib/actions/AjaxAction.js +20 -18
  171. package/lib/actions/BreakAction.js +1 -1
  172. package/lib/actions/BroadcastAction.js +1 -1
  173. package/lib/actions/CmptAction.d.ts +1 -2
  174. package/lib/actions/CmptAction.js +47 -32
  175. package/lib/actions/ContinueAction.js +1 -1
  176. package/lib/actions/CopyAction.js +1 -1
  177. package/lib/actions/CustomAction.js +9 -5
  178. package/lib/actions/DialogAction.d.ts +2 -0
  179. package/lib/actions/DialogAction.js +39 -23
  180. package/lib/actions/DrawerAction.js +4 -4
  181. package/lib/actions/EmailAction.js +1 -1
  182. package/lib/actions/LinkAction.js +1 -1
  183. package/lib/actions/LoopAction.js +1 -1
  184. package/lib/actions/PageAction.js +1 -1
  185. package/lib/actions/ParallelAction.js +1 -1
  186. package/lib/actions/StatusAction.d.ts +15 -0
  187. package/lib/actions/StatusAction.js +53 -0
  188. package/lib/actions/SwitchAction.js +1 -1
  189. package/lib/actions/ToastAction.js +1 -1
  190. package/lib/actions/index.d.ts +1 -0
  191. package/lib/components/CustomStyle.js +1 -1
  192. package/lib/components/LazyComponent.js +12 -14
  193. package/lib/components/Overlay.js +15 -14
  194. package/lib/components/PopOver.js +12 -10
  195. package/lib/env.js +4 -1
  196. package/lib/envOverwrite.js +1 -1
  197. package/lib/factory.js +11 -9
  198. package/lib/index.d.ts +3 -1
  199. package/lib/index.js +26 -19
  200. package/lib/locale.js +6 -3
  201. package/lib/polyfills.d.ts +3 -0
  202. package/lib/polyfills.js +20 -0
  203. package/lib/renderers/Form.d.ts +7 -7
  204. package/lib/renderers/Form.js +194 -135
  205. package/lib/renderers/Item.d.ts +82 -77
  206. package/lib/renderers/Item.js +126 -104
  207. package/lib/renderers/Options.js +10 -5
  208. package/lib/renderers/Placeholder.js +1 -1
  209. package/lib/renderers/builtin.js +1 -1
  210. package/lib/renderers/register.js +1 -1
  211. package/lib/renderers/wrapControl.d.ts +4 -24
  212. package/lib/renderers/wrapControl.js +143 -88
  213. package/lib/store/app.js +44 -3
  214. package/lib/store/combo.d.ts +564 -1892
  215. package/lib/store/combo.js +9 -2
  216. package/lib/store/crud.d.ts +4 -2
  217. package/lib/store/crud.js +17 -4
  218. package/lib/store/form.d.ts +182 -882
  219. package/lib/store/form.js +81 -79
  220. package/lib/store/formItem.d.ts +6 -2
  221. package/lib/store/formItem.js +19 -3
  222. package/lib/store/iRenderer.js +9 -5
  223. package/lib/store/index.js +1 -1
  224. package/lib/store/list.d.ts +1 -0
  225. package/lib/store/list.js +8 -2
  226. package/lib/store/manager.js +1 -1
  227. package/lib/store/modal.js +1 -1
  228. package/lib/store/node.js +1 -1
  229. package/lib/store/pagination.js +1 -1
  230. package/lib/store/root.js +9 -5
  231. package/lib/store/service.js +17 -12
  232. package/lib/store/status.js +1 -1
  233. package/lib/store/table.d.ts +604 -2020
  234. package/lib/store/table.js +85 -55
  235. package/lib/store/table2.d.ts +49 -0
  236. package/lib/store/table2.js +36 -3
  237. package/lib/theme.js +6 -3
  238. package/lib/types.d.ts +22 -5
  239. package/lib/utils/Animation.js +1 -1
  240. package/lib/utils/ColorScale.js +1 -1
  241. package/lib/utils/DataSchema.d.ts +3 -2
  242. package/lib/utils/DataSchema.js +27 -7
  243. package/lib/utils/DataScope.d.ts +10 -3
  244. package/lib/utils/DataScope.js +50 -11
  245. package/lib/utils/RootClose.js +1 -1
  246. package/lib/utils/SimpleMap.js +1 -1
  247. package/lib/utils/api.d.ts +2 -2
  248. package/lib/utils/api.js +151 -111
  249. package/lib/utils/arraySlice.d.ts +1 -0
  250. package/lib/utils/arraySlice.js +80 -0
  251. package/lib/utils/attachmentAdpator.js +1 -1
  252. package/lib/utils/autobind.js +1 -1
  253. package/lib/utils/columnsSplit.js +8 -6
  254. package/lib/utils/dataMapping.js +29 -19
  255. package/lib/utils/date.js +1 -1
  256. package/lib/utils/debug.d.ts +2 -0
  257. package/lib/utils/debug.js +61 -33
  258. package/lib/utils/decodeEntity.js +1 -1
  259. package/lib/utils/dom.js +10 -5
  260. package/lib/utils/errors.js +1 -1
  261. package/lib/utils/escapeHtml.js +1 -1
  262. package/lib/utils/filter-schema.js +1 -1
  263. package/lib/utils/filter.js +1 -1
  264. package/lib/utils/formatDuration.js +1 -1
  265. package/lib/utils/formula.d.ts +0 -1
  266. package/lib/utils/formula.js +6 -10
  267. package/lib/utils/getVariable.js +1 -1
  268. package/lib/utils/grammar.js +1 -1
  269. package/lib/utils/handleAction.js +1 -1
  270. package/lib/utils/helper.d.ts +19 -2
  271. package/lib/utils/helper.js +70 -9
  272. package/lib/utils/highlight.js +8 -9
  273. package/lib/utils/icon.d.ts +4 -2
  274. package/lib/utils/icon.js +12 -10
  275. package/lib/utils/image.js +1 -1
  276. package/lib/utils/index.d.ts +2 -0
  277. package/lib/utils/isPureVariable.js +1 -1
  278. package/lib/utils/json-schema-2-amis-schema.js +1 -1
  279. package/lib/utils/keyToPath.js +1 -1
  280. package/lib/utils/makeSorter.js +1 -1
  281. package/lib/utils/math.d.ts +3 -0
  282. package/lib/utils/math.js +58 -0
  283. package/lib/utils/memoryParse.js +1 -1
  284. package/lib/utils/normalizeLink.js +18 -9
  285. package/lib/utils/normalizeOptions.js +1 -1
  286. package/lib/utils/object.d.ts +7 -0
  287. package/lib/utils/object.js +13 -1
  288. package/lib/utils/offset.js +1 -1
  289. package/lib/utils/offsetParent.js +1 -1
  290. package/lib/utils/optionValueCompare.js +7 -3
  291. package/lib/utils/position.js +1 -1
  292. package/lib/utils/prettyBytes.js +1 -1
  293. package/lib/utils/renderer-event.d.ts +1 -1
  294. package/lib/utils/renderer-event.js +13 -5
  295. package/lib/utils/replaceText.js +1 -1
  296. package/lib/utils/resize-sensor.js +1 -1
  297. package/lib/utils/resolveCondition.js +1 -1
  298. package/lib/utils/resolveVariable.js +1 -1
  299. package/lib/utils/resolveVariableAndFilter.js +1 -1
  300. package/lib/utils/resolveVariableAndFilterForAsync.js +1 -1
  301. package/lib/utils/scrollPosition.js +1 -1
  302. package/lib/utils/string2regExp.js +1 -1
  303. package/lib/utils/stripNumber.js +1 -1
  304. package/lib/utils/style-helper.js +1 -1
  305. package/lib/utils/style.js +1 -1
  306. package/lib/utils/toNumber.js +1 -1
  307. package/lib/utils/tokenize.js +1 -1
  308. package/lib/utils/tpl-builtin.js +1 -1
  309. package/lib/utils/tpl-lodash.js +1 -1
  310. package/lib/utils/tpl.js +1 -1
  311. package/lib/utils/uncontrollable.js +1 -1
  312. package/lib/utils/validations.js +1 -1
  313. package/package.json +9 -4
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.1.1
2
+ * amis-core v3.3.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -11,6 +11,14 @@ var tslib = require('tslib');
11
11
  var helper = require('./helper.js');
12
12
  var keyToPath = require('./keyToPath.js');
13
13
 
14
+ var DATASCHEMA_TYPE_MAP = {
15
+ boolean: '布尔',
16
+ integer: '整数',
17
+ number: '数字',
18
+ string: '文本',
19
+ array: '数组',
20
+ object: '对象'
21
+ };
14
22
  var DataScope = /** @class */ (function () {
15
23
  function DataScope(schemas, id) {
16
24
  this.children = [];
@@ -171,31 +179,61 @@ var DataScope = /** @class */ (function () {
171
179
  });
172
180
  return mergedSchema;
173
181
  };
174
- DataScope.prototype.buildOptions = function (options, schema, path, key) {
182
+ DataScope.prototype.buildOptions = function (options, schema, path, key, isMember // 是否是数组成员
183
+ ) {
175
184
  var _this = this;
176
- var _a;
177
- if (path === void 0) { path = ''; }
185
+ var _a, _b, _c;
186
+ if (path === void 0) { path = { label: '', value: '' }; }
178
187
  if (key === void 0) { key = ''; }
179
188
  // todo 支持 oneOf, anyOf
180
189
  var option = {
181
190
  label: schema.title || key,
182
- value: path,
191
+ value: schema.title === '成员' ? '' : path.value,
192
+ path: schema.title === '成员' ? '' : path.label,
183
193
  type: schema.type,
184
- tag: (_a = schema.description) !== null && _a !== void 0 ? _a : schema.type
194
+ tag: (_b = (_a = schema.typeLabel) !== null && _a !== void 0 ? _a : DATASCHEMA_TYPE_MAP[schema.type]) !== null && _b !== void 0 ? _b : schema.type,
195
+ description: schema.description,
196
+ isMember: isMember,
197
+ disabled: schema.title === '成员'
185
198
  };
186
- options.push(option);
199
+ // 处理option分组
200
+ if (schema.group) {
201
+ var index = options.findIndex(function (item) { return item.label === schema.group; });
202
+ if (~index) {
203
+ options[index].children.push(option);
204
+ }
205
+ else {
206
+ options.push({
207
+ label: schema.group,
208
+ value: '',
209
+ children: [option]
210
+ });
211
+ }
212
+ }
213
+ else {
214
+ options.push(option);
215
+ }
187
216
  if (schema.type === 'object' && schema.properties) {
188
217
  option.children = [];
189
218
  var keys = Object.keys(schema.properties);
190
219
  keys.forEach(function (key) {
220
+ var _a;
191
221
  var child = schema.properties[key];
192
- _this.buildOptions(option.children, child, path + (path ? '.' : '') + key, key);
222
+ _this.buildOptions(option.children, child, {
223
+ label: path.label + (path.label ? '.' : '') + ((_a = child.title) !== null && _a !== void 0 ? _a : key),
224
+ value: path.value + (path.value ? '.' : '') + key
225
+ }, key, schema.title === '成员');
193
226
  });
194
227
  }
195
- else if (schema.type === 'array' && schema.items) {
228
+ else if (schema.type === 'array' && ((_c = schema.items) === null || _c === void 0 ? void 0 : _c.properties)) {
196
229
  option.children = [];
197
- this.buildOptions(option.children, tslib.__assign(tslib.__assign({ title: '成员' }, schema.items), { disabled: true }), path, 'items');
198
- option.children = helper.mapTree(option.children, function (item) { return (tslib.__assign(tslib.__assign({}, item), { disabled: true })); });
230
+ this.buildOptions(option.children, tslib.__assign(tslib.__assign({ title: '成员' }, schema.items), { disabled: true }), {
231
+ label: path.label,
232
+ value: path.value
233
+ }, 'items', schema.title === '成员');
234
+ option.children = helper.mapTree(option.children, function (item) { return (tslib.__assign({}, item
235
+ // disabled: true
236
+ )); });
199
237
  }
200
238
  };
201
239
  DataScope.prototype.getDataPropsAsOptions = function () {
@@ -236,4 +274,5 @@ var DataScope = /** @class */ (function () {
236
274
  return DataScope;
237
275
  }());
238
276
 
277
+ exports.DATASCHEMA_TYPE_MAP = DATASCHEMA_TYPE_MAP;
239
278
  exports.DataScope = DataScope;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.1.1
2
+ * amis-core v3.3.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.1.1
2
+ * amis-core v3.3.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -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/lib/utils/api.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.1.1
2
+ * amis-core v3.3.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -56,10 +56,10 @@ function buildApi(api, data, options) {
56
56
  api.headers = dataMapping.dataMapping(api.headers, data, undefined, false);
57
57
  }
58
58
  if (api.requestAdaptor && typeof api.requestAdaptor === 'string') {
59
- api.requestAdaptor = str2function(api.requestAdaptor, 'api');
59
+ api.requestAdaptor = str2AsyncFunction(api.requestAdaptor, 'api', 'context');
60
60
  }
61
61
  if (api.adaptor && typeof api.adaptor === 'string') {
62
- api.adaptor = str2function(api.adaptor, 'payload', 'response', 'api');
62
+ api.adaptor = str2AsyncFunction(api.adaptor, 'payload', 'response', 'api', 'context');
63
63
  }
64
64
  if (!data) {
65
65
  return api;
@@ -105,6 +105,23 @@ function buildApi(api, data, options) {
105
105
  }
106
106
  : undefined);
107
107
  };
108
+ /** 追加data到请求的Query中 */
109
+ var attachDataToQuery = function (apiObject, ctx, merge) {
110
+ var idx = apiObject.url.indexOf('?');
111
+ if (~idx) {
112
+ var params = (apiObject.query = tslib.__assign(tslib.__assign(tslib.__assign({}, helper.qsparse(apiObject.url.substring(idx + 1))), apiObject.query), ctx));
113
+ apiObject.url =
114
+ apiObject.url.substring(0, idx) + '?' + queryStringify(params);
115
+ }
116
+ else {
117
+ apiObject.query = tslib.__assign(tslib.__assign({}, apiObject.query), ctx);
118
+ var query = queryStringify(merge ? apiObject.query : ctx);
119
+ if (query) {
120
+ apiObject.url = "".concat(apiObject.url, "?").concat(query);
121
+ }
122
+ }
123
+ return apiObject;
124
+ };
108
125
  if (~idx) {
109
126
  var hashIdx = url.indexOf('#');
110
127
  var params = helper.qsparse(url.substring(idx + 1, ~hashIdx && hashIdx > idx ? hashIdx : undefined));
@@ -158,41 +175,19 @@ function buildApi(api, data, options) {
158
175
  else if (api.attachDataToQuery === false &&
159
176
  api.data &&
160
177
  ((!~raw.indexOf('$') && autoAppend) || api.forceAppendDataToQuery)) {
161
- var idx_1 = api.url.indexOf('?');
162
- if (~idx_1) {
163
- var params = (api.query = tslib.__assign(tslib.__assign(tslib.__assign({}, helper.qsparse(api.url.substring(idx_1 + 1))), api.query), data));
164
- api.url = api.url.substring(0, idx_1) + '?' + queryStringify(params);
165
- }
166
- else {
167
- api.query = tslib.__assign(tslib.__assign({}, api.query), data);
168
- var query = queryStringify(data);
169
- if (query) {
170
- api.url = "".concat(api.url, "?").concat(query);
171
- }
172
- }
178
+ api = attachDataToQuery(api, data, false);
173
179
  }
174
180
  if (api.data && api.attachDataToQuery !== false) {
175
- var idx_2 = api.url.indexOf('?');
176
- if (~idx_2) {
177
- var params = (api.query = tslib.__assign(tslib.__assign(tslib.__assign({}, helper.qsparse(api.url.substring(idx_2 + 1))), api.query), api.data));
178
- api.url = api.url.substring(0, idx_2) + '?' + queryStringify(params);
179
- }
180
- else {
181
- api.query = tslib.__assign(tslib.__assign({}, api.query), api.data);
182
- var query = queryStringify(api.query);
183
- if (query) {
184
- api.url = "".concat(api.url, "?").concat(query);
185
- }
186
- }
181
+ api = attachDataToQuery(api, api.data, true);
187
182
  delete api.data;
188
183
  }
189
184
  }
190
185
  // 非 get 类请求也可以携带参数到 url,只要 query 有值
191
186
  else if (api.method) {
192
- var idx_3 = api.url.indexOf('?');
193
- if (~idx_3) {
194
- var params = (api.query = tslib.__assign(tslib.__assign({}, helper.qsparse(api.url.substring(idx_3 + 1))), api.query));
195
- api.url = api.url.substring(0, idx_3) + '?' + queryStringify(params);
187
+ var idx_1 = api.url.indexOf('?');
188
+ if (~idx_1) {
189
+ var params = (api.query = tslib.__assign(tslib.__assign({}, helper.qsparse(api.url.substring(idx_1 + 1))), api.query));
190
+ api.url = api.url.substring(0, idx_1) + '?' + queryStringify(params);
196
191
  }
197
192
  else {
198
193
  var query = queryStringify(api.query);
@@ -217,8 +212,21 @@ function buildApi(api, data, options) {
217
212
  }
218
213
  else if (api.jsonql) {
219
214
  api.method = 'post';
220
- api.jsonql = dataMapping.dataMapping(api.jsonql, tslib.__assign(tslib.__assign({}, api.query), data), undefined, false, true);
221
- api.body = api.data = api.jsonql;
215
+ api.jsonql = dataMapping.dataMapping(api.jsonql,
216
+ /** 需要上层数据域的内容 */
217
+ object.extendObject(data, tslib.__assign(tslib.__assign({}, api.query), data), false), undefined, false, true);
218
+ /** 同时设置了JSONQL和data时走兼容场景 */
219
+ api.body = api.data =
220
+ api.data && api.jsonql
221
+ ? {
222
+ data: api.data,
223
+ jsonql: api.jsonql
224
+ }
225
+ : api.jsonql;
226
+ /** JSONQL所有method需要追加data中的变量到query中 */
227
+ if (api.forceAppendDataToQuery) {
228
+ api = attachDataToQuery(api, data, true);
229
+ }
222
230
  }
223
231
  return api;
224
232
  }
@@ -355,68 +363,84 @@ function wrapFetcher(fn, tracker) {
355
363
  }
356
364
  var wrappedFetcher = function (api, data, options) {
357
365
  var _a, _b, _c;
358
- api = buildApi(api, data, options);
359
- if (api.requestAdaptor) {
360
- debug.debug('api', 'before requestAdaptor', api);
361
- api = api.requestAdaptor(api) || api;
362
- debug.debug('api', 'after requestAdaptor', api);
363
- }
364
- if (api.data &&
365
- (api.data instanceof FormData ||
366
- helper.hasFile(api.data) ||
367
- api.dataType === 'form-data')) {
368
- api.data =
369
- api.data instanceof FormData
370
- ? api.data
371
- : helper.object2formData(api.data, api.qsOptions);
372
- }
373
- else if (api.data &&
374
- typeof api.data !== 'string' &&
375
- api.dataType === 'form') {
376
- api.data = helper.qsstringify(api.data, api.qsOptions);
377
- api.headers = api.headers || (api.headers = {});
378
- api.headers['Content-Type'] = 'application/x-www-form-urlencoded';
379
- }
380
- else if (api.data &&
381
- typeof api.data !== 'string' &&
382
- api.dataType === 'json') {
383
- api.data = JSON.stringify(api.data);
384
- api.headers = api.headers || (api.headers = {});
385
- api.headers['Content-Type'] = 'application/json';
386
- }
387
- if (!isValidApi(api.url)) {
388
- throw new Error("invalid api url:".concat(api.url));
389
- }
390
- debug.debug('api', 'request api', api);
391
- tracker === null || tracker === void 0 ? void 0 : tracker({ eventType: 'api', eventData: omit__default["default"](api, ['config', 'data', 'body']) }, api.data);
392
- if (((_a = api.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === 'jsonp') {
393
- return wrapAdaptor(jsonpFetcher(api), api);
394
- }
395
- if (((_b = api.method) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) === 'js') {
396
- return wrapAdaptor(jsFetcher(fn, api), api);
397
- }
398
- if (typeof api.cache === 'number' && api.cache > 0) {
399
- var apiCache = getApiCache(api);
400
- return wrapAdaptor(apiCache
401
- ? apiCache.cachedPromise
402
- : setApiCache(api, fn(api)), api);
403
- }
404
- // IE get 请求会被缓存,所以自动加个时间戳
405
- if (isIE && api && ((_c = api.method) === null || _c === void 0 ? void 0 : _c.toLocaleLowerCase()) === 'get') {
406
- var timeStamp = "_t=".concat(Date.now());
407
- if (api.url.indexOf('?') === -1) {
408
- api.url = api.url + "?".concat(timeStamp);
409
- }
410
- else {
411
- api.url = api.url + "&".concat(timeStamp);
412
- }
413
- }
414
- return wrapAdaptor(fn(api), api);
366
+ return tslib.__awaiter(this, void 0, void 0, function () {
367
+ var apiCache, timeStamp;
368
+ return tslib.__generator(this, function (_d) {
369
+ switch (_d.label) {
370
+ case 0:
371
+ api = buildApi(api, data, options);
372
+ if (!api.requestAdaptor) return [3 /*break*/, 2];
373
+ debug.debug('api', 'before requestAdaptor', api);
374
+ return [4 /*yield*/, api.requestAdaptor(api, data)];
375
+ case 1:
376
+ api = (_d.sent()) || api;
377
+ debug.debug('api', 'after requestAdaptor', api);
378
+ _d.label = 2;
379
+ case 2:
380
+ if (api.data &&
381
+ (api.data instanceof FormData ||
382
+ helper.hasFile(api.data) ||
383
+ api.dataType === 'form-data')) {
384
+ api.data =
385
+ api.data instanceof FormData
386
+ ? api.data
387
+ : helper.object2formData(api.data, api.qsOptions);
388
+ }
389
+ else if (api.data &&
390
+ typeof api.data !== 'string' &&
391
+ api.dataType === 'form') {
392
+ api.data = helper.qsstringify(api.data, api.qsOptions);
393
+ api.headers = api.headers || (api.headers = {});
394
+ api.headers['Content-Type'] = 'application/x-www-form-urlencoded';
395
+ }
396
+ else if (api.data &&
397
+ typeof api.data !== 'string' &&
398
+ api.dataType === 'json') {
399
+ api.data = JSON.stringify(api.data);
400
+ api.headers = api.headers || (api.headers = {});
401
+ api.headers['Content-Type'] = 'application/json';
402
+ }
403
+ // 如果发送适配器中设置了 mockResponse
404
+ // 则直接跳过请求发送
405
+ if (api.mockResponse) {
406
+ return [2 /*return*/, wrapAdaptor(Promise.resolve(api.mockResponse), api, data)];
407
+ }
408
+ if (!isValidApi(api.url)) {
409
+ throw new Error("invalid api url:".concat(api.url));
410
+ }
411
+ debug.debug('api', 'request api', api);
412
+ tracker === null || tracker === void 0 ? void 0 : tracker({ eventType: 'api', eventData: omit__default["default"](api, ['config', 'data', 'body']) }, api.data);
413
+ if (((_a = api.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === 'jsonp') {
414
+ return [2 /*return*/, wrapAdaptor(jsonpFetcher(api), api, data)];
415
+ }
416
+ if (((_b = api.method) === null || _b === void 0 ? void 0 : _b.toLocaleLowerCase()) === 'js') {
417
+ return [2 /*return*/, wrapAdaptor(jsFetcher(fn, api), api, data)];
418
+ }
419
+ if (typeof api.cache === 'number' && api.cache > 0) {
420
+ apiCache = getApiCache(api);
421
+ return [2 /*return*/, wrapAdaptor(apiCache
422
+ ? apiCache.cachedPromise
423
+ : setApiCache(api, fn(api)), api, data)];
424
+ }
425
+ // IE 下 get 请求会被缓存,所以自动加个时间戳
426
+ if (isIE && api && ((_c = api.method) === null || _c === void 0 ? void 0 : _c.toLocaleLowerCase()) === 'get') {
427
+ timeStamp = "_t=".concat(Date.now());
428
+ if (api.url.indexOf('?') === -1) {
429
+ api.url = api.url + "?".concat(timeStamp);
430
+ }
431
+ else {
432
+ api.url = api.url + "&".concat(timeStamp);
433
+ }
434
+ }
435
+ return [2 /*return*/, wrapAdaptor(fn(api), api, data)];
436
+ }
437
+ });
438
+ });
415
439
  };
416
440
  wrappedFetcher._wrappedFetcher = true;
417
441
  return wrappedFetcher;
418
442
  }
419
- function wrapAdaptor(promise, api) {
443
+ function wrapAdaptor(promise, api, context) {
420
444
  var _this = this;
421
445
  var adaptor = api.adaptor;
422
446
  return adaptor
@@ -427,7 +451,7 @@ function wrapAdaptor(promise, api) {
427
451
  switch (_a.label) {
428
452
  case 0:
429
453
  debug.debug('api', 'before adaptor data', response.data);
430
- result = adaptor(response.data, response, api);
454
+ result = adaptor(response.data, response, api, context);
431
455
  if (!(result === null || result === void 0 ? void 0 : result.then)) return [3 /*break*/, 2];
432
456
  return [4 /*yield*/, result];
433
457
  case 1:
@@ -541,41 +565,57 @@ function isApiOutdated(prevApi, nextApi, prevData, nextData) {
541
565
  return true;
542
566
  }
543
567
  nextApi = normalizeApi(nextApi);
568
+ prevApi = (prevApi ? normalizeApi(prevApi) : prevApi);
544
569
  if (nextApi.autoRefresh === false) {
545
570
  return false;
546
571
  }
572
+ // api 本身有变化
573
+ if ((prevApi && prevApi.url !== nextApi.url) || !prevApi) {
574
+ return !!(isValidApi(nextApi.url) &&
575
+ (!nextApi.sendOn || tpl.evalExpression(nextApi.sendOn, nextData)));
576
+ }
547
577
  var trackExpression = (_a = nextApi.trackExpression) !== null && _a !== void 0 ? _a : nextApi.url;
548
578
  if (typeof trackExpression !== 'string' || !~trackExpression.indexOf('$')) {
549
579
  return false;
550
580
  }
551
581
  var isModified = false;
552
- if (prevApi) {
553
- prevApi = normalizeApi(prevApi);
554
- if (nextApi.trackExpression || prevApi.trackExpression) {
555
- isModified =
556
- tokenize.tokenize(prevApi.trackExpression || '', prevData) !==
557
- tokenize.tokenize(nextApi.trackExpression || '', nextData);
558
- }
559
- else {
560
- prevApi = buildApi(prevApi, prevData, {
561
- ignoreData: true
562
- });
563
- nextApi = buildApi(nextApi, nextData, {
564
- ignoreData: true
565
- });
566
- isModified = prevApi.url !== nextApi.url;
567
- }
582
+ if (nextApi.trackExpression || prevApi.trackExpression) {
583
+ isModified =
584
+ tokenize.tokenize(prevApi.trackExpression || '', prevData) !==
585
+ tokenize.tokenize(nextApi.trackExpression || '', nextData);
568
586
  }
569
587
  else {
570
- isModified = true;
588
+ prevApi = buildApi(prevApi, prevData, {
589
+ ignoreData: true
590
+ });
591
+ nextApi = buildApi(nextApi, nextData, {
592
+ ignoreData: true
593
+ });
594
+ isModified = prevApi.url !== nextApi.url;
571
595
  }
572
596
  return !!(isModified &&
573
597
  isValidApi(nextApi.url) &&
574
598
  (!nextApi.sendOn || tpl.evalExpression(nextApi.sendOn, nextData)));
575
599
  }
576
600
  function isValidApi(api) {
577
- return (api &&
578
- /^(?:(https?|wss?|taf):\/\/[^\/]+)?(\/?[^\s\/\?]*){1,}(\?.*)?$/.test(api));
601
+ if (!api || typeof api !== 'string') {
602
+ return false;
603
+ }
604
+ var idx = api.indexOf('://');
605
+ // 不允许直接相对路径写 api
606
+ // 不允许 :// 结尾
607
+ if ((!~idx && api[0] !== '/') || (~idx && idx + 3 === api.length)) {
608
+ return false;
609
+ }
610
+ try {
611
+ // 不补一个协议,URL 判断为 false
612
+ api = (~idx ? '' : 'schema://domain') + api;
613
+ new URL(api);
614
+ }
615
+ catch (error) {
616
+ return false;
617
+ }
618
+ return true;
579
619
  }
580
620
  function isEffectiveApi(api, data, initFetch, initFetchOn) {
581
621
  if (!api) {
@@ -0,0 +1 @@
1
+ export declare function arraySlice(array: any[], slice: string): any[];
@@ -0,0 +1,80 @@
1
+ /**
2
+ * amis-core v3.3.0
3
+ * Copyright 2018-2023 fex
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+
10
+ var tslib = require('tslib');
11
+ var mobx = require('mobx');
12
+
13
+ function arraySlice(array, slice) {
14
+ var e_1, _a;
15
+ if (typeof slice !== 'string') {
16
+ return array;
17
+ }
18
+ if (mobx.isObservableArray(array)) {
19
+ array = mobx.toJS(array);
20
+ }
21
+ slice = slice.trim();
22
+ if (!slice || !Array.isArray(array)) {
23
+ return array;
24
+ }
25
+ var parts = slice.split(',');
26
+ var ret = [];
27
+ var arrayLength = array.length;
28
+ if (!arrayLength) {
29
+ return array;
30
+ }
31
+ try {
32
+ for (var parts_1 = tslib.__values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
33
+ var part = parts_1_1.value;
34
+ // 普通的场景
35
+ if (part.indexOf(':') === -1) {
36
+ var index = parseInt(part, 10);
37
+ if (!isNaN(index) && index < arrayLength) {
38
+ ret.push(array[index]);
39
+ }
40
+ }
41
+ else {
42
+ var _b = tslib.__read(part.split(':'), 2), start = _b[0], end = _b[1];
43
+ var startIndex = parseInt(start || '0', 10);
44
+ if (isNaN(startIndex) || startIndex < 0) {
45
+ startIndex = 0;
46
+ }
47
+ // 大于就没意义了
48
+ if (startIndex >= arrayLength) {
49
+ continue;
50
+ }
51
+ var endIndex = parseInt(end, 10);
52
+ if (isNaN(endIndex)) {
53
+ endIndex = arrayLength;
54
+ }
55
+ // 负数就从后面开始取
56
+ if (endIndex < 0) {
57
+ endIndex = arrayLength + endIndex;
58
+ }
59
+ // 小于没有意义
60
+ if (endIndex < startIndex) {
61
+ continue;
62
+ }
63
+ if (endIndex > arrayLength) {
64
+ endIndex = arrayLength;
65
+ }
66
+ ret.push.apply(ret, tslib.__spreadArray([], tslib.__read(array.slice(startIndex, endIndex)), false));
67
+ }
68
+ }
69
+ }
70
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
71
+ finally {
72
+ try {
73
+ if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
74
+ }
75
+ finally { if (e_1) throw e_1.error; }
76
+ }
77
+ return ret;
78
+ }
79
+
80
+ exports.arraySlice = arraySlice;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.1.1
2
+ * amis-core v3.3.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.1.1
2
+ * amis-core v3.3.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.1.1
2
+ * amis-core v3.3.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -8,14 +8,16 @@
8
8
  Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
10
  var tslib = require('tslib');
11
- var React = require('react');
11
+ require('react');
12
12
  var chunk = require('lodash/chunk');
13
13
 
14
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
15
 
16
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
17
16
  var chunk__default = /*#__PURE__*/_interopDefaultLegacy(chunk);
18
17
 
18
+ var __react_jsx__ = require('react');
19
+ var _J$X_ = (__react_jsx__["default"] || __react_jsx__).createElement;
20
+ (__react_jsx__["default"] || __react_jsx__).Fragment;
19
21
  function columnsSplit(body, cx, columnsCount) {
20
22
  if (Array.isArray(columnsCount) && columnsCount.length) {
21
23
  var bodyIndex_1 = 0;
@@ -24,10 +26,10 @@ function columnsSplit(body, cx, columnsCount) {
24
26
  var cellClassName_1 = "Grid-col--sm".concat(maxSize);
25
27
  columnsCount.forEach(function (columnSize, groupIndex) {
26
28
  if (columnSize) {
27
- bodyList_1.push(React__default["default"].createElement("div", { className: cx('Grid'), key: groupIndex }, Array.from({ length: columnSize }).map(function (_, index) {
29
+ bodyList_1.push(_J$X_("div", { className: cx('Grid'), key: groupIndex }, Array.from({ length: columnSize }).map(function (_, index) {
28
30
  if (bodyIndex_1 + index < body.length) {
29
31
  // 避免溢出
30
- return (React__default["default"].createElement("div", { key: index, className: cx(cellClassName_1) }, body[bodyIndex_1 + index]));
32
+ return (_J$X_("div", { key: index, className: cx(cellClassName_1) }, body[bodyIndex_1 + index]));
31
33
  }
32
34
  else {
33
35
  return null;
@@ -41,7 +43,7 @@ function columnsSplit(body, cx, columnsCount) {
41
43
  else if (typeof columnsCount === 'number' && columnsCount > 1) {
42
44
  var weight = 12 / columnsCount;
43
45
  var cellClassName_2 = "Grid-col--sm".concat(weight === Math.round(weight) ? weight : '');
44
- body = chunk__default["default"](body, columnsCount).map(function (group, groupIndex) { return (React__default["default"].createElement("div", { className: cx('Grid'), key: groupIndex }, Array.from({ length: columnsCount }).map(function (_, index) { return (React__default["default"].createElement("div", { key: index, className: cx(cellClassName_2) }, group[index])); }))); });
46
+ body = chunk__default["default"](body, columnsCount).map(function (group, groupIndex) { return (_J$X_("div", { className: cx('Grid'), key: groupIndex }, Array.from({ length: columnsCount }).map(function (_, index) { return (_J$X_("div", { key: index, className: cx(cellClassName_2) }, group[index])); }))); });
45
47
  }
46
48
  return body;
47
49
  }