@spectrum-web-components/shared 0.15.0-devmode.0 → 0.15.1
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.dev.js +4 -1
- package/src/first-focusable-in.dev.js.map +1 -1
- package/src/first-focusable-in.js +1 -5
- package/src/first-focusable-in.js.map +2 -2
- package/src/focus-visible.dev.js +10 -2
- package/src/focus-visible.dev.js.map +1 -1
- package/src/focus-visible.js +1 -67
- package/src/focus-visible.js.map +2 -2
- package/src/focusable.d.ts +2 -0
- package/src/focusable.dev.js +36 -10
- package/src/focusable.dev.js.map +2 -2
- package/src/focusable.js +1 -189
- package/src/focusable.js.map +3 -3
- package/src/get-active-element.dev.js +1 -0
- package/src/get-active-element.dev.js.map +1 -1
- package/src/get-active-element.js +1 -3
- package/src/get-active-element.js.map +2 -2
- package/src/get-deep-element-from-point.dev.js +1 -0
- package/src/get-deep-element-from-point.dev.js.map +1 -1
- package/src/get-deep-element-from-point.js +1 -11
- package/src/get-deep-element-from-point.js.map +2 -2
- package/src/index.dev.js +1 -0
- package/src/index.dev.js.map +1 -1
- package/src/index.js +1 -9
- package/src/index.js.map +1 -1
- package/src/like-anchor.dev.js +1 -0
- package/src/like-anchor.dev.js.map +1 -1
- package/src/like-anchor.js +12 -57
- package/src/like-anchor.js.map +2 -2
- package/src/observe-slot-presence.dev.js +11 -3
- package/src/observe-slot-presence.dev.js.map +1 -1
- package/src/observe-slot-presence.js +1 -51
- package/src/observe-slot-presence.js.map +2 -2
- package/src/observe-slot-text.dev.js +8 -5
- package/src/observe-slot-text.dev.js.map +1 -1
- package/src/observe-slot-text.js +1 -78
- package/src/observe-slot-text.js.map +2 -2
- package/src/platform.dev.js +1 -0
- package/src/platform.dev.js.map +1 -1
- package/src/platform.js +1 -30
- package/src/platform.js.map +2 -2
- package/src/reparent-children.dev.js +9 -2
- package/src/reparent-children.dev.js.map +1 -1
- package/src/reparent-children.js +1 -49
- package/src/reparent-children.js.map +2 -2
- package/test/focusable.test.js +5 -2
- package/test/focusable.test.js.map +1 -1
- package/test/observe-slot-presence.test.js +9 -3
- package/test/observe-slot-presence.test.js.map +1 -1
- package/test/observe-slot-text.test.js +5 -2
- package/test/observe-slot-text.test.js.map +1 -1
- package/test/reparent-children.test.js +25 -8
- package/test/reparent-children.test.js.map +2 -2
package/src/focusable.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["focusable.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, 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"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
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.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 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": "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",
|
|
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-active-element.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\n/* c8 ignore next 3 */\nexport const getActiveElement = (el: Node): Element | null => {\n return (el.getRootNode() as Document).activeElement;\n};\n"],
|
|
5
|
-
"mappings": "AAaO,aAAM,mBAAmB,CAAC,OAA6B;AAC1D,SAAQ,GAAG,YAAY,EAAe;AAC1C;",
|
|
5
|
+
"mappings": ";AAaO,aAAM,mBAAmB,CAAC,OAA6B;AAC1D,SAAQ,GAAG,YAAY,EAAe;AAC1C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["get-active-element.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\n/* c8 ignore next 3 */\nexport const getActiveElement = (el: Node): Element | null => {\n return (el.getRootNode() as Document).activeElement;\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "aAaO,aAAM,iBAAoBA,GACrBA,EAAG,YAAY,EAAe",
|
|
6
|
+
"names": ["el"]
|
|
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,0BAA0B,CACnC,GACA,MACiB;AACjB,MAAI,SAAS,SAAS,iBAAiB,GAAG,CAAC;AAC3C,SAAO,iCAAQ,YAAY;AACvB,UAAM,cACF,OAAO,WAGT,iBAAiB,GAAG,CAAC;AACvB,QAAI,CAAC,eAAe,gBAAgB,QAAQ;AACxC;AAAA,IACJ;AACA,aAAS;AAAA,EACb;AACA,SAAO;AACX;",
|
|
5
|
+
"mappings": ";AAYO,aAAM,0BAA0B,CACnC,GACA,MACiB;AACjB,MAAI,SAAS,SAAS,iBAAiB,GAAG,CAAC;AAC3C,SAAO,iCAAQ,YAAY;AACvB,UAAM,cACF,OAAO,WAGT,iBAAiB,GAAG,CAAC;AACvB,QAAI,CAAC,eAAe,gBAAgB,QAAQ;AACxC;AAAA,IACJ;AACA,aAAS;AAAA,EACb;AACA,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
export const getDeepElementFromPoint = (
|
|
2
|
-
let target = document.elementFromPoint(x, y);
|
|
3
|
-
while (target == null ? void 0 : target.shadowRoot) {
|
|
4
|
-
const innerTarget = target.shadowRoot.elementFromPoint(x, y);
|
|
5
|
-
if (!innerTarget || innerTarget === target) {
|
|
6
|
-
break;
|
|
7
|
-
}
|
|
8
|
-
target = innerTarget;
|
|
9
|
-
}
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
1
|
+
"use strict";export const getDeepElementFromPoint=(o,t)=>{let e=document.elementFromPoint(o,t);for(;e!=null&&e.shadowRoot;){const n=e.shadowRoot.elementFromPoint(o,t);if(!n||n===e)break;e=n}return e};
|
|
12
2
|
//# sourceMappingURL=get-deep-element-from-point.js.map
|
|
@@ -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": "
|
|
6
|
-
"names": []
|
|
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,CACb,CACA,OAAOD,CACX",
|
|
6
|
+
"names": ["x", "y", "target", "innerTarget"]
|
|
7
7
|
}
|
package/src/index.dev.js
CHANGED
package/src/index.dev.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.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\nexport * from './first-focusable-in.dev.js'\nexport * from './focus-visible.dev.js'\nexport * from './focusable.dev.js'\nexport * from './get-active-element.dev.js'\nexport * from './like-anchor.dev.js'\nexport * from './observe-slot-presence.dev.js'\nexport * from './observe-slot-text.dev.js'\nexport * from './platform.dev.js'\nexport * from './reparent-children.dev.js'\n"],
|
|
5
|
-
"mappings": "AAYA;
|
|
5
|
+
"mappings": ";AAYA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./focus-visible.js";
|
|
3
|
-
export * from "./focusable.js";
|
|
4
|
-
export * from "./get-active-element.js";
|
|
5
|
-
export * from "./like-anchor.js";
|
|
6
|
-
export * from "./observe-slot-presence.js";
|
|
7
|
-
export * from "./observe-slot-text.js";
|
|
8
|
-
export * from "./platform.js";
|
|
9
|
-
export * from "./reparent-children.js";
|
|
1
|
+
"use strict";export*from"./first-focusable-in.js";export*from"./focus-visible.js";export*from"./focusable.js";export*from"./get-active-element.js";export*from"./like-anchor.js";export*from"./observe-slot-presence.js";export*from"./observe-slot-text.js";export*from"./platform.js";export*from"./reparent-children.js";
|
|
10
2
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.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\nexport * from './first-focusable-in.js';\nexport * from './focus-visible.js';\nexport * from './focusable.js';\nexport * from './get-active-element.js';\nexport * from './like-anchor.js';\nexport * from './observe-slot-presence.js';\nexport * from './observe-slot-text.js';\nexport * from './platform.js';\nexport * from './reparent-children.js';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "aAYA,WAAc,0BACd,WAAc,qBACd,WAAc,iBACd,WAAc,0BACd,WAAc,mBACd,WAAc,6BACd,WAAc,yBACd,WAAc,gBACd,WAAc",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/like-anchor.dev.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["like-anchor.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n html,\n ReactiveElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ntype RenderAnchorOptions = {\n id: string;\n className?: string;\n ariaHidden?: boolean;\n anchorContent?: TemplateResult | TemplateResult[];\n labelledby?: string;\n tabindex?: -1 | 0;\n};\n\nexport interface LikeAnchorInterface {\n download?: string;\n label?: string;\n href?: string;\n rel?: string;\n target?: '_blank' | '_parent' | '_self' | '_top';\n renderAnchor(options: RenderAnchorOptions): TemplateResult;\n}\n\nexport function LikeAnchor<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<LikeAnchorInterface> {\n class LikeAnchorElement extends constructor {\n @property({ reflect: true })\n public download?: string;\n\n @property()\n public label?: string;\n\n @property({ reflect: true })\n public href?: string;\n\n @property({ reflect: true })\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n @property({ reflect: true })\n public rel?: string;\n\n public renderAnchor({\n id,\n className,\n ariaHidden,\n labelledby,\n tabindex,\n // prettier-ignore\n anchorContent = html`<slot></slot>`,\n }: RenderAnchorOptions): TemplateResult {\n // prettier-ignore\n return html\n `<a\n id=${id}\n class=${ifDefined(className)}\n href=${ifDefined(this.href)}\n download=${ifDefined(this.download)}\n target=${ifDefined(this.target)}\n aria-label=${ifDefined(this.label)}\n aria-labelledby=${ifDefined(labelledby)}\n aria-hidden=${ifDefined(ariaHidden ? 'true' : undefined)}\n tabindex=${ifDefined(tabindex)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAWA;AAAA,EACI;AAAA,OAGG;AACP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AA0BnB,gBAAS,WACZ,aACoC;AACpC,QAAM,0BAA0B,YAAY;AAAA,IAgBjC,aAAa;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA,gBAAgB;AAAA,IACpB,GAAwC;AAEpC,aAAO;AAAA,yBAEM;AAAA,4BACG,UAAU,SAAS;AAAA,2BACpB,UAAU,KAAK,IAAI;AAAA,+BACf,UAAU,KAAK,QAAQ;AAAA,6BACzB,UAAU,KAAK,MAAM;AAAA,iCACjB,UAAU,KAAK,KAAK;AAAA,sCACf,UAAU,UAAU;AAAA,kCACxB,UAAU,aAAa,SAAS,MAAS;AAAA,+BAC5C,UAAU,QAAQ;AAAA,0BACvB,UAAU,KAAK,GAAG;AAAA,mBACzB;AAAA,IACX;AAAA,EACJ;AAtCW;AAAA,IADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KADzB,kBAEK;AAGA;AAAA,IADN,SAAS;AAAA,KAJR,kBAKK;AAGA;AAAA,IADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KAPzB,kBAQK;AAGA;AAAA,IADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KAVzB,kBAWK;AAGA;AAAA,IADN,SAAS,EAAE,SAAS,KAAK,CAAC;AAAA,KAbzB,kBAcK;AA2BX,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/like-anchor.js
CHANGED
|
@@ -1,58 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
html
|
|
14
|
-
} from "@spectrum-web-components/base";
|
|
15
|
-
import { property } from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
-
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
|
17
|
-
export function LikeAnchor(constructor) {
|
|
18
|
-
class LikeAnchorElement extends constructor {
|
|
19
|
-
renderAnchor({
|
|
20
|
-
id,
|
|
21
|
-
className,
|
|
22
|
-
ariaHidden,
|
|
23
|
-
labelledby,
|
|
24
|
-
tabindex,
|
|
25
|
-
anchorContent = html`<slot></slot>`
|
|
26
|
-
}) {
|
|
27
|
-
return html`<a
|
|
28
|
-
id=${id}
|
|
29
|
-
class=${ifDefined(className)}
|
|
30
|
-
href=${ifDefined(this.href)}
|
|
31
|
-
download=${ifDefined(this.download)}
|
|
32
|
-
target=${ifDefined(this.target)}
|
|
33
|
-
aria-label=${ifDefined(this.label)}
|
|
34
|
-
aria-labelledby=${ifDefined(labelledby)}
|
|
35
|
-
aria-hidden=${ifDefined(ariaHidden ? "true" : void 0)}
|
|
36
|
-
tabindex=${ifDefined(tabindex)}
|
|
37
|
-
rel=${ifDefined(this.rel)}
|
|
38
|
-
>${anchorContent}</a>`;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
__decorateClass([
|
|
42
|
-
property({ reflect: true })
|
|
43
|
-
], LikeAnchorElement.prototype, "download", 2);
|
|
44
|
-
__decorateClass([
|
|
45
|
-
property()
|
|
46
|
-
], LikeAnchorElement.prototype, "label", 2);
|
|
47
|
-
__decorateClass([
|
|
48
|
-
property({ reflect: true })
|
|
49
|
-
], LikeAnchorElement.prototype, "href", 2);
|
|
50
|
-
__decorateClass([
|
|
51
|
-
property({ reflect: true })
|
|
52
|
-
], LikeAnchorElement.prototype, "target", 2);
|
|
53
|
-
__decorateClass([
|
|
54
|
-
property({ reflect: true })
|
|
55
|
-
], LikeAnchorElement.prototype, "rel", 2);
|
|
56
|
-
return LikeAnchorElement;
|
|
57
|
-
}
|
|
1
|
+
"use strict";var b=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var n=(s,e,p,l)=>{for(var t=l>1?void 0:l?g(e,p):e,a=s.length-1,i;a>=0;a--)(i=s[a])&&(t=(l?i(e,p,t):i(t))||t);return l&&t&&b(e,p,t),t};import{html as d}from"@spectrum-web-components/base";import{property as o}from"@spectrum-web-components/base/src/decorators.js";import{ifDefined as r}from"@spectrum-web-components/base/src/directives.js";export function LikeAnchor(s){class e extends s{renderAnchor({id:t,className:a,ariaHidden:i,labelledby:c,tabindex:u,anchorContent:f=d`<slot></slot>`}){return d`<a
|
|
2
|
+
id=${t}
|
|
3
|
+
class=${r(a)}
|
|
4
|
+
href=${r(this.href)}
|
|
5
|
+
download=${r(this.download)}
|
|
6
|
+
target=${r(this.target)}
|
|
7
|
+
aria-label=${r(this.label)}
|
|
8
|
+
aria-labelledby=${r(c)}
|
|
9
|
+
aria-hidden=${r(i?"true":void 0)}
|
|
10
|
+
tabindex=${r(u)}
|
|
11
|
+
rel=${r(this.rel)}
|
|
12
|
+
>${f}</a>`}}return n([o({reflect:!0})],e.prototype,"download",2),n([o()],e.prototype,"label",2),n([o({reflect:!0})],e.prototype,"href",2),n([o({reflect:!0})],e.prototype,"target",2),n([o({reflect:!0})],e.prototype,"rel",2),e}
|
|
58
13
|
//# sourceMappingURL=like-anchor.js.map
|
package/src/like-anchor.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["like-anchor.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport {\n html,\n ReactiveElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\ntype RenderAnchorOptions = {\n id: string;\n className?: string;\n ariaHidden?: boolean;\n anchorContent?: TemplateResult | TemplateResult[];\n labelledby?: string;\n tabindex?: -1 | 0;\n};\n\nexport interface LikeAnchorInterface {\n download?: string;\n label?: string;\n href?: string;\n rel?: string;\n target?: '_blank' | '_parent' | '_self' | '_top';\n renderAnchor(options: RenderAnchorOptions): TemplateResult;\n}\n\nexport function LikeAnchor<T extends Constructor<ReactiveElement>>(\n constructor: T\n): T & Constructor<LikeAnchorInterface> {\n class LikeAnchorElement extends constructor {\n @property({ reflect: true })\n public download?: string;\n\n @property()\n public label?: string;\n\n @property({ reflect: true })\n public href?: string;\n\n @property({ reflect: true })\n public target?: '_blank' | '_parent' | '_self' | '_top';\n\n @property({ reflect: true })\n public rel?: string;\n\n public renderAnchor({\n id,\n className,\n ariaHidden,\n labelledby,\n tabindex,\n // prettier-ignore\n anchorContent = html`<slot></slot>`,\n }: RenderAnchorOptions): TemplateResult {\n // prettier-ignore\n return html\n `<a\n id=${id}\n class=${ifDefined(className)}\n href=${ifDefined(this.href)}\n download=${ifDefined(this.download)}\n target=${ifDefined(this.target)}\n aria-label=${ifDefined(this.label)}\n aria-labelledby=${ifDefined(labelledby)}\n aria-hidden=${ifDefined(ariaHidden ? 'true' : undefined)}\n tabindex=${ifDefined(tabindex)}\n rel=${ifDefined(this.rel)}\n >${anchorContent}</a>`;\n }\n }\n return LikeAnchorElement;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "qNAWA,OACI,QAAAA,MAGG,gCACP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,aAAAC,MAAiB,kDA0BnB,gBAAS,WACZC,EACoC,CACpC,MAAMC,UAA0BD,CAAY,CAgBjC,aAAa,CAChB,GAAAE,EACA,UAAAC,EACA,WAAAC,EACA,WAAAC,EACA,SAAAC,EAEA,cAAAC,EAAgBV,gBACpB,EAAwC,CAEpC,OAAOA;AAAA,yBAEMK;AAAA,4BACGH,EAAUI,CAAS;AAAA,2BACpBJ,EAAU,KAAK,IAAI;AAAA,+BACfA,EAAU,KAAK,QAAQ;AAAA,6BACzBA,EAAU,KAAK,MAAM;AAAA,iCACjBA,EAAU,KAAK,KAAK;AAAA,sCACfA,EAAUM,CAAU;AAAA,kCACxBN,EAAUK,EAAa,OAAS,MAAS;AAAA,+BAC5CL,EAAUO,CAAQ;AAAA,0BACvBP,EAAU,KAAK,GAAG;AAAA,mBACzBQ,OACX,CACJ,CAtCW,OAAAC,EAAA,CADNV,EAAS,CAAE,QAAS,EAAK,CAAC,GADzBG,EAEK,wBAGAO,EAAA,CADNV,EAAS,GAJRG,EAKK,qBAGAO,EAAA,CADNV,EAAS,CAAE,QAAS,EAAK,CAAC,GAPzBG,EAQK,oBAGAO,EAAA,CADNV,EAAS,CAAE,QAAS,EAAK,CAAC,GAVzBG,EAWK,sBAGAO,EAAA,CADNV,EAAS,CAAE,QAAS,EAAK,CAAC,GAbzBG,EAcK,mBA2BJA,CACX",
|
|
6
|
+
"names": ["html", "property", "ifDefined", "constructor", "LikeAnchorElement", "id", "className", "ariaHidden", "labelledby", "tabindex", "anchorContent", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
2
3
|
const slotContentIsPresent = Symbol("slotContentIsPresent");
|
|
3
4
|
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
@@ -13,7 +14,10 @@ export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
|
13
14
|
const nextValue = !!this.querySelector(selector);
|
|
14
15
|
const previousValue = this[slotContentIsPresent].get(selector) || false;
|
|
15
16
|
changes = changes || previousValue !== nextValue;
|
|
16
|
-
this[slotContentIsPresent].set(
|
|
17
|
+
this[slotContentIsPresent].set(
|
|
18
|
+
selector,
|
|
19
|
+
!!this.querySelector(selector)
|
|
20
|
+
);
|
|
17
21
|
});
|
|
18
22
|
if (changes) {
|
|
19
23
|
this.updateComplete.then(() => {
|
|
@@ -36,14 +40,18 @@ export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
|
36
40
|
if (lightDomSelectors.length === 1) {
|
|
37
41
|
return this[slotContentIsPresent].get(lightDomSelectors[0]) || false;
|
|
38
42
|
} else {
|
|
39
|
-
throw new Error(
|
|
43
|
+
throw new Error(
|
|
44
|
+
"Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead."
|
|
45
|
+
);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
getSlotContentPresence(selector) {
|
|
43
49
|
if (this[slotContentIsPresent].has(selector)) {
|
|
44
50
|
return this[slotContentIsPresent].get(selector) || false;
|
|
45
51
|
}
|
|
46
|
-
throw new Error(
|
|
52
|
+
throw new Error(
|
|
53
|
+
`The provided selector \`${selector}\` is not being observed.`
|
|
54
|
+
);
|
|
47
55
|
}
|
|
48
56
|
}
|
|
49
57
|
_a = slotContentIsPresent;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ReactiveElement } from '@spectrum-web-components/base';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.managePresenceObservedSlot();\n },\n });\n\n this.managePresenceObservedSlot();\n }\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`${selector}\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n let changes = false;\n lightDomSelectors.forEach((selector) => {\n const nextValue = !!this.querySelector(selector);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n if (changes) {\n this.updateComplete.then(() => {\n this.requestUpdate();\n });\n }\n };\n }\n return SlotPresenceObservingElement;\n}\n"],
|
|
5
|
-
"mappings": "AAWA;
|
|
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,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,sBAAsB,IAAI,QAAQ,KAAK;AAChD,oBAAU,WAAW,kBAAkB;AACvC,eAAK,sBAAsB;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,IAKA,IAAW,uBAAgC;AACvC,UAAI,kBAAkB,WAAW,GAAG;AAChC,eACI,KAAK,sBAAsB,IAAI,kBAAkB,EAAE,KACnD;AAAA,MAER,OAAO;AACH,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,IAGO,uBAAuB,UAA2B;AACrD,UAAI,KAAK,sBAAsB,IAAI,QAAQ,GAAG;AAC1C,eAAO,KAAK,sBAAsB,IAAI,QAAQ,KAAK;AAAA,MACvD;AACA,YAAM,IAAI;AAAA,QACN,2BAA2B;AAAA,MAC/B;AAAA,IACJ;AAAA,EAoBJ;AAnGJ,EAsEiB;AA8Bb,SAAO;AACX;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,52 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
const slotContentIsPresent = Symbol("slotContentIsPresent");
|
|
3
|
-
export function ObserveSlotPresence(constructor, lightDomSelector) {
|
|
4
|
-
var _a;
|
|
5
|
-
const lightDomSelectors = Array.isArray(lightDomSelector) ? lightDomSelector : [lightDomSelector];
|
|
6
|
-
class SlotPresenceObservingElement extends constructor {
|
|
7
|
-
constructor(...args) {
|
|
8
|
-
super(args);
|
|
9
|
-
this[_a] = /* @__PURE__ */ new Map();
|
|
10
|
-
this.managePresenceObservedSlot = () => {
|
|
11
|
-
let changes = false;
|
|
12
|
-
lightDomSelectors.forEach((selector) => {
|
|
13
|
-
const nextValue = !!this.querySelector(selector);
|
|
14
|
-
const previousValue = this[slotContentIsPresent].get(selector) || false;
|
|
15
|
-
changes = changes || previousValue !== nextValue;
|
|
16
|
-
this[slotContentIsPresent].set(selector, !!this.querySelector(selector));
|
|
17
|
-
});
|
|
18
|
-
if (changes) {
|
|
19
|
-
this.updateComplete.then(() => {
|
|
20
|
-
this.requestUpdate();
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
new MutationController(this, {
|
|
25
|
-
config: {
|
|
26
|
-
childList: true,
|
|
27
|
-
subtree: true
|
|
28
|
-
},
|
|
29
|
-
callback: () => {
|
|
30
|
-
this.managePresenceObservedSlot();
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
this.managePresenceObservedSlot();
|
|
34
|
-
}
|
|
35
|
-
get slotContentIsPresent() {
|
|
36
|
-
if (lightDomSelectors.length === 1) {
|
|
37
|
-
return this[slotContentIsPresent].get(lightDomSelectors[0]) || false;
|
|
38
|
-
} else {
|
|
39
|
-
throw new Error("Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
getSlotContentPresence(selector) {
|
|
43
|
-
if (this[slotContentIsPresent].has(selector)) {
|
|
44
|
-
return this[slotContentIsPresent].get(selector) || false;
|
|
45
|
-
}
|
|
46
|
-
throw new Error(`The provided selector \`${selector}\` is not being observed.`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
_a = slotContentIsPresent;
|
|
50
|
-
return SlotPresenceObservingElement;
|
|
51
|
-
}
|
|
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}
|
|
52
2
|
//# sourceMappingURL=observe-slot-presence.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-presence.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { ReactiveElement } from '@spectrum-web-components/base';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst slotContentIsPresent = Symbol('slotContentIsPresent');\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SlotPresenceObservingInterface {\n slotContentIsPresent: boolean;\n getSlotContentPresence(selector: string): boolean;\n managePresenceObservedSlot(): void;\n}\n\nexport function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement\n extends constructor\n implements SlotPresenceObservingInterface\n {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(...args: any[]) {\n super(args);\n\n new MutationController(this, {\n config: {\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.managePresenceObservedSlot();\n },\n });\n\n this.managePresenceObservedSlot();\n }\n\n /**\n * @private\n */\n public get slotContentIsPresent(): boolean {\n if (lightDomSelectors.length === 1) {\n return (\n this[slotContentIsPresent].get(lightDomSelectors[0]) ||\n false\n );\n } else {\n throw new Error(\n 'Multiple selectors provided to `ObserveSlotPresence` use `getSlotContentPresence(selector: string)` instead.'\n );\n }\n }\n private [slotContentIsPresent]: Map<string, boolean> = new Map();\n\n public getSlotContentPresence(selector: string): boolean {\n if (this[slotContentIsPresent].has(selector)) {\n return this[slotContentIsPresent].get(selector) || false;\n }\n throw new Error(\n `The provided selector \\`${selector}\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n let changes = false;\n lightDomSelectors.forEach((selector) => {\n const nextValue = !!this.querySelector(selector);\n const previousValue =\n this[slotContentIsPresent].get(selector) || false;\n changes = changes || previousValue !== nextValue;\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n if (changes) {\n this.updateComplete.then(() => {\n this.requestUpdate();\n });\n }\n };\n }\n return SlotPresenceObservingElement;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
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,GAAsB,IAAIQ,CAAQ,GAAK,GAChDD,EAAUA,GAAWG,IAAkBD,EACvC,KAAKT,GAAsB,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,GAAsB,IAAII,EAAkB,EAAE,GACnD,GAGJ,MAAM,IAAI,MACN,8GACJ,CAER,CAGO,uBAAuBI,EAA2B,CACrD,GAAI,KAAKR,GAAsB,IAAIQ,CAAQ,EACvC,OAAO,KAAKR,GAAsB,IAAIQ,CAAQ,GAAK,GAEvD,MAAM,IAAI,MACN,2BAA2BA,4BAC/B,CACJ,CAoBJ,CAnGJ,OAsEiBL,EAAAH,EA8BNK,CACX",
|
|
6
|
+
"names": ["MutationController", "slotContentIsPresent", "constructor", "lightDomSelector", "_a", "lightDomSelectors", "SlotPresenceObservingElement", "args", "changes", "selector", "nextValue", "previousValue"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -39,12 +40,14 @@ export function ObserveSlotText(constructor, slotName) {
|
|
|
39
40
|
manageTextObservedSlot() {
|
|
40
41
|
if (!this[assignedNodesList])
|
|
41
42
|
return;
|
|
42
|
-
const assignedNodes = [...this[assignedNodesList]].filter(
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const assignedNodes = [...this[assignedNodesList]].filter(
|
|
44
|
+
(node) => {
|
|
45
|
+
if (node.tagName) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return node.textContent ? node.textContent.trim() : false;
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
});
|
|
50
|
+
);
|
|
48
51
|
this.slotHasContent = assignedNodes.length > 0;
|
|
49
52
|
}
|
|
50
53
|
update(changedProperties) {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["observe-slot-text.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { PropertyValues, ReactiveElement } from '@spectrum-web-components/base';\nimport {\n property,\n queryAssignedNodes,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { MutationController } from '@lit-labs/observers/mutation_controller.js';\n\nconst assignedNodesList = Symbol('assignedNodes');\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport interface SlotTextObservingInterface {\n slotHasContent: boolean;\n manageTextObservedSlot(): void;\n}\n\nexport function ObserveSlotText<T extends Constructor<ReactiveElement>>(\n constructor: T,\n slotName?: string\n): 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": "
|
|
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,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;AAAoB;AAC9B,YAAM,gBAAgB,CAAC,GAAG,KAAK,kBAAkB,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,79 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
-
if (decorator = decorators[i])
|
|
7
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
-
if (kind && result)
|
|
9
|
-
__defProp(target, key, result);
|
|
10
|
-
return result;
|
|
11
|
-
};
|
|
12
|
-
import {
|
|
13
|
-
property,
|
|
14
|
-
queryAssignedNodes
|
|
15
|
-
} from "@spectrum-web-components/base/src/decorators.js";
|
|
16
|
-
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
17
|
-
const assignedNodesList = Symbol("assignedNodes");
|
|
18
|
-
export function ObserveSlotText(constructor, slotName) {
|
|
19
|
-
var _a;
|
|
20
|
-
class SlotTextObservingElement extends constructor {
|
|
21
|
-
constructor(...args) {
|
|
22
|
-
super(args);
|
|
23
|
-
this.slotHasContent = false;
|
|
24
|
-
new MutationController(this, {
|
|
25
|
-
config: {
|
|
26
|
-
characterData: true,
|
|
27
|
-
subtree: true
|
|
28
|
-
},
|
|
29
|
-
callback: (mutationsList) => {
|
|
30
|
-
for (const mutation of mutationsList) {
|
|
31
|
-
if (mutation.type === "characterData") {
|
|
32
|
-
this.manageTextObservedSlot();
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
manageTextObservedSlot() {
|
|
40
|
-
if (!this[assignedNodesList])
|
|
41
|
-
return;
|
|
42
|
-
const assignedNodes = [...this[assignedNodesList]].filter((node) => {
|
|
43
|
-
if (node.tagName) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return node.textContent ? node.textContent.trim() : false;
|
|
47
|
-
});
|
|
48
|
-
this.slotHasContent = assignedNodes.length > 0;
|
|
49
|
-
}
|
|
50
|
-
update(changedProperties) {
|
|
51
|
-
if (!this.hasUpdated) {
|
|
52
|
-
const { childNodes } = this;
|
|
53
|
-
const textNodes = [...childNodes].filter((node) => {
|
|
54
|
-
if (node.tagName) {
|
|
55
|
-
return slotName ? node.getAttribute("slot") === slotName : !node.hasAttribute("slot");
|
|
56
|
-
}
|
|
57
|
-
return node.textContent ? node.textContent.trim() : false;
|
|
58
|
-
});
|
|
59
|
-
this.slotHasContent = textNodes.length > 0;
|
|
60
|
-
}
|
|
61
|
-
super.update(changedProperties);
|
|
62
|
-
}
|
|
63
|
-
firstUpdated(changedProperties) {
|
|
64
|
-
super.firstUpdated(changedProperties);
|
|
65
|
-
this.updateComplete.then(() => {
|
|
66
|
-
this.manageTextObservedSlot();
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
_a = assignedNodesList;
|
|
71
|
-
__decorateClass([
|
|
72
|
-
property({ type: Boolean, attribute: false })
|
|
73
|
-
], SlotTextObservingElement.prototype, "slotHasContent", 2);
|
|
74
|
-
__decorateClass([
|
|
75
|
-
queryAssignedNodes(slotName, true)
|
|
76
|
-
], SlotTextObservingElement.prototype, _a, 2);
|
|
77
|
-
return SlotTextObservingElement;
|
|
78
|
-
}
|
|
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}
|
|
79
2
|
//# sourceMappingURL=observe-slot-text.js.map
|