|
1 | | -import { createContext, useContext, useEffect, useMemo, useState } from "react"; |
| 1 | +import { |
| 2 | + createContext, |
| 3 | + useCallback, |
| 4 | + useContext, |
| 5 | + useEffect, |
| 6 | + useMemo, |
| 7 | + useState, |
| 8 | +} from "react"; |
2 | 9 | import { useAppSelector } from "../../store/store"; |
3 | 10 | import { createWebsocketConnection } from "./utils/createWebsocketConnection"; |
4 | 11 | import ReviewTaskApi from "../../api/reviewTaskApi"; |
@@ -27,14 +34,15 @@ interface ContextType { |
27 | 34 |
|
28 | 35 | export const VisualEditorContext = createContext<ContextType>({}); |
29 | 36 |
|
| 37 | +const editorConfig = new EditorConfig(); |
| 38 | + |
30 | 39 | interface VisualEditorProviderProps { |
31 | 40 | data_hash: string; |
32 | 41 | children: React.ReactNode; |
33 | 42 | source?: string; |
34 | 43 | } |
35 | 44 |
|
36 | 45 | export const VisualEditorProvider = (props: VisualEditorProviderProps) => { |
37 | | - const editorConfig = new EditorConfig(); |
38 | 46 | const { machineService, reportModel, reviewTaskType } = useContext( |
39 | 47 | ReviewTaskMachineContext |
40 | 48 | ); |
@@ -101,26 +109,29 @@ export const VisualEditorProvider = (props: VisualEditorProviderProps) => { |
101 | 109 | }; |
102 | 110 | }, [enableCollaborativeEdit, props.data_hash, websocketUrl]); |
103 | 111 |
|
104 | | - const extensions = useMemo( |
| 112 | + const getExtensions = useCallback( |
105 | 113 | () => |
106 | 114 | editorConfig.getExtensions( |
107 | 115 | reviewTaskType, |
108 | 116 | websocketProvider, |
109 | 117 | enableEditorAnnotations |
110 | 118 | ), |
111 | | - [websocketProvider, reviewTaskType] |
| 119 | + [reviewTaskType, websocketProvider, enableEditorAnnotations] |
112 | 120 | ); |
113 | 121 |
|
114 | | - const editorConfiguration = { |
115 | | - readonly, |
116 | | - extensions, |
117 | | - isCollaborative, |
118 | | - core: { excludeExtensions: ["history"] }, |
119 | | - stringHandler: "html", |
120 | | - content: isCollaborative |
121 | | - ? undefined |
122 | | - : (editorContentObject as RemirrorContentType), |
123 | | - }; |
| 122 | + const editorConfiguration = useMemo( |
| 123 | + () => ({ |
| 124 | + readonly, |
| 125 | + extensions: getExtensions, |
| 126 | + isCollaborative, |
| 127 | + core: { excludeExtensions: ["history"] }, |
| 128 | + stringHandler: "html", |
| 129 | + content: isCollaborative |
| 130 | + ? undefined |
| 131 | + : (editorContentObject as RemirrorContentType), |
| 132 | + }), |
| 133 | + [readonly, getExtensions, isCollaborative, editorContentObject] |
| 134 | + ); |
124 | 135 |
|
125 | 136 | const value = useMemo( |
126 | 137 | () => ({ |
|
0 commit comments