@eturnity/eturnity_reusable_components 7.12.6-EPDM-7951.8 → 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.8",
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: {
@@ -103,18 +104,7 @@ const IconImage = styled.div`
103
104
  const icon = reactive({ html: '' })
104
105
 
105
106
  const loadSvg = async () => {
106
- const fileName = props.name.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 response = await fetch(fetchUrl)
114
- icon.html = await response.text()
115
- } catch (_) {
116
- console.error(`Failed to load ${props.name}.svg`)
117
- }
107
+ icon.html = await fetchIcon(props.name.toLowerCase())
118
108
  }
119
109
 
120
110
  onMounted(() => loadSvg())