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

@deskpro/content-editor

v3.2.11-alpha.0

Published

Base package for abstracting a customizable ProseMirror editor implementation.

Downloads

261

Readme

Deskpro Content Editor

This core package abstracts away the ProseMirror-specific configuration and setup to enable better extensibility, regardless of the target framework or UI.

Getting Started

This package contains most of the base ProseMirror-related logic and implements a robust extension system strongly inspired by tiptap's own extension system.

Usage

Usually, you would want to grab a wrapper package to use on top of this core package. For React, this is where @deskpro/react-content-editor comes in. Only React is fully-supported by this editor at the moment.

Regardless, this core content-editor package contains the base functionality of the editor and its extensibility without keeping a dependency on any frameworks.

Quick Start

To get started, you need to install the core package:

npm install --save @deskpro/content-editor

And set it up manually:

import { Editor, EditorEvents } from '@deskpro/content-editor';

...

// instantiate an editor
const editor = new Editor();

// apply extensions
editor
    .useStandardSchema()
    .useStandardPlugins()
    .use([ ...yourCustomExtensions ]);

// listen to editor events
editor
    .on(EditorEvents.CHANGE, () => {
        console.log('Content changed:', editor.getHTML());
    });

// attach editor to the DOM
const container = document.querySelector("#editor-wrapper");
editor.setRoot(container);

...

Once you call setRoot on the editor, all extensions will be initialized and the contenteditable instance is attached to the given container. From there, you can access a variety of members and methods to manipulate the editor and its data.

While the editor is usable on non-React environments, most of the extensions are currently dependent on reusable React components to speed up development. This means that you won't be able to use most of the built-in features like the standard toolbar, table editing, image manipulation, and pretty much any extension that renders complex menus and popups.

Ideally in the future, all extensions should be available without being tied to React.

Passing Editor Options

You may pass options to the Editor's constructor to set its initial content or template schema.

const editor = new Editor({
    template: "heading paragraph*",
    initialContent: "<h1>Hello~</h1><p>It's me...</p>"
});

The above will force all content on the editor to explicitly start with a heading, and allow only paragraphs after it. Then it will use the provided HTML as the document's initial content.

Accessing Content

You may get and set content through the editor instance.

const editor = new Editor();

editor.getHTML();    // gets the current contents of the editor, in HTML
editor.getContent(); // gets the contents in a ProseMirror object format
editor.getJSON();    // just like getContent, but in a JSON string

// at any point in time, you may replace the contents of the
// entire editor by passing either an HTML string or an object
// output of the above getContent call.
editor.setContent(stringOrObject);

The object received from getContent is a subset of ProseMirror's node data structure as described on the documentation.

Dispatching Commands

You have access to all of the editor's commands through editor.commands, organized based on extensions. You can use these to build transactions and apply those on the editor using editor.dispatch().

const editor = new Editor();

...

// insert some text at the start of the document
const tr = editor.view.state.tr.insertText('some text', 0);
editor.dispatch(tr);

Development

As this is part of a monorepo, make sure you have installed all dependencies through Lerna on the root folder:

lerna bootstrap --hoist

You can start the typescript watcher locally on this package using:

npm run watch