@mgdis/mg-components 6.19.0 → 6.21.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 (164) hide show
  1. package/dist/cjs/{index-Bp6wZzau.js → index-C2viYwrR.js} +1757 -80
  2. package/dist/cjs/{index-TUElr4Wv.js → index-CCsGMNyq.js} +46 -0
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/mg-action-more_37.cjs.entry.js +735 -337
  5. package/dist/cjs/mg-alert.cjs.entry.js +17 -9
  6. package/dist/cjs/mg-components.cjs.js +3 -3
  7. package/dist/cjs/mg-fieldset.cjs.entry.js +24 -7
  8. package/dist/cjs/mg-input-combobox.cjs.entry.js +63 -29
  9. package/dist/cjs/mg-input-file.cjs.entry.js +384 -0
  10. package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js +30 -18
  11. package/dist/cjs/{mg-input.conf-D7jmj_lh.js → mg-input.conf-BNpeATnq.js} +7 -0
  12. package/dist/cjs/mg-loader.cjs.entry.js +8 -6
  13. package/dist/cjs/mg-progress.cjs.entry.js +19 -9
  14. package/dist/collection/collection-manifest.json +3 -2
  15. package/dist/collection/components/atoms/mg-icon/mg-icon.js +1 -1
  16. package/dist/collection/components/molecules/inputs/mg-input/mg-input.conf.js +6 -0
  17. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox-paginated/mg-input-checkbox-paginated.js +1 -1
  18. package/dist/collection/components/molecules/inputs/mg-input-combobox/mg-input-combobox.js +15 -11
  19. package/dist/collection/components/molecules/inputs/mg-input-file/mg-input-file.js +877 -0
  20. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +1 -1
  21. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +1 -1
  22. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
  23. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js +12 -12
  24. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +1 -1
  25. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +2 -2
  26. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
  27. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +72 -84
  28. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +1 -1
  29. package/dist/collection/components/molecules/mg-alert/mg-alert.js +1 -1
  30. package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
  31. package/dist/collection/components/molecules/mg-fieldset/mg-fieldset.js +12 -3
  32. package/dist/collection/components/molecules/mg-form/mg-form.js +12 -2
  33. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -1
  34. package/dist/collection/components/molecules/mg-loader/mg-loader.js +1 -1
  35. package/dist/collection/components/molecules/mg-message/mg-message.js +2 -2
  36. package/dist/collection/components/molecules/mg-modal/mg-modal.js +2 -2
  37. package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
  38. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
  39. package/dist/collection/components/molecules/mg-popover/mg-popover.js +1 -1
  40. package/dist/collection/components/molecules/mg-progress/mg-progress.js +1 -1
  41. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
  42. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +1 -1
  43. package/dist/collection/locales/en/messages.json +11 -0
  44. package/dist/collection/locales/fr/messages.json +11 -0
  45. package/dist/components/events.utils.js +1 -23
  46. package/dist/components/index.d.ts +2 -0
  47. package/dist/components/index.js +1 -1
  48. package/dist/components/index2.js +1 -408
  49. package/dist/components/index3.js +1 -476
  50. package/dist/components/mg-action-more.js +1 -254
  51. package/dist/components/mg-alert.js +1 -224
  52. package/dist/components/mg-badge.js +1 -6
  53. package/dist/components/mg-badge2.js +1 -113
  54. package/dist/components/mg-button.js +1 -6
  55. package/dist/components/mg-button2.js +1 -275
  56. package/dist/components/mg-card.js +1 -6
  57. package/dist/components/mg-card2.js +1 -92
  58. package/dist/components/mg-character-left.js +1 -6
  59. package/dist/components/mg-character-left2.js +1 -75
  60. package/dist/components/mg-details.js +1 -104
  61. package/dist/components/mg-divider.js +1 -6
  62. package/dist/components/mg-divider2.js +1 -49
  63. package/dist/components/mg-fieldset.js +1 -209
  64. package/dist/components/mg-form.js +1 -302
  65. package/dist/components/mg-icon.js +1 -6
  66. package/dist/components/mg-icon2.js +1 -188
  67. package/dist/components/mg-illustrated-message.js +1 -129
  68. package/dist/components/mg-input-checkbox-paginated.js +1 -6
  69. package/dist/components/mg-input-checkbox-paginated2.js +1 -135
  70. package/dist/components/mg-input-checkbox.js +1 -762
  71. package/dist/components/mg-input-combobox.js +1 -936
  72. package/dist/components/mg-input-date.js +1 -463
  73. package/dist/components/mg-input-file.d.ts +11 -0
  74. package/dist/components/mg-input-file.js +1 -0
  75. package/dist/components/mg-input-numeric.js +1 -592
  76. package/dist/components/mg-input-password.js +1 -360
  77. package/dist/components/mg-input-radio.js +1 -392
  78. package/dist/components/mg-input-rich-text-editor.js +1 -16797
  79. package/dist/components/mg-input-select.js +1 -6
  80. package/dist/components/mg-input-select2.js +1 -481
  81. package/dist/components/mg-input-text.js +1 -6
  82. package/dist/components/mg-input-text2.js +1 -514
  83. package/dist/components/mg-input-textarea.js +1 -412
  84. package/dist/components/mg-input-title.js +1 -6
  85. package/dist/components/mg-input-title2.js +1 -81
  86. package/dist/components/mg-input-toggle.js +1 -386
  87. package/dist/components/mg-input.conf.js +1 -0
  88. package/dist/components/mg-input.js +1 -6
  89. package/dist/components/mg-input2.js +1 -459
  90. package/dist/components/mg-item-more.js +1 -6
  91. package/dist/components/mg-item-more2.js +1 -505
  92. package/dist/components/mg-loader.js +1 -6
  93. package/dist/components/mg-loader2.js +1 -74
  94. package/dist/components/mg-menu-item.js +1 -6
  95. package/dist/components/mg-menu-item2.js +1 -485
  96. package/dist/components/mg-menu.js +1 -6
  97. package/dist/components/mg-message.js +1 -6
  98. package/dist/components/mg-message2.js +1 -146
  99. package/dist/components/mg-modal.js +1 -184
  100. package/dist/components/mg-pagination.js +1 -234
  101. package/dist/components/mg-panel.js +1 -350
  102. package/dist/components/mg-popover-content.js +1 -6
  103. package/dist/components/mg-popover-content2.js +1 -96
  104. package/dist/components/mg-popover.js +1 -6
  105. package/dist/components/mg-popover2.js +1 -312
  106. package/dist/components/mg-progress.js +1 -123
  107. package/dist/components/mg-skip-links.js +1 -78
  108. package/dist/components/mg-table.js +1 -319
  109. package/dist/components/mg-tabs.js +1 -6
  110. package/dist/components/mg-tabs2.js +1 -315
  111. package/dist/components/mg-tag.js +1 -133
  112. package/dist/components/mg-tooltip-content.js +1 -6
  113. package/dist/components/mg-tooltip-content2.js +1 -42
  114. package/dist/components/mg-tooltip.js +1 -6
  115. package/dist/components/mg-tooltip2.js +1 -421
  116. package/dist/components/popper.js +1 -1790
  117. package/dist/esm/{index-CNX6lq0x.js → index-D-uaxCxH.js} +46 -1
  118. package/dist/esm/{index-BluNKQ3L.js → index-DFwaH2hS.js} +1757 -80
  119. package/dist/esm/loader.js +3 -3
  120. package/dist/esm/mg-action-more_37.entry.js +735 -337
  121. package/dist/esm/mg-alert.entry.js +17 -9
  122. package/dist/esm/mg-components.js +4 -4
  123. package/dist/esm/mg-fieldset.entry.js +24 -7
  124. package/dist/esm/mg-input-combobox.entry.js +63 -29
  125. package/dist/esm/mg-input-file.entry.js +382 -0
  126. package/dist/esm/mg-input-rich-text-editor.entry.js +30 -18
  127. package/dist/esm/{mg-input.conf-DDnrE1hD.js → mg-input.conf-C9rmNQIL.js} +7 -1
  128. package/dist/esm/mg-loader.entry.js +8 -6
  129. package/dist/esm/mg-progress.entry.js +19 -9
  130. package/dist/mg-components/locales/en/messages.json +11 -0
  131. package/dist/mg-components/locales/fr/messages.json +11 -0
  132. package/dist/mg-components/mg-components.esm.js +1 -1
  133. package/dist/mg-components/{p-d5a276eb.entry.js → p-08fa327b.entry.js} +1 -1
  134. package/dist/mg-components/p-4175dcbe.entry.js +1 -0
  135. package/dist/mg-components/p-6b57f249.entry.js +1 -0
  136. package/dist/mg-components/p-6b655830.entry.js +1 -0
  137. package/dist/mg-components/p-988c282e.entry.js +1 -0
  138. package/dist/mg-components/p-C9rmNQIL.js +1 -0
  139. package/dist/mg-components/p-D-uaxCxH.js +1 -0
  140. package/dist/mg-components/p-DFwaH2hS.js +2 -0
  141. package/dist/mg-components/p-a79b1f19.entry.js +1 -0
  142. package/dist/mg-components/{p-916dfb6d.entry.js → p-c3d116b9.entry.js} +1 -1
  143. package/dist/mg-components/p-dd1934f4.entry.js +1 -0
  144. package/dist/types/components/molecules/inputs/mg-input/mg-input.conf.d.ts +7 -1
  145. package/dist/types/components/molecules/inputs/mg-input-file/mg-input-file.d.ts +210 -0
  146. package/dist/types/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.d.ts +4 -4
  147. package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +13 -16
  148. package/dist/types/components.d.ts +217 -18
  149. package/dist/types/stencil-public-runtime.d.ts +76 -12
  150. package/ide/intellij/web-types.json +373 -26
  151. package/ide/vscode/css-custom-data.json +12 -0
  152. package/ide/vscode/html-custom-data.json +341 -79
  153. package/package.json +22 -22
  154. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/editor.scss +0 -1
  155. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.conf.js +0 -1
  156. package/dist/mg-components/p-016bd291.entry.js +0 -1
  157. package/dist/mg-components/p-186a6139.entry.js +0 -1
  158. package/dist/mg-components/p-66a1cb83.entry.js +0 -1
  159. package/dist/mg-components/p-6efd819f.entry.js +0 -1
  160. package/dist/mg-components/p-BluNKQ3L.js +0 -2
  161. package/dist/mg-components/p-CNX6lq0x.js +0 -1
  162. package/dist/mg-components/p-DDnrE1hD.js +0 -1
  163. package/dist/mg-components/p-d2c72f09.entry.js +0 -1
  164. package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.conf.d.ts +0 -8
@@ -1,936 +1 @@
1
- import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
- import { P as Paginate, C as ClassList, t as toString, e as Cursor, n as nextTick, h as Page, j as getObjectValueFromKey, d as allItemsAreString, i as isValidString, k as isObject, f as formatID } from './index2.js';
3
- import { d as defineCustomElement$8, c as classReadonly, a as classDisabled, w as widths } from './mg-input2.js';
4
- import { i as initLocales } from './index3.js';
5
- import { K as Keys } from './events.utils.js';
6
- import { d as defineCustomElement$b } from './mg-button2.js';
7
- import { d as defineCustomElement$a } from './mg-card2.js';
8
- import { d as defineCustomElement$9 } from './mg-icon2.js';
9
- import { d as defineCustomElement$7 } from './mg-input-title2.js';
10
- import { d as defineCustomElement$6 } from './mg-loader2.js';
11
- import { d as defineCustomElement$5 } from './mg-popover2.js';
12
- import { d as defineCustomElement$4 } from './mg-popover-content2.js';
13
- import { d as defineCustomElement$3 } from './mg-tooltip2.js';
14
- import { d as defineCustomElement$2 } from './mg-tooltip-content2.js';
15
-
16
- const mgInputComboboxCss = ".mg-c-input__box{height:var(--mg-b-size-min-height);box-sizing:border-box;padding:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2) var(--mg-b-size-8);border-width:var(--mg-c-input-border-width);border-style:solid;border-color:var(--mg-c-input-color-border);border-radius:var(--mg-c-input-border-radius);background-color:var(--mg-b-color-light);color:var(--mg-b-color-dark);font-family:inherit;font-size:var(--mg-b-font-size);text-align:var(--mg-c-input-text-align, left)}.mg-c-input__box::placeholder{color:var(--mg-c-input-placeholder-color-text);font-style:italic}.mg-c-input__box:focus{box-shadow:0 0 var(--mg-b-size-4) var(--mg-c-input-color-box-shadow-focus)}.mg-c-input__box:disabled{opacity:var(--mg-b-opacity-element-disabled)}.mg-c-input.mg-c-input--has-error .mg-c-input__box{border-color:var(--mg-b-color-danger)}.mg-c-input.mg-c-input--is-input-group-append{--mg-c-button-border-radius-top-left:0;--mg-c-button-border-radius-bottom-left:0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box{margin-right:calc(-1*var(--mg-b-size-border));border-bottom-right-radius:0;border-top-right-radius:0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box:focus-visible{outline-offset:-0.2rem;outline-style:solid;outline-width:.2rem}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-c-button-border-radius-top-right:0;--mg-c-button-border-radius-bottom-right:0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-c-button-border-right-width:0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-c-button-border-radius-top-right:var(--mg-c-input-border-radius);--mg-c-button-border-radius-bottom-right:var(--mg-c-input-border-radius)}.mg-c-input.mg-c-input--is-append-input-slot-content:not(.mg-c-input--readonly) ::slotted([slot=append-input]){align-self:start;padding-top:calc((var(--mg-b-size-min-height) - var(--mg-b-size-16))/2)}.mg-c-input.mg-c-input--has-icon .mg-c-input__input-group-container{position:relative}.mg-c-input.mg-c-input--has-icon .mg-c-input__input-group-container>mg-icon:first-of-type{position:absolute;top:50%;left:var(--mg-b-size-8);color:var(--mg-c-input-color-icon);transform:translateY(-50%)}.mg-c-input.mg-c-input--has-icon .mg-c-input__input-group-container .mg-c-input__box{padding-left:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2)}.mg-c-input__popover-info{padding:var(--mg-b-size-8);margin:0;color:var(--mg-b-color-neutral-90);text-align:center}.mg-c-input__input-container{width:100%;flex:1 auto}.mg-c-input.mg-c-input--width-full .mg-c-input__box{width:100%}.mg-c-input.mg-c-input--width-full .mg-c-input__input-group-container{width:100%;flex-grow:1}.mg-c-input.mg-c-input--width-2.mg-c-input--display-character-left .mg-c-input__input-group-container,.mg-c-input.mg-c-input--width-4.mg-c-input--display-character-left .mg-c-input__input-group-container,.mg-c-input.mg-c-input--width-16.mg-c-input--display-character-left .mg-c-input__input-group-container{width:max-content}.mg-c-input.mg-c-input--width-2 .mg-c-input__box{width:var(--mg-b-size-48)}.mg-c-input.mg-c-input--width-2.mg-c-input--text.mg-c-input--display-character-left .mg-c-input__box{width:calc(var(--mg-b-size-48) + var(--mg-c-character-left-message-length)*(.35ch + .3rem))}.mg-c-input.mg-c-input--width-4 .mg-c-input__box{width:var(--mg-b-size-72)}.mg-c-input.mg-c-input--width-4.mg-c-input--text.mg-c-input--display-character-left .mg-c-input__box{width:calc(var(--mg-b-size-72) + var(--mg-c-character-left-message-length)*(.35ch + .3rem))}.mg-c-input.mg-c-input--width-16 .mg-c-input__box{width:calc(26*var(--mg-b-size-8))}.mg-c-input.mg-c-input--width-16.mg-c-input--text.mg-c-input--display-character-left .mg-c-input__box{width:calc(calc(26 * var(--mg-b-size-8)) + var(--mg-c-character-left-message-length)*(.35ch + .3rem))}.mg-c-input.mg-c-input--width-full:not(.mg-c-input--label-on-top){justify-content:stretch}.mg-c-input.mg-c-input--is-input-group-append ::slotted([slot=append-input]),.mg-c-input.mg-c-input--is-append-input-slot-content ::slotted([slot=append-input]){width:auto}:host(.mg-c-input.mg-c-input--width-full) ::slotted(*:not(mg-input-title)){width:100%;max-width:100%}.mg-c-input__readonly-value{min-height:var(--mg-b-font-size);align-self:flex-start;margin-top:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2);overflow-wrap:anywhere}.mg-u-visually-hidden{position:absolute !important;overflow:hidden !important;width:.1rem !important;height:.1rem !important;padding:0 !important;border:0 !important;margin:-0.1rem !important;clip:rect(0.1rem, 0.1rem, 0.1rem, 0.1rem) !important;clip-path:inset(50%) !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media (prefers-reduced-motion){*{animation:none !important;transition:none !important}}a{color:inherit;text-decoration:underline}a:hover,a:focus,a:active{text-decoration:none}.mg-c-input.mg-c-input--combobox mg-popover{--mg-c-card-overflow:hidden;--mg-c-popover-padding-vertical:0;--mg-c-popover-padding-horizontal:0}.mg-c-input.mg-c-input--combobox .mg-c-input__input-group-container{position:relative}.mg-c-input.mg-c-input--combobox .mg-c-input__box{cursor:pointer}.mg-c-input.mg-c-input--combobox .mg-c-input__popover-container{display:flex;min-width:var(--mg-c-input-list-width);max-height:calc(50*var(--mg-b-size-8) - var(--mg-b-size-32));flex-direction:column;gap:var(--mg-b-size-4);overflow-y:scroll}.mg-c-input.mg-c-input--combobox .mg-c-input__load-more{padding:0 var(--mg-b-size-8) var(--mg-b-size-4)}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list{padding:0;margin:0;cursor:pointer;list-style:none}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item{display:flex;padding:var(--mg-b-size-8)}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item:hover,.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item.mg-c-input__input-list-item--focus-visible{background-color:var(--mg-b-color-neutral-20)}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item.mg-c-input__input-list-item--selected{font-weight:700}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item.mg-c-input__input-list-item--selected mg-icon{margin-left:auto}.mg-c-input.mg-c-input--combobox.mg-c-input--width-2 .mg-c-input__box{width:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2 + var(--mg-b-size-24) + var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-4 .mg-c-input__box{width:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2 + var(--mg-b-size-48) + var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-16 .mg-c-input__box{width:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2 + calc(23 * var(--mg-b-size-8)) + var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-full mg-popover{--mg-c-popover-max-width:var(--mg-c-input-list-width, var(--mg-c-popover-max-width))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-full .mg-c-input__input-group-container{display:flex;width:100%}.mg-c-input.mg-c-input--combobox.mg-c-input--width-full .mg-c-input__box{flex:1}.mg-c-input.mg-c-input--combobox.mg-c-input--input-append .mg-c-input__box{padding-right:calc(var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--input-append .mg-c-input__box-append{position:absolute;top:0;right:0}";
17
-
18
- /**
19
- * Check if object is an item
20
- * @param item - object to check
21
- * @returns True if object is an item
22
- */
23
- const isItem = (item) => item && typeof item === 'object' && typeof item.title === 'string' && item.value !== undefined;
24
- /**
25
- * Check if objects are items
26
- * @param items - items to check
27
- * @returns True if objects are items
28
- */
29
- const isItems = (items) => Array.isArray(items) && items.every(isItem);
30
- /**
31
- * Check if object is valid combobox fetchmappings
32
- * @param value - to validate
33
- * @returns truthy if mapping is valid
34
- */
35
- const isFetchmappings = (value) => {
36
- const isValidRoot = isObject(value) && Object.hasOwn(value, 'request') && Object.hasOwn(value, 'response');
37
- if (isValidRoot) {
38
- const { request, response } = value;
39
- if ([request, response].some(property => !isObject(property)))
40
- return false;
41
- const isValidRequest = typeof request.filter === 'string' && (request.filterTransform === undefined || typeof request.filterTransform === 'function');
42
- const isValidResponse = typeof response === 'object' &&
43
- typeof response.total === 'string' &&
44
- typeof response.items === 'string' &&
45
- typeof response.next === 'string' &&
46
- typeof response.itemTitle === 'string' &&
47
- (typeof response.itemValue === 'string' || response.itemValue === undefined);
48
- return isValidRequest && isValidResponse;
49
- }
50
- else {
51
- return isValidRoot;
52
- }
53
- };
54
- const MgInputCombobox$1 = /*@__PURE__*/ proxyCustomElement(class MgInputCombobox extends HTMLElement {
55
- constructor(registerHost) {
56
- super();
57
- if (registerHost !== false) {
58
- this.__registerHost();
59
- }
60
- this.__attachShadow();
61
- this.valueChange = createEvent(this, "value-change", 7);
62
- this.filterChange = createEvent(this, "filter-change", 7);
63
- this.showMore = createEvent(this, "load-more", 7);
64
- this.inputValid = createEvent(this, "input-valid", 7);
65
- this.fetchError = createEvent(this, "fetch-error", 7);
66
- // hasDisplayedError (triggered by blur event)
67
- this.hasDisplayedError = false;
68
- this.customErrorMessage = { lock: false };
69
- /**
70
- * Input name
71
- * If not set the value equals the identifier
72
- */
73
- this.name = this.identifier;
74
- /**
75
- * Define if label is displayed on top
76
- */
77
- this.labelOnTop = false;
78
- /**
79
- * Define if label is visible
80
- */
81
- this.labelHide = false;
82
- /**
83
- * Define if input is required
84
- */
85
- this.required = false;
86
- /**
87
- * Define if input is readonly
88
- */
89
- this.readonly = false;
90
- /**
91
- * Define if input is disabled
92
- */
93
- this.disabled = false;
94
- /**
95
- * Define input width
96
- */
97
- this.mgWidth = 'full';
98
- /**
99
- * Define tooltip position
100
- */
101
- this.tooltipPosition = 'input';
102
- /**
103
- * Formated items for display
104
- */
105
- this.options = new Paginate([]);
106
- /**
107
- * Option filter
108
- */
109
- this.filter = '';
110
- /**
111
- * Component classes
112
- */
113
- this.classCollection = new ClassList(['mg-c-input--combobox', 'mg-c-input--has-icon', 'mg-c-input--input-append']);
114
- /**
115
- * Popover display state
116
- */
117
- this.popoverDisplay = false;
118
- /**
119
- * Handle `click` event on option
120
- * @param event - option element click event
121
- */
122
- this.handleOptionClick = (event) => {
123
- this.setValue(this.options.items.find(option => toString(option.value) === event.target.dataset.value));
124
- this.popoverDisplay = false;
125
- };
126
- /**
127
- * Handle `click` event on reset button
128
- * @param event - click event
129
- */
130
- this.handleResetButton = (event) => {
131
- event.stopPropagation();
132
- this.reset().then(() => {
133
- this.input.focus();
134
- });
135
- };
136
- /**
137
- * Handle `display-change` event on mg-popover
138
- */
139
- this.handlePopoverDisplay = (event) => {
140
- this.popoverDisplay = event.detail;
141
- };
142
- /**
143
- * Handle input event
144
- */
145
- this.handleFilterInput = () => {
146
- this.checkValidity();
147
- if (this.hasDisplayedError)
148
- this.setErrorMessage();
149
- if (!this.popoverDisplay)
150
- this.popoverDisplay = true;
151
- // update filter with debounce to prevent filter update overload
152
- if (!this.debounce) {
153
- this.debounce = true;
154
- setTimeout(() => {
155
- this.filter = this.input.value;
156
- this.debounce = false;
157
- }, 250);
158
- }
159
- };
160
- /**
161
- * Handle `blur` event
162
- */
163
- this.handleFilterBlur = () => {
164
- // skip process if popover is displayed
165
- if (this.popoverDisplay)
166
- return;
167
- // Display Error
168
- this.handlerInProgress = 'blur';
169
- this.displayError().finally(() => {
170
- // reset guard
171
- this.handlerInProgress = undefined;
172
- });
173
- };
174
- /**
175
- * Handle `focus` event
176
- */
177
- this.handleFilterFocus = () => {
178
- // ensure visual focus is always clear on focus when component isn't in loading state
179
- if (!this.isLoading) {
180
- this.option = null;
181
- }
182
- };
183
- /**
184
- * Handle load-more <mg-button> `click`
185
- */
186
- this.handleLoadMoreButton = () => {
187
- this.loadingWrapper({ name: 'load-more', cursor: Cursor.NEXT }).then(() => {
188
- this.input.focus();
189
- });
190
- };
191
- /**
192
- * Handle `keypress` event
193
- * @param event - keyboard event
194
- */
195
- this.handleFilterKeydown = (event) => {
196
- var _a;
197
- if (this.disabled || event.ctrlKey || event.shiftKey)
198
- return;
199
- let guard = false;
200
- // override keys actions
201
- switch (event.key) {
202
- case Keys.TAB:
203
- case Keys.ENTER: {
204
- guard = event.key === Keys.ENTER;
205
- const option = (_a = this.option) !== null && _a !== void 0 ? _a : this.options.items.find(this.isCurrentOption);
206
- // Sets the value to the content of the focused option in the listbox.
207
- if (this.popoverDisplay) {
208
- this.setValue(option);
209
- }
210
- // Closes the popover.
211
- this.popoverDisplay = false;
212
- break;
213
- }
214
- case Keys.DOWN:
215
- case Keys.ARROWDOWN:
216
- case Keys.UP:
217
- case Keys.ARROWUP: {
218
- guard = true;
219
- if (this.isLoading || this.page.total === 0) {
220
- this.popoverDisplay = true;
221
- break;
222
- }
223
- if (Boolean(event.altKey) && [Keys.DOWN, Keys.ARROWDOWN].includes(event.key)) {
224
- // Opens the popover without moving focus or changing selection.
225
- this.popoverDisplay = true;
226
- break;
227
- }
228
- // define cursor
229
- let cursor;
230
- const isNavigationStart = this.popoverDisplay && isItem(this.option);
231
- if ([Keys.DOWN, Keys.ARROWDOWN].includes(event.key)) {
232
- // If the filter is not empty and the popover is displayed, moves visual focus to the first suggested value.
233
- // If the filter is empty and the popover is not displayed, opens the popover and moves visual focus to the first option.
234
- // Moves visual focus to the next option.
235
- // If visual focus is on the last option, moves visual focus to the first option.
236
- cursor = isNavigationStart ? Cursor.NEXT : Cursor.FIRST;
237
- }
238
- else if ([Keys.UP, Keys.ARROWUP].includes(event.key)) {
239
- // If the filter is not empty and the popover is displayed, moves visual focus to the last suggested value.
240
- // If the filter is empty, first opens the popover if it is not already displayed and then moves visual focus to the last option.
241
- // Moves visual focus to the previous option.
242
- // If visual focus is on the first option, moves visual focus to the last option.
243
- cursor = isNavigationStart ? Cursor.PREVIOUS : Cursor.LAST;
244
- }
245
- // update scroll and visual focused option in wrapper
246
- this.loadingWrapper({ name: 'scroll', cursor });
247
- // open popover
248
- this.popoverDisplay = true;
249
- break;
250
- }
251
- case Keys.LEFT:
252
- case Keys.ARROWLEFT:
253
- case Keys.HOME:
254
- case Keys.RIGHT:
255
- case Keys.ARROWRIGHT:
256
- case Keys.END: {
257
- // skip process if visual focus is not in popover
258
- if (!isItem(this.option))
259
- break;
260
- guard = true;
261
- // Remove visual focus from popover options
262
- this.option = null;
263
- let index;
264
- if (Keys.HOME === event.key) {
265
- // Moves visual focus to the textbox and places the editing cursor at the beginning of the field.
266
- index = 0;
267
- }
268
- else if (Keys.END === event.key) {
269
- // Moves visual focus to the textbox and places the editing cursor at the end of the field.
270
- index = this.filter.length;
271
- }
272
- if (typeof index === 'number') {
273
- this.input.setSelectionRange(index, index);
274
- }
275
- break;
276
- }
277
- case Keys.ESC:
278
- case Keys.ESCAPE: {
279
- guard = true;
280
- if (this.popoverDisplay) {
281
- // If the popover is displayed, closes it.
282
- this.popoverDisplay = false;
283
- }
284
- else {
285
- // If the popover is not displayed, clears the filter.
286
- this.setValue(null);
287
- this.filter = '';
288
- // Sets visual focus on the textbox.
289
- this.option = null;
290
- }
291
- break;
292
- }
293
- default: {
294
- // Remove visual focus from popover options
295
- this.option = null;
296
- break;
297
- }
298
- }
299
- if (guard) {
300
- event.stopPropagation();
301
- event.preventDefault();
302
- }
303
- };
304
- /**
305
- * Scroll to next option from cursor
306
- * @param index - targeted option index to scroll into
307
- */
308
- this.scrollToIndex = (index) => {
309
- // ensure we have an opened popover element on screen when the scrollIntiView is called
310
- requestAnimationFrame(() => {
311
- var _a;
312
- if (!this.popoverDisplay)
313
- return;
314
- (_a = this.element.shadowRoot.querySelector(`li:nth-of-type(${(index || 0) + this.page.baseIndex})`)) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'nearest' });
315
- });
316
- };
317
- /**
318
- * Is option the current value
319
- * @param option - option to match with
320
- * @returns true if option is the current value
321
- */
322
- this.isCurrentOption = (option) => (isItem(this.value) ? this.value.value : this.value) === option.value;
323
- /**
324
- * get value prop title
325
- * @returns value title
326
- */
327
- this.getValueTitle = () => {
328
- if (this.value && isItem(this.value))
329
- return this.value.title;
330
- else if (typeof this.value === 'string')
331
- return this.value;
332
- else
333
- return '';
334
- };
335
- /**
336
- * Check if input is valid
337
- */
338
- this.checkValidity = () => {
339
- this.setValidity(this.readonly || this.disabled || this.input.checkValidity());
340
- };
341
- /**
342
- * Set input error message
343
- * @param fromSetErrorContext - context come from `setError` method
344
- */
345
- this.setErrorMessage = (fromSetErrorContext = false) => {
346
- // Set error message
347
- this.errorMessage = undefined;
348
- if (!this.valid) {
349
- // Does have a new custom error message OR does have a custom error message locked
350
- if (fromSetErrorContext || (this.customErrorMessage.lock && this.customErrorMessage.message !== undefined)) {
351
- this.errorMessage = this.customErrorMessage.message;
352
- }
353
- // required
354
- else if (this.input.validity.valueMissing) {
355
- this.errorMessage = this.messages.errors.required;
356
- }
357
- }
358
- };
359
- /**
360
- * Get first page with filter applied
361
- * @returns first page with filter applied
362
- */
363
- this.getFirstPage = () => this.options.getPage(0, option => this.filter === '' || option.title.toLocaleLowerCase().includes(this.filter.toLocaleLowerCase()));
364
- /**
365
- * Loading wrapper with a given action
366
- * @param action - wrapped loading action
367
- * @returns promisified action
368
- */
369
- this.loadingWrapper = (action) => {
370
- var _a;
371
- let promise;
372
- let index;
373
- // cache initial loading action if not defined
374
- (_a = this.loadingAction) !== null && _a !== void 0 ? _a : (this.loadingAction = action.name);
375
- // update index
376
- if (Boolean(this.option) && this.loadingAction !== 'load-more') {
377
- index = this.page.items.findIndex(option => toString(option.value) === toString(this.option.value));
378
- }
379
- else if (this.loadingAction === 'load-more') {
380
- index = this.page.items.length - this.page.baseIndex;
381
- }
382
- // when action require a showMore we fetch the API else we report action to next tick
383
- // Set "Show more" if action match OR if next item not available in the current page
384
- if (action.name === 'load-more') {
385
- // wait for new element render and update scroll position
386
- // set component loading
387
- this.isLoading = true;
388
- promise = this.goToNextPage;
389
- }
390
- else if (action.cursor === Cursor.NEXT &&
391
- this.page.items.length <= this.page.total &&
392
- index + this.page.baseIndex === this.page.items.length &&
393
- index + this.page.baseIndex < this.page.total) {
394
- // trigger load-more from button to benefit from `disabled-on-click`
395
- this.loadMoreElement.click();
396
- return;
397
- }
398
- else if (action.name === 'scroll') {
399
- promise = nextTick;
400
- }
401
- else {
402
- promise = this.updatePage;
403
- }
404
- return promise()
405
- .then(() => {
406
- // parse full items list from options
407
- const options = this.filter === '' ? this.options.items : this.options.items.filter(option => option.title.includes(this.filter));
408
- // update visual focus
409
- if (action.name !== 'load-data') {
410
- index = this.page.getIndexFromCursor(action.cursor, this.loadingAction === 'load-more' && index >= 0 ? options[index] : this.option);
411
- }
412
- this.option = options[index];
413
- // update scroll position
414
- this.scrollToIndex(index);
415
- })
416
- .finally(() => {
417
- // reset loading after next render
418
- requestAnimationFrame(() => {
419
- this.isLoading = false;
420
- this.loadingAction = undefined;
421
- });
422
- });
423
- };
424
- /**
425
- * Go to next page
426
- * @returns promise
427
- */
428
- this.goToNextPage = () => {
429
- this.showMore.emit();
430
- if (this.fetchurl !== undefined) {
431
- return this.getOptions(typeof this.page.next === 'string' ? this.page.next : undefined).then(nextPage => {
432
- if (nextPage !== undefined) {
433
- // merge items from current page and next page
434
- const items = [...this.page.items, ...nextPage.items];
435
- // create new options pagination withe merged items
436
- this.options = new Paginate(items, { total: nextPage.total, next: nextPage.next, top: items.length });
437
- }
438
- });
439
- }
440
- else {
441
- return nextTick(() => {
442
- if (typeof this.page.next === 'function') {
443
- const nextPage = this.page.next();
444
- this.page = new Page(Object.assign(Object.assign({}, nextPage), { items: [...this.page.items, ...nextPage.items] }));
445
- }
446
- });
447
- }
448
- };
449
- /**
450
- * Go to next page
451
- * @returns promise
452
- */
453
- this.updatePage = async () => {
454
- if (this.fetchurl !== undefined) {
455
- return this.getOptions().then(page => {
456
- if (page !== undefined) {
457
- // reset current options pagination from API response
458
- this.options = new Paginate(page.items, { total: page.total, next: page.next, top: page.top });
459
- }
460
- });
461
- }
462
- else {
463
- this.page = this.getFirstPage();
464
- }
465
- };
466
- /**
467
- * Fetch request
468
- * @param url - to fetch
469
- * @returns new page from url
470
- */
471
- this.getOptions = async (url = this.fetchurl) => {
472
- // add text filter to url
473
- const filter = typeof this.fetchmappings.request.filterTransform === 'function' ? this.fetchmappings.request.filterTransform(this.filter) : this.filter;
474
- const updateUrl = (typeof url === 'string' ? url : url.toString()).replaceAll(this.fetchmappings.request.filter, encodeURIComponent(filter));
475
- try {
476
- const response = await fetch(updateUrl, this.fetchoptions);
477
- if (!response.ok) {
478
- this.fetchError.emit(new Error(`${response.status} - ${response.statusText}`));
479
- return;
480
- }
481
- const json = await response.json();
482
- const items = getObjectValueFromKey(json, this.fetchmappings.response.items).map((item) => {
483
- var _a;
484
- return ({
485
- title: getObjectValueFromKey(item, this.fetchmappings.response.itemTitle),
486
- value: (_a = getObjectValueFromKey(item, this.fetchmappings.response.itemValue)) !== null && _a !== void 0 ? _a : item,
487
- });
488
- });
489
- const total = Number(getObjectValueFromKey(json, this.fetchmappings.response.total, 0));
490
- let next = getObjectValueFromKey(json, this.fetchmappings.response.next);
491
- if (URL.canParse(updateUrl) && Boolean(next) && !URL.canParse(next)) {
492
- const previousUrl = new URL(updateUrl);
493
- if (previousUrl.pathname.endsWith(next.split('?')[0])) {
494
- next = new URL(next, previousUrl).toString();
495
- }
496
- }
497
- return { items, total, next, top: items.length };
498
- }
499
- catch (error) {
500
- this.fetchError.emit(error);
501
- }
502
- };
503
- }
504
- watchValue(newValue) {
505
- this.filter = this.getValueTitle();
506
- this.valueChange.emit(newValue);
507
- }
508
- watchItems(newValue) {
509
- if (this.fetchurl !== undefined && newValue === undefined) {
510
- // skip newValue check
511
- return;
512
- }
513
- else if (this.fetchurl !== undefined && newValue !== undefined) {
514
- throw new Error(`<mg-input-combobox> prop "items" values cannot be use with "fetchurl" prop defined. Passed value: ${toString(newValue)}.`);
515
- }
516
- // Empty options
517
- else if (Array.isArray(newValue) && newValue.length === 0) {
518
- this.options = new Paginate([]);
519
- }
520
- // String array
521
- else if (allItemsAreString(newValue)) {
522
- this.options = new Paginate(newValue.map(item => ({ title: item, value: item })), { total: newValue.length });
523
- }
524
- // Object array
525
- else if (isItems(newValue)) {
526
- this.options = new Paginate(newValue, { total: newValue.length });
527
- }
528
- else {
529
- throw new Error(`<mg-input-combobox> prop "items" values must be the same type, string or Option. Passed value: ${toString(newValue)}.`);
530
- }
531
- }
532
- watchIdentifier(newValue) {
533
- if (isValidString(newValue)) {
534
- this.popoverId = `${newValue}-popover`;
535
- this.element.dataset.mgPopoverGuard = this.popoverId;
536
- }
537
- }
538
- watchReadonly(newValue) {
539
- if (newValue)
540
- this.classCollection.add(classReadonly);
541
- else
542
- this.classCollection.delete(classReadonly);
543
- }
544
- watchValidityChange(newValue, _oldValue, prop) {
545
- if (this.input === undefined)
546
- return;
547
- this.input[prop] = newValue;
548
- this.checkValidity();
549
- if (this.hasDisplayedError) {
550
- this.setErrorMessage();
551
- this.hasDisplayedError = false;
552
- }
553
- }
554
- watchDisabled(newValue) {
555
- if (newValue) {
556
- this.classCollection.add(classDisabled);
557
- }
558
- else {
559
- this.classCollection.delete(classDisabled);
560
- }
561
- }
562
- watchMgWidth(newValue) {
563
- // reset width class
564
- widths.forEach(width => {
565
- this.classCollection.delete(`mg-c-input--width-${width}`);
566
- });
567
- // apply new width
568
- if (newValue !== undefined)
569
- this.classCollection.add(`mg-c-input--width-${this.mgWidth}`);
570
- this.classCollection = new ClassList(this.classCollection.classes);
571
- }
572
- watchFetchUrl(newValue) {
573
- if (newValue !== undefined) {
574
- this.loadingWrapper({ name: 'load-data' });
575
- }
576
- }
577
- watchFetchOptions(newValue) {
578
- if (this.fetchurl && newValue && !isObject(newValue)) {
579
- throw new Error(`<mg-input-combobox> prop "fetchoptions" value must be a valid RequestInit. Passed value: ${toString(newValue)}.`);
580
- }
581
- }
582
- watchFetchMappings(newValue) {
583
- if (this.fetchurl !== undefined && !isObject(newValue)) {
584
- throw new Error(`<mg-input-combobox> prop "fetchmappings" is required with "fetchurl" prop.`);
585
- }
586
- else if (newValue !== undefined && !isFetchmappings(newValue)) {
587
- throw new Error(`<mg-input-combobox> prop "fetchmappings" value must be { request: RequestMappingType, response: ResponseMappingType }. Passed value: ${toString(newValue)}.`);
588
- }
589
- }
590
- watchOptions() {
591
- this.page = this.getFirstPage();
592
- }
593
- watchFilter(newValue) {
594
- this.loadingWrapper({ name: 'load-data' });
595
- this.filterChange.emit(newValue);
596
- }
597
- watchPopoverDisplay(newValue) {
598
- if (newValue) {
599
- this.input.focus();
600
- }
601
- else {
602
- // remove visual focus
603
- this.option = null;
604
- // reset filter with value
605
- this.filter = this.getValueTitle();
606
- this.handlerInProgress = 'blur';
607
- this.displayError().finally(() => {
608
- // reset guard
609
- this.handlerInProgress = undefined;
610
- });
611
- }
612
- }
613
- /**
614
- * Set focus on input.
615
- */
616
- async setFocus() {
617
- var _a;
618
- (_a = this.input) === null || _a === void 0 ? void 0 : _a.focus();
619
- }
620
- /**
621
- * Display input error if it exists.
622
- */
623
- displayError() {
624
- // Use `Promise` as requested for stencil method
625
- // Use `requestAnimationFrame` to ensure:
626
- // - DOM is fully updated before validation
627
- // - Async operations are completed
628
- // - No timing issues with Stencil's render cycle
629
- // - Keep everything in sync both inside and outside the component
630
- return new Promise(resolve => {
631
- requestAnimationFrame(() => {
632
- this.checkValidity();
633
- this.setErrorMessage();
634
- this.hasDisplayedError = this.invalid;
635
- resolve();
636
- });
637
- });
638
- }
639
- /**
640
- * Set an error and display a custom error message.
641
- * This method can be used to set the component's error state from its concombobox by passing a boolean value to the `valid` parameter.
642
- * It must be paired with an error message to display for the given concombobox.
643
- * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
644
- * @param valid - value indicating the validity
645
- * @param errorMessage - the error message to display
646
- * @param errorMessageLock - lock the error message and validity state
647
- */
648
- async setError(valid, errorMessage, errorMessageLock = false) {
649
- if (typeof valid !== 'boolean') {
650
- throw new Error('<mg-input-combobox> method "setError()" param "valid" must be a boolean.');
651
- }
652
- else if (errorMessage !== undefined && !isValidString(errorMessage)) {
653
- throw new Error('<mg-input-combobox> method "setError()" param "errorMessage" must be a string.');
654
- }
655
- else {
656
- this.customErrorMessage = {
657
- lock: valid ? false : errorMessageLock,
658
- message: valid ? undefined : errorMessage,
659
- };
660
- this.setValidity(valid);
661
- this.setErrorMessage(true);
662
- this.hasDisplayedError = this.invalid;
663
- }
664
- }
665
- /**
666
- * Reset value, validity and error state
667
- */
668
- async reset() {
669
- if (!this.readonly) {
670
- this.setValue(null);
671
- this.option = null;
672
- this.filter = '';
673
- // Use `Promise` as requested for stencil method
674
- // Use `requestAnimationFrame` to ensure:
675
- // - DOM is fully updated before validation
676
- // - Async operations are completed
677
- // - No timing issues with Stencil's render cycle
678
- // - Keep everything in sync both inside and outside the component
679
- return new Promise(resolve => {
680
- requestAnimationFrame(() => {
681
- // unlock validity check by reseting customErrorMessage
682
- this.customErrorMessage = { lock: false };
683
- this.checkValidity();
684
- this.errorMessage = undefined;
685
- this.hasDisplayedError = false;
686
- resolve();
687
- });
688
- });
689
- }
690
- }
691
- /**
692
- * Set value prop
693
- * @param newValue - slected option item
694
- */
695
- setValue(newValue) {
696
- if (!isItem(newValue)) {
697
- this.value = '';
698
- }
699
- else if (allItemsAreString(this.items || this.options.items)) {
700
- this.value = newValue.title;
701
- }
702
- else {
703
- this.value = Object.assign({}, newValue);
704
- }
705
- }
706
- /**
707
- * Method to set validity values
708
- * @param newValue - valid new value
709
- */
710
- setValidity(newValue) {
711
- const oldValue = this.valid;
712
- if (!this.customErrorMessage.lock || (this.customErrorMessage.message !== undefined && !newValue)) {
713
- this.valid = newValue;
714
- }
715
- this.invalid = !this.valid;
716
- // We need to send valid event even if it is the same value
717
- if (this.handlerInProgress === undefined || (this.handlerInProgress === 'blur' && this.valid !== oldValue))
718
- this.inputValid.emit(this.valid);
719
- }
720
- /*************
721
- * Lifecycle *
722
- *************/
723
- /**
724
- * Check if component props are well configured on init
725
- * @returns timeout
726
- */
727
- componentWillLoad() {
728
- // Get locales
729
- this.messages = initLocales(this.element).messages;
730
- // Validate
731
- this.watchIdentifier(this.identifier);
732
- this.watchItems(this.items);
733
- if (this.fetchurl !== undefined) {
734
- this.watchFetchOptions(this.fetchoptions);
735
- this.watchFetchMappings(this.fetchmappings);
736
- this.loadingWrapper({ name: 'load-data' });
737
- }
738
- this.watchValue(this.value);
739
- this.watchOptions();
740
- this.watchMgWidth(this.mgWidth);
741
- this.watchReadonly(this.readonly);
742
- this.watchDisabled(this.disabled);
743
- // Check validity when component is ready
744
- // return a promise to process action only in the FIRST render().
745
- // https://stenciljs.com/docs/component-lifecycle#componentwillload
746
- return setTimeout(() => {
747
- this.checkValidity();
748
- }, 0);
749
- }
750
- /**
751
- * Render
752
- * @returns HTML Element
753
- */
754
- render() {
755
- var _a, _b, _c, _d, _e, _f;
756
- const listId = `${this.identifier}-list`;
757
- const readonlyValue = this.getValueTitle();
758
- const withResetButton = this.value && !this.disabled;
759
- let popoverContent;
760
- if (((_a = this.page) === null || _a === void 0 ? void 0 : _a.items.length) > 0) {
761
- popoverContent = 'list';
762
- }
763
- else if (((_b = this.page) === null || _b === void 0 ? void 0 : _b.items.length) === 0 && this.filter.length > 0) {
764
- popoverContent = 'notfound';
765
- }
766
- else if (((_c = this.page) === null || _c === void 0 ? void 0 : _c.items.length) === 0) {
767
- popoverContent = 'notavailable';
768
- }
769
- let activeDescendant;
770
- if (((_d = this.option) === null || _d === void 0 ? void 0 : _d.value) !== undefined) {
771
- activeDescendant = this.option.value;
772
- }
773
- else if (typeof this.value === 'string') {
774
- activeDescendant = this.value;
775
- }
776
- else {
777
- activeDescendant = (_e = this.value) === null || _e === void 0 ? void 0 : _e.value;
778
- }
779
- return (h("mg-input", { key: 'fd5a59f1e0bf31342a3bf935a60a2877e5df1772', label: this.label, identifier: this.identifier, class: this.classCollection.classes.join(' '), ariaDescribedbyIDs: popoverContent && popoverContent !== 'list' ? popoverContent : undefined, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, tooltip: this.tooltip, tooltipPosition: this.readonly && this.value === undefined ? 'label' : this.tooltipPosition, helpText: this.helpText, errorMessage: this.errorMessage }, this.readonly ? (readonlyValue && h("b", { class: "mg-c-input__readonly-value" }, readonlyValue)) : (h("mg-popover", { identifier: this.popoverId, placement: "bottom-start", display: this.popoverDisplay, "arrow-hide": true, style: {
780
- '--mg-c-input-list-width': ((_f = this.input) === null || _f === void 0 ? void 0 : _f.offsetWidth) > 0 ? `${this.input.offsetWidth}px` : undefined,
781
- }, "data-fallback-placement": "bottom-end", "onDisplay-change": this.handlePopoverDisplay }, h("div", { class: "mg-c-input__input-group-container" }, h("mg-icon", { icon: "magnifying-glass" }), h("input", { type: "text", role: "combobox", class: "mg-c-input__box mg-c-input__box--width", value: this.filter, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, autocomplete: "off", "aria-autocomplete": "list", "aria-expanded": this.popoverDisplay.toString(), "aria-controls": listId, "aria-invalid": (this.invalid === true).toString(), "aria-activedescendant": formatID(activeDescendant), onInput: this.handleFilterInput, onBlur: this.handleFilterBlur, onFocus: this.handleFilterFocus, onKeyDown: this.handleFilterKeydown, ref: (el) => {
782
- if (el !== null)
783
- this.input = el;
784
- } }), withResetButton ? (h("mg-button", { class: "mg-c-input__box-append mg-c-input__reset", variant: "flat", "is-icon": true, label: this.messages.general.reset, "aria-controls": this.identifier, tabindex: "-1", onClick: this.handleResetButton }, h("mg-icon", { icon: "cross" }))) : (h("mg-button", { class: "mg-c-input__box-append", variant: "flat", "is-icon": true, label: this.itemsLabel, tabindex: "-1", disabled: this.disabled }, h("mg-icon", { icon: `chevron-${this.popoverDisplay ? 'up' : 'down'}` })))), h("div", { slot: "content", class: "mg-c-input__popover-container" }, popoverContent === 'list' && [
785
- // eslint-disable-next-line jsx-a11y/role-supports-aria-props
786
- h("ul", { key: "list", class: "mg-c-input__input-list", role: "listbox", id: listId, "aria-label": this.itemsLabel, "aria-setsize": this.page.total }, this.page.items.map(option => {
787
- var _a;
788
- return (
789
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events
790
- h("li", { role: "option", class: {
791
- 'mg-c-input__input-list-item': true,
792
- 'mg-c-input__input-list-item--focus-visible': JSON.stringify((_a = this.option) === null || _a === void 0 ? void 0 : _a.value) === JSON.stringify(option.value),
793
- 'mg-c-input__input-list-item--selected': this.isCurrentOption(option),
794
- }, key: option.title, id: formatID(option.value), "aria-selected": this.isCurrentOption(option).toString(), "data-value": toString(option.value), onClick: this.handleOptionClick }, option.title, this.isCurrentOption(option) && h("mg-icon", { icon: "check" })));
795
- })),
796
- this.isLoading && h("mg-loader", { key: "loader", message: this.messages.input.combobox.search, class: { 'mg-u-visually-hidden': Boolean(this.page.next) } }),
797
- this.page.next && (h("mg-button", { key: "load-more", variant: "flat", class: "mg-c-input__load-more", tabIndex: -1, disabled: this.isLoading, "full-width": true, "disable-on-click": true, onClick: this.handleLoadMoreButton, "aria-controls": listId, ref: (el) => {
798
- if (el !== null)
799
- this.loadMoreElement = el;
800
- } }, h("mg-icon", { icon: "chevron-down" }), this.messages.input.showMore)),
801
- ], popoverContent === 'notfound' && (h("p", { id: popoverContent, class: "mg-c-input__popover-info" }, this.messages.input.combobox.notFound)), popoverContent === 'notavailable' && (h("p", { id: popoverContent, class: "mg-c-input__popover-info" }, this.messages.input.combobox.notAvailable)))))));
802
- }
803
- get element() { return this; }
804
- static get watchers() { return {
805
- "value": ["watchValue"],
806
- "items": ["watchItems"],
807
- "identifier": ["watchIdentifier"],
808
- "readonly": ["watchReadonly", "watchValidityChange"],
809
- "required": ["watchValidityChange"],
810
- "disabled": ["watchValidityChange", "watchDisabled"],
811
- "mgWidth": ["watchMgWidth"],
812
- "fetchurl": ["watchFetchUrl"],
813
- "fetchoptions": ["watchFetchOptions"],
814
- "fetchmappings": ["watchFetchMappings"],
815
- "options": ["watchOptions"],
816
- "filter": ["watchFilter"],
817
- "popoverDisplay": ["watchPopoverDisplay"]
818
- }; }
819
- static get style() { return mgInputComboboxCss; }
820
- }, [257, "mg-input-combobox", {
821
- "value": [1537],
822
- "items": [16],
823
- "itemsLabel": [1, "items-label"],
824
- "identifier": [1],
825
- "name": [1],
826
- "label": [1],
827
- "labelOnTop": [4, "label-on-top"],
828
- "labelHide": [4, "label-hide"],
829
- "placeholder": [1],
830
- "required": [4],
831
- "readonly": [4],
832
- "disabled": [4],
833
- "mgWidth": [8, "mg-width"],
834
- "tooltip": [1],
835
- "tooltipPosition": [1, "tooltip-position"],
836
- "helpText": [1, "help-text"],
837
- "fetchurl": [1],
838
- "fetchoptions": [16],
839
- "fetchmappings": [16],
840
- "valid": [1028],
841
- "invalid": [1028],
842
- "isLoading": [32],
843
- "options": [32],
844
- "option": [32],
845
- "filter": [32],
846
- "classCollection": [32],
847
- "errorMessage": [32],
848
- "popoverDisplay": [32],
849
- "setFocus": [64],
850
- "displayError": [64],
851
- "setError": [64],
852
- "reset": [64]
853
- }, undefined, {
854
- "value": ["watchValue"],
855
- "items": ["watchItems"],
856
- "identifier": ["watchIdentifier"],
857
- "readonly": ["watchReadonly", "watchValidityChange"],
858
- "required": ["watchValidityChange"],
859
- "disabled": ["watchValidityChange", "watchDisabled"],
860
- "mgWidth": ["watchMgWidth"],
861
- "fetchurl": ["watchFetchUrl"],
862
- "fetchoptions": ["watchFetchOptions"],
863
- "fetchmappings": ["watchFetchMappings"],
864
- "options": ["watchOptions"],
865
- "filter": ["watchFilter"],
866
- "popoverDisplay": ["watchPopoverDisplay"]
867
- }]);
868
- function defineCustomElement$1() {
869
- if (typeof customElements === "undefined") {
870
- return;
871
- }
872
- const components = ["mg-input-combobox", "mg-button", "mg-card", "mg-icon", "mg-input", "mg-input-title", "mg-loader", "mg-popover", "mg-popover-content", "mg-tooltip", "mg-tooltip-content"];
873
- components.forEach(tagName => { switch (tagName) {
874
- case "mg-input-combobox":
875
- if (!customElements.get(tagName)) {
876
- customElements.define(tagName, MgInputCombobox$1);
877
- }
878
- break;
879
- case "mg-button":
880
- if (!customElements.get(tagName)) {
881
- defineCustomElement$b();
882
- }
883
- break;
884
- case "mg-card":
885
- if (!customElements.get(tagName)) {
886
- defineCustomElement$a();
887
- }
888
- break;
889
- case "mg-icon":
890
- if (!customElements.get(tagName)) {
891
- defineCustomElement$9();
892
- }
893
- break;
894
- case "mg-input":
895
- if (!customElements.get(tagName)) {
896
- defineCustomElement$8();
897
- }
898
- break;
899
- case "mg-input-title":
900
- if (!customElements.get(tagName)) {
901
- defineCustomElement$7();
902
- }
903
- break;
904
- case "mg-loader":
905
- if (!customElements.get(tagName)) {
906
- defineCustomElement$6();
907
- }
908
- break;
909
- case "mg-popover":
910
- if (!customElements.get(tagName)) {
911
- defineCustomElement$5();
912
- }
913
- break;
914
- case "mg-popover-content":
915
- if (!customElements.get(tagName)) {
916
- defineCustomElement$4();
917
- }
918
- break;
919
- case "mg-tooltip":
920
- if (!customElements.get(tagName)) {
921
- defineCustomElement$3();
922
- }
923
- break;
924
- case "mg-tooltip-content":
925
- if (!customElements.get(tagName)) {
926
- defineCustomElement$2();
927
- }
928
- break;
929
- } });
930
- }
931
- defineCustomElement$1();
932
-
933
- const MgInputCombobox = MgInputCombobox$1;
934
- const defineCustomElement = defineCustomElement$1;
935
-
936
- export { MgInputCombobox, defineCustomElement };
1
+ import{transformTag as t,proxyCustomElement as i,HTMLElement as s,createEvent as o,h as e}from"@stencil/core/internal/client";import{P as n,C as a,t as r,e as c,n as h,h as p,j as m,d as l,i as u,k as g,f as d}from"./index2.js";import{c as b,b as v,w as f}from"./mg-input.conf.js";import{i as w}from"./index3.js";import{K as _}from"./events.utils.js";import{d as x}from"./mg-button2.js";import{d as y}from"./mg-card2.js";import{d as z}from"./mg-icon2.js";import{d as k}from"./mg-input2.js";import{d as E}from"./mg-input-title2.js";import{d as j}from"./mg-loader2.js";import{d as F}from"./mg-popover2.js";import{d as O}from"./mg-popover-content2.js";import{d as q}from"./mg-tooltip2.js";import{d as C}from"./mg-tooltip-content2.js";const D=t=>t&&"object"==typeof t&&"string"==typeof t.title&&void 0!==t.value,P=i(class extends s{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.valueChange=o(this,"value-change",7),this.filterChange=o(this,"filter-change",7),this.showMore=o(this,"load-more",7),this.inputValid=o(this,"input-valid",7),this.fetchError=o(this,"fetch-error",7),this.hasDisplayedError=!1,this.customErrorMessage={lock:!1},this.name=this.identifier,this.labelOnTop=!1,this.labelHide=!1,this.required=!1,this.readonly=!1,this.disabled=!1,this.mgWidth="full",this.tooltipPosition="input",this.options=new n([]),this.filter="",this.classCollection=new a(["mg-c-input--combobox","mg-c-input--has-icon","mg-c-input--input-append"]),this.popoverDisplay=!1,this.handleOptionClick=t=>{this.setValue(this.options.items.find((i=>r(i.value)===t.target.dataset.value))),this.popoverDisplay=!1},this.handleResetButton=t=>{t.stopPropagation(),this.reset().then((()=>{this.input.focus()}))},this.handlePopoverDisplay=t=>{this.popoverDisplay=t.detail},this.handleFilterInput=()=>{this.checkValidity(),this.hasDisplayedError&&this.setErrorMessage(),this.popoverDisplay||(this.popoverDisplay=!0),this.debounce||(this.debounce=!0,setTimeout((()=>{this.filter=this.input.value,this.debounce=!1}),250))},this.handleFilterBlur=t=>{this.popoverDisplay?(t.stopImmediatePropagation(),this.input.focus()):(this.handlerInProgress="blur",this.displayError().finally((()=>{this.handlerInProgress=void 0})))},this.handleFilterFocus=()=>{this.isLoading||(this.option=null)},this.handleLoadMoreButton=()=>{this.loadingWrapper({name:"load-more",cursor:c.NEXT}).then((()=>{this.input.focus()}))},this.handleFilterKeydown=t=>{var i;if(this.disabled||t.ctrlKey||t.shiftKey)return;let s=!1;switch(t.key){case _.TAB:case _.ENTER:{s=t.key===_.ENTER;const o=null!==(i=this.option)&&void 0!==i?i:this.options.items.find(this.isCurrentOption);this.popoverDisplay&&this.setValue(o),this.popoverDisplay=!1;break}case _.DOWN:case _.ARROWDOWN:case _.UP:case _.ARROWUP:{if(s=!0,this.isLoading||0===this.page.total){this.popoverDisplay=!0;break}if(t.altKey&&[_.DOWN,_.ARROWDOWN].includes(t.key)){this.popoverDisplay=!0;break}let i;const o=this.popoverDisplay&&D(this.option);[_.DOWN,_.ARROWDOWN].includes(t.key)?i=o?c.NEXT:c.FIRST:[_.UP,_.ARROWUP].includes(t.key)&&(i=o?c.PREVIOUS:c.LAST),this.loadingWrapper({name:"scroll",cursor:i}),this.popoverDisplay=!0;break}case _.LEFT:case _.ARROWLEFT:case _.HOME:case _.RIGHT:case _.ARROWRIGHT:case _.END:{if(!D(this.option))break;let i;s=!0,this.option=null,_.HOME===t.key?i=0:_.END===t.key&&(i=this.filter.length),"number"==typeof i&&this.input.setSelectionRange(i,i);break}case _.ESC:case _.ESCAPE:s=!0,this.popoverDisplay?this.popoverDisplay=!1:(this.setValue(null),this.filter="",this.option=null);break;default:this.option=null}s&&(t.stopPropagation(),t.preventDefault())},this.scrollToIndex=t=>{requestAnimationFrame((()=>{var i;this.popoverDisplay&&(null===(i=this.element.shadowRoot.querySelector(`li:nth-of-type(${(t||0)+this.page.baseIndex})`))||void 0===i||i.scrollIntoView({block:"nearest"}))}))},this.isCurrentOption=t=>(D(this.value)?this.value.value:this.value)===t.value,this.getValueTitle=()=>this.value&&D(this.value)?this.value.title:"string"==typeof this.value?this.value:"",this.checkValidity=()=>{this.setValidity(this.readonly||this.disabled||this.input.checkValidity())},this.setErrorMessage=(t=!1)=>{this.errorMessage=void 0,this.valid||(t||this.customErrorMessage.lock&&void 0!==this.customErrorMessage.message?this.errorMessage=this.customErrorMessage.message:this.input.validity.valueMissing&&(this.errorMessage=this.messages.errors.required))},this.getFirstPage=()=>this.options.getPage(0,(t=>""===this.filter||t.title.toLocaleLowerCase().includes(this.filter.toLocaleLowerCase()))),this.loadingWrapper=t=>{var i;let s,o;if(null!==(i=this.loadingAction)&&void 0!==i||(this.loadingAction=t.name),this.option&&"load-more"!==this.loadingAction?o=this.page.items.findIndex((t=>r(t.value)===r(this.option.value))):"load-more"===this.loadingAction&&(o=this.page.items.length-this.page.baseIndex),"load-more"===t.name)this.isLoading=!0,s=this.goToNextPage;else{if(t.cursor===c.NEXT&&this.page.items.length<=this.page.total&&o+this.page.baseIndex===this.page.items.length&&o+this.page.baseIndex<this.page.total)return void this.loadMoreElement.click();s="scroll"===t.name?h:this.updatePage}return s().then((()=>{const i=""===this.filter?this.options.items:this.options.items.filter((t=>t.title.includes(this.filter)));"load-data"!==t.name&&(o=this.page.getIndexFromCursor(t.cursor,"load-more"===this.loadingAction&&o>=0?i[o]:this.option)),this.option=i[o],this.scrollToIndex(o)})).finally((()=>{requestAnimationFrame((()=>{this.isLoading=!1,this.loadingAction=void 0}))}))},this.goToNextPage=()=>(this.showMore.emit(),void 0!==this.fetchurl?this.getOptions("string"==typeof this.page.next?this.page.next:void 0).then((t=>{if(void 0!==t){const i=[...this.page.items,...t.items];this.options=new n(i,{total:t.total,next:t.next,top:i.length})}})):h((()=>{if("function"==typeof this.page.next){const t=this.page.next();this.page=new p(Object.assign(Object.assign({},t),{items:[...this.page.items,...t.items]}))}}))),this.updatePage=async()=>{if(void 0!==this.fetchurl)return this.getOptions().then((t=>{void 0!==t&&(this.options=new n(t.items,{total:t.total,next:t.next,top:t.top}))}));this.page=this.getFirstPage()},this.getOptions=async(t=this.fetchurl)=>{const i="function"==typeof this.fetchmappings.request.filterTransform?this.fetchmappings.request.filterTransform(this.filter):this.filter,s=("string"==typeof t?t:""+t).replaceAll(this.fetchmappings.request.filter,encodeURIComponent(i));try{const t=await fetch(s,this.fetchoptions);if(!t.ok)return void this.fetchError.emit(Error(`${t.status} - ${t.statusText}`));const i=await t.json(),o=m(i,this.fetchmappings.response.items).map((t=>{var i;return{title:m(t,this.fetchmappings.response.itemTitle),value:null!==(i=m(t,this.fetchmappings.response.itemValue))&&void 0!==i?i:t}})),e=Number(m(i,this.fetchmappings.response.total,0));let n=m(i,this.fetchmappings.response.next);if(URL.canParse(s)&&n&&!URL.canParse(n)){const t=new URL(s);t.pathname.endsWith(n.split("?")[0])&&(n=""+new URL(n,t))}return{items:o,total:e,next:n,top:o.length}}catch(t){this.fetchError.emit(t)}}}watchValue(t){this.filter=this.getValueTitle(),this.valueChange.emit(t)}watchItems(t){if(void 0===this.fetchurl||void 0!==t){if(void 0!==this.fetchurl&&void 0!==t)throw Error(`<mg-input-combobox> prop "items" values cannot be use with "fetchurl" prop defined. Passed value: ${r(t)}.`);if(Array.isArray(t)&&0===t.length)this.options=new n([]);else if(l(t))this.options=new n(t.map((t=>({title:t,value:t}))),{total:t.length});else{if(!(t=>Array.isArray(t)&&t.every(D))(t))throw Error(`<mg-input-combobox> prop "items" values must be the same type, string or Option. Passed value: ${r(t)}.`);this.options=new n(t,{total:t.length})}}}watchIdentifier(t){u(t)&&(this.popoverId=t+"-popover",this.element.dataset.mgPopoverGuard=this.popoverId)}watchReadonly(t){t?this.classCollection.add(b):this.classCollection.delete(b)}watchValidityChange(t,i,s){void 0!==this.input&&(this.input[s]=t,this.checkValidity(),this.hasDisplayedError&&(this.setErrorMessage(),this.hasDisplayedError=!1))}watchDisabled(t){t?this.classCollection.add(v):this.classCollection.delete(v)}watchMgWidth(t){f.forEach((t=>{this.classCollection.delete("mg-c-input--width-"+t)})),void 0!==t&&this.classCollection.add("mg-c-input--width-"+this.mgWidth),this.classCollection=new a(this.classCollection.classes)}watchFetchUrl(t){void 0!==t&&this.loadingWrapper({name:"load-data"})}watchFetchOptions(t){if(this.fetchurl&&t&&!g(t))throw Error(`<mg-input-combobox> prop "fetchoptions" value must be a valid RequestInit. Passed value: ${r(t)}.`)}watchFetchMappings(t){if(void 0!==this.fetchurl&&!g(t))throw Error('<mg-input-combobox> prop "fetchmappings" is required with "fetchurl" prop.');if(void 0!==t&&!(t=>{const i=g(t)&&Object.hasOwn(t,"request")&&Object.hasOwn(t,"response");if(i){const{request:i,response:s}=t;return![i,s].some((t=>!g(t)))&&!("string"!=typeof i.filter||void 0!==i.filterTransform&&"function"!=typeof i.filterTransform||"object"!=typeof s||"string"!=typeof s.total||"string"!=typeof s.items||"string"!=typeof s.next||"string"!=typeof s.itemTitle||"string"!=typeof s.itemValue&&void 0!==s.itemValue)}return i})(t))throw Error(`<mg-input-combobox> prop "fetchmappings" value must be { request: RequestMappingType, response: ResponseMappingType }. Passed value: ${r(t)}.`)}watchOptions(){this.page=this.getFirstPage()}watchFilter(t){this.loadingWrapper({name:"load-data"}),this.filterChange.emit(t)}watchPopoverDisplay(t){t?this.input.focus():(this.option=null,this.filter=this.getValueTitle(),this.handlerInProgress="blur",this.displayError().finally((()=>{this.handlerInProgress=void 0})))}async setFocus(){var t;null===(t=this.input)||void 0===t||t.focus()}displayError(){return new Promise((t=>{requestAnimationFrame((()=>{this.checkValidity(),this.setErrorMessage(),this.hasDisplayedError=this.invalid,t()}))}))}async setError(t,i,s=!1){if("boolean"!=typeof t)throw Error('<mg-input-combobox> method "setError()" param "valid" must be a boolean.');if(void 0!==i&&!u(i))throw Error('<mg-input-combobox> method "setError()" param "errorMessage" must be a string.');this.customErrorMessage={lock:!t&&s,message:t?void 0:i},this.setValidity(t),this.setErrorMessage(!0),this.hasDisplayedError=this.invalid}async reset(){if(!this.readonly)return this.setValue(null),this.option=null,this.filter="",new Promise((t=>{requestAnimationFrame((()=>{this.customErrorMessage={lock:!1},this.checkValidity(),this.errorMessage=void 0,this.hasDisplayedError=!1,t()}))}))}setValue(t){this.value=D(t)?l(this.items||this.options.items)?t.title:Object.assign({},t):""}setValidity(t){const i=this.valid;this.customErrorMessage.lock&&(void 0===this.customErrorMessage.message||t)||(this.valid=t),this.invalid=!this.valid,(void 0===this.handlerInProgress||"blur"===this.handlerInProgress&&this.valid!==i)&&this.inputValid.emit(this.valid)}componentWillLoad(){return this.messages=w(this.element).messages,this.watchIdentifier(this.identifier),this.watchItems(this.items),void 0!==this.fetchurl&&(this.watchFetchOptions(this.fetchoptions),this.watchFetchMappings(this.fetchmappings),this.loadingWrapper({name:"load-data"})),this.watchValue(this.value),this.watchOptions(),this.watchMgWidth(this.mgWidth),this.watchReadonly(this.readonly),this.watchDisabled(this.disabled),setTimeout((()=>{this.checkValidity()}),0)}render(){var t,i,s,o,n,a;const c=this.identifier+"-list",h=this.getValueTitle(),p=this.value&&!this.disabled;let m,l;return(null===(t=this.page)||void 0===t?void 0:t.items.length)>0?m="list":0===(null===(i=this.page)||void 0===i?void 0:i.items.length)&&this.filter.length>0?m="notfound":0===(null===(s=this.page)||void 0===s?void 0:s.items.length)&&(m="notavailable"),l=void 0!==(null===(o=this.option)||void 0===o?void 0:o.value)?this.option.value:"string"==typeof this.value?this.value:null===(n=this.value)||void 0===n?void 0:n.value,e("mg-input",{key:"ee8222484fa6546a422eb724fdea67402644c0cc",label:this.label,identifier:this.identifier,class:this.classCollection.classes.join(" "),ariaDescribedbyIDs:m&&"list"!==m?m:void 0,labelOnTop:this.labelOnTop,labelHide:this.labelHide,required:this.required,tooltip:this.tooltip,tooltipPosition:this.readonly&&void 0===this.value?"label":this.tooltipPosition,helpText:this.helpText,errorMessage:this.errorMessage},this.readonly?h&&e("b",{class:"mg-c-input__readonly-value"},h):e("mg-popover",{identifier:this.popoverId,placement:"bottom-start",display:this.popoverDisplay,"arrow-hide":!0,style:{"--mg-c-input-list-width":(null===(a=this.input)||void 0===a?void 0:a.offsetWidth)>0?this.input.offsetWidth+"px":void 0},"data-fallback-placement":"bottom-end","onDisplay-change":this.handlePopoverDisplay},e("div",{class:"mg-c-input__input-group-container"},e("mg-icon",{icon:"magnifying-glass"}),e("input",{type:"text",role:"combobox",class:"mg-c-input__box mg-c-input__box--width",value:this.filter,id:this.identifier,name:this.name,placeholder:this.placeholder,title:this.placeholder,disabled:this.disabled,required:this.required,autocomplete:"off","aria-autocomplete":"list","aria-expanded":""+this.popoverDisplay,"aria-controls":c,"aria-invalid":""+(!0===this.invalid),"aria-activedescendant":d(l),onInput:this.handleFilterInput,onBlur:this.handleFilterBlur,onFocus:this.handleFilterFocus,onKeyDown:this.handleFilterKeydown,ref:t=>{null!==t&&(this.input=t)}}),p?e("mg-button",{class:"mg-c-input__box-append mg-c-input__reset",variant:"flat","is-icon":!0,label:this.messages.general.reset,"aria-controls":this.identifier,tabindex:"-1",onClick:this.handleResetButton},e("mg-icon",{icon:"cross"})):e("mg-button",{class:"mg-c-input__box-append",variant:"flat","is-icon":!0,label:this.itemsLabel,tabindex:"-1",disabled:this.disabled},e("mg-icon",{icon:"chevron-"+(this.popoverDisplay?"up":"down")}))),e("div",{slot:"content",class:"mg-c-input__popover-container"},"list"===m&&[e("ul",{key:"list",class:"mg-c-input__input-list",role:"listbox",id:c,"aria-label":this.itemsLabel,"aria-setsize":this.page.total},this.page.items.map((t=>{var i;return e("li",{role:"option",class:{"mg-c-input__input-list-item":!0,"mg-c-input__input-list-item--focus-visible":JSON.stringify(null===(i=this.option)||void 0===i?void 0:i.value)===JSON.stringify(t.value),"mg-c-input__input-list-item--selected":this.isCurrentOption(t)},key:t.title,id:d(t.value),"aria-selected":""+this.isCurrentOption(t),"data-value":r(t.value),onClick:this.handleOptionClick},t.title,this.isCurrentOption(t)&&e("mg-icon",{icon:"check"}))}))),this.isLoading&&e("mg-loader",{key:"loader",message:this.messages.input.combobox.search,class:{"mg-u-visually-hidden":!!this.page.next}}),this.page.next&&e("mg-button",{key:"load-more",variant:"flat",class:"mg-c-input__load-more",tabIndex:-1,disabled:this.isLoading,"full-width":!0,"disable-on-click":!0,onClick:this.handleLoadMoreButton,"aria-controls":c,ref:t=>{null!==t&&(this.loadMoreElement=t)}},e("mg-icon",{icon:"chevron-down"}),this.messages.input.showMore)],"notfound"===m&&e("p",{id:m,class:"mg-c-input__popover-info"},this.messages.input.combobox.notFound),"notavailable"===m&&e("p",{id:m,class:"mg-c-input__popover-info"},this.messages.input.combobox.notAvailable))))}get element(){return this}static get watchers(){return{value:[{watchValue:0}],items:[{watchItems:0}],identifier:[{watchIdentifier:0}],readonly:[{watchReadonly:0},{watchValidityChange:0}],required:[{watchValidityChange:0}],disabled:[{watchValidityChange:0},{watchDisabled:0}],mgWidth:[{watchMgWidth:0}],fetchurl:[{watchFetchUrl:0}],fetchoptions:[{watchFetchOptions:0}],fetchmappings:[{watchFetchMappings:0}],options:[{watchOptions:0}],filter:[{watchFilter:0}],popoverDisplay:[{watchPopoverDisplay:0}]}}static get style(){return".mg-c-input__box{height:var(--mg-b-size-min-height);box-sizing:border-box;padding:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2) var(--mg-b-size-8);border-width:var(--mg-c-input-border-width);border-style:solid;border-color:var(--mg-c-input-color-border);border-radius:var(--mg-c-input-border-radius);background-color:var(--mg-b-color-light);color:var(--mg-b-color-dark);font-family:inherit;font-size:var(--mg-b-font-size);text-align:var(--mg-c-input-text-align, left)}.mg-c-input__box::placeholder{color:var(--mg-c-input-placeholder-color-text);font-style:italic}.mg-c-input__box:focus{box-shadow:0 0 var(--mg-b-size-4) var(--mg-c-input-color-box-shadow-focus)}.mg-c-input__box:disabled{opacity:var(--mg-b-opacity-element-disabled)}.mg-c-input.mg-c-input--has-error .mg-c-input__box{border-color:var(--mg-b-color-danger)}.mg-c-input.mg-c-input--is-input-group-append{--mg-c-button-border-radius-top-left:0;--mg-c-button-border-radius-bottom-left:0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box{margin-right:calc(-1*var(--mg-b-size-border));border-bottom-right-radius:0;border-top-right-radius:0}.mg-c-input.mg-c-input--is-input-group-append .mg-c-input__box:focus-visible{outline-offset:-0.2rem;outline-style:solid;outline-width:.2rem}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-c-button-border-radius-top-right:0;--mg-c-button-border-radius-bottom-right:0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-c-button-border-right-width:0}.mg-c-input.mg-c-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-c-button-border-radius-top-right:var(--mg-c-input-border-radius);--mg-c-button-border-radius-bottom-right:var(--mg-c-input-border-radius)}.mg-c-input.mg-c-input--is-append-input-slot-content:not(.mg-c-input--readonly) ::slotted([slot=append-input]){align-self:start;padding-top:calc((var(--mg-b-size-min-height) - var(--mg-b-size-16))/2)}.mg-c-input.mg-c-input--has-icon .mg-c-input__input-group-container{position:relative}.mg-c-input.mg-c-input--has-icon .mg-c-input__input-group-container>mg-icon:first-of-type{position:absolute;top:50%;left:var(--mg-b-size-8);color:var(--mg-c-input-color-icon);transform:translateY(-50%)}.mg-c-input.mg-c-input--has-icon .mg-c-input__input-group-container .mg-c-input__box{padding-left:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2)}.mg-c-input__popover-info{padding:var(--mg-b-size-8);margin:0;color:var(--mg-b-color-neutral-90);text-align:center}.mg-c-input__input-container{width:100%;flex:1 auto}.mg-c-input.mg-c-input--width-full .mg-c-input__box{width:100%}.mg-c-input.mg-c-input--width-full .mg-c-input__input-group-container{width:100%;flex-grow:1}.mg-c-input.mg-c-input--width-2.mg-c-input--display-character-left .mg-c-input__input-group-container,.mg-c-input.mg-c-input--width-4.mg-c-input--display-character-left .mg-c-input__input-group-container,.mg-c-input.mg-c-input--width-16.mg-c-input--display-character-left .mg-c-input__input-group-container{width:max-content}.mg-c-input.mg-c-input--width-2 .mg-c-input__box{width:var(--mg-b-size-48)}.mg-c-input.mg-c-input--width-2.mg-c-input--text.mg-c-input--display-character-left .mg-c-input__box{width:calc(var(--mg-b-size-48) + var(--mg-c-character-left-message-length)*(.35ch + .3rem))}.mg-c-input.mg-c-input--width-4 .mg-c-input__box{width:var(--mg-b-size-72)}.mg-c-input.mg-c-input--width-4.mg-c-input--text.mg-c-input--display-character-left .mg-c-input__box{width:calc(var(--mg-b-size-72) + var(--mg-c-character-left-message-length)*(.35ch + .3rem))}.mg-c-input.mg-c-input--width-16 .mg-c-input__box{width:calc(26*var(--mg-b-size-8))}.mg-c-input.mg-c-input--width-16.mg-c-input--text.mg-c-input--display-character-left .mg-c-input__box{width:calc(calc(26 * var(--mg-b-size-8)) + var(--mg-c-character-left-message-length)*(.35ch + .3rem))}.mg-c-input.mg-c-input--width-full:not(.mg-c-input--label-on-top){justify-content:stretch}.mg-c-input.mg-c-input--is-input-group-append ::slotted([slot=append-input]),.mg-c-input.mg-c-input--is-append-input-slot-content ::slotted([slot=append-input]){width:auto}:host(.mg-c-input.mg-c-input--width-full) ::slotted(*:not(mg-input-title)){width:100%;max-width:100%}.mg-c-input__readonly-value{min-height:var(--mg-b-font-size);align-self:flex-start;margin-top:calc((var(--mg-b-size-min-height) - var(--mg-b-font-size)*var(--mg-b-line-height))/2);overflow-wrap:anywhere}.mg-u-visually-hidden{position:absolute !important;overflow:hidden !important;width:.1rem !important;height:.1rem !important;padding:0 !important;border:0 !important;margin:-0.1rem !important;clip:rect(0.1rem, 0.1rem, 0.1rem, 0.1rem) !important;clip-path:inset(50%) !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media (prefers-reduced-motion){*{animation:none !important;transition:none !important}}a{color:inherit;text-decoration:underline}a:hover,a:focus,a:active{text-decoration:none}.mg-c-input.mg-c-input--combobox mg-popover{--mg-c-popover-overflow:auto;--mg-c-popover-padding-vertical:0;--mg-c-popover-padding-horizontal:0;--mg-c-popover-min-width:var(--mg-c-input-list-width);--mg-c-popover-max-height:calc(50 * var(--mg-b-size-8) - var(--mg-b-size-32))}.mg-c-input.mg-c-input--combobox .mg-c-input__input-group-container{position:relative}.mg-c-input.mg-c-input--combobox .mg-c-input__box{cursor:pointer}.mg-c-input.mg-c-input--combobox .mg-c-input__popover-container{display:flex;flex-direction:column;gap:var(--mg-b-size-4)}.mg-c-input.mg-c-input--combobox .mg-c-input__load-more{padding:0 var(--mg-b-size-8) var(--mg-b-size-4)}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list{padding:0;margin:0;cursor:pointer;list-style:none}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item{display:flex;padding:var(--mg-b-size-8)}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item:hover,.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item.mg-c-input__input-list-item--focus-visible{background-color:var(--mg-b-color-neutral-20)}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item.mg-c-input__input-list-item--selected{font-weight:700}.mg-c-input.mg-c-input--combobox .mg-c-input__input-list-item.mg-c-input__input-list-item--selected mg-icon{margin-left:auto}.mg-c-input.mg-c-input--combobox.mg-c-input--width-2 .mg-c-input__box{width:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2 + var(--mg-b-size-24) + var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-4 .mg-c-input__box{width:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2 + var(--mg-b-size-48) + var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-16 .mg-c-input__box{width:calc(var(--mg-b-size-16) + var(--mg-b-size-8)*2 + calc(23 * var(--mg-b-size-8)) + var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-full mg-popover{--mg-c-popover-max-width:var(--mg-c-input-list-width, var(--mg-c-popover-max-width))}.mg-c-input.mg-c-input--combobox.mg-c-input--width-full .mg-c-input__input-group-container{display:flex;width:100%}.mg-c-input.mg-c-input--combobox.mg-c-input--width-full .mg-c-input__box{flex:1}.mg-c-input.mg-c-input--combobox.mg-c-input--input-append .mg-c-input__box{padding-right:calc(var(--mg-b-size-min-height) + var(--mg-b-size-4))}.mg-c-input.mg-c-input--combobox.mg-c-input--input-append .mg-c-input__box-append{position:absolute;top:0;right:0}"}},[1,"mg-input-combobox",{value:[1537],items:[16],itemsLabel:[1,"items-label"],identifier:[1],name:[1],label:[1],labelOnTop:[4,"label-on-top"],labelHide:[4,"label-hide"],placeholder:[1],required:[4],readonly:[4],disabled:[4],mgWidth:[8,"mg-width"],tooltip:[1],tooltipPosition:[1,"tooltip-position"],helpText:[1,"help-text"],fetchurl:[1],fetchoptions:[16],fetchmappings:[16],valid:[1028],invalid:[1028],isLoading:[32],options:[32],option:[32],filter:[32],classCollection:[32],errorMessage:[32],popoverDisplay:[32],setFocus:[64],displayError:[64],setError:[64],reset:[64]},void 0,{value:[{watchValue:0}],items:[{watchItems:0}],identifier:[{watchIdentifier:0}],readonly:[{watchReadonly:0},{watchValidityChange:0}],required:[{watchValidityChange:0}],disabled:[{watchValidityChange:0},{watchDisabled:0}],mgWidth:[{watchMgWidth:0}],fetchurl:[{watchFetchUrl:0}],fetchoptions:[{watchFetchOptions:0}],fetchmappings:[{watchFetchMappings:0}],options:[{watchOptions:0}],filter:[{watchFilter:0}],popoverDisplay:[{watchPopoverDisplay:0}]}]);function V(){"undefined"!=typeof customElements&&["mg-input-combobox","mg-button","mg-card","mg-icon","mg-input","mg-input-title","mg-loader","mg-popover","mg-popover-content","mg-tooltip","mg-tooltip-content"].forEach((i=>{switch(i){case"mg-input-combobox":customElements.get(t(i))||customElements.define(t(i),P);break;case"mg-button":customElements.get(t(i))||x();break;case"mg-card":customElements.get(t(i))||y();break;case"mg-icon":customElements.get(t(i))||z();break;case"mg-input":customElements.get(t(i))||k();break;case"mg-input-title":customElements.get(t(i))||E();break;case"mg-loader":customElements.get(t(i))||j();break;case"mg-popover":customElements.get(t(i))||F();break;case"mg-popover-content":customElements.get(t(i))||O();break;case"mg-tooltip":customElements.get(t(i))||q();break;case"mg-tooltip-content":customElements.get(t(i))||C()}}))}V();const I=P,M=V;export{I as MgInputCombobox,M as defineCustomElement}