@spectrum-web-components/sidenav 0.13.7 → 0.13.8
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/sidenav",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
"lit-html"
|
|
76
76
|
],
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@spectrum-web-components/base": "^0.7.
|
|
78
|
+
"@spectrum-web-components/base": "^0.7.4",
|
|
79
79
|
"@spectrum-web-components/reactive-controllers": "^0.3.5",
|
|
80
|
-
"@spectrum-web-components/shared": "^0.15.
|
|
80
|
+
"@spectrum-web-components/shared": "^0.15.5"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@spectrum-css/sidenav": "^3.0.25"
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"./sp-*.js",
|
|
89
89
|
"./**/*.dev.js"
|
|
90
90
|
],
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "6b88f4e9d596e410c2f9ed2272bc7d8d961eed1e"
|
|
92
92
|
}
|
package/src/SidenavItem.dev.js
CHANGED
|
@@ -53,7 +53,7 @@ const _SideNavItem = class extends LikeAnchor(Focusable) {
|
|
|
53
53
|
if (!this.href && event) {
|
|
54
54
|
event.preventDefault();
|
|
55
55
|
}
|
|
56
|
-
if (!this.disabled) {
|
|
56
|
+
if (!this.disabled && (!this.href || (event == null ? void 0 : event.defaultPrevented))) {
|
|
57
57
|
if (this.hasChildren) {
|
|
58
58
|
this.expanded = !this.expanded;
|
|
59
59
|
} else if (this.value) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["SidenavItem.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\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';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\n\nimport { SideNav, SidenavSelectDetail } from './Sidenav.dev.js'\n\nimport sidenavItemStyles from './sidenav-item.css.js';\n\n/**\n * @element sp-sidenav-item\n *\n * @slot - the Sidenav Items to display as children of this item\n */\nexport class SideNavItem extends LikeAnchor(Focusable) {\n public static override get styles(): CSSResultArray {\n return [sidenavItemStyles];\n }\n\n @property()\n public value: string | undefined = undefined;\n\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: Boolean, reflect: true })\n public expanded = false;\n\n protected get parentSideNav(): SideNav | undefined {\n if (!this._parentSidenav) {\n this._parentSidenav = this.closest('sp-sidenav') as\n | SideNav\n | undefined;\n }\n return this._parentSidenav;\n }\n\n protected _parentSidenav?: SideNav;\n\n protected get hasChildren(): boolean {\n return !!this.querySelector('sp-sidenav-item');\n }\n\n protected get depth(): number {\n let depth = 0;\n let element = this.parentElement;\n while (element instanceof SideNavItem) {\n depth++;\n element = element.parentElement;\n }\n return depth;\n }\n\n public handleSideNavSelect(event: Event): void {\n this.selected = event.target === this;\n }\n\n protected handleClick(event?: Event): void {\n if (!this.href && event) {\n event.preventDefault();\n }\n if (!this.disabled) {\n if (this.hasChildren) {\n this.expanded = !this.expanded;\n } else if (this.value) {\n this.announceSelected(this.value);\n }\n }\n }\n\n private announceSelected(value: string): void {\n const selectDetail: SidenavSelectDetail = {\n value,\n };\n\n const selectionEvent = new CustomEvent('sidenav-select', {\n bubbles: true,\n composed: true,\n detail: selectDetail,\n });\n\n this.dispatchEvent(selectionEvent);\n }\n\n public override click(): void {\n this.handleClick();\n }\n\n public override get focusElement(): HTMLElement {\n return this.shadowRoot.querySelector('#item-link') as HTMLElement;\n }\n\n protected override update(changes: PropertyValues): void {\n if (!this.hasAttribute('slot')) {\n this.slot = 'descendant';\n }\n super.update(changes);\n }\n\n protected override render(): TemplateResult {\n return html`\n <a\n href=${this.href || '#'}\n target=${ifDefined(this.target)}\n download=${ifDefined(this.download)}\n rel=${ifDefined(this.rel)}\n data-level=\"${this.depth}\"\n @click=\"${this.handleClick}\"\n id=\"item-link\"\n aria-current=${ifDefined(\n this.selected && this.href ? 'page' : undefined\n )}\n >\n <slot name=\"icon\"></slot>\n ${this.label}\n <slot></slot>\n </a>\n ${this.expanded\n ? html`\n <slot name=\"descendant\"></slot>\n `\n : html``}\n `;\n }\n\n protected override updated(changes: PropertyValues): void {\n if (this.hasChildren && this.expanded && !this.selected) {\n this.focusElement.tabIndex = -1;\n }\n super.updated(changes);\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.startTrackingSelection();\n }\n\n public override disconnectedCallback(): void {\n this.stopTrackingSelection();\n super.disconnectedCallback();\n }\n\n private async startTrackingSelection(): Promise<void> {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n await parentSideNav.updateComplete;\n parentSideNav.startTrackingSelectionForItem(this);\n this.selected =\n this.value != null && this.value === parentSideNav.value;\n }\n }\n\n private stopTrackingSelection(): void {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n parentSideNav.stopTrackingSelectionForItem(this);\n }\n this._parentSidenav = undefined;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,OAGG;AACP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAI1B,OAAO,uBAAuB;AAOvB,MAAM,eAAN,cAA0B,WAAW,SAAS,EAAE;AAAA,EAAhD;AAAA;AAMH,SAAO,QAA4B;AAGnC,SAAO,WAAW;AAGlB,SAAO,WAAW;AAAA;AAAA,EAXlB,WAA2B,SAAyB;AAChD,WAAO,CAAC,iBAAiB;AAAA,EAC7B;AAAA,EAWA,IAAc,gBAAqC;AAC/C,QAAI,CAAC,KAAK,gBAAgB;AACtB,WAAK,iBAAiB,KAAK,QAAQ,YAAY;AAAA,IAGnD;AACA,WAAO,KAAK;AAAA,EAChB;AAAA,EAIA,IAAc,cAAuB;AACjC,WAAO,CAAC,CAAC,KAAK,cAAc,iBAAiB;AAAA,EACjD;AAAA,EAEA,IAAc,QAAgB;AAC1B,QAAI,QAAQ;AACZ,QAAI,UAAU,KAAK;AACnB,WAAO,mBAAmB,cAAa;AACnC;AACA,gBAAU,QAAQ;AAAA,IACtB;AACA,WAAO;AAAA,EACX;AAAA,EAEO,oBAAoB,OAAoB;AAC3C,SAAK,WAAW,MAAM,WAAW;AAAA,EACrC;AAAA,EAEU,YAAY,OAAqB;AACvC,QAAI,CAAC,KAAK,QAAQ,OAAO;AACrB,YAAM,eAAe;AAAA,IACzB;
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\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';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\n\nimport { SideNav, SidenavSelectDetail } from './Sidenav.dev.js'\n\nimport sidenavItemStyles from './sidenav-item.css.js';\n\n/**\n * @element sp-sidenav-item\n *\n * @slot - the Sidenav Items to display as children of this item\n */\nexport class SideNavItem extends LikeAnchor(Focusable) {\n public static override get styles(): CSSResultArray {\n return [sidenavItemStyles];\n }\n\n @property()\n public value: string | undefined = undefined;\n\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: Boolean, reflect: true })\n public expanded = false;\n\n protected get parentSideNav(): SideNav | undefined {\n if (!this._parentSidenav) {\n this._parentSidenav = this.closest('sp-sidenav') as\n | SideNav\n | undefined;\n }\n return this._parentSidenav;\n }\n\n protected _parentSidenav?: SideNav;\n\n protected get hasChildren(): boolean {\n return !!this.querySelector('sp-sidenav-item');\n }\n\n protected get depth(): number {\n let depth = 0;\n let element = this.parentElement;\n while (element instanceof SideNavItem) {\n depth++;\n element = element.parentElement;\n }\n return depth;\n }\n\n public handleSideNavSelect(event: Event): void {\n this.selected = event.target === this;\n }\n\n protected handleClick(event?: Event): void {\n if (!this.href && event) {\n event.preventDefault();\n }\n // With an `href` this click will change the page contents, not toggle its children or become \"selected\".\n if (!this.disabled && (!this.href || event?.defaultPrevented)) {\n if (this.hasChildren) {\n this.expanded = !this.expanded;\n } else if (this.value) {\n this.announceSelected(this.value);\n }\n }\n }\n\n private announceSelected(value: string): void {\n const selectDetail: SidenavSelectDetail = {\n value,\n };\n\n const selectionEvent = new CustomEvent('sidenav-select', {\n bubbles: true,\n composed: true,\n detail: selectDetail,\n });\n\n this.dispatchEvent(selectionEvent);\n }\n\n public override click(): void {\n this.handleClick();\n }\n\n public override get focusElement(): HTMLElement {\n return this.shadowRoot.querySelector('#item-link') as HTMLElement;\n }\n\n protected override update(changes: PropertyValues): void {\n if (!this.hasAttribute('slot')) {\n this.slot = 'descendant';\n }\n super.update(changes);\n }\n\n protected override render(): TemplateResult {\n return html`\n <a\n href=${this.href || '#'}\n target=${ifDefined(this.target)}\n download=${ifDefined(this.download)}\n rel=${ifDefined(this.rel)}\n data-level=\"${this.depth}\"\n @click=\"${this.handleClick}\"\n id=\"item-link\"\n aria-current=${ifDefined(\n this.selected && this.href ? 'page' : undefined\n )}\n >\n <slot name=\"icon\"></slot>\n ${this.label}\n <slot></slot>\n </a>\n ${this.expanded\n ? html`\n <slot name=\"descendant\"></slot>\n `\n : html``}\n `;\n }\n\n protected override updated(changes: PropertyValues): void {\n if (this.hasChildren && this.expanded && !this.selected) {\n this.focusElement.tabIndex = -1;\n }\n super.updated(changes);\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.startTrackingSelection();\n }\n\n public override disconnectedCallback(): void {\n this.stopTrackingSelection();\n super.disconnectedCallback();\n }\n\n private async startTrackingSelection(): Promise<void> {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n await parentSideNav.updateComplete;\n parentSideNav.startTrackingSelectionForItem(this);\n this.selected =\n this.value != null && this.value === parentSideNav.value;\n }\n }\n\n private stopTrackingSelection(): void {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n parentSideNav.stopTrackingSelectionForItem(this);\n }\n this._parentSidenav = undefined;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,OAGG;AACP,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAI1B,OAAO,uBAAuB;AAOvB,MAAM,eAAN,cAA0B,WAAW,SAAS,EAAE;AAAA,EAAhD;AAAA;AAMH,SAAO,QAA4B;AAGnC,SAAO,WAAW;AAGlB,SAAO,WAA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GARjC,YASF;AAGA;AAAA,EADN,SAAS,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,GAXjC,YAYF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/SidenavItem.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";var h=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var s=(p,r,e,t)=>{for(var i=t>1?void 0:t?u(r,e):r,n=p.length-1,l;n>=0;n--)(l=p[n])&&(i=(t?l(r,e,i):l(i))||i);return t&&i&&h(r,e,i),i};import{html as d}from"@spectrum-web-components/base";import{property as o}from"@spectrum-web-components/base/src/decorators.js";import{ifDefined as a}from"@spectrum-web-components/base/src/directives.js";import{LikeAnchor as v}from"@spectrum-web-components/shared/src/like-anchor.js";import{Focusable as f}from"@spectrum-web-components/shared/src/focusable.js";import m from"./sidenav-item.css.js";const c=class extends v(f){constructor(){super(...arguments);this.value=void 0;this.selected=!1;this.expanded=!1}static get styles(){return[m]}get parentSideNav(){return this._parentSidenav||(this._parentSidenav=this.closest("sp-sidenav")),this._parentSidenav}get hasChildren(){return!!this.querySelector("sp-sidenav-item")}get depth(){let e=0,t=this.parentElement;for(;t instanceof c;)e++,t=t.parentElement;return e}handleSideNavSelect(e){this.selected=e.target===this}handleClick(e){!this.href&&e&&e.preventDefault(),!this.disabled&&(!this.href||e!=null&&e.defaultPrevented)&&(this.hasChildren?this.expanded=!this.expanded:this.value&&this.announceSelected(this.value))}announceSelected(e){const t={value:e},i=new CustomEvent("sidenav-select",{bubbles:!0,composed:!0,detail:t});this.dispatchEvent(i)}click(){this.handleClick()}get focusElement(){return this.shadowRoot.querySelector("#item-link")}update(e){this.hasAttribute("slot")||(this.slot="descendant"),super.update(e)}render(){return d`
|
|
2
2
|
<a
|
|
3
3
|
href=${this.href||"#"}
|
|
4
|
-
target=${
|
|
5
|
-
download=${
|
|
6
|
-
rel=${
|
|
4
|
+
target=${a(this.target)}
|
|
5
|
+
download=${a(this.download)}
|
|
6
|
+
rel=${a(this.rel)}
|
|
7
7
|
data-level="${this.depth}"
|
|
8
8
|
@click="${this.handleClick}"
|
|
9
9
|
id="item-link"
|
|
10
|
-
aria-current=${
|
|
10
|
+
aria-current=${a(this.selected&&this.href?"page":void 0)}
|
|
11
11
|
>
|
|
12
12
|
<slot name="icon"></slot>
|
|
13
13
|
${this.label}
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
${this.expanded?d`
|
|
17
17
|
<slot name="descendant"></slot>
|
|
18
18
|
`:d``}
|
|
19
|
-
`}updated(e){this.hasChildren&&this.expanded&&!this.selected&&(this.focusElement.tabIndex=-1),super.updated(e)}connectedCallback(){super.connectedCallback(),this.startTrackingSelection()}disconnectedCallback(){this.stopTrackingSelection(),super.disconnectedCallback()}async startTrackingSelection(){const e=this.parentSideNav;e&&(await e.updateComplete,e.startTrackingSelectionForItem(this),this.selected=this.value!=null&&this.value===e.value)}stopTrackingSelection(){const e=this.parentSideNav;e&&e.stopTrackingSelectionForItem(this),this._parentSidenav=void 0}};export let SideNavItem=c;
|
|
19
|
+
`}updated(e){this.hasChildren&&this.expanded&&!this.selected&&(this.focusElement.tabIndex=-1),super.updated(e)}connectedCallback(){super.connectedCallback(),this.startTrackingSelection()}disconnectedCallback(){this.stopTrackingSelection(),super.disconnectedCallback()}async startTrackingSelection(){const e=this.parentSideNav;e&&(await e.updateComplete,e.startTrackingSelectionForItem(this),this.selected=this.value!=null&&this.value===e.value)}stopTrackingSelection(){const e=this.parentSideNav;e&&e.stopTrackingSelectionForItem(this),this._parentSidenav=void 0}};export let SideNavItem=c;s([o()],SideNavItem.prototype,"value",2),s([o({type:Boolean,reflect:!0})],SideNavItem.prototype,"selected",2),s([o({type:Boolean,reflect:!0})],SideNavItem.prototype,"expanded",2);
|
|
20
20
|
//# sourceMappingURL=SidenavItem.js.map
|
package/src/SidenavItem.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["SidenavItem.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\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';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\n\nimport { SideNav, SidenavSelectDetail } from './Sidenav.js';\n\nimport sidenavItemStyles from './sidenav-item.css.js';\n\n/**\n * @element sp-sidenav-item\n *\n * @slot - the Sidenav Items to display as children of this item\n */\nexport class SideNavItem extends LikeAnchor(Focusable) {\n public static override get styles(): CSSResultArray {\n return [sidenavItemStyles];\n }\n\n @property()\n public value: string | undefined = undefined;\n\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: Boolean, reflect: true })\n public expanded = false;\n\n protected get parentSideNav(): SideNav | undefined {\n if (!this._parentSidenav) {\n this._parentSidenav = this.closest('sp-sidenav') as\n | SideNav\n | undefined;\n }\n return this._parentSidenav;\n }\n\n protected _parentSidenav?: SideNav;\n\n protected get hasChildren(): boolean {\n return !!this.querySelector('sp-sidenav-item');\n }\n\n protected get depth(): number {\n let depth = 0;\n let element = this.parentElement;\n while (element instanceof SideNavItem) {\n depth++;\n element = element.parentElement;\n }\n return depth;\n }\n\n public handleSideNavSelect(event: Event): void {\n this.selected = event.target === this;\n }\n\n protected handleClick(event?: Event): void {\n if (!this.href && event) {\n event.preventDefault();\n }\n if (!this.disabled) {\n if (this.hasChildren) {\n this.expanded = !this.expanded;\n } else if (this.value) {\n this.announceSelected(this.value);\n }\n }\n }\n\n private announceSelected(value: string): void {\n const selectDetail: SidenavSelectDetail = {\n value,\n };\n\n const selectionEvent = new CustomEvent('sidenav-select', {\n bubbles: true,\n composed: true,\n detail: selectDetail,\n });\n\n this.dispatchEvent(selectionEvent);\n }\n\n public override click(): void {\n this.handleClick();\n }\n\n public override get focusElement(): HTMLElement {\n return this.shadowRoot.querySelector('#item-link') as HTMLElement;\n }\n\n protected override update(changes: PropertyValues): void {\n if (!this.hasAttribute('slot')) {\n this.slot = 'descendant';\n }\n super.update(changes);\n }\n\n protected override render(): TemplateResult {\n return html`\n <a\n href=${this.href || '#'}\n target=${ifDefined(this.target)}\n download=${ifDefined(this.download)}\n rel=${ifDefined(this.rel)}\n data-level=\"${this.depth}\"\n @click=\"${this.handleClick}\"\n id=\"item-link\"\n aria-current=${ifDefined(\n this.selected && this.href ? 'page' : undefined\n )}\n >\n <slot name=\"icon\"></slot>\n ${this.label}\n <slot></slot>\n </a>\n ${this.expanded\n ? html`\n <slot name=\"descendant\"></slot>\n `\n : html``}\n `;\n }\n\n protected override updated(changes: PropertyValues): void {\n if (this.hasChildren && this.expanded && !this.selected) {\n this.focusElement.tabIndex = -1;\n }\n super.updated(changes);\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.startTrackingSelection();\n }\n\n public override disconnectedCallback(): void {\n this.stopTrackingSelection();\n super.disconnectedCallback();\n }\n\n private async startTrackingSelection(): Promise<void> {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n await parentSideNav.updateComplete;\n parentSideNav.startTrackingSelectionForItem(this);\n this.selected =\n this.value != null && this.value === parentSideNav.value;\n }\n }\n\n private stopTrackingSelection(): void {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n parentSideNav.stopTrackingSelectionForItem(this);\n }\n this._parentSidenav = undefined;\n }\n}\n"],
|
|
5
|
-
"mappings": "qNAYA,OAEI,QAAAA,MAGG,gCACP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,aAAAC,MAAiB,kDAC1B,OAAS,cAAAC,MAAkB,qDAC3B,OAAS,aAAAC,MAAiB,mDAI1B,OAAOC,MAAuB,wBAOvB,MAAMC,EAAN,cAA0BH,EAAWC,CAAS,CAAE,CAAhD,kCAMH,KAAO,MAA4B,OAGnC,KAAO,SAAW,GAGlB,KAAO,SAAW,GAXlB,WAA2B,QAAyB,CAChD,MAAO,CAACC,CAAiB,CAC7B,CAWA,IAAc,eAAqC,CAC/C,OAAK,KAAK,iBACN,KAAK,eAAiB,KAAK,QAAQ,YAAY,GAI5C,KAAK,cAChB,CAIA,IAAc,aAAuB,CACjC,MAAO,CAAC,CAAC,KAAK,cAAc,iBAAiB,CACjD,CAEA,IAAc,OAAgB,CAC1B,IAAIE,EAAQ,EACRC,EAAU,KAAK,cACnB,KAAOA,aAAmBF,GACtBC,IACAC,EAAUA,EAAQ,cAEtB,OAAOD,CACX,CAEO,oBAAoBE,EAAoB,CAC3C,KAAK,SAAWA,EAAM,SAAW,IACrC,CAEU,YAAYA,EAAqB,CACnC,CAAC,KAAK,MAAQA,GACdA,EAAM,eAAe,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\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';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\n\nimport { SideNav, SidenavSelectDetail } from './Sidenav.js';\n\nimport sidenavItemStyles from './sidenav-item.css.js';\n\n/**\n * @element sp-sidenav-item\n *\n * @slot - the Sidenav Items to display as children of this item\n */\nexport class SideNavItem extends LikeAnchor(Focusable) {\n public static override get styles(): CSSResultArray {\n return [sidenavItemStyles];\n }\n\n @property()\n public value: string | undefined = undefined;\n\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: Boolean, reflect: true })\n public expanded = false;\n\n protected get parentSideNav(): SideNav | undefined {\n if (!this._parentSidenav) {\n this._parentSidenav = this.closest('sp-sidenav') as\n | SideNav\n | undefined;\n }\n return this._parentSidenav;\n }\n\n protected _parentSidenav?: SideNav;\n\n protected get hasChildren(): boolean {\n return !!this.querySelector('sp-sidenav-item');\n }\n\n protected get depth(): number {\n let depth = 0;\n let element = this.parentElement;\n while (element instanceof SideNavItem) {\n depth++;\n element = element.parentElement;\n }\n return depth;\n }\n\n public handleSideNavSelect(event: Event): void {\n this.selected = event.target === this;\n }\n\n protected handleClick(event?: Event): void {\n if (!this.href && event) {\n event.preventDefault();\n }\n // With an `href` this click will change the page contents, not toggle its children or become \"selected\".\n if (!this.disabled && (!this.href || event?.defaultPrevented)) {\n if (this.hasChildren) {\n this.expanded = !this.expanded;\n } else if (this.value) {\n this.announceSelected(this.value);\n }\n }\n }\n\n private announceSelected(value: string): void {\n const selectDetail: SidenavSelectDetail = {\n value,\n };\n\n const selectionEvent = new CustomEvent('sidenav-select', {\n bubbles: true,\n composed: true,\n detail: selectDetail,\n });\n\n this.dispatchEvent(selectionEvent);\n }\n\n public override click(): void {\n this.handleClick();\n }\n\n public override get focusElement(): HTMLElement {\n return this.shadowRoot.querySelector('#item-link') as HTMLElement;\n }\n\n protected override update(changes: PropertyValues): void {\n if (!this.hasAttribute('slot')) {\n this.slot = 'descendant';\n }\n super.update(changes);\n }\n\n protected override render(): TemplateResult {\n return html`\n <a\n href=${this.href || '#'}\n target=${ifDefined(this.target)}\n download=${ifDefined(this.download)}\n rel=${ifDefined(this.rel)}\n data-level=\"${this.depth}\"\n @click=\"${this.handleClick}\"\n id=\"item-link\"\n aria-current=${ifDefined(\n this.selected && this.href ? 'page' : undefined\n )}\n >\n <slot name=\"icon\"></slot>\n ${this.label}\n <slot></slot>\n </a>\n ${this.expanded\n ? html`\n <slot name=\"descendant\"></slot>\n `\n : html``}\n `;\n }\n\n protected override updated(changes: PropertyValues): void {\n if (this.hasChildren && this.expanded && !this.selected) {\n this.focusElement.tabIndex = -1;\n }\n super.updated(changes);\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.startTrackingSelection();\n }\n\n public override disconnectedCallback(): void {\n this.stopTrackingSelection();\n super.disconnectedCallback();\n }\n\n private async startTrackingSelection(): Promise<void> {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n await parentSideNav.updateComplete;\n parentSideNav.startTrackingSelectionForItem(this);\n this.selected =\n this.value != null && this.value === parentSideNav.value;\n }\n }\n\n private stopTrackingSelection(): void {\n const parentSideNav = this.parentSideNav;\n if (parentSideNav) {\n parentSideNav.stopTrackingSelectionForItem(this);\n }\n this._parentSidenav = undefined;\n }\n}\n"],
|
|
5
|
+
"mappings": "qNAYA,OAEI,QAAAA,MAGG,gCACP,OAAS,YAAAC,MAAgB,kDACzB,OAAS,aAAAC,MAAiB,kDAC1B,OAAS,cAAAC,MAAkB,qDAC3B,OAAS,aAAAC,MAAiB,mDAI1B,OAAOC,MAAuB,wBAOvB,MAAMC,EAAN,cAA0BH,EAAWC,CAAS,CAAE,CAAhD,kCAMH,KAAO,MAA4B,OAGnC,KAAO,SAAW,GAGlB,KAAO,SAAW,GAXlB,WAA2B,QAAyB,CAChD,MAAO,CAACC,CAAiB,CAC7B,CAWA,IAAc,eAAqC,C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AAA,cAGT,KAAK,SACDF;AAAA;AAAA,oBAGAA;AAAA,SAEd,CAEmB,QAAQa,EAA+B,CAClD,KAAK,aAAe,KAAK,UAAY,CAAC,KAAK,WAC3C,KAAK,aAAa,SAAW,IAEjC,MAAM,QAAQA,CAAO,CACzB,CAEgB,mBAA0B,CACtC,MAAM,kBAAkB,EACxB,KAAK,uBAAuB,CAChC,CAEgB,sBAA6B,CACzC,KAAK,sBAAsB,EAC3B,MAAM,qBAAqB,CAC/B,CAEA,MAAc,wBAAwC,CAClD,MAAMC,EAAgB,KAAK,cACvBA,IACA,MAAMA,EAAc,eACpBA,EAAc,8BAA8B,IAAI,EAChD,KAAK,SACD,KAAK,OAAS,MAAQ,KAAK,QAAUA,EAAc,MAE/D,CAEQ,uBAA8B,CAClC,MAAMA,EAAgB,KAAK,cACvBA,GACAA,EAAc,6BAA6B,IAAI,EAEnD,KAAK,eAAiB,MAC1B,CACJ,EAlJO,WAAM,YAANR,EAMIS,EAAA,CADNd,EAAS,GALD,YAMF,qBAGAc,EAAA,CADNd,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,GARjC,YASF,wBAGAc,EAAA,CADNd,EAAS,CAAE,KAAM,QAAS,QAAS,EAAK,CAAC,GAXjC,YAYF",
|
|
6
6
|
"names": ["html", "property", "ifDefined", "LikeAnchor", "Focusable", "sidenavItemStyles", "_SideNavItem", "depth", "element", "event", "value", "selectDetail", "selectionEvent", "changes", "parentSideNav", "__decorateClass"]
|
|
7
7
|
}
|