PageEditor.tsx 21 KB

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