@api-client/ui 0.5.0 → 0.5.2
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/build/src/elements/highlight/MarkedHighlight.d.ts.map +1 -1
- package/build/src/elements/highlight/MarkedHighlight.js +2 -1
- package/build/src/elements/highlight/MarkedHighlight.js.map +1 -1
- package/build/src/md/button/internals/base.js +1 -1
- package/build/src/md/button/internals/base.js.map +1 -1
- package/build/src/md/dialog/internals/Dialog.d.ts +18 -0
- package/build/src/md/dialog/internals/Dialog.d.ts.map +1 -1
- package/build/src/md/dialog/internals/Dialog.js +60 -2
- package/build/src/md/dialog/internals/Dialog.js.map +1 -1
- package/build/src/md/input/Input.d.ts +4 -4
- package/build/src/md/input/Input.d.ts.map +1 -1
- package/build/src/md/input/Input.js +3 -11
- package/build/src/md/input/Input.js.map +1 -1
- package/build/src/md/text-area/internals/TextAreaElement.d.ts.map +1 -1
- package/build/src/md/text-area/internals/TextAreaElement.js +1 -2
- package/build/src/md/text-area/internals/TextAreaElement.js.map +1 -1
- package/build/src/md/text-field/internals/TextField.d.ts.map +1 -1
- package/build/src/md/text-field/internals/TextField.js +1 -2
- package/build/src/md/text-field/internals/TextField.js.map +1 -1
- package/demo/md/dialog/dialog.ts +135 -1
- package/package.json +2 -2
- package/src/elements/highlight/MarkedHighlight.ts +2 -1
- package/src/md/button/internals/base.ts +1 -1
- package/src/md/dialog/internals/Dialog.ts +54 -1
- package/src/md/input/Input.ts +4 -4
- package/src/md/text-area/internals/TextAreaElement.ts +1 -2
- package/src/md/text-field/internals/TextField.ts +4 -5
- package/test/README.md +372 -0
- package/test/dom-assertions.test.ts +182 -0
- package/test/helpers/TestUtils.ts +243 -0
- package/test/helpers/UiMock.ts +83 -13
- package/test/md/dialog/UiDialog.test.ts +169 -0
- package/test/setup.test.ts +217 -0
- package/test/setup.ts +117 -0
- package/.github/workflows/test.yml +0 -42
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,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I,IAAI;IA2CtB;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;IA6B/B;;OAEG;cACa,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB3D;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI;IAarC,SAAS,CAAC,sBAAsB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI;IAUzD,MAAM,IAAI,cAAc;CAGlC"}
|
|
@@ -203,7 +203,8 @@ let MarkedHighlight = (() => {
|
|
|
203
203
|
pedantic: this.pedantic,
|
|
204
204
|
gfm: true,
|
|
205
205
|
};
|
|
206
|
-
|
|
206
|
+
// eslint-disable-next-line no-misleading-character-class
|
|
207
|
+
let out = marked(data.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/, ''), opts);
|
|
207
208
|
if (this.sanitize) {
|
|
208
209
|
if (this.sanitizer) {
|
|
209
210
|
out = this.sanitizer(out);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkedHighlight.js","sourceRoot":"","sources":["../../../../src/elements/highlight/MarkedHighlight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkC,MAAM,KAAK,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,MAAM,EAAiB,MAAM,QAAQ,CAAA;;sBA+ED,UAAU;;;;;;;;;;;;;;;;;;;;;;iBAAlC,eAAgB,SAAQ,WAAU;;;oCAKpD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kCAO1B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oCAO1C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OA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;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,+BA2QC","sourcesContent":["import { html, LitElement, TemplateResult, PropertyValues } from 'lit'\nimport { property } from 'lit/decorators.js'\nimport DOMPurify from 'dompurify'\nimport { marked, MarkedOptions } from 'marked'\n// import { PrismHighlighter } from './PrismHighlighter.js';\n\n/**\nElement wrapper for the [marked](https://github.com/chjj/marked) library.\n\n`<marked-highlight>` accepts Markdown source and renders it to a child\nelement with the class `markdown-html`. This child element can be styled\nas you would a normal DOM element. If you do not provide a child element\nwith the `markdown-html` class, the Markdown source will still be rendered,\nbut to a shadow DOM child that cannot be styled.\n\n### Markdown Content\n\nThe Markdown source can be specified several ways:\n\n#### Use the `markdown` attribute to bind markdown\n\n```html\n<marked-highlight markdown=\"`Markdown` is _awesome_!\">\n <div slot=\"markdown-html\"></div>\n</marked-highlight>\n```\n#### Use `<script type=\"text/markdown\">` element child to inline markdown\n\n```html\n<marked-highlight>\n <div slot=\"markdown-html\"></div>\n <script type=\"text/markdown\">\n Check out my markdown!\n We can even embed elements without fear of the HTML parser mucking up their\n textual representation:\n </script>\n</marked-highlight>\n```\n#### Use `<script type=\"text/markdown\" src=\"URL\">` element child to specify remote markdown\n\n```html\n<marked-highlight>\n <div slot=\"markdown-html\"></div>\n <script type=\"text/markdown\" src=\"../guidelines.md\"></script>\n</marked-highlight>\n```\n\nNote that the `<script type=\"text/markdown\">` approach is *static*. Changes to\nthe script content will *not* update the rendered markdown!\n\nThough, you can data bind to the `src` attribute to change the markdown.\n\n```html\n<marked-highlight>\n <div slot=\"markdown-html\"></div>\n <script type=\"text/markdown\" src$=\"[[source]]\"></script>\n</marked-highlight>\n<script>\n ...\n this.source = '../guidelines.md';\n</script>\n```\n\n### Styling\n\nIf you are using a child with the `markdown-html` class, you can style it\nas you would a regular DOM element:\n\n```css\n[slot=\"markdown-html\"] p {\n color: red;\n}\n[slot=\"markdown-html\"] td:first-child {\n padding-left: 24px;\n}\n```\n\n@fires markedrendercomplete - Event dispatched when the element renders the output.\n@fires markedloaded - Event dispatched when the element loads the script from the URL.\n@fires markedloaderror - An event dispatched when an error ocurred when downloading\n the script content. The detail has the original error.\n */\nexport default class MarkedHighlight extends LitElement {\n /**\n * The markdown source to be rendered by this element.\n * @attribute\n */\n @property({ type: String }) accessor markdown: string | undefined\n\n /**\n * Enable GFM line breaks (regular newlines instead of two spaces for\n * breaks)\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor breaks: boolean | undefined\n\n /**\n * Conform to obscure parts of markdown.pl as much as possible. Don't fix\n * any of the original markdown bugs or poor behavior.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor pedantic: boolean | undefined\n\n /**\n * Function used to customize a renderer based on the [API specified in the\n * Marked\n * library](https://github.com/chjj/marked#overriding-renderer-methods).\n * It takes one argument: a marked renderer object, which is mutated by the\n * function.\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n @property({ type: Object }) accessor renderer: Function | undefined\n\n /**\n * Sanitize the output. Ignore any HTML that has been input.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor sanitize: boolean | undefined\n\n /**\n * Function used to customize a sanitize behavior.\n * It takes one argument: element String without text Contents.\n *\n * e.g. `<div>` `<a href=\"/\">` `</p>'.\n * Note: To enable this function, must set `sanitize` to true.\n * WARNING: If you are using this option to un-trusted text, you must to\n * prevent XSS Attacks.\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n @property({ type: Object }) accessor sanitizer: Function | undefined\n\n /**\n * If true, disables the default sanitization of any markdown received by\n * a request and allows fetched un-sanitized markdown\n *\n * e.g. fetching markdown via `src` that has HTML.\n * Note: this value overrides `sanitize` if a request is made.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor disableRemoteSanitization: boolean | undefined\n\n /**\n * @returns A reference to the output element.\n */\n get outputElement(): HTMLElement | null {\n const slot = this.shadowRoot?.querySelector('slot[name=\"markdown-html\"]') as HTMLSlotElement | null\n if (!slot) {\n return null\n }\n const nodes = slot.assignedNodes()\n const child = nodes.find(\n (node) => node.nodeType === 1 && (node as HTMLElement).getAttribute('slot') === 'markdown-html'\n ) as HTMLElement | undefined\n return child || (this.shadowRoot?.querySelector('#content') as HTMLElement | null)\n }\n\n protected override willUpdate(cp: PropertyValues<this>): void {\n super.willUpdate(cp)\n if (\n cp.has('markdown') ||\n cp.has('sanitizer') ||\n cp.has('sanitize') ||\n cp.has('renderer') ||\n cp.has('pedantic') ||\n cp.has('breaks')\n ) {\n this.renderMarkdown()\n }\n }\n\n protected markdownElement?: HTMLScriptElement | null\n\n protected attachedValue = false\n\n override firstUpdated(): void {\n if (this.markdown) {\n this.renderMarkdown()\n return\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.attachedValue = true\n this.processScript()\n this.renderMarkdown()\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n this.attachedValue = false\n }\n\n protected async processScript(): Promise<void> {\n // Use the Markdown from the first `<script>` descendant whose MIME type\n // starts with \"text/markdown\". Script elements beyond the first are\n // ignored.\n const script = this.querySelector('[type=\"text/markdown\"]') as HTMLScriptElement | null\n if (!script) {\n return\n }\n this.markdownElement = script\n\n if (script.src) {\n this.requestMarkdown(script.src)\n }\n const content = script.textContent\n if (content && content.trim() !== '') {\n this.markdown = this.unindent(content)\n }\n\n const observer = new MutationObserver(this.scriptAttributeHandler.bind(this))\n observer.observe(script, { attributes: true })\n }\n\n /**\n * Renders `markdown` into this element's DOM.\n *\n * This is automatically called whenever the `markdown` property is changed.\n *\n * The only case where you should be calling this is if you are providing\n * markdown via `<script type=\"text/markdown\">` after this element has been\n * constructed (or updating that markdown).\n * @event markedrendercomplete\n */\n renderMarkdown(): void {\n if (!this.attachedValue) {\n return\n }\n const node = this.outputElement\n if (!node) {\n return\n }\n\n if (!this.markdown) {\n node.innerHTML = ''\n return\n }\n const renderer = new marked.Renderer()\n if (this.renderer) {\n this.renderer(renderer)\n }\n const data = this.markdown\n const opts: MarkedOptions = {\n renderer,\n breaks: this.breaks,\n pedantic: this.pedantic,\n gfm: true,\n }\n let out = marked(data, opts) as string\n if (this.sanitize) {\n if (this.sanitizer) {\n out = this.sanitizer(out)\n } else {\n const result = DOMPurify.sanitize(out)\n if (typeof result === 'string') {\n out = result\n } else {\n // @ts-expect-error Sometimes the result is an object!\n out = result.toString()\n }\n }\n }\n node.innerHTML = out\n this.dispatchEvent(new Event('markedrendercomplete'))\n }\n\n /**\n * Un-indents the markdown source that will be rendered.\n */\n unindent(text?: string): string {\n if (!text) {\n return ''\n }\n const lines = text.replace(/\\t/g, ' ').split('\\n')\n const indent = lines.reduce((prev: number | null, line: string): number | null => {\n if (/^\\s*$/.test(line)) {\n return prev // Completely ignore blank lines.\n }\n const match = line.match(/^(\\s*)/)\n if (!match) {\n return prev\n }\n\n const lineIndent = match[0].length\n if (prev === null) {\n return lineIndent\n }\n\n return lineIndent < prev ? lineIndent : prev\n }, null)\n\n if (indent === null) {\n return text\n }\n\n return lines.map((l) => l.substring(indent)).join('\\n')\n }\n\n /**\n * Fired when the XHR finishes loading\n */\n protected async requestMarkdown(url: string): Promise<void> {\n try {\n const response = await fetch(url, {\n headers: { accept: 'text/markdown' },\n })\n const { status } = response\n if (status === 0 || (status >= 200 && status < 300)) {\n this.sanitize = !this.disableRemoteSanitization\n this.markdown = await response.text()\n this.dispatchEvent(new Event('markedloaded'))\n } else {\n throw new Error('Unable to download the data')\n }\n } catch (e) {\n this.handleError(e as Error)\n }\n }\n\n /**\n * Fired when an error is received while fetching remote markdown content.\n */\n protected handleError(e: Error): void {\n const evt = new CustomEvent('markedloaderror', {\n composed: true,\n bubbles: true,\n cancelable: true,\n detail: e,\n })\n this.dispatchEvent(evt)\n if (!evt.defaultPrevented) {\n this.markdown = 'Failed loading markdown source'\n }\n }\n\n protected scriptAttributeHandler(mutation: MutationRecord[]): void {\n if (mutation[0].attributeName !== 'src') {\n return\n }\n const elm = this.markdownElement\n if (elm) {\n this.requestMarkdown(elm.src)\n }\n }\n\n override render(): TemplateResult {\n return html`<slot name=\"markdown-html\"><div id=\"content\"></div></slot>`\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MarkedHighlight.js","sourceRoot":"","sources":["../../../../src/elements/highlight/MarkedHighlight.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkC,MAAM,KAAK,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,MAAM,EAAiB,MAAM,QAAQ,CAAA;;sBA+ED,UAAU;;;;;;;;;;;;;;;;;;;;;;iBAAlC,eAAgB,SAAQ,WAAU;;;oCAKpD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kCAO1B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oCAO1C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oCAU1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oCAM1B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qCAY1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAU1B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YApDf,6KAAS,QAAQ,6BAAR,QAAQ,2FAAoB;YAOrB,uKAAS,MAAM,6BAAN,MAAM,uFAAqB;YAOpC,6KAAS,QAAQ,6BAAR,QAAQ,2FAAqB;YAUtD,6KAAS,QAAQ,6BAAR,QAAQ,2FAAsB;YAMvB,6KAAS,QAAQ,6BAAR,QAAQ,2FAAqB;YAYtD,gLAAS,SAAS,6BAAT,SAAS,6FAAsB;YAUxB,gOAAS,yBAAyB,6BAAzB,yBA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,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,IAAI;gBAChB,MAAM,EAAE,CAAC;aACV,CAAC,CAAA;YACF,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;YACvB,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;gBAC1B,IAAI,CAAC,QAAQ,GAAG,gCAAgC,CAAA;YAClD,CAAC;QACH,CAAC;QAES,sBAAsB,CAAC,QAA0B;YACzD,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,aAAa,KAAK,KAAK,EAAE,CAAC;gBACxC,OAAM;YACR,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAA;YAChC,IAAI,GAAG,EAAE,CAAC;gBACR,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;QAEQ,MAAM;YACb,OAAO,IAAI,CAAA,4DAA4D,CAAA;QACzE,CAAC;;;AAzVH,4DAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AACH,+BA4QC","sourcesContent":["import { html, LitElement, TemplateResult, PropertyValues } from 'lit'\nimport { property } from 'lit/decorators.js'\nimport DOMPurify from 'dompurify'\nimport { marked, MarkedOptions } from 'marked'\n// import { PrismHighlighter } from './PrismHighlighter.js';\n\n/**\nElement wrapper for the [marked](https://github.com/chjj/marked) library.\n\n`<marked-highlight>` accepts Markdown source and renders it to a child\nelement with the class `markdown-html`. This child element can be styled\nas you would a normal DOM element. If you do not provide a child element\nwith the `markdown-html` class, the Markdown source will still be rendered,\nbut to a shadow DOM child that cannot be styled.\n\n### Markdown Content\n\nThe Markdown source can be specified several ways:\n\n#### Use the `markdown` attribute to bind markdown\n\n```html\n<marked-highlight markdown=\"`Markdown` is _awesome_!\">\n <div slot=\"markdown-html\"></div>\n</marked-highlight>\n```\n#### Use `<script type=\"text/markdown\">` element child to inline markdown\n\n```html\n<marked-highlight>\n <div slot=\"markdown-html\"></div>\n <script type=\"text/markdown\">\n Check out my markdown!\n We can even embed elements without fear of the HTML parser mucking up their\n textual representation:\n </script>\n</marked-highlight>\n```\n#### Use `<script type=\"text/markdown\" src=\"URL\">` element child to specify remote markdown\n\n```html\n<marked-highlight>\n <div slot=\"markdown-html\"></div>\n <script type=\"text/markdown\" src=\"../guidelines.md\"></script>\n</marked-highlight>\n```\n\nNote that the `<script type=\"text/markdown\">` approach is *static*. Changes to\nthe script content will *not* update the rendered markdown!\n\nThough, you can data bind to the `src` attribute to change the markdown.\n\n```html\n<marked-highlight>\n <div slot=\"markdown-html\"></div>\n <script type=\"text/markdown\" src$=\"[[source]]\"></script>\n</marked-highlight>\n<script>\n ...\n this.source = '../guidelines.md';\n</script>\n```\n\n### Styling\n\nIf you are using a child with the `markdown-html` class, you can style it\nas you would a regular DOM element:\n\n```css\n[slot=\"markdown-html\"] p {\n color: red;\n}\n[slot=\"markdown-html\"] td:first-child {\n padding-left: 24px;\n}\n```\n\n@fires markedrendercomplete - Event dispatched when the element renders the output.\n@fires markedloaded - Event dispatched when the element loads the script from the URL.\n@fires markedloaderror - An event dispatched when an error ocurred when downloading\n the script content. The detail has the original error.\n */\nexport default class MarkedHighlight extends LitElement {\n /**\n * The markdown source to be rendered by this element.\n * @attribute\n */\n @property({ type: String }) accessor markdown: string | undefined\n\n /**\n * Enable GFM line breaks (regular newlines instead of two spaces for\n * breaks)\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor breaks: boolean | undefined\n\n /**\n * Conform to obscure parts of markdown.pl as much as possible. Don't fix\n * any of the original markdown bugs or poor behavior.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor pedantic: boolean | undefined\n\n /**\n * Function used to customize a renderer based on the [API specified in the\n * Marked\n * library](https://github.com/chjj/marked#overriding-renderer-methods).\n * It takes one argument: a marked renderer object, which is mutated by the\n * function.\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n @property({ type: Object }) accessor renderer: Function | undefined\n\n /**\n * Sanitize the output. Ignore any HTML that has been input.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor sanitize: boolean | undefined\n\n /**\n * Function used to customize a sanitize behavior.\n * It takes one argument: element String without text Contents.\n *\n * e.g. `<div>` `<a href=\"/\">` `</p>'.\n * Note: To enable this function, must set `sanitize` to true.\n * WARNING: If you are using this option to un-trusted text, you must to\n * prevent XSS Attacks.\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n @property({ type: Object }) accessor sanitizer: Function | undefined\n\n /**\n * If true, disables the default sanitization of any markdown received by\n * a request and allows fetched un-sanitized markdown\n *\n * e.g. fetching markdown via `src` that has HTML.\n * Note: this value overrides `sanitize` if a request is made.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor disableRemoteSanitization: boolean | undefined\n\n /**\n * @returns A reference to the output element.\n */\n get outputElement(): HTMLElement | null {\n const slot = this.shadowRoot?.querySelector('slot[name=\"markdown-html\"]') as HTMLSlotElement | null\n if (!slot) {\n return null\n }\n const nodes = slot.assignedNodes()\n const child = nodes.find(\n (node) => node.nodeType === 1 && (node as HTMLElement).getAttribute('slot') === 'markdown-html'\n ) as HTMLElement | undefined\n return child || (this.shadowRoot?.querySelector('#content') as HTMLElement | null)\n }\n\n protected override willUpdate(cp: PropertyValues<this>): void {\n super.willUpdate(cp)\n if (\n cp.has('markdown') ||\n cp.has('sanitizer') ||\n cp.has('sanitize') ||\n cp.has('renderer') ||\n cp.has('pedantic') ||\n cp.has('breaks')\n ) {\n this.renderMarkdown()\n }\n }\n\n protected markdownElement?: HTMLScriptElement | null\n\n protected attachedValue = false\n\n override firstUpdated(): void {\n if (this.markdown) {\n this.renderMarkdown()\n return\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.attachedValue = true\n this.processScript()\n this.renderMarkdown()\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n this.attachedValue = false\n }\n\n protected async processScript(): Promise<void> {\n // Use the Markdown from the first `<script>` descendant whose MIME type\n // starts with \"text/markdown\". Script elements beyond the first are\n // ignored.\n const script = this.querySelector('[type=\"text/markdown\"]') as HTMLScriptElement | null\n if (!script) {\n return\n }\n this.markdownElement = script\n\n if (script.src) {\n this.requestMarkdown(script.src)\n }\n const content = script.textContent\n if (content && content.trim() !== '') {\n this.markdown = this.unindent(content)\n }\n\n const observer = new MutationObserver(this.scriptAttributeHandler.bind(this))\n observer.observe(script, { attributes: true })\n }\n\n /**\n * Renders `markdown` into this element's DOM.\n *\n * This is automatically called whenever the `markdown` property is changed.\n *\n * The only case where you should be calling this is if you are providing\n * markdown via `<script type=\"text/markdown\">` after this element has been\n * constructed (or updating that markdown).\n * @event markedrendercomplete\n */\n renderMarkdown(): void {\n if (!this.attachedValue) {\n return\n }\n const node = this.outputElement\n if (!node) {\n return\n }\n\n if (!this.markdown) {\n node.innerHTML = ''\n return\n }\n const renderer = new marked.Renderer()\n if (this.renderer) {\n this.renderer(renderer)\n }\n const data = this.markdown\n const opts: MarkedOptions = {\n renderer,\n breaks: this.breaks,\n pedantic: this.pedantic,\n gfm: true,\n }\n // eslint-disable-next-line no-misleading-character-class\n let out = marked(data.replace(/^[\\u200B\\u200C\\u200D\\u200E\\u200F\\uFEFF]/, ''), opts) as string\n if (this.sanitize) {\n if (this.sanitizer) {\n out = this.sanitizer(out)\n } else {\n const result = DOMPurify.sanitize(out)\n if (typeof result === 'string') {\n out = result\n } else {\n // @ts-expect-error Sometimes the result is an object!\n out = result.toString()\n }\n }\n }\n node.innerHTML = out\n this.dispatchEvent(new Event('markedrendercomplete'))\n }\n\n /**\n * Un-indents the markdown source that will be rendered.\n */\n unindent(text?: string): string {\n if (!text) {\n return ''\n }\n const lines = text.replace(/\\t/g, ' ').split('\\n')\n const indent = lines.reduce((prev: number | null, line: string): number | null => {\n if (/^\\s*$/.test(line)) {\n return prev // Completely ignore blank lines.\n }\n const match = line.match(/^(\\s*)/)\n if (!match) {\n return prev\n }\n\n const lineIndent = match[0].length\n if (prev === null) {\n return lineIndent\n }\n\n return lineIndent < prev ? lineIndent : prev\n }, null)\n\n if (indent === null) {\n return text\n }\n\n return lines.map((l) => l.substring(indent)).join('\\n')\n }\n\n /**\n * Fired when the XHR finishes loading\n */\n protected async requestMarkdown(url: string): Promise<void> {\n try {\n const response = await fetch(url, {\n headers: { accept: 'text/markdown' },\n })\n const { status } = response\n if (status === 0 || (status >= 200 && status < 300)) {\n this.sanitize = !this.disableRemoteSanitization\n this.markdown = await response.text()\n this.dispatchEvent(new Event('markedloaded'))\n } else {\n throw new Error('Unable to download the data')\n }\n } catch (e) {\n this.handleError(e as Error)\n }\n }\n\n /**\n * Fired when an error is received while fetching remote markdown content.\n */\n protected handleError(e: Error): void {\n const evt = new CustomEvent('markedloaderror', {\n composed: true,\n bubbles: true,\n cancelable: true,\n detail: e,\n })\n this.dispatchEvent(evt)\n if (!evt.defaultPrevented) {\n this.markdown = 'Failed loading markdown source'\n }\n }\n\n protected scriptAttributeHandler(mutation: MutationRecord[]): void {\n if (mutation[0].attributeName !== 'src') {\n return\n }\n const elm = this.markdownElement\n if (elm) {\n this.requestMarkdown(elm.src)\n }\n }\n\n override render(): TemplateResult {\n return html`<slot name=\"markdown-html\"><div id=\"content\"></div></slot>`\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/md/button/internals/base.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAA4C,MAAM,KAAK,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEl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ACxC,CAAC;QAES,eAAe;YACvB,OAAO,IAAI,CAAA,iEAAiE,IAAmB,oBAAoB,CAAA;QACrH,CAAC;QAES,YAAY;YACpB,OAAO,IAAI,CAAA,wCAAwC,IAAI,CAAC,QAAQ,gBAAgB,CAAA;QAClF,CAAC;;;AAlWH;;;;;;;;;;GAUG;AACH","sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit'\nimport { property, query } from 'lit/decorators.js'\nimport { nanoid } from 'nanoid'\nimport { UiElement } from '../../UiElement.js'\nimport type { BeginPressConfig, EndPressConfig } from '../../../controllers/ActionController.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiRipple from '../../ripple/internals/ripple.js'\nimport { findElementInShadowRoots } from '../../../lib/Dom.js'\n\nimport '../../ripple/ui-ripple.js'\nimport '@material/web/focus/md-focus-ring.js'\n\nexport type ButtonType = 'submit' | 'reset' | 'button'\nexport type MdButtonShape = 'round' | 'square'\nexport type MdButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl'\n\n/**\n * A material design button with M3 Expressive features - CSS-native implementation.\n *\n * @slot icon - A slot for the icon element\n * @slot - The default slot for the label\n * @attribute {string} form - The form associated with this element when the element is outside the form.\n * @fires {ToggleEvent} toggle - Fired when the `toggle` property is true and the button is clicked,\n * changing its selection state.\n * The event's `newState` and `oldState` properties (string values: 'selected' or\n * 'unselected') detail this selection change.\n */\nexport default class BaseButton extends UiElement {\n static readonly formAssociated = true\n\n #internals = this.attachInternals()\n\n /**\n * The form associated with this element\n * @attribute\n */\n get form(): HTMLFormElement | null | string {\n return this.#internals.form\n }\n\n get validity() {\n return this.#internals.validity\n }\n\n get validationMessage() {\n return this.#internals.validationMessage\n }\n\n get willValidate() {\n return this.#internals.willValidate\n }\n\n /**\n * The name of the button, submitted as a pair with the button's value as part of the form data.\n * @attribute\n */\n @property({ type: String }) accessor name: string | undefined\n\n #value?: string\n\n get value(): string | undefined {\n return this.#value\n }\n\n /**\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @attribute\n */\n @property({ type: String })\n set value(value: string | undefined) {\n if (this.#value === value) {\n return\n }\n this.#value = value\n this.#internals?.setFormValue(value || null)\n }\n\n /**\n * Whether to render the icon at the inline end of the label rather than the inline start.\n * @attribute\n */\n @property({ type: Boolean, attribute: 'trailingicon', reflect: true }) accessor trailingIcon = false\n\n /**\n * The default behavior of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor type: ButtonType = 'button'\n\n /**\n * When set, the button is a toggle button.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor toggle = false\n\n /**\n * Indicates that the button is currently selected.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor selected = false\n\n /**\n * The shape of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor shape: MdButtonShape = 'round'\n\n /**\n * The size of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor size: MdButtonSize = 's'\n\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is in a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n @query('ui-ripple') protected accessor ripple!: UiRipple | null\n\n /**\n * Turns a `<ui-button>` element into a popover control button; takes the ID\n * of the popover element to control as its value.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor popoverTarget: string | undefined\n /**\n * Specifies the action to be performed on a popover element being controlled\n * by a control <ui-button>. Possible values are:\n *\n * - `hide` - The button will hide a shown popover. If you try to hide an already hidden popover,\n * no action will be taken.\n * - `show` - The button will show a hidden popover. If you try to show an already showing popover,\n * no action will be taken.\n * - `toggle` - The button will toggle a popover between showing and hidden. If the popover is hidden,\n * it will be shown; if the popover is showing, it will be hidden. If popoverTargetAction is omitted,\n * \"toggle\" is the default action that will be performed by the control button.\n */\n @property({ type: String, reflect: true }) accessor popoverTargetAction: string | undefined\n\n constructor() {\n super()\n this.actionController.cancelKeyboardEvents = true\n this.addEventListener('keydown', this.handleKeyDown.bind(this))\n this.addEventListener('keyup', this.handleKeyUp.bind(this))\n this.addEventListener('click', this.handleClick.bind(this))\n this.addEventListener('pointerdown', this.handlePointerDown.bind(this))\n this.addEventListener('pointerup', this.handlePointerUp.bind(this))\n this.addEventListener('pointercancel', this.handlePointerCancel.bind(this))\n this.addEventListener('pointerleave', this.handlePointerLeave.bind(this))\n this.addEventListener('pointerenter', this.handlePointerEnter.bind(this))\n this.addEventListener('contextmenu', this.handleContextMenu.bind(this))\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'button')\n }\n if (!this.hasAttribute('tabindex') && !this.disabled) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n protected override update(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('popoverTarget')) {\n this.setupPopoverTarget()\n }\n super.update(changedProperties)\n }\n\n protected override updated(cp: PropertyValues<this>): void {\n super.updated(cp)\n\n // If the button is disabled, remove the tabindex attribute\n if (cp.has('disabled')) {\n if (this.disabled) {\n this.removeAttribute('tabindex')\n } else if (!this.hasAttribute('tabindex')) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n if (cp.has('toggle') || cp.has('selected')) {\n this.updatePressedState()\n }\n }\n\n protected updatePressedState(): void {\n if (this.toggle) {\n this.ariaPressed = String(this.selected)\n } else {\n this.selected = false\n this.removeAttribute('aria-pressed')\n }\n }\n\n checkValidity() {\n return this.#internals.checkValidity()\n }\n\n reportValidity() {\n return this.#internals.reportValidity()\n }\n\n protected override firstUpdated(): void {\n this.#internals?.setFormValue(this.value || null)\n }\n\n override beginPress(options: BeginPressConfig): void {\n super.beginPress(options)\n this.classList.add('pressed')\n this.ripple?.beginFocus()\n }\n\n override endPress(config: EndPressConfig): void {\n super.endPress(config)\n this.classList.remove('pressed')\n this.ripple?.endFocus()\n const { cancelled, reason } = config\n if (cancelled) {\n return\n }\n const allowedReasons = reason === 'enter' || reason === 'space'\n if (this.type === 'submit' && (!reason || allowedReasons)) {\n this.handleSubmit()\n } else if (allowedReasons) {\n this.click()\n }\n }\n\n override handleClick(e: MouseEvent): void {\n super.handleClick(e)\n if (this.disabled) {\n e.preventDefault()\n e.stopPropagation()\n return\n }\n\n if (this.toggle) {\n this.selected = !this.selected\n const e = new ToggleEvent('toggle', {\n bubbles: true,\n composed: true,\n newState: this.selected ? 'selected' : 'unselected',\n oldState: this.selected ? 'unselected' : 'selected',\n })\n this.dispatchEvent(e)\n }\n this.handlePopoverAction()\n this.endPress({ cancelled: false, actionData: { event: e } })\n }\n\n protected setupPopoverTarget(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n // A regular button first sets its value to the popover target ID,\n this.value = id\n // create an anchor association with the popover target\n if (!this.id) {\n this.id = nanoid()\n }\n const anchorName = `--anchor-${this.id}`\n this.style.setProperty('anchor-name', anchorName)\n element.style.setProperty('position-anchor', anchorName)\n this.setAttribute('aria-details', id)\n this.setAttribute('aria-controls', id)\n }\n\n /**\n * When the button has a popover target, this method toggles the popover\n * visibility by finding the element in the shadow roots and calling its\n * `togglePopover` method.\n */\n protected handlePopoverAction(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n const action = this.popoverTargetAction || 'toggle'\n if (action === 'hide') {\n element.hidePopover()\n } else if (action === 'show') {\n element.showPopover()\n } else {\n element.togglePopover()\n }\n element.focus()\n }\n\n protected handleSubmit(): void {\n const { name, value, type, disabled, form } = this\n if (!form || !type || disabled) {\n return\n }\n const typedForm = form as HTMLFormElement\n let button: HTMLButtonElement | undefined\n if (name || value) {\n button = document.createElement('button')\n if (name) {\n button.name = name\n }\n if (value) {\n button.value = value\n }\n button.type = type\n button.hidden = true\n typedForm.append(button)\n }\n try {\n typedForm.requestSubmit(button)\n } catch {\n // Ignore errors\n }\n if (button) {\n typedForm.removeChild(button)\n }\n }\n\n override handlePointerEnter(e: PointerEvent): void {\n super.handlePointerEnter(e)\n this.ripple?.beginHover(e)\n }\n\n override handlePointerLeave(e: PointerEvent): void {\n super.handlePointerLeave(e)\n this.ripple?.endHover()\n }\n\n protected override render(): TemplateResult {\n const { trailingIcon = false } = this\n const icon = this.renderIcon()\n\n return html`\n ${this.renderFocusRing()} ${this.renderRipple()} ${trailingIcon ? nothing : icon}\n <slot></slot>\n ${trailingIcon ? icon : nothing}\n `\n }\n\n protected renderIcon(): TemplateResult {\n return html`<slot name=\"icon\"></slot>`\n }\n\n protected renderFocusRing(): TemplateResult {\n return html`<md-focus-ring part=\"focus-ring\" class=\"focus-ring\" .control=\"${this as HTMLElement}\"></md-focus-ring>`\n }\n\n protected renderRipple(): TemplateResult {\n return html`<ui-ripple class=\"ripple\" ?disabled=\"${this.disabled}\"></ui-ripple>`\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/md/button/internals/base.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAA4C,MAAM,KAAK,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAE9D,OAAO,2BAA2B,CAAA;AAClC,OAAO,sCAAsC,CAAA;;sBAiBL,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA5B,UAAW,SAAQ,WAAS;;;gCA6B9C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qCAY1B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,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BACH,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;YACjC,CAAC;YAAC,MAAM,CAAC;gBACP,gBAAgB;YAClB,CAAC;YACD,IAAI,MAAM,EAAE,CAAC;gBACX,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;QAEQ,kBAAkB,CAAC,CAAe;YACzC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;QAC5B,CAAC;QAEQ,kBAAkB,CAAC,CAAe;YACzC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAA;QACzB,CAAC;QAEkB,MAAM;YACvB,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,GAAG,IAAI,CAAA;YACrC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;YAE9B,OAAO,IAAI,CAAA;QACP,IAAI,CAAC,eAAe,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,IAAI,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;;QAE9E,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;KAChC,CAAA;QACH,CAAC;QAES,UAAU;YAClB,OAAO,IAAI,CAAA,2BAA2B,CAAA;QACxC,CAAC;QAES,eAAe;YACvB,OAAO,IAAI,CAAA,iEAAiE,IAAmB,oBAAoB,CAAA;QACrH,CAAC;QAES,YAAY;YACpB,OAAO,IAAI,CAAA,wCAAwC,IAAI,CAAC,QAAQ,gBAAgB,CAAA;QAClF,CAAC;;;AAlWH;;;;;;;;;;GAUG;AACH","sourcesContent":["import { html, nothing, type PropertyValues, type TemplateResult } from 'lit'\nimport { property, query } from 'lit/decorators.js'\nimport { nanoid } from 'nanoid'\nimport { UiElement } from '../../UiElement.js'\nimport type { BeginPressConfig, EndPressConfig } from '../../../controllers/ActionController.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiRipple from '../../ripple/internals/ripple.js'\nimport { findElementInShadowRoots } from '../../../lib/Dom.js'\n\nimport '../../ripple/ui-ripple.js'\nimport '@material/web/focus/md-focus-ring.js'\n\nexport type ButtonType = 'submit' | 'reset' | 'button'\nexport type MdButtonShape = 'round' | 'square'\nexport type MdButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl'\n\n/**\n * A material design button with M3 Expressive features - CSS-native implementation.\n *\n * @slot icon - A slot for the icon element\n * @slot - The default slot for the label\n * @attribute {string} form - The form associated with this element when the element is outside the form.\n * @fires {ToggleEvent} toggle - Fired when the `toggle` property is true and the button is clicked,\n * changing its selection state.\n * The event's `newState` and `oldState` properties (string values: 'selected' or\n * 'unselected') detail this selection change.\n */\nexport default class BaseButton extends UiElement {\n static readonly formAssociated = true\n\n #internals = this.attachInternals()\n\n /**\n * The form associated with this element\n * @attribute\n */\n get form(): HTMLFormElement | null | string {\n return this.#internals.form\n }\n\n get validity() {\n return this.#internals.validity\n }\n\n get validationMessage() {\n return this.#internals.validationMessage\n }\n\n get willValidate() {\n return this.#internals.willValidate\n }\n\n /**\n * The name of the button, submitted as a pair with the button's value as part of the form data.\n * @attribute\n */\n @property({ type: String }) accessor name: string | undefined\n\n #value?: string\n\n get value(): string | undefined {\n return this.#value\n }\n\n /**\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @attribute\n */\n @property({ type: String })\n set value(value: string | undefined) {\n if (this.#value === value) {\n return\n }\n this.#value = value\n this.#internals?.setFormValue(value || null)\n }\n\n /**\n * Whether to render the icon at the inline end of the label rather than the inline start.\n * @attribute\n */\n @property({ type: Boolean, attribute: 'trailingicon', reflect: true }) accessor trailingIcon = false\n\n /**\n * The default behavior of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor type: ButtonType = 'button'\n\n /**\n * When set, the button is a toggle button.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor toggle = false\n\n /**\n * Indicates that the button is currently selected.\n * @attribute\n */\n @property({ type: Boolean, reflect: true }) accessor selected = false\n\n /**\n * The shape of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor shape: MdButtonShape = 'round'\n\n /**\n * The size of the button.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor size: MdButtonSize = 's'\n\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is in a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n @query('ui-ripple') protected accessor ripple!: UiRipple | null\n\n /**\n * Turns a `<ui-button>` element into a popover control button; takes the ID\n * of the popover element to control as its value.\n * @attribute\n */\n @property({ type: String, reflect: true }) accessor popoverTarget: string | undefined\n /**\n * Specifies the action to be performed on a popover element being controlled\n * by a control <ui-button>. Possible values are:\n *\n * - `hide` - The button will hide a shown popover. If you try to hide an already hidden popover,\n * no action will be taken.\n * - `show` - The button will show a hidden popover. If you try to show an already showing popover,\n * no action will be taken.\n * - `toggle` - The button will toggle a popover between showing and hidden. If the popover is hidden,\n * it will be shown; if the popover is showing, it will be hidden. If popoverTargetAction is omitted,\n * \"toggle\" is the default action that will be performed by the control button.\n */\n @property({ type: String, reflect: true }) accessor popoverTargetAction: string | undefined\n\n constructor() {\n super()\n this.actionController.cancelKeyboardEvents = true\n this.addEventListener('keydown', this.handleKeyDown.bind(this))\n this.addEventListener('keyup', this.handleKeyUp.bind(this))\n this.addEventListener('click', this.handleClick.bind(this))\n this.addEventListener('pointerdown', this.handlePointerDown.bind(this))\n this.addEventListener('pointerup', this.handlePointerUp.bind(this))\n this.addEventListener('pointercancel', this.handlePointerCancel.bind(this))\n this.addEventListener('pointerleave', this.handlePointerLeave.bind(this))\n this.addEventListener('pointerenter', this.handlePointerEnter.bind(this))\n this.addEventListener('contextmenu', this.handleContextMenu.bind(this))\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'button')\n }\n if (!this.hasAttribute('tabindex') && !this.disabled) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n protected override update(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('popoverTarget')) {\n this.setupPopoverTarget()\n }\n super.update(changedProperties)\n }\n\n protected override updated(cp: PropertyValues<this>): void {\n super.updated(cp)\n\n // If the button is disabled, remove the tabindex attribute\n if (cp.has('disabled')) {\n if (this.disabled) {\n this.removeAttribute('tabindex')\n } else if (!this.hasAttribute('tabindex')) {\n this.setAttribute('tabindex', '0')\n }\n }\n\n if (cp.has('toggle') || cp.has('selected')) {\n this.updatePressedState()\n }\n }\n\n protected updatePressedState(): void {\n if (this.toggle) {\n this.ariaPressed = String(this.selected)\n } else {\n this.selected = false\n this.removeAttribute('aria-pressed')\n }\n }\n\n checkValidity() {\n return this.#internals.checkValidity()\n }\n\n reportValidity() {\n return this.#internals.reportValidity()\n }\n\n protected override firstUpdated(): void {\n this.#internals?.setFormValue(this.value || null)\n }\n\n override beginPress(options: BeginPressConfig): void {\n super.beginPress(options)\n this.classList.add('pressed')\n this.ripple?.beginFocus()\n }\n\n override endPress(config: EndPressConfig): void {\n super.endPress(config)\n this.classList.remove('pressed')\n this.ripple?.endFocus()\n const { cancelled, reason } = config\n if (cancelled) {\n return\n }\n const allowedReasons = reason === 'enter' || reason === 'space'\n if (this.type === 'submit' && (!reason || allowedReasons)) {\n this.handleSubmit()\n } else if (allowedReasons) {\n this.click()\n }\n }\n\n override handleClick(e: MouseEvent): void {\n // Do not call super.handleClick() here, as it would call `endPress` again.\n if (this.disabled) {\n e.preventDefault()\n e.stopPropagation()\n return\n }\n\n if (this.toggle) {\n this.selected = !this.selected\n const e = new ToggleEvent('toggle', {\n bubbles: true,\n composed: true,\n newState: this.selected ? 'selected' : 'unselected',\n oldState: this.selected ? 'unselected' : 'selected',\n })\n this.dispatchEvent(e)\n }\n this.handlePopoverAction()\n this.endPress({ cancelled: false, actionData: { event: e } })\n }\n\n protected setupPopoverTarget(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n // A regular button first sets its value to the popover target ID,\n this.value = id\n // create an anchor association with the popover target\n if (!this.id) {\n this.id = nanoid()\n }\n const anchorName = `--anchor-${this.id}`\n this.style.setProperty('anchor-name', anchorName)\n element.style.setProperty('position-anchor', anchorName)\n this.setAttribute('aria-details', id)\n this.setAttribute('aria-controls', id)\n }\n\n /**\n * When the button has a popover target, this method toggles the popover\n * visibility by finding the element in the shadow roots and calling its\n * `togglePopover` method.\n */\n protected handlePopoverAction(): void {\n const id = this.popoverTarget\n if (!id) {\n return\n }\n const element = findElementInShadowRoots(id, this)\n if (!element) {\n return\n }\n const action = this.popoverTargetAction || 'toggle'\n if (action === 'hide') {\n element.hidePopover()\n } else if (action === 'show') {\n element.showPopover()\n } else {\n element.togglePopover()\n }\n element.focus()\n }\n\n protected handleSubmit(): void {\n const { name, value, type, disabled, form } = this\n if (!form || !type || disabled) {\n return\n }\n const typedForm = form as HTMLFormElement\n let button: HTMLButtonElement | undefined\n if (name || value) {\n button = document.createElement('button')\n if (name) {\n button.name = name\n }\n if (value) {\n button.value = value\n }\n button.type = type\n button.hidden = true\n typedForm.append(button)\n }\n try {\n typedForm.requestSubmit(button)\n } catch {\n // Ignore errors\n }\n if (button) {\n typedForm.removeChild(button)\n }\n }\n\n override handlePointerEnter(e: PointerEvent): void {\n super.handlePointerEnter(e)\n this.ripple?.beginHover(e)\n }\n\n override handlePointerLeave(e: PointerEvent): void {\n super.handlePointerLeave(e)\n this.ripple?.endHover()\n }\n\n protected override render(): TemplateResult {\n const { trailingIcon = false } = this\n const icon = this.renderIcon()\n\n return html`\n ${this.renderFocusRing()} ${this.renderRipple()} ${trailingIcon ? nothing : icon}\n <slot></slot>\n ${trailingIcon ? icon : nothing}\n `\n }\n\n protected renderIcon(): TemplateResult {\n return html`<slot name=\"icon\"></slot>`\n }\n\n protected renderFocusRing(): TemplateResult {\n return html`<md-focus-ring part=\"focus-ring\" class=\"focus-ring\" .control=\"${this as HTMLElement}\"></md-focus-ring>`\n }\n\n protected renderRipple(): TemplateResult {\n return html`<ui-ripple class=\"ripple\" ?disabled=\"${this.disabled}\"></ui-ripple>`\n }\n}\n"]}
|
|
@@ -115,6 +115,8 @@ export default class UiDialog extends UiElement implements TypedEvents<DialogEve
|
|
|
115
115
|
* - When the submit event is not cancelled, then:
|
|
116
116
|
* - The default confirm action is invoked.
|
|
117
117
|
* - The dialog is closed.
|
|
118
|
+
*
|
|
119
|
+
* @deprecated Wrap the content in a `<form>` element instead.
|
|
118
120
|
*/
|
|
119
121
|
accessor useForm: boolean | undefined;
|
|
120
122
|
/**
|
|
@@ -124,6 +126,15 @@ export default class UiDialog extends UiElement implements TypedEvents<DialogEve
|
|
|
124
126
|
* @attribute
|
|
125
127
|
*/
|
|
126
128
|
accessor confirmValue: string | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* When the dialog is wrapped in a form, set this to `true` to close the dialog
|
|
131
|
+
* when the form is submitted.
|
|
132
|
+
*
|
|
133
|
+
* Note that the dialog doesn't perform any validation of the form. It only closes
|
|
134
|
+
* when the form is submitted, regardless of the application logic. The `submit` event
|
|
135
|
+
* is dispatched by the dialog when the form is valid.
|
|
136
|
+
*/
|
|
137
|
+
accessor submitClose: boolean | undefined;
|
|
127
138
|
/**
|
|
128
139
|
* A reference to the underlying dialog element.
|
|
129
140
|
*/
|
|
@@ -139,16 +150,23 @@ export default class UiDialog extends UiElement implements TypedEvents<DialogEve
|
|
|
139
150
|
* This is passed to the close event.
|
|
140
151
|
*/
|
|
141
152
|
dialogValue?: unknown;
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated Use `useForm` instead.
|
|
155
|
+
*/
|
|
142
156
|
get formId(): string | undefined;
|
|
143
157
|
constructor();
|
|
144
158
|
/**
|
|
145
159
|
* Allows to inject a template into the internals of the element.
|
|
146
160
|
* This is helpful when working with imperative dialogs.
|
|
147
161
|
* @param content The content to inject into the body.
|
|
162
|
+
* @deprecated This will be removed in the future. To use forms, wrap the content in a `<form>` element.
|
|
148
163
|
*/
|
|
149
164
|
inject(content?: TemplateResult | RenderFunction, styles?: CSSResultOrNative[]): void;
|
|
165
|
+
connectedCallback(): void;
|
|
166
|
+
disconnectedCallback(): void;
|
|
150
167
|
protected firstUpdated(): void;
|
|
151
168
|
willUpdate(cp: PropertyValues<this>): void;
|
|
169
|
+
protected handleFormSubmit(): void;
|
|
152
170
|
handleClick(e: MouseEvent): void;
|
|
153
171
|
handleKeyDown(e: KeyboardEvent): void;
|
|
154
172
|
updated(changedProperties: PropertyValues<this>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../../../src/md/dialog/internals/Dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAe,MAAM,KAAK,CAAA;AAGlH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGzD,OAAO,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../../../src/md/dialog/internals/Dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAe,MAAM,KAAK,CAAA;AAGlH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGzD,OAAO,2BAA2B,CAAA;AAGlC,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAA;IACl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S,CAAC,QAAQ,CAAC,OAAO,EAAG,WAAW,EAAE,CAAA;IAEpG;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAIrB;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;;IA4BD;;;;;OAKG;IACH,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,MAAM,CAAC,EAAE,iBAAiB,EAAE,GAAG,IAAI;IAiB5E,iBAAiB,IAAI,IAAI;IAQzB,oBAAoB,IAAI,IAAI;cAQlB,YAAY,IAAI,IAAI;IAS9B,UAAU,CAAC,EAAE,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;IAQnD,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAMzB,WAAW,CAAC,CAAC,EAAE,UAAU,GAAG,IAAI;IAkBhC,aAAa,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI;IAOrC,OAAO,CAAC,iBAAiB,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI;IA8B/D,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI;IAmB/D,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAQnC,SAAS,CAAC,aAAa,IAAI,IAAI;IAI/B,SAAS,CAAC,aAAa,IAAI,IAAI;IAsBtB,MAAM,IAAI,cAAc;IASjC,SAAS,CAAC,aAAa,IAAI,cAAc,EAAE,GAAG,cAAc;IAY5D,SAAS,CAAC,UAAU,IAAI,cAAc;IAYtC,SAAS,CAAC,WAAW,IAAI,cAAc;IAYvC,SAAS,CAAC,UAAU,IAAI,cAAc;IAStC,SAAS,CAAC,aAAa,IAAI,cAAc;CAgD1C"}
|
|
@@ -7,6 +7,7 @@ import { isDisabled, setDisabled } from '../../../lib/disabled.js';
|
|
|
7
7
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
8
8
|
import { SyntheticSubmitEvent } from '../../../events/SyntheticSubmitEvent.js';
|
|
9
9
|
import '../../button/ui-button.js';
|
|
10
|
+
import { bound } from '../../../decorators/bound.js';
|
|
10
11
|
let UiDialog = (() => {
|
|
11
12
|
let _classSuper = UiElement;
|
|
12
13
|
let _instanceExtraInitializers = [];
|
|
@@ -29,6 +30,9 @@ let UiDialog = (() => {
|
|
|
29
30
|
let _confirmValue_decorators;
|
|
30
31
|
let _confirmValue_initializers = [];
|
|
31
32
|
let _confirmValue_extraInitializers = [];
|
|
33
|
+
let _submitClose_decorators;
|
|
34
|
+
let _submitClose_initializers = [];
|
|
35
|
+
let _submitClose_extraInitializers = [];
|
|
32
36
|
let _dialog_decorators;
|
|
33
37
|
let _dialog_initializers = [];
|
|
34
38
|
let _dialog_extraInitializers = [];
|
|
@@ -54,6 +58,7 @@ let UiDialog = (() => {
|
|
|
54
58
|
let _private_inject_initializers = [];
|
|
55
59
|
let _private_inject_extraInitializers = [];
|
|
56
60
|
let _private_inject_descriptor;
|
|
61
|
+
let _handleFormSubmit_decorators;
|
|
57
62
|
return class UiDialog extends _classSuper {
|
|
58
63
|
static {
|
|
59
64
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
@@ -64,6 +69,7 @@ let UiDialog = (() => {
|
|
|
64
69
|
_confirmLabel_decorators = [property({ type: String })];
|
|
65
70
|
_useForm_decorators = [property({ type: Boolean })];
|
|
66
71
|
_confirmValue_decorators = [property({ type: String })];
|
|
72
|
+
_submitClose_decorators = [property({ type: Boolean })];
|
|
67
73
|
_dialog_decorators = [query('dialog')];
|
|
68
74
|
_hasIcon_decorators = [state()];
|
|
69
75
|
_hasTitle_decorators = [state()];
|
|
@@ -72,6 +78,7 @@ let UiDialog = (() => {
|
|
|
72
78
|
_titles_decorators = [queryAssignedNodes({ flatten: true, slot: 'title' })];
|
|
73
79
|
_buttons_decorators = [queryAssignedElements({ flatten: true, slot: 'button' })];
|
|
74
80
|
_private_inject_decorators = [state()];
|
|
81
|
+
_handleFormSubmit_decorators = [bound];
|
|
75
82
|
__esDecorate(this, null, _set_disabled_decorators, { kind: "setter", name: "disabled", static: false, private: false, access: { has: obj => "disabled" in obj, set: (obj, value) => { obj.disabled = value; } }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
76
83
|
__esDecorate(this, null, _modal_decorators, { kind: "accessor", name: "modal", static: false, private: false, access: { has: obj => "modal" in obj, get: obj => obj.modal, set: (obj, value) => { obj.modal = value; } }, metadata: _metadata }, _modal_initializers, _modal_extraInitializers);
|
|
77
84
|
__esDecorate(this, null, _open_decorators, { kind: "accessor", name: "open", static: false, private: false, access: { has: obj => "open" in obj, get: obj => obj.open, set: (obj, value) => { obj.open = value; } }, metadata: _metadata }, _open_initializers, _open_extraInitializers);
|
|
@@ -79,6 +86,7 @@ let UiDialog = (() => {
|
|
|
79
86
|
__esDecorate(this, null, _confirmLabel_decorators, { kind: "accessor", name: "confirmLabel", static: false, private: false, access: { has: obj => "confirmLabel" in obj, get: obj => obj.confirmLabel, set: (obj, value) => { obj.confirmLabel = value; } }, metadata: _metadata }, _confirmLabel_initializers, _confirmLabel_extraInitializers);
|
|
80
87
|
__esDecorate(this, null, _useForm_decorators, { kind: "accessor", name: "useForm", static: false, private: false, access: { has: obj => "useForm" in obj, get: obj => obj.useForm, set: (obj, value) => { obj.useForm = value; } }, metadata: _metadata }, _useForm_initializers, _useForm_extraInitializers);
|
|
81
88
|
__esDecorate(this, null, _confirmValue_decorators, { kind: "accessor", name: "confirmValue", static: false, private: false, access: { has: obj => "confirmValue" in obj, get: obj => obj.confirmValue, set: (obj, value) => { obj.confirmValue = value; } }, metadata: _metadata }, _confirmValue_initializers, _confirmValue_extraInitializers);
|
|
89
|
+
__esDecorate(this, null, _submitClose_decorators, { kind: "accessor", name: "submitClose", static: false, private: false, access: { has: obj => "submitClose" in obj, get: obj => obj.submitClose, set: (obj, value) => { obj.submitClose = value; } }, metadata: _metadata }, _submitClose_initializers, _submitClose_extraInitializers);
|
|
82
90
|
__esDecorate(this, null, _dialog_decorators, { kind: "accessor", name: "dialog", static: false, private: false, access: { has: obj => "dialog" in obj, get: obj => obj.dialog, set: (obj, value) => { obj.dialog = value; } }, metadata: _metadata }, _dialog_initializers, _dialog_extraInitializers);
|
|
83
91
|
__esDecorate(this, null, _hasIcon_decorators, { kind: "accessor", name: "hasIcon", static: false, private: false, access: { has: obj => "hasIcon" in obj, get: obj => obj.hasIcon, set: (obj, value) => { obj.hasIcon = value; } }, metadata: _metadata }, _hasIcon_initializers, _hasIcon_extraInitializers);
|
|
84
92
|
__esDecorate(this, null, _hasTitle_decorators, { kind: "accessor", name: "hasTitle", static: false, private: false, access: { has: obj => "hasTitle" in obj, get: obj => obj.hasTitle, set: (obj, value) => { obj.hasTitle = value; } }, metadata: _metadata }, _hasTitle_initializers, _hasTitle_extraInitializers);
|
|
@@ -87,6 +95,7 @@ let UiDialog = (() => {
|
|
|
87
95
|
__esDecorate(this, null, _titles_decorators, { kind: "accessor", name: "titles", static: false, private: false, access: { has: obj => "titles" in obj, get: obj => obj.titles, set: (obj, value) => { obj.titles = value; } }, metadata: _metadata }, _titles_initializers, _titles_extraInitializers);
|
|
88
96
|
__esDecorate(this, null, _buttons_decorators, { kind: "accessor", name: "buttons", static: false, private: false, access: { has: obj => "buttons" in obj, get: obj => obj.buttons, set: (obj, value) => { obj.buttons = value; } }, metadata: _metadata }, _buttons_initializers, _buttons_extraInitializers);
|
|
89
97
|
__esDecorate(this, _private_inject_descriptor = { get: __setFunctionName(function () { return this.#inject_accessor_storage; }, "#inject", "get"), set: __setFunctionName(function (value) { this.#inject_accessor_storage = value; }, "#inject", "set") }, _private_inject_decorators, { kind: "accessor", name: "#inject", static: false, private: true, access: { has: obj => #inject in obj, get: obj => obj.#inject, set: (obj, value) => { obj.#inject = value; } }, metadata: _metadata }, _private_inject_initializers, _private_inject_extraInitializers);
|
|
98
|
+
__esDecorate(this, null, _handleFormSubmit_decorators, { kind: "method", name: "handleFormSubmit", static: false, private: false, access: { has: obj => "handleFormSubmit" in obj, get: obj => obj.handleFormSubmit }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
90
99
|
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
91
100
|
}
|
|
92
101
|
get disabled() {
|
|
@@ -163,6 +172,8 @@ let UiDialog = (() => {
|
|
|
163
172
|
* - When the submit event is not cancelled, then:
|
|
164
173
|
* - The default confirm action is invoked.
|
|
165
174
|
* - The dialog is closed.
|
|
175
|
+
*
|
|
176
|
+
* @deprecated Wrap the content in a `<form>` element instead.
|
|
166
177
|
*/
|
|
167
178
|
get useForm() { return this.#useForm_accessor_storage; }
|
|
168
179
|
set useForm(value) { this.#useForm_accessor_storage = value; }
|
|
@@ -175,7 +186,18 @@ let UiDialog = (() => {
|
|
|
175
186
|
*/
|
|
176
187
|
get confirmValue() { return this.#confirmValue_accessor_storage; }
|
|
177
188
|
set confirmValue(value) { this.#confirmValue_accessor_storage = value; }
|
|
178
|
-
#
|
|
189
|
+
#submitClose_accessor_storage = (__runInitializers(this, _confirmValue_extraInitializers), __runInitializers(this, _submitClose_initializers, void 0));
|
|
190
|
+
/**
|
|
191
|
+
* When the dialog is wrapped in a form, set this to `true` to close the dialog
|
|
192
|
+
* when the form is submitted.
|
|
193
|
+
*
|
|
194
|
+
* Note that the dialog doesn't perform any validation of the form. It only closes
|
|
195
|
+
* when the form is submitted, regardless of the application logic. The `submit` event
|
|
196
|
+
* is dispatched by the dialog when the form is valid.
|
|
197
|
+
*/
|
|
198
|
+
get submitClose() { return this.#submitClose_accessor_storage; }
|
|
199
|
+
set submitClose(value) { this.#submitClose_accessor_storage = value; }
|
|
200
|
+
#dialog_accessor_storage = (__runInitializers(this, _submitClose_extraInitializers), __runInitializers(this, _dialog_initializers, void 0));
|
|
179
201
|
/**
|
|
180
202
|
* A reference to the underlying dialog element.
|
|
181
203
|
*/
|
|
@@ -205,13 +227,30 @@ let UiDialog = (() => {
|
|
|
205
227
|
*/
|
|
206
228
|
dialogValue = __runInitializers(this, _buttons_extraInitializers);
|
|
207
229
|
#formId;
|
|
230
|
+
/**
|
|
231
|
+
* @deprecated Use `useForm` instead.
|
|
232
|
+
*/
|
|
208
233
|
get formId() {
|
|
209
234
|
return this.#formId;
|
|
210
235
|
}
|
|
211
236
|
#inject_accessor_storage = __runInitializers(this, _private_inject_initializers, void 0);
|
|
237
|
+
/**
|
|
238
|
+
* @deprecated This will be removed in the future.
|
|
239
|
+
*/
|
|
212
240
|
get #inject() { return _private_inject_descriptor.get.call(this); }
|
|
213
241
|
set #inject(value) { return _private_inject_descriptor.set.call(this, value); }
|
|
242
|
+
/**
|
|
243
|
+
* @deprecated This will be removed in the future.
|
|
244
|
+
*/
|
|
214
245
|
#pendingStyles = __runInitializers(this, _private_inject_extraInitializers);
|
|
246
|
+
/**
|
|
247
|
+
* A reference to the parent form element.
|
|
248
|
+
* When a form is found, the dialog will hook into the form's submit event
|
|
249
|
+
* and close the dialog when the form is submitted.
|
|
250
|
+
* Since the `submit` event is dispatched when the form is valid,
|
|
251
|
+
* we can use this to close the dialog and not worry about the form validation.
|
|
252
|
+
*/
|
|
253
|
+
#form = null;
|
|
215
254
|
constructor() {
|
|
216
255
|
super();
|
|
217
256
|
this.addEventListener('click', this.handleClick);
|
|
@@ -221,6 +260,7 @@ let UiDialog = (() => {
|
|
|
221
260
|
* Allows to inject a template into the internals of the element.
|
|
222
261
|
* This is helpful when working with imperative dialogs.
|
|
223
262
|
* @param content The content to inject into the body.
|
|
263
|
+
* @deprecated This will be removed in the future. To use forms, wrap the content in a `<form>` element.
|
|
224
264
|
*/
|
|
225
265
|
inject(content, styles) {
|
|
226
266
|
this.#inject = content;
|
|
@@ -239,6 +279,20 @@ let UiDialog = (() => {
|
|
|
239
279
|
adoptStyles(this.shadowRoot, styles);
|
|
240
280
|
}
|
|
241
281
|
}
|
|
282
|
+
connectedCallback() {
|
|
283
|
+
super.connectedCallback();
|
|
284
|
+
this.#form = this.closest('form');
|
|
285
|
+
if (this.#form) {
|
|
286
|
+
this.#form.addEventListener('submit', this.handleFormSubmit);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
disconnectedCallback() {
|
|
290
|
+
super.disconnectedCallback();
|
|
291
|
+
if (this.#form) {
|
|
292
|
+
this.#form.removeEventListener('submit', this.handleFormSubmit);
|
|
293
|
+
this.#form = null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
242
296
|
firstUpdated() {
|
|
243
297
|
const styles = this.#pendingStyles;
|
|
244
298
|
if (styles) {
|
|
@@ -253,6 +307,11 @@ let UiDialog = (() => {
|
|
|
253
307
|
this.#formId = `form-${r}`;
|
|
254
308
|
}
|
|
255
309
|
}
|
|
310
|
+
handleFormSubmit() {
|
|
311
|
+
if (this.submitClose) {
|
|
312
|
+
this.handleInteraction('confirm');
|
|
313
|
+
}
|
|
314
|
+
}
|
|
256
315
|
handleClick(e) {
|
|
257
316
|
super.handleClick(e);
|
|
258
317
|
const path = e.composedPath();
|
|
@@ -265,7 +324,6 @@ let UiDialog = (() => {
|
|
|
265
324
|
// Adds support for forms.
|
|
266
325
|
// When a form's submit button is clicked we yield the flow control to the form.
|
|
267
326
|
// This way the form can handle the submit event.
|
|
268
|
-
e.preventDefault();
|
|
269
327
|
return;
|
|
270
328
|
}
|
|
271
329
|
const { value = '' } = button;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../../../src/md/dialog/internals/Dialog.ts"],"names":[],"mappings":";AAAA,OAAO,EAA0B,IAAI,EAAE,OAAO,EAA4C,WAAW,EAAE,MAAM,KAAK,CAAA;AAClH,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACrG,OAAO,EAAkB,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB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AY,EAAE,GAAG,IAAI,CAAA;YAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,OAAO,CAAA;YAChB,CAAC;YACD,OAAO,IAAI,CAAA;;;;;kBAKG,IAAI,CAAC,aAAa;;WAEzB,YAAY;;KAElB,CAAA;QACH,CAAC;QAED,oBAAoB;YAClB,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;YAChE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,OAAO,CAAA;YAChB,CAAC;YACD,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;YAC1C,OAAO,IAAI,CAAA;;;gBAGC,IAAI;iBACH,YAAY;;kBAEX,IAAI,CAAC,aAAa;;WAEzB,YAAY;;KAElB,CAAA;QACH,CAAC;;;AAxZH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAyWC","sourcesContent":["import { type CSSResultOrNative, html, nothing, type PropertyValues, type TemplateResult, adoptStyles } from 'lit'\nimport { property, query, queryAssignedElements, queryAssignedNodes, state } from 'lit/decorators.js'\nimport { type ClassInfo, classMap } from 'lit/directives/class-map.js'\nimport { UiElement } from '../../UiElement.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiButton from '../../button/internals/button.js'\nimport type { TypedEvents } from '../../../core/types.js'\nimport { ifDefined } from 'lit/directives/if-defined.js'\nimport { SyntheticSubmitEvent } from '../../../events/SyntheticSubmitEvent.js'\nimport '../../button/ui-button.js'\n\nexport interface UiDialogClosingReason {\n /**\n * Whether the dialog was cancelled by either activating the `dismiss` button\n * or by pressing escape.\n */\n cancelled: boolean\n /**\n * This is used in cases when the dialog has more complex purpose.\n * This is the value expected from the dialog.\n */\n value?: unknown\n}\n\ninterface DialogEventMap {\n close: CustomEvent<UiDialogClosingReason>\n}\n\nexport type RenderFunction = () => TemplateResult\n\n/**\n * Styled dialog using a native `<dialog>` element under the hood.\n * Note, since native dialog renders in the top layer it is not necessary\n * to place the dialog in the `<body>`.\n *\n * **Using Buttons**\n *\n * The dialog automatically recognizes buttons with values `confirm` and `dismiss`\n * to close the dialog and dispatch the `close` event. The event has additional\n * closing reason detail.\n *\n * ```javascript\n * <ui-button color=\"text\" value=\"dismiss\">Cancel</ui-button>\n * <ui-button color=\"text\" value=\"confirm\">Take action</ui-button>\n * ```\n *\n * ```javascript\n * <button value=\"dismiss\">Cancel</button>\n * <button value=\"confirm\">Take action</button>\n * ```\n *\n * The detail object of the `close` event has the following properties:\n * - cancelled - Whether the dialog was cancelled by either activating the `dismiss` button or by pressing escape.\n *\n * The `close` event is only dispatched when the user interact with the dialog. Imperative control of the\n * dialog won't trigger the close button.\n *\n * ** Full example**\n *\n * ```javascript\n * <ui-dialog modal>\n * <ui-icon slot=\"icon\" icon=\"delete\"></ui-icon>\n *\n * <span slot=\"title\">Delete photos?</span>\n * <p>This action will permanently remove the selected pictures from your account.</p>\n *\n * <ui-button color=\"text\" slot=\"button\" value=\"dismiss\" type=\"text\">Cancel</ui-button>\n * <ui-button color=\"text\" slot=\"button\" value=\"confirm\" type=\"text\">Confirm</ui-button>\n * </ui-dialog>\n * ```\n *\n * @slot - The slot for the content of the dialog.\n * @slot icon - The slot to place the dialog icon\n * @slot title - The slot to place the dialog title. Do not put elements here, just the text.\n * @slot button - The slot to place the dialog buttons. Use the `confirm` or `dismiss`\n * buttons to automatically close the dialog.\n * @fires close - A non-bubbling, non-cancellable event with the `UiDialogClosingReason` as the detail.\n */\nexport default class UiDialog extends UiElement implements TypedEvents<DialogEventMap> {\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n /**\n * Opens the dialog as modal when toggling dialog's open state.\n *\n * Setting this value after the dialog was opened has no effect.\n *\n * @attribute\n */\n @property({ type: Boolean }) accessor modal = false\n\n /**\n * Toggles visibility of the dialog.\n * Note, the dialog is opened asynchronously after the update is performed.\n * @attribute\n */\n @property({ type: Boolean }) accessor open = false\n\n /**\n * Imperative access to create a dismiss button.\n * When set this will render a dismiss button at the end of the buttons line, before the `confirmLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor dismissLabel: string | undefined\n\n /**\n * Imperative access to create a confirm button.\n * When set this will render a confirm button at the end of the buttons line, after the `dismissLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor confirmLabel: string | undefined\n\n /**\n * Part of the imperative access to the element.\n * When set, it wraps the content in a `<form>` element.\n * When this is enabled the following will happen:\n * - The `confirm` button will get `type=\"submit\"`\n * - The form `method` attribute is set to `dialog`\n * - The form `id` attribute is set to a random string. You can get it from the `formId` getter.\n * - The dialog will dispatch the same `submit` event as the form.\n * - When the `submit` event dispatched by the dialog gets cancelled, then:\n * - The original submit event also gets cancelled.\n * - The default confirm action is not invoked\n * - The dialog stays opened\n * - When the submit event is not cancelled, then:\n * - The default confirm action is invoked.\n * - The dialog is closed.\n */\n @property({ type: Boolean }) accessor useForm: boolean | undefined\n\n /**\n * Only when `confirmLabel` is set.\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#value}\n * @attribute\n */\n @property({ type: String }) accessor confirmValue: string | undefined\n\n /**\n * A reference to the underlying dialog element.\n */\n @query('dialog') accessor dialog!: HTMLDialogElement\n\n @state() protected accessor hasIcon = false\n\n @state() protected accessor hasTitle = false\n\n @state() protected accessor hasButton = false\n\n @queryAssignedElements({ flatten: true, slot: 'icon' }) protected accessor icons!: HTMLElement[]\n\n @queryAssignedNodes({ flatten: true, slot: 'title' }) protected accessor titles!: HTMLElement[]\n\n @queryAssignedElements({ flatten: true, slot: 'button' }) protected accessor buttons!: HTMLElement[]\n\n /**\n * To be set by a child class when closing the dialog.\n * This is passed to the close event.\n */\n dialogValue?: unknown\n\n #formId?: string\n\n get formId(): string | undefined {\n return this.#formId\n }\n\n @state() accessor #inject: TemplateResult | RenderFunction | undefined\n\n #pendingStyles?: CSSResultOrNative[]\n\n constructor() {\n super()\n\n this.addEventListener('click', this.handleClick)\n this.addEventListener('keydown', this.handleKeyDown)\n }\n\n /**\n * Allows to inject a template into the internals of the element.\n * This is helpful when working with imperative dialogs.\n * @param content The content to inject into the body.\n */\n inject(content?: TemplateResult | RenderFunction, styles?: CSSResultOrNative[]): void {\n this.#inject = content\n if (styles) {\n if (this.shadowRoot) {\n adoptStyles(this.shadowRoot, styles)\n } else {\n if (!this.#pendingStyles) {\n this.#pendingStyles = []\n }\n this.#pendingStyles.push(...styles)\n }\n }\n if (this.shadowRoot && styles) {\n adoptStyles(this.shadowRoot, styles)\n }\n }\n\n protected override firstUpdated(): void {\n const styles = this.#pendingStyles\n if (styles) {\n const root = this.shadowRoot as ShadowRoot\n const all = [...root.adoptedStyleSheets, ...styles]\n adoptStyles(this.shadowRoot as ShadowRoot, all)\n }\n }\n\n override willUpdate(cp: PropertyValues<this>): void {\n if (cp.has('useForm') && this.useForm && !this.#formId) {\n const r = (Math.random() + 1).toString(36).substring(7)\n this.#formId = `form-${r}`\n }\n }\n\n override handleClick(e: MouseEvent): void {\n super.handleClick(e)\n const path = e.composedPath()\n const { buttons } = this\n const button = path.find((i) => buttons.includes(i as HTMLElement)) as HTMLButtonElement | UiButton | undefined\n if (!button) {\n return\n }\n if (button.type === 'submit') {\n // Adds support for forms.\n // When a form's submit button is clicked we yield the flow control to the form.\n // This way the form can handle the submit event.\n e.preventDefault()\n return\n }\n const { value = '' } = button\n this.handleInteraction(value as 'dismiss' | 'confirm')\n }\n\n override handleKeyDown(e: KeyboardEvent): void {\n super.handleKeyDown(e)\n if (e.key === 'Escape') {\n this.handleInteraction('dismiss')\n }\n }\n\n override updated(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('open')) {\n this.#controlVisibility()\n }\n super.updated(changedProperties)\n }\n\n #controlVisibility(): void {\n const { dialog, modal, open } = this\n if (!dialog) {\n return\n }\n if (open) {\n if (modal) {\n dialog.showModal()\n } else {\n dialog.show()\n }\n } else {\n dialog.close()\n }\n }\n\n #handleSlotChange(): void {\n const { icons, titles, buttons } = this\n this.hasIcon = !!icons && !!icons.length\n this.hasTitle = !!titles && !!titles.length\n this.hasButton = !!buttons && !!buttons.length\n }\n\n protected handleInteraction(value: 'dismiss' | 'confirm'): void {\n if (!['dismiss', 'confirm'].includes(value)) {\n return\n }\n this.open = false\n const detail: UiDialogClosingReason = {\n cancelled: value === 'dismiss',\n }\n if (this.dialogValue !== undefined) {\n detail.value = this.dialogValue\n }\n this.dispatchEvent(\n new CustomEvent<UiDialogClosingReason>('close', {\n composed: true,\n detail,\n })\n )\n }\n\n protected handleDialogClose(): void {\n if (!this.open) {\n return\n }\n this.open = false\n this.handleInteraction('dismiss')\n }\n\n protected handleDismiss(): void {\n this.handleInteraction('dismiss')\n }\n\n protected handleConfirm(): void {\n if (!this.useForm) {\n this.handleInteraction('confirm')\n }\n }\n\n #handleSubmit(event: SubmitEvent): void {\n const form = event.target as HTMLFormElement\n const copy = new SyntheticSubmitEvent(event.type, form, {\n submitter: event.submitter,\n cancelable: true,\n bubbles: false,\n composed: false,\n })\n const dispatched = this.dispatchEvent(copy)\n if (dispatched) {\n this.handleInteraction('confirm')\n } else {\n event.preventDefault()\n }\n }\n\n override render(): TemplateResult {\n const { useForm } = this\n return html`\n <dialog @close=\"${this.handleDialogClose}\" part=\"dialog\">\n <div class=\"container\">${useForm ? this.#renderFormContent() : this.renderContent()}</div>\n </dialog>\n `\n }\n\n protected renderContent(): TemplateResult[] | TemplateResult {\n return [this.renderIcon(), this.renderTitle(), this.renderBody(), this.renderButtons()]\n }\n\n #renderFormContent(): TemplateResult {\n return html`\n <form id=\"${ifDefined(this.formId)}\" method=\"dialog\" @submit=\"${this.#handleSubmit}\" part=\"form\">\n ${this.renderContent()}\n </form>\n `\n }\n\n protected renderIcon(): TemplateResult {\n const classes: ClassInfo = {\n 'icon': true,\n 'with-icon': this.hasIcon,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"icon\">\n <slot name=\"icon\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderTitle(): TemplateResult {\n const classes: ClassInfo = {\n 'title': true,\n 'with-title': this.hasTitle,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"title\">\n <slot name=\"title\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderBody(): TemplateResult {\n let content = this.#inject\n if (typeof content === 'function') {\n content = content()\n }\n const injected = content || nothing\n return html` <div class=\"content\" part=\"body\"><slot></slot>${injected}</div> `\n }\n\n protected renderButtons(): TemplateResult {\n const classes: ClassInfo = {\n 'buttons': true,\n 'with-buttons': this.hasButton || !!this.confirmLabel || !!this.dismissLabel,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"button\">\n <slot name=\"button\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n ${this.#renderDismissButton()} ${this.#renderConfirmButton()}\n </div>\n `\n }\n\n #renderDismissButton(): TemplateResult | typeof nothing {\n const { dismissLabel } = this\n if (!dismissLabel) {\n return nothing\n }\n return html`\n <ui-button\n color=\"text\"\n value=\"dismiss\"\n class=\"internal-button\"\n @click=\"${this.handleDismiss}\"\n part=\"negative-action\"\n >${dismissLabel}</ui-button\n >\n `\n }\n\n #renderConfirmButton(): TemplateResult | typeof nothing {\n const { confirmLabel, confirmValue = 'confirm', useForm } = this\n if (!confirmLabel) {\n return nothing\n }\n const type = useForm ? 'submit' : 'button'\n return html`\n <ui-button\n color=\"text\"\n type=\"${type}\"\n value=\"${confirmValue}\"\n class=\"internal-button\"\n @click=\"${this.handleConfirm}\"\n part=\"positive-action\"\n >${confirmLabel}</ui-button\n >\n `\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file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AiB;UACvD,IAAI,CAAC,oBAAoB,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE;;KAE/D,CAAA;QACH,CAAC;QAED,oBAAoB;YAClB,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAA;YAC7B,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,OAAO,CAAA;YAChB,CAAC;YACD,OAAO,IAAI,CAAA;;;;;kBAKG,IAAI,CAAC,aAAa;;WAEzB,YAAY;;KAElB,CAAA;QACH,CAAC;QAED,oBAAoB;YAClB,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;YAChE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,OAAO,CAAA;YAChB,CAAC;YACD,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;YAC1C,OAAO,IAAI,CAAA;;;gBAGC,IAAI;iBACH,YAAY;;kBAEX,IAAI,CAAC,aAAa;;WAEzB,YAAY;;KAElB,CAAA;QACH,CAAC;;;AA5cH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBA6ZC","sourcesContent":["import { type CSSResultOrNative, html, nothing, type PropertyValues, type TemplateResult, adoptStyles } from 'lit'\nimport { property, query, queryAssignedElements, queryAssignedNodes, state } from 'lit/decorators.js'\nimport { type ClassInfo, classMap } from 'lit/directives/class-map.js'\nimport { UiElement } from '../../UiElement.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiButton from '../../button/internals/button.js'\nimport type { TypedEvents } from '../../../core/types.js'\nimport { ifDefined } from 'lit/directives/if-defined.js'\nimport { SyntheticSubmitEvent } from '../../../events/SyntheticSubmitEvent.js'\nimport '../../button/ui-button.js'\nimport { bound } from '../../../decorators/bound.js'\n\nexport interface UiDialogClosingReason {\n /**\n * Whether the dialog was cancelled by either activating the `dismiss` button\n * or by pressing escape.\n */\n cancelled: boolean\n /**\n * This is used in cases when the dialog has more complex purpose.\n * This is the value expected from the dialog.\n */\n value?: unknown\n}\n\ninterface DialogEventMap {\n close: CustomEvent<UiDialogClosingReason>\n}\n\nexport type RenderFunction = () => TemplateResult\n\n/**\n * Styled dialog using a native `<dialog>` element under the hood.\n * Note, since native dialog renders in the top layer it is not necessary\n * to place the dialog in the `<body>`.\n *\n * **Using Buttons**\n *\n * The dialog automatically recognizes buttons with values `confirm` and `dismiss`\n * to close the dialog and dispatch the `close` event. The event has additional\n * closing reason detail.\n *\n * ```javascript\n * <ui-button color=\"text\" value=\"dismiss\">Cancel</ui-button>\n * <ui-button color=\"text\" value=\"confirm\">Take action</ui-button>\n * ```\n *\n * ```javascript\n * <button value=\"dismiss\">Cancel</button>\n * <button value=\"confirm\">Take action</button>\n * ```\n *\n * The detail object of the `close` event has the following properties:\n * - cancelled - Whether the dialog was cancelled by either activating the `dismiss` button or by pressing escape.\n *\n * The `close` event is only dispatched when the user interact with the dialog. Imperative control of the\n * dialog won't trigger the close button.\n *\n * ** Full example**\n *\n * ```javascript\n * <ui-dialog modal>\n * <ui-icon slot=\"icon\" icon=\"delete\"></ui-icon>\n *\n * <span slot=\"title\">Delete photos?</span>\n * <p>This action will permanently remove the selected pictures from your account.</p>\n *\n * <ui-button color=\"text\" slot=\"button\" value=\"dismiss\" type=\"text\">Cancel</ui-button>\n * <ui-button color=\"text\" slot=\"button\" value=\"confirm\" type=\"text\">Confirm</ui-button>\n * </ui-dialog>\n * ```\n *\n * @slot - The slot for the content of the dialog.\n * @slot icon - The slot to place the dialog icon\n * @slot title - The slot to place the dialog title. Do not put elements here, just the text.\n * @slot button - The slot to place the dialog buttons. Use the `confirm` or `dismiss`\n * buttons to automatically close the dialog.\n * @fires close - A non-bubbling, non-cancellable event with the `UiDialogClosingReason` as the detail.\n */\nexport default class UiDialog extends UiElement implements TypedEvents<DialogEventMap> {\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n /**\n * Opens the dialog as modal when toggling dialog's open state.\n *\n * Setting this value after the dialog was opened has no effect.\n *\n * @attribute\n */\n @property({ type: Boolean }) accessor modal = false\n\n /**\n * Toggles visibility of the dialog.\n * Note, the dialog is opened asynchronously after the update is performed.\n * @attribute\n */\n @property({ type: Boolean }) accessor open = false\n\n /**\n * Imperative access to create a dismiss button.\n * When set this will render a dismiss button at the end of the buttons line, before the `confirmLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor dismissLabel: string | undefined\n\n /**\n * Imperative access to create a confirm button.\n * When set this will render a confirm button at the end of the buttons line, after the `dismissLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor confirmLabel: string | undefined\n\n /**\n * Part of the imperative access to the element.\n * When set, it wraps the content in a `<form>` element.\n * When this is enabled the following will happen:\n * - The `confirm` button will get `type=\"submit\"`\n * - The form `method` attribute is set to `dialog`\n * - The form `id` attribute is set to a random string. You can get it from the `formId` getter.\n * - The dialog will dispatch the same `submit` event as the form.\n * - When the `submit` event dispatched by the dialog gets cancelled, then:\n * - The original submit event also gets cancelled.\n * - The default confirm action is not invoked\n * - The dialog stays opened\n * - When the submit event is not cancelled, then:\n * - The default confirm action is invoked.\n * - The dialog is closed.\n *\n * @deprecated Wrap the content in a `<form>` element instead.\n */\n @property({ type: Boolean }) accessor useForm: boolean | undefined\n\n /**\n * Only when `confirmLabel` is set.\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#value}\n * @attribute\n */\n @property({ type: String }) accessor confirmValue: string | undefined\n /**\n * When the dialog is wrapped in a form, set this to `true` to close the dialog\n * when the form is submitted.\n *\n * Note that the dialog doesn't perform any validation of the form. It only closes\n * when the form is submitted, regardless of the application logic. The `submit` event\n * is dispatched by the dialog when the form is valid.\n */\n @property({ type: Boolean }) accessor submitClose: boolean | undefined\n\n /**\n * A reference to the underlying dialog element.\n */\n @query('dialog') accessor dialog!: HTMLDialogElement\n\n @state() protected accessor hasIcon = false\n\n @state() protected accessor hasTitle = false\n\n @state() protected accessor hasButton = false\n\n @queryAssignedElements({ flatten: true, slot: 'icon' }) protected accessor icons!: HTMLElement[]\n\n @queryAssignedNodes({ flatten: true, slot: 'title' }) protected accessor titles!: HTMLElement[]\n\n @queryAssignedElements({ flatten: true, slot: 'button' }) protected accessor buttons!: HTMLElement[]\n\n /**\n * To be set by a child class when closing the dialog.\n * This is passed to the close event.\n */\n dialogValue?: unknown\n\n #formId?: string\n\n /**\n * @deprecated Use `useForm` instead.\n */\n get formId(): string | undefined {\n return this.#formId\n }\n\n /**\n * @deprecated This will be removed in the future.\n */\n @state() accessor #inject: TemplateResult | RenderFunction | undefined\n\n /**\n * @deprecated This will be removed in the future.\n */\n #pendingStyles?: CSSResultOrNative[]\n\n /**\n * A reference to the parent form element.\n * When a form is found, the dialog will hook into the form's submit event\n * and close the dialog when the form is submitted.\n * Since the `submit` event is dispatched when the form is valid,\n * we can use this to close the dialog and not worry about the form validation.\n */\n #form: HTMLFormElement | null = null\n\n constructor() {\n super()\n\n this.addEventListener('click', this.handleClick)\n this.addEventListener('keydown', this.handleKeyDown)\n }\n\n /**\n * Allows to inject a template into the internals of the element.\n * This is helpful when working with imperative dialogs.\n * @param content The content to inject into the body.\n * @deprecated This will be removed in the future. To use forms, wrap the content in a `<form>` element.\n */\n inject(content?: TemplateResult | RenderFunction, styles?: CSSResultOrNative[]): void {\n this.#inject = content\n if (styles) {\n if (this.shadowRoot) {\n adoptStyles(this.shadowRoot, styles)\n } else {\n if (!this.#pendingStyles) {\n this.#pendingStyles = []\n }\n this.#pendingStyles.push(...styles)\n }\n }\n if (this.shadowRoot && styles) {\n adoptStyles(this.shadowRoot, styles)\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.#form = this.closest('form')\n if (this.#form) {\n this.#form.addEventListener('submit', this.handleFormSubmit)\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n if (this.#form) {\n this.#form.removeEventListener('submit', this.handleFormSubmit)\n this.#form = null\n }\n }\n\n protected override firstUpdated(): void {\n const styles = this.#pendingStyles\n if (styles) {\n const root = this.shadowRoot as ShadowRoot\n const all = [...root.adoptedStyleSheets, ...styles]\n adoptStyles(this.shadowRoot as ShadowRoot, all)\n }\n }\n\n override willUpdate(cp: PropertyValues<this>): void {\n if (cp.has('useForm') && this.useForm && !this.#formId) {\n const r = (Math.random() + 1).toString(36).substring(7)\n this.#formId = `form-${r}`\n }\n }\n\n @bound\n protected handleFormSubmit(): void {\n if (this.submitClose) {\n this.handleInteraction('confirm')\n }\n }\n\n override handleClick(e: MouseEvent): void {\n super.handleClick(e)\n const path = e.composedPath()\n const { buttons } = this\n const button = path.find((i) => buttons.includes(i as HTMLElement)) as HTMLButtonElement | UiButton | undefined\n if (!button) {\n return\n }\n if (button.type === 'submit') {\n // Adds support for forms.\n // When a form's submit button is clicked we yield the flow control to the form.\n // This way the form can handle the submit event.\n return\n }\n const { value = '' } = button\n this.handleInteraction(value as 'dismiss' | 'confirm')\n }\n\n override handleKeyDown(e: KeyboardEvent): void {\n super.handleKeyDown(e)\n if (e.key === 'Escape') {\n this.handleInteraction('dismiss')\n }\n }\n\n override updated(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('open')) {\n this.#controlVisibility()\n }\n super.updated(changedProperties)\n }\n\n #controlVisibility(): void {\n const { dialog, modal, open } = this\n if (!dialog) {\n return\n }\n if (open) {\n if (modal) {\n dialog.showModal()\n } else {\n dialog.show()\n }\n } else {\n dialog.close()\n }\n }\n\n #handleSlotChange(): void {\n const { icons, titles, buttons } = this\n this.hasIcon = !!icons && !!icons.length\n this.hasTitle = !!titles && !!titles.length\n this.hasButton = !!buttons && !!buttons.length\n }\n\n protected handleInteraction(value: 'dismiss' | 'confirm'): void {\n if (!['dismiss', 'confirm'].includes(value)) {\n return\n }\n this.open = false\n const detail: UiDialogClosingReason = {\n cancelled: value === 'dismiss',\n }\n if (this.dialogValue !== undefined) {\n detail.value = this.dialogValue\n }\n this.dispatchEvent(\n new CustomEvent<UiDialogClosingReason>('close', {\n composed: true,\n detail,\n })\n )\n }\n\n protected handleDialogClose(): void {\n if (!this.open) {\n return\n }\n this.open = false\n this.handleInteraction('dismiss')\n }\n\n protected handleDismiss(): void {\n this.handleInteraction('dismiss')\n }\n\n protected handleConfirm(): void {\n if (!this.useForm) {\n this.handleInteraction('confirm')\n }\n }\n\n #handleSubmit(event: SubmitEvent): void {\n const form = event.target as HTMLFormElement\n const copy = new SyntheticSubmitEvent(event.type, form, {\n submitter: event.submitter,\n cancelable: true,\n bubbles: false,\n composed: false,\n })\n const dispatched = this.dispatchEvent(copy)\n if (dispatched) {\n this.handleInteraction('confirm')\n } else {\n event.preventDefault()\n }\n }\n\n override render(): TemplateResult {\n const { useForm } = this\n return html`\n <dialog @close=\"${this.handleDialogClose}\" part=\"dialog\">\n <div class=\"container\">${useForm ? this.#renderFormContent() : this.renderContent()}</div>\n </dialog>\n `\n }\n\n protected renderContent(): TemplateResult[] | TemplateResult {\n return [this.renderIcon(), this.renderTitle(), this.renderBody(), this.renderButtons()]\n }\n\n #renderFormContent(): TemplateResult {\n return html`\n <form id=\"${ifDefined(this.formId)}\" method=\"dialog\" @submit=\"${this.#handleSubmit}\" part=\"form\">\n ${this.renderContent()}\n </form>\n `\n }\n\n protected renderIcon(): TemplateResult {\n const classes: ClassInfo = {\n 'icon': true,\n 'with-icon': this.hasIcon,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"icon\">\n <slot name=\"icon\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderTitle(): TemplateResult {\n const classes: ClassInfo = {\n 'title': true,\n 'with-title': this.hasTitle,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"title\">\n <slot name=\"title\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderBody(): TemplateResult {\n let content = this.#inject\n if (typeof content === 'function') {\n content = content()\n }\n const injected = content || nothing\n return html` <div class=\"content\" part=\"body\"><slot></slot>${injected}</div> `\n }\n\n protected renderButtons(): TemplateResult {\n const classes: ClassInfo = {\n 'buttons': true,\n 'with-buttons': this.hasButton || !!this.confirmLabel || !!this.dismissLabel,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"button\">\n <slot name=\"button\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n ${this.#renderDismissButton()} ${this.#renderConfirmButton()}\n </div>\n `\n }\n\n #renderDismissButton(): TemplateResult | typeof nothing {\n const { dismissLabel } = this\n if (!dismissLabel) {\n return nothing\n }\n return html`\n <ui-button\n color=\"text\"\n value=\"dismiss\"\n class=\"internal-button\"\n @click=\"${this.handleDismiss}\"\n part=\"negative-action\"\n >${dismissLabel}</ui-button\n >\n `\n }\n\n #renderConfirmButton(): TemplateResult | typeof nothing {\n const { confirmLabel, confirmValue = 'confirm', useForm } = this\n if (!confirmLabel) {\n return nothing\n }\n const type = useForm ? 'submit' : 'button'\n return html`\n <ui-button\n color=\"text\"\n type=\"${type}\"\n value=\"${confirmValue}\"\n class=\"internal-button\"\n @click=\"${this.handleConfirm}\"\n part=\"positive-action\"\n >${confirmLabel}</ui-button\n >\n `\n }\n}\n"]}
|