@spectrum-web-components/shared 0.15.8-overlay.18 → 0.30.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/package.json +4 -4
- package/src/first-focusable-in.d.ts +0 -1
- package/src/first-focusable-in.dev.js +0 -6
- package/src/first-focusable-in.dev.js.map +2 -2
- package/src/first-focusable-in.js +1 -1
- package/src/first-focusable-in.js.map +3 -3
- package/src/focus-visible.js.map +1 -1
- package/src/focusable.js.map +1 -1
- package/src/get-deep-element-from-point.js.map +1 -1
- package/src/observe-slot-presence.dev.js +1 -1
- 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 +1 -1
- package/src/observe-slot-text.dev.js +1 -1
- 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/src/reparent-children.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"lit-html"
|
|
89
89
|
],
|
|
90
90
|
"dependencies": {
|
|
91
|
-
"@lit-labs/observers": "^
|
|
92
|
-
"@spectrum-web-components/base": "^0.
|
|
91
|
+
"@lit-labs/observers": "^2.0.0",
|
|
92
|
+
"@spectrum-web-components/base": "^0.30.0",
|
|
93
93
|
"focus-visible": "^5.1.0"
|
|
94
94
|
},
|
|
95
95
|
"types": "./src/index.d.ts",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"sideEffects": [
|
|
98
98
|
"./**/*.dev.js"
|
|
99
99
|
],
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "e34a26bf2bbea5f60a5e415e0f12c97654f0e20d"
|
|
101
101
|
}
|
|
@@ -6,10 +6,4 @@ export const firstFocusableIn = (root) => {
|
|
|
6
6
|
);
|
|
7
7
|
return firstFocusable;
|
|
8
8
|
};
|
|
9
|
-
export const firstFocusableSlottedIn = (root) => {
|
|
10
|
-
const firstFocusable = root.assignedElements().find(
|
|
11
|
-
(element) => element.matches(firstFocusableSelector)
|
|
12
|
-
);
|
|
13
|
-
return firstFocusable;
|
|
14
|
-
};
|
|
15
9
|
//# sourceMappingURL=first-focusable-in.dev.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["first-focusable-in.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n
|
|
5
|
-
"mappings": ";AAcA,MAAM,yBACF;AAEG,aAAM,mBAAmB,CAC5B,SACyB;AACzB,QAAM,iBAAiB,KAAK;AAAA,IACxB;AAAA,EACJ;AACA,SAAO;AACX;
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n"],
|
|
5
|
+
"mappings": ";AAcA,MAAM,yBACF;AAEG,aAAM,mBAAmB,CAC5B,SACyB;AACzB,QAAM,iBAAiB,KAAK;AAAA,IACxB;AAAA,EACJ;AACA,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e='button:not([tabindex="-1"]), [href]:not([tabindex="-1"]), input:not([tabindex="-1"]), select:not([tabindex="-1"]), textarea:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [focusable]:not([tabindex="-1"])';export const firstFocusableIn=t=>t.querySelector(e)
|
|
1
|
+
"use strict";const e='button:not([tabindex="-1"]), [href]:not([tabindex="-1"]), input:not([tabindex="-1"]), select:not([tabindex="-1"]), textarea:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [focusable]:not([tabindex="-1"])';export const firstFocusableIn=t=>t.querySelector(e);
|
|
2
2
|
//# sourceMappingURL=first-focusable-in.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["first-focusable-in.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n
|
|
5
|
-
"mappings": "aAcA,MAAMA,EACF,sNAEG,aAAM,iBACTC,GAEuBA,EAAK,cACxBD,CACJ
|
|
6
|
-
"names": ["firstFocusableSelector", "root"
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { SpectrumElement } from '@spectrum-web-components/base';\n\nconst firstFocusableSelector =\n 'button:not([tabindex=\"-1\"]), [href]:not([tabindex=\"-1\"]), input:not([tabindex=\"-1\"]), select:not([tabindex=\"-1\"]), textarea:not([tabindex=\"-1\"]), [tabindex]:not([tabindex=\"-1\"]), [focusable]:not([tabindex=\"-1\"])';\n\nexport const firstFocusableIn = (\n root: HTMLElement | ShadowRoot\n): SpectrumElement | null => {\n const firstFocusable = root.querySelector(\n firstFocusableSelector\n ) as SpectrumElement;\n return firstFocusable;\n};\n"],
|
|
5
|
+
"mappings": "aAcA,MAAMA,EACF,sNAEG,aAAM,iBACTC,GAEuBA,EAAK,cACxBD,CACJ",
|
|
6
|
+
"names": ["firstFocusableSelector", "root"]
|
|
7
7
|
}
|
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,EAAP,CACED,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,
|
|
5
|
+
"mappings": "aAkCA,IAAIA,EAAkB,GAEtB,GAAI,CACA,SAAS,KAAK,cAAc,gBAAgB,CAChD,OAASC,EAAP,CACED,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,EAIJ,MAAO,IAAM,CAAC,CAClB,EAEMC,EAA2B,OAAO,yBAAyB,EAKjE,MAAMC,UAAgCN,CAAW,CAAjD,kCACI,KAASC,GACL,KAIK,mBAA0B,CAC/B,MAAM,mBAAqB,MAAM,kBAAkB,EAC9CH,GACD,sBAAsB,IAAM,CACpB,KAAKO,CAAwB,GAAK,OAClC,KAAKA,CAAwB,EACzBH,EAAuB,IAAI,EAEvC,CAAC,CAET,CAES,sBAA6B,CAClC,MAAM,sBAAwB,MAAM,qBAAqB,EAGpDJ,GACD,sBAAsB,IAAM,CACpB,KAAKO,CAAwB,GAAK,OAElC,KAAKA,CAAwB,EAAG,EAChC,KAAKA,CAAwB,EAAI,KAEzC,CAAC,CAET,CACJ,CAzJJ,OA0HiBJ,EAAAI,EAiCNC,CACX",
|
|
6
6
|
"names": ["hasFocusVisible", "error", "SuperClass", "_a", "coordinateWithPolyfill", "instance", "coordinationHandler", "$endPolyfillCoordination", "FocusVisibleCoordinator"]
|
|
7
7
|
}
|
package/src/focusable.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.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 = -1;\n\n private onPointerdownManagementOfTabIndex(): void {\n if (this.tabIndex === -1) {\n this.tabIndex = 0;\n this.focus({ preventScroll: true });\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 if (this._recentlyConnected) {\n this._recentlyConnected = false;\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 }\n return complete;\n }\n\n private _recentlyConnected = false;\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this._recentlyConnected = true;\n this.updateComplete.then(() => {\n this.manageAutoFocus();\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "qNAWA,OAAyB,mBAAAA,MAAuB,gCAChD,OAAS,YAAAC,MAAgB,kDAEzB,OAAS,6BAAAC,MAAiC,qBAI1C,SAASC,GAA2B,CAChC,OAAO,IAAI,QAASC,GAAQ,sBAAsB,IAAMA,EAAI,CAAC,CAAC,CAClE,CAQO,aAAM,kBAAkBF,EAA0BF,CAAe,CAAE,CAAnE,kCAKH,KAAO,SAAW,GAOlB,KAAgB,UAAY,GAqF5B,KAAQ,UAAY,GAqBpB,KAAQ,qBAAuB,GA0I/B,KAAQ,mBAAqB,GA3O7B,IAAoB,UAAmB,CACnC,GAAI,KAAK,eAAiB,KAAM,CAC5B,MAAMK,EAAW,KAAK,aAAa,UAAU,EACvC,OAAO,KAAK,aAAa,UAAU,CAAC,EACpC,IACN,OAAQ,MAAMA,CAAQ,EAAe,GAAXA,
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["SpectrumElement", "property", "FocusVisiblePolyfillMixin", "nextFrame", "res", "tabindex", "tabIndexAttribute", "tabIndex", "options", "focusElement", "changes", "changedProperties", "disabled", "oldDisabled", "canSetDisabled", "complete", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["get-deep-element-from-point.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 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,wBAA0B,CACnCA,EACAC,IACiB,CACjB,IAAIC,EAAS,SAAS,iBAAiBF,EAAGC,CAAC,EAC3C,KAAOC,GAAA,MAAAA,EAAQ,YAAY,CACvB,MAAMC,EACFD,EAAO,WAGT,iBAAiBF,EAAGC,CAAC,EACvB,GAAI,CAACE,GAAeA,IAAgBD,EAChC,MAEJA,EAASC,
|
|
5
|
+
"mappings": "aAYO,aAAM,wBAA0B,CACnCA,EACAC,IACiB,CACjB,IAAIC,EAAS,SAAS,iBAAiBF,EAAGC,CAAC,EAC3C,KAAOC,GAAA,MAAAA,EAAQ,YAAY,CACvB,MAAMC,EACFD,EAAO,WAGT,iBAAiBF,EAAGC,CAAC,EACvB,GAAI,CAACE,GAAeA,IAAgBD,EAChC,MAEJA,EAASC,EAEb,OAAOD,CACX",
|
|
6
6
|
"names": ["x", "y", "target", "innerTarget"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { MutationController } from "@lit-labs/observers/
|
|
2
|
+
import { MutationController } from "@lit-labs/observers/mutation-controller.js";
|
|
3
3
|
const slotContentIsPresent = Symbol("slotContentIsPresent");
|
|
4
4
|
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
5
5
|
var _a;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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/
|
|
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
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;AACvB,QAAM,qCACM,YAEZ;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,QAAQ;AAC/C,gBAAM,gBACF,KAAK,oBAAoB,EAAE,IAAI,QAAQ,KAAK;AAChD,oBAAU,WAAW,kBAAkB;AACvC,eAAK,oBAAoB,EAAE;AAAA,YACvB;AAAA,YACA,CAAC,CAAC,KAAK,cAAc,QAAQ;AAAA,UACjC;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;AAAA,MAC/B;AAAA,IACJ;AAAA,EAoBJ;AAnGJ,EAsEiB;AA8Bb,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{MutationController as g}from"@lit-labs/observers/
|
|
1
|
+
"use strict";import{MutationController as g}from"@lit-labs/observers/mutation-controller.js";const t=Symbol("slotContentIsPresent");export function ObserveSlotPresence(o,r){var l;const s=Array.isArray(r)?r:[r];class i extends o{constructor(...e){super(e);this[l]=new Map;this.managePresenceObservedSlot=()=>{let e=!1;s.forEach(n=>{const a=!!this.querySelector(n),c=this[t].get(n)||!1;e=e||c!==a,this[t].set(n,!!this.querySelector(n))}),e&&this.updateComplete.then(()=>{this.requestUpdate()})};new g(this,{config:{childList:!0,subtree:!0},callback:()=>{this.managePresenceObservedSlot()}}),this.managePresenceObservedSlot()}get slotContentIsPresent(){if(s.length===1)return this[t].get(s[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 l=t,i}
|
|
2
2
|
//# sourceMappingURL=observe-slot-presence.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
|
-
"sourcesContent": ["/*\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/
|
|
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
5
|
"mappings": "aAWA,OAAS,sBAAAA,MAA0B,6CAEnC,MAAMC,EAAuB,OAAO,sBAAsB,EAcnD,gBAAS,oBACZC,EACAC,EAC+C,CA9BnD,IAAAC,EA+BI,MAAMC,EAAoB,MAAM,QAAQF,CAAgB,EAClDA,EACA,CAACA,CAAgB,EACvB,MAAMG,UACMJ,CAEZ,CAEI,eAAeK,EAAa,CACxB,MAAMA,CAAI,EA8Bd,KAASH,GAA8C,IAAI,IAW3D,KAAO,2BAA6B,IAAY,CAC5C,IAAII,EAAU,GACdH,EAAkB,QAASI,GAAa,CACpC,MAAMC,EAAY,CAAC,CAAC,KAAK,cAAcD,CAAQ,EACzCE,EACF,KAAKV,CAAoB,EAAE,IAAIQ,CAAQ,GAAK,GAChDD,EAAUA,GAAWG,IAAkBD,EACvC,KAAKT,CAAoB,EAAE,IACvBQ,EACA,CAAC,CAAC,KAAK,cAAcA,CAAQ,CACjC,CACJ,CAAC,EACGD,GACA,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,cAAc,CACvB,CAAC,CAET,EAxDI,IAAIR,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,GAAIK,EAAkB,SAAW,EAC7B,OACI,KAAKJ,CAAoB,EAAE,IAAII,EAAkB,CAAC,CAAC,GACnD,GAGJ,MAAM,IAAI,MACN,8GACJ,CAER,CAGO,uBAAuBI,EAA2B,CACrD,GAAI,KAAKR,CAAoB,EAAE,IAAIQ,CAAQ,EACvC,OAAO,KAAKR,CAAoB,EAAE,IAAIQ,CAAQ,GAAK,GAEvD,MAAM,IAAI,MACN,2BAA2BA,4BAC/B,CACJ,CAoBJ,CAnGJ,OAsEiBL,EAAAH,EA8BNK,CACX",
|
|
6
6
|
"names": ["MutationController", "slotContentIsPresent", "constructor", "lightDomSelector", "_a", "lightDomSelectors", "SlotPresenceObservingElement", "args", "changes", "selector", "nextValue", "previousValue"]
|
|
7
7
|
}
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
property,
|
|
15
15
|
queryAssignedNodes
|
|
16
16
|
} from "@spectrum-web-components/base/src/decorators.js";
|
|
17
|
-
import { MutationController } from "@lit-labs/observers/
|
|
17
|
+
import { MutationController } from "@lit-labs/observers/mutation-controller.js";
|
|
18
18
|
const assignedNodesList = Symbol("assignedNodes");
|
|
19
19
|
export function ObserveSlotText(constructor, slotName) {
|
|
20
20
|
var _a;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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/
|
|
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
5
|
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,0BAA0B;AAEnC,MAAM,oBAAoB,OAAO,eAAe;AAazC,gBAAS,gBACZ,aACA,UAC2C;AAlC/C;AAmCI,QAAM,iCACM,YAEZ;AAAA;AAAA,IAEI,eAAe,MAAa;AACxB,YAAM,IAAI;AAmBd,WAAO,iBAAiB;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,iBAAiB;AAAG;AAC9B,YAAM,gBAAgB,CAAC,GAAG,KAAK,iBAAiB,CAAC,EAAE;AAAA,QAC/C,CAAC,SAAS;AACN,cAAK,KAAqB,SAAS;AAC/B,mBAAO;AAAA,UACX;AACA,iBAAO,KAAK,cAAc,KAAK,YAAY,KAAK,IAAI;AAAA,QACxD;AAAA,MACJ;AACA,WAAK,iBAAiB,cAAc,SAAS;AAAA,IACjD;AAAA,IAEmB,OAAO,mBAAyC;AAC/D,UAAI,CAAC,KAAK,YAAY;AAClB,cAAM,EAAE,WAAW,IAAI;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,IADN,SAAS,EAAE,MAAM,SAAS,WAAW,MAAM,CAAC;AAAA,KAxB3C,yBAyBK;AAGE;AAAA,IADR,mBAAmB,UAAU,IAAI;AAAA,KA3BhC,yBA4BO;AAyCb,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/observe-slot-text.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var c=(i,e,s,n)=>{for(var r=n>1?void 0:n?f(e,s):e,l=i.length-1,t;l>=0;l--)(t=i[l])&&(r=(n?t(e,s,r):t(r))||r);return n&&r&&p(e,s,r),r};import{property as m,queryAssignedNodes as g}from"@spectrum-web-components/base/src/decorators.js";import{MutationController as h}from"@lit-labs/observers/
|
|
1
|
+
"use strict";var p=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var c=(i,e,s,n)=>{for(var r=n>1?void 0:n?f(e,s):e,l=i.length-1,t;l>=0;l--)(t=i[l])&&(r=(n?t(e,s,r):t(r))||r);return n&&r&&p(e,s,r),r};import{property as m,queryAssignedNodes as g}from"@spectrum-web-components/base/src/decorators.js";import{MutationController as h}from"@lit-labs/observers/mutation-controller.js";const d=Symbol("assignedNodes");export function ObserveSlotText(i,e){var n;class s extends i{constructor(...t){super(t);this.slotHasContent=!1;new h(this,{config:{characterData:!0,subtree:!0},callback:o=>{for(const u of o)if(u.type==="characterData"){this.manageTextObservedSlot();return}}})}manageTextObservedSlot(){if(!this[d])return;const t=[...this[d]].filter(o=>o.tagName?!0:o.textContent?o.textContent.trim():!1);this.slotHasContent=t.length>0}update(t){if(!this.hasUpdated){const{childNodes:o}=this,u=[...o].filter(a=>a.tagName?e?a.getAttribute("slot")===e:!a.hasAttribute("slot"):a.textContent?a.textContent.trim():!1);this.slotHasContent=u.length>0}super.update(t)}firstUpdated(t){super.firstUpdated(t),this.updateComplete.then(()=>{this.manageTextObservedSlot()})}}return n=d,c([m({type:Boolean,attribute:!1})],s.prototype,"slotHasContent",2),c([g(e,!0)],s.prototype,n,2),s}
|
|
2
2
|
//# sourceMappingURL=observe-slot-text.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.ts"],
|
|
4
|
-
"sourcesContent": ["/*\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/
|
|
5
|
-
"mappings": "qNAYA,OACI,YAAAA,EACA,sBAAAC,MACG,kDACP,OAAS,sBAAAC,MAA0B,6CAEnC,MAAMC,EAAoB,OAAO,eAAe,EAazC,gBAAS,gBACZC,EACAC,EAC2C,CAlC/C,IAAAC,EAmCI,MAAMC,UACMH,CAEZ,CAEI,eAAeI,EAAa,CACxB,MAAMA,CAAI,EAmBd,KAAO,eAAiB,GAjBpB,IAAIN,EAAmB,KAAM,CACzB,OAAQ,CACJ,cAAe,GACf,QAAS,EACb,EACA,SAAWO,GAAyC,CAChD,UAAWC,KAAYD,EACnB,GAAIC,EAAS,OAAS,gBAAiB,CACnC,KAAK,uBAAuB,EAC5B,
|
|
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": "qNAYA,OACI,YAAAA,EACA,sBAAAC,MACG,kDACP,OAAS,sBAAAC,MAA0B,6CAEnC,MAAMC,EAAoB,OAAO,eAAe,EAazC,gBAAS,gBACZC,EACAC,EAC2C,CAlC/C,IAAAC,EAmCI,MAAMC,UACMH,CAEZ,CAEI,eAAeI,EAAa,CACxB,MAAMA,CAAI,EAmBd,KAAO,eAAiB,GAjBpB,IAAIN,EAAmB,KAAM,CACzB,OAAQ,CACJ,cAAe,GACf,QAAS,EACb,EACA,SAAWO,GAAyC,CAChD,UAAWC,KAAYD,EACnB,GAAIC,EAAS,OAAS,gBAAiB,CACnC,KAAK,uBAAuB,EAC5B,OAGZ,CACJ,CAAC,CACL,CAQO,wBAA+B,CAClC,GAAI,CAAC,KAAKP,CAAiB,EAAG,OAC9B,MAAMQ,EAAgB,CAAC,GAAG,KAAKR,CAAiB,CAAC,EAAE,OAC9CS,GACQA,EAAqB,QACf,GAEJA,EAAK,YAAcA,EAAK,YAAY,KAAK,EAAI,EAE5D,EACA,KAAK,eAAiBD,EAAc,OAAS,CACjD,CAEmB,OAAOE,EAAyC,CAC/D,GAAI,CAAC,KAAK,WAAY,CAClB,KAAM,CAAE,WAAAC,CAAW,EAAI,KACjBC,EAAY,CAAC,GAAGD,CAAU,EAAE,OAAQF,GACjCA,EAAqB,QACfP,EACAO,EAAqB,aAAa,MAAM,IACrCP,EACJ,CAAEO,EAAqB,aAAa,MAAM,EAE7CA,EAAK,YAAcA,EAAK,YAAY,KAAK,EAAI,EACvD,EACD,KAAK,eAAiBG,EAAU,OAAS,EAE7C,MAAM,OAAOF,CAAiB,CAClC,CAEmB,aACfA,EACI,CACJ,MAAM,aAAaA,CAAiB,EACpC,KAAK,eAAe,KAAK,IAAM,CAC3B,KAAK,uBAAuB,CAChC,CAAC,CACL,CACJ,CAvGJ,OA+DiBP,EAAAH,EAHFa,EAAA,CADNhB,EAAS,CAAE,KAAM,QAAS,UAAW,EAAM,CAAC,GAxB3CO,EAyBK,8BAGES,EAAA,CADRf,EAAmBI,EAAU,EAAI,GA3BhCE,EA4BO,UAAAD,EAAA,GAyCNC,CACX",
|
|
6
6
|
"names": ["property", "queryAssignedNodes", "MutationController", "assignedNodesList", "constructor", "slotName", "_a", "SlotTextObservingElement", "args", "mutationsList", "mutation", "assignedNodes", "node", "changedProperties", "childNodes", "textNodes", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["reparent-children.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*/\nfunction restoreChildren<T extends Element>(\n placeholderItems: Comment[],\n srcElements: T[],\n cleanupCallbacks: ((el: T) => void)[] = []\n): T[] {\n for (let index = 0; index < srcElements.length; ++index) {\n const srcElement = srcElements[index];\n const placeholderItem = placeholderItems[index];\n const parentElement =\n placeholderItem.parentElement || placeholderItem.getRootNode();\n if (cleanupCallbacks[index]) {\n cleanupCallbacks[index](srcElement);\n }\n if (parentElement && parentElement !== placeholderItem) {\n parentElement.replaceChild(srcElement, placeholderItem);\n }\n delete placeholderItems[index];\n }\n return srcElements;\n}\n\nexport const reparentChildren = <T extends Element>(\n srcElements: T[],\n destination: Element,\n {\n position,\n prepareCallback,\n }: {\n position: InsertPosition;\n prepareCallback?: (el: T) => ((el: T) => void) | void;\n } = { position: 'beforeend' }\n): (() => T[]) => {\n let { length } = srcElements;\n if (length === 0) {\n return () => srcElements;\n }\n\n let step = 1;\n let index = 0;\n\n if (position === 'afterbegin' || position === 'afterend') {\n step = -1;\n index = length - 1;\n }\n\n const placeholderItems = new Array<Comment>(length);\n const cleanupCallbacks = new Array<(el: T) => void>(length);\n const placeholderTemplate: Comment = document.createComment(\n 'placeholder for reparented element'\n );\n\n do {\n const srcElement = srcElements[index];\n if (prepareCallback) {\n cleanupCallbacks[index] = prepareCallback(srcElement) as (\n el: T\n ) => void;\n }\n placeholderItems[index] = placeholderTemplate.cloneNode() as Comment;\n\n const parentElement =\n srcElement.parentElement || srcElement.getRootNode();\n if (parentElement && parentElement !== srcElement) {\n parentElement.replaceChild(placeholderItems[index], srcElement);\n }\n destination.insertAdjacentElement(position, srcElement);\n\n index += step;\n } while (--length > 0);\n\n return function (): T[] {\n return restoreChildren<T>(\n placeholderItems,\n srcElements,\n cleanupCallbacks\n );\n };\n};\n"],
|
|
5
|
-
"mappings": "aAWA,SAASA,EACLC,EACAC,EACAC,EAAwC,CAAC,EACtC,CACH,QAASC,EAAQ,EAAGA,EAAQF,EAAY,OAAQ,EAAEE,EAAO,CACrD,MAAMC,EAAaH,EAAYE,CAAK,EAC9BE,EAAkBL,EAAiBG,CAAK,EACxCG,EACFD,EAAgB,eAAiBA,EAAgB,YAAY,EAC7DH,EAAiBC,CAAK,GACtBD,EAAiBC,CAAK,EAAEC,CAAU,EAElCE,GAAiBA,IAAkBD,GACnCC,EAAc,aAAaF,EAAYC,CAAe,EAE1D,OAAOL,EAAiBG,CAAK,
|
|
5
|
+
"mappings": "aAWA,SAASA,EACLC,EACAC,EACAC,EAAwC,CAAC,EACtC,CACH,QAASC,EAAQ,EAAGA,EAAQF,EAAY,OAAQ,EAAEE,EAAO,CACrD,MAAMC,EAAaH,EAAYE,CAAK,EAC9BE,EAAkBL,EAAiBG,CAAK,EACxCG,EACFD,EAAgB,eAAiBA,EAAgB,YAAY,EAC7DH,EAAiBC,CAAK,GACtBD,EAAiBC,CAAK,EAAEC,CAAU,EAElCE,GAAiBA,IAAkBD,GACnCC,EAAc,aAAaF,EAAYC,CAAe,EAE1D,OAAOL,EAAiBG,CAAK,EAEjC,OAAOF,CACX,CAEO,aAAM,iBAAmB,CAC5BA,EACAM,EACA,CACI,SAAAC,EACA,gBAAAC,CACJ,EAGI,CAAE,SAAU,WAAY,IACd,CACd,GAAI,CAAE,OAAAC,CAAO,EAAIT,EACjB,GAAIS,IAAW,EACX,MAAO,IAAMT,EAGjB,IAAIU,EAAO,EACPR,EAAQ,GAERK,IAAa,cAAgBA,IAAa,cAC1CG,EAAO,GACPR,EAAQO,EAAS,GAGrB,MAAMV,EAAmB,IAAI,MAAeU,CAAM,EAC5CR,EAAmB,IAAI,MAAuBQ,CAAM,EACpDE,EAA+B,SAAS,cAC1C,oCACJ,EAEA,EAAG,CACC,MAAMR,EAAaH,EAAYE,CAAK,EAChCM,IACAP,EAAiBC,CAAK,EAAIM,EAAgBL,CAAU,GAIxDJ,EAAiBG,CAAK,EAAIS,EAAoB,UAAU,EAExD,MAAMN,EACFF,EAAW,eAAiBA,EAAW,YAAY,EACnDE,GAAiBA,IAAkBF,GACnCE,EAAc,aAAaN,EAAiBG,CAAK,EAAGC,CAAU,EAElEG,EAAY,sBAAsBC,EAAUJ,CAAU,EAEtDD,GAASQ,QACJ,EAAED,EAAS,GAEpB,OAAO,UAAiB,CACpB,OAAOX,EACHC,EACAC,EACAC,CACJ,CACJ,CACJ",
|
|
6
6
|
"names": ["restoreChildren", "placeholderItems", "srcElements", "cleanupCallbacks", "index", "srcElement", "placeholderItem", "parentElement", "destination", "position", "prepareCallback", "length", "step", "placeholderTemplate"]
|
|
7
7
|
}
|