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