0.10.2 • Published 4 years ago

draftjs-utils v0.10.2

Weekly downloads
167,460
License
MIT
Repository
github
Last release
4 years ago

DraftJS Utils

An collection of useful utility functions for DraftJS.

I have been using DraftJS in few of my projects. DraftJS is very nice library for creating editors. I wrote a couple of utility functions for myself which I can re-use across my projects. They are well tested. I am open-sourcing them so that others can also leverage. Many of the functions described use ImmutableJS.

Installing

npm install draftjs-utils

Methods

Method NameParametersReturn TypeDescription
1getSelectedBlocksMapEditorStateOrderedMapThe function will return an Immutable OrderedMap of currently selected Blocks. The key is key of Block and value is ContentBlock.
2getSelectedBlocksListEditorStateListThe function will return an Immutable List of currently selected Blocks. The data type of returned objects is ContentBlock.
3getSelectedBlockEditorStateContentBlockThe function will return first of currently selected Blocks, this is more useful when we expect user to select only one Block. The data type of returned object is ContentBlock.
3getBlockBeforeSelectedBlockEditorStateContentBlockThe function will return block just before the selected block(s). The data type of returned object is ContentBlock.
5getAllBlocksEditorStateListThe function will return all the Blocks of the editor. The data type of returned objects is ContentBlock.
6getSelectedBlocksTypeEditorStatestringThe function will return the type of currently selected Blocks. The type is a simple string. It will return undefined if not all selected Blocks have same type.
7removeSelectedBlocksStyleEditorStateEditorStateThe function will reset the type of selected Blocks to unstyled.
8getSelectionTextEditorStatestringThe function will return plain text of current selection.
9addLineBreakRemovingSelectionEditorStateEditorStateThe function will replace currently selected text with a \n.
10insertNewUnstyledBlockEditorStateEditorStateThe function will add a new unstyled Block and copy current selection to it.
11clearEditorContentEditorStateEditorStateThe function will clear all content from the Editor.
12getSelectionInlineStyleEditorStateobjectThe function will return inline style applicable to current selection. The function will return only those styles that are applicable to whole selection.
13setBlockDataEditorState, objectEditorStateThe function will add block level meta-data.
14getSelectedBlocksMetadataEditorStateMapThe function will return map of block data of current block.
15blockRenderMapMapThe function will return map of block types Block Type -> HTML Tag.
16getSelectionEntityEditorStateEntityThe function will return the Entity of current selection. Entity can not span multiple Blocks, method will check only first selected Block.
17getEntityRangeEditorState, entityKeyobjectThe function will return the range of given Entity in currently selected Block. Entity can not span multiple Blocks, method will check only first selected Block.
18handleNewLineEditorStateEditorState, EventThe function will handle newline event in editor gracefully, it will insert \n for soft-new lines and remove selected text if any.
19isListBlockContentBlockbooleanThe function will return true is type of block is 'unordered-list-item' or 'ordered-list-item'.
20changeDepthEditorState , adjustment, maxDepthEditorStateChange the depth of selected Blocks by adjustment if its less than maxdepth.
21getSelectionCustomInlineStyleEditorState , Array (of styles)objectFunction will return Map of custom inline styles applicable to current selection.
22toggleCustomInlineStyleEditorState , string (styleType), string(styleValue)EditorStateToggle application of custom inline style to current selection.
23removeAllInlineStylesEditorStateEditorStateThe function will remove all inline styles of current selection.

Demo

For a complete example, check out https://github.com/jpuri/react-draft-wysiwyg repo.

License

MIT.

@wdaglb/braft-editorhorsen-braft-editorbraft-editor-improved@kichiyaki/react-draft-wysiwygmdt-libwebull-draft-editor@infinitebrahmanuniverse/nolb-draf@everything-registry/sub-chunk-1513braft-editor-fixyach.open.draft-editxhf-editor@duyndawing/react-draft-wysiwygvv-braft-editorws-react-draft-wysiwygtowlang-braft-utilstest-wsyiwygtest-editor-modify@francistec/react-draft-wysiwygupdate-packs-braft-editor@inner-desktop/braft-utils@inner-desktop/braft-editor@hassenkarnit/react-draft-wysiwyg@innovaccer/rich-text-editor@ingrao-blog/editor@golpasal/editorfake-core-widgetcomfolks-react-draft-wysiwyg@dock365/react-draft-wysiwyg@doky-lab/react-draft-wysiwygo2-editor@datlas/mdt-libprolar-editorprolar-master-editorprolar-rich-editorqhc_job_uidef-editordraft-js-handlebars-plugindraftjs-coredraftodraft-richtextdraft-js-testdictaipsamreact-tagareareact-wysiwyg-draftreact-text-area-editorreact16-draft-wysiwygreact-txt-editorreact-waynechu-wysiwygrenpanpan5-braft-editorshytoolssimon-editor-clonesp-react-draft-wysiwygsupcon-editorsupcon-editor-originsupcon-braft-editorbraft-editorbraft-editor-2braft-editor-91braft-editor-dreamcogbraft-editor-extendbraft-editor-featbraft-editor-flowbraft-editor-iframebraft-editor-ihshbraft-editor-imgbraft-editor-kanyun-secbraft-editor-mentionbraft-editor-newbraft-editor-reactbraft-editor-selfbraft-editor-testbraft-editor-v2braft-editor-videobraft-editor-zdfbraft-editor0-fixedbraft-editor1-fixedbraft-react-antdbraft-v2colba-react-draft-wysiwyg@mintlab/ui@mk-editor/platform-sdk@olisti/react-draft-wysiwyg@kedao/editorfs-editor@kedao/utils@mikeljames/react-draft-wysiwyg@orazoulay/react-draft-wysiwyg@morishin/react-draft-wysiwygwysiwyg-with-mention-callback@ghostramses/react-draft-wysiwyg@geosolutions/react-draft-wysiwyg@fi1osof/react-draft-wysiwygfork-braft-editor@jrohlandt/react-draft-wysiwyg@huynh315/react-draft-wysiwygkbsnd3laboriosamquisquambasic-braft-editorbf-editor-qolioneatui-editor
0.10.1

4 years ago

0.10.2

4 years ago

0.10.0

4 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.8

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.0

7 years ago

0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

8 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.1.7

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago