0.6.5 • Published 8 months ago

@iserp/verbum v0.6.5

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

Verbum

Verbum - Flexible Text Editor for React

Verbum is a fully flexible rich text editor based on lexical-playground and lexical framework.

⚠️ As the Lexical framework is currently in early development, this component library is also likely to change quite often

Installation

npm install @iserp/verbum --save

Demo

Demo Live demo is coming soon...

Usage

import { FC } from 'react';
import {
  EditorComposer,
  Editor,
  ToolbarPlugin,
  AlignDropdown,
  BackgroundColorPicker,
  BoldButton,
  CodeFormatButton,
  FloatingLinkEditor,
  FontFamilyDropdown,
  FontSizeDropdown,
  InsertDropdown,
  InsertLinkButton,
  ItalicButton,
  TextColorPicker,
  TextFormatDropdown,
  UnderlineButton,
  Divider,
} from 'verbum';

const NoteViewer: FC = () => {
  return (
    <EditorComposer>
      <Editor hashtagsEnabled={true}>
        <ToolbarPlugin defaultFontSize="20px">
          <FontFamilyDropdown />
          <FontSizeDropdown />
          <Divider />
          <BoldButton />
          <ItalicButton />
          <UnderlineButton />
          <CodeFormatButton />
          <InsertLinkButton />
          <TextColorPicker />
          <BackgroundColorPicker />
          <TextFormatDropdown />
          <Divider />
          <InsertDropdown enablePoll={true} />
          <Divider />
          <AlignDropdown />
        </ToolbarPlugin>
      </Editor>
    </EditorComposer>
  );
};

export default NoteViewer;

API

<EditorComposer />

PropertyTypedescription
childrenReactNoderequiredNested child component which is the Editor itself
initialEditorStateInitialEditorStateTypeoptionalThe initial state of the editor

<Editor />

PropertyTypedescription
childrenReactNodeoptionalNested child components, like the ToolbarPlugin
hashtagsEnabledbooleanoptionalEnables the automatic hashtag highlighting, default is false
autoLinkEnabledbooleanoptionalEnables the automatic link highlighting, default is false
emojisEnabledbooleanoptionalReplaces the emoji combiniations with its corresponding symbol, default is false
emojiPickerEnabledbooleanoptionalUse : for search and paste emoji, default is false
actionsEnabledbooleanoptionalEnables the actions toolbar, default is false
placeholderstringoptionalThe default content of the editor when it is first loaded
listMaxIndentnumberoptionalThe maximum indent capacity of any listed element, the default is 7
isEditablebooleanoptionalEnables read-only mode for the editor, default is false
initialEditorStatestringoptionalJSON string to initialize the initial content of the editor.
onChange(editorState: string, editorInstance?: LexicalEditor) => voidoptionalAccessing the current editor state and the active editor instance
locale'en', 'fr', 'ptBr', 'ru', null;optionalEnables localization in the language of your choice, default is en. Available languages are en, fr, ptBr and ru

Automatic browser language detection Support

Verbum supports automatic browser language detection by default if locale not provided. If the browser language is set to fr, the editor will be automatically localized in French. If the browser language is set to en, the editor will be automatically localized in English. If the browser language is set to any other language, the editor will be automatically localized in English.

Plugins

<ToolbarPlugin />

PropertyTypedescription
childrenReact.ReactElement[]optionalNested child components, like the InsertDropdown
defaultFontSizestringoptionalThe default font size selected when the editor first loaded, default value is 15px
defaultFontColorstringoptionalThe default font color selected when the editor first loaded, default value is #000
defaultBgColorstringoptionalThe default text background color selected when the editor first loaded, default value is #fff
defaultFontFamilystringoptionalThe default font family selected when the editor first loaded, default value is Arial

Toolbar components

<FontFamilyDropdown />

Add your own font families.

PropertyTypedescription
fontOptionsFontOptions = [string, string][]optionalList of fonts

<FontSizeDropdown />

Add your own font sizes.

PropertyTypedescription
fontSizeOptionsFontOptions = [string, string][]optionalList of font sizes

<InsertDropdown />

PropertyTypedescription
enableTablebooleanoptionalEnables table inserting feature
enableYoutubebooleanoptionalEnables youtube video inserting feature
enableTwitterbooleanoptionalEnables tweet inserting feature
enablePollbooleanoptionalEnables poll inserting feature
enableImage{ enable: boolean; maxWidth: number };optionalEnables image inserting feature, set max width
enableEquationsbooleanoptionalEnables equation inserting feature
enableExcalidrawbooleanoptionalEnables diagram inserting feature
enableHorizontalRulebooleanoptionalEnables the horizontal rule inserting for layout
enableStickyNotebooleanoptionalEnables stick note inserting for layout

<MentionsPlugin />

PropertyTypedescription
searchDataSearchData<A>requiredSearching data using input string
getTypeaheadValuesGetTypeaheadValues<A>requiredSearch data transormation

GetTypeaheadValues<A>

PropertyTypedescription
urlstringrequiredURL adress
valuestringrequiredMention menu option value
pictureJSX.ElementrequiredMention menu option picture
popoverCardPopoverCard<A>optionalDisplaying a popup card when hovering over a username

PopoverCard<A>

PropertyTypedescription
card(data: A) => JSX.ElementrequiredPopover card, depends on <A> type
offsetOffsetCardrequiredCard offset (left, top)

Plugins support

Plugin nameWorkingDescriptionSource
ActionsPlugin:white_check_mark:Action menu in the right bottom cornerEditor.tsx
AutoLinkPlugin:white_check_mark:Auto highlight linksEditor.tsx
CharacterStylesPopupPlugin:white_check_mark:Modal style editor for selected textIndependent
ClickableLinkPlugin:white_check_mark:Enable to open links in new tabIndependent
CodeHighlightPlugin:white_check_mark:Code Block with different languagesIndependent
CommentPlugin:x:CharacterStylesPopupPlugin
EmojisPlugin:white_check_mark:A few emojisEditor.tsx
EmojiPickerPlugin:white_check_mark:Emoji picker (emoji-list.ts)Editor.tsx
EquationsPlugin:scissors:Katex, It's too heavy (cut out)InsertDropdown.tsx
ExcalidrawPlugin:scissors:Excalidraw (cut out)InsertDropdown.tsx
HorizontalRulePlugin:white_check_mark:Horizontal dividerInsertDropdown.tsx
ImagesPlugin:x:Insert file only (no URLs)InsertDropdown.tsx
KeywordsPlugin:x:Independent
ListMaxIndentLevelPlugin:white_check_mark:Max Indent Level (bullet, numeric)Independent
MarkdownShortcutPlugin:white_check_mark:Convert into Markdown formatActionsPlugin
MentionsPlugin:white_check_mark:Mentions, starts with @Independent
PollPlugin:x:Poll, need test with many votesInsertDropdown.tsx
SpeechToTextPlugin:white_check_mark:Voice recognition to textActionsPlugin
StickyPlugin:x:Yellow sticker, there is a bug with text styleInsertDropdown.tsx
TabFocusPlugin
TableActionMenuPlugin:white_check_mark:Create tableInsertDropdown.tsx
TestRecorderPlugin
TreeViewPlugin
TwitterPlugin:white_check_mark:Insert twitsInsertDropdown.tsx
TypingPerfPlugin
YouTubePlugin:white_check_mark:Insert YouTube videosInsertDropdown.tsx

Development

For development use:

$ npm install (in case of an error, run `npm install --legacy-peer-deps`)
$ npm start

Also you can test it locally using Storybook:

$ npm run storybook

Future plans

  • Test coverage
  • Programmatic access to the editor input as JSON
  • Localization
  • Ready templates with different options (MUI, Bootstrap, etc...)
  • Dark/Light modes
  • Custom styling flexibility
  • Disassembling all of the toolbar to enable using them as nested components, increasing the flexibility
  • Enabling adjusting editor settings such read-only mode and etc. programmatically

License

Licensed under MIT License.