From a42a458ed55291bbe5a18ab79456f1a08db374d6 Mon Sep 17 00:00:00 2001 From: Tumppi066 <83072683+Tumppi066@users.noreply.github.com> Date: Thu, 23 Jan 2025 19:03:43 +0200 Subject: [PATCH] Improve dialog support --- components/value-dialog.tsx | 126 +++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 22 deletions(-) diff --git a/components/value-dialog.tsx b/components/value-dialog.tsx index 1022137..4105a41 100644 --- a/components/value-dialog.tsx +++ b/components/value-dialog.tsx @@ -2,17 +2,10 @@ import { Dialog, DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, DialogTrigger, } from "@/components/ui/dialog" -import useSWR, { mutate } from "swr" -import { GetPlugins, PluginFunctionCall } from "@/apis/backend" import { Separator } from "./ui/separator" import { Input } from "./ui/input" -import { GetSettingsJSON, SetSettingByKey, SetSettingByKeys } from "@/apis/settings" -import { DisablePlugin, EnablePlugin } from "@/apis/backend" import { Select, SelectContent, @@ -23,35 +16,64 @@ import { import { Toggle } from "@/components/ui/toggle" import { Switch } from "./ui/switch" import { Button } from "./ui/button" -import { toast } from "sonner" -import { useEffect } from "react" import { Slider } from "./ui/slider" import { useState } from "react" import { translate } from "@/apis/translation" -import React, { Component } from 'react'; -import { SkeletonItem } from "./skeleton_item" +import React from 'react'; import { Check, X } from "lucide-react" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Progress } from "./ui/progress" +import Markdown from "react-markdown" +// @ts-expect-error +import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; +// @ts-expect-error +import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'; export default function ValueDialog({onClose, open, json}: {onClose: any, open: boolean, json: string}) { const [returnValue, setReturnValue] = useState({}) if (!json) return
- const TitleRenderer = (data:string) => { - return

{translate(data)}

+ const text_sizes = { + "xs": "text-xs", + "sm": "text-sm", + "md": "text-base", + "lg": "text-lg", + "xl": "text-xl", + "2xl": "text-2xl", } - const DescriptionRenderer = (data:string) => { - return

{translate(data)}

+ // Literal["thin", "light", "normal", "medium", "semibold", "bold"] + const weights = { + "thin": "font-thin", + "light": "font-light", + "normal": "font-normal", + "medium": "font-medium", + "semibold": "font-semibold", + "bold": "font-bold" } - const LabelRenderer = (data:string) => { - return

{translate(data)}

+ const TitleRenderer = (data: any) => { + // @ts-ignore + return

{translate(data.text)}

+ } + + const DescriptionRenderer = (data: any) => { + // @ts-ignore + return

{translate(data.text)}

+ } + + const LabelRenderer = (data: any) => { + // @ts-ignore + return

{translate(data.text)}

+ } + + const LinkRenderer = (data: any) => { + // @ts-ignore + return {translate(data.text)} } const SeparatorRenderer = () => { @@ -60,6 +82,60 @@ export default function ValueDialog({onClose, open, json}: {onClose: any, open: } + function MarkdownRenderer(data: any, no_padding?: boolean) { + return ( + + {children} + + ); + } + + // For code blocks (has line breaks) + return ( + + {String(children).replace(/\n$/, '')} + + ); + }, + // Custom renderer for images + img({node, ...props}) { + return ( + + ); + }, + }} className={data.classname}> + {data} + + ); + } + const SpaceRenderer = (data:number) => { if (data) { return
@@ -246,13 +322,19 @@ export default function ValueDialog({onClose, open, json}: {onClose: any, open: // Page looks if(key == "title"){ - result.push(TitleRenderer(key_data.text)) + result.push(TitleRenderer(key_data)) } if(key == "description"){ - result.push(DescriptionRenderer(key_data.text)) + result.push(DescriptionRenderer(key_data)) } if (key == "label") { - result.push(LabelRenderer(key_data.text)) + result.push(LabelRenderer(key_data)) + } + if (key == "link") { + result.push(LinkRenderer(key_data)) + } + if (key == "markdown") { + result.push(MarkdownRenderer(key_data.text)) } if (key == "separator") { result.push(SeparatorRenderer()) @@ -331,8 +413,8 @@ export default function ValueDialog({onClose, open, json}: {onClose: any, open:
- -
+ +
{PageRenderer(json)}