summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/AddNoteRowMenu.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/menus/AddNoteRowMenu.svelte')
-rw-r--r--web/src/lib/ui/menus/AddNoteRowMenu.svelte113
1 files changed, 113 insertions, 0 deletions
diff --git a/web/src/lib/ui/menus/AddNoteRowMenu.svelte b/web/src/lib/ui/menus/AddNoteRowMenu.svelte
new file mode 100644
index 0000000..5bb14a0
--- /dev/null
+++ b/web/src/lib/ui/menus/AddNoteRowMenu.svelte
@@ -0,0 +1,113 @@
+<!--
+ Add Note Row (the reference `NoteRowAddMenu`, Phase 3 form): a colour
+ picker, free text, and an optional link to a figure. Sending
+ `addNoteRow` appends the row (beneath its linked figure, if any).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { isCharacter, isMonster } from '$lib/protocol/types';
+ import { t } from '$lib/i18n';
+ import Menu from '../Menu.svelte';
+
+ let {
+ session,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ open?: boolean;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+
+ const COLORS = [
+ 0xffb58900,
+ 0xff1565c0,
+ 0xff2e7d32,
+ 0xffc2185b,
+ 0xffffb300,
+ 0xff5e35b1
+ ];
+
+ let color = $state(COLORS[0]);
+ let text = $state('');
+ let linkedId = $state('');
+
+ $effect(() => {
+ if (!open) return;
+ color = COLORS[0];
+ text = '';
+ linkedId = '';
+ });
+
+ const figures = $derived.by(() =>
+ ($gameState?.currentList ?? [])
+ .filter((i) => isCharacter(i) || isMonster(i))
+ .map((i) => ({
+ id: i.id,
+ name: isCharacter(i) ? i.characterState.display : i.id
+ }))
+ );
+
+ function colorCss(c: number): string {
+ return `#${c.toString(16).padStart(8, '0').slice(2)}`;
+ }
+
+ function add() {
+ if (!$player) return;
+ const id =
+ typeof crypto !== 'undefined' && 'randomUUID' in crypto
+ ? crypto.randomUUID()
+ : `note-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
+ session.command('addNoteRow', {
+ noteRow: {
+ id,
+ text: text.trim(),
+ color,
+ linkedId,
+ standeeNr: 0
+ }
+ });
+ open = false;
+ }
+</script>
+
+<Menu open={open} title={t('menuAddNoteRow')}>
+ <div style="display: flex; gap: 6px; padding: 8px 4px">
+ {#each COLORS as c (c)}
+ <button
+ aria-label="note colour"
+ style="width: 32px; height: 32px; border-radius: 6px; background: {colorCss(c)}; outline: {c === color ? '3px solid #fff' : 'none'}"
+ onclick={() => (color = c)}
+ ></button>
+ {/each}
+ </div>
+
+ <input class="search" placeholder={t('noteRowHint')} bind:value={text} />
+
+ <div class="statrow" style="align-items: center">
+ <span class="statrow__label" style="font-size: 13px">{t('noteRowWholeGroup')}</span>
+ <select
+ class="search"
+ style="margin: 0; width: auto"
+ value={linkedId}
+ onchange={(e) => (linkedId = e.currentTarget.value)}
+ >
+ <option value="">{t('noteRowAll')}</option>
+ {#each figures as f (f.id)}
+ <option value={f.id}>{f.name}</option>
+ {/each}
+ </select>
+ </div>
+
+ <div style="display: flex; justify-content: flex-end; padding: 8px 4px">
+ <button
+ class="stepbtn"
+ style="border-radius: 6px"
+ disabled={!$player || text.trim() === ''}
+ onclick={add}
+ >
+ {t('noteRowAddFromMenu')}
+ </button>
+ </div>
+</Menu>