2
0

PageEditor.tsx 21 KB

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