Lutra/ui/src/components/editor/ClosePrompt.vue
danny 7c0fb312f6 M1.11: English message catalog for every UI string
ui/src/i18n: en.json (20 flat dotted keys) and t(key, params?) with
{name} interpolation; a missing key warns in dev and returns the key.
All template text, title/aria-label attributes, notices and frontend
error texts go through t. ESLint vue/no-bare-strings-in-template is an
error. Catalog tests: interpolation, missing key, every t() key exists,
no unused keys. Engine messages stay English (G14). Docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 06:39:42 +02:00

136 lines
3 KiB
Vue

<script setup lang="ts">
/**
* The question shown when a tab with unsaved changes closes: Save,
* Don't Save or Cancel. Escape cancels; Save has the focus.
*/
import { nextTick, ref, watch } from "vue";
import { t } from "../../i18n";
import { useEditorStore } from "../../stores/editor";
const editor = useEditorStore();
/** The Save button, focused when the question appears. */
const saveButton = ref<HTMLButtonElement | null>(null);
watch(
() => editor.closePrompt,
async (prompt) => {
if (prompt) {
await nextTick();
saveButton.value?.focus();
}
},
{ immediate: true },
);
/**
* Cancels on Escape.
*
* @param event - the key event inside the dialog.
*/
function onKeydown(event: KeyboardEvent): void {
if (event.key === "Escape") {
event.preventDefault();
void editor.resolveClose("cancel");
}
}
</script>
<template>
<div
v-if="editor.closePrompt"
class="close-prompt"
data-test="close-prompt"
>
<div
class="close-prompt__dialog"
role="alertdialog"
aria-modal="true"
aria-labelledby="lt-close-prompt-title"
@keydown="onKeydown"
>
<p
id="lt-close-prompt-title"
class="close-prompt__text"
>
{{ t("editor.closePrompt.question", { name: editor.closePrompt.name }) }}
</p>
<div class="close-prompt__buttons">
<button
ref="saveButton"
type="button"
class="close-prompt__button close-prompt__button--primary"
data-test="close-save"
@click="editor.resolveClose('save')"
>
{{ t("common.save") }}
</button>
<button
type="button"
class="close-prompt__button"
data-test="close-discard"
@click="editor.resolveClose('discard')"
>
{{ t("common.dontSave") }}
</button>
<button
type="button"
class="close-prompt__button"
data-test="close-cancel"
@click="editor.resolveClose('cancel')"
>
{{ t("common.cancel") }}
</button>
</div>
</div>
</div>
</template>
<style scoped>
.close-prompt {
position: absolute;
inset: 0;
display: flex;
align-items: flex-start;
justify-content: center;
padding-top: 15%;
background: color-mix(in srgb, var(--lt-bg) 50%, transparent);
z-index: 10;
}
.close-prompt__dialog {
min-width: 320px;
padding: 16px;
background: var(--lt-bg);
color: var(--lt-fg);
border: 1px solid var(--lt-border);
border-radius: 6px;
}
.close-prompt__text {
margin: 0 0 16px;
}
.close-prompt__buttons {
display: flex;
justify-content: flex-end;
gap: 8px;
}
.close-prompt__button {
padding: 4px 12px;
font: inherit;
color: var(--lt-fg);
background: var(--lt-editor-bg);
border: 1px solid var(--lt-border);
border-radius: 4px;
}
.close-prompt__button--primary {
border-color: var(--lt-accent);
}
.close-prompt__button:focus-visible {
outline: 1px solid var(--lt-accent);
}
</style>