mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
Every hand-written button in the AI chat panel (Settings, the quick prompts, an attachment's remove, Attach layer, Attach a file, Expand conversation, the command suggestions, Expand chat, Add attachment and Send / Stop reply) and in the voice control (Open AI chat, Back to chat, Back to voice, the Preview and Settings tabs and the error tray's DISMISS) is a ghost UiButton keeping its id, classes, aria and data attributes, title and listeners. The Settings and tab Material glyphs are UiIcons with :size="null", so voice-cost.css and voice-card.css still size them. The tabs keep role="tab" and aria-selected; DISMISS is a text button, so it stays a UiButton rather than a UiCloseButton. The inline SVG glyphs, the message box, the file picker and the minutes field stay as they are. src/ui/kit/chatVoiceControls.test.mjs pins it: no hand-written button or Material span in the chat, voice, voice card, panel layout and visualizer templates, kit counts per file, the pressed toggles through :pressed, the icons' :size="null", the native fields left, and no button built in script by the voice modules. docs/VUE-MIGRATION.md describes the surface. Co-authored-by: Manjunath Paparaju <[email protected]>
124 lines
9.3 KiB
Vue
124 lines
9.3 KiB
Vue
<script setup>
|
||
import { nextTick, ref, watch } from 'vue';
|
||
import { storeToRefs } from 'pinia';
|
||
import { t } from '../../../i18n/index.js';
|
||
import { useVoiceStore } from '../../stores/voice.js';
|
||
import { ASSISTANT_NAME } from '../../../voice/control.js';
|
||
import PanelLayoutButtons from './PanelLayoutButtons.vue';
|
||
import UiButton from '../../kit/UiButton.vue';
|
||
import UiIcon from '../../kit/UiIcon.vue';
|
||
import UiCloseButton from '../../kit/UiCloseButton.vue';
|
||
import UiSelect from '../../kit/UiSelect.js';
|
||
|
||
// The typed chat in the command dock, as its owner (src/voice/chatControl.js)
|
||
// writes the voice control presenter. Messages arrive apart from the view, so
|
||
// a reply revealed frame by frame renders only this list.
|
||
const props = defineProps({ view: { type: Object, required: true } });
|
||
const store = useVoiceStore();
|
||
const { controls, chat: messages } = storeToRefs(store);
|
||
const emit = (name, ...args) => controls.value?.emit(name, ...args);
|
||
const list = ref(null);
|
||
const layerChoice = ref('');
|
||
|
||
// The input holds what the person types until its owner writes it (history
|
||
// recall, a suggestion, clearing after send): only then is it replaced.
|
||
const vOwnedDraft = {
|
||
mounted(el, { value }) {
|
||
el.value = value.text;
|
||
},
|
||
updated(el, { value, oldValue }) {
|
||
if (value.revision !== oldValue?.revision && el.value !== value.text)
|
||
el.value = value.text;
|
||
},
|
||
};
|
||
|
||
// Keep the newest message in view as the conversation grows, while the
|
||
// reader is at the bottom: one who scrolled up to read stays there until
|
||
// they send. The position is read on scroll, not on every reveal frame.
|
||
let stuck = true;
|
||
const onListScroll = () => {
|
||
const el = list.value;
|
||
if (el) stuck = el.scrollHeight - el.scrollTop - el.clientHeight < 24;
|
||
};
|
||
// A send is a new newest user message. The log is capped, so a full one
|
||
// does not grow as it takes a message: compare ids, not lengths.
|
||
const lastSent = (list) => list?.findLast((entry) => entry.role === 'user')?.id;
|
||
watch(messages, (next, previous) => {
|
||
const sent =
|
||
next.at(-1)?.role === 'user' && lastSent(next) !== lastSent(previous);
|
||
if (!stuck && !sent) return;
|
||
void nextTick(() => {
|
||
if (list.value) list.value.scrollTop = list.value.scrollHeight;
|
||
});
|
||
});
|
||
|
||
// Arrow keys only move the layer choice (a closed select changes on each
|
||
// press on Windows and Linux); the Attach button or Enter attaches it.
|
||
function attachLayer() {
|
||
const value = layerChoice.value;
|
||
layerChoice.value = '';
|
||
if (value) emit('chat-layer', value);
|
||
}
|
||
|
||
const quickPrompts = () => [t('Fly to Tokyo'), t('Show live flights')];
|
||
</script>
|
||
|
||
<template>
|
||
<section id="gev-chat-panel" :hidden="!props.view.chat.open" :data-minimized="props.view.chat.minimized ? 'true' : undefined" :aria-label="t('AI chat')">
|
||
<header class="gev-chat-header">
|
||
<div><strong>{{ t('GEV CHAT') }}</strong><p>{{ t('Ask about the map. Tell it where to go.') }}</p></div>
|
||
<div id="gev-chat-header-actions">
|
||
<PanelLayoutButtons :docked="props.view.layout.docked" :minimized="props.view.chat.minimized" @dock="emit('layout-dock')" @minimize="emit('chat-minimize')" />
|
||
<UiButton v-if="props.view.panel" id="gev-voice-settings-button" class="gev-voice-settings-button" :aria-label="t('Settings')" :title="t('Settings')" aria-controls="gev-voice-panel" :aria-expanded="String(props.view.voicePanel.settingsExpanded)" @click="emit('settings-button')"><UiIcon name="settings" class="gev-voice-settings-icon" :size="null" /></UiButton>
|
||
<UiCloseButton id="gev-chat-close" :label="t('Close chat')" @click="emit('chat-close')" />
|
||
</div>
|
||
</header>
|
||
<div id="gev-chat-messages" ref="list" role="log" :aria-label="t('Conversation')" aria-live="polite" :aria-busy="props.view.chat.busy || props.view.chat.revealing ? 'true' : undefined" @scroll.passive="onListScroll">
|
||
<div id="gev-chat-empty" :hidden="!props.view.chat.empty">
|
||
<svg viewBox="0 0 24 24" width="32" height="32" fill="none" stroke="currentColor" stroke-width="1" aria-hidden="true"><circle cx="12" cy="12" r="10"></circle><ellipse cx="12" cy="12" rx="4" ry="10"></ellipse><path d="M2 12h20"></path></svg>
|
||
<h3>{{ t('Explore with a question') }}</h3>
|
||
<p>{{ t('Find a place, explore live data, or change your view.') }}</p>
|
||
<UiButton v-for="prompt in quickPrompts()" :key="prompt" :hidden="!props.view.chat.quickChecked" @click="emit('chat-prompt', prompt)">{{ prompt }}</UiButton>
|
||
</div>
|
||
<div v-for="message in messages" :key="message.id" class="gev-chat-message" :data-role="message.role">
|
||
<small>{{ message.role === 'user' ? t('YOU') : ASSISTANT_NAME }}</small><span>{{ message.text }}</span>
|
||
</div>
|
||
</div>
|
||
<p id="gev-chat-status" role="status">{{ props.view.chat.status }}</p>
|
||
<!-- Stays under the status for the whole conversation. -->
|
||
<p v-if="props.view.chat.authNote" id="gev-chat-auth-note">{{ props.view.chat.authNote }}</p>
|
||
<div id="gev-chat-attachments" :aria-label="t('Attachments')" :hidden="!props.view.chat.attachments.length">
|
||
<UiButton v-for="item in props.view.chat.attachments" :key="item.key" :disabled="props.view.chat.locked" :aria-label="`${t('Remove attachment')}: ${item.name}`" @click="emit('chat-attachment-remove', item.key)">{{ item.name }} ×</UiButton>
|
||
</div>
|
||
<div id="gev-chat-attach-menu" :hidden="!props.view.chat.attachMenuOpen" @keydown="emit('chat-attach-keydown', $event)">
|
||
<label for="gev-chat-layer">{{ t('Attach a map layer') }}</label>
|
||
<div id="gev-chat-layer-row">
|
||
<UiSelect id="gev-chat-layer" v-model="layerChoice" :disabled="props.view.chat.locked" @keydown.enter.prevent="attachLayer()">
|
||
<option value="">{{ t('Choose a layer…') }}</option>
|
||
<option v-for="layer in props.view.chat.layers" :key="layer.value" :value="layer.value">{{ layer.label }}</option>
|
||
</UiSelect>
|
||
<UiButton id="gev-chat-layer-attach" :disabled="props.view.chat.locked || !layerChoice" @click="attachLayer()">{{ t('Attach layer') }}</UiButton>
|
||
</div>
|
||
<UiButton id="gev-chat-file-button" :disabled="props.view.chat.locked" @click="emit('chat-file-button')">{{ t('Attach a file') }}</UiButton>
|
||
<p>{{ t('TXT, Markdown, CSV, JSON or GeoJSON · up to 10 KB in total. Attachments are sent to your AI provider with your message.') }}</p>
|
||
<input id="gev-chat-file" type="file" accept=".txt,.md,.csv,.json,.geojson" multiple hidden @change="emit('chat-files', $event.target)" />
|
||
</div>
|
||
<aside id="gev-chat-mini-reply" :hidden="!props.view.chat.miniReply" :aria-label="t('Latest AI response')">
|
||
<header><span translate="no">{{ ASSISTANT_NAME }}</span><UiButton id="gev-chat-expand-reply" :aria-label="t('Expand conversation')" :title="t('Expand conversation')" @click="emit('chat-restore')"><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M14 4h6v6m0-6-7 7M10 20H4v-6m0 6 7-7"></path></svg></UiButton></header>
|
||
<p id="gev-chat-mini-text" aria-live="polite">{{ props.view.chat.miniReply }}</p>
|
||
</aside>
|
||
<div id="gev-chat-suggestions" :aria-label="t('Command suggestions')" :hidden="!props.view.chat.suggestions.length">
|
||
<div v-for="group in props.view.chat.suggestions" :key="group.label">
|
||
<small>{{ group.label }}</small>
|
||
<UiButton v-for="command in group.items" :key="command" :title="command" @click="emit('chat-suggestion', command)">{{ command }}</UiButton>
|
||
</div>
|
||
</div>
|
||
<form id="gev-chat-form" @submit.prevent="emit('chat-submit')">
|
||
<UiButton id="gev-chat-restore" :aria-label="t('Expand chat')" :title="t('Expand chat')" @click="emit('chat-restore')"><svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 4V6a2 2 0 0 1 2-2Z"></path></svg></UiButton>
|
||
<UiButton id="gev-chat-attach" :disabled="props.view.chat.busy" :aria-label="t('Add attachment')" :aria-expanded="String(props.view.chat.attachMenuOpen)" aria-controls="gev-chat-attach-menu" @click="emit('chat-attach-toggle')" @keydown="emit('chat-attach-keydown', $event)"><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="m8 12 6-6a3 3 0 0 1 4 4l-8 8a5 5 0 0 1-7-7l9-9"></path></svg></UiButton>
|
||
<textarea id="gev-chat-input" v-owned-draft="{ text: props.view.chat.draft, revision: props.view.chat.draftRevision }" :rows="props.view.chat.rows" maxlength="4000" :aria-label="t('Message GEV')" :placeholder="t('Ask GEV anything about the map…')" @input="emit('chat-input', $event.target.value)" @keydown="emit('chat-keydown', $event)"></textarea>
|
||
<UiButton id="gev-chat-send" :type="props.view.chat.busy ? 'button' : 'submit'" :disabled="props.view.chat.sendDisabled" :data-busy="String(props.view.chat.busy)" :aria-label="props.view.chat.busy ? t('Stop reply') : t('Send message')" :title="props.view.chat.busy ? t('Stop reply') : t('Send message')" @click="props.view.chat.busy && emit('chat-stop')"><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path class="gev-chat-enter-icon" d="M19 5v8H5m5-5-5 5 5 5"></path><rect class="gev-chat-stop-icon" x="6" y="6" width="12" height="12" rx="1.5" fill="currentColor" stroke="none"></rect></svg></UiButton>
|
||
</form>
|
||
</section>
|
||
</template>
|