@spectrum-web-components/shared 0.12.10 → 0.13.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/shared",
3
- "version": "0.12.10",
3
+ "version": "0.13.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,12 +42,12 @@
42
42
  "lit-html"
43
43
  ],
44
44
  "dependencies": {
45
- "@spectrum-web-components/base": "^0.4.5",
45
+ "@spectrum-web-components/base": "^0.5.1",
46
46
  "focus-visible": "^5.1.0",
47
47
  "tslib": "^2.0.0"
48
48
  },
49
49
  "types": "./src/index.d.ts",
50
50
  "customElements": "custom-elements.json",
51
51
  "sideEffects": false,
52
- "gitHead": "12d891f3dc85e8de641804d8efc9ca06b7fdee2d"
52
+ "gitHead": "df3f333ee26a45f9fc247716b6e8ef051dca630b"
53
53
  }
@@ -1,4 +1,4 @@
1
- import { SpectrumElement, PropertyValues } from '@spectrum-web-components/base';
1
+ import { PropertyValues, SpectrumElement } from '@spectrum-web-components/base';
2
2
  declare type DisableableElement = HTMLElement & {
3
3
  disabled?: boolean;
4
4
  };
package/src/focusable.js CHANGED
@@ -10,7 +10,8 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
10
10
  OF ANY KIND, either express or implied. See the License for the specific language
11
11
  governing permissions and limitations under the License.
12
12
  */
13
- import { SpectrumElement, property, } from '@spectrum-web-components/base';
13
+ import { SpectrumElement } from '@spectrum-web-components/base';
14
+ import { property } from '@spectrum-web-components/base/src/decorators.js';
14
15
  import { FocusVisiblePolyfillMixin } from './focus-visible.js';
15
16
  /**
16
17
  * Focusable base class handles tabindex setting into shadowed elements automatically.
@@ -1 +1 @@
1
- {"version":3,"file":"focusable.js","sourceRoot":"","sources":["focusable.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EACH,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AAxOG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,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 {\n SpectrumElement,\n property,\n PropertyValues,\n} from '@spectrum-web-components/base';\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 this.manageAutoFocus();\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"]}
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,GAAG,KAAK,CAAC;QAoFjB,cAAS,GAAG,CAAC,CAAC;QAqBd,yBAAoB,GAAG,KAAK,CAAC;IAwHzC,CAAC;IA/NG;;;;;OAKG;IAEH,IAAW,QAAQ;QACf,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,UAAU,CAChC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;YACzB,CAAC,C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AAG,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;CACJ;AAxOG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,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 this.manageAutoFocus();\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"]}
@@ -1,4 +1,4 @@
1
- import { UpdatingElement, TemplateResult } from '@spectrum-web-components/base';
1
+ import { ReactiveElement, TemplateResult } from '@spectrum-web-components/base';
2
2
  declare type Constructor<T = Record<string, unknown>> = {
3
3
  new (...args: any[]): T;
4
4
  prototype: T;
@@ -19,5 +19,5 @@ export interface LikeAnchorInterface {
19
19
  target?: '_blank' | '_parent' | '_self' | '_top';
20
20
  renderAnchor(options: RenderAnchorOptions): TemplateResult;
21
21
  }
22
- export declare function LikeAnchor<T extends Constructor<UpdatingElement>>(constructor: T): T & Constructor<LikeAnchorInterface>;
22
+ export declare function LikeAnchor<T extends Constructor<ReactiveElement>>(constructor: T): T & Constructor<LikeAnchorInterface>;
23
23
  export {};
@@ -10,7 +10,9 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
10
10
  OF ANY KIND, either express or implied. See the License for the specific language
11
11
  governing permissions and limitations under the License.
12
12
  */
13
- import { property, html, ifDefined, } from '@spectrum-web-components/base';
13
+ import { html, } from '@spectrum-web-components/base';
14
+ import { property } from '@spectrum-web-components/base/src/decorators.js';
15
+ import { ifDefined } from '@spectrum-web-components/base/src/directives.js';
14
16
  export function LikeAnchor(constructor) {
15
17
  class LikeAnchorElement extends constructor {
16
18
  renderAnchor({ id, className, ariaHidden, labelledby, tabindex,
@@ -1 +1 @@
1
- {"version":3,"file":"like-anchor.js","sourceRoot":"","sources":["like-anchor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAEH,QAAQ,EAER,IAAI,EACJ,SAAS,GACZ,MAAM,+BAA+B,CAAC;AA0BvC,MAAM,UAAU,UAAU,CACtB,WAAc;IAEd,MAAM,iBAAkB,SAAQ,WAAW;QAgBhC,YAAY,CAAC,EAChB,EAAE,EACF,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ;QACR,kBAAkB;QAClB,aAAa,GAAG,IAAI,CAAA,eAAe,GACjB;YAClB,kBAAkB;YAClB,OAAO,IAAI,CACP;yBACS,EAAE;4BACC,SAAS,CAAC,SAAS,CAAC;2BACrB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;+BAChB,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;6BAC1B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;iCAClB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;sCAChB,SAAS,CAAC,UAAU,CAAC;kCACzB,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;+BAC7C,SAAS,CAAC,QAAQ,CAAC;0BACxB,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;mBAC1B,aAAa,MAAM,CAAC;QAC/B,CAAC;KACJ;IAtCG;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;uDACH;IAGzB;QADC,QAAQ,EAAE;oDACW;IAGtB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;mDACP;IAGrB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qDAC4B;IAGxD;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;kDACR;IA2BxB,OAAO,iBAAiB,CAAC;AAC7B,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 {\n UpdatingElement,\n property,\n TemplateResult,\n html,\n ifDefined,\n} from '@spectrum-web-components/base';\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<UpdatingElement>>(\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"]}
1
+ {"version":3,"file":"like-anchor.js","sourceRoot":"","sources":["like-anchor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EACH,IAAI,GAGP,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,iDAAiD,CAAC;AA0B5E,MAAM,UAAU,UAAU,CACtB,WAAc;IAEd,MAAM,iBAAkB,SAAQ,WAAW;QAgBhC,YAAY,CAAC,EAChB,EAAE,EACF,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ;QACR,kBAAkB;QAClB,aAAa,GAAG,IAAI,CAAA,eAAe,GACjB;YAClB,kBAAkB;YAClB,OAAO,IAAI,CACP;yBACS,EAAE;4BACC,SAAS,CAAC,SAAS,CAAC;2BACrB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;+BAChB,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC;6BAC1B,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;iCAClB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;sCAChB,SAAS,CAAC,UAAU,CAAC;kCACzB,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;+BAC7C,SAAS,CAAC,QAAQ,CAAC;0BACxB,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;mBAC1B,aAAa,MAAM,CAAC;QAC/B,CAAC;KACJ;IAtCG;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;uDACH;IAGzB;QADC,QAAQ,EAAE;oDACW;IAGtB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;mDACP;IAGrB;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qDAC4B;IAGxD;QADC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;kDACR;IA2BxB,OAAO,iBAAiB,CAAC;AAC7B,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 {\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"]}
@@ -1,4 +1,4 @@
1
- import { UpdatingElement } from '@spectrum-web-components/base';
1
+ import { ReactiveElement } from '@spectrum-web-components/base';
2
2
  declare type Constructor<T = Record<string, unknown>> = {
3
3
  new (...args: any[]): T;
4
4
  prototype: T;
@@ -8,5 +8,5 @@ export interface SlotPresenceObservingInterface {
8
8
  getSlotContentPresence(selector: string): boolean;
9
9
  managePresenceObservedSlot(): void;
10
10
  }
11
- export declare function ObserveSlotPresence<T extends Constructor<UpdatingElement>>(constructor: T, lightDomSelector: string | string[]): T & Constructor<SlotPresenceObservingInterface>;
11
+ export declare function ObserveSlotPresence<T extends Constructor<ReactiveElement>>(constructor: T, lightDomSelector: string | string[]): T & Constructor<SlotPresenceObservingInterface>;
12
12
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"observe-slot-presence.js","sourceRoot":"","sources":["observe-slot-presence.ts"],"names":[],"mappings":"AAYA,MAAM,mBAAmB,GAAG,MAAM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AAI,KAAK,CACX,mDAAmD,CACtD,CAAC;QACN,CAAC;QAYO,OArBC,oBAAoB,EAqBpB,cAAc,EAAC;YACpB,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAClD,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE;gBAC5B,IAAI,CAAC,mBAAmB,CAAC,GAAG,IAAI,gBAAgB,CAC5C,IAAI,CAAC,0BAA0B,CAClC,CAAC;aACL;YACD,IAAI,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAChD,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACtC,CAAC;QAEM,iBAAiB;YACpB,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC1B,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QAC3B,CAAC;QAEM,oBAAoB;YACvB,IAAI,CAAC,mBAAmB,CAAC,CAAC,UAAU,EAAE,CAAC;YACvC,KAAK,CAAC,oBAAoB,EAAE,CAAC;QACjC,CAAC;KACJ;IACD,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 { UpdatingElement } from '@spectrum-web-components/base';\n\nconst slotElementObserver = Symbol('slotElementObserver');\nconst startObserving = Symbol('startObserving');\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<UpdatingElement>>(\n constructor: T,\n lightDomSelector: string | string[]\n): T & Constructor<SlotPresenceObservingInterface> {\n const lightDomSelectors = Array.isArray(lightDomSelector)\n ? lightDomSelector\n : [lightDomSelector];\n class SlotPresenceObservingElement extends constructor\n implements SlotPresenceObservingInterface {\n private [slotElementObserver]!: MutationObserver;\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 \\`\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n lightDomSelectors.forEach((selector) => {\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n this.requestUpdate();\n };\n\n private [startObserving](): void {\n const config = { childList: true, subtree: true };\n if (!this[slotElementObserver]) {\n this[slotElementObserver] = new MutationObserver(\n this.managePresenceObservedSlot\n );\n }\n this[slotElementObserver].observe(this, config);\n this.managePresenceObservedSlot();\n }\n\n public connectedCallback(): void {\n super.connectedCallback();\n this[startObserving]();\n }\n\n public disconnectedCallback(): void {\n this[slotElementObserver].disconnect();\n super.disconnectedCallback();\n }\n }\n return SlotPresenceObservingElement;\n}\n"]}
1
+ {"version":3,"file":"observe-slot-presence.js","sourceRoot":"","sources":["observe-slot-presence.ts"],"names":[],"mappings":"AAYA,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AA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C;QACN,CAAC;QAYO,OArBC,oBAAoB,EAqBpB,cAAc,EAAC;YACpB,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAClD,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE;gBAC5B,IAAI,CAAC,mBAAmB,CAAC,GAAG,IAAI,gBAAgB,CAC5C,IAAI,CAAC,0BAA0B,CAClC,CAAC;aACL;YACD,IAAI,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAChD,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACtC,CAAC;QAEM,iBAAiB;YACpB,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC1B,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QAC3B,CAAC;QAEM,oBAAoB;YACvB,IAAI,CAAC,mBAAmB,CAAC,CAAC,UAAU,EAAE,CAAC;YACvC,KAAK,CAAC,oBAAoB,EAAE,CAAC;QACjC,CAAC;KACJ;IACD,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';\n\nconst slotElementObserver = Symbol('slotElementObserver');\nconst startObserving = Symbol('startObserving');\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 private [slotElementObserver]!: MutationObserver;\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 \\`\\` is not being observed.`\n );\n }\n\n public managePresenceObservedSlot = (): void => {\n lightDomSelectors.forEach((selector) => {\n this[slotContentIsPresent].set(\n selector,\n !!this.querySelector(selector)\n );\n });\n this.requestUpdate();\n };\n\n private [startObserving](): void {\n const config = { childList: true, subtree: true };\n if (!this[slotElementObserver]) {\n this[slotElementObserver] = new MutationObserver(\n this.managePresenceObservedSlot\n );\n }\n this[slotElementObserver].observe(this, config);\n this.managePresenceObservedSlot();\n }\n\n public connectedCallback(): void {\n super.connectedCallback();\n this[startObserving]();\n }\n\n public disconnectedCallback(): void {\n this[slotElementObserver].disconnect();\n super.disconnectedCallback();\n }\n }\n return SlotPresenceObservingElement;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { UpdatingElement } from '@spectrum-web-components/base';
1
+ import { ReactiveElement } from '@spectrum-web-components/base';
2
2
  declare type Constructor<T = Record<string, unknown>> = {
3
3
  new (...args: any[]): T;
4
4
  prototype: T;
@@ -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<UpdatingElement>>(constructor: T, slotSelector?: string): T & Constructor<SlotTextObservingInterface>;
10
+ export declare function ObserveSlotText<T extends Constructor<ReactiveElement>>(constructor: T, slotSelector?: string): T & Constructor<SlotTextObservingInterface>;
11
11
  export {};
@@ -1,17 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
- /*
3
- Copyright 2020 Adobe. All rights reserved.
4
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License. You may obtain a copy
6
- of the License at http://www.apache.org/licenses/LICENSE-2.0
7
-
8
- Unless required by applicable law or agreed to in writing, software distributed under
9
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- OF ANY KIND, either express or implied. See the License for the specific language
11
- governing permissions and limitations under the License.
12
- */
13
- import { queryAssignedNodes, property, } from '@spectrum-web-components/base';
2
+ import { property, queryAssignedNodes, } from '@spectrum-web-components/base/src/decorators.js';
14
3
  const slotElementObserver = Symbol('slotElementObserver');
4
+ // Fix needed for: https://github.com/lit/lit/issues/1789
15
5
  const assignedNodesList = Symbol('assignedNodes');
16
6
  const startObserving = Symbol('startObserving');
17
7
  export function ObserveSlotText(constructor, slotSelector) {
@@ -1 +1 @@
1
- {"version":3,"file":"observe-slot-text.js","sourceRoot":"","sources":["observe-slot-text.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAGH,kBAAkB,EAClB,QAAQ,GACX,MAAM,+BAA+B,CAAC;AAEvC,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC1D,MAAM,iBAAiB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAClD,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAahD,MAAM,UAAU,eAAe,CAC3B,WA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AI,EAAE,MAAM,CAAC,CAAC;QACpD,CAAC;QAEM,iBAAiB;YACpB,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC1B,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QAC3B,CAAC;QAEM,oBAAoB;YACvB,IAAI,IAAI,CAAC,mBAAmB,CAAC,EAAE;gBAC3B,IAAI,CAAC,mBAAmB,CAAC,CAAC,UAAU,EAAE,CAAC;aAC1C;YACD,KAAK,CAAC,oBAAoB,EAAE,CAAC;QACjC,CAAC;KACJ;IAnDG;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oEAChB;IAG9B;QADC,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC;sDACe;IAiD1D,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 {\n PropertyValues,\n UpdatingElement,\n queryAssignedNodes,\n property,\n} from '@spectrum-web-components/base';\n\nconst slotElementObserver = Symbol('slotElementObserver');\nconst assignedNodesList = Symbol('assignedNodes');\nconst startObserving = Symbol('startObserving');\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<UpdatingElement>>(\n constructor: T,\n slotSelector?: string\n): T & Constructor<SlotTextObservingInterface> {\n class SlotTextObservingElement extends constructor\n implements SlotTextObservingInterface {\n private [slotElementObserver]: MutationObserver;\n\n @property({ type: Boolean, attribute: false })\n public slotHasContent = false;\n\n @queryAssignedNodes(slotSelector, 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 firstUpdated(changedProperties: PropertyValues): void {\n super.firstUpdated(changedProperties);\n this.manageTextObservedSlot();\n }\n\n private [startObserving](): void {\n const config = { characterData: true, subtree: true };\n if (!this[slotElementObserver]) {\n const callback = (\n mutationsList: Array<MutationRecord>\n ): void => {\n for (const mutation of mutationsList) {\n if (mutation.type === 'characterData') {\n this.manageTextObservedSlot();\n }\n }\n };\n this[slotElementObserver] = new MutationObserver(callback);\n }\n this[slotElementObserver].observe(this, config);\n }\n\n public connectedCallback(): void {\n super.connectedCallback();\n this[startObserving]();\n }\n\n public disconnectedCallback(): void {\n if (this[slotElementObserver]) {\n this[slotElementObserver].disconnect();\n }\n super.disconnectedCallback();\n }\n }\n return SlotTextObservingElement;\n}\n"]}
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;AAEzD,MAAM,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC1D,yDAAyD;AACzD,MAAM,iBAAiB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAClD,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAahD,MAAM,UAAU,eAAe,CAC3B,WAAc,EACd,YAAqB;;IAErB,MAAM,wBACF,SAAQ,WAAW;QADvB;;YAOW,mBAAc,GAAG,KAAK,CAAC;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C;YAC1B,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;QAC3B,CAAC;QAEM,oBAAoB;YACvB,IAAI,IAAI,CAAC,mBAAmB,CAAC,EAAE;gBAC3B,IAAI,CAAC,mBAAmB,CAAC,CAAC,UAAU,EAAE,CAAC;aAC1C;YACD,KAAK,CAAC,oBAAoB,EAAE,CAAC;QACjC,CAAC;KACJ;IAnDG;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oEAChB;IAG9B;QADC,kBAAkB,CAAC,YAAY,EAAE,IAAI,CAAC;sDACe;IAiD1D,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';\n\nconst slotElementObserver = Symbol('slotElementObserver');\n// Fix needed for: https://github.com/lit/lit/issues/1789\nconst assignedNodesList = Symbol('assignedNodes');\nconst startObserving = Symbol('startObserving');\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 slotSelector?: string\n): T & Constructor<SlotTextObservingInterface> {\n class SlotTextObservingElement\n extends constructor\n implements SlotTextObservingInterface\n {\n private [slotElementObserver]: MutationObserver;\n\n @property({ type: Boolean, attribute: false })\n public slotHasContent = false;\n\n @queryAssignedNodes(slotSelector, 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 firstUpdated(changedProperties: PropertyValues): void {\n super.firstUpdated(changedProperties);\n this.manageTextObservedSlot();\n }\n\n private [startObserving](): void {\n const config = { characterData: true, subtree: true };\n if (!this[slotElementObserver]) {\n const callback = (\n mutationsList: Array<MutationRecord>\n ): void => {\n for (const mutation of mutationsList) {\n if (mutation.type === 'characterData') {\n this.manageTextObservedSlot();\n }\n }\n };\n this[slotElementObserver] = new MutationObserver(callback);\n }\n this[slotElementObserver].observe(this, config);\n }\n\n public connectedCallback(): void {\n super.connectedCallback();\n this[startObserving]();\n }\n\n public disconnectedCallback(): void {\n if (this[slotElementObserver]) {\n this[slotElementObserver].disconnect();\n }\n super.disconnectedCallback();\n }\n }\n return SlotTextObservingElement;\n}\n"]}