npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@revesuite/virgo

v0.6.1-alpha.8

Published

A micro editor.

Downloads

43

Readme

@blocksuite/virgo

Introduction

Virgo is a minimized rich-text editing kernel that synchronizes the state between DOM and Y.Text, which differs from other rich-text editing frameworks in that its data model are natively CRDT. For example, to support collaborative editing in Slate.js, you may need to use a plugin like slate-yjs, a wrapper around Yjs. In these plugins, all text operations should be converted between Yjs and Slate.js operations. This may result in undo/redo properly and hard to maintain the code. However, with Virgo, we can directly synchronize the DOM state between Yjs and DOM, which means that the state in Yjs is the single source of truth. It signify that to update, can just calling the Y.Text API to manipulate the DOM state, which could significantly reduces the complexity of the editor.

Initially in BlockSuite, we use Quill for in-block rich-text editing, which only utilizes a small subset of its APIs. Every paragraph in BlockSuite is managed in a standalone Quill instance, which is attached to a Y.Text instance for collaborative editing. Virgo makes this further simpler, since what it needs to do is the same as how we use the Quill subset. It just needs to provide a flat rich-text synchronization mechanism, since the block-tree-level state management is handled by the data store in BlockSuite.

A virgo editor state corresponds to Y.Text, it's easy to convert between them. Virgo also provides a Delta format to represent the editor state, which is also supported by Yjs. So we can use Yjs to manipulate all the states of the text including format.

const yText = new Y.Text();

// Bind Y.Text to virgo editor, then type 'aaa\nbbb'
// ...
console.log(yText.toString()); // 'aaa\nbbb'

console.log(yText.toDelta());
/*
[
  {
    insert: 'aaa\nbbb',
  },
];
*/

If you format from the first character to the second character, the string representation in Y.Text will still be aaa\nbbb. But if we covert it to Delta, you will see the difference:

// Continue the example before, format 'aa' to bold
// ...
console.log(yText.toString()); // 'aaa\nbbb'

console.log(yText.toDelta());
/*
[
  {
    insert: 'aa',
    attributes: {
      bold: true,
    },
  },
  {
    insert: 'a\nbbb',
  },
];
*/

You will see that there is a type attribute in the Delta format, which is used to represent the type of text segments, like base text (bold, italic, line-break, inline-code, link, etc.). This format makes it easy implementing customized inline elements.

Usage

To use Virgo in your project, all you need to do is to create a Y.Text instance from Y.Doc, bind it to the virgo editor, then mount it to the DOM:

import * as Y from 'yjs';
import { VEditor } from '@blocksuite/virgo';

const doc = new Y.Doc();
const yText = doc.getText('text');
const vEditor = new VEditor(yText);

const editorContainer = document.getElementById('editor');
vEditor.mount(editorContainer);

You can go to virgo playground for online testing and check out the code in its repository.

🚧 The documentation about customizing inline elements and detailed APIs are still in progress. Stay tuned!