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
 
@@ -29,9 +29,11 @@ var capitalize__default = /*#__PURE__*/_interopDefaultLegacy(capitalize);
29
29
 
30
30
  var conditionResolverMap = {};
31
31
  var DEFAULT_RESULT = true;
32
+ var conditionComputeErrorHandler;
32
33
  function resolveCondition(conditions, data, defaultResult) {
33
34
  if (defaultResult === void 0) { defaultResult = true; }
34
35
  return tslib.__awaiter(this, void 0, void 0, function () {
36
+ var e_1;
35
37
  return tslib.__generator(this, function (_a) {
36
38
  switch (_a.label) {
37
39
  case 0:
@@ -41,8 +43,18 @@ function resolveCondition(conditions, data, defaultResult) {
41
43
  !conditions.children.length) {
42
44
  return [2 /*return*/, defaultResult];
43
45
  }
46
+ _a.label = 1;
47
+ case 1:
48
+ _a.trys.push([1, 3, , 6]);
44
49
  return [4 /*yield*/, computeConditions(conditions.children, conditions.conjunction, data)];
45
- case 1: return [2 /*return*/, _a.sent()];
50
+ case 2: return [2 /*return*/, _a.sent()];
51
+ case 3:
52
+ e_1 = _a.sent();
53
+ if (!(e_1.name === 'FormulaEvalError')) return [3 /*break*/, 5];
54
+ return [4 /*yield*/, (conditionComputeErrorHandler === null || conditionComputeErrorHandler === void 0 ? void 0 : conditionComputeErrorHandler(conditions.children, conditions.conjunction, data))];
55
+ case 4: return [2 /*return*/, _a.sent()];
56
+ case 5: return [2 /*return*/, defaultResult];
57
+ case 6: return [2 /*return*/];
46
58
  }
47
59
  });
48
60
  });
@@ -93,7 +105,7 @@ function computeCondition(rule, index, data) {
93
105
  switch (_b.label) {
94
106
  case 0:
95
107
  leftValue = get__default["default"](data, rule.left.field);
96
- return [4 /*yield*/, resolveVariableAndFilterForAsync.resolveVariableAndFilterForAsync(rule.right, data)];
108
+ return [4 /*yield*/, resolveVariableAndFilterForAsync.resolveVariableAndFilterForAsync(rule.right, data, undefined, undefined, true)];
97
109
  case 1:
98
110
  rightValue = _b.sent();
99
111
  func = (_a = conditionResolverMap["".concat(rule.op, "For").concat(capitalize__default["default"](rule.left.type))]) !== null && _a !== void 0 ? _a : conditionResolverMap[rule.op];
@@ -282,6 +294,9 @@ function registerConditionComputer(op, func, fieldType) {
282
294
  function getConditionComputers() {
283
295
  return conditionResolverMap;
284
296
  }
297
+ function setConditionComputeErrorHandler(fn) {
298
+ conditionComputeErrorHandler = fn;
299
+ }
285
300
  registerConditionComputer('greater', greaterFunc);
286
301
  registerConditionComputer('greater', greaterForDateFunc, 'date');
287
302
  registerConditionComputer('greater', greaterForDateFunc, 'time');
@@ -320,3 +335,4 @@ registerConditionComputer('ends_with', endsWithFunc);
320
335
  exports.getConditionComputers = getConditionComputers;
321
336
  exports.registerConditionComputer = registerConditionComputer;
322
337
  exports.resolveCondition = resolveCondition;
338
+ exports.setConditionComputeErrorHandler = setConditionComputeErrorHandler;
@@ -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
 
@@ -9,6 +9,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
10
  var amisFormula = require('amis-formula');
11
11
  var getVariable = require('./getVariable.js');
12
+ var memoryParse = require('./memoryParse.js');
12
13
 
13
14
  function resolveVariable(path, data, canAccessSuper) {
14
15
  if (data === void 0) { data = {}; }
@@ -26,7 +27,7 @@ function resolveVariable(path, data, canAccessSuper) {
26
27
  // 带 namespace 的用公式
27
28
  // 主要是用公式会严格点,不能出现奇怪的变量名
28
29
  try {
29
- return new amisFormula.Evaluator(data).evalute(amisFormula.parse(path, {
30
+ return new amisFormula.Evaluator(data).evalute(memoryParse.memoryParse(path, {
30
31
  variableMode: true,
31
32
  allowFilter: false
32
33
  }));
@@ -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,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
 
@@ -9,11 +9,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
10
  var tslib = require('tslib');
11
11
  var amisFormula = require('amis-formula');
12
+ var memoryParse = require('./memoryParse.js');
12
13
 
13
- var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fallbackValue) {
14
+ var formulaEvalErrorHandler;
15
+ /**
16
+ * 设置自定义函数,functions中找不到处理的函数时执行
17
+ * @param fn
18
+ */
19
+ function setFormulaEvalErrorHandler(fn) {
20
+ formulaEvalErrorHandler = fn;
21
+ }
22
+ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fallbackValue, skipFormulaEvalErrorHandler) {
14
23
  if (data === void 0) { data = {}; }
15
24
  if (defaultFilter === void 0) { defaultFilter = '| html'; }
16
25
  if (fallbackValue === void 0) { fallbackValue = function (value) { return value; }; }
26
+ if (skipFormulaEvalErrorHandler === void 0) { skipFormulaEvalErrorHandler = false; }
17
27
  return tslib.__awaiter(void 0, void 0, void 0, function () {
18
28
  var ast, ret, e_1;
19
29
  return tslib.__generator(this, function (_a) {
@@ -25,7 +35,7 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
25
35
  _a.label = 1;
26
36
  case 1:
27
37
  _a.trys.push([1, 3, , 4]);
28
- ast = amisFormula.parse(path, {
38
+ ast = memoryParse.memoryParse(path, {
29
39
  evalMode: false,
30
40
  allowFilter: true
31
41
  });
@@ -39,6 +49,14 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
39
49
  : ret];
40
50
  case 3:
41
51
  e_1 = _a.sent();
52
+ if (e_1.name === 'FormulaEvalError') {
53
+ if (!skipFormulaEvalErrorHandler) {
54
+ // 无法解析时,执行handler自定义解析逻辑
55
+ return [2 /*return*/, formulaEvalErrorHandler === null || formulaEvalErrorHandler === void 0 ? void 0 : formulaEvalErrorHandler(path, data, defaultFilter, fallbackValue)];
56
+ }
57
+ // 跳过自定义解析逻辑,则直接抛异常
58
+ throw e_1;
59
+ }
42
60
  console.warn(e_1);
43
61
  return [2 /*return*/, undefined];
44
62
  case 4: return [2 /*return*/];
@@ -48,3 +66,4 @@ var resolveVariableAndFilterForAsync = function (path, data, defaultFilter, fall
48
66
  };
49
67
 
50
68
  exports.resolveVariableAndFilterForAsync = resolveVariableAndFilterForAsync;
69
+ exports.setFormulaEvalErrorHandler = 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,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
 
@@ -9,6 +9,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
10
  var tslib = require('tslib');
11
11
  var helper = require('./helper.js');
12
+ var cloneDeep = require('lodash/cloneDeep');
13
+
14
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
+
16
+ var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
12
17
 
13
18
  var valueMap = {
14
19
  'marginTop': 'margin-top',
@@ -35,6 +40,10 @@ var valueMap = {
35
40
  'fontWeight': 'font-weight',
36
41
  'lineHeight': 'line-height'
37
42
  };
43
+ var inheritValueMap = {
44
+ background: 'bg-color',
45
+ radius: 'border'
46
+ };
38
47
  function findOrCreactStyle(id) {
39
48
  var varStyleTag = document.getElementById(id);
40
49
  if (!varStyleTag) {
@@ -54,10 +63,47 @@ function addStyle(style, id) {
54
63
  // bca-disable-line
55
64
  varStyleTag.innerHTML += style;
56
65
  }
57
- function formatStyle(css, classNames, id) {
66
+ // 继承数据处理
67
+ function handleInheritData(statusMap, data) {
68
+ if (!data) {
69
+ return;
70
+ }
71
+ // 检查是否存在inherit
72
+ ['hover', 'active'].forEach(function (status) {
73
+ for (var key in statusMap[status]) {
74
+ if (typeof statusMap[status][key] === 'object') {
75
+ for (var style in statusMap[status][key]) {
76
+ if (statusMap[status][key][style] === 'inherit') {
77
+ // 值为inherit时设置为default的值或者主题中的default值
78
+ if (statusMap['default'][key] && statusMap['default'][key][style]) {
79
+ statusMap[status][key][style] = statusMap.default[key][style];
80
+ }
81
+ else {
82
+ var value = inheritValueMap[key] || key;
83
+ statusMap[status][key][style] =
84
+ data['default'].body[value][style];
85
+ }
86
+ }
87
+ }
88
+ }
89
+ else {
90
+ if (statusMap[status][key] === 'inherit') {
91
+ if (statusMap['default'][key] && statusMap['default'][key]) {
92
+ statusMap[status][key] = statusMap.default[key];
93
+ }
94
+ else {
95
+ var value = inheritValueMap[key] || key;
96
+ statusMap[status][key] = data['default'].body[value];
97
+ }
98
+ }
99
+ }
100
+ }
101
+ });
102
+ }
103
+ function formatStyle(themeCss, classNames, id, defaultData) {
58
104
  var e_1, _a;
59
105
  var _b;
60
- if (!css) {
106
+ if (!themeCss) {
61
107
  return { value: '', origin: [] };
62
108
  }
63
109
  var res = [];
@@ -69,7 +115,7 @@ function formatStyle(css, classNames, id) {
69
115
  };
70
116
  var _loop_1 = function (item) {
71
117
  var e_2, _c;
72
- var body = css[item.key];
118
+ var body = themeCss[item.key];
73
119
  var list = (_b = item.value) === null || _b === void 0 ? void 0 : _b.split(' ');
74
120
  var classNameList = [];
75
121
  if (!body) {
@@ -77,7 +123,7 @@ function formatStyle(css, classNames, id) {
77
123
  }
78
124
  list === null || list === void 0 ? void 0 : list.forEach(function (n) {
79
125
  if (/(\S*[C|c]lassName-\S*)/.test(n) &&
80
- !!~n.indexOf((id === null || id === void 0 ? void 0 : id.replace('u:', '').replace('-label', '').replace('-description', '').replace('-addOn', '')) || '')) {
126
+ !!~n.indexOf((id === null || id === void 0 ? void 0 : id.replace('u:', '').replace('-label', '').replace('-description', '').replace('-addOn', '').replace('-icon', '').replace('-inner', '')) || '')) {
81
127
  classNameList.push(n);
82
128
  }
83
129
  });
@@ -112,6 +158,7 @@ function formatStyle(css, classNames, id) {
112
158
  statusMap.default[key] = body[key];
113
159
  }
114
160
  }
161
+ handleInheritData(statusMap, defaultData);
115
162
  var _loop_2 = function (status_1) {
116
163
  var weights = weightsList[status_1];
117
164
  var styles = [];
@@ -146,21 +193,31 @@ function formatStyle(css, classNames, id) {
146
193
  }
147
194
  else {
148
195
  var value = style;
149
- value && fn(key, value);
196
+ if (key === 'iconSize') {
197
+ fn('width', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
198
+ fn('height', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
199
+ fn('font-size', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
200
+ }
201
+ else {
202
+ value &&
203
+ fn(key, value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
204
+ }
150
205
  }
151
206
  }
152
207
  if (styles.length > 0) {
153
208
  var cx = ((weights === null || weights === void 0 ? void 0 : weights.pre) || '') + className + ((weights === null || weights === void 0 ? void 0 : weights.suf) || '');
209
+ var inner = (weights === null || weights === void 0 ? void 0 : weights.inner) || '';
154
210
  res.push({
155
- className: cx + status2string[status_1],
156
- content: ".".concat(cx + status2string[status_1], " {\n ").concat(styles.join('\n '), "\n}")
211
+ className: cx + status2string[status_1] + inner,
212
+ content: ".".concat(cx + status2string[status_1], " ").concat(inner, "{\n ").concat(styles.join('\n '), "\n}")
157
213
  });
158
- if (['hover', 'active', 'disabled'].includes(status_1)) {
159
- res.push({
160
- className: cx + '.' + status_1,
161
- content: ".".concat(cx, ".").concat(status_1, " {\n ").concat(styles.join('\n '), "\n}")
162
- });
163
- }
214
+ // TODO:切换状态暂时先不改变组件的样式
215
+ // if (['hover', 'active', 'disabled'].includes(status)) {
216
+ // res.push({
217
+ // className: cx + '.' + status,
218
+ // content: `.${cx}.${status} {\n ${styles.join('\n ')}\n}`
219
+ // });
220
+ // }
164
221
  }
165
222
  };
166
223
  for (var status_1 in statusMap) {
@@ -194,17 +251,43 @@ function formatStyle(css, classNames, id) {
194
251
  origin: res
195
252
  };
196
253
  }
197
- function insertCustomStyle(css, classNames, id) {
198
- if (!css) {
254
+ function insertCustomStyle(themeCss, classNames, id, defaultData, customStyleClassPrefix) {
255
+ if (!themeCss) {
199
256
  return;
200
257
  }
201
- var value = formatStyle(css, classNames, id).value;
202
- insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || helper.uuid());
258
+ var value = formatStyle(themeCss, classNames, id, defaultData).value;
259
+ if (value) {
260
+ value = customStyleClassPrefix
261
+ ? "".concat(customStyleClassPrefix, " ").concat(value)
262
+ : value;
263
+ insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || helper.uuid());
264
+ }
265
+ }
266
+ /**
267
+ * 根据路径获取默认值
268
+ */
269
+ function getValueByPath(path, data) {
270
+ try {
271
+ if (!path || !data) {
272
+ return null;
273
+ }
274
+ var keys = path.split('.');
275
+ var value = cloneDeep__default["default"](data.component);
276
+ for (var i = 0; i < keys.length; i++) {
277
+ value = value[keys[i]];
278
+ }
279
+ return value;
280
+ }
281
+ catch (e) {
282
+ return null;
283
+ }
203
284
  }
204
285
 
205
286
  exports.addStyle = addStyle;
206
287
  exports.findOrCreactStyle = findOrCreactStyle;
207
288
  exports.formatStyle = formatStyle;
289
+ exports.getValueByPath = getValueByPath;
290
+ exports.inheritValueMap = inheritValueMap;
208
291
  exports.insertCustomStyle = insertCustomStyle;
209
292
  exports.insertStyle = insertStyle;
210
293
  exports.valueMap = valueMap;
@@ -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
 
@@ -7,9 +7,9 @@
7
7
 
8
8
  Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
+ require('tslib');
10
11
  require('amis-formula');
11
12
  require('moment');
12
- require('tslib');
13
13
  require('lodash/isPlainObject');
14
14
  var resolveVariableAndFilter = require('./resolveVariableAndFilter.js');
15
15
  require('./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,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
 
@@ -7,11 +7,12 @@
7
7
 
8
8
  Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
+ var tslib = require('tslib');
10
11
  var amisFormula = require('amis-formula');
11
12
  require('moment');
12
- require('tslib');
13
13
  require('lodash/isPlainObject');
14
14
  var tokenize = require('./tokenize.js');
15
+ var resolveVariableAndFilterForAsync = require('./resolveVariableAndFilterForAsync.js');
15
16
  require('./filter.js');
16
17
 
17
18
  function matchSynatax(str) {
@@ -41,6 +42,7 @@ function matchSynatax(str) {
41
42
  return false;
42
43
  }
43
44
  function register() {
45
+ var _this = this;
44
46
  return {
45
47
  name: 'builtin',
46
48
  test: function (str) { return typeof str === 'string' && matchSynatax(str); },
@@ -55,6 +57,20 @@ function register() {
55
57
  catch (e) {
56
58
  return "error: ".concat(e.message);
57
59
  }
60
+ },
61
+ asyncCompile: function (str, data, defaultFilter) {
62
+ if (defaultFilter === void 0) { defaultFilter = '| html'; }
63
+ return tslib.__awaiter(_this, void 0, void 0, function () {
64
+ return tslib.__generator(this, function (_a) {
65
+ try {
66
+ return [2 /*return*/, resolveVariableAndFilterForAsync.resolveVariableAndFilterForAsync(str, data, defaultFilter)];
67
+ }
68
+ catch (e) {
69
+ return [2 /*return*/, "error: ".concat(e.message)];
70
+ }
71
+ return [2 /*return*/];
72
+ });
73
+ });
58
74
  }
59
75
  };
60
76
  }
@@ -72,4 +88,5 @@ Object.defineProperty(exports, 'registerFunction', {
72
88
  get: function () { return amisFormula.registerFunction; }
73
89
  });
74
90
  exports.tokenize = tokenize.tokenize;
91
+ exports.resolveVariableAndFilterForAsync = resolveVariableAndFilterForAsync.resolveVariableAndFilterForAsync;
75
92
  exports.register = register;
@@ -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
 
@@ -64,7 +64,8 @@ function register() {
64
64
  return {
65
65
  name: 'lodash',
66
66
  test: function (str) { return !!~str.indexOf('<%'); },
67
- compile: function (str, data) { return lodashCompile(str, data); }
67
+ compile: function (str, data) { return lodashCompile(str, data); },
68
+ asyncCompile: function (str, data) { return lodashCompile(str, data); }
68
69
  };
69
70
  }
70
71
 
@@ -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/lib/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
 
@@ -38,6 +38,27 @@ function filter(tpl, data) {
38
38
  }
39
39
  return tpl;
40
40
  }
41
+ function asyncFilter(tpl, data) {
42
+ if (data === void 0) { data = {}; }
43
+ var rest = [];
44
+ for (var _i = 2; _i < arguments.length; _i++) {
45
+ rest[_i - 2] = arguments[_i];
46
+ }
47
+ if (!tpl || typeof tpl !== 'string') {
48
+ return Promise.resolve('');
49
+ }
50
+ var keys = Object.keys(enginers);
51
+ for (var i = 0, len = keys.length; i < len; i++) {
52
+ var enginer = enginers[keys[i]];
53
+ if (enginer.test(tpl)) {
54
+ return enginer.asyncCompile.apply(enginer, tslib.__spreadArray([tpl, data], tslib.__read(rest), false));
55
+ }
56
+ else if (enginer.removeEscapeToken) {
57
+ tpl = enginer.removeEscapeToken(tpl);
58
+ }
59
+ }
60
+ return tpl;
61
+ }
41
62
  // 缓存一下提升性能
42
63
  var EVAL_CACHE = {};
43
64
  var customEvalExpressionFn;
@@ -148,10 +169,12 @@ function evalJS(js, data) {
148
169
  registerTplEnginer(info.name, {
149
170
  test: info.test,
150
171
  compile: info.compile,
172
+ asyncCompile: info.asyncCompile,
151
173
  removeEscapeToken: info.removeEscapeToken
152
174
  });
153
175
  });
154
176
 
177
+ exports.asyncFilter = asyncFilter;
155
178
  exports.evalExpression = evalExpression;
156
179
  exports.evalExpressionWithConditionBuilder = evalExpressionWithConditionBuilder;
157
180
  exports.evalJS = evalJS;
@@ -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;