mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-18 22:45:48 +01:00
36 lines
848 B
JavaScript
36 lines
848 B
JavaScript
|
|
export function mapActionBehavior(actionIdGetter) {
|
|
return ({services}, props) => {
|
|
const actionId = actionIdGetter(props);
|
|
|
|
let request = {actionId, x:0, y:0};
|
|
let canceled = true;
|
|
let shown = false;
|
|
|
|
function updateCoords({pageX, pageY}) {
|
|
request.x = pageX + 10;
|
|
request.y = pageY + 10;
|
|
}
|
|
|
|
return {
|
|
onClick: e => services.action.run(actionId, e),
|
|
onMouseEnter: e => {
|
|
updateCoords(e);
|
|
canceled = false;
|
|
shown = false;
|
|
setTimeout(() => {
|
|
if (!canceled) {
|
|
shown = true;
|
|
services.action.showHintFor(request)
|
|
}
|
|
}, 500);
|
|
},
|
|
onMouseMove: updateCoords,
|
|
onMouseLeave: () => {
|
|
canceled = true;
|
|
if (shown) {
|
|
services.action.showHintFor(null)
|
|
}
|
|
}
|
|
}};
|
|
}
|