1 | import inherits from 'inherits-browser';
|
2 |
|
3 | import Ids from 'ids';
|
4 |
|
5 | import BaseViewer from './BaseViewer';
|
6 |
|
7 |
|
8 | /**
|
9 | * @typedef {import('./BaseViewer').BaseViewerOptions} BaseViewerOptions
|
10 | * @typedef {import('./BaseViewer').ModdleElementsById} ModdleElementsById
|
11 | *
|
12 | * @typedef {import('./model/Types').ModdleElement} ModdleElement
|
13 | */
|
14 |
|
15 | /**
|
16 | * A base modeler for BPMN 2.0 diagrams.
|
17 | *
|
18 | * See {@link Modeler} for a fully-featured modeler.
|
19 | *
|
20 | * @param {BaseViewerOptions} [options] The options to configure the modeler.
|
21 | */
|
22 | export default function BaseModeler(options) {
|
23 | BaseViewer.call(this, options);
|
24 |
|
25 | // hook ID collection into the modeler
|
26 | this.on('import.parse.complete', function(event) {
|
27 | if (!event.error) {
|
28 | this._collectIds(event.definitions, event.elementsById);
|
29 | }
|
30 | }, this);
|
31 |
|
32 | this.on('diagram.destroy', function() {
|
33 | this.get('moddle').ids.clear();
|
34 | }, this);
|
35 | }
|
36 |
|
37 | inherits(BaseModeler, BaseViewer);
|
38 |
|
39 |
|
40 | /**
|
41 | * Create a moddle instance, attaching IDs to it.
|
42 | *
|
43 | * @param {BaseViewerOptions} options
|
44 | *
|
45 | * @return {Moddle}
|
46 | */
|
47 | BaseModeler.prototype._createModdle = function(options) {
|
48 | var moddle = BaseViewer.prototype._createModdle.call(this, options);
|
49 |
|
50 | // attach ids to moddle to be able to track and validated ids in the BPMN 2.0
|
51 | // XML document tree
|
52 | moddle.ids = new Ids([ 32, 36, 1 ]);
|
53 |
|
54 | return moddle;
|
55 | };
|
56 |
|
57 | /**
|
58 | * Collect IDs processed during parsing of the definitions object.
|
59 | *
|
60 | * @param {ModdleElement} definitions
|
61 | * @param {ModdleElementsById} elementsById
|
62 | */
|
63 | BaseModeler.prototype._collectIds = function(definitions, elementsById) {
|
64 |
|
65 | var moddle = definitions.$model,
|
66 | ids = moddle.ids,
|
67 | id;
|
68 |
|
69 | // remove references from previous import
|
70 | ids.clear();
|
71 |
|
72 | for (id in elementsById) {
|
73 | ids.claim(id, elementsById[ id ]);
|
74 | }
|
75 | };
|