1 | import inherits from 'inherits';
|
2 |
|
3 | import Ids from 'ids';
|
4 |
|
5 | import Viewer from './Viewer';
|
6 |
|
7 | import NavigatedViewer from './NavigatedViewer';
|
8 |
|
9 | import KeyboardMoveModule from 'diagram-js/lib/navigation/keyboard-move';
|
10 | import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
|
11 | import TouchModule from 'diagram-js/lib/navigation/touch';
|
12 | import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
|
13 |
|
14 | import AlignElementsModule from 'diagram-js/lib/features/align-elements';
|
15 | import AutoPlaceModule from './features/auto-place';
|
16 | import AutoResizeModule from './features/auto-resize';
|
17 | import AutoScrollModule from 'diagram-js/lib/features/auto-scroll';
|
18 | import BendpointsModule from 'diagram-js/lib/features/bendpoints';
|
19 | import ContextPadModule from './features/context-pad';
|
20 | import CopyPasteModule from './features/copy-paste';
|
21 | import DistributeElementsModule from './features/distribute-elements';
|
22 | import EditorActionsModule from './features/editor-actions';
|
23 | import KeyboardModule from './features/keyboard';
|
24 | import KeyboardMoveSelectionModule from 'diagram-js/lib/features/keyboard-move-selection';
|
25 | import LabelEditingModule from './features/label-editing';
|
26 | import ModelingModule from './features/modeling';
|
27 | import MoveModule from 'diagram-js/lib/features/move';
|
28 | import PaletteModule from './features/palette';
|
29 | import ReplacePreviewModule from './features/replace-preview';
|
30 | import ResizeModule from 'diagram-js/lib/features/resize';
|
31 | import SnappingModule from './features/snapping';
|
32 | import SearchModule from './features/search';
|
33 |
|
34 |
|
35 | var initialDiagram =
|
36 | '<?xml version="1.0" encoding="UTF-8"?>' +
|
37 | '<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
|
38 | 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
|
39 | 'xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
|
40 | 'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" ' +
|
41 | 'targetNamespace="http://bpmn.io/schema/bpmn" ' +
|
42 | 'id="Definitions_1">' +
|
43 | '<bpmn:process id="Process_1" isExecutable="false">' +
|
44 | '<bpmn:startEvent id="StartEvent_1"/>' +
|
45 | '</bpmn:process>' +
|
46 | '<bpmndi:BPMNDiagram id="BPMNDiagram_1">' +
|
47 | '<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">' +
|
48 | '<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">' +
|
49 | '<dc:Bounds height="36.0" width="36.0" x="173.0" y="102.0"/>' +
|
50 | '</bpmndi:BPMNShape>' +
|
51 | '</bpmndi:BPMNPlane>' +
|
52 | '</bpmndi:BPMNDiagram>' +
|
53 | '</bpmn:definitions>';
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | export default function Modeler(options) {
|
129 | Viewer.call(this, options);
|
130 |
|
131 |
|
132 | this.on('import.parse.complete', function(event) {
|
133 | if (!event.error) {
|
134 | this._collectIds(event.definitions, event.context);
|
135 | }
|
136 | }, this);
|
137 |
|
138 | this.on('diagram.destroy', function() {
|
139 | this.get('moddle').ids.clear();
|
140 | }, this);
|
141 | }
|
142 |
|
143 | inherits(Modeler, Viewer);
|
144 |
|
145 | Modeler.Viewer = Viewer;
|
146 | Modeler.NavigatedViewer = NavigatedViewer;
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | Modeler.prototype.createDiagram = function(done) {
|
154 | return this.importXML(initialDiagram, done);
|
155 | };
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 | Modeler.prototype._createModdle = function(options) {
|
163 | var moddle = Viewer.prototype._createModdle.call(this, options);
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | moddle.ids = new Ids([ 32, 36, 1 ]);
|
169 |
|
170 | return moddle;
|
171 | };
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | Modeler.prototype._collectIds = function(definitions, context) {
|
181 |
|
182 | var moddle = definitions.$model,
|
183 | ids = moddle.ids,
|
184 | id;
|
185 |
|
186 |
|
187 | ids.clear();
|
188 |
|
189 | for (id in context.elementsById) {
|
190 | ids.claim(id, context.elementsById[id]);
|
191 | }
|
192 | };
|
193 |
|
194 | Modeler.prototype._interactionModules = [
|
195 |
|
196 | KeyboardMoveModule,
|
197 | MoveCanvasModule,
|
198 | TouchModule,
|
199 | ZoomScrollModule
|
200 | ];
|
201 |
|
202 | Modeler.prototype._modelingModules = [
|
203 |
|
204 | AlignElementsModule,
|
205 | AutoPlaceModule,
|
206 | AutoScrollModule,
|
207 | AutoResizeModule,
|
208 | BendpointsModule,
|
209 | ContextPadModule,
|
210 | CopyPasteModule,
|
211 | DistributeElementsModule,
|
212 | EditorActionsModule,
|
213 | KeyboardModule,
|
214 | KeyboardMoveSelectionModule,
|
215 | LabelEditingModule,
|
216 | ModelingModule,
|
217 | MoveModule,
|
218 | PaletteModule,
|
219 | ReplacePreviewModule,
|
220 | ResizeModule,
|
221 | SnappingModule,
|
222 | SearchModule
|
223 | ];
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | Modeler.prototype._modules = [].concat(
|
233 | Modeler.prototype._modules,
|
234 | Modeler.prototype._interactionModules,
|
235 | Modeler.prototype._modelingModules);
|