Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(ui-library): add Realtime Monaco ui component (#41766)

Tiago Antunes9bf981f371fd
diff --git a/apps/ui-library/__registry__/index.tsx b/apps/ui-library/__registry__/index.tsx
index f20ed0206cd..7cd9c0996e9 100644
--- a/apps/ui-library/__registry__/index.tsx
+++ b/apps/ui-library/__registry__/index.tsx
@@ -15,6 +15,10 @@ export const Index = {
component: React.lazy(() => import("@/registry/default/examples/realtime-cursor-demo.tsx")),
}
,
+ "realtime-monaco-demo": {
+ component: React.lazy(() => import("@/registry/default/examples/realtime-monaco-demo.tsx")),
+ }
+ ,
"password-based-auth-demo": {
component: React.lazy(() => import("@/registry/default/examples/password-based-auth.tsx")),
}
diff --git a/apps/ui-library/app/example/realtime-monaco-demo/page.tsx b/apps/ui-library/app/example/realtime-monaco-demo/page.tsx
new file mode 100644
index 00000000000..7e2bdc7961c
--- /dev/null
+++ b/apps/ui-library/app/example/realtime-monaco-demo/page.tsx
@@ -0,0 +1,9 @@
+'use client'
+
+import Demo from '@/registry/default/examples/realtime-monaco-demo'
+
+const RealtimeMonacoDemoPage = () => {
+ return <Demo />
+}
+
+export default RealtimeMonacoDemoPage
diff --git a/apps/ui-library/components/dual-realtime-monaco.tsx b/apps/ui-library/components/dual-realtime-monaco.tsx
new file mode 100644
index 00000000000..687a0ea63f9
--- /dev/null
+++ b/apps/ui-library/components/dual-realtime-monaco.tsx
@@ -0,0 +1,12 @@
+'use client'
+
+import { BlockPreview } from './block-preview'
+
+export function DualRealtimeMonaco() {
+ return (
+ <div className="flex flex-row -space-x-px w-full">
+ <BlockPreview name="realtime-monaco-demo" isPair />
+ <BlockPreview name="realtime-monaco-demo" isPair />
+ </div>
+ )
+}
diff --git a/apps/ui-library/components/mdx-components.tsx b/apps/ui-library/components/mdx-components.tsx
index 22600e89326..372a9d82406 100644
--- a/apps/ui-library/components/mdx-components.tsx
+++ b/apps/ui-library/components/mdx-components.tsx
@@ -14,6 +14,7 @@ import { Callout } from './callout'
import { ComponentPreview } from './component-preview'
import { CopyButton } from './copy-button'
import { DualRealtimeChat } from './dual-realtime-chat'
+import { DualRealtimeMonaco } from './dual-realtime-monaco'
import { RegistryBlock } from './registry-block'
import { StyleWrapper } from './style-wrapper'
import TanStackBeta from './tanstack-beta'
@@ -182,6 +183,7 @@ const components = {
BlockItem,
BlockPreview,
DualRealtimeChat,
+ DualRealtimeMonaco,
TanstackDBGenerator,
}
diff --git a/apps/ui-library/config/docs.ts b/apps/ui-library/config/docs.ts
index 17302b7ff19..34c7f4a4893 100644
--- a/apps/ui-library/config/docs.ts
+++ b/apps/ui-library/config/docs.ts
@@ -88,6 +88,13 @@ export const componentPages: SidebarNavGroup = {
items: [],
commandItemLabel: 'Realtime Cursor',
},
+ {
+ title: 'Realtime Monaco',
+ supportedFrameworks: ['nextjs', 'react-router', 'tanstack', 'react'],
+ href: '/docs/nextjs/realtime-monaco',
+ items: [],
+ commandItemLabel: 'Realtime Monaco',
+ },
{
title: 'Current User Avatar',
supportedFrameworks: ['nextjs', 'react-router', 'tanstack', 'react', 'vue', 'nuxtjs'],
diff --git a/apps/ui-library/content/docs/nextjs/realtime-monaco.mdx b/apps/ui-library/content/docs/nextjs/realtime-monaco.mdx
new file mode 100644
index 00000000000..06b21c75070
--- /dev/null
+++ b/apps/ui-library/content/docs/nextjs/realtime-monaco.mdx
@@ -0,0 +1,124 @@
+---
+title: Realtime Monaco
+description: Real-time Monaco editor for collaborative applications
+---
+
+<DualRealtimeMonaco />
+
+## Installation
+
+<BlockItem
+ name="realtime-monaco-nextjs"
+ description="Real-time Monaco editor for collaborative applications."
+/>
+
+## Folder structure
+
+<RegistryBlock itemName="realtime-monaco-nextjs" />
+
+## Introduction
+
+The Realtime Monaco component provides a collaborative code editor powered by [Monaco](https://microsoft.github.io/monaco-editor/) and [Yjs](https://yjs.dev/). It uses [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase) under the hood to sync document state across clients through Supabase Realtime.
+
+**Features**
+
+- Real-time document synchronization via Supabase Realtime broadcast
+- Cursor and selection sharing between collaborators (awareness)
+- Optional persistence to Postgres so documents survive page reloads
+- Supports all Monaco languages and themes
+- Room-based isolation for scoped collaboration
+
+## How it works under the hood
+
+The component creates a [Yjs](https://yjs.dev/) document and connects it to a Supabase Realtime channel using `SupabaseProvider` from `@supabase-labs/y-supabase`. A `MonacoBinding` from `y-monaco` bridges the Yjs document with the Monaco editor model, keeping them in sync.
+
+When **awareness** is enabled, each user's cursor position and selection are broadcast to other clients in the same channel. Remote cursors are rendered with unique colors via dynamically injected CSS.
+
+When **persistence** is enabled, the full Yjs document state is saved to a Postgres table so it can be restored when clients reconnect.
+
+## Usage
+
+### Basic usage
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" />
+}
+```
+
+### With persistence
+
+Enable persistence to save the editor content to your Supabase database. This requires a table to store the Yjs document state.
+
+First, create the required table in your Supabase project:
+
+```sql
+create table yjs_documents (
+ room text primary key,
+ state text not null
+);
+```
+
+Then pass `persistence` to the component:
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" persistence />
+}
+```
+
+You can also pass a `SupabasePersistenceOptions` object:
+
+```tsx
+<RealtimeMonaco
+ channel="realtime-monaco-demo"
+ language="typescript"
+ persistence={{
+ table: 'yjs_documents',
+ roomColumn: 'room',
+ stateColumn: 'state',
+ storeTimeout: 2000,
+ }}
+/>
+```
+
+### Without awareness
+
+By default, cursor and selection positions are shared between collaborators. To disable this:
+
+```tsx
+<RealtimeMonaco channel="realtime-monaco-demo" awareness={false} />
+```
+
+## Props
+
+| Prop | Type | Description |
+| -------------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
+| `channel` | `string` | Unique channel name used to sync editor content between collaborators in the same session. |
+| `language?` | `string` | Monaco [language identifier](https://code.visualstudio.com/docs/languages/identifiers) (e.g. `typescript`, `python`). Defaults to `javascript`. |
+| `height?` | `string \| number` | Height of the editor container. Accepts a pixel number or CSS string (e.g. `"100%"`). Defaults to `550`. |
+| `className?` | `string` | CSS class applied to the editor wrapper element. |
+| `awareness?` | `boolean \| Awareness` | Enables cursor and selection sharing between users. Pass `false` to disable or a custom `Awareness` instance. Defaults to `true`. |
+| `persistence?` | `boolean \| SupabasePersistenceOptions` | Persists editor content to Supabase so it survives page reloads. Pass `true` for defaults or an options object for fine-grained control. |
+| `theme?` | `'light' \| 'dark'` | Color theme for the editor. Maps to Monaco's `light` and `vs-dark` themes. |
+
+### SupabasePersistenceOptions
+
+| Option | Type | Default | Description |
+| -------------- | -------- | ----------------- | --------------------------------------------------- |
+| `table` | `string` | `'yjs_documents'` | Name of the Postgres table used to store documents. |
+| `schema` | `string` | `'public'` | Schema where the table is located. |
+| `roomColumn` | `string` | `'room'` | Column used as the document identifier. |
+| `stateColumn` | `string` | `'state'` | Column used to store the binary Yjs state. |
+| `storeTimeout` | `number` | `1000` | Debounce delay (ms) before persisting changes. |
+
+## Further reading
+
+- [Realtime Broadcast](https://supabase.com/docs/guides/realtime/broadcast)
+- [Realtime authorization](https://supabase.com/docs/guides/realtime/authorization)
+- [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase)
+- [Yjs documentation](https://docs.yjs.dev/)
diff --git a/apps/ui-library/content/docs/react-router/realtime-monaco.mdx b/apps/ui-library/content/docs/react-router/realtime-monaco.mdx
new file mode 100644
index 00000000000..3959f8a34e0
--- /dev/null
+++ b/apps/ui-library/content/docs/react-router/realtime-monaco.mdx
@@ -0,0 +1,124 @@
+---
+title: Realtime Monaco
+description: Real-time Monaco editor for collaborative applications
+---
+
+<DualRealtimeMonaco />
+
+## Installation
+
+<BlockItem
+ name="realtime-monaco-react-router"
+ description="Real-time Monaco editor for collaborative applications."
+/>
+
+## Folder structure
+
+<RegistryBlock itemName="realtime-monaco-react-router" />
+
+## Introduction
+
+The Realtime Monaco component provides a collaborative code editor powered by [Monaco](https://microsoft.github.io/monaco-editor/) and [Yjs](https://yjs.dev/). It uses [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase) under the hood to sync document state across clients through Supabase Realtime.
+
+**Features**
+
+- Real-time document synchronization via Supabase Realtime broadcast
+- Cursor and selection sharing between collaborators (awareness)
+- Optional persistence to Postgres so documents survive page reloads
+- Supports all Monaco languages and themes
+- Room-based isolation for scoped collaboration
+
+## How it works under the hood
+
+The component creates a [Yjs](https://yjs.dev/) document and connects it to a Supabase Realtime channel using `SupabaseProvider` from `@supabase-labs/y-supabase`. A `MonacoBinding` from `y-monaco` bridges the Yjs document with the Monaco editor model, keeping them in sync.
+
+When **awareness** is enabled, each user's cursor position and selection are broadcast to other clients in the same channel. Remote cursors are rendered with unique colors via dynamically injected CSS.
+
+When **persistence** is enabled, the full Yjs document state is saved to a Postgres table so it can be restored when clients reconnect.
+
+## Usage
+
+### Basic usage
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" />
+}
+```
+
+### With persistence
+
+Enable persistence to save the editor content to your Supabase database. This requires a table to store the Yjs document state.
+
+First, create the required table in your Supabase project:
+
+```sql
+create table yjs_documents (
+ room text primary key,
+ state text not null
+);
+```
+
+Then pass `persistence` to the component:
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" persistence />
+}
+```
+
+You can also pass a `SupabasePersistenceOptions` object:
+
+```tsx
+<RealtimeMonaco
+ channel="realtime-monaco-demo"
+ language="typescript"
+ persistence={{
+ table: 'yjs_documents',
+ roomColumn: 'room',
+ stateColumn: 'state',
+ storeTimeout: 2000,
+ }}
+/>
+```
+
+### Without awareness
+
+By default, cursor and selection positions are shared between collaborators. To disable this:
+
+```tsx
+<RealtimeMonaco channel="realtime-monaco-demo" awareness={false} />
+```
+
+## Props
+
+| Prop | Type | Description |
+| -------------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
+| `channel` | `string` | Unique channel name used to sync editor content between collaborators in the same session. |
+| `language?` | `string` | Monaco [language identifier](https://code.visualstudio.com/docs/languages/identifiers) (e.g. `typescript`, `python`). Defaults to `javascript`. |
+| `height?` | `string \| number` | Height of the editor container. Accepts a pixel number or CSS string (e.g. `"100%"`). Defaults to `550`. |
+| `className?` | `string` | CSS class applied to the editor wrapper element. |
+| `awareness?` | `boolean \| Awareness` | Enables cursor and selection sharing between users. Pass `false` to disable or a custom `Awareness` instance. Defaults to `true`. |
+| `persistence?` | `boolean \| SupabasePersistenceOptions` | Persists editor content to Supabase so it survives page reloads. Pass `true` for defaults or an options object for fine-grained control. |
+| `theme?` | `'light' \| 'dark'` | Color theme for the editor. Maps to Monaco's `light` and `vs-dark` themes. |
+
+### SupabasePersistenceOptions
+
+| Option | Type | Default | Description |
+| -------------- | -------- | ----------------- | --------------------------------------------------- |
+| `table` | `string` | `'yjs_documents'` | Name of the Postgres table used to store documents. |
+| `schema` | `string` | `'public'` | Schema where the table is located. |
+| `roomColumn` | `string` | `'room'` | Column used as the document identifier. |
+| `stateColumn` | `string` | `'state'` | Column used to store the binary Yjs state. |
+| `storeTimeout` | `number` | `1000` | Debounce delay (ms) before persisting changes. |
+
+## Further reading
+
+- [Realtime Broadcast](https://supabase.com/docs/guides/realtime/broadcast)
+- [Realtime authorization](https://supabase.com/docs/guides/realtime/authorization)
+- [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase)
+- [Yjs documentation](https://docs.yjs.dev/)
diff --git a/apps/ui-library/content/docs/react/realtime-monaco.mdx b/apps/ui-library/content/docs/react/realtime-monaco.mdx
new file mode 100644
index 00000000000..016f2baa712
--- /dev/null
+++ b/apps/ui-library/content/docs/react/realtime-monaco.mdx
@@ -0,0 +1,124 @@
+---
+title: Realtime Monaco
+description: Real-time Monaco editor for collaborative applications
+---
+
+<DualRealtimeMonaco />
+
+## Installation
+
+<BlockItem
+ name="realtime-monaco-react"
+ description="Real-time Monaco editor for collaborative applications."
+/>
+
+## Folder structure
+
+<RegistryBlock itemName="realtime-monaco-react" />
+
+## Introduction
+
+The Realtime Monaco component provides a collaborative code editor powered by [Monaco](https://microsoft.github.io/monaco-editor/) and [Yjs](https://yjs.dev/). It uses [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase) under the hood to sync document state across clients through Supabase Realtime.
+
+**Features**
+
+- Real-time document synchronization via Supabase Realtime broadcast
+- Cursor and selection sharing between collaborators (awareness)
+- Optional persistence to Postgres so documents survive page reloads
+- Supports all Monaco languages and themes
+- Room-based isolation for scoped collaboration
+
+## How it works under the hood
+
+The component creates a [Yjs](https://yjs.dev/) document and connects it to a Supabase Realtime channel using `SupabaseProvider` from `@supabase-labs/y-supabase`. A `MonacoBinding` from `y-monaco` bridges the Yjs document with the Monaco editor model, keeping them in sync.
+
+When **awareness** is enabled, each user's cursor position and selection are broadcast to other clients in the same channel. Remote cursors are rendered with unique colors via dynamically injected CSS.
+
+When **persistence** is enabled, the full Yjs document state is saved to a Postgres table so it can be restored when clients reconnect.
+
+## Usage
+
+### Basic usage
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" />
+}
+```
+
+### With persistence
+
+Enable persistence to save the editor content to your Supabase database. This requires a table to store the Yjs document state.
+
+First, create the required table in your Supabase project:
+
+```sql
+create table yjs_documents (
+ room text primary key,
+ state text not null
+);
+```
+
+Then pass `persistence` to the component:
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" persistence />
+}
+```
+
+You can also pass a `SupabasePersistenceOptions` object:
+
+```tsx
+<RealtimeMonaco
+ channel="realtime-monaco-demo"
+ language="typescript"
+ persistence={{
+ table: 'yjs_documents',
+ roomColumn: 'room',
+ stateColumn: 'state',
+ storeTimeout: 2000,
+ }}
+/>
+```
+
+### Without awareness
+
+By default, cursor and selection positions are shared between collaborators. To disable this:
+
+```tsx
+<RealtimeMonaco channel="realtime-monaco-demo" awareness={false} />
+```
+
+## Props
+
+| Prop | Type | Description |
+| -------------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
+| `channel` | `string` | Unique channel name used to sync editor content between collaborators in the same session. |
+| `language?` | `string` | Monaco [language identifier](https://code.visualstudio.com/docs/languages/identifiers) (e.g. `typescript`, `python`). Defaults to `javascript`. |
+| `height?` | `string \| number` | Height of the editor container. Accepts a pixel number or CSS string (e.g. `"100%"`). Defaults to `550`. |
+| `className?` | `string` | CSS class applied to the editor wrapper element. |
+| `awareness?` | `boolean \| Awareness` | Enables cursor and selection sharing between users. Pass `false` to disable or a custom `Awareness` instance. Defaults to `true`. |
+| `persistence?` | `boolean \| SupabasePersistenceOptions` | Persists editor content to Supabase so it survives page reloads. Pass `true` for defaults or an options object for fine-grained control. |
+| `theme?` | `'light' \| 'dark'` | Color theme for the editor. Maps to Monaco's `light` and `vs-dark` themes. |
+
+### SupabasePersistenceOptions
+
+| Option | Type | Default | Description |
+| -------------- | -------- | ----------------- | --------------------------------------------------- |
+| `table` | `string` | `'yjs_documents'` | Name of the Postgres table used to store documents. |
+| `schema` | `string` | `'public'` | Schema where the table is located. |
+| `roomColumn` | `string` | `'room'` | Column used as the document identifier. |
+| `stateColumn` | `string` | `'state'` | Column used to store the binary Yjs state. |
+| `storeTimeout` | `number` | `1000` | Debounce delay (ms) before persisting changes. |
+
+## Further reading
+
+- [Realtime Broadcast](https://supabase.com/docs/guides/realtime/broadcast)
+- [Realtime authorization](https://supabase.com/docs/guides/realtime/authorization)
+- [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase)
+- [Yjs documentation](https://docs.yjs.dev/)
diff --git a/apps/ui-library/content/docs/tanstack/realtime-monaco.mdx b/apps/ui-library/content/docs/tanstack/realtime-monaco.mdx
new file mode 100644
index 00000000000..cd29727b136
--- /dev/null
+++ b/apps/ui-library/content/docs/tanstack/realtime-monaco.mdx
@@ -0,0 +1,124 @@
+---
+title: Realtime Monaco
+description: Real-time Monaco editor for collaborative applications
+---
+
+<DualRealtimeMonaco />
+
+## Installation
+
+<BlockItem
+ name="realtime-monaco-tanstack"
+ description="Real-time Monaco editor for collaborative applications."
+/>
+
+## Folder structure
+
+<RegistryBlock itemName="realtime-monaco-tanstack" />
+
+## Introduction
+
+The Realtime Monaco component provides a collaborative code editor powered by [Monaco](https://microsoft.github.io/monaco-editor/) and [Yjs](https://yjs.dev/). It uses [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase) under the hood to sync document state across clients through Supabase Realtime.
+
+**Features**
+
+- Real-time document synchronization via Supabase Realtime broadcast
+- Cursor and selection sharing between collaborators (awareness)
+- Optional persistence to Postgres so documents survive page reloads
+- Supports all Monaco languages and themes
+- Room-based isolation for scoped collaboration
+
+## How it works under the hood
+
+The component creates a [Yjs](https://yjs.dev/) document and connects it to a Supabase Realtime channel using `SupabaseProvider` from `@supabase-labs/y-supabase`. A `MonacoBinding` from `y-monaco` bridges the Yjs document with the Monaco editor model, keeping them in sync.
+
+When **awareness** is enabled, each user's cursor position and selection are broadcast to other clients in the same channel. Remote cursors are rendered with unique colors via dynamically injected CSS.
+
+When **persistence** is enabled, the full Yjs document state is saved to a Postgres table so it can be restored when clients reconnect.
+
+## Usage
+
+### Basic usage
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" />
+}
+```
+
+### With persistence
+
+Enable persistence to save the editor content to your Supabase database. This requires a table to store the Yjs document state.
+
+First, create the required table in your Supabase project:
+
+```sql
+create table yjs_documents (
+ room text primary key,
+ state text not null
+);
+```
+
+Then pass `persistence` to the component:
+
+```tsx
+import { RealtimeMonaco } from '@/components/realtime-monaco'
+
+export default function MonacoPage() {
+ return <RealtimeMonaco channel="realtime-monaco-demo" language="typescript" persistence />
+}
+```
+
+You can also pass a `SupabasePersistenceOptions` object:
+
+```tsx
+<RealtimeMonaco
+ channel="realtime-monaco-demo"
+ language="typescript"
+ persistence={{
+ table: 'yjs_documents',
+ roomColumn: 'room',
+ stateColumn: 'state',
+ storeTimeout: 2000,
+ }}
+/>
+```
+
+### Without awareness
+
+By default, cursor and selection positions are shared between collaborators. To disable this:
+
+```tsx
+<RealtimeMonaco channel="realtime-monaco-demo" awareness={false} />
+```
+
+## Props
+
+| Prop | Type | Description |
+| -------------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
+| `channel` | `string` | Unique channel name used to sync editor content between collaborators in the same session. |
+| `language?` | `string` | Monaco [language identifier](https://code.visualstudio.com/docs/languages/identifiers) (e.g. `typescript`, `python`). Defaults to `javascript`. |
+| `height?` | `string \| number` | Height of the editor container. Accepts a pixel number or CSS string (e.g. `"100%"`). Defaults to `550`. |
+| `className?` | `string` | CSS class applied to the editor wrapper element. |
+| `awareness?` | `boolean \| Awareness` | Enables cursor and selection sharing between users. Pass `false` to disable or a custom `Awareness` instance. Defaults to `true`. |
+| `persistence?` | `boolean \| SupabasePersistenceOptions` | Persists editor content to Supabase so it survives page reloads. Pass `true` for defaults or an options object for fine-grained control. |
+| `theme?` | `'light' \| 'dark'` | Color theme for the editor. Maps to Monaco's `light` and `vs-dark` themes. |
+
+### SupabasePersistenceOptions
+
+| Option | Type | Default | Description |
+| -------------- | -------- | ----------------- | --------------------------------------------------- |
+| `table` | `string` | `'yjs_documents'` | Name of the Postgres table used to store documents. |
+| `schema` | `string` | `'public'` | Schema where the table is located. |
+| `roomColumn` | `string` | `'room'` | Column used as the document identifier. |
+| `stateColumn` | `string` | `'state'` | Column used to store the binary Yjs state. |
+| `storeTimeout` | `number` | `1000` | Debounce delay (ms) before persisting changes. |
+
+## Further reading
+
+- [Realtime Broadcast](https://supabase.com/docs/guides/realtime/broadcast)
+- [Realtime authorization](https://supabase.com/docs/guides/realtime/authorization)
+- [`@supabase-labs/y-supabase`](https://github.com/supabase-community/y-supabase)
+- [Yjs documentation](https://docs.yjs.dev/)
diff --git a/apps/ui-library/package.json b/apps/ui-library/package.json
index 544f1a5fd3f..9820ec83582 100644
--- a/apps/ui-library/package.json
+++ b/apps/ui-library/package.json
@@ -47,11 +47,12 @@
"@radix-ui/react-toggle-group": "*",
"@radix-ui/react-tooltip": "*",
"@react-router/fs-routes": "^7.4.0",
+ "@supabase-labs/y-supabase": "0.1.0",
"@supabase/postgrest-js": "catalog:",
"@supabase/supa-mdx-lint": "0.2.6-alpha",
+ "@supabase/vue-blocks": "workspace:*",
"@tanstack/react-query": "^5.83.0",
"api-types": "workspace:*",
- "@supabase/vue-blocks": "workspace:*",
"axios": "^1.12.0",
"class-variance-authority": "*",
"cmdk": "^1.0.0",
@@ -63,6 +64,7 @@
"icons": "workspace:*",
"jotai": "^2.8.0",
"lucide-react": "*",
+ "monaco-editor": "^0.55.1",
"next": "catalog:",
"next-contentlayer2": "0.4.6",
"next-themes": "^0.3.0",
@@ -85,9 +87,13 @@
"ui-patterns": "workspace:*",
"unist-util-visit": "^5.0.0",
"vaul": "^0.9.6",
+ "y-monaco": "^0.1.6",
+ "y-protocols": "^1.0.7",
+ "yjs": "^13.6.29",
"zod": "catalog:"
},
"devDependencies": {
+ "@babel/core": "*",
"@react-router/dev": "^7.9.0",
"@shikijs/compat": "^1.1.7",
"@supabase/ssr": "^0.7.0",
diff --git a/apps/ui-library/public/llms.txt b/apps/ui-library/public/llms.txt
index 1b76808e7e7..2e039c7f2b3 100644
--- a/apps/ui-library/public/llms.txt
+++ b/apps/ui-library/public/llms.txt
@@ -29,6 +29,8 @@ Library of components for your project. The components integrate with Supabase a
- Real-time chat component for collaborative applications
- [Realtime Cursor](https://supabase.com/ui/docs/nextjs/realtime-cursor)
- Real-time cursor sharing for collaborative applications
+- [Realtime Monaco](https://supabase.com/ui/docs/nextjs/realtime-monaco)
+ - Real-time Monaco editor for collaborative applications
- [Social Authentication](https://supabase.com/ui/docs/nextjs/social-auth)
- Social authentication block for Next.js
- [Supabase Client Libraries](https://supabase.com/ui/docs/nuxtjs/client)
@@ -61,6 +63,8 @@ Library of components for your project. The components integrate with Supabase a
- Real-time chat component for collaborative applications
- [Realtime Cursor](https://supabase.com/ui/docs/react-router/realtime-cursor)
- Real-time cursor sharing for collaborative applications
+- [Realtime Monaco](https://supabase.com/ui/docs/react-router/realtime-monaco)
+ - Real-time Monaco editor for collaborative applications
- [Social Authentication](https://supabase.com/ui/docs/react-router/social-auth)
- Social authentication block for React Router
- [Supabase Client Libraries](https://supabase.com/ui/docs/react/client)
@@ -77,6 +81,8 @@ Library of components for your project. The components integrate with Supabase a
- Real-time chat component for collaborative applications
- [Realtime Cursor](https://supabase.com/ui/docs/react/realtime-cursor)
- Real-time cursor sharing for collaborative applications
+- [Realtime Monaco](https://supabase.com/ui/docs/react/realtime-monaco)
+ - Real-time Monaco editor for collaborative applications
- [Social Authentication](https://supabase.com/ui/docs/react/social-auth)
- Social authentication block for React Single Page Applications
- [Supabase Client Libraries](https://supabase.com/ui/docs/tanstack/client)
@@ -93,6 +99,8 @@ Library of components for your project. The components integrate with Supabase a
- Real-time chat component for collaborative applications
- [Realtime Cursor](https://supabase.com/ui/docs/tanstack/realtime-cursor)
- Real-time cursor sharing for collaborative applications
+- [Realtime Monaco](https://supabase.com/ui/docs/tanstack/realtime-monaco)
+ - Real-time Monaco editor for collaborative applications
- [Social Authentication](https://supabase.com/ui/docs/tanstack/social-auth)
- Social authentication block for Tanstack Start
- [Supabase Client Libraries](https://supabase.com/ui/docs/vue/client)
diff --git a/apps/ui-library/public/r/realtime-monaco-nextjs.json b/apps/ui-library/public/r/realtime-monaco-nextjs.json
new file mode 100644
index 00000000000..cf141d4690b
--- /dev/null
+++ b/apps/ui-library/public/r/realtime-monaco-nextjs.json
@@ -0,0 +1,47 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-nextjs",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/ssr@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "registryDependencies": [],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "content": "'use client'\n\nimport { SupabasePersistenceOptions, SupabaseProvider } from '@supabase-labs/y-supabase'\nimport type { editor as MonacoEditor } from 'monaco-editor'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { MonacoBinding } from 'y-monaco'\nimport { Awareness } from 'y-protocols/awareness'\nimport * as Y from 'yjs'\n\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\n\ntype UseConnectOnMountOptions = {\n channel: string\n persistence?: boolean | SupabasePersistenceOptions\n awareness?: boolean | Awareness\n}\n\nconst generateRandomColor = () => `hsl(${Math.floor(Math.random() * 360)}, 80%, 60%)`\n\nexport function useConnectOnMount({\n channel,\n persistence,\n awareness = true,\n}: UseConnectOnMountOptions) {\n const docRef = useRef<Y.Doc | null>(null)\n const providerRef = useRef<SupabaseProvider | null>(null)\n const bindingRef = useRef<MonacoBinding | null>(null)\n const userRef = useRef<{ color: string } | null>(null)\n const styleRef = useRef<HTMLStyleElement | null>(null)\n const awarenessHandlerRef = useRef<(() => void) | null>(null)\n\n const connectOnMount = useCallback(\n (editor: MonacoEditor.IStandaloneCodeEditor) => {\n if (bindingRef.current) return\n\n const model = editor.getModel()\n if (!model) return\n\n const doc = new Y.Doc()\n const yText = doc.getText('monaco')\n const supabase = createClient()\n const provider = new SupabaseProvider(channel, doc, supabase as any, {\n awareness,\n persistence,\n })\n const providerAwareness = provider.getAwareness()\n\n if (providerAwareness) {\n if (!userRef.current) {\n userRef.current = {\n color: generateRandomColor(),\n }\n }\n providerAwareness.setLocalStateField('user', userRef.current)\n\n const applyAwarenessStyles = () => {\n if (!styleRef.current) {\n styleRef.current = document.createElement('style')\n styleRef.current.setAttribute('data-monaco-y-cursors', 'true')\n document.head.appendChild(styleRef.current)\n }\n\n let css = `\n .yRemoteSelection {\n background-color: var(--y-remote-selection-color, rgba(0, 0, 0, 0.2));\n opacity: 0.2;\n }\n .yRemoteSelectionHead {\n border-left: 2px solid var(--y-remote-selection-color, rgba(0, 0, 0, 0.7));\n margin-left: -1px;\n box-sizing: border-box;\n }\n `\n\n providerAwareness.getStates().forEach((state, clientId) => {\n const color = state?.user?.color\n const isValidHsl = /^hsl\\(\\d{1,3},\\s*\\d{1,3}%,\\s*\\d{1,3}%\\)$/.test(color)\n\n if (!isValidHsl) return\n if (!color) return\n\n css += `\n .yRemoteSelection-${clientId}, .yRemoteSelectionHead-${clientId} {\n --y-remote-selection-color: ${color};\n }\n `\n })\n\n styleRef.current.textContent = css\n }\n\n awarenessHandlerRef.current = applyAwarenessStyles\n applyAwarenessStyles()\n providerAwareness.on('update', applyAwarenessStyles)\n }\n\n docRef.current = doc\n providerRef.current = provider\n bindingRef.current = new MonacoBinding(yText, model, new Set([editor]), providerAwareness)\n },\n [channel]\n )\n\n useEffect(() => {\n return () => {\n if (awarenessHandlerRef.current && providerRef.current) {\n const awareness = providerRef.current.getAwareness()\n awareness?.off('update', awarenessHandlerRef.current)\n }\n styleRef.current?.remove()\n bindingRef.current?.destroy()\n bindingRef.current = null\n providerRef.current?.destroy()\n providerRef.current = null\n docRef.current?.destroy()\n docRef.current = null\n }\n }, [])\n\n return { connectOnMount }\n}\n",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "content": "'use client'\n\nimport { Editor } from '@monaco-editor/react'\nimport { SupabasePersistenceOptions } from '@supabase-labs/y-supabase'\nimport { Awareness } from 'y-protocols/awareness.js'\n\nimport { useConnectOnMount } from '../hooks/use-connect-on-mount'\n\ntype RealtimeMonacoProps = {\n channel: string\n language?: string\n height?: string | number\n className?: string\n awareness?: boolean | Awareness\n persistence?: boolean | SupabasePersistenceOptions\n theme?: 'light' | 'dark'\n}\n\nconst DEFAULT_HEIGHT = 550\n\nconst RealtimeMonaco = ({\n channel,\n language = 'javascript',\n height = DEFAULT_HEIGHT,\n awareness = true,\n persistence,\n theme,\n ...rest\n}: RealtimeMonacoProps) => {\n const { connectOnMount } = useConnectOnMount({ channel, persistence, awareness })\n\n return (\n <Editor\n height={height}\n language={language}\n theme={theme === 'dark' ? 'vs-dark' : 'light'}\n onMount={connectOnMount}\n {...rest}\n />\n )\n}\n\nexport { RealtimeMonaco }\n",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/nextjs/lib/supabase/client.ts",
+ "content": "import { createBrowserClient } from '@supabase/ssr'\n\nexport function createClient() {\n return createBrowserClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",
+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { NextResponse, type NextRequest } from 'next/server'\n\nexport async function updateSession(request: NextRequest) {\n let supabaseResponse = NextResponse.next({\n request,\n })\n\n // With Fluid compute, don't put this client in a global environment\n // variable. Always create a new one on each request.\n const supabase = createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return request.cookies.getAll()\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value }) => request.cookies.set(name, value))\n supabaseResponse = NextResponse.next({\n request,\n })\n cookiesToSet.forEach(({ name, value, options }) =>\n supabaseResponse.cookies.set(name, value, options)\n )\n },\n },\n }\n )\n\n // Do not run code between createServerClient and\n // supabase.auth.getClaims(). A simple mistake could make it very hard to debug\n // issues with users being randomly logged out.\n\n // IMPORTANT: If you remove getClaims() and you use server-side rendering\n // with the Supabase client, your users may be randomly logged out.\n const { data } = await supabase.auth.getClaims()\n const user = data?.claims\n\n if (\n !user &&\n !request.nextUrl.pathname.startsWith('/login') &&\n !request.nextUrl.pathname.startsWith('/auth')\n ) {\n // no user, potentially respond by redirecting the user to the login page\n const url = request.nextUrl.clone()\n url.pathname = '/auth/login'\n return NextResponse.redirect(url)\n }\n\n // IMPORTANT: You *must* return the supabaseResponse object as it is.\n // If you're creating a new response object with NextResponse.next() make sure to:\n // 1. Pass the request in it, like so:\n // const myNewResponse = NextResponse.next({ request })\n // 2. Copy over the cookies, like so:\n // myNewResponse.cookies.setAll(supabaseResponse.cookies.getAll())\n // 3. Change the myNewResponse object to fit your needs, but avoid changing\n // the cookies!\n // 4. Finally:\n // return myNewResponse\n // If this is not done, you may be causing the browser and server to go out\n // of sync and terminate the user's session prematurely!\n\n return supabaseResponse\n}\n",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/nextjs/lib/supabase/server.ts",
+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { cookies } from 'next/headers'\n\n/**\n * If using Fluid compute: Don't put this client in a global variable. Always create a new client within each\n * function when using it.\n */\nexport async function createClient() {\n const cookieStore = await cookies()\n\n return createServerClient(\n process.env.NEXT_PUBLIC_SUPABASE_URL!,\n process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return cookieStore.getAll()\n },\n setAll(cookiesToSet) {\n try {\n cookiesToSet.forEach(({ name, value, options }) =>\n cookieStore.set(name, value, options)\n )\n } catch {\n // The `setAll` method was called from a Server Component.\n // This can be ignored if you have middleware refreshing\n // user sessions.\n }\n },\n },\n }\n )\n}\n",
+ "type": "registry:lib"
+ }
+ ],
+ "envVars": {
+ "NEXT_PUBLIC_SUPABASE_URL": "",
+ "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY": ""
+ },
+ "docs": "You'll need to set the following environment variables in your project: `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`."
+}
\ No newline at end of file
diff --git a/apps/ui-library/public/r/realtime-monaco-react-router.json b/apps/ui-library/public/r/realtime-monaco-react-router.json
new file mode 100644
index 00000000000..55eee0edccc
--- /dev/null
+++ b/apps/ui-library/public/r/realtime-monaco-react-router.json
@@ -0,0 +1,42 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-react-router",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/ssr@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "registryDependencies": [],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "content": "'use client'\n\nimport { SupabasePersistenceOptions, SupabaseProvider } from '@supabase-labs/y-supabase'\nimport type { editor as MonacoEditor } from 'monaco-editor'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { MonacoBinding } from 'y-monaco'\nimport { Awareness } from 'y-protocols/awareness'\nimport * as Y from 'yjs'\n\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\n\ntype UseConnectOnMountOptions = {\n channel: string\n persistence?: boolean | SupabasePersistenceOptions\n awareness?: boolean | Awareness\n}\n\nconst generateRandomColor = () => `hsl(${Math.floor(Math.random() * 360)}, 80%, 60%)`\n\nexport function useConnectOnMount({\n channel,\n persistence,\n awareness = true,\n}: UseConnectOnMountOptions) {\n const docRef = useRef<Y.Doc | null>(null)\n const providerRef = useRef<SupabaseProvider | null>(null)\n const bindingRef = useRef<MonacoBinding | null>(null)\n const userRef = useRef<{ color: string } | null>(null)\n const styleRef = useRef<HTMLStyleElement | null>(null)\n const awarenessHandlerRef = useRef<(() => void) | null>(null)\n\n const connectOnMount = useCallback(\n (editor: MonacoEditor.IStandaloneCodeEditor) => {\n if (bindingRef.current) return\n\n const model = editor.getModel()\n if (!model) return\n\n const doc = new Y.Doc()\n const yText = doc.getText('monaco')\n const supabase = createClient()\n const provider = new SupabaseProvider(channel, doc, supabase as any, {\n awareness,\n persistence,\n })\n const providerAwareness = provider.getAwareness()\n\n if (providerAwareness) {\n if (!userRef.current) {\n userRef.current = {\n color: generateRandomColor(),\n }\n }\n providerAwareness.setLocalStateField('user', userRef.current)\n\n const applyAwarenessStyles = () => {\n if (!styleRef.current) {\n styleRef.current = document.createElement('style')\n styleRef.current.setAttribute('data-monaco-y-cursors', 'true')\n document.head.appendChild(styleRef.current)\n }\n\n let css = `\n .yRemoteSelection {\n background-color: var(--y-remote-selection-color, rgba(0, 0, 0, 0.2));\n opacity: 0.2;\n }\n .yRemoteSelectionHead {\n border-left: 2px solid var(--y-remote-selection-color, rgba(0, 0, 0, 0.7));\n margin-left: -1px;\n box-sizing: border-box;\n }\n `\n\n providerAwareness.getStates().forEach((state, clientId) => {\n const color = state?.user?.color\n const isValidHsl = /^hsl\\(\\d{1,3},\\s*\\d{1,3}%,\\s*\\d{1,3}%\\)$/.test(color)\n\n if (!isValidHsl) return\n if (!color) return\n\n css += `\n .yRemoteSelection-${clientId}, .yRemoteSelectionHead-${clientId} {\n --y-remote-selection-color: ${color};\n }\n `\n })\n\n styleRef.current.textContent = css\n }\n\n awarenessHandlerRef.current = applyAwarenessStyles\n applyAwarenessStyles()\n providerAwareness.on('update', applyAwarenessStyles)\n }\n\n docRef.current = doc\n providerRef.current = provider\n bindingRef.current = new MonacoBinding(yText, model, new Set([editor]), providerAwareness)\n },\n [channel]\n )\n\n useEffect(() => {\n return () => {\n if (awarenessHandlerRef.current && providerRef.current) {\n const awareness = providerRef.current.getAwareness()\n awareness?.off('update', awarenessHandlerRef.current)\n }\n styleRef.current?.remove()\n bindingRef.current?.destroy()\n bindingRef.current = null\n providerRef.current?.destroy()\n providerRef.current = null\n docRef.current?.destroy()\n docRef.current = null\n }\n }, [])\n\n return { connectOnMount }\n}\n",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "content": "'use client'\n\nimport { Editor } from '@monaco-editor/react'\nimport { SupabasePersistenceOptions } from '@supabase-labs/y-supabase'\nimport { Awareness } from 'y-protocols/awareness.js'\n\nimport { useConnectOnMount } from '../hooks/use-connect-on-mount'\n\ntype RealtimeMonacoProps = {\n channel: string\n language?: string\n height?: string | number\n className?: string\n awareness?: boolean | Awareness\n persistence?: boolean | SupabasePersistenceOptions\n theme?: 'light' | 'dark'\n}\n\nconst DEFAULT_HEIGHT = 550\n\nconst RealtimeMonaco = ({\n channel,\n language = 'javascript',\n height = DEFAULT_HEIGHT,\n awareness = true,\n persistence,\n theme,\n ...rest\n}: RealtimeMonacoProps) => {\n const { connectOnMount } = useConnectOnMount({ channel, persistence, awareness })\n\n return (\n <Editor\n height={height}\n language={language}\n theme={theme === 'dark' ? 'vs-dark' : 'light'}\n onMount={connectOnMount}\n {...rest}\n />\n )\n}\n\nexport { RealtimeMonaco }\n",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/react-router/lib/supabase/client.ts",
+ "content": "/// <reference types=\"vite/types/importMeta.d.ts\" />\nimport { createBrowserClient } from '@supabase/ssr'\n\nexport function createClient() {\n return createBrowserClient(\n import.meta.env.VITE_SUPABASE_URL!,\n import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/react-router/lib/supabase/server.ts",
+ "content": "import { createServerClient, parseCookieHeader, serializeCookieHeader } from '@supabase/ssr'\n\nexport function createClient(request: Request) {\n const headers = new Headers()\n\n const supabase = createServerClient(\n process.env.VITE_SUPABASE_URL!,\n process.env.VITE_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return parseCookieHeader(request.headers.get('Cookie') ?? '') as {\n name: string\n value: string\n }[]\n },\n setAll(cookiesToSet) {\n cookiesToSet.forEach(({ name, value, options }) =>\n headers.append('Set-Cookie', serializeCookieHeader(name, value, options))\n )\n },\n },\n }\n )\n\n return { supabase, headers }\n}\n",
+ "type": "registry:lib"
+ }
+ ],
+ "envVars": {
+ "VITE_SUPABASE_URL": "",
+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""
+ },
+ "docs": "You'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`."
+}
\ No newline at end of file
diff --git a/apps/ui-library/public/r/realtime-monaco-react.json b/apps/ui-library/public/r/realtime-monaco-react.json
new file mode 100644
index 00000000000..a2645c9fb21
--- /dev/null
+++ b/apps/ui-library/public/r/realtime-monaco-react.json
@@ -0,0 +1,36 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-react",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "registryDependencies": [],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "content": "'use client'\n\nimport { SupabasePersistenceOptions, SupabaseProvider } from '@supabase-labs/y-supabase'\nimport type { editor as MonacoEditor } from 'monaco-editor'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { MonacoBinding } from 'y-monaco'\nimport { Awareness } from 'y-protocols/awareness'\nimport * as Y from 'yjs'\n\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\n\ntype UseConnectOnMountOptions = {\n channel: string\n persistence?: boolean | SupabasePersistenceOptions\n awareness?: boolean | Awareness\n}\n\nconst generateRandomColor = () => `hsl(${Math.floor(Math.random() * 360)}, 80%, 60%)`\n\nexport function useConnectOnMount({\n channel,\n persistence,\n awareness = true,\n}: UseConnectOnMountOptions) {\n const docRef = useRef<Y.Doc | null>(null)\n const providerRef = useRef<SupabaseProvider | null>(null)\n const bindingRef = useRef<MonacoBinding | null>(null)\n const userRef = useRef<{ color: string } | null>(null)\n const styleRef = useRef<HTMLStyleElement | null>(null)\n const awarenessHandlerRef = useRef<(() => void) | null>(null)\n\n const connectOnMount = useCallback(\n (editor: MonacoEditor.IStandaloneCodeEditor) => {\n if (bindingRef.current) return\n\n const model = editor.getModel()\n if (!model) return\n\n const doc = new Y.Doc()\n const yText = doc.getText('monaco')\n const supabase = createClient()\n const provider = new SupabaseProvider(channel, doc, supabase as any, {\n awareness,\n persistence,\n })\n const providerAwareness = provider.getAwareness()\n\n if (providerAwareness) {\n if (!userRef.current) {\n userRef.current = {\n color: generateRandomColor(),\n }\n }\n providerAwareness.setLocalStateField('user', userRef.current)\n\n const applyAwarenessStyles = () => {\n if (!styleRef.current) {\n styleRef.current = document.createElement('style')\n styleRef.current.setAttribute('data-monaco-y-cursors', 'true')\n document.head.appendChild(styleRef.current)\n }\n\n let css = `\n .yRemoteSelection {\n background-color: var(--y-remote-selection-color, rgba(0, 0, 0, 0.2));\n opacity: 0.2;\n }\n .yRemoteSelectionHead {\n border-left: 2px solid var(--y-remote-selection-color, rgba(0, 0, 0, 0.7));\n margin-left: -1px;\n box-sizing: border-box;\n }\n `\n\n providerAwareness.getStates().forEach((state, clientId) => {\n const color = state?.user?.color\n const isValidHsl = /^hsl\\(\\d{1,3},\\s*\\d{1,3}%,\\s*\\d{1,3}%\\)$/.test(color)\n\n if (!isValidHsl) return\n if (!color) return\n\n css += `\n .yRemoteSelection-${clientId}, .yRemoteSelectionHead-${clientId} {\n --y-remote-selection-color: ${color};\n }\n `\n })\n\n styleRef.current.textContent = css\n }\n\n awarenessHandlerRef.current = applyAwarenessStyles\n applyAwarenessStyles()\n providerAwareness.on('update', applyAwarenessStyles)\n }\n\n docRef.current = doc\n providerRef.current = provider\n bindingRef.current = new MonacoBinding(yText, model, new Set([editor]), providerAwareness)\n },\n [channel]\n )\n\n useEffect(() => {\n return () => {\n if (awarenessHandlerRef.current && providerRef.current) {\n const awareness = providerRef.current.getAwareness()\n awareness?.off('update', awarenessHandlerRef.current)\n }\n styleRef.current?.remove()\n bindingRef.current?.destroy()\n bindingRef.current = null\n providerRef.current?.destroy()\n providerRef.current = null\n docRef.current?.destroy()\n docRef.current = null\n }\n }, [])\n\n return { connectOnMount }\n}\n",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "content": "'use client'\n\nimport { Editor } from '@monaco-editor/react'\nimport { SupabasePersistenceOptions } from '@supabase-labs/y-supabase'\nimport { Awareness } from 'y-protocols/awareness.js'\n\nimport { useConnectOnMount } from '../hooks/use-connect-on-mount'\n\ntype RealtimeMonacoProps = {\n channel: string\n language?: string\n height?: string | number\n className?: string\n awareness?: boolean | Awareness\n persistence?: boolean | SupabasePersistenceOptions\n theme?: 'light' | 'dark'\n}\n\nconst DEFAULT_HEIGHT = 550\n\nconst RealtimeMonaco = ({\n channel,\n language = 'javascript',\n height = DEFAULT_HEIGHT,\n awareness = true,\n persistence,\n theme,\n ...rest\n}: RealtimeMonacoProps) => {\n const { connectOnMount } = useConnectOnMount({ channel, persistence, awareness })\n\n return (\n <Editor\n height={height}\n language={language}\n theme={theme === 'dark' ? 'vs-dark' : 'light'}\n onMount={connectOnMount}\n {...rest}\n />\n )\n}\n\nexport { RealtimeMonaco }\n",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/react/lib/supabase/client.ts",
+ "content": "import { createClient as createSupabaseClient } from '@supabase/supabase-js'\n\nexport function createClient() {\n return createSupabaseClient(\n import.meta.env.VITE_SUPABASE_URL!,\n import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",
+ "type": "registry:lib"
+ }
+ ],
+ "envVars": {
+ "VITE_SUPABASE_URL": "",
+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""
+ },
+ "docs": "You'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`."
+}
\ No newline at end of file
diff --git a/apps/ui-library/public/r/realtime-monaco-tanstack.json b/apps/ui-library/public/r/realtime-monaco-tanstack.json
new file mode 100644
index 00000000000..e03695557ef
--- /dev/null
+++ b/apps/ui-library/public/r/realtime-monaco-tanstack.json
@@ -0,0 +1,42 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-tanstack",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/ssr@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "registryDependencies": [],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "content": "'use client'\n\nimport { SupabasePersistenceOptions, SupabaseProvider } from '@supabase-labs/y-supabase'\nimport type { editor as MonacoEditor } from 'monaco-editor'\nimport { useCallback, useEffect, useRef } from 'react'\nimport { MonacoBinding } from 'y-monaco'\nimport { Awareness } from 'y-protocols/awareness'\nimport * as Y from 'yjs'\n\nimport { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'\n\ntype UseConnectOnMountOptions = {\n channel: string\n persistence?: boolean | SupabasePersistenceOptions\n awareness?: boolean | Awareness\n}\n\nconst generateRandomColor = () => `hsl(${Math.floor(Math.random() * 360)}, 80%, 60%)`\n\nexport function useConnectOnMount({\n channel,\n persistence,\n awareness = true,\n}: UseConnectOnMountOptions) {\n const docRef = useRef<Y.Doc | null>(null)\n const providerRef = useRef<SupabaseProvider | null>(null)\n const bindingRef = useRef<MonacoBinding | null>(null)\n const userRef = useRef<{ color: string } | null>(null)\n const styleRef = useRef<HTMLStyleElement | null>(null)\n const awarenessHandlerRef = useRef<(() => void) | null>(null)\n\n const connectOnMount = useCallback(\n (editor: MonacoEditor.IStandaloneCodeEditor) => {\n if (bindingRef.current) return\n\n const model = editor.getModel()\n if (!model) return\n\n const doc = new Y.Doc()\n const yText = doc.getText('monaco')\n const supabase = createClient()\n const provider = new SupabaseProvider(channel, doc, supabase as any, {\n awareness,\n persistence,\n })\n const providerAwareness = provider.getAwareness()\n\n if (providerAwareness) {\n if (!userRef.current) {\n userRef.current = {\n color: generateRandomColor(),\n }\n }\n providerAwareness.setLocalStateField('user', userRef.current)\n\n const applyAwarenessStyles = () => {\n if (!styleRef.current) {\n styleRef.current = document.createElement('style')\n styleRef.current.setAttribute('data-monaco-y-cursors', 'true')\n document.head.appendChild(styleRef.current)\n }\n\n let css = `\n .yRemoteSelection {\n background-color: var(--y-remote-selection-color, rgba(0, 0, 0, 0.2));\n opacity: 0.2;\n }\n .yRemoteSelectionHead {\n border-left: 2px solid var(--y-remote-selection-color, rgba(0, 0, 0, 0.7));\n margin-left: -1px;\n box-sizing: border-box;\n }\n `\n\n providerAwareness.getStates().forEach((state, clientId) => {\n const color = state?.user?.color\n const isValidHsl = /^hsl\\(\\d{1,3},\\s*\\d{1,3}%,\\s*\\d{1,3}%\\)$/.test(color)\n\n if (!isValidHsl) return\n if (!color) return\n\n css += `\n .yRemoteSelection-${clientId}, .yRemoteSelectionHead-${clientId} {\n --y-remote-selection-color: ${color};\n }\n `\n })\n\n styleRef.current.textContent = css\n }\n\n awarenessHandlerRef.current = applyAwarenessStyles\n applyAwarenessStyles()\n providerAwareness.on('update', applyAwarenessStyles)\n }\n\n docRef.current = doc\n providerRef.current = provider\n bindingRef.current = new MonacoBinding(yText, model, new Set([editor]), providerAwareness)\n },\n [channel]\n )\n\n useEffect(() => {\n return () => {\n if (awarenessHandlerRef.current && providerRef.current) {\n const awareness = providerRef.current.getAwareness()\n awareness?.off('update', awarenessHandlerRef.current)\n }\n styleRef.current?.remove()\n bindingRef.current?.destroy()\n bindingRef.current = null\n providerRef.current?.destroy()\n providerRef.current = null\n docRef.current?.destroy()\n docRef.current = null\n }\n }, [])\n\n return { connectOnMount }\n}\n",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "content": "'use client'\n\nimport { Editor } from '@monaco-editor/react'\nimport { SupabasePersistenceOptions } from '@supabase-labs/y-supabase'\nimport { Awareness } from 'y-protocols/awareness.js'\n\nimport { useConnectOnMount } from '../hooks/use-connect-on-mount'\n\ntype RealtimeMonacoProps = {\n channel: string\n language?: string\n height?: string | number\n className?: string\n awareness?: boolean | Awareness\n persistence?: boolean | SupabasePersistenceOptions\n theme?: 'light' | 'dark'\n}\n\nconst DEFAULT_HEIGHT = 550\n\nconst RealtimeMonaco = ({\n channel,\n language = 'javascript',\n height = DEFAULT_HEIGHT,\n awareness = true,\n persistence,\n theme,\n ...rest\n}: RealtimeMonacoProps) => {\n const { connectOnMount } = useConnectOnMount({ channel, persistence, awareness })\n\n return (\n <Editor\n height={height}\n language={language}\n theme={theme === 'dark' ? 'vs-dark' : 'light'}\n onMount={connectOnMount}\n {...rest}\n />\n )\n}\n\nexport { RealtimeMonaco }\n",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/tanstack/lib/supabase/client.ts",
+ "content": "/// <reference types=\"vite/types/importMeta.d.ts\" />\nimport { createBrowserClient } from '@supabase/ssr'\n\nexport function createClient() {\n return createBrowserClient(\n import.meta.env.VITE_SUPABASE_URL!,\n import.meta.env.VITE_SUPABASE_PUBLISHABLE_KEY!\n )\n}\n",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/tanstack/lib/supabase/server.ts",
+ "content": "import { createServerClient } from '@supabase/ssr'\nimport { getCookies, setCookie } from '@tanstack/react-start/server'\n\nexport function createClient() {\n return createServerClient(\n process.env.VITE_SUPABASE_URL!,\n process.env.VITE_SUPABASE_PUBLISHABLE_KEY!,\n {\n cookies: {\n getAll() {\n return Object.entries(getCookies()).map(\n ([name, value]) =>\n ({\n name,\n value,\n }) as { name: string; value: string }\n )\n },\n setAll(cookies) {\n cookies.forEach((cookie) => {\n setCookie(cookie.name, cookie.value)\n })\n },\n },\n }\n )\n}\n",
+ "type": "registry:lib"
+ }
+ ],
+ "envVars": {
+ "VITE_SUPABASE_URL": "",
+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""
+ },
+ "docs": "You'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`."
+}
\ No newline at end of file
diff --git a/apps/ui-library/public/r/registry.json b/apps/ui-library/public/r/registry.json
index bb2b4b399e3..f9168973a6d 100644
--- a/apps/ui-library/public/r/registry.json
+++ b/apps/ui-library/public/r/registry.json
@@ -1399,6 +1399,157 @@
"VITE_SUPABASE_PUBLISHABLE_KEY": ""
}
},
+ {
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-nextjs",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "registryDependencies": [],
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/ssr@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/nextjs/lib/supabase/client.ts",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/nextjs/lib/supabase/middleware.ts",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/nextjs/lib/supabase/server.ts",
+ "type": "registry:lib"
+ }
+ ],
+ "docs": "You'll need to set the following environment variables in your project: `NEXT_PUBLIC_SUPABASE_URL` and `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`.",
+ "envVars": {
+ "NEXT_PUBLIC_SUPABASE_URL": "",
+ "NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY": ""
+ }
+ },
+ {
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-react",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "registryDependencies": [],
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/react/lib/supabase/client.ts",
+ "type": "registry:lib"
+ }
+ ],
+ "docs": "You'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`.",
+ "envVars": {
+ "VITE_SUPABASE_URL": "",
+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""
+ }
+ },
+ {
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-react-router",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "registryDependencies": [],
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/ssr@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/react-router/lib/supabase/client.ts",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/react-router/lib/supabase/server.ts",
+ "type": "registry:lib"
+ }
+ ],
+ "docs": "You'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`.",
+ "envVars": {
+ "VITE_SUPABASE_URL": "",
+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""
+ }
+ },
+ {
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco-tanstack",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "registryDependencies": [],
+ "dependencies": [
+ "@monaco-editor/react@latest",
+ "y-monaco@latest",
+ "yjs@latest",
+ "@supabase/ssr@latest",
+ "@supabase/supabase-js@latest"
+ ],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "type": "registry:component"
+ },
+ {
+ "path": "registry/default/clients/tanstack/lib/supabase/client.ts",
+ "type": "registry:lib"
+ },
+ {
+ "path": "registry/default/clients/tanstack/lib/supabase/server.ts",
+ "type": "registry:lib"
+ }
+ ],
+ "docs": "You'll need to set the following environment variables in your project: `VITE_SUPABASE_URL` and `VITE_SUPABASE_PUBLISHABLE_KEY`.",
+ "envVars": {
+ "VITE_SUPABASE_URL": "",
+ "VITE_SUPABASE_PUBLISHABLE_KEY": ""
+ }
+ },
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "infinite-query-hook",
diff --git a/apps/ui-library/registry/blocks.ts b/apps/ui-library/registry/blocks.ts
index d54c7bcd59e..513875a7f5c 100644
--- a/apps/ui-library/registry/blocks.ts
+++ b/apps/ui-library/registry/blocks.ts
@@ -11,6 +11,7 @@ import passwordBasedAuthTanstack from './default/blocks/password-based-auth-tans
import realtimeAvatarStack from './default/blocks/realtime-avatar-stack/registry-item.json' with { type: 'json' }
import realtimeChat from './default/blocks/realtime-chat/registry-item.json' with { type: 'json' }
import realtimeCursor from './default/blocks/realtime-cursor/registry-item.json' with { type: 'json' }
+import realtimeMonaco from './default/blocks/realtime-monaco/registry-item.json' with { type: 'json' }
import socialAuthNextjs from './default/blocks/social-auth-nextjs/registry-item.json' with { type: 'json' }
import socialAuthReactRouter from './default/blocks/social-auth-react-router/registry-item.json' with { type: 'json' }
import socialAuthReact from './default/blocks/social-auth-react/registry-item.json' with { type: 'json' }
@@ -51,6 +52,7 @@ export const blocks = [
...combine(currentUserAvatar as RegistryItem),
...combine(realtimeAvatarStack as RegistryItem),
...combine(realtimeChat as RegistryItem),
+ ...combine(realtimeMonaco as RegistryItem),
// infinite query hook is intentionally not combined with the clients since it depends on clients having database types.
infiniteQueryHook as RegistryItem,
diff --git a/apps/ui-library/registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx b/apps/ui-library/registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx
new file mode 100644
index 00000000000..e90b00d4306
--- /dev/null
+++ b/apps/ui-library/registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx
@@ -0,0 +1,43 @@
+'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 }
diff --git a/apps/ui-library/registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts b/apps/ui-library/registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts
new file mode 100644
index 00000000000..4ebd629a301
--- /dev/null
+++ b/apps/ui-library/registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts
@@ -0,0 +1,121 @@
+'use client'
+
+import { SupabasePersistenceOptions, SupabaseProvider } from '@supabase-labs/y-supabase'
+import type { editor as MonacoEditor } from 'monaco-editor'
+import { useCallback, useEffect, useRef } from 'react'
+import { MonacoBinding } from 'y-monaco'
+import { Awareness } from 'y-protocols/awareness'
+import * as Y from 'yjs'
+
+import { createClient } from '@/registry/default/clients/nextjs/lib/supabase/client'
+
+type UseConnectOnMountOptions = {
+ channel: string
+ persistence?: boolean | SupabasePersistenceOptions
+ awareness?: boolean | Awareness
+}
+
+const generateRandomColor = () => `hsl(${Math.floor(Math.random() * 360)}, 80%, 60%)`
+
+export function useConnectOnMount({
+ channel,
+ persistence,
+ awareness = true,
+}: UseConnectOnMountOptions) {
+ const docRef = useRef<Y.Doc | null>(null)
+ const providerRef = useRef<SupabaseProvider | null>(null)
+ const bindingRef = useRef<MonacoBinding | null>(null)
+ const userRef = useRef<{ color: string } | null>(null)
+ const styleRef = useRef<HTMLStyleElement | null>(null)
+ const awarenessHandlerRef = useRef<(() => void) | null>(null)
+
+ const connectOnMount = useCallback(
+ (editor: MonacoEditor.IStandaloneCodeEditor) => {
+ if (bindingRef.current) return
+
+ const model = editor.getModel()
+ if (!model) return
+
+ const doc = new Y.Doc()
+ const yText = doc.getText('monaco')
+ const supabase = createClient()
+ const provider = new SupabaseProvider(channel, doc, supabase as any, {
+ awareness,
+ persistence,
+ })
+ const providerAwareness = provider.getAwareness()
+
+ if (providerAwareness) {
+ if (!userRef.current) {
+ userRef.current = {
+ color: generateRandomColor(),
+ }
+ }
+ providerAwareness.setLocalStateField('user', userRef.current)
+
+ const applyAwarenessStyles = () => {
+ if (!styleRef.current) {
+ styleRef.current = document.createElement('style')
+ styleRef.current.setAttribute('data-monaco-y-cursors', 'true')
+ document.head.appendChild(styleRef.current)
+ }
+
+ let css = `
+ .yRemoteSelection {
+ background-color: var(--y-remote-selection-color, rgba(0, 0, 0, 0.2));
+ opacity: 0.2;
+ }
+ .yRemoteSelectionHead {
+ border-left: 2px solid var(--y-remote-selection-color, rgba(0, 0, 0, 0.7));
+ margin-left: -1px;
+ box-sizing: border-box;
+ }
+ `
+
+ providerAwareness.getStates().forEach((state, clientId) => {
+ const color = state?.user?.color
+ const isValidHsl = /^hsl\(\d{1,3},\s*\d{1,3}%,\s*\d{1,3}%\)$/.test(color)
+
+ if (!isValidHsl) return
+ if (!color) return
+
+ css += `
+ .yRemoteSelection-${clientId}, .yRemoteSelectionHead-${clientId} {
+ --y-remote-selection-color: ${color};
+ }
+ `
+ })
+
+ styleRef.current.textContent = css
+ }
+
+ awarenessHandlerRef.current = applyAwarenessStyles
+ applyAwarenessStyles()
+ providerAwareness.on('update', applyAwarenessStyles)
+ }
+
+ docRef.current = doc
+ providerRef.current = provider
+ bindingRef.current = new MonacoBinding(yText, model, new Set([editor]), providerAwareness)
+ },
+ [channel]
+ )
+
+ useEffect(() => {
+ return () => {
+ if (awarenessHandlerRef.current && providerRef.current) {
+ const awareness = providerRef.current.getAwareness()
+ awareness?.off('update', awarenessHandlerRef.current)
+ }
+ styleRef.current?.remove()
+ bindingRef.current?.destroy()
+ bindingRef.current = null
+ providerRef.current?.destroy()
+ providerRef.current = null
+ docRef.current?.destroy()
+ docRef.current = null
+ }
+ }, [])
+
+ return { connectOnMount }
+}
diff --git a/apps/ui-library/registry/default/blocks/realtime-monaco/registry-item.json b/apps/ui-library/registry/default/blocks/realtime-monaco/registry-item.json
new file mode 100644
index 00000000000..f36e4769d7a
--- /dev/null
+++ b/apps/ui-library/registry/default/blocks/realtime-monaco/registry-item.json
@@ -0,0 +1,19 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "realtime-monaco",
+ "type": "registry:component",
+ "title": "Realtime Monaco",
+ "description": "Real-time Monaco editor for collaborative applications.",
+ "registryDependencies": [],
+ "dependencies": ["@monaco-editor/react@latest", "y-monaco@latest", "yjs@latest"],
+ "files": [
+ {
+ "path": "registry/default/blocks/realtime-monaco/hooks/use-connect-on-mount.ts",
+ "type": "registry:hook"
+ },
+ {
+ "path": "registry/default/blocks/realtime-monaco/components/realtime-monaco.tsx",
+ "type": "registry:component"
+ }
+ ]
+}
diff --git a/apps/ui-library/registry/default/examples/realtime-monaco-demo.tsx b/apps/ui-library/registry/default/examples/realtime-monaco-demo.tsx
new file mode 100644
index 00000000000..730e04ca5ac
--- /dev/null
+++ b/apps/ui-library/registry/default/examples/realtime-monaco-demo.tsx
@@ -0,0 +1,29 @@
+'use client'
+
+import { useTheme } from 'next-themes'
+import dynamic from 'next/dynamic'
+
+const Editor = dynamic(
+ () =>
+ import('../blocks/realtime-monaco/components/realtime-monaco').then(
+ (mod) => mod.RealtimeMonaco
+ ),
+ { ssr: false }
+)
+
+const RealtimeMonacoDemo = () => {
+ const { resolvedTheme } = useTheme()
+ const isDark = resolvedTheme?.includes('dark')
+
+ return (
+ <div className="p-4">
+ <Editor
+ channel="realtime-monaco-demo"
+ language="typescript"
+ theme={isDark ? 'dark' : 'light'}
+ />
+ </div>
+ )
+}
+
+export default RealtimeMonacoDemo
diff --git a/apps/ui-library/registry/examples.ts b/apps/ui-library/registry/examples.ts
index c7a160cd627..83e3fcd837f 100644
--- a/apps/ui-library/registry/examples.ts
+++ b/apps/ui-library/registry/examples.ts
@@ -23,6 +23,17 @@ export const examples: RegistryItem[] = [
},
],
},
+ {
+ name: 'realtime-monaco-demo',
+ type: 'registry:example',
+ registryDependencies: [],
+ files: [
+ {
+ path: 'registry/default/examples/realtime-monaco-demo.tsx',
+ type: 'registry:example',
+ },
+ ],
+ },
{
name: 'password-based-auth-demo',
type: 'registry:example',
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f0e979d9d09..cc0906e1ccd 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1290,7 +1290,7 @@ importers:
'@monaco-editor/react':
specifier: ^4.6.0
'@radix-ui/react-accordion':
specifier: '*'
@@ -1375,6 +1375,9 @@ importers:
'@react-router/fs-routes':
specifier: ^7.4.0
+ '@supabase-labs/y-supabase':
+ specifier: 0.1.0
+ version: 0.1.0
'@supabase/postgrest-js':
specifier: 'catalog:'
version: 2.99.1
@@ -1423,6 +1426,9 @@ importers:
lucide-react:
specifier: '*'
version: 0.436.0([email protected])
+ monaco-editor:
+ specifier: ^0.55.1
+ version: 0.55.1
next:
specifier: 'catalog:'
@@ -1489,10 +1495,22 @@ importers:
vaul:
specifier: ^0.9.6
+ y-monaco:
+ specifier: ^0.1.6
+ y-protocols:
+ specifier: ^1.0.7
+ version: 1.0.7([email protected])
+ yjs:
+ specifier: ^13.6.29
+ version: 13.6.29
zod:
specifier: 'catalog:'
version: 3.25.76
devDependencies:
+ '@babel/core':
+ specifier: '*'
+ version: 7.29.0([email protected])
'@react-router/dev':
specifier: ^7.9.0
@@ -8305,6 +8323,9 @@ packages:
resolution: {integrity: sha512-Cq3KKe+G1o7PSBMbmrgpT2JgBeyH2THHr3RdIX2MqF7AnBuspIMgtZ3ktcCgP7kZsTMvnmWymr7zZCT1zeWbMw==}
engines: {node: '>=12.16'}
+ '@supabase-labs/[email protected]':
+ resolution: {integrity: sha512-1ItaKbcImgy7ueYfJcyVYihqCKi9RAee9MKBV8wcCqSMNsrWvw4ibhW8ai91kWsewsiWzIDXVPONgcUcxagk9g==}
+
'@supabase/[email protected]':
resolution: {integrity: sha512-x7lKKTvKjABJt/FYcRSPiTT01Xhm2FF8RhfL8+RHMkmlwmRQ88/lREupIHKwFPW0W6pTCJqkZb7Yhpw/EZ+fNw==}
engines: {node: '>=20.0.0'}
@@ -13220,6 +13241,9 @@ packages:
peerDependencies:
ws: '*'
+ resolution: {integrity: sha512-PIeMbHqMt4DnUP3MA/Flc0HElYjMXArsw1qwJZcm9sqR8mq3l8NYizFMty0pWwE/tzIGH3EKK5+jes5mAr85yw==}
+
resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==}
engines: {node: '>=8'}
@@ -13509,6 +13533,11 @@ packages:
resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==}
engines: {node: '>= 0.8.0'}
+ resolution: {integrity: sha512-DeXj9X5xDCjgKLU/7RR+/HQEVzuuEUiwldwOGsHK/sfAfELGWEyTcf0x+uOvCvK3O2zPmZePXWL85vtia6GyZw==}
+ engines: {node: '>=16'}
+ hasBin: true
+
resolution: {integrity: sha512-RLvnKPLWngNR7bNep/Q9euPcfFJVFfDg/iP13lYGxcSI01emS/1vbTw6EBd8UordweWFdvUuK+31sHp104dukA==}
@@ -13805,6 +13834,11 @@ packages:
resolution: {integrity: sha512-S12OTkyXCkOgI1n1rZY9cg4bK/PGu80Emjpvwp8BEjwCxhPV3yddF0U6+QhCitdBsI1tzWcoeahmW7k0Pq81OA==}
+ resolution: {integrity: sha512-uIj4+faQ+MgHgwUW1l2PsPglZLOLOT1uErt06dAPtx2kjteLAkbsd/0FiYg/MGS+i7ZKLb7w2WClxHkzOOuryQ==}
+ engines: {node: '>= 18'}
+ hasBin: true
+
resolution: {integrity: sha512-K3UxuKu6l6bmA5FUwYho8CfJBlsUWAooKtdGgMcERSpF7gcBUrCGsLH7wDaaNOzwq18JzSUDyoEb/YsrqMac3w==}
engines: {node: '>= 20'}
@@ -14428,6 +14462,9 @@ packages:
resolution: {integrity: sha512-GEQWEZmfkOGLdd3XK8ryrfWz3AIP8YymVXiPHEdewrUq7mh0qrKrfHLNCXcbB6sTnMLnOZ3ztSiKcciFUkIJwQ==}
+ resolution: {integrity: sha512-jz4x+TJNFHwHtwuV9vA9rMujcZRb0CEilTEwG2rRSpe/A7Jdkuj8xPKttCgOh+v/lkHy7HsZ64oj+q3xoAFl9A==}
+
resolution: {integrity: sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==}
@@ -18597,6 +18634,19 @@ packages:
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
engines: {node: '>=0.4'}
+ resolution: {integrity: sha512-sYRywMmcylt+Nupl+11AvizD2am06ST8lkVbUXuaEmrtV6Tf+TD4rsEm6u9YGGowYue+Vfg1IJ97SUP2J+PVXg==}
+ engines: {node: '>=12.0.0', npm: '>=6.0.0'}
+ peerDependencies:
+ monaco-editor: '>=0.20.0'
+ yjs: ^13.3.1
+
+ resolution: {integrity: sha512-YSVsLoXxO67J6eE/nV4AtFtT3QEotZf5sK5BHxFBXso7VDUT3Tx07IfA6hsu5Q5OmBdMkQVmFZ9QOA7fikWvnw==}
+ engines: {node: '>=16.0.0', npm: '>=8.0.0'}
+ peerDependencies:
+ yjs: ^13.0.0
+
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
engines: {node: '>=10'}
@@ -18642,6 +18692,10 @@ packages:
resolution: {integrity: sha512-sosfr7agy4ibLM7BvXBkM6BpBmKMGuBO8DUYQEuey+QqaqrgW+2bsSg6D050ocBYIz0PuHxUyehyzEztZTU4pw==}
+ resolution: {integrity: sha512-kHqDPdltoXH+X4w1lVmMtddE3Oeqq48nM40FD5ojTd8xYhQpzIDcfE2keMSU5bAgRPJBe225WTUdyUgj1DtbiQ==}
+ engines: {node: '>=16.0.0', npm: '>=8.0.0'}
+
resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==}
engines: {node: '>=6'}
@@ -21543,10 +21597,10 @@ snapshots:
react: 18.3.1
react-dom: 18.3.1([email protected])
dependencies:
'@monaco-editor/loader': 1.5.0
- monaco-editor: 0.52.2
+ monaco-editor: 0.55.1
react: 18.3.1
react-dom: 18.3.1([email protected])
@@ -25624,6 +25678,15 @@ snapshots:
'@stripe/[email protected]': {}
+ '@supabase-labs/[email protected]':
+ dependencies:
+ '@supabase/supabase-js': 2.99.1
+ y-protocols: 1.0.7([email protected])
+ yjs: 13.6.29
+ transitivePeerDependencies:
+ - bufferutil
+ - utf-8-validate
+
'@supabase/[email protected]':
dependencies:
tslib: 2.8.1
@@ -31282,6 +31345,8 @@ snapshots:
dependencies:
ws: 8.18.3
+
@@ -31567,6 +31632,10 @@ snapshots:
prelude-ls: 1.2.1
type-check: 0.4.0
+ dependencies:
+ isomorphic.js: 0.2.5
+
dependencies:
'@mapbox/node-pre-gyp': 1.0.11([email protected])([email protected])
@@ -31948,6 +32017,8 @@ snapshots:
+
@@ -33114,6 +33185,11 @@ snapshots:
+ dependencies:
+ dompurify: 3.2.7
+ marked: 14.0.0
+
@@ -35361,7 +35437,7 @@ snapshots:
classnames: 2.5.1
core-js: 3.35.0
decko: 1.2.0
- dompurify: 3.2.7
+ dompurify: 3.3.1
eventemitter3: 5.0.1
json-pointer: 0.6.2
lunr: 2.3.9
@@ -38167,6 +38243,17 @@ snapshots:
+ dependencies:
+ lib0: 0.2.117
+ monaco-editor: 0.55.1
+ yjs: 13.6.29
+
+ dependencies:
+ lib0: 0.2.117
+ yjs: 13.6.29
+
@@ -38207,6 +38294,10 @@ snapshots:
+ dependencies:
+ lib0: 0.2.117
+
optional: true
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index 603292f9c78..d51300ab4c9 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -44,6 +44,7 @@ minimumReleaseAge: 10080
minimumReleaseAgeExclude:
- '@ai-sdk/*'
- '@supabase/*'
+ - '@supabase-labs/*'
- next
- '@next/*'
- ai