|
@@ -1,11 +1,11 @@
|
|
|
import { useCallback, useEffect } from 'react';
|
|
import { useCallback, useEffect } from 'react';
|
|
|
|
|
|
|
|
-import type EventEmitter from 'events';
|
|
|
|
|
-
|
|
|
|
|
import { Origin } from '@growi/core';
|
|
import { Origin } from '@growi/core';
|
|
|
|
|
+import { globalEventTarget } from '@growi/core/dist/utils';
|
|
|
import type { MarkdownTable } from '@growi/editor';
|
|
import type { MarkdownTable } from '@growi/editor';
|
|
|
|
|
|
|
|
import { getMarkdownTableFromLine, replaceMarkdownTableInMarkdown } from '~/client/components/Page/markdown-table-util-for-view';
|
|
import { getMarkdownTableFromLine, replaceMarkdownTableInMarkdown } from '~/client/components/Page/markdown-table-util-for-view';
|
|
|
|
|
+import type { LaunchHandsonTableModalEventDetail } from '~/client/interfaces/handsontable-modal';
|
|
|
import { extractRemoteRevisionDataFromErrorObj, useUpdatePage } from '~/client/services/update-page';
|
|
import { extractRemoteRevisionDataFromErrorObj, useUpdatePage } from '~/client/services/update-page';
|
|
|
import { useShareLinkId } from '~/stores-universal/context';
|
|
import { useShareLinkId } from '~/stores-universal/context';
|
|
|
import { useHandsontableModal, useConflictDiffModal } from '~/stores/modal';
|
|
import { useHandsontableModal, useConflictDiffModal } from '~/stores/modal';
|
|
@@ -17,12 +17,6 @@ import loggerFactory from '~/utils/logger';
|
|
|
const logger = loggerFactory('growi:cli:side-effects:useHandsontableModalLauncherForView');
|
|
const logger = loggerFactory('growi:cli:side-effects:useHandsontableModalLauncherForView');
|
|
|
|
|
|
|
|
|
|
|
|
|
-declare global {
|
|
|
|
|
- // eslint-disable-next-line vars-on-top, no-var
|
|
|
|
|
- var globalEmitter: EventEmitter;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
export const useHandsontableModalLauncherForView = (opts?: {
|
|
export const useHandsontableModalLauncherForView = (opts?: {
|
|
|
onSaveSuccess?: () => void,
|
|
onSaveSuccess?: () => void,
|
|
|
onSaveError?: (error: any) => void,
|
|
onSaveError?: (error: any) => void,
|
|
@@ -68,7 +62,7 @@ export const useHandsontableModalLauncherForView = (opts?: {
|
|
|
logger.error('failed to save', error);
|
|
logger.error('failed to save', error);
|
|
|
opts?.onSaveError?.(error);
|
|
opts?.onSaveError?.(error);
|
|
|
}
|
|
}
|
|
|
- }, [closeConflictDiffModal, currentPage, opts, shareLinkId]);
|
|
|
|
|
|
|
+ }, [_updatePage, closeConflictDiffModal, currentPage, opts, shareLinkId]);
|
|
|
|
|
|
|
|
// eslint-disable-next-line max-len
|
|
// eslint-disable-next-line max-len
|
|
|
const generateResolveConflictHandler = useCallback((revisionId: string, onConflict: (conflictData: RemoteRevisionData, newMarkdown: string) => void) => {
|
|
const generateResolveConflictHandler = useCallback((revisionId: string, onConflict: (conflictData: RemoteRevisionData, newMarkdown: string) => void) => {
|
|
@@ -106,17 +100,18 @@ export const useHandsontableModalLauncherForView = (opts?: {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const handler = (bol: number, eol: number) => {
|
|
|
|
|
|
|
+ const handler = (evt: CustomEvent<LaunchHandsonTableModalEventDetail>) => {
|
|
|
if (currentPage.revision == null) return;
|
|
if (currentPage.revision == null) return;
|
|
|
|
|
|
|
|
const markdown = currentPage.revision.body;
|
|
const markdown = currentPage.revision.body;
|
|
|
|
|
+ const { bol, eol } = evt.detail;
|
|
|
const currentMarkdownTable = getMarkdownTableFromLine(markdown, bol, eol);
|
|
const currentMarkdownTable = getMarkdownTableFromLine(markdown, bol, eol);
|
|
|
openHandsontableModal(currentMarkdownTable, false, table => saveByHandsontableModal(table, bol, eol));
|
|
openHandsontableModal(currentMarkdownTable, false, table => saveByHandsontableModal(table, bol, eol));
|
|
|
};
|
|
};
|
|
|
- globalEmitter.on('launchHandsonTableModal', handler);
|
|
|
|
|
|
|
+ globalEventTarget.addEventListener('launchHandsonTableModal', handler);
|
|
|
|
|
|
|
|
return function cleanup() {
|
|
return function cleanup() {
|
|
|
- globalEmitter.removeListener('launchHandsonTableModal', handler);
|
|
|
|
|
|
|
+ globalEventTarget.removeEventListener('launchHandsonTableModal', handler);
|
|
|
};
|
|
};
|
|
|
}, [currentPage, openHandsontableModal, saveByHandsontableModal, shareLinkId]);
|
|
}, [currentPage, openHandsontableModal, saveByHandsontableModal, shareLinkId]);
|
|
|
};
|
|
};
|