{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "code-editor-languages",
  "title": "Languages",
  "description": "Language support for the code editor: syntax aware indentation, bracket matching, folding and completion.",
  "dependencies": [
    "@codemirror/lang-css",
    "@codemirror/lang-html",
    "@codemirror/lang-javascript",
    "@codemirror/lang-json",
    "@codemirror/lang-markdown",
    "@codemirror/state",
    "@codemirror/view"
  ],
  "registryDependencies": [
    "litingyes/blocove/code-editor-extension"
  ],
  "files": [
    {
      "path": "src/registry/blocove/ui/code-editor/languages.tsx",
      "content": "import type { Extension } from '@codemirror/state'\nimport type { CodeEditorExtensionContext } from '@/lib/blocove/code-editor-extension'\nimport { Compartment } from '@codemirror/state'\nimport { ViewPlugin } from '@codemirror/view'\nimport { defineCodeEditorExtension } from '@/lib/blocove/code-editor-extension'\n\nexport interface CodeEditorLanguagesProps {\n  /** Language used by the editing extensions. Falls back to the root language. */\n  language?: string\n}\n\n// A language is a CodeMirror extension that understands the document, so\n// indentation, bracket matching and folding follow the syntax. Highlighting is\n// separate: it comes from the shiki item.\nconst languageLoaders: Record<string, () => Promise<Extension>> = {\n  css: () => import('@codemirror/lang-css').then(module => module.css()),\n  html: () => import('@codemirror/lang-html').then(module => module.html()),\n  javascript: () => import('@codemirror/lang-javascript').then(module => module.javascript()),\n  json: () => import('@codemirror/lang-json').then(module => module.json()),\n  jsonc: () => import('@codemirror/lang-json').then(module => module.json()),\n  jsx: () => import('@codemirror/lang-javascript').then(module => module.javascript({ jsx: true })),\n  markdown: () => import('@codemirror/lang-markdown').then(module => module.markdown()),\n  tsx: () => import('@codemirror/lang-javascript').then(module => module.javascript({ jsx: true, typescript: true })),\n  typescript: () => import('@codemirror/lang-javascript').then(module => module.javascript({ typescript: true })),\n}\n\nconst aliases: Record<string, string> = {\n  js: 'javascript',\n  md: 'markdown',\n  ts: 'typescript',\n}\n\nfunction resolveLoader(language: string | undefined) {\n  if (!language) {\n    return null\n  }\n\n  const name = language.toLowerCase()\n\n  return languageLoaders[name] ?? languageLoaders[aliases[name]] ?? null\n}\n\nfunction languageSupport(language: string | undefined): Extension[] {\n  const loader = resolveLoader(language)\n\n  if (!loader) {\n    return []\n  }\n\n  const compartment = new Compartment()\n\n  return [\n    compartment.of([]),\n    ViewPlugin.define((view) => {\n      let cancelled = false\n\n      loader().then((extension) => {\n        if (cancelled) {\n          return\n        }\n\n        view.dispatch({\n          effects: compartment.reconfigure(extension),\n        })\n      }).catch(() => {})\n\n      return {\n        destroy() {\n          cancelled = true\n        },\n      }\n    }),\n  ]\n}\n\n/**\n * Language support for the editor: parses the document so the editing\n * behaviour (indentation, bracket matching, folding, completion) follows the\n * syntax. Colors come from the shiki item.\n */\nexport const CodeEditorLanguages = defineCodeEditorExtension<CodeEditorLanguagesProps>(\n  'languages',\n  (props: CodeEditorLanguagesProps, context: CodeEditorExtensionContext): Extension[] =>\n    languageSupport(props.language ?? context.language),\n)\n",
      "type": "registry:ui",
      "target": "components/blocove/code-editor/languages.tsx"
    }
  ],
  "categories": [
    "code-editor",
    "language"
  ],
  "type": "registry:ui"
}