mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-19 13:56:04 +00:00
Enhance authentication and authorization components
- Refactored `AppAuth` to introduce `getGuardContextSchema` for improved user context handling. - Updated `Authenticator` to utilize `pickKeys` for user data extraction in JWT generation. - Enhanced `Guard` class to improve permission checks and error handling. - Modified `SystemController` to return context schema alongside permissions in API responses. - Added new `permissions` method in `SystemApi` for fetching permissions. - Improved UI components with additional props and tooltip support for better user experience.
This commit is contained in:
73
app/src/ui/components/code/CodePreview.tsx
Normal file
73
app/src/ui/components/code/CodePreview.tsx
Normal file
@@ -0,0 +1,73 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTheme } from "ui/client/use-theme";
|
||||
import { cn } from "ui/lib/utils";
|
||||
|
||||
export type CodePreviewProps = {
|
||||
code: string;
|
||||
className?: string;
|
||||
lang?: string;
|
||||
theme?: string;
|
||||
enabled?: boolean;
|
||||
};
|
||||
|
||||
export const CodePreview = ({
|
||||
code,
|
||||
className,
|
||||
lang = "typescript",
|
||||
theme: _theme,
|
||||
enabled = true,
|
||||
}: CodePreviewProps) => {
|
||||
const [highlightedHtml, setHighlightedHtml] = useState<string | null>(null);
|
||||
const $theme = useTheme();
|
||||
const theme = (_theme ?? $theme.theme === "dark") ? "github-dark" : "github-light";
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
|
||||
let cancelled = false;
|
||||
setHighlightedHtml(null);
|
||||
|
||||
async function highlightCode() {
|
||||
try {
|
||||
// Dynamically import Shiki from CDN
|
||||
// @ts-expect-error - Dynamic CDN import
|
||||
const { codeToHtml } = await import("https://esm.sh/shiki@3.13.0");
|
||||
|
||||
if (cancelled) return;
|
||||
|
||||
const html = await codeToHtml(code, {
|
||||
lang,
|
||||
theme,
|
||||
structure: "inline",
|
||||
});
|
||||
|
||||
if (cancelled) return;
|
||||
|
||||
setHighlightedHtml(html);
|
||||
} catch (error) {
|
||||
console.error("Failed to load Shiki:", error);
|
||||
// Fallback to plain text if Shiki fails to load
|
||||
if (!cancelled) {
|
||||
setHighlightedHtml(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
highlightCode();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [code, enabled]);
|
||||
|
||||
if (!highlightedHtml) {
|
||||
return <pre className={cn("select-text cursor-text", className)}>{code}</pre>;
|
||||
}
|
||||
|
||||
return (
|
||||
<pre
|
||||
className={cn("select-text cursor-text", className)}
|
||||
dangerouslySetInnerHTML={{ __html: highlightedHtml }}
|
||||
/>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user