This commit is contained in:
hanjian
2024-08-14 15:17:51 +08:00
parent 20a221c1a2
commit b610f94b2e
3483 changed files with 650965 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import {
isString,
assign
} from 'min-dash';
/**
* Create a fake key event for testing purposes.
*
* @param {String|Number} key the key or keyCode/charCode
* @param {Object} [attrs]
*
* @return {Event}
*/
export function createKeyEvent(key, attrs) {
var event = document.createEvent('Events') || new document.defaultView.CustomEvent('keyEvent');
// init and mark as bubbles / cancelable
event.initEvent('keydown', false, true);
var keyAttrs = isString(key) ? { key: key } : { keyCode: key, which: key };
return assign(event, keyAttrs, attrs || {});
}

View File

@@ -0,0 +1,53 @@
import {
assign
} from 'min-dash';
import {
getBpmnJS
} from 'test/TestHelper';
/**
* Create an event with global coordinates
* computed based on the loaded diagrams canvas position and the
* specified canvas local coordinates.
*
* @param {Point} point of the event local the canvas (closure)
* @param {Object} data
*
* @return {Event} event, scoped to the given canvas
*/
export function createCanvasEvent(position, data) {
return getBpmnJS().invoke(function(canvas) {
var target = canvas._svg;
var clientRect = canvas._container.getBoundingClientRect();
var absolutePosition = {
x: position.x + clientRect.left,
y: position.y + clientRect.top
};
return createEvent(target, absolutePosition, data);
});
}
export function createEvent(target, position, data) {
return getBpmnJS().invoke(function(eventBus) {
data = assign({
target: target,
x: position.x,
y: position.y,
clientX: position.x,
clientY: position.y,
offsetX: position.x,
offsetY: position.y
}, data || {});
return eventBus.createEvent(data);
});
}

View File

@@ -0,0 +1,16 @@
import inherits from 'inherits';
import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider';
export default function CustomRules(eventBus) {
RuleProvider.call(this, eventBus);
}
CustomRules.$inject = [ 'eventBus' ];
inherits(CustomRules, RuleProvider);
CustomRules.prototype.init = function() {
// placeholder
};

View File

@@ -0,0 +1,6 @@
import CustomRules from './CustomRules';
export default {
__init__: [ 'customRules' ],
customRules: [ 'type', CustomRules ]
};