@mgdis/mg-components 6.20.0 → 6.22.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 (205) hide show
  1. package/dist/cjs/{index-TUElr4Wv.js → index-BxB20_Vw.js} +54 -0
  2. package/dist/cjs/{index-Bp6wZzau.js → index-C2viYwrR.js} +1761 -80
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/mg-action-more_37.cjs.entry.js +761 -371
  5. package/dist/cjs/mg-alert.cjs.entry.js +17 -9
  6. package/dist/cjs/mg-breadcrumb.cjs.entry.js +63 -0
  7. package/dist/cjs/mg-components.cjs.js +3 -3
  8. package/dist/cjs/mg-fieldset.cjs.entry.js +24 -7
  9. package/dist/cjs/mg-input-combobox.cjs.entry.js +49 -19
  10. package/dist/cjs/mg-input-file.cjs.entry.js +384 -0
  11. package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js +40096 -15821
  12. package/dist/cjs/{mg-input.conf-D7jmj_lh.js → mg-input.conf-BNpeATnq.js} +7 -0
  13. package/dist/cjs/mg-loader.cjs.entry.js +8 -6
  14. package/dist/cjs/mg-progress.cjs.entry.js +19 -9
  15. package/dist/collection/assets/icons/index.js +1 -1
  16. package/dist/collection/collection-manifest.json +5 -3
  17. package/dist/collection/components/atoms/internals/mg-character-left/mg-character-left.js +1 -1
  18. package/dist/collection/components/atoms/internals/mg-input-title/mg-input-title.js +1 -1
  19. package/dist/collection/components/atoms/mg-card/mg-card.js +1 -1
  20. package/dist/collection/components/atoms/mg-divider/mg-divider.js +1 -1
  21. package/dist/collection/components/atoms/mg-icon/mg-icon.js +2 -2
  22. package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -1
  23. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip-content/mg-tooltip-content.js +1 -1
  24. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +1 -1
  25. package/dist/collection/components/molecules/inputs/mg-input/mg-input.conf.js +6 -0
  26. package/dist/collection/components/molecules/inputs/mg-input/mg-input.js +1 -1
  27. package/dist/collection/components/molecules/inputs/mg-input-checkbox/MgInputCheckboxList.js +2 -2
  28. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js +2 -2
  29. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +1 -1
  30. package/dist/collection/components/molecules/inputs/mg-input-combobox/mg-input-combobox.js +1 -1
  31. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +1 -1
  32. package/dist/collection/components/molecules/inputs/mg-input-file/mg-input-file.js +877 -0
  33. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +1 -1
  34. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +2 -2
  35. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
  36. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/custom-properties.scss +212 -0
  37. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/editor.conf.js +1 -0
  38. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/index.js +300 -94
  39. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.conf.js +29 -0
  40. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js +163 -53
  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-text/mg-input-text.js +2 -2
  43. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
  44. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
  45. package/dist/collection/components/molecules/internals/mg-item-more/mg-item-more.js +3 -36
  46. package/dist/collection/components/molecules/menus/mg-menu/mg-menu.conf.js +0 -4
  47. package/dist/collection/components/molecules/menus/mg-menu/mg-menu.js +21 -43
  48. package/dist/collection/components/molecules/menus/mg-menu-item/mg-menu-item.js +65 -38
  49. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +2 -2
  50. package/dist/collection/components/molecules/mg-alert/mg-alert.js +1 -1
  51. package/dist/collection/components/molecules/mg-breadcrumb/mg-breadcrumb.conf.js +1 -0
  52. package/dist/collection/components/molecules/mg-breadcrumb/mg-breadcrumb.js +92 -0
  53. package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
  54. package/dist/collection/components/molecules/mg-fieldset/mg-fieldset.js +12 -3
  55. package/dist/collection/components/molecules/mg-form/mg-form.js +12 -2
  56. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -1
  57. package/dist/collection/components/molecules/mg-loader/mg-loader.js +1 -1
  58. package/dist/collection/components/molecules/mg-message/mg-message.js +2 -2
  59. package/dist/collection/components/molecules/mg-modal/mg-modal.js +2 -2
  60. package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
  61. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
  62. package/dist/collection/components/molecules/mg-popover/mg-popover.js +1 -1
  63. package/dist/collection/components/molecules/mg-progress/mg-progress.js +1 -1
  64. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
  65. package/dist/collection/components/molecules/mg-table/mg-table.js +37 -0
  66. package/dist/collection/components/molecules/mg-tabs/mg-tabs.conf.js +0 -4
  67. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +13 -33
  68. package/dist/collection/locales/en/messages.json +14 -0
  69. package/dist/collection/locales/fr/messages.json +14 -0
  70. package/dist/components/events.utils.js +1 -23
  71. package/dist/components/index.d.ts +2 -0
  72. package/dist/components/index.js +1 -1
  73. package/dist/components/index2.js +1 -408
  74. package/dist/components/index3.js +1 -476
  75. package/dist/components/mg-action-more.js +1 -254
  76. package/dist/components/mg-alert.js +1 -224
  77. package/dist/components/mg-badge.js +1 -6
  78. package/dist/components/mg-badge2.js +1 -113
  79. package/dist/components/mg-breadcrumb.d.ts +11 -0
  80. package/dist/components/mg-breadcrumb.js +1 -0
  81. package/dist/components/mg-button.js +1 -6
  82. package/dist/components/mg-button2.js +1 -275
  83. package/dist/components/mg-card.js +1 -6
  84. package/dist/components/mg-card2.js +1 -92
  85. package/dist/components/mg-character-left.js +1 -6
  86. package/dist/components/mg-character-left2.js +1 -75
  87. package/dist/components/mg-details.js +1 -104
  88. package/dist/components/mg-divider.js +1 -6
  89. package/dist/components/mg-divider2.js +1 -49
  90. package/dist/components/mg-fieldset.js +1 -209
  91. package/dist/components/mg-form.js +1 -302
  92. package/dist/components/mg-icon.js +1 -6
  93. package/dist/components/mg-icon2.js +1 -188
  94. package/dist/components/mg-illustrated-message.js +1 -129
  95. package/dist/components/mg-input-checkbox-paginated.js +1 -6
  96. package/dist/components/mg-input-checkbox-paginated2.js +1 -135
  97. package/dist/components/mg-input-checkbox.js +1 -762
  98. package/dist/components/mg-input-combobox.js +1 -940
  99. package/dist/components/mg-input-date.js +1 -463
  100. package/dist/components/mg-input-file.d.ts +11 -0
  101. package/dist/components/mg-input-file.js +1 -0
  102. package/dist/components/mg-input-numeric.js +1 -592
  103. package/dist/components/mg-input-password.js +1 -360
  104. package/dist/components/mg-input-radio.js +1 -392
  105. package/dist/components/mg-input-rich-text-editor.js +1663 -16797
  106. package/dist/components/mg-input-select.js +1 -6
  107. package/dist/components/mg-input-select2.js +1 -481
  108. package/dist/components/mg-input-text.js +1 -6
  109. package/dist/components/mg-input-text2.js +1 -514
  110. package/dist/components/mg-input-textarea.js +1 -412
  111. package/dist/components/mg-input-title.js +1 -6
  112. package/dist/components/mg-input-title2.js +1 -81
  113. package/dist/components/mg-input-toggle.js +1 -371
  114. package/dist/components/mg-input.conf.js +1 -0
  115. package/dist/components/mg-input.js +1 -6
  116. package/dist/components/mg-input2.js +1 -459
  117. package/dist/components/mg-item-more.js +1 -6
  118. package/dist/components/mg-item-more2.js +1 -505
  119. package/dist/components/mg-loader.js +1 -6
  120. package/dist/components/mg-loader2.js +1 -74
  121. package/dist/components/mg-menu-item.js +1 -6
  122. package/dist/components/mg-menu-item2.js +1 -485
  123. package/dist/components/mg-menu.js +1 -6
  124. package/dist/components/mg-message.js +1 -6
  125. package/dist/components/mg-message2.js +1 -146
  126. package/dist/components/mg-modal.js +1 -184
  127. package/dist/components/mg-pagination.js +1 -234
  128. package/dist/components/mg-panel.js +1 -350
  129. package/dist/components/mg-popover-content.js +1 -6
  130. package/dist/components/mg-popover-content2.js +1 -96
  131. package/dist/components/mg-popover.js +1 -6
  132. package/dist/components/mg-popover2.js +1 -312
  133. package/dist/components/mg-progress.js +1 -123
  134. package/dist/components/mg-skip-links.js +1 -78
  135. package/dist/components/mg-table.js +1 -319
  136. package/dist/components/mg-tabs.js +1 -6
  137. package/dist/components/mg-tabs2.js +1 -315
  138. package/dist/components/mg-tag.js +1 -133
  139. package/dist/components/mg-tooltip-content.js +1 -6
  140. package/dist/components/mg-tooltip-content2.js +1 -42
  141. package/dist/components/mg-tooltip.js +1 -6
  142. package/dist/components/mg-tooltip2.js +1 -421
  143. package/dist/components/popper.js +1 -1790
  144. package/dist/esm/{index-BluNKQ3L.js → index-DFwaH2hS.js} +1761 -80
  145. package/dist/esm/{index-CNX6lq0x.js → index-DSEloqPn.js} +54 -1
  146. package/dist/esm/loader.js +3 -3
  147. package/dist/esm/mg-action-more_37.entry.js +761 -371
  148. package/dist/esm/mg-alert.entry.js +17 -9
  149. package/dist/esm/mg-breadcrumb.entry.js +61 -0
  150. package/dist/esm/mg-components.js +4 -4
  151. package/dist/esm/mg-fieldset.entry.js +24 -7
  152. package/dist/esm/mg-input-combobox.entry.js +49 -19
  153. package/dist/esm/mg-input-file.entry.js +382 -0
  154. package/dist/esm/mg-input-rich-text-editor.entry.js +40083 -15808
  155. package/dist/esm/{mg-input.conf-DDnrE1hD.js → mg-input.conf-C9rmNQIL.js} +7 -1
  156. package/dist/esm/mg-loader.entry.js +8 -6
  157. package/dist/esm/mg-progress.entry.js +19 -9
  158. package/dist/mg-components/locales/en/messages.json +14 -0
  159. package/dist/mg-components/locales/fr/messages.json +14 -0
  160. package/dist/mg-components/mg-components.esm.js +1 -1
  161. package/dist/mg-components/p-0482eb9f.entry.js +1 -0
  162. package/dist/mg-components/{p-7132bca1.entry.js → p-2ee92f38.entry.js} +1 -1
  163. package/dist/mg-components/{p-916dfb6d.entry.js → p-3b653226.entry.js} +1 -1
  164. package/dist/mg-components/p-5745fbea.entry.js +1 -0
  165. package/dist/mg-components/p-C9rmNQIL.js +1 -0
  166. package/dist/mg-components/p-DFwaH2hS.js +2 -0
  167. package/dist/mg-components/p-DSEloqPn.js +1 -0
  168. package/dist/mg-components/p-adec7fcc.entry.js +1 -0
  169. package/dist/mg-components/p-c63f97f0.entry.js +1658 -0
  170. package/dist/mg-components/p-c8c8cfc1.entry.js +1 -0
  171. package/dist/mg-components/p-cc793586.entry.js +1 -0
  172. package/dist/mg-components/p-d5e69c95.entry.js +1 -0
  173. package/dist/types/assets/icons/index.d.ts +2 -0
  174. package/dist/types/components/molecules/inputs/mg-input/mg-input.conf.d.ts +7 -1
  175. package/dist/types/components/molecules/inputs/mg-input-file/mg-input-file.d.ts +210 -0
  176. package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/editor/editor.conf.d.ts +17 -0
  177. package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/editor/index.d.ts +27 -19
  178. package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.conf.d.ts +3 -0
  179. package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.d.ts +50 -16
  180. package/dist/types/components/molecules/internals/mg-item-more/mg-item-more.conf.d.ts +0 -5
  181. package/dist/types/components/molecules/internals/mg-item-more/mg-item-more.d.ts +1 -6
  182. package/dist/types/components/molecules/menus/mg-menu/mg-menu.conf.d.ts +2 -10
  183. package/dist/types/components/molecules/menus/mg-menu/mg-menu.d.ts +7 -7
  184. package/dist/types/components/molecules/menus/mg-menu-item/mg-menu-item.d.ts +12 -8
  185. package/dist/types/components/molecules/mg-breadcrumb/mg-breadcrumb.conf.d.ts +18 -0
  186. package/dist/types/components/molecules/mg-breadcrumb/mg-breadcrumb.d.ts +34 -0
  187. package/dist/types/components/molecules/mg-table/mg-table.d.ts +6 -0
  188. package/dist/types/components/molecules/mg-tabs/mg-tabs.conf.d.ts +1 -9
  189. package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +4 -4
  190. package/dist/types/components.d.ts +302 -46
  191. package/dist/types/stencil-public-runtime.d.ts +76 -12
  192. package/ide/intellij/web-types.json +483 -51
  193. package/ide/vscode/css-custom-data.json +10 -2
  194. package/ide/vscode/html-custom-data.json +445 -104
  195. package/package.json +24 -23
  196. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/editor.scss +0 -1
  197. package/dist/mg-components/p-016bd291.entry.js +0 -1
  198. package/dist/mg-components/p-186a6139.entry.js +0 -1
  199. package/dist/mg-components/p-BluNKQ3L.js +0 -2
  200. package/dist/mg-components/p-CNX6lq0x.js +0 -1
  201. package/dist/mg-components/p-DDnrE1hD.js +0 -1
  202. package/dist/mg-components/p-cd061b38.entry.js +0 -1
  203. package/dist/mg-components/p-d2c72f09.entry.js +0 -1
  204. package/dist/mg-components/p-d5a276eb.entry.js +0 -1
  205. package/ide/vscode/custom.css-data.json +0 -425
@@ -1,408 +1 @@
1
- /**
2
- * Class to manage component classlist
3
- */
4
- class ClassList {
5
- /**
6
- * Available classes
7
- */
8
- classes;
9
- constructor(classlist = []) {
10
- this.classes = classlist;
11
- }
12
- /**
13
- * Add class
14
- * @param className - class name to add
15
- */
16
- add = (className) => {
17
- if (!this.has(className)) {
18
- this.classes.push(className);
19
- }
20
- };
21
- /**
22
- * Delete class
23
- * @param className - class name to delete
24
- */
25
- delete = (className) => {
26
- const index = this.classes.indexOf(className);
27
- if (index > -1) {
28
- this.classes.splice(index, 1);
29
- }
30
- };
31
- /**
32
- * Check if class exist in list
33
- * @param className - class name to check
34
- * @returns class name is in the list
35
- */
36
- has = (className) => {
37
- return this.classes.includes(className);
38
- };
39
- /**
40
- * Join classes seperated by spaces
41
- * @returns joined values
42
- */
43
- join = () => {
44
- return this.classes.join(' ');
45
- };
46
- }
47
-
48
- /**
49
- * Check if a value is of object type.
50
- * @param object - The value to validate.
51
- * @returns `true` if the value is a valid object (non-null and not an array), otherwise `false`.
52
- */
53
- const isObject = (object) => typeof object === 'object' && !Array.isArray(object) && object !== null;
54
- /**
55
- * Get object value from key
56
- * @param object - object to query
57
- * @param path - path of the property to get. Nested keys are allowed with `.` separators (eg: 'key0.key1.key2' = object[key0][key1][key2])
58
- * @param defaultValue - The value returned for `undefined` resolved values
59
- * @returns object value
60
- */
61
- const getObjectValueFromKey = (object, path, defaultValue) => {
62
- const separator = '.';
63
- if (!isObject(object) || typeof path !== 'string') {
64
- return defaultValue;
65
- }
66
- const [current, ...next] = path.split(separator);
67
- if (next.length) {
68
- return getObjectValueFromKey(object[current], next.join(separator), defaultValue);
69
- }
70
- else {
71
- return object[current] ?? defaultValue;
72
- }
73
- };
74
-
75
- /**
76
- * Typeguard function to check if all array items are strings.
77
- * @param items - items to check
78
- * @returns `true` if all items are strings
79
- */
80
- const allItemsAreString = (items) => Array.isArray(items) && items.every(item => typeof item === 'string');
81
- /**
82
- * Validate string
83
- * @param value - value to check
84
- * @returns `true` if string is valid
85
- */
86
- const isValidString = (value) => typeof value === 'string' && value.trim() !== '';
87
- /**
88
- * Stringify value
89
- * @param value - value to stringify
90
- * @returns stringified value
91
- */
92
- const toString = (value) => (typeof value === 'object' ? JSON.stringify(value) : String(value));
93
- /**
94
- * Cleans string characters by removing special characters and converting to lowercase.
95
- * @param text - text to clean
96
- * @returns cleaned string
97
- * @example
98
- * ```ts
99
- * cleanString('âäàçéèêñù') // 'aaaceeenu'
100
- * cleanString('BATMAN') // 'batman'
101
- * ```
102
- */
103
- const cleanString = (text) => typeof text === 'string'
104
- ? text
105
- .toLocaleLowerCase()
106
- .normalize('NFD')
107
- .replaceAll(/[\u0300-\u036f]/g, '')
108
- : text;
109
-
110
- /**
111
- * Convert a string to kebab-case.
112
- *
113
- * This function ensures:
114
- * - All characters are converted to lowercase. Based on : https://stackoverflow.com/questions/63116039/camelcase-to-kebab-case
115
- * - Non-alphabetic characters (except numbers and hyphens) are replaced with hyphens.
116
- * - Consecutive hyphens are replaced with a single hyphen.
117
- * - Leading and trailing hyphens are removed.
118
- *
119
- * @param str - The input string to convert.
120
- * @returns The kebab-case formatted string.
121
- *
122
- * @example
123
- * ```typescript
124
- * toKebabCase('XMLHttpRequest'); // 'xml-http-request'
125
- * ```
126
- */
127
- const toKebabCase = (str) => str
128
- .replace(/[A-Z]+(?![a-z])|[A-Z]/g, (match, offset) => (offset > 0 ? '-' : '') + match.toLowerCase())
129
- .replace(/[^a-z0-9-]+/g, '-') // Replace non a-z, 0-9, or hyphen characters with a hyphen
130
- .replace(/--+/g, '-') // Replace multiple consecutive hyphens with a single hyphen
131
- .replace(/(?:^-)|(?:-$)/g, ''); // Remove leading hyphens or number or trailing hyphens
132
-
133
- /**
134
- * Create random ID
135
- * @param prefix - add prefix to created ID
136
- * @param length - ID length
137
- * @returns ID
138
- */
139
- const createID = (prefix = '', length = 10) => {
140
- const randomBytes = new Uint8Array(length);
141
- crypto.getRandomValues(randomBytes);
142
- const hexString = Array.from(randomBytes)
143
- .map(byte => byte.toString(16).padStart(2, '0'))
144
- .join('')
145
- .slice(0, length);
146
- return prefix !== '' ? `${prefix}-${hexString}` : hexString;
147
- };
148
- /**
149
- * Validate html `id` format
150
- * @param newValue - id value to validate
151
- * @returns true if `id` is valid
152
- */
153
- const isValideID = (newValue) => isValidString(newValue) && /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.exec(newValue) !== null;
154
- /**
155
- * Format id from value
156
- * @param value - id to transforme
157
- * @returns valid id
158
- */
159
- const formatID = (value) => {
160
- let id;
161
- if (typeof value === 'string') {
162
- id = value;
163
- }
164
- else if (Boolean(value) && typeof value === 'object' && (isObject(value) || Array.isArray(value))) {
165
- id = JSON.stringify(value);
166
- }
167
- else if (value !== null && value !== undefined && typeof value !== 'boolean' && typeof value !== 'object') {
168
- id = String(value);
169
- }
170
- return id ? toKebabCase(id) : id;
171
- };
172
-
173
- /**
174
- * Use to process code next tick in the event loop
175
- * @param callback - code to excute on next tick
176
- * @returns differed code excution
177
- */
178
- const nextTick = async (callback) => {
179
- if (callback)
180
- return callback();
181
- };
182
- /**
183
- * Cursor possible values
184
- */
185
- const Cursor = {
186
- FIRST: 'first',
187
- NEXT: 'next',
188
- PREVIOUS: 'previous',
189
- LAST: 'last',
190
- };
191
- const DEFAULT_TOP = 10;
192
- /**
193
- * Define a valid Page object and navigate throw page items with cursor.
194
- * Page object entries follow the REST API page practices.
195
- */
196
- class Page {
197
- /**
198
- * Define items
199
- */
200
- items = [];
201
- /**
202
- * Define total
203
- */
204
- total;
205
- /**
206
- * Define top
207
- */
208
- top = DEFAULT_TOP;
209
- /**
210
- * Define next
211
- */
212
- next;
213
- /**
214
- * Define base index
215
- */
216
- baseIndex = 1;
217
- constructor(init) {
218
- if (!isObject(init)) {
219
- throw new Error('Page - init must match IPage type.');
220
- }
221
- else {
222
- if (Array.isArray(init.items))
223
- this.items = init.items;
224
- if (typeof init.top === 'number')
225
- this.top = init.top;
226
- this.total = typeof init.total === 'number' ? init.total : this.items.length;
227
- this.next = init.next;
228
- }
229
- }
230
- /**
231
- * Get index of items from cursor
232
- * @param cursor - cursor to find
233
- * @param oldItem - previous item
234
- * @returns item index
235
- */
236
- getIndexFromCursor = (cursor = 'first', oldItem) => {
237
- const startIndex = 0;
238
- if (!Array.isArray(this.items) || !this.items.length)
239
- return null;
240
- const lastIndex = this.items.length - this.baseIndex;
241
- let newIndex;
242
- let oldIndex = startIndex;
243
- if (['previous', 'next'].includes(cursor) && oldItem) {
244
- const findedIndex = this.items.findIndex(item => JSON.stringify(item) === JSON.stringify(oldItem));
245
- if (findedIndex === -1)
246
- return startIndex;
247
- oldIndex = findedIndex;
248
- }
249
- // Update index from cursor
250
- if (cursor === 'first') {
251
- newIndex = startIndex;
252
- }
253
- else if (cursor === 'last') {
254
- newIndex = lastIndex;
255
- }
256
- else if (cursor === 'previous') {
257
- newIndex = JSON.stringify(this.items[oldIndex]) === JSON.stringify(this.items[startIndex]) ? lastIndex : oldIndex - this.baseIndex;
258
- }
259
- else if (cursor === 'next') {
260
- newIndex = JSON.stringify(this.items[oldIndex]) === JSON.stringify(this.items[lastIndex]) ? startIndex : oldIndex + this.baseIndex;
261
- }
262
- else {
263
- newIndex = startIndex;
264
- }
265
- return newIndex;
266
- };
267
- }
268
- /**
269
- * Paginate an items array to navigate into with pages.
270
- * It follow REST standard and allow to navigate in items array with a similar format.
271
- */
272
- class Paginate {
273
- /**
274
- * Define paginated items
275
- */
276
- items = [];
277
- /* Privates */
278
- #top = DEFAULT_TOP;
279
- #next;
280
- #total;
281
- constructor(items, options) {
282
- if (Array.isArray(items))
283
- this.items = items;
284
- if (options && (['string', 'function'].includes(typeof options.next) || (isObject(options.next) && URL.canParse(options.next))))
285
- this.#next = options.next;
286
- if (typeof options?.top === 'number')
287
- this.#top = options.top;
288
- if (typeof options?.total === 'number')
289
- this.#total = options.total;
290
- }
291
- /**
292
- * Get page
293
- * @param offset - pagiantion offset
294
- * @param filter - filter methode
295
- * @returns formated page
296
- */
297
- getPage = (offset = 0, filter) => {
298
- const items = typeof filter === 'function' ? this.items.filter(filter) : this.items;
299
- let next;
300
- if (this.#next)
301
- next = this.#next;
302
- else if (items.length > offset + this.#top)
303
- next = () => this.getPage(offset + this.#top, filter);
304
- return new Page({
305
- items: items.slice(offset, offset + this.#top),
306
- total: this.#total,
307
- top: this.#top,
308
- next,
309
- });
310
- };
311
- }
312
-
313
- /**
314
- * Date RegExp, usefull to test if string is a follow the date pattern
315
- * @example
316
- * ```ts
317
- * dateRegExp.test('mystring') // false
318
- * dateRegExp.test('2020-12-31') // true
319
- * ```
320
- */
321
- const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
322
- /**
323
- * Formats a date object to a string with the pattern 'YYYY-MM-DD'.
324
- * @param date - date to parse
325
- * @returns string date with pattern 'YYYY-MM-DD'
326
- * @example
327
- * ```ts
328
- * dateToString(new Date('2023-12-24')) // '2023-12-24'
329
- * ```
330
- */
331
- const dateToString = (date) => date.toISOString().split('T')[0];
332
-
333
- /**
334
- * Check if element belongs to the given tagNames list
335
- * @param element - element to check
336
- * @param tagNames - allowed tag names list
337
- * @returns `true` if element tagName is in the tagNames list
338
- */
339
- const isTagName = (element, tagNames) => tagNames.includes(element?.tagName.toLowerCase());
340
- /**
341
- * CSS selector to select focusable elements.
342
- * @example
343
- * ```ts
344
- * const allFocusableElements: HTMLElement[] = Array.from(this.element.querySelectorAll(focusableElements));
345
- * ```
346
- */
347
- const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier], mg-button';
348
-
349
- /**
350
- * Validate number
351
- * @param value - value to check
352
- * @returns `true` if number is valid
353
- */
354
- const isValidNumber = (value) => typeof value === 'number' && !Number.isNaN(value);
355
-
356
- /**
357
- * Get windows
358
- * @param localWindow - the window we are lookink for other windows
359
- * @returns The list of windows found
360
- */
361
- const getWindows = (localWindow) => {
362
- const parentWindows = getParentWindows(localWindow);
363
- const childWindows = getChildWindows(localWindow);
364
- return [localWindow, ...parentWindows, ...childWindows];
365
- };
366
- /**
367
- * Get parent windows
368
- * @param localWindow - the window we are lookink for parents
369
- * @param windows - The list of allready found windows
370
- * @returns The list of windows found
371
- */
372
- const getParentWindows = (localWindow, windows = []) => {
373
- // Check if is in iframe
374
- if (localWindow.self !== localWindow.top) {
375
- // Check if we have permission to access parent
376
- try {
377
- const parentWindow = localWindow.parent;
378
- if (parentWindow) {
379
- windows.push(parentWindow);
380
- return getParentWindows(parentWindow, windows);
381
- }
382
- else
383
- return windows;
384
- }
385
- catch (err) {
386
- console.error('Different hosts between iframes:', err);
387
- return windows;
388
- }
389
- }
390
- return windows;
391
- };
392
- /**
393
- * Get child windows
394
- * @param localWindow - the window we are lookink for children
395
- * @param windows - The list of allready found windows
396
- * @returns The list of windows found
397
- */
398
- const getChildWindows = (localWindow, windows = []) => {
399
- if (localWindow.frames.length > 0) {
400
- for (const childWindow of Array.from(localWindow.frames)) {
401
- windows.push(childWindow);
402
- getChildWindows(childWindow, windows);
403
- }
404
- }
405
- return windows;
406
- };
407
-
408
- export { ClassList as C, Paginate as P, isValideID as a, isTagName as b, createID as c, allItemsAreString as d, Cursor as e, formatID as f, getWindows as g, Page as h, isValidString as i, getObjectValueFromKey as j, isObject as k, focusableElements as l, cleanString as m, nextTick as n, dateRegExp as o, dateToString as p, isValidNumber as q, toString as t };
1
+ class t{classes;constructor(t=[]){this.classes=t}add=t=>{this.has(t)||this.classes.push(t)};delete=t=>{const s=this.classes.indexOf(t);s>-1&&this.classes.splice(s,1)};has=t=>this.classes.includes(t);join=()=>this.classes.join(" ")}const s=t=>"object"==typeof t&&!Array.isArray(t)&&null!==t,e=(t,r,i)=>{if(!s(t)||"string"!=typeof r)return i;const[n,...o]=r.split(".");return o.length?e(t[n],o.join("."),i):t[n]??i},r=t=>Array.isArray(t)&&t.every((t=>"string"==typeof t)),i=t=>"string"==typeof t&&""!==t.trim(),n=t=>"object"==typeof t?JSON.stringify(t):String(t),o=t=>"string"==typeof t?t.toLocaleLowerCase().normalize("NFD").replaceAll(/[\u0300-\u036f]/g,""):t,a=(t="",s=10)=>{const e=new Uint8Array(s);crypto.getRandomValues(e);const r=Array.from(e).map((t=>t.toString(16).padStart(2,"0"))).join("").slice(0,s);return""!==t?`${t}-${r}`:r},h=t=>i(t)&&null!==/^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.exec(t),f=t=>{let e;return"string"==typeof t?e=t:Boolean(t)&&"object"==typeof t&&(s(t)||Array.isArray(t))?e=JSON.stringify(t):null!=t&&"boolean"!=typeof t&&"object"!=typeof t&&(e=String(t)),e?e.replace(/[A-Z]+(?![a-z])|[A-Z]/g,((t,s)=>(s>0?"-":"")+t.toLowerCase())).replace(/[^a-z0-9-]+/g,"-").replace(/--+/g,"-").replace(/(?:^-)|(?:-$)/g,""):e},u=async t=>{if(t)return t()},c={FIRST:"first",NEXT:"next",PREVIOUS:"previous",LAST:"last"};class y{items=[];total;top=10;next;baseIndex=1;constructor(t){if(!s(t))throw new Error("Page - init must match IPage type.");Array.isArray(t.items)&&(this.items=t.items),"number"==typeof t.top&&(this.top=t.top),this.total="number"==typeof t.total?t.total:this.items.length,this.next=t.next}getIndexFromCursor=(t="first",s)=>{if(!Array.isArray(this.items)||!this.items.length)return null;const e=this.items.length-this.baseIndex;let r,i=0;if(["previous","next"].includes(t)&&s){const t=this.items.findIndex((t=>JSON.stringify(t)===JSON.stringify(s)));if(-1===t)return 0;i=t}return r="first"===t?0:"last"===t?e:"previous"===t?JSON.stringify(this.items[i])===JSON.stringify(this.items[0])?e:i-this.baseIndex:"next"===t?JSON.stringify(this.items[i])===JSON.stringify(this.items[e])?0:i+this.baseIndex:0,r}}class p{items=[];#t=10;#s;#e;constructor(t,e){Array.isArray(t)&&(this.items=t),e&&(["string","function"].includes(typeof e.next)||s(e.next)&&URL.canParse(e.next))&&(this.#s=e.next),"number"==typeof e?.top&&(this.#t=e.top),"number"==typeof e?.total&&(this.#e=e.total)}getPage=(t=0,s)=>{const e="function"==typeof s?this.items.filter(s):this.items;let r;return this.#s?r=this.#s:e.length>t+this.#t&&(r=()=>this.getPage(t+this.#t,s)),new y({items:e.slice(t,t+this.#t),total:this.#e,top:this.#t,next:r})}}const l=/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/,g=t=>t.toISOString().split("T")[0],b=(t,s)=>s.includes(t?.tagName.toLowerCase()),m='a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier], mg-button',S=t=>"number"==typeof t&&!Number.isNaN(t),d=t=>[t,...x(t),...A(t)],x=(t,s=[])=>{if(t.self!==t.top)try{const e=t.parent;return e?(s.push(e),x(e,s)):s}catch(t){return console.error("Different hosts between iframes:",t),s}return s},A=(t,s=[])=>{if(t.frames.length>0)for(const e of Array.from(t.frames))s.push(e),A(e,s);return s};export{t as C,p as P,h as a,b,a as c,r as d,c as e,f,d as g,y as h,i,e as j,s as k,m as l,o as m,u as n,l as o,g as p,S as q,n as t}