brd-ui-kit 0.1.72 → 0.1.75

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 (252) hide show
  1. package/dist/brd-ui-kit.css +1 -1
  2. package/dist/calendar-C0DXP3T-.js +3118 -0
  3. package/dist/calendar-C0DXP3T-.js.map +1 -0
  4. package/dist/calendar-DReGV_22.cjs +2 -0
  5. package/dist/calendar-DReGV_22.cjs.map +1 -0
  6. package/dist/calendar-locale-CP2pxhFK.cjs +2 -0
  7. package/dist/calendar-locale-CP2pxhFK.cjs.map +1 -0
  8. package/dist/calendar-locale-DJf03PI9.js +592 -0
  9. package/dist/calendar-locale-DJf03PI9.js.map +1 -0
  10. package/dist/{chart-CgVfpT_X.cjs → chart-C69jBlXa.cjs} +2 -2
  11. package/dist/{chart-CgVfpT_X.cjs.map → chart-C69jBlXa.cjs.map} +1 -1
  12. package/dist/{chart-D15EtNmb.js → chart-CAPCe8o5.js} +3 -3
  13. package/dist/{chart-D15EtNmb.js.map → chart-CAPCe8o5.js.map} +1 -1
  14. package/dist/components/basic-table/basic-table.d.ts +33 -2
  15. package/dist/components/basic-table/index.d.ts +1 -1
  16. package/dist/components/data-table/data-table-actions-column.d.ts +23 -0
  17. package/dist/components/data-table/data-table-bulk-actions.d.ts +20 -0
  18. package/dist/components/data-table/data-table-column-visibility.d.ts +17 -0
  19. package/dist/components/data-table/data-table-editable-column.d.ts +12 -0
  20. package/dist/components/data-table/data-table-filter.d.ts +12 -0
  21. package/dist/components/data-table/data-table-row-actions-column.d.ts +53 -0
  22. package/dist/components/data-table/data-table-select-column.d.ts +2 -0
  23. package/dist/components/data-table/data-table.d.ts +2 -0
  24. package/dist/components/data-table/data-table.styles.d.ts +8 -0
  25. package/dist/components/data-table/index.d.ts +17 -0
  26. package/dist/components/data-table/use-data-table-editable-rows.d.ts +60 -0
  27. package/dist/components/data-table.d.ts +2 -0
  28. package/dist/components/files-uploader/files-uploader.d.ts +8 -6
  29. package/dist/components/textarea-field/index.d.ts +1 -1
  30. package/dist/components/ui/button/button.styles.d.ts +2 -2
  31. package/dist/components/ui/calendar/calendar.d.ts +14 -10
  32. package/dist/components/ui/calendar/calendar.styles.d.ts +60 -2
  33. package/dist/components/ui/calendar/index.d.ts +3 -2
  34. package/dist/components/ui/dropdown-menu/dropdown-menu.d.ts +102 -0
  35. package/dist/components/ui/dropdown-menu/dropdown-menu.styles.d.ts +9 -0
  36. package/dist/components/ui/dropdown-menu/index.d.ts +2 -0
  37. package/dist/components/ui/dropdown-menu.d.ts +2 -0
  38. package/dist/components/ui/icon/icon-presets.d.ts +5 -5
  39. package/dist/components/ui/icon/icon.d.ts +2 -1
  40. package/dist/components/ui/pagination/pagination.d.ts +6 -5
  41. package/dist/components/ui/select/select.styles.d.ts +2 -2
  42. package/dist/components/ui/select-calendar-menu/index.d.ts +1 -0
  43. package/dist/components/ui/select-calendar-menu/select-calendar-menu.d.ts +33 -0
  44. package/dist/components/ui/select-calendar-menu.d.ts +2 -0
  45. package/dist/components/ui/textarea/textarea.d.ts +2 -2
  46. package/dist/components/ui/toggle/index.d.ts +3 -0
  47. package/dist/components/ui/toggle/toggle.d.ts +5 -0
  48. package/dist/components/ui/toggle/toggle.styles.d.ts +10 -0
  49. package/dist/components/ui/toggle-group/index.d.ts +1 -0
  50. package/dist/components/ui/toggle-group/toggle-group.d.ts +13 -0
  51. package/dist/components/ui/toggle-group/toggle-group.styles.d.ts +14 -0
  52. package/dist/components/ui/toggle-group.d.ts +2 -0
  53. package/dist/components/ui/toggle.d.ts +2 -0
  54. package/dist/components-app-pagination-app-pagination.cjs +1 -1
  55. package/dist/components-app-pagination-app-pagination.cjs.map +1 -1
  56. package/dist/components-app-pagination-app-pagination.js +46 -30
  57. package/dist/components-app-pagination-app-pagination.js.map +1 -1
  58. package/dist/components-app-pagination-app-pagination.styles.cjs +2 -2
  59. package/dist/components-app-pagination-app-pagination.styles.cjs.map +1 -1
  60. package/dist/components-app-pagination-app-pagination.styles.js +12 -12
  61. package/dist/components-app-pagination-app-pagination.styles.js.map +1 -1
  62. package/dist/components-avatar-uploader-avatar-uploader.cjs +2 -2
  63. package/dist/components-avatar-uploader-avatar-uploader.cjs.map +1 -1
  64. package/dist/components-avatar-uploader-avatar-uploader.js +8 -4
  65. package/dist/components-avatar-uploader-avatar-uploader.js.map +1 -1
  66. package/dist/components-basic-avatar-basic-avatar.cjs +2 -2
  67. package/dist/components-basic-avatar-basic-avatar.cjs.map +1 -1
  68. package/dist/components-basic-avatar-basic-avatar.js +8 -4
  69. package/dist/components-basic-avatar-basic-avatar.js.map +1 -1
  70. package/dist/components-basic-chart-basic-chart.cjs +1 -1
  71. package/dist/components-basic-chart-basic-chart.js +1 -1
  72. package/dist/components-basic-drawer-basic-drawer.cjs +1 -1
  73. package/dist/components-basic-drawer-basic-drawer.cjs.map +1 -1
  74. package/dist/components-basic-drawer-basic-drawer.js +13 -14
  75. package/dist/components-basic-drawer-basic-drawer.js.map +1 -1
  76. package/dist/components-basic-table-basic-table.cjs +2 -2
  77. package/dist/components-basic-table-basic-table.cjs.map +1 -1
  78. package/dist/components-basic-table-basic-table.js +874 -757
  79. package/dist/components-basic-table-basic-table.js.map +1 -1
  80. package/dist/components-data-table-data-table-actions-column.cjs +2 -0
  81. package/dist/components-data-table-data-table-actions-column.cjs.map +1 -0
  82. package/dist/components-data-table-data-table-actions-column.js +72 -0
  83. package/dist/components-data-table-data-table-actions-column.js.map +1 -0
  84. package/dist/components-data-table-data-table-bulk-actions.cjs +2 -0
  85. package/dist/components-data-table-data-table-bulk-actions.cjs.map +1 -0
  86. package/dist/components-data-table-data-table-bulk-actions.js +60 -0
  87. package/dist/components-data-table-data-table-bulk-actions.js.map +1 -0
  88. package/dist/components-data-table-data-table-column-visibility.cjs +3 -0
  89. package/dist/components-data-table-data-table-column-visibility.cjs.map +1 -0
  90. package/dist/components-data-table-data-table-column-visibility.js +100 -0
  91. package/dist/components-data-table-data-table-column-visibility.js.map +1 -0
  92. package/dist/components-data-table-data-table-editable-column.cjs +2 -0
  93. package/dist/components-data-table-data-table-editable-column.cjs.map +1 -0
  94. package/dist/components-data-table-data-table-editable-column.js +15 -0
  95. package/dist/components-data-table-data-table-editable-column.js.map +1 -0
  96. package/dist/components-data-table-data-table-filter.cjs +2 -0
  97. package/dist/components-data-table-data-table-filter.cjs.map +1 -0
  98. package/dist/components-data-table-data-table-filter.js +39 -0
  99. package/dist/components-data-table-data-table-filter.js.map +1 -0
  100. package/dist/components-data-table-data-table-row-actions-column.cjs +2 -0
  101. package/dist/components-data-table-data-table-row-actions-column.cjs.map +1 -0
  102. package/dist/components-data-table-data-table-row-actions-column.js +174 -0
  103. package/dist/components-data-table-data-table-row-actions-column.js.map +1 -0
  104. package/dist/components-data-table-data-table-select-column.cjs +2 -0
  105. package/dist/components-data-table-data-table-select-column.cjs.map +1 -0
  106. package/dist/components-data-table-data-table-select-column.js +44 -0
  107. package/dist/components-data-table-data-table-select-column.js.map +1 -0
  108. package/dist/components-data-table-data-table.cjs +2 -0
  109. package/dist/components-data-table-data-table.cjs.map +1 -0
  110. package/dist/components-data-table-data-table.js +37 -0
  111. package/dist/components-data-table-data-table.js.map +1 -0
  112. package/dist/components-data-table-data-table.styles.cjs +4 -0
  113. package/dist/components-data-table-data-table.styles.cjs.map +1 -0
  114. package/dist/components-data-table-data-table.styles.js +22 -0
  115. package/dist/components-data-table-data-table.styles.js.map +1 -0
  116. package/dist/components-data-table-use-data-table-editable-rows.cjs +2 -0
  117. package/dist/components-data-table-use-data-table-editable-rows.cjs.map +1 -0
  118. package/dist/components-data-table-use-data-table-editable-rows.js +156 -0
  119. package/dist/components-data-table-use-data-table-editable-rows.js.map +1 -0
  120. package/dist/components-data-table.cjs +2 -0
  121. package/dist/components-data-table.cjs.map +1 -0
  122. package/dist/components-data-table.js +21 -0
  123. package/dist/components-data-table.js.map +1 -0
  124. package/dist/components-files-uploader-files-uploader.cjs +6 -6
  125. package/dist/components-files-uploader-files-uploader.cjs.map +1 -1
  126. package/dist/components-files-uploader-files-uploader.js +108 -109
  127. package/dist/components-files-uploader-files-uploader.js.map +1 -1
  128. package/dist/components-input-contact-input-contact.cjs +1 -1
  129. package/dist/components-input-contact-input-contact.cjs.map +1 -1
  130. package/dist/components-input-contact-input-contact.js +8 -4
  131. package/dist/components-input-contact-input-contact.js.map +1 -1
  132. package/dist/components-input-password-input-password.cjs +1 -1
  133. package/dist/components-input-password-input-password.cjs.map +1 -1
  134. package/dist/components-input-password-input-password.js +8 -4
  135. package/dist/components-input-password-input-password.js.map +1 -1
  136. package/dist/components-popover-modal-popover-modal.cjs.map +1 -1
  137. package/dist/components-popover-modal-popover-modal.js +27 -20
  138. package/dist/components-popover-modal-popover-modal.js.map +1 -1
  139. package/dist/components-textarea-field-textarea-field.cjs.map +1 -1
  140. package/dist/components-textarea-field-textarea-field.js.map +1 -1
  141. package/dist/components-ui-button-button.styles.cjs +18 -8
  142. package/dist/components-ui-button-button.styles.cjs.map +1 -1
  143. package/dist/components-ui-button-button.styles.js +49 -33
  144. package/dist/components-ui-button-button.styles.js.map +1 -1
  145. package/dist/components-ui-calendar-calendar.cjs +1 -12
  146. package/dist/components-ui-calendar-calendar.cjs.map +1 -1
  147. package/dist/components-ui-calendar-calendar.js +12 -3757
  148. package/dist/components-ui-calendar-calendar.js.map +1 -1
  149. package/dist/components-ui-calendar-calendar.styles.cjs +17 -13
  150. package/dist/components-ui-calendar-calendar.styles.cjs.map +1 -1
  151. package/dist/components-ui-calendar-calendar.styles.js +193 -24
  152. package/dist/components-ui-calendar-calendar.styles.js.map +1 -1
  153. package/dist/components-ui-calendar.cjs +1 -1
  154. package/dist/components-ui-calendar.js +3 -2
  155. package/dist/components-ui-calendar.js.map +1 -1
  156. package/dist/components-ui-card-card.styles.cjs +2 -2
  157. package/dist/components-ui-card-card.styles.cjs.map +1 -1
  158. package/dist/components-ui-card-card.styles.js +2 -2
  159. package/dist/components-ui-card-card.styles.js.map +1 -1
  160. package/dist/components-ui-chart-chart.cjs +1 -1
  161. package/dist/components-ui-chart-chart.js +1 -1
  162. package/dist/components-ui-chart.cjs +1 -1
  163. package/dist/components-ui-chart.js +1 -1
  164. package/dist/components-ui-dropdown-menu-dropdown-menu.cjs +3 -0
  165. package/dist/components-ui-dropdown-menu-dropdown-menu.cjs.map +1 -0
  166. package/dist/components-ui-dropdown-menu-dropdown-menu.js +293 -0
  167. package/dist/components-ui-dropdown-menu-dropdown-menu.js.map +1 -0
  168. package/dist/components-ui-dropdown-menu-dropdown-menu.styles.cjs +29 -0
  169. package/dist/components-ui-dropdown-menu-dropdown-menu.styles.cjs.map +1 -0
  170. package/dist/components-ui-dropdown-menu-dropdown-menu.styles.js +43 -0
  171. package/dist/components-ui-dropdown-menu-dropdown-menu.styles.js.map +1 -0
  172. package/dist/components-ui-dropdown-menu.cjs +2 -0
  173. package/dist/components-ui-dropdown-menu.cjs.map +1 -0
  174. package/dist/components-ui-dropdown-menu.js +17 -0
  175. package/dist/components-ui-dropdown-menu.js.map +1 -0
  176. package/dist/components-ui-field-field.cjs +1 -1
  177. package/dist/components-ui-field-field.cjs.map +1 -1
  178. package/dist/components-ui-field-field.js +14 -14
  179. package/dist/components-ui-field-field.js.map +1 -1
  180. package/dist/components-ui-icon-icon-presets.cjs +1 -1
  181. package/dist/components-ui-icon-icon-presets.cjs.map +1 -1
  182. package/dist/components-ui-icon-icon-presets.js +3 -3
  183. package/dist/components-ui-icon-icon-presets.js.map +1 -1
  184. package/dist/components-ui-icon-icon.cjs +1 -1
  185. package/dist/components-ui-icon-icon.cjs.map +1 -1
  186. package/dist/components-ui-icon-icon.js +2621 -3595
  187. package/dist/components-ui-icon-icon.js.map +1 -1
  188. package/dist/components-ui-input-group-input-group.cjs.map +1 -1
  189. package/dist/components-ui-input-group-input-group.js.map +1 -1
  190. package/dist/components-ui-pagination-pagination.cjs +2 -1
  191. package/dist/components-ui-pagination-pagination.cjs.map +1 -1
  192. package/dist/components-ui-pagination-pagination.js +93 -62
  193. package/dist/components-ui-pagination-pagination.js.map +1 -1
  194. package/dist/components-ui-popover-popover.cjs.map +1 -1
  195. package/dist/components-ui-popover-popover.js +24 -14
  196. package/dist/components-ui-popover-popover.js.map +1 -1
  197. package/dist/components-ui-popover-popover.styles.cjs.map +1 -1
  198. package/dist/components-ui-popover-popover.styles.js.map +1 -1
  199. package/dist/components-ui-select-calendar-menu-select-calendar-menu.cjs +2 -0
  200. package/dist/components-ui-select-calendar-menu-select-calendar-menu.cjs.map +1 -0
  201. package/dist/components-ui-select-calendar-menu-select-calendar-menu.js +138 -0
  202. package/dist/components-ui-select-calendar-menu-select-calendar-menu.js.map +1 -0
  203. package/dist/components-ui-select-calendar-menu.cjs +2 -0
  204. package/dist/components-ui-select-calendar-menu.cjs.map +1 -0
  205. package/dist/components-ui-select-calendar-menu.js +5 -0
  206. package/dist/components-ui-select-calendar-menu.js.map +1 -0
  207. package/dist/components-ui-select-select.cjs.map +1 -1
  208. package/dist/components-ui-select-select.js.map +1 -1
  209. package/dist/components-ui-select-select.styles.cjs +2 -2
  210. package/dist/components-ui-select-select.styles.cjs.map +1 -1
  211. package/dist/components-ui-select-select.styles.js +5 -5
  212. package/dist/components-ui-select-select.styles.js.map +1 -1
  213. package/dist/components-ui-sonner-sonner.styles.cjs.map +1 -1
  214. package/dist/components-ui-sonner-sonner.styles.js.map +1 -1
  215. package/dist/components-ui-textarea-textarea.cjs +1 -1
  216. package/dist/components-ui-textarea-textarea.cjs.map +1 -1
  217. package/dist/components-ui-textarea-textarea.js +2 -3
  218. package/dist/components-ui-textarea-textarea.js.map +1 -1
  219. package/dist/components-ui-textarea-textarea.styles.cjs +1 -1
  220. package/dist/components-ui-textarea-textarea.styles.cjs.map +1 -1
  221. package/dist/components-ui-textarea-textarea.styles.js +1 -1
  222. package/dist/components-ui-textarea-textarea.styles.js.map +1 -1
  223. package/dist/components-ui-toggle-group-toggle-group.cjs +2 -0
  224. package/dist/components-ui-toggle-group-toggle-group.cjs.map +1 -0
  225. package/dist/components-ui-toggle-group-toggle-group.js +122 -0
  226. package/dist/components-ui-toggle-group-toggle-group.js.map +1 -0
  227. package/dist/components-ui-toggle-group-toggle-group.styles.cjs +2 -0
  228. package/dist/components-ui-toggle-group-toggle-group.styles.cjs.map +1 -0
  229. package/dist/components-ui-toggle-group-toggle-group.styles.js +81 -0
  230. package/dist/components-ui-toggle-group-toggle-group.styles.js.map +1 -0
  231. package/dist/components-ui-toggle-group.cjs +2 -0
  232. package/dist/components-ui-toggle-group.cjs.map +1 -0
  233. package/dist/components-ui-toggle-group.js +6 -0
  234. package/dist/components-ui-toggle-group.js.map +1 -0
  235. package/dist/components-ui-toggle-toggle.cjs +2 -0
  236. package/dist/components-ui-toggle-toggle.cjs.map +1 -0
  237. package/dist/components-ui-toggle-toggle.js +57 -0
  238. package/dist/components-ui-toggle-toggle.js.map +1 -0
  239. package/dist/components-ui-toggle-toggle.styles.cjs +7 -0
  240. package/dist/components-ui-toggle-toggle.styles.cjs.map +1 -0
  241. package/dist/components-ui-toggle-toggle.styles.js +33 -0
  242. package/dist/components-ui-toggle-toggle.styles.js.map +1 -0
  243. package/dist/components-ui-toggle.cjs +2 -0
  244. package/dist/components-ui-toggle.cjs.map +1 -0
  245. package/dist/components-ui-toggle.js +7 -0
  246. package/dist/components-ui-toggle.js.map +1 -0
  247. package/dist/constants/calendar-locale.d.ts +5 -0
  248. package/dist/index.cjs +1 -1
  249. package/dist/index.d.ts +11 -2
  250. package/dist/index.js +227 -191
  251. package/dist/index.js.map +1 -1
  252. package/package.json +62 -17
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),p=require("./lib-utils.cjs"),b=require("react"),D=require("./index-DJD-8LQA.cjs"),h=require("./components-ui-icon-icon.cjs"),L=require("./components-ui-typography-typography.cjs");require("./components-ui-typography-typography.styles.cjs");const $=["B","KB","MB","GB","TB"],u=1024,B=5*u*u,P=5,C=["all"],F=800,k={image:{"image/*":[".jpg",".jpeg",".png",".webp"]},pdf:{"application/pdf":[".pdf"]},doc:{"application/msword":[".doc"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[".docx"]},excel:{"application/vnd.ms-excel":[".xls"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"]},text:{"text/plain":[".txt"]},all:{}},O=r=>{if(r===0)return"0 B";const e=Math.floor(Math.log(r)/Math.log(u));return`${(r/Math.pow(u,e)).toFixed(2)} ${$[e]}`},Z=r=>r.reduce((e,l)=>({...e,...k[l]}),{}),z=r=>{const e=r.name.split(".").pop()?.toLowerCase();return e?["jpg","jpeg","png","webp"].includes(e)?"image":e==="pdf"?"pdf":["doc","docx"].includes(e)?"doc":["xls","xlsx"].includes(e)?"excel":e==="txt"?"text":"other":"other"},K=({value:r=null,onChange:e,multiple:l=!1,maxFiles:i=P,disabled:y=!1,className:d,maxSize:g=B,variant:m="grid",accepts:T=C,icon:U,title:j,text:v,showFiles:_=!0})=>{const[f,w]=b.useState(!1),[A,x]=b.useState(null),s=Array.isArray(r)?r:r?[r]:[],E=b.useCallback((o,n)=>{if(x(null),s.length+o.length>i){x(`Максимальное количество файлов: ${i}`);return}if(n.length>0){const c=n[0].errors[0]?.code==="file-too-large"?`Файл слишком большой. Максимальный размер: ${g/1024/1024}MB`:"Неподдерживаемый формат файла";x(c);return}w(!0),setTimeout(()=>{const a=o.map(c=>({url:URL.createObjectURL(c),name:c.name,size:O(c.size),addedAt:new Date().toISOString()}));l?e?.([...s,...a]):(s[0]?.url?.startsWith("blob:")&&URL.revokeObjectURL(s[0].url),e?.(a[0]??null)),w(!1)},F)},[s,i,g,l,e]),{getRootProps:I,getInputProps:M,isDragActive:N}=D.useDropzone({onDrop:E,accept:Z(T),maxSize:g,multiple:l&&i>1,disabled:y||f,maxFiles:i-s.length}),R=o=>()=>{s[o]?.url?.startsWith("blob:")&&URL.revokeObjectURL(s[o].url);const n=s.filter((a,c)=>c!==o);e?.(l?n:n[0]||null)},S=s.length>=i,q={grid:"grid-cols-2 sm:grid-cols-3 md:grid-cols-4",list:"grid-cols-1",compact:"grid-cols-2 sm:grid-cols-3"};return t.jsxs("div",{className:p.cn("w-full space-y-4",d?.container),children:[t.jsxs("div",{className:p.cn("grid h-full w-full gap-4",m==="list"?"grid-cols-1":q[m]),children:[_&&s.map((o,n)=>{const a=z(o);return t.jsxs("div",{className:`group bg-primary-bg relative aspect-square h-full w-full
2
- overflow-hidden rounded-lg`,children:[a==="image"?t.jsx("img",{src:o.url,alt:`Preview ${n+1}`,className:"h-full w-full object-cover"}):t.jsx("div",{className:`flex h-full w-full items-center justify-center bg-gray-100
3
- text-sm font-semibold`,children:o.name.split(".").pop()?.toUpperCase()}),t.jsx("div",{className:`text-primary-bg bg-primary-inverse-bg/50 absolute inset-0 flex
4
- cursor-pointer items-center justify-center rounded-lg opacity-0
5
- transition-opacity hover:opacity-100`,onClick:c=>c.stopPropagation(),children:t.jsx(h.Icon,{type:"x",onClick:R(n)})})]},n)}),(!S||!_)&&t.jsxs("div",{...I(),className:p.cn(`relative flex cursor-pointer flex-col items-center justify-center
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),p=require("./lib-utils.cjs"),A=require("react"),X=require("./index-DJD-8LQA.cjs"),j=require("./components-ui-icon-icon.cjs"),M=require("./components-ui-typography-typography.cjs");require("./components-ui-typography-typography.styles.cjs");const G=["B","KB","MB","GB","TB"],f=1024,V=5*f*f,H=5,J=["all"],Q=800,W={image:{"image/*":[".jpg",".jpeg",".png",".webp"]},pdf:{"application/pdf":[".pdf"]},doc:{"application/msword":[".doc"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[".docx"]},excel:{"application/vnd.ms-excel":[".xls"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[".xlsx"]},text:{"text/plain":[".txt"]},all:{}},Y=e=>{if(!e)return"0 B";const t=Math.floor(Math.log(e)/Math.log(f));return`${(e/Math.pow(f,t)).toFixed(2)} ${G[t]}`},v=e=>`${e.name}:${e.size}`,ee=e=>e.reduce((t,o)=>({...t,...W[o]}),{}),te=(e,t)=>{const o=e.filter(n=>n.status==="uploaded"),l=e.filter(n=>n.status==="error"),a=Math.max(0,t-o.length);return[...o,...l.slice(0,a)]},w=(e,t,o)=>({url:URL.createObjectURL(e),name:e.name,size:Y(e.size),addedAt:new Date().toISOString(),status:t,error:o}),re=e=>e==="file-too-large"?"Файл слишком большой":"Неподдерживаемый формат",se=(e,t,o)=>{const l=new Set(o.map(v)),a=new Set(t.map(v));return e.filter(n=>{if(n.status!=="error")return!0;const g=v(n);return!l.has(g)&&!a.has(g)})},oe=e=>{const t=e.name.split(".").pop()?.toLowerCase();return t?["jpg","jpeg","png","webp"].includes(t)?"image":t==="pdf"?"pdf":["doc","docx"].includes(t)?"doc":["xls","xlsx"].includes(t)?"excel":t==="txt"?"text":"other":"other"},ne=({value:e=[],onChange:t,multiple:o=!1,maxFiles:l=H,disabled:a=!1,className:n,maxSize:g=V,variant:h="grid",accepts:U=J,icon:L,title:F,text:_,showFiles:$=!0,isErrorText:N=!1})=>{const[y,E]=A.useState(!1),[I,S]=A.useState(null),m=e,b=m.filter(r=>r.status==="uploaded").length,q=(r,c)=>{S(null);const u=Math.max(0,l-b),x=r.slice(0,u),Z=r.slice(u),d=[...c.map(i=>w(i.file,"error",re(i.errors[0]?.code))),...Z.map(i=>w(i,"error",`Максимальное количество файлов: ${l}`))];d.length&&S(d[0].error||"Ошибка загрузки"),!(!x.length&&!d.length)&&(E(!0),setTimeout(()=>{const i=x.map(K=>w(K,"uploaded")),k=se(m,i,d),T=o?te([...k,...i,...d],l):[...i,...d].slice(0,1);t?.(T.length?T:[]),E(!1)},Q))},{getRootProps:D,getInputProps:B,isDragActive:C}=X.useDropzone({onDrop:q,accept:ee(U),maxSize:g,multiple:o&&l>1,disabled:a||y}),R=r=>()=>{const c=m.filter((u,x)=>x!==r);t?.(c.length?c:[])},P=m.map((r,c)=>({file:r,index:c})).filter(({file:r})=>r.status==="uploaded"),z=b>=l,O={grid:"grid-cols-2 sm:grid-cols-3 md:grid-cols-4",list:"grid-cols-1",compact:"grid-cols-2 sm:grid-cols-3"};return s.jsxs("div",{className:p.cn("w-full space-y-4",n?.container),children:[s.jsxs("div",{className:p.cn("grid h-full w-full gap-4",h==="list"?"grid-cols-1":O[h]),children:[$&&P.map(({file:r,index:c})=>{const u=oe(r);return s.jsxs("div",{className:`group bg-primary-bg relative aspect-square h-full w-full
2
+ overflow-hidden rounded-lg`,children:[u==="image"?s.jsx("img",{src:r.url,className:"h-full w-full object-cover"}):s.jsx("div",{className:`flex h-full w-full items-center justify-center bg-gray-100
3
+ text-sm font-semibold`,children:r.name.split(".").pop()?.toUpperCase()}),s.jsx("div",{className:`bg-primary-inverse-bg/50 text-primary-bg absolute inset-0
4
+ flex items-center justify-center opacity-0 transition-opacity
5
+ hover:opacity-100`,children:s.jsx(j.Icon,{onClick:R(c),type:"x"})})]},`${r.url}-${r.addedAt}-${c}`)}),!z&&s.jsxs("div",{...D(),className:p.cn(`relative flex cursor-pointer flex-col items-center justify-center
6
6
  rounded-lg border-2 border-dashed border-gray-300 bg-gray-50
7
- transition-colors hover:bg-gray-100`,N&&"border-primary bg-primary/5",(y||f)&&"cursor-not-allowed opacity-50",m==="list"?"min-h-37.5":"aspect-square",d?.blockAdd),children:[t.jsx("input",{...M()}),f?t.jsx(h.Icon,{type:"spinner-gap",className:"text-sub-label-text h-8 w-8 animate-spin"}):t.jsxs("div",{className:"flex flex-col items-center space-y-2 p-4 text-center",children:[t.jsx(h.Icon,{type:U?.type??"plus",className:p.cn("text-sub-label-text h-8 w-8",d?.icon)}),t.jsx(L.Typography,{variant:"body-md-medium",className:p.cn("text-sub-label-text",d?.title),children:l?`${j||"Добавить"} (${s.length}/${i})`:`${j||"Добавить"}`}),v&&t.jsx(L.Typography,{variant:"body-xxs-medium",className:p.cn("text-sub-label-text",d?.text),children:v})]})]})]}),A&&t.jsx("div",{className:"rounded-lg bg-red-50 p-3 text-sm text-red-600",children:A})]})};exports.FilesUploader=K;
7
+ transition-colors hover:bg-gray-100`,C&&"border-primary bg-primary/5",(a||y)&&"cursor-not-allowed opacity-50",h==="list"?"min-h-37.5":"aspect-square",n?.blockAdd),children:[s.jsx("input",{...B()}),y?s.jsx(j.Icon,{type:"spinner-gap",className:"text-sub-label-text h-8 w-8 animate-spin"}):s.jsxs("div",{className:"flex flex-col items-center space-y-2 p-4 text-center",children:[s.jsx(j.Icon,{type:L?.type??"plus",className:p.cn("text-sub-label-text h-8 w-8",n?.icon)}),s.jsx(M.Typography,{className:p.cn("text-sub-label-text",n?.title),children:o?`${F||"Добавить"} (${b}/${l})`:F||"Добавить"}),_&&s.jsx(M.Typography,{className:p.cn("text-sub-label-text",n?.text),children:_})]})]})]}),!N&&I&&s.jsx("div",{className:"rounded-lg bg-red-50 p-3 text-sm text-red-600",children:I})]})};exports.FilesUploader=ne;
8
8
  //# sourceMappingURL=components-files-uploader-files-uploader.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"components-files-uploader-files-uploader.cjs","sources":["../src/components/files-uploader/files-uploader.tsx"],"sourcesContent":["import { cn } from \"@/lib/utils\";\nimport { useCallback, useState } from \"react\";\nimport { type FileRejection, useDropzone } from \"react-dropzone\";\nimport { Icon, type IconProps } from \"../ui/icon\";\nimport { Typography } from \"../ui/typography\";\n\ntype Variant = \"grid\" | \"list\" | \"compact\";\ntype AcceptType = \"image\" | \"pdf\" | \"doc\" | \"excel\" | \"text\" | \"all\";\ntype UploadedFileData = {\n url: string;\n name: string;\n size: string;\n addedAt: string;\n};\ntype FilesUploaderValue = UploadedFileData | UploadedFileData[] | null;\n\ntype PropsFilesUploader = {\n value?: FilesUploaderValue;\n onChange?: (value: FilesUploaderValue) => void;\n multiple?: boolean;\n maxFiles?: number;\n disabled?: boolean;\n className?: {\n container?: string;\n blockAdd?: string;\n title?: string;\n text?: string;\n icon?: string;\n };\n displayFiles?: boolean;\n maxSize?: number;\n variant?: Variant;\n accepts?: AcceptType[];\n icon?: IconProps;\n title?: string;\n text?: string;\n showFiles?: boolean,\n \n};\nconst FILE_SIZE_UNITS = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\nconst FILE_SIZE_KB = 1024;\nconst DEFAULT_MAX_SIZE = 5 * FILE_SIZE_KB * FILE_SIZE_KB;\nconst DEFAULT_MAX_FILES = 5;\nconst DEFAULT_ACCEPT: AcceptType[] = [\"all\"];\nconst DEFAULT_TIMEOUT = 800;\n\nconst ACCEPT_MAP: Record<AcceptType, Record<string, string[]>> = {\n image: { \"image/*\": [\".jpg\", \".jpeg\", \".png\", \".webp\"] },\n pdf: { \"application/pdf\": [\".pdf\"] },\n doc: {\n \"application/msword\": [\".doc\"],\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\": [\".docx\"],\n },\n excel: {\n \"application/vnd.ms-excel\": [\".xls\"],\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": [\".xlsx\"],\n },\n text: { \"text/plain\": [\".txt\"] },\n all: {},\n};\n\nconst formatFileSize = (bytes: number) => {\n if (bytes === 0) return \"0 B\";\n const i = Math.floor(Math.log(bytes) / Math.log(FILE_SIZE_KB));\n return `${(bytes / Math.pow(FILE_SIZE_KB, i)).toFixed(2)} ${FILE_SIZE_UNITS[i]}`;\n};\n\nconst fileAcceptMap = (accepts: AcceptType[]): Record<string, string[]> =>\n accepts.reduce((acc, t) => ({ ...acc, ...ACCEPT_MAP[t] }), {});\n\nconst getFileType = (file: UploadedFileData) => {\n const ext = file.name.split(\".\").pop()?.toLowerCase();\n\n if (!ext) return \"other\";\n\n if ([\"jpg\", \"jpeg\", \"png\", \"webp\"].includes(ext)) return \"image\";\n if (ext === \"pdf\") return \"pdf\";\n if ([\"doc\", \"docx\"].includes(ext)) return \"doc\";\n if ([\"xls\", \"xlsx\"].includes(ext)) return \"excel\";\n if (ext === \"txt\") return \"text\";\n\n return \"other\";\n};\n\nexport const FilesUploader = ({\n value = null,\n onChange,\n multiple = false,\n maxFiles = DEFAULT_MAX_FILES,\n disabled = false,\n className,\n maxSize = DEFAULT_MAX_SIZE,\n variant = \"grid\",\n accepts = DEFAULT_ACCEPT,\n icon,\n title,\n text,\n showFiles = true,\n}: PropsFilesUploader) => {\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const files = Array.isArray(value) ? value : value ? [value] : [];\n \n\n const onDrop = useCallback(\n (acceptedFiles: File[], rejectedFiles: FileRejection[]) => {\n setError(null);\n\n if (files.length + acceptedFiles.length > maxFiles) {\n setError(`Максимальное количество файлов: ${maxFiles}`);\n return;\n }\n\n if (rejectedFiles.length > 0) {\n const rejection = rejectedFiles[0];\n const errorMessage =\n rejection.errors[0]?.code === \"file-too-large\"\n ? `Файл слишком большой. Максимальный размер: ${maxSize / 1024 / 1024}MB`\n : \"Неподдерживаемый формат файла\";\n setError(errorMessage);\n return;\n }\n\n setLoading(true);\n\n setTimeout(() => {\n const newFilesData: UploadedFileData[] = acceptedFiles.map((file) => ({\n url: URL.createObjectURL(file),\n name: file.name,\n size: formatFileSize(file.size),\n addedAt: new Date().toISOString(),\n }));\n\n if (multiple) {\n onChange?.([...files, ...newFilesData]);\n } else {\n if (files[0]?.url?.startsWith(\"blob:\")) URL.revokeObjectURL(files[0].url);\n onChange?.(newFilesData[0] ?? null);\n }\n\n setLoading(false);\n }, DEFAULT_TIMEOUT);\n },\n [files, maxFiles, maxSize, multiple, onChange],\n );\n\n const { getRootProps, getInputProps, isDragActive } = useDropzone({\n onDrop,\n accept: fileAcceptMap(accepts),\n maxSize,\n multiple: multiple && maxFiles > 1,\n disabled: disabled || loading,\n maxFiles: maxFiles - files.length,\n });\n\n const removeImage = (index: number) => {\n return () => {\n if (files[index]?.url?.startsWith(\"blob:\")) {\n URL.revokeObjectURL(files[index].url);\n }\n const newFiles = files.filter((_, i) => i !== index);\n onChange?.(multiple ? newFiles : newFiles[0] || null);\n };\n };\n\n const isMaxFilesReached = files.length >= maxFiles;\n\n // Варианты отображения\n const gridClasses = {\n grid: \"grid-cols-2 sm:grid-cols-3 md:grid-cols-4\",\n list: \"grid-cols-1\",\n compact: \"grid-cols-2 sm:grid-cols-3\",\n };\n\n return (\n <div className={cn(\"w-full space-y-4\", className?.container)}>\n {/* Предпросмотр с возможностью добавления новых */}\n <div\n className={cn(\n \"grid h-full w-full gap-4\",\n variant === \"list\" ? \"grid-cols-1\" : gridClasses[variant],\n )}\n >\n {showFiles && files.map((file, index) => {\n const type = getFileType(file);\n\n return (\n <div\n key={index}\n className=\"group bg-primary-bg relative aspect-square h-full w-full\n overflow-hidden rounded-lg\"\n >\n {type === \"image\" ? (\n <img\n src={file.url}\n alt={`Preview ${index + 1}`}\n className=\"h-full w-full object-cover\"\n />\n ) : (\n <div\n className=\"flex h-full w-full items-center justify-center bg-gray-100\n text-sm font-semibold\"\n >\n {file.name.split(\".\").pop()?.toUpperCase()}\n </div>\n )}\n\n <div\n className=\"text-primary-bg bg-primary-inverse-bg/50 absolute inset-0 flex\n cursor-pointer items-center justify-center rounded-lg opacity-0\n transition-opacity hover:opacity-100\"\n onClick={(e) => e.stopPropagation()}\n >\n <Icon\n type=\"x\"\n onClick={removeImage(index)}\n />\n </div>\n </div>\n );\n })}\n {/* Кнопка добавления нового изображения */}\n {(!isMaxFilesReached || !showFiles) && (\n <div\n {...getRootProps()}\n className={cn(\n `relative flex cursor-pointer flex-col items-center justify-center\n rounded-lg border-2 border-dashed border-gray-300 bg-gray-50\n transition-colors hover:bg-gray-100`,\n isDragActive && \"border-primary bg-primary/5\",\n (disabled || loading) && \"cursor-not-allowed opacity-50\",\n variant === \"list\" ? \"min-h-37.5\" : \"aspect-square\",\n className?.blockAdd,\n )}\n >\n <input {...getInputProps()} />\n\n {loading ? (\n <Icon\n type=\"spinner-gap\"\n className=\"text-sub-label-text h-8 w-8 animate-spin\"\n />\n ) : (\n <div className=\"flex flex-col items-center space-y-2 p-4 text-center\">\n <Icon\n type={icon?.type ?? \"plus\"}\n className={cn(\"text-sub-label-text h-8 w-8\", className?.icon)}\n />\n <Typography\n variant=\"body-md-medium\"\n className={cn(\"text-sub-label-text\", className?.title)}\n >\n {multiple\n ? `${title || \"Добавить\"} (${files.length}/${maxFiles})`\n : `${title || \"Добавить\"}`}\n </Typography>\n {text && (\n <Typography variant=\"body-xxs-medium\" className={cn(\"text-sub-label-text\", className?.text)}>\n {text}\n </Typography>\n )}\n </div>\n )}\n </div>\n )}\n </div>\n\n {/* Информация о количестве */}\n {/* {multiple && images.length > 0 && (\n <p className=\"text-xs text-gray-500\">\n Загружено {images.length} из {maxFiles} изображений\n </p>\n )} */}\n\n {/* Ошибка */}\n {error && (\n <div className=\"rounded-lg bg-red-50 p-3 text-sm text-red-600\">{error}</div>\n )}\n </div>\n );\n};\n\nexport type { PropsFilesUploader, UploadedFileData, FilesUploaderValue };\n"],"names":["FILE_SIZE_UNITS","FILE_SIZE_KB","DEFAULT_MAX_SIZE","DEFAULT_MAX_FILES","DEFAULT_ACCEPT","DEFAULT_TIMEOUT","ACCEPT_MAP","formatFileSize","bytes","i","fileAcceptMap","accepts","acc","t","getFileType","file","ext","FilesUploader","value","onChange","multiple","maxFiles","disabled","className","maxSize","variant","icon","title","text","showFiles","loading","setLoading","useState","error","setError","files","onDrop","useCallback","acceptedFiles","rejectedFiles","errorMessage","newFilesData","getRootProps","getInputProps","isDragActive","useDropzone","removeImage","index","newFiles","_","isMaxFilesReached","gridClasses","cn","jsxs","type","jsx","e","Icon","Typography"],"mappings":"qWAuCA,MAAMA,EAAkB,CAAC,IAAK,KAAM,KAAM,KAAM,IAAI,EAC9CC,EAAe,KACfC,EAAmB,EAAID,EAAeA,EACtCE,EAAoB,EACpBC,EAA+B,CAAC,KAAK,EACrCC,EAAkB,IAElBC,EAA2D,CAC/D,MAAO,CAAE,UAAW,CAAC,OAAQ,QAAS,OAAQ,OAAO,CAAA,EACrD,IAAK,CAAE,kBAAmB,CAAC,MAAM,CAAA,EACjC,IAAK,CACH,qB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A,EAGb,SAAA,CAAAgC,EAAAA,IAAC,QAAA,CAAO,GAAGZ,EAAA,CAAc,CAAG,EAE3Bb,EACCyB,EAAAA,IAACE,EAAAA,KAAA,CACC,KAAK,cACL,UAAU,0CAAA,CAAA,EAGZJ,EAAAA,KAAC,MAAA,CAAI,UAAU,uDACb,SAAA,CAAAE,EAAAA,IAACE,EAAAA,KAAA,CACC,KAAM/B,GAAM,MAAQ,OACpB,UAAW0B,EAAAA,GAAG,8BAA+B7B,GAAW,IAAI,CAAA,CAAA,EAE9DgC,EAAAA,IAACG,EAAAA,WAAA,CACC,QAAQ,iBACR,UAAWN,EAAAA,GAAG,sBAAuB7B,GAAW,KAAK,EAEpD,SAAAH,EACG,GAAGO,GAAS,UAAU,KAAKQ,EAAM,MAAM,IAAId,CAAQ,IACnD,GAAGM,GAAS,UAAU,EAAA,CAAA,EAE3BC,GACC2B,EAAAA,IAACG,EAAAA,WAAA,CAAW,QAAQ,kBAAkB,UAAWN,EAAAA,GAAG,sBAAuB7B,GAAW,IAAI,EACvF,SAAAK,CAAA,CACH,CAAA,CAAA,CAEJ,CAAA,CAAA,CAAA,CAEJ,CAAA,CAAA,EAYHK,GACCsB,EAAAA,IAAC,MAAA,CAAI,UAAU,gDAAiD,SAAAtB,CAAA,CAAM,CAAA,EAE1E,CAEJ"}
1
+ {"version":3,"file":"components-files-uploader-files-uploader.cjs","sources":["../src/components/files-uploader/files-uploader.tsx"],"sourcesContent":["import { cn } from \"@/lib/utils\";\nimport { useState } from \"react\";\nimport { type FileRejection, useDropzone } from \"react-dropzone\";\nimport { Icon, type IconProps } from \"../ui/icon\";\nimport { Typography } from \"../ui/typography\";\n\ntype Variant = \"grid\" | \"list\" | \"compact\";\ntype AcceptType = \"image\" | \"pdf\" | \"doc\" | \"excel\" | \"text\" | \"all\";\n\nexport type UploadedFileData = {\n url: string;\n name: string;\n size: string;\n addedAt: string;\n status: \"uploaded\" | \"error\";\n error?: string;\n};\n\nexport type FilesUploaderValue = UploadedFileData[] | [];\n\nexport type PropsFilesUploader = {\n value?: FilesUploaderValue;\n onChange?: (value: FilesUploaderValue) => void;\n multiple?: boolean;\n maxFiles?: number;\n disabled?: boolean;\n isErrorText?: boolean;\n className?: {\n container?: string;\n blockAdd?: string;\n title?: string;\n text?: string;\n icon?: string;\n };\n maxSize?: number;\n variant?: Variant;\n accepts?: AcceptType[];\n icon?: IconProps;\n title?: string;\n text?: string;\n showFiles?: boolean;\n};\n\nconst FILE_SIZE_UNITS = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\nconst FILE_SIZE_KB = 1024;\n\nconst DEFAULT_MAX_SIZE = 5 * FILE_SIZE_KB * FILE_SIZE_KB;\nconst DEFAULT_MAX_FILES = 5;\nconst DEFAULT_ACCEPT: AcceptType[] = [\"all\"];\nconst DEFAULT_TIMEOUT = 800;\n\nconst ACCEPT_MAP: Record<AcceptType, Record<string, string[]>> = {\n image: { \"image/*\": [\".jpg\", \".jpeg\", \".png\", \".webp\"] },\n pdf: { \"application/pdf\": [\".pdf\"] },\n doc: {\n \"application/msword\": [\".doc\"],\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\": [\".docx\"],\n },\n excel: {\n \"application/vnd.ms-excel\": [\".xls\"],\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": [\".xlsx\"],\n },\n text: { \"text/plain\": [\".txt\"] },\n all: {},\n};\n\nconst formatFileSize = (bytes: number) => {\n if (!bytes) return \"0 B\";\n const i = Math.floor(Math.log(bytes) / Math.log(FILE_SIZE_KB));\n return `${(bytes / Math.pow(FILE_SIZE_KB, i)).toFixed(2)} ${FILE_SIZE_UNITS[i]}`;\n};\n\nconst getFileIdentity = (file: Pick<UploadedFileData, \"name\" | \"size\">) =>\n `${file.name}:${file.size}`;\n\nconst fileAcceptMap = (accepts: AcceptType[]) =>\n accepts.reduce((acc, t) => ({ ...acc, ...ACCEPT_MAP[t] }), {});\n\nconst limitFilesForValue = (\n nextFiles: UploadedFileData[],\n maxFiles: number,\n): UploadedFileData[] => {\n const uploadedFiles = nextFiles.filter((file) => file.status === \"uploaded\");\n const errorFiles = nextFiles.filter((file) => file.status === \"error\");\n const availableErrorSlots = Math.max(0, maxFiles - uploadedFiles.length);\n\n return [...uploadedFiles, ...errorFiles.slice(0, availableErrorSlots)];\n};\n\nconst mapFile = (\n file: File,\n status: UploadedFileData[\"status\"],\n error?: string,\n): UploadedFileData => ({\n url: URL.createObjectURL(file),\n name: file.name,\n size: formatFileSize(file.size),\n addedAt: new Date().toISOString(),\n status,\n error,\n});\n\nconst getRejectedError = (code?: string) =>\n code === \"file-too-large\" ? \"Файл слишком большой\" : \"Неподдерживаемый формат\";\n\nconst replaceDuplicateErrors = (\n currentFiles: UploadedFileData[],\n newFiles: UploadedFileData[],\n rejectedFiles: UploadedFileData[],\n) => {\n const rejectedFileIds = new Set(rejectedFiles.map(getFileIdentity));\n const acceptedFileIds = new Set(newFiles.map(getFileIdentity));\n\n return currentFiles.filter((existingFile) => {\n if (existingFile.status !== \"error\") return true;\n const id = getFileIdentity(existingFile);\n return !rejectedFileIds.has(id) && !acceptedFileIds.has(id);\n });\n};\n\nconst getFileType = (file: UploadedFileData) => {\n const ext = file.name.split(\".\").pop()?.toLowerCase();\n\n if (!ext) return \"other\";\n if ([\"jpg\", \"jpeg\", \"png\", \"webp\"].includes(ext)) return \"image\";\n if (ext === \"pdf\") return \"pdf\";\n if ([\"doc\", \"docx\"].includes(ext)) return \"doc\";\n if ([\"xls\", \"xlsx\"].includes(ext)) return \"excel\";\n if (ext === \"txt\") return \"text\";\n\n return \"other\";\n};\n\nexport const FilesUploader = ({\n value = [],\n onChange,\n multiple = false,\n maxFiles = DEFAULT_MAX_FILES,\n disabled = false,\n className,\n maxSize = DEFAULT_MAX_SIZE,\n variant = \"grid\",\n accepts = DEFAULT_ACCEPT,\n icon,\n title,\n text,\n showFiles = true,\n isErrorText = false,\n}: PropsFilesUploader) => {\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const files = value;\n const uploadedCount = files.filter((file) => file.status === \"uploaded\").length;\n\n const onDrop = (acceptedFiles: File[], rejectedFiles: FileRejection[]) => {\n setError(null);\n const remainingUploadSlots = Math.max(0, maxFiles - uploadedCount);\n const acceptedFilesToUpload = acceptedFiles.slice(0, remainingUploadSlots);\n const overflowAcceptedFiles = acceptedFiles.slice(remainingUploadSlots);\n\n const rejectedMapped = [\n ...rejectedFiles.map((rejection) =>\n mapFile(rejection.file, \"error\", getRejectedError(rejection.errors[0]?.code)),\n ),\n ...overflowAcceptedFiles.map((file) =>\n mapFile(file, \"error\", `Максимальное количество файлов: ${maxFiles}`),\n ),\n ];\n\n if (rejectedMapped.length) {\n setError(rejectedMapped[0].error || \"Ошибка загрузки\");\n }\n\n if (!acceptedFilesToUpload.length && !rejectedMapped.length) return;\n\n setLoading(true);\n\n setTimeout(() => {\n const newFiles = acceptedFilesToUpload.map((file) => mapFile(file, \"uploaded\"));\n const nextBaseFiles = replaceDuplicateErrors(files, newFiles, rejectedMapped);\n const nextFiles = multiple\n ? limitFilesForValue([...nextBaseFiles, ...newFiles, ...rejectedMapped], maxFiles)\n : [...newFiles, ...rejectedMapped].slice(0, 1);\n\n onChange?.(nextFiles.length ? nextFiles : []);\n setLoading(false);\n }, DEFAULT_TIMEOUT);\n };\n\n const { getRootProps, getInputProps, isDragActive } = useDropzone({\n onDrop,\n accept: fileAcceptMap(accepts),\n maxSize,\n multiple: multiple && maxFiles > 1,\n disabled: disabled || loading,\n });\n\n const removeFile = (index: number) => () => {\n const updated = files.filter((_, i) => i !== index);\n onChange?.(updated.length ? updated : []);\n };\n\n const uploadedFiles = files\n .map((file, index) => ({ file, index }))\n .filter(({ file }) => file.status === \"uploaded\");\n\n const isMaxFilesReached = uploadedCount >= maxFiles;\n\n const gridClasses = {\n grid: \"grid-cols-2 sm:grid-cols-3 md:grid-cols-4\",\n list: \"grid-cols-1\",\n compact: \"grid-cols-2 sm:grid-cols-3\",\n };\n\n return (\n <div className={cn(\"w-full space-y-4\", className?.container)}>\n <div\n className={cn(\n \"grid h-full w-full gap-4\",\n variant === \"list\" ? \"grid-cols-1\" : gridClasses[variant],\n )}\n >\n {showFiles &&\n uploadedFiles.map(({ file, index }) => {\n const type = getFileType(file);\n\n return (\n <div\n key={`${file.url}-${file.addedAt}-${index}`}\n className=\"group bg-primary-bg relative aspect-square h-full w-full\n overflow-hidden rounded-lg\"\n >\n {type === \"image\" ? (\n <img\n src={file.url}\n className=\"h-full w-full object-cover\"\n />\n ) : (\n <div\n className=\"flex h-full w-full items-center justify-center bg-gray-100\n text-sm font-semibold\"\n >\n {file.name.split(\".\").pop()?.toUpperCase()}\n </div>\n )}\n\n <div\n className=\"bg-primary-inverse-bg/50 text-primary-bg absolute inset-0\n flex items-center justify-center opacity-0 transition-opacity\n hover:opacity-100\"\n >\n <Icon\n onClick={removeFile(index)}\n type={\"x\"}\n />\n </div>\n </div>\n );\n })}\n\n {!isMaxFilesReached && (\n <div\n {...getRootProps()}\n className={cn(\n `relative flex cursor-pointer flex-col items-center justify-center\n rounded-lg border-2 border-dashed border-gray-300 bg-gray-50\n transition-colors hover:bg-gray-100`,\n isDragActive && \"border-primary bg-primary/5\",\n (disabled || loading) && \"cursor-not-allowed opacity-50\",\n variant === \"list\" ? \"min-h-37.5\" : \"aspect-square\",\n className?.blockAdd,\n )}\n >\n <input {...getInputProps()} />\n\n {loading ? (\n <Icon\n type=\"spinner-gap\"\n className=\"text-sub-label-text h-8 w-8 animate-spin\"\n />\n ) : (\n <div className=\"flex flex-col items-center space-y-2 p-4 text-center\">\n <Icon\n type={icon?.type ?? \"plus\"}\n className={cn(\"text-sub-label-text h-8 w-8\", className?.icon)}\n />\n\n <Typography className={cn(\"text-sub-label-text\", className?.title)}>\n {multiple\n ? `${title || \"Добавить\"} (${uploadedCount}/${maxFiles})`\n : title || \"Добавить\"}\n </Typography>\n\n {text && (\n <Typography className={cn(\"text-sub-label-text\", className?.text)}>\n {text}\n </Typography>\n )}\n </div>\n )}\n </div>\n )}\n </div>\n\n {!isErrorText && error && (\n <div className=\"rounded-lg bg-red-50 p-3 text-sm text-red-600\">{error}</div>\n )}\n </div>\n );\n};\n"],"names":["FILE_SIZE_UNITS","FILE_SIZE_KB","DEFAULT_MAX_SIZE","DEFAULT_MAX_FILES","DEFAULT_ACCEPT","DEFAULT_TIMEOUT","ACCEPT_MAP","formatFileSize","bytes","i","getFileIdentity","file","fileAcceptMap","accepts","acc","t","limitFilesForValue","nextFiles","maxFiles","uploadedFiles","errorFiles","availableErrorSlots","mapFile","status","error","getRejectedError","code","replaceDuplicateErrors","currentFiles","newFiles","rejectedFiles","rejectedFileIds","acceptedFileIds","existingFile","id","getFileType","ext","FilesUploader","value","onChange","multiple","disabled","className","maxSize","variant","icon","title","text","showFiles","isErrorText","loading","setLoading","useState","setError","files","uploadedCount","onDrop","acceptedFiles","remainingUploadSlots","acceptedFilesToUpload","overflowAcceptedFiles","rejectedMapped","rejection","nextBaseFiles","getRootProps","getInputProps","isDragActive","useDropzone","removeFile","index","updated","_","isMaxFilesReached","gridClasses","cn","jsxs","type","jsx","Icon","Typography"],"mappings":"qWA2CA,MAAMA,EAAkB,CAAC,IAAK,KAAM,KAAM,KAAM,IAAI,EAC9CC,EAAe,KAEfC,EAAmB,EAAID,EAAeA,EACtCE,EAAoB,EACpBC,EAA+B,CAAC,KAAK,EACrCC,EAAkB,IAElBC,EAA2D,CAC/D,MAAO,CAAE,UAAW,CAAC,OAAQ,QAAS,OAAQ,OAAO,CAAA,EACrD,IAAK,CAAE,kBAAmB,CAAC,MAAM,CAAA,EACjC,IAAK,CACH,qBAAsB,CAAC,MAAM,EAC7B,0EAA2E,CAAC,OAAO,CAAA,EAErF,MAAO,CACL,2BAA4B,CAAC,MAAM,EACnC,oEAAqE,CAAC,OAAO,CAAA,EAE/E,KAAM,CAAE,aAAc,CAAC,MAAM,CAAA,EAC7B,IAAK,CAAA,CACP,EAEMC,EAAkBC,GAAkB,CACxC,GAAI,CAACA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,GAAW,KAAK,EAC9D,SAAAF,EACG,GAAGM,GAAS,UAAU,KAAKS,CAAa,IAAIrC,CAAQ,IACpD4B,GAAS,WACf,EAECC,SACEgC,aAAA,CAAW,UAAWL,EAAAA,GAAG,sBAAuBhC,GAAW,IAAI,EAC7D,SAAAK,CAAA,CACH,CAAA,CAAA,CAEJ,CAAA,CAAA,CAAA,CAEJ,CAAA,CAAA,EAIH,CAACE,GAAezB,SACd,MAAA,CAAI,UAAU,gDAAiD,SAAAA,CAAA,CAAM,CAAA,EAE1E,CAEJ"}
@@ -1,11 +1,11 @@
1
- import { jsxs as u, jsx as s } from "react/jsx-runtime";
1
+ import { jsxs as m, jsx as n } from "react/jsx-runtime";
2
2
  import { cn as p } from "./lib-utils.js";
3
- import { useState as E, useCallback as C } from "react";
4
- import { u as P } from "./index-CVlBIwtP.js";
5
- import { Icon as x } from "./components-ui-icon-icon.js";
6
- import { Typography as U } from "./components-ui-typography-typography.js";
3
+ import { useState as U } from "react";
4
+ import { u as G } from "./index-CVlBIwtP.js";
5
+ import { Icon as w } from "./components-ui-icon-icon.js";
6
+ import { Typography as _ } from "./components-ui-typography-typography.js";
7
7
  import "./components-ui-typography-typography.styles.js";
8
- const S = ["B", "KB", "MB", "GB", "TB"], g = 1024, k = 5 * g * g, F = 5, O = ["all"], Z = 800, q = {
8
+ const V = ["B", "KB", "MB", "GB", "TB"], x = 1024, H = 5 * x * x, J = 5, Q = ["all"], W = 800, Y = {
9
9
  image: { "image/*": [".jpg", ".jpeg", ".png", ".webp"] },
10
10
  pdf: { "application/pdf": [".pdf"] },
11
11
  doc: {
@@ -18,157 +18,156 @@ const S = ["B", "KB", "MB", "GB", "TB"], g = 1024, k = 5 * g * g, F = 5, O = ["a
18
18
  },
19
19
  text: { "text/plain": [".txt"] },
20
20
  all: {}
21
- }, z = (t) => {
22
- if (t === 0) return "0 B";
23
- const e = Math.floor(Math.log(t) / Math.log(g));
24
- return `${(t / Math.pow(g, e)).toFixed(2)} ${S[e]}`;
25
- }, K = (t) => t.reduce((e, i) => ({ ...e, ...q[i] }), {}), W = (t) => {
26
- const e = t.name.split(".").pop()?.toLowerCase();
27
- return e ? ["jpg", "jpeg", "png", "webp"].includes(e) ? "image" : e === "pdf" ? "pdf" : ["doc", "docx"].includes(e) ? "doc" : ["xls", "xlsx"].includes(e) ? "excel" : e === "txt" ? "text" : "other" : "other";
28
- }, ee = ({
29
- value: t = null,
30
- onChange: e,
31
- multiple: i = !1,
32
- maxFiles: c = F,
33
- disabled: y = !1,
34
- className: d,
35
- maxSize: m = k,
36
- variant: f = "grid",
37
- accepts: M = O,
38
- icon: T,
39
- title: v,
40
- text: w,
41
- showFiles: A = !0
21
+ }, ee = (e) => {
22
+ if (!e) return "0 B";
23
+ const t = Math.floor(Math.log(e) / Math.log(x));
24
+ return `${(e / Math.pow(x, t)).toFixed(2)} ${V[t]}`;
25
+ }, F = (e) => `${e.name}:${e.size}`, te = (e) => e.reduce((t, o) => ({ ...t, ...Y[o] }), {}), re = (e, t) => {
26
+ const o = e.filter((s) => s.status === "uploaded"), l = e.filter((s) => s.status === "error"), a = Math.max(0, t - o.length);
27
+ return [...o, ...l.slice(0, a)];
28
+ }, E = (e, t, o) => ({
29
+ url: URL.createObjectURL(e),
30
+ name: e.name,
31
+ size: ee(e.size),
32
+ addedAt: (/* @__PURE__ */ new Date()).toISOString(),
33
+ status: t,
34
+ error: o
35
+ }), oe = (e) => e === "file-too-large" ? "Файл слишком большой" : "Неподдерживаемый формат", se = (e, t, o) => {
36
+ const l = new Set(o.map(F)), a = new Set(t.map(F));
37
+ return e.filter((s) => {
38
+ if (s.status !== "error") return !0;
39
+ const g = F(s);
40
+ return !l.has(g) && !a.has(g);
41
+ });
42
+ }, le = (e) => {
43
+ const t = e.name.split(".").pop()?.toLowerCase();
44
+ return t ? ["jpg", "jpeg", "png", "webp"].includes(t) ? "image" : t === "pdf" ? "pdf" : ["doc", "docx"].includes(t) ? "doc" : ["xls", "xlsx"].includes(t) ? "excel" : t === "txt" ? "text" : "other" : "other";
45
+ }, me = ({
46
+ value: e = [],
47
+ onChange: t,
48
+ multiple: o = !1,
49
+ maxFiles: l = J,
50
+ disabled: a = !1,
51
+ className: s,
52
+ maxSize: g = H,
53
+ variant: b = "grid",
54
+ accepts: L = Q,
55
+ icon: $,
56
+ title: A,
57
+ text: I,
58
+ showFiles: N = !0,
59
+ isErrorText: D = !1
42
60
  }) => {
43
- const [b, L] = E(!1), [j, h] = E(null), r = Array.isArray(t) ? t : t ? [t] : [], I = C(
44
- (o, l) => {
45
- if (h(null), r.length + o.length > c) {
46
- h(`Максимальное количество файлов: ${c}`);
47
- return;
48
- }
49
- if (l.length > 0) {
50
- const n = l[0].errors[0]?.code === "file-too-large" ? `Файл слишком большой. Максимальный размер: ${m / 1024 / 1024}MB` : "Неподдерживаемый формат файла";
51
- h(n);
52
- return;
53
- }
54
- L(!0), setTimeout(() => {
55
- const a = o.map((n) => ({
56
- url: URL.createObjectURL(n),
57
- name: n.name,
58
- size: z(n.size),
59
- addedAt: (/* @__PURE__ */ new Date()).toISOString()
60
- }));
61
- i ? e?.([...r, ...a]) : (r[0]?.url?.startsWith("blob:") && URL.revokeObjectURL(r[0].url), e?.(a[0] ?? null)), L(!1);
62
- }, Z);
63
- },
64
- [r, c, m, i, e]
65
- ), { getRootProps: _, getInputProps: N, isDragActive: D } = P({
66
- onDrop: I,
67
- accept: K(M),
68
- maxSize: m,
69
- multiple: i && c > 1,
70
- disabled: y || b,
71
- maxFiles: c - r.length
72
- }), $ = (o) => () => {
73
- r[o]?.url?.startsWith("blob:") && URL.revokeObjectURL(r[o].url);
74
- const l = r.filter((a, n) => n !== o);
75
- e?.(i ? l : l[0] || null);
76
- }, B = r.length >= c, R = {
61
+ const [y, M] = U(!1), [T, j] = U(null), f = e, v = f.filter((r) => r.status === "uploaded").length, B = (r, c) => {
62
+ j(null);
63
+ const u = Math.max(0, l - v), h = r.slice(0, u), q = r.slice(u), d = [
64
+ ...c.map(
65
+ (i) => E(i.file, "error", oe(i.errors[0]?.code))
66
+ ),
67
+ ...q.map(
68
+ (i) => E(i, "error", `Максимальное количество файлов: ${l}`)
69
+ )
70
+ ];
71
+ d.length && j(d[0].error || "Ошибка загрузки"), !(!h.length && !d.length) && (M(!0), setTimeout(() => {
72
+ const i = h.map((X) => E(X, "uploaded")), K = se(f, i, d), S = o ? re([...K, ...i, ...d], l) : [...i, ...d].slice(0, 1);
73
+ t?.(S.length ? S : []), M(!1);
74
+ }, W));
75
+ }, { getRootProps: C, getInputProps: z, isDragActive: P } = G({
76
+ onDrop: B,
77
+ accept: te(L),
78
+ maxSize: g,
79
+ multiple: o && l > 1,
80
+ disabled: a || y
81
+ }), R = (r) => () => {
82
+ const c = f.filter((u, h) => h !== r);
83
+ t?.(c.length ? c : []);
84
+ }, O = f.map((r, c) => ({ file: r, index: c })).filter(({ file: r }) => r.status === "uploaded"), Z = v >= l, k = {
77
85
  grid: "grid-cols-2 sm:grid-cols-3 md:grid-cols-4",
78
86
  list: "grid-cols-1",
79
87
  compact: "grid-cols-2 sm:grid-cols-3"
80
88
  };
81
- return /* @__PURE__ */ u("div", { className: p("w-full space-y-4", d?.container), children: [
82
- /* @__PURE__ */ u(
89
+ return /* @__PURE__ */ m("div", { className: p("w-full space-y-4", s?.container), children: [
90
+ /* @__PURE__ */ m(
83
91
  "div",
84
92
  {
85
93
  className: p(
86
94
  "grid h-full w-full gap-4",
87
- f === "list" ? "grid-cols-1" : R[f]
95
+ b === "list" ? "grid-cols-1" : k[b]
88
96
  ),
89
97
  children: [
90
- A && r.map((o, l) => {
91
- const a = W(o);
92
- return /* @__PURE__ */ u(
98
+ N && O.map(({ file: r, index: c }) => {
99
+ const u = le(r);
100
+ return /* @__PURE__ */ m(
93
101
  "div",
94
102
  {
95
103
  className: `group bg-primary-bg relative aspect-square h-full w-full
96
- overflow-hidden rounded-lg`,
104
+ overflow-hidden rounded-lg`,
97
105
  children: [
98
- a === "image" ? /* @__PURE__ */ s(
106
+ u === "image" ? /* @__PURE__ */ n(
99
107
  "img",
100
108
  {
101
- src: o.url,
102
- alt: `Preview ${l + 1}`,
109
+ src: r.url,
103
110
  className: "h-full w-full object-cover"
104
111
  }
105
- ) : /* @__PURE__ */ s(
112
+ ) : /* @__PURE__ */ n(
106
113
  "div",
107
114
  {
108
115
  className: `flex h-full w-full items-center justify-center bg-gray-100
109
- text-sm font-semibold`,
110
- children: o.name.split(".").pop()?.toUpperCase()
116
+ text-sm font-semibold`,
117
+ children: r.name.split(".").pop()?.toUpperCase()
111
118
  }
112
119
  ),
113
- /* @__PURE__ */ s(
120
+ /* @__PURE__ */ n(
114
121
  "div",
115
122
  {
116
- className: `text-primary-bg bg-primary-inverse-bg/50 absolute inset-0 flex
117
- cursor-pointer items-center justify-center rounded-lg opacity-0
118
- transition-opacity hover:opacity-100`,
119
- onClick: (n) => n.stopPropagation(),
120
- children: /* @__PURE__ */ s(
121
- x,
123
+ className: `bg-primary-inverse-bg/50 text-primary-bg absolute inset-0
124
+ flex items-center justify-center opacity-0 transition-opacity
125
+ hover:opacity-100`,
126
+ children: /* @__PURE__ */ n(
127
+ w,
122
128
  {
123
- type: "x",
124
- onClick: $(l)
129
+ onClick: R(c),
130
+ type: "x"
125
131
  }
126
132
  )
127
133
  }
128
134
  )
129
135
  ]
130
136
  },
131
- l
137
+ `${r.url}-${r.addedAt}-${c}`
132
138
  );
133
139
  }),
134
- (!B || !A) && /* @__PURE__ */ u(
140
+ !Z && /* @__PURE__ */ m(
135
141
  "div",
136
142
  {
137
- ..._(),
143
+ ...C(),
138
144
  className: p(
139
145
  `relative flex cursor-pointer flex-col items-center justify-center
140
146
  rounded-lg border-2 border-dashed border-gray-300 bg-gray-50
141
147
  transition-colors hover:bg-gray-100`,
142
- D && "border-primary bg-primary/5",
143
- (y || b) && "cursor-not-allowed opacity-50",
144
- f === "list" ? "min-h-37.5" : "aspect-square",
145
- d?.blockAdd
148
+ P && "border-primary bg-primary/5",
149
+ (a || y) && "cursor-not-allowed opacity-50",
150
+ b === "list" ? "min-h-37.5" : "aspect-square",
151
+ s?.blockAdd
146
152
  ),
147
153
  children: [
148
- /* @__PURE__ */ s("input", { ...N() }),
149
- b ? /* @__PURE__ */ s(
150
- x,
154
+ /* @__PURE__ */ n("input", { ...z() }),
155
+ y ? /* @__PURE__ */ n(
156
+ w,
151
157
  {
152
158
  type: "spinner-gap",
153
159
  className: "text-sub-label-text h-8 w-8 animate-spin"
154
160
  }
155
- ) : /* @__PURE__ */ u("div", { className: "flex flex-col items-center space-y-2 p-4 text-center", children: [
156
- /* @__PURE__ */ s(
157
- x,
158
- {
159
- type: T?.type ?? "plus",
160
- className: p("text-sub-label-text h-8 w-8", d?.icon)
161
- }
162
- ),
163
- /* @__PURE__ */ s(
164
- U,
161
+ ) : /* @__PURE__ */ m("div", { className: "flex flex-col items-center space-y-2 p-4 text-center", children: [
162
+ /* @__PURE__ */ n(
163
+ w,
165
164
  {
166
- variant: "body-md-medium",
167
- className: p("text-sub-label-text", d?.title),
168
- children: i ? `${v || "Добавить"} (${r.length}/${c})` : `${v || "Добавить"}`
165
+ type: $?.type ?? "plus",
166
+ className: p("text-sub-label-text h-8 w-8", s?.icon)
169
167
  }
170
168
  ),
171
- w && /* @__PURE__ */ s(U, { variant: "body-xxs-medium", className: p("text-sub-label-text", d?.text), children: w })
169
+ /* @__PURE__ */ n(_, { className: p("text-sub-label-text", s?.title), children: o ? `${A || "Добавить"} (${v}/${l})` : A || "Добавить" }),
170
+ I && /* @__PURE__ */ n(_, { className: p("text-sub-label-text", s?.text), children: I })
172
171
  ] })
173
172
  ]
174
173
  }
@@ -176,10 +175,10 @@ const S = ["B", "KB", "MB", "GB", "TB"], g = 1024, k = 5 * g * g, F = 5, O = ["a
176
175
  ]
177
176
  }
178
177
  ),
179
- j && /* @__PURE__ */ s("div", { className: "rounded-lg bg-red-50 p-3 text-sm text-red-600", children: j })
178
+ !D && T && /* @__PURE__ */ n("div", { className: "rounded-lg bg-red-50 p-3 text-sm text-red-600", children: T })
180
179
  ] });
181
180
  };
182
181
  export {
183
- ee as FilesUploader
182
+ me as FilesUploader
184
183
  };
185
184
  //# sourceMappingURL=components-files-uploader-files-uploader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components-files-uploader-files-uploader.js","sources":["../src/components/files-uploader/files-uploader.tsx"],"sourcesContent":["import { cn } from \"@/lib/utils\";\nimport { useCallback, useState } from \"react\";\nimport { type FileRejection, useDropzone } from \"react-dropzone\";\nimport { Icon, type IconProps } from \"../ui/icon\";\nimport { Typography } from \"../ui/typography\";\n\ntype Variant = \"grid\" | \"list\" | \"compact\";\ntype AcceptType = \"image\" | \"pdf\" | \"doc\" | \"excel\" | \"text\" | \"all\";\ntype UploadedFileData = {\n url: string;\n name: string;\n size: string;\n addedAt: string;\n};\ntype FilesUploaderValue = UploadedFileData | UploadedFileData[] | null;\n\ntype PropsFilesUploader = {\n value?: FilesUploaderValue;\n onChange?: (value: FilesUploaderValue) => void;\n multiple?: boolean;\n maxFiles?: number;\n disabled?: boolean;\n className?: {\n container?: string;\n blockAdd?: string;\n title?: string;\n text?: string;\n icon?: string;\n };\n displayFiles?: boolean;\n maxSize?: number;\n variant?: Variant;\n accepts?: AcceptType[];\n icon?: IconProps;\n title?: string;\n text?: string;\n showFiles?: boolean,\n \n};\nconst FILE_SIZE_UNITS = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\nconst FILE_SIZE_KB = 1024;\nconst DEFAULT_MAX_SIZE = 5 * FILE_SIZE_KB * FILE_SIZE_KB;\nconst DEFAULT_MAX_FILES = 5;\nconst DEFAULT_ACCEPT: AcceptType[] = [\"all\"];\nconst DEFAULT_TIMEOUT = 800;\n\nconst ACCEPT_MAP: Record<AcceptType, Record<string, string[]>> = {\n image: { \"image/*\": [\".jpg\", \".jpeg\", \".png\", \".webp\"] },\n pdf: { \"application/pdf\": [\".pdf\"] },\n doc: {\n \"application/msword\": [\".doc\"],\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\": [\".docx\"],\n },\n excel: {\n \"application/vnd.ms-excel\": [\".xls\"],\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": [\".xlsx\"],\n },\n text: { \"text/plain\": [\".txt\"] },\n all: {},\n};\n\nconst formatFileSize = (bytes: number) => {\n if (bytes === 0) return \"0 B\";\n const i = Math.floor(Math.log(bytes) / Math.log(FILE_SIZE_KB));\n return `${(bytes / Math.pow(FILE_SIZE_KB, i)).toFixed(2)} ${FILE_SIZE_UNITS[i]}`;\n};\n\nconst fileAcceptMap = (accepts: AcceptType[]): Record<string, string[]> =>\n accepts.reduce((acc, t) => ({ ...acc, ...ACCEPT_MAP[t] }), {});\n\nconst getFileType = (file: UploadedFileData) => {\n const ext = file.name.split(\".\").pop()?.toLowerCase();\n\n if (!ext) return \"other\";\n\n if ([\"jpg\", \"jpeg\", \"png\", \"webp\"].includes(ext)) return \"image\";\n if (ext === \"pdf\") return \"pdf\";\n if ([\"doc\", \"docx\"].includes(ext)) return \"doc\";\n if ([\"xls\", \"xlsx\"].includes(ext)) return \"excel\";\n if (ext === \"txt\") return \"text\";\n\n return \"other\";\n};\n\nexport const FilesUploader = ({\n value = null,\n onChange,\n multiple = false,\n maxFiles = DEFAULT_MAX_FILES,\n disabled = false,\n className,\n maxSize = DEFAULT_MAX_SIZE,\n variant = \"grid\",\n accepts = DEFAULT_ACCEPT,\n icon,\n title,\n text,\n showFiles = true,\n}: PropsFilesUploader) => {\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const files = Array.isArray(value) ? value : value ? [value] : [];\n \n\n const onDrop = useCallback(\n (acceptedFiles: File[], rejectedFiles: FileRejection[]) => {\n setError(null);\n\n if (files.length + acceptedFiles.length > maxFiles) {\n setError(`Максимальное количество файлов: ${maxFiles}`);\n return;\n }\n\n if (rejectedFiles.length > 0) {\n const rejection = rejectedFiles[0];\n const errorMessage =\n rejection.errors[0]?.code === \"file-too-large\"\n ? `Файл слишком большой. Максимальный размер: ${maxSize / 1024 / 1024}MB`\n : \"Неподдерживаемый формат файла\";\n setError(errorMessage);\n return;\n }\n\n setLoading(true);\n\n setTimeout(() => {\n const newFilesData: UploadedFileData[] = acceptedFiles.map((file) => ({\n url: URL.createObjectURL(file),\n name: file.name,\n size: formatFileSize(file.size),\n addedAt: new Date().toISOString(),\n }));\n\n if (multiple) {\n onChange?.([...files, ...newFilesData]);\n } else {\n if (files[0]?.url?.startsWith(\"blob:\")) URL.revokeObjectURL(files[0].url);\n onChange?.(newFilesData[0] ?? null);\n }\n\n setLoading(false);\n }, DEFAULT_TIMEOUT);\n },\n [files, maxFiles, maxSize, multiple, onChange],\n );\n\n const { getRootProps, getInputProps, isDragActive } = useDropzone({\n onDrop,\n accept: fileAcceptMap(accepts),\n maxSize,\n multiple: multiple && maxFiles > 1,\n disabled: disabled || loading,\n maxFiles: maxFiles - files.length,\n });\n\n const removeImage = (index: number) => {\n return () => {\n if (files[index]?.url?.startsWith(\"blob:\")) {\n URL.revokeObjectURL(files[index].url);\n }\n const newFiles = files.filter((_, i) => i !== index);\n onChange?.(multiple ? newFiles : newFiles[0] || null);\n };\n };\n\n const isMaxFilesReached = files.length >= maxFiles;\n\n // Варианты отображения\n const gridClasses = {\n grid: \"grid-cols-2 sm:grid-cols-3 md:grid-cols-4\",\n list: \"grid-cols-1\",\n compact: \"grid-cols-2 sm:grid-cols-3\",\n };\n\n return (\n <div className={cn(\"w-full space-y-4\", className?.container)}>\n {/* Предпросмотр с возможностью добавления новых */}\n <div\n className={cn(\n \"grid h-full w-full gap-4\",\n variant === \"list\" ? \"grid-cols-1\" : gridClasses[variant],\n )}\n >\n {showFiles && files.map((file, index) => {\n const type = getFileType(file);\n\n return (\n <div\n key={index}\n className=\"group bg-primary-bg relative aspect-square h-full w-full\n overflow-hidden rounded-lg\"\n >\n {type === \"image\" ? (\n <img\n src={file.url}\n alt={`Preview ${index + 1}`}\n className=\"h-full w-full object-cover\"\n />\n ) : (\n <div\n className=\"flex h-full w-full items-center justify-center bg-gray-100\n text-sm font-semibold\"\n >\n {file.name.split(\".\").pop()?.toUpperCase()}\n </div>\n )}\n\n <div\n className=\"text-primary-bg bg-primary-inverse-bg/50 absolute inset-0 flex\n cursor-pointer items-center justify-center rounded-lg opacity-0\n transition-opacity hover:opacity-100\"\n onClick={(e) => e.stopPropagation()}\n >\n <Icon\n type=\"x\"\n onClick={removeImage(index)}\n />\n </div>\n </div>\n );\n })}\n {/* Кнопка добавления нового изображения */}\n {(!isMaxFilesReached || !showFiles) && (\n <div\n {...getRootProps()}\n className={cn(\n `relative flex cursor-pointer flex-col items-center justify-center\n rounded-lg border-2 border-dashed border-gray-300 bg-gray-50\n transition-colors hover:bg-gray-100`,\n isDragActive && \"border-primary bg-primary/5\",\n (disabled || loading) && \"cursor-not-allowed opacity-50\",\n variant === \"list\" ? \"min-h-37.5\" : \"aspect-square\",\n className?.blockAdd,\n )}\n >\n <input {...getInputProps()} />\n\n {loading ? (\n <Icon\n type=\"spinner-gap\"\n className=\"text-sub-label-text h-8 w-8 animate-spin\"\n />\n ) : (\n <div className=\"flex flex-col items-center space-y-2 p-4 text-center\">\n <Icon\n type={icon?.type ?? \"plus\"}\n className={cn(\"text-sub-label-text h-8 w-8\", className?.icon)}\n />\n <Typography\n variant=\"body-md-medium\"\n className={cn(\"text-sub-label-text\", className?.title)}\n >\n {multiple\n ? `${title || \"Добавить\"} (${files.length}/${maxFiles})`\n : `${title || \"Добавить\"}`}\n </Typography>\n {text && (\n <Typography variant=\"body-xxs-medium\" className={cn(\"text-sub-label-text\", className?.text)}>\n {text}\n </Typography>\n )}\n </div>\n )}\n </div>\n )}\n </div>\n\n {/* Информация о количестве */}\n {/* {multiple && images.length > 0 && (\n <p className=\"text-xs text-gray-500\">\n Загружено {images.length} из {maxFiles} изображений\n </p>\n )} */}\n\n {/* Ошибка */}\n {error && (\n <div className=\"rounded-lg bg-red-50 p-3 text-sm text-red-600\">{error}</div>\n )}\n </div>\n );\n};\n\nexport type { PropsFilesUploader, UploadedFileData, FilesUploaderValue };\n"],"names":["FILE_SIZE_UNITS","FILE_SIZE_KB","DEFAULT_MAX_SIZE","DEFAULT_MAX_FILES","DEFAULT_ACCEPT","DEFAULT_TIMEOUT","ACCEPT_MAP","formatFileSize","bytes","i","fileAcceptMap","accepts","acc","t","getFileType","file","ext","FilesUploader","value","onChange","multiple","maxFiles","disabled","className","maxSize","variant","icon","title","text","showFiles","loading","setLoading","useState","error","setError","files","onDrop","useCallback","acceptedFiles","rejectedFiles","errorMessage","newFilesData","getRootProps","getInputProps","isDragActive","useDropzone","removeImage","index","newFiles","_","isMaxFilesReached","gridClasses","cn","jsxs","type","jsx","e","Icon","Typography"],"mappings":";;;;;;;AAuCA,MAAMA,IAAkB,CAAC,KAAK,MAAM,MAAM,MAAM,IAAI,GAC9CC,IAAe,MACfC,IAAmB,IAAID,IAAeA,GACtCE,IAAoB,GACpBC,IAA+B,CAAC,KAAK,GACrCC,IAAkB,KAElBC,IAA2D;AAAA,EAC/D,OAAO,EAAE,WAAW,CAAC,QAAQ,SAAS,QAAQ,OAAO,EAAA;AAAA,EACrD,KAAK,EAAE,mBAAmB,CAAC,MAAM,EAAA;AAAA,EACjC,KAAK;AAAA,IACH,sBAAsB,CAAC,MAAM;AAAA,IAC7B,2EAA2E,CAAC,OAAO;AAAA,EAAA;AAAA,EAErF,OAAO;AAAA,IACL,4BAA4B,CAAC,MAAM;AAAA,IACnC,qEAAqE,CAAC,OAAO;AAAA,EAAA;AAAA,EAE/E,MAAM,EAAE,cAAc,CAAC,MAAM,EAAA;AAAA,EAC7B,KAAK,CAAA;AACP,GAEMC,IAAiB,CAACC,MAAkB;AACxC,MAAIA,MAAU,EAAG,QAAO;AACxB,QAAMC,IAAI,KAAK,MAAM,KAAK,IAAID,CAAK,IAAI,KAAK,IAAIP,CAAY,CAAC;AAC7D,SAAO,IAAIO,IAAQ,KAAK,IAAIP,GAAcQ,CAAC,GAAG,QAAQ,CAAC,CAAC,IAAIT,EAAgBS,CAAC,CAAC;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uploader.tsx"],"sourcesContent":["import { cn } from \"@/lib/utils\";\nimport { useState } from \"react\";\nimport { type FileRejection, useDropzone } from \"react-dropzone\";\nimport { Icon, type IconProps } from \"../ui/icon\";\nimport { Typography } from \"../ui/typography\";\n\ntype Variant = \"grid\" | \"list\" | \"compact\";\ntype AcceptType = \"image\" | \"pdf\" | \"doc\" | \"excel\" | \"text\" | \"all\";\n\nexport type UploadedFileData = {\n url: string;\n name: string;\n size: string;\n addedAt: string;\n status: \"uploaded\" | \"error\";\n error?: string;\n};\n\nexport type FilesUploaderValue = UploadedFileData[] | [];\n\nexport type PropsFilesUploader = {\n value?: FilesUploaderValue;\n onChange?: (value: FilesUploaderValue) => void;\n multiple?: boolean;\n maxFiles?: number;\n disabled?: boolean;\n isErrorText?: boolean;\n className?: {\n container?: string;\n blockAdd?: string;\n title?: string;\n text?: string;\n icon?: string;\n };\n maxSize?: number;\n variant?: Variant;\n accepts?: AcceptType[];\n icon?: IconProps;\n title?: string;\n text?: string;\n showFiles?: boolean;\n};\n\nconst FILE_SIZE_UNITS = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\nconst FILE_SIZE_KB = 1024;\n\nconst DEFAULT_MAX_SIZE = 5 * FILE_SIZE_KB * FILE_SIZE_KB;\nconst DEFAULT_MAX_FILES = 5;\nconst DEFAULT_ACCEPT: AcceptType[] = [\"all\"];\nconst DEFAULT_TIMEOUT = 800;\n\nconst ACCEPT_MAP: Record<AcceptType, Record<string, string[]>> = {\n image: { \"image/*\": [\".jpg\", \".jpeg\", \".png\", \".webp\"] },\n pdf: { \"application/pdf\": [\".pdf\"] },\n doc: {\n \"application/msword\": [\".doc\"],\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\": [\".docx\"],\n },\n excel: {\n \"application/vnd.ms-excel\": [\".xls\"],\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\": [\".xlsx\"],\n },\n text: { \"text/plain\": [\".txt\"] },\n all: {},\n};\n\nconst formatFileSize = (bytes: number) => {\n if (!bytes) return \"0 B\";\n const i = Math.floor(Math.log(bytes) / Math.log(FILE_SIZE_KB));\n return `${(bytes / Math.pow(FILE_SIZE_KB, i)).toFixed(2)} ${FILE_SIZE_UNITS[i]}`;\n};\n\nconst getFileIdentity = (file: Pick<UploadedFileData, \"name\" | \"size\">) =>\n `${file.name}:${file.size}`;\n\nconst fileAcceptMap = (accepts: AcceptType[]) =>\n accepts.reduce((acc, t) => ({ ...acc, ...ACCEPT_MAP[t] }), {});\n\nconst limitFilesForValue = (\n nextFiles: UploadedFileData[],\n maxFiles: number,\n): UploadedFileData[] => {\n const uploadedFiles = nextFiles.filter((file) => file.status === \"uploaded\");\n const errorFiles = nextFiles.filter((file) => file.status === \"error\");\n const availableErrorSlots = Math.max(0, maxFiles - uploadedFiles.length);\n\n return [...uploadedFiles, ...errorFiles.slice(0, availableErrorSlots)];\n};\n\nconst mapFile = (\n file: File,\n status: UploadedFileData[\"status\"],\n error?: string,\n): UploadedFileData => ({\n url: URL.createObjectURL(file),\n name: file.name,\n size: formatFileSize(file.size),\n addedAt: new Date().toISOString(),\n status,\n error,\n});\n\nconst getRejectedError = (code?: string) =>\n code === \"file-too-large\" ? \"Файл слишком большой\" : \"Неподдерживаемый формат\";\n\nconst replaceDuplicateErrors = (\n currentFiles: UploadedFileData[],\n newFiles: UploadedFileData[],\n rejectedFiles: UploadedFileData[],\n) => {\n const rejectedFileIds = new Set(rejectedFiles.map(getFileIdentity));\n const acceptedFileIds = new Set(newFiles.map(getFileIdentity));\n\n return currentFiles.filter((existingFile) => {\n if (existingFile.status !== \"error\") return true;\n const id = getFileIdentity(existingFile);\n return !rejectedFileIds.has(id) && !acceptedFileIds.has(id);\n });\n};\n\nconst getFileType = (file: UploadedFileData) => {\n const ext = file.name.split(\".\").pop()?.toLowerCase();\n\n if (!ext) return \"other\";\n if ([\"jpg\", \"jpeg\", \"png\", \"webp\"].includes(ext)) return \"image\";\n if (ext === \"pdf\") return \"pdf\";\n if ([\"doc\", \"docx\"].includes(ext)) return \"doc\";\n if ([\"xls\", \"xlsx\"].includes(ext)) return \"excel\";\n if (ext === \"txt\") return \"text\";\n\n return \"other\";\n};\n\nexport const FilesUploader = ({\n value = [],\n onChange,\n multiple = false,\n maxFiles = DEFAULT_MAX_FILES,\n disabled = false,\n className,\n maxSize = DEFAULT_MAX_SIZE,\n variant = \"grid\",\n accepts = DEFAULT_ACCEPT,\n icon,\n title,\n text,\n showFiles = true,\n isErrorText = false,\n}: PropsFilesUploader) => {\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const files = value;\n const uploadedCount = files.filter((file) => file.status === \"uploaded\").length;\n\n const onDrop = (acceptedFiles: File[], rejectedFiles: FileRejection[]) => {\n setError(null);\n const remainingUploadSlots = Math.max(0, maxFiles - uploadedCount);\n const acceptedFilesToUpload = acceptedFiles.slice(0, remainingUploadSlots);\n const overflowAcceptedFiles = acceptedFiles.slice(remainingUploadSlots);\n\n const rejectedMapped = [\n ...rejectedFiles.map((rejection) =>\n mapFile(rejection.file, \"error\", getRejectedError(rejection.errors[0]?.code)),\n ),\n ...overflowAcceptedFiles.map((file) =>\n mapFile(file, \"error\", `Максимальное количество файлов: ${maxFiles}`),\n ),\n ];\n\n if (rejectedMapped.length) {\n setError(rejectedMapped[0].error || \"Ошибка загрузки\");\n }\n\n if (!acceptedFilesToUpload.length && !rejectedMapped.length) return;\n\n setLoading(true);\n\n setTimeout(() => {\n const newFiles = acceptedFilesToUpload.map((file) => mapFile(file, \"uploaded\"));\n const nextBaseFiles = replaceDuplicateErrors(files, newFiles, rejectedMapped);\n const nextFiles = multiple\n ? limitFilesForValue([...nextBaseFiles, ...newFiles, ...rejectedMapped], maxFiles)\n : [...newFiles, ...rejectedMapped].slice(0, 1);\n\n onChange?.(nextFiles.length ? nextFiles : []);\n setLoading(false);\n }, DEFAULT_TIMEOUT);\n };\n\n const { getRootProps, getInputProps, isDragActive } = useDropzone({\n onDrop,\n accept: fileAcceptMap(accepts),\n maxSize,\n multiple: multiple && maxFiles > 1,\n disabled: disabled || loading,\n });\n\n const removeFile = (index: number) => () => {\n const updated = files.filter((_, i) => i !== index);\n onChange?.(updated.length ? updated : []);\n };\n\n const uploadedFiles = files\n .map((file, index) => ({ file, index }))\n .filter(({ file }) => file.status === \"uploaded\");\n\n const isMaxFilesReached = uploadedCount >= maxFiles;\n\n const gridClasses = {\n grid: \"grid-cols-2 sm:grid-cols-3 md:grid-cols-4\",\n list: \"grid-cols-1\",\n compact: \"grid-cols-2 sm:grid-cols-3\",\n };\n\n return (\n <div className={cn(\"w-full space-y-4\", className?.container)}>\n <div\n className={cn(\n \"grid h-full w-full gap-4\",\n variant === \"list\" ? \"grid-cols-1\" : gridClasses[variant],\n )}\n >\n {showFiles &&\n uploadedFiles.map(({ file, index }) => {\n const type = getFileType(file);\n\n return (\n <div\n key={`${file.url}-${file.addedAt}-${index}`}\n className=\"group bg-primary-bg relative aspect-square h-full w-full\n overflow-hidden rounded-lg\"\n >\n {type === \"image\" ? (\n <img\n src={file.url}\n className=\"h-full w-full object-cover\"\n />\n ) : (\n <div\n className=\"flex h-full w-full items-center justify-center bg-gray-100\n text-sm font-semibold\"\n >\n {file.name.split(\".\").pop()?.toUpperCase()}\n </div>\n )}\n\n <div\n className=\"bg-primary-inverse-bg/50 text-primary-bg absolute inset-0\n flex items-center justify-center opacity-0 transition-opacity\n hover:opacity-100\"\n >\n <Icon\n onClick={removeFile(index)}\n type={\"x\"}\n />\n </div>\n </div>\n );\n })}\n\n {!isMaxFilesReached && (\n <div\n {...getRootProps()}\n className={cn(\n `relative flex cursor-pointer flex-col items-center justify-center\n rounded-lg border-2 border-dashed border-gray-300 bg-gray-50\n transition-colors hover:bg-gray-100`,\n isDragActive && \"border-primary bg-primary/5\",\n (disabled || loading) && \"cursor-not-allowed opacity-50\",\n variant === \"list\" ? \"min-h-37.5\" : \"aspect-square\",\n className?.blockAdd,\n )}\n >\n <input {...getInputProps()} />\n\n {loading ? (\n <Icon\n type=\"spinner-gap\"\n className=\"text-sub-label-text h-8 w-8 animate-spin\"\n />\n ) : (\n <div className=\"flex flex-col items-center space-y-2 p-4 text-center\">\n <Icon\n type={icon?.type ?? \"plus\"}\n className={cn(\"text-sub-label-text h-8 w-8\", className?.icon)}\n />\n\n <Typography className={cn(\"text-sub-label-text\", className?.title)}>\n {multiple\n ? `${title || \"Добавить\"} (${uploadedCount}/${maxFiles})`\n : title || \"Добавить\"}\n </Typography>\n\n {text && (\n <Typography className={cn(\"text-sub-label-text\", className?.text)}>\n {text}\n </Typography>\n )}\n </div>\n )}\n </div>\n )}\n </div>\n\n {!isErrorText && error && (\n <div className=\"rounded-lg bg-red-50 p-3 text-sm text-red-600\">{error}</div>\n )}\n </div>\n );\n};\n"],"names":["FILE_SIZE_UNITS","FILE_SIZE_KB","DEFAULT_MAX_SIZE","DEFAULT_MAX_FILES","DEFAULT_ACCEPT","DEFAULT_TIMEOUT","ACCEPT_MAP","formatFileSize","bytes","i","getFileIdentity","file","fileAcceptMap","accepts","acc","t","limitFilesForValue","nextFiles","maxFiles","uploadedFiles","errorFiles","availableErrorSlots","mapFile","status","error","getRejectedError","code","replaceDuplicateErrors","currentFiles","newFiles","rejectedFiles","rejectedFileIds","acceptedFileIds","existingFile","id","getFileType","ext","FilesUploader","value","onChange","multiple","disabled","className","maxSize","variant","icon","title","text","showFiles","isErrorText","loading","setLoading","useState","setError","files","uploadedCount","onDrop","acceptedFiles","remainingUploadSlots","acceptedFilesToUpload","overflowAcceptedFiles","rejectedMapped","rejection","nextBaseFiles","getRootProps","getInputProps","isDragActive","useDropzone","removeFile","index","updated","_","isMaxFilesReached","gridClasses","cn","jsxs","type","jsx","Icon","Typography"],"mappings":";;;;;;;AA2CA,MAAMA,IAAkB,CAAC,KAAK,MAAM,MAAM,MAAM,IAAI,GAC9CC,IAAe,MAEfC,IAAmB,IAAID,IAAeA,GACtCE,IAAoB,GACpBC,IAA+B,CAAC,KAAK,GACrCC,IAAkB,KAElBC,IAA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IAAIrC,CAAQ,MACpD4B,KAAS,YACf;AAAA,kBAECC,uBACEgC,GAAA,EAAW,WAAWL,EAAG,uBAAuBhC,GAAW,IAAI,GAC7D,UAAAK,EAAA,CACH;AAAA,gBAAA,EAAA,CAEJ;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,IAIH,CAACE,KAAezB,uBACd,OAAA,EAAI,WAAU,iDAAiD,UAAAA,EAAA,CAAM;AAAA,EAAA,GAE1E;AAEJ;"}
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./brd-ui-kit.css');const r=require("react/jsx-runtime");;/* empty css */const g=require("./lib-utils.cjs");require("class-variance-authority");const c=require("react");require("./components-ui-badge-badge.styles.cjs");const y=require("./components-ui-button-button.cjs");require("./components-ui-button-button.styles.cjs");require("./components-ui-card-card.cjs");require("./components-ui-checkbox-checkbox.cjs");const s=require("./components-ui-icon-icon.cjs");require("./components-ui-combobox-combobox.cjs");require("./components-ui-dialog-dialog.cjs");require("./components-ui-label-label.cjs");require("./components-ui-separator-separator.cjs");require("./components-ui-field-field.styles.cjs");require("./components-ui-input-input.styles.cjs");require("./components-ui-textarea-textarea.cjs");require("./components-ui-input-group-input-group.styles.cjs");require("./components-ui-navigation-item-navigation-item.styles.cjs");require("./components-ui-navigation-menu-navigation-menu.styles.cjs");require("./components-ui-pagination-pagination.cjs");require("./components-ui-progress-progress.cjs");require("./components-ui-radio-group-radio-group.cjs");require("./components-ui-switch-switch.cjs");require("./components-ui-table-table.cjs");require("./components-ui-tabs-tabs.cjs");require("./components-ui-tooltip-tooltip.cjs");require("./components-ui-typography-typography.styles.cjs");const v=require("./hooks-usePopupControls.cjs");require("./components-app-pagination-app-pagination.styles.cjs");require("./components-app-sidebar-app-sidebar.styles.cjs");const _=require("./components-input-field-input-field.cjs");require("./components-select-field-select-field.cjs");require("./lodash-kqhtUJfz.cjs");require("./chart-CgVfpT_X.cjs");require("./index-DGxwh2Ms.cjs");require("./index-fTTv8YY8.cjs");const j=require("./components-input-phone-input-phone.cjs");require("./components-ui-calendar-calendar.styles.cjs");const w=[{label:"Мобильный",icon:"phone"},{label:"Telegram",icon:"telegram-logo"},{label:"WhatsApp",icon:"whats-app-logo-filled"},{label:"Max",icon:"max-logo"},{label:"E-mail",icon:"envelope-simple"}],q=n=>{switch(n){case"max-logo":return{bgColor:"bg-[linear-gradient(135deg,#9933DD_0%,#2831B9_50%,#44CCFF_100%)]"};case"telegram-logo":return{bgColor:"bg-[#289AD2]"};case"whats-app-logo-filled":return{bgColor:"bg-[#00C202]",textColor:"text-[#00C202]"};default:return{}}},a=n=>({wrapper:g.cn(`flex h-5.5 w-5.5 shrink-0 items-center justify-center rounded-sm
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./brd-ui-kit.css');const r=require("react/jsx-runtime");;/* empty css */const g=require("./lib-utils.cjs");require("class-variance-authority");const c=require("react");require("./components-ui-badge-badge.styles.cjs");const y=require("./components-ui-button-button.cjs");require("./components-ui-button-button.styles.cjs");require("./components-ui-card-card.cjs");require("./components-ui-checkbox-checkbox.cjs");const s=require("./components-ui-icon-icon.cjs");require("./calendar-DReGV_22.cjs");require("./components-ui-combobox-combobox.cjs");require("./components-ui-dialog-dialog.cjs");require("./components-ui-label-label.cjs");require("./components-ui-separator-separator.cjs");require("./components-ui-field-field.styles.cjs");require("./components-ui-input-input.styles.cjs");require("./components-ui-textarea-textarea.cjs");require("./components-ui-input-group-input-group.styles.cjs");require("./components-ui-navigation-item-navigation-item.styles.cjs");require("./components-ui-navigation-menu-navigation-menu.styles.cjs");require("./components-ui-pagination-pagination.cjs");require("./components-ui-progress-progress.cjs");require("./components-ui-radio-group-radio-group.cjs");require("./components-ui-switch-switch.cjs");require("./components-ui-toggle-toggle.styles.cjs");require("./components-ui-toggle-group-toggle-group.cjs");require("./components-ui-table-table.cjs");require("./components-ui-tabs-tabs.cjs");require("./components-ui-tooltip-tooltip.cjs");require("./components-ui-typography-typography.styles.cjs");const v=require("./hooks-usePopupControls.cjs");require("./components-app-pagination-app-pagination.styles.cjs");require("./components-app-sidebar-app-sidebar.styles.cjs");require("./components-data-table-data-table.styles.cjs");require("./components-ui-dropdown-menu-dropdown-menu.styles.cjs");const _=require("./components-input-field-input-field.cjs");require("./components-select-field-select-field.cjs");require("./lodash-kqhtUJfz.cjs");require("./chart-C69jBlXa.cjs");require("./index-DGxwh2Ms.cjs");require("./index-fTTv8YY8.cjs");const j=require("./components-input-phone-input-phone.cjs"),w=[{label:"Мобильный",icon:"phone"},{label:"Telegram",icon:"telegram-logo"},{label:"WhatsApp",icon:"whats-app-logo-filled"},{label:"Max",icon:"max-logo"},{label:"E-mail",icon:"envelope-simple"}],q=n=>{switch(n){case"max-logo":return{bgColor:"bg-[linear-gradient(135deg,#9933DD_0%,#2831B9_50%,#44CCFF_100%)]"};case"telegram-logo":return{bgColor:"bg-[#289AD2]"};case"whats-app-logo-filled":return{bgColor:"bg-[#00C202]",textColor:"text-[#00C202]"};default:return{}}},a=n=>({wrapper:g.cn(`flex h-5.5 w-5.5 shrink-0 items-center justify-center rounded-sm
2
2
  ${q(n).bgColor??"bg-primary-inverse-hover-bg"}
3
3
  ${q(n).textColor??"text-primary-inverse-text"}`),icon:"size-5 shrink-0"}),P=n=>{const{inputProps:h,inputPhoneProps:x,onTypeChange:b,...p}=n,[o,C]=c.useState("phone"),{isOpened:t,openPopup:m,closePopup:u}=v.usePopupControls(),l=c.useRef(null);c.useEffect(()=>{const e=i=>{l.current&&!l.current.contains(i.target)&&u()};return t&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[t,u]);const d=e=>{switch(e){case"phone":return"+7 (999) 999-99-99";case"telegram-logo":return"@username";case"whats-app-logo-filled":return"+7 (999) 999-99-99";case"max-logo":return"ID пользователя Max";case"envelope-simple":return"example@mail.com";default:return"Введите значение"}},f=e=>()=>{C(e),b?.(e),u()};return r.jsxs("div",{className:g.cn("relative",n.classes?.container),children:[["telegram-logo","max-logo","envelope-simple"].includes(o)?r.jsx(_.InputField,{...h,...p,date:[{id:"0",position:"inline-start",component:r.jsx(s.Icon,{type:o,size:"medium",classes:a(o)})},{id:"1",position:"inline-end",component:r.jsx(s.Icon,{type:t?"caret-up":"caret-down",size:"medium",className:"cursor-pointer",onClick:m})}],placeholder:d(o)}):r.jsx(j.InputPhone,{...x,...p,date:[{id:"0",position:"inline-start",component:r.jsx(s.Icon,{type:o,size:"medium",classes:a(o)})},{id:"1",position:"inline-end",component:r.jsx(s.Icon,{type:t?"caret-up":"caret-down",size:"medium",className:"cursor-pointer",onClick:m})}],placeholder:d(o)}),t&&r.jsx("div",{className:`border-inp-hover-border bg-primary-bg absolute my-2 flex w-full
4
4
  flex-col rounded-xl border`,ref:l,children:w.map(({label:e,icon:i})=>r.jsxs(y.Button,{variant:"ghost",className:"flex w-full justify-start",type:"button",onClick:f(i),children:[r.jsx(s.Icon,{type:i,size:"medium",className:"text-primary-inverse-text",classes:a(i)}),e]},e))})]})};exports.InputContact=P;
@@ -1 +1 @@
1
- {"version":3,"file":"components-input-contact-input-contact.cjs","sources":["../src/constants/contact-input.ts","../src/components/input-contact/input-contact.tsx"],"sourcesContent":["import type { TOption } from \"@/components/input-contact/input-contact\";\n\nexport const OPTIONS: TOption[] = [\n {\n label: \"Мобильный\",\n icon: \"phone\",\n },\n {\n label: \"Telegram\",\n icon: \"telegram-logo\",\n },\n {\n label: \"WhatsApp\",\n icon: \"whats-app-logo-filled\",\n },\n {\n label: \"Max\",\n icon: \"max-logo\",\n },\n {\n label: \"E-mail\",\n icon: \"envelope-simple\",\n },\n];\n","import { OPTIONS } from \"@/constants/contact-input\";\nimport {\n Button,\n Icon,\n InputField,\n InputPhone,\n cn,\n usePopupControls,\n type InputPhoneProps,\n} from \"@/index\";\nimport { useEffect, useRef, useState } from \"react\";\n\nexport type TOption = {\n label: string;\n icon: TypesChange;\n};\n\ntype TypesChange =\n | \"phone\"\n | \"telegram-logo\"\n | \"whats-app-logo-filled\"\n | \"max-logo\"\n | \"envelope-simple\";\n\ntype Props = {\n isValid?: boolean;\n label?: string;\n description?: string;\n classes?: {\n fieldset?: string;\n fieldgroup?: string;\n field?: string;\n container?: string;\n };\n value?: string;\n name?: string;\n onTypeChange?: (type: TypesChange) => void;\n inputProps: React.ComponentPropsWithRef<\"input\">;\n inputPhoneProps: InputPhoneProps;\n};\n\n// TODO: заменить цвета\nconst iconStyles = (icon: TypesChange) => {\n switch (icon) {\n case \"max-logo\":\n return {\n bgColor: \"bg-[linear-gradient(135deg,#9933DD_0%,#2831B9_50%,#44CCFF_100%)]\",\n };\n\n case \"telegram-logo\":\n return {\n bgColor: \"bg-[#289AD2]\",\n };\n\n case \"whats-app-logo-filled\":\n return {\n bgColor: \"bg-[#00C202]\",\n textColor: \"text-[#00C202]\",\n };\n\n default:\n return {};\n }\n};\n\nconst getContactIconClasses = (icon: TypesChange) => ({\n wrapper: cn(\n `flex h-5.5 w-5.5 shrink-0 items-center justify-center rounded-sm\n ${iconStyles(icon).bgColor ?? \"bg-primary-inverse-hover-bg\"}\n ${iconStyles(icon).textColor ?? \"text-primary-inverse-text\"}`,\n ),\n icon: \"size-5 shrink-0\",\n});\n\nexport const InputContact = (props: Props) => {\n const { inputProps, inputPhoneProps, onTypeChange, ...rest } = props;\n\n const [type, setType] = useState<TypesChange>(\"phone\");\n const { isOpened, openPopup, closePopup } = usePopupControls();\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (wrapperRef.current && !wrapperRef.current.contains(event.target as Node)) {\n closePopup();\n }\n };\n\n if (isOpened) {\n document.addEventListener(\"mousedown\", handleClickOutside);\n }\n\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n }, [isOpened, closePopup]);\n\n const getPlaceholder = (type: TypesChange): string => {\n switch (type) {\n case \"phone\":\n return \"+7 (999) 999-99-99\";\n case \"telegram-logo\":\n return \"@username\";\n case \"whats-app-logo-filled\":\n return \"+7 (999) 999-99-99\";\n case \"max-logo\":\n return \"ID пользователя Max\";\n case \"envelope-simple\":\n return \"example@mail.com\";\n default:\n return \"Введите значение\";\n }\n };\n\n const handleTypeChange = (type: TypesChange) => {\n return () => {\n setType(type);\n onTypeChange?.(type);\n closePopup();\n };\n };\n\n return (\n <div className={cn(\"relative\", props.classes?.container)}>\n {[\"telegram-logo\", \"max-logo\", \"envelope-simple\"].includes(type) ? (\n <InputField\n {...inputProps}\n {...rest}\n date={[\n {\n id: \"0\",\n position: \"inline-start\",\n component: (\n <Icon\n type={type}\n size=\"medium\"\n classes={getContactIconClasses(type)}\n />\n ),\n },\n {\n id: \"1\",\n position: \"inline-end\",\n component: (\n <Icon\n type={isOpened ? \"caret-up\" : \"caret-down\"}\n size=\"medium\"\n className=\"cursor-pointer\"\n onClick={openPopup}\n />\n ),\n },\n ]}\n placeholder={getPlaceholder(type)}\n />\n ) : (\n <InputPhone\n {...inputPhoneProps}\n {...rest}\n date={[\n {\n id: \"0\",\n position: \"inline-start\",\n component: (\n <Icon\n type={type}\n size=\"medium\"\n classes={getContactIconClasses(type)}\n />\n ),\n },\n {\n id: \"1\",\n position: \"inline-end\",\n component: (\n <Icon\n type={isOpened ? \"caret-up\" : \"caret-down\"}\n size=\"medium\"\n className=\"cursor-pointer\"\n onClick={openPopup}\n />\n ),\n },\n ]}\n placeholder={getPlaceholder(type)}\n />\n )}\n\n {isOpened && (\n <div\n className=\"border-inp-hover-border bg-primary-bg absolute my-2 flex w-full\n flex-col rounded-xl border\"\n ref={wrapperRef}\n >\n {OPTIONS.map(({ label, icon }) => {\n return (\n <Button\n key={label}\n variant=\"ghost\"\n className=\"flex w-full justify-start\"\n type=\"button\"\n onClick={handleTypeChange(icon)}\n >\n <Icon\n type={icon}\n size=\"medium\"\n className=\"text-primary-inverse-text\"\n classes={getContactIconClasses(icon)}\n />\n\n {label}\n </Button>\n );\n })}\n </div>\n )}\n </div>\n );\n};\n\nexport type { Props as InputContactProps, TypesChange };\n"],"names":["OPTIONS","iconStyles","icon","getContactIconClasses","cn","InputContact","props","inputProps","inputPhoneProps","onTypeChange","rest","type","setType","useState","isOpened","openPopup","closePopup","usePopupControls","wrapperRef","useRef","useEffect","handleClickOutside","event","getPlaceholder","handleTypeChange","jsxs","jsx","InputField","Icon","InputPhone","label","Button"],"mappings":"o9DAEO,MAAMA,EAAqB,CAChC,CACE,MAAO,YACP,KAAM,OAAA,EAER,CACE,MAAO,WACP,KAAM,eAAA,EAER,CACE,MAAO,WACP,KAAM,uBAAA,EAER,CACE,MAAO,MACP,KAAM,UAAA,EAER,CACE,MAAO,SACP,KAAM,iBAAA,CAEV,ECmBMC,EAAcC,GAAsB,CACxC,OAAQA,EAAA,CACN,IAAK,WACH,MAAO,CACL,QAAS,kEAAA,EAGb,IAAK,gBACH,MAAO,CACL,QAAS,cAAA,EAGb,IAAK,wBACH,MAAO,CACL,QAAS,eACT,UAAW,gBAAA,EAGf,QACE,MAAO,CAAA,CAAC,CAEd,EAEMC,EAAyBD,IAAuB,CACpD,QAASE,EAAAA,GACP;AAAA,MACEH,EAAWC,CAAI,EAAE,SAAW,6BAA6B;AAAA,MACzDD,EAAWC,CAAI,EAAE,WAAa,2BAA2B,EAAA,EAE7D,KAAM,iBACR,GAEaG,EAAgBC,GAAiB,CAC5C,KAAM,CAAE,WAAAC,EAAY,gBAAAC,EAAiB,aAAAC,EAAc,GAAGC,GAASJ,EAEzD,CAACK,EAAMC,CAAO,EAAIC,EAAAA,SAAsB,OAAO,EAC/C,CAAE,SAAAC,EAAU,UAAAC,EAAW,WAAAC,CAAA,EAAeC,EAAAA,iBAAA,EACtCC,EAAaC,EAAAA,OAAuB,IAAI,EAE9CC,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAsBC,GAAsB,CAC5CJ,EAAW,SAAW,CAACA,EAAW,QAAQ,SAASI,EAAM,MAAc,GACzEN,EAAA,CAEJ,EAEA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Md,EAAW,WAAa,aAC9B,KAAK,SACL,UAAU,iBACV,QAASC,CAAA,CAAA,CACX,CAEJ,EAEF,YAAaQ,EAAeZ,CAAI,CAAA,CAAA,EAInCG,GACCY,EAAAA,IAAC,MAAA,CACC,UAAU;AAAA,wCAEV,IAAKR,EAEJ,WAAQ,IAAI,CAAC,CAAE,MAAAY,EAAO,KAAA5B,KAEnBuB,EAAAA,KAACM,EAAAA,OAAA,CAEC,QAAQ,QACR,UAAU,4BACV,KAAK,SACL,QAASP,EAAiBtB,CAAI,EAE9B,SAAA,CAAAwB,EAAAA,IAACE,EAAAA,KAAA,CACC,KAAM1B,EACN,KAAK,SACL,UAAU,4BACV,QAASC,EAAsBD,CAAI,CAAA,CAAA,EAGpC4B,CAAA,CAAA,EAbIA,CAAA,CAgBV,CAAA,CAAA,CACH,EAEJ,CAEJ"}
1
+ {"version":3,"file":"components-input-contact-input-contact.cjs","sources":["../src/constants/contact-input.ts","../src/components/input-contact/input-contact.tsx"],"sourcesContent":["import type { TOption } from \"@/components/input-contact/input-contact\";\n\nexport const OPTIONS: TOption[] = [\n {\n label: \"Мобильный\",\n icon: \"phone\",\n },\n {\n label: \"Telegram\",\n icon: \"telegram-logo\",\n },\n {\n label: \"WhatsApp\",\n icon: \"whats-app-logo-filled\",\n },\n {\n label: \"Max\",\n icon: \"max-logo\",\n },\n {\n label: \"E-mail\",\n icon: \"envelope-simple\",\n },\n];\n","import { OPTIONS } from \"@/constants/contact-input\";\nimport {\n Button,\n Icon,\n InputField,\n InputPhone,\n cn,\n usePopupControls,\n type InputPhoneProps,\n} from \"@/index\";\nimport { useEffect, useRef, useState } from \"react\";\n\nexport type TOption = {\n label: string;\n icon: TypesChange;\n};\n\ntype TypesChange =\n | \"phone\"\n | \"telegram-logo\"\n | \"whats-app-logo-filled\"\n | \"max-logo\"\n | \"envelope-simple\";\n\ntype Props = {\n isValid?: boolean;\n label?: string;\n description?: string;\n classes?: {\n fieldset?: string;\n fieldgroup?: string;\n field?: string;\n container?: string;\n };\n value?: string;\n name?: string;\n onTypeChange?: (type: TypesChange) => void;\n inputProps: React.ComponentPropsWithRef<\"input\">;\n inputPhoneProps: InputPhoneProps;\n};\n\n// TODO: заменить цвета\nconst iconStyles = (icon: TypesChange) => {\n switch (icon) {\n case \"max-logo\":\n return {\n bgColor: \"bg-[linear-gradient(135deg,#9933DD_0%,#2831B9_50%,#44CCFF_100%)]\",\n };\n\n case \"telegram-logo\":\n return {\n bgColor: \"bg-[#289AD2]\",\n };\n\n case \"whats-app-logo-filled\":\n return {\n bgColor: \"bg-[#00C202]\",\n textColor: \"text-[#00C202]\",\n };\n\n default:\n return {};\n }\n};\n\nconst getContactIconClasses = (icon: TypesChange) => ({\n wrapper: cn(\n `flex h-5.5 w-5.5 shrink-0 items-center justify-center rounded-sm\n ${iconStyles(icon).bgColor ?? \"bg-primary-inverse-hover-bg\"}\n ${iconStyles(icon).textColor ?? \"text-primary-inverse-text\"}`,\n ),\n icon: \"size-5 shrink-0\",\n});\n\nexport const InputContact = (props: Props) => {\n const { inputProps, inputPhoneProps, onTypeChange, ...rest } = props;\n\n const [type, setType] = useState<TypesChange>(\"phone\");\n const { isOpened, openPopup, closePopup } = usePopupControls();\n const wrapperRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (wrapperRef.current && !wrapperRef.current.contains(event.target as Node)) {\n closePopup();\n }\n };\n\n if (isOpened) {\n document.addEventListener(\"mousedown\", handleClickOutside);\n }\n\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n }, [isOpened, closePopup]);\n\n const getPlaceholder = (type: TypesChange): string => {\n switch (type) {\n case \"phone\":\n return \"+7 (999) 999-99-99\";\n case \"telegram-logo\":\n return \"@username\";\n case \"whats-app-logo-filled\":\n return \"+7 (999) 999-99-99\";\n case \"max-logo\":\n return \"ID пользователя Max\";\n case \"envelope-simple\":\n return \"example@mail.com\";\n default:\n return \"Введите значение\";\n }\n };\n\n const handleTypeChange = (type: TypesChange) => {\n return () => {\n setType(type);\n onTypeChange?.(type);\n closePopup();\n };\n };\n\n return (\n <div className={cn(\"relative\", props.classes?.container)}>\n {[\"telegram-logo\", \"max-logo\", \"envelope-simple\"].includes(type) ? (\n <InputField\n {...inputProps}\n {...rest}\n date={[\n {\n id: \"0\",\n position: \"inline-start\",\n component: (\n <Icon\n type={type}\n size=\"medium\"\n classes={getContactIconClasses(type)}\n />\n ),\n },\n {\n id: \"1\",\n position: \"inline-end\",\n component: (\n <Icon\n type={isOpened ? \"caret-up\" : \"caret-down\"}\n size=\"medium\"\n className=\"cursor-pointer\"\n onClick={openPopup}\n />\n ),\n },\n ]}\n placeholder={getPlaceholder(type)}\n />\n ) : (\n <InputPhone\n {...inputPhoneProps}\n {...rest}\n date={[\n {\n id: \"0\",\n position: \"inline-start\",\n component: (\n <Icon\n type={type}\n size=\"medium\"\n classes={getContactIconClasses(type)}\n />\n ),\n },\n {\n id: \"1\",\n position: \"inline-end\",\n component: (\n <Icon\n type={isOpened ? \"caret-up\" : \"caret-down\"}\n size=\"medium\"\n className=\"cursor-pointer\"\n onClick={openPopup}\n />\n ),\n },\n ]}\n placeholder={getPlaceholder(type)}\n />\n )}\n\n {isOpened && (\n <div\n className=\"border-inp-hover-border bg-primary-bg absolute my-2 flex w-full\n flex-col rounded-xl border\"\n ref={wrapperRef}\n >\n {OPTIONS.map(({ label, icon }) => {\n return (\n <Button\n key={label}\n variant=\"ghost\"\n className=\"flex w-full justify-start\"\n type=\"button\"\n onClick={handleTypeChange(icon)}\n >\n <Icon\n type={icon}\n size=\"medium\"\n className=\"text-primary-inverse-text\"\n classes={getContactIconClasses(icon)}\n />\n\n {label}\n </Button>\n );\n })}\n </div>\n )}\n </div>\n );\n};\n\nexport type { Props as InputContactProps, TypesChange };\n"],"names":["OPTIONS","iconStyles","icon","getContactIconClasses","cn","InputContact","props","inputProps","inputPhoneProps","onTypeChange","rest","type","setType","useState","isOpened","openPopup","closePopup","usePopupControls","wrapperRef","useRef","useEffect","handleClickOutside","event","getPlaceholder","handleTypeChange","jsxs","jsx","InputField","Icon","InputPhone","label","Button"],"mappings":"uqEAEaA,EAAqB,CAChC,CACE,MAAO,YACP,KAAM,OAAA,EAER,CACE,MAAO,WACP,KAAM,eAAA,EAER,CACE,MAAO,WACP,KAAM,uBAAA,EAER,CACE,MAAO,MACP,KAAM,UAAA,EAER,CACE,MAAO,SACP,KAAM,iBAAA,CAEV,ECmBMC,EAAcC,GAAsB,CACxC,OAAQA,EAAA,CACN,IAAK,WACH,MAAO,CACL,QAAS,kEAAA,EAGb,IAAK,gBACH,MAAO,CACL,QAAS,cAAA,EAGb,IAAK,wBACH,MAAO,CACL,QAAS,eACT,UAAW,gBAAA,EAGf,QACE,MAAO,CAAA,CAAC,CAEd,EAEMC,EAAyBD,IAAuB,CACpD,QAASE,EAAAA,GACP;AAAA,MACEH,EAAWC,CAAI,EAAE,SAAW,6BAA6B;AAAA,MACzDD,EAAWC,CAAI,EAAE,WAAa,2BAA2B,EAAA,EAE7D,KAAM,iBACR,GAEaG,EAAgBC,GAAiB,CAC5C,KAAM,CAAE,WAAAC,EAAY,gBAAAC,EAAiB,aAAAC,EAAc,GAAGC,GAASJ,EAEzD,CAACK,EAAMC,CAAO,EAAIC,EAAAA,SAAsB,OAAO,EAC/C,CAAE,SAAAC,EAAU,UAAAC,EAAW,WAAAC,CAAA,EAAeC,EAAAA,iBAAA,EACtCC,EAAaC,EAAAA,OAAuB,IAAI,EAE9CC,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAsBC,GAAsB,CAC5CJ,EAAW,SAAW,CAACA,EAAW,QAAQ,SAASI,EAAM,MAAc,GACzEN,EAAA,CAEJ,EAEA,OAAIF,GACF,SAAS,iBAAiB,YAAaO,CAAkB,EAGpD,IAAM,CACX,SAAS,oBAAoB,YAAaA,CAAkB,CAC9D,CACF,EAAG,CAACP,EAAUE,CAAU,CAAC,EAEzB,MAAMO,EAAkBZ,GAA8B,CACpD,O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