@techzyapp/ui-library 1.0.32 → 1.0.33
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.
- package/dist/AdminRoot-CwUHa2us.js +107 -0
- package/dist/AdminRoot-CwUHa2us.js.map +1 -0
- package/dist/AdminRoot-cjP_Ad4r.cjs +2 -0
- package/dist/AdminRoot-cjP_Ad4r.cjs.map +1 -0
- package/dist/{Alert-B9l1VhIr.cjs → Alert-CfjDmLR8.cjs} +2 -2
- package/dist/{Alert-B9l1VhIr.cjs.map → Alert-CfjDmLR8.cjs.map} +1 -1
- package/dist/{Alert-B7w9xD2p.js → Alert-LJDrtkJy.js} +3 -3
- package/dist/{Alert-B7w9xD2p.js.map → Alert-LJDrtkJy.js.map} +1 -1
- package/dist/{Breadcrumbs-B1JMwCjO.cjs → Breadcrumbs-COb2zmDk.cjs} +2 -2
- package/dist/{Breadcrumbs-B1JMwCjO.cjs.map → Breadcrumbs-COb2zmDk.cjs.map} +1 -1
- package/dist/{Breadcrumbs-Cl1CgKkk.js → Breadcrumbs-DYeVrOns.js} +3 -3
- package/dist/{Breadcrumbs-Cl1CgKkk.js.map → Breadcrumbs-DYeVrOns.js.map} +1 -1
- package/dist/{Button-BZq1mIUH.cjs → Button-BD5wpg-t.cjs} +2 -2
- package/dist/{Button-BZq1mIUH.cjs.map → Button-BD5wpg-t.cjs.map} +1 -1
- package/dist/{Button-BJ5Xd10u.js → Button-PBZnkRNn.js} +2 -2
- package/dist/{Button-BJ5Xd10u.js.map → Button-PBZnkRNn.js.map} +1 -1
- package/dist/{Calendar-r-dDXWEp.cjs → Calendar-842vjtdN.cjs} +2 -2
- package/dist/{Calendar-r-dDXWEp.cjs.map → Calendar-842vjtdN.cjs.map} +1 -1
- package/dist/{Calendar-rRPnaU9M.js → Calendar-Bb5Ekbpr.js} +3 -3
- package/dist/{Calendar-rRPnaU9M.js.map → Calendar-Bb5Ekbpr.js.map} +1 -1
- package/dist/{Card-Cr3D2bzJ.js → Card-CV_rHego.js} +2 -2
- package/dist/{Card-Cr3D2bzJ.js.map → Card-CV_rHego.js.map} +1 -1
- package/dist/{Card-KsczbH5c.cjs → Card-DL7XnkOA.cjs} +2 -2
- package/dist/{Card-KsczbH5c.cjs.map → Card-DL7XnkOA.cjs.map} +1 -1
- package/dist/{Chip-BZ3I4Lbe.cjs → Chip-CLPIPC9a.cjs} +2 -2
- package/dist/{Chip-BZ3I4Lbe.cjs.map → Chip-CLPIPC9a.cjs.map} +1 -1
- package/dist/{Chip-DEp1zWh1.js → Chip-DdOUVF0Z.js} +2 -2
- package/dist/{Chip-DEp1zWh1.js.map → Chip-DdOUVF0Z.js.map} +1 -1
- package/dist/{CodeBlock-CMHqvoBJ.js → CodeBlock-B35NXZzd.js} +3 -3
- package/dist/{CodeBlock-CMHqvoBJ.js.map → CodeBlock-B35NXZzd.js.map} +1 -1
- package/dist/{CodeBlock-DIkyeG4S.cjs → CodeBlock-C0dbyxcl.cjs} +2 -2
- package/dist/{CodeBlock-DIkyeG4S.cjs.map → CodeBlock-C0dbyxcl.cjs.map} +1 -1
- package/dist/{ColorPicker-5SMyU5oh.js → ColorPicker-6UraVYFy.js} +3 -3
- package/dist/{ColorPicker-5SMyU5oh.js.map → ColorPicker-6UraVYFy.js.map} +1 -1
- package/dist/{ColorPicker-B1riGs1z.cjs → ColorPicker-DmLGKaYF.cjs} +2 -2
- package/dist/{ColorPicker-B1riGs1z.cjs.map → ColorPicker-DmLGKaYF.cjs.map} +1 -1
- package/dist/{ColorPickerPanel-4Y6oXL7v.js → ColorPickerPanel-DZ-W_wOI.js} +2 -2
- package/dist/{ColorPickerPanel-4Y6oXL7v.js.map → ColorPickerPanel-DZ-W_wOI.js.map} +1 -1
- package/dist/{ColorPickerPanel-CzBlh0zw.cjs → ColorPickerPanel-WuxwwfCI.cjs} +2 -2
- package/dist/{ColorPickerPanel-CzBlh0zw.cjs.map → ColorPickerPanel-WuxwwfCI.cjs.map} +1 -1
- package/dist/{ColorRamp-Qc8ZtPDh.js → ColorRamp-CSqzzHZx.js} +2 -2
- package/dist/{ColorRamp-Qc8ZtPDh.js.map → ColorRamp-CSqzzHZx.js.map} +1 -1
- package/dist/{ColorRamp-D_h-hp7n.cjs → ColorRamp-D_9gsqJl.cjs} +2 -2
- package/dist/{ColorRamp-D_h-hp7n.cjs.map → ColorRamp-D_9gsqJl.cjs.map} +1 -1
- package/dist/{ConfigProvider-CzAQf_d_.cjs → ConfigProvider-CVLHPXQm.cjs} +2 -2
- package/dist/ConfigProvider-CVLHPXQm.cjs.map +1 -0
- package/dist/{ConfigProvider-D2svpXFu.js → ConfigProvider-tvLbKiqu.js} +2 -2
- package/dist/ConfigProvider-tvLbKiqu.js.map +1 -0
- package/dist/{CopyButton-DUtx2-Gi.cjs → CopyButton-0w4OToIy.cjs} +2 -2
- package/dist/{CopyButton-DUtx2-Gi.cjs.map → CopyButton-0w4OToIy.cjs.map} +1 -1
- package/dist/{CopyButton-BNcW9-KU.js → CopyButton-B_mYxcXV.js} +3 -3
- package/dist/{CopyButton-BNcW9-KU.js.map → CopyButton-B_mYxcXV.js.map} +1 -1
- package/dist/{DatePicker-D2PyGdec.js → DatePicker-Bt-M87zX.js} +4 -4
- package/dist/{DatePicker-D2PyGdec.js.map → DatePicker-Bt-M87zX.js.map} +1 -1
- package/dist/{DatePicker-D_PqDvKt.cjs → DatePicker-D1uFIm3M.cjs} +2 -2
- package/dist/{DatePicker-D_PqDvKt.cjs.map → DatePicker-D1uFIm3M.cjs.map} +1 -1
- package/dist/{DateTimePicker-C3Kq5hKE.cjs → DateTimePicker-DPt-LDVJ.cjs} +2 -2
- package/dist/{DateTimePicker-C3Kq5hKE.cjs.map → DateTimePicker-DPt-LDVJ.cjs.map} +1 -1
- package/dist/{DateTimePicker-DdXFzqO_.js → DateTimePicker-zJUc9crs.js} +7 -7
- package/dist/{DateTimePicker-DdXFzqO_.js.map → DateTimePicker-zJUc9crs.js.map} +1 -1
- package/dist/{DescriptionList-DxRgKNEJ.js → DescriptionList-BLx9NfAW.js} +4 -4
- package/dist/{DescriptionList-DxRgKNEJ.js.map → DescriptionList-BLx9NfAW.js.map} +1 -1
- package/dist/{DescriptionList-C7AOcw_2.cjs → DescriptionList-CPCbzU9b.cjs} +2 -2
- package/dist/{DescriptionList-C7AOcw_2.cjs.map → DescriptionList-CPCbzU9b.cjs.map} +1 -1
- package/dist/{EmptyState-CvpKSYY4.js → EmptyState-BEVEGcLx.js} +2 -2
- package/dist/{EmptyState-CvpKSYY4.js.map → EmptyState-BEVEGcLx.js.map} +1 -1
- package/dist/{EmptyState-ECc6e_En.cjs → EmptyState-C54C0Qwc.cjs} +2 -2
- package/dist/{EmptyState-ECc6e_En.cjs.map → EmptyState-C54C0Qwc.cjs.map} +1 -1
- package/dist/ErrorBoundary-8iu-mR5Y.cjs +2 -0
- package/dist/ErrorBoundary-8iu-mR5Y.cjs.map +1 -0
- package/dist/ErrorBoundary-BSJL381Y.js +49 -0
- package/dist/ErrorBoundary-BSJL381Y.js.map +1 -0
- package/dist/ErrorState-BXMjBWav.cjs +4 -0
- package/dist/ErrorState-BXMjBWav.cjs.map +1 -0
- package/dist/ErrorState-DKhZ4aJh.js +142 -0
- package/dist/ErrorState-DKhZ4aJh.js.map +1 -0
- package/dist/{FileCard-Bjqsgi7S.cjs → FileCard-B3dfdTVN.cjs} +2 -2
- package/dist/{FileCard-Bjqsgi7S.cjs.map → FileCard-B3dfdTVN.cjs.map} +1 -1
- package/dist/{FileCard-D4t0-ms2.js → FileCard-R_sB8Qbx.js} +3 -3
- package/dist/{FileCard-D4t0-ms2.js.map → FileCard-R_sB8Qbx.js.map} +1 -1
- package/dist/{FileUploader-DWM8WrY6.cjs → FileUploader-4UMy0urx.cjs} +2 -2
- package/dist/{FileUploader-DWM8WrY6.cjs.map → FileUploader-4UMy0urx.cjs.map} +1 -1
- package/dist/{FileUploader-DdcvZoUb.js → FileUploader-B55atuxq.js} +5 -5
- package/dist/{FileUploader-DdcvZoUb.js.map → FileUploader-B55atuxq.js.map} +1 -1
- package/dist/{Flag-D5rqScYG.cjs → Flag-CFvJHC0u.cjs} +2 -2
- package/dist/{Flag-D5rqScYG.cjs.map → Flag-CFvJHC0u.cjs.map} +1 -1
- package/dist/{Flag-BLEBMdb-.js → Flag-D7fmMqqy.js} +2 -2
- package/dist/{Flag-BLEBMdb-.js.map → Flag-D7fmMqqy.js.map} +1 -1
- package/dist/{FullscreenToggle-DZnKK1Lj.js → FullscreenToggle-CXmPqxJv.js} +3 -3
- package/dist/{FullscreenToggle-DZnKK1Lj.js.map → FullscreenToggle-CXmPqxJv.js.map} +1 -1
- package/dist/{FullscreenToggle-CZoc5pYg.cjs → FullscreenToggle-D7tUPCNI.cjs} +2 -2
- package/dist/{FullscreenToggle-CZoc5pYg.cjs.map → FullscreenToggle-D7tUPCNI.cjs.map} +1 -1
- package/dist/{IconButton-V8tjArlt.cjs → IconButton-BVrO9TBP.cjs} +2 -2
- package/dist/{IconButton-V8tjArlt.cjs.map → IconButton-BVrO9TBP.cjs.map} +1 -1
- package/dist/{IconButton-CqFgam3J.js → IconButton-sC_E_TXd.js} +2 -2
- package/dist/{IconButton-CqFgam3J.js.map → IconButton-sC_E_TXd.js.map} +1 -1
- package/dist/{Loader-Bsz0BkGr.js → Loader-ChrouvaR.js} +2 -2
- package/dist/{Loader-Bsz0BkGr.js.map → Loader-ChrouvaR.js.map} +1 -1
- package/dist/{Loader-CqRaCdzF.cjs → Loader-DNCEHqZb.cjs} +2 -2
- package/dist/{Loader-CqRaCdzF.cjs.map → Loader-DNCEHqZb.cjs.map} +1 -1
- package/dist/{LocationPicker-BRGNcTd_.cjs → LocationPicker-CJ6bCJC4.cjs} +2 -2
- package/dist/{LocationPicker-BRGNcTd_.cjs.map → LocationPicker-CJ6bCJC4.cjs.map} +1 -1
- package/dist/{LocationPicker-DtMDpPFZ.js → LocationPicker-DxiQ27k6.js} +6 -6
- package/dist/{LocationPicker-DtMDpPFZ.js.map → LocationPicker-DxiQ27k6.js.map} +1 -1
- package/dist/{Modal-CcrqM4kn.cjs → Modal-BL_XihC8.cjs} +2 -2
- package/dist/{Modal-CcrqM4kn.cjs.map → Modal-BL_XihC8.cjs.map} +1 -1
- package/dist/{Modal-DCee1a9m.js → Modal-Do8pzyMl.js} +3 -3
- package/dist/{Modal-DCee1a9m.js.map → Modal-Do8pzyMl.js.map} +1 -1
- package/dist/{MultiSelect-JQ6iKHyI.js → MultiSelect-BfsEdXNa.js} +4 -4
- package/dist/{MultiSelect-JQ6iKHyI.js.map → MultiSelect-BfsEdXNa.js.map} +1 -1
- package/dist/{MultiSelect-BJ-qMpA5.cjs → MultiSelect-WS5YNGRD.cjs} +2 -2
- package/dist/{MultiSelect-BJ-qMpA5.cjs.map → MultiSelect-WS5YNGRD.cjs.map} +1 -1
- package/dist/{NumberField-mZjwZB8E.cjs → NumberField-CxiEfRAi.cjs} +2 -2
- package/dist/{NumberField-mZjwZB8E.cjs.map → NumberField-CxiEfRAi.cjs.map} +1 -1
- package/dist/{NumberField-Bf-vDNLy.js → NumberField-P68n6q5m.js} +3 -3
- package/dist/{NumberField-Bf-vDNLy.js.map → NumberField-P68n6q5m.js.map} +1 -1
- package/dist/{OtpField-DaAIBp6C.js → OtpField-DjTJH4Kh.js} +2 -2
- package/dist/{OtpField-DaAIBp6C.js.map → OtpField-DjTJH4Kh.js.map} +1 -1
- package/dist/{OtpField-TdjMkgQi.cjs → OtpField-XieJfl1y.cjs} +2 -2
- package/dist/{OtpField-TdjMkgQi.cjs.map → OtpField-XieJfl1y.cjs.map} +1 -1
- package/dist/PageError-ClR7k0Zb.js +69 -0
- package/dist/PageError-ClR7k0Zb.js.map +1 -0
- package/dist/PageError-D7_Q8wz8.cjs +2 -0
- package/dist/PageError-D7_Q8wz8.cjs.map +1 -0
- package/dist/{PageLayout-BoHvt2cT.cjs → PageLayout-DTG83hLL.cjs} +2 -2
- package/dist/{PageLayout-BoHvt2cT.cjs.map → PageLayout-DTG83hLL.cjs.map} +1 -1
- package/dist/{PageLayout-Bwv8Oohb.js → PageLayout-XQ_aQTf5.js} +2 -2
- package/dist/{PageLayout-Bwv8Oohb.js.map → PageLayout-XQ_aQTf5.js.map} +1 -1
- package/dist/PageNotFound-CpwHMTxG.js +24 -0
- package/dist/PageNotFound-CpwHMTxG.js.map +1 -0
- package/dist/PageNotFound-D3wJ4Job.cjs +2 -0
- package/dist/PageNotFound-D3wJ4Job.cjs.map +1 -0
- package/dist/{Pagination-DzkTjEZL.cjs → Pagination-BF8cmQMi.cjs} +2 -2
- package/dist/{Pagination-DzkTjEZL.cjs.map → Pagination-BF8cmQMi.cjs.map} +1 -1
- package/dist/{Pagination-C0xr3D-g.js → Pagination-Df-F9i2o.js} +2 -2
- package/dist/{Pagination-C0xr3D-g.js.map → Pagination-Df-F9i2o.js.map} +1 -1
- package/dist/{PaletteField-CQV2dll0.cjs → PaletteField-BFRPv7AC.cjs} +2 -2
- package/dist/{PaletteField-CQV2dll0.cjs.map → PaletteField-BFRPv7AC.cjs.map} +1 -1
- package/dist/{PaletteField-CQv6MBKe.js → PaletteField-DUu4jz1c.js} +3 -3
- package/dist/{PaletteField-CQv6MBKe.js.map → PaletteField-DUu4jz1c.js.map} +1 -1
- package/dist/{PhoneField-Bqj5-33G.js → PhoneField-CXIQX_hR.js} +4 -4
- package/dist/{PhoneField-Bqj5-33G.js.map → PhoneField-CXIQX_hR.js.map} +1 -1
- package/dist/{PhoneField-Dzdm5hfY.cjs → PhoneField-O5syyH7u.cjs} +2 -2
- package/dist/{PhoneField-Dzdm5hfY.cjs.map → PhoneField-O5syyH7u.cjs.map} +1 -1
- package/dist/{Popconfirm-CYkwGTh-.js → Popconfirm-D4J7tlk_.js} +3 -3
- package/dist/{Popconfirm-CYkwGTh-.js.map → Popconfirm-D4J7tlk_.js.map} +1 -1
- package/dist/{Popconfirm-DS6tCxV0.cjs → Popconfirm-bEoOPmZY.cjs} +2 -2
- package/dist/{Popconfirm-DS6tCxV0.cjs.map → Popconfirm-bEoOPmZY.cjs.map} +1 -1
- package/dist/{Progress-DZUtn3Sh.js → Progress-BxvqmmGS.js} +2 -2
- package/dist/{Progress-DZUtn3Sh.js.map → Progress-BxvqmmGS.js.map} +1 -1
- package/dist/{Progress-lf9vIKIk.cjs → Progress-CqXX0rRp.cjs} +2 -2
- package/dist/{Progress-lf9vIKIk.cjs.map → Progress-CqXX0rRp.cjs.map} +1 -1
- package/dist/{RemoveDialog-DaWh4xmW.js → RemoveDialog-DH3eNUxC.js} +5 -5
- package/dist/{RemoveDialog-DaWh4xmW.js.map → RemoveDialog-DH3eNUxC.js.map} +1 -1
- package/dist/{RemoveDialog-Csfhv9ve.cjs → RemoveDialog-FrieNcjL.cjs} +2 -2
- package/dist/{RemoveDialog-Csfhv9ve.cjs.map → RemoveDialog-FrieNcjL.cjs.map} +1 -1
- package/dist/{RichTextEditor-BLEDQq2H.js → RichTextEditor-6frB2C5G.js} +7 -7
- package/dist/{RichTextEditor-BLEDQq2H.js.map → RichTextEditor-6frB2C5G.js.map} +1 -1
- package/dist/{RichTextEditor-Eo8uLXlI.cjs → RichTextEditor-B-C4NPDk.cjs} +2 -2
- package/dist/{RichTextEditor-Eo8uLXlI.cjs.map → RichTextEditor-B-C4NPDk.cjs.map} +1 -1
- package/dist/{RootLayout-D-ZlsTXF.js → RootLayout-C7n79JjM.js} +219 -202
- package/dist/RootLayout-C7n79JjM.js.map +1 -0
- package/dist/RootLayout-CtkpgPGV.cjs +2 -0
- package/dist/RootLayout-CtkpgPGV.cjs.map +1 -0
- package/dist/{Select-CH3mF6y1.cjs → Select-Bjq_p8_e.cjs} +2 -2
- package/dist/{Select-CH3mF6y1.cjs.map → Select-Bjq_p8_e.cjs.map} +1 -1
- package/dist/{Select-C0UBQXhg.js → Select-DO3zDQYV.js} +3 -3
- package/dist/{Select-C0UBQXhg.js.map → Select-DO3zDQYV.js.map} +1 -1
- package/dist/{Sidebar-6wu2fuPT.cjs → Sidebar-2oH285Xs.cjs} +2 -2
- package/dist/{Sidebar-6wu2fuPT.cjs.map → Sidebar-2oH285Xs.cjs.map} +1 -1
- package/dist/{Sidebar--rOPtrqa.js → Sidebar-CKbSWc5q.js} +3 -3
- package/dist/{Sidebar--rOPtrqa.js.map → Sidebar-CKbSWc5q.js.map} +1 -1
- package/dist/{SpeedDial-BIodC6td.js → SpeedDial-BZK-z_r9.js} +2 -2
- package/dist/{SpeedDial-BIodC6td.js.map → SpeedDial-BZK-z_r9.js.map} +1 -1
- package/dist/{SpeedDial-BtxXH6Ij.cjs → SpeedDial-KGf8b4Gq.cjs} +2 -2
- package/dist/{SpeedDial-BtxXH6Ij.cjs.map → SpeedDial-KGf8b4Gq.cjs.map} +1 -1
- package/dist/{Stepper-CPBPTxbP.js → Stepper-BI3pjWf_.js} +2 -2
- package/dist/{Stepper-CPBPTxbP.js.map → Stepper-BI3pjWf_.js.map} +1 -1
- package/dist/{Stepper-B38I8PBS.cjs → Stepper-s9Vah5R2.cjs} +2 -2
- package/dist/{Stepper-B38I8PBS.cjs.map → Stepper-s9Vah5R2.cjs.map} +1 -1
- package/dist/Table-CLjLsYYS.cjs +2 -0
- package/dist/Table-CLjLsYYS.cjs.map +1 -0
- package/dist/{Table-BV-dr36o.js → Table-PsNnKn_j.js} +153 -152
- package/dist/Table-PsNnKn_j.js.map +1 -0
- package/dist/{Tabs-RjyUkLTB.js → Tabs-B2WzlRXI.js} +2 -2
- package/dist/{Tabs-RjyUkLTB.js.map → Tabs-B2WzlRXI.js.map} +1 -1
- package/dist/{Tabs-DIs8iFA-.cjs → Tabs-DQoNP0QT.cjs} +2 -2
- package/dist/{Tabs-DIs8iFA-.cjs.map → Tabs-DQoNP0QT.cjs.map} +1 -1
- package/dist/{TagsField-CJ10-kFr.cjs → TagsField-CLfAAz4N.cjs} +2 -2
- package/dist/{TagsField-CJ10-kFr.cjs.map → TagsField-CLfAAz4N.cjs.map} +1 -1
- package/dist/{TagsField-B3MtFiFs.js → TagsField-pdvQU4zh.js} +4 -4
- package/dist/{TagsField-B3MtFiFs.js.map → TagsField-pdvQU4zh.js.map} +1 -1
- package/dist/{TextField-D_hzd5Gf.cjs → TextField-CgPfN-4d.cjs} +2 -2
- package/dist/{TextField-D_hzd5Gf.cjs.map → TextField-CgPfN-4d.cjs.map} +1 -1
- package/dist/{TextField-CInaL0FR.js → TextField-LONfx4jy.js} +3 -3
- package/dist/{TextField-CInaL0FR.js.map → TextField-LONfx4jy.js.map} +1 -1
- package/dist/{ThemeToggle-DkhhlH_r.cjs → ThemeToggle-9RBaRALj.cjs} +2 -2
- package/dist/{ThemeToggle-DkhhlH_r.cjs.map → ThemeToggle-9RBaRALj.cjs.map} +1 -1
- package/dist/{ThemeToggle-CWfuK0tZ.js → ThemeToggle-DTkFppOd.js} +3 -3
- package/dist/{ThemeToggle-CWfuK0tZ.js.map → ThemeToggle-DTkFppOd.js.map} +1 -1
- package/dist/{TimeColumns-fD6dosYP.js → TimeColumns-B7af5Cbj.js} +2 -2
- package/dist/{TimeColumns-fD6dosYP.js.map → TimeColumns-B7af5Cbj.js.map} +1 -1
- package/dist/{TimeColumns-t3Pn01v5.cjs → TimeColumns-CJ13uf3K.cjs} +2 -2
- package/dist/{TimeColumns-t3Pn01v5.cjs.map → TimeColumns-CJ13uf3K.cjs.map} +1 -1
- package/dist/{TimePicker-DypTHDW0.js → TimePicker-BitZ7wv-.js} +5 -5
- package/dist/{TimePicker-DypTHDW0.js.map → TimePicker-BitZ7wv-.js.map} +1 -1
- package/dist/{TimePicker-DOwQF7sX.cjs → TimePicker-Dshko7IJ.cjs} +2 -2
- package/dist/{TimePicker-DOwQF7sX.cjs.map → TimePicker-Dshko7IJ.cjs.map} +1 -1
- package/dist/{Toaster-DdUOwi7L.cjs → Toaster-8ynQTcc0.cjs} +2 -2
- package/dist/{Toaster-DdUOwi7L.cjs.map → Toaster-8ynQTcc0.cjs.map} +1 -1
- package/dist/{Toaster-BwNAKDMc.js → Toaster-CYVETXVZ.js} +2 -2
- package/dist/{Toaster-BwNAKDMc.js.map → Toaster-CYVETXVZ.js.map} +1 -1
- package/dist/{TranslatedFields-D9FQlxiQ.cjs → TranslatedFields-BKI3jrNd.cjs} +2 -2
- package/dist/{TranslatedFields-D9FQlxiQ.cjs.map → TranslatedFields-BKI3jrNd.cjs.map} +1 -1
- package/dist/{TranslatedFields-C_-qPixE.js → TranslatedFields-dmb-0Yn7.js} +5 -5
- package/dist/{TranslatedFields-C_-qPixE.js.map → TranslatedFields-dmb-0Yn7.js.map} +1 -1
- package/dist/{UserCard-C-q2s2Cw.cjs → UserCard-ah6K1y0H.cjs} +2 -2
- package/dist/{UserCard-C-q2s2Cw.cjs.map → UserCard-ah6K1y0H.cjs.map} +1 -1
- package/dist/{UserCard-CwWv0HXD.js → UserCard-pEJZqiDF.js} +3 -3
- package/dist/{UserCard-CwWv0HXD.js.map → UserCard-pEJZqiDF.js.map} +1 -1
- package/dist/app/AdminRoot.d.cts +75 -4
- package/dist/app/AdminRoot.d.ts +75 -4
- package/dist/components/Alert/index.cjs +1 -1
- package/dist/components/Alert/index.js +1 -1
- package/dist/components/Breadcrumbs/index.cjs +1 -1
- package/dist/components/Breadcrumbs/index.js +1 -1
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/Card/index.cjs +1 -1
- package/dist/components/Card/index.js +1 -1
- package/dist/components/Chip/index.cjs +1 -1
- package/dist/components/Chip/index.js +1 -1
- package/dist/components/CodeBlock/index.cjs +1 -1
- package/dist/components/CodeBlock/index.js +1 -1
- package/dist/components/ColorPicker/index.cjs +1 -1
- package/dist/components/ColorPicker/index.js +1 -1
- package/dist/components/ColorRamp/index.cjs +1 -1
- package/dist/components/ColorRamp/index.js +1 -1
- package/dist/components/CopyButton/index.cjs +1 -1
- package/dist/components/CopyButton/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/DateTimePicker/index.cjs +1 -1
- package/dist/components/DateTimePicker/index.js +1 -1
- package/dist/components/DescriptionList/index.cjs +1 -1
- package/dist/components/DescriptionList/index.js +1 -1
- package/dist/components/EmptyState/index.cjs +1 -1
- package/dist/components/EmptyState/index.js +1 -1
- package/dist/components/ErrorState/ErrorBoundary.d.cts +3 -3
- package/dist/components/ErrorState/ErrorBoundary.d.ts +3 -3
- package/dist/components/ErrorState/ErrorState.d.cts +37 -9
- package/dist/components/ErrorState/ErrorState.d.ts +37 -9
- package/dist/components/ErrorState/errorMessage.d.cts +35 -3
- package/dist/components/ErrorState/errorMessage.d.ts +35 -3
- package/dist/components/ErrorState/index.cjs +1 -1
- package/dist/components/ErrorState/index.d.cts +2 -2
- package/dist/components/ErrorState/index.d.ts +2 -2
- package/dist/components/ErrorState/index.js +15 -10
- package/dist/components/ErrorState/index.js.map +1 -1
- package/dist/components/FileCard/index.cjs +1 -1
- package/dist/components/FileCard/index.js +1 -1
- package/dist/components/FileUploader/index.cjs +1 -1
- package/dist/components/FileUploader/index.js +1 -1
- package/dist/components/Flag/index.cjs +1 -1
- package/dist/components/Flag/index.js +1 -1
- package/dist/components/FullscreenToggle/index.cjs +1 -1
- package/dist/components/FullscreenToggle/index.js +1 -1
- package/dist/components/IconButton/index.cjs +1 -1
- package/dist/components/IconButton/index.js +1 -1
- package/dist/components/Loader/index.cjs +1 -1
- package/dist/components/Loader/index.js +1 -1
- package/dist/components/LocationPicker/index.cjs +1 -1
- package/dist/components/LocationPicker/index.js +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/MultiSelect/MultiSelect.d.cts +1 -1
- package/dist/components/MultiSelect/MultiSelect.d.ts +1 -1
- package/dist/components/MultiSelect/index.cjs +1 -1
- package/dist/components/MultiSelect/index.js +1 -1
- package/dist/components/NumberField/index.cjs +1 -1
- package/dist/components/NumberField/index.js +1 -1
- package/dist/components/OptionMenu/OptionMenu.d.cts +1 -1
- package/dist/components/OptionMenu/OptionMenu.d.ts +1 -1
- package/dist/components/OtpField/index.cjs +1 -1
- package/dist/components/OtpField/index.js +1 -1
- package/dist/components/PageError/PageError.d.cts +53 -0
- package/dist/components/PageError/PageError.d.ts +53 -0
- package/dist/components/PageError/index.cjs +2 -0
- package/dist/components/PageError/index.cjs.map +1 -0
- package/dist/components/PageError/index.d.cts +2 -0
- package/dist/components/PageError/index.d.ts +2 -0
- package/dist/components/PageError/index.js +6 -0
- package/dist/components/PageError/index.js.map +1 -0
- package/dist/components/PageLayout/index.cjs +1 -1
- package/dist/components/PageLayout/index.js +1 -1
- package/dist/components/PageNotFound/index.cjs +1 -1
- package/dist/components/PageNotFound/index.js +1 -1
- package/dist/components/PageNotFound/useHomeTo.d.cts +10 -0
- package/dist/components/PageNotFound/useHomeTo.d.ts +10 -0
- package/dist/components/Pagination/index.cjs +1 -1
- package/dist/components/Pagination/index.js +1 -1
- package/dist/components/PaletteField/index.cjs +1 -1
- package/dist/components/PaletteField/index.js +1 -1
- package/dist/components/PhoneField/index.cjs +1 -1
- package/dist/components/PhoneField/index.js +1 -1
- package/dist/components/Popconfirm/index.cjs +1 -1
- package/dist/components/Popconfirm/index.js +1 -1
- package/dist/components/Progress/index.cjs +1 -1
- package/dist/components/Progress/index.js +1 -1
- package/dist/components/RemoveDialog/index.cjs +1 -1
- package/dist/components/RemoveDialog/index.js +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/RootLayout/index.cjs +1 -1
- package/dist/components/RootLayout/index.js +1 -1
- package/dist/components/Select/Select.d.cts +1 -1
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.js +1 -1
- package/dist/components/Sidebar/index.cjs +1 -1
- package/dist/components/Sidebar/index.js +1 -1
- package/dist/components/SpeedDial/index.cjs +1 -1
- package/dist/components/SpeedDial/index.js +1 -1
- package/dist/components/Stepper/index.cjs +1 -1
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/Table/Table.d.cts +1 -1
- package/dist/components/Table/Table.d.ts +1 -1
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Tabs/index.cjs +1 -1
- package/dist/components/Tabs/index.js +1 -1
- package/dist/components/TagsField/TagsField.d.cts +1 -1
- package/dist/components/TagsField/TagsField.d.ts +1 -1
- package/dist/components/TagsField/index.cjs +1 -1
- package/dist/components/TagsField/index.js +1 -1
- package/dist/components/TextField/TextField.d.cts +1 -1
- package/dist/components/TextField/TextField.d.ts +1 -1
- package/dist/components/TextField/index.cjs +1 -1
- package/dist/components/TextField/index.js +1 -1
- package/dist/components/ThemeToggle/index.cjs +1 -1
- package/dist/components/ThemeToggle/index.js +1 -1
- package/dist/components/TimePicker/index.cjs +1 -1
- package/dist/components/TimePicker/index.js +1 -1
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/TranslatedFields/index.cjs +1 -1
- package/dist/components/TranslatedFields/index.js +1 -1
- package/dist/components/UserCard/UserCard.d.cts +1 -1
- package/dist/components/UserCard/UserCard.d.ts +1 -1
- package/dist/components/UserCard/index.cjs +1 -1
- package/dist/components/UserCard/index.js +1 -1
- package/dist/components/index.d.cts +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/entries/app.cjs +1 -1
- package/dist/entries/app.d.cts +1 -1
- package/dist/entries/app.d.ts +1 -1
- package/dist/entries/app.js +1 -1
- package/dist/entries/components.cjs +1 -1
- package/dist/entries/components.js +166 -159
- package/dist/entries/components.js.map +1 -1
- package/dist/entries/i18n.cjs +1 -1
- package/dist/entries/i18n.js +2 -2
- package/dist/entries/theme.cjs +1 -1
- package/dist/entries/theme.js +1 -1
- package/dist/errorMessage-C7N4KvUS.cjs +2 -0
- package/dist/errorMessage-C7N4KvUS.cjs.map +1 -0
- package/dist/errorMessage-C83fB2h5.js +98 -0
- package/dist/errorMessage-C83fB2h5.js.map +1 -0
- package/dist/i18n/messages.d.cts +15 -1
- package/dist/i18n/messages.d.ts +15 -1
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +212 -205
- package/dist/index.js.map +1 -1
- package/dist/{messages-BOJsnD0O.js → messages-C1eTrGJy.js} +128 -79
- package/dist/messages-C1eTrGJy.js.map +1 -0
- package/dist/messages-DCr7iFmv.cjs +36 -0
- package/dist/messages-DCr7iFmv.cjs.map +1 -0
- package/dist/theme/ConfigProvider.d.cts +17 -3
- package/dist/theme/ConfigProvider.d.ts +17 -3
- package/dist/useHomeTo-Cr6Usr_D.cjs +2 -0
- package/dist/useHomeTo-Cr6Usr_D.cjs.map +1 -0
- package/dist/useHomeTo-yTXajO22.js +25 -0
- package/dist/useHomeTo-yTXajO22.js.map +1 -0
- package/dist/{useOptionMenu-8hjCTNL4.cjs → useOptionMenu-DHGSbQmS.cjs} +2 -2
- package/dist/{useOptionMenu-8hjCTNL4.cjs.map → useOptionMenu-DHGSbQmS.cjs.map} +1 -1
- package/dist/{useOptionMenu-C1wOZ9NT.js → useOptionMenu-DK0ixg-p.js} +3 -3
- package/dist/{useOptionMenu-C1wOZ9NT.js.map → useOptionMenu-DK0ixg-p.js.map} +1 -1
- package/package.json +1 -1
- package/dist/AdminRoot-B9A4Hoz0.js +0 -57
- package/dist/AdminRoot-B9A4Hoz0.js.map +0 -1
- package/dist/AdminRoot-BVUEWczU.cjs +0 -2
- package/dist/AdminRoot-BVUEWczU.cjs.map +0 -1
- package/dist/ConfigProvider-CzAQf_d_.cjs.map +0 -1
- package/dist/ConfigProvider-D2svpXFu.js.map +0 -1
- package/dist/ErrorBoundary-CJx5E9wJ.js +0 -163
- package/dist/ErrorBoundary-CJx5E9wJ.js.map +0 -1
- package/dist/ErrorBoundary-DbKRtdgS.cjs +0 -2
- package/dist/ErrorBoundary-DbKRtdgS.cjs.map +0 -1
- package/dist/PageNotFound-CMt8vnky.js +0 -39
- package/dist/PageNotFound-CMt8vnky.js.map +0 -1
- package/dist/PageNotFound-DDm6nwQh.cjs +0 -2
- package/dist/PageNotFound-DDm6nwQh.cjs.map +0 -1
- package/dist/QueryError-Dl8yzdxw.js +0 -19
- package/dist/QueryError-Dl8yzdxw.js.map +0 -1
- package/dist/QueryError-RF7Mh5zg.cjs +0 -2
- package/dist/QueryError-RF7Mh5zg.cjs.map +0 -1
- package/dist/RootLayout-BvyeNM9_.cjs +0 -2
- package/dist/RootLayout-BvyeNM9_.cjs.map +0 -1
- package/dist/RootLayout-D-ZlsTXF.js.map +0 -1
- package/dist/Table-1RVWzyS6.cjs +0 -2
- package/dist/Table-1RVWzyS6.cjs.map +0 -1
- package/dist/Table-BV-dr36o.js.map +0 -1
- package/dist/messages-BOJsnD0O.js.map +0 -1
- package/dist/messages-ejfYfHwL.cjs +0 -36
- package/dist/messages-ejfYfHwL.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorState-BXMjBWav.cjs","sources":["../src/components/ErrorState/ErrorState.tsx"],"sourcesContent":["import { forwardRef, type ReactNode } from 'react'\nimport { clsx } from 'clsx'\nimport { useT } from '../../theme'\nimport { Alert } from '../Alert'\nimport { Button } from '../Button'\nimport { CopyButton } from '../CopyButton'\nimport { EmptyState, type EmptyStateProps } from '../EmptyState'\nimport { Icon } from '../Icon'\nimport type { IconName } from '../../icons/names'\nimport {\n getErrorDetails,\n getErrorFieldErrors,\n getErrorMessage,\n getErrorTraceId,\n humanizeField,\n isNetworkError,\n isDev,\n} from './errorMessage'\nimport styles from './ErrorState.module.css'\n\nexport type ErrorStateVariant = 'block' | 'alert'\n\nexport interface ErrorStateProps extends Omit<EmptyStateProps, 'icon' | 'title' | 'color'> {\n /**\n * The shape. `'block'` (default) — the `EmptyState`-style block (puck, title, centred message), for a read\n * that failed where its data would be. `'alert'` — a one-line red `Alert` banner for a **failed save**\n * above a form or in a modal, where the form stays on screen: the message (no default title), a muted\n * trace id line, and the copy / retry / `action` buttons in the alert's action slot. `showDetails`,\n * `compact` and `pattern` don't apply to `'alert'`.\n */\n variant?: ErrorStateVariant\n /**\n * What failed — an `Error`, a string, an axios-style error, a `{ message }` or a raw `{ status }`\n * response. Its message becomes the description (unless `description` is given) and its stack feeds\n * the details panel.\n */\n error?: unknown\n /**\n * Heading. Block: defaults to the localized \"Something Went Wrong\". Alert: none unless given — the message\n * is the point.\n */\n title?: ReactNode\n /**\n * Leading icon — a known `IconName`, any node, or `false`. Block: defaults to `Danger` (or `CloudCross` when\n * the request never got a response — an explicit `status: 0` / network error code), tinted `error`. Alert:\n * the alert's own error icon unless overridden.\n */\n icon?: IconName | ReactNode | false\n /** Adds a \"Try Again\" button that calls this (e.g. a query's `refetch`). */\n onRetry?: () => void\n /**\n * The retry is running (e.g. `query.isFetching`) — the \"Try Again\" button shows its loader and is disabled,\n * so a slow refetch doesn't look like a dead click. Defaults to `false`.\n */\n retrying?: boolean\n /** Retry button label. Defaults to the localized \"Try Again\". */\n retryLabel?: ReactNode\n /**\n * Show a collapsible technical details panel (stack / raw error). `'dev'` (default) shows it only in\n * development builds; `true` always; `false` never.\n */\n showDetails?: boolean | 'dev'\n /** The inline variant — small, no hero pattern — for inside a table, card or panel. Defaults to `false`. */\n compact?: boolean\n /**\n * The server's trace id, shown under the message with a copy button (it matches a report to the server\n * log). Defaults to the one on `error` (`error.traceId` / `error.response.data.traceId`); `false` hides it.\n */\n traceId?: string | false\n /**\n * Per-field validation messages (`{ field: message }`), listed as the description when there's no explicit\n * `description`. Defaults to the ones on `error` (`getErrorFieldErrors`: `error.fieldErrors` — an object, a\n * method or a `{ field, message }[]` —, `error.details`, `error.response.data.errors`); `false` hides them. In a form, put them on the inputs instead.\n */\n fieldErrors?: Record<string, string> | false\n /**\n * Labels for the field-error keys (`{ newPassword: 'New Password' }`). A key without one is shown humanized\n * and Title Cased (`newPassword` / `new_password` → \"New Password\"; a dotted path keeps its last segment).\n */\n fieldLabels?: Record<string, ReactNode>\n}\n\n/**\n * The \"loading failed\" counterpart of `EmptyState` — a semantic preset over it: an `error`-tinted\n * `Danger` puck, a localized \"Something Went Wrong\" title, the failure's own message as the description\n * (extracted from an `Error`, a string, an axios-style `response.data.message`, a `{ message }`, or a raw\n * `{ status }` response → \"Request failed (404)\"), an optional **Try Again** button (`onRetry`), and a\n * developer-only details panel with the stack (`showDetails`, default `'dev'`). `compact` is the inline\n * variant for a table / card. The server's `traceId` (copyable) and a 400's per-field `fieldErrors` are shown\n * when the error carries them. `variant=\"alert\"` renders the same data as a one-line `Alert` banner — for a\n * failed save above a form or in a modal. `retrying` puts the retry button in its loading state. Announced to\n * assistive tech once (`role=\"alert\"`).\n * `forwardRef` to the root; any other `EmptyState` prop (`size`, `pattern`, `action`, …) passes through.\n */\nexport const ErrorState = forwardRef<HTMLDivElement, ErrorStateProps>(function ErrorState(\n {\n error,\n variant = 'block',\n title,\n description,\n icon,\n onRetry,\n retrying = false,\n retryLabel,\n showDetails = 'dev',\n compact = false,\n traceId: traceIdProp,\n fieldErrors: fieldErrorsProp,\n fieldLabels,\n size,\n pattern,\n action,\n className,\n children,\n ...props\n },\n ref,\n) {\n const t = useT()\n const message = getErrorMessage(error, (status) => t('errorState.requestFailed', { status }))\n const traceId = traceIdProp === false ? undefined : (traceIdProp ?? getErrorTraceId(error))\n const fieldErrors =\n fieldErrorsProp === false ? undefined : (fieldErrorsProp ?? getErrorFieldErrors(error))\n const fieldErrorList =\n fieldErrors && Object.keys(fieldErrors).length > 0 ? (\n <ul className={styles.fieldErrors}>\n {Object.entries(fieldErrors).map(([field, msg]) => (\n <li key={field}>\n <span className={styles.field}>{fieldLabels?.[field] ?? humanizeField(field)}</span> —{' '}\n {msg}\n </li>\n ))}\n </ul>\n ) : undefined\n const body = description ?? fieldErrorList ?? message ?? t('errorState.description')\n const traceLabel = traceId != null && (\n <>\n {t('errorState.traceId')}: <code className={styles.traceId}>{traceId}</code>\n </>\n )\n\n // ── alert: a one-line banner for a failed save above a form / in a modal ──\n if (variant === 'alert') {\n const alertActions =\n traceId != null || onRetry != null || action != null ? (\n <span className={styles.alertActions}>\n {traceId != null && <CopyButton value={traceId} size=\"sm\" variant=\"text\" color=\"error\" />}\n {onRetry != null && (\n <Button\n size=\"sm\"\n variant=\"text\"\n color=\"error\"\n loading={retrying}\n disabled={retrying}\n onClick={onRetry}\n >\n {retryLabel ?? t('errorState.retry')}\n </Button>\n )}\n {action}\n </span>\n ) : undefined\n return (\n <Alert\n ref={ref}\n color=\"error\"\n icon={icon}\n action={alertActions}\n className={clsx(styles.alertVariant, className)}\n {...props}\n >\n {title != null && <span className={styles.alertTitle}>{title}</span>}\n <span className={styles.alertBody}>{body}</span>\n {traceLabel && <span className={styles.alertTrace}>{traceLabel}</span>}\n {children}\n </Alert>\n )\n }\n\n // ── block ──\n // the trace id leads the developer panel too (it's what matches the server log)\n const rawDetails = (showDetails === 'dev' ? isDev() : showDetails)\n ? getErrorDetails(error)\n : undefined\n const details =\n rawDetails != null && traceId != null\n ? `${t('errorState.traceId')}: ${traceId}\\n\\n${rawDetails}`\n : rawDetails\n\n const retry =\n onRetry != null ? (\n <Button\n size=\"sm\"\n variant=\"outlined\"\n color=\"primary\"\n startIcon={<Icon name=\"RefreshRight\" />}\n loading={retrying}\n disabled={retrying}\n onClick={onRetry}\n >\n {retryLabel ?? t('errorState.retry')}\n </Button>\n ) : null\n\n return (\n <EmptyState\n ref={ref}\n // one announcement, assertive: an error is what the user needs to know now (role=\"alert\" already\n // implies aria-live=\"assertive\" — pairing it with \"polite\" was contradictory)\n role=\"alert\"\n color=\"error\"\n icon={icon === undefined ? (isNetworkError(error) ? 'CloudCross' : 'Danger') : icon}\n title={title ?? t('errorState.title')}\n // a 400's message is the generic \"validation errors occurred\" — the per-field list is the useful part\n description={body}\n size={size ?? (compact ? 'sm' : 'md')}\n pattern={pattern ?? !compact}\n action={\n retry || action ? (\n <span className={styles.actions}>\n {retry}\n {action}\n </span>\n ) : undefined\n }\n className={clsx(styles.errorState, compact && styles.compact, className)}\n {...props}\n >\n {traceId != null && (\n <span className={styles.trace}>\n <span>{traceLabel}</span>\n <CopyButton value={traceId} size=\"sm\" variant=\"text\" color=\"primary\" />\n </span>\n )}\n {details != null && (\n <details className={styles.details}>\n <summary className={styles.summary}>{t('errorState.details')}</summary>\n <pre className={styles.pre}>{details}</pre>\n </details>\n )}\n {children}\n </EmptyState>\n )\n})\n"],"names":["ErrorState","forwardRef","error","variant","title","description","icon","onRetry","retrying","retryLabel","showDetails","compact","traceIdProp","fieldErrorsProp","fieldLabels","size","pattern","action","className","children","props","ref","t","useT","message","getErrorMessage","status","traceId","getErrorTraceId","fieldErrors","getErrorFieldErrors","fieldErrorList","jsx","styles","field","msg","jsxs","humanizeField","body","traceLabel","Fragment","alertActions","CopyButton","Button","Alert","clsx","rawDetails","isDev","getErrorDetails","details","retry","Icon","EmptyState","isNetworkError"],"mappings":"22BA8FaA,GAAaC,EAAAA,WAA4C,SACpE,CACE,MAAAC,EACA,QAAAC,EAAU,QACV,MAAAC,EACA,YAAAC,EACA,KAAAC,EACA,QAAAC,EACA,SAAAC,EAAW,GACX,WAAAC,EACA,YAAAC,EAAc,MACd,QAAAC,EAAU,GACV,QAASC,EACT,YAAaC,EACb,YAAAC,EACA,KAAAC,EACA,QAAAC,EACA,OAAAC,EACA,UAAAC,EACA,SAAAC,EACA,GAAGC,CACL,EACAC,EACA,CACA,MAAMC,EAAIC,EAAAA,KAAA,EACJC,EAAUC,kBAAgBvB,EAAQwB,GAAWJ,EAAE,2BAA4B,CAAE,OAAAI,CAAA,CAAQ,CAAC,EACtFC,EAAUf,IAAgB,GAAQ,OAAaA,GAAegB,EAAAA,gBAAgB1B,CAAK,EACnF2B,EACJhB,IAAoB,GAAQ,OAAaA,GAAmBiB,EAAAA,oBAAoB5B,CAAK,EACjF6B,EACJF,GAAe,OAAO,KAAKA,CAAW,EAAE,OAAS,EAC/CG,EAAAA,IAAC,KAAA,CAAG,UAAWC,EAAO,YACnB,SAAA,OAAO,QAAQJ,CAAW,EAAE,IAAI,CAAC,CAACK,EAAOC,CAAG,IAC3CC,EAA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O,QACzB,SAAA,CAAAD,MAAC,WAAQ,UAAWC,EAAO,QAAU,SAAAX,EAAE,oBAAoB,EAAE,EAC7DU,EAAAA,IAAC,MAAA,CAAI,UAAWC,EAAO,IAAM,SAAAgB,CAAA,CAAQ,CAAA,EACvC,EAED9B,CAAA,CAAA,CAAA,CAGP,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx as a, jsxs as s, Fragment as O } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as q } from "react";
|
|
3
|
+
import { clsx as B } from "clsx";
|
|
4
|
+
import { A as M } from "./Alert-LJDrtkJy.js";
|
|
5
|
+
import { B as z } from "./Button-PBZnkRNn.js";
|
|
6
|
+
import { C } from "./CopyButton-B_mYxcXV.js";
|
|
7
|
+
import { E as G } from "./EmptyState-BEVEGcLx.js";
|
|
8
|
+
import { I as H } from "./Icon-CGQ5yGSZ.js";
|
|
9
|
+
import { b as J, d as K, a as Q, h as U, f as W, g as X, i as Y } from "./errorMessage-C83fB2h5.js";
|
|
10
|
+
import { a as Z } from "./ConfigProvider-tvLbKiqu.js";
|
|
11
|
+
const R = "_errorState_19ba2_4", P = "_actions_19ba2_9", L = "_fieldErrors_19ba2_18", rr = "_field_19ba2_18", ar = "_trace_19ba2_32", er = "_traceId_19ba2_39", tr = "_compact_19ba2_45", sr = "_details_19ba2_50", lr = "_summary_19ba2_56", or = "_pre_19ba2_63", cr = "_alertVariant_19ba2_80", nr = "_alertTitle_19ba2_83", ir = "_alertBody_19ba2_87", dr = "_alertTrace_19ba2_92", mr = "_alertActions_19ba2_99", r = {
|
|
12
|
+
errorState: R,
|
|
13
|
+
actions: P,
|
|
14
|
+
fieldErrors: L,
|
|
15
|
+
field: rr,
|
|
16
|
+
trace: ar,
|
|
17
|
+
traceId: er,
|
|
18
|
+
compact: tr,
|
|
19
|
+
details: sr,
|
|
20
|
+
summary: lr,
|
|
21
|
+
pre: or,
|
|
22
|
+
alertVariant: cr,
|
|
23
|
+
alertTitle: nr,
|
|
24
|
+
alertBody: ir,
|
|
25
|
+
alertTrace: dr,
|
|
26
|
+
alertActions: mr
|
|
27
|
+
}, Ir = q(function({
|
|
28
|
+
error: o,
|
|
29
|
+
variant: k = "block",
|
|
30
|
+
title: d,
|
|
31
|
+
description: j,
|
|
32
|
+
icon: m,
|
|
33
|
+
onRetry: c,
|
|
34
|
+
retrying: n = !1,
|
|
35
|
+
retryLabel: b,
|
|
36
|
+
showDetails: E = "dev",
|
|
37
|
+
compact: _ = !1,
|
|
38
|
+
traceId: v,
|
|
39
|
+
fieldErrors: S,
|
|
40
|
+
fieldLabels: u,
|
|
41
|
+
size: F,
|
|
42
|
+
pattern: V,
|
|
43
|
+
action: i,
|
|
44
|
+
className: N,
|
|
45
|
+
children: y,
|
|
46
|
+
...I
|
|
47
|
+
}, g) {
|
|
48
|
+
const t = Z(), D = J(o, (l) => t("errorState.requestFailed", { status: l })), e = v === !1 ? void 0 : v ?? K(o), p = S === !1 ? void 0 : S ?? Q(o), $ = p && Object.keys(p).length > 0 ? /* @__PURE__ */ a("ul", { className: r.fieldErrors, children: Object.entries(p).map(([l, w]) => /* @__PURE__ */ s("li", { children: [
|
|
49
|
+
/* @__PURE__ */ a("span", { className: r.field, children: (u == null ? void 0 : u[l]) ?? U(l) }),
|
|
50
|
+
" —",
|
|
51
|
+
" ",
|
|
52
|
+
w
|
|
53
|
+
] }, l)) }) : void 0, T = j ?? $ ?? D ?? t("errorState.description"), f = e != null && /* @__PURE__ */ s(O, { children: [
|
|
54
|
+
t("errorState.traceId"),
|
|
55
|
+
": ",
|
|
56
|
+
/* @__PURE__ */ a("code", { className: r.traceId, children: e })
|
|
57
|
+
] });
|
|
58
|
+
if (k === "alert") {
|
|
59
|
+
const l = e != null || c != null || i != null ? /* @__PURE__ */ s("span", { className: r.alertActions, children: [
|
|
60
|
+
e != null && /* @__PURE__ */ a(C, { value: e, size: "sm", variant: "text", color: "error" }),
|
|
61
|
+
c != null && /* @__PURE__ */ a(
|
|
62
|
+
z,
|
|
63
|
+
{
|
|
64
|
+
size: "sm",
|
|
65
|
+
variant: "text",
|
|
66
|
+
color: "error",
|
|
67
|
+
loading: n,
|
|
68
|
+
disabled: n,
|
|
69
|
+
onClick: c,
|
|
70
|
+
children: b ?? t("errorState.retry")
|
|
71
|
+
}
|
|
72
|
+
),
|
|
73
|
+
i
|
|
74
|
+
] }) : void 0;
|
|
75
|
+
return /* @__PURE__ */ s(
|
|
76
|
+
M,
|
|
77
|
+
{
|
|
78
|
+
ref: g,
|
|
79
|
+
color: "error",
|
|
80
|
+
icon: m,
|
|
81
|
+
action: l,
|
|
82
|
+
className: B(r.alertVariant, N),
|
|
83
|
+
...I,
|
|
84
|
+
children: [
|
|
85
|
+
d != null && /* @__PURE__ */ a("span", { className: r.alertTitle, children: d }),
|
|
86
|
+
/* @__PURE__ */ a("span", { className: r.alertBody, children: T }),
|
|
87
|
+
f && /* @__PURE__ */ a("span", { className: r.alertTrace, children: f }),
|
|
88
|
+
y
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const h = (E === "dev" ? W() : E) ? X(o) : void 0, x = h != null && e != null ? `${t("errorState.traceId")}: ${e}
|
|
94
|
+
|
|
95
|
+
${h}` : h, A = c != null ? /* @__PURE__ */ a(
|
|
96
|
+
z,
|
|
97
|
+
{
|
|
98
|
+
size: "sm",
|
|
99
|
+
variant: "outlined",
|
|
100
|
+
color: "primary",
|
|
101
|
+
startIcon: /* @__PURE__ */ a(H, { name: "RefreshRight" }),
|
|
102
|
+
loading: n,
|
|
103
|
+
disabled: n,
|
|
104
|
+
onClick: c,
|
|
105
|
+
children: b ?? t("errorState.retry")
|
|
106
|
+
}
|
|
107
|
+
) : null;
|
|
108
|
+
return /* @__PURE__ */ s(
|
|
109
|
+
G,
|
|
110
|
+
{
|
|
111
|
+
ref: g,
|
|
112
|
+
role: "alert",
|
|
113
|
+
color: "error",
|
|
114
|
+
icon: m === void 0 ? Y(o) ? "CloudCross" : "Danger" : m,
|
|
115
|
+
title: d ?? t("errorState.title"),
|
|
116
|
+
description: T,
|
|
117
|
+
size: F ?? (_ ? "sm" : "md"),
|
|
118
|
+
pattern: V ?? !_,
|
|
119
|
+
action: A || i ? /* @__PURE__ */ s("span", { className: r.actions, children: [
|
|
120
|
+
A,
|
|
121
|
+
i
|
|
122
|
+
] }) : void 0,
|
|
123
|
+
className: B(r.errorState, _ && r.compact, N),
|
|
124
|
+
...I,
|
|
125
|
+
children: [
|
|
126
|
+
e != null && /* @__PURE__ */ s("span", { className: r.trace, children: [
|
|
127
|
+
/* @__PURE__ */ a("span", { children: f }),
|
|
128
|
+
/* @__PURE__ */ a(C, { value: e, size: "sm", variant: "text", color: "primary" })
|
|
129
|
+
] }),
|
|
130
|
+
x != null && /* @__PURE__ */ s("details", { className: r.details, children: [
|
|
131
|
+
/* @__PURE__ */ a("summary", { className: r.summary, children: t("errorState.details") }),
|
|
132
|
+
/* @__PURE__ */ a("pre", { className: r.pre, children: x })
|
|
133
|
+
] }),
|
|
134
|
+
y
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
export {
|
|
140
|
+
Ir as E
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=ErrorState-DKhZ4aJh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorState-DKhZ4aJh.js","sources":["../src/components/ErrorState/ErrorState.tsx"],"sourcesContent":["import { forwardRef, type ReactNode } from 'react'\nimport { clsx } from 'clsx'\nimport { useT } from '../../theme'\nimport { Alert } from '../Alert'\nimport { Button } from '../Button'\nimport { CopyButton } from '../CopyButton'\nimport { EmptyState, type EmptyStateProps } from '../EmptyState'\nimport { Icon } from '../Icon'\nimport type { IconName } from '../../icons/names'\nimport {\n getErrorDetails,\n getErrorFieldErrors,\n getErrorMessage,\n getErrorTraceId,\n humanizeField,\n isNetworkError,\n isDev,\n} from './errorMessage'\nimport styles from './ErrorState.module.css'\n\nexport type ErrorStateVariant = 'block' | 'alert'\n\nexport interface ErrorStateProps extends Omit<EmptyStateProps, 'icon' | 'title' | 'color'> {\n /**\n * The shape. `'block'` (default) — the `EmptyState`-style block (puck, title, centred message), for a read\n * that failed where its data would be. `'alert'` — a one-line red `Alert` banner for a **failed save**\n * above a form or in a modal, where the form stays on screen: the message (no default title), a muted\n * trace id line, and the copy / retry / `action` buttons in the alert's action slot. `showDetails`,\n * `compact` and `pattern` don't apply to `'alert'`.\n */\n variant?: ErrorStateVariant\n /**\n * What failed — an `Error`, a string, an axios-style error, a `{ message }` or a raw `{ status }`\n * response. Its message becomes the description (unless `description` is given) and its stack feeds\n * the details panel.\n */\n error?: unknown\n /**\n * Heading. Block: defaults to the localized \"Something Went Wrong\". Alert: none unless given — the message\n * is the point.\n */\n title?: ReactNode\n /**\n * Leading icon — a known `IconName`, any node, or `false`. Block: defaults to `Danger` (or `CloudCross` when\n * the request never got a response — an explicit `status: 0` / network error code), tinted `error`. Alert:\n * the alert's own error icon unless overridden.\n */\n icon?: IconName | ReactNode | false\n /** Adds a \"Try Again\" button that calls this (e.g. a query's `refetch`). */\n onRetry?: () => void\n /**\n * The retry is running (e.g. `query.isFetching`) — the \"Try Again\" button shows its loader and is disabled,\n * so a slow refetch doesn't look like a dead click. Defaults to `false`.\n */\n retrying?: boolean\n /** Retry button label. Defaults to the localized \"Try Again\". */\n retryLabel?: ReactNode\n /**\n * Show a collapsible technical details panel (stack / raw error). `'dev'` (default) shows it only in\n * development builds; `true` always; `false` never.\n */\n showDetails?: boolean | 'dev'\n /** The inline variant — small, no hero pattern — for inside a table, card or panel. Defaults to `false`. */\n compact?: boolean\n /**\n * The server's trace id, shown under the message with a copy button (it matches a report to the server\n * log). Defaults to the one on `error` (`error.traceId` / `error.response.data.traceId`); `false` hides it.\n */\n traceId?: string | false\n /**\n * Per-field validation messages (`{ field: message }`), listed as the description when there's no explicit\n * `description`. Defaults to the ones on `error` (`getErrorFieldErrors`: `error.fieldErrors` — an object, a\n * method or a `{ field, message }[]` —, `error.details`, `error.response.data.errors`); `false` hides them. In a form, put them on the inputs instead.\n */\n fieldErrors?: Record<string, string> | false\n /**\n * Labels for the field-error keys (`{ newPassword: 'New Password' }`). A key without one is shown humanized\n * and Title Cased (`newPassword` / `new_password` → \"New Password\"; a dotted path keeps its last segment).\n */\n fieldLabels?: Record<string, ReactNode>\n}\n\n/**\n * The \"loading failed\" counterpart of `EmptyState` — a semantic preset over it: an `error`-tinted\n * `Danger` puck, a localized \"Something Went Wrong\" title, the failure's own message as the description\n * (extracted from an `Error`, a string, an axios-style `response.data.message`, a `{ message }`, or a raw\n * `{ status }` response → \"Request failed (404)\"), an optional **Try Again** button (`onRetry`), and a\n * developer-only details panel with the stack (`showDetails`, default `'dev'`). `compact` is the inline\n * variant for a table / card. The server's `traceId` (copyable) and a 400's per-field `fieldErrors` are shown\n * when the error carries them. `variant=\"alert\"` renders the same data as a one-line `Alert` banner — for a\n * failed save above a form or in a modal. `retrying` puts the retry button in its loading state. Announced to\n * assistive tech once (`role=\"alert\"`).\n * `forwardRef` to the root; any other `EmptyState` prop (`size`, `pattern`, `action`, …) passes through.\n */\nexport const ErrorState = forwardRef<HTMLDivElement, ErrorStateProps>(function ErrorState(\n {\n error,\n variant = 'block',\n title,\n description,\n icon,\n onRetry,\n retrying = false,\n retryLabel,\n showDetails = 'dev',\n compact = false,\n traceId: traceIdProp,\n fieldErrors: fieldErrorsProp,\n fieldLabels,\n size,\n pattern,\n action,\n className,\n children,\n ...props\n },\n ref,\n) {\n const t = useT()\n const message = getErrorMessage(error, (status) => t('errorState.requestFailed', { status }))\n const traceId = traceIdProp === false ? undefined : (traceIdProp ?? getErrorTraceId(error))\n const fieldErrors =\n fieldErrorsProp === false ? undefined : (fieldErrorsProp ?? getErrorFieldErrors(error))\n const fieldErrorList =\n fieldErrors && Object.keys(fieldErrors).length > 0 ? (\n <ul className={styles.fieldErrors}>\n {Object.entries(fieldErrors).map(([field, msg]) => (\n <li key={field}>\n <span className={styles.field}>{fieldLabels?.[field] ?? humanizeField(field)}</span> —{' '}\n {msg}\n </li>\n ))}\n </ul>\n ) : undefined\n const body = description ?? fieldErrorList ?? message ?? t('errorState.description')\n const traceLabel = traceId != null && (\n <>\n {t('errorState.traceId')}: <code className={styles.traceId}>{traceId}</code>\n </>\n )\n\n // ── alert: a one-line banner for a failed save above a form / in a modal ──\n if (variant === 'alert') {\n const alertActions =\n traceId != null || onRetry != null || action != null ? (\n <span className={styles.alertActions}>\n {traceId != null && <CopyButton value={traceId} size=\"sm\" variant=\"text\" color=\"error\" />}\n {onRetry != null && (\n <Button\n size=\"sm\"\n variant=\"text\"\n color=\"error\"\n loading={retrying}\n disabled={retrying}\n onClick={onRetry}\n >\n {retryLabel ?? t('errorState.retry')}\n </Button>\n )}\n {action}\n </span>\n ) : undefined\n return (\n <Alert\n ref={ref}\n color=\"error\"\n icon={icon}\n action={alertActions}\n className={clsx(styles.alertVariant, className)}\n {...props}\n >\n {title != null && <span className={styles.alertTitle}>{title}</span>}\n <span className={styles.alertBody}>{body}</span>\n {traceLabel && <span className={styles.alertTrace}>{traceLabel}</span>}\n {children}\n </Alert>\n )\n }\n\n // ── block ──\n // the trace id leads the developer panel too (it's what matches the server log)\n const rawDetails = (showDetails === 'dev' ? isDev() : showDetails)\n ? getErrorDetails(error)\n : undefined\n const details =\n rawDetails != null && traceId != null\n ? `${t('errorState.traceId')}: ${traceId}\\n\\n${rawDetails}`\n : rawDetails\n\n const retry =\n onRetry != null ? (\n <Button\n size=\"sm\"\n variant=\"outlined\"\n color=\"primary\"\n startIcon={<Icon name=\"RefreshRight\" />}\n loading={retrying}\n disabled={retrying}\n onClick={onRetry}\n >\n {retryLabel ?? t('errorState.retry')}\n </Button>\n ) : null\n\n return (\n <EmptyState\n ref={ref}\n // one announcement, assertive: an error is what the user needs to know now (role=\"alert\" already\n // implies aria-live=\"assertive\" — pairing it with \"polite\" was contradictory)\n role=\"alert\"\n color=\"error\"\n icon={icon === undefined ? (isNetworkError(error) ? 'CloudCross' : 'Danger') : icon}\n title={title ?? t('errorState.title')}\n // a 400's message is the generic \"validation errors occurred\" — the per-field list is the useful part\n description={body}\n size={size ?? (compact ? 'sm' : 'md')}\n pattern={pattern ?? !compact}\n action={\n retry || action ? (\n <span className={styles.actions}>\n {retry}\n {action}\n </span>\n ) : undefined\n }\n className={clsx(styles.errorState, compact && styles.compact, className)}\n {...props}\n >\n {traceId != null && (\n <span className={styles.trace}>\n <span>{traceLabel}</span>\n <CopyButton value={traceId} size=\"sm\" variant=\"text\" color=\"primary\" />\n </span>\n )}\n {details != null && (\n <details className={styles.details}>\n <summary className={styles.summary}>{t('errorState.details')}</summary>\n <pre className={styles.pre}>{details}</pre>\n </details>\n )}\n {children}\n </EmptyState>\n )\n})\n"],"names":["ErrorState","forwardRef","error","variant","title","description","icon","onRetry","retrying","retryLabel","showDetails","compact","traceIdProp","fieldErrorsProp","fieldLabels","size","pattern","action","className","children","props","ref","useT","message","getErrorMessage","status","traceId","getErrorTraceId","fieldErrors","getErrorFieldErrors","fieldErrorList","jsx","styles","field","msg","jsxs","humanizeField","body","traceLabel","Fragment","alertActions","CopyButton","Button","Alert","clsx","rawDetails","isDev","getErrorDetails","details","retry","Icon","EmptyState","isNetworkError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;GA8FaA,KAAaC,EAA4C,SACpE;AAAA,EACE,OAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,YAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,SAAAC,IAAU;AAAA,EACV,SAASC;AAAA,EACT,aAAaC;AAAA,EACb,aAAAC;AAAA,EACA,MAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,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A,IAAA;AAAA,MACC,KAAA9B;AAAA,MAGA,MAAK;AAAA,MACL,OAAM;AAAA,MACN,MAAMf,MAAS,SAAa8C,EAAelD,CAAK,IAAI,eAAe,WAAYI;AAAA,MAC/E,OAAOF,KAAS,EAAE,kBAAkB;AAAA,MAEpC,aAAaiC;AAAA,MACb,MAAMtB,MAASJ,IAAU,OAAO;AAAA,MAChC,SAASK,KAAW,CAACL;AAAA,MACrB,QACEsC,KAAShC,sBACN,QAAA,EAAK,WAAWe,EAAO,SACrB,UAAA;AAAA,QAAAiB;AAAA,QACAhC;AAAA,MAAA,EAAA,CACH,IACE;AAAA,MAEN,WAAW2B,EAAKZ,EAAO,YAAYrB,KAAWqB,EAAO,SAASd,CAAS;AAAA,MACtE,GAAGE;AAAA,MAEH,UAAA;AAAA,QAAAM,KAAW,QACV,gBAAAS,EAAC,QAAA,EAAK,WAAWH,EAAO,OACtB,UAAA;AAAA,UAAA,gBAAAD,EAAC,UAAM,UAAAO,EAAA,CAAW;AAAA,UAClB,gBAAAP,EAACU,KAAW,OAAOf,GAAS,MAAK,MAAK,SAAQ,QAAO,OAAM,UAAA,CAAU;AAAA,QAAA,GACvE;AAAA,QAEDsB,KAAW,QACV,gBAAAb,EAAC,WAAA,EAAQ,WAAWH,EAAO,SACzB,UAAA;AAAA,UAAA,gBAAAD,EAAC,aAAQ,WAAWC,EAAO,SAAU,UAAA,EAAE,oBAAoB,GAAE;AAAA,UAC7D,gBAAAD,EAAC,OAAA,EAAI,WAAWC,EAAO,KAAM,UAAAgB,EAAA,CAAQ;AAAA,QAAA,GACvC;AAAA,QAED7B;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const o=require("react/jsx-runtime"),u=require("react"),M=require("clsx"),S=require("./Avatar-CQ--wGWS.cjs"),A=require("./IconButton-
|
|
2
|
-
//# sourceMappingURL=FileCard-
|
|
1
|
+
"use strict";const o=require("react/jsx-runtime"),u=require("react"),M=require("clsx"),S=require("./Avatar-CQ--wGWS.cjs"),A=require("./IconButton-BVrO9TBP.cjs"),O=require("./Icon-BUP5_kRs.cjs"),L=require("./Typography-B6ASPrzT.cjs"),$=require("./ConfigProvider-CVLHPXQm.cjs"),V="_fileCard_kpeb5_3",G="_avatar_kpeb5_24",R="_body_kpeb5_29",H="_name_kpeb5_38",K="_nameBase_kpeb5_45",P="_nameExt_kpeb5_51",U="_type_kpeb5_57",W="_download_kpeb5_61",X="_sm_kpeb5_66",z="_md_kpeb5_77",J="_lg_kpeb5_81",s={fileCard:V,avatar:G,body:R,name:H,nameBase:K,nameExt:P,type:U,download:W,sm:X,md:z,lg:J},Q=new Set(["png","jpg","jpeg","webp","svg","gif","avif","bmp","ico","heic"]),Y={pdf:"DocumentText",doc:"DocumentText",docx:"DocumentText",txt:"DocumentText",rtf:"DocumentText",md:"DocumentText",csv:"DocumentText",xls:"DocumentText",xlsx:"DocumentText",json:"DocumentCode",xml:"DocumentCode",zip:"Folder",rar:"Folder","7z":"Folder",mp4:"VideoSquare",mov:"VideoSquare",webm:"VideoSquare",mp3:"MusicSquare",wav:"MusicSquare"};function Z(n,e){const t=n.lastIndexOf(".");return t>0&&n.length-t<=7?n.slice(t+1).toLowerCase():e&&e.includes("/")?e.slice(e.indexOf("/")+1).toLowerCase():""}function ee(n){const e=n.lastIndexOf(".");return e>0&&n.length-e<=7?{base:n.slice(0,e),ext:n.slice(e)}:{base:n,ext:""}}function g(n){if(!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB","TB"];let t=n/1024,a=0;for(;t>=1024&&a<e.length-1;)t/=1024,a+=1;return`${t<10?t.toFixed(1):Math.round(t)} ${e[a]}`}const te=u.forwardRef(function({name:e,src:t,type:a,image:v,fileSize:c,fetchSize:m=!1,meta:C,color:x="accent",size:d="md",downloadable:T=!0,onDownload:i,className:j,style:q,...w},k){const B=$.useT(),l=Z(e,a),f=v??((a==null?void 0:a.startsWith("image/"))||Q.has(l)),{base:D,ext:_}=ee(e),[p,N]=u.useState(null);u.useEffect(()=>{if(!m||c!=null||!t||typeof fetch>"u")return;let r=!1;return fetch(t,{method:"HEAD"}).then(y=>{const b=y.headers.get("content-length");!r&&b&&N(Number(b))}).catch(()=>{}),()=>{r=!0}},[m,c,t]);const E=c!=null?typeof c=="number"?g(c):c:p!=null?g(p):"",I=[l?l.toUpperCase():"",E].filter(Boolean).join(" · "),h=C??(I||null),F=()=>{if(i)return i();if(!t)return;const r=document.createElement("a");r.href=t,r.download=e,r.rel="noopener",r.click()};return o.jsxs("div",{ref:k,className:M.clsx(s.fileCard,s[d],j),style:{"--tz-btn-rgb":`var(--tz-color-${x}-rgb)`,...q},...w,children:[o.jsx(S.Avatar,{className:s.avatar,src:f?t:void 0,icon:f?void 0:Y[l]??"Document",name:e,shape:"square",size:d,color:x}),o.jsxs("div",{className:s.body,children:[o.jsxs("span",{className:s.name,title:e,children:[o.jsx("span",{className:s.nameBase,children:D}),_&&o.jsx("span",{className:s.nameExt,children:_})]}),h!=null&&o.jsx(L.Typography,{as:"span",variant:"bodySmall",color:"muted",uppercase:!0,className:s.type,children:h})]}),T&&(t||i)&&o.jsx(A.IconButton,{variant:"filled",size:d==="lg"?"md":"sm",className:s.download,"aria-label":B("fileCard.download",{name:e}),onClick:F,children:o.jsx(O.Icon,{name:"ImportArrow"})})]})});exports.FileCard=te;
|
|
2
|
+
//# sourceMappingURL=FileCard-B3dfdTVN.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileCard-Bjqsgi7S.cjs","sources":["../src/components/FileCard/FileCard.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Avatar, type AvatarSize } from '../Avatar'\nimport { IconButton } from '../IconButton'\nimport { Icon } from '../Icon'\nimport { Typography } from '../Typography'\nimport type { IconName } from '../../icons/names'\nimport styles from './FileCard.module.css'\n\nexport type FileCardSize = AvatarSize\n\nconst IMAGE_EXTS = new Set([\n 'png',\n 'jpg',\n 'jpeg',\n 'webp',\n 'svg',\n 'gif',\n 'avif',\n 'bmp',\n 'ico',\n 'heic',\n])\n\n// a leading icon per file family (non-image); everything else gets the generic document icon\nconst FILE_ICONS: Record<string, IconName> = {\n pdf: 'DocumentText',\n doc: 'DocumentText',\n docx: 'DocumentText',\n txt: 'DocumentText',\n rtf: 'DocumentText',\n md: 'DocumentText',\n csv: 'DocumentText',\n xls: 'DocumentText',\n xlsx: 'DocumentText',\n json: 'DocumentCode',\n xml: 'DocumentCode',\n zip: 'Folder',\n rar: 'Folder',\n '7z': 'Folder',\n mp4: 'VideoSquare',\n mov: 'VideoSquare',\n webm: 'VideoSquare',\n mp3: 'MusicSquare',\n wav: 'MusicSquare',\n}\n\n/** The lowercased extension from a file name, else the subtype from a MIME `type` (`image/png` → `png`). */\nfunction extensionOf(name: string, type?: string): string {\n const dot = name.lastIndexOf('.')\n if (dot > 0 && name.length - dot <= 7) return name.slice(dot + 1).toLowerCase()\n if (type && type.includes('/')) return type.slice(type.indexOf('/') + 1).toLowerCase()\n return ''\n}\n\n/** Split `report.pdf` into `{ base: 'report', ext: '.pdf' }` so the base can ellipsize and the type stays. */\nfunction splitName(name: string): { base: string; ext: string } {\n const dot = name.lastIndexOf('.')\n return dot > 0 && name.length - dot <= 7\n ? { base: name.slice(0, dot), ext: name.slice(dot) }\n : { base: name, ext: '' }\n}\n\n/** Human-readable byte size — `2411724` → `\"2.3 MB\"`. */\nfunction formatBytes(bytes: number): string {\n if (!Number.isFinite(bytes) || bytes < 0) return ''\n if (bytes < 1024) return `${bytes} B`\n const units = ['KB', 'MB', 'GB', 'TB']\n let value = bytes / 1024\n let i = 0\n while (value >= 1024 && i < units.length - 1) {\n value /= 1024\n i += 1\n }\n return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[i]}`\n}\n\nexport interface FileCardProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'color'> {\n /** File name — shown middle-truncated (`test-file-na….pdf`) so the extension always stays visible. */\n name: string\n /** File URL — the download target and, for an image, the thumbnail `src`. */\n src?: string\n /** File type — an extension (`'pdf'`) or MIME (`'image/png'`). Derived from `name` when omitted. */\n type?: string\n /** Force image vs. file rendering. Inferred from `type` / `name` / `src` when omitted. */\n image?: boolean\n /** File size — a **bytes** number (auto-formatted to `\"2.3 MB\"`) or a preformatted string. Shown after the type. */\n fileSize?: number | string\n /**\n * When no `fileSize` is given, fetch it from `src` via a `HEAD` request (reads `Content-Length`). Off\n * by default — it's a network call and needs CORS to expose the header; prefer passing `fileSize` from\n * the backend. Fails silently (no size shown) when unavailable.\n */\n fetchSize?: boolean\n /** Meta line under the name — overrides the derived `TYPE · size`. */\n meta?: ReactNode\n /** Theme token tinting the avatar / file-icon box. Defaults to `accent`. */\n color?: ThemeColor\n /** Size — scales the avatar, text and padding. Defaults to `md`. */\n size?: FileCardSize\n /** Show the download control (only when there's a `src` or `onDownload`). Defaults to `true`. */\n downloadable?: boolean\n /** Custom download handler — replaces the default (a download of `src`). */\n onDownload?: () => void\n}\n\n/**\n * A compact, read-only **file card** for displaying a file that already exists (e.g. from the backend) —\n * an image or a document (`pdf` / `docx` / `csv` / `svg` / …). Shows a leading **`Avatar`** (the image\n * thumbnail via `src`, or a type-based file icon in a tinted square), the **name** middle-truncated so\n * the extension is never lost, the **type** underneath, and a **download** control. Simple to drop in —\n * pass `name` (+ `src` for the thumbnail/download). Not to be confused with `FileUploader` (which\n * *collects* files to upload); this only *displays* one. Token-only styling.\n *\n * @example\n * <FileCard name=\"annual-report.pdf\" src=\"/files/annual-report.pdf\" />\n * <FileCard name=\"avatar.png\" src={url} meta=\"240 KB\" />\n */\nexport const FileCard = forwardRef<HTMLDivElement, FileCardProps>(function FileCard(\n {\n name,\n src,\n type,\n image,\n fileSize,\n fetchSize = false,\n meta,\n color = 'accent',\n size = 'md',\n downloadable = true,\n onDownload,\n className,\n style,\n ...props\n },\n ref,\n) {\n const t = useT()\n const ext = extensionOf(name, type)\n const isImage = image ?? (type?.startsWith('image/') || IMAGE_EXTS.has(ext))\n const { base, ext: nameExt } = splitName(name)\n\n // optional auto size via a HEAD request (only when opted in and no explicit fileSize)\n const [fetchedSize, setFetchedSize] = useState<number | null>(null)\n useEffect(() => {\n if (!fetchSize || fileSize != null || !src || typeof fetch === 'undefined') return\n let cancelled = false\n fetch(src, { method: 'HEAD' })\n .then((res) => {\n const len = res.headers.get('content-length')\n if (!cancelled && len) setFetchedSize(Number(len))\n })\n .catch(() => {})\n return () => {\n cancelled = true\n }\n }, [fetchSize, fileSize, src])\n\n const sizeText =\n fileSize != null\n ? typeof fileSize === 'number'\n ? formatBytes(fileSize)\n : fileSize\n : fetchedSize != null\n ? formatBytes(fetchedSize)\n : ''\n // \"TYPE · 2.3 MB\" (either part optional) — overridden wholesale by `meta`\n const derivedMeta = [ext ? ext.toUpperCase() : '', sizeText].filter(Boolean).join(' · ')\n const metaLine = meta ?? (derivedMeta || null)\n\n const handleDownload = () => {\n if (onDownload) return onDownload()\n if (!src) return\n const a = document.createElement('a')\n a.href = src\n a.download = name\n a.rel = 'noopener'\n a.click()\n }\n\n return (\n <div\n ref={ref}\n className={clsx(styles.fileCard, styles[size], className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n {...props}\n >\n <Avatar\n className={styles.avatar}\n src={isImage ? src : undefined}\n icon={isImage ? undefined : (FILE_ICONS[ext] ?? 'Document')}\n name={name}\n shape=\"square\"\n size={size}\n color={color}\n />\n <div className={styles.body}>\n <span className={styles.name} title={name}>\n <span className={styles.nameBase}>{base}</span>\n {nameExt && <span className={styles.nameExt}>{nameExt}</span>}\n </span>\n {metaLine != null && (\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\" uppercase className={styles.type}>\n {metaLine}\n </Typography>\n )}\n </div>\n {downloadable && (src || onDownload) && (\n <IconButton\n variant=\"filled\"\n size={size === 'lg' ? 'md' : 'sm'}\n className={styles.download}\n aria-label={t('fileCard.download', { name })}\n onClick={handleDownload}\n >\n <Icon name=\"ImportArrow\" />\n </IconButton>\n )}\n </div>\n )\n})\n"],"names":["IMAGE_EXTS","FILE_ICONS","extensionOf","name","type","dot","splitName","formatBytes","bytes","units","value","i","FileCard","forwardRef","src","image","fileSize","fetchSize","meta","color","size","downloadable","onDownload","className","style","props","ref","t","useT","ext","isImage","base","nameExt","fetchedSize","setFetchedSize","useState","useEffect","cancelled","res","len","sizeText","derivedMeta","metaLine","handleDownload","a","jsxs","clsx","styles","jsx","Avatar","Typography","IconButton","Icon"],"mappings":"2kBAmBMA,MAAiB,IAAI,CACzB,MACA,MACA,OACA,OACA,MACA,MACA,OACA,MACA,MACA,MACF,CAAC,EAGKC,EAAuC,CAC3C,IAAK,eACL,IAAK,eACL,KAAM,eACN,IAAK,eACL,IAAK,eACL,GAAI,eACJ,IAAK,eACL,IAAK,eACL,KAAM,eACN,KAAM,eACN,IAAK,eACL,IAAK,SACL,IAAK,SACL,KAAM,SACN,IAAK,cACL,IAAK,cACL,KAAM,cACN,IAAK,cACL,IAAK,aACP,EAGA,SAASC,EAAYC,EAAcC,EAAuB,CACxD,MAAMC,EAAMF,EAAK,YAAY,GAAG,EAChC,OAAIE,EAAM,GAAKF,EAAK,OAASE,GAAO,EAAUF,EAAK,MAAME,EAAM,CAAC,EAAE,YAAA,EAC9DD,GAAQA,EAAK,SAAS,GAAG,EAAUA,EAAK,MAAMA,EAAK,QAAQ,GAAG,EAAI,CAAC,EAAE,YAAA,EAClE,EACT,CAGA,SAASE,GAAUH,EAA6C,CAC9D,MAAME,EAAMF,EAAK,YAAY,GAAG,EAChC,OAAOE,EAAM,GAAKF,EAAK,OAASE,GAAO,EACnC,CAAE,KAAMF,EAAK,MAAM,EAAGE,CAAG,EAAG,IAAKF,EAAK,MAAME,CAAG,GAC/C,CAAE,KA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,CAAA,EACxD,EACCU,GAAY,MACXM,MAACE,EAAAA,WAAA,CAAW,GAAG,OAAO,QAAQ,YAAY,MAAM,QAAQ,UAAS,GAAC,UAAWH,EAAO,KACjF,SAAAL,CAAA,CACH,CAAA,EAEJ,EACCrB,IAAiBP,GAAOQ,IACvB0B,EAAAA,IAACG,EAAAA,WAAA,CACC,QAAQ,SACR,KAAM/B,IAAS,KAAO,KAAO,KAC7B,UAAW2B,EAAO,SAClB,aAAYpB,EAAE,oBAAqB,CAAE,KAAAxB,EAAM,EAC3C,QAASwC,EAET,SAAAK,EAAAA,IAACI,EAAAA,KAAA,CAAK,KAAK,aAAA,CAAc,CAAA,CAAA,CAC3B,CAAA,CAAA,CAIR,CAAC"}
|
|
1
|
+
{"version":3,"file":"FileCard-B3dfdTVN.cjs","sources":["../src/components/FileCard/FileCard.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Avatar, type AvatarSize } from '../Avatar'\nimport { IconButton } from '../IconButton'\nimport { Icon } from '../Icon'\nimport { Typography } from '../Typography'\nimport type { IconName } from '../../icons/names'\nimport styles from './FileCard.module.css'\n\nexport type FileCardSize = AvatarSize\n\nconst IMAGE_EXTS = new Set([\n 'png',\n 'jpg',\n 'jpeg',\n 'webp',\n 'svg',\n 'gif',\n 'avif',\n 'bmp',\n 'ico',\n 'heic',\n])\n\n// a leading icon per file family (non-image); everything else gets the generic document icon\nconst FILE_ICONS: Record<string, IconName> = {\n pdf: 'DocumentText',\n doc: 'DocumentText',\n docx: 'DocumentText',\n txt: 'DocumentText',\n rtf: 'DocumentText',\n md: 'DocumentText',\n csv: 'DocumentText',\n xls: 'DocumentText',\n xlsx: 'DocumentText',\n json: 'DocumentCode',\n xml: 'DocumentCode',\n zip: 'Folder',\n rar: 'Folder',\n '7z': 'Folder',\n mp4: 'VideoSquare',\n mov: 'VideoSquare',\n webm: 'VideoSquare',\n mp3: 'MusicSquare',\n wav: 'MusicSquare',\n}\n\n/** The lowercased extension from a file name, else the subtype from a MIME `type` (`image/png` → `png`). */\nfunction extensionOf(name: string, type?: string): string {\n const dot = name.lastIndexOf('.')\n if (dot > 0 && name.length - dot <= 7) return name.slice(dot + 1).toLowerCase()\n if (type && type.includes('/')) return type.slice(type.indexOf('/') + 1).toLowerCase()\n return ''\n}\n\n/** Split `report.pdf` into `{ base: 'report', ext: '.pdf' }` so the base can ellipsize and the type stays. */\nfunction splitName(name: string): { base: string; ext: string } {\n const dot = name.lastIndexOf('.')\n return dot > 0 && name.length - dot <= 7\n ? { base: name.slice(0, dot), ext: name.slice(dot) }\n : { base: name, ext: '' }\n}\n\n/** Human-readable byte size — `2411724` → `\"2.3 MB\"`. */\nfunction formatBytes(bytes: number): string {\n if (!Number.isFinite(bytes) || bytes < 0) return ''\n if (bytes < 1024) return `${bytes} B`\n const units = ['KB', 'MB', 'GB', 'TB']\n let value = bytes / 1024\n let i = 0\n while (value >= 1024 && i < units.length - 1) {\n value /= 1024\n i += 1\n }\n return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[i]}`\n}\n\nexport interface FileCardProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'color'> {\n /** File name — shown middle-truncated (`test-file-na….pdf`) so the extension always stays visible. */\n name: string\n /** File URL — the download target and, for an image, the thumbnail `src`. */\n src?: string\n /** File type — an extension (`'pdf'`) or MIME (`'image/png'`). Derived from `name` when omitted. */\n type?: string\n /** Force image vs. file rendering. Inferred from `type` / `name` / `src` when omitted. */\n image?: boolean\n /** File size — a **bytes** number (auto-formatted to `\"2.3 MB\"`) or a preformatted string. Shown after the type. */\n fileSize?: number | string\n /**\n * When no `fileSize` is given, fetch it from `src` via a `HEAD` request (reads `Content-Length`). Off\n * by default — it's a network call and needs CORS to expose the header; prefer passing `fileSize` from\n * the backend. Fails silently (no size shown) when unavailable.\n */\n fetchSize?: boolean\n /** Meta line under the name — overrides the derived `TYPE · size`. */\n meta?: ReactNode\n /** Theme token tinting the avatar / file-icon box. Defaults to `accent`. */\n color?: ThemeColor\n /** Size — scales the avatar, text and padding. Defaults to `md`. */\n size?: FileCardSize\n /** Show the download control (only when there's a `src` or `onDownload`). Defaults to `true`. */\n downloadable?: boolean\n /** Custom download handler — replaces the default (a download of `src`). */\n onDownload?: () => void\n}\n\n/**\n * A compact, read-only **file card** for displaying a file that already exists (e.g. from the backend) —\n * an image or a document (`pdf` / `docx` / `csv` / `svg` / …). Shows a leading **`Avatar`** (the image\n * thumbnail via `src`, or a type-based file icon in a tinted square), the **name** middle-truncated so\n * the extension is never lost, the **type** underneath, and a **download** control. Simple to drop in —\n * pass `name` (+ `src` for the thumbnail/download). Not to be confused with `FileUploader` (which\n * *collects* files to upload); this only *displays* one. Token-only styling.\n *\n * @example\n * <FileCard name=\"annual-report.pdf\" src=\"/files/annual-report.pdf\" />\n * <FileCard name=\"avatar.png\" src={url} meta=\"240 KB\" />\n */\nexport const FileCard = forwardRef<HTMLDivElement, FileCardProps>(function FileCard(\n {\n name,\n src,\n type,\n image,\n fileSize,\n fetchSize = false,\n meta,\n color = 'accent',\n size = 'md',\n downloadable = true,\n onDownload,\n className,\n style,\n ...props\n },\n ref,\n) {\n const t = useT()\n const ext = extensionOf(name, type)\n const isImage = image ?? (type?.startsWith('image/') || IMAGE_EXTS.has(ext))\n const { base, ext: nameExt } = splitName(name)\n\n // optional auto size via a HEAD request (only when opted in and no explicit fileSize)\n const [fetchedSize, setFetchedSize] = useState<number | null>(null)\n useEffect(() => {\n if (!fetchSize || fileSize != null || !src || typeof fetch === 'undefined') return\n let cancelled = false\n fetch(src, { method: 'HEAD' })\n .then((res) => {\n const len = res.headers.get('content-length')\n if (!cancelled && len) setFetchedSize(Number(len))\n })\n .catch(() => {})\n return () => {\n cancelled = true\n }\n }, [fetchSize, fileSize, src])\n\n const sizeText =\n fileSize != null\n ? typeof fileSize === 'number'\n ? formatBytes(fileSize)\n : fileSize\n : fetchedSize != null\n ? formatBytes(fetchedSize)\n : ''\n // \"TYPE · 2.3 MB\" (either part optional) — overridden wholesale by `meta`\n const derivedMeta = [ext ? ext.toUpperCase() : '', sizeText].filter(Boolean).join(' · ')\n const metaLine = meta ?? (derivedMeta || null)\n\n const handleDownload = () => {\n if (onDownload) return onDownload()\n if (!src) return\n const a = document.createElement('a')\n a.href = src\n a.download = name\n a.rel = 'noopener'\n a.click()\n }\n\n return (\n <div\n ref={ref}\n className={clsx(styles.fileCard, styles[size], className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n {...props}\n >\n <Avatar\n className={styles.avatar}\n src={isImage ? src : undefined}\n icon={isImage ? undefined : (FILE_ICONS[ext] ?? 'Document')}\n name={name}\n shape=\"square\"\n size={size}\n color={color}\n />\n <div className={styles.body}>\n <span className={styles.name} title={name}>\n <span className={styles.nameBase}>{base}</span>\n {nameExt && <span className={styles.nameExt}>{nameExt}</span>}\n </span>\n {metaLine != null && (\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\" uppercase className={styles.type}>\n {metaLine}\n </Typography>\n )}\n </div>\n {downloadable && (src || onDownload) && (\n <IconButton\n variant=\"filled\"\n size={size === 'lg' ? 'md' : 'sm'}\n className={styles.download}\n aria-label={t('fileCard.download', { name })}\n onClick={handleDownload}\n >\n <Icon name=\"ImportArrow\" />\n </IconButton>\n )}\n </div>\n )\n})\n"],"names":["IMAGE_EXTS","FILE_ICONS","extensionOf","name","type","dot","splitName","formatBytes","bytes","units","value","i","FileCard","forwardRef","src","image","fileSize","fetchSize","meta","color","size","downloadable","onDownload","className","style","props","ref","t","useT","ext","isImage","base","nameExt","fetchedSize","setFetchedSize","useState","useEffect","cancelled","res","len","sizeText","derivedMeta","metaLine","handleDownload","a","jsxs","clsx","styles","jsx","Avatar","Typography","IconButton","Icon"],"mappings":"2kBAmBMA,MAAiB,IAAI,CACzB,MACA,MACA,OACA,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} from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef as S, useState as A, useEffect as O } from "react";
|
|
3
3
|
import { clsx as y } from "clsx";
|
|
4
4
|
import { A as L } from "./Avatar-MwWIcj8z.js";
|
|
5
|
-
import { I as $ } from "./IconButton-
|
|
5
|
+
import { I as $ } from "./IconButton-sC_E_TXd.js";
|
|
6
6
|
import { I as V } from "./Icon-CGQ5yGSZ.js";
|
|
7
7
|
import { T as G } from "./Typography-CJv5AnRP.js";
|
|
8
|
-
import { a as H } from "./ConfigProvider-
|
|
8
|
+
import { a as H } from "./ConfigProvider-tvLbKiqu.js";
|
|
9
9
|
const K = "_fileCard_kpeb5_3", R = "_avatar_kpeb5_24", U = "_body_kpeb5_29", W = "_name_kpeb5_38", X = "_nameBase_kpeb5_45", z = "_nameExt_kpeb5_51", J = "_type_kpeb5_57", P = "_download_kpeb5_61", Q = "_sm_kpeb5_66", Y = "_md_kpeb5_77", Z = "_lg_kpeb5_81", o = {
|
|
10
10
|
fileCard: K,
|
|
11
11
|
avatar: R,
|
|
@@ -146,4 +146,4 @@ const ue = S(function({
|
|
|
146
146
|
export {
|
|
147
147
|
ue as F
|
|
148
148
|
};
|
|
149
|
-
//# sourceMappingURL=FileCard-
|
|
149
|
+
//# sourceMappingURL=FileCard-R_sB8Qbx.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileCard-D4t0-ms2.js","sources":["../src/components/FileCard/FileCard.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Avatar, type AvatarSize } from '../Avatar'\nimport { IconButton } from '../IconButton'\nimport { Icon } from '../Icon'\nimport { Typography } from '../Typography'\nimport type { IconName } from '../../icons/names'\nimport styles from './FileCard.module.css'\n\nexport type FileCardSize = AvatarSize\n\nconst IMAGE_EXTS = new Set([\n 'png',\n 'jpg',\n 'jpeg',\n 'webp',\n 'svg',\n 'gif',\n 'avif',\n 'bmp',\n 'ico',\n 'heic',\n])\n\n// a leading icon per file family (non-image); everything else gets the generic document icon\nconst FILE_ICONS: Record<string, IconName> = {\n pdf: 'DocumentText',\n doc: 'DocumentText',\n docx: 'DocumentText',\n txt: 'DocumentText',\n rtf: 'DocumentText',\n md: 'DocumentText',\n csv: 'DocumentText',\n xls: 'DocumentText',\n xlsx: 'DocumentText',\n json: 'DocumentCode',\n xml: 'DocumentCode',\n zip: 'Folder',\n rar: 'Folder',\n '7z': 'Folder',\n mp4: 'VideoSquare',\n mov: 'VideoSquare',\n webm: 'VideoSquare',\n mp3: 'MusicSquare',\n wav: 'MusicSquare',\n}\n\n/** The lowercased extension from a file name, else the subtype from a MIME `type` (`image/png` → `png`). */\nfunction extensionOf(name: string, type?: string): string {\n const dot = name.lastIndexOf('.')\n if (dot > 0 && name.length - dot <= 7) return name.slice(dot + 1).toLowerCase()\n if (type && type.includes('/')) return type.slice(type.indexOf('/') + 1).toLowerCase()\n return ''\n}\n\n/** Split `report.pdf` into `{ base: 'report', ext: '.pdf' }` so the base can ellipsize and the type stays. */\nfunction splitName(name: string): { base: string; ext: string } {\n const dot = name.lastIndexOf('.')\n return dot > 0 && name.length - dot <= 7\n ? { base: name.slice(0, dot), ext: name.slice(dot) }\n : { base: name, ext: '' }\n}\n\n/** Human-readable byte size — `2411724` → `\"2.3 MB\"`. */\nfunction formatBytes(bytes: number): string {\n if (!Number.isFinite(bytes) || bytes < 0) return ''\n if (bytes < 1024) return `${bytes} B`\n const units = ['KB', 'MB', 'GB', 'TB']\n let value = bytes / 1024\n let i = 0\n while (value >= 1024 && i < units.length - 1) {\n value /= 1024\n i += 1\n }\n return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[i]}`\n}\n\nexport interface FileCardProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'color'> {\n /** File name — shown middle-truncated (`test-file-na….pdf`) so the extension always stays visible. */\n name: string\n /** File URL — the download target and, for an image, the thumbnail `src`. */\n src?: string\n /** File type — an extension (`'pdf'`) or MIME (`'image/png'`). Derived from `name` when omitted. */\n type?: string\n /** Force image vs. file rendering. Inferred from `type` / `name` / `src` when omitted. */\n image?: boolean\n /** File size — a **bytes** number (auto-formatted to `\"2.3 MB\"`) or a preformatted string. Shown after the type. */\n fileSize?: number | string\n /**\n * When no `fileSize` is given, fetch it from `src` via a `HEAD` request (reads `Content-Length`). Off\n * by default — it's a network call and needs CORS to expose the header; prefer passing `fileSize` from\n * the backend. Fails silently (no size shown) when unavailable.\n */\n fetchSize?: boolean\n /** Meta line under the name — overrides the derived `TYPE · size`. */\n meta?: ReactNode\n /** Theme token tinting the avatar / file-icon box. Defaults to `accent`. */\n color?: ThemeColor\n /** Size — scales the avatar, text and padding. Defaults to `md`. */\n size?: FileCardSize\n /** Show the download control (only when there's a `src` or `onDownload`). Defaults to `true`. */\n downloadable?: boolean\n /** Custom download handler — replaces the default (a download of `src`). */\n onDownload?: () => void\n}\n\n/**\n * A compact, read-only **file card** for displaying a file that already exists (e.g. from the backend) —\n * an image or a document (`pdf` / `docx` / `csv` / `svg` / …). Shows a leading **`Avatar`** (the image\n * thumbnail via `src`, or a type-based file icon in a tinted square), the **name** middle-truncated so\n * the extension is never lost, the **type** underneath, and a **download** control. Simple to drop in —\n * pass `name` (+ `src` for the thumbnail/download). Not to be confused with `FileUploader` (which\n * *collects* files to upload); this only *displays* one. Token-only styling.\n *\n * @example\n * <FileCard name=\"annual-report.pdf\" src=\"/files/annual-report.pdf\" />\n * <FileCard name=\"avatar.png\" src={url} meta=\"240 KB\" />\n */\nexport const FileCard = forwardRef<HTMLDivElement, FileCardProps>(function FileCard(\n {\n name,\n src,\n type,\n image,\n fileSize,\n fetchSize = false,\n meta,\n color = 'accent',\n size = 'md',\n downloadable = true,\n onDownload,\n className,\n style,\n ...props\n },\n ref,\n) {\n const t = useT()\n const ext = extensionOf(name, type)\n const isImage = image ?? (type?.startsWith('image/') || IMAGE_EXTS.has(ext))\n const { base, ext: nameExt } = splitName(name)\n\n // optional auto size via a HEAD request (only when opted in and no explicit fileSize)\n const [fetchedSize, setFetchedSize] = useState<number | null>(null)\n useEffect(() => {\n if (!fetchSize || fileSize != null || !src || typeof fetch === 'undefined') return\n let cancelled = false\n fetch(src, { method: 'HEAD' })\n .then((res) => {\n const len = res.headers.get('content-length')\n if (!cancelled && len) setFetchedSize(Number(len))\n })\n .catch(() => {})\n return () => {\n cancelled = true\n }\n }, [fetchSize, fileSize, src])\n\n const sizeText =\n fileSize != null\n ? typeof fileSize === 'number'\n ? formatBytes(fileSize)\n : fileSize\n : fetchedSize != null\n ? formatBytes(fetchedSize)\n : ''\n // \"TYPE · 2.3 MB\" (either part optional) — overridden wholesale by `meta`\n const derivedMeta = [ext ? ext.toUpperCase() : '', sizeText].filter(Boolean).join(' · ')\n const metaLine = meta ?? (derivedMeta || null)\n\n const handleDownload = () => {\n if (onDownload) return onDownload()\n if (!src) return\n const a = document.createElement('a')\n a.href = src\n a.download = name\n a.rel = 'noopener'\n a.click()\n }\n\n return (\n <div\n ref={ref}\n className={clsx(styles.fileCard, styles[size], className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n {...props}\n >\n <Avatar\n className={styles.avatar}\n src={isImage ? src : undefined}\n icon={isImage ? undefined : (FILE_ICONS[ext] ?? 'Document')}\n name={name}\n shape=\"square\"\n size={size}\n color={color}\n />\n <div className={styles.body}>\n <span className={styles.name} title={name}>\n <span className={styles.nameBase}>{base}</span>\n {nameExt && <span className={styles.nameExt}>{nameExt}</span>}\n </span>\n {metaLine != null && (\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\" uppercase className={styles.type}>\n {metaLine}\n </Typography>\n )}\n </div>\n {downloadable && (src || onDownload) && (\n <IconButton\n variant=\"filled\"\n size={size === 'lg' ? 'md' : 'sm'}\n className={styles.download}\n aria-label={t('fileCard.download', { name })}\n onClick={handleDownload}\n >\n <Icon name=\"ImportArrow\" />\n </IconButton>\n )}\n </div>\n )\n})\n"],"names":["IMAGE_EXTS","FILE_ICONS","extensionOf","name","type","dot","splitName","formatBytes","bytes","units","value","i","FileCard","forwardRef","src","image","fileSize","fetchSize","meta","color","size","downloadable","onDownload","className","style","props","ref","t","useT","ext","isImage","base","nameExt","fetchedSize","setFetchedSize","useState","useEffect","cancelled","res","len","sizeText","derivedMeta","metaLine","handleDownload","a","jsxs","clsx","styles","jsx","Avatar","Typography","IconButton","Icon"],"mappings":";;;;;;;;;;;;;;;;;;;;GAmBMA,yBAAiB,IAAI;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC,GAGKC,KAAuC;AAAA,EAC3C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AACP;AAGA,SAASC,GAAYC,GAAcC,GAAuB;AACxD,QAAMC,IAAMF,EAAK,YAAY,GAAG;AAChC,SAAIE,IAAM,KAAKF,EAAK,SAASE,KAAO,IAAUF,EAAK,MAAME,IAAM,CAAC,EAAE,YAAA,IAC9DD,KAAQA,EAAK,SAAS,GAAG,IAAUA,EAAK,MAAMA,EAAK,QAAQ,GAAG,IAAI,CAAC,EAAE,YAAA,IAClE;AACT;AAGA,SAASE,GAAUH,GAA6C;AAC9D,QAAME,IAAMF,EAAK,YAAY,GAAG;AAChC,SAAOE,IAAM,KAAKF,EAAK,SAASE,KAAO,IACnC,EAAE,M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,OAAAD;AAAA,UAAA;AAAA,QAAA;AAAA,QAEF,gBAAA0B,EAAC,OAAA,EAAI,WAAWE,EAAO,MACrB,UAAA;AAAA,UAAA,gBAAAF,EAAC,QAAA,EAAK,WAAWE,EAAO,MAAM,OAAO5C,GACnC,UAAA;AAAA,YAAA,gBAAA6C,EAAC,QAAA,EAAK,WAAWD,EAAO,UAAW,UAAAhB,GAAK;AAAA,YACvCC,KAAW,gBAAAgB,EAAC,QAAA,EAAK,WAAWD,EAAO,SAAU,UAAAf,EAAA,CAAQ;AAAA,UAAA,GACxD;AAAA,UACCU,KAAY,QACX,gBAAAM,EAACE,GAAA,EAAW,IAAG,QAAO,SAAQ,aAAY,OAAM,SAAQ,WAAS,IAAC,WAAWH,EAAO,MACjF,UAAAL,EAAA,CACH;AAAA,QAAA,GAEJ;AAAA,QACCrB,MAAiBP,KAAOQ,MACvB,gBAAA0B;AAAA,UAACG;AAAA,UAAA;AAAA,YACC,SAAQ;AAAA,YACR,MAAM/B,MAAS,OAAO,OAAO;AAAA,YAC7B,WAAW2B,EAAO;AAAA,YAClB,cAAYpB,EAAE,qBAAqB,EAAE,MAAAxB,GAAM;AAAA,YAC3C,SAASwC;AAAA,YAET,UAAA,gBAAAK,EAACI,GAAA,EAAK,MAAK,cAAA,CAAc;AAAA,UAAA;AAAA,QAAA;AAAA,MAC3B;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
1
|
+
{"version":3,"file":"FileCard-R_sB8Qbx.js","sources":["../src/components/FileCard/FileCard.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type ReactNode,\n} from 'react'\nimport { clsx } from 'clsx'\nimport { useT, type ThemeColor } from '../../theme'\nimport { Avatar, type AvatarSize } from '../Avatar'\nimport { IconButton } from '../IconButton'\nimport { Icon } from '../Icon'\nimport { Typography } from '../Typography'\nimport type { IconName } from '../../icons/names'\nimport styles from './FileCard.module.css'\n\nexport type FileCardSize = AvatarSize\n\nconst IMAGE_EXTS = new Set([\n 'png',\n 'jpg',\n 'jpeg',\n 'webp',\n 'svg',\n 'gif',\n 'avif',\n 'bmp',\n 'ico',\n 'heic',\n])\n\n// a leading icon per file family (non-image); everything else gets the generic document icon\nconst FILE_ICONS: Record<string, IconName> = {\n pdf: 'DocumentText',\n doc: 'DocumentText',\n docx: 'DocumentText',\n txt: 'DocumentText',\n rtf: 'DocumentText',\n md: 'DocumentText',\n csv: 'DocumentText',\n xls: 'DocumentText',\n xlsx: 'DocumentText',\n json: 'DocumentCode',\n xml: 'DocumentCode',\n zip: 'Folder',\n rar: 'Folder',\n '7z': 'Folder',\n mp4: 'VideoSquare',\n mov: 'VideoSquare',\n webm: 'VideoSquare',\n mp3: 'MusicSquare',\n wav: 'MusicSquare',\n}\n\n/** The lowercased extension from a file name, else the subtype from a MIME `type` (`image/png` → `png`). */\nfunction extensionOf(name: string, type?: string): string {\n const dot = name.lastIndexOf('.')\n if (dot > 0 && name.length - dot <= 7) return name.slice(dot + 1).toLowerCase()\n if (type && type.includes('/')) return type.slice(type.indexOf('/') + 1).toLowerCase()\n return ''\n}\n\n/** Split `report.pdf` into `{ base: 'report', ext: '.pdf' }` so the base can ellipsize and the type stays. */\nfunction splitName(name: string): { base: string; ext: string } {\n const dot = name.lastIndexOf('.')\n return dot > 0 && name.length - dot <= 7\n ? { base: name.slice(0, dot), ext: name.slice(dot) }\n : { base: name, ext: '' }\n}\n\n/** Human-readable byte size — `2411724` → `\"2.3 MB\"`. */\nfunction formatBytes(bytes: number): string {\n if (!Number.isFinite(bytes) || bytes < 0) return ''\n if (bytes < 1024) return `${bytes} B`\n const units = ['KB', 'MB', 'GB', 'TB']\n let value = bytes / 1024\n let i = 0\n while (value >= 1024 && i < units.length - 1) {\n value /= 1024\n i += 1\n }\n return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[i]}`\n}\n\nexport interface FileCardProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title' | 'color'> {\n /** File name — shown middle-truncated (`test-file-na….pdf`) so the extension always stays visible. */\n name: string\n /** File URL — the download target and, for an image, the thumbnail `src`. */\n src?: string\n /** File type — an extension (`'pdf'`) or MIME (`'image/png'`). Derived from `name` when omitted. */\n type?: string\n /** Force image vs. file rendering. Inferred from `type` / `name` / `src` when omitted. */\n image?: boolean\n /** File size — a **bytes** number (auto-formatted to `\"2.3 MB\"`) or a preformatted string. Shown after the type. */\n fileSize?: number | string\n /**\n * When no `fileSize` is given, fetch it from `src` via a `HEAD` request (reads `Content-Length`). Off\n * by default — it's a network call and needs CORS to expose the header; prefer passing `fileSize` from\n * the backend. Fails silently (no size shown) when unavailable.\n */\n fetchSize?: boolean\n /** Meta line under the name — overrides the derived `TYPE · size`. */\n meta?: ReactNode\n /** Theme token tinting the avatar / file-icon box. Defaults to `accent`. */\n color?: ThemeColor\n /** Size — scales the avatar, text and padding. Defaults to `md`. */\n size?: FileCardSize\n /** Show the download control (only when there's a `src` or `onDownload`). Defaults to `true`. */\n downloadable?: boolean\n /** Custom download handler — replaces the default (a download of `src`). */\n onDownload?: () => void\n}\n\n/**\n * A compact, read-only **file card** for displaying a file that already exists (e.g. from the backend) —\n * an image or a document (`pdf` / `docx` / `csv` / `svg` / …). Shows a leading **`Avatar`** (the image\n * thumbnail via `src`, or a type-based file icon in a tinted square), the **name** middle-truncated so\n * the extension is never lost, the **type** underneath, and a **download** control. Simple to drop in —\n * pass `name` (+ `src` for the thumbnail/download). Not to be confused with `FileUploader` (which\n * *collects* files to upload); this only *displays* one. Token-only styling.\n *\n * @example\n * <FileCard name=\"annual-report.pdf\" src=\"/files/annual-report.pdf\" />\n * <FileCard name=\"avatar.png\" src={url} meta=\"240 KB\" />\n */\nexport const FileCard = forwardRef<HTMLDivElement, FileCardProps>(function FileCard(\n {\n name,\n src,\n type,\n image,\n fileSize,\n fetchSize = false,\n meta,\n color = 'accent',\n size = 'md',\n downloadable = true,\n onDownload,\n className,\n style,\n ...props\n },\n ref,\n) {\n const t = useT()\n const ext = extensionOf(name, type)\n const isImage = image ?? (type?.startsWith('image/') || IMAGE_EXTS.has(ext))\n const { base, ext: nameExt } = splitName(name)\n\n // optional auto size via a HEAD request (only when opted in and no explicit fileSize)\n const [fetchedSize, setFetchedSize] = useState<number | null>(null)\n useEffect(() => {\n if (!fetchSize || fileSize != null || !src || typeof fetch === 'undefined') return\n let cancelled = false\n fetch(src, { method: 'HEAD' })\n .then((res) => {\n const len = res.headers.get('content-length')\n if (!cancelled && len) setFetchedSize(Number(len))\n })\n .catch(() => {})\n return () => {\n cancelled = true\n }\n }, [fetchSize, fileSize, src])\n\n const sizeText =\n fileSize != null\n ? typeof fileSize === 'number'\n ? formatBytes(fileSize)\n : fileSize\n : fetchedSize != null\n ? formatBytes(fetchedSize)\n : ''\n // \"TYPE · 2.3 MB\" (either part optional) — overridden wholesale by `meta`\n const derivedMeta = [ext ? ext.toUpperCase() : '', sizeText].filter(Boolean).join(' · ')\n const metaLine = meta ?? (derivedMeta || null)\n\n const handleDownload = () => {\n if (onDownload) return onDownload()\n if (!src) return\n const a = document.createElement('a')\n a.href = src\n a.download = name\n a.rel = 'noopener'\n a.click()\n }\n\n return (\n <div\n ref={ref}\n className={clsx(styles.fileCard, styles[size], className)}\n style={{ '--tz-btn-rgb': `var(--tz-color-${color}-rgb)`, ...style } as CSSProperties}\n {...props}\n >\n <Avatar\n className={styles.avatar}\n src={isImage ? src : undefined}\n icon={isImage ? undefined : (FILE_ICONS[ext] ?? 'Document')}\n name={name}\n shape=\"square\"\n size={size}\n color={color}\n />\n <div className={styles.body}>\n <span className={styles.name} title={name}>\n <span className={styles.nameBase}>{base}</span>\n {nameExt && <span className={styles.nameExt}>{nameExt}</span>}\n </span>\n {metaLine != null && (\n <Typography as=\"span\" variant=\"bodySmall\" color=\"muted\" uppercase className={styles.type}>\n {metaLine}\n </Typography>\n )}\n </div>\n {downloadable && (src || onDownload) && (\n <IconButton\n variant=\"filled\"\n size={size === 'lg' ? 'md' : 'sm'}\n className={styles.download}\n aria-label={t('fileCard.download', { name })}\n onClick={handleDownload}\n >\n <Icon name=\"ImportArrow\" />\n </IconButton>\n )}\n </div>\n )\n})\n"],"names":["IMAGE_EXTS","FILE_ICONS","extensionOf","name","type","dot","splitName","formatBytes","bytes","units","value","i","FileCard","forwardRef","src","image","fileSize","fetchSize","meta","color","size","downloadable","onDownload","className","style","props","ref","t","useT","ext","isImage","base","nameExt","fetchedSize","setFetchedSize","useState","useEffect","cancelled","res","len","sizeText","derivedMeta","metaLine","handleDownload","a","jsxs","clsx","styles","jsx","Avatar","Typography","IconButton","Icon"],"mappings":";;;;;;;;;;;;;;;;;;;;GAmBMA,yBAAiB,IAAI;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC,GAGKC,KAAuC;AAAA,EAC3C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AACP;AAGA,SAASC,GAAYC,GAAcC,GAAuB;AACxD,QAAMC,IAAMF,EAAK,YAAY,GAAG;AAChC,SAAIE,IAAM,KAAKF,EAAK,SAASE,KAAO,IAAUF,EAAK,MAAME,IAAM,CAAC,EAAE,YAAA,IAC9DD,KAAQA,EAAK,SAAS,GAAG,IAAUA,EAAK,MAAMA,EAAK,QAAQ,GAAG,IAAI,CAAC,EAAE,YAAA,IAClE;AACT;AAGA,SAASE,GAAUH,GAA6C;AAC9D,QAAME,IAAMF,EAAK,YAAY,GAAG;AAChC,SAAOE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AAAA,YACA,OAAM;AAAA,YACN,MAAAiB;AAAA,YACA,OAAAD;AAAA,UAAA;AAAA,QAAA;AAAA,QAEF,gBAAA0B,EAAC,OAAA,EAAI,WAAWE,EAAO,MACrB,UAAA;AAAA,UAAA,gBAAAF,EAAC,QAAA,EAAK,WAAWE,EAAO,MAAM,OAAO5C,GACnC,UAAA;AAAA,YAAA,gBAAA6C,EAAC,QAAA,EAAK,WAAWD,EAAO,UAAW,UAAAhB,GAAK;AAAA,YACvCC,KAAW,gBAAAgB,EAAC,QAAA,EAAK,WAAWD,EAAO,SAAU,UAAAf,EAAA,CAAQ;AAAA,UAAA,GACxD;AAAA,UACCU,KAAY,QACX,gBAAAM,EAACE,GAAA,EAAW,IAAG,QAAO,SAAQ,aAAY,OAAM,SAAQ,WAAS,IAAC,WAAWH,EAAO,MACjF,UAAAL,EAAA,CACH;AAAA,QAAA,GAEJ;AAAA,QACCrB,MAAiBP,KAAOQ,MACvB,gBAAA0B;AAAA,UAACG;AAAA,UAAA;AAAA,YACC,SAAQ;AAAA,YACR,MAAM/B,MAAS,OAAO,OAAO;AAAA,YAC7B,WAAW2B,EAAO;AAAA,YAClB,cAAYpB,EAAE,qBAAqB,EAAE,MAAAxB,GAAM;AAAA,YAC3C,SAASwC;AAAA,YAET,UAAA,gBAAAK,EAACI,GAAA,EAAK,MAAK,cAAA,CAAc;AAAA,UAAA;AAAA,QAAA;AAAA,MAC3B;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const t=require("react/jsx-runtime"),d=require("react"),L=require("clsx"),V=require("@dnd-kit/core"),ae=require("@dnd-kit/sortable"),Et=require("@dnd-kit/utilities"),kt=require("@formkit/auto-animate/react"),Rt=require("react-dropzone"),zt=require("./formContext-bTWrqdEV.cjs"),Ve=require("./toastStore-B4Tk2Xk7.cjs"),M=require("./Icon-BUP5_kRs.cjs"),Ft=require("./Skeleton-DK0lAjS9.cjs"),ie=require("./Typography-B6ASPrzT.cjs"),Dt=require("react-image-crop"),Ge=require("./Button-BZq1mIUH.cjs"),Ye=require("./Modal-CcrqM4kn.cjs"),Ct=require("./TextField-D_hzd5Gf.cjs"),ce=require("./ConfigProvider-CzAQf_d_.cjs"),Ie=require("./TextField.module-DsNCo8vN.cjs"),Mt="_cropSection_1j2zs_4",Pt="_cropHead_1j2zs_10",qt="_cropStage_1j2zs_16",Lt="_crop_1j2zs_4",Bt="_cropImg_1j2zs_30",$t="_altFields_1j2zs_35",Q={cropSection:Mt,cropHead:Pt,cropStage:qt,crop:Lt,cropImg:Bt,altFields:$t};function Ot({mode:n,name:o,imageUrl:l,mimeType:p,editLocales:S,initialDraft:w,onClose:N,onSave:P}){const h=ce.useT(),z=d.useRef(null),[_,B]=d.useState(),[i,$]=d.useState(null),[O,G]=d.useState(null),[Y,A]=d.useState(w),[W,X]=d.useState(null),[E,T]=d.useState(!1),Z=(c,y)=>{B(y);const g=z.current;if(g&&g.width>0&&c.width>=1&&c.height>=1){const k=g.naturalWidth/g.width,q=g.naturalHeight/g.height;$({x:Math.round(c.x*k),y:Math.round(c.y*q),width:Math.round(c.width*k),height:Math.round(c.height*q)})}else $(null)},U=async()=>{const c=z.current;if(!c||!i||i.width<1||i.height<1)return;const y=document.createElement("canvas");y.width=i.width,y.height=i.height;const g=y.getContext("2d");if(!g)return;g.imageSmoothingEnabled=!1,g.drawImage(c,i.x,i.y,i.width,i.height,0,0,i.width,i.height);const k=await new Promise(q=>y.toBlob(q,p,1));if(!k)throw new Error("canvas.toBlob returned null");return new File([k],o,{type:p,lastModified:Date.now()})},J=async()=>{if(n==="altText"){P({draft:Y});return}T(!0);try{const c=i&&i.width>=1&&i.height>=1?await U():void 0;P({croppedFile:c})}catch{X(h("fileUploader.cropError")),T(!1)}};return t.jsx(Ye.Modal,{open:!0,onClose:N,size:n==="crop"?"lg":"sm",icon:n==="crop"?"Crop":"Text",title:h(n==="crop"?"fileUploader.cropTitle":"fileUploader.altTitle"),description:o,footer:t.jsxs(t.Fragment,{children:[t.jsx(Ge.Button,{variant:"text",color:"accent",size:"sm",onClick:N,disabled:E,children:h("common.cancel")}),t.jsx(Ge.Button,{size:"sm",onClick:J,loading:E,children:h("common.save")})]}),children:n==="crop"?t.jsxs("div",{className:Q.cropSection,children:[t.jsxs("div",{className:Q.cropHead,children:[t.jsx(ie.Typography,{variant:"bodySmall",color:"muted",children:h("fileUploader.cropHint")}),t.jsx(ie.Typography,{variant:"bodySmall",color:i?"text":"muted",children:i?`${i.width} × ${i.height} px`:O?`${O.w} × ${O.h} px`:""})]}),t.jsx("div",{className:Q.cropStage,children:t.jsx(Dt,{crop:_,onChange:Z,className:Q.crop,children:t.jsx("img",{ref:z,src:l??void 0,alt:"",className:Q.cropImg,onLoad:c=>G({w:c.currentTarget.naturalWidth,h:c.currentTarget.naturalHeight})})})}),W&&t.jsx(ie.Typography,{variant:"bodySmall",color:"error",children:W})]}):t.jsx("div",{className:Q.altFields,children:S.map(c=>t.jsx(Ct.TextField,{label:c.label??(c.code||h("fileUploader.altTitle")),placeholder:h("fileUploader.altPlaceholder"),value:Y[c.code]??"",onChange:y=>A(g=>({...g,[c.code]:y.target.value}))},c.code))})})}const At="_backdrop_uqdv2_5",Wt="_media_uqdv2_9",Ht="_mediaSvg_uqdv2_19",Kt="_close_uqdv2_27",re={backdrop:At,media:Wt,mediaSvg:Ht,close:Kt};function Vt({url:n,isVideo:o,isSvg:l,name:p,onClose:S}){const w=ce.useT();return t.jsxs(Ye.Overlay,{open:!0,onClose:S,dim:.85,className:re.backdrop,role:"dialog","aria-modal":"true","aria-label":w("fileUploader.preview",{name:p}),children:[t.jsx("button",{type:"button",className:re.close,"aria-label":w("fileUploader.closePreview"),onClick:S,autoFocus:!0,children:t.jsx(M.Icon,{name:"Close",size:"lg"})}),o?t.jsx("video",{src:n,className:re.media,controls:!0,playsInline:!0}):t.jsx("img",{src:n,alt:p,className:L.clsx(re.media,l&&re.mediaSvg)})]})}const Gt="_root_m8xag_4",Yt="_fullWidth_m8xag_9",Jt="_disabled_m8xag_14",Qt="_dropzone_m8xag_17",Xt="_dropText_m8xag_41",Zt="_dropping_m8xag_56",eo="_error_m8xag_61",to="_dropIcon_m8xag_65",oo="_prompt_m8xag_77",no="_accent_m8xag_82",so="_hint_m8xag_87",ro="_list_m8xag_93",ao="_populated_m8xag_103",lo="_tile_m8xag_121",io="_grabbable_m8xag_130",co="_entering_m8xag_139",uo="_dragging_m8xag_142",fo="_tileError_m8xag_148",po="_tileImg_m8xag_153",go="_tileImgPending_m8xag_161",mo="_tileSkeleton_m8xag_164",ho="_tileFallback_m8xag_169",xo="_tilePlay_m8xag_179",_o="_tileTop_m8xag_198",bo="_tileBottom_m8xag_208",yo="_tileRemove_m8xag_218",vo="_tileAction_m8xag_219",jo="_tileActionEnd_m8xag_254",So="_tileText_m8xag_257",To="_name_m8xag_264",Uo="_nameBase_m8xag_271",Io="_nameExt_m8xag_277",wo="_tileMeta_m8xag_281",No="_metaError_m8xag_285",r={root:Gt,fullWidth:Yt,disabled:Jt,dropzone:Qt,dropText:Xt,dropping:Zt,error:eo,dropIcon:to,prompt:oo,accent:no,hint:so,list:ro,populated:ao,tile:lo,grabbable:io,entering:co,dragging:uo,tileError:fo,tileImg:po,tileImgPending:go,tileSkeleton:mo,tileFallback:ho,tilePlay:xo,tileTop:_o,tileBottom:bo,tileRemove:yo,tileAction:vo,tileActionEnd:jo,tileText:So,name:To,nameBase:Uo,nameExt:Io,tileMeta:wo,metaError:No},Je=()=>typeof URL<"u"&&typeof URL.createObjectURL=="function",Eo=300,ko=(n,o,l,p)=>{let S=[{},{}],w=Eo;if(o==="add")w=0;else if(o==="remove")S=[{opacity:1,transform:"translateY(0)"},{opacity:0,transform:"translateY(-8px)"}];else if(l&&p){const N=l.left-p.left,P=l.top-p.top;S=[{transform:`translate(${N}px, ${P}px)`},{transform:"translate(0, 0)"}]}return new KeyframeEffect(n,S,{duration:w,easing:"ease-out"})},le=n=>{if(n<1024)return`${n} B`;const o=["KB","MB","GB","TB"];let l=n/1024,p=0;for(;l>=1024&&p<o.length-1;)l/=1024,p+=1;return`${l.toFixed(l<10?1:0)} ${o[p]}`},Ro=n=>{if(typeof n=="number")return n;const o=/^\s*([\d.]+)\s*(b|kb|mb|gb|tb)?\s*$/i.exec(n);if(!o)return;const l={b:1,kb:1024,mb:1024**2,gb:1024**3,tb:1024**4};return parseFloat(o[1])*(l[(o[2]||"b").toLowerCase()]??1)},Qe=n=>`f:${n.name}:${n.size}:${n.lastModified}`,zo=n=>n.file?Qe(n.file):`s:${n.source??""}`,me=n=>n.file?n.file.name:n.source?/^(data|blob):/i.test(n.source)?"File":n.source.split(/[?#]/)[0].split("/").pop()||"File":"File",we=n=>{if(n.file)return n.file.type.startsWith("image/");const o=n.source;return o?/^data:image\//i.test(o)?!0:/^data:/i.test(o)?!1:/\.(png|jpe?g|gif|webp|avif|svg|bmp|ico|heic|heif)(?:[?#]|$)/i.test(o)||!/\.[a-z0-9]{1,8}(?:[?#]|$)/i.test(o):!1},Ne=n=>{if(n.file)return n.file.type.startsWith("video/");const o=n.source;return o?/^data:video\//i.test(o)||/\.(mp4|webm|ogg|ogv|mov|m4v|avi|mkv)(?:[?#]|$)/i.test(o):!1},Fo=n=>{if(typeof document>"u")return;const o=document.createElement("a");if(o.style.display="none",n.file){if(!Je())return;const l=URL.createObjectURL(n.file);o.href=l,o.download=n.file.name,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(l),1e3)}else n.source&&(o.href=n.source,o.download=me(n),o.target="_blank",o.rel="noopener",document.body.appendChild(o),o.click(),o.remove())},Do=n=>{const o=n.lastIndexOf(".");return o>0&&n.length-o<=7?{base:n.slice(0,o),ext:n.slice(o)}:{base:n,ext:""}};function Co({id:n,item:o,preview:l,sortable:p,entering:S,disabled:w,error:N,onRemove:P,onCrop:h,onAltText:z,onDownload:_,onView:B,onPreviewError:i}){const{attributes:$,listeners:O,setNodeRef:G,transform:Y,transition:A,isDragging:W}=ae.useSortable({id:n,disabled:!p}),X={transform:Et.CSS.Transform.toString(Y),transition:A},E=ce.useT(),T=me(o),{base:Z,ext:U}=Do(T),[J,c]=d.useState(()=>!l||l.startsWith("blob:")),y=d.useRef(l);y.current!==l&&(y.current=l,c(!l||l.startsWith("blob:")));const g=d.useRef(null);d.useEffect(()=>{const m=g.current;m!=null&&m.complete&&m.naturalWidth>0&&c(!0)},[l]);const k=()=>{c(!0),i==null||i()},q=o.file?le(o.file.size):E("fileUploader.uploaded"),he=Ne(o),de=_?t.jsx("button",{type:"button",className:r.tileAction,"aria-label":E("fileUploader.download",{name:T}),onClick:_,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"DocumentDownload",size:"sm"})}):null;return t.jsxs("div",{ref:G,style:X,className:L.clsx(r.tile,p&&r.grabbable,S&&r.entering,W&&r.dragging,N&&r.tileError),...$,...O,children:[l&&!J&&t.jsx(Ft.Skeleton,{variant:"rect",width:"100%",height:"100%",className:r.tileSkeleton}),l?he?t.jsxs(t.Fragment,{children:[t.jsx("video",{src:l,className:r.tileImg,muted:!0,playsInline:!0,preload:"metadata",draggable:!1,onLoadedData:()=>c(!0),onError:k}),t.jsx("span",{className:r.tilePlay,"aria-hidden":"true",children:t.jsx(M.Icon,{name:"Play",size:"lg"})})]}):t.jsx("img",{ref:g,src:l,alt:"",className:L.clsx(r.tileImg,!J&&r.tileImgPending),draggable:!1,onLoad:()=>c(!0),onError:k}):t.jsx("span",{className:r.tileFallback,"aria-hidden":"true",children:t.jsx(M.Icon,{name:"Document",size:"lg"})}),t.jsxs("div",{className:r.tileTop,children:[t.jsxs("span",{className:r.tileText,children:[t.jsxs("span",{className:r.name,title:T,children:[t.jsx("span",{className:r.nameBase,children:Z}),U&&t.jsx("span",{className:r.nameExt,children:U})]}),t.jsx("span",{className:L.clsx(r.tileMeta,N&&r.metaError),children:N??q})]}),!w&&t.jsx("button",{type:"button",className:r.tileRemove,"aria-label":E("fileUploader.remove",{name:T}),onClick:P,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Close",size:"sm"})})]}),(h||z||_||B)&&t.jsxs("div",{className:r.tileBottom,children:[h&&t.jsx("button",{type:"button",className:r.tileAction,"aria-label":E("fileUploader.crop",{name:T}),onClick:h,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Crop",size:"sm"})}),z&&t.jsx("button",{type:"button",className:r.tileAction,"aria-label":E("fileUploader.editAlt",{name:T}),onClick:z,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Text",size:"sm"})}),de,B&&t.jsx("button",{type:"button",className:L.clsx(r.tileAction,r.tileActionEnd),"aria-label":E("fileUploader.preview",{name:T}),onClick:B,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Eye",size:"sm"})})]})]})}const Mo=d.forwardRef(function({multiple:o=!1,allowDrop:l=!0,allowReorder:p=!0,allowDownload:S=!0,allowPreview:w=!0,allowAltText:N=!0,altTextLocales:P,localizedAltText:h=!0,allowDuplicates:z=!1,disabled:_=!1,accept:B,maxFiles:i,maxFileSize:$,itemInsertLocation:O="end",value:G,defaultValue:Y,onChange:A,label:W,error:X,helperText:E,required:T=!1,fullWidth:Z=!0,name:U,id:J,onBlur:c,className:y,style:g,...k},q){var We;const he=d.useId(),de=J??he,m=`${de}-helper`,F=$!=null?Ro($):void 0,[ue,xe]=d.useState(null);d.useEffect(()=>{if(!ue)return;const e=window.setTimeout(()=>xe(null),4e3);return()=>window.clearTimeout(e)},[ue]);const ee=zt.useFormContext(),Ee=!!(ee&&U),D=ee&&U?ee.field(U):void 0,ke=o?[]:null,Re=G!==void 0?G:Ee?ee.values[U]??ke:void 0,ze=Re!==void 0,[Xe,Ze]=d.useState(Y??ke),te=ze?Re:Xe,x=te==null?[]:Array.isArray(te)?te:[te],_e=X??(D==null?void 0:D.error)??!1,et=E??(D==null?void 0:D.helperText),be=ue??et,tt=!!ue||_e,fe=p&&o&&!_,Fe=d.useRef(new WeakMap),De=d.useRef(0),ot=(e,s)=>{if(e.file){let a=Fe.current.get(e.file);return a||(De.current+=1,a=`f${De.current}`,Fe.current.set(e.file,a)),a}return e.source?`s:${e.source}`:`i:${s}`},I=x.map((e,s)=>ot(e,s)),Ce=d.useRef(new Set),nt=new Set(I.filter(e=>!Ce.current.has(e)));d.useEffect(()=>{Ce.current=new Set(I)});const[st,Me]=d.useState(()=>new Set),rt=e=>Me(s=>s.has(e)?s:new Set(s).add(e)),[at,lt]=d.useState(()=>new Set),it=e=>lt(s=>s.has(e)?s:new Set(s).add(e)),pe=d.useRef(new Map),ge=e=>{if(e.file){const s=e.file.type;if(!s.startsWith("image/")&&!s.startsWith("video/")||!Je()||at.has(e.file))return null;let a=pe.current.get(e.file);return a||(a=URL.createObjectURL(e.file),pe.current.set(e.file,a)),a}return e.source&&!st.has(e.source)?e.source:null},[C,Pe]=d.useState(null);d.useEffect(()=>{const e=pe.current,s=new Set(x.map(u=>u.file).filter(Boolean)),a=new Set(x.filter(u=>!u.file&&u.source).map(u=>u.source));for(const[u,f]of e)!s.has(u)&&f!==(C==null?void 0:C.url)&&(URL.revokeObjectURL(f),e.delete(u));Me(u=>{if(u.size===0)return u;const f=new Set([...u].filter(v=>a.has(v)));return f.size===u.size?u:f})},[te,C]),d.useEffect(()=>{const e=pe.current;return()=>{for(const s of e.values())URL.revokeObjectURL(s);e.clear()}},[]);const ct=e=>e.map((s,a)=>s.sortIndex===a?s:{...s,sortIndex:a}),oe=e=>{const s=ct(e),a=o?s:s[0]??null;ze||Ze(a),Ee&&ee.setValue(U,a),A==null||A(a)},ye=()=>D==null?void 0:D.onBlur({}),b=ce.useT(),dt=ce.useLocales(),qe=P??dt,ut=h&&qe.length>0?qe:[{code:""}],[ne,ve]=d.useState(null),[Le,Be]=d.useState("altText"),je=ne!=null?I.indexOf(ne):-1,R=je!==-1?x[je]:null,ft=e=>{Be("crop"),ve(I[e]??null)},pt=e=>{Be("altText"),ve(I[e]??null)},Se=()=>ve(null),gt=e=>{const s=ge(e);if(!s)return;const a=e.file?e.file.type==="image/svg+xml":/^data:image\/svg/i.test(e.source??"")||/\.svg(?:[?#]|$)/i.test(e.source??"");Pe({url:s,isVideo:Ne(e),isSvg:a,name:me(e)})},mt=R?h?R.altText&&typeof R.altText=="object"?{...R.altText}:{}:{"":typeof R.altText=="string"?R.altText:""}:{},ht=({draft:e,croppedFile:s})=>{if(je===-1)return Se();oe(x.map((a,u)=>{if(I[u]!==ne)return a;const f={...a};if(e!==void 0)if(h){const v=Object.fromEntries(Object.entries(e).map(([H,j])=>[H,j.trim()]).filter(([,H])=>H!==""));f.altText=Object.keys(v).length>0?v:void 0}else f.altText=(e[""]??"").trim()||void 0;return s&&(f.file=s,f.source=""),f})),Se()},xt=(e,s=[])=>{const a=s.filter(j=>j.errors.some(K=>K.code==="file-invalid-type")),u=s.filter(j=>j.errors.some(K=>K.code==="file-too-large"));a.length>0&&Ve.toast.error(a.length===1?b("fileUploader.wrongTypeOne",{name:a[0].file.name}):b("fileUploader.wrongTypeMany",{count:a.length})),u.length>0&&F!=null&&Ve.toast.error(u.length===1?b("fileUploader.tooLargeOne",{name:u[0].file.name,size:le(F)}):b("fileUploader.tooLargeMany",{count:u.length,size:le(F)}));const f=[];let v=e;if(o&&!z){const j=new Set(x.map(zo)),K=[];for(const He of v){const Ke=Qe(He);j.has(Ke)||(j.add(Ke),K.push(He))}K.length<v.length&&f.push(b("fileUploader.duplicate")),v=K}if(o&&i!=null){const j=Math.max(0,i-x.length);v.length>j&&(v=v.slice(0,j),f.push(i===1?b("fileUploader.hintUpToOne",{count:i}):b("fileUploader.hintUpToMany",{count:i})))}if(xe(f.length>0?f.join(" · "):null),v.length===0)return;const H=v.map(j=>({file:j,source:"",sortIndex:0}));if(!o){oe([H[0]]);return}oe(O==="start"?[...H,...x]:[...x,...H])},_t=e=>{xe(null),oe(x.filter((s,a)=>a!==e)),ye()},[bt,Te]=kt.useAutoAnimate(ko),$e=()=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>Te(!0)):Te(!0)},yt=()=>Te(!1),vt=()=>$e(),jt=e=>{const{active:s,over:a}=e;if(a&&s.id!==a.id){const u=I.indexOf(String(s.id)),f=I.indexOf(String(a.id));u!==-1&&f!==-1&&oe(ae.arrayMove(x,u,f))}$e()},St=V.useSensors(V.useSensor(V.PointerSensor,{activationConstraint:{distance:5}}),V.useSensor(V.KeyboardSensor,{coordinateGetter:ae.sortableKeyboardCoordinates})),se=d.useRef(!1),{getRootProps:Tt,getInputProps:Ut,isDragActive:It}=Rt.useDropzone({multiple:o,accept:B,maxSize:F,disabled:_,noKeyboard:!1,noDrag:!l,onFileDialogOpen:()=>{se.current=!0},onFileDialogCancel:()=>{se.current=!1,ye()},onDrop:(e,s)=>{se.current=!1,xt(e,s)}}),Oe=o||x.length===0,Ue=[];o&&i!=null&&Ue.push(i===1?b("fileUploader.hintUpToOne",{count:i}):b("fileUploader.hintUpToMany",{count:i})),F!=null&&Ue.push(b("fileUploader.hintMax",{size:le(F)}));const Ae=Ue.join(" · "),wt=l?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:r.accent,children:b("fileUploader.choose")})," ",b("fileUploader.dropSuffix")]}):t.jsx("span",{className:r.accent,children:b("fileUploader.choose")}),Nt=e=>{if(c==null||c(e),!e.currentTarget.contains(e.relatedTarget)&&ne==null){if(se.current){se.current=!1;return}ye()}};return t.jsxs("div",{ref:q,id:de,className:L.clsx(r.root,Z&&r.fullWidth,_e&&r.error,_&&r.disabled,y),style:g,"aria-invalid":_e||void 0,"aria-describedby":be!=null?m:void 0,onBlur:Nt,...k,...U?{name:U,tabIndex:-1}:{},children:[W!=null&&t.jsxs("label",{className:Ie.fieldStyles.label,children:[t.jsx(ie.Typography,{as:"span",variant:"bodySmall",color:"muted",children:W}),T&&t.jsx("span",{className:Ie.fieldStyles.required,"aria-hidden":"true",children:"*"})]}),Oe&&t.jsxs("div",{...Tt({className:L.clsx(r.dropzone,It&&r.dropping)}),children:[t.jsx("input",{...Ut()}),t.jsx("span",{className:r.dropIcon,"aria-hidden":"true",children:t.jsx(M.Icon,{name:"DocumentUpload",size:"lg"})}),t.jsxs("span",{className:r.dropText,children:[t.jsx("span",{className:r.prompt,children:wt}),Ae&&t.jsx("span",{className:r.hint,children:Ae})]})]}),t.jsx(V.DndContext,{sensors:St,collisionDetection:V.closestCenter,onDragStart:fe?yt:void 0,onDragEnd:fe?jt:void 0,onDragCancel:fe?vt:void 0,children:t.jsx(ae.SortableContext,{items:I,strategy:ae.rectSortingStrategy,children:t.jsx("div",{ref:bt,className:L.clsx(r.list,Oe&&x.length>0&&r.populated),children:x.map((e,s)=>t.jsx(Co,{id:I[s],item:e,preview:ge(e),sortable:fe&&x.length>1,entering:nt.has(I[s]),disabled:_,error:e.file&&F!=null&&e.file.size>F?b("fileUploader.exceedsLimit",{size:le(F)}):void 0,onRemove:()=>_t(s),onCrop:N&&!_&&we(e)?()=>ft(s):void 0,onAltText:N&&!_&&we(e)?()=>pt(s):void 0,onDownload:S&&!_?()=>Fo(e):void 0,onView:w&&!_&&ge(e)!=null&&(we(e)||Ne(e))?()=>gt(e):void 0,onPreviewError:e.file?()=>it(e.file):e.source?()=>rt(e.source):void 0},I[s]))})})}),be!=null&&t.jsx(ie.Typography,{as:"span",id:m,variant:"bodySmall",color:tt?"error":"muted",className:Ie.fieldStyles.helper,role:"status","aria-live":"polite",children:be}),R&&t.jsx(Ot,{mode:Le,name:me(R),imageUrl:ge(R),mimeType:((We=R.file)==null?void 0:We.type)||"image/png",editLocales:ut,initialDraft:mt,onClose:Se,onSave:ht},`${ne}:${Le}`),C&&t.jsx(Vt,{url:C.url,isVideo:C.isVideo,isSvg:C.isSvg,name:C.name,onClose:()=>Pe(null)})]})});exports.FileUploader=Mo;
|
|
2
|
-
//# sourceMappingURL=FileUploader-
|
|
1
|
+
"use strict";const t=require("react/jsx-runtime"),d=require("react"),L=require("clsx"),V=require("@dnd-kit/core"),ae=require("@dnd-kit/sortable"),Et=require("@dnd-kit/utilities"),kt=require("@formkit/auto-animate/react"),Rt=require("react-dropzone"),zt=require("./formContext-bTWrqdEV.cjs"),Ve=require("./toastStore-B4Tk2Xk7.cjs"),M=require("./Icon-BUP5_kRs.cjs"),Ft=require("./Skeleton-DK0lAjS9.cjs"),ie=require("./Typography-B6ASPrzT.cjs"),Dt=require("react-image-crop"),Ge=require("./Button-BD5wpg-t.cjs"),Ye=require("./Modal-BL_XihC8.cjs"),Ct=require("./TextField-CgPfN-4d.cjs"),ce=require("./ConfigProvider-CVLHPXQm.cjs"),Ie=require("./TextField.module-DsNCo8vN.cjs"),Mt="_cropSection_1j2zs_4",Pt="_cropHead_1j2zs_10",qt="_cropStage_1j2zs_16",Lt="_crop_1j2zs_4",Bt="_cropImg_1j2zs_30",$t="_altFields_1j2zs_35",Q={cropSection:Mt,cropHead:Pt,cropStage:qt,crop:Lt,cropImg:Bt,altFields:$t};function Ot({mode:n,name:o,imageUrl:l,mimeType:p,editLocales:S,initialDraft:w,onClose:N,onSave:P}){const h=ce.useT(),z=d.useRef(null),[_,B]=d.useState(),[i,$]=d.useState(null),[O,G]=d.useState(null),[Y,A]=d.useState(w),[W,X]=d.useState(null),[E,T]=d.useState(!1),Z=(c,y)=>{B(y);const g=z.current;if(g&&g.width>0&&c.width>=1&&c.height>=1){const k=g.naturalWidth/g.width,q=g.naturalHeight/g.height;$({x:Math.round(c.x*k),y:Math.round(c.y*q),width:Math.round(c.width*k),height:Math.round(c.height*q)})}else $(null)},U=async()=>{const c=z.current;if(!c||!i||i.width<1||i.height<1)return;const y=document.createElement("canvas");y.width=i.width,y.height=i.height;const g=y.getContext("2d");if(!g)return;g.imageSmoothingEnabled=!1,g.drawImage(c,i.x,i.y,i.width,i.height,0,0,i.width,i.height);const k=await new Promise(q=>y.toBlob(q,p,1));if(!k)throw new Error("canvas.toBlob returned null");return new File([k],o,{type:p,lastModified:Date.now()})},J=async()=>{if(n==="altText"){P({draft:Y});return}T(!0);try{const c=i&&i.width>=1&&i.height>=1?await U():void 0;P({croppedFile:c})}catch{X(h("fileUploader.cropError")),T(!1)}};return t.jsx(Ye.Modal,{open:!0,onClose:N,size:n==="crop"?"lg":"sm",icon:n==="crop"?"Crop":"Text",title:h(n==="crop"?"fileUploader.cropTitle":"fileUploader.altTitle"),description:o,footer:t.jsxs(t.Fragment,{children:[t.jsx(Ge.Button,{variant:"text",color:"accent",size:"sm",onClick:N,disabled:E,children:h("common.cancel")}),t.jsx(Ge.Button,{size:"sm",onClick:J,loading:E,children:h("common.save")})]}),children:n==="crop"?t.jsxs("div",{className:Q.cropSection,children:[t.jsxs("div",{className:Q.cropHead,children:[t.jsx(ie.Typography,{variant:"bodySmall",color:"muted",children:h("fileUploader.cropHint")}),t.jsx(ie.Typography,{variant:"bodySmall",color:i?"text":"muted",children:i?`${i.width} × ${i.height} px`:O?`${O.w} × ${O.h} px`:""})]}),t.jsx("div",{className:Q.cropStage,children:t.jsx(Dt,{crop:_,onChange:Z,className:Q.crop,children:t.jsx("img",{ref:z,src:l??void 0,alt:"",className:Q.cropImg,onLoad:c=>G({w:c.currentTarget.naturalWidth,h:c.currentTarget.naturalHeight})})})}),W&&t.jsx(ie.Typography,{variant:"bodySmall",color:"error",children:W})]}):t.jsx("div",{className:Q.altFields,children:S.map(c=>t.jsx(Ct.TextField,{label:c.label??(c.code||h("fileUploader.altTitle")),placeholder:h("fileUploader.altPlaceholder"),value:Y[c.code]??"",onChange:y=>A(g=>({...g,[c.code]:y.target.value}))},c.code))})})}const At="_backdrop_uqdv2_5",Wt="_media_uqdv2_9",Ht="_mediaSvg_uqdv2_19",Kt="_close_uqdv2_27",re={backdrop:At,media:Wt,mediaSvg:Ht,close:Kt};function Vt({url:n,isVideo:o,isSvg:l,name:p,onClose:S}){const w=ce.useT();return t.jsxs(Ye.Overlay,{open:!0,onClose:S,dim:.85,className:re.backdrop,role:"dialog","aria-modal":"true","aria-label":w("fileUploader.preview",{name:p}),children:[t.jsx("button",{type:"button",className:re.close,"aria-label":w("fileUploader.closePreview"),onClick:S,autoFocus:!0,children:t.jsx(M.Icon,{name:"Close",size:"lg"})}),o?t.jsx("video",{src:n,className:re.media,controls:!0,playsInline:!0}):t.jsx("img",{src:n,alt:p,className:L.clsx(re.media,l&&re.mediaSvg)})]})}const Gt="_root_m8xag_4",Yt="_fullWidth_m8xag_9",Jt="_disabled_m8xag_14",Qt="_dropzone_m8xag_17",Xt="_dropText_m8xag_41",Zt="_dropping_m8xag_56",eo="_error_m8xag_61",to="_dropIcon_m8xag_65",oo="_prompt_m8xag_77",no="_accent_m8xag_82",so="_hint_m8xag_87",ro="_list_m8xag_93",ao="_populated_m8xag_103",lo="_tile_m8xag_121",io="_grabbable_m8xag_130",co="_entering_m8xag_139",uo="_dragging_m8xag_142",fo="_tileError_m8xag_148",po="_tileImg_m8xag_153",go="_tileImgPending_m8xag_161",mo="_tileSkeleton_m8xag_164",ho="_tileFallback_m8xag_169",xo="_tilePlay_m8xag_179",_o="_tileTop_m8xag_198",bo="_tileBottom_m8xag_208",yo="_tileRemove_m8xag_218",vo="_tileAction_m8xag_219",jo="_tileActionEnd_m8xag_254",So="_tileText_m8xag_257",To="_name_m8xag_264",Uo="_nameBase_m8xag_271",Io="_nameExt_m8xag_277",wo="_tileMeta_m8xag_281",No="_metaError_m8xag_285",r={root:Gt,fullWidth:Yt,disabled:Jt,dropzone:Qt,dropText:Xt,dropping:Zt,error:eo,dropIcon:to,prompt:oo,accent:no,hint:so,list:ro,populated:ao,tile:lo,grabbable:io,entering:co,dragging:uo,tileError:fo,tileImg:po,tileImgPending:go,tileSkeleton:mo,tileFallback:ho,tilePlay:xo,tileTop:_o,tileBottom:bo,tileRemove:yo,tileAction:vo,tileActionEnd:jo,tileText:So,name:To,nameBase:Uo,nameExt:Io,tileMeta:wo,metaError:No},Je=()=>typeof URL<"u"&&typeof URL.createObjectURL=="function",Eo=300,ko=(n,o,l,p)=>{let S=[{},{}],w=Eo;if(o==="add")w=0;else if(o==="remove")S=[{opacity:1,transform:"translateY(0)"},{opacity:0,transform:"translateY(-8px)"}];else if(l&&p){const N=l.left-p.left,P=l.top-p.top;S=[{transform:`translate(${N}px, ${P}px)`},{transform:"translate(0, 0)"}]}return new KeyframeEffect(n,S,{duration:w,easing:"ease-out"})},le=n=>{if(n<1024)return`${n} B`;const o=["KB","MB","GB","TB"];let l=n/1024,p=0;for(;l>=1024&&p<o.length-1;)l/=1024,p+=1;return`${l.toFixed(l<10?1:0)} ${o[p]}`},Ro=n=>{if(typeof n=="number")return n;const o=/^\s*([\d.]+)\s*(b|kb|mb|gb|tb)?\s*$/i.exec(n);if(!o)return;const l={b:1,kb:1024,mb:1024**2,gb:1024**3,tb:1024**4};return parseFloat(o[1])*(l[(o[2]||"b").toLowerCase()]??1)},Qe=n=>`f:${n.name}:${n.size}:${n.lastModified}`,zo=n=>n.file?Qe(n.file):`s:${n.source??""}`,me=n=>n.file?n.file.name:n.source?/^(data|blob):/i.test(n.source)?"File":n.source.split(/[?#]/)[0].split("/").pop()||"File":"File",we=n=>{if(n.file)return n.file.type.startsWith("image/");const o=n.source;return o?/^data:image\//i.test(o)?!0:/^data:/i.test(o)?!1:/\.(png|jpe?g|gif|webp|avif|svg|bmp|ico|heic|heif)(?:[?#]|$)/i.test(o)||!/\.[a-z0-9]{1,8}(?:[?#]|$)/i.test(o):!1},Ne=n=>{if(n.file)return n.file.type.startsWith("video/");const o=n.source;return o?/^data:video\//i.test(o)||/\.(mp4|webm|ogg|ogv|mov|m4v|avi|mkv)(?:[?#]|$)/i.test(o):!1},Fo=n=>{if(typeof document>"u")return;const o=document.createElement("a");if(o.style.display="none",n.file){if(!Je())return;const l=URL.createObjectURL(n.file);o.href=l,o.download=n.file.name,document.body.appendChild(o),o.click(),o.remove(),setTimeout(()=>URL.revokeObjectURL(l),1e3)}else n.source&&(o.href=n.source,o.download=me(n),o.target="_blank",o.rel="noopener",document.body.appendChild(o),o.click(),o.remove())},Do=n=>{const o=n.lastIndexOf(".");return o>0&&n.length-o<=7?{base:n.slice(0,o),ext:n.slice(o)}:{base:n,ext:""}};function Co({id:n,item:o,preview:l,sortable:p,entering:S,disabled:w,error:N,onRemove:P,onCrop:h,onAltText:z,onDownload:_,onView:B,onPreviewError:i}){const{attributes:$,listeners:O,setNodeRef:G,transform:Y,transition:A,isDragging:W}=ae.useSortable({id:n,disabled:!p}),X={transform:Et.CSS.Transform.toString(Y),transition:A},E=ce.useT(),T=me(o),{base:Z,ext:U}=Do(T),[J,c]=d.useState(()=>!l||l.startsWith("blob:")),y=d.useRef(l);y.current!==l&&(y.current=l,c(!l||l.startsWith("blob:")));const g=d.useRef(null);d.useEffect(()=>{const m=g.current;m!=null&&m.complete&&m.naturalWidth>0&&c(!0)},[l]);const k=()=>{c(!0),i==null||i()},q=o.file?le(o.file.size):E("fileUploader.uploaded"),he=Ne(o),de=_?t.jsx("button",{type:"button",className:r.tileAction,"aria-label":E("fileUploader.download",{name:T}),onClick:_,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"DocumentDownload",size:"sm"})}):null;return t.jsxs("div",{ref:G,style:X,className:L.clsx(r.tile,p&&r.grabbable,S&&r.entering,W&&r.dragging,N&&r.tileError),...$,...O,children:[l&&!J&&t.jsx(Ft.Skeleton,{variant:"rect",width:"100%",height:"100%",className:r.tileSkeleton}),l?he?t.jsxs(t.Fragment,{children:[t.jsx("video",{src:l,className:r.tileImg,muted:!0,playsInline:!0,preload:"metadata",draggable:!1,onLoadedData:()=>c(!0),onError:k}),t.jsx("span",{className:r.tilePlay,"aria-hidden":"true",children:t.jsx(M.Icon,{name:"Play",size:"lg"})})]}):t.jsx("img",{ref:g,src:l,alt:"",className:L.clsx(r.tileImg,!J&&r.tileImgPending),draggable:!1,onLoad:()=>c(!0),onError:k}):t.jsx("span",{className:r.tileFallback,"aria-hidden":"true",children:t.jsx(M.Icon,{name:"Document",size:"lg"})}),t.jsxs("div",{className:r.tileTop,children:[t.jsxs("span",{className:r.tileText,children:[t.jsxs("span",{className:r.name,title:T,children:[t.jsx("span",{className:r.nameBase,children:Z}),U&&t.jsx("span",{className:r.nameExt,children:U})]}),t.jsx("span",{className:L.clsx(r.tileMeta,N&&r.metaError),children:N??q})]}),!w&&t.jsx("button",{type:"button",className:r.tileRemove,"aria-label":E("fileUploader.remove",{name:T}),onClick:P,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Close",size:"sm"})})]}),(h||z||_||B)&&t.jsxs("div",{className:r.tileBottom,children:[h&&t.jsx("button",{type:"button",className:r.tileAction,"aria-label":E("fileUploader.crop",{name:T}),onClick:h,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Crop",size:"sm"})}),z&&t.jsx("button",{type:"button",className:r.tileAction,"aria-label":E("fileUploader.editAlt",{name:T}),onClick:z,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Text",size:"sm"})}),de,B&&t.jsx("button",{type:"button",className:L.clsx(r.tileAction,r.tileActionEnd),"aria-label":E("fileUploader.preview",{name:T}),onClick:B,onPointerDown:m=>m.stopPropagation(),children:t.jsx(M.Icon,{name:"Eye",size:"sm"})})]})]})}const Mo=d.forwardRef(function({multiple:o=!1,allowDrop:l=!0,allowReorder:p=!0,allowDownload:S=!0,allowPreview:w=!0,allowAltText:N=!0,altTextLocales:P,localizedAltText:h=!0,allowDuplicates:z=!1,disabled:_=!1,accept:B,maxFiles:i,maxFileSize:$,itemInsertLocation:O="end",value:G,defaultValue:Y,onChange:A,label:W,error:X,helperText:E,required:T=!1,fullWidth:Z=!0,name:U,id:J,onBlur:c,className:y,style:g,...k},q){var We;const he=d.useId(),de=J??he,m=`${de}-helper`,F=$!=null?Ro($):void 0,[ue,xe]=d.useState(null);d.useEffect(()=>{if(!ue)return;const e=window.setTimeout(()=>xe(null),4e3);return()=>window.clearTimeout(e)},[ue]);const ee=zt.useFormContext(),Ee=!!(ee&&U),D=ee&&U?ee.field(U):void 0,ke=o?[]:null,Re=G!==void 0?G:Ee?ee.values[U]??ke:void 0,ze=Re!==void 0,[Xe,Ze]=d.useState(Y??ke),te=ze?Re:Xe,x=te==null?[]:Array.isArray(te)?te:[te],_e=X??(D==null?void 0:D.error)??!1,et=E??(D==null?void 0:D.helperText),be=ue??et,tt=!!ue||_e,fe=p&&o&&!_,Fe=d.useRef(new WeakMap),De=d.useRef(0),ot=(e,s)=>{if(e.file){let a=Fe.current.get(e.file);return a||(De.current+=1,a=`f${De.current}`,Fe.current.set(e.file,a)),a}return e.source?`s:${e.source}`:`i:${s}`},I=x.map((e,s)=>ot(e,s)),Ce=d.useRef(new Set),nt=new Set(I.filter(e=>!Ce.current.has(e)));d.useEffect(()=>{Ce.current=new Set(I)});const[st,Me]=d.useState(()=>new Set),rt=e=>Me(s=>s.has(e)?s:new Set(s).add(e)),[at,lt]=d.useState(()=>new Set),it=e=>lt(s=>s.has(e)?s:new Set(s).add(e)),pe=d.useRef(new Map),ge=e=>{if(e.file){const s=e.file.type;if(!s.startsWith("image/")&&!s.startsWith("video/")||!Je()||at.has(e.file))return null;let a=pe.current.get(e.file);return a||(a=URL.createObjectURL(e.file),pe.current.set(e.file,a)),a}return e.source&&!st.has(e.source)?e.source:null},[C,Pe]=d.useState(null);d.useEffect(()=>{const e=pe.current,s=new Set(x.map(u=>u.file).filter(Boolean)),a=new Set(x.filter(u=>!u.file&&u.source).map(u=>u.source));for(const[u,f]of e)!s.has(u)&&f!==(C==null?void 0:C.url)&&(URL.revokeObjectURL(f),e.delete(u));Me(u=>{if(u.size===0)return u;const f=new Set([...u].filter(v=>a.has(v)));return f.size===u.size?u:f})},[te,C]),d.useEffect(()=>{const e=pe.current;return()=>{for(const s of e.values())URL.revokeObjectURL(s);e.clear()}},[]);const ct=e=>e.map((s,a)=>s.sortIndex===a?s:{...s,sortIndex:a}),oe=e=>{const s=ct(e),a=o?s:s[0]??null;ze||Ze(a),Ee&&ee.setValue(U,a),A==null||A(a)},ye=()=>D==null?void 0:D.onBlur({}),b=ce.useT(),dt=ce.useLocales(),qe=P??dt,ut=h&&qe.length>0?qe:[{code:""}],[ne,ve]=d.useState(null),[Le,Be]=d.useState("altText"),je=ne!=null?I.indexOf(ne):-1,R=je!==-1?x[je]:null,ft=e=>{Be("crop"),ve(I[e]??null)},pt=e=>{Be("altText"),ve(I[e]??null)},Se=()=>ve(null),gt=e=>{const s=ge(e);if(!s)return;const a=e.file?e.file.type==="image/svg+xml":/^data:image\/svg/i.test(e.source??"")||/\.svg(?:[?#]|$)/i.test(e.source??"");Pe({url:s,isVideo:Ne(e),isSvg:a,name:me(e)})},mt=R?h?R.altText&&typeof R.altText=="object"?{...R.altText}:{}:{"":typeof R.altText=="string"?R.altText:""}:{},ht=({draft:e,croppedFile:s})=>{if(je===-1)return Se();oe(x.map((a,u)=>{if(I[u]!==ne)return a;const f={...a};if(e!==void 0)if(h){const v=Object.fromEntries(Object.entries(e).map(([H,j])=>[H,j.trim()]).filter(([,H])=>H!==""));f.altText=Object.keys(v).length>0?v:void 0}else f.altText=(e[""]??"").trim()||void 0;return s&&(f.file=s,f.source=""),f})),Se()},xt=(e,s=[])=>{const a=s.filter(j=>j.errors.some(K=>K.code==="file-invalid-type")),u=s.filter(j=>j.errors.some(K=>K.code==="file-too-large"));a.length>0&&Ve.toast.error(a.length===1?b("fileUploader.wrongTypeOne",{name:a[0].file.name}):b("fileUploader.wrongTypeMany",{count:a.length})),u.length>0&&F!=null&&Ve.toast.error(u.length===1?b("fileUploader.tooLargeOne",{name:u[0].file.name,size:le(F)}):b("fileUploader.tooLargeMany",{count:u.length,size:le(F)}));const f=[];let v=e;if(o&&!z){const j=new Set(x.map(zo)),K=[];for(const He of v){const Ke=Qe(He);j.has(Ke)||(j.add(Ke),K.push(He))}K.length<v.length&&f.push(b("fileUploader.duplicate")),v=K}if(o&&i!=null){const j=Math.max(0,i-x.length);v.length>j&&(v=v.slice(0,j),f.push(i===1?b("fileUploader.hintUpToOne",{count:i}):b("fileUploader.hintUpToMany",{count:i})))}if(xe(f.length>0?f.join(" · "):null),v.length===0)return;const H=v.map(j=>({file:j,source:"",sortIndex:0}));if(!o){oe([H[0]]);return}oe(O==="start"?[...H,...x]:[...x,...H])},_t=e=>{xe(null),oe(x.filter((s,a)=>a!==e)),ye()},[bt,Te]=kt.useAutoAnimate(ko),$e=()=>{typeof requestAnimationFrame=="function"?requestAnimationFrame(()=>Te(!0)):Te(!0)},yt=()=>Te(!1),vt=()=>$e(),jt=e=>{const{active:s,over:a}=e;if(a&&s.id!==a.id){const u=I.indexOf(String(s.id)),f=I.indexOf(String(a.id));u!==-1&&f!==-1&&oe(ae.arrayMove(x,u,f))}$e()},St=V.useSensors(V.useSensor(V.PointerSensor,{activationConstraint:{distance:5}}),V.useSensor(V.KeyboardSensor,{coordinateGetter:ae.sortableKeyboardCoordinates})),se=d.useRef(!1),{getRootProps:Tt,getInputProps:Ut,isDragActive:It}=Rt.useDropzone({multiple:o,accept:B,maxSize:F,disabled:_,noKeyboard:!1,noDrag:!l,onFileDialogOpen:()=>{se.current=!0},onFileDialogCancel:()=>{se.current=!1,ye()},onDrop:(e,s)=>{se.current=!1,xt(e,s)}}),Oe=o||x.length===0,Ue=[];o&&i!=null&&Ue.push(i===1?b("fileUploader.hintUpToOne",{count:i}):b("fileUploader.hintUpToMany",{count:i})),F!=null&&Ue.push(b("fileUploader.hintMax",{size:le(F)}));const Ae=Ue.join(" · "),wt=l?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:r.accent,children:b("fileUploader.choose")})," ",b("fileUploader.dropSuffix")]}):t.jsx("span",{className:r.accent,children:b("fileUploader.choose")}),Nt=e=>{if(c==null||c(e),!e.currentTarget.contains(e.relatedTarget)&&ne==null){if(se.current){se.current=!1;return}ye()}};return t.jsxs("div",{ref:q,id:de,className:L.clsx(r.root,Z&&r.fullWidth,_e&&r.error,_&&r.disabled,y),style:g,"aria-invalid":_e||void 0,"aria-describedby":be!=null?m:void 0,onBlur:Nt,...k,...U?{name:U,tabIndex:-1}:{},children:[W!=null&&t.jsxs("label",{className:Ie.fieldStyles.label,children:[t.jsx(ie.Typography,{as:"span",variant:"bodySmall",color:"muted",children:W}),T&&t.jsx("span",{className:Ie.fieldStyles.required,"aria-hidden":"true",children:"*"})]}),Oe&&t.jsxs("div",{...Tt({className:L.clsx(r.dropzone,It&&r.dropping)}),children:[t.jsx("input",{...Ut()}),t.jsx("span",{className:r.dropIcon,"aria-hidden":"true",children:t.jsx(M.Icon,{name:"DocumentUpload",size:"lg"})}),t.jsxs("span",{className:r.dropText,children:[t.jsx("span",{className:r.prompt,children:wt}),Ae&&t.jsx("span",{className:r.hint,children:Ae})]})]}),t.jsx(V.DndContext,{sensors:St,collisionDetection:V.closestCenter,onDragStart:fe?yt:void 0,onDragEnd:fe?jt:void 0,onDragCancel:fe?vt:void 0,children:t.jsx(ae.SortableContext,{items:I,strategy:ae.rectSortingStrategy,children:t.jsx("div",{ref:bt,className:L.clsx(r.list,Oe&&x.length>0&&r.populated),children:x.map((e,s)=>t.jsx(Co,{id:I[s],item:e,preview:ge(e),sortable:fe&&x.length>1,entering:nt.has(I[s]),disabled:_,error:e.file&&F!=null&&e.file.size>F?b("fileUploader.exceedsLimit",{size:le(F)}):void 0,onRemove:()=>_t(s),onCrop:N&&!_&&we(e)?()=>ft(s):void 0,onAltText:N&&!_&&we(e)?()=>pt(s):void 0,onDownload:S&&!_?()=>Fo(e):void 0,onView:w&&!_&&ge(e)!=null&&(we(e)||Ne(e))?()=>gt(e):void 0,onPreviewError:e.file?()=>it(e.file):e.source?()=>rt(e.source):void 0},I[s]))})})}),be!=null&&t.jsx(ie.Typography,{as:"span",id:m,variant:"bodySmall",color:tt?"error":"muted",className:Ie.fieldStyles.helper,role:"status","aria-live":"polite",children:be}),R&&t.jsx(Ot,{mode:Le,name:me(R),imageUrl:ge(R),mimeType:((We=R.file)==null?void 0:We.type)||"image/png",editLocales:ut,initialDraft:mt,onClose:Se,onSave:ht},`${ne}:${Le}`),C&&t.jsx(Vt,{url:C.url,isVideo:C.isVideo,isSvg:C.isSvg,name:C.name,onClose:()=>Pe(null)})]})});exports.FileUploader=Mo;
|
|
2
|
+
//# sourceMappingURL=FileUploader-4UMy0urx.cjs.map
|