aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/ProseMirrorEditorView.tsx
diff options
context:
space:
mode:
authorMohammad Amoush <47069173+mamoush34@users.noreply.github.com>2020-02-08 17:03:12 -0500
committerMohammad Amoush <47069173+mamoush34@users.noreply.github.com>2020-02-08 17:03:12 -0500
commitf9855e8d1ec83405ae3cc7d0113b46de63fc0848 (patch)
treebf4be61a021e59b771c1cd5958fd9fd43cac8693 /src/client/util/ProseMirrorEditorView.tsx
parent87f5f043388b591c52e96a795fa461a79770550d (diff)
parent1b046f76cf39f1f6cb1875aa84b45db74b6d994e (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into webcam_mohammad
Diffstat (limited to 'src/client/util/ProseMirrorEditorView.tsx')
-rw-r--r--src/client/util/ProseMirrorEditorView.tsx74
1 files changed, 0 insertions, 74 deletions
diff --git a/src/client/util/ProseMirrorEditorView.tsx b/src/client/util/ProseMirrorEditorView.tsx
deleted file mode 100644
index b42adfbb4..000000000
--- a/src/client/util/ProseMirrorEditorView.tsx
+++ /dev/null
@@ -1,74 +0,0 @@
-import React from "react";
-import { EditorView } from "prosemirror-view";
-import { EditorState } from "prosemirror-state";
-
-export interface ProseMirrorEditorViewProps {
- /* EditorState instance to use. */
- editorState: EditorState;
- /* Called when EditorView produces new EditorState. */
- onEditorState: (editorState: EditorState) => any;
-}
-
-/**
- * This wraps ProseMirror's EditorView into React component.
- * This code was found on https://discuss.prosemirror.net/t/using-with-react/904
- */
-export class ProseMirrorEditorView extends React.Component<ProseMirrorEditorViewProps> {
-
- private _editorView?: EditorView;
-
- _createEditorView = (element: HTMLDivElement | null) => {
- if (element !== null) {
- this._editorView = new EditorView(element, {
- state: this.props.editorState,
- dispatchTransaction: this.dispatchTransaction,
- });
- }
- }
-
- dispatchTransaction = (tx: any) => {
- // In case EditorView makes any modification to a state we funnel those
- // modifications up to the parent and apply to the EditorView itself.
- const editorState = this.props.editorState.apply(tx);
- if (this._editorView) {
- this._editorView.updateState(editorState);
- }
- this.props.onEditorState(editorState);
- }
-
- focus() {
- if (this._editorView) {
- this._editorView.focus();
- }
- }
-
- componentWillReceiveProps(nextProps: { editorState: EditorState<any>; }) {
- // In case we receive new EditorState through props — we apply it to the
- // EditorView instance.
- if (this._editorView) {
- if (nextProps.editorState !== this.props.editorState) {
- this._editorView.updateState(nextProps.editorState);
- }
- }
- }
-
- componentWillUnmount() {
- if (this._editorView) {
- this._editorView.destroy();
- }
- }
-
- shouldComponentUpdate() {
- // Note that EditorView manages its DOM itself so we'd ratrher don't mess
- // with it.
- return false;
- }
-
- render() {
- // Render just an empty div which is then used as a container for an
- // EditorView instance.
- return (
- <div ref={this._createEditorView} />
- );
- }
-} \ No newline at end of file