diff --git a/src/components/editor/extensions/CodeBlockComponents/CodeBlock.tsx b/src/components/editor/extensions/CodeBlockComponents/CodeBlock.tsx index 22bd508..92b7fad 100644 --- a/src/components/editor/extensions/CodeBlockComponents/CodeBlock.tsx +++ b/src/components/editor/extensions/CodeBlockComponents/CodeBlock.tsx @@ -1,35 +1,114 @@ import React, { useEffect, useMemo, useState } from 'react' import { NodeViewWrapper, NodeViewContent, NodeViewProps } from '@tiptap/react' +import { Dropdown } from '@nextui-org/react' +import { + SiArduino, + SiGnubash, + SiC, + SiCplusplus, + SiCsharp, + SiCss3, + SiGo, + SiJava, + SiJavascript, + SiJson, + SiKotlin, + SiLess, + SiLua, + SiMarkdown, + SiPerl, + SiPhp, + SiPython, + SiR, + SiRuby, + SiRust, + SiSass, + SiShell, + SiSqlite, + SiSwift, + SiTypescript, +} from 'react-icons/si' +import { BiCodeAlt } from 'react-icons/bi' +import { BsFileText } from 'react-icons/bs' +import { VscDiff } from 'react-icons/vsc' -import { lowlight } from 'lowlight/lib/common.js'; import { getReverseLangAlias } from '../CodeBlockLowLight'; import './styles/CodeBlock.scss' +const langsIconsMap = { + "arduino": SiArduino, + "bash": SiGnubash, + "c": SiC, + "cpp": SiCplusplus, + "csharp": SiCsharp, + "css": SiCss3, + "diff": VscDiff, + "go": SiGo, + "ini": null, + "java": SiJava, + "javascript": SiJavascript, + "json": SiJson, + "kotlin": SiKotlin, + "less": SiLess, + "lua": SiLua, + "makefile": null, + "markdown": SiMarkdown, + "objectivec": SiC, + "perl": SiPerl, + "php": SiPhp, + "php-template": SiPhp, + "plaintext": BsFileText, + "python": SiPython, + "python-repl": SiPython, + "r": SiR, + "ruby": SiRuby, + "rust": SiRust, + "scss": SiSass, + "shell": SiShell, + "sql": SiSqlite, + "swift": SiSwift, + "typescript": SiTypescript, + "vbnet": null, + "xml": null, + "yaml": null +} + const CodeBlock: React.FC = ({ node: { attrs: { language } }, updateAttributes, editor }) => { const reverseLangAlias = useMemo(getReverseLangAlias, []) - const langs = useMemo(() => lowlight.listLanguages() || [], []) - const [val, setVal] = useState('') useEffect(() => { setVal(reverseLangAlias[language] || language) }, [language]) return ( -
-        
+           updateAttributes({ language: [...keys][0] || '' })}
+          >
+            {
+              Object.entries(langsIconsMap)
+                .map(([lang, icon]) => (
+                  
+                    {lang}
+                  
+                ))
+            }
+          
+        
         
       
diff --git a/src/components/editor/extensions/CodeBlockComponents/styles/CodeBlock.scss b/src/components/editor/extensions/CodeBlockComponents/styles/CodeBlock.scss index b301a7d..939f097 100644 --- a/src/components/editor/extensions/CodeBlockComponents/styles/CodeBlock.scss +++ b/src/components/editor/extensions/CodeBlockComponents/styles/CodeBlock.scss @@ -1,17 +1,10 @@ .code-block { position: relative; - select { - appearance: none; - background-color: var(--nextui-colors-background); - border-radius: var(--nextui-radii-sm); + .dropdown { padding-left: 10px; - justify-content: center; position: absolute; - right: 1rem; - top: 8px; - z-index: 100; - transform: translateY(-100%); - width: fit-content; + right: 4px; + top: 4px; } }