@phcdevworks/spectre-components 1.0.0 → 1.1.0
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/README.md +113 -40
- package/dist/{base-DQtCQ-dP.d.cts → base-2rD8EmdC.d.cts} +15 -5
- package/dist/{base-DQtCQ-dP.d.ts → base-2rD8EmdC.d.ts} +15 -5
- package/dist/button.cjs +158 -58
- package/dist/button.cjs.map +1 -1
- package/dist/button.d.cts +22 -28
- package/dist/button.d.ts +22 -28
- package/dist/button.js +158 -58
- package/dist/button.js.map +1 -1
- package/dist/checkbox.cjs +164 -64
- package/dist/checkbox.cjs.map +1 -1
- package/dist/checkbox.d.cts +18 -23
- package/dist/checkbox.d.ts +18 -23
- package/dist/checkbox.js +164 -64
- package/dist/checkbox.js.map +1 -1
- package/dist/fieldset.cjs +154 -55
- package/dist/fieldset.cjs.map +1 -1
- package/dist/fieldset.d.cts +13 -18
- package/dist/fieldset.d.ts +13 -18
- package/dist/fieldset.js +154 -55
- package/dist/fieldset.js.map +1 -1
- package/dist/index.cjs +324 -261
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +324 -261
- package/dist/index.js.map +1 -1
- package/dist/input.cjs +174 -72
- package/dist/input.cjs.map +1 -1
- package/dist/input.d.cts +33 -38
- package/dist/input.d.ts +33 -38
- package/dist/input.js +174 -72
- package/dist/input.js.map +1 -1
- package/dist/label.cjs +152 -56
- package/dist/label.cjs.map +1 -1
- package/dist/label.d.cts +8 -13
- package/dist/label.d.ts +8 -13
- package/dist/label.js +152 -56
- package/dist/label.js.map +1 -1
- package/dist/{projectable-DcnBRiko.d.cts → projectable-BzDQ4xp_.d.cts} +1 -1
- package/dist/{projectable-SzbPvXfM.d.ts → projectable-s3SgvjGX.d.ts} +1 -1
- package/dist/radio.cjs +164 -64
- package/dist/radio.cjs.map +1 -1
- package/dist/radio.d.cts +18 -23
- package/dist/radio.d.ts +18 -23
- package/dist/radio.js +164 -64
- package/dist/radio.js.map +1 -1
- package/dist/select.cjs +161 -61
- package/dist/select.cjs.map +1 -1
- package/dist/select.d.cts +22 -27
- package/dist/select.d.ts +22 -27
- package/dist/select.js +161 -61
- package/dist/select.js.map +1 -1
- package/dist/textarea.cjs +172 -72
- package/dist/textarea.cjs.map +1 -1
- package/dist/textarea.d.cts +27 -32
- package/dist/textarea.d.ts +27 -32
- package/dist/textarea.js +172 -72
- package/dist/textarea.js.map +1 -1
- package/package.json +9 -8
package/dist/label.cjs
CHANGED
|
@@ -7,22 +7,67 @@ var ifDefined_js = require('lit/directives/if-defined.js');
|
|
|
7
7
|
var SpectreBaseElement = class extends lit.LitElement {
|
|
8
8
|
constructor() {
|
|
9
9
|
super(...arguments);
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
10
|
+
this._ariaLabel = null;
|
|
11
|
+
this._ariaLabelledBy = null;
|
|
12
|
+
this._ariaDescribedBy = null;
|
|
13
|
+
this._title = "";
|
|
14
|
+
this._id = "";
|
|
15
|
+
}
|
|
16
|
+
get ariaLabel() {
|
|
17
|
+
return this._ariaLabel;
|
|
18
|
+
}
|
|
19
|
+
set ariaLabel(value) {
|
|
20
|
+
if (this._ariaLabel === value) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this._ariaLabel = value;
|
|
24
|
+
this._removeHostAttribute("aria-label");
|
|
25
|
+
this.requestUpdate();
|
|
26
|
+
}
|
|
27
|
+
get ariaLabelledBy() {
|
|
28
|
+
return this._ariaLabelledBy;
|
|
29
|
+
}
|
|
30
|
+
set ariaLabelledBy(value) {
|
|
31
|
+
if (this._ariaLabelledBy === value) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this._ariaLabelledBy = value;
|
|
35
|
+
this._removeHostAttribute("aria-labelledby");
|
|
36
|
+
this.requestUpdate();
|
|
37
|
+
}
|
|
38
|
+
get ariaDescribedBy() {
|
|
39
|
+
return this._ariaDescribedBy;
|
|
40
|
+
}
|
|
41
|
+
set ariaDescribedBy(value) {
|
|
42
|
+
if (this._ariaDescribedBy === value) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this._ariaDescribedBy = value;
|
|
46
|
+
this._removeHostAttribute("aria-describedby");
|
|
47
|
+
this.requestUpdate();
|
|
48
|
+
}
|
|
49
|
+
get title() {
|
|
50
|
+
return this._title;
|
|
51
|
+
}
|
|
52
|
+
set title(value) {
|
|
53
|
+
const normalizedValue = value ?? "";
|
|
54
|
+
if (this._title === normalizedValue) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this._title = normalizedValue;
|
|
58
|
+
this._removeHostAttribute("title");
|
|
59
|
+
this.requestUpdate();
|
|
13
60
|
}
|
|
14
61
|
get id() {
|
|
15
|
-
return this._id
|
|
62
|
+
return this._id;
|
|
16
63
|
}
|
|
17
64
|
set id(value) {
|
|
18
|
-
|
|
65
|
+
const normalizedValue = value ?? "";
|
|
66
|
+
if (this._id === normalizedValue) {
|
|
19
67
|
return;
|
|
20
68
|
}
|
|
21
|
-
this._id =
|
|
22
|
-
|
|
23
|
-
if (HTMLElement.prototype.hasAttribute.call(host, "id")) {
|
|
24
|
-
HTMLElement.prototype.removeAttribute.call(host, "id");
|
|
25
|
-
}
|
|
69
|
+
this._id = normalizedValue;
|
|
70
|
+
this._removeHostAttribute("id");
|
|
26
71
|
this.requestUpdate();
|
|
27
72
|
}
|
|
28
73
|
// Spectre components intentionally render in light DOM so the global
|
|
@@ -32,36 +77,99 @@ var SpectreBaseElement = class extends lit.LitElement {
|
|
|
32
77
|
}
|
|
33
78
|
connectedCallback() {
|
|
34
79
|
super.connectedCallback();
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
80
|
+
const proxiedAttributes = [
|
|
81
|
+
"id",
|
|
82
|
+
"title",
|
|
83
|
+
"aria-label",
|
|
84
|
+
"aria-labelledby",
|
|
85
|
+
"aria-describedby"
|
|
86
|
+
];
|
|
87
|
+
proxiedAttributes.forEach((attr) => {
|
|
88
|
+
const value = super.getAttribute(attr);
|
|
89
|
+
if (value !== null) {
|
|
90
|
+
this.setAttribute(attr, value);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
39
93
|
}
|
|
40
94
|
getAttribute(qualifiedName) {
|
|
41
|
-
|
|
42
|
-
|
|
95
|
+
switch (qualifiedName) {
|
|
96
|
+
case "id":
|
|
97
|
+
return this.id || null;
|
|
98
|
+
case "title":
|
|
99
|
+
return this.title || null;
|
|
100
|
+
case "aria-label":
|
|
101
|
+
return this.ariaLabel;
|
|
102
|
+
case "aria-labelledby":
|
|
103
|
+
return this.ariaLabelledBy;
|
|
104
|
+
case "aria-describedby":
|
|
105
|
+
return this.ariaDescribedBy;
|
|
106
|
+
default:
|
|
107
|
+
return super.getAttribute(qualifiedName);
|
|
43
108
|
}
|
|
44
|
-
return super.getAttribute(qualifiedName);
|
|
45
109
|
}
|
|
46
110
|
hasAttribute(qualifiedName) {
|
|
47
|
-
|
|
48
|
-
|
|
111
|
+
switch (qualifiedName) {
|
|
112
|
+
case "id":
|
|
113
|
+
return this.id !== "";
|
|
114
|
+
case "title":
|
|
115
|
+
return this.title !== "";
|
|
116
|
+
case "aria-label":
|
|
117
|
+
return this.ariaLabel !== null;
|
|
118
|
+
case "aria-labelledby":
|
|
119
|
+
return this.ariaLabelledBy !== null;
|
|
120
|
+
case "aria-describedby":
|
|
121
|
+
return this.ariaDescribedBy !== null;
|
|
122
|
+
default:
|
|
123
|
+
return super.hasAttribute(qualifiedName);
|
|
49
124
|
}
|
|
50
|
-
return super.hasAttribute(qualifiedName);
|
|
51
125
|
}
|
|
52
126
|
setAttribute(qualifiedName, value) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
127
|
+
switch (qualifiedName) {
|
|
128
|
+
case "id":
|
|
129
|
+
this.id = value;
|
|
130
|
+
break;
|
|
131
|
+
case "title":
|
|
132
|
+
this.title = value;
|
|
133
|
+
break;
|
|
134
|
+
case "aria-label":
|
|
135
|
+
this.ariaLabel = value;
|
|
136
|
+
break;
|
|
137
|
+
case "aria-labelledby":
|
|
138
|
+
this.ariaLabelledBy = value;
|
|
139
|
+
break;
|
|
140
|
+
case "aria-describedby":
|
|
141
|
+
this.ariaDescribedBy = value;
|
|
142
|
+
break;
|
|
143
|
+
default:
|
|
144
|
+
super.setAttribute(qualifiedName, value);
|
|
56
145
|
}
|
|
57
|
-
super.setAttribute(qualifiedName, value);
|
|
58
146
|
}
|
|
59
147
|
removeAttribute(qualifiedName) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
148
|
+
switch (qualifiedName) {
|
|
149
|
+
case "id":
|
|
150
|
+
this.id = "";
|
|
151
|
+
break;
|
|
152
|
+
case "title":
|
|
153
|
+
this.title = "";
|
|
154
|
+
break;
|
|
155
|
+
case "aria-label":
|
|
156
|
+
this.ariaLabel = null;
|
|
157
|
+
break;
|
|
158
|
+
case "aria-labelledby":
|
|
159
|
+
this.ariaLabelledBy = null;
|
|
160
|
+
break;
|
|
161
|
+
case "aria-describedby":
|
|
162
|
+
this.ariaDescribedBy = null;
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
super.removeAttribute(qualifiedName);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
_removeHostAttribute(name) {
|
|
169
|
+
const host = this;
|
|
170
|
+
if (HTMLElement.prototype.hasAttribute.call(host, name)) {
|
|
171
|
+
HTMLElement.prototype.removeAttribute.call(host, name);
|
|
63
172
|
}
|
|
64
|
-
super.removeAttribute(qualifiedName);
|
|
65
173
|
}
|
|
66
174
|
get forwardedAriaLabel() {
|
|
67
175
|
const value = this.ariaLabel?.trim();
|
|
@@ -76,11 +184,7 @@ var SpectreBaseElement = class extends lit.LitElement {
|
|
|
76
184
|
return value ? value : void 0;
|
|
77
185
|
}
|
|
78
186
|
};
|
|
79
|
-
SpectreBaseElement.properties = {
|
|
80
|
-
ariaLabel: { attribute: "aria-label", type: String },
|
|
81
|
-
ariaLabelledBy: { attribute: "aria-labelledby", type: String },
|
|
82
|
-
ariaDescribedBy: { attribute: "aria-describedby", type: String }
|
|
83
|
-
};
|
|
187
|
+
SpectreBaseElement.properties = {};
|
|
84
188
|
|
|
85
189
|
// src/utils/dom.ts
|
|
86
190
|
function hasMeaningfulContent(nodes) {
|
|
@@ -141,9 +245,9 @@ var SpectreProjectableElement = class extends SpectreBaseElement {
|
|
|
141
245
|
}
|
|
142
246
|
this.contentObserver = new MutationObserver((mutations) => {
|
|
143
247
|
const isInternalMovement = mutations.every(
|
|
144
|
-
(mutation) =>
|
|
248
|
+
(mutation) => [...mutation.removedNodes].every(
|
|
145
249
|
(node) => this.isInternalNode(node) || this.contains(node)
|
|
146
|
-
) &&
|
|
250
|
+
) && [...mutation.addedNodes].every((node) => this.isInternalNode(node))
|
|
147
251
|
);
|
|
148
252
|
if (isInternalMovement) {
|
|
149
253
|
return;
|
|
@@ -162,10 +266,6 @@ var SpectreProjectableElement = class extends SpectreBaseElement {
|
|
|
162
266
|
|
|
163
267
|
// src/components/label/sp-label.ts
|
|
164
268
|
var SpectreLabelElement = class extends SpectreProjectableElement {
|
|
165
|
-
constructor() {
|
|
166
|
-
super(...arguments);
|
|
167
|
-
this.title = "";
|
|
168
|
-
}
|
|
169
269
|
getContentContainer() {
|
|
170
270
|
return this.querySelector("[data-sp-label-native]");
|
|
171
271
|
}
|
|
@@ -183,26 +283,22 @@ var SpectreLabelElement = class extends SpectreProjectableElement {
|
|
|
183
283
|
this.getContentContainer()?.blur();
|
|
184
284
|
}
|
|
185
285
|
render() {
|
|
186
|
-
return lit.html
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
${this.hasProjectedContent ? this.projectedContent : lit.nothing}
|
|
199
|
-
</label>
|
|
200
|
-
`;
|
|
286
|
+
return lit.html`<label
|
|
287
|
+
aria-describedby="${ifDefined_js.ifDefined(this.forwardedAriaDescribedBy)}"
|
|
288
|
+
aria-label="${ifDefined_js.ifDefined(this.forwardedAriaLabel)}"
|
|
289
|
+
aria-labelledby="${ifDefined_js.ifDefined(this.forwardedAriaLabelledBy)}"
|
|
290
|
+
class="sp-label"
|
|
291
|
+
data-sp-label-native
|
|
292
|
+
for="${ifDefined_js.ifDefined(this.htmlFor || void 0)}"
|
|
293
|
+
id="${ifDefined_js.ifDefined(this.id || void 0)}"
|
|
294
|
+
title="${ifDefined_js.ifDefined(this.title || void 0)}"
|
|
295
|
+
>
|
|
296
|
+
${this.hasProjectedContent ? this.projectedContent : lit.nothing}
|
|
297
|
+
</label>`;
|
|
201
298
|
}
|
|
202
299
|
};
|
|
203
300
|
SpectreLabelElement.properties = {
|
|
204
|
-
htmlFor: { attribute: "for", type: String, reflect: true }
|
|
205
|
-
title: { type: String, reflect: true }
|
|
301
|
+
htmlFor: { attribute: "for", type: String, reflect: true }
|
|
206
302
|
};
|
|
207
303
|
function defineSpectreLabel(tagName = "sp-label") {
|
|
208
304
|
const existingElement = customElements.get(tagName);
|
package/dist/label.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/base.ts","../src/utils/dom.ts","../src/utils/projectable.ts","../src/components/label/sp-label.ts"],"names":["LitElement","html","ifDefined","nothing"],"mappings":";;;;;;AAEO,IAAM,kBAAA,GAAN,cAAiCA,cAAA,CAAW;AAAA,EAA5C,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAOL,IAAA,IAAA,CAAA,SAAA,GAA2B,IAAA;AAC3B,IAAA,IAAA,CAAA,cAAA,GAAgC,IAAA;AAChC,IAAA,IAAA,CAAA,eAAA,GAAiC,IAAA;AAAA,EAAA;AAAA,EAIjC,IAAa,EAAA,GAAa;AACxB,IAAA,OAAO,KAAK,GAAA,IAAO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CAAU,IAAA,CAAK,EAAA,IAAM,MAAS,CAAC;AAAA;AAAA,cAAA,EAE5BA,sBAAA,CAAU,IAAA,CAAK,KAAA,IAAS,MAAS,CAAC;AAAA;AAAA,QAAA,EAExC,IAAA,CAAK,mBAAA,GAAsB,IAAA,CAAK,gBAAA,GAAmBC,WAAO;AAAA;AAAA,IAAA,CAAA;AAAA,EAGlE;AACF;AA/Ca,mBAAA,CACJ,UAAA,GAAa;AAAA,EAClB,SAAS,EAAE,SAAA,EAAW,OAAO,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA,EAAK;AAAA,EACzD,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA;AAClC,CAAA;AA6CK,SAAS,kBAAA,CAAmB,UAAU,UAAA,EAAwC;AACnF,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,mBAAmB,CAAA;AAClD,EAAA,OAAO,mBAAA;AACT","file":"label.cjs","sourcesContent":["import { LitElement, type PropertyDeclarations } from 'lit';\n\nexport class SpectreBaseElement extends LitElement {\n static properties: PropertyDeclarations = {\n ariaLabel: { attribute: 'aria-label', type: String },\n ariaLabelledBy: { attribute: 'aria-labelledby', type: String },\n ariaDescribedBy: { attribute: 'aria-describedby', type: String },\n };\n\n ariaLabel: string | null = null;\n ariaLabelledBy: string | null = null;\n ariaDescribedBy: string | null = null;\n\n private _id?: string;\n\n override get id(): string {\n return this._id ?? '';\n }\n\n override set id(value: string) {\n if ((this._id ?? '') === value) {\n return;\n }\n\n this._id = value;\n\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, 'id')) {\n HTMLElement.prototype.removeAttribute.call(host, 'id');\n }\n\n this.requestUpdate();\n }\n\n // Spectre components intentionally render in light DOM so the global\n // `@phcdevworks/spectre-ui` styling contract can apply directly.\n createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n const hostId = super.getAttribute('id');\n if (hostId !== null) {\n this.id = hostId;\n }\n }\n\n override getAttribute(qualifiedName: string): string | null {\n if (qualifiedName === 'id') {\n return this.id || null;\n }\n\n return super.getAttribute(qualifiedName);\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n if (qualifiedName === 'id') {\n return this.id !== '';\n }\n\n return super.hasAttribute(qualifiedName);\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n if (qualifiedName === 'id') {\n this.id = value;\n return;\n }\n\n super.setAttribute(qualifiedName, value);\n }\n\n override removeAttribute(qualifiedName: string): void {\n if (qualifiedName === 'id') {\n this.id = '';\n return;\n }\n\n super.removeAttribute(qualifiedName);\n }\n\n protected get forwardedAriaLabel(): string | undefined {\n const value = this.ariaLabel?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaLabelledBy(): string | undefined {\n const value = this.ariaLabelledBy?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaDescribedBy(): string | undefined {\n const value = this.ariaDescribedBy?.trim();\n return value ? value : undefined;\n }\n}\n","export function hasMeaningfulContent(nodes: readonly Node[]): boolean {\n return nodes.some((node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n return true;\n }\n\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent?.trim().length ?? 0) > 0;\n }\n\n return false;\n });\n}\n","import { SpectreBaseElement } from './base';\nimport { hasMeaningfulContent } from './dom';\n\nexport abstract class SpectreProjectableElement extends SpectreBaseElement {\n protected projectedContent: Node[] = [];\n private contentObserver?: MutationObserver | undefined;\n\n // Return the native container whose existing children are also treated as\n // projected content sources (e.g. the rendered <button>, <select>, <label>).\n protected abstract getContentContainer(): Element | null;\n\n // Return true if the node was rendered by this component and should not be\n // treated as external projected content.\n protected abstract isInternalNode(node: Node): boolean;\n\n protected get hasProjectedContent(): boolean {\n return hasMeaningfulContent(this.projectedContent);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.syncProjectedContent();\n this.startContentObserver();\n }\n\n override disconnectedCallback(): void {\n this.stopContentObserver();\n super.disconnectedCallback();\n }\n\n protected override update(changedProperties: Map<PropertyKey, unknown>): void {\n this.stopContentObserver();\n super.update(changedProperties);\n this.startContentObserver();\n }\n\n protected syncProjectedContent(): boolean {\n const nextProjectedContent: Node[] = [];\n const sourceNodes = [\n ...this.childNodes,\n ...(this.getContentContainer()?.childNodes ?? []),\n ];\n\n sourceNodes.forEach((node) => {\n if (!this.isInternalNode(node) && !nextProjectedContent.includes(node)) {\n nextProjectedContent.push(node);\n }\n });\n\n const hasChanged =\n nextProjectedContent.length !== this.projectedContent.length ||\n nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);\n\n if (hasChanged) {\n this.projectedContent = nextProjectedContent;\n }\n\n return hasChanged;\n }\n\n private startContentObserver(): void {\n if (this.contentObserver) {\n return;\n }\n\n this.contentObserver = new MutationObserver((mutations) => {\n const isInternalMovement = mutations.every((mutation) =>\n Array.from(mutation.removedNodes).every(\n (node) => this.isInternalNode(node) || this.contains(node),\n ) &&\n Array.from(mutation.addedNodes).every((node) => this.isInternalNode(node)),\n );\n\n if (isInternalMovement) {\n return;\n }\n\n if (this.syncProjectedContent()) {\n this.requestUpdate();\n }\n });\n\n this.contentObserver.observe(this, { childList: true });\n }\n\n private stopContentObserver(): void {\n this.contentObserver?.disconnect();\n this.contentObserver = undefined;\n }\n}\n","import { html, nothing } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { SpectreProjectableElement } from '../../utils/projectable';\n\nexport interface SpectreLabelProps {\n ariaLabel?: string | null;\n ariaLabelledBy?: string | null;\n ariaDescribedBy?: string | null;\n htmlFor?: string;\n title?: string;\n}\n\nexport class SpectreLabelElement extends SpectreProjectableElement implements SpectreLabelProps {\n static properties = {\n htmlFor: { attribute: 'for', type: String, reflect: true },\n title: { type: String, reflect: true },\n };\n\n htmlFor?: string;\n override title = '';\n\n protected override getContentContainer(): Element | null {\n return this.querySelector('[data-sp-label-native]');\n }\n\n protected override isInternalNode(node: Node): boolean {\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return false;\n }\n\n const el = node as Element;\n return el.hasAttribute('data-sp-label-native');\n }\n\n override focus(options?: FocusOptions): void {\n (this.getContentContainer() as HTMLLabelElement | null)?.focus(options);\n }\n\n override blur(): void {\n (this.getContentContainer() as HTMLLabelElement | null)?.blur();\n }\n\n override render() {\n return html`\n <label\n aria-describedby=${ifDefined(this.forwardedAriaDescribedBy)}\n aria-label=${ifDefined(this.forwardedAriaLabel)}\n aria-labelledby=${ifDefined(this.forwardedAriaLabelledBy)}\n class='sp-label'\n data-sp-label-native\n for=${ifDefined(this.htmlFor)}\n id=${ifDefined(this.id || undefined)}\n tabindex='-1'\n title=${ifDefined(this.title || undefined)}\n >\n ${this.hasProjectedContent ? this.projectedContent : nothing}\n </label>\n `;\n }\n}\n\nexport function defineSpectreLabel(tagName = 'sp-label'): typeof SpectreLabelElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreLabelElement;\n }\n\n customElements.define(tagName, SpectreLabelElement);\n return SpectreLabelElement;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/base.ts","../src/utils/dom.ts","../src/utils/projectable.ts","../src/components/label/sp-label.ts"],"names":["LitElement","html","ifDefined","nothing"],"mappings":";;;;;;AAEO,IAAM,kBAAA,GAAN,cAAiCA,cAAA,CAAW;AAAA,EAA5C,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAGL,IAAA,IAAA,CAAQ,UAAA,GAA4B,IAAA;AACpC,IAAA,IAAA,CAAQ,eAAA,GAAiC,IAAA;AACzC,IAAA,IAAA,CAAQ,gBAAA,GAAkC,IAAA;AAC1C,IAAA,IAAA,CAAQ,MAAA,GAAS,EAAA;AACjB,IAAA,IAAA,CAAQ,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uB,CAAC,CAAA;AAAA;AAAA;AAAA,WAAA,EAGnDA,sBAAA,CAAU,IAAA,CAAK,OAAA,IAAW,MAAS,CAAC,CAAA;AAAA,UAAA,EACrCA,sBAAA,CAAU,IAAA,CAAK,EAAA,IAAM,MAAS,CAAC,CAAA;AAAA,aAAA,EAC5BA,sBAAA,CAAU,IAAA,CAAK,KAAA,IAAS,MAAS,CAAC,CAAA;AAAA;AAAA,MAAA,EAEzC,IAAA,CAAK,mBAAA,GAAsB,IAAA,CAAK,gBAAA,GAAmBC,WAAO;AAAA,YAAA,CAAA;AAAA,EAEhE;AACF;AA1Ca,mBAAA,CACJ,UAAA,GAAa;AAAA,EAClB,SAAS,EAAE,SAAA,EAAW,OAAO,IAAA,EAAM,MAAA,EAAQ,SAAS,IAAA;AACtD,CAAA;AAyCK,SAAS,kBAAA,CAAmB,UAAU,UAAA,EAAwC;AACnF,EAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA;AAElD,EAAA,IAAI,eAAA,EAAiB;AACnB,IAAA,OAAO,eAAA;AAAA,EACT;AAEA,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,mBAAmB,CAAA;AAClD,EAAA,OAAO,mBAAA;AACT","file":"label.cjs","sourcesContent":["import { LitElement, type PropertyDeclarations } from 'lit';\n\nexport class SpectreBaseElement extends LitElement {\n static properties: PropertyDeclarations = {};\n\n private _ariaLabel: string | null = null;\n private _ariaLabelledBy: string | null = null;\n private _ariaDescribedBy: string | null = null;\n private _title = '';\n private _id = '';\n\n get ariaLabel(): string | null {\n return this._ariaLabel;\n }\n\n set ariaLabel(value: string | null) {\n if (this._ariaLabel === value) {\n return;\n }\n this._ariaLabel = value;\n this._removeHostAttribute('aria-label');\n this.requestUpdate();\n }\n\n get ariaLabelledBy(): string | null {\n return this._ariaLabelledBy;\n }\n\n set ariaLabelledBy(value: string | null) {\n if (this._ariaLabelledBy === value) {\n return;\n }\n this._ariaLabelledBy = value;\n this._removeHostAttribute('aria-labelledby');\n this.requestUpdate();\n }\n\n get ariaDescribedBy(): string | null {\n return this._ariaDescribedBy;\n }\n\n set ariaDescribedBy(value: string | null) {\n if (this._ariaDescribedBy === value) {\n return;\n }\n this._ariaDescribedBy = value;\n this._removeHostAttribute('aria-describedby');\n this.requestUpdate();\n }\n\n override get title(): string {\n return this._title;\n }\n\n override set title(value: string | undefined | null) {\n const normalizedValue = value ?? '';\n if (this._title === normalizedValue) {\n return;\n }\n this._title = normalizedValue;\n this._removeHostAttribute('title');\n this.requestUpdate();\n }\n\n override get id(): string {\n return this._id;\n }\n\n override set id(value: string | undefined | null) {\n const normalizedValue = value ?? '';\n if (this._id === normalizedValue) {\n return;\n }\n this._id = normalizedValue;\n this._removeHostAttribute('id');\n this.requestUpdate();\n }\n\n // Spectre components intentionally render in light DOM so the global\n // `@phcdevworks/spectre-ui` styling contract can apply directly.\n createRenderRoot(): this {\n return this;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n\n const proxiedAttributes = [\n 'id',\n 'title',\n 'aria-label',\n 'aria-labelledby',\n 'aria-describedby',\n ];\n\n proxiedAttributes.forEach((attr) => {\n const value = super.getAttribute(attr);\n if (value !== null) {\n this.setAttribute(attr, value);\n }\n });\n }\n\n override getAttribute(qualifiedName: string): string | null {\n switch (qualifiedName) {\n case 'id':\n return this.id || null;\n case 'title':\n return this.title || null;\n case 'aria-label':\n return this.ariaLabel;\n case 'aria-labelledby':\n return this.ariaLabelledBy;\n case 'aria-describedby':\n return this.ariaDescribedBy;\n default:\n return super.getAttribute(qualifiedName);\n }\n }\n\n override hasAttribute(qualifiedName: string): boolean {\n switch (qualifiedName) {\n case 'id':\n return this.id !== '';\n case 'title':\n return this.title !== '';\n case 'aria-label':\n return this.ariaLabel !== null;\n case 'aria-labelledby':\n return this.ariaLabelledBy !== null;\n case 'aria-describedby':\n return this.ariaDescribedBy !== null;\n default:\n return super.hasAttribute(qualifiedName);\n }\n }\n\n override setAttribute(qualifiedName: string, value: string): void {\n switch (qualifiedName) {\n case 'id':\n this.id = value;\n break;\n case 'title':\n this.title = value;\n break;\n case 'aria-label':\n this.ariaLabel = value;\n break;\n case 'aria-labelledby':\n this.ariaLabelledBy = value;\n break;\n case 'aria-describedby':\n this.ariaDescribedBy = value;\n break;\n default:\n super.setAttribute(qualifiedName, value);\n }\n }\n\n override removeAttribute(qualifiedName: string): void {\n switch (qualifiedName) {\n case 'id':\n this.id = '';\n break;\n case 'title':\n this.title = '';\n break;\n case 'aria-label':\n this.ariaLabel = null;\n break;\n case 'aria-labelledby':\n this.ariaLabelledBy = null;\n break;\n case 'aria-describedby':\n this.ariaDescribedBy = null;\n break;\n default:\n super.removeAttribute(qualifiedName);\n }\n }\n\n private _removeHostAttribute(name: string): void {\n const host = this as unknown as HTMLElement;\n if (HTMLElement.prototype.hasAttribute.call(host, name)) {\n HTMLElement.prototype.removeAttribute.call(host, name);\n }\n }\n\n protected get forwardedAriaLabel(): string | undefined {\n const value = this.ariaLabel?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaLabelledBy(): string | undefined {\n const value = this.ariaLabelledBy?.trim();\n return value ? value : undefined;\n }\n\n protected get forwardedAriaDescribedBy(): string | undefined {\n const value = this.ariaDescribedBy?.trim();\n return value ? value : undefined;\n }\n}\n","export function hasMeaningfulContent(nodes: readonly Node[]): boolean {\n return nodes.some((node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n return true;\n }\n\n if (node.nodeType === Node.TEXT_NODE) {\n return (node.textContent?.trim().length ?? 0) > 0;\n }\n\n return false;\n });\n}\n","import { SpectreBaseElement } from './base';\nimport { hasMeaningfulContent } from './dom';\n\nexport abstract class SpectreProjectableElement extends SpectreBaseElement {\n protected projectedContent: Node[] = [];\n private contentObserver?: MutationObserver | undefined;\n\n // Return the native container whose existing children are also treated as\n // projected content sources (e.g. the rendered <button>, <select>, <label>).\n protected abstract getContentContainer(): Element | null;\n\n // Return true if the node was rendered by this component and should not be\n // treated as external projected content.\n protected abstract isInternalNode(node: Node): boolean;\n\n protected get hasProjectedContent(): boolean {\n return hasMeaningfulContent(this.projectedContent);\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.syncProjectedContent();\n this.startContentObserver();\n }\n\n override disconnectedCallback(): void {\n this.stopContentObserver();\n super.disconnectedCallback();\n }\n\n protected override update(changedProperties: Map<PropertyKey, unknown>): void {\n this.stopContentObserver();\n super.update(changedProperties);\n this.startContentObserver();\n }\n\n protected syncProjectedContent(): boolean {\n const nextProjectedContent: Node[] = [];\n const sourceNodes = [\n ...this.childNodes,\n ...(this.getContentContainer()?.childNodes ?? []),\n ];\n\n sourceNodes.forEach((node) => {\n if (!this.isInternalNode(node) && !nextProjectedContent.includes(node)) {\n nextProjectedContent.push(node);\n }\n });\n\n const hasChanged =\n nextProjectedContent.length !== this.projectedContent.length ||\n nextProjectedContent.some((node, index) => node !== this.projectedContent[index]);\n\n if (hasChanged) {\n this.projectedContent = nextProjectedContent;\n }\n\n return hasChanged;\n }\n\n private startContentObserver(): void {\n if (this.contentObserver) {\n return;\n }\n\n this.contentObserver = new MutationObserver((mutations) => {\n const isInternalMovement = mutations.every((mutation) =>\n [...mutation.removedNodes].every(\n (node) => this.isInternalNode(node) || this.contains(node),\n ) &&\n [...mutation.addedNodes].every((node) => this.isInternalNode(node)),\n );\n\n if (isInternalMovement) {\n return;\n }\n\n if (this.syncProjectedContent()) {\n this.requestUpdate();\n }\n });\n\n this.contentObserver.observe(this, { childList: true });\n }\n\n private stopContentObserver(): void {\n this.contentObserver?.disconnect();\n this.contentObserver = undefined;\n }\n}\n","import { html, nothing } from 'lit';\nimport { ifDefined } from 'lit/directives/if-defined.js';\n\nimport { SpectreProjectableElement } from '../../utils/projectable';\n\nexport interface SpectreLabelProps {\n ariaLabel: string | null;\n ariaLabelledBy: string | null;\n ariaDescribedBy: string | null;\n htmlFor?: string | undefined;\n title?: string | undefined;\n}\n\nexport class SpectreLabelElement extends SpectreProjectableElement implements SpectreLabelProps {\n static properties = {\n htmlFor: { attribute: 'for', type: String, reflect: true },\n };\n\n htmlFor: string | undefined;\n\n protected override getContentContainer(): Element | null {\n return this.querySelector('[data-sp-label-native]');\n }\n\n protected override isInternalNode(node: Node): boolean {\n if (node.nodeType !== Node.ELEMENT_NODE) {\n return false;\n }\n\n const el = node as Element;\n return el.hasAttribute('data-sp-label-native');\n }\n\n override focus(options?: FocusOptions): void {\n (this.getContentContainer() as HTMLLabelElement | null)?.focus(options);\n }\n\n override blur(): void {\n (this.getContentContainer() as HTMLLabelElement | null)?.blur();\n }\n\n override render() {\n return html`<label\n aria-describedby=\"${ifDefined(this.forwardedAriaDescribedBy)}\"\n aria-label=\"${ifDefined(this.forwardedAriaLabel)}\"\n aria-labelledby=\"${ifDefined(this.forwardedAriaLabelledBy)}\"\n class=\"sp-label\"\n data-sp-label-native\n for=\"${ifDefined(this.htmlFor || undefined)}\"\n id=\"${ifDefined(this.id || undefined)}\"\n title=\"${ifDefined(this.title || undefined)}\"\n >\n ${this.hasProjectedContent ? this.projectedContent : nothing}\n </label>`;\n }\n}\n\nexport function defineSpectreLabel(tagName = 'sp-label'): typeof SpectreLabelElement {\n const existingElement = customElements.get(tagName);\n\n if (existingElement) {\n return existingElement as unknown as typeof SpectreLabelElement;\n }\n\n customElements.define(tagName, SpectreLabelElement);\n return SpectreLabelElement;\n}\n"]}
|
package/dist/label.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as lit_html from 'lit-html';
|
|
2
|
-
import { S as SpectreProjectableElement } from './projectable-
|
|
3
|
-
import './base-
|
|
2
|
+
import { S as SpectreProjectableElement } from './projectable-BzDQ4xp_.cjs';
|
|
3
|
+
import './base-2rD8EmdC.cjs';
|
|
4
4
|
import 'lit';
|
|
5
5
|
|
|
6
6
|
interface SpectreLabelProps {
|
|
7
|
-
ariaLabel
|
|
8
|
-
ariaLabelledBy
|
|
9
|
-
ariaDescribedBy
|
|
10
|
-
htmlFor?: string;
|
|
11
|
-
title?: string;
|
|
7
|
+
ariaLabel: string | null;
|
|
8
|
+
ariaLabelledBy: string | null;
|
|
9
|
+
ariaDescribedBy: string | null;
|
|
10
|
+
htmlFor?: string | undefined;
|
|
11
|
+
title?: string | undefined;
|
|
12
12
|
}
|
|
13
13
|
declare class SpectreLabelElement extends SpectreProjectableElement implements SpectreLabelProps {
|
|
14
14
|
static properties: {
|
|
@@ -17,13 +17,8 @@ declare class SpectreLabelElement extends SpectreProjectableElement implements S
|
|
|
17
17
|
type: StringConstructor;
|
|
18
18
|
reflect: boolean;
|
|
19
19
|
};
|
|
20
|
-
title: {
|
|
21
|
-
type: StringConstructor;
|
|
22
|
-
reflect: boolean;
|
|
23
|
-
};
|
|
24
20
|
};
|
|
25
|
-
htmlFor
|
|
26
|
-
title: string;
|
|
21
|
+
htmlFor: string | undefined;
|
|
27
22
|
protected getContentContainer(): Element | null;
|
|
28
23
|
protected isInternalNode(node: Node): boolean;
|
|
29
24
|
focus(options?: FocusOptions): void;
|
package/dist/label.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as lit_html from 'lit-html';
|
|
2
|
-
import { S as SpectreProjectableElement } from './projectable-
|
|
3
|
-
import './base-
|
|
2
|
+
import { S as SpectreProjectableElement } from './projectable-s3SgvjGX.js';
|
|
3
|
+
import './base-2rD8EmdC.js';
|
|
4
4
|
import 'lit';
|
|
5
5
|
|
|
6
6
|
interface SpectreLabelProps {
|
|
7
|
-
ariaLabel
|
|
8
|
-
ariaLabelledBy
|
|
9
|
-
ariaDescribedBy
|
|
10
|
-
htmlFor?: string;
|
|
11
|
-
title?: string;
|
|
7
|
+
ariaLabel: string | null;
|
|
8
|
+
ariaLabelledBy: string | null;
|
|
9
|
+
ariaDescribedBy: string | null;
|
|
10
|
+
htmlFor?: string | undefined;
|
|
11
|
+
title?: string | undefined;
|
|
12
12
|
}
|
|
13
13
|
declare class SpectreLabelElement extends SpectreProjectableElement implements SpectreLabelProps {
|
|
14
14
|
static properties: {
|
|
@@ -17,13 +17,8 @@ declare class SpectreLabelElement extends SpectreProjectableElement implements S
|
|
|
17
17
|
type: StringConstructor;
|
|
18
18
|
reflect: boolean;
|
|
19
19
|
};
|
|
20
|
-
title: {
|
|
21
|
-
type: StringConstructor;
|
|
22
|
-
reflect: boolean;
|
|
23
|
-
};
|
|
24
20
|
};
|
|
25
|
-
htmlFor
|
|
26
|
-
title: string;
|
|
21
|
+
htmlFor: string | undefined;
|
|
27
22
|
protected getContentContainer(): Element | null;
|
|
28
23
|
protected isInternalNode(node: Node): boolean;
|
|
29
24
|
focus(options?: FocusOptions): void;
|