Line data Source code
1 : <!-- The main global dialog to show various things -->
2 : <template>
3 3745 : <template v-for="item in dialogStore.dialogStack" :key="item.key">
4 1005 : <Dialog
5 : :open="item.visible"
6 : @update:open="(open) => onRekaOpenChange(item.key, open)"
7 : >
8 : <DialogPortal>
9 : <DialogOverlay />
10 : <DialogContent
11 : v-bind="isNamedByHeader(item) ? { 'aria-labelledby': item.key } : {}"
12 : :size="
13 : item.dialogComponentProps.headless
14 : ? 'fit'
15 : : (item.dialogComponentProps.size ?? 'md')
16 : "
17 : :surface="item.dialogComponentProps.headless ? 'none' : 'card'"
18 : :maximized="!!item.dialogComponentProps.maximized"
19 : :data-dialog-key="item.key"
20 : @escape-key-down="
21 : (e) => onRekaEscapeKeyDown(item.dialogComponentProps, e)
22 : "
23 : @pointer-down-outside="
24 : (e) => onRekaPointerDownOutside(item.dialogComponentProps, e)
25 : "
26 : @mousedown="() => dialogStore.riseDialog({ key: item.key })"
27 : >
28 : <template v-if="item.dialogComponentProps.headless">
29 : <component
30 : :is="item.component"
31 : v-bind="item.contentProps"
32 : :maximized="item.dialogComponentProps.maximized"
33 : />
34 : </template>
35 : <template v-else>
36 : <DialogHeader
37 : :class="
38 : item.headerComponent &&
39 : item.dialogComponentProps.flush &&
40 : cn('p-0', hasHeaderActions(item) && 'pr-3')
41 : "
42 : >
43 : <component
44 : :is="item.headerComponent"
45 : v-if="item.headerComponent"
46 : v-bind="item.headerProps"
47 : :id="item.key"
48 : />
49 : <DialogTitle v-else :id="item.key">
50 : {{ item.title || ' ' }}
51 : </DialogTitle>
52 : <div
53 : v-if="hasHeaderActions(item)"
54 : class="flex items-center gap-1"
55 : >
56 : <DialogMaximize
57 : v-if="item.dialogComponentProps.maximizable"
58 : :aria-label="
59 : item.dialogComponentProps.maximized
60 : ? $t('g.restoreDialog')
61 : : $t('g.maximizeDialog')
62 : "
63 : :maximized="!!item.dialogComponentProps.maximized"
64 : @toggle="toggleMaximize(item)"
65 : />
66 : <DialogClose
67 : v-if="hasCloseButton(item)"
68 : :aria-label="$t('g.close')"
69 : />
70 : </div>
71 : </DialogHeader>
72 : <div
73 : :class="
74 : cn(
75 : 'flex min-h-0 flex-1 flex-col overflow-auto',
76 : !item.dialogComponentProps.flush && 'px-4 py-2'
77 : )
78 : "
79 : >
80 : <component
81 : :is="item.component"
82 : v-bind="item.contentProps"
83 : :maximized="item.dialogComponentProps.maximized"
84 : />
85 : </div>
86 : <DialogFooter
87 : v-if="item.footerComponent"
88 : :class="item.dialogComponentProps.flush && 'p-0'"
89 : >
90 : <component :is="item.footerComponent" v-bind="item.footerProps" />
91 : </DialogFooter>
92 : </template>
93 : </DialogContent>
94 : </DialogPortal>
95 : </Dialog>
96 : </template>
97 : </template>
98 :
99 : <script setup lang="ts">
100 : import { cn } from '@comfyorg/tailwind-utils'
101 : import { provide } from 'vue'
102 :
103 : import { LocalAgentPanelPortKey } from '@/platform/openOnCloud/localAgentPanelPort'
104 : import { useOpenAgentPanel } from '@/workbench/extensions/agent/composables/agent/useOpenAgentPanel'
105 :
106 : import Dialog from '@comfyorg/design-system/dialog/Dialog'
107 : import DialogClose from '@comfyorg/design-system/dialog/DialogClose'
108 : import DialogContent from '@comfyorg/design-system/dialog/DialogContent'
109 : import DialogFooter from '@comfyorg/design-system/dialog/DialogFooter'
110 : import DialogHeader from '@comfyorg/design-system/dialog/DialogHeader'
111 : import DialogMaximize from '@comfyorg/design-system/dialog/DialogMaximize'
112 : import DialogOverlay from '@comfyorg/design-system/dialog/DialogOverlay'
113 : import DialogPortal from '@comfyorg/design-system/dialog/DialogPortal'
114 : import DialogTitle from '@comfyorg/design-system/dialog/DialogTitle'
115 : import {
116 : onRekaEscapeKeyDown,
117 : onRekaPointerDownOutside
118 : } from '@/components/dialog/dialogDismissGuards'
119 : import type { DialogInstance } from '@/stores/dialogStore'
120 : import { useDialogStore } from '@/stores/dialogStore'
121 :
122 2355 : provide(LocalAgentPanelPortKey, useOpenAgentPanel('cloud_button'))
123 :
124 2355 : const dialogStore = useDialogStore()
125 :
126 27 : function onRekaOpenChange(key: string, open: boolean) {
127 27 : if (!open) dialogStore.closeDialog({ key })
128 : }
129 :
130 988 : function isNamedByHeader(item: DialogInstance) {
131 988 : return (
132 : !item.dialogComponentProps.headless &&
133 : (!!item.headerComponent || !!item.title)
134 : )
135 : }
136 :
137 1352 : function hasCloseButton({ dialogComponentProps }: DialogInstance) {
138 1352 : return (
139 : dialogComponentProps.closable !== false &&
140 : dialogComponentProps.showCloseButton !== false
141 : )
142 : }
143 :
144 891 : function hasHeaderActions(item: DialogInstance) {
145 891 : return !!item.dialogComponentProps.maximizable || hasCloseButton(item)
146 : }
147 :
148 4 : function toggleMaximize(item: DialogInstance) {
149 4 : item.dialogComponentProps.maximized = !item.dialogComponentProps.maximized
150 : }
151 : </script>
|