0.0.70 • Published 2 months ago

bq-editor v0.0.70

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

bq Editor

Simple and Bqeautiful React Rich Text Editor.

Installation

npm i bq-editor
yarn add bq-editor

Usage

Render

To render the editor with default extensions we simply do:

<Editor />

Extensions

Extensions indicate what type of content the editor can handle.

<Editor
  extensions={[
    [
      {
        name: "heading",
        attrs: {
          levels: [1, 2, 3]
        }
      },
      {
        name: "bold"
      },
      {
        name: "italic"
      }
    ],
    [
      {
        name: "text-color",
        attrs: {
          color: #ffffff
        }
      }
    ]
  ]}
/>

It is an matrix, whose order and separations will define the toolbar.

Everything you type will be passed through with keybindings to the extensions. Users can even bold text via input rules: Type **bold** to add bold text.

Some extensions have additional parameters, run the storybook or go to the examples folder to see them.

Content

Editor provides an onChange function to export and save the contents.

export const MyEditor<{ content: ProsemirrorNode }> = ({ content }) => {
  const [doc, setDoc] = useState<ProsemirrorNode>();

  return (
    <Editor
      initialContent={JSON.stringify(content)}
      onChange={setDoc}
    />
  );
};

The output content is a ProsemirrorNode type.

The input content is a string, which will be handle as ProsemirrorNode type except if a specific string handle is activated.

Html Editor

Two remirror functions are exposed to handle html content: editorNodeToHtml and htmlToEditorNode.

export const MyHtmlEditor<{ html: string }> = ({ html }) => {
  const [doc, setDoc] = useState<ProsemirrorNode>();

  return (
    <Editor
      initialContent={html}
      onChange={setDoc}
      stringHandler="html"
    />
  );
};

Markdown Editor

Due to the limitations of markdown some extensions do not work.

export const MyMarkdownEditor<{ markdown: string }> = ({ markdown }) => {
  const [doc, setDoc] = useState<ProsemirrorNode>();

  return (
    <Editor
      initialContent={markdown}
      onChange={setDoc}
      stringHandler="markdown"
    />
  );
};

Code Editor

The code editor is activated with the codeEditor variable, there is no need to add extensions.

export const MyCodeEditor<{ content: ProsemirrorNode }> = ({ content }) => {
  const [doc, setDoc] = useState<ProsemirrorNode>();

  return (
    <Editor
      codeEditor
      initialContent={JSON.stringify(content)}
      onChange={setDoc}
    />
  );
};

Visor

To view non-editable content:

export const MyVisor<{ content: ProsemirrorNode }> = ({ content }) => {
  return (
    <Visor content={JSON.stringify(content)} />
  );
};

Corresponding extensions, handler or codeEditor must be added so visor can interpret the content.

Storybook

To see more examples and play with them, download the project, install dependencies and run our storybook:

yarn storybook:start

Contribute

First of all, thanks for using bq editor!

If you run into any issues, open an issue in our github repository or create a pull request with your improvement proposal, explaining in detail the problem and the solution.

Please be patient, as this is a work in progress project.

Credits

This editor uses the wonderful Remirror React library.

All credits and applause go to the Remirror team.

License

This project is licensed under the MIT License. See LICENSE file for more details.

0.0.70

2 months ago

0.0.69

2 months ago

0.0.66

3 months ago

0.0.67

3 months ago

0.0.68

3 months ago

0.0.63

3 months ago

0.0.64

3 months ago

0.0.65

3 months ago

0.0.62

3 months ago

0.0.60

3 months ago

0.0.61

3 months ago

0.0.59

3 months ago

0.0.58

3 months ago

0.0.56

3 months ago

0.0.57

3 months ago

0.0.54

4 months ago

0.0.55

4 months ago

0.0.52

4 months ago

0.0.53

4 months ago

0.0.40

7 months ago

0.0.41

7 months ago

0.0.42

7 months ago

0.0.43

7 months ago

0.0.44

7 months ago

0.0.45

6 months ago

0.0.46

6 months ago

0.0.47

6 months ago

0.0.37

7 months ago

0.0.38

7 months ago

0.0.39

7 months ago

0.0.30

9 months ago

0.0.31

9 months ago

0.0.32

7 months ago

0.0.33

7 months ago

0.0.34

7 months ago

0.0.35

7 months ago

0.0.36

7 months ago

0.0.51

6 months ago

0.0.50

6 months ago

0.0.48

6 months ago

0.0.49

6 months ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.26

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago