@graview/graverse 0.0.0-stage → 0.2.19
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/LICENSE +96 -0
- package/README.md +50 -2
- package/dist/camera.d.ts +108 -0
- package/dist/camera.d.ts.map +1 -0
- package/dist/camera.js +169 -0
- package/dist/camera.js.map +1 -0
- package/dist/client.d.ts +14 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +72 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +610 -0
- package/dist/index.js.map +1 -0
- package/dist/labels.d.ts +36 -0
- package/dist/labels.d.ts.map +1 -0
- package/dist/labels.js +79 -0
- package/dist/labels.js.map +1 -0
- package/dist/layout.d.ts +74 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +238 -0
- package/dist/layout.js.map +1 -0
- package/dist/space-host.d.ts +47 -0
- package/dist/space-host.d.ts.map +1 -0
- package/dist/space-host.js +2 -0
- package/dist/space-host.js.map +1 -0
- package/dist/space.d.ts +3 -0
- package/dist/space.d.ts.map +1 -0
- package/dist/space.js +757 -0
- package/dist/space.js.map +1 -0
- package/dist/style.d.ts +2 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/style.js +125 -0
- package/dist/style.js.map +1 -0
- package/dist/words.d.ts +16 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +43 -0
- package/dist/words.js.map +1 -0
- package/package.json +63 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import { hubClient } from "./client.js";
|
|
2
|
+
import { universeLayout } from "./layout.js";
|
|
3
|
+
import { STYLE } from "./style.js";
|
|
4
|
+
import { agoWords, counted, nounOf, pluralOf, sentence, termsOf, withoutTerm } from "./words.js";
|
|
5
|
+
export { hubClient } from "./client.js";
|
|
6
|
+
const esc = (text) => text.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
7
|
+
const reEsc = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8
|
+
/** Whether this browser can draw WebGL at all: asked of a canvas nobody sees. */
|
|
9
|
+
export function canDrawSpace() {
|
|
10
|
+
try {
|
|
11
|
+
const canvas = document.createElement("canvas");
|
|
12
|
+
return !!(canvas.getContext("webgl2") ?? canvas.getContext("webgl"));
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function el(tag, attrs = {}, html = "") {
|
|
19
|
+
const node = document.createElement(tag);
|
|
20
|
+
for (const [name, value] of Object.entries(attrs))
|
|
21
|
+
node.setAttribute(name, value);
|
|
22
|
+
if (html)
|
|
23
|
+
node.innerHTML = html;
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
export function mountGraverse(root, options = {}) {
|
|
27
|
+
const client = options.client ?? hubClient();
|
|
28
|
+
const go = options.go ?? ((url) => window.location.assign(url));
|
|
29
|
+
const today = () => options.today ?? new Date().toISOString();
|
|
30
|
+
const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)");
|
|
31
|
+
if (!document.getElementById("gv-style"))
|
|
32
|
+
document.head.append(el("style", { id: "gv-style" }, STYLE));
|
|
33
|
+
const shell = el("div", { class: "gv flat", "data-graverse": "loading" });
|
|
34
|
+
shell.innerHTML = `
|
|
35
|
+
<div class="gv-stage" aria-hidden="true"></div>
|
|
36
|
+
<div class="gv-veil"></div>
|
|
37
|
+
<header class="gv-top">
|
|
38
|
+
<h1 class="gv-mark">Graverse</h1>
|
|
39
|
+
<nav class="gv-crumbs" aria-label="Where you are"></nav>
|
|
40
|
+
<div class="gv-pill" role="status" hidden></div>
|
|
41
|
+
</header>
|
|
42
|
+
<div class="gv-body">
|
|
43
|
+
<section class="gv-index" aria-label="Every app">
|
|
44
|
+
<form class="gv-find" role="search">
|
|
45
|
+
<label class="sr-only" for="gv-q">Find anything, in any field of any app</label>
|
|
46
|
+
<input id="gv-q" type="search" placeholder="Find anything, in any app" autocomplete="off" spellcheck="false" enterkeyhint="search">
|
|
47
|
+
</form>
|
|
48
|
+
<div class="gv-list" aria-live="polite"></div>
|
|
49
|
+
</section>
|
|
50
|
+
<section class="gv-detail" aria-label="Chosen" hidden></section>
|
|
51
|
+
</div>
|
|
52
|
+
<p class="gv-hint" hidden><b>Drag</b> to move · <b>Scroll</b> to zoom · <b>Right-drag</b> or <b>Option-drag</b> to turn · <b>Click</b> to choose, again to open · <b>Esc</b> steps back · <b>/</b> finds</p>`;
|
|
53
|
+
root.append(shell);
|
|
54
|
+
const $ = (selector) => shell.querySelector(selector);
|
|
55
|
+
const stage = $(".gv-stage");
|
|
56
|
+
const crumbs = $(".gv-crumbs");
|
|
57
|
+
const pill = $(".gv-pill");
|
|
58
|
+
const input = $("#gv-q");
|
|
59
|
+
const list = $(".gv-list");
|
|
60
|
+
const detail = $(".gv-detail");
|
|
61
|
+
const hint = $(".gv-hint");
|
|
62
|
+
let description = null;
|
|
63
|
+
let refused = null;
|
|
64
|
+
let layout = null;
|
|
65
|
+
let chosen = {};
|
|
66
|
+
let search = null;
|
|
67
|
+
let finding = null;
|
|
68
|
+
let typing;
|
|
69
|
+
const clouds = new Map();
|
|
70
|
+
let space = null;
|
|
71
|
+
let destroyed = false;
|
|
72
|
+
const appOf = (address) => description?.apps.find((one) => one.app.address === address);
|
|
73
|
+
const readable = (app) => app.state === "ready" || app.state === "seed-only";
|
|
74
|
+
const recordsIn = (app) => Object.values(app.facts?.counts ?? {}).reduce((sum, n) => sum + n, 0);
|
|
75
|
+
const changedOf = (app) => app.facts?.changed ?? app.changed;
|
|
76
|
+
const terms = () => (search ? termsOf(search.query).filter((term) => !/^[a-z][\w-]*(?:>=|<=|[:=<>])/i.test(term)) : []);
|
|
77
|
+
const highlight = (text) => {
|
|
78
|
+
const words = terms().filter((term) => term.length > 1);
|
|
79
|
+
if (words.length === 0)
|
|
80
|
+
return esc(text);
|
|
81
|
+
// Split the text as written, then escape each piece: a term never matches inside an escaped character.
|
|
82
|
+
return text
|
|
83
|
+
.split(new RegExp(`(${words.map(reEsc).join("|")})`, "gi"))
|
|
84
|
+
.map((piece, i) => (i % 2 === 1 ? `<mark>${esc(piece)}</mark>` : esc(piece)))
|
|
85
|
+
.join("");
|
|
86
|
+
};
|
|
87
|
+
const matches = () => (search ? new Map(search.groups.map((group) => [group.app.address, group.total])) : null);
|
|
88
|
+
/** The url of a record of an app's cloud: its kind's list under the app, then its id. */
|
|
89
|
+
const recordUrl = (app, cloud, point) => {
|
|
90
|
+
const kind = cloud.kinds[point.k];
|
|
91
|
+
const base = app.app.url.endsWith("/") ? app.app.url.slice(0, -1) : app.app.url;
|
|
92
|
+
return `${base}${kind?.path ?? `/${encodeURIComponent(kind?.kind ?? "")}`}/${encodeURIComponent(point.id)}`;
|
|
93
|
+
};
|
|
94
|
+
/* ── asking ───────────────────────────────────────────────────────── */
|
|
95
|
+
function askCloud(address) {
|
|
96
|
+
const app = appOf(address);
|
|
97
|
+
const had = clouds.get(address);
|
|
98
|
+
// A cloud asked, or come, is not asked again; one refused or slow is, the next time it is chosen or approached.
|
|
99
|
+
if (!app || !readable(app) || had === "asking" || (had && "points" in had))
|
|
100
|
+
return;
|
|
101
|
+
clouds.set(address, "asking");
|
|
102
|
+
void client.cloud(address).then((answer) => {
|
|
103
|
+
clouds.set(address, answer);
|
|
104
|
+
if (destroyed)
|
|
105
|
+
return;
|
|
106
|
+
render();
|
|
107
|
+
space?.changed();
|
|
108
|
+
}, () => {
|
|
109
|
+
clouds.set(address, { refused: `${app.app.name} could not be read.` });
|
|
110
|
+
if (destroyed)
|
|
111
|
+
return;
|
|
112
|
+
render();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
async function describe() {
|
|
116
|
+
let answer = await client.describe();
|
|
117
|
+
if ("refused" in answer) {
|
|
118
|
+
refused = answer.refused;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// The apps whose facts were not asked yet are asked next, a few calls at most.
|
|
122
|
+
for (let more = 0; answer.next && more < 4; more++) {
|
|
123
|
+
const next = await client.describe({ after: answer.next });
|
|
124
|
+
if ("refused" in next)
|
|
125
|
+
break;
|
|
126
|
+
const facts = new Map(next.apps.filter((one) => one.facts).map((one) => [one.app.address, one.facts]));
|
|
127
|
+
answer = { ...next, apps: answer.apps.map((one) => (facts.has(one.app.address) ? { ...one, facts: facts.get(one.app.address) } : one)) };
|
|
128
|
+
}
|
|
129
|
+
description = answer;
|
|
130
|
+
layout = universeLayout(answer, { today: today() });
|
|
131
|
+
}
|
|
132
|
+
function find(query, cursor) {
|
|
133
|
+
finding?.abort();
|
|
134
|
+
const trimmed = query.trim();
|
|
135
|
+
if (!trimmed) {
|
|
136
|
+
finding = null;
|
|
137
|
+
search = null;
|
|
138
|
+
update();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const control = new AbortController();
|
|
142
|
+
finding = control;
|
|
143
|
+
const carried = cursor && search && search.query === trimmed ? search : null;
|
|
144
|
+
const now = carried ? { ...carried, slow: [], refused: [], done: false } : { query: trimmed, groups: [], slow: [], refused: [], done: false };
|
|
145
|
+
search = now;
|
|
146
|
+
update();
|
|
147
|
+
void (async () => {
|
|
148
|
+
for await (const event of client.find(trimmed, { ...(cursor ? { cursor } : {}), signal: control.signal })) {
|
|
149
|
+
if (control.signal.aborted || search !== now)
|
|
150
|
+
return;
|
|
151
|
+
if (event.type === "app") {
|
|
152
|
+
now.groups = [...now.groups.filter((group) => group.app.address !== event.group.app.address), event.group];
|
|
153
|
+
}
|
|
154
|
+
else if (event.type === "slow")
|
|
155
|
+
now.slow.push(event);
|
|
156
|
+
else if (event.type === "refused")
|
|
157
|
+
now.refused.push(event);
|
|
158
|
+
else if (event.type === "call-refused") {
|
|
159
|
+
now.callRefused = event.refused.refused;
|
|
160
|
+
now.done = true;
|
|
161
|
+
}
|
|
162
|
+
else if (event.type === "done") {
|
|
163
|
+
now.answer = event.answer;
|
|
164
|
+
now.done = true;
|
|
165
|
+
if (event.answer.next)
|
|
166
|
+
now.next = event.answer.next;
|
|
167
|
+
else
|
|
168
|
+
delete now.next;
|
|
169
|
+
// The batch's groups are the whole of this call; what came before from a cursor stays.
|
|
170
|
+
for (const group of event.answer.groups)
|
|
171
|
+
if (!now.groups.some((one) => one.app.address === group.app.address))
|
|
172
|
+
now.groups.push(group);
|
|
173
|
+
}
|
|
174
|
+
update();
|
|
175
|
+
}
|
|
176
|
+
if (search === now && !now.done) {
|
|
177
|
+
now.done = true;
|
|
178
|
+
update();
|
|
179
|
+
}
|
|
180
|
+
})();
|
|
181
|
+
}
|
|
182
|
+
/* ── choosing ─────────────────────────────────────────────────────── */
|
|
183
|
+
function choose(next, how = {}) {
|
|
184
|
+
chosen = next;
|
|
185
|
+
if (next.app)
|
|
186
|
+
askCloud(next.app);
|
|
187
|
+
update(how.focus === "detail" ? "detail" : undefined);
|
|
188
|
+
if (how.move !== false)
|
|
189
|
+
space?.frame(chosen);
|
|
190
|
+
}
|
|
191
|
+
/** One step back along the breadcrumb: a record to its app, an app to its space, a space to everything. */
|
|
192
|
+
function back() {
|
|
193
|
+
if (chosen.record)
|
|
194
|
+
choose({ space: chosen.space, app: chosen.app });
|
|
195
|
+
else if (chosen.app)
|
|
196
|
+
choose({ space: chosen.space });
|
|
197
|
+
else if (chosen.space)
|
|
198
|
+
choose({});
|
|
199
|
+
else
|
|
200
|
+
return false;
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
function clearSearch() {
|
|
204
|
+
input.value = "";
|
|
205
|
+
find("");
|
|
206
|
+
}
|
|
207
|
+
/* ── drawing the page ─────────────────────────────────────────────── */
|
|
208
|
+
let focusAfter;
|
|
209
|
+
function update(focus) {
|
|
210
|
+
if (focus === "detail")
|
|
211
|
+
focusAfter = "detail-heading";
|
|
212
|
+
render();
|
|
213
|
+
space?.changed();
|
|
214
|
+
}
|
|
215
|
+
/** Renders the page from the state, keeping the keyboard where it was: on the same control, or where it was sent. */
|
|
216
|
+
function render() {
|
|
217
|
+
if (destroyed)
|
|
218
|
+
return;
|
|
219
|
+
const active = document.activeElement;
|
|
220
|
+
const key = active && shell.contains(active) ? active.dataset["key"] : undefined;
|
|
221
|
+
shell.classList.toggle("searching", search !== null);
|
|
222
|
+
shell.classList.toggle("chosen", chosen.app !== undefined || chosen.space !== undefined);
|
|
223
|
+
shell.dataset["graverse"] = description ? "ready" : refused ? "refused" : "loading";
|
|
224
|
+
renderCrumbs();
|
|
225
|
+
renderPill();
|
|
226
|
+
renderList();
|
|
227
|
+
renderDetail();
|
|
228
|
+
const want = focusAfter;
|
|
229
|
+
focusAfter = undefined;
|
|
230
|
+
const find = (name) => (name ? shell.querySelector(`[data-key="${CSS.escape(name)}"]`) : null);
|
|
231
|
+
if (want) {
|
|
232
|
+
const target = find(want);
|
|
233
|
+
if (target)
|
|
234
|
+
target.focus();
|
|
235
|
+
else if (active && !active.isConnected)
|
|
236
|
+
input.focus();
|
|
237
|
+
}
|
|
238
|
+
else if (active && !active.isConnected)
|
|
239
|
+
(find(key) ?? input).focus();
|
|
240
|
+
}
|
|
241
|
+
function renderCrumbs() {
|
|
242
|
+
const parts = [{ label: "Everything", to: {} }];
|
|
243
|
+
const app = appOf(chosen.app);
|
|
244
|
+
if (chosen.space)
|
|
245
|
+
parts.push({ label: chosen.space, to: { space: chosen.space } });
|
|
246
|
+
if (app)
|
|
247
|
+
parts.push({ label: app.app.name, to: { space: app.app.space, app: app.app.address } });
|
|
248
|
+
if (chosen.record)
|
|
249
|
+
parts.push({ label: chosen.record.label, to: null });
|
|
250
|
+
crumbs.innerHTML = "";
|
|
251
|
+
const ol = el("ol");
|
|
252
|
+
parts.forEach((part, i) => {
|
|
253
|
+
const li = el("li");
|
|
254
|
+
const last = i === parts.length - 1;
|
|
255
|
+
const button = el("button", { type: "button", "data-key": `crumb:${i}`, ...(last ? { "aria-current": "location" } : {}) });
|
|
256
|
+
button.textContent = part.label;
|
|
257
|
+
if (!last && part.to)
|
|
258
|
+
button.addEventListener("click", () => choose(part.to, { focus: "detail" }));
|
|
259
|
+
li.append(button);
|
|
260
|
+
ol.append(li);
|
|
261
|
+
});
|
|
262
|
+
crumbs.append(ol);
|
|
263
|
+
}
|
|
264
|
+
function renderPill() {
|
|
265
|
+
pill.hidden = search === null;
|
|
266
|
+
if (!search) {
|
|
267
|
+
pill.innerHTML = "";
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
pill.innerHTML = `<span>Showing what matches <b>${esc(search.query)}</b></span>`;
|
|
271
|
+
const clear = el("button", { type: "button", "data-key": "pill-clear" });
|
|
272
|
+
clear.textContent = "Clear";
|
|
273
|
+
clear.addEventListener("click", () => {
|
|
274
|
+
focusAfter = "find";
|
|
275
|
+
clearSearch();
|
|
276
|
+
});
|
|
277
|
+
pill.append(clear);
|
|
278
|
+
}
|
|
279
|
+
const row = (key, html, onPress, extra = "") => {
|
|
280
|
+
const button = el("button", { type: "button", class: `gv-row ${extra}`.trim(), "data-key": key }, html);
|
|
281
|
+
button.addEventListener("click", onPress);
|
|
282
|
+
return button;
|
|
283
|
+
};
|
|
284
|
+
const heading = (text) => el("h3", {}, esc(text));
|
|
285
|
+
function renderList() {
|
|
286
|
+
list.innerHTML = "";
|
|
287
|
+
if (refused) {
|
|
288
|
+
list.append(el("p", { class: "gv-said" }, esc(refused)));
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (!description) {
|
|
292
|
+
list.append(el("p", { class: "gv-said" }, "Asking the hub for every app…"));
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (search)
|
|
296
|
+
return renderFound(search);
|
|
297
|
+
if (description.apps.length === 0) {
|
|
298
|
+
list.append(el("p", { class: "gv-said" }, "No apps are registered yet. Run <code>graview hub add <folder></code>, or choose Register with local hub in an app's menu."));
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
// Where to start, once: what the universe says asks for attention.
|
|
302
|
+
if (!chosen.space && description.starts.length > 0) {
|
|
303
|
+
list.append(heading("Worth a look"));
|
|
304
|
+
const ul = el("ul");
|
|
305
|
+
description.starts.slice(0, 5).forEach((start, i) => {
|
|
306
|
+
const li = el("li");
|
|
307
|
+
const button = el("button", { type: "button", class: "gv-note", "data-key": `start:${i}` }, esc(start.said));
|
|
308
|
+
const first = appOf(start.apps[0]);
|
|
309
|
+
button.addEventListener("click", () => first && choose({ space: first.app.space, app: first.app.address }, { focus: "detail" }));
|
|
310
|
+
li.append(button);
|
|
311
|
+
ul.append(li);
|
|
312
|
+
});
|
|
313
|
+
list.append(ul);
|
|
314
|
+
}
|
|
315
|
+
list.append(heading("Spaces, most recent first"));
|
|
316
|
+
const ul = el("ul");
|
|
317
|
+
const spaces = [...new Set(description.apps.map((one) => one.app.space))];
|
|
318
|
+
const latest = (space) => description.apps.filter((one) => one.app.space === space).reduce((most, one) => ((changedOf(one) ?? "") > most ? (changedOf(one) ?? "") : most), "");
|
|
319
|
+
spaces.sort((a, b) => latest(b).localeCompare(latest(a)) || a.localeCompare(b));
|
|
320
|
+
for (const name of spaces) {
|
|
321
|
+
const apps = description.apps.filter((one) => one.app.space === name).sort((a, b) => (changedOf(b) ?? "").localeCompare(changedOf(a) ?? "") || a.app.name.localeCompare(b.app.name));
|
|
322
|
+
const li = el("li");
|
|
323
|
+
const when = latest(name);
|
|
324
|
+
li.append(row(`space:${name}`, `<span class="t">${esc(name)}</span><span class="n">${when ? esc(agoWords(when, today())) : ""}</span>`, () => choose({ space: name }, { focus: "detail" }), `space${chosen.space === name && !chosen.app ? " on" : ""}`));
|
|
325
|
+
const inner = el("ul");
|
|
326
|
+
for (const app of apps) {
|
|
327
|
+
const item = el("li");
|
|
328
|
+
const sub = readable(app) ? (app.facts ? recordsIn(app).toLocaleString("en-US") : "") : "cannot be read";
|
|
329
|
+
item.append(row(`app:${app.app.address}`, `<span class="t">${esc(app.app.name)}</span><span class="n">${esc(sub)}</span>`, () => choose({ space: app.app.space, app: app.app.address }, { focus: "detail" }), `app${chosen.app === app.app.address ? " on" : ""}${readable(app) ? "" : " dark"}`));
|
|
330
|
+
inner.append(item);
|
|
331
|
+
}
|
|
332
|
+
li.append(inner);
|
|
333
|
+
ul.append(li);
|
|
334
|
+
}
|
|
335
|
+
list.append(ul);
|
|
336
|
+
}
|
|
337
|
+
function renderFound(now) {
|
|
338
|
+
const total = now.groups.reduce((sum, group) => sum + group.total, 0);
|
|
339
|
+
const apps = now.groups.filter((group) => group.total > 0).sort((a, b) => b.total - a.total || a.app.name.localeCompare(b.app.name));
|
|
340
|
+
list.append(el("p", { class: "gv-count", "data-testid": "found-count" }, `<b>${total.toLocaleString("en-US")}</b> ${total === 1 ? "match" : "matches"}${total ? ` in ${counted(apps.length, "app")}` : ""}${now.done ? "" : " so far"}`));
|
|
341
|
+
// Each term, to take away; and every term at once.
|
|
342
|
+
const chips = el("div", { class: "gv-chips" });
|
|
343
|
+
const tokens = termsOf(now.query);
|
|
344
|
+
tokens.forEach((token, i) => {
|
|
345
|
+
const chip = el("button", { type: "button", class: "gv-chip", "data-key": `chip:${i}`, "aria-label": `Take away ${token}` }, `${esc(token)} <span aria-hidden="true">×</span>`);
|
|
346
|
+
chip.addEventListener("click", () => {
|
|
347
|
+
input.value = withoutTerm(now.query, i);
|
|
348
|
+
focusAfter = "find";
|
|
349
|
+
find(input.value);
|
|
350
|
+
});
|
|
351
|
+
chips.append(chip);
|
|
352
|
+
});
|
|
353
|
+
// One term is the pill's to clear; several are each taken away here.
|
|
354
|
+
if (tokens.length > 1)
|
|
355
|
+
list.append(chips);
|
|
356
|
+
if (now.callRefused) {
|
|
357
|
+
list.append(el("p", { class: "gv-said" }, esc(now.callRefused)));
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (now.done && total === 0 && now.slow.length === 0) {
|
|
361
|
+
list.append(el("p", { class: "gv-said" }, `Nothing matches. Find reads every field of every app you can see. You can also write <code>kind:person</code>, <code>app:pricing</code>, <code>space:neumo</code> or a field, such as <code>status=open</code> or <code>price>10</code>.`));
|
|
362
|
+
}
|
|
363
|
+
for (const group of apps) {
|
|
364
|
+
const app = appOf(group.app.address);
|
|
365
|
+
const header = el("button", { type: "button", class: "gv-group", "data-key": `group:${group.app.address}` }, `<span>${esc(group.app.name)}</span><span class="n">${group.total.toLocaleString("en-US")}</span>`);
|
|
366
|
+
header.addEventListener("click", () => choose({ space: group.app.space, app: group.app.address }, { focus: "detail" }));
|
|
367
|
+
list.append(header);
|
|
368
|
+
const ul = el("ul");
|
|
369
|
+
for (const hit of group.hits)
|
|
370
|
+
ul.append(hitItem(hit, app));
|
|
371
|
+
list.append(ul);
|
|
372
|
+
if (group.total > group.hits.length)
|
|
373
|
+
list.append(el("p", { class: "gv-said" }, `${(group.total - group.hits.length).toLocaleString("en-US")} more in ${esc(group.app.name)}: add a word or a field to narrow it.`));
|
|
374
|
+
if (group.more)
|
|
375
|
+
list.append(el("p", { class: "gv-said" }, esc(group.more)));
|
|
376
|
+
}
|
|
377
|
+
if (now.slow.length > 0 || now.refused.length > 0) {
|
|
378
|
+
list.append(heading("Not answered"));
|
|
379
|
+
const ul = el("ul");
|
|
380
|
+
for (const one of now.slow)
|
|
381
|
+
ul.append(el("li", { class: "gv-said" }, `${esc(one.name)} was slow to answer.`));
|
|
382
|
+
for (const one of now.refused)
|
|
383
|
+
ul.append(el("li", { class: "gv-said" }, `${esc(one.name)}: ${esc(one.said)}`));
|
|
384
|
+
list.append(ul);
|
|
385
|
+
}
|
|
386
|
+
if (now.done && now.next) {
|
|
387
|
+
const again = el("button", { type: "button", class: "gv-ask", "data-key": "ask-again" }, "Ask again");
|
|
388
|
+
again.addEventListener("click", () => find(now.query, now.next));
|
|
389
|
+
list.append(again);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function hitItem(hit, app) {
|
|
393
|
+
const li = el("li");
|
|
394
|
+
const noun = nounOf(app?.shape, hit.kind);
|
|
395
|
+
const why = hit.why
|
|
396
|
+
.filter((one) => one.field !== "label" && one.fragment)
|
|
397
|
+
.slice(0, 3)
|
|
398
|
+
.map((one) => `<span class="gv-why"><i>${esc(one.reading)}</i>${highlight(one.fragment)}</span>`)
|
|
399
|
+
.join("");
|
|
400
|
+
const link = el("a", { class: "gv-hit", href: hit.url, "data-key": `hit:${hit.url}` }, `<span class="l1"><span class="l">${highlight(hit.label)}</span><span class="n">${esc(noun)}</span></span>${why}`);
|
|
401
|
+
li.append(link);
|
|
402
|
+
return li;
|
|
403
|
+
}
|
|
404
|
+
function renderDetail() {
|
|
405
|
+
const app = appOf(chosen.app);
|
|
406
|
+
detail.hidden = !chosen.space && !app;
|
|
407
|
+
if (detail.hidden) {
|
|
408
|
+
detail.innerHTML = "";
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const h2 = (text) => `<h2 tabindex="-1" data-key="detail-heading">${esc(text)}</h2>`;
|
|
412
|
+
if (chosen.record && app) {
|
|
413
|
+
const cloud = clouds.get(app.app.address);
|
|
414
|
+
const record = chosen.record;
|
|
415
|
+
detail.innerHTML = `<div class="gv-over">${esc(nounOf(app.shape, record.kind))} in ${esc(app.app.name)}</div>${h2(record.label)}${record.at ? `<p>Changed ${esc(agoWords(record.at, today()))}</p>` : ""}`;
|
|
416
|
+
const open = el("a", { class: "gv-open", href: record.url, "data-key": "open" });
|
|
417
|
+
open.textContent = `Open ${record.label}`;
|
|
418
|
+
detail.append(open);
|
|
419
|
+
if (cloud && typeof cloud === "object" && "points" in cloud) {
|
|
420
|
+
const at = cloud.points.findIndex((point) => point.id === record.id);
|
|
421
|
+
const linked = at === -1 ? [] : [...new Set([...cloud.points[at].to, ...cloud.points.flatMap((point, i) => (point.to.includes(at) ? [i] : []))])];
|
|
422
|
+
if (linked.length > 0) {
|
|
423
|
+
detail.append(heading(counted(linked.length, "link")));
|
|
424
|
+
const ul = el("ul");
|
|
425
|
+
for (const i of linked.slice(0, 30)) {
|
|
426
|
+
const point = cloud.points[i];
|
|
427
|
+
const li = el("li");
|
|
428
|
+
li.append(row(`linked:${point.id}`, `<span class="t">${esc(point.label)}</span><span class="n">${esc(nounOf(app.shape, cloud.kinds[point.k]?.kind ?? ""))}</span>`, () => choose({ space: app.app.space, app: app.app.address, record: recordOf(app, cloud, point) }, { focus: "detail" })));
|
|
429
|
+
ul.append(li);
|
|
430
|
+
}
|
|
431
|
+
detail.append(ul);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (app) {
|
|
437
|
+
const host = app.host;
|
|
438
|
+
const facts = [];
|
|
439
|
+
if (app.facts)
|
|
440
|
+
facts.push(`<dt>Records</dt><dd>${recordsIn(app).toLocaleString("en-US")}</dd>`);
|
|
441
|
+
const changed = changedOf(app);
|
|
442
|
+
if (changed)
|
|
443
|
+
facts.push(`<dt>Changed</dt><dd>${esc(agoWords(changed, today()))}</dd>`);
|
|
444
|
+
if (host.kind === "local") {
|
|
445
|
+
const current = host.checkouts.find((one) => one.current);
|
|
446
|
+
if (current?.branch)
|
|
447
|
+
facts.push(`<dt>Branch</dt><dd>${esc(current.branch)}</dd>`);
|
|
448
|
+
if (host.checkouts.length > 1)
|
|
449
|
+
facts.push(`<dt>Checkouts</dt><dd>${host.checkouts.length}</dd>`);
|
|
450
|
+
if (host.git && host.git.uncommitted > 0)
|
|
451
|
+
facts.push(`<dt>Git</dt><dd>${esc(counted(host.git.uncommitted, "uncommitted change"))}</dd>`);
|
|
452
|
+
}
|
|
453
|
+
if (app.facts?.store === "seed-only" && !app.said)
|
|
454
|
+
facts.push(`<dt>Store</dt><dd>Only a seed</dd>`);
|
|
455
|
+
detail.innerHTML = `<div class="gv-over">App · ${esc(app.app.address)}</div>${h2(app.app.name)}${app.shape?.description ? `<p>${esc(app.shape.description)}</p>` : ""}${app.said || app.refused ? `<p>${esc(sentence(app.refused ?? app.said ?? ""))}</p>` : ""}${facts.length ? `<dl>${facts.join("")}</dl>` : ""}`;
|
|
456
|
+
if (readable(app) && !app.refused) {
|
|
457
|
+
const open = el("a", { class: "gv-open", href: app.app.url, "data-key": "open" });
|
|
458
|
+
open.textContent = `Open ${app.app.name}`;
|
|
459
|
+
detail.append(open);
|
|
460
|
+
}
|
|
461
|
+
const counts = Object.entries(app.facts?.counts ?? {}).filter(([, n]) => n > 0);
|
|
462
|
+
if (counts.length > 0) {
|
|
463
|
+
detail.append(heading("Kinds"));
|
|
464
|
+
const ul = el("ul");
|
|
465
|
+
for (const [kind, n] of counts.sort((a, b) => b[1] - a[1]))
|
|
466
|
+
ul.append(el("li", { class: "gv-row" }, `<span class="t">${esc(pluralOf(app.shape, kind))}</span><span class="n">${n.toLocaleString("en-US")}</span>`));
|
|
467
|
+
detail.append(ul);
|
|
468
|
+
}
|
|
469
|
+
const cloud = clouds.get(app.app.address);
|
|
470
|
+
if (cloud === "asking")
|
|
471
|
+
detail.append(el("p", {}, "Reading its records…"));
|
|
472
|
+
else if (cloud && "refused" in cloud)
|
|
473
|
+
detail.append(el("p", {}, esc(cloud.refused)));
|
|
474
|
+
else if (cloud && cloud.points.length > 0) {
|
|
475
|
+
detail.append(heading("Changed lately"));
|
|
476
|
+
const ul = el("ul");
|
|
477
|
+
for (const point of cloud.points.slice(0, 12)) {
|
|
478
|
+
const li = el("li");
|
|
479
|
+
const link = el("a", { class: "gv-row", href: recordUrl(app, cloud, point), "data-key": `record:${point.id}` }, `<span class="t">${esc(point.label)}</span><span class="n">${esc(nounOf(app.shape, cloud.kinds[point.k]?.kind ?? ""))}</span>`);
|
|
480
|
+
li.append(link);
|
|
481
|
+
ul.append(li);
|
|
482
|
+
}
|
|
483
|
+
detail.append(ul);
|
|
484
|
+
if (cloud.beyond > 0)
|
|
485
|
+
detail.append(el("p", {}, `${cloud.beyond.toLocaleString("en-US")} more not drawn.`));
|
|
486
|
+
}
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
// A space: its apps.
|
|
490
|
+
const apps = (description?.apps ?? []).filter((one) => one.app.space === chosen.space);
|
|
491
|
+
const total = apps.reduce((sum, one) => sum + recordsIn(one), 0);
|
|
492
|
+
detail.innerHTML = `<div class="gv-over">Space</div>${h2(chosen.space)}<p>${esc(counted(apps.length, "app"))}, ${esc(counted(total, "record"))} in all.</p>`;
|
|
493
|
+
const ul = el("ul");
|
|
494
|
+
for (const one of apps) {
|
|
495
|
+
const li = el("li");
|
|
496
|
+
li.append(row(`detail-app:${one.app.address}`, `<span class="t">${esc(one.app.name)}</span><span class="n">${readable(one) ? recordsIn(one).toLocaleString("en-US") : "cannot be read"}</span>`, () => choose({ space: one.app.space, app: one.app.address }, { focus: "detail" })));
|
|
497
|
+
ul.append(li);
|
|
498
|
+
}
|
|
499
|
+
detail.append(heading("Apps"), ul);
|
|
500
|
+
}
|
|
501
|
+
const recordOf = (app, cloud, point) => ({
|
|
502
|
+
id: point.id,
|
|
503
|
+
label: point.label,
|
|
504
|
+
kind: cloud.kinds[point.k]?.kind ?? "",
|
|
505
|
+
url: recordUrl(app, cloud, point),
|
|
506
|
+
...(point.at ? { at: point.at } : {}),
|
|
507
|
+
});
|
|
508
|
+
/* ── the keyboard and the box ─────────────────────────────────────── */
|
|
509
|
+
input.addEventListener("input", () => {
|
|
510
|
+
clearTimeout(typing);
|
|
511
|
+
typing = setTimeout(() => find(input.value), 160);
|
|
512
|
+
});
|
|
513
|
+
$(".gv-find").addEventListener("submit", (event) => {
|
|
514
|
+
event.preventDefault();
|
|
515
|
+
clearTimeout(typing);
|
|
516
|
+
find(input.value);
|
|
517
|
+
});
|
|
518
|
+
const onKey = (event) => {
|
|
519
|
+
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey)
|
|
520
|
+
return;
|
|
521
|
+
const typingHere = event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement;
|
|
522
|
+
if (event.key === "/" && !typingHere) {
|
|
523
|
+
event.preventDefault();
|
|
524
|
+
input.focus();
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
if (event.key !== "Escape")
|
|
528
|
+
return;
|
|
529
|
+
// Escape steps back along the breadcrumb; once nothing is chosen, it clears the search.
|
|
530
|
+
const was = chosen;
|
|
531
|
+
if (back()) {
|
|
532
|
+
event.preventDefault();
|
|
533
|
+
focusAfter = was.record ? "detail-heading" : was.app ? `app:${was.app}` : `space:${was.space}`;
|
|
534
|
+
if (search && was.app && !was.record)
|
|
535
|
+
focusAfter = `group:${was.app}`;
|
|
536
|
+
render();
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
if (search || input.value) {
|
|
540
|
+
event.preventDefault();
|
|
541
|
+
focusAfter = "find";
|
|
542
|
+
clearSearch();
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
document.addEventListener("keydown", onKey);
|
|
546
|
+
input.dataset["key"] = "find";
|
|
547
|
+
/* ── the space, when it can be drawn ──────────────────────────────── */
|
|
548
|
+
const host = {
|
|
549
|
+
view: () => ({ layout: layout, description: description, chosen, matches: matches(), hits: new Map((search?.groups ?? []).map((group) => [group.app.address, group.hits])), clouds }),
|
|
550
|
+
choose: (next) => choose(next, { focus: "keep" }),
|
|
551
|
+
open: (url) => go(url),
|
|
552
|
+
ask: (address) => askCloud(address),
|
|
553
|
+
reducedMotion: () => reduced?.matches === true,
|
|
554
|
+
inset: () => {
|
|
555
|
+
const width = window.innerWidth;
|
|
556
|
+
const height = window.innerHeight;
|
|
557
|
+
const box = (node) => (node.hidden || node.offsetParent === null ? null : node.getBoundingClientRect());
|
|
558
|
+
const top = (box($(".gv-top"))?.bottom ?? 0) + 8;
|
|
559
|
+
const index = box($(".gv-index"));
|
|
560
|
+
const chosenBox = box(detail);
|
|
561
|
+
// A phone's panels are sheets along the bottom; a desk's stand at the sides.
|
|
562
|
+
if (width <= 720)
|
|
563
|
+
return { top, right: 0, bottom: height - Math.min(index?.top ?? height, chosenBox?.top ?? height) + 8, left: 0 };
|
|
564
|
+
return { top, right: chosenBox ? width - chosenBox.left + 16 : 0, bottom: 40, left: index ? index.right + 16 : 0 };
|
|
565
|
+
},
|
|
566
|
+
recordOf: (address, point) => {
|
|
567
|
+
const app = appOf(address);
|
|
568
|
+
const cloud = clouds.get(address);
|
|
569
|
+
return app && cloud && typeof cloud === "object" && "points" in cloud ? recordOf(app, cloud, point) : null;
|
|
570
|
+
},
|
|
571
|
+
};
|
|
572
|
+
const ready = (async () => {
|
|
573
|
+
render();
|
|
574
|
+
await describe();
|
|
575
|
+
render();
|
|
576
|
+
if (destroyed || !description || options.space === false || !canDrawSpace())
|
|
577
|
+
return;
|
|
578
|
+
try {
|
|
579
|
+
const { mountSpace } = await import("./space.js");
|
|
580
|
+
if (destroyed)
|
|
581
|
+
return;
|
|
582
|
+
// The panels take their places beside the drawing before it measures what they cover.
|
|
583
|
+
shell.classList.remove("flat");
|
|
584
|
+
space = mountSpace(stage, host);
|
|
585
|
+
}
|
|
586
|
+
catch {
|
|
587
|
+
space = null;
|
|
588
|
+
}
|
|
589
|
+
if (!space)
|
|
590
|
+
shell.classList.add("flat");
|
|
591
|
+
if (space) {
|
|
592
|
+
stage.removeAttribute("aria-hidden");
|
|
593
|
+
hint.hidden = window.innerWidth <= 720;
|
|
594
|
+
shell.dataset["space"] = "drawn";
|
|
595
|
+
space.changed();
|
|
596
|
+
}
|
|
597
|
+
})();
|
|
598
|
+
return {
|
|
599
|
+
ready,
|
|
600
|
+
destroy() {
|
|
601
|
+
destroyed = true;
|
|
602
|
+
finding?.abort();
|
|
603
|
+
clearTimeout(typing);
|
|
604
|
+
document.removeEventListener("keydown", onKey);
|
|
605
|
+
space?.destroy();
|
|
606
|
+
shell.remove();
|
|
607
|
+
},
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
//# sourceMappingURL=index.js.map
|