Files
multica/packages/views/common/markdown.tsx
Naiyuan Qing 53cb01cc91 refactor(editor): remove hardcoded CDN domain, unify file card rendering
- Add GET /api/config endpoint exposing cdn_domain from CLOUDFRONT_DOMAIN
- Create packages/core/config/ zustand store, fetched at app startup
- Extract file card preprocessing to packages/ui/markdown/file-cards.ts
  with isCdnUrl(url, cdnDomain) using exact hostname match
- Add file card support to packages/ui/markdown/Markdown.tsx (was missing)
- Remove hardcoded .copilothub.ai hostname check from file-card.tsx
- Fix LocalStorage.CdnDomain() to return hostname not full URL
- Always run preprocessFileCards regardless of cdnDomain availability
  (!file syntax works without CDN domain, only legacy matching needs it)
- Use useConfigStore hook in common/markdown.tsx for reactive updates

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 10:43:36 +08:00

44 lines
1.2 KiB
TypeScript

"use client";
import * as React from "react";
import {
Markdown as MarkdownBase,
type MarkdownProps as MarkdownBaseProps,
type RenderMode,
} from "@multica/ui/markdown";
import { useConfigStore } from "@multica/core/config";
import { IssueMentionCard } from "../issues/components/issue-mention-card";
export type { RenderMode };
export type MarkdownProps = MarkdownBaseProps;
/**
* Default renderMention that delegates to IssueMentionCard for issue mentions
* and renders a styled span for other mention types.
*/
function defaultRenderMention({
type,
id,
}: {
type: string;
id: string;
}): React.ReactNode {
if (type === "issue") {
return <IssueMentionCard issueId={id} />;
}
return null;
}
/**
* App-level Markdown wrapper that injects IssueMentionCard via renderMention
* and cdnDomain from the config store for file card rendering.
*/
export function Markdown(props: MarkdownProps): React.JSX.Element {
const cdnDomain = useConfigStore((s) => s.cdnDomain);
return <MarkdownBase renderMention={defaultRenderMention} cdnDomain={cdnDomain} {...props} />;
}
export const MemoizedMarkdown = React.memo(Markdown);
MemoizedMarkdown.displayName = "MemoizedMarkdown";