Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(demo): fetch the BPMN diagrams #287

Merged
merged 12 commits into from
Sep 11, 2024
5 changes: 2 additions & 3 deletions packages/demo/src/overlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import type { FitOptions } from 'bpmn-visualization';
import { BpmnVisualization, OverlaysPlugin } from '@process-analytics/bv-experimental-add-ons';
import { FitType } from 'bpmn-visualization';

// This is simple example of the BPMN diagram, loaded as string. The '?.raw' extension support is provided by Vite.
// For other load methods, see https://github.com/process-analytics/bpmn-visualization-examples
import diagram from './assets/diagram.bpmn?raw';
import { fetchDiagram } from './shared/diagrams';
import { ZoomComponent } from './shared/zoom-component';

// Instantiate BpmnVisualization, and pass the OverlaysPlugin
Expand All @@ -32,6 +30,7 @@ const bpmnVisualization = new BpmnVisualization({
plugins: [OverlaysPlugin],
});
// Load the BPMN diagram defined above
const diagram = await fetchDiagram();
const fitOptions: FitOptions = { type: FitType.Center, margin: 20 };
bpmnVisualization.load(diagram, { fit: fitOptions });

Expand Down
5 changes: 2 additions & 3 deletions packages/demo/src/path-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ import type { BpmnElement } from 'bpmn-visualization';
import { BpmnVisualization, ElementsPlugin, PathResolver, ShapeUtil, StylePlugin } from '@process-analytics/bv-experimental-add-ons';
import { FitType } from 'bpmn-visualization';

// This is simple example of the BPMN diagram, loaded as string. The '?.raw' extension support is provided by Vite.
// For other load methods, see https://github.com/process-analytics/bpmn-visualization-examples
import diagram from './assets/diagram.bpmn?raw';
import { fetchDiagram } from './shared/diagrams';

// Instantiate BpmnVisualization, pass the container HTMLElement - present in path-resolver.html
const bpmnVisualization = new BpmnVisualization({
container: 'bpmn-container',
plugins: [ElementsPlugin, StylePlugin],
});
// Load the BPMN diagram defined above
const diagram = await fetchDiagram();
bpmnVisualization.load(diagram, { fit: { type: FitType.Center, margin: 20 } });
const elementsPlugin = bpmnVisualization.getPlugin<ElementsPlugin>('elements');
const stylePlugin = bpmnVisualization.getPlugin<StylePlugin>('style');
Expand Down
5 changes: 2 additions & 3 deletions packages/demo/src/plugins-by-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import type { FitOptions, StyleUpdate } from 'bpmn-visualization';
import { BpmnVisualization, StyleByNamePlugin } from '@process-analytics/bv-experimental-add-ons';
import { FitType } from 'bpmn-visualization';

// This is simple example of the BPMN diagram, loaded as string. The '?.raw' extension support is provided by Vite.
// For other load methods, see https://github.com/process-analytics/bpmn-visualization-examples
import diagram from './assets/diagram.bpmn?raw';
import { fetchDiagram } from './shared/diagrams';
import { ZoomComponent } from './shared/zoom-component';

// Instantiate BpmnVisualization, and pass the OverlaysPlugin
Expand All @@ -33,6 +31,7 @@ const bpmnVisualization = new BpmnVisualization({
plugins: [StyleByNamePlugin],
});
// Load the BPMN diagram defined above
const diagram = await fetchDiagram();
const fitOptions: FitOptions = { type: FitType.Center, margin: 20 };
bpmnVisualization.load(diagram, { fit: fitOptions });

Expand Down
25 changes: 25 additions & 0 deletions packages/demo/src/shared/diagrams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Copyright 2024 Bonitasoft S.A.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// This is simple example of the BPMN diagram, loaded from a URL. The '?.url' extension support is provided by Vite.
// See https://vitejs.dev/guide/assets#importing-asset-as-url
// For other load methods, see https://github.com/process-analytics/bpmn-visualization-examples
import diagramUrl from '../assets/bpmn/EC-purchase-orders-collapsed.xml?url';

export async function fetchDiagram(): Promise<string> {
const response = await fetch(diagramUrl);
return await response.text();
}
4 changes: 4 additions & 0 deletions packages/demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default defineConfig(() => {
},
},
chunkSizeWarningLimit: 838, // mxgraph
// to add support for top-level await
// see https://github.com/vitejs/vite/issues/6985#issuecomment-1044375490
// see https://vitejs.dev/config/build-options#build-target
target: ['esnext'],
},
};
});
Loading