Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update stencil version and improve logging #72

Open
wants to merge 23 commits into
base: release-3.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bc8fb52
post merge
nuke-ellington Jan 30, 2025
b2bcde7
test: update ct
nuke-ellington Jan 30, 2025
640908a
docs: update readme.md
nuke-ellington Jan 30, 2025
7a94349
Merge branch 'release-3.0.0' into v3-add-icons
nuke-ellington Jan 30, 2025
a39c758
ci: fix snapshot workflow
nuke-ellington Jan 30, 2025
6cc87a1
Merge branch 'main' into release-3.0.0
nuke-ellington Jan 30, 2025
3f6a87f
Merge branch 'release-3.0.0' into v3-add-icons
nuke-ellington Jan 30, 2025
95e6c1d
ci: fix version
nuke-ellington Jan 30, 2025
6f066d4
docs: update readme
danielleroux Jan 31, 2025
bb4a336
docs: update readme.md
nuke-ellington Jan 31, 2025
ae0acb3
fix: update latest stencil version
danielleroux Feb 3, 2025
3c7d7f6
fix: disable external runtime
danielleroux Feb 5, 2025
9f9c67d
fix: snapshots
danielleroux Feb 5, 2025
1222196
refactor: replace throw error with empty string
danielleroux Feb 5, 2025
ee7182b
Merge remote-tracking branch 'origin/release-3.0.0' into v3-add-icons
danielleroux Feb 5, 2025
b06998a
test: remove unused mock
danielleroux Feb 5, 2025
9917f3b
fix: fix error branch which results in object string
danielleroux Feb 5, 2025
15af300
feat: improve error logging
danielleroux Feb 26, 2025
160cfee
Merge remote-tracking branch 'origin/release-3.0.0' into error-loggin…
danielleroux Feb 26, 2025
5174fb3
update stencil version
danielleroux Feb 26, 2025
f43cad7
add changeset
danielleroux Feb 26, 2025
1053f27
add logging to parser
danielleroux Feb 27, 2025
c13a04e
pass through element
danielleroux Feb 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/light-schools-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@siemens/ix-icons': minor
---

- Improve logging include html element inside logging to identify which component creates the logging
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Improve logging include html element inside logging to identify which component creates the logging
- Improve logging by including HTML element in output to identify the source component.

- Update stencil version to 4.27.1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ SPDX-License-Identifier: MIT

## Usage

### Settng up with Siemens Industrial Experience design system
### Setting up with Siemens Industrial Experience design system

If you are also using the library [Siemens Industrial Experience](https://github.com/siemens/ix/), no additional project setup will be necessary. The packages `@siemens/ix-angular`, `@siemens/ix-react` or `@siemens/ix-vue` will take care of setting up the icon library for you.
If you are also using the library [Siemens Industrial Experience](https://github.com/siemens/ix/), no additional project setup will be necessary. The packages `@siemens/ix-angular`, `@siemens/ix-react` or `@siemens/ix-vue` will take care of setting up the icon library for you.

### Setting up without Siemens Industrial Experience design system

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ci:publish": "pnpm changeset publish"
},
"dependencies": {
"@stencil/core": "^4.25.1"
"@stencil/core": "^4.27.1"
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export namespace Components {
* Only fetch and parse svg data when icon is visible
*/
"lazyLoading": boolean;
/**
* @deprecated use camelCase instead. Support for dash-casing will be removed in Stencil v5.
*/
"lazy-loading"?: boolean;
/**
* Use one of our defined icon names e.g. `copy` https://ix.siemens.io/docs/icon-library/icons or the import variant ``` import { rocket } from '@siemens/ix-icons/icons'; <ix-icon name={rocket}></ix-icon> ```
*/
Expand Down Expand Up @@ -46,6 +50,10 @@ declare namespace LocalJSX {
* Only fetch and parse svg data when icon is visible
*/
"lazyLoading"?: boolean;
/**
* @deprecated use camelCase instead. Support for dash-casing will be removed in Stencil v5.
*/
"lazy-loading"?: boolean;
/**
* Use one of our defined icon names e.g. `copy` https://ix.siemens.io/docs/icon-library/icons or the import variant ``` import { rocket } from '@siemens/ix-icons/icons'; <ix-icon name={rocket}></ix-icon> ```
*/
Expand Down
8 changes: 6 additions & 2 deletions src/components/icon/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let parser: any = null;
export const errorSymbol =
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='512' height='512' viewBox='0 0 512 512'><path fill-rule='evenodd' d='M384,0 L384,384 L0,384 L0,0 L384,0 Z M192,207.085 L57.751,341.333 L326.248,341.333 L192,207.085 Z M42.666,57.751 L42.666,326.248 L176.915,192 L42.666,57.751 Z M341.333,57.751 L207.085,192 L341.333,326.248 L341.333,57.751 Z M326.248,42.666 L57.751,42.666 L192,176.915 L326.248,42.666 Z' transform='translate(64 64)'/></svg>";

export function parseSVGDataContent(content: string): string {
export function parseSVGDataContent(content: string, element?: HTMLElement): string {
if (typeof window['DOMParser'] === 'undefined') {
console.error('DOMParser not supported by your browser.');
return '';
Expand All @@ -21,7 +21,11 @@ export function parseSVGDataContent(content: string): string {
const svgElement = svgDocument.querySelector('svg') as HTMLElement;

if (!svgElement) {
console.error('No valid svg data provided');
if (element) {
console.error('No valid svg data provided', element);
} else {
console.error('No valid svg data provided');
}
return '';
}

Expand Down
29 changes: 17 additions & 12 deletions src/components/icon/resolveIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const isSvgDataUrl = (url: string) => {
return url.startsWith('data:image/svg+xml');
};

async function fetchSVG(url: string) {
async function fetchSVG(url: string, element: HTMLIxIconElement) {
const cache = getIconCacheMap();

if (cache.has(url)) {
Expand All @@ -61,16 +61,16 @@ async function fetchSVG(url: string) {

let svgContent = '';
if (response.ok) {
svgContent = parseSVGDataContent(responseText);
svgContent = parseSVGDataContent(responseText, element);
cache.set(url, svgContent);
} else {
console.error('Failed to request svg data from', url, 'with status code', response.status);
console.error('Failed to request svg data from', url, 'with status code', response.status, element);
}

return svgContent;
})
.catch(() => {
console.error('Failed to fetch svg data:', url);
console.error('Failed to fetch svg data:', url, element);
cache.set(url, '');
return '';
})
Expand All @@ -87,7 +87,7 @@ function isValidUrl(url: string) {
return urlRegex.test(url);
}

export function getIconUrl(name: string) {
export function getIconUrl(name: string, element: HTMLIxIconElement) {
const customAssetUrl = getCustomAssetUrl();

if (customAssetUrl) {
Expand All @@ -99,7 +99,7 @@ export function getIconUrl(name: string) {
try {
url = getAssetPath(url);
} catch (error) {
console.warn(`Could not load icon with name "${name}". Ensure that the icon is registered using addIcons or that the icon SVG data is passed directly to the property.`);
console.warn(`Could not load icon with name "${name}". Ensure that the icon is registered using addIcons or that the icon SVG data is passed directly to property.`, element);
}

return url;
Expand All @@ -112,30 +112,35 @@ export async function resolveIcon(element: HTMLIxIconElement, iconName?: string)
}

if (isSvgDataUrl(iconName)) {
return parseSVGDataContent(iconName);
const content = parseSVGDataContent(iconName, element);

if (!content) {
console.error('Failed to parse icon data', element);
}
return content;
}

return loadIcon(iconName);
return loadIcon(iconName, element);
}

async function loadIcon(iconName: string): Promise<string> {
async function loadIcon(iconName: string, element: HTMLIxIconElement): Promise<string> {
const cache = getIconCacheMap();

if (cache.has(iconName)) {
return cache.get(iconName)!;
}

if (isValidUrl(iconName)) {
return fetchSVG(iconName);
return fetchSVG(iconName, element);
}

const iconUrl = getIconUrl(iconName);
const iconUrl = getIconUrl(iconName, element);

if (!iconUrl) {
return '';
}

return fetchSVG(iconUrl);
return fetchSVG(iconUrl, element);
}

function removePrefix(name: string, prefix: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/icon/test/resolveIcon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ test('fill cache map if not loaded', async () => {
const data = await resolveIcon(element, 'star');

expect(data).toBe(parseSVGDataContent(iconStar));
expect(cacheMap.get(getIconUrl('star'))).toBe(parseSVGDataContent(iconStar));
expect(cacheMap.get(getIconUrl('star', element))).toBe(parseSVGDataContent(iconStar));
});

test('preload custom icon', async () => {
Expand All @@ -115,7 +115,7 @@ test('preload custom icon', async () => {
const cacheMap = getIconCacheMap();
cacheMap.clear();

cacheMap.set(getIconUrl('star'), '<svg>Test</svg>');
cacheMap.set(getIconUrl('star', element), '<svg>Test</svg>');

const data = await resolveIcon(element, 'star');
expect(data).toBe('<svg>Test</svg>');
Expand Down