PageEditor.tsx 21 KB

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