@mgdis/mg-components 6.9.0 → 6.10.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 (207) hide show
  1. package/dist/cjs/events.utils-D5SAtkpQ.js +28 -0
  2. package/dist/cjs/events.utils-D5SAtkpQ.js.map +1 -0
  3. package/dist/cjs/index-CATFkm3O.js +4 -0
  4. package/dist/cjs/{index-CTU2m-sy.js → index-CfIlskRh.js} +20 -6
  5. package/dist/cjs/{index-CTU2m-sy.js.map → index-CfIlskRh.js.map} +1 -1
  6. package/dist/cjs/index.es-BCLy9yYb.js +250 -0
  7. package/dist/cjs/index.es-BCLy9yYb.js.map +1 -0
  8. package/dist/cjs/loader.cjs.js +1 -1
  9. package/dist/cjs/mg-action-more_37.cjs.entry.js +382 -373
  10. package/dist/cjs/mg-action-more_37.cjs.entry.js.map +1 -1
  11. package/dist/cjs/mg-alert.cjs.entry.js +7 -7
  12. package/dist/cjs/mg-components.cjs.js +1 -1
  13. package/dist/cjs/mg-input-combobox.cjs.entry.js +774 -0
  14. package/dist/cjs/mg-input-combobox.cjs.entry.js.map +1 -0
  15. package/dist/cjs/mg-input-combobox.entry.cjs.js.map +1 -0
  16. package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js +16 -14
  17. package/dist/cjs/mg-input-rich-text-editor.cjs.entry.js.map +1 -1
  18. package/dist/cjs/mg-input-rich-text-editor.entry.cjs.js.map +1 -1
  19. package/dist/cjs/mg-loader.cjs.entry.js +5 -5
  20. package/dist/cjs/mg-progress.cjs.entry.js +11 -11
  21. package/dist/collection/collection-manifest.json +1 -0
  22. package/dist/collection/components/atoms/mg-button/mg-button.js +3 -2
  23. package/dist/collection/components/atoms/mg-button/mg-button.js.map +1 -1
  24. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +47 -57
  25. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
  26. package/dist/collection/components/molecules/inputs/mg-input-combobox/mg-input-combobox.conf.js +2 -0
  27. package/dist/collection/components/molecules/inputs/mg-input-combobox/mg-input-combobox.conf.js.map +1 -0
  28. package/dist/collection/components/molecules/inputs/mg-input-combobox/mg-input-combobox.js +1443 -0
  29. package/dist/collection/components/molecules/inputs/mg-input-combobox/mg-input-combobox.js.map +1 -0
  30. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +1 -1
  31. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +2 -2
  32. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
  33. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +1 -1
  34. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +1 -1
  35. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/editor/editor.scss +1 -0
  36. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js +3 -3
  37. package/dist/collection/components/molecules/inputs/mg-input-rich-text-editor/mg-input-rich-text-editor.js.map +1 -1
  38. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +1 -1
  39. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +1 -1
  40. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +1 -1
  41. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
  42. package/dist/collection/components/molecules/menus/mg-menu/mg-menu.js +2 -2
  43. package/dist/collection/components/molecules/menus/mg-menu/mg-menu.js.map +1 -1
  44. package/dist/collection/components/molecules/menus/mg-menu-item/mg-menu-item.js +3 -3
  45. package/dist/collection/components/molecules/menus/mg-menu-item/mg-menu-item.js.map +1 -1
  46. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js +2 -2
  47. package/dist/collection/components/molecules/mg-action-more/mg-action-more.js.map +1 -1
  48. package/dist/collection/components/molecules/mg-alert/mg-alert.js +1 -1
  49. package/dist/collection/components/molecules/mg-details/mg-details.js +1 -1
  50. package/dist/collection/components/molecules/mg-form/mg-form.js +1 -1
  51. package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +1 -1
  52. package/dist/collection/components/molecules/mg-loader/mg-loader.js +1 -1
  53. package/dist/collection/components/molecules/mg-message/mg-message.js +2 -2
  54. package/dist/collection/components/molecules/mg-modal/mg-modal.js +2 -2
  55. package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +3 -3
  56. package/dist/collection/components/molecules/mg-panel/mg-panel.js +1 -1
  57. package/dist/collection/components/molecules/mg-popover/mg-popover-content/mg-popover-content.js +1 -1
  58. package/dist/collection/components/molecules/mg-popover/mg-popover.js +55 -81
  59. package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
  60. package/dist/collection/components/molecules/mg-progress/mg-progress.js +1 -1
  61. package/dist/collection/components/molecules/mg-skip-links/mg-skip-links.js +1 -1
  62. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +6 -5
  63. package/dist/collection/components/molecules/mg-tabs/mg-tabs.js.map +1 -1
  64. package/dist/collection/locales/en/messages.json +8 -1
  65. package/dist/collection/locales/fr/messages.json +8 -1
  66. package/dist/collection/utils/behaviors.utils.js +3 -3
  67. package/dist/collection/utils/behaviors.utils.js.map +1 -1
  68. package/dist/collection/utils/events.utils.js +22 -0
  69. package/dist/collection/utils/events.utils.js.map +1 -0
  70. package/dist/collection/utils/floating-ui.utils.js +46 -2
  71. package/dist/collection/utils/floating-ui.utils.js.map +1 -1
  72. package/dist/components/events.utils.js +26 -0
  73. package/dist/components/events.utils.js.map +1 -0
  74. package/dist/components/floating-ui.utils.js +47 -3
  75. package/dist/components/floating-ui.utils.js.map +1 -1
  76. package/dist/components/index.es.js +136 -43
  77. package/dist/components/index.es.js.map +1 -1
  78. package/dist/components/index2.js +18 -4
  79. package/dist/components/index2.js.map +1 -1
  80. package/dist/components/mg-action-more.js +8 -8
  81. package/dist/components/mg-action-more.js.map +1 -1
  82. package/dist/components/mg-alert.js +6 -6
  83. package/dist/components/mg-badge2.js +6 -6
  84. package/dist/components/mg-button2.js +9 -8
  85. package/dist/components/mg-button2.js.map +1 -1
  86. package/dist/components/mg-character-left2.js +4 -4
  87. package/dist/components/mg-details.js +4 -4
  88. package/dist/components/mg-details.js.map +1 -1
  89. package/dist/components/mg-form.js +8 -8
  90. package/dist/components/mg-icon2.js +6 -6
  91. package/dist/components/mg-illustrated-message.js +6 -6
  92. package/dist/components/mg-input-checkbox.js +9 -9
  93. package/dist/components/mg-input-combobox.d.ts +11 -0
  94. package/dist/components/mg-input-combobox.js +897 -0
  95. package/dist/components/mg-input-combobox.js.map +1 -0
  96. package/dist/components/mg-input-date.js +18 -18
  97. package/dist/components/mg-input-date.js.map +1 -1
  98. package/dist/components/mg-input-numeric.js +16 -16
  99. package/dist/components/mg-input-numeric.js.map +1 -1
  100. package/dist/components/mg-input-password.js +5 -5
  101. package/dist/components/mg-input-password.js.map +1 -1
  102. package/dist/components/mg-input-radio.js +8 -8
  103. package/dist/components/mg-input-rich-text-editor.js +15 -13
  104. package/dist/components/mg-input-rich-text-editor.js.map +1 -1
  105. package/dist/components/mg-input-select2.js +9 -9
  106. package/dist/components/mg-input-select2.js.map +1 -1
  107. package/dist/components/mg-input-text2.js +11 -11
  108. package/dist/components/mg-input-text2.js.map +1 -1
  109. package/dist/components/mg-input-textarea.js +9 -9
  110. package/dist/components/mg-input-textarea.js.map +1 -1
  111. package/dist/components/mg-input-title2.js +4 -4
  112. package/dist/components/mg-input-toggle.js +7 -7
  113. package/dist/components/mg-input2.js +8 -8
  114. package/dist/components/mg-item-more2.js +12 -12
  115. package/dist/components/mg-item-more2.js.map +1 -1
  116. package/dist/components/mg-loader.js +1 -70
  117. package/dist/components/mg-loader.js.map +1 -1
  118. package/dist/components/mg-loader2.js +75 -0
  119. package/dist/components/mg-loader2.js.map +1 -0
  120. package/dist/components/mg-menu-item2.js +13 -13
  121. package/dist/components/mg-menu-item2.js.map +1 -1
  122. package/dist/components/mg-message2.js +6 -6
  123. package/dist/components/mg-modal.js +10 -10
  124. package/dist/components/mg-pagination2.js +9 -9
  125. package/dist/components/mg-panel.js +10 -10
  126. package/dist/components/mg-popover-content2.js +5 -5
  127. package/dist/components/mg-popover-content2.js.map +1 -1
  128. package/dist/components/mg-popover2.js +60 -86
  129. package/dist/components/mg-popover2.js.map +1 -1
  130. package/dist/components/mg-progress.js +11 -11
  131. package/dist/components/mg-skip-links.js +3 -3
  132. package/dist/components/mg-table.js +6 -6
  133. package/dist/components/mg-tabs.js +18 -17
  134. package/dist/components/mg-tabs.js.map +1 -1
  135. package/dist/components/mg-tag.js +4 -4
  136. package/dist/components/mg-tooltip-content2.js +1 -1
  137. package/dist/components/mg-tooltip-content2.js.map +1 -1
  138. package/dist/components/mg-tooltip2.js +56 -66
  139. package/dist/components/mg-tooltip2.js.map +1 -1
  140. package/dist/esm/events.utils-yMGqY8YG.js +26 -0
  141. package/dist/esm/events.utils-yMGqY8YG.js.map +1 -0
  142. package/dist/esm/index-CAuxALt5.js +4 -0
  143. package/dist/esm/{index-SQlkEaXW.js → index-DmsGewMC.js} +20 -6
  144. package/dist/esm/{index-SQlkEaXW.js.map → index-DmsGewMC.js.map} +1 -1
  145. package/dist/esm/index.es-rLV3KFPd.js +223 -0
  146. package/dist/esm/index.es-rLV3KFPd.js.map +1 -0
  147. package/dist/esm/loader.js +1 -1
  148. package/dist/esm/mg-action-more_37.entry.js +383 -374
  149. package/dist/esm/mg-action-more_37.entry.js.map +1 -1
  150. package/dist/esm/mg-alert.entry.js +7 -7
  151. package/dist/esm/mg-components.js +1 -1
  152. package/dist/esm/mg-input-combobox.entry.js +772 -0
  153. package/dist/esm/mg-input-combobox.entry.js.map +1 -0
  154. package/dist/esm/mg-input-rich-text-editor.entry.js +17 -15
  155. package/dist/esm/mg-input-rich-text-editor.entry.js.map +1 -1
  156. package/dist/esm/{mg-input.conf-BtkqaBXm.js → mg-input.conf-CNgv8hc5.js} +3 -3
  157. package/dist/esm/{mg-input.conf-BtkqaBXm.js.map → mg-input.conf-CNgv8hc5.js.map} +1 -1
  158. package/dist/esm/mg-loader.entry.js +5 -5
  159. package/dist/esm/mg-progress.entry.js +11 -11
  160. package/dist/mg-components/locales/en/messages.json +8 -1
  161. package/dist/mg-components/locales/fr/messages.json +8 -1
  162. package/dist/mg-components/mg-components.esm.js +1 -1
  163. package/dist/mg-components/mg-input-combobox.entry.esm.js.map +1 -0
  164. package/dist/mg-components/mg-input-rich-text-editor.entry.esm.js.map +1 -1
  165. package/dist/mg-components/p-0f761c6c.entry.js +2 -0
  166. package/dist/mg-components/p-0f761c6c.entry.js.map +1 -0
  167. package/dist/mg-components/{p-650d6986.entry.js → p-73099ed7.entry.js} +3 -3
  168. package/dist/mg-components/p-73099ed7.entry.js.map +1 -0
  169. package/dist/mg-components/p-88f77de2.entry.js +2 -0
  170. package/dist/mg-components/{p-680948e3.entry.js.map → p-88f77de2.entry.js.map} +1 -1
  171. package/dist/mg-components/p-CNgv8hc5.js +2 -0
  172. package/dist/mg-components/{p-BtkqaBXm.js.map → p-CNgv8hc5.js.map} +1 -1
  173. package/dist/mg-components/p-DK9teKTo.js +2 -0
  174. package/dist/mg-components/{p-CqGbLOnN.js.map → p-DK9teKTo.js.map} +1 -1
  175. package/dist/mg-components/{p-583b3769.entry.js → p-ad66e7b3.entry.js} +2 -2
  176. package/dist/mg-components/p-cdbe689e.entry.js +2 -0
  177. package/dist/mg-components/{p-9acc6504.entry.js.map → p-cdbe689e.entry.js.map} +1 -1
  178. package/dist/mg-components/p-d3a868f0.entry.js +2 -0
  179. package/dist/mg-components/p-d3a868f0.entry.js.map +1 -0
  180. package/dist/mg-components/p-rLV3KFPd.js +2 -0
  181. package/dist/mg-components/p-rLV3KFPd.js.map +1 -0
  182. package/dist/mg-components/p-yMGqY8YG.js +2 -0
  183. package/dist/mg-components/p-yMGqY8YG.js.map +1 -0
  184. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +6 -5
  185. package/dist/types/components/molecules/inputs/mg-input-combobox/mg-input-combobox.conf.d.ts +24 -0
  186. package/dist/types/components/molecules/inputs/mg-input-combobox/mg-input-combobox.d.ts +340 -0
  187. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +5 -9
  188. package/dist/types/components.d.ts +247 -2
  189. package/dist/types/utils/events.utils.d.ts +4 -0
  190. package/dist/types/utils/floating-ui.utils.d.ts +9 -1
  191. package/ide/intellij/web-types.json +400 -1
  192. package/ide/vscode/html-custom-data.json +332 -0
  193. package/package.json +12 -12
  194. package/dist/cjs/index.es-jXqiN1uw.js +0 -152
  195. package/dist/cjs/index.es-jXqiN1uw.js.map +0 -1
  196. package/dist/esm/index.es-DDBtzymI.js +0 -130
  197. package/dist/esm/index.es-DDBtzymI.js.map +0 -1
  198. package/dist/mg-components/p-650d6986.entry.js.map +0 -1
  199. package/dist/mg-components/p-680948e3.entry.js +0 -2
  200. package/dist/mg-components/p-9acc6504.entry.js +0 -2
  201. package/dist/mg-components/p-BtkqaBXm.js +0 -2
  202. package/dist/mg-components/p-CqGbLOnN.js +0 -2
  203. package/dist/mg-components/p-DDBtzymI.js +0 -2
  204. package/dist/mg-components/p-DDBtzymI.js.map +0 -1
  205. package/dist/mg-components/p-c0fb6f62.entry.js +0 -2
  206. package/dist/mg-components/p-c0fb6f62.entry.js.map +0 -1
  207. /package/dist/mg-components/{p-583b3769.entry.js.map → p-ad66e7b3.entry.js.map} +0 -0
@@ -0,0 +1,772 @@
1
+ import { r as registerInstance, c as createEvent, h, g as getElement } from './index-CAuxALt5.js';
2
+ import { Y as Yt, Z as Zt, K as Kt, X as Xt, q as qe, G as Gt, D as Dt, i as ie, a as De, H as He } from './index.es-rLV3KFPd.js';
3
+ import { c as classReadonly, a as classDisabled, w as widths } from './mg-input.conf-CNgv8hc5.js';
4
+ import { i as initLocales } from './index-DmsGewMC.js';
5
+ import { K as Keys } from './events.utils-yMGqY8YG.js';
6
+
7
+ 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__with-character-left>mg-icon:first-of-type,.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__with-character-left .mg-c-input__box,.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__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-2 .mg-c-input__with-character-left,.mg-c-input.mg-c-input--width-4 .mg-c-input__with-character-left,.mg-c-input.mg-c-input--width-16 .mg-c-input__with-character-left{width:max-content}.mg-c-input.mg-c-input--width-2 .mg-c-input__with-character-left:has(textarea),.mg-c-input.mg-c-input--width-4 .mg-c-input__with-character-left:has(textarea),.mg-c-input.mg-c-input--width-16 .mg-c-input__with-character-left:has(textarea){flex-grow:inherit}.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__with-character-left:not(:has(textarea)) .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__with-character-left:not(:has(textarea)) .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__with-character-left:not(:has(textarea)) .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);word-break:break-word}.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}}.mg-c-input.mg-c-input--combobox mg-popover{--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__popover-info{padding:var(--mg-b-size-8);margin:0;text-align:center}.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__reset{padding-right:var(--mg-b-size-min-height)}.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)*2 + 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)*2 + 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)*2 + 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-c-input-append-x) + 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}";
8
+
9
+ /**
10
+ * Check if object is an item
11
+ * @param item - object to check
12
+ * @returns True if object is an item
13
+ */
14
+ const isItem = (item) => item && typeof item === 'object' && typeof item.title === 'string' && item.value !== undefined;
15
+ /**
16
+ * Check if objects are items
17
+ * @param items - items to check
18
+ * @returns True if objects are items
19
+ */
20
+ const isItems = (items) => Array.isArray(items) && items.every(isItem);
21
+ /**
22
+ * Check if object is valid combobox fetchmappings
23
+ * @param value - to validate
24
+ * @returns truthy if mapping is valid
25
+ */
26
+ const isFetchmappings = (value) => {
27
+ const isValidRoot = ie(value) && Object.hasOwn(value, 'request') && Object.hasOwn(value, 'response');
28
+ if (isValidRoot) {
29
+ const { request, response } = value;
30
+ if ([request, response].some(property => !ie(property)))
31
+ return false;
32
+ const isValidRequest = typeof request.filter === 'string';
33
+ const isValidResponse = typeof response === 'object' &&
34
+ typeof response.total === 'string' &&
35
+ typeof response.items === 'string' &&
36
+ typeof response.next === 'string' &&
37
+ typeof response.itemTitle === 'string' &&
38
+ typeof response.itemValue === 'string';
39
+ return isValidRequest && isValidResponse;
40
+ }
41
+ else {
42
+ return isValidRoot;
43
+ }
44
+ };
45
+ /**
46
+ * Map new URL from old url
47
+ * @param newValue - new URL value
48
+ * @param oldValue - previous URL value
49
+ * @returns updated url
50
+ */
51
+ const mapUrl = (newValue, oldValue) => {
52
+ if (!Boolean(newValue))
53
+ return;
54
+ else if (URL.canParse(newValue)) {
55
+ return newValue;
56
+ }
57
+ // build new URL
58
+ const params = newValue.includes('?') && newValue.split('?').pop();
59
+ if (Boolean(params)) {
60
+ const { origin, pathname } = new URL(oldValue);
61
+ return `${origin}${pathname}?${params}`;
62
+ }
63
+ else {
64
+ return newValue;
65
+ }
66
+ };
67
+ const MgInputCombobox = class {
68
+ constructor(hostRef) {
69
+ registerInstance(this, hostRef);
70
+ this.valueChange = createEvent(this, "value-change");
71
+ this.filterChange = createEvent(this, "filter-change");
72
+ this.loadMore = createEvent(this, "load-more");
73
+ this.inputValid = createEvent(this, "input-valid");
74
+ /************
75
+ * Internal *
76
+ ************/
77
+ // Classes
78
+ this.classFocus = 'mg-u-is-focused';
79
+ // hasDisplayedError (triggered by blur event)
80
+ this.hasDisplayedError = false;
81
+ /**
82
+ * Input name
83
+ * If not set the value equals the identifier
84
+ */
85
+ this.name = this.identifier;
86
+ /**
87
+ * Define if label is displayed on top
88
+ */
89
+ this.labelOnTop = false;
90
+ /**
91
+ * Define if label is visible
92
+ */
93
+ this.labelHide = false;
94
+ /**
95
+ * Define if input is required
96
+ */
97
+ this.required = false;
98
+ /**
99
+ * Define if input is readonly
100
+ */
101
+ this.readonly = false;
102
+ /**
103
+ * Define if input is disabled
104
+ */
105
+ this.disabled = false;
106
+ /**
107
+ * Define input width
108
+ */
109
+ this.mgWidth = 'full';
110
+ /**
111
+ * Define tooltip position
112
+ */
113
+ this.tooltipPosition = 'input';
114
+ /**
115
+ * Formated items for display
116
+ */
117
+ this.options = new Yt([]);
118
+ /**
119
+ * Option filter
120
+ */
121
+ this.filter = '';
122
+ /**
123
+ * Component classes
124
+ */
125
+ this.classCollection = new Zt(['mg-c-input--combobox', 'mg-c-input--has-icon', 'mg-c-input--input-append']);
126
+ /**
127
+ * Popover display state
128
+ */
129
+ this.popoverDisplay = false;
130
+ /**
131
+ * Handle `click` event on option
132
+ * @param event - option element click event
133
+ */
134
+ this.handleOptionClick = (event) => {
135
+ this.setValue(this.options.items.find(option => option.value === event.target.id));
136
+ this.popoverDisplay = false;
137
+ };
138
+ /**
139
+ * Handle `click` event on reset button
140
+ * @param event - click event
141
+ */
142
+ this.handleResetButton = (event) => {
143
+ event.stopPropagation();
144
+ this.reset().then(() => {
145
+ this.input.focus();
146
+ });
147
+ };
148
+ /**
149
+ * Handle `display-change` event on mg-popover
150
+ */
151
+ this.handlePopoverDisplay = (event) => {
152
+ this.popoverDisplay = event.detail;
153
+ };
154
+ /**
155
+ * Handle input event
156
+ */
157
+ this.handleFilterInput = () => {
158
+ this.checkValidity();
159
+ if (this.hasDisplayedError)
160
+ this.setErrorMessage();
161
+ if (!this.popoverDisplay)
162
+ this.popoverDisplay = true;
163
+ this.filter = this.input.value;
164
+ };
165
+ /**
166
+ * Handle `blur` event
167
+ */
168
+ this.handleFilterBlur = () => {
169
+ // skip process if popover is displayed
170
+ if (this.popoverDisplay)
171
+ return;
172
+ // Display Error
173
+ this.handlerInProgress = 'blur';
174
+ this.displayError().finally(() => {
175
+ // reset guard
176
+ this.handlerInProgress = undefined;
177
+ });
178
+ };
179
+ /**
180
+ * Handle `focus` event
181
+ */
182
+ this.handleFilterFocus = () => {
183
+ // ensure visual focus is always clear on focus when component isn't in loading state
184
+ if (!this.isLoading) {
185
+ this.option = null;
186
+ }
187
+ };
188
+ /**
189
+ * Handle load-more <mg-button> `click`
190
+ */
191
+ this.handleLoadMoreButton = () => {
192
+ this.loadingWrapper({ name: 'load-more', cursor: Kt.NEXT }).then(() => {
193
+ this.input.focus();
194
+ });
195
+ };
196
+ /**
197
+ * Handle `keypress` event
198
+ * @param event - keyboard event
199
+ */
200
+ this.handleFilterKeydown = (event) => {
201
+ if (this.disabled || event.ctrlKey || event.shiftKey)
202
+ return;
203
+ let guard = false;
204
+ // override keys actions
205
+ switch (event.key) {
206
+ case Keys.TAB:
207
+ case Keys.ENTER:
208
+ guard = event.key === Keys.ENTER;
209
+ const option = this.option || this.options.items.find(this.isCurrentOption);
210
+ // Sets the value to the content of the focused option in the listbox.
211
+ if (this.popoverDisplay)
212
+ this.setValue(this.page.total > 0 ? option : null);
213
+ // Closes the popover.
214
+ this.popoverDisplay = false;
215
+ break;
216
+ case Keys.DOWN:
217
+ case Keys.ARROWDOWN:
218
+ case Keys.UP:
219
+ case Keys.ARROWUP:
220
+ guard = true;
221
+ if (this.isLoading || !(this.page.total > 0)) {
222
+ this.popoverDisplay = true;
223
+ break;
224
+ }
225
+ if (Boolean(event.altKey) && [Keys.DOWN, Keys.ARROWDOWN].includes(event.key)) {
226
+ // Opens the popover without moving focus or changing selection.
227
+ this.popoverDisplay = true;
228
+ break;
229
+ }
230
+ // define cursor
231
+ let cursor;
232
+ const isNavigationStart = this.popoverDisplay && isItem(this.option);
233
+ if ([Keys.DOWN, Keys.ARROWDOWN].includes(event.key)) {
234
+ // If the filter is not empty and the popover is displayed, moves visual focus to the first suggested value.
235
+ // If the filter is empty and the popover is not displayed, opens the popover and moves visual focus to the first option.
236
+ // Moves visual focus to the next option.
237
+ // If visual focus is on the last option, moves visual focus to the first option.
238
+ cursor = isNavigationStart ? Kt.NEXT : Kt.FIRST;
239
+ }
240
+ else if ([Keys.UP, Keys.ARROWUP].includes(event.key)) {
241
+ // If the filter is not empty and the popover is displayed, moves visual focus to the last suggested value.
242
+ // If the filter is empty, first opens the popover if it is not already displayed and then moves visual focus to the last option.
243
+ // Moves visual focus to the previous option.
244
+ // If visual focus is on the first option, moves visual focus to the last option.
245
+ cursor = isNavigationStart ? Kt.PREVIOUS : Kt.LAST;
246
+ }
247
+ // update scroll and visual focused option in wrapper
248
+ this.loadingWrapper({ name: 'scroll', cursor });
249
+ // open popover
250
+ this.popoverDisplay = true;
251
+ break;
252
+ case Keys.LEFT:
253
+ case Keys.ARROWLEFT:
254
+ case Keys.HOME:
255
+ case Keys.RIGHT:
256
+ case Keys.ARROWRIGHT:
257
+ case Keys.END:
258
+ // skip process if visual focus is not in popover
259
+ if (!isItem(this.option))
260
+ break;
261
+ guard = true;
262
+ // Remove visual focus from popover options
263
+ this.option = null;
264
+ let index;
265
+ if (Keys.HOME === event.key) {
266
+ // Moves visual focus to the textbox and places the editing cursor at the beginning of the field.
267
+ index = 0;
268
+ }
269
+ else if (Keys.END === event.key) {
270
+ // Moves visual focus to the textbox and places the editing cursor at the end of the field.
271
+ index = this.filter.length;
272
+ }
273
+ if (typeof index === 'number') {
274
+ this.input.setSelectionRange(index, index);
275
+ }
276
+ break;
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
+ default:
293
+ // Remove visual focus from popover options
294
+ this.option = null;
295
+ break;
296
+ }
297
+ if (guard) {
298
+ event.stopPropagation();
299
+ event.preventDefault();
300
+ }
301
+ };
302
+ /**
303
+ * Scroll to next option from cursor
304
+ * @param index - targeted option index to scroll into
305
+ */
306
+ this.scrollToIndex = (index) => {
307
+ var _a;
308
+ (_a = this.element.shadowRoot.querySelector(`li:nth-of-type(${(index || 0) + this.page.baseIndex})`)) === null || _a === void 0 ? void 0 : _a.scrollIntoView();
309
+ };
310
+ /**
311
+ * Is option the current value
312
+ * @param option - option to match with
313
+ * @returns true if option is the current value
314
+ */
315
+ this.isCurrentOption = (option) => (isItem(this.value) ? this.value.value : this.value) === option.value;
316
+ /**
317
+ * get value prop title
318
+ * @returns value title
319
+ */
320
+ this.getValueTitle = () => {
321
+ if (this.value && isItem(this.value))
322
+ return this.value.title;
323
+ else if (typeof this.value === 'string')
324
+ return this.value;
325
+ else
326
+ return '';
327
+ };
328
+ /**
329
+ * Check if input is valid
330
+ */
331
+ this.checkValidity = () => {
332
+ this.setValidity(this.readonly || this.disabled || this.input.checkValidity());
333
+ };
334
+ /**
335
+ * Set input error message
336
+ * @param errorMessage - errorMessage override
337
+ */
338
+ this.setErrorMessage = (errorMessage) => {
339
+ // Set error message
340
+ this.errorMessage = undefined;
341
+ // Does have a custom error message
342
+ if (!this.valid && errorMessage !== undefined) {
343
+ this.errorMessage = errorMessage;
344
+ }
345
+ // required
346
+ else if (!this.valid && this.input.validity.valueMissing) {
347
+ this.errorMessage = this.messages.errors.required;
348
+ }
349
+ };
350
+ /**
351
+ * Get filtered options from `filter` input value
352
+ * @returns filtered options
353
+ */
354
+ this.optionsFilter = (option) => (this.filter === '' ? true : option.title.toLocaleLowerCase().includes(this.filter.toLocaleLowerCase()));
355
+ /**
356
+ * Loading wrapper with a given action
357
+ * @param action - wrapped loading action
358
+ * @returns promisified action
359
+ */
360
+ this.loadingWrapper = (action) => {
361
+ let promise;
362
+ let index;
363
+ // cache initial loading action if not defined
364
+ if (!Boolean(this.loadingAction)) {
365
+ this.loadingAction = action.name;
366
+ }
367
+ // update index
368
+ if (Boolean(this.option) && this.loadingAction !== 'load-more') {
369
+ index = this.page.items.findIndex(option => option.value.toString() === this.option.value.toString());
370
+ }
371
+ else if (this.loadingAction === 'load-more') {
372
+ index = this.page.items.length - this.page.baseIndex;
373
+ }
374
+ // when action require a loadMore we fetch the API else we report action to next tick
375
+ // Set "load more" if action match OR if next item not available in the current page
376
+ if (action.name === 'load-more') {
377
+ // wait for new element render and update scroll position
378
+ // set component loading
379
+ this.isLoading = true;
380
+ promise = this.goToNextPage;
381
+ }
382
+ else if (action.cursor === Kt.NEXT &&
383
+ this.page.items.length <= this.page.total &&
384
+ index + this.page.baseIndex === this.page.items.length &&
385
+ index + this.page.baseIndex < this.page.total) {
386
+ // trigger load-more from button to benefit from `disabled-on-click`
387
+ this.loadMoreElement.click();
388
+ return;
389
+ }
390
+ else if (action.name === 'scroll') {
391
+ promise = Xt;
392
+ }
393
+ else {
394
+ promise = this.updatePage;
395
+ }
396
+ return promise()
397
+ .then(() => {
398
+ // parse full items list from options
399
+ const options = this.options.items.filter(this.optionsFilter);
400
+ // update visual focus
401
+ if (action.name !== 'load-data') {
402
+ index = this.page.getIndexFromCursor(action.cursor, this.loadingAction === 'load-more' && index >= 0 ? options[index] : this.option);
403
+ }
404
+ this.option = options[index];
405
+ // update scroll position
406
+ this.scrollToIndex(index);
407
+ })
408
+ .finally(() => {
409
+ // reset loading after next render
410
+ requestAnimationFrame(() => {
411
+ this.isLoading = false;
412
+ this.loadingAction = undefined;
413
+ });
414
+ });
415
+ };
416
+ /**
417
+ * Go to next page
418
+ * @returns promise
419
+ */
420
+ this.goToNextPage = () => {
421
+ this.loadMore.emit();
422
+ if (Boolean(this.fetchurl)) {
423
+ return this.getOptions(typeof this.page.next === 'string' ? this.page.next : undefined).then(nextPage => {
424
+ if (!Boolean(nextPage))
425
+ return;
426
+ // merge items from current page and next page
427
+ const items = [...this.page.items, ...nextPage.items];
428
+ // create new options pagination withe merged items
429
+ this.options = new Yt(items, { total: nextPage.total, next: nextPage.next, top: items.length });
430
+ });
431
+ }
432
+ else {
433
+ return Xt(() => {
434
+ if (typeof this.page.next === 'function') {
435
+ const nextPage = this.page.next();
436
+ this.page = new He(Object.assign(Object.assign({}, nextPage), { items: [...this.page.items, ...nextPage.items] }));
437
+ }
438
+ });
439
+ }
440
+ };
441
+ /**
442
+ * Go to next page
443
+ * @returns promise
444
+ */
445
+ this.updatePage = async () => {
446
+ if (Boolean(this.fetchurl)) {
447
+ return this.getOptions().then(page => {
448
+ if (!Boolean(page))
449
+ return;
450
+ // reset current options pagination from API response
451
+ this.options = new Yt(page.items, { total: page.total, next: page.next, top: page.top });
452
+ });
453
+ }
454
+ else {
455
+ this.page = this.options.getPage(0, this.optionsFilter);
456
+ }
457
+ };
458
+ /**
459
+ * Fetch request
460
+ * @param url - to fetch
461
+ * @returns new page from url
462
+ */
463
+ this.getOptions = async (url = this.fetchurl) => {
464
+ // add text filter
465
+ const updateUrl = (typeof url === 'string' ? url : url.toString()).replaceAll(this.fetchmappings.request.filter, encodeURIComponent(this.filter));
466
+ try {
467
+ const response = await fetch(updateUrl, this.fetchoptions).then(response => response.json());
468
+ if (!response)
469
+ return null;
470
+ const items = qe(response, this.fetchmappings.response.items).map((item) => ({
471
+ title: qe(item, this.fetchmappings.response.itemTitle),
472
+ value: qe(item, this.fetchmappings.response.itemValue),
473
+ }));
474
+ const total = Number(qe(response, this.fetchmappings.response.total, 0));
475
+ const next = mapUrl(qe(response, this.fetchmappings.response.next), this.fetchurl.toString());
476
+ return { items, total, next, top: items.length };
477
+ }
478
+ catch (_a) { }
479
+ };
480
+ }
481
+ watchValue(newValue) {
482
+ this.filter = this.getValueTitle();
483
+ this.valueChange.emit(newValue);
484
+ }
485
+ watchItems(newValue) {
486
+ if (Boolean(this.fetchurl) && !Boolean(newValue)) {
487
+ // skip newValue check
488
+ return;
489
+ }
490
+ else if (Boolean(this.fetchurl) && Boolean(newValue)) {
491
+ throw new Error(`<mg-input-combobox> prop "items" values cannot be use with "fetchurl" prop defined. Passed value: ${Gt(newValue)}.`);
492
+ }
493
+ // Empty options
494
+ else if (Array.isArray(newValue) && newValue.length === 0) {
495
+ this.options = new Yt([]);
496
+ }
497
+ // String array
498
+ else if (Dt(newValue)) {
499
+ this.options = new Yt(newValue.map(item => ({ title: item, value: item })), { total: newValue.length });
500
+ }
501
+ // Object array
502
+ else if (isItems(newValue)) {
503
+ this.options = new Yt(newValue, { total: newValue.length });
504
+ }
505
+ else {
506
+ throw new Error(`<mg-input-combobox> prop "items" values must be the same type, string or Option. Passed value: ${Gt(newValue)}.`);
507
+ }
508
+ }
509
+ watchIdentifier(newValue) {
510
+ if (Boolean(newValue)) {
511
+ this.popoverId = `${newValue}-popover`;
512
+ this.element.dataset.mgPopoverGuard = this.popoverId;
513
+ }
514
+ }
515
+ watchReadonly(newValue) {
516
+ if (newValue)
517
+ this.classCollection.add(classReadonly);
518
+ else
519
+ this.classCollection.delete(classReadonly);
520
+ }
521
+ watchValidityChange(newValue, _oldValue, prop) {
522
+ if (this.input === undefined)
523
+ return;
524
+ this.input[prop] = newValue;
525
+ this.checkValidity();
526
+ if (this.hasDisplayedError) {
527
+ this.setErrorMessage();
528
+ this.hasDisplayedError = false;
529
+ }
530
+ }
531
+ watchDisabled(newValue) {
532
+ if (newValue) {
533
+ this.classCollection.add(classDisabled);
534
+ }
535
+ else {
536
+ this.classCollection.delete(classDisabled);
537
+ }
538
+ }
539
+ watchMgWidth(newValue) {
540
+ // reset width class
541
+ widths.forEach(width => {
542
+ this.classCollection.delete(`mg-c-input--width-${width}`);
543
+ });
544
+ // apply new width
545
+ if (newValue !== undefined)
546
+ this.classCollection.add(`mg-c-input--width-${this.mgWidth}`);
547
+ this.classCollection = new Zt(this.classCollection.classes);
548
+ }
549
+ watchFetchUrl(newValue) {
550
+ if (newValue && !URL.canParse(newValue)) {
551
+ throw new Error(`<mg-input-combobox> prop "fetchurl" value must be URL or string. Passed value: ${Gt(newValue)}.`);
552
+ }
553
+ }
554
+ watchFetchOptions(newValue) {
555
+ if (this.fetchurl && newValue && !ie(newValue)) {
556
+ throw new Error(`<mg-input-combobox> prop "fetchoptions" value must be a valid RequestInit. Passed value: ${Gt(newValue)}.`);
557
+ }
558
+ else {
559
+ new Request(this.fetchurl, newValue);
560
+ }
561
+ }
562
+ watchFetchMappings(newValue) {
563
+ if (Boolean(this.fetchurl) && !Boolean(newValue)) {
564
+ throw new Error(`<mg-input-combobox> prop "fetchmappings" is required with "fetchurl" prop.`);
565
+ }
566
+ else if (Boolean(newValue) && !isFetchmappings(newValue)) {
567
+ throw new Error(`<mg-input-combobox> prop "fetchmappings" value must be { request: RequestMappingType, response: ResponseMappingType }. Passed value: ${Gt(newValue)}.`);
568
+ }
569
+ }
570
+ watchOptions(newValue) {
571
+ this.page = newValue.getPage(0, Boolean(this.filter) ? this.optionsFilter : undefined);
572
+ }
573
+ watchFilter(newValue) {
574
+ this.loadingWrapper({ name: 'load-data' });
575
+ this.filterChange.emit(newValue);
576
+ }
577
+ watchPopoverDisplay(newValue) {
578
+ if (newValue) {
579
+ this.classCollection.add(this.classFocus);
580
+ this.input.focus();
581
+ this.scrollToIndex(0);
582
+ }
583
+ else {
584
+ // remove visual focus
585
+ this.option = null;
586
+ // reset filter with value
587
+ this.filter = this.getValueTitle();
588
+ this.classCollection.delete(this.classFocus);
589
+ this.handlerInProgress = 'blur';
590
+ this.displayError().finally(() => {
591
+ // reset guard
592
+ this.handlerInProgress = undefined;
593
+ });
594
+ }
595
+ }
596
+ /**
597
+ * Public method to play input focus
598
+ */
599
+ async setFocus() {
600
+ this.input.focus();
601
+ }
602
+ /**
603
+ * Display input error if it exists.
604
+ */
605
+ displayError() {
606
+ // Use `Promise` as requested for stencil method
607
+ // Use `requestAnimationFrame` to ensure:
608
+ // - DOM is fully updated before validation
609
+ // - Async operations are completed
610
+ // - No timing issues with Stencil's render cycle
611
+ // - Keep everything in sync both inside and outside the component
612
+ return new Promise(resolve => {
613
+ requestAnimationFrame(() => {
614
+ this.checkValidity();
615
+ this.setErrorMessage();
616
+ this.hasDisplayedError = this.invalid;
617
+ resolve();
618
+ });
619
+ });
620
+ }
621
+ /**
622
+ * Set an error and display a custom error message.
623
+ * This method can be used to set the component's error state from its concombobox by passing a boolean value to the `valid` parameter.
624
+ * It must be paired with an error message to display for the given concombobox.
625
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
626
+ * @param valid - value indicating the validity
627
+ * @param errorMessage - the error message to display
628
+ */
629
+ async setError(valid, errorMessage) {
630
+ if (typeof valid !== 'boolean') {
631
+ throw new Error('<mg-input-combobox> method "setError()" param "valid" must be a boolean.');
632
+ }
633
+ else if (!De(errorMessage)) {
634
+ throw new Error('<mg-input-combobox> method "setError()" param "errorMessage" must be a string.');
635
+ }
636
+ else {
637
+ this.setValidity(valid);
638
+ this.setErrorMessage(valid ? undefined : errorMessage);
639
+ this.hasDisplayedError = this.invalid;
640
+ }
641
+ }
642
+ /**
643
+ * Reset value, validity and error state
644
+ */
645
+ async reset() {
646
+ if (this.readonly)
647
+ return;
648
+ this.setValue(null);
649
+ this.option = null;
650
+ this.filter = '';
651
+ this.checkValidity();
652
+ this.errorMessage = undefined;
653
+ this.hasDisplayedError = false;
654
+ }
655
+ /**
656
+ * Set value prop
657
+ * @param newValue - slected option item
658
+ */
659
+ setValue(newValue) {
660
+ if (!isItem(newValue)) {
661
+ this.value = '';
662
+ }
663
+ else {
664
+ this.value = Dt(this.items || this.options.items) ? newValue.title : Object.assign({}, newValue);
665
+ }
666
+ }
667
+ /**
668
+ * Method to set validity values
669
+ * @param newValue - valid new value
670
+ */
671
+ setValidity(newValue) {
672
+ const oldValidValue = this.valid;
673
+ this.valid = newValue;
674
+ this.invalid = !this.valid;
675
+ // We need to send valid event even if it is the same value
676
+ if (this.handlerInProgress === undefined || (this.handlerInProgress === 'blur' && this.valid !== oldValidValue))
677
+ this.inputValid.emit(this.valid);
678
+ }
679
+ /*************
680
+ * Lifecycle *
681
+ *************/
682
+ /**
683
+ * Check if component props are well configured on init
684
+ * @returns timeout
685
+ */
686
+ componentWillLoad() {
687
+ // Get locales
688
+ this.messages = initLocales(this.element).messages;
689
+ // Validate
690
+ this.watchIdentifier(this.identifier);
691
+ this.watchItems(this.items);
692
+ if (Boolean(this.fetchurl)) {
693
+ this.watchFetchUrl(this.fetchurl);
694
+ this.watchFetchOptions(this.fetchoptions);
695
+ this.watchFetchMappings(this.fetchmappings);
696
+ this.loadingWrapper({ name: 'load-data' });
697
+ }
698
+ this.watchValue(this.value);
699
+ this.watchOptions(this.options);
700
+ this.watchMgWidth(this.mgWidth);
701
+ this.watchReadonly(this.readonly);
702
+ this.watchDisabled(this.disabled);
703
+ // Check validity when component is ready
704
+ // return a promise to process action only in the FIRST render().
705
+ // https://stenciljs.com/docs/component-lifecycle#componentwillload
706
+ return setTimeout(() => {
707
+ this.checkValidity();
708
+ }, 0);
709
+ }
710
+ /**
711
+ * Render
712
+ * @returns HTML Element
713
+ */
714
+ render() {
715
+ var _a, _b, _c, _d, _e, _f;
716
+ const listId = `${this.identifier}-list`;
717
+ const readonlyValue = this.getValueTitle();
718
+ const withResetButton = this.value && !this.disabled;
719
+ let popoverContent;
720
+ if (((_a = this.page) === null || _a === void 0 ? void 0 : _a.items.length) > 0)
721
+ popoverContent = 'list';
722
+ else if (((_b = this.page) === null || _b === void 0 ? void 0 : _b.items.length) === 0 && Boolean(this.filter))
723
+ popoverContent = 'notfound';
724
+ else if (((_c = this.page) === null || _c === void 0 ? void 0 : _c.items.length) === 0)
725
+ popoverContent = 'notavailable';
726
+ return (h("mg-input", { key: 'b8c4c6d18bb1d16ff0a8494ddb698cb4e0198e43', label: this.label, identifier: this.identifier, class: this.classCollection.classes.join(' '), ariaDescribedbyIDs: popoverContent && popoverContent !== 'list' ? [popoverContent] : [], 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: {
727
+ '--mg-c-input-list-width': Boolean((_d = this.input) === null || _d === void 0 ? void 0 : _d.offsetWidth) ? `${this.input.offsetWidth}px` : undefined,
728
+ '--mg-c-input-append-x': withResetButton ? '2' : '1',
729
+ }, "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": Boolean((_e = this.option) === null || _e === void 0 ? void 0 : _e.value) ? this.option.value : typeof this.value === 'string' ? this.value : (_f = this.value) === null || _f === void 0 ? void 0 : _f.value, onInput: this.handleFilterInput, onBlur: this.handleFilterBlur, onFocus: this.handleFilterFocus, onKeyDown: this.handleFilterKeydown, ref: (el) => {
730
+ if (el !== null)
731
+ this.input = el;
732
+ } }), 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' && [
733
+ // eslint-disable-next-line jsx-a11y/role-supports-aria-props
734
+ 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 => {
735
+ return (
736
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events
737
+ h("li", { role: "option", class: {
738
+ 'mg-c-input__input-list-item': true,
739
+ 'mg-c-input__input-list-item--focus-visible': this.option === option,
740
+ 'mg-c-input__input-list-item--selected': this.isCurrentOption(option),
741
+ }, key: option.title, id: option.value.toString(), "aria-selected": this.isCurrentOption(option).toString(), onClick: this.handleOptionClick }, option.title, this.isCurrentOption(option) && h("mg-icon", { icon: "check" })));
742
+ })),
743
+ this.isLoading && h("mg-loader", { key: "loader", message: this.messages.input.combobox.search, class: { 'mg-u-visually-hidden': Boolean(this.page.next) } }),
744
+ 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) => {
745
+ if (el !== null)
746
+ this.loadMoreElement = el;
747
+ } }, h("mg-icon", { icon: "chevron-down" }), this.messages.input.combobox.loadMore)),
748
+ ], 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)))))));
749
+ }
750
+ get element() { return getElement(this); }
751
+ static get watchers() { return {
752
+ "value": ["watchValue"],
753
+ "items": ["watchItems"],
754
+ "identifier": ["watchIdentifier"],
755
+ "readonly": ["watchReadonly", "watchValidityChange"],
756
+ "required": ["watchValidityChange"],
757
+ "disabled": ["watchValidityChange", "watchDisabled"],
758
+ "mgWidth": ["watchMgWidth"],
759
+ "fetchurl": ["watchFetchUrl"],
760
+ "fetchoptions": ["watchFetchOptions"],
761
+ "fetchmappings": ["watchFetchMappings"],
762
+ "options": ["watchOptions"],
763
+ "filter": ["watchFilter"],
764
+ "popoverDisplay": ["watchPopoverDisplay"]
765
+ }; }
766
+ };
767
+ MgInputCombobox.style = mgInputComboboxCss;
768
+
769
+ export { MgInputCombobox as mg_input_combobox };
770
+ //# sourceMappingURL=mg-input-combobox.entry.js.map
771
+
772
+ //# sourceMappingURL=mg-input-combobox.entry.js.map