Files
supabase/apps/ui-library/registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx
Tiago AntunesandIvan Vasilov 9bf981f371 feat(ui-library): add Realtime Monaco ui component (#41766)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES
## What kind of change does this PR introduce?

Adds a new Realtime Monaco component to the UI Library, enabling
collaborative code editing with Supabase Realtime synchronization using
Monaco Editor and Yjs.

## Additional context

This is WIP and used for discuss further changes to the y-supabase
provider.

## Demo

https://github.com/user-attachments/assets/84a761e5-73bb-478e-979a-682121ffee89



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added a new Realtime Monaco collaborative code editor component with
real-time synchronization support across multiple frameworks (Next.js,
React, React Router, Tanstack).

* **Documentation**
* Added comprehensive documentation and usage guides for the Realtime
Monaco component across all supported frameworks.

* **Dependencies**
* Added Monaco editor, Yjs, y-monaco, and Supabase collaboration
packages.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2026-03-17 13:55:03 +01:00

44 lines
982 B
TypeScript

'use client'
import { Editor } from '@monaco-editor/react'
import { SupabasePersistenceOptions } from '@supabase-labs/y-supabase'
import { Awareness } from 'y-protocols/awareness.js'
import { useConnectOnMount } from '../hooks/use-connect-on-mount'
type RealtimeMonacoProps = {
channel: string
language?: string
height?: string | number
className?: string
awareness?: boolean | Awareness
persistence?: boolean | SupabasePersistenceOptions
theme?: 'light' | 'dark'
}
const DEFAULT_HEIGHT = 550
const RealtimeMonaco = ({
channel,
language = 'javascript',
height = DEFAULT_HEIGHT,
awareness = true,
persistence,
theme,
...rest
}: RealtimeMonacoProps) => {
const { connectOnMount } = useConnectOnMount({ channel, persistence, awareness })
return (
<Editor
height={height}
language={language}
theme={theme === 'dark' ? 'vs-dark' : 'light'}
onMount={connectOnMount}
{...rest}
/>
)
}
export { RealtimeMonaco }