amis-core 3.6.4 → 6.1.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 (316) hide show
  1. package/esm/Root.js +1 -1
  2. package/esm/RootRenderer.js +3 -2
  3. package/esm/SchemaRenderer.js +4 -1
  4. package/esm/Scoped.d.ts +6 -0
  5. package/esm/Scoped.js +45 -7
  6. package/esm/StatusScoped.js +1 -1
  7. package/esm/WithRootStore.js +1 -1
  8. package/esm/WithStore.js +3 -5
  9. package/esm/actions/Action.js +31 -27
  10. package/esm/actions/AjaxAction.js +1 -1
  11. package/esm/actions/BreakAction.js +1 -1
  12. package/esm/actions/BroadcastAction.js +1 -1
  13. package/esm/actions/CmptAction.js +65 -26
  14. package/esm/actions/ContinueAction.js +1 -1
  15. package/esm/actions/CopyAction.js +1 -1
  16. package/esm/actions/CustomAction.js +4 -3
  17. package/esm/actions/DialogAction.js +1 -1
  18. package/esm/actions/DrawerAction.js +1 -1
  19. package/esm/actions/EmailAction.js +1 -1
  20. package/esm/actions/LinkAction.js +9 -4
  21. package/esm/actions/LoopAction.js +1 -1
  22. package/esm/actions/PageAction.js +1 -1
  23. package/esm/actions/ParallelAction.js +1 -1
  24. package/esm/actions/StatusAction.js +1 -1
  25. package/esm/actions/SwitchAction.js +1 -1
  26. package/esm/actions/ToastAction.js +1 -1
  27. package/esm/components/CustomStyle.d.ts +1 -2
  28. package/esm/components/CustomStyle.js +19 -6
  29. package/esm/components/ErrorBoundary.js +1 -1
  30. package/esm/components/LazyComponent.js +1 -1
  31. package/esm/components/Overlay.js +12 -9
  32. package/esm/components/PopOver.js +8 -5
  33. package/esm/env.d.ts +4 -0
  34. package/esm/env.js +1 -1
  35. package/esm/envOverwrite.js +1 -1
  36. package/esm/factory.js +14 -1
  37. package/esm/index.d.ts +2 -2
  38. package/esm/index.js +14 -7
  39. package/esm/locale.js +1 -1
  40. package/esm/polyfills.js +1 -1
  41. package/esm/renderers/Form.d.ts +4 -3
  42. package/esm/renderers/Form.js +216 -150
  43. package/esm/renderers/Item.d.ts +1 -0
  44. package/esm/renderers/Item.js +17 -17
  45. package/esm/renderers/Options.d.ts +5 -0
  46. package/esm/renderers/Options.js +188 -57
  47. package/esm/renderers/Placeholder.js +1 -1
  48. package/esm/renderers/builtin.js +1 -1
  49. package/esm/renderers/register.js +1 -1
  50. package/esm/renderers/wrapControl.js +39 -30
  51. package/esm/store/app.d.ts +2 -2
  52. package/esm/store/app.js +4 -3
  53. package/esm/store/combo.d.ts +79 -55
  54. package/esm/store/combo.js +1 -1
  55. package/esm/store/crud.d.ts +3 -2
  56. package/esm/store/crud.js +18 -4
  57. package/esm/store/form.d.ts +33 -23
  58. package/esm/store/form.js +5 -5
  59. package/esm/store/formItem.d.ts +2 -1
  60. package/esm/store/formItem.js +3 -2
  61. package/esm/store/iRenderer.d.ts +1 -1
  62. package/esm/store/iRenderer.js +10 -3
  63. package/esm/store/index.js +1 -1
  64. package/esm/store/list.d.ts +1 -1
  65. package/esm/store/list.js +18 -13
  66. package/esm/store/manager.js +1 -1
  67. package/esm/store/modal.d.ts +2 -2
  68. package/esm/store/modal.js +1 -1
  69. package/esm/store/node.js +1 -1
  70. package/esm/store/pagination.d.ts +2 -1
  71. package/esm/store/pagination.js +3 -2
  72. package/esm/store/root.d.ts +2 -2
  73. package/esm/store/root.js +4 -3
  74. package/esm/store/service.d.ts +2 -2
  75. package/esm/store/service.js +11 -7
  76. package/esm/store/status.js +1 -1
  77. package/esm/store/table.d.ts +69 -47
  78. package/esm/store/table.js +54 -25
  79. package/esm/store/table2.d.ts +14 -3
  80. package/esm/store/table2.js +22 -9
  81. package/esm/theme.js +1 -1
  82. package/esm/types.d.ts +7 -0
  83. package/esm/utils/Animation.js +1 -1
  84. package/esm/utils/ColorScale.js +1 -1
  85. package/esm/utils/DataSchema.js +1 -1
  86. package/esm/utils/DataScope.js +1 -1
  87. package/esm/utils/RootClose.js +1 -1
  88. package/esm/utils/SimpleMap.js +1 -1
  89. package/esm/utils/api.js +1 -1
  90. package/esm/utils/arraySlice.js +1 -1
  91. package/esm/utils/attachmentAdpator.js +1 -1
  92. package/esm/utils/autobind.js +1 -1
  93. package/esm/utils/browser.d.ts +1 -0
  94. package/esm/utils/browser.js +11 -0
  95. package/esm/utils/columnsSplit.js +1 -1
  96. package/esm/utils/concatData.d.ts +8 -0
  97. package/esm/utils/concatData.js +39 -0
  98. package/esm/utils/dataMapping.js +1 -1
  99. package/esm/utils/date.js +1 -1
  100. package/esm/utils/debug.js +1 -1
  101. package/esm/utils/decodeEntity.js +1 -1
  102. package/esm/utils/dom.js +1 -1
  103. package/esm/utils/errors.js +1 -1
  104. package/esm/utils/escapeHtml.js +1 -1
  105. package/esm/utils/filter-schema.js +1 -1
  106. package/esm/utils/filter.js +1 -1
  107. package/esm/utils/formatDuration.js +1 -1
  108. package/esm/utils/formula.js +1 -1
  109. package/esm/utils/getVariable.js +1 -1
  110. package/esm/utils/grammar.js +1 -1
  111. package/esm/utils/handleAction.js +1 -1
  112. package/esm/utils/helper.d.ts +14 -2
  113. package/esm/utils/helper.js +49 -14
  114. package/esm/utils/highlight.js +3 -2
  115. package/esm/utils/icon.js +1 -1
  116. package/esm/utils/image.js +1 -1
  117. package/esm/utils/index.d.ts +3 -0
  118. package/esm/utils/isPureVariable.js +1 -1
  119. package/esm/utils/json-schema-2-amis-schema.js +1 -1
  120. package/esm/utils/keyToPath.js +1 -1
  121. package/esm/utils/labelToString.d.ts +1 -0
  122. package/esm/utils/labelToString.js +38 -0
  123. package/esm/utils/makeSorter.js +1 -1
  124. package/esm/utils/math.js +1 -1
  125. package/esm/utils/memoryParse.js +1 -1
  126. package/esm/utils/normalizeLink.js +1 -1
  127. package/esm/utils/normalizeOptions.js +1 -1
  128. package/esm/utils/object.js +1 -1
  129. package/esm/utils/offset.js +1 -1
  130. package/esm/utils/offsetParent.js +1 -1
  131. package/esm/utils/optionValueCompare.js +1 -1
  132. package/esm/utils/position.js +1 -1
  133. package/esm/utils/prettyBytes.js +1 -1
  134. package/esm/utils/renderer-event.js +19 -3
  135. package/esm/utils/replaceText.js +9 -11
  136. package/esm/utils/resize-sensor.js +1 -1
  137. package/esm/utils/resolveCondition.js +1 -1
  138. package/esm/utils/resolveVariable.js +1 -1
  139. package/esm/utils/resolveVariableAndFilter.js +1 -1
  140. package/esm/utils/resolveVariableAndFilterForAsync.js +1 -1
  141. package/esm/utils/scrollPosition.js +1 -1
  142. package/esm/utils/string2regExp.d.ts +1 -1
  143. package/esm/utils/string2regExp.js +4 -3
  144. package/esm/utils/stripNumber.js +1 -1
  145. package/esm/utils/style-helper.d.ts +24 -5
  146. package/esm/utils/style-helper.js +49 -21
  147. package/esm/utils/style.js +1 -1
  148. package/esm/utils/toNumber.js +1 -1
  149. package/esm/utils/tokenize.d.ts +1 -0
  150. package/esm/utils/tokenize.js +10 -3
  151. package/esm/utils/tpl-builtin.js +1 -1
  152. package/esm/utils/tpl-lodash.js +1 -1
  153. package/esm/utils/tpl.js +6 -8
  154. package/esm/utils/uncontrollable.js +1 -1
  155. package/esm/utils/validateId.d.ts +16 -0
  156. package/esm/utils/validateId.js +154 -0
  157. package/esm/utils/validations.js +16 -8
  158. package/lib/Root.js +1 -1
  159. package/lib/RootRenderer.js +3 -2
  160. package/lib/SchemaRenderer.js +4 -1
  161. package/lib/Scoped.d.ts +6 -0
  162. package/lib/Scoped.js +45 -6
  163. package/lib/StatusScoped.js +1 -1
  164. package/lib/WithRootStore.js +1 -1
  165. package/lib/WithStore.js +3 -5
  166. package/lib/actions/Action.js +31 -27
  167. package/lib/actions/AjaxAction.js +1 -1
  168. package/lib/actions/BreakAction.js +1 -1
  169. package/lib/actions/BroadcastAction.js +1 -1
  170. package/lib/actions/CmptAction.js +65 -26
  171. package/lib/actions/ContinueAction.js +1 -1
  172. package/lib/actions/CopyAction.js +1 -1
  173. package/lib/actions/CustomAction.js +4 -3
  174. package/lib/actions/DialogAction.js +1 -1
  175. package/lib/actions/DrawerAction.js +1 -1
  176. package/lib/actions/EmailAction.js +1 -1
  177. package/lib/actions/LinkAction.js +9 -4
  178. package/lib/actions/LoopAction.js +1 -1
  179. package/lib/actions/PageAction.js +1 -1
  180. package/lib/actions/ParallelAction.js +1 -1
  181. package/lib/actions/StatusAction.js +1 -1
  182. package/lib/actions/SwitchAction.js +1 -1
  183. package/lib/actions/ToastAction.js +1 -1
  184. package/lib/components/CustomStyle.d.ts +1 -2
  185. package/lib/components/CustomStyle.js +19 -6
  186. package/lib/components/ErrorBoundary.js +1 -1
  187. package/lib/components/LazyComponent.js +1 -1
  188. package/lib/components/Overlay.js +11 -8
  189. package/lib/components/PopOver.js +8 -5
  190. package/lib/env.d.ts +4 -0
  191. package/lib/env.js +1 -1
  192. package/lib/envOverwrite.js +1 -1
  193. package/lib/factory.js +14 -1
  194. package/lib/index.d.ts +2 -2
  195. package/lib/index.js +19 -4
  196. package/lib/locale.js +1 -1
  197. package/lib/polyfills.js +1 -1
  198. package/lib/renderers/Form.d.ts +4 -3
  199. package/lib/renderers/Form.js +216 -150
  200. package/lib/renderers/Item.d.ts +1 -0
  201. package/lib/renderers/Item.js +17 -17
  202. package/lib/renderers/Options.d.ts +5 -0
  203. package/lib/renderers/Options.js +188 -57
  204. package/lib/renderers/Placeholder.js +1 -1
  205. package/lib/renderers/builtin.js +1 -1
  206. package/lib/renderers/register.js +1 -1
  207. package/lib/renderers/wrapControl.js +38 -29
  208. package/lib/store/app.d.ts +2 -2
  209. package/lib/store/app.js +4 -3
  210. package/lib/store/combo.d.ts +55 -31
  211. package/lib/store/combo.js +1 -1
  212. package/lib/store/crud.d.ts +3 -2
  213. package/lib/store/crud.js +18 -4
  214. package/lib/store/form.d.ts +23 -13
  215. package/lib/store/form.js +5 -5
  216. package/lib/store/formItem.d.ts +2 -1
  217. package/lib/store/formItem.js +3 -2
  218. package/lib/store/iRenderer.d.ts +1 -1
  219. package/lib/store/iRenderer.js +10 -3
  220. package/lib/store/index.js +1 -1
  221. package/lib/store/list.d.ts +1 -1
  222. package/lib/store/list.js +18 -14
  223. package/lib/store/manager.js +1 -1
  224. package/lib/store/modal.d.ts +2 -2
  225. package/lib/store/modal.js +1 -1
  226. package/lib/store/node.js +1 -1
  227. package/lib/store/pagination.d.ts +2 -1
  228. package/lib/store/pagination.js +3 -2
  229. package/lib/store/root.d.ts +2 -2
  230. package/lib/store/root.js +4 -3
  231. package/lib/store/service.d.ts +2 -2
  232. package/lib/store/service.js +11 -7
  233. package/lib/store/status.js +1 -1
  234. package/lib/store/table.d.ts +49 -27
  235. package/lib/store/table.js +54 -26
  236. package/lib/store/table2.d.ts +14 -3
  237. package/lib/store/table2.js +22 -9
  238. package/lib/theme.js +1 -1
  239. package/lib/types.d.ts +7 -0
  240. package/lib/utils/Animation.js +1 -1
  241. package/lib/utils/ColorScale.js +1 -1
  242. package/lib/utils/DataSchema.js +1 -1
  243. package/lib/utils/DataScope.js +1 -1
  244. package/lib/utils/RootClose.js +1 -1
  245. package/lib/utils/SimpleMap.js +1 -1
  246. package/lib/utils/api.js +1 -1
  247. package/lib/utils/arraySlice.js +1 -1
  248. package/lib/utils/attachmentAdpator.js +1 -1
  249. package/lib/utils/autobind.js +1 -1
  250. package/lib/utils/browser.d.ts +1 -0
  251. package/lib/utils/browser.js +15 -0
  252. package/lib/utils/columnsSplit.js +1 -1
  253. package/lib/utils/concatData.d.ts +8 -0
  254. package/lib/utils/concatData.js +43 -0
  255. package/lib/utils/dataMapping.js +1 -1
  256. package/lib/utils/date.js +1 -1
  257. package/lib/utils/debug.js +1 -1
  258. package/lib/utils/decodeEntity.js +1 -1
  259. package/lib/utils/dom.js +1 -1
  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.js +1 -1
  266. package/lib/utils/getVariable.js +1 -1
  267. package/lib/utils/grammar.js +1 -1
  268. package/lib/utils/handleAction.js +1 -1
  269. package/lib/utils/helper.d.ts +14 -2
  270. package/lib/utils/helper.js +50 -12
  271. package/lib/utils/highlight.js +3 -2
  272. package/lib/utils/icon.js +1 -1
  273. package/lib/utils/image.js +1 -1
  274. package/lib/utils/index.d.ts +3 -0
  275. package/lib/utils/isPureVariable.js +1 -1
  276. package/lib/utils/json-schema-2-amis-schema.js +1 -1
  277. package/lib/utils/keyToPath.js +1 -1
  278. package/lib/utils/labelToString.d.ts +1 -0
  279. package/lib/utils/labelToString.js +46 -0
  280. package/lib/utils/makeSorter.js +1 -1
  281. package/lib/utils/math.js +1 -1
  282. package/lib/utils/memoryParse.js +1 -1
  283. package/lib/utils/normalizeLink.js +1 -1
  284. package/lib/utils/normalizeOptions.js +1 -1
  285. package/lib/utils/object.js +1 -1
  286. package/lib/utils/offset.js +1 -1
  287. package/lib/utils/offsetParent.js +1 -1
  288. package/lib/utils/optionValueCompare.js +1 -1
  289. package/lib/utils/position.js +1 -1
  290. package/lib/utils/prettyBytes.js +1 -1
  291. package/lib/utils/renderer-event.js +19 -3
  292. package/lib/utils/replaceText.js +8 -14
  293. package/lib/utils/resize-sensor.js +1 -1
  294. package/lib/utils/resolveCondition.js +1 -1
  295. package/lib/utils/resolveVariable.js +1 -1
  296. package/lib/utils/resolveVariableAndFilter.js +1 -1
  297. package/lib/utils/resolveVariableAndFilterForAsync.js +1 -1
  298. package/lib/utils/scrollPosition.js +1 -1
  299. package/lib/utils/string2regExp.d.ts +1 -1
  300. package/lib/utils/string2regExp.js +4 -3
  301. package/lib/utils/stripNumber.js +1 -1
  302. package/lib/utils/style-helper.d.ts +24 -5
  303. package/lib/utils/style-helper.js +49 -21
  304. package/lib/utils/style.js +1 -1
  305. package/lib/utils/toNumber.js +1 -1
  306. package/lib/utils/tokenize.d.ts +1 -0
  307. package/lib/utils/tokenize.js +10 -2
  308. package/lib/utils/tpl-builtin.js +1 -1
  309. package/lib/utils/tpl-lodash.js +1 -1
  310. package/lib/utils/tpl.js +5 -7
  311. package/lib/utils/uncontrollable.js +1 -1
  312. package/lib/utils/validateId.d.ts +16 -0
  313. package/lib/utils/validateId.js +160 -0
  314. package/lib/utils/validations.js +16 -8
  315. package/package.json +4 -3
  316. package/LICENSE +0 -201
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.6.4
2
+ * amis-core v6.1.0
3
3
  * Copyright 2018-2024 fex
4
4
  */
5
5
 
@@ -26,6 +26,7 @@ require('../utils/filter.js');
26
26
  var api = require('../utils/api.js');
27
27
  var LazyComponent = require('../components/LazyComponent.js');
28
28
  var mobxStateTree = require('mobx-state-tree');
29
+ require('../utils/browser.js');
29
30
  require('../utils/ColorScale.js');
30
31
  require('../utils/columnsSplit.js');
31
32
  require('../utils/DataSchema.js');
@@ -42,13 +43,13 @@ require('../utils/image.js');
42
43
  require('lodash/isPlainObject');
43
44
  require('lodash/isEqual');
44
45
  require('../actions/Action.js');
45
- require('lodash/cloneDeep');
46
46
  require('../utils/resize-sensor.js');
47
47
  require('react-overlays/useRootClose');
48
48
  require('react-dom');
49
49
  require('../utils/SimpleMap.js');
50
50
  require('lodash/mapValues');
51
51
  require('lodash/camelCase');
52
+ require('lodash/cloneDeep');
52
53
  require('lodash/map');
53
54
  require('lodash/isEmpty');
54
55
  require('lodash/kebabCase');
@@ -80,6 +81,8 @@ var Form = /** @class */ (function (_super) {
80
81
  trailing: true,
81
82
  leading: false
82
83
  });
84
+ // 如果开启了 lazyChange,需要一个 flush 方法把队列中值应用上。
85
+ _this.flushing = false;
83
86
  _this.onInit = _this.onInit.bind(_this);
84
87
  _this.handleAction = _this.handleAction.bind(_this);
85
88
  _this.handleQuery = _this.handleQuery.bind(_this);
@@ -392,22 +395,27 @@ var Form = /** @class */ (function (_super) {
392
395
  Form.prototype.isValidated = function () {
393
396
  return this.props.store.validated;
394
397
  };
395
- Form.prototype.validate = function (forceValidate, throwErrors, toastErrors) {
398
+ Form.prototype.validate = function (forceValidate, throwErrors, toastErrors, skipFlush) {
396
399
  if (throwErrors === void 0) { throwErrors = false; }
397
400
  if (toastErrors === void 0) { toastErrors = true; }
401
+ if (skipFlush === void 0) { skipFlush = false; }
398
402
  return tslib.__awaiter(this, void 0, void 0, function () {
399
403
  var _a, store, dispatchEvent, data, messages, __, result;
400
404
  return tslib.__generator(this, function (_b) {
401
405
  switch (_b.label) {
402
406
  case 0:
403
407
  _a = this.props, store = _a.store, dispatchEvent = _a.dispatchEvent, data = _a.data, messages = _a.messages, __ = _a.translate;
404
- this.flush();
405
- return [4 /*yield*/, store.validate(this.hooks['validate'] || [], forceValidate, throwErrors, toastErrors === false
406
- ? ''
407
- : typeof (messages === null || messages === void 0 ? void 0 : messages.validateFailed) === 'string'
408
- ? __(tpl.filter(messages.validateFailed, store.data))
409
- : undefined)];
408
+ if (!!skipFlush) return [3 /*break*/, 2];
409
+ return [4 /*yield*/, this.flush()];
410
410
  case 1:
411
+ _b.sent();
412
+ _b.label = 2;
413
+ case 2: return [4 /*yield*/, store.validate(this.hooks['validate'] || [], forceValidate, throwErrors, toastErrors === false
414
+ ? ''
415
+ : typeof (messages === null || messages === void 0 ? void 0 : messages.validateFailed) === 'string'
416
+ ? __(tpl.filter(messages.validateFailed, store.data))
417
+ : undefined)];
418
+ case 3:
411
419
  result = _b.sent();
412
420
  dispatchEvent(result ? 'validateSucc' : 'validateError', data);
413
421
  return [2 /*return*/, result];
@@ -434,20 +442,55 @@ var Form = /** @class */ (function (_super) {
434
442
  this.flush();
435
443
  store.setValues(value, undefined, replace);
436
444
  };
437
- Form.prototype.submit = function (fn, throwErrors) {
445
+ Form.prototype.submit = function (fn, throwErrors, skipFlush) {
438
446
  if (throwErrors === void 0) { throwErrors = false; }
439
- var _a = this.props, store = _a.store, messages = _a.messages, __ = _a.translate, dispatchEvent = _a.dispatchEvent, data = _a.data;
440
- this.flush();
441
- var validateErrCb = function () { return dispatchEvent('validateError', data); };
442
- return store.submit(fn, this.hooks['validate'] || [], typeof (messages === null || messages === void 0 ? void 0 : messages.validateFailed) === 'string'
443
- ? __(tpl.filter(messages.validateFailed, store.data))
444
- : undefined, validateErrCb, throwErrors);
447
+ if (skipFlush === void 0) { skipFlush = false; }
448
+ return tslib.__awaiter(this, void 0, void 0, function () {
449
+ var _a, store, messages, __, dispatchEvent, data, validateErrCb;
450
+ return tslib.__generator(this, function (_b) {
451
+ switch (_b.label) {
452
+ case 0:
453
+ _a = this.props, store = _a.store, messages = _a.messages, __ = _a.translate, dispatchEvent = _a.dispatchEvent, data = _a.data;
454
+ if (!!skipFlush) return [3 /*break*/, 2];
455
+ return [4 /*yield*/, this.flush()];
456
+ case 1:
457
+ _b.sent();
458
+ _b.label = 2;
459
+ case 2:
460
+ validateErrCb = function () { return dispatchEvent('validateError', data); };
461
+ return [2 /*return*/, store.submit(fn, this.hooks['validate'] || [], typeof (messages === null || messages === void 0 ? void 0 : messages.validateFailed) === 'string'
462
+ ? __(tpl.filter(messages.validateFailed, store.data))
463
+ : undefined, validateErrCb, throwErrors)];
464
+ }
465
+ });
466
+ });
445
467
  };
446
- // 如果开启了 lazyChange,需要一个 flush 方法把队列中值应用上。
447
468
  Form.prototype.flush = function () {
448
- var hooks = this.hooks['flush'] || [];
449
- hooks.forEach(function (fn) { return fn(); });
450
- this.lazyEmitChange.flush();
469
+ return tslib.__awaiter(this, void 0, void 0, function () {
470
+ var hooks;
471
+ return tslib.__generator(this, function (_a) {
472
+ switch (_a.label) {
473
+ case 0:
474
+ _a.trys.push([0, , 3, 4]);
475
+ if (this.flushing) {
476
+ return [2 /*return*/];
477
+ }
478
+ this.flushing = true;
479
+ hooks = this.hooks['flush'] || [];
480
+ return [4 /*yield*/, Promise.all(hooks.map(function (fn) { return fn(); }))];
481
+ case 1:
482
+ _a.sent();
483
+ return [4 /*yield*/, this.lazyEmitChange.flush()];
484
+ case 2:
485
+ _a.sent();
486
+ return [3 /*break*/, 4];
487
+ case 3:
488
+ this.flushing = false;
489
+ return [7 /*endfinally*/];
490
+ case 4: return [2 /*return*/];
491
+ }
492
+ });
493
+ });
451
494
  };
452
495
  Form.prototype.reset = function () {
453
496
  var _a = this.props, store = _a.store, onReset = _a.onReset;
@@ -519,11 +562,17 @@ var Form = /** @class */ (function (_super) {
519
562
  onChange && onChange.apply(null, changeProps);
520
563
  }
521
564
  store.clearRestError();
522
- (submit || (submitOnChange && store.inited)) &&
523
- this.handleAction(undefined, {
524
- type: 'submit'
525
- }, store.data);
526
- return [2 /*return*/];
565
+ if (!(submit || (submitOnChange && store.inited))) return [3 /*break*/, 3];
566
+ return [4 /*yield*/, this.handleAction(undefined, {
567
+ type: 'submit',
568
+ // 如果这里不跳过,会相互依赖死循环,flush 会 让 emiteChange 立即执行
569
+ // handleAction 里面又会调用 flush
570
+ skipFormFlush: true
571
+ }, store.data)];
572
+ case 2:
573
+ _b.sent();
574
+ _b.label = 3;
575
+ case 3: return [2 /*return*/];
527
576
  }
528
577
  });
529
578
  });
@@ -574,8 +623,12 @@ var Form = /** @class */ (function (_super) {
574
623
  switch (_f.label) {
575
624
  case 0:
576
625
  _c = this.props, store = _c.store, onSubmit = _c.onSubmit, api$1 = _c.api, asyncApi = _c.asyncApi, finishedField = _c.finishedField, checkInterval = _c.checkInterval, _d = _c.messages, saveSuccess = _d.saveSuccess, saveFailed = _d.saveFailed, resetAfterSubmit = _c.resetAfterSubmit, clearAfterSubmit = _c.clearAfterSubmit, onAction = _c.onAction, onSaved = _c.onSaved, onReset = _c.onReset, onFinished = _c.onFinished, onFailed = _c.onFailed, redirect = _c.redirect, reload = _c.reload, target = _c.target, env = _c.env, onChange = _c.onChange, clearPersistDataAfterSubmit = _c.clearPersistDataAfterSubmit, trimValues = _c.trimValues, dispatchEvent = _c.dispatchEvent, __ = _c.translate;
577
- // 做动作之前,先把数据同步一下。
578
- this.flush();
626
+ if (!!action.skipFormFlush) return [3 /*break*/, 2];
627
+ return [4 /*yield*/, this.flush()];
628
+ case 1:
629
+ _f.sent();
630
+ _f.label = 2;
631
+ case 2:
579
632
  if (trimValues) {
580
633
  store.trimValues();
581
634
  }
@@ -583,7 +636,7 @@ var Form = /** @class */ (function (_super) {
583
636
  if (data === this.props.data) {
584
637
  data = store.data;
585
638
  }
586
- if (!(Array.isArray(action.required) && action.required.length)) return [3 /*break*/, 4];
639
+ if (!(Array.isArray(action.required) && action.required.length)) return [3 /*break*/, 6];
587
640
  /** 如果是按钮指定了required,则校验前先清空一下遗留的校验报错 */
588
641
  store.clearErrors();
589
642
  fields = action.required.map(function (item) { return ({
@@ -591,31 +644,31 @@ var Form = /** @class */ (function (_super) {
591
644
  rules: { isRequired: true }
592
645
  }); });
593
646
  return [4 /*yield*/, store.validateFields(fields)];
594
- case 1:
647
+ case 3:
595
648
  validationRes = _f.sent();
596
- if (!!validationRes) return [3 /*break*/, 3];
649
+ if (!!validationRes) return [3 /*break*/, 5];
597
650
  return [4 /*yield*/, dispatchEvent('validateError', this.props.data)];
598
- case 2:
651
+ case 4:
599
652
  dispatcher = _f.sent();
600
653
  if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
601
654
  env.notify('error', __('Form.validateFailed'));
602
655
  }
603
656
  /** 抛异常是为了在dialog中catch这个错误,避免弹窗直接关闭 */
604
657
  return [2 /*return*/, Promise.reject(__('Form.validateFailed'))];
605
- case 3:
658
+ case 5:
606
659
  /** 重置validated状态,保证submit时触发表单中的校验项 */
607
660
  store.clearErrors();
608
- _f.label = 4;
609
- case 4:
661
+ _f.label = 6;
662
+ case 6:
610
663
  if (!(action.type === 'submit' ||
611
664
  action.actionType === 'submit' ||
612
665
  action.actionType === 'confirm' ||
613
666
  action.actionType === 'reset-and-submit' ||
614
- action.actionType === 'clear-and-submit')) return [3 /*break*/, 6];
667
+ action.actionType === 'clear-and-submit')) return [3 /*break*/, 8];
615
668
  _e = this.props, dispatchEvent_1 = _e.dispatchEvent, onEvent = _e.onEvent;
616
669
  submitEvent = (_b = (_a = onEvent === null || onEvent === void 0 ? void 0 : onEvent.submit) === null || _a === void 0 ? void 0 : _a.actions) === null || _b === void 0 ? void 0 : _b.length;
617
670
  return [4 /*yield*/, dispatchEvent_1('submit', this.props.data)];
618
- case 5:
671
+ case 7:
619
672
  dispatcher = _f.sent();
620
673
  if ((dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented) || submitEvent) {
621
674
  return [2 /*return*/];
@@ -627,119 +680,132 @@ var Form = /** @class */ (function (_super) {
627
680
  else if (action.actionType === 'clear-and-submit') {
628
681
  store.clear(this.handleReset(action));
629
682
  }
630
- return [2 /*return*/, this.submit(function (values) {
683
+ return [2 /*return*/, this.submit(function (values) { return tslib.__awaiter(_this, void 0, void 0, function () {
684
+ var result, finnalAsyncApi_1;
631
685
  var _a;
632
- if (onSubmit && onSubmit(values, action) === false) {
633
- return Promise.resolve(false);
634
- }
635
- // 走到这里代表校验成功了
636
- dispatchEvent_1('validateSucc', _this.props.data);
637
- if (target) {
638
- _this.submitToTarget(Scoped.filterTarget(target, values), values);
639
- /** 可能配置页面跳转事件,页面路由变化导致persistKey不一致,无法清除持久化数据,所以提交成功事件之前先清理一下 */
640
- clearPersistDataAfterSubmit && store.clearLocalPersistData();
641
- dispatchEvent_1('submitSucc', object.createObject(_this.props.data, values));
642
- }
643
- else if (action.actionType === 'reload') {
644
- action.target &&
645
- _this.reloadTarget(Scoped.filterTarget(action.target, values), values);
646
- }
647
- else if (action.actionType === 'dialog') {
648
- store.openDialog(data, undefined, action.callback, delegate || _this.context);
649
- }
650
- else if (action.actionType === 'drawer') {
651
- store.openDrawer(data);
652
- }
653
- else if (api.isEffectiveApi(action.api || api$1, values)) {
654
- var finnalAsyncApi_1 = action.asyncApi || asyncApi;
655
- api.isEffectiveApi(finnalAsyncApi_1, store.data) &&
656
- store.updateData((_a = {},
657
- _a[finishedField || 'finished'] = false,
658
- _a));
659
- return store
660
- .saveRemote(action.api || api$1, values, {
661
- successMessage: typeof saveSuccess === 'string'
662
- ? tpl.filter(saveSuccess, store.data)
663
- : undefined,
664
- errorMessage: typeof saveFailed === 'string'
665
- ? tpl.filter(saveFailed, store.data)
666
- : undefined,
667
- onSuccess: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
668
- var dispatcher, cbResult;
669
- var _this = this;
670
- return tslib.__generator(this, function (_a) {
671
- switch (_a.label) {
672
- case 0:
673
- clearPersistDataAfterSubmit && store.clearLocalPersistData();
674
- return [4 /*yield*/, dispatchEvent_1('submitSucc', object.createObject(this.props.data, { result: result }))];
675
- case 1:
676
- dispatcher = _a.sent();
677
- if (!api.isEffectiveApi(finnalAsyncApi_1, store.data) ||
678
- store.data[finishedField || 'finished']) {
679
- return [2 /*return*/, {
680
- cbResult: null,
681
- dispatcher: dispatcher
682
- }];
683
- }
684
- cbResult = helper.until(function () { return store.checkRemote(finnalAsyncApi_1, store.data); }, function (ret) { return ret && ret[finishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, checkInterval).then(function (value) {
685
- // 派发asyncApiFinished事件
686
- dispatchEvent_1('asyncApiFinished', store.data);
686
+ var _this = this;
687
+ return tslib.__generator(this, function (_b) {
688
+ switch (_b.label) {
689
+ case 0:
690
+ if (!onSubmit) return [3 /*break*/, 2];
691
+ return [4 /*yield*/, onSubmit(values, action)];
692
+ case 1:
693
+ result = _b.sent();
694
+ if (result === false) {
695
+ return [2 /*return*/, Promise.resolve(false)];
696
+ }
697
+ _b.label = 2;
698
+ case 2:
699
+ // 走到这里代表校验成功了
700
+ dispatchEvent_1('validateSucc', this.props.data);
701
+ if (target) {
702
+ this.submitToTarget(Scoped.filterTarget(target, values), values);
703
+ /** 可能配置页面跳转事件,页面路由变化导致persistKey不一致,无法清除持久化数据,所以提交成功事件之前先清理一下 */
704
+ clearPersistDataAfterSubmit && store.clearLocalPersistData();
705
+ dispatchEvent_1('submitSucc', object.createObject(this.props.data, values));
706
+ }
707
+ else if (action.actionType === 'reload') {
708
+ action.target &&
709
+ this.reloadTarget(Scoped.filterTarget(action.target, values), values);
710
+ }
711
+ else if (action.actionType === 'dialog') {
712
+ store.openDialog(data, undefined, action.callback, delegate || this.context);
713
+ }
714
+ else if (action.actionType === 'drawer') {
715
+ store.openDrawer(data);
716
+ }
717
+ else if (api.isEffectiveApi(action.api || api$1, values)) {
718
+ finnalAsyncApi_1 = action.asyncApi || asyncApi;
719
+ api.isEffectiveApi(finnalAsyncApi_1, store.data) &&
720
+ store.updateData((_a = {},
721
+ _a[finishedField || 'finished'] = false,
722
+ _a));
723
+ return [2 /*return*/, store
724
+ .saveRemote(action.api || api$1, values, {
725
+ successMessage: typeof saveSuccess === 'string'
726
+ ? tpl.filter(saveSuccess, store.data)
727
+ : undefined,
728
+ errorMessage: typeof saveFailed === 'string'
729
+ ? tpl.filter(saveFailed, store.data)
730
+ : undefined,
731
+ onSuccess: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
732
+ var dispatcher, cbResult;
733
+ var _this = this;
734
+ return tslib.__generator(this, function (_a) {
735
+ switch (_a.label) {
736
+ case 0:
737
+ clearPersistDataAfterSubmit && store.clearLocalPersistData();
738
+ return [4 /*yield*/, dispatchEvent_1('submitSucc', object.createObject(this.props.data, { result: result }))];
739
+ case 1:
740
+ dispatcher = _a.sent();
741
+ if (!api.isEffectiveApi(finnalAsyncApi_1, store.data) ||
742
+ store.data[finishedField || 'finished']) {
743
+ return [2 /*return*/, {
744
+ cbResult: null,
745
+ dispatcher: dispatcher
746
+ }];
747
+ }
748
+ cbResult = helper.until(function () { return store.checkRemote(finnalAsyncApi_1, store.data); }, function (ret) { return ret && ret[finishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, checkInterval).then(function (value) {
749
+ // 派发asyncApiFinished事件
750
+ dispatchEvent_1('asyncApiFinished', store.data);
751
+ });
752
+ return [2 /*return*/, {
753
+ cbResult: cbResult,
754
+ dispatcher: dispatcher
755
+ }];
756
+ }
757
+ });
758
+ }); },
759
+ onFailed: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
760
+ var dispatcher;
761
+ return tslib.__generator(this, function (_a) {
762
+ switch (_a.label) {
763
+ case 0: return [4 /*yield*/, dispatchEvent_1('submitFail', object.createObject(this.props.data, { error: result }))];
764
+ case 1:
765
+ dispatcher = _a.sent();
766
+ return [2 /*return*/, {
767
+ dispatcher: dispatcher
768
+ }];
769
+ }
770
+ });
771
+ }); }
772
+ })
773
+ .then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
774
+ var feedback, confirmed;
775
+ return tslib.__generator(this, function (_a) {
776
+ switch (_a.label) {
777
+ case 0:
778
+ onSaved && onSaved(values, response);
779
+ feedback = action.feedback || this.props.feedback;
780
+ if (!(feedback && helper.isVisible(feedback, store.data))) return [3 /*break*/, 2];
781
+ return [4 /*yield*/, this.openFeedback(feedback, store.data)];
782
+ case 1:
783
+ confirmed = _a.sent();
784
+ // 如果 feedback 配置了,取消就跳过原有逻辑。
785
+ if (feedback.skipRestOnCancel && !confirmed) {
786
+ throw new helper.SkipOperation();
787
+ }
788
+ else if (feedback.skipRestOnConfirm && confirmed) {
789
+ throw new helper.SkipOperation();
790
+ }
791
+ _a.label = 2;
792
+ case 2: return [2 /*return*/, object.injectObjectChain(store.data, {
793
+ __payload: values,
794
+ __response: response
795
+ })];
796
+ }
687
797
  });
688
- return [2 /*return*/, {
689
- cbResult: cbResult,
690
- dispatcher: dispatcher
691
- }];
692
- }
693
- });
694
- }); },
695
- onFailed: function (result) { return tslib.__awaiter(_this, void 0, void 0, function () {
696
- var dispatcher;
697
- return tslib.__generator(this, function (_a) {
698
- switch (_a.label) {
699
- case 0: return [4 /*yield*/, dispatchEvent_1('submitFail', object.createObject(this.props.data, { error: result }))];
700
- case 1:
701
- dispatcher = _a.sent();
702
- return [2 /*return*/, {
703
- dispatcher: dispatcher
704
- }];
705
- }
706
- });
707
- }); }
708
- })
709
- .then(function (response) { return tslib.__awaiter(_this, void 0, void 0, function () {
710
- var feedback, confirmed;
711
- return tslib.__generator(this, function (_a) {
712
- switch (_a.label) {
713
- case 0:
714
- onSaved && onSaved(values, response);
715
- feedback = action.feedback || this.props.feedback;
716
- if (!(feedback && helper.isVisible(feedback, store.data))) return [3 /*break*/, 2];
717
- return [4 /*yield*/, this.openFeedback(feedback, store.data)];
718
- case 1:
719
- confirmed = _a.sent();
720
- // 如果 feedback 配置了,取消就跳过原有逻辑。
721
- if (feedback.skipRestOnCancel && !confirmed) {
722
- throw new helper.SkipOperation();
723
- }
724
- else if (feedback.skipRestOnConfirm && confirmed) {
725
- throw new helper.SkipOperation();
726
- }
727
- _a.label = 2;
728
- case 2: return [2 /*return*/, object.injectObjectChain(store.data, {
729
- __payload: values,
730
- __response: response
731
- })];
798
+ }); })];
732
799
  }
733
- });
734
- }); });
735
- }
736
- else {
737
- clearPersistDataAfterSubmit && store.clearLocalPersistData();
738
- // type为submit,但是没有配api以及target时,只派发事件
739
- dispatchEvent_1('submitSucc', object.createObject(_this.props.data, values));
740
- }
741
- return Promise.resolve(null);
742
- }, throwErrors)
800
+ else {
801
+ clearPersistDataAfterSubmit && store.clearLocalPersistData();
802
+ // type为submit,但是没有配api以及target时,只派发事件
803
+ dispatchEvent_1('submitSucc', object.createObject(this.props.data, values));
804
+ }
805
+ return [2 /*return*/, Promise.resolve(null)];
806
+ }
807
+ });
808
+ }); }, throwErrors, true)
743
809
  .then(function (values) {
744
810
  // 有可能 onSubmit return false 了,那么后面的就不应该再执行了。
745
811
  if (values === false) {
@@ -767,7 +833,7 @@ var Form = /** @class */ (function (_super) {
767
833
  throw reason;
768
834
  }
769
835
  })];
770
- case 6:
836
+ case 8:
771
837
  if (action.type === 'reset' || action.actionType === 'reset') {
772
838
  store.setCurrentAction(action);
773
839
  store.reset(onReset);
@@ -778,7 +844,7 @@ var Form = /** @class */ (function (_super) {
778
844
  }
779
845
  else if (action.actionType === 'validate') {
780
846
  store.setCurrentAction(action);
781
- return [2 /*return*/, this.validate(true, throwErrors)];
847
+ return [2 /*return*/, this.validate(true, throwErrors, true, true)];
782
848
  }
783
849
  else if (action.actionType === 'dialog') {
784
850
  store.setCurrentAction(action);
@@ -854,8 +920,8 @@ var Form = /** @class */ (function (_super) {
854
920
  // 不识别的丢给上层去处理。
855
921
  return [2 /*return*/, onAction(e, action, data, throwErrors, delegate || this.context)];
856
922
  }
857
- _f.label = 7;
858
- case 7: return [2 /*return*/];
923
+ _f.label = 9;
924
+ case 9: return [2 /*return*/];
859
925
  }
860
926
  });
861
927
  });
@@ -361,6 +361,7 @@ export interface FormItemProps extends RendererProps {
361
361
  };
362
362
  error?: string;
363
363
  showErrorMsg?: boolean;
364
+ testid?: string;
364
365
  }
365
366
  export type FormControlProps = RendererProps & {
366
367
  onOpenDialog: (schema: Schema, data: any) => Promise<any>;