@mgdis/mg-components 5.7.0 → 5.8.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.
Files changed (66) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/mg-action-more_31.cjs.entry.js +351 -600
  3. package/dist/cjs/mg-components.cjs.js +1 -1
  4. package/dist/cjs/mg-item-more.cjs.entry.js +273 -0
  5. package/dist/cjs/mg-menu.conf-9afe6571.js +242 -0
  6. package/dist/collection/collection-manifest.json +2 -1
  7. package/dist/collection/components/atoms/mg-button/mg-button.js +24 -0
  8. package/dist/collection/components/atoms/mg-icon/mg-icon.conf.js +8 -0
  9. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +6 -2
  10. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +14 -10
  11. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +91 -21
  12. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.conf.js +0 -13
  13. package/dist/collection/components/molecules/menu/mg-menu/mg-menu.js +80 -76
  14. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.css +7 -5
  15. package/dist/collection/components/molecules/menu/mg-menu-item/mg-menu-item.js +174 -78
  16. package/dist/collection/components/molecules/mg-form/mg-form.js +1 -1
  17. package/dist/collection/components/molecules/mg-item-more/mg-item-more.conf.js +1 -0
  18. package/dist/collection/components/molecules/mg-item-more/mg-item-more.css +30 -0
  19. package/dist/collection/components/molecules/mg-item-more/mg-item-more.js +200 -0
  20. package/dist/collection/components/molecules/mg-tabs/mg-tabs.css +0 -2
  21. package/dist/collection/styles/navigation-button.scss +1 -1
  22. package/dist/collection/utils/behaviors.utils.js +33 -29
  23. package/dist/collection/utils/components.utils.js +2 -4
  24. package/dist/collection/utils/unit.test.utils.js +25 -0
  25. package/dist/components/components.utils.js +2 -4
  26. package/dist/components/index.d.ts +1 -0
  27. package/dist/components/index.js +1 -0
  28. package/dist/components/mg-action-more.js +2 -1
  29. package/dist/components/mg-button2.js +4 -1
  30. package/dist/components/mg-form.js +1 -1
  31. package/dist/components/mg-icon2.js +8 -0
  32. package/dist/components/mg-input-checkbox.js +5 -4
  33. package/dist/components/mg-input-select2.js +83 -17
  34. package/dist/components/mg-item-more.d.ts +11 -0
  35. package/dist/components/mg-item-more.js +336 -0
  36. package/dist/components/mg-menu-item2.js +138 -251
  37. package/dist/components/mg-menu.conf.js +14 -0
  38. package/dist/components/mg-menu2.js +76 -111
  39. package/dist/components/mg-tabs.js +1 -1
  40. package/dist/components/mg-tooltip2.js +6 -2
  41. package/dist/esm/loader.js +1 -1
  42. package/dist/esm/mg-action-more_31.entry.js +321 -570
  43. package/dist/esm/mg-components.js +1 -1
  44. package/dist/esm/mg-item-more.entry.js +269 -0
  45. package/dist/esm/mg-menu.conf-881fbd82.js +235 -0
  46. package/dist/mg-components/mg-components.css +1 -1
  47. package/dist/mg-components/mg-components.esm.js +1 -1
  48. package/dist/mg-components/p-1221773c.entry.js +1 -0
  49. package/dist/mg-components/p-30bc87db.entry.js +1 -0
  50. package/dist/mg-components/p-367f92d2.js +1 -0
  51. package/dist/mg-components/styles/navigation-button.scss +1 -1
  52. package/dist/types/components/atoms/mg-button/mg-button.d.ts +5 -0
  53. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +3 -3
  54. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +39 -4
  55. package/dist/types/components/molecules/menu/mg-menu/mg-menu.conf.d.ts +3 -27
  56. package/dist/types/components/molecules/menu/mg-menu/mg-menu.d.ts +38 -30
  57. package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.conf.d.ts +5 -0
  58. package/dist/types/components/molecules/menu/mg-menu-item/mg-menu-item.d.ts +69 -16
  59. package/dist/types/components/molecules/mg-item-more/mg-item-more.conf.d.ts +26 -0
  60. package/dist/types/components/molecules/mg-item-more/mg-item-more.d.ts +74 -0
  61. package/dist/types/components.d.ts +75 -17
  62. package/dist/types/utils/behaviors.utils.d.ts +12 -5
  63. package/dist/types/utils/components.utils.d.ts +2 -2
  64. package/dist/types/utils/unit.test.utils.d.ts +11 -0
  65. package/package.json +1 -1
  66. package/dist/mg-components/p-4cfd5423.entry.js +0 -1
@@ -0,0 +1,336 @@
1
+ import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
2
+ import { i as initLocales } from './index2.js';
3
+ import { D as Direction } from './mg-menu.conf.js';
4
+ import { d as defineCustomElement$8 } from './mg-badge2.js';
5
+ import { d as defineCustomElement$7 } from './mg-button2.js';
6
+ import { d as defineCustomElement$6 } from './mg-card2.js';
7
+ import { d as defineCustomElement$5 } from './mg-icon2.js';
8
+ import { d as defineCustomElement$4 } from './mg-menu2.js';
9
+ import { d as defineCustomElement$3 } from './mg-menu-item2.js';
10
+ import { d as defineCustomElement$2 } from './mg-popover2.js';
11
+
12
+ /**
13
+ * MgItemMore type guard
14
+ *
15
+ * @param {HTMLElement} element element to control type
16
+ * @returns {boolean} truthy if element is mg-item-more
17
+ */
18
+ const isMgItemMore = (element) => element.nodeName === 'MG-ITEM-MORE';
19
+ var OverflowBehaviorElements;
20
+ (function (OverflowBehaviorElements) {
21
+ OverflowBehaviorElements["BASE_INDEX"] = "data-overflow-base-index";
22
+ OverflowBehaviorElements["PROXY_INDEX"] = "data-overflow-proxy-index";
23
+ })(OverflowBehaviorElements || (OverflowBehaviorElements = {}));
24
+ class OverflowBehavior {
25
+ constructor(element, render) {
26
+ this.element = element;
27
+ this.render = render;
28
+ /**********
29
+ * Public *
30
+ **********/
31
+ /**
32
+ * Disconnect ResizeObserver
33
+ *
34
+ * @returns {void}
35
+ */
36
+ this.disconnect = () => {
37
+ this._resizeObserver.disconnect();
38
+ };
39
+ /************
40
+ * Internal *
41
+ ************/
42
+ /**
43
+ * run overflow behavior
44
+ *
45
+ * @param {number} width width of the container. Optional.
46
+ * @returns {void}
47
+ */
48
+ this.run = (width) => {
49
+ if (this._moreElement === undefined) {
50
+ // set moreElement
51
+ this._moreElement = this.render();
52
+ // set children
53
+ this._baseChildren = this.getInteractiveItems(this.element);
54
+ if (isMgItemMore(this._moreElement)) {
55
+ this._proxyChildren = this.getInteractiveItems(this._moreElement.shadowRoot.querySelector('mg-menu'));
56
+ }
57
+ // update children
58
+ this._baseChildren.forEach((child, index) => {
59
+ child.setAttribute(OverflowBehaviorElements.BASE_INDEX, `${index}`);
60
+ // set moreElement children
61
+ this._proxyChildren[index].setAttribute(OverflowBehaviorElements.PROXY_INDEX, `${index}`);
62
+ });
63
+ }
64
+ if (width !== undefined)
65
+ this.updateDisplayedItems(width);
66
+ };
67
+ /**
68
+ * Get interactive children filtred by authorized nodeName ['MG-MENU-ITEM', 'MG-BUTTON']
69
+ *
70
+ * @param {Element} element element to parse
71
+ * @returns {Element[]} children
72
+ */
73
+ this.getInteractiveItems = (element) => { var _a; return (((_a = element.children) === null || _a === void 0 ? void 0 : _a.length) > 0 ? Array.from(element.children) : []).filter(element => ['MG-MENU-ITEM', 'MG-BUTTON'].includes(element.nodeName)); };
74
+ /**
75
+ * Update displayed items in container from a given available space
76
+ *
77
+ * @param {number} availableWidth available width in container to display child items
78
+ * @returns {void}
79
+ */
80
+ this.updateDisplayedItems = (availableWidth) => {
81
+ this.restoreItems();
82
+ const acc = { accWidth: 0, previousItem: null };
83
+ [...this._baseChildren, this._moreElement].forEach((child) => {
84
+ acc.accWidth += child.offsetWidth;
85
+ const isPreviousItemHidden = acc.previousItem !== null && acc.previousItem.getAttribute('hidden') !== null;
86
+ // if previous item is hidden AND is NOT more element we hidde current
87
+ // OR if item has an overflow we hidde current
88
+ // OR if current item is more element AND have NOT previous hidden items, current more element item is an hidden item
89
+ // ELSE current is a display item
90
+ this.toggleItem(child, (isPreviousItemHidden && !this.isMoreElement(child)) || this.isOverflowElement(acc.accWidth, child, availableWidth) || (this.isMoreElement(child) && !isPreviousItemHidden));
91
+ // update previous item with current item
92
+ acc.previousItem = child;
93
+ });
94
+ };
95
+ /**
96
+ * Utility method to know if item overflow partialy or totaly in the container
97
+ *
98
+ * @param {number} cumulateWidth previous sibling elements cumulate width + item width
99
+ * @param {HTMLElement} item item HTML element
100
+ * @param {number} availableWidth container available width
101
+ * @returns {boolean} truthy if element is overflow
102
+ */
103
+ this.isOverflowElement = (cumulateWidth, item, availableWidth) => {
104
+ if (item.previousElementSibling === null || this.isMoreElement(item))
105
+ return false;
106
+ else if (!this.isMoreElement(item.nextElementSibling))
107
+ return cumulateWidth + this._moreElement.offsetWidth > availableWidth;
108
+ else
109
+ return cumulateWidth > availableWidth;
110
+ };
111
+ /**
112
+ * Utility method to know if a given element is the 'MORE' element
113
+ *
114
+ * @param {Element} element element to match with 'MORE' element
115
+ * @returns {boolean} truthy if element is the 'MORE' element
116
+ */
117
+ this.isMoreElement = (element) => element.nodeName === 'MG-ITEM-MORE';
118
+ /**
119
+ * Toggle display item element
120
+ *
121
+ * @param {HTMLElement} item item to control
122
+ * @param {boolean} isHidden is item hidden
123
+ * @returns {void}
124
+ */
125
+ this.toggleItem = (item, isHidden) => {
126
+ const mgActionMenuindex = Number(item.getAttribute(OverflowBehaviorElements.BASE_INDEX));
127
+ if (this.isMoreElement(item))
128
+ this.toggleElement(this._moreElement, isHidden);
129
+ else if (mgActionMenuindex >= 0) {
130
+ this.toggleElement(item, isHidden);
131
+ this.toggleElement(this._proxyChildren[mgActionMenuindex], !isHidden);
132
+ }
133
+ };
134
+ /**
135
+ * Toggle element's hidde attribute
136
+ *
137
+ * @param {Element} element element to toggle
138
+ * @param {boolean} isHidden element is hidden
139
+ * @returns {void}
140
+ */
141
+ this.toggleElement = (element, isHidden) => {
142
+ if (isHidden)
143
+ element.setAttribute('hidden', '');
144
+ else
145
+ element.removeAttribute('hidden');
146
+ };
147
+ /**
148
+ * Remove hidden attributes on all items
149
+ *
150
+ * @returns {void}
151
+ */
152
+ this.restoreItems = () => {
153
+ [...this._baseChildren, this._moreElement].forEach(item => item.removeAttribute('hidden'));
154
+ };
155
+ if (this._resizeObserver === undefined) {
156
+ // add resize observer
157
+ this._resizeObserver = new ResizeObserver(entries => {
158
+ entries.forEach(entry => {
159
+ this.run(entry.contentRect.width);
160
+ });
161
+ });
162
+ this._resizeObserver.observe(this.element);
163
+ }
164
+ this.run();
165
+ }
166
+ }
167
+
168
+ const mgItemMoreCss = ".sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media (prefers-reduced-motion){.mg-a11y-animation{animation:none !important;transition:none !important}}:host{display:flex}";
169
+
170
+ const MgItemMore$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
171
+ constructor() {
172
+ super();
173
+ this.__registerHost();
174
+ this.__attachShadow();
175
+ /************
176
+ * Internal *
177
+ ************/
178
+ this.name = 'mg-item-more';
179
+ /***********
180
+ * Methods *
181
+ ***********/
182
+ /**
183
+ * render mg-item-more overflow element
184
+ *
185
+ * @returns {HTMLMgItemMoreElement} mg-item-more element
186
+ */
187
+ this.renderMgMenuItemOverflowElement = () => {
188
+ // create menu items proxy element from item clones
189
+ const moreElementMenuItem = this.element.shadowRoot.querySelector('mg-menu-item');
190
+ this.menuItems.forEach((child) => {
191
+ moreElementMenuItem.querySelector('mg-menu').appendChild(child.cloneNode(true));
192
+ });
193
+ const allMenuItem = Array.from(this.parentMenu.querySelectorAll('mg-menu-item:not([data-overflow-more])'));
194
+ Array.from(moreElementMenuItem.querySelectorAll('mg-menu-item:not([data-overflow-more])')).forEach((proxy, index) => {
195
+ // manage click on proxy to mirror it on initial element
196
+ proxy.addEventListener('click', () => {
197
+ (allMenuItem[index].shadowRoot.querySelector('a') || allMenuItem[index].shadowRoot.querySelector('button')).dispatchEvent(new MouseEvent('click', { bubbles: true }));
198
+ });
199
+ // add id suffix to prevent duplicate key. default html id is: '';
200
+ if (proxy.id.trim() !== '')
201
+ proxy.id = `${proxy.id}-proxy`;
202
+ // manage status change miror in proxy
203
+ allMenuItem[index].addEventListener('status-change', (event) => {
204
+ proxy.setAttribute('status', event.detail);
205
+ });
206
+ });
207
+ return this.element;
208
+ };
209
+ this.icon = { icon: 'ellipsis-vertical' };
210
+ this.slotlabel = { display: false };
211
+ this.size = undefined;
212
+ this.parentMenu = undefined;
213
+ }
214
+ validateIcon(newValue) {
215
+ if (typeof newValue !== 'object' || (typeof newValue === 'object' && typeof newValue.icon !== 'string'))
216
+ throw new Error(`<${this.name}> prop "icon" must match MgItemMore['icon'] type.`);
217
+ }
218
+ validateSlotLabel(newValue) {
219
+ if (typeof newValue !== 'object' || (typeof newValue === 'object' && typeof newValue.display !== 'boolean'))
220
+ throw new Error(`<${this.name}> prop "slotlabel" must match MgItemMore['slotlabel'] type.`);
221
+ else if (typeof newValue.label !== 'string')
222
+ this.slotlabel.label = this.messages.moreLabel;
223
+ }
224
+ validateSize(newValue) {
225
+ if (newValue && typeof newValue !== 'string')
226
+ throw new Error(`<${this.name}> prop "size" must match MgItemMore['size'] type.`);
227
+ }
228
+ /*************
229
+ * Lifecycle *
230
+ *************/
231
+ /**
232
+ * Disconnect overflow ResizeObserver
233
+ *
234
+ * @returns {void} run overflow resize obeserver disconnexion
235
+ */
236
+ disconnectedCallback() {
237
+ this.overflowBehavior.disconnect();
238
+ }
239
+ /**
240
+ * Set variables and validate props
241
+ *
242
+ * @returns {void}
243
+ */
244
+ componentWillLoad() {
245
+ // init variables
246
+ this.messages = initLocales(this.element).messages.plusMenu;
247
+ this.parentMenu = this.element.closest('mg-menu');
248
+ this.menuItems = Array.from(this.parentMenu.children).filter(item => item.nodeName === 'MG-MENU-ITEM');
249
+ // validate props
250
+ this.validateIcon(this.icon);
251
+ this.validateSlotLabel(this.slotlabel);
252
+ this.validateSize(this.size);
253
+ }
254
+ /**
255
+ * Add overflow behavior
256
+ *
257
+ * @returns {void}
258
+ */
259
+ componentDidLoad() {
260
+ this.overflowBehavior = new OverflowBehavior(this.parentMenu, this.renderMgMenuItemOverflowElement);
261
+ }
262
+ /**
263
+ * Render
264
+ *
265
+ * @returns {HTMLElement} HTML Element
266
+ */
267
+ render() {
268
+ return (h(Host, { role: "menuitem", "aria-haspopup": "true" }, h("mg-menu-item", { "data-overflow-more": true, "data-size": this.parentMenu.size }, h("mg-icon", { icon: this.icon.icon, slot: "image" }), h("span", { class: { 'sr-only': !this.slotlabel.display }, slot: "label" }, this.slotlabel.label), h("mg-menu", { direction: Direction.VERTICAL, label: this.messages.moreLabel, size: this.size }))));
269
+ }
270
+ get element() { return this; }
271
+ static get watchers() { return {
272
+ "icon": ["validateIcon"],
273
+ "slotlabel": ["validateSlotLabel"],
274
+ "size": ["validateSize"]
275
+ }; }
276
+ static get style() { return mgItemMoreCss; }
277
+ }, [1, "mg-item-more", {
278
+ "icon": [16],
279
+ "slotlabel": [16],
280
+ "size": [1],
281
+ "parentMenu": [32]
282
+ }]);
283
+ function defineCustomElement$1() {
284
+ if (typeof customElements === "undefined") {
285
+ return;
286
+ }
287
+ const components = ["mg-item-more", "mg-badge", "mg-button", "mg-card", "mg-icon", "mg-menu", "mg-menu-item", "mg-popover"];
288
+ components.forEach(tagName => { switch (tagName) {
289
+ case "mg-item-more":
290
+ if (!customElements.get(tagName)) {
291
+ customElements.define(tagName, MgItemMore$1);
292
+ }
293
+ break;
294
+ case "mg-badge":
295
+ if (!customElements.get(tagName)) {
296
+ defineCustomElement$8();
297
+ }
298
+ break;
299
+ case "mg-button":
300
+ if (!customElements.get(tagName)) {
301
+ defineCustomElement$7();
302
+ }
303
+ break;
304
+ case "mg-card":
305
+ if (!customElements.get(tagName)) {
306
+ defineCustomElement$6();
307
+ }
308
+ break;
309
+ case "mg-icon":
310
+ if (!customElements.get(tagName)) {
311
+ defineCustomElement$5();
312
+ }
313
+ break;
314
+ case "mg-menu":
315
+ if (!customElements.get(tagName)) {
316
+ defineCustomElement$4();
317
+ }
318
+ break;
319
+ case "mg-menu-item":
320
+ if (!customElements.get(tagName)) {
321
+ defineCustomElement$3();
322
+ }
323
+ break;
324
+ case "mg-popover":
325
+ if (!customElements.get(tagName)) {
326
+ defineCustomElement$2();
327
+ }
328
+ break;
329
+ } });
330
+ }
331
+ defineCustomElement$1();
332
+
333
+ const MgItemMore = MgItemMore$1;
334
+ const defineCustomElement = defineCustomElement$1;
335
+
336
+ export { MgItemMore, defineCustomElement };