@olares/lares-mobile 0.15.17 → 0.15.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,153 @@
1
+ <template>
2
+ <div v-if="view.value" class="lares-voice-preferences">
3
+ <label>{{ t('preferences.dictationStyle') }}
4
+ <select :value="view.value.config.dictationPreset" :disabled="guardView.selecting || Boolean(view.pending.dictationPreset)" @change="selectPreset($event)">
5
+ <option v-for="id in presets" :key="id" :value="id">{{ t(`dictation.${id}`) }}</option>
6
+ </select>
7
+ </label>
8
+ <p v-if="view.errors.dictationPreset" role="alert">{{ t('settings.saveFailed') }}</p>
9
+ <p v-if="view.value.config.dictationPreset === 'raw'">{{ t('dictation.noLlm') }}</p>
10
+ <div v-else class="lares-voice-preferences__editor">
11
+ <label>{{ t('dictation.model') }}
12
+ <select :value="profile.model" :disabled="profilePending" @change="preferences.edit(view.value.config.dictationPreset, { model: $event.target.value })">
13
+ <option value="">{{ t('settings.model.none') }}</option>
14
+ <option v-for="item in models" :key="item.id" :value="item.id" :disabled="item.disabled">{{ item.label }}</option>
15
+ </select>
16
+ </label>
17
+ <label>{{ t('dictation.instructions') }}
18
+ <textarea ref="instructions" :value="profile.instructions" :disabled="profilePending" rows="6" maxlength="8000" @input="preferences.edit(view.value.config.dictationPreset, { instructions: $event.target.value })" />
19
+ </label>
20
+ <div class="lares-voice-preferences__actions">
21
+ <button type="button" :disabled="profilePending" @click="preferences.restore(view.value.config.dictationPreset)">{{ t('dictation.reset') }}</button>
22
+ <template v-if="preferences.dirty(view.value.config.dictationPreset)">
23
+ <button type="button" :disabled="profilePending" @click="preferences.discard([view.value.config.dictationPreset])">{{ t('preferences.cancel') }}</button>
24
+ <button type="button" :disabled="profilePending" @click="saveProfile">{{ t(profilePending ? 'preferences.saving' : 'preferences.save') }}</button>
25
+ </template>
26
+ </div>
27
+ <p v-if="view.errors[`profile:${view.value.config.dictationPreset}`]" role="alert">{{ t('settings.saveFailed') }}</p>
28
+ </div>
29
+ <TtsSettings :preferences="preferences" :view="view" :t="t" :fetcher="ttsFetch" />
30
+ <section v-if="device === 'desktop'" class="lares-voice-preferences__shortcuts">
31
+ <h3>{{ t('preferences.shortcuts') }}</h3>
32
+ <p>{{ t('preferences.shortcutScope') }}</p>
33
+ <div v-for="id in shortcutIds" :key="id" data-voice-shortcut-recorder @keydown.capture="shortcutKey($event, false)" @keyup.capture="shortcutKey($event, true)" @focusout="shortcutBlur($event, id)">
34
+ <div class="lares-voice-preferences__row">
35
+ <span>{{ shortcutTitle(id) }}</span>
36
+ <div class="lares-voice-preferences__actions">
37
+ <button :ref="element => { bindings[id] = element; }" type="button" :disabled="Boolean(shortcut.pending[id])" :aria-label="`${shortcutTitle(id)}: ${shortcutLabel(id)}`" :data-recording="shortcut.action === id" @click="recorder.begin(id)">{{ shortcutLabel(id) }}</button>
38
+ <button v-if="view.value.config.dictationShortcuts[id]" type="button" :disabled="Boolean(shortcut.pending[id])" :aria-label="`${t('preferences.clear')} ${shortcutTitle(id)}`" @click="recorder.clear(id)">×</button>
39
+ </div>
40
+ </div>
41
+ <p v-if="shortcut.action === id" role="status">{{ t('preferences.shortcutHelp') }}</p>
42
+ <p v-if="shortcut.errors[id]" role="alert">{{ t(`preferences.shortcutError.${shortcut.errors[id]}`) }}
43
+ <button v-if="shortcut.failed[id] != null" type="button" :disabled="Boolean(shortcut.pending[id])" @click="recorder.retry(id)">{{ t('dictation.retry') }}</button>
44
+ </p>
45
+ </div>
46
+ </section>
47
+ <LaresSheet :open="guardView.open" :title="t('preferences.unsaved')" @close="guard.answer('continue')">
48
+ <div class="lares-voice-preferences__question">
49
+ <p>{{ t('preferences.unsavedHint') }}</p>
50
+ <p v-if="guardView.error" role="alert">{{ t('settings.saveFailed') }}</p>
51
+ <button type="button" :disabled="guardView.saving" @click="guard.answer('continue')">{{ t('preferences.continue') }}</button>
52
+ <button type="button" :disabled="guardView.saving" @click="guard.answer('discard')">{{ t('preferences.discard') }}</button>
53
+ <button type="button" :disabled="guardView.saving" @click="guard.answer('save')">{{ t(guardView.saving ? 'preferences.saving' : 'preferences.save') }}</button>
54
+ </div>
55
+ </LaresSheet>
56
+ </div>
57
+ <p v-else role="status">{{ t(view.loadError ? 'settings.loadFailed' : 'settings.loading') }}</p>
58
+ </template>
59
+
60
+ <script>
61
+ import { markRaw, toRaw } from "vue";
62
+ import { createVoicePreferences, createPreferencesGuard } from "@olares/lares-core/voice/preferences";
63
+ import { createVoiceShortcutRecorder, formatVoiceShortcut } from "@olares/lares-core/voice/shortcuts";
64
+ import { DICTATION_PRESETS } from "@olares/lares-core/voice/dictation";
65
+ import LaresSheet from "./Sheet.vue";
66
+ import TtsSettings from "./TtsSettings.vue";
67
+
68
+ export default {
69
+ components: { LaresSheet, TtsSettings },
70
+ props: { ttsFetch: { type: Function, required: true }, settings: { type: Object, required: true }, snapshot: { type: Object, default: null }, device: { type: String, default: "mobile" }, t: { type: Function, required: true }, bindBeforeLeave: { type: Function, default: undefined } },
71
+ expose: ["beforeLeave", "reload", "patch"],
72
+ emits: ["change"],
73
+ data() {
74
+ const settings = this.settings;
75
+ const preferences = markRaw(createVoicePreferences({ load: options => settings.voice(options.force, { diagnostics: false }), save: patch => settings.saveVoice(patch, { diagnostics: false }) }));
76
+ if (this.snapshot) preferences.accept(toRaw(this.snapshot));
77
+ const guard = markRaw(createPreferencesGuard(preferences));
78
+ const recorder = markRaw(createVoiceShortcutRecorder({ current: () => preferences.getSnapshot().value.config.dictationShortcuts, save: (id, key) => preferences.saveShortcut(id, key) }));
79
+ return { preferences, guard, recorder, view: preferences.getSnapshot(), guardView: guard.getSnapshot(), shortcut: recorder.getSnapshot(), bindings: markRaw({}), presets: DICTATION_PRESETS, shortcutIds: ["default", ...DICTATION_PRESETS] };
80
+ },
81
+ computed: {
82
+ profile() { return this.view.value && this.view.value.config.dictationPreset !== "raw" ? this.preferences.profile(this.view.value.config.dictationPreset) : null; },
83
+ profilePending() { return this.guardView.selecting || Boolean(this.view.pending[`profile:${this.view.value.config.dictationPreset}`]); },
84
+ models() {
85
+ const available = this.view.value?.chatModels || [];
86
+ return [...new Set([this.profile?.model, ...(available.length ? ["default-chat"] : []), ...available].filter(Boolean))].map(id => {
87
+ const ready = available.includes(id) || id === "default-chat" && available.length > 0;
88
+ return { id, label: ready ? id : `${id} · ${this.t('preferences.unavailable')}`, disabled: !ready };
89
+ });
90
+ },
91
+ },
92
+ watch: {
93
+ snapshot(value) { if (value && toRaw(value) !== this.preferences.getSnapshot().value) this.preferences.accept(toRaw(value)); },
94
+ },
95
+ mounted() {
96
+ this.offPreferences = this.preferences.subscribe(() => { this.view = this.preferences.getSnapshot(); if (this.view.value) this.$emit("change", this.view.value); });
97
+ this.offGuard = this.guard.subscribe(() => { this.guardView = this.guard.getSnapshot(); });
98
+ this.offShortcut = this.recorder.subscribe(() => {
99
+ const previous = this.shortcut.pending; this.shortcut = this.recorder.getSnapshot();
100
+ if (!this.shortcut.action && document.activeElement === document.body) {
101
+ const id = Object.keys(previous).find(id => previous[id] && !this.shortcut.pending[id]);
102
+ if (id) this.$nextTick(() => this.bindings[id]?.focus());
103
+ }
104
+ });
105
+ this.offLeave = this.bindBeforeLeave?.(() => this.beforeLeave());
106
+ this.onUnload = event => { if (this.preferences.dirtyIds().length) { event.preventDefault(); event.returnValue = ""; } };
107
+ this.onEscape = event => { if (event.key === "Escape" && this.guardView.open) { event.preventDefault(); event.stopImmediatePropagation(); void this.guard.answer("continue"); } };
108
+ window.addEventListener("beforeunload", this.onUnload); window.addEventListener("keydown", this.onEscape, true);
109
+ if (this.snapshot) this.preferences.accept(toRaw(this.snapshot));
110
+ void this.preferences.load().catch(() => {});
111
+ },
112
+ beforeUnmount() {
113
+ this.offPreferences?.(); this.offGuard?.(); this.offShortcut?.(); this.offLeave?.(); this.guard.dispose();
114
+ window.removeEventListener("beforeunload", this.onUnload); window.removeEventListener("keydown", this.onEscape, true);
115
+ },
116
+ methods: {
117
+ beforeLeave() { return this.guard.request(); },
118
+ async patch(partial) { if (!this.view.value) await this.preferences.load(); return this.preferences.patch(partial); },
119
+ reload() { return this.preferences.load(true); },
120
+ async selectPreset(event) {
121
+ const id = event.target.value;
122
+ event.target.value = this.view.value.config.dictationPreset;
123
+ await this.guard.selectPreset(id).catch(() => {});
124
+ },
125
+ async saveProfile() { try { await this.preferences.saveProfile(this.view.value.config.dictationPreset); this.$refs.instructions?.focus(); } catch { /* The shared store retains the draft and error. */ } },
126
+ shortcutTitle(id) { return this.t(id === "default" ? "dictation.shortcut" : `dictation.${id}`); },
127
+ shortcutLabel(id) {
128
+ const mac = /Mac|iPhone|iPad/.test(globalThis.navigator?.platform || "");
129
+ return this.shortcut.action === id ? formatVoiceShortcut(this.shortcut.candidate, mac) || this.t("preferences.shortcutRecording") : this.shortcut.pending[id] ? this.t("preferences.saving") : formatVoiceShortcut(this.view.value.config.dictationShortcuts[id], mac) || this.t("preferences.unset");
130
+ },
131
+ shortcutKey(event, up) { if ((up ? this.recorder.keyup(event) : this.recorder.keydown(event))) { event.preventDefault(); event.stopPropagation(); } },
132
+ shortcutBlur(event, id) { if (!event.currentTarget.contains(event.relatedTarget) && this.shortcut.action === id) this.recorder.cancel(); },
133
+ },
134
+ };
135
+ </script>
136
+
137
+ <style scoped>
138
+ .lares-voice-preferences { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
139
+ .lares-voice-preferences h3 { margin: 8px 0 0; font-size: 15px; font-weight: 500; }
140
+ .lares-voice-preferences p { margin: 0; font-size: 13px; color: var(--q-ink-3); }
141
+ .lares-voice-preferences [role="alert"] { color: var(--q-orange-default); }
142
+ .lares-voice-preferences__row { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--q-separator); }
143
+ .lares-voice-preferences__row > span { flex: 1; min-width: 0; }
144
+ .lares-voice-preferences__actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
145
+ .lares-voice-preferences button, .lares-voice-preferences select { font: inherit; color: inherit; background: var(--q-background-2, transparent); border: 1px solid var(--q-separator); border-radius: 8px; padding: 6px 8px; cursor: pointer; max-width: 100%; }
146
+ .lares-voice-preferences button:disabled { opacity: .45; cursor: default; }
147
+ .lares-voice-preferences button[data-recording="true"] { outline: 2px solid var(--q-blue-default, #3978f6); }
148
+ .lares-voice-preferences button:focus-visible, .lares-voice-preferences textarea:focus-visible { outline: 2px solid var(--q-blue-default, #3978f6); outline-offset: 2px; }
149
+ .lares-voice-preferences__editor, .lares-voice-preferences label { display: flex; flex-direction: column; gap: 10px; }
150
+ .lares-voice-preferences textarea { box-sizing: border-box; width: 100%; min-height: 144px; padding: 10px; resize: vertical; color: inherit; background: transparent; border: 1px solid var(--q-separator); border-radius: 8px; font: inherit; line-height: 1.5; }
151
+ .lares-voice-preferences__shortcuts, .lares-voice-preferences__question { display: flex; flex-direction: column; gap: 12px; }
152
+ .lares-voice-preferences__question { padding: 12px 20px; }
153
+ </style>