Skip to content

Commit eb4836b

Browse files
committed
Add parentEvent parameters to onSave and onClose events
1 parent b387ed9 commit eb4836b

File tree

6 files changed

+91
-72
lines changed

6 files changed

+91
-72
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 0.1.6
1+
# 0.1.7
22
- Added `parentEvent` parameters to `onSave` and `onClose` events when the callbacks are triggered by another event.
33

44
# 0.1.5

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-drawio",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"type": "module",
55
"description": "React component for integrating the Diagrams (draw.io) embed iframe",
66
"main": "index.js",

src/DrawIoEmbed.tsx

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,79 +36,84 @@ export const DrawIoEmbed = forwardRef<DrawIoEmbedRef, DrawIoEmbedProps>(
3636
const [isInitialized, setIsInitialized] = useState(false);
3737

3838
const messageHandler = (evt: MessageEvent) => {
39-
handleEvent(evt, {
40-
init: () => {
41-
setIsInitialized(true);
42-
},
43-
load: (data) => {
44-
if (onLoad) {
45-
onLoad(data);
46-
}
47-
},
48-
configure: (data) => {
49-
if (configuration) {
50-
action.configure({ config: configuration });
51-
}
39+
handleEvent(
40+
evt,
41+
{
42+
init: () => {
43+
setIsInitialized(true);
44+
},
45+
load: (data) => {
46+
if (onLoad) {
47+
onLoad(data);
48+
}
49+
},
50+
configure: (data) => {
51+
if (configuration) {
52+
action.configure({ config: configuration });
53+
}
5254

53-
if (onConfigure) {
54-
onConfigure(data);
55-
}
56-
},
57-
save: (data) => {
58-
action.exportDiagram({
59-
format: exportFormat || 'xmlsvg',
60-
// @ts-ignore not allowed normally, but only for internal use
61-
exit: data.exit
62-
});
63-
},
64-
exit: (data) => {
65-
if (onClose) {
66-
onClose(data);
67-
}
68-
},
69-
draft: (data) => {
70-
if (onDraft) {
71-
onDraft(data);
72-
}
73-
},
74-
export: (data) => {
75-
if (onSave) {
76-
onSave({
77-
event: 'save',
78-
xml: data.data,
79-
parentEvent: 'export'
55+
if (onConfigure) {
56+
onConfigure(data);
57+
}
58+
},
59+
save: (data) => {
60+
action.exportDiagram({
61+
format: exportFormat || 'xmlsvg',
62+
// @ts-ignore not allowed normally, but only for internal use
63+
exit: data.exit,
64+
parentEvent: 'save'
8065
});
81-
}
66+
},
67+
exit: (data) => {
68+
if (onClose) {
69+
onClose(data);
70+
}
71+
},
72+
draft: (data) => {
73+
if (onDraft) {
74+
onDraft(data);
75+
}
76+
},
77+
export: (data) => {
78+
if (onSave) {
79+
onSave({
80+
event: 'save',
81+
xml: data.data,
82+
parentEvent: data.message.parentEvent || 'export'
83+
});
84+
}
8285

83-
if (onExport) {
84-
onExport(data);
85-
}
86+
if (onExport) {
87+
onExport(data);
88+
}
8689

87-
// @ts-ignore not allowed normally, but only for internal use
88-
if (data.message.exit && onClose) {
89-
onClose({
90-
event: 'exit',
91-
modified: true,
92-
parentEvent: 'export'
93-
});
94-
}
95-
},
96-
merge: (data) => {
97-
if (onMerge) {
98-
onMerge(data);
99-
}
100-
},
101-
prompt: (data) => {
102-
if (onPrompt) {
103-
onPrompt(data);
90+
// @ts-ignore not allowed normally, but only for internal use
91+
if (data.message.exit && onClose) {
92+
onClose({
93+
event: 'exit',
94+
modified: true,
95+
parentEvent: data.message.parentEvent || 'export'
96+
});
97+
}
98+
},
99+
merge: (data) => {
100+
if (onMerge) {
101+
onMerge(data);
102+
}
103+
},
104+
prompt: (data) => {
105+
if (onPrompt) {
106+
onPrompt(data);
107+
}
108+
},
109+
template: (data) => {
110+
if (onTemplate) {
111+
onTemplate(data);
112+
}
104113
}
105114
},
106-
template: (data) => {
107-
if (onTemplate) {
108-
onTemplate(data);
109-
}
110-
}
111-
}, baseUrl);
115+
baseUrl
116+
);
112117
};
113118

114119
useImperativeHandle(

src/hooks/useActions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import { RefObject } from 'react';
2-
import { ActionConfigure, ActionDialog, ActionDraft, ActionExport, ActionLayout, ActionLoad, ActionMerge, ActionPrompt, ActionSpinner, ActionStatus, ActionTemplate, EmbedActions } from '../types';
2+
import {
3+
ActionConfigure,
4+
ActionDialog,
5+
ActionDraft,
6+
ActionExport,
7+
ActionLayout,
8+
ActionLoad,
9+
ActionMerge,
10+
ActionPrompt,
11+
ActionSpinner,
12+
ActionStatus,
13+
ActionTemplate,
14+
EmbedActions
15+
} from '../types';
316

417
type UniqueActionProps<T> = Omit<T, 'action'>;
518

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,5 @@ export type ActionExport = {
238238
data?: string;
239239
message?: string;
240240
xml?: string;
241+
parentEvent?: string;
241242
};

0 commit comments

Comments
 (0)