Spaces:
Sleeping
Sleeping
Download packages/react-text/src/plugins/with-text.ts from manhteky123/mindmap: direct link, hf CLI and curl.
- Browser
- Download file 730 Bytes
-
https://huggingface.co/spaces/manhteky123/mindmap/resolve/main/packages/react-text/src/plugins/with-text.ts
- Command line
-
hf download hf://spaces/manhteky123/mindmap/packages/react-text/src/plugins/with-text.ts
-
curl -L -o with-text.ts https://huggingface.co/spaces/manhteky123/mindmap/resolve/main/packages/react-text/src/plugins/with-text.ts
730 Bytes
| import { ReactEditor } from 'slate-react'; | |
| export const withText = <T extends ReactEditor>(editor: T) => { | |
| const e = editor as T; | |
| const { insertData } = e; | |
| e.insertBreak = () => { | |
| editor.insertText('\n'); | |
| }; | |
| e.insertSoftBreak = () => { | |
| editor.insertText('\n'); | |
| }; | |
| e.insertData = (data: DataTransfer) => { | |
| let text = data.getData('text/plain'); | |
| const plaitData = data.getData(`application/x-slate-fragment`); | |
| if (!plaitData && text) { | |
| if (text.endsWith('\n')) { | |
| text = text.substring(0, text.length - 1); | |
| } | |
| text = text.trim().replace(/\t+/g, ' '); | |
| e.insertText(text); | |
| return; | |
| } | |
| insertData(data); | |
| }; | |
| return e; | |
| }; | |