@claspo/common 7.3.1-dev.3 → 7.3.1-dev.4

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 (221) hide show
  1. package/coverage/lcov-report/block-navigation.js +87 -0
  2. package/coverage/lcov-report/prettify.js +2 -0
  3. package/coverage/lcov-report/sorter.js +196 -0
  4. package/jest.config.ts +204 -0
  5. package/out/package.json +50 -0
  6. package/package.json +1 -1
  7. package/src/DefaultEventEmitter.test.ts +84 -0
  8. package/src/DefaultEventEmitter.ts +96 -0
  9. package/src/HttpAbortableLoader.ts +35 -0
  10. package/src/InAppLayoutType.ts +6 -0
  11. package/src/LayoutType.ts +18 -0
  12. package/src/PrizePool.interface.ts +32 -0
  13. package/src/RenderMode.ts +10 -0
  14. package/src/UuidGenerator.ts +16 -0
  15. package/src/WidgetInitConfig.interface.ts +163 -0
  16. package/src/WidgetType.ts +18 -0
  17. package/src/action/type.ts +7 -0
  18. package/src/async/createAsyncIterator.ts +33 -0
  19. package/src/async/debounce.ts +28 -0
  20. package/src/async/timeout.ts +3 -0
  21. package/src/component-manifest/ComponentManifest.interface.ts +160 -0
  22. package/src/component-manifest/ContextMenuManifest.interface.ts +52 -0
  23. package/src/component-manifest/DisplayCondition.interface.ts +65 -0
  24. package/src/component-manifest/FloatingControlManifest.interface.ts +89 -0
  25. package/src/component-manifest/PropPathCondition.interface.ts +4 -0
  26. package/src/component-manifest/PropertyPaneManifest.interface.ts +614 -0
  27. package/src/converter/time/TimeConverter.spec.ts +11 -0
  28. package/src/converter/time/TimeUnit.spec.ts +12 -0
  29. package/src/converter/time/TimeUnit.ts +34 -0
  30. package/src/converter/time/TimerConverter.ts +29 -0
  31. package/src/document/ComponentInsertType.ts +6 -0
  32. package/src/document/Document.interface.ts +625 -0
  33. package/src/document/DocumentCssVarsReplace.test.ts +2947 -0
  34. package/src/document/DocumentCssVarsReplace.ts +31 -0
  35. package/src/document/DocumentUtils.test.ts +595 -0
  36. package/src/document/DocumentUtils.ts +194 -0
  37. package/src/document/hidden-fields.interface.ts +54 -0
  38. package/src/dom/ViewportSize.ts +61 -0
  39. package/src/dom/copyToClipboard.ts +17 -0
  40. package/src/dom/getMostNestedNode.ts +9 -0
  41. package/src/dom/insertHtmlIntoElement.ts +36 -0
  42. package/src/dom/sanitizeHTML.test.ts +59 -0
  43. package/src/dom/sanitizeHTML.ts +78 -0
  44. package/src/element/BaseElementInViewportHandler.ts +41 -0
  45. package/src/element/CssVarsOperations.ts +37 -0
  46. package/src/element/ThemeCssVars.ts +28 -0
  47. package/src/element/recursiveFindParentNodeByAttribute.test.ts +63 -0
  48. package/src/element/recursiveFindParentNodeByAttribute.ts +25 -0
  49. package/src/flat.ts +16 -0
  50. package/src/handler/HandlerTypes.ts +4 -0
  51. package/src/math/RandomDistributor.test.ts +35 -0
  52. package/src/math/RandomDistributor.ts +58 -0
  53. package/src/math/sum.ts +3 -0
  54. package/src/network/HttpClient.ts +28 -0
  55. package/src/network/HttpStatus.ts +4 -0
  56. package/src/object/isDictionary.test.ts +24 -0
  57. package/src/object/isDictionary.ts +13 -0
  58. package/src/object/omitKeys.test.ts +19 -0
  59. package/src/object/omitKeys.ts +20 -0
  60. package/src/storage/BaseCachingStorage.test.ts +70 -0
  61. package/src/storage/BaseCachingStorage.ts +37 -0
  62. package/src/storage/CachingCookieStorage.test.ts +75 -0
  63. package/src/storage/CachingCookieStorage.ts +36 -0
  64. package/src/storage/CachingLocalStorage.test.ts +59 -0
  65. package/src/storage/CachingLocalStorage.ts +34 -0
  66. package/src/storage/getCookie.test.ts +53 -0
  67. package/src/storage/getCookie.ts +10 -0
  68. package/src/storage/setCookie.test.ts +97 -0
  69. package/src/storage/setCookie.ts +49 -0
  70. package/src/theme/theme.utils.ts +50 -0
  71. package/src/url/sanitizeUrl.test.ts +62 -0
  72. package/src/url/sanitizeUrl.ts +51 -0
  73. package/src/utils/CaseTransformer.test.ts +16 -0
  74. package/src/utils/CaseTransformer.ts +10 -0
  75. package/src/utils/NullishCoalescingOperator.ts +3 -0
  76. package/src/utils/NumericDecline.ts +25 -0
  77. package/src/utils/addEventListener.ts +23 -0
  78. package/src/utils/allSettled.ts +6 -0
  79. package/src/utils/checkTimeZone.spec.ts +18 -0
  80. package/src/utils/checkTimeZone.ts +6 -0
  81. package/src/utils/deviceUtils.ts +12 -0
  82. package/src/utils/flatMap.test.ts +21 -0
  83. package/src/utils/flatMap.ts +3 -0
  84. package/src/utils/fromEntries.ts +6 -0
  85. package/src/utils/generateRandomNumber.test.ts +23 -0
  86. package/src/utils/generateRandomNumber.ts +3 -0
  87. package/src/utils/objectSort.ts +41 -0
  88. package/src/utils/orientationUtils.ts +18 -0
  89. package/src/velocity/SysVelocityContext.spec.ts +88 -0
  90. package/src/velocity/SysVelocityContext.ts +129 -0
  91. package/src/velocity/SysVelocityRenderer.spec.ts +36 -0
  92. package/src/velocity/SysVelocityRenderer.ts +11 -0
  93. package/test/__mocks/jestGlobalMocks.js +1887 -0
  94. /package/{DefaultEventEmitter.d.ts → out/DefaultEventEmitter.d.ts} +0 -0
  95. /package/{DefaultEventEmitter.js → out/DefaultEventEmitter.js} +0 -0
  96. /package/{HttpAbortableLoader.d.ts → out/HttpAbortableLoader.d.ts} +0 -0
  97. /package/{HttpAbortableLoader.js → out/HttpAbortableLoader.js} +0 -0
  98. /package/{InAppLayoutType.d.ts → out/InAppLayoutType.d.ts} +0 -0
  99. /package/{InAppLayoutType.js → out/InAppLayoutType.js} +0 -0
  100. /package/{LayoutType.d.ts → out/LayoutType.d.ts} +0 -0
  101. /package/{LayoutType.js → out/LayoutType.js} +0 -0
  102. /package/{PrizePool.interface.d.ts → out/PrizePool.interface.d.ts} +0 -0
  103. /package/{PrizePool.interface.js → out/PrizePool.interface.js} +0 -0
  104. /package/{RenderMode.d.ts → out/RenderMode.d.ts} +0 -0
  105. /package/{RenderMode.js → out/RenderMode.js} +0 -0
  106. /package/{UuidGenerator.d.ts → out/UuidGenerator.d.ts} +0 -0
  107. /package/{UuidGenerator.js → out/UuidGenerator.js} +0 -0
  108. /package/{WidgetInitConfig.interface.d.ts → out/WidgetInitConfig.interface.d.ts} +0 -0
  109. /package/{WidgetInitConfig.interface.js → out/WidgetInitConfig.interface.js} +0 -0
  110. /package/{WidgetType.d.ts → out/WidgetType.d.ts} +0 -0
  111. /package/{WidgetType.js → out/WidgetType.js} +0 -0
  112. /package/{action → out/action}/type.d.ts +0 -0
  113. /package/{action → out/action}/type.js +0 -0
  114. /package/{async → out/async}/createAsyncIterator.d.ts +0 -0
  115. /package/{async → out/async}/createAsyncIterator.js +0 -0
  116. /package/{async → out/async}/debounce.d.ts +0 -0
  117. /package/{async → out/async}/debounce.js +0 -0
  118. /package/{async → out/async}/timeout.d.ts +0 -0
  119. /package/{async → out/async}/timeout.js +0 -0
  120. /package/{component-manifest → out/component-manifest}/ComponentManifest.interface.d.ts +0 -0
  121. /package/{component-manifest → out/component-manifest}/ComponentManifest.interface.js +0 -0
  122. /package/{component-manifest → out/component-manifest}/ContextMenuManifest.interface.d.ts +0 -0
  123. /package/{component-manifest → out/component-manifest}/ContextMenuManifest.interface.js +0 -0
  124. /package/{component-manifest → out/component-manifest}/DisplayCondition.interface.d.ts +0 -0
  125. /package/{component-manifest → out/component-manifest}/DisplayCondition.interface.js +0 -0
  126. /package/{component-manifest → out/component-manifest}/FloatingControlManifest.interface.d.ts +0 -0
  127. /package/{component-manifest → out/component-manifest}/FloatingControlManifest.interface.js +0 -0
  128. /package/{component-manifest → out/component-manifest}/PropPathCondition.interface.d.ts +0 -0
  129. /package/{component-manifest → out/component-manifest}/PropPathCondition.interface.js +0 -0
  130. /package/{component-manifest → out/component-manifest}/PropertyPaneManifest.interface.d.ts +0 -0
  131. /package/{component-manifest → out/component-manifest}/PropertyPaneManifest.interface.js +0 -0
  132. /package/{converter → out/converter}/time/TimeUnit.d.ts +0 -0
  133. /package/{converter → out/converter}/time/TimeUnit.js +0 -0
  134. /package/{converter → out/converter}/time/TimerConverter.d.ts +0 -0
  135. /package/{converter → out/converter}/time/TimerConverter.js +0 -0
  136. /package/{document → out/document}/ComponentInsertType.d.ts +0 -0
  137. /package/{document → out/document}/ComponentInsertType.js +0 -0
  138. /package/{document → out/document}/Document.interface.d.ts +0 -0
  139. /package/{document → out/document}/Document.interface.js +0 -0
  140. /package/{document → out/document}/DocumentCssVarsReplace.d.ts +0 -0
  141. /package/{document → out/document}/DocumentCssVarsReplace.js +0 -0
  142. /package/{document → out/document}/DocumentUtils.d.ts +0 -0
  143. /package/{document → out/document}/DocumentUtils.js +0 -0
  144. /package/{document → out/document}/hidden-fields.interface.d.ts +0 -0
  145. /package/{document → out/document}/hidden-fields.interface.js +0 -0
  146. /package/{dom → out/dom}/ViewportSize.d.ts +0 -0
  147. /package/{dom → out/dom}/ViewportSize.js +0 -0
  148. /package/{dom → out/dom}/copyToClipboard.d.ts +0 -0
  149. /package/{dom → out/dom}/copyToClipboard.js +0 -0
  150. /package/{dom → out/dom}/getMostNestedNode.d.ts +0 -0
  151. /package/{dom → out/dom}/getMostNestedNode.js +0 -0
  152. /package/{dom → out/dom}/insertHtmlIntoElement.d.ts +0 -0
  153. /package/{dom → out/dom}/insertHtmlIntoElement.js +0 -0
  154. /package/{dom → out/dom}/sanitizeHTML.d.ts +0 -0
  155. /package/{dom → out/dom}/sanitizeHTML.js +0 -0
  156. /package/{element → out/element}/BaseElementInViewportHandler.d.ts +0 -0
  157. /package/{element → out/element}/BaseElementInViewportHandler.js +0 -0
  158. /package/{element → out/element}/CssVarsOperations.d.ts +0 -0
  159. /package/{element → out/element}/CssVarsOperations.js +0 -0
  160. /package/{element → out/element}/ThemeCssVars.d.ts +0 -0
  161. /package/{element → out/element}/ThemeCssVars.js +0 -0
  162. /package/{element → out/element}/recursiveFindParentNodeByAttribute.d.ts +0 -0
  163. /package/{element → out/element}/recursiveFindParentNodeByAttribute.js +0 -0
  164. /package/{flat.d.ts → out/flat.d.ts} +0 -0
  165. /package/{flat.js → out/flat.js} +0 -0
  166. /package/{handler → out/handler}/HandlerTypes.d.ts +0 -0
  167. /package/{handler → out/handler}/HandlerTypes.js +0 -0
  168. /package/{math → out/math}/RandomDistributor.d.ts +0 -0
  169. /package/{math → out/math}/RandomDistributor.js +0 -0
  170. /package/{math → out/math}/sum.d.ts +0 -0
  171. /package/{math → out/math}/sum.js +0 -0
  172. /package/{network → out/network}/HttpClient.d.ts +0 -0
  173. /package/{network → out/network}/HttpClient.js +0 -0
  174. /package/{network → out/network}/HttpStatus.d.ts +0 -0
  175. /package/{network → out/network}/HttpStatus.js +0 -0
  176. /package/{object → out/object}/isDictionary.d.ts +0 -0
  177. /package/{object → out/object}/isDictionary.js +0 -0
  178. /package/{object → out/object}/omitKeys.d.ts +0 -0
  179. /package/{object → out/object}/omitKeys.js +0 -0
  180. /package/{storage → out/storage}/BaseCachingStorage.d.ts +0 -0
  181. /package/{storage → out/storage}/BaseCachingStorage.js +0 -0
  182. /package/{storage → out/storage}/CachingCookieStorage.d.ts +0 -0
  183. /package/{storage → out/storage}/CachingCookieStorage.js +0 -0
  184. /package/{storage → out/storage}/CachingLocalStorage.d.ts +0 -0
  185. /package/{storage → out/storage}/CachingLocalStorage.js +0 -0
  186. /package/{storage → out/storage}/getCookie.d.ts +0 -0
  187. /package/{storage → out/storage}/getCookie.js +0 -0
  188. /package/{storage → out/storage}/setCookie.d.ts +0 -0
  189. /package/{storage → out/storage}/setCookie.js +0 -0
  190. /package/{theme → out/theme}/theme.utils.d.ts +0 -0
  191. /package/{theme → out/theme}/theme.utils.js +0 -0
  192. /package/{url → out/url}/sanitizeUrl.d.ts +0 -0
  193. /package/{url → out/url}/sanitizeUrl.js +0 -0
  194. /package/{utils → out/utils}/CaseTransformer.d.ts +0 -0
  195. /package/{utils → out/utils}/CaseTransformer.js +0 -0
  196. /package/{utils → out/utils}/NullishCoalescingOperator.d.ts +0 -0
  197. /package/{utils → out/utils}/NullishCoalescingOperator.js +0 -0
  198. /package/{utils → out/utils}/NumericDecline.d.ts +0 -0
  199. /package/{utils → out/utils}/NumericDecline.js +0 -0
  200. /package/{utils → out/utils}/addEventListener.d.ts +0 -0
  201. /package/{utils → out/utils}/addEventListener.js +0 -0
  202. /package/{utils → out/utils}/allSettled.d.ts +0 -0
  203. /package/{utils → out/utils}/allSettled.js +0 -0
  204. /package/{utils → out/utils}/checkTimeZone.d.ts +0 -0
  205. /package/{utils → out/utils}/checkTimeZone.js +0 -0
  206. /package/{utils → out/utils}/deviceUtils.d.ts +0 -0
  207. /package/{utils → out/utils}/deviceUtils.js +0 -0
  208. /package/{utils → out/utils}/flatMap.d.ts +0 -0
  209. /package/{utils → out/utils}/flatMap.js +0 -0
  210. /package/{utils → out/utils}/fromEntries.d.ts +0 -0
  211. /package/{utils → out/utils}/fromEntries.js +0 -0
  212. /package/{utils → out/utils}/generateRandomNumber.d.ts +0 -0
  213. /package/{utils → out/utils}/generateRandomNumber.js +0 -0
  214. /package/{utils → out/utils}/objectSort.d.ts +0 -0
  215. /package/{utils → out/utils}/objectSort.js +0 -0
  216. /package/{utils → out/utils}/orientationUtils.d.ts +0 -0
  217. /package/{utils → out/utils}/orientationUtils.js +0 -0
  218. /package/{velocity → out/velocity}/SysVelocityContext.d.ts +0 -0
  219. /package/{velocity → out/velocity}/SysVelocityContext.js +0 -0
  220. /package/{velocity → out/velocity}/SysVelocityRenderer.d.ts +0 -0
  221. /package/{velocity → out/velocity}/SysVelocityRenderer.js +0 -0
@@ -0,0 +1,31 @@
1
+ import {ClDocumentCssVarsI, ClDocumentI} from './Document.interface';
2
+
3
+ export default class DocumentCssVarsReplace {
4
+ static replaceVars(document: ClDocumentI, colorsMap: ClDocumentCssVarsI): ClDocumentI {
5
+ const cssVarsMap = {...document.shared.cssVars, ...colorsMap};
6
+ let documentString = JSON.stringify(document);
7
+
8
+ Object.keys(cssVarsMap)
9
+ .forEach((varName) => {
10
+ let search = `var(--${varName})`;
11
+ let replacement = cssVarsMap[varName];
12
+ documentString = documentString.split(search).join(replacement);
13
+ });
14
+
15
+ return JSON.parse(documentString);
16
+ }
17
+
18
+ static replaceValues(document: ClDocumentI, cssVarsMap: ClDocumentCssVarsI): ClDocumentI {
19
+ let documentString = JSON.stringify(document);
20
+ Object.keys(cssVarsMap)
21
+ .forEach((varName) => {
22
+ let search = cssVarsMap[varName];
23
+ let replacement = `var(--${varName})`;
24
+ documentString = documentString.split(search).join(replacement);
25
+ });
26
+
27
+ return JSON.parse(documentString);
28
+
29
+ }
30
+
31
+ }
@@ -0,0 +1,595 @@
1
+ // @ts-nocheck
2
+ import DocumentUtils from "./DocumentUtils";
3
+ import {ComponentInsertType} from "./ComponentInsertType";
4
+
5
+ function getDocument(): any {
6
+ return {
7
+ views: [
8
+ {
9
+ id: 'id1',
10
+ path: [0],
11
+ children: [
12
+ {
13
+ id: 'id2',
14
+ path: [0, 0],
15
+ },
16
+ {
17
+ id: 'id3',
18
+ path: [0, 1],
19
+ children: [
20
+ {
21
+ id: 'id4',
22
+ path: [0, 1, 0],
23
+ }
24
+
25
+ ]
26
+ },
27
+ {
28
+ id: 'id5',
29
+ path: [0, 2]
30
+ }
31
+
32
+ ]
33
+ },
34
+ {
35
+ id: 'id12',
36
+ path: [1],
37
+ children: [
38
+ {
39
+ id: 'id22',
40
+ path: [1, 0],
41
+ },
42
+ {
43
+ id: 'id32',
44
+ path: [1, 1],
45
+ children: [
46
+ {
47
+ id: 'id42',
48
+ path: [1, 1, 0],
49
+ }
50
+
51
+ ]
52
+ },
53
+ {
54
+ id: 'id52',
55
+ path: [1, 2]
56
+ }
57
+
58
+ ]
59
+ },
60
+ ]
61
+ };
62
+ }
63
+
64
+ describe('DocumentUtils', () => {
65
+
66
+ it('removeNode', function () {
67
+ const document = getDocument();
68
+ const expectedModel = {
69
+ views: [
70
+ {
71
+ id: 'id1',
72
+ path: [0],
73
+ children: [
74
+ {
75
+ id: 'id3',
76
+ path: [0, 0],
77
+ children: [
78
+ {
79
+ id: 'id4',
80
+ path: [0, 0, 0],
81
+ }
82
+
83
+ ]
84
+ },
85
+ {
86
+ id: 'id5',
87
+ path: [0, 1]
88
+ }
89
+
90
+
91
+ ]
92
+ },
93
+ ...document.views.slice(1),
94
+ ]
95
+ };
96
+
97
+ const removedNode = DocumentUtils.removeNode(document.views, [0, 0]);
98
+
99
+ expect(removedNode.id).toEqual('id2');
100
+ expect(document).toEqual(expectedModel);
101
+ });
102
+
103
+ it('removeNode VIEW', function () {
104
+ const document = getDocument();
105
+ const expectedModel = {
106
+ views: [
107
+ {
108
+ id: 'id12',
109
+ path: [0],
110
+ children: [
111
+ {
112
+ id: 'id22',
113
+ path: [0, 0],
114
+ },
115
+ {
116
+ id: 'id32',
117
+ path: [0, 1],
118
+ children: [
119
+ {
120
+ id: 'id42',
121
+ path: [0, 1, 0],
122
+ }
123
+
124
+ ]
125
+ },
126
+ {
127
+ id: 'id52',
128
+ path: [0, 2]
129
+ }
130
+
131
+ ]
132
+ }]
133
+ };
134
+
135
+ const removedNode = DocumentUtils.removeNode(document.views, [0]);
136
+
137
+ expect(removedNode.id).toEqual('id1');
138
+ expect(document).toEqual(expectedModel);
139
+ })
140
+
141
+ it('insertNode before first', function () {
142
+
143
+ const document = getDocument();
144
+ const expectedModel = {
145
+ views: [
146
+ {
147
+ id: 'id1',
148
+ path: [0],
149
+ children: [
150
+ {
151
+ id: 'Inserted',
152
+ path: [0, 0],
153
+ },
154
+ {
155
+ id: 'id2',
156
+ path: [0, 1],
157
+ },
158
+ {
159
+ id: 'id3',
160
+ path: [0, 2],
161
+ children: [
162
+ {
163
+ id: 'id4',
164
+ path: [0, 2, 0],
165
+ }
166
+
167
+ ]
168
+ },
169
+ {
170
+ id: 'id5',
171
+ path: [0, 3]
172
+ }
173
+
174
+ ]
175
+ },
176
+ ...document.views.slice(1),
177
+ ]
178
+ };
179
+
180
+ const node = {
181
+ id: 'Inserted'
182
+ };
183
+
184
+ DocumentUtils.insertNode(node, [0, 0], document.views, ComponentInsertType.BEFORE);
185
+
186
+ expect(document).toEqual(expectedModel);
187
+ });
188
+ it('insertNode in the middle', function () {
189
+
190
+ const document = getDocument();
191
+ const expectedModel = {
192
+ views: [
193
+ {
194
+ id: 'id1',
195
+ path: [0],
196
+ children: [
197
+ {
198
+ id: 'id2',
199
+ path: [0, 0],
200
+ },
201
+ {
202
+ id: 'Inserted',
203
+ path: [0, 1],
204
+ },
205
+ {
206
+ id: 'id3',
207
+ path: [0, 2],
208
+ children: [
209
+ {
210
+ id: 'id4',
211
+ path: [0, 2, 0],
212
+ }
213
+
214
+ ]
215
+ },
216
+ {
217
+ id: 'id5',
218
+ path: [0, 3]
219
+ }
220
+
221
+ ]
222
+ },
223
+ ...document.views.slice(1),
224
+ ]
225
+ };
226
+
227
+ const node = {
228
+ id: 'Inserted'
229
+ };
230
+
231
+ DocumentUtils.insertNode(node, [0, 1], document.views, ComponentInsertType.BEFORE);
232
+
233
+ expect(document).toEqual(expectedModel);
234
+ });
235
+ it('insertNode after last', function () {
236
+
237
+ const document = getDocument();
238
+ const expectedModel = {
239
+ views: [
240
+ {
241
+ id: 'id1',
242
+ path: [0],
243
+ children: [
244
+ {
245
+ id: 'id2',
246
+ path: [0, 0],
247
+ },
248
+ {
249
+ id: 'id3',
250
+ path: [0, 1],
251
+ children: [
252
+ {
253
+ id: 'id4',
254
+ path: [0, 1, 0],
255
+ }
256
+
257
+ ]
258
+ },
259
+ {
260
+ id: 'id5',
261
+ path: [0, 2]
262
+ },
263
+ {
264
+ id: 'Inserted',
265
+ path: [0, 3]
266
+ }
267
+ ]
268
+ },
269
+ ...document.views.slice(1),
270
+ ]
271
+ };
272
+
273
+ const node = {
274
+ id: 'Inserted'
275
+ };
276
+
277
+ DocumentUtils.insertNode(node, [0, 2], document.views, ComponentInsertType.AFTER);
278
+
279
+ expect(document).toEqual(expectedModel);
280
+ });
281
+ it('insertNode VIEW', function () {
282
+
283
+ const document = getDocument();
284
+ const expectedModel = {
285
+ views: [
286
+ {
287
+ id: 'id1',
288
+ path: [0],
289
+ children: [
290
+ {
291
+ id: 'id2',
292
+ path: [0, 0],
293
+ },
294
+ {
295
+ id: 'id3',
296
+ path: [0, 1],
297
+ children: [
298
+ {
299
+ id: 'id4',
300
+ path: [0, 1, 0],
301
+ }
302
+
303
+ ]
304
+ },
305
+ {
306
+ id: 'id5',
307
+ path: [0, 2]
308
+ }
309
+
310
+ ]
311
+ },
312
+ {
313
+ id: 'inserted',
314
+ path: [1],
315
+ children: [
316
+ {
317
+ id: 'inserted',
318
+ path: [1, 0],
319
+ },
320
+ {
321
+ id: 'inserted',
322
+ path: [1, 1],
323
+ children: [
324
+ {
325
+ id: 'inserted',
326
+ path: [1, 1, 0],
327
+ }
328
+
329
+ ]
330
+ },
331
+ {
332
+ id: 'inserted',
333
+ path: [1, 2]
334
+ }
335
+
336
+ ]
337
+ },
338
+ {
339
+ id: 'id12',
340
+ path: [2],
341
+ children: [
342
+ {
343
+ id: 'id22',
344
+ path: [2, 0],
345
+ },
346
+ {
347
+ id: 'id32',
348
+ path: [2, 1],
349
+ children: [
350
+ {
351
+ id: 'id42',
352
+ path: [2, 1, 0],
353
+ }
354
+
355
+ ]
356
+ },
357
+ {
358
+ id: 'id52',
359
+ path: [2, 2]
360
+ }
361
+ ]
362
+ }
363
+ ]
364
+ };
365
+
366
+ const node = {
367
+ id: 'inserted',
368
+ path: [22],
369
+ children: [
370
+ {
371
+ id: 'inserted',
372
+ path: [1, 0],
373
+ },
374
+ {
375
+ id: 'inserted',
376
+ path: [1, 1],
377
+ children: [
378
+ {
379
+ id: 'inserted',
380
+ path: [1, 1, 0],
381
+ }
382
+
383
+ ]
384
+ },
385
+ {
386
+ id: 'inserted',
387
+ path: [1, 2]
388
+ }
389
+
390
+ ]
391
+ };
392
+
393
+ DocumentUtils.insertNode(node, [1], document.views, ComponentInsertType.BEFORE);
394
+
395
+ expect(document).toEqual(expectedModel);
396
+ });
397
+
398
+ it('move node from first to last position', () => {
399
+ const views = [{
400
+ id: 'view1',
401
+ path: [0],
402
+ children: [
403
+ {
404
+ id: 'child1',
405
+ path: [0, 0],
406
+ },
407
+ {
408
+ id: 'child2',
409
+ path: [0, 1],
410
+ },
411
+ {
412
+ id: 'child3',
413
+ path: [0, 2],
414
+ },
415
+ ]
416
+ }];
417
+
418
+ DocumentUtils.moveNode(
419
+ views,
420
+ [0, 0],
421
+ [0, 2],
422
+ ComponentInsertType.AFTER,
423
+ );
424
+
425
+ expect(views[0].children[0].id).toEqual('child2');
426
+ expect(views[0].children[1].id).toEqual('child3');
427
+ expect(views[0].children[2].id).toEqual('child1');
428
+ });
429
+
430
+ it('move node from last to first position', () => {
431
+ const views = [{
432
+ id: 'view1',
433
+ path: [0],
434
+ children: [
435
+ {
436
+ id: 'child1',
437
+ path: [0, 0],
438
+ },
439
+ {
440
+ id: 'child2',
441
+ path: [0, 1],
442
+ },
443
+ {
444
+ id: 'child3',
445
+ path: [0, 2],
446
+ },
447
+ ]
448
+ }];
449
+
450
+ DocumentUtils.moveNode(
451
+ views,
452
+ [0, 2],
453
+ [0, 0],
454
+ ComponentInsertType.BEFORE,
455
+ );
456
+
457
+ expect(views[0].children[0].id).toEqual('child3');
458
+ expect(views[0].children[1].id).toEqual('child1');
459
+ expect(views[0].children[2].id).toEqual('child2');
460
+ });
461
+
462
+ it('move node from first view to second one', () => {
463
+ const views = [
464
+ {
465
+ id: 'view1',
466
+ path: [0],
467
+ children: [
468
+ {
469
+ id: 'child1',
470
+ path: [0, 0],
471
+ },
472
+ {
473
+ id: 'child2',
474
+ path: [0, 1],
475
+ },
476
+ ]
477
+ },
478
+ {
479
+ id: 'view2',
480
+ path: [1],
481
+ children: [
482
+ {
483
+ id: 'child3',
484
+ path: [1, 0],
485
+ },
486
+ ]
487
+ }
488
+ ];
489
+
490
+ DocumentUtils.moveNode(
491
+ views,
492
+ [0, 0],
493
+ [1, 0],
494
+ ComponentInsertType.BEFORE,
495
+ );
496
+
497
+ expect(views[0].children[0].id).toEqual('child2');
498
+ expect(views[1].children[0].id).toEqual('child1');
499
+ expect(views[1].children[1].id).toEqual('child3');
500
+ });
501
+
502
+ it('iterateDepthFirst', function () {
503
+ const node = {
504
+ children: [
505
+ {},
506
+ {},
507
+ {}
508
+ ]
509
+ };
510
+ const expected = {
511
+ upd: true,
512
+ children: [
513
+ {upd: true,},
514
+ {upd: true,},
515
+ {upd: true,}
516
+ ]
517
+ }
518
+
519
+ DocumentUtils.iterateDepthFirst(node, (node) => node.upd = true);
520
+ expect(node).toEqual(expected);
521
+
522
+ });
523
+
524
+ it('reIndex', function () {
525
+ const expectedModel = getDocument();
526
+ const document = {
527
+ views: [
528
+ {
529
+ id: 'id1',
530
+
531
+ children: [
532
+ {
533
+ id: 'id2',
534
+ path: [23],
535
+ },
536
+ {
537
+ id: 'id3',
538
+ children: [
539
+ {
540
+ id: 'id4',
541
+ }
542
+
543
+ ]
544
+ },
545
+ {
546
+ id: 'id5',
547
+ }
548
+ ]
549
+ },
550
+ ...expectedModel.views.slice(1),
551
+ ]
552
+ };
553
+
554
+ DocumentUtils.reIndex(document.views[0], [0]);
555
+
556
+ expect(document).toEqual(expectedModel);
557
+ });
558
+
559
+ it('getRelativePath', function () {
560
+ expect(DocumentUtils.getRelativePath([0, 1])).toEqual([1]);
561
+ });
562
+
563
+ it('getParentPath', function () {
564
+ expect(DocumentUtils.getParentPath([0, 1])).toEqual([0]);
565
+ });
566
+
567
+ it('getNodeByPath', function () {
568
+
569
+ const node1 = DocumentUtils.getNodeByPath(getDocument().views, [0, 1, 0]);
570
+ expect(node1.id).toEqual('id4');
571
+
572
+ const node2 = DocumentUtils.getNodeByPath(getDocument().views, [1, 1, 0]);
573
+ expect(node2.id).toEqual('id42');
574
+ });
575
+
576
+ it('getNodeById', function () {
577
+
578
+ const node = DocumentUtils.getNodeById(getDocument().views, 'id4');
579
+ expect(node.path).toEqual([0, 1, 0]);
580
+ });
581
+
582
+ it('getPathToInsert', function () {
583
+ const pathToInsert = DocumentUtils.getPathToInsert([0, 0], ComponentInsertType.BEFORE, getDocument().views);
584
+ expect(pathToInsert).toEqual([0, 0]);
585
+
586
+ const pathToInsert1 = DocumentUtils.getPathToInsert([0, 2], ComponentInsertType.AFTER, getDocument().views);
587
+ expect(pathToInsert1).toEqual([0, 3]);
588
+
589
+ const pathToInsert2 = DocumentUtils.getPathToInsert([0, 1], ComponentInsertType.AFTER, getDocument().views);
590
+ expect(pathToInsert2).toEqual([0, 2]);
591
+
592
+ const pathToInsert3 = DocumentUtils.getPathToInsert([0], ComponentInsertType.INSIDE, getDocument().views);
593
+ expect(pathToInsert3).toEqual([0, 3]);
594
+ });
595
+ })