@kui-shell/plugin-tutorials
Version:
IBM Cloud shell plugin for tutorials
79 lines • 2.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = require("debug");
const debug = debug_1.default('tutorial.wskflow');
const stepInterval = 2500;
const terminateAfter = 20000;
const maxIter = 5;
const inBounds = (rect, bounds) => {
return (rect.left >= bounds.left && rect.right <= bounds.right && rect.top >= bounds.top && rect.bottom <= bounds.bottom);
};
const hoverOn = elements => {
let currentTask;
let cleanupHover;
let stop = false;
const cancel = () => {
stop = true;
if (currentTask) {
debug('wskflowCycle cancel');
clearTimeout(currentTask);
}
if (cleanupHover) {
debug('cleanup hover');
cleanupHover();
}
};
currentTask = setTimeout(() => {
const one = (idx, iter) => {
if (stop) {
return;
}
const element = elements[idx];
if (!element && iter < maxIter) {
one(0, iter + 1);
}
else {
const bounds = document.getElementById('wskflowSVG').getBoundingClientRect();
const rect = element.getBoundingClientRect();
if (inBounds(rect, bounds)) {
const event = new MouseEvent('mouseover', { view: window });
element.classList.add('hover');
element.dispatchEvent(event);
cleanupHover = () => {
const event = new MouseEvent('mouseout', { view: window });
element.classList.remove('hover');
element.dispatchEvent(event);
};
setTimeout(cleanupHover, stepInterval);
currentTask = setTimeout(() => {
if (!stop) {
one(idx + 1, iter);
}
}, stepInterval);
}
else if (!stop) {
debug('skipping', element);
one(idx + 1, iter);
}
}
};
one(0, 0);
}, 0);
return cancel;
};
exports.wskflowCycle = obj => {
debug('wskflowCycle');
const actions = document.querySelectorAll('#wskflowSVG .node.wskflow-node-with-special-meaning rect');
const edges = document.querySelectorAll('#wskflowSVG path.has-hover-effect');
const all = [];
for (let idx = 0; idx < actions.length; idx++) {
all.push(actions[idx]);
}
for (let idx = edges.length - 1; idx >= 0; idx--) {
all.push(edges[idx]);
}
const cancel = hoverOn(all.reverse());
setTimeout(cancel, terminateAfter);
obj.cancellables.push(cancel);
};
//# sourceMappingURL=wskflow.js.map