@eturnity/eturnity_reusable_components 7.12.6-EPDM-7951.7 → 7.12.6-EPDM-7951.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "7.12.6-EPDM-7951.7",
3
+ "version": "7.12.6-EPDM-7951.9",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
@@ -0,0 +1,23 @@
1
+ const iconCache = {}
2
+
3
+ export const fetchIcon = async (fileName) => {
4
+ if (iconCache[fileName]) {
5
+ return iconCache[fileName]
6
+ }
7
+
8
+ // We need to use "new URL" to load dynamic assets (https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url)
9
+ const fetchUrl = new URL(
10
+ `../../assets/svgIcons/${fileName}.svg`,
11
+ import.meta.url
12
+ ).href
13
+
14
+ try {
15
+ const response = await fetch(fetchUrl)
16
+ const rawFile = await response.text()
17
+ iconCache[fileName] = rawFile
18
+
19
+ return rawFile
20
+ } catch (error) {
21
+ console.error(`Failed to load ${fileName}.svg`)
22
+ }
23
+ }
@@ -21,6 +21,7 @@
21
21
 
22
22
  import { onMounted, reactive, watch } from 'vue'
23
23
  import styled from 'vue3-styled-components'
24
+ import { fetchIcon } from './iconCache'
24
25
 
25
26
  const props = defineProps({
26
27
  disabled: {
@@ -102,29 +103,11 @@ const IconImage = styled.div`
102
103
 
103
104
  const icon = reactive({ html: '' })
104
105
 
105
- const loadSvg = async (fileName = props.name) => {
106
- const _fileName = fileName.toLowerCase()
107
- // We need to use "new URL" to load dynamic assets (https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url)
108
- const fetchUrl = new URL(
109
- `../../assets/svgIcons/${_fileName}.svg`,
110
- import.meta.url
111
- ).href
112
- try {
113
- const fetchResponse = await fetch(fetchUrl)
114
- icon.html = await fetchResponse.text()
115
- } catch (error) {
116
- console.error(`Failed to load ${props.name}.svg`)
117
- }
106
+ const loadSvg = async () => {
107
+ icon.html = await fetchIcon(props.name.toLowerCase())
118
108
  }
119
109
 
120
- onMounted(async () => {
121
- const iconPath = `../../assets/svgIcons/${props.name.toLowerCase()}.svg?raw`
122
- const module = await import(/* @vite-ignore */ iconPath)
123
- console.log(module.default)
124
- icon.html = module.default
125
- })
126
-
127
- // onMounted(() => loadSvg())
110
+ onMounted(() => loadSvg())
128
111
 
129
112
  watch(() => props.name, loadSvg)
130
113
  </script>