PageEditor.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. // the upload event handler
  238. const uploadHandler = useCallback((files: File[]) => {
  239. files.forEach(async(file) => {
  240. try {
  241. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  242. const resLimit: any = await apiGet('/attachments.limit', {
  243. fileSize: file.size,
  244. });
  245. if (!resLimit.isUploadable) {
  246. throw new Error(resLimit.errorMessage);
  247. }
  248. const formData = new FormData();
  249. formData.append('file', file);
  250. if (currentPagePath != null) {
  251. formData.append('path', currentPagePath);
  252. }
  253. if (pageId != null) {
  254. formData.append('page_id', pageId);
  255. }
  256. if (pageId == null) {
  257. formData.append('page_body', codeMirrorEditor?.getDoc() ?? '');
  258. }
  259. const resAdd: any = await apiPostForm('/attachments.add', formData);
  260. const attachment = resAdd.attachment;
  261. const fileName = attachment.originalName;
  262. let insertText = `[${fileName}](${attachment.filePathProxied})\n`;
  263. // when image
  264. if (attachment.fileFormat.startsWith('image/')) {
  265. // modify to "![fileName](url)" syntax
  266. insertText = `!${insertText}`;
  267. }
  268. // TODO: implement
  269. // refs: https://redmine.weseek.co.jp/issues/126528
  270. // editorRef.current.insertText(insertText);
  271. codeMirrorEditor?.insertText(insertText);
  272. // when if created newly
  273. // Not using 'mutateGrant' to inherit the grant of the parent page
  274. if (resAdd.pageCreated) {
  275. logger.info('Page is created', resAdd.page._id);
  276. mutateIsLatestRevision(true);
  277. setCreatedPageRevisionIdWithAttachment(resAdd.page.revision);
  278. await mutateCurrentPageId(resAdd.page._id);
  279. await mutateCurrentPage();
  280. }
  281. }
  282. catch (e) {
  283. logger.error('failed to upload', e);
  284. toastError(e);
  285. }
  286. finally {
  287. // TODO: implement
  288. // refs: https://redmine.weseek.co.jp/issues/126528
  289. // editorRef.current.terminateUploadingState();
  290. }
  291. });
  292. }, [codeMirrorEditor, currentPagePath, mutateCurrentPage, mutateCurrentPageId, mutateIsLatestRevision, pageId]);
  293. const scrollPreviewByEditorLine = useCallback((line: number) => {
  294. if (previewRef.current == null) {
  295. return;
  296. }
  297. // prevent circular invocation
  298. if (isOriginOfScrollSyncPreview) {
  299. isOriginOfScrollSyncPreview = false; // turn off the flag
  300. return;
  301. }
  302. // turn on the flag
  303. isOriginOfScrollSyncEditor = true;
  304. scrollSyncHelper.scrollPreview(previewRef.current, line);
  305. }, []);
  306. const scrollPreviewByEditorLineWithThrottle = useMemo(() => throttle(20, scrollPreviewByEditorLine), [scrollPreviewByEditorLine]);
  307. /**
  308. * the scroll event handler from codemirror
  309. * @param {any} data {left, top, width, height, clientWidth, clientHeight} object that represents the current scroll position,
  310. * the size of the scrollable area, and the size of the visible area (minus scrollbars).
  311. * And data.line is also available that is added by Editor component
  312. * @see https://codemirror.net/doc/manual.html#events
  313. */
  314. const editorScrolledHandler = useCallback(({ line }: { line: number }) => {
  315. // prevent scrolling
  316. // if the elapsed time from last scroll with cursor is shorter than 40ms
  317. const now = new Date();
  318. if (lastScrolledDateWithCursor != null && now.getTime() - lastScrolledDateWithCursor.getTime() < 40) {
  319. return;
  320. }
  321. scrollPreviewByEditorLineWithThrottle(line);
  322. }, [scrollPreviewByEditorLineWithThrottle]);
  323. /**
  324. * scroll Preview element by cursor moving
  325. * @param {number} line
  326. */
  327. const scrollPreviewByCursorMoving = useCallback((line: number) => {
  328. if (previewRef.current == null) {
  329. return;
  330. }
  331. // prevent circular invocation
  332. if (isOriginOfScrollSyncPreview) {
  333. isOriginOfScrollSyncPreview = false; // turn off the flag
  334. return;
  335. }
  336. // turn on the flag
  337. isOriginOfScrollSyncEditor = true;
  338. if (previewRef.current != null) {
  339. scrollSyncHelper.scrollPreviewToRevealOverflowing(previewRef.current, line);
  340. }
  341. }, []);
  342. const scrollPreviewByCursorMovingWithThrottle = useMemo(() => throttle(20, scrollPreviewByCursorMoving), [scrollPreviewByCursorMoving]);
  343. /**
  344. * the scroll event handler from codemirror
  345. * @param {number} line
  346. * @see https://codemirror.net/doc/manual.html#events
  347. */
  348. const editorScrollCursorIntoViewHandler = useCallback((line: number) => {
  349. // record date
  350. lastScrolledDateWithCursor = new Date();
  351. scrollPreviewByCursorMovingWithThrottle(line);
  352. }, [scrollPreviewByCursorMovingWithThrottle]);
  353. /**
  354. * scroll Editor component by scroll event of Preview component
  355. * @param {number} offset
  356. */
  357. // const scrollEditorByPreviewScroll = useCallback((offset: number) => {
  358. // if (editorRef.current == null || previewRef.current == null) {
  359. // return;
  360. // }
  361. // // prevent circular invocation
  362. // if (isOriginOfScrollSyncEditor) {
  363. // isOriginOfScrollSyncEditor = false; // turn off the flag
  364. // return;
  365. // }
  366. // // turn on the flag
  367. // // eslint-disable-next-line @typescript-eslint/no-unused-vars
  368. // isOriginOfScrollSyncPreview = true;
  369. // scrollSyncHelper.scrollEditor(editorRef.current, previewRef.current, offset);
  370. // }, []);
  371. // const scrollEditorByPreviewScrollWithThrottle = useMemo(() => throttle(20, scrollEditorByPreviewScroll), [scrollEditorByPreviewScroll]);
  372. const afterResolvedHandler = useCallback(async() => {
  373. // get page data from db
  374. const pageData = await mutateCurrentPage();
  375. // update tag
  376. await mutateTagsInfo(); // get from DB
  377. syncTagsInfoForEditor(); // sync global state for client
  378. // clear isConflict
  379. mutateIsConflict(false);
  380. // set resolved markdown in editing markdown
  381. const markdown = pageData?.revision.body ?? '';
  382. mutateEditingMarkdown(markdown);
  383. }, [mutateCurrentPage, mutateEditingMarkdown, mutateIsConflict, mutateTagsInfo, syncTagsInfoForEditor]);
  384. // initialize
  385. useEffect(() => {
  386. if (initialValue == null) {
  387. return;
  388. }
  389. codeMirrorEditor?.initDoc(initialValue);
  390. setMarkdownToPreview(initialValue);
  391. mutateIsEnabledUnsavedWarning(false);
  392. }, [codeMirrorEditor, initialValue, mutateIsEnabledUnsavedWarning]);
  393. // initial caret line
  394. useEffect(() => {
  395. codeMirrorEditor?.setCaretLine();
  396. }, [codeMirrorEditor]);
  397. // set handler to set caret line
  398. useEffect(() => {
  399. const handler = (line) => {
  400. codeMirrorEditor?.setCaretLine(line);
  401. if (previewRef.current != null) {
  402. scrollSyncHelper.scrollPreview(previewRef.current, line);
  403. }
  404. };
  405. globalEmitter.on('setCaretLine', handler);
  406. return function cleanup() {
  407. globalEmitter.removeListener('setCaretLine', handler);
  408. };
  409. }, [codeMirrorEditor]);
  410. // set handler to save and return to View
  411. useEffect(() => {
  412. globalEmitter.on('saveAndReturnToView', saveAndReturnToViewHandler);
  413. return function cleanup() {
  414. globalEmitter.removeListener('saveAndReturnToView', saveAndReturnToViewHandler);
  415. };
  416. }, [saveAndReturnToViewHandler]);
  417. // set handler to focus
  418. useLayoutEffect(() => {
  419. if (editorMode === EditorMode.Editor) {
  420. codeMirrorEditor?.focus();
  421. }
  422. }, [codeMirrorEditor, editorMode]);
  423. // Detect indent size from contents (only when users are allowed to change it)
  424. useEffect(() => {
  425. // do nothing if the indent size fixed
  426. if (isIndentSizeForced == null || isIndentSizeForced) {
  427. mutateCurrentIndentSize(undefined);
  428. return;
  429. }
  430. // detect from markdown
  431. if (initialValue != null) {
  432. const detectedIndent = detectIndent(initialValue);
  433. if (detectedIndent.type === 'space' && new Set([2, 4]).has(detectedIndent.amount)) {
  434. mutateCurrentIndentSize(detectedIndent.amount);
  435. }
  436. }
  437. }, [initialValue, isIndentSizeForced, mutateCurrentIndentSize]);
  438. // when transitioning to a different page, if the initialValue is the same,
  439. // UnControlled CodeMirror value does not reset, so explicitly set the value to initialValue
  440. const onRouterChangeComplete = useCallback(() => {
  441. codeMirrorEditor?.initDoc(initialValue);
  442. codeMirrorEditor?.setCaretLine();
  443. }, [codeMirrorEditor, initialValue]);
  444. useEffect(() => {
  445. router.events.on('routeChangeComplete', onRouterChangeComplete);
  446. return () => {
  447. router.events.off('routeChangeComplete', onRouterChangeComplete);
  448. };
  449. }, [onRouterChangeComplete, router.events]);
  450. if (!isEditable) {
  451. return <></>;
  452. }
  453. if (rendererOptions == null) {
  454. return <></>;
  455. }
  456. const isUploadable = isUploadableImage || isUploadableFile;
  457. return (
  458. <div data-testid="page-editor" id="page-editor" className={`flex-expand-horiz ${props.visibility ? '' : 'd-none'}`}>
  459. <div className="page-editor-editor-container flex-expand-vert">
  460. {/* <Editor
  461. ref={editorRef}
  462. value={initialValue}
  463. isUploadable={isUploadable}
  464. isUploadableFile={isUploadableFile}
  465. indentSize={currentIndentSize}
  466. onScroll={editorScrolledHandler}
  467. onScrollCursorIntoView={editorScrollCursorIntoViewHandler}
  468. onChange={markdownChangedHandler}
  469. onUpload={uploadHandler}
  470. onSave={saveWithShortcut}
  471. /> */}
  472. <CodeMirrorEditorMain
  473. onChange={markdownChangedHandler}
  474. onSave={saveWithShortcut}
  475. onUpload={uploadHandler}
  476. indentSize={currentIndentSize ?? defaultIndentSize}
  477. />
  478. </div>
  479. <div className="page-editor-preview-container flex-expand-vert d-none d-lg-flex">
  480. <Preview
  481. ref={previewRef}
  482. rendererOptions={rendererOptions}
  483. markdown={markdownToPreview}
  484. pagePath={currentPagePath}
  485. // TODO: implement
  486. // refs: https://redmine.weseek.co.jp/issues/126519
  487. // onScroll={offset => scrollEditorByPreviewScrollWithThrottle(offset)}
  488. />
  489. </div>
  490. {/*
  491. <ConflictDiffModal
  492. isOpen={conflictDiffModalStatus?.isOpened}
  493. onClose={() => closeConflictDiffModal()}
  494. markdownOnEdit={markdownToPreview}
  495. optionsToSave={optionsToSave}
  496. afterResolvedHandler={afterResolvedHandler}
  497. />
  498. */}
  499. </div>
  500. );
  501. });
  502. PageEditor.displayName = 'PageEditor';