Singapore
DocsGitHub
docs/start-here/quick-start.md

Quick start

Mount an editable text view in a browser application. You need a client-side JavaScript entry point and a bundler that resolves ESM and CSS imports, such as Vite.

1. Install the core

npm install
@singapore-editor/core
# or: pnpm add
@singapore-editor/core
# or: bun add
@singapore-editor/core
# or: yarn add
@singapore-editor/core
npm install
@singapore-editor/core
# or: pnpm add
@singapore-editor/core
# or: bun add
@singapore-editor/core
# or: yarn add
@singapore-editor/core
npm install
@singapore-editor/core
# or: pnpm add
@singapore-editor/core
# or: bun add
@singapore-editor/core
# or: yarn add
@singapore-editor/core
npm install
@singapore-editor/core
# or: pnpm add
@singapore-editor/core
# or: bun add
@singapore-editor/core
# or: yarn add
@singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add
@singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add
@singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add
@singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add
@singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
npm install @singapore-editor/core
# or: pnpm add @singapore-editor/core
# or: bun add @singapore-editor/core
# or: yarn add @singapore-editor/core
sh example

2. Give the editor a container

Add an HTML element with the id editor. Set height: 20rem, display: flex and flex-direction: column in your stylesheet. This constrains the editor’s scroll area to the element’s height.

3. Mount it

Save this as main.ts. Retain the editor so you can release it when the view closes.

import { Editor } from
'@singapore-editor/cor
e/editor'
const element =
document.querySelector
<HTMLElement>('#editor
')!
const editor = new
Editor(element)
editor.setText('const
greeting = "Hello,
Singapore"\n')
window.addEventListene
r('pagehide', (event)
=> {
if
(!event.persisted)
editor.dispose()
})
import { Editor } from
'@singapore-editor/cor
e/editor'
const element =
document.querySelector
<HTMLElement>('#editor
')!
const editor = new
Editor(element)
editor.setText('const
greeting = "Hello,
Singapore"\n')
window.addEventListene
r('pagehide', (event)
=> {
if
(!event.persisted)
editor.dispose()
})
import { Editor } from
'@singapore-editor/core/edit
or'
const element =
document.querySelector<HTMLE
lement>('#editor')!
const editor = new
Editor(element)
editor.setText('const
greeting = "Hello,
Singapore"\n')
window.addEventListener('pag
ehide', (event) => {
if (!event.persisted)
editor.dispose()
})
import { Editor } from
'@singapore-editor/core/edit
or'
const element =
document.querySelector<HTMLE
lement>('#editor')!
const editor = new
Editor(element)
editor.setText('const
greeting = "Hello,
Singapore"\n')
window.addEventListener('pag
ehide', (event) => {
if (!event.persisted)
editor.dispose()
})
import { Editor } from
'@singapore-editor/core/editor'
const element =
document.querySelector<HTMLElement>(
'#editor')!
const editor = new Editor(element)
editor.setText('const greeting =
"Hello, Singapore"\n')
window.addEventListener('pagehide',
(event) => {
if (!event.persisted)
editor.dispose()
})
import { Editor } from
'@singapore-editor/core/editor'
const element =
document.querySelector<HTMLElement>(
'#editor')!
const editor = new Editor(element)
editor.setText('const greeting =
"Hello, Singapore"\n')
window.addEventListener('pagehide',
(event) => {
if (!event.persisted)
editor.dispose()
})
import { Editor } from
'@singapore-editor/core/editor'
const element =
document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello,
Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
import { Editor } from
'@singapore-editor/core/editor'
const element =
document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello,
Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
import { Editor } from '@singapore-editor/core/editor'
const element = document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello, Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
import { Editor } from '@singapore-editor/core/editor'
const element = document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello, Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
import { Editor } from '@singapore-editor/core/editor'
const element = document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello, Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
import { Editor } from '@singapore-editor/core/editor'
const element = document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello, Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
import { Editor } from '@singapore-editor/core/editor'
const element = document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello, Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
import { Editor } from '@singapore-editor/core/editor'
const element = document.querySelector<HTMLElement>('#editor')!
const editor = new Editor(element)
editor.setText('const greeting = "Hello, Singapore"\n')
window.addEventListener('pagehide', (event) => {
if (!event.persisted) editor.dispose()
})
ts example

You should see one line of text and be able to move the caret, select text and type. Undo returns to an earlier edit. Syntax colours need a highlighting plugin. If nothing shows, see If it doesn’t work.

Choose Make live under a code example to try editing it. Changes stay in this browser tab.

Open a named document

Use a document id when a view needs identity, such as a tab or a language-server URI. Plain setText remains useful for unnamed text.

import { Editor } from
'@singapore-editor/cor
e/editor'
const editor = new
Editor(document.queryS
elector<HTMLElement>('
#editor')!)
editor.openDocument({
documentId:
'example.ts',
text: 'const value =
1\n',
languageId:
'typescript',
})
import { Editor } from
'@singapore-editor/cor
e/editor'
const editor = new
Editor(document.queryS
elector<HTMLElement>('
#editor')!)
editor.openDocument({
documentId:
'example.ts',
text: 'const value =
1\n',
languageId:
'typescript',
})
import { Editor } from
'@singapore-editor/core/edit
or'
const editor = new
Editor(document.querySelecto
r<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from
'@singapore-editor/core/edit
or'
const editor = new
Editor(document.querySelecto
r<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from
'@singapore-editor/core/editor'
const editor = new
Editor(document.querySelector<HTMLEl
ement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from
'@singapore-editor/core/editor'
const editor = new
Editor(document.querySelector<HTMLEl
ement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from
'@singapore-editor/core/editor'
const editor = new
Editor(document.querySelector<HTMLElement>('#editor
')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from
'@singapore-editor/core/editor'
const editor = new
Editor(document.querySelector<HTMLElement>('#editor
')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from '@singapore-editor/core/editor'
const editor = new
Editor(document.querySelector<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from '@singapore-editor/core/editor'
const editor = new
Editor(document.querySelector<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from '@singapore-editor/core/editor'
const editor = new Editor(document.querySelector<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from '@singapore-editor/core/editor'
const editor = new Editor(document.querySelector<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from '@singapore-editor/core/editor'
const editor = new Editor(document.querySelector<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
import { Editor } from '@singapore-editor/core/editor'
const editor = new Editor(document.querySelector<HTMLElement>('#editor')!)
editor.openDocument({
documentId: 'example.ts',
text: 'const value = 1\n',
languageId: 'typescript',
})
ts example

If it doesn’t work

The editor has no visible rows

Check the container’s height, flex layout and the core stylesheet import. Mount after the container exists in the DOM.

Highlighting is absent

The core edits plain text. Follow the languages and tree-sitter guide to load a syntax plugin.

A server-rendered page fails to load

Create the editor after client-side mount. The core uses browser DOM APIs.

Continue with documents and sessions, themes, or the TypeScript playground.