@spectrum-web-components/alert-dialog 0.41.2 → 0.42.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/custom-elements.json +1 -1
- package/package.json +9 -9
- package/src/AlertDialog.dev.js +3 -3
- package/src/AlertDialog.dev.js.map +2 -2
- package/src/AlertDialog.js +6 -6
- package/src/AlertDialog.js.map +3 -3
- package/test/alert-dialog-memory.test.js +6 -0
- package/test/alert-dialog-memory.test.js.map +7 -0
package/custom-elements.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/alert-dialog",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -58,15 +58,15 @@
|
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@lit-labs/observers": "^2.0.0",
|
|
61
|
-
"@spectrum-web-components/base": "^0.
|
|
62
|
-
"@spectrum-web-components/button": "^0.
|
|
63
|
-
"@spectrum-web-components/button-group": "^0.
|
|
64
|
-
"@spectrum-web-components/divider": "^0.
|
|
65
|
-
"@spectrum-web-components/icons-workflow": "^0.
|
|
66
|
-
"@spectrum-web-components/shared": "^0.
|
|
61
|
+
"@spectrum-web-components/base": "^0.42.1",
|
|
62
|
+
"@spectrum-web-components/button": "^0.42.1",
|
|
63
|
+
"@spectrum-web-components/button-group": "^0.42.1",
|
|
64
|
+
"@spectrum-web-components/divider": "^0.42.1",
|
|
65
|
+
"@spectrum-web-components/icons-workflow": "^0.42.1",
|
|
66
|
+
"@spectrum-web-components/shared": "^0.42.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@spectrum-css/alertdialog": "^1.2.
|
|
69
|
+
"@spectrum-css/alertdialog": "^1.2.4"
|
|
70
70
|
},
|
|
71
71
|
"types": "./src/index.d.ts",
|
|
72
72
|
"customElements": "custom-elements.json",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"./**/*.dev.js",
|
|
76
76
|
"./**/*.dev.js"
|
|
77
77
|
],
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "c7ab5516e86d20194e92114afd04affa490b7248"
|
|
79
79
|
}
|
package/src/AlertDialog.dev.js
CHANGED
|
@@ -19,7 +19,8 @@ import {
|
|
|
19
19
|
query
|
|
20
20
|
} from "@spectrum-web-components/base/src/decorators.js";
|
|
21
21
|
import "@spectrum-web-components/button/sp-button.js";
|
|
22
|
-
import { FocusVisiblePolyfillMixin } from "@spectrum-web-components/shared";
|
|
22
|
+
import { FocusVisiblePolyfillMixin } from "@spectrum-web-components/shared/src/focus-visible.js";
|
|
23
|
+
import { randomID } from "@spectrum-web-components/shared/src/random-id.js";
|
|
23
24
|
import { conditionAttributeWithId } from "@spectrum-web-components/base/src/condition-attribute-with-id.js";
|
|
24
25
|
import { ResizeController } from "@lit-labs/observers/resize-controller.js";
|
|
25
26
|
import alertStyles from "./alert-dialog.css.js";
|
|
@@ -31,7 +32,6 @@ export const alertDialogVariants = [
|
|
|
31
32
|
"destructive",
|
|
32
33
|
"secondary"
|
|
33
34
|
];
|
|
34
|
-
let appliedIds = 0;
|
|
35
35
|
function gatherAppliedIdsFromSlottedChildren(slot, idBase) {
|
|
36
36
|
const assignedElements = slot.assignedElements();
|
|
37
37
|
const ids = [];
|
|
@@ -39,7 +39,7 @@ function gatherAppliedIdsFromSlottedChildren(slot, idBase) {
|
|
|
39
39
|
if (el.id) {
|
|
40
40
|
ids.push(el.id);
|
|
41
41
|
} else {
|
|
42
|
-
const id = idBase + `-${
|
|
42
|
+
const id = idBase + `-${randomID()}`;
|
|
43
43
|
el.id = id;
|
|
44
44
|
ids.push(id);
|
|
45
45
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["AlertDialog.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2023 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 CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared';\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { ResizeController } from '@lit-labs/observers/resize-controller.js';\nimport alertStyles from './alert-dialog.css.js';\n\nexport type AlertDialogVariants =\n | 'confirmation'\n | 'information'\n | 'warning'\n | 'error'\n | 'destructive'\n | 'secondary'\n | '';\n\nexport const alertDialogVariants: AlertDialogVariants[] = [\n 'confirmation',\n 'information',\n 'warning',\n 'error',\n 'destructive',\n 'secondary',\n];\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAWA;AAAA,EAEI;AAAA,EACA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,OAAO;AACP,SAAS,iCAAiC;AAC1C,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AACjC,OAAO,iBAAiB;AAWjB,aAAM,sBAA6C;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEA,
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { ResizeController } from '@lit-labs/observers/resize-controller.js';\nimport alertStyles from './alert-dialog.css.js';\n\nexport type AlertDialogVariants =\n | 'confirmation'\n | 'information'\n | 'warning'\n | 'error'\n | 'destructive'\n | 'secondary'\n | '';\n\nexport const alertDialogVariants: AlertDialogVariants[] = [\n 'confirmation',\n 'information',\n 'warning',\n 'error',\n 'destructive',\n 'secondary',\n];\n\nfunction gatherAppliedIdsFromSlottedChildren(\n slot: HTMLSlotElement,\n idBase: string\n): string[] {\n const assignedElements = slot.assignedElements();\n const ids: string[] = [];\n assignedElements.forEach((el) => {\n if (el.id) {\n ids.push(el.id);\n } else {\n const id = idBase + `-${randomID()}`;\n el.id = id;\n ids.push(id);\n }\n });\n return ids;\n}\nexport class AlertDialog extends FocusVisiblePolyfillMixin(SpectrumElement) {\n public static override get styles(): CSSResultArray {\n return [alertStyles];\n }\n\n @query('.content')\n private contentElement!: HTMLDivElement;\n\n private resizeController = new ResizeController(this, {\n callback: () => {\n this.shouldManageTabOrderForScrolling();\n },\n });\n\n public _variant: AlertDialogVariants = '';\n\n @property({ type: String, reflect: true })\n public set variant(variant: AlertDialogVariants) {\n if (variant === this.variant) {\n return;\n }\n const oldValue = this.variant;\n if (alertDialogVariants.includes(variant)) {\n this.setAttribute('variant', variant);\n this._variant = variant;\n } else {\n this.removeAttribute('variant');\n this._variant = '';\n }\n this.requestUpdate('variant', oldValue);\n }\n\n public get variant(): AlertDialogVariants {\n return this._variant;\n }\n\n protected renderIcon(): TemplateResult {\n switch (this.variant) {\n case 'warning':\n case 'error':\n return html`\n <sp-icon-alert class=\"icon\"></sp-icon-alert>\n `;\n\n default:\n return html``;\n }\n }\n\n protected renderHeading(): TemplateResult {\n return html`\n <slot name=\"heading\" @slotchange=${this.onHeadingSlotchange}></slot>\n `;\n }\n\n protected renderContent(): TemplateResult {\n return html`\n <div class=\"content\">\n <slot @slotchange=${this.onContentSlotChange}></slot>\n </div>\n `;\n }\n\n static instanceCount = 0;\n private labelledbyId = `sp-dialog-label-${AlertDialog.instanceCount++}`;\n private conditionLabelledby?: () => void;\n private conditionDescribedby?: () => void;\n\n private onHeadingSlotchange({\n target,\n }: Event & { target: HTMLSlotElement }): void {\n if (this.conditionLabelledby) {\n this.conditionLabelledby();\n delete this.conditionLabelledby;\n }\n const ids = gatherAppliedIdsFromSlottedChildren(\n target,\n this.labelledbyId\n );\n if (ids.length) {\n this.conditionLabelledby = conditionAttributeWithId(\n this,\n 'aria-labelledby',\n ids\n );\n }\n }\n\n public shouldManageTabOrderForScrolling = (): void => {\n if (!this.contentElement) return;\n\n const { offsetHeight, scrollHeight } = this.contentElement;\n if (offsetHeight < scrollHeight) {\n this.contentElement.tabIndex = 0;\n } else {\n this.contentElement.removeAttribute('tabindex');\n }\n };\n\n private describedbyId = `sp-dialog-description-${AlertDialog.instanceCount++}`;\n\n protected onContentSlotChange({\n target,\n }: Event & { target: HTMLSlotElement }): void {\n requestAnimationFrame(() => {\n // Can happen more than once. Take this.contentElement out\n // of the observer before adding it again.\n this.resizeController.unobserve(this.contentElement);\n this.resizeController.observe(this.contentElement);\n });\n if (this.conditionDescribedby) {\n this.conditionDescribedby();\n delete this.conditionDescribedby;\n }\n const ids = gatherAppliedIdsFromSlottedChildren(\n target,\n this.describedbyId\n );\n if (ids.length && ids.length < 4) {\n this.conditionDescribedby = conditionAttributeWithId(\n this,\n 'aria-describedby',\n ids\n );\n } else if (!ids.length) {\n const idProvided = !!this.id;\n if (!idProvided) this.id = this.describedbyId;\n const conditionDescribedby = conditionAttributeWithId(\n this,\n 'aria-describedby',\n this.id\n );\n this.conditionDescribedby = () => {\n conditionDescribedby();\n if (!idProvided) {\n this.removeAttribute('id');\n }\n };\n }\n }\n\n protected renderButtons(): TemplateResult {\n return html`\n <sp-button-group class=\"button-group\">\n <slot name=\"button\"></slot>\n </sp-button-group>\n `;\n }\n\n protected override render(): TemplateResult {\n return html`\n <div class=\"grid\">\n <div class=\"header\">\n ${this.renderHeading()} ${this.renderIcon()}\n </div>\n <sp-divider size=\"m\" class=\"divider\"></sp-divider>\n ${this.renderContent()} ${this.renderButtons()}\n </div>\n `;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAWA;AAAA,EAEI;AAAA,EACA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,OAAO;AACP,SAAS,iCAAiC;AAC1C,SAAS,gBAAgB;AACzB,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AACjC,OAAO,iBAAiB;AAWjB,aAAM,sBAA6C;AAAA,EACtD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ;AAEA,SAAS,oCACL,MACA,QACQ;AACR,QAAM,mBAAmB,KAAK,iBAAiB;AAC/C,QAAM,MAAgB,CAAC;AACvB,mBAAiB,QAAQ,CAAC,OAAO;AAC7B,QAAI,GAAG,IAAI;AACP,UAAI,KAAK,GAAG,EAAE;AAAA,IAClB,OAAO;AACH,YAAM,KAAK,SAAS,IAAI,SAAS,CAAC;AAClC,SAAG,KAAK;AACR,UAAI,KAAK,EAAE;AAAA,IACf;AAAA,EACJ,CAAC;AACD,SAAO;AACX;AACO,MAAM,eAAN,MAAM,qBAAoB,0BA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AAA,kBAG7C,KAAK,cAAc,CAAC,IAAI,KAAK,cAAc,CAAC;AAAA;AAAA;AAAA,EAG1D;AACJ;AAhKa,aA+DF,gBAAgB;AAzDf;AAAA,EADP,MAAM,UAAU;AAAA,GALR,aAMD;AAWG;AAAA,EADV,SAAS,EAAE,MAAM,QAAQ,SAAS,KAAK,CAAC;AAAA,GAhBhC,aAiBE;AAjBR,WAAM,cAAN;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/AlertDialog.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=(a,r,e,t)=>{for(var i=t>1?void 0:t?u(r,e):r,n=a.length-1,d;n>=0;n--)(d=a[n])&&(i=(t?d(r,e,i):d(i))||i);return t&&i&&b(r,e,i),i};import{html as s,SpectrumElement as p}from"@spectrum-web-components/base";import{property as m,query as g}from"@spectrum-web-components/base/src/decorators.js";import"@spectrum-web-components/button/sp-button.js";import{FocusVisiblePolyfillMixin as v}from"@spectrum-web-components/shared/src/focus-visible.js";import{randomID as y}from"@spectrum-web-components/shared/src/random-id.js";import{conditionAttributeWithId as c}from"@spectrum-web-components/base/src/condition-attribute-with-id.js";import{ResizeController as f}from"@lit-labs/observers/resize-controller.js";import E from"./alert-dialog.css.js";export const alertDialogVariants=["confirmation","information","warning","error","destructive","secondary"];function h(a,r){const e=a.assignedElements(),t=[];return e.forEach(i=>{if(i.id)t.push(i.id);else{const n=r+`-${y()}`;i.id=n,t.push(n)}}),t}const o=class o extends v(p){constructor(){super(...arguments);this.resizeController=new f(this,{callback:()=>{this.shouldManageTabOrderForScrolling()}});this._variant="";this.labelledbyId=`sp-dialog-label-${o.instanceCount++}`;this.shouldManageTabOrderForScrolling=()=>{if(!this.contentElement)return;const{offsetHeight:e,scrollHeight:t}=this.contentElement;e<t?this.contentElement.tabIndex=0:this.contentElement.removeAttribute("tabindex")};this.describedbyId=`sp-dialog-description-${o.instanceCount++}`}static get styles(){return[E]}set variant(e){if(e===this.variant)return;const t=this.variant;alertDialogVariants.includes(e)?(this.setAttribute("variant",e),this._variant=e):(this.removeAttribute("variant"),this._variant=""),this.requestUpdate("variant",t)}get variant(){return this._variant}renderIcon(){switch(this.variant){case"warning":case"error":return s`
|
|
2
2
|
<sp-icon-alert class="icon"></sp-icon-alert>
|
|
3
|
-
`;default:return
|
|
3
|
+
`;default:return s``}}renderHeading(){return s`
|
|
4
4
|
<slot name="heading" @slotchange=${this.onHeadingSlotchange}></slot>
|
|
5
|
-
`}renderContent(){return
|
|
5
|
+
`}renderContent(){return s`
|
|
6
6
|
<div class="content">
|
|
7
7
|
<slot @slotchange=${this.onContentSlotChange}></slot>
|
|
8
8
|
</div>
|
|
9
|
-
`}onHeadingSlotchange({target:e}){this.conditionLabelledby&&(this.conditionLabelledby(),delete this.conditionLabelledby);const t=h(e,this.labelledbyId);t.length&&(this.conditionLabelledby=c(this,"aria-labelledby",t))}onContentSlotChange({target:e}){requestAnimationFrame(()=>{this.resizeController.unobserve(this.contentElement),this.resizeController.observe(this.contentElement)}),this.conditionDescribedby&&(this.conditionDescribedby(),delete this.conditionDescribedby);const t=h(e,this.describedbyId);if(t.length&&t.length<4)this.conditionDescribedby=c(this,"aria-describedby",t);else if(!t.length){const i=!!this.id;i||(this.id=this.describedbyId);const n=c(this,"aria-describedby",this.id);this.conditionDescribedby=()=>{n(),i||this.removeAttribute("id")}}}renderButtons(){return
|
|
9
|
+
`}onHeadingSlotchange({target:e}){this.conditionLabelledby&&(this.conditionLabelledby(),delete this.conditionLabelledby);const t=h(e,this.labelledbyId);t.length&&(this.conditionLabelledby=c(this,"aria-labelledby",t))}onContentSlotChange({target:e}){requestAnimationFrame(()=>{this.resizeController.unobserve(this.contentElement),this.resizeController.observe(this.contentElement)}),this.conditionDescribedby&&(this.conditionDescribedby(),delete this.conditionDescribedby);const t=h(e,this.describedbyId);if(t.length&&t.length<4)this.conditionDescribedby=c(this,"aria-describedby",t);else if(!t.length){const i=!!this.id;i||(this.id=this.describedbyId);const n=c(this,"aria-describedby",this.id);this.conditionDescribedby=()=>{n(),i||this.removeAttribute("id")}}}renderButtons(){return s`
|
|
10
10
|
<sp-button-group class="button-group">
|
|
11
11
|
<slot name="button"></slot>
|
|
12
12
|
</sp-button-group>
|
|
13
|
-
`}render(){return
|
|
13
|
+
`}render(){return s`
|
|
14
14
|
<div class="grid">
|
|
15
15
|
<div class="header">
|
|
16
16
|
${this.renderHeading()} ${this.renderIcon()}
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
<sp-divider size="m" class="divider"></sp-divider>
|
|
19
19
|
${this.renderContent()} ${this.renderButtons()}
|
|
20
20
|
</div>
|
|
21
|
-
`}};
|
|
21
|
+
`}};o.instanceCount=0,l([g(".content")],o.prototype,"contentElement",2),l([m({type:String,reflect:!0})],o.prototype,"variant",1);export let AlertDialog=o;
|
|
22
22
|
//# sourceMappingURL=AlertDialog.js.map
|
package/src/AlertDialog.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["AlertDialog.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2023 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 CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared';\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { ResizeController } from '@lit-labs/observers/resize-controller.js';\nimport alertStyles from './alert-dialog.css.js';\n\nexport type AlertDialogVariants =\n | 'confirmation'\n | 'information'\n | 'warning'\n | 'error'\n | 'destructive'\n | 'secondary'\n | '';\n\nexport const alertDialogVariants: AlertDialogVariants[] = [\n 'confirmation',\n 'information',\n 'warning',\n 'error',\n 'destructive',\n 'secondary',\n];\n\
|
|
5
|
-
"mappings": "qNAWA,OAEI,QAAAA,EACA,mBAAAC,MAEG,gCACP,OACI,YAAAC,EACA,SAAAC,MACG,kDACP,MAAO,+CACP,OAAS,6BAAAC,MAAiC,
|
|
6
|
-
"names": ["html", "SpectrumElement", "property", "query", "FocusVisiblePolyfillMixin", "
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport '@spectrum-web-components/button/sp-button.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';\nimport { randomID } from '@spectrum-web-components/shared/src/random-id.js';\nimport { conditionAttributeWithId } from '@spectrum-web-components/base/src/condition-attribute-with-id.js';\nimport { ResizeController } from '@lit-labs/observers/resize-controller.js';\nimport alertStyles from './alert-dialog.css.js';\n\nexport type AlertDialogVariants =\n | 'confirmation'\n | 'information'\n | 'warning'\n | 'error'\n | 'destructive'\n | 'secondary'\n | '';\n\nexport const alertDialogVariants: AlertDialogVariants[] = [\n 'confirmation',\n 'information',\n 'warning',\n 'error',\n 'destructive',\n 'secondary',\n];\n\nfunction gatherAppliedIdsFromSlottedChildren(\n slot: HTMLSlotElement,\n idBase: string\n): string[] {\n const assignedElements = slot.assignedElements();\n const ids: string[] = [];\n assignedElements.forEach((el) => {\n if (el.id) {\n ids.push(el.id);\n } else {\n const id = idBase + `-${randomID()}`;\n el.id = id;\n ids.push(id);\n }\n });\n return ids;\n}\nexport class AlertDialog extends FocusVisiblePolyfillMixin(SpectrumElement) {\n public static override get styles(): CSSResultArray {\n return [alertStyles];\n }\n\n @query('.content')\n private contentElement!: HTMLDivElement;\n\n private resizeController = new ResizeController(this, {\n callback: () => {\n this.shouldManageTabOrderForScrolling();\n },\n });\n\n public _variant: AlertDialogVariants = '';\n\n @property({ type: String, reflect: true })\n public set variant(variant: AlertDialogVariants) {\n if (variant === this.variant) {\n return;\n }\n const oldValue = this.variant;\n if (alertDialogVariants.includes(variant)) {\n this.setAttribute('variant', variant);\n this._variant = variant;\n } else {\n this.removeAttribute('variant');\n this._variant = '';\n }\n this.requestUpdate('variant', oldValue);\n }\n\n public get variant(): AlertDialogVariants {\n return this._variant;\n }\n\n protected renderIcon(): TemplateResult {\n switch (this.variant) {\n case 'warning':\n case 'error':\n return html`\n <sp-icon-alert class=\"icon\"></sp-icon-alert>\n `;\n\n default:\n return html``;\n }\n }\n\n protected renderHeading(): TemplateResult {\n return html`\n <slot name=\"heading\" @slotchange=${this.onHeadingSlotchange}></slot>\n `;\n }\n\n protected renderContent(): TemplateResult {\n return html`\n <div class=\"content\">\n <slot @slotchange=${this.onContentSlotChange}></slot>\n </div>\n `;\n }\n\n static instanceCount = 0;\n private labelledbyId = `sp-dialog-label-${AlertDialog.instanceCount++}`;\n private conditionLabelledby?: () => void;\n private conditionDescribedby?: () => void;\n\n private onHeadingSlotchange({\n target,\n }: Event & { target: HTMLSlotElement }): void {\n if (this.conditionLabelledby) {\n this.conditionLabelledby();\n delete this.conditionLabelledby;\n }\n const ids = gatherAppliedIdsFromSlottedChildren(\n target,\n this.labelledbyId\n );\n if (ids.length) {\n this.conditionLabelledby = conditionAttributeWithId(\n this,\n 'aria-labelledby',\n ids\n );\n }\n }\n\n public shouldManageTabOrderForScrolling = (): void => {\n if (!this.contentElement) return;\n\n const { offsetHeight, scrollHeight } = this.contentElement;\n if (offsetHeight < scrollHeight) {\n this.contentElement.tabIndex = 0;\n } else {\n this.contentElement.removeAttribute('tabindex');\n }\n };\n\n private describedbyId = `sp-dialog-description-${AlertDialog.instanceCount++}`;\n\n protected onContentSlotChange({\n target,\n }: Event & { target: HTMLSlotElement }): void {\n requestAnimationFrame(() => {\n // Can happen more than once. Take this.contentElement out\n // of the observer before adding it again.\n this.resizeController.unobserve(this.contentElement);\n this.resizeController.observe(this.contentElement);\n });\n if (this.conditionDescribedby) {\n this.conditionDescribedby();\n delete this.conditionDescribedby;\n }\n const ids = gatherAppliedIdsFromSlottedChildren(\n target,\n this.describedbyId\n );\n if (ids.length && ids.length < 4) {\n this.conditionDescribedby = conditionAttributeWithId(\n this,\n 'aria-describedby',\n ids\n );\n } else if (!ids.length) {\n const idProvided = !!this.id;\n if (!idProvided) this.id = this.describedbyId;\n const conditionDescribedby = conditionAttributeWithId(\n this,\n 'aria-describedby',\n this.id\n );\n this.conditionDescribedby = () => {\n conditionDescribedby();\n if (!idProvided) {\n this.removeAttribute('id');\n }\n };\n }\n }\n\n protected renderButtons(): TemplateResult {\n return html`\n <sp-button-group class=\"button-group\">\n <slot name=\"button\"></slot>\n </sp-button-group>\n `;\n }\n\n protected override render(): TemplateResult {\n return html`\n <div class=\"grid\">\n <div class=\"header\">\n ${this.renderHeading()} ${this.renderIcon()}\n </div>\n <sp-divider size=\"m\" class=\"divider\"></sp-divider>\n ${this.renderContent()} ${this.renderButtons()}\n </div>\n `;\n }\n}\n"],
|
|
5
|
+
"mappings": "qNAWA,OAEI,QAAAA,EACA,mBAAAC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CACxC,OAAOA;AAAA;AAAA;AAAA,sBAGO,KAAK,cAAc,CAAC,IAAI,KAAK,WAAW,CAAC;AAAA;AAAA;AAAA,kBAG7C,KAAK,cAAc,CAAC,IAAI,KAAK,cAAc,CAAC;AAAA;AAAA,SAG1D,CACJ,EAhKagB,EA+DF,cAAgB,EAzDfQ,EAAA,CADPrB,EAAM,UAAU,GALRa,EAMD,8BAWGQ,EAAA,CADVtB,EAAS,CAAE,KAAM,OAAQ,QAAS,EAAK,CAAC,GAhBhCc,EAiBE,uBAjBR,WAAM,YAANA",
|
|
6
|
+
"names": ["html", "SpectrumElement", "property", "query", "FocusVisiblePolyfillMixin", "randomID", "conditionAttributeWithId", "ResizeController", "alertStyles", "gatherAppliedIdsFromSlottedChildren", "slot", "idBase", "assignedElements", "ids", "el", "id", "_AlertDialog", "offsetHeight", "scrollHeight", "variant", "oldValue", "target", "idProvided", "conditionDescribedby", "__decorateClass"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { fixture } from "@open-wc/testing";
|
|
3
|
+
import { confirmation } from "../stories/alert-dialog.stories.js";
|
|
4
|
+
import { testForMemoryLeaks } from "../../../test/testing-helpers.js";
|
|
5
|
+
testForMemoryLeaks(async () => await fixture(confirmation()));
|
|
6
|
+
//# sourceMappingURL=alert-dialog-memory.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["alert-dialog-memory.test.ts"],
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2023 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 { fixture } from '@open-wc/testing';\nimport { confirmation } from '../stories/alert-dialog.stories.js';\nimport { AlertDialog } from '@spectrum-web-components/alert-dialog';\nimport { testForMemoryLeaks } from '../../../test/testing-helpers.js';\n\ntestForMemoryLeaks(async () => await fixture<AlertDialog>(confirmation()));\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAE7B,SAAS,0BAA0B;AAEnC,mBAAmB,YAAY,MAAM,QAAqB,aAAa,CAAC,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|