PM: merge M1.12 notifications
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/architecture.md # docs/gaps.md # docs/roadmap.md # docs/target-app-parity.md # docs/ui-parity.md
This commit is contained in:
commit
2f8fef876b
21 changed files with 1178 additions and 94 deletions
|
|
@ -5,17 +5,20 @@
|
|||
*
|
||||
* Shortcuts come from the engine's command specs (see `shortcuts.ts`); the
|
||||
* area listens on the window in the capture phase so they also work while
|
||||
* CodeMirror has the focus.
|
||||
* CodeMirror has the focus. A keymap that cannot be loaded raises an
|
||||
* error toast.
|
||||
*/
|
||||
import { onBeforeUnmount, onMounted } from "vue";
|
||||
import { t } from "../../i18n";
|
||||
import { useEditorStore } from "../../stores/editor";
|
||||
import { useNotificationsStore } from "../../stores/notifications";
|
||||
import ClosePrompt from "./ClosePrompt.vue";
|
||||
import CodeEditor from "./CodeEditor.vue";
|
||||
import EditorTabs from "./EditorTabs.vue";
|
||||
import { commandFor, loadEditorKeymap, type EditorKeymap } from "./shortcuts";
|
||||
|
||||
const editor = useEditorStore();
|
||||
const notifications = useNotificationsStore();
|
||||
|
||||
/** Keymap loaded from the engine, empty until loaded. */
|
||||
let keymap: EditorKeymap = [];
|
||||
|
|
@ -52,7 +55,7 @@ onMounted(() => {
|
|||
if (result.ok) {
|
||||
keymap = result.value;
|
||||
} else {
|
||||
editor.lastError = result.error;
|
||||
notifications.notifyError("listCommands", result.error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
168
ui/src/components/notifications/NotificationStack.vue
Normal file
168
ui/src/components/notifications/NotificationStack.vue
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The toast stack at the bottom right of the window, newest at the bottom.
|
||||
*
|
||||
* Shows the toasts of the notifications store: info toasts as
|
||||
* `role="status"`, warnings and errors as `role="alert"`. Each toast has a
|
||||
* close button and closes with Escape while focus is inside it; older
|
||||
* toasts beyond the visible limit collapse into a "+n more" button. The
|
||||
* colours match the editor's in-place notices (`--lt-notice-bg`, the error
|
||||
* tint).
|
||||
*/
|
||||
import { CircleAlert, Info, TriangleAlert, X } from "@lucide/vue";
|
||||
import { t } from "../../i18n";
|
||||
import { useNotificationsStore, type NotificationLevel } from "../../stores/notifications";
|
||||
|
||||
const notifications = useNotificationsStore();
|
||||
|
||||
/** Icon of each level. */
|
||||
const ICONS = { info: Info, warning: TriangleAlert, error: CircleAlert } as const;
|
||||
|
||||
/**
|
||||
* ARIA role of a toast: errors and warnings interrupt, info is polite.
|
||||
*
|
||||
* @param level - the toast's level.
|
||||
*/
|
||||
function roleOf(level: NotificationLevel): "status" | "alert" {
|
||||
return level === "info" ? "status" : "alert";
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section
|
||||
v-if="notifications.toasts.length > 0"
|
||||
class="toasts"
|
||||
:aria-label="t('notification.stack.label')"
|
||||
data-test="toasts"
|
||||
>
|
||||
<button
|
||||
v-if="notifications.hiddenCount > 0"
|
||||
type="button"
|
||||
class="toasts__more"
|
||||
data-test="toasts-more"
|
||||
@click="notifications.expand()"
|
||||
>
|
||||
{{ t("notification.stack.more", { count: notifications.hiddenCount }) }}
|
||||
</button>
|
||||
<div
|
||||
v-for="toast in notifications.visible"
|
||||
:key="toast.id"
|
||||
class="toast"
|
||||
:class="`toast--${toast.level}`"
|
||||
:role="roleOf(toast.level)"
|
||||
data-test="toast"
|
||||
:data-level="toast.level"
|
||||
@keydown.escape.stop="notifications.dismiss(toast.id)"
|
||||
>
|
||||
<component
|
||||
:is="ICONS[toast.level]"
|
||||
class="toast__icon"
|
||||
:size="16"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span
|
||||
class="toast__text"
|
||||
data-test="toast-text"
|
||||
>{{ toast.text }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="toast__close"
|
||||
:aria-label="t('notification.close')"
|
||||
:title="t('notification.close')"
|
||||
data-test="toast-close"
|
||||
@click="notifications.dismiss(toast.id)"
|
||||
>
|
||||
<X
|
||||
:size="14"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.toasts {
|
||||
position: fixed;
|
||||
right: 16px;
|
||||
bottom: 36px;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 8px;
|
||||
width: min(420px, calc(100vw - 32px));
|
||||
max-height: calc(100vh - 72px);
|
||||
overflow-y: auto;
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
.toast {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 8px 8px 8px 12px;
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-notice-bg);
|
||||
border: 1px solid var(--lt-border);
|
||||
border-left: 3px solid var(--lt-fg-muted);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.toast--warning {
|
||||
border-left-color: var(--lt-accent);
|
||||
}
|
||||
|
||||
.toast--error {
|
||||
background: color-mix(in srgb, var(--lt-error) 15%, var(--lt-bg));
|
||||
border-left-color: var(--lt-error);
|
||||
}
|
||||
|
||||
.toast__icon {
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.toast--warning .toast__icon {
|
||||
color: var(--lt-accent);
|
||||
}
|
||||
|
||||
.toast--error .toast__icon {
|
||||
color: var(--lt-error);
|
||||
}
|
||||
|
||||
.toast__text {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.toast__close,
|
||||
.toasts__more {
|
||||
font: inherit;
|
||||
color: var(--lt-fg);
|
||||
background: transparent;
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.toast__close {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.toasts__more {
|
||||
padding: 2px 8px;
|
||||
background: var(--lt-notice-bg);
|
||||
}
|
||||
|
||||
.toast__close:focus-visible,
|
||||
.toasts__more:focus-visible {
|
||||
outline: 2px solid var(--lt-accent);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue