Editor

A block editor with a slash menu for headings, lists, to-dos and more.

Status
In review
Owner
Maya Chen
Target date
Jan 14
Comments are open until Friday. Hover a block for its handle, or press Esc to choose blocks.

Problem

Teams write a spec in one place and track the work in another, so the two drift apart within a week.

Goals

  • One page holds the why, the plan and the live task list.
  • Comments sit on the sentence they're about.
DatabaseLaunch tasks
Confirm search rules with @Ana Ruiz.

Background is in Research notes.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/editor

Usage

import { Block } from "./ui/uicontext/components/kit/Blocks.ts"import { Editor } from "./ui/uicontext/components/kit/Editor.ts"
const Message = UiSchema.TaggedEnum({ EditedBody: { blocks: Schema.Array(Block) } })// the app holds the blocks; every edit comes back as the whole next documentexport const PageBody = (h: Html.H<typeof Message.Type>, blocks: ReadonlyArray<Block>) =>	Editor(h, {		props: { id: "page-body", label: "Page content", blocks, placeholder: "Type / for blocks" },		onEmit: {			Changed: ({ blocks }) => Message.EditedBody({ blocks }),			ChoseCommand: () => undefined,			QueriedMention: () => undefined,			RequestedAction: () => undefined,			OpenedLink: () => undefined,			OpenedMention: () => undefined,			OpenedComment: () => undefined,			Blurred: () => undefined,			RequestedUpload: () => undefined,		},	})

Examples

Compact

A description field inside a record: smaller type, no handles, and a short list of block types.

Description

Exports over 10,000 rows time out after 30 seconds.

Stream the file instead of building it in memory
Email a link when the export is ready

Images and code

Paste or drop a picture and the app uploads it through RequestedUpload; captions sit under pictures, and code blocks pick a language.

Weekly signups

Signups grew every week after the new onboarding shipped.

Bar chart rising each week
Signups per week, March
select week, count(*) from signups group by week

Read-only

With readOnly, a page shows its blocks without editing, for a locked page or a viewer.

On-call handbook

The person on call answers pages within 15 minutes, day or night.

  1. Acknowledge the page.
  2. Post in the incident channel what you see.
  3. Hand over at 9:00 with a written summary.
Who to call when the database is down

Page the platform lead, then post the status in the incident channel.

Locked by Priya Nair. Ask an owner to change it.

API reference

Props

Editor props
NameTypeDefaultDescription
agentIdstringeditor:<id>This editor's id for agents, unique on the page; editor:<id> by default
idrequiredstring—Unique on the page
labelrequiredstring—The accessible name: "Page content", "Description"
blocksrequiredBlock[]—The document's blocks, in order; edits come back as events
syncEditorSync—Opt in from the first mount when persisting native changes asynchronously.
readOnlyboolean—Shown as plain elements, with no editing (below Can edit, a locked page)
compactboolean—Smaller type, for comments and descriptions in a dense app
placeholderstring—On the empty line with the caret
emptyPlaceholderstring—When the whole document is empty
blockTypesBlockType[]—The block types the menu offers (default: every type but embed)
commandsSlashCommand[]—The app's own / commands, sent as ChoseCommand
mentionsboolean—@ opens the mention menu
mentionOptionsMentionOption[]—For @ and [[: people, agents and pages (a page option's detail is its path)
mentionsLoadingboolean—Shows a loading row in the mention menu while results for the query arrive
actionsToolbarAction[]—The app's buttons on the selection toolbar, sent as RequestedAction
heldRange | null—A range the app holds highlighted, such as the text an AI is rewriting
asideboolean—Shows the aside slot under the held range (or the selection): an AI prompt, a comment box
handlesboolean—Block handles, the block menu and block selection; on unless compact
blockLinkstring—The page's address: "Copy link to block" copies it with # and the block's id
commentsEditorComment[]—Discussions on ranges of the text: highlighted, with a bubble each in the margin
activeCommentstring | null—The discussion that is open now: its highlight is stronger
recentstring[]—Block menu keys picked lately (newest first), shown as "Recent" in the / menu
pageTitlestring—The id of the PageTitle above this body: ArrowUp on the first line goes back into the title

Events

Editor events
EventPayloadDescription
Changed{ id: string; blocks: Block[]; change?: EditorChangeToken }Keep blocks immediately. Native edits include an acknowledgement token in revisioned mode.
ChoseCommand{ id: string; command: string; block: string }One of the app's / commands; the /query is already gone from the line
QueriedMention{ id: string; query: string }The person typed after @: answer with mentionOptions
RequestedAction{ id: string; action: string; range: Range; text: string; markdown: string }A toolbar action on the selection
OpenedLink{ id: string; href: string }Mod+click on a link, or a click on a card
OpenedMention{ id: string; mention: MentionRef }A click on a mention of a person, agent or page: open it
Blurred{ id: string }Focus left the editor and its parts: a good time to save
OpenedComment{ id: string; comment: string }A comment's highlight or bubble was clicked: show its thread
RequestedUpload{ id: string; block: string; name: string; size: number; type: string; preview: string }A picture was pasted, dropped or chosen. Its block shows the local preview while uploading; store the file (fetch it from preview), then send the block back with its address and without uploading. A refused upload: remove the block, or keep it with a caption saying why.

Slots

aside, databases

Wiring it to your app

Keep the blocks in your app, and pass them straight back on each Changed event. The editor handles typing, selection and composition itself.

If saves can finish out of order, set sync.revision on the first mount and echo each change token as sync.acknowledged. Apply a saved result only while its revision, session and sequence still match. To restore a saved version, advance the revision and clear the acknowledgement.

View a complete app example
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { Block, paragraph, plainText } from "./ui/uicontext/components/kit/Blocks.ts"import { Editor, EditorChangeToken } from "./ui/uicontext/components/kit/Editor.ts"const Save = Schema.Struct({ blocks: Schema.Array(Block), change: EditorChangeToken })const Message = UiSchema.TaggedEnum({	Edited: { blocks: Schema.Array(Block), change: Schema.optional(EditorChangeToken) },	Restored: {},	DeliveredSave: {},})const sameEdit = (a: typeof EditorChangeToken.Type | null, b: typeof EditorChangeToken.Type) =>	a?.revision === b.revision && a.session === b.session && a.sequence === b.sequenceexport const Notes = Html.component({	name: "ControlledNotes",	model: Schema.Struct({		blocks: Schema.Array(Block),		revision: Schema.Int,		acknowledged: Schema.NullOr(EditorChangeToken),		pending: Schema.NullOr(Save),		status: Schema.String,	}),	message: Message,}).make({	init: () => ({		blocks: [paragraph("note", "Starting note")],		revision: 0,		acknowledged: null,		pending: null,		status: "",	}),	update: {		Edited: ($, { blocks, change }) => {			if (change === undefined) {				return $.evolve({					blocks,					revision: (revision) => revision + 1,					acknowledged: null,					pending: null,				})			}			if (change.revision !== $.model.revision) return $.model			return $.evolve({ blocks, acknowledged: change, pending: { blocks, change }, status: "Draft ready to save." })		},		Restored: ($) => $.evolve({			blocks: [paragraph("note", "Restored note")],			revision: (revision) => revision + 1,			acknowledged: null,			status: "Revision restored.",		}),		DeliveredSave: ($) => {			const { pending, acknowledged } = $.model			if (pending === null) return $.model			return sameEdit(acknowledged, pending.change)				? $.evolve({ blocks: pending.blocks, pending: null, status: "Draft saved." })				: $.evolve({ pending: null, status: "Earlier save ignored." })		},	},	view: (h, { blocks, revision, acknowledged, pending, status }) =>		h.section.attrs({ "aria-labelledby": "notes-heading", class: "contract-notes" }).children(			h.h2.attr("id", "notes-heading").children("Editable notes"),			Editor(h, {				key: "notes",				props: {					id: "notes",					label: "Notes",					blocks,					sync: { revision, acknowledged: acknowledged ?? undefined },				},				onEmit: {					Changed: ({ blocks, change }) => Message.Edited({ blocks, change }),					ChoseCommand: () => undefined,					QueriedMention: () => undefined,					RequestedAction: () => undefined,					OpenedLink: () => undefined,					OpenedMention: () => undefined,					OpenedComment: () => undefined,					RequestedUpload: () => undefined,					Blurred: () => undefined,				},			}),			h.div.attr("class", "contract-actions").children(				Button(h, { emphasis: "outline" }).on("click", Message.Restored()).children("Restore revision"),				Button(h, { emphasis: "outline" }).disabled(pending === null)					.on("click", Message.DeliveredSave()).children("Deliver save response"),			),			h.output.attr("aria-label", "App-owned note").children(blocks.map((block) => plainText(block.content)).join("\n")),			h.p.attr("role", "status").children(status),		),})
notes.ts on GitHub

Accessibility

  • The page is one textbox with aria-multiline; the / and @ menus keep focus in the text and mark the active option with aria-activedescendant.
  • Escape chooses the blocks the caret is in: Up and Down move, Shift extends, Alt+Shift+Up and Down move them, Mod+D duplicates, Backspace deletes and Enter goes back to the text.
  • Mod+/ opens the block menu, and Escape then Tab reaches the add button and the handle, so every pointer action has a keyboard path.
  • Each comment bubble names how many comments it holds and the text they're about.

Source