PageEditor.tsx 21 KB

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