|
@@ -5,11 +5,9 @@ import React, {
|
|
|
import EventEmitter from 'events';
|
|
import EventEmitter from 'events';
|
|
|
import nodePath from 'path';
|
|
import nodePath from 'path';
|
|
|
|
|
|
|
|
-import { keymap } from '@codemirror/view';
|
|
|
|
|
import type { IPageHasId } from '@growi/core';
|
|
import type { IPageHasId } from '@growi/core';
|
|
|
import { pathUtils } from '@growi/core/dist/utils';
|
|
import { pathUtils } from '@growi/core/dist/utils';
|
|
|
-import { CodeMirrorEditorContainer, useCodeMirrorEditorMain } from '@growi/editor';
|
|
|
|
|
-import { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
|
|
|
|
|
+import { CodeMirrorEditorMain, GlobalCodeMirrorEditorKey, useCodeMirrorEditorIsolated } from '@growi/editor';
|
|
|
import detectIndent from 'detect-indent';
|
|
import detectIndent from 'detect-indent';
|
|
|
import { useTranslation } from 'next-i18next';
|
|
import { useTranslation } from 'next-i18next';
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
@@ -166,18 +164,13 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
mutateIsEnabledUnsavedWarning(value !== initialValueRef.current);
|
|
mutateIsEnabledUnsavedWarning(value !== initialValueRef.current);
|
|
|
})), [mutateIsEnabledUnsavedWarning]);
|
|
})), [mutateIsEnabledUnsavedWarning]);
|
|
|
|
|
|
|
|
- const useCodeMirrorEditorMainProps = useMemo<ReactCodeMirrorProps>(() => {
|
|
|
|
|
- return {
|
|
|
|
|
- onChange: (value) => {
|
|
|
|
|
- setMarkdownPreviewWithDebounce(value);
|
|
|
|
|
- mutateIsEnabledUnsavedWarningWithDebounce(value);
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const markdownChangedHandler = useCallback((value: string) => {
|
|
|
|
|
+ setMarkdownPreviewWithDebounce(value);
|
|
|
|
|
+ mutateIsEnabledUnsavedWarningWithDebounce(value);
|
|
|
}, [mutateIsEnabledUnsavedWarningWithDebounce, setMarkdownPreviewWithDebounce]);
|
|
}, [mutateIsEnabledUnsavedWarningWithDebounce, setMarkdownPreviewWithDebounce]);
|
|
|
- const { data: codeMirrorEditor } = useCodeMirrorEditorMain(
|
|
|
|
|
- codeMirrorEditorContainerRef.current,
|
|
|
|
|
- useCodeMirrorEditorMainProps,
|
|
|
|
|
- );
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
|
|
|
|
|
|
|
|
|
|
|
|
|
const checkIsConflict = useCallback((data) => {
|
|
const checkIsConflict = useCallback((data) => {
|
|
@@ -514,25 +507,6 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
};
|
|
};
|
|
|
}, [saveAndReturnToViewHandler]);
|
|
}, [saveAndReturnToViewHandler]);
|
|
|
|
|
|
|
|
- // set handler to save with shortcut key
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- const extension = keymap.of([
|
|
|
|
|
- {
|
|
|
|
|
- key: 'Mod-s',
|
|
|
|
|
- preventDefault: true,
|
|
|
|
|
- run: () => {
|
|
|
|
|
- saveWithShortcut();
|
|
|
|
|
- return true;
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
-
|
|
|
|
|
- const cleanupFunction = codeMirrorEditor?.appendExtension(extension);
|
|
|
|
|
-
|
|
|
|
|
- return cleanupFunction;
|
|
|
|
|
-
|
|
|
|
|
- }, [codeMirrorEditor, saveWithShortcut]);
|
|
|
|
|
-
|
|
|
|
|
// set handler to focus
|
|
// set handler to focus
|
|
|
useLayoutEffect(() => {
|
|
useLayoutEffect(() => {
|
|
|
if (editorMode === EditorMode.Editor) {
|
|
if (editorMode === EditorMode.Editor) {
|
|
@@ -595,7 +569,10 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
onUpload={uploadHandler}
|
|
onUpload={uploadHandler}
|
|
|
onSave={saveWithShortcut}
|
|
onSave={saveWithShortcut}
|
|
|
/> */}
|
|
/> */}
|
|
|
- <CodeMirrorEditorContainer ref={codeMirrorEditorContainerRef} />
|
|
|
|
|
|
|
+ <CodeMirrorEditorMain
|
|
|
|
|
+ onChange={markdownChangedHandler}
|
|
|
|
|
+ onSave={saveWithShortcut}
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
<div className="page-editor-preview-container flex-expand-vert d-none d-lg-flex">
|
|
<div className="page-editor-preview-container flex-expand-vert d-none d-lg-flex">
|
|
|
<Preview
|
|
<Preview
|