@mgdis/mg-components 5.22.0 → 5.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/dist/cjs/{index-28bf9033.js → index-0cf3e6d5.js} +22 -13
  2. package/dist/cjs/index-0cf3e6d5.js.map +1 -0
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/mg-action-more_34.cjs.entry.js +225 -158
  5. package/dist/cjs/mg-action-more_34.cjs.entry.js.map +1 -1
  6. package/dist/cjs/mg-components.cjs.js +2 -2
  7. package/dist/cjs/mg-components.cjs.js.map +1 -1
  8. package/dist/cjs/mg-item-more.cjs.entry.js +7 -6
  9. package/dist/cjs/mg-item-more.cjs.entry.js.map +1 -1
  10. package/dist/cjs/mg-menu.conf-0229bb75.js +333 -0
  11. package/dist/cjs/mg-menu.conf-0229bb75.js.map +1 -0
  12. package/dist/collection/collection-manifest.json +2 -2
  13. package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -1
  14. package/dist/collection/components/atoms/mg-badge/mg-badge.js.map +1 -1
  15. package/dist/collection/components/atoms/mg-button/mg-button.js +1 -1
  16. package/dist/collection/components/atoms/mg-button/mg-button.js.map +1 -1
  17. package/dist/collection/components/atoms/mg-card/mg-card.js +1 -1
  18. package/dist/collection/components/atoms/mg-card/mg-card.js.map +1 -1
  19. package/dist/collection/components/atoms/mg-character-left/mg-character-left.js.map +1 -1
  20. package/dist/collection/components/atoms/mg-icon/mg-icon.js +1 -1
  21. package/dist/collection/components/atoms/mg-icon/mg-icon.js.map +1 -1
  22. package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +1 -1
  23. package/dist/collection/components/atoms/mg-input-title/mg-input-title.js.map +1 -1
  24. package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -1
  25. package/dist/collection/components/atoms/mg-tag/mg-tag.js.map +1 -1
  26. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +1 -1
  27. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
  28. package/dist/collection/components/molecules/inputs/MgInput.js +1 -1
  29. package/dist/collection/components/molecules/inputs/MgInput.js.map +1 -1
  30. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js.map +1 -1
  31. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +10 -7
  32. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
  33. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +35 -6
  34. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
  35. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +1 -2
  36. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
  37. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +1 -1
  38. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
  39. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
  40. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
  41. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +1 -1
  42. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
  43. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +1 -1
  44. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
  45. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
  46. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
  47. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
  48. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js.map +1 -1
  49. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js.map +1 -1
  50. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +1 -1
  51. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js.map +1 -1
  52. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +1 -1
  53. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js.map +1 -1
  54. package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
  55. package/dist/collection/components/molecules/mg-details/mg-details.js.map +1 -1
  56. package/dist/collection/components/molecules/mg-form/mg-form.js +1 -1
  57. package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
  58. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -1
  59. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js.map +1 -1
  60. package/dist/collection/components/molecules/mg-item-more/mg-item-more.js +1 -1
  61. package/dist/collection/components/molecules/mg-item-more/mg-item-more.js.map +1 -1
  62. package/dist/collection/components/molecules/mg-message/mg-message.js +1 -1
  63. package/dist/collection/components/molecules/mg-message/mg-message.js.map +1 -1
  64. package/dist/collection/components/molecules/mg-modal/mg-modal.js +6 -5
  65. package/dist/collection/components/molecules/mg-modal/mg-modal.js.map +1 -1
  66. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +1 -1
  67. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js.map +1 -1
  68. package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
  69. package/dist/collection/components/molecules/mg-panel/mg-panel.js.map +1 -1
  70. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
  71. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js.map +1 -1
  72. package/dist/collection/components/molecules/mg-popover/mg-popover.js +1 -1
  73. package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
  74. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
  75. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js.map +1 -1
  76. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +1 -1
  77. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js.map +1 -1
  78. package/dist/collection/locales/en/messages.json +9 -1
  79. package/dist/collection/locales/fr/messages.json +9 -1
  80. package/dist/collection/locales/index.js +2 -2
  81. package/dist/collection/locales/index.js.map +1 -1
  82. package/dist/collection/utils/behaviors.utils.js.map +1 -1
  83. package/dist/collection/utils/behaviors.utils.spec.js +1 -1
  84. package/dist/collection/utils/behaviors.utils.spec.js.map +1 -1
  85. package/dist/collection/utils/unit.test.utils.js +0 -104
  86. package/dist/collection/utils/unit.test.utils.js.map +1 -1
  87. package/dist/components/MgInput.js +3 -3
  88. package/dist/components/MgInput.js.map +1 -1
  89. package/dist/components/index.es.js +75 -0
  90. package/dist/components/index.es.js.map +1 -0
  91. package/dist/components/index2.js +22 -61
  92. package/dist/components/index2.js.map +1 -1
  93. package/dist/components/mg-action-more.js +5 -4
  94. package/dist/components/mg-action-more.js.map +1 -1
  95. package/dist/components/mg-badge2.js +5 -4
  96. package/dist/components/mg-badge2.js.map +1 -1
  97. package/dist/components/mg-button2.js +6 -5
  98. package/dist/components/mg-button2.js.map +1 -1
  99. package/dist/components/mg-card2.js +4 -3
  100. package/dist/components/mg-card2.js.map +1 -1
  101. package/dist/components/mg-character-left2.js +2 -1
  102. package/dist/components/mg-character-left2.js.map +1 -1
  103. package/dist/components/mg-details.js +4 -3
  104. package/dist/components/mg-details.js.map +1 -1
  105. package/dist/components/mg-divider.js +2 -1
  106. package/dist/components/mg-divider.js.map +1 -1
  107. package/dist/components/mg-form.js +5 -4
  108. package/dist/components/mg-form.js.map +1 -1
  109. package/dist/components/mg-icon2.js +4 -3
  110. package/dist/components/mg-icon2.js.map +1 -1
  111. package/dist/components/mg-illustrated-message.js +4 -3
  112. package/dist/components/mg-illustrated-message.js.map +1 -1
  113. package/dist/components/mg-input-checkbox.js +16 -12
  114. package/dist/components/mg-input-checkbox.js.map +1 -1
  115. package/dist/components/mg-input-date.js +41 -10
  116. package/dist/components/mg-input-date.js.map +1 -1
  117. package/dist/components/mg-input-numeric.js +7 -6
  118. package/dist/components/mg-input-numeric.js.map +1 -1
  119. package/dist/components/mg-input-password.js +5 -4
  120. package/dist/components/mg-input-password.js.map +1 -1
  121. package/dist/components/mg-input-radio.js +6 -5
  122. package/dist/components/mg-input-radio.js.map +1 -1
  123. package/dist/components/mg-input-select2.js +8 -7
  124. package/dist/components/mg-input-select2.js.map +1 -1
  125. package/dist/components/mg-input-text2.js +8 -7
  126. package/dist/components/mg-input-text2.js.map +1 -1
  127. package/dist/components/mg-input-textarea.js +8 -7
  128. package/dist/components/mg-input-textarea.js.map +1 -1
  129. package/dist/components/mg-input-title2.js +4 -3
  130. package/dist/components/mg-input-title2.js.map +1 -1
  131. package/dist/components/mg-input-toggle.js +6 -5
  132. package/dist/components/mg-input-toggle.js.map +1 -1
  133. package/dist/components/mg-item-more.js +4 -3
  134. package/dist/components/mg-item-more.js.map +1 -1
  135. package/dist/components/mg-menu-item2.js +6 -5
  136. package/dist/components/mg-menu-item2.js.map +1 -1
  137. package/dist/components/mg-menu2.js +2 -1
  138. package/dist/components/mg-menu2.js.map +1 -1
  139. package/dist/components/mg-message.js +5 -4
  140. package/dist/components/mg-message.js.map +1 -1
  141. package/dist/components/mg-modal.js +12 -10
  142. package/dist/components/mg-modal.js.map +1 -1
  143. package/dist/components/mg-pagination2.js +4 -3
  144. package/dist/components/mg-pagination2.js.map +1 -1
  145. package/dist/components/mg-panel.js +6 -5
  146. package/dist/components/mg-panel.js.map +1 -1
  147. package/dist/components/mg-popover-content2.js +5 -4
  148. package/dist/components/mg-popover-content2.js.map +1 -1
  149. package/dist/components/mg-popover2.js +5 -4
  150. package/dist/components/mg-popover2.js.map +1 -1
  151. package/dist/components/mg-skip-links.js +4 -3
  152. package/dist/components/mg-skip-links.js.map +1 -1
  153. package/dist/components/mg-tabs.js +8 -7
  154. package/dist/components/mg-tabs.js.map +1 -1
  155. package/dist/components/mg-tag.js +5 -4
  156. package/dist/components/mg-tag.js.map +1 -1
  157. package/dist/components/mg-tooltip-content2.js +2 -1
  158. package/dist/components/mg-tooltip-content2.js.map +1 -1
  159. package/dist/components/mg-tooltip2.js +8 -7
  160. package/dist/components/mg-tooltip2.js.map +1 -1
  161. package/dist/esm/{index-93dafb06.js → index-91977c3d.js} +22 -13
  162. package/dist/esm/index-91977c3d.js.map +1 -0
  163. package/dist/esm/loader.js +2 -2
  164. package/dist/esm/mg-action-more_34.entry.js +193 -126
  165. package/dist/esm/mg-action-more_34.entry.js.map +1 -1
  166. package/dist/esm/mg-components.js +3 -3
  167. package/dist/esm/mg-components.js.map +1 -1
  168. package/dist/esm/mg-item-more.entry.js +5 -4
  169. package/dist/esm/mg-item-more.entry.js.map +1 -1
  170. package/dist/esm/mg-menu.conf-4b2d2eab.js +315 -0
  171. package/dist/esm/mg-menu.conf-4b2d2eab.js.map +1 -0
  172. package/dist/mg-components/locales/en/messages.json +9 -1
  173. package/dist/mg-components/locales/fr/messages.json +9 -1
  174. package/dist/mg-components/mg-components.esm.js +1 -1
  175. package/dist/mg-components/mg-components.esm.js.map +1 -1
  176. package/dist/mg-components/p-1564df7a.js +2 -0
  177. package/dist/mg-components/p-1564df7a.js.map +1 -0
  178. package/dist/mg-components/p-49e1ffcb.js +3 -0
  179. package/dist/mg-components/p-49e1ffcb.js.map +1 -0
  180. package/dist/mg-components/p-6c68c7eb.entry.js +2 -0
  181. package/dist/mg-components/p-6c68c7eb.entry.js.map +1 -0
  182. package/dist/mg-components/p-d6d71404.entry.js +2 -0
  183. package/dist/mg-components/p-d6d71404.entry.js.map +1 -0
  184. package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +1 -1
  185. package/dist/types/components/atoms/mg-button/mg-button.d.ts +1 -1
  186. package/dist/types/components/atoms/mg-card/mg-card.d.ts +1 -1
  187. package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +1 -1
  188. package/dist/types/components/atoms/mg-tag/mg-tag.d.ts +1 -1
  189. package/dist/types/components/molecules/inputs/MgInput.d.ts +1 -1
  190. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +1 -1
  191. package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +18 -1
  192. package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +1 -1
  193. package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +1 -1
  194. package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +1 -1
  195. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +1 -1
  196. package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +1 -1
  197. package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +1 -1
  198. package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +1 -1
  199. package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +1 -1
  200. package/dist/types/components/molecules/mg-form/mg-form.d.ts +1 -1
  201. package/dist/types/components/molecules/mg-message/mg-message.d.ts +1 -1
  202. package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +1 -1
  203. package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +1 -1
  204. package/dist/types/components/molecules/mg-popover/mg-popover-content/mg-popover-content.d.ts +1 -1
  205. package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +1 -1
  206. package/dist/types/components.d.ts +2 -2
  207. package/dist/types/locales/index.d.ts +1 -180
  208. package/dist/types/utils/unit.test.utils.d.ts +0 -82
  209. package/package.json +33 -32
  210. package/dist/cjs/components.utils-637c479d.js +0 -447
  211. package/dist/cjs/components.utils-637c479d.js.map +0 -1
  212. package/dist/cjs/index-28bf9033.js.map +0 -1
  213. package/dist/collection/utils/components.utils.js +0 -147
  214. package/dist/collection/utils/components.utils.js.map +0 -1
  215. package/dist/collection/utils/components.utils.spec.js +0 -156
  216. package/dist/collection/utils/components.utils.spec.js.map +0 -1
  217. package/dist/collection/utils/e2e.test.utils.js +0 -46
  218. package/dist/collection/utils/e2e.test.utils.js.map +0 -1
  219. package/dist/collection/utils/locale.utils.js +0 -57
  220. package/dist/collection/utils/locale.utils.js.map +0 -1
  221. package/dist/collection/utils/locale.utils.spec.js +0 -52
  222. package/dist/collection/utils/locale.utils.spec.js.map +0 -1
  223. package/dist/components/components.utils.js +0 -150
  224. package/dist/components/components.utils.js.map +0 -1
  225. package/dist/esm/components.utils-f7c073a0.js +0 -431
  226. package/dist/esm/components.utils-f7c073a0.js.map +0 -1
  227. package/dist/esm/index-93dafb06.js.map +0 -1
  228. package/dist/mg-components/p-457dd62a.entry.js +0 -2
  229. package/dist/mg-components/p-457dd62a.entry.js.map +0 -1
  230. package/dist/mg-components/p-4fa40a8f.entry.js +0 -2
  231. package/dist/mg-components/p-4fa40a8f.entry.js.map +0 -1
  232. package/dist/mg-components/p-721c4571.js +0 -2
  233. package/dist/mg-components/p-721c4571.js.map +0 -1
  234. package/dist/mg-components/p-8155d0e2.js +0 -3
  235. package/dist/mg-components/p-8155d0e2.js.map +0 -1
  236. package/dist/types/utils/components.utils.d.ts +0 -87
  237. package/dist/types/utils/e2e.test.utils.d.ts +0 -22
  238. package/dist/types/utils/locale.utils.d.ts +0 -38
@@ -1,147 +0,0 @@
1
- /**
2
- * Create random ID
3
- * @param prefix - add prefix to created ID
4
- * @param length - ID length
5
- * @returns ID
6
- */
7
- export const createID = (prefix = '', length = 10) => {
8
- const randomBytes = new Uint8Array(length);
9
- crypto.getRandomValues(randomBytes);
10
- const hexString = Array.from(randomBytes)
11
- .map(byte => byte.toString(16).padStart(2, '0'))
12
- .join('')
13
- .slice(0, length);
14
- return prefix !== '' ? `${prefix}-${hexString}` : hexString;
15
- };
16
- /**
17
- * Class to manage component classlist
18
- * Set() are not working when imported in project
19
- */
20
- export class ClassList {
21
- constructor(classlist = []) {
22
- /**
23
- * Add class
24
- * @param className - class name to add
25
- */
26
- this.add = (className) => {
27
- if (!this.has(className)) {
28
- this.classes.push(className);
29
- }
30
- };
31
- /**
32
- * Delete class
33
- * @param className - class name to delete
34
- */
35
- this.delete = (className) => {
36
- const index = this.classes.indexOf(className);
37
- if (index > -1) {
38
- this.classes.splice(index, 1);
39
- }
40
- };
41
- /**
42
- * Check if class exist in list
43
- * @param className - class name to check
44
- * @returns class name is in the list
45
- */
46
- this.has = (className) => {
47
- return this.classes.includes(className);
48
- };
49
- /**
50
- * Join classes seperated by spaces
51
- * @returns joined values
52
- */
53
- this.join = () => {
54
- return this.classes.join(' ');
55
- };
56
- this.classes = classlist;
57
- }
58
- }
59
- /**
60
- * Check if all items are string
61
- * @param items - items to check
62
- * @returns all items are string
63
- */
64
- export const allItemsAreString = (items) => Array.isArray(items) && items.every(item => typeof item === 'string');
65
- /**
66
- * Check if element is a heading
67
- * @param element - slotted element
68
- * @param tagNames - allowed tag names list
69
- * @returns element is a heading
70
- */
71
- export const isTagName = (element, tagNames) => {
72
- return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
73
- };
74
- /**
75
- * Focusable elements query selector
76
- */
77
- export const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier]';
78
- /**
79
- * Get windows
80
- * @param localWindow - the window we are lookink for other windows
81
- * @returns The list of windows found
82
- */
83
- export const getWindows = (localWindow) => {
84
- const parentWindows = getParentWindows(localWindow);
85
- const childWindows = getChildWindows(localWindow);
86
- return [localWindow, ...parentWindows, ...childWindows];
87
- };
88
- /**
89
- * Get parent windows
90
- * @param localWindow - the window we are lookink for parents
91
- * @param windows - The list of allready found windows
92
- * @returns The list of windows found
93
- */
94
- export const getParentWindows = (localWindow, windows = []) => {
95
- // Check if is in iframe
96
- if (localWindow.self !== localWindow.top) {
97
- // Check if we have permission to access parent
98
- try {
99
- const parentWindow = localWindow.parent;
100
- windows.push(parentWindow);
101
- return getParentWindows(parentWindow, windows);
102
- }
103
- catch (err) {
104
- console.error('Different hosts between iframes:', err);
105
- return windows;
106
- }
107
- }
108
- return windows;
109
- };
110
- /**
111
- * Get child windows
112
- * @param localWindow - the window we are lookink for children
113
- * @param windows - The list of allready found windows
114
- * @returns The list of windows found
115
- */
116
- const getChildWindows = (localWindow, windows = []) => {
117
- if (localWindow.frames.length > 0) {
118
- for (const childWindow of Array.from(localWindow.frames)) {
119
- windows.push(childWindow);
120
- getChildWindows(childWindow, windows);
121
- }
122
- }
123
- return windows;
124
- };
125
- /**
126
- * Validate string
127
- * @param value - value to check
128
- * @returns if string is valid
129
- */
130
- export const isValidString = (value) => typeof value === 'string' && value.trim() !== '';
131
- /**
132
- * Clean string caraters
133
- * @param text - text to cliean
134
- * @returns cleanded string
135
- */
136
- export const cleanString = (text) => typeof text === 'string' &&
137
- text
138
- .toLocaleLowerCase()
139
- .normalize('NFD')
140
- .replaceAll(/[\u0300-\u036f]/g, '');
141
- /**
142
- * Use to process code next tick in the event loop
143
- * @param callback - code to excute on next tick
144
- * @returns differed code excution
145
- */
146
- export const nextTick = async (callback) => callback();
147
- //# sourceMappingURL=components.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.utils.js","sourceRoot":"","sources":["../../src/utils/components.utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAU,EAAE;IAC3D,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAE3C,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAEpC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC;SACtC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC/C,IAAI,CAAC,EAAE,CAAC;SACR,KAAK,CAAC,CAAC,E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CAAC,EAAE;QACjC,KAAK,MAAM,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;YACxD,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC1B,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;SACvC;KACF;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AAE3G;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAClD,OAAO,IAAI,KAAK,QAAQ;IACxB,IAAI;SACD,iBAAiB,EAAE;SACnB,SAAS,CAAC,KAAK,CAAC;SAChB,UAAU,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,QAAoB,EAAiB,EAAE,CAAC,QAAQ,EAAE,CAAC","sourcesContent":["/**\n * Create random ID\n * @param prefix - add prefix to created ID\n * @param length - ID length\n * @returns ID\n */\nexport const createID = (prefix = '', length = 10): string => {\n const randomBytes = new Uint8Array(length);\n\n crypto.getRandomValues(randomBytes);\n\n const hexString = Array.from(randomBytes)\n .map(byte => byte.toString(16).padStart(2, '0'))\n .join('')\n .slice(0, length);\n\n return prefix !== '' ? `${prefix}-${hexString}` : hexString;\n};\n\n/**\n * Class to manage component classlist\n * Set() are not working when imported in project\n */\nexport class ClassList {\n /**\n * Available classes\n */\n classes: string[];\n\n constructor(classlist: string[] = []) {\n this.classes = classlist;\n }\n\n /**\n * Add class\n * @param className - class name to add\n */\n add = (className: string): void => {\n if (!this.has(className)) {\n this.classes.push(className);\n }\n };\n\n /**\n * Delete class\n * @param className - class name to delete\n */\n delete = (className: string): void => {\n const index = this.classes.indexOf(className);\n if (index > -1) {\n this.classes.splice(index, 1);\n }\n };\n\n /**\n * Check if class exist in list\n * @param className - class name to check\n * @returns class name is in the list\n */\n has = (className: string): boolean => {\n return this.classes.includes(className);\n };\n\n /**\n * Join classes seperated by spaces\n * @returns joined values\n */\n join = (): string => {\n return this.classes.join(' ');\n };\n}\n\n/**\n * Check if all items are string\n * @param items - items to check\n * @returns all items are string\n */\nexport const allItemsAreString = (items: unknown): items is string[] => Array.isArray(items) && items.every(item => typeof item === 'string');\n\n/**\n * Check if element is a heading\n * @param element - slotted element\n * @param tagNames - allowed tag names list\n * @returns element is a heading\n */\nexport const isTagName = (element: Element, tagNames: string[]): boolean => {\n return tagNames.includes(element?.tagName.toLowerCase());\n};\n\n/**\n * Focusable elements query selector\n */\nexport const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex=\"-1\"]), [identifier]';\n\n/**\n * Get windows\n * @param localWindow - the window we are lookink for other windows\n * @returns The list of windows found\n */\nexport const getWindows = (localWindow: Window): Window[] => {\n const parentWindows = getParentWindows(localWindow);\n const childWindows = getChildWindows(localWindow);\n return [localWindow, ...parentWindows, ...childWindows];\n};\n\n/**\n * Get parent windows\n * @param localWindow - the window we are lookink for parents\n * @param windows - The list of allready found windows\n * @returns The list of windows found\n */\nexport const getParentWindows = (localWindow: Window, windows: Window[] = []): Window[] => {\n // Check if is in iframe\n if (localWindow.self !== localWindow.top) {\n // Check if we have permission to access parent\n try {\n const parentWindow: Window = localWindow.parent;\n windows.push(parentWindow);\n return getParentWindows(parentWindow, windows);\n } catch (err) {\n console.error('Different hosts between iframes:', err);\n return windows;\n }\n }\n return windows;\n};\n\n/**\n * Get child windows\n * @param localWindow - the window we are lookink for children\n * @param windows - The list of allready found windows\n * @returns The list of windows found\n */\nconst getChildWindows = (localWindow: Window, windows: Window[] = []): Window[] => {\n if (localWindow.frames.length > 0) {\n for (const childWindow of Array.from(localWindow.frames)) {\n windows.push(childWindow);\n getChildWindows(childWindow, windows);\n }\n }\n return windows;\n};\n\n/**\n * Validate string\n * @param value - value to check\n * @returns if string is valid\n */\nexport const isValidString = (value: unknown): boolean => typeof value === 'string' && value.trim() !== '';\n\n/**\n * Clean string caraters\n * @param text - text to cliean\n * @returns cleanded string\n */\nexport const cleanString = (text: string): string =>\n typeof text === 'string' &&\n text\n .toLocaleLowerCase()\n .normalize('NFD')\n .replaceAll(/[\\u0300-\\u036f]/g, '');\n\n/**\n * Use to process code next tick in the event loop\n * @param callback - code to excute on next tick\n * @returns differed code excution\n */\nexport const nextTick = async (callback: () => void): Promise<void> => callback();\n"]}
@@ -1,156 +0,0 @@
1
- import { createID, ClassList, allItemsAreString, isTagName, getWindows, isValidString, cleanString, nextTick } from "./components.utils";
2
- import { mockConsoleError } from "./unit.test.utils";
3
- mockConsoleError();
4
- describe('components.utils', () => {
5
- describe('createID', () => {
6
- test.each([undefined, '', 'blu'])('Should generate a prefixed ID if defined : %s', prefix => {
7
- const id = createID(prefix);
8
- let regexp = /^[a-z0-9]{10}$/;
9
- if (prefix !== undefined && prefix !== '') {
10
- regexp = new RegExp(`^${prefix}-[a-z0-9]{10}$`);
11
- }
12
- expect(id).toMatch(regexp);
13
- });
14
- test('Should generate a unique ID when both are created at the same time', () => {
15
- const id1 = createID();
16
- const id2 = createID();
17
- expect(id1).not.toEqual(id2);
18
- });
19
- });
20
- describe('ClassList', () => {
21
- test('Should add classes to list', () => {
22
- const classCollection = new ClassList();
23
- expect(classCollection.classes).toEqual([]);
24
- classCollection.add('blu');
25
- expect(classCollection.classes).toEqual(['blu']);
26
- classCollection.add('bli');
27
- expect(classCollection.classes).toEqual(['blu', 'bli']);
28
- // Should not add classes if already in list
29
- classCollection.add('blu');
30
- expect(classCollection.classes).toEqual(['blu', 'bli']);
31
- });
32
- test('Should delete classes from list', () => {
33
- const classCollection = new ClassList(['blu', 'bli']);
34
- classCollection.delete('blu');
35
- expect(classCollection.classes).toEqual(['bli']);
36
- // List doesn't change if class name doesn't existe in list
37
- classCollection.delete('bla');
38
- expect(classCollection.classes).toEqual(['bli']);
39
- });
40
- test('Should check if class already in list', () => {
41
- const classCollection = new ClassList(['blu']);
42
- expect(classCollection.has('blu')).toEqual(true);
43
- expect(classCollection.has('bli')).toEqual(false);
44
- });
45
- test('Should return seperated space classes list', () => {
46
- const classCollection = new ClassList(['blu', 'bli']);
47
- expect(classCollection.join()).toEqual('blu bli');
48
- });
49
- });
50
- describe('allItemsAreString', () => {
51
- test.each([
52
- { items: ['blu', 'bli', 'blo', 'bla'], expected: true },
53
- { items: ['blu', 'bli', 'blo', { value: 'bla' }], expected: false },
54
- ])('Should test if all otems are string: %s', ({ items, expected }) => {
55
- expect(allItemsAreString(items)).toEqual(expected);
56
- });
57
- });
58
- describe('isTagName', () => {
59
- test.each([
60
- { querySelector: 'h1', expected: true },
61
- { querySelector: 'span', expected: false },
62
- { querySelector: 'blu', expected: false },
63
- ])('Should test if all otems are string: %s', ({ querySelector, expected }) => {
64
- const div = document.createElement('div');
65
- div.innerHTML = '<h1></h1><span></span>';
66
- const elm = div.querySelector(querySelector);
67
- expect(isTagName(elm, ['h1'])).toEqual(expected);
68
- });
69
- });
70
- describe('getWindows', () => {
71
- const mockWindowFramesLength = jest.fn();
72
- const mockWindowIndexZero = jest.fn();
73
- Object.defineProperty(window, 'frames', {
74
- value: {
75
- get length() {
76
- return mockWindowFramesLength();
77
- },
78
- get 0() {
79
- return mockWindowIndexZero();
80
- },
81
- },
82
- });
83
- afterEach(() => {
84
- jest.clearAllMocks();
85
- });
86
- test('Should return the window in an array', () => {
87
- mockWindowFramesLength.mockReturnValue(0);
88
- const localWindow = window;
89
- const windows = getWindows(localWindow);
90
- expect(windows).toHaveLength(1);
91
- expect(windows[0]).toEqual(localWindow);
92
- });
93
- test('Should return the window with a parent', () => {
94
- mockWindowFramesLength.mockReturnValue(0);
95
- const spyWindowSelf = jest.spyOn(window, 'self', 'get').mockImplementationOnce(jest.fn());
96
- const spyWindowParent = jest.spyOn(window, 'parent', 'get').mockImplementationOnce(() => window);
97
- const windows = getWindows(window);
98
- expect(windows).toHaveLength(2);
99
- expect(spyWindowSelf).toBeCalledTimes(2);
100
- expect(spyWindowParent).toBeCalledTimes(1);
101
- });
102
- test('Should return the window with a child', () => {
103
- mockWindowFramesLength.mockReturnValueOnce(1).mockReturnValueOnce(1).mockReturnValue(0);
104
- mockWindowIndexZero.mockReturnValueOnce(window);
105
- const windows = getWindows(window);
106
- expect(windows).toHaveLength(2);
107
- });
108
- test('Should throw an error when cannot access top parent window', () => {
109
- mockWindowFramesLength.mockReturnValue(0);
110
- const spyConsole = jest.spyOn(console, 'error');
111
- const spyWindowSelf = jest.spyOn(window, 'self', 'get').mockImplementationOnce(jest.fn());
112
- const spyWindowParent = jest.spyOn(window, 'parent', 'get').mockImplementationOnce(() => {
113
- throw new Error('non');
114
- });
115
- const localWindow = window;
116
- const windows = getWindows(localWindow);
117
- expect(windows).toHaveLength(1);
118
- expect(windows[0]).toEqual(localWindow);
119
- expect(spyConsole).toBeCalledTimes(1);
120
- expect(spyWindowSelf).toBeCalledTimes(1);
121
- expect(spyWindowParent).toBeCalledTimes(1);
122
- });
123
- });
124
- describe('isValidString', () => {
125
- test.each(['', ' ', null, undefined, 1, {}, []])('Should return "false" for invalid values', value => {
126
- expect(isValidString(value)).toEqual(false);
127
- });
128
- test.each(['batman', 'batman '])('Should return "true" for valid value', value => {
129
- expect(isValidString(value)).toEqual(true);
130
- });
131
- });
132
- describe('cleanString', () => {
133
- test.each([
134
- { string: 'batman', expected: 'batman' },
135
- { string: 'BATMAN', expected: 'batman' },
136
- { string: 'Batman', expected: 'batman' },
137
- { string: ' batman ', expected: ' batman ' },
138
- { string: ' batman', expected: ' batman' },
139
- { string: 'batman ', expected: 'batman ' },
140
- { string: 'âäàçéèêñù', expected: 'aaaceeenu' },
141
- ])('Should format string properly', ({ string, expected }) => {
142
- expect(cleanString(string)).toEqual(expected);
143
- });
144
- });
145
- describe('nextTick', () => {
146
- test('Should wrapp and execute a callback in a promise', async () => {
147
- const fn = jest.fn();
148
- const job = nextTick(fn);
149
- expect(job.then).toBeDefined();
150
- const res = await job;
151
- expect(fn).toHaveBeenCalled();
152
- expect(res).toBeUndefined();
153
- });
154
- });
155
- });
156
- //# sourceMappingURL=components.utils.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.utils.spec.js","sourceRoot":"","sources":["../../src/utils/components.utils.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACzI,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,gBAAgB,EAAE,CAAC;AAEnB,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;QACxB,IAAI,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,+CAA+C,EAAE,MAAM,CAAC,EAAE;YAC1F,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC5B,IAAI,MAAM,GAAG,gBAAgB,CAAC;YAC9B,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE,EAAE;gBACzC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,MAAM,gBAAgB,CAAC,CAAC;aACjD;YACD,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,oEAAoE,EAAE,GAAG,EAAE;YAC9E,MAAM,GAAG,GAAG,QAAQ,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,QAAQ,EAAE,CAAC;YACvB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,GA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CAAC,CAAC,WAAW,EAAE,CAAC;YAE/B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC;YACtB,MAAM,CAAC,EAAE,CAAC,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createID, ClassList, allItemsAreString, isTagName, getWindows, isValidString, cleanString, nextTick } from './components.utils';\nimport { mockConsoleError } from './unit.test.utils';\n\nmockConsoleError();\n\ndescribe('components.utils', () => {\n describe('createID', () => {\n test.each([undefined, '', 'blu'])('Should generate a prefixed ID if defined : %s', prefix => {\n const id = createID(prefix);\n let regexp = /^[a-z0-9]{10}$/;\n if (prefix !== undefined && prefix !== '') {\n regexp = new RegExp(`^${prefix}-[a-z0-9]{10}$`);\n }\n expect(id).toMatch(regexp);\n });\n test('Should generate a unique ID when both are created at the same time', () => {\n const id1 = createID();\n const id2 = createID();\n expect(id1).not.toEqual(id2);\n });\n });\n\n describe('ClassList', () => {\n test('Should add classes to list', () => {\n const classCollection = new ClassList();\n expect(classCollection.classes).toEqual([]);\n classCollection.add('blu');\n expect(classCollection.classes).toEqual(['blu']);\n classCollection.add('bli');\n expect(classCollection.classes).toEqual(['blu', 'bli']);\n // Should not add classes if already in list\n classCollection.add('blu');\n expect(classCollection.classes).toEqual(['blu', 'bli']);\n });\n\n test('Should delete classes from list', () => {\n const classCollection = new ClassList(['blu', 'bli']);\n classCollection.delete('blu');\n expect(classCollection.classes).toEqual(['bli']);\n // List doesn't change if class name doesn't existe in list\n classCollection.delete('bla');\n expect(classCollection.classes).toEqual(['bli']);\n });\n\n test('Should check if class already in list', () => {\n const classCollection = new ClassList(['blu']);\n expect(classCollection.has('blu')).toEqual(true);\n expect(classCollection.has('bli')).toEqual(false);\n });\n\n test('Should return seperated space classes list', () => {\n const classCollection = new ClassList(['blu', 'bli']);\n expect(classCollection.join()).toEqual('blu bli');\n });\n });\n\n describe('allItemsAreString', () => {\n test.each([\n { items: ['blu', 'bli', 'blo', 'bla'], expected: true },\n { items: ['blu', 'bli', 'blo', { value: 'bla' }], expected: false },\n ])('Should test if all otems are string: %s', ({ items, expected }) => {\n expect(allItemsAreString(items as string[])).toEqual(expected);\n });\n });\n\n describe('isTagName', () => {\n test.each([\n { querySelector: 'h1', expected: true },\n { querySelector: 'span', expected: false },\n { querySelector: 'blu', expected: false },\n ])('Should test if all otems are string: %s', ({ querySelector, expected }) => {\n const div = document.createElement('div');\n div.innerHTML = '<h1></h1><span></span>';\n const elm = div.querySelector(querySelector);\n expect(isTagName(elm as HTMLElement, ['h1'])).toEqual(expected);\n });\n });\n\n describe('getWindows', () => {\n const mockWindowFramesLength = jest.fn();\n const mockWindowIndexZero = jest.fn();\n Object.defineProperty(window, 'frames', {\n value: {\n get length() {\n return mockWindowFramesLength();\n },\n get 0() {\n return mockWindowIndexZero();\n },\n },\n });\n\n afterEach(() => {\n jest.clearAllMocks();\n });\n\n test('Should return the window in an array', () => {\n mockWindowFramesLength.mockReturnValue(0);\n const localWindow: Window = window;\n const windows: Window[] = getWindows(localWindow);\n expect(windows).toHaveLength(1);\n expect(windows[0]).toEqual(localWindow);\n });\n\n test('Should return the window with a parent', () => {\n mockWindowFramesLength.mockReturnValue(0);\n const spyWindowSelf = jest.spyOn(window, 'self', 'get').mockImplementationOnce(jest.fn());\n const spyWindowParent = jest.spyOn(window, 'parent', 'get').mockImplementationOnce(() => window);\n\n const windows = getWindows(window);\n expect(windows).toHaveLength(2);\n expect(spyWindowSelf).toBeCalledTimes(2);\n expect(spyWindowParent).toBeCalledTimes(1);\n });\n\n test('Should return the window with a child', () => {\n mockWindowFramesLength.mockReturnValueOnce(1).mockReturnValueOnce(1).mockReturnValue(0);\n mockWindowIndexZero.mockReturnValueOnce(window);\n const windows = getWindows(window);\n expect(windows).toHaveLength(2);\n });\n\n test('Should throw an error when cannot access top parent window', () => {\n mockWindowFramesLength.mockReturnValue(0);\n const spyConsole = jest.spyOn(console, 'error');\n const spyWindowSelf = jest.spyOn(window, 'self', 'get').mockImplementationOnce(jest.fn());\n const spyWindowParent = jest.spyOn(window, 'parent', 'get').mockImplementationOnce(() => {\n throw new Error('non');\n });\n const localWindow: Window = window;\n const windows: Window[] = getWindows(localWindow);\n expect(windows).toHaveLength(1);\n expect(windows[0]).toEqual(localWindow);\n expect(spyConsole).toBeCalledTimes(1);\n expect(spyWindowSelf).toBeCalledTimes(1);\n expect(spyWindowParent).toBeCalledTimes(1);\n });\n });\n\n describe('isValidString', () => {\n test.each(['', ' ', null, undefined, 1, {}, []])('Should return \"false\" for invalid values', value => {\n expect(isValidString(value)).toEqual(false);\n });\n\n test.each(['batman', 'batman '])('Should return \"true\" for valid value', value => {\n expect(isValidString(value)).toEqual(true);\n });\n });\n\n describe('cleanString', () => {\n test.each([\n { string: 'batman', expected: 'batman' },\n { string: 'BATMAN', expected: 'batman' },\n { string: 'Batman', expected: 'batman' },\n { string: ' batman ', expected: ' batman ' },\n { string: ' batman', expected: ' batman' },\n { string: 'batman ', expected: 'batman ' },\n { string: 'âäàçéèêñù', expected: 'aaaceeenu' },\n ])('Should format string properly', ({ string, expected }) => {\n expect(cleanString(string)).toEqual(expected);\n });\n });\n\n describe('nextTick', () => {\n test('Should wrapp and execute a callback in a promise', async () => {\n const fn = jest.fn();\n const job = nextTick(fn);\n expect(job.then).toBeDefined();\n\n const res = await job;\n expect(fn).toHaveBeenCalled();\n expect(res).toBeUndefined();\n });\n });\n});\n"]}
@@ -1,46 +0,0 @@
1
- /**
2
- * Add a darker background
3
- * usefull for light rendered element
4
- * @param condition - condition to add darker background
5
- * @param html - html to update
6
- * @returns html to render
7
- */
8
- export const darkBackground = (condition, html) => `${condition ? '<span style="background:#999;display:inline-block;">' : ''}${html}${condition ? '</span>' : ''}`;
9
- /**
10
- * Render attributes from props objects
11
- * @param args - argument to render as string. ex: `{status: 'visible'}`
12
- * @returns formated inline attributed. ex: 'status="visible"'
13
- */
14
- export const renderAttributes = (args) => (typeof args === 'object' &&
15
- Object.keys(args)
16
- .filter(key => ![null, undefined, false].includes(args[key]) && typeof args[key] !== 'object')
17
- .map(key => `${key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()}="${args[key]}"`)
18
- .join(' ')) ||
19
- '';
20
- /**
21
- * Render properties from props objects.
22
- * Insert return value in <script></script> element
23
- * @param args - argument to render as script. ex: `{status: 'visible'}`
24
- * @param selector - querySelector get targetted element and bind properties on it
25
- * @returns stringified properties script
26
- */
27
- export const renderProperties = (args, selector) => {
28
- // has generated id selector starting with "#" create charcters (ex: '#0j3xzw4w7m') make test crashed sometime with "querySelector"
29
- // we use "getElementById" document query
30
- const query = selector.startsWith('#') ? 'getElementById' : 'querySelector';
31
- if (query === 'getElementById')
32
- selector = selector.replace('#', '');
33
- return typeof args === 'object'
34
- ? `
35
- ${Object.keys(args)
36
- .filter(key => typeof args[key] === 'object')
37
- .map(key => `document.${query}('${selector}').${key}=${JSON.stringify(args[key], (_key, val) => (typeof val === 'function' ? `<fn>${val}</fn>` : val))}`) // stringify json AND keep function values
38
- .join(';\n') // create string
39
- .split('"<fn>') // remove fn start decorator
40
- .join('')
41
- .split('</fn>"')
42
- .join('') // remove fn end decorator
43
- }`
44
- : '';
45
- };
46
- //# sourceMappingURL=e2e.test.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"e2e.test.utils.js","sourceRoot":"","sources":["../../src/utils/e2e.test.utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAkB,EAAE,IAAY,EAAU,EAAE,CACzE,GAAG,SAAS,CAAC,CAAC,CAAC,sDAAsD,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAEnH;;;;GAIG;AACH,MAAM,CAAC,MAA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AE,EAAE,CAAC,CAAC,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,0CAA0C;aACnM,IAAI,CAAC,KAAK,CAAC,CAAC,gBAAgB;aAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,4BAA4B;aAC3C,IAAI,CAAC,EAAE,CAAC;aACR,KAAK,CAAC,QAAQ,CAAC;aACf,IAAI,CAAC,EAAE,CAAC,CAAC,0BAA0B;QACxC,EAAE;QACA,CAAC,CAAC,EAAE,CAAC;AACT,CAAC,CAAC","sourcesContent":["/**\n * Add a darker background\n * usefull for light rendered element\n * @param condition - condition to add darker background\n * @param html - html to update\n * @returns html to render\n */\nexport const darkBackground = (condition: boolean, html: string): string =>\n `${condition ? '<span style=\"background:#999;display:inline-block;\">' : ''}${html}${condition ? '</span>' : ''}`;\n\n/**\n * Render attributes from props objects\n * @param args - argument to render as string. ex: `{status: 'visible'}`\n * @returns formated inline attributed. ex: 'status=\"visible\"'\n */\nexport const renderAttributes = (args: unknown): string =>\n (typeof args === 'object' &&\n Object.keys(args)\n .filter(key => ![null, undefined, false].includes(args[key]) && typeof args[key] !== 'object')\n .map(key => `${key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()}=\"${args[key]}\"`)\n .join(' ')) ||\n '';\n\n/**\n * Render properties from props objects.\n * Insert return value in <script></script> element\n * @param args - argument to render as script. ex: `{status: 'visible'}`\n * @param selector - querySelector get targetted element and bind properties on it\n * @returns stringified properties script\n */\nexport const renderProperties = (args: unknown, selector: string): string => {\n // has generated id selector starting with \"#\" create charcters (ex: '#0j3xzw4w7m') make test crashed sometime with \"querySelector\"\n // we use \"getElementById\" document query\n const query: 'querySelector' | 'getElementById' = selector.startsWith('#') ? 'getElementById' : 'querySelector';\n if (query === 'getElementById') selector = selector.replace('#', '');\n\n return typeof args === 'object'\n ? `\n ${\n Object.keys(args)\n .filter(key => typeof args[key] === 'object')\n .map(key => `document.${query}('${selector}').${key}=${JSON.stringify(args[key], (_key, val) => (typeof val === 'function' ? `<fn>${val}</fn>` : val))}`) // stringify json AND keep function values\n .join(';\\n') // create string\n .split('\"<fn>') // remove fn start decorator\n .join('')\n .split('</fn>\"')\n .join('') // remove fn end decorator\n }`\n : '';\n};\n"]}
@@ -1,57 +0,0 @@
1
- /**
2
- * Format number to the locale currency
3
- * @param number - number to format
4
- * @param locale - locale to apply
5
- * @param currency - currency to apply
6
- * @returns formatted currency
7
- */
8
- export const localeCurrency = (number, locale, currency) => {
9
- return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
10
- };
11
- /**
12
- * Format number to locale
13
- * @param number - number to format
14
- * @param locale - locale to apply
15
- * @returns formatted number
16
- */
17
- export const localeNumber = (number, locale) => {
18
- return new Intl.NumberFormat(locale).format(number);
19
- };
20
- /**
21
- * Date RegExp
22
- */
23
- export const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
24
- /**
25
- * Locale date format
26
- * @param date - date to format
27
- * @param locale - locale to apply
28
- * @returns formatted date
29
- */
30
- export const localeDate = (date, locale) => {
31
- if (typeof date !== 'string' || date === '' || !dateRegExp.test(date)) {
32
- return '';
33
- }
34
- return new Intl.DateTimeFormat(locale).format(new Date(date));
35
- };
36
- /**
37
- * Get locale and messages
38
- * We load the defined locale but for now we only support the first subtag for messages
39
- * @param element - element we need to get the language
40
- * @param messages - messages to use
41
- * @param defaultLocale - default messages locale
42
- * @returns messages object
43
- */
44
- export const getLocaleMessages = (element, messages, defaultLocale) => {
45
- // Get local
46
- const closestLangAttribute = element.closest('[lang]');
47
- const closestLang = Intl.NumberFormat.supportedLocalesOf(closestLangAttribute === null || closestLangAttribute === void 0 ? void 0 : closestLangAttribute.lang);
48
- const locale = closestLang.length > 0 ? closestLang[0] : navigator.language || defaultLocale;
49
- // Only keep first subtag
50
- const localeSubtag = locale.split('-').shift();
51
- // Return
52
- return {
53
- locale,
54
- messages: messages[localeSubtag] || messages[defaultLocale],
55
- };
56
- };
57
- //# sourceMappingURL=locale.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"locale.utils.js","sourceRoot":"","sources":["../../src/utils/locale.utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,QAAgB,EAAU,EAAE;IACzF,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACvF,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,MAAc,EAAU,EAAE;IACrE,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,+CAA+C,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,MAAc,EAAU,EAAE;IACjE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACrE,OAAO,EAAE,CAAC;KACX;IACD,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAAoB,EAAE,QAAiB,EAAE,aAAqB,EAAyD,EAAE;IACzJ,YAAY;IACZ,MAAM,oBAAoB,GAAgB,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpE,MAAM,WAAW,GAAa,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,IAAI,CAAC,CAAC;IAC/F,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,IAAI,aAAa,CAAC;IAC7F,yBAAyB;IACzB,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IAC/C,SAAS;IACT,OAAO;QACL,MAAM;QACN,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC,aAAa,CAAC;KAC5D,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * Format number to the locale currency\n * @param number - number to format\n * @param locale - locale to apply\n * @param currency - currency to apply\n * @returns formatted currency\n */\nexport const localeCurrency = (number: number, locale: string, currency: string): string => {\n return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);\n};\n\n/**\n * Format number to locale\n * @param number - number to format\n * @param locale - locale to apply\n * @returns formatted number\n */\nexport const localeNumber = (number: number, locale: string): string => {\n return new Intl.NumberFormat(locale).format(number);\n};\n\n/**\n * Date RegExp\n */\nexport const dateRegExp = /^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$/;\n\n/**\n * Locale date format\n * @param date - date to format\n * @param locale - locale to apply\n * @returns formatted date\n */\nexport const localeDate = (date: string, locale: string): string => {\n if (typeof date !== 'string' || date === '' || !dateRegExp.test(date)) {\n return '';\n }\n return new Intl.DateTimeFormat(locale).format(new Date(date));\n};\n\n/**\n * Get locale and messages\n * We load the defined locale but for now we only support the first subtag for messages\n * @param element - element we need to get the language\n * @param messages - messages to use\n * @param defaultLocale - default messages locale\n * @returns messages object\n */\nexport const getLocaleMessages = (element: HTMLElement, messages: unknown, defaultLocale: string): { locale: string; messages: Record<string, unknown> } => {\n // Get local\n const closestLangAttribute: HTMLElement = element.closest('[lang]');\n const closestLang: string[] = Intl.NumberFormat.supportedLocalesOf(closestLangAttribute?.lang);\n const locale = closestLang.length > 0 ? closestLang[0] : navigator.language || defaultLocale;\n // Only keep first subtag\n const localeSubtag = locale.split('-').shift();\n // Return\n return {\n locale,\n messages: messages[localeSubtag] || messages[defaultLocale],\n };\n};\n"]}
@@ -1,52 +0,0 @@
1
- import { localeCurrency, localeNumber, localeDate, getLocaleMessages } from "./locale.utils";
2
- import messagesEn from "../locales/en/messages.json";
3
- import messagesFr from "../locales/fr/messages.json";
4
- describe('locale.utils', () => {
5
- describe.each(['en', 'fr'])('locale.utils: %s', locale => {
6
- describe('localeCurrency', () => {
7
- test('Should Format number to the locale currency', () => {
8
- const formatedCurrency = localeCurrency(1234567890.12, locale, 'EUR');
9
- expect(formatedCurrency).toEqual(locale === 'en' ? '€1,234,567,890.12' : '1 234 567 890,12\xa0€');
10
- });
11
- });
12
- describe('localeNumber', () => {
13
- test('Should Format number to the locale', () => {
14
- const formatedCurrency = localeNumber(1234567890.12, locale);
15
- expect(formatedCurrency).toEqual(locale === 'en' ? '1,234,567,890.12' : '1 234 567 890,12');
16
- });
17
- });
18
- describe('localeDate', () => {
19
- test.each([undefined, '', 'blu'])('Should return empty string: %s', date => {
20
- const formatedDate = localeDate(date, locale);
21
- expect(formatedDate).toEqual('');
22
- });
23
- test('Should return formated date', () => {
24
- const formatedDate = localeDate('2022-06-02', locale);
25
- expect(formatedDate).toEqual(locale === 'en' ? '6/2/2022' : '02/06/2022');
26
- });
27
- });
28
- describe('getLocaleMessages', () => {
29
- const messages = { en: messagesEn, fr: messagesFr };
30
- test('Should return default locale', () => {
31
- const locales = getLocaleMessages(document.createElement('div'), messages, 'en');
32
- expect(locales.locale).toEqual('en');
33
- expect(locales.messages).toMatchObject(messagesEn);
34
- });
35
- test('Should return matching locale', () => {
36
- const div = document.createElement('div');
37
- div.lang = 'fr-FR';
38
- const locales = getLocaleMessages(div, messages, 'en');
39
- expect(locales.locale).toEqual(div.lang);
40
- expect(locales.messages).toMatchObject(messagesFr);
41
- });
42
- test('Should return default locale messages when requested does not exist', () => {
43
- const div = document.createElement('div');
44
- div.lang = 'ca';
45
- const locales = getLocaleMessages(div, messages, 'en');
46
- expect(locales.locale).toEqual(div.lang);
47
- expect(locales.messages).toMatchObject(messagesEn);
48
- });
49
- });
50
- });
51
- });
52
- //# sourceMappingURL=locale.utils.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"locale.utils.spec.js","sourceRoot":"","sources":["../../src/utils/locale.utils.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,UAAU,MAAM,6BAA6B,CAAC;AAErD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,kBAAkB,EAAE,MAAM,CAAC,EAAE;QACvD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;YAC9B,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAAE;gBACvD,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;gBACtE,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC;YACpG,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;YAC5B,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;gBAC9C,MAAM,gBAAgB,GAAG,YA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,QAAQ,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,+BAA+B,EAAE,GAAG,EAAE;gBACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAC1C,GAAG,CAAC,IAAI,GAAG,OAAO,CAAC;gBACnB,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACvD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACzC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,qEAAqE,EAAE,GAAG,EAAE;gBAC/E,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;gBAC1C,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;gBAChB,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;gBACvD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBACzC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YACrD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { localeCurrency, localeNumber, localeDate, getLocaleMessages } from './locale.utils';\nimport messagesEn from '../locales/en/messages.json';\nimport messagesFr from '../locales/fr/messages.json';\n\ndescribe('locale.utils', () => {\n describe.each(['en', 'fr'])('locale.utils: %s', locale => {\n describe('localeCurrency', () => {\n test('Should Format number to the locale currency', () => {\n const formatedCurrency = localeCurrency(1234567890.12, locale, 'EUR');\n expect(formatedCurrency).toEqual(locale === 'en' ? '€1,234,567,890.12' : '1 234 567 890,12\\xa0€');\n });\n });\n\n describe('localeNumber', () => {\n test('Should Format number to the locale', () => {\n const formatedCurrency = localeNumber(1234567890.12, locale);\n expect(formatedCurrency).toEqual(locale === 'en' ? '1,234,567,890.12' : '1 234 567 890,12');\n });\n });\n\n describe('localeDate', () => {\n test.each([undefined, '', 'blu'])('Should return empty string: %s', date => {\n const formatedDate = localeDate(date, locale);\n expect(formatedDate).toEqual('');\n });\n\n test('Should return formated date', () => {\n const formatedDate = localeDate('2022-06-02', locale);\n expect(formatedDate).toEqual(locale === 'en' ? '6/2/2022' : '02/06/2022');\n });\n });\n\n describe('getLocaleMessages', () => {\n const messages = { en: messagesEn, fr: messagesFr };\n test('Should return default locale', () => {\n const locales = getLocaleMessages(document.createElement('div'), messages, 'en');\n expect(locales.locale).toEqual('en');\n expect(locales.messages).toMatchObject(messagesEn);\n });\n\n test('Should return matching locale', () => {\n const div = document.createElement('div');\n div.lang = 'fr-FR';\n const locales = getLocaleMessages(div, messages, 'en');\n expect(locales.locale).toEqual(div.lang);\n expect(locales.messages).toMatchObject(messagesFr);\n });\n\n test('Should return default locale messages when requested does not exist', () => {\n const div = document.createElement('div');\n div.lang = 'ca';\n const locales = getLocaleMessages(div, messages, 'en');\n expect(locales.locale).toEqual(div.lang);\n expect(locales.messages).toMatchObject(messagesEn);\n });\n });\n });\n});\n"]}