CHEWCHEWW / react-web-editor

The react-web-editor is a WYSIWYG editor library. you can resize and drag your component. It also has simple rich text editor
https://reactwebeditor.com
264 stars 35 forks source link
drag-and-drop draggable editor hooks react react-web-editor resizable wysiwyg wysiwyg-editor
# react-web-editor

### A Simple **WYSIWYG** editor for react users #### You can make your own editor using our library

demo gif image ### You can explore various features on the website. [Visit My Website!](https://www.reactwebeditor.com) ### You can also try on CodeSandBox. [CodeSandBox](https://codesandbox.io/s/react-web-editor-my626?file=/src/App.js)

🗂️Table of contents

  1. What is React Web Editor
  2. Core characteristics
  3. Getting started
  4. Version up log
  5. Documents

🎨What is React Web Editor

💭Core characteristics

💁Getting started

installing

npm -i react-web-editor

import

import { StyleEditorBlock, TextEditorBlock, ... } from "react-web-editor;

or you can import as below

import ReactWebEditor from "react-web-editor";

🔥Version up log

Version Log
2.2.0 Upgrade Ui, Fix Hooks usage
2.1.0 Upgrade Drag and Drop feature
2.0.0 Create Editable Board, minor bug update
1.2.0 Upgrade Text Editor to initialize options
1.1.0 Upgrade editor to use unit like "rem"
~ 1.0.5 Use helmet, Update helmet to async
~ 1.0.2 Upgrade Drag and Drop feature, Solve minor Ui bug
1.0.0 Add Text Editor
0.1.6 Upgrade Style editor features
~ 0.1.5 Solve Next.js Font disappear bug

📃Documents

Block components

These components are designed to be user friendly. Easily control components using no more than props.

Style Editor Block

The Style Editor Component(SEC) is a block component which can change size and location of components. Another powerful usage of The SEC is uploading images on the screen or changing a component's background color. By wrapping a component with the SEC and setting the position of the component ‘absolute’, the component becomes editable on an website. This component also can be used without your own component.

Two tabs will appear on the screen when you hover a cursor on the component. The First tab is a uploading image tab, which is help you add an image. The Second tab is a color handler. It changes component's background color.

Drag and Drop Table

The Drag and Drop Table(DNDT) component makes all child components draggable within the DNDT area. You can use the DNDT by wrapping your components that you desire to be draggable.

Hooks

Our library structured with "hooks" friendly. Use the hook when you need a single feature from hooks or when you want to make a custom component.

With the React-Web-Editor you can generate editor pages and your own library. These need a more precise usage. So If you want to use our library's features simply, We recommend using block components.

useDraggable

return usage
handleDragStart onMouseDown handler
handleDragEnd onMouseUp handler

This component can be used with DraggableHandler, and EditorBlockWrapper.

useResize

It returns Resize handlers. It can be used with "ResizeHandlerWrapper", The helper component to resize.

- returns

|return     | usage|
|------------|--------------|
|handleMouseDown      | onMouseDown handler |
------
This component can be used with ResizeHandlerWrapper and EditorBlockWrapper.

### useImage
The UseImage hook helps upload and display images on the screen.

- props
```js
type UseImageProps {
  initialImage?: string;
}
return usage
imageSrc string
handleFileChange onChangeHandler of InputElement

useColor

The UseColor hook returns color change handler.

return usage
color string
handleColorChange onChangeHandler of InputElement

Helper Components

These components help you customize and generate your own component. You can make your own library using this feature. It lets you easily handle hooks and editor components.

Editable Board

The Editable Board component is a helper component. If you put a block component (like StyleEditorBlock, or TextEditorBlock) to this component's children and define parentStyle, the children components will bound in the Editable board area.

EditorBlockWrapper

The Editor Block Wrapper is a style component. The size and location of the component are received in props. It changes style dynamically with these props. It can be used with useResize and useDraggable

import { useState } from "react";
import { EditorBlockWrapper, useDraggable } from "react-web-editor";

const [componentStyle, setComponentStyle] = useState({
  width: 20,
  height: 40,
  top: 40,
  left: 40,
});
// this state can be used for your own component.
const {
  handleDragEnd, // onMouseUp handler
  handleDragStart, // onMouseDown handler
} = useDraggable({
  ...componentStyle,
  onDrag: setComponentStyle,
  unit: "px",
});

return (
  <EditorBlockWrapper
    width={componentStyle.width}
    height={componentStyle.height}
    top={componentStyle.top}
    left={componentStyle.left}
    onMouseDown={handleDragStart}
    onMouseUp={handleDragEnd}
  >
    <YourOwnComponent style={{ position: "absolute" }}>
  </EditorBlcokWrapper> // Now, This component dynamically change location.
);

ResizeHandlerWrapper

This component is specialized for the useResize hook. It generates vertices in the four directions of the component.

import { useState } from "react";
import { EditorBlockWrapper, ResizeHandlerWrapper, useResize } from "react-web-editor";

const [componentStyle, setComponentStyle] = useState({
  width: 20,
  height: 40,
  top: 40,
  left: 40,
});
// this state can be used for your own component.
const { handleMouseDown } = useDraggable({
  ...componentStyle,
  onResize: setComponentStyle,
  unit: "px",
});

return (
  <EditorBlockWrapper
    width={componentStyle.width}
    height={componentStyle.height}
    top={componentStyle.top}
    left={componentStyle.left}
  >
    <ResizeHandlersWrapper>
      {DIRECTIIONS.map((item) => (
        <div key={item} className={item} onMouseDown={handleMouseDown} />
      ))}
    </ResizeHandlersWrapper>
  </EditorBlcokWrapper> // Now, This component can change size.
);