@arqlet/engine-client 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/THIRD_PARTY_NOTICES.md +1530 -0
- package/arqlet.wasm +0 -0
- package/elk.d.ts +26 -0
- package/elk.js +6 -3
- package/package.json +10 -3
- package/session.d.ts +147 -1
- package/session.js +227 -3
- package/view-controller.d.ts +164 -0
- package/view-controller.js +764 -0
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
// A headless view controller (provisional, request 31): what a user does between two scenes (opening and closing groups,
|
|
2
|
+
// paging through `+N more`, filtering, a path or a neighbourhood kept as the highlight, a step back and forward) on top of
|
|
3
|
+
// a layout session (`createSession`), with one state object and `subscribe`, so that a React binding is
|
|
4
|
+
// `useSyncExternalStore(controller.subscribe, controller.getState)` and nothing else. No DOM, no framework, no fetch:
|
|
5
|
+
// loading data, access control, presets and drawing stay with the host.
|
|
6
|
+
//
|
|
7
|
+
// The view's decisions are the engine's values (operations `intent` and `restore`): a step back restores the decisions
|
|
8
|
+
// before a change, in one engine step. The highlight is a read-only query (`trace`, `neighbourhood`) that is asked again
|
|
9
|
+
// after every change, so it stays on the view until it is cleared. Every step carries the difference between the scenes
|
|
10
|
+
// before and after it (`sceneDiff`), so every renderer can animate the same way.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What changed between two scenes: nodes and routes added, removed, and changed (nodes moved or resized, routes with other
|
|
14
|
+
* points), by id. Either scene may be null (everything added or removed).
|
|
15
|
+
*/
|
|
16
|
+
export function sceneDiff(before, after) {
|
|
17
|
+
const byId = list => new Map((list ?? []).map(x => [x.id, x]));
|
|
18
|
+
const compare = (a, b, same) => {
|
|
19
|
+
const out = {added: [], removed: [], changed: []};
|
|
20
|
+
for (const [id, x] of b) {
|
|
21
|
+
const old = a.get(id);
|
|
22
|
+
if (!old) out.added.push(id);
|
|
23
|
+
else if (!same(old, x)) out.changed.push(id);
|
|
24
|
+
}
|
|
25
|
+
for (const id of a.keys()) if (!b.has(id)) out.removed.push(id);
|
|
26
|
+
return out;
|
|
27
|
+
};
|
|
28
|
+
const sameBounds = (p, q) => p.bounds.x === q.bounds.x && p.bounds.y === q.bounds.y
|
|
29
|
+
&& p.bounds.width === q.bounds.width && p.bounds.height === q.bounds.height && !!p.collapsed === !!q.collapsed;
|
|
30
|
+
const samePoints = (p, q) => p.points.length === q.points.length
|
|
31
|
+
&& p.points.every((pt, k) => pt.x === q.points[k].x && pt.y === q.points[k].y);
|
|
32
|
+
return {
|
|
33
|
+
nodes: compare(byId(before?.nodes), byId(after?.nodes), sameBounds),
|
|
34
|
+
routes: compare(byId(before?.routes), byId(after?.routes), samePoints),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Provisional (keyboard navigation): the node of `scene` that `direction` leads to from node `from`, or null; pure and
|
|
42
|
+
* deterministic (ties by id). `left`, `right`, `up`, `down`: the nearest box whose centre lies that way (within a cone
|
|
43
|
+
* of twice the main distance first, then anywhere that way), leaving out the node's own containers and contents;
|
|
44
|
+
* `parent`; `child`: the first child in reading order (top to bottom, then left to right); `next`, `previous`: the
|
|
45
|
+
* neighbouring sibling in reading order, wrapping; `out`, `in`: the nearest node a drawn edge leads to or comes from.
|
|
46
|
+
* Without `from`, the first top-level node in reading order.
|
|
47
|
+
*/
|
|
48
|
+
export function navigateScene(scene, from, direction) {
|
|
49
|
+
const nodes = scene?.nodes ?? [];
|
|
50
|
+
const byId = new Map(nodes.map(n => [n.id, n]));
|
|
51
|
+
const centre = n => ({x: n.bounds.x + n.bounds.width / 2, y: n.bounds.y + n.bounds.height / 2});
|
|
52
|
+
const reading = (a, b) => a.bounds.y - b.bounds.y || a.bounds.x - b.bounds.x || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
53
|
+
const first = list => [...list].sort(reading)[0]?.id ?? null;
|
|
54
|
+
const node = from ? byId.get(from) : null;
|
|
55
|
+
if (!node) return first(nodes.filter(n => !n.parentId || !byId.has(n.parentId)));
|
|
56
|
+
const nearest = (candidates, score) => {
|
|
57
|
+
let best = null;
|
|
58
|
+
let bestScore = Infinity;
|
|
59
|
+
for (const c of candidates) {
|
|
60
|
+
const s = score(c);
|
|
61
|
+
if (s === null) continue;
|
|
62
|
+
if (s < bestScore || (s === bestScore && c.id < best.id)) {
|
|
63
|
+
best = c;
|
|
64
|
+
bestScore = s;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return best?.id ?? null;
|
|
68
|
+
};
|
|
69
|
+
const here = centre(node);
|
|
70
|
+
switch (direction) {
|
|
71
|
+
case 'parent':
|
|
72
|
+
return node.parentId && byId.has(node.parentId) ? node.parentId : null;
|
|
73
|
+
case 'child':
|
|
74
|
+
return first(nodes.filter(n => n.parentId === node.id));
|
|
75
|
+
case 'next':
|
|
76
|
+
case 'previous': {
|
|
77
|
+
const siblings = nodes.filter(n => (n.parentId ?? null) === (node.parentId ?? null)).sort(reading);
|
|
78
|
+
if (siblings.length < 2) return null;
|
|
79
|
+
const at = siblings.findIndex(n => n.id === node.id);
|
|
80
|
+
const step = direction === 'next' ? 1 : siblings.length - 1;
|
|
81
|
+
return siblings[(at + step) % siblings.length].id;
|
|
82
|
+
}
|
|
83
|
+
case 'out':
|
|
84
|
+
case 'in': {
|
|
85
|
+
const ends = new Set((scene.routes ?? [])
|
|
86
|
+
.filter(r => (direction === 'out' ? r.source : r.target) === node.id)
|
|
87
|
+
.map(r => (direction === 'out' ? r.target : r.source))
|
|
88
|
+
.filter(id => id !== node.id && byId.has(id)));
|
|
89
|
+
return nearest([...ends].map(id => byId.get(id)), c => {
|
|
90
|
+
const p = centre(c);
|
|
91
|
+
return (p.x - here.x) ** 2 + (p.y - here.y) ** 2;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
case 'left':
|
|
95
|
+
case 'right':
|
|
96
|
+
case 'up':
|
|
97
|
+
case 'down': {
|
|
98
|
+
// Not its own containers (they hold it) nor its contents (`child` goes there).
|
|
99
|
+
const above = new Set();
|
|
100
|
+
for (let at = node.parentId; at && byId.has(at) && !above.has(at); at = byId.get(at).parentId) above.add(at);
|
|
101
|
+
const inside = c => {
|
|
102
|
+
for (let at = c.parentId, steps = 0; at && steps <= nodes.length; at = byId.get(at)?.parentId, steps++) {
|
|
103
|
+
if (at === node.id) return true;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
};
|
|
107
|
+
const candidates = nodes.filter(c => c.id !== node.id && !above.has(c.id) && !inside(c));
|
|
108
|
+
const axis = c => {
|
|
109
|
+
const p = centre(c);
|
|
110
|
+
const dx = p.x - here.x;
|
|
111
|
+
const dy = p.y - here.y;
|
|
112
|
+
const main = direction === 'right' ? dx : direction === 'left' ? -dx : direction === 'down' ? dy : -dy;
|
|
113
|
+
const side = Math.abs(direction === 'left' || direction === 'right' ? dy : dx);
|
|
114
|
+
return {main, side};
|
|
115
|
+
};
|
|
116
|
+
const inCone = nearest(candidates, c => {
|
|
117
|
+
const {main, side} = axis(c);
|
|
118
|
+
return main > 0 && side <= 2 * main ? main + 2 * side : null;
|
|
119
|
+
});
|
|
120
|
+
return inCone ?? nearest(candidates, c => {
|
|
121
|
+
const {main, side} = axis(c);
|
|
122
|
+
return main > 0 ? main + 2 * side : null;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
126
|
+
throw Error(`Unknown direction: ${direction}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A bookmark as text for a URL (base64url of its JSON, UTF-8), and back. `decodeBookmark` throws on text that is not one.
|
|
132
|
+
*/
|
|
133
|
+
export function encodeBookmark(bookmark) {
|
|
134
|
+
const bytes = new TextEncoder().encode(JSON.stringify(bookmark));
|
|
135
|
+
let binary = '';
|
|
136
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
137
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function decodeBookmark(text) {
|
|
141
|
+
const base64 = text.replace(/-/g, '+').replace(/_/g, '/');
|
|
142
|
+
const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4));
|
|
143
|
+
const bookmark = JSON.parse(new TextDecoder().decode(Uint8Array.from(binary, c => c.charCodeAt(0))));
|
|
144
|
+
if (bookmark?.version !== 1 || typeof bookmark.intent !== 'object') throw Error('Not a view bookmark.');
|
|
145
|
+
return bookmark;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Creates a view controller on `session` (from `createSession`). `page` is how many children `showRest` reveals at a
|
|
150
|
+
* time; `historyLimit` how many steps back are kept; with `scenes: false` the state carries no scene and no diff (a host
|
|
151
|
+
* that draws from the snapshot itself saves the engine call); `detailLimit` caps the edge ids of a line's details.
|
|
152
|
+
*
|
|
153
|
+
* `refine` (provisional) is the second engine for refinement, typically another worker (`workerRefineRun`): a function
|
|
154
|
+
* `(request, {onPublication, signal}) => Promise<answer>` that runs a refinement request on a snapshot the controller
|
|
155
|
+
* sends and calls `onPublication(publication)` for every intermediate result of a progressive one. It runs beside the
|
|
156
|
+
* interactive steps, never in their queue; `publicationInterval` (ms) throttles how often intermediate results are shown.
|
|
157
|
+
*
|
|
158
|
+
* `keepGeometry` (default true, provisional, #148): every step keeps the snapshots before and after it (`session.keep`),
|
|
159
|
+
* so that `back` and `forward` restore the geometry as it was (`session.recall`) instead of laying the view out again;
|
|
160
|
+
* only when a snapshot is no longer kept or the graph changed since is the view laid out again from the decisions
|
|
161
|
+
* (the step's result then says `relaidOut: true`). With `false` only the decisions are kept, as before.
|
|
162
|
+
*/
|
|
163
|
+
export function createViewController(session, {page = 12, historyLimit = 50, scenes = true, detailLimit, refine: refineRun,
|
|
164
|
+
publicationInterval = 120, keepGeometry = true} = {}) {
|
|
165
|
+
let state = Object.freeze({
|
|
166
|
+
snapshot: null, scene: null, diff: null, busy: false, error: null,
|
|
167
|
+
highlight: null, selection: null, details: null, hover: null, search: null, focus: null, peek: null, refining: null, refined: null,
|
|
168
|
+
discarded: 0, hide: {}, canBack: false, canForward: false, backLabel: null, forwardLabel: null, steps: 0,
|
|
169
|
+
});
|
|
170
|
+
const listeners = new Set();
|
|
171
|
+
const publish = patch => {
|
|
172
|
+
state = Object.freeze({...state, ...patch});
|
|
173
|
+
for (const listener of [...listeners]) listener();
|
|
174
|
+
};
|
|
175
|
+
let back = [];
|
|
176
|
+
let forward = [];
|
|
177
|
+
let queue = Promise.resolve();
|
|
178
|
+
let generation = 0;
|
|
179
|
+
let pending = 0;
|
|
180
|
+
|
|
181
|
+
// Runs `step` after every step before it; a step queued before `cancel()` and not yet started is dropped.
|
|
182
|
+
// `fresh`: the step starts a new chain (another view), not waiting for the steps before it, which no longer publish.
|
|
183
|
+
const enqueue = (step, {fresh = false} = {}) => {
|
|
184
|
+
if (fresh) {
|
|
185
|
+
generation += 1;
|
|
186
|
+
queue = Promise.resolve();
|
|
187
|
+
}
|
|
188
|
+
const mine = generation;
|
|
189
|
+
pending += 1;
|
|
190
|
+
if (!state.busy) publish({busy: true});
|
|
191
|
+
const result = queue.then(async () => {
|
|
192
|
+
if (mine !== generation) return {ok: false, cancelled: true};
|
|
193
|
+
try {
|
|
194
|
+
return await step(() => mine === generation);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
publish({error: error.message ?? String(error)});
|
|
197
|
+
return {ok: false, error: error.message ?? String(error)};
|
|
198
|
+
}
|
|
199
|
+
}).finally(() => {
|
|
200
|
+
pending -= 1;
|
|
201
|
+
if (pending === 0) publish({busy: false});
|
|
202
|
+
});
|
|
203
|
+
queue = result.catch(() => {});
|
|
204
|
+
return result;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// The fingerprint of the graph (`digest`), for bookmarks; null when the engine does not answer it.
|
|
208
|
+
const digest = async () => {
|
|
209
|
+
const answer = await session.apply({op: 'digest'});
|
|
210
|
+
return answer.ok ? answer.digest ?? null : null;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// The current snapshot kept by the session for `back` (#148): its mark, or null without it.
|
|
214
|
+
const mark = async () => {
|
|
215
|
+
if (!keepGeometry || typeof session.keep !== 'function') return null;
|
|
216
|
+
const answer = await session.keep({limit: Math.min(historyLimit + 1, 1000)});
|
|
217
|
+
return answer?.ok ? answer.mark : null;
|
|
218
|
+
};
|
|
219
|
+
const intent = async () => {
|
|
220
|
+
const answer = await session.apply({op: 'intent'});
|
|
221
|
+
if (!answer.ok) throw Error(answer.error ?? 'No intent');
|
|
222
|
+
return answer.intent;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// Asks the highlight's query again on the current view (its visible nodes and routes depend on what is open).
|
|
226
|
+
const refreshHighlight = async highlight => {
|
|
227
|
+
if (!highlight) return null;
|
|
228
|
+
const answer = highlight.kind === 'trace'
|
|
229
|
+
? await session.trace(highlight.from, highlight.to, highlight.init)
|
|
230
|
+
: await session.neighbourhood(highlight.nodeId, highlight.init);
|
|
231
|
+
return answer.ok ? {...highlight, answer} : null;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// The details of the selection on the current view (the box that shows a node and the edges a line stands for depend on
|
|
235
|
+
// what is open); null when the selection is gone (a drawn line the change removed).
|
|
236
|
+
const detailsOf = async selection => {
|
|
237
|
+
if (!selection) return null;
|
|
238
|
+
const answer = await session.details(selection, detailLimit === undefined ? {} : {limit: detailLimit});
|
|
239
|
+
return answer.ok ? answer : null;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// After an applied change: the new scene, its difference to the one before, the highlight and the details asked again.
|
|
243
|
+
const settle = async (extra = {}, current = () => true) => {
|
|
244
|
+
const scene = scenes ? await session.scene() : null;
|
|
245
|
+
const highlight = await refreshHighlight(state.highlight);
|
|
246
|
+
const details = await detailsOf(state.selection);
|
|
247
|
+
if (!current()) return;
|
|
248
|
+
publish({
|
|
249
|
+
details, selection: details ? state.selection : null,
|
|
250
|
+
snapshot: session.snapshot, scene, diff: scenes ? sceneDiff(state.scene, scene) : null, highlight, error: null,
|
|
251
|
+
canBack: back.length > 0, canForward: forward.length > 0,
|
|
252
|
+
backLabel: back.at(-1)?.label ?? null, forwardLabel: forward.at(-1)?.label ?? null, steps: state.steps + 1, ...extra,
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// The refinement under way on the second engine: its job, the state it started from, the last publication applied.
|
|
257
|
+
let job = null;
|
|
258
|
+
let jobs = 0;
|
|
259
|
+
// Ends the refinement under way (its later results are dropped); `reason` is reported in `state.refined`.
|
|
260
|
+
const stopRefinement = reason => {
|
|
261
|
+
if (!job) return;
|
|
262
|
+
const stopped = job;
|
|
263
|
+
job = null;
|
|
264
|
+
clearTimeout(stopped.timer);
|
|
265
|
+
stopped.abort.abort();
|
|
266
|
+
publish({refining: null, refined: {op: stopped.op, applied: stopped.applied > 0, [reason]: true}});
|
|
267
|
+
};
|
|
268
|
+
// Whether a refinement result still fits the view: the view is the one the job started from (or the job's own last
|
|
269
|
+
// publication), and the result is the next layout of it.
|
|
270
|
+
const fits = (j, snapshot) => {
|
|
271
|
+
const now = session.snapshot;
|
|
272
|
+
const shown = j.base.layoutVersion + (j.applied > 0 ? 1 : 0);
|
|
273
|
+
return !!now && !!snapshot && now.revision === j.base.revision && (now.layoutVersion ?? 0) === shown
|
|
274
|
+
&& snapshot.revision === j.base.revision && snapshot.baseRevision === j.base.revision
|
|
275
|
+
&& (snapshot.layoutVersion ?? 0) === j.base.layoutVersion + 1;
|
|
276
|
+
};
|
|
277
|
+
// Applies a refinement result after the steps queued before it; a result the view has moved away from is discarded
|
|
278
|
+
// and counted.
|
|
279
|
+
const applyRefined = (j, snapshot, final) => enqueue(async current => {
|
|
280
|
+
if (job !== j) return {ok: false, stale: true};
|
|
281
|
+
if (!fits(j, snapshot)) {
|
|
282
|
+
if (final) job = null;
|
|
283
|
+
publish({discarded: state.discarded + 1, ...(final ? {refining: null, refined: {op: j.op, applied: false, stale: true}} : {})});
|
|
284
|
+
return {ok: false, stale: true};
|
|
285
|
+
}
|
|
286
|
+
const loaded = await session.load(snapshot);
|
|
287
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
288
|
+
if (!loaded.ok) {
|
|
289
|
+
publish({error: loaded.error ?? 'The refined layout was refused.'});
|
|
290
|
+
return loaded;
|
|
291
|
+
}
|
|
292
|
+
j.applied += 1;
|
|
293
|
+
if (final) job = null;
|
|
294
|
+
j.onApplied?.(snapshot, {final, shown: j.applied});
|
|
295
|
+
await settle(final
|
|
296
|
+
? {refining: null, refined: {op: j.op, applied: true, optimization: snapshot.optimization ?? null}}
|
|
297
|
+
: {refining: {op: j.op, jobId: j.id, shown: j.applied}}, current);
|
|
298
|
+
return {ok: true, applied: true};
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// A change the user makes: its decisions before and after are remembered (unless `remember` is false), so that `back`
|
|
302
|
+
// undoes it. A refinement under way is stopped: its result would be for the view before the change.
|
|
303
|
+
const change = (label, run, extra = () => ({}), remember = true, merge = false) => enqueue(async current => {
|
|
304
|
+
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
305
|
+
stopRefinement('cancelled');
|
|
306
|
+
const before = remember ? await intent() : null;
|
|
307
|
+
const beforeMark = remember ? await mark() : null;
|
|
308
|
+
const result = await run();
|
|
309
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
310
|
+
if (!result.ok) {
|
|
311
|
+
publish({error: result.error ?? 'The engine refused the change.'});
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
const after = remember ? await intent() : null;
|
|
315
|
+
const afterMark = remember ? await mark() : null;
|
|
316
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
317
|
+
// A look into a container belongs to the view before the change.
|
|
318
|
+
if (state.peek) state = Object.freeze({...state, peek: null});
|
|
319
|
+
if (remember && merge && back.length) {
|
|
320
|
+
// A follow-up of the last change (such as a container keeping the size a drop gave it): one entry for both.
|
|
321
|
+
const last = back.at(-1);
|
|
322
|
+
last.after = after;
|
|
323
|
+
last.afterMark = afterMark;
|
|
324
|
+
if (same(last.before, last.after)) back.pop();
|
|
325
|
+
forward = [];
|
|
326
|
+
} else if (remember && !same(before, after)) {
|
|
327
|
+
back.push({label, before, after, beforeMark, afterMark});
|
|
328
|
+
if (back.length > historyLimit) back.shift();
|
|
329
|
+
forward = [];
|
|
330
|
+
}
|
|
331
|
+
await settle(extra(), current);
|
|
332
|
+
return result;
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Back and forward: the kept snapshot of that side comes back with its geometry (#148); when it is no longer kept or the
|
|
336
|
+
// graph changed since, the engine restores the remembered decisions and lays the view out again. A refused step keeps
|
|
337
|
+
// the entry.
|
|
338
|
+
const step = direction => enqueue(async current => {
|
|
339
|
+
stopRefinement('cancelled');
|
|
340
|
+
const from = direction < 0 ? back : forward;
|
|
341
|
+
const entry = from.at(-1);
|
|
342
|
+
if (!entry) return {ok: false, error: direction < 0 ? 'Nothing to undo.' : 'Nothing to redo.'};
|
|
343
|
+
const kept = direction < 0 ? entry.beforeMark : entry.afterMark;
|
|
344
|
+
let result = kept == null ? null : await session.recall(kept);
|
|
345
|
+
if (result && !result.ok && !result.evicted && !result.changed) {
|
|
346
|
+
publish({error: result.error ?? 'The engine refused the step.'});
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
if (result?.ok) {
|
|
350
|
+
result = {...result, relaidOut: false};
|
|
351
|
+
} else {
|
|
352
|
+
result = await session.apply({op: 'restore', intent: direction < 0 ? entry.before : entry.after});
|
|
353
|
+
if (result.ok) result = {...result, relaidOut: true};
|
|
354
|
+
}
|
|
355
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
356
|
+
if (!result.ok) {
|
|
357
|
+
publish({error: result.error ?? 'The engine refused the restore.'});
|
|
358
|
+
return result;
|
|
359
|
+
}
|
|
360
|
+
from.pop();
|
|
361
|
+
(direction < 0 ? forward : back).push(entry);
|
|
362
|
+
if (state.peek) state = Object.freeze({...state, peek: null});
|
|
363
|
+
const hidden = (direction < 0 ? entry.before : entry.after).hidden ?? {};
|
|
364
|
+
await settle({hide: hidden}, current);
|
|
365
|
+
return result;
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
const controller = {
|
|
369
|
+
/** The current state (a new frozen object after every change; the same object while nothing changed). */
|
|
370
|
+
getState: () => state,
|
|
371
|
+
|
|
372
|
+
/** Calls `listener` after every change of the state; returns the function that stops it. */
|
|
373
|
+
subscribe(listener) {
|
|
374
|
+
listeners.add(listener);
|
|
375
|
+
return () => listeners.delete(listener);
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
/** Lays out `graph` and starts the view on it (see `session.import`); the history and the highlight start empty. */
|
|
379
|
+
import(graph, init) {
|
|
380
|
+
stopRefinement('cancelled');
|
|
381
|
+
back = [];
|
|
382
|
+
forward = [];
|
|
383
|
+
return enqueue(async current => {
|
|
384
|
+
const result = await session.import(graph, init);
|
|
385
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
386
|
+
if (!result.ok) {
|
|
387
|
+
publish({error: result.error ?? 'The import failed.'});
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
state = Object.freeze({...state, scene: null, highlight: null, selection: null, details: null, hover: null,
|
|
391
|
+
search: null, focus: null, peek: null, hide: {}, steps: 0});
|
|
392
|
+
await settle({}, current);
|
|
393
|
+
return result;
|
|
394
|
+
}, {fresh: true});
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
/** Opens container `id` (nothing when it is open). */
|
|
398
|
+
open(id) { return change(`Open ${id}`, () => session.expand(id)); },
|
|
399
|
+
/** Closes container `id` (nothing when it is closed). */
|
|
400
|
+
close(id) { return change(`Close ${id}`, () => session.collapse(id)); },
|
|
401
|
+
/** Opens or closes container `id`. */
|
|
402
|
+
toggle(id) { return change(`Toggle ${id}`, () => session.toggle(id)); },
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Shows the next `count` (default `page`) children of `container`'s `+N more` box; on the last page the container is
|
|
406
|
+
* whole again. A collapsed container opens in part with its first page. `container` may also be the rest's id
|
|
407
|
+
* (`rest:<container>`).
|
|
408
|
+
*/
|
|
409
|
+
showRest(container, count = page) {
|
|
410
|
+
const id = container.startsWith('rest:') ? container.slice(5) : container;
|
|
411
|
+
return change(`Next ${count} of ${id}`, () => session.apply({op: 'reveal', more: {container: id, count}}));
|
|
412
|
+
},
|
|
413
|
+
|
|
414
|
+
/** Opens the groups that hold `nodeIds` (only as far as needed with `partial`, the default). */
|
|
415
|
+
reveal(nodeIds, init) { return change('Reveal', () => session.reveal(nodeIds, init)); },
|
|
416
|
+
|
|
417
|
+
/** Hides nodes by kind or id and edges by kind (see `session.filter`); `{}` shows everything again. */
|
|
418
|
+
filter(hide = {}) { return change('Filter', () => session.filter(hide), () => ({hide})); },
|
|
419
|
+
|
|
420
|
+
/** Highlights the paths from `from` to `to` (see `session.trace`) until it is cleared; the view does not change. */
|
|
421
|
+
trace(from, to, init) {
|
|
422
|
+
return enqueue(async () => {
|
|
423
|
+
const answer = await session.trace(from, to, init);
|
|
424
|
+
if (!answer.ok) {
|
|
425
|
+
publish({error: answer.error ?? 'No path.'});
|
|
426
|
+
return answer;
|
|
427
|
+
}
|
|
428
|
+
publish({highlight: {kind: 'trace', from, to, init, answer}, error: null});
|
|
429
|
+
return answer;
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
|
|
433
|
+
/** Highlights the neighbourhood of `nodeId` (one id or a list; see `session.neighbourhood`) until it is cleared. */
|
|
434
|
+
neighbourhood(nodeId, init) {
|
|
435
|
+
return enqueue(async () => {
|
|
436
|
+
const answer = await session.neighbourhood(nodeId, init);
|
|
437
|
+
if (!answer.ok) {
|
|
438
|
+
publish({error: answer.error ?? 'No neighbourhood.'});
|
|
439
|
+
return answer;
|
|
440
|
+
}
|
|
441
|
+
publish({highlight: {kind: 'neighbourhood', nodeId, init, answer}, error: null});
|
|
442
|
+
return answer;
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
/** Opens what the highlight passes through (the groups on a path or around a neighbourhood). */
|
|
447
|
+
revealHighlight() {
|
|
448
|
+
const nodes = state.highlight?.answer?.nodes;
|
|
449
|
+
return nodes?.length ? controller.reveal(nodes) : Promise.resolve({ok: true, unchanged: true});
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
/** Clears the highlight. */
|
|
453
|
+
clearHighlight() { if (state.highlight) publish({highlight: null}); },
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Selects a node (`{nodeId}`) or an edge (`{edgeId}`: a drawn line or an edge of the source graph), or nothing
|
|
457
|
+
* (`null`): `state.details` then holds what the engine knows about it (see `session.details`), asked again after
|
|
458
|
+
* every change until the selection is cleared. How it is shown (a panel, a tooltip, a zoom to `details.node.bounds`)
|
|
459
|
+
* is the host's; domain attributes the host looks up by id. Not a step for `back`.
|
|
460
|
+
*/
|
|
461
|
+
select(target) {
|
|
462
|
+
const selection = target ? ('nodeId' in target ? {nodeId: target.nodeId} : {edgeId: target.edgeId}) : null;
|
|
463
|
+
if (!selection) {
|
|
464
|
+
if (state.selection || state.details) publish({selection: null, details: null});
|
|
465
|
+
return Promise.resolve({ok: true});
|
|
466
|
+
}
|
|
467
|
+
return enqueue(async current => {
|
|
468
|
+
const answer = await session.details(selection, detailLimit === undefined ? {} : {limit: detailLimit});
|
|
469
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
470
|
+
if (!answer.ok) {
|
|
471
|
+
publish({error: answer.error ?? 'No details.'});
|
|
472
|
+
return answer;
|
|
473
|
+
}
|
|
474
|
+
publish({selection, details: answer, error: null});
|
|
475
|
+
return answer;
|
|
476
|
+
});
|
|
477
|
+
},
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Finds nodes by label or id (see `session.find`), also those the view hides; the answer is also `state.search`
|
|
481
|
+
* until `clearSearch`. Read only.
|
|
482
|
+
*/
|
|
483
|
+
find(query, init) {
|
|
484
|
+
return enqueue(async current => {
|
|
485
|
+
const answer = await session.find(query, init);
|
|
486
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
487
|
+
if (!answer.ok) {
|
|
488
|
+
publish({error: answer.error ?? 'Nothing found.'});
|
|
489
|
+
return answer;
|
|
490
|
+
}
|
|
491
|
+
publish({search: {query, answer}, error: null});
|
|
492
|
+
return answer;
|
|
493
|
+
});
|
|
494
|
+
},
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* A look into the collapsed container `nodeId` without opening it (see `session.peek`): `state.peek` holds its contents
|
|
498
|
+
* as a small scene until `closePeek` or the next change. Read only, not a step for `back`.
|
|
499
|
+
*/
|
|
500
|
+
peek(nodeId, init) {
|
|
501
|
+
return enqueue(async current => {
|
|
502
|
+
const answer = await session.peek(nodeId, init);
|
|
503
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
504
|
+
if (!answer.ok) {
|
|
505
|
+
publish({error: answer.error ?? 'Nothing to look into.'});
|
|
506
|
+
return answer;
|
|
507
|
+
}
|
|
508
|
+
publish({peek: {nodeId, answer}, error: null});
|
|
509
|
+
return answer;
|
|
510
|
+
});
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Provisional (ADR 0023, R1): changes the session's content (see `session.payload`) and asks the selection's details
|
|
515
|
+
* again, so that `state.details` shows the new properties. Not a step for `back`: content is not a view decision.
|
|
516
|
+
*/
|
|
517
|
+
payload(change) {
|
|
518
|
+
return enqueue(async current => {
|
|
519
|
+
const answer = await session.payload(change);
|
|
520
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
521
|
+
if (!answer.ok) {
|
|
522
|
+
publish({error: answer.error ?? 'The content was refused.'});
|
|
523
|
+
return answer;
|
|
524
|
+
}
|
|
525
|
+
const details = await detailsOf(state.selection);
|
|
526
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
527
|
+
publish({details, contentRevision: answer.contentRevision, error: null});
|
|
528
|
+
return answer;
|
|
529
|
+
});
|
|
530
|
+
},
|
|
531
|
+
|
|
532
|
+
/** Ends the look into a container. */
|
|
533
|
+
closePeek() { if (state.peek) publish({peek: null}); },
|
|
534
|
+
|
|
535
|
+
/** Clears the search. */
|
|
536
|
+
clearSearch() { if (state.search) publish({search: null}); },
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Brings node `nodeId` into view: opens the groups that hide it (a step for `back`; not with `reveal: false`, and only
|
|
540
|
+
* as far as needed unless `partial: false`), selects it (`state.details`), and sets `state.focus` to
|
|
541
|
+
* `{nodeId, bounds, serial}`: the bounds of the box that shows it, for the host's camera to center or fit (`serial`
|
|
542
|
+
* counts focus requests, so the same node can be focused again). `bounds` is null when the view hides it anyway (a
|
|
543
|
+
* filter).
|
|
544
|
+
*/
|
|
545
|
+
async focus(nodeId, {reveal = true, partial} = {}) {
|
|
546
|
+
let answer = await controller.select({nodeId});
|
|
547
|
+
if (!answer.ok) return answer;
|
|
548
|
+
if (reveal && answer.node.shownAs !== nodeId) {
|
|
549
|
+
const shown = await change(`Show ${nodeId}`,
|
|
550
|
+
() => session.reveal([nodeId], partial === undefined ? undefined : {partial}));
|
|
551
|
+
if (!shown.ok) return shown;
|
|
552
|
+
answer = state.details ?? answer;
|
|
553
|
+
}
|
|
554
|
+
const node = answer.node;
|
|
555
|
+
publish({focus: {nodeId, bounds: node.bounds ?? null, shownAs: node.shownAs ?? null, serial: (state.focus?.serial ?? 0) + 1}});
|
|
556
|
+
return {ok: true, focus: state.focus};
|
|
557
|
+
},
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Keyboard navigation: moves the selection from the selected node (or, without one, to the first top-level node)
|
|
561
|
+
* the way `direction` says (see `navigateScene`) and sets `state.focus` for the camera, without opening anything
|
|
562
|
+
* (not a step for `back`). `{ok: false, none: true}` when nothing lies that way; a closed container has no child to go
|
|
563
|
+
* to until it is opened.
|
|
564
|
+
*/
|
|
565
|
+
async navigate(direction) {
|
|
566
|
+
const step = await enqueue(async current => {
|
|
567
|
+
const scene = state.scene ?? await session.scene();
|
|
568
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
569
|
+
if (!scene) return {ok: false, error: 'Nothing imported yet.'};
|
|
570
|
+
const from = state.selection?.nodeId ?? null;
|
|
571
|
+
const nodeId = navigateScene(scene, from, direction);
|
|
572
|
+
if (!nodeId) {
|
|
573
|
+
const node = scene.nodes.find(n => n.id === from);
|
|
574
|
+
return {ok: false, none: true, ...(direction === 'child' && node?.collapsed ? {collapsed: true} : {})};
|
|
575
|
+
}
|
|
576
|
+
return {ok: true, nodeId};
|
|
577
|
+
});
|
|
578
|
+
if (!step.ok) return step;
|
|
579
|
+
const focused = await controller.focus(step.nodeId, {reveal: false});
|
|
580
|
+
return focused.ok ? {ok: true, nodeId: step.nodeId, focus: focused.focus} : focused;
|
|
581
|
+
},
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Refines the current view on the second engine (option `refine`): `{op: 'refine'}` by default, or
|
|
585
|
+
* `refineProgressive` (intermediate results shown as they arrive, at most one per `publicationInterval`),
|
|
586
|
+
* `structuredRefine`, with any further fields of the request (such as `threads`). It starts after the steps queued
|
|
587
|
+
* before it and runs beside the interactive ones; `state.refining` names it meanwhile. A result is applied only if
|
|
588
|
+
* the view is still the one it started from (otherwise `state.refined.stale` and `state.discarded` counts it); a
|
|
589
|
+
* change, a step back or a new refinement stops it (`cancelled`). Not a step for `back`: it changes the layout, not a
|
|
590
|
+
* decision. `onApplied(snapshot, {final, shown})` is called for every result applied (for a host that draws from the
|
|
591
|
+
* snapshot itself).
|
|
592
|
+
*/
|
|
593
|
+
refine(request = {}, {onApplied} = {}) {
|
|
594
|
+
if (!refineRun) return Promise.resolve({ok: false, error: 'No refinement engine (option refine).'});
|
|
595
|
+
const op = request.op ?? 'refine';
|
|
596
|
+
return enqueue(async () => {
|
|
597
|
+
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
598
|
+
stopRefinement('cancelled');
|
|
599
|
+
const snapshot = session.snapshot;
|
|
600
|
+
const j = {id: `refine-${++jobs}`, op, base: {revision: snapshot.revision, layoutVersion: snapshot.layoutVersion ?? 0},
|
|
601
|
+
applied: 0, lastSequence: 0, pending: null, timer: null, abort: new AbortController(), onApplied};
|
|
602
|
+
job = j;
|
|
603
|
+
publish({refining: {op, jobId: j.id, shown: 0}});
|
|
604
|
+
return {ok: true, j, snapshot};
|
|
605
|
+
}).then(started => {
|
|
606
|
+
if (!started.ok) return started;
|
|
607
|
+
const {j, snapshot} = started;
|
|
608
|
+
// Intermediate results: the first at once, then the newest one per interval.
|
|
609
|
+
const showPending = () => {
|
|
610
|
+
j.timer = null;
|
|
611
|
+
const next = j.pending;
|
|
612
|
+
j.pending = null;
|
|
613
|
+
if (next && job === j) {
|
|
614
|
+
applyRefined(j, next, false);
|
|
615
|
+
j.timer = setTimeout(showPending, publicationInterval);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
const onPublication = publication => {
|
|
619
|
+
if (job !== j || publication?.jobId !== j.id || !(publication.sequence > j.lastSequence)) return;
|
|
620
|
+
j.lastSequence = publication.sequence;
|
|
621
|
+
j.pending = publication.snapshot;
|
|
622
|
+
if (j.timer === null) showPending();
|
|
623
|
+
};
|
|
624
|
+
return Promise.resolve(refineRun({...request, op, jobId: j.id, snapshot, expectedRevision: j.base.revision,
|
|
625
|
+
expectedLayoutVersion: j.base.layoutVersion}, {onPublication, signal: j.abort.signal}))
|
|
626
|
+
.then(answer => {
|
|
627
|
+
if (job !== j) return {ok: false, cancelled: true};
|
|
628
|
+
clearTimeout(j.timer);
|
|
629
|
+
j.timer = null;
|
|
630
|
+
if (!answer?.ok) {
|
|
631
|
+
job = null;
|
|
632
|
+
publish({refining: null, refined: {op, applied: j.applied > 0, error: answer?.error ?? 'The refinement failed.'}});
|
|
633
|
+
return {ok: false, error: answer?.error};
|
|
634
|
+
}
|
|
635
|
+
return applyRefined(j, answer.snapshot, true).then(r => ({...r, answer}));
|
|
636
|
+
}, error => {
|
|
637
|
+
if (job !== j) return {ok: false, cancelled: true};
|
|
638
|
+
job = null;
|
|
639
|
+
publish({refining: null, refined: {op, applied: j.applied > 0, error: error.message ?? String(error)}});
|
|
640
|
+
return {ok: false, error: error.message ?? String(error)};
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
|
|
645
|
+
/** Stops the refinement under way (`state.refined.cancelled`); its later results are dropped. */
|
|
646
|
+
cancelRefinement() { stopRefinement('cancelled'); },
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* The view as a value to keep or share: the decisions (the engine's intent: open groups, pages, filter, options), the
|
|
650
|
+
* highlight and the selection, and the digest of the graph it belongs to. `encodeBookmark` makes it text for a URL.
|
|
651
|
+
*/
|
|
652
|
+
bookmark() {
|
|
653
|
+
return enqueue(async () => {
|
|
654
|
+
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
655
|
+
const h = state.highlight;
|
|
656
|
+
const highlight = h ? {kind: h.kind, ...(h.kind === 'trace' ? {from: h.from, to: h.to} : {nodeId: h.nodeId}),
|
|
657
|
+
...(h.init ? {init: h.init} : {})} : null;
|
|
658
|
+
const bookmark = {version: 1, digest: await digest(), intent: await intent(),
|
|
659
|
+
...(highlight ? {highlight} : {}), ...(state.selection ? {selection: state.selection} : {})};
|
|
660
|
+
return {ok: true, bookmark};
|
|
661
|
+
});
|
|
662
|
+
},
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Opens a bookmark on the current graph (a step for `back`): its decisions, highlight and selection. A bookmark of
|
|
666
|
+
* another graph (another digest) is refused unless `force`.
|
|
667
|
+
*/
|
|
668
|
+
openBookmark(bookmark, {force = false} = {}) {
|
|
669
|
+
return enqueue(async current => {
|
|
670
|
+
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
671
|
+
if (bookmark?.version !== 1 || typeof bookmark.intent !== 'object') return {ok: false, error: 'Not a view bookmark.'};
|
|
672
|
+
const now = bookmark.digest && !force ? await digest() : null;
|
|
673
|
+
if (now && bookmark.digest !== now) {
|
|
674
|
+
const error = 'The bookmark belongs to another graph.';
|
|
675
|
+
publish({error});
|
|
676
|
+
return {ok: false, error};
|
|
677
|
+
}
|
|
678
|
+
stopRefinement('cancelled');
|
|
679
|
+
const before = await intent();
|
|
680
|
+
const beforeMark = await mark();
|
|
681
|
+
const result = await session.apply({op: 'restore', intent: bookmark.intent});
|
|
682
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
683
|
+
if (!result.ok) {
|
|
684
|
+
publish({error: result.error ?? 'The engine refused the bookmark.'});
|
|
685
|
+
return result;
|
|
686
|
+
}
|
|
687
|
+
const after = await intent();
|
|
688
|
+
if (!same(before, after)) {
|
|
689
|
+
back.push({label: 'Open bookmark', before, after, beforeMark, afterMark: await mark()});
|
|
690
|
+
if (back.length > historyLimit) back.shift();
|
|
691
|
+
forward = [];
|
|
692
|
+
}
|
|
693
|
+
state = Object.freeze({...state, highlight: bookmark.highlight ?? null, selection: bookmark.selection ?? null});
|
|
694
|
+
await settle({hide: bookmark.intent.hidden ?? {}}, current);
|
|
695
|
+
return result;
|
|
696
|
+
});
|
|
697
|
+
},
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* What the pointer is over (`{nodeId}`, `{edgeId}` or `null`), for a renderer's hover state (a tooltip from the
|
|
701
|
+
* scene's label, a lighter outline); no engine call. A tooltip with the engine's facts asks `select` or
|
|
702
|
+
* `session.details` itself.
|
|
703
|
+
*/
|
|
704
|
+
hover(target) {
|
|
705
|
+
const next = target ? ('nodeId' in target ? {nodeId: target.nodeId} : {edgeId: target.edgeId}) : null;
|
|
706
|
+
if (same(next, state.hover)) return;
|
|
707
|
+
publish({hover: next});
|
|
708
|
+
},
|
|
709
|
+
|
|
710
|
+
/** Undoes the last change (its decisions before it are restored). */
|
|
711
|
+
back() { return step(-1); },
|
|
712
|
+
/** Redoes the last undone change. */
|
|
713
|
+
forward() { return step(1); },
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Any other change of the engine's protocol (see `session.apply`), remembered for `back` under `label` (not with
|
|
717
|
+
* `remember: false`, for steps that change no decision, such as settling).
|
|
718
|
+
*/
|
|
719
|
+
apply(request, label = request.op, {remember = true, merge = false} = {}) {
|
|
720
|
+
return change(label, () => session.apply(request), () => ({}), remember, merge);
|
|
721
|
+
},
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Continues from `snapshot`, made by the host (a drag, a refinement, a loaded document); with `forget` the history and
|
|
725
|
+
* the highlight start empty (another graph).
|
|
726
|
+
*/
|
|
727
|
+
adopt(snapshot, {forget = false, remember = null} = {}) {
|
|
728
|
+
return enqueue(async current => {
|
|
729
|
+
// With `remember` (a label) the change from the session's snapshot to this one is remembered for `back`.
|
|
730
|
+
stopRefinement('cancelled');
|
|
731
|
+
const before = remember && session.snapshot ? await intent() : null;
|
|
732
|
+
const beforeMark = before ? await mark() : null;
|
|
733
|
+
const result = await session.load(snapshot, {reset: forget});
|
|
734
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
735
|
+
if (!result.ok) {
|
|
736
|
+
publish({error: result.error ?? 'The snapshot was refused.'});
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
if (forget) {
|
|
740
|
+
back = [];
|
|
741
|
+
forward = [];
|
|
742
|
+
state = Object.freeze({...state, highlight: null, selection: null, details: null, hover: null, search: null,
|
|
743
|
+
focus: null, peek: null, hide: {}});
|
|
744
|
+
} else if (before) {
|
|
745
|
+
const after = await intent();
|
|
746
|
+
if (!same(before, after)) {
|
|
747
|
+
back.push({label: remember, before, after, beforeMark, afterMark: await mark()});
|
|
748
|
+
if (back.length > historyLimit) back.shift();
|
|
749
|
+
forward = [];
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
await settle({hide: snapshot.options?.hidden ?? (forget ? {} : state.hide)}, current);
|
|
753
|
+
return result;
|
|
754
|
+
}, {fresh: forget});
|
|
755
|
+
},
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Drops the steps queued and not started yet (they resolve `{ok: false, cancelled: true}`); a step under way finishes,
|
|
759
|
+
* since an engine call cannot be stopped from outside.
|
|
760
|
+
*/
|
|
761
|
+
cancel() { generation += 1; },
|
|
762
|
+
};
|
|
763
|
+
return controller;
|
|
764
|
+
}
|