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.
This commit is contained in:
hypercross 2026-07-12 14:18:01 +08:00
parent 42e8971ff7
commit d690d5922e
3 changed files with 10 additions and 27 deletions

View File

@ -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<string, unknown>);
return;
}
return;
}
// GM: all commands
if (parsed.type === "roll") {
const p = resolveRollPayload(
parsed.payload as { notation: string; label?: string },

View File

@ -24,7 +24,7 @@ export const cmdDirective = {
const label = (token.attrs?.label as string) || command;
return `<span class="cmd-link" data-cmd="${escapeAttr(command)}" role="button" tabindex="0">${escapeHtml(label)}</span>`;
return `<a class="cmd-link" data-cmd="${escapeAttr(command)}">${escapeHtml(label)}</a>`;
},
};

View File

@ -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;
}