@spectrum-web-components/shared 1.9.0 → 1.9.1-nightly.20251028214328
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/CHANGELOG.md +636 -0
- package/README.md +161 -42
- package/package.json +111 -111
- package/src/get-label-from-slot.d.ts +1 -1
- package/src/get-label-from-slot.dev.js +1 -15
- package/src/get-label-from-slot.dev.js.map +2 -2
- package/src/get-label-from-slot.js +1 -1
- package/src/get-label-from-slot.js.map +3 -3
- package/src/observe-slot-presence.d.ts +1 -12
- package/src/observe-slot-presence.dev.js +1 -61
- package/src/observe-slot-presence.dev.js.map +2 -2
- package/src/observe-slot-presence.js +1 -1
- package/src/observe-slot-presence.js.map +3 -3
- package/src/observe-slot-text.d.ts +1 -11
- package/src/observe-slot-text.dev.js +1 -93
- package/src/observe-slot-text.dev.js.map +2 -2
- package/src/observe-slot-text.js +1 -1
- package/src/observe-slot-text.js.map +3 -3
- package/test/focusable.test.js +23 -0
- package/test/focusable.test.js.map +7 -0
- package/test/observe-slot-presence.test.js +28 -0
- package/test/observe-slot-presence.test.js.map +7 -0
- package/test/observe-slot-text.test.js +25 -0
- package/test/observe-slot-text.test.js.map +7 -0
- package/test/random-id.test.js +25 -0
- package/test/random-id.test.js.map +7 -0
- package/test/reparent-children.test.js +254 -0
- package/test/reparent-children.test.js.map +7 -0
|
@@ -1,63 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
const slotContentIsPresent = Symbol("slotContentIsPresent");
|
|
4
|
-
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
5
|
-
var _a, _b;
|
|
6
|
-
const lightDomSelectors = Array.isArray(lightDomSelector) ? lightDomSelector : [lightDomSelector];
|
|
7
|
-
class SlotPresenceObservingElement extends (_b = constructor, _a = slotContentIsPresent, _b) {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
constructor(...args) {
|
|
10
|
-
super(args);
|
|
11
|
-
this[_a] = /* @__PURE__ */ new Map();
|
|
12
|
-
this.managePresenceObservedSlot = () => {
|
|
13
|
-
let changes = false;
|
|
14
|
-
lightDomSelectors.forEach((selector) => {
|
|
15
|
-
const nextValue = !!this.querySelector(`:scope > ${selector}`);
|
|
16
|
-
const previousValue = this[slotContentIsPresent].get(selector) || false;
|
|
17
|
-
changes = changes || previousValue !== nextValue;
|
|
18
|
-
this[slotContentIsPresent].set(
|
|
19
|
-
selector,
|
|
20
|
-
!!this.querySelector(`:scope > ${selector}`)
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
if (changes) {
|
|
24
|
-
this.updateComplete.then(() => {
|
|
25
|
-
this.requestUpdate();
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
new MutationController(this, {
|
|
30
|
-
config: {
|
|
31
|
-
childList: true,
|
|
32
|
-
subtree: true
|
|
33
|
-
},
|
|
34
|
-
callback: () => {
|
|
35
|
-
this.managePresenceObservedSlot();
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
this.managePresenceObservedSlot();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* @private
|
|
42
|
-
*/
|
|
43
|
-
get slotContentIsPresent() {
|
|
44
|
-
if (lightDomSelectors.length === 1) {
|
|
45
|
-
return this[slotContentIsPresent].get(lightDomSelectors[0]) || false;
|
|
46
|
-
} else {
|
|
47
|
-
throw new Error(
|
|
48
|
-
"Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead."
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
getSlotContentPresence(selector) {
|
|
53
|
-
if (this[slotContentIsPresent].has(selector)) {
|
|
54
|
-
return this[slotContentIsPresent].get(selector) || false;
|
|
55
|
-
}
|
|
56
|
-
throw new Error(
|
|
57
|
-
`The provided selector \`${selector}\` is not being observed.`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return SlotPresenceObservingElement;
|
|
62
|
-
}
|
|
2
|
+
export * from "@spectrum-web-components/core/shared/observe-slot-presence.js";
|
|
63
3
|
//# sourceMappingURL=observe-slot-presence.dev.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport * from '@spectrum-web-components/core/shared/observe-slot-presence.js';\n"],
|
|
5
|
+
"mappings": ";AAWA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";export*from"@spectrum-web-components/core/shared/observe-slot-presence.js";
|
|
2
2
|
//# sourceMappingURL=observe-slot-presence.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport * from '@spectrum-web-components/core/shared/observe-slot-presence.js';\n"],
|
|
5
|
+
"mappings": "aAWA,WAAc",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -9,14 +9,4 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
type Constructor<T = Record<string, unknown>> = {
|
|
14
|
-
new (...args: any[]): T;
|
|
15
|
-
prototype: T;
|
|
16
|
-
};
|
|
17
|
-
export interface SlotTextObservingInterface {
|
|
18
|
-
slotHasContent: boolean;
|
|
19
|
-
manageTextObservedSlot(): void;
|
|
20
|
-
}
|
|
21
|
-
export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T, slotName?: string, excludedSelectors?: string[]): T & Constructor<SlotTextObservingInterface>;
|
|
22
|
-
export {};
|
|
12
|
+
export * from '@spectrum-web-components/core/shared/observe-slot-text.js';
|
|
@@ -1,95 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
-
property,
|
|
14
|
-
queryAssignedNodes
|
|
15
|
-
} from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
-
import { MutationController } from "@lit-labs/observers/mutation-controller.js";
|
|
17
|
-
const assignedNodesList = Symbol("assignedNodes");
|
|
18
|
-
export function ObserveSlotText(constructor, slotName, excludedSelectors = []) {
|
|
19
|
-
var _a, _b;
|
|
20
|
-
const notExcluded = (el) => (selector) => {
|
|
21
|
-
return el.matches(selector);
|
|
22
|
-
};
|
|
23
|
-
class SlotTextObservingElement extends (_b = constructor, _a = assignedNodesList, _b) {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
constructor(...args) {
|
|
26
|
-
super(args);
|
|
27
|
-
this.slotHasContent = false;
|
|
28
|
-
new MutationController(this, {
|
|
29
|
-
config: {
|
|
30
|
-
characterData: true,
|
|
31
|
-
subtree: true
|
|
32
|
-
},
|
|
33
|
-
callback: (mutationsList) => {
|
|
34
|
-
for (const mutation of mutationsList) {
|
|
35
|
-
if (mutation.type === "characterData") {
|
|
36
|
-
this.manageTextObservedSlot();
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
manageTextObservedSlot() {
|
|
44
|
-
if (!this[assignedNodesList]) return;
|
|
45
|
-
const assignedNodes = [...this[assignedNodesList]].filter(
|
|
46
|
-
(currentNode) => {
|
|
47
|
-
const node = currentNode;
|
|
48
|
-
if (node.tagName) {
|
|
49
|
-
return !excludedSelectors.some(notExcluded(node));
|
|
50
|
-
}
|
|
51
|
-
return node.textContent ? node.textContent.trim() : false;
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
this.slotHasContent = assignedNodes.length > 0;
|
|
55
|
-
}
|
|
56
|
-
update(changedProperties) {
|
|
57
|
-
if (!this.hasUpdated) {
|
|
58
|
-
const { childNodes } = this;
|
|
59
|
-
const textNodes = [...childNodes].filter((currentNode) => {
|
|
60
|
-
const node = currentNode;
|
|
61
|
-
if (node.tagName) {
|
|
62
|
-
const excluded = excludedSelectors.some(
|
|
63
|
-
notExcluded(node)
|
|
64
|
-
);
|
|
65
|
-
return !excluded ? (
|
|
66
|
-
// This pass happens at element upgrade and before slot rendering.
|
|
67
|
-
// Confirm it would exisit in a targeted slot if there was one supplied.
|
|
68
|
-
slotName ? node.getAttribute("slot") === slotName : !node.hasAttribute("slot")
|
|
69
|
-
) : false;
|
|
70
|
-
}
|
|
71
|
-
return node.textContent ? node.textContent.trim() : false;
|
|
72
|
-
});
|
|
73
|
-
this.slotHasContent = textNodes.length > 0;
|
|
74
|
-
}
|
|
75
|
-
super.update(changedProperties);
|
|
76
|
-
}
|
|
77
|
-
firstUpdated(changedProperties) {
|
|
78
|
-
super.firstUpdated(changedProperties);
|
|
79
|
-
this.updateComplete.then(() => {
|
|
80
|
-
this.manageTextObservedSlot();
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
__decorateClass([
|
|
85
|
-
property({ type: Boolean, attribute: false })
|
|
86
|
-
], SlotTextObservingElement.prototype, "slotHasContent", 2);
|
|
87
|
-
__decorateClass([
|
|
88
|
-
queryAssignedNodes({
|
|
89
|
-
slot: slotName,
|
|
90
|
-
flatten: true
|
|
91
|
-
})
|
|
92
|
-
], SlotTextObservingElement.prototype, _a, 2);
|
|
93
|
-
return SlotTextObservingElement;
|
|
94
|
-
}
|
|
2
|
+
export * from "@spectrum-web-components/core/shared/observe-slot-text.js";
|
|
95
3
|
//# sourceMappingURL=observe-slot-text.dev.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport * from '@spectrum-web-components/core/shared/observe-slot-text.js';\n"],
|
|
5
|
+
"mappings": ";AAWA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/observe-slot-text.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";export*from"@spectrum-web-components/core/shared/observe-slot-text.js";
|
|
2
2
|
//# sourceMappingURL=observe-slot-text.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport * from '@spectrum-web-components/core/shared/observe-slot-text.js';\n"],
|
|
5
|
+
"mappings": "aAWA,WAAc",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import "@spectrum-web-components/shared/src/focusable.js";
|
|
3
|
+
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
4
|
+
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
5
|
+
describe("Focusable", () => {
|
|
6
|
+
it("enforces the presense of a `focusElement`", async () => {
|
|
7
|
+
customElements.define("focusable-test", class extends Focusable {
|
|
8
|
+
});
|
|
9
|
+
try {
|
|
10
|
+
const el = await fixture(html`
|
|
11
|
+
<focusable-test></focusable-test>
|
|
12
|
+
`);
|
|
13
|
+
await elementUpdated(el);
|
|
14
|
+
const focusEl = el.focusElement;
|
|
15
|
+
expect(focusEl).to.exist;
|
|
16
|
+
} catch (error) {
|
|
17
|
+
expect(() => {
|
|
18
|
+
throw error;
|
|
19
|
+
}).to.throw("Must implement focusElement getter!");
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=focusable.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["focusable.test.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport '@spectrum-web-components/shared/src/focusable.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\ndescribe('Focusable', () => {\n it('enforces the presense of a `focusElement`', async () => {\n customElements.define('focusable-test', class extends Focusable {});\n try {\n const el = await fixture<Focusable>(html`\n <focusable-test></focusable-test>\n `);\n await elementUpdated(el);\n const focusEl = el.focusElement;\n expect(focusEl).to.exist;\n } catch (error) {\n expect(() => {\n throw error;\n }).to.throw('Must implement focusElement getter!');\n }\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,OAAO;AACP,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AAEtD,SAAS,aAAa,MAAM;AACxB,KAAG,6CAA6C,YAAY;AACxD,mBAAe,OAAO,kBAAkB,cAAc,UAAU;AAAA,IAAC,CAAC;AAClE,QAAI;AACA,YAAM,KAAK,MAAM,QAAmB;AAAA;AAAA,aAEnC;AACD,YAAM,eAAe,EAAE;AACvB,YAAM,UAAU,GAAG;AACnB,aAAO,OAAO,EAAE,GAAG;AAAA,IACvB,SAAS,OAAO;AACZ,aAAO,MAAM;AACT,cAAM;AAAA,MACV,CAAC,EAAE,GAAG,MAAM,qCAAqC;AAAA,IACrD;AAAA,EACJ,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { ObserveSlotPresence } from "@spectrum-web-components/shared/src/observe-slot-presence.js";
|
|
3
|
+
import { LitElement } from "@spectrum-web-components/base";
|
|
4
|
+
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
5
|
+
class ObserverTest extends ObserveSlotPresence(
|
|
6
|
+
LitElement,
|
|
7
|
+
'[slot="test-slot"]'
|
|
8
|
+
) {
|
|
9
|
+
render() {
|
|
10
|
+
return html`
|
|
11
|
+
Test Element
|
|
12
|
+
`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
customElements.define("observe-presence-test", ObserverTest);
|
|
16
|
+
describe("ObserveSlotPresence", () => {
|
|
17
|
+
it("does no management when slot unavailable", async () => {
|
|
18
|
+
const el = await fixture(html`
|
|
19
|
+
<observe-presence-test></observe-presence-test>
|
|
20
|
+
`);
|
|
21
|
+
await elementUpdated(el);
|
|
22
|
+
expect(el.slotContentIsPresent).to.be.false;
|
|
23
|
+
el.innerHTML = '<div slot="test-slot"></div>';
|
|
24
|
+
await elementUpdated(el);
|
|
25
|
+
expect(el.slotContentIsPresent).to.be.true;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=observe-slot-presence.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observe-slot-presence.test.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { ObserveSlotPresence } from '@spectrum-web-components/shared/src/observe-slot-presence.js';\nimport { LitElement, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\nclass ObserverTest extends ObserveSlotPresence(\n LitElement,\n '[slot=\"test-slot\"]'\n) {\n protected override render(): TemplateResult {\n return html`\n Test Element\n `;\n }\n}\n\ncustomElements.define('observe-presence-test', ObserverTest);\n\ndescribe('ObserveSlotPresence', () => {\n it('does no management when slot unavailable', async () => {\n const el = await fixture<ObserverTest>(html`\n <observe-presence-test></observe-presence-test>\n `);\n await elementUpdated(el);\n\n expect(el.slotContentIsPresent).to.be.false;\n\n el.innerHTML = '<div slot=\"test-slot\"></div>';\n await elementUpdated(el);\n\n expect(el.slotContentIsPresent).to.be.true;\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,2BAA2B;AACpC,SAAS,kBAAkC;AAC3C,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AAEtD,MAAM,qBAAqB;AAAA,EACvB;AAAA,EACA;AACJ,EAAE;AAAA,EACqB,SAAyB;AACxC,WAAO;AAAA;AAAA;AAAA,EAGX;AACJ;AAEA,eAAe,OAAO,yBAAyB,YAAY;AAE3D,SAAS,uBAAuB,MAAM;AAClC,KAAG,4CAA4C,YAAY;AACvD,UAAM,KAAK,MAAM,QAAsB;AAAA;AAAA,SAEtC;AACD,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,oBAAoB,EAAE,GAAG,GAAG;AAEtC,OAAG,YAAY;AACf,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,oBAAoB,EAAE,GAAG,GAAG;AAAA,EAC1C,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { ObserveSlotText } from "@spectrum-web-components/shared/src/observe-slot-text.js";
|
|
3
|
+
import { LitElement } from "@spectrum-web-components/base";
|
|
4
|
+
import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
|
|
5
|
+
class ObserverTest extends ObserveSlotText(LitElement) {
|
|
6
|
+
render() {
|
|
7
|
+
return html`
|
|
8
|
+
<slot @slotchange=${this.manageTextObservedSlot}></slot>
|
|
9
|
+
`;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
customElements.define("observe-slot-test", ObserverTest);
|
|
13
|
+
describe("ObserveSlotText", () => {
|
|
14
|
+
it("does no management when slot unavailable", async () => {
|
|
15
|
+
const el = await fixture(html`
|
|
16
|
+
<observe-slot-test></observe-slot-test>
|
|
17
|
+
`);
|
|
18
|
+
await elementUpdated(el);
|
|
19
|
+
expect(el.slotHasContent).to.be.false;
|
|
20
|
+
el.textContent = `hi, i'm some text`;
|
|
21
|
+
await elementUpdated(el);
|
|
22
|
+
expect(el.slotHasContent).to.be.true;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=observe-slot-text.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observe-slot-text.test.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { ObserveSlotText } from '@spectrum-web-components/shared/src/observe-slot-text.js';\nimport { LitElement, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\nclass ObserverTest extends ObserveSlotText(LitElement) {\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.manageTextObservedSlot}></slot>\n `;\n }\n}\n\ncustomElements.define('observe-slot-test', ObserverTest);\n\ndescribe('ObserveSlotText', () => {\n it('does no management when slot unavailable', async () => {\n const el = await fixture<ObserverTest>(html`\n <observe-slot-test></observe-slot-test>\n `);\n await elementUpdated(el);\n\n expect(el.slotHasContent).to.be.false;\n\n el.textContent = `hi, i'm some text`;\n\n await elementUpdated(el);\n\n expect(el.slotHasContent).to.be.true;\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,uBAAuB;AAChC,SAAS,kBAAkC;AAC3C,SAAS,gBAAgB,QAAQ,SAAS,YAAY;AAEtD,MAAM,qBAAqB,gBAAgB,UAAU,EAAE;AAAA,EAChC,SAAyB;AACxC,WAAO;AAAA,gCACiB,KAAK,sBAAsB;AAAA;AAAA,EAEvD;AACJ;AAEA,eAAe,OAAO,qBAAqB,YAAY;AAEvD,SAAS,mBAAmB,MAAM;AAC9B,KAAG,4CAA4C,YAAY;AACvD,UAAM,KAAK,MAAM,QAAsB;AAAA;AAAA,SAEtC;AACD,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,cAAc,EAAE,GAAG,GAAG;AAEhC,OAAG,cAAc;AAEjB,UAAM,eAAe,EAAE;AAEvB,WAAO,GAAG,cAAc,EAAE,GAAG,GAAG;AAAA,EACpC,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { randomID } from "@spectrum-web-components/shared/src/random-id.js";
|
|
3
|
+
import { expect } from "@open-wc/testing";
|
|
4
|
+
describe("randomID()", () => {
|
|
5
|
+
it("creates unique strings of 8 hex characters", () => {
|
|
6
|
+
const n = 1e3;
|
|
7
|
+
const ids = Array.from({ length: n }, randomID);
|
|
8
|
+
const shape = ids.filter((id) => {
|
|
9
|
+
return typeof id === "string" && id.length === 8 && id.split("").every((char) => "0123456789abcdef".includes(char));
|
|
10
|
+
});
|
|
11
|
+
const unique = new Set(ids);
|
|
12
|
+
expect(shape).to.have.length(n);
|
|
13
|
+
expect(unique).to.have.length(n);
|
|
14
|
+
});
|
|
15
|
+
it("generates 100k IDs in less than a second", () => {
|
|
16
|
+
const n = 1e5;
|
|
17
|
+
const sec = 1e3;
|
|
18
|
+
const start = performance.now();
|
|
19
|
+
const ids = Array.from({ length: n }, randomID);
|
|
20
|
+
const time = performance.now() - start;
|
|
21
|
+
expect(ids).to.have.length(n);
|
|
22
|
+
expect(time).to.be.lessThan(sec);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=random-id.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["random-id.test.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\nimport { expect } from '@open-wc/testing';\n\ndescribe('randomID()', () => {\n it('creates unique strings of 8 hex characters', () => {\n const n = 1000;\n const ids = Array.from({ length: n }, randomID);\n const shape = ids.filter((id) => {\n return (\n typeof id === 'string' &&\n id.length === 8 &&\n id.split('').every((char) => '0123456789abcdef'.includes(char))\n );\n });\n const unique = new Set(ids);\n\n expect(shape).to.have.length(n);\n expect(unique).to.have.length(n);\n });\n it('generates 100k IDs in less than a second', () => {\n const n = 100000;\n const sec = 1000;\n const start = performance.now();\n const ids = Array.from({ length: n }, randomID);\n const time = performance.now() - start;\n\n expect(ids).to.have.length(n);\n expect(time).to.be.lessThan(sec);\n });\n});\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAEvB,SAAS,cAAc,MAAM;AACzB,KAAG,8CAA8C,MAAM;AACnD,UAAM,IAAI;AACV,UAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ;AAC9C,UAAM,QAAQ,IAAI,OAAO,CAAC,OAAO;AAC7B,aACI,OAAO,OAAO,YACd,GAAG,WAAW,KACd,GAAG,MAAM,EAAE,EAAE,MAAM,CAAC,SAAS,mBAAmB,SAAS,IAAI,CAAC;AAAA,IAEtE,CAAC;AACD,UAAM,SAAS,IAAI,IAAI,GAAG;AAE1B,WAAO,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC;AAC9B,WAAO,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC;AAAA,EACnC,CAAC;AACD,KAAG,4CAA4C,MAAM;AACjD,UAAM,IAAI;AACV,UAAM,MAAM;AACZ,UAAM,QAAQ,YAAY,IAAI;AAC9B,UAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ;AAC9C,UAAM,OAAO,YAAY,IAAI,IAAI;AAEjC,WAAO,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC;AAC5B,WAAO,IAAI,EAAE,GAAG,GAAG,SAAS,GAAG;AAAA,EACnC,CAAC;AACL,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|