Skip to main content
Glama
codemirror.js1.73 kB
/* eslint-env browser */ import * as Y from 'yjs' // @ts-ignore import { yCollab, yUndoManagerKeymap } from 'y-codemirror.next' import { WebrtcProvider } from 'y-webrtc' import { EditorView, basicSetup } from 'codemirror' import { keymap } from '@codemirror/view' import { javascript } from '@codemirror/lang-javascript' // import { oneDark } from '@codemirror/next/theme-one-dark' import * as random from 'lib0/random' import { EditorState } from '@codemirror/state' export const usercolors = [ { color: '#30bced', light: '#30bced33' }, { color: '#6eeb83', light: '#6eeb8333' }, { color: '#ffbc42', light: '#ffbc4233' }, { color: '#ecd444', light: '#ecd44433' }, { color: '#ee6352', light: '#ee635233' }, { color: '#9ac2c9', light: '#9ac2c933' }, { color: '#8acb88', light: '#8acb8833' }, { color: '#1be7ff', light: '#1be7ff33' } ] export const userColor = usercolors[random.uint32() % usercolors.length] const ydoc = new Y.Doc() // const provider = new WebrtcProvider('codemirror6-demo-room', ydoc) const provider = new WebrtcProvider('codemirror6-demo-room-2', ydoc) const ytext = ydoc.getText('codemirror') provider.awareness.setLocalStateField('user', { name: 'Anonymous ' + Math.floor(Math.random() * 100), color: userColor.color, colorLight: userColor.light }) const state = EditorState.create({ doc: ytext.toString(), extensions: [ keymap.of([ ...yUndoManagerKeymap ]), basicSetup, javascript(), EditorView.lineWrapping, yCollab(ytext, provider.awareness) // oneDark ] }) const view = new EditorView({ state, parent: /** @type {HTMLElement} */ (document.querySelector('#editor')) }) // @ts-ignore window.example = { provider, ydoc, ytext, view }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'

If you have feedback or need assistance with the MCP directory API, please join our Discord server