mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
1c97901299
commit
bb06b0a0c9
1 changed files with 27 additions and 10 deletions
|
@ -28,7 +28,7 @@ const resetHandler = () => {
|
|||
window.onmouseup = null;
|
||||
};
|
||||
|
||||
const setupHandler = (commit, target) => {
|
||||
const setupHandler = (commit, target, initialCallback, initialClientX, initialClientY) => {
|
||||
// Ancestor has to be identified on setup, rather than 1st interaction, otherwise events may be triggered on
|
||||
// DOM elements that had been removed: kibana-canvas github issue #1093
|
||||
const canvasPage = ancestorElement(target);
|
||||
|
@ -63,6 +63,10 @@ const setupHandler = (commit, target) => {
|
|||
commit('mouseEvent', { event: 'mouseUp', x, y, altKey, metaKey, shiftKey, ctrlKey });
|
||||
resetHandler();
|
||||
};
|
||||
if (typeof initialCallback === 'function' && !isNaN(initialClientX) && !isNaN(initialClientY)) {
|
||||
const { x, y } = localMousePosition(canvasOrigin, initialClientX, initialClientY);
|
||||
initialCallback(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
const handleMouseMove = (
|
||||
|
@ -72,9 +76,13 @@ const handleMouseMove = (
|
|||
) => {
|
||||
// mouse move must be handled even before an initial click
|
||||
if (!window.onmousemove && isEditable) {
|
||||
const { x, y } = localMousePosition(target, clientX, clientY);
|
||||
setupHandler(commit, target);
|
||||
commit('cursorPosition', { x, y, altKey, metaKey, shiftKey, ctrlKey });
|
||||
setupHandler(
|
||||
commit,
|
||||
target,
|
||||
(x, y) => commit('cursorPosition', { x, y, altKey, metaKey, shiftKey, ctrlKey }),
|
||||
clientX,
|
||||
clientY
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -85,9 +93,13 @@ const handleWheel = (
|
|||
) => {
|
||||
// new mouse position must be registered when page scrolls
|
||||
if (isEditable) {
|
||||
const { x, y } = localMousePosition(target, clientX, clientY);
|
||||
setupHandler(commit, target);
|
||||
commit('cursorPosition', { x, y, altKey, metaKey, shiftKey, ctrlKey });
|
||||
setupHandler(
|
||||
commit,
|
||||
target,
|
||||
(x, y) => commit('cursorPosition', { x, y, altKey, metaKey, shiftKey, ctrlKey }),
|
||||
clientX,
|
||||
clientY
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -102,9 +114,14 @@ const handleMouseDown = (commit, e, isEditable) => {
|
|||
if (!ancestor) {
|
||||
return;
|
||||
}
|
||||
const { x, y } = localMousePosition(ancestor, clientX, clientY);
|
||||
setupHandler(commit, ancestor);
|
||||
commit('mouseEvent', { event: 'mouseDown', x, y, altKey, metaKey, shiftKey, ctrlKey });
|
||||
setupHandler(
|
||||
commit,
|
||||
ancestor,
|
||||
(x, y) =>
|
||||
commit('mouseEvent', { event: 'mouseDown', x, y, altKey, metaKey, shiftKey, ctrlKey }),
|
||||
clientX,
|
||||
clientY
|
||||
);
|
||||
};
|
||||
|
||||
const keyCode = key => (key === 'Meta' ? 'MetaLeft' : 'Key' + key.toUpperCase());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue