12.4.0 • Published 11 days ago

@doc-tools/yfm-editor v12.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

@doc-tools/yfm-editor · npm package CI storybook

YFM WYSIWYG Editor

Preview: https://preview.yandexcloud.dev/yfm-editor/

Install

npm install @doc-tools/yfm-editor

Ensure that peer dependencies are installed in your project

npm install react@17 react-dom@17 @diplodoc/transform@4 @gravity-ui/uikit@5 @gravity-ui/components@2 lodash@4

Usage

import {
    YfmEditor,
    BasePreset,
    BehaviorPreset,
    MarkdownBlocksPreset,
    MarkdownMarksPreset,
    YfmPreset,
} from '@doc-tools/yfm-editor';

const domElem = document.querySelector('#editor');

const editor = new YfmEditor({
    domElem,
    linkify: true,
    allowHTML: false,
    extensions: (builder) =>
        builder
            .use(BasePreset, {})
            .use(BehaviorPreset, {})
            .use(MarkdownBlocksPreset, {image: false, heading: false})
            .use(MarkdownMarksPreset, {})
            .use(YfmPreset, {}),
    onDocChange: () => {
        console.log('The contents of the editor have been changed');
    },
});

// Serialize current content in YFM
editor.getValue();

Usage with React

import React from 'react';
import {
    Extension,
    BasePreset,
    BehaviorPreset,
    MarkdownBlocksPreset,
    MarkdownMarksPreset,
    useYfmEditor,
    YfmEditorComponent,
    YfmPreset,
} from '@doc-tools/yfm-editor';

export function Editor({initialContent}) {
    const extensions = React.useMemo<Extension>(
        () => (builder) =>
            builder
                .use(BasePreset, {})
                .use(BehaviorPreset, {})
                .use(MarkdownBlocksPreset, {image: false, heading: false})
                .use(MarkdownMarksPreset, {})
                .use(YfmPreset, {}),
        [],
    );

    const editor = useYfmEditor({
        linkify: true,
        allowHTML: false,
        extensions,
        initialContent,
    });

    // Serialize current content in YFM
    editor.getValue();

    return <YfmEditorComponent autofocus editor={editor} />;
}

Development

To start the dev storybook

npm run dev
12.4.0

11 days ago

12.3.0

16 days ago

12.2.1

24 days ago

12.2.0

25 days ago

12.1.0

28 days ago

12.0.1

29 days ago

12.0.0

1 month ago

11.0.0

2 months ago

10.2.3

2 months ago

10.2.2

2 months ago

10.2.0

2 months ago

10.2.1

2 months ago

10.1.0

3 months ago

10.0.0

3 months ago

9.3.1

3 months ago

9.3.0

3 months ago

9.2.0

3 months ago

9.1.1

4 months ago

9.1.0

4 months ago

8.2.1

5 months ago

9.0.0

5 months ago

8.2.0

5 months ago

8.1.0

5 months ago

5.5.1

10 months ago

5.5.0

10 months ago

6.1.0

8 months ago

6.3.0

7 months ago

6.1.2

8 months ago

6.1.1

8 months ago

6.5.0

6 months ago

6.1.4

7 months ago

6.1.3

7 months ago

7.1.0

6 months ago

6.6.0

6 months ago

5.6.0

10 months ago

6.0.0

9 months ago

6.2.0

7 months ago

6.4.0

6 months ago

7.0.0

6 months ago

7.2.0

6 months ago

8.0.0

5 months ago

6.7.0

6 months ago

5.4.0

10 months ago

5.3.0

11 months ago

5.2.0

12 months ago

5.1.0

1 year ago

5.0.0

1 year ago

3.4.5

1 year ago

3.4.4

1 year ago

3.7.0

1 year ago

3.4.3

1 year ago

3.6.0

1 year ago

3.5.0

1 year ago

4.5.0

1 year ago

4.4.1

1 year ago

4.4.0

1 year ago

4.1.0

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.3.0

1 year ago

4.2.0

1 year ago

3.4.0

1 year ago

3.4.2

1 year ago

3.4.1

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.0

2 years ago

3.0.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago