Skip to content

Collab editor

Several people in one file around the rich editor, with carets, tracked changes and comments.

<div data-mount="two"></div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/collab-editor.css";

Usage

import "capsomer/collab-editor.css";
import { RichEditor } from "capsomer/react/rich-editor";
import { useRoomEditing } from "capsomer/react/collab-editor";

const editing = useRoomEditing({
  path: "/rooms/12/getting-started",
  initial: markdown,
  unsaved: false,
  viewer: { id: 7, name: "Alex Rivera", access: "edit" },
  names: { 7: "Alex Rivera", 9: "Sam Lee" },
  hideFrontMatter: true,
  mode, onMode: setMode, round, onRound: setRound,
});

{editing.bar}
{editing.rich ? (
  <RichEditor key={editing.rich.key} room={editing.rich} onReady={(h) => editing.setEditor(h.editor)} ... />
) : null}
{editing.panels}

Examples

The bar: offline, connecting, only you

<div data-mount="bars"></div>

API reference

Functions

FunctionSignatureDoes
useRichRoom(options: RichRoomOptions): RichRoom | nullThe rich editor's room for a Yjs copy: the binding, the others' carets under the names the room gives, suggesting as this person, and the open threads marked. useRoomEditing uses it over a y-partyserver room; any other provider (or two copies in one page) can use it directly.
useRoomEditing(options: RoomEditingOptions): RoomEditing
usePending(editor: Editor | null): numberThe suggestions waiting in an editor's text, counted again on each change.

CSS variables

VariableDefault
--whovar(--series-1)
--who-textvar(--series-text-1)

Parts and data attributes

ClassIs
.cap-collab-actionsits own class
.cap-collab-barits own class
.cap-collab-caretthe root
.cap-collab-caret-namea part
.cap-collab-caret-selectiona part
.cap-collab-commentits own class
.cap-collab-comment-bodyits own class
.cap-collab-comment-formits own class
.cap-collab-comment-metaits own class
.cap-collab-lineits own class
.cap-collab-markits own class
.cap-collab-noteits own class
.cap-collab-peopleits own class
.cap-collab-personits own class
.cap-collab-resolvedits own class
.cap-collab-stackits own class
.cap-collab-suggestionits own class
.cap-collab-suggestion-textits own class
.cap-collab-suggestionsits own class
.cap-collab-threadits own class
.cap-collab-thread-commentsits own class
.cap-collab-thread-quoteits own class
AttributeValues
data-activepresent or absent
data-suggestionmodification
data-who0 1 2 3 4 5 6 7
StateRead from
:focus-visiblethe platform

Accessibility

KeyDoes
TabMoves through the bar (Editing, Suggesting), the text, then the panels' fields and buttons
Left arrow, Right arrow (bar)Changes between Editing and Suggesting
Enter (comment field)A new line; Send posts it

Everything in the text is the rich editor's keyboard.

  • The bar's line ("Only you are here.", "Sam Lee is here too.", Offline, Connecting) is a status region. The others' avatars are a group named "Also here: …".
  • Carets are drawn decorations; the names are in the bar's line, so nothing depends on seeing a caret.
  • Suggestions and comments are listed in panels, in reading order, with who and when; Accept, Reject, Resolve and Delete are buttons with names. A thread chosen in the text takes focus in its panel.