PageEditor.tsx 22 KB

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