PageEditor.tsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. import React, {
  2. useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
  3. } from 'react';
  4. import EventEmitter from 'events';
  5. import nodePath from 'path';
  6. import type { IPageHasId } from '@growi/core';
  7. import { useGlobalSocket } from '@growi/core/dist/swr';
  8. import { pathUtils } from '@growi/core/dist/utils';
  9. import {
  10. CodeMirrorEditorMain, GlobalCodeMirrorEditorKey, AcceptedUploadFileType,
  11. useCodeMirrorEditorIsolated, useResolvedThemeForEditor,
  12. } from '@growi/editor';
  13. import detectIndent from 'detect-indent';
  14. import { useTranslation } from 'next-i18next';
  15. import { useRouter } from 'next/router';
  16. import { throttle, debounce } from 'throttle-debounce';
  17. import { useShouldExpandContent } from '~/client/services/layout';
  18. import { useUpdateStateAfterSave, useSaveOrUpdate } from '~/client/services/page-operation';
  19. import { apiGet, apiPostForm } from '~/client/util/apiv1-client';
  20. import { toastError, toastSuccess } from '~/client/util/toastr';
  21. import { OptionsToSave } from '~/interfaces/page-operation';
  22. import { SocketEventName } from '~/interfaces/websocket';
  23. import {
  24. useDefaultIndentSize, useCurrentUser,
  25. useCurrentPathname, useIsEnabledAttachTitleHeader,
  26. useIsEditable, useIsUploadAllFileAllowed, useIsUploadEnabled, useIsIndentSizeForced,
  27. } from '~/stores/context';
  28. import {
  29. useCurrentIndentSize, useIsSlackEnabled, usePageTagsForEditors,
  30. useIsEnabledUnsavedWarning,
  31. useIsConflict,
  32. useEditingMarkdown,
  33. useWaitingSaveProcessing,
  34. } from '~/stores/editor';
  35. import { useConflictDiffModal } from '~/stores/modal';
  36. import {
  37. useCurrentPagePath, useSWRMUTxCurrentPage, useSWRxCurrentPage, useSWRxTagsInfo, useCurrentPageId, useIsNotFound, useIsLatestRevision, useTemplateBodyData,
  38. } from '~/stores/page';
  39. import { mutatePageTree } from '~/stores/page-listing';
  40. import {
  41. useRemoteRevisionId,
  42. useRemoteRevisionBody,
  43. useRemoteRevisionLastUpdatedAt,
  44. useRemoteRevisionLastUpdateUser,
  45. } from '~/stores/remote-latest-page';
  46. import { usePreviewOptions } from '~/stores/renderer';
  47. import {
  48. EditorMode,
  49. useEditorMode, useSelectedGrant,
  50. } from '~/stores/ui';
  51. import { useNextThemes } from '~/stores/use-next-themes';
  52. import loggerFactory from '~/utils/logger';
  53. // import { ConflictDiffModal } from './PageEditor/ConflictDiffModal';
  54. // import { ConflictDiffModal } from './ConflictDiffModal';
  55. // import Editor from './Editor';
  56. import EditorNavbarBottom from './EditorNavbarBottom';
  57. import Preview from './Preview';
  58. import scrollSyncHelper from './ScrollSyncHelper';
  59. import '@growi/editor/dist/style.css';
  60. const logger = loggerFactory('growi:PageEditor');
  61. declare global {
  62. // eslint-disable-next-line vars-on-top, no-var
  63. var globalEmitter: EventEmitter;
  64. }
  65. // for scrolling
  66. let lastScrolledDateWithCursor: Date | null = null;
  67. let isOriginOfScrollSyncEditor = false;
  68. let isOriginOfScrollSyncPreview = false;
  69. type Props = {
  70. visibility?: boolean,
  71. }
  72. export const PageEditor = React.memo((props: Props): JSX.Element => {
  73. const { t } = useTranslation();
  74. const router = useRouter();
  75. const previewRef = useRef<HTMLDivElement>(null);
  76. const codeMirrorEditorContainerRef = useRef<HTMLDivElement>(null);
  77. const { data: isNotFound } = useIsNotFound();
  78. const { data: pageId, mutate: mutateCurrentPageId } = useCurrentPageId();
  79. const { data: currentPagePath } = useCurrentPagePath();
  80. const { data: currentPathname } = useCurrentPathname();
  81. const { data: currentPage } = useSWRxCurrentPage();
  82. const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
  83. const { data: grantData } = useSelectedGrant();
  84. const { sync: syncTagsInfoForEditor } = usePageTagsForEditors(pageId);
  85. const { mutate: mutateTagsInfo } = useSWRxTagsInfo(pageId);
  86. const { data: editingMarkdown, mutate: mutateEditingMarkdown } = useEditingMarkdown();
  87. const { data: isEnabledAttachTitleHeader } = useIsEnabledAttachTitleHeader();
  88. const { data: templateBodyData } = useTemplateBodyData();
  89. const { data: isEditable } = useIsEditable();
  90. const { mutate: mutateWaitingSaveProcessing } = useWaitingSaveProcessing();
  91. const { data: editorMode, mutate: mutateEditorMode } = useEditorMode();
  92. const { data: isSlackEnabled } = useIsSlackEnabled();
  93. const { data: isIndentSizeForced } = useIsIndentSizeForced();
  94. const { data: currentIndentSize, mutate: mutateCurrentIndentSize } = useCurrentIndentSize();
  95. const { data: defaultIndentSize } = useDefaultIndentSize();
  96. const { data: isUploadAllFileAllowed } = useIsUploadAllFileAllowed();
  97. const { data: isUploadEnabled } = useIsUploadEnabled();
  98. const { data: conflictDiffModalStatus, close: closeConflictDiffModal } = useConflictDiffModal();
  99. const { mutate: mutateIsLatestRevision } = useIsLatestRevision();
  100. const { mutate: mutateRemotePageId } = useRemoteRevisionId();
  101. const { mutate: mutateRemoteRevisionId } = useRemoteRevisionBody();
  102. const { mutate: mutateRemoteRevisionLastUpdatedAt } = useRemoteRevisionLastUpdatedAt();
  103. const { mutate: mutateRemoteRevisionLastUpdateUser } = useRemoteRevisionLastUpdateUser();
  104. const { data: user } = useCurrentUser();
  105. const { data: socket } = useGlobalSocket();
  106. const { data: rendererOptions } = usePreviewOptions();
  107. const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
  108. const { mutate: mutateIsConflict } = useIsConflict();
  109. const { mutate: mutateResolvedTheme } = useResolvedThemeForEditor();
  110. const shouldExpandContent = useShouldExpandContent(currentPage);
  111. const saveOrUpdate = useSaveOrUpdate();
  112. const updateStateAfterSave = useUpdateStateAfterSave(pageId, { supressEditingMarkdownMutation: true });
  113. const { resolvedTheme } = useNextThemes();
  114. mutateResolvedTheme(resolvedTheme);
  115. // TODO: remove workaround
  116. // for https://redmine.weseek.co.jp/issues/125923
  117. const [createdPageRevisionIdWithAttachment, setCreatedPageRevisionIdWithAttachment] = useState();
  118. // TODO: remove workaround
  119. // for https://redmine.weseek.co.jp/issues/125923
  120. const currentRevisionId = currentPage?.revision?._id ?? createdPageRevisionIdWithAttachment;
  121. const initialValueRef = useRef('');
  122. const initialValue = useMemo(() => {
  123. if (!isNotFound) {
  124. return editingMarkdown ?? '';
  125. }
  126. let initialValue = '';
  127. if (isEnabledAttachTitleHeader && currentPathname != null) {
  128. const pageTitle = nodePath.basename(currentPathname);
  129. initialValue += `${pathUtils.attachTitleHeader(pageTitle)}\n`;
  130. }
  131. if (templateBodyData != null) {
  132. initialValue += `${templateBodyData}\n`;
  133. }
  134. return initialValue;
  135. }, [isNotFound, currentPathname, editingMarkdown, isEnabledAttachTitleHeader, templateBodyData]);
  136. useEffect(() => {
  137. // set to ref
  138. initialValueRef.current = initialValue;
  139. }, [initialValue]);
  140. const [markdownToPreview, setMarkdownToPreview] = useState<string>(initialValue);
  141. const setMarkdownPreviewWithDebounce = useMemo(() => debounce(100, throttle(150, (value: string) => {
  142. setMarkdownToPreview(value);
  143. })), []);
  144. // const mutateIsEnabledUnsavedWarningWithDebounce = useMemo(() => debounce(600, throttle(900, (value: string) => {
  145. // // Displays an unsaved warning alert
  146. // mutateIsEnabledUnsavedWarning(value !== initialValueRef.current);
  147. // })), [mutateIsEnabledUnsavedWarning]);
  148. const markdownChangedHandler = useCallback((value: string) => {
  149. setMarkdownPreviewWithDebounce(value);
  150. // mutateIsEnabledUnsavedWarningWithDebounce(value);
  151. // }, [mutateIsEnabledUnsavedWarningWithDebounce, setMarkdownPreviewWithDebounce]);
  152. }, [setMarkdownPreviewWithDebounce]);
  153. const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
  154. const checkIsConflict = useCallback((data) => {
  155. const { s2cMessagePageUpdated } = data;
  156. const isConflict = markdownToPreview !== s2cMessagePageUpdated.revisionBody;
  157. mutateIsConflict(isConflict);
  158. }, [markdownToPreview, mutateIsConflict]);
  159. // TODO: remove workaround
  160. // for https://redmine.weseek.co.jp/issues/125923
  161. useEffect(() => {
  162. setCreatedPageRevisionIdWithAttachment(undefined);
  163. }, [router]);
  164. useEffect(() => {
  165. if (socket == null) { return }
  166. socket.on(SocketEventName.PageUpdated, checkIsConflict);
  167. return () => {
  168. socket.off(SocketEventName.PageUpdated, checkIsConflict);
  169. };
  170. }, [socket, checkIsConflict]);
  171. const optionsToSave = useMemo((): OptionsToSave | undefined => {
  172. if (grantData == null) {
  173. return;
  174. }
  175. const grantedGroups = grantData.grantedGroups?.map((group) => {
  176. return { item: group.id, type: group.type };
  177. });
  178. const optionsToSave = {
  179. isSlackEnabled: isSlackEnabled ?? false,
  180. slackChannels: '', // set in save method by opts in SavePageControlls.tsx
  181. grant: grantData.grant,
  182. // pageTags: pageTags ?? [],
  183. grantUserGroupIds: grantedGroups,
  184. };
  185. return optionsToSave;
  186. }, [grantData, isSlackEnabled]);
  187. const save = useCallback(async(opts?: {slackChannels: string, overwriteScopesOfDescendants?: boolean}): Promise<IPageHasId | null> => {
  188. if (currentPathname == null || optionsToSave == null) {
  189. logger.error('Some materials to save are invalid', { grantData, isSlackEnabled, currentPathname });
  190. throw new Error('Some materials to save are invalid');
  191. }
  192. const options = Object.assign(optionsToSave, opts);
  193. try {
  194. mutateWaitingSaveProcessing(true);
  195. const { page } = await saveOrUpdate(
  196. codeMirrorEditor?.getDoc() ?? '',
  197. { pageId, path: currentPagePath || currentPathname, revisionId: currentRevisionId },
  198. options,
  199. );
  200. // to sync revision id with page tree: https://github.com/weseek/growi/pull/7227
  201. mutatePageTree();
  202. return page;
  203. }
  204. catch (error) {
  205. logger.error('failed to save', error);
  206. toastError(error);
  207. if (error.code === 'conflict') {
  208. mutateRemotePageId(error.data.revisionId);
  209. mutateRemoteRevisionId(error.data.revisionBody);
  210. mutateRemoteRevisionLastUpdatedAt(error.data.createdAt);
  211. mutateRemoteRevisionLastUpdateUser(error.data.user);
  212. }
  213. return null;
  214. }
  215. finally {
  216. mutateWaitingSaveProcessing(false);
  217. }
  218. }, [
  219. codeMirrorEditor,
  220. currentPathname, optionsToSave, grantData, isSlackEnabled, saveOrUpdate, pageId,
  221. currentPagePath, currentRevisionId,
  222. mutateWaitingSaveProcessing, mutateRemotePageId, mutateRemoteRevisionId, mutateRemoteRevisionLastUpdatedAt, mutateRemoteRevisionLastUpdateUser,
  223. ]);
  224. const saveAndReturnToViewHandler = useCallback(async(opts: {slackChannels: string, overwriteScopesOfDescendants?: boolean}) => {
  225. const page = await save(opts);
  226. if (page == null) {
  227. return;
  228. }
  229. if (isNotFound) {
  230. await router.push(`/${page._id}`);
  231. }
  232. else {
  233. updateStateAfterSave?.();
  234. }
  235. mutateEditorMode(EditorMode.View);
  236. }, [save, isNotFound, mutateEditorMode, router, updateStateAfterSave]);
  237. const saveWithShortcut = useCallback(async() => {
  238. const page = await save();
  239. if (page == null) {
  240. return;
  241. }
  242. if (isNotFound) {
  243. await router.push(`/${page._id}#edit`);
  244. }
  245. else {
  246. updateStateAfterSave?.();
  247. }
  248. toastSuccess(t('toaster.save_succeeded'));
  249. mutateEditorMode(EditorMode.Editor);
  250. }, [isNotFound, mutateEditorMode, router, save, t, updateStateAfterSave]);
  251. // the upload event handler
  252. const uploadHandler = useCallback((files: File[]) => {
  253. files.forEach(async(file) => {
  254. try {
  255. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  256. const resLimit: any = await apiGet('/attachments.limit', {
  257. fileSize: file.size,
  258. });
  259. if (!resLimit.isUploadable) {
  260. throw new Error(resLimit.errorMessage);
  261. }
  262. const formData = new FormData();
  263. formData.append('file', file);
  264. if (currentPagePath != null) {
  265. formData.append('path', currentPagePath);
  266. }
  267. if (pageId != null) {
  268. formData.append('page_id', pageId);
  269. }
  270. if (pageId == null) {
  271. formData.append('page_body', codeMirrorEditor?.getDoc() ?? '');
  272. }
  273. const resAdd: any = await apiPostForm('/attachments.add', formData);
  274. const attachment = resAdd.attachment;
  275. const fileName = attachment.originalName;
  276. let insertText = `[${fileName}](${attachment.filePathProxied})\n`;
  277. // when image
  278. if (attachment.fileFormat.startsWith('image/')) {
  279. // modify to "![fileName](url)" syntax
  280. insertText = `!${insertText}`;
  281. }
  282. // TODO: implement
  283. // refs: https://redmine.weseek.co.jp/issues/126528
  284. // editorRef.current.insertText(insertText);
  285. codeMirrorEditor?.insertText(insertText);
  286. }
  287. catch (e) {
  288. logger.error('failed to upload', e);
  289. toastError(e);
  290. }
  291. finally {
  292. // TODO: implement
  293. // refs: https://redmine.weseek.co.jp/issues/126528
  294. // editorRef.current.terminateUploadingState();
  295. }
  296. });
  297. }, [codeMirrorEditor, currentPagePath, pageId]);
  298. const acceptedFileType = useMemo(() => {
  299. if (!isUploadEnabled) {
  300. return AcceptedUploadFileType.NONE;
  301. }
  302. if (isUploadAllFileAllowed) {
  303. return AcceptedUploadFileType.ALL;
  304. }
  305. return AcceptedUploadFileType.IMAGE;
  306. }, [isUploadAllFileAllowed, isUploadEnabled]);
  307. const scrollPreviewByEditorLine = useCallback((line: number) => {
  308. if (previewRef.current == null) {
  309. return;
  310. }
  311. // prevent circular invocation
  312. if (isOriginOfScrollSyncPreview) {
  313. isOriginOfScrollSyncPreview = false; // turn off the flag
  314. return;
  315. }
  316. // turn on the flag
  317. isOriginOfScrollSyncEditor = true;
  318. scrollSyncHelper.scrollPreview(previewRef.current, line);
  319. }, []);
  320. const scrollPreviewByEditorLineWithThrottle = useMemo(() => throttle(20, scrollPreviewByEditorLine), [scrollPreviewByEditorLine]);
  321. /**
  322. * the scroll event handler from codemirror
  323. * @param {any} data {left, top, width, height, clientWidth, clientHeight} object that represents the current scroll position,
  324. * the size of the scrollable area, and the size of the visible area (minus scrollbars).
  325. * And data.line is also available that is added by Editor component
  326. * @see https://codemirror.net/doc/manual.html#events
  327. */
  328. const editorScrolledHandler = useCallback(({ line }: { line: number }) => {
  329. // prevent scrolling
  330. // if the elapsed time from last scroll with cursor is shorter than 40ms
  331. const now = new Date();
  332. if (lastScrolledDateWithCursor != null && now.getTime() - lastScrolledDateWithCursor.getTime() < 40) {
  333. return;
  334. }
  335. scrollPreviewByEditorLineWithThrottle(line);
  336. }, [scrollPreviewByEditorLineWithThrottle]);
  337. /**
  338. * scroll Preview element by cursor moving
  339. * @param {number} line
  340. */
  341. const scrollPreviewByCursorMoving = useCallback((line: number) => {
  342. if (previewRef.current == null) {
  343. return;
  344. }
  345. // prevent circular invocation
  346. if (isOriginOfScrollSyncPreview) {
  347. isOriginOfScrollSyncPreview = false; // turn off the flag
  348. return;
  349. }
  350. // turn on the flag
  351. isOriginOfScrollSyncEditor = true;
  352. if (previewRef.current != null) {
  353. scrollSyncHelper.scrollPreviewToRevealOverflowing(previewRef.current, line);
  354. }
  355. }, []);
  356. const scrollPreviewByCursorMovingWithThrottle = useMemo(() => throttle(20, scrollPreviewByCursorMoving), [scrollPreviewByCursorMoving]);
  357. /**
  358. * the scroll event handler from codemirror
  359. * @param {number} line
  360. * @see https://codemirror.net/doc/manual.html#events
  361. */
  362. const editorScrollCursorIntoViewHandler = useCallback((line: number) => {
  363. // record date
  364. lastScrolledDateWithCursor = new Date();
  365. scrollPreviewByCursorMovingWithThrottle(line);
  366. }, [scrollPreviewByCursorMovingWithThrottle]);
  367. /**
  368. * scroll Editor component by scroll event of Preview component
  369. * @param {number} offset
  370. */
  371. // const scrollEditorByPreviewScroll = useCallback((offset: number) => {
  372. // if (editorRef.current == null || previewRef.current == null) {
  373. // return;
  374. // }
  375. // // prevent circular invocation
  376. // if (isOriginOfScrollSyncEditor) {
  377. // isOriginOfScrollSyncEditor = false; // turn off the flag
  378. // return;
  379. // }
  380. // // turn on the flag
  381. // // eslint-disable-next-line @typescript-eslint/no-unused-vars
  382. // isOriginOfScrollSyncPreview = true;
  383. // scrollSyncHelper.scrollEditor(editorRef.current, previewRef.current, offset);
  384. // }, []);
  385. // const scrollEditorByPreviewScrollWithThrottle = useMemo(() => throttle(20, scrollEditorByPreviewScroll), [scrollEditorByPreviewScroll]);
  386. const afterResolvedHandler = useCallback(async() => {
  387. // get page data from db
  388. const pageData = await mutateCurrentPage();
  389. // update tag
  390. await mutateTagsInfo(); // get from DB
  391. syncTagsInfoForEditor(); // sync global state for client
  392. // clear isConflict
  393. mutateIsConflict(false);
  394. // set resolved markdown in editing markdown
  395. const markdown = pageData?.revision.body ?? '';
  396. mutateEditingMarkdown(markdown);
  397. }, [mutateCurrentPage, mutateEditingMarkdown, mutateIsConflict, mutateTagsInfo, syncTagsInfoForEditor]);
  398. // initial caret line
  399. useEffect(() => {
  400. codeMirrorEditor?.setCaretLine();
  401. }, [codeMirrorEditor]);
  402. // set handler to set caret line
  403. useEffect(() => {
  404. const handler = (line) => {
  405. codeMirrorEditor?.setCaretLine(line);
  406. if (previewRef.current != null) {
  407. scrollSyncHelper.scrollPreview(previewRef.current, line);
  408. }
  409. };
  410. globalEmitter.on('setCaretLine', handler);
  411. return function cleanup() {
  412. globalEmitter.removeListener('setCaretLine', handler);
  413. };
  414. }, [codeMirrorEditor]);
  415. // set handler to save and return to View
  416. useEffect(() => {
  417. globalEmitter.on('saveAndReturnToView', saveAndReturnToViewHandler);
  418. return function cleanup() {
  419. globalEmitter.removeListener('saveAndReturnToView', saveAndReturnToViewHandler);
  420. };
  421. }, [saveAndReturnToViewHandler]);
  422. // set handler to focus
  423. useLayoutEffect(() => {
  424. if (editorMode === EditorMode.Editor) {
  425. codeMirrorEditor?.focus();
  426. }
  427. }, [codeMirrorEditor, editorMode]);
  428. // Detect indent size from contents (only when users are allowed to change it)
  429. useEffect(() => {
  430. // do nothing if the indent size fixed
  431. if (isIndentSizeForced == null || isIndentSizeForced) {
  432. mutateCurrentIndentSize(undefined);
  433. return;
  434. }
  435. // detect from markdown
  436. if (initialValue != null) {
  437. const detectedIndent = detectIndent(initialValue);
  438. if (detectedIndent.type === 'space' && new Set([2, 4]).has(detectedIndent.amount)) {
  439. mutateCurrentIndentSize(detectedIndent.amount);
  440. }
  441. }
  442. }, [initialValue, isIndentSizeForced, mutateCurrentIndentSize]);
  443. // TODO: Check the reproduction conditions that made this code necessary and confirm reproduction
  444. // // when transitioning to a different page, if the initialValue is the same,
  445. // // UnControlled CodeMirror value does not reset, so explicitly set the value to initialValue
  446. // const onRouterChangeComplete = useCallback(() => {
  447. // codeMirrorEditor?.initDoc(ydoc?.getText('codemirror').toString());
  448. // codeMirrorEditor?.setCaretLine();
  449. // }, [codeMirrorEditor, ydoc]);
  450. // useEffect(() => {
  451. // router.events.on('routeChangeComplete', onRouterChangeComplete);
  452. // return () => {
  453. // router.events.off('routeChangeComplete', onRouterChangeComplete);
  454. // };
  455. // }, [onRouterChangeComplete, router.events]);
  456. if (!isEditable) {
  457. return <></>;
  458. }
  459. if (rendererOptions == null) {
  460. return <></>;
  461. }
  462. return (
  463. <div data-testid="page-editor" id="page-editor" className={`flex-expand-vert ${props.visibility ? '' : 'd-none'}`}>
  464. <div className="flex-expand-vert justify-content-center align-items-center" style={{ minHeight: '72px' }}>
  465. <div>Header</div>
  466. </div>
  467. <div className={`flex-expand-horiz ${props.visibility ? '' : 'd-none'}`}>
  468. <div className="page-editor-editor-container flex-expand-vert">
  469. {/* <Editor
  470. ref={editorRef}
  471. value={initialValue}
  472. isUploadable={isUploadable}
  473. isUploadAllFileAllowed={isUploadAllFileAllowed}
  474. indentSize={currentIndentSize}
  475. onScroll={editorScrolledHandler}
  476. onScrollCursorIntoView={editorScrollCursorIntoViewHandler}
  477. onChange={markdownChangedHandler}
  478. onUpload={uploadHandler}
  479. onSave={saveWithShortcut}
  480. /> */}
  481. <CodeMirrorEditorMain
  482. onChange={markdownChangedHandler}
  483. onSave={saveWithShortcut}
  484. onUpload={uploadHandler}
  485. acceptedFileType={acceptedFileType}
  486. indentSize={currentIndentSize ?? defaultIndentSize}
  487. userName={user?.name}
  488. pageId={pageId ?? undefined}
  489. initialValue={initialValue}
  490. onOpenEditor={markdown => setMarkdownToPreview(markdown)}
  491. />
  492. </div>
  493. <div className="page-editor-preview-container flex-expand-vert d-none d-lg-flex">
  494. <Preview
  495. ref={previewRef}
  496. rendererOptions={rendererOptions}
  497. markdown={markdownToPreview}
  498. pagePath={currentPagePath}
  499. expandContentWidth={shouldExpandContent}
  500. // TODO: implement
  501. // refs: https://redmine.weseek.co.jp/issues/126519
  502. // onScroll={offset => scrollEditorByPreviewScrollWithThrottle(offset)}
  503. />
  504. </div>
  505. {/*
  506. <ConflictDiffModal
  507. isOpen={conflictDiffModalStatus?.isOpened}
  508. onClose={() => closeConflictDiffModal()}
  509. markdownOnEdit={markdownToPreview}
  510. optionsToSave={optionsToSave}
  511. afterResolvedHandler={afterResolvedHandler}
  512. />
  513. */}
  514. </div>
  515. <EditorNavbarBottom />
  516. </div>
  517. );
  518. });
  519. PageEditor.displayName = 'PageEditor';