mirror of
https://github.com/supabase/supabase.git
synced 2026-06-17 21:23:59 +08:00
- Most changes are related to either types or `useRef` usages (it now requires an initial value). - also updated `vaul` to its latest version and haven't noticed any change ([design-system demo](https://design-system-git-react-19-supabase.vercel.app/design-system/docs/components/drawer)) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Upgraded workspace to React 19. * **Bug Fixes** * Improved null-safety and ref handling across editors, UI components, shortcuts, and markdown/image rendering to reduce runtime errors. * Safer event/timeout/interval cleanup and more robust command/context handling. * **Chores** * Bumped vaul dependency versions. * **Documentation** * Type and TypeScript accuracy improvements for clearer developer feedback. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45886) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
107 lines
2.4 KiB
TypeScript
107 lines
2.4 KiB
TypeScript
import Editor, { OnChange, useMonaco } from '@monaco-editor/react'
|
|
import { noop } from 'lodash'
|
|
import { useEffect, useRef } from 'react'
|
|
import { LogoLoader } from 'ui'
|
|
|
|
import { formatSql } from '@/lib/formatSql'
|
|
|
|
// [Joshen] We should deprecate this and use CodeEditor instead
|
|
|
|
interface SqlEditorProps {
|
|
contextmenu?: boolean
|
|
defaultValue?: string
|
|
language?: string
|
|
onInputChange?: OnChange
|
|
queryId?: string
|
|
readOnly?: boolean
|
|
}
|
|
|
|
/**
|
|
* @deprecated Use CodeEditor instead
|
|
*/
|
|
const SqlEditor = ({
|
|
queryId,
|
|
language = 'pgsql',
|
|
defaultValue = '',
|
|
readOnly = false,
|
|
contextmenu = true,
|
|
onInputChange = noop,
|
|
}: SqlEditorProps) => {
|
|
const monaco = useMonaco()
|
|
const editorRef = useRef<any>(null)
|
|
|
|
useEffect(() => {
|
|
if (monaco) {
|
|
// Enable pgsql format
|
|
const formatprovider = monaco.languages.registerDocumentFormattingEditProvider('pgsql', {
|
|
async provideDocumentFormattingEdits(model: any) {
|
|
const value = model.getValue()
|
|
const formatted = formatSql(value)
|
|
return [
|
|
{
|
|
range: model.getFullModelRange(),
|
|
text: formatted,
|
|
},
|
|
]
|
|
},
|
|
})
|
|
|
|
return () => {
|
|
formatprovider.dispose()
|
|
}
|
|
}
|
|
}, [monaco])
|
|
|
|
useEffect(() => {
|
|
if (editorRef.current) {
|
|
// add margin above first line
|
|
editorRef.current?.changeViewZones((accessor: any) => {
|
|
accessor.addZone({
|
|
afterLineNumber: 0,
|
|
heightInPx: 4,
|
|
domNode: document.createElement('div'),
|
|
})
|
|
})
|
|
}
|
|
}, [queryId])
|
|
|
|
const onMount = (editor: any, _monaco: any) => {
|
|
editorRef.current = editor
|
|
|
|
// Add margin above first line
|
|
editor.changeViewZones((accessor: any) => {
|
|
accessor.addZone({
|
|
afterLineNumber: 0,
|
|
heightInPx: 4,
|
|
domNode: document.createElement('div'),
|
|
})
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Editor
|
|
className="monaco-editor"
|
|
theme="supabase"
|
|
defaultLanguage={language}
|
|
defaultValue={defaultValue}
|
|
path={queryId}
|
|
loading={<LogoLoader />}
|
|
options={{
|
|
readOnly,
|
|
tabSize: 2,
|
|
fontSize: 13,
|
|
minimap: {
|
|
enabled: false,
|
|
},
|
|
wordWrap: 'on',
|
|
fixedOverflowWidgets: true,
|
|
contextmenu: contextmenu,
|
|
}}
|
|
onMount={onMount}
|
|
onChange={onInputChange}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export default SqlEditor
|