Skip to content

Commit 89e7cf0

Browse files
committed
feat(embedding): feature shared clipboard
Allows to try out keyboard shortcuts in a more advanced scenario.
1 parent 461ae44 commit 89e7cf0

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

embedding/src/app.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,53 @@ import BpmnModeler from 'bpmn-js/lib/Modeler';
99
import BpmnViewer from 'bpmn-js/lib/Viewer';
1010
import BpmnNavigatedViewer from 'bpmn-js/lib/NavigatedViewer';
1111

12+
import Clipboard from 'diagram-js/lib/features/clipboard/Clipboard';
13+
1214
const editorMap = {
1315
'editor': BpmnModeler,
1416
'viewer': BpmnViewer,
15-
'navigated-viewer': BpmnNavigatedViewer,
16-
'default': BpmnModeler
17+
'navigated-viewer': BpmnNavigatedViewer
18+
};
19+
20+
const sharedClipboard = {
21+
'clipboard': [ 'value', new Clipboard() ]
22+
};
23+
24+
const additionalModulesMap = {
25+
'first-modeler': [
26+
sharedClipboard
27+
],
28+
'second-modeler': [
29+
sharedClipboard
30+
]
1731
};
1832

1933
const modelers = new Map();
2034

35+
function createModeler(viewerType, config, id) {
36+
37+
const BpmnJS = editorMap[viewerType] || BpmnModeler;
38+
39+
const additionalModules = additionalModulesMap[id] || [];
40+
41+
return new BpmnJS({
42+
...config,
43+
additionalModules
44+
});
45+
}
46+
2147
async function openDiagram(element) {
2248

2349
const diagramURL = element.dataset.diagram;
2450
const viewerType = element.dataset.editor;
51+
const id = element.id || '__default';
2552

26-
const BpmnJS = editorMap[viewerType] || editorMap.default;
27-
28-
const diagramXML = await fetch(diagramURL).then(response => response.text());
29-
30-
const modeler = new BpmnJS({ container: element });
53+
const modeler = createModeler(viewerType, { container: element }, id);
3154

3255
modelers.set(element, modeler);
3356

57+
const diagramXML = await fetch(diagramURL).then(response => response.text());
58+
3459
await modeler.importXML(diagramXML);
3560
}
3661

embedding/src/index.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ <h1>Embedding example</h1>
1717

1818
<div class="diagram-grid single">
1919
<figure>
20-
<div class="canvas" data-diagram="./diagrams/overview.bpmn"></div>
21-
<figcaption>BPMN Modeler</figcaption>
20+
<div class="canvas" data-diagram="./diagrams/second.bpmn" data-editor="navigated-viewer"></div>
21+
<figcaption>BPMN Navigated Viewer</figcaption>
2222
</figure>
2323
</div>
2424

@@ -30,19 +30,27 @@ <h1>Embedding example</h1>
3030
Orci vestibulum turpis quis vehicula risus porttitor ornare. Facilisis aenean vivamus turpis quisque elementum condimentum tempus. Nisi orci sem potenti congue; malesuada himenaeos parturient. Primis sagittis mollis nascetur metus est inceptos platea. Quisque faucibus maximus eget lacinia sit sapien. Ex molestie suspendisse suscipit vehicula nunc. Augue sem facilisis mollis in torquent venenatis sem. Neque natoque phasellus diam habitant turpis pulvinar convallis euismod. Sociosqu bibendum facilisi praesent vitae ornare vehicula ut dapibus lacus.
3131
</p>
3232

33+
<div class="diagram-grid">
34+
<figure>
35+
<div id="second-modeler" class="canvas" data-diagram="./diagrams/overview.bpmn"></div>
36+
<figcaption>A BPMN Modeler</figcaption>
37+
</figure>
38+
39+
<figure>
40+
<div id="first-modeler" class="canvas" data-diagram="./diagrams/first.bpmn"></div>
41+
<figcaption>Another BPMN Modeler</figcaption>
42+
</figure>
43+
</div>
44+
3345
<p>
3446
Pretium rhoncus sem metus imperdiet vel hendrerit fusce habitant. Nec elit dictum vitae nam mattis nostra. Fermentum aenean sollicitudin molestie platea nulla risus et at. Et ligula convallis, duis per facilisis et sagittis sollicitudin porta. Cursus bibendum curae porttitor vivamus torquent elementum tempor. Fermentum elementum aliquam lacus praesent eleifend bibendum.
3547
</p>
3648

37-
<div class="diagram-grid">
49+
<div class="diagram-grid single">
3850
<figure>
3951
<div class="canvas" data-diagram="./diagrams/first.bpmn" data-editor="viewer"></div>
4052
<figcaption>BPMN Viewer</figcaption>
4153
</figure>
42-
<figure>
43-
<div class="canvas" data-diagram="./diagrams/second.bpmn" data-editor="navigated-viewer"></div>
44-
<figcaption>BPMN Navigated Viewer</figcaption>
45-
</figure>
4654
</div>
4755

4856
<p>

0 commit comments

Comments
 (0)