@spectrum-web-components/shared 0.42.2 → 0.42.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/focus-visible.d.ts +2 -2
- package/src/focus-visible.dev.js +2 -3
- package/src/focus-visible.dev.js.map +1 -1
- package/src/focus-visible.js +1 -1
- package/src/focus-visible.js.map +2 -2
- package/src/focusable.d.ts +1 -1
- package/src/focusable.dev.js +1 -2
- package/src/focusable.dev.js.map +1 -1
- package/src/get-label-from-slot.dev.js +1 -2
- package/src/get-label-from-slot.dev.js.map +1 -1
- package/src/like-anchor.d.ts +2 -2
- package/src/like-anchor.dev.js +1 -2
- package/src/like-anchor.dev.js.map +1 -1
- package/src/like-anchor.js +7 -7
- package/src/observe-slot-presence.d.ts +1 -1
- package/src/observe-slot-presence.dev.js +2 -3
- package/src/observe-slot-presence.dev.js.map +1 -1
- package/src/observe-slot-presence.js +1 -1
- package/src/observe-slot-presence.js.map +2 -2
- package/src/observe-slot-text.d.ts +1 -1
- package/src/observe-slot-text.dev.js +4 -7
- package/src/observe-slot-text.dev.js.map +1 -1
- package/src/observe-slot-text.js +1 -1
- package/src/observe-slot-text.js.map +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/shared",
|
|
3
|
-
"version": "0.42.
|
|
3
|
+
"version": "0.42.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
"lit-html"
|
|
101
101
|
],
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@lit-labs/observers": "^2.0.
|
|
104
|
-
"@spectrum-web-components/base": "^0.42.
|
|
103
|
+
"@lit-labs/observers": "^2.0.2",
|
|
104
|
+
"@spectrum-web-components/base": "^0.42.4",
|
|
105
105
|
"focus-visible": "^5.1.0"
|
|
106
106
|
},
|
|
107
107
|
"types": "./src/index.d.ts",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"sideEffects": [
|
|
110
110
|
"./**/*.dev.js"
|
|
111
111
|
],
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "4924ffd06681ced537edaed873a9ce8b42cf155c"
|
|
113
113
|
}
|
package/src/focus-visible.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ declare global {
|
|
|
3
3
|
applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
type Constructor<T = Record<string, unknown>> = {
|
|
7
7
|
new (...args: any[]): T;
|
|
8
8
|
prototype: T;
|
|
9
9
|
};
|
|
@@ -12,7 +12,7 @@ interface OptionalLifecycleCallbacks {
|
|
|
12
12
|
disconnectedCallback?(): void;
|
|
13
13
|
manageAutoFocus?(): void;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
type MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;
|
|
16
16
|
/**
|
|
17
17
|
* This mixin function is designed to be applied to a class that inherits
|
|
18
18
|
* from HTMLElement. It makes it easy for a custom element to coordinate with
|
package/src/focus-visible.dev.js
CHANGED
|
@@ -7,7 +7,7 @@ try {
|
|
|
7
7
|
import("focus-visible");
|
|
8
8
|
}
|
|
9
9
|
export const FocusVisiblePolyfillMixin = (SuperClass) => {
|
|
10
|
-
var _a;
|
|
10
|
+
var _a, _b;
|
|
11
11
|
const coordinateWithPolyfill = (instance) => {
|
|
12
12
|
if (instance.shadowRoot == null || instance.hasAttribute("data-js-focus-visible")) {
|
|
13
13
|
return () => {
|
|
@@ -43,7 +43,7 @@ export const FocusVisiblePolyfillMixin = (SuperClass) => {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
const $endPolyfillCoordination = Symbol("endPolyfillCoordination");
|
|
46
|
-
class FocusVisibleCoordinator extends SuperClass {
|
|
46
|
+
class FocusVisibleCoordinator extends (_b = SuperClass, _a = $endPolyfillCoordination, _b) {
|
|
47
47
|
constructor() {
|
|
48
48
|
super(...arguments);
|
|
49
49
|
this[_a] = null;
|
|
@@ -72,7 +72,6 @@ export const FocusVisiblePolyfillMixin = (SuperClass) => {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
_a = $endPolyfillCoordination;
|
|
76
75
|
return FocusVisibleCoordinator;
|
|
77
76
|
};
|
|
78
77
|
//# sourceMappingURL=focus-visible.dev.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["focus-visible.ts"],
|
|
4
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\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\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\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n override connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"],
|
|
5
|
-
"mappings": ";AAkCA,IAAI,kBAAkB;AAEtB,IAAI;AACA,WAAS,KAAK,cAAc,gBAAgB;AAChD,SAAS,OAAO;AACZ,oBAAkB;AAGlB,SAAO,eAAe;AAC1B;AAcO,aAAM,4BAA4B,CAGrC,eACI;AA7DR;AA8DI,QAAM,yBAAyB,CAC3B,aACkC;AAIlC,QACI,SAAS,cAAc,QACvB,SAAS,aAAa,uBAAuB,GAC/C;AAEE,aAAO,MAAM;AAAA,MAAC;AAAA,IAClB;AAIA,QAAI,KAAK,2BAA2B;AAChC,WAAK,0BAA0B,SAAS,UAAU;AAElD,UAAI,SAAS,iBAAiB;AAC1B,iBAAS,gBAAgB;AAAA,MAC7B;AAAA,IACJ,OAAO;AACH,YAAM,sBAAsB,MAAY;AACpC,YAAI,KAAK,6BAA6B,SAAS,YAAY;AACvD,eAAK,0BAA0B,SAAS,UAAU;AAAA,QACtD;AAEA,YAAI,SAAS,iBAAiB;AAC1B,mBAAS,gBAAgB;AAAA,QAC7B;AAAA,MACJ;AAKA,WAAK;AAAA,QACD;AAAA,QACA;AAAA,QACA,EAAE,MAAM,KAAK;AAAA,MACjB;AAEA,aAAO,MAAM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AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,wBAAwB,KAAK,MAAM;AACxC,iBAAK,wBAAwB,IACzB,uBAAuB,IAAI;AAAA,UACnC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,IAES,uBAA6B;AAClC,YAAM,wBAAwB,MAAM,qBAAqB;AAGzD,UAAI,CAAC,iBAAiB;AAClB,8BAAsB,MAAM;AACxB,cAAI,KAAK,wBAAwB,KAAK,MAAM;AAExC,iBAAK,wBAAwB,EAAG;AAChC,iBAAK,wBAAwB,IAAI;AAAA,UACrC;AAAA,QACJ,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/focus-visible.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";let i=!0;try{document.body.querySelector(":focus-visible")}catch(a){i=!1,import("focus-visible")}export const FocusVisiblePolyfillMixin=a=>{var
|
|
1
|
+
"use strict";let i=!0;try{document.body.querySelector(":focus-visible")}catch(a){i=!1,import("focus-visible")}export const FocusVisiblePolyfillMixin=a=>{var s,t;const n=l=>{if(l.shadowRoot==null||l.hasAttribute("data-js-focus-visible"))return()=>{};if(self.applyFocusVisiblePolyfill)self.applyFocusVisiblePolyfill(l.shadowRoot),l.manageAutoFocus&&l.manageAutoFocus();else{const e=()=>{self.applyFocusVisiblePolyfill&&l.shadowRoot&&self.applyFocusVisiblePolyfill(l.shadowRoot),l.manageAutoFocus&&l.manageAutoFocus()};return self.addEventListener("focus-visible-polyfill-ready",e,{once:!0}),()=>{self.removeEventListener("focus-visible-polyfill-ready",e)}}return()=>{}},o=Symbol("endPolyfillCoordination");class c extends(t=a,s=o,t){constructor(){super(...arguments);this[s]=null}connectedCallback(){super.connectedCallback&&super.connectedCallback(),i||requestAnimationFrame(()=>{this[o]==null&&(this[o]=n(this))})}disconnectedCallback(){super.disconnectedCallback&&super.disconnectedCallback(),i||requestAnimationFrame(()=>{this[o]!=null&&(this[o](),this[o]=null)})}}return c};
|
|
2
2
|
//# sourceMappingURL=focus-visible.js.map
|
package/src/focus-visible.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["focus-visible.ts"],
|
|
4
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\ndeclare global {\n interface Window {\n applyFocusVisiblePolyfill?: (scope: Document | ShadowRoot) => void;\n }\n}\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\ninterface OptionalLifecycleCallbacks {\n connectedCallback?(): void;\n disconnectedCallback?(): void;\n manageAutoFocus?(): void;\n}\n\ntype MixableBaseClass = HTMLElement & OptionalLifecycleCallbacks;\n\ntype EndPolyfillCoordinationCallback = () => void;\n\nlet hasFocusVisible = true;\n\ntry {\n document.body.querySelector(':focus-visible');\n} catch (error) {\n hasFocusVisible = false;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n import('focus-visible');\n}\n\n/**\n * This mixin function is designed to be applied to a class that inherits\n * from HTMLElement. It makes it easy for a custom element to coordinate with\n * the :focus-visible polyfill.\n *\n * NOTE(cdata): The code here was adapted from an example proposed with the\n * introduction of ShadowDOM support in the :focus-visible polyfill.\n *\n * @see https://github.com/WICG/focus-visible/pull/196\n * @param {Function} SuperClass The base class implementation to decorate with\n * implementation that coordinates with the :focus-visible polyfill\n */\nexport const FocusVisiblePolyfillMixin = <\n T extends Constructor<MixableBaseClass>\n>(\n SuperClass: T\n): T => {\n const coordinateWithPolyfill = (\n instance: MixableBaseClass\n ): EndPolyfillCoordinationCallback => {\n // If there is no shadow root, there is no need to coordinate with\n // the polyfill. If we already coordinated with the polyfill, we can\n // skip subsequent invokcations:\n if (\n instance.shadowRoot == null ||\n instance.hasAttribute('data-js-focus-visible')\n ) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n }\n\n // The polyfill might already be loaded. If so, we can apply it to\n // the shadow root immediately:\n if (self.applyFocusVisiblePolyfill) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n } else {\n const coordinationHandler = (): void => {\n if (self.applyFocusVisiblePolyfill && instance.shadowRoot) {\n self.applyFocusVisiblePolyfill(instance.shadowRoot);\n }\n\n if (instance.manageAutoFocus) {\n instance.manageAutoFocus();\n }\n };\n // Otherwise, wait for the polyfill to be loaded lazily. It might\n // never be loaded, but if it is then we can apply it to the\n // shadow root at the appropriate time by waiting for the ready\n // event:\n self.addEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler,\n { once: true }\n );\n\n return () => {\n self.removeEventListener(\n 'focus-visible-polyfill-ready',\n coordinationHandler\n );\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n return () => {};\n };\n\n const $endPolyfillCoordination = Symbol('endPolyfillCoordination');\n\n // IE11 doesn't natively support custom elements or JavaScript class\n // syntax The mixin implementation assumes that the user will take the\n // appropriate steps to support both:\n class FocusVisibleCoordinator extends SuperClass {\n private [$endPolyfillCoordination]: EndPolyfillCoordinationCallback | null =\n null;\n\n // Attempt to coordinate with the polyfill when connected to the\n // document:\n override connectedCallback(): void {\n super.connectedCallback && super.connectedCallback();\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] == null) {\n this[$endPolyfillCoordination] =\n coordinateWithPolyfill(this);\n }\n });\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback && super.disconnectedCallback();\n // It's important to remove the polyfill event listener when we\n // disconnect, otherwise we will leak the whole element via window:\n if (!hasFocusVisible) {\n requestAnimationFrame(() => {\n if (this[$endPolyfillCoordination] != null) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this[$endPolyfillCoordination]!();\n this[$endPolyfillCoordination] = null;\n }\n });\n }\n }\n }\n\n return FocusVisibleCoordinator;\n};\n"],
|
|
5
|
-
"mappings": "aAkCA,IAAIA,EAAkB,GAEtB,GAAI,CACA,SAAS,KAAK,cAAc,gBAAgB,CAChD,OAASC,EAAO,CACZD,EAAkB,GAGlB,OAAO,eAAe,CAC1B,CAcO,aAAM,0BAGTE,GACI,CA7DR,IAAAC,EA8DI,MAAMC,EACFC,GACkC,CAIlC,GACIA,EAAS,YAAc,MACvBA,EAAS,aAAa,uBAAuB,EAG7C,MAAO,IAAM,CAAC,EAKlB,GAAI,KAAK,0BACL,KAAK,0BAA0BA,EAAS,UAAU,EAE9CA,EAAS,iBACTA,EAAS,gBAAgB,MAE1B,CACH,MAAMC,EAAsB,IAAY,CAChC,KAAK,2BAA6BD,EAAS,YAC3C,KAAK,0BAA0BA,EAAS,UAAU,EAGlDA,EAAS,iBACTA,EAAS,gBAAgB,CAEjC,EAKA,YAAK,iBACD,+BACAC,EACA,CAAE,KAAM,EAAK,CACjB,EAEO,IAAM,CACT,KAAK,oBACD,+BACAA,CACJ,CACJ,CACJ,CAGA,MAAO,IAAM,CAAC,CAClB,EAEMC,EAA2B,OAAO,yBAAyB,EAKjE,MAAMC,
|
|
6
|
-
"names": ["hasFocusVisible", "error", "SuperClass", "_a", "coordinateWithPolyfill", "instance", "coordinationHandler", "$endPolyfillCoordination", "FocusVisibleCoordinator"]
|
|
5
|
+
"mappings": "aAkCA,IAAIA,EAAkB,GAEtB,GAAI,CACA,SAAS,KAAK,cAAc,gBAAgB,CAChD,OAASC,EAAO,CACZD,EAAkB,GAGlB,OAAO,eAAe,CAC1B,CAcO,aAAM,0BAGTE,GACI,CA7DR,IAAAC,EAAAC,EA8DI,MAAMC,EACFC,GACkC,CAIlC,GACIA,EAAS,YAAc,MACvBA,EAAS,aAAa,uBAAuB,EAG7C,MAAO,IAAM,CAAC,EAKlB,GAAI,KAAK,0BACL,KAAK,0BAA0BA,EAAS,UAAU,EAE9CA,EAAS,iBACTA,EAAS,gBAAgB,MAE1B,CACH,MAAMC,EAAsB,IAAY,CAChC,KAAK,2BAA6BD,EAAS,YAC3C,KAAK,0BAA0BA,EAAS,UAAU,EAGlDA,EAAS,iBACTA,EAAS,gBAAgB,CAEjC,EAKA,YAAK,iBACD,+BACAC,EACA,CAAE,KAAM,EAAK,CACjB,EAEO,IAAM,CACT,KAAK,oBACD,+BACAA,CACJ,CACJ,CACJ,CAGA,MAAO,IAAM,CAAC,CAClB,EAEMC,EAA2B,OAAO,yBAAyB,EAKjE,MAAMC,UAAgCL,EAAAF,EACzBC,EAAAK,EADyBJ,EAAW,CAAjD,kCACI,KAASD,GACL,KAIK,mBAA0B,CAC/B,MAAM,mBAAqB,MAAM,kBAAkB,EAC9CH,GACD,sBAAsB,IAAM,CACpB,KAAKQ,CAAwB,GAAK,OAClC,KAAKA,CAAwB,EACzBH,EAAuB,IAAI,EAEvC,CAAC,CAET,CAES,sBAA6B,CAClC,MAAM,sBAAwB,MAAM,qBAAqB,EAGpDL,GACD,sBAAsB,IAAM,CACpB,KAAKQ,CAAwB,GAAK,OAElC,KAAKA,CAAwB,EAAG,EAChC,KAAKA,CAAwB,EAAI,KAEzC,CAAC,CAET,CACJ,CAEA,OAAOC,CACX",
|
|
6
|
+
"names": ["hasFocusVisible", "error", "SuperClass", "_a", "_b", "coordinateWithPolyfill", "instance", "coordinationHandler", "$endPolyfillCoordination", "FocusVisibleCoordinator"]
|
|
7
7
|
}
|
package/src/focusable.d.ts
CHANGED
package/src/focusable.dev.js
CHANGED
|
@@ -6,8 +6,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
6
6
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
7
|
if (decorator = decorators[i])
|
|
8
8
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
-
if (kind && result)
|
|
10
|
-
__defProp(target, key, result);
|
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
10
|
return result;
|
|
12
11
|
};
|
|
13
12
|
import { SpectrumElement } from "@spectrum-web-components/base";
|
package/src/focusable.dev.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["focusable.ts"],
|
|
4
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, SpectrumElement } from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nimport { FocusVisiblePolyfillMixin } from './focus-visible.dev.js'\n\ntype DisableableElement = HTMLElement & { disabled?: boolean };\n\nfunction nextFrame(): Promise<void> {\n return new Promise((res) => requestAnimationFrame(() => res()));\n}\n\n/**\n * Focusable base class handles tabindex setting into shadowed elements automatically.\n *\n * This implementation is based heavily on the aybolit delegate-focus-mixin at\n * https://github.com/web-padawan/aybolit/blob/master/packages/core/src/mixins/delegate-focus-mixin.js\n */\nexport class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {\n /**\n * Disable this control. It will not receive focus or events\n */\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n /**\n * When this control is rendered, focus it automatically\n * @private\n */\n @property({ type: Boolean })\n public override autofocus = false;\n\n /**\n * The tab index to apply to this control. See general documentation about\n * the tabindex HTML property\n *\n * @private\n */\n @property({ type: Number })\n public override get tabIndex(): number {\n if (this.focusElement === this) {\n const tabindex = this.hasAttribute('tabindex')\n ? Number(this.getAttribute('tabindex'))\n : NaN;\n return !isNaN(tabindex) ? tabindex : -1;\n }\n const tabIndexAttribute = parseFloat(\n this.hasAttribute('tabindex')\n ? (this.getAttribute('tabindex') as string) || '0'\n : '0'\n );\n // When `disabled` tabindex is -1.\n // When host tabindex -1, use that as the cache.\n if (this.disabled || tabIndexAttribute < 0) {\n return -1;\n }\n // When `focusElement` isn't available yet,\n // use host tabindex as the cache.\n if (!this.focusElement) {\n return tabIndexAttribute;\n }\n // All other times, use the tabindex of `focusElement`\n // as the cache for this value.\n return this.focusElement.tabIndex;\n }\n public override set tabIndex(tabIndex: number) {\n // Flipping `manipulatingTabindex` to true before a change\n // allows for that change NOT to effect the cached value of tabindex\n if (this.manipulatingTabindex) {\n this.manipulatingTabindex = false;\n return;\n }\n if (this.focusElement === this) {\n if (tabIndex !== this._tabIndex) {\n this._tabIndex = tabIndex;\n const tabindex = this.disabled ? '-1' : '' + tabIndex;\n this.manipulatingTabindex = true;\n this.setAttribute('tabindex', tabindex);\n }\n return;\n }\n if (tabIndex === -1) {\n this.addEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n } else {\n // All code paths are about to address the host tabindex without side effect.\n this.manipulatingTabindex = true;\n this.removeEventListener(\n 'pointerdown',\n this.onPointerdownManagementOfTabIndex\n );\n }\n if (tabIndex === -1 || this.disabled) {\n // Do not cange the tabindex of `focusElement` as it is the \"old\" value cache.\n // Make element NOT focusable.\n this.setAttribute('tabindex', '-1');\n this.removeAttribute('focusable');\n if (tabIndex !== -1) {\n // Cache all NON-`-1` values on the `focusElement`.\n this.manageFocusElementTabindex(tabIndex);\n }\n return;\n }\n this.setAttribute('focusable', '');\n if (this.hasAttribute('tabindex')) {\n this.removeAttribute('tabindex');\n } else {\n // You can't remove an attribute that isn't there,\n // manually end the `manipulatingTabindex` guard.\n this.manipulatingTabindex = false;\n }\n this.manageFocusElementTabindex(tabIndex);\n }\n private _tabIndex = 0;\n\n private onPointerdownManagementOfTabIndex(): void {\n if (this.tabIndex === -1) {\n setTimeout(() => {\n // Ensure this happens _after_ WebKit attempts to focus the :host.\n this.tabIndex = 0;\n this.focus({ preventScroll: true });\n this.tabIndex = -1;\n });\n }\n }\n\n private async manageFocusElementTabindex(tabIndex: number): Promise<void> {\n if (!this.focusElement) {\n // allow setting these values to be async when needed.\n await this.updateComplete;\n }\n if (tabIndex === null) {\n this.focusElement.removeAttribute('tabindex');\n } else {\n this.focusElement.tabIndex = tabIndex;\n }\n }\n\n private manipulatingTabindex = false;\n\n /**\n * @private\n */\n public get focusElement(): DisableableElement {\n throw new Error('Must implement focusElement getter!');\n }\n\n public override focus(options?: FocusOptions): void {\n if (this.disabled || !this.focusElement) {\n return;\n }\n\n if (this.focusElement !== this) {\n this.focusElement.focus(options);\n } else {\n HTMLElement.prototype.focus.apply(this, [options]);\n }\n }\n\n public override blur(): void {\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.blur();\n } else {\n HTMLElement.prototype.blur.apply(this);\n }\n }\n\n public override click(): void {\n if (this.disabled) {\n return;\n }\n\n const focusElement = this.focusElement || this;\n if (focusElement !== this) {\n focusElement.click();\n } else {\n HTMLElement.prototype.click.apply(this);\n }\n }\n\n protected manageAutoFocus(): void {\n if (this.autofocus) {\n /**\n * Trick :focus-visible polyfill into thinking keyboard based focus\n *\n * @private\n **/\n this.dispatchEvent(\n new KeyboardEvent('keydown', {\n code: 'Tab',\n })\n );\n this.focusElement.focus();\n }\n }\n\n protected override firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (\n !this.hasAttribute('tabindex') ||\n this.getAttribute('tabindex') !== '-1'\n ) {\n this.setAttribute('focusable', '');\n }\n }\n\n protected override update(changedProperties: PropertyValues): void {\n if (changedProperties.has('disabled')) {\n this.handleDisabledChanged(\n this.disabled,\n changedProperties.get('disabled') as boolean\n );\n }\n\n super.update(changedProperties);\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n\n if (changedProperties.has('disabled') && this.disabled) {\n this.blur();\n }\n }\n\n private async handleDisabledChanged(\n disabled: boolean,\n oldDisabled: boolean\n ): Promise<void> {\n const canSetDisabled = (): boolean =>\n this.focusElement !== this &&\n typeof this.focusElement.disabled !== 'undefined';\n if (disabled) {\n this.manipulatingTabindex = true;\n this.setAttribute('tabindex', '-1');\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = true;\n } else {\n this.setAttribute('aria-disabled', 'true');\n }\n } else if (oldDisabled) {\n this.manipulatingTabindex = true;\n if (this.focusElement === this) {\n this.setAttribute('tabindex', '' + this._tabIndex);\n } else {\n this.removeAttribute('tabindex');\n }\n await this.updateComplete;\n if (canSetDisabled()) {\n this.focusElement.disabled = false;\n } else {\n this.removeAttribute('aria-disabled');\n }\n }\n }\n\n protected override async getUpdateComplete(): Promise<boolean> {\n const complete = (await super.getUpdateComplete()) as boolean;\n await this.autofocusReady;\n return complete;\n }\n\n private autofocusReady = Promise.resolve();\n\n public override connectedCallback(): void {\n super.connectedCallback();\n if (this.autofocus) {\n this.autofocusReady = new Promise(async (res) => {\n // If at connect time the [autofocus] content is placed within\n // content that needs to be \"hidden\" by default, it would need to wait\n // two rAFs for animations to be triggered on that content in\n // order for the [autofocus] to become \"visisble\" and have its\n // focus() capabilities enabled.\n //\n // Await this with `getUpdateComplete` so that the element cannot\n // become \"ready\" until `manageFocus` has occured.\n await nextFrame();\n await nextFrame();\n res();\n });\n this.updateComplete.then(() => {\n this.manageAutoFocus();\n });\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAWA,SAAyB,uBAAuB;AAChD,SAAS,gBAAgB;AAEzB,SAAS,iCAAiC;AAI1C,SAAS,YAA2B;AAChC,SAAO,IAAI,QAAQ,CAAC,QAAQ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uB;AAC5B,UAAI,KAAK,iBAAiB,MAAM;AAC5B,aAAK,aAAa,YAAY,KAAK,KAAK,SAAS;AAAA,MACrD,OAAO;AACH,aAAK,gBAAgB,UAAU;AAAA,MACnC;AACA,YAAM,KAAK;AACX,UAAI,eAAe,GAAG;AAClB,aAAK,aAAa,WAAW;AAAA,MACjC,OAAO;AACH,aAAK,gBAAgB,eAAe;AAAA,MACxC;AAAA,IACJ;AAAA,EACJ;AAAA,EAEA,MAAyB,oBAAsC;AAC3D,UAAM,WAAY,MAAM,MAAM,kBAAkB;AAChD,UAAM,KAAK;AACX,WAAO;AAAA,EACX;AAAA,EAIgB,oBAA0B;AACtC,UAAM,kBAAkB;AACxB,QAAI,KAAK,WAAW;AAChB,WAAK,iBAAiB,IAAI,QAAQ,OAAO,QAAQ;AAS7C,cAAM,UAAU;AAChB,cAAM,UAAU;AAChB,YAAI;AAAA,MACR,CAAC;AACD,WAAK,eAAe,KAAK,MAAM;AAC3B,aAAK,gBAAgB;AAAA,MACzB,CAAC;AAAA,IACL;AAAA,EACJ;AACJ;AA1QW;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GAJjC,UAKF;AAOS;AAAA,EADf,SAAS,EAAE,MAAM,QAAQ,CAAC;AAAA,GAXlB,UAYO;AASI;AAAA,EADnB,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GApBjB,UAqBW;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
export const getLabelFromSlot = (label, slotEl) => {
|
|
3
|
-
if (label)
|
|
4
|
-
return null;
|
|
3
|
+
if (label) return null;
|
|
5
4
|
const textContent = slotEl.assignedNodes().reduce((accumulator, node) => {
|
|
6
5
|
if (node.textContent) {
|
|
7
6
|
return accumulator + node.textContent;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["get-label-from-slot.ts"],
|
|
4
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 getLabelFromSlot = (\n label: string,\n slotEl: HTMLSlotElement\n): string | null => {\n if (label) return null;\n const textContent = slotEl\n .assignedNodes()\n .reduce((accumulator: string, node: Node) => {\n if (node.textContent) {\n return accumulator + node.textContent;\n } else {\n return accumulator;\n }\n }, '');\n if (textContent) {\n return textContent.trim();\n } else {\n return null;\n }\n};\n"],
|
|
5
|
-
"mappings": ";AAYO,aAAM,mBAAmB,CAC5B,OACA,WACgB;AAChB,MAAI
|
|
5
|
+
"mappings": ";AAYO,aAAM,mBAAmB,CAC5B,OACA,WACgB;AAChB,MAAI,MAAO,QAAO;AAClB,QAAM,cAAc,OACf,cAAc,EACd,OAAO,CAAC,aAAqB,SAAe;AACzC,QAAI,KAAK,aAAa;AAClB,aAAO,cAAc,KAAK;AAAA,IAC9B,OAAO;AACH,aAAO;AAAA,IACX;AAAA,EACJ,GAAG,EAAE;AACT,MAAI,aAAa;AACb,WAAO,YAAY,KAAK;AAAA,EAC5B,OAAO;AACH,WAAO;AAAA,EACX;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/like-anchor.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ReactiveElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
-
|
|
2
|
+
type Constructor<T = Record<string, unknown>> = {
|
|
3
3
|
new (...args: any[]): T;
|
|
4
4
|
prototype: T;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
type RenderAnchorOptions = {
|
|
7
7
|
id: string;
|
|
8
8
|
className?: string;
|
|
9
9
|
ariaHidden?: boolean;
|
package/src/like-anchor.dev.js
CHANGED
|
@@ -6,8 +6,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
6
6
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
7
|
if (decorator = decorators[i])
|
|
8
8
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
-
if (kind && result)
|
|
10
|
-
__defProp(target, key, result);
|
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
10
|
return result;
|
|
12
11
|
};
|
|
13
12
|
import {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["like-anchor.ts"],
|
|
4
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 /**\n * Causes the browser to treat the linked URL as a download.\n */\n @property()\n public download?: string;\n\n /**\n * An accessible label that describes the component.\n * It will be applied to aria-label, but not visually rendered.\n */\n @property()\n public label?: string;\n\n /**\n * The URL that the hyperlink points to.\n */\n @property()\n public href?: string;\n\n /**\n * Where to display the linked URL, as the name for a browsing context (a tab, window, or <iframe>).\n */\n @property()\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n /**\n * How much of the referrer to send when following the link.\n */\n @property()\n public referrerpolicy?:\n | 'no-referrer'\n | 'no-referrer-when-downgrade'\n | 'origin'\n | 'origin-when-cross-origin'\n | 'same-origin'\n | 'strict-origin'\n | 'strict-origin-when-cross-origin'\n | 'unsafe-url';\n\n /**\n * The relationship of the linked URL as space-separated link types.\n */\n @property()\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 referrerpolicy=${ifDefined(this.referrerpolicy)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAWA;AAAA,EACI;AAAA,OAGG;AACP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AA0BnB,gBAAS,WACZ,aACoC;AAAA,EACpC,MAAM,0BAA0B,YAAY;AAAA,IA8CjC,aAAa;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,gBAAgB;AAAA,IACpB,GAAwC;AAEpC,aAAO;AAAA,yBAEM,EAAE;AAAA,4BACC,UAAU,SAAS,CAAC;AAAA,2BACrB,UAAU,KAAK,IAAI,CAAC;AAAA,+BAChB,UAAU,KAAK,QAAQ,CAAC;AAAA,6BAC1B,UAAU,KAAK,MAAM,CAAC;AAAA,iCAClB,UAAU,KAAK,KAAK,CAAC;AAAA,sCAChB,UAAU,UAAU,CAAC;AAAA,kCACzB,UAAU,aAAa,SAAS,MAAS,CAAC;AAAA,+BAC7C,UAAU,QAAQ,CAAC;AAAA,qCACb,UAAU,KAAK,cAAc,CAAC;AAAA,0BACzC,UAAU,KAAK,GAAG,CAAC;AAAA,mBAC1B,aAAa;AAAA,IACxB;AAAA,EACJ;AAlEW;AAAA,IADN,SAAS;AAAA,KAJR,kBAKK;AAOA;AAAA,IADN,SAAS;AAAA,KAXR,kBAYK;AAMA;AAAA,IADN,SAAS;AAAA,KAjBR,kBAkBK;AAMA;AAAA,IADN,SAAS;AAAA,KAvBR,kBAwBK;AAMA;AAAA,IADN,SAAS;AAAA,KA7BR,kBA8BK;AAcA;AAAA,IADN,SAAS;AAAA,KA3CR,kBA4CK;AA4BX,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/like-anchor.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
id=${
|
|
3
|
-
class=${e(
|
|
1
|
+
"use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var n=(s,r,p,i)=>{for(var t=i>1?void 0:i?f(r,p):r,a=s.length-1,l;a>=0;a--)(l=s[a])&&(t=(i?l(r,p,t):l(t))||t);return i&&t&&u(r,p,t),t};import{html as c}from"@spectrum-web-components/base";import{property as o}from"@spectrum-web-components/base/src/decorators.js";import{ifDefined as e}from"@spectrum-web-components/base/src/directives.js";export function LikeAnchor(s){class r extends s{renderAnchor({id:i,className:t,ariaHidden:a,labelledby:l,tabindex:d,anchorContent:g=c`<slot></slot>`}){return c`<a
|
|
2
|
+
id=${i}
|
|
3
|
+
class=${e(t)}
|
|
4
4
|
href=${e(this.href)}
|
|
5
5
|
download=${e(this.download)}
|
|
6
6
|
target=${e(this.target)}
|
|
7
7
|
aria-label=${e(this.label)}
|
|
8
|
-
aria-labelledby=${e(
|
|
9
|
-
aria-hidden=${e(
|
|
10
|
-
tabindex=${e(
|
|
8
|
+
aria-labelledby=${e(l)}
|
|
9
|
+
aria-hidden=${e(a?"true":void 0)}
|
|
10
|
+
tabindex=${e(d)}
|
|
11
11
|
referrerpolicy=${e(this.referrerpolicy)}
|
|
12
12
|
rel=${e(this.rel)}
|
|
13
|
-
>${
|
|
13
|
+
>${g}</a>`}}return n([o()],r.prototype,"download",2),n([o()],r.prototype,"label",2),n([o()],r.prototype,"href",2),n([o()],r.prototype,"target",2),n([o()],r.prototype,"referrerpolicy",2),n([o()],r.prototype,"rel",2),r}
|
|
14
14
|
//# sourceMappingURL=like-anchor.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { MutationController } from "@lit-labs/observers/mutation-controller.js";
|
|
3
3
|
const slotContentIsPresent = Symbol("slotContentIsPresent");
|
|
4
4
|
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
5
|
-
var _a;
|
|
5
|
+
var _a, _b;
|
|
6
6
|
const lightDomSelectors = Array.isArray(lightDomSelector) ? lightDomSelector : [lightDomSelector];
|
|
7
|
-
class SlotPresenceObservingElement extends constructor {
|
|
7
|
+
class SlotPresenceObservingElement extends (_b = constructor, _a = slotContentIsPresent, _b) {
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
9
|
constructor(...args) {
|
|
10
10
|
super(args);
|
|
@@ -58,7 +58,6 @@ export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
_a = slotContentIsPresent;
|
|
62
61
|
return SlotPresenceObservingElement;
|
|
63
62
|
}
|
|
64
63
|
//# sourceMappingURL=observe-slot-presence.dev.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
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(`:scope > ${selector}`);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(`:scope > ${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,SAAS,0BAA0B;AAEnC,MAAM,uBAAuB,OAAO,sBAAsB;AAcnD,gBAAS,oBACZ,aACA,kBAC+C;AA9BnD;AA+BI,QAAM,oBAAoB,MAAM,QAAQ,gBAAgB,IAClD,mBACA,CAAC,gBAAgB;AAAA,EACvB,MAAM,
|
|
5
|
+
"mappings": ";AAWA,SAAS,0BAA0B;AAEnC,MAAM,uBAAuB,OAAO,sBAAsB;AAcnD,gBAAS,oBACZ,aACA,kBAC+C;AA9BnD;AA+BI,QAAM,oBAAoB,MAAM,QAAQ,gBAAgB,IAClD,mBACA,CAAC,gBAAgB;AAAA,EACvB,MAAM,sCACM,kBAmCC,2BAnCD,IAEZ;AAAA;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AA8Bd,WAAS,MAA8C,oBAAI,IAAI;AAW/D,WAAO,6BAA6B,MAAY;AAC5C,YAAI,UAAU;AACd,0BAAkB,QAAQ,CAAC,aAAa;AACpC,gBAAM,YAAY,CAAC,CAAC,KAAK,cAAc,YAAY,QAAQ,EAAE;AAC7D,gBAAM,gBACF,KAAK,oBAAoB,EAAE,IAAI,QAAQ,KAAK;AAChD,oBAAU,WAAW,kBAAkB;AACvC,eAAK,oBAAoB,EAAE;AAAA,YACvB;AAAA,YACA,CAAC,CAAC,KAAK,cAAc,YAAY,QAAQ,EAAE;AAAA,UAC/C;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;AAAA;AAAA;AAAA,IAKA,IAAW,uBAAgC;AACvC,UAAI,kBAAkB,WAAW,GAAG;AAChC,eACI,KAAK,oBAAoB,EAAE,IAAI,kBAAkB,CAAC,CAAC,KACnD;AAAA,MAER,OAAO;AACH,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,IAGO,uBAAuB,UAA2B;AACrD,UAAI,KAAK,oBAAoB,EAAE,IAAI,QAAQ,GAAG;AAC1C,eAAO,KAAK,oBAAoB,EAAE,IAAI,QAAQ,KAAK;AAAA,MACvD;AACA,YAAM,IAAI;AAAA,QACN,2BAA2B,QAAQ;AAAA,MACvC;AAAA,IACJ;AAAA,EAoBJ;AACA,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{MutationController as
|
|
1
|
+
"use strict";import{MutationController as u}from"@lit-labs/observers/mutation-controller.js";const t=Symbol("slotContentIsPresent");export function ObserveSlotPresence(l,s){var o,i;const r=Array.isArray(s)?s:[s];class a extends(i=l,o=t,i){constructor(...e){super(e);this[o]=new Map;this.managePresenceObservedSlot=()=>{let e=!1;r.forEach(n=>{const c=!!this.querySelector(`:scope > ${n}`),g=this[t].get(n)||!1;e=e||g!==c,this[t].set(n,!!this.querySelector(`:scope > ${n}`))}),e&&this.updateComplete.then(()=>{this.requestUpdate()})};new u(this,{config:{childList:!0,subtree:!0},callback:()=>{this.managePresenceObservedSlot()}}),this.managePresenceObservedSlot()}get slotContentIsPresent(){if(r.length===1)return this[t].get(r[0])||!1;throw new Error("Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.")}getSlotContentPresence(e){if(this[t].has(e))return this[t].get(e)||!1;throw new Error(`The provided selector \`${e}\` is not being observed.`)}}return a}
|
|
2
2
|
//# sourceMappingURL=observe-slot-presence.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
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(`:scope > ${selector}`);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(`:scope > ${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,OAAS,sBAAAA,MAA0B,6CAEnC,MAAMC,EAAuB,OAAO,sBAAsB,EAcnD,gBAAS,oBACZC,EACAC,EAC+C,CA9BnD,IAAAC,EA+BI,MAAMC,EAAoB,MAAM,
|
|
6
|
-
"names": ["MutationController", "slotContentIsPresent", "constructor", "lightDomSelector", "_a", "lightDomSelectors", "SlotPresenceObservingElement", "args", "changes", "selector", "nextValue", "previousValue"]
|
|
5
|
+
"mappings": "aAWA,OAAS,sBAAAA,MAA0B,6CAEnC,MAAMC,EAAuB,OAAO,sBAAsB,EAcnD,gBAAS,oBACZC,EACAC,EAC+C,CA9BnD,IAAAC,EAAAC,EA+BI,MAAMC,EAAoB,MAAM,QAAQH,CAAgB,EAClDA,EACA,CAACA,CAAgB,EACvB,MAAMI,UACMF,EAAAH,EAmCCE,EAAAH,EAnCDI,EAEZ,CAEI,eAAeG,EAAa,CACxB,MAAMA,CAAI,EA8Bd,KAASJ,GAA8C,IAAI,IAW3D,KAAO,2BAA6B,IAAY,CAC5C,IAAIK,EAAU,GACdH,EAAkB,QAASI,GAAa,CACpC,MAAMC,EAAY,CAAC,CAAC,KAAK,cAAc,YAAYD,CAAQ,EAAE,EACvDE,EACF,KAAKX,CAAoB,EAAE,IAAIS,CAAQ,GAAK,GAChDD,EAAUA,GAAWG,IAAkBD,EACvC,KAAKV,CAAoB,EAAE,IACvBS,EACA,CAAC,CAAC,KAAK,cAAc,YAAYA,CAAQ,EAAE,CAC/C,CACJ,CAAC,EACGD,GACA,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,cAAc,CACvB,CAAC,CAET,EAxDI,IAAIT,EAAmB,KAAM,CACzB,OAAQ,CACJ,UAAW,GACX,QAAS,EACb,EACA,SAAU,IAAM,CACZ,KAAK,2BAA2B,CACpC,CACJ,CAAC,EAED,KAAK,2BAA2B,CACpC,CAKA,IAAW,sBAAgC,CACvC,GAAIM,EAAkB,SAAW,EAC7B,OACI,KAAKL,CAAoB,EAAE,IAAIK,EAAkB,CAAC,CAAC,GACnD,GAGJ,MAAM,IAAI,MACN,8GACJ,CAER,CAGO,uBAAuBI,EAA2B,CACrD,GAAI,KAAKT,CAAoB,EAAE,IAAIS,CAAQ,EACvC,OAAO,KAAKT,CAAoB,EAAE,IAAIS,CAAQ,GAAK,GAEvD,MAAM,IAAI,MACN,2BAA2BA,CAAQ,2BACvC,CACJ,CAoBJ,CACA,OAAOH,CACX",
|
|
6
|
+
"names": ["MutationController", "slotContentIsPresent", "constructor", "lightDomSelector", "_a", "_b", "lightDomSelectors", "SlotPresenceObservingElement", "args", "changes", "selector", "nextValue", "previousValue"]
|
|
7
7
|
}
|
|
@@ -6,8 +6,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
6
6
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
7
|
if (decorator = decorators[i])
|
|
8
8
|
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
-
if (kind && result)
|
|
10
|
-
__defProp(target, key, result);
|
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
10
|
return result;
|
|
12
11
|
};
|
|
13
12
|
import {
|
|
@@ -17,11 +16,11 @@ import {
|
|
|
17
16
|
import { MutationController } from "@lit-labs/observers/mutation-controller.js";
|
|
18
17
|
const assignedNodesList = Symbol("assignedNodes");
|
|
19
18
|
export function ObserveSlotText(constructor, slotName, excludedSelectors = []) {
|
|
20
|
-
var _a;
|
|
19
|
+
var _a, _b;
|
|
21
20
|
const notExcluded = (el) => (selector) => {
|
|
22
21
|
return el.matches(selector);
|
|
23
22
|
};
|
|
24
|
-
class SlotTextObservingElement extends constructor {
|
|
23
|
+
class SlotTextObservingElement extends (_b = constructor, _a = assignedNodesList, _b) {
|
|
25
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
25
|
constructor(...args) {
|
|
27
26
|
super(args);
|
|
@@ -42,8 +41,7 @@ export function ObserveSlotText(constructor, slotName, excludedSelectors = []) {
|
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
43
|
manageTextObservedSlot() {
|
|
45
|
-
if (!this[assignedNodesList])
|
|
46
|
-
return;
|
|
44
|
+
if (!this[assignedNodesList]) return;
|
|
47
45
|
const assignedNodes = [...this[assignedNodesList]].filter(
|
|
48
46
|
(currentNode) => {
|
|
49
47
|
const node = currentNode;
|
|
@@ -83,7 +81,6 @@ export function ObserveSlotText(constructor, slotName, excludedSelectors = []) {
|
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
|
-
_a = assignedNodesList;
|
|
87
84
|
__decorateClass([
|
|
88
85
|
property({ type: Boolean, attribute: false })
|
|
89
86
|
], SlotTextObservingElement.prototype, "slotHasContent", 2);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.ts"],
|
|
4
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 excludedSelectors: string[] = []\n): T & Constructor<SlotTextObservingInterface> {\n const notExcluded = (el: HTMLElement) => (selector: string) => {\n return el.matches(selector);\n };\n\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({\n slot: slotName,\n flatten: true,\n })\n private [assignedNodesList]!: NodeListOf<HTMLElement>;\n\n public manageTextObservedSlot(): void {\n if (!this[assignedNodesList]) return;\n const assignedNodes = [...this[assignedNodesList]].filter(\n (currentNode) => {\n const node = currentNode as HTMLElement;\n if (node.tagName) {\n return !excludedSelectors.some(notExcluded(node));\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((currentNode) => {\n const node = currentNode as HTMLElement;\n if (node.tagName) {\n const excluded = excludedSelectors.some(\n notExcluded(node)\n );\n return !excluded\n ? // This pass happens at element upgrade and before slot rendering.\n // Confirm it would exisit in a targeted slot if there was one supplied.\n slotName\n ? node.getAttribute('slot') === slotName\n : !node.hasAttribute('slot')\n : false;\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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAYA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,0BAA0B;AAEnC,MAAM,oBAAoB,OAAO,eAAe;AAazC,gBAAS,gBACZ,aACA,UACA,oBAA8B,CAAC,GACY;AAnC/C;AAoCI,QAAM,cAAc,CAAC,OAAoB,CAAC,aAAqB;AAC3D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AI;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;AAtDW;AAAA,IADN,SAAS,EAAE,MAAM,SAAS,WAAW,MAAM,CAAC;AAAA,KAxB3C,yBAyBK;AAME;AAAA,IAJR,mBAAmB;AAAA,MAChB,MAAM;AAAA,MACN,SAAS;AAAA,IACb,CAAC;AAAA,KA9BC,yBA+BO;AAiDb,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/observe-slot-text.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var u=(c,e,s,o)=>{for(var t=o>1?void 0:o?x(e,s):e,a=c.length-1,i;a>=0;a--)(i=c[a])&&(t=(o?i(e,s,t):i(t))||t);return o&&t&&h(e,s,t),t};import{property as T,queryAssignedNodes as b}from"@spectrum-web-components/base/src/decorators.js";import{MutationController as v}from"@lit-labs/observers/mutation-controller.js";const p=Symbol("assignedNodes");export function ObserveSlotText(c,e,s=[]){var a,i;const o=f=>m=>f.matches(m);class t extends(i=c,a=p,i){constructor(...n){super(n);this.slotHasContent=!1;new v(this,{config:{characterData:!0,subtree:!0},callback:d=>{for(const r of d)if(r.type==="characterData"){this.manageTextObservedSlot();return}}})}manageTextObservedSlot(){if(!this[p])return;const n=[...this[p]].filter(d=>{const r=d;return r.tagName?!s.some(o(r)):r.textContent?r.textContent.trim():!1});this.slotHasContent=n.length>0}update(n){if(!this.hasUpdated){const{childNodes:d}=this,r=[...d].filter(g=>{const l=g;return l.tagName?s.some(o(l))?!1:e?l.getAttribute("slot")===e:!l.hasAttribute("slot"):l.textContent?l.textContent.trim():!1});this.slotHasContent=r.length>0}super.update(n)}firstUpdated(n){super.firstUpdated(n),this.updateComplete.then(()=>{this.manageTextObservedSlot()})}}return u([T({type:Boolean,attribute:!1})],t.prototype,"slotHasContent",2),u([b({slot:e,flatten:!0})],t.prototype,a,2),t}
|
|
2
2
|
//# sourceMappingURL=observe-slot-text.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.ts"],
|
|
4
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 excludedSelectors: string[] = []\n): T & Constructor<SlotTextObservingInterface> {\n const notExcluded = (el: HTMLElement) => (selector: string) => {\n return el.matches(selector);\n };\n\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({\n slot: slotName,\n flatten: true,\n })\n private [assignedNodesList]!: NodeListOf<HTMLElement>;\n\n public manageTextObservedSlot(): void {\n if (!this[assignedNodesList]) return;\n const assignedNodes = [...this[assignedNodesList]].filter(\n (currentNode) => {\n const node = currentNode as HTMLElement;\n if (node.tagName) {\n return !excludedSelectors.some(notExcluded(node));\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((currentNode) => {\n const node = currentNode as HTMLElement;\n if (node.tagName) {\n const excluded = excludedSelectors.some(\n notExcluded(node)\n );\n return !excluded\n ? // This pass happens at element upgrade and before slot rendering.\n // Confirm it would exisit in a targeted slot if there was one supplied.\n slotName\n ? node.getAttribute('slot') === slotName\n : !node.hasAttribute('slot')\n : false;\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": "qNAYA,OACI,YAAAA,EACA,sBAAAC,MACG,kDACP,OAAS,sBAAAC,MAA0B,6CAEnC,MAAMC,EAAoB,OAAO,eAAe,EAazC,gBAAS,gBACZC,EACAC,EACAC,EAA8B,CAAC,EACY,CAnC/C,IAAAC,EAoCI,MAAMC,EAAeC,GAAqBC,GAC/BD,EAAG,QAAQC,CAAQ,EAG9B,MAAMC,
|
|
6
|
-
"names": ["property", "queryAssignedNodes", "MutationController", "assignedNodesList", "constructor", "slotName", "excludedSelectors", "_a", "notExcluded", "el", "selector", "SlotTextObservingElement", "args", "mutationsList", "mutation", "assignedNodes", "currentNode", "node", "changedProperties", "childNodes", "textNodes", "__decorateClass"]
|
|
5
|
+
"mappings": "qNAYA,OACI,YAAAA,EACA,sBAAAC,MACG,kDACP,OAAS,sBAAAC,MAA0B,6CAEnC,MAAMC,EAAoB,OAAO,eAAe,EAazC,gBAAS,gBACZC,EACAC,EACAC,EAA8B,CAAC,EACY,CAnC/C,IAAAC,EAAAC,EAoCI,MAAMC,EAAeC,GAAqBC,GAC/BD,EAAG,QAAQC,CAAQ,EAG9B,MAAMC,UACMJ,EAAAJ,EA8BCG,EAAAJ,EA9BDK,EAEZ,CAEI,eAAeK,EAAa,CACxB,MAAMA,CAAI,EAmBd,KAAO,eAAiB,GAjBpB,IAAIX,EAAmB,KAAM,CACzB,OAAQ,CACJ,cAAe,GACf,QAAS,EACb,EACA,SAAWY,GAAyC,CAChD,UAAWC,KAAYD,EACnB,GAAIC,EAAS,OAAS,gBAAiB,CACnC,KAAK,uBAAuB,EAC5B,MACJ,CAER,CACJ,CAAC,CACL,CAWO,wBAA+B,CAClC,GAAI,CAAC,KAAKZ,CAAiB,EAAG,OAC9B,MAAMa,EAAgB,CAAC,GAAG,KAAKb,CAAiB,CAAC,EAAE,OAC9Cc,GAAgB,CACb,MAAMC,EAAOD,EACb,OAAIC,EAAK,QACE,CAACZ,EAAkB,KAAKG,EAAYS,CAAI,CAAC,EAE7CA,EAAK,YAAcA,EAAK,YAAY,KAAK,EAAI,EACxD,CACJ,EACA,KAAK,eAAiBF,EAAc,OAAS,CACjD,CAEmB,OAAOG,EAAyC,CAC/D,GAAI,CAAC,KAAK,WAAY,CAClB,KAAM,CAAE,WAAAC,CAAW,EAAI,KACjBC,EAAY,CAAC,GAAGD,CAAU,EAAE,OAAQH,GAAgB,CACtD,MAAMC,EAAOD,EACb,OAAIC,EAAK,QACYZ,EAAkB,KAC/BG,EAAYS,CAAI,CACpB,EAOM,GAHAb,EACIa,EAAK,aAAa,MAAM,IAAMb,EAC9B,CAACa,EAAK,aAAa,MAAM,EAGhCA,EAAK,YAAcA,EAAK,YAAY,KAAK,EAAI,EACxD,CAAC,EACD,KAAK,eAAiBG,EAAU,OAAS,CAC7C,CACA,MAAM,OAAOF,CAAiB,CAClC,CAEmB,aACfA,EACI,CACJ,MAAM,aAAaA,CAAiB,EACpC,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,uBAAuB,CAChC,CAAC,CACL,CACJ,CAtDW,OAAAG,EAAA,CADNtB,EAAS,CAAE,KAAM,QAAS,UAAW,EAAM,CAAC,GAxB3CY,EAyBK,8BAMEU,EAAA,CAJRrB,EAAmB,CAChB,KAAMI,EACN,QAAS,EACb,CAAC,GA9BCO,EA+BO,UAAAL,EAAA,GAiDNK,CACX",
|
|
6
|
+
"names": ["property", "queryAssignedNodes", "MutationController", "assignedNodesList", "constructor", "slotName", "excludedSelectors", "_a", "_b", "notExcluded", "el", "selector", "SlotTextObservingElement", "args", "mutationsList", "mutation", "assignedNodes", "currentNode", "node", "changedProperties", "childNodes", "textNodes", "__decorateClass"]
|
|
7
7
|
}
|