Skip to content

Commit 6b45aa6

Browse files
committed
fix(core): add custom confirm for reset buttons in popup mode
1 parent e32fc21 commit 6b45aa6

6 files changed

Lines changed: 96 additions & 10 deletions

File tree

packages/core/src/client/webcomponents/.generated/css.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<script setup lang="ts">
2+
import { ConfirmPromise } from '../../state/confirm'
3+
4+
function resolveConfirm(resolve: (value: boolean) => void, value: boolean) {
5+
resolve(value)
6+
}
7+
</script>
8+
9+
<template>
10+
<ConfirmPromise v-slot="{ resolve, args: [options] }">
11+
<div
12+
class="fixed inset-0 z-2147483647 flex items-center justify-center p-4 color-base"
13+
role="dialog"
14+
aria-modal="true"
15+
:aria-labelledby="options.title ? 'vite-devtools-confirm-title' : undefined"
16+
aria-describedby="vite-devtools-confirm-message"
17+
@keydown.esc.prevent.stop="resolveConfirm(resolve, false)"
18+
>
19+
<div
20+
class="absolute inset-0 bg-black/30 dark:bg-black/45 backdrop-blur-1 cursor-default"
21+
aria-hidden="true"
22+
@click="resolveConfirm(resolve, false)"
23+
/>
24+
25+
<div class="relative w-full max-w-96 bg-base border border-base rounded-lg shadow-xl p-5">
26+
<h3 v-if="options.title" id="vite-devtools-confirm-title" class="text-sm font-medium leading-5">
27+
{{ options.title }}
28+
</h3>
29+
<p
30+
id="vite-devtools-confirm-message"
31+
class="text-xs op60 leading-5"
32+
:class="options.title ? 'mt-1.5' : ''"
33+
>
34+
{{ options.message }}
35+
</p>
36+
37+
<div class="flex items-center justify-end gap-2 mt-6">
38+
<button
39+
type="button"
40+
class="px-3 py-1.5 rounded text-xs op60 hover:op100 hover:bg-gray/10 transition-colors"
41+
@click="resolveConfirm(resolve, false)"
42+
>
43+
{{ options.cancelText ?? 'Cancel' }}
44+
</button>
45+
<button
46+
type="button"
47+
autofocus
48+
class="px-3 py-1.5 rounded text-xs transition-colors bg-primary/15 text-primary hover:bg-primary/25"
49+
@click="resolveConfirm(resolve, true)"
50+
>
51+
{{ options.confirmText ?? 'OK' }}
52+
</button>
53+
</div>
54+
</div>
55+
</div>
56+
</ConfirmPromise>
57+
</template>

packages/core/src/client/webcomponents/components/dock/DockEmbedded.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { onUnmounted, ref } from 'vue'
55
import { sharedStateToRef } from '../../state/docks'
66
import { closeDockPopup, useIsDockPopupOpen } from '../../state/popup'
77
import CommandPalette from '../command-palette/CommandPalette.vue'
8+
import Confirm from '../display/Confirm.vue'
89
import ToastOverlay from '../display/ToastOverlay.vue'
910
import FloatingElements from '../floating/FloatingElements.vue'
1011
import Dock from './Dock.vue'
@@ -67,6 +68,7 @@ onUnmounted(() => {
6768
</Dock>
6869
</template>
6970
<FloatingElements />
71+
<Confirm />
7072
</template>
7173
<CommandPalette :context />
7274
<ToastOverlay :context />

packages/core/src/client/webcomponents/components/dock/DockStandalone.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { DocksContext } from '@vitejs/devtools-kit/client'
33
import { computed, markRaw, ref, useTemplateRef, watch } from 'vue'
44
import { PersistedDomViewsManager } from '../../utils/PersistedDomViewsManager'
55
import CommandPalette from '../command-palette/CommandPalette.vue'
6+
import Confirm from '../display/Confirm.vue'
67
import ToastOverlay from '../display/ToastOverlay.vue'
78
import FloatingElements from '../floating/FloatingElements.vue'
89
import VitePlus from '../icons/VitePlus.vue'
@@ -79,5 +80,6 @@ function switchEntry(id: string | undefined) {
7980
</div>
8081
<FloatingElements />
8182
<CommandPalette :context />
83+
<Confirm />
8284
<ToastOverlay :context />
8385
</template>

packages/core/src/client/webcomponents/components/views-builtin/SettingsAdvanced.vue

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,42 @@ import type { DocksContext } from '@vitejs/devtools-kit/client'
33
import type { SharedState } from 'devframe/utils/shared-state'
44
import type { DevToolsDocksUserSettings } from '../../state/dock-settings'
55
import { DEFAULT_STATE_USER_SETTINGS } from '@vitejs/devtools-kit/constants'
6+
import { useConfirm } from '../../state/confirm'
67
78
const props = defineProps<{
89
context: DocksContext
910
settingsStore: SharedState<DevToolsDocksUserSettings>
1011
}>()
1112
12-
function resetAllSettings() {
13-
// eslint-disable-next-line no-alert
14-
if (confirm('Reset all settings to defaults? This includes appearance, docks, and shortcuts.')) {
13+
const confirm = useConfirm()
14+
15+
async function resetAllSettings() {
16+
if (await confirm({
17+
title: 'Reset All Settings',
18+
message: 'Reset all settings to defaults? This includes appearance, docks, and shortcuts.',
19+
})) {
1520
props.settingsStore.mutate(() => {
1621
return DEFAULT_STATE_USER_SETTINGS()
1722
})
1823
}
1924
}
2025
21-
function resetShortcuts() {
22-
// eslint-disable-next-line no-alert
23-
if (confirm('Reset all keyboard shortcuts to defaults?')) {
26+
async function resetShortcuts() {
27+
if (await confirm({
28+
title: 'Reset Keyboard Shortcuts',
29+
message: 'Reset all keyboard shortcuts to defaults?',
30+
})) {
2431
props.settingsStore.mutate((state) => {
2532
state.commandShortcuts = {}
2633
})
2734
}
2835
}
2936
30-
function resetDocks() {
31-
// eslint-disable-next-line no-alert
32-
if (confirm('Reset dock visibility, order, and pinning to defaults?')) {
37+
async function resetDocks() {
38+
if (await confirm({
39+
title: 'Reset Dock Settings',
40+
message: 'Reset dock visibility, order, and pinning to defaults?',
41+
})) {
3342
props.settingsStore.mutate((state) => {
3443
const defaults = DEFAULT_STATE_USER_SETTINGS()
3544
state.docksHidden = defaults.docksHidden
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createTemplatePromise } from '@vueuse/core'
2+
3+
export interface ConfirmOptions {
4+
title?: string
5+
message: string
6+
confirmText?: string
7+
cancelText?: string
8+
}
9+
10+
export const ConfirmPromise = createTemplatePromise<boolean, [ConfirmOptions]>({
11+
singleton: true,
12+
})
13+
14+
export function useConfirm() {
15+
return ConfirmPromise.start
16+
}

0 commit comments

Comments
 (0)