3.2.11-alpha.0 • Published 3 years ago

@deskpro/content-editor v3.2.11-alpha.0

Weekly downloads
12
License
ISC
Repository
github
Last release
3 years ago

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
3.2.11-alpha.0

3 years ago

3.2.6-alpha.0

3 years ago

3.2.10-alpha.0

3 years ago

3.2.5-alpha.0

3 years ago

3.2.9-alpha.0

3 years ago

3.2.4-alpha.0

3 years ago

3.2.8-alpha.0

3 years ago

3.2.7-alpha.0

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.4

3 years ago

3.2.3

3 years ago

3.2.0

3 years ago

3.1.5

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.4

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.8

3 years ago

3.0.9

3 years ago

3.0.7

3 years ago

3.1.0-alpha.0

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

2.4.1

3 years ago

3.0.0-alpha.0

3 years ago

3.0.0

3 years ago

2.4.0

3 years ago

2.3.2

3 years ago

2.3.4

3 years ago

2.3.3

3 years ago

2.3.0

3 years ago

2.3.1

3 years ago

2.2.3

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.4

3 years ago

2.1.2

3 years ago

2.1.3

3 years ago

2.0.1

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

2.0.0-beta.48

3 years ago

2.0.0-beta.51

3 years ago

2.0.0-beta.50

3 years ago

2.0.0-beta.49

3 years ago

2.0.0-beta.47

3 years ago

2.0.0-beta.46

3 years ago

2.0.0-beta.44

3 years ago

2.0.0-beta.43

3 years ago

2.0.0-beta.42

3 years ago

2.0.0-beta.41

3 years ago

2.0.0-beta.45

3 years ago

2.0.0-beta.40

3 years ago

2.0.0-beta.22

3 years ago

2.0.0-beta.21

3 years ago

2.0.0-beta.26

3 years ago

2.0.0-beta.25

3 years ago

2.0.0-beta.24

3 years ago

2.0.0-beta.23

3 years ago

2.0.0-beta.29

3 years ago

2.0.0-beta.28

3 years ago

2.0.0-beta.27

3 years ago

2.0.0-beta.33

3 years ago

2.0.0-beta.32

3 years ago

2.0.0-beta.31

3 years ago

2.0.0-beta.30

3 years ago

2.0.0-beta.37

3 years ago

2.0.0-beta.36

3 years ago

2.0.0-beta.35

3 years ago

2.0.0-beta.34

3 years ago

2.0.0-beta.39

3 years ago

2.0.0-beta.38

3 years ago

2.0.0-beta.20

3 years ago

2.0.0-beta.19

3 years ago

2.0.0-beta.18

3 years ago

2.0.0-beta.17

3 years ago

2.0.0-beta.16

3 years ago

2.0.0-beta.15

3 years ago

2.0.0-beta.14

3 years ago

2.0.0-beta.13

3 years ago

2.0.0-beta.12

3 years ago

2.0.0-beta.11

3 years ago

2.0.0-beta.10

3 years ago

2.0.0-beta.9

3 years ago

2.0.0-beta.8

3 years ago

2.0.0-beta.7

3 years ago

2.0.0-beta.6

3 years ago

2.0.0-beta.5

3 years ago

2.0.0-beta.4

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.3

3 years ago

2.0.0-alpha.0

3 years ago

2.0.0-beta.1

3 years ago

2.0.0-beta.0

3 years ago

1.0.1

3 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.15

4 years ago

0.1.14-collab.1

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.11-collab.5

5 years ago

0.1.11-collab.4

5 years ago

0.1.10-collab.10

5 years ago

0.1.10-collab.8

5 years ago

0.1.11-collab.2

5 years ago

0.1.11-collab.1

5 years ago

0.1.10-collab.7

5 years ago

0.1.10-collab.6

5 years ago

0.1.10-collab.5

5 years ago

0.1.10-collab.4

5 years ago

0.1.10-collab.3

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago