PageEditor.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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 {
  9. CodeMirrorEditorMain, GlobalCodeMirrorEditorKey, useCodeMirrorEditorIsolated, useResolvedThemeForEditor,
  10. } from '@growi/editor';
  11. import detectIndent from 'detect-indent';
  12. import { useTranslation } from 'next-i18next';
  13. import { useRouter } from 'next/router';
  14. import { throttle, debounce } from 'throttle-debounce';
  15. import { useUpdateStateAfterSave, useSaveOrUpdate } from '~/client/services/page-operation';
  16. import { apiGet, apiPostForm } from '~/client/util/apiv1-client';
  17. import { toastError, toastSuccess } from '~/client/util/toastr';
  18. import { OptionsToSave } from '~/interfaces/page-operation';
  19. import { SocketEventName } from '~/interfaces/websocket';
  20. import {
  21. useDefaultIndentSize,
  22. useCurrentPathname, useIsEnabledAttachTitleHeader,
  23. useIsEditable, useIsUploadableFile, useIsUploadableImage, useIsIndentSizeForced,
  24. } from '~/stores/context';
  25. import {
  26. useCurrentIndentSize, useIsSlackEnabled, usePageTagsForEditors,
  27. useIsEnabledUnsavedWarning,
  28. useIsConflict,
  29. useEditingMarkdown,
  30. useWaitingSaveProcessing,
  31. } from '~/stores/editor';
  32. import { useConflictDiffModal } from '~/stores/modal';
  33. import {
  34. useCurrentPagePath, useSWRMUTxCurrentPage, useSWRxCurrentPage, useSWRxTagsInfo, useCurrentPageId, useIsNotFound, useIsLatestRevision, useTemplateBodyData,
  35. } from '~/stores/page';
  36. import { mutatePageTree } from '~/stores/page-listing';
  37. import {
  38. useRemoteRevisionId,
  39. useRemoteRevisionBody,
  40. useRemoteRevisionLastUpdatedAt,
  41. useRemoteRevisionLastUpdateUser,
  42. } from '~/stores/remote-latest-page';
  43. import { usePreviewOptions } from '~/stores/renderer';
  44. import {
  45. EditorMode,
  46. useEditorMode, useSelectedGrant,
  47. } from '~/stores/ui';
  48. import { useNextThemes } from '~/stores/use-next-themes';
  49. import { useGlobalSocket } from '~/stores/websocket';
  50. import loggerFactory from '~/utils/logger';
  51. // import { ConflictDiffModal } from './PageEditor/ConflictDiffModal';
  52. // import { ConflictDiffModal } from './ConflictDiffModal';
  53. // import Editor from './Editor';
  54. import Preview from './Preview';
  55. import scrollSyncHelper from './ScrollSyncHelper';
  56. import '@growi/editor/dist/style.css';
  57. const logger = loggerFactory('growi:PageEditor');
  58. declare global {
  59. // eslint-disable-next-line vars-on-top, no-var
  60. var globalEmitter: EventEmitter;
  61. }
  62. // for scrolling
  63. let lastScrolledDateWithCursor: Date | null = null;
  64. let isOriginOfScrollSyncEditor = false;
  65. let isOriginOfScrollSyncPreview = false;
  66. type Props = {
  67. visibility?: boolean,
  68. }
  69. export const PageEditor = React.memo((props: Props): JSX.Element => {
  70. const { t } = useTranslation();
  71. const router = useRouter();
  72. const previewRef = useRef<HTMLDivElement>(null);
  73. const codeMirrorEditorContainerRef = useRef<HTMLDivElement>(null);
  74. const { data: isNotFound } = useIsNotFound();
  75. const { data: pageId, mutate: mutateCurrentPageId } = useCurrentPageId();
  76. const { data: currentPagePath } = useCurrentPagePath();
  77. const { data: currentPathname } = useCurrentPathname();
  78. const { data: currentPage } = useSWRxCurrentPage();
  79. const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
  80. const { data: grantData } = useSelectedGrant();
  81. const { data: pageTags, sync: syncTagsInfoForEditor } = usePageTagsForEditors(pageId);
  82. const { mutate: mutateTagsInfo } = useSWRxTagsInfo(pageId);
  83. const { data: editingMarkdown, mutate: mutateEditingMarkdown } = useEditingMarkdown();
  84. const { data: isEnabledAttachTitleHeader } = useIsEnabledAttachTitleHeader();
  85. const { data: templateBodyData } = useTemplateBodyData();
  86. const { data: isEditable } = useIsEditable();
  87. const { mutate: mutateWaitingSaveProcessing } = useWaitingSaveProcessing();
  88. const { data: editorMode, mutate: mutateEditorMode } = useEditorMode();
  89. const { data: isSlackEnabled } = useIsSlackEnabled();
  90. const { data: isIndentSizeForced } = useIsIndentSizeForced();
  91. const { data: currentIndentSize, mutate: mutateCurrentIndentSize } = useCurrentIndentSize();
  92. const { data: defaultIndentSize } = useDefaultIndentSize();
  93. const { data: isUploadableFile } = useIsUploadableFile();
  94. const { data: isUploadableImage } = useIsUploadableImage();
  95. const { data: conflictDiffModalStatus, close: closeConflictDiffModal } = useConflictDiffModal();
  96. const { mutate: mutateIsLatestRevision } = useIsLatestRevision();
  97. const { mutate: mutateRemotePageId } = useRemoteRevisionId();
  98. const { mutate: mutateRemoteRevisionId } = useRemoteRevisionBody();
  99. const { mutate: mutateRemoteRevisionLastUpdatedAt } = useRemoteRevisionLastUpdatedAt();
  100. const { mutate: mutateRemoteRevisionLastUpdateUser } = useRemoteRevisionLastUpdateUser();
  101. const { data: socket } = useGlobalSocket();
  102. const { data: rendererOptions } = usePreviewOptions();
  103. const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
  104. const { mutate: mutateIsConflict } = useIsConflict();
  105. const { mutate: mutateResolvedTheme } = useResolvedThemeForEditor();
  106. const saveOrUpdate = useSaveOrUpdate();
  107. const updateStateAfterSave = useUpdateStateAfterSave(pageId, { supressEditingMarkdownMutation: true });
  108. const { resolvedTheme } = useNextThemes();
  109. mutateResolvedTheme(resolvedTheme);
  110. // TODO: remove workaround
  111. // for https://redmine.weseek.co.jp/issues/125923
  112. const [createdPageRevisionIdWithAttachment, setCreatedPageRevisionIdWithAttachment] = useState();
  113. // TODO: remove workaround
  114. // for https://redmine.weseek.co.jp/issues/125923
  115. const currentRevisionId = currentPage?.revision?._id ?? createdPageRevisionIdWithAttachment;
  116. const initialValueRef = useRef('');
  117. const initialValue = useMemo(() => {
  118. if (!isNotFound) {
  119. return editingMarkdown ?? '';
  120. }
  121. let initialValue = '';
  122. if (isEnabledAttachTitleHeader && currentPathname != null) {
  123. const pageTitle = nodePath.basename(currentPathname);
  124. initialValue += `${pathUtils.attachTitleHeader(pageTitle)}\n`;
  125. }
  126. if (templateBodyData != null) {
  127. initialValue += `${templateBodyData}\n`;
  128. }
  129. return initialValue;
  130. }, [isNotFound, currentPathname, editingMarkdown, isEnabledAttachTitleHeader, templateBodyData]);
  131. useEffect(() => {
  132. // set to ref
  133. initialValueRef.current = initialValue;
  134. }, [initialValue]);
  135. const [markdownToPreview, setMarkdownToPreview] = useState<string>(initialValue);
  136. const setMarkdownPreviewWithDebounce = useMemo(() => debounce(100, throttle(150, (value: string) => {
  137. setMarkdownToPreview(value);
  138. })), []);
  139. const mutateIsEnabledUnsavedWarningWithDebounce = useMemo(() => debounce(600, throttle(900, (value: string) => {
  140. // Displays an unsaved warning alert
  141. mutateIsEnabledUnsavedWarning(value !== initialValueRef.current);
  142. })), [mutateIsEnabledUnsavedWarning]);
  143. const markdownChangedHandler = useCallback((value: string) => {
  144. setMarkdownPreviewWithDebounce(value);
  145. mutateIsEnabledUnsavedWarningWithDebounce(value);
  146. }, [mutateIsEnabledUnsavedWarningWithDebounce, setMarkdownPreviewWithDebounce]);
  147. const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
  148. const checkIsConflict = useCallback((data) => {
  149. const { s2cMessagePageUpdated } = data;
  150. const isConflict = markdownToPreview !== s2cMessagePageUpdated.revisionBody;
  151. mutateIsConflict(isConflict);
  152. }, [markdownToPreview, mutateIsConflict]);
  153. // TODO: remove workaround
  154. // for https://redmine.weseek.co.jp/issues/125923
  155. useEffect(() => {
  156. setCreatedPageRevisionIdWithAttachment(undefined);
  157. }, [router]);
  158. useEffect(() => {
  159. if (socket == null) { return }
  160. socket.on(SocketEventName.PageUpdated, checkIsConflict);
  161. return () => {
  162. socket.off(SocketEventName.PageUpdated, checkIsConflict);
  163. };
  164. }, [socket, checkIsConflict]);
  165. const optionsToSave = useMemo((): OptionsToSave | undefined => {
  166. if (grantData == null) {
  167. return;
  168. }
  169. const optionsToSave = {
  170. isSlackEnabled: isSlackEnabled ?? false,
  171. slackChannels: '', // set in save method by opts in SavePageControlls.tsx
  172. grant: grantData.grant,
  173. pageTags: pageTags ?? [],
  174. grantUserGroupId: grantData.grantedGroup?.id,
  175. grantUserGroupName: grantData.grantedGroup?.name,
  176. };
  177. return optionsToSave;
  178. }, [grantData, isSlackEnabled, pageTags]);
  179. const save = useCallback(async(opts?: {slackChannels: string, overwriteScopesOfDescendants?: boolean}): Promise<IPageHasId | null> => {
  180. if (currentPathname == null || optionsToSave == null) {
  181. logger.error('Some materials to save are invalid', { grantData, isSlackEnabled, currentPathname });
  182. throw new Error('Some materials to save are invalid');
  183. }
  184. const options = Object.assign(optionsToSave, opts);
  185. try {
  186. mutateWaitingSaveProcessing(true);
  187. const { page } = await saveOrUpdate(
  188. codeMirrorEditor?.getDoc() ?? '',
  189. { pageId, path: currentPagePath || currentPathname, revisionId: currentRevisionId },
  190. options,
  191. );
  192. // to sync revision id with page tree: https://github.com/weseek/growi/pull/7227
  193. mutatePageTree();
  194. return page;
  195. }
  196. catch (error) {
  197. logger.error('failed to save', error);
  198. toastError(error);
  199. if (error.code === 'conflict') {
  200. mutateRemotePageId(error.data.revisionId);
  201. mutateRemoteRevisionId(error.data.revisionBody);
  202. mutateRemoteRevisionLastUpdatedAt(error.data.createdAt);
  203. mutateRemoteRevisionLastUpdateUser(error.data.user);
  204. }
  205. return null;
  206. }
  207. finally {
  208. mutateWaitingSaveProcessing(false);
  209. }
  210. }, [
  211. codeMirrorEditor,
  212. currentPathname, optionsToSave, grantData, isSlackEnabled, saveOrUpdate, pageId,
  213. currentPagePath, currentRevisionId,
  214. mutateWaitingSaveProcessing, mutateRemotePageId, mutateRemoteRevisionId, mutateRemoteRevisionLastUpdatedAt, mutateRemoteRevisionLastUpdateUser,
  215. ]);
  216. const saveAndReturnToViewHandler = useCallback(async(opts: {slackChannels: string, overwriteScopesOfDescendants?: boolean}) => {
  217. const page = await save(opts);
  218. if (page == null) {
  219. return;
  220. }
  221. if (isNotFound) {
  222. await router.push(`/${page._id}`);
  223. }
  224. else {
  225. updateStateAfterSave?.();
  226. }
  227. mutateEditorMode(EditorMode.View);
  228. }, [save, isNotFound, mutateEditorMode, router, updateStateAfterSave]);
  229. const saveWithShortcut = useCallback(async() => {
  230. const page = await save();
  231. if (page == null) {
  232. return;
  233. }
  234. if (isNotFound) {
  235. await router.push(`/${page._id}#edit`);
  236. }
  237. else {
  238. updateStateAfterSave?.();
  239. }
  240. toastSuccess(t('toaster.save_succeeded'));
  241. mutateEditorMode(EditorMode.Editor);
  242. }, [isNotFound, mutateEditorMode, router, save, t, updateStateAfterSave]);
  243. // the upload event handler
  244. const uploadHandler = useCallback((files: File[]) => {
  245. files.forEach(async(file) => {
  246. try {
  247. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  248. const resLimit: any = await apiGet('/attachments.limit', {
  249. fileSize: file.size,
  250. });
  251. if (!resLimit.isUploadable) {
  252. throw new Error(resLimit.errorMessage);
  253. }
  254. const formData = new FormData();
  255. formData.append('file', file);
  256. if (currentPagePath != null) {
  257. formData.append('path', currentPagePath);
  258. }
  259. if (pageId != null) {
  260. formData.append('page_id', pageId);
  261. }
  262. if (pageId == null) {
  263. formData.append('page_body', codeMirrorEditor?.getDoc() ?? '');
  264. }
  265. const resAdd: any = await apiPostForm('/attachments.add', formData);
  266. const attachment = resAdd.attachment;
  267. const fileName = attachment.originalName;
  268. let insertText = `[${fileName}](${attachment.filePathProxied})\n`;
  269. // when image
  270. if (attachment.fileFormat.startsWith('image/')) {
  271. // modify to "![fileName](url)" syntax
  272. insertText = `!${insertText}`;
  273. }
  274. // TODO: implement
  275. // refs: https://redmine.weseek.co.jp/issues/126528
  276. // editorRef.current.insertText(insertText);
  277. codeMirrorEditor?.insertText(insertText);
  278. // when if created newly
  279. // Not using 'mutateGrant' to inherit the grant of the parent page
  280. if (resAdd.pageCreated) {
  281. logger.info('Page is created', resAdd.page._id);
  282. mutateIsLatestRevision(true);
  283. setCreatedPageRevisionIdWithAttachment(resAdd.page.revision);
  284. await mutateCurrentPageId(resAdd.page._id);
  285. await mutateCurrentPage();
  286. }
  287. }
  288. catch (e) {
  289. logger.error('failed to upload', e);
  290. toastError(e);
  291. }
  292. finally {
  293. // TODO: implement
  294. // refs: https://redmine.weseek.co.jp/issues/126528
  295. // editorRef.current.terminateUploadingState();
  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';