amis-core 3.4.0 → 3.4.2

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 (285) hide show
  1. package/esm/Root.js +1 -1
  2. package/esm/RootRenderer.js +8 -8
  3. package/esm/SchemaRenderer.js +16 -12
  4. package/esm/Scoped.js +3 -1
  5. package/esm/StatusScoped.js +1 -1
  6. package/esm/WithRootStore.js +1 -1
  7. package/esm/WithStore.js +9 -8
  8. package/esm/actions/Action.js +1 -1
  9. package/esm/actions/AjaxAction.js +2 -2
  10. package/esm/actions/BreakAction.js +1 -1
  11. package/esm/actions/BroadcastAction.js +1 -1
  12. package/esm/actions/CmptAction.js +1 -1
  13. package/esm/actions/ContinueAction.js +1 -1
  14. package/esm/actions/CopyAction.js +1 -1
  15. package/esm/actions/CustomAction.js +3 -1
  16. package/esm/actions/DialogAction.js +1 -1
  17. package/esm/actions/DrawerAction.js +5 -1
  18. package/esm/actions/EmailAction.js +1 -1
  19. package/esm/actions/LinkAction.js +1 -1
  20. package/esm/actions/LoopAction.js +1 -1
  21. package/esm/actions/PageAction.js +1 -1
  22. package/esm/actions/ParallelAction.js +1 -1
  23. package/esm/actions/StatusAction.js +1 -1
  24. package/esm/actions/SwitchAction.js +1 -1
  25. package/esm/actions/ToastAction.js +1 -1
  26. package/esm/components/CustomStyle.d.ts +5 -6
  27. package/esm/components/CustomStyle.js +47 -6
  28. package/esm/components/LazyComponent.d.ts +1 -2
  29. package/esm/components/LazyComponent.js +12 -8
  30. package/esm/components/Overlay.js +3 -1
  31. package/esm/components/PopOver.d.ts +12 -12
  32. package/esm/components/PopOver.js +3 -1
  33. package/esm/env.d.ts +2 -2
  34. package/esm/env.js +1 -1
  35. package/esm/envOverwrite.js +1 -1
  36. package/esm/factory.d.ts +7 -7
  37. package/esm/factory.js +1 -1
  38. package/esm/index.js +5 -5
  39. package/esm/locale.d.ts +1 -1
  40. package/esm/locale.js +3 -3
  41. package/esm/polyfills.js +1 -1
  42. package/esm/renderers/Form.d.ts +1 -1
  43. package/esm/renderers/Form.js +10 -8
  44. package/esm/renderers/Item.d.ts +24 -56
  45. package/esm/renderers/Item.js +25 -31
  46. package/esm/renderers/Options.js +14 -12
  47. package/esm/renderers/Placeholder.js +1 -1
  48. package/esm/renderers/builtin.js +1 -1
  49. package/esm/renderers/register.js +1 -1
  50. package/esm/renderers/wrapControl.js +70 -80
  51. package/esm/store/app.js +3 -1
  52. package/esm/store/combo.d.ts +384 -0
  53. package/esm/store/combo.js +1 -1
  54. package/esm/store/crud.js +31 -25
  55. package/esm/store/form.d.ts +160 -0
  56. package/esm/store/form.js +15 -13
  57. package/esm/store/formItem.d.ts +4 -0
  58. package/esm/store/formItem.js +42 -26
  59. package/esm/store/iRenderer.js +3 -1
  60. package/esm/store/index.js +1 -1
  61. package/esm/store/list.js +1 -1
  62. package/esm/store/manager.js +1 -1
  63. package/esm/store/modal.js +1 -1
  64. package/esm/store/node.js +1 -1
  65. package/esm/store/pagination.js +1 -1
  66. package/esm/store/root.d.ts +1 -1
  67. package/esm/store/root.js +12 -5
  68. package/esm/store/service.js +38 -33
  69. package/esm/store/status.js +1 -1
  70. package/esm/store/table.d.ts +760 -21
  71. package/esm/store/table.js +157 -57
  72. package/esm/store/table2.js +11 -8
  73. package/esm/theme.d.ts +18 -31
  74. package/esm/theme.js +1 -1
  75. package/esm/utils/Animation.js +1 -1
  76. package/esm/utils/ColorScale.js +1 -1
  77. package/esm/utils/DataSchema.js +1 -1
  78. package/esm/utils/DataScope.js +1 -1
  79. package/esm/utils/RootClose.js +1 -1
  80. package/esm/utils/SimpleMap.js +1 -1
  81. package/esm/utils/api.d.ts +3 -3
  82. package/esm/utils/api.js +3 -2
  83. package/esm/utils/arraySlice.js +1 -1
  84. package/esm/utils/attachmentAdpator.js +1 -1
  85. package/esm/utils/autobind.js +1 -1
  86. package/esm/utils/columnsSplit.js +1 -1
  87. package/esm/utils/dataMapping.js +1 -1
  88. package/esm/utils/date.js +1 -1
  89. package/esm/utils/debug.d.ts +1 -0
  90. package/esm/utils/debug.js +24 -2
  91. package/esm/utils/decodeEntity.js +1 -1
  92. package/esm/utils/dom.js +1 -1
  93. package/esm/utils/errors.js +1 -1
  94. package/esm/utils/escapeHtml.js +1 -1
  95. package/esm/utils/filter-schema.js +1 -1
  96. package/esm/utils/filter.js +1 -1
  97. package/esm/utils/formatDuration.js +1 -1
  98. package/esm/utils/formula.js +1 -1
  99. package/esm/utils/getVariable.js +1 -1
  100. package/esm/utils/grammar.js +1 -1
  101. package/esm/utils/handleAction.js +1 -1
  102. package/esm/utils/helper.d.ts +13 -1
  103. package/esm/utils/helper.js +99 -5
  104. package/esm/utils/highlight.js +1 -1
  105. package/esm/utils/icon.js +1 -1
  106. package/esm/utils/image.js +1 -1
  107. package/esm/utils/isPureVariable.js +1 -1
  108. package/esm/utils/json-schema-2-amis-schema.js +1 -1
  109. package/esm/utils/keyToPath.d.ts +1 -1
  110. package/esm/utils/keyToPath.js +2 -1
  111. package/esm/utils/makeSorter.js +1 -1
  112. package/esm/utils/math.js +1 -1
  113. package/esm/utils/memoryParse.js +1 -1
  114. package/esm/utils/normalizeLink.js +1 -1
  115. package/esm/utils/normalizeOptions.js +1 -1
  116. package/esm/utils/object.js +1 -1
  117. package/esm/utils/offset.js +1 -1
  118. package/esm/utils/offsetParent.js +1 -1
  119. package/esm/utils/optionValueCompare.js +1 -1
  120. package/esm/utils/position.js +1 -1
  121. package/esm/utils/prettyBytes.js +1 -1
  122. package/esm/utils/renderer-event.js +2 -2
  123. package/esm/utils/replaceText.js +1 -1
  124. package/esm/utils/resize-sensor.d.ts +3 -1
  125. package/esm/utils/resize-sensor.js +34 -22
  126. package/esm/utils/resolveCondition.js +1 -1
  127. package/esm/utils/resolveVariable.js +1 -1
  128. package/esm/utils/resolveVariableAndFilter.js +1 -1
  129. package/esm/utils/resolveVariableAndFilterForAsync.js +1 -1
  130. package/esm/utils/scrollPosition.js +1 -1
  131. package/esm/utils/string2regExp.js +1 -1
  132. package/esm/utils/stripNumber.js +1 -1
  133. package/esm/utils/style-helper.d.ts +22 -14
  134. package/esm/utils/style-helper.js +181 -120
  135. package/esm/utils/style.js +1 -1
  136. package/esm/utils/toNumber.js +1 -1
  137. package/esm/utils/tokenize.js +1 -1
  138. package/esm/utils/tpl-builtin.js +1 -1
  139. package/esm/utils/tpl-lodash.js +1 -1
  140. package/esm/utils/tpl.js +1 -1
  141. package/esm/utils/uncontrollable.js +1 -1
  142. package/esm/utils/validations.js +1 -1
  143. package/lib/Root.js +1 -1
  144. package/lib/RootRenderer.js +8 -8
  145. package/lib/SchemaRenderer.js +16 -12
  146. package/lib/Scoped.js +3 -1
  147. package/lib/StatusScoped.js +1 -1
  148. package/lib/WithRootStore.js +1 -1
  149. package/lib/WithStore.js +9 -8
  150. package/lib/actions/Action.js +1 -1
  151. package/lib/actions/AjaxAction.js +2 -2
  152. package/lib/actions/BreakAction.js +1 -1
  153. package/lib/actions/BroadcastAction.js +1 -1
  154. package/lib/actions/CmptAction.js +1 -1
  155. package/lib/actions/ContinueAction.js +1 -1
  156. package/lib/actions/CopyAction.js +1 -1
  157. package/lib/actions/CustomAction.js +3 -1
  158. package/lib/actions/DialogAction.js +1 -1
  159. package/lib/actions/DrawerAction.js +5 -1
  160. package/lib/actions/EmailAction.js +1 -1
  161. package/lib/actions/LinkAction.js +1 -1
  162. package/lib/actions/LoopAction.js +1 -1
  163. package/lib/actions/PageAction.js +1 -1
  164. package/lib/actions/ParallelAction.js +1 -1
  165. package/lib/actions/StatusAction.js +1 -1
  166. package/lib/actions/SwitchAction.js +1 -1
  167. package/lib/actions/ToastAction.js +1 -1
  168. package/lib/components/CustomStyle.d.ts +5 -6
  169. package/lib/components/CustomStyle.js +46 -4
  170. package/lib/components/LazyComponent.d.ts +1 -2
  171. package/lib/components/LazyComponent.js +12 -9
  172. package/lib/components/Overlay.js +3 -1
  173. package/lib/components/PopOver.d.ts +12 -12
  174. package/lib/components/PopOver.js +3 -1
  175. package/lib/env.d.ts +2 -2
  176. package/lib/env.js +1 -1
  177. package/lib/envOverwrite.js +1 -1
  178. package/lib/factory.d.ts +7 -7
  179. package/lib/factory.js +1 -1
  180. package/lib/index.js +11 -3
  181. package/lib/locale.d.ts +1 -1
  182. package/lib/locale.js +3 -3
  183. package/lib/polyfills.js +1 -1
  184. package/lib/renderers/Form.d.ts +1 -1
  185. package/lib/renderers/Form.js +10 -8
  186. package/lib/renderers/Item.d.ts +24 -56
  187. package/lib/renderers/Item.js +26 -31
  188. package/lib/renderers/Options.js +14 -12
  189. package/lib/renderers/Placeholder.js +1 -1
  190. package/lib/renderers/builtin.js +1 -1
  191. package/lib/renderers/register.js +1 -1
  192. package/lib/renderers/wrapControl.js +70 -79
  193. package/lib/store/app.js +3 -1
  194. package/lib/store/combo.d.ts +384 -0
  195. package/lib/store/combo.js +1 -1
  196. package/lib/store/crud.js +31 -25
  197. package/lib/store/form.d.ts +160 -0
  198. package/lib/store/form.js +15 -13
  199. package/lib/store/formItem.d.ts +4 -0
  200. package/lib/store/formItem.js +41 -25
  201. package/lib/store/iRenderer.js +3 -1
  202. package/lib/store/index.js +1 -1
  203. package/lib/store/list.js +1 -1
  204. package/lib/store/manager.js +1 -1
  205. package/lib/store/modal.js +1 -1
  206. package/lib/store/node.js +1 -1
  207. package/lib/store/pagination.js +1 -1
  208. package/lib/store/root.d.ts +1 -1
  209. package/lib/store/root.js +11 -4
  210. package/lib/store/service.js +38 -33
  211. package/lib/store/status.js +1 -1
  212. package/lib/store/table.d.ts +760 -21
  213. package/lib/store/table.js +157 -57
  214. package/lib/store/table2.js +11 -8
  215. package/lib/theme.d.ts +18 -31
  216. package/lib/theme.js +1 -1
  217. package/lib/utils/Animation.js +1 -1
  218. package/lib/utils/ColorScale.js +1 -1
  219. package/lib/utils/DataSchema.js +1 -1
  220. package/lib/utils/DataScope.js +1 -1
  221. package/lib/utils/RootClose.js +1 -1
  222. package/lib/utils/SimpleMap.js +1 -1
  223. package/lib/utils/api.d.ts +3 -3
  224. package/lib/utils/api.js +3 -2
  225. package/lib/utils/arraySlice.js +1 -1
  226. package/lib/utils/attachmentAdpator.js +1 -1
  227. package/lib/utils/autobind.js +1 -1
  228. package/lib/utils/columnsSplit.js +1 -1
  229. package/lib/utils/dataMapping.js +1 -1
  230. package/lib/utils/date.js +1 -1
  231. package/lib/utils/debug.d.ts +1 -0
  232. package/lib/utils/debug.js +24 -1
  233. package/lib/utils/decodeEntity.js +1 -1
  234. package/lib/utils/dom.js +1 -1
  235. package/lib/utils/errors.js +1 -1
  236. package/lib/utils/escapeHtml.js +1 -1
  237. package/lib/utils/filter-schema.js +1 -1
  238. package/lib/utils/filter.js +1 -1
  239. package/lib/utils/formatDuration.js +1 -1
  240. package/lib/utils/formula.js +1 -1
  241. package/lib/utils/getVariable.js +1 -1
  242. package/lib/utils/grammar.js +1 -1
  243. package/lib/utils/handleAction.js +1 -1
  244. package/lib/utils/helper.d.ts +13 -1
  245. package/lib/utils/helper.js +101 -4
  246. package/lib/utils/highlight.js +1 -1
  247. package/lib/utils/icon.js +1 -1
  248. package/lib/utils/image.js +1 -1
  249. package/lib/utils/isPureVariable.js +1 -1
  250. package/lib/utils/json-schema-2-amis-schema.js +1 -1
  251. package/lib/utils/keyToPath.d.ts +1 -1
  252. package/lib/utils/keyToPath.js +2 -1
  253. package/lib/utils/makeSorter.js +1 -1
  254. package/lib/utils/math.js +1 -1
  255. package/lib/utils/memoryParse.js +1 -1
  256. package/lib/utils/normalizeLink.js +1 -1
  257. package/lib/utils/normalizeOptions.js +1 -1
  258. package/lib/utils/object.js +1 -1
  259. package/lib/utils/offset.js +1 -1
  260. package/lib/utils/offsetParent.js +1 -1
  261. package/lib/utils/optionValueCompare.js +1 -1
  262. package/lib/utils/position.js +1 -1
  263. package/lib/utils/prettyBytes.js +1 -1
  264. package/lib/utils/renderer-event.js +2 -2
  265. package/lib/utils/replaceText.js +1 -1
  266. package/lib/utils/resize-sensor.d.ts +3 -1
  267. package/lib/utils/resize-sensor.js +34 -22
  268. package/lib/utils/resolveCondition.js +1 -1
  269. package/lib/utils/resolveVariable.js +1 -1
  270. package/lib/utils/resolveVariableAndFilter.js +1 -1
  271. package/lib/utils/resolveVariableAndFilterForAsync.js +1 -1
  272. package/lib/utils/scrollPosition.js +1 -1
  273. package/lib/utils/string2regExp.js +1 -1
  274. package/lib/utils/stripNumber.js +1 -1
  275. package/lib/utils/style-helper.d.ts +22 -14
  276. package/lib/utils/style-helper.js +188 -120
  277. package/lib/utils/style.js +1 -1
  278. package/lib/utils/toNumber.js +1 -1
  279. package/lib/utils/tokenize.js +1 -1
  280. package/lib/utils/tpl-builtin.js +1 -1
  281. package/lib/utils/tpl-lodash.js +1 -1
  282. package/lib/utils/tpl.js +1 -1
  283. package/lib/utils/uncontrollable.js +1 -1
  284. package/lib/utils/validations.js +1 -1
  285. package/package.json +5 -5
@@ -1,10 +1,8 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
- import { __spreadArray, __read } from 'tslib';
7
-
8
6
  /**
9
7
  * @file resize-sensor.js.
10
8
  * @author fex
@@ -13,16 +11,22 @@ var EventQueue = /** @class */ (function () {
13
11
  function EventQueue() {
14
12
  this.q = [];
15
13
  }
16
- EventQueue.prototype.add = function (cb) {
17
- this.q.push(cb);
14
+ EventQueue.prototype.add = function (cb, type) {
15
+ if (type === void 0) { type = 'both'; }
16
+ this.q.push({
17
+ fn: cb,
18
+ type: type
19
+ });
18
20
  };
19
- EventQueue.prototype.call = function () {
21
+ EventQueue.prototype.call = function (type) {
20
22
  var args = [];
21
- for (var _i = 0; _i < arguments.length; _i++) {
22
- args[_i] = arguments[_i];
23
+ for (var _i = 1; _i < arguments.length; _i++) {
24
+ args[_i - 1] = arguments[_i];
23
25
  }
24
- this.q.forEach(function (fn) {
25
- fn.apply(void 0, __spreadArray([], __read(args), false));
26
+ this.q.forEach(function (item) {
27
+ if (item.type === type || item.type === 'both' || type === 'both') {
28
+ item.fn.apply(null, args);
29
+ }
26
30
  });
27
31
  };
28
32
  return EventQueue;
@@ -39,16 +43,17 @@ function getComputedStyle(element, prop) {
39
43
  return element.style[prop];
40
44
  }
41
45
  }
42
- function attachResizeEvent(element, resized) {
46
+ function attachResizeEvent(element, resized, type) {
47
+ if (type === void 0) { type = 'both'; }
43
48
  if (!element) {
44
49
  return;
45
50
  }
46
51
  if (!element.resizedAttached) {
47
52
  element.resizedAttached = new EventQueue();
48
- element.resizedAttached.add(resized);
53
+ element.resizedAttached.add(resized, type);
49
54
  }
50
55
  else if (element.resizedAttached) {
51
- element.resizedAttached.add(resized);
56
+ element.resizedAttached.add(resized, type);
52
57
  return;
53
58
  }
54
59
  var resizeSensor = (element.resizeSensor =
@@ -90,9 +95,10 @@ function attachResizeEvent(element, resized) {
90
95
  }
91
96
  };
92
97
  reset();
93
- var changed = function () {
98
+ var changed = function (type) {
99
+ if (type === void 0) { type = 'both'; }
94
100
  if (element.resizedAttached) {
95
- element.resizedAttached.call();
101
+ element.resizedAttached.call(type);
96
102
  }
97
103
  };
98
104
  var addEvent = function (el, name, cb) {
@@ -112,9 +118,14 @@ function attachResizeEvent(element, resized) {
112
118
  }
113
119
  };
114
120
  var onScroll = function (e) {
115
- if (element.offsetWidth != lastWidth ||
116
- element.offsetHeight != lastHeight) {
117
- changed();
121
+ var widthChanged = element.offsetWidth != lastWidth;
122
+ var heightChanged = element.offsetHeight != lastHeight;
123
+ if (widthChanged || heightChanged) {
124
+ changed(widthChanged && heightChanged
125
+ ? 'both'
126
+ : widthChanged
127
+ ? 'width'
128
+ : 'height');
118
129
  }
119
130
  reset();
120
131
  };
@@ -146,8 +157,9 @@ function detach(element) {
146
157
  delete element.originPosition;
147
158
  }
148
159
  }
149
- function resizeSensor(element, callback, once) {
160
+ function resizeSensor(element, callback, once, type) {
150
161
  if (once === void 0) { once = false; }
162
+ if (type === void 0) { type = 'both'; }
151
163
  if (!element) {
152
164
  return function () { };
153
165
  }
@@ -157,10 +169,10 @@ function resizeSensor(element, callback, once) {
157
169
  callback.apply(this, arguments);
158
170
  disposeEvent === null || disposeEvent === void 0 ? void 0 : disposeEvent();
159
171
  detach(element);
160
- });
161
- return;
172
+ }, type);
173
+ return function () { };
162
174
  }
163
- disposeEvent = attachResizeEvent(element, callback);
175
+ disposeEvent = attachResizeEvent(element, callback, type);
164
176
  var detached = false;
165
177
  return function () {
166
178
  if (detached)
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -7,19 +7,10 @@ interface extra {
7
7
  pre?: string;
8
8
  suf?: string;
9
9
  }
10
- export declare function findOrCreactStyle(id: string): HTMLElement;
11
- export declare function insertStyle(style: string, id: string): void;
10
+ export declare function findOrCreateStyle(id: string, doc?: Document): HTMLElement;
11
+ export declare function insertStyle(style: string, id: string, doc?: Document): void;
12
12
  export declare function addStyle(style: string, id: string): void;
13
- export declare function formatStyle(themeCss: any, classNames: {
14
- key: string;
15
- value?: string;
16
- weights?: {
17
- default?: extra;
18
- hover?: extra;
19
- active?: extra;
20
- disabled?: extra;
21
- };
22
- }[], id?: string, defaultData?: any): {
13
+ export declare function formatStyle(themeCss: any, classNames?: CustomStyleClassName[], id?: string, defaultData?: any): {
23
14
  value: string;
24
15
  origin: {
25
16
  className: string;
@@ -28,7 +19,6 @@ export declare function formatStyle(themeCss: any, classNames: {
28
19
  };
29
20
  export interface CustomStyleClassName {
30
21
  key: string;
31
- value?: string;
32
22
  weights?: {
33
23
  default?: extra;
34
24
  hover?: extra;
@@ -36,9 +26,27 @@ export interface CustomStyleClassName {
36
26
  disabled?: extra;
37
27
  };
38
28
  }
39
- export declare function insertCustomStyle(themeCss: any, classNames: CustomStyleClassName[], id?: string, defaultData?: any, customStyleClassPrefix?: string): void;
29
+ export declare function insertCustomStyle(themeCss: any, classNames: CustomStyleClassName[], id: string, defaultData?: any, customStyleClassPrefix?: string, doc?: Document): void;
40
30
  /**
41
31
  * 根据路径获取默认值
42
32
  */
43
33
  export declare function getValueByPath(path: string, data: any): any;
34
+ /**
35
+ * 设置源码编辑自定义样式
36
+ */
37
+ export declare function insertEditCustomStyle(customStyle: any, id?: string, doc?: Document): void;
38
+ export interface InsertCustomStyle {
39
+ themeCss: any;
40
+ classNames: CustomStyleClassName[];
41
+ id?: string;
42
+ defaultData?: any;
43
+ customStyleClassPrefix?: string;
44
+ doc?: Document;
45
+ }
46
+ /**
47
+ * 移除自定义样式
48
+ */
49
+ export declare function removeCustomStyle(type: string, id: string, doc?: Document): void;
50
+ export declare function formatInputThemeCss(themeCss: any): any;
51
+ export declare function setThemeClassName(name: string, id?: string, themeCss?: any, extra?: string): string;
44
52
  export {};
@@ -1,11 +1,14 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
6
6
  import { __values } from 'tslib';
7
7
  import { uuid } from './helper.js';
8
8
  import cloneDeep from 'lodash/cloneDeep';
9
+ import isObject from 'lodash/isObject';
10
+ import map from 'lodash/map';
11
+ import isEmpty from 'lodash/isEmpty';
9
12
 
10
13
  var valueMap = {
11
14
  'marginTop': 'margin-top',
@@ -36,22 +39,26 @@ var inheritValueMap = {
36
39
  background: 'bg-color',
37
40
  radius: 'border'
38
41
  };
39
- function findOrCreactStyle(id) {
40
- var varStyleTag = document.getElementById(id);
42
+ function findOrCreateStyle(id, doc) {
43
+ doc = doc || document;
44
+ var varStyleTag = doc.getElementById(id);
41
45
  if (!varStyleTag) {
42
- varStyleTag = document.createElement('style');
46
+ varStyleTag = doc.createElement('style');
43
47
  varStyleTag.id = id;
44
- document.body.appendChild(varStyleTag);
48
+ doc.body.appendChild(varStyleTag);
45
49
  }
46
50
  return varStyleTag;
47
51
  }
48
- function insertStyle(style, id) {
49
- var varStyleTag = findOrCreactStyle(id);
52
+ function insertStyle(style, id, doc) {
53
+ var varStyleTag = findOrCreateStyle(id, doc);
50
54
  // bca-disable-line
51
55
  varStyleTag.innerHTML = style;
56
+ if (!style) {
57
+ varStyleTag.remove();
58
+ }
52
59
  }
53
60
  function addStyle(style, id) {
54
- var varStyleTag = findOrCreactStyle(id);
61
+ var varStyleTag = findOrCreateStyle(id);
55
62
  // bca-disable-line
56
63
  varStyleTag.innerHTML += style;
57
64
  }
@@ -62,9 +69,9 @@ function handleInheritData(statusMap, data) {
62
69
  }
63
70
  // 检查是否存在inherit
64
71
  ['hover', 'active'].forEach(function (status) {
65
- for (var key in statusMap[status]) {
72
+ Object.keys(statusMap[status]).forEach(function (key) {
66
73
  if (typeof statusMap[status][key] === 'object') {
67
- for (var style in statusMap[status][key]) {
74
+ Object.keys(statusMap[status][key]).forEach(function (style) {
68
75
  if (statusMap[status][key][style] === 'inherit') {
69
76
  // 值为inherit时设置为default的值或者主题中的default值
70
77
  if (statusMap['default'][key] && statusMap['default'][key][style]) {
@@ -76,7 +83,7 @@ function handleInheritData(statusMap, data) {
76
83
  data['default'].body[value][style];
77
84
  }
78
85
  }
79
- }
86
+ });
80
87
  }
81
88
  else {
82
89
  if (statusMap[status][key] === 'inherit') {
@@ -89,13 +96,13 @@ function handleInheritData(statusMap, data) {
89
96
  }
90
97
  }
91
98
  }
92
- }
99
+ });
93
100
  });
94
101
  }
95
102
  function formatStyle(themeCss, classNames, id, defaultData) {
96
103
  var e_1, _a;
97
- var _b;
98
- if (!themeCss) {
104
+ // 没有具体的样式,或者没有对应的classname
105
+ if (!themeCss || !classNames) {
99
106
  return { value: '', origin: [] };
100
107
  }
101
108
  var res = [];
@@ -106,124 +113,97 @@ function formatStyle(themeCss, classNames, id, defaultData) {
106
113
  disabled: '.is-disabled'
107
114
  };
108
115
  var _loop_1 = function (item) {
109
- var e_2, _c;
110
116
  var body = themeCss[item.key];
111
- var list = (_b = item.value) === null || _b === void 0 ? void 0 : _b.split(' ');
112
- var classNameList = [];
113
117
  if (!body) {
114
118
  return "continue";
115
119
  }
116
- list === null || list === void 0 ? void 0 : list.forEach(function (n) {
117
- if (/(\S*[C|c]lassName-\S*)/.test(n) &&
118
- !!~n.indexOf((id === null || id === void 0 ? void 0 : id.replace('u:', '').replace('-label', '').replace('-description', '').replace('-addOn', '').replace('-icon', '').replace('-inner', '')) || '')) {
119
- classNameList.push(n);
120
- }
121
- });
120
+ var className = item.key + '-' + (id === null || id === void 0 ? void 0 : id.replace('u:', ''));
122
121
  var weightsList = item.weights || {};
123
- try {
124
- for (var classNameList_1 = (e_2 = void 0, __values(classNameList)), classNameList_1_1 = classNameList_1.next(); !classNameList_1_1.done; classNameList_1_1 = classNameList_1.next()) {
125
- var className = classNameList_1_1.value;
126
- // 没有具体的样式,或者没有对应的classname
127
- var statusMap = {
128
- default: {},
129
- hover: {},
130
- active: {},
131
- disabled: {}
132
- };
133
- for (var key in body) {
134
- if (key === '$$id') {
135
- continue;
136
- }
137
- if (!!~key.indexOf(':default')) {
138
- statusMap.default[key.replace(':default', '')] = body[key];
139
- }
140
- else if (!!~key.indexOf(':hover')) {
141
- statusMap.hover[key.replace(':hover', '')] = body[key];
142
- }
143
- else if (!!~key.indexOf(':active')) {
144
- statusMap.active[key.replace(':active', '')] = body[key];
145
- }
146
- else if (!!~key.indexOf(':disabled')) {
147
- statusMap.disabled[key.replace(':disabled', '')] = body[key];
148
- }
149
- else {
150
- statusMap.default[key] = body[key];
151
- }
122
+ var statusMap = {
123
+ default: {},
124
+ hover: {},
125
+ active: {},
126
+ disabled: {}
127
+ };
128
+ Object.keys(body).forEach(function (key) {
129
+ if (key !== '$$id' && body[key]) {
130
+ if (!!~key.indexOf(':default')) {
131
+ statusMap.default[key.replace(':default', '')] = body[key];
152
132
  }
153
- handleInheritData(statusMap, defaultData);
154
- var _loop_2 = function (status_1) {
155
- var weights = weightsList[status_1];
156
- var styles = [];
157
- var fn = function (key, value) {
158
- key = valueMap[key] || key;
159
- styles.push("".concat(key, ": ").concat(value, ";"));
160
- };
161
- for (var key in statusMap[status_1]) {
162
- if (key === '$$id') {
163
- continue;
133
+ else if (!!~key.indexOf(':hover')) {
134
+ statusMap.hover[key.replace(':hover', '')] = body[key];
135
+ }
136
+ else if (!!~key.indexOf(':active')) {
137
+ statusMap.active[key.replace(':active', '')] = body[key];
138
+ }
139
+ else if (!!~key.indexOf(':disabled')) {
140
+ statusMap.disabled[key.replace(':disabled', '')] = body[key];
141
+ }
142
+ else {
143
+ statusMap.default[key] = body[key];
144
+ }
145
+ }
146
+ });
147
+ handleInheritData(statusMap, defaultData);
148
+ Object.keys(statusMap).forEach(function (status) {
149
+ var weights = weightsList[status];
150
+ var styles = [];
151
+ var fn = function (key, value) {
152
+ key = valueMap[key] || key;
153
+ styles.push("".concat(key, ": ").concat(value, ";"));
154
+ };
155
+ Object.keys(statusMap[status]).forEach(function (key) {
156
+ if (key !== '$$id') {
157
+ var style_1 = statusMap[status][key];
158
+ if (typeof style_1 === 'object') {
159
+ // 圆角特殊处理
160
+ if (key === 'radius') {
161
+ fn('border-radius', [
162
+ style_1['top-left-border-radius'] || 0,
163
+ style_1['top-right-border-radius'] || 0,
164
+ style_1['bottom-right-border-radius'] || 0,
165
+ style_1['bottom-left-border-radius'] || 0
166
+ ].join(' '));
164
167
  }
165
- var style = statusMap[status_1][key];
166
- if (typeof style === 'object') {
167
- // 圆角特殊处理
168
- if (key === 'radius') {
169
- fn('border-radius', [
170
- style['top-left-border-radius'],
171
- style['top-right-border-radius'],
172
- style['bottom-right-border-radius'],
173
- style['bottom-left-border-radius']
174
- ].join(' '));
175
- }
176
- else {
177
- for (var k in style) {
178
- if (k === '$$id') {
179
- continue;
180
- }
181
- var value = style[k];
168
+ else {
169
+ Object.keys(style_1).forEach(function (k) {
170
+ if (k !== '$$id') {
171
+ var value = style_1[k];
182
172
  value && fn(k, value);
183
173
  }
184
- }
174
+ });
175
+ }
176
+ }
177
+ else {
178
+ var value = style_1;
179
+ if (key === 'iconSize') {
180
+ fn('width', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
181
+ fn('height', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
182
+ fn('font-size', value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
185
183
  }
186
184
  else {
187
- var value = style;
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
- }
185
+ value &&
186
+ fn(key, value + ((weights === null || weights === void 0 ? void 0 : weights.important) ? ' !important' : ''));
197
187
  }
198
188
  }
199
- if (styles.length > 0) {
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) || '';
202
- res.push({
203
- className: cx + status2string[status_1] + inner,
204
- content: ".".concat(cx + status2string[status_1], " ").concat(inner, "{\n ").concat(styles.join('\n '), "\n}")
205
- });
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
- // }
213
- }
214
- };
215
- for (var status_1 in statusMap) {
216
- _loop_2(status_1);
217
189
  }
190
+ });
191
+ if (styles.length > 0) {
192
+ var cx = ((weights === null || weights === void 0 ? void 0 : weights.pre) || '') + className + ((weights === null || weights === void 0 ? void 0 : weights.suf) || '');
193
+ var inner = (weights === null || weights === void 0 ? void 0 : weights.inner) || '';
194
+ res.push({
195
+ className: cx + status2string[status] + inner,
196
+ content: ".".concat(cx + status2string[status], " ").concat(inner, "{\n ").concat(styles.join('\n '), "\n}")
197
+ });
198
+ // TODO:切换状态暂时先不改变组件的样式
199
+ // if (['hover', 'active', 'disabled'].includes(status)) {
200
+ // res.push({
201
+ // className: cx + '.' + status,
202
+ // content: `.${cx}.${status} {\n ${styles.join('\n ')}\n}`
203
+ // });
204
+ // }
218
205
  }
219
- }
220
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
221
- finally {
222
- try {
223
- if (classNameList_1_1 && !classNameList_1_1.done && (_c = classNameList_1.return)) _c.call(classNameList_1);
224
- }
225
- finally { if (e_2) throw e_2.error; }
226
- }
206
+ });
227
207
  };
228
208
  try {
229
209
  for (var classNames_1 = __values(classNames), classNames_1_1 = classNames_1.next(); !classNames_1_1.done; classNames_1_1 = classNames_1.next()) {
@@ -243,7 +223,7 @@ function formatStyle(themeCss, classNames, id, defaultData) {
243
223
  origin: res
244
224
  };
245
225
  }
246
- function insertCustomStyle(themeCss, classNames, id, defaultData, customStyleClassPrefix) {
226
+ function insertCustomStyle(themeCss, classNames, id, defaultData, customStyleClassPrefix, doc) {
247
227
  if (!themeCss) {
248
228
  return;
249
229
  }
@@ -252,7 +232,7 @@ function insertCustomStyle(themeCss, classNames, id, defaultData, customStyleCla
252
232
  value = customStyleClassPrefix
253
233
  ? "".concat(customStyleClassPrefix, " ").concat(value)
254
234
  : value;
255
- insertStyle(value, (id === null || id === void 0 ? void 0 : id.replace('u:', '')) || uuid());
235
+ insertStyle(value, id.replace('u:', ''), doc);
256
236
  }
257
237
  }
258
238
  /**
@@ -274,5 +254,86 @@ function getValueByPath(path, data) {
274
254
  return null;
275
255
  }
276
256
  }
257
+ // 递归处理嵌套的样式,转化成一维对象
258
+ function traverseStyle(style, path, result) {
259
+ Object.keys(style).forEach(function (key) {
260
+ if (key !== '$$id') {
261
+ if (isObject(style[key])) {
262
+ var nowPath = path ? "".concat(path, " ").concat(key) : key;
263
+ traverseStyle(style[key], nowPath, result);
264
+ }
265
+ else if (path === '') {
266
+ !result[key] && (result[key] = {});
267
+ result[key] = style[key];
268
+ }
269
+ else {
270
+ !result[path] && (result[path] = {});
271
+ result[path][key] = style[key];
272
+ }
273
+ }
274
+ });
275
+ }
276
+ /**
277
+ * 设置源码编辑自定义样式
278
+ */
279
+ function insertEditCustomStyle(customStyle, id, doc) {
280
+ var styles = {};
281
+ traverseStyle(customStyle, '', styles);
282
+ var content = '';
283
+ if (!isEmpty(styles)) {
284
+ var className_1 = "wrapperCustomStyle-".concat(id === null || id === void 0 ? void 0 : id.replace('u:', ''));
285
+ Object.keys(styles).forEach(function (key) {
286
+ if (!isObject(styles[key])) {
287
+ content += "\n.".concat(className_1, " {\n ").concat(key, ": ").concat(styles[key], "\n}");
288
+ }
289
+ else if (key === 'root') {
290
+ var res = map(styles[key], function (value, key) { return "".concat(key, ": ").concat(value, ";"); });
291
+ content += "\n.".concat(className_1, " {\n ").concat(res.join('\n '), "\n}");
292
+ }
293
+ else if (/^root:/.test(key)) {
294
+ var res = map(styles[key], function (value, key) { return "".concat(key, ": ").concat(value, ";"); });
295
+ var nowKey = key.replace('root', '');
296
+ content += "\n.".concat(className_1, " ").concat(nowKey, " {\n ").concat(res.join('\n '), "\n}");
297
+ }
298
+ else {
299
+ var res = map(styles[key], function (value, key) { return "".concat(key, ": ").concat(value, ";"); });
300
+ content += "\n.".concat(className_1, " ").concat(key, " {\n ").concat(res.join('\n '), "\n}");
301
+ }
302
+ });
303
+ }
304
+ insertStyle(content, 'wrapperCustomStyle-' + ((id === null || id === void 0 ? void 0 : id.replace('u:', '')) || uuid()), doc);
305
+ }
306
+ /**
307
+ * 移除自定义样式
308
+ */
309
+ function removeCustomStyle(type, id, doc) {
310
+ var style = (doc || document).getElementById((type ? type + '-' : '') + id.replace('u:', ''));
311
+ if (style) {
312
+ style.remove();
313
+ }
314
+ }
315
+ function formatInputThemeCss(themeCss) {
316
+ if (!themeCss) {
317
+ return;
318
+ }
319
+ var inputFontThemeCss = { inputControlClassName: {} };
320
+ var inputControlClassNameObject = (themeCss === null || themeCss === void 0 ? void 0 : themeCss.inputControlClassName) || {};
321
+ Object.keys(inputControlClassNameObject).forEach(function (key) {
322
+ if (~key.indexOf('font')) {
323
+ inputFontThemeCss.inputControlClassName[key] =
324
+ inputControlClassNameObject[key];
325
+ }
326
+ });
327
+ return inputFontThemeCss;
328
+ }
329
+ function setThemeClassName(name, id, themeCss, extra) {
330
+ if (!id || !themeCss) {
331
+ return '';
332
+ }
333
+ if (name !== 'wrapperCustomStyle' && !themeCss[name]) {
334
+ return '';
335
+ }
336
+ return "".concat(name, "-").concat(id.replace('u:', '')) + (extra ? "-".concat(extra) : '');
337
+ }
277
338
 
278
- export { addStyle, findOrCreactStyle, formatStyle, getValueByPath, inheritValueMap, insertCustomStyle, insertStyle, valueMap };
339
+ export { addStyle, findOrCreateStyle, formatInputThemeCss, formatStyle, getValueByPath, inheritValueMap, insertCustomStyle, insertEditCustomStyle, insertStyle, removeCustomStyle, setThemeClassName, valueMap };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * amis-core v3.4.0
2
+ * amis-core v3.4.2
3
3
  * Copyright 2018-2023 fex
4
4
  */
5
5