@mgdis/mg-components 5.22.0 → 5.23.1
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.
- package/dist/cjs/{index-28bf9033.js → index-0cf3e6d5.js} +22 -13
- package/dist/cjs/index-0cf3e6d5.js.map +1 -0
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mg-action-more_34.cjs.entry.js +238 -169
- package/dist/cjs/mg-action-more_34.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-components.cjs.js +3 -3
- package/dist/cjs/mg-components.cjs.js.map +1 -1
- package/dist/cjs/mg-item-more.cjs.entry.js +7 -6
- package/dist/cjs/mg-item-more.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-menu.conf-0229bb75.js +333 -0
- package/dist/cjs/mg-menu.conf-0229bb75.js.map +1 -0
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.js.map +1 -1
- package/dist/collection/components/atoms/mg-button/mg-button.js +1 -1
- package/dist/collection/components/atoms/mg-button/mg-button.js.map +1 -1
- package/dist/collection/components/atoms/mg-card/mg-card.js +1 -1
- package/dist/collection/components/atoms/mg-card/mg-card.js.map +1 -1
- package/dist/collection/components/atoms/mg-character-left/mg-character-left.js.map +1 -1
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +1 -1
- package/dist/collection/components/atoms/mg-icon/mg-icon.js.map +1 -1
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +1 -1
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.js.map +1 -1
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -1
- package/dist/collection/components/atoms/mg-tag/mg-tag.js.map +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
- package/dist/collection/components/molecules/inputs/MgInput.js +1 -1
- package/dist/collection/components/molecules/inputs/MgInput.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +10 -7
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +84 -49
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +43 -38
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js.map +1 -1
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +1 -1
- package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js.map +1 -1
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +1 -1
- package/dist/collection/components/molecules/mg-action-more/mg-action-more.js.map +1 -1
- package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
- package/dist/collection/components/molecules/mg-details/mg-details.js.map +1 -1
- package/dist/collection/components/molecules/mg-form/mg-form.js +1 -1
- package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -1
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js.map +1 -1
- package/dist/collection/components/molecules/mg-item-more/mg-item-more.js +1 -1
- package/dist/collection/components/molecules/mg-item-more/mg-item-more.js.map +1 -1
- package/dist/collection/components/molecules/mg-message/mg-message.js +1 -1
- package/dist/collection/components/molecules/mg-message/mg-message.js.map +1 -1
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +6 -5
- package/dist/collection/components/molecules/mg-modal/mg-modal.js.map +1 -1
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +1 -1
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js.map +1 -1
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
- package/dist/collection/components/molecules/mg-panel/mg-panel.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
- package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js.map +1 -1
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +1 -1
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js.map +1 -1
- package/dist/collection/locales/en/messages.json +9 -1
- package/dist/collection/locales/fr/messages.json +9 -1
- package/dist/collection/locales/index.js +2 -2
- package/dist/collection/locales/index.js.map +1 -1
- package/dist/collection/styles/fonts.css +1 -0
- package/dist/collection/styles/global.css +1 -0
- package/dist/collection/styles/main.css +1 -0
- package/dist/collection/styles/mg-components-utils.css +1 -0
- package/dist/collection/styles/variables.css +1 -0
- package/dist/collection/utils/behaviors.utils.js.map +1 -1
- package/dist/collection/utils/behaviors.utils.spec.js +1 -1
- package/dist/collection/utils/behaviors.utils.spec.js.map +1 -1
- package/dist/collection/utils/unit.test.utils.js +0 -104
- package/dist/collection/utils/unit.test.utils.js.map +1 -1
- package/dist/components/MgInput.js +3 -3
- package/dist/components/MgInput.js.map +1 -1
- package/dist/components/index.es.js +75 -0
- package/dist/components/index.es.js.map +1 -0
- package/dist/components/index2.js +22 -61
- package/dist/components/index2.js.map +1 -1
- package/dist/components/mg-action-more.js +5 -4
- package/dist/components/mg-action-more.js.map +1 -1
- package/dist/components/mg-badge2.js +5 -4
- package/dist/components/mg-badge2.js.map +1 -1
- package/dist/components/mg-button2.js +6 -5
- package/dist/components/mg-button2.js.map +1 -1
- package/dist/components/mg-card2.js +4 -3
- package/dist/components/mg-card2.js.map +1 -1
- package/dist/components/mg-character-left2.js +2 -1
- package/dist/components/mg-character-left2.js.map +1 -1
- package/dist/components/mg-details.js +4 -3
- package/dist/components/mg-details.js.map +1 -1
- package/dist/components/mg-divider.js +2 -1
- package/dist/components/mg-divider.js.map +1 -1
- package/dist/components/mg-form.js +5 -4
- package/dist/components/mg-form.js.map +1 -1
- package/dist/components/mg-icon2.js +4 -3
- package/dist/components/mg-icon2.js.map +1 -1
- package/dist/components/mg-illustrated-message.js +4 -3
- package/dist/components/mg-illustrated-message.js.map +1 -1
- package/dist/components/mg-input-checkbox.js +16 -12
- package/dist/components/mg-input-checkbox.js.map +1 -1
- package/dist/components/mg-input-date.js +55 -24
- package/dist/components/mg-input-date.js.map +1 -1
- package/dist/components/mg-input-numeric.js +15 -10
- package/dist/components/mg-input-numeric.js.map +1 -1
- package/dist/components/mg-input-password.js +5 -4
- package/dist/components/mg-input-password.js.map +1 -1
- package/dist/components/mg-input-radio.js +6 -5
- package/dist/components/mg-input-radio.js.map +1 -1
- package/dist/components/mg-input-select2.js +8 -7
- package/dist/components/mg-input-select2.js.map +1 -1
- package/dist/components/mg-input-text2.js +8 -7
- package/dist/components/mg-input-text2.js.map +1 -1
- package/dist/components/mg-input-textarea.js +8 -7
- package/dist/components/mg-input-textarea.js.map +1 -1
- package/dist/components/mg-input-title2.js +4 -3
- package/dist/components/mg-input-title2.js.map +1 -1
- package/dist/components/mg-input-toggle.js +6 -5
- package/dist/components/mg-input-toggle.js.map +1 -1
- package/dist/components/mg-item-more.js +4 -3
- package/dist/components/mg-item-more.js.map +1 -1
- package/dist/components/mg-menu-item2.js +6 -5
- package/dist/components/mg-menu-item2.js.map +1 -1
- package/dist/components/mg-menu2.js +2 -1
- package/dist/components/mg-menu2.js.map +1 -1
- package/dist/components/mg-message.js +5 -4
- package/dist/components/mg-message.js.map +1 -1
- package/dist/components/mg-modal.js +12 -10
- package/dist/components/mg-modal.js.map +1 -1
- package/dist/components/mg-pagination2.js +4 -3
- package/dist/components/mg-pagination2.js.map +1 -1
- package/dist/components/mg-panel.js +6 -5
- package/dist/components/mg-panel.js.map +1 -1
- package/dist/components/mg-popover-content2.js +5 -4
- package/dist/components/mg-popover-content2.js.map +1 -1
- package/dist/components/mg-popover2.js +5 -4
- package/dist/components/mg-popover2.js.map +1 -1
- package/dist/components/mg-skip-links.js +4 -3
- package/dist/components/mg-skip-links.js.map +1 -1
- package/dist/components/mg-tabs.js +8 -7
- package/dist/components/mg-tabs.js.map +1 -1
- package/dist/components/mg-tag.js +5 -4
- package/dist/components/mg-tag.js.map +1 -1
- package/dist/components/mg-tooltip-content2.js +2 -1
- package/dist/components/mg-tooltip-content2.js.map +1 -1
- package/dist/components/mg-tooltip2.js +8 -7
- package/dist/components/mg-tooltip2.js.map +1 -1
- package/dist/esm/{index-93dafb06.js → index-91977c3d.js} +22 -13
- package/dist/esm/index-91977c3d.js.map +1 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mg-action-more_34.entry.js +206 -137
- package/dist/esm/mg-action-more_34.entry.js.map +1 -1
- package/dist/esm/mg-components.js +4 -4
- package/dist/esm/mg-components.js.map +1 -1
- package/dist/esm/mg-item-more.entry.js +5 -4
- package/dist/esm/mg-item-more.entry.js.map +1 -1
- package/dist/esm/mg-menu.conf-4b2d2eab.js +315 -0
- package/dist/esm/mg-menu.conf-4b2d2eab.js.map +1 -0
- package/dist/mg-components/locales/en/messages.json +9 -1
- package/dist/mg-components/locales/fr/messages.json +9 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/mg-components.esm.js.map +1 -1
- package/dist/mg-components/p-1564df7a.js +2 -0
- package/dist/mg-components/p-1564df7a.js.map +1 -0
- package/dist/mg-components/p-49e1ffcb.js +3 -0
- package/dist/mg-components/p-49e1ffcb.js.map +1 -0
- package/dist/mg-components/p-6c68c7eb.entry.js +2 -0
- package/dist/mg-components/p-6c68c7eb.entry.js.map +1 -0
- package/dist/mg-components/p-896da866.entry.js +2 -0
- package/dist/mg-components/p-896da866.entry.js.map +1 -0
- package/dist/mg-components/styles/fonts.css +1 -0
- package/dist/mg-components/styles/global.css +1 -0
- package/dist/mg-components/styles/main.css +1 -0
- package/dist/mg-components/styles/mg-components-utils.css +1 -0
- package/dist/mg-components/styles/variables.css +1 -0
- package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +1 -1
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +1 -1
- package/dist/types/components/atoms/mg-card/mg-card.d.ts +1 -1
- package/dist/types/components/atoms/mg-icon/mg-icon.d.ts +1 -1
- package/dist/types/components/atoms/mg-tag/mg-tag.d.ts +1 -1
- package/dist/types/components/molecules/inputs/MgInput.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +29 -12
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +9 -9
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +1 -1
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +1 -1
- package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +1 -1
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +1 -1
- package/dist/types/components/molecules/mg-message/mg-message.d.ts +1 -1
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +1 -1
- package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +1 -1
- package/dist/types/components/molecules/mg-popover/mg-popover-content/mg-popover-content.d.ts +1 -1
- package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +1 -1
- package/dist/types/components.d.ts +2 -2
- package/dist/types/locales/index.d.ts +1 -180
- package/dist/types/utils/unit.test.utils.d.ts +0 -82
- package/package.json +38 -35
- package/dist/cjs/components.utils-637c479d.js +0 -447
- package/dist/cjs/components.utils-637c479d.js.map +0 -1
- package/dist/cjs/index-28bf9033.js.map +0 -1
- package/dist/collection/utils/components.utils.js +0 -147
- package/dist/collection/utils/components.utils.js.map +0 -1
- package/dist/collection/utils/components.utils.spec.js +0 -156
- package/dist/collection/utils/components.utils.spec.js.map +0 -1
- package/dist/collection/utils/e2e.test.utils.js +0 -46
- package/dist/collection/utils/e2e.test.utils.js.map +0 -1
- package/dist/collection/utils/locale.utils.js +0 -57
- package/dist/collection/utils/locale.utils.js.map +0 -1
- package/dist/collection/utils/locale.utils.spec.js +0 -52
- package/dist/collection/utils/locale.utils.spec.js.map +0 -1
- package/dist/components/components.utils.js +0 -150
- package/dist/components/components.utils.js.map +0 -1
- package/dist/esm/components.utils-f7c073a0.js +0 -431
- package/dist/esm/components.utils-f7c073a0.js.map +0 -1
- package/dist/esm/index-93dafb06.js.map +0 -1
- package/dist/mg-components/p-457dd62a.entry.js +0 -2
- package/dist/mg-components/p-457dd62a.entry.js.map +0 -1
- package/dist/mg-components/p-4fa40a8f.entry.js +0 -2
- package/dist/mg-components/p-4fa40a8f.entry.js.map +0 -1
- package/dist/mg-components/p-721c4571.js +0 -2
- package/dist/mg-components/p-721c4571.js.map +0 -1
- package/dist/mg-components/p-8155d0e2.js +0 -3
- package/dist/mg-components/p-8155d0e2.js.map +0 -1
- package/dist/types/utils/components.utils.d.ts +0 -87
- package/dist/types/utils/e2e.test.utils.d.ts +0 -22
- package/dist/types/utils/locale.utils.d.ts +0 -38
|
@@ -1,150 +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
|
-
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
|
-
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
|
-
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
|
-
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
|
-
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
|
-
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
|
-
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
|
-
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
|
-
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
|
-
const nextTick = async (callback) => callback();
|
|
147
|
-
|
|
148
|
-
export { ClassList as C, isTagName as a, cleanString as b, createID as c, allItemsAreString as d, focusableElements as f, getWindows as g, isValidString as i, nextTick as n };
|
|
149
|
-
|
|
150
|
-
//# sourceMappingURL=components.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"components.utils.js","mappings":"AAAA;;;;;;MAMa,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE;IAC/C,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,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SAC/C,IAAI,CAAC,EAAE,CAAC;SACR,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAEpB,OAAO,MAAM,KAAK,EAAE,GAAG,GAAG,MAAM,IAAI,SAAS,EAAE,GAAG,SAAS,CAAC;AAC9D,EAAE;AAEF;;;;MAIa,SAAS;IAMpB,YAAY,YAAsB,EAAE;;;;;QAQpC,QAAG,GAAG,CAAC,SAAiB;YACtB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC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ent":["/**\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"],"version":3}
|
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
const errors$1 = {
|
|
2
|
-
required: "This field is required.",
|
|
3
|
-
date: {
|
|
4
|
-
badInput: "The date format must be <span aria-hidden=\"true\">mm/dd/yyyy</span><span class=\"mg-u-visually-hidden\">m m / d d / y y y y</span> and the date must be greater than {min}",
|
|
5
|
-
min: "The date cannot be earlier than {min}",
|
|
6
|
-
max: "The date cannot be later than {max}",
|
|
7
|
-
minMax: "The date must be between {min} and {max}"
|
|
8
|
-
},
|
|
9
|
-
numeric: {
|
|
10
|
-
min: "The value cannot be less than {min}",
|
|
11
|
-
max: "The value cannot be greater than {max}",
|
|
12
|
-
minMax: "The value must be between {min} et {max}"
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const nbCharLeft$1 = "{counter} characters left.";
|
|
16
|
-
const input$1 = {
|
|
17
|
-
select: {
|
|
18
|
-
placeholder: "Select a value"
|
|
19
|
-
},
|
|
20
|
-
checkbox: {
|
|
21
|
-
selectedValues: "{nb} selected values",
|
|
22
|
-
selectedValue: "{nb} selected value",
|
|
23
|
-
editButton: "Edit",
|
|
24
|
-
selectButton: "Select values",
|
|
25
|
-
showButton: "Show",
|
|
26
|
-
label: "Enter a value",
|
|
27
|
-
result: "result",
|
|
28
|
-
results: "results",
|
|
29
|
-
searchResults: "Search result(s) list.",
|
|
30
|
-
noResult: "No result.",
|
|
31
|
-
sections: {
|
|
32
|
-
selected: {
|
|
33
|
-
title: "Selected",
|
|
34
|
-
titlePlurial: "Selected",
|
|
35
|
-
action: "Unselect all",
|
|
36
|
-
tooltip: "Unselect all current search results"
|
|
37
|
-
},
|
|
38
|
-
notSelected: {
|
|
39
|
-
title: "Not selected",
|
|
40
|
-
titlePlurial: "Not selected",
|
|
41
|
-
action: "Select all",
|
|
42
|
-
tooltip: "Select all current search results"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const form$1 = {
|
|
48
|
-
required: "Fields with a <strong class=\"mg-u-is-asterisk\">*</strong> are required",
|
|
49
|
-
requiredSingle: "Field with a <strong class=\"mg-u-is-asterisk\">*</strong> is required",
|
|
50
|
-
allRequired: "All fields are required",
|
|
51
|
-
allRequiredSingle: "The field is required"
|
|
52
|
-
};
|
|
53
|
-
const message$1 = {
|
|
54
|
-
closeButton: "Close message"
|
|
55
|
-
};
|
|
56
|
-
const modal$1 = {
|
|
57
|
-
closeButton: "Close modal"
|
|
58
|
-
};
|
|
59
|
-
const pagination$1 = {
|
|
60
|
-
label: "Pagination",
|
|
61
|
-
page: "page",
|
|
62
|
-
pages: "pages",
|
|
63
|
-
nextPage: "Next page",
|
|
64
|
-
previousPage: "Previous page",
|
|
65
|
-
selectPage: "Select the page to display."
|
|
66
|
-
};
|
|
67
|
-
const panel$1 = {
|
|
68
|
-
editLabel: "Edit section title."
|
|
69
|
-
};
|
|
70
|
-
const skipLinks$1 = {
|
|
71
|
-
navLabel: "Quick access"
|
|
72
|
-
};
|
|
73
|
-
const general$1 = {
|
|
74
|
-
confirm: "Confirm",
|
|
75
|
-
cancel: "Cancel",
|
|
76
|
-
close: "Close",
|
|
77
|
-
next: "next",
|
|
78
|
-
previous: "previous"
|
|
79
|
-
};
|
|
80
|
-
const plusMenu$1 = {
|
|
81
|
-
moreLabel: "Additional menu",
|
|
82
|
-
badgeLabel: "Include notification(s)"
|
|
83
|
-
};
|
|
84
|
-
const actionMore$1 = {
|
|
85
|
-
label: "Actions"
|
|
86
|
-
};
|
|
87
|
-
const en = {
|
|
88
|
-
errors: errors$1,
|
|
89
|
-
nbCharLeft: nbCharLeft$1,
|
|
90
|
-
input: input$1,
|
|
91
|
-
form: form$1,
|
|
92
|
-
message: message$1,
|
|
93
|
-
modal: modal$1,
|
|
94
|
-
pagination: pagination$1,
|
|
95
|
-
panel: panel$1,
|
|
96
|
-
skipLinks: skipLinks$1,
|
|
97
|
-
general: general$1,
|
|
98
|
-
plusMenu: plusMenu$1,
|
|
99
|
-
actionMore: actionMore$1
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const errors = {
|
|
103
|
-
required: "Ce champ est obligatoire.",
|
|
104
|
-
date: {
|
|
105
|
-
badInput: "Le format de la date doit être du type <span aria-hidden=\"true\">jj/mm/aaaa</span><span class=\"mg-u-visually-hidden\">j j / m m / a a a a</span> et la date supérieure au {min}",
|
|
106
|
-
min: "La date ne peut pas être antérieure au {min}",
|
|
107
|
-
max: "La date ne peut pas être postérieure au {max}",
|
|
108
|
-
minMax: "La date doit être comprise entre le {min} et le {max}"
|
|
109
|
-
},
|
|
110
|
-
numeric: {
|
|
111
|
-
min: "La valeur ne peut pas être inférieure à {min}",
|
|
112
|
-
max: "La valeur ne peut pas être supérieure à {max}",
|
|
113
|
-
minMax: "La valeur doit être comprise entre {min} et {max}"
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const nbCharLeft = "{counter} caractères disponibles.";
|
|
117
|
-
const input = {
|
|
118
|
-
select: {
|
|
119
|
-
placeholder: "Sélectionnez une valeur"
|
|
120
|
-
},
|
|
121
|
-
checkbox: {
|
|
122
|
-
selectedValues: "{nb} valeurs selectionnées",
|
|
123
|
-
selectedValue: "{nb} valeur selectionnée",
|
|
124
|
-
editButton: "Modifier",
|
|
125
|
-
selectButton: "Sélectionner des valeurs",
|
|
126
|
-
showButton: "Voir",
|
|
127
|
-
label: "Saisissez une valeur",
|
|
128
|
-
result: "résultat",
|
|
129
|
-
results: "résultats",
|
|
130
|
-
searchResults: "List de résultat(s) de la recherche.",
|
|
131
|
-
noResult: "Aucun résultat.",
|
|
132
|
-
sections: {
|
|
133
|
-
selected: {
|
|
134
|
-
title: "Sélectionné",
|
|
135
|
-
titlePlurial: "Sélectionnés",
|
|
136
|
-
action: "Tout désélectionner",
|
|
137
|
-
tooltip: "Désélectionne tous les résultats de la recherche en cours"
|
|
138
|
-
},
|
|
139
|
-
notSelected: {
|
|
140
|
-
title: "Non sélectionné",
|
|
141
|
-
titlePlurial: "Non sélectionnés",
|
|
142
|
-
action: "Tout sélectionner",
|
|
143
|
-
tooltip: "Sélectionne tous les résultats de la recherche en cours"
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
const form = {
|
|
149
|
-
required: "Les champs marqués d'un <strong class=\"mg-u-is-asterisk\">*</strong> sont obligatoires",
|
|
150
|
-
requiredSingle: "Le champ marqué d'un <strong class=\"mg-u-is-asterisk\">*</strong> est obligatoire",
|
|
151
|
-
allRequired: "Tous les champs sont obligatoires",
|
|
152
|
-
allRequiredSingle: "Le champ est obligatoire"
|
|
153
|
-
};
|
|
154
|
-
const message = {
|
|
155
|
-
closeButton: "Fermer le message"
|
|
156
|
-
};
|
|
157
|
-
const modal = {
|
|
158
|
-
closeButton: "Fermer la modale"
|
|
159
|
-
};
|
|
160
|
-
const pagination = {
|
|
161
|
-
label: "Pagination",
|
|
162
|
-
page: "page",
|
|
163
|
-
pages: "pages",
|
|
164
|
-
nextPage: "Page suivante",
|
|
165
|
-
previousPage: "Page précédente",
|
|
166
|
-
selectPage: "Sélectionner la page à afficher."
|
|
167
|
-
};
|
|
168
|
-
const panel = {
|
|
169
|
-
editLabel: "Modifier le titre de la section."
|
|
170
|
-
};
|
|
171
|
-
const skipLinks = {
|
|
172
|
-
navLabel: "Accès rapide"
|
|
173
|
-
};
|
|
174
|
-
const general = {
|
|
175
|
-
confirm: "Valider",
|
|
176
|
-
cancel: "Annuler",
|
|
177
|
-
close: "Fermer",
|
|
178
|
-
next: "suivant",
|
|
179
|
-
previous: "précédent"
|
|
180
|
-
};
|
|
181
|
-
const plusMenu = {
|
|
182
|
-
moreLabel: "Menu complémentaire",
|
|
183
|
-
badgeLabel: "Notification(s) incluse(s)"
|
|
184
|
-
};
|
|
185
|
-
const actionMore = {
|
|
186
|
-
label: "Actions"
|
|
187
|
-
};
|
|
188
|
-
const fr = {
|
|
189
|
-
errors: errors,
|
|
190
|
-
nbCharLeft: nbCharLeft,
|
|
191
|
-
input: input,
|
|
192
|
-
form: form,
|
|
193
|
-
message: message,
|
|
194
|
-
modal: modal,
|
|
195
|
-
pagination: pagination,
|
|
196
|
-
panel: panel,
|
|
197
|
-
skipLinks: skipLinks,
|
|
198
|
-
general: general,
|
|
199
|
-
plusMenu: plusMenu,
|
|
200
|
-
actionMore: actionMore
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Format number to the locale currency
|
|
205
|
-
* @param number - number to format
|
|
206
|
-
* @param locale - locale to apply
|
|
207
|
-
* @param currency - currency to apply
|
|
208
|
-
* @returns formatted currency
|
|
209
|
-
*/
|
|
210
|
-
const localeCurrency = (number, locale, currency) => {
|
|
211
|
-
return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* Format number to locale
|
|
215
|
-
* @param number - number to format
|
|
216
|
-
* @param locale - locale to apply
|
|
217
|
-
* @returns formatted number
|
|
218
|
-
*/
|
|
219
|
-
const localeNumber = (number, locale) => {
|
|
220
|
-
return new Intl.NumberFormat(locale).format(number);
|
|
221
|
-
};
|
|
222
|
-
/**
|
|
223
|
-
* Date RegExp
|
|
224
|
-
*/
|
|
225
|
-
const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
226
|
-
/**
|
|
227
|
-
* Locale date format
|
|
228
|
-
* @param date - date to format
|
|
229
|
-
* @param locale - locale to apply
|
|
230
|
-
* @returns formatted date
|
|
231
|
-
*/
|
|
232
|
-
const localeDate = (date, locale) => {
|
|
233
|
-
if (typeof date !== 'string' || date === '' || !dateRegExp.test(date)) {
|
|
234
|
-
return '';
|
|
235
|
-
}
|
|
236
|
-
return new Intl.DateTimeFormat(locale).format(new Date(date));
|
|
237
|
-
};
|
|
238
|
-
/**
|
|
239
|
-
* Get locale and messages
|
|
240
|
-
* We load the defined locale but for now we only support the first subtag for messages
|
|
241
|
-
* @param element - element we need to get the language
|
|
242
|
-
* @param messages - messages to use
|
|
243
|
-
* @param defaultLocale - default messages locale
|
|
244
|
-
* @returns messages object
|
|
245
|
-
*/
|
|
246
|
-
const getLocaleMessages = (element, messages, defaultLocale) => {
|
|
247
|
-
// Get local
|
|
248
|
-
const closestLangAttribute = element.closest('[lang]');
|
|
249
|
-
const closestLang = Intl.NumberFormat.supportedLocalesOf(closestLangAttribute === null || closestLangAttribute === void 0 ? void 0 : closestLangAttribute.lang);
|
|
250
|
-
const locale = closestLang.length > 0 ? closestLang[0] : navigator.language || defaultLocale;
|
|
251
|
-
// Only keep first subtag
|
|
252
|
-
const localeSubtag = locale.split('-').shift();
|
|
253
|
-
// Return
|
|
254
|
-
return {
|
|
255
|
-
locale,
|
|
256
|
-
messages: messages[localeSubtag] || messages[defaultLocale],
|
|
257
|
-
};
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const defaultLocale = 'en';
|
|
261
|
-
const messages = { en, fr };
|
|
262
|
-
/**
|
|
263
|
-
* Get Intl object
|
|
264
|
-
* @param element - element we need to get the language
|
|
265
|
-
* @returns messages object
|
|
266
|
-
*/
|
|
267
|
-
const initLocales = (element) => getLocaleMessages(element, messages, defaultLocale);
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Menu direction type
|
|
271
|
-
*/
|
|
272
|
-
var Direction;
|
|
273
|
-
(function (Direction) {
|
|
274
|
-
Direction["VERTICAL"] = "vertical";
|
|
275
|
-
Direction["HORIZONTAL"] = "horizontal";
|
|
276
|
-
})(Direction || (Direction = {}));
|
|
277
|
-
/**
|
|
278
|
-
* List of all possibles sizes
|
|
279
|
-
*/
|
|
280
|
-
const sizes = ['regular', 'medium', 'large'];
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Create random ID
|
|
284
|
-
* @param prefix - add prefix to created ID
|
|
285
|
-
* @param length - ID length
|
|
286
|
-
* @returns ID
|
|
287
|
-
*/
|
|
288
|
-
const createID = (prefix = '', length = 10) => {
|
|
289
|
-
const randomBytes = new Uint8Array(length);
|
|
290
|
-
crypto.getRandomValues(randomBytes);
|
|
291
|
-
const hexString = Array.from(randomBytes)
|
|
292
|
-
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
293
|
-
.join('')
|
|
294
|
-
.slice(0, length);
|
|
295
|
-
return prefix !== '' ? `${prefix}-${hexString}` : hexString;
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Class to manage component classlist
|
|
299
|
-
* Set() are not working when imported in project
|
|
300
|
-
*/
|
|
301
|
-
class ClassList {
|
|
302
|
-
constructor(classlist = []) {
|
|
303
|
-
/**
|
|
304
|
-
* Add class
|
|
305
|
-
* @param className - class name to add
|
|
306
|
-
*/
|
|
307
|
-
this.add = (className) => {
|
|
308
|
-
if (!this.has(className)) {
|
|
309
|
-
this.classes.push(className);
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
/**
|
|
313
|
-
* Delete class
|
|
314
|
-
* @param className - class name to delete
|
|
315
|
-
*/
|
|
316
|
-
this.delete = (className) => {
|
|
317
|
-
const index = this.classes.indexOf(className);
|
|
318
|
-
if (index > -1) {
|
|
319
|
-
this.classes.splice(index, 1);
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
/**
|
|
323
|
-
* Check if class exist in list
|
|
324
|
-
* @param className - class name to check
|
|
325
|
-
* @returns class name is in the list
|
|
326
|
-
*/
|
|
327
|
-
this.has = (className) => {
|
|
328
|
-
return this.classes.includes(className);
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* Join classes seperated by spaces
|
|
332
|
-
* @returns joined values
|
|
333
|
-
*/
|
|
334
|
-
this.join = () => {
|
|
335
|
-
return this.classes.join(' ');
|
|
336
|
-
};
|
|
337
|
-
this.classes = classlist;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Check if all items are string
|
|
342
|
-
* @param items - items to check
|
|
343
|
-
* @returns all items are string
|
|
344
|
-
*/
|
|
345
|
-
const allItemsAreString = (items) => Array.isArray(items) && items.every(item => typeof item === 'string');
|
|
346
|
-
/**
|
|
347
|
-
* Check if element is a heading
|
|
348
|
-
* @param element - slotted element
|
|
349
|
-
* @param tagNames - allowed tag names list
|
|
350
|
-
* @returns element is a heading
|
|
351
|
-
*/
|
|
352
|
-
const isTagName = (element, tagNames) => {
|
|
353
|
-
return tagNames.includes(element === null || element === void 0 ? void 0 : element.tagName.toLowerCase());
|
|
354
|
-
};
|
|
355
|
-
/**
|
|
356
|
-
* Focusable elements query selector
|
|
357
|
-
*/
|
|
358
|
-
const focusableElements = 'a[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), [identifier]';
|
|
359
|
-
/**
|
|
360
|
-
* Get windows
|
|
361
|
-
* @param localWindow - the window we are lookink for other windows
|
|
362
|
-
* @returns The list of windows found
|
|
363
|
-
*/
|
|
364
|
-
const getWindows = (localWindow) => {
|
|
365
|
-
const parentWindows = getParentWindows(localWindow);
|
|
366
|
-
const childWindows = getChildWindows(localWindow);
|
|
367
|
-
return [localWindow, ...parentWindows, ...childWindows];
|
|
368
|
-
};
|
|
369
|
-
/**
|
|
370
|
-
* Get parent windows
|
|
371
|
-
* @param localWindow - the window we are lookink for parents
|
|
372
|
-
* @param windows - The list of allready found windows
|
|
373
|
-
* @returns The list of windows found
|
|
374
|
-
*/
|
|
375
|
-
const getParentWindows = (localWindow, windows = []) => {
|
|
376
|
-
// Check if is in iframe
|
|
377
|
-
if (localWindow.self !== localWindow.top) {
|
|
378
|
-
// Check if we have permission to access parent
|
|
379
|
-
try {
|
|
380
|
-
const parentWindow = localWindow.parent;
|
|
381
|
-
windows.push(parentWindow);
|
|
382
|
-
return getParentWindows(parentWindow, windows);
|
|
383
|
-
}
|
|
384
|
-
catch (err) {
|
|
385
|
-
console.error('Different hosts between iframes:', err);
|
|
386
|
-
return windows;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
return windows;
|
|
390
|
-
};
|
|
391
|
-
/**
|
|
392
|
-
* Get child windows
|
|
393
|
-
* @param localWindow - the window we are lookink for children
|
|
394
|
-
* @param windows - The list of allready found windows
|
|
395
|
-
* @returns The list of windows found
|
|
396
|
-
*/
|
|
397
|
-
const getChildWindows = (localWindow, windows = []) => {
|
|
398
|
-
if (localWindow.frames.length > 0) {
|
|
399
|
-
for (const childWindow of Array.from(localWindow.frames)) {
|
|
400
|
-
windows.push(childWindow);
|
|
401
|
-
getChildWindows(childWindow, windows);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return windows;
|
|
405
|
-
};
|
|
406
|
-
/**
|
|
407
|
-
* Validate string
|
|
408
|
-
* @param value - value to check
|
|
409
|
-
* @returns if string is valid
|
|
410
|
-
*/
|
|
411
|
-
const isValidString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
412
|
-
/**
|
|
413
|
-
* Clean string caraters
|
|
414
|
-
* @param text - text to cliean
|
|
415
|
-
* @returns cleanded string
|
|
416
|
-
*/
|
|
417
|
-
const cleanString = (text) => typeof text === 'string' &&
|
|
418
|
-
text
|
|
419
|
-
.toLocaleLowerCase()
|
|
420
|
-
.normalize('NFD')
|
|
421
|
-
.replaceAll(/[\u0300-\u036f]/g, '');
|
|
422
|
-
/**
|
|
423
|
-
* Use to process code next tick in the event loop
|
|
424
|
-
* @param callback - code to excute on next tick
|
|
425
|
-
* @returns differed code excution
|
|
426
|
-
*/
|
|
427
|
-
const nextTick = async (callback) => callback();
|
|
428
|
-
|
|
429
|
-
export { ClassList as C, Direction as D, isValidString as a, isTagName as b, createID as c, cleanString as d, dateRegExp as e, localeCurrency as f, localeNumber as g, allItemsAreString as h, initLocales as i, focusableElements as j, getWindows as k, localeDate as l, nextTick as n, sizes as s };
|
|
430
|
-
|
|
431
|
-
//# sourceMappingURL=components.utils-f7c073a0.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"file":"components.utils-f7c073a0.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;MAOa,cAAc,GAAG,CAAC,MAAc,EAAE,MAAc,EAAE,QAAgB;IAC7E,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,Q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AChD,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC3B,OAAO,gBAAgB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;SAChD;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;YACvD,OAAO,OAAO,CAAC;SAChB;KACF;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;AAMA,MAAM,eAAe,GAAG,CAAC,WAAmB,EAAE,UAAoB,EAAE;IAClE,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,GAAG,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;;;;;MAKa,aAAa,GAAG,CAAC,KAAc,KAAc,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG;AAE3G;;;;;MAKa,WAAW,GAAG,CAAC,IAAY,KACtC,OAAO,IAAI,KAAK,QAAQ;IACxB,IAAI;SACD,iBAAiB,EAAE;SACnB,SAAS,CAAC,KAAK,CAAC;SAChB,UAAU,CAAC,kBAAkB,EAAE,EAAE,EAAE;AAExC;;;;;MAKa,QAAQ,GAAG,OAAO,QAAoB,KAAoB,QAAQ;;;;","names":[],"sources":["src/utils/locale.utils.ts","src/locales/index.ts","src/components/molecules/menu/mg-menu/mg-menu.conf.ts","src/utils/components.utils.ts"],"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","import en from './en/messages.json';\nimport fr from './fr/messages.json';\nimport { getLocaleMessages } from '../utils/locale.utils';\n\nconst defaultLocale = 'en';\nconst messages = { en, fr };\n\n/**\n * Get Intl object\n * @param element - element we need to get the language\n * @returns messages object\n */\nexport const initLocales = (element: HTMLElement): { locale: string; messages: Record<string, unknown> } => getLocaleMessages(element, messages, defaultLocale);\n","import { MgItemMore } from '../../mg-item-more/mg-item-more';\n\n/**\n * Menu direction type\n */\nexport enum Direction {\n VERTICAL = 'vertical',\n HORIZONTAL = 'horizontal',\n}\n\n/**\n * ItemMore prop type\n */\nexport type ItemMoreType = Pick<MgItemMore, 'icon' | 'slotlabel' | 'size'>;\n\n/**\n * List of all possibles sizes\n */\nexport const sizes = ['regular', 'medium', 'large'] as const;\n\n/**\n * item Size from sizes\n */\nexport type MenuSizeType = (typeof sizes)[number];\n","/**\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"],"version":3}
|