@watermarkinsights/ripple 3.6.0-2 → 3.6.0-3

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 (173) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/{functions-0cf2d639.js → functions-068b9a56.js} +442 -442
  3. package/dist/cjs/{global-b6602785.js → global-4e77664e.js} +65 -65
  4. package/dist/cjs/{http-service-494d81de.js → http-service-9e8c4dd5.js} +49 -49
  5. package/dist/cjs/{interfaces-a3338581.js → interfaces-30a74c1f.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 +134 -134
  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 -421
  23. package/dist/cjs/wm-option_2.cjs.entry.js +494 -494
  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 +570 -570
  29. package/dist/cjs/wm-timepicker.cjs.entry.js +380 -380
  30. package/dist/cjs/wm-toggletip.cjs.entry.js +124 -124
  31. package/dist/cjs/wm-uploader.cjs.entry.js +347 -360
  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 +424 -424
  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 +720 -720
  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 +801 -801
  57. package/dist/collection/components/wm-timepicker/wm-timepicker.js +580 -580
  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 -772
  60. package/dist/collection/components/wm-uploader/wm-uploader.css +11 -18
  61. package/dist/collection/components/wm-uploader/wm-uploader.js +748 -794
  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/missing.js +39 -39
  72. package/dist/collection/lang/piglatin.js +93 -93
  73. package/dist/esm/{functions-223fb0dc.js → functions-122ab496.js} +442 -442
  74. package/dist/esm/{global-f9c17bf1.js → global-0fd112f7.js} +65 -65
  75. package/dist/esm/{http-service-3dc3b3e7.js → http-service-5d037e16.js} +49 -49
  76. package/dist/esm/{interfaces-2b97fab2.js → interfaces-61c6305b.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 -667
  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 +474 -474
  92. package/dist/esm/wm-datepicker.entry.js +256 -256
  93. package/dist/esm/wm-input.entry.js +134 -134
  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 -421
  99. package/dist/esm/wm-option_2.entry.js +494 -494
  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 +570 -570
  105. package/dist/esm/wm-timepicker.entry.js +380 -380
  106. package/dist/esm/wm-toggletip.entry.js +124 -124
  107. package/dist/esm/wm-uploader.entry.js +348 -361
  108. package/dist/esm/wm-wrapper.entry.js +12 -12
  109. package/dist/ripple/{p-e26c9858.entry.js → p-067909ce.entry.js} +1 -1
  110. package/dist/ripple/{p-cf075b3b.js → p-08e67884.js} +0 -0
  111. package/dist/ripple/{p-6b28f3fe.entry.js → p-1c23f228.entry.js} +1 -1
  112. package/dist/ripple/{p-c637686e.entry.js → p-2aa79663.entry.js} +1 -1
  113. package/dist/ripple/{p-d5938de0.entry.js → p-2b3f75eb.entry.js} +1 -1
  114. package/dist/ripple/{p-a84de435.entry.js → p-3ff67fd5.entry.js} +1 -1
  115. package/dist/ripple/{p-6d0b3f08.entry.js → p-4629470d.entry.js} +1 -1
  116. package/dist/ripple/p-4b1f14bb.entry.js +1 -0
  117. package/dist/ripple/{p-07f557b0.entry.js → p-4b72f4eb.entry.js} +1 -1
  118. package/dist/ripple/{p-1fdd85ea.entry.js → p-54c39a0b.entry.js} +1 -1
  119. package/dist/ripple/p-7da00f33.entry.js +1 -0
  120. package/dist/ripple/{p-addbfa91.entry.js → p-803b19aa.entry.js} +1 -1
  121. package/dist/ripple/{p-43f1298b.js → p-888bec42.js} +0 -0
  122. package/dist/ripple/{p-b14062a7.entry.js → p-888c18c3.entry.js} +1 -1
  123. package/dist/ripple/{p-94f584c5.entry.js → p-97884327.entry.js} +1 -1
  124. package/dist/ripple/{p-03f14a00.entry.js → p-9a8fbfad.entry.js} +1 -1
  125. package/dist/ripple/{p-f23d6211.entry.js → p-a2b02aec.entry.js} +1 -1
  126. package/dist/ripple/{p-c8655e6c.entry.js → p-a61b07de.entry.js} +1 -1
  127. package/dist/ripple/{p-fd8070fb.js → p-a6d6eae7.js} +0 -0
  128. package/dist/ripple/{p-c5d718c7.entry.js → p-e36853fd.entry.js} +1 -1
  129. package/dist/ripple/{p-0b1cdd4e.entry.js → p-ecbb441f.entry.js} +1 -1
  130. package/dist/ripple/{p-792a78d7.js → p-f2a1d8b1.js} +1 -1
  131. package/dist/ripple/{p-0663e9fc.entry.js → p-f6bed262.entry.js} +1 -1
  132. package/dist/ripple/{p-2d7891e9.entry.js → p-f95c2283.entry.js} +1 -1
  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 +82 -82
  139. package/dist/types/components/wm-datepicker/priv-datepicker/priv-datepicker.d.ts +76 -76
  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 -46
  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 +92 -92
  158. package/dist/types/components/wm-timepicker/wm-timepicker.d.ts +61 -61
  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 -86
  161. package/dist/types/components/wm-uploader/wm-uploader.d.ts +80 -84
  162. package/dist/types/components/wm-wrapper/wm-wrapper.d.ts +7 -7
  163. package/dist/types/components.d.ts +24 -30
  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 +47 -47
  172. package/dist/ripple/p-a1fc8e81.entry.js +0 -1
  173. package/dist/ripple/p-fb90d334.entry.js +0 -1
@@ -6339,448 +6339,448 @@ function createIntl(config, cache) {
6339
6339
  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) });
6340
6340
  }
6341
6341
 
6342
- const DEFAULT_LANGUAGE = "en";
6343
- function getBrowserLang() {
6344
- const langAttr = document.documentElement.getAttribute("lang");
6345
- if (!!langAttr) {
6346
- return langAttr;
6347
- }
6348
- else if (window.navigator && window.navigator.language) {
6349
- const lang = window.navigator.languages ? window.navigator.languages[0] : window.navigator.language;
6350
- return lang.slice(0, 2);
6351
- }
6352
- else {
6353
- return DEFAULT_LANGUAGE;
6354
- }
6355
- }
6356
- // prevents memory leak
6357
- const cache = createIntlCache();
6358
- const locale = getBrowserLang();
6359
- const intl = createIntl({
6360
- locale: locale,
6361
- defaultLocale: "en",
6362
- messages: lang[locale] || en,
6363
- }, cache);
6364
- function generateId() {
6365
- return "wmcl-" + Math.random().toString(36).substr(2, 10);
6366
- }
6367
- function debounce(fn, wait) {
6368
- let timeout;
6369
- return function () {
6370
- const context = this;
6371
- const functionCall = () => fn.apply(context, arguments);
6372
- clearTimeout(timeout);
6373
- timeout = setTimeout(functionCall, wait);
6374
- };
6375
- }
6376
- function getTextDir() {
6377
- const dir = document.querySelector("html").getAttribute("dir");
6378
- return dir ? dir.toLowerCase() : "";
6379
- }
6380
- function getPosition(el) {
6381
- const coords = el.getBoundingClientRect();
6382
- let x = coords.x;
6383
- let y = coords.y;
6384
- // Edge doesn't have x and y
6385
- if (!x) {
6386
- if (getTextDir() === "rtl") {
6387
- x = coords.right;
6388
- }
6389
- else {
6390
- x = coords.left;
6391
- }
6392
- y = coords.top;
6393
- }
6394
- return { x, y };
6395
- }
6396
- function findParentWithScrollbar(el) {
6397
- while (!!el) {
6398
- if (el.scrollHeight > el.clientHeight && ["scroll", "auto"].includes(window.getComputedStyle(el).overflowY)) {
6399
- return el;
6400
- }
6401
- el = el.parentElement;
6402
- }
6403
- }
6404
- function findParentWithHiddenOverflow(el) {
6405
- while (!!el) {
6406
- if (window.getComputedStyle(el).overflowY !== "visible") {
6407
- return el;
6408
- }
6409
- el = el.parentElement;
6410
- }
6411
- }
6412
- function getClosableElementMeasurements(fixedEl, closableEl) {
6413
- const parent = findParentWithHiddenOverflow(fixedEl);
6414
- // if parent is not found, measurements are checked against the viewport
6415
- return {
6416
- closableElHeight: closableEl.clientHeight,
6417
- closableElWidth: closableEl.clientWidth,
6418
- // NB boundingClientRect.bottom is space from top of viewport to bottom of el
6419
- // to get space below the el -> height of viewport minus boundingClientRect.bottom
6420
- spaceAbove: parent
6421
- ? fixedEl.getBoundingClientRect().top - parent.getBoundingClientRect().top
6422
- : fixedEl.getBoundingClientRect().top,
6423
- // NB boundingClientRect.bottom is space from top of viewport to bottom of el
6424
- // to get space below the el -> height of viewport minus boundingClientRect.bottom
6425
- spaceBelow: parent
6426
- ? parent.getBoundingClientRect().bottom - fixedEl.getBoundingClientRect().bottom
6427
- : document.documentElement.clientHeight - fixedEl.getBoundingClientRect().bottom,
6428
- spaceLeft: parent
6429
- ? fixedEl.getBoundingClientRect().left - parent.getBoundingClientRect().left
6430
- : fixedEl.getBoundingClientRect().left,
6431
- spaceRight: parent
6432
- ? parent.getBoundingClientRect().right - fixedEl.getBoundingClientRect().right
6433
- : document.documentElement.clientWidth - fixedEl.getBoundingClientRect().right,
6434
- };
6435
- }
6436
- function shouldOpenUp(fixedEl, //the element visible on the page when the component is closed
6437
- closableEl, //the dropdown/popup/etc that becomes visible when the component is open
6438
- offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
6439
- offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
6440
- ) {
6441
- const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
6442
- //we want to open up only if there's not enough space below AND there is enough space above
6443
- const openUp = closableElHeight > spaceBelow + offsetBelow && closableElHeight <= spaceAbove + offsetAbove;
6444
- return openUp;
6445
- }
6446
- function shouldOpenDown(fixedEl, //the element visible on the page when the component is closed
6447
- closableEl, //the dropdown/popup/etc that becomes visible when the component is open
6448
- offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
6449
- offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
6450
- ) {
6451
- const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
6452
- //we want to open up only if there's not enough space below AND there is enough space above
6453
- const openDown = closableElHeight > spaceAbove + offsetAbove && closableElHeight <= spaceBelow + offsetBelow;
6454
- return openDown;
6455
- }
6456
- function shouldShiftRight(fixedEl, closableEl) {
6457
- const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
6458
- const needsSpaceLeft = closableElWidth > spaceLeft && spaceRight > spaceLeft;
6459
- return needsSpaceLeft;
6460
- }
6461
- function shouldShiftLeft(fixedEl, closableEl) {
6462
- const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
6463
- const needsSpaceRight = closableElWidth > spaceRight && spaceLeft > spaceRight;
6464
- return needsSpaceRight;
6465
- }
6466
- function adjustTooltipPosition(tPos, el, tooltipEl) {
6467
- // position must be reset before measurements are taken in adjustTooltipPosition
6468
- // otherwise text-wrapping from previous position makes width measurement inconsistent
6469
- tooltipEl.style.top = "";
6470
- tooltipEl.style.left = "";
6471
- const { spaceLeft, spaceRight, spaceBelow, spaceAbove } = getClosableElementMeasurements(el, tooltipEl);
6472
- const tooltipWidth = tooltipEl.getBoundingClientRect().width;
6473
- const tooltipHeight = tooltipEl.getBoundingClientRect().height;
6474
- const enoughSpaceAbove = spaceAbove > tooltipHeight;
6475
- const enoughSpaceBelow = spaceBelow > tooltipHeight;
6476
- // a tooltip should never be closer than 24px to the edge of a screen
6477
- const enoughSpaceLeft = spaceLeft - 24 > tooltipWidth;
6478
- const enoughSpaceRight = spaceRight - 24 > tooltipWidth;
6479
- const swapAbove = (position) => {
6480
- return !enoughSpaceAbove ? position.replace("top", "bottom") : position;
6481
- };
6482
- const swapBelow = (position) => {
6483
- return !enoughSpaceBelow && enoughSpaceAbove ? position.replace("bottom", "top") : position;
6484
- };
6485
- const swapLeft = (position, centeredPosition) => {
6486
- if (!enoughSpaceLeft && enoughSpaceRight) {
6487
- position = position.replace("left", "right");
6488
- }
6489
- else if (!enoughSpaceLeft && !enoughSpaceRight) {
6490
- position = centeredPosition;
6491
- }
6492
- return position;
6493
- };
6494
- const swapRight = (position, centeredPosition) => {
6495
- if (!enoughSpaceRight && enoughSpaceLeft) {
6496
- position = position.replace("right", "left");
6497
- }
6498
- else if (!enoughSpaceRight && !enoughSpaceLeft) {
6499
- position = centeredPosition;
6500
- }
6501
- return position;
6502
- };
6503
- // horizontal checks must occur before vertical checks, because horizontal can affect vertical positioning but not vice versa
6504
- switch (tPos) {
6505
- case "left":
6506
- tPos = swapLeft(tPos, "bottom");
6507
- case "right":
6508
- tPos = swapRight(tPos, "bottom");
6509
- case "top-left":
6510
- tPos = swapLeft(tPos, "top");
6511
- tPos = swapAbove(tPos);
6512
- case "top-right":
6513
- tPos = swapRight(tPos, "top");
6514
- tPos = swapAbove(tPos);
6515
- case "bottom-left":
6516
- tPos = swapLeft(tPos, "bottom");
6517
- tPos = swapBelow(tPos);
6518
- case "bottom-right":
6519
- tPos = swapRight(tPos, "bottom");
6520
- tPos = swapBelow(tPos);
6521
- case "top":
6522
- tPos = swapAbove(tPos);
6523
- case "bottom":
6524
- tPos = swapBelow(tPos);
6525
- }
6526
- return tPos;
6527
- }
6528
- function hasRoomRight(x, spaceNeeded) {
6529
- let horizOffset = 0;
6530
- // if (getTextDir() === "ltr") {
6531
- if (x.type === "click") {
6532
- // if it's a mouse event, deal with mouse coords
6533
- horizOffset = x.clientX;
6534
- // if it's a focus event, the offset is 0
6535
- }
6536
- else if (x.type === "focus") {
6537
- horizOffset = 0;
6538
- }
6539
- else {
6540
- // otherwise an element was passed, calculate how far it is from the edge of the window
6541
- let el = x; // re-assignment is for clarity
6542
- while (el) {
6543
- if (el.tagName == "BODY") {
6544
- // deal with browser quirks with body/window/document and page scroll
6545
- var xScroll = el.scrollLeft || document.documentElement.scrollLeft;
6546
- horizOffset += el.offsetLeft - xScroll + el.clientLeft;
6547
- }
6548
- else {
6549
- // for all other non-BODY elements
6550
- horizOffset += el.offsetLeft - el.scrollLeft + el.clientLeft;
6551
- }
6552
- el = el.offsetParent;
6553
- }
6554
- // }
6555
- }
6556
- return window.innerWidth - horizOffset >= spaceNeeded;
6557
- }
6558
- function checkForActiveElInShadow(element) {
6559
- while (element && element.shadowRoot) {
6560
- element = element.shadowRoot.activeElement;
6561
- }
6562
- return element;
6563
- }
6564
- function checkForFocusableElInShadow(element) {
6565
- const selectors = [
6566
- "button",
6567
- "a",
6568
- "input",
6569
- "select",
6570
- "textarea",
6571
- "wm-button",
6572
- "wm-search",
6573
- "wm-select",
6574
- "wm-action-menu",
6575
- "wm-tab-item",
6576
- "wm-datepicker",
6577
- ];
6578
- let focusableEl = element;
6579
- selectors.forEach((selector) => {
6580
- if (focusableEl && focusableEl.shadowRoot) {
6581
- let elInShadow = focusableEl.shadowRoot.querySelector(selector);
6582
- if (elInShadow) {
6583
- if (selector.startsWith("wm-")) {
6584
- focusableEl = checkForFocusableElInShadow(elInShadow);
6585
- }
6586
- else {
6587
- focusableEl = elInShadow;
6588
- }
6589
- }
6590
- }
6591
- });
6592
- return focusableEl;
6593
- }
6594
- function isFocusable(element) {
6595
- if (element.tabIndex > 0 || (element.tabIndex === 0 && element.getAttribute("tabIndex") !== null)) {
6596
- return true;
6597
- }
6598
- if (element.disabled) {
6599
- return false;
6600
- }
6601
- switch (element.nodeName) {
6602
- case "A":
6603
- return !!element.href && element.rel != "ignore";
6604
- case "INPUT":
6605
- return element.type != "hidden" && element.type != "file";
6606
- case "BUTTON":
6607
- case "SELECT":
6608
- case "TEXTAREA":
6609
- case "WM-BUTTON":
6610
- case "WM-SELECT":
6611
- case "WM-ACTION-MENU":
6612
- case "WM-DATEPICKER":
6613
- case "WM-TIMEPICKER":
6614
- case "WM-INPUT":
6615
- case "WM-TAG-INPUT":
6616
- case "WM-TAB-ITEM":
6617
- case "WM-SEARCH":
6618
- return true;
6619
- default:
6620
- return false;
6621
- }
6622
- }
6623
- function getFirstFocusableDescendant(element) {
6624
- if (isFocusable(element)) {
6625
- return checkForFocusableElInShadow(element);
6626
- }
6627
- else if (element.childNodes.length > 0) {
6628
- element.childNodes.forEach((i) => {
6629
- const childEl = getFirstFocusableDescendant(i);
6630
- return childEl && checkForFocusableElInShadow(childEl);
6631
- });
6632
- }
6633
- }
6634
- function hasValidType(file, types) {
6635
- const acceptedExtensions = types.split(" ");
6636
- const parts = file.name && file.name.split(".");
6637
- const ext = parts && parts.length > 1 && parts[parts.length - 1];
6638
- return ext
6639
- ? acceptedExtensions.includes(ext.toLowerCase())
6640
- : // fallback: if we couldn't obtain an extension,
6641
- // validate based on MIME type...
6642
- !!file.type
6643
- ? getAcceptedMimeTypesList(acceptedExtensions).includes(file.type)
6644
- : // ...and if that failed too, accept the file
6645
- // as it's preferable to accept an invalid file
6646
- // than refusing a valid one (back-end will take care of what slips through)
6647
- true;
6648
- }
6649
- // takes a string (space separated list of extensions), returns an array of strings (corresponding MIME types)
6650
- function getAcceptedMimeTypesList(acceptedExtensions) {
6651
- // this is just a list of common file types (regardless of whether they are/can be valid or not)
6652
- // front end checks are just a convenience to users, independent of security.
6653
- // it allows users to be notified of an invalid type as soon as they select the file, rather than when it gets uploaded
6654
- const lookupTable = {
6655
- aac: ["audio/aac"],
6656
- abw: ["application/x-abiword"],
6657
- arc: ["application/x-freearc"],
6658
- avi: ["video/x-msvideo"],
6659
- azw: ["application/vnd.amazon.ebook"],
6660
- bin: ["application/octet-stream"],
6661
- bmp: ["image/bmp"],
6662
- bz: ["application/x-bzip"],
6663
- bz2: ["application/x-bzip2"],
6664
- csh: ["application/x-csh"],
6665
- css: ["text/css"],
6666
- csv: ["text/csv"],
6667
- doc: ["application/msword"],
6668
- docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
6669
- eot: ["application/vnd.ms-fontobject"],
6670
- epub: ["application/epub+zip"],
6671
- gz: ["application/gzip"],
6672
- gif: ["image/gif"],
6673
- htm: ["text/html"],
6674
- html: ["text/html"],
6675
- ico: ["image/vnd.microsoft.icon"],
6676
- ics: ["text/calendar"],
6677
- jar: ["application/java-archive"],
6678
- jpeg: ["image/jpeg"],
6679
- jpg: ["image/jpeg"],
6680
- js: ["text/javascript"],
6681
- json: ["application/json"],
6682
- jsonld: ["application/ld+json"],
6683
- log: ["text/plain"],
6684
- mid: ["audio/x-midi"],
6685
- midi: ["audio/x-midi"],
6686
- mjs: ["text/javascript"],
6687
- mp3: ["audio/mpeg"],
6688
- mpeg: ["video/mpeg"],
6689
- mpkg: ["application/vnd.apple.installer+xml"],
6690
- odp: ["application/vnd.oasis.opendocument.presentation"],
6691
- ods: ["application/vnd.oasis.opendocument.spreadsheet"],
6692
- odt: ["application/vnd.oasis.opendocument.text"],
6693
- oga: ["audio/ogg"],
6694
- ogv: ["video/ogg"],
6695
- ogx: ["application/ogg"],
6696
- opus: ["audio/opus"],
6697
- otf: ["font/otf"],
6698
- png: ["image/png"],
6699
- pdf: ["application/pdf"],
6700
- php: ["application/php"],
6701
- ppt: ["application/vnd.ms-powerpoint"],
6702
- pptx: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
6703
- rar: ["application/vnd.rar", "application/x-rar", "application/x-rar-compressed"],
6704
- rtf: ["application/rtf"],
6705
- sh: ["application/x-sh"],
6706
- svg: ["image/svg+xml"],
6707
- swf: ["application/x-shockwave-flash"],
6708
- tar: ["application/x-tar"],
6709
- tif: ["image/tiff"],
6710
- tiff: ["image/tiff"],
6711
- ts: ["video/mp2t"],
6712
- ttf: ["font/ttf"],
6713
- txt: ["text/plain"],
6714
- vsd: ["application/vnd.visio"],
6715
- wav: ["audio/wav"],
6716
- weba: ["audio/webm"],
6717
- webm: ["video/webm"],
6718
- webp: ["image/webp"],
6719
- woff: ["font/woff"],
6720
- woff2: ["font/woff2"],
6721
- xhtml: ["application/xhtml+xml"],
6722
- xls: ["application/vnd.ms-excel"],
6723
- xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
6724
- xml: ["application/xml", "text/xml"],
6725
- xul: ["application/vnd.mozilla.xul+xml"],
6726
- zip: ["application/zip", "application/x-zip-compressed", "multipart/x-zip"],
6727
- "3gp": ["video/3gpp", "audio/3gpp"],
6728
- "3g2": ["video/3gpp2", "audio/3gpp2"],
6729
- "7z": ["application/x-7z-compressed"],
6730
- };
6731
- return acceptedExtensions.reduce((acc, ext) => acc.concat(lookupTable[ext]), []);
6732
- }
6733
- function snakeCaseToCamelCase(str) {
6734
- const snakeCaseRegexp = /^([a-z0-9]*)(_[a-z0-9]*)*$/g;
6735
- if (snakeCaseRegexp.test(str)) {
6736
- let camelCase = "";
6737
- let arr = str.split("_");
6738
- arr.forEach((word, idx) => {
6739
- camelCase += idx === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1);
6740
- });
6741
- return camelCase;
6742
- }
6743
- else {
6744
- return str;
6745
- }
6746
- }
6747
- function getNewIndexToFocus(currentIndex, direction, listLength) {
6748
- let newIndex = currentIndex;
6749
- if (direction === "ArrowDown") {
6750
- newIndex = (currentIndex + 1) % listLength;
6751
- }
6752
- if (direction === "ArrowUp") {
6753
- newIndex = currentIndex === 0 ? listLength - 1 : currentIndex - 1;
6754
- }
6755
- return newIndex;
6756
- }
6757
- function isRelatedTarget(ev, id) {
6758
- // used for onBlur events to check the element that has been clicked
6759
- const ids = id.split(" ");
6760
- return ev.relatedTarget && ids.includes(ev.relatedTarget.id);
6761
- }
6762
- /*
6763
- * this is going to be needed to solve the extra tabbing on navigator
6764
- * and for programmatic focus of tabs
6765
- * Here's a draft, not bug proof, see:
6766
- * https://stackoverflow.com/a/10730308/3741713
6767
-
6768
- function getKeyboardFocusableElements(element = document) {
6769
- 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'));
6770
- return els.filter((el: Element) => !el.hasAttribute("disabled")) as HTMLElement[];
6771
- }
6772
-
6773
- export function getPreviousKeyboardFocusableElement(element: HTMLElement) {
6774
- const els = getKeyboardFocusableElements();
6775
- const current = els.indexOf(element);
6776
- return els[current - 1] as HTMLElement;
6777
- }
6778
-
6779
- export function getNextKeyboardFocusableElement(element: HTMLElement) {
6780
- const els = getKeyboardFocusableElements();
6781
- const current = els.indexOf(element);
6782
- return els[current + 1] as HTMLElement;
6783
- }
6342
+ const DEFAULT_LANGUAGE = "en";
6343
+ function getBrowserLang() {
6344
+ const langAttr = document.documentElement.getAttribute("lang");
6345
+ if (!!langAttr) {
6346
+ return langAttr;
6347
+ }
6348
+ else if (window.navigator && window.navigator.language) {
6349
+ const lang = window.navigator.languages ? window.navigator.languages[0] : window.navigator.language;
6350
+ return lang.slice(0, 2);
6351
+ }
6352
+ else {
6353
+ return DEFAULT_LANGUAGE;
6354
+ }
6355
+ }
6356
+ // prevents memory leak
6357
+ const cache = createIntlCache();
6358
+ const locale = getBrowserLang();
6359
+ const intl = createIntl({
6360
+ locale: locale,
6361
+ defaultLocale: "en",
6362
+ messages: lang[locale] || en,
6363
+ }, cache);
6364
+ function generateId() {
6365
+ return "wmcl-" + Math.random().toString(36).substr(2, 10);
6366
+ }
6367
+ function debounce(fn, wait) {
6368
+ let timeout;
6369
+ return function () {
6370
+ const context = this;
6371
+ const functionCall = () => fn.apply(context, arguments);
6372
+ clearTimeout(timeout);
6373
+ timeout = setTimeout(functionCall, wait);
6374
+ };
6375
+ }
6376
+ function getTextDir() {
6377
+ const dir = document.querySelector("html").getAttribute("dir");
6378
+ return dir ? dir.toLowerCase() : "";
6379
+ }
6380
+ function getPosition(el) {
6381
+ const coords = el.getBoundingClientRect();
6382
+ let x = coords.x;
6383
+ let y = coords.y;
6384
+ // Edge doesn't have x and y
6385
+ if (!x) {
6386
+ if (getTextDir() === "rtl") {
6387
+ x = coords.right;
6388
+ }
6389
+ else {
6390
+ x = coords.left;
6391
+ }
6392
+ y = coords.top;
6393
+ }
6394
+ return { x, y };
6395
+ }
6396
+ function findParentWithScrollbar(el) {
6397
+ while (!!el) {
6398
+ if (el.scrollHeight > el.clientHeight && ["scroll", "auto"].includes(window.getComputedStyle(el).overflowY)) {
6399
+ return el;
6400
+ }
6401
+ el = el.parentElement;
6402
+ }
6403
+ }
6404
+ function findParentWithHiddenOverflow(el) {
6405
+ while (!!el) {
6406
+ if (window.getComputedStyle(el).overflowY !== "visible") {
6407
+ return el;
6408
+ }
6409
+ el = el.parentElement;
6410
+ }
6411
+ }
6412
+ function getClosableElementMeasurements(fixedEl, closableEl) {
6413
+ const parent = findParentWithHiddenOverflow(fixedEl);
6414
+ // if parent is not found, measurements are checked against the viewport
6415
+ return {
6416
+ closableElHeight: closableEl.clientHeight,
6417
+ closableElWidth: closableEl.clientWidth,
6418
+ // NB boundingClientRect.bottom is space from top of viewport to bottom of el
6419
+ // to get space below the el -> height of viewport minus boundingClientRect.bottom
6420
+ spaceAbove: parent
6421
+ ? fixedEl.getBoundingClientRect().top - parent.getBoundingClientRect().top
6422
+ : fixedEl.getBoundingClientRect().top,
6423
+ // NB boundingClientRect.bottom is space from top of viewport to bottom of el
6424
+ // to get space below the el -> height of viewport minus boundingClientRect.bottom
6425
+ spaceBelow: parent
6426
+ ? parent.getBoundingClientRect().bottom - fixedEl.getBoundingClientRect().bottom
6427
+ : document.documentElement.clientHeight - fixedEl.getBoundingClientRect().bottom,
6428
+ spaceLeft: parent
6429
+ ? fixedEl.getBoundingClientRect().left - parent.getBoundingClientRect().left
6430
+ : fixedEl.getBoundingClientRect().left,
6431
+ spaceRight: parent
6432
+ ? parent.getBoundingClientRect().right - fixedEl.getBoundingClientRect().right
6433
+ : document.documentElement.clientWidth - fixedEl.getBoundingClientRect().right,
6434
+ };
6435
+ }
6436
+ function shouldOpenUp(fixedEl, //the element visible on the page when the component is closed
6437
+ closableEl, //the dropdown/popup/etc that becomes visible when the component is open
6438
+ offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
6439
+ offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
6440
+ ) {
6441
+ const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
6442
+ //we want to open up only if there's not enough space below AND there is enough space above
6443
+ const openUp = closableElHeight > spaceBelow + offsetBelow && closableElHeight <= spaceAbove + offsetAbove;
6444
+ return openUp;
6445
+ }
6446
+ function shouldOpenDown(fixedEl, //the element visible on the page when the component is closed
6447
+ closableEl, //the dropdown/popup/etc that becomes visible when the component is open
6448
+ offsetAbove = 0, // if closableEl covers a part of fixedEl, that part should be offset
6449
+ offsetBelow = 0 // if closableEl covers a part of fixedEl, that part should be offset
6450
+ ) {
6451
+ const { closableElHeight, spaceAbove, spaceBelow } = getClosableElementMeasurements(fixedEl, closableEl);
6452
+ //we want to open up only if there's not enough space below AND there is enough space above
6453
+ const openDown = closableElHeight > spaceAbove + offsetAbove && closableElHeight <= spaceBelow + offsetBelow;
6454
+ return openDown;
6455
+ }
6456
+ function shouldShiftRight(fixedEl, closableEl) {
6457
+ const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
6458
+ const needsSpaceLeft = closableElWidth > spaceLeft && spaceRight > spaceLeft;
6459
+ return needsSpaceLeft;
6460
+ }
6461
+ function shouldShiftLeft(fixedEl, closableEl) {
6462
+ const { closableElWidth, spaceLeft, spaceRight } = getClosableElementMeasurements(fixedEl, closableEl);
6463
+ const needsSpaceRight = closableElWidth > spaceRight && spaceLeft > spaceRight;
6464
+ return needsSpaceRight;
6465
+ }
6466
+ function adjustTooltipPosition(tPos, el, tooltipEl) {
6467
+ // position must be reset before measurements are taken in adjustTooltipPosition
6468
+ // otherwise text-wrapping from previous position makes width measurement inconsistent
6469
+ tooltipEl.style.top = "";
6470
+ tooltipEl.style.left = "";
6471
+ const { spaceLeft, spaceRight, spaceBelow, spaceAbove } = getClosableElementMeasurements(el, tooltipEl);
6472
+ const tooltipWidth = tooltipEl.getBoundingClientRect().width;
6473
+ const tooltipHeight = tooltipEl.getBoundingClientRect().height;
6474
+ const enoughSpaceAbove = spaceAbove > tooltipHeight;
6475
+ const enoughSpaceBelow = spaceBelow > tooltipHeight;
6476
+ // a tooltip should never be closer than 24px to the edge of a screen
6477
+ const enoughSpaceLeft = spaceLeft - 24 > tooltipWidth;
6478
+ const enoughSpaceRight = spaceRight - 24 > tooltipWidth;
6479
+ const swapAbove = (position) => {
6480
+ return !enoughSpaceAbove ? position.replace("top", "bottom") : position;
6481
+ };
6482
+ const swapBelow = (position) => {
6483
+ return !enoughSpaceBelow && enoughSpaceAbove ? position.replace("bottom", "top") : position;
6484
+ };
6485
+ const swapLeft = (position, centeredPosition) => {
6486
+ if (!enoughSpaceLeft && enoughSpaceRight) {
6487
+ position = position.replace("left", "right");
6488
+ }
6489
+ else if (!enoughSpaceLeft && !enoughSpaceRight) {
6490
+ position = centeredPosition;
6491
+ }
6492
+ return position;
6493
+ };
6494
+ const swapRight = (position, centeredPosition) => {
6495
+ if (!enoughSpaceRight && enoughSpaceLeft) {
6496
+ position = position.replace("right", "left");
6497
+ }
6498
+ else if (!enoughSpaceRight && !enoughSpaceLeft) {
6499
+ position = centeredPosition;
6500
+ }
6501
+ return position;
6502
+ };
6503
+ // horizontal checks must occur before vertical checks, because horizontal can affect vertical positioning but not vice versa
6504
+ switch (tPos) {
6505
+ case "left":
6506
+ tPos = swapLeft(tPos, "bottom");
6507
+ case "right":
6508
+ tPos = swapRight(tPos, "bottom");
6509
+ case "top-left":
6510
+ tPos = swapLeft(tPos, "top");
6511
+ tPos = swapAbove(tPos);
6512
+ case "top-right":
6513
+ tPos = swapRight(tPos, "top");
6514
+ tPos = swapAbove(tPos);
6515
+ case "bottom-left":
6516
+ tPos = swapLeft(tPos, "bottom");
6517
+ tPos = swapBelow(tPos);
6518
+ case "bottom-right":
6519
+ tPos = swapRight(tPos, "bottom");
6520
+ tPos = swapBelow(tPos);
6521
+ case "top":
6522
+ tPos = swapAbove(tPos);
6523
+ case "bottom":
6524
+ tPos = swapBelow(tPos);
6525
+ }
6526
+ return tPos;
6527
+ }
6528
+ function hasRoomRight(x, spaceNeeded) {
6529
+ let horizOffset = 0;
6530
+ // if (getTextDir() === "ltr") {
6531
+ if (x.type === "click") {
6532
+ // if it's a mouse event, deal with mouse coords
6533
+ horizOffset = x.clientX;
6534
+ // if it's a focus event, the offset is 0
6535
+ }
6536
+ else if (x.type === "focus") {
6537
+ horizOffset = 0;
6538
+ }
6539
+ else {
6540
+ // otherwise an element was passed, calculate how far it is from the edge of the window
6541
+ let el = x; // re-assignment is for clarity
6542
+ while (el) {
6543
+ if (el.tagName == "BODY") {
6544
+ // deal with browser quirks with body/window/document and page scroll
6545
+ var xScroll = el.scrollLeft || document.documentElement.scrollLeft;
6546
+ horizOffset += el.offsetLeft - xScroll + el.clientLeft;
6547
+ }
6548
+ else {
6549
+ // for all other non-BODY elements
6550
+ horizOffset += el.offsetLeft - el.scrollLeft + el.clientLeft;
6551
+ }
6552
+ el = el.offsetParent;
6553
+ }
6554
+ // }
6555
+ }
6556
+ return window.innerWidth - horizOffset >= spaceNeeded;
6557
+ }
6558
+ function checkForActiveElInShadow(element) {
6559
+ while (element && element.shadowRoot) {
6560
+ element = element.shadowRoot.activeElement;
6561
+ }
6562
+ return element;
6563
+ }
6564
+ function checkForFocusableElInShadow(element) {
6565
+ const selectors = [
6566
+ "button",
6567
+ "a",
6568
+ "input",
6569
+ "select",
6570
+ "textarea",
6571
+ "wm-button",
6572
+ "wm-search",
6573
+ "wm-select",
6574
+ "wm-action-menu",
6575
+ "wm-tab-item",
6576
+ "wm-datepicker",
6577
+ ];
6578
+ let focusableEl = element;
6579
+ selectors.forEach((selector) => {
6580
+ if (focusableEl && focusableEl.shadowRoot) {
6581
+ let elInShadow = focusableEl.shadowRoot.querySelector(selector);
6582
+ if (elInShadow) {
6583
+ if (selector.startsWith("wm-")) {
6584
+ focusableEl = checkForFocusableElInShadow(elInShadow);
6585
+ }
6586
+ else {
6587
+ focusableEl = elInShadow;
6588
+ }
6589
+ }
6590
+ }
6591
+ });
6592
+ return focusableEl;
6593
+ }
6594
+ function isFocusable(element) {
6595
+ if (element.tabIndex > 0 || (element.tabIndex === 0 && element.getAttribute("tabIndex") !== null)) {
6596
+ return true;
6597
+ }
6598
+ if (element.disabled) {
6599
+ return false;
6600
+ }
6601
+ switch (element.nodeName) {
6602
+ case "A":
6603
+ return !!element.href && element.rel != "ignore";
6604
+ case "INPUT":
6605
+ return element.type != "hidden" && element.type != "file";
6606
+ case "BUTTON":
6607
+ case "SELECT":
6608
+ case "TEXTAREA":
6609
+ case "WM-BUTTON":
6610
+ case "WM-SELECT":
6611
+ case "WM-ACTION-MENU":
6612
+ case "WM-DATEPICKER":
6613
+ case "WM-TIMEPICKER":
6614
+ case "WM-INPUT":
6615
+ case "WM-TAG-INPUT":
6616
+ case "WM-TAB-ITEM":
6617
+ case "WM-SEARCH":
6618
+ return true;
6619
+ default:
6620
+ return false;
6621
+ }
6622
+ }
6623
+ function getFirstFocusableDescendant(element) {
6624
+ if (isFocusable(element)) {
6625
+ return checkForFocusableElInShadow(element);
6626
+ }
6627
+ else if (element.childNodes.length > 0) {
6628
+ element.childNodes.forEach((i) => {
6629
+ const childEl = getFirstFocusableDescendant(i);
6630
+ return childEl && checkForFocusableElInShadow(childEl);
6631
+ });
6632
+ }
6633
+ }
6634
+ function hasValidType(file, types) {
6635
+ const acceptedExtensions = types.split(" ");
6636
+ const parts = file.name && file.name.split(".");
6637
+ const ext = parts && parts.length > 1 && parts[parts.length - 1];
6638
+ return ext
6639
+ ? acceptedExtensions.includes(ext.toLowerCase())
6640
+ : // fallback: if we couldn't obtain an extension,
6641
+ // validate based on MIME type...
6642
+ !!file.type
6643
+ ? getAcceptedMimeTypesList(acceptedExtensions).includes(file.type)
6644
+ : // ...and if that failed too, accept the file
6645
+ // as it's preferable to accept an invalid file
6646
+ // than refusing a valid one (back-end will take care of what slips through)
6647
+ true;
6648
+ }
6649
+ // takes a string (space separated list of extensions), returns an array of strings (corresponding MIME types)
6650
+ function getAcceptedMimeTypesList(acceptedExtensions) {
6651
+ // this is just a list of common file types (regardless of whether they are/can be valid or not)
6652
+ // front end checks are just a convenience to users, independent of security.
6653
+ // it allows users to be notified of an invalid type as soon as they select the file, rather than when it gets uploaded
6654
+ const lookupTable = {
6655
+ aac: ["audio/aac"],
6656
+ abw: ["application/x-abiword"],
6657
+ arc: ["application/x-freearc"],
6658
+ avi: ["video/x-msvideo"],
6659
+ azw: ["application/vnd.amazon.ebook"],
6660
+ bin: ["application/octet-stream"],
6661
+ bmp: ["image/bmp"],
6662
+ bz: ["application/x-bzip"],
6663
+ bz2: ["application/x-bzip2"],
6664
+ csh: ["application/x-csh"],
6665
+ css: ["text/css"],
6666
+ csv: ["text/csv"],
6667
+ doc: ["application/msword"],
6668
+ docx: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
6669
+ eot: ["application/vnd.ms-fontobject"],
6670
+ epub: ["application/epub+zip"],
6671
+ gz: ["application/gzip"],
6672
+ gif: ["image/gif"],
6673
+ htm: ["text/html"],
6674
+ html: ["text/html"],
6675
+ ico: ["image/vnd.microsoft.icon"],
6676
+ ics: ["text/calendar"],
6677
+ jar: ["application/java-archive"],
6678
+ jpeg: ["image/jpeg"],
6679
+ jpg: ["image/jpeg"],
6680
+ js: ["text/javascript"],
6681
+ json: ["application/json"],
6682
+ jsonld: ["application/ld+json"],
6683
+ log: ["text/plain"],
6684
+ mid: ["audio/x-midi"],
6685
+ midi: ["audio/x-midi"],
6686
+ mjs: ["text/javascript"],
6687
+ mp3: ["audio/mpeg"],
6688
+ mpeg: ["video/mpeg"],
6689
+ mpkg: ["application/vnd.apple.installer+xml"],
6690
+ odp: ["application/vnd.oasis.opendocument.presentation"],
6691
+ ods: ["application/vnd.oasis.opendocument.spreadsheet"],
6692
+ odt: ["application/vnd.oasis.opendocument.text"],
6693
+ oga: ["audio/ogg"],
6694
+ ogv: ["video/ogg"],
6695
+ ogx: ["application/ogg"],
6696
+ opus: ["audio/opus"],
6697
+ otf: ["font/otf"],
6698
+ png: ["image/png"],
6699
+ pdf: ["application/pdf"],
6700
+ php: ["application/php"],
6701
+ ppt: ["application/vnd.ms-powerpoint"],
6702
+ pptx: ["application/vnd.openxmlformats-officedocument.presentationml.presentation"],
6703
+ rar: ["application/vnd.rar", "application/x-rar", "application/x-rar-compressed"],
6704
+ rtf: ["application/rtf"],
6705
+ sh: ["application/x-sh"],
6706
+ svg: ["image/svg+xml"],
6707
+ swf: ["application/x-shockwave-flash"],
6708
+ tar: ["application/x-tar"],
6709
+ tif: ["image/tiff"],
6710
+ tiff: ["image/tiff"],
6711
+ ts: ["video/mp2t"],
6712
+ ttf: ["font/ttf"],
6713
+ txt: ["text/plain"],
6714
+ vsd: ["application/vnd.visio"],
6715
+ wav: ["audio/wav"],
6716
+ weba: ["audio/webm"],
6717
+ webm: ["video/webm"],
6718
+ webp: ["image/webp"],
6719
+ woff: ["font/woff"],
6720
+ woff2: ["font/woff2"],
6721
+ xhtml: ["application/xhtml+xml"],
6722
+ xls: ["application/vnd.ms-excel"],
6723
+ xlsx: ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
6724
+ xml: ["application/xml", "text/xml"],
6725
+ xul: ["application/vnd.mozilla.xul+xml"],
6726
+ zip: ["application/zip", "application/x-zip-compressed", "multipart/x-zip"],
6727
+ "3gp": ["video/3gpp", "audio/3gpp"],
6728
+ "3g2": ["video/3gpp2", "audio/3gpp2"],
6729
+ "7z": ["application/x-7z-compressed"],
6730
+ };
6731
+ return acceptedExtensions.reduce((acc, ext) => acc.concat(lookupTable[ext]), []);
6732
+ }
6733
+ function snakeCaseToCamelCase(str) {
6734
+ const snakeCaseRegexp = /^([a-z0-9]*)(_[a-z0-9]*)*$/g;
6735
+ if (snakeCaseRegexp.test(str)) {
6736
+ let camelCase = "";
6737
+ let arr = str.split("_");
6738
+ arr.forEach((word, idx) => {
6739
+ camelCase += idx === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1);
6740
+ });
6741
+ return camelCase;
6742
+ }
6743
+ else {
6744
+ return str;
6745
+ }
6746
+ }
6747
+ function getNewIndexToFocus(currentIndex, direction, listLength) {
6748
+ let newIndex = currentIndex;
6749
+ if (direction === "ArrowDown") {
6750
+ newIndex = (currentIndex + 1) % listLength;
6751
+ }
6752
+ if (direction === "ArrowUp") {
6753
+ newIndex = currentIndex === 0 ? listLength - 1 : currentIndex - 1;
6754
+ }
6755
+ return newIndex;
6756
+ }
6757
+ function isRelatedTarget(ev, id) {
6758
+ // used for onBlur events to check the element that has been clicked
6759
+ const ids = id.split(" ");
6760
+ return ev.relatedTarget && ids.includes(ev.relatedTarget.id);
6761
+ }
6762
+ /*
6763
+ * this is going to be needed to solve the extra tabbing on navigator
6764
+ * and for programmatic focus of tabs
6765
+ * Here's a draft, not bug proof, see:
6766
+ * https://stackoverflow.com/a/10730308/3741713
6767
+
6768
+ function getKeyboardFocusableElements(element = document) {
6769
+ 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'));
6770
+ return els.filter((el: Element) => !el.hasAttribute("disabled")) as HTMLElement[];
6771
+ }
6772
+
6773
+ export function getPreviousKeyboardFocusableElement(element: HTMLElement) {
6774
+ const els = getKeyboardFocusableElements();
6775
+ const current = els.indexOf(element);
6776
+ return els[current - 1] as HTMLElement;
6777
+ }
6778
+
6779
+ export function getNextKeyboardFocusableElement(element: HTMLElement) {
6780
+ const els = getKeyboardFocusableElements();
6781
+ const current = els.indexOf(element);
6782
+ return els[current + 1] as HTMLElement;
6783
+ }
6784
6784
  */
6785
6785
 
6786
6786
  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 };