@spectrum-web-components/shared 0.14.1 → 0.14.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/README.md +8 -4
- package/package.json +4 -3
- package/src/focus-visible.js.map +1 -1
- package/src/focusable.js.map +1 -1
- package/src/get-deep-element-from-point.d.ts +1 -0
- package/src/get-deep-element-from-point.js +23 -0
- package/src/get-deep-element-from-point.js.map +1 -0
- package/src/observe-slot-presence.js +25 -22
- package/src/observe-slot-presence.js.map +1 -1
- package/src/observe-slot-text.d.ts +1 -1
- package/src/observe-slot-text.js +39 -31
- package/src/observe-slot-text.js.map +1 -1
- package/test/observe-slot-presence.test.js.map +1 -1
- package/test/observe-slot-text.test.js.map +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@ import {
|
|
|
23
23
|
} from '@spectrum-web-components/shared';
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
### getDeepElementFromPoint
|
|
27
|
+
|
|
28
|
+
The `getDeepElementFromPoint` method allows you to obtain the deepest possible element at a given coordinates on the current page. The method will step into any available `shadowRoot`s until it reaches the first element with no `shadowRoot` or no children available at the given coordinates.
|
|
29
|
+
|
|
26
30
|
### Focusable
|
|
27
31
|
|
|
28
32
|
The `Focusable` subclass of `LitElement` adds some helpers method and lifecycle coverage in order to support passing focus to a container element inside of a custom element. The Focusable base class handles tabindex setting into shadowed elements automatically and is based heavily on the [aybolit delegate-focus-mixin](https://github.com/web-padawan/aybolit/blob/master/packages/core/src/mixins/delegate-focus-mixin.js).
|
|
@@ -32,14 +36,14 @@ import { Focusable } from '@spectrum-web-components/shared';
|
|
|
32
36
|
import { html } from 'lit-element';
|
|
33
37
|
|
|
34
38
|
class FocusableButton extends Focusable {
|
|
35
|
-
public static get styles(): CSSResultArray {
|
|
39
|
+
public static override get styles(): CSSResultArray {
|
|
36
40
|
return [...super.styles];
|
|
37
41
|
}
|
|
38
42
|
public get focusElement(): HTMLElement {
|
|
39
43
|
return this.shadowRoot.querySelector('#button') as HTMLElement;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
protected render(): TemplateResult {
|
|
46
|
+
protected override render(): TemplateResult {
|
|
43
47
|
return html`
|
|
44
48
|
<button
|
|
45
49
|
id="button"
|
|
@@ -75,7 +79,7 @@ class ObserveSlotPresenceElement extends ObserveSlotPresence(LitElement, '[slot=
|
|
|
75
79
|
protected get hasConditionalSlotContent() {
|
|
76
80
|
return this.slotContentIsPresent;
|
|
77
81
|
}
|
|
78
|
-
protected render(): TemplateResult {
|
|
82
|
+
protected override render(): TemplateResult {
|
|
79
83
|
return html`
|
|
80
84
|
<button
|
|
81
85
|
id="button"
|
|
@@ -107,7 +111,7 @@ import { ObserveSlotText } from '@spectrum-web-components/shared';
|
|
|
107
111
|
import { LitElement, html } from 'lit-element';
|
|
108
112
|
|
|
109
113
|
class ObserveSlotTextElement extends ObserveSlotText(LitElement, '#observing-slot') {
|
|
110
|
-
protected render(): TemplateResult {
|
|
114
|
+
protected override render(): TemplateResult {
|
|
111
115
|
return html`
|
|
112
116
|
<button
|
|
113
117
|
id="button"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/shared",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,12 +42,13 @@
|
|
|
42
42
|
"lit-html"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@
|
|
45
|
+
"@lit-labs/observers": "^1.0.1",
|
|
46
|
+
"@spectrum-web-components/base": "^0.5.8",
|
|
46
47
|
"focus-visible": "^5.1.0",
|
|
47
48
|
"tslib": "^2.0.0"
|
|
48
49
|
},
|
|
49
50
|
"types": "./src/index.d.ts",
|
|
50
51
|
"customElements": "custom-elements.json",
|
|
51
52
|
"sideEffects": false,
|
|
52
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "3be62133721efba844cd7032566a2c49ed6d9875"
|
|
53
54
|
}
|
package/src/focus-visible.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focus-visible.js","sourceRoot":"","sources":["focus-visible.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAwBF,IAAI,eAAe,GAAG,IAAI,CAAC;AAE3B,IAAI;IACA,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;CACjD;AAAC,OAAO,KAAK,EAAE;IACZ,eAAe,GAAG,KAAK,CAAC;IACxB,6DAA6D;IAC7D,aAAa;IACb,MAAM,CAAC,eAAe,CAAC,CAAC;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAGrC,UAAa,EACZ,EAAE;;IACH,MAAM,sBAAsB,GAAG,CAC3B,QAA0B,EACK,EAAE;QACjC,kEAAkE;QAClE,oEAAoE;QACpE,gCAAgC;QAChC,IACI,QAAQ,CAAC,UAAU,IAAI,IAAI;YAC3B,QAAQ,CAAC,YAAY,CAAC,uBAAuB,CAAC,EAChD;YACE,gEAAgE;YAChE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;SACnB;QAED,kEAAkE;QAClE,+BAA+B;QAC/B,IAAI,IAAI,CAAC,yBAAyB,EAAE;YAChC,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAEpD,IAAI,QAAQ,CAAC,eAAe,EAAE;gBAC1B,QAAQ,CAAC,eAAe,EAAE,CAAC;aAC9B;SACJ;aAAM;YACH,MAAM,mBAAmB,GAAG,GAAS,EAAE;gBACnC,IAAI,IAAI,CAAC,yBAAyB,IAAI,QAAQ,CAAC,UAAU,EAAE;oBACvD,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;iBACvD;gBAED,IAAI,QAAQ,CAAC,eAAe,EAA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ACrD,IAAI,CAAC,eAAe,EAAE;gBAClB,qBAAqB,CAAC,GAAG,EAAE;oBACvB,IAAI,IAAI,CAAC,wBAAwB,CAAC,IAAI,IAAI,EAAE;wBACxC,IAAI,CAAC,wBAAwB,CAAC;4BAC1B,sBAAsB,CAAC,IAAI,CAAC,CAAC;qBACpC;gBACL,CAAC,CAAC,CAAC;aACN;QACL,CAAC;QAEQ,oBAAoB;YACzB,KAAK,CAAC,oBAAoB,IAAI,KAAK,CAAC,oBAAoB,EAAE,CAAC;YAC3D,+DAA+D;YAC/D,mEAAmE;YACnE,IAAI,CAAC,eAAe,EAAE;gBAClB,qBAAqB,CAAC,GAAG,EAAE;oBACvB,IAAI,IAAI,CAAC,wBAAwB,CAAC,IAAI,IAAI,EAAE;wBACxC,oEAAoE;wBACpE,IAAI,CAAC,wBAAwB,CAAE,EAAE,CAAC;wBAClC,IAAI,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAAC;qBACzC;gBACL,CAAC,CAAC,CAAC;aACN;QACL,CAAC;KACJ;SA/BY,wBAAwB;IAiCrC,OAAO,uBAAuB,CAAC;AACnC,CAAC,CAAC","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"]}
|
package/src/focusable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"focusable.js","sourceRoot":"","sources":["focusable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAkB,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAI/D;;;;;GAKG;AACH,MAAM,OAAO,SAAU,SAAQ,yBAAyB,CAAC,eAAe,CAAC;IAAzE;;QACI;;WAEG;QAEI,aAAQ,GAAG,KAAK,CAAC;QAExB;;;WAGG;QAEI,cAAS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,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2CACnB;AAOxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CACH;AASzB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCA0B1B","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\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 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 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 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.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 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 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 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 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 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 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 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 public connectedCallback(): void {\n super.connectedCallback();\n this.updateComplete.then(() => {\n requestAnimationFrame(() => {\n this.manageAutoFocus();\n });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"focusable.js","sourceRoot":"","sources":["focusable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAkB,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAI/D;;;;;GAKG;AACH,MAAM,OAAO,SAAU,SAAQ,yBAAyB,CAAC,eAAe,CAAC;IAAzE;;QACI;;WAEG;QAEI,aAAQ,GAAG,KAAK,CAAC;QAExB;;;WAGG;QAEa,cAAS,GAAG,KAAK,CAAC;QAoF1B,cAAS,GAAG,CAAC,CAAC;QAqBd,yBAAoB,GAAG,KAAK,CAAC;IAgIzC,CAAC;IAvOG;;;;;OAKG;IAEH,IAAoB,QAAQ;QACxB,IAAI,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE;YAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;gBAC1C,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;gBACvC,CAAC,CAAC,GAAG,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3C;QACD,MAAM,iBAAiB,GAAG,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AE;YACpB,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;YACjC,IAAI,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE;gBAC5B,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;aACtD;iBAAM;gBACH,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;aACpC;YACD,MAAM,IAAI,CAAC,cAAc,CAAC;YAC1B,IAAI,cAAc,EAAE,EAAE;gBAClB,IAAI,CAAC,YAAY,CAAC,QAAQ,GAAG,KAAK,CAAC;aACtC;iBAAM;gBACH,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;aACzC;SACJ;IACL,CAAC;IAEe,iBAAiB;QAC7B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE;YAC1B,qBAAqB,CAAC,GAAG,EAAE;gBACvB,IAAI,CAAC,eAAe,EAAE,CAAC;YAC3B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAhPG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2CACnB;AAOxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;4CACM;AASlC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCA0B1B","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\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.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 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 public override connectedCallback(): void {\n super.connectedCallback();\n this.updateComplete.then(() => {\n requestAnimationFrame(() => {\n this.manageAutoFocus();\n });\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDeepElementFromPoint: (x: number, y: number) => Element | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export const getDeepElementFromPoint = (x, y) => {
|
|
13
|
+
let target = document.elementFromPoint(x, y);
|
|
14
|
+
while (target === null || target === void 0 ? void 0 : target.shadowRoot) {
|
|
15
|
+
const innerTarget = target.shadowRoot.elementFromPoint(x, y);
|
|
16
|
+
if (!innerTarget || innerTarget === target) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
target = innerTarget;
|
|
20
|
+
}
|
|
21
|
+
return target;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=get-deep-element-from-point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-deep-element-from-point.js","sourceRoot":"","sources":["get-deep-element-from-point.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACnC,CAAS,EACT,CAAS,EACK,EAAE;IAChB,IAAI,MAAM,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C,OAAO,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,EAAE;QACvB,MAAM,WAAW,GACb,MAAM,CAAC,UAGV,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,WAAW,IAAI,WAAW,KAAK,MAAM,EAAE;YACxC,MAAM;SACT;QACD,MAAM,GAAG,WAAW,CAAC;KACxB;IACD,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC","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"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const startObserving = Symbol('startObserving');
|
|
1
|
+
import { MutationController } from '@lit-labs/observers/mutation_controller.js';
|
|
3
2
|
const slotContentIsPresent = Symbol('slotContentIsPresent');
|
|
4
3
|
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
5
4
|
var _a;
|
|
@@ -7,15 +6,34 @@ export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
|
7
6
|
? lightDomSelector
|
|
8
7
|
: [lightDomSelector];
|
|
9
8
|
class SlotPresenceObservingElement extends constructor {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
constructor(...args) {
|
|
11
|
+
super(args);
|
|
12
12
|
this[_a] = new Map();
|
|
13
13
|
this.managePresenceObservedSlot = () => {
|
|
14
|
+
let changes = false;
|
|
14
15
|
lightDomSelectors.forEach((selector) => {
|
|
16
|
+
const nextValue = !!this.querySelector(selector);
|
|
17
|
+
const previousValue = this[slotContentIsPresent].get(selector) || false;
|
|
18
|
+
changes = changes || previousValue !== nextValue;
|
|
15
19
|
this[slotContentIsPresent].set(selector, !!this.querySelector(selector));
|
|
16
20
|
});
|
|
17
|
-
|
|
21
|
+
if (changes) {
|
|
22
|
+
this.updateComplete.then(() => {
|
|
23
|
+
this.requestUpdate();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
18
26
|
};
|
|
27
|
+
new MutationController(this, {
|
|
28
|
+
config: {
|
|
29
|
+
childList: true,
|
|
30
|
+
subtree: true,
|
|
31
|
+
},
|
|
32
|
+
callback: () => {
|
|
33
|
+
this.managePresenceObservedSlot();
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
this.managePresenceObservedSlot();
|
|
19
37
|
}
|
|
20
38
|
/**
|
|
21
39
|
* @private
|
|
@@ -33,25 +51,10 @@ export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
|
33
51
|
if (this[slotContentIsPresent].has(selector)) {
|
|
34
52
|
return this[slotContentIsPresent].get(selector) || false;
|
|
35
53
|
}
|
|
36
|
-
throw new Error(`The provided selector
|
|
37
|
-
}
|
|
38
|
-
[(_a = slotContentIsPresent, startObserving)]() {
|
|
39
|
-
const config = { childList: true, subtree: true };
|
|
40
|
-
if (!this[slotElementObserver]) {
|
|
41
|
-
this[slotElementObserver] = new MutationObserver(this.managePresenceObservedSlot);
|
|
42
|
-
}
|
|
43
|
-
this[slotElementObserver].observe(this, config);
|
|
44
|
-
this.managePresenceObservedSlot();
|
|
45
|
-
}
|
|
46
|
-
connectedCallback() {
|
|
47
|
-
super.connectedCallback();
|
|
48
|
-
this[startObserving]();
|
|
49
|
-
}
|
|
50
|
-
disconnectedCallback() {
|
|
51
|
-
this[slotElementObserver].disconnect();
|
|
52
|
-
super.disconnectedCallback();
|
|
54
|
+
throw new Error(`The provided selector \`${selector}\` is not being observed.`);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
57
|
+
_a = slotContentIsPresent;
|
|
55
58
|
return SlotPresenceObservingElement;
|
|
56
59
|
}
|
|
57
60
|
//# sourceMappingURL=observe-slot-presence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-slot-presence.js","sourceRoot":"","sources":["observe-slot-presence.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"observe-slot-presence.js","sourceRoot":"","sources":["observe-slot-presence.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,MAAM,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAc5D,MAAM,UAAU,mBAAmB,CAC/B,WAAc,EACd,gBAAmC;;IAEnC,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACrD,CAAC,CAAC,gBAAgB;QAClB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACzB,MAAM,4BACF,SAAQ,WAAW;QAGnB,8DAA8D;QAC9D,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,IAAI,CAAC,CAAC;YA8BR,QAAsB,GAAyB,IAAI,GAAG,EAAE,CAAC;YAW1D,+BAA0B,GAAG,GAAS,EAAE;gBAC3C,IAAI,OAAO,GAAG,KAAK,CAAC;gBACpB,iBAAiB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;oBACnC,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;oBACjD,MAAM,aAAa,GACf,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC;oBACtD,OAAO,GAAG,OAAO,IAAI,aAAa,KAAK,SAAS,CAAC;oBACjD,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAC1B,QAAQ,EACR,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CACjC,CAAC;gBACN,CAAC,CAAC,CAAC;gBACH,IAAI,OAAO,EAAE;oBACT,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE;wBAC1B,IAAI,CAAC,aAAa,EAAE,CAAC;oBACzB,CAAC,CAAC,CAAC;iBACN;YACL,CAAC,CAAC;YAxDE,IAAI,kBAAkB,CAAC,IAAI,EAAE;gBACzB,MAAM,EAAE;oBACJ,SAAS,EAAE,IAAI;oBACf,OAAO,EAAE,IAAI;iBAChB;gBACD,QAAQ,EAAE,GAAG,EAAE;oBACX,IAAI,CAAC,0BAA0B,EAAE,CAAC;gBACtC,CAAC;aACJ,CAAC,CAAC;YAEH,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACtC,CAAC;QAED;;WAEG;QACH,IAAW,oBAAoB;YAC3B,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE;gBAChC,OAAO,CACH,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;oBACpD,KAAK,CACR,CAAC;aACL;iBAAM;gBACH,MAAM,IAAI,KAAK,CACX,8GAA8G,CACjH,CAAC;aACL;QACL,CAAC;QAGM,sBAAsB,CAAC,QAAgB;YAC1C,IAAI,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBAC1C,OAAO,IAAI,CAAC,oBAAoB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC;aAC5D;YACD,MAAM,IAAI,KAAK,CACX,2BAA2B,QAAQ,2BAA2B,CACjE,CAAC;QACN,CAAC;KAoBJ;SA7BY,oBAAoB;IA8BjC,OAAO,4BAA4B,CAAC;AACxC,CAAC","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"]}
|
|
@@ -7,5 +7,5 @@ export interface SlotTextObservingInterface {
|
|
|
7
7
|
slotHasContent: boolean;
|
|
8
8
|
manageTextObservedSlot(): void;
|
|
9
9
|
}
|
|
10
|
-
export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T,
|
|
10
|
+
export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T, slotName?: string): T & Constructor<SlotTextObservingInterface>;
|
|
11
11
|
export {};
|
package/src/observe-slot-text.js
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { property, queryAssignedNodes, } from '@spectrum-web-components/base/src/decorators.js';
|
|
3
|
-
|
|
4
|
-
// Fix needed for: https://github.com/lit/lit/issues/1789
|
|
3
|
+
import { MutationController } from '@lit-labs/observers/mutation_controller.js';
|
|
5
4
|
const assignedNodesList = Symbol('assignedNodes');
|
|
6
|
-
|
|
7
|
-
export function ObserveSlotText(constructor, slotSelector) {
|
|
5
|
+
export function ObserveSlotText(constructor, slotName) {
|
|
8
6
|
var _a;
|
|
9
7
|
class SlotTextObservingElement extends constructor {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
constructor(...args) {
|
|
10
|
+
super(args);
|
|
12
11
|
this.slotHasContent = false;
|
|
12
|
+
new MutationController(this, {
|
|
13
|
+
config: {
|
|
14
|
+
characterData: true,
|
|
15
|
+
subtree: true,
|
|
16
|
+
},
|
|
17
|
+
callback: (mutationsList) => {
|
|
18
|
+
for (const mutation of mutationsList) {
|
|
19
|
+
if (mutation.type === 'characterData') {
|
|
20
|
+
this.manageTextObservedSlot();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
});
|
|
13
26
|
}
|
|
14
27
|
manageTextObservedSlot() {
|
|
15
28
|
if (!this[assignedNodesList])
|
|
@@ -22,40 +35,35 @@ export function ObserveSlotText(constructor, slotSelector) {
|
|
|
22
35
|
});
|
|
23
36
|
this.slotHasContent = assignedNodes.length > 0;
|
|
24
37
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (mutation.type === 'characterData') {
|
|
35
|
-
this.manageTextObservedSlot();
|
|
36
|
-
}
|
|
38
|
+
update(changedProperties) {
|
|
39
|
+
if (!this.hasUpdated) {
|
|
40
|
+
const { childNodes } = this;
|
|
41
|
+
const textNodes = [...childNodes].filter((node) => {
|
|
42
|
+
if (node.tagName) {
|
|
43
|
+
return slotName
|
|
44
|
+
? node.getAttribute('slot') ===
|
|
45
|
+
slotName
|
|
46
|
+
: !node.hasAttribute('slot');
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
return node.textContent ? node.textContent.trim() : false;
|
|
49
|
+
});
|
|
50
|
+
this.slotHasContent = textNodes.length > 0;
|
|
40
51
|
}
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
connectedCallback() {
|
|
44
|
-
super.connectedCallback();
|
|
45
|
-
this[startObserving]();
|
|
52
|
+
super.update(changedProperties);
|
|
46
53
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
firstUpdated(changedProperties) {
|
|
55
|
+
super.firstUpdated(changedProperties);
|
|
56
|
+
this.updateComplete.then(() => {
|
|
57
|
+
this.manageTextObservedSlot();
|
|
58
|
+
});
|
|
52
59
|
}
|
|
53
60
|
}
|
|
61
|
+
_a = assignedNodesList;
|
|
54
62
|
__decorate([
|
|
55
63
|
property({ type: Boolean, attribute: false })
|
|
56
64
|
], SlotTextObservingElement.prototype, "slotHasContent", void 0);
|
|
57
65
|
__decorate([
|
|
58
|
-
queryAssignedNodes(
|
|
66
|
+
queryAssignedNodes(slotName, true)
|
|
59
67
|
], SlotTextObservingElement.prototype, _a, void 0);
|
|
60
68
|
return SlotTextObservingElement;
|
|
61
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-slot-text.js","sourceRoot":"","sources":["observe-slot-text.ts"],"names":[],"mappings":";AAYA,OAAO,EACH,QAAQ,EACR,kBAAkB,GACrB,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"observe-slot-text.js","sourceRoot":"","sources":["observe-slot-text.ts"],"names":[],"mappings":";AAYA,OAAO,EACH,QAAQ,EACR,kBAAkB,GACrB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,MAAM,iBAAiB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAalD,MAAM,UAAU,eAAe,CAC3B,WAAc,EACd,QAAiB;;IAEjB,MAAM,wBACF,SAAQ,WAAW;QAGnB,8DAA8D;QAC9D,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,IAAI,CAAC,CAAC;YAmBT,mBAAc,GAAG,KAAK,CAAC;YAjB1B,IAAI,kBAAkB,CAAC,IAAI,EAAE;gBACzB,MAAM,EAAE;oBACJ,aAAa,EAAE,IAAI;oBACnB,OAAO,EAAE,IAAI;iBAChB;gBACD,QAAQ,EAAE,CAAC,aAAoC,EAAE,EAAE;oBAC/C,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE;wBAClC,IAAI,QAAQ,CAAC,IAAI,KAAK,eAAe,EAAE;4BACnC,IAAI,CAAC,sBAAsB,EAAE,CAAC;4BAC9B,OAAO;yBACV;qBACJ;gBACL,CAAC;aACJ,CAAC,CAAC;QACP,CAAC;QAQM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CAAC;YACtC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC1B,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAClC,CAAC,CAAC,CAAC;QACP,CAAC;KACJ;SAxCY,iBAAiB;IAH1B;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oEAChB;IAG9B;QADC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,CAAC;sDACmB;IAyC1D,OAAO,wBAAwB,CAAC;AACpC,CAAC","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-slot-presence.test.js","sourceRoot":"","sources":["observe-slot-presence.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAEF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAkB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,YAAa,SAAQ,mBAAmB,CAC1C,UAAU,EACV,oBAAoB,CACvB;
|
|
1
|
+
{"version":3,"file":"observe-slot-presence.test.js","sourceRoot":"","sources":["observe-slot-presence.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAEF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAkB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,YAAa,SAAQ,mBAAmB,CAC1C,UAAU,EACV,oBAAoB,CACvB;IACsB,MAAM;QACrB,OAAO,IAAI,CAAA;;SAEV,CAAC;IACN,CAAC;CACJ;AAED,cAAc,CAAC,MAAM,CAAC,uBAAuB,EAAE,YAAY,CAAC,CAAC;AAE7D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;aAEH,CACJ,CAAC;QACF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAE5C,EAAE,CAAC,SAAS,GAAG,8BAA8B,CAAC;QAC9C,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","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*/\n\nimport { ObserveSlotPresence } from '../src/observe-slot-presence.js';\nimport { LitElement, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\nclass ObserverTest extends ObserveSlotPresence(\n LitElement,\n '[slot=\"test-slot\"]'\n) {\n protected override render(): TemplateResult {\n return html`\n Test Element\n `;\n }\n}\n\ncustomElements.define('observe-presence-test', ObserverTest);\n\ndescribe('ObserveSlotPresence', () => {\n it('does no management when slot unavailable', async () => {\n const el = await fixture<ObserverTest>(\n html`\n <observe-presence-test></observe-presence-test>\n `\n );\n await elementUpdated(el);\n\n expect(el.slotContentIsPresent).to.be.false;\n\n el.innerHTML = '<div slot=\"test-slot\"></div>';\n await elementUpdated(el);\n\n expect(el.slotContentIsPresent).to.be.true;\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe-slot-text.test.js","sourceRoot":"","sources":["observe-slot-text.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAkB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,YAAa,SAAQ,eAAe,CAAC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"observe-slot-text.test.js","sourceRoot":"","sources":["observe-slot-text.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAkB,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,YAAa,SAAQ,eAAe,CAAC,UAAU,CAAC;IAC/B,MAAM;QACrB,OAAO,IAAI,CAAA;gCACa,IAAI,CAAC,sBAAsB;SAClD,CAAC;IACN,CAAC;CACJ;AAED,cAAc,CAAC,MAAM,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;aAEH,CACJ,CAAC;QACF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;QAEtC,EAAE,CAAC,WAAW,GAAG,mBAAmB,CAAC;QAErC,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","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 { ObserveSlotText } from '../src/observe-slot-text.js';\nimport { LitElement, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\nclass ObserverTest extends ObserveSlotText(LitElement) {\n protected override render(): TemplateResult {\n return html`\n <slot @slotchange=${this.manageTextObservedSlot}></slot>\n `;\n }\n}\n\ncustomElements.define('observe-slot-test', ObserverTest);\n\ndescribe('ObserveSlotText', () => {\n it('does no management when slot unavailable', async () => {\n const el = await fixture<ObserverTest>(\n html`\n <observe-slot-test></observe-slot-test>\n `\n );\n await elementUpdated(el);\n\n expect(el.slotHasContent).to.be.false;\n\n el.textContent = `hi, i'm some text`;\n\n await elementUpdated(el);\n\n expect(el.slotHasContent).to.be.true;\n });\n});\n"]}
|