123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- import inherits from 'inherits';
- import BaseModeler from './BaseModeler';
- import Viewer from './Viewer';
- import NavigatedViewer from './NavigatedViewer';
- import KeyboardMoveModule from 'diagram-js/lib/navigation/keyboard-move';
- import MoveCanvasModule from 'diagram-js/lib/navigation/movecanvas';
- import TouchModule from 'diagram-js/lib/navigation/touch';
- import ZoomScrollModule from 'diagram-js/lib/navigation/zoomscroll';
- import AlignElementsModule from 'diagram-js/lib/features/align-elements';
- import AutoPlaceModule from './features/auto-place';
- import AutoResizeModule from './features/auto-resize';
- import AutoScrollModule from 'diagram-js/lib/features/auto-scroll';
- import BendpointsModule from 'diagram-js/lib/features/bendpoints';
- import ConnectModule from 'diagram-js/lib/features/connect';
- import ConnectionPreviewModule from 'diagram-js/lib/features/connection-preview';
- import ContextPadModule from './features/context-pad';
- import CopyPasteModule from './features/copy-paste';
- import CreateModule from 'diagram-js/lib/features/create';
- import DistributeElementsModule from './features/distribute-elements';
- import EditorActionsModule from './features/editor-actions';
- import GridSnappingModule from './features/grid-snapping';
- import InteractionEventsModule from './features/interaction-events';
- import KeyboardModule from './features/keyboard';
- import KeyboardMoveSelectionModule from 'diagram-js/lib/features/keyboard-move-selection';
- import LabelEditingModule from './features/label-editing';
- import ModelingModule from './features/modeling';
- import MoveModule from 'diagram-js/lib/features/move';
- import PaletteModule from './features/palette';
- import ReplacePreviewModule from './features/replace-preview';
- import ResizeModule from 'diagram-js/lib/features/resize';
- import SnappingModule from './features/snapping';
- import SearchModule from './features/search';
- var initialDiagram =
- '<?xml version="1.0" encoding="UTF-8"?>' +
- '<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
- 'xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" ' +
- 'xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" ' +
- 'xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" ' +
- 'targetNamespace="http://bpmn.io/schema/bpmn" ' +
- 'id="Definitions_1">' +
- '<bpmn:process id="Process_1" isExecutable="false">' +
- '<bpmn:startEvent id="StartEvent_1"/>' +
- '</bpmn:process>' +
- '<bpmndi:BPMNDiagram id="BPMNDiagram_1">' +
- '<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">' +
- '<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">' +
- '<dc:Bounds height="36.0" width="36.0" x="173.0" y="102.0"/>' +
- '</bpmndi:BPMNShape>' +
- '</bpmndi:BPMNPlane>' +
- '</bpmndi:BPMNDiagram>' +
- '</bpmn:definitions>';
- /**
- * A modeler for BPMN 2.0 diagrams.
- *
- *
- * ## Extending the Modeler
- *
- * In order to extend the viewer pass extension modules to bootstrap via the
- * `additionalModules` option. An extension module is an object that exposes
- * named services.
- *
- * The following example depicts the integration of a simple
- * logging component that integrates with interaction events:
- *
- *
- * ```javascript
- *
- * // logging component
- * function InteractionLogger(eventBus) {
- * eventBus.on('element.hover', function(event) {
- * console.log()
- * })
- * }
- *
- * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
- *
- * // extension module
- * var extensionModule = {
- * __init__: [ 'interactionLogger' ],
- * interactionLogger: [ 'type', InteractionLogger ]
- * };
- *
- * // extend the viewer
- * var bpmnModeler = new Modeler({ additionalModules: [ extensionModule ] });
- * bpmnModeler.importXML(...);
- * ```
- *
- *
- * ## Customizing / Replacing Components
- *
- * You can replace individual diagram components by redefining them in override modules.
- * This works for all components, including those defined in the core.
- *
- * Pass in override modules via the `options.additionalModules` flag like this:
- *
- * ```javascript
- * function CustomContextPadProvider(contextPad) {
- *
- * contextPad.registerProvider(this);
- *
- * this.getContextPadEntries = function(element) {
- * // no entries, effectively disable the context pad
- * return {};
- * };
- * }
- *
- * CustomContextPadProvider.$inject = [ 'contextPad' ];
- *
- * var overrideModule = {
- * contextPadProvider: [ 'type', CustomContextPadProvider ]
- * };
- *
- * var bpmnModeler = new Modeler({ additionalModules: [ overrideModule ]});
- * ```
- *
- * @param {Object} [options] configuration options to pass to the viewer
- * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
- * @param {string|number} [options.width] the width of the viewer
- * @param {string|number} [options.height] the height of the viewer
- * @param {Object} [options.moddleExtensions] extension packages to provide
- * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
- * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
- */
- export default function Modeler(options) {
- BaseModeler.call(this, options);
- }
- inherits(Modeler, BaseModeler);
- Modeler.Viewer = Viewer;
- Modeler.NavigatedViewer = NavigatedViewer;
- /**
- * Create a new diagram to start modeling.
- *
- * @param {Function} [done]
- */
- Modeler.prototype.createDiagram = function(done) {
- return this.importXML(initialDiagram, done);
- };
- Modeler.prototype._interactionModules = [
- // non-modeling components
- KeyboardMoveModule,
- MoveCanvasModule,
- TouchModule,
- ZoomScrollModule
- ];
- Modeler.prototype._modelingModules = [
- // modeling components
- AlignElementsModule,
- AutoPlaceModule,
- AutoScrollModule,
- AutoResizeModule,
- BendpointsModule,
- ConnectModule,
- ConnectionPreviewModule,
- ContextPadModule,
- CopyPasteModule,
- CreateModule,
- DistributeElementsModule,
- EditorActionsModule,
- GridSnappingModule,
- InteractionEventsModule,
- KeyboardModule,
- KeyboardMoveSelectionModule,
- LabelEditingModule,
- ModelingModule,
- MoveModule,
- PaletteModule,
- ReplacePreviewModule,
- ResizeModule,
- SnappingModule,
- SearchModule
- ];
- // modules the modeler is composed of
- //
- // - viewer modules
- // - interaction modules
- // - modeling modules
- Modeler.prototype._modules = [].concat(
- Viewer.prototype._modules,
- Modeler.prototype._interactionModules,
- Modeler.prototype._modelingModules
- );
|