brd-ui-kit 0.1.71 → 0.1.73

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 (157) hide show
  1. package/dist/brd-ui-kit.css +1 -1
  2. package/dist/components/basic-table/basic-table.d.ts +3 -1
  3. package/dist/components/files-uploader/files-uploader.d.ts +8 -6
  4. package/dist/components/input-contact/input-contact.d.ts +2 -2
  5. package/dist/components/ui/calendar/calendar.d.ts +19 -0
  6. package/dist/components/ui/calendar/calendar.styles.d.ts +4 -0
  7. package/dist/components/ui/calendar/index.d.ts +2 -0
  8. package/dist/components/ui/calendar.d.ts +2 -0
  9. package/dist/components/ui/icon/icon-presets.d.ts +35 -0
  10. package/dist/components/ui/icon/icon.d.ts +11 -7
  11. package/dist/components/ui/icon/index.d.ts +3 -1
  12. package/dist/components/ui/table/table.d.ts +2 -1
  13. package/dist/components/ui/textarea/textarea.d.ts +2 -2
  14. package/dist/components/ui/toggle/index.d.ts +3 -0
  15. package/dist/components/ui/toggle/toggle.d.ts +5 -0
  16. package/dist/components/ui/toggle/toggle.styles.d.ts +9 -0
  17. package/dist/components/ui/toggle-group/index.d.ts +1 -0
  18. package/dist/components/ui/toggle-group/toggle-group.d.ts +12 -0
  19. package/dist/components/ui/toggle-group/toggle-group.styles.d.ts +8 -0
  20. package/dist/components/ui/toggle-group.d.ts +2 -0
  21. package/dist/components/ui/toggle.d.ts +2 -0
  22. package/dist/components-app-pagination-app-pagination.cjs +1 -1
  23. package/dist/components-app-pagination-app-pagination.cjs.map +1 -1
  24. package/dist/components-app-pagination-app-pagination.js +35 -35
  25. package/dist/components-app-pagination-app-pagination.js.map +1 -1
  26. package/dist/components-app-sidebar-app-sidebar.cjs +1 -1
  27. package/dist/components-app-sidebar-app-sidebar.cjs.map +1 -1
  28. package/dist/components-app-sidebar-app-sidebar.js +16 -16
  29. package/dist/components-app-sidebar-app-sidebar.js.map +1 -1
  30. package/dist/components-avatar-uploader-avatar-uploader.cjs +1 -1
  31. package/dist/components-avatar-uploader-avatar-uploader.cjs.map +1 -1
  32. package/dist/components-avatar-uploader-avatar-uploader.js +5 -4
  33. package/dist/components-avatar-uploader-avatar-uploader.js.map +1 -1
  34. package/dist/components-basic-avatar-basic-avatar.cjs +2 -2
  35. package/dist/components-basic-avatar-basic-avatar.cjs.map +1 -1
  36. package/dist/components-basic-avatar-basic-avatar.js +16 -14
  37. package/dist/components-basic-avatar-basic-avatar.js.map +1 -1
  38. package/dist/components-basic-table-basic-table.cjs +2 -2
  39. package/dist/components-basic-table-basic-table.cjs.map +1 -1
  40. package/dist/components-basic-table-basic-table.js +259 -255
  41. package/dist/components-basic-table-basic-table.js.map +1 -1
  42. package/dist/components-files-uploader-files-uploader.cjs +6 -6
  43. package/dist/components-files-uploader-files-uploader.cjs.map +1 -1
  44. package/dist/components-files-uploader-files-uploader.js +111 -112
  45. package/dist/components-files-uploader-files-uploader.js.map +1 -1
  46. package/dist/components-input-contact-input-contact.cjs +4 -8
  47. package/dist/components-input-contact-input-contact.cjs.map +1 -1
  48. package/dist/components-input-contact-input-contact.js +95 -110
  49. package/dist/components-input-contact-input-contact.js.map +1 -1
  50. package/dist/components-input-password-input-password.cjs +1 -1
  51. package/dist/components-input-password-input-password.cjs.map +1 -1
  52. package/dist/components-input-password-input-password.js +6 -4
  53. package/dist/components-input-password-input-password.js.map +1 -1
  54. package/dist/components-ui-button-button.styles.cjs +4 -4
  55. package/dist/components-ui-button-button.styles.cjs.map +1 -1
  56. package/dist/components-ui-button-button.styles.js +5 -5
  57. package/dist/components-ui-button-button.styles.js.map +1 -1
  58. package/dist/components-ui-calendar-calendar.cjs +13 -0
  59. package/dist/components-ui-calendar-calendar.cjs.map +1 -0
  60. package/dist/components-ui-calendar-calendar.js +3761 -0
  61. package/dist/components-ui-calendar-calendar.js.map +1 -0
  62. package/dist/components-ui-calendar-calendar.styles.cjs +14 -0
  63. package/dist/components-ui-calendar-calendar.styles.cjs.map +1 -0
  64. package/dist/components-ui-calendar-calendar.styles.js +34 -0
  65. package/dist/components-ui-calendar-calendar.styles.js.map +1 -0
  66. package/dist/components-ui-calendar.cjs +2 -0
  67. package/dist/components-ui-calendar.cjs.map +1 -0
  68. package/dist/components-ui-calendar.js +6 -0
  69. package/dist/components-ui-calendar.js.map +1 -0
  70. package/dist/components-ui-checkbox-checkbox.cjs +1 -1
  71. package/dist/components-ui-checkbox-checkbox.cjs.map +1 -1
  72. package/dist/components-ui-checkbox-checkbox.js +12 -11
  73. package/dist/components-ui-checkbox-checkbox.js.map +1 -1
  74. package/dist/components-ui-combobox-combobox.cjs +4 -4
  75. package/dist/components-ui-combobox-combobox.cjs.map +1 -1
  76. package/dist/components-ui-combobox-combobox.js +4 -4
  77. package/dist/components-ui-combobox-combobox.js.map +1 -1
  78. package/dist/components-ui-dialog-dialog.cjs +1 -1
  79. package/dist/components-ui-dialog-dialog.cjs.map +1 -1
  80. package/dist/components-ui-dialog-dialog.js +4 -10
  81. package/dist/components-ui-dialog-dialog.js.map +1 -1
  82. package/dist/components-ui-field-field.js +4 -4
  83. package/dist/components-ui-icon-icon-presets.cjs +2 -0
  84. package/dist/components-ui-icon-icon-presets.cjs.map +1 -0
  85. package/dist/components-ui-icon-icon-presets.js +14 -0
  86. package/dist/components-ui-icon-icon-presets.js.map +1 -0
  87. package/dist/components-ui-icon-icon.cjs +1 -1
  88. package/dist/components-ui-icon-icon.cjs.map +1 -1
  89. package/dist/components-ui-icon-icon.js +62714 -34
  90. package/dist/components-ui-icon-icon.js.map +1 -1
  91. package/dist/components-ui-icon.cjs +1 -1
  92. package/dist/components-ui-icon.js +4 -2
  93. package/dist/components-ui-icon.js.map +1 -1
  94. package/dist/components-ui-pagination-pagination.cjs +1 -1
  95. package/dist/components-ui-pagination-pagination.cjs.map +1 -1
  96. package/dist/components-ui-pagination-pagination.js +50 -50
  97. package/dist/components-ui-pagination-pagination.js.map +1 -1
  98. package/dist/components-ui-select-select.cjs +1 -1
  99. package/dist/components-ui-select-select.cjs.map +1 -1
  100. package/dist/components-ui-select-select.js +1 -1
  101. package/dist/components-ui-select-select.js.map +1 -1
  102. package/dist/components-ui-sonner-sonner.cjs +1 -1
  103. package/dist/components-ui-sonner-sonner.cjs.map +1 -1
  104. package/dist/components-ui-sonner-sonner.js +14 -14
  105. package/dist/components-ui-sonner-sonner.js.map +1 -1
  106. package/dist/components-ui-table-table.cjs +4 -4
  107. package/dist/components-ui-table-table.cjs.map +1 -1
  108. package/dist/components-ui-table-table.js +89 -85
  109. package/dist/components-ui-table-table.js.map +1 -1
  110. package/dist/components-ui-textarea-textarea.cjs +1 -1
  111. package/dist/components-ui-textarea-textarea.cjs.map +1 -1
  112. package/dist/components-ui-textarea-textarea.js +2 -3
  113. package/dist/components-ui-textarea-textarea.js.map +1 -1
  114. package/dist/components-ui-textarea-textarea.styles.cjs +1 -1
  115. package/dist/components-ui-textarea-textarea.styles.cjs.map +1 -1
  116. package/dist/components-ui-textarea-textarea.styles.js +1 -1
  117. package/dist/components-ui-textarea-textarea.styles.js.map +1 -1
  118. package/dist/components-ui-toggle-group-toggle-group.cjs +2 -0
  119. package/dist/components-ui-toggle-group-toggle-group.cjs.map +1 -0
  120. package/dist/components-ui-toggle-group-toggle-group.js +112 -0
  121. package/dist/components-ui-toggle-group-toggle-group.js.map +1 -0
  122. package/dist/components-ui-toggle-group-toggle-group.styles.cjs +18 -0
  123. package/dist/components-ui-toggle-group-toggle-group.styles.cjs.map +1 -0
  124. package/dist/components-ui-toggle-group-toggle-group.styles.js +58 -0
  125. package/dist/components-ui-toggle-group-toggle-group.styles.js.map +1 -0
  126. package/dist/components-ui-toggle-group.cjs +2 -0
  127. package/dist/components-ui-toggle-group.cjs.map +1 -0
  128. package/dist/components-ui-toggle-group.js +6 -0
  129. package/dist/components-ui-toggle-group.js.map +1 -0
  130. package/dist/components-ui-toggle-toggle.cjs +2 -0
  131. package/dist/components-ui-toggle-toggle.cjs.map +1 -0
  132. package/dist/components-ui-toggle-toggle.js +57 -0
  133. package/dist/components-ui-toggle-toggle.js.map +1 -0
  134. package/dist/components-ui-toggle-toggle.styles.cjs +12 -0
  135. package/dist/components-ui-toggle-toggle.styles.cjs.map +1 -0
  136. package/dist/components-ui-toggle-toggle.styles.js +35 -0
  137. package/dist/components-ui-toggle-toggle.styles.js.map +1 -0
  138. package/dist/components-ui-toggle.cjs +2 -0
  139. package/dist/components-ui-toggle.cjs.map +1 -0
  140. package/dist/components-ui-toggle.js +7 -0
  141. package/dist/components-ui-toggle.js.map +1 -0
  142. package/dist/index.cjs +1 -1
  143. package/dist/index.d.ts +5 -1
  144. package/dist/index.js +151 -147
  145. package/dist/index.js.map +1 -1
  146. package/dist/types/types.d.ts +2 -2
  147. package/package.json +45 -16
  148. package/dist/components/ui/icon/icon-dictionary.d.ts +0 -60
  149. package/dist/components/ui/icon/overrides.d.ts +0 -21
  150. package/dist/components-ui-icon-icon-dictionary.cjs +0 -2
  151. package/dist/components-ui-icon-icon-dictionary.cjs.map +0 -1
  152. package/dist/components-ui-icon-icon-dictionary.js +0 -63
  153. package/dist/components-ui-icon-icon-dictionary.js.map +0 -1
  154. package/dist/components-ui-icon-overrides.cjs +0 -2
  155. package/dist/components-ui-icon-overrides.cjs.map +0 -1
  156. package/dist/components-ui-icon-overrides.js +0 -175
  157. package/dist/components-ui-icon-overrides.js.map +0 -1
@@ -1,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),d=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:p,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:d.cn("w-full space-y-4",p?.container),children:[t.jsxs("div",{className:d.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:"close",onClick:R(n)})})]},n)}),(!S||!_)&&t.jsxs("div",{...I(),className:d.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",p?.blockAdd),children:[t.jsx("input",{...M()}),f?t.jsx(h.Icon,{type:"loader",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:d.cn("text-sub-label-text h-8 w-8",p?.icon)}),t.jsx(L.Typography,{variant:"body-md-medium",className:d.cn("text-sub-label-text",p?.title),children:l?`${j||"Добавить"} (${s.length}/${i})`:`${j||"Добавить"}`}),v&&t.jsx(L.Typography,{variant:"body-xxs-medium",className:d.cn("text-sub-label-text",p?.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=\"close\"\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=\"loader\"\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\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,qBAAsB,CAAC,MAAM,EAC7B,0EAA2E,CAAC,OAAO,CAAA,EAErF,MAAO,CACL,2BAA4B,CAAC,MAAM,EACnC,oEAAqE,CAAC,OAAO,CAAA,EAE/E,KAA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,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)} type={\"x\"} />\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,EAAO,MAAO,MACnB,MAAMC,EAAI,KAAK,MAAM,KAAK,IAAID,CAAK,EAAI,KAAK,IAAIP,CAAY,CAAC,EAC7D,MAAO,IAAIO,EAAQ,KAAK,IAAIP,EA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AAAA,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";
2
- import { cn as d } 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";
1
+ import { jsxs as m, jsx as n } from "react/jsx-runtime";
2
+ import { cn as p } from "./lib-utils.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"], m = 1024, k = 5 * m * m, 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"], m = 1024, k = 5 * m * m, 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(m));
24
- return `${(t / Math.pow(m, e)).toFixed(2)} ${S[e]}`;
25
- }, K = (t) => t.reduce((e, c) => ({ ...e, ...q[c] }), {}), 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: c = !1,
32
- maxFiles: i = F,
33
- disabled: y = !1,
34
- className: p,
35
- maxSize: g = 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 > i) {
46
- h(`Максимальное количество файлов: ${i}`);
47
- return;
48
- }
49
- if (l.length > 0) {
50
- const n = l[0].errors[0]?.code === "file-too-large" ? `Файл слишком большой. Максимальный размер: ${g / 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
- c ? e?.([...r, ...a]) : (r[0]?.url?.startsWith("blob:") && URL.revokeObjectURL(r[0].url), e?.(a[0] ?? null)), L(!1);
62
- }, Z);
63
- },
64
- [r, i, g, c, e]
65
- ), { getRootProps: _, getInputProps: N, isDragActive: D } = P({
66
- onDrop: I,
67
- accept: K(M),
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),
68
78
  maxSize: g,
69
- multiple: c && i > 1,
70
- disabled: y || b,
71
- maxFiles: i - 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?.(c ? l : l[0] || null);
76
- }, B = r.length >= i, R = {
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: d("w-full space-y-4", p?.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
- className: d(
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: "close",
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
- ..._(),
138
- className: d(
143
+ ...C(),
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
- p?.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
- type: "loader",
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: d("text-sub-label-text h-8 w-8", p?.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: d("text-sub-label-text", p?.title),
168
- children: c ? `${v || "Добавить"} (${r.length}/${i})` : `${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: d("text-sub-label-text", p?.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"], m = 1024, k = 5 * m * m, 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=\"close\"\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=\"loader\"\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\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;AAChF,GAEMC,IAAgB,CAACC,MACrBA,EAAQ,OAAO,CAACC,GAAKC,OAAO,EAAE,GAAGD,GAAK,GAAGN,EA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KAAYQ,MAAY;AAAA,gBACzBL,MAAY,SAAS,eAAe;AAAA,gBACpCF,GAAW;AAAA,cAAA;AAAA,cAGb,UAAA;AAAA,gBAAA,gBAAAgC,EAAC,SAAA,EAAO,GAAGZ,EAAA,EAAc,CAAG;AAAA,gBAE3Bb,IACC,gBAAAyB;AAAA,kBAACE;AAAA,kBAAA;AAAA,oBACC,MAAK;AAAA,oBACL,WAAU;AAAA,kBAAA;AAAA,gBAAA,IAGZ,gBAAAJ,EAAC,OAAA,EAAI,WAAU,wDACb,UAAA;AAAA,kBAAA,gBAAAE;AAAA,oBAACE;AAAA,oBAAA;AAAA,sBACC,MAAM/B,GAAM,QAAQ;AAAA,sBACpB,WAAW0B,EAAG,+BAA+B7B,GAAW,IAAI;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAE9D,gBAAAgC;AAAA,oBAACG;AAAA,oBAAA;AAAA,sBACC,SAAQ;AAAA,sBACR,WAAWN,EAAG,uBAAuB7B,GAAW,KAAK;AAAA,sBAEpD,UAAAH,IACG,GAAGO,KAAS,UAAU,KAAKQ,EAAM,MAAM,IAAId,CAAQ,MACnD,GAAGM,KAAS,UAAU;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAE3BC,KACC,gBAAA2B,EAACG,GAAA,EAAW,SAAQ,mBAAkB,WAAWN,EAAG,uBAAuB7B,GAAW,IAAI,GACvF,UAAAK,EAAA,CACH;AAAA,gBAAA,EAAA,CAEJ;AAAA,cAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,IAYHK,KACC,gBAAAsB,EAAC,OAAA,EAAI,WAAU,iDAAiD,UAAAtB,EAAA,CAAM;AAAA,EAAA,GAE1E;AAEJ;"}
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 { 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)} type={\"x\"} />\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,IAA2D;AAAA,EAC/D,OAAO,EAAE,WAAW,CAAC,QAAQ,SAAS,QAAQ,OAAO,EAAA;AAAA,EACrD,KAAK,EAAE,mB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W,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,9 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./brd-ui-kit.css');const t=require("react/jsx-runtime");;/* empty css */const c=require("./lib-utils.cjs");require("class-variance-authority");const p=require("react");require("./components-ui-badge-badge.styles.cjs");const f=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 j=require("./hooks-usePopupControls.cjs");require("lucide-react");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 P=require("./components-input-phone-input-phone.cjs"),B=[{label:"Мобильный",icon:"phone"},{label:"Telegram",icon:"telegram"},{label:"WhatsApp",icon:"whats-app"},{label:"Max",icon:"max"},{label:"E-mail",icon:"mail"}],n=u=>{switch(u){case"max":return{viewBox:"0 0 16 16",bgColor:"bg-[linear-gradient(135deg,#9933DD_0%,#2831B9_50%,#44CCFF_100%)]"};case"telegram":return{viewBox:"0 0 17 17",bgColor:"bg-[#289AD2]"};case"whats-app":return{viewBox:"0 0 18 18",bgColor:"bg-[#00C202]",textColor:"text-[#00C202]"};default:return{viewBox:"0 0 24 24"}}},I=u=>{const{inputProps:q,inputPhoneProps:h,onTypeChange:v,...m}=u,[e,b]=p.useState("phone"),{isOpened:o,openPopup:x,closePopup:a}=j.usePopupControls(),l=p.useRef(null);p.useEffect(()=>{const r=i=>{l.current&&!l.current.contains(i.target)&&a()};return o&&document.addEventListener("mousedown",r),()=>{document.removeEventListener("mousedown",r)}},[o,a]);const d=r=>{switch(r){case"phone":return"+7 (999) 999-99-99";case"telegram":return"@username";case"whats-app":return"+7 (999) 999-99-99";case"max":return"ID пользователя Max";case"mail":return"example@mail.com";default:return"Введите значение"}},g=r=>()=>{b(r),v?.(r),a()};return t.jsxs("div",{className:c.cn("relative",u.classes?.container),children:[["telegram","max","mail"].includes(e)?t.jsx(_.InputField,{...q,...m,date:[{id:"0",position:"inline-start",component:t.jsx(s.Icon,{type:e,classes:{wrapper:c.cn(`flex h-5.5 w-5.5 items-center justify-center rounded-sm p-[3.5px]
2
- ${n(e).bgColor??"bg-primary-inverse-hover-bg"}
3
- ${n(e).textColor??"text-primary-inverse-text"}`)},viewBox:n(e).viewBox})},{id:"1",position:"inline-end",component:t.jsx(s.Icon,{type:o?"chevron-up":"chevron",className:"cursor-pointer",onClick:x})}],placeholder:d(e)}):t.jsx(P.InputPhone,{...h,...m,date:[{id:"0",position:"inline-start",component:t.jsx(s.Icon,{type:e,classes:{wrapper:c.cn(`flex h-5.5 w-5.5 items-center justify-center rounded-sm p-[3.5px]
4
- ${n(e).bgColor??"bg-primary-inverse-hover-bg"}
5
- ${n(e).textColor??"text-primary-inverse-text"}`)},viewBox:n(e).viewBox})},{id:"1",position:"inline-end",component:t.jsx(s.Icon,{type:o?"chevron-up":"chevron",className:"cursor-pointer",onClick:x})}],placeholder:d(e)}),o&&t.jsx("div",{className:`border-inp-hover-border bg-primary-bg absolute my-2 flex w-full
6
- flex-col rounded-xl border`,ref:l,children:B.map(({label:r,icon:i})=>{const{bgColor:w,textColor:C,viewBox:y}=n(i);return t.jsxs(f.Button,{variant:"ghost",className:"flex w-full justify-start",type:"button",onClick:g(i),children:[t.jsx(s.Icon,{type:i,className:"text-primary-inverse-text",classes:{wrapper:c.cn(`flex h-5.5 w-5.5 items-center justify-center rounded-sm
7
- ${w??"bg-primary-inverse-hover-bg"}
8
- ${C??"text-primary-inverse-text"}`)},viewBox:y}),r]},r)})})]})};exports.InputContact=I;
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-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");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
2
+ ${q(n).bgColor??"bg-primary-inverse-hover-bg"}
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
+ 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;
9
5
  //# sourceMappingURL=components-input-contact-input-contact.cjs.map