@watermarkinsights/ripple 3.5.2 → 3.6.0-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 (172) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/{functions-8fb310fe.js → functions-653e695c.js} +442 -442
  3. package/dist/cjs/{global-fe8e4bb7.js → global-e676a97a.js} +65 -65
  4. package/dist/cjs/{http-service-9e8c4dd5.js → http-service-494d81de.js} +49 -49
  5. package/dist/cjs/{interfaces-30a74c1f.js → interfaces-a3338581.js} +29 -29
  6. package/dist/cjs/loader.cjs.js +2 -2
  7. package/dist/cjs/priv-chart-popover.cjs.entry.js +78 -78
  8. package/dist/cjs/priv-datepicker.cjs.entry.js +667 -667
  9. package/dist/cjs/priv-navigator-button.cjs.entry.js +18 -18
  10. package/dist/cjs/priv-navigator-item.cjs.entry.js +23 -23
  11. package/dist/cjs/ripple.cjs.js +2 -2
  12. package/dist/cjs/wm-action-menu_2.cjs.entry.js +341 -341
  13. package/dist/cjs/wm-button.cjs.entry.js +218 -218
  14. package/dist/cjs/wm-chart-slice.cjs.entry.js +13 -13
  15. package/dist/cjs/wm-chart.cjs.entry.js +474 -474
  16. package/dist/cjs/wm-datepicker.cjs.entry.js +256 -256
  17. package/dist/cjs/wm-input.cjs.entry.js +133 -133
  18. package/dist/cjs/wm-modal-footer.cjs.entry.js +31 -31
  19. package/dist/cjs/wm-modal-header.cjs.entry.js +34 -34
  20. package/dist/cjs/wm-modal.cjs.entry.js +161 -161
  21. package/dist/cjs/wm-navigator.cjs.entry.js +268 -268
  22. package/dist/cjs/wm-network-uploader.cjs.entry.js +420 -420
  23. package/dist/cjs/wm-option_2.cjs.entry.js +492 -492
  24. package/dist/cjs/wm-pagination.cjs.entry.js +167 -167
  25. package/dist/cjs/wm-search.cjs.entry.js +231 -231
  26. package/dist/cjs/wm-snackbar.cjs.entry.js +170 -170
  27. package/dist/cjs/wm-tab-item_3.cjs.entry.js +300 -300
  28. package/dist/cjs/wm-tag-input.cjs.entry.js +556 -556
  29. package/dist/cjs/wm-timepicker.cjs.entry.js +379 -379
  30. package/dist/cjs/wm-toggletip.cjs.entry.js +124 -124
  31. package/dist/cjs/wm-uploader.cjs.entry.js +356 -347
  32. package/dist/cjs/wm-wrapper.cjs.entry.js +12 -12
  33. package/dist/collection/components/wm-action-menu/wm-action-menu.js +460 -460
  34. package/dist/collection/components/wm-button/wm-button.js +485 -485
  35. package/dist/collection/components/wm-chart/priv-chart-popover/priv-chart-popover.js +232 -232
  36. package/dist/collection/components/wm-chart/wm-chart-slice.js +64 -64
  37. package/dist/collection/components/wm-chart/wm-chart.js +719 -719
  38. package/dist/collection/components/wm-datepicker/priv-datepicker/priv-datepicker.js +1015 -1015
  39. package/dist/collection/components/wm-datepicker/wm-datepicker.js +462 -462
  40. package/dist/collection/components/wm-input/wm-input.js +423 -423
  41. package/dist/collection/components/wm-menuitem/wm-menuitem.js +444 -444
  42. package/dist/collection/components/wm-modal/wm-modal-footer.js +141 -141
  43. package/dist/collection/components/wm-modal/wm-modal-header.js +92 -92
  44. package/dist/collection/components/wm-modal/wm-modal.js +459 -459
  45. package/dist/collection/components/wm-navigator/priv-navigator-button/priv-navigator-button.js +97 -97
  46. package/dist/collection/components/wm-navigator/priv-navigator-item/priv-navigator-item.js +114 -114
  47. package/dist/collection/components/wm-navigator/wm-navigator.js +468 -468
  48. package/dist/collection/components/wm-option/wm-option.js +422 -422
  49. package/dist/collection/components/wm-pagination/wm-pagination.js +368 -368
  50. package/dist/collection/components/wm-search/wm-search.js +479 -479
  51. package/dist/collection/components/wm-select/wm-select.js +718 -718
  52. package/dist/collection/components/wm-snackbar/wm-snackbar.js +297 -297
  53. package/dist/collection/components/wm-tabs/wm-tab-item/wm-tab-item.js +219 -219
  54. package/dist/collection/components/wm-tabs/wm-tab-list/wm-tab-list.js +331 -331
  55. package/dist/collection/components/wm-tabs/wm-tab-panel/wm-tab-panel.js +104 -104
  56. package/dist/collection/components/wm-tag-input/wm-tag-input.js +787 -787
  57. package/dist/collection/components/wm-timepicker/wm-timepicker.js +579 -579
  58. package/dist/collection/components/wm-toggletip/wm-toggletip.js +241 -241
  59. package/dist/collection/components/wm-uploader/wm-network-uploader/wm-network-uploader.js +753 -753
  60. package/dist/collection/components/wm-uploader/wm-uploader.css +16 -9
  61. package/dist/collection/components/wm-uploader/wm-uploader.js +790 -748
  62. package/dist/collection/components/wm-wrapper/wm-wrapper.js +27 -27
  63. package/dist/collection/dev/scripts.js +20 -20
  64. package/dist/collection/global/__mocks__/functions.js +6 -6
  65. package/dist/collection/global/functions.js +445 -445
  66. package/dist/collection/global/global.js +72 -72
  67. package/dist/collection/global/interfaces.js +49 -49
  68. package/dist/collection/global/services/__mocks__/http-service.js +130 -130
  69. package/dist/collection/global/services/http-service.js +50 -50
  70. package/dist/collection/lang/lang.js +5 -5
  71. package/dist/collection/lang/piglatin.js +93 -93
  72. package/dist/esm/{functions-c315390d.js → functions-e528c934.js} +442 -442
  73. package/dist/esm/{global-169de013.js → global-39a2f585.js} +65 -65
  74. package/dist/esm/{http-service-5d037e16.js → http-service-3dc3b3e7.js} +49 -49
  75. package/dist/esm/{interfaces-61c6305b.js → interfaces-2b97fab2.js} +29 -29
  76. package/dist/esm/loader.js +2 -2
  77. package/dist/esm/polyfills/core-js.js +0 -0
  78. package/dist/esm/polyfills/dom.js +0 -0
  79. package/dist/esm/polyfills/es5-html-element.js +0 -0
  80. package/dist/esm/polyfills/index.js +0 -0
  81. package/dist/esm/polyfills/system.js +0 -0
  82. package/dist/esm/priv-chart-popover.entry.js +78 -78
  83. package/dist/esm/priv-datepicker.entry.js +667 -667
  84. package/dist/esm/priv-navigator-button.entry.js +18 -18
  85. package/dist/esm/priv-navigator-item.entry.js +23 -23
  86. package/dist/esm/ripple.js +2 -2
  87. package/dist/esm/wm-action-menu_2.entry.js +341 -341
  88. package/dist/esm/wm-button.entry.js +218 -218
  89. package/dist/esm/wm-chart-slice.entry.js +13 -13
  90. package/dist/esm/wm-chart.entry.js +474 -474
  91. package/dist/esm/wm-datepicker.entry.js +256 -256
  92. package/dist/esm/wm-input.entry.js +133 -133
  93. package/dist/esm/wm-modal-footer.entry.js +31 -31
  94. package/dist/esm/wm-modal-header.entry.js +34 -34
  95. package/dist/esm/wm-modal.entry.js +161 -161
  96. package/dist/esm/wm-navigator.entry.js +268 -268
  97. package/dist/esm/wm-network-uploader.entry.js +420 -420
  98. package/dist/esm/wm-option_2.entry.js +492 -492
  99. package/dist/esm/wm-pagination.entry.js +167 -167
  100. package/dist/esm/wm-search.entry.js +231 -231
  101. package/dist/esm/wm-snackbar.entry.js +170 -170
  102. package/dist/esm/wm-tab-item_3.entry.js +300 -300
  103. package/dist/esm/wm-tag-input.entry.js +556 -556
  104. package/dist/esm/wm-timepicker.entry.js +379 -379
  105. package/dist/esm/wm-toggletip.entry.js +124 -124
  106. package/dist/esm/wm-uploader.entry.js +356 -347
  107. package/dist/esm/wm-wrapper.entry.js +12 -12
  108. package/dist/ripple/{p-c5e44367.entry.js → p-092b01f3.entry.js} +1 -1
  109. package/dist/ripple/{p-5ffa983b.entry.js → p-1e0c41a9.entry.js} +1 -1
  110. package/dist/ripple/{p-374b4fa6.entry.js → p-33524565.entry.js} +1 -1
  111. package/dist/ripple/{p-888bec42.js → p-43f1298b.js} +0 -0
  112. package/dist/ripple/{p-dea72d46.entry.js → p-4cc71463.entry.js} +1 -1
  113. package/dist/ripple/{p-e60fe2f5.js → p-588b4475.js} +0 -0
  114. package/dist/ripple/{p-b03382ea.entry.js → p-65e3a656.entry.js} +1 -1
  115. package/dist/ripple/{p-a50439f1.entry.js → p-67e288fe.entry.js} +1 -1
  116. package/dist/ripple/{p-31fde2c6.entry.js → p-690b4f41.entry.js} +1 -1
  117. package/dist/ripple/{p-75a9ba2f.entry.js → p-754d3d41.entry.js} +1 -1
  118. package/dist/ripple/{p-7bbd123c.entry.js → p-8923b7d0.entry.js} +1 -1
  119. package/dist/ripple/{p-ba9d3069.entry.js → p-8cd1396e.entry.js} +1 -1
  120. package/dist/ripple/p-a53165df.entry.js +1 -0
  121. package/dist/ripple/{p-e574fb73.entry.js → p-aa973691.entry.js} +1 -1
  122. package/dist/ripple/{p-b4a8c8d3.entry.js → p-b3d5ea85.entry.js} +1 -1
  123. package/dist/ripple/p-c9dcb2ef.js +1 -0
  124. package/dist/ripple/{p-d69c1688.entry.js → p-d8ecd974.entry.js} +1 -1
  125. package/dist/ripple/{p-41f39509.entry.js → p-dc9c9fda.entry.js} +1 -1
  126. package/dist/ripple/{p-34694011.entry.js → p-e7616311.entry.js} +1 -1
  127. package/dist/ripple/{p-36da5d4a.entry.js → p-e9e8334e.entry.js} +1 -1
  128. package/dist/ripple/{p-ec5db255.entry.js → p-ec9697db.entry.js} +1 -1
  129. package/dist/ripple/{p-c724ce54.entry.js → p-efdaf3b6.entry.js} +1 -1
  130. package/dist/ripple/{p-042d6449.entry.js → p-fcdc6395.entry.js} +1 -1
  131. package/dist/ripple/{p-a6d6eae7.js → p-fd8070fb.js} +0 -0
  132. package/dist/ripple/ripple.esm.js +1 -1
  133. package/dist/types/components/wm-action-menu/wm-action-menu.d.ts +48 -48
  134. package/dist/types/components/wm-button/wm-button.d.ts +44 -44
  135. package/dist/types/components/wm-chart/priv-chart-popover/priv-chart-popover.d.ts +23 -23
  136. package/dist/types/components/wm-chart/wm-chart-slice.d.ts +8 -8
  137. package/dist/types/components/wm-chart/wm-chart.d.ts +82 -82
  138. package/dist/types/components/wm-datepicker/priv-datepicker/priv-datepicker.d.ts +76 -76
  139. package/dist/types/components/wm-datepicker/wm-datepicker.d.ts +41 -41
  140. package/dist/types/components/wm-input/wm-input.d.ts +46 -46
  141. package/dist/types/components/wm-menuitem/wm-menuitem.d.ts +34 -34
  142. package/dist/types/components/wm-modal/wm-modal-footer.d.ts +15 -15
  143. package/dist/types/components/wm-modal/wm-modal-header.d.ts +12 -12
  144. package/dist/types/components/wm-modal/wm-modal.d.ts +41 -41
  145. package/dist/types/components/wm-navigator/priv-navigator-button/priv-navigator-button.d.ts +10 -10
  146. package/dist/types/components/wm-navigator/priv-navigator-item/priv-navigator-item.d.ts +13 -13
  147. package/dist/types/components/wm-navigator/wm-navigator.d.ts +61 -61
  148. package/dist/types/components/wm-option/wm-option.d.ts +32 -32
  149. package/dist/types/components/wm-pagination/wm-pagination.d.ts +32 -32
  150. package/dist/types/components/wm-search/wm-search.d.ts +86 -86
  151. package/dist/types/components/wm-select/wm-select.d.ts +66 -66
  152. package/dist/types/components/wm-snackbar/wm-snackbar.d.ts +35 -35
  153. package/dist/types/components/wm-tabs/wm-tab-item/wm-tab-item.d.ts +38 -38
  154. package/dist/types/components/wm-tabs/wm-tab-list/wm-tab-list.d.ts +53 -53
  155. package/dist/types/components/wm-tabs/wm-tab-panel/wm-tab-panel.d.ts +20 -20
  156. package/dist/types/components/wm-tag-input/wm-tag-input.d.ts +91 -91
  157. package/dist/types/components/wm-timepicker/wm-timepicker.d.ts +61 -61
  158. package/dist/types/components/wm-toggletip/wm-toggletip.d.ts +27 -27
  159. package/dist/types/components/wm-uploader/wm-network-uploader/wm-network-uploader.d.ts +85 -85
  160. package/dist/types/components/wm-uploader/wm-uploader.d.ts +82 -80
  161. package/dist/types/components/wm-wrapper/wm-wrapper.d.ts +7 -7
  162. package/dist/types/components.d.ts +28 -24
  163. package/dist/types/global/__mocks__/functions.d.ts +6 -6
  164. package/dist/types/global/functions.d.ts +40 -40
  165. package/dist/types/global/global.d.ts +1 -1
  166. package/dist/types/global/interfaces.d.ts +34 -34
  167. package/dist/types/global/services/__mocks__/http-service.d.ts +6 -6
  168. package/dist/types/global/services/http-service.d.ts +4 -4
  169. package/dist/types/lang/lang.d.ts +5 -5
  170. package/package.json +46 -46
  171. package/dist/ripple/p-5ff97329.js +0 -1
  172. package/dist/ripple/p-d5fafa9c.entry.js +0 -1
@@ -5697,448 +5697,448 @@ function createIntl(config, cache) {
5697
5697
  return __assign(__assign({}, resolvedConfig), { formatters: formatters, formatNumber: formatNumber.bind(null, resolvedConfig, formatters.getNumberFormat), formatNumberToParts: formatNumberToParts.bind(null, resolvedConfig, formatters.getNumberFormat), formatRelativeTime: formatRelativeTime.bind(null, resolvedConfig, formatters.getRelativeTimeFormat), formatDate: formatDate.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateToParts: formatDateToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTime: formatTime.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatDateTimeRange: formatDateTimeRange.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatTimeToParts: formatTimeToParts.bind(null, resolvedConfig, formatters.getDateTimeFormat), formatPlural: formatPlural.bind(null, resolvedConfig, formatters.getPluralRules), formatMessage: formatMessage.bind(null, resolvedConfig, formatters), formatList: formatList.bind(null, resolvedConfig, formatters.getListFormat), formatListToParts: formatListToParts.bind(null, resolvedConfig, formatters.getListFormat), formatDisplayName: formatDisplayName.bind(null, resolvedConfig, formatters.getDisplayNames) });
5698
5698
  }
5699
5699
 
5700
- const DEFAULT_LANGUAGE = "en";
5701
- function getBrowserLang() {
5702
- const langAttr = document.documentElement.getAttribute("lang");
5703
- if (!!langAttr) {
5704
- return langAttr;
5705
- }
5706
- else if (window.navigator && window.navigator.language) {
5707
- const lang = window.navigator.languages ? window.navigator.languages[0] : window.navigator.language;
5708
- return lang.slice(0, 2);
5709
- }
5710
- else {
5711
- return DEFAULT_LANGUAGE;
5712
- }
5713
- }
5714
- // prevents memory leak
5715
- const cache = createIntlCache();
5716
- const locale = getBrowserLang();
5717
- const intl = createIntl({
5718
- locale: locale,
5719
- defaultLocale: "en",
5720
- messages: lang[locale] || en,
5721
- }, cache);
5722
- function generateId() {
5723
- return "wmcl-" + Math.random().toString(36).substr(2, 10);
5724
- }
5725
- function debounce(fn, wait) {
5726
- let timeout;
5727
- return function () {
5728
- const context = this;
5729
- const functionCall = () => fn.apply(context, arguments);
5730
- clearTimeout(timeout);
5731
- timeout = setTimeout(functionCall, wait);
5732
- };
5733
- }
5734
- function getTextDir() {
5735
- const dir = document.querySelector("html").getAttribute("dir");
5736
- return dir ? dir.toLowerCase() : "";
5737
- }
5738
- function getPosition(el) {
5739
- const coords = el.getBoundingClientRect();
5740
- let x = coords.x;
5741
- let y = coords.y;
5742
- // Edge doesn't have x and y
5743
- if (!x) {
5744
- if (getTextDir() === "rtl") {
5745
- x = coords.right;
5746
- }
5747
- else {
5748
- x = coords.left;
5749
- }
5750
- y = coords.top;
5751
- }
5752
- return { x, y };
5753
- }
5754
- function findParentWithScrollbar(el) {
5755
- while (!!el) {
5756
- if (el.scrollHeight > el.clientHeight && ["scroll", "auto"].includes(window.getComputedStyle(el).overflowY)) {
5757
- return el;
5758
- }
5759
- el = el.parentElement;
5760
- }
5761
- }
5762
- function findParentWithHiddenOverflow(el) {
5763
- while (!!el) {
5764
- if (window.getComputedStyle(el).overflowY !== "visible") {
5765
- return el;
5766
- }
5767
- el = el.parentElement;
5768
- }
5769
- }
5770
- function getClosableElementMeasurements(fixedEl, closableEl) {
5771
- const parent = findParentWithHiddenOverflow(fixedEl);
5772
- // if parent is not found, measurements are checked against the viewport
5773
- return {
5774
- closableElHeight: closableEl.clientHeight,
5775
- closableElWidth: closableEl.clientWidth,
5776
- // NB boundingClientRect.bottom is space from top of viewport to bottom of el
5777
- // to get space below the el -> height of viewport minus boundingClientRect.bottom
5778
- spaceAbove: parent
5779
- ? fixedEl.getBoundingClientRect().top - parent.getBoundingClientRect().top
5780
- : fixedEl.getBoundingClientRect().top,
5781
- // NB boundingClientRect.bottom is space from top of viewport to bottom of el
5782
- // to get space below the el -> height of viewport minus boundingClientRect.bottom
5783
- spaceBelow: parent
5784
- ? parent.getBoundingClientRect().bottom - fixedEl.getBoundingClientRect().bottom
5785
- : document.documentElement.clientHeight - fixedEl.getBoundingClientRect().bottom,
5786
- spaceLeft: parent
5787
- ? fixedEl.getBoundingClientRect().left - parent.getBoundingClientRect().left
5788
- : fixedEl.getBoundingClientRect().left,
5789
- spaceRight: parent
5790
- ? parent.getBoundingClientRect().right - fixedEl.getBoundingClientRect().right
5791
- : document.documentElement.clientWidth - fixedEl.getBoundingClientRect().right,
5792
- };
5793
- }
5794
- function shouldOpenUp(fixedEl, //the element visible on the page when the component is closed
5795
- closableEl, //the dropdown/popup/etc that becomes visible when the component is open
5796
- offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
5797
- offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
5798
- ) {
5799
- const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
5800
- //we want to open up only if there's not enough space below AND there is enough space above
5801
- const openUp = closableElHeight > spaceBelow + offsetBelow && closableElHeight <= spaceAbove + offsetAbove;
5802
- return openUp;
5803
- }
5804
- function shouldOpenDown(fixedEl, //the element visible on the page when the component is closed
5805
- closableEl, //the dropdown/popup/etc that becomes visible when the component is open
5806
- offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
5807
- offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
5808
- ) {
5809
- const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
5810
- //we want to open up only if there's not enough space below AND there is enough space above
5811
- const openDown = closableElHeight > spaceAbove + offsetAbove && closableElHeight <= spaceBelow + offsetBelow;
5812
- return openDown;
5813
- }
5814
- function shouldShiftRight(fixedEl, closableEl) {
5815
- const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
5816
- const needsSpaceLeft = closableElWidth > spaceLeft && spaceRight > spaceLeft;
5817
- return needsSpaceLeft;
5818
- }
5819
- function shouldShiftLeft(fixedEl, closableEl) {
5820
- const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
5821
- const needsSpaceRight = closableElWidth > spaceRight && spaceLeft > spaceRight;
5822
- return needsSpaceRight;
5823
- }
5824
- function adjustTooltipPosition(tPos, el, tooltipEl) {
5825
- // position must be reset before measurements are taken in adjustTooltipPosition
5826
- // otherwise text-wrapping from previous position makes width measurement inconsistent
5827
- tooltipEl.style.top = "";
5828
- tooltipEl.style.left = "";
5829
- const { spaceLeft, spaceRight, spaceBelow, spaceAbove } = getClosableElementMeasurements(el, tooltipEl);
5830
- const tooltipWidth = tooltipEl.getBoundingClientRect().width;
5831
- const tooltipHeight = tooltipEl.getBoundingClientRect().height;
5832
- const enoughSpaceAbove = spaceAbove > tooltipHeight;
5833
- const enoughSpaceBelow = spaceBelow > tooltipHeight;
5834
- // a tooltip should never be closer than 24px to the edge of a screen
5835
- const enoughSpaceLeft = spaceLeft - 24 > tooltipWidth;
5836
- const enoughSpaceRight = spaceRight - 24 > tooltipWidth;
5837
- const swapAbove = (position) => {
5838
- return !enoughSpaceAbove ? position.replace("top", "bottom") : position;
5839
- };
5840
- const swapBelow = (position) => {
5841
- return !enoughSpaceBelow && enoughSpaceAbove ? position.replace("bottom", "top") : position;
5842
- };
5843
- const swapLeft = (position, centeredPosition) => {
5844
- if (!enoughSpaceLeft && enoughSpaceRight) {
5845
- position = position.replace("left", "right");
5846
- }
5847
- else if (!enoughSpaceLeft && !enoughSpaceRight) {
5848
- position = centeredPosition;
5849
- }
5850
- return position;
5851
- };
5852
- const swapRight = (position, centeredPosition) => {
5853
- if (!enoughSpaceRight && enoughSpaceLeft) {
5854
- position = position.replace("right", "left");
5855
- }
5856
- else if (!enoughSpaceRight && !enoughSpaceLeft) {
5857
- position = centeredPosition;
5858
- }
5859
- return position;
5860
- };
5861
- // horizontal checks must occur before vertical checks, because horizontal can affect vertical positioning but not vice versa
5862
- switch (tPos) {
5863
- case "left":
5864
- tPos = swapLeft(tPos, "bottom");
5865
- case "right":
5866
- tPos = swapRight(tPos, "bottom");
5867
- case "top-left":
5868
- tPos = swapLeft(tPos, "top");
5869
- tPos = swapAbove(tPos);
5870
- case "top-right":
5871
- tPos = swapRight(tPos, "top");
5872
- tPos = swapAbove(tPos);
5873
- case "bottom-left":
5874
- tPos = swapLeft(tPos, "bottom");
5875
- tPos = swapBelow(tPos);
5876
- case "bottom-right":
5877
- tPos = swapRight(tPos, "bottom");
5878
- tPos = swapBelow(tPos);
5879
- case "top":
5880
- tPos = swapAbove(tPos);
5881
- case "bottom":
5882
- tPos = swapBelow(tPos);
5883
- }
5884
- return tPos;
5885
- }
5886
- function hasRoomRight(x, spaceNeeded) {
5887
- let horizOffset = 0;
5888
- // if (getTextDir() === "ltr") {
5889
- if (x.type === "click") {
5890
- // if it's a mouse event, deal with mouse coords
5891
- horizOffset = x.clientX;
5892
- // if it's a focus event, the offset is 0
5893
- }
5894
- else if (x.type === "focus") {
5895
- horizOffset = 0;
5896
- }
5897
- else {
5898
- // otherwise an element was passed, calculate how far it is from the edge of the window
5899
- let el = x; // re-assignment is for clarity
5900
- while (el) {
5901
- if (el.tagName == "BODY") {
5902
- // deal with browser quirks with body/window/document and page scroll
5903
- var xScroll = el.scrollLeft || document.documentElement.scrollLeft;
5904
- horizOffset += el.offsetLeft - xScroll + el.clientLeft;
5905
- }
5906
- else {
5907
- // for all other non-BODY elements
5908
- horizOffset += el.offsetLeft - el.scrollLeft + el.clientLeft;
5909
- }
5910
- el = el.offsetParent;
5911
- }
5912
- // }
5913
- }
5914
- return window.innerWidth - horizOffset >= spaceNeeded;
5915
- }
5916
- function checkForActiveElInShadow(element) {
5917
- while (element && element.shadowRoot) {
5918
- element = element.shadowRoot.activeElement;
5919
- }
5920
- return element;
5921
- }
5922
- function checkForFocusableElInShadow(element) {
5923
- const selectors = [
5924
- "button",
5925
- "a",
5926
- "input",
5927
- "select",
5928
- "textarea",
5929
- "wm-button",
5930
- "wm-search",
5931
- "wm-select",
5932
- "wm-action-menu",
5933
- "wm-tab-item",
5934
- "wm-datepicker",
5935
- ];
5936
- let focusableEl = element;
5937
- selectors.forEach((selector) => {
5938
- if (focusableEl && focusableEl.shadowRoot) {
5939
- let elInShadow = focusableEl.shadowRoot.querySelector(selector);
5940
- if (elInShadow) {
5941
- if (selector.startsWith("wm-")) {
5942
- focusableEl = checkForFocusableElInShadow(elInShadow);
5943
- }
5944
- else {
5945
- focusableEl = elInShadow;
5946
- }
5947
- }
5948
- }
5949
- });
5950
- return focusableEl;
5951
- }
5952
- function isFocusable(element) {
5953
- if (element.tabIndex > 0 || (element.tabIndex === 0 && element.getAttribute("tabIndex") !== null)) {
5954
- return true;
5955
- }
5956
- if (element.disabled) {
5957
- return false;
5958
- }
5959
- switch (element.nodeName) {
5960
- case "A":
5961
- return !!element.href && element.rel != "ignore";
5962
- case "INPUT":
5963
- return element.type != "hidden" && element.type != "file";
5964
- case "BUTTON":
5965
- case "SELECT":
5966
- case "TEXTAREA":
5967
- case "WM-BUTTON":
5968
- case "WM-SELECT":
5969
- case "WM-ACTION-MENU":
5970
- case "WM-DATEPICKER":
5971
- case "WM-TIMEPICKER":
5972
- case "WM-INPUT":
5973
- case "WM-TAG-INPUT":
5974
- case "WM-TAB-ITEM":
5975
- case "WM-SEARCH":
5976
- return true;
5977
- default:
5978
- return false;
5979
- }
5980
- }
5981
- function getFirstFocusableDescendant(element) {
5982
- if (isFocusable(element)) {
5983
- return checkForFocusableElInShadow(element);
5984
- }
5985
- else if (element.childNodes.length > 0) {
5986
- element.childNodes.forEach((i) => {
5987
- const childEl = getFirstFocusableDescendant(i);
5988
- return childEl && checkForFocusableElInShadow(childEl);
5989
- });
5990
- }
5991
- }
5992
- function hasValidType(file, types) {
5993
- const acceptedExtensions = types.split(" ");
5994
- const parts = file.name && file.name.split(".");
5995
- const ext = parts && parts.length > 1 && parts[parts.length - 1];
5996
- return ext
5997
- ? acceptedExtensions.includes(ext.toLowerCase())
5998
- : // fallback: if we couldn't obtain an extension,
5999
- // validate based on MIME type...
6000
- !!file.type
6001
- ? getAcceptedMimeTypesList(acceptedExtensions).includes(file.type)
6002
- : // ...and if that failed too, accept the file
6003
- // as it's preferable to accept an invalid file
6004
- // than refusing a valid one (back-end will take care of what slips through)
6005
- true;
6006
- }
6007
- // takes a string (space separated list of extensions), returns an array of strings (corresponding MIME types)
6008
- function getAcceptedMimeTypesList(acceptedExtensions) {
6009
- // this is just a list of common file types (regardless of whether they are/can be valid or not)
6010
- // front end checks are just a convenience to users, independent of security.
6011
- // it allows users to be notified of an invalid type as soon as they select the file, rather than when it gets uploaded
6012
- const lookupTable = {
6013
- aac: ["audio/aac"],
6014
- abw: ["application/x-abiword"],
6015
- arc: ["application/x-freearc"],
6016
- avi: ["video/x-msvideo"],
6017
- azw: ["application/vnd.amazon.ebook"],
6018
- bin: ["application/octet-stream"],
6019
- bmp: ["image/bmp"],
6020
- bz: ["application/x-bzip"],
6021
- bz2: ["application/x-bzip2"],
6022
- csh: ["application/x-csh"],
6023
- css: ["text/css"],
6024
- csv: ["text/csv"],
6025
- doc: ["application/msword"],
6026
- docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
6027
- eot: ["application/vnd.ms-fontobject"],
6028
- epub: ["application/epub+zip"],
6029
- gz: ["application/gzip"],
6030
- gif: ["image/gif"],
6031
- htm: ["text/html"],
6032
- html: ["text/html"],
6033
- ico: ["image/vnd.microsoft.icon"],
6034
- ics: ["text/calendar"],
6035
- jar: ["application/java-archive"],
6036
- jpeg: ["image/jpeg"],
6037
- jpg: ["image/jpeg"],
6038
- js: ["text/javascript"],
6039
- json: ["application/json"],
6040
- jsonld: ["application/ld+json"],
6041
- log: ["text/plain"],
6042
- mid: ["audio/x-midi"],
6043
- midi: ["audio/x-midi"],
6044
- mjs: ["text/javascript"],
6045
- mp3: ["audio/mpeg"],
6046
- mpeg: ["video/mpeg"],
6047
- mpkg: ["application/vnd.apple.installer+xml"],
6048
- odp: ["application/vnd.oasis.opendocument.presentation"],
6049
- ods: ["application/vnd.oasis.opendocument.spreadsheet"],
6050
- odt: ["application/vnd.oasis.opendocument.text"],
6051
- oga: ["audio/ogg"],
6052
- ogv: ["video/ogg"],
6053
- ogx: ["application/ogg"],
6054
- opus: ["audio/opus"],
6055
- otf: ["font/otf"],
6056
- png: ["image/png"],
6057
- pdf: ["application/pdf"],
6058
- php: ["application/php"],
6059
- ppt: ["application/vnd.ms-powerpoint"],
6060
- pptx: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
6061
- rar: ["application/vnd.rar", "application/x-rar", "application/x-rar-compressed"],
6062
- rtf: ["application/rtf"],
6063
- sh: ["application/x-sh"],
6064
- svg: ["image/svg+xml"],
6065
- swf: ["application/x-shockwave-flash"],
6066
- tar: ["application/x-tar"],
6067
- tif: ["image/tiff"],
6068
- tiff: ["image/tiff"],
6069
- ts: ["video/mp2t"],
6070
- ttf: ["font/ttf"],
6071
- txt: ["text/plain"],
6072
- vsd: ["application/vnd.visio"],
6073
- wav: ["audio/wav"],
6074
- weba: ["audio/webm"],
6075
- webm: ["video/webm"],
6076
- webp: ["image/webp"],
6077
- woff: ["font/woff"],
6078
- woff2: ["font/woff2"],
6079
- xhtml: ["application/xhtml+xml"],
6080
- xls: ["application/vnd.ms-excel"],
6081
- xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
6082
- xml: ["application/xml", "text/xml"],
6083
- xul: ["application/vnd.mozilla.xul+xml"],
6084
- zip: ["application/zip", "application/x-zip-compressed", "multipart/x-zip"],
6085
- "3gp": ["video/3gpp", "audio/3gpp"],
6086
- "3g2": ["video/3gpp2", "audio/3gpp2"],
6087
- "7z": ["application/x-7z-compressed"],
6088
- };
6089
- return acceptedExtensions.reduce((acc, ext) => acc.concat(lookupTable[ext]), []);
6090
- }
6091
- function snakeCaseToCamelCase(str) {
6092
- const snakeCaseRegexp = /^([a-z0-9]*)(_[a-z0-9]*)*$/g;
6093
- if (snakeCaseRegexp.test(str)) {
6094
- let camelCase = "";
6095
- let arr = str.split("_");
6096
- arr.forEach((word, idx) => {
6097
- camelCase += idx === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1);
6098
- });
6099
- return camelCase;
6100
- }
6101
- else {
6102
- return str;
6103
- }
6104
- }
6105
- function getNewIndexToFocus(currentIndex, direction, listLength) {
6106
- let newIndex = currentIndex;
6107
- if (direction === "ArrowDown") {
6108
- newIndex = (currentIndex + 1) % listLength;
6109
- }
6110
- if (direction === "ArrowUp") {
6111
- newIndex = currentIndex === 0 ? listLength - 1 : currentIndex - 1;
6112
- }
6113
- return newIndex;
6114
- }
6115
- function isRelatedTarget(ev, id) {
6116
- // used for onBlur events to check the element that has been clicked
6117
- const ids = id.split(" ");
6118
- return ev.relatedTarget && ids.includes(ev.relatedTarget.id);
6119
- }
6120
- /*
6121
- * this is going to be needed to solve the extra tabbing on navigator
6122
- * and for programmatic focus of tabs
6123
- * Here's a draft, not bug proof, see:
6124
- * https://stackoverflow.com/a/10730308/3741713
6125
-
6126
- function getKeyboardFocusableElements(element = document) {
6127
- const els = Array.from(element.querySelectorAll('a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), wm-search, wm-timepicker, wm-tab-list, wm-tab-item, wm-button, wm-action-menu'));
6128
- return els.filter((el: Element) => !el.hasAttribute("disabled")) as HTMLElement[];
6129
- }
6130
-
6131
- export function getPreviousKeyboardFocusableElement(element: HTMLElement) {
6132
- const els = getKeyboardFocusableElements();
6133
- const current = els.indexOf(element);
6134
- return els[current - 1] as HTMLElement;
6135
- }
6136
-
6137
- export function getNextKeyboardFocusableElement(element: HTMLElement) {
6138
- const els = getKeyboardFocusableElements();
6139
- const current = els.indexOf(element);
6140
- return els[current + 1] as HTMLElement;
6141
- }
5700
+ const DEFAULT_LANGUAGE = "en";
5701
+ function getBrowserLang() {
5702
+ const langAttr = document.documentElement.getAttribute("lang");
5703
+ if (!!langAttr) {
5704
+ return langAttr;
5705
+ }
5706
+ else if (window.navigator && window.navigator.language) {
5707
+ const lang = window.navigator.languages ? window.navigator.languages[0] : window.navigator.language;
5708
+ return lang.slice(0, 2);
5709
+ }
5710
+ else {
5711
+ return DEFAULT_LANGUAGE;
5712
+ }
5713
+ }
5714
+ // prevents memory leak
5715
+ const cache = createIntlCache();
5716
+ const locale = getBrowserLang();
5717
+ const intl = createIntl({
5718
+ locale: locale,
5719
+ defaultLocale: "en",
5720
+ messages: lang[locale] || en,
5721
+ }, cache);
5722
+ function generateId() {
5723
+ return "wmcl-" + Math.random().toString(36).substr(2, 10);
5724
+ }
5725
+ function debounce(fn, wait) {
5726
+ let timeout;
5727
+ return function () {
5728
+ const context = this;
5729
+ const functionCall = () => fn.apply(context, arguments);
5730
+ clearTimeout(timeout);
5731
+ timeout = setTimeout(functionCall, wait);
5732
+ };
5733
+ }
5734
+ function getTextDir() {
5735
+ const dir = document.querySelector("html").getAttribute("dir");
5736
+ return dir ? dir.toLowerCase() : "";
5737
+ }
5738
+ function getPosition(el) {
5739
+ const coords = el.getBoundingClientRect();
5740
+ let x = coords.x;
5741
+ let y = coords.y;
5742
+ // Edge doesn't have x and y
5743
+ if (!x) {
5744
+ if (getTextDir() === "rtl") {
5745
+ x = coords.right;
5746
+ }
5747
+ else {
5748
+ x = coords.left;
5749
+ }
5750
+ y = coords.top;
5751
+ }
5752
+ return { x, y };
5753
+ }
5754
+ function findParentWithScrollbar(el) {
5755
+ while (!!el) {
5756
+ if (el.scrollHeight > el.clientHeight && ["scroll", "auto"].includes(window.getComputedStyle(el).overflowY)) {
5757
+ return el;
5758
+ }
5759
+ el = el.parentElement;
5760
+ }
5761
+ }
5762
+ function findParentWithHiddenOverflow(el) {
5763
+ while (!!el) {
5764
+ if (window.getComputedStyle(el).overflowY !== "visible") {
5765
+ return el;
5766
+ }
5767
+ el = el.parentElement;
5768
+ }
5769
+ }
5770
+ function getClosableElementMeasurements(fixedEl, closableEl) {
5771
+ const parent = findParentWithHiddenOverflow(fixedEl);
5772
+ // if parent is not found, measurements are checked against the viewport
5773
+ return {
5774
+ closableElHeight: closableEl.clientHeight,
5775
+ closableElWidth: closableEl.clientWidth,
5776
+ // NB boundingClientRect.bottom is space from top of viewport to bottom of el
5777
+ // to get space below the el -> height of viewport minus boundingClientRect.bottom
5778
+ spaceAbove: parent
5779
+ ? fixedEl.getBoundingClientRect().top - parent.getBoundingClientRect().top
5780
+ : fixedEl.getBoundingClientRect().top,
5781
+ // NB boundingClientRect.bottom is space from top of viewport to bottom of el
5782
+ // to get space below the el -> height of viewport minus boundingClientRect.bottom
5783
+ spaceBelow: parent
5784
+ ? parent.getBoundingClientRect().bottom - fixedEl.getBoundingClientRect().bottom
5785
+ : document.documentElement.clientHeight - fixedEl.getBoundingClientRect().bottom,
5786
+ spaceLeft: parent
5787
+ ? fixedEl.getBoundingClientRect().left - parent.getBoundingClientRect().left
5788
+ : fixedEl.getBoundingClientRect().left,
5789
+ spaceRight: parent
5790
+ ? parent.getBoundingClientRect().right - fixedEl.getBoundingClientRect().right
5791
+ : document.documentElement.clientWidth - fixedEl.getBoundingClientRect().right,
5792
+ };
5793
+ }
5794
+ function shouldOpenUp(fixedEl, //the element visible on the page when the component is closed
5795
+ closableEl, //the dropdown/popup/etc that becomes visible when the component is open
5796
+ offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
5797
+ offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
5798
+ ) {
5799
+ const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
5800
+ //we want to open up only if there's not enough space below AND there is enough space above
5801
+ const openUp = closableElHeight > spaceBelow + offsetBelow && closableElHeight <= spaceAbove + offsetAbove;
5802
+ return openUp;
5803
+ }
5804
+ function shouldOpenDown(fixedEl, //the element visible on the page when the component is closed
5805
+ closableEl, //the dropdown/popup/etc that becomes visible when the component is open
5806
+ offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
5807
+ offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
5808
+ ) {
5809
+ const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
5810
+ //we want to open up only if there's not enough space below AND there is enough space above
5811
+ const openDown = closableElHeight > spaceAbove + offsetAbove && closableElHeight <= spaceBelow + offsetBelow;
5812
+ return openDown;
5813
+ }
5814
+ function shouldShiftRight(fixedEl, closableEl) {
5815
+ const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
5816
+ const needsSpaceLeft = closableElWidth > spaceLeft && spaceRight > spaceLeft;
5817
+ return needsSpaceLeft;
5818
+ }
5819
+ function shouldShiftLeft(fixedEl, closableEl) {
5820
+ const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
5821
+ const needsSpaceRight = closableElWidth > spaceRight && spaceLeft > spaceRight;
5822
+ return needsSpaceRight;
5823
+ }
5824
+ function adjustTooltipPosition(tPos, el, tooltipEl) {
5825
+ // position must be reset before measurements are taken in adjustTooltipPosition
5826
+ // otherwise text-wrapping from previous position makes width measurement inconsistent
5827
+ tooltipEl.style.top = "";
5828
+ tooltipEl.style.left = "";
5829
+ const { spaceLeft, spaceRight, spaceBelow, spaceAbove } = getClosableElementMeasurements(el, tooltipEl);
5830
+ const tooltipWidth = tooltipEl.getBoundingClientRect().width;
5831
+ const tooltipHeight = tooltipEl.getBoundingClientRect().height;
5832
+ const enoughSpaceAbove = spaceAbove > tooltipHeight;
5833
+ const enoughSpaceBelow = spaceBelow > tooltipHeight;
5834
+ // a tooltip should never be closer than 24px to the edge of a screen
5835
+ const enoughSpaceLeft = spaceLeft - 24 > tooltipWidth;
5836
+ const enoughSpaceRight = spaceRight - 24 > tooltipWidth;
5837
+ const swapAbove = (position) => {
5838
+ return !enoughSpaceAbove ? position.replace("top", "bottom") : position;
5839
+ };
5840
+ const swapBelow = (position) => {
5841
+ return !enoughSpaceBelow && enoughSpaceAbove ? position.replace("bottom", "top") : position;
5842
+ };
5843
+ const swapLeft = (position, centeredPosition) => {
5844
+ if (!enoughSpaceLeft && enoughSpaceRight) {
5845
+ position = position.replace("left", "right");
5846
+ }
5847
+ else if (!enoughSpaceLeft && !enoughSpaceRight) {
5848
+ position = centeredPosition;
5849
+ }
5850
+ return position;
5851
+ };
5852
+ const swapRight = (position, centeredPosition) => {
5853
+ if (!enoughSpaceRight && enoughSpaceLeft) {
5854
+ position = position.replace("right", "left");
5855
+ }
5856
+ else if (!enoughSpaceRight && !enoughSpaceLeft) {
5857
+ position = centeredPosition;
5858
+ }
5859
+ return position;
5860
+ };
5861
+ // horizontal checks must occur before vertical checks, because horizontal can affect vertical positioning but not vice versa
5862
+ switch (tPos) {
5863
+ case "left":
5864
+ tPos = swapLeft(tPos, "bottom");
5865
+ case "right":
5866
+ tPos = swapRight(tPos, "bottom");
5867
+ case "top-left":
5868
+ tPos = swapLeft(tPos, "top");
5869
+ tPos = swapAbove(tPos);
5870
+ case "top-right":
5871
+ tPos = swapRight(tPos, "top");
5872
+ tPos = swapAbove(tPos);
5873
+ case "bottom-left":
5874
+ tPos = swapLeft(tPos, "bottom");
5875
+ tPos = swapBelow(tPos);
5876
+ case "bottom-right":
5877
+ tPos = swapRight(tPos, "bottom");
5878
+ tPos = swapBelow(tPos);
5879
+ case "top":
5880
+ tPos = swapAbove(tPos);
5881
+ case "bottom":
5882
+ tPos = swapBelow(tPos);
5883
+ }
5884
+ return tPos;
5885
+ }
5886
+ function hasRoomRight(x, spaceNeeded) {
5887
+ let horizOffset = 0;
5888
+ // if (getTextDir() === "ltr") {
5889
+ if (x.type === "click") {
5890
+ // if it's a mouse event, deal with mouse coords
5891
+ horizOffset = x.clientX;
5892
+ // if it's a focus event, the offset is 0
5893
+ }
5894
+ else if (x.type === "focus") {
5895
+ horizOffset = 0;
5896
+ }
5897
+ else {
5898
+ // otherwise an element was passed, calculate how far it is from the edge of the window
5899
+ let el = x; // re-assignment is for clarity
5900
+ while (el) {
5901
+ if (el.tagName == "BODY") {
5902
+ // deal with browser quirks with body/window/document and page scroll
5903
+ var xScroll = el.scrollLeft || document.documentElement.scrollLeft;
5904
+ horizOffset += el.offsetLeft - xScroll + el.clientLeft;
5905
+ }
5906
+ else {
5907
+ // for all other non-BODY elements
5908
+ horizOffset += el.offsetLeft - el.scrollLeft + el.clientLeft;
5909
+ }
5910
+ el = el.offsetParent;
5911
+ }
5912
+ // }
5913
+ }
5914
+ return window.innerWidth - horizOffset >= spaceNeeded;
5915
+ }
5916
+ function checkForActiveElInShadow(element) {
5917
+ while (element && element.shadowRoot) {
5918
+ element = element.shadowRoot.activeElement;
5919
+ }
5920
+ return element;
5921
+ }
5922
+ function checkForFocusableElInShadow(element) {
5923
+ const selectors = [
5924
+ "button",
5925
+ "a",
5926
+ "input",
5927
+ "select",
5928
+ "textarea",
5929
+ "wm-button",
5930
+ "wm-search",
5931
+ "wm-select",
5932
+ "wm-action-menu",
5933
+ "wm-tab-item",
5934
+ "wm-datepicker",
5935
+ ];
5936
+ let focusableEl = element;
5937
+ selectors.forEach((selector) => {
5938
+ if (focusableEl && focusableEl.shadowRoot) {
5939
+ let elInShadow = focusableEl.shadowRoot.querySelector(selector);
5940
+ if (elInShadow) {
5941
+ if (selector.startsWith("wm-")) {
5942
+ focusableEl = checkForFocusableElInShadow(elInShadow);
5943
+ }
5944
+ else {
5945
+ focusableEl = elInShadow;
5946
+ }
5947
+ }
5948
+ }
5949
+ });
5950
+ return focusableEl;
5951
+ }
5952
+ function isFocusable(element) {
5953
+ if (element.tabIndex > 0 || (element.tabIndex === 0 && element.getAttribute("tabIndex") !== null)) {
5954
+ return true;
5955
+ }
5956
+ if (element.disabled) {
5957
+ return false;
5958
+ }
5959
+ switch (element.nodeName) {
5960
+ case "A":
5961
+ return !!element.href && element.rel != "ignore";
5962
+ case "INPUT":
5963
+ return element.type != "hidden" && element.type != "file";
5964
+ case "BUTTON":
5965
+ case "SELECT":
5966
+ case "TEXTAREA":
5967
+ case "WM-BUTTON":
5968
+ case "WM-SELECT":
5969
+ case "WM-ACTION-MENU":
5970
+ case "WM-DATEPICKER":
5971
+ case "WM-TIMEPICKER":
5972
+ case "WM-INPUT":
5973
+ case "WM-TAG-INPUT":
5974
+ case "WM-TAB-ITEM":
5975
+ case "WM-SEARCH":
5976
+ return true;
5977
+ default:
5978
+ return false;
5979
+ }
5980
+ }
5981
+ function getFirstFocusableDescendant(element) {
5982
+ if (isFocusable(element)) {
5983
+ return checkForFocusableElInShadow(element);
5984
+ }
5985
+ else if (element.childNodes.length > 0) {
5986
+ element.childNodes.forEach((i) => {
5987
+ const childEl = getFirstFocusableDescendant(i);
5988
+ return childEl && checkForFocusableElInShadow(childEl);
5989
+ });
5990
+ }
5991
+ }
5992
+ function hasValidType(file, types) {
5993
+ const acceptedExtensions = types.split(" ");
5994
+ const parts = file.name && file.name.split(".");
5995
+ const ext = parts && parts.length > 1 && parts[parts.length - 1];
5996
+ return ext
5997
+ ? acceptedExtensions.includes(ext.toLowerCase())
5998
+ : // fallback: if we couldn't obtain an extension,
5999
+ // validate based on MIME type...
6000
+ !!file.type
6001
+ ? getAcceptedMimeTypesList(acceptedExtensions).includes(file.type)
6002
+ : // ...and if that failed too, accept the file
6003
+ // as it's preferable to accept an invalid file
6004
+ // than refusing a valid one (back-end will take care of what slips through)
6005
+ true;
6006
+ }
6007
+ // takes a string (space separated list of extensions), returns an array of strings (corresponding MIME types)
6008
+ function getAcceptedMimeTypesList(acceptedExtensions) {
6009
+ // this is just a list of common file types (regardless of whether they are/can be valid or not)
6010
+ // front end checks are just a convenience to users, independent of security.
6011
+ // it allows users to be notified of an invalid type as soon as they select the file, rather than when it gets uploaded
6012
+ const lookupTable = {
6013
+ aac: ["audio/aac"],
6014
+ abw: ["application/x-abiword"],
6015
+ arc: ["application/x-freearc"],
6016
+ avi: ["video/x-msvideo"],
6017
+ azw: ["application/vnd.amazon.ebook"],
6018
+ bin: ["application/octet-stream"],
6019
+ bmp: ["image/bmp"],
6020
+ bz: ["application/x-bzip"],
6021
+ bz2: ["application/x-bzip2"],
6022
+ csh: ["application/x-csh"],
6023
+ css: ["text/css"],
6024
+ csv: ["text/csv"],
6025
+ doc: ["application/msword"],
6026
+ docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
6027
+ eot: ["application/vnd.ms-fontobject"],
6028
+ epub: ["application/epub+zip"],
6029
+ gz: ["application/gzip"],
6030
+ gif: ["image/gif"],
6031
+ htm: ["text/html"],
6032
+ html: ["text/html"],
6033
+ ico: ["image/vnd.microsoft.icon"],
6034
+ ics: ["text/calendar"],
6035
+ jar: ["application/java-archive"],
6036
+ jpeg: ["image/jpeg"],
6037
+ jpg: ["image/jpeg"],
6038
+ js: ["text/javascript"],
6039
+ json: ["application/json"],
6040
+ jsonld: ["application/ld+json"],
6041
+ log: ["text/plain"],
6042
+ mid: ["audio/x-midi"],
6043
+ midi: ["audio/x-midi"],
6044
+ mjs: ["text/javascript"],
6045
+ mp3: ["audio/mpeg"],
6046
+ mpeg: ["video/mpeg"],
6047
+ mpkg: ["application/vnd.apple.installer+xml"],
6048
+ odp: ["application/vnd.oasis.opendocument.presentation"],
6049
+ ods: ["application/vnd.oasis.opendocument.spreadsheet"],
6050
+ odt: ["application/vnd.oasis.opendocument.text"],
6051
+ oga: ["audio/ogg"],
6052
+ ogv: ["video/ogg"],
6053
+ ogx: ["application/ogg"],
6054
+ opus: ["audio/opus"],
6055
+ otf: ["font/otf"],
6056
+ png: ["image/png"],
6057
+ pdf: ["application/pdf"],
6058
+ php: ["application/php"],
6059
+ ppt: ["application/vnd.ms-powerpoint"],
6060
+ pptx: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
6061
+ rar: ["application/vnd.rar", "application/x-rar", "application/x-rar-compressed"],
6062
+ rtf: ["application/rtf"],
6063
+ sh: ["application/x-sh"],
6064
+ svg: ["image/svg+xml"],
6065
+ swf: ["application/x-shockwave-flash"],
6066
+ tar: ["application/x-tar"],
6067
+ tif: ["image/tiff"],
6068
+ tiff: ["image/tiff"],
6069
+ ts: ["video/mp2t"],
6070
+ ttf: ["font/ttf"],
6071
+ txt: ["text/plain"],
6072
+ vsd: ["application/vnd.visio"],
6073
+ wav: ["audio/wav"],
6074
+ weba: ["audio/webm"],
6075
+ webm: ["video/webm"],
6076
+ webp: ["image/webp"],
6077
+ woff: ["font/woff"],
6078
+ woff2: ["font/woff2"],
6079
+ xhtml: ["application/xhtml+xml"],
6080
+ xls: ["application/vnd.ms-excel"],
6081
+ xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
6082
+ xml: ["application/xml", "text/xml"],
6083
+ xul: ["application/vnd.mozilla.xul+xml"],
6084
+ zip: ["application/zip", "application/x-zip-compressed", "multipart/x-zip"],
6085
+ "3gp": ["video/3gpp", "audio/3gpp"],
6086
+ "3g2": ["video/3gpp2", "audio/3gpp2"],
6087
+ "7z": ["application/x-7z-compressed"],
6088
+ };
6089
+ return acceptedExtensions.reduce((acc, ext) => acc.concat(lookupTable[ext]), []);
6090
+ }
6091
+ function snakeCaseToCamelCase(str) {
6092
+ const snakeCaseRegexp = /^([a-z0-9]*)(_[a-z0-9]*)*$/g;
6093
+ if (snakeCaseRegexp.test(str)) {
6094
+ let camelCase = "";
6095
+ let arr = str.split("_");
6096
+ arr.forEach((word, idx) => {
6097
+ camelCase += idx === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1);
6098
+ });
6099
+ return camelCase;
6100
+ }
6101
+ else {
6102
+ return str;
6103
+ }
6104
+ }
6105
+ function getNewIndexToFocus(currentIndex, direction, listLength) {
6106
+ let newIndex = currentIndex;
6107
+ if (direction === "ArrowDown") {
6108
+ newIndex = (currentIndex + 1) % listLength;
6109
+ }
6110
+ if (direction === "ArrowUp") {
6111
+ newIndex = currentIndex === 0 ? listLength - 1 : currentIndex - 1;
6112
+ }
6113
+ return newIndex;
6114
+ }
6115
+ function isRelatedTarget(ev, id) {
6116
+ // used for onBlur events to check the element that has been clicked
6117
+ const ids = id.split(" ");
6118
+ return ev.relatedTarget && ids.includes(ev.relatedTarget.id);
6119
+ }
6120
+ /*
6121
+ * this is going to be needed to solve the extra tabbing on navigator
6122
+ * and for programmatic focus of tabs
6123
+ * Here's a draft, not bug proof, see:
6124
+ * https://stackoverflow.com/a/10730308/3741713
6125
+
6126
+ function getKeyboardFocusableElements(element = document) {
6127
+ const els = Array.from(element.querySelectorAll('a, button, input, textarea, select, details, [tabindex]:not([tabindex="-1"]), wm-search, wm-timepicker, wm-tab-list, wm-tab-item, wm-button, wm-action-menu'));
6128
+ return els.filter((el: Element) => !el.hasAttribute("disabled")) as HTMLElement[];
6129
+ }
6130
+
6131
+ export function getPreviousKeyboardFocusableElement(element: HTMLElement) {
6132
+ const els = getKeyboardFocusableElements();
6133
+ const current = els.indexOf(element);
6134
+ return els[current - 1] as HTMLElement;
6135
+ }
6136
+
6137
+ export function getNextKeyboardFocusableElement(element: HTMLElement) {
6138
+ const els = getKeyboardFocusableElements();
6139
+ const current = els.indexOf(element);
6140
+ return els[current + 1] as HTMLElement;
6141
+ }
6142
6142
  */
6143
6143
 
6144
6144
  export { adjustTooltipPosition as a, getPosition as b, checkForActiveElInShadow as c, debounce as d, isRelatedTarget as e, findParentWithScrollbar as f, generateId as g, checkForFocusableElInShadow as h, intl as i, getFirstFocusableDescendant as j, getNewIndexToFocus as k, shouldOpenUp as l, shouldOpenDown as m, shouldShiftRight as n, shouldShiftLeft as o, hasValidType as p, getTextDir as q, hasRoomRight as r, snakeCaseToCamelCase as s };