@celobus/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +91 -0
- package/README.md +38 -2
- package/dist/access.d.ts +141 -0
- package/dist/access.js +232 -0
- package/dist/codec.d.ts +29 -0
- package/dist/codec.js +361 -0
- package/dist/cron.d.ts +2 -0
- package/dist/cron.js +113 -0
- package/dist/ctx.d.ts +644 -0
- package/dist/ctx.js +657 -0
- package/dist/db.d.ts +234 -0
- package/dist/db.js +495 -0
- package/dist/decimal.d.ts +39 -0
- package/dist/decimal.js +158 -0
- package/dist/declare.d.ts +311 -0
- package/dist/declare.js +78 -0
- package/dist/descriptor.d.ts +229 -0
- package/dist/descriptor.js +899 -0
- package/dist/errors.d.ts +65 -0
- package/dist/errors.js +114 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +34 -0
- package/dist/log.d.ts +39 -0
- package/dist/log.js +101 -0
- package/dist/names.d.ts +12 -0
- package/dist/names.js +41 -0
- package/dist/notify.d.ts +185 -0
- package/dist/notify.js +234 -0
- package/dist/platform.d.ts +61 -0
- package/dist/platform.js +47 -0
- package/dist/plugin.d.ts +43 -0
- package/dist/plugin.js +117 -0
- package/dist/query.d.ts +326 -0
- package/dist/query.js +794 -0
- package/dist/remote.d.ts +8 -0
- package/dist/remote.js +19 -0
- package/dist/schema.d.ts +487 -0
- package/dist/schema.js +405 -0
- package/dist/serve.d.ts +63 -0
- package/dist/serve.js +411 -0
- package/dist/sql.d.ts +13 -0
- package/dist/sql.js +33 -0
- package/dist/ui.d.ts +1867 -0
- package/dist/ui.js +3964 -0
- package/dist/viz-kinds.d.ts +12 -0
- package/dist/viz-kinds.js +14 -0
- package/package.json +33 -4
- package/proto/plugin.proto +994 -0
package/dist/ui.js
ADDED
|
@@ -0,0 +1,3964 @@
|
|
|
1
|
+
import { Decimal } from "./decimal.js";
|
|
2
|
+
import { snake } from "./names.js";
|
|
3
|
+
import { EntityDef, FieldRef, MessageDef, PlatformEntity } from "./schema.js";
|
|
4
|
+
import { VIZ_KINDS } from "./viz-kinds.js";
|
|
5
|
+
/** The catalog revision these builders write (2: charts and figures, `ui.viz`, and dashboards, `ui.board`; 3: the app-like primitives). */
|
|
6
|
+
export const CATALOG = 3;
|
|
7
|
+
/** @internal A part of the document known only when the plugin resolves. */
|
|
8
|
+
export class Deferred {
|
|
9
|
+
resolve;
|
|
10
|
+
constructor(resolve) {
|
|
11
|
+
this.resolve = resolve;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** @internal Anything that becomes JSON in the document. */
|
|
15
|
+
export class Built {
|
|
16
|
+
}
|
|
17
|
+
/** A catalog text: its key and its English (fallback) text, which goes into the document's `texts.en`. */
|
|
18
|
+
export class TextKey {
|
|
19
|
+
key;
|
|
20
|
+
en;
|
|
21
|
+
args;
|
|
22
|
+
constructor(key, en, args = {}) {
|
|
23
|
+
this.key = key;
|
|
24
|
+
this.en = en;
|
|
25
|
+
this.args = args;
|
|
26
|
+
}
|
|
27
|
+
/** An argument of the text (`ui.text('orders.cancel', 'Cancel order {number}?').arg('number', r.get(order.f.number))`). */
|
|
28
|
+
arg(name, v) {
|
|
29
|
+
return new TextKey(this.key, this.en, { ...this.args, [name]: value(v) });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function endpointRef(def) {
|
|
33
|
+
return new Deferred((r, path) => r.endpoint(def, path));
|
|
34
|
+
}
|
|
35
|
+
/** A literal as the wire carries it: int64 and decimals as strings, timestamps in RFC 3339, bytes in base64. */
|
|
36
|
+
function encode(x) {
|
|
37
|
+
if (typeof x === "bigint")
|
|
38
|
+
return x.toString();
|
|
39
|
+
if (x instanceof Date)
|
|
40
|
+
return x.toISOString();
|
|
41
|
+
if (x instanceof Decimal)
|
|
42
|
+
return x.toString();
|
|
43
|
+
if (x instanceof Uint8Array)
|
|
44
|
+
return Buffer.from(x).toString("base64");
|
|
45
|
+
if (Array.isArray(x))
|
|
46
|
+
return x.map(encode);
|
|
47
|
+
return x;
|
|
48
|
+
}
|
|
49
|
+
/** `[]` → `undefined`, so the key is left out. */
|
|
50
|
+
function some(a) {
|
|
51
|
+
return a.length > 0 ? [...a] : undefined;
|
|
52
|
+
}
|
|
53
|
+
/** `in_progress` → `In progress`. */
|
|
54
|
+
function labelOf(v) {
|
|
55
|
+
const s = v.replace(/_/g, " ");
|
|
56
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
57
|
+
}
|
|
58
|
+
/** The descriptor's type of a field (`string`, `enum:OrderStatus`, `message:Order`, `ref:platform.user`). */
|
|
59
|
+
function spelled(field) {
|
|
60
|
+
const spec = field.spec;
|
|
61
|
+
switch (spec.kind) {
|
|
62
|
+
case "scalar":
|
|
63
|
+
return spec.scalar;
|
|
64
|
+
case "enum":
|
|
65
|
+
return `enum:${spec.enumDef.name}`;
|
|
66
|
+
case "message":
|
|
67
|
+
return `message:${spec.message.name}`;
|
|
68
|
+
case "array":
|
|
69
|
+
return spelled(spec.inner);
|
|
70
|
+
case "ref": {
|
|
71
|
+
const target = spec.ref;
|
|
72
|
+
if (target instanceof PlatformEntity)
|
|
73
|
+
return `ref:${target.ref}`;
|
|
74
|
+
if (typeof target === "string")
|
|
75
|
+
return `ref:${target}`;
|
|
76
|
+
return new Deferred((r, path) => {
|
|
77
|
+
const e = target instanceof EntityDef ? target : target();
|
|
78
|
+
return `ref:${r.entity(e, path)}`;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function enumOptions(field) {
|
|
84
|
+
const f = field.spec.kind === "array" ? field.spec.inner : field;
|
|
85
|
+
if (f.spec.kind !== "enum")
|
|
86
|
+
return [];
|
|
87
|
+
return f.spec.enumDef.values.map((v) => ({ value: v, label: labelOf(v) }));
|
|
88
|
+
}
|
|
89
|
+
// ---------------------------------------------------------------------------------------------- values
|
|
90
|
+
/** A value of type `T` from somewhere: a literal, a param, state, a query field, a row field, the caller, … */
|
|
91
|
+
export class Val extends Built {
|
|
92
|
+
v;
|
|
93
|
+
constructor(/** @internal */ v) {
|
|
94
|
+
super();
|
|
95
|
+
this.v = v;
|
|
96
|
+
}
|
|
97
|
+
/** @internal */
|
|
98
|
+
json() {
|
|
99
|
+
return this.v;
|
|
100
|
+
}
|
|
101
|
+
eq(other) {
|
|
102
|
+
return new Cond({ eq: [this.v, value(other)] });
|
|
103
|
+
}
|
|
104
|
+
ne(other) {
|
|
105
|
+
return new Cond({ ne: [this.v, value(other)] });
|
|
106
|
+
}
|
|
107
|
+
gt(other) {
|
|
108
|
+
return new Cond({ gt: [this.v, value(other)] });
|
|
109
|
+
}
|
|
110
|
+
lt(other) {
|
|
111
|
+
return new Cond({ lt: [this.v, value(other)] });
|
|
112
|
+
}
|
|
113
|
+
/** Absent, `""` or `[]`. */
|
|
114
|
+
empty() {
|
|
115
|
+
return new Cond({ empty: this.v });
|
|
116
|
+
}
|
|
117
|
+
isIn(set) {
|
|
118
|
+
return new Cond({ in: { value: this.v, set: set.map(encode) } });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** @internal The document value of a `ValueLike`. */
|
|
122
|
+
function value(x) {
|
|
123
|
+
if (x instanceof Val)
|
|
124
|
+
return x.v;
|
|
125
|
+
if (x instanceof ParamRef)
|
|
126
|
+
return { param: x.name };
|
|
127
|
+
if (x instanceof StateRef)
|
|
128
|
+
return { state: x.name };
|
|
129
|
+
return { lit: encode(x) };
|
|
130
|
+
}
|
|
131
|
+
/** A presentation condition (never access control): `val.eq(..)`, `.and(..)`, `ui.not(..)`. */
|
|
132
|
+
export class Cond extends Built {
|
|
133
|
+
c;
|
|
134
|
+
constructor(/** @internal */ c) {
|
|
135
|
+
super();
|
|
136
|
+
this.c = c;
|
|
137
|
+
}
|
|
138
|
+
/** @internal */
|
|
139
|
+
json() {
|
|
140
|
+
return this.c;
|
|
141
|
+
}
|
|
142
|
+
and(other) {
|
|
143
|
+
return new Cond({ and: [this.c, other.c] });
|
|
144
|
+
}
|
|
145
|
+
or(other) {
|
|
146
|
+
return new Cond({ or: [this.c, other.c] });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function txt(t) {
|
|
150
|
+
if (typeof t === "string" || t instanceof TextKey)
|
|
151
|
+
return t;
|
|
152
|
+
return value(t);
|
|
153
|
+
}
|
|
154
|
+
function args(a) {
|
|
155
|
+
return Object.entries(a ?? {})
|
|
156
|
+
.filter(([, v]) => v !== undefined)
|
|
157
|
+
.map(([k, v]) => ({ field: snake(k), value: value(v) }));
|
|
158
|
+
}
|
|
159
|
+
// ---------------------------------------------------------------------------------------------- topics
|
|
160
|
+
/**
|
|
161
|
+
* A topic: `const ORDERS = topic('orders', t.message('AllOrders', {}))`. Endpoints declare that they invalidate it
|
|
162
|
+
* (`.invalidates(ORDERS)`); queries follow it (`.follow(ORDERS)`, or one key: `.follow(ORDER.key({ id }))`).
|
|
163
|
+
*/
|
|
164
|
+
export class TopicDef {
|
|
165
|
+
name;
|
|
166
|
+
keyMessage;
|
|
167
|
+
constructor(name,
|
|
168
|
+
/** The key message (its fields name one record; none: the topic has one key). */
|
|
169
|
+
keyMessage) {
|
|
170
|
+
this.name = name;
|
|
171
|
+
this.keyMessage = keyMessage;
|
|
172
|
+
}
|
|
173
|
+
/** The declaration with its defaults (no roles or scopes, invalidated by endpoint declarations). */
|
|
174
|
+
decl() {
|
|
175
|
+
return new TopicDecl(this, [], [], undefined, false, "");
|
|
176
|
+
}
|
|
177
|
+
/** Members with any of these roles may follow it. */
|
|
178
|
+
roles(roles) {
|
|
179
|
+
return this.decl().roles(roles);
|
|
180
|
+
}
|
|
181
|
+
scopes(scopes) {
|
|
182
|
+
return this.decl().scopes(scopes);
|
|
183
|
+
}
|
|
184
|
+
/** The read endpoint that decides whether a member may follow one key (it takes the key's fields). */
|
|
185
|
+
authorize(endpoint) {
|
|
186
|
+
return this.decl().authorize(endpoint);
|
|
187
|
+
}
|
|
188
|
+
/** Invalidated by code (`ctx.invalidate`) rather than by endpoint declarations. */
|
|
189
|
+
manual() {
|
|
190
|
+
return this.decl().manual();
|
|
191
|
+
}
|
|
192
|
+
describe(text) {
|
|
193
|
+
return this.decl().describe(text);
|
|
194
|
+
}
|
|
195
|
+
/** One key of the topic, for `.follow(..)`: `ORDER.key({ id })`. */
|
|
196
|
+
key(key) {
|
|
197
|
+
return new FollowKey(this.name, args(key));
|
|
198
|
+
}
|
|
199
|
+
/** An invalidation of the key whose field `key` is the response's field `from`: `ORDER.by(orderKey.f.id, order.f.id)`. */
|
|
200
|
+
by(key, from) {
|
|
201
|
+
return new Invalidation(this.name, [[key.name, from.name]]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** Declares a topic and its key message. */
|
|
205
|
+
export function topic(name, key) {
|
|
206
|
+
return new TopicDef(name, key);
|
|
207
|
+
}
|
|
208
|
+
/** A topic as the plugin declares it (`plugin({ topics: [ORDERS.roles([clerk])] })`). */
|
|
209
|
+
export class TopicDecl {
|
|
210
|
+
topic;
|
|
211
|
+
roleList;
|
|
212
|
+
scopeList;
|
|
213
|
+
authorizer;
|
|
214
|
+
isManual;
|
|
215
|
+
description;
|
|
216
|
+
constructor(topic,
|
|
217
|
+
/** @internal */ roleList,
|
|
218
|
+
/** @internal */ scopeList,
|
|
219
|
+
/** @internal */ authorizer,
|
|
220
|
+
/** @internal */ isManual,
|
|
221
|
+
/** @internal */ description) {
|
|
222
|
+
this.topic = topic;
|
|
223
|
+
this.roleList = roleList;
|
|
224
|
+
this.scopeList = scopeList;
|
|
225
|
+
this.authorizer = authorizer;
|
|
226
|
+
this.isManual = isManual;
|
|
227
|
+
this.description = description;
|
|
228
|
+
}
|
|
229
|
+
roles(roles) {
|
|
230
|
+
return new TopicDecl(this.topic, [...roles], this.scopeList, this.authorizer, this.isManual, this.description);
|
|
231
|
+
}
|
|
232
|
+
scopes(scopes) {
|
|
233
|
+
return new TopicDecl(this.topic, this.roleList, [...scopes], this.authorizer, this.isManual, this.description);
|
|
234
|
+
}
|
|
235
|
+
authorize(endpoint) {
|
|
236
|
+
return new TopicDecl(this.topic, this.roleList, this.scopeList, endpoint, this.isManual, this.description);
|
|
237
|
+
}
|
|
238
|
+
manual() {
|
|
239
|
+
return new TopicDecl(this.topic, this.roleList, this.scopeList, this.authorizer, true, this.description);
|
|
240
|
+
}
|
|
241
|
+
describe(text) {
|
|
242
|
+
return new TopicDecl(this.topic, this.roleList, this.scopeList, this.authorizer, this.isManual, text);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** @internal */
|
|
246
|
+
export function topicDecl(t) {
|
|
247
|
+
return t instanceof TopicDecl ? t : t.decl();
|
|
248
|
+
}
|
|
249
|
+
/** An endpoint's declared invalidation: a topic, and the key taken from the response. */
|
|
250
|
+
export class Invalidation {
|
|
251
|
+
topic;
|
|
252
|
+
key;
|
|
253
|
+
constructor(topic,
|
|
254
|
+
/** @internal [key field, response field] */ key) {
|
|
255
|
+
this.topic = topic;
|
|
256
|
+
this.key = key;
|
|
257
|
+
}
|
|
258
|
+
/** Another key field. */
|
|
259
|
+
and(key, from) {
|
|
260
|
+
return new Invalidation(this.topic, [...this.key, [key.name, from.name]]);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/** @internal The descriptor's `invalidates` entry. */
|
|
264
|
+
export function invalidationJson(i) {
|
|
265
|
+
if (i instanceof TopicDef)
|
|
266
|
+
return { topic: i.name };
|
|
267
|
+
const out = { topic: i.topic };
|
|
268
|
+
if (i.key.length > 0)
|
|
269
|
+
out.key = i.key.map(([field, from]) => ({ field, from }));
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
272
|
+
/** A followed topic with a key value. */
|
|
273
|
+
export class FollowKey {
|
|
274
|
+
topic;
|
|
275
|
+
key;
|
|
276
|
+
constructor(topic,
|
|
277
|
+
/** @internal */ key) {
|
|
278
|
+
this.topic = topic;
|
|
279
|
+
this.key = key;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function copyQuery(q) {
|
|
283
|
+
return { ...q, args: [...q.args], follow: q.follow.map((f) => ({ ...f })), join: q.join ? [...q.join] : undefined };
|
|
284
|
+
}
|
|
285
|
+
function queryJson(q) {
|
|
286
|
+
return {
|
|
287
|
+
name: q.name,
|
|
288
|
+
endpoint: q.endpoint,
|
|
289
|
+
args: some(q.args),
|
|
290
|
+
rows: q.rows,
|
|
291
|
+
paged: q.paged || undefined,
|
|
292
|
+
feed: q.feed,
|
|
293
|
+
follow: some(q.follow),
|
|
294
|
+
poll: q.poll,
|
|
295
|
+
max_age: q.max_age,
|
|
296
|
+
when: q.when,
|
|
297
|
+
older: q.older,
|
|
298
|
+
debounce_ms: q.debounce_ms,
|
|
299
|
+
join: q.join && some(q.join),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/** A query definition: `ui.call(listOrders, { status }).rows(listOrdersResponse.f.orders).paged().follow(ORDERS)`. */
|
|
303
|
+
export class QueryDef {
|
|
304
|
+
q;
|
|
305
|
+
constructor(/** @internal */ q) {
|
|
306
|
+
this.q = q;
|
|
307
|
+
}
|
|
308
|
+
/** The repeated field tables, lists and charts iterate. */
|
|
309
|
+
rows(f) {
|
|
310
|
+
return new QueryDef({ ...copyQuery(this.q), rows: f.name });
|
|
311
|
+
}
|
|
312
|
+
/** `page_token`/`page_size` in the request, `next_page_token` in the response. */
|
|
313
|
+
paged() {
|
|
314
|
+
return new QueryDef({ ...copyQuery(this.q), paged: true });
|
|
315
|
+
}
|
|
316
|
+
/** Re-run on the topic's invalidations (any key, or one key: `ORDER.key({ id })`), at most every `minIntervalMs`. */
|
|
317
|
+
follow(t, minIntervalMs) {
|
|
318
|
+
const q = copyQuery(this.q);
|
|
319
|
+
const f = t instanceof TopicDef ? { topic: t.name } : { topic: t.topic, key: some(t.key) };
|
|
320
|
+
q.follow.push(minIntervalMs === undefined ? f : { ...f, min_interval_ms: minIntervalMs });
|
|
321
|
+
return new QueryDef(q);
|
|
322
|
+
}
|
|
323
|
+
/** An append-only feed: `after` takes the last cursor, `cursor` gives it, rows are deduplicated by `key`. */
|
|
324
|
+
feed(after, cursor, key) {
|
|
325
|
+
return new QueryDef({ ...copyQuery(this.q), feed: { after: after.name, cursor: cursor.name, key: key.name } });
|
|
326
|
+
}
|
|
327
|
+
/** Re-run every `seconds` (at least 15). */
|
|
328
|
+
poll(seconds) {
|
|
329
|
+
return new QueryDef({ ...copyQuery(this.q), poll: seconds });
|
|
330
|
+
}
|
|
331
|
+
/** The oldest the data may get while shown (seconds). */
|
|
332
|
+
maxAge(seconds) {
|
|
333
|
+
return new QueryDef({ ...copyQuery(this.q), max_age: seconds });
|
|
334
|
+
}
|
|
335
|
+
/** Runs only while `c` holds (a record panel reads once a row is selected). */
|
|
336
|
+
when(c) {
|
|
337
|
+
return new QueryDef({ ...copyQuery(this.q), when: c });
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* The page before the rows (catalog 3): the same endpoint and args read again with the request field `arg` set to
|
|
341
|
+
* the answer's `token`; a `stream` loads older pages with it.
|
|
342
|
+
*/
|
|
343
|
+
older(token, arg) {
|
|
344
|
+
return new QueryDef({ ...copyQuery(this.q), older: { token: token.name, arg: arg.name } });
|
|
345
|
+
}
|
|
346
|
+
/** Arguments that change wait this long (ms, at most 2000) before the read: a preview of what is typed (catalog 3). */
|
|
347
|
+
debounceMs(ms) {
|
|
348
|
+
return new QueryDef({ ...copyQuery(this.q), debounce_ms: ms });
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* A lookup the rows' templates read as `<via>.<field>` (catalog 3): each row gets the item of the response's
|
|
352
|
+
* repeated field `rows` whose `key` equals the row's `by`:
|
|
353
|
+
* `.join(who, channelView.f.people, face.f.id, msg.f.by)` with `const who = ui.via('who', msg, face)`.
|
|
354
|
+
*/
|
|
355
|
+
join(via, rows, key, by) {
|
|
356
|
+
const q = copyQuery(this.q);
|
|
357
|
+
q.join = [...(q.join ?? []), { as: via.name, rows: rows.name, key: key.name, by: by.name }];
|
|
358
|
+
return new QueryDef(q);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/** A call of one of the plugin's read-only `ui` endpoints with its arguments. */
|
|
362
|
+
function call(endpoint, a) {
|
|
363
|
+
return new QueryDef({ name: "", endpoint: endpointRef(endpoint), args: args(a), paged: false, follow: [] });
|
|
364
|
+
}
|
|
365
|
+
/** A declared query of a screen, an overlay or the document: read its fields, iterate its rows. */
|
|
366
|
+
export class Q {
|
|
367
|
+
name;
|
|
368
|
+
constructor(name) {
|
|
369
|
+
this.name = name;
|
|
370
|
+
}
|
|
371
|
+
/** A field of the response (one record). */
|
|
372
|
+
field(f) {
|
|
373
|
+
return new Val({ data: { query: this.name, field: f.name } });
|
|
374
|
+
}
|
|
375
|
+
/** A nested field by path (`customer.name`). */
|
|
376
|
+
path(path) {
|
|
377
|
+
return new Val({ data: { query: this.name, field: path } });
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/** The current row of a table, list, chart or row menu. */
|
|
381
|
+
export class RowRef {
|
|
382
|
+
get(f) {
|
|
383
|
+
return new Val({ row: f.name });
|
|
384
|
+
}
|
|
385
|
+
/** A row value by path: a nested field (`ui.path(..)`) or a field of a query's join (`who.f(face.f.name)`). */
|
|
386
|
+
at(p) {
|
|
387
|
+
return new Val({ row: rowPath(p) });
|
|
388
|
+
}
|
|
389
|
+
/** The row as a list item (`r.view(r.get(order.f.customer)).subtitle(..)`): a table's compact view, a search result. */
|
|
390
|
+
view(title) {
|
|
391
|
+
return new RowViewB(title);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/** The values of the enclosing form. */
|
|
395
|
+
export class FormVals {
|
|
396
|
+
get(f) {
|
|
397
|
+
return new Val({ form: f.name });
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
// ---------------------------------------------------------------------------------------------- screens
|
|
401
|
+
/** A screen's key and its params message; `ui.screen(key, build)` builds it. */
|
|
402
|
+
export class ScreenKey {
|
|
403
|
+
id;
|
|
404
|
+
paramsMessage;
|
|
405
|
+
constructor(id,
|
|
406
|
+
/** @internal */ paramsMessage) {
|
|
407
|
+
this.id = id;
|
|
408
|
+
this.paramsMessage = paramsMessage;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/** An overlay's key and its params message. */
|
|
412
|
+
export class OverlayKey {
|
|
413
|
+
id;
|
|
414
|
+
paramsMessage;
|
|
415
|
+
constructor(id,
|
|
416
|
+
/** @internal */ paramsMessage) {
|
|
417
|
+
this.id = id;
|
|
418
|
+
this.paramsMessage = paramsMessage;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/** A screen or overlay param. */
|
|
422
|
+
export class ParamRef {
|
|
423
|
+
name;
|
|
424
|
+
field;
|
|
425
|
+
constructor(name,
|
|
426
|
+
/** @internal */ field) {
|
|
427
|
+
this.name = name;
|
|
428
|
+
this.field = field;
|
|
429
|
+
}
|
|
430
|
+
val() {
|
|
431
|
+
return new Val({ param: this.name });
|
|
432
|
+
}
|
|
433
|
+
input(control, label) {
|
|
434
|
+
return new InputB({ name: this.name, control, label: txt(label ?? labelOf(this.name)) });
|
|
435
|
+
}
|
|
436
|
+
/** A select in a filter bar: the enum's values (or `.option(..)`); the label defaults to the param's name. */
|
|
437
|
+
select(label) {
|
|
438
|
+
const i = this.input("select", label);
|
|
439
|
+
if (this.field)
|
|
440
|
+
i.i.options = enumOptions(this.field);
|
|
441
|
+
return i;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* A filter that takes several values: the enum's values (or `.option(..)`). The param is a string: the chosen
|
|
445
|
+
* values joined with commas, in the options' order (`unpaid,pending`); the endpoint splits it.
|
|
446
|
+
*/
|
|
447
|
+
choices(label) {
|
|
448
|
+
const i = this.input("multi_select", label);
|
|
449
|
+
if (this.field)
|
|
450
|
+
i.i.options = enumOptions(this.field);
|
|
451
|
+
return i;
|
|
452
|
+
}
|
|
453
|
+
search(label) {
|
|
454
|
+
return this.input("search", label);
|
|
455
|
+
}
|
|
456
|
+
date(label) {
|
|
457
|
+
return this.input("date", label);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/** A state value of a screen or overlay. */
|
|
461
|
+
export class StateRef {
|
|
462
|
+
name;
|
|
463
|
+
constructor(name) {
|
|
464
|
+
this.name = name;
|
|
465
|
+
}
|
|
466
|
+
val() {
|
|
467
|
+
return new Val({ state: this.name });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
/** A declared action (a chain of steps). */
|
|
471
|
+
export class ActionRef {
|
|
472
|
+
name;
|
|
473
|
+
constructor(name) {
|
|
474
|
+
this.name = name;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/** The builder a screen's or overlay's function gets. */
|
|
478
|
+
export class ScreenBuilder {
|
|
479
|
+
/** @internal */ params = [];
|
|
480
|
+
/** @internal */ states = [];
|
|
481
|
+
/** @internal */ queries = [];
|
|
482
|
+
/** @internal */ actions = [];
|
|
483
|
+
/** @internal */ overlays = [];
|
|
484
|
+
/** @internal */ headerNodes = [];
|
|
485
|
+
/** @internal */ titleText;
|
|
486
|
+
/** @internal */ subtitleText;
|
|
487
|
+
/** @internal */ kickerText;
|
|
488
|
+
/** @internal */ sizeValue = "medium";
|
|
489
|
+
/** @internal */ layoutNode;
|
|
490
|
+
counter = 0;
|
|
491
|
+
constructor(paramsMessage) {
|
|
492
|
+
for (const [key, field] of Object.entries((paramsMessage?.fields ?? {}))) {
|
|
493
|
+
this.params.push({
|
|
494
|
+
name: snake(key),
|
|
495
|
+
type: spelled(field),
|
|
496
|
+
required: !field.isOptional && field.spec.kind !== "array",
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
title(t) {
|
|
501
|
+
this.titleText = txt(t);
|
|
502
|
+
return this;
|
|
503
|
+
}
|
|
504
|
+
subtitle(t) {
|
|
505
|
+
this.subtitleText = txt(t);
|
|
506
|
+
return this;
|
|
507
|
+
}
|
|
508
|
+
/** A small line above an overlay's title (`COMMERCE · ORDERS`). */
|
|
509
|
+
kicker(t) {
|
|
510
|
+
this.kickerText = txt(t);
|
|
511
|
+
return this;
|
|
512
|
+
}
|
|
513
|
+
/** An overlay's size (default medium). */
|
|
514
|
+
size(size) {
|
|
515
|
+
this.sizeValue = size;
|
|
516
|
+
return this;
|
|
517
|
+
}
|
|
518
|
+
/** A param of the params message (a filter, a record id). */
|
|
519
|
+
param(f) {
|
|
520
|
+
return new ParamRef(f.name, f.field);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* A param with a default: a screen opened without it behaves as if the link had the default (the queries get it,
|
|
524
|
+
* a `segmented` or a tab bound to it shows it selected), and the link stays without it. The param always has a
|
|
525
|
+
* value, so the handle is of the plain type even when the field is optional:
|
|
526
|
+
* `const range = s.paramOr(reportParams.f.range, '30')`.
|
|
527
|
+
*/
|
|
528
|
+
paramOr(f, initial) {
|
|
529
|
+
const p = this.params.find((x) => x.name === f.name);
|
|
530
|
+
if (p) {
|
|
531
|
+
p.required = false;
|
|
532
|
+
p.default = encode(initial);
|
|
533
|
+
}
|
|
534
|
+
return new ParamRef(f.name, f.field);
|
|
535
|
+
}
|
|
536
|
+
/** State of a type (a `t.*` field) with its initial value. */
|
|
537
|
+
state(name, type, initial) {
|
|
538
|
+
this.states.push({ name, type: spelled(type), default: initial === undefined ? undefined : encode(initial) });
|
|
539
|
+
return new StateRef(name);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* State that returns to its default when one of these params changes (catalog 3; a tab that starts over in another
|
|
543
|
+
* conversation): `s.stateReset('tab', t.text(), 'notes', [channel])`.
|
|
544
|
+
*/
|
|
545
|
+
stateReset(name, type, initial, params) {
|
|
546
|
+
const r = this.state(name, type, initial);
|
|
547
|
+
this.states[this.states.length - 1].reset = some(params.map((p) => (typeof p === "string" ? p : p.name)));
|
|
548
|
+
return r;
|
|
549
|
+
}
|
|
550
|
+
query(name, def) {
|
|
551
|
+
this.queries.push(queryJson({ ...copyQuery(def.q), name }));
|
|
552
|
+
return new Q(name);
|
|
553
|
+
}
|
|
554
|
+
/** A chain of steps run by a button, a menu item or a row open. */
|
|
555
|
+
action(name, build) {
|
|
556
|
+
const c = new Chain();
|
|
557
|
+
build(c);
|
|
558
|
+
return this.pushAction(name, c);
|
|
559
|
+
}
|
|
560
|
+
/** A chain that reads the row it is run on (`r.get(order.f.id)`). */
|
|
561
|
+
rowAction(name, _rows, build) {
|
|
562
|
+
const c = new Chain();
|
|
563
|
+
build(c, new RowRef());
|
|
564
|
+
return this.pushAction(name, c);
|
|
565
|
+
}
|
|
566
|
+
pushAction(name, c) {
|
|
567
|
+
this.actions.push({ name, steps: c.steps, on_error: some(c.errorSteps) });
|
|
568
|
+
return new ActionRef(name);
|
|
569
|
+
}
|
|
570
|
+
/** Buttons and menus in the header (a screen) or the footer (a dialog). */
|
|
571
|
+
header(nodes) {
|
|
572
|
+
this.headerNodes.push(...nodes);
|
|
573
|
+
return this;
|
|
574
|
+
}
|
|
575
|
+
/** The same as `header`, as overlays name it. */
|
|
576
|
+
buttons(nodes) {
|
|
577
|
+
return this.header(nodes);
|
|
578
|
+
}
|
|
579
|
+
/** An overlay this screen opens (`a.open(CANCEL, { id })`). */
|
|
580
|
+
overlay(o) {
|
|
581
|
+
this.overlays.push(o);
|
|
582
|
+
return this;
|
|
583
|
+
}
|
|
584
|
+
layout(node) {
|
|
585
|
+
this.layoutNode = node;
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
/** A form filling `endpoint`'s request; its submit runs the chain `submit` builds (`a.callForm(endpoint, ..)`). */
|
|
589
|
+
form(endpoint, build, submitLabel, submit) {
|
|
590
|
+
const fb = new FormB();
|
|
591
|
+
build(fb);
|
|
592
|
+
let alternate;
|
|
593
|
+
if (fb.alternateButton) {
|
|
594
|
+
this.counter += 1;
|
|
595
|
+
const alt = this.pushAction(`alternate_${this.counter}`, fb.alternateButton.chain);
|
|
596
|
+
alternate = { label: fb.alternateButton.label, action: alt.name };
|
|
597
|
+
}
|
|
598
|
+
this.counter += 1;
|
|
599
|
+
const c = new Chain();
|
|
600
|
+
submit(c, new FormVals());
|
|
601
|
+
const a = this.pushAction(`submit_${this.counter}`, c);
|
|
602
|
+
return new N("form", {
|
|
603
|
+
endpoint: endpointRef(endpoint),
|
|
604
|
+
sections: fb.sections
|
|
605
|
+
.filter((s) => s.inputs.length > 0)
|
|
606
|
+
.map((s) => ({ title: s.title, inputs: s.inputs.map((i) => i.i) })),
|
|
607
|
+
submit: a.name,
|
|
608
|
+
submit_label: txt(submitLabel),
|
|
609
|
+
phone_submit_label: fb.phoneSubmitLabel,
|
|
610
|
+
cancel_label: fb.cancelLabel,
|
|
611
|
+
summary: fb.summaryValue,
|
|
612
|
+
note: fb.noteText,
|
|
613
|
+
alternate,
|
|
614
|
+
notes: some(fb.notes),
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
/** @internal */
|
|
618
|
+
finish(id, result) {
|
|
619
|
+
const layout = result instanceof Node ? result : this.layoutNode;
|
|
620
|
+
if (!layout)
|
|
621
|
+
throw new TypeError(`ui: ${id} has no layout (return a node or call s.layout(..))`);
|
|
622
|
+
this.titleText ??= labelOf(id);
|
|
623
|
+
return layout;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
/** A screen: `/w/{slug}/p/{plugin}/s/{id}?{params}`. */
|
|
627
|
+
export class ScreenDef extends ScreenKey {
|
|
628
|
+
build;
|
|
629
|
+
constructor(id, paramsMessage, build) {
|
|
630
|
+
super(id, paramsMessage);
|
|
631
|
+
this.build = build;
|
|
632
|
+
}
|
|
633
|
+
/** @internal */
|
|
634
|
+
json() {
|
|
635
|
+
const s = new ScreenBuilder(this.paramsMessage);
|
|
636
|
+
const layout = s.finish(this.id, this.build(s));
|
|
637
|
+
return {
|
|
638
|
+
id: this.id,
|
|
639
|
+
title: s.titleText,
|
|
640
|
+
subtitle: s.subtitleText,
|
|
641
|
+
params: some(s.params),
|
|
642
|
+
state: some(s.states),
|
|
643
|
+
queries: some(s.queries),
|
|
644
|
+
actions: some(s.actions),
|
|
645
|
+
overlays: some(s.overlays.map((o) => o.json())),
|
|
646
|
+
header: some(s.headerNodes),
|
|
647
|
+
layout,
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
/** A dialog, side panel or sheet over a screen. */
|
|
652
|
+
export class OverlayDef extends OverlayKey {
|
|
653
|
+
kind;
|
|
654
|
+
build;
|
|
655
|
+
constructor(id, paramsMessage, kind, build) {
|
|
656
|
+
super(id, paramsMessage);
|
|
657
|
+
this.kind = kind;
|
|
658
|
+
this.build = build;
|
|
659
|
+
}
|
|
660
|
+
/** @internal */
|
|
661
|
+
json() {
|
|
662
|
+
const s = new ScreenBuilder(this.paramsMessage);
|
|
663
|
+
const layout = s.finish(this.id, this.build(s));
|
|
664
|
+
return {
|
|
665
|
+
id: this.id,
|
|
666
|
+
kind: this.kind,
|
|
667
|
+
size: s.sizeValue,
|
|
668
|
+
title: s.titleText,
|
|
669
|
+
kicker: s.kickerText,
|
|
670
|
+
params: some(s.params),
|
|
671
|
+
state: some(s.states),
|
|
672
|
+
queries: some(s.queries),
|
|
673
|
+
actions: some(s.actions),
|
|
674
|
+
buttons: some(s.headerNodes),
|
|
675
|
+
layout,
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function screenKey(id, params) {
|
|
680
|
+
return new ScreenKey(id, params);
|
|
681
|
+
}
|
|
682
|
+
function overlayKey(id, params) {
|
|
683
|
+
return new OverlayKey(id, params);
|
|
684
|
+
}
|
|
685
|
+
function screen(a, b, c) {
|
|
686
|
+
if (a instanceof ScreenKey)
|
|
687
|
+
return new ScreenDef(a.id, a.paramsMessage, b);
|
|
688
|
+
return b instanceof MessageDef ? new ScreenDef(a, b, c) : new ScreenDef(a, undefined, b);
|
|
689
|
+
}
|
|
690
|
+
function overlayOf(kind) {
|
|
691
|
+
function make(a, b, c) {
|
|
692
|
+
if (a instanceof OverlayKey)
|
|
693
|
+
return new OverlayDef(a.id, a.paramsMessage, kind, b);
|
|
694
|
+
return b instanceof MessageDef ? new OverlayDef(a, b, kind, c) : new OverlayDef(a, undefined, kind, b);
|
|
695
|
+
}
|
|
696
|
+
return make;
|
|
697
|
+
}
|
|
698
|
+
// ---------------------------------------------------------------------------------------------- actions
|
|
699
|
+
/** A confirmation before the next steps: `ui.confirm('Archive it?')`, `ui.confirm.danger('Delete it?')`. */
|
|
700
|
+
export class ConfirmB {
|
|
701
|
+
/** @internal */ c;
|
|
702
|
+
constructor(title) {
|
|
703
|
+
this.c = { title: txt(title) };
|
|
704
|
+
}
|
|
705
|
+
text(t) {
|
|
706
|
+
this.c.text = txt(t);
|
|
707
|
+
return this;
|
|
708
|
+
}
|
|
709
|
+
confirmLabel(t) {
|
|
710
|
+
this.c.confirm_label = txt(t);
|
|
711
|
+
return this;
|
|
712
|
+
}
|
|
713
|
+
danger() {
|
|
714
|
+
this.c.danger = true;
|
|
715
|
+
return this;
|
|
716
|
+
}
|
|
717
|
+
/** The member types this value to confirm. */
|
|
718
|
+
typed(v) {
|
|
719
|
+
this.c.typed = value(v);
|
|
720
|
+
return this;
|
|
721
|
+
}
|
|
722
|
+
cancelLabel(t) {
|
|
723
|
+
this.c.cancel_label = txt(t);
|
|
724
|
+
return this;
|
|
725
|
+
}
|
|
726
|
+
/** What is affected, as a record line with an icon (`Order #1048 · Hartwell & Co · $2,480.00`). */
|
|
727
|
+
summary(icon, t) {
|
|
728
|
+
this.c.summary = txt(t);
|
|
729
|
+
this.c.summary_icon = icon;
|
|
730
|
+
return this;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
const confirm = Object.assign((title) => new ConfirmB(title), {
|
|
734
|
+
danger: (title) => new ConfirmB(title).danger(),
|
|
735
|
+
});
|
|
736
|
+
/** A chain of steps: `a.confirm(..).call(..).toast(..).close()`; `onError` for the failure branch. */
|
|
737
|
+
export class Chain {
|
|
738
|
+
/** @internal */ steps = [];
|
|
739
|
+
/** @internal */ errorSteps = [];
|
|
740
|
+
confirm(c) {
|
|
741
|
+
this.steps.push({ confirm: c instanceof ConfirmB ? { ...c.c } : { title: txt(c) } });
|
|
742
|
+
return this;
|
|
743
|
+
}
|
|
744
|
+
/** Calls a `ui` endpoint as the member. */
|
|
745
|
+
call(endpoint, a) {
|
|
746
|
+
this.steps.push({ call: { endpoint: endpointRef(endpoint), args: some(args(a)) } });
|
|
747
|
+
return this;
|
|
748
|
+
}
|
|
749
|
+
/** Calls with the enclosing form's values (and `a` over them). */
|
|
750
|
+
callForm(endpoint, a) {
|
|
751
|
+
this.steps.push({ call: { endpoint: endpointRef(endpoint), args: some(args(a)), form: true } });
|
|
752
|
+
return this;
|
|
753
|
+
}
|
|
754
|
+
/** The last call shows a pending row in `rows` until a re-read returns it. */
|
|
755
|
+
pending(rows) {
|
|
756
|
+
const last = this.steps.at(-1);
|
|
757
|
+
if (last && "call" in last)
|
|
758
|
+
last.call.pending = rows.name;
|
|
759
|
+
return this;
|
|
760
|
+
}
|
|
761
|
+
toast(t, tone) {
|
|
762
|
+
this.steps.push({ toast: { text: txt(t), tone } });
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
/** In `onError`: the failing call's own message. */
|
|
766
|
+
toastError() {
|
|
767
|
+
this.steps.push({ toast: { tone: "danger", error: true } });
|
|
768
|
+
return this;
|
|
769
|
+
}
|
|
770
|
+
/** The last toast gets a second line. */
|
|
771
|
+
described(t) {
|
|
772
|
+
const last = this.steps.at(-1);
|
|
773
|
+
if (last && "toast" in last)
|
|
774
|
+
last.toast.description = txt(t);
|
|
775
|
+
return this;
|
|
776
|
+
}
|
|
777
|
+
/** The last toast gets a button running `action` (`Undo`). */
|
|
778
|
+
withButton(label, action) {
|
|
779
|
+
const last = this.steps.at(-1);
|
|
780
|
+
if (last && "toast" in last)
|
|
781
|
+
last.toast.action = { label: txt(label), action: action.name };
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
open(overlay, a) {
|
|
785
|
+
this.steps.push({ open: { overlay: overlay.id, args: some(args(a)) } });
|
|
786
|
+
return this;
|
|
787
|
+
}
|
|
788
|
+
close() {
|
|
789
|
+
this.steps.push({ close: {} });
|
|
790
|
+
return this;
|
|
791
|
+
}
|
|
792
|
+
navigate(screen, a) {
|
|
793
|
+
this.steps.push({ navigate: { screen: screen.id, args: some(args(a)) } });
|
|
794
|
+
return this;
|
|
795
|
+
}
|
|
796
|
+
back() {
|
|
797
|
+
this.steps.push({ back: {} });
|
|
798
|
+
return this;
|
|
799
|
+
}
|
|
800
|
+
set(state, v) {
|
|
801
|
+
this.steps.push({ set: { state: state.name, value: value(v) } });
|
|
802
|
+
return this;
|
|
803
|
+
}
|
|
804
|
+
setParam(param, v) {
|
|
805
|
+
this.steps.push({ set: { param: param.name, value: value(v) } });
|
|
806
|
+
return this;
|
|
807
|
+
}
|
|
808
|
+
/** Re-run these queries (none: every query of the screen). */
|
|
809
|
+
refresh(...queries) {
|
|
810
|
+
this.steps.push({ refresh: { queries: some(queries.map((q) => (typeof q === "string" ? q : q.name))) } });
|
|
811
|
+
return this;
|
|
812
|
+
}
|
|
813
|
+
openUrl(url) {
|
|
814
|
+
this.steps.push({ open_url: { value: value(url) } });
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
/** Puts the text into the composer of the item's stream (or the frame's primary composer), focused (catalog 3). */
|
|
818
|
+
draft(t) {
|
|
819
|
+
this.steps.push({ draft: { text: txt(t) } });
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
/** Adds `@<name> ` to the composer and sends `key` as its `reply` while the mention stays (catalog 3). */
|
|
823
|
+
replyTo(name, key) {
|
|
824
|
+
this.steps.push({ reply_to: { name: value(name), key: key.v } });
|
|
825
|
+
return this;
|
|
826
|
+
}
|
|
827
|
+
/** Scrolls the stream that holds an item with this key so the item is centred (catalog 3). */
|
|
828
|
+
scrollTo(key) {
|
|
829
|
+
this.steps.push({ scroll_to: { key: key.v } });
|
|
830
|
+
return this;
|
|
831
|
+
}
|
|
832
|
+
/** Copies a value to the clipboard (catalog 3). */
|
|
833
|
+
copy(v) {
|
|
834
|
+
this.steps.push({ copy: { value: value(v) } });
|
|
835
|
+
return this;
|
|
836
|
+
}
|
|
837
|
+
/** Copies the screen's link with `#<key>` (catalog 3). */
|
|
838
|
+
copyLink(key) {
|
|
839
|
+
this.steps.push({ copy: { link: value(key) } });
|
|
840
|
+
return this;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Puts a row into the loaded rows of a query (by the stream's key) until the query's next answer (catalog 3):
|
|
844
|
+
* `a.call(postMessage, ..).merge(msgs, ui.result(posted.f.message))`.
|
|
845
|
+
*/
|
|
846
|
+
merge(q, row) {
|
|
847
|
+
this.steps.push({ merge: { query: q.name, row: row.v } });
|
|
848
|
+
return this;
|
|
849
|
+
}
|
|
850
|
+
/** The steps run when a step fails. */
|
|
851
|
+
onError(build) {
|
|
852
|
+
const c = new Chain();
|
|
853
|
+
build(c);
|
|
854
|
+
this.errorSteps = c.steps;
|
|
855
|
+
return this;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
// ---------------------------------------------------------------------------------------------- nodes
|
|
859
|
+
/** A primitive with the common options: `.visible(cond)`, `.enabled(cond)`, `.fallback(node)`. */
|
|
860
|
+
export class Node extends Built {
|
|
861
|
+
kind;
|
|
862
|
+
body;
|
|
863
|
+
visibleCond;
|
|
864
|
+
enabledCond;
|
|
865
|
+
fallbackNode;
|
|
866
|
+
constructor(
|
|
867
|
+
/** @internal */ kind,
|
|
868
|
+
/** @internal */ body) {
|
|
869
|
+
super();
|
|
870
|
+
this.kind = kind;
|
|
871
|
+
this.body = body;
|
|
872
|
+
}
|
|
873
|
+
visible(c) {
|
|
874
|
+
this.visibleCond = c;
|
|
875
|
+
return this;
|
|
876
|
+
}
|
|
877
|
+
enabled(c) {
|
|
878
|
+
this.enabledCond = c;
|
|
879
|
+
return this;
|
|
880
|
+
}
|
|
881
|
+
/** What an older client draws instead (display primitives only). */
|
|
882
|
+
fallback(n) {
|
|
883
|
+
this.fallbackNode = n;
|
|
884
|
+
return this;
|
|
885
|
+
}
|
|
886
|
+
/** @internal */
|
|
887
|
+
json() {
|
|
888
|
+
return { [this.kind]: this.body, visible: this.visibleCond, enabled: this.enabledCond, fallback: this.fallbackNode };
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
const formats = {
|
|
892
|
+
money: (currency, code) => ({ money: { currency, code } }),
|
|
893
|
+
number: (decimals) => ({ number: { decimals } }),
|
|
894
|
+
percent: (decimals) => ({ percent: { decimals } }),
|
|
895
|
+
status: (tones) => ({ status: { tones: tonesJson(tones) } }),
|
|
896
|
+
plain: (name) => ({ [name]: {} }),
|
|
897
|
+
};
|
|
898
|
+
function tonesJson(tones) {
|
|
899
|
+
const out = Object.fromEntries(Object.entries(tones).filter(([, v]) => v !== undefined));
|
|
900
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
901
|
+
}
|
|
902
|
+
/** The generic primitive; its options apply to the primitives that have them (as in the other SDKs). */
|
|
903
|
+
export class N extends Node {
|
|
904
|
+
setFormat(f) {
|
|
905
|
+
if (["metric", "text", "chart"].includes(this.kind))
|
|
906
|
+
this.body.format = f;
|
|
907
|
+
if (this.kind === "card")
|
|
908
|
+
this.body.trailing_format = f;
|
|
909
|
+
return this;
|
|
910
|
+
}
|
|
911
|
+
// --- structure
|
|
912
|
+
/** The gap of a stack or row. */
|
|
913
|
+
gap(gap) {
|
|
914
|
+
if (this.kind === "stack")
|
|
915
|
+
this.body.gap = gap;
|
|
916
|
+
return this;
|
|
917
|
+
}
|
|
918
|
+
/** A horizontal stack's children spread to both ends. */
|
|
919
|
+
between() {
|
|
920
|
+
if (this.kind === "stack")
|
|
921
|
+
this.body.justify = "between";
|
|
922
|
+
return this;
|
|
923
|
+
}
|
|
924
|
+
/** A value at the end of a card's title line (a total; its format is the card's `.moneyIn(..)` and the like). */
|
|
925
|
+
trailing(v) {
|
|
926
|
+
if (this.kind === "card")
|
|
927
|
+
this.body.trailing = v;
|
|
928
|
+
return this;
|
|
929
|
+
}
|
|
930
|
+
/** Relative widths of columns (`[2, 1]`). */
|
|
931
|
+
ratios(r) {
|
|
932
|
+
if (this.kind === "columns")
|
|
933
|
+
this.body.ratios = some(r);
|
|
934
|
+
return this;
|
|
935
|
+
}
|
|
936
|
+
/** A section's description. */
|
|
937
|
+
description(t) {
|
|
938
|
+
if (this.kind === "section")
|
|
939
|
+
this.body.description = txt(t);
|
|
940
|
+
return this;
|
|
941
|
+
}
|
|
942
|
+
/** Buttons in a section's head. */
|
|
943
|
+
actions(nodes) {
|
|
944
|
+
if (this.kind === "section")
|
|
945
|
+
this.body.actions = some(nodes);
|
|
946
|
+
return this;
|
|
947
|
+
}
|
|
948
|
+
/** A section's footer. */
|
|
949
|
+
footer(nodes) {
|
|
950
|
+
if (this.kind === "section")
|
|
951
|
+
this.body.footer = some(nodes);
|
|
952
|
+
return this;
|
|
953
|
+
}
|
|
954
|
+
/** The state (or param) that holds the selected tab. */
|
|
955
|
+
bind(to) {
|
|
956
|
+
if (this.kind === "tabs")
|
|
957
|
+
this.body.bind = to instanceof StateRef ? { state: to.name } : { param: to.name };
|
|
958
|
+
return this;
|
|
959
|
+
}
|
|
960
|
+
// --- data
|
|
961
|
+
/** A metric's change next to its value. */
|
|
962
|
+
delta(v) {
|
|
963
|
+
if (this.kind === "metric")
|
|
964
|
+
this.body.delta = v;
|
|
965
|
+
return this;
|
|
966
|
+
}
|
|
967
|
+
/** A metric's, meter's or progress' caption. */
|
|
968
|
+
caption(t) {
|
|
969
|
+
if (["metric", "meter", "progress"].includes(this.kind))
|
|
970
|
+
this.body.caption = txt(t);
|
|
971
|
+
return this;
|
|
972
|
+
}
|
|
973
|
+
/** A metric's caption tone and icon (`$33.9k overdue` in red with an alert icon). */
|
|
974
|
+
captionTone(tone, icon) {
|
|
975
|
+
if (this.kind === "metric") {
|
|
976
|
+
this.body.caption_tone = tone;
|
|
977
|
+
this.body.caption_icon = icon;
|
|
978
|
+
}
|
|
979
|
+
return this;
|
|
980
|
+
}
|
|
981
|
+
/** A card's or fields' title. */
|
|
982
|
+
titled(t) {
|
|
983
|
+
if (["card", "fields", "chart"].includes(this.kind))
|
|
984
|
+
this.body.title = txt(t);
|
|
985
|
+
return this;
|
|
986
|
+
}
|
|
987
|
+
/** At most this many avatars of an avatar stack (default 5). */
|
|
988
|
+
max(n) {
|
|
989
|
+
if (this.kind === "avatar_stack")
|
|
990
|
+
this.body.max = n;
|
|
991
|
+
return this;
|
|
992
|
+
}
|
|
993
|
+
// --- formats of a metric or a text
|
|
994
|
+
moneyIn(code) {
|
|
995
|
+
return this.setFormat(formats.money(undefined, code));
|
|
996
|
+
}
|
|
997
|
+
number(decimals) {
|
|
998
|
+
return this.setFormat(formats.number(decimals));
|
|
999
|
+
}
|
|
1000
|
+
percent(decimals) {
|
|
1001
|
+
return this.setFormat(formats.percent(decimals));
|
|
1002
|
+
}
|
|
1003
|
+
date() {
|
|
1004
|
+
return this.setFormat(formats.plain("date"));
|
|
1005
|
+
}
|
|
1006
|
+
datetime() {
|
|
1007
|
+
return this.setFormat(formats.plain("datetime"));
|
|
1008
|
+
}
|
|
1009
|
+
relative() {
|
|
1010
|
+
return this.setFormat(formats.plain("relative"));
|
|
1011
|
+
}
|
|
1012
|
+
member() {
|
|
1013
|
+
return this.setFormat(formats.plain("member"));
|
|
1014
|
+
}
|
|
1015
|
+
status(tones) {
|
|
1016
|
+
return this.setFormat(formats.status(tones));
|
|
1017
|
+
}
|
|
1018
|
+
/** Counts up, live, from a moment in ms (`0:48`, `1:02:05`; catalog 3). */
|
|
1019
|
+
elapsed() {
|
|
1020
|
+
return this.setFormat(formats.plain("elapsed"));
|
|
1021
|
+
}
|
|
1022
|
+
/** Counts down, live, to a moment in ms (`8 min`; catalog 3). */
|
|
1023
|
+
countdown() {
|
|
1024
|
+
return this.setFormat(formats.plain("countdown"));
|
|
1025
|
+
}
|
|
1026
|
+
/** A duration in ms (`1m 05s`; catalog 3). */
|
|
1027
|
+
span() {
|
|
1028
|
+
return this.setFormat(formats.plain("span"));
|
|
1029
|
+
}
|
|
1030
|
+
// --- a split as an app-like screen (catalog 3)
|
|
1031
|
+
/**
|
|
1032
|
+
* A split as an app-like screen: the viewport's height under the shell's header, each side scrolling itself (its
|
|
1033
|
+
* first `stream` takes the free height), the detail an in-page side panel shown while its `visible` holds.
|
|
1034
|
+
*/
|
|
1035
|
+
fill() {
|
|
1036
|
+
if (this.kind === "split")
|
|
1037
|
+
this.body.fill = true;
|
|
1038
|
+
return this;
|
|
1039
|
+
}
|
|
1040
|
+
/** The split's panel width is dragged by its border: px from `min` to `max`, `initial` at first and on reset, the
|
|
1041
|
+
* column keeping at least `keep`. */
|
|
1042
|
+
resize(min, max, initial, keep) {
|
|
1043
|
+
if (this.kind === "split")
|
|
1044
|
+
this.body.resize = { min, max, default: initial, keep };
|
|
1045
|
+
return this;
|
|
1046
|
+
}
|
|
1047
|
+
/** The bool state the detail's header's expand button toggles: true, the detail fills the screen. */
|
|
1048
|
+
expand(state) {
|
|
1049
|
+
if (this.kind === "split")
|
|
1050
|
+
this.body.expand = { state: state.name };
|
|
1051
|
+
return this;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* An icon button as a toggle (catalog 3): `pressed` says whether it is on; the icon and label given to
|
|
1055
|
+
* `ui.iconButton` are the pressed ones, these the others. Its action reads `ui.form.pressed()`.
|
|
1056
|
+
*/
|
|
1057
|
+
toggle(pressed, iconOff, labelOff) {
|
|
1058
|
+
if (this.kind === "icon_button")
|
|
1059
|
+
Object.assign(this.body, { pressed: value(pressed), icon_off: iconOff, label_off: txt(labelOff) });
|
|
1060
|
+
return this;
|
|
1061
|
+
}
|
|
1062
|
+
// --- actions
|
|
1063
|
+
emphasis(e) {
|
|
1064
|
+
if (this.kind === "button")
|
|
1065
|
+
this.body.emphasis = e;
|
|
1066
|
+
return this;
|
|
1067
|
+
}
|
|
1068
|
+
primary() {
|
|
1069
|
+
return this.emphasis("primary");
|
|
1070
|
+
}
|
|
1071
|
+
ghost() {
|
|
1072
|
+
return this.emphasis("ghost");
|
|
1073
|
+
}
|
|
1074
|
+
danger() {
|
|
1075
|
+
return this.emphasis("danger");
|
|
1076
|
+
}
|
|
1077
|
+
/** The action a button runs. */
|
|
1078
|
+
run(action) {
|
|
1079
|
+
if (this.kind === "button")
|
|
1080
|
+
this.body.action = action.name;
|
|
1081
|
+
return this;
|
|
1082
|
+
}
|
|
1083
|
+
/** A button's, menu's or empty state's icon. */
|
|
1084
|
+
icon(icon) {
|
|
1085
|
+
if (["button", "menu", "empty"].includes(this.kind))
|
|
1086
|
+
this.body.icon = icon;
|
|
1087
|
+
return this;
|
|
1088
|
+
}
|
|
1089
|
+
/** A notice's title, or a menu's label. */
|
|
1090
|
+
title(t) {
|
|
1091
|
+
if (this.kind === "notice")
|
|
1092
|
+
this.body.title = txt(t);
|
|
1093
|
+
if (this.kind === "menu")
|
|
1094
|
+
this.body.label = txt(t);
|
|
1095
|
+
return this;
|
|
1096
|
+
}
|
|
1097
|
+
/** A notice's or an empty state's button. */
|
|
1098
|
+
withAction(b) {
|
|
1099
|
+
if (["notice", "empty"].includes(this.kind))
|
|
1100
|
+
this.body.action = b;
|
|
1101
|
+
return this;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
function n(kind, body) {
|
|
1105
|
+
return new N(kind, body);
|
|
1106
|
+
}
|
|
1107
|
+
// --- structure
|
|
1108
|
+
function stack(children) {
|
|
1109
|
+
return n("stack", { direction: "vertical", gap: "normal", children: [...children] });
|
|
1110
|
+
}
|
|
1111
|
+
function row(x) {
|
|
1112
|
+
if (x instanceof FieldRef)
|
|
1113
|
+
return new Val({ row: x.name });
|
|
1114
|
+
return n("stack", { direction: "horizontal", gap: "normal", children: [...x] });
|
|
1115
|
+
}
|
|
1116
|
+
/** Columns that stack on a phone. */
|
|
1117
|
+
function columns(children) {
|
|
1118
|
+
return n("columns", { children: [...children] });
|
|
1119
|
+
}
|
|
1120
|
+
function section(title, children) {
|
|
1121
|
+
return n("section", { title: txt(title), children: [...children] });
|
|
1122
|
+
}
|
|
1123
|
+
function card(children) {
|
|
1124
|
+
return n("card", { children: [...children] });
|
|
1125
|
+
}
|
|
1126
|
+
function divider() {
|
|
1127
|
+
return n("divider", {});
|
|
1128
|
+
}
|
|
1129
|
+
function split(list, detail) {
|
|
1130
|
+
return n("split", { list, detail });
|
|
1131
|
+
}
|
|
1132
|
+
/** One tab: its id, title and content. */
|
|
1133
|
+
export class TabB extends Built {
|
|
1134
|
+
id;
|
|
1135
|
+
title;
|
|
1136
|
+
children;
|
|
1137
|
+
badgeValue;
|
|
1138
|
+
constructor(id, title, children) {
|
|
1139
|
+
super();
|
|
1140
|
+
this.id = id;
|
|
1141
|
+
this.title = title;
|
|
1142
|
+
this.children = children;
|
|
1143
|
+
}
|
|
1144
|
+
badge(v) {
|
|
1145
|
+
this.badgeValue = v;
|
|
1146
|
+
return this;
|
|
1147
|
+
}
|
|
1148
|
+
/** @internal */
|
|
1149
|
+
json() {
|
|
1150
|
+
return { id: this.id, title: txt(this.title), badge: this.badgeValue, children: [...this.children] };
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
function tab(id, title, children) {
|
|
1154
|
+
return new TabB(id, title, children);
|
|
1155
|
+
}
|
|
1156
|
+
function tabs(list) {
|
|
1157
|
+
return n("tabs", { tabs: [...list] });
|
|
1158
|
+
}
|
|
1159
|
+
// --- navigation
|
|
1160
|
+
/**
|
|
1161
|
+
* A switch between a few options, bound to a state or to a param: a view switch,
|
|
1162
|
+
* `ui.segmented(view, [['list', 'List'], ['board', 'Board']])`, or the range of a report, in the link,
|
|
1163
|
+
* `ui.segmented(range, [['7', '7 days'], ['30', '30 days']])`. The options are values of the state's or the param's
|
|
1164
|
+
* type; give a param a default (`s.paramOr(..)`) so the switch shows it on a link without the param.
|
|
1165
|
+
*/
|
|
1166
|
+
function segmented(to, options) {
|
|
1167
|
+
return n("segmented", {
|
|
1168
|
+
bind: to instanceof StateRef ? { state: to.name } : { param: to.name },
|
|
1169
|
+
options: options.map(([v, l]) => ({ value: encode(v), label: txt(l) })),
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
function link(text, screen, a) {
|
|
1173
|
+
return n("link", { text: txt(text), target: { screen: screen.id, args: some(args(a)) } });
|
|
1174
|
+
}
|
|
1175
|
+
// --- data
|
|
1176
|
+
/** A table over a query's rows; columns and row values are handles of the row message. */
|
|
1177
|
+
export class TableB extends Node {
|
|
1178
|
+
columns = [];
|
|
1179
|
+
rowActions = [];
|
|
1180
|
+
rowTones = [];
|
|
1181
|
+
constructor(query) {
|
|
1182
|
+
super("table", { query });
|
|
1183
|
+
this.body.columns = this.columns;
|
|
1184
|
+
}
|
|
1185
|
+
column(f, title, format, align) {
|
|
1186
|
+
this.columns.push({ field: f.name, title: txt(title), format, align });
|
|
1187
|
+
return this;
|
|
1188
|
+
}
|
|
1189
|
+
col(f, title) {
|
|
1190
|
+
return this.column(f, title);
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* A column that sorts the list by the request's string field `by`: a click on its head passes `asc`, the next
|
|
1194
|
+
* `desc`, the third leaves the field out. One column sorts at a time.
|
|
1195
|
+
*/
|
|
1196
|
+
sortable(f, title, by) {
|
|
1197
|
+
this.column(f, title);
|
|
1198
|
+
this.columns[this.columns.length - 1].sort = snake(by);
|
|
1199
|
+
return this;
|
|
1200
|
+
}
|
|
1201
|
+
mono(f, title) {
|
|
1202
|
+
return this.column(f, title, formats.plain("mono"));
|
|
1203
|
+
}
|
|
1204
|
+
number(f, title, decimals) {
|
|
1205
|
+
return this.column(f, title, formats.number(decimals), "end");
|
|
1206
|
+
}
|
|
1207
|
+
/** A decimal amount in the currency of the row's field `currency`. */
|
|
1208
|
+
money(f, title, currency) {
|
|
1209
|
+
return this.column(f, title, formats.money(currency.name), "end");
|
|
1210
|
+
}
|
|
1211
|
+
/** A decimal amount in a fixed currency (`USD`). */
|
|
1212
|
+
moneyIn(f, title, code) {
|
|
1213
|
+
return this.column(f, title, formats.money(undefined, code), "end");
|
|
1214
|
+
}
|
|
1215
|
+
date(f, title) {
|
|
1216
|
+
return this.column(f, title, formats.plain("date"));
|
|
1217
|
+
}
|
|
1218
|
+
datetime(f, title) {
|
|
1219
|
+
return this.column(f, title, formats.plain("datetime"));
|
|
1220
|
+
}
|
|
1221
|
+
relative(f, title) {
|
|
1222
|
+
return this.column(f, title, formats.plain("relative"));
|
|
1223
|
+
}
|
|
1224
|
+
member(f, title) {
|
|
1225
|
+
return this.column(f, title, formats.plain("member"));
|
|
1226
|
+
}
|
|
1227
|
+
avatar(f, title) {
|
|
1228
|
+
return this.column(f, title, formats.plain("avatar"));
|
|
1229
|
+
}
|
|
1230
|
+
tags(f, title) {
|
|
1231
|
+
return this.column(f, title, formats.plain("tags"));
|
|
1232
|
+
}
|
|
1233
|
+
percent(f, title, decimals) {
|
|
1234
|
+
return this.column(f, title, formats.percent(decimals));
|
|
1235
|
+
}
|
|
1236
|
+
bool(f, title) {
|
|
1237
|
+
return this.column(f, title, formats.plain("bool"));
|
|
1238
|
+
}
|
|
1239
|
+
/** An enum column drawn as a status with a tone per value. */
|
|
1240
|
+
status(f, title, tones) {
|
|
1241
|
+
return this.column(f, title, formats.status(tones));
|
|
1242
|
+
}
|
|
1243
|
+
/** The action run when a row is opened. */
|
|
1244
|
+
open(action) {
|
|
1245
|
+
this.body.open = action.name;
|
|
1246
|
+
return this;
|
|
1247
|
+
}
|
|
1248
|
+
/** A button (or menu) on every row; a function gets the row (`r.get(order.f.status)`). */
|
|
1249
|
+
rowButton(node) {
|
|
1250
|
+
this.rowActions.push(typeof node === "function" ? node(new RowRef()) : node);
|
|
1251
|
+
this.body.row_actions = this.rowActions;
|
|
1252
|
+
return this;
|
|
1253
|
+
}
|
|
1254
|
+
/** The same as `rowButton`. */
|
|
1255
|
+
rowAction(node) {
|
|
1256
|
+
return this.rowButton(node);
|
|
1257
|
+
}
|
|
1258
|
+
/** Buttons, search and filters above the table. */
|
|
1259
|
+
toolbar(nodes) {
|
|
1260
|
+
this.body.toolbar = some(nodes);
|
|
1261
|
+
return this;
|
|
1262
|
+
}
|
|
1263
|
+
empty(t) {
|
|
1264
|
+
this.body.empty = txt(t);
|
|
1265
|
+
return this;
|
|
1266
|
+
}
|
|
1267
|
+
/** The selected row's key goes into this state. */
|
|
1268
|
+
select(state, key) {
|
|
1269
|
+
this.body.select = { state: state.name, key: key.name };
|
|
1270
|
+
return this;
|
|
1271
|
+
}
|
|
1272
|
+
/** The last column gets a second line from `f`. */
|
|
1273
|
+
secondLine(f) {
|
|
1274
|
+
const c = this.columns.at(-1);
|
|
1275
|
+
if (c)
|
|
1276
|
+
c.subtitle = f.name;
|
|
1277
|
+
return this;
|
|
1278
|
+
}
|
|
1279
|
+
/** The last column gets an avatar: a picture URL from `f`, else the value's initials. */
|
|
1280
|
+
withAvatar(f) {
|
|
1281
|
+
const c = this.columns.at(-1);
|
|
1282
|
+
if (c)
|
|
1283
|
+
c.avatar = f.name;
|
|
1284
|
+
return this;
|
|
1285
|
+
}
|
|
1286
|
+
/** Rows can be checked; `state` holds the checked keys. */
|
|
1287
|
+
checks(state, key) {
|
|
1288
|
+
this.body.checks = { state: state.name, key: key.name };
|
|
1289
|
+
return this;
|
|
1290
|
+
}
|
|
1291
|
+
/** How many rows there are in all (`Showing 1–10 of 1,248`). */
|
|
1292
|
+
count(v) {
|
|
1293
|
+
this.body.count = v;
|
|
1294
|
+
return this;
|
|
1295
|
+
}
|
|
1296
|
+
/** The line over the compact rows (`412 of 1,248 orders · newest first`); the count alone when absent. */
|
|
1297
|
+
countLabel(t) {
|
|
1298
|
+
this.body.count_label = txt(t);
|
|
1299
|
+
return this;
|
|
1300
|
+
}
|
|
1301
|
+
/** The row as a list item where a table does not fit (`(r) => r.view(r.get(order.f.customer)).subtitle(..)`). */
|
|
1302
|
+
compact(view) {
|
|
1303
|
+
this.body.compact = view(new RowRef());
|
|
1304
|
+
return this;
|
|
1305
|
+
}
|
|
1306
|
+
/** The row whose key is in this param is drawn selected (a record panel next to the list). */
|
|
1307
|
+
selectedBy(param, key) {
|
|
1308
|
+
this.body.select = { state: param.name, key: key.name };
|
|
1309
|
+
return this;
|
|
1310
|
+
}
|
|
1311
|
+
/** A tone for rows that match (first match wins). */
|
|
1312
|
+
rowTone(when, tone) {
|
|
1313
|
+
this.rowTones.push({ when: typeof when === "function" ? when(new RowRef()) : when, tone });
|
|
1314
|
+
this.body.row_tone = this.rowTones;
|
|
1315
|
+
return this;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
function table(q) {
|
|
1319
|
+
return new TableB(q.name);
|
|
1320
|
+
}
|
|
1321
|
+
/** A list over a query's rows: a title per row, optionally a subtitle, meta, avatar, status. */
|
|
1322
|
+
export class ListB extends Node {
|
|
1323
|
+
rowActions = [];
|
|
1324
|
+
constructor(query, title) {
|
|
1325
|
+
super("list", { query, title });
|
|
1326
|
+
}
|
|
1327
|
+
subtitle(f) {
|
|
1328
|
+
this.body.subtitle = f.name;
|
|
1329
|
+
return this;
|
|
1330
|
+
}
|
|
1331
|
+
meta(f) {
|
|
1332
|
+
this.body.meta = f.name;
|
|
1333
|
+
return this;
|
|
1334
|
+
}
|
|
1335
|
+
/** Meta shown as a relative time ("5 min ago"). */
|
|
1336
|
+
metaRelative(f) {
|
|
1337
|
+
this.body.meta = f.name;
|
|
1338
|
+
this.body.meta_format = formats.plain("relative");
|
|
1339
|
+
return this;
|
|
1340
|
+
}
|
|
1341
|
+
avatar(f) {
|
|
1342
|
+
this.body.avatar = f.name;
|
|
1343
|
+
return this;
|
|
1344
|
+
}
|
|
1345
|
+
icon(icon) {
|
|
1346
|
+
this.body.icon = icon;
|
|
1347
|
+
return this;
|
|
1348
|
+
}
|
|
1349
|
+
/** A row field naming the row's icon. */
|
|
1350
|
+
iconField(f) {
|
|
1351
|
+
this.body.icon_field = f.name;
|
|
1352
|
+
return this;
|
|
1353
|
+
}
|
|
1354
|
+
/** A quiet text before the meta (`×2`). */
|
|
1355
|
+
aside(t) {
|
|
1356
|
+
this.body.aside = txt(t);
|
|
1357
|
+
return this;
|
|
1358
|
+
}
|
|
1359
|
+
/** The meta is money in a currency. */
|
|
1360
|
+
moneyIn(code) {
|
|
1361
|
+
this.body.meta_format = formats.money(undefined, code);
|
|
1362
|
+
return this;
|
|
1363
|
+
}
|
|
1364
|
+
status(f, tones) {
|
|
1365
|
+
this.body.status = { field: f.name, tones: tonesJson(tones) };
|
|
1366
|
+
return this;
|
|
1367
|
+
}
|
|
1368
|
+
open(action) {
|
|
1369
|
+
this.body.open = action.name;
|
|
1370
|
+
return this;
|
|
1371
|
+
}
|
|
1372
|
+
rowButton(node) {
|
|
1373
|
+
this.rowActions.push(typeof node === "function" ? node(new RowRef()) : node);
|
|
1374
|
+
this.body.row_actions = this.rowActions;
|
|
1375
|
+
return this;
|
|
1376
|
+
}
|
|
1377
|
+
empty(t) {
|
|
1378
|
+
this.body.empty = txt(t);
|
|
1379
|
+
return this;
|
|
1380
|
+
}
|
|
1381
|
+
/** A filter box over the rows' titles with this placeholder; it filters the loaded rows, no request (catalog 3). */
|
|
1382
|
+
search(placeholder) {
|
|
1383
|
+
this.body.search = txt(placeholder);
|
|
1384
|
+
return this;
|
|
1385
|
+
}
|
|
1386
|
+
/** A green dot after the title while this field is true (catalog 3). */
|
|
1387
|
+
online(f) {
|
|
1388
|
+
this.body.online = f.name;
|
|
1389
|
+
return this;
|
|
1390
|
+
}
|
|
1391
|
+
/** On a phone, the first `n` rows (1 to 100), then `Show all` (catalog 3). */
|
|
1392
|
+
limit(n) {
|
|
1393
|
+
this.body.limit = n;
|
|
1394
|
+
return this;
|
|
1395
|
+
}
|
|
1396
|
+
/** On a phone, a label over the rows in a card (`People · 9`; catalog 3). */
|
|
1397
|
+
groupLabel(t) {
|
|
1398
|
+
this.body.group_label = txt(t);
|
|
1399
|
+
return this;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
function list(q, title) {
|
|
1403
|
+
return new ListB(q.name, title.name);
|
|
1404
|
+
}
|
|
1405
|
+
/** One label/value pair of `ui.fields` (`ui.item('Total', order.field(..)).moneyIn('USD')`). */
|
|
1406
|
+
export class ItemB extends Built {
|
|
1407
|
+
label;
|
|
1408
|
+
v;
|
|
1409
|
+
format;
|
|
1410
|
+
target;
|
|
1411
|
+
avatarValue;
|
|
1412
|
+
constructor(label, v) {
|
|
1413
|
+
super();
|
|
1414
|
+
this.label = label;
|
|
1415
|
+
this.v = v;
|
|
1416
|
+
}
|
|
1417
|
+
setFormat(f) {
|
|
1418
|
+
this.format = f;
|
|
1419
|
+
return this;
|
|
1420
|
+
}
|
|
1421
|
+
moneyIn(code) {
|
|
1422
|
+
return this.setFormat(formats.money(undefined, code));
|
|
1423
|
+
}
|
|
1424
|
+
number(decimals) {
|
|
1425
|
+
return this.setFormat(formats.number(decimals));
|
|
1426
|
+
}
|
|
1427
|
+
percent(decimals) {
|
|
1428
|
+
return this.setFormat(formats.percent(decimals));
|
|
1429
|
+
}
|
|
1430
|
+
date() {
|
|
1431
|
+
return this.setFormat(formats.plain("date"));
|
|
1432
|
+
}
|
|
1433
|
+
datetime() {
|
|
1434
|
+
return this.setFormat(formats.plain("datetime"));
|
|
1435
|
+
}
|
|
1436
|
+
relative() {
|
|
1437
|
+
return this.setFormat(formats.plain("relative"));
|
|
1438
|
+
}
|
|
1439
|
+
member() {
|
|
1440
|
+
return this.setFormat(formats.plain("member"));
|
|
1441
|
+
}
|
|
1442
|
+
bool() {
|
|
1443
|
+
return this.setFormat(formats.plain("bool"));
|
|
1444
|
+
}
|
|
1445
|
+
mono() {
|
|
1446
|
+
return this.setFormat(formats.plain("mono"));
|
|
1447
|
+
}
|
|
1448
|
+
status(tones) {
|
|
1449
|
+
return this.setFormat(formats.status(tones));
|
|
1450
|
+
}
|
|
1451
|
+
/** The value links to a screen (a chip with an arrow). */
|
|
1452
|
+
link(screen, a) {
|
|
1453
|
+
this.target = { screen: screen.id, args: some(args(a)) };
|
|
1454
|
+
return this;
|
|
1455
|
+
}
|
|
1456
|
+
/** The value drawn as a chip with initials. */
|
|
1457
|
+
chip() {
|
|
1458
|
+
return this.setFormat(formats.plain("avatar"));
|
|
1459
|
+
}
|
|
1460
|
+
/** The chip's picture URL or initials. */
|
|
1461
|
+
chipAvatar(v) {
|
|
1462
|
+
this.avatarValue = v;
|
|
1463
|
+
return this.setFormat(formats.plain("avatar"));
|
|
1464
|
+
}
|
|
1465
|
+
/** @internal */
|
|
1466
|
+
json() {
|
|
1467
|
+
return { label: txt(this.label), value: this.v, format: this.format, open: this.target, avatar: this.avatarValue };
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
/** Label/value pairs of one record. */
|
|
1471
|
+
function fields(items) {
|
|
1472
|
+
return n("fields", { items: [...items] });
|
|
1473
|
+
}
|
|
1474
|
+
function item(label, v) {
|
|
1475
|
+
return new ItemB(label, v);
|
|
1476
|
+
}
|
|
1477
|
+
function metric(title, v) {
|
|
1478
|
+
return n("metric", { title: txt(title), value: v });
|
|
1479
|
+
}
|
|
1480
|
+
/**
|
|
1481
|
+
* A chart over a query's rows: the first charts (catalog 1), kept for compatibility. New screens use `ui.viz`
|
|
1482
|
+
* (`ui.viz.bar.column()`, `ui.viz.line.line()`, …), which has every kind of the charts catalogue.
|
|
1483
|
+
*/
|
|
1484
|
+
export class ChartB extends Node {
|
|
1485
|
+
seriesList = [];
|
|
1486
|
+
constructor(kind, query, x) {
|
|
1487
|
+
super("chart", { kind, query, x });
|
|
1488
|
+
this.body.series = this.seriesList;
|
|
1489
|
+
}
|
|
1490
|
+
series(f, label) {
|
|
1491
|
+
this.seriesList.push({ field: f.name, label: txt(label) });
|
|
1492
|
+
return this;
|
|
1493
|
+
}
|
|
1494
|
+
title(t) {
|
|
1495
|
+
this.body.title = txt(t);
|
|
1496
|
+
return this;
|
|
1497
|
+
}
|
|
1498
|
+
moneyIn(code) {
|
|
1499
|
+
this.body.format = formats.money(undefined, code);
|
|
1500
|
+
return this;
|
|
1501
|
+
}
|
|
1502
|
+
number(decimals) {
|
|
1503
|
+
this.body.format = formats.number(decimals);
|
|
1504
|
+
return this;
|
|
1505
|
+
}
|
|
1506
|
+
percent(decimals) {
|
|
1507
|
+
this.body.format = formats.percent(decimals);
|
|
1508
|
+
return this;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
function chartOf(kind) {
|
|
1512
|
+
return (q, x) => new ChartB(kind, q.name, x.name);
|
|
1513
|
+
}
|
|
1514
|
+
// --- dashboards
|
|
1515
|
+
/**
|
|
1516
|
+
* A dashboard (catalog revision 2): cards on one shared 12-column grid. The items flow left to right and wrap when a
|
|
1517
|
+
* row is full; every row is as tall as its tallest card, and a narrower screen widens the cards.
|
|
1518
|
+
*
|
|
1519
|
+
* ui.board().quarter(revenue).quarter(orders).half(target).full(ui.heading('Sales')).span(8, line).third(donut)
|
|
1520
|
+
*
|
|
1521
|
+
* A chart is placed on the board itself (it draws its own card). A board is not put inside another board, and holds
|
|
1522
|
+
* at most 60 items. An older client (catalog 1) draws the board's `.fallback(..)`.
|
|
1523
|
+
*/
|
|
1524
|
+
export class BoardB extends Node {
|
|
1525
|
+
items = [];
|
|
1526
|
+
constructor() {
|
|
1527
|
+
super("board", {});
|
|
1528
|
+
this.body.children = this.items;
|
|
1529
|
+
}
|
|
1530
|
+
/** An item `columns` wide, of the grid's 12. */
|
|
1531
|
+
span(columns, n) {
|
|
1532
|
+
this.items.push({ span: columns === 12 ? undefined : columns, node: n });
|
|
1533
|
+
return this;
|
|
1534
|
+
}
|
|
1535
|
+
/** An item of the full width: a wide chart, a table, a heading between groups. */
|
|
1536
|
+
full(n) {
|
|
1537
|
+
return this.span(12, n);
|
|
1538
|
+
}
|
|
1539
|
+
/** An item of half the width (6 columns). */
|
|
1540
|
+
half(n) {
|
|
1541
|
+
return this.span(6, n);
|
|
1542
|
+
}
|
|
1543
|
+
/** An item of a third of the width (4 columns). */
|
|
1544
|
+
third(n) {
|
|
1545
|
+
return this.span(4, n);
|
|
1546
|
+
}
|
|
1547
|
+
/** An item of a quarter of the width (3 columns): a row of four metrics. */
|
|
1548
|
+
quarter(n) {
|
|
1549
|
+
return this.span(3, n);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
function board() {
|
|
1553
|
+
return new BoardB();
|
|
1554
|
+
}
|
|
1555
|
+
/**
|
|
1556
|
+
* A chart or a figure of the charts catalogue (catalog revision 2): a kind of a family, its static options and the
|
|
1557
|
+
* data bound into them from the screen's queries.
|
|
1558
|
+
*
|
|
1559
|
+
* ui.viz.line.line().title('Revenue').range('Last 30 days').option('fmt', 'money')
|
|
1560
|
+
* .dates(sales, day.f.day).values(sales, day.f.total).open(ORDERS)
|
|
1561
|
+
*
|
|
1562
|
+
* The data methods add a bind each, in order; `.to(..)`, `.asText()`, `.asDate()` and `.textKeys(..)` change the
|
|
1563
|
+
* bind just added. A chart draws its own card: place it on a `ui.board()`, in columns or in a stack, not next to
|
|
1564
|
+
* other children of a card or a section. An older client (catalog 1) draws the node's `.fallback(..)`.
|
|
1565
|
+
*/
|
|
1566
|
+
export class VizB extends Node {
|
|
1567
|
+
binds = [];
|
|
1568
|
+
constructor(family, kind) {
|
|
1569
|
+
super("viz", { family, kind });
|
|
1570
|
+
}
|
|
1571
|
+
title(t) {
|
|
1572
|
+
this.body.title = txt(t);
|
|
1573
|
+
return this;
|
|
1574
|
+
}
|
|
1575
|
+
/** The muted text at the right of the head (`Last 30 days`). */
|
|
1576
|
+
range(t) {
|
|
1577
|
+
this.body.range = txt(t);
|
|
1578
|
+
return this;
|
|
1579
|
+
}
|
|
1580
|
+
/** The height in px (16 to 1200); the kind's own height when not set. */
|
|
1581
|
+
height(px) {
|
|
1582
|
+
this.body.height = px;
|
|
1583
|
+
return this;
|
|
1584
|
+
}
|
|
1585
|
+
/** A static option of the kind: `.option('fmt', 'money')`, `.option('bands', [50, 80])`. */
|
|
1586
|
+
option(name, value) {
|
|
1587
|
+
return this.options({ [name]: value });
|
|
1588
|
+
}
|
|
1589
|
+
/** Several static options at once: `.options({ fmt: 'money', curve: 'smooth' })`. */
|
|
1590
|
+
options(options) {
|
|
1591
|
+
this.body.options = { ...this.body.options, ...options };
|
|
1592
|
+
return this;
|
|
1593
|
+
}
|
|
1594
|
+
/** A bind written by hand (the typed methods below cover the sources). */
|
|
1595
|
+
bind(to, from) {
|
|
1596
|
+
this.binds.push({ to, from });
|
|
1597
|
+
this.body.bind = this.binds;
|
|
1598
|
+
return this;
|
|
1599
|
+
}
|
|
1600
|
+
last(source) {
|
|
1601
|
+
return this.binds.at(-1)?.from[source];
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* A row field of every row, as an array in the option `to`. Numbers and numeric strings become numbers;
|
|
1605
|
+
* `.asText()` keeps strings, `.asDate()` makes short date labels.
|
|
1606
|
+
*/
|
|
1607
|
+
column(to, q, f) {
|
|
1608
|
+
return this.bind(to, { column: { query: q.name, field: f.name } });
|
|
1609
|
+
}
|
|
1610
|
+
/** The `labels` (the x positions or the row names) from a row field, kept as text. */
|
|
1611
|
+
labels(q, f) {
|
|
1612
|
+
return this.column("labels", q, f).asText();
|
|
1613
|
+
}
|
|
1614
|
+
/** The `labels` from a date or timestamp field, as short dates (`Nov 4`). */
|
|
1615
|
+
dates(q, f) {
|
|
1616
|
+
return this.column("labels", q, f).asDate();
|
|
1617
|
+
}
|
|
1618
|
+
/** The `values` (one series) from a row field. */
|
|
1619
|
+
values(q, f) {
|
|
1620
|
+
return this.column("values", q, f);
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* One more series of the option `series`: the row field with its name in the legend. Calls one after another
|
|
1624
|
+
* over the same query (also after `.series(..)`) make one bind.
|
|
1625
|
+
*/
|
|
1626
|
+
serie(q, f, label) {
|
|
1627
|
+
const s = { field: f.name, label: txt(label) };
|
|
1628
|
+
const last = this.last("series");
|
|
1629
|
+
if (last && this.binds.at(-1).to === "series" && last.query === q.name) {
|
|
1630
|
+
last.fields.push(s);
|
|
1631
|
+
return this;
|
|
1632
|
+
}
|
|
1633
|
+
return this.bind("series", { series: { query: q.name, fields: [s] } });
|
|
1634
|
+
}
|
|
1635
|
+
/** The option `series`, one series per row field: `.series(q, [[day.f.online, 'Online'], [day.f.retail, 'Retail']])`. */
|
|
1636
|
+
series(q, fields) {
|
|
1637
|
+
return this.bind("series", { series: { query: q.name, fields: fields.map(([f, l]) => ({ field: f.name, label: txt(l) })) } });
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Long rows to wide: `labels` gets the distinct values of `x` in row order, the option `series` one series per
|
|
1641
|
+
* distinct value of `series`, with `value` in its cells (`.asDate()` makes the labels short dates).
|
|
1642
|
+
*/
|
|
1643
|
+
pivot(q, x, series, value) {
|
|
1644
|
+
return this.bind("series", { pivot: { query: q.name, x: x.name, series: series.name, value: value.name } });
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* The option `rows`: an object per row with the keys given, each from a row field:
|
|
1648
|
+
* `.rows(top, { name: product.f.title, value: product.f.revenue })`. Numeric strings become numbers except under
|
|
1649
|
+
* the keys named by `.textKeys(..)`.
|
|
1650
|
+
*/
|
|
1651
|
+
rows(q, map) {
|
|
1652
|
+
return this.bind("rows", { rows: { query: q.name, map: Object.fromEntries(Object.entries(map).map(([k, f]) => [k, f.name])) } });
|
|
1653
|
+
}
|
|
1654
|
+
/** The keys of the `rows` bind just added that stay text (a product named `2024` is not a number). */
|
|
1655
|
+
textKeys(keys) {
|
|
1656
|
+
const rows = this.last("rows");
|
|
1657
|
+
if (rows && keys.length > 0)
|
|
1658
|
+
rows.text = [...(rows.text ?? []), ...keys];
|
|
1659
|
+
return this;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* One value in the option `to` (a name or a dotted path: `center.value`): a query's field
|
|
1663
|
+
* (`summary.field(summaryResponse.f.revenue)`), a state, a param or a literal.
|
|
1664
|
+
*/
|
|
1665
|
+
value(to, v) {
|
|
1666
|
+
return this.bind(to, { value: value(v) });
|
|
1667
|
+
}
|
|
1668
|
+
/** Another option for the bind just added: `.rows(q, ..).to('parts')`, `.series(q, ..).to('groups')`. */
|
|
1669
|
+
to(to) {
|
|
1670
|
+
const last = this.binds.at(-1);
|
|
1671
|
+
if (last)
|
|
1672
|
+
last.to = to;
|
|
1673
|
+
return this;
|
|
1674
|
+
}
|
|
1675
|
+
cast(as) {
|
|
1676
|
+
const last = this.last("column") ?? this.last("pivot");
|
|
1677
|
+
if (last)
|
|
1678
|
+
last.as = as;
|
|
1679
|
+
return this;
|
|
1680
|
+
}
|
|
1681
|
+
/** The `column` just added keeps its cells as text (the labels of a `pivot` too). */
|
|
1682
|
+
asText() {
|
|
1683
|
+
return this.cast("text");
|
|
1684
|
+
}
|
|
1685
|
+
/** The `column` just added (or the labels of the `pivot`) holds ISO dates or datetimes: they become short labels. */
|
|
1686
|
+
asDate() {
|
|
1687
|
+
return this.cast("date");
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* The state that receives what the member picks in the chart (a bar, a slice, a row): the picked value, or null
|
|
1691
|
+
* when nothing is picked. Queries and conditions of the screen read it like any state.
|
|
1692
|
+
*/
|
|
1693
|
+
selectState(state) {
|
|
1694
|
+
this.body.select = { state: state.name };
|
|
1695
|
+
return this;
|
|
1696
|
+
}
|
|
1697
|
+
/** The same, into a param of the screen (it is in the URL). */
|
|
1698
|
+
selectParam(param) {
|
|
1699
|
+
this.body.select = { param: param.name };
|
|
1700
|
+
return this;
|
|
1701
|
+
}
|
|
1702
|
+
/** The screen the card's link leads to, with its params like `ui.link` (a literal, a param, a state): `.open(ORDERS, { status: 'paid' })`. */
|
|
1703
|
+
open(screen, a) {
|
|
1704
|
+
this.body.open = { screen: screen.id, args: some(args(a)) };
|
|
1705
|
+
return this;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
function vizOf(family, kind) {
|
|
1709
|
+
return new VizB(family, kind);
|
|
1710
|
+
}
|
|
1711
|
+
/** `ui.viz('line', 'line')`, or a constructor per kind: `ui.viz.line.line()`, `ui.viz.bar.column()`, `ui.viz.figure.metric()`. */
|
|
1712
|
+
const viz = Object.assign(vizOf, Object.fromEntries(Object.entries(VIZ_KINDS).map(([family, kinds]) => [family, Object.fromEntries(kinds.map((kind) => [kind, () => new VizB(family, kind)]))])));
|
|
1713
|
+
/** A timeline over a query's rows: text, time and optionally the actor. */
|
|
1714
|
+
export class TimelineB extends Node {
|
|
1715
|
+
constructor(query, text, time) {
|
|
1716
|
+
super("timeline", { query, text, time });
|
|
1717
|
+
}
|
|
1718
|
+
actor(f) {
|
|
1719
|
+
this.body.actor = f.name;
|
|
1720
|
+
return this;
|
|
1721
|
+
}
|
|
1722
|
+
/** The actor's picture URL (else initials). */
|
|
1723
|
+
avatar(f) {
|
|
1724
|
+
this.body.avatar = f.name;
|
|
1725
|
+
return this;
|
|
1726
|
+
}
|
|
1727
|
+
/** A row field with an icon name for actors without a face. */
|
|
1728
|
+
icon(f) {
|
|
1729
|
+
this.body.icon = f.name;
|
|
1730
|
+
return this;
|
|
1731
|
+
}
|
|
1732
|
+
/** Times as `2 min`, `40 min`, `2 h`. */
|
|
1733
|
+
shortTime() {
|
|
1734
|
+
this.body.time_format = { relative: { short: true } };
|
|
1735
|
+
return this;
|
|
1736
|
+
}
|
|
1737
|
+
tone(f, tones) {
|
|
1738
|
+
this.body.tone = { field: f.name, tones: tonesJson(tones) };
|
|
1739
|
+
return this;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
function timeline(q, text, time) {
|
|
1743
|
+
return new TimelineB(q.name, text.name, time.name);
|
|
1744
|
+
}
|
|
1745
|
+
function status(v, tones = {}) {
|
|
1746
|
+
return n("status", { value: v, tones: tonesJson(tones) });
|
|
1747
|
+
}
|
|
1748
|
+
function tag(t) {
|
|
1749
|
+
return n("tag", { text: txt(t) });
|
|
1750
|
+
}
|
|
1751
|
+
function avatar(v) {
|
|
1752
|
+
return n("avatar", { value: v });
|
|
1753
|
+
}
|
|
1754
|
+
function avatarStack(v) {
|
|
1755
|
+
return n("avatar_stack", { value: v, max: 5 });
|
|
1756
|
+
}
|
|
1757
|
+
function meter(v, max) {
|
|
1758
|
+
return n("meter", { value: v, max });
|
|
1759
|
+
}
|
|
1760
|
+
/** A fraction 0..1. */
|
|
1761
|
+
function progress(v) {
|
|
1762
|
+
return n("progress", { value: v });
|
|
1763
|
+
}
|
|
1764
|
+
function textNode(t, style) {
|
|
1765
|
+
return n("text", { text: txt(t), style });
|
|
1766
|
+
}
|
|
1767
|
+
function text(a, en, a2) {
|
|
1768
|
+
if (typeof a === "string" && en !== undefined) {
|
|
1769
|
+
return new TextKey(a, en, Object.fromEntries(Object.entries(a2 ?? {}).map(([k, v]) => [k, value(v)])));
|
|
1770
|
+
}
|
|
1771
|
+
return textNode(a, "body");
|
|
1772
|
+
}
|
|
1773
|
+
function heading(t) {
|
|
1774
|
+
return textNode(t, "heading");
|
|
1775
|
+
}
|
|
1776
|
+
function caption(t) {
|
|
1777
|
+
return textNode(t, "caption");
|
|
1778
|
+
}
|
|
1779
|
+
function mono(t) {
|
|
1780
|
+
return textNode(t, "mono");
|
|
1781
|
+
}
|
|
1782
|
+
function copyField(label, v) {
|
|
1783
|
+
return n("copy_field", { value: v, label: txt(label) });
|
|
1784
|
+
}
|
|
1785
|
+
function empty(title, t) {
|
|
1786
|
+
return n("empty", { title: txt(title), text: t === undefined ? undefined : txt(t) });
|
|
1787
|
+
}
|
|
1788
|
+
function notice(tone, t) {
|
|
1789
|
+
return n("notice", { tone, text: txt(t) });
|
|
1790
|
+
}
|
|
1791
|
+
// --- actions
|
|
1792
|
+
/** A button running an action (`ui.button('Cancel', cancel)` or `ui.button('Cancel').run(cancel)`). */
|
|
1793
|
+
function button(label, action) {
|
|
1794
|
+
return n("button", { label: txt(label), action: action?.name ?? "", emphasis: "secondary" });
|
|
1795
|
+
}
|
|
1796
|
+
function iconButton(icon, label, action) {
|
|
1797
|
+
return n("icon_button", { icon, label: txt(label), action: action.name });
|
|
1798
|
+
}
|
|
1799
|
+
/** A menu item running an action. */
|
|
1800
|
+
export class MenuItemB extends Built {
|
|
1801
|
+
m;
|
|
1802
|
+
constructor(label, action) {
|
|
1803
|
+
super();
|
|
1804
|
+
this.m = { label: txt(label), action: action.name };
|
|
1805
|
+
}
|
|
1806
|
+
danger() {
|
|
1807
|
+
this.m.danger = true;
|
|
1808
|
+
return this;
|
|
1809
|
+
}
|
|
1810
|
+
icon(icon) {
|
|
1811
|
+
this.m.icon = icon;
|
|
1812
|
+
return this;
|
|
1813
|
+
}
|
|
1814
|
+
/** Shown only when the condition holds. */
|
|
1815
|
+
when(c) {
|
|
1816
|
+
this.m.visible = c;
|
|
1817
|
+
return this;
|
|
1818
|
+
}
|
|
1819
|
+
enabled(c) {
|
|
1820
|
+
this.m.enabled = c;
|
|
1821
|
+
return this;
|
|
1822
|
+
}
|
|
1823
|
+
/** Starts a new group with this title. */
|
|
1824
|
+
section(t) {
|
|
1825
|
+
this.m.section = txt(t);
|
|
1826
|
+
return this;
|
|
1827
|
+
}
|
|
1828
|
+
/** @internal */
|
|
1829
|
+
json() {
|
|
1830
|
+
return this.m;
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
function menuItem(label, action) {
|
|
1834
|
+
return new MenuItemB(label, action);
|
|
1835
|
+
}
|
|
1836
|
+
function menu(items) {
|
|
1837
|
+
return n("menu", { icon: "more-horizontal", items: [...items] });
|
|
1838
|
+
}
|
|
1839
|
+
// --- input
|
|
1840
|
+
/** A form or filter input. */
|
|
1841
|
+
export class InputB extends Built {
|
|
1842
|
+
i;
|
|
1843
|
+
constructor(/** @internal */ i) {
|
|
1844
|
+
super();
|
|
1845
|
+
this.i = i;
|
|
1846
|
+
}
|
|
1847
|
+
required() {
|
|
1848
|
+
this.i.required = true;
|
|
1849
|
+
return this;
|
|
1850
|
+
}
|
|
1851
|
+
help(t) {
|
|
1852
|
+
this.i.help = txt(t);
|
|
1853
|
+
return this;
|
|
1854
|
+
}
|
|
1855
|
+
placeholder(t) {
|
|
1856
|
+
this.i.placeholder = txt(t);
|
|
1857
|
+
return this;
|
|
1858
|
+
}
|
|
1859
|
+
initial(v) {
|
|
1860
|
+
this.i.initial = v;
|
|
1861
|
+
return this;
|
|
1862
|
+
}
|
|
1863
|
+
/** A literal option of a select, multi-select or radio cards. */
|
|
1864
|
+
option(v, label) {
|
|
1865
|
+
const options = this.i.options ?? [];
|
|
1866
|
+
options.push({ value: encode(v), label: txt(label) });
|
|
1867
|
+
this.i.options = options;
|
|
1868
|
+
return this;
|
|
1869
|
+
}
|
|
1870
|
+
/** `repeat`: rows at least / at most. */
|
|
1871
|
+
items(min, max) {
|
|
1872
|
+
this.i.min_items = min;
|
|
1873
|
+
this.i.max_items = max;
|
|
1874
|
+
return this;
|
|
1875
|
+
}
|
|
1876
|
+
/** A filter chip's icon. */
|
|
1877
|
+
icon(icon) {
|
|
1878
|
+
this.i.icon = icon;
|
|
1879
|
+
return this;
|
|
1880
|
+
}
|
|
1881
|
+
/** Shares its line with the next half input. */
|
|
1882
|
+
half() {
|
|
1883
|
+
this.i.width = "half";
|
|
1884
|
+
return this;
|
|
1885
|
+
}
|
|
1886
|
+
/** A number with − and + buttons. */
|
|
1887
|
+
stepper() {
|
|
1888
|
+
this.i.stepper = true;
|
|
1889
|
+
return this;
|
|
1890
|
+
}
|
|
1891
|
+
/** `repeat`: a value at the end of each row from the i-th row of `q` (a line total from a quote). */
|
|
1892
|
+
aside(title, q, f, moneyIn) {
|
|
1893
|
+
this.i.aside = { title: txt(title), query: q.name, field: f.name, format: formats.money(undefined, moneyIn) };
|
|
1894
|
+
return this;
|
|
1895
|
+
}
|
|
1896
|
+
/** `repeat`: the add row's label. */
|
|
1897
|
+
addLabel(t) {
|
|
1898
|
+
this.i.add_label = txt(t);
|
|
1899
|
+
return this;
|
|
1900
|
+
}
|
|
1901
|
+
/** @internal */
|
|
1902
|
+
json() {
|
|
1903
|
+
return this.i;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
/** Inputs that set params (a filter bar over a list screen). */
|
|
1907
|
+
function filterBar(inputs) {
|
|
1908
|
+
return n("filter_bar", { inputs: [...inputs] });
|
|
1909
|
+
}
|
|
1910
|
+
/** The inputs of a form over `Req`. */
|
|
1911
|
+
export class FormB {
|
|
1912
|
+
/** @internal */ sections = [{ inputs: [] }];
|
|
1913
|
+
/** @internal */ cancelLabel;
|
|
1914
|
+
/** @internal */ phoneSubmitLabel;
|
|
1915
|
+
/** @internal */ summaryValue;
|
|
1916
|
+
/** @internal */ noteText;
|
|
1917
|
+
/** @internal */ alternateButton;
|
|
1918
|
+
/** @internal */ notes = [];
|
|
1919
|
+
input(f, control, label) {
|
|
1920
|
+
const i = new InputB({ name: f.name, control, label: txt(label) });
|
|
1921
|
+
this.sections[this.sections.length - 1].inputs.push(i);
|
|
1922
|
+
return i;
|
|
1923
|
+
}
|
|
1924
|
+
/** Starts a titled section. */
|
|
1925
|
+
section(title) {
|
|
1926
|
+
this.sections.push({ title: txt(title), inputs: [] });
|
|
1927
|
+
return this;
|
|
1928
|
+
}
|
|
1929
|
+
cancel(label) {
|
|
1930
|
+
this.cancelLabel = txt(label);
|
|
1931
|
+
return this;
|
|
1932
|
+
}
|
|
1933
|
+
/** The submit button's label on a phone, where the form is a sheet (absent: the submit label). */
|
|
1934
|
+
phoneSubmit(label) {
|
|
1935
|
+
this.phoneSubmitLabel = txt(label);
|
|
1936
|
+
return this;
|
|
1937
|
+
}
|
|
1938
|
+
text(f, label) {
|
|
1939
|
+
return this.input(f, "text", label);
|
|
1940
|
+
}
|
|
1941
|
+
textarea(f, label) {
|
|
1942
|
+
return this.input(f, "textarea", label);
|
|
1943
|
+
}
|
|
1944
|
+
number(f, label) {
|
|
1945
|
+
return this.input(f, "number", label);
|
|
1946
|
+
}
|
|
1947
|
+
money(f, label) {
|
|
1948
|
+
return this.input(f, "money", label);
|
|
1949
|
+
}
|
|
1950
|
+
date(f, label) {
|
|
1951
|
+
return this.input(f, "date", label);
|
|
1952
|
+
}
|
|
1953
|
+
datetime(f, label) {
|
|
1954
|
+
return this.input(f, "datetime", label);
|
|
1955
|
+
}
|
|
1956
|
+
checkbox(f, label) {
|
|
1957
|
+
return this.input(f, "checkbox", label);
|
|
1958
|
+
}
|
|
1959
|
+
switch(f, label) {
|
|
1960
|
+
return this.input(f, "switch", label);
|
|
1961
|
+
}
|
|
1962
|
+
member(f, label) {
|
|
1963
|
+
return this.input(f, "member", label);
|
|
1964
|
+
}
|
|
1965
|
+
upload(f, label) {
|
|
1966
|
+
return this.input(f, "upload", label);
|
|
1967
|
+
}
|
|
1968
|
+
search(f, label) {
|
|
1969
|
+
return this.input(f, "search", label);
|
|
1970
|
+
}
|
|
1971
|
+
/** A select over an enum's values (or `.option(..)`). */
|
|
1972
|
+
select(f, label) {
|
|
1973
|
+
const i = this.input(f, "select", label);
|
|
1974
|
+
i.i.options = some(enumOptions(f.field));
|
|
1975
|
+
return i;
|
|
1976
|
+
}
|
|
1977
|
+
/** A multi-select over a repeated enum's values (or `.option(..)`). */
|
|
1978
|
+
multiSelect(f, label) {
|
|
1979
|
+
const i = this.input(f, "multi_select", label);
|
|
1980
|
+
i.i.options = some(enumOptions(f.field));
|
|
1981
|
+
return i;
|
|
1982
|
+
}
|
|
1983
|
+
/** Radio cards over an enum's values. */
|
|
1984
|
+
radio(f, label) {
|
|
1985
|
+
const i = this.input(f, "radio_cards", label);
|
|
1986
|
+
i.i.options = some(enumOptions(f.field));
|
|
1987
|
+
return i;
|
|
1988
|
+
}
|
|
1989
|
+
/** A select whose options come from a query's rows. */
|
|
1990
|
+
selectFrom(f, label, q, v, shown) {
|
|
1991
|
+
const i = this.input(f, "select", label);
|
|
1992
|
+
i.i.options_from = { query: q.name, value: v.name, label: shown.name };
|
|
1993
|
+
return i;
|
|
1994
|
+
}
|
|
1995
|
+
/** Rows of a repeated message field (`Items`: product, quantity per row). */
|
|
1996
|
+
repeat(f, label, row) {
|
|
1997
|
+
const rf = new RowForm();
|
|
1998
|
+
row(rf);
|
|
1999
|
+
const i = this.input(f, "repeat", label);
|
|
2000
|
+
i.i.fields = some(rf.inputs);
|
|
2001
|
+
i.i.min_items = 1;
|
|
2002
|
+
return i;
|
|
2003
|
+
}
|
|
2004
|
+
/** A total under the inputs. */
|
|
2005
|
+
summary(title, caption, v, moneyIn) {
|
|
2006
|
+
this.summaryValue = {
|
|
2007
|
+
title: txt(title),
|
|
2008
|
+
caption: caption === undefined ? undefined : txt(caption),
|
|
2009
|
+
value: v,
|
|
2010
|
+
format: formats.money(undefined, moneyIn),
|
|
2011
|
+
};
|
|
2012
|
+
return this;
|
|
2013
|
+
}
|
|
2014
|
+
/** A line next to the buttons. */
|
|
2015
|
+
note(t) {
|
|
2016
|
+
this.noteText = txt(t);
|
|
2017
|
+
return this;
|
|
2018
|
+
}
|
|
2019
|
+
/** A second button that sends the values another way (`Save draft`). */
|
|
2020
|
+
alternate(label, build) {
|
|
2021
|
+
const c = new Chain();
|
|
2022
|
+
build(c);
|
|
2023
|
+
this.alternateButton = { label: txt(label), chain: c };
|
|
2024
|
+
return this;
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Chips over a directory (catalog 3): the rows of `q`, each chosen by `value` and drawn with `title`. The field gets
|
|
2028
|
+
* the chosen values joined with `, `; `ui.pickedCount(f)`, `ui.pickedAgents(f)` and `ui.pickedFirst(f)` read the
|
|
2029
|
+
* choice in conditions and texts, `ui.pickedQuery(f)` what is typed (in the `empty` text).
|
|
2030
|
+
*/
|
|
2031
|
+
pick(f, label, q, value, title) {
|
|
2032
|
+
const i = new PickB({ name: f.name, control: "pick", label: txt(label), pick: { query: q.name, value: value.name, label: title.name } });
|
|
2033
|
+
this.sections[this.sections.length - 1].inputs.push(i);
|
|
2034
|
+
return i;
|
|
2035
|
+
}
|
|
2036
|
+
/** A line under the inputs while `c` (over the form's values) holds (catalog 3). */
|
|
2037
|
+
noteWhen(t, c) {
|
|
2038
|
+
this.notes.push({ text: txt(t), visible: c });
|
|
2039
|
+
return this;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
/** A `pick` input: its directory's fields and texts (catalog 3). */
|
|
2043
|
+
export class PickB extends InputB {
|
|
2044
|
+
pick() {
|
|
2045
|
+
return this.i.pick;
|
|
2046
|
+
}
|
|
2047
|
+
avatar(f) {
|
|
2048
|
+
this.pick().avatar = f.name;
|
|
2049
|
+
return this;
|
|
2050
|
+
}
|
|
2051
|
+
/** A bool field: the row is an agent (drawn with its tile; counted by `ui.pickedAgents`). */
|
|
2052
|
+
agent(f) {
|
|
2053
|
+
this.pick().agent = f.name;
|
|
2054
|
+
return this;
|
|
2055
|
+
}
|
|
2056
|
+
/** The agent tile: the glyph and the engine. */
|
|
2057
|
+
tile(icon, engine) {
|
|
2058
|
+
Object.assign(this.pick(), { icon: icon.name, engine: engine.name });
|
|
2059
|
+
return this;
|
|
2060
|
+
}
|
|
2061
|
+
detail(f) {
|
|
2062
|
+
this.pick().detail = f.name;
|
|
2063
|
+
return this;
|
|
2064
|
+
}
|
|
2065
|
+
/** The rows are grouped by this field. */
|
|
2066
|
+
section(f) {
|
|
2067
|
+
this.pick().section = f.name;
|
|
2068
|
+
return this;
|
|
2069
|
+
}
|
|
2070
|
+
/** A list value of values not offered (the members already in). */
|
|
2071
|
+
exclude(v) {
|
|
2072
|
+
this.pick().exclude = value(v);
|
|
2073
|
+
return this;
|
|
2074
|
+
}
|
|
2075
|
+
/** The line when nothing matches the typed text, and when every row is chosen. */
|
|
2076
|
+
empty(nothing, all) {
|
|
2077
|
+
Object.assign(this.pick(), { empty: txt(nothing), empty_done: txt(all) });
|
|
2078
|
+
return this;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
/** The inputs of one row of a `repeat`. */
|
|
2082
|
+
export class RowForm {
|
|
2083
|
+
/** @internal */ inputs = [];
|
|
2084
|
+
push(f, control, label) {
|
|
2085
|
+
const i = new InputB({ name: f.name, control, label: txt(label) });
|
|
2086
|
+
this.inputs.push(i);
|
|
2087
|
+
return i;
|
|
2088
|
+
}
|
|
2089
|
+
/** A select from a query's rows. */
|
|
2090
|
+
selectFrom(f, label, q, value, shown) {
|
|
2091
|
+
const i = this.push(f, "select", label);
|
|
2092
|
+
i.i.required = true;
|
|
2093
|
+
i.i.options_from = { query: q.name, value: value.name, label: shown.name };
|
|
2094
|
+
return this;
|
|
2095
|
+
}
|
|
2096
|
+
/** A number with − and + buttons, starting at `initial`. */
|
|
2097
|
+
stepper(f, label, initial) {
|
|
2098
|
+
const i = this.push(f, "number", label);
|
|
2099
|
+
i.i.required = true;
|
|
2100
|
+
i.i.initial = { lit: initial };
|
|
2101
|
+
i.i.stepper = true;
|
|
2102
|
+
return this;
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
// ---------------------------------------------------------------------------------------------- contributions
|
|
2106
|
+
/** A sidebar entry: a screen with its params, an optional icon and badge. */
|
|
2107
|
+
export class EntryB extends Built {
|
|
2108
|
+
screen;
|
|
2109
|
+
title;
|
|
2110
|
+
args;
|
|
2111
|
+
iconName;
|
|
2112
|
+
badgeValue;
|
|
2113
|
+
alertBadge = false;
|
|
2114
|
+
/** @internal */ badgeQuery;
|
|
2115
|
+
constructor(screen, title, args) {
|
|
2116
|
+
super();
|
|
2117
|
+
this.screen = screen;
|
|
2118
|
+
this.title = title;
|
|
2119
|
+
this.args = args;
|
|
2120
|
+
}
|
|
2121
|
+
icon(icon) {
|
|
2122
|
+
this.iconName = icon;
|
|
2123
|
+
return this;
|
|
2124
|
+
}
|
|
2125
|
+
/** A count from a document-level query (`badge_<field>`), live through the topics it follows. */
|
|
2126
|
+
badge(def, count) {
|
|
2127
|
+
const q = copyQuery(def.q);
|
|
2128
|
+
q.name = `badge_${count.name}`;
|
|
2129
|
+
for (const f of q.follow)
|
|
2130
|
+
f.min_interval_ms ??= 2000;
|
|
2131
|
+
this.badgeQuery = q;
|
|
2132
|
+
this.badgeValue = { data: { query: q.name, field: count.name } };
|
|
2133
|
+
return this;
|
|
2134
|
+
}
|
|
2135
|
+
/** The badge asks for attention (a filled pill) instead of a quiet count. */
|
|
2136
|
+
alert() {
|
|
2137
|
+
this.alertBadge = true;
|
|
2138
|
+
return this;
|
|
2139
|
+
}
|
|
2140
|
+
/** @internal */ rowsJson;
|
|
2141
|
+
/** Rows: each row's icon field (`hash`, an agent's `bot`). */
|
|
2142
|
+
rowIcon(f) {
|
|
2143
|
+
if (this.rowsJson)
|
|
2144
|
+
this.rowsJson.icon = f.name;
|
|
2145
|
+
return this;
|
|
2146
|
+
}
|
|
2147
|
+
/** Rows: the unread count of each row (its label turns bold) and the viewer's mentions (an amber pill). */
|
|
2148
|
+
unread(unread, mentions) {
|
|
2149
|
+
if (this.rowsJson)
|
|
2150
|
+
Object.assign(this.rowsJson, { badge: unread.name, mentions: mentions.name });
|
|
2151
|
+
return this;
|
|
2152
|
+
}
|
|
2153
|
+
/** Rows: how many show before "Show all" (1 to 20). */
|
|
2154
|
+
limit(n) {
|
|
2155
|
+
if (this.rowsJson)
|
|
2156
|
+
this.rowsJson.limit = n;
|
|
2157
|
+
return this;
|
|
2158
|
+
}
|
|
2159
|
+
/** Rows: an add row under them (`New channel`) that opens a document-level overlay. */
|
|
2160
|
+
add(title, overlay) {
|
|
2161
|
+
if (this.rowsJson)
|
|
2162
|
+
this.rowsJson.add = { title: txt(title), overlay: overlay.id };
|
|
2163
|
+
return this;
|
|
2164
|
+
}
|
|
2165
|
+
/** @internal */
|
|
2166
|
+
json() {
|
|
2167
|
+
if (this.rowsJson)
|
|
2168
|
+
return { title: txt(this.title), icon: this.iconName, rows: this.rowsJson };
|
|
2169
|
+
return {
|
|
2170
|
+
title: txt(this.title),
|
|
2171
|
+
icon: this.iconName,
|
|
2172
|
+
screen: this.screen.id,
|
|
2173
|
+
args: some(this.args),
|
|
2174
|
+
badge: this.badgeValue,
|
|
2175
|
+
badge_style: this.alertBadge ? "alert" : undefined,
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
function entry(screen, title, a) {
|
|
2180
|
+
return new EntryB(screen, title, args(a));
|
|
2181
|
+
}
|
|
2182
|
+
/** Entries from a query's rows (channels, direct messages): `ui.entryRows('Channels', def, channel.f.name, CHANNEL,
|
|
2183
|
+
* { c: ui.rowValue(channel.f.id) })`, five shown before "Show all". */
|
|
2184
|
+
function entryRows(title, def, label, screen, a) {
|
|
2185
|
+
const e = new EntryB(screen, title, []);
|
|
2186
|
+
const q = copyQuery(def.q);
|
|
2187
|
+
q.name = `rows_${label.name}`;
|
|
2188
|
+
for (const f of q.follow)
|
|
2189
|
+
f.min_interval_ms ??= 2000;
|
|
2190
|
+
e.badgeQuery = q;
|
|
2191
|
+
e.rowsJson = { query: q.name, label: label.name, screen: screen.id, args: some(args(a)), limit: 5 };
|
|
2192
|
+
return e;
|
|
2193
|
+
}
|
|
2194
|
+
/** A sidebar group: `ui.nav('Orders', 'shopping-bag', [ui.entry(..)])`. */
|
|
2195
|
+
export class NavB extends Built {
|
|
2196
|
+
title;
|
|
2197
|
+
iconName;
|
|
2198
|
+
/** @internal */ entries;
|
|
2199
|
+
constructor(title, icon, entries = []) {
|
|
2200
|
+
super();
|
|
2201
|
+
this.title = title;
|
|
2202
|
+
this.iconName = icon;
|
|
2203
|
+
this.entries = [...entries];
|
|
2204
|
+
}
|
|
2205
|
+
icon(icon) {
|
|
2206
|
+
this.iconName = icon;
|
|
2207
|
+
return this;
|
|
2208
|
+
}
|
|
2209
|
+
entry(e) {
|
|
2210
|
+
this.entries.push(e);
|
|
2211
|
+
return this;
|
|
2212
|
+
}
|
|
2213
|
+
/** @internal */
|
|
2214
|
+
json() {
|
|
2215
|
+
return { title: txt(this.title), icon: this.iconName, entries: some(this.entries) };
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
function nav(title, icon, entries) {
|
|
2219
|
+
return new NavB(title, icon, entries);
|
|
2220
|
+
}
|
|
2221
|
+
/** A command-palette entry. */
|
|
2222
|
+
export class CommandB extends Built {
|
|
2223
|
+
id;
|
|
2224
|
+
title;
|
|
2225
|
+
target;
|
|
2226
|
+
iconName;
|
|
2227
|
+
constructor(id, title, target) {
|
|
2228
|
+
super();
|
|
2229
|
+
this.id = id;
|
|
2230
|
+
this.title = title;
|
|
2231
|
+
this.target = target;
|
|
2232
|
+
}
|
|
2233
|
+
icon(icon) {
|
|
2234
|
+
this.iconName = icon;
|
|
2235
|
+
return this;
|
|
2236
|
+
}
|
|
2237
|
+
/** @internal */
|
|
2238
|
+
json() {
|
|
2239
|
+
return { id: this.id, title: txt(this.title), icon: this.iconName, target: this.target };
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
const command = {
|
|
2243
|
+
/**
|
|
2244
|
+
* Navigates to a screen, with params like a link: `ui.command.navigate('week', 'Sales: last 7 days', REPORT,
|
|
2245
|
+
* { range: '7' })`. A command runs from anywhere, so its args are literals.
|
|
2246
|
+
*/
|
|
2247
|
+
navigate: (id, title, screen, a) => new CommandB(id, title, { screen: screen.id, args: some(args(a)) }),
|
|
2248
|
+
/** Opens a document-level overlay (`ui.define({ overlays })`), with params (literals). */
|
|
2249
|
+
open: (id, title, overlay, a) => new CommandB(id, title, { overlay: overlay.id, args: some(args(a)) }),
|
|
2250
|
+
};
|
|
2251
|
+
/** The builder a home widget's function gets: its queries are document-level (`home_<id>_<name>`). */
|
|
2252
|
+
export class WidgetBuilder {
|
|
2253
|
+
prefix;
|
|
2254
|
+
/** @internal */ queries = [];
|
|
2255
|
+
constructor(prefix) {
|
|
2256
|
+
this.prefix = prefix;
|
|
2257
|
+
}
|
|
2258
|
+
query(name, def) {
|
|
2259
|
+
const q = copyQuery(def.q);
|
|
2260
|
+
q.name = `${this.prefix}_${name}`;
|
|
2261
|
+
for (const f of q.follow)
|
|
2262
|
+
f.min_interval_ms ??= 2000;
|
|
2263
|
+
this.queries.push(q);
|
|
2264
|
+
return new Q(q.name);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
/** A workspace home widget. */
|
|
2268
|
+
export class HomeB {
|
|
2269
|
+
id;
|
|
2270
|
+
title;
|
|
2271
|
+
build;
|
|
2272
|
+
target;
|
|
2273
|
+
constructor(id, title, build) {
|
|
2274
|
+
this.id = id;
|
|
2275
|
+
this.title = title;
|
|
2276
|
+
this.build = build;
|
|
2277
|
+
}
|
|
2278
|
+
/** The screen the widget opens. */
|
|
2279
|
+
opens(screen, a) {
|
|
2280
|
+
this.target = { screen: screen.id, args: some(args(a)) };
|
|
2281
|
+
return this;
|
|
2282
|
+
}
|
|
2283
|
+
/** @internal */
|
|
2284
|
+
json() {
|
|
2285
|
+
const w = new WidgetBuilder(`home_${this.id}`);
|
|
2286
|
+
const node = this.build(w);
|
|
2287
|
+
return { widget: { id: this.id, title: txt(this.title), node, open: this.target }, queries: w.queries };
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
function home(id, title, build) {
|
|
2291
|
+
return new HomeB(id, title, build);
|
|
2292
|
+
}
|
|
2293
|
+
/** The plugin's UI, for `plugin({ ui })`. */
|
|
2294
|
+
export class UiDoc {
|
|
2295
|
+
tree;
|
|
2296
|
+
texts;
|
|
2297
|
+
constructor(
|
|
2298
|
+
/** @internal */ tree,
|
|
2299
|
+
/** @internal */ texts) {
|
|
2300
|
+
this.tree = tree;
|
|
2301
|
+
this.texts = texts;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
/** The plugin's UI: `ui.define({ nav, screens, commands, home, overlays })`. Screens are built here, in order. */
|
|
2305
|
+
function define(options) {
|
|
2306
|
+
const queries = [];
|
|
2307
|
+
const addQuery = (q) => {
|
|
2308
|
+
if (!queries.some((x) => x.name === q.name))
|
|
2309
|
+
queries.push(q);
|
|
2310
|
+
};
|
|
2311
|
+
for (const g of options.nav ?? [])
|
|
2312
|
+
for (const e of g.entries)
|
|
2313
|
+
if (e.badgeQuery)
|
|
2314
|
+
addQuery(e.badgeQuery);
|
|
2315
|
+
const home = (options.home ?? []).map((h) => {
|
|
2316
|
+
const { widget, queries: qs } = h.json();
|
|
2317
|
+
qs.forEach(addQuery);
|
|
2318
|
+
return widget;
|
|
2319
|
+
});
|
|
2320
|
+
const tree = {
|
|
2321
|
+
nav: some(options.nav ?? []),
|
|
2322
|
+
landing: options.landing?.id,
|
|
2323
|
+
home: some(home),
|
|
2324
|
+
commands: some(options.commands ?? []),
|
|
2325
|
+
queries: some(queries.map(queryJson)),
|
|
2326
|
+
screens: some((options.screens ?? []).map((s) => s.json())),
|
|
2327
|
+
overlays: some((options.overlays ?? []).map((o) => o.json())),
|
|
2328
|
+
search: some(options.search ?? []),
|
|
2329
|
+
};
|
|
2330
|
+
return new UiDoc(tree, Object.fromEntries(Object.entries(options.texts ?? {}).map(([k, v]) => [k, { ...v }])));
|
|
2331
|
+
}
|
|
2332
|
+
/** @internal The document as the descriptor carries it: deferred parts resolved, texts collected. */
|
|
2333
|
+
export function resolveUi(doc, r) {
|
|
2334
|
+
const en = new Map();
|
|
2335
|
+
const walk = (v, path) => {
|
|
2336
|
+
if (v instanceof Deferred)
|
|
2337
|
+
return walk(v.resolve(r, path), path);
|
|
2338
|
+
if (v instanceof Built)
|
|
2339
|
+
return walk(v.json(), path);
|
|
2340
|
+
if (v instanceof TextKey) {
|
|
2341
|
+
en.set(v.key, v.en);
|
|
2342
|
+
const args = walk(v.args, `${path}.args`);
|
|
2343
|
+
return Object.keys(args).length > 0 ? { key: v.key, args } : { key: v.key };
|
|
2344
|
+
}
|
|
2345
|
+
if (Array.isArray(v))
|
|
2346
|
+
return v.map((x, i) => walk(x, `${path}[${i}]`));
|
|
2347
|
+
if (v !== null && typeof v === "object") {
|
|
2348
|
+
const out = {};
|
|
2349
|
+
for (const [k, x] of Object.entries(v))
|
|
2350
|
+
if (x !== undefined)
|
|
2351
|
+
out[k] = walk(x, `${path}.${k}`);
|
|
2352
|
+
return out;
|
|
2353
|
+
}
|
|
2354
|
+
return v;
|
|
2355
|
+
};
|
|
2356
|
+
const out = walk(doc.tree, "ui");
|
|
2357
|
+
const texts = {};
|
|
2358
|
+
for (const [locale, catalog] of Object.entries(doc.texts))
|
|
2359
|
+
texts[locale] = { ...catalog };
|
|
2360
|
+
if (en.size > 0) {
|
|
2361
|
+
const catalog = (texts.en ??= {});
|
|
2362
|
+
for (const [k, v] of en)
|
|
2363
|
+
if (!(k in catalog))
|
|
2364
|
+
catalog[k] = v;
|
|
2365
|
+
}
|
|
2366
|
+
return { catalog: CATALOG, ...out, ...(Object.keys(texts).length > 0 ? { texts } : {}) };
|
|
2367
|
+
}
|
|
2368
|
+
// ---------------------------------------------------------------------------------------------- records
|
|
2369
|
+
/** A row as a list item: `r.view(r.get(order.f.customer)).subtitle(..).meta(..)` (a compact table row, a search result). */
|
|
2370
|
+
export class RowViewB extends Built {
|
|
2371
|
+
v;
|
|
2372
|
+
constructor(title) {
|
|
2373
|
+
super();
|
|
2374
|
+
this.v = { title: txt(title) };
|
|
2375
|
+
}
|
|
2376
|
+
subtitle(t) {
|
|
2377
|
+
this.v.subtitle = txt(t);
|
|
2378
|
+
return this;
|
|
2379
|
+
}
|
|
2380
|
+
meta(v) {
|
|
2381
|
+
this.v.meta = v;
|
|
2382
|
+
return this;
|
|
2383
|
+
}
|
|
2384
|
+
/** The meta is money in the row's currency field. */
|
|
2385
|
+
money(currency) {
|
|
2386
|
+
this.v.meta_format = formats.money(currency.name);
|
|
2387
|
+
return this;
|
|
2388
|
+
}
|
|
2389
|
+
avatar(f) {
|
|
2390
|
+
this.v.avatar = f.name;
|
|
2391
|
+
return this;
|
|
2392
|
+
}
|
|
2393
|
+
icon(icon) {
|
|
2394
|
+
this.v.icon = icon;
|
|
2395
|
+
return this;
|
|
2396
|
+
}
|
|
2397
|
+
status(f, tones) {
|
|
2398
|
+
this.v.status = { field: f.name, tones: tonesJson(tones) };
|
|
2399
|
+
return this;
|
|
2400
|
+
}
|
|
2401
|
+
/** @internal */
|
|
2402
|
+
json() {
|
|
2403
|
+
return this.v;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
/** A row as a list item; inside `compact`/`item` callbacks `r.view(..)` infers the row type. */
|
|
2407
|
+
function rowView(title) {
|
|
2408
|
+
return new RowViewB(title);
|
|
2409
|
+
}
|
|
2410
|
+
/** The head of a record: `ui.recordHeader(title).short(..).subtitle(..).tags([..]).actions([..]).menu([..])`. */
|
|
2411
|
+
export class RecordHeaderB extends Node {
|
|
2412
|
+
constructor(title) {
|
|
2413
|
+
super("record_header", { title: txt(title) });
|
|
2414
|
+
}
|
|
2415
|
+
/** The top bar's title on a phone (`#1048`). */
|
|
2416
|
+
short(t) {
|
|
2417
|
+
this.body.short = txt(t);
|
|
2418
|
+
return this;
|
|
2419
|
+
}
|
|
2420
|
+
subtitle(t) {
|
|
2421
|
+
this.body.subtitle = txt(t);
|
|
2422
|
+
return this;
|
|
2423
|
+
}
|
|
2424
|
+
/** The heading and the line under it on a phone. */
|
|
2425
|
+
compact(title, subtitle) {
|
|
2426
|
+
this.body.compact_title = txt(title);
|
|
2427
|
+
this.body.compact_subtitle = txt(subtitle);
|
|
2428
|
+
return this;
|
|
2429
|
+
}
|
|
2430
|
+
/** Status chips next to the title. */
|
|
2431
|
+
tags(nodes) {
|
|
2432
|
+
this.body.tags = some(nodes);
|
|
2433
|
+
return this;
|
|
2434
|
+
}
|
|
2435
|
+
/** Buttons under the title. */
|
|
2436
|
+
actions(nodes) {
|
|
2437
|
+
this.body.actions = some(nodes);
|
|
2438
|
+
return this;
|
|
2439
|
+
}
|
|
2440
|
+
/** More actions (`…`). */
|
|
2441
|
+
menu(items) {
|
|
2442
|
+
this.body.menu = { label: "More actions", icon: "more-horizontal", items: [...items] };
|
|
2443
|
+
return this;
|
|
2444
|
+
}
|
|
2445
|
+
/** The action of the panel's expand button. */
|
|
2446
|
+
expand(action) {
|
|
2447
|
+
this.body.expand = action.name;
|
|
2448
|
+
return this;
|
|
2449
|
+
}
|
|
2450
|
+
/** The action of the panel's close button. */
|
|
2451
|
+
close(action) {
|
|
2452
|
+
this.body.close = action.name;
|
|
2453
|
+
return this;
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
function recordHeader(title) {
|
|
2457
|
+
return new RecordHeaderB(title);
|
|
2458
|
+
}
|
|
2459
|
+
/** An agent's run on a record: who, its state, its steps, Stop and a message box. */
|
|
2460
|
+
export class AgentRunB extends Node {
|
|
2461
|
+
constructor(body) {
|
|
2462
|
+
super("agent_run", body);
|
|
2463
|
+
}
|
|
2464
|
+
/** The line under the agent's name. */
|
|
2465
|
+
subtitle(f) {
|
|
2466
|
+
this.body.subtitle = f.name;
|
|
2467
|
+
return this;
|
|
2468
|
+
}
|
|
2469
|
+
/** A Stop button, shown while `when` holds. */
|
|
2470
|
+
stop(action, when) {
|
|
2471
|
+
this.body.stop = action.name;
|
|
2472
|
+
this.body.stop_when = when;
|
|
2473
|
+
return this;
|
|
2474
|
+
}
|
|
2475
|
+
/** A message box; the action reads the text as `ui.formValue(..)` of the field `text`. */
|
|
2476
|
+
message(placeholder, action) {
|
|
2477
|
+
this.body.message = { placeholder: txt(placeholder), action: action.name };
|
|
2478
|
+
return this;
|
|
2479
|
+
}
|
|
2480
|
+
/** What the run needs from the viewer, first and in amber: the request (a run field, empty when nothing is needed)
|
|
2481
|
+
* and one button; `due` is the deadline next to it (`by 11:30`). */
|
|
2482
|
+
needs(text, label, action, due) {
|
|
2483
|
+
this.body.needs = { text: text.name, label: txt(label), action: action.name, ...(due ? { due: due.name } : {}) };
|
|
2484
|
+
return this;
|
|
2485
|
+
}
|
|
2486
|
+
/** Opens the run's session page; the card then shows the current step instead of the step list. */
|
|
2487
|
+
open(label, action) {
|
|
2488
|
+
this.body.open = { label: txt(label), action: action.name };
|
|
2489
|
+
return this;
|
|
2490
|
+
}
|
|
2491
|
+
/** The changes the run made to this record: `changes('Changes to this order', run.f.changes, change.f.text)`. */
|
|
2492
|
+
changes(title, field, text) {
|
|
2493
|
+
this.body.changes = { title: txt(title), field: field.name, text: text.name };
|
|
2494
|
+
return this;
|
|
2495
|
+
}
|
|
2496
|
+
/** The agent's earlier sessions on this record: a run field with the line, hidden while empty, and its action. */
|
|
2497
|
+
earlier(text, action) {
|
|
2498
|
+
this.body.earlier = { text: text.name, action: action.name };
|
|
2499
|
+
return this;
|
|
2500
|
+
}
|
|
2501
|
+
/** The run's full log in a panel (catalog 3): the head, every step, the note. */
|
|
2502
|
+
log() {
|
|
2503
|
+
this.body.log = true;
|
|
2504
|
+
return this;
|
|
2505
|
+
}
|
|
2506
|
+
/** The agent's tile in the log's head: response fields with the glyph and the engine (catalog 3). */
|
|
2507
|
+
tile(icon, engine) {
|
|
2508
|
+
this.body.icon = icon.name;
|
|
2509
|
+
this.body.engine = engine.name;
|
|
2510
|
+
return this;
|
|
2511
|
+
}
|
|
2512
|
+
/** The status's label in the log's head (catalog 3). */
|
|
2513
|
+
statusLabel(f) {
|
|
2514
|
+
this.body.status_label = f.name;
|
|
2515
|
+
return this;
|
|
2516
|
+
}
|
|
2517
|
+
/** The current step's label in the log's head (catalog 3). */
|
|
2518
|
+
stepLabel(f) {
|
|
2519
|
+
this.body.step_label = f.name;
|
|
2520
|
+
return this;
|
|
2521
|
+
}
|
|
2522
|
+
/** How long the run has worked, in the log's head (catalog 3). */
|
|
2523
|
+
elapsed(f) {
|
|
2524
|
+
this.body.elapsed = f.name;
|
|
2525
|
+
return this;
|
|
2526
|
+
}
|
|
2527
|
+
/** The line under the steps while the run is not live (catalog 3). */
|
|
2528
|
+
note(f) {
|
|
2529
|
+
this.body.note = f.name;
|
|
2530
|
+
return this;
|
|
2531
|
+
}
|
|
2532
|
+
/** While this holds the run is live (no note; catalog 3). */
|
|
2533
|
+
liveWhen(c) {
|
|
2534
|
+
this.body.live_when = c;
|
|
2535
|
+
return this;
|
|
2536
|
+
}
|
|
2537
|
+
/** A step's detail line (a field of a step; catalog 3). */
|
|
2538
|
+
stepDetail(f) {
|
|
2539
|
+
this.body.step_detail = f.name;
|
|
2540
|
+
return this;
|
|
2541
|
+
}
|
|
2542
|
+
/** A step's time (catalog 3). */
|
|
2543
|
+
stepTime(f) {
|
|
2544
|
+
this.body.step_time = f.name;
|
|
2545
|
+
return this;
|
|
2546
|
+
}
|
|
2547
|
+
/** A step's call, drawn as a process row's (catalog 3). */
|
|
2548
|
+
stepTool(f) {
|
|
2549
|
+
this.body.step_tool = f.name;
|
|
2550
|
+
return this;
|
|
2551
|
+
}
|
|
2552
|
+
/** A step's evidence (catalog 3). */
|
|
2553
|
+
stepEvidence(f) {
|
|
2554
|
+
this.body.step_evidence = f.name;
|
|
2555
|
+
return this;
|
|
2556
|
+
}
|
|
2557
|
+
/** A step's lines (catalog 3). */
|
|
2558
|
+
stepLines(f) {
|
|
2559
|
+
this.body.step_lines = f.name;
|
|
2560
|
+
return this;
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
/** `ui.agentRun(run, runResponse.f.agent, runResponse.f.status, tones, runResponse.f.steps, step.f.text, step.f.state)`. */
|
|
2564
|
+
function agentRun(q, title, status, tones, steps, stepText, stepState) {
|
|
2565
|
+
return new AgentRunB({
|
|
2566
|
+
query: q.name,
|
|
2567
|
+
title: title.name,
|
|
2568
|
+
status: { field: status.name, tones: tonesJson(tones) },
|
|
2569
|
+
steps: steps.name,
|
|
2570
|
+
step_text: stepText.name,
|
|
2571
|
+
step_state: stepState.name,
|
|
2572
|
+
});
|
|
2573
|
+
}
|
|
2574
|
+
/** A conversation (a channel, a thread, a direct message): its messages oldest first, a card per message and a
|
|
2575
|
+
* message box. */
|
|
2576
|
+
export class ConversationB extends Node {
|
|
2577
|
+
constructor(query, author, text, time) {
|
|
2578
|
+
super("conversation", { query, author, text, time });
|
|
2579
|
+
}
|
|
2580
|
+
cardBody() {
|
|
2581
|
+
return (this.body.card ??= { title: "" });
|
|
2582
|
+
}
|
|
2583
|
+
/** The author's picture URL (else their initials). */
|
|
2584
|
+
avatar(f) {
|
|
2585
|
+
this.body.avatar = f.name;
|
|
2586
|
+
return this;
|
|
2587
|
+
}
|
|
2588
|
+
/** An icon name for authors without a face (an agent: `bot`). */
|
|
2589
|
+
icon(f) {
|
|
2590
|
+
this.body.icon = f.name;
|
|
2591
|
+
return this;
|
|
2592
|
+
}
|
|
2593
|
+
/** A small chip after the author (`AGENT`). */
|
|
2594
|
+
badge(f) {
|
|
2595
|
+
this.body.badge = f.name;
|
|
2596
|
+
return this;
|
|
2597
|
+
}
|
|
2598
|
+
/** A quiet line after the time (`via Commerce`). */
|
|
2599
|
+
via(f) {
|
|
2600
|
+
this.body.via = f.name;
|
|
2601
|
+
return this;
|
|
2602
|
+
}
|
|
2603
|
+
/** A chip before the text (`To people`). */
|
|
2604
|
+
tag(f) {
|
|
2605
|
+
this.body.tag = f.name;
|
|
2606
|
+
return this;
|
|
2607
|
+
}
|
|
2608
|
+
/** The receipt under a message (`Applied · step 3`), toned by a field. */
|
|
2609
|
+
receipt(text, tone, tones) {
|
|
2610
|
+
this.body.receipt = { text: text.name, tone: { field: tone.name, tones: tonesJson(tones) } };
|
|
2611
|
+
return this;
|
|
2612
|
+
}
|
|
2613
|
+
/** A card under the message, shown while its title is not empty, with its text. */
|
|
2614
|
+
card(title, text) {
|
|
2615
|
+
Object.assign(this.cardBody(), { title: title.name, text: text.name });
|
|
2616
|
+
return this;
|
|
2617
|
+
}
|
|
2618
|
+
/** The card's band and its aside (`by 11:30`), toned by a field. */
|
|
2619
|
+
cardBand(band, aside, tone, tones) {
|
|
2620
|
+
Object.assign(this.cardBody(), { band: band.name, aside: aside.name, tone: { field: tone.name, tones: tonesJson(tones) } });
|
|
2621
|
+
return this;
|
|
2622
|
+
}
|
|
2623
|
+
/** The card's footer line (`14 replies · last 10:58`). */
|
|
2624
|
+
cardFooter(f) {
|
|
2625
|
+
this.cardBody().footer = f.name;
|
|
2626
|
+
return this;
|
|
2627
|
+
}
|
|
2628
|
+
/** The card's button: its label is a row field (hidden while empty), the action runs on the row. */
|
|
2629
|
+
cardButton(label, action) {
|
|
2630
|
+
Object.assign(this.cardBody(), { button: label.name, action: action.name });
|
|
2631
|
+
return this;
|
|
2632
|
+
}
|
|
2633
|
+
/** The message box; its action reads `ui.formValue(..)` of the fields `text` and, with addressees, `to`. */
|
|
2634
|
+
composer(placeholder, action) {
|
|
2635
|
+
this.body.composer = { placeholder: txt(placeholder), action: action.name };
|
|
2636
|
+
return this;
|
|
2637
|
+
}
|
|
2638
|
+
/** An addressee of the message box; the first is the default. */
|
|
2639
|
+
to(value, label) {
|
|
2640
|
+
const c = this.body.composer;
|
|
2641
|
+
if (c)
|
|
2642
|
+
(c.to ??= []).push({ value, label: txt(label) });
|
|
2643
|
+
return this;
|
|
2644
|
+
}
|
|
2645
|
+
empty(t) {
|
|
2646
|
+
this.body.empty = txt(t);
|
|
2647
|
+
return this;
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
/** `ui.conversation(messages, msg.f.author, msg.f.text, msg.f.at)`. */
|
|
2651
|
+
function conversation(q, author, text, time) {
|
|
2652
|
+
return new ConversationB(q.name, author.name, text.name, time.name);
|
|
2653
|
+
}
|
|
2654
|
+
/** A messenger screen (`ui.chat(channel, send)`): the open thread, a run's log and the members as side panels and
|
|
2655
|
+
* the actions on messages.
|
|
2656
|
+
* @deprecated Catalog 3 deprecates `chat` (`W_UI_DEPRECATED`); build the screen from a `fill` split with a
|
|
2657
|
+
* `ui.header`, `ui.stream`s of posts, a `ui.strip` and a `ui.composer`. */
|
|
2658
|
+
export class ChatB extends Node {
|
|
2659
|
+
constructor(channel, send) {
|
|
2660
|
+
super("chat", { channel, actions: { send } });
|
|
2661
|
+
}
|
|
2662
|
+
act(o) {
|
|
2663
|
+
Object.assign(this.body.actions, o);
|
|
2664
|
+
return this;
|
|
2665
|
+
}
|
|
2666
|
+
/** The open thread (`root`, `replies`) and the reply action (`{form: text, to, also}`). */
|
|
2667
|
+
thread(q, reply) {
|
|
2668
|
+
this.body.thread = q.name;
|
|
2669
|
+
return this.act({ reply: reply.name });
|
|
2670
|
+
}
|
|
2671
|
+
/** An agent run's log (`steps`), with Stop and a note to the agent (`{form: text}`). */
|
|
2672
|
+
run(q, stop, tell) {
|
|
2673
|
+
this.body.run = q.name;
|
|
2674
|
+
return this.act({ stop: stop.name, tell: tell.name });
|
|
2675
|
+
}
|
|
2676
|
+
/** The members (`people`, `agents`) and the action that opens them. */
|
|
2677
|
+
members(q, open) {
|
|
2678
|
+
this.body.members = q.name;
|
|
2679
|
+
return this.act({ members: open.name });
|
|
2680
|
+
}
|
|
2681
|
+
/** Opens a message's thread, and closes the side panel. */
|
|
2682
|
+
openThread(open, close) {
|
|
2683
|
+
return this.act({ thread: open.name, close: close.name });
|
|
2684
|
+
}
|
|
2685
|
+
/**
|
|
2686
|
+
* The open thread's Following bell: the action follows the thread (`{form: follow}` true) or stops following it
|
|
2687
|
+
* (false); the thread query reads `following`, whether the reader follows it.
|
|
2688
|
+
*/
|
|
2689
|
+
followThread(a) {
|
|
2690
|
+
return this.act({ follow: a.name });
|
|
2691
|
+
}
|
|
2692
|
+
/** Opens a message's run log. */
|
|
2693
|
+
openRun(a) {
|
|
2694
|
+
return this.act({ run: a.name });
|
|
2695
|
+
}
|
|
2696
|
+
/** Approve, Decline and Undo on a message's approval. */
|
|
2697
|
+
approval(approve, decline, undo) {
|
|
2698
|
+
return this.act({ approve: approve.name, decline: decline.name, undo: undo.name });
|
|
2699
|
+
}
|
|
2700
|
+
/** A message card's button. */
|
|
2701
|
+
card(a) {
|
|
2702
|
+
return this.act({ card: a.name });
|
|
2703
|
+
}
|
|
2704
|
+
/** Reactions on a message (`{form: emoji}`). */
|
|
2705
|
+
react(a) {
|
|
2706
|
+
return this.act({ react: a.name });
|
|
2707
|
+
}
|
|
2708
|
+
/** The author's own changes to a message (edit `{form: text}`, delete), and pin or unpin it. */
|
|
2709
|
+
editing(edit, del, pin) {
|
|
2710
|
+
return this.act({ edit: edit.name, delete: del.name, pin: pin.name });
|
|
2711
|
+
}
|
|
2712
|
+
/** Chooses an option of a message's decision (`{form: choice}`). */
|
|
2713
|
+
choose(a) {
|
|
2714
|
+
return this.act({ choose: a.name });
|
|
2715
|
+
}
|
|
2716
|
+
/** The agent a direct message is with (`name`) and the action that pauses or resumes it. */
|
|
2717
|
+
about(q, pause) {
|
|
2718
|
+
this.body.about = q.name;
|
|
2719
|
+
return this.act({ pause: pause.name });
|
|
2720
|
+
}
|
|
2721
|
+
/** Whom a new message can go to (`people`, `agents`) and the action that starts it (`{form: to, text}`). */
|
|
2722
|
+
directory(q, start) {
|
|
2723
|
+
this.body.directory = q.name;
|
|
2724
|
+
return this.act({ start: start.name });
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
/** @deprecated Catalog 3 deprecates `chat`: a `fill` split with `ui.header`, `ui.stream`, `ui.strip` and `ui.composer`. */
|
|
2728
|
+
function chat(channel, send) {
|
|
2729
|
+
return new ChatB(channel.name, send.name);
|
|
2730
|
+
}
|
|
2731
|
+
/** Records the command palette finds: `ui.search('Orders', findOrders, findRequest.f.text, findResponse.f.orders)`. */
|
|
2732
|
+
export class SearchB extends Built {
|
|
2733
|
+
title;
|
|
2734
|
+
endpoint;
|
|
2735
|
+
text;
|
|
2736
|
+
rows;
|
|
2737
|
+
itemView = new RowViewB("");
|
|
2738
|
+
target = {};
|
|
2739
|
+
actions = [];
|
|
2740
|
+
constructor(title, endpoint, text, rows) {
|
|
2741
|
+
super();
|
|
2742
|
+
this.title = title;
|
|
2743
|
+
this.endpoint = endpoint;
|
|
2744
|
+
this.text = text;
|
|
2745
|
+
this.rows = rows;
|
|
2746
|
+
}
|
|
2747
|
+
/** A result as a list item (`(r) => r.view(r.get(order.f.number)).subtitle(..)`). */
|
|
2748
|
+
item(view) {
|
|
2749
|
+
this.itemView = view(new RowRef());
|
|
2750
|
+
return this;
|
|
2751
|
+
}
|
|
2752
|
+
/** Where a result leads (`(r) => ({ id: r.get(order.f.id) })`). */
|
|
2753
|
+
open(screen, a) {
|
|
2754
|
+
this.target = { screen: screen.id, args: some(args(a?.(new RowRef()))) };
|
|
2755
|
+
return this;
|
|
2756
|
+
}
|
|
2757
|
+
/** An action the palette offers on the top result: a document-level overlay with args from the result (`New order for {name}`). */
|
|
2758
|
+
action(title, icon, overlay, a) {
|
|
2759
|
+
this.actions.push({ title: txt(title), icon, target: { overlay: overlay.id, args: some(args(a?.(new RowRef()))) } });
|
|
2760
|
+
return this;
|
|
2761
|
+
}
|
|
2762
|
+
/** @internal */
|
|
2763
|
+
json() {
|
|
2764
|
+
return {
|
|
2765
|
+
title: txt(this.title),
|
|
2766
|
+
endpoint: this.endpoint,
|
|
2767
|
+
text: this.text,
|
|
2768
|
+
rows: this.rows,
|
|
2769
|
+
item: this.itemView,
|
|
2770
|
+
open: this.target,
|
|
2771
|
+
actions: some(this.actions),
|
|
2772
|
+
};
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
/** A source of records for the command palette: a read `ui` endpoint called with the typed text in `text`. */
|
|
2776
|
+
function search(title, endpoint, text, rows) {
|
|
2777
|
+
return new SearchB(title, endpointRef(endpoint), text.name, rows.name);
|
|
2778
|
+
}
|
|
2779
|
+
/** A card with a title line (`3 items · from catalog`); `.trailing(v).moneyIn(..)` adds a value at its end. */
|
|
2780
|
+
function titledCard(title, children) {
|
|
2781
|
+
return n("card", { title: txt(title), children: [...children] });
|
|
2782
|
+
}
|
|
2783
|
+
/** A small uppercase label over a group (`ACTIVITY`). */
|
|
2784
|
+
function label(t) {
|
|
2785
|
+
return textNode(t, "label");
|
|
2786
|
+
}
|
|
2787
|
+
/** A menu opened by a labelled button (`View`). */
|
|
2788
|
+
function menuButton(labelText, icon, items) {
|
|
2789
|
+
return n("menu", { label: txt(labelText), icon, items: [...items] });
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* A path into a row of `R` reading a `T`: a nested field (`ui.path(msg.f.thread, summary.f.count)` is
|
|
2793
|
+
* `thread.count`) or a field of a query's join (`who.f(face.f.name)` is `who.name`). Templates take it wherever they
|
|
2794
|
+
* take a field.
|
|
2795
|
+
*/
|
|
2796
|
+
export class PathOf {
|
|
2797
|
+
path;
|
|
2798
|
+
constructor(path) {
|
|
2799
|
+
this.path = path;
|
|
2800
|
+
}
|
|
2801
|
+
/** A field of the message this path leads to (or of its items). */
|
|
2802
|
+
dot(f) {
|
|
2803
|
+
return new PathOf(`${this.path}.${f.name}`);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
/** @internal The row path a field or a path names. */
|
|
2807
|
+
function rowPath(p) {
|
|
2808
|
+
return p instanceof PathOf ? p.path : p.name;
|
|
2809
|
+
}
|
|
2810
|
+
/** A nested field of a row: `ui.path(msg.f.thread, summary.f.count)` (`thread.count`); `.dot(..)` goes deeper. */
|
|
2811
|
+
function path(field, next) {
|
|
2812
|
+
return new PathOf(`${field.name}.${next.name}`);
|
|
2813
|
+
}
|
|
2814
|
+
/** A lookup of a query's rows (`QueryDef.join(..)`): the rows of `R` read the item of `J` as `<name>.<field>`. */
|
|
2815
|
+
export class Via {
|
|
2816
|
+
name;
|
|
2817
|
+
constructor(name) {
|
|
2818
|
+
this.name = name;
|
|
2819
|
+
}
|
|
2820
|
+
/** A field of the looked-up item, as a path of the row. */
|
|
2821
|
+
f(f) {
|
|
2822
|
+
return new PathOf(`${this.name}.${f.name}`);
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
function via(name) {
|
|
2826
|
+
return new Via(name);
|
|
2827
|
+
}
|
|
2828
|
+
/** A row value by path (a nested or joined field), for conditions and texts: `ui.rowAt(who.f(face.f.agent)).eq(true)`. */
|
|
2829
|
+
function rowAt(p) {
|
|
2830
|
+
return new Val({ row: rowPath(p) });
|
|
2831
|
+
}
|
|
2832
|
+
function formVal(name) {
|
|
2833
|
+
return new Val({ form: name });
|
|
2834
|
+
}
|
|
2835
|
+
/** The values a composer's `send`, a post's actions and a toggle give their chain (`{form: …}`; catalog 3). */
|
|
2836
|
+
const form = {
|
|
2837
|
+
/** The text typed (a composer, a post's inline edit). */
|
|
2838
|
+
text: () => formVal("text"),
|
|
2839
|
+
/** The key of the item Reply was on (a composer with `.reply()`). */
|
|
2840
|
+
reply: () => formVal("reply"),
|
|
2841
|
+
/** A dictated recording: a data URL. */
|
|
2842
|
+
audio: () => formVal("audio"),
|
|
2843
|
+
/** The recording's duration. */
|
|
2844
|
+
duration: () => formVal("duration"),
|
|
2845
|
+
/** The recording's language. */
|
|
2846
|
+
language: () => formVal("language"),
|
|
2847
|
+
/** The recording's timed words (JSON). */
|
|
2848
|
+
words: () => formVal("words"),
|
|
2849
|
+
/** A composer's checkbox (`.option(name, label)`). */
|
|
2850
|
+
option: (name) => formVal(name),
|
|
2851
|
+
/** The emoji of a reaction. */
|
|
2852
|
+
emoji: () => formVal("emoji"),
|
|
2853
|
+
/** The name an identity card's button is for. */
|
|
2854
|
+
to: () => formVal("to"),
|
|
2855
|
+
/** A toggle's new state. */
|
|
2856
|
+
pressed: () => formVal("pressed"),
|
|
2857
|
+
};
|
|
2858
|
+
/** Of a `pick` input: how many are chosen. */
|
|
2859
|
+
function pickedCount(f) {
|
|
2860
|
+
return formVal(`${f.name}.count`);
|
|
2861
|
+
}
|
|
2862
|
+
/** Of a `pick` input: how many of the chosen are agents. */
|
|
2863
|
+
function pickedAgents(f) {
|
|
2864
|
+
return formVal(`${f.name}.agents`);
|
|
2865
|
+
}
|
|
2866
|
+
/** Of a `pick` input: the first word of the first chosen label. */
|
|
2867
|
+
function pickedFirst(f) {
|
|
2868
|
+
return formVal(`${f.name}.first`);
|
|
2869
|
+
}
|
|
2870
|
+
/** Of a `pick` input: what is typed in its search (its `empty` text reads it: `Nobody matches “{q}”.`). */
|
|
2871
|
+
function pickedQuery(f) {
|
|
2872
|
+
return formVal(`${f.name}.query`);
|
|
2873
|
+
}
|
|
2874
|
+
/** A deep copy of plain objects and arrays; builders and values inside are shared. */
|
|
2875
|
+
function copyPlain(x) {
|
|
2876
|
+
if (Array.isArray(x))
|
|
2877
|
+
return x.map(copyPlain);
|
|
2878
|
+
if (x !== null && typeof x === "object" && Object.getPrototypeOf(x) === Object.prototype) {
|
|
2879
|
+
return Object.fromEntries(Object.entries(x).map(([k, v]) => [k, copyPlain(v)]));
|
|
2880
|
+
}
|
|
2881
|
+
return x;
|
|
2882
|
+
}
|
|
2883
|
+
// --- header
|
|
2884
|
+
/** A piece of a header's subtitle: `ui.seg.text(..)`, `ui.seg.dotWaiting()`, `ui.seg.countdown(..).prefix('ends in ')`. */
|
|
2885
|
+
export class SegB extends Built {
|
|
2886
|
+
s;
|
|
2887
|
+
constructor(/** @internal */ s) {
|
|
2888
|
+
super();
|
|
2889
|
+
this.s = s;
|
|
2890
|
+
}
|
|
2891
|
+
/** A text before the value, left out with it. */
|
|
2892
|
+
prefix(t) {
|
|
2893
|
+
this.s.prefix = txt(t);
|
|
2894
|
+
return this;
|
|
2895
|
+
}
|
|
2896
|
+
visible(c) {
|
|
2897
|
+
this.s.visible = c;
|
|
2898
|
+
return this;
|
|
2899
|
+
}
|
|
2900
|
+
/** @internal */
|
|
2901
|
+
json() {
|
|
2902
|
+
return this.s;
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
const seg = {
|
|
2906
|
+
/** A text; left out while its value is empty. */
|
|
2907
|
+
text: (t) => new SegB({ text: txt(t) }),
|
|
2908
|
+
/** The amber dot of something at work. */
|
|
2909
|
+
dotLive: () => new SegB({ dot: "live" }),
|
|
2910
|
+
/** The hollow dot of something waiting. */
|
|
2911
|
+
dotWaiting: () => new SegB({ dot: "waiting" }),
|
|
2912
|
+
/** The line in the tone of something at work (amber), with no dot drawn. */
|
|
2913
|
+
toneLive: () => new SegB({ tone: "live" }),
|
|
2914
|
+
/** The line in the tone of something waiting, with no dot drawn. */
|
|
2915
|
+
toneWaiting: () => new SegB({ tone: "waiting" }),
|
|
2916
|
+
/** The time left until a moment in ms (left out while empty). */
|
|
2917
|
+
countdown: (v) => new SegB({ value: value(v), format: formats.plain("countdown") }),
|
|
2918
|
+
/** The time since a moment in ms. */
|
|
2919
|
+
elapsed: (v) => new SegB({ value: value(v), format: formats.plain("elapsed") }),
|
|
2920
|
+
};
|
|
2921
|
+
/** A tab of a header: `ui.headerTab('pinned', 'Pinned').badge(q.field(view.f.pinnedCount))`. */
|
|
2922
|
+
export class HeaderTabB extends Built {
|
|
2923
|
+
t;
|
|
2924
|
+
constructor(id, title) {
|
|
2925
|
+
super();
|
|
2926
|
+
this.t = { id, title: txt(title) };
|
|
2927
|
+
}
|
|
2928
|
+
/** ` · N` after the title while above 0. */
|
|
2929
|
+
badge(v) {
|
|
2930
|
+
this.t.badge = v;
|
|
2931
|
+
return this;
|
|
2932
|
+
}
|
|
2933
|
+
/** Runs the action instead of selecting the tab. */
|
|
2934
|
+
action(a) {
|
|
2935
|
+
this.t.action = a.name;
|
|
2936
|
+
return this;
|
|
2937
|
+
}
|
|
2938
|
+
/** @internal */
|
|
2939
|
+
json() {
|
|
2940
|
+
return this.t;
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
function headerTab(id, title) {
|
|
2944
|
+
return new HeaderTabB(id, title);
|
|
2945
|
+
}
|
|
2946
|
+
/**
|
|
2947
|
+
* A head of a screen's column or of a side panel (catalog 3): a leading tile or faces, the title with a glyph, a
|
|
2948
|
+
* subtitle line of segments, a faces pill, text pills, icon buttons, a `…` menu, tabs, and the panel's expand and
|
|
2949
|
+
* close. On a phone a column's header is the shell's top bar; a panel's header is a back bar.
|
|
2950
|
+
*/
|
|
2951
|
+
export class HeaderB extends Node {
|
|
2952
|
+
buttonList = [];
|
|
2953
|
+
constructor(title) {
|
|
2954
|
+
super("header", { title: txt(title) });
|
|
2955
|
+
}
|
|
2956
|
+
/** An icon name before the title. */
|
|
2957
|
+
titleIcon(v) {
|
|
2958
|
+
this.body.title_icon = value(v);
|
|
2959
|
+
return this;
|
|
2960
|
+
}
|
|
2961
|
+
/** The icon the breadcrumb and the phone's top bar put before the screen's title. */
|
|
2962
|
+
crumbIcon(v) {
|
|
2963
|
+
this.body.crumb_icon = value(v);
|
|
2964
|
+
return this;
|
|
2965
|
+
}
|
|
2966
|
+
/** An agent tile: the glyph and the engine (`claude`, `codex`, `pi`; empty: the ink cell). */
|
|
2967
|
+
leadingTile(icon, engine) {
|
|
2968
|
+
this.body.leading = { tile: { icon: value(icon), engine: value(engine) } };
|
|
2969
|
+
return this;
|
|
2970
|
+
}
|
|
2971
|
+
/** A stack of faces (a list of `name`, `avatar`, `agent`, `icon`, `engine`). */
|
|
2972
|
+
leadingFaces(v) {
|
|
2973
|
+
this.body.leading = { faces: v };
|
|
2974
|
+
return this;
|
|
2975
|
+
}
|
|
2976
|
+
/** The leading's size in px. */
|
|
2977
|
+
leadingSize(px) {
|
|
2978
|
+
const l = this.body.leading;
|
|
2979
|
+
if (l)
|
|
2980
|
+
l.size = px;
|
|
2981
|
+
return this;
|
|
2982
|
+
}
|
|
2983
|
+
/** One line of segments joined with ` · `; a segment with an empty value is left out. */
|
|
2984
|
+
subtitle(segs) {
|
|
2985
|
+
this.body.subtitle = some(segs);
|
|
2986
|
+
return this;
|
|
2987
|
+
}
|
|
2988
|
+
/** The subtitle line is a button running this action. */
|
|
2989
|
+
subtitleAction(a) {
|
|
2990
|
+
this.body.subtitle_action = a.name;
|
|
2991
|
+
return this;
|
|
2992
|
+
}
|
|
2993
|
+
/** A muted text after the title (a panel's `# returns`). */
|
|
2994
|
+
context(t) {
|
|
2995
|
+
this.body.context = txt(t);
|
|
2996
|
+
return this;
|
|
2997
|
+
}
|
|
2998
|
+
/** A faces pill: the faces, the label (`9 members`), the action. */
|
|
2999
|
+
faces(faces, label, a) {
|
|
3000
|
+
this.body.faces = { value: faces, label: txt(label), action: a.name };
|
|
3001
|
+
return this;
|
|
3002
|
+
}
|
|
3003
|
+
/** The faces pill's accessible name (absent: `{label}: open`). Call it after `faces`. */
|
|
3004
|
+
facesAriaLabel(t) {
|
|
3005
|
+
const f = this.body.faces;
|
|
3006
|
+
if (f)
|
|
3007
|
+
f.aria_label = txt(t);
|
|
3008
|
+
return this;
|
|
3009
|
+
}
|
|
3010
|
+
/** The faces pill is shown while `c` holds. */
|
|
3011
|
+
facesWhen(c) {
|
|
3012
|
+
const f = this.body.faces;
|
|
3013
|
+
if (f)
|
|
3014
|
+
f.visible = c;
|
|
3015
|
+
return this;
|
|
3016
|
+
}
|
|
3017
|
+
/** A text pill (at most 4). */
|
|
3018
|
+
button(label, a) {
|
|
3019
|
+
this.buttonList.push({ label: txt(label), action: a.name });
|
|
3020
|
+
this.body.buttons = this.buttonList;
|
|
3021
|
+
return this;
|
|
3022
|
+
}
|
|
3023
|
+
/** The last pill is shown while `c` holds. */
|
|
3024
|
+
buttonWhen(c) {
|
|
3025
|
+
const b = this.buttonList.at(-1);
|
|
3026
|
+
if (b)
|
|
3027
|
+
b.visible = c;
|
|
3028
|
+
return this;
|
|
3029
|
+
}
|
|
3030
|
+
/** `ui.iconButton` nodes (at most 4; a toggle bell). */
|
|
3031
|
+
icons(nodes) {
|
|
3032
|
+
this.body.icons = some(nodes);
|
|
3033
|
+
return this;
|
|
3034
|
+
}
|
|
3035
|
+
/** The `…` menu. */
|
|
3036
|
+
menu(items) {
|
|
3037
|
+
this.body.menu = { items: [...items] };
|
|
3038
|
+
return this;
|
|
3039
|
+
}
|
|
3040
|
+
/** The `…` button's and its menu's accessible label (absent: `More actions`). Call it after `menu`. */
|
|
3041
|
+
menuLabel(t) {
|
|
3042
|
+
const menu = this.body.menu;
|
|
3043
|
+
if (menu)
|
|
3044
|
+
menu.label = txt(t);
|
|
3045
|
+
return this;
|
|
3046
|
+
}
|
|
3047
|
+
/** Tabs bound to a string state (or param) whose default is one of the ids. */
|
|
3048
|
+
tabs(bind, items) {
|
|
3049
|
+
this.body.tabs = { bind: bind instanceof StateRef ? { state: bind.name } : { param: bind.name }, items: [...items] };
|
|
3050
|
+
return this;
|
|
3051
|
+
}
|
|
3052
|
+
/** The tab bar's accessible label (absent: the title). Call it after `tabs`. */
|
|
3053
|
+
tabsLabel(t) {
|
|
3054
|
+
const tabs = this.body.tabs;
|
|
3055
|
+
if (tabs)
|
|
3056
|
+
tabs.label = txt(t);
|
|
3057
|
+
return this;
|
|
3058
|
+
}
|
|
3059
|
+
/** The enclosing split's expand button (desktop). */
|
|
3060
|
+
expand() {
|
|
3061
|
+
this.body.expand = true;
|
|
3062
|
+
return this;
|
|
3063
|
+
}
|
|
3064
|
+
/** The panel's close button (desktop) and back button (phone). */
|
|
3065
|
+
close(a) {
|
|
3066
|
+
this.body.close = a.name;
|
|
3067
|
+
return this;
|
|
3068
|
+
}
|
|
3069
|
+
/** The phone back button's label. */
|
|
3070
|
+
back(t) {
|
|
3071
|
+
this.body.back = txt(t);
|
|
3072
|
+
return this;
|
|
3073
|
+
}
|
|
3074
|
+
phone() {
|
|
3075
|
+
return (this.body.phone ??= {});
|
|
3076
|
+
}
|
|
3077
|
+
/** The line under the phone's top-bar title. */
|
|
3078
|
+
phoneSub(t) {
|
|
3079
|
+
this.phone().sub = txt(t);
|
|
3080
|
+
return this;
|
|
3081
|
+
}
|
|
3082
|
+
/** Top-bar icon buttons on a phone: the actions of the header's icons or faces. */
|
|
3083
|
+
phoneIcons(actions) {
|
|
3084
|
+
this.phone().icons = some(actions.map((a) => a.name));
|
|
3085
|
+
return this;
|
|
3086
|
+
}
|
|
3087
|
+
/** The tabs first in the phone's `…` menu. */
|
|
3088
|
+
menuTabs() {
|
|
3089
|
+
this.phone().menu_tabs = true;
|
|
3090
|
+
return this;
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
function header(title) {
|
|
3094
|
+
return new HeaderB(title);
|
|
3095
|
+
}
|
|
3096
|
+
// --- stream
|
|
3097
|
+
/**
|
|
3098
|
+
* A live list of a query's rows (catalog 3), the newest at the bottom by default: older pages by the query's
|
|
3099
|
+
* `older`, day dividers, follow mode and jump to the latest, a `tail` query's rows merged after the rows by key, a
|
|
3100
|
+
* `head` row, an action when the newest row is seen, a post template per row:
|
|
3101
|
+
* `ui.stream(msgs).key(msg.f.id).post((p) => ..).days(msg.f.time)`.
|
|
3102
|
+
*/
|
|
3103
|
+
export class StreamB extends Node {
|
|
3104
|
+
constructor(query) {
|
|
3105
|
+
super("stream", { query, key: "", item: { post: new PostB() } });
|
|
3106
|
+
}
|
|
3107
|
+
/** The row field that identifies an item (pages, the tail, `merge` and `scrollTo` go by it). */
|
|
3108
|
+
key(f) {
|
|
3109
|
+
this.body.key = f.name;
|
|
3110
|
+
return this;
|
|
3111
|
+
}
|
|
3112
|
+
/** The template of a row. */
|
|
3113
|
+
post(build) {
|
|
3114
|
+
this.body.item = { post: build(new PostB()) };
|
|
3115
|
+
return this;
|
|
3116
|
+
}
|
|
3117
|
+
/** A template built elsewhere (shared by two streams); the stream keeps it as it is now. */
|
|
3118
|
+
postWith(p) {
|
|
3119
|
+
this.body.item = { post: p.clone() };
|
|
3120
|
+
return this;
|
|
3121
|
+
}
|
|
3122
|
+
/** Rows whose `field` equals `when` are one centred muted line: the author, the text, the time. */
|
|
3123
|
+
kindsLine(field, when, author, text, time) {
|
|
3124
|
+
this.body.kinds = { field: field.name, line: { when, author: rowPath(author), text: rowPath(text), time: rowPath(time) } };
|
|
3125
|
+
return this;
|
|
3126
|
+
}
|
|
3127
|
+
/**
|
|
3128
|
+
* Another query's rows (of the same row message) after the rows, by key: live items. A tail row gone from the next
|
|
3129
|
+
* tail answer stays until the main query has answered once more.
|
|
3130
|
+
*/
|
|
3131
|
+
tail(q) {
|
|
3132
|
+
this.body.tail = { query: q.name, hold: true };
|
|
3133
|
+
return this;
|
|
3134
|
+
}
|
|
3135
|
+
/** A row of the answer before the rows (drawn with the template, without its summary), and a rule under it. */
|
|
3136
|
+
head(row, rule) {
|
|
3137
|
+
this.body.head = { row: row.name, rule: txt(rule) };
|
|
3138
|
+
return this;
|
|
3139
|
+
}
|
|
3140
|
+
/** A list read from the top (no follow mode). */
|
|
3141
|
+
anchorTop() {
|
|
3142
|
+
this.body.anchor = "top";
|
|
3143
|
+
return this;
|
|
3144
|
+
}
|
|
3145
|
+
/** Older pages by a button only, with this label. */
|
|
3146
|
+
olderButton(label) {
|
|
3147
|
+
this.body.older_load = "button";
|
|
3148
|
+
this.body.older_label = txt(label);
|
|
3149
|
+
return this;
|
|
3150
|
+
}
|
|
3151
|
+
/** The label of the button that loads older pages. */
|
|
3152
|
+
olderLabel(label) {
|
|
3153
|
+
this.body.older_label = txt(label);
|
|
3154
|
+
return this;
|
|
3155
|
+
}
|
|
3156
|
+
/** A divider before each day (`Today`, `Yesterday`, the date) of this field's moments. */
|
|
3157
|
+
days(f) {
|
|
3158
|
+
this.body.days = rowPath(f);
|
|
3159
|
+
return this;
|
|
3160
|
+
}
|
|
3161
|
+
/** A `New` divider after the item with this key. */
|
|
3162
|
+
unread(key) {
|
|
3163
|
+
this.body.unread = value(key);
|
|
3164
|
+
return this;
|
|
3165
|
+
}
|
|
3166
|
+
/** The jump button's text when nothing new came (`Assistant is working`). */
|
|
3167
|
+
jumpWorking(t) {
|
|
3168
|
+
this.body.jump_working = txt(t);
|
|
3169
|
+
return this;
|
|
3170
|
+
}
|
|
3171
|
+
empty(t) {
|
|
3172
|
+
this.body.empty = txt(t);
|
|
3173
|
+
return this;
|
|
3174
|
+
}
|
|
3175
|
+
/** A muted line above the first item on a phone. */
|
|
3176
|
+
phoneIntro(t) {
|
|
3177
|
+
this.body.phone_intro = txt(t);
|
|
3178
|
+
return this;
|
|
3179
|
+
}
|
|
3180
|
+
/** Runs the action with `{row: <the newest row>}` once the reader is at the end and the newest row changed. */
|
|
3181
|
+
onSeen(a) {
|
|
3182
|
+
this.body.on_seen = { action: a.name };
|
|
3183
|
+
return this;
|
|
3184
|
+
}
|
|
3185
|
+
/** `onSeen` only while `c` holds (read in the newest row). */
|
|
3186
|
+
onSeenWhen(c) {
|
|
3187
|
+
const o = this.body.on_seen;
|
|
3188
|
+
if (o)
|
|
3189
|
+
o.when = c;
|
|
3190
|
+
return this;
|
|
3191
|
+
}
|
|
3192
|
+
/** The name composers refer to (`ui.composer(send).forStream('messages')`). */
|
|
3193
|
+
id(id) {
|
|
3194
|
+
this.body.id = id;
|
|
3195
|
+
return this;
|
|
3196
|
+
}
|
|
3197
|
+
/** The list's accessible name (`Messages`). */
|
|
3198
|
+
label(t) {
|
|
3199
|
+
this.body.label = txt(t);
|
|
3200
|
+
return this;
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
function stream(q) {
|
|
3204
|
+
return new StreamB(q.name);
|
|
3205
|
+
}
|
|
3206
|
+
// --- post
|
|
3207
|
+
/**
|
|
3208
|
+
* The template of a stream's row (catalog 3): who wrote it and when, its text and recording, marks and lines under
|
|
3209
|
+
* it, a slot for a run of work, reactions, a summary of what follows from it, and what can be done with it. Every
|
|
3210
|
+
* field is a row field or a path (`who.f(face.f.name)`, `ui.path(..)`).
|
|
3211
|
+
*/
|
|
3212
|
+
export class PostB extends Built {
|
|
3213
|
+
p;
|
|
3214
|
+
constructor(/** @internal */ p = { author: "", time: "" }) {
|
|
3215
|
+
super();
|
|
3216
|
+
this.p = p;
|
|
3217
|
+
}
|
|
3218
|
+
/** A copy to change apart (a second stream's template without its summary). */
|
|
3219
|
+
clone() {
|
|
3220
|
+
return new PostB(copyPlain(this.p));
|
|
3221
|
+
}
|
|
3222
|
+
author(f) {
|
|
3223
|
+
this.p.author = rowPath(f);
|
|
3224
|
+
return this;
|
|
3225
|
+
}
|
|
3226
|
+
time(f) {
|
|
3227
|
+
this.p.time = rowPath(f);
|
|
3228
|
+
return this;
|
|
3229
|
+
}
|
|
3230
|
+
avatarBody() {
|
|
3231
|
+
return (this.p.avatar ??= {});
|
|
3232
|
+
}
|
|
3233
|
+
/** The picture's URL (else the author's initials). */
|
|
3234
|
+
avatar(f) {
|
|
3235
|
+
this.avatarBody().url = rowPath(f);
|
|
3236
|
+
return this;
|
|
3237
|
+
}
|
|
3238
|
+
/** The agent tile: the glyph and the engine (drawn by default while `agent` is true or the glyph is not empty). */
|
|
3239
|
+
tile(icon, engine) {
|
|
3240
|
+
this.avatarBody().tile = { icon: rowPath(icon), engine: rowPath(engine) };
|
|
3241
|
+
return this;
|
|
3242
|
+
}
|
|
3243
|
+
/** The tile is drawn while `c` holds. */
|
|
3244
|
+
tileWhen(c) {
|
|
3245
|
+
const t = this.p.avatar?.tile;
|
|
3246
|
+
if (t)
|
|
3247
|
+
t.when = c;
|
|
3248
|
+
return this;
|
|
3249
|
+
}
|
|
3250
|
+
/** A tag after the name (`AGENT`) while `c` holds. */
|
|
3251
|
+
badge(t, c) {
|
|
3252
|
+
this.p.badge = { text: txt(t), when: c };
|
|
3253
|
+
return this;
|
|
3254
|
+
}
|
|
3255
|
+
/** A quiet line after the time (`via Commerce`). */
|
|
3256
|
+
source(f) {
|
|
3257
|
+
this.p.source = rowPath(f);
|
|
3258
|
+
return this;
|
|
3259
|
+
}
|
|
3260
|
+
/** The text as Markdown. */
|
|
3261
|
+
markdown(f) {
|
|
3262
|
+
this.p.text = { field: rowPath(f) };
|
|
3263
|
+
return this;
|
|
3264
|
+
}
|
|
3265
|
+
/** The text as plain text with `@[Name]` and `#[x]` chips (and the words lit while the recording plays). */
|
|
3266
|
+
plain(f) {
|
|
3267
|
+
this.p.text = { field: rowPath(f), format: "plain" };
|
|
3268
|
+
return this;
|
|
3269
|
+
}
|
|
3270
|
+
/** A bool field: the text is being written (a caret). */
|
|
3271
|
+
writing(f) {
|
|
3272
|
+
if (this.p.text)
|
|
3273
|
+
this.p.text.writing = rowPath(f);
|
|
3274
|
+
return this;
|
|
3275
|
+
}
|
|
3276
|
+
/** A recording: its duration (s); `.audioMore(label, url, words)`. */
|
|
3277
|
+
audio(duration) {
|
|
3278
|
+
this.p.audio = { duration: rowPath(duration) };
|
|
3279
|
+
return this;
|
|
3280
|
+
}
|
|
3281
|
+
/** The recording's label, URL (a data URL) and timed words (`word`, `start`, `end`). */
|
|
3282
|
+
audioMore(label, url, words) {
|
|
3283
|
+
if (this.p.audio)
|
|
3284
|
+
Object.assign(this.p.audio, { label: rowPath(label), url: rowPath(url), words: rowPath(words) });
|
|
3285
|
+
return this;
|
|
3286
|
+
}
|
|
3287
|
+
/** A bool field: `(edited)` after the text. */
|
|
3288
|
+
edited(f) {
|
|
3289
|
+
this.p.edited = rowPath(f);
|
|
3290
|
+
return this;
|
|
3291
|
+
}
|
|
3292
|
+
/** A bool field: pinned; `mark` true draws `Pinned` above the head. */
|
|
3293
|
+
pinned(f, mark) {
|
|
3294
|
+
this.p.pinned = { field: rowPath(f), mark: value(mark) };
|
|
3295
|
+
return this;
|
|
3296
|
+
}
|
|
3297
|
+
/** A bool field: the viewer's own row (no Reply to it). */
|
|
3298
|
+
mine(f) {
|
|
3299
|
+
this.p.mine = rowPath(f);
|
|
3300
|
+
return this;
|
|
3301
|
+
}
|
|
3302
|
+
/** A line under the text; its tone by a field's value (`{ done: 'ok' }`). Drawn while the route's `to` is empty. */
|
|
3303
|
+
receipt(text, tone, tones) {
|
|
3304
|
+
this.p.receipt = { text: rowPath(text), tone: { field: rowPath(tone), tones: tonesJson(tones) } };
|
|
3305
|
+
return this;
|
|
3306
|
+
}
|
|
3307
|
+
/** `→ <to> · <status>` with `why` as its tooltip; drawn while `to` is not empty. */
|
|
3308
|
+
route(to, status, why) {
|
|
3309
|
+
this.p.route = { to: rowPath(to), status: rowPath(status), why: rowPath(why) };
|
|
3310
|
+
return this;
|
|
3311
|
+
}
|
|
3312
|
+
/** A correction inline for 30 s after the moment `from` (ms), then in the menu: its label, the action. */
|
|
3313
|
+
correction(label, a, from) {
|
|
3314
|
+
this.p.correction = { label: rowPath(label), action: a.name, from: rowPath(from), window_ms: 30_000 };
|
|
3315
|
+
return this;
|
|
3316
|
+
}
|
|
3317
|
+
/** The correction's menu label, the words before it inline, its icon (`undo`, `arrow-right`). */
|
|
3318
|
+
correctionWords(menuLabel, lead, icon) {
|
|
3319
|
+
if (this.p.correction)
|
|
3320
|
+
Object.assign(this.p.correction, { menu_label: rowPath(menuLabel), lead: rowPath(lead), icon: rowPath(icon) });
|
|
3321
|
+
return this;
|
|
3322
|
+
}
|
|
3323
|
+
/** How long the correction stays inline (ms, at most 120000). */
|
|
3324
|
+
correctionWindowMs(ms) {
|
|
3325
|
+
if (this.p.correction)
|
|
3326
|
+
this.p.correction.window_ms = ms;
|
|
3327
|
+
return this;
|
|
3328
|
+
}
|
|
3329
|
+
/** Reaction chips: the repeated field, each one's emoji and count; a click runs `a` with `ui.form.emoji()`. */
|
|
3330
|
+
reactions(field, emoji, count, a) {
|
|
3331
|
+
this.p.reactions = { field: rowPath(field), emoji: emoji.name, count: count.name, action: a.name };
|
|
3332
|
+
return this;
|
|
3333
|
+
}
|
|
3334
|
+
/** The field of a reaction: the viewer's own (pressed). */
|
|
3335
|
+
reactionsMine(f) {
|
|
3336
|
+
if (this.p.reactions)
|
|
3337
|
+
this.p.reactions.mine = f.name;
|
|
3338
|
+
return this;
|
|
3339
|
+
}
|
|
3340
|
+
/** The emoji the hover's React offers (at most 8). */
|
|
3341
|
+
quick(emoji) {
|
|
3342
|
+
if (this.p.reactions)
|
|
3343
|
+
this.p.reactions.quick = some(emoji);
|
|
3344
|
+
return this;
|
|
3345
|
+
}
|
|
3346
|
+
/** What follows from the item (replies): its count and the action that opens it. */
|
|
3347
|
+
summary(count, a) {
|
|
3348
|
+
this.p.summary = { count: rowPath(count), action: a.name };
|
|
3349
|
+
return this;
|
|
3350
|
+
}
|
|
3351
|
+
/** The summary's label (`{count} replies`). */
|
|
3352
|
+
summaryLabel(t) {
|
|
3353
|
+
if (this.p.summary)
|
|
3354
|
+
this.p.summary.label = txt(t);
|
|
3355
|
+
return this;
|
|
3356
|
+
}
|
|
3357
|
+
/** The summary's faces, last line, who works (since a moment in ms) and who waits. */
|
|
3358
|
+
summaryMore(faces, last, working, since, waiting) {
|
|
3359
|
+
if (this.p.summary) {
|
|
3360
|
+
Object.assign(this.p.summary, {
|
|
3361
|
+
faces: rowPath(faces),
|
|
3362
|
+
last: rowPath(last),
|
|
3363
|
+
working: rowPath(working),
|
|
3364
|
+
since: rowPath(since),
|
|
3365
|
+
waiting: rowPath(waiting),
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
return this;
|
|
3369
|
+
}
|
|
3370
|
+
/** No summary (a pinned list's posts). */
|
|
3371
|
+
noSummary() {
|
|
3372
|
+
delete this.p.summary;
|
|
3373
|
+
return this;
|
|
3374
|
+
}
|
|
3375
|
+
/** A run of work above the text: `at` is the field holding it; the block's fields are fields of what it holds. */
|
|
3376
|
+
process(at, build) {
|
|
3377
|
+
this.p.process = build(new ProcessB(rowPath(at))).p;
|
|
3378
|
+
return this;
|
|
3379
|
+
}
|
|
3380
|
+
/** The rail on hover (desktop), in order. */
|
|
3381
|
+
hover(entries) {
|
|
3382
|
+
this.p.hover = some(entries);
|
|
3383
|
+
return this;
|
|
3384
|
+
}
|
|
3385
|
+
/** The `…` menu, in order. */
|
|
3386
|
+
menu(entries) {
|
|
3387
|
+
this.p.menu = some(entries);
|
|
3388
|
+
return this;
|
|
3389
|
+
}
|
|
3390
|
+
/** The phone's long-press sheet, in order. */
|
|
3391
|
+
sheet(entries) {
|
|
3392
|
+
this.p.sheet = some(entries);
|
|
3393
|
+
return this;
|
|
3394
|
+
}
|
|
3395
|
+
/** The inline editor of the text: `a` reads `ui.form.text()`; offered while `c` holds. */
|
|
3396
|
+
edit(a, c) {
|
|
3397
|
+
this.p.edit = { action: a.name, when: c };
|
|
3398
|
+
return this;
|
|
3399
|
+
}
|
|
3400
|
+
/** While false: no rail, menu, sheet or inline correction. */
|
|
3401
|
+
actionsWhen(c) {
|
|
3402
|
+
this.p.actions_when = c;
|
|
3403
|
+
return this;
|
|
3404
|
+
}
|
|
3405
|
+
/** The identity card a mention, the lead or the name opens. */
|
|
3406
|
+
card(c) {
|
|
3407
|
+
this.p.card = c;
|
|
3408
|
+
return this;
|
|
3409
|
+
}
|
|
3410
|
+
/** @internal */
|
|
3411
|
+
json() {
|
|
3412
|
+
return this.p;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
function post() {
|
|
3416
|
+
return new PostB();
|
|
3417
|
+
}
|
|
3418
|
+
/** An entry of a post's hover rail, menu or sheet: a built-in gesture (`ui.builtin.*`) or an action with its label. */
|
|
3419
|
+
export class PostEntryB extends Built {
|
|
3420
|
+
e;
|
|
3421
|
+
constructor(/** @internal */ e) {
|
|
3422
|
+
super();
|
|
3423
|
+
this.e = e;
|
|
3424
|
+
}
|
|
3425
|
+
icon(icon) {
|
|
3426
|
+
this.e.icon = icon;
|
|
3427
|
+
return this;
|
|
3428
|
+
}
|
|
3429
|
+
/** Drawn as a text button (the hover's `Ask agent`). */
|
|
3430
|
+
textStyle() {
|
|
3431
|
+
this.e.style = "text";
|
|
3432
|
+
return this;
|
|
3433
|
+
}
|
|
3434
|
+
/** Drawn as an icon button (the label is its tooltip). */
|
|
3435
|
+
iconStyle() {
|
|
3436
|
+
this.e.style = "icon";
|
|
3437
|
+
return this;
|
|
3438
|
+
}
|
|
3439
|
+
danger() {
|
|
3440
|
+
this.e.danger = true;
|
|
3441
|
+
return this;
|
|
3442
|
+
}
|
|
3443
|
+
visible(c) {
|
|
3444
|
+
this.e.visible = c;
|
|
3445
|
+
return this;
|
|
3446
|
+
}
|
|
3447
|
+
/** @internal */
|
|
3448
|
+
json() {
|
|
3449
|
+
return this.e;
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
/** An entry running an action on the row: `ui.postEntry(openThread, 'Reply in thread').icon('message-square-text')`. */
|
|
3453
|
+
function postEntry(a, label) {
|
|
3454
|
+
return new PostEntryB({ action: a.name, label: txt(label) });
|
|
3455
|
+
}
|
|
3456
|
+
const builtinEntry = (name) => () => new PostEntryB({ builtin: name });
|
|
3457
|
+
/** The built-in entries of a post: client gestures that need no plugin action (or the post's own options). */
|
|
3458
|
+
const builtin = {
|
|
3459
|
+
/** The quick reactions (needs `reactions`). */
|
|
3460
|
+
react: builtinEntry("react"),
|
|
3461
|
+
/** Reply to the author (needs a composer with `.reply()`). */
|
|
3462
|
+
reply: builtinEntry("reply"),
|
|
3463
|
+
copyText: builtinEntry("copy_text"),
|
|
3464
|
+
copyLink: builtinEntry("copy_link"),
|
|
3465
|
+
/** Play or pause the recording (needs `audio`). */
|
|
3466
|
+
play: builtinEntry("play"),
|
|
3467
|
+
/** The inline editor (needs `edit`). */
|
|
3468
|
+
edit: builtinEntry("edit"),
|
|
3469
|
+
/** The correction after its inline window (needs `correction`). */
|
|
3470
|
+
correction: builtinEntry("correction"),
|
|
3471
|
+
/** The `…` button that opens the menu (the hover rail only). */
|
|
3472
|
+
more: builtinEntry("more"),
|
|
3473
|
+
separator: builtinEntry("separator"),
|
|
3474
|
+
};
|
|
3475
|
+
/** An identity card: a name looked up (case-insensitively) in a query's rows. */
|
|
3476
|
+
export class CardB extends Built {
|
|
3477
|
+
c;
|
|
3478
|
+
constructor(query, name) {
|
|
3479
|
+
super();
|
|
3480
|
+
this.c = { query, name };
|
|
3481
|
+
}
|
|
3482
|
+
avatar(f) {
|
|
3483
|
+
this.c.avatar = f.name;
|
|
3484
|
+
return this;
|
|
3485
|
+
}
|
|
3486
|
+
agent(f) {
|
|
3487
|
+
this.c.agent = f.name;
|
|
3488
|
+
return this;
|
|
3489
|
+
}
|
|
3490
|
+
tile(icon, engine) {
|
|
3491
|
+
Object.assign(this.c, { icon: icon.name, engine: engine.name });
|
|
3492
|
+
return this;
|
|
3493
|
+
}
|
|
3494
|
+
detail(f) {
|
|
3495
|
+
this.c.detail = f.name;
|
|
3496
|
+
return this;
|
|
3497
|
+
}
|
|
3498
|
+
/** The card's button: `a` reads `ui.form.to()`. */
|
|
3499
|
+
action(a) {
|
|
3500
|
+
this.c.action = a.name;
|
|
3501
|
+
return this;
|
|
3502
|
+
}
|
|
3503
|
+
/** What the card says of a name not in the rows. */
|
|
3504
|
+
unknown(t) {
|
|
3505
|
+
this.c.unknown = txt(t);
|
|
3506
|
+
return this;
|
|
3507
|
+
}
|
|
3508
|
+
/** @internal */
|
|
3509
|
+
json() {
|
|
3510
|
+
return this.c;
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
/** `ui.cardOf(people, face.f.name)`: the identity card over a query's rows. */
|
|
3514
|
+
function cardOf(q, name) {
|
|
3515
|
+
return new CardB(q.name, name.name);
|
|
3516
|
+
}
|
|
3517
|
+
// --- process
|
|
3518
|
+
/**
|
|
3519
|
+
* A run of work (catalog 3): as a post's slot (`p.process(msg.f.work, (w) => w.state(work.f.state)..)`) or on its own
|
|
3520
|
+
* over a query's answer (`ui.process(runQ, (w) => ..)`). Live (`starting`, `working`), done, or ended (`stopped`,
|
|
3521
|
+
* `failed`, `timed_out`, `gone`); no block while `state` is empty. Its rows and calls have fixed field names.
|
|
3522
|
+
*/
|
|
3523
|
+
export class ProcessB {
|
|
3524
|
+
at;
|
|
3525
|
+
/** @internal */ p = { state: "" };
|
|
3526
|
+
constructor(at) {
|
|
3527
|
+
this.at = at;
|
|
3528
|
+
}
|
|
3529
|
+
path(f) {
|
|
3530
|
+
return this.at === undefined ? f.name : `${this.at}.${f.name}`;
|
|
3531
|
+
}
|
|
3532
|
+
/** `starting`, `working`, `done`, `stopped`, `failed`, `timed_out`, `gone`; no block while empty. */
|
|
3533
|
+
state(f) {
|
|
3534
|
+
this.p.state = this.path(f);
|
|
3535
|
+
return this;
|
|
3536
|
+
}
|
|
3537
|
+
label(f) {
|
|
3538
|
+
this.p.label = this.path(f);
|
|
3539
|
+
return this;
|
|
3540
|
+
}
|
|
3541
|
+
meta(f) {
|
|
3542
|
+
this.p.meta = this.path(f);
|
|
3543
|
+
return this;
|
|
3544
|
+
}
|
|
3545
|
+
/** The moment (ms) the live block counts from. */
|
|
3546
|
+
started(f) {
|
|
3547
|
+
this.p.started = this.path(f);
|
|
3548
|
+
return this;
|
|
3549
|
+
}
|
|
3550
|
+
/** The rows: `kind`, `title`, `detail`, `state`, `time`, `at`, `calls`, `tools`. */
|
|
3551
|
+
rows(f) {
|
|
3552
|
+
this.p.rows = this.path(f);
|
|
3553
|
+
return this;
|
|
3554
|
+
}
|
|
3555
|
+
/** The number of steps (`View N steps`). */
|
|
3556
|
+
steps(f) {
|
|
3557
|
+
this.p.steps = this.path(f);
|
|
3558
|
+
return this;
|
|
3559
|
+
}
|
|
3560
|
+
/** The text being written (with a caret). */
|
|
3561
|
+
saying(f) {
|
|
3562
|
+
this.p.saying = this.path(f);
|
|
3563
|
+
return this;
|
|
3564
|
+
}
|
|
3565
|
+
/** Retry on an ended block, with its label from a field, while `c` holds. */
|
|
3566
|
+
retry(a, label, c) {
|
|
3567
|
+
this.p.retry = { action: a.name, label: this.path(label), when: c };
|
|
3568
|
+
return this;
|
|
3569
|
+
}
|
|
3570
|
+
/** `Open full log`. */
|
|
3571
|
+
log(a) {
|
|
3572
|
+
this.p.log = { action: a.name };
|
|
3573
|
+
return this;
|
|
3574
|
+
}
|
|
3575
|
+
/**
|
|
3576
|
+
* How a truncated call is read whole: `q` read once more with `a` and the request field `call` set to the call's
|
|
3577
|
+
* id; the answer's `field` replaces the call.
|
|
3578
|
+
*/
|
|
3579
|
+
fetchCall(q, call, field, a) {
|
|
3580
|
+
this.p.fetch_call = { query: q.name, args: some(args(a)), call: call.name, field: field.name };
|
|
3581
|
+
return this;
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
/** A run of work on its own, over a query's answer: `ui.process(runQ, (w) => w.state(run.f.state).rows(run.f.rows))`. */
|
|
3585
|
+
function processNode(q, build) {
|
|
3586
|
+
return n("process", { query: q.name, ...build(new ProcessB()).p });
|
|
3587
|
+
}
|
|
3588
|
+
// --- strip
|
|
3589
|
+
/** A button of a strip's row: `ui.stripButton('Stop', stop).icon('square').stopStyle()`. */
|
|
3590
|
+
export class StripButtonB extends Built {
|
|
3591
|
+
s;
|
|
3592
|
+
constructor(label, a) {
|
|
3593
|
+
super();
|
|
3594
|
+
this.s = { label: txt(label), action: a.name };
|
|
3595
|
+
}
|
|
3596
|
+
icon(icon) {
|
|
3597
|
+
this.s.icon = icon;
|
|
3598
|
+
return this;
|
|
3599
|
+
}
|
|
3600
|
+
/** The red-outlined Stop with the filled square. */
|
|
3601
|
+
stopStyle() {
|
|
3602
|
+
this.s.style = "stop";
|
|
3603
|
+
return this;
|
|
3604
|
+
}
|
|
3605
|
+
/** A muted text button. */
|
|
3606
|
+
textStyle() {
|
|
3607
|
+
this.s.style = "text";
|
|
3608
|
+
return this;
|
|
3609
|
+
}
|
|
3610
|
+
visible(c) {
|
|
3611
|
+
this.s.visible = c;
|
|
3612
|
+
return this;
|
|
3613
|
+
}
|
|
3614
|
+
/** @internal */
|
|
3615
|
+
json() {
|
|
3616
|
+
return this.s;
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
function stripButton(label, a) {
|
|
3620
|
+
return new StripButtonB(label, a);
|
|
3621
|
+
}
|
|
3622
|
+
/**
|
|
3623
|
+
* A pinned list of live items (catalog 3): a tile, the title, a dot (live, waiting), `Starting` or the time since
|
|
3624
|
+
* `since`, a sub line, a jump to the item's place in a stream and buttons; hidden while there are no rows.
|
|
3625
|
+
*/
|
|
3626
|
+
export class StripB extends Node {
|
|
3627
|
+
buttonList = [];
|
|
3628
|
+
constructor(body) {
|
|
3629
|
+
super("strip", body);
|
|
3630
|
+
}
|
|
3631
|
+
/** Above the items (`2 live runs`); none while empty. */
|
|
3632
|
+
label(t) {
|
|
3633
|
+
this.body.label = txt(t);
|
|
3634
|
+
return this;
|
|
3635
|
+
}
|
|
3636
|
+
tile(icon, engine) {
|
|
3637
|
+
this.body.tile = { icon: icon.name, engine: engine.name };
|
|
3638
|
+
return this;
|
|
3639
|
+
}
|
|
3640
|
+
/** Which values of the field are live, waiting and starting. */
|
|
3641
|
+
state(f, live, waiting = [], starting = []) {
|
|
3642
|
+
this.body.state = { field: f.name, live: some(live), waiting: some(waiting), starting: some(starting) };
|
|
3643
|
+
return this;
|
|
3644
|
+
}
|
|
3645
|
+
/** The moment (ms) an item counts from. */
|
|
3646
|
+
since(f) {
|
|
3647
|
+
this.body.since = f.name;
|
|
3648
|
+
return this;
|
|
3649
|
+
}
|
|
3650
|
+
/** The moment (ms) a waiting item counts down to. */
|
|
3651
|
+
until(f) {
|
|
3652
|
+
this.body.until = f.name;
|
|
3653
|
+
return this;
|
|
3654
|
+
}
|
|
3655
|
+
/** The line under the title. */
|
|
3656
|
+
subLine(f) {
|
|
3657
|
+
this.body.sub = f.name;
|
|
3658
|
+
return this;
|
|
3659
|
+
}
|
|
3660
|
+
/** After a waiting item's sub line, with `{left}` the countdown (`ends in {left}`). */
|
|
3661
|
+
countdownText(t) {
|
|
3662
|
+
this.body.countdown_text = txt(t);
|
|
3663
|
+
return this;
|
|
3664
|
+
}
|
|
3665
|
+
/** The tile and the title run it (row context). */
|
|
3666
|
+
open(a) {
|
|
3667
|
+
this.body.open = a.name;
|
|
3668
|
+
return this;
|
|
3669
|
+
}
|
|
3670
|
+
/** The jump to the item's place in a stream: the key in `f`, the labels by state. */
|
|
3671
|
+
jump(f, label, labelWaiting) {
|
|
3672
|
+
this.body.jump = { field: f.name, label: txt(label), label_waiting: txt(labelWaiting) };
|
|
3673
|
+
return this;
|
|
3674
|
+
}
|
|
3675
|
+
button(b) {
|
|
3676
|
+
this.buttonList.push(b);
|
|
3677
|
+
this.body.buttons = this.buttonList;
|
|
3678
|
+
return this;
|
|
3679
|
+
}
|
|
3680
|
+
ariaLabel(t) {
|
|
3681
|
+
this.body.aria_label = txt(t);
|
|
3682
|
+
return this;
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
/** A strip over a repeated field of a query's answer, each item keyed by `key` and titled by `title`. */
|
|
3686
|
+
function strip(q, rows, key, title) {
|
|
3687
|
+
return new StripB({ query: q.name, rows: rows.name, key: key.name, title: title.name });
|
|
3688
|
+
}
|
|
3689
|
+
/** The mention picker's directory: `ui.mentions(people, face.f.name).tile(face.f.icon, face.f.engine)`. */
|
|
3690
|
+
export class MentionsB extends Built {
|
|
3691
|
+
m;
|
|
3692
|
+
constructor(query, name) {
|
|
3693
|
+
super();
|
|
3694
|
+
this.m = { query, name };
|
|
3695
|
+
}
|
|
3696
|
+
avatar(f) {
|
|
3697
|
+
this.m.avatar = f.name;
|
|
3698
|
+
return this;
|
|
3699
|
+
}
|
|
3700
|
+
agent(f) {
|
|
3701
|
+
this.m.agent = f.name;
|
|
3702
|
+
return this;
|
|
3703
|
+
}
|
|
3704
|
+
tile(icon, engine) {
|
|
3705
|
+
Object.assign(this.m, { icon: icon.name, engine: engine.name });
|
|
3706
|
+
return this;
|
|
3707
|
+
}
|
|
3708
|
+
detail(f) {
|
|
3709
|
+
this.m.detail = f.name;
|
|
3710
|
+
return this;
|
|
3711
|
+
}
|
|
3712
|
+
/** The rows are grouped by this field on a desktop. */
|
|
3713
|
+
section(f) {
|
|
3714
|
+
this.m.section = f.name;
|
|
3715
|
+
return this;
|
|
3716
|
+
}
|
|
3717
|
+
/** The picker's footer note. */
|
|
3718
|
+
note(t) {
|
|
3719
|
+
this.m.note = txt(t);
|
|
3720
|
+
return this;
|
|
3721
|
+
}
|
|
3722
|
+
/** @internal */
|
|
3723
|
+
json() {
|
|
3724
|
+
return this.m;
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
function mentions(q, name) {
|
|
3728
|
+
return new MentionsB(q.name, name.name);
|
|
3729
|
+
}
|
|
3730
|
+
/**
|
|
3731
|
+
* A message box (catalog 3): `ui.composer(send).forStream('messages').primary().mentions(..).reply()`. `send` reads
|
|
3732
|
+
* `ui.form.text()`, `ui.form.reply()`, the recording (`audio`, `duration`, `language`, `words`) and each option
|
|
3733
|
+
* (`ui.form.option('also')`).
|
|
3734
|
+
*/
|
|
3735
|
+
export class ComposerB extends Node {
|
|
3736
|
+
optionList = [];
|
|
3737
|
+
captionList = [];
|
|
3738
|
+
constructor(send) {
|
|
3739
|
+
super("composer", { send });
|
|
3740
|
+
}
|
|
3741
|
+
/** The `id` of the stream it belongs to (jumps to its end on send; `draft` and `replyTo` from its items). */
|
|
3742
|
+
forStream(id) {
|
|
3743
|
+
this.body.for = id;
|
|
3744
|
+
return this;
|
|
3745
|
+
}
|
|
3746
|
+
placeholder(t) {
|
|
3747
|
+
this.body.placeholder = txt(t);
|
|
3748
|
+
return this;
|
|
3749
|
+
}
|
|
3750
|
+
/** Owns ⌥ Space and the steps of rows outside a stream; one per frame. */
|
|
3751
|
+
primary() {
|
|
3752
|
+
this.body.primary = true;
|
|
3753
|
+
return this;
|
|
3754
|
+
}
|
|
3755
|
+
/** The panel's box. */
|
|
3756
|
+
compact() {
|
|
3757
|
+
this.body.compact = true;
|
|
3758
|
+
return this;
|
|
3759
|
+
}
|
|
3760
|
+
/** The tools besides the mention; none when empty. */
|
|
3761
|
+
tools(tools) {
|
|
3762
|
+
this.body.tools = some(tools);
|
|
3763
|
+
return this;
|
|
3764
|
+
}
|
|
3765
|
+
mentions(m) {
|
|
3766
|
+
this.body.mentions = m;
|
|
3767
|
+
return this;
|
|
3768
|
+
}
|
|
3769
|
+
/** `#word` becomes `#[word]` on send. */
|
|
3770
|
+
tags() {
|
|
3771
|
+
this.body.tags = true;
|
|
3772
|
+
return this;
|
|
3773
|
+
}
|
|
3774
|
+
/** The Dictate button (shown when the workspace has a speech connection). */
|
|
3775
|
+
dictation() {
|
|
3776
|
+
this.body.dictation ??= {};
|
|
3777
|
+
return this;
|
|
3778
|
+
}
|
|
3779
|
+
/** Words for the recogniser besides the mentionable names. */
|
|
3780
|
+
vocabulary(t) {
|
|
3781
|
+
(this.body.dictation ??= {}).vocabulary = txt(t);
|
|
3782
|
+
return this;
|
|
3783
|
+
}
|
|
3784
|
+
/** Takes `replyTo`: `ui.form.reply()` is the key. */
|
|
3785
|
+
reply() {
|
|
3786
|
+
this.body.reply = true;
|
|
3787
|
+
return this;
|
|
3788
|
+
}
|
|
3789
|
+
/** A checkbox under the box (`ui.form.option(name)`). */
|
|
3790
|
+
option(name, label) {
|
|
3791
|
+
this.optionList.push({ name, label: txt(label) });
|
|
3792
|
+
this.body.options = this.optionList;
|
|
3793
|
+
return this;
|
|
3794
|
+
}
|
|
3795
|
+
/** The last option is shown while `c` holds. */
|
|
3796
|
+
optionWhen(c) {
|
|
3797
|
+
const o = this.optionList.at(-1);
|
|
3798
|
+
if (o)
|
|
3799
|
+
o.visible = c;
|
|
3800
|
+
return this;
|
|
3801
|
+
}
|
|
3802
|
+
/** A caption line naming who will answer (`↳ …`); the first caption with a value is drawn. */
|
|
3803
|
+
captionRoute(t) {
|
|
3804
|
+
this.captionList.push({ value: txt(t), icon: "corner-down-right", style: "route" });
|
|
3805
|
+
this.body.caption = this.captionList;
|
|
3806
|
+
return this;
|
|
3807
|
+
}
|
|
3808
|
+
/** A plain caption line. */
|
|
3809
|
+
captionDot(t) {
|
|
3810
|
+
this.captionList.push({ value: txt(t), style: "dot" });
|
|
3811
|
+
this.body.caption = this.captionList;
|
|
3812
|
+
return this;
|
|
3813
|
+
}
|
|
3814
|
+
/** While `c` holds and the box is empty, Send is a labelled Stop running `a` (and Esc runs it). */
|
|
3815
|
+
stop(a, c) {
|
|
3816
|
+
this.body.stop = { action: a.name, when: c };
|
|
3817
|
+
return this;
|
|
3818
|
+
}
|
|
3819
|
+
stopLabel(t) {
|
|
3820
|
+
const s = this.body.stop;
|
|
3821
|
+
if (s)
|
|
3822
|
+
s.label = txt(t);
|
|
3823
|
+
return this;
|
|
3824
|
+
}
|
|
3825
|
+
/** The Stop button's accessible name (absent: its label). Call it after `stop`. */
|
|
3826
|
+
stopAriaLabel(t) {
|
|
3827
|
+
const s = this.body.stop;
|
|
3828
|
+
if (s)
|
|
3829
|
+
s.aria_label = txt(t);
|
|
3830
|
+
return this;
|
|
3831
|
+
}
|
|
3832
|
+
/** While `c` holds, the reason stands where the box would be. */
|
|
3833
|
+
readOnly(c, reason) {
|
|
3834
|
+
this.body.readonly = { when: c, reason: txt(reason) };
|
|
3835
|
+
return this;
|
|
3836
|
+
}
|
|
3837
|
+
/** The text is mirrored into this string state, for a query that reads what is typed. */
|
|
3838
|
+
draftState(s) {
|
|
3839
|
+
this.body.draft_state = s.name;
|
|
3840
|
+
return this;
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
function composer(send) {
|
|
3844
|
+
return new ComposerB(send.name);
|
|
3845
|
+
}
|
|
3846
|
+
// ---------------------------------------------------------------------------------------------- the namespace
|
|
3847
|
+
/** The UI builders. */
|
|
3848
|
+
export const ui = {
|
|
3849
|
+
define,
|
|
3850
|
+
// texts and values
|
|
3851
|
+
text,
|
|
3852
|
+
lit: (x) => new Val({ lit: encode(x) }),
|
|
3853
|
+
row,
|
|
3854
|
+
/** A field of the last call's result in the running chain. */
|
|
3855
|
+
result: (f) => new Val({ result: f.name }),
|
|
3856
|
+
/** The member looking at the screen. */
|
|
3857
|
+
callerId: () => new Val({ caller: "user_id" }),
|
|
3858
|
+
callerName: () => new Val({ caller: "display_name" }),
|
|
3859
|
+
/** In `onError`: what failed. */
|
|
3860
|
+
errorCode: () => new Val({ error: "code" }),
|
|
3861
|
+
errorMessage: () => new Val({ error: "message" }),
|
|
3862
|
+
errorOutcome: () => new Val({ error: "outcome" }),
|
|
3863
|
+
errorStep: () => new Val({ error: "step" }),
|
|
3864
|
+
/** No value: clears an optional param or state (`a.setParam(order, ui.none())`). */
|
|
3865
|
+
none: () => new Val({ lit: null }),
|
|
3866
|
+
/** A field of the current row, where no row handle is at hand (a list's aside text). */
|
|
3867
|
+
rowValue: (f) => new Val({ row: f.name }),
|
|
3868
|
+
/** The form's current values, for queries of the same overlay (a quote that reads them as they change). */
|
|
3869
|
+
formValue: (f) => new Val({ form: f.name }),
|
|
3870
|
+
not: (c) => new Cond({ not: c.c }),
|
|
3871
|
+
// queries, screens, overlays, actions
|
|
3872
|
+
call,
|
|
3873
|
+
screenKey,
|
|
3874
|
+
overlayKey,
|
|
3875
|
+
screen,
|
|
3876
|
+
dialog: overlayOf("dialog"),
|
|
3877
|
+
sidePanel: overlayOf("side_panel"),
|
|
3878
|
+
sheet: overlayOf("sheet"),
|
|
3879
|
+
confirm,
|
|
3880
|
+
// structure
|
|
3881
|
+
stack,
|
|
3882
|
+
columns,
|
|
3883
|
+
section,
|
|
3884
|
+
card,
|
|
3885
|
+
titledCard,
|
|
3886
|
+
tabs,
|
|
3887
|
+
tab,
|
|
3888
|
+
divider,
|
|
3889
|
+
split,
|
|
3890
|
+
board,
|
|
3891
|
+
// navigation
|
|
3892
|
+
segmented,
|
|
3893
|
+
link,
|
|
3894
|
+
// data
|
|
3895
|
+
table,
|
|
3896
|
+
list,
|
|
3897
|
+
fields,
|
|
3898
|
+
item,
|
|
3899
|
+
metric,
|
|
3900
|
+
barChart: chartOf("bar"),
|
|
3901
|
+
lineChart: chartOf("line"),
|
|
3902
|
+
areaChart: chartOf("area"),
|
|
3903
|
+
pieChart: chartOf("pie"),
|
|
3904
|
+
viz,
|
|
3905
|
+
timeline,
|
|
3906
|
+
status,
|
|
3907
|
+
tag,
|
|
3908
|
+
avatar,
|
|
3909
|
+
avatarStack,
|
|
3910
|
+
meter,
|
|
3911
|
+
progress,
|
|
3912
|
+
heading,
|
|
3913
|
+
caption,
|
|
3914
|
+
mono,
|
|
3915
|
+
copyField,
|
|
3916
|
+
label,
|
|
3917
|
+
empty,
|
|
3918
|
+
notice,
|
|
3919
|
+
// records
|
|
3920
|
+
recordHeader,
|
|
3921
|
+
agentRun,
|
|
3922
|
+
conversation,
|
|
3923
|
+
/** @deprecated Catalog 3 deprecates `chat` (`W_UI_DEPRECATED`): a `fill` split with `ui.header`, `ui.stream`,
|
|
3924
|
+
* `ui.strip` and `ui.composer`. */
|
|
3925
|
+
chat,
|
|
3926
|
+
rowView,
|
|
3927
|
+
search,
|
|
3928
|
+
// input and actions
|
|
3929
|
+
filterBar,
|
|
3930
|
+
button,
|
|
3931
|
+
iconButton,
|
|
3932
|
+
menu,
|
|
3933
|
+
menuButton,
|
|
3934
|
+
menuItem,
|
|
3935
|
+
// app-like screens (catalog 3)
|
|
3936
|
+
via,
|
|
3937
|
+
path,
|
|
3938
|
+
rowAt,
|
|
3939
|
+
/** The values a composer, a post's actions and a toggle give their chain. */
|
|
3940
|
+
form,
|
|
3941
|
+
pickedCount,
|
|
3942
|
+
pickedAgents,
|
|
3943
|
+
pickedFirst,
|
|
3944
|
+
pickedQuery,
|
|
3945
|
+
header,
|
|
3946
|
+
headerTab,
|
|
3947
|
+
seg,
|
|
3948
|
+
stream,
|
|
3949
|
+
post,
|
|
3950
|
+
postEntry,
|
|
3951
|
+
builtin,
|
|
3952
|
+
cardOf,
|
|
3953
|
+
process: processNode,
|
|
3954
|
+
strip,
|
|
3955
|
+
stripButton,
|
|
3956
|
+
composer,
|
|
3957
|
+
mentions,
|
|
3958
|
+
// contributions
|
|
3959
|
+
nav,
|
|
3960
|
+
entry,
|
|
3961
|
+
entryRows,
|
|
3962
|
+
command,
|
|
3963
|
+
home,
|
|
3964
|
+
};
|