@noctuatech/uswds 1.4.6 → 1.4.8
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 +1 -1
- package/src/lib/define.ts +49 -49
- package/src/lib/icon/icon.element.ts +1 -12
- package/src/lib/services/icon.service.element.test.ts +30 -0
- package/src/lib/services/icon.service.ts +9 -10
- package/target/lib/define.d.ts +49 -49
- package/target/lib/define.js +49 -49
- package/target/lib/icon/icon.element.d.ts +0 -1
- package/target/lib/icon/icon.element.js +3 -14
- package/target/lib/icon/icon.element.js.map +1 -1
- package/target/lib/services/icon.service.d.ts +1 -1
- package/target/lib/services/icon.service.element.test.js +25 -0
- package/target/lib/services/icon.service.element.test.js.map +1 -1
- package/target/lib/services/icon.service.js +6 -7
- package/target/lib/services/icon.service.js.map +1 -1
package/package.json
CHANGED
package/src/lib/define.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
import
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
import
|
|
46
|
-
import
|
|
47
|
-
import
|
|
48
|
-
import
|
|
49
|
-
import
|
|
1
|
+
import './config/config.element.js';
|
|
2
|
+
import './alert/alert.element.js';
|
|
3
|
+
import './button/button.element.js';
|
|
4
|
+
import './checkbox/checkbox.element.js';
|
|
5
|
+
import './description/description.element.js';
|
|
6
|
+
import './file-input/file-input.element.js';
|
|
7
|
+
import './file-input/file-input-preview/file-input-preview.element.js';
|
|
8
|
+
import './icon/icon.element.js';
|
|
9
|
+
import './input/input.element.js';
|
|
10
|
+
import './input-mask/input-mask.element.js';
|
|
11
|
+
import './link/link.element.js';
|
|
12
|
+
import './radio/radio.element.js';
|
|
13
|
+
import './radio/radio-option/radio-option.element.js';
|
|
14
|
+
import './select/select.element.js';
|
|
15
|
+
import './select/select-option/select-option.element.js';
|
|
16
|
+
import './tag/tag.element.js';
|
|
17
|
+
import './accordion/accordion.element.js';
|
|
18
|
+
import './side-nav/side-nav.element.js';
|
|
19
|
+
import './side-nav/side-nav-item/side-nav-item.element.js';
|
|
20
|
+
import './summary-box/summary-box.element.js';
|
|
21
|
+
import './step-indicator/step-indicator.element.js';
|
|
22
|
+
import './step-indicator/step/step.element.js';
|
|
23
|
+
import './modal/modal.element.js';
|
|
24
|
+
import './modal/modal-close/modal-close.element.js';
|
|
25
|
+
import './modal/modal-heading/modal-heading.element.js';
|
|
26
|
+
import './card/card.element.js';
|
|
27
|
+
import './card/card-header/card-header.element.js';
|
|
28
|
+
import './card/card-body/card-body.element.js';
|
|
29
|
+
import './card/card-footer/card-footer.element.js';
|
|
30
|
+
import './card/card-media/card-media.element.js';
|
|
31
|
+
import './card/card-group/card-group.element.js';
|
|
32
|
+
import './textarea/textarea.element.js';
|
|
33
|
+
import './collection/collection.element.js';
|
|
34
|
+
import './collection/collection-item/collection-item.element.js';
|
|
35
|
+
import './checkbox/checkbox-group/checkbox-group.element.js';
|
|
36
|
+
import './range-slider/range-slider.element.js';
|
|
37
|
+
import './combo-box/combo-box.element.js';
|
|
38
|
+
import './combo-box/combo-box-option/combo-box-option.element.js';
|
|
39
|
+
import './search/search.element.js';
|
|
40
|
+
import './process-list/process-list.element.js';
|
|
41
|
+
import './process-list/process-list-item/process-list-item.element.js';
|
|
42
|
+
import './in-page-nav/in-page-nav.element.js';
|
|
43
|
+
import './in-page-nav/in-page-nav-item/in-page-nav-item.element.js';
|
|
44
|
+
import './button-group/button-group.element.js';
|
|
45
|
+
import './breadcrumbs/breadcrumbs.element.js';
|
|
46
|
+
import './breadcrumbs/breadcrumb/breadcrumb.element.js';
|
|
47
|
+
import './pagination/pagination.element.js';
|
|
48
|
+
import './pagination/pagination-item/pagination-item.element.js';
|
|
49
|
+
import './pagination/pagination-no/pagination-no.element.js';
|
|
@@ -3,7 +3,6 @@ import { attr, css, element } from '@joist/element';
|
|
|
3
3
|
|
|
4
4
|
import { IconService } from '../services/icon.service.js';
|
|
5
5
|
import type { USAIcon } from './icon-types.js';
|
|
6
|
-
import { effect, observe } from '@joist/observable';
|
|
7
6
|
|
|
8
7
|
declare global {
|
|
9
8
|
interface HTMLElementTagNameMap {
|
|
@@ -35,27 +34,17 @@ declare global {
|
|
|
35
34
|
})
|
|
36
35
|
export class USAIconElement extends HTMLElement {
|
|
37
36
|
@attr()
|
|
38
|
-
@observe()
|
|
39
37
|
accessor icon: USAIcon | '' = '';
|
|
40
38
|
|
|
41
39
|
ariaHidden: string | null = 'true';
|
|
42
40
|
|
|
43
41
|
#icon = inject(IconService);
|
|
44
|
-
#abortController: AbortController | null = null;
|
|
45
42
|
|
|
46
43
|
connectedCallback() {
|
|
47
44
|
this.#updateIcon();
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
@effect()
|
|
51
|
-
onIconUpdate() {
|
|
52
|
-
this.#updateIcon();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
47
|
async #updateIcon() {
|
|
56
|
-
this.#abortController?.abort();
|
|
57
|
-
this.#abortController = new AbortController();
|
|
58
|
-
|
|
59
48
|
if (!this.icon) {
|
|
60
49
|
return;
|
|
61
50
|
}
|
|
@@ -63,7 +52,7 @@ export class USAIconElement extends HTMLElement {
|
|
|
63
52
|
const icon = this.#icon();
|
|
64
53
|
|
|
65
54
|
icon
|
|
66
|
-
.getIcon(this.icon
|
|
55
|
+
.getIcon(this.icon)
|
|
67
56
|
.then((currentIcon) => {
|
|
68
57
|
if (this.shadowRoot) {
|
|
69
58
|
if (this.shadowRoot.firstElementChild) {
|
|
@@ -60,4 +60,34 @@ describe('IconService', () => {
|
|
|
60
60
|
assert.equal(res.nodeName, 'svg');
|
|
61
61
|
assert.equal(callCount, 1);
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
it('should not fetch multiple times if the same icon is requested at the same time', async () => {
|
|
65
|
+
let callCount = 0;
|
|
66
|
+
|
|
67
|
+
const app = new Injector({
|
|
68
|
+
providers: [
|
|
69
|
+
[
|
|
70
|
+
HttpService,
|
|
71
|
+
{
|
|
72
|
+
use: class extends HttpService {
|
|
73
|
+
async fetch(): Promise<Response> {
|
|
74
|
+
callCount++;
|
|
75
|
+
return new Response('<svg></svg>');
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const icon = app.inject(IconService);
|
|
84
|
+
|
|
85
|
+
await Promise.all([
|
|
86
|
+
icon.getIcon('accessibility_new'),
|
|
87
|
+
icon.getIcon('accessibility_new'),
|
|
88
|
+
icon.getIcon('accessibility_new'),
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
assert.equal(callCount, 1);
|
|
92
|
+
});
|
|
63
93
|
});
|
|
@@ -8,26 +8,26 @@ import { USAIcon } from '../icon/icon-types.js';
|
|
|
8
8
|
export class IconService {
|
|
9
9
|
#config = inject(USAConfig);
|
|
10
10
|
#http = inject(HttpService);
|
|
11
|
-
#iconCache: Map<USAIcon, HTMLTemplateElement
|
|
11
|
+
#iconCache: Map<USAIcon, Promise<HTMLTemplateElement>> = new Map();
|
|
12
12
|
|
|
13
|
-
async getIcon(icon: USAIcon
|
|
13
|
+
async getIcon(icon: USAIcon): Promise<Node> {
|
|
14
14
|
const config = this.#config();
|
|
15
15
|
const http = this.#http();
|
|
16
16
|
|
|
17
17
|
const cached = this.#iconCache.get(icon);
|
|
18
18
|
|
|
19
19
|
if (cached) {
|
|
20
|
-
|
|
20
|
+
const res = await cached;
|
|
21
|
+
|
|
22
|
+
if (!res.content.firstElementChild) {
|
|
21
23
|
throw Error('cached value is not valid');
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
return
|
|
26
|
+
return res.content.firstElementChild.cloneNode(true);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
const svg = http
|
|
28
|
-
.fetch(`${config.iconPath}${icon}.svg
|
|
29
|
-
signal: abortSignal,
|
|
30
|
-
})
|
|
30
|
+
.fetch(`${config.iconPath}${icon}.svg`)
|
|
31
31
|
.then((res) => {
|
|
32
32
|
switch (res.status) {
|
|
33
33
|
case 200:
|
|
@@ -39,12 +39,11 @@ export class IconService {
|
|
|
39
39
|
.then((res) => {
|
|
40
40
|
const template = document.createElement('template');
|
|
41
41
|
template.innerHTML = res;
|
|
42
|
-
|
|
43
|
-
this.#iconCache.set(icon, template);
|
|
44
|
-
|
|
45
42
|
return template;
|
|
46
43
|
});
|
|
47
44
|
|
|
45
|
+
this.#iconCache.set(icon, svg);
|
|
46
|
+
|
|
48
47
|
return svg.then((res) => {
|
|
49
48
|
if (!res.content.firstElementChild) {
|
|
50
49
|
throw Error('ICON is not valid');
|
package/target/lib/define.d.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
import
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
import
|
|
46
|
-
import
|
|
47
|
-
import
|
|
48
|
-
import
|
|
49
|
-
import
|
|
1
|
+
import './config/config.element.js';
|
|
2
|
+
import './alert/alert.element.js';
|
|
3
|
+
import './button/button.element.js';
|
|
4
|
+
import './checkbox/checkbox.element.js';
|
|
5
|
+
import './description/description.element.js';
|
|
6
|
+
import './file-input/file-input.element.js';
|
|
7
|
+
import './file-input/file-input-preview/file-input-preview.element.js';
|
|
8
|
+
import './icon/icon.element.js';
|
|
9
|
+
import './input/input.element.js';
|
|
10
|
+
import './input-mask/input-mask.element.js';
|
|
11
|
+
import './link/link.element.js';
|
|
12
|
+
import './radio/radio.element.js';
|
|
13
|
+
import './radio/radio-option/radio-option.element.js';
|
|
14
|
+
import './select/select.element.js';
|
|
15
|
+
import './select/select-option/select-option.element.js';
|
|
16
|
+
import './tag/tag.element.js';
|
|
17
|
+
import './accordion/accordion.element.js';
|
|
18
|
+
import './side-nav/side-nav.element.js';
|
|
19
|
+
import './side-nav/side-nav-item/side-nav-item.element.js';
|
|
20
|
+
import './summary-box/summary-box.element.js';
|
|
21
|
+
import './step-indicator/step-indicator.element.js';
|
|
22
|
+
import './step-indicator/step/step.element.js';
|
|
23
|
+
import './modal/modal.element.js';
|
|
24
|
+
import './modal/modal-close/modal-close.element.js';
|
|
25
|
+
import './modal/modal-heading/modal-heading.element.js';
|
|
26
|
+
import './card/card.element.js';
|
|
27
|
+
import './card/card-header/card-header.element.js';
|
|
28
|
+
import './card/card-body/card-body.element.js';
|
|
29
|
+
import './card/card-footer/card-footer.element.js';
|
|
30
|
+
import './card/card-media/card-media.element.js';
|
|
31
|
+
import './card/card-group/card-group.element.js';
|
|
32
|
+
import './textarea/textarea.element.js';
|
|
33
|
+
import './collection/collection.element.js';
|
|
34
|
+
import './collection/collection-item/collection-item.element.js';
|
|
35
|
+
import './checkbox/checkbox-group/checkbox-group.element.js';
|
|
36
|
+
import './range-slider/range-slider.element.js';
|
|
37
|
+
import './combo-box/combo-box.element.js';
|
|
38
|
+
import './combo-box/combo-box-option/combo-box-option.element.js';
|
|
39
|
+
import './search/search.element.js';
|
|
40
|
+
import './process-list/process-list.element.js';
|
|
41
|
+
import './process-list/process-list-item/process-list-item.element.js';
|
|
42
|
+
import './in-page-nav/in-page-nav.element.js';
|
|
43
|
+
import './in-page-nav/in-page-nav-item/in-page-nav-item.element.js';
|
|
44
|
+
import './button-group/button-group.element.js';
|
|
45
|
+
import './breadcrumbs/breadcrumbs.element.js';
|
|
46
|
+
import './breadcrumbs/breadcrumb/breadcrumb.element.js';
|
|
47
|
+
import './pagination/pagination.element.js';
|
|
48
|
+
import './pagination/pagination-item/pagination-item.element.js';
|
|
49
|
+
import './pagination/pagination-no/pagination-no.element.js';
|
package/target/lib/define.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
import
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
import
|
|
46
|
-
import
|
|
47
|
-
import
|
|
48
|
-
import
|
|
49
|
-
import
|
|
1
|
+
import './config/config.element.js';
|
|
2
|
+
import './alert/alert.element.js';
|
|
3
|
+
import './button/button.element.js';
|
|
4
|
+
import './checkbox/checkbox.element.js';
|
|
5
|
+
import './description/description.element.js';
|
|
6
|
+
import './file-input/file-input.element.js';
|
|
7
|
+
import './file-input/file-input-preview/file-input-preview.element.js';
|
|
8
|
+
import './icon/icon.element.js';
|
|
9
|
+
import './input/input.element.js';
|
|
10
|
+
import './input-mask/input-mask.element.js';
|
|
11
|
+
import './link/link.element.js';
|
|
12
|
+
import './radio/radio.element.js';
|
|
13
|
+
import './radio/radio-option/radio-option.element.js';
|
|
14
|
+
import './select/select.element.js';
|
|
15
|
+
import './select/select-option/select-option.element.js';
|
|
16
|
+
import './tag/tag.element.js';
|
|
17
|
+
import './accordion/accordion.element.js';
|
|
18
|
+
import './side-nav/side-nav.element.js';
|
|
19
|
+
import './side-nav/side-nav-item/side-nav-item.element.js';
|
|
20
|
+
import './summary-box/summary-box.element.js';
|
|
21
|
+
import './step-indicator/step-indicator.element.js';
|
|
22
|
+
import './step-indicator/step/step.element.js';
|
|
23
|
+
import './modal/modal.element.js';
|
|
24
|
+
import './modal/modal-close/modal-close.element.js';
|
|
25
|
+
import './modal/modal-heading/modal-heading.element.js';
|
|
26
|
+
import './card/card.element.js';
|
|
27
|
+
import './card/card-header/card-header.element.js';
|
|
28
|
+
import './card/card-body/card-body.element.js';
|
|
29
|
+
import './card/card-footer/card-footer.element.js';
|
|
30
|
+
import './card/card-media/card-media.element.js';
|
|
31
|
+
import './card/card-group/card-group.element.js';
|
|
32
|
+
import './textarea/textarea.element.js';
|
|
33
|
+
import './collection/collection.element.js';
|
|
34
|
+
import './collection/collection-item/collection-item.element.js';
|
|
35
|
+
import './checkbox/checkbox-group/checkbox-group.element.js';
|
|
36
|
+
import './range-slider/range-slider.element.js';
|
|
37
|
+
import './combo-box/combo-box.element.js';
|
|
38
|
+
import './combo-box/combo-box-option/combo-box-option.element.js';
|
|
39
|
+
import './search/search.element.js';
|
|
40
|
+
import './process-list/process-list.element.js';
|
|
41
|
+
import './process-list/process-list-item/process-list-item.element.js';
|
|
42
|
+
import './in-page-nav/in-page-nav.element.js';
|
|
43
|
+
import './in-page-nav/in-page-nav-item/in-page-nav-item.element.js';
|
|
44
|
+
import './button-group/button-group.element.js';
|
|
45
|
+
import './breadcrumbs/breadcrumbs.element.js';
|
|
46
|
+
import './breadcrumbs/breadcrumb/breadcrumb.element.js';
|
|
47
|
+
import './pagination/pagination.element.js';
|
|
48
|
+
import './pagination/pagination-item/pagination-item.element.js';
|
|
49
|
+
import './pagination/pagination-no/pagination-no.element.js';
|
|
50
50
|
//# sourceMappingURL=define.js.map
|
|
@@ -2,7 +2,6 @@ import { __esDecorate, __runInitializers } from "tslib";
|
|
|
2
2
|
import { inject, injectable } from '@joist/di';
|
|
3
3
|
import { attr, css, element } from '@joist/element';
|
|
4
4
|
import { IconService } from '../services/icon.service.js';
|
|
5
|
-
import { effect, observe } from '@joist/observable';
|
|
6
5
|
let USAIconElement = (() => {
|
|
7
6
|
let _classDecorators = [element({
|
|
8
7
|
tagName: 'usa-icon',
|
|
@@ -16,45 +15,35 @@ let USAIconElement = (() => {
|
|
|
16
15
|
let _classExtraInitializers = [];
|
|
17
16
|
let _classThis;
|
|
18
17
|
let _classSuper = HTMLElement;
|
|
19
|
-
let _instanceExtraInitializers = [];
|
|
20
18
|
let _icon_decorators;
|
|
21
19
|
let _icon_initializers = [];
|
|
22
20
|
let _icon_extraInitializers = [];
|
|
23
|
-
let _onIconUpdate_decorators;
|
|
24
21
|
var USAIconElement = class extends _classSuper {
|
|
25
22
|
static { _classThis = this; }
|
|
26
23
|
static {
|
|
27
24
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
28
|
-
_icon_decorators = [attr()
|
|
29
|
-
_onIconUpdate_decorators = [effect()];
|
|
25
|
+
_icon_decorators = [attr()];
|
|
30
26
|
__esDecorate(this, null, _icon_decorators, { kind: "accessor", name: "icon", static: false, private: false, access: { has: obj => "icon" in obj, get: obj => obj.icon, set: (obj, value) => { obj.icon = value; } }, metadata: _metadata }, _icon_initializers, _icon_extraInitializers);
|
|
31
|
-
__esDecorate(this, null, _onIconUpdate_decorators, { kind: "method", name: "onIconUpdate", static: false, private: false, access: { has: obj => "onIconUpdate" in obj, get: obj => obj.onIconUpdate }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
32
27
|
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
33
28
|
USAIconElement = _classThis = _classDescriptor.value;
|
|
34
29
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
35
30
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
36
31
|
}
|
|
37
|
-
#icon_accessor_storage =
|
|
32
|
+
#icon_accessor_storage = __runInitializers(this, _icon_initializers, '');
|
|
38
33
|
get icon() { return this.#icon_accessor_storage; }
|
|
39
34
|
set icon(value) { this.#icon_accessor_storage = value; }
|
|
40
35
|
ariaHidden = (__runInitializers(this, _icon_extraInitializers), 'true');
|
|
41
36
|
#icon = inject(IconService);
|
|
42
|
-
#abortController = null;
|
|
43
37
|
connectedCallback() {
|
|
44
38
|
this.#updateIcon();
|
|
45
39
|
}
|
|
46
|
-
onIconUpdate() {
|
|
47
|
-
this.#updateIcon();
|
|
48
|
-
}
|
|
49
40
|
async #updateIcon() {
|
|
50
|
-
this.#abortController?.abort();
|
|
51
|
-
this.#abortController = new AbortController();
|
|
52
41
|
if (!this.icon) {
|
|
53
42
|
return;
|
|
54
43
|
}
|
|
55
44
|
const icon = this.#icon();
|
|
56
45
|
icon
|
|
57
|
-
.getIcon(this.icon
|
|
46
|
+
.getIcon(this.icon)
|
|
58
47
|
.then((currentIcon) => {
|
|
59
48
|
if (this.shadowRoot) {
|
|
60
49
|
if (this.shadowRoot.firstElementChild) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.element.js","sourceRoot":"","sources":["../../../src/lib/icon/icon.element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"icon.element.js","sourceRoot":"","sources":["../../../src/lib/icon/icon.element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;IA+B7C,cAAc;4BAtB1B,OAAO,CAAC;YACP,OAAO,EAAE,UAAU;YACnB,SAAS,EAAE;gBACT,GAAG,CAAA;;;;;;;;;;;;;KAaF;aACF;SACF,CAAC,EACD,UAAU,CAAC;YACV,IAAI,EAAE,cAAc;SACrB,CAAC;;;;sBACkC,WAAW;;;;8BAAnB,SAAQ,WAAW;;;;gCAC5C,IAAI,EAAE;YACP,iKAAS,IAAI,6BAAJ,IAAI,mFAAoB;YAFnC,6KAgCC;;;YAhCY,uDAAc;;QAEzB,qEAA8B,EAAE,EAAC;QAAjC,IAAS,IAAI,0CAAoB;QAAjC,IAAS,IAAI,gDAAoB;QAEjC,UAAU,sDAAkB,MAAM,EAAC;QAEnC,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;QAE5B,iBAAiB;YACf,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,CAAC;QAED,KAAK,CAAC,WAAW;YACf,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACf,OAAO;YACT,CAAC;YAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAE1B,IAAI;iBACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;iBAClB,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;gBACpB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;oBACpB,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC;wBACtC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;oBAC7D,CAAC;yBAAM,CAAC;wBACN,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;oBACtC,CAAC;gBACH,CAAC;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACrB,CAAC;;;;SA/BU,cAAc"}
|
|
@@ -48,5 +48,30 @@ describe('IconService', () => {
|
|
|
48
48
|
assert.equal(res.nodeName, 'svg');
|
|
49
49
|
assert.equal(callCount, 1);
|
|
50
50
|
});
|
|
51
|
+
it('should not fetch multiple times if the same icon is requested at the same time', async () => {
|
|
52
|
+
let callCount = 0;
|
|
53
|
+
const app = new Injector({
|
|
54
|
+
providers: [
|
|
55
|
+
[
|
|
56
|
+
HttpService,
|
|
57
|
+
{
|
|
58
|
+
use: class extends HttpService {
|
|
59
|
+
async fetch() {
|
|
60
|
+
callCount++;
|
|
61
|
+
return new Response('<svg></svg>');
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
const icon = app.inject(IconService);
|
|
69
|
+
await Promise.all([
|
|
70
|
+
icon.getIcon('accessibility_new'),
|
|
71
|
+
icon.getIcon('accessibility_new'),
|
|
72
|
+
icon.getIcon('accessibility_new'),
|
|
73
|
+
]);
|
|
74
|
+
assert.equal(callCount, 1);
|
|
75
|
+
});
|
|
51
76
|
});
|
|
52
77
|
//# sourceMappingURL=icon.service.element.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.service.element.test.js","sourceRoot":"","sources":["../../../src/lib/services/icon.service.element.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,EAAE,CAAC,mCAAmC,EAAE,KAAK,IAAI,EAAE;QACjD,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC;YACvB,SAAS,EAAE;gBACT;oBACE,WAAW;oBACX;wBACE,GAAG,EAAE,KAAM,SAAQ,WAAW;4BAC5B,KAAK,CAAC,KAAK;gCACT,SAAS,EAAE,CAAC;gCACZ,OAAO,IAAI,QAAQ,CAAC,aAAa,CAAC,CAAC;4BACrC,CAAC;yBACF;qBACF;iBACF;aACF;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAErC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAa,CAAC,CAAC;QAE9C,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6DAA6D,EAAE,KAAK,IAAI,EAAE;QAC3E,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC;YACvB,SAAS,EAAE;gBACT;oBACE,WAAW;oBACX;wBACE,GAAG,EAAE,KAAM,SAAQ,WAAW;4BAC5B,KAAK,CAAC,KAAK;gCACT,SAAS,EAAE,CAAC;gCACZ,OAAO,IAAI,QAAQ,CAAC,aAAa,CAAC,CAAC;4BACrC,CAAC;yBACF;qBACF;iBACF;aACF;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAErC,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAExC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAEpD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"icon.service.element.test.js","sourceRoot":"","sources":["../../../src/lib/services/icon.service.element.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE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C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAEpD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gFAAgF,EAAE,KAAK,IAAI,EAAE;QAC9F,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC;YACvB,SAAS,EAAE;gBACT;oBACE,WAAW;oBACX;wBACE,GAAG,EAAE,KAAM,SAAQ,WAAW;4BAC5B,KAAK,CAAC,KAAK;gCACT,SAAS,EAAE,CAAC;gCACZ,OAAO,IAAI,QAAQ,CAAC,aAAa,CAAC,CAAC;4BACrC,CAAC;yBACF;qBACF;iBACF;aACF;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAErC,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC;SAClC,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -19,20 +19,19 @@ let IconService = (() => {
|
|
|
19
19
|
#config = inject(USAConfig);
|
|
20
20
|
#http = inject(HttpService);
|
|
21
21
|
#iconCache = new Map();
|
|
22
|
-
async getIcon(icon
|
|
22
|
+
async getIcon(icon) {
|
|
23
23
|
const config = this.#config();
|
|
24
24
|
const http = this.#http();
|
|
25
25
|
const cached = this.#iconCache.get(icon);
|
|
26
26
|
if (cached) {
|
|
27
|
-
|
|
27
|
+
const res = await cached;
|
|
28
|
+
if (!res.content.firstElementChild) {
|
|
28
29
|
throw Error('cached value is not valid');
|
|
29
30
|
}
|
|
30
|
-
return
|
|
31
|
+
return res.content.firstElementChild.cloneNode(true);
|
|
31
32
|
}
|
|
32
33
|
const svg = http
|
|
33
|
-
.fetch(`${config.iconPath}${icon}.svg
|
|
34
|
-
signal: abortSignal,
|
|
35
|
-
})
|
|
34
|
+
.fetch(`${config.iconPath}${icon}.svg`)
|
|
36
35
|
.then((res) => {
|
|
37
36
|
switch (res.status) {
|
|
38
37
|
case 200:
|
|
@@ -43,9 +42,9 @@ let IconService = (() => {
|
|
|
43
42
|
.then((res) => {
|
|
44
43
|
const template = document.createElement('template');
|
|
45
44
|
template.innerHTML = res;
|
|
46
|
-
this.#iconCache.set(icon, template);
|
|
47
45
|
return template;
|
|
48
46
|
});
|
|
47
|
+
this.#iconCache.set(icon, svg);
|
|
49
48
|
return svg.then((res) => {
|
|
50
49
|
if (!res.content.firstElementChild) {
|
|
51
50
|
throw Error('ICON is not valid');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.service.js","sourceRoot":"","sources":["../../../src/lib/services/icon.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;IAInC,WAAW;4BADvB,UAAU,EAAE;;;;;;;;YACb,
|
|
1
|
+
{"version":3,"file":"icon.service.js","sourceRoot":"","sources":["../../../src/lib/services/icon.service.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;IAInC,WAAW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