mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 23:59:08 +03:00
* Start * Refactor code and remove unused imports * Refactor SchemaFlowHandler and UserChat components * Refactor code and remove unused files * Refactor Thread component and remove CurrentThreadName import * Remove oldest_messages view from supabase.ts * Refactor supabase.ts file * Hook up loading state ChatInput component and remove old route handlers * Add updated prompt * Refactor chat form component and remove unused code * Make the suspense work when fetching messages. * Small refactor in the chat assistant form component. * Experimenting with streaming responses. WIP. * Move all components to thread_id/message_id folder. * Massive refactor but uses Nextjs app router properly. * Add a conditional submit which is used if the user haven't been logged in. * Add a typecheck command to db-new app. * Minor fixes. * Bunch of minor fixes. * Clean up more code. * Refactor the AssistantChatForm to use the new React forms features. * Run fitView after 50 milliseconds because it didn't run in some cases. * Style and flow nudges * Prettier * Delete old file --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
102 lines
2.6 KiB
TypeScript
102 lines
2.6 KiB
TypeScript
'use client'
|
|
|
|
import Editor, { BeforeMount, EditorProps } from '@monaco-editor/react'
|
|
import { merge } from 'lodash'
|
|
|
|
interface MonacoEditorProps {
|
|
id: string
|
|
language: 'pgsql' | 'json' | 'html'
|
|
autofocus?: boolean
|
|
defaultValue?: string
|
|
isReadOnly?: boolean
|
|
onInputChange?: (value?: string) => void
|
|
onInputRun?: (value: string) => void
|
|
hideLineNumbers?: boolean
|
|
loading?: boolean
|
|
options?: EditorProps['options']
|
|
value?: string
|
|
}
|
|
|
|
const MonacoEditor = ({
|
|
id,
|
|
language,
|
|
defaultValue,
|
|
hideLineNumbers = false,
|
|
options,
|
|
value,
|
|
}: MonacoEditorProps) => {
|
|
// const monacoRef = useRef<any>()
|
|
// const { resolvedTheme } = useTheme()
|
|
|
|
const beforeMount: BeforeMount = (monaco) => {
|
|
// monacoRef.current = monaco
|
|
monaco.editor.defineTheme('supabase', {
|
|
base: 'vs-dark',
|
|
inherit: true,
|
|
rules: [
|
|
{ token: '', background: '1f1f1f' },
|
|
{ token: '', background: '1f1f1f', foreground: 'd4d4d4' },
|
|
{ token: 'string.sql', foreground: '24b47e' },
|
|
{ token: 'comment', foreground: '666666' },
|
|
{ token: 'predefined.sql', foreground: 'D4D4D4' },
|
|
],
|
|
colors: { 'editor.background': '#1f1f1f' },
|
|
})
|
|
}
|
|
|
|
// const onMount: OnMount = async (editor) => {
|
|
// // Add margin above first line
|
|
// editor.changeViewZones((accessor) => {
|
|
// accessor.addZone({
|
|
// afterLineNumber: 0,
|
|
// heightInPx: 4,
|
|
// domNode: document.createElement('div'),
|
|
// })
|
|
// })
|
|
|
|
// if (resolvedTheme) {
|
|
// const mode: any = getTheme(resolvedTheme)
|
|
// monacoRef.current.editor.defineTheme('supabase', mode)
|
|
// }
|
|
// }
|
|
|
|
const optionsMerged = merge(
|
|
{
|
|
tabSize: 2,
|
|
fontSize: 13,
|
|
readOnly: true,
|
|
minimap: { enabled: false },
|
|
wordWrap: 'on',
|
|
fixedOverflowWidgets: true,
|
|
contextmenu: true,
|
|
lineNumbers: hideLineNumbers ? 'off' : undefined,
|
|
glyphMargin: hideLineNumbers ? false : undefined,
|
|
lineNumbersMinChars: hideLineNumbers ? 0 : undefined,
|
|
occurrencesHighlight: false,
|
|
folding: hideLineNumbers ? false : undefined,
|
|
renderLineHighlight: 'none',
|
|
selectionHighlight: false,
|
|
},
|
|
options
|
|
)
|
|
|
|
merge({ cpp: '12' }, { java: '23' }, { python: '35' })
|
|
|
|
return (
|
|
<Editor
|
|
path={id}
|
|
theme="supabase"
|
|
className={'bg-alternative [&>div]:p-0'}
|
|
value={value ?? undefined}
|
|
defaultLanguage={language}
|
|
defaultValue={defaultValue ?? undefined}
|
|
loading={false}
|
|
options={optionsMerged}
|
|
beforeMount={beforeMount}
|
|
// onMount={onMount}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export { MonacoEditor }
|