0.2.0-beta.9 • Published 2 months ago

@train860/tide v0.2.0-beta.9

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

@train860/tide

介绍

本包提供了 React 易于使用的编辑器组件。

安装

如果你不希望启用代码块的语法高亮功能,可以不安装 highlight.js

npm install --save @train860/tide @train860/tide-starter-kit highlight.js
# or
yarn add @train860/tide @train860/tide-starter-kit highlight.js
# or
pnpm add @train860/tide @train860/tide-starter-kit highlight.js

使用

import React, { useState } from 'react';
import { EditorRender, useEditor } from '@train860/tide';
import { StarterKit } from '@train860/tide-starter-kit';

import '@train860/tide/dist/style.css';
import 'highlight.js/styles/default.css';

function App() {
  const editor = useEditor({
    extensions: [StarterKit],
    content: '# Hello World!',
    onChange: (doc) => console.log('onChange', doc),
  });

  // Update editor content
  // editor.setContent('Changed content');

  return <EditorRender editor={editor} />;
}

如需自定义样式,可参考 @train860/tide-theme/dist/variable.less 中的 CSS Variables 进行覆盖。

配置

useEditor Options

配置说明类型默认值
content内容HTMLContent \| JSONContent \| JSONContent[] \| null-
autofocus是否自动聚焦'start' \| 'end' \| 'all' \| number \| boolean \| nullfalse
editable是否允许编辑booleantrue
fullscreen是否全屏模式booleanfalse
readOnlyEmptyView只读模式下无内容时的视图ReactNodenull
readOnlyShowMenu只读模式下是否显示菜单栏booleanfalse
menuEnableUndoRedo菜单栏是否启用撤销重做booleantrue
menuEnableFullscreen菜单栏是否启用全屏booleantrue
onFullscreenChange全屏状态变更时的回调函数(fullscreen: boolean) => void-
onReady初始化完成后的回调函数(editor: TideEditor) => void-
onChange内容变更时的回调函数(doc: JSONContent, editor: TideEditor) => void-

更多配置可参考 TideEditorOptions 接口定义。

EditorRenderProps

属性说明类型默认值
className容器自定义 classNamestring-
style容器自定义 styleCSSProperties-
menuClassName菜单栏自定义 classNamestring-
menuStyle菜单栏自定义 styleCSSProperties-
contentClassName内容区自定义 classNamestring-
contentStyle内容区自定义 styleCSSProperties-