πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

reactjs-editor

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reactjs-editor

A simple react library that lets you highlight text, make text bold, and add comment on any text as a sticky notes

3.3.8
Source
npm
Version published
Weekly downloads
31
-6.06%
Maintainers
1
Weekly downloads
Β 
Created
Source


ReactjsEditor
ReactJSEditor

React package to highlight text,make text bold,add comment to text.View Demo.

screenshot

Get Started πŸ‘¨πŸ»β€βœˆοΈ

πŸ› οΈπŸ› οΈ Installation and Setup 🌱🌱


$ npm i reactjs-editor


---

πŸ› οΈπŸ› οΈ [Must have Configurations for Typescript project only] πŸ› οΈπŸ› οΈ

⏭️ ⏭️ For javascript project, you can skip this section ⏭️ ⏭️


In typescript you will probably get this error while trying to import package

⚠️⚠️⚠️ Could not find a declaration file for module 'reactjs-editor'. ⚠️⚠️⚠️


#### So we have to setup type declaration support for Typescript and fix that error
CLICK TO SETUP TYPE DECLARATION FOR TYPESCRIPT PROJECT
-----------------------------  FIRST STEP: -------------------------------


1. Go to your project 
$ cd <your typescript project root>

2. Create a new [FILE_NAME].d.ts file 
$ touch reacteditor.d.ts  

3. Make change to that file by adding the line below
$ nano reacteditor.d.ts

## Add this line below and save πŸ“πŸ“

declare module 'reactjs-editor';    //add this line and save

4. Save that file 

----------------------------- SECOND STEP: -------------------------------

1. Now open tsconfig.json file, you can find it in root of react typescript project πŸƒπŸƒπŸƒ 

2. Make change to tsconfig.json file by including path to [FILENAME].d.ts file
$ nano tsconfig.json  

## And just include path to file you created above  βž•βž•βž•

 "include": [
  "src",
  "./reacteditor.d.ts"  //Add this line and save
  ...
 ] 

πŸ‘©πŸΏβ€πŸ”§πŸ‘©πŸΏβ€πŸ”§ After this configuration setup, typescript won't show type error

πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰ Congratulations for successful Setup πŸ₯³πŸ₯³πŸ₯³



πŸ¦„βœ¨πŸ§™πŸΌβ€β™€οΈ Let's create a magic now πŸ¦„βœ¨πŸ§™πŸΌβ€β™€οΈ

Import Package in your project

$ import { Editor } from 'reactjs-editor';

Use Editor component and insert any html content

   <Editor
        htmlContent={`<main> 
          <h1>Welcome to My Website</h1>
          <p>This is a paragraph of text in HTML. It's simple and easy to create.</p>
          <p>HTML stands for HyperText Markup Language. It's the standard markup language for  creating web pages.</p>
          <p>In HTML, you can create different types of elements such as headings, paragraphs, links, lists, and more to structure and format your content.</p>
         </main>`}
      />

πŸŽ‰πŸŽ‰πŸŽ‰ Easy Peasy πŸŽ‰πŸŽ‰πŸŽ‰ Check it out



🚨🚨🚨 Note: ⚠️⚠️ Its important:

🚨🚨🚨 Make sure your htmlContent is wrapped inside main tag

βœ…βœ…βœ…

htmlContent={
<main>
{ *** all your html content here *** }
</main>
}

βœ…βœ…βœ…


πŸŽ‰πŸŽ‰πŸŽ‰ That's it. πŸŽ‰πŸŽ‰πŸŽ‰



Additional Props for Customizations

Add your own colors

<Editor
      colors={["black","gold","red"]}
      ....
      />

Make sure to add your class in your css file

/* In your css file */

.black{
    background-color:#000,
    color:#fff,
},
.red{
    background-color:red,
    color:#fff,
}
.gold{
    background-color:gold,
    color:#fff,
}

//add as much as you like



Get Access to Changed HTML Element.

πŸ’Ύ Save user html changes and show them their changes on subsequent visit


import { Editor, useDomValue } from 'reactjs-editor';

...

 const { dom, setDom } = useDomValue();

  // eslint-disable-next-line react-hooks/exhaustive-deps
  const updatedDomValue  = {
    key: dom?.key,
    props: dom?.props,
    ref: dom?.ref,
    type: dom?.type,
  }


  console.log("%j", updatedDomValue );  
  
  // get your changed dom  like this and save it if you like to in your database or some place

Update dom using that " updatedDomValue " values you saved from above


useEffect(()=>{
  function updateDom(updatedDomValue:any){
   setDom(updatedDomValue); //set your dom like this
 
  }
  updateDom(updatedDomValue) // call this function where ever you like

},[])



If you want to customize designs of all other components such as floating button and modals

1. Inspect html element
2. Find className of specific elements
3. Override css present there from your own css files 

 In future update, I will create option to pass all components in a props

Support

Buy Me A Coffee

License

MIT

vivekneupane11@gmail.com Β Β·Β  GitHub @vivekneupane11 Β Β·Β 

Keywords

react-editor

FAQs

Package last updated on 04 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts