tiptap: remove unused code

This commit is contained in:
fantasticit 2022-06-03 16:35:31 +08:00
parent 4966dfc509
commit a1f519d8ca
2 changed files with 0 additions and 47 deletions

View File

@ -1,5 +0,0 @@
import { EditorContent, NodeViewContent, NodeViewWrapper } from '@tiptap/react';
import { Editor, useEditor } from './useEditor';
export { Editor, EditorContent, NodeViewContent, NodeViewWrapper, useEditor };

View File

@ -1,42 +0,0 @@
import { EditorOptions } from '@tiptap/core';
import { Editor as BuiltInEditor } from '@tiptap/react';
import { EventEmitter } from 'helpers/event-emitter';
import { DependencyList, useEffect, useState } from 'react';
function useForceUpdate() {
const [, setValue] = useState(0);
return () => setValue((value) => value + 1);
}
export class Editor extends BuiltInEditor {
public eventEmitter: EventEmitter = new EventEmitter();
}
export const useEditor = (options: Partial<EditorOptions> = {}, deps: DependencyList = []) => {
const [editor, setEditor] = useState<Editor | null>(null);
const forceUpdate = useForceUpdate();
useEffect(() => {
const instance = new Editor(options);
setEditor(instance);
if (!options.editable) {
instance.on('transaction', () => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
forceUpdate();
});
});
});
}
return () => {
instance.destroy();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);
return editor;
};