@yelon/util 12.0.16 → 12.0.17

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 (224) hide show
  1. package/LICENSE +21 -21
  2. package/array/array-type.service.d.ts +68 -68
  3. package/array/array.service.d.ts +75 -75
  4. package/array/index.d.ts +2 -2
  5. package/array/yelon-util-array.d.ts +4 -4
  6. package/browser/browser.d.ts +4 -4
  7. package/browser/cookie.service.d.ts +64 -64
  8. package/browser/copy.d.ts +6 -6
  9. package/browser/index.d.ts +5 -5
  10. package/browser/is-empty.d.ts +6 -6
  11. package/browser/scroll.service.d.ts +34 -34
  12. package/browser/style.d.ts +21 -21
  13. package/bundles/browser.umd.js +275 -275
  14. package/bundles/yelon-util-array.umd.js +602 -602
  15. package/bundles/yelon-util-config.umd.js +366 -366
  16. package/bundles/yelon-util-date-time.umd.js +216 -216
  17. package/bundles/yelon-util-decorator.umd.js +437 -437
  18. package/bundles/yelon-util-form.umd.js +116 -116
  19. package/bundles/yelon-util-format.umd.js +726 -726
  20. package/bundles/yelon-util-math.umd.js +83 -83
  21. package/bundles/yelon-util-other.umd.js +652 -652
  22. package/bundles/yelon-util-pipes-currency.umd.js +83 -83
  23. package/bundles/yelon-util-pipes-filter.umd.js +353 -353
  24. package/bundles/yelon-util-pipes-format.umd.js +47 -47
  25. package/bundles/yelon-util-pipes.umd.js +7 -7
  26. package/bundles/yelon-util-token.umd.js +30 -30
  27. package/bundles/yelon-util.umd.js +7 -7
  28. package/config/abc/date-picker.type.d.ts +52 -52
  29. package/config/abc/error-collect.type.d.ts +10 -10
  30. package/config/abc/image.type.d.ts +15 -15
  31. package/config/abc/index.d.ts +16 -16
  32. package/config/abc/loading.type.d.ts +31 -31
  33. package/config/abc/lodop.type.d.ts +33 -33
  34. package/config/abc/media.type.d.ts +11 -11
  35. package/config/abc/onboarding.type.d.ts +4 -4
  36. package/config/abc/page-header.type.d.ts +39 -39
  37. package/config/abc/pdf.type.d.ts +35 -35
  38. package/config/abc/qr.type.d.ts +25 -25
  39. package/config/abc/se.type.d.ts +32 -32
  40. package/config/abc/sg.type.d.ts +10 -10
  41. package/config/abc/st.type.d.ts +427 -427
  42. package/config/abc/sv.type.d.ts +14 -14
  43. package/config/abc/xlsx.type.d.ts +12 -12
  44. package/config/abc/zip.type.d.ts +10 -10
  45. package/config/acl/acl.type.d.ts +32 -32
  46. package/config/auth/auth.type.d.ts +55 -55
  47. package/config/bis/bis.type.d.ts +7 -7
  48. package/config/cache/cache.type.d.ts +40 -40
  49. package/config/chart/chart.type.d.ts +33 -33
  50. package/config/config.service.d.ts +10 -10
  51. package/config/config.types.d.ts +49 -49
  52. package/config/index.d.ts +14 -14
  53. package/config/mock/mock.type.d.ts +18 -18
  54. package/config/sf/sf.type.d.ts +127 -127
  55. package/config/stomp/stomp.type.d.ts +2 -2
  56. package/config/theme/http.type.d.ts +14 -14
  57. package/config/theme/i18n.type.d.ts +8 -8
  58. package/config/theme/index.d.ts +3 -3
  59. package/config/theme/responsive.type.d.ts +12 -12
  60. package/config/util/array.type.d.ts +22 -22
  61. package/config/util/currency.type.d.ts +39 -39
  62. package/config/yelon-util-config.d.ts +4 -4
  63. package/date-time/index.d.ts +2 -2
  64. package/date-time/picker.d.ts +68 -68
  65. package/date-time/time.d.ts +26 -26
  66. package/date-time/yelon-util-date-time.d.ts +4 -4
  67. package/decorator/convert.d.ts +24 -24
  68. package/decorator/index.d.ts +2 -2
  69. package/decorator/yelon-util-decorator.d.ts +4 -4
  70. package/decorator/zone-outside.d.ts +35 -35
  71. package/esm2015/array/array-type.service.js +1 -1
  72. package/esm2015/array/array.service.js +249 -249
  73. package/esm2015/array/index.js +2 -2
  74. package/esm2015/array/yelon-util-array.js +4 -4
  75. package/esm2015/browser/browser.js +4 -4
  76. package/esm2015/browser/cookie.service.js +103 -103
  77. package/esm2015/browser/copy.js +26 -26
  78. package/esm2015/browser/index.js +5 -5
  79. package/esm2015/browser/is-empty.js +18 -18
  80. package/esm2015/browser/scroll.service.js +88 -88
  81. package/esm2015/browser/style.js +37 -37
  82. package/esm2015/config/abc/date-picker.type.js +1 -1
  83. package/esm2015/config/abc/error-collect.type.js +1 -1
  84. package/esm2015/config/abc/image.type.js +1 -1
  85. package/esm2015/config/abc/index.js +16 -16
  86. package/esm2015/config/abc/loading.type.js +1 -1
  87. package/esm2015/config/abc/lodop.type.js +1 -1
  88. package/esm2015/config/abc/media.type.js +1 -1
  89. package/esm2015/config/abc/onboarding.type.js +1 -1
  90. package/esm2015/config/abc/page-header.type.js +1 -1
  91. package/esm2015/config/abc/pdf.type.js +1 -1
  92. package/esm2015/config/abc/qr.type.js +1 -1
  93. package/esm2015/config/abc/se.type.js +1 -1
  94. package/esm2015/config/abc/sg.type.js +1 -1
  95. package/esm2015/config/abc/st.type.js +1 -1
  96. package/esm2015/config/abc/sv.type.js +2 -2
  97. package/esm2015/config/abc/xlsx.type.js +1 -1
  98. package/esm2015/config/abc/zip.type.js +1 -1
  99. package/esm2015/config/acl/acl.type.js +1 -1
  100. package/esm2015/config/auth/auth.type.js +1 -1
  101. package/esm2015/config/bis/bis.type.js +1 -1
  102. package/esm2015/config/cache/cache.type.js +1 -1
  103. package/esm2015/config/chart/chart.type.js +1 -1
  104. package/esm2015/config/config.service.js +33 -33
  105. package/esm2015/config/config.types.js +8 -8
  106. package/esm2015/config/index.js +14 -14
  107. package/esm2015/config/mock/mock.type.js +1 -1
  108. package/esm2015/config/sf/sf.type.js +1 -1
  109. package/esm2015/config/stomp/stomp.type.js +1 -1
  110. package/esm2015/config/theme/http.type.js +1 -1
  111. package/esm2015/config/theme/i18n.type.js +1 -1
  112. package/esm2015/config/theme/index.js +3 -3
  113. package/esm2015/config/theme/responsive.type.js +1 -1
  114. package/esm2015/config/util/array.type.js +1 -1
  115. package/esm2015/config/util/currency.type.js +1 -1
  116. package/esm2015/config/yelon-util-config.js +4 -4
  117. package/esm2015/date-time/index.js +2 -2
  118. package/esm2015/date-time/picker.js +115 -115
  119. package/esm2015/date-time/time.js +83 -83
  120. package/esm2015/date-time/yelon-util-date-time.js +4 -4
  121. package/esm2015/decorator/convert.js +55 -55
  122. package/esm2015/decorator/index.js +2 -2
  123. package/esm2015/decorator/yelon-util-decorator.js +4 -4
  124. package/esm2015/decorator/zone-outside.js +54 -54
  125. package/esm2015/form/index.js +2 -2
  126. package/esm2015/form/match-control.js +29 -29
  127. package/esm2015/form/validators.js +80 -80
  128. package/esm2015/form/yelon-util-form.js +4 -4
  129. package/esm2015/format/currency.service.js +224 -224
  130. package/esm2015/format/currency.types.js +7 -7
  131. package/esm2015/format/index.js +4 -4
  132. package/esm2015/format/string.js +75 -75
  133. package/esm2015/format/validate.js +93 -93
  134. package/esm2015/format/yelon-util-format.js +4 -4
  135. package/esm2015/index.js +11 -11
  136. package/esm2015/math/in-range.js +24 -24
  137. package/esm2015/math/index.js +2 -2
  138. package/esm2015/math/round.js +52 -52
  139. package/esm2015/math/yelon-util-math.js +4 -4
  140. package/esm2015/other/assert.js +66 -66
  141. package/esm2015/other/deep.js +75 -75
  142. package/esm2015/other/index.js +4 -4
  143. package/esm2015/other/lazy.service.js +117 -117
  144. package/esm2015/other/logger.js +32 -32
  145. package/esm2015/other/yelon-util-other.js +4 -4
  146. package/esm2015/pipes/currency/cny.pipe.js +21 -21
  147. package/esm2015/pipes/currency/index.js +3 -3
  148. package/esm2015/pipes/currency/mega.pipe.js +25 -25
  149. package/esm2015/pipes/currency/module.js +13 -13
  150. package/esm2015/pipes/currency/price.pipe.js +25 -25
  151. package/esm2015/pipes/currency/yelon-util-pipes-currency.js +5 -5
  152. package/esm2015/pipes/filter/filter.pipe.js +14 -14
  153. package/esm2015/pipes/filter/index.js +2 -2
  154. package/esm2015/pipes/filter/module.js +11 -11
  155. package/esm2015/pipes/filter/yelon-util-pipes-filter.js +4 -4
  156. package/esm2015/pipes/format/index.js +2 -2
  157. package/esm2015/pipes/format/mask.pipe.js +29 -29
  158. package/esm2015/pipes/format/module.js +11 -11
  159. package/esm2015/pipes/format/yelon-util-pipes-format.js +4 -4
  160. package/esm2015/pipes/index.js +3 -3
  161. package/esm2015/pipes/yelon-util-pipes.js +4 -4
  162. package/esm2015/token/index.js +2 -2
  163. package/esm2015/token/page-visibility.js +15 -15
  164. package/esm2015/token/window.js +16 -16
  165. package/esm2015/token/yelon-util-token.js +4 -4
  166. package/esm2015/yelon-util.js +4 -4
  167. package/fesm2015/browser.js +257 -257
  168. package/fesm2015/yelon-util-array.js +245 -245
  169. package/fesm2015/yelon-util-config.js +36 -36
  170. package/fesm2015/yelon-util-date-time.js +196 -196
  171. package/fesm2015/yelon-util-decorator.js +107 -107
  172. package/fesm2015/yelon-util-form.js +108 -108
  173. package/fesm2015/yelon-util-format.js +390 -390
  174. package/fesm2015/yelon-util-math.js +75 -75
  175. package/fesm2015/yelon-util-other.js +280 -280
  176. package/fesm2015/yelon-util-pipes-currency.js +72 -72
  177. package/fesm2015/yelon-util-pipes-filter.js +22 -22
  178. package/fesm2015/yelon-util-pipes-format.js +36 -36
  179. package/fesm2015/yelon-util-pipes.js +2 -2
  180. package/fesm2015/yelon-util-token.js +25 -25
  181. package/fesm2015/yelon-util.js +2 -2
  182. package/form/index.d.ts +2 -2
  183. package/form/match-control.d.ts +15 -15
  184. package/form/validators.d.ts +62 -62
  185. package/form/yelon-util-form.d.ts +4 -4
  186. package/format/currency.service.d.ts +34 -34
  187. package/format/currency.types.d.ts +77 -77
  188. package/format/index.d.ts +4 -4
  189. package/format/string.d.ts +44 -44
  190. package/format/validate.d.ts +72 -72
  191. package/format/yelon-util-format.d.ts +4 -4
  192. package/index.d.ts +11 -11
  193. package/math/in-range.d.ts +14 -14
  194. package/math/index.d.ts +2 -2
  195. package/math/round.d.ts +33 -33
  196. package/math/yelon-util-math.d.ts +4 -4
  197. package/other/assert.d.ts +36 -36
  198. package/other/deep.d.ts +33 -33
  199. package/other/index.d.ts +4 -4
  200. package/other/lazy.service.d.ts +22 -22
  201. package/other/logger.d.ts +5 -5
  202. package/other/yelon-util-other.d.ts +4 -4
  203. package/package.json +1 -1
  204. package/pipes/currency/cny.pipe.d.ts +12 -12
  205. package/pipes/currency/index.d.ts +3 -3
  206. package/pipes/currency/mega.pipe.d.ts +13 -13
  207. package/pipes/currency/module.d.ts +2 -2
  208. package/pipes/currency/price.pipe.d.ts +16 -16
  209. package/pipes/currency/yelon-util-pipes-currency.d.ts +5 -5
  210. package/pipes/filter/filter.pipe.d.ts +10 -10
  211. package/pipes/filter/index.d.ts +2 -2
  212. package/pipes/filter/module.d.ts +2 -2
  213. package/pipes/filter/yelon-util-pipes-filter.d.ts +4 -4
  214. package/pipes/format/index.d.ts +2 -2
  215. package/pipes/format/mask.pipe.d.ts +24 -24
  216. package/pipes/format/module.d.ts +2 -2
  217. package/pipes/format/yelon-util-pipes-format.d.ts +4 -4
  218. package/pipes/index.d.ts +3 -3
  219. package/pipes/yelon-util-pipes.d.ts +4 -4
  220. package/token/index.d.ts +2 -2
  221. package/token/page-visibility.d.ts +8 -8
  222. package/token/window.d.ts +7 -7
  223. package/token/yelon-util-token.d.ts +4 -4
  224. package/yelon-util.d.ts +4 -4
@@ -4,253 +4,253 @@ import * as i1 from '@yelon/util/config';
4
4
  import { YunzaiConfigService } from '@yelon/util/config';
5
5
  import { NzTreeNode } from 'ng-zorro-antd/core/tree';
6
6
 
7
- /* eslint-disable @typescript-eslint/no-explicit-any */
8
- class ArrayService {
9
- constructor(cog) {
10
- this.c = cog.merge('utilArray', {
11
- deepMapName: 'deep',
12
- parentMapName: 'parent',
13
- idMapName: 'id',
14
- parentIdMapName: 'parent_id',
15
- childrenMapName: 'children',
16
- titleMapName: 'title',
17
- checkedMapname: 'checked',
18
- selectedMapname: 'selected',
19
- expandedMapname: 'expanded',
20
- disabledMapname: 'disabled'
21
- });
22
- }
23
- /**
24
- * Convert tree structure to array structure
25
- *
26
- * 将树结构转换成数组结构
27
- */
28
- treeToArr(tree, options) {
29
- const opt = Object.assign({ deepMapName: this.c.deepMapName, parentMapName: this.c.parentMapName, childrenMapName: this.c.childrenMapName, clearChildren: true, cb: null }, options);
30
- const result = [];
31
- const inFn = (list, parent, deep = 0) => {
32
- for (const i of list) {
33
- i[opt.deepMapName] = deep;
34
- i[opt.parentMapName] = parent;
35
- if (opt.cb) {
36
- opt.cb(i, parent, deep);
37
- }
38
- result.push(i);
39
- const children = i[opt.childrenMapName];
40
- if (children != null && Array.isArray(children) && children.length > 0) {
41
- inFn(children, i, deep + 1);
42
- }
43
- if (opt.clearChildren) {
44
- delete i[opt.childrenMapName];
45
- }
46
- }
47
- };
48
- inFn(tree, null);
49
- return result;
50
- }
51
- /**
52
- * Convert array structure to tree structure
53
- *
54
- * 数组转换成树数据
55
- */
56
- arrToTree(arr, options) {
57
- if (!Array.isArray(arr) || arr.length === 0) {
58
- return [];
59
- }
60
- const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, childrenMapName: this.c.childrenMapName, cb: null }, options);
61
- const tree = [];
62
- const childrenOf = {};
63
- let rootPid = opt.rootParentIdValue;
64
- const arrType = arr;
65
- if (!rootPid) {
66
- const pids = arrType.map(i => i[opt.parentIdMapName]);
67
- const emptyPid = pids.findIndex(w => w == null);
68
- rootPid = emptyPid !== -1 ? pids[emptyPid] : pids.sort()[0];
69
- }
70
- for (const item of arrType) {
71
- const id = item[opt.idMapName];
72
- const pid = item[opt.parentIdMapName];
73
- childrenOf[id] = childrenOf[id] || [];
74
- item[opt.childrenMapName] = childrenOf[id];
75
- if (opt.cb) {
76
- opt.cb(item);
77
- }
78
- if (pid !== rootPid) {
79
- childrenOf[pid] = childrenOf[pid] || [];
80
- childrenOf[pid].push(item);
81
- }
82
- else {
83
- tree.push(item);
84
- }
85
- }
86
- return tree;
87
- }
88
- /**
89
- * 数组转换成 `nz-tree` 数据源,通过 `options` 转化项名,也可以使用 `options.cb` 更高级决定数据项
90
- */
91
- arrToTreeNode(arr, options) {
92
- const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, titleMapName: this.c.titleMapName, isLeafMapName: 'isLeaf', checkedMapname: this.c.checkedMapname, selectedMapname: this.c.selectedMapname, expandedMapname: this.c.expandedMapname, disabledMapname: this.c.disabledMapname, cb: null }, options);
93
- const tree = this.arrToTree(arr, {
94
- idMapName: opt.idMapName,
95
- parentIdMapName: opt.parentIdMapName,
96
- childrenMapName: 'children'
97
- });
98
- this.visitTree(tree, (item, parent, deep) => {
99
- item.key = item[opt.idMapName];
100
- item.title = item[opt.titleMapName];
101
- item.checked = item[opt.checkedMapname];
102
- item.selected = item[opt.selectedMapname];
103
- item.expanded = item[opt.expandedMapname];
104
- item.disabled = item[opt.disabledMapname];
105
- if (item[opt.isLeafMapName] == null) {
106
- item.isLeaf = item.children.length === 0;
107
- }
108
- else {
109
- item.isLeaf = item[opt.isLeafMapName];
110
- }
111
- if (opt.cb) {
112
- opt.cb(item, parent, deep);
113
- }
114
- });
115
- return tree.map(node => new NzTreeNode(node));
116
- }
117
- /**
118
- * 递归访问整个树
119
- */
120
- visitTree(tree, cb, options) {
121
- options = Object.assign({ childrenMapName: this.c.childrenMapName }, options);
122
- const inFn = (data, parent, deep) => {
123
- for (const item of data) {
124
- cb(item, parent, deep);
125
- const childrenVal = item[options.childrenMapName];
126
- if (Array.isArray(childrenVal) && childrenVal.length > 0) {
127
- inFn(childrenVal, item, deep + 1);
128
- }
129
- }
130
- };
131
- inFn(tree, null, 1);
132
- }
133
- /**
134
- * Return the value of the first tree value in the tree where predicate is true, and `undefined` otherwise
135
- *
136
- * 根据条件返回树的第一个值,否则返回 `undefined`
137
- */
138
- findTree(tree, predicate, options) {
139
- let res;
140
- this.visitTree(tree, item => {
141
- if (res === undefined && predicate(item)) {
142
- res = item;
143
- }
144
- }, options);
145
- return res;
146
- }
147
- /**
148
- * 获取所有已经选中的 `key` 值
149
- */
150
- getKeysByTreeNode(tree, options) {
151
- const opt = Object.assign({ includeHalfChecked: true }, options);
152
- const keys = [];
153
- this.visitTree(tree, (item, parent, deep) => {
154
- if (item.isChecked || (opt.includeHalfChecked && item.isHalfChecked)) {
155
- keys.push(opt.cb ? opt.cb(item, parent, deep) : opt.keyMapName ? item.origin[opt.keyMapName] : item.key);
156
- }
157
- });
158
- return keys;
159
- }
160
- baseFlat(array, depth, result = []) {
161
- let index = -1;
162
- while (++index < array.length) {
163
- const value = array[index];
164
- if (depth > 0 && Array.isArray(value)) {
165
- if (depth > 1) {
166
- this.baseFlat(value, depth - 1, result);
167
- }
168
- else {
169
- let pushIndex = -1;
170
- const offset = result.length;
171
- while (++pushIndex < value.length) {
172
- result[offset + pushIndex] = value[pushIndex];
173
- }
174
- }
175
- }
176
- else {
177
- result[result.length] = value;
178
- }
179
- }
180
- return result;
181
- }
182
- /**
183
- * Recursively flattens array
184
- *
185
- * 递归扁平数组
186
- * ```ts
187
- * srv.flat([1, [2, 3, [4, 5, [6]]]]) => [1,2,3,4,5,6]
188
- * srv.flat([1, [2, 3, [4, 5, [6]]]], 1) => [1,2,3,[4, 5, [6]]]
189
- * ```
190
- */
191
- flat(array, depth = 1 / 0) {
192
- return Array.isArray(array) ? this.baseFlat(array, depth) : array;
193
- }
194
- /**
195
- * Group the array
196
- *
197
- * 对数组进行分组
198
- * ```ts
199
- * srv.groupBy([6.1, 4.2, 6.3], Math.floor) => {"4":[4.2],"6":[6.1,6.3]}
200
- * srv.groupBy(['one', 'two', 'three'], v => v.length) => {"3":["one","two"],"5":["three"]}
201
- * ```
202
- */
203
- groupBy(array, iteratee) {
204
- if (!Array.isArray(array)) {
205
- return {};
206
- }
207
- return array.reduce((result, value) => {
208
- const key = iteratee(value);
209
- if (Object.prototype.hasOwnProperty.call(result, key)) {
210
- result[key].push(value);
211
- }
212
- else {
213
- result[key] = [value];
214
- }
215
- return result;
216
- }, {});
217
- }
218
- /**
219
- * Creates a duplicate-free version of an array
220
- *
221
- * 创建去重后的数组
222
- * ```ts
223
- * uniq([1, 2, 2, 3, 1]) => [1,2,3]
224
- * uniq([{ a: 1 }, { a: 1 }, { a: 2 }], 'a') => [{"a":1},{"a":2}]
225
- * uniq([{ a: 1 }, { a: 1 }, { a: 2 }], i => (i.a === 1 ? 'a' : 'b')) => [{"a":1},{"a":2}]
226
- * ```
227
- */
228
- uniq(array, predicate) {
229
- return Array.from(array
230
- .reduce((map, value) => {
231
- const key = predicate
232
- ? typeof predicate === 'string'
233
- ? value[predicate]
234
- : predicate(value)
235
- : value;
236
- if (!map.has(key)) {
237
- map.set(key, value);
238
- }
239
- return map;
240
- }, new Map())
241
- .values());
242
- }
243
- }
244
- ArrayService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ArrayService_Factory() { return new ArrayService(i0.ɵɵinject(i1.YunzaiConfigService)); }, token: ArrayService, providedIn: "root" });
245
- ArrayService.decorators = [
246
- { type: Injectable, args: [{ providedIn: 'root' },] }
247
- ];
248
- ArrayService.ctorParameters = () => [
249
- { type: YunzaiConfigService }
7
+ /* eslint-disable @typescript-eslint/no-explicit-any */
8
+ class ArrayService {
9
+ constructor(cog) {
10
+ this.c = cog.merge('utilArray', {
11
+ deepMapName: 'deep',
12
+ parentMapName: 'parent',
13
+ idMapName: 'id',
14
+ parentIdMapName: 'parent_id',
15
+ childrenMapName: 'children',
16
+ titleMapName: 'title',
17
+ checkedMapname: 'checked',
18
+ selectedMapname: 'selected',
19
+ expandedMapname: 'expanded',
20
+ disabledMapname: 'disabled'
21
+ });
22
+ }
23
+ /**
24
+ * Convert tree structure to array structure
25
+ *
26
+ * 将树结构转换成数组结构
27
+ */
28
+ treeToArr(tree, options) {
29
+ const opt = Object.assign({ deepMapName: this.c.deepMapName, parentMapName: this.c.parentMapName, childrenMapName: this.c.childrenMapName, clearChildren: true, cb: null }, options);
30
+ const result = [];
31
+ const inFn = (list, parent, deep = 0) => {
32
+ for (const i of list) {
33
+ i[opt.deepMapName] = deep;
34
+ i[opt.parentMapName] = parent;
35
+ if (opt.cb) {
36
+ opt.cb(i, parent, deep);
37
+ }
38
+ result.push(i);
39
+ const children = i[opt.childrenMapName];
40
+ if (children != null && Array.isArray(children) && children.length > 0) {
41
+ inFn(children, i, deep + 1);
42
+ }
43
+ if (opt.clearChildren) {
44
+ delete i[opt.childrenMapName];
45
+ }
46
+ }
47
+ };
48
+ inFn(tree, null);
49
+ return result;
50
+ }
51
+ /**
52
+ * Convert array structure to tree structure
53
+ *
54
+ * 数组转换成树数据
55
+ */
56
+ arrToTree(arr, options) {
57
+ if (!Array.isArray(arr) || arr.length === 0) {
58
+ return [];
59
+ }
60
+ const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, childrenMapName: this.c.childrenMapName, cb: null }, options);
61
+ const tree = [];
62
+ const childrenOf = {};
63
+ let rootPid = opt.rootParentIdValue;
64
+ const arrType = arr;
65
+ if (!rootPid) {
66
+ const pids = arrType.map(i => i[opt.parentIdMapName]);
67
+ const emptyPid = pids.findIndex(w => w == null);
68
+ rootPid = emptyPid !== -1 ? pids[emptyPid] : pids.sort()[0];
69
+ }
70
+ for (const item of arrType) {
71
+ const id = item[opt.idMapName];
72
+ const pid = item[opt.parentIdMapName];
73
+ childrenOf[id] = childrenOf[id] || [];
74
+ item[opt.childrenMapName] = childrenOf[id];
75
+ if (opt.cb) {
76
+ opt.cb(item);
77
+ }
78
+ if (pid !== rootPid) {
79
+ childrenOf[pid] = childrenOf[pid] || [];
80
+ childrenOf[pid].push(item);
81
+ }
82
+ else {
83
+ tree.push(item);
84
+ }
85
+ }
86
+ return tree;
87
+ }
88
+ /**
89
+ * 数组转换成 `nz-tree` 数据源,通过 `options` 转化项名,也可以使用 `options.cb` 更高级决定数据项
90
+ */
91
+ arrToTreeNode(arr, options) {
92
+ const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, titleMapName: this.c.titleMapName, isLeafMapName: 'isLeaf', checkedMapname: this.c.checkedMapname, selectedMapname: this.c.selectedMapname, expandedMapname: this.c.expandedMapname, disabledMapname: this.c.disabledMapname, cb: null }, options);
93
+ const tree = this.arrToTree(arr, {
94
+ idMapName: opt.idMapName,
95
+ parentIdMapName: opt.parentIdMapName,
96
+ childrenMapName: 'children'
97
+ });
98
+ this.visitTree(tree, (item, parent, deep) => {
99
+ item.key = item[opt.idMapName];
100
+ item.title = item[opt.titleMapName];
101
+ item.checked = item[opt.checkedMapname];
102
+ item.selected = item[opt.selectedMapname];
103
+ item.expanded = item[opt.expandedMapname];
104
+ item.disabled = item[opt.disabledMapname];
105
+ if (item[opt.isLeafMapName] == null) {
106
+ item.isLeaf = item.children.length === 0;
107
+ }
108
+ else {
109
+ item.isLeaf = item[opt.isLeafMapName];
110
+ }
111
+ if (opt.cb) {
112
+ opt.cb(item, parent, deep);
113
+ }
114
+ });
115
+ return tree.map(node => new NzTreeNode(node));
116
+ }
117
+ /**
118
+ * 递归访问整个树
119
+ */
120
+ visitTree(tree, cb, options) {
121
+ options = Object.assign({ childrenMapName: this.c.childrenMapName }, options);
122
+ const inFn = (data, parent, deep) => {
123
+ for (const item of data) {
124
+ cb(item, parent, deep);
125
+ const childrenVal = item[options.childrenMapName];
126
+ if (Array.isArray(childrenVal) && childrenVal.length > 0) {
127
+ inFn(childrenVal, item, deep + 1);
128
+ }
129
+ }
130
+ };
131
+ inFn(tree, null, 1);
132
+ }
133
+ /**
134
+ * Return the value of the first tree value in the tree where predicate is true, and `undefined` otherwise
135
+ *
136
+ * 根据条件返回树的第一个值,否则返回 `undefined`
137
+ */
138
+ findTree(tree, predicate, options) {
139
+ let res;
140
+ this.visitTree(tree, item => {
141
+ if (res === undefined && predicate(item)) {
142
+ res = item;
143
+ }
144
+ }, options);
145
+ return res;
146
+ }
147
+ /**
148
+ * 获取所有已经选中的 `key` 值
149
+ */
150
+ getKeysByTreeNode(tree, options) {
151
+ const opt = Object.assign({ includeHalfChecked: true }, options);
152
+ const keys = [];
153
+ this.visitTree(tree, (item, parent, deep) => {
154
+ if (item.isChecked || (opt.includeHalfChecked && item.isHalfChecked)) {
155
+ keys.push(opt.cb ? opt.cb(item, parent, deep) : opt.keyMapName ? item.origin[opt.keyMapName] : item.key);
156
+ }
157
+ });
158
+ return keys;
159
+ }
160
+ baseFlat(array, depth, result = []) {
161
+ let index = -1;
162
+ while (++index < array.length) {
163
+ const value = array[index];
164
+ if (depth > 0 && Array.isArray(value)) {
165
+ if (depth > 1) {
166
+ this.baseFlat(value, depth - 1, result);
167
+ }
168
+ else {
169
+ let pushIndex = -1;
170
+ const offset = result.length;
171
+ while (++pushIndex < value.length) {
172
+ result[offset + pushIndex] = value[pushIndex];
173
+ }
174
+ }
175
+ }
176
+ else {
177
+ result[result.length] = value;
178
+ }
179
+ }
180
+ return result;
181
+ }
182
+ /**
183
+ * Recursively flattens array
184
+ *
185
+ * 递归扁平数组
186
+ * ```ts
187
+ * srv.flat([1, [2, 3, [4, 5, [6]]]]) => [1,2,3,4,5,6]
188
+ * srv.flat([1, [2, 3, [4, 5, [6]]]], 1) => [1,2,3,[4, 5, [6]]]
189
+ * ```
190
+ */
191
+ flat(array, depth = 1 / 0) {
192
+ return Array.isArray(array) ? this.baseFlat(array, depth) : array;
193
+ }
194
+ /**
195
+ * Group the array
196
+ *
197
+ * 对数组进行分组
198
+ * ```ts
199
+ * srv.groupBy([6.1, 4.2, 6.3], Math.floor) => {"4":[4.2],"6":[6.1,6.3]}
200
+ * srv.groupBy(['one', 'two', 'three'], v => v.length) => {"3":["one","two"],"5":["three"]}
201
+ * ```
202
+ */
203
+ groupBy(array, iteratee) {
204
+ if (!Array.isArray(array)) {
205
+ return {};
206
+ }
207
+ return array.reduce((result, value) => {
208
+ const key = iteratee(value);
209
+ if (Object.prototype.hasOwnProperty.call(result, key)) {
210
+ result[key].push(value);
211
+ }
212
+ else {
213
+ result[key] = [value];
214
+ }
215
+ return result;
216
+ }, {});
217
+ }
218
+ /**
219
+ * Creates a duplicate-free version of an array
220
+ *
221
+ * 创建去重后的数组
222
+ * ```ts
223
+ * uniq([1, 2, 2, 3, 1]) => [1,2,3]
224
+ * uniq([{ a: 1 }, { a: 1 }, { a: 2 }], 'a') => [{"a":1},{"a":2}]
225
+ * uniq([{ a: 1 }, { a: 1 }, { a: 2 }], i => (i.a === 1 ? 'a' : 'b')) => [{"a":1},{"a":2}]
226
+ * ```
227
+ */
228
+ uniq(array, predicate) {
229
+ return Array.from(array
230
+ .reduce((map, value) => {
231
+ const key = predicate
232
+ ? typeof predicate === 'string'
233
+ ? value[predicate]
234
+ : predicate(value)
235
+ : value;
236
+ if (!map.has(key)) {
237
+ map.set(key, value);
238
+ }
239
+ return map;
240
+ }, new Map())
241
+ .values());
242
+ }
243
+ }
244
+ ArrayService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ArrayService_Factory() { return new ArrayService(i0.ɵɵinject(i1.YunzaiConfigService)); }, token: ArrayService, providedIn: "root" });
245
+ ArrayService.decorators = [
246
+ { type: Injectable, args: [{ providedIn: 'root' },] }
247
+ ];
248
+ ArrayService.ctorParameters = () => [
249
+ { type: YunzaiConfigService }
250
250
  ];
251
251
 
252
- /**
253
- * Generated bundle index. Do not edit.
252
+ /**
253
+ * Generated bundle index. Do not edit.
254
254
  */
255
255
 
256
256
  export { ArrayService };
@@ -2,48 +2,48 @@ import * as i0 from '@angular/core';
2
2
  import { InjectionToken, Injectable, Optional, Inject } from '@angular/core';
3
3
  import { deepMergeKey } from '@yelon/util/other';
4
4
 
5
- class YunzaiSVConfig {
5
+ class YunzaiSVConfig {
6
6
  }
7
7
 
8
- const YUNZAI_CONFIG = new InjectionToken('yunzai-config', {
9
- providedIn: 'root',
10
- factory: YUNZAI_CONFIG_FACTORY
11
- });
12
- function YUNZAI_CONFIG_FACTORY() {
13
- return {};
8
+ const YUNZAI_CONFIG = new InjectionToken('yunzai-config', {
9
+ providedIn: 'root',
10
+ factory: YUNZAI_CONFIG_FACTORY
11
+ });
12
+ function YUNZAI_CONFIG_FACTORY() {
13
+ return {};
14
14
  }
15
15
 
16
- class YunzaiConfigService {
17
- constructor(defaultConfig) {
18
- this.config = Object.assign({}, defaultConfig);
19
- }
20
- get(componentName, key) {
21
- const res = (this.config[componentName] || {});
22
- return key ? { [key]: res[key] } : res;
23
- }
24
- merge(componentName, ...defaultValues) {
25
- return deepMergeKey({}, true, ...defaultValues, this.get(componentName));
26
- }
27
- attach(componentThis, componentName, defaultValues) {
28
- Object.assign(componentThis, this.merge(componentName, defaultValues));
29
- }
30
- attachKey(componentThis, componentName, key) {
31
- Object.assign(componentThis, this.get(componentName, key));
32
- }
33
- set(componentName, value) {
34
- this.config[componentName] = Object.assign(Object.assign({}, this.config[componentName]), value);
35
- }
36
- }
37
- YunzaiConfigService.ɵprov = i0.ɵɵdefineInjectable({ factory: function YunzaiConfigService_Factory() { return new YunzaiConfigService(i0.ɵɵinject(YUNZAI_CONFIG, 8)); }, token: YunzaiConfigService, providedIn: "root" });
38
- YunzaiConfigService.decorators = [
39
- { type: Injectable, args: [{ providedIn: 'root' },] }
40
- ];
41
- YunzaiConfigService.ctorParameters = () => [
42
- { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [YUNZAI_CONFIG,] }] }
16
+ class YunzaiConfigService {
17
+ constructor(defaultConfig) {
18
+ this.config = Object.assign({}, defaultConfig);
19
+ }
20
+ get(componentName, key) {
21
+ const res = (this.config[componentName] || {});
22
+ return key ? { [key]: res[key] } : res;
23
+ }
24
+ merge(componentName, ...defaultValues) {
25
+ return deepMergeKey({}, true, ...defaultValues, this.get(componentName));
26
+ }
27
+ attach(componentThis, componentName, defaultValues) {
28
+ Object.assign(componentThis, this.merge(componentName, defaultValues));
29
+ }
30
+ attachKey(componentThis, componentName, key) {
31
+ Object.assign(componentThis, this.get(componentName, key));
32
+ }
33
+ set(componentName, value) {
34
+ this.config[componentName] = Object.assign(Object.assign({}, this.config[componentName]), value);
35
+ }
36
+ }
37
+ YunzaiConfigService.ɵprov = i0.ɵɵdefineInjectable({ factory: function YunzaiConfigService_Factory() { return new YunzaiConfigService(i0.ɵɵinject(YUNZAI_CONFIG, 8)); }, token: YunzaiConfigService, providedIn: "root" });
38
+ YunzaiConfigService.decorators = [
39
+ { type: Injectable, args: [{ providedIn: 'root' },] }
40
+ ];
41
+ YunzaiConfigService.ctorParameters = () => [
42
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [YUNZAI_CONFIG,] }] }
43
43
  ];
44
44
 
45
- /**
46
- * Generated bundle index. Do not edit.
45
+ /**
46
+ * Generated bundle index. Do not edit.
47
47
  */
48
48
 
49
49
  export { YUNZAI_CONFIG, YUNZAI_CONFIG_FACTORY, YunzaiConfigService, YunzaiSVConfig };