@arqlet/engine-client 0.9.0 → 0.10.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 +1 -1
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/arqlet.wasm +0 -0
- package/package.json +2 -2
- package/session.d.ts +21 -8
- package/session.js +20 -3
- package/view-controller.d.ts +34 -5
- package/view-controller.js +106 -19
- package/wasm-client.js +2 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The Arqlet engine as WebAssembly (`arqlet.wasm`, included) and its JavaScript ac
|
|
|
12
12
|
with `subscribe` (for `useSyncExternalStore`), open/close, paging through `+N more`, filters, a path or neighbourhood
|
|
13
13
|
kept as the highlight, the details of a selected node or edge (`select`, `state.details`) and the hover, back and
|
|
14
14
|
forward, search (`find`), `focus` for the camera, keyboard navigation (`navigate`, `navigateScene`), bookmarks
|
|
15
|
-
(`bookmark`, `openBookmark`, `encodeBookmark`), a look into a collapsed container (`peek`), refinement on a second
|
|
15
|
+
(`bookmark`, `openBookmark`, `encodeBookmark`; `compactBookmark` for a short text in a URL), a look into a collapsed container (`peek`), refinement on a second
|
|
16
16
|
engine (`refine` option,
|
|
17
17
|
`workerRefineRun`), and a
|
|
18
18
|
scene diff per step, snapshots the host made (`adopt`);
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Third-party notices
|
|
2
2
|
|
|
3
|
-
The WebAssembly
|
|
3
|
+
The WebAssembly module in this package contains the Rust crates listed below, each under the license named, and their
|
|
4
4
|
copyright and license notices follow. Arqlet itself is licensed under either of the Apache License, Version 2.0
|
|
5
5
|
(LICENSE-APACHE) or the MIT license (LICENSE-MIT), at your option.
|
|
6
6
|
|
package/arqlet.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arqlet/engine-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"access": "public"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@arqlet/contracts": "^0.
|
|
87
|
+
"@arqlet/contracts": "^0.10.0"
|
|
88
88
|
},
|
|
89
89
|
"scripts": {
|
|
90
90
|
"test": "node --test"
|
package/session.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ export type DetailTarget = {nodeId: string; edgeId?: never} | {edgeId: string; n
|
|
|
93
93
|
/** The answer of a read-only request (`trace`, `neighbourhood`): its fields beside `ok: true`, or the error. */
|
|
94
94
|
/** Provisional (ADR 0021, M5b): what a query is given besides its text. */
|
|
95
95
|
export interface QueryInit {
|
|
96
|
-
/** The values of the `$name` parameters (JSON values;
|
|
96
|
+
/** The values of the `$name` parameters (JSON values; an object is a map). */
|
|
97
97
|
params?: Record<string, unknown>;
|
|
98
98
|
/** Also map the answer onto the current view (`shown`); costs a few milliseconds on a large view. */
|
|
99
99
|
view?: boolean;
|
|
@@ -103,8 +103,19 @@ export interface QueryInit {
|
|
|
103
103
|
maxHops?: number;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
/**
|
|
107
|
-
|
|
106
|
+
/**
|
|
107
|
+
* A value in a row of a query answer: a JSON value or a list. Every object is tagged: a node is `{node: id}`, an edge
|
|
108
|
+
* `{edge: id}`, a map `{map: {key: value}}`.
|
|
109
|
+
*/
|
|
110
|
+
export type QueryValue =
|
|
111
|
+
| null
|
|
112
|
+
| boolean
|
|
113
|
+
| number
|
|
114
|
+
| string
|
|
115
|
+
| {node: string}
|
|
116
|
+
| {edge: string}
|
|
117
|
+
| {map: {[key: string]: QueryValue}}
|
|
118
|
+
| QueryValue[];
|
|
108
119
|
|
|
109
120
|
/** Provisional (ADR 0021, M5b): the answer of a query. */
|
|
110
121
|
export interface QueryAnswer {
|
|
@@ -120,7 +131,7 @@ export interface QueryAnswer {
|
|
|
120
131
|
contentRevision?: number;
|
|
121
132
|
/** Content for ids the graph does not have (kept, ignored by the query). */
|
|
122
133
|
ignoredContent?: number;
|
|
123
|
-
/** Content values the query layer has no type for (
|
|
134
|
+
/** Content values the query layer has no type for (an integer beyond 64 bits), read as null. */
|
|
124
135
|
skippedValues?: number;
|
|
125
136
|
/** With `view: true`: the box that shows each node and the drawn line that carries each edge (null when none). */
|
|
126
137
|
shown?: {nodes: Record<string, string | null>; edges: Record<string, string | null>};
|
|
@@ -312,7 +323,8 @@ export function httpRun(
|
|
|
312
323
|
|
|
313
324
|
/**
|
|
314
325
|
* An overview request without `op` and `graph` (`OverviewRequest` in `@arqlet/contracts`): `start` without positions
|
|
315
|
-
* continues from the last overview.
|
|
326
|
+
* continues from the last overview, `start.nodes` (places by node id) from the places given, also on a new graph, and
|
|
327
|
+
* keeps their clusters.
|
|
316
328
|
*/
|
|
317
329
|
export type OverviewSessionRequest = Omit<OverviewRequest, 'graph'>;
|
|
318
330
|
|
|
@@ -329,7 +341,8 @@ export interface OverviewAnswer {
|
|
|
329
341
|
export interface OverviewSession {
|
|
330
342
|
/** Lays out `graph`; replaces the graph the session had. */
|
|
331
343
|
open(graph: Graph, request?: OverviewSessionRequest): Promise<OverviewAnswer>;
|
|
332
|
-
/** Lays out the graph again; `start` without positions continues from the last overview (same cluster options).
|
|
344
|
+
/** Lays out the graph again; `start` without positions continues from the last overview (same cluster options).
|
|
345
|
+
* With `edgeData: true` the answer has each edge's kind and weight (ask each time). */
|
|
333
346
|
layOut(request?: OverviewSessionRequest): Promise<OverviewAnswer>;
|
|
334
347
|
/** Provisional: the paths between two nodes of the overview's graph, read only (`GraphTrace`). */
|
|
335
348
|
trace(from: string, to: string, init?: {mode?: 'shortest' | 'all'; edgeKinds?: string[]}): Promise<ReadAnswer<GraphTrace>>;
|
|
@@ -354,8 +367,8 @@ export function createOverviewSession(
|
|
|
354
367
|
init?: {
|
|
355
368
|
resident?: boolean | 'auto';
|
|
356
369
|
/**
|
|
357
|
-
* Provisional (ADR 0019, step 4): the overview's numbers (`parent`, `x`, `y`, `r`, `kind`, `edges`, `links
|
|
358
|
-
* arrays instead of JSON arrays, moved without JSON (copied once out of the engine's memory, transferred from a
|
|
370
|
+
* Provisional (ADR 0019, step 4): the overview's numbers (`parent`, `x`, `y`, `r`, `kind`, `edges`, `links`, and
|
|
371
|
+
* with `edgeData` `edgeKind` and `edgeWeight`) as typed arrays instead of JSON arrays, moved without JSON (copied once out of the engine's memory, transferred from a
|
|
359
372
|
* worker). Needs a resident session in an engine that offers `overview` (WASM, a worker); an answer says so
|
|
360
373
|
* otherwise. Default false: the arrays are plain, as before. Typed arrays index like arrays; a `start` built from
|
|
361
374
|
* them is sent as plain arrays.
|
package/session.js
CHANGED
|
@@ -574,6 +574,10 @@ const plain = request => {
|
|
|
574
574
|
return {...request, start: fixed};
|
|
575
575
|
};
|
|
576
576
|
|
|
577
|
+
// An overview's places by node id, as `start.nodes` takes them, each with its parent's id.
|
|
578
|
+
const placesOf = o => Object.fromEntries(Array.from(o.ids, (id, i) => [id,
|
|
579
|
+
{x: o.x[i], y: o.y[i], r: o.r[i], ...(o.parent[i] >= 0 ? {parent: o.ids[o.parent[i]]} : {})}]));
|
|
580
|
+
|
|
577
581
|
// The options the overview's clusters depend on; a continuation needs the same ones (as the engine's session checks).
|
|
578
582
|
// Defaults as the engine's (`communities` 120, `satellites` 0); `groups` and `hubs` compared as given.
|
|
579
583
|
const clustersOf = options => JSON.stringify([options?.communities ?? 120, options?.satellites ?? 0, options?.groups ?? null, options?.hubs ?? null]);
|
|
@@ -582,7 +586,8 @@ const clustersOf = options => JSON.stringify([options?.communities ?? 120, optio
|
|
|
582
586
|
* Provisional (ADR 0019 for the overview): an overview of one graph, laid out again as the host asks, with the graph kept
|
|
583
587
|
* in the engine where it can keep a session (`run.openSession`). `open(graph, request)` lays out a graph; `layOut(request)`
|
|
584
588
|
* lays it out again (other options, `radii`, `intent`, `configSet`); a `start` without positions (`{settle}` or `{}`)
|
|
585
|
-
* continues from the last overview
|
|
589
|
+
* continues from the last overview, and `{nodes}` (places by node id) from those places, also on a new graph (`open`).
|
|
590
|
+
* Without a resident session the graph and the last positions stay here and are sent
|
|
586
591
|
* along; the answers are the same. A new `open` overtakes what is still under way (`{ok: false, stale: true}`).
|
|
587
592
|
*/
|
|
588
593
|
export function createOverviewSession(run, {resident: wanted = 'auto', columns = false} = {}) {
|
|
@@ -591,6 +596,9 @@ export function createOverviewSession(run, {resident: wanted = 'auto', columns =
|
|
|
591
596
|
const opened = resident ? Promise.resolve(run.openSession()) : null;
|
|
592
597
|
// `graph` is kept here only without a resident session; `started`: an `open` was asked for (it may still run).
|
|
593
598
|
let graph = null, started = false, last = null, clusters = null, generation = 0, queue = Promise.resolve();
|
|
599
|
+
// Whether the last overview's clusters are those of places by id: an engine given the graph again would cluster it
|
|
600
|
+
// anew, so a continuation of it is sent by id too.
|
|
601
|
+
let byPlaces = false;
|
|
594
602
|
|
|
595
603
|
const send = async request => {
|
|
596
604
|
if (resident) {
|
|
@@ -604,15 +612,23 @@ export function createOverviewSession(run, {resident: wanted = 'auto', columns =
|
|
|
604
612
|
const answer = await (columns ? kept.overview(plain(asked), {copy: true}) : kept.run(asked));
|
|
605
613
|
if (answer.ok && answer.overview?.positionsOnly) {
|
|
606
614
|
const {positionsOnly: _moved, ...moved} = answer.overview;
|
|
607
|
-
|
|
615
|
+
// What became of places by id belongs to the answer that was asked with them.
|
|
616
|
+
const {continuation: _earlier, ...kept} = last;
|
|
617
|
+
return {...answer, overview: {...kept, ...moved}};
|
|
608
618
|
}
|
|
609
619
|
return answer;
|
|
610
620
|
}
|
|
611
621
|
const sent = {...request, graph: request.graph ?? graph};
|
|
612
622
|
const start = request.start;
|
|
613
|
-
if (start && start.x === undefined) {
|
|
623
|
+
if (start && start.x === undefined && start.nodes === undefined) {
|
|
614
624
|
if (!last || request.graph) return {ok: false, error: 'No overview to continue from: lay out without start first.'};
|
|
615
625
|
if (clustersOf(request.options) !== clusters) return {ok: false, error: 'The clusters changed since the last overview; lay out without start.'};
|
|
626
|
+
if (byPlaces) {
|
|
627
|
+
const answer = await run({...sent, start: {...start, nodes: placesOf(last)}});
|
|
628
|
+
if (!answer.ok) return answer;
|
|
629
|
+
const {continuation: _own, ...overview} = answer.overview;
|
|
630
|
+
return {...answer, overview};
|
|
631
|
+
}
|
|
616
632
|
sent.start = {...start, x: last.x, y: last.y, r: last.r};
|
|
617
633
|
}
|
|
618
634
|
return run(sent);
|
|
@@ -638,6 +654,7 @@ export function createOverviewSession(run, {resident: wanted = 'auto', columns =
|
|
|
638
654
|
if (answer.ok) {
|
|
639
655
|
last = answer.overview;
|
|
640
656
|
clusters = clustersOf(request.options);
|
|
657
|
+
byPlaces = !!request.start && (request.start.nodes !== undefined || (byPlaces && request.start.x === undefined));
|
|
641
658
|
if (fresh && !resident) graph = request.graph;
|
|
642
659
|
}
|
|
643
660
|
return answer;
|
package/view-controller.d.ts
CHANGED
|
@@ -2,7 +2,11 @@ import type {DetailsAnswer, FindAnswer, Graph, Hidden, Intent, NeighbourhoodAnsw
|
|
|
2
2
|
import type {DetailTarget, PayloadAnswer, PayloadChange, PeekAnswer, ReadAnswer, RefineRun, Session, SessionResult} from './session.js';
|
|
3
3
|
import type {EngineRequest} from './wasm-client.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Provisional: a view as a value (`bookmark`): the engine's intent, the highlight, the selection, and the digest of the
|
|
7
|
+
* source graph as the view had it (with its changed shapes, directions, strategies, routing and ports). Whether it
|
|
8
|
+
* belongs to a graph is answered by `openBookmark` (or the engine's `readBookmark`), not by comparing digests.
|
|
9
|
+
*/
|
|
6
10
|
export interface ViewBookmark {
|
|
7
11
|
version: 1;
|
|
8
12
|
digest: string | null;
|
|
@@ -11,7 +15,22 @@ export interface ViewBookmark {
|
|
|
11
15
|
selection?: DetailTarget;
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Provisional: what reading a bookmark against the current graph left out (`openBookmark` of a compact bookmark, or of a
|
|
20
|
+
* forced one of another graph).
|
|
21
|
+
*/
|
|
22
|
+
export interface BookmarkReport {
|
|
23
|
+
/** Whether the bookmark was made on this graph (not counting shapes, directions, strategies, routing and ports). */
|
|
24
|
+
sameSource: boolean;
|
|
25
|
+
/** Whether the view as imported that a compact bookmark was compared with is the one it was read with. */
|
|
26
|
+
sameDefaults: boolean;
|
|
27
|
+
/** The ids the bookmark names that the graph does not have. */
|
|
28
|
+
missing: string[];
|
|
29
|
+
/** The decisions left out, by kind (`collapsed`, `pins`, `partial`, `hidden`, `highlight`, `selection`, …) and id. */
|
|
30
|
+
ignored: {field: string; id: string}[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A bookmark as URL-safe text, and back (throws on text that is not one, such as a compact bookmark). */
|
|
15
34
|
export function encodeBookmark(bookmark: ViewBookmark): string;
|
|
16
35
|
export function decodeBookmark(text: string): ViewBookmark;
|
|
17
36
|
|
|
@@ -137,10 +156,20 @@ export interface ViewController {
|
|
|
137
156
|
cancelRefinement(): void;
|
|
138
157
|
/** Moves the selection the way `direction` says and sets `state.focus` (nothing opened, not a step for `back`). */
|
|
139
158
|
navigate(direction: NavigationDirection): Promise<ViewResult | {ok: false; none: true; collapsed?: boolean}>;
|
|
140
|
-
/** The view as a value to keep or share (`encodeBookmark` for a URL). */
|
|
159
|
+
/** The view as a value to keep or share (`encodeBookmark` for a URL; `compactBookmark` for a short one). */
|
|
141
160
|
bookmark(): Promise<{ok: true; bookmark: ViewBookmark} | {ok: false; error?: string; cancelled?: boolean}>;
|
|
142
|
-
/**
|
|
143
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Provisional: the view as a short text for a URL (`b1.…`): what differs from the view as imported, with the highlight
|
|
163
|
+
* and the selection. `openBookmark` opens it.
|
|
164
|
+
*/
|
|
165
|
+
compactBookmark(): Promise<{ok: true; text: string} | {ok: false; error?: string; cancelled?: boolean}>;
|
|
166
|
+
/**
|
|
167
|
+
* Opens a bookmark (a step for `back`), a value or a text. Another graph's long form is refused unless `force` (a graph
|
|
168
|
+
* that differs only in shapes, directions, strategies, routing and ports is the same one, and the bookmark's are
|
|
169
|
+
* restored); a compact one, and a forced one of another graph, restores what the graph has and reports the rest
|
|
170
|
+
* (`BookmarkReport`).
|
|
171
|
+
*/
|
|
172
|
+
openBookmark(bookmark: ViewBookmark | string, options?: {force?: boolean}): Promise<ViewResult & Partial<BookmarkReport>>;
|
|
144
173
|
back(): Promise<ViewResult>;
|
|
145
174
|
forward(): Promise<ViewResult>;
|
|
146
175
|
/** Any other change of the protocol, remembered for `back` under `label`. */
|
package/view-controller.js
CHANGED
|
@@ -127,8 +127,12 @@ export function navigateScene(scene, from, direction) {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
// The engine's compact bookmark (`compactBookmark`): `b1.` and base64url; the JSON form's text holds no `.`.
|
|
131
|
+
const compactText = /^b\d+\./;
|
|
132
|
+
|
|
130
133
|
/**
|
|
131
134
|
* A bookmark as text for a URL (base64url of its JSON, UTF-8), and back. `decodeBookmark` throws on text that is not one.
|
|
135
|
+
* This is the long form; `compactBookmark` of a view controller gives a short one, which `openBookmark` takes as text.
|
|
132
136
|
*/
|
|
133
137
|
export function encodeBookmark(bookmark) {
|
|
134
138
|
const bytes = new TextEncoder().encode(JSON.stringify(bookmark));
|
|
@@ -138,6 +142,7 @@ export function encodeBookmark(bookmark) {
|
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
export function decodeBookmark(text) {
|
|
145
|
+
if (compactText.test(text)) throw Error('A compact bookmark: open its text with openBookmark.');
|
|
141
146
|
const base64 = text.replace(/-/g, '+').replace(/_/g, '/');
|
|
142
147
|
const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4));
|
|
143
148
|
const bookmark = JSON.parse(new TextDecoder().decode(Uint8Array.from(binary, c => c.charCodeAt(0))));
|
|
@@ -210,6 +215,31 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
210
215
|
return answer.ok ? answer.digest ?? null : null;
|
|
211
216
|
};
|
|
212
217
|
|
|
218
|
+
// The view's decisions as it was imported, which a compact bookmark is compared with: undefined until they are read,
|
|
219
|
+
// null when unknown. They are read with the first change that reads the decisions anyway, or for a bookmark, so that no
|
|
220
|
+
// step costs an engine call for them; `pristine` says whether the view then came from an import.
|
|
221
|
+
let defaults;
|
|
222
|
+
let pristine = null;
|
|
223
|
+
const isPristine = snapshot => !!snapshot && (snapshot.layoutVersion ?? 0) === 0;
|
|
224
|
+
// Another view: its defaults are read from it, if it is as an import left it (a snapshot that went through changes holds
|
|
225
|
+
// decisions, which must stay in the bookmark).
|
|
226
|
+
const newView = () => {
|
|
227
|
+
defaults = undefined;
|
|
228
|
+
pristine = isPristine(session.snapshot);
|
|
229
|
+
};
|
|
230
|
+
// `now` is the current intent, if the caller has read it.
|
|
231
|
+
const readDefaults = async now => {
|
|
232
|
+
if (defaults !== undefined) return;
|
|
233
|
+
defaults = (pristine ?? isPristine(session.snapshot)) ? now ?? await intent() : null;
|
|
234
|
+
};
|
|
235
|
+
// Call before a change that may alter decisions, with the intent before it if the step has read it. Without it the
|
|
236
|
+
// defaults stay unknown: a compact bookmark then keeps every decision.
|
|
237
|
+
const beforeChange = async before => {
|
|
238
|
+
if (before) await readDefaults(before);
|
|
239
|
+
else if (defaults === undefined) defaults = null;
|
|
240
|
+
};
|
|
241
|
+
const withDefaults = request => (defaults ? {...request, defaults} : request);
|
|
242
|
+
|
|
213
243
|
// The current snapshot kept by the session for `back` (#148): its mark, or null without it.
|
|
214
244
|
const mark = async () => {
|
|
215
245
|
if (!keepGeometry || typeof session.keep !== 'function') return null;
|
|
@@ -222,6 +252,14 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
222
252
|
return answer.intent;
|
|
223
253
|
};
|
|
224
254
|
|
|
255
|
+
// What a bookmark keeps beside the decisions: the highlight's question (not its answer) and the selection.
|
|
256
|
+
const marks = () => {
|
|
257
|
+
const h = state.highlight;
|
|
258
|
+
const highlight = h ? {kind: h.kind, ...(h.kind === 'trace' ? {from: h.from, to: h.to} : {nodeId: h.nodeId}),
|
|
259
|
+
...(h.init ? {init: h.init} : {})} : null;
|
|
260
|
+
return {...(highlight ? {highlight} : {}), ...(state.selection ? {selection: state.selection} : {})};
|
|
261
|
+
};
|
|
262
|
+
|
|
225
263
|
// Asks the highlight's query again on the current view (its visible nodes and routes depend on what is open).
|
|
226
264
|
const refreshHighlight = async highlight => {
|
|
227
265
|
if (!highlight) return null;
|
|
@@ -300,10 +338,12 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
300
338
|
|
|
301
339
|
// A change the user makes: its decisions before and after are remembered (unless `remember` is false), so that `back`
|
|
302
340
|
// undoes it. A refinement under way is stopped: its result would be for the view before the change.
|
|
303
|
-
|
|
341
|
+
// `settles`: the change moves nodes and alters no decision.
|
|
342
|
+
const change = (label, run, extra = () => ({}), remember = true, merge = false, settles = false) => enqueue(async current => {
|
|
304
343
|
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
305
344
|
stopRefinement('cancelled');
|
|
306
345
|
const before = remember ? await intent() : null;
|
|
346
|
+
if (!settles) await beforeChange(before);
|
|
307
347
|
const beforeMark = remember ? await mark() : null;
|
|
308
348
|
const result = await run();
|
|
309
349
|
if (!current()) return {ok: false, cancelled: true};
|
|
@@ -387,6 +427,7 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
387
427
|
publish({error: result.error ?? 'The import failed.'});
|
|
388
428
|
return result;
|
|
389
429
|
}
|
|
430
|
+
newView();
|
|
390
431
|
state = Object.freeze({...state, scene: null, highlight: null, selection: null, details: null, hover: null,
|
|
391
432
|
search: null, focus: null, peek: null, hide: {}, steps: 0});
|
|
392
433
|
await settle({}, current);
|
|
@@ -647,42 +688,86 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
647
688
|
|
|
648
689
|
/**
|
|
649
690
|
* 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
|
|
691
|
+
* highlight and the selection, and the digest of the graph it belongs to. `encodeBookmark` makes it text for a URL;
|
|
692
|
+
* `compactBookmark` gives a much shorter one.
|
|
651
693
|
*/
|
|
652
694
|
bookmark() {
|
|
653
695
|
return enqueue(async () => {
|
|
654
696
|
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
697
|
+
return {ok: true, bookmark: {version: 1, digest: await digest(), intent: await intent(), ...marks()}};
|
|
698
|
+
});
|
|
699
|
+
},
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Provisional: the view as a short text for a URL, `{ok, text}` (`b1.…`, base64url), made by the engine (operation
|
|
703
|
+
* `compactBookmark`): only what differs from the view as it was imported, every id once, with the highlight and the
|
|
704
|
+
* selection. `openBookmark(text)` opens it.
|
|
705
|
+
*/
|
|
706
|
+
compactBookmark() {
|
|
707
|
+
return enqueue(async () => {
|
|
708
|
+
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
709
|
+
await readDefaults();
|
|
710
|
+
const answer = await session.apply(withDefaults({op: 'compactBookmark', ...marks()}));
|
|
711
|
+
if (!answer.ok) publish({error: answer.error ?? 'No bookmark.'});
|
|
712
|
+
return answer;
|
|
661
713
|
});
|
|
662
714
|
},
|
|
663
715
|
|
|
664
716
|
/**
|
|
665
|
-
* Opens a bookmark on the current graph (a step for `back`): its decisions, highlight and selection.
|
|
666
|
-
*
|
|
717
|
+
* Opens a bookmark on the current graph (a step for `back`): its decisions, highlight and selection. `bookmark` is the
|
|
718
|
+
* value of `bookmark()` or a text (of `compactBookmark` or `encodeBookmark`). A bookmark in the long form of another
|
|
719
|
+
* graph is refused unless `force`: one with another digest that the engine does not find to be this graph with the
|
|
720
|
+
* bookmark's own shapes, directions, strategies, routing and ports (`readBookmark`, `sameSource`). A compact one, and
|
|
721
|
+
* a forced one of another graph, is read against the graph (`readBookmark`): what names an id the graph no longer has
|
|
722
|
+
* is left out, and the result says so (`missing`, `ignored`, `sameSource`, `sameDefaults`).
|
|
667
723
|
*/
|
|
668
724
|
openBookmark(bookmark, {force = false} = {}) {
|
|
669
725
|
return enqueue(async current => {
|
|
670
726
|
if (!session.snapshot) return {ok: false, error: 'Nothing imported yet.'};
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
if (
|
|
727
|
+
const compact = typeof bookmark === 'string' && compactText.test(bookmark);
|
|
728
|
+
let opened = bookmark;
|
|
729
|
+
if (typeof bookmark === 'string' && !compact) {
|
|
730
|
+
try { opened = decodeBookmark(bookmark); } catch { opened = null; }
|
|
731
|
+
}
|
|
732
|
+
if (!compact && (opened?.version !== 1 || typeof opened.intent !== 'object')) {
|
|
733
|
+
return {ok: false, error: 'Not a view bookmark.'};
|
|
734
|
+
}
|
|
735
|
+
const now = !compact && opened.digest ? await digest() : null;
|
|
736
|
+
let other = false;
|
|
737
|
+
let read = null;
|
|
738
|
+
if (now && opened.digest !== now) {
|
|
739
|
+
// The digest is of the graph with the shapes, directions and so on of the bookmarked view: the engine says
|
|
740
|
+
// whether this is that graph.
|
|
741
|
+
read = await session.apply({op: 'readBookmark', bookmark: opened});
|
|
742
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
743
|
+
other = !(read.ok && read.sameSource);
|
|
744
|
+
}
|
|
745
|
+
if (other && !force) {
|
|
674
746
|
const error = 'The bookmark belongs to another graph.';
|
|
675
747
|
publish({error});
|
|
676
748
|
return {ok: false, error};
|
|
677
749
|
}
|
|
678
750
|
stopRefinement('cancelled');
|
|
679
751
|
const before = await intent();
|
|
752
|
+
await readDefaults(before);
|
|
753
|
+
let report = {};
|
|
754
|
+
if (compact || other) {
|
|
755
|
+
if (compact) read = await session.apply(withDefaults({op: 'readBookmark', text: bookmark}));
|
|
756
|
+
if (!current()) return {ok: false, cancelled: true};
|
|
757
|
+
if (!read.ok) {
|
|
758
|
+
publish({error: read.error ?? 'The engine refused the bookmark.'});
|
|
759
|
+
return read;
|
|
760
|
+
}
|
|
761
|
+
const {sameSource, sameDefaults, missing, ignored} = read;
|
|
762
|
+
report = {sameSource, sameDefaults, missing, ignored};
|
|
763
|
+
opened = read.bookmark;
|
|
764
|
+
}
|
|
680
765
|
const beforeMark = await mark();
|
|
681
|
-
const result = await session.apply({op: 'restore', intent:
|
|
766
|
+
const result = await session.apply({op: 'restore', intent: opened.intent});
|
|
682
767
|
if (!current()) return {ok: false, cancelled: true};
|
|
683
768
|
if (!result.ok) {
|
|
684
769
|
publish({error: result.error ?? 'The engine refused the bookmark.'});
|
|
685
|
-
return result;
|
|
770
|
+
return {...result, ...report};
|
|
686
771
|
}
|
|
687
772
|
const after = await intent();
|
|
688
773
|
if (!same(before, after)) {
|
|
@@ -690,9 +775,9 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
690
775
|
if (back.length > historyLimit) back.shift();
|
|
691
776
|
forward = [];
|
|
692
777
|
}
|
|
693
|
-
state = Object.freeze({...state, highlight:
|
|
694
|
-
await settle({hide:
|
|
695
|
-
return result;
|
|
778
|
+
state = Object.freeze({...state, highlight: opened.highlight ?? null, selection: opened.selection ?? null});
|
|
779
|
+
await settle({hide: opened.intent.hidden ?? {}}, current);
|
|
780
|
+
return {...result, ...report};
|
|
696
781
|
});
|
|
697
782
|
},
|
|
698
783
|
|
|
@@ -717,7 +802,7 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
717
802
|
* `remember: false`, for steps that change no decision, such as settling).
|
|
718
803
|
*/
|
|
719
804
|
apply(request, label = request.op, {remember = true, merge = false} = {}) {
|
|
720
|
-
return change(label, () => session.apply(request), () => ({}), remember, merge);
|
|
805
|
+
return change(label, () => session.apply(request), () => ({}), remember, merge, request.op === 'settle');
|
|
721
806
|
},
|
|
722
807
|
|
|
723
808
|
/**
|
|
@@ -729,6 +814,7 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
729
814
|
// With `remember` (a label) the change from the session's snapshot to this one is remembered for `back`.
|
|
730
815
|
stopRefinement('cancelled');
|
|
731
816
|
const before = remember && session.snapshot ? await intent() : null;
|
|
817
|
+
if (!forget && session.snapshot) await beforeChange(before);
|
|
732
818
|
const beforeMark = before ? await mark() : null;
|
|
733
819
|
const result = await session.load(snapshot, {reset: forget});
|
|
734
820
|
if (!current()) return {ok: false, cancelled: true};
|
|
@@ -737,6 +823,7 @@ export function createViewController(session, {page = 12, historyLimit = 50, sce
|
|
|
737
823
|
return result;
|
|
738
824
|
}
|
|
739
825
|
if (forget) {
|
|
826
|
+
newView();
|
|
740
827
|
back = [];
|
|
741
828
|
forward = [];
|
|
742
829
|
state = Object.freeze({...state, highlight: null, selection: null, details: null, hover: null, search: null,
|
package/wasm-client.js
CHANGED
|
@@ -56,7 +56,8 @@ export async function createEngine(bytes,{onPublish}={}) {
|
|
|
56
56
|
return {...result,...viewsOf(listed,index=>api.lw_session_column(id,index),false)};
|
|
57
57
|
};
|
|
58
58
|
// Provisional: an `overview` request whose numbers come back as typed arrays instead of JSON arrays (`parent`, `x`,
|
|
59
|
-
// `y`, `r`, `kind`, `edges`, `links
|
|
59
|
+
// `y`, `r`, `kind`, `edges`, `links`, and with `edgeData` `edgeKind` and `edgeWeight`; a continuation with
|
|
60
|
+
// `positionsOnly` only `x`, `y` and `r`), in an answer shaped
|
|
60
61
|
// like the JSON one. `copy` (default false) copies them out of the module's memory, for a host that keeps them past
|
|
61
62
|
// its next request; views are valid only until then.
|
|
62
63
|
const overview=(request,{copy=false}={})=>{
|