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
 
@@ -15,9 +15,11 @@ import capitalize from 'lodash/capitalize';
15
15
 
16
16
  var conditionResolverMap = {};
17
17
  var DEFAULT_RESULT = true;
18
+ var conditionComputeErrorHandler;
18
19
  function resolveCondition(conditions, data, defaultResult) {
19
20
  if (defaultResult === void 0) { defaultResult = true; }
20
21
  return __awaiter(this, void 0, void 0, function () {
22
+ var e_1;
21
23
  return __generator(this, function (_a) {
22
24
  switch (_a.label) {
23
25
  case 0:
@@ -27,8 +29,18 @@ function resolveCondition(conditions, data, defaultResult) {
27
29
  !conditions.children.length) {
28
30
  return [2 /*return*/, defaultResult];
29
31
  }
32
+ _a.label = 1;
33
+ case 1:
34
+ _a.trys.push([1, 3, , 6]);
30
35
  return [4 /*yield*/, computeConditions(conditions.children, conditions.conjunction, data)];
31
- case 1: return [2 /*return*/, _a.sent()];
36
+ case 2: return [2 /*return*/, _a.sent()];
37
+ case 3:
38
+ e_1 = _a.sent();
39
+ if (!(e_1.name === 'FormulaEvalError')) return [3 /*break*/, 5];
40
+ return [4 /*yield*/, (conditionComputeErrorHandler === null || conditionComputeErrorHandler === void 0 ? void 0 : conditionComputeErrorHandler(conditions.children, conditions.conjunction, data))];
41
+ case 4: return [2 /*return*/, _a.sent()];
42
+ case 5: return [2 /*return*/, defaultResult];
43
+ case 6: return [2 /*return*/];
32
44
  }
33
45
  });
34
46
  });
@@ -79,7 +91,7 @@ function computeCondition(rule, index, data) {
79
91
  switch (_b.label) {
80
92
  case 0:
81
93
  leftValue = get(data, rule.left.field);
82
- return [4 /*yield*/, resolveVariableAndFilterForAsync(rule.right, data)];
94
+ return [4 /*yield*/, resolveVariableAndFilterForAsync(rule.right, data, undefined, undefined, true)];
83
95
  case 1:
84
96
  rightValue = _b.sent();
85
97
  func = (_a = conditionResolverMap["".concat(rule.op, "For").concat(capitalize(rule.left.type))]) !== null && _a !== void 0 ? _a : conditionResolverMap[rule.op];
@@ -268,6 +280,9 @@ function registerConditionComputer(op, func, fieldType) {
268
280
  function getConditionComputers() {
269
281
  return conditionResolverMap;
270
282
  }
283
+ function setConditionComputeErrorHandler(fn) {
284
+ conditionComputeErrorHandler = fn;
285
+ }
271
286
  registerConditionComputer('greater', greaterFunc);
272
287
  registerConditionComputer('greater', greaterForDateFunc, 'date');
273
288
  registerConditionComputer('greater', greaterForDateFunc, 'time');
@@ -303,4 +318,4 @@ registerConditionComputer('select_not_any_in', selectNotAnyInFunc);
303
318
  registerConditionComputer('starts_with', startsWithFunc);
304
319
  registerConditionComputer('ends_with', endsWithFunc);
305
320
 
306
- export { getConditionComputers, registerConditionComputer, resolveCondition };
321
+ export { getConditionComputers, registerConditionComputer, resolveCondition, setConditionComputeErrorHandler };
@@ -1,10 +1,11 @@
1
1
  /**
2
- * amis-core v2.9.0
2
+ * amis-core v3.1.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
- import { Evaluator, parse } from 'amis-formula';
6
+ import { Evaluator } from 'amis-formula';
7
7
  import { getVariable } from './getVariable.js';
8
+ import { memoryParse } from './memoryParse.js';
8
9
 
9
10
  function resolveVariable(path, data, canAccessSuper) {
10
11
  if (data === void 0) { data = {}; }
@@ -22,7 +23,7 @@ function resolveVariable(path, data, canAccessSuper) {
22
23
  // 带 namespace 的用公式
23
24
  // 主要是用公式会严格点,不能出现奇怪的变量名
24
25
  try {
25
- return new Evaluator(data).evalute(parse(path, {
26
+ return new Evaluator(data).evalute(memoryParse(path, {
26
27
  variableMode: true,
27
28
  allowFilter: false
28
29
  }));
@@ -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
 
@@ -1 +1,6 @@
1
- export declare const resolveVariableAndFilterForAsync: (path?: string, data?: object, defaultFilter?: string, fallbackValue?: (value: any) => any) => Promise<any>;
1
+ /**
2
+ * 设置自定义函数,functions中找不到处理的函数时执行
3
+ * @param fn
4
+ */
5
+ export declare function setFormulaEvalErrorHandler(fn: (path: string, data?: object, ...args: any[]) => any): void;
6
+ export declare const resolveVariableAndFilterForAsync: (path?: string, data?: object, defaultFilter?: string, fallbackValue?: (value: any) => any, skipFormulaEvalErrorHandler?: boolean) => Promise<any>;
@@ -1,15 +1,25 @@
1
1
  /**
2
- * amis-core v2.9.0
2
+ * amis-core v3.1.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
6
  import { __awaiter, __generator } from 'tslib';
7
- import { parse, AsyncEvaluator } from 'amis-formula';
7
+ import { AsyncEvaluator } from 'amis-formula';
8
+ import { memoryParse } from './memoryParse.js';
8
9
 
9
- var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fallbackValue) {
10
+ var formulaEvalErrorHandler;
11
+ /**
12
+ * 设置自定义函数,functions中找不到处理的函数时执行
13
+ * @param fn
14
+ */
15
+ function setFormulaEvalErrorHandler(fn) {
16
+ formulaEvalErrorHandler = fn;
17
+ }
18
+ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fallbackValue, skipFormulaEvalErrorHandler) {
10
19
  if (data === void 0) { data = {}; }
11
20
  if (defaultFilter === void 0) { defaultFilter = '| html'; }
12
21
  if (fallbackValue === void 0) { fallbackValue = function (value) { return value; }; }
22
+ if (skipFormulaEvalErrorHandler === void 0) { skipFormulaEvalErrorHandler = false; }
13
23
  return __awaiter(void 0, void 0, void 0, function () {
14
24
  var ast, ret, e_1;
15
25
  return __generator(this, function (_a) {
@@ -21,7 +31,7 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
21
31
  _a.label = 1;
22
32
  case 1:
23
33
  _a.trys.push([1, 3, , 4]);
24
- ast = parse(path, {
34
+ ast = memoryParse(path, {
25
35
  evalMode: false,
26
36
  allowFilter: true
27
37
  });
@@ -35,6 +45,14 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
35
45
  : ret];
36
46
  case 3:
37
47
  e_1 = _a.sent();
48
+ if (e_1.name === 'FormulaEvalError') {
49
+ if (!skipFormulaEvalErrorHandler) {
50
+ // 无法解析时,执行handler自定义解析逻辑
51
+ return [2 /*return*/, formulaEvalErrorHandler === null || formulaEvalErrorHandler === void 0 ? void 0 : formulaEvalErrorHandler(path, data, defaultFilter, fallbackValue)];
52
+ }
53
+ // 跳过自定义解析逻辑,则直接抛异常
54
+ throw e_1;
55
+ }
38
56
  console.warn(e_1);
39
57
  return [2 /*return*/, undefined];
40
58
  case 4: return [2 /*return*/];
@@ -43,4 +61,4 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
43
61
  });
44
62
  };
45
63
 
46
- export { resolveVariableAndFilterForAsync };
64
+ export { resolveVariableAndFilterForAsync, setFormulaEvalErrorHandler };
@@ -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
 
@@ -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
 
@@ -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
 
@@ -1,13 +1,16 @@
1
1
  import { PlainObject } from '../types';
2
2
  export declare const valueMap: PlainObject;
3
+ export declare const inheritValueMap: PlainObject;
3
4
  interface extra {
5
+ important?: boolean;
6
+ inner?: string;
4
7
  pre?: string;
5
8
  suf?: string;
6
9
  }
7
10
  export declare function findOrCreactStyle(id: string): HTMLElement;
8
11
  export declare function insertStyle(style: string, id: string): void;
9
12
  export declare function addStyle(style: string, id: string): void;
10
- export declare function formatStyle(css: any, classNames: {
13
+ export declare function formatStyle(themeCss: any, classNames: {
11
14
  key: string;
12
15
  value?: string;
13
16
  weights?: {
@@ -16,14 +19,14 @@ export declare function formatStyle(css: any, classNames: {
16
19
  active?: extra;
17
20
  disabled?: extra;
18
21
  };
19
- }[], id?: string): {
22
+ }[], id?: string, defaultData?: any): {
20
23
  value: string;
21
24
  origin: {
22
25
  className: string;
23
26
  content: string;
24
27
  }[];
25
28
  };
26
- export declare function insertCustomStyle(css: any, classNames: {
29
+ export interface CustomStyleClassName {
27
30
  key: string;
28
31
  value?: string;
29
32
  weights?: {
@@ -32,5 +35,10 @@ export declare function insertCustomStyle(css: any, classNames: {
32
35
  active?: extra;
33
36
  disabled?: extra;
34
37
  };
35
- }[], id?: string): void;
38
+ }
39
+ export declare function insertCustomStyle(themeCss: any, classNames: CustomStyleClassName[], id?: string, defaultData?: any, customStyleClassPrefix?: string): void;
40
+ /**
41
+ * 根据路径获取默认值
42
+ */
43
+ export declare function getValueByPath(path: string, data: any): any;
36
44
  export {};
@@ -1,10 +1,11 @@
1
1
  /**
2
- * amis-core v2.9.0
2
+ * amis-core v3.1.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', '').replace('-inner', '')) || '')) {
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 = [];
@@ -142,21 +185,31 @@ function formatStyle(css, classNames, id) {
142
185
  }
143
186
  else {
144
187
  var value = style;
145
- value && fn(key, value);
188
+ if (key === 'iconSize') {
189
+ fn('width', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
190
+ fn('height', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
191
+ fn('font-size', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
192
+ }
193
+ else {
194
+ value &&
195
+ fn(key, value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
196
+ }
146
197
  }
147
198
  }
148
199
  if (styles.length > 0) {
149
200
  var cx = ((weights === null || weights === void 0 ? void 0 : weights.pre) || '') + className + ((weights === null || weights === void 0 ? void 0 : weights.suf) || '');
201
+ var inner = (weights === null || weights === void 0 ? void 0 : weights.inner) || '';
150
202
  res.push({
151
- className: cx + status2string[status_1],
152
- content: ".".concat(cx + status2string[status_1], " {\n ").concat(styles.join('\n '), "\n}")
203
+ className: cx + status2string[status_1] + inner,
204
+ content: ".".concat(cx + status2string[status_1], " ").concat(inner, "{\n ").concat(styles.join('\n '), "\n}")
153
205
  });
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
- }
206
+ // TODO:切换状态暂时先不改变组件的样式
207
+ // if (['hover', 'active', 'disabled'].includes(status)) {
208
+ // res.push({
209
+ // className: cx + '.' + status,
210
+ // content: `.${cx}.${status} {\n ${styles.join('\n ')}\n}`
211
+ // });
212
+ // }
160
213
  }
161
214
  };
162
215
  for (var status_1 in statusMap) {
@@ -190,12 +243,36 @@ function formatStyle(css, classNames, id) {
190
243
  origin: res
191
244
  };
192
245
  }
193
- function insertCustomStyle(css, classNames, id) {
194
- if (!css) {
246
+ function insertCustomStyle(themeCss, classNames, id, defaultData, customStyleClassPrefix) {
247
+ if (!themeCss) {
195
248
  return;
196
249
  }
197
- var value = formatStyle(css, classNames, id).value;
198
- insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || uuid());
250
+ var value = formatStyle(themeCss, classNames, id, defaultData).value;
251
+ if (value) {
252
+ value = customStyleClassPrefix
253
+ ? "".concat(customStyleClassPrefix, " ").concat(value)
254
+ : value;
255
+ insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || uuid());
256
+ }
257
+ }
258
+ /**
259
+ * 根据路径获取默认值
260
+ */
261
+ function getValueByPath(path, data) {
262
+ try {
263
+ if (!path || !data) {
264
+ return null;
265
+ }
266
+ var keys = path.split('.');
267
+ var value = cloneDeep(data.component);
268
+ for (var i = 0; i < keys.length; i++) {
269
+ value = value[keys[i]];
270
+ }
271
+ return value;
272
+ }
273
+ catch (e) {
274
+ return null;
275
+ }
199
276
  }
200
277
 
201
- export { addStyle, findOrCreactStyle, formatStyle, insertCustomStyle, insertStyle, valueMap };
278
+ export { addStyle, findOrCreactStyle, formatStyle, getValueByPath, inheritValueMap, insertCustomStyle, insertStyle, valueMap };
@@ -1,11 +1,11 @@
1
1
  /**
2
- * amis-core v2.9.0
2
+ * amis-core v3.1.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.9.0
2
+ * amis-core v3.1.0
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -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
 
@@ -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,14 +1,16 @@
1
1
  /**
2
- * amis-core v2.9.0
2
+ * amis-core v3.1.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
10
  import { tokenize } from './tokenize.js';
11
11
  export { tokenize } from './tokenize.js';
12
+ import { resolveVariableAndFilterForAsync } from './resolveVariableAndFilterForAsync.js';
13
+ export { resolveVariableAndFilterForAsync } from './resolveVariableAndFilterForAsync.js';
12
14
  import './filter.js';
13
15
 
14
16
  function matchSynatax(str) {
@@ -38,6 +40,7 @@ function matchSynatax(str) {
38
40
  return false;
39
41
  }
40
42
  function register() {
43
+ var _this = this;
41
44
  return {
42
45
  name: 'builtin',
43
46
  test: function (str) { return typeof str === 'string' && matchSynatax(str); },
@@ -52,6 +55,20 @@ function register() {
52
55
  catch (e) {
53
56
  return "error: ".concat(e.message);
54
57
  }
58
+ },
59
+ asyncCompile: function (str, data, defaultFilter) {
60
+ if (defaultFilter === void 0) { defaultFilter = '| html'; }
61
+ return __awaiter(_this, void 0, void 0, function () {
62
+ return __generator(this, function (_a) {
63
+ try {
64
+ return [2 /*return*/, resolveVariableAndFilterForAsync(str, data, defaultFilter)];
65
+ }
66
+ catch (e) {
67
+ return [2 /*return*/, "error: ".concat(e.message)];
68
+ }
69
+ return [2 /*return*/];
70
+ });
71
+ });
55
72
  }
56
73
  };
57
74
  }
@@ -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
 
@@ -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,9 +2,11 @@ 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;
10
12
  /**
package/esm/utils/tpl.js CHANGED
@@ -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
 
@@ -34,6 +34,27 @@ function filter(tpl, data) {
34
34
  }
35
35
  return tpl;
36
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
+ }
37
58
  // 缓存一下提升性能
38
59
  var EVAL_CACHE = {};
39
60
  var customEvalExpressionFn;
@@ -144,8 +165,9 @@ function evalJS(js, data) {
144
165
  registerTplEnginer(info.name, {
145
166
  test: info.test,
146
167
  compile: info.compile,
168
+ asyncCompile: info.asyncCompile,
147
169
  removeEscapeToken: info.removeEscapeToken
148
170
  });
149
171
  });
150
172
 
151
- export { evalExpression, evalExpressionWithConditionBuilder, 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.9.0
2
+ * amis-core v3.1.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;