@watermarkinsights/ripple 3.3.2-0 → 3.4.0-2

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