@spectrum-web-components/shared 0.14.2 → 0.14.5-devmode.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 +4 -0
- package/package.json +53 -6
- package/src/first-focusable-in.dev.js +6 -0
- package/src/first-focusable-in.dev.js.map +7 -0
- package/src/first-focusable-in.js +3 -14
- package/src/first-focusable-in.js.map +7 -1
- package/src/focus-visible.dev.js +68 -0
- package/src/focus-visible.dev.js.map +7 -0
- package/src/focus-visible.js +59 -105
- package/src/focus-visible.js.map +7 -1
- package/src/focusable.dev.js +190 -0
- package/src/focusable.dev.js.map +7 -0
- package/src/focusable.js +185 -244
- package/src/focusable.js.map +7 -1
- package/src/get-active-element.dev.js +4 -0
- package/src/get-active-element.dev.js.map +7 -0
- package/src/get-active-element.js +2 -14
- package/src/get-active-element.js.map +7 -1
- package/src/get-deep-element-from-point.d.ts +1 -0
- package/src/get-deep-element-from-point.dev.js +12 -0
- package/src/get-deep-element-from-point.dev.js.map +7 -0
- package/src/get-deep-element-from-point.js +12 -0
- package/src/get-deep-element-from-point.js.map +7 -0
- package/src/index.dev.js +10 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +10 -21
- package/src/index.js.map +7 -1
- package/src/like-anchor.dev.js +58 -0
- package/src/like-anchor.dev.js.map +7 -0
- package/src/like-anchor.js +45 -40
- package/src/like-anchor.js.map +7 -1
- package/src/observe-slot-presence.dev.js +52 -0
- package/src/observe-slot-presence.dev.js.map +7 -0
- package/src/observe-slot-presence.js +47 -52
- package/src/observe-slot-presence.js.map +7 -1
- package/src/observe-slot-text.d.ts +1 -1
- package/src/observe-slot-text.dev.js +79 -0
- package/src/observe-slot-text.dev.js.map +7 -0
- package/src/observe-slot-text.js +74 -57
- package/src/observe-slot-text.js.map +7 -1
- package/src/platform.dev.js +31 -0
- package/src/platform.dev.js.map +7 -0
- package/src/platform.js +11 -32
- package/src/platform.js.map +7 -1
- package/src/reparent-children.dev.js +50 -0
- package/src/reparent-children.dev.js.map +7 -0
- package/src/reparent-children.js +44 -52
- package/src/reparent-children.js.map +7 -1
- package/test/focusable.test.js +19 -31
- package/test/focusable.test.js.map +7 -1
- package/test/observe-slot-presence.test.js +17 -27
- package/test/observe-slot-presence.test.js.map +7 -1
- package/test/observe-slot-text.test.js +17 -28
- package/test/observe-slot-text.test.js.map +7 -1
- package/test/reparent-children.test.js +151 -162
- package/test/reparent-children.test.js.map +7 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["get-deep-element-from-point.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2022 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\nexport const getDeepElementFromPoint = (\n x: number,\n y: number\n): Element | null => {\n let target = document.elementFromPoint(x, y);\n while (target?.shadowRoot) {\n const innerTarget = (\n target.shadowRoot as unknown as {\n elementFromPoint: (x: number, y: number) => Element | null;\n }\n ).elementFromPoint(x, y);\n if (!innerTarget || innerTarget === target) {\n break;\n }\n target = innerTarget;\n }\n return target;\n};\n"],
|
|
5
|
+
"mappings": "AAYO,aAAM,0BAA0B,CACnC,GACA,MACiB;AACjB,MAAI,SAAS,SAAS,iBAAiB,GAAG,CAAC;AAC3C,SAAO,iCAAQ,YAAY;AACvB,UAAM,cACF,OAAO,WAGT,iBAAiB,GAAG,CAAC;AACvB,QAAI,CAAC,eAAe,gBAAgB,QAAQ;AACxC;AAAA,IACJ;AACA,aAAS;AAAA,EACb;AACA,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/index.dev.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./first-focusable-in.dev.js";
|
|
2
|
+
export * from "./focus-visible.dev.js";
|
|
3
|
+
export * from "./focusable.dev.js";
|
|
4
|
+
export * from "./get-active-element.dev.js";
|
|
5
|
+
export * from "./like-anchor.dev.js";
|
|
6
|
+
export * from "./observe-slot-presence.dev.js";
|
|
7
|
+
export * from "./observe-slot-text.dev.js";
|
|
8
|
+
export * from "./platform.dev.js";
|
|
9
|
+
export * from "./reparent-children.dev.js";
|
|
10
|
+
//# sourceMappingURL=index.dev.js.map
|
|
@@ -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\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\nexport * from './first-focusable-in.dev.js'\nexport * from './focus-visible.dev.js'\nexport * from './focusable.dev.js'\nexport * from './get-active-element.dev.js'\nexport * from './like-anchor.dev.js'\nexport * from './observe-slot-presence.dev.js'\nexport * from './observe-slot-text.dev.js'\nexport * from './platform.dev.js'\nexport * from './reparent-children.dev.js'\n"],
|
|
5
|
+
"mappings": "AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
export * from './first-focusable-in.js';
|
|
13
|
-
export * from './focus-visible.js';
|
|
14
|
-
export * from './focusable.js';
|
|
15
|
-
export * from './get-active-element.js';
|
|
16
|
-
export * from './like-anchor.js';
|
|
17
|
-
export * from './observe-slot-presence.js';
|
|
18
|
-
export * from './observe-slot-text.js';
|
|
19
|
-
export * from './platform.js';
|
|
20
|
-
export * from './reparent-children.js';
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./first-focusable-in.js";
|
|
2
|
+
export * from "./focus-visible.js";
|
|
3
|
+
export * from "./focusable.js";
|
|
4
|
+
export * from "./get-active-element.js";
|
|
5
|
+
export * from "./like-anchor.js";
|
|
6
|
+
export * from "./observe-slot-presence.js";
|
|
7
|
+
export * from "./observe-slot-text.js";
|
|
8
|
+
export * from "./platform.js";
|
|
9
|
+
export * from "./reparent-children.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
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\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\nexport * from './first-focusable-in.js';\nexport * from './focus-visible.js';\nexport * from './focusable.js';\nexport * from './get-active-element.js';\nexport * from './like-anchor.js';\nexport * from './observe-slot-presence.js';\nexport * from './observe-slot-text.js';\nexport * from './platform.js';\nexport * from './reparent-children.js';\n"],
|
|
5
|
+
"mappings": "AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html
|
|
14
|
+
} from "@spectrum-web-components/base";
|
|
15
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
+
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
|
17
|
+
export function LikeAnchor(constructor) {
|
|
18
|
+
class LikeAnchorElement extends constructor {
|
|
19
|
+
renderAnchor({
|
|
20
|
+
id,
|
|
21
|
+
className,
|
|
22
|
+
ariaHidden,
|
|
23
|
+
labelledby,
|
|
24
|
+
tabindex,
|
|
25
|
+
anchorContent = html`<slot></slot>`
|
|
26
|
+
}) {
|
|
27
|
+
return html`<a
|
|
28
|
+
id=${id}
|
|
29
|
+
class=${ifDefined(className)}
|
|
30
|
+
href=${ifDefined(this.href)}
|
|
31
|
+
download=${ifDefined(this.download)}
|
|
32
|
+
target=${ifDefined(this.target)}
|
|
33
|
+
aria-label=${ifDefined(this.label)}
|
|
34
|
+
aria-labelledby=${ifDefined(labelledby)}
|
|
35
|
+
aria-hidden=${ifDefined(ariaHidden ? "true" : void 0)}
|
|
36
|
+
tabindex=${ifDefined(tabindex)}
|
|
37
|
+
rel=${ifDefined(this.rel)}
|
|
38
|
+
>${anchorContent}</a>`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
__decorateClass([
|
|
42
|
+
property({ reflect: true })
|
|
43
|
+
], LikeAnchorElement.prototype, "download", 2);
|
|
44
|
+
__decorateClass([
|
|
45
|
+
property()
|
|
46
|
+
], LikeAnchorElement.prototype, "label", 2);
|
|
47
|
+
__decorateClass([
|
|
48
|
+
property({ reflect: true })
|
|
49
|
+
], LikeAnchorElement.prototype, "href", 2);
|
|
50
|
+
__decorateClass([
|
|
51
|
+
property({ reflect: true })
|
|
52
|
+
], LikeAnchorElement.prototype, "target", 2);
|
|
53
|
+
__decorateClass([
|
|
54
|
+
property({ reflect: true })
|
|
55
|
+
], LikeAnchorElement.prototype, "rel", 2);
|
|
56
|
+
return LikeAnchorElement;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=like-anchor.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["like-anchor.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 {\n html,\n ReactiveElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ntype RenderAnchorOptions = {\n id: string;\n className?: string;\n ariaHidden?: boolean;\n anchorContent?: TemplateResult | TemplateResult[];\n labelledby?: string;\n tabindex?: -1 | 0;\n};\n\nexport interface LikeAnchorInterface {\n download?: string;\n label?: string;\n href?: string;\n rel?: string;\n target?: '_blank' | '_parent' | '_self' | '_top';\n renderAnchor(options: RenderAnchorOptions): TemplateResult;\n}\n\nexport function LikeAnchor<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<LikeAnchorInterface> {\n class LikeAnchorElement extends constructor {\n @property({ reflect: true })\n public download?: string;\n\n @property()\n public label?: string;\n\n @property({ reflect: true })\n public href?: string;\n\n @property({ reflect: true })\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n @property({ reflect: true })\n public rel?: string;\n\n public renderAnchor({\n id,\n className,\n ariaHidden,\n labelledby,\n tabindex,\n // prettier-ignore\n anchorContent = html`<slot></slot>`,\n }: RenderAnchorOptions): TemplateResult {\n // prettier-ignore\n return html\n `<a\n id=${id}\n class=${ifDefined(className)}\n href=${ifDefined(this.href)}\n download=${ifDefined(this.download)}\n target=${ifDefined(this.target)}\n aria-label=${ifDefined(this.label)}\n aria-labelledby=${ifDefined(labelledby)}\n aria-hidden=${ifDefined(ariaHidden ? 'true' : undefined)}\n tabindex=${ifDefined(tabindex)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAWA;AAAA;AAAA;AAKA;AACA;AA0BO,2BACH,aACoC;AACpC,QAAM,0BAA0B,YAAY;AAAA,IAgBjC,aAAa;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA,gBAAgB;AAAA,OACoB;AAEpC,aAAO;AAAA,yBAEM;AAAA,4BACG,UAAU,SAAS;AAAA,2BACpB,UAAU,KAAK,IAAI;AAAA,+BACf,UAAU,KAAK,QAAQ;AAAA,6BACzB,UAAU,KAAK,MAAM;AAAA,iCACjB,UAAU,KAAK,KAAK;AAAA,sCACf,UAAU,UAAU;AAAA,kCACxB,UAAU,aAAa,SAAS,MAAS;AAAA,+BAC5C,UAAU,QAAQ;AAAA,0BACvB,UAAU,KAAK,GAAG;AAAA,mBACzB;AAAA,IACX;AAAA,EACJ;AAtCW;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAFX,kBAEW;AAGA;AAAA,IADP,AAAC,SAAS;AAAA,KACH,AALX,kBAKW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AARX,kBAQW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAXX,kBAWW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAdX,kBAcW;AA2BX,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/src/like-anchor.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import {
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html
|
|
14
|
+
} from "@spectrum-web-components/base";
|
|
15
|
+
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
+
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
|
16
17
|
export function LikeAnchor(constructor) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
class LikeAnchorElement extends constructor {
|
|
19
|
+
renderAnchor({
|
|
20
|
+
id,
|
|
21
|
+
className,
|
|
22
|
+
ariaHidden,
|
|
23
|
+
labelledby,
|
|
24
|
+
tabindex,
|
|
25
|
+
anchorContent = html`<slot></slot>`
|
|
26
|
+
}) {
|
|
27
|
+
return html`<a
|
|
23
28
|
id=${id}
|
|
24
29
|
class=${ifDefined(className)}
|
|
25
30
|
href=${ifDefined(this.href)}
|
|
@@ -27,27 +32,27 @@ export function LikeAnchor(constructor) {
|
|
|
27
32
|
target=${ifDefined(this.target)}
|
|
28
33
|
aria-label=${ifDefined(this.label)}
|
|
29
34
|
aria-labelledby=${ifDefined(labelledby)}
|
|
30
|
-
aria-hidden=${ifDefined(ariaHidden ?
|
|
35
|
+
aria-hidden=${ifDefined(ariaHidden ? "true" : void 0)}
|
|
31
36
|
tabindex=${ifDefined(tabindex)}
|
|
32
37
|
rel=${ifDefined(this.rel)}
|
|
33
38
|
>${anchorContent}</a>`;
|
|
34
|
-
}
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
}
|
|
41
|
+
__decorateClass([
|
|
42
|
+
property({ reflect: true })
|
|
43
|
+
], LikeAnchorElement.prototype, "download", 2);
|
|
44
|
+
__decorateClass([
|
|
45
|
+
property()
|
|
46
|
+
], LikeAnchorElement.prototype, "label", 2);
|
|
47
|
+
__decorateClass([
|
|
48
|
+
property({ reflect: true })
|
|
49
|
+
], LikeAnchorElement.prototype, "href", 2);
|
|
50
|
+
__decorateClass([
|
|
51
|
+
property({ reflect: true })
|
|
52
|
+
], LikeAnchorElement.prototype, "target", 2);
|
|
53
|
+
__decorateClass([
|
|
54
|
+
property({ reflect: true })
|
|
55
|
+
], LikeAnchorElement.prototype, "rel", 2);
|
|
56
|
+
return LikeAnchorElement;
|
|
52
57
|
}
|
|
53
|
-
//# sourceMappingURL=like-anchor.js.map
|
|
58
|
+
//# sourceMappingURL=like-anchor.js.map
|
package/src/like-anchor.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["like-anchor.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 {\n html,\n ReactiveElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ntype RenderAnchorOptions = {\n id: string;\n className?: string;\n ariaHidden?: boolean;\n anchorContent?: TemplateResult | TemplateResult[];\n labelledby?: string;\n tabindex?: -1 | 0;\n};\n\nexport interface LikeAnchorInterface {\n download?: string;\n label?: string;\n href?: string;\n rel?: string;\n target?: '_blank' | '_parent' | '_self' | '_top';\n renderAnchor(options: RenderAnchorOptions): TemplateResult;\n}\n\nexport function LikeAnchor<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<LikeAnchorInterface> {\n class LikeAnchorElement extends constructor {\n @property({ reflect: true })\n public download?: string;\n\n @property()\n public label?: string;\n\n @property({ reflect: true })\n public href?: string;\n\n @property({ reflect: true })\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n @property({ reflect: true })\n public rel?: string;\n\n public renderAnchor({\n id,\n className,\n ariaHidden,\n labelledby,\n tabindex,\n // prettier-ignore\n anchorContent = html`<slot></slot>`,\n }: RenderAnchorOptions): TemplateResult {\n // prettier-ignore\n return html\n `<a\n id=${id}\n class=${ifDefined(className)}\n href=${ifDefined(this.href)}\n download=${ifDefined(this.download)}\n target=${ifDefined(this.target)}\n aria-label=${ifDefined(this.label)}\n aria-labelledby=${ifDefined(labelledby)}\n aria-hidden=${ifDefined(ariaHidden ? 'true' : undefined)}\n tabindex=${ifDefined(tabindex)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAWA;AAAA;AAAA;AAKA;AACA;AA0BO,2BACH,aACoC;AACpC,QAAM,0BAA0B,YAAY;AAAA,IAgBjC,aAAa;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA,gBAAgB;AAAA,OACoB;AAEpC,aAAO;AAAA,yBAEM;AAAA,4BACG,UAAU,SAAS;AAAA,2BACpB,UAAU,KAAK,IAAI;AAAA,+BACf,UAAU,KAAK,QAAQ;AAAA,6BACzB,UAAU,KAAK,MAAM;AAAA,iCACjB,UAAU,KAAK,KAAK;AAAA,sCACf,UAAU,UAAU;AAAA,kCACxB,UAAU,aAAa,SAAS,MAAS;AAAA,+BAC5C,UAAU,QAAQ;AAAA,0BACvB,UAAU,KAAK,GAAG;AAAA,mBACzB;AAAA,IACX;AAAA,EACJ;AAtCW;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAFX,kBAEW;AAGA;AAAA,IADP,AAAC,SAAS;AAAA,KACH,AALX,kBAKW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AARX,kBAQW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAXX,kBAWW;AAGA;AAAA,IADP,AAAC,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KACpB,AAdX,kBAcW;AA2BX,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
2
|
+
const slotContentIsPresent = Symbol("slotContentIsPresent");
|
|
3
|
+
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
4
|
+
var _a;
|
|
5
|
+
const lightDomSelectors = Array.isArray(lightDomSelector) ? lightDomSelector : [lightDomSelector];
|
|
6
|
+
class SlotPresenceObservingElement extends constructor {
|
|
7
|
+
constructor(...args) {
|
|
8
|
+
super(args);
|
|
9
|
+
this[_a] = /* @__PURE__ */ new Map();
|
|
10
|
+
this.managePresenceObservedSlot = () => {
|
|
11
|
+
let changes = false;
|
|
12
|
+
lightDomSelectors.forEach((selector) => {
|
|
13
|
+
const nextValue = !!this.querySelector(selector);
|
|
14
|
+
const previousValue = this[slotContentIsPresent].get(selector) || false;
|
|
15
|
+
changes = changes || previousValue !== nextValue;
|
|
16
|
+
this[slotContentIsPresent].set(selector, !!this.querySelector(selector));
|
|
17
|
+
});
|
|
18
|
+
if (changes) {
|
|
19
|
+
this.updateComplete.then(() => {
|
|
20
|
+
this.requestUpdate();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
new MutationController(this, {
|
|
25
|
+
config: {
|
|
26
|
+
childList: true,
|
|
27
|
+
subtree: true
|
|
28
|
+
},
|
|
29
|
+
callback: () => {
|
|
30
|
+
this.managePresenceObservedSlot();
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this.managePresenceObservedSlot();
|
|
34
|
+
}
|
|
35
|
+
get slotContentIsPresent() {
|
|
36
|
+
if (lightDomSelectors.length === 1) {
|
|
37
|
+
return this[slotContentIsPresent].get(lightDomSelectors[0]) || false;
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error("Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getSlotContentPresence(selector) {
|
|
43
|
+
if (this[slotContentIsPresent].has(selector)) {
|
|
44
|
+
return this[slotContentIsPresent].get(selector) || false;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`The provided selector \`${selector}\` is not being observed.`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
_a = slotContentIsPresent;
|
|
50
|
+
return SlotPresenceObservingElement;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=observe-slot-presence.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observe-slot-presence.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*/\nimport { ReactiveElement } from '@spectrum-web-components/base';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.managePresenceObservedSlot();\n },\n });\n\n this.managePresenceObservedSlot();\n }\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`${selector}\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n let changes = false;\n lightDomSelectors.forEach((selector) => {\n const nextValue = !!this.querySelector(selector);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n if (changes) {\n this.updateComplete.then(() => {\n this.requestUpdate();\n });\n }\n };\n }\n return SlotPresenceObservingElement;\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,MAAM,uBAAuB,OAAO,sBAAsB;AAcnD,oCACH,aACA,kBAC+C;AA9BnD;AA+BI,QAAM,oBAAoB,MAAM,QAAQ,gBAAgB,IAClD,mBACA,CAAC,gBAAgB;AACvB,QAAM,qCACM,YAEZ;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AA8BL,iBAA8C,oBAAI,IAAI;AAWxD,wCAA6B,MAAY;AAC5C,YAAI,UAAU;AACd,0BAAkB,QAAQ,CAAC,aAAa;AACpC,gBAAM,YAAY,CAAC,CAAC,KAAK,cAAc,QAAQ;AAC/C,gBAAM,gBACF,KAAK,sBAAsB,IAAI,QAAQ,KAAK;AAChD,oBAAU,WAAW,kBAAkB;AACvC,eAAK,sBAAsB,IACvB,UACA,CAAC,CAAC,KAAK,cAAc,QAAQ,CACjC;AAAA,QACJ,CAAC;AACD,YAAI,SAAS;AACT,eAAK,eAAe,KAAK,MAAM;AAC3B,iBAAK,cAAc;AAAA,UACvB,CAAC;AAAA,QACL;AAAA,MACJ;AAxDI,UAAI,mBAAmB,MAAM;AAAA,QACzB,QAAQ;AAAA,UACJ,WAAW;AAAA,UACX,SAAS;AAAA,QACb;AAAA,QACA,UAAU,MAAM;AACZ,eAAK,2BAA2B;AAAA,QACpC;AAAA,MACJ,CAAC;AAED,WAAK,2BAA2B;AAAA,IACpC;AAAA,QAKW,uBAAgC;AACvC,UAAI,kBAAkB,WAAW,GAAG;AAChC,eACI,KAAK,sBAAsB,IAAI,kBAAkB,EAAE,KACnD;AAAA,MAER,OAAO;AACH,cAAM,IAAI,MACN,8GACJ;AAAA,MACJ;AAAA,IACJ;AAAA,IAGO,uBAAuB,UAA2B;AACrD,UAAI,KAAK,sBAAsB,IAAI,QAAQ,GAAG;AAC1C,eAAO,KAAK,sBAAsB,IAAI,QAAQ,KAAK;AAAA,MACvD;AACA,YAAM,IAAI,MACN,2BAA2B,mCAC/B;AAAA,IACJ;AAAA,EAoBJ;AAnGJ,EAsEiB;AA8Bb,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,57 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const slotContentIsPresent = Symbol('slotContentIsPresent');
|
|
1
|
+
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
2
|
+
const slotContentIsPresent = Symbol("slotContentIsPresent");
|
|
4
3
|
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
var _a;
|
|
5
|
+
const lightDomSelectors = Array.isArray(lightDomSelector) ? lightDomSelector : [lightDomSelector];
|
|
6
|
+
class SlotPresenceObservingElement extends constructor {
|
|
7
|
+
constructor(...args) {
|
|
8
|
+
super(args);
|
|
9
|
+
this[_a] = /* @__PURE__ */ new Map();
|
|
10
|
+
this.managePresenceObservedSlot = () => {
|
|
11
|
+
let changes = false;
|
|
12
|
+
lightDomSelectors.forEach((selector) => {
|
|
13
|
+
const nextValue = !!this.querySelector(selector);
|
|
14
|
+
const previousValue = this[slotContentIsPresent].get(selector) || false;
|
|
15
|
+
changes = changes || previousValue !== nextValue;
|
|
16
|
+
this[slotContentIsPresent].set(selector, !!this.querySelector(selector));
|
|
17
|
+
});
|
|
18
|
+
if (changes) {
|
|
19
|
+
this.updateComplete.then(() => {
|
|
20
|
+
this.requestUpdate();
|
|
21
|
+
});
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else {
|
|
29
|
-
throw new Error('Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
getSlotContentPresence(selector) {
|
|
33
|
-
if (this[slotContentIsPresent].has(selector)) {
|
|
34
|
-
return this[slotContentIsPresent].get(selector) || false;
|
|
35
|
-
}
|
|
36
|
-
throw new Error(`The provided selector \`\` is not being observed.`);
|
|
37
|
-
}
|
|
38
|
-
[(_a = slotContentIsPresent, startObserving)]() {
|
|
39
|
-
const config = { childList: true, subtree: true };
|
|
40
|
-
if (!this[slotElementObserver]) {
|
|
41
|
-
this[slotElementObserver] = new MutationObserver(this.managePresenceObservedSlot);
|
|
42
|
-
}
|
|
43
|
-
this[slotElementObserver].observe(this, config);
|
|
44
|
-
this.managePresenceObservedSlot();
|
|
45
|
-
}
|
|
46
|
-
connectedCallback() {
|
|
47
|
-
super.connectedCallback();
|
|
48
|
-
this[startObserving]();
|
|
49
|
-
}
|
|
50
|
-
disconnectedCallback() {
|
|
51
|
-
this[slotElementObserver].disconnect();
|
|
52
|
-
super.disconnectedCallback();
|
|
23
|
+
};
|
|
24
|
+
new MutationController(this, {
|
|
25
|
+
config: {
|
|
26
|
+
childList: true,
|
|
27
|
+
subtree: true
|
|
28
|
+
},
|
|
29
|
+
callback: () => {
|
|
30
|
+
this.managePresenceObservedSlot();
|
|
53
31
|
}
|
|
32
|
+
});
|
|
33
|
+
this.managePresenceObservedSlot();
|
|
34
|
+
}
|
|
35
|
+
get slotContentIsPresent() {
|
|
36
|
+
if (lightDomSelectors.length === 1) {
|
|
37
|
+
return this[slotContentIsPresent].get(lightDomSelectors[0]) || false;
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error("Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getSlotContentPresence(selector) {
|
|
43
|
+
if (this[slotContentIsPresent].has(selector)) {
|
|
44
|
+
return this[slotContentIsPresent].get(selector) || false;
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`The provided selector \`${selector}\` is not being observed.`);
|
|
54
47
|
}
|
|
55
|
-
|
|
48
|
+
}
|
|
49
|
+
_a = slotContentIsPresent;
|
|
50
|
+
return SlotPresenceObservingElement;
|
|
56
51
|
}
|
|
57
|
-
//# sourceMappingURL=observe-slot-presence.js.map
|
|
52
|
+
//# sourceMappingURL=observe-slot-presence.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observe-slot-presence.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*/\nimport { ReactiveElement } from '@spectrum-web-components/base';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.managePresenceObservedSlot();\n },\n });\n\n this.managePresenceObservedSlot();\n }\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`${selector}\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n let changes = false;\n lightDomSelectors.forEach((selector) => {\n const nextValue = !!this.querySelector(selector);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n if (changes) {\n this.updateComplete.then(() => {\n this.requestUpdate();\n });\n }\n };\n }\n return SlotPresenceObservingElement;\n}\n"],
|
|
5
|
+
"mappings": "AAWA;AAEA,MAAM,uBAAuB,OAAO,sBAAsB;AAcnD,oCACH,aACA,kBAC+C;AA9BnD;AA+BI,QAAM,oBAAoB,MAAM,QAAQ,gBAAgB,IAClD,mBACA,CAAC,gBAAgB;AACvB,QAAM,qCACM,YAEZ;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AA8BL,iBAA8C,oBAAI,IAAI;AAWxD,wCAA6B,MAAY;AAC5C,YAAI,UAAU;AACd,0BAAkB,QAAQ,CAAC,aAAa;AACpC,gBAAM,YAAY,CAAC,CAAC,KAAK,cAAc,QAAQ;AAC/C,gBAAM,gBACF,KAAK,sBAAsB,IAAI,QAAQ,KAAK;AAChD,oBAAU,WAAW,kBAAkB;AACvC,eAAK,sBAAsB,IACvB,UACA,CAAC,CAAC,KAAK,cAAc,QAAQ,CACjC;AAAA,QACJ,CAAC;AACD,YAAI,SAAS;AACT,eAAK,eAAe,KAAK,MAAM;AAC3B,iBAAK,cAAc;AAAA,UACvB,CAAC;AAAA,QACL;AAAA,MACJ;AAxDI,UAAI,mBAAmB,MAAM;AAAA,QACzB,QAAQ;AAAA,UACJ,WAAW;AAAA,UACX,SAAS;AAAA,QACb;AAAA,QACA,UAAU,MAAM;AACZ,eAAK,2BAA2B;AAAA,QACpC;AAAA,MACJ,CAAC;AAED,WAAK,2BAA2B;AAAA,IACpC;AAAA,QAKW,uBAAgC;AACvC,UAAI,kBAAkB,WAAW,GAAG;AAChC,eACI,KAAK,sBAAsB,IAAI,kBAAkB,EAAE,KACnD;AAAA,MAER,OAAO;AACH,cAAM,IAAI,MACN,8GACJ;AAAA,MACJ;AAAA,IACJ;AAAA,IAGO,uBAAuB,UAA2B;AACrD,UAAI,KAAK,sBAAsB,IAAI,QAAQ,GAAG;AAC1C,eAAO,KAAK,sBAAsB,IAAI,QAAQ,KAAK;AAAA,MACvD;AACA,YAAM,IAAI,MACN,2BAA2B,mCAC/B;AAAA,IACJ;AAAA,EAoBJ;AAnGJ,EAsEiB;AA8Bb,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -7,5 +7,5 @@ export interface SlotTextObservingInterface {
|
|
|
7
7
|
slotHasContent: boolean;
|
|
8
8
|
manageTextObservedSlot(): void;
|
|
9
9
|
}
|
|
10
|
-
export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T,
|
|
10
|
+
export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T, slotName?: string): T & Constructor<SlotTextObservingInterface>;
|
|
11
11
|
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__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) {
|
|
19
|
+
var _a;
|
|
20
|
+
class SlotTextObservingElement extends constructor {
|
|
21
|
+
constructor(...args) {
|
|
22
|
+
super(args);
|
|
23
|
+
this.slotHasContent = false;
|
|
24
|
+
new MutationController(this, {
|
|
25
|
+
config: {
|
|
26
|
+
characterData: true,
|
|
27
|
+
subtree: true
|
|
28
|
+
},
|
|
29
|
+
callback: (mutationsList) => {
|
|
30
|
+
for (const mutation of mutationsList) {
|
|
31
|
+
if (mutation.type === "characterData") {
|
|
32
|
+
this.manageTextObservedSlot();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
manageTextObservedSlot() {
|
|
40
|
+
if (!this[assignedNodesList])
|
|
41
|
+
return;
|
|
42
|
+
const assignedNodes = [...this[assignedNodesList]].filter((node) => {
|
|
43
|
+
if (node.tagName) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return node.textContent ? node.textContent.trim() : false;
|
|
47
|
+
});
|
|
48
|
+
this.slotHasContent = assignedNodes.length > 0;
|
|
49
|
+
}
|
|
50
|
+
update(changedProperties) {
|
|
51
|
+
if (!this.hasUpdated) {
|
|
52
|
+
const { childNodes } = this;
|
|
53
|
+
const textNodes = [...childNodes].filter((node) => {
|
|
54
|
+
if (node.tagName) {
|
|
55
|
+
return slotName ? node.getAttribute("slot") === slotName : !node.hasAttribute("slot");
|
|
56
|
+
}
|
|
57
|
+
return node.textContent ? node.textContent.trim() : false;
|
|
58
|
+
});
|
|
59
|
+
this.slotHasContent = textNodes.length > 0;
|
|
60
|
+
}
|
|
61
|
+
super.update(changedProperties);
|
|
62
|
+
}
|
|
63
|
+
firstUpdated(changedProperties) {
|
|
64
|
+
super.firstUpdated(changedProperties);
|
|
65
|
+
this.updateComplete.then(() => {
|
|
66
|
+
this.manageTextObservedSlot();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
_a = assignedNodesList;
|
|
71
|
+
__decorateClass([
|
|
72
|
+
property({ type: Boolean, attribute: false })
|
|
73
|
+
], SlotTextObservingElement.prototype, "slotHasContent", 2);
|
|
74
|
+
__decorateClass([
|
|
75
|
+
queryAssignedNodes(slotName, true)
|
|
76
|
+
], SlotTextObservingElement.prototype, _a, 2);
|
|
77
|
+
return SlotTextObservingElement;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=observe-slot-text.dev.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["observe-slot-text.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 { PropertyValues, ReactiveElement } from '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst assignedNodesList = Symbol('assignedNodes');\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SlotTextObservingInterface {\n slotHasContent: boolean;\n manageTextObservedSlot(): void;\n}\n\nexport function ObserveSlotText<T extends Constructor<ReactiveElement>>(\n constructor: T,\n slotName?: string\n): T & Constructor<SlotTextObservingInterface> {\n class SlotTextObservingElement\n extends constructor\n implements SlotTextObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n characterData: true,\n subtree: true,\n },\n callback: (mutationsList: Array<MutationRecord>) => {\n for (const mutation of mutationsList) {\n if (mutation.type === 'characterData') {\n this.manageTextObservedSlot();\n return;\n }\n }\n },\n });\n }\n\n @property({ type: Boolean, attribute: false })\n public slotHasContent = false;\n\n @queryAssignedNodes(slotName, true)\n private [assignedNodesList]!: NodeListOf<HTMLElement>;\n\n public manageTextObservedSlot(): void {\n if (!this[assignedNodesList]) return;\n const assignedNodes = [...this[assignedNodesList]].filter(\n (node) => {\n if ((node as HTMLElement).tagName) {\n return true;\n }\n return node.textContent ? node.textContent.trim() : false;\n }\n );\n this.slotHasContent = assignedNodes.length > 0;\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (!this.hasUpdated) {\n const { childNodes } = this;\n const textNodes = [...childNodes].filter((node) => {\n if ((node as HTMLElement).tagName) {\n return slotName\n ? (node as HTMLElement).getAttribute('slot') ===\n slotName\n : !(node as HTMLElement).hasAttribute('slot');\n }\n return node.textContent ? node.textContent.trim() : false;\n });\n this.slotHasContent = textNodes.length > 0;\n }\n super.update(changedProperties);\n }\n\n protected override firstUpdated(\n changedProperties: PropertyValues\n ): void {\n super.firstUpdated(changedProperties);\n this.updateComplete.then(() => {\n this.manageTextObservedSlot();\n });\n }\n }\n return SlotTextObservingElement;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA;AAAA;AAAA;AAIA;AAEA,MAAM,oBAAoB,OAAO,eAAe;AAazC,gCACH,aACA,UAC2C;AAlC/C;AAmCI,QAAM,iCACM,YAEZ;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AAmBP,4BAAiB;AAjBpB,UAAI,mBAAmB,MAAM;AAAA,QACzB,QAAQ;AAAA,UACJ,eAAe;AAAA,UACf,SAAS;AAAA,QACb;AAAA,QACA,UAAU,CAAC,kBAAyC;AAChD,qBAAW,YAAY,eAAe;AAClC,gBAAI,SAAS,SAAS,iBAAiB;AACnC,mBAAK,uBAAuB;AAC5B;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,IAQO,yBAA+B;AAClC,UAAI,CAAC,KAAK;AAAoB;AAC9B,YAAM,gBAAgB,CAAC,GAAG,KAAK,kBAAkB,EAAE,OAC/C,CAAC,SAAS;AACN,YAAK,KAAqB,SAAS;AAC/B,iBAAO;AAAA,QACX;AACA,eAAO,KAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAAA,MACxD,CACJ;AACA,WAAK,iBAAiB,cAAc,SAAS;AAAA,IACjD;AAAA,IAEmB,OAAO,mBAAyC;AAC/D,UAAI,CAAC,KAAK,YAAY;AAClB,cAAM,EAAE,eAAe;AACvB,cAAM,YAAY,CAAC,GAAG,UAAU,EAAE,OAAO,CAAC,SAAS;AAC/C,cAAK,KAAqB,SAAS;AAC/B,mBAAO,WACA,KAAqB,aAAa,MAAM,MACrC,WACJ,CAAE,KAAqB,aAAa,MAAM;AAAA,UACpD;AACA,iBAAO,KAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAAA,QACxD,CAAC;AACD,aAAK,iBAAiB,UAAU,SAAS;AAAA,MAC7C;AACA,YAAM,OAAO,iBAAiB;AAAA,IAClC;AAAA,IAEmB,aACf,mBACI;AACJ,YAAM,aAAa,iBAAiB;AACpC,WAAK,eAAe,KAAK,MAAM;AAC3B,aAAK,uBAAuB;AAAA,MAChC,CAAC;AAAA,IACL;AAAA,EACJ;AAvGJ,EA+DiB;AAHF;AAAA,IADP,AAAC,SAAS,EAAE,MAAM,SAAS,WAAW,MAAM,CAAC;AAAA,KACtC,AAzBX,yBAyBW;AAGE;AAAA,IADT,AAAC,mBAAmB,UAAU,IAAI;AAAA,KACzB,AA5Bb,yBA4Ba;AAyCb,SAAO;AACX;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|