0.1.10 • Published 11 months ago

@appflowyinc/editor v0.1.10

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

AppFlowy Web Editor

A modern editor library with support for rich text, markdown, and code editing.

✨ Features

  • 🌓 Day/Night mode switching
  • 🌍 Multi-language support
  • 📱 Responsive design
  • 💪 TypeScript support
  • 📝 Rich text, markdown, and code editing
  • 📦 Easy to integrate
  • 🎉 And more!

📦 Installation

To install the AppFlowy Web Editor, run the following command:

npm install @appflowyinc/editor

# or

yarn add @appflowyinc/editor

# or

pnpm add @appflowyinc/editor

Note: This package requires these peer dependencies to be installed:

"peerDependencies": {
    "i18next": "^22.4.10",
    "i18next-resources-to-backend": "^1.2.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-i18next": "^14.1.0",
    "slate": "^0.112.0",
    "slate-history": "^0.110.3",
    "slate-react": "^0.112.0"
}

🚀 Quick Start

To use the AppFlowy Web Editor, import the Editor and EditorProvider components from the package and wrap your app

Note: Using the editor requires the EditorProvider component. Therefore, each Editor component needs to be wrapped by the corresponding EditorProvider

import { Editor, EditorProvider } from '@appflowyinc/editor';

const App = () => {
  return <EditorProvider>
    <Editor/>
  </EditorProvider>
};

export default App;

🎨 Custom Toolbar

The AppFlowy Web Editor provides a toolbar with various options for editing content. You can customize the toolbar by passing the ToolbarComponent prop to the Editor component.

import { Editor, EditorProvider, FixedToolbar } from '@appflowyinc/editor';

const App = () => {
  return <EditorProvider>
    <Editor ToolbarComponent={FixedToolbar}/>
  </EditorProvider>;
};

export default App;

📚 Apply Data

You can get editor from the useEditor hook and apply data to the editor.

import { Editor, EditorProvider, useEditor, NodeType } from '@appflowyinc/editor';

const App = () => {
  const editor = useEditor();

  useEffect(() => {
    editor.applyData({
      type: NodeType.Paragraph,
      delta: [
        {
          insert: 'Hello, World!',
        },
      ],
      children: []
    });

    // or apply markdown
    editor.applyMarkdown('# Hello, World!');
  }, []);

  return
  <Editor/>;
};

const Main = () => {
  return <EditorProvider>
    <App/>
  </EditorProvider>;
};

export default App;

💡 Theme Switching

The AppFlowy Web Editor supports theme switching between light and dark modes. You can customize the themes by passing the theme prop to the Editor component.

import { Editor, EditorProvider } from '@appflowyinc/editor';

const App = () => {
  return <EditorProvider>
    <Editor theme={'dark'}/>
  </EditorProvider>;
};

export default App;

🌍 Multi-language Usage

The AppFlowy Web Editor supports multiple languages. You can customize the language by passing the language prop to the Editor component.

import { Editor, EditorProvider } from '@appflowyinc/editor';
// Optionally, you can import the language resources from the package
import zh from '@appflowyinc/editor/locales/zh-CN.json';

import hostI18n from 'i18next';

const App = () => {
  return <I18nextProvider i18n={hostI18n}>
    <EditorProvider>
      <Editor locale={{
        // The language code.
        lang: 'zh-CN',
        // Optionally, you can pass the language resources or let it use the default resources
        resources: zh,
      }}/>
    </EditorProvider>
  </I18nextProvider>;
};

export default App;

Supported Languages

  • English(en)
  • Arabic(ar-SA)
  • Catalan(ca-ES)
  • Central Kurdish(ckb-KU)
  • Czech(cs-CZ)
  • German(de-DE)
  • Spanish(es-VE)
  • Basque(eu-ES)
  • Persian(fa)
  • French(fr-CA)
  • French(fr-FR)
  • Hebrew(he)
  • Hungarian(hu-HU)
  • Indonesian(id-ID)
  • Italian(it-IT)
  • Japanese(ja-JP)
  • Korean(ko-KR)
  • Polish(pl-PL)
  • Brazilian Portuguese(pt-BR)
  • Portuguese(pt-PT)
  • Russian(ru-RU)
  • Swedish(sv-SE)
  • Thai(th-TH)
  • Turkish(tr-TR)
  • Ukrainian(uk-UA)
  • Vietnamese(vi)
  • Vietnamese(vi-VN)
  • Simplified Chinese(zh-CN)
  • Traditional Chinese(zh-TW)

📖 API

Editor Props

PropTypeDefaultDescription
theme'light' \| 'dark''light'Editor theme
locale{ lang: string; resources?: Record<string, string> }-Editor language configuration
readOnlybooleanfalseWhether the editor is read-only
onChange(data: EditorData) => void-Callback when editor content changes
initialValueEditorData-Initial editor content
modalZIndexnumber50Editor modal z-index
ToolbarComponentFC-Custom toolbar component

EditorProvider Props

PropTypeDefaultDescription
childrenReactNode-The children components

EditorData

type EditorData = {
  type: NodeType;
  data: Record<string, any>;
  delta: DeltaOperation[];
  children: EditorData[];
};

NodeType

enum NodeType {
  Paragraph = 'paragraph',
  Heading = 'heading',
  NestedBlock = 'nested-block',
  Todo = 'todo_list',
  NumberedList = 'numbered_list',
  BulletedList = 'bulleted_list',
  Quote = 'quote',
}

Hooks

useEditor

Returns the editor instance with methods to control the editor.

const editor = useEditor();
MethodDescription
applyDataApply data to the editor
applyMarkdownApply markdown to the editor

🔨 Development

Guide

Development Mode

# Install dependencies

pnpm i

# Start development server

pnpm run dev

# Build library

pnpm run build

To run the demo locally:

pnpm install
pnpm run dev

Open http://localhost:5173/ with your browser to see the result. img.png

Switch between light and dark mode by clicking the theme switcher in the top right corner. img_1.png

📄 License

MIT License

[]: # (END) README.md
0.1.10

11 months ago

0.1.9

11 months ago

0.1.8

11 months ago

0.1.7

12 months ago

0.1.6

12 months ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.40

1 year ago

0.0.39

1 year ago

0.0.38

1 year ago

0.0.37

1 year ago

0.0.36

1 year ago

0.0.35

1 year ago

0.0.34

1 year ago

0.0.33

1 year ago

0.0.32

1 year ago

0.0.31

1 year ago

0.0.30

1 year ago

0.0.29

1 year ago

0.0.28

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.23

1 year ago

0.0.22

1 year ago

0.0.21

1 year ago

0.0.20

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago