amis-core 2.9.0 → 3.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 (331) hide show
  1. package/esm/Root.d.ts +89 -4
  2. package/esm/Root.js +15 -4
  3. package/esm/RootRenderer.d.ts +3 -1
  4. package/esm/RootRenderer.js +9 -3
  5. package/esm/SchemaRenderer.d.ts +4 -2
  6. package/esm/SchemaRenderer.js +32 -24
  7. package/esm/Scoped.d.ts +8 -0
  8. package/esm/Scoped.js +20 -5
  9. package/esm/StatusScoped.d.ts +58 -0
  10. package/esm/StatusScoped.js +54 -0
  11. package/esm/WithRootStore.d.ts +2 -2
  12. package/esm/WithRootStore.js +1 -1
  13. package/esm/WithStore.js +6 -2
  14. package/esm/actions/Action.d.ts +1 -0
  15. package/esm/actions/Action.js +19 -5
  16. package/esm/actions/AjaxAction.js +1 -1
  17. package/esm/actions/BreakAction.js +1 -1
  18. package/esm/actions/BroadcastAction.js +1 -1
  19. package/esm/actions/CmptAction.js +8 -7
  20. package/esm/actions/ContinueAction.js +1 -1
  21. package/esm/actions/CopyAction.js +1 -1
  22. package/esm/actions/CustomAction.js +4 -4
  23. package/esm/actions/DialogAction.d.ts +16 -2
  24. package/esm/actions/DialogAction.js +23 -7
  25. package/esm/actions/DrawerAction.js +1 -1
  26. package/esm/actions/EmailAction.js +1 -1
  27. package/esm/actions/LinkAction.js +1 -1
  28. package/esm/actions/LoopAction.js +1 -1
  29. package/esm/actions/PageAction.js +1 -1
  30. package/esm/actions/ParallelAction.js +1 -1
  31. package/esm/actions/SwitchAction.js +1 -1
  32. package/esm/actions/ToastAction.js +1 -1
  33. package/esm/components/CustomStyle.d.ts +13 -0
  34. package/esm/components/CustomStyle.js +18 -0
  35. package/esm/components/LazyComponent.d.ts +1 -1
  36. package/esm/components/LazyComponent.js +1 -1
  37. package/esm/components/Overlay.d.ts +3 -3
  38. package/esm/components/Overlay.js +1 -1
  39. package/esm/components/PopOver.d.ts +2 -2
  40. package/esm/components/PopOver.js +1 -1
  41. package/esm/env.d.ts +10 -2
  42. package/esm/env.js +1 -1
  43. package/esm/envOverwrite.js +1 -5
  44. package/esm/factory.d.ts +5 -3
  45. package/esm/factory.js +3 -3
  46. package/esm/index.d.ts +11 -4
  47. package/esm/index.js +55 -33
  48. package/esm/locale.d.ts +2 -2
  49. package/esm/locale.js +10 -3
  50. package/esm/renderers/Form.d.ts +3 -2
  51. package/esm/renderers/Form.js +216 -180
  52. package/esm/renderers/Item.d.ts +55 -41
  53. package/esm/renderers/Item.js +30 -19
  54. package/esm/renderers/Options.js +11 -4
  55. package/esm/renderers/Placeholder.js +1 -1
  56. package/esm/renderers/builtin.js +1 -1
  57. package/esm/renderers/register.js +1 -1
  58. package/esm/renderers/wrapControl.d.ts +2 -2
  59. package/esm/renderers/wrapControl.js +13 -16
  60. package/esm/store/app.d.ts +1 -0
  61. package/esm/store/app.js +1 -1
  62. package/esm/store/combo.d.ts +3 -0
  63. package/esm/store/combo.js +1 -1
  64. package/esm/store/crud.d.ts +2 -0
  65. package/esm/store/crud.js +31 -9
  66. package/esm/store/form.d.ts +1 -0
  67. package/esm/store/form.js +10 -4
  68. package/esm/store/formItem.js +2 -2
  69. package/esm/store/iRenderer.d.ts +1 -0
  70. package/esm/store/iRenderer.js +54 -13
  71. package/esm/store/index.js +1 -1
  72. package/esm/store/list.d.ts +1 -0
  73. package/esm/store/list.js +7 -3
  74. package/esm/store/manager.js +1 -1
  75. package/esm/store/modal.d.ts +1 -0
  76. package/esm/store/modal.js +1 -1
  77. package/esm/store/node.js +1 -1
  78. package/esm/store/pagination.d.ts +1 -0
  79. package/esm/store/pagination.js +2 -2
  80. package/esm/store/root.d.ts +4 -6
  81. package/esm/store/root.js +53 -24
  82. package/esm/store/service.d.ts +1 -0
  83. package/esm/store/service.js +1 -1
  84. package/esm/store/status.d.ts +12 -0
  85. package/esm/store/status.js +38 -0
  86. package/esm/store/table.d.ts +28 -23
  87. package/esm/store/table.js +26 -5
  88. package/esm/store/table2.d.ts +7 -6
  89. package/esm/store/table2.js +27 -23
  90. package/esm/theme.d.ts +1 -1
  91. package/esm/theme.js +1 -1
  92. package/esm/types.d.ts +7 -1
  93. package/esm/utils/Animation.js +1 -1
  94. package/esm/utils/ColorScale.js +1 -1
  95. package/esm/utils/DataSchema.js +1 -1
  96. package/esm/utils/DataScope.d.ts +3 -5
  97. package/esm/utils/DataScope.js +88 -31
  98. package/esm/utils/RootClose.js +1 -1
  99. package/esm/utils/SimpleMap.js +1 -1
  100. package/esm/utils/api.js +14 -5
  101. package/esm/utils/attachmentAdpator.js +2 -2
  102. package/esm/utils/autobind.js +1 -1
  103. package/esm/utils/columnsSplit.js +1 -1
  104. package/esm/utils/dataMapping.js +1 -1
  105. package/esm/utils/date.d.ts +7 -0
  106. package/esm/utils/date.js +34 -2
  107. package/esm/utils/debug.js +4 -4
  108. package/esm/utils/decodeEntity.js +1 -1
  109. package/esm/utils/dom.d.ts +3 -0
  110. package/esm/utils/dom.js +47 -10
  111. package/esm/utils/errors.js +1 -1
  112. package/esm/utils/escapeHtml.js +1 -1
  113. package/esm/utils/filter-schema.js +1 -1
  114. package/esm/utils/filter.js +1 -1
  115. package/esm/utils/formatDuration.js +1 -1
  116. package/esm/utils/formula.js +2 -2
  117. package/esm/utils/getVariable.js +1 -1
  118. package/esm/utils/grammar.js +3 -3
  119. package/esm/utils/handleAction.js +1 -1
  120. package/esm/utils/helper.d.ts +9 -2
  121. package/esm/utils/helper.js +52 -20
  122. package/esm/utils/highlight.js +1 -1
  123. package/esm/utils/icon.d.ts +6 -1
  124. package/esm/utils/icon.js +6 -1
  125. package/esm/utils/image.js +1 -1
  126. package/esm/utils/isPureVariable.js +3 -3
  127. package/esm/utils/json-schema-2-amis-schema.js +1 -1
  128. package/esm/utils/keyToPath.js +1 -1
  129. package/esm/utils/makeSorter.js +1 -1
  130. package/esm/utils/memoryParse.d.ts +17 -0
  131. package/esm/utils/memoryParse.js +26 -0
  132. package/esm/utils/normalizeLink.js +1 -1
  133. package/esm/utils/normalizeOptions.js +4 -2
  134. package/esm/utils/object.d.ts +2 -0
  135. package/esm/utils/object.js +27 -2
  136. package/esm/utils/offset.js +1 -1
  137. package/esm/utils/offsetParent.js +1 -1
  138. package/esm/utils/optionValueCompare.js +1 -1
  139. package/esm/utils/position.js +1 -1
  140. package/esm/utils/prettyBytes.js +1 -1
  141. package/esm/utils/renderer-event.js +35 -32
  142. package/esm/utils/replaceText.js +1 -1
  143. package/esm/utils/resize-sensor.js +1 -1
  144. package/esm/utils/resolveCondition.d.ts +1 -0
  145. package/esm/utils/resolveCondition.js +19 -4
  146. package/esm/utils/resolveVariable.js +4 -3
  147. package/esm/utils/resolveVariableAndFilter.js +1 -1
  148. package/esm/utils/resolveVariableAndFilterForAsync.d.ts +6 -1
  149. package/esm/utils/resolveVariableAndFilterForAsync.js +23 -5
  150. package/esm/utils/scrollPosition.js +1 -1
  151. package/esm/utils/string2regExp.js +1 -1
  152. package/esm/utils/stripNumber.js +1 -1
  153. package/esm/utils/style-helper.d.ts +12 -4
  154. package/esm/utils/style-helper.js +96 -19
  155. package/esm/utils/style.js +2 -2
  156. package/esm/utils/toNumber.js +1 -1
  157. package/esm/utils/tokenize.js +1 -1
  158. package/esm/utils/tpl-builtin.d.ts +2 -1
  159. package/esm/utils/tpl-builtin.js +19 -2
  160. package/esm/utils/tpl-lodash.js +3 -2
  161. package/esm/utils/tpl.d.ts +2 -0
  162. package/esm/utils/tpl.js +24 -2
  163. package/esm/utils/uncontrollable.js +1 -1
  164. package/esm/utils/validations.d.ts +4 -1
  165. package/esm/utils/validations.js +27 -12
  166. package/lib/Root.d.ts +89 -4
  167. package/lib/Root.js +15 -4
  168. package/lib/RootRenderer.d.ts +3 -1
  169. package/lib/RootRenderer.js +8 -2
  170. package/lib/SchemaRenderer.d.ts +4 -2
  171. package/lib/SchemaRenderer.js +32 -23
  172. package/lib/Scoped.d.ts +8 -0
  173. package/lib/Scoped.js +20 -4
  174. package/lib/StatusScoped.d.ts +58 -0
  175. package/lib/StatusScoped.js +63 -0
  176. package/lib/WithRootStore.d.ts +2 -2
  177. package/lib/WithRootStore.js +1 -1
  178. package/lib/WithStore.js +6 -2
  179. package/lib/actions/Action.d.ts +1 -0
  180. package/lib/actions/Action.js +19 -5
  181. package/lib/actions/AjaxAction.js +1 -1
  182. package/lib/actions/BreakAction.js +1 -1
  183. package/lib/actions/BroadcastAction.js +1 -1
  184. package/lib/actions/CmptAction.js +8 -7
  185. package/lib/actions/ContinueAction.js +1 -1
  186. package/lib/actions/CopyAction.js +1 -1
  187. package/lib/actions/CustomAction.js +4 -4
  188. package/lib/actions/DialogAction.d.ts +16 -2
  189. package/lib/actions/DialogAction.js +23 -7
  190. package/lib/actions/DrawerAction.js +1 -1
  191. package/lib/actions/EmailAction.js +1 -1
  192. package/lib/actions/LinkAction.js +1 -1
  193. package/lib/actions/LoopAction.js +1 -1
  194. package/lib/actions/PageAction.js +1 -1
  195. package/lib/actions/ParallelAction.js +1 -1
  196. package/lib/actions/SwitchAction.js +1 -1
  197. package/lib/actions/ToastAction.js +1 -1
  198. package/lib/components/CustomStyle.d.ts +13 -0
  199. package/lib/components/CustomStyle.js +22 -0
  200. package/lib/components/LazyComponent.d.ts +1 -1
  201. package/lib/components/LazyComponent.js +1 -1
  202. package/lib/components/Overlay.d.ts +3 -3
  203. package/lib/components/Overlay.js +1 -1
  204. package/lib/components/PopOver.d.ts +2 -2
  205. package/lib/components/PopOver.js +1 -1
  206. package/lib/env.d.ts +10 -2
  207. package/lib/env.js +1 -1
  208. package/lib/envOverwrite.js +1 -5
  209. package/lib/factory.d.ts +5 -3
  210. package/lib/factory.js +3 -3
  211. package/lib/index.d.ts +11 -4
  212. package/lib/index.js +61 -23
  213. package/lib/locale.d.ts +2 -2
  214. package/lib/locale.js +10 -3
  215. package/lib/renderers/Form.d.ts +3 -2
  216. package/lib/renderers/Form.js +215 -179
  217. package/lib/renderers/Item.d.ts +55 -41
  218. package/lib/renderers/Item.js +30 -19
  219. package/lib/renderers/Options.js +11 -4
  220. package/lib/renderers/Placeholder.js +1 -1
  221. package/lib/renderers/builtin.js +1 -1
  222. package/lib/renderers/register.js +1 -1
  223. package/lib/renderers/wrapControl.d.ts +2 -2
  224. package/lib/renderers/wrapControl.js +12 -15
  225. package/lib/store/app.d.ts +1 -0
  226. package/lib/store/app.js +1 -1
  227. package/lib/store/combo.d.ts +3 -0
  228. package/lib/store/combo.js +1 -1
  229. package/lib/store/crud.d.ts +2 -0
  230. package/lib/store/crud.js +31 -9
  231. package/lib/store/form.d.ts +1 -0
  232. package/lib/store/form.js +10 -4
  233. package/lib/store/formItem.js +2 -2
  234. package/lib/store/iRenderer.d.ts +1 -0
  235. package/lib/store/iRenderer.js +53 -12
  236. package/lib/store/index.js +1 -1
  237. package/lib/store/list.d.ts +1 -0
  238. package/lib/store/list.js +7 -3
  239. package/lib/store/manager.js +1 -1
  240. package/lib/store/modal.d.ts +1 -0
  241. package/lib/store/modal.js +1 -1
  242. package/lib/store/node.js +1 -1
  243. package/lib/store/pagination.d.ts +1 -0
  244. package/lib/store/pagination.js +2 -2
  245. package/lib/store/root.d.ts +4 -6
  246. package/lib/store/root.js +52 -23
  247. package/lib/store/service.d.ts +1 -0
  248. package/lib/store/service.js +1 -1
  249. package/lib/store/status.d.ts +12 -0
  250. package/lib/store/status.js +42 -0
  251. package/lib/store/table.d.ts +28 -23
  252. package/lib/store/table.js +26 -5
  253. package/lib/store/table2.d.ts +7 -6
  254. package/lib/store/table2.js +27 -23
  255. package/lib/theme.d.ts +1 -1
  256. package/lib/theme.js +1 -1
  257. package/lib/types.d.ts +7 -1
  258. package/lib/utils/Animation.js +1 -1
  259. package/lib/utils/ColorScale.js +1 -1
  260. package/lib/utils/DataSchema.js +1 -1
  261. package/lib/utils/DataScope.d.ts +3 -5
  262. package/lib/utils/DataScope.js +86 -29
  263. package/lib/utils/RootClose.js +1 -1
  264. package/lib/utils/SimpleMap.js +1 -1
  265. package/lib/utils/api.js +13 -4
  266. package/lib/utils/attachmentAdpator.js +2 -2
  267. package/lib/utils/autobind.js +1 -1
  268. package/lib/utils/columnsSplit.js +1 -1
  269. package/lib/utils/dataMapping.js +1 -1
  270. package/lib/utils/date.d.ts +7 -0
  271. package/lib/utils/date.js +34 -1
  272. package/lib/utils/debug.js +4 -4
  273. package/lib/utils/decodeEntity.js +1 -1
  274. package/lib/utils/dom.d.ts +3 -0
  275. package/lib/utils/dom.js +48 -9
  276. package/lib/utils/errors.js +1 -1
  277. package/lib/utils/escapeHtml.js +1 -1
  278. package/lib/utils/filter-schema.js +1 -1
  279. package/lib/utils/filter.js +1 -1
  280. package/lib/utils/formatDuration.js +1 -1
  281. package/lib/utils/formula.js +2 -2
  282. package/lib/utils/getVariable.js +1 -1
  283. package/lib/utils/grammar.js +3 -3
  284. package/lib/utils/handleAction.js +1 -1
  285. package/lib/utils/helper.d.ts +9 -2
  286. package/lib/utils/helper.js +53 -19
  287. package/lib/utils/highlight.js +1 -1
  288. package/lib/utils/icon.d.ts +6 -1
  289. package/lib/utils/icon.js +6 -1
  290. package/lib/utils/image.js +1 -1
  291. package/lib/utils/isPureVariable.js +3 -3
  292. package/lib/utils/json-schema-2-amis-schema.js +1 -1
  293. package/lib/utils/keyToPath.js +1 -1
  294. package/lib/utils/makeSorter.js +1 -1
  295. package/lib/utils/memoryParse.d.ts +17 -0
  296. package/lib/utils/memoryParse.js +30 -0
  297. package/lib/utils/normalizeLink.js +1 -1
  298. package/lib/utils/normalizeOptions.js +4 -2
  299. package/lib/utils/object.d.ts +2 -0
  300. package/lib/utils/object.js +28 -1
  301. package/lib/utils/offset.js +1 -1
  302. package/lib/utils/offsetParent.js +1 -1
  303. package/lib/utils/optionValueCompare.js +1 -1
  304. package/lib/utils/position.js +1 -1
  305. package/lib/utils/prettyBytes.js +1 -1
  306. package/lib/utils/renderer-event.js +35 -32
  307. package/lib/utils/replaceText.js +1 -1
  308. package/lib/utils/resize-sensor.js +1 -1
  309. package/lib/utils/resolveCondition.d.ts +1 -0
  310. package/lib/utils/resolveCondition.js +19 -3
  311. package/lib/utils/resolveVariable.js +3 -2
  312. package/lib/utils/resolveVariableAndFilter.js +1 -1
  313. package/lib/utils/resolveVariableAndFilterForAsync.d.ts +6 -1
  314. package/lib/utils/resolveVariableAndFilterForAsync.js +22 -3
  315. package/lib/utils/scrollPosition.js +1 -1
  316. package/lib/utils/string2regExp.js +1 -1
  317. package/lib/utils/stripNumber.js +1 -1
  318. package/lib/utils/style-helper.d.ts +12 -4
  319. package/lib/utils/style-helper.js +101 -18
  320. package/lib/utils/style.js +2 -2
  321. package/lib/utils/toNumber.js +1 -1
  322. package/lib/utils/tokenize.js +1 -1
  323. package/lib/utils/tpl-builtin.d.ts +2 -1
  324. package/lib/utils/tpl-builtin.js +19 -2
  325. package/lib/utils/tpl-lodash.js +3 -2
  326. package/lib/utils/tpl.d.ts +2 -0
  327. package/lib/utils/tpl.js +24 -1
  328. package/lib/utils/uncontrollable.js +1 -1
  329. package/lib/utils/validations.d.ts +4 -1
  330. package/lib/utils/validations.js +27 -12
  331. package/package.json +3 -3
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.9.0
2
+ * amis-core v3.1.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -14,7 +14,7 @@ import { promisify, isEmpty, until, noop, difference, isVisible, repeatCount, qs
14
14
  import debounce from 'lodash/debounce';
15
15
  import flatten from 'lodash/flatten';
16
16
  import find from 'lodash/find';
17
- import { ScopedContext } from '../Scoped.js';
17
+ import { filterTarget, ScopedContext } from '../Scoped.js';
18
18
  import 'amis-formula';
19
19
  import 'moment';
20
20
  import { isObject, createObject, cloneObject } from '../utils/object.js';
@@ -54,6 +54,7 @@ var Form = /** @class */ (function (_super) {
54
54
  _this.reload = _this.reload.bind(_this);
55
55
  _this.silentReload = _this.silentReload.bind(_this);
56
56
  _this.initInterval = _this.initInterval.bind(_this);
57
+ _this.dispatchInited = _this.dispatchInited.bind(_this);
57
58
  _this.blockRouting = _this.blockRouting.bind(_this);
58
59
  _this.beforePageUnload = _this.beforePageUnload.bind(_this);
59
60
  var store = props.store, canAccessSuperData = props.canAccessSuperData, persistData = props.persistData, simpleMode = props.simpleMode;
@@ -136,6 +137,7 @@ var Form = /** @class */ (function (_super) {
136
137
  return until(function () { return store.checkRemote(initAsyncApi, store.data); }, function (ret) { return ret && ret[initFinishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, initCheckInterval);
137
138
  }
138
139
  })
140
+ .then(this.dispatchInited)
139
141
  .then(this.initInterval)
140
142
  .then(this.onInit);
141
143
  }
@@ -155,7 +157,9 @@ var Form = /** @class */ (function (_super) {
155
157
  store[store.hasRemoteData ? 'fetchData' : 'fetchInitData'](props.initApi, store.data, {
156
158
  successMessage: fetchSuccess,
157
159
  errorMessage: fetchFailed
158
- }).then(this.initInterval);
160
+ })
161
+ .then(this.dispatchInited)
162
+ .then(this.initInterval);
159
163
  }
160
164
  };
161
165
  Form.prototype.componentWillUnmount = function () {
@@ -170,6 +174,27 @@ var Form = /** @class */ (function (_super) {
170
174
  window.removeEventListener('beforeunload', this.beforePageUnload);
171
175
  (_a = this.unBlockRouting) === null || _a === void 0 ? void 0 : _a.call(this);
172
176
  };
177
+ Form.prototype.dispatchInited = function (value) {
178
+ var _a;
179
+ return __awaiter(this, void 0, void 0, function () {
180
+ var _b, data, store, dispatchEvent;
181
+ return __generator(this, function (_c) {
182
+ switch (_c.label) {
183
+ case 0:
184
+ _b = this.props, data = _b.data, store = _b.store, dispatchEvent = _b.dispatchEvent;
185
+ if (store.fetching) {
186
+ return [2 /*return*/];
187
+ }
188
+ // 派发init事件,参数为初始化数据
189
+ return [4 /*yield*/, dispatchEvent('inited', createObject(data, __assign(__assign({}, value === null || value === void 0 ? void 0 : value.data), { responseData: (_a = value === null || value === void 0 ? void 0 : value.data) !== null && _a !== void 0 ? _a : {}, responseStatus: store.error ? 1 : 0, responseMsg: store.msg })))];
190
+ case 1:
191
+ // 派发init事件,参数为初始化数据
192
+ _c.sent();
193
+ return [2 /*return*/, value];
194
+ }
195
+ });
196
+ });
197
+ };
173
198
  Form.prototype.blockRouting = function () {
174
199
  var store = this.props.store;
175
200
  var _a = this.props, promptPageLeaveMessage = _a.promptPageLeaveMessage, promptPageLeave = _a.promptPageLeave;
@@ -186,11 +211,11 @@ var Form = /** @class */ (function (_super) {
186
211
  };
187
212
  Form.prototype.onInit = function () {
188
213
  return __awaiter(this, void 0, void 0, function () {
189
- var _a, onInit, store, persistData, submitOnInit, dispatchEvent, data, initedAt, hooks, dispatcher;
214
+ var _a, onInit, store, persistData, submitOnInit, data, initedAt, hooks;
190
215
  return __generator(this, function (_b) {
191
216
  switch (_b.label) {
192
217
  case 0:
193
- _a = this.props, onInit = _a.onInit, store = _a.store, persistData = _a.persistData, submitOnInit = _a.submitOnInit, dispatchEvent = _a.dispatchEvent;
218
+ _a = this.props, onInit = _a.onInit, store = _a.store, persistData = _a.persistData, submitOnInit = _a.submitOnInit, _a.dispatchEvent;
194
219
  if (!isAlive(store)) {
195
220
  return [2 /*return*/];
196
221
  }
@@ -215,12 +240,7 @@ var Form = /** @class */ (function (_super) {
215
240
  store.getLocalPersistData();
216
241
  data = cloneObject(store.data);
217
242
  }
218
- return [4 /*yield*/, dispatchEvent('inited', createObject(this.props.data, data))];
219
- case 2:
220
- dispatcher = _b.sent();
221
- if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
222
- onInit && onInit(data, this.props);
223
- }
243
+ onInit && onInit(data, this.props);
224
244
  submitOnInit &&
225
245
  this.handleAction(undefined, {
226
246
  type: 'submit'
@@ -255,12 +275,23 @@ var Form = /** @class */ (function (_super) {
255
275
  return until(function () { return store.checkRemote(initAsyncApi, store.data); }, function (ret) { return ret && ret[initFinishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); });
256
276
  }
257
277
  })
258
- .then(function (result) {
259
- if (result === null || result === void 0 ? void 0 : result.ok) {
260
- _this.initInterval(result);
261
- store.reset(undefined, false);
262
- }
263
- })
278
+ .then(function (result) { return __awaiter(_this, void 0, void 0, function () {
279
+ return __generator(this, function (_a) {
280
+ switch (_a.label) {
281
+ case 0:
282
+ // 派发初始化接口请求完成事件
283
+ return [4 /*yield*/, this.dispatchInited(result)];
284
+ case 1:
285
+ // 派发初始化接口请求完成事件
286
+ _a.sent();
287
+ if (result === null || result === void 0 ? void 0 : result.ok) {
288
+ this.initInterval(result);
289
+ store.reset(undefined, false);
290
+ }
291
+ return [2 /*return*/];
292
+ }
293
+ });
294
+ }); })
264
295
  : store.reset(undefined, false);
265
296
  };
266
297
  Form.prototype.receive = function (values, name, replace) {
@@ -443,14 +474,15 @@ var Form = /** @class */ (function (_super) {
443
474
  };
444
475
  };
445
476
  Form.prototype.handleAction = function (e, action, data, throwErrors, delegate) {
477
+ var _a, _b;
446
478
  if (throwErrors === void 0) { throwErrors = false; }
447
479
  return __awaiter(this, void 0, void 0, function () {
448
- var _a, store, onSubmit, api, asyncApi, finishedField, checkInterval, _b, saveSuccess, saveFailed, resetAfterSubmit, clearAfterSubmit, onAction, onSaved, onReset, onFinished, onFailed, redirect, reload, target, env, onChange, clearPersistDataAfterSubmit, trimValues, dispatchEvent, __, fields, validationRes, dispatcher;
480
+ var _c, store, onSubmit, api, asyncApi, finishedField, checkInterval, _d, saveSuccess, saveFailed, resetAfterSubmit, clearAfterSubmit, onAction, onSaved, onReset, onFinished, onFailed, redirect, reload, target, env, onChange, clearPersistDataAfterSubmit, trimValues, dispatchEvent, __, fields, validationRes, dispatcher, _e, dispatchEvent_1, onEvent, submitEvent, dispatcher;
449
481
  var _this = this;
450
- return __generator(this, function (_c) {
451
- switch (_c.label) {
482
+ return __generator(this, function (_f) {
483
+ switch (_f.label) {
452
484
  case 0:
453
- _a = this.props, store = _a.store, onSubmit = _a.onSubmit, api = _a.api, asyncApi = _a.asyncApi, finishedField = _a.finishedField, checkInterval = _a.checkInterval, _b = _a.messages, saveSuccess = _b.saveSuccess, saveFailed = _b.saveFailed, resetAfterSubmit = _a.resetAfterSubmit, clearAfterSubmit = _a.clearAfterSubmit, onAction = _a.onAction, onSaved = _a.onSaved, onReset = _a.onReset, onFinished = _a.onFinished, onFailed = _a.onFailed, redirect = _a.redirect, reload = _a.reload, target = _a.target, env = _a.env, onChange = _a.onChange, clearPersistDataAfterSubmit = _a.clearPersistDataAfterSubmit, trimValues = _a.trimValues, dispatchEvent = _a.dispatchEvent, __ = _a.translate;
485
+ _c = this.props, store = _c.store, onSubmit = _c.onSubmit, api = _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;
454
486
  // 做动作之前,先把数据同步一下。
455
487
  this.flush();
456
488
  if (trimValues) {
@@ -469,11 +501,11 @@ var Form = /** @class */ (function (_super) {
469
501
  }); });
470
502
  return [4 /*yield*/, store.validateFields(fields)];
471
503
  case 1:
472
- validationRes = _c.sent();
504
+ validationRes = _f.sent();
473
505
  if (!!validationRes) return [3 /*break*/, 3];
474
506
  return [4 /*yield*/, dispatchEvent('validateError', this.props.data)];
475
507
  case 2:
476
- dispatcher = _c.sent();
508
+ dispatcher = _f.sent();
477
509
  if (!(dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented)) {
478
510
  env.notify('error', __('Form.validateFailed'));
479
511
  }
@@ -482,147 +514,158 @@ var Form = /** @class */ (function (_super) {
482
514
  case 3:
483
515
  /** 重置validated状态,保证submit时触发表单中的校验项 */
484
516
  store.clearErrors();
485
- _c.label = 4;
517
+ _f.label = 4;
486
518
  case 4:
487
- if (action.type === 'submit' ||
519
+ if (!(action.type === 'submit' ||
488
520
  action.actionType === 'submit' ||
489
521
  action.actionType === 'confirm' ||
490
522
  action.actionType === 'reset-and-submit' ||
491
- action.actionType === 'clear-and-submit') {
492
- store.setCurrentAction(action);
493
- if (action.actionType === 'reset-and-submit') {
494
- store.reset(this.handleReset(action));
495
- }
496
- else if (action.actionType === 'clear-and-submit') {
497
- store.clear(this.handleReset(action));
498
- }
499
- return [2 /*return*/, this.submit(function (values) {
500
- var _a;
501
- if (onSubmit && onSubmit(values, action) === false) {
502
- return Promise.resolve(false);
503
- }
504
- // 走到这里代表校验成功了
505
- dispatchEvent('validateSucc', _this.props.data);
506
- if (target) {
507
- _this.submitToTarget(filter(target, values), values);
508
- dispatchEvent('submitSucc', createObject(_this.props.data, values));
509
- }
510
- else if (action.actionType === 'reload') {
511
- action.target &&
512
- _this.reloadTarget(filter(action.target, values), values);
513
- }
514
- else if (action.actionType === 'dialog') {
515
- store.openDialog(data);
516
- }
517
- else if (action.actionType === 'drawer') {
518
- store.openDrawer(data);
519
- }
520
- else if (isEffectiveApi(action.api || api, values)) {
521
- var finnalAsyncApi_1 = action.asyncApi || asyncApi;
522
- isEffectiveApi(finnalAsyncApi_1, store.data) &&
523
- store.updateData((_a = {},
524
- _a[finishedField || 'finished'] = false,
525
- _a));
526
- return store
527
- .saveRemote(action.api || api, values, {
528
- successMessage: saveSuccess,
529
- errorMessage: saveFailed,
530
- onSuccess: function (result) { return __awaiter(_this, void 0, void 0, function () {
531
- var dispatcher, cbResult;
532
- var _this = this;
533
- return __generator(this, function (_a) {
534
- switch (_a.label) {
535
- case 0: return [4 /*yield*/, dispatchEvent('submitSucc', createObject(this.props.data, { result: result }))];
536
- case 1:
537
- dispatcher = _a.sent();
538
- if (!isEffectiveApi(finnalAsyncApi_1, store.data) ||
539
- store.data[finishedField || 'finished']) {
540
- return [2 /*return*/, {
541
- cbResult: null,
542
- dispatcher: dispatcher
543
- }];
544
- }
545
- cbResult = until(function () { return store.checkRemote(finnalAsyncApi_1, store.data); }, function (ret) { return ret && ret[finishedField || 'finished']; }, function (cancel) { return (_this.asyncCancel = cancel); }, checkInterval);
546
- return [2 /*return*/, {
547
- cbResult: cbResult,
548
- dispatcher: dispatcher
549
- }];
550
- }
551
- });
552
- }); },
553
- onFailed: function (result) { return __awaiter(_this, void 0, void 0, function () {
554
- var dispatcher;
555
- return __generator(this, function (_a) {
556
- switch (_a.label) {
557
- case 0: return [4 /*yield*/, dispatchEvent('submitFail', createObject(this.props.data, { error: result }))];
558
- case 1:
559
- dispatcher = _a.sent();
523
+ action.actionType === 'clear-and-submit')) return [3 /*break*/, 6];
524
+ _e = this.props, dispatchEvent_1 = _e.dispatchEvent, onEvent = _e.onEvent;
525
+ 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;
526
+ return [4 /*yield*/, dispatchEvent_1('submit', this.props.data)];
527
+ case 5:
528
+ dispatcher = _f.sent();
529
+ if ((dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented) || submitEvent) {
530
+ return [2 /*return*/];
531
+ }
532
+ store.setCurrentAction(action);
533
+ if (action.actionType === 'reset-and-submit') {
534
+ store.reset(this.handleReset(action));
535
+ }
536
+ else if (action.actionType === 'clear-and-submit') {
537
+ store.clear(this.handleReset(action));
538
+ }
539
+ return [2 /*return*/, this.submit(function (values) {
540
+ var _a;
541
+ if (onSubmit && onSubmit(values, action) === false) {
542
+ return Promise.resolve(false);
543
+ }
544
+ // 走到这里代表校验成功了
545
+ dispatchEvent_1('validateSucc', _this.props.data);
546
+ if (target) {
547
+ _this.submitToTarget(filterTarget(target, values), values);
548
+ dispatchEvent_1('submitSucc', createObject(_this.props.data, values));
549
+ }
550
+ else if (action.actionType === 'reload') {
551
+ action.target &&
552
+ _this.reloadTarget(filterTarget(action.target, values), values);
553
+ }
554
+ else if (action.actionType === 'dialog') {
555
+ store.openDialog(data);
556
+ }
557
+ else if (action.actionType === 'drawer') {
558
+ store.openDrawer(data);
559
+ }
560
+ else if (isEffectiveApi(action.api || api, values)) {
561
+ var finnalAsyncApi_1 = action.asyncApi || asyncApi;
562
+ isEffectiveApi(finnalAsyncApi_1, store.data) &&
563
+ store.updateData((_a = {},
564
+ _a[finishedField || 'finished'] = false,
565
+ _a));
566
+ return store
567
+ .saveRemote(action.api || api, values, {
568
+ successMessage: saveSuccess,
569
+ errorMessage: saveFailed,
570
+ onSuccess: function (result) { return __awaiter(_this, void 0, void 0, function () {
571
+ var dispatcher, cbResult;
572
+ var _this = this;
573
+ return __generator(this, function (_a) {
574
+ switch (_a.label) {
575
+ case 0: return [4 /*yield*/, dispatchEvent_1('submitSucc', createObject(this.props.data, { result: result }))];
576
+ case 1:
577
+ dispatcher = _a.sent();
578
+ if (!isEffectiveApi(finnalAsyncApi_1, store.data) ||
579
+ store.data[finishedField || 'finished']) {
560
580
  return [2 /*return*/, {
581
+ cbResult: null,
561
582
  dispatcher: dispatcher
562
583
  }];
563
- }
564
- });
565
- }); }
566
- })
567
- .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
568
- var feedback, confirmed;
584
+ }
585
+ cbResult = 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) {
586
+ // 派发asyncApiFinished事件
587
+ dispatchEvent_1('asyncApiFinished', store.data);
588
+ });
589
+ return [2 /*return*/, {
590
+ cbResult: cbResult,
591
+ dispatcher: dispatcher
592
+ }];
593
+ }
594
+ });
595
+ }); },
596
+ onFailed: function (result) { return __awaiter(_this, void 0, void 0, function () {
597
+ var dispatcher;
569
598
  return __generator(this, function (_a) {
570
599
  switch (_a.label) {
571
- case 0:
572
- onSaved && onSaved(values, response);
573
- feedback = action.feedback || this.props.feedback;
574
- if (!(feedback && isVisible(feedback, store.data))) return [3 /*break*/, 2];
575
- return [4 /*yield*/, this.openFeedback(feedback, store.data)];
600
+ case 0: return [4 /*yield*/, dispatchEvent_1('submitFail', createObject(this.props.data, { error: result }))];
576
601
  case 1:
577
- confirmed = _a.sent();
578
- // 如果 feedback 配置了,取消就跳过原有逻辑。
579
- if (feedback.skipRestOnCancel && !confirmed) {
580
- throw new SkipOperation();
581
- }
582
- else if (feedback.skipRestOnConfirm && confirmed) {
583
- throw new SkipOperation();
584
- }
585
- _a.label = 2;
586
- case 2: return [2 /*return*/];
602
+ dispatcher = _a.sent();
603
+ return [2 /*return*/, {
604
+ dispatcher: dispatcher
605
+ }];
587
606
  }
588
607
  });
589
- }); });
590
- }
591
- else {
592
- // type为submit,但是没有配api以及target时,只派发事件
593
- dispatchEvent('submitSucc', createObject(_this.props.data, values));
594
- }
595
- return Promise.resolve(null);
596
- })
597
- .then(function (values) {
598
- // 有可能 onSubmit return false 了,那么后面的就不应该再执行了。
599
- if (values === false) {
600
- return store.data;
601
- }
602
- if (onFinished && onFinished(values, action) === false) {
603
- return values;
604
- }
605
- resetAfterSubmit && store.reset(_this.handleReset(action));
606
- clearAfterSubmit && store.clear(_this.handleReset(action));
607
- clearPersistDataAfterSubmit && store.clearLocalPersistData();
608
- if (action.redirect || redirect) {
609
- var finalRedirect = filter(action.redirect || redirect, store.data);
610
- finalRedirect && env.jumpTo(finalRedirect, action);
611
- }
612
- else if (action.reload || reload) {
613
- _this.reloadTarget(filter(action.reload || reload, store.data), store.data);
614
- }
615
- action.close && _this.closeTarget(action.close);
608
+ }); }
609
+ })
610
+ .then(function (response) { return __awaiter(_this, void 0, void 0, function () {
611
+ var feedback, confirmed;
612
+ return __generator(this, function (_a) {
613
+ switch (_a.label) {
614
+ case 0:
615
+ onSaved && onSaved(values, response);
616
+ feedback = action.feedback || this.props.feedback;
617
+ if (!(feedback && isVisible(feedback, store.data))) return [3 /*break*/, 2];
618
+ return [4 /*yield*/, this.openFeedback(feedback, store.data)];
619
+ case 1:
620
+ confirmed = _a.sent();
621
+ // 如果 feedback 配置了,取消就跳过原有逻辑。
622
+ if (feedback.skipRestOnCancel && !confirmed) {
623
+ throw new SkipOperation();
624
+ }
625
+ else if (feedback.skipRestOnConfirm && confirmed) {
626
+ throw new SkipOperation();
627
+ }
628
+ _a.label = 2;
629
+ case 2: return [2 /*return*/];
630
+ }
631
+ });
632
+ }); });
633
+ }
634
+ else {
635
+ // type为submit,但是没有配api以及target时,只派发事件
636
+ dispatchEvent_1('submitSucc', createObject(_this.props.data, values));
637
+ }
638
+ return Promise.resolve(null);
639
+ })
640
+ .then(function (values) {
641
+ // 有可能 onSubmit return false 了,那么后面的就不应该再执行了。
642
+ if (values === false) {
643
+ return store.data;
644
+ }
645
+ if (onFinished && onFinished(values, action) === false) {
616
646
  return values;
617
- })
618
- .catch(function (reason) {
619
- onFailed && onFailed(reason, store.errors);
620
- if (throwErrors) {
621
- throw reason;
622
- }
623
- })];
624
- }
625
- else if (action.type === 'reset' || action.actionType === 'reset') {
647
+ }
648
+ resetAfterSubmit && store.reset(_this.handleReset(action));
649
+ clearAfterSubmit && store.clear(_this.handleReset(action));
650
+ clearPersistDataAfterSubmit && store.clearLocalPersistData();
651
+ if (action.redirect || redirect) {
652
+ var finalRedirect = filter(action.redirect || redirect, store.data);
653
+ finalRedirect && env.jumpTo(finalRedirect, action);
654
+ }
655
+ else if (action.reload || reload) {
656
+ _this.reloadTarget(filterTarget(action.reload || reload, store.data), store.data);
657
+ }
658
+ action.close && _this.closeTarget(action.close);
659
+ return values;
660
+ })
661
+ .catch(function (reason) {
662
+ onFailed && onFailed(reason, store.errors);
663
+ if (throwErrors) {
664
+ throw reason;
665
+ }
666
+ })];
667
+ case 6:
668
+ if (action.type === 'reset' || action.actionType === 'reset') {
626
669
  store.setCurrentAction(action);
627
670
  store.reset(onReset);
628
671
  }
@@ -675,7 +718,7 @@ var Form = /** @class */ (function (_super) {
675
718
  redirect = action.redirect && filter(action.redirect, store.data);
676
719
  redirect && env.jumpTo(redirect, action);
677
720
  action.reload &&
678
- this.reloadTarget(filter(action.reload, store.data), store.data);
721
+ this.reloadTarget(filterTarget(action.reload, store.data), store.data);
679
722
  action.close && this.closeTarget(action.close);
680
723
  return [2 /*return*/];
681
724
  }
@@ -691,18 +734,19 @@ var Form = /** @class */ (function (_super) {
691
734
  else if (action.actionType === 'reload') {
692
735
  store.setCurrentAction(action);
693
736
  if (action.target) {
694
- this.reloadTarget(filter(action.target, data), data);
737
+ this.reloadTarget(filterTarget(action.target, data), data);
695
738
  }
696
739
  else {
697
740
  this.receive(data);
698
741
  }
699
- // action.target && this.reloadTarget(action.target, data);
742
+ // action.target && this.reloadTarget(filterTarget(action.target, data), data);
700
743
  }
701
744
  else if (onAction) {
702
745
  // 不识别的丢给上层去处理。
703
746
  return [2 /*return*/, onAction(e, action, data, throwErrors, delegate || this.context)];
704
747
  }
705
- return [2 /*return*/];
748
+ _f.label = 7;
749
+ case 7: return [2 /*return*/];
706
750
  }
707
751
  });
708
752
  });
@@ -1050,33 +1094,25 @@ var FormRenderer = /** @class */ (function (_super) {
1050
1094
  return this.handleAction(undefined, action, data, throwErrors);
1051
1095
  };
1052
1096
  FormRenderer.prototype.handleAction = function (e, action, ctx, throwErrors, delegate) {
1053
- var _a, _b;
1054
1097
  if (throwErrors === void 0) { throwErrors = false; }
1055
1098
  return __awaiter(this, void 0, void 0, function () {
1056
- var _c, dispatchEvent, onEvent, submitEvent, dispatcher, scoped_1;
1057
- return __generator(this, function (_d) {
1058
- switch (_d.label) {
1059
- case 0:
1060
- _c = this.props, dispatchEvent = _c.dispatchEvent, onEvent = _c.onEvent;
1061
- 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;
1062
- return [4 /*yield*/, dispatchEvent('submit', this.props.data)];
1063
- case 1:
1064
- dispatcher = _d.sent();
1065
- if ((dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.prevented) || submitEvent) {
1066
- return [2 /*return*/];
1067
- }
1068
- if (action.target && action.actionType !== 'reload') {
1069
- scoped_1 = this.context;
1070
- return [2 /*return*/, Promise.all(action.target.split(',').map(function (name) {
1071
- var target = scoped_1.getComponentByName(name);
1072
- return (target &&
1073
- target.doAction &&
1074
- target.doAction(__assign(__assign({}, action), { target: undefined }), ctx, throwErrors));
1075
- }))];
1076
- }
1077
- else {
1078
- return [2 /*return*/, _super.prototype.handleAction.call(this, e, action, ctx, throwErrors, delegate)];
1079
- }
1099
+ var scoped_1;
1100
+ return __generator(this, function (_a) {
1101
+ // 禁用了不要做任何动作。@先注释掉,会引起其他问题
1102
+ // if (this.props.disabled) {
1103
+ // return;
1104
+ // }
1105
+ if (action.target && action.actionType !== 'reload') {
1106
+ scoped_1 = this.context;
1107
+ return [2 /*return*/, Promise.all(action.target.split(',').map(function (name) {
1108
+ var target = scoped_1.getComponentByName(name);
1109
+ return (target &&
1110
+ target.doAction &&
1111
+ target.doAction(__assign(__assign({}, action), { target: undefined }), ctx, throwErrors));
1112
+ }))];
1113
+ }
1114
+ else {
1115
+ return [2 /*return*/, _super.prototype.handleAction.call(this, e, action, ctx, throwErrors, delegate)];
1080
1116
  }
1081
1117
  });
1082
1118
  });