|
@@ -8,6 +8,7 @@ import nodePath from 'path';
|
|
|
|
|
|
|
|
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, useCodeMirrorEditor } 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';
|
|
@@ -51,10 +52,13 @@ import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
|
|
|
|
|
// import { ConflictDiffModal } from './PageEditor/ConflictDiffModal';
|
|
// import { ConflictDiffModal } from './PageEditor/ConflictDiffModal';
|
|
|
-import { ConflictDiffModal } from './PageEditor/ConflictDiffModal';
|
|
|
|
|
-import Editor from './PageEditor/Editor';
|
|
|
|
|
-import Preview from './PageEditor/Preview';
|
|
|
|
|
-import scrollSyncHelper from './PageEditor/ScrollSyncHelper';
|
|
|
|
|
|
|
+// import { ConflictDiffModal } from './ConflictDiffModal';
|
|
|
|
|
+// import Editor from './Editor';
|
|
|
|
|
+import Preview from './Preview';
|
|
|
|
|
+import scrollSyncHelper from './ScrollSyncHelper';
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import '@growi/editor/dist/style.css';
|
|
|
|
|
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:PageEditor');
|
|
const logger = loggerFactory('growi:PageEditor');
|
|
@@ -71,11 +75,20 @@ let lastScrolledDateWithCursor: Date | null = null;
|
|
|
let isOriginOfScrollSyncEditor = false;
|
|
let isOriginOfScrollSyncEditor = false;
|
|
|
let isOriginOfScrollSyncPreview = false;
|
|
let isOriginOfScrollSyncPreview = false;
|
|
|
|
|
|
|
|
-const PageEditor = React.memo((): JSX.Element => {
|
|
|
|
|
|
|
+
|
|
|
|
|
+type Props = {
|
|
|
|
|
+ visibility?: boolean,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
|
|
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
+ const editorRef = useRef<IEditorMethods>(null);
|
|
|
|
|
+ const previewRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
+ const codeMirrorEditorContainerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
+
|
|
|
const { data: isNotFound } = useIsNotFound();
|
|
const { data: isNotFound } = useIsNotFound();
|
|
|
const { data: pageId, mutate: mutateCurrentPageId } = useCurrentPageId();
|
|
const { data: pageId, mutate: mutateCurrentPageId } = useCurrentPageId();
|
|
|
const { data: currentPagePath } = useCurrentPagePath();
|
|
const { data: currentPagePath } = useCurrentPagePath();
|
|
@@ -103,6 +116,15 @@ const PageEditor = React.memo((): JSX.Element => {
|
|
|
const { mutate: mutateRemoteRevisionLastUpdatedAt } = useRemoteRevisionLastUpdatedAt();
|
|
const { mutate: mutateRemoteRevisionLastUpdatedAt } = useRemoteRevisionLastUpdatedAt();
|
|
|
const { mutate: mutateRemoteRevisionLastUpdateUser } = useRemoteRevisionLastUpdateUser();
|
|
const { mutate: mutateRemoteRevisionLastUpdateUser } = useRemoteRevisionLastUpdateUser();
|
|
|
|
|
|
|
|
|
|
+ const { setContainer } = useCodeMirrorEditor({
|
|
|
|
|
+ container: codeMirrorEditorContainerRef.current,
|
|
|
|
|
+ });
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (codeMirrorEditorContainerRef.current != null) {
|
|
|
|
|
+ setContainer(codeMirrorEditorContainerRef.current);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [setContainer]);
|
|
|
|
|
+
|
|
|
const { data: rendererOptions } = usePreviewOptions();
|
|
const { data: rendererOptions } = usePreviewOptions();
|
|
|
const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
|
|
const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
|
|
|
const saveOrUpdate = useSaveOrUpdate();
|
|
const saveOrUpdate = useSaveOrUpdate();
|
|
@@ -142,9 +164,6 @@ const PageEditor = React.memo((): JSX.Element => {
|
|
|
const { mutate: mutateIsConflict } = useIsConflict();
|
|
const { mutate: mutateIsConflict } = useIsConflict();
|
|
|
|
|
|
|
|
|
|
|
|
|
- const editorRef = useRef<IEditorMethods>(null);
|
|
|
|
|
- const previewRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
-
|
|
|
|
|
const checkIsConflict = useCallback((data) => {
|
|
const checkIsConflict = useCallback((data) => {
|
|
|
const { s2cMessagePageUpdated } = data;
|
|
const { s2cMessagePageUpdated } = data;
|
|
|
|
|
|
|
@@ -554,9 +573,9 @@ const PageEditor = React.memo((): JSX.Element => {
|
|
|
const isUploadable = isUploadableImage || isUploadableFile;
|
|
const isUploadable = isUploadableImage || isUploadableFile;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div className="d-flex flex-wrap">
|
|
|
|
|
|
|
+ <div data-testid="page-editor" id="page-editor" className={`d-flex flex-grow-1 overflow-auto ${props.visibility ? '' : 'd-none'}`}>
|
|
|
<div className="page-editor-editor-container flex-grow-1 flex-basis-0 mw-0">
|
|
<div className="page-editor-editor-container flex-grow-1 flex-basis-0 mw-0">
|
|
|
- <Editor
|
|
|
|
|
|
|
+ {/* <Editor
|
|
|
ref={editorRef}
|
|
ref={editorRef}
|
|
|
value={initialValue}
|
|
value={initialValue}
|
|
|
isUploadable={isUploadable}
|
|
isUploadable={isUploadable}
|
|
@@ -567,9 +586,10 @@ const PageEditor = React.memo((): JSX.Element => {
|
|
|
onChange={markdownChangedHandler}
|
|
onChange={markdownChangedHandler}
|
|
|
onUpload={uploadHandler}
|
|
onUpload={uploadHandler}
|
|
|
onSave={saveWithShortcut}
|
|
onSave={saveWithShortcut}
|
|
|
- />
|
|
|
|
|
|
|
+ /> */}
|
|
|
|
|
+ <CodeMirrorEditorContainer ref={codeMirrorEditorContainerRef} />
|
|
|
</div>
|
|
</div>
|
|
|
- <div className="d-none d-lg-block page-editor-preview-container flex-grow-1 flex-basis-0 mw-0">
|
|
|
|
|
|
|
+ <div className="d-none d-lg-flex page-editor-preview-container justify-content-center flex-grow-1 flex-basis-0 mw-0">
|
|
|
<Preview
|
|
<Preview
|
|
|
ref={previewRef}
|
|
ref={previewRef}
|
|
|
rendererOptions={rendererOptions}
|
|
rendererOptions={rendererOptions}
|
|
@@ -578,6 +598,7 @@ const PageEditor = React.memo((): JSX.Element => {
|
|
|
onScroll={offset => scrollEditorByPreviewScrollWithThrottle(offset)}
|
|
onScroll={offset => scrollEditorByPreviewScrollWithThrottle(offset)}
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ {/*
|
|
|
<ConflictDiffModal
|
|
<ConflictDiffModal
|
|
|
isOpen={conflictDiffModalStatus?.isOpened}
|
|
isOpen={conflictDiffModalStatus?.isOpened}
|
|
|
onClose={() => closeConflictDiffModal()}
|
|
onClose={() => closeConflictDiffModal()}
|
|
@@ -585,9 +606,8 @@ const PageEditor = React.memo((): JSX.Element => {
|
|
|
optionsToSave={optionsToSave}
|
|
optionsToSave={optionsToSave}
|
|
|
afterResolvedHandler={afterResolvedHandler}
|
|
afterResolvedHandler={afterResolvedHandler}
|
|
|
/>
|
|
/>
|
|
|
|
|
+ */}
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
PageEditor.displayName = 'PageEditor';
|
|
PageEditor.displayName = 'PageEditor';
|
|
|
-
|
|
|
|
|
-export default PageEditor;
|
|
|