PageEditor.tsx 21 KB

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