@eturnity/eturnity_reusable_components 9.19.8 → 9.19.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": "9.19.8",
3
+ "version": "9.19.9",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -250,7 +250,12 @@
250
250
  const icon = reactive({ html: '' })
251
251
 
252
252
  const loadSvg = async () => {
253
- let svgString = await fetchIcon(props.name.toLowerCase())
253
+ const raw = props.name
254
+ if (raw == null || String(raw).trim() === '') {
255
+ icon.html = ''
256
+ return
257
+ }
258
+ let svgString = await fetchIcon(String(raw).toLowerCase())
254
259
  if (props.svgRotation) svgString = rotateSvg(svgString, props.svgRotation)
255
260
  icon.html = svgString
256
261
  }
@@ -1,23 +1,53 @@
1
+ /**
2
+ * Load SVG icon markup by file stem (lowercase), matching files in
3
+ * `src/assets/svgIcons/<stem>.svg`.
4
+ *
5
+ * Uses `import.meta.glob` instead of `new URL(..., import.meta.url)` + `fetch`
6
+ * so Vite does not emit a broken asset URL when this package is linked via
7
+ * `@fs/...` (which previously produced requests like `.../icon/undefined`).
8
+ */
9
+ const rawIconModules = import.meta.glob('../../assets/svgIcons/*.svg', {
10
+ query: '?raw',
11
+ import: 'default',
12
+ })
13
+
14
+ const iconLoadersByStem = {}
15
+ for (const path of Object.keys(rawIconModules)) {
16
+ const normalized = path.replace(/\\/g, '/')
17
+ const match = normalized.match(/\/([^/]+)\.svg$/i)
18
+ if (!match) continue
19
+ iconLoadersByStem[match[1].toLowerCase()] = rawIconModules[path]
20
+ }
21
+
1
22
  const iconCache = {}
2
23
 
3
24
  export const fetchIcon = async (fileName) => {
4
- if (iconCache[fileName]) {
5
- return iconCache[fileName]
25
+ if (fileName == null) {
26
+ console.warn('fetchIcon called with null or undefined fileName')
27
+ return ''
6
28
  }
7
29
 
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
30
+ const stem = String(fileName).trim().toLowerCase()
31
+ if (!stem) {
32
+ return ''
33
+ }
13
34
 
14
- try {
15
- const response = await fetch(fetchUrl)
16
- const rawFile = await response.text()
17
- iconCache[fileName] = rawFile
35
+ if (iconCache[stem]) {
36
+ return iconCache[stem]
37
+ }
38
+
39
+ const loader = iconLoadersByStem[stem]
40
+ if (!loader) {
41
+ console.error(`Unknown icon SVG: ${stem}.svg`)
42
+ return ''
43
+ }
18
44
 
45
+ try {
46
+ const rawFile = await loader()
47
+ iconCache[stem] = rawFile
19
48
  return rawFile
20
49
  } catch (error) {
21
- console.error(`Failed to load ${fileName}.svg`)
50
+ console.error(`Failed to load ${stem}.svg`, error)
51
+ return ''
22
52
  }
23
53
  }
@@ -142,6 +142,7 @@
142
142
  >
143
143
  <IconCell :is-collapsed="isCollapsed">
144
144
  <IconComponent
145
+ v-if="item.icon"
145
146
  :color="
146
147
  item.id === activeItemId
147
148
  ? theme.semanticColors.purple[500]
@@ -187,6 +188,7 @@
187
188
  >
188
189
  <IconCell :is-collapsed="isCollapsed">
189
190
  <IconComponent
191
+ v-if="item.icon"
190
192
  :color="
191
193
  item.id === activeParentId
192
194
  ? theme.semanticColors.purple[500]