@arqlet/engine-client 0.6.0 → 0.7.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/arqlet.wasm +0 -0
- package/columns.d.ts +3 -0
- package/columns.js +5 -1
- package/package.json +2 -2
- package/session.d.ts +38 -0
- package/session.js +75 -0
- package/wasm-client.js +3 -1
package/arqlet.wasm
CHANGED
|
Binary file
|
package/columns.d.ts
CHANGED
|
@@ -22,6 +22,9 @@ export interface SceneColumns {
|
|
|
22
22
|
nodeKind: Uint32Array;
|
|
23
23
|
/** Values of `SHAPES`. */
|
|
24
24
|
nodeShape: Uint32Array;
|
|
25
|
+
/** Provisional: each node's `childCount` and `hiddenCount`, `NONE` when absent. */
|
|
26
|
+
nodeChildCount: Uint32Array;
|
|
27
|
+
nodeHiddenCount: Uint32Array;
|
|
25
28
|
|
|
26
29
|
/** Route ids by route index. */
|
|
27
30
|
routeIds: string[];
|
package/columns.js
CHANGED
|
@@ -56,12 +56,16 @@ export function columnsOfScene(scene) {
|
|
|
56
56
|
const nodeFlags = new Uint32Array(nodes.length);
|
|
57
57
|
const nodeKind = new Uint32Array(nodes.length);
|
|
58
58
|
const nodeShape = new Uint32Array(nodes.length);
|
|
59
|
+
const nodeChildCount = new Uint32Array(nodes.length);
|
|
60
|
+
const nodeHiddenCount = new Uint32Array(nodes.length);
|
|
59
61
|
const nodeKinds = table();
|
|
60
62
|
nodes.forEach((n, i) => {
|
|
61
63
|
nodeParent[i] = n.parentId == null ? NONE : at(n.parentId);
|
|
62
64
|
nodeFlags[i] = (n.container ? 1 : 0) | (n.aggregate ? 2 : 0) | (n.collapsed ? 4 : 0) | (n.invalid ? 8 : 0);
|
|
63
65
|
nodeKind[i] = nodeKinds.id(n.kind);
|
|
64
66
|
nodeShape[i] = SHAPES[n.shape] ?? 0;
|
|
67
|
+
nodeChildCount[i] = n.childCount ?? NONE;
|
|
68
|
+
nodeHiddenCount[i] = n.hiddenCount ?? NONE;
|
|
65
69
|
});
|
|
66
70
|
|
|
67
71
|
const routeSource = new Uint32Array(routes.length);
|
|
@@ -137,7 +141,7 @@ export function columnsOfScene(scene) {
|
|
|
137
141
|
buses: scene.buses ?? [],
|
|
138
142
|
bounds: b ? [b.x, b.y, b.width, b.height] : [0, 0, 0, 0],
|
|
139
143
|
showPorts: Boolean(scene.showPorts),
|
|
140
|
-
nodeBounds, nodeParent, nodeFlags, nodeKind, nodeShape,
|
|
144
|
+
nodeBounds, nodeParent, nodeFlags, nodeKind, nodeShape, nodeChildCount, nodeHiddenCount,
|
|
141
145
|
routeSource, routeTarget, routeWeight, routeFlags, routeOffsets, routePoints,
|
|
142
146
|
routeKind, routeBackWeight, routeMemberOffsets: Uint32Array.from(routeMemberOffsets), routeMembers: Uint32Array.from(routeMembers),
|
|
143
147
|
portNode, portEdge, portFlags, portSide, portPosition: points(ports, p => p.position),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arqlet/engine-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The Arqlet graph-layout engine as WebAssembly, with a loader, a worker protocol, an ELK-style layout call and preset sequencing. Provisional.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graph",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@arqlet/contracts": "^0.
|
|
80
|
+
"@arqlet/contracts": "^0.7.0"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"test": "node --test"
|
package/session.d.ts
CHANGED
|
@@ -3,6 +3,31 @@ import type {SceneColumns} from './columns.js';
|
|
|
3
3
|
import type {EngineRequest, EngineResponse, Run} from './wasm-client.js';
|
|
4
4
|
|
|
5
5
|
/** An engine answer as the session reports it. `stale`: an import or reset overtook the change, nothing was applied. */
|
|
6
|
+
/** Provisional (drag API): a move gesture of `Session.drag`. */
|
|
7
|
+
export interface DragHandle {
|
|
8
|
+
/** The node being moved. */
|
|
9
|
+
readonly node: string;
|
|
10
|
+
/** Whether the gesture still takes positions (not dropped, cancelled or refused). */
|
|
11
|
+
readonly active: boolean;
|
|
12
|
+
/** Steps sent, positions replaced by a newer one before they were sent, and steps the engine applied. */
|
|
13
|
+
readonly stats: {sent: number; coalesced: number; applied: number};
|
|
14
|
+
/** The answer to picking the node up (the first step). */
|
|
15
|
+
readonly begun: Promise<SessionResult>;
|
|
16
|
+
/**
|
|
17
|
+
* A newer position (and optionally newer positions of the others). Positions that arrive while one is computed replace
|
|
18
|
+
* each other: only the newest is sent. Resolves with the answer of the step that carried it, or `{ok: true, unchanged}`
|
|
19
|
+
* when a newer position took its place.
|
|
20
|
+
*/
|
|
21
|
+
move(position: {x: number; y: number}, others?: Record<string, {x: number; y: number}>): Promise<SessionResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Applies the last position and ends the gesture; the node stays pinned there, or with `release` the layout may move it
|
|
24
|
+
* again. With `settle`, force-directed areas settle afterwards (`op: settle`).
|
|
25
|
+
*/
|
|
26
|
+
drop(init?: {release?: boolean; settle?: boolean}): Promise<SessionResult>;
|
|
27
|
+
/** Ends the gesture and puts the node (and the others) back where they were. */
|
|
28
|
+
cancel(): Promise<SessionResult>;
|
|
29
|
+
}
|
|
30
|
+
|
|
6
31
|
export interface SessionResult {
|
|
7
32
|
ok: boolean;
|
|
8
33
|
snapshot?: Snapshot;
|
|
@@ -61,6 +86,19 @@ export interface Session {
|
|
|
61
86
|
* where it was.
|
|
62
87
|
*/
|
|
63
88
|
patch(patch: GraphPatch): Promise<SessionResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Provisional (drag API): pins `nodeId` at `position` (in its parent's frame, as `toReactFlow` gives `position`), or
|
|
91
|
+
* where it is now. The layout keeps a pinned node in place.
|
|
92
|
+
*/
|
|
93
|
+
pin(nodeId: string, position?: {x: number; y: number}): Promise<SessionResult>;
|
|
94
|
+
/** Provisional (drag API): releases the pin of `nodeId`; the layout may move it again. */
|
|
95
|
+
unpin(nodeId: string): Promise<SessionResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Provisional (drag API): starts moving leaf `nodeId` to `position` (in its parent's frame). `others` maps further
|
|
98
|
+
* nodes moved with it (a selection) to their positions; the set is fixed for the gesture. Each applied step changes the
|
|
99
|
+
* session's snapshot (`onChange`); other changes wait until the gesture ends.
|
|
100
|
+
*/
|
|
101
|
+
drag(nodeId: string, position: {x: number; y: number}, init?: {others?: Record<string, {x: number; y: number}>}): DragHandle;
|
|
64
102
|
/** Provisional: opens the groups that hold `nodeIds`; with `partial` (default true) only as far as needed. */
|
|
65
103
|
reveal(nodeIds: string[], init?: {partial?: boolean}): Promise<SessionResult>;
|
|
66
104
|
/** Provisional: hides nodes by kind or id (with what they hold) and edges by kind, keeping the place of the rest, or
|
package/session.js
CHANGED
|
@@ -85,6 +85,8 @@ export function httpRun(base = '/api', {fetchImpl = globalThis.fetch} = {}) {
|
|
|
85
85
|
* chooses: `'auto'` (default) where the engine can, `true` always (an error without it), `false` never (every request
|
|
86
86
|
* sends the snapshot, as before 0.4).
|
|
87
87
|
*/
|
|
88
|
+
let dragCounter = 0;
|
|
89
|
+
|
|
88
90
|
export function createSession(run, {onChange, resident: wanted = 'auto'} = {}) {
|
|
89
91
|
let snapshot = null;
|
|
90
92
|
let generation = 0;
|
|
@@ -206,6 +208,79 @@ export function createSession(run, {onChange, resident: wanted = 'auto'} = {}) {
|
|
|
206
208
|
*/
|
|
207
209
|
patch(patch) { return change({op: 'patch', patch}); },
|
|
208
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Provisional (drag API): pins `nodeId` at `position` (in its parent's frame, as `toReactFlow` gives `position`), or
|
|
213
|
+
* where it is now; the layout keeps it there.
|
|
214
|
+
*/
|
|
215
|
+
pin(nodeId, position) { return change({op: 'pin', nodeId, ...(position ? {position} : {})}); },
|
|
216
|
+
|
|
217
|
+
/** Provisional (drag API): releases the pin of `nodeId`; the layout may move it again. */
|
|
218
|
+
unpin(nodeId) { return change({op: 'pin', nodeId, unpin: true}); },
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Provisional (drag API): starts moving leaf `nodeId` to `position` (in its parent's frame). `others` maps further
|
|
222
|
+
* nodes moved with it (a selection) to their positions; the set is fixed for the gesture. Returns a handle:
|
|
223
|
+
* `move(position, others?)` sends a newer position (positions that arrive while one is computed replace each other, so
|
|
224
|
+
* only the newest is sent); `drop({release, settle})` applies the last position and ends the gesture, keeping the node
|
|
225
|
+
* pinned there (or releasing the pin with `release`), then with `settle` lets force-directed areas settle; `cancel()`
|
|
226
|
+
* puts the node back. Every applied step changes the session's snapshot (`onChange`), so a host redraws from
|
|
227
|
+
* `scene()`. Other changes wait until the gesture ends.
|
|
228
|
+
*/
|
|
229
|
+
drag(nodeId, position, {others = {}} = {}) {
|
|
230
|
+
const id = `drag-${++dragCounter}`;
|
|
231
|
+
let seq = 0, pending = null, inFlight = null, ended = false, refused = null;
|
|
232
|
+
const stats = {sent: 0, coalesced: 0, applied: 0};
|
|
233
|
+
const step = (phase, at, release = false) => {
|
|
234
|
+
seq += 1;
|
|
235
|
+
stats.sent += 1;
|
|
236
|
+
return enqueue(() => send({op: 'move', gestureId: id, seq, phase, node: nodeId, position: at, release,
|
|
237
|
+
...(Object.keys(others).length ? {others} : {})})).then(answer => {
|
|
238
|
+
if (answer.ok) stats.applied += 1; else refused ??= answer;
|
|
239
|
+
return answer;
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
// One step at a time; the newest pending position goes next.
|
|
243
|
+
const pump = () => {
|
|
244
|
+
if (inFlight || !pending || refused) return inFlight;
|
|
245
|
+
const at = pending;
|
|
246
|
+
pending = null;
|
|
247
|
+
inFlight = step('update', at).finally(() => { inFlight = null; pump(); });
|
|
248
|
+
return inFlight;
|
|
249
|
+
};
|
|
250
|
+
const begun = step('begin', position);
|
|
251
|
+
const end = async (phase, release, settle) => {
|
|
252
|
+
if (ended) return {ok: false, error: 'The gesture has ended.'};
|
|
253
|
+
ended = true;
|
|
254
|
+
await begun;
|
|
255
|
+
while (inFlight) await inFlight;
|
|
256
|
+
if (phase === 'cancel') pending = null;
|
|
257
|
+
if (pending && !refused) { const at = pending; pending = null; await step('update', at); }
|
|
258
|
+
if (refused) return refused;
|
|
259
|
+
const answer = await step(phase, null, release);
|
|
260
|
+
if (answer.ok && settle) return change({op: 'settle'});
|
|
261
|
+
return answer;
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
/** The node being moved. */
|
|
265
|
+
node: nodeId,
|
|
266
|
+
/** Whether the gesture still takes positions. */
|
|
267
|
+
get active() { return !ended && !refused; },
|
|
268
|
+
/** Steps sent, positions replaced by newer ones before they were sent, and steps applied. */
|
|
269
|
+
get stats() { return {...stats}; },
|
|
270
|
+
/** The answer of the first step (the engine's view after the node was picked up). */
|
|
271
|
+
begun,
|
|
272
|
+
move(at, moved) {
|
|
273
|
+
if (ended || refused) return Promise.resolve(refused ?? {ok: false, error: 'The gesture has ended.'});
|
|
274
|
+
if (pending) stats.coalesced += 1;
|
|
275
|
+
pending = at;
|
|
276
|
+
if (moved) others = moved;
|
|
277
|
+
return begun.then(() => pump() ?? {ok: true, unchanged: true});
|
|
278
|
+
},
|
|
279
|
+
drop({release = false, settle = false} = {}) { return end('finish', release, settle); },
|
|
280
|
+
cancel() { return end('cancel', false, false); },
|
|
281
|
+
};
|
|
282
|
+
},
|
|
283
|
+
|
|
209
284
|
/** Provisional: opens the groups that hold `nodeIds`; with `partial` (default) only as far as needed. */
|
|
210
285
|
reveal(nodeIds, {partial = true} = {}) { return change({op: 'reveal', nodeIds, partial}); },
|
|
211
286
|
|
package/wasm-client.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// `onPublish(message)` receives each progressive publication as JSON while the call that produced it is still running.
|
|
2
|
-
// The module always imports `lw_publish`; without a callback the messages are dropped.
|
|
2
|
+
// The module always imports `lw_publish` and `lw_now`; without a callback the messages are dropped.
|
|
3
3
|
export async function createEngine(bytes,{onPublish}={}) {
|
|
4
4
|
const decoder=new TextDecoder();
|
|
5
5
|
let api;
|
|
6
6
|
const imports={env:{
|
|
7
|
+
// The clock for phase timings (`timings: true` on a request); the layout itself never reads it.
|
|
8
|
+
lw_now:()=>performance.now(),
|
|
7
9
|
lw_publish:(ptr,len)=>{
|
|
8
10
|
if(!onPublish) return;
|
|
9
11
|
// Copy out of linear memory now: the module releases the buffer when this returns.
|