mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +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) {
|
dispatch(key, data) {
|
||||||
|
console.log('dispatch: ' + key + ' -> ' + JSON.stringify(data));
|
||||||
|
|
||||||
if (this.lock.has(key)) {
|
if (this.lock.has(key)) {
|
||||||
console.warn('recursive dispatch');
|
console.warn('recursive dispatch');
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,35 @@ export function mapActionBehavior(actionIdProp) {
|
||||||
return ({dispatch}, props) => {
|
return ({dispatch}, props) => {
|
||||||
const actionId = props[actionIdProp];
|
const actionId = props[actionIdProp];
|
||||||
const actionRunToken = ACTION_TOKENS.actionRun(actionId);
|
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 {
|
return {
|
||||||
onClick: data => dispatch(actionRunToken, data),
|
onClick: data => dispatch(actionRunToken, data),
|
||||||
onMouseEnter: ({pageX, pageY}) => dispatch(ACTION_TOKENS.SHOW_HINT_FOR, [actionId, pageX, pageY]),
|
onMouseEnter: e => {
|
||||||
onMouseLeave: () => dispatch(ACTION_TOKENS.SHOW_HINT_FOR, null)
|
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) {
|
function synchActionHint(bus) {
|
||||||
|
|
||||||
let lastRequest = null;
|
|
||||||
|
|
||||||
// bus.subscribe(TOKENS.REQUEST_SHOW_HINT_FOR
|
|
||||||
bus.subscribe(TOKENS.SHOW_HINT_FOR, request => {
|
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) {
|
if (request) {
|
||||||
setTimeout(() => {
|
let {actionId, x, y} = request;
|
||||||
if (!request.spoiled) {
|
let actionState = bus.getState(TOKENS.actionState(actionId));
|
||||||
let [actionId, x, y] = request;
|
let actionAppearance = bus.getState(TOKENS.actionAppearance(actionId));
|
||||||
let actionState = bus.getState(TOKENS.actionState(actionId));
|
if (actionState && actionAppearance) {
|
||||||
let actionAppearance = bus.getState(TOKENS.actionAppearance(actionId));
|
bus.dispatch(TOKENS.HINT, {
|
||||||
if (actionState && actionAppearance) {
|
actionId, x, y,
|
||||||
bus.dispatch(TOKENS.HINT, {
|
info: actionAppearance.info,
|
||||||
actionId, x: x + 10, y: y + 10,
|
hint: actionState.hint
|
||||||
info: actionAppearance.info,
|
});
|
||||||
hint: actionState.hint
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
} else {
|
} else {
|
||||||
bus.dispatch(TOKENS.HINT, null);
|
bus.dispatch(TOKENS.HINT, null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
.root {
|
.root {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
pointer-events:none;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue