MCPcopy Create free account
hub / github.com/massCodeIO/massCode / setup

Function setup

src/renderer/composables/useDialog.ts:47–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45 return new Promise<boolean>((resolve) => {
46 const DialogComponent = defineComponent({
47 setup() {
48 const isOpen = ref(true)
49
50 const onConfirm = () => {
51 if (!isDialogActive)
52 return
53
54 resolve(true)
55 isOpen.value = false
56 cleanup()
57 }
58
59 const onCancel = () => {
60 if (!isDialogActive)
61 return
62
63 resolve(false)
64 isOpen.value = false
65 cleanup()
66 }
67
68 const handleKeyDown = (event: KeyboardEvent) => {
69 if (event.key === 'Enter' && isOpen.value && isDialogActive) {
70 event.preventDefault()
71 onConfirm()
72 }
73 }
74
75 useEventListener(document, 'keydown', handleKeyDown)
76
77 onBeforeUnmount(() => {
78 isDialogActive = false
79 })
80
81 return () =>
82 h(
83 Dialog.Dialog,
84 {
85 'defaultOpen': isOpen.value,
86 'open': isOpen.value,
87 'onUpdate:open': (open: boolean) => {
88 isOpen.value = open
89 // Если диалог закрывается через UI, вызываем onCancel
90 if (!open && isDialogActive) {
91 onCancel()
92 }
93 },
94 },
95 {
96 default: () => [
97 h(
98 Dialog.DialogContent,
99 { class: 'sm:max-w-[425px]' },
100 {
101 default: () => [
102 h(
103 Dialog.DialogHeader,
104 {},

Callers

nothing calls this directly

Calls 1

onCancelFunction · 0.85

Tested by

no test coverage detected