@@ -7,13 +7,14 @@ import TextField from '@mui/material/TextField'
7
7
import { imageToBase64 } from '~/utils'
8
8
import Modal from '~/components/Modal'
9
9
10
- const modules = import . meta. glob ( '../../../assets/*.svg' , { eager : true } )
11
- const urls = Object . keys ( modules ) . map ( ( path ) => new URL ( path , import . meta. url ) . toString ( ) )
12
- const sortedIcons = urls . sort ( ( a , b ) => ( a . toUpperCase ( ) < b . toUpperCase ( ) ? - 1 : 1 ) )
13
- const icons = sortedIcons . map ( ( url ) => ( {
14
- name : decodeURIComponent ( url . split ( 'assets/' ) . pop ( ) ! . split ( '.svg' ) . shift ( ) as string ) ,
15
- url,
16
- } ) )
10
+ const modules = import . meta. glob ( '/assets/*.svg' , { as : 'raw' , eager : true } )
11
+ const icons = Object . entries ( modules ) . map ( ( [ key , value ] ) => {
12
+ const name = decodeURIComponent ( key . split ( 'assets/' ) . pop ( ) ! . split ( '.svg' ) . shift ( ) as string )
13
+ const svg = new Blob ( [ value ] , { type : 'image/svg+xml' } )
14
+ const url = URL . createObjectURL ( svg )
15
+ return { name, url }
16
+ } )
17
+ const sortedIcons = icons . sort ( ( a , b ) => ( a . name . toUpperCase ( ) < b . name . toUpperCase ( ) ? - 1 : 1 ) )
17
18
18
19
type Icon = {
19
20
name : string
@@ -47,7 +48,7 @@ const IconsModal = ({
47
48
const { t } = useTranslation ( )
48
49
const [ , startTransition ] = useTransition ( )
49
50
const [ searchTerm , setSearchTerm ] = useState ( '' )
50
- const [ filteredIcons , setFilteredIcons ] = useState ( icons )
51
+ const [ filteredIcons , setFilteredIcons ] = useState ( sortedIcons )
51
52
52
53
const onInputChange = ( event : React . ChangeEvent < HTMLTextAreaElement | HTMLInputElement > ) => {
53
54
const searchTerm = event . target . value
0 commit comments