From d690d5922ea6b44cb67d2eca51bb7adcf50ede45 Mon Sep 17 00:00:00 2001 From: hypercross Date: Sun, 12 Jul 2026 14:18:01 +0800 Subject: [PATCH] refactor: simplify command dispatch and update cmd-link - Simplify `dispatchCommand` by removing role-based logic and ensuring commands are prefixed with a slash. - Change `:cmd[]` directive output from a `span` to an `a` tag. - Update `.cmd-link` styles to improve link appearance and prevent text selection. --- src/components/CommandLinkManager.tsx | 27 +++------------------------ src/markdown/cmd.ts | 2 +- src/styles.css | 8 ++++++-- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/components/CommandLinkManager.tsx b/src/components/CommandLinkManager.tsx index 4218757..67dcd7f 100644 --- a/src/components/CommandLinkManager.tsx +++ b/src/components/CommandLinkManager.tsx @@ -34,9 +34,6 @@ export const CommandLinkManager: Component = () => { const stream = useJournalStream(); const comp = useJournalCompletions(); - const isObserver = () => stream.myRole === "observer"; - const isPlayer = () => stream.myRole === "player"; - // ---- Click interceptor (capture phase) ---- const onClick = (e: MouseEvent) => { @@ -65,29 +62,11 @@ export const CommandLinkManager: Component = () => { // ---- Command dispatch ---- function dispatchCommand(command: string) { - // Observers: everything goes as chat - if (isObserver()) { - sendMessage("chat", { text: command }); - return; - } - - const parsed = parseInput(command); + // parseInput expects /roll, /spark, etc. — prepend / if missing + const prefixed = command.startsWith("/") ? command : "/" + command; + const parsed = parseInput(prefixed); if (parsed.error) return; - // Players: chat + stat commands only - if (isPlayer()) { - if (parsed.type === "chat") { - sendMessage("chat", { text: command }); - return; - } - if (parsed.type === "stat") { - dispatchStat(parsed.payload as Record); - return; - } - return; - } - - // GM: all commands if (parsed.type === "roll") { const p = resolveRollPayload( parsed.payload as { notation: string; label?: string }, diff --git a/src/markdown/cmd.ts b/src/markdown/cmd.ts index 157dbe2..c435c87 100644 --- a/src/markdown/cmd.ts +++ b/src/markdown/cmd.ts @@ -24,7 +24,7 @@ export const cmdDirective = { const label = (token.attrs?.label as string) || command; - return `${escapeHtml(label)}`; + return `${escapeHtml(label)}`; }, }; diff --git a/src/styles.css b/src/styles.css index 212ea19..37ee3b5 100644 --- a/src/styles.css +++ b/src/styles.css @@ -150,9 +150,13 @@ icon.big .icon-label-stroke { opacity: unset; } -/* cmd-link — clickable command spans from :cmd[] directive */ +/* cmd-link — clickable command links from :cmd[] directive */ .cmd-link { - @apply text-blue-600 underline cursor-pointer; + @apply text-blue-600 underline cursor-pointer select-none outline-none; @apply hover:text-blue-800; + @apply active:text-blue-900; + user-select: none; + -webkit-user-select: none; + -webkit-tap-highlight-color: transparent; }