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,5 +1,6 @@
1
1
  import { PlainObject } from '../types';
2
2
  export declare const valueMap: PlainObject;
3
+ export declare const inheritValueMap: PlainObject;
3
4
  interface extra {
4
5
  pre?: string;
5
6
  suf?: string;
@@ -7,7 +8,7 @@ interface extra {
7
8
  export declare function findOrCreactStyle(id: string): HTMLElement;
8
9
  export declare function insertStyle(style: string, id: string): void;
9
10
  export declare function addStyle(style: string, id: string): void;
10
- export declare function formatStyle(css: any, classNames: {
11
+ export declare function formatStyle(themeCss: any, classNames: {
11
12
  key: string;
12
13
  value?: string;
13
14
  weights?: {
@@ -16,14 +17,14 @@ export declare function formatStyle(css: any, classNames: {
16
17
  active?: extra;
17
18
  disabled?: extra;
18
19
  };
19
- }[], id?: string): {
20
+ }[], id?: string, defaultData?: any): {
20
21
  value: string;
21
22
  origin: {
22
23
  className: string;
23
24
  content: string;
24
25
  }[];
25
26
  };
26
- export declare function insertCustomStyle(css: any, classNames: {
27
+ export declare function insertCustomStyle(themeCss: any, classNames: {
27
28
  key: string;
28
29
  value?: string;
29
30
  weights?: {
@@ -32,5 +33,9 @@ export declare function insertCustomStyle(css: any, classNames: {
32
33
  active?: extra;
33
34
  disabled?: extra;
34
35
  };
35
- }[], id?: string): void;
36
+ }[], id?: string, defaultData?: any): void;
37
+ /**
38
+ * 根据路径获取默认值
39
+ */
40
+ export declare function getValueByPath(path: string, data: any): any;
36
41
  export {};
@@ -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
 
@@ -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', '')) || '')) {
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 = [];
@@ -155,12 +202,13 @@ function formatStyle(css, classNames, id) {
155
202
  className: cx + status2string[status_1],
156
203
  content: ".".concat(cx + status2string[status_1], " {\n ").concat(styles.join('\n '), "\n}")
157
204
  });
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
- }
205
+ // TODO:切换状态暂时先不改变组件的样式
206
+ // if (['hover', 'active', 'disabled'].includes(status)) {
207
+ // res.push({
208
+ // className: cx + '.' + status,
209
+ // content: `.${cx}.${status} {\n ${styles.join('\n ')}\n}`
210
+ // });
211
+ // }
164
212
  }
165
213
  };
166
214
  for (var status_1 in statusMap) {
@@ -194,17 +242,40 @@ function formatStyle(css, classNames, id) {
194
242
  origin: res
195
243
  };
196
244
  }
197
- function insertCustomStyle(css, classNames, id) {
198
- if (!css) {
245
+ function insertCustomStyle(themeCss, classNames, id, defaultData) {
246
+ if (!themeCss) {
199
247
  return;
200
248
  }
201
- var value = formatStyle(css, classNames, id).value;
202
- insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || helper.uuid());
249
+ var value = formatStyle(themeCss, classNames, id, defaultData).value;
250
+ if (value) {
251
+ insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || helper.uuid());
252
+ }
253
+ }
254
+ /**
255
+ * 根据路径获取默认值
256
+ */
257
+ function getValueByPath(path, data) {
258
+ try {
259
+ if (!path || !data) {
260
+ return null;
261
+ }
262
+ var keys = path.split('.');
263
+ var value = cloneDeep__default["default"](data.component);
264
+ for (var i = 0; i < keys.length; i++) {
265
+ value = value[keys[i]];
266
+ }
267
+ return value;
268
+ }
269
+ catch (e) {
270
+ return null;
271
+ }
203
272
  }
204
273
 
205
274
  exports.addStyle = addStyle;
206
275
  exports.findOrCreactStyle = findOrCreactStyle;
207
276
  exports.formatStyle = formatStyle;
277
+ exports.getValueByPath = getValueByPath;
278
+ exports.inheritValueMap = inheritValueMap;
208
279
  exports.insertCustomStyle = insertCustomStyle;
209
280
  exports.insertStyle = insertStyle;
210
281
  exports.valueMap = valueMap;
@@ -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
 
@@ -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.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,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
 
@@ -7,6 +7,7 @@
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
 
12
13
  var tokenize = function (str, data, defaultFilter) {
@@ -29,5 +30,36 @@ var tokenize = function (str, data, defaultFilter) {
29
30
  return str;
30
31
  }
31
32
  };
33
+ var asyncTokenize = function (str, data, defaultFilter) {
34
+ if (defaultFilter === void 0) { defaultFilter = '| html'; }
35
+ return tslib.__awaiter(void 0, void 0, void 0, function () {
36
+ var ast, result, e_1;
37
+ return tslib.__generator(this, function (_a) {
38
+ switch (_a.label) {
39
+ case 0:
40
+ if (!str || typeof str !== 'string') {
41
+ return [2 /*return*/, str];
42
+ }
43
+ _a.label = 1;
44
+ case 1:
45
+ _a.trys.push([1, 3, , 4]);
46
+ ast = amisFormula.parse(str, {
47
+ evalMode: false,
48
+ allowFilter: true
49
+ });
50
+ return [4 /*yield*/, amisFormula.evaluateForAsync(ast, data, { defaultFilter: defaultFilter })];
51
+ case 2:
52
+ result = _a.sent();
53
+ return [2 /*return*/, "".concat(result == null ? '' : result)];
54
+ case 3:
55
+ e_1 = _a.sent();
56
+ console.warn(e_1);
57
+ return [2 /*return*/, str];
58
+ case 4: return [2 /*return*/];
59
+ }
60
+ });
61
+ });
62
+ };
32
63
 
64
+ exports.asyncTokenize = asyncTokenize;
33
65
  exports.tokenize = 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,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
 
@@ -7,9 +7,9 @@
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
15
  require('./filter.js');
@@ -41,6 +41,7 @@ function matchSynatax(str) {
41
41
  return false;
42
42
  }
43
43
  function register() {
44
+ var _this = this;
44
45
  return {
45
46
  name: 'builtin',
46
47
  test: function (str) { return typeof str === 'string' && matchSynatax(str); },
@@ -55,6 +56,20 @@ function register() {
55
56
  catch (e) {
56
57
  return "error: ".concat(e.message);
57
58
  }
59
+ },
60
+ asyncCompile: function (str, data, defaultFilter) {
61
+ if (defaultFilter === void 0) { defaultFilter = '| html'; }
62
+ return tslib.__awaiter(_this, void 0, void 0, function () {
63
+ return tslib.__generator(this, function (_a) {
64
+ try {
65
+ return [2 /*return*/, tokenize.asyncTokenize(str, data, defaultFilter)];
66
+ }
67
+ catch (e) {
68
+ return [2 /*return*/, "error: ".concat(e.message)];
69
+ }
70
+ return [2 /*return*/];
71
+ });
72
+ });
58
73
  }
59
74
  };
60
75
  }
@@ -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
 
@@ -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,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/lib/utils/tpl.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
 
@@ -11,6 +11,7 @@ var tslib = require('tslib');
11
11
  var tplBuiltin = require('./tpl-builtin.js');
12
12
  var tplLodash = require('./tpl-lodash.js');
13
13
  var amisFormula = require('amis-formula');
14
+ var resolveCondition = require('./resolveCondition.js');
14
15
 
15
16
  var enginers = {};
16
17
  function registerTplEnginer(name, enginer) {
@@ -37,6 +38,27 @@ function filter(tpl, data) {
37
38
  }
38
39
  return tpl;
39
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
+ }
40
62
  // 缓存一下提升性能
41
63
  var EVAL_CACHE = {};
42
64
  var customEvalExpressionFn;
@@ -83,6 +105,25 @@ function evalExpression(expression, data) {
83
105
  return false;
84
106
  }
85
107
  }
108
+ /**
109
+ * 解析表达式(支持condition-builder)
110
+ * @param expression 表达式 or condition-builder对象
111
+ * @param data 上下文
112
+ * @returns
113
+ */
114
+ function evalExpressionWithConditionBuilder(expression, data, defaultResult) {
115
+ return tslib.__awaiter(this, void 0, void 0, function () {
116
+ return tslib.__generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0:
119
+ if (!(Object.prototype.toString.call(expression) === '[object Object]')) return [3 /*break*/, 2];
120
+ return [4 /*yield*/, resolveCondition.resolveCondition(expression, data, defaultResult)];
121
+ case 1: return [2 /*return*/, _a.sent()];
122
+ case 2: return [2 /*return*/, evalExpression(String(expression), data)];
123
+ }
124
+ });
125
+ });
126
+ }
86
127
  var AST_CACHE = {};
87
128
  function evalFormula(expression, data) {
88
129
  var ast = AST_CACHE[expression] ||
@@ -128,11 +169,14 @@ function evalJS(js, data) {
128
169
  registerTplEnginer(info.name, {
129
170
  test: info.test,
130
171
  compile: info.compile,
172
+ asyncCompile: info.asyncCompile,
131
173
  removeEscapeToken: info.removeEscapeToken
132
174
  });
133
175
  });
134
176
 
177
+ exports.asyncFilter = asyncFilter;
135
178
  exports.evalExpression = evalExpression;
179
+ exports.evalExpressionWithConditionBuilder = evalExpressionWithConditionBuilder;
136
180
  exports.evalJS = evalJS;
137
181
  exports.filter = filter;
138
182
  exports.registerTplEnginer = registerTplEnginer;
@@ -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
 
@@ -358,12 +358,16 @@ var validateMessages = {
358
358
  isVariableName: 'validate.isVariableName'
359
359
  };
360
360
  function validate(value, values, rules, messages, __) {
361
+ var _a;
361
362
  if (__ === void 0) { __ = function (str) { return str; }; }
362
363
  var errors = [];
363
- rules &&
364
- Object.keys(rules).forEach(function (ruleName) {
364
+ if (rules) {
365
+ var ruleNames = Object.keys(rules);
366
+ var length_1 = ruleNames.length;
367
+ for (var index = 0; index < length_1; index++) {
368
+ var ruleName = ruleNames[index];
365
369
  if (!rules[ruleName] && rules[ruleName] !== 0) {
366
- return;
370
+ continue;
367
371
  }
368
372
  else if (typeof validations[ruleName] !== 'function') {
369
373
  throw new Error('Validation `' + ruleName + '` not exists!');
@@ -375,19 +379,30 @@ function validate(value, values, rules, messages, __) {
375
379
  }
376
380
  return item;
377
381
  });
378
- if (!fn.apply(void 0, tslib.__spreadArray([values, value], tslib.__read(args), false))) {
382
+ var validateRes = fn.apply(void 0, tslib.__spreadArray([values, value], tslib.__read(args), false));
383
+ // addRule 允许返回
384
+ // {error: true, msg: '错误提示'}
385
+ // 格式的信息来灵活展示错误
386
+ var fnResErrorMsg = '';
387
+ if (typeof validateRes === 'object' &&
388
+ validateRes.error === true) {
389
+ fnResErrorMsg = (_a = validateRes === null || validateRes === void 0 ? void 0 : validateRes.msg) !== null && _a !== void 0 ? _a : '';
390
+ }
391
+ if (!validateRes || fnResErrorMsg) {
379
392
  var msgRuleName = ruleName;
380
393
  if (Array.isArray(value)) {
381
394
  msgRuleName = "".concat(ruleName, "Array");
382
395
  }
383
- errors.push({
384
- rule: ruleName,
385
- msg: tpl.filter(__((messages && messages[ruleName]) ||
386
- validateMessages[msgRuleName] ||
387
- validateMessages[ruleName]), tslib.__assign({}, [''].concat(args)))
388
- });
396
+ return [{
397
+ rule: ruleName,
398
+ msg: tpl.filter(__((messages && messages[ruleName]) ||
399
+ fnResErrorMsg ||
400
+ validateMessages[msgRuleName] ||
401
+ validateMessages[ruleName]), tslib.__assign({}, [''].concat(args)))
402
+ }];
389
403
  }
390
- });
404
+ }
405
+ }
391
406
  return errors;
392
407
  }
393
408
  function validateObject(values, rules, messages, __) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amis-core",
3
- "version": "2.8.0",
3
+ "version": "3.0.0",
4
4
  "description": "amis-core",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -17,8 +17,8 @@
17
17
  "@types/file-saver": "^2.0.1",
18
18
  "@types/hoist-non-react-statics": "^3.3.1",
19
19
  "@types/jest": "^28.1.0",
20
- "@types/react": "^17.0.39",
21
- "@types/react-dom": "^17.0.11",
20
+ "@types/react": "^18.0.24",
21
+ "@types/react-dom": "^18.0.8",
22
22
  "immutable": "^4.1.0",
23
23
  "jest": "^29.0.3",
24
24
  "jest-environment-jsdom": "^29.0.3",
@@ -45,7 +45,7 @@
45
45
  "esm"
46
46
  ],
47
47
  "dependencies": {
48
- "amis-formula": "^2.8.0",
48
+ "amis-formula": "^3.0.0",
49
49
  "classnames": "2.3.1",
50
50
  "file-saver": "^2.0.2",
51
51
  "hoist-non-react-statics": "^3.3.2",
@@ -101,5 +101,5 @@
101
101
  "/.rollup.cache/"
102
102
  ]
103
103
  },
104
- "gitHead": "b92b6ca54eb2bbe0029d79b9d185ff2ee6d8d7d5"
104
+ "gitHead": "9220b4c13f4d042ebf2bf1dd8ee8e24d11e39141"
105
105
  }