mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 08:53:25 +01:00
improve action hint behavior
This commit is contained in:
parent
8396629277
commit
8d06e86708
4 changed files with 42 additions and 30 deletions
|
|
@ -75,6 +75,8 @@ export default class Bus {
|
|||
}
|
||||
|
||||
dispatch(key, data) {
|
||||
console.log('dispatch: ' + key + ' -> ' + JSON.stringify(data));
|
||||
|
||||
if (this.lock.has(key)) {
|
||||
console.warn('recursive dispatch');
|
||||
return
|
||||
|
|
|
|||
|
|
@ -4,9 +4,35 @@ export function mapActionBehavior(actionIdProp) {
|
|||
return ({dispatch}, props) => {
|
||||
const actionId = props[actionIdProp];
|
||||
const actionRunToken = ACTION_TOKENS.actionRun(actionId);
|
||||
|
||||
let request = {actionId, x:0, y:0};
|
||||
let canceled = true;
|
||||
let showed = false;
|
||||
|
||||
function updateCoords({pageX, pageY}) {
|
||||
request.x = pageX + 10;
|
||||
request.y = pageY + 10;
|
||||
}
|
||||
|
||||
return {
|
||||
onClick: data => dispatch(actionRunToken, data),
|
||||
onMouseEnter: ({pageX, pageY}) => dispatch(ACTION_TOKENS.SHOW_HINT_FOR, [actionId, pageX, pageY]),
|
||||
onMouseLeave: () => dispatch(ACTION_TOKENS.SHOW_HINT_FOR, null)
|
||||
onMouseEnter: e => {
|
||||
updateCoords(e);
|
||||
canceled = false;
|
||||
showed = false;
|
||||
setTimeout(() => {
|
||||
if (!canceled) {
|
||||
showed = true;
|
||||
dispatch(ACTION_TOKENS.SHOW_HINT_FOR, request)
|
||||
}
|
||||
}, 500);
|
||||
},
|
||||
onMouseMove: updateCoords,
|
||||
onMouseLeave: () => {
|
||||
canceled = true;
|
||||
if (showed) {
|
||||
dispatch(ACTION_TOKENS.SHOW_HINT_FOR, null)
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,35 +59,18 @@ export function activate(context) {
|
|||
|
||||
function synchActionHint(bus) {
|
||||
|
||||
let lastRequest = null;
|
||||
|
||||
// bus.subscribe(TOKENS.REQUEST_SHOW_HINT_FOR
|
||||
bus.subscribe(TOKENS.SHOW_HINT_FOR, request => {
|
||||
if (lastRequest !== null) {
|
||||
if (request !== null) {
|
||||
if (request[0] === lastRequest[0]) {
|
||||
Object.assign(lastRequest, request);
|
||||
return;
|
||||
}
|
||||
}
|
||||
lastRequest.spoiled = true;
|
||||
}
|
||||
lastRequest = request;
|
||||
if (request) {
|
||||
setTimeout(() => {
|
||||
if (!request.spoiled) {
|
||||
let [actionId, x, y] = request;
|
||||
let actionState = bus.getState(TOKENS.actionState(actionId));
|
||||
let actionAppearance = bus.getState(TOKENS.actionAppearance(actionId));
|
||||
if (actionState && actionAppearance) {
|
||||
bus.dispatch(TOKENS.HINT, {
|
||||
actionId, x: x + 10, y: y + 10,
|
||||
info: actionAppearance.info,
|
||||
hint: actionState.hint
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 500);
|
||||
let {actionId, x, y} = request;
|
||||
let actionState = bus.getState(TOKENS.actionState(actionId));
|
||||
let actionAppearance = bus.getState(TOKENS.actionAppearance(actionId));
|
||||
if (actionState && actionAppearance) {
|
||||
bus.dispatch(TOKENS.HINT, {
|
||||
actionId, x, y,
|
||||
info: actionAppearance.info,
|
||||
hint: actionState.hint
|
||||
});
|
||||
}
|
||||
} else {
|
||||
bus.dispatch(TOKENS.HINT, null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
.root {
|
||||
display: flex;
|
||||
pointer-events:none;
|
||||
}
|
||||
Loading…
Reference in a new issue