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,CACI,CACA,CACP,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC","sourcesContent":["import { DNode } from '@dojo/framework/core/interfaces';\nimport i18n from '@dojo/framework/core/middleware/i18n';\nimport { createICacheMiddleware } from '@dojo/framework/core/middleware/icache';\nimport { uuid } from '@dojo/framework/core/util';\nimport { create, tsx } from '@dojo/framework/core/vdom';\nimport { formatAriaProperties, Keys } from '../common/util';\nimport Icon from '../icon';\nimport theme from '../middleware/theme';\nimport bodyScroll from '../middleware/bodyScroll';\nimport * as css from '../theme/default/dialog.m.css';\nimport * as fixedCss from './styles/dialog.m.css';\nimport bundle from './nls/Dialog';\nimport GlobalEvent from '../global-event';\nimport inert from '@dojo/framework/core/middleware/inert';\n\nexport interface DialogPropertiesBase {\n\t/** Custom aria attributes */\n\taria?: { [key: string]: string | null };\n\t/** Determines whether the dialog can be closed */\n\tcloseable?: boolean;\n\t/** Hidden text used by screen readers to display for the close button */\n\tcloseText?: string;\n\t/** Determines whether the dialog is open or closed */\n\topen: boolean;\n\t/** Determines whether a semi-transparent background shows behind the dialog */\n\tunderlay?: boolean;\n\t/** Called when the dialog opens */\n\tonOpen?(): void;\n\t/** Called when the dialog is closed */\n\tonRequestClose(): void;\n}\n\nexport interface DialogPropertiesDialogRole extends DialogPropertiesBase {\n\t/** Role of this dialog for accessibility, either 'alertdialog' or 'dialog' */\n\trole?: 'dialog';\n\t/** Determines whether the dialog can be closed by clicking outside its content. Only applicable when using \"dialog\" role */\n\tmodal?: boolean;\n}\n\nexport interface DialogPropertiesAlertDialogRole extends DialogPropertiesBase {\n\trole: 'alertdialog';\n}\n\nexport type DialogProperties = DialogPropertiesDialogRole | DialogPropertiesAlertDialogRole;\n\nexport interface DialogChild {\n\ttitle?: DNode;\n\tcontent?: DNode;\n\tactions?: DNode;\n}\n\nexport interface DialogState {\n\twasOpen: boolean;\n\tcallFocus: boolean;\n\ttitleId: string;\n\tcontentId: string;\n}\n\nconst factory = create({\n\ttheme,\n\ti18n,\n\ticache: createICacheMiddleware<DialogState>(),\n\tinert,\n\tbodyScroll\n})\n\t.properties<DialogProperties>()\n\t.children<DialogChild>();\nexport const Dialog = factory(function Dialog({\n\tmiddleware: { theme, i18n, icache, inert, bodyScroll },\n\tproperties,\n\tchildren\n}) {\n\tconst themeCss = theme.classes(css);\n\n\tlet {\n\t\topen,\n\t\taria = {},\n\t\tunderlay,\n\t\trole = 'dialog',\n\t\tcloseable = true,\n\t\tcloseText,\n\t\tclasses,\n\t\ttheme: themeProp,\n\t\tvariant\n\t} = properties();\n\tconst [{ title, actions, content }] = children();\n\tconst modal = role === 'alertdialog' || (properties() as DialogPropertiesDialogRole).modal;\n\n\tinert.set('dialog', open, true);\n\n\tif (!closeText) {\n\t\tconst { messages } = i18n.localize(bundle);\n\t\tcloseText = `${messages.close} ${title || ''}`;\n\t}\n\n\tconst wasOpen = icache.getOrSet('wasOpen', false);\n\tconst titleId = icache.getOrSet('titleId', uuid());\n\tconst contentId = icache.getOrSet('contentId', uuid());\n\n\tconst onOpen = () => {\n\t\tconst { onOpen } = properties();\n\t\ticache.set('callFocus', true);\n\n\t\tonOpen && onOpen();\n\t};\n\n\tconst close = () => {\n\t\tconst { closeable = true, onRequestClose } = properties();\n\n\t\tcloseable && onRequestClose();\n\t};\n\n\topen && !wasOpen && onOpen();\n\tif (wasOpen !== open) {\n\t\ticache.set('wasOpen', open);\n\t}\n\n\tconst callFocus = icache.getOrSet('callFocus', false);\n\tif (callFocus) {\n\t\ticache.set('callFocus', false);\n\t}\n\n\tconst keyup = (event: KeyboardEvent) => {\n\t\tevent.stopPropagation();\n\t\tif (event.which === Keys.Escape) {\n\t\t\tclose();\n\t\t}\n\t};\n\n\tbodyScroll(!open);\n\n\treturn (\n\t\t<body>\n\t\t\t<div\n\t\t\t\tkey=\"dialog\"\n\t\t\t\tclasses={[theme.variant(), themeCss.root, open ? themeCss.open : null]}\n\t\t\t>\n\t\t\t\t{open && (\n\t\t\t\t\t<virtual>\n\t\t\t\t\t\t<GlobalEvent key=\"global\" document={{ keyup }} />\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclasses={[\n\t\t\t\t\t\t\t\tunderlay ? themeCss.underlayVisible : null,\n\t\t\t\t\t\t\t\tfixedCss.underlay\n\t\t\t\t\t\t\t]}\n\t\t\t\t\t\t\tenterAnimation={themeCss.underlayEnter}\n\t\t\t\t\t\t\texitAnimation={themeCss.underlayExit}\n\t\t\t\t\t\t\tkey=\"underlay\"\n\t\t\t\t\t\t\tonclick={(event) => {\n\t\t\t\t\t\t\t\tconst { role } = properties();\n\t\t\t\t\t\t\t\tconst modal =\n\t\t\t\t\t\t\t\t\trole === 'alertdialog' ||\n\t\t\t\t\t\t\t\t\t(properties() as DialogPropertiesDialogRole).modal;\n\n\t\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\t\t!modal && close();\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\taria-labelledby={titleId}\n\t\t\t\t\t\t\taria-modal={modal ? 'true' : 'false'}\n\t\t\t\t\t\t\taria-describedby={role === 'alertdialog' ? contentId : undefined}\n\t\t\t\t\t\t\t{...formatAriaProperties(aria)}\n\t\t\t\t\t\t\tclasses={[themeCss.main, fixedCss.main]}\n\t\t\t\t\t\t\tenterAnimation={themeCss.enter}\n\t\t\t\t\t\t\texitAnimation={themeCss.exit}\n\t\t\t\t\t\t\tkey=\"main\"\n\t\t\t\t\t\t\trole={role}\n\t\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\t\tfocus={callFocus}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<div classes={themeCss.title} key=\"title\" id={titleId}>\n\t\t\t\t\t\t\t\t<div>{title}</div>\n\t\t\t\t\t\t\t\t{closeable && (\n\t\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t\tclasses={themeCss.close}\n\t\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t\t\tonclick={(event) => {\n\t\t\t\t\t\t\t\t\t\t\tevent.stopPropagation();\n\t\t\t\t\t\t\t\t\t\t\tclose();\n\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{closeText}\n\t\t\t\t\t\t\t\t\t\t<span classes={themeCss.closeIcon}>\n\t\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\t\ttheme={themeProp}\n\t\t\t\t\t\t\t\t\t\t\t\tclasses={classes}\n\t\t\t\t\t\t\t\t\t\t\t\tvariant={variant}\n\t\t\t\t\t\t\t\t\t\t\t\ttype=\"closeIcon\"\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div classes={themeCss.content} key=\"content\" id={contentId}>\n\t\t\t\t\t\t\t\t{content}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t{actions && (\n\t\t\t\t\t\t\t\t<div classes={themeCss.actions} key=\"actions\">\n\t\t\t\t\t\t\t\t\t{actions}\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</virtual>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</body>\n\t);\n});\n\nexport default Dialog;\n"]}