|
@@ -3,7 +3,6 @@ import React, {
|
|
|
useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
|
|
useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
-
|
|
|
|
|
import type EventEmitter from 'events';
|
|
import type EventEmitter from 'events';
|
|
|
import nodePath from 'path';
|
|
import nodePath from 'path';
|
|
|
|
|
|
|
@@ -14,6 +13,7 @@ import { CodeMirrorEditorMain } from '@growi/editor/dist/client/components/CodeM
|
|
|
import { useCodeMirrorEditorIsolated } from '@growi/editor/dist/client/stores/codemirror-editor';
|
|
import { useCodeMirrorEditorIsolated } from '@growi/editor/dist/client/stores/codemirror-editor';
|
|
|
import { useResolvedThemeForEditor } from '@growi/editor/dist/client/stores/use-resolved-theme';
|
|
import { useResolvedThemeForEditor } from '@growi/editor/dist/client/stores/use-resolved-theme';
|
|
|
import { useRect } from '@growi/ui/dist/utils';
|
|
import { useRect } from '@growi/ui/dist/utils';
|
|
|
|
|
+import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
|
import detectIndent from 'detect-indent';
|
|
import detectIndent from 'detect-indent';
|
|
|
import { useTranslation } from 'next-i18next';
|
|
import { useTranslation } from 'next-i18next';
|
|
|
import { throttle, debounce } from 'throttle-debounce';
|
|
import { throttle, debounce } from 'throttle-debounce';
|
|
@@ -159,10 +159,6 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
setMarkdownToPreview(value);
|
|
setMarkdownToPreview(value);
|
|
|
})), []);
|
|
})), []);
|
|
|
|
|
|
|
|
- const markdownChangedHandler = useCallback((value: string) => {
|
|
|
|
|
- setMarkdownPreviewWithDebounce(value);
|
|
|
|
|
- }, [setMarkdownPreviewWithDebounce]);
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.MAIN, previewRef);
|
|
const { scrollEditorHandler, scrollPreviewHandler } = useScrollSync(GlobalCodeMirrorEditorKey.MAIN, previewRef);
|
|
|
|
|
|
|
@@ -267,6 +263,14 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
});
|
|
});
|
|
|
}, [codeMirrorEditor, pageId]);
|
|
}, [codeMirrorEditor, pageId]);
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const cmProps = useMemo<ReactCodeMirrorProps>(() => ({
|
|
|
|
|
+ onChange: (value: string) => {
|
|
|
|
|
+ setMarkdownPreviewWithDebounce(value);
|
|
|
|
|
+ },
|
|
|
|
|
+ }), [setMarkdownPreviewWithDebounce]);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// set handler to save and return to View
|
|
// set handler to save and return to View
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
globalEmitter.on('saveAndReturnToView', saveAndReturnToViewHandler);
|
|
globalEmitter.on('saveAndReturnToView', saveAndReturnToViewHandler);
|
|
@@ -363,7 +367,6 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
<div className="page-editor-editor-container flex-expand-vert border-end">
|
|
<div className="page-editor-editor-container flex-expand-vert border-end">
|
|
|
<CodeMirrorEditorMain
|
|
<CodeMirrorEditorMain
|
|
|
isEditorMode={editorMode === EditorMode.Editor}
|
|
isEditorMode={editorMode === EditorMode.Editor}
|
|
|
- onChange={markdownChangedHandler}
|
|
|
|
|
onSave={saveWithShortcut}
|
|
onSave={saveWithShortcut}
|
|
|
onUpload={uploadHandler}
|
|
onUpload={uploadHandler}
|
|
|
acceptedUploadFileType={acceptedUploadFileType}
|
|
acceptedUploadFileType={acceptedUploadFileType}
|
|
@@ -374,6 +377,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
initialValue={initialValue}
|
|
initialValue={initialValue}
|
|
|
editorSettings={editorSettings}
|
|
editorSettings={editorSettings}
|
|
|
onEditorsUpdated={onEditorsUpdated}
|
|
onEditorsUpdated={onEditorsUpdated}
|
|
|
|
|
+ cmProps={cmProps}
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|
|
|
<div
|
|
<div
|