认识
2024年07月05日
一、认识
基于 @tiptap/react
封装的 richTextEditor
富文本组件。架构如下:
|-- menu
|-- bubbleMenuChildren.tsx
|-- customMenuBar.tsx
|-- floatingMenuChildren.tsx
|-- menuMap.tsx
|-- 各种菜单
|-- extensions
|-- extensionList.ts
|-- 各种插件
|-- richTextEditor.tsx
|-- richTextEditor.scss
二、依赖
{
"name": "react",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@rc-component/color-picker": "^1.4.1",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-character-count": "^2.4.0",
"@tiptap/extension-code-block": "^2.4.0",
"@tiptap/extension-color": "^2.4.0",
"@tiptap/extension-document": "^2.4.0",
"@tiptap/extension-floating-menu": "^2.4.0",
"@tiptap/extension-highlight": "^2.4.0",
"@tiptap/extension-image": "^2.4.0",
"@tiptap/extension-link": "^2.4.0",
"@tiptap/extension-list-item": "^2.4.0",
"@tiptap/extension-placeholder": "^2.4.0",
"@tiptap/extension-table": "^2.4.0",
"@tiptap/extension-table-cell": "^2.4.0",
"@tiptap/extension-table-header": "^2.4.0",
"@tiptap/extension-table-row": "^2.4.0",
"@tiptap/extension-text": "^2.4.0",
"@tiptap/extension-text-align": "^2.4.0",
"@tiptap/extension-text-style": "^2.4.0",
"@tiptap/extension-underline": "^2.4.0",
"@tiptap/extension-youtube": "^2.4.0",
"@tiptap/react": "^2.4.0",
"@tiptap/starter-kit": "^2.4.0",
"react": "^18.2.0",
"react-color": "^2.19.3",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.12",
"redux": "^5.0.1"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"sass": "^1.77.4",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
三、测试
import { useRef } from "react";
import RichTextEditor from "./components/richTextEditor/richTextEditor";
function App() {
const contentRef = useRef({
htmlContent: "",
textContent: "",
});
const onUpdate = (htmlContent: string, textContent: string) => {
contentRef.current.htmlContent = htmlContent;
contentRef.current.textContent = textContent;
console.log("contentRef.current: ", contentRef.current);
};
return (
<div className="app">
<RichTextEditor
content={contentRef.current.htmlContent}
onUpdate={onUpdate}
/>
</div>
);
}
export default App;