0.0.51-canary • Published 11 months ago

@spendit-dev/editor v0.0.51-canary

Weekly downloads
-
License
GPL-2.0
Repository
github
Last release
11 months ago

Editor

A simple rich text editor using CKEditor.

Demo

Demo

Specification Summary

- Toolbar Custom: X

- Responsive Toolbar: O

- Changing ReadOnly or Edit Mode:O

- Language: 'ko' | 'en'

- Editor Auto Height: X

- Editor Manual Height: O

- Editor Diff Mode: O

How to use

1. Install

npm install @spendit-dev/editor or
yarn add @spendit-dev/editor

2. Import

import '@spendit-dev/editor/default.css';
import '@spendit-dev/editor/editor.css';
import { initEditor, initEditorSizingButton } from '@spendit-dev/editor';

3. Initialize

const {editor} = await initEditor({
    targetId: 'sample-editor',
    lang: 'en',
    initialData: '<p>test</p>',
    onContentChange: (content: string) => {
        console.log('change', content);
    },
    debounceDelay: 500,
    onBlur: (content:string) => {
        console.log('blur', content);
    },
    onFocus: (bool:boolean) => {
        console.log('focus', bool);
    },
});

// if you want to use manual editor heignt sizing button add the following code.
initEditorSizingButton({
    editor,
    sizingButtonPosition: 'inner',
    resizeButtonCallback: (currentHeight: number) => {
        console.log('currentHeight', currentHeight);
    },
});

// html
<div id="sample-editor"></div>

4. Set Read Only Mode

you can make the editor read-only mode by using the following code.

  const handleReadonlyEvent = (readonly: boolean) => {
    if (readonly) {
        editor.enableReadOnlyMode('targetId');
        editor.ui.view.toolbar.element!.style.display = 'none';
    } else {
        editor.disableReadOnlyMode('targetId');
        editor.ui.view.toolbar.element!.style.display = 'block';
    }
};

5. Destroy Editor

editor.destroy();

6. Get Content From Editor

const content = editor.getData();

7. Set Content To Editor

editor.setData('<p>test</p>');

8. Diff Mode Editor

await initDiffModeEditor({
    targetId: 'sample-diff-editor',
    lang: 'en',
    textPrevious: '<p>test removed this</p>',
    textCurrent: '<p>test added this</p>',
});

// html
<div id="sample-diff-editor"></div>

9. Else

editor instance is CKEditor instance. you can find more API in the CKEditor documentation.


API for spendit-editor

Func: initEditor()

Property NameDescriptionTypeRequired
targetIdHTML element id to attaching editor instancestringtrue
langLanguage of the editor'ko' | 'en'false
initialDataInitial data of the editorstringfalse
onContentChangeCallback function when content is changed(content: string) => voidfalse
debounceDelay?To debounce the onContentChange function, specify the delay in seconds. The default value is 3000 milliseconds (3 seconds).numberfalse
onBlur?Callback function when editor is blurred(content: string) => voidfalse
onFocus?Callback function when editor is focused(bool: boolean) => voidfalse

Returns of initEditor()

Property NameDescriptionTypeRequired
editorCKEditor instanceCKEditortrue

Func: initEditorSizingButton()

Property NameDescriptionTypeRequired
editorCKEditor instanceCKEditortrue
minHeightMinimum height of the editornumberfalse
maxHeightMaximum height of the editornumberfalse
gapHeightHeight to adjust at oncenumberfalse
sizingButtonPositionPosition of the sizing button'inner' | 'outer'false
resizeButtonCallbackCallback function when the editor height is changed(currentHeight: number) => voidfalse

Func: initDiffModeEditor()

Property NameDescriptionTypeRequired
targetIdHTML element id to attaching editor instancestringtrue
langLanguage of the editor'ko' | 'en'false
textPreviousPrevious Text for Diffstringtrue
textCurrentCurrent Text for Diffstringtrue

Returns of initDiffModeEditor()

Property NameDescriptionTypeRequired
editorCKEditor instanceCKEditortrue

Typescript Error

If you get a typescript error, you can add the following code to your type.d.ts file.

declare module '@spendit-dev/editor';

and you also need to add the following code to your tsconfig.json file.

{
    "compilerOptions": {
        "typeRoots": ["your type.d.ts path"],
        "types": ["@spendit-dev/editor"]
    }
}

This Editor isn't very open to customization. If you want to customize it, I'd recommend forking this repository and modifying it.

0.0.51-canary

11 months ago

0.0.40

1 year ago

0.0.41

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.47

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.30

1 year ago

0.0.31

1 year ago

0.0.32

1 year ago

0.0.33

1 year ago

0.0.34

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

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.19

1 year ago

0.0.50

11 months ago

0.0.48

12 months ago

0.0.49

12 months ago

0.0.18

1 year ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.9

1 year ago

0.0.16

1 year ago

0.0.17

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