@jylups/cmmn-js 0.0.0-stage → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +3 -0
- package/CHANGELOG.md +119 -0
- package/LICENSE +23 -0
- package/README.md +107 -2
- package/dist/assets/cmmn-font/css/cmmn-codes.css +41 -0
- package/dist/assets/cmmn-font/css/cmmn-embedded.css +94 -0
- package/dist/assets/cmmn-font/css/cmmn.css +97 -0
- package/dist/assets/cmmn-font/font/cmmn.eot +0 -0
- package/dist/assets/cmmn-font/font/cmmn.svg +90 -0
- package/dist/assets/cmmn-font/font/cmmn.ttf +0 -0
- package/dist/assets/cmmn-font/font/cmmn.woff +0 -0
- package/dist/assets/cmmn-font/font/cmmn.woff2 +0 -0
- package/dist/assets/diagram-js.css +713 -0
- package/dist/cmmn-modeler.development.js +44817 -0
- package/dist/cmmn-modeler.production.min.js +2 -0
- package/dist/cmmn-navigated-viewer.development.js +18131 -0
- package/dist/cmmn-navigated-viewer.production.min.js +2 -0
- package/dist/cmmn-viewer.development.js +17599 -0
- package/dist/cmmn-viewer.production.min.js +2 -0
- package/index.js +1 -0
- package/lib/Modeler.js +222 -0
- package/lib/NavigatedViewer.js +28 -0
- package/lib/Viewer.js +489 -0
- package/lib/core/ItemRegistry.js +316 -0
- package/lib/core/index.js +7 -0
- package/lib/draw/CmmnRenderer.js +1235 -0
- package/lib/draw/PathMap.js +335 -0
- package/lib/draw/index.js +5 -0
- package/lib/features/auto-resize/CmmnAutoResizeProvider.js +57 -0
- package/lib/features/auto-resize/index.js +7 -0
- package/lib/features/context-pad/ContextPadProvider.js +240 -0
- package/lib/features/context-pad/index.js +11 -0
- package/lib/features/editor-actions/CmmnEditorActions.js +105 -0
- package/lib/features/editor-actions/index.js +10 -0
- package/lib/features/keyboard/CmmnKeyboardBindings.js +159 -0
- package/lib/features/keyboard/index.js +7 -0
- package/lib/features/label-editing/LabelEditingProvider.js +221 -0
- package/lib/features/label-editing/LabelUtil.js +95 -0
- package/lib/features/label-editing/cmd/UpdateLabelHandler.js +63 -0
- package/lib/features/label-editing/index.js +9 -0
- package/lib/features/modeling/CmmnFactory.js +166 -0
- package/lib/features/modeling/CmmnLayouter.js +49 -0
- package/lib/features/modeling/CmmnUpdater.js +511 -0
- package/lib/features/modeling/ElementFactory.js +215 -0
- package/lib/features/modeling/Modeling.js +185 -0
- package/lib/features/modeling/behavior/AttachCriterionBehavior.js +58 -0
- package/lib/features/modeling/behavior/CaseFileItemUpdater.js +324 -0
- package/lib/features/modeling/behavior/LabelBehavior.js +139 -0
- package/lib/features/modeling/behavior/PlanItemDefinitionUpdater.js +449 -0
- package/lib/features/modeling/behavior/PlanningTableUpdater.js +620 -0
- package/lib/features/modeling/behavior/ReplaceConnectionBehavior.js +320 -0
- package/lib/features/modeling/behavior/ReplaceElementBehavior.js +395 -0
- package/lib/features/modeling/behavior/ResizeCasePlanModelBehavior.js +108 -0
- package/lib/features/modeling/behavior/SentryUpdater.js +678 -0
- package/lib/features/modeling/behavior/UnclaimIdBehavior.js +28 -0
- package/lib/features/modeling/behavior/index.js +24 -0
- package/lib/features/modeling/cmd/AppendShapeHandler.js +52 -0
- package/lib/features/modeling/cmd/IdClaimHandler.js +38 -0
- package/lib/features/modeling/cmd/ReconnectConnectionHandler.js +57 -0
- package/lib/features/modeling/cmd/ReplaceShapeHandler.js +46 -0
- package/lib/features/modeling/cmd/UpdateControlsHandler.js +221 -0
- package/lib/features/modeling/cmd/UpdatePropertiesHandler.js +240 -0
- package/lib/features/modeling/cmd/UpdateSemanticParentHandler.js +94 -0
- package/lib/features/modeling/index.js +20 -0
- package/lib/features/modeling/util/ModelingUtil.js +138 -0
- package/lib/features/modeling/util/PlanItemDefinitionUtil.js +183 -0
- package/lib/features/ordering/CmmnOrderingProvider.js +146 -0
- package/lib/features/ordering/index.js +4 -0
- package/lib/features/outline/Outline.js +47 -0
- package/lib/features/outline/index.js +6 -0
- package/lib/features/palette/PaletteProvider.js +171 -0
- package/lib/features/palette/index.js +12 -0
- package/lib/features/popup-menu/ReplaceMenuProvider.js +448 -0
- package/lib/features/popup-menu/index.js +4 -0
- package/lib/features/replace/CmmnReplace.js +355 -0
- package/lib/features/replace/ReplaceOptions.js +241 -0
- package/lib/features/replace/index.js +8 -0
- package/lib/features/replace-preview/CmmnReplacePreview.js +247 -0
- package/lib/features/replace-preview/index.js +7 -0
- package/lib/features/rules/CmmnRules.js +1040 -0
- package/lib/features/rules/index.js +7 -0
- package/lib/features/search/CmmnSearchProvider.js +129 -0
- package/lib/features/search/index.js +7 -0
- package/lib/features/snapping/CmmnConnectSnapping.js +110 -0
- package/lib/features/snapping/CmmnCreateMoveSnapping.js +148 -0
- package/lib/features/snapping/CmmnResizeSnapping.js +42 -0
- package/lib/features/snapping/CmmnSnappingUtil.js +76 -0
- package/lib/features/snapping/index.js +17 -0
- package/lib/import/CmmnImporter.js +251 -0
- package/lib/import/CmmnTreeWalker.js +410 -0
- package/lib/import/Importer.js +73 -0
- package/lib/import/Util.js +9 -0
- package/lib/import/index.js +3 -0
- package/lib/util/DiUtil.js +39 -0
- package/lib/util/LabelUtil.js +124 -0
- package/lib/util/ModelUtil.js +257 -0
- package/lib/util/PoweredByUtil.js +91 -0
- package/package.json +88 -4
- package/test/helper/index.js +231 -0
- package/test/util/KeyEvents.js +23 -0
- package/test/util/MockEvents.js +55 -0
- package/test/util/custom-rules/CustomRules.js +19 -0
- package/test/util/custom-rules/index.js +4 -0
package/lib/Viewer.js
ADDED
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The code in the <project-logo></project-logo> area
|
|
3
|
+
* must not be changed.
|
|
4
|
+
*
|
|
5
|
+
* @see http://bpmn.io/license for more information.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var assign = require('min-dash').assign,
|
|
10
|
+
omit = require('min-dash').omit,
|
|
11
|
+
isNumber = require('min-dash').isNumber;
|
|
12
|
+
|
|
13
|
+
var inherits = require('inherits');
|
|
14
|
+
|
|
15
|
+
var domify = require('min-dom').domify,
|
|
16
|
+
domQuery = require('min-dom').query,
|
|
17
|
+
domRemove = require('min-dom').remove;
|
|
18
|
+
|
|
19
|
+
var innerSVG = require('tiny-svg').innerSVG;
|
|
20
|
+
|
|
21
|
+
var Diagram = require('diagram-js').default,
|
|
22
|
+
CmmnModdle = require('@jylups/cmmn-moddle').default;
|
|
23
|
+
|
|
24
|
+
var Importer = require('./import/Importer');
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function checkValidationError(err) {
|
|
28
|
+
|
|
29
|
+
// check if we can help the user by indicating wrong CMMN 1.1 xml
|
|
30
|
+
// (in case he or the exporting tool did not get that right)
|
|
31
|
+
|
|
32
|
+
var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
|
|
33
|
+
var match = pattern.exec(err.message);
|
|
34
|
+
|
|
35
|
+
if (match) {
|
|
36
|
+
err.message =
|
|
37
|
+
'unparsable content <' + match[1] + '> detected; ' +
|
|
38
|
+
'this may indicate an invalid CMMN 1.1 diagram file' + match[2];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return err;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var DEFAULT_OPTIONS = {
|
|
45
|
+
width: '100%',
|
|
46
|
+
height: '100%',
|
|
47
|
+
position: 'relative'
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Ensure the passed argument is a proper unit (defaulting to px)
|
|
53
|
+
*/
|
|
54
|
+
function ensureUnit(val) {
|
|
55
|
+
return val + (isNumber(val) ? 'px' : '');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A viewer for CMMN 1.1 diagrams.
|
|
60
|
+
*
|
|
61
|
+
* Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
|
|
62
|
+
* additional features.
|
|
63
|
+
*
|
|
64
|
+
*
|
|
65
|
+
* ## Extending the Viewer
|
|
66
|
+
*
|
|
67
|
+
* In order to extend the viewer pass extension modules to bootstrap via the
|
|
68
|
+
* `additionalModules` option. An extension module is an object that exposes
|
|
69
|
+
* named services.
|
|
70
|
+
*
|
|
71
|
+
* The following example depicts the integration of a simple
|
|
72
|
+
* logging component that integrates with interaction events:
|
|
73
|
+
*
|
|
74
|
+
*
|
|
75
|
+
* ```javascript
|
|
76
|
+
*
|
|
77
|
+
* // logging component
|
|
78
|
+
* function InteractionLogger(eventBus) {
|
|
79
|
+
* eventBus.on('element.hover', function(event) {
|
|
80
|
+
* console.log()
|
|
81
|
+
* })
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* InteractionLogger.$inject = [ 'eventBus' ]; // minification save
|
|
85
|
+
*
|
|
86
|
+
* // extension module
|
|
87
|
+
* var extensionModule = {
|
|
88
|
+
* __init__: [ 'interactionLogger' ],
|
|
89
|
+
* interactionLogger: [ 'type', InteractionLogger ]
|
|
90
|
+
* };
|
|
91
|
+
*
|
|
92
|
+
* // extend the viewer
|
|
93
|
+
* var cmmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
|
|
94
|
+
* cmmnViewer.importXML(...);
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @param {Object} [options] configuration options to pass to the viewer
|
|
98
|
+
* @param {DOMElement} [options.container] the container to attach to
|
|
99
|
+
* @param {String|Number} [options.width] the width of the viewer
|
|
100
|
+
* @param {String|Number} [options.height] the height of the viewer
|
|
101
|
+
* @param {Object} [options.moddleExtensions] extension packages to provide
|
|
102
|
+
* @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
|
|
103
|
+
* @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
|
|
104
|
+
*/
|
|
105
|
+
function Viewer(options) {
|
|
106
|
+
|
|
107
|
+
options = assign({}, DEFAULT_OPTIONS, options);
|
|
108
|
+
|
|
109
|
+
this._moddle = this._createModdle(options);
|
|
110
|
+
|
|
111
|
+
this._container = this._createContainer(options);
|
|
112
|
+
|
|
113
|
+
/* <project-logo> */
|
|
114
|
+
|
|
115
|
+
addProjectLogo(this._container);
|
|
116
|
+
|
|
117
|
+
/* </project-logo> */
|
|
118
|
+
|
|
119
|
+
this._init(this._container, this._moddle, options);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
inherits(Viewer, Diagram);
|
|
123
|
+
|
|
124
|
+
module.exports = Viewer;
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Parse and render a CMMN 1.1 diagram.
|
|
129
|
+
*
|
|
130
|
+
* Once finished the viewer reports back the result to the
|
|
131
|
+
* provided callback function with (err, warnings).
|
|
132
|
+
*
|
|
133
|
+
* ## Life-Cycle Events
|
|
134
|
+
*
|
|
135
|
+
* During import the viewer will fire life-cycle events:
|
|
136
|
+
*
|
|
137
|
+
* * import.parse.start (about to read model from xml)
|
|
138
|
+
* * import.parse.complete (model read; may have worked or not)
|
|
139
|
+
* * import.render.start (graphical import start)
|
|
140
|
+
* * import.render.complete (graphical import finished)
|
|
141
|
+
* * import.done (everything done)
|
|
142
|
+
*
|
|
143
|
+
* You can use these events to hook into the life-cycle.
|
|
144
|
+
*
|
|
145
|
+
* @param {String} xml the CMMN 1.1 xml
|
|
146
|
+
* @param {Function} [done] invoked with (err, warnings=[])
|
|
147
|
+
*/
|
|
148
|
+
Viewer.prototype.importXML = function(xml, done) {
|
|
149
|
+
|
|
150
|
+
// done is optional
|
|
151
|
+
done = done || function() {};
|
|
152
|
+
|
|
153
|
+
var self = this;
|
|
154
|
+
|
|
155
|
+
// hook in pre-parse listeners +
|
|
156
|
+
// allow xml manipulation
|
|
157
|
+
xml = this._emit('import.parse.start', { xml: xml }) || xml;
|
|
158
|
+
|
|
159
|
+
this._moddle.fromXML(xml, 'cmmn:Definitions', function(err, definitions, context) {
|
|
160
|
+
|
|
161
|
+
// hook in post parse listeners +
|
|
162
|
+
// allow definitions manipulation
|
|
163
|
+
definitions = self._emit('import.parse.complete', {
|
|
164
|
+
error: err,
|
|
165
|
+
definitions: definitions,
|
|
166
|
+
context: context
|
|
167
|
+
}) || definitions;
|
|
168
|
+
|
|
169
|
+
var parseWarnings = context.warnings;
|
|
170
|
+
|
|
171
|
+
if (err) {
|
|
172
|
+
err = checkValidationError(err);
|
|
173
|
+
|
|
174
|
+
self._emit('import.done', { error: err, warnings: parseWarnings });
|
|
175
|
+
|
|
176
|
+
return done(err, parseWarnings);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
self.importDefinitions(definitions, function(err, importWarnings) {
|
|
180
|
+
var allWarnings = [].concat(parseWarnings, importWarnings || []);
|
|
181
|
+
|
|
182
|
+
self._emit('import.done', { error: err, warnings: allWarnings });
|
|
183
|
+
|
|
184
|
+
done(err, allWarnings);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Export the currently displayed CMMN 1.1 diagram as
|
|
191
|
+
* a CMMN 1.1 XML document.
|
|
192
|
+
*
|
|
193
|
+
* ## Life-Cycle Events
|
|
194
|
+
*
|
|
195
|
+
* During XML saving the viewer will fire life-cycle events:
|
|
196
|
+
*
|
|
197
|
+
* * saveXML.start (before serialization)
|
|
198
|
+
* * saveXML.serialized (after xml generation)
|
|
199
|
+
* * saveXML.done (everything done)
|
|
200
|
+
*
|
|
201
|
+
* You can use these events to hook into the life-cycle.
|
|
202
|
+
*
|
|
203
|
+
* @param {Object} [options] export options
|
|
204
|
+
* @param {Boolean} [options.format=false] output formated XML
|
|
205
|
+
* @param {Boolean} [options.preamble=true] output preamble
|
|
206
|
+
*
|
|
207
|
+
* @param {Function} done invoked with (err, xml)
|
|
208
|
+
*/
|
|
209
|
+
Viewer.prototype.saveXML = function(options, done) {
|
|
210
|
+
|
|
211
|
+
if (!done) {
|
|
212
|
+
done = options;
|
|
213
|
+
options = {};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var self = this;
|
|
217
|
+
|
|
218
|
+
var definitions = this._definitions;
|
|
219
|
+
|
|
220
|
+
if (!definitions) {
|
|
221
|
+
return done(new Error('no definitions loaded'));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// allow to fiddle around with definitions
|
|
225
|
+
definitions = this._emit('saveXML.start', {
|
|
226
|
+
definitions: definitions
|
|
227
|
+
}) || definitions;
|
|
228
|
+
|
|
229
|
+
this._moddle.toXML(definitions, options, function(err, xml) {
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
xml = self._emit('saveXML.serialized', {
|
|
233
|
+
error: err,
|
|
234
|
+
xml: xml
|
|
235
|
+
}) || xml;
|
|
236
|
+
|
|
237
|
+
self._emit('saveXML.done', {
|
|
238
|
+
error: err,
|
|
239
|
+
xml: xml
|
|
240
|
+
});
|
|
241
|
+
} catch (e) {
|
|
242
|
+
console.error('error in saveXML life-cycle listener', e);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
done(err, xml);
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
Viewer.prototype.saveSVG = function(options, done) {
|
|
250
|
+
|
|
251
|
+
if (!done) {
|
|
252
|
+
done = options;
|
|
253
|
+
options = {};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
var canvas = this.get('canvas');
|
|
257
|
+
|
|
258
|
+
var contentNode = canvas.getDefaultLayer(),
|
|
259
|
+
defsNode = domQuery('defs', canvas._svg);
|
|
260
|
+
|
|
261
|
+
var contents = innerSVG(contentNode),
|
|
262
|
+
defs = (defsNode && defsNode.outerHTML) || '';
|
|
263
|
+
|
|
264
|
+
var bbox = contentNode.getBBox();
|
|
265
|
+
|
|
266
|
+
var svg =
|
|
267
|
+
'<?xml version="1.0" encoding="utf-8"?>\n' +
|
|
268
|
+
'<!-- created with cmmn-js / http://bpmn.io -->\n' +
|
|
269
|
+
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
|
|
270
|
+
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
|
|
271
|
+
'width="' + bbox.width + '" height="' + bbox.height + '" ' +
|
|
272
|
+
'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
|
|
273
|
+
defs + contents +
|
|
274
|
+
'</svg>';
|
|
275
|
+
|
|
276
|
+
done(null, svg);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
Viewer.prototype.importDefinitions = function(definitions, done) {
|
|
280
|
+
|
|
281
|
+
// use try/catch to not swallow synchronous exceptions
|
|
282
|
+
// that may be raised during model parsing
|
|
283
|
+
try {
|
|
284
|
+
|
|
285
|
+
if (this._definitions) {
|
|
286
|
+
// clear existing rendered diagram
|
|
287
|
+
this.clear();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// update definitions
|
|
291
|
+
this._definitions = definitions;
|
|
292
|
+
|
|
293
|
+
// perform graphical import
|
|
294
|
+
Importer.importCmmnDiagram(this, definitions, done);
|
|
295
|
+
} catch (e) {
|
|
296
|
+
|
|
297
|
+
// handle synchronous errors
|
|
298
|
+
done(e);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
Viewer.prototype.attachTo = function(parentNode) {
|
|
303
|
+
|
|
304
|
+
if (!parentNode) {
|
|
305
|
+
throw new Error('parentNode required');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ensure we detach from the
|
|
309
|
+
// previous, old parent
|
|
310
|
+
this.detach();
|
|
311
|
+
|
|
312
|
+
// unwrap jQuery if provided
|
|
313
|
+
if (parentNode.get && parentNode.constructor.prototype.jquery) {
|
|
314
|
+
parentNode = parentNode.get(0);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (typeof parentNode === 'string') {
|
|
318
|
+
parentNode = domQuery(parentNode);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
parentNode.appendChild(this._container);
|
|
322
|
+
|
|
323
|
+
this._emit('attach', {});
|
|
324
|
+
|
|
325
|
+
this.get('canvas').resized();
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
Viewer.prototype.getDefinitions = function() {
|
|
329
|
+
return this._definitions;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
Viewer.prototype.detach = function() {
|
|
333
|
+
|
|
334
|
+
var container = this._container,
|
|
335
|
+
parentNode = container.parentNode;
|
|
336
|
+
|
|
337
|
+
if (!parentNode) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
this._emit('detach', {});
|
|
342
|
+
|
|
343
|
+
parentNode.removeChild(container);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
Viewer.prototype.getModules = function() {
|
|
347
|
+
return this._modules;
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Destroy the viewer instance and remove all its
|
|
352
|
+
* remainders from the document tree.
|
|
353
|
+
*/
|
|
354
|
+
Viewer.prototype.destroy = function() {
|
|
355
|
+
|
|
356
|
+
// diagram destroy
|
|
357
|
+
Diagram.prototype.destroy.call(this);
|
|
358
|
+
|
|
359
|
+
// dom detach
|
|
360
|
+
domRemove(this._container);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Register an event listener
|
|
365
|
+
*
|
|
366
|
+
* Remove a previously added listener via {@link #off(event, callback)}.
|
|
367
|
+
*
|
|
368
|
+
* @param {String} event
|
|
369
|
+
* @param {Number} [priority]
|
|
370
|
+
* @param {Function} callback
|
|
371
|
+
* @param {Object} [that]
|
|
372
|
+
*/
|
|
373
|
+
Viewer.prototype.on = function(event, priority, callback, target) {
|
|
374
|
+
return this.get('eventBus').on(event, priority, callback, target);
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* De-register an event listener
|
|
379
|
+
*
|
|
380
|
+
* @param {String} event
|
|
381
|
+
* @param {Function} callback
|
|
382
|
+
*/
|
|
383
|
+
Viewer.prototype.off = function(event, callback) {
|
|
384
|
+
this.get('eventBus').off(event, callback);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
Viewer.prototype._init = function(container, moddle, options) {
|
|
389
|
+
|
|
390
|
+
var baseModules = options.modules || this.getModules(),
|
|
391
|
+
additionalModules = options.additionalModules || [],
|
|
392
|
+
staticModules = [
|
|
393
|
+
{
|
|
394
|
+
cmmnjs: [ 'value', this ],
|
|
395
|
+
moddle: [ 'value', moddle ]
|
|
396
|
+
}
|
|
397
|
+
];
|
|
398
|
+
|
|
399
|
+
var diagramModules = [].concat(staticModules, baseModules, additionalModules);
|
|
400
|
+
|
|
401
|
+
var diagramOptions = assign(omit(options, 'additionalModules'), {
|
|
402
|
+
canvas: assign({}, options.canvas, { container: container }),
|
|
403
|
+
modules: diagramModules
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// invoke diagram constructor
|
|
407
|
+
Diagram.call(this, diagramOptions);
|
|
408
|
+
|
|
409
|
+
if (options && options.container) {
|
|
410
|
+
this.attachTo(options.container);
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Emit an event on the underlying {@link EventBus}
|
|
416
|
+
*
|
|
417
|
+
* @param {String} type
|
|
418
|
+
* @param {Object} event
|
|
419
|
+
*
|
|
420
|
+
* @return {Object} event processing result (if any)
|
|
421
|
+
*/
|
|
422
|
+
Viewer.prototype._emit = function(type, event) {
|
|
423
|
+
return this.get('eventBus').fire(type, event);
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
Viewer.prototype._createContainer = function(options) {
|
|
427
|
+
|
|
428
|
+
var container = domify('<div class="cjs-container"></div>');
|
|
429
|
+
|
|
430
|
+
assign(container.style, {
|
|
431
|
+
width: ensureUnit(options.width),
|
|
432
|
+
height: ensureUnit(options.height),
|
|
433
|
+
position: options.position
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
return container;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
Viewer.prototype._createModdle = function(options) {
|
|
440
|
+
var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
|
|
441
|
+
|
|
442
|
+
return new CmmnModdle(moddleOptions);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
// modules the viewer is composed of
|
|
447
|
+
Viewer.prototype._modules = [
|
|
448
|
+
require('./core'),
|
|
449
|
+
require('diagram-js/lib/features/selection').default,
|
|
450
|
+
require('diagram-js/lib/features/overlays').default
|
|
451
|
+
];
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
/* <project-logo> */
|
|
455
|
+
|
|
456
|
+
var PoweredBy = require('./util/PoweredByUtil'),
|
|
457
|
+
domEvent = require('min-dom').event;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Adds the project logo to the diagram container as
|
|
461
|
+
* required by the bpmn.io license.
|
|
462
|
+
*
|
|
463
|
+
* @see http://bpmn.io/license
|
|
464
|
+
*
|
|
465
|
+
* @param {Element} container
|
|
466
|
+
*/
|
|
467
|
+
function addProjectLogo(container) {
|
|
468
|
+
|
|
469
|
+
var linkMarkup =
|
|
470
|
+
'<a href="http://bpmn.io" ' +
|
|
471
|
+
'target="_blank" ' +
|
|
472
|
+
'class="bjs-powered-by" ' +
|
|
473
|
+
'title="Powered by bpmn.io" ' +
|
|
474
|
+
'style="position: absolute; bottom: 15px; right: 15px; z-index: 100; ' + PoweredBy.LINK_STYLES + '">' +
|
|
475
|
+
PoweredBy.BPMNIO_IMG +
|
|
476
|
+
'</a>';
|
|
477
|
+
|
|
478
|
+
var linkElement = domify(linkMarkup);
|
|
479
|
+
|
|
480
|
+
container.appendChild(linkElement);
|
|
481
|
+
|
|
482
|
+
domEvent.bind(linkElement, 'click', function(event) {
|
|
483
|
+
PoweredBy.open();
|
|
484
|
+
|
|
485
|
+
event.preventDefault();
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/* </project-logo> */
|