1.0.22 • Published 1 month ago

urdu-web-editor v1.0.22

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

urdu-web-editor

Urdu Rich Text Editor for web based on lexical

NPM JavaScript Style Guide

Install

npm install --save urdu-web-editor

Usage

import React, { useState, useCallback, Component } from 'react'

import Editor from 'urdu-web-editor'

class Example extends Component {
  const [value, setValue] = useState(null);
  const onSave = useCallback((newContents) => {
    console.log('onSave:', newContents)
  });

  const onChange = useCallback((newContents) => {
    console.log('onChange:', newContents)
  });

  const uiConfiguration = {
    "richText" : true,
    "format": "raw",
    "language" : "en",
    "placeholder" : null,
    "toolbar" : {
      "showAlignment": true,
      "showBlockFormat": true,
      "showFontFormat": true,
      "showInsert": true,
      "showListFormat": true,
      "showUndoRedo": true,
      "showExtraFormat": true,
      "showInsertLink": true,
      "showSave": true,
    },
    "spellchecker" : {
      "enabled": false,
      "language" : "en",
      "punctuationCorrections": () => [],
      "autoCorrections": () => [],
      "wordList" : () => [],
    }
  };

  render() {
    return <Editor initialValue={value}
        onChange={onChange}
        onSave={onSave}
        configuration={uiConfiguration} />
  }
}

Properties

Value

It is the value that you want to set for the editor. Its value depends on the format. If the type of editor and format used.

  • If using plain text editor, it must be plain text.
  • If using rich text editor with raw format, provided value must be a valid lexical state json
  • If using rich text editor with markdown format, provided value must be a valid markdown

Pass null if initializing an empty editor

OnChange

Callback function called when any change in editor takes place, parameter passed in the callback function is the formatted value from editor. This value can be passed back into value property.

OnSave

This callback function is called when save button is clicked on the editor. This will only work if the showSave is set to true in the configuration object

Configuration

Configuration object to customize the functionality and ui of the editor. Its structure is as follows:

  {
    "richText" : false,
    "format": "raw",
    "language" : "en",
    "placeholder" : null,
    "toolbar" : {
      "fonts" : null,
      "defaultFont": null,
      "showAlignment": true,
      "showBlockFormat": true,
      "showFontFormat": true,
      "showInsert": true,
      "showListFormat": true,
      "showUndoRedo": true,
      "showExtraFormat": true,
      "showInsertLink": true,
      "showSave": false,
    },
    "spellchecker" : {
      "enabled": false,
      "language" : "en",
      "punctuationCorrections": () => [],
      "autoCorrections": () => [],
      "wordList" : () => [],
    }
  }
richText

Type : boolean

Default value : false

Set it to true to use rich text editor. Otherwise plain text editor is used.

format

Type : string

Default value : raw

Possible values : raw, markdown

Set the format of output from editor when richText is set to true. The value, onChange and onSave will use this property to import or export editor contents in the selected format.

language

Type : string

Default value : en

Possible values : en, ur

This is the two letter language code to use for user interface. Editor features and layout will be modified based on language.

placeholder

Type: string

Default value : null

Text to use when there is no value present. By default a generic message will be used while placeholder is not specified or is null.

toolbar

Type : object

Default value :

{
  "fonts" : null,
  "defaultFont": null,
  "showAlignment": true,
  "showBlockFormat": true,
  "showFontFormat": true,
  "showInsert": true,
  "showListFormat": true,
  "showUndoRedo": true,
  "showExtraFormat": true,
  "showInsertLink": true,
  "showSave": false,
}
PropertytypeDefault ValueDescription
fontsobjectnullList of fonts to show. If null a standard list of fonts is shown.
defaultFontstringnullFont-face value of default font. If this property is null first font is selected as default font.
showAlignmentbooltrueShow/hide text alignment controls
showBlockFormatbooltrueShow/hide text alignment controls
showFontFormatbooltrueShow/hide text alignment controls
showInsertbooltrueShow/hide text insert menu
showListFormatbooltrueShow/hide text list formatting controls
showUndoRedobooltrueShow/hide text undo and redo controls
showExtraFormatbooltrueShow/hide extra formatting options of superscript, subscript and strike through
showInsertLinkbooltrueShow/hide insert link button
showSaveboolfalseShow/hide save button
Default font list and value of font-face
[
  { "value": "Arial", "label": "Arial" },
  { "value": "Courier New", "label": "Courier New" },
  { "value": "Georgia", "label": "Georgia" },
  { "value": "Times New Roman", "label": "Times New Roman" },
  { "value": "Trebuchet MS", "label": "Trebuchet MS" },
  { "value": "Verdana", "label": "Verdana" },
]

spellchecker

Type : object

Default value :

{
  "enabled": false,
  "language : "en",
  "punctuationCorrections": (lang) => [],
  "autoCorrections": (lang) => [],
  "wordList" : (lang) => [],
}
PropertytypeDefault ValueDescription
enabledboolfalseEnable/disable language tools including spell checker
languagestringenTwo character language code to use for language tools including spell checker.
punctuationCorrectionsfunction(language)[]Function to load punctuation correction list. See below for details.
autoCorrectionsfunction(language)[]Function to load automatic correction list. See below for details.
wordListfunction(language)[]Function to load word list for spell checking. It is a simple string array.
Punctuation and auto correct function response structure
[{
  "incorrectText": "",
  "correctText": "",
  "completeWord": true
}]

Development

Install dependencies

npm install

Develop library

npm start

License

MIT © umerfaruk

1.0.22

1 month ago

1.0.19

1 month ago

1.0.18

1 month ago

1.0.21

1 month ago

1.0.20

1 month ago

1.0.17

2 months ago

1.0.16

2 months ago

1.0.15

2 months ago

1.0.14

2 months ago

1.0.13

2 months ago

1.0.9

2 months ago

1.0.8

2 months ago

1.0.11

2 months ago

1.0.10

2 months ago

1.0.12

2 months ago

1.0.7

2 months ago

1.0.6

2 months ago

1.0.5

2 months ago

1.0.3

2 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago

1.0.0-beta.6

3 months ago

1.0.0-beta.7

3 months ago

1.0.0-beta.4

3 months ago

1.0.0-beta.5

3 months ago

1.0.0-beta.3

5 months ago

1.0.0-beta.2

5 months ago

1.0.0-beta.1

5 months ago