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:
parent
42e8971ff7
commit
d690d5922e
|
|
@ -34,9 +34,6 @@ export const CommandLinkManager: Component = () => {
|
||||||
const stream = useJournalStream();
|
const stream = useJournalStream();
|
||||||
const comp = useJournalCompletions();
|
const comp = useJournalCompletions();
|
||||||
|
|
||||||
const isObserver = () => stream.myRole === "observer";
|
|
||||||
const isPlayer = () => stream.myRole === "player";
|
|
||||||
|
|
||||||
// ---- Click interceptor (capture phase) ----
|
// ---- Click interceptor (capture phase) ----
|
||||||
|
|
||||||
const onClick = (e: MouseEvent) => {
|
const onClick = (e: MouseEvent) => {
|
||||||
|
|
@ -65,29 +62,11 @@ export const CommandLinkManager: Component = () => {
|
||||||
// ---- Command dispatch ----
|
// ---- Command dispatch ----
|
||||||
|
|
||||||
function dispatchCommand(command: string) {
|
function dispatchCommand(command: string) {
|
||||||
// Observers: everything goes as chat
|
// parseInput expects /roll, /spark, etc. — prepend / if missing
|
||||||
if (isObserver()) {
|
const prefixed = command.startsWith("/") ? command : "/" + command;
|
||||||
sendMessage("chat", { text: command });
|
const parsed = parseInput(prefixed);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsed = parseInput(command);
|
|
||||||
if (parsed.error) return;
|
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") {
|
if (parsed.type === "roll") {
|
||||||
const p = resolveRollPayload(
|
const p = resolveRollPayload(
|
||||||
parsed.payload as { notation: string; label?: string },
|
parsed.payload as { notation: string; label?: string },
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export const cmdDirective = {
|
||||||
|
|
||||||
const label = (token.attrs?.label as string) || command;
|
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>`;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,9 +150,13 @@ icon.big .icon-label-stroke {
|
||||||
opacity: unset;
|
opacity: unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cmd-link — clickable command spans from :cmd[] directive */
|
/* cmd-link — clickable command links from :cmd[] directive */
|
||||||
|
|
||||||
.cmd-link {
|
.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 hover:text-blue-800;
|
||||||
|
@apply active:text-blue-900;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue