@spectrum-web-components/iconset 1.1.0 → 1.1.2
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 +3 -3
- package/src/iconset-registry.d.ts +22 -0
- package/src/iconset-registry.dev.js +35 -0
- package/src/iconset-registry.dev.js.map +7 -0
- package/src/iconset-registry.js +2 -0
- package/src/iconset-registry.js.map +7 -0
- package/src/iconset-svg.d.ts +29 -0
- package/src/iconset-svg.dev.js +123 -0
- package/src/iconset-svg.dev.js.map +7 -0
- package/src/iconset-svg.js +6 -0
- package/src/iconset-svg.js.map +7 -0
- package/src/iconset.d.ts +31 -0
- package/src/iconset.dev.js +87 -0
- package/src/iconset.dev.js.map +7 -0
- package/src/iconset.js +2 -0
- package/src/iconset.js.map +7 -0
- package/src/index.d.ts +3 -0
- package/src/index.dev.js +5 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -0
- package/src/index.js.map +7 -0
- package/stories/icons-demo.js +280 -0
- package/stories/icons-demo.js.map +7 -0
- package/test/iconset.test.js +105 -0
- package/test/iconset.test.js.map +7 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@spectrum-web-components/iconset",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.2",
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
@@ -60,7 +60,7 @@
|
|
60
60
|
"lit-html"
|
61
61
|
],
|
62
62
|
"dependencies": {
|
63
|
-
"@spectrum-web-components/base": "^1.1.
|
63
|
+
"@spectrum-web-components/base": "^1.1.2"
|
64
64
|
},
|
65
65
|
"types": "./src/index.d.ts",
|
66
66
|
"customElements": "custom-elements.json",
|
@@ -71,5 +71,5 @@
|
|
71
71
|
"./stories/iconsList.json",
|
72
72
|
"./**/*.dev.js"
|
73
73
|
],
|
74
|
-
"gitHead": "
|
74
|
+
"gitHead": "9ee45f2dfd3ac1939072726d00195c6c05d9a562"
|
75
75
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Iconset } from './iconset.js';
|
2
|
+
export interface IconsetAddedDetail {
|
3
|
+
name: string;
|
4
|
+
iconset: Iconset;
|
5
|
+
}
|
6
|
+
export interface IconsetRemovedDetail {
|
7
|
+
name: string;
|
8
|
+
}
|
9
|
+
export declare class IconsetRegistry {
|
10
|
+
static getInstance(): IconsetRegistry;
|
11
|
+
private static instance;
|
12
|
+
private iconsetMap;
|
13
|
+
addIconset(name: string, iconset: Iconset): void;
|
14
|
+
removeIconset(name: string): void;
|
15
|
+
getIconset(name: string): Iconset | undefined;
|
16
|
+
}
|
17
|
+
declare global {
|
18
|
+
interface GlobalEventHandlersEventMap {
|
19
|
+
'sp-iconset-added': CustomEvent<IconsetAddedDetail>;
|
20
|
+
'sp-iconset-removed': CustomEvent<IconsetRemovedDetail>;
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
export class IconsetRegistry {
|
3
|
+
constructor() {
|
4
|
+
this.iconsetMap = /* @__PURE__ */ new Map();
|
5
|
+
}
|
6
|
+
// singleton getter
|
7
|
+
static getInstance() {
|
8
|
+
if (!IconsetRegistry.instance) {
|
9
|
+
IconsetRegistry.instance = new IconsetRegistry();
|
10
|
+
}
|
11
|
+
return IconsetRegistry.instance;
|
12
|
+
}
|
13
|
+
addIconset(name, iconset) {
|
14
|
+
this.iconsetMap.set(name, iconset);
|
15
|
+
const event = new CustomEvent("sp-iconset-added", {
|
16
|
+
bubbles: true,
|
17
|
+
composed: true,
|
18
|
+
detail: { name, iconset }
|
19
|
+
});
|
20
|
+
setTimeout(() => window.dispatchEvent(event), 0);
|
21
|
+
}
|
22
|
+
removeIconset(name) {
|
23
|
+
this.iconsetMap.delete(name);
|
24
|
+
const event = new CustomEvent("sp-iconset-removed", {
|
25
|
+
bubbles: true,
|
26
|
+
composed: true,
|
27
|
+
detail: { name }
|
28
|
+
});
|
29
|
+
setTimeout(() => window.dispatchEvent(event), 0);
|
30
|
+
}
|
31
|
+
getIconset(name) {
|
32
|
+
return this.iconsetMap.get(name);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
//# sourceMappingURL=iconset-registry.dev.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["iconset-registry.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { Iconset } from './iconset.dev.js'\nexport interface IconsetAddedDetail {\n name: string;\n iconset: Iconset;\n}\nexport interface IconsetRemovedDetail {\n name: string;\n}\n\nexport class IconsetRegistry {\n // singleton getter\n public static getInstance(): IconsetRegistry {\n if (!IconsetRegistry.instance) {\n IconsetRegistry.instance = new IconsetRegistry();\n }\n return IconsetRegistry.instance;\n }\n private static instance: IconsetRegistry;\n\n private iconsetMap = new Map<string, Iconset>();\n\n public addIconset(name: string, iconset: Iconset): void {\n this.iconsetMap.set(name, iconset);\n\n // dispatch a sp-iconset-added event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-added', {\n bubbles: true,\n composed: true,\n detail: { name, iconset },\n });\n // we're dispatching this event in the next tick to allow the iconset to finish any slotchange or other event\n // listeners caused by connection to the dom and first render to complete, this way any icons listening for\n // this iconset will be able to access the completed iconset\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public removeIconset(name: string): void {\n this.iconsetMap.delete(name);\n // dispatch a sp-iconset-removed event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-removed', {\n bubbles: true,\n composed: true,\n detail: { name },\n });\n // we're dispatching this event in the next tick To keep the event model consistent with the added event\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public getIconset(name: string): Iconset | undefined {\n return this.iconsetMap.get(name);\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-iconset-added': CustomEvent<IconsetAddedDetail>;\n 'sp-iconset-removed': CustomEvent<IconsetRemovedDetail>;\n }\n}\n"],
|
5
|
+
"mappings": ";AAoBO,aAAM,gBAAgB;AAAA,EAAtB;AAUH,SAAQ,aAAa,oBAAI,IAAqB;AAAA;AAAA;AAAA,EAR9C,OAAc,cAA+B;AACzC,QAAI,CAAC,gBAAgB,UAAU;AAC3B,sBAAgB,WAAW,IAAI,gBAAgB;AAAA,IACnD;AACA,WAAO,gBAAgB;AAAA,EAC3B;AAAA,EAKO,WAAW,MAAc,SAAwB;AACpD,SAAK,WAAW,IAAI,MAAM,OAAO;AAKjC,UAAM,QAAQ,IAAI,YAAY,oBAAoB;AAAA,MAC9C,SAAS;AAAA,MACT,UAAU;AAAA,MACV,QAAQ,EAAE,MAAM,QAAQ;AAAA,IAC5B,CAAC;AAID,eAAW,MAAM,OAAO,cAAc,KAAK,GAAG,CAAC;AAAA,EACnD;AAAA,EACO,cAAc,MAAoB;AACrC,SAAK,WAAW,OAAO,IAAI;AAI3B,UAAM,QAAQ,IAAI,YAAY,sBAAsB;AAAA,MAChD,SAAS;AAAA,MACT,UAAU;AAAA,MACV,QAAQ,EAAE,KAAK;AAAA,IACnB,CAAC;AAED,eAAW,MAAM,OAAO,cAAc,KAAK,GAAG,CAAC;AAAA,EACnD;AAAA,EACO,WAAW,MAAmC;AACjD,WAAO,KAAK,WAAW,IAAI,IAAI;AAAA,EACnC;AACJ;",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";export class IconsetRegistry{constructor(){this.iconsetMap=new Map}static getInstance(){return IconsetRegistry.instance||(IconsetRegistry.instance=new IconsetRegistry),IconsetRegistry.instance}addIconset(e,t){this.iconsetMap.set(e,t);const n=new CustomEvent("sp-iconset-added",{bubbles:!0,composed:!0,detail:{name:e,iconset:t}});setTimeout(()=>window.dispatchEvent(n),0)}removeIconset(e){this.iconsetMap.delete(e);const t=new CustomEvent("sp-iconset-removed",{bubbles:!0,composed:!0,detail:{name:e}});setTimeout(()=>window.dispatchEvent(t),0)}getIconset(e){return this.iconsetMap.get(e)}}
|
2
|
+
//# sourceMappingURL=iconset-registry.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["iconset-registry.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { Iconset } from './iconset.js';\nexport interface IconsetAddedDetail {\n name: string;\n iconset: Iconset;\n}\nexport interface IconsetRemovedDetail {\n name: string;\n}\n\nexport class IconsetRegistry {\n // singleton getter\n public static getInstance(): IconsetRegistry {\n if (!IconsetRegistry.instance) {\n IconsetRegistry.instance = new IconsetRegistry();\n }\n return IconsetRegistry.instance;\n }\n private static instance: IconsetRegistry;\n\n private iconsetMap = new Map<string, Iconset>();\n\n public addIconset(name: string, iconset: Iconset): void {\n this.iconsetMap.set(name, iconset);\n\n // dispatch a sp-iconset-added event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-added', {\n bubbles: true,\n composed: true,\n detail: { name, iconset },\n });\n // we're dispatching this event in the next tick to allow the iconset to finish any slotchange or other event\n // listeners caused by connection to the dom and first render to complete, this way any icons listening for\n // this iconset will be able to access the completed iconset\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public removeIconset(name: string): void {\n this.iconsetMap.delete(name);\n // dispatch a sp-iconset-removed event on window to let everyone know we have a new iconset\n // note we're using window here for efficiency since we don't need to bubble through the dom since everyone\n // will know where to look for this event\n const event = new CustomEvent('sp-iconset-removed', {\n bubbles: true,\n composed: true,\n detail: { name },\n });\n // we're dispatching this event in the next tick To keep the event model consistent with the added event\n setTimeout(() => window.dispatchEvent(event), 0);\n }\n public getIconset(name: string): Iconset | undefined {\n return this.iconsetMap.get(name);\n }\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-iconset-added': CustomEvent<IconsetAddedDetail>;\n 'sp-iconset-removed': CustomEvent<IconsetRemovedDetail>;\n }\n}\n"],
|
5
|
+
"mappings": "aAoBO,aAAM,eAAgB,CAAtB,cAUH,KAAQ,WAAa,IAAI,IARzB,OAAc,aAA+B,CACzC,OAAK,gBAAgB,WACjB,gBAAgB,SAAW,IAAI,iBAE5B,gBAAgB,QAC3B,CAKO,WAAWA,EAAcC,EAAwB,CACpD,KAAK,WAAW,IAAID,EAAMC,CAAO,EAKjC,MAAMC,EAAQ,IAAI,YAAY,mBAAoB,CAC9C,QAAS,GACT,SAAU,GACV,OAAQ,CAAE,KAAAF,EAAM,QAAAC,CAAQ,CAC5B,CAAC,EAID,WAAW,IAAM,OAAO,cAAcC,CAAK,EAAG,CAAC,CACnD,CACO,cAAcF,EAAoB,CACrC,KAAK,WAAW,OAAOA,CAAI,EAI3B,MAAME,EAAQ,IAAI,YAAY,qBAAsB,CAChD,QAAS,GACT,SAAU,GACV,OAAQ,CAAE,KAAAF,CAAK,CACnB,CAAC,EAED,WAAW,IAAM,OAAO,cAAcE,CAAK,EAAG,CAAC,CACnD,CACO,WAAWF,EAAmC,CACjD,OAAO,KAAK,WAAW,IAAIA,CAAI,CACnC,CACJ",
|
6
|
+
"names": ["name", "iconset", "event"]
|
7
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { PropertyValues, TemplateResult } from '@spectrum-web-components/base';
|
2
|
+
import { Iconset } from './iconset.js';
|
3
|
+
export declare abstract class IconsetSVG extends Iconset {
|
4
|
+
private iconMap;
|
5
|
+
private slotContainer?;
|
6
|
+
/**
|
7
|
+
* First updated handler just ensures we've processed any slotted symbols
|
8
|
+
*/
|
9
|
+
updated(changedProperties: PropertyValues): void;
|
10
|
+
/**
|
11
|
+
* Applies the requested icon from this iconset instance to the given element.
|
12
|
+
*
|
13
|
+
* @param el - the element to apply the icon to
|
14
|
+
* @param icon - the name of the icon within this set to apply.
|
15
|
+
*/
|
16
|
+
applyIconToElement(el: HTMLElement, icon: string, _size: string, label: string): Promise<void>;
|
17
|
+
/**
|
18
|
+
* Returns a list of all icons in this iconset.
|
19
|
+
*/
|
20
|
+
getIconList(): string[];
|
21
|
+
protected prepareSvgClone(sourceSvg: SVGSymbolElement): SVGSVGElement;
|
22
|
+
protected getSVGIconName(icon: string): string;
|
23
|
+
protected getSanitizedIconName(icon: string): string;
|
24
|
+
protected renderDefaultContent(): TemplateResult;
|
25
|
+
protected render(): TemplateResult;
|
26
|
+
protected updateSVG(nodes: SVGElement[]): void;
|
27
|
+
protected getSVGNodes(slotTarget: HTMLSlotElement): SVGElement[];
|
28
|
+
private onSlotChange;
|
29
|
+
}
|
@@ -0,0 +1,123 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
5
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
6
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
7
|
+
if (decorator = decorators[i])
|
8
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
10
|
+
return result;
|
11
|
+
};
|
12
|
+
import {
|
13
|
+
html
|
14
|
+
} from "@spectrum-web-components/base";
|
15
|
+
import { query } from "@spectrum-web-components/base/src/decorators.js";
|
16
|
+
import { Iconset } from "./iconset.dev.js";
|
17
|
+
export class IconsetSVG extends Iconset {
|
18
|
+
constructor() {
|
19
|
+
super(...arguments);
|
20
|
+
this.iconMap = /* @__PURE__ */ new Map();
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* First updated handler just ensures we've processed any slotted symbols
|
24
|
+
*/
|
25
|
+
updated(changedProperties) {
|
26
|
+
if (!this.slotContainer) {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
const currentSVGNodes = this.getSVGNodes(this.slotContainer);
|
30
|
+
this.updateSVG(currentSVGNodes);
|
31
|
+
super.updated(changedProperties);
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Applies the requested icon from this iconset instance to the given element.
|
35
|
+
*
|
36
|
+
* @param el - the element to apply the icon to
|
37
|
+
* @param icon - the name of the icon within this set to apply.
|
38
|
+
*/
|
39
|
+
async applyIconToElement(el, icon, _size, label) {
|
40
|
+
await this.updateComplete;
|
41
|
+
const iconSymbol = this.iconMap.get(icon);
|
42
|
+
if (!iconSymbol) {
|
43
|
+
throw new Error(`Unable to find icon ${icon}`);
|
44
|
+
}
|
45
|
+
const clonedNode = this.prepareSvgClone(iconSymbol);
|
46
|
+
clonedNode.setAttribute("role", "img");
|
47
|
+
if (label) {
|
48
|
+
clonedNode.setAttribute("aria-label", label);
|
49
|
+
} else {
|
50
|
+
clonedNode.setAttribute("aria-hidden", "true");
|
51
|
+
}
|
52
|
+
if (el.shadowRoot) {
|
53
|
+
el.shadowRoot.appendChild(clonedNode);
|
54
|
+
} else {
|
55
|
+
el.appendChild(clonedNode);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
/**
|
59
|
+
* Returns a list of all icons in this iconset.
|
60
|
+
*/
|
61
|
+
getIconList() {
|
62
|
+
return [...this.iconMap.keys()];
|
63
|
+
}
|
64
|
+
prepareSvgClone(sourceSvg) {
|
65
|
+
const content = sourceSvg.cloneNode(true);
|
66
|
+
const svg = document.createElementNS(
|
67
|
+
"http://www.w3.org/2000/svg",
|
68
|
+
"svg"
|
69
|
+
);
|
70
|
+
const viewBox = content.getAttribute("viewBox") || "";
|
71
|
+
const cssText = "pointer-events: none; display: block; width: 100%; height: 100%;";
|
72
|
+
svg.style.cssText = cssText;
|
73
|
+
svg.setAttribute("viewBox", viewBox);
|
74
|
+
svg.setAttribute("preserveAspectRatio", "xMidYMid meet");
|
75
|
+
svg.setAttribute("focusable", "false");
|
76
|
+
while (content.childNodes.length > 0) {
|
77
|
+
svg.appendChild(content.childNodes[0]);
|
78
|
+
}
|
79
|
+
return svg;
|
80
|
+
}
|
81
|
+
getSVGIconName(icon) {
|
82
|
+
return icon;
|
83
|
+
}
|
84
|
+
getSanitizedIconName(icon) {
|
85
|
+
return icon;
|
86
|
+
}
|
87
|
+
renderDefaultContent() {
|
88
|
+
return html``;
|
89
|
+
}
|
90
|
+
render() {
|
91
|
+
return html`
|
92
|
+
<slot @slotchange=${this.onSlotChange}>
|
93
|
+
${this.renderDefaultContent()}
|
94
|
+
</slot>
|
95
|
+
`;
|
96
|
+
}
|
97
|
+
updateSVG(nodes) {
|
98
|
+
const symbols = nodes.reduce((prev, svgNode) => {
|
99
|
+
const containedSymbols = svgNode.querySelectorAll("symbol");
|
100
|
+
prev.push(...containedSymbols);
|
101
|
+
return prev;
|
102
|
+
}, []);
|
103
|
+
symbols.forEach((symbol) => {
|
104
|
+
this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);
|
105
|
+
});
|
106
|
+
}
|
107
|
+
getSVGNodes(slotTarget) {
|
108
|
+
const nodes = slotTarget.assignedNodes({ flatten: true });
|
109
|
+
const svgNodes = nodes.filter((node) => {
|
110
|
+
return node.nodeName === "svg";
|
111
|
+
});
|
112
|
+
return svgNodes;
|
113
|
+
}
|
114
|
+
onSlotChange(event) {
|
115
|
+
const slotTarget = event.target;
|
116
|
+
const svgNodes = this.getSVGNodes(slotTarget);
|
117
|
+
this.updateSVG(svgNodes);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
__decorateClass([
|
121
|
+
query("slot")
|
122
|
+
], IconsetSVG.prototype, "slotContainer", 2);
|
123
|
+
//# sourceMappingURL=iconset-svg.dev.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["iconset-svg.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { query } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { Iconset } from './iconset.dev.js'\n\nexport abstract class IconsetSVG extends Iconset {\n private iconMap: Map<string, SVGSymbolElement> = new Map();\n\n @query('slot')\n private slotContainer?: HTMLSlotElement;\n\n /**\n * First updated handler just ensures we've processed any slotted symbols\n */\n public override updated(changedProperties: PropertyValues): void {\n if (!this.slotContainer) {\n return;\n }\n const currentSVGNodes = this.getSVGNodes(this.slotContainer);\n this.updateSVG(currentSVGNodes);\n super.updated(changedProperties);\n }\n /**\n * Applies the requested icon from this iconset instance to the given element.\n *\n * @param el - the element to apply the icon to\n * @param icon - the name of the icon within this set to apply.\n */\n public async applyIconToElement(\n el: HTMLElement,\n icon: string,\n _size: string,\n label: string\n ): Promise<void> {\n await this.updateComplete;\n const iconSymbol = this.iconMap.get(icon);\n if (!iconSymbol) {\n throw new Error(`Unable to find icon ${icon}`);\n }\n // we cannot share a single SVG globally across shadowroot boundaries\n // so copy the template node so we can inject it where we need it\n const clonedNode = this.prepareSvgClone(iconSymbol);\n clonedNode.setAttribute('role', 'img');\n if (label) {\n clonedNode.setAttribute('aria-label', label);\n } else {\n clonedNode.setAttribute('aria-hidden', 'true');\n }\n // append the svg to the node either in its shadowroot or directly into its dom\n if (el.shadowRoot) {\n el.shadowRoot.appendChild(clonedNode);\n } else {\n el.appendChild(clonedNode);\n }\n }\n\n /**\n * Returns a list of all icons in this iconset.\n */\n public getIconList(): string[] {\n return [...this.iconMap.keys()];\n }\n\n protected prepareSvgClone(sourceSvg: SVGSymbolElement): SVGSVGElement {\n const content = sourceSvg.cloneNode(true) as SVGSymbolElement;\n // we're going to create a new svg element that will have our symbol geometry inside\n const svg = document.createElementNS(\n 'http://www.w3.org/2000/svg',\n 'svg'\n );\n const viewBox = content.getAttribute('viewBox') || '';\n // inline style isn't ideal but will work in all cases and means our icons don't need to know\n // if they are svg or spritesheet provided\n const cssText =\n 'pointer-events: none; display: block; width: 100%; height: 100%;';\n svg.style.cssText = cssText;\n // copy the viewbox and other properties into the svg\n svg.setAttribute('viewBox', viewBox);\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n svg.setAttribute('focusable', 'false');\n // move all the child nodes over to the svg\n while (content.childNodes.length > 0) {\n svg.appendChild(content.childNodes[0]);\n }\n return svg;\n }\n protected getSVGIconName(icon: string): string {\n return icon;\n }\n protected getSanitizedIconName(icon: string): string {\n return icon;\n }\n protected renderDefaultContent(): TemplateResult {\n return html``;\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.onSlotChange}>\n ${this.renderDefaultContent()}\n </slot>\n `;\n }\n\n protected updateSVG(nodes: SVGElement[]): void {\n // iterate over the nodes that were passed in, and find all the top level symbols\n const symbols = nodes.reduce((prev, svgNode) => {\n const containedSymbols = svgNode.querySelectorAll('symbol');\n prev.push(...containedSymbols);\n return prev;\n }, [] as SVGSymbolElement[]);\n symbols.forEach((symbol) => {\n this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);\n });\n }\n\n protected getSVGNodes(slotTarget: HTMLSlotElement): SVGElement[] {\n const nodes = slotTarget.assignedNodes({ flatten: true });\n // find all the svg nodes\n const svgNodes = nodes.filter((node) => {\n return node.nodeName === 'svg';\n }) as SVGElement[];\n return svgNodes;\n }\n\n private onSlotChange(event: Event): void {\n const slotTarget = event.target as HTMLSlotElement;\n const svgNodes = this.getSVGNodes(slotTarget);\n this.updateSVG(svgNodes);\n }\n}\n"],
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA,EACI;AAAA,OAGG;AACP,SAAS,aAAa;AAEtB,SAAS,eAAe;AAEjB,aAAe,mBAAmB,QAAQ;AAAA,EAA1C;AAAA;AACH,SAAQ,UAAyC,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzC,QAAQ,mBAAyC;AAC7D,QAAI,CAAC,KAAK,eAAe;AACrB;AAAA,IACJ;AACA,UAAM,kBAAkB,KAAK,YAAY,KAAK,aAAa;AAC3D,SAAK,UAAU,eAAe;AAC9B,UAAM,QAAQ,iBAAiB;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAa,mBACT,IACA,MACA,OACA,OACa;AACb,UAAM,KAAK;AACX,UAAM,aAAa,KAAK,QAAQ,IAAI,IAAI;AACxC,QAAI,CAAC,YAAY;AACb,YAAM,IAAI,MAAM,uBAAuB,IAAI,EAAE;AAAA,IACjD;AAGA,UAAM,aAAa,KAAK,gBAAgB,UAAU;AAClD,eAAW,aAAa,QAAQ,KAAK;AACrC,QAAI,OAAO;AACP,iBAAW,aAAa,cAAc,KAAK;AAAA,IAC/C,OAAO;AACH,iBAAW,aAAa,eAAe,MAAM;AAAA,IACjD;AAEA,QAAI,GAAG,YAAY;AACf,SAAG,WAAW,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EAAE,SAAS,KAAK,CAAC;AAExD,UAAM,WAAW,MAAM,OAAO,CAAC,SAAS;AACpC,aAAO,KAAK,aAAa;AAAA,IAC7B,CAAC;AACD,WAAO;AAAA,EACX;AAAA,EAEQ,aAAa,OAAoB;AACrC,UAAM,aAAa,MAAM;AACzB,UAAM,WAAW,KAAK,YAAY,UAAU;AAC5C,SAAK,UAAU,QAAQ;AAAA,EAC3B;AACJ;AAzHY;AAAA,EADP,MAAM,MAAM;AAAA,GAHK,WAIV;",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
"use strict";var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var a=(l,r,t,o)=>{for(var e=o>1?void 0:o?p(r,t):r,s=l.length-1,n;s>=0;s--)(n=l[s])&&(e=(o?n(r,t,e):n(e))||e);return o&&e&&c(r,t,e),e};import{html as d}from"@spectrum-web-components/base";import{query as u}from"@spectrum-web-components/base/src/decorators.js";import{Iconset as m}from"./iconset.js";export class IconsetSVG extends m{constructor(){super(...arguments);this.iconMap=new Map}updated(t){if(!this.slotContainer)return;const o=this.getSVGNodes(this.slotContainer);this.updateSVG(o),super.updated(t)}async applyIconToElement(t,o,e,s){await this.updateComplete;const n=this.iconMap.get(o);if(!n)throw new Error(`Unable to find icon ${o}`);const i=this.prepareSvgClone(n);i.setAttribute("role","img"),s?i.setAttribute("aria-label",s):i.setAttribute("aria-hidden","true"),t.shadowRoot?t.shadowRoot.appendChild(i):t.appendChild(i)}getIconList(){return[...this.iconMap.keys()]}prepareSvgClone(t){const o=t.cloneNode(!0),e=document.createElementNS("http://www.w3.org/2000/svg","svg"),s=o.getAttribute("viewBox")||"",n="pointer-events: none; display: block; width: 100%; height: 100%;";for(e.style.cssText=n,e.setAttribute("viewBox",s),e.setAttribute("preserveAspectRatio","xMidYMid meet"),e.setAttribute("focusable","false");o.childNodes.length>0;)e.appendChild(o.childNodes[0]);return e}getSVGIconName(t){return t}getSanitizedIconName(t){return t}renderDefaultContent(){return d``}render(){return d`
|
2
|
+
<slot @slotchange=${this.onSlotChange}>
|
3
|
+
${this.renderDefaultContent()}
|
4
|
+
</slot>
|
5
|
+
`}updateSVG(t){t.reduce((e,s)=>{const n=s.querySelectorAll("symbol");return e.push(...n),e},[]).forEach(e=>{this.iconMap.set(this.getSanitizedIconName(e.id),e)})}getSVGNodes(t){return t.assignedNodes({flatten:!0}).filter(s=>s.nodeName==="svg")}onSlotChange(t){const o=t.target,e=this.getSVGNodes(o);this.updateSVG(e)}}a([u("slot")],IconsetSVG.prototype,"slotContainer",2);
|
6
|
+
//# sourceMappingURL=iconset-svg.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["iconset-svg.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { query } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { Iconset } from './iconset.js';\n\nexport abstract class IconsetSVG extends Iconset {\n private iconMap: Map<string, SVGSymbolElement> = new Map();\n\n @query('slot')\n private slotContainer?: HTMLSlotElement;\n\n /**\n * First updated handler just ensures we've processed any slotted symbols\n */\n public override updated(changedProperties: PropertyValues): void {\n if (!this.slotContainer) {\n return;\n }\n const currentSVGNodes = this.getSVGNodes(this.slotContainer);\n this.updateSVG(currentSVGNodes);\n super.updated(changedProperties);\n }\n /**\n * Applies the requested icon from this iconset instance to the given element.\n *\n * @param el - the element to apply the icon to\n * @param icon - the name of the icon within this set to apply.\n */\n public async applyIconToElement(\n el: HTMLElement,\n icon: string,\n _size: string,\n label: string\n ): Promise<void> {\n await this.updateComplete;\n const iconSymbol = this.iconMap.get(icon);\n if (!iconSymbol) {\n throw new Error(`Unable to find icon ${icon}`);\n }\n // we cannot share a single SVG globally across shadowroot boundaries\n // so copy the template node so we can inject it where we need it\n const clonedNode = this.prepareSvgClone(iconSymbol);\n clonedNode.setAttribute('role', 'img');\n if (label) {\n clonedNode.setAttribute('aria-label', label);\n } else {\n clonedNode.setAttribute('aria-hidden', 'true');\n }\n // append the svg to the node either in its shadowroot or directly into its dom\n if (el.shadowRoot) {\n el.shadowRoot.appendChild(clonedNode);\n } else {\n el.appendChild(clonedNode);\n }\n }\n\n /**\n * Returns a list of all icons in this iconset.\n */\n public getIconList(): string[] {\n return [...this.iconMap.keys()];\n }\n\n protected prepareSvgClone(sourceSvg: SVGSymbolElement): SVGSVGElement {\n const content = sourceSvg.cloneNode(true) as SVGSymbolElement;\n // we're going to create a new svg element that will have our symbol geometry inside\n const svg = document.createElementNS(\n 'http://www.w3.org/2000/svg',\n 'svg'\n );\n const viewBox = content.getAttribute('viewBox') || '';\n // inline style isn't ideal but will work in all cases and means our icons don't need to know\n // if they are svg or spritesheet provided\n const cssText =\n 'pointer-events: none; display: block; width: 100%; height: 100%;';\n svg.style.cssText = cssText;\n // copy the viewbox and other properties into the svg\n svg.setAttribute('viewBox', viewBox);\n svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');\n svg.setAttribute('focusable', 'false');\n // move all the child nodes over to the svg\n while (content.childNodes.length > 0) {\n svg.appendChild(content.childNodes[0]);\n }\n return svg;\n }\n protected getSVGIconName(icon: string): string {\n return icon;\n }\n protected getSanitizedIconName(icon: string): string {\n return icon;\n }\n protected renderDefaultContent(): TemplateResult {\n return html``;\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.onSlotChange}>\n ${this.renderDefaultContent()}\n </slot>\n `;\n }\n\n protected updateSVG(nodes: SVGElement[]): void {\n // iterate over the nodes that were passed in, and find all the top level symbols\n const symbols = nodes.reduce((prev, svgNode) => {\n const containedSymbols = svgNode.querySelectorAll('symbol');\n prev.push(...containedSymbols);\n return prev;\n }, [] as SVGSymbolElement[]);\n symbols.forEach((symbol) => {\n this.iconMap.set(this.getSanitizedIconName(symbol.id), symbol);\n });\n }\n\n protected getSVGNodes(slotTarget: HTMLSlotElement): SVGElement[] {\n const nodes = slotTarget.assignedNodes({ flatten: true });\n // find all the svg nodes\n const svgNodes = nodes.filter((node) => {\n return node.nodeName === 'svg';\n }) as SVGElement[];\n return svgNodes;\n }\n\n private onSlotChange(event: Event): void {\n const slotTarget = event.target as HTMLSlotElement;\n const svgNodes = this.getSVGNodes(slotTarget);\n this.updateSVG(svgNodes);\n }\n}\n"],
|
5
|
+
"mappings": "qNAYA,OACI,QAAAA,MAGG,gCACP,OAAS,SAAAC,MAAa,kDAEtB,OAAS,WAAAC,MAAe,eAEjB,aAAe,mBAAmBA,CAAQ,CAA1C,kCACH,KAAQ,QAAyC,IAAI,IAQrC,QAAQC,EAAyC,CAC7D,GAAI,CAAC,KAAK,cACN,OAEJ,MAAMC,EAAkB,KAAK,YAAY,KAAK,aAAa,EAC3D,KAAK,UAAUA,CAAe,EAC9B,MAAM,QAAQD,CAAiB,CACnC,CAOA,MAAa,mBACTE,EACAC,EACAC,EACAC,EACa,CACb,MAAM,KAAK,eACX,MAAMC,EAAa,KAAK,QAAQ,IAAIH,CAAI,EACxC,GAAI,CAACG,EACD,MAAM,IAAI,MAAM,uBAAuBH,CAAI,EAAE,EAIjD,MAAMI,EAAa,KAAK,gBAAgBD,CAAU,EAClDC,EAAW,aAAa,OAAQ,KAAK,EACjCF,EACAE,EAAW,aAAa,aAAcF,CAAK,EAE3CE,EAAW,aAAa,cAAe,MAAM,EAG7CL,EAAG,WACHA,EAAG,WAAW,YAAYK,CAAU,EAEpCL,EAAG,YAAYK,CAAU,CAEjC,CAKO,aAAwB,CAC3B,M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iconset", "changedProperties", "currentSVGNodes", "el", "icon", "_size", "label", "iconSymbol", "clonedNode", "sourceSvg", "content", "svg", "viewBox", "cssText", "nodes", "prev", "svgNode", "containedSymbols", "symbol", "slotTarget", "node", "event", "svgNodes", "__decorateClass"]
|
7
|
+
}
|
package/src/iconset.d.ts
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import { LitElement } from '@spectrum-web-components/base';
|
2
|
+
export declare abstract class Iconset extends LitElement {
|
3
|
+
protected registered: boolean;
|
4
|
+
private _name;
|
5
|
+
protected firstUpdated(): void;
|
6
|
+
/**
|
7
|
+
* Name of the iconset, used by the IconsetRegistry to serve this icon set
|
8
|
+
* to consuming icons.
|
9
|
+
*/
|
10
|
+
set name(value: string);
|
11
|
+
get name(): string;
|
12
|
+
/**
|
13
|
+
* Applies an icon to the given element
|
14
|
+
*/
|
15
|
+
abstract applyIconToElement(el: HTMLElement, icon: string, size: string, label: string): void;
|
16
|
+
/**
|
17
|
+
* Returns a list of all icons in this iconset.
|
18
|
+
*/
|
19
|
+
abstract getIconList(): string[];
|
20
|
+
private handleRemoved;
|
21
|
+
/**
|
22
|
+
* On updated we register the iconset if we're not already registered
|
23
|
+
*/
|
24
|
+
connectedCallback(): void;
|
25
|
+
/**
|
26
|
+
* On disconnected we remove the iconset
|
27
|
+
*/
|
28
|
+
disconnectedCallback(): void;
|
29
|
+
private addIconset;
|
30
|
+
private removeIconset;
|
31
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
5
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
6
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
7
|
+
if (decorator = decorators[i])
|
8
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
10
|
+
return result;
|
11
|
+
};
|
12
|
+
import { IconsetRegistry } from "./iconset-registry.dev.js";
|
13
|
+
import { LitElement } from "@spectrum-web-components/base";
|
14
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
15
|
+
export class Iconset extends LitElement {
|
16
|
+
constructor() {
|
17
|
+
super(...arguments);
|
18
|
+
this.registered = false;
|
19
|
+
this.handleRemoved = ({
|
20
|
+
detail
|
21
|
+
}) => {
|
22
|
+
if (detail.name === this.name) {
|
23
|
+
this.registered = false;
|
24
|
+
this.addIconset();
|
25
|
+
}
|
26
|
+
};
|
27
|
+
}
|
28
|
+
firstUpdated() {
|
29
|
+
this.style.display = "none";
|
30
|
+
if (true) {
|
31
|
+
window.__swc.warn(
|
32
|
+
this,
|
33
|
+
"Iconsets have been deprecated and will be removed from the project in an upcoming version. For default Spectrum Icons, learn more about leveraging UI Icons (https://opensource.adobe.com/spectrum-web-components/components/icons-ui/) or Workflow Icons (https://opensource.adobe.com/spectrum-web-components/components/icons-workflow/) as an alternative.",
|
34
|
+
"https://opensource.adobe.com/spectrum-web-components/components/iconset/#deprecated",
|
35
|
+
{ level: "deprecation" }
|
36
|
+
);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
set name(value) {
|
40
|
+
if (this.registered) {
|
41
|
+
if (this._name) {
|
42
|
+
IconsetRegistry.getInstance().removeIconset(this._name);
|
43
|
+
}
|
44
|
+
if (value) {
|
45
|
+
IconsetRegistry.getInstance().addIconset(value, this);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
this._name = value;
|
49
|
+
}
|
50
|
+
get name() {
|
51
|
+
return this._name;
|
52
|
+
}
|
53
|
+
/**
|
54
|
+
* On updated we register the iconset if we're not already registered
|
55
|
+
*/
|
56
|
+
connectedCallback() {
|
57
|
+
super.connectedCallback();
|
58
|
+
this.addIconset();
|
59
|
+
window.addEventListener("sp-iconset-removed", this.handleRemoved);
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* On disconnected we remove the iconset
|
63
|
+
*/
|
64
|
+
disconnectedCallback() {
|
65
|
+
super.disconnectedCallback();
|
66
|
+
window.removeEventListener("sp-iconset-removed", this.handleRemoved);
|
67
|
+
this.removeIconset();
|
68
|
+
}
|
69
|
+
addIconset() {
|
70
|
+
if (!this.name || this.registered) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
IconsetRegistry.getInstance().addIconset(this.name, this);
|
74
|
+
this.registered = true;
|
75
|
+
}
|
76
|
+
removeIconset() {
|
77
|
+
if (!this.name) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
IconsetRegistry.getInstance().removeIconset(this.name);
|
81
|
+
this.registered = false;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
__decorateClass([
|
85
|
+
property()
|
86
|
+
], Iconset.prototype, "name", 1);
|
87
|
+
//# sourceMappingURL=iconset.dev.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["iconset.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { IconsetRegistry } from './iconset-registry.dev.js'\n\nimport { LitElement } from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nexport abstract class Iconset extends LitElement {\n protected registered = false;\n\n private _name!: string;\n\n protected override firstUpdated(): void {\n // force no display for all iconsets\n this.style.display = 'none';\n if (window.__swc.DEBUG) {\n window.__swc.warn(\n this,\n 'Iconsets have been deprecated and will be removed from the project in an upcoming version. For default Spectrum Icons, learn more about leveraging UI Icons (https://opensource.adobe.com/spectrum-web-components/components/icons-ui/) or Workflow Icons (https://opensource.adobe.com/spectrum-web-components/components/icons-workflow/) as an alternative.',\n 'https://opensource.adobe.com/spectrum-web-components/components/iconset/#deprecated',\n { level: 'deprecation' }\n );\n }\n }\n\n /**\n * Name of the iconset, used by the IconsetRegistry to serve this icon set\n * to consuming icons.\n */\n @property()\n public set name(value: string) {\n // if we're already registered in the iconset registry\n // we'll need to update our registration\n if (this.registered) {\n if (this._name) {\n // remove from the iconset map using the old name\n IconsetRegistry.getInstance().removeIconset(this._name);\n }\n\n if (value) {\n // set in the map using the new name\n IconsetRegistry.getInstance().addIconset(value, this);\n }\n }\n this._name = value;\n }\n public get name(): string {\n return this._name;\n }\n\n /**\n * Applies an icon to the given element\n */\n public abstract applyIconToElement(\n el: HTMLElement,\n icon: string,\n size: string,\n label: string\n ): void;\n\n /**\n * Returns a list of all icons in this iconset.\n */\n public abstract getIconList(): string[];\n\n private handleRemoved = ({\n detail,\n }: {\n detail: { name: string };\n }): void => {\n if (detail.name === this.name) {\n this.registered = false;\n this.addIconset();\n }\n };\n\n /**\n * On updated we register the iconset if we're not already registered\n */\n public override connectedCallback(): void {\n super.connectedCallback();\n this.addIconset();\n window.addEventListener('sp-iconset-removed', this.handleRemoved);\n }\n /**\n * On disconnected we remove the iconset\n */\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n window.removeEventListener('sp-iconset-removed', this.handleRemoved);\n this.removeIconset();\n }\n\n private addIconset(): void {\n if (!this.name || this.registered) {\n return;\n }\n IconsetRegistry.getInstance().addIconset(this.name, this);\n this.registered = true;\n }\n\n private removeIconset(): void {\n if (!this.name) {\n return;\n }\n IconsetRegistry.getInstance().removeIconset(this.name);\n this.registered = false;\n }\n}\n"],
|
5
|
+
"mappings": ";;;;;;;;;;;AAWA,SAAS,uBAAuB;AAEhC,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAElB,aAAe,gBAAgB,WAAW;AAAA,EAA1C;AAAA;AACH,SAAU,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ACJ;AA9Ee;AAAA,EADV,SAAS;AAAA,GAtBQ,QAuBP;",
|
6
|
+
"names": []
|
7
|
+
}
|
package/src/iconset.js
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";var d=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var a=(i,n,e,s)=>{for(var t=s>1?void 0:s?m(n,e):n,r=i.length-1,c;r>=0;r--)(c=i[r])&&(t=(s?c(n,e,t):c(t))||t);return s&&t&&d(n,e,t),t};import{IconsetRegistry as o}from"./iconset-registry.js";import{LitElement as p}from"@spectrum-web-components/base";import{property as l}from"@spectrum-web-components/base/src/decorators.js";export class Iconset extends p{constructor(){super(...arguments);this.registered=!1;this.handleRemoved=({detail:e})=>{e.name===this.name&&(this.registered=!1,this.addIconset())}}firstUpdated(){this.style.display="none"}set name(e){this.registered&&(this._name&&o.getInstance().removeIconset(this._name),e&&o.getInstance().addIconset(e,this)),this._name=e}get name(){return this._name}connectedCallback(){super.connectedCallback(),this.addIconset(),window.addEventListener("sp-iconset-removed",this.handleRemoved)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("sp-iconset-removed",this.handleRemoved),this.removeIconset()}addIconset(){!this.name||this.registered||(o.getInstance().addIconset(this.name,this),this.registered=!0)}removeIconset(){this.name&&(o.getInstance().removeIconset(this.name),this.registered=!1)}}a([l()],Iconset.prototype,"name",1);
|
2
|
+
//# sourceMappingURL=iconset.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["iconset.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { IconsetRegistry } from './iconset-registry.js';\n\nimport { LitElement } from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nexport abstract class Iconset extends LitElement {\n protected registered = false;\n\n private _name!: string;\n\n protected override firstUpdated(): void {\n // force no display for all iconsets\n this.style.display = 'none';\n if (window.__swc.DEBUG) {\n window.__swc.warn(\n this,\n 'Iconsets have been deprecated and will be removed from the project in an upcoming version. For default Spectrum Icons, learn more about leveraging UI Icons (https://opensource.adobe.com/spectrum-web-components/components/icons-ui/) or Workflow Icons (https://opensource.adobe.com/spectrum-web-components/components/icons-workflow/) as an alternative.',\n 'https://opensource.adobe.com/spectrum-web-components/components/iconset/#deprecated',\n { level: 'deprecation' }\n );\n }\n }\n\n /**\n * Name of the iconset, used by the IconsetRegistry to serve this icon set\n * to consuming icons.\n */\n @property()\n public set name(value: string) {\n // if we're already registered in the iconset registry\n // we'll need to update our registration\n if (this.registered) {\n if (this._name) {\n // remove from the iconset map using the old name\n IconsetRegistry.getInstance().removeIconset(this._name);\n }\n\n if (value) {\n // set in the map using the new name\n IconsetRegistry.getInstance().addIconset(value, this);\n }\n }\n this._name = value;\n }\n public get name(): string {\n return this._name;\n }\n\n /**\n * Applies an icon to the given element\n */\n public abstract applyIconToElement(\n el: HTMLElement,\n icon: string,\n size: string,\n label: string\n ): void;\n\n /**\n * Returns a list of all icons in this iconset.\n */\n public abstract getIconList(): string[];\n\n private handleRemoved = ({\n detail,\n }: {\n detail: { name: string };\n }): void => {\n if (detail.name === this.name) {\n this.registered = false;\n this.addIconset();\n }\n };\n\n /**\n * On updated we register the iconset if we're not already registered\n */\n public override connectedCallback(): void {\n super.connectedCallback();\n this.addIconset();\n window.addEventListener('sp-iconset-removed', this.handleRemoved);\n }\n /**\n * On disconnected we remove the iconset\n */\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n window.removeEventListener('sp-iconset-removed', this.handleRemoved);\n this.removeIconset();\n }\n\n private addIconset(): void {\n if (!this.name || this.registered) {\n return;\n }\n IconsetRegistry.getInstance().addIconset(this.name, this);\n this.registered = true;\n }\n\n private removeIconset(): void {\n if (!this.name) {\n return;\n }\n IconsetRegistry.getInstance().removeIconset(this.name);\n this.registered = false;\n }\n}\n"],
|
5
|
+
"mappings": "qNAWA,OAAS,mBAAAA,MAAuB,wBAEhC,OAAS,cAAAC,MAAkB,gCAC3B,OAAS,YAAAC,MAAgB,kDAElB,aAAe,gBAAgBD,CAAW,CAA1C,kCACH,KAAU,WAAa,GAyDvB,KAAQ,cAAgB,CAAC,CACrB,OAAAE,CACJ,IAEY,CACJA,EAAO,OAAS,KAAK,OACrB,KAAK,WAAa,GAClB,KAAK,WAAW,EAExB,EA9DmB,cAAqB,CAEpC,KAAK,MAAM,QAAU,MASzB,CAOA,IAAW,KAAKC,EAAe,CAGvB,KAAK,aACD,KAAK,OAELJ,EAAgB,YAAY,EAAE,cAAc,KAAK,KAAK,EAGtDI,GAEAJ,EAAgB,YAAY,EAAE,WAAWI,EAAO,IAAI,GAG5D,KAAK,MAAQA,CACjB,CACA,IAAW,MAAe,CACtB,OAAO,KAAK,KAChB,CA+BgB,mBAA0B,CACtC,MAAM,kBAAkB,EACxB,KAAK,WAAW,EAChB,OAAO,iBAAiB,qBAAsB,KAAK,aAAa,CACpE,CAIgB,sBAA6B,CACzC,MAAM,qBAAqB,EAC3B,OAAO,oBAAoB,qBAAsB,KAAK,aAAa,EACnE,KAAK,cAAc,CACvB,CAEQ,YAAmB,CACnB,CAAC,KAAK,MAAQ,KAAK,aAGvBJ,EAAgB,YAAY,EAAE,WAAW,KAAK,KAAM,IAAI,EACxD,KAAK,WAAa,GACtB,CAEQ,eAAsB,CACrB,KAAK,OAGVA,EAAgB,YAAY,EAAE,cAAc,KAAK,IAAI,EACrD,KAAK,WAAa,GACtB,CACJ,CA9EeK,EAAA,CADVH,EAAS,GAtBQ,QAuBP",
|
6
|
+
"names": ["IconsetRegistry", "LitElement", "property", "detail", "value", "__decorateClass"]
|
7
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.dev.js
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["index.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nexport * from './iconset.dev.js'\nexport * from './iconset-svg.dev.js'\nexport * from './iconset-registry.dev.js'\n"],
|
5
|
+
"mappings": ";AAUA,cAAc;AACd,cAAc;AACd,cAAc;",
|
6
|
+
"names": []
|
7
|
+
}
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["index.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nexport * from './iconset.js';\nexport * from './iconset-svg.js';\nexport * from './iconset-registry.js';\n"],
|
5
|
+
"mappings": "aAUA,WAAc,eACd,WAAc,mBACd,WAAc",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -0,0 +1,280 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
5
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
6
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
7
|
+
if (decorator = decorators[i])
|
8
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
10
|
+
return result;
|
11
|
+
};
|
12
|
+
import {
|
13
|
+
css,
|
14
|
+
html,
|
15
|
+
SpectrumElement
|
16
|
+
} from "@spectrum-web-components/base";
|
17
|
+
import {
|
18
|
+
customElement,
|
19
|
+
property,
|
20
|
+
state
|
21
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
22
|
+
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
23
|
+
import "@spectrum-web-components/search/sp-search.js";
|
24
|
+
import "@spectrum-web-components/field-label/sp-field-label.js";
|
25
|
+
import bodyStyles from "@spectrum-web-components/styles/body.js";
|
26
|
+
import "@spectrum-web-components/icon/sp-icon.js";
|
27
|
+
import "@spectrum-web-components/help-text/sp-help-text.js";
|
28
|
+
import iconsList from "./iconsList.json";
|
29
|
+
import {
|
30
|
+
SystemResolutionController,
|
31
|
+
systemResolverUpdatedSymbol
|
32
|
+
} from "@spectrum-web-components/reactive-controllers/src/SystemContextResolution.js";
|
33
|
+
export let DelayedReady = class extends SpectrumElement {
|
34
|
+
render() {
|
35
|
+
return html`
|
36
|
+
<slot @slotchange=${this.handleSlotchange}></slot>
|
37
|
+
`;
|
38
|
+
}
|
39
|
+
firstUpdated() {
|
40
|
+
this._delayedReady = new Promise(
|
41
|
+
(res) => this._resolveDelayedReady = res
|
42
|
+
);
|
43
|
+
}
|
44
|
+
async getUpdateComplete() {
|
45
|
+
const complete = await super.getUpdateComplete();
|
46
|
+
await this._delayedReady;
|
47
|
+
return complete;
|
48
|
+
}
|
49
|
+
handleSlotchange({
|
50
|
+
target
|
51
|
+
}) {
|
52
|
+
if (target.assignedElements({ flatten: true }).length) {
|
53
|
+
requestAnimationFrame(() => {
|
54
|
+
this._resolveDelayedReady();
|
55
|
+
});
|
56
|
+
}
|
57
|
+
}
|
58
|
+
};
|
59
|
+
DelayedReady = __decorateClass([
|
60
|
+
customElement("delayed-ready")
|
61
|
+
], DelayedReady);
|
62
|
+
export let IconsDemo = class extends SpectrumElement {
|
63
|
+
constructor() {
|
64
|
+
super();
|
65
|
+
this.name = "ui";
|
66
|
+
this.package = "";
|
67
|
+
this.size = "m";
|
68
|
+
this.search = "";
|
69
|
+
this.icons = [];
|
70
|
+
this.filteredIcons = [];
|
71
|
+
this.unsubscribeSystemContext = null;
|
72
|
+
this.spectrumVersion = 1;
|
73
|
+
this.iconset = [];
|
74
|
+
this.systemResolver = new SystemResolutionController(this);
|
75
|
+
this.iconset = [];
|
76
|
+
this.handleIconSetAdded = this.handleIconSetAdded.bind(this);
|
77
|
+
}
|
78
|
+
async connectedCallback() {
|
79
|
+
super.connectedCallback();
|
80
|
+
window.addEventListener("sp-iconset-added", this.handleIconSetAdded);
|
81
|
+
}
|
82
|
+
disconnectedCallback() {
|
83
|
+
window.removeEventListener("sp-iconset-added", this.handleIconSetAdded);
|
84
|
+
super.disconnectedCallback();
|
85
|
+
if (this.unsubscribeSystemContext) {
|
86
|
+
this.unsubscribeSystemContext();
|
87
|
+
this.unsubscribeSystemContext = null;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
filterIconsBySpectrumVersion() {
|
91
|
+
const iconVersion = this.spectrumVersion === 2 ? "s2" : "s1";
|
92
|
+
let filteredIcons = this.icons;
|
93
|
+
if (this.name === "workflow") {
|
94
|
+
filteredIcons = filteredIcons.filter((icon) => {
|
95
|
+
const iconName = icon.name.replace(/\s/g, "").toLowerCase();
|
96
|
+
return iconsList[iconVersion].includes(iconName);
|
97
|
+
});
|
98
|
+
}
|
99
|
+
const iconSet = /* @__PURE__ */ new Set();
|
100
|
+
filteredIcons = filteredIcons.filter((icon) => {
|
101
|
+
if (iconSet.has(icon.name)) {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
iconSet.add(icon.name);
|
105
|
+
return true;
|
106
|
+
});
|
107
|
+
this.filteredIcons = filteredIcons;
|
108
|
+
}
|
109
|
+
update(changes) {
|
110
|
+
if (changes.has(systemResolverUpdatedSymbol)) {
|
111
|
+
this.spectrumVersion = this.systemResolver.system === "spectrum-two" ? 2 : 1;
|
112
|
+
this.filterIconsBySpectrumVersion();
|
113
|
+
}
|
114
|
+
if (changes.has("icons")) {
|
115
|
+
this.filterIconsBySpectrumVersion();
|
116
|
+
}
|
117
|
+
super.update(changes);
|
118
|
+
}
|
119
|
+
handleIconSetAdded(event) {
|
120
|
+
const { iconset } = event.detail;
|
121
|
+
this.iconset = iconset.getIconList();
|
122
|
+
this.requestUpdate();
|
123
|
+
}
|
124
|
+
static get styles() {
|
125
|
+
return [
|
126
|
+
...bodyStyles,
|
127
|
+
css`
|
128
|
+
:host {
|
129
|
+
display: grid;
|
130
|
+
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
131
|
+
gap: 20px;
|
132
|
+
align-items: flex-start;
|
133
|
+
}
|
134
|
+
.icon {
|
135
|
+
display: flex;
|
136
|
+
flex-direction: column;
|
137
|
+
align-items: center;
|
138
|
+
text-align: center;
|
139
|
+
border-radius: var(
|
140
|
+
--spectrum-alias-focus-ring-gap,
|
141
|
+
var(--spectrum-spacing-50)
|
142
|
+
);
|
143
|
+
}
|
144
|
+
:host([package]) .icon {
|
145
|
+
cursor: pointer;
|
146
|
+
}
|
147
|
+
sp-icon {
|
148
|
+
margin-bottom: 10px;
|
149
|
+
}
|
150
|
+
.search {
|
151
|
+
grid-column-start: 1;
|
152
|
+
grid-column-end: -1;
|
153
|
+
}
|
154
|
+
.icon[tabindex]:focus {
|
155
|
+
outline: none;
|
156
|
+
}
|
157
|
+
.icon[tabindex]:focus-visible {
|
158
|
+
outline: var(--spectrum-alias-focus-ring-size) solid
|
159
|
+
var(--spectrum-alias-focus-ring-color);
|
160
|
+
outline-offset: calc(
|
161
|
+
var(
|
162
|
+
--spectrum-alias-focus-ring-gap,
|
163
|
+
var(--spectrum-spacing-50)
|
164
|
+
) * 2
|
165
|
+
);
|
166
|
+
}
|
167
|
+
`
|
168
|
+
];
|
169
|
+
}
|
170
|
+
handleKeydown(event, tag) {
|
171
|
+
const { code } = event;
|
172
|
+
if (code !== "Enter" && code !== "NumpadEnter" && code !== "Space") {
|
173
|
+
return;
|
174
|
+
}
|
175
|
+
event.preventDefault();
|
176
|
+
this.shouldCopy(tag);
|
177
|
+
}
|
178
|
+
shouldCopy(tag) {
|
179
|
+
if (!this.package) return;
|
180
|
+
const conditionedTag = tag.slice(1, tag.length - 1);
|
181
|
+
const importURL = `import '@spectrum-web-components/${this.package}/icons/${conditionedTag}.js';`;
|
182
|
+
this.dispatchEvent(
|
183
|
+
new CustomEvent("copy-text", {
|
184
|
+
bubbles: true,
|
185
|
+
composed: true,
|
186
|
+
detail: {
|
187
|
+
message: "Import statement copied to clipboard!",
|
188
|
+
text: importURL
|
189
|
+
}
|
190
|
+
})
|
191
|
+
);
|
192
|
+
}
|
193
|
+
updateSearch(event) {
|
194
|
+
event.stopPropagation();
|
195
|
+
this.search = event.target.value;
|
196
|
+
}
|
197
|
+
submit(event) {
|
198
|
+
event.stopPropagation();
|
199
|
+
this.updateSearch(event);
|
200
|
+
}
|
201
|
+
renderSearch() {
|
202
|
+
const matchingIcons = this.search ? this.filteredIcons.filter(
|
203
|
+
(icon) => icon.name.toLowerCase().includes(this.search.toLowerCase())
|
204
|
+
) : this.filteredIcons;
|
205
|
+
return html`
|
206
|
+
<div class="search" part="search">
|
207
|
+
<sp-field-label for="search">Spectrum icons:</sp-field-label>
|
208
|
+
<sp-search
|
209
|
+
id="search"
|
210
|
+
@keydown=${this.updateSearch}
|
211
|
+
@input=${this.updateSearch}
|
212
|
+
@submit=${this.submit}
|
213
|
+
.value=${this.search}
|
214
|
+
label="Search for icons"
|
215
|
+
autocomplete="off"
|
216
|
+
>
|
217
|
+
<sp-help-text slot="help-text">
|
218
|
+
Showing ${matchingIcons.length} of
|
219
|
+
${this.filteredIcons.length} available icons.
|
220
|
+
</sp-help-text>
|
221
|
+
</sp-search>
|
222
|
+
</div>
|
223
|
+
${matchingIcons.map((icon) => {
|
224
|
+
return html`
|
225
|
+
<bdo
|
226
|
+
class="icon"
|
227
|
+
part="icon"
|
228
|
+
dir="ltr"
|
229
|
+
class="icon"
|
230
|
+
@click=${() => this.shouldCopy(icon.tag)}
|
231
|
+
@keydown=${(event) => this.handleKeydown(event, icon.tag)}
|
232
|
+
tabindex=${ifDefined(this.package ? "0" : void 0)}
|
233
|
+
>
|
234
|
+
${icon.story(this.size)} ${icon.tag}
|
235
|
+
</bdo>
|
236
|
+
`;
|
237
|
+
})}
|
238
|
+
`;
|
239
|
+
}
|
240
|
+
render() {
|
241
|
+
return html`
|
242
|
+
${this.filteredIcons.length ? this.renderSearch() : html`
|
243
|
+
<slot></slot>
|
244
|
+
`}
|
245
|
+
${this.iconset.map(
|
246
|
+
(icon) => html`
|
247
|
+
<bdo class="icon" dir="ltr">
|
248
|
+
<sp-icon
|
249
|
+
size="xl"
|
250
|
+
name=${`${this.name}:${icon}`}
|
251
|
+
></sp-icon>
|
252
|
+
${icon}
|
253
|
+
</bdo>
|
254
|
+
`
|
255
|
+
)}
|
256
|
+
`;
|
257
|
+
}
|
258
|
+
};
|
259
|
+
__decorateClass([
|
260
|
+
property()
|
261
|
+
], IconsDemo.prototype, "name", 2);
|
262
|
+
__decorateClass([
|
263
|
+
property()
|
264
|
+
], IconsDemo.prototype, "package", 2);
|
265
|
+
__decorateClass([
|
266
|
+
property()
|
267
|
+
], IconsDemo.prototype, "size", 2);
|
268
|
+
__decorateClass([
|
269
|
+
property()
|
270
|
+
], IconsDemo.prototype, "search", 2);
|
271
|
+
__decorateClass([
|
272
|
+
property({ attribute: false })
|
273
|
+
], IconsDemo.prototype, "icons", 2);
|
274
|
+
__decorateClass([
|
275
|
+
state()
|
276
|
+
], IconsDemo.prototype, "spectrumVersion", 2);
|
277
|
+
IconsDemo = __decorateClass([
|
278
|
+
customElement("icons-demo")
|
279
|
+
], IconsDemo);
|
280
|
+
//# sourceMappingURL=icons-demo.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["icons-demo.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { IconsetAddedDetail } from '@spectrum-web-components/iconset';\nimport {\n css,\n CSSResultGroup,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n customElement,\n property,\n state,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport { Search } from '@spectrum-web-components/search';\nimport '@spectrum-web-components/search/sp-search.js';\nimport '@spectrum-web-components/field-label/sp-field-label.js';\nimport bodyStyles from '@spectrum-web-components/styles/body.js';\nimport '@spectrum-web-components/icon/sp-icon.js';\nimport '@spectrum-web-components/help-text/sp-help-text.js';\n\nimport iconsList from './iconsList.json' assert { type: 'json' };\n\nimport {\n SystemResolutionController,\n systemResolverUpdatedSymbol,\n} from '@spectrum-web-components/reactive-controllers/src/SystemContextResolution.js';\n\n@customElement('delayed-ready')\nexport class DelayedReady extends SpectrumElement {\n _delayedReady!: Promise<void>;\n _resolveDelayedReady!: () => void;\n\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.handleSlotchange}></slot>\n `;\n }\n\n protected override firstUpdated(): void {\n this._delayedReady = new Promise(\n (res) => (this._resolveDelayedReady = res)\n );\n }\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this._delayedReady;\n return complete;\n }\n\n public handleSlotchange({\n target,\n }: Event & { target: HTMLSlotElement }): void {\n if (target.assignedElements({ flatten: true }).length) {\n requestAnimationFrame(() => {\n this._resolveDelayedReady();\n });\n }\n }\n}\n\n@customElement('icons-demo')\nexport class IconsDemo extends SpectrumElement {\n @property()\n public name = 'ui';\n\n @property()\n public package = '';\n\n @property()\n public size = 'm';\n\n @property()\n public search = '';\n\n @property({ attribute: false })\n public icons: {\n name: string;\n story(size: string): TemplateResult;\n tag: string;\n }[] = [];\n\n private filteredIcons: {\n name: string;\n story(size: string): TemplateResult;\n tag: string;\n }[] = [];\n\n private unsubscribeSystemContext: (() => void) | null = null;\n\n @state()\n public spectrumVersion = 1;\n\n private iconset: string[] = [];\n public constructor() {\n super();\n this.iconset = [];\n this.handleIconSetAdded = this.handleIconSetAdded.bind(this);\n }\n\n public override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n window.addEventListener('sp-iconset-added', this.handleIconSetAdded);\n }\n public override disconnectedCallback(): void {\n window.removeEventListener('sp-iconset-added', this.handleIconSetAdded);\n super.disconnectedCallback();\n if (this.unsubscribeSystemContext) {\n this.unsubscribeSystemContext();\n this.unsubscribeSystemContext = null;\n }\n }\n\n private filterIconsBySpectrumVersion(): void {\n const iconVersion = this.spectrumVersion === 2 ? 's2' : 's1';\n let filteredIcons = this.icons;\n // Filter out icons that are not in the current version for workflow icons\n if (this.name === 'workflow') {\n filteredIcons = filteredIcons.filter((icon) => {\n const iconName = icon.name.replace(/\\s/g, '').toLowerCase();\n return iconsList[iconVersion].includes(iconName);\n });\n }\n\n // Use a Set to remove duplicates that may get added because of the same icon name in both versions\n const iconSet = new Set();\n filteredIcons = filteredIcons.filter((icon) => {\n if (iconSet.has(icon.name)) {\n return false;\n }\n iconSet.add(icon.name);\n return true;\n });\n\n this.filteredIcons = filteredIcons;\n }\n\n private systemResolver = new SystemResolutionController(this);\n\n protected override update(changes: PropertyValues): void {\n if (changes.has(systemResolverUpdatedSymbol)) {\n this.spectrumVersion =\n this.systemResolver.system === 'spectrum-two' ? 2 : 1;\n this.filterIconsBySpectrumVersion();\n }\n\n if (changes.has('icons')) {\n this.filterIconsBySpectrumVersion();\n }\n\n super.update(changes);\n }\n\n public handleIconSetAdded(event: CustomEvent<IconsetAddedDetail>): void {\n const { iconset } = event.detail;\n this.iconset = iconset.getIconList();\n this.requestUpdate();\n }\n public static override get styles(): CSSResultGroup {\n return [\n ...bodyStyles,\n css`\n :host {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));\n gap: 20px;\n align-items: flex-start;\n }\n .icon {\n display: flex;\n flex-direction: column;\n align-items: center;\n text-align: center;\n border-radius: var(\n --spectrum-alias-focus-ring-gap,\n var(--spectrum-spacing-50)\n );\n }\n :host([package]) .icon {\n cursor: pointer;\n }\n sp-icon {\n margin-bottom: 10px;\n }\n .search {\n grid-column-start: 1;\n grid-column-end: -1;\n }\n .icon[tabindex]:focus {\n outline: none;\n }\n .icon[tabindex]:focus-visible {\n outline: var(--spectrum-alias-focus-ring-size) solid\n var(--spectrum-alias-focus-ring-color);\n outline-offset: calc(\n var(\n --spectrum-alias-focus-ring-gap,\n var(--spectrum-spacing-50)\n ) * 2\n );\n }\n `,\n ];\n }\n private handleKeydown(event: KeyboardEvent, tag: string): void {\n const { code } = event;\n if (code !== 'Enter' && code !== 'NumpadEnter' && code !== 'Space') {\n return;\n }\n event.preventDefault();\n this.shouldCopy(tag);\n }\n\n private shouldCopy(tag: string): void {\n if (!this.package) return;\n const conditionedTag = tag.slice(1, tag.length - 1);\n const importURL = `import '@spectrum-web-components/${this.package}/icons/${conditionedTag}.js';`;\n this.dispatchEvent(\n new CustomEvent('copy-text', {\n bubbles: true,\n composed: true,\n detail: {\n message: 'Import statement copied to clipboard!',\n text: importURL,\n },\n })\n );\n }\n private updateSearch(event: Event & { target: Search }): void {\n event.stopPropagation();\n this.search = event.target.value;\n }\n private submit(event: Event & { target: Search }): void {\n event.stopPropagation();\n this.updateSearch(event);\n }\n private renderSearch(): TemplateResult {\n const matchingIcons = this.search\n ? this.filteredIcons.filter((icon) =>\n icon.name.toLowerCase().includes(this.search.toLowerCase())\n )\n : this.filteredIcons;\n\n return html`\n <div class=\"search\" part=\"search\">\n <sp-field-label for=\"search\">Spectrum icons:</sp-field-label>\n <sp-search\n id=\"search\"\n @keydown=${this.updateSearch}\n @input=${this.updateSearch}\n @submit=${this.submit}\n .value=${this.search}\n label=\"Search for icons\"\n autocomplete=\"off\"\n >\n <sp-help-text slot=\"help-text\">\n Showing ${matchingIcons.length} of\n ${this.filteredIcons.length} available icons.\n </sp-help-text>\n </sp-search>\n </div>\n ${matchingIcons.map((icon) => {\n return html`\n <bdo\n class=\"icon\"\n part=\"icon\"\n dir=\"ltr\"\n class=\"icon\"\n @click=${() => this.shouldCopy(icon.tag)}\n @keydown=${(event: KeyboardEvent) =>\n this.handleKeydown(event, icon.tag)}\n tabindex=${ifDefined(this.package ? '0' : undefined)}\n >\n ${icon.story(this.size)} ${icon.tag}\n </bdo>\n `;\n })}\n `;\n }\n protected override render(): TemplateResult {\n return html`\n ${this.filteredIcons.length\n ? this.renderSearch()\n : html`\n <slot></slot>\n `}\n ${this.iconset.map(\n (icon) => html`\n <bdo class=\"icon\" dir=\"ltr\">\n <sp-icon\n size=\"xl\"\n name=${`${this.name}:${icon}`}\n ></sp-icon>\n ${icon}\n </bdo>\n `\n )}\n `;\n }\n}\n"],
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA,EACI;AAAA,EAEA;AAAA,EAEA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,OACG;AACP,SAAS,iBAAiB;AAE1B,OAAO;AACP,OAAO;AACP,OAAO,gBAA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;AAAA,cAIrC,cAAc,IAAI,CAAC,SAAS;AAC1B,aAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAMU,MAAM,KAAK,WAAW,KAAK,GAAG,CAAC;AAAA,mCAC7B,CAAC,UACR,KAAK,cAAc,OAAO,KAAK,GAAG,CAAC;AAAA,mCAC5B,UAAU,KAAK,UAAU,MAAM,MAAS,CAAC;AAAA;AAAA,0BAElD,KAAK,MAAM,KAAK,IAAI,CAAC,IAAI,KAAK,GAAG;AAAA;AAAA;AAAA,IAG/C,CAAC,CAAC;AAAA;AAAA,EAEV;AAAA,EACmB,SAAyB;AACxC,WAAO;AAAA,cACD,KAAK,cAAc,SACf,KAAK,aAAa,IAClB;AAAA;AAAA,mBAEC;AAAA,cACL,KAAK,QAAQ;AAAA,MACX,CAAC,SAAS;AAAA;AAAA;AAAA;AAAA,mCAIS,GAAG,KAAK,IAAI,IAAI,IAAI,EAAE;AAAA;AAAA,0BAE/B,IAAI;AAAA;AAAA;AAAA,IAGlB,CAAC;AAAA;AAAA,EAET;AACJ;AA3OW;AAAA,EADN,SAAS;AAAA,GADD,UAEF;AAGA;AAAA,EADN,SAAS;AAAA,GAJD,UAKF;AAGA;AAAA,EADN,SAAS;AAAA,GAPD,UAQF;AAGA;AAAA,EADN,SAAS;AAAA,GAVD,UAWF;AAGA;AAAA,EADN,SAAS,EAAE,WAAW,MAAM,CAAC;AAAA,GAbrB,UAcF;AAeA;AAAA,EADN,MAAM;AAAA,GA5BE,UA6BF;AA7BE,YAAN;AAAA,EADN,cAAc,YAAY;AAAA,GACd;",
|
6
|
+
"names": []
|
7
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
"use strict";
|
2
|
+
import { waitForPredicate } from "../../../test/testing-helpers.js";
|
3
|
+
import "@spectrum-web-components/icons/sp-icons-medium.js";
|
4
|
+
import "@spectrum-web-components/icon/sp-icon.js";
|
5
|
+
import { IconsetRegistry } from "@spectrum-web-components/iconset/src/iconset-registry.js";
|
6
|
+
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
7
|
+
import { stub } from "sinon";
|
8
|
+
describe("Iconset", () => {
|
9
|
+
after(() => {
|
10
|
+
const sets = [...document.querySelectorAll("sp-icons-medium")];
|
11
|
+
sets.map((set) => set.remove());
|
12
|
+
});
|
13
|
+
it("warns in Dev Mode of deprecation", async () => {
|
14
|
+
const consoleWarnStub = stub(console, "warn");
|
15
|
+
const el = document.createElement("sp-icons-medium");
|
16
|
+
document.body.append(el);
|
17
|
+
await elementUpdated(el);
|
18
|
+
expect(consoleWarnStub.called).to.be.true;
|
19
|
+
const spyCall = consoleWarnStub.getCall(0);
|
20
|
+
expect(
|
21
|
+
spyCall.args.at(0).includes("deprecated"),
|
22
|
+
"confirm deprecation message"
|
23
|
+
).to.be.true;
|
24
|
+
expect(spyCall.args.at(-1), "confirm `data` shape").to.deep.equal({
|
25
|
+
data: {
|
26
|
+
localName: "sp-icons-medium",
|
27
|
+
type: "api",
|
28
|
+
level: "deprecation"
|
29
|
+
}
|
30
|
+
});
|
31
|
+
consoleWarnStub.restore();
|
32
|
+
});
|
33
|
+
it("will re-register with new name", async () => {
|
34
|
+
const icons = document.createElement("sp-icons-medium");
|
35
|
+
document.body.append(icons);
|
36
|
+
icons.name = "first-name";
|
37
|
+
const registry = IconsetRegistry.getInstance();
|
38
|
+
expect(registry.getIconset("first-name")).to.not.be.undefined;
|
39
|
+
expect(registry.getIconset("")).to.be.undefined;
|
40
|
+
expect(registry.getIconset("second-name")).to.be.undefined;
|
41
|
+
expect(registry.getIconset("ui")).to.be.undefined;
|
42
|
+
icons.name = "";
|
43
|
+
expect(registry.getIconset("first-name")).to.be.undefined;
|
44
|
+
expect(registry.getIconset("")).to.be.undefined;
|
45
|
+
expect(registry.getIconset("second-name")).to.be.undefined;
|
46
|
+
expect(registry.getIconset("ui")).to.be.undefined;
|
47
|
+
icons.name = "second-name";
|
48
|
+
expect(registry.getIconset("first-name")).to.be.undefined;
|
49
|
+
expect(registry.getIconset("")).to.be.undefined;
|
50
|
+
expect(registry.getIconset("second-name")).to.not.be.undefined;
|
51
|
+
expect(registry.getIconset("ui")).to.be.undefined;
|
52
|
+
});
|
53
|
+
it("will not re-register on (dis)connect without a name", async () => {
|
54
|
+
const icons = document.createElement("sp-icons-medium");
|
55
|
+
document.body.append(icons);
|
56
|
+
const registry = IconsetRegistry.getInstance();
|
57
|
+
expect(registry.getIconset("ui")).to.not.be.undefined;
|
58
|
+
icons.name = "";
|
59
|
+
expect(registry.getIconset("ui")).to.be.undefined;
|
60
|
+
icons.remove();
|
61
|
+
document.body.append(icons);
|
62
|
+
expect(registry.getIconset("ui")).to.be.undefined;
|
63
|
+
});
|
64
|
+
it("renders after adding and removing a second iconset of same name", async () => {
|
65
|
+
const icons = document.createElement("sp-icons-medium");
|
66
|
+
document.body.append(icons);
|
67
|
+
const icons2 = document.createElement("sp-icons-medium");
|
68
|
+
document.body.append(icons2);
|
69
|
+
icons2.remove();
|
70
|
+
window.dispatchEvent(
|
71
|
+
new CustomEvent("sp-iconset-removed", {
|
72
|
+
detail: { name: "Other Set" }
|
73
|
+
})
|
74
|
+
);
|
75
|
+
const el = await fixture(
|
76
|
+
html`
|
77
|
+
<sp-icon name="ui:Chevron200"></sp-icon>
|
78
|
+
`
|
79
|
+
);
|
80
|
+
let svg = el.shadowRoot ? el.shadowRoot.querySelector('[role="img"]') : null;
|
81
|
+
function getSVG() {
|
82
|
+
svg = el.shadowRoot ? el.shadowRoot.querySelector('[role="img"]') : null;
|
83
|
+
return svg !== null;
|
84
|
+
}
|
85
|
+
await waitForPredicate(getSVG);
|
86
|
+
expect(svg).to.not.be.null;
|
87
|
+
});
|
88
|
+
it("can be after `<sp-icon/>` in the DOM order", async () => {
|
89
|
+
const el = await fixture(
|
90
|
+
html`
|
91
|
+
<div>
|
92
|
+
<sp-icon name="ui:Chevron200"></sp-icon>
|
93
|
+
<sp-icons-medium></sp-icons-medium>
|
94
|
+
</div>
|
95
|
+
`
|
96
|
+
);
|
97
|
+
const icon = el.querySelector("sp-icon");
|
98
|
+
const iconSet = el.querySelector("sp-icons-medium");
|
99
|
+
await elementUpdated(iconSet);
|
100
|
+
await elementUpdated(icon);
|
101
|
+
const svg = icon.shadowRoot ? icon.shadowRoot.querySelector('[role="img"]') : null;
|
102
|
+
expect(svg).to.not.be.null;
|
103
|
+
});
|
104
|
+
});
|
105
|
+
//# sourceMappingURL=iconset.test.js.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["iconset.test.ts"],
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { waitForPredicate } from '../../../test/testing-helpers.js';\nimport '@spectrum-web-components/icons/sp-icons-medium.js';\nimport '@spectrum-web-components/icon/sp-icon.js';\nimport { IconsMedium } from '@spectrum-web-components/icons';\nimport { Icon } from '@spectrum-web-components/icon';\nimport { IconsetRegistry } from '@spectrum-web-components/iconset/src/iconset-registry.js';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\nimport { stub } from 'sinon';\n\ndescribe('Iconset', () => {\n after(() => {\n const sets = [...document.querySelectorAll('sp-icons-medium')];\n sets.map((set) => set.remove());\n });\n it('warns in Dev Mode of deprecation', async () => {\n const consoleWarnStub = stub(console, 'warn');\n const el = document.createElement('sp-icons-medium');\n document.body.append(el);\n\n await elementUpdated(el);\n\n expect(consoleWarnStub.called).to.be.true;\n const spyCall = consoleWarnStub.getCall(0);\n expect(\n spyCall.args.at(0).includes('deprecated'),\n 'confirm deprecation message'\n ).to.be.true;\n expect(spyCall.args.at(-1), 'confirm `data` shape').to.deep.equal({\n data: {\n localName: 'sp-icons-medium',\n type: 'api',\n level: 'deprecation',\n },\n });\n consoleWarnStub.restore();\n });\n\n it('will re-register with new name', async () => {\n const icons = document.createElement('sp-icons-medium');\n document.body.append(icons);\n icons.name = 'first-name';\n\n const registry = IconsetRegistry.getInstance();\n\n expect(registry.getIconset('first-name')).to.not.be.undefined;\n expect(registry.getIconset('')).to.be.undefined;\n expect(registry.getIconset('second-name')).to.be.undefined;\n expect(registry.getIconset('ui')).to.be.undefined;\n\n icons.name = '';\n\n expect(registry.getIconset('first-name')).to.be.undefined;\n expect(registry.getIconset('')).to.be.undefined;\n expect(registry.getIconset('second-name')).to.be.undefined;\n expect(registry.getIconset('ui')).to.be.undefined;\n\n icons.name = 'second-name';\n\n expect(registry.getIconset('first-name')).to.be.undefined;\n expect(registry.getIconset('')).to.be.undefined;\n expect(registry.getIconset('second-name')).to.not.be.undefined;\n expect(registry.getIconset('ui')).to.be.undefined;\n });\n it('will not re-register on (dis)connect without a name', async () => {\n const icons = document.createElement('sp-icons-medium');\n document.body.append(icons);\n\n const registry = IconsetRegistry.getInstance();\n\n expect(registry.getIconset('ui')).to.not.be.undefined;\n\n icons.name = '';\n\n expect(registry.getIconset('ui')).to.be.undefined;\n\n icons.remove();\n\n document.body.append(icons);\n\n expect(registry.getIconset('ui')).to.be.undefined;\n });\n it('renders after adding and removing a second iconset of same name', async () => {\n const icons = document.createElement('sp-icons-medium');\n document.body.append(icons);\n\n const icons2 = document.createElement('sp-icons-medium');\n document.body.append(icons2);\n\n icons2.remove();\n\n window.dispatchEvent(\n new CustomEvent('sp-iconset-removed', {\n detail: { name: 'Other Set' },\n })\n );\n\n const el = await fixture<Icon>(\n html`\n <sp-icon name=\"ui:Chevron200\"></sp-icon>\n `\n );\n\n let svg = el.shadowRoot\n ? el.shadowRoot.querySelector('[role=\"img\"]')\n : null;\n\n function getSVG(): boolean {\n svg = el.shadowRoot\n ? el.shadowRoot.querySelector('[role=\"img\"]')\n : null;\n\n return svg !== null;\n }\n\n await waitForPredicate(getSVG);\n\n expect(svg).to.not.be.null;\n });\n\n it('can be after `<sp-icon/>` in the DOM order', async () => {\n const el = await fixture<HTMLDivElement>(\n html`\n <div>\n <sp-icon name=\"ui:Chevron200\"></sp-icon>\n <sp-icons-medium></sp-icons-medium>\n </div>\n `\n );\n\n const icon = el.querySelector('sp-icon') as Icon;\n const iconSet = el.querySelector('sp-icons-medium') as IconsMedium;\n\n await elementUpdated(iconSet);\n await elementUpdated(icon);\n\n const svg = icon.shadowRoot\n ? icon.shadowRoot.querySelector('[role=\"img\"]')\n : null;\n expect(svg).to.not.be.null;\n });\n});\n"],
|
5
|
+
"mappings": ";AAYA,SAAS,wBAAwB;AACjC,OAAO;AACP,OAAO;AAGP,SAAS,uBAAuB;AAChC,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AACtD,SAAS,YAAY;AAErB,SAAS,WAAW,MAAM;AACtB,QAAM,MAAM;AACR,UAAM,OAAO,CAAC,GAAG,SAAS,iBAAiB,iBAAiB,CAAC;AAC7D,SAAK,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;AAAA,EAClC,CAAC;AACD,KAAG,oCAAoC,YAAY;AAC/C,UAAM,kBAAkB,KAAK,SAAS,MAAM;AAC5C,UAAM,KAAK,SAAS,cAAc,iBAAiB;AACnD,aAAS,KAAK,OAAO,EAAE;AAEvB,UAAM,eAAe,EAAE;AAEvB,WAAO,gBAAgB,MAAM,EAAE,GAAG,GAAG;AACrC,UAAM,UAAU,gBAAgB,QAAQ,CAAC;AACzC;AAAA,MACI,QAAQ,KAAK,GAAG,CAAC,EAAE,SAAS,YAAY;AAAA,MACxC;AAAA,IACJ,EAAE,GAAG,GAAG;AACR,WAAO,QAAQ,KAAK,GAAG,EAAE,GAAG,sBAAsB,EAAE,GAAG,KAAK,MAAM;AAAA,MAC9D,MAAM;AAAA,QACF,WAAW;AAAA,QACX,MAAM;AAAA,QACN,O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