PageEditor.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. import React, {
  2. useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState,
  3. } from 'react';
  4. import EventEmitter from 'events';
  5. import nodePath from 'path';
  6. import type { IPageHasId } from '@growi/core';
  7. import { pathUtils } from '@growi/core/dist/utils';
  8. import {
  9. CodeMirrorEditorMain, GlobalCodeMirrorEditorKey, AcceptedUploadFileType,
  10. useCodeMirrorEditorIsolated, useResolvedThemeForEditor,
  11. } from '@growi/editor';
  12. import detectIndent from 'detect-indent';
  13. import { useTranslation } from 'next-i18next';
  14. import { useRouter } from 'next/router';
  15. import { throttle, debounce } from 'throttle-debounce';
  16. import { useShouldExpandContent } from '~/client/services/layout';
  17. import { useUpdateStateAfterSave, useSaveOrUpdate } from '~/client/services/page-operation';
  18. import { apiGet, apiPostForm } from '~/client/util/apiv1-client';
  19. import { toastError, toastSuccess } from '~/client/util/toastr';
  20. import { OptionsToSave } from '~/interfaces/page-operation';
  21. import { SocketEventName } from '~/interfaces/websocket';
  22. import {
  23. useDefaultIndentSize,
  24. useCurrentPathname, useIsEnabledAttachTitleHeader,
  25. useIsEditable, useIsUploadAllFileAllowed, useIsUploadEnabled, useIsIndentSizeForced,
  26. } from '~/stores/context';
  27. import {
  28. useCurrentIndentSize, useIsSlackEnabled, usePageTagsForEditors,
  29. useIsEnabledUnsavedWarning,
  30. useIsConflict,
  31. useEditingMarkdown,
  32. useWaitingSaveProcessing,
  33. } from '~/stores/editor';
  34. import { useConflictDiffModal } from '~/stores/modal';
  35. import {
  36. useCurrentPagePath, useSWRMUTxCurrentPage, useSWRxCurrentPage, useSWRxTagsInfo, useCurrentPageId, useIsNotFound, useIsLatestRevision, useTemplateBodyData,
  37. } from '~/stores/page';
  38. import { mutatePageTree } from '~/stores/page-listing';
  39. import {
  40. useRemoteRevisionId,
  41. useRemoteRevisionBody,
  42. useRemoteRevisionLastUpdatedAt,
  43. useRemoteRevisionLastUpdateUser,
  44. } from '~/stores/remote-latest-page';
  45. import { usePreviewOptions } from '~/stores/renderer';
  46. import {
  47. EditorMode,
  48. useEditorMode, useSelectedGrant,
  49. } from '~/stores/ui';
  50. import { useNextThemes } from '~/stores/use-next-themes';
  51. import { useGlobalSocket } from '~/stores/websocket';
  52. import loggerFactory from '~/utils/logger';
  53. // import { ConflictDiffModal } from './PageEditor/ConflictDiffModal';
  54. // import { ConflictDiffModal } from './ConflictDiffModal';
  55. // import Editor from './Editor';
  56. import EditorNavbarBottom from './EditorNavbarBottom';
  57. import Preview from './Preview';
  58. import scrollSyncHelper from './ScrollSyncHelper';
  59. import '@growi/editor/dist/style.css';
  60. const logger = loggerFactory('growi:PageEditor');
  61. declare global {
  62. // eslint-disable-next-line vars-on-top, no-var
  63. var globalEmitter: EventEmitter;
  64. }
  65. // for scrolling
  66. let lastScrolledDateWithCursor: Date | null = null;
  67. let isOriginOfScrollSyncEditor = false;
  68. let isOriginOfScrollSyncPreview = false;
  69. type Props = {
  70. visibility?: boolean,
  71. }
  72. export const PageEditor = React.memo((props: Props): JSX.Element => {
  73. const { t } = useTranslation();
  74. const router = useRouter();
  75. const previewRef = useRef<HTMLDivElement>(null);
  76. const codeMirrorEditorContainerRef = useRef<HTMLDivElement>(null);
  77. const { data: isNotFound } = useIsNotFound();
  78. const { data: pageId, mutate: mutateCurrentPageId } = useCurrentPageId();
  79. const { data: currentPagePath } = useCurrentPagePath();
  80. const { data: currentPathname } = useCurrentPathname();
  81. const { data: currentPage } = useSWRxCurrentPage();
  82. const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
  83. const { data: grantData } = useSelectedGrant();
  84. const { sync: syncTagsInfoForEditor } = usePageTagsForEditors(pageId);
  85. const { mutate: mutateTagsInfo } = useSWRxTagsInfo(pageId);
  86. const { data: editingMarkdown, mutate: mutateEditingMarkdown } = useEditingMarkdown();
  87. const { data: isEnabledAttachTitleHeader } = useIsEnabledAttachTitleHeader();
  88. const { data: templateBodyData } = useTemplateBodyData();
  89. const { data: isEditable } = useIsEditable();
  90. const { mutate: mutateWaitingSaveProcessing } = useWaitingSaveProcessing();
  91. const { data: editorMode, mutate: mutateEditorMode } = useEditorMode();
  92. const { data: isSlackEnabled } = useIsSlackEnabled();
  93. const { data: isIndentSizeForced } = useIsIndentSizeForced();
  94. const { data: currentIndentSize, mutate: mutateCurrentIndentSize } = useCurrentIndentSize();
  95. const { data: defaultIndentSize } = useDefaultIndentSize();
  96. const { data: isUploadAllFileAllowed } = useIsUploadAllFileAllowed();
  97. const { data: isUploadEnabled } = useIsUploadEnabled();
  98. const { data: conflictDiffModalStatus, close: closeConflictDiffModal } = useConflictDiffModal();
  99. const { mutate: mutateIsLatestRevision } = useIsLatestRevision();
  100. const { mutate: mutateRemotePageId } = useRemoteRevisionId();
  101. const { mutate: mutateRemoteRevisionId } = useRemoteRevisionBody();
  102. const { mutate: mutateRemoteRevisionLastUpdatedAt } = useRemoteRevisionLastUpdatedAt();
  103. const { mutate: mutateRemoteRevisionLastUpdateUser } = useRemoteRevisionLastUpdateUser();
  104. const { data: socket } = useGlobalSocket();
  105. const { data: rendererOptions } = usePreviewOptions();
  106. const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
  107. const { mutate: mutateIsConflict } = useIsConflict();
  108. const { mutate: mutateResolvedTheme } = useResolvedThemeForEditor();
  109. const shouldExpandContent = useShouldExpandContent(currentPage);
  110. const saveOrUpdate = useSaveOrUpdate();
  111. const updateStateAfterSave = useUpdateStateAfterSave(pageId, { supressEditingMarkdownMutation: true });
  112. const { resolvedTheme } = useNextThemes();
  113. mutateResolvedTheme(resolvedTheme);
  114. // TODO: remove workaround
  115. // for https://redmine.weseek.co.jp/issues/125923
  116. const [createdPageRevisionIdWithAttachment, setCreatedPageRevisionIdWithAttachment] = useState();
  117. // TODO: remove workaround
  118. // for https://redmine.weseek.co.jp/issues/125923
  119. const currentRevisionId = currentPage?.revision?._id ?? createdPageRevisionIdWithAttachment;
  120. const initialValueRef = useRef('');
  121. const initialValue = useMemo(() => {
  122. if (!isNotFound) {
  123. return editingMarkdown ?? '';
  124. }
  125. let initialValue = '';
  126. if (isEnabledAttachTitleHeader && currentPathname != null) {
  127. const pageTitle = nodePath.basename(currentPathname);
  128. initialValue += `${pathUtils.attachTitleHeader(pageTitle)}\n`;
  129. }
  130. if (templateBodyData != null) {
  131. initialValue += `${templateBodyData}\n`;
  132. }
  133. return initialValue;
  134. }, [isNotFound, currentPathname, editingMarkdown, isEnabledAttachTitleHeader, templateBodyData]);
  135. useEffect(() => {
  136. // set to ref
  137. initialValueRef.current = initialValue;
  138. }, [initialValue]);
  139. const [markdownToPreview, setMarkdownToPreview] = useState<string>(initialValue);
  140. const setMarkdownPreviewWithDebounce = useMemo(() => debounce(100, throttle(150, (value: string) => {
  141. setMarkdownToPreview(value);
  142. })), []);
  143. const mutateIsEnabledUnsavedWarningWithDebounce = useMemo(() => debounce(600, throttle(900, (value: string) => {
  144. // Displays an unsaved warning alert
  145. mutateIsEnabledUnsavedWarning(value !== initialValueRef.current);
  146. })), [mutateIsEnabledUnsavedWarning]);
  147. const markdownChangedHandler = useCallback((value: string) => {
  148. setMarkdownPreviewWithDebounce(value);
  149. mutateIsEnabledUnsavedWarningWithDebounce(value);
  150. }, [mutateIsEnabledUnsavedWarningWithDebounce, setMarkdownPreviewWithDebounce]);
  151. const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
  152. const checkIsConflict = useCallback((data) => {
  153. const { s2cMessagePageUpdated } = data;
  154. const isConflict = markdownToPreview !== s2cMessagePageUpdated.revisionBody;
  155. mutateIsConflict(isConflict);
  156. }, [markdownToPreview, mutateIsConflict]);
  157. // TODO: remove workaround
  158. // for https://redmine.weseek.co.jp/issues/125923
  159. useEffect(() => {
  160. setCreatedPageRevisionIdWithAttachment(undefined);
  161. }, [router]);
  162. useEffect(() => {
  163. if (socket == null) { return }
  164. socket.on(SocketEventName.PageUpdated, checkIsConflict);
  165. return () => {
  166. socket.off(SocketEventName.PageUpdated, checkIsConflict);
  167. };
  168. }, [socket, checkIsConflict]);
  169. const optionsToSave = useMemo((): OptionsToSave | undefined => {
  170. if (grantData == null) {
  171. return;
  172. }
  173. const grantedGroups = grantData.grantedGroups?.map((group) => {
  174. return { item: group.id, type: group.type };
  175. });
  176. const optionsToSave = {
  177. isSlackEnabled: isSlackEnabled ?? false,
  178. slackChannels: '', // set in save method by opts in SavePageControlls.tsx
  179. grant: grantData.grant,
  180. // pageTags: pageTags ?? [],
  181. grantUserGroupIds: grantedGroups,
  182. };
  183. return optionsToSave;
  184. }, [grantData, isSlackEnabled]);
  185. const save = useCallback(async(opts?: {slackChannels: string, overwriteScopesOfDescendants?: boolean}): Promise<IPageHasId | null> => {
  186. if (currentPathname == null || optionsToSave == null) {
  187. logger.error('Some materials to save are invalid', { grantData, isSlackEnabled, currentPathname });
  188. throw new Error('Some materials to save are invalid');
  189. }
  190. const options = Object.assign(optionsToSave, opts);
  191. try {
  192. mutateWaitingSaveProcessing(true);
  193. const { page } = await saveOrUpdate(
  194. codeMirrorEditor?.getDoc() ?? '',
  195. { pageId, path: currentPagePath || currentPathname, revisionId: currentRevisionId },
  196. options,
  197. );
  198. // to sync revision id with page tree: https://github.com/weseek/growi/pull/7227
  199. mutatePageTree();
  200. return page;
  201. }
  202. catch (error) {
  203. logger.error('failed to save', error);
  204. toastError(error);
  205. if (error.code === 'conflict') {
  206. mutateRemotePageId(error.data.revisionId);
  207. mutateRemoteRevisionId(error.data.revisionBody);
  208. mutateRemoteRevisionLastUpdatedAt(error.data.createdAt);
  209. mutateRemoteRevisionLastUpdateUser(error.data.user);
  210. }
  211. return null;
  212. }
  213. finally {
  214. mutateWaitingSaveProcessing(false);
  215. }
  216. }, [
  217. codeMirrorEditor,
  218. currentPathname, optionsToSave, grantData, isSlackEnabled, saveOrUpdate, pageId,
  219. currentPagePath, currentRevisionId,
  220. mutateWaitingSaveProcessing, mutateRemotePageId, mutateRemoteRevisionId, mutateRemoteRevisionLastUpdatedAt, mutateRemoteRevisionLastUpdateUser,
  221. ]);
  222. const saveAndReturnToViewHandler = useCallback(async(opts: {slackChannels: string, overwriteScopesOfDescendants?: boolean}) => {
  223. const page = await save(opts);
  224. if (page == null) {
  225. return;
  226. }
  227. if (isNotFound) {
  228. await router.push(`/${page._id}`);
  229. }
  230. else {
  231. updateStateAfterSave?.();
  232. }
  233. mutateEditorMode(EditorMode.View);
  234. }, [save, isNotFound, mutateEditorMode, router, updateStateAfterSave]);
  235. const saveWithShortcut = useCallback(async() => {
  236. const page = await save();
  237. if (page == null) {
  238. return;
  239. }
  240. if (isNotFound) {
  241. await router.push(`/${page._id}#edit`);
  242. }
  243. else {
  244. updateStateAfterSave?.();
  245. }
  246. toastSuccess(t('toaster.save_succeeded'));
  247. mutateEditorMode(EditorMode.Editor);
  248. }, [isNotFound, mutateEditorMode, router, save, t, updateStateAfterSave]);
  249. // the upload event handler
  250. const uploadHandler = useCallback((files: File[]) => {
  251. files.forEach(async(file) => {
  252. try {
  253. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  254. const resLimit: any = await apiGet('/attachments.limit', {
  255. fileSize: file.size,
  256. });
  257. if (!resLimit.isUploadable) {
  258. throw new Error(resLimit.errorMessage);
  259. }
  260. const formData = new FormData();
  261. formData.append('file', file);
  262. if (currentPagePath != null) {
  263. formData.append('path', currentPagePath);
  264. }
  265. if (pageId != null) {
  266. formData.append('page_id', pageId);
  267. }
  268. if (pageId == null) {
  269. formData.append('page_body', codeMirrorEditor?.getDoc() ?? '');
  270. }
  271. const resAdd: any = await apiPostForm('/attachments.add', formData);
  272. const attachment = resAdd.attachment;
  273. const fileName = attachment.originalName;
  274. let insertText = `[${fileName}](${attachment.filePathProxied})\n`;
  275. // when image
  276. if (attachment.fileFormat.startsWith('image/')) {
  277. // modify to "![fileName](url)" syntax
  278. insertText = `!${insertText}`;
  279. }
  280. // TODO: implement
  281. // refs: https://redmine.weseek.co.jp/issues/126528
  282. // editorRef.current.insertText(insertText);
  283. codeMirrorEditor?.insertText(insertText);
  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, pageId]);
  296. const acceptedFileType = useMemo(() => {
  297. if (!isUploadEnabled) {
  298. return AcceptedUploadFileType.NONE;
  299. }
  300. if (isUploadAllFileAllowed) {
  301. return AcceptedUploadFileType.ALL;
  302. }
  303. return AcceptedUploadFileType.IMAGE;
  304. }, [isUploadAllFileAllowed, isUploadEnabled]);
  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. isUploadAllFileAllowed={isUploadAllFileAllowed}
  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. expandContentWidth={shouldExpandContent}
  502. // TODO: implement
  503. // refs: https://redmine.weseek.co.jp/issues/126519
  504. // onScroll={offset => scrollEditorByPreviewScrollWithThrottle(offset)}
  505. />
  506. </div>
  507. {/*
  508. <ConflictDiffModal
  509. isOpen={conflictDiffModalStatus?.isOpened}
  510. onClose={() => closeConflictDiffModal()}
  511. markdownOnEdit={markdownToPreview}
  512. optionsToSave={optionsToSave}
  513. afterResolvedHandler={afterResolvedHandler}
  514. />
  515. */}
  516. </div>
  517. <EditorNavbarBottom />
  518. </div>
  519. );
  520. });
  521. PageEditor.displayName = 'PageEditor';