chunk-6IT32OMX.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {
  2. forEach,
  3. isArray,
  4. isFunction,
  5. isNumber,
  6. isObject
  7. } from "./chunk-4AK4GF4H.js";
  8. // node_modules/.pnpm/diagram-js@11.9.1/node_modules/diagram-js/lib/command/CommandInterceptor.js
  9. var DEFAULT_PRIORITY = 1e3;
  10. function CommandInterceptor(eventBus) {
  11. this._eventBus = eventBus;
  12. }
  13. CommandInterceptor.$inject = ["eventBus"];
  14. function unwrapEvent(fn, that) {
  15. return function(event) {
  16. return fn.call(that || null, event.context, event.command, event);
  17. };
  18. }
  19. CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
  20. if (isFunction(hook) || isNumber(hook)) {
  21. that = unwrap;
  22. unwrap = handlerFn;
  23. handlerFn = priority;
  24. priority = hook;
  25. hook = null;
  26. }
  27. if (isFunction(priority)) {
  28. that = unwrap;
  29. unwrap = handlerFn;
  30. handlerFn = priority;
  31. priority = DEFAULT_PRIORITY;
  32. }
  33. if (isObject(unwrap)) {
  34. that = unwrap;
  35. unwrap = false;
  36. }
  37. if (!isFunction(handlerFn)) {
  38. throw new Error("handlerFn must be a function");
  39. }
  40. if (!isArray(events)) {
  41. events = [events];
  42. }
  43. var eventBus = this._eventBus;
  44. forEach(events, function(event) {
  45. var fullEvent = ["commandStack", event, hook].filter(function(e) {
  46. return e;
  47. }).join(".");
  48. eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
  49. });
  50. };
  51. var hooks = [
  52. "canExecute",
  53. "preExecute",
  54. "preExecuted",
  55. "execute",
  56. "executed",
  57. "postExecute",
  58. "postExecuted",
  59. "revert",
  60. "reverted"
  61. ];
  62. forEach(hooks, function(hook) {
  63. CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
  64. if (isFunction(events) || isNumber(events)) {
  65. that = unwrap;
  66. unwrap = handlerFn;
  67. handlerFn = priority;
  68. priority = events;
  69. events = null;
  70. }
  71. this.on(events, hook, priority, handlerFn, unwrap, that);
  72. };
  73. });
  74. export {
  75. CommandInterceptor
  76. };
  77. //# sourceMappingURL=chunk-6IT32OMX.js.map