amis-core 2.8.0 → 3.0.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 (315) hide show
  1. package/esm/Root.d.ts +1 -1
  2. package/esm/Root.js +1 -1
  3. package/esm/RootRenderer.d.ts +1 -1
  4. package/esm/RootRenderer.js +21 -4
  5. package/esm/SchemaRenderer.d.ts +3 -1
  6. package/esm/SchemaRenderer.js +7 -5
  7. package/esm/Scoped.js +30 -2
  8. package/esm/WithRootStore.d.ts +4 -8
  9. package/esm/WithRootStore.js +1 -1
  10. package/esm/WithStore.js +1 -1
  11. package/esm/actions/Action.d.ts +2 -1
  12. package/esm/actions/Action.js +40 -12
  13. package/esm/actions/AjaxAction.js +1 -1
  14. package/esm/actions/BreakAction.js +1 -1
  15. package/esm/actions/BroadcastAction.js +1 -1
  16. package/esm/actions/CmptAction.js +1 -1
  17. package/esm/actions/ContinueAction.js +1 -1
  18. package/esm/actions/CopyAction.js +1 -1
  19. package/esm/actions/CustomAction.js +2 -1
  20. package/esm/actions/DialogAction.d.ts +1 -1
  21. package/esm/actions/DialogAction.js +12 -3
  22. package/esm/actions/DrawerAction.js +1 -1
  23. package/esm/actions/EmailAction.js +1 -1
  24. package/esm/actions/LinkAction.js +1 -1
  25. package/esm/actions/LoopAction.js +1 -1
  26. package/esm/actions/PageAction.js +1 -1
  27. package/esm/actions/ParallelAction.js +1 -1
  28. package/esm/actions/SwitchAction.js +18 -15
  29. package/esm/actions/ToastAction.js +1 -1
  30. package/esm/components/LazyComponent.d.ts +3 -3
  31. package/esm/components/LazyComponent.js +1 -1
  32. package/esm/components/Overlay.d.ts +2 -2
  33. package/esm/components/Overlay.js +2 -1
  34. package/esm/components/PopOver.d.ts +2 -4
  35. package/esm/components/PopOver.js +2 -1
  36. package/esm/env.d.ts +3 -7
  37. package/esm/env.js +1 -1
  38. package/esm/envOverwrite.js +1 -1
  39. package/esm/factory.d.ts +2 -1
  40. package/esm/factory.js +5 -3
  41. package/esm/index.d.ts +9 -5
  42. package/esm/index.js +12 -9
  43. package/esm/locale.d.ts +1 -3
  44. package/esm/locale.js +1 -1
  45. package/esm/renderers/Form.d.ts +1 -1
  46. package/esm/renderers/Form.js +17 -15
  47. package/esm/renderers/Item.d.ts +9 -15
  48. package/esm/renderers/Item.js +11 -7
  49. package/esm/renderers/Options.js +4 -3
  50. package/esm/renderers/Placeholder.js +1 -1
  51. package/esm/renderers/builtin.js +1 -1
  52. package/esm/renderers/register.js +1 -1
  53. package/esm/renderers/wrapControl.d.ts +4 -8
  54. package/esm/renderers/wrapControl.js +21 -30
  55. package/esm/store/app.d.ts +4 -2
  56. package/esm/store/app.js +1 -1
  57. package/esm/store/combo.d.ts +12 -6
  58. package/esm/store/combo.js +1 -1
  59. package/esm/store/crud.d.ts +5 -2
  60. package/esm/store/crud.js +46 -12
  61. package/esm/store/form.d.ts +4 -2
  62. package/esm/store/form.js +1 -1
  63. package/esm/store/formItem.js +6 -5
  64. package/esm/store/iRenderer.d.ts +5 -2
  65. package/esm/store/iRenderer.js +15 -3
  66. package/esm/store/index.js +1 -1
  67. package/esm/store/list.d.ts +4 -2
  68. package/esm/store/list.js +5 -5
  69. package/esm/store/manager.js +1 -1
  70. package/esm/store/modal.d.ts +4 -2
  71. package/esm/store/modal.js +1 -1
  72. package/esm/store/node.js +1 -1
  73. package/esm/store/pagination.d.ts +4 -2
  74. package/esm/store/pagination.js +2 -2
  75. package/esm/store/root.d.ts +4 -2
  76. package/esm/store/root.js +1 -1
  77. package/esm/store/service.d.ts +4 -2
  78. package/esm/store/service.js +1 -1
  79. package/esm/store/table.d.ts +36 -29
  80. package/esm/store/table.js +28 -5
  81. package/esm/store/table2.d.ts +9 -7
  82. package/esm/store/table2.js +23 -19
  83. package/esm/theme.d.ts +2 -4
  84. package/esm/theme.js +1 -1
  85. package/esm/types.d.ts +45 -2
  86. package/esm/utils/Animation.js +1 -1
  87. package/esm/utils/ColorScale.js +1 -1
  88. package/esm/utils/DataSchema.js +1 -1
  89. package/esm/utils/DataScope.js +1 -1
  90. package/esm/utils/RootClose.js +1 -1
  91. package/esm/utils/SimpleMap.js +1 -1
  92. package/esm/utils/api.js +11 -5
  93. package/esm/utils/attachmentAdpator.js +1 -1
  94. package/esm/utils/autobind.js +1 -1
  95. package/esm/utils/columnsSplit.js +1 -1
  96. package/esm/utils/dataMapping.js +1 -1
  97. package/esm/utils/date.js +1 -1
  98. package/esm/utils/debug.d.ts +1 -0
  99. package/esm/utils/debug.js +4 -4
  100. package/esm/utils/decodeEntity.js +1 -1
  101. package/esm/utils/dom.d.ts +2 -0
  102. package/esm/utils/dom.js +47 -10
  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.d.ts +1 -0
  109. package/esm/utils/formula.js +7 -3
  110. package/esm/utils/getVariable.js +1 -1
  111. package/esm/utils/grammar.js +1 -1
  112. package/esm/utils/handleAction.js +1 -1
  113. package/esm/utils/helper.d.ts +7 -0
  114. package/esm/utils/helper.js +28 -3
  115. package/esm/utils/highlight.js +1 -1
  116. package/esm/utils/icon.d.ts +6 -1
  117. package/esm/utils/icon.js +6 -1
  118. package/esm/utils/image.js +1 -1
  119. package/esm/utils/index.d.ts +2 -0
  120. package/esm/utils/isPureVariable.js +1 -1
  121. package/esm/utils/json-schema-2-amis-schema.js +1 -1
  122. package/esm/utils/keyToPath.js +1 -1
  123. package/esm/utils/makeSorter.js +1 -1
  124. package/esm/utils/normalizeLink.js +1 -1
  125. package/esm/utils/normalizeOptions.js +1 -1
  126. package/esm/utils/object.js +1 -1
  127. package/esm/utils/offset.js +1 -1
  128. package/esm/utils/offsetParent.js +1 -1
  129. package/esm/utils/optionValueCompare.js +7 -3
  130. package/esm/utils/position.js +1 -1
  131. package/esm/utils/prettyBytes.js +1 -1
  132. package/esm/utils/renderer-event.js +35 -32
  133. package/esm/utils/replaceText.js +1 -1
  134. package/esm/utils/resize-sensor.js +1 -1
  135. package/esm/utils/resolveCondition.d.ts +6 -0
  136. package/esm/utils/resolveCondition.js +321 -0
  137. package/esm/utils/resolveVariable.js +1 -1
  138. package/esm/utils/resolveVariableAndFilter.js +1 -1
  139. package/esm/utils/resolveVariableAndFilterForAsync.d.ts +6 -0
  140. package/esm/utils/resolveVariableAndFilterForAsync.js +63 -0
  141. package/esm/utils/scrollPosition.js +1 -1
  142. package/esm/utils/string2regExp.js +1 -1
  143. package/esm/utils/stripNumber.js +1 -1
  144. package/esm/utils/style-helper.d.ts +9 -4
  145. package/esm/utils/style-helper.js +81 -16
  146. package/esm/utils/style.js +2 -2
  147. package/esm/utils/toNumber.js +1 -1
  148. package/esm/utils/tokenize.d.ts +1 -0
  149. package/esm/utils/tokenize.js +34 -3
  150. package/esm/utils/tpl-builtin.d.ts +2 -1
  151. package/esm/utils/tpl-builtin.js +18 -3
  152. package/esm/utils/tpl-lodash.js +3 -2
  153. package/esm/utils/tpl.d.ts +9 -0
  154. package/esm/utils/tpl.js +45 -3
  155. package/esm/utils/uncontrollable.js +1 -1
  156. package/esm/utils/validations.d.ts +4 -1
  157. package/esm/utils/validations.js +27 -12
  158. package/lib/Root.d.ts +1 -1
  159. package/lib/Root.js +1 -1
  160. package/lib/RootRenderer.d.ts +1 -1
  161. package/lib/RootRenderer.js +21 -4
  162. package/lib/SchemaRenderer.d.ts +3 -1
  163. package/lib/SchemaRenderer.js +7 -4
  164. package/lib/Scoped.js +30 -2
  165. package/lib/WithRootStore.d.ts +4 -8
  166. package/lib/WithRootStore.js +1 -1
  167. package/lib/WithStore.js +1 -1
  168. package/lib/actions/Action.d.ts +2 -1
  169. package/lib/actions/Action.js +39 -11
  170. package/lib/actions/AjaxAction.js +1 -1
  171. package/lib/actions/BreakAction.js +1 -1
  172. package/lib/actions/BroadcastAction.js +1 -1
  173. package/lib/actions/CmptAction.js +1 -1
  174. package/lib/actions/ContinueAction.js +1 -1
  175. package/lib/actions/CopyAction.js +1 -1
  176. package/lib/actions/CustomAction.js +2 -1
  177. package/lib/actions/DialogAction.d.ts +1 -1
  178. package/lib/actions/DialogAction.js +12 -3
  179. package/lib/actions/DrawerAction.js +1 -1
  180. package/lib/actions/EmailAction.js +1 -1
  181. package/lib/actions/LinkAction.js +1 -1
  182. package/lib/actions/LoopAction.js +1 -1
  183. package/lib/actions/PageAction.js +1 -1
  184. package/lib/actions/ParallelAction.js +1 -1
  185. package/lib/actions/SwitchAction.js +17 -14
  186. package/lib/actions/ToastAction.js +1 -1
  187. package/lib/components/LazyComponent.d.ts +3 -3
  188. package/lib/components/LazyComponent.js +1 -1
  189. package/lib/components/Overlay.d.ts +2 -2
  190. package/lib/components/Overlay.js +2 -1
  191. package/lib/components/PopOver.d.ts +2 -4
  192. package/lib/components/PopOver.js +2 -1
  193. package/lib/env.d.ts +3 -7
  194. package/lib/env.js +1 -1
  195. package/lib/envOverwrite.js +1 -1
  196. package/lib/factory.d.ts +2 -1
  197. package/lib/factory.js +5 -3
  198. package/lib/index.d.ts +9 -5
  199. package/lib/index.js +30 -2
  200. package/lib/locale.d.ts +1 -3
  201. package/lib/locale.js +1 -1
  202. package/lib/renderers/Form.d.ts +1 -1
  203. package/lib/renderers/Form.js +16 -14
  204. package/lib/renderers/Item.d.ts +9 -15
  205. package/lib/renderers/Item.js +11 -7
  206. package/lib/renderers/Options.js +4 -3
  207. package/lib/renderers/Placeholder.js +1 -1
  208. package/lib/renderers/builtin.js +1 -1
  209. package/lib/renderers/register.js +1 -1
  210. package/lib/renderers/wrapControl.d.ts +4 -8
  211. package/lib/renderers/wrapControl.js +20 -28
  212. package/lib/store/app.d.ts +4 -2
  213. package/lib/store/app.js +1 -1
  214. package/lib/store/combo.d.ts +12 -6
  215. package/lib/store/combo.js +1 -1
  216. package/lib/store/crud.d.ts +5 -2
  217. package/lib/store/crud.js +45 -11
  218. package/lib/store/form.d.ts +4 -2
  219. package/lib/store/form.js +1 -1
  220. package/lib/store/formItem.js +6 -5
  221. package/lib/store/iRenderer.d.ts +5 -2
  222. package/lib/store/iRenderer.js +15 -3
  223. package/lib/store/index.js +1 -1
  224. package/lib/store/list.d.ts +4 -2
  225. package/lib/store/list.js +5 -5
  226. package/lib/store/manager.js +1 -1
  227. package/lib/store/modal.d.ts +4 -2
  228. package/lib/store/modal.js +1 -1
  229. package/lib/store/node.js +1 -1
  230. package/lib/store/pagination.d.ts +4 -2
  231. package/lib/store/pagination.js +2 -2
  232. package/lib/store/root.d.ts +4 -2
  233. package/lib/store/root.js +1 -1
  234. package/lib/store/service.d.ts +4 -2
  235. package/lib/store/service.js +1 -1
  236. package/lib/store/table.d.ts +36 -29
  237. package/lib/store/table.js +28 -5
  238. package/lib/store/table2.d.ts +9 -7
  239. package/lib/store/table2.js +23 -19
  240. package/lib/theme.d.ts +2 -4
  241. package/lib/theme.js +1 -1
  242. package/lib/types.d.ts +45 -2
  243. package/lib/utils/Animation.js +1 -1
  244. package/lib/utils/ColorScale.js +1 -1
  245. package/lib/utils/DataSchema.js +1 -1
  246. package/lib/utils/DataScope.js +1 -1
  247. package/lib/utils/RootClose.js +1 -1
  248. package/lib/utils/SimpleMap.js +1 -1
  249. package/lib/utils/api.js +10 -4
  250. package/lib/utils/attachmentAdpator.js +1 -1
  251. package/lib/utils/autobind.js +1 -1
  252. package/lib/utils/columnsSplit.js +1 -1
  253. package/lib/utils/dataMapping.js +1 -1
  254. package/lib/utils/date.js +1 -1
  255. package/lib/utils/debug.d.ts +1 -0
  256. package/lib/utils/debug.js +4 -4
  257. package/lib/utils/decodeEntity.js +1 -1
  258. package/lib/utils/dom.d.ts +2 -0
  259. package/lib/utils/dom.js +48 -9
  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 +1 -0
  266. package/lib/utils/formula.js +7 -2
  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 +7 -0
  271. package/lib/utils/helper.js +29 -2
  272. package/lib/utils/highlight.js +1 -1
  273. package/lib/utils/icon.d.ts +6 -1
  274. package/lib/utils/icon.js +6 -1
  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/normalizeLink.js +1 -1
  282. package/lib/utils/normalizeOptions.js +1 -1
  283. package/lib/utils/object.js +1 -1
  284. package/lib/utils/offset.js +1 -1
  285. package/lib/utils/offsetParent.js +1 -1
  286. package/lib/utils/optionValueCompare.js +7 -3
  287. package/lib/utils/position.js +1 -1
  288. package/lib/utils/prettyBytes.js +1 -1
  289. package/lib/utils/renderer-event.js +35 -32
  290. package/lib/utils/replaceText.js +1 -1
  291. package/lib/utils/resize-sensor.js +1 -1
  292. package/lib/utils/resolveCondition.d.ts +6 -0
  293. package/lib/utils/resolveCondition.js +338 -0
  294. package/lib/utils/resolveVariable.js +1 -1
  295. package/lib/utils/resolveVariableAndFilter.js +1 -1
  296. package/lib/utils/resolveVariableAndFilterForAsync.d.ts +6 -0
  297. package/lib/utils/resolveVariableAndFilterForAsync.js +68 -0
  298. package/lib/utils/scrollPosition.js +1 -1
  299. package/lib/utils/string2regExp.js +1 -1
  300. package/lib/utils/stripNumber.js +1 -1
  301. package/lib/utils/style-helper.d.ts +9 -4
  302. package/lib/utils/style-helper.js +86 -15
  303. package/lib/utils/style.js +2 -2
  304. package/lib/utils/toNumber.js +1 -1
  305. package/lib/utils/tokenize.d.ts +1 -0
  306. package/lib/utils/tokenize.js +33 -1
  307. package/lib/utils/tpl-builtin.d.ts +2 -1
  308. package/lib/utils/tpl-builtin.js +17 -2
  309. package/lib/utils/tpl-lodash.js +3 -2
  310. package/lib/utils/tpl.d.ts +9 -0
  311. package/lib/utils/tpl.js +45 -1
  312. package/lib/utils/uncontrollable.js +1 -1
  313. package/lib/utils/validations.d.ts +4 -1
  314. package/lib/utils/validations.js +27 -12
  315. package/package.json +5 -5
@@ -1,10 +1,11 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
6
  import { __values } from 'tslib';
7
7
  import { uuid } from './helper.js';
8
+ import cloneDeep from 'lodash/cloneDeep';
8
9
 
9
10
  var valueMap = {
10
11
  'marginTop': 'margin-top',
@@ -31,6 +32,10 @@ var valueMap = {
31
32
  'fontWeight': 'font-weight',
32
33
  'lineHeight': 'line-height'
33
34
  };
35
+ var inheritValueMap = {
36
+ background: 'bg-color',
37
+ radius: 'border'
38
+ };
34
39
  function findOrCreactStyle(id) {
35
40
  var varStyleTag = document.getElementById(id);
36
41
  if (!varStyleTag) {
@@ -50,10 +55,47 @@ function addStyle(style, id) {
50
55
  // bca-disable-line
51
56
  varStyleTag.innerHTML += style;
52
57
  }
53
- function formatStyle(css, classNames, id) {
58
+ // 继承数据处理
59
+ function handleInheritData(statusMap, data) {
60
+ if (!data) {
61
+ return;
62
+ }
63
+ // 检查是否存在inherit
64
+ ['hover', 'active'].forEach(function (status) {
65
+ for (var key in statusMap[status]) {
66
+ if (typeof statusMap[status][key] === 'object') {
67
+ for (var style in statusMap[status][key]) {
68
+ if (statusMap[status][key][style] === 'inherit') {
69
+ // 值为inherit时设置为default的值或者主题中的default值
70
+ if (statusMap['default'][key] && statusMap['default'][key][style]) {
71
+ statusMap[status][key][style] = statusMap.default[key][style];
72
+ }
73
+ else {
74
+ var value = inheritValueMap[key] || key;
75
+ statusMap[status][key][style] =
76
+ data['default'].body[value][style];
77
+ }
78
+ }
79
+ }
80
+ }
81
+ else {
82
+ if (statusMap[status][key] === 'inherit') {
83
+ if (statusMap['default'][key] && statusMap['default'][key]) {
84
+ statusMap[status][key] = statusMap.default[key];
85
+ }
86
+ else {
87
+ var value = inheritValueMap[key] || key;
88
+ statusMap[status][key] = data['default'].body[value];
89
+ }
90
+ }
91
+ }
92
+ }
93
+ });
94
+ }
95
+ function formatStyle(themeCss, classNames, id, defaultData) {
54
96
  var e_1, _a;
55
97
  var _b;
56
- if (!css) {
98
+ if (!themeCss) {
57
99
  return { value: '', origin: [] };
58
100
  }
59
101
  var res = [];
@@ -65,7 +107,7 @@ function formatStyle(css, classNames, id) {
65
107
  };
66
108
  var _loop_1 = function (item) {
67
109
  var e_2, _c;
68
- var body = css[item.key];
110
+ var body = themeCss[item.key];
69
111
  var list = (_b = item.value) === null || _b === void 0 ? void 0 : _b.split(' ');
70
112
  var classNameList = [];
71
113
  if (!body) {
@@ -73,7 +115,7 @@ function formatStyle(css, classNames, id) {
73
115
  }
74
116
  list === null || list === void 0 ? void 0 : list.forEach(function (n) {
75
117
  if (/(\S*[C|c]lassName-\S*)/.test(n) &&
76
- !!~n.indexOf((id === null || id === void 0 ? void 0 : id.replace('u:', '').replace('-label', '').replace('-description', '').replace('-addOn', '')) || '')) {
118
+ !!~n.indexOf((id === null || id === void 0 ? void 0 : id.replace('u:', '').replace('-label', '').replace('-description', '').replace('-addOn', '').replace('-icon', '')) || '')) {
77
119
  classNameList.push(n);
78
120
  }
79
121
  });
@@ -108,6 +150,7 @@ function formatStyle(css, classNames, id) {
108
150
  statusMap.default[key] = body[key];
109
151
  }
110
152
  }
153
+ handleInheritData(statusMap, defaultData);
111
154
  var _loop_2 = function (status_1) {
112
155
  var weights = weightsList[status_1];
113
156
  var styles = [];
@@ -151,12 +194,13 @@ function formatStyle(css, classNames, id) {
151
194
  className: cx + status2string[status_1],
152
195
  content: ".".concat(cx + status2string[status_1], " {\n ").concat(styles.join('\n '), "\n}")
153
196
  });
154
- if (['hover', 'active', 'disabled'].includes(status_1)) {
155
- res.push({
156
- className: cx + '.' + status_1,
157
- content: ".".concat(cx, ".").concat(status_1, " {\n ").concat(styles.join('\n '), "\n}")
158
- });
159
- }
197
+ // TODO:切换状态暂时先不改变组件的样式
198
+ // if (['hover', 'active', 'disabled'].includes(status)) {
199
+ // res.push({
200
+ // className: cx + '.' + status,
201
+ // content: `.${cx}.${status} {\n ${styles.join('\n ')}\n}`
202
+ // });
203
+ // }
160
204
  }
161
205
  };
162
206
  for (var status_1 in statusMap) {
@@ -190,12 +234,33 @@ function formatStyle(css, classNames, id) {
190
234
  origin: res
191
235
  };
192
236
  }
193
- function insertCustomStyle(css, classNames, id) {
194
- if (!css) {
237
+ function insertCustomStyle(themeCss, classNames, id, defaultData) {
238
+ if (!themeCss) {
195
239
  return;
196
240
  }
197
- var value = formatStyle(css, classNames, id).value;
198
- insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || uuid());
241
+ var value = formatStyle(themeCss, classNames, id, defaultData).value;
242
+ if (value) {
243
+ insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || uuid());
244
+ }
245
+ }
246
+ /**
247
+ * 根据路径获取默认值
248
+ */
249
+ function getValueByPath(path, data) {
250
+ try {
251
+ if (!path || !data) {
252
+ return null;
253
+ }
254
+ var keys = path.split('.');
255
+ var value = cloneDeep(data.component);
256
+ for (var i = 0; i < keys.length; i++) {
257
+ value = value[keys[i]];
258
+ }
259
+ return value;
260
+ }
261
+ catch (e) {
262
+ return null;
263
+ }
199
264
  }
200
265
 
201
- export { addStyle, findOrCreactStyle, formatStyle, insertCustomStyle, insertStyle, valueMap };
266
+ export { addStyle, findOrCreactStyle, formatStyle, getValueByPath, inheritValueMap, insertCustomStyle, insertStyle, valueMap };
@@ -1,11 +1,11 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
+ import 'tslib';
6
7
  import 'amis-formula';
7
8
  import 'moment';
8
- import 'tslib';
9
9
  import 'lodash/isPlainObject';
10
10
  import { resolveVariableAndFilter } from './resolveVariableAndFilter.js';
11
11
  import './filter.js';
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1 +1,2 @@
1
1
  export declare const tokenize: (str: string, data: object, defaultFilter?: string) => string;
2
+ export declare const asyncTokenize: (str: string, data: object, defaultFilter?: string) => Promise<string>;
@@ -1,9 +1,10 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
- import { parse, Evaluator } from 'amis-formula';
6
+ import { __awaiter, __generator } from 'tslib';
7
+ import { parse, Evaluator, evaluateForAsync } from 'amis-formula';
7
8
 
8
9
  var tokenize = function (str, data, defaultFilter) {
9
10
  if (defaultFilter === void 0) { defaultFilter = '| html'; }
@@ -25,5 +26,35 @@ var tokenize = function (str, data, defaultFilter) {
25
26
  return str;
26
27
  }
27
28
  };
29
+ var asyncTokenize = function (str, data, defaultFilter) {
30
+ if (defaultFilter === void 0) { defaultFilter = '| html'; }
31
+ return __awaiter(void 0, void 0, void 0, function () {
32
+ var ast, result, e_1;
33
+ return __generator(this, function (_a) {
34
+ switch (_a.label) {
35
+ case 0:
36
+ if (!str || typeof str !== 'string') {
37
+ return [2 /*return*/, str];
38
+ }
39
+ _a.label = 1;
40
+ case 1:
41
+ _a.trys.push([1, 3, , 4]);
42
+ ast = parse(str, {
43
+ evalMode: false,
44
+ allowFilter: true
45
+ });
46
+ return [4 /*yield*/, evaluateForAsync(ast, data, { defaultFilter: defaultFilter })];
47
+ case 2:
48
+ result = _a.sent();
49
+ return [2 /*return*/, "".concat(result == null ? '' : result)];
50
+ case 3:
51
+ e_1 = _a.sent();
52
+ console.warn(e_1);
53
+ return [2 /*return*/, str];
54
+ case 4: return [2 /*return*/];
55
+ }
56
+ });
57
+ });
58
+ };
28
59
 
29
- export { tokenize };
60
+ export { asyncTokenize, tokenize };
@@ -10,9 +10,10 @@ import { stripNumber } from './stripNumber';
10
10
  import { tokenize } from './tokenize';
11
11
  import { resolveVariable } from './resolveVariable';
12
12
  import { resolveVariableAndFilter } from './resolveVariableAndFilter';
13
+ import { resolveVariableAndFilterForAsync } from './resolveVariableAndFilterForAsync';
13
14
  import { dataMapping, resolveMapping, resolveMappingObject } from './dataMapping';
14
15
  import './filter';
15
- export { prettyBytes, escapeHtml, formatDuration, filterDate, relativeValueRe, parseDuration, getFilters, registerFilter, registerFunction, pickValues, isPureVariable, stripNumber, tokenize, resolveVariable, resolveVariableAndFilter, resolveMapping, resolveMappingObject, dataMapping };
16
+ export { prettyBytes, escapeHtml, formatDuration, filterDate, relativeValueRe, parseDuration, getFilters, registerFilter, registerFunction, pickValues, isPureVariable, stripNumber, tokenize, resolveVariable, resolveVariableAndFilter, resolveVariableAndFilterForAsync, resolveMapping, resolveMappingObject, dataMapping };
16
17
  export declare function register(): Enginer & {
17
18
  name: string;
18
19
  };
@@ -1,13 +1,13 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
+ import { __awaiter, __generator } from 'tslib';
6
7
  export { getFilters, registerFilter, registerFunction } from 'amis-formula';
7
8
  import 'moment';
8
- import 'tslib';
9
9
  import 'lodash/isPlainObject';
10
- import { tokenize } from './tokenize.js';
10
+ import { tokenize, asyncTokenize } from './tokenize.js';
11
11
  export { tokenize } from './tokenize.js';
12
12
  import './filter.js';
13
13
 
@@ -38,6 +38,7 @@ function matchSynatax(str) {
38
38
  return false;
39
39
  }
40
40
  function register() {
41
+ var _this = this;
41
42
  return {
42
43
  name: 'builtin',
43
44
  test: function (str) { return typeof str === 'string' && matchSynatax(str); },
@@ -52,6 +53,20 @@ function register() {
52
53
  catch (e) {
53
54
  return "error: ".concat(e.message);
54
55
  }
56
+ },
57
+ asyncCompile: function (str, data, defaultFilter) {
58
+ if (defaultFilter === void 0) { defaultFilter = '| html'; }
59
+ return __awaiter(_this, void 0, void 0, function () {
60
+ return __generator(this, function (_a) {
61
+ try {
62
+ return [2 /*return*/, asyncTokenize(str, data, defaultFilter)];
63
+ }
64
+ catch (e) {
65
+ return [2 /*return*/, "error: ".concat(e.message)];
66
+ }
67
+ return [2 /*return*/];
68
+ });
69
+ });
55
70
  }
56
71
  };
57
72
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -55,7 +55,8 @@ function register() {
55
55
  return {
56
56
  name: 'lodash',
57
57
  test: function (str) { return !!~str.indexOf('<%'); },
58
- compile: function (str, data) { return lodashCompile(str, data); }
58
+ compile: function (str, data) { return lodashCompile(str, data); },
59
+ asyncCompile: function (str, data) { return lodashCompile(str, data); }
59
60
  };
60
61
  }
61
62
 
@@ -2,10 +2,19 @@ export interface Enginer {
2
2
  test: (tpl: string) => boolean;
3
3
  removeEscapeToken?: (tpl: string) => string;
4
4
  compile: (tpl: string, data: object, ...rest: Array<any>) => string;
5
+ asyncCompile: (tpl: string, data: object, ...rest: Array<any>) => Promise<string>;
5
6
  }
6
7
  export declare function registerTplEnginer(name: string, enginer: Enginer): void;
7
8
  export declare function filter(tpl?: any, data?: object, ...rest: Array<any>): string;
9
+ export declare function asyncFilter(tpl?: any, data?: object, ...rest: Array<any>): Promise<string>;
8
10
  export declare function setCustomEvalExpression(fn: (expression: string, data?: any) => boolean): void;
9
11
  export declare function evalExpression(expression: string, data?: object): boolean;
12
+ /**
13
+ * 解析表达式(支持condition-builder)
14
+ * @param expression 表达式 or condition-builder对象
15
+ * @param data 上下文
16
+ * @returns
17
+ */
18
+ export declare function evalExpressionWithConditionBuilder(expression: any, data?: object, defaultResult?: boolean): Promise<boolean>;
10
19
  export declare function setCustomEvalJs(fn: (expression: string, data?: any) => any): void;
11
20
  export declare function evalJS(js: string, data: object): any;
package/esm/utils/tpl.js CHANGED
@@ -1,12 +1,13 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
- import { __spreadArray, __read } from 'tslib';
6
+ import { __spreadArray, __read, __awaiter, __generator } from 'tslib';
7
7
  import { register } from './tpl-builtin.js';
8
8
  import { register as register$1 } from './tpl-lodash.js';
9
9
  import { getFilters, parse, evaluate } from 'amis-formula';
10
+ import { resolveCondition } from './resolveCondition.js';
10
11
 
11
12
  var enginers = {};
12
13
  function registerTplEnginer(name, enginer) {
@@ -33,6 +34,27 @@ function filter(tpl, data) {
33
34
  }
34
35
  return tpl;
35
36
  }
37
+ function asyncFilter(tpl, data) {
38
+ if (data === void 0) { data = {}; }
39
+ var rest = [];
40
+ for (var _i = 2; _i < arguments.length; _i++) {
41
+ rest[_i - 2] = arguments[_i];
42
+ }
43
+ if (!tpl || typeof tpl !== 'string') {
44
+ return Promise.resolve('');
45
+ }
46
+ var keys = Object.keys(enginers);
47
+ for (var i = 0, len = keys.length; i < len; i++) {
48
+ var enginer = enginers[keys[i]];
49
+ if (enginer.test(tpl)) {
50
+ return enginer.asyncCompile.apply(enginer, __spreadArray([tpl, data], __read(rest), false));
51
+ }
52
+ else if (enginer.removeEscapeToken) {
53
+ tpl = enginer.removeEscapeToken(tpl);
54
+ }
55
+ }
56
+ return tpl;
57
+ }
36
58
  // 缓存一下提升性能
37
59
  var EVAL_CACHE = {};
38
60
  var customEvalExpressionFn;
@@ -79,6 +101,25 @@ function evalExpression(expression, data) {
79
101
  return false;
80
102
  }
81
103
  }
104
+ /**
105
+ * 解析表达式(支持condition-builder)
106
+ * @param expression 表达式 or condition-builder对象
107
+ * @param data 上下文
108
+ * @returns
109
+ */
110
+ function evalExpressionWithConditionBuilder(expression, data, defaultResult) {
111
+ return __awaiter(this, void 0, void 0, function () {
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ if (!(Object.prototype.toString.call(expression) === '[object Object]')) return [3 /*break*/, 2];
116
+ return [4 /*yield*/, resolveCondition(expression, data, defaultResult)];
117
+ case 1: return [2 /*return*/, _a.sent()];
118
+ case 2: return [2 /*return*/, evalExpression(String(expression), data)];
119
+ }
120
+ });
121
+ });
122
+ }
82
123
  var AST_CACHE = {};
83
124
  function evalFormula(expression, data) {
84
125
  var ast = AST_CACHE[expression] ||
@@ -124,8 +165,9 @@ function evalJS(js, data) {
124
165
  registerTplEnginer(info.name, {
125
166
  test: info.test,
126
167
  compile: info.compile,
168
+ asyncCompile: info.asyncCompile,
127
169
  removeEscapeToken: info.removeEscapeToken
128
170
  });
129
171
  });
130
172
 
131
- export { evalExpression, evalJS, filter, registerTplEnginer, setCustomEvalExpression, setCustomEvalJs };
173
+ export { asyncFilter, evalExpression, evalExpressionWithConditionBuilder, evalJS, filter, registerTplEnginer, setCustomEvalExpression, setCustomEvalJs };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,7 +1,10 @@
1
1
  export interface ValidateFn {
2
2
  (values: {
3
3
  [propsName: string]: any;
4
- }, value: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any): boolean;
4
+ }, value: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any): boolean | {
5
+ error: boolean;
6
+ msg?: string;
7
+ };
5
8
  }
6
9
  export declare const validations: {
7
10
  [propsName: string]: ValidateFn;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -348,12 +348,16 @@ var validateMessages = {
348
348
  isVariableName: 'validate.isVariableName'
349
349
  };
350
350
  function validate(value, values, rules, messages, __) {
351
+ var _a;
351
352
  if (__ === void 0) { __ = function (str) { return str; }; }
352
353
  var errors = [];
353
- rules &&
354
- Object.keys(rules).forEach(function (ruleName) {
354
+ if (rules) {
355
+ var ruleNames = Object.keys(rules);
356
+ var length_1 = ruleNames.length;
357
+ for (var index = 0; index < length_1; index++) {
358
+ var ruleName = ruleNames[index];
355
359
  if (!rules[ruleName] && rules[ruleName] !== 0) {
356
- return;
360
+ continue;
357
361
  }
358
362
  else if (typeof validations[ruleName] !== 'function') {
359
363
  throw new Error('Validation `' + ruleName + '` not exists!');
@@ -365,19 +369,30 @@ function validate(value, values, rules, messages, __) {
365
369
  }
366
370
  return item;
367
371
  });
368
- if (!fn.apply(void 0, __spreadArray([values, value], __read(args), false))) {
372
+ var validateRes = fn.apply(void 0, __spreadArray([values, value], __read(args), false));
373
+ // addRule 允许返回
374
+ // {error: true, msg: '错误提示'}
375
+ // 格式的信息来灵活展示错误
376
+ var fnResErrorMsg = '';
377
+ if (typeof validateRes === 'object' &&
378
+ validateRes.error === true) {
379
+ fnResErrorMsg = (_a = validateRes === null || validateRes === void 0 ? void 0 : validateRes.msg) !== null && _a !== void 0 ? _a : '';
380
+ }
381
+ if (!validateRes || fnResErrorMsg) {
369
382
  var msgRuleName = ruleName;
370
383
  if (Array.isArray(value)) {
371
384
  msgRuleName = "".concat(ruleName, "Array");
372
385
  }
373
- errors.push({
374
- rule: ruleName,
375
- msg: filter(__((messages && messages[ruleName]) ||
376
- validateMessages[msgRuleName] ||
377
- validateMessages[ruleName]), __assign({}, [''].concat(args)))
378
- });
386
+ return [{
387
+ rule: ruleName,
388
+ msg: filter(__((messages && messages[ruleName]) ||
389
+ fnResErrorMsg ||
390
+ validateMessages[msgRuleName] ||
391
+ validateMessages[ruleName]), __assign({}, [''].concat(args)))
392
+ }];
379
393
  }
380
- });
394
+ }
395
+ }
381
396
  return errors;
382
397
  }
383
398
  function validateObject(values, rules, messages, __) {
package/lib/Root.d.ts CHANGED
@@ -21,7 +21,7 @@ export interface RootProps {
21
21
  }
22
22
  export interface RootWrapperProps {
23
23
  env: RendererEnv;
24
- children: React.ReactNode;
24
+ children: React.ReactNode | Array<React.ReactNode>;
25
25
  schema: SchemaNode;
26
26
  rootStore: IRendererStore;
27
27
  theme: string;
package/lib/Root.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -23,5 +23,5 @@ export declare class RootRenderer extends React.Component<RootRendererProps> {
23
23
  handleDrawerClose(): void;
24
24
  openFeedback(dialog: any, ctx: any): Promise<unknown>;
25
25
  reloadTarget(scoped: IScopedContext, target: string, data?: any): void;
26
- render(): React.ReactNode;
26
+ render(): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
27
27
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -122,11 +122,11 @@ var RootRenderer = /** @class */ (function (_super) {
122
122
  }
123
123
  else if (action.actionType === 'dialog') {
124
124
  store.setCurrentAction(action);
125
- store.openDialog(ctx);
125
+ store.openDialog(ctx, undefined, undefined, delegate);
126
126
  }
127
127
  else if (action.actionType === 'drawer') {
128
128
  store.setCurrentAction(action);
129
- store.openDrawer(ctx);
129
+ store.openDrawer(ctx, undefined, undefined, delegate);
130
130
  }
131
131
  else if (action.actionType === 'toast') {
132
132
  (_b = (_a = action.toast) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.forEach(function (item) {
@@ -160,7 +160,7 @@ var RootRenderer = /** @class */ (function (_super) {
160
160
  redirect = action.redirect && tpl.filter(action.redirect, store.data);
161
161
  redirect && env.jumpTo(redirect, action);
162
162
  action.reload &&
163
- this.reloadTarget(delegate || this.context, action.reload, store.data);
163
+ this.reloadTarget(delegate || this.context, tpl.filter(action.reload, ctx), store.data);
164
164
  return [2 /*return*/];
165
165
  }
166
166
  });
@@ -192,6 +192,7 @@ var RootRenderer = /** @class */ (function (_super) {
192
192
  }
193
193
  };
194
194
  RootRenderer.prototype.handleDialogConfirm = function (values, action) {
195
+ var _a;
195
196
  var args = [];
196
197
  for (var _i = 2; _i < arguments.length; _i++) {
197
198
  args[_i - 2] = arguments[_i];
@@ -206,7 +207,13 @@ var RootRenderer = /** @class */ (function (_super) {
206
207
  dialog.onConfirm.apply(dialog, tslib.__spreadArray([values, action], tslib.__read(args), false)) === false) {
207
208
  return;
208
209
  }
210
+ var dialogAction = store.action;
211
+ var reload = (_a = action.reload) !== null && _a !== void 0 ? _a : dialogAction.reload;
212
+ var scoped = store.getDialogScoped() || this.context;
209
213
  store.closeDialog(true);
214
+ if (reload) {
215
+ scoped.reload(reload, store.data);
216
+ }
210
217
  };
211
218
  RootRenderer.prototype.handleDialogClose = function (confirmed) {
212
219
  if (confirmed === void 0) { confirmed = false; }
@@ -214,6 +221,7 @@ var RootRenderer = /** @class */ (function (_super) {
214
221
  store.closeDialog(confirmed);
215
222
  };
216
223
  RootRenderer.prototype.handleDrawerConfirm = function (values, action) {
224
+ var _a;
217
225
  var args = [];
218
226
  for (var _i = 2; _i < arguments.length; _i++) {
219
227
  args[_i - 2] = arguments[_i];
@@ -228,7 +236,16 @@ var RootRenderer = /** @class */ (function (_super) {
228
236
  drawer.onConfirm.apply(drawer, tslib.__spreadArray([values, action], tslib.__read(args), false)) === false) {
229
237
  return;
230
238
  }
239
+ var drawerAction = store.action;
240
+ var reload = (_a = action.reload) !== null && _a !== void 0 ? _a : drawerAction.reload;
241
+ var scoped = store.getDrawerScoped() || this.context;
231
242
  store.closeDrawer();
243
+ // 稍等会,等动画结束。
244
+ setTimeout(function () {
245
+ if (reload) {
246
+ scoped.reload(reload, store.data);
247
+ }
248
+ }, 300);
232
249
  };
233
250
  RootRenderer.prototype.handleDrawerClose = function () {
234
251
  var store = this.store;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { RendererConfig, RendererEnv, RendererProps } from './factory';
3
+ import { IScopedContext } from './Scoped';
3
4
  import { Schema, SchemaNode } from './types';
4
5
  import { RendererEvent } from './utils/renderer-event';
5
6
  interface SchemaRendererProps extends Partial<RendererProps> {
@@ -7,9 +8,10 @@ interface SchemaRendererProps extends Partial<RendererProps> {
7
8
  $path: string;
8
9
  env: RendererEnv;
9
10
  }
11
+ export declare const RENDERER_TRANSMISSION_OMIT_PROPS: string[];
10
12
  export declare class SchemaRenderer extends React.Component<SchemaRendererProps, any> {
11
13
  static displayName: string;
12
- static contextType: React.Context<import("./Scoped").IScopedContext>;
14
+ static contextType: React.Context<IScopedContext>;
13
15
  rendererKey: string;
14
16
  renderer: RendererConfig | null;
15
17
  ref: any;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v2.8.0
2
+ * amis-core v3.0.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -35,7 +35,7 @@ var difference__default = /*#__PURE__*/_interopDefaultLegacy(difference);
35
35
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
36
36
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
37
37
 
38
- var defaultOmitList = [
38
+ var RENDERER_TRANSMISSION_OMIT_PROPS = [
39
39
  'type',
40
40
  'name',
41
41
  '$ref',
@@ -60,7 +60,9 @@ var defaultOmitList = [
60
60
  'mode',
61
61
  'body',
62
62
  'id',
63
- 'inputOnly'
63
+ 'inputOnly',
64
+ 'label',
65
+ 'renderLabel'
64
66
  ];
65
67
  var componentCache = new SimpleMap.SimpleMap();
66
68
  var SchemaRenderer = /** @class */ (function (_super) {
@@ -178,7 +180,7 @@ var SchemaRenderer = /** @class */ (function (_super) {
178
180
  if (subProps === void 0) { subProps = {}; }
179
181
  var _a = this.props; _a.schema; _a.$path; var env = _a.env, render = _a.render, rest = tslib.__rest(_a, ["schema", "$path", "env", "render"]);
180
182
  var $path = this.resolveRenderer(this.props).path;
181
- var omitList = defaultOmitList.concat();
183
+ var omitList = RENDERER_TRANSMISSION_OMIT_PROPS.concat();
182
184
  if (this.renderer) {
183
185
  var Component = this.renderer.component;
184
186
  Component.propsList &&
@@ -351,4 +353,5 @@ var PlaceholderComponent = /** @class */ (function (_super) {
351
353
  return PlaceholderComponent;
352
354
  }(React__default["default"].Component));
353
355
 
356
+ exports.RENDERER_TRANSMISSION_OMIT_PROPS = RENDERER_TRANSMISSION_OMIT_PROPS;
354
357
  exports.SchemaRenderer = SchemaRenderer;