@pritzlaff/nano-ui 0.4.0 → 0.5.1
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/explorer-details.d.ts +44 -0
- package/explorer-nodes.d.ts +9 -0
- package/explorer.d.ts +22 -6
- package/filter/filter.d.ts +40 -0
- package/filter/model.d.ts +25 -0
- package/index.d.ts +17 -2
- package/index.js +1785 -187
- package/index.js.map +39 -15
- package/interfaces.d.ts +127 -1
- package/layout.d.ts +3 -11
- package/observe/bar.d.ts +46 -0
- package/observe/clock-driver.d.ts +16 -0
- package/observe/entry.d.ts +66 -0
- package/observe/fold.d.ts +14 -0
- package/observe/in-flight.d.ts +10 -0
- package/observe/memory-store.d.ts +5 -0
- package/observe/record.d.ts +15 -0
- package/observe/replay.d.ts +56 -0
- package/observe/restart-order.d.ts +3 -0
- package/observe/ring-view.d.ts +86 -0
- package/observe/ring.d.ts +38 -0
- package/observe/shadow.d.ts +18 -0
- package/observe/time-machine.d.ts +55 -0
- package/package.json +3 -3
- package/pods/clock.d.ts +3 -0
- package/pods/debounce.d.ts +4 -1
- package/pods/input.d.ts +3 -0
- package/pods/random.d.ts +5 -0
- package/pods/sim-clock.d.ts +3 -0
- package/views/debounce-model.d.ts +72 -0
- package/views/debounce-parts.d.ts +12 -0
- package/views/debounce.d.ts +36 -0
- package/views/faces.d.ts +0 -13
- package/views/input.d.ts +9 -0
- package/views/view.d.ts +3 -2
package/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// packages/ui/src/provider.ts
|
|
2
|
-
import { Coord as
|
|
2
|
+
import { Coord as Coord9 } from "@pritzlaff/nano-core";
|
|
3
3
|
|
|
4
|
-
// packages/ui/src/pods/
|
|
5
|
-
import {
|
|
6
|
-
import { Coord as Coord2, Schema as Schema2, Implementation, provide, success } from "@pritzlaff/nano-core";
|
|
4
|
+
// packages/ui/src/pods/clock.ts
|
|
5
|
+
import { Coord as Coord2, Implementation, provide, success } from "@pritzlaff/nano-core";
|
|
7
6
|
|
|
8
7
|
// packages/ui/src/interfaces.ts
|
|
9
8
|
import { Type } from "typebox";
|
|
@@ -14,9 +13,19 @@ var Nothing = Schema.define(Type.Null(), "Nothing");
|
|
|
14
13
|
var Entries = Schema.define(Type.Array(Type.Unknown()), "Entries");
|
|
15
14
|
var Text = Schema.define(Type.String(), "Text");
|
|
16
15
|
var Approval = Schema.define(Type.Object({ title: Type.String(), detail: Type.Optional(Type.String()) }), "Approval");
|
|
16
|
+
var Num = Schema.define(Type.Number(), "Num");
|
|
17
|
+
var TimerId = Schema.define(Type.Integer({ minimum: 1 }), "TimerId");
|
|
18
|
+
var After = Schema.define(Type.Object({ ms: Type.Integer({ minimum: 0, maximum: 2147483647 }), tag: Type.Optional(Type.String()) }), "After");
|
|
19
|
+
var Fired = Schema.define(Type.Object({ id: Type.Integer({ minimum: 1 }), tag: Type.Optional(Type.String()), at: Type.Number() }), "Fired");
|
|
17
20
|
var Approved = Schema.define(Type.Boolean(), "Approved");
|
|
18
|
-
var
|
|
19
|
-
|
|
21
|
+
var Addition = Schema.define(Type.Object({
|
|
22
|
+
pods: Type.Record(Type.String(), Type.Unknown()),
|
|
23
|
+
runtimes: Type.Record(Type.String(), Type.Unknown()),
|
|
24
|
+
onConflict: Type.Optional(Type.Union([Type.Literal("error"), Type.Literal("overwrite")]))
|
|
25
|
+
}), "Addition");
|
|
26
|
+
var Removal = Schema.define(Type.Object({ runtimes: Type.Array(Type.String()) }), "Removal");
|
|
27
|
+
var Input = ns.interface("Input", { submit: Op.action(Any, Any), change: Op.action(Any, Any) });
|
|
28
|
+
var Debounce = ns.interface("Debounce", { push: Op.action(Any, Nothing), flushed: Op.event(Any), batch: Op.event(Entries) });
|
|
20
29
|
var MapIface = ns.interface("Map", { map: Op.action(Any, Any) });
|
|
21
30
|
var Log = ns.interface("Log", {
|
|
22
31
|
log: Op.action(Any, Nothing),
|
|
@@ -28,94 +37,258 @@ var HostUI = ns.interface("HostUI", {
|
|
|
28
37
|
approve: Op.action(Approval, Approved),
|
|
29
38
|
setAppBar: Op.action(Text, Nothing)
|
|
30
39
|
});
|
|
40
|
+
var HostDeploy = ns.interface("HostDeploy", { deploy: Op.action(Addition, Nothing), undeploy: Op.action(Removal, Nothing) });
|
|
41
|
+
var Clock = ns.interface("Clock", {
|
|
42
|
+
now: Op.action(Nothing, Num),
|
|
43
|
+
after: Op.action(After, TimerId),
|
|
44
|
+
cancel: Op.action(TimerId, Nothing),
|
|
45
|
+
fired: Op.event(Fired)
|
|
46
|
+
});
|
|
47
|
+
var ClockControl = ns.interface("ClockControl", { advance: Op.action(Num, Nothing), set: Op.action(Num, Nothing) });
|
|
48
|
+
var Random = ns.interface("Random", { next: Op.action(Nothing, Num) });
|
|
31
49
|
|
|
32
|
-
// packages/ui/src/pods/
|
|
50
|
+
// packages/ui/src/pods/clock.ts
|
|
33
51
|
var ns2 = Coord2.namespace("nano.ui");
|
|
34
|
-
var
|
|
35
|
-
provides: [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let timer;
|
|
40
|
-
let closed = false;
|
|
52
|
+
var clock = Implementation.define(ns2.implementationId("clock"), {
|
|
53
|
+
provides: [Clock],
|
|
54
|
+
make: (ctx) => {
|
|
55
|
+
const timers = new Map;
|
|
56
|
+
let next = 0, closed = false;
|
|
41
57
|
ctx.addOnCloseListener(() => {
|
|
42
58
|
closed = true;
|
|
43
|
-
clearTimeout
|
|
59
|
+
timers.forEach(clearTimeout);
|
|
60
|
+
timers.clear();
|
|
44
61
|
});
|
|
45
|
-
return [provide(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
return [provide(Clock, {
|
|
63
|
+
now: async () => success(Date.now()),
|
|
64
|
+
after: async ({ ms, tag }) => {
|
|
65
|
+
const id = ++next;
|
|
66
|
+
timers.set(id, setTimeout(() => {
|
|
67
|
+
timers.delete(id);
|
|
68
|
+
if (!closed)
|
|
69
|
+
ctx.publish(Clock.ops.fired, { id, ...tag === undefined ? {} : { tag }, at: Date.now() });
|
|
70
|
+
}, ms));
|
|
71
|
+
return success(id);
|
|
72
|
+
},
|
|
73
|
+
cancel: async (id) => {
|
|
74
|
+
clearTimeout(timers.get(id));
|
|
75
|
+
timers.delete(id);
|
|
53
76
|
return success(null);
|
|
54
77
|
}
|
|
55
78
|
})];
|
|
56
79
|
}
|
|
57
80
|
});
|
|
58
81
|
|
|
59
|
-
// packages/ui/src/pods/
|
|
60
|
-
import {
|
|
82
|
+
// packages/ui/src/pods/sim-clock.ts
|
|
83
|
+
import { Type as Type2 } from "typebox";
|
|
84
|
+
import { Coord as Coord3, Schema as Schema2, Implementation as Implementation2, provide as provide2, success as success2, failure } from "@pritzlaff/nano-core";
|
|
61
85
|
var ns3 = Coord3.namespace("nano.ui");
|
|
62
|
-
var
|
|
63
|
-
provides: [
|
|
64
|
-
|
|
86
|
+
var simClock = Implementation2.define(ns3.implementationId("sim-clock"), {
|
|
87
|
+
provides: [Clock, ClockControl],
|
|
88
|
+
config: Schema2.define(Type2.Union([Type2.Object({ start: Type2.Optional(Type2.Number()) }), Type2.Undefined()]), "SimClockConfig"),
|
|
89
|
+
make: (ctx, config) => {
|
|
90
|
+
let time = config?.start ?? 0, next = 0;
|
|
91
|
+
let queue = Promise.resolve();
|
|
92
|
+
const run = (f) => queue = queue.then(f, f);
|
|
93
|
+
let timers = [];
|
|
94
|
+
const moveTo = async (t) => {
|
|
95
|
+
for (;; ) {
|
|
96
|
+
const due = timers.filter((x) => x.due <= t).sort((a, b) => a.due - b.due || a.id - b.id)[0];
|
|
97
|
+
if (!due)
|
|
98
|
+
break;
|
|
99
|
+
timers = timers.filter((x) => x !== due);
|
|
100
|
+
time = due.due;
|
|
101
|
+
const { id, tag } = due;
|
|
102
|
+
await ctx.publish(Clock.ops.fired, { id, ...tag === undefined ? {} : { tag }, at: time });
|
|
103
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
104
|
+
}
|
|
105
|
+
time = t;
|
|
106
|
+
return success2(null);
|
|
107
|
+
};
|
|
108
|
+
const set = (t) => run(async () => t < time ? failure("invalid-input", `the clock is at ${time}; it cannot go back to ${t}`) : await moveTo(t));
|
|
109
|
+
return [
|
|
110
|
+
provide2(Clock, {
|
|
111
|
+
now: async () => success2(time),
|
|
112
|
+
after: async ({ ms, tag }) => {
|
|
113
|
+
const id = ++next;
|
|
114
|
+
timers.push({ id, due: time + ms, ...tag === undefined ? {} : { tag } });
|
|
115
|
+
return success2(id);
|
|
116
|
+
},
|
|
117
|
+
cancel: async (id) => {
|
|
118
|
+
timers = timers.filter((x) => x.id !== id);
|
|
119
|
+
return success2(null);
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
provide2(ClockControl, {
|
|
123
|
+
advance: (ms) => run(async () => ms < 0 ? failure("invalid-input", `cannot advance by ${ms}`) : moveTo(time + ms)),
|
|
124
|
+
set
|
|
125
|
+
})
|
|
126
|
+
];
|
|
127
|
+
}
|
|
65
128
|
});
|
|
66
129
|
|
|
67
|
-
// packages/ui/src/pods/
|
|
130
|
+
// packages/ui/src/pods/random.ts
|
|
68
131
|
import { Type as Type3 } from "typebox";
|
|
69
132
|
import { Coord as Coord4, Schema as Schema3, Implementation as Implementation3, provide as provide3, success as success3 } from "@pritzlaff/nano-core";
|
|
70
133
|
var ns4 = Coord4.namespace("nano.ui");
|
|
71
|
-
var
|
|
134
|
+
var random = Implementation3.define(ns4.implementationId("random"), {
|
|
135
|
+
provides: [Random],
|
|
136
|
+
make: () => [provide3(Random, { next: async () => success3(Math.random()) })]
|
|
137
|
+
});
|
|
138
|
+
var seededRandom = Implementation3.define(ns4.implementationId("seeded-random"), {
|
|
139
|
+
provides: [Random],
|
|
140
|
+
config: Schema3.define(Type3.Union([Type3.Object({ seed: Type3.Optional(Type3.Integer()) }), Type3.Undefined()]), "SeededRandomConfig"),
|
|
141
|
+
make: (ctx, config) => {
|
|
142
|
+
let s = (config?.seed ?? 1) >>> 0;
|
|
143
|
+
return [provide3(Random, { next: async () => {
|
|
144
|
+
s = s + 1831565813 >>> 0;
|
|
145
|
+
let t = Math.imul(s ^ s >>> 15, s | 1);
|
|
146
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
147
|
+
return success3(((t ^ t >>> 14) >>> 0) / 4294967296);
|
|
148
|
+
} })];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// packages/ui/src/pods/debounce.ts
|
|
153
|
+
import { Type as Type4 } from "typebox";
|
|
154
|
+
import { Coord as Coord5, Schema as Schema4, Implementation as Implementation4, provide as provide4, success as success4 } from "@pritzlaff/nano-core";
|
|
155
|
+
var ns5 = Coord5.namespace("nano.ui");
|
|
156
|
+
var Ms = Type4.Integer({ minimum: 0, maximum: 60000 });
|
|
157
|
+
var debounce = Implementation4.define(ns5.implementationId("debounce"), {
|
|
158
|
+
provides: [Debounce],
|
|
159
|
+
config: Schema4.define(Type4.Union([Type4.Object({ quietMs: Ms, maxWaitMs: Type4.Optional(Ms) }), Type4.Undefined()]), "DebounceConfig"),
|
|
160
|
+
dependencies: { clock: Clock },
|
|
161
|
+
make: (ctx, config) => {
|
|
162
|
+
const quietMs = config?.quietMs ?? 300, maxWaitMs = config?.maxWaitMs;
|
|
163
|
+
let queue = [], closed = false;
|
|
164
|
+
const slots = {};
|
|
165
|
+
let pushes = Promise.resolve();
|
|
166
|
+
const wired = ctx.one(Clock);
|
|
167
|
+
const clear = (tag) => {
|
|
168
|
+
const s = slots[tag];
|
|
169
|
+
delete slots[tag];
|
|
170
|
+
if (s === undefined)
|
|
171
|
+
return;
|
|
172
|
+
if (wired.ok)
|
|
173
|
+
wired.value.call.cancel(s);
|
|
174
|
+
else
|
|
175
|
+
clearTimeout(s);
|
|
176
|
+
};
|
|
177
|
+
const start = async (tag, ms) => {
|
|
178
|
+
if (!wired.ok) {
|
|
179
|
+
slots[tag] = setTimeout(flush, ms);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const r = await wired.value.call.after({ ms, tag });
|
|
183
|
+
if (!r.ok)
|
|
184
|
+
return;
|
|
185
|
+
if (closed)
|
|
186
|
+
wired.value.call.cancel(r.value);
|
|
187
|
+
else
|
|
188
|
+
slots[tag] = r.value;
|
|
189
|
+
};
|
|
190
|
+
const flush = () => {
|
|
191
|
+
clear("quiet");
|
|
192
|
+
clear("max");
|
|
193
|
+
const batch = queue;
|
|
194
|
+
queue = [];
|
|
195
|
+
if (closed || batch.length === 0)
|
|
196
|
+
return;
|
|
197
|
+
ctx.publish(Debounce.ops.flushed, batch.at(-1));
|
|
198
|
+
ctx.publish(Debounce.ops.batch, batch);
|
|
199
|
+
};
|
|
200
|
+
if (wired.ok)
|
|
201
|
+
wired.value.on(Clock.ops.fired, ({ output }) => {
|
|
202
|
+
if (output.tag && slots[output.tag] === output.id) {
|
|
203
|
+
delete slots[output.tag];
|
|
204
|
+
flush();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
ctx.addOnCloseListener(() => {
|
|
208
|
+
closed = true;
|
|
209
|
+
clear("quiet");
|
|
210
|
+
clear("max");
|
|
211
|
+
});
|
|
212
|
+
return [provide4(Debounce, {
|
|
213
|
+
push: (value) => {
|
|
214
|
+
const run = async () => {
|
|
215
|
+
if (closed)
|
|
216
|
+
return success4(null);
|
|
217
|
+
queue.push(value);
|
|
218
|
+
clear("quiet");
|
|
219
|
+
await start("quiet", quietMs);
|
|
220
|
+
if (maxWaitMs !== undefined && slots.max === undefined)
|
|
221
|
+
await start("max", maxWaitMs);
|
|
222
|
+
return success4(null);
|
|
223
|
+
};
|
|
224
|
+
return wired.ok ? pushes = pushes.then(run, run) : run();
|
|
225
|
+
}
|
|
226
|
+
})];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// packages/ui/src/pods/input.ts
|
|
231
|
+
import { Type as Type5 } from "typebox";
|
|
232
|
+
import { Coord as Coord6, Implementation as Implementation5, Schema as Schema5, provide as provide5, success as success5 } from "@pritzlaff/nano-core";
|
|
233
|
+
var ns6 = Coord6.namespace("nano.ui");
|
|
234
|
+
var KINDS = ["text", "textarea", "number", "boolean"];
|
|
235
|
+
var input = Implementation5.define(ns6.implementationId("input"), {
|
|
236
|
+
provides: [Input],
|
|
237
|
+
config: Schema5.define(Type5.Union([Type5.Object({ kind: Type5.Optional(Type5.Union(KINDS.map((k) => Type5.Literal(k)))) }), Type5.Undefined()]), "InputConfig"),
|
|
238
|
+
make: () => [provide5(Input, { submit: async (v) => success5(v), change: async (v) => success5(v) })]
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// packages/ui/src/pods/log.ts
|
|
242
|
+
import { Type as Type6 } from "typebox";
|
|
243
|
+
import { Coord as Coord7, Schema as Schema6, Implementation as Implementation6, provide as provide6, success as success6 } from "@pritzlaff/nano-core";
|
|
244
|
+
var ns7 = Coord7.namespace("nano.ui");
|
|
245
|
+
var log = Implementation6.define(ns7.implementationId("log"), {
|
|
72
246
|
provides: [Log],
|
|
73
|
-
config:
|
|
247
|
+
config: Schema6.define(Type6.Union([Type6.Object({ max: Type6.Optional(Type6.Integer({ minimum: 1, maximum: 1000 })) }), Type6.Undefined()]), "LogConfig"),
|
|
74
248
|
make: (_ctx, config) => {
|
|
75
249
|
const max = config?.max ?? 100;
|
|
76
250
|
let entries = [];
|
|
77
|
-
return [
|
|
251
|
+
return [provide6(Log, {
|
|
78
252
|
log: async (v) => {
|
|
79
253
|
entries = [...entries, v].slice(-max);
|
|
80
|
-
return
|
|
254
|
+
return success6(null);
|
|
81
255
|
},
|
|
82
|
-
entries: async () =>
|
|
256
|
+
entries: async () => success6([...entries]),
|
|
83
257
|
clear: async () => {
|
|
84
258
|
entries = [];
|
|
85
|
-
return
|
|
259
|
+
return success6(null);
|
|
86
260
|
}
|
|
87
261
|
})];
|
|
88
262
|
}
|
|
89
263
|
});
|
|
90
264
|
|
|
91
265
|
// packages/ui/src/pods/map.ts
|
|
92
|
-
import { Type as
|
|
93
|
-
import { Coord as
|
|
94
|
-
var
|
|
95
|
-
var map =
|
|
266
|
+
import { Type as Type7 } from "typebox";
|
|
267
|
+
import { Coord as Coord8, Schema as Schema7, Implementation as Implementation7, provide as provide7, success as success7 } from "@pritzlaff/nano-core";
|
|
268
|
+
var ns8 = Coord8.namespace("nano.ui");
|
|
269
|
+
var map = Implementation7.define(ns8.implementationId("map"), {
|
|
96
270
|
provides: [MapIface],
|
|
97
|
-
config:
|
|
271
|
+
config: Schema7.define(Type7.Object({ code: Type7.String() }, { default: { code: "return x" } }), "MapConfig"),
|
|
98
272
|
make: (_ctx, config) => {
|
|
99
273
|
const fn = new Function("x", config.code);
|
|
100
|
-
return [
|
|
274
|
+
return [provide7(MapIface, { map: async (x) => success7(fn(x)) })];
|
|
101
275
|
}
|
|
102
276
|
});
|
|
103
277
|
|
|
104
278
|
// packages/ui/src/provider.ts
|
|
105
|
-
var
|
|
106
|
-
var uiProvider =
|
|
279
|
+
var ns9 = Coord9.namespace("nano.ui");
|
|
280
|
+
var uiProvider = ns9.provider([input, debounce, map, log, clock, simClock, random, seededRandom]);
|
|
107
281
|
// packages/ui/src/views/faces.ts
|
|
108
|
-
import {
|
|
282
|
+
import { html as html2 } from "lit";
|
|
109
283
|
import { port } from "@pritzlaff/nano-core";
|
|
110
|
-
import { base as base2, t } from "@pritzlaff/nano-elements";
|
|
111
284
|
|
|
112
285
|
// packages/ui/src/views/view.ts
|
|
113
286
|
import { LitElement, html } from "lit";
|
|
114
287
|
import { base } from "@pritzlaff/nano-elements";
|
|
115
288
|
var defined = (tag) => tag && customElements.get(tag) ? tag : undefined;
|
|
116
|
-
function viewFor(pod, deployment, defaults) {
|
|
289
|
+
function viewFor(pod, deployment, defaults, overrides = {}) {
|
|
117
290
|
const impl = deployment.pods[pod]?.implementation;
|
|
118
|
-
return defined(
|
|
291
|
+
return defined(overrides[pod]) ?? defined(impl === undefined ? undefined : defaults[impl]) ?? "nano-pod-view";
|
|
119
292
|
}
|
|
120
293
|
|
|
121
294
|
class ViewElement extends LitElement {
|
|
@@ -181,49 +354,6 @@ class ViewElement extends LitElement {
|
|
|
181
354
|
var shown = (r) => r === undefined ? "—" : r.ok ? JSON.stringify(r.value) : `failed: ${r.fail?.reason}`;
|
|
182
355
|
|
|
183
356
|
// packages/ui/src/views/faces.ts
|
|
184
|
-
class NanoInput extends ViewElement {
|
|
185
|
-
async enter(e, tg) {
|
|
186
|
-
if (e.key !== "Enter")
|
|
187
|
-
return;
|
|
188
|
-
const box = e.target;
|
|
189
|
-
await this.pod(tg).submit(box.value);
|
|
190
|
-
}
|
|
191
|
-
face(tg) {
|
|
192
|
-
return html2`<input type="text" aria-label=${tg.pod} @keydown=${(e) => this.enter(e, tg)}>`;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
var PUSH = port(Debounce, Debounce.ops.push);
|
|
196
|
-
|
|
197
|
-
class NanoDebounce extends ViewElement {
|
|
198
|
-
static styles = [base2, css`.flash { color: ${t("accent")} }`];
|
|
199
|
-
pending = false;
|
|
200
|
-
flash = false;
|
|
201
|
-
timer;
|
|
202
|
-
hear(e, tg) {
|
|
203
|
-
if (e.type !== "sent")
|
|
204
|
-
return;
|
|
205
|
-
if (e.to === tg.pod && e.port === PUSH)
|
|
206
|
-
this.pending = true;
|
|
207
|
-
else if (e.from === tg.pod) {
|
|
208
|
-
this.pending = false;
|
|
209
|
-
this.flash = true;
|
|
210
|
-
clearTimeout(this.timer);
|
|
211
|
-
this.timer = setTimeout(() => {
|
|
212
|
-
this.flash = false;
|
|
213
|
-
this.requestUpdate();
|
|
214
|
-
}, 300);
|
|
215
|
-
} else
|
|
216
|
-
return;
|
|
217
|
-
this.requestUpdate();
|
|
218
|
-
}
|
|
219
|
-
disconnectedCallback() {
|
|
220
|
-
super.disconnectedCallback();
|
|
221
|
-
clearTimeout(this.timer);
|
|
222
|
-
}
|
|
223
|
-
face() {
|
|
224
|
-
return html2`<span class=${this.flash ? "badge accent flash" : "badge"}>${this.flash ? "flushed" : this.pending ? "pending" : "idle"}</span>`;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
357
|
var MAP = port(MapIface, MapIface.ops.map);
|
|
228
358
|
|
|
229
359
|
class NanoMap extends ViewElement {
|
|
@@ -272,21 +402,606 @@ class NanoLog extends ViewElement {
|
|
|
272
402
|
}
|
|
273
403
|
}
|
|
274
404
|
|
|
405
|
+
// packages/ui/src/views/debounce.ts
|
|
406
|
+
import { css, html as html4 } from "lit";
|
|
407
|
+
import { port as port2 } from "@pritzlaff/nano-core";
|
|
408
|
+
|
|
409
|
+
// packages/ui/src/views/debounce-model.ts
|
|
410
|
+
var G = {
|
|
411
|
+
rows: 3,
|
|
412
|
+
perRow: 18,
|
|
413
|
+
sp: 54,
|
|
414
|
+
xEnd: 1110,
|
|
415
|
+
xStart: 192,
|
|
416
|
+
rowY: [176, 106, 36],
|
|
417
|
+
maxPos: 53,
|
|
418
|
+
hidePos: -2.3,
|
|
419
|
+
bucketTop: 290,
|
|
420
|
+
bucketH: 270,
|
|
421
|
+
pitch: 122,
|
|
422
|
+
history: 8,
|
|
423
|
+
enterSpeed: 0.07,
|
|
424
|
+
flushSpeed: 0.06,
|
|
425
|
+
hatchLeadMs: 180,
|
|
426
|
+
settleMs: 260,
|
|
427
|
+
slideMs: 480
|
|
428
|
+
};
|
|
429
|
+
var reasonFor = (q, quiet, maxWait = Infinity) => q.at(-1).at + quiet <= q[0].at + maxWait ? "quiet" : "max wait";
|
|
430
|
+
var dueAt = (q, quiet, maxWait = Infinity) => Math.min(q.at(-1).at + quiet, q[0].at + maxWait);
|
|
431
|
+
var arrivalPos = (slot, at, now) => Math.max(slot, G.maxPos - (now - at) * G.enterSpeed);
|
|
432
|
+
var flushTravel = (f, now) => Math.max(0, now - f.at - G.hatchLeadMs) * G.flushSpeed;
|
|
433
|
+
function startFlush(events, now, reason) {
|
|
434
|
+
const farthest = Math.max(...events.map((e, i) => arrivalPos(i, e.at, now)));
|
|
435
|
+
return { events, at: now, doneAt: now + G.hatchLeadMs + (farthest - G.hidePos) / G.flushSpeed + G.settleMs, reason };
|
|
436
|
+
}
|
|
437
|
+
function slotXY(pos) {
|
|
438
|
+
if (pos < 0)
|
|
439
|
+
return { x: G.xEnd, y: G.rowY[0] - pos * G.sp };
|
|
440
|
+
const r = Math.min(G.rows - 1, Math.floor(pos / G.perRow)), i = pos - r * G.perRow;
|
|
441
|
+
const xAt = (row, idx) => row % 2 === 0 ? G.xEnd - idx * G.sp : G.xStart + idx * G.sp;
|
|
442
|
+
if (i <= G.perRow - 1)
|
|
443
|
+
return { x: xAt(r, i), y: G.rowY[r] };
|
|
444
|
+
const frac = i - (G.perRow - 1);
|
|
445
|
+
return { x: xAt(r, G.perRow - 1), y: G.rowY[r] + (G.rowY[r + 1] - G.rowY[r]) * frac };
|
|
446
|
+
}
|
|
447
|
+
function colorOf(v) {
|
|
448
|
+
return typeof v === "number" ? "var(--nano-s1, #4C8DFF)" : typeof v === "string" ? "var(--nano-s2, #FF9F1C)" : v === null || typeof v === "boolean" ? "var(--nano-s5, #B48CFF)" : "var(--nano-s3, #2EC4A6)";
|
|
449
|
+
}
|
|
450
|
+
var tint = (color, a) => `color-mix(in srgb, ${color} ${Math.round(a * 100)}%, transparent)`;
|
|
451
|
+
var label = (v, n) => {
|
|
452
|
+
const s = typeof v === "string" ? v : JSON.stringify(v) ?? String(v);
|
|
453
|
+
return s.length > n ? s.slice(0, n - 1) + "…" : s;
|
|
454
|
+
};
|
|
455
|
+
var clamp01 = (v) => Math.max(0, Math.min(1, v));
|
|
456
|
+
function bucketView(events) {
|
|
457
|
+
const n = events.length, inner = G.bucketH - 8, gap = n > 40 ? 0 : 2;
|
|
458
|
+
const h = n === 0 ? 0 : Math.max(1, Math.min(18, Math.floor((inner - gap * (n - 1)) / n)));
|
|
459
|
+
const fill = n === 0 ? 0 : Math.min(inner, n * h + (n - 1) * gap);
|
|
460
|
+
return {
|
|
461
|
+
n,
|
|
462
|
+
gap,
|
|
463
|
+
solid: n > 0,
|
|
464
|
+
countTop: G.bucketTop + G.bucketH - 4 - fill - 24,
|
|
465
|
+
cells: events.map((e) => ({ color: colorOf(e.value), bg: tint(colorOf(e.value), 0.32), h, text: h >= 16 ? label(e.value, 8) : "" }))
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// packages/ui/src/views/debounce-parts.ts
|
|
470
|
+
import { html as html3 } from "lit";
|
|
471
|
+
var MONO = "'JetBrains Mono', ui-monospace, monospace";
|
|
472
|
+
var slider = (name, aria, min, max, step, value, elapsed, color, drag, set, off) => html3`
|
|
473
|
+
<label style="display:flex; flex-direction:column; gap:6px; width:180px">
|
|
474
|
+
<span style="display:flex; justify-content:space-between"><span>${off ? html3`<input type="checkbox" aria-label=${"Use " + name} .checked=${off.on} @change=${(e) => off.toggle(e.target.checked)}> ` : ""}${name}</span><span style="color:var(--nano-fg, #E6EAF0)">${off && !off.on ? "off" : `${Math.round(Math.min(elapsed, value))} / ${value} ms`}</span></span>
|
|
475
|
+
<span style="display:block; height:6px; border-radius:3px; background:var(--nano-surface-2, #222933); overflow:hidden"><span style="display:block; height:6px; width:${off && !off.on ? 0 : Math.round(clamp01(elapsed / (value || 1)) * 100)}%; background:${color}"></span></span>
|
|
476
|
+
<input type="range" min=${min} max=${max} step=${step} .value=${String(value)} ?disabled=${off && !off.on} aria-label=${aria} style="width:180px; margin:0; accent-color:${color}"
|
|
477
|
+
@input=${(e) => drag(Number(e.target.value))} @change=${(e) => set(Number(e.target.value))}>
|
|
478
|
+
</label>`;
|
|
479
|
+
var track = () => html3`
|
|
480
|
+
<div style="position:absolute; left:100px; top:12px; width:80px; height:48px; border-radius:24px 0 0 24px; background:var(--nano-surface, #131820)"></div>
|
|
481
|
+
<div style="position:absolute; left:114px; top:28px; font-family:${MONO}; font-size:12px; color:var(--nano-muted, #9AA4B2)">in →</div>
|
|
482
|
+
<div style="position:absolute; left:164px; top:12px; width:974px; height:48px; border-radius:24px; background:var(--nano-surface-2, #161B22)"></div>
|
|
483
|
+
<div style="position:absolute; left:1086px; top:36px; width:48px; height:70px; background:var(--nano-surface-2, #161B22)"></div>
|
|
484
|
+
<div style="position:absolute; left:164px; top:82px; width:974px; height:48px; border-radius:24px; background:var(--nano-surface-2, #161B22)"></div>
|
|
485
|
+
<div style="position:absolute; left:168px; top:106px; width:48px; height:70px; background:var(--nano-surface-2, #161B22)"></div>
|
|
486
|
+
<div style="position:absolute; left:164px; top:152px; width:974px; height:48px; border-radius:24px; background:var(--nano-surface-2, #161B22)"></div>
|
|
487
|
+
<div style="position:absolute; left:1082px; top:176px; width:56px; height:114px; background:var(--nano-surface-2, #161B22)"></div>`;
|
|
488
|
+
function bucket(v, left, opacity, id, reason, reasonColor, live, border = "var(--nano-border, #2A313C)") {
|
|
489
|
+
return html3`<div class=${live ? "live" : "batch"} style="position:absolute; left:${left}px; top:0; width:122px; height:610px; opacity:${opacity}; pointer-events:none">
|
|
490
|
+
${v.n ? html3`<div style="position:absolute; left:0; top:${v.countTop}px; width:122px; text-align:center; font-family:${MONO}; font-size:13px; color:var(--nano-fg, #E6EAF0)">${v.n}</div>` : ""}
|
|
491
|
+
<div style="position:absolute; left:15px; top:290px; width:92px; height:270px; box-sizing:border-box; border:${live ? "2px solid " + border : "1px " + (v.solid ? "solid" : "dashed") + " var(--nano-border, #2A313C)"}; border-top:none; border-radius:0 0 10px 10px; padding:${live ? 3 : 4}px; display:flex; flex-direction:column-reverse; gap:${v.gap}px; overflow:hidden${live ? "; background:var(--nano-surface, #12171E)" : ""}">
|
|
492
|
+
${v.cells.map((c) => html3`<div class="cell" style="flex:none; height:${c.h}px; box-sizing:border-box; border-radius:3px; background:${c.bg}; border:1px solid ${c.color}; color:${c.color}; display:flex; align-items:center; justify-content:center; font-family:${MONO}; font-size:10px; overflow:hidden">${c.text}</div>`)}
|
|
493
|
+
</div>
|
|
494
|
+
<div style="position:absolute; left:0; top:568px; width:122px; display:flex; flex-direction:column; align-items:center; gap:3px; font-family:${MONO}; font-size:12px">
|
|
495
|
+
<span style="color:${live ? "var(--nano-warn, #E8B04B)" : "var(--nano-fg, #E6EAF0)"}">${id}</span><span style="color:${reasonColor}">${reason}</span>
|
|
496
|
+
</div>
|
|
497
|
+
</div>`;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// packages/ui/src/views/debounce.ts
|
|
501
|
+
var PUSH = port2(Debounce, Debounce.ops.push);
|
|
502
|
+
var BOX = { x: 90, w: 1090, h: 600 };
|
|
503
|
+
var REASON_COLOR = { quiet: "var(--nano-muted, #9AA4B2)", "max wait": "var(--nano-warn, #E8B04B)" };
|
|
504
|
+
|
|
505
|
+
class NanoDebounce extends ViewElement {
|
|
506
|
+
static styles = [...ViewElement.styles, css`:host { display: block; height: 100%; min-height: 160px }`];
|
|
507
|
+
pending = [];
|
|
508
|
+
flushing = null;
|
|
509
|
+
batches = [];
|
|
510
|
+
batchSeq = 0;
|
|
511
|
+
committed = 0;
|
|
512
|
+
lastCommitAt = -1e9;
|
|
513
|
+
dragged = {};
|
|
514
|
+
valued = false;
|
|
515
|
+
unsub;
|
|
516
|
+
raf = 0;
|
|
517
|
+
fit = { w: BOX.w, h: BOX.h };
|
|
518
|
+
ro;
|
|
519
|
+
config(tg) {
|
|
520
|
+
return { ...tg.app.deployment().pods[tg.pod]?.config, ...this.dragged };
|
|
521
|
+
}
|
|
522
|
+
quiet(tg) {
|
|
523
|
+
return this.config(tg).quietMs ?? 300;
|
|
524
|
+
}
|
|
525
|
+
maxWait(tg) {
|
|
526
|
+
return this.config(tg).maxWaitMs;
|
|
527
|
+
}
|
|
528
|
+
started(tg) {
|
|
529
|
+
this.unsub?.();
|
|
530
|
+
try {
|
|
531
|
+
this.unsub = tg.app.runtime(tg.runtime).subscribe(Debounce.ops.push, ({ input: input2 }) => this.arrive(input2));
|
|
532
|
+
this.valued = true;
|
|
533
|
+
} catch {
|
|
534
|
+
this.unsub = undefined;
|
|
535
|
+
this.valued = false;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
hear(e, tg) {
|
|
539
|
+
if (e.type === "applied" && (e.changed.includes(tg.pod) || e.added.includes(tg.pod))) {
|
|
540
|
+
this.pending = [];
|
|
541
|
+
this.started(tg);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (e.type !== "sent" || e.kind === "subscribe" || e.kind === "unsubscribe")
|
|
545
|
+
return;
|
|
546
|
+
if (!this.valued && e.to === tg.pod && e.port === PUSH)
|
|
547
|
+
this.arrive("•");
|
|
548
|
+
else if (e.from === tg.pod && (e.kind === "pipe" || e.kind === "on") && e.port !== PUSH)
|
|
549
|
+
this.flush(tg);
|
|
550
|
+
}
|
|
551
|
+
arrive(value) {
|
|
552
|
+
this.pending = [...this.pending, { value, at: Date.now() }];
|
|
553
|
+
this.requestUpdate();
|
|
554
|
+
}
|
|
555
|
+
flush(tg, now = Date.now()) {
|
|
556
|
+
if (!this.pending.length)
|
|
557
|
+
return;
|
|
558
|
+
if (this.flushing)
|
|
559
|
+
this.commit(now);
|
|
560
|
+
this.flushing = startFlush(this.pending, now, reasonFor(this.pending, this.quiet(tg), this.maxWait(tg)));
|
|
561
|
+
this.pending = [];
|
|
562
|
+
this.requestUpdate();
|
|
563
|
+
}
|
|
564
|
+
commit(now) {
|
|
565
|
+
const f = this.flushing;
|
|
566
|
+
this.batchSeq += 1;
|
|
567
|
+
this.committed += f.events.length;
|
|
568
|
+
this.lastCommitAt = now;
|
|
569
|
+
this.batches = [...this.batches, { id: this.batchSeq, events: f.events, reason: f.reason }].slice(-G.history);
|
|
570
|
+
this.flushing = null;
|
|
571
|
+
}
|
|
572
|
+
async set(tg, c) {
|
|
573
|
+
const d = tg.app.deployment(), p = d.pods[tg.pod];
|
|
574
|
+
if (!p)
|
|
575
|
+
return;
|
|
576
|
+
const config = { ...p.config, ...c };
|
|
577
|
+
if (config.maxWaitMs === undefined)
|
|
578
|
+
delete config.maxWaitMs;
|
|
579
|
+
const pods = { ...d.pods, [tg.pod]: { ...p, config: { quietMs: 300, ...config } } };
|
|
580
|
+
await tg.app.apply({ ...d, pods });
|
|
581
|
+
this.dragged = {};
|
|
582
|
+
this.requestUpdate();
|
|
583
|
+
}
|
|
584
|
+
firstUpdated() {
|
|
585
|
+
const box = this.renderRoot.querySelector(".fit");
|
|
586
|
+
if (!box || typeof ResizeObserver === "undefined")
|
|
587
|
+
return;
|
|
588
|
+
this.ro = new ResizeObserver(() => {
|
|
589
|
+
this.fit = { w: box.clientWidth, h: box.clientHeight };
|
|
590
|
+
this.requestUpdate();
|
|
591
|
+
});
|
|
592
|
+
this.ro.observe(box);
|
|
593
|
+
}
|
|
594
|
+
connectedCallback() {
|
|
595
|
+
super.connectedCallback();
|
|
596
|
+
const box = this.renderRoot?.querySelector?.(".fit");
|
|
597
|
+
if (box)
|
|
598
|
+
this.ro?.observe(box);
|
|
599
|
+
}
|
|
600
|
+
disconnectedCallback() {
|
|
601
|
+
super.disconnectedCallback();
|
|
602
|
+
this.unsub?.();
|
|
603
|
+
this.unsub = undefined;
|
|
604
|
+
this.ro?.disconnect();
|
|
605
|
+
cancelAnimationFrame(this.raf);
|
|
606
|
+
this.raf = 0;
|
|
607
|
+
}
|
|
608
|
+
willUpdate(changed) {
|
|
609
|
+
super.willUpdate(changed);
|
|
610
|
+
const now = Date.now(), tg = this.target;
|
|
611
|
+
if (tg && this.pending.length && now >= dueAt(this.pending, this.quiet(tg), this.maxWait(tg)) + 40)
|
|
612
|
+
this.flush(tg, now);
|
|
613
|
+
if (this.flushing && now >= this.flushing.doneAt)
|
|
614
|
+
this.commit(now);
|
|
615
|
+
}
|
|
616
|
+
updated() {
|
|
617
|
+
const busy = this.pending.length > 0 || this.flushing !== null || Date.now() - this.lastCommitAt < G.slideMs;
|
|
618
|
+
if (busy && !this.raf && typeof requestAnimationFrame !== "undefined")
|
|
619
|
+
this.raf = requestAnimationFrame(() => {
|
|
620
|
+
this.raf = 0;
|
|
621
|
+
this.requestUpdate();
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
face(tg) {
|
|
625
|
+
const now = Date.now(), pending = this.pending, f = this.flushing, quiet = this.quiet(tg), maxWait = this.maxWait(tg);
|
|
626
|
+
const travel = f ? flushTravel(f, now) : 0;
|
|
627
|
+
const placed = [...pending.map((e, i) => ({ e, pos: arrivalPos(i, e.at, now) })), ...f ? f.events.map((e, i) => ({ e, pos: arrivalPos(i, e.at, now) - travel })) : []];
|
|
628
|
+
const items = placed.filter((p) => p.pos <= G.maxPos && p.pos > G.hidePos).map((p) => ({ ...slotXY(p.pos), v: p.e.value }));
|
|
629
|
+
const overflow = placed.filter((p) => p.pos > G.maxPos).length;
|
|
630
|
+
const live = bucketView(placed.filter((p) => p.pos <= G.hidePos).map((p) => p.e));
|
|
631
|
+
const ease = 1 - Math.pow(1 - clamp01((now - this.lastCommitAt) / G.slideMs), 3);
|
|
632
|
+
const doorDeg = f ? Math.round(80 * Math.min(clamp01((now - f.at) / 140), clamp01((f.doneAt - now - 60) / 160))) : 0;
|
|
633
|
+
const n = pending.length, first = pending[0]?.at ?? 0, last = pending.at(-1)?.at ?? 0;
|
|
634
|
+
const dropIn = n ? Math.max(0, Math.round(dueAt(pending, quiet, maxWait) - now)) : 0;
|
|
635
|
+
const status = n ? "collecting " + n + (f ? " · hatch busy" : " · drops in " + dropIn + " ms (" + reasonFor(pending, quiet, maxWait) + ")") : f ? "hatch open · dropping " + f.events.length : "idle · waiting for events";
|
|
636
|
+
const total = this.committed + (f?.events.length ?? 0) + n, batches = this.batchSeq + (f ? 1 : 0);
|
|
637
|
+
const k = Math.max(0.1, Math.min(this.fit.w / BOX.w, this.fit.h / BOX.h));
|
|
638
|
+
const dx = (this.fit.w - BOX.w * k) / 2 - BOX.x * k, dy = Math.max(0, (this.fit.h - BOX.h * k) / 2);
|
|
639
|
+
const muted = "var(--nano-muted, #9AA4B2)", fg = "var(--nano-fg, #E6EAF0)", warn = "var(--nano-warn, #E8B04B)";
|
|
640
|
+
return html4`<div style="box-sizing:border-box; height:100%; padding:12px 16px; display:flex; flex-direction:column; gap:12px; background:var(--nano-bg, #0E1116); color:${fg}; font-family:Inter, system-ui, sans-serif; overflow:hidden">
|
|
641
|
+
<div style="display:flex; justify-content:space-between; align-items:flex-end; gap:12px 20px; flex-wrap:wrap; font-family:${MONO}; font-size:12px; color:${muted}">
|
|
642
|
+
<div style="display:flex; gap:20px">
|
|
643
|
+
<div style="display:flex; flex-direction:column; gap:4px"><span>in → out</span><span class="ratio" style="color:${fg}; font-size:14px">${total} → ${batches} batches</span></div>
|
|
644
|
+
<div style="display:flex; flex-direction:column; gap:4px"><span>avg batch</span><span style="color:${fg}; font-size:14px">${this.batchSeq ? (this.committed / this.batchSeq).toFixed(1) + " values" : "—"}</span></div>
|
|
645
|
+
</div>
|
|
646
|
+
<div style="display:flex; gap:12px 20px; flex-wrap:wrap">
|
|
647
|
+
${slider("quiet", "Quiet period in milliseconds", 0, 5000, 50, quiet, n ? now - last : 0, "var(--nano-accent, #8FB3FF)", (v) => {
|
|
648
|
+
this.dragged = { ...this.dragged, quietMs: v };
|
|
649
|
+
this.requestUpdate();
|
|
650
|
+
}, (v) => this.set(tg, { quietMs: v }))}
|
|
651
|
+
${slider("max wait", "Maximum wait in milliseconds", 100, 1e4, 100, maxWait ?? 1000, n ? now - first : 0, warn, (v) => {
|
|
652
|
+
this.dragged = { ...this.dragged, maxWaitMs: v };
|
|
653
|
+
this.requestUpdate();
|
|
654
|
+
}, (v) => this.set(tg, { maxWaitMs: v }), { on: maxWait !== undefined, toggle: (on) => this.set(tg, { maxWaitMs: on ? 1000 : undefined }) })}
|
|
655
|
+
</div>
|
|
656
|
+
</div>
|
|
657
|
+
<div class="fit" style="flex:1; min-height:0; position:relative; overflow:hidden"><div style="position:absolute; left:0; top:0; width:1200px; height:610px; transform:translate(${dx}px, ${dy}px) scale(${k}); transform-origin:0 0">
|
|
658
|
+
${track()}
|
|
659
|
+
${overflow ? html4`<div style="position:absolute; left:100px; top:70px; font-family:${MONO}; font-size:12px; color:${warn}">+${overflow} queued</div>` : ""}
|
|
660
|
+
<div class="status" style="position:absolute; left:660px; top:214px; width:400px; text-align:right; font-family:${MONO}; font-size:13px; color:${muted}">${status}</div>
|
|
661
|
+
<div style="position:absolute; left:1146px; top:210px; font-family:${MONO}; font-size:11px; letter-spacing:0.08em; color:${muted}">HATCH</div>
|
|
662
|
+
<div style="position:absolute; left:1082px; top:206px; width:28px; height:6px; border-radius:2px; background:${warn}; transform-origin:0 50%; transform:rotate(${doorDeg}deg); z-index:2"></div>
|
|
663
|
+
<div style="position:absolute; left:1110px; top:206px; width:28px; height:6px; border-radius:2px; background:${warn}; transform-origin:100% 50%; transform:rotate(${-doorDeg}deg); z-index:2"></div>
|
|
664
|
+
${items.map((it) => html4`<div class="item" style="position:absolute; left:${Math.round(it.x - 20)}px; top:${Math.round(it.y - 20)}px; width:40px; height:40px; box-sizing:border-box; border-radius:10px; border:1.5px solid ${colorOf(it.v)}; background:${tint(colorOf(it.v), 0.16)}; color:${colorOf(it.v)}; display:flex; align-items:center; justify-content:center; z-index:3; font-family:${MONO}; font-size:11px; overflow:hidden">${label(it.v, 4)}</div>`)}
|
|
665
|
+
<div style="position:absolute; left:0; top:0; width:1200px; height:610px; transform:translateX(${Math.round(G.pitch * (1 - ease))}px); pointer-events:none">
|
|
666
|
+
${this.batches.slice().reverse().map((b, i) => bucket(bucketView(b.events), G.xEnd - G.pitch * (i + 1) - G.pitch / 2, i + 1 >= G.history ? Math.round((1 - ease) * 100) / 100 : 1, "#" + b.id, b.reason, REASON_COLOR[b.reason], false))}
|
|
667
|
+
</div>
|
|
668
|
+
${bucket(live, 1049, 1, "#" + (this.batchSeq + 1), f ? "filling · " + f.reason : "next batch", muted, true, f ? warn : "var(--nano-border-strong, #3A4350)")}
|
|
669
|
+
</div></div>
|
|
670
|
+
</div>`;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// packages/ui/src/views/input.ts
|
|
675
|
+
import { html as html5 } from "lit";
|
|
676
|
+
class NanoInput extends ViewElement {
|
|
677
|
+
value = "";
|
|
678
|
+
kind(tg) {
|
|
679
|
+
return tg.app.deployment().pods[tg.pod]?.config?.kind ?? "text";
|
|
680
|
+
}
|
|
681
|
+
async edit(tg, v) {
|
|
682
|
+
this.value = v;
|
|
683
|
+
await this.pod(tg).change(v);
|
|
684
|
+
}
|
|
685
|
+
async send(tg) {
|
|
686
|
+
await this.pod(tg).submit(this.value);
|
|
687
|
+
}
|
|
688
|
+
async setKind(tg, kind) {
|
|
689
|
+
const d = tg.app.deployment(), p = d.pods[tg.pod];
|
|
690
|
+
if (!p)
|
|
691
|
+
return;
|
|
692
|
+
const pods = { ...d.pods, [tg.pod]: { ...p, config: { ...p.config, kind } } };
|
|
693
|
+
this.value = kind === "boolean" ? false : kind === "number" ? 0 : "";
|
|
694
|
+
await tg.app.apply({ ...d, pods });
|
|
695
|
+
}
|
|
696
|
+
face(tg) {
|
|
697
|
+
const kind = this.kind(tg), box = (e) => e.target;
|
|
698
|
+
const parse = (el) => kind === "number" ? el.value === "" ? null : Number(el.value) : kind === "boolean" ? el.checked : el.value;
|
|
699
|
+
const key = (e) => {
|
|
700
|
+
if (e.key !== "Enter" || kind === "textarea" && !e.ctrlKey && !e.metaKey)
|
|
701
|
+
return;
|
|
702
|
+
e.preventDefault();
|
|
703
|
+
this.value = parse(box(e));
|
|
704
|
+
this.send(tg);
|
|
705
|
+
};
|
|
706
|
+
const field = kind === "textarea" ? html5`<textarea rows="3" aria-label=${tg.pod} .value=${String(this.value ?? "")} @input=${(e) => this.edit(tg, parse(box(e)))} @keydown=${key}></textarea>` : kind === "boolean" ? html5`<input type="checkbox" aria-label=${tg.pod} .checked=${!!this.value} @change=${async (e) => {
|
|
707
|
+
await this.edit(tg, parse(box(e)));
|
|
708
|
+
await this.send(tg);
|
|
709
|
+
}}>` : html5`<input type=${kind} aria-label=${tg.pod} .value=${String(this.value ?? "")} @input=${(e) => this.edit(tg, parse(box(e)))} @keydown=${key}>`;
|
|
710
|
+
return html5`<div class="row">
|
|
711
|
+
<select aria-label="Kind" @change=${(e) => this.setKind(tg, e.target.value)}>${KINDS.map((k) => html5`<option ?selected=${k === kind}>${k}</option>`)}</select>
|
|
712
|
+
${field}<button class="primary" @click=${() => this.send(tg)}>Send</button></div>`;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// packages/ui/src/explorer.ts
|
|
717
|
+
import { LitElement as LitElement3, css as css3, html as html9 } from "lit";
|
|
718
|
+
|
|
719
|
+
// packages/ui/src/explorer-details.ts
|
|
720
|
+
import { html as html6, nothing } from "lit";
|
|
721
|
+
var op = (port3) => port3.slice(port3.lastIndexOf("/") + 1);
|
|
722
|
+
var row = (k, v) => html6`<dt>${k}</dt><dd>${v}</dd>`;
|
|
723
|
+
var link = (c, id, label2) => html6`<a href="#" @click=${(e) => {
|
|
724
|
+
e.preventDefault();
|
|
725
|
+
c.go(id);
|
|
726
|
+
}}>${label2}</a>`;
|
|
727
|
+
var list = (items) => items.length ? html6`<ul>${items.map((i) => html6`<li>${i}</li>`)}</ul>` : html6`<span class="muted">none</span>`;
|
|
728
|
+
var placed = (d, pod) => Object.keys(d.runtimes).filter((r) => d.runtimes[r].pods.includes(pod));
|
|
729
|
+
var podLink = (c, pod) => {
|
|
730
|
+
const r = placed(c.d, pod)[0];
|
|
731
|
+
return r ? link(c, `p:${r}:${pod}`, pod) : pod;
|
|
732
|
+
};
|
|
733
|
+
var pipeText = (s, end = (p) => p) => html6`${end(s.from)}.${op(s.source)} → ${end(s.to)}.${op(s.target)}`;
|
|
734
|
+
var opAt = (c, port3) => {
|
|
735
|
+
const at = port3.lastIndexOf("/"), coord = port3.slice(0, at), name = port3.slice(at + 1);
|
|
736
|
+
return { coord, name, o: Object.values(c.registry.interface(coord)?.ops ?? {}).find((x) => x.name === name) };
|
|
737
|
+
};
|
|
738
|
+
var callRow = (c, x, from, to) => html6`${from ? html6`${podLink(c, x.from)}.` : nothing}${x.source === null ? "?" : op(x.source)} → ${to ? html6`${podLink(c, x.to)}.` : nothing}${op(x.target)}${x.declared ? nothing : html6` <span class="warn">not declared</span>`}`;
|
|
739
|
+
function pod(c, runtime, name) {
|
|
740
|
+
const p = c.d.pods[name];
|
|
741
|
+
if (!p)
|
|
742
|
+
return html6`<p class="muted">${name} is no longer deployed.</p>`;
|
|
743
|
+
const impl = c.registry.implementation(p.implementation);
|
|
744
|
+
const subs = Object.entries(c.d.runtimes).flatMap(([r, rt]) => rt.subscriptions.map((s) => ({ r, s })));
|
|
745
|
+
const calls = subs.filter(({ s }) => s.kind === "call" && s.from === name).map(({ s }) => s.to);
|
|
746
|
+
const needs = Object.entries(impl?.dependencies ?? {}).map(([role, sel]) => {
|
|
747
|
+
const to = calls.find((t) => {
|
|
748
|
+
const i = c.registry.implementation(c.d.pods[t]?.implementation ?? "");
|
|
749
|
+
return !sel.implements || i?.provides.some((x) => x.coord === String(sel.implements));
|
|
750
|
+
});
|
|
751
|
+
return html6`${role} (${sel.implements ?? "any"}) → ${to ? podLink(c, to) : html6`<span class="warn">not connected</span>`}`;
|
|
752
|
+
});
|
|
753
|
+
return html6`<h3>pod ${name}</h3><dl>
|
|
754
|
+
${row("implementation", link(c, `m:${p.implementation}`, p.implementation))}
|
|
755
|
+
${row("runtimes", placed(c.d, name).map((r, i) => html6`${i ? ", " : ""}${link(c, `r:${r}`, r)}`))}
|
|
756
|
+
${row("isolation", p.isolation ?? "host")}${row("starts", p.eager ? "eager" : "lazy")}${row("state", c.status(placed(c.d, name)[0] ?? "", name))}
|
|
757
|
+
${row("config", p.config === undefined ? html6`<span class="muted">none</span>` : html6`<code>${JSON.stringify(p.config)}</code>`)}
|
|
758
|
+
${row("needs", list(needs))}
|
|
759
|
+
${c.calls ? row("calls", list(c.calls.filter((x) => x.from === name).map((x) => callRow(c, x, false, true)))) : nothing}
|
|
760
|
+
${row("called by", c.calls?.some((x) => x.to === name) ? list(c.calls.filter((x) => x.to === name).map((x) => callRow(c, x, true, false))) : list(subs.filter(({ s }) => s.kind === "call" && s.to === name).map(({ s }) => podLink(c, s.from))))}
|
|
761
|
+
${row("pipes", list(subs.flatMap(({ s }) => s.kind === "pipe" && (s.from === name || s.to === name) ? [pipeText(s)] : [])))}
|
|
762
|
+
</dl><button class="btn" @click=${() => c.open({ runtime, pod: name })}>Open view</button>`;
|
|
763
|
+
}
|
|
764
|
+
function runtime(c, id) {
|
|
765
|
+
const r = c.d.runtimes[id];
|
|
766
|
+
if (!r)
|
|
767
|
+
return html6`<p class="muted">${id} is no longer deployed.</p>`;
|
|
768
|
+
return html6`<h3>runtime ${id}</h3><dl>
|
|
769
|
+
${row("pods", list(r.pods.map((p) => link(c, `p:${id}:${p}`, p))))}
|
|
770
|
+
${row("call edges", list(r.subscriptions.flatMap((s) => s.kind === "call" ? [html6`${podLink(c, s.from)} → ${podLink(c, s.to)}`] : [])))}
|
|
771
|
+
${row("pipes", list(r.subscriptions.flatMap((s) => s.kind === "pipe" ? [pipeText(s)] : [])))}
|
|
772
|
+
${row("policy", !r.policy ? "none (everything allowed)" : r.policy.kind === "rules" ? `${r.policy.rules.length} rules (see Settings)` : r.policy.kind)}
|
|
773
|
+
</dl><button class="btn" @click=${() => c.remove(id)}>Delete runtime</button>`;
|
|
774
|
+
}
|
|
775
|
+
var typeName = (def) => {
|
|
776
|
+
if (!def)
|
|
777
|
+
return "nothing";
|
|
778
|
+
if (def.label)
|
|
779
|
+
return def.label;
|
|
780
|
+
if (def.anyOf)
|
|
781
|
+
return def.anyOf.map(typeName).join(" | ");
|
|
782
|
+
if (def.const !== undefined)
|
|
783
|
+
return JSON.stringify(def.const);
|
|
784
|
+
if (def.type === "object") {
|
|
785
|
+
const k = Object.keys(def.properties ?? {});
|
|
786
|
+
return `{ ${k.slice(0, 4).join(", ")}${k.length > 4 ? ", …" : ""} }`;
|
|
787
|
+
}
|
|
788
|
+
if (def.type === "array")
|
|
789
|
+
return `${typeName(def.items)}[]`;
|
|
790
|
+
return def.type ?? "any";
|
|
791
|
+
};
|
|
792
|
+
function opRow(c, port3, side) {
|
|
793
|
+
const { coord, name, o } = opAt(c, port3);
|
|
794
|
+
const type = o && (side === "source" ? o.output : o.input);
|
|
795
|
+
return html6`${link(c, `i:${coord}`, coord)}/<code>${name}</code>${o ? html6` <span class="muted">${o.kind}, ${side === "source" ? "emits" : "takes"}</span> <code>${typeName(type)}</code>` : nothing}`;
|
|
796
|
+
}
|
|
797
|
+
function subscription(c, runtime2, pod2, i) {
|
|
798
|
+
const s = c.d.runtimes[runtime2]?.subscriptions.filter((x) => x.from === pod2)[i];
|
|
799
|
+
if (!s)
|
|
800
|
+
return html6`<p class="muted">That subscription is no longer deployed.</p>`;
|
|
801
|
+
return html6`<h3>${s.kind === "call" ? "call edge" : "pipe"}</h3><dl>
|
|
802
|
+
${row("runtime", link(c, `r:${runtime2}`, runtime2))}${row("from", podLink(c, s.from))}${row("to", podLink(c, s.to))}
|
|
803
|
+
${s.kind === "pipe" ? html6`${row("source", opRow(c, s.source, "source"))}${row("target", opRow(c, s.target, "target"))}` : nothing}
|
|
804
|
+
</dl>${s.kind === "call" ? html6`<button class="btn" @click=${() => c.open({ runtime: placed(c.d, s.to)[0] ?? runtime2, pod: s.to })}>Open ${s.to}</button>` : nothing}`;
|
|
805
|
+
}
|
|
806
|
+
function iface(c, coord) {
|
|
807
|
+
const i = c.registry.manifest().interfaces.find((x) => x.coord === coord);
|
|
808
|
+
if (!i)
|
|
809
|
+
return html6`<p class="muted">${coord} is not registered.</p>`;
|
|
810
|
+
return html6`<h3>interface ${coord}</h3><dl>
|
|
811
|
+
${row("ops", list(i.ops.map(({ name, kind }) => {
|
|
812
|
+
const { o } = opAt(c, `${coord}/${name}`), out = html6`<code>${typeName(o?.output)}</code>`;
|
|
813
|
+
const shape = kind === "event" ? html6`emits ${out}` : html6`<code>${typeName(o?.input)}</code> → ${out}`;
|
|
814
|
+
return html6`${link(c, `o:${coord}/${name}`, name)} ${kind} <span class="muted">${shape}</span>`;
|
|
815
|
+
})))}
|
|
816
|
+
${row("implementations", list(c.registry.implementationsOf(coord).map((m) => link(c, `m:${m.coord}`, m.coord))))}
|
|
817
|
+
</dl>`;
|
|
818
|
+
}
|
|
819
|
+
function implementation(c, coord) {
|
|
820
|
+
const m = c.registry.implementation(coord);
|
|
821
|
+
if (!m)
|
|
822
|
+
return html6`<p class="muted">${coord} is not registered.</p>`;
|
|
823
|
+
return html6`<h3>implementation ${coord}</h3>${m.description ? html6`<p>${m.description}</p>` : nothing}<dl>
|
|
824
|
+
${row("provider", m.provider)}
|
|
825
|
+
${row("provides", list(m.provides.map((i) => link(c, `i:${i.coord}`, i.coord))))}
|
|
826
|
+
${row("needs", list(Object.entries(m.dependencies).map(([role, s]) => html6`${role}: ${s.implements ? link(c, `i:${s.implements}`, String(s.implements)) : JSON.stringify(s)}`)))}
|
|
827
|
+
${row("pods", list(Object.entries(c.d.pods).filter(([, p]) => p.implementation === coord).map(([n]) => podLink(c, n))))}
|
|
828
|
+
</dl>`;
|
|
829
|
+
}
|
|
830
|
+
function operation(c, port3) {
|
|
831
|
+
const { coord, name, o } = opAt(c, port3);
|
|
832
|
+
if (!o)
|
|
833
|
+
return html6`<p class="muted">${port3} is not registered.</p>`;
|
|
834
|
+
const impls = c.registry.implementationsOf(coord).map((m) => m.coord);
|
|
835
|
+
const subs = Object.values(c.d.runtimes).flatMap((r) => r.subscriptions);
|
|
836
|
+
const pipes = subs.flatMap((s) => s.kind === "pipe" && (s.source === port3 || s.target === port3) ? [pipeText(s, (p) => podLink(c, p))] : []);
|
|
837
|
+
return html6`<h3>${o.kind} ${name}</h3>${o.description ? html6`<p>${o.description}</p>` : nothing}<dl>
|
|
838
|
+
${row("interface", link(c, `i:${coord}`, coord))}
|
|
839
|
+
${o.kind === "event" ? row("emits", html6`<code>${typeName(o.output)}</code>`) : html6`${row("takes", html6`<code>${typeName(o.input)}</code>`)}${row("returns", html6`<code>${typeName(o.output)}</code>`)}`}
|
|
840
|
+
${row("implementations", list(impls.map((m) => link(c, `m:${m}`, m))))}
|
|
841
|
+
${row("pods", list(Object.keys(c.d.pods).filter((p) => impls.includes(c.d.pods[p].implementation)).map((p) => podLink(c, p))))}
|
|
842
|
+
${row("pipes", list(pipes))}
|
|
843
|
+
${c.calls ? html6`${row("called by", list(c.calls.filter((x) => x.target === port3).map((x) => callRow(c, x, true, true))))}${row("calls", list(c.calls.filter((x) => x.source === port3).map((x) => callRow(c, x, true, true))))}` : nothing}
|
|
844
|
+
</dl>`;
|
|
845
|
+
}
|
|
846
|
+
function details(c, id) {
|
|
847
|
+
if (!id)
|
|
848
|
+
return html6`<p class="muted">Select a runtime, pod, subscription, interface, implementation or operation.</p>`;
|
|
849
|
+
const [kind, ...rest] = id.split(":"), at = rest.join(":");
|
|
850
|
+
if (kind === "r")
|
|
851
|
+
return runtime(c, at);
|
|
852
|
+
if (kind === "p")
|
|
853
|
+
return pod(c, rest[0], rest.slice(1).join(":"));
|
|
854
|
+
if (kind === "s")
|
|
855
|
+
return subscription(c, rest[0], rest[1], Number(rest[2]));
|
|
856
|
+
if (kind === "i")
|
|
857
|
+
return iface(c, at);
|
|
858
|
+
if (kind === "m")
|
|
859
|
+
return implementation(c, at);
|
|
860
|
+
if (kind === "o")
|
|
861
|
+
return operation(c, at);
|
|
862
|
+
return html6``;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// packages/ui/src/explorer-nodes.ts
|
|
866
|
+
import { html as html7 } from "lit";
|
|
867
|
+
var primary = (id) => id.slice(id.lastIndexOf("|") + 1);
|
|
868
|
+
var op2 = (port3) => port3.slice(port3.lastIndexOf("/") + 1);
|
|
869
|
+
var namespaceOf = (coord) => coord.includes("/") ? coord.slice(0, coord.indexOf("/")) : coord.slice(0, Math.max(0, coord.lastIndexOf(".")));
|
|
870
|
+
var group = (id, label2, children) => ({ id, label: label2, count: children.length, children });
|
|
871
|
+
var alias = (at, n) => ({ ...n, id: `${at}|${n.id}`, children: undefined, body: undefined });
|
|
872
|
+
function nodes(d, registry, status) {
|
|
873
|
+
const m = registry.manifest();
|
|
874
|
+
const ops = m.interfaces.flatMap((i) => i.ops.map((o) => ({ port: `${i.coord}/${o.name}`, iface: i.coord, name: o.name, kind: o.kind })));
|
|
875
|
+
const provides = (impl) => registry.implementation(impl)?.provides.map((i) => i.coord) ?? [];
|
|
876
|
+
const where = (pod2) => Object.keys(d.runtimes).find((r) => d.runtimes[r].pods.includes(pod2)) ?? "";
|
|
877
|
+
const podNode = (pod2) => ({ id: `p:${where(pod2)}:${pod2}`, label: pod2, kind: "pod", data: { ns: namespaceOf(d.pods[pod2]?.implementation ?? ""), status: status(where(pod2), pod2) } });
|
|
878
|
+
const ifaceNode = (c) => ({ id: `i:${c}`, label: c, kind: "interface", data: { ns: namespaceOf(c) } });
|
|
879
|
+
const implNode = (c) => ({ id: `m:${c}`, label: c, kind: "implementation", data: { ns: namespaceOf(c) } });
|
|
880
|
+
const opNode = (o) => ({ id: `o:${o.port}`, label: o.port, kind: o.kind, data: { ns: namespaceOf(o.iface) } });
|
|
881
|
+
const runtimes = Object.entries(d.runtimes).map(([runtime2, r]) => {
|
|
882
|
+
const at = `r:${runtime2}`;
|
|
883
|
+
const impls = [...new Set(r.pods.map((p) => d.pods[p]?.implementation).filter((x) => !!x))];
|
|
884
|
+
const ifaces = [...new Set(impls.flatMap(provides))];
|
|
885
|
+
const pods = r.pods.map((pod2) => {
|
|
886
|
+
const p = d.pods[pod2];
|
|
887
|
+
const subs = r.subscriptions.filter((s) => s.from === pod2).map((s, i) => ({
|
|
888
|
+
id: `s:${runtime2}:${pod2}:${i}`,
|
|
889
|
+
label: s.kind === "call" ? `built on → ${s.to}` : `${op2(s.source)} → ${s.to}.${op2(s.target)}`
|
|
890
|
+
}));
|
|
891
|
+
return {
|
|
892
|
+
...podNode(pod2),
|
|
893
|
+
id: `p:${runtime2}:${pod2}`,
|
|
894
|
+
terms: [p?.implementation ?? ""],
|
|
895
|
+
body: html7`${p?.implementation} ${p?.config === undefined ? "" : JSON.stringify(p.config)}`,
|
|
896
|
+
children: subs
|
|
897
|
+
};
|
|
898
|
+
});
|
|
899
|
+
return { id: at, label: runtime2, kind: "runtime", count: r.pods.length, data: { ns: namespaceOf(runtime2) }, children: [
|
|
900
|
+
group(`${at}/pods`, "Pods", pods),
|
|
901
|
+
group(`${at}/impls`, "Implementations", impls.map((c) => alias(at, implNode(c)))),
|
|
902
|
+
group(`${at}/ifaces`, "Interfaces", ifaces.map((c) => alias(at, ifaceNode(c)))),
|
|
903
|
+
group(`${at}/ops`, "Operations", ops.filter((o) => ifaces.includes(o.iface)).map((o) => alias(at, opNode(o))))
|
|
904
|
+
] };
|
|
905
|
+
});
|
|
906
|
+
return runtimes;
|
|
907
|
+
}
|
|
908
|
+
var namespaces = (list2) => [...new Set(list2.flatMap(function all(n) {
|
|
909
|
+
return [...n.data?.ns ? [n.data.ns] : [], ...(n.children ?? []).flatMap(all)];
|
|
910
|
+
}))].filter(Boolean).sort();
|
|
911
|
+
|
|
912
|
+
// packages/ui/src/filter/model.ts
|
|
913
|
+
var emptyFilter = () => ({ text: "", kinds: new Set, namespaces: new Set, statuses: new Set });
|
|
914
|
+
function matches(item, f, known) {
|
|
915
|
+
const q = f.text.toLowerCase();
|
|
916
|
+
const ns10 = known?.namespaces ? [...f.namespaces].filter((n) => known.namespaces.has(n)) : [...f.namespaces];
|
|
917
|
+
return (!q || [item.label, ...item.terms ?? []].some((s) => s.toLowerCase().includes(q))) && (!f.kinds.size || !!item.kind && f.kinds.has(item.kind)) && (!ns10.length || !!item.ns && ns10.includes(item.ns)) && (!f.statuses.size || !!item.status && f.statuses.has(item.status));
|
|
918
|
+
}
|
|
919
|
+
function filterTree(nodes2, f) {
|
|
920
|
+
const known = { namespaces: new Set(namespaces(nodes2)) };
|
|
921
|
+
const walk = (list2) => list2.flatMap((n) => {
|
|
922
|
+
const item = { label: n.label, kind: n.kind, ns: n.data?.ns, status: n.data?.status, terms: n.terms };
|
|
923
|
+
if (n.kind && matches(item, f, known))
|
|
924
|
+
return [n];
|
|
925
|
+
const kids = walk(n.children ?? []);
|
|
926
|
+
return kids.length ? [{ ...n, children: kids, body: undefined, ...n.count !== undefined && !n.kind && { count: kids.length } }] : [];
|
|
927
|
+
});
|
|
928
|
+
return walk(nodes2);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// packages/ui/src/filter/filter.ts
|
|
932
|
+
import { LitElement as LitElement2, css as css2, html as html8 } from "lit";
|
|
933
|
+
import { base as base2, kit, t } from "@pritzlaff/nano-elements";
|
|
934
|
+
var names = { kinds: "Type", namespaces: "Namespace", statuses: "Status" };
|
|
935
|
+
|
|
936
|
+
class NanoFilter extends LitElement2 {
|
|
937
|
+
static properties = { groups: { attribute: false }, value: { attribute: false }, open: { state: true } };
|
|
938
|
+
static styles = [base2, kit, css2`
|
|
939
|
+
:host { position: relative; display: flex; gap: 6px; align-items: center }
|
|
940
|
+
input { flex: 1 1 auto; min-width: 0 }
|
|
941
|
+
.pop { box-sizing: border-box; padding: 8px } .pop:popover-open { display: grid; gap: 8px }
|
|
942
|
+
.row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center } .row > span { width: 100%; font-size: 11px; color: ${t("muted")} }
|
|
943
|
+
.n { margin-left: 4px; padding: 0 6px; border-radius: 999px; background: ${t("accent-soft")}; color: ${t("fg")}; font-weight: 600; font-variant-numeric: tabular-nums }`];
|
|
944
|
+
constructor() {
|
|
945
|
+
super();
|
|
946
|
+
this.groups = {};
|
|
947
|
+
this.value = emptyFilter();
|
|
948
|
+
this.open = false;
|
|
949
|
+
}
|
|
950
|
+
emit(v) {
|
|
951
|
+
this.dispatchEvent(new CustomEvent("change", { detail: v, bubbles: true, composed: true }));
|
|
952
|
+
}
|
|
953
|
+
flip(g, o) {
|
|
954
|
+
const set = new Set(this.value[g]);
|
|
955
|
+
set.has(o) ? set.delete(o) : set.add(o);
|
|
956
|
+
this.emit({ ...this.value, [g]: set });
|
|
957
|
+
}
|
|
958
|
+
toggled(e) {
|
|
959
|
+
const panel = e.target, button = this.renderRoot.querySelector(".toggle");
|
|
960
|
+
this.open = e.newState === "open";
|
|
961
|
+
if (this.open) {
|
|
962
|
+
const h = this.getBoundingClientRect(), b = button.getBoundingClientRect();
|
|
963
|
+
Object.assign(panel.style, { top: `${b.bottom + 4}px`, left: `${Math.max(0, h.left)}px`, width: `${Math.max(220, h.width)}px`, maxWidth: `calc(100vw - ${Math.max(0, h.left)}px)` });
|
|
964
|
+
panel.querySelector(".row button")?.focus();
|
|
965
|
+
} else if (panel.contains(this.shadowRoot.activeElement))
|
|
966
|
+
button.focus();
|
|
967
|
+
}
|
|
968
|
+
render() {
|
|
969
|
+
const v = this.value, count = v.kinds.size + v.namespaces.size + v.statuses.size;
|
|
970
|
+
const rows = Object.keys(names).filter((g) => this.groups[g]);
|
|
971
|
+
return html8`
|
|
972
|
+
<input type="search" placeholder="Search" aria-label="Search" .value=${v.text} @input=${(e) => this.emit({ ...v, text: e.target.value })}>
|
|
973
|
+
<button class="toggle" popovertarget="panel" aria-haspopup="true" aria-controls="panel" aria-expanded=${this.open}>Filter${count ? ` (${count} active)` : ""}</button>
|
|
974
|
+
<div class="pop" id="panel" popover="auto" role="group" aria-label="Filters" @toggle=${this.toggled}>${rows.map((g) => html8`
|
|
975
|
+
<div class="row" role="group" aria-labelledby="h-${g}"><span id="h-${g}">${names[g]}${v[g].size ? html8` <b class="n" aria-label="${v[g].size} chosen">${v[g].size}</b>` : ""}</span>${this.groups[g].map((o) => html8`
|
|
976
|
+
<button aria-pressed=${v[g].has(o)} @click=${() => this.flip(g, o)}>${o}</button>`)}</div>`)}</div>`;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
275
980
|
// packages/ui/src/explorer.ts
|
|
276
|
-
import { LitElement as LitElement2, html as html3 } from "lit";
|
|
277
981
|
import { base as base3 } from "@pritzlaff/nano-elements";
|
|
278
982
|
import"@pritzlaff/nano-elements";
|
|
279
|
-
var
|
|
983
|
+
var KINDS2 = ["runtime", "pod", "interface", "implementation", "action", "event"];
|
|
984
|
+
var STATUSES = ["running", "not started", "stopped", "failed"];
|
|
985
|
+
var LIFECYCLE = new Set(["built", "closed", "restarted", "failure", "applied"]);
|
|
280
986
|
|
|
281
|
-
class NanoExplorer extends
|
|
282
|
-
static properties = { target: { attribute: false },
|
|
283
|
-
static styles = [base3
|
|
987
|
+
class NanoExplorer extends LitElement3 {
|
|
988
|
+
static properties = { target: { attribute: false }, icon: { attribute: false }, selected: { state: true }, filter: { state: true } };
|
|
989
|
+
static styles = [base3, css3`
|
|
990
|
+
:host { display: block; height: 100%; container-type: inline-size }
|
|
991
|
+
.pane { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0 }
|
|
992
|
+
nano-filter { padding: 0 0 6px }
|
|
993
|
+
.split { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 12px; height: 100% }
|
|
994
|
+
.details { overflow: auto; padding: 0 8px; border-left: 1px solid var(--nano-line, rgba(128,128,128,.3)) }
|
|
995
|
+
nano-tree { overflow: auto; min-height: 0 }
|
|
996
|
+
@container (max-width: 520px) { .split { grid-template-columns: 1fr; grid-template-rows: minmax(0, 3fr) minmax(0, 2fr) } .details { border-left: 0; border-top: 1px solid var(--nano-line, rgba(128,128,128,.3)); padding-top: 8px } }
|
|
997
|
+
h3 { margin: 4px 0 8px; font-size: 13px } dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 12px }
|
|
998
|
+
a { color: inherit; text-decoration: underline dotted } dt { opacity: .7 } dd { margin: 0 } ul { margin: 0; padding-left: 16px } .warn { color: var(--nano-warn, #d9a400) } .muted { opacity: .7 }`];
|
|
284
999
|
off;
|
|
285
1000
|
watching;
|
|
286
|
-
opens = new Map;
|
|
287
1001
|
constructor() {
|
|
288
1002
|
super();
|
|
289
|
-
this.
|
|
1003
|
+
this.selected = null;
|
|
1004
|
+
this.filter = emptyFilter();
|
|
290
1005
|
}
|
|
291
1006
|
connectedCallback() {
|
|
292
1007
|
super.connectedCallback();
|
|
@@ -307,12 +1022,8 @@ class NanoExplorer extends LitElement2 {
|
|
|
307
1022
|
this.stop();
|
|
308
1023
|
this.watching = t2;
|
|
309
1024
|
this.off = t2.app.listen((e) => {
|
|
310
|
-
if (e.type === "
|
|
311
|
-
|
|
312
|
-
else if (e.type === "applied") {
|
|
313
|
-
const live = t2.app.deployment().pods;
|
|
314
|
-
this.states = Object.fromEntries(Object.entries(this.states).filter(([pod]) => Object.hasOwn(live, pod)));
|
|
315
|
-
}
|
|
1025
|
+
if (LIFECYCLE.has(e.type) || e.type === "sent" && e.kind === "call" && t2.calls)
|
|
1026
|
+
queueMicrotask(() => this.requestUpdate());
|
|
316
1027
|
});
|
|
317
1028
|
}
|
|
318
1029
|
stop() {
|
|
@@ -320,50 +1031,48 @@ class NanoExplorer extends LitElement2 {
|
|
|
320
1031
|
this.off = undefined;
|
|
321
1032
|
this.watching = undefined;
|
|
322
1033
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
this.opens.set(id, { runtime, pod });
|
|
334
|
-
const subs = r.subscriptions.filter((s) => s.from === pod).map((s, i) => {
|
|
335
|
-
const sid = `s:${runtime}:${pod}:${i}`;
|
|
336
|
-
if (s.kind === "call") {
|
|
337
|
-
this.opens.set(sid, { runtime, pod: s.to });
|
|
338
|
-
return { id: sid, label: `built on → ${s.to}` };
|
|
339
|
-
}
|
|
340
|
-
return { id: sid, label: `${op(s.source)} → ${s.to}.${op(s.target)}` };
|
|
341
|
-
});
|
|
342
|
-
return {
|
|
343
|
-
id,
|
|
344
|
-
label: pod,
|
|
345
|
-
kind: "pod",
|
|
346
|
-
badge: this.states[pod],
|
|
347
|
-
terms: [p?.implementation ?? ""],
|
|
348
|
-
body: html3`${p?.implementation} ${p?.config === undefined ? "" : JSON.stringify(p.config)}`,
|
|
349
|
-
children: subs
|
|
350
|
-
};
|
|
351
|
-
})
|
|
352
|
-
}));
|
|
1034
|
+
open(w) {
|
|
1035
|
+
this.dispatchEvent(new CustomEvent("nano-open", { detail: w, bubbles: true, composed: true }));
|
|
1036
|
+
}
|
|
1037
|
+
del(runtime2) {
|
|
1038
|
+
this.dispatchEvent(new CustomEvent("nano-delete", { detail: { runtime: runtime2 }, bubbles: true, composed: true }));
|
|
1039
|
+
}
|
|
1040
|
+
dbl() {
|
|
1041
|
+
const [k, r, ...p] = (this.selected ?? "").split(":");
|
|
1042
|
+
if (k === "p")
|
|
1043
|
+
this.open({ runtime: r, pod: p.join(":") });
|
|
353
1044
|
}
|
|
354
1045
|
render() {
|
|
355
1046
|
if (!this.target)
|
|
356
|
-
return
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
1047
|
+
return html9``;
|
|
1048
|
+
const t2 = this.target;
|
|
1049
|
+
const status = (r, pod2) => {
|
|
1050
|
+
const s = t2.app.runtime(r).status(pod2);
|
|
1051
|
+
return s.ok ? s.value : "not started";
|
|
1052
|
+
};
|
|
1053
|
+
const c = { d: t2.app.deployment(), registry: t2.registry, status, calls: t2.calls, go: (id) => {
|
|
1054
|
+
this.selected = id;
|
|
1055
|
+
}, open: (w) => this.open(w), remove: (r) => this.del(r) };
|
|
1056
|
+
const all = nodes(c.d, t2.registry, status);
|
|
1057
|
+
const shown2 = filterTree(all, { ...this.filter, text: "" });
|
|
1058
|
+
const groups = { kinds: KINDS2, namespaces: namespaces(all), statuses: STATUSES };
|
|
1059
|
+
return html9`<div class="split"><div class="pane">
|
|
1060
|
+
<nano-filter .groups=${groups} .value=${this.filter} @change=${(e) => {
|
|
1061
|
+
this.filter = e.detail;
|
|
1062
|
+
}}></nano-filter>
|
|
1063
|
+
<nano-tree .nodes=${shown2} .icon=${this.icon} .query=${this.filter.text} .selected=${this.selected} open-depth="2" @dblclick=${() => this.dbl()}
|
|
1064
|
+
@select=${(e) => {
|
|
1065
|
+
e.preventDefault();
|
|
1066
|
+
const id = primary(e.detail.id);
|
|
1067
|
+
if (!/\/(pods|impls|ifaces|ops)$/.test(id))
|
|
1068
|
+
this.selected = id;
|
|
1069
|
+
}}></nano-tree></div>
|
|
1070
|
+
<section class="details" aria-label="Details">${details(c, this.selected)}</section></div>`;
|
|
362
1071
|
}
|
|
363
1072
|
}
|
|
364
1073
|
|
|
365
1074
|
// packages/ui/src/wiring/wiring.ts
|
|
366
|
-
import { LitElement as
|
|
1075
|
+
import { LitElement as LitElement4 } from "lit";
|
|
367
1076
|
|
|
368
1077
|
// packages/ui/src/wiring/constants.ts
|
|
369
1078
|
var TYPE_COLOR = { string: "#2dd4bf", number: "#fbbf24", boolean: "#f472b6", object: "#60a5fa", array: "#a78bfa", signal: "#94a3b8", any: "#e5e7eb", call: "#4CC2FF" };
|
|
@@ -449,12 +1158,12 @@ function padTypeOf(schema) {
|
|
|
449
1158
|
}
|
|
450
1159
|
|
|
451
1160
|
// packages/ui/src/wiring/model.ts
|
|
452
|
-
var padsOf = (scope,
|
|
453
|
-
const impl = registry.implementation(deployment.pods[
|
|
454
|
-
const pad = (
|
|
455
|
-
key: `${scope}${
|
|
456
|
-
instance:
|
|
457
|
-
op:
|
|
1161
|
+
var padsOf = (scope, pod2, deployment, registry) => {
|
|
1162
|
+
const impl = registry.implementation(deployment.pods[pod2]?.implementation ?? "");
|
|
1163
|
+
const pad = (port3, o, dir, kind, schema) => ({
|
|
1164
|
+
key: `${scope}${pod2} ${port3}:${dir}`,
|
|
1165
|
+
instance: pod2,
|
|
1166
|
+
op: port3,
|
|
458
1167
|
label: o.name,
|
|
459
1168
|
dir,
|
|
460
1169
|
kind,
|
|
@@ -463,8 +1172,8 @@ var padsOf = (scope, pod, deployment, registry) => {
|
|
|
463
1172
|
...schema && { schema: schema.schema }
|
|
464
1173
|
});
|
|
465
1174
|
return (impl?.provides ?? []).flatMap((i) => Object.values(i.ops).flatMap((o) => {
|
|
466
|
-
const
|
|
467
|
-
return o.kind === "action" ? [pad(
|
|
1175
|
+
const port3 = `${i.coord}/${o.name}`;
|
|
1176
|
+
return o.kind === "action" ? [pad(port3, o, "in", "call", o.input), pad(port3, o, "out", "event", o.output)] : [pad(port3, o, "out", "event", o.output)];
|
|
468
1177
|
}));
|
|
469
1178
|
};
|
|
470
1179
|
var gridBoxes = (n) => {
|
|
@@ -480,11 +1189,11 @@ function circuitOf(deployment, registry) {
|
|
|
480
1189
|
const shared = [...count].filter(([, n]) => n > 1).map(([p]) => p);
|
|
481
1190
|
const layers = runtimes.map(([id, r]) => {
|
|
482
1191
|
const grid = gridBoxes(r.pods.length);
|
|
483
|
-
return { screen: id, title: id, system: id, footprints: r.pods.map((
|
|
1192
|
+
return { screen: id, title: id, system: id, footprints: r.pods.map((pod2, i) => ({ system: id, instance: pod2, title: pod2, box: grid[i], shared: shared.includes(pod2), pads: padsOf(`${id}/`, pod2, deployment, registry) })) };
|
|
484
1193
|
});
|
|
485
|
-
const side = shared.map((
|
|
1194
|
+
const side = shared.map((pod2) => ({ system: pod2, items: [{ system: pod2, instance: pod2, title: pod2, pads: padsOf("shared:", pod2, deployment, registry) }] }));
|
|
486
1195
|
const cables = runtimes.flatMap(([id, r]) => r.subscriptions.flatMap((s) => {
|
|
487
|
-
const pads = (
|
|
1196
|
+
const pads = (pod2) => layers.find((l) => l.screen === id).footprints.find((f) => f.instance === pod2).pads;
|
|
488
1197
|
const at = { layer: id };
|
|
489
1198
|
if (s.kind === "call") {
|
|
490
1199
|
const a2 = pads(s.from).find((p) => p.dir === "out") ?? pads(s.from)[0], b2 = pads(s.to).find((p) => p.dir === "in") ?? pads(s.to)[0];
|
|
@@ -493,34 +1202,34 @@ function circuitOf(deployment, registry) {
|
|
|
493
1202
|
const a = pads(s.from).find((p) => p.op === s.source && p.dir === "out"), b = pads(s.to).find((p) => p.op === s.target && p.dir === "in");
|
|
494
1203
|
return a && b ? [{ id: `${id}|${s.from}|${s.to}|${s.target}|${s.source}`, system: id, from: { pad: a.key, at }, to: { pad: b.key, at }, type: a.type }] : [];
|
|
495
1204
|
}));
|
|
496
|
-
for (const
|
|
497
|
-
const sp = side.find((b) => b.system ===
|
|
1205
|
+
for (const pod2 of shared) {
|
|
1206
|
+
const sp = side.find((b) => b.system === pod2).items[0].pads[0];
|
|
498
1207
|
for (const l of layers) {
|
|
499
|
-
const p = l.footprints.find((f) => f.instance ===
|
|
1208
|
+
const p = l.footprints.find((f) => f.instance === pod2)?.pads[0];
|
|
500
1209
|
if (p && sp)
|
|
501
|
-
cables.push({ id: `link|${l.screen}|${
|
|
1210
|
+
cables.push({ id: `link|${l.screen}|${pod2}`, system: pod2, from: { pad: p.key, at: { layer: l.screen } }, to: { pad: sp.key, at: { side: pod2 } }, type: "signal" });
|
|
502
1211
|
}
|
|
503
1212
|
}
|
|
504
1213
|
return { layers, side, cables };
|
|
505
1214
|
}
|
|
506
1215
|
|
|
507
1216
|
// packages/ui/src/wiring/render-pills.ts
|
|
508
|
-
import { html as
|
|
1217
|
+
import { html as html10 } from "lit";
|
|
509
1218
|
function renderPills(el) {
|
|
510
1219
|
const { focus } = el.s;
|
|
511
|
-
return
|
|
1220
|
+
return html10`<nav class="pills" aria-label="Wiring views">
|
|
512
1221
|
<button class="pill" data-whole @click=${() => el.fitAll()}>Whole board</button>
|
|
513
|
-
${el.model.layers.map((l) =>
|
|
1222
|
+
${el.model.layers.map((l) => html10`<button class="pill" data-screen=${l.screen} aria-pressed=${focus === l.screen} @click=${() => el.go(l.screen)}>
|
|
514
1223
|
<span class="ic" aria-hidden="true">${l.title.slice(0, 1).toUpperCase()}</span>${l.title}</button>`)}
|
|
515
1224
|
</nav>`;
|
|
516
1225
|
}
|
|
517
1226
|
|
|
518
1227
|
// packages/ui/src/wiring/render-stage.ts
|
|
519
|
-
import { html as
|
|
1228
|
+
import { html as html12, svg } from "lit";
|
|
520
1229
|
import { styleMap } from "lit/directives/style-map.js";
|
|
521
1230
|
|
|
522
1231
|
// packages/ui/src/wiring/render-drawer.ts
|
|
523
|
-
import { html as
|
|
1232
|
+
import { html as html11, nothing as nothing2 } from "lit";
|
|
524
1233
|
var uniq = (xs) => [...new Set(xs)];
|
|
525
1234
|
function describe(el) {
|
|
526
1235
|
const { sel } = el.s, m = el.model;
|
|
@@ -575,16 +1284,16 @@ function describe(el) {
|
|
|
575
1284
|
}
|
|
576
1285
|
function renderDrawer(el) {
|
|
577
1286
|
const d = describe(el);
|
|
578
|
-
return
|
|
1287
|
+
return html11`<aside class="drawer" aria-label="Details" ?hidden=${!d} @wheel=${(e) => e.stopPropagation()}>${!d ? nothing2 : html11`
|
|
579
1288
|
<div class="d-head"><div><div class="kicker">${d.kicker}</div><div class="d-title">${d.title}</div><div class="d-sub">${d.sub}</div></div>
|
|
580
1289
|
<button aria-label="Close details" @click=${() => {
|
|
581
1290
|
el.select(null);
|
|
582
1291
|
el.refocus();
|
|
583
1292
|
}}>✕</button></div>
|
|
584
|
-
<div class="chips">${d.types.map((t2) =>
|
|
585
|
-
<dl>${d.rows.map(([k, v]) =>
|
|
586
|
-
${d.schemaLabel ?
|
|
587
|
-
${d.follow ?
|
|
1293
|
+
<div class="chips">${d.types.map((t2) => html11`<span class="chip"><span class="glyph" aria-hidden="true" style="background:${TYPE_COLOR[t2]}">${TYPE_GLYPH[t2]}</span>${TYPE_NAME[t2]}</span>`)}</div>
|
|
1294
|
+
<dl>${d.rows.map(([k, v]) => html11`<dt>${k}</dt><dd>${v}</dd>`)}</dl>
|
|
1295
|
+
${d.schemaLabel ? html11`<div class="kicker">${d.schemaLabel}</div><pre>${d.schema === undefined ? "none (signal)" : JSON.stringify(d.schema, null, 2)}</pre>` : nothing2}
|
|
1296
|
+
${d.follow ? html11`<div class="actions"><button @click=${() => el.follow()}>Follow cable</button></div>` : nothing2}`}</aside>`;
|
|
588
1297
|
}
|
|
589
1298
|
|
|
590
1299
|
// packages/ui/src/wiring/render-stage.ts
|
|
@@ -592,14 +1301,14 @@ var px = (r) => ({ left: `${r.x}px`, top: `${r.y}px`, width: `${r.w}px`, height:
|
|
|
592
1301
|
function pad(el, { pad: p, x, y }) {
|
|
593
1302
|
const c = TYPE_COLOR[p.type], out = p.dir === "out";
|
|
594
1303
|
const style = { left: `${x - 12}px`, top: `${y - 12}px`, borderColor: c, background: out ? c : "transparent", color: out ? "#0B0E12" : c, borderRadius: p.kind === "event" ? "50%" : "6px" };
|
|
595
|
-
return
|
|
1304
|
+
return html12`<button class="pad" data-pad=${p.key} data-dir=${p.dir} data-kind=${p.kind} style=${styleMap(style)} title=${p.description ?? ""}
|
|
596
1305
|
aria-label=${`${p.instance}.${p.label}, ${TYPE_NAME[p.type]}, ${p.dir}`}
|
|
597
1306
|
aria-pressed=${el.s.sel === `pad:${p.key}`} @click=${() => el.select(`pad:${p.key}`)}>${TYPE_GLYPH[p.type]}</button>
|
|
598
1307
|
<span class="plabel ${p.dir}" style=${styleMap({ top: `${y - 7}px`, ...out ? { right: `calc(100% - ${x - 18}px)`, textAlign: "right" } : { left: `${x + 18}px` } })}>${p.label}</span>`;
|
|
599
1308
|
}
|
|
600
1309
|
function box(el, b, shared) {
|
|
601
1310
|
const { item } = b, fp = (i) => `fp:${i.system}/${i.instance}`;
|
|
602
|
-
return
|
|
1311
|
+
return html12`<div class="fp" data-instance=${item.instance} data-sel=${el.s.sel === fp(item)} style=${styleMap(px(b.rect))}>
|
|
603
1312
|
<button class="ftitle" @click=${() => el.select(fp(item))}>${item.title}${shared ? " ⧉" : ""}</button>
|
|
604
1313
|
${b.pads.map((p) => pad(el, p))}</div>`;
|
|
605
1314
|
}
|
|
@@ -630,7 +1339,7 @@ function cables(el, f) {
|
|
|
630
1339
|
function minimap(el) {
|
|
631
1340
|
const { bounds: b, layers, blocks } = el.geo, { panX, panY, zoom, focus } = el.s, { w, h } = el.stageSize();
|
|
632
1341
|
const vp = { x: -panX / zoom - w / zoom / 2, y: -panY / zoom - h / zoom / 2, w: w / zoom, h: h / zoom };
|
|
633
|
-
return
|
|
1342
|
+
return html12`<svg class="minimap" role="img" aria-label="Minimap" viewBox=${`${b.x - MARGIN} ${b.y - MARGIN} ${b.w + 2 * MARGIN} ${b.h + 2 * MARGIN}`}
|
|
634
1343
|
@click=${(e) => el.panFromMinimap(e)}>
|
|
635
1344
|
${layers.map((l) => svg`<rect class="mm-layer" data-focus=${l.layer.screen === focus} x=${l.rect.x} y=${l.rect.y} width=${l.rect.w} height=${l.rect.h}/>`)}
|
|
636
1345
|
${blocks.map((l) => svg`<rect class="mm-side" x=${l.rect.x} y=${l.rect.y} width=${l.rect.w} height=${l.rect.h}/>`)}
|
|
@@ -639,26 +1348,26 @@ function minimap(el) {
|
|
|
639
1348
|
function renderStage(el) {
|
|
640
1349
|
const { focus, zoom, panX, panY } = el.s, reduced = el.reduced(), at = el.model.layers.findIndex((l) => l.screen === focus);
|
|
641
1350
|
const world = { transform: `${reduced ? "" : TILT} translate(${panX}px, ${panY}px) scale(${zoom})` };
|
|
642
|
-
return
|
|
1351
|
+
return html12`<div class="stage" tabindex="0" aria-label="Wiring" @pointerdown=${(e) => el.dragStart(e)} @wheel=${(e) => el.wheel(e)}>
|
|
643
1352
|
<div class="world ${el.dragging || reduced ? "" : "anim"}" style=${styleMap(world)}>
|
|
644
1353
|
${el.geo.layers.map((f) => {
|
|
645
1354
|
const d = f.index - at, l = f.layer;
|
|
646
|
-
return
|
|
1355
|
+
return html12`<div class="frame" data-screen=${l.screen} style=${styleMap({ left: `${f.origin.x}px`, top: `${f.origin.y}px`, transform: `translateZ(${-Math.abs(d) * ZGAP}px)` })}>
|
|
647
1356
|
<section class="layer" aria-label=${l.title} data-focus=${d === 0} style=${styleMap({ width: `${PW}px`, height: `${PH}px`, opacity: String(fade(d)) })}>
|
|
648
1357
|
<h3 class="ltitle">${l.title}</h3>
|
|
649
1358
|
${f.boxes.map((b) => box(el, b, "shared" in b.item && b.item.shared))}</section>
|
|
650
1359
|
${cables(el, f)}</div>`;
|
|
651
1360
|
})}
|
|
652
|
-
${el.geo.blocks.map((f) =>
|
|
1361
|
+
${el.geo.blocks.map((f) => html12`<div class="frame side" data-system=${f.block.system} style=${styleMap({ left: `${f.origin.x}px`, top: `${f.origin.y}px` })}>
|
|
653
1362
|
<h3 class="ltitle">${f.block.system}</h3>${f.boxes.map((b) => box(el, b, false))}${cables(el, f)}</div>`)}
|
|
654
1363
|
</div>
|
|
655
1364
|
${minimap(el)}${renderDrawer(el)}</div>`;
|
|
656
1365
|
}
|
|
657
1366
|
|
|
658
1367
|
// packages/ui/src/wiring/styles.ts
|
|
659
|
-
import { css as
|
|
1368
|
+
import { css as css4 } from "lit";
|
|
660
1369
|
import { base as base4, t as t2 } from "@pritzlaff/nano-elements";
|
|
661
|
-
var styles = [base4,
|
|
1370
|
+
var styles = [base4, css4`
|
|
662
1371
|
:host { display: block; height: 100%; min-height: 360px; color: ${t2("fg")} }
|
|
663
1372
|
.pills { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px; background: ${t2("bg")} }
|
|
664
1373
|
.ic { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; background: ${t2("surface-2")}; font-size: 10px }
|
|
@@ -694,7 +1403,7 @@ var styles = [base4, css2`
|
|
|
694
1403
|
// packages/ui/src/wiring/wiring.ts
|
|
695
1404
|
var clamp = (z) => Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, z));
|
|
696
1405
|
|
|
697
|
-
class NanoWiring extends
|
|
1406
|
+
class NanoWiring extends LitElement4 {
|
|
698
1407
|
static properties = { target: { attribute: false } };
|
|
699
1408
|
static styles = styles;
|
|
700
1409
|
s = { focus: null, zoom: 1, panX: 0, panY: 0, sel: null };
|
|
@@ -734,7 +1443,7 @@ class NanoWiring extends LitElement3 {
|
|
|
734
1443
|
this.off = t3.app.listen((e) => {
|
|
735
1444
|
if (e.type === "applied")
|
|
736
1445
|
this.load(t3);
|
|
737
|
-
else if (e.type === "sent")
|
|
1446
|
+
else if (e.type === "sent" && e.kind !== "start")
|
|
738
1447
|
this.light(e.kind === "call" ? `${e.runtime}|${e.from}|${e.to}|call|` : `${e.runtime}|${e.from}|${e.to}|${e.port}|`);
|
|
739
1448
|
});
|
|
740
1449
|
this.load(t3);
|
|
@@ -872,10 +1581,10 @@ class NanoWiring extends LitElement3 {
|
|
|
872
1581
|
}
|
|
873
1582
|
|
|
874
1583
|
// packages/ui/src/views/pod-view.ts
|
|
875
|
-
import { css as
|
|
1584
|
+
import { css as css5, html as html13 } from "lit";
|
|
876
1585
|
import { base as base5, t as t3 } from "@pritzlaff/nano-elements";
|
|
877
1586
|
class NanoPodView extends ViewElement {
|
|
878
|
-
static styles = [base5,
|
|
1587
|
+
static styles = [base5, css5`
|
|
879
1588
|
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px }
|
|
880
1589
|
dt { color: ${t3("muted")} } dd { margin: 0; font-family: ${t3("font-mono")} }
|
|
881
1590
|
table { width: 100%; border-collapse: collapse } td { padding: 3px 6px; border-top: 1px solid ${t3("border")} }
|
|
@@ -889,7 +1598,7 @@ class NanoPodView extends ViewElement {
|
|
|
889
1598
|
this.requestUpdate();
|
|
890
1599
|
}
|
|
891
1600
|
hear(e, tg) {
|
|
892
|
-
if (e.type === "sent" && e.to === tg.pod) {
|
|
1601
|
+
if (e.type === "sent" && e.kind !== "start" && e.to === tg.pod) {
|
|
893
1602
|
this.ports.set(e.id, e.port);
|
|
894
1603
|
const s = this.stats.get(e.port) ?? { calls: 0 };
|
|
895
1604
|
this.stats.set(e.port, { ...s, calls: s.calls + 1 });
|
|
@@ -904,55 +1613,944 @@ class NanoPodView extends ViewElement {
|
|
|
904
1613
|
}
|
|
905
1614
|
face(tg) {
|
|
906
1615
|
const d = tg.app.deployment();
|
|
907
|
-
const
|
|
1616
|
+
const pod2 = d.pods[tg.pod];
|
|
908
1617
|
const runtimes = Object.entries(d.runtimes).filter(([, r]) => r.pods.includes(tg.pod)).map(([id]) => id);
|
|
909
|
-
const provides = tg.registry.implementation(
|
|
910
|
-
return
|
|
1618
|
+
const provides = tg.registry.implementation(pod2?.implementation ?? "")?.provides ?? [];
|
|
1619
|
+
return html13`
|
|
911
1620
|
<dl>
|
|
912
1621
|
<dt>pod</dt><dd>${tg.pod}</dd>
|
|
913
|
-
<dt>implementation</dt><dd>${
|
|
914
|
-
<dt>config</dt><dd>${JSON.stringify(
|
|
1622
|
+
<dt>implementation</dt><dd>${pod2?.implementation ?? "—"}</dd>
|
|
1623
|
+
<dt>config</dt><dd>${JSON.stringify(pod2?.config ?? null)}</dd>
|
|
915
1624
|
<dt>runtimes</dt><dd>${runtimes.join(", ") || "—"}</dd>
|
|
916
1625
|
</dl>
|
|
917
|
-
${provides.map((i) =>
|
|
1626
|
+
${provides.map((i) => html13`
|
|
918
1627
|
<div class="iface">${i.coord}</div>
|
|
919
1628
|
<table>${Object.values(i.ops).map((o) => {
|
|
920
1629
|
const p = `${i.coord}/${o.name}`, s = this.stats.get(p);
|
|
921
|
-
return
|
|
1630
|
+
return html13`<tr data-port=${p}><td>${o.name}</td><td class="badge">${o.kind}</td>
|
|
922
1631
|
<td>${s?.calls ?? 0} calls</td><td>${shown(s?.last)}</td></tr>`;
|
|
923
1632
|
})}</table>`)}`;
|
|
924
1633
|
}
|
|
925
1634
|
}
|
|
926
1635
|
|
|
1636
|
+
// packages/ui/src/observe/bar.ts
|
|
1637
|
+
import { LitElement as LitElement5, css as css6, html as html14 } from "lit";
|
|
1638
|
+
|
|
1639
|
+
// packages/ui/src/observe/replay.ts
|
|
1640
|
+
import { failure as failure2, success as success8 } from "@pritzlaff/nano-core";
|
|
1641
|
+
|
|
1642
|
+
// packages/ui/src/observe/in-flight.ts
|
|
1643
|
+
var wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1644
|
+
var QUIET_MS = 31000;
|
|
1645
|
+
function inFlight(app) {
|
|
1646
|
+
const open = new Set;
|
|
1647
|
+
let wake = () => {};
|
|
1648
|
+
const stop = app.listen((e) => {
|
|
1649
|
+
if (e.type === "sent")
|
|
1650
|
+
open.add(e.id);
|
|
1651
|
+
else if ((e.type === "delivered" || e.type === "denied") && open.delete(e.id) && !open.size)
|
|
1652
|
+
wake();
|
|
1653
|
+
});
|
|
1654
|
+
const quiet = async () => {
|
|
1655
|
+
const end = Date.now() + QUIET_MS;
|
|
1656
|
+
for (;; ) {
|
|
1657
|
+
while (open.size) {
|
|
1658
|
+
if (Date.now() >= end)
|
|
1659
|
+
return false;
|
|
1660
|
+
let timer;
|
|
1661
|
+
await new Promise((r) => {
|
|
1662
|
+
wake = r;
|
|
1663
|
+
timer = setTimeout(r, end - Date.now());
|
|
1664
|
+
});
|
|
1665
|
+
clearTimeout(timer);
|
|
1666
|
+
}
|
|
1667
|
+
await wait(0);
|
|
1668
|
+
if (!open.size)
|
|
1669
|
+
return true;
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
return { quiet, stop };
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// packages/ui/src/observe/restart-order.ts
|
|
1676
|
+
import { lookup } from "@pritzlaff/nano-core";
|
|
1677
|
+
function restartOrder(d) {
|
|
1678
|
+
const calls = lookup(d).callsFrom, out = [], seen = new Set;
|
|
1679
|
+
const visit = (pod2) => {
|
|
1680
|
+
if (seen.has(pod2) || !(pod2 in d.pods))
|
|
1681
|
+
return;
|
|
1682
|
+
seen.add(pod2);
|
|
1683
|
+
for (const { to } of calls.get(pod2) ?? [])
|
|
1684
|
+
visit(to);
|
|
1685
|
+
out.push(pod2);
|
|
1686
|
+
};
|
|
1687
|
+
Object.keys(d.pods).forEach(visit);
|
|
1688
|
+
return out;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// packages/ui/src/observe/entry.ts
|
|
1692
|
+
var CAP = 65536;
|
|
1693
|
+
var MARK = "…truncated";
|
|
1694
|
+
function snap(v) {
|
|
1695
|
+
const stack = [];
|
|
1696
|
+
let text;
|
|
1697
|
+
try {
|
|
1698
|
+
text = String(JSON.stringify(v, function(_k, x) {
|
|
1699
|
+
if (typeof x === "bigint")
|
|
1700
|
+
return `${x}n`;
|
|
1701
|
+
if (typeof x === "function")
|
|
1702
|
+
return "[function]";
|
|
1703
|
+
if (x !== null && typeof x === "object") {
|
|
1704
|
+
while (stack.length && stack[stack.length - 1] !== this)
|
|
1705
|
+
stack.pop();
|
|
1706
|
+
if (stack.includes(x))
|
|
1707
|
+
return "[cycle]";
|
|
1708
|
+
stack.push(x);
|
|
1709
|
+
}
|
|
1710
|
+
return x;
|
|
1711
|
+
}));
|
|
1712
|
+
} catch {
|
|
1713
|
+
text = '"[unserializable]"';
|
|
1714
|
+
}
|
|
1715
|
+
return text.length > CAP ? text.slice(0, CAP) + MARK : text;
|
|
1716
|
+
}
|
|
1717
|
+
var truncated = (text) => text.endsWith(MARK);
|
|
1718
|
+
function pair(entries) {
|
|
1719
|
+
const byId = new Map;
|
|
1720
|
+
const out = [];
|
|
1721
|
+
for (const { seq, at, event } of entries) {
|
|
1722
|
+
if (event.type === "sent") {
|
|
1723
|
+
const m = { seq, at, sent: event };
|
|
1724
|
+
byId.set(event.id, m);
|
|
1725
|
+
out.push(m);
|
|
1726
|
+
} else if (event.type === "delivered" || event.type === "denied") {
|
|
1727
|
+
const m = byId.get(event.id);
|
|
1728
|
+
if (m)
|
|
1729
|
+
m.outcome = event;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
return out;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// packages/ui/src/observe/replay.ts
|
|
1736
|
+
async function cleanStart(store) {
|
|
1737
|
+
await store.flush();
|
|
1738
|
+
const [start] = await store.range(undefined, undefined, 1);
|
|
1739
|
+
return start?.event.type === "deployment" && start.event.clean ? start : undefined;
|
|
1740
|
+
}
|
|
1741
|
+
var roots = (messages) => messages.filter((m) => m.sent.from === "host" && (m.sent.kind === "call" || m.sent.kind === "start") && m.sent.cause === undefined);
|
|
1742
|
+
var wait2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1743
|
+
async function replay(app, store, opts = {}) {
|
|
1744
|
+
const start = await cleanStart(store);
|
|
1745
|
+
if (!start)
|
|
1746
|
+
return failure2("not-found", "the recording no longer holds a clean start");
|
|
1747
|
+
const entries = await store.range(start.seq, opts.to);
|
|
1748
|
+
if (!entries.length)
|
|
1749
|
+
return failure2("not-found", `the recording starts after ${opts.to}`);
|
|
1750
|
+
const sends = new Map(roots(pair(entries)).map((m) => [m.seq, m]));
|
|
1751
|
+
const cut = [...sends.values()].find((m) => m.sent.input !== undefined && truncated(m.sent.input));
|
|
1752
|
+
if (cut)
|
|
1753
|
+
return failure2("invalid-input", `message ${cut.seq}: its input was truncated when recorded`);
|
|
1754
|
+
const inputs = entries.filter((e) => sends.has(e.seq) || e.event.type === "restarted" || e.event.type === "deployment" && e !== start && (e.event.caller ?? "host") === "host");
|
|
1755
|
+
const flight = opts.pace === "fast" ? inFlight(app) : undefined;
|
|
1756
|
+
try {
|
|
1757
|
+
const reset = await app.apply(start.event.deployment);
|
|
1758
|
+
if (!reset.ok)
|
|
1759
|
+
return reset;
|
|
1760
|
+
for (const pod2 of restartOrder(start.event.deployment)) {
|
|
1761
|
+
const r = await app.restart(pod2);
|
|
1762
|
+
if (!r.ok)
|
|
1763
|
+
return r;
|
|
1764
|
+
}
|
|
1765
|
+
const now = opts.now ?? Date.now, sleep = opts.sleep ?? wait2, began = now();
|
|
1766
|
+
const n = { sent: 0, failed: 0, applied: 0, restarted: 0, from: start.seq, to: entries.at(-1).seq };
|
|
1767
|
+
const settled = new Map(entries.flatMap((e) => e.event.type === "delivered" || e.event.type === "denied" ? [[e.event.id, e.seq]] : []));
|
|
1768
|
+
const calls = [];
|
|
1769
|
+
for (const { seq, at, event } of inputs) {
|
|
1770
|
+
if (flight) {
|
|
1771
|
+
if (!await flight.quiet())
|
|
1772
|
+
n.failed++;
|
|
1773
|
+
} else
|
|
1774
|
+
await sleep(Math.max(at - start.at - (now() - began), 0));
|
|
1775
|
+
await Promise.all(calls.filter((c) => c.settled < seq).map((c) => c.done));
|
|
1776
|
+
if (event.type === "deployment" || event.type === "restarted") {
|
|
1777
|
+
const r = event.type === "deployment" ? await app.apply(event.deployment) : await app.restart(event.pod);
|
|
1778
|
+
if (!r.ok) {
|
|
1779
|
+
await Promise.all(calls.map((c) => c.done));
|
|
1780
|
+
return r;
|
|
1781
|
+
}
|
|
1782
|
+
n[event.type === "deployment" ? "applied" : "restarted"]++;
|
|
1783
|
+
continue;
|
|
1784
|
+
}
|
|
1785
|
+
const { sent } = sends.get(seq);
|
|
1786
|
+
const input2 = sent.input === undefined || sent.input === "undefined" ? undefined : JSON.parse(sent.input);
|
|
1787
|
+
const port3 = sent.port ?? "", op3 = port3.slice(port3.lastIndexOf("/") + 1);
|
|
1788
|
+
n.sent++;
|
|
1789
|
+
const rt = app.runtime(sent.runtime);
|
|
1790
|
+
const done = Promise.resolve().then(() => sent.kind === "start" ? rt.start(sent.to) : rt.call(sent.to)[op3](input2)).then((r) => {
|
|
1791
|
+
if (!r.ok)
|
|
1792
|
+
n.failed++;
|
|
1793
|
+
}, () => {
|
|
1794
|
+
n.failed++;
|
|
1795
|
+
});
|
|
1796
|
+
calls.push({ settled: settled.get(sent.id) ?? Infinity, done });
|
|
1797
|
+
}
|
|
1798
|
+
await Promise.all(calls.map((c) => c.done));
|
|
1799
|
+
if (flight && !await flight.quiet())
|
|
1800
|
+
n.failed++;
|
|
1801
|
+
return success8(n);
|
|
1802
|
+
} finally {
|
|
1803
|
+
flight?.stop();
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
var same = (m) => JSON.stringify([
|
|
1807
|
+
m.sent.kind,
|
|
1808
|
+
m.sent.from,
|
|
1809
|
+
m.sent.to,
|
|
1810
|
+
m.sent.port,
|
|
1811
|
+
m.sent.input,
|
|
1812
|
+
m.outcome?.type,
|
|
1813
|
+
m.outcome?.type === "delivered" ? [m.outcome.ok, m.outcome.result] : undefined
|
|
1814
|
+
]);
|
|
1815
|
+
function diverge(recorded, replayed) {
|
|
1816
|
+
const msgs = (ms) => ms.filter((m) => m.sent.kind !== "subscribe" && m.sent.kind !== "unsubscribe");
|
|
1817
|
+
const a = msgs(recorded), b = msgs(replayed);
|
|
1818
|
+
for (let i = 0;i < Math.max(a.length, b.length); i++)
|
|
1819
|
+
if (!a[i] || !b[i] || same(a[i]) !== same(b[i]))
|
|
1820
|
+
return { index: i, recorded: a[i], replayed: b[i] };
|
|
1821
|
+
return null;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// packages/ui/src/observe/time-machine.ts
|
|
1825
|
+
var IDLE = 1000;
|
|
1826
|
+
var SPEEDS = [1 / 30, 1 / 10, 1 / 4, 1 / 2, 1, 2];
|
|
1827
|
+
var raf = { now: () => Date.now(), frame: (fn) => {
|
|
1828
|
+
const id = requestAnimationFrame(fn);
|
|
1829
|
+
return () => cancelAnimationFrame(id);
|
|
1830
|
+
} };
|
|
1831
|
+
async function timeMachine(source, opts = {}) {
|
|
1832
|
+
const ticker = opts.ticker ?? raf, keep = opts.recent ?? 200, travelMs = opts.travelMs ?? 600;
|
|
1833
|
+
const msgs = [];
|
|
1834
|
+
const byId = new Map;
|
|
1835
|
+
const span = { from: 0, to: 0 };
|
|
1836
|
+
let empty = true, lastSeq = 0;
|
|
1837
|
+
let mode = "live", speed = 1, cursor = 0;
|
|
1838
|
+
let pinned;
|
|
1839
|
+
let cancel, last = 0;
|
|
1840
|
+
const subs = new Set;
|
|
1841
|
+
const upTo = (t4) => {
|
|
1842
|
+
let lo = 0, hi = msgs.length;
|
|
1843
|
+
while (lo < hi) {
|
|
1844
|
+
const mid = lo + hi >> 1;
|
|
1845
|
+
if (msgs[mid].at <= t4)
|
|
1846
|
+
lo = mid + 1;
|
|
1847
|
+
else
|
|
1848
|
+
hi = mid;
|
|
1849
|
+
}
|
|
1850
|
+
return lo;
|
|
1851
|
+
};
|
|
1852
|
+
const inFlightAt = (t4) => {
|
|
1853
|
+
const out = [];
|
|
1854
|
+
for (let i = upTo(t4) - 1;i >= 0 && msgs[i].at >= t4 - travelMs; i--)
|
|
1855
|
+
out.unshift({ message: msgs[i], progress: (t4 - msgs[i].at) / travelMs });
|
|
1856
|
+
return out;
|
|
1857
|
+
};
|
|
1858
|
+
const frame = () => {
|
|
1859
|
+
const end = pinned !== undefined ? pinned + 1 : upTo(cursor);
|
|
1860
|
+
return { t: cursor, inFlight: inFlightAt(cursor), recent: msgs.slice(Math.max(0, end - keep), end), ...end ? { at: msgs[end - 1] } : {} };
|
|
1861
|
+
};
|
|
1862
|
+
const emit = () => {
|
|
1863
|
+
const f = frame();
|
|
1864
|
+
for (const fn of subs)
|
|
1865
|
+
try {
|
|
1866
|
+
fn(f);
|
|
1867
|
+
} catch {}
|
|
1868
|
+
};
|
|
1869
|
+
const add = (e) => {
|
|
1870
|
+
if (e.seq <= lastSeq)
|
|
1871
|
+
return;
|
|
1872
|
+
lastSeq = e.seq;
|
|
1873
|
+
if (empty) {
|
|
1874
|
+
span.from = e.at;
|
|
1875
|
+
empty = false;
|
|
1876
|
+
}
|
|
1877
|
+
span.to = Math.max(span.to, e.at);
|
|
1878
|
+
const ev = e.event;
|
|
1879
|
+
if (ev.type === "sent") {
|
|
1880
|
+
const m = { seq: e.seq, at: e.at, sent: ev };
|
|
1881
|
+
byId.set(ev.id, m);
|
|
1882
|
+
msgs.splice(upTo(e.at), 0, m);
|
|
1883
|
+
} else if (ev.type === "delivered" || ev.type === "denied") {
|
|
1884
|
+
const m = byId.get(ev.id);
|
|
1885
|
+
if (m)
|
|
1886
|
+
m.outcome = ev;
|
|
1887
|
+
}
|
|
1888
|
+
};
|
|
1889
|
+
const stopTicking = () => {
|
|
1890
|
+
cancel?.();
|
|
1891
|
+
cancel = undefined;
|
|
1892
|
+
};
|
|
1893
|
+
const liveFrame = () => {
|
|
1894
|
+
emit();
|
|
1895
|
+
if (!cancel && inFlightAt(cursor).length)
|
|
1896
|
+
cancel = ticker.frame(tick);
|
|
1897
|
+
};
|
|
1898
|
+
const goLive = () => {
|
|
1899
|
+
stopTicking();
|
|
1900
|
+
mode = "live";
|
|
1901
|
+
pinned = undefined;
|
|
1902
|
+
cursor = span.to;
|
|
1903
|
+
liveFrame();
|
|
1904
|
+
};
|
|
1905
|
+
const tick = () => {
|
|
1906
|
+
cancel = undefined;
|
|
1907
|
+
const now = ticker.now();
|
|
1908
|
+
if (mode === "live") {
|
|
1909
|
+
cursor = Math.max(now, span.to);
|
|
1910
|
+
return liveFrame();
|
|
1911
|
+
}
|
|
1912
|
+
let c = cursor + (now - last) * speed;
|
|
1913
|
+
last = now;
|
|
1914
|
+
const target = msgs[upTo(cursor)]?.at ?? span.to;
|
|
1915
|
+
if (inFlightAt(c).length === 0 && target - c > IDLE)
|
|
1916
|
+
c = target;
|
|
1917
|
+
if (c >= span.to)
|
|
1918
|
+
return goLive();
|
|
1919
|
+
cursor = c;
|
|
1920
|
+
pinned = undefined;
|
|
1921
|
+
emit();
|
|
1922
|
+
cancel = ticker.frame(tick);
|
|
1923
|
+
};
|
|
1924
|
+
let held = [];
|
|
1925
|
+
const unlisten = source.listen((e) => {
|
|
1926
|
+
if (held) {
|
|
1927
|
+
held.push(e);
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
add(e);
|
|
1931
|
+
if (mode === "live") {
|
|
1932
|
+
cursor = Math.max(cursor, span.to);
|
|
1933
|
+
liveFrame();
|
|
1934
|
+
}
|
|
1935
|
+
});
|
|
1936
|
+
try {
|
|
1937
|
+
for (const e of await source.store.range())
|
|
1938
|
+
add(e);
|
|
1939
|
+
} catch (err) {
|
|
1940
|
+
unlisten();
|
|
1941
|
+
throw err;
|
|
1942
|
+
}
|
|
1943
|
+
for (const e of held)
|
|
1944
|
+
add(e);
|
|
1945
|
+
held = undefined;
|
|
1946
|
+
cursor = span.to;
|
|
1947
|
+
liveFrame();
|
|
1948
|
+
return {
|
|
1949
|
+
get cursor() {
|
|
1950
|
+
return cursor;
|
|
1951
|
+
},
|
|
1952
|
+
get mode() {
|
|
1953
|
+
return mode;
|
|
1954
|
+
},
|
|
1955
|
+
get speed() {
|
|
1956
|
+
return speed;
|
|
1957
|
+
},
|
|
1958
|
+
get span() {
|
|
1959
|
+
return { ...span };
|
|
1960
|
+
},
|
|
1961
|
+
seek(t4) {
|
|
1962
|
+
stopTicking();
|
|
1963
|
+
mode = "paused";
|
|
1964
|
+
pinned = undefined;
|
|
1965
|
+
cursor = t4;
|
|
1966
|
+
emit();
|
|
1967
|
+
},
|
|
1968
|
+
step(dir) {
|
|
1969
|
+
stopTicking();
|
|
1970
|
+
mode = "paused";
|
|
1971
|
+
const i = (pinned ?? upTo(cursor) - 1) + dir;
|
|
1972
|
+
if (i >= 0 && i < msgs.length) {
|
|
1973
|
+
pinned = i;
|
|
1974
|
+
cursor = msgs[i].at;
|
|
1975
|
+
}
|
|
1976
|
+
emit();
|
|
1977
|
+
},
|
|
1978
|
+
play() {
|
|
1979
|
+
if (mode === "playing")
|
|
1980
|
+
return;
|
|
1981
|
+
if (cursor >= span.to)
|
|
1982
|
+
return goLive();
|
|
1983
|
+
mode = "playing";
|
|
1984
|
+
last = ticker.now();
|
|
1985
|
+
cancel = ticker.frame(tick);
|
|
1986
|
+
},
|
|
1987
|
+
pause() {
|
|
1988
|
+
stopTicking();
|
|
1989
|
+
mode = "paused";
|
|
1990
|
+
emit();
|
|
1991
|
+
},
|
|
1992
|
+
live: goLive,
|
|
1993
|
+
setSpeed(s) {
|
|
1994
|
+
const known = SPEEDS.find((x) => Math.abs(x - s) < 0.000000001);
|
|
1995
|
+
if (known === undefined)
|
|
1996
|
+
throw new RangeError(`speed ${s} is not one of 1/30, 1/10, 1/4, 1/2, 1, 2`);
|
|
1997
|
+
speed = known;
|
|
1998
|
+
emit();
|
|
1999
|
+
},
|
|
2000
|
+
subscribe(fn) {
|
|
2001
|
+
subs.add(fn);
|
|
2002
|
+
return () => {
|
|
2003
|
+
subs.delete(fn);
|
|
2004
|
+
};
|
|
2005
|
+
},
|
|
2006
|
+
close() {
|
|
2007
|
+
stopTicking();
|
|
2008
|
+
unlisten();
|
|
2009
|
+
subs.clear();
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
// packages/ui/src/observe/bar.ts
|
|
2015
|
+
var label2 = (s) => (s < 1 ? `1/${Math.round(1 / s)}` : String(s)) + "×";
|
|
2016
|
+
|
|
2017
|
+
class NanoTimeMachine extends LitElement5 {
|
|
2018
|
+
static properties = { tm: { attribute: false }, store: { attribute: false }, driver: { attribute: false }, tooLong: { state: true } };
|
|
2019
|
+
static styles = css6`
|
|
2020
|
+
:host { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; color: #E6EDF3; font: 12px system-ui, sans-serif; background: #0B0E12 }
|
|
2021
|
+
button, select { padding: 4px 10px; border: 1px solid #2A323D; border-radius: 999px; background: #12161C; color: inherit; font: inherit; cursor: pointer }
|
|
2022
|
+
button[aria-pressed="true"] { border-color: #4CC2FF; color: #4CC2FF }
|
|
2023
|
+
input[type=range] { flex: 1 1 160px; min-width: 0; accent-color: #4CC2FF }
|
|
2024
|
+
small { color: #94a3b8 } small.warn { color: #fbbf24 }`;
|
|
2025
|
+
off;
|
|
2026
|
+
clean;
|
|
2027
|
+
constructor() {
|
|
2028
|
+
super();
|
|
2029
|
+
this.tooLong = false;
|
|
2030
|
+
}
|
|
2031
|
+
connectedCallback() {
|
|
2032
|
+
super.connectedCallback();
|
|
2033
|
+
this.watch();
|
|
2034
|
+
}
|
|
2035
|
+
disconnectedCallback() {
|
|
2036
|
+
super.disconnectedCallback();
|
|
2037
|
+
this.off?.();
|
|
2038
|
+
this.off = undefined;
|
|
2039
|
+
}
|
|
2040
|
+
willUpdate(changed) {
|
|
2041
|
+
if (changed.has("tm") || changed.has("store")) {
|
|
2042
|
+
this.tooLong = false;
|
|
2043
|
+
this.clean = undefined;
|
|
2044
|
+
this.watch();
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
watch() {
|
|
2048
|
+
this.off?.();
|
|
2049
|
+
this.off = this.isConnected ? this.tm?.subscribe(() => {
|
|
2050
|
+
this.requestUpdate();
|
|
2051
|
+
this.check();
|
|
2052
|
+
}) : undefined;
|
|
2053
|
+
this.check();
|
|
2054
|
+
}
|
|
2055
|
+
async check() {
|
|
2056
|
+
const store = this.store;
|
|
2057
|
+
if (!store || this.tooLong)
|
|
2058
|
+
return;
|
|
2059
|
+
const oldest = await store.oldest();
|
|
2060
|
+
if (oldest === this.clean)
|
|
2061
|
+
return;
|
|
2062
|
+
const start = await cleanStart(store);
|
|
2063
|
+
if (store !== this.store)
|
|
2064
|
+
return;
|
|
2065
|
+
this.clean = start?.seq;
|
|
2066
|
+
this.tooLong = !start;
|
|
2067
|
+
}
|
|
2068
|
+
act(fn) {
|
|
2069
|
+
return () => {
|
|
2070
|
+
if (this.tm) {
|
|
2071
|
+
fn(this.tm);
|
|
2072
|
+
this.requestUpdate();
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
render() {
|
|
2077
|
+
const tm = this.tm;
|
|
2078
|
+
if (!tm)
|
|
2079
|
+
return html14``;
|
|
2080
|
+
const playing = tm.mode === "playing", span = tm.span, reason = this.driver?.reason;
|
|
2081
|
+
return html14`
|
|
2082
|
+
<button aria-label=${playing ? "Pause" : "Play"} @click=${this.act((t4) => playing ? t4.pause() : t4.play())}>${playing ? "❚❚" : "▶"}</button>
|
|
2083
|
+
<button aria-label="Step back" @click=${this.act((t4) => t4.step(-1))}>◀|</button>
|
|
2084
|
+
<button aria-label="Step forward" @click=${this.act((t4) => t4.step(1))}>|▶</button>
|
|
2085
|
+
<input type="range" aria-label="Time" min=${span.from} max=${span.to} step="1" .value=${String(Math.min(tm.cursor, span.to))}
|
|
2086
|
+
@input=${(e) => this.act((t4) => t4.seek(Number(e.target.value)))()}>
|
|
2087
|
+
<select aria-label="Speed" @change=${(e) => this.act((t4) => t4.setSpeed(Number(e.target.value)))()}>
|
|
2088
|
+
${SPEEDS.map((s) => html14`<option value=${String(s)} ?selected=${s === tm.speed}>${label2(s)}</option>`)}</select>
|
|
2089
|
+
<button aria-label="Live" aria-pressed=${tm.mode === "live"} @click=${this.act((t4) => t4.live())}>Live</button>
|
|
2090
|
+
<button aria-label="Reset" @click=${() => this.dispatchEvent(new CustomEvent("reset", { bubbles: true, composed: true }))}>Reset</button>
|
|
2091
|
+
${this.tooLong ? html14`<small class="warn">history too long to rebuild state</small>` : ""}
|
|
2092
|
+
${reason ? html14`<small>${reason}</small>` : ""}`;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
// packages/ui/src/observe/ring-view.ts
|
|
2097
|
+
import { LitElement as LitElement6, css as css7, html as html15, svg as svg2 } from "lit";
|
|
2098
|
+
import { t as t4, tv } from "@pritzlaff/nano-elements";
|
|
2099
|
+
|
|
2100
|
+
// packages/ui/src/observe/ring.ts
|
|
2101
|
+
var placedIn = (d, pod2) => Object.keys(d.runtimes).filter((r) => d.runtimes[r].pods.includes(pod2));
|
|
2102
|
+
var around = (o, n) => Array.from({ length: n }, (_, i) => n === 1 ? { x: o.x, y: o.y } : { x: o.x + o.r * Math.cos(2 * Math.PI * i / n - Math.PI / 2), y: o.y + o.r * Math.sin(2 * Math.PI * i / n - Math.PI / 2) });
|
|
2103
|
+
function ringLayout(d, opts) {
|
|
2104
|
+
const { size } = opts, c = size / 2, ids = Object.keys(d.runtimes), one = ids.length === 1;
|
|
2105
|
+
const ring = one ? 0 : 0.36 * size, r = one ? 0.38 * size : Math.min(0.12 * size, ring * Math.sin(Math.PI / ids.length) * 0.9);
|
|
2106
|
+
const runtimes = around({ x: c, y: c, r: ring }, ids.length).map((p, i) => ({ id: ids[i], ...p, r }));
|
|
2107
|
+
const shown2 = (p) => !opts.show || opts.show(p, d.pods[p].implementation);
|
|
2108
|
+
const own = runtimes.flatMap((rt) => {
|
|
2109
|
+
const ps = d.runtimes[rt.id].pods.filter((p) => d.pods[p] && placedIn(d, p).length === 1 && shown2(p));
|
|
2110
|
+
return around(rt, ps.length).map((xy, i) => ({ pod: ps[i], runtime: rt.id, ...xy }));
|
|
2111
|
+
});
|
|
2112
|
+
const shared = Object.keys(d.pods).filter((p) => placedIn(d, p).length > 1 && shown2(p));
|
|
2113
|
+
return { runtimes, pods: [...own, ...around({ x: c, y: c, r: 0.1 * size }, shared.length).map((xy, i) => ({ pod: shared[i], runtime: null, ...xy }))] };
|
|
2114
|
+
}
|
|
2115
|
+
function placeOf(l, d, pod2, runtime2) {
|
|
2116
|
+
const own = l.pods.find((p) => p.pod === pod2);
|
|
2117
|
+
if (own)
|
|
2118
|
+
return own;
|
|
2119
|
+
const places = placedIn(d, pod2), rt = places.includes(runtime2) ? runtime2 : places[0];
|
|
2120
|
+
return l.runtimes.find((r) => r.id === rt);
|
|
2121
|
+
}
|
|
2122
|
+
function ringDot(l, d, m, progress) {
|
|
2123
|
+
const a = placeOf(l, d, m.sent.from, m.sent.runtime), b = placeOf(l, d, m.sent.to, m.sent.runtime);
|
|
2124
|
+
return a && b ? { x: a.x + (b.x - a.x) * progress, y: a.y + (b.y - a.y) * progress } : undefined;
|
|
2125
|
+
}
|
|
2126
|
+
function ringSource(mode, atNewest, rebuildable) {
|
|
2127
|
+
return mode === "live" || atNewest ? "live" : rebuildable ? "past" : "too-long";
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
// packages/ui/src/observe/shadow.ts
|
|
2131
|
+
import { failure as failure3 } from "@pritzlaff/nano-core";
|
|
2132
|
+
|
|
2133
|
+
// packages/ui/src/observe/memory-store.ts
|
|
2134
|
+
function memoryStore(opts = {}) {
|
|
2135
|
+
const max = opts.max ?? 1e5;
|
|
2136
|
+
let all = [];
|
|
2137
|
+
return {
|
|
2138
|
+
append(e) {
|
|
2139
|
+
all.push(e);
|
|
2140
|
+
if (all.length > max)
|
|
2141
|
+
all.shift();
|
|
2142
|
+
},
|
|
2143
|
+
flush: async () => {},
|
|
2144
|
+
range: async (from = -Infinity, to = Infinity, limit = Infinity) => limit <= 0 ? [] : all.filter((e) => e.seq >= from && e.seq <= to).slice(0, limit),
|
|
2145
|
+
search: async (text, limit = Infinity) => {
|
|
2146
|
+
const t4 = text.toLowerCase();
|
|
2147
|
+
return limit <= 0 ? [] : all.filter((e) => JSON.stringify(e.event).toLowerCase().includes(t4)).slice(-limit);
|
|
2148
|
+
},
|
|
2149
|
+
oldest: async () => all[0]?.seq,
|
|
2150
|
+
size: async () => all.length,
|
|
2151
|
+
clear: async () => {
|
|
2152
|
+
all = [];
|
|
2153
|
+
}
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
// packages/ui/src/observe/shadow.ts
|
|
2158
|
+
function without(d, host) {
|
|
2159
|
+
const out = structuredClone(d);
|
|
2160
|
+
delete out.pods[host];
|
|
2161
|
+
delete out.tags?.[host];
|
|
2162
|
+
for (const r of Object.values(out.runtimes)) {
|
|
2163
|
+
r.pods = r.pods.filter((p) => p !== host);
|
|
2164
|
+
r.subscriptions = r.subscriptions.filter((s) => s.from !== host && s.to !== host);
|
|
2165
|
+
}
|
|
2166
|
+
return out;
|
|
2167
|
+
}
|
|
2168
|
+
async function shadowAt(store, t4, create, opts = {}) {
|
|
2169
|
+
const host = opts.host ?? "ui";
|
|
2170
|
+
const start = await cleanStart(store);
|
|
2171
|
+
if (!start)
|
|
2172
|
+
return failure3("not-found", "the recording no longer holds a clean start");
|
|
2173
|
+
const all = await store.range(), last = all.findLast((e) => e.at <= t4);
|
|
2174
|
+
if (!last)
|
|
2175
|
+
return failure3("not-found", `the recording starts after ${t4}`);
|
|
2176
|
+
const copy = memoryStore({ max: Infinity }), dropped = new Set;
|
|
2177
|
+
for (const e of all) {
|
|
2178
|
+
if (e.seq > last.seq)
|
|
2179
|
+
break;
|
|
2180
|
+
const kept = shadowed(e, host, dropped);
|
|
2181
|
+
if (kept)
|
|
2182
|
+
copy.append(kept);
|
|
2183
|
+
}
|
|
2184
|
+
const made = await create(without(start.event.deployment, host));
|
|
2185
|
+
if (!made.ok)
|
|
2186
|
+
return made;
|
|
2187
|
+
const r = await replay(made.value, copy, { pace: "fast" });
|
|
2188
|
+
if (!r.ok) {
|
|
2189
|
+
await made.value.close();
|
|
2190
|
+
return r;
|
|
2191
|
+
}
|
|
2192
|
+
return made;
|
|
2193
|
+
}
|
|
2194
|
+
function shadowed(e, host, dropped) {
|
|
2195
|
+
const ev = e.event;
|
|
2196
|
+
if (ev.type === "deployment")
|
|
2197
|
+
return { ...e, event: { ...ev, deployment: without(ev.deployment, host) } };
|
|
2198
|
+
if (ev.type === "sent" && ev.from === "host" && ev.to === host) {
|
|
2199
|
+
dropped.add(ev.id);
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
if ((ev.type === "delivered" || ev.type === "denied") && dropped.has(ev.id))
|
|
2203
|
+
return;
|
|
2204
|
+
if (ev.type === "restarted" && ev.pod === host)
|
|
2205
|
+
return;
|
|
2206
|
+
return e;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
// packages/ui/src/observe/ring-view.ts
|
|
2210
|
+
var SIZE = 600;
|
|
2211
|
+
var STILL_MS = 200;
|
|
2212
|
+
|
|
2213
|
+
class NanoRing extends LitElement6 {
|
|
2214
|
+
static properties = {
|
|
2215
|
+
app: { attribute: false },
|
|
2216
|
+
registry: { attribute: false },
|
|
2217
|
+
tm: { attribute: false },
|
|
2218
|
+
store: { attribute: false },
|
|
2219
|
+
create: { attribute: false },
|
|
2220
|
+
show: { attribute: false },
|
|
2221
|
+
views: { attribute: false },
|
|
2222
|
+
frame: { state: true },
|
|
2223
|
+
shadow: { state: true },
|
|
2224
|
+
tooLong: { state: true },
|
|
2225
|
+
failed: { state: true }
|
|
2226
|
+
};
|
|
2227
|
+
static styles = css7`
|
|
2228
|
+
:host { display: block; overflow: auto; color: ${t4("fg")}; font: 12px ${t4("font")}; background: ${t4("bg")} }
|
|
2229
|
+
.stage { position: relative; margin: 8px auto }
|
|
2230
|
+
svg { position: absolute; inset: 0; overflow: visible; pointer-events: none }
|
|
2231
|
+
circle.rt { fill: none; stroke: ${t4("border")}; stroke-width: 2 } circle[data-dot] { pointer-events: all; cursor: pointer }
|
|
2232
|
+
.pod { position: absolute; transform: translate(-50%, -50%); width: 150px; max-height: 120px; overflow: auto; padding: 4px; border: 1px solid ${t4("border")}; border-radius: ${t4("radius")}; background: ${t4("surface")} }
|
|
2233
|
+
.pod[inert] { opacity: .85; border-style: dashed } .pod > b { display: block; font-size: 11px; color: ${t4("muted")} }
|
|
2234
|
+
small.warn { display: block; padding: 6px 8px; color: ${t4("warn")} }`;
|
|
2235
|
+
offs = [];
|
|
2236
|
+
els = new Map;
|
|
2237
|
+
timer;
|
|
2238
|
+
still;
|
|
2239
|
+
build = 0;
|
|
2240
|
+
shown = false;
|
|
2241
|
+
resized = new ResizeObserver(() => {
|
|
2242
|
+
if ((this.checkVisibility?.() ?? true) !== this.shown)
|
|
2243
|
+
this.requestUpdate();
|
|
2244
|
+
});
|
|
2245
|
+
constructor() {
|
|
2246
|
+
super();
|
|
2247
|
+
this.tooLong = false;
|
|
2248
|
+
}
|
|
2249
|
+
connectedCallback() {
|
|
2250
|
+
super.connectedCallback();
|
|
2251
|
+
this.resized.observe(this);
|
|
2252
|
+
this.watch();
|
|
2253
|
+
}
|
|
2254
|
+
disconnectedCallback() {
|
|
2255
|
+
super.disconnectedCallback();
|
|
2256
|
+
this.resized.disconnect();
|
|
2257
|
+
for (const off of this.offs.splice(0))
|
|
2258
|
+
off();
|
|
2259
|
+
this.toLive();
|
|
2260
|
+
}
|
|
2261
|
+
willUpdate(changed) {
|
|
2262
|
+
if (changed.has("store") || changed.has("tm")) {
|
|
2263
|
+
this.tooLong = false;
|
|
2264
|
+
this.toLive();
|
|
2265
|
+
}
|
|
2266
|
+
if (changed.has("app") || changed.has("tm"))
|
|
2267
|
+
this.watch();
|
|
2268
|
+
}
|
|
2269
|
+
watch() {
|
|
2270
|
+
for (const off of this.offs.splice(0))
|
|
2271
|
+
off();
|
|
2272
|
+
if (!this.isConnected)
|
|
2273
|
+
return;
|
|
2274
|
+
if (this.app)
|
|
2275
|
+
this.offs.push(this.app.listen((e) => {
|
|
2276
|
+
if (e.type === "applied")
|
|
2277
|
+
this.requestUpdate();
|
|
2278
|
+
}));
|
|
2279
|
+
if (this.tm)
|
|
2280
|
+
this.offs.push(this.tm.subscribe((f) => {
|
|
2281
|
+
this.frame = f;
|
|
2282
|
+
this.sync();
|
|
2283
|
+
}));
|
|
2284
|
+
this.sync();
|
|
2285
|
+
}
|
|
2286
|
+
sync() {
|
|
2287
|
+
const tm = this.tm;
|
|
2288
|
+
if (!tm || ringSource(tm.mode, tm.cursor >= tm.span.to, !this.tooLong) !== "past")
|
|
2289
|
+
return this.toLive();
|
|
2290
|
+
if (tm.cursor === this.still)
|
|
2291
|
+
return;
|
|
2292
|
+
this.still = tm.cursor;
|
|
2293
|
+
clearTimeout(this.timer);
|
|
2294
|
+
this.timer = setTimeout(() => void this.rebuild(tm.cursor), STILL_MS);
|
|
2295
|
+
}
|
|
2296
|
+
toLive() {
|
|
2297
|
+
clearTimeout(this.timer);
|
|
2298
|
+
this.still = undefined;
|
|
2299
|
+
this.build++;
|
|
2300
|
+
this.failed = undefined;
|
|
2301
|
+
this.bind(undefined);
|
|
2302
|
+
}
|
|
2303
|
+
bind(shadow) {
|
|
2304
|
+
const old = this.shadow;
|
|
2305
|
+
this.shadow = shadow;
|
|
2306
|
+
if (old && old !== shadow)
|
|
2307
|
+
old.close();
|
|
2308
|
+
}
|
|
2309
|
+
async rebuild(t5) {
|
|
2310
|
+
const mine = ++this.build, store = this.store, create = this.create;
|
|
2311
|
+
if (!store || !create)
|
|
2312
|
+
return;
|
|
2313
|
+
if (!await cleanStart(store)) {
|
|
2314
|
+
if (mine === this.build) {
|
|
2315
|
+
this.tooLong = true;
|
|
2316
|
+
this.toLive();
|
|
2317
|
+
}
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
const made = await shadowAt(store, t5, create);
|
|
2321
|
+
if (mine !== this.build) {
|
|
2322
|
+
if (made.ok)
|
|
2323
|
+
await made.value.close();
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
if (made.ok) {
|
|
2327
|
+
this.failed = undefined;
|
|
2328
|
+
this.bind(made.value);
|
|
2329
|
+
} else {
|
|
2330
|
+
this.failed = made.fail.reason;
|
|
2331
|
+
this.bind(undefined);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
view(d, pod2, runtime2, app, registry) {
|
|
2335
|
+
const map2 = { ...views, ...this.views }, tag = viewFor(pod2, d, map2), key = `${pod2} ${tag}`;
|
|
2336
|
+
if (tag === "nano-pod-view" && map2[d.pods[pod2]?.implementation ?? ""] !== tag)
|
|
2337
|
+
return "";
|
|
2338
|
+
let el = this.els.get(key);
|
|
2339
|
+
if (!el)
|
|
2340
|
+
this.els.set(key, el = document.createElement(tag));
|
|
2341
|
+
const t5 = el.target;
|
|
2342
|
+
if (!t5 || t5.app !== app || t5.runtime !== runtime2 || t5.registry !== registry)
|
|
2343
|
+
el.target = { app, registry, runtime: runtime2, pod: pod2 };
|
|
2344
|
+
return el;
|
|
2345
|
+
}
|
|
2346
|
+
render() {
|
|
2347
|
+
const { app, registry, tm } = this;
|
|
2348
|
+
this.shown = this.checkVisibility?.() ?? true;
|
|
2349
|
+
if (!app || !registry || !this.shown)
|
|
2350
|
+
return html15``;
|
|
2351
|
+
const bound = this.shadow ?? app, past = !!this.shadow, d = bound.deployment(), l = ringLayout(d, { size: SIZE, show: this.show });
|
|
2352
|
+
const tooLong = !!tm && this.tooLong && ringSource(tm.mode, tm.cursor >= tm.span.to, false) === "too-long";
|
|
2353
|
+
const home = (pod2, rt) => rt ?? Object.keys(d.runtimes).find((r) => d.runtimes[r].pods.includes(pod2));
|
|
2354
|
+
const dots = (this.frame?.inFlight ?? []).flatMap(({ message, progress }) => {
|
|
2355
|
+
const p = ringDot(l, d, message, Math.min(1, progress));
|
|
2356
|
+
return p ? [svg2`<circle data-dot=${message.sent.id} cx=${p.x} cy=${p.y} r="6" fill=${tv("s2")} stroke=${tv("bg")} stroke-width="2" @click=${() => tm?.seek(message.at)}></circle>`] : [];
|
|
2357
|
+
});
|
|
2358
|
+
return html15`
|
|
2359
|
+
${tooLong ? html15`<small class="warn">history too long to rebuild state</small>` : ""}
|
|
2360
|
+
${this.failed ? html15`<small class="warn">${this.failed}</small>` : ""}
|
|
2361
|
+
<div class="stage" style="width:${SIZE}px;height:${SIZE}px">
|
|
2362
|
+
<svg>${l.runtimes.map((r) => svg2`<circle class="rt" cx=${r.x} cy=${r.y} r=${r.r}></circle><text x=${r.x} y=${r.y - r.r - 8} text-anchor="middle" fill=${tv("muted")}>${r.id}</text>`)}</svg>
|
|
2363
|
+
${l.pods.map((p) => html15`<div class="pod" data-pod=${p.pod} .inert=${past} style="left:${p.x}px;top:${p.y}px"><b>${p.pod}</b>${this.view(d, p.pod, home(p.pod, p.runtime), bound, registry)}</div>`)}
|
|
2364
|
+
<svg>${dots}</svg>
|
|
2365
|
+
</div>`;
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
|
|
927
2369
|
// packages/ui/src/views/define.ts
|
|
928
2370
|
var views = { "nano.ui/input": "nano-input", "nano.ui/debounce": "nano-debounce", "nano.ui/map": "nano-map", "nano.ui/log": "nano-log" };
|
|
929
|
-
var tags = { "nano-explorer": NanoExplorer, "nano-wiring": NanoWiring, "nano-pod-view": NanoPodView, "nano-input": NanoInput, "nano-debounce": NanoDebounce, "nano-map": NanoMap, "nano-log": NanoLog };
|
|
2371
|
+
var tags = { "nano-filter": NanoFilter, "nano-time-machine": NanoTimeMachine, "nano-ring": NanoRing, "nano-explorer": NanoExplorer, "nano-wiring": NanoWiring, "nano-pod-view": NanoPodView, "nano-input": NanoInput, "nano-debounce": NanoDebounce, "nano-map": NanoMap, "nano-log": NanoLog };
|
|
930
2372
|
function defineViews() {
|
|
931
2373
|
for (const [tag, cls] of Object.entries(tags))
|
|
932
2374
|
if (!customElements.get(tag))
|
|
933
2375
|
customElements.define(tag, cls);
|
|
934
2376
|
}
|
|
2377
|
+
// packages/ui/src/observe/record.ts
|
|
2378
|
+
var recorded = (e) => {
|
|
2379
|
+
if (e.type === "sent") {
|
|
2380
|
+
const { input: input2, ...rest } = e;
|
|
2381
|
+
return "input" in e ? { ...rest, input: snap(input2) } : rest;
|
|
2382
|
+
}
|
|
2383
|
+
if (e.type === "delivered")
|
|
2384
|
+
return { type: "delivered", id: e.id, ok: e.result.ok, result: snap(e.result.ok ? e.result.value : e.result.fail), ms: e.ms };
|
|
2385
|
+
return e;
|
|
2386
|
+
};
|
|
2387
|
+
async function record(app, store, opts = {}) {
|
|
2388
|
+
const now = opts.now ?? Date.now;
|
|
2389
|
+
let seq = 0;
|
|
2390
|
+
const heard = new Set;
|
|
2391
|
+
let held = [];
|
|
2392
|
+
const add = (event, at = now()) => {
|
|
2393
|
+
try {
|
|
2394
|
+
if (held)
|
|
2395
|
+
held.push({ at, event });
|
|
2396
|
+
else {
|
|
2397
|
+
const entry = { seq: ++seq, at, event };
|
|
2398
|
+
store.append(entry);
|
|
2399
|
+
for (const fn of heard)
|
|
2400
|
+
try {
|
|
2401
|
+
fn(entry);
|
|
2402
|
+
} catch {}
|
|
2403
|
+
}
|
|
2404
|
+
} catch {}
|
|
2405
|
+
};
|
|
2406
|
+
const deployment = (clean, caller) => add({ type: "deployment", deployment: app.deployment(), ...clean ? { clean: true } : {}, ...caller ? { caller } : {} });
|
|
2407
|
+
deployment(opts.clean);
|
|
2408
|
+
const stop = app.listen((e) => {
|
|
2409
|
+
try {
|
|
2410
|
+
add(recorded(e));
|
|
2411
|
+
if (e.type === "applied")
|
|
2412
|
+
deployment(false, e.caller);
|
|
2413
|
+
} catch {}
|
|
2414
|
+
});
|
|
2415
|
+
try {
|
|
2416
|
+
await store.flush();
|
|
2417
|
+
const n = await store.size();
|
|
2418
|
+
seq = n ? (await store.range(await store.oldest() + n - 1)).at(-1)?.seq ?? 0 : 0;
|
|
2419
|
+
} catch (e) {
|
|
2420
|
+
stop();
|
|
2421
|
+
throw e;
|
|
2422
|
+
}
|
|
2423
|
+
const waiting = held;
|
|
2424
|
+
held = undefined;
|
|
2425
|
+
for (const { at, event } of waiting)
|
|
2426
|
+
add(event, at);
|
|
2427
|
+
return { stop, listen: (fn) => {
|
|
2428
|
+
heard.add(fn);
|
|
2429
|
+
return () => {
|
|
2430
|
+
heard.delete(fn);
|
|
2431
|
+
};
|
|
2432
|
+
} };
|
|
2433
|
+
}
|
|
2434
|
+
// packages/ui/src/observe/clock-driver.ts
|
|
2435
|
+
import { lookup as lookup2 } from "@pritzlaff/nano-core";
|
|
2436
|
+
var raf2 = { now: () => Date.now(), frame: (fn) => {
|
|
2437
|
+
const id = requestAnimationFrame(fn);
|
|
2438
|
+
return () => cancelAnimationFrame(id);
|
|
2439
|
+
} };
|
|
2440
|
+
function clockDriver(app, registry, tm, opts = {}) {
|
|
2441
|
+
const ticker = opts.ticker ?? raf2, gap = 1000 / (opts.maxHz ?? 20);
|
|
2442
|
+
let driving = null, reason;
|
|
2443
|
+
const find = () => {
|
|
2444
|
+
const d = app.deployment();
|
|
2445
|
+
const clocks = Object.keys(d.pods).filter((p) => registry.implementation(d.pods[p].implementation)?.provides.some((i) => i.coord === ClockControl.coord));
|
|
2446
|
+
driving = clocks.length === 1 ? clocks[0] : null;
|
|
2447
|
+
reason = driving ? undefined : clocks.length ? `${clocks.length} pods provide ClockControl: ${clocks.join(", ")}` : "no pod provides ClockControl";
|
|
2448
|
+
};
|
|
2449
|
+
find();
|
|
2450
|
+
const unlisten = app.listen((e) => {
|
|
2451
|
+
if (e.type === "applied")
|
|
2452
|
+
find();
|
|
2453
|
+
});
|
|
2454
|
+
const flight = inFlight(app);
|
|
2455
|
+
let last = ticker.now(), cancel, closed = false;
|
|
2456
|
+
const loop = async () => {
|
|
2457
|
+
const now = ticker.now();
|
|
2458
|
+
if (driving && tm.mode === "live") {
|
|
2459
|
+
if (now - last >= gap) {
|
|
2460
|
+
const ms = (now - last) * tm.speed;
|
|
2461
|
+
last = now;
|
|
2462
|
+
const runtime2 = lookup2(app.deployment()).placedIn.get(driving)?.[0];
|
|
2463
|
+
if (runtime2) {
|
|
2464
|
+
await app.call(runtime2, driving).advance(ms);
|
|
2465
|
+
await flight.quiet();
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
} else
|
|
2469
|
+
last = now;
|
|
2470
|
+
if (!closed)
|
|
2471
|
+
cancel = ticker.frame(loop);
|
|
2472
|
+
};
|
|
2473
|
+
cancel = ticker.frame(loop);
|
|
2474
|
+
return {
|
|
2475
|
+
get driving() {
|
|
2476
|
+
return driving;
|
|
2477
|
+
},
|
|
2478
|
+
get reason() {
|
|
2479
|
+
return reason;
|
|
2480
|
+
},
|
|
2481
|
+
close() {
|
|
2482
|
+
closed = true;
|
|
2483
|
+
cancel?.();
|
|
2484
|
+
unlisten();
|
|
2485
|
+
flight.stop();
|
|
2486
|
+
}
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
// packages/ui/src/observe/fold.ts
|
|
2490
|
+
async function foldAt(store, t5, r) {
|
|
2491
|
+
await store.flush();
|
|
2492
|
+
const entries = await store.range();
|
|
2493
|
+
const last = entries.findLast((e) => e.at <= t5)?.seq ?? -Infinity;
|
|
2494
|
+
const messages = new Map(pair(entries).map((m) => [m.seq, m]));
|
|
2495
|
+
let s = r.initial;
|
|
2496
|
+
for (const e of entries) {
|
|
2497
|
+
if (e.seq > last)
|
|
2498
|
+
break;
|
|
2499
|
+
const m = messages.get(e.seq);
|
|
2500
|
+
if (m)
|
|
2501
|
+
s = r.step(s, m);
|
|
2502
|
+
else if (e.event.type === "deployment" && r.deployment)
|
|
2503
|
+
s = r.deployment(s, e.event.deployment);
|
|
2504
|
+
}
|
|
2505
|
+
return s;
|
|
2506
|
+
}
|
|
935
2507
|
// packages/ui/src/index.ts
|
|
936
2508
|
var src_default = uiProvider;
|
|
937
2509
|
export {
|
|
938
2510
|
views,
|
|
939
2511
|
viewFor,
|
|
940
2512
|
uiProvider,
|
|
2513
|
+
truncated,
|
|
2514
|
+
timeMachine,
|
|
2515
|
+
snap,
|
|
2516
|
+
simClock,
|
|
2517
|
+
shadowAt,
|
|
2518
|
+
seededRandom,
|
|
2519
|
+
roots,
|
|
2520
|
+
replay,
|
|
2521
|
+
record,
|
|
2522
|
+
random,
|
|
2523
|
+
pair,
|
|
2524
|
+
memoryStore,
|
|
2525
|
+
matches,
|
|
941
2526
|
map,
|
|
942
2527
|
log,
|
|
943
2528
|
input,
|
|
2529
|
+
foldAt,
|
|
2530
|
+
filterTree,
|
|
2531
|
+
emptyFilter,
|
|
2532
|
+
diverge,
|
|
944
2533
|
defineViews,
|
|
945
2534
|
src_default as default,
|
|
946
2535
|
debounce,
|
|
2536
|
+
clockDriver,
|
|
2537
|
+
clock,
|
|
947
2538
|
circuitOf,
|
|
2539
|
+
Random,
|
|
948
2540
|
Nothing,
|
|
2541
|
+
NanoTimeMachine,
|
|
2542
|
+
NanoRing,
|
|
2543
|
+
NanoFilter,
|
|
949
2544
|
MapIface,
|
|
950
2545
|
Log,
|
|
951
2546
|
Input,
|
|
952
2547
|
HostUI,
|
|
2548
|
+
HostDeploy,
|
|
953
2549
|
Debounce,
|
|
2550
|
+
ClockControl,
|
|
2551
|
+
Clock,
|
|
954
2552
|
Any
|
|
955
2553
|
};
|
|
956
2554
|
|
|
957
|
-
//# debugId=
|
|
2555
|
+
//# debugId=E83F4F542A4BD60B64756E2164756E21
|
|
958
2556
|
//# sourceMappingURL=index.js.map
|