PageEditor.tsx 21 KB

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