0.3.8 • Published 2 years ago

nagwa-html-editor v0.3.8

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Nagwa HTML Editor

A Typescript & React project that creates a WYSIWYG Rich text/ HTML editor using Slate js.

Table of Content:

1. Getting Started

These instructions will guide you to consume the API provided by the app.

1.1. Installation

1.1.1. Using CDN

Following these instructions will integrate the app into your website and will provide a globally defined API to be used.

  1. Download the latest version of the app.
  2. Link the app's CSS file the head of your HTML File. Example:

      <head>
          <link href="/static/css/app-min.css" rel="stylesheet"/>
      </head>
  3. Link the app's Javascript file in the body of your HTML File. Example:

      <body>
          <script src="/static/js/NagwaHTMLEditor.js"></script>
      </body>

1.1.2. Using NPM

Following these instructions will integrate the app into your website and will provide a react component library that provides the editor react component to be rendered.

  npm i nagwa-html-editor

and then in your React app import the editor as follows:

import NagwaHTMLEditor from "nagwa-html-editor"

1.2. Documentation

Here will explain the API provided by our app that can be found under the globally defined namespace NagwaHTMLEditor.

1.2.1. Static API Interface

The NagwaHTMLEditor is implementing the following interface:

type Descendant = CustomElement | CustomText

class NagwaHTMLEditor {
  public static init: (config: EditorConfig) => EditorAPI
}

interface EditorConfig {
  containerId: string
  uploadImage?:
    | string
    | ((image: File) => Promise<string>)
    | { storeUrl: string; uploadFn: (image: File) => Promise<string> }
  oldValue?: string
  locale?: "ar/eg" | "en/eg"
  hideToolbarOnBlur?: boolean
}

interface EditorAPI {
  editor: CustomEditor //The slate Editor API
  getValue: () => string
  getDeserializedValue(): Descendant[]
  setValue(oldValue: string, locale?: "ar/eg" | "en/eg"): void
  setDeserializedValue(oldValue: Descendant[]): void
  clear(): void
  readonly isEmpty: boolean
}

1.2.2. Static API Explanation

Here's an explanation of the provided API:

  • NagwaHTMLEditor:
    • init: The main method that initiates the app with the desired config and returns Editor object with utility methods.
  • EditorConfig:
    • containerId: The id of the HTML element to contain the app. Note that the element corresponding with the provided id will be replaced with a div element with the same provided id. This property is mandatory for the app to run, if not provided the app won't run.
    • oldValue: The old HTML value to initiate the app with. This is an optional property, if not provided the app will start with an empty state.
    • locale: The locale of the provided oldValue to set the direction of the element according to it. This property is optional and falls back to "en/eg" if not provided.
    • uploadImage: Can be a function that handles uploading the image inputted bt the user, a string url that represents a file storage or hosting service that contains images to be called by ID, or an object containing both properties. This property is optional, if not provided the feature of inserting image will not be available.
    • hideToolbarOnBlur: If this property was passed as true the toolbar will be hidden until the editor is focused. The default value is false which will make the toolbar visible at all times.
  • Editor:
    • getValue: This method serializes the current editor value state into the desired HTML output.
    • getDeserializedValue: This method returns the current state of the corresponding editor. The state matches the structure mentioned in the @types folder.
    • setValue: This method deserializes the HTML string inputted and sets the editor's state to the deserialized value.
    • setDeserializedValue: This method returns sets the current state of the corresponding editor with a new one. The state must match the structure mentioned in the @types folder.
    • clear: This method clears the current editor value state and empties the editable area.
    • isEmpty: This is a readonly property that tells you if the current state of the editor is empty or not.

1.2.3. Component Library API

The component library uses the same API with some differences.
A react component is exposed and export as default that renders the Editor component.

interface Props {
  mode?: "full" | "lite"
  uniqueKey?: string
  hideToolbarOnBlur?: boolean
}
export const NagwaHTMLEditor: React.VFC<Props> = () => {...}
export default NagwaHTMLEditor

Aside from the exported component the API extraction and deletion is implementing the following functions that are namely exported.

export function getEditorAPI(uniqueKey: string): EditorAPI //The same Static API interface (See the above section)
export function deleteEditorAPI(uniqueKey: string): boolean

1.2.4. Component Library API Explanation

The component library API uses the same API of the Static API's EditorAPI Interface with the different exported items.

  • NagwaHTMLEditor: This is the main component to be used to render an instance of the Editor and keep its state in memory. This component is exported namely and as default so that you can use the NagwaHTMLEditor name when importing or use any other name needed in your case. This is a void react component that accepts some props as follows:
    • mode: The mode of the Editor to be rendered if it was not provided it will fallback to "full".
    • uniqueKey: This key is required and has to be unique because it stores the different editors states in an object with this uniqueKey. If it was not provided (not recommended) it will fallback to "main" so that you won't need to add a uniqueKey when you need to render only one Editor, if there's more than one please provide a uniqueKey.
    • hideToolbarOnBlur: If this property was passed as true the toolbar will be hidden until the editor is focused. The default value is false which will make the toolbar visible at all times.
  • getEditorAPI: A function that accesses the store with the uniqueKey and returns the corresponding EditorAPI for this editor instance. Notice that this uniqueKey should be the same one as the one provided for the NagwaHTMLEditor component.
    This function is only namely exported.
  • deleteEditorAPI: A function that accesses the store with the uniqueKey and deletes the corresponding EditorAPI for this editor instance. Notice that this uniqueKey should be the same one as the one provided for the NagwaHTMLEditor component.
    This function is only namely exported.

1.3. Editor Output Samples

Here are some editor output samples that you can get using the getValue method:

  • 3 text samples (bold, italic, ... etc.):

    • EN:
      Example 1 Input English Sample

      <p style="text-align: left;"><b>This is Bold.</b></p>
      <p style="text-align: left;"><i>This is Italic.</i></p>
      <p style="text-align: left;"><u>This is Underlined.</u></p>
      <p style="text-align: left;"><span style="color:#e51d74">This is Colored.</span></p>
      <p style="text-align: left;"><i><b>This is Bold Italic.</b></i></p>
      <p style="text-align: left;"><u><b>This is Bold and Underlined.</b></u></p>
      <p style="text-align: left;"><span style="color:#e51d74"><b>This is Bold and Colored.</b></span></p>
      <p style="text-align: left;"><u><i>This is Italic and Underlined.</i></u></p>
      <p style="text-align: left;"><span style="color:#e51d74"><i>This is Italic and Colored.</i></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u>This is Underlined and Colored.</u></span></p>
      <p style="text-align: left;"><u><i><b>This is Bold, Italic, and Underlined.</b></i></u></p>
      <p style="text-align: left;"><span style="color:#e51d74"><i><b>This is Bold, Italic, and Colored</b></i></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u><b>This is Bold, Underlined, and Colored.</b></u></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u><i>This is Italic, Underlined, and Colored</i></u></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u><i><b>This is Bold, Italic, Underlined and Colored.</b></i></u></span></p>
    • FR:
      Example 1 Input French Sample

      <p style="text-align: left;"><b>C'est audacieux.</b></p>
      <p style="text-align: left;"><i>C'est en italique.</i></p>
      <p style="text-align: left;"><u>Ceci est souligné.</u></p>
      <p style="text-align: left;"><span style="color:#e51d74">C'est coloré.</span></p>
      <p style="text-align: left;"><i><b>Ceci est en gras italique.</b></i></p>
      <p style="text-align: left;"><u><b>Ceci est gras et souligné.</b></u></p>
      <p style="text-align: left;"><span style="color:#e51d74"><b>C'est audacieux et coloré.</b></span></p>
      <p style="text-align: left;"><u><i>Ceci est en italique et souligné.</i></u></p>
      <p style="text-align: left;"><span style="color:#e51d74"><i>Ceci est en italique et en couleur.</i></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u>Ceci est souligné et coloré.</u></span></p>
      <p style="text-align: left;"><u><i><b>Ceci est en gras, italique et souligné.</b></i></u></p>
      <p style="text-align: left;"><span style="color:#e51d74"><i><b>Ceci est gras, italique et coloré.</b></i></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u><b>Ceci est gras, souligné et coloré.</b></u></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u><i>Ceci est en italique, souligné et coloré.</i></u></span></p>
      <p style="text-align: left;"><span style="color:#e51d74"><u><i><b>Ceci est gras, italique, souligné et coloré.</b></i></u></span></p>
    • AR:
      Example 1 Arabic Input Sample

      <p dir="rtl" style="text-align: right;"><b>هذا غامق.</b></p>
      <p dir="rtl" style="text-align: right;"><i>هذا مائل.</i></p>
      <p dir="rtl" style="text-align: right;"><u>هذا مسطر.</u></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74">هذا ملون.</span></p>
      <p dir="rtl" style="text-align: right;"><i><b>هذا غامق ومائل.</b></i></p>
      <p dir="rtl" style="text-align: right;"><u><b>هذا غامق ومسطر.</b></u></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74"><b>هذا غامق وملون.</b></span></p>
      <p dir="rtl" style="text-align: right;"><u><i>هذا مائل ومسطر.</i></u></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74"><i>هذا مائل وملون.</i></span></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74"><u>هذا مسطر وملون.</u></span></p>
      <p dir="rtl" style="text-align: right;"><u><i><b>هذا غامق، مائل ومسطر.</b></i></u></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74"><i><b>هذا غامق، مائل وملون.</b></i></span></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74"><u><b>هذا غامق، مسطر وملون.</b></u></span></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74"><u><i>هذا مائل، مسطر وملون</i></u></span></p>
      <p dir="rtl" style="text-align: right;"><span style="color:#e51d74"><u><i><b>هذا غامق، مائل، مسطر وملون.</b></i></u></span></p>
  • 2 Text (bold, italic, ... etc.) + inline math:

    • EN:
      Example 2 Input English Sample

      <p dir="ltr" style="text-align: left;"><b>This is Bold and here's an equation: </b>
          <math-field default-mode="inline-math" value="x+y=z" className="hoverable-mathlive-mathfield inline"></math-field><b>.</b>
      </p>
      <p dir="ltr" style="text-align: left;"><i>This is Italic and here's an equation : </i>
          <math-field default-mode="inline-math" value="\\sin\\left(\\frac{x}{y}\\right)" className="hoverable-mathlive-mathfield inline"></math-field><i>.</i>
      </p>
      <p dir="ltr" style="text-align: left;"><u>This is Underlined and here's an equation: </u>
          <math-field default-mode="inline-math" value="\\sqrt[3]{x^2+y^2}" className="hoverable-mathlive-mathfield inline"></math-field><u>.</u>
      </p>
      <p dir="ltr" style="text-align: left;"><span style="color:#e51d74">This is Colored and here's an equation: </span>
          <math-field default-mode="inline-math" value="x^{\\left(\\frac{\\sin45}{\\cos45}\\right)}" className="hoverable-mathlive-mathfield inline"></math-field><span style="color:#e51d74">.</span>
      </p>
    • AR:
      Example 2 Arabic Input Sample

      <p dir="rtl" style="text-align: right;"><b>هذا غامق وهذه معادلة:</b>
          <math-field default-mode="inline-math" value="س+ص=ع" className="hoverable-mathlive-mathfield inline"></math-field>
          <b>.</b>
      </p>
      <p dir="rtl" style="text-align: right;"><i>هذا مائل وهذه معادلة:</i>
          <math-field default-mode="inline-math" value="\\ga\\left(\\frac{س}{ص}\\right)" className="hoverable-mathlive-mathfield inline"></math-field><i>.</i>
      </p>
      <p dir="rtl" style="text-align: right;"><u>هذا مسطر وهذه معادلة:</u>
          <math-field default-mode="inline-math" value="\\sqrt[٣]{س^٢+ص^٢}" className="hoverable-mathlive-mathfield inline"></math-field><u>.</u>
      </p>
      <p dir="rtl" style="text-align: right;"><span style="color:rgb(229, 29, 116)">هذا ملون وهذه معادلة:</span>
          <math-field default-mode="inline-math" value="س^{\\left(\\frac{\\ga٤٥}{\\gata٤٥}\\right)}" className="hoverable-mathlive-mathfield inline"></math-field><span style="color:rgb(229, 29, 116)">.</span>
      </p>
  • 2 Text + inline math + Displayed math:

    • EN:
      Example 3 Input English Sample

      <p>Here's an inline equation: <math-field default-mode="inline-math" value="x^2\\;=\\;\\sqrt[3]{y^{\\frac{x}{2}}+z}" className="hoverable-mathlive-mathfield inline"></math-field></p>
      <p>Here's a display equation:</p>
      <math-field default-mode="math" value="x^2e^{^{\\cos x}}=\\int_0^t\\frac{1}{\\sqrt{t^7}}\\;\\differentialD t" className="hoverable-mathlive-mathfield block"></math-field>
    • AR:
      Example 3 Arabic Input Sample

      <p dir="rtl" style="text-align: right;">هذه معادلة في نفس السطر: <math-field default-mode="inline-math" value="س^٢=\\;\\sqrt[٣]{ص^{\\frac{س}{٢}}+ع}" className="hoverable-mathlive-mathfield inline"></math-field></p>
      <p dir="rtl" style="text-align: right;">هذه معادلة في سطر منفصل:</p>
      <math-field default-mode="math" value="س^٢\\exponentialHaa^{\\gataس}=\\int_٠^ز\\frac{١}{\\sqrt{ز^٧}}\\;دز" className="hoverable-mathlive-mathfield block"></math-field>
  • 2 Text + inline math + chemistry:

    • EN:
      Example 4 Input English Sample

      <p>This is an inline equation <math-field default-mode="inline-math" value="y^{\\frac{3}{2}}" className="hoverable-mathlive-mathfield inline"></math-field></p>
      <p>This is a display chemistry equation:</p>
      <math-field default-mode="math" value="\\ce{H2O}+\\ce{2H2SO4}\\ce{->[\\Delta]}\\ce{\\ce{Na}}^-+\\ce{NaCL}\\ce{v}" className="hoverable-mathlive-mathfield block"></math-field>
    • AR:
      Example 4 Arabic Input Sample

      <p dir="rtl" style="text-align: right;">هذه معادلة في نفس السطر: <math-field default-mode="inline-math" value="ص^{\\frac{٢}{٣}}" className="hoverable-mathlive-mathfield inline"></math-field></p>
      <p dir="rtl" style="text-align: right;">هذه معادلة كيميائية في سطر منفصل:</p>
      <math-field default-mode="math" value="\\ce{H2O}+\\ce{2H2SO4}\\ce{->[\\Delta]}\\ce{Na}^-+\\ce{NaCL}\\ce{v}" className="hoverable-mathlive-mathfield block"></math-field>
  • 2 Text + inline math + chemistry + Table (cells include chemistry, math, text):

    • EN:
      Example 5 Input English Sample

      <p>Table without Headers:</p>
      <div class="table-wrapper">
          <table>
              <tbody>
                  <tr>
                      <td>Cell1</td>
                      <td>Cell2</td>
                      <td>Cell3</td>
                  </tr>
                  <tr>
                      <td>This is an inline equation: <math-field default-mode="inline-math" value="x+y=z\\sin45^{2+3}" className="hoverable-mathlive-mathfield inline"></math-field></td>
                      <td>This is an inline chemistry equation: <math-field default-mode="inline-math" value="\\ce{HCl}+\\ce{NaOH}\\ce{->[Heat][Heat]}\\ce{H2O}+\\ce{NaCl}\\ce{v}" className="hoverable-mathlive-mathfield inline"></math-field></td>
                      <td>Cell4</td>
                  </tr>
                  <tr>
                      <td>Cell5</td>
                      <td>Cell6</td>
                      <td>Cell7</td>
                  </tr>
              </tbody>
          </table>
      </div>
      <p>Table with Headers:</p>
      <div class="table-wrapper">
          <table>
              <thead>
                  <tr>
                      <th>Heading1</th>
                      <th>Heading2</th>
                      <th>Heading3</th>
                  </tr>
              </thead>
              <tbody>
                  <tr>
                      <td>Cell1</td>
                      <td style="text-align: right;">Cell2</td>
                      <td>Cell3</td>
                  </tr>
                  <tr>
                      <td>Cell4</td>
                      <td style="text-align: center;">Cell5</td>
                      <td>Cell6</td>
                  </tr>
              </tbody>
          </table>
      </div>
    • AR:
      Example 5 Arabic Input Sample

      <p dir="rtl" style="text-align: right;">جدول بلا عناوين:</p>
      <div class="table-wrapper">
          <table>
              <tbody>
                  <tr>
                      <td dir="rtl" style="text-align: right;">خلية٣</td>
                      <td dir="rtl" style="text-align: right;">خلية٢</td>
                      <td dir="rtl" style="text-align: right;">خلية١</td>
                  </tr>
                  <tr>
                      <td dir="rtl" style="text-align: right;">هذه معادلة: <math-field default-mode="inline-math"
                              value="س+ص=ع\\ga٤٥^{٢+٣}" className="hoverable-mathlive-mathfield inline"></math-field>
                      </td>
                      <td dir="rtl" style="text-align: right;">هذه معادلة كيميائية: <math-field default-mode="inline-math"
                              value="\\ce{HCl}+\\ce{NaOH}\\ce{->[Heat][Heat]}\\ce{H2O}+\\ce{NaCl}\\ce{v}"
                              className="hoverable-mathlive-mathfield inline"></math-field>
                      </td>
                      <td dir="rtl" style="text-align: right;">خلية٤</td>
                  </tr>
                  <tr>
                      <td dir="rtl" style="text-align: right;">خلية٧</td>
                      <td dir="rtl" style="text-align: right;">خلية٦</td>
                      <td dir="rtl" style="text-align: right;">خلية٥</td>
                  </tr>
              </tbody>
          </table>
      </div>
      <p dir="rtl" style="text-align: right;">جدول بعناوين:</p>
      <div class="table-wrapper">
          <table>
              <thead>
                  <tr>
                      <th dir="rtl" style="text-align: right;">عنوان ٣</th>
                      <th dir="rtl" style="text-align: right;">عنوان ٢</th>
                      <th dir="rtl" style="text-align: right;">عنوان ١</th>
                  </tr>
              </thead>
              <tbody>
                  <tr>
                      <td dir="rtl" style="text-align: right;">خلية٣</td>
                      <td dir="rtl" style="text-align: center;">خلية٢</td>
                      <td dir="rtl" style="text-align: right;">خلية١</td>
                  </tr>
                  <tr>
                      <td dir="rtl" style="text-align: right;">خلية٦</td>
                      <td dir="rtl" style="text-align: left;">خلية٥</td>
                      <td dir="rtl" style="text-align: right;">خلية٤</td>
                  </tr>
              </tbody>
          </table>
      </div>
  • 2 Text + inline math + image with style:

    • EN:
      Example 6 Input English Sample

      <p>Here's an equation: <math-field default-mode="inline-math" value="\\frac{x+y}{x+z}=y+2" className="hoverable-mathlive-mathfield inline"></math-field></p>
      <div><img src="https://media.glassdoor.com/l/8b/74/4e/81/the-premises-at-night.jpg" alt="Nagwa's premises" /></div>
      <p>Here's an unordered list:</p>
      <ul>
          <li>item</li>
          <li>item</li>
          <li>item</li>
      </ul>
      <p>Here's an ordered list:</p>
      <ol>
          <li>item</li>
          <li>equation: <math-field default-mode="inline-math" value="x^2+1" className="hoverable-mathlive-mathfield inline"></math-field></li>
          <li>item</li>
      </ol>
    • AR:
      Example 6 Arabic Input Sample

      <p dir="rtl" style="text-align: right;">هذه معادلة: <math-field default-mode="inline-math" value="\\frac{س+ص}{س+ع}=ص+٢" className="hoverable-mathlive-mathfield inline"></math-field></p>
      <p></p>
      <div><img src="https://media.glassdoor.com/l/8b/74/4e/81/the-premises-at-night.jpg" alt="Nagwa's premises" /></div>
      <p dir="rtl" style="text-align: right;">هذه قائمة غير مرقمة:</p>
      <ul>
          <li dir="rtl" style="text-align: right;">عنصر</li>
          <li dir="rtl" style="text-align: right;">عنصر</li>
          <li dir="rtl" style="text-align: right;">عنصر</li>
      </ul>
      <p dir="rtl" style="text-align: right;">هذه قائمة مرقمة:</p>
      <ol>
          <li dir="rtl" style="text-align: right;">عنصر</li>
          <li dir="rtl" style="text-align: right;">معادلة: <math-field default-mode="inline-math" value="س^٢+١" className="hoverable-mathlive-mathfield inline"></math-field></li>
          <li dir="rtl" style="text-align: right;">عنصر</li>
      </ol>

1.4. Example Using The API

1.4.1. Using the Static API

Here's an example of how to consume the API.
Folder Structure:

build
├─ index.html
└─ static
   ├─ css
   │  ├─ NagwaHTMLEditor-min.css
   │  └─ NagwaHTMLEditor-min.css.map
   ├─ fonts
   │  ├─ KaTeX_AMS-Regular.woff2
   │  ├─ KaTeX_Caligraphic-Bold.woff2
   │  ├─ KaTeX_Caligraphic-Regular.woff2
   │  ├─ KaTeX_Fraktur-Bold.woff2
   │  ├─ KaTeX_Fraktur-Regular.woff2
   │  ├─ KaTeX_Main-Bold.woff2
   │  ├─ KaTeX_Main-BoldItalic.woff2
   │  ├─ KaTeX_Main-Italic.woff2
   │  ├─ KaTeX_Main-Regular.woff2
   │  ├─ KaTeX_Math-BoldItalic.woff2
   │  ├─ KaTeX_Math-Italic.woff2
   │  ├─ KaTeX_SansSerif-Bold.woff2
   │  ├─ KaTeX_SansSerif-Italic.woff2
   │  ├─ KaTeX_SansSerif-Regular.woff2
   │  ├─ KaTeX_Script-Regular.woff2
   │  ├─ KaTeX_Size1-Regular.woff2
   │  ├─ KaTeX_Size2-Regular.woff2
   │  ├─ KaTeX_Size3-Regular.woff2
   │  ├─ KaTeX_Size4-Regular.woff2
   │  ├─ KaTeX_Typewriter-Regular.woff2
   │  ├─ NagwaArabicMath.woff2
   │  ├─ NagwaMath.woff2
   │  ├─ NotoNaskhArabic-Bold.woff2
   │  ├─ NotoNaskhArabic-Regular.woff2
   │  ├─ STIX2Text-Bold.woff2
   │  ├─ STIX2Text-BoldItalic.woff2
   │  ├─ STIX2Text-Italic.woff2
   │  ├─ STIX2Text-Regular.woff2
   │  ├─ droidnaskh-bold.woff2
   │  ├─ droidnaskh-regular.woff2
   │  ├─ fa-brands-400.woff2
   │  ├─ fa-light-300.woff2
   │  ├─ fa-regular-400.woff2
   │  ├─ fa-solid-900.woff2
   │  ├─ notosans-bold-webfont.woff2
   │  ├─ notosans-regular-webfont.woff2
   │  ├─ summernote.eot
   │  ├─ summernote.ttf
   │  ├─ summernote.woff
   │  ├─ summernote.woff2
   │  └─ times-extrabold.woff2
   ├─ images
   │  ├─ image-file.svg
   │  ├─ latex-icon-blue.svg
   │  ├─ latex-icon.svg
   │  ├─ pattern.svg
   │  ├─ select-arrow.svg
   │  ├─ sorting-asc.svg
   │  ├─ sorting-desc.svg
   │  ├─ sorting.svg
   │  ├─ three-dots.svg
   │  ├─ upload-cloud-icon.svg
   │  ├─ video-play-blue.svg
   │  └─ video_play.svg
   └─ js
      ├─ NagwaHTMLEditor.js
      ├─ NagwaHTMLEditor.js.LICENSE.txt
      └─ NagwaHTMLEditor.js.map

index.html:

<!doctype html>
<html lang="en">

<head>
    ...
    <link href="/static/css/NagwaHTMLEditor-min.css" rel="stylesheet">
</head>

<body>
    ...
    <div id="StemEditor"></div>
    ...
    <script src="/static/js/NagwaHTMLEditor.js"></script>
    <script>
      const stemEditor = NagwaHTMLEditor.init({
        containerId: "StemEditor",
        oldValue: "<p>Hello World!</p>",
        locale: "en/eg"
      })
      const stemEditorValue = stemEditor.getValue()
    </script>
</body>

</html>

1.4.2. Using the Component Library API

Here's an example of how to consume the Component Library API.
After installing the library (see: Install Component Library Using NPM), in your react app import the editor and the needed functions from the library as follows:

import { FC, useEffect } from "react"
import NagwaHTMLEditor, { getEditorAPI } from "nagwa-html-editor"

const uniqueKey = "******" //make sure it's unique for every editor instance

const Component:FC = () => {

  useEffect(() => {
    const editorAPI = getEditorAPI(uniqueKey)
    console.log(editorAPI)
  })

  return <NagwaHTMLEditor uniqueKey={uniqueKey} />
}

2. Forking Guide

These instructions will get you a copy of the project up and running on your local machine.

2.1. Prerequisites

You have to have Node.js v14.18.1, and npm v6.14.15 installed.
Also, check ./package.json for all the packages used in this project

2.2. Installing

Clone this repo, open the terminal and navigate to the repo directory on your local machine, and then run:

npm install

wait until it's done and you're good to go!

Note: if installation fails because if npm, make sure you're using v16. if it still fails, install using v14, then re-install using v16.

Note: There will be a high severity audit problem when you install the packages.
This Problem is caused by react-scripts package.
This is a false positive according to #9469 (comment) from the maintainers on this issue, so there's nothing to worry about.

3. Built With

  • TypeScript - The main language used.
  • Node.js v16 - The run-time environment used to run and build the app (Currently working using v16).
  • React - The web framework used.
  • Slate - The library used to create the text editor.

4. Main Features

  • Inserting any type of text.
  • Making text bold.
  • Making text italic.
  • Making text underlined.
  • Making text code.
  • Making text superscript.
  • Making text subscript.
  • Inserting bulleted list.
  • Inserting numbered list.
  • Aligning text to any direction.
  • Justify text.
  • Setting the direction of the text to "ltr" or "rtl.
  • Inserting a table.
  • Inserting inline editable math equation.
  • Inserting display editable math equation.

5. Git Style

5.1. Message Structure

A commit messages consists of three distinct parts separated by a blank line: the title, an optional body and an optional footer. The layout looks like this:

type: subject

body

5.1.1. The Type

The type is contained within the title and can be one of these types:

  • feat: a new feature
  • fix: a bug fix
  • docs: changes to documentation
  • style: formatting, missing semi colons, etc; no code change
  • refactor: refactoring production code
  • test: adding tests, refactoring test; no production code change
  • chore: updating build tasks, package manager configs, etc; no production code change

5.1.2. The Subject

Subjects should be no greater than 50 characters, should begin with a capital letter and do not end with a period.

Use an imperative tone to describe what a commit does, rather than what it did. For example, use change; not changed or changes.

5.1.3. The Body

Not all commits are complex enough to warrant a body, therefore it is optional and only used when a commit requires a bit of explanation and context. Use the body to explain the what and why of a commit, not the how.

When writing a body, the blank line between the title and the body is required and you should limit the length of each line to no more than 72 characters.

For more information about the style guide for Git and programming Languages check: Udacity's Code Style Guide

6. Release Steps

  1. Update version in packages.json
  2. Create a .md file with version name inside CHANGELOG folder, like the follwing: v0.1.11.md (v is a must)
  3. Run npm i in terminal, to update package.lock
  4. Push changes
  5. Create tag with version name on gitlab, like this: v0.1.11. (v is a must)
  6. Jenkins will take its time to create the release on gitlab, can be viewed here: jenkins.nagwa.com
  7. Run npm run build:static in terminal
  8. Delete asset-manifest.json file, and static folder from bucket
  9. Upload newly built asset-manifest.json file, and static folder -->
  10. Run npm run build:static in terminal
  11. Merge contents from dist folder from nagwa-mathlive, with contents of build/static folder
  12. Open FileZilla, and connect to given dev-educator credentials
  13. Delete contents of dev-educator folder
  14. Upload content of build/static folder, to dev-educator folder on FileZilla -->
0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.3

2 years ago