"use client"; import { formatCodeBlock, isLangSupported } from "@platejs/code-block"; import { BracesIcon, Check, CheckIcon, CopyIcon } from "lucide-react"; import { NodeApi, type TCodeBlockElement, type TCodeSyntaxLeaf } from "platejs"; import { PlateElement, type PlateElementProps, PlateLeaf, type PlateLeafProps, useEditorRef, useElement, useReadOnly, } from "platejs/react"; import * as React from "react"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; export function CodeBlockElement(props: PlateElementProps) { const { editor, element } = props; return (
					{props.children}
				
{isLangSupported(element.lang) && ( )} NodeApi.string(element)} />
); } function CodeBlockCombobox() { const [open, setOpen] = React.useState(false); const readOnly = useReadOnly(); const editor = useEditorRef(); const element = useElement(); const value = element.lang || "plaintext"; const [searchValue, setSearchValue] = React.useState(""); const items = React.useMemo( () => languages.filter( (language) => !searchValue || language.label.toLowerCase().includes(searchValue.toLowerCase()) ), [searchValue] ); if (readOnly) return null; return ( setSearchValue("")}> setSearchValue(value)} placeholder="Search language..." /> No language found. {items.map((language) => ( { editor.tf.setNodes({ lang: value }, { at: element }); setSearchValue(value); setOpen(false); }} > {language.label} ))} ); } function CopyButton({ value, ...props }: { value: (() => string) | string } & Omit, "value">) { const [hasCopied, setHasCopied] = React.useState(false); React.useEffect(() => { if (!hasCopied) return; const timer = setTimeout(() => { setHasCopied(false); }, 2000); return () => clearTimeout(timer); }, [hasCopied]); return ( ); } export function CodeLineElement(props: PlateElementProps) { return ; } export function CodeSyntaxLeaf(props: PlateLeafProps) { const tokenClassName = props.leaf.className as string; return ; } const languages: { label: string; value: string }[] = [ { label: "Auto", value: "auto" }, { label: "Plain Text", value: "plaintext" }, { label: "ABAP", value: "abap" }, { label: "Agda", value: "agda" }, { label: "Arduino", value: "arduino" }, { label: "ASCII Art", value: "ascii" }, { label: "Assembly", value: "x86asm" }, { label: "Bash", value: "bash" }, { label: "BASIC", value: "basic" }, { label: "BNF", value: "bnf" }, { label: "C", value: "c" }, { label: "C#", value: "csharp" }, { label: "C++", value: "cpp" }, { label: "Clojure", value: "clojure" }, { label: "CoffeeScript", value: "coffeescript" }, { label: "Coq", value: "coq" }, { label: "CSS", value: "css" }, { label: "Dart", value: "dart" }, { label: "Dhall", value: "dhall" }, { label: "Diff", value: "diff" }, { label: "Docker", value: "dockerfile" }, { label: "EBNF", value: "ebnf" }, { label: "Elixir", value: "elixir" }, { label: "Elm", value: "elm" }, { label: "Erlang", value: "erlang" }, { label: "F#", value: "fsharp" }, { label: "Flow", value: "flow" }, { label: "Fortran", value: "fortran" }, { label: "Gherkin", value: "gherkin" }, { label: "GLSL", value: "glsl" }, { label: "Go", value: "go" }, { label: "GraphQL", value: "graphql" }, { label: "Groovy", value: "groovy" }, { label: "Haskell", value: "haskell" }, { label: "HCL", value: "hcl" }, { label: "HTML", value: "html" }, { label: "Idris", value: "idris" }, { label: "Java", value: "java" }, { label: "JavaScript", value: "javascript" }, { label: "JSON", value: "json" }, { label: "Julia", value: "julia" }, { label: "Kotlin", value: "kotlin" }, { label: "LaTeX", value: "latex" }, { label: "Less", value: "less" }, { label: "Lisp", value: "lisp" }, { label: "LiveScript", value: "livescript" }, { label: "LLVM IR", value: "llvm" }, { label: "Lua", value: "lua" }, { label: "Makefile", value: "makefile" }, { label: "Markdown", value: "markdown" }, { label: "Markup", value: "markup" }, { label: "MATLAB", value: "matlab" }, { label: "Mathematica", value: "mathematica" }, { label: "Mermaid", value: "mermaid" }, { label: "Nix", value: "nix" }, { label: "Notion Formula", value: "notion" }, { label: "Objective-C", value: "objectivec" }, { label: "OCaml", value: "ocaml" }, { label: "Pascal", value: "pascal" }, { label: "Perl", value: "perl" }, { label: "PHP", value: "php" }, { label: "PowerShell", value: "powershell" }, { label: "Prolog", value: "prolog" }, { label: "Protocol Buffers", value: "protobuf" }, { label: "PureScript", value: "purescript" }, { label: "Python", value: "python" }, { label: "R", value: "r" }, { label: "Racket", value: "racket" }, { label: "Reason", value: "reasonml" }, { label: "Ruby", value: "ruby" }, { label: "Rust", value: "rust" }, { label: "Sass", value: "scss" }, { label: "Scala", value: "scala" }, { label: "Scheme", value: "scheme" }, { label: "SCSS", value: "scss" }, { label: "Shell", value: "shell" }, { label: "Smalltalk", value: "smalltalk" }, { label: "Solidity", value: "solidity" }, { label: "SQL", value: "sql" }, { label: "Swift", value: "swift" }, { label: "TOML", value: "toml" }, { label: "TypeScript", value: "typescript" }, { label: "VB.Net", value: "vbnet" }, { label: "Verilog", value: "verilog" }, { label: "VHDL", value: "vhdl" }, { label: "Visual Basic", value: "vbnet" }, { label: "WebAssembly", value: "wasm" }, { label: "XML", value: "xml" }, { label: "YAML", value: "yaml" }, ];