@duetds/components 4.30.1 → 4.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/hydrate/index.js +230 -1038
  2. package/lib/cjs/duet-alert.cjs.entry.js +4 -2
  3. package/lib/cjs/duet-badge.cjs.entry.js +2 -2
  4. package/lib/cjs/duet-button_2.cjs.entry.js +4 -3
  5. package/lib/cjs/duet-caption_4.cjs.entry.js +7 -8
  6. package/lib/cjs/duet-card.cjs.entry.js +4 -4
  7. package/lib/cjs/duet-checkbox.cjs.entry.js +1 -1
  8. package/lib/cjs/duet-choice_2.cjs.entry.js +4 -3
  9. package/lib/cjs/duet-collapsible.cjs.entry.js +2 -2
  10. package/lib/cjs/duet-cookie-consent.cjs.entry.js +1 -1
  11. package/lib/cjs/duet-date-picker.cjs.entry.js +22 -12
  12. package/lib/cjs/duet-divider_2.cjs.entry.js +1 -1
  13. package/lib/cjs/duet-empty-state.cjs.entry.js +1 -1
  14. package/lib/cjs/duet-fieldset.cjs.entry.js +1 -1
  15. package/lib/cjs/duet-footer.cjs.entry.js +4 -4
  16. package/lib/cjs/duet-grid_2.cjs.entry.js +1 -1
  17. package/lib/cjs/duet-header_2.cjs.entry.js +25 -9
  18. package/lib/cjs/duet-hero.cjs.entry.js +6 -6
  19. package/lib/cjs/duet-icon.cjs.entry.js +3 -3
  20. package/lib/cjs/duet-input_2.cjs.entry.js +2 -2
  21. package/lib/cjs/duet-layout.cjs.entry.js +1 -1
  22. package/lib/cjs/duet-list_2.cjs.entry.js +1 -1
  23. package/lib/cjs/duet-modal.cjs.entry.js +8 -7
  24. package/lib/cjs/duet-notification_2.cjs.entry.js +6 -5
  25. package/lib/cjs/duet-number-input.cjs.entry.js +36 -15
  26. package/lib/cjs/duet-radio_2.cjs.entry.js +1 -1
  27. package/lib/cjs/duet-range-slider.cjs.entry.js +1 -1
  28. package/lib/cjs/duet-select.cjs.entry.js +2 -2
  29. package/lib/cjs/duet-step_2.cjs.entry.js +1 -1
  30. package/lib/cjs/duet-tab_2.cjs.entry.js +11 -5
  31. package/lib/cjs/duet-table.cjs.entry.js +1 -1
  32. package/lib/cjs/duet-textarea.cjs.entry.js +1 -1
  33. package/lib/cjs/duet-toggle.cjs.entry.js +1 -1
  34. package/lib/cjs/duet-tooltip.cjs.entry.js +21 -10
  35. package/lib/cjs/duet-tray.cjs.entry.js +20 -9
  36. package/lib/cjs/duet-visually-hidden.cjs.entry.js +1 -1
  37. package/lib/cjs/duet.cjs.js +2 -2
  38. package/lib/cjs/{focus-utils-7605778f.js → focus-utils-bd331feb.js} +1 -1
  39. package/lib/cjs/{index-0c949193.js → index-113c2add.js} +0 -3
  40. package/lib/cjs/{language-utils-70d6a9a4.js → language-utils-48b8860b.js} +23 -8
  41. package/lib/cjs/loader.cjs.js +2 -2
  42. package/lib/cjs/{string-utils-a6de43d8.js → string-utils-267e3dbb.js} +7 -0
  43. package/lib/collection/collection-manifest.json +0 -6
  44. package/lib/collection/components/duet-alert/duet-alert.js +10 -4
  45. package/lib/collection/components/duet-badge/duet-badge.css +1 -0
  46. package/lib/collection/components/duet-button/duet-button.js +7 -5
  47. package/lib/collection/components/duet-card/duet-card.css +10 -7
  48. package/lib/collection/components/duet-card/duet-card.js +3 -5
  49. package/lib/collection/components/duet-choice/duet-choice.js +5 -3
  50. package/lib/collection/components/duet-choice-group/duet-choice-group.css +1 -0
  51. package/lib/collection/components/duet-date-picker/duet-date-picker.css +1 -1
  52. package/lib/collection/components/duet-date-picker/duet-date-picker.js +73 -38
  53. package/lib/collection/components/duet-footer/duet-footer.js +7 -5
  54. package/lib/collection/components/duet-header/duet-header.js +46 -21
  55. package/lib/collection/components/duet-heading/duet-heading.css +1 -0
  56. package/lib/collection/components/duet-hero/duet-hero.js +14 -9
  57. package/lib/collection/components/duet-icon/icon-utils.js +1 -1
  58. package/lib/collection/components/duet-label/duet-label.css +2 -0
  59. package/lib/collection/components/duet-link/duet-link.js +10 -11
  60. package/lib/collection/components/duet-modal/duet-modal.js +16 -11
  61. package/lib/collection/components/duet-notification-drawer/duet-notification-drawer.js +14 -9
  62. package/lib/collection/components/duet-number-input/duet-number-input.js +141 -17
  63. package/lib/collection/components/duet-tab-group/duet-tab-group.js +35 -4
  64. package/lib/collection/components/duet-tooltip/duet-tooltip.js +72 -10
  65. package/lib/collection/components/duet-tray/duet-tray.js +71 -9
  66. package/lib/collection/utils/fixture-utils.js +7 -5
  67. package/lib/collection/utils/language-utils.js +22 -8
  68. package/lib/collection/utils/string-utils.js +6 -0
  69. package/lib/custom-elements-bundle/index.d.ts +0 -6
  70. package/lib/custom-elements-bundle/index.js +224 -995
  71. package/lib/duet/duet.esm.js +1 -1
  72. package/lib/duet/duet.js +1 -1
  73. package/lib/duet/p-0058512b.js +4 -0
  74. package/lib/duet/p-0224db45.entry.js +4 -0
  75. package/lib/duet/{p-345ea4f2.system.entry.js → p-02ad46a0.system.entry.js} +1 -1
  76. package/lib/duet/{p-62806bb6.system.entry.js → p-07263910.system.entry.js} +1 -1
  77. package/lib/duet/{p-f82709ba.entry.js → p-1bfbc988.entry.js} +1 -1
  78. package/lib/duet/p-1cd7177f.entry.js +4 -0
  79. package/lib/duet/p-1cec5a70.system.entry.js +4 -0
  80. package/lib/duet/p-1e7222c2.entry.js +4 -0
  81. package/lib/duet/{p-c0b95b58.entry.js → p-202bbd70.entry.js} +1 -1
  82. package/lib/duet/{p-d1817efe.system.entry.js → p-22f56356.system.entry.js} +1 -1
  83. package/lib/duet/{p-f81d8534.entry.js → p-28b67b94.entry.js} +1 -1
  84. package/lib/duet/{p-b4374f0e.entry.js → p-33426ddc.entry.js} +1 -1
  85. package/lib/duet/p-33cf6ed1.entry.js +4 -0
  86. package/lib/duet/p-3d3f773d.system.entry.js +4 -0
  87. package/lib/duet/p-3e1ef509.system.entry.js +4 -0
  88. package/lib/duet/p-3f78a826.system.js +4 -0
  89. package/lib/duet/{p-2a1a9f9f.entry.js → p-44ffb960.entry.js} +1 -1
  90. package/lib/duet/{p-dee41056.system.entry.js → p-453955cc.system.entry.js} +1 -1
  91. package/lib/duet/{p-66dde4d2.entry.js → p-4670a654.entry.js} +1 -1
  92. package/lib/duet/p-47645ea8.system.entry.js +4 -0
  93. package/lib/duet/p-504dbf8f.system.entry.js +4 -0
  94. package/lib/duet/{p-62c294d6.system.entry.js → p-5230ee3c.system.entry.js} +1 -1
  95. package/lib/duet/{p-bbc229d8.system.entry.js → p-56e172f5.system.entry.js} +1 -1
  96. package/lib/duet/{p-de2be65b.system.js → p-57ea2576.system.js} +1 -1
  97. package/lib/duet/p-5aa0d34d.entry.js +4 -0
  98. package/lib/duet/p-5fc7e1f7.system.entry.js +4 -0
  99. package/lib/duet/{p-3dc9d15d.system.entry.js → p-605bc214.system.entry.js} +1 -1
  100. package/lib/duet/{p-4a7911fd.entry.js → p-60ab57d4.entry.js} +1 -1
  101. package/lib/duet/p-64109493.entry.js +4 -0
  102. package/lib/duet/{p-7e108b7e.entry.js → p-69a5dc6b.entry.js} +1 -1
  103. package/lib/duet/{p-8cfce39e.system.entry.js → p-6a230911.system.entry.js} +1 -1
  104. package/lib/duet/p-6a760b8a.entry.js +4 -0
  105. package/lib/duet/{p-c9303f9a.entry.js → p-6d2da245.entry.js} +1 -1
  106. package/lib/duet/{p-ceb75b35.system.entry.js → p-712e7dde.system.entry.js} +1 -1
  107. package/lib/duet/{p-f71f12ed.entry.js → p-746655ba.entry.js} +1 -1
  108. package/lib/duet/p-7b6db837.system.entry.js +4 -0
  109. package/lib/duet/p-7d080785.system.entry.js +4 -0
  110. package/lib/duet/{p-4095dba5.entry.js → p-82dc2e0b.entry.js} +1 -1
  111. package/lib/duet/p-8c8e82aa.system.js +4 -0
  112. package/lib/duet/{p-fc397e03.system.entry.js → p-8c980350.system.entry.js} +1 -1
  113. package/lib/duet/{p-1cfe38b1.system.entry.js → p-8cb47a70.system.entry.js} +1 -1
  114. package/lib/duet/{p-7ee52f58.entry.js → p-8f03c3eb.entry.js} +1 -1
  115. package/lib/duet/p-91fa68a5.js +4 -0
  116. package/lib/duet/{p-e26116e0.system.entry.js → p-92d38668.system.entry.js} +1 -1
  117. package/lib/duet/p-95626e7e.system.entry.js +4 -0
  118. package/lib/duet/p-96808a2e.system.entry.js +4 -0
  119. package/lib/duet/{p-8ffe1461.system.entry.js → p-96c103b2.system.entry.js} +1 -1
  120. package/lib/duet/p-986779fb.js +4 -0
  121. package/lib/duet/{p-35e45c19.system.js → p-9a945278.system.js} +1 -1
  122. package/lib/duet/{p-2d2c45f9.entry.js → p-9c94be45.entry.js} +1 -1
  123. package/lib/duet/p-9ce1baab.system.entry.js +4 -0
  124. package/lib/duet/p-9ff25646.entry.js +4 -0
  125. package/lib/duet/p-a1d12e94.system.entry.js +4 -0
  126. package/lib/duet/p-b03a46b6.entry.js +4 -0
  127. package/lib/duet/{p-a88df408.entry.js → p-b1b8e510.entry.js} +1 -1
  128. package/lib/duet/p-b694cbf5.system.js +4 -0
  129. package/lib/duet/p-b7e50cfa.entry.js +4 -0
  130. package/lib/duet/p-b82927b0.system.entry.js +4 -0
  131. package/lib/duet/{p-c3688975.entry.js → p-ba205dca.entry.js} +1 -1
  132. package/lib/duet/{p-f71e337e.system.entry.js → p-bcae23fc.system.entry.js} +1 -1
  133. package/lib/duet/{p-5c5bdb06.system.entry.js → p-be19c57b.system.entry.js} +1 -1
  134. package/lib/duet/{p-a321a98c.entry.js → p-c4737f88.entry.js} +1 -1
  135. package/lib/duet/p-c5beceed.js +4 -0
  136. package/lib/duet/{p-27d538f7.system.entry.js → p-c5f10483.system.entry.js} +1 -1
  137. package/lib/duet/{p-a6096b05.system.entry.js → p-d35fd913.system.entry.js} +1 -1
  138. package/lib/duet/p-d4b4bfa6.entry.js +4 -0
  139. package/lib/duet/p-d7623eb8.system.entry.js +4 -0
  140. package/lib/duet/{p-36007600.entry.js → p-dc85d2a4.entry.js} +1 -1
  141. package/lib/duet/p-de093c16.entry.js +4 -0
  142. package/lib/duet/p-de842863.entry.js +4 -0
  143. package/lib/duet/{p-59a07cf9.entry.js → p-e08b8909.entry.js} +1 -1
  144. package/lib/duet/p-e39471b6.entry.js +4 -0
  145. package/lib/duet/p-e834c8d5.system.entry.js +4 -0
  146. package/lib/duet/{p-ce1374a4.system.entry.js → p-ef45cfe9.system.entry.js} +1 -1
  147. package/lib/duet/{p-031c2cd8.system.entry.js → p-f0b1850a.system.entry.js} +1 -1
  148. package/lib/duet/p-f53c8019.entry.js +4 -0
  149. package/lib/duet/{p-4265de16.system.entry.js → p-f96c4093.system.entry.js} +1 -1
  150. package/lib/duet/p-fbd83d67.entry.js +4 -0
  151. package/lib/duet/{p-1c41525a.entry.js → p-fdecaf46.entry.js} +1 -1
  152. package/lib/esm/duet-alert.entry.js +4 -2
  153. package/lib/esm/duet-badge.entry.js +2 -2
  154. package/lib/esm/duet-button_2.entry.js +4 -3
  155. package/lib/esm/duet-caption_4.entry.js +7 -8
  156. package/lib/esm/duet-card.entry.js +4 -4
  157. package/lib/esm/duet-checkbox.entry.js +1 -1
  158. package/lib/esm/duet-choice_2.entry.js +4 -3
  159. package/lib/esm/duet-collapsible.entry.js +2 -2
  160. package/lib/esm/duet-cookie-consent.entry.js +1 -1
  161. package/lib/esm/duet-date-picker.entry.js +22 -12
  162. package/lib/esm/duet-divider_2.entry.js +1 -1
  163. package/lib/esm/duet-empty-state.entry.js +1 -1
  164. package/lib/esm/duet-fieldset.entry.js +1 -1
  165. package/lib/esm/duet-footer.entry.js +4 -4
  166. package/lib/esm/duet-grid_2.entry.js +1 -1
  167. package/lib/esm/duet-header_2.entry.js +25 -9
  168. package/lib/esm/duet-hero.entry.js +6 -6
  169. package/lib/esm/duet-icon.entry.js +3 -3
  170. package/lib/esm/duet-input_2.entry.js +2 -2
  171. package/lib/esm/duet-layout.entry.js +1 -1
  172. package/lib/esm/duet-list_2.entry.js +1 -1
  173. package/lib/esm/duet-modal.entry.js +8 -7
  174. package/lib/esm/duet-notification_2.entry.js +6 -5
  175. package/lib/esm/duet-number-input.entry.js +36 -15
  176. package/lib/esm/duet-radio_2.entry.js +1 -1
  177. package/lib/esm/duet-range-slider.entry.js +1 -1
  178. package/lib/esm/duet-select.entry.js +2 -2
  179. package/lib/esm/duet-step_2.entry.js +1 -1
  180. package/lib/esm/duet-tab_2.entry.js +11 -5
  181. package/lib/esm/duet-table.entry.js +1 -1
  182. package/lib/esm/duet-textarea.entry.js +1 -1
  183. package/lib/esm/duet-toggle.entry.js +1 -1
  184. package/lib/esm/duet-tooltip.entry.js +21 -10
  185. package/lib/esm/duet-tray.entry.js +20 -9
  186. package/lib/esm/duet-visually-hidden.entry.js +1 -1
  187. package/lib/esm/duet.js +2 -2
  188. package/lib/esm/{focus-utils-0b12f0df.js → focus-utils-1995e5a9.js} +1 -1
  189. package/lib/esm/{index-f70ddc7f.js → index-6e246691.js} +0 -3
  190. package/lib/esm/{language-utils-ab9c3afc.js → language-utils-d5c38f65.js} +23 -8
  191. package/lib/esm/loader.js +2 -2
  192. package/lib/esm/{string-utils-69cf0d09.js → string-utils-2f1793b8.js} +7 -1
  193. package/lib/esm-es5/duet-alert.entry.js +1 -1
  194. package/lib/esm-es5/duet-badge.entry.js +1 -1
  195. package/lib/esm-es5/duet-button_2.entry.js +1 -1
  196. package/lib/esm-es5/duet-caption_4.entry.js +1 -1
  197. package/lib/esm-es5/duet-card.entry.js +1 -1
  198. package/lib/esm-es5/duet-checkbox.entry.js +1 -1
  199. package/lib/esm-es5/duet-choice_2.entry.js +1 -1
  200. package/lib/esm-es5/duet-collapsible.entry.js +1 -1
  201. package/lib/esm-es5/duet-cookie-consent.entry.js +1 -1
  202. package/lib/esm-es5/duet-date-picker.entry.js +1 -1
  203. package/lib/esm-es5/duet-divider_2.entry.js +1 -1
  204. package/lib/esm-es5/duet-empty-state.entry.js +1 -1
  205. package/lib/esm-es5/duet-fieldset.entry.js +1 -1
  206. package/lib/esm-es5/duet-footer.entry.js +1 -1
  207. package/lib/esm-es5/duet-grid_2.entry.js +1 -1
  208. package/lib/esm-es5/duet-header_2.entry.js +1 -1
  209. package/lib/esm-es5/duet-hero.entry.js +1 -1
  210. package/lib/esm-es5/duet-icon.entry.js +1 -1
  211. package/lib/esm-es5/duet-input_2.entry.js +1 -1
  212. package/lib/esm-es5/duet-layout.entry.js +1 -1
  213. package/lib/esm-es5/duet-list_2.entry.js +1 -1
  214. package/lib/esm-es5/duet-modal.entry.js +1 -1
  215. package/lib/esm-es5/duet-notification_2.entry.js +1 -1
  216. package/lib/esm-es5/duet-number-input.entry.js +2 -2
  217. package/lib/esm-es5/duet-radio_2.entry.js +1 -1
  218. package/lib/esm-es5/duet-range-slider.entry.js +1 -1
  219. package/lib/esm-es5/duet-select.entry.js +1 -1
  220. package/lib/esm-es5/duet-step_2.entry.js +1 -1
  221. package/lib/esm-es5/duet-tab_2.entry.js +1 -1
  222. package/lib/esm-es5/duet-table.entry.js +1 -1
  223. package/lib/esm-es5/duet-textarea.entry.js +1 -1
  224. package/lib/esm-es5/duet-toggle.entry.js +1 -1
  225. package/lib/esm-es5/duet-tooltip.entry.js +1 -1
  226. package/lib/esm-es5/duet-tray.entry.js +1 -1
  227. package/lib/esm-es5/duet-visually-hidden.entry.js +1 -1
  228. package/lib/esm-es5/duet.js +1 -1
  229. package/lib/esm-es5/focus-utils-1995e5a9.js +4 -0
  230. package/lib/esm-es5/{index-f70ddc7f.js → index-6e246691.js} +1 -1
  231. package/lib/esm-es5/language-utils-d5c38f65.js +4 -0
  232. package/lib/esm-es5/loader.js +1 -1
  233. package/lib/esm-es5/{string-utils-69cf0d09.js → string-utils-2f1793b8.js} +1 -1
  234. package/lib/html.html-data.json +4489 -0
  235. package/lib/types/components/duet-alert/duet-alert.d.ts +2 -1
  236. package/lib/types/components/duet-button/duet-button.d.ts +1 -1
  237. package/lib/types/components/duet-choice/duet-choice.d.ts +1 -1
  238. package/lib/types/components/duet-date-picker/duet-date-picker.d.ts +13 -7
  239. package/lib/types/components/duet-footer/duet-footer.d.ts +1 -1
  240. package/lib/types/components/duet-header/duet-header.d.ts +21 -5
  241. package/lib/types/components/duet-hero/duet-hero.d.ts +3 -3
  242. package/lib/types/components/duet-link/duet-link.d.ts +2 -3
  243. package/lib/types/components/duet-modal/duet-modal.d.ts +3 -3
  244. package/lib/types/components/duet-notification-drawer/duet-notification-drawer.d.ts +3 -3
  245. package/lib/types/components/duet-number-input/duet-number-input.d.ts +21 -0
  246. package/lib/types/components/duet-tab-group/duet-tab-group.d.ts +6 -0
  247. package/lib/types/components/duet-tooltip/duet-tooltip.d.ts +11 -0
  248. package/lib/types/components/duet-tray/duet-tray.d.ts +11 -0
  249. package/lib/types/components.d.ts +146 -384
  250. package/lib/types/utils/language-utils.d.ts +3 -2
  251. package/lib/types/utils/string-utils.d.ts +1 -0
  252. package/package.json +18 -14
  253. package/lib/cjs/duet-upload.cjs.entry.js +0 -866
  254. package/lib/collection/components/duet-upload/duet-upload-file-list.js +0 -49
  255. package/lib/collection/components/duet-upload/duet-upload-validators.js +0 -93
  256. package/lib/collection/components/duet-upload/duet-upload.css +0 -133
  257. package/lib/collection/components/duet-upload/duet-upload.js +0 -1440
  258. package/lib/collection/components/duet-upload/errorcodes.utils.js +0 -20
  259. package/lib/collection/components/duet-upload/mock.helpers.js +0 -91
  260. package/lib/collection/components/duet-upload/upload.helpers.js +0 -13
  261. package/lib/collection/components/duet-upload/xhr.helpers.js +0 -34
  262. package/lib/duet/p-0733c303.system.entry.js +0 -4
  263. package/lib/duet/p-095060cc.js +0 -4
  264. package/lib/duet/p-156864a1.system.entry.js +0 -4
  265. package/lib/duet/p-1911dfe7.system.entry.js +0 -4
  266. package/lib/duet/p-2834a302.entry.js +0 -4
  267. package/lib/duet/p-28a3d38f.system.entry.js +0 -4
  268. package/lib/duet/p-2a4d7c5b.system.entry.js +0 -4
  269. package/lib/duet/p-4289b543.entry.js +0 -4
  270. package/lib/duet/p-46a3ae43.system.js +0 -4
  271. package/lib/duet/p-4a38cf9d.entry.js +0 -4
  272. package/lib/duet/p-4be8e814.entry.js +0 -4
  273. package/lib/duet/p-591b2137.entry.js +0 -4
  274. package/lib/duet/p-5f70e318.entry.js +0 -4
  275. package/lib/duet/p-6c2729da.js +0 -4
  276. package/lib/duet/p-6f107847.system.entry.js +0 -4
  277. package/lib/duet/p-77a5fe4c.system.js +0 -4
  278. package/lib/duet/p-7809e78b.system.entry.js +0 -4
  279. package/lib/duet/p-7a36d76f.system.entry.js +0 -4
  280. package/lib/duet/p-884693f1.entry.js +0 -4
  281. package/lib/duet/p-8977b722.entry.js +0 -4
  282. package/lib/duet/p-89db3b94.entry.js +0 -4
  283. package/lib/duet/p-9381c2d4.entry.js +0 -4
  284. package/lib/duet/p-9a450c9a.entry.js +0 -4
  285. package/lib/duet/p-9bbfe606.system.entry.js +0 -4
  286. package/lib/duet/p-a0a066cb.system.entry.js +0 -4
  287. package/lib/duet/p-a89d5d7c.entry.js +0 -4
  288. package/lib/duet/p-b07055fd.system.entry.js +0 -4
  289. package/lib/duet/p-b456d684.system.entry.js +0 -4
  290. package/lib/duet/p-bd18c93f.js +0 -4
  291. package/lib/duet/p-bddb1c15.system.entry.js +0 -4
  292. package/lib/duet/p-c4d183e6.entry.js +0 -4
  293. package/lib/duet/p-cd4e8ccf.js +0 -4
  294. package/lib/duet/p-cf243bcb.system.entry.js +0 -4
  295. package/lib/duet/p-d37c8a05.system.js +0 -4
  296. package/lib/duet/p-d989af11.entry.js +0 -4
  297. package/lib/duet/p-e6128d82.system.entry.js +0 -4
  298. package/lib/duet/p-e86cdc17.entry.js +0 -4
  299. package/lib/duet/p-eadb29c7.entry.js +0 -4
  300. package/lib/duet/p-f30b14d6.system.entry.js +0 -4
  301. package/lib/duet/p-f79f8da1.entry.js +0 -4
  302. package/lib/esm/duet-upload.entry.js +0 -862
  303. package/lib/esm-es5/duet-upload.entry.js +0 -4
  304. package/lib/esm-es5/focus-utils-0b12f0df.js +0 -4
  305. package/lib/esm-es5/language-utils-ab9c3afc.js +0 -4
  306. package/lib/types/components/duet-upload/duet-upload-file-list.d.ts +0 -9
  307. package/lib/types/components/duet-upload/duet-upload-validators.d.ts +0 -12
  308. package/lib/types/components/duet-upload/duet-upload.d.ts +0 -311
  309. package/lib/types/components/duet-upload/errorcodes.utils.d.ts +0 -7
  310. package/lib/types/components/duet-upload/mock.helpers.d.ts +0 -2
  311. package/lib/types/components/duet-upload/upload.helpers.d.ts +0 -1
  312. package/lib/types/components/duet-upload/xhr.helpers.d.ts +0 -12
@@ -1,866 +0,0 @@
1
- /*!
2
- * Built with Duet Design System
3
- */
4
- 'use strict';
5
-
6
- Object.defineProperty(exports, '__esModule', { value: true });
7
-
8
- const index = require('./index-0c949193.js');
9
- const createId = require('./create-id-c3b984b1.js');
10
- const languageUtils = require('./language-utils-70d6a9a4.js');
11
- const themeableComponent = require('./themeable-component-0c1be552.js');
12
-
13
- const formatBytes = (bytes, decimals = 2) => {
14
- if (bytes === 0) {
15
- return "0 Bytes";
16
- }
17
- const k = 1024;
18
- const dm = decimals < 0 ? 0 : decimals;
19
- const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
20
- const i = Math.floor(Math.log(bytes) / Math.log(k));
21
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
22
- };
23
-
24
- const DuetUploadFileList = ({ data, onDelete, onCancel, getError }) => {
25
- if (data.invalid.length === 0 && data.valid.length === 0) {
26
- return;
27
- }
28
- return (index.h("ol", { class: "duet-upload-filelist" },
29
- data.valid.length !== 0 && (index.h("li", null,
30
- index.h("duet-visually-hidden", null, "Files"),
31
- index.h("ul", null, data.valid.length !== 0 &&
32
- data.valid.map(e => (index.h("li", { class: "duet-upload-file" },
33
- index.h("div", { class: "duet-upload-file-container" },
34
- index.h("div", { class: "duet-upload-file-link" }, e.url ? (index.h("duet-button", { variation: "plain", icon: "messaging-attachment", url: e.url },
35
- e.item.name,
36
- " (",
37
- formatBytes(e.item.size),
38
- ")")) : (`${e.item.name} (${formatBytes(e.item.size)})`)),
39
- index.h("ul", { class: "duet-upload-file-actions", role: "menubar", "aria-label": "file actions" },
40
- e.progress < 100 && (index.h("li", { role: "none" },
41
- index.h("duet-button", { role: "menuitem", variation: "plain", icon: "messaging-declined", "icon-only": true, "icon-size": "large", margin: "none", onClick: ev => onCancel(e.item.name, ev) }))),
42
- e.progress === 100 && (index.h("li", { role: "none" },
43
- index.h("duet-button", { role: "menuitem", variation: "destructive", icon: "action-delete", "icon-only": true, "icon-size": "large", margin: "none", onClick: ev => onDelete(e.item.name, ev) }))))),
44
- e.progress < 100 && (index.h("div", { class: "duet-upload-file-progress" },
45
- index.h("progress", { value: e.progress, max: "100" },
46
- index.h("div", { class: "progress-bar" },
47
- index.h("span", { style: { width: `${e.progress}%;` } },
48
- "Progress: ",
49
- e.progress,
50
- "%"))))))))))),
51
- data.invalid.length !== 0 && (index.h("li", null,
52
- index.h("duet-visually-hidden", null, "Files with Errors"),
53
- index.h("ul", null, data.invalid.map(e => {
54
- return (index.h("li", { class: "duet-upload-file duet-upload-file-errors" },
55
- index.h("div", { class: "duet-upload-file-container" },
56
- index.h("div", { class: "duet-upload-file-link duet-upload-file-link-error" },
57
- index.h("div", null,
58
- e.item.name,
59
- " (",
60
- formatBytes(e.item.size),
61
- ")"),
62
- index.h("div", { "data-error-type": e.error.type, "data-error-message": e.error.system_message }, getError(e.error.type))),
63
- index.h("ul", { class: "duet-upload-file-actions", role: "menubar", "aria-label": "file actions" },
64
- index.h("li", { role: "none" },
65
- index.h("duet-button", { role: "menuitem", variation: "destructive", icon: "action-delete", "icon-only": true, "icon-size": "large", margin: "none", onClick: ev => onDelete(e.item.name, ev) }))))));
66
- }))))));
67
- };
68
-
69
- const errorcodes = [
70
- {
71
- type: "default",
72
- system_message: "unknown error",
73
- message: {
74
- fi: "",
75
- sv: "",
76
- en: "An unknown error occured, please try again"
77
- }
78
- },
79
- {
80
- type: "400",
81
- system_message: "Bad Request: The server could not understand the request due to invalid syntax.",
82
- message: {
83
- fi: "",
84
- sv: "",
85
- en: "The server rejected your file"
86
- }
87
- },
88
- {
89
- type: "401",
90
- system_message: "Not Authenticated: The client must authenticate itself to get the requested response..",
91
- message: {
92
- fi: "",
93
- sv: "",
94
- en: "You need to be logged in to upload files"
95
- }
96
- },
97
- {
98
- type: "403",
99
- system_message: "No Access: The client does not have access rights to the content;",
100
- message: {
101
- fi: "",
102
- sv: "",
103
- en: "You do not have the correct access rights to upload files"
104
- }
105
- },
106
- {
107
- type: "413",
108
- system_message: "Payload too large",
109
- message: {
110
- fi: "",
111
- sv: "",
112
- en: "The file was to large for the server to handle"
113
- }
114
- },
115
- {
116
- type: "415",
117
- system_message: "Unsupported media type",
118
- message: {
119
- fi: "",
120
- sv: "",
121
- en: "The server rejected the file because it had the wrong type"
122
- }
123
- },
124
- {
125
- type: "429",
126
- system_message: "Too many request from same address",
127
- message: {
128
- fi: "",
129
- sv: "",
130
- en: "The server has received to many request from you, please try again later"
131
- }
132
- },
133
- {
134
- type: "500",
135
- system_message: "Internal Server Error",
136
- message: {
137
- fi: "",
138
- sv: "",
139
- en: "The server reported an unknown error and the upload failed"
140
- }
141
- },
142
- {
143
- type: "duet-upload-100",
144
- system_message: "File extension not allowed",
145
- message: {
146
- fi: "",
147
- sv: "",
148
- en: "You cannot upload files with that extension"
149
- }
150
- },
151
- {
152
- type: "duet-upload-001",
153
- system_message: "File transfer failed",
154
- message: {
155
- fi: "",
156
- sv: "",
157
- en: "Your connection to the server was interrupted, try again"
158
- }
159
- },
160
- {
161
- type: "duet-upload-101",
162
- system_message: "File mimetype not allowed",
163
- message: {
164
- fi: "",
165
- sv: "",
166
- en: "You cannot upload files of that type"
167
- }
168
- },
169
- {
170
- type: "duet-upload-201",
171
- system_message: "File is too large",
172
- message: {
173
- fi: "",
174
- sv: "",
175
- en: "The file is larger than permitted"
176
- }
177
- },
178
- {
179
- type: "duet-upload-202",
180
- system_message: "The combined size of all files is too large",
181
- message: {
182
- fi: "",
183
- sv: "",
184
- en: "You have reached the maximum combined filesize"
185
- }
186
- },
187
- {
188
- type: "duet-upload-301",
189
- system_message: "The maximum file limit has been reached",
190
- message: {
191
- fi: "Liitteiden maksimimäärä saavutettu.",
192
- sv: "",
193
- en: "Maximum number of attachments reached."
194
- }
195
- }
196
- ];
197
-
198
- const getError = (code) => {
199
- let error = {
200
- type: undefined,
201
- system_message: undefined,
202
- message: undefined,
203
- };
204
- error = errorcodes.filter(errorItem => {
205
- return errorItem.type === code;
206
- })[0];
207
- if (!error) {
208
- error = errorcodes.filter(errorItem => {
209
- return errorItem.type === "default";
210
- })[0];
211
- }
212
- return error;
213
- };
214
-
215
- const validateFileExtension = (name, allowedExtensions) => {
216
- if (!allowedExtensions) {
217
- return true;
218
- }
219
- const ext = name.split(".");
220
- const validExtension = allowedExtensions.split(",");
221
- const extension = ext[ext.length - 1];
222
- return validExtension.includes(extension);
223
- };
224
- const validateFileMime = (type, allowedMimetypes) => {
225
- if (!allowedMimetypes || !type) {
226
- return true;
227
- }
228
- const validMimeTypes = allowedMimetypes.split(",");
229
- let valid = false;
230
- validMimeTypes.forEach(mimeType => {
231
- const allowedTypes = mimeType.split("/");
232
- const fileType = type.split("/");
233
- if (allowedTypes[0] === fileType[0] && (allowedTypes[1] === fileType[1] || allowedTypes[1] === "*")) {
234
- valid = true;
235
- }
236
- });
237
- return valid;
238
- };
239
- const validateFileSize = (size, maxBytes) => {
240
- if (!maxBytes || !size) {
241
- return true;
242
- }
243
- return maxBytes >= size;
244
- };
245
- const validateFile = (item, validators) => {
246
- const { allowedMimetypes, allowedExtensions, maxBytes } = validators;
247
- let valid = false;
248
- let errorMessage = getError("default");
249
- if (item) {
250
- const { name, type, size } = item;
251
- const mime = validateFileMime(type, allowedMimetypes);
252
- const ext = validateFileExtension(name, allowedExtensions);
253
- const bytes = validateFileSize(size, maxBytes);
254
- if (!mime) {
255
- errorMessage = getError("duet-upload-101");
256
- }
257
- if (!ext) {
258
- errorMessage = getError("duet-upload-100");
259
- }
260
- if (!bytes) {
261
- errorMessage = getError("duet-upload-201");
262
- }
263
- valid = mime && ext && bytes;
264
- }
265
- else {
266
- valid = false;
267
- }
268
- return {
269
- valid,
270
- errorMessage: valid ? undefined : languageUtils.getLocaleString(errorMessage.message),
271
- errorSystem: valid ? undefined : errorMessage.system_message,
272
- errorType: valid ? undefined : errorMessage.type,
273
- };
274
- };
275
- const validateTotalSizeIsAboveMax = (filelist, maxTotalBytes) => {
276
- let total = 0;
277
- if (maxTotalBytes) {
278
- filelist.forEach(item => {
279
- if (item.valid && item.size) {
280
- total += item.size;
281
- }
282
- });
283
- if (total < maxTotalBytes) {
284
- return true;
285
- }
286
- }
287
- return false;
288
- };
289
- const validateTotalAmountIsAboveMax = (filelist, maxFiles) => {
290
- let total = 0;
291
- if (maxFiles) {
292
- filelist.forEach(item => {
293
- if (item.valid) {
294
- total++;
295
- }
296
- });
297
- if (total > maxFiles) {
298
- return true;
299
- }
300
- }
301
- return false;
302
- };
303
-
304
- const makeXhrRequest = (payload, options, onFailure, onSuccess, onProgress) => {
305
- const { type, xhr, uri, argument, headers } = Object.assign({
306
- type: "POST",
307
- argument: null,
308
- headers: null,
309
- }, options);
310
- xhr.open(type, `${uri}${argument || ""}`, true);
311
- const { data, name } = payload;
312
- // headers must be added after open
313
- if (headers) {
314
- Object.keys(headers).forEach(key => {
315
- xhr.setRequestHeader(key, headers[key]);
316
- });
317
- }
318
- if (type === "POST") {
319
- xhr.onreadystatechange = () => {
320
- // Call a function when the state changes.
321
- if (xhr.readyState === XMLHttpRequest.DONE && xhr.status >= 200 && xhr.status < 300) {
322
- // Request finished without errors
323
- onSuccess(xhr, name, xhr.status);
324
- }
325
- if (xhr.readyState === XMLHttpRequest.DONE && xhr.status >= 300 && xhr.status < 999) {
326
- // Request finished with errors
327
- onFailure(xhr, name, xhr.status);
328
- }
329
- };
330
- onProgress(name);
331
- }
332
- xhr.send(data);
333
- return xhr;
334
- };
335
-
336
- const duetUploadCss = "*,*::after,*::before{box-sizing:border-box;padding:0;margin:0;background:transparent;border:0;-moz-appearance:none;-webkit-appearance:none;appearance:none}:host{box-sizing:border-box;padding:0;margin:0;background:transparent;border:0;-moz-appearance:none;-webkit-appearance:none;appearance:none}:host li{list-style:none}.duet-upload{box-sizing:border-box;padding:0;margin:0;background:transparent;border:0;-moz-appearance:none;-webkit-appearance:none;appearance:none}.duet-upload li{list-style:none}.duet-upload-file-errors{padding:20px 0;color:#de2362}.duet-upload-filelist{margin-bottom:25px}.duet-upload-filelist-empty{display:flex;align-items:center;justify-content:center;width:100%;height:75px;margin:0 auto;background-color:#f3f9fc}.duet-upload-file{display:flex;flex-flow:column;justify-content:center;min-height:50px;border-bottom:1px solid #e1e3e6}.duet-upload-file:first-of-type:not(.duet-upload-file-errors){border-top:1px solid #e1e3e6}.duet-upload-file-container{display:flex;place-items:center;width:100%}.duet-upload-file-link{display:flex;flex-grow:2;place-items:center}.duet-upload-file-link-error{flex-direction:column;place-items:flex-start}.duet-upload-file-link duet-button{position:relative;top:6px}.duet-upload-file-actions{display:flex;transform:scale(0.8)}.duet-upload-file-progress{}.duet-upload-file-progress .progress-bar{position:relative;display:block;width:100%;height:15px;background-color:#f3f9fc;border-radius:0;box-shadow:none}.duet-upload-file-progress .progress-bar>span{display:block;text-indent:-9999px;background-color:#0077b3;border-radius:0}.duet-upload-file-progress progress[value]{display:flex;width:100%;height:15px;color:#0077b3;border:0 none;-webkit-appearance:none;-moz-appearance:none;appearance:none}.duet-upload-file-progress progress[value]::-webkit-progress-bar{background-color:#f3f9fc;border-radius:0}.duet-upload-file-progress progress[value]::-webkit-progress-value{background-color:#0077b3;background-size:35px 20px, 100% 100%, 100% 100%;border-radius:0;-webkit-animation:animate-stripes 5s linear infinite;animation:animate-stripes 5s linear infinite}.duet-upload-file-progress progress[value] ::-moz-progress-bar{background-color:#f3f9fc}";
337
-
338
- let DuetUpload = class {
339
- constructor(hostRef) {
340
- index.registerInstance(this, hostRef);
341
- this.duetChange = index.createEvent(this, "duetChange", 3);
342
- this.duetBlur = index.createEvent(this, "duetBlur", 7);
343
- this.duetFocus = index.createEvent(this, "duetFocus", 7);
344
- this.duetDone = index.createEvent(this, "duetDone", 3);
345
- this.duetState = index.createEvent(this, "duetState", 3);
346
- this.duetDelete = index.createEvent(this, "duetDelete", 3);
347
- this.duetCancel = index.createEvent(this, "duetCancel", 3);
348
- this.duetProgress = index.createEvent(this, "duetProgress", 3);
349
- this.duetUpload = index.createEvent(this, "duetUpload", 3);
350
- /**
351
- * Own Properties
352
- */
353
- this.buttonId = createId.createID("DuetButton");
354
- this.labelId = createId.createID("DuetLabel");
355
- this.uploadId = createId.createID("DuetUpload");
356
- this.filesInProgress = new Map();
357
- this.fileMaxReached = false;
358
- this.bytesMaxReached = false;
359
- /**
360
- * State() variables
361
- */
362
- this.tick = Date.now();
363
- /**
364
- * If external is set to true, the upload component will not actually upload the files, but only keep states
365
- * it will be up to you to handle the upload and return progress information to the upload-component
366
- */
367
- this.external = false;
368
- /**
369
- * Property to change descriptionDefaults defaults on the component.
370
- * normally you would handle these strings on an application level and override @label when needed
371
- */
372
- this.buttonLabelDefaults = {
373
- fi: "Lisää liite",
374
- sv: "Lägg till en bilaga",
375
- en: "Add an attachment",
376
- };
377
- /**
378
- * Label of button
379
- * @default { fi: "Lisää liite", sv: "Lägg till en bilaga", en: "Add an attachment" }
380
- */
381
- this.buttonLabel = languageUtils.getLocaleString(this.buttonLabelDefaults);
382
- /**
383
- * accessible Label of button
384
- */
385
- this.accessibleButtonLabel = undefined;
386
- /**
387
- * Theme of the input.
388
- */
389
- this.theme = "";
390
- /**
391
- * Makes the input component disabled. This prevents users from being able to
392
- * interact with the upload component, and conveys its inactive state to assistive technologies.
393
- */
394
- this.disabled = false;
395
- /**
396
- * Controls the margin of the component.
397
- */
398
- this.margin = "auto";
399
- /**
400
- * Set whether the input is required or not. Please note that this is necessary for
401
- * accessible inputs when the user is required to fill them. When using this property
402
- * you need to also set “novalidate” attribute to your form element to prevent
403
- * browser from displaying its own validation errors.
404
- */
405
- this.required = false;
406
- /**
407
- * Map of string that contain list of uploaded files.
408
- */
409
- this.files = new Map();
410
- /**
411
- * Property to read if filelist contains errors or not
412
- */
413
- this.valid = !this.required;
414
- /**
415
- * Property to change labelDefaults defaults on the component.
416
- * normally you would handle these strings on an application level and override @label when needed
417
- */
418
- this.labelDefaults = {
419
- fi: "Lisää liite",
420
- sv: "Lägg till en bilaga",
421
- en: "Add attachments",
422
- };
423
- /**
424
- * Label for the input.
425
- * @default { fi: "Lisää liite",sv: "Lägg till en bilaga",en: "Add attachments"}
426
- */
427
- this.label = languageUtils.getLocaleString(this.labelDefaults);
428
- /**
429
- * Property to change descriptionDefaults defaults on the component.
430
- * normally you would handle these strings on an application level and override @label when needed
431
- */
432
- this.descriptionDefaults = {
433
- fi: "Voit liittää {filetypes}-muotoisia tiedostoja sekä yleisimpiä videotiedostoja. Voit lähettää {maxbytes} verran tiedostoja yhdellä kertaa, ja lisätä enintään {maxfiles} liitettä kerrallaan.",
434
- sv: "Du kan bifoga filer i flg. formater {filetypes} samt de vanligaste videofilerna. Du kan ladda upp {maxbytes} filer åt gången och lägga till upp till {maxfiles} bilagor åt gången.",
435
- en: "You may attach the following filetypes: {filetypes} - as well as the most common video files. You can upload {maxbytes} of files at a time, and add up to {maxfiles} attachments at a time.",
436
- };
437
- /**
438
- * Description for the upload component.
439
- * @default ...
440
- */
441
- this.description = languageUtils.getLocaleString(this.descriptionDefaults);
442
- /**
443
- * Defaults for the filelist's empty state.
444
- * @default { fi: "Lisää liite",sv: "Lägg till en bilaga",en: "Add attachments"}
445
- */
446
- this.fileListEmptyDefaults = {
447
- fi: "Ei vielä lisättyjä tiedostoja.",
448
- sv: "Inga filer har lagts till ännu.",
449
- en: "No files added yet.",
450
- };
451
- /**
452
- * Label for the filelist's empty state.
453
- * @default { fi: "Ei vielä lisättyjä tiedostoja.",sv: "Inga filer har lagts till ännu.",en: "No files added yet."}
454
- */
455
- this.fileListEmpty = languageUtils.getLocaleString(this.fileListEmptyDefaults);
456
- /**
457
- * Display the input in error state along with an error message.
458
- */
459
- this.error = "";
460
- /**
461
- * Visually hide the label, but still show it to screen readers.
462
- */
463
- this.labelHidden = false;
464
- /**
465
- * if set, allows capture of media from user camera / microphone
466
- * The capture attribute value is a string that specifies which camera to use for capture
467
- * of image or video data, if the accept attribute indicates that the input should be of
468
- * one of those types. A value of user indicates that the user-facing camera and/or
469
- * microphone should be used. A value of environment specifies that the outward-facing
470
- * camera and/or microphone should be used. If this attribute is missing, the user agent
471
- * is free to decide on its own what to do. If the requested facing mode isn't available,
472
- * the user agent may fall back to its preferred default mode.
473
- */
474
- this.capture = undefined;
475
- /**
476
- * Use maxBytes to specify the maximum size in Bytes of a file that can be uploaded.
477
- */
478
- this.maxBytes = 200000000;
479
- /**
480
- * Use maxBytesTotal to specify the maximum size in Bytes of All files combined that can be uploaded.
481
- */
482
- this.maxBytesTotal = undefined;
483
- /**
484
- * Use maxFiles to specify the maximum amount of files that can be uploaded
485
- */
486
- this.maxFiles = 99;
487
- /**
488
- * A string of commaseperated file type values that are allowed
489
- * @example: .pdf,.doc,.docx
490
- */
491
- this.allowedExtensions = "all";
492
- /**
493
- * A string of commaseperated mime type values that are allowed
494
- * @example: image/*,application/msword,
495
- */
496
- this.allowedMimetypes = "*";
497
- /**
498
- * Use multiple to allow the user to select multiple files when uploading
499
- */
500
- this.multiple = true;
501
- /**
502
- * Use limitSelection to enforce the value in allowedExtension & allowedMimetypes when selecting files,
503
- * by default this is off, setting this to true will limit the users choices to what has been explicitly set
504
- */
505
- this.limitSelection = false;
506
- /**
507
- * Private functions
508
- */
509
- this.kick = () => (this.tick = Date.now()); // will trigger re-render
510
- this.genHashName = () => Date.now().toString(36) + Math.random();
511
- this.updateValueInMap = (item, key, value, kick = true) => {
512
- const fileItem = this.files.get(item);
513
- fileItem[key] = value;
514
- this.files.set(item, fileItem);
515
- if (kick) {
516
- this.kick();
517
- }
518
- };
519
- this.updateProgress = (ev, name) => {
520
- if (ev.lengthComputable) {
521
- const percentComplete = (ev.loaded / ev.total) * 100;
522
- this.updateValueInMap(name, "progress", percentComplete);
523
- this.onProgress(name, percentComplete, ev);
524
- }
525
- else {
526
- console.log("cant read progress");
527
- }
528
- };
529
- this.trackProgress = (name, remove = false) => {
530
- if (remove) {
531
- this.filesInProgress.delete(name);
532
- }
533
- else {
534
- this.filesInProgress.set(name, "inprogress");
535
- }
536
- if (this.filesInProgress.size === 0) {
537
- this.onDone();
538
- }
539
- };
540
- this.getFilesAsArray = () => {
541
- const filesInQueue = [];
542
- const filesInError = [];
543
- this.files.forEach(value => {
544
- if (value.valid && !value.deleted) {
545
- filesInQueue.push(value);
546
- }
547
- else if (!value.valid && !value.deleted) {
548
- filesInError.push(value);
549
- }
550
- });
551
- return { valid: filesInQueue, invalid: filesInError };
552
- };
553
- this.resetFormFields = () => {
554
- /**
555
- * You cannot modify a FileList, nor remove single items from it
556
- * This completely removes all items in the FileList
557
- * We reset the form fields to always be able to re-upload files
558
- * and because we handle all uploads and states internally in the component (not relying on native form elements)
559
- */
560
- this.nativeInput.value = "";
561
- };
562
- this.getI18nError = (errorCode) => {
563
- const errorFromJson = getError(errorCode);
564
- const i18String = languageUtils.getLocaleString(errorFromJson.message);
565
- if (i18String === "" || !i18String) {
566
- return errorFromJson.system_message;
567
- }
568
- else {
569
- return i18String;
570
- }
571
- };
572
- /**
573
- * Eventlisteners for the XHR requests
574
- */
575
- this.transferComplete = name => {
576
- this.updateValueInMap(name, "progress", 100, false);
577
- this.trackProgress(name, true);
578
- };
579
- this.transferDone = (xhr, name, status) => {
580
- this.updateValueInMap(name, "status", status, false);
581
- try {
582
- const response = JSON.parse(xhr.response);
583
- this.updateValueInMap(name, "url", response.url);
584
- }
585
- catch (e) {
586
- this.updateValueInMap(name, "url", null);
587
- console.error("Server did not respond with expected response {url: string}");
588
- }
589
- return;
590
- };
591
- this.transferDoneWithFailure = (xhr, name, status) => {
592
- try {
593
- const { error } = JSON.parse(xhr.response);
594
- this.updateValueInMap(name, "error", { message: error.message, type: error.type });
595
- }
596
- catch (e) {
597
- console.error("Server did not respond with expected response error:{message: string, type: int}");
598
- this.updateValueInMap(name, "error", { type: status });
599
- }
600
- };
601
- this.transferFailed = name => {
602
- this.updateValueInMap(name, "error", getError("duet-upload-001"));
603
- };
604
- this.transferCanceled = name => {
605
- this.files.delete(name);
606
- this.validateTotals(name);
607
- this.kick();
608
- };
609
- this.validateTotals = (name) => {
610
- const isTotalSizeOverMaxSize = validateTotalSizeIsAboveMax(this.files, this.maxBytesTotal);
611
- const isTotalFileAmountAboveMax = validateTotalAmountIsAboveMax(this.files, this.maxFiles);
612
- if (isTotalSizeOverMaxSize && name) {
613
- this.updateValueInMap(name, "error", getError("duet-upload-202"), false);
614
- }
615
- if (isTotalFileAmountAboveMax && name) {
616
- this.updateValueInMap(name, "error", getError("duet-upload-301"), false);
617
- }
618
- this.bytesMaxReached = isTotalSizeOverMaxSize;
619
- this.fileMaxReached = isTotalFileAmountAboveMax;
620
- return {
621
- bytesMaxReached: isTotalSizeOverMaxSize,
622
- fileMaxReached: isTotalFileAmountAboveMax,
623
- };
624
- };
625
- this.onDelete = (key, ev) => {
626
- const deletedItem = this.files.get(key);
627
- this.files.delete(key);
628
- this.validateTotals();
629
- this.kick();
630
- if (!this.external) {
631
- this.makeXHRDeleteRequest(deletedItem);
632
- }
633
- this.resetFormFields();
634
- this.duetDelete.emit({
635
- originalEvent: ev,
636
- data: { deletion: deletedItem },
637
- component: "duet-upload",
638
- });
639
- };
640
- this.onCancel = (key, ev) => {
641
- const cancelledItem = this.files.get(key);
642
- this.files.delete(key);
643
- if (!this.external) {
644
- const { xhr } = cancelledItem;
645
- xhr.abort();
646
- }
647
- else {
648
- this.kick();
649
- }
650
- this.resetFormFields();
651
- this.duetCancel.emit({
652
- originalEvent: ev,
653
- data: { cancelled: cancelledItem },
654
- component: "duet-upload",
655
- });
656
- };
657
- this.onUpload = (ev) => {
658
- this.duetUpload.emit({
659
- originalEvent: ev,
660
- component: "duet-upload",
661
- });
662
- };
663
- this.onBlur = (ev) => {
664
- this.duetBlur.emit({
665
- originalEvent: ev,
666
- component: "duet-upload",
667
- });
668
- };
669
- this.onProgress = (key, percentComplete, ev) => {
670
- this.duetChange.emit({
671
- originalEvent: ev,
672
- data: {
673
- key,
674
- percentComplete,
675
- },
676
- component: "duet-upload",
677
- });
678
- };
679
- this.onFocus = (ev) => {
680
- this.duetFocus.emit({
681
- originalEvent: ev,
682
- component: "duet-upload",
683
- });
684
- };
685
- this.onDone = () => {
686
- this.duetDone.emit({
687
- component: "duet-upload",
688
- data: { files: this.files },
689
- });
690
- };
691
- this.startUpload = async (ev) => {
692
- await this.setFocus();
693
- this.nativeInput.click();
694
- this.onUpload(ev);
695
- ev.stopPropagation();
696
- ev.preventDefault();
697
- };
698
- }
699
- watchValidHandler(newValue, oldValue) {
700
- if (newValue !== oldValue) {
701
- this.kick();
702
- }
703
- }
704
- /**
705
- * Component lifecycle events.
706
- */
707
- componentWillLoad() {
708
- themeableComponent.inheritGlobalTheme(this);
709
- }
710
- componentWillRender() {
711
- const { invalid, valid } = this.getFilesAsArray();
712
- const oldValid = this.valid;
713
- this.valid = invalid.length === 0 && valid.length !== 0;
714
- if (this.valid !== oldValid) {
715
- this.duetState.emit({
716
- originalEvent: undefined,
717
- data: { valid: this.valid, from: "componentWillRender" },
718
- component: "duet-upload",
719
- });
720
- }
721
- }
722
- /**
723
- * XHR request utilities
724
- */
725
- makeXHRPostRequest(data) {
726
- const xhr = new XMLHttpRequest();
727
- const name = data.get("name");
728
- xhr.upload.addEventListener("progress", ev => {
729
- this.updateProgress(ev, name);
730
- });
731
- xhr.upload.addEventListener("load", () => {
732
- this.transferComplete(name);
733
- });
734
- xhr.upload.addEventListener("error", () => {
735
- this.transferFailed(name);
736
- });
737
- xhr.upload.addEventListener("abort", () => {
738
- this.transferCanceled(name);
739
- });
740
- return makeXhrRequest({ data, name }, { type: "POST", uri: this.uri, xhr, argument: null, headers: null }, this.transferDoneWithFailure, this.transferDone, this.trackProgress);
741
- }
742
- makeXHRDeleteRequest(data) {
743
- const { uid, item } = data;
744
- const xhr = new XMLHttpRequest();
745
- // don't present server issues to user on deletes, just remove them from the visible list
746
- return makeXhrRequest({ data: null, name }, {
747
- type: "DELETE",
748
- xhr,
749
- uri: this.uri,
750
- arguments: `?key=${uid}&name=${item.name}`,
751
- headers: {
752
- "x-fileuid": uid,
753
- "x-filename": item.name,
754
- },
755
- }, this.transferDoneWithFailure, this.transferDone, this.trackProgress);
756
- }
757
- /**
758
- * Component event handling.
759
- */
760
- async onChange(ev) {
761
- var _a;
762
- const selectedFiles = Array.from((_a = this.nativeInput) === null || _a === void 0 ? void 0 : _a.files);
763
- // FileList is a nice array like structure but
764
- // to ensure uniqueness of files we use a mapping structure and
765
- // key to the name (makes it easier to delete)
766
- if (selectedFiles) {
767
- for (const item of selectedFiles) {
768
- const { valid, errorMessage, errorType, errorSystem } = validateFile(item, {
769
- maxBytes: this.maxBytes,
770
- allowedExtensions: this.allowedExtensions,
771
- allowedMimetypes: this.allowedMimetypes,
772
- });
773
- const uid = this.genHashName();
774
- const fileListItem = {
775
- uid,
776
- item: item,
777
- size: item.size,
778
- valid,
779
- error: {
780
- type: valid ? undefined : errorType,
781
- message: valid ? undefined : errorMessage,
782
- system_message: valid ? undefined : errorSystem,
783
- },
784
- progress: 0,
785
- deleted: false,
786
- xhr: false,
787
- url: false,
788
- };
789
- this.files.set(item.name, fileListItem);
790
- // validate that we haven't hit any maxfiles or maxbytes limits before we upload
791
- const { bytesMaxReached, fileMaxReached } = this.validateTotals(item.name);
792
- if (bytesMaxReached) {
793
- // in case one of the global maxes have been reached, invalidate the file
794
- this.updateValueInMap(item.name, "valid", false, false);
795
- }
796
- else if (fileMaxReached) {
797
- // in case one of the global maxes have been reached, invalidate the file
798
- this.updateValueInMap(item.name, "valid", false, false);
799
- }
800
- else if (valid && !this.external) {
801
- // if all is well AND external file upload handling has not been set, start upload
802
- const data = new FormData();
803
- data.append("file", item);
804
- data.append("uid", uid);
805
- data.append("name", item.name);
806
- data.append("metadata", JSON.stringify({ uid, url: this.uri, size: item.size }));
807
- fileListItem.xhr = await this.makeXHRPostRequest(data);
808
- }
809
- // kick the stat to force update
810
- this.kick();
811
- }
812
- }
813
- // reset the form, so that a user may upload a file again (with the same name)
814
- this.resetFormFields();
815
- this.duetChange.emit({
816
- originalEvent: ev,
817
- data: { files: this.files },
818
- component: "duet-upload",
819
- });
820
- }
821
- /**
822
- * Sets focus on the specified `duet-input`. Use this method instead of the global
823
- * `input.focus()`.
824
- */
825
- async setFocus(options) {
826
- if (this.nativeInput) {
827
- this.nativeInput.focus(options);
828
- }
829
- return;
830
- }
831
- /**
832
- * Get list of files, divided in errors and valid sections
833
- */
834
- async getFiles() {
835
- if (!this.files || this.files.size === 0) {
836
- return false;
837
- }
838
- return this.getFilesAsArray();
839
- }
840
- /**
841
- * render() function
842
- * Always the last one in the class.
843
- */
844
- render() {
845
- const identifier = this.identifier || this.uploadId;
846
- let caption = this.description.replace(/{maxfiles}/g, this.maxFiles.toString());
847
- caption = caption.replace(/{maxbytes}/g, `${Math.floor(this.maxBytes / 1024 / 1024)} MB`);
848
- caption = caption.replace(/{filetypes}/g, this.allowedExtensions.split(",").join(", "));
849
- return (index.h(index.Host, { class: { "duet-m-0": this.margin === "none" } }, index.h("duet-fieldset", { label: this.label, caption: caption }, index.h("slot", { name: "header" }), index.h("duet-label", { theme: this.theme === "turva" ? "turva" : "default", size: "small", class: {
850
- "duet-upload-filelist-empty": !this.files.size,
851
- "duet-upload-filelist": true,
852
- "duet-upload-filelist-filled": this.files.size,
853
- }, id: this.labelId, for: identifier }, !this.files.size && this.fileListEmpty), !!this.files.size && index.h("slot", { name: "fileheader" }), index.h(DuetUploadFileList, { data: this.getFilesAsArray(), onDelete: this.onDelete, onCancel: this.onCancel, getError: this.getI18nError }, index.h("li", null, "testing something")), !!this.files.size && index.h("slot", { name: "filefooter" }), index.h("duet-spacer", { size: "large" }), index.h("duet-button", { id: this.buttonId, onClick: this.startUpload, "accessible-controls": identifier, disabled: this.fileMaxReached, "accessible-label": this.accessibleButtonLabel, "accessible-owns": identifier, size: "small", variation: "secondary", fixed: true, icon: "action-add-circle" }, this.buttonLabel), index.h("duet-spacer", { size: "medium" }), (this.fileMaxReached || this.bytesMaxReached) && (index.h("duet-alert", null, this.fileMaxReached && this.getI18nError("duet-upload-301"), this.bytesMaxReached && this.getI18nError("duet-upload-202"))), index.h("duet-spacer", { size: "medium" }), index.h("duet-visually-hidden", null, index.h("input", { ref: input => {
854
- this.nativeInput = input;
855
- }, accept: this.limitSelection ? undefined : `${this.allowedMimetypes},${this.allowedExtensions}`, onBlur: this.onBlur, onFocus: this.onFocus, onChange: e => this.onChange(e), type: "file", class: {
856
- "duet-upload": true,
857
- }, disabled: this.disabled, "aria-hidden": "true", required: this.required, name: this.name, id: this.identifier, multiple: this.multiple, capture: "user" })))));
858
- }
859
- get element() { return index.getElement(this); }
860
- static get watchers() { return {
861
- "valid": ["watchValidHandler"]
862
- }; }
863
- };
864
- DuetUpload.style = duetUploadCss;
865
-
866
- exports.duet_upload = DuetUpload;