The composer now writes markdown with bold, italic, strike, code, links, quotes and lists, from shortcuts, markdown typing or a bubble over the selection. @ mentions a bot and # a workspace, shown as chips and saved as [bot:ID] / [workspace:ID]. Text selected in a message can be quoted into the composer. User messages render as markdown, and replies tell the bot who and what the user mentioned. Adds an ESM stand-in for use-sync-external-store, since bunext keeps React external in page bundles and the CommonJS original requires it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import type { ComponentProps } from "react";
|
|
import Link from "@moduletrace/twui/layout/Link";
|
|
import { ComputerViewModes, type ComputerViewMode } from "@/src/dict/computer-dict";
|
|
import {
|
|
BotRefHrefPrefix,
|
|
ComputerRefHrefPrefix,
|
|
TakeOverRefHrefPrefix,
|
|
WorkspaceRefHrefPrefix,
|
|
} from "@/src/utils/link-computer-refs";
|
|
import BotRefChip from "./bot-ref-chip";
|
|
import ComputerRefChip from "./computer-ref-chip";
|
|
import TakeOverChip from "./take-over-chip";
|
|
import WorkspaceRefChip from "./workspace-ref-chip";
|
|
|
|
/**
|
|
* A link in a bot message. A computer the bot named (`linkComputerRefs`)
|
|
* becomes its switch button, a take-over request a button that opens the
|
|
* computer, a bot it named a link to that bot's conversation, a workspace
|
|
* a link to that workspace; anything else opens in a new tab.
|
|
*/
|
|
export default function MarkdownLink({ href, children }: ComponentProps<"a">) {
|
|
if (href?.startsWith(ComputerRefHrefPrefix)) {
|
|
const computer_id = Number(href.slice(ComputerRefHrefPrefix.length));
|
|
|
|
if (computer_id) return <ComputerRefChip computer_id={computer_id} />;
|
|
}
|
|
|
|
if (href?.startsWith(TakeOverRefHrefPrefix)) {
|
|
const [id, mode] = href.slice(TakeOverRefHrefPrefix.length).split("-");
|
|
const computer_id = Number(id);
|
|
const known = ComputerViewModes.some((m) => m.value == mode);
|
|
|
|
if (computer_id) {
|
|
return (
|
|
<TakeOverChip
|
|
computer_id={computer_id}
|
|
mode={(known ? mode : ComputerViewModes[0].value) as ComputerViewMode}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
if (href?.startsWith(BotRefHrefPrefix)) {
|
|
const bot_id = Number(href.slice(BotRefHrefPrefix.length));
|
|
|
|
if (bot_id) return <BotRefChip bot_id={bot_id} />;
|
|
}
|
|
|
|
if (href?.startsWith(WorkspaceRefHrefPrefix)) {
|
|
const workspace_id = Number(href.slice(WorkspaceRefHrefPrefix.length));
|
|
|
|
if (workspace_id) return <WorkspaceRefChip workspace_id={workspace_id} />;
|
|
}
|
|
|
|
return (
|
|
<Link
|
|
href={href}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="text-ink underline underline-offset-2 hover:opacity-80 break-words"
|
|
>
|
|
{children}
|
|
</Link>
|
|
);
|
|
}
|