Viewer.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import inherits from 'inherits';
  2. import CoreModule from './core';
  3. import TranslateModule from 'diagram-js/lib/i18n/translate';
  4. import SelectionModule from 'diagram-js/lib/features/selection';
  5. import OverlaysModule from 'diagram-js/lib/features/overlays';
  6. import BaseViewer from './BaseViewer';
  7. /**
  8. * A viewer for BPMN 2.0 diagrams.
  9. *
  10. * Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
  11. * additional features.
  12. *
  13. *
  14. * ## Extending the Viewer
  15. *
  16. * In order to extend the viewer pass extension modules to bootstrap via the
  17. * `additionalModules` option. An extension module is an object that exposes
  18. * named services.
  19. *
  20. * The following example depicts the integration of a simple
  21. * logging component that integrates with interaction events:
  22. *
  23. *
  24. * ```javascript
  25. *
  26. * // logging component
  27. * function InteractionLogger(eventBus) {
  28. * eventBus.on('element.hover', function(event) {
  29. * console.log()
  30. * })
  31. * }
  32. *
  33. * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
  34. *
  35. * // extension module
  36. * var extensionModule = {
  37. * __init__: [ 'interactionLogger' ],
  38. * interactionLogger: [ 'type', InteractionLogger ]
  39. * };
  40. *
  41. * // extend the viewer
  42. * var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
  43. * bpmnViewer.importXML(...);
  44. * ```
  45. *
  46. * @param {Object} [options] configuration options to pass to the viewer
  47. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  48. * @param {string|number} [options.width] the width of the viewer
  49. * @param {string|number} [options.height] the height of the viewer
  50. * @param {Object} [options.moddleExtensions] extension packages to provide
  51. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  52. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  53. */
  54. export default function Viewer(options) {
  55. BaseViewer.call(this, options);
  56. }
  57. inherits(Viewer, BaseViewer);
  58. // modules the viewer is composed of
  59. Viewer.prototype._modules = [
  60. CoreModule,
  61. TranslateModule,
  62. SelectionModule,
  63. OverlaysModule
  64. ];
  65. // default moddle extensions the viewer is composed of
  66. Viewer.prototype._moddleExtensions = {};