Skip to content

Commit 00fead6

Browse files
Marc VeensMarc Veens
authored andcommitted
Added .vsdx example
1 parent a23d073 commit 00fead6

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

public/mydrawio.vsdx

618 KB
Binary file not shown.

stories/DiagramsEmbed.stories.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ export const WithRemotePng: Story = {
6565
args: {}
6666
};
6767

68+
export const WithRemoteVsdx: Story = {
69+
decorators: [
70+
(Story) => {
71+
const { inputXml, urlToBase64 } = useRemoteFile();
72+
73+
useEffect(() => {
74+
urlToBase64('/mydrawio.vsdx', {
75+
isVisio: true
76+
});
77+
}, []);
78+
79+
return <Story args={{ xml: inputXml }} />;
80+
}
81+
],
82+
args: {}
83+
};
84+
6885
export const WithConfigurations: Story = {
6986
args: {
7087
xml: '<mxfile host="embed.diagrams.net" modified="2023-08-27T13:33:23.800Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36" version="21.6.9" etag="xthbfrarG6SmZwCYJPbt" type="embed"><diagram id="kaqXdMjmixOsNJA9w4jU" name="Page-1"><mxGraphModel dx="314" dy="361" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"><root><mxCell id="0" /><mxCell id="1" parent="0" /><mxCell id="2" value="" style="shape=cube;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;darkOpacity=0.05;darkOpacity2=0.1;fillColor=#99FFFF;strokeColor=#0066CC;" vertex="1" parent="1"><mxGeometry x="110" y="150" width="120" height="80" as="geometry" /></mxCell></root></mxGraphModel></diagram></mxfile>',

stories/hooks/useRemoteFile.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
import { useState } from 'react';
22

3+
type UrlToBase64Options = {
4+
isVisio?: boolean;
5+
};
6+
37
export const useRemoteFile = () => {
48
const [inputXml, setInputXml] = useState<string>('');
59

6-
const urlToBase64 = async (url: string) => {
10+
const urlToBase64 = async (url: string, options?: UrlToBase64Options) => {
711
const data = await fetch(url);
812

9-
console.log(data);
10-
1113
if (data) {
1214
const blob = await data.blob();
1315

1416
const reader = new FileReader();
1517
reader.readAsDataURL(blob);
1618
reader.onloadend = () => {
17-
const base64data = reader.result;
19+
let base64data = (reader.result || '') as string;
20+
21+
if (options?.isVisio) {
22+
base64data = base64data.replace('data:application/octet-stream;base64', 'data:application/vnd.visio;base64');
23+
}
1824

19-
setInputXml(base64data as string);
25+
setInputXml(base64data);
2026
};
2127
}
2228
};

0 commit comments

Comments
 (0)