|
@@ -1,4 +1,6 @@
|
|
|
import React, {
|
|
import React, {
|
|
|
|
|
+ useCallback,
|
|
|
|
|
+ useEffect,
|
|
|
useMemo,
|
|
useMemo,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
@@ -13,25 +15,42 @@ import { useDrawioUri } from '~/stores/context';
|
|
|
import { useDrawioModal } from '~/stores/modal';
|
|
import { useDrawioModal } from '~/stores/modal';
|
|
|
import { usePersonalSettings } from '~/stores/personal-settings';
|
|
import { usePersonalSettings } from '~/stores/personal-settings';
|
|
|
|
|
|
|
|
|
|
+import { DrawioCommunicationHelper } from './DrawioCommunicationHelper';
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+const headerColor = '#334455';
|
|
|
|
|
+const fontFamily = "Lato, -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif";
|
|
|
|
|
+
|
|
|
|
|
+const drawioConfig = {
|
|
|
|
|
+ css: `
|
|
|
|
|
+ .geMenubarContainer { background-color: ${headerColor} !important; }
|
|
|
|
|
+ .geMenubar { background-color: ${headerColor} !important; }
|
|
|
|
|
+ .geEditor { font-family: ${fontFamily} !important; }
|
|
|
|
|
+ html td.mxPopupMenuItem {
|
|
|
|
|
+ font-family: ${fontFamily} !important;
|
|
|
|
|
+ font-size: 8pt !important;
|
|
|
|
|
+ }
|
|
|
|
|
+ `,
|
|
|
|
|
+ customFonts: ['Lato', 'Charter'],
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
|
// onSave: (drawioData) => void,
|
|
// onSave: (drawioData) => void,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const DrawioModal = (props: Props): JSX.Element => {
|
|
export const DrawioModal = (props: Props): JSX.Element => {
|
|
|
- const { data: growiDrawioUri } = useDrawioUri();
|
|
|
|
|
|
|
+ const { data: drawioUri } = useDrawioUri();
|
|
|
const { data: personalSettingsInfo } = usePersonalSettings();
|
|
const { data: personalSettingsInfo } = usePersonalSettings();
|
|
|
|
|
|
|
|
-
|
|
|
|
|
const { data: drawioModalData, close: closeDrawioModal } = useDrawioModal();
|
|
const { data: drawioModalData, close: closeDrawioModal } = useDrawioModal();
|
|
|
const isOpened = drawioModalData?.isOpened ?? false;
|
|
const isOpened = drawioModalData?.isOpened ?? false;
|
|
|
|
|
|
|
|
- const cancel = () => {
|
|
|
|
|
- closeDrawioModal();
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const drawioUriWithParams = useMemo(() => {
|
|
|
|
|
+ if (drawioUri == null) {
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- const drawioUrl = useMemo(() => {
|
|
|
|
|
- const drawioUri = growiDrawioUri || 'https://embed.diagrams.net/';
|
|
|
|
|
const url = new URL(drawioUri);
|
|
const url = new URL(drawioUri);
|
|
|
|
|
|
|
|
// refs: https://desk.draw.io/support/solutions/articles/16000042546-what-url-parameters-are-supported-
|
|
// refs: https://desk.draw.io/support/solutions/articles/16000042546-what-url-parameters-are-supported-
|
|
@@ -42,13 +61,46 @@ export const DrawioModal = (props: Props): JSX.Element => {
|
|
|
url.searchParams.append('configure', '1');
|
|
url.searchParams.append('configure', '1');
|
|
|
|
|
|
|
|
return url;
|
|
return url;
|
|
|
- }, [growiDrawioUri, personalSettingsInfo?.lang]);
|
|
|
|
|
|
|
+ }, [drawioUri, personalSettingsInfo?.lang]);
|
|
|
|
|
+
|
|
|
|
|
+ const drawioCommunicationHelper = useMemo(() => {
|
|
|
|
|
+ if (drawioUri == null) {
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ return new DrawioCommunicationHelper(
|
|
|
|
|
+ drawioUri,
|
|
|
|
|
+ drawioConfig,
|
|
|
|
|
+ { onClose: closeDrawioModal },
|
|
|
|
|
+ );
|
|
|
|
|
+ }, [closeDrawioModal, drawioUri]);
|
|
|
|
|
+
|
|
|
|
|
+ const receiveMessageHandler = useCallback((event: MessageEvent) => {
|
|
|
|
|
+ if (drawioModalData == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ drawioCommunicationHelper?.onReceiveMessage(event, drawioModalData.drawioMxFile);
|
|
|
|
|
+ }, [drawioCommunicationHelper, drawioModalData]);
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (isOpened) {
|
|
|
|
|
+ window.addEventListener('message', receiveMessageHandler);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ window.removeEventListener('message', receiveMessageHandler);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // clean up
|
|
|
|
|
+ return function() {
|
|
|
|
|
+ window.removeEventListener('message', receiveMessageHandler);
|
|
|
|
|
+ };
|
|
|
|
|
+ }, [isOpened, receiveMessageHandler]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<Modal
|
|
<Modal
|
|
|
isOpen={isOpened}
|
|
isOpen={isOpened}
|
|
|
- toggle={cancel}
|
|
|
|
|
|
|
+ toggle={() => closeDrawioModal()}
|
|
|
backdrop="static"
|
|
backdrop="static"
|
|
|
className="drawio-modal grw-body-only-modal-expanded"
|
|
className="drawio-modal grw-body-only-modal-expanded"
|
|
|
size="xl"
|
|
size="xl"
|
|
@@ -62,15 +114,17 @@ export const DrawioModal = (props: Props): JSX.Element => {
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
{/* iframe */}
|
|
{/* iframe */}
|
|
|
- <div className="w-100 h-100 position-absolute d-flex">
|
|
|
|
|
- { isOpened && (
|
|
|
|
|
- <iframe
|
|
|
|
|
- src={drawioUrl.href}
|
|
|
|
|
- className="border-0 flex-grow-1"
|
|
|
|
|
- >
|
|
|
|
|
- </iframe>
|
|
|
|
|
- ) }
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ { drawioUriWithParams != null && (
|
|
|
|
|
+ <div className="w-100 h-100 position-absolute d-flex">
|
|
|
|
|
+ { isOpened && (
|
|
|
|
|
+ <iframe
|
|
|
|
|
+ src={drawioUriWithParams.href}
|
|
|
|
|
+ className="border-0 flex-grow-1"
|
|
|
|
|
+ >
|
|
|
|
|
+ </iframe>
|
|
|
|
|
+ ) }
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) }
|
|
|
</ModalBody>
|
|
</ModalBody>
|
|
|
</Modal>
|
|
</Modal>
|
|
|
);
|
|
);
|