@protobase/cli 0.89.1 → 0.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/package.js +1 -1
- package/dist/doctor/view-shapes.js +18 -2
- package/package.json +8 -8
- package/skills/protobase/references/features/composed-pages.md +1 -0
- package/skills/protobase/references/features/record-pages.md +2 -1
- package/skills/protobase/references/guides/api-functions.md +1 -1
- package/skills/protobase/references/reference/blocks.md +39 -3
- package/skills/protobase/references/reference/client.md +1 -1
- package/skills/protobase/references/reference/custom-components.md +3 -0
- package/skills/protobase/references/reference/layouts.md +1 -0
- package/skills/protobase/references/reference/ui-config.md +40 -1
package/dist/cli/package.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { all, any, anyOf, compare, configFilter, configSort, isTrue, sortText } from "./shape-filters.js";
|
|
2
|
+
import { threadSort } from "@protobase/layout";
|
|
2
3
|
import { isGroupChart, layoutItems, viewOfList } from "@protobase/schema/internal";
|
|
3
4
|
//#region src/doctor/view-shapes.ts
|
|
4
5
|
const numberTypes = [
|
|
@@ -127,6 +128,21 @@ const recordChartShapes = (item, owner, models) => {
|
|
|
127
128
|
}
|
|
128
129
|
}];
|
|
129
130
|
};
|
|
131
|
+
const threadShapes = (item, owner, models) => {
|
|
132
|
+
const target = models[item.resource];
|
|
133
|
+
const field = target?.fields[item.field];
|
|
134
|
+
if (!target || !field || !target.fields[item.time]) return [];
|
|
135
|
+
const sort = configSort(target, threadSort(item.time));
|
|
136
|
+
return [{
|
|
137
|
+
resource: target.name,
|
|
138
|
+
request: request(target.name, `${field.name} = …`, sort),
|
|
139
|
+
from: `thread "${item.title}" on the ${owner} record page`,
|
|
140
|
+
query: {
|
|
141
|
+
filter: compare(field),
|
|
142
|
+
...sort && { sort }
|
|
143
|
+
}
|
|
144
|
+
}];
|
|
145
|
+
};
|
|
130
146
|
const displayShapes = (model, view, models) => (view.list?.displays ?? []).flatMap((display) => {
|
|
131
147
|
if (display.kind === "map") {
|
|
132
148
|
const latitude = model.fields[display.latitude];
|
|
@@ -261,7 +277,7 @@ const listShapes = (model, view, list, models) => [
|
|
|
261
277
|
];
|
|
262
278
|
/**
|
|
263
279
|
* The reads a view's pages make: its list in its order, the filter widgets and their counts, its chart per value, its displays' maps,
|
|
264
|
-
* board columns and photos, the records of its related sections and
|
|
280
|
+
* board columns and photos, the records of its related sections, charts and conversations and the photos of its galleries, the recent records in the sidebar, a saved search's new records and the records sorted by hand.
|
|
265
281
|
*/
|
|
266
282
|
const viewShapes = (view, models) => {
|
|
267
283
|
const model = models[view.resource];
|
|
@@ -270,7 +286,7 @@ const viewShapes = (view, models) => {
|
|
|
270
286
|
return [
|
|
271
287
|
...listShapes(model, view, list, models),
|
|
272
288
|
...(view.lists ?? []).flatMap((named) => listShapes(model, viewOfList(view, named.name), `${list} "${named.name}"`, models)),
|
|
273
|
-
...layoutItems(view.layout).flatMap((item) => item.kind === "related" ? relatedShapes(item, model.name, models) : item.kind === "gallery" ? galleryShapes(item, model.name, models) : item.kind === "chart" ? recordChartShapes(item, model.name, models) : []),
|
|
289
|
+
...layoutItems(view.layout).flatMap((item) => item.kind === "related" ? relatedShapes(item, model.name, models) : item.kind === "gallery" ? galleryShapes(item, model.name, models) : item.kind === "chart" ? recordChartShapes(item, model.name, models) : item.kind === "thread" ? threadShapes(item, model.name, models) : []),
|
|
274
290
|
...recentShapes(model, view),
|
|
275
291
|
...searchesShapes(view, models),
|
|
276
292
|
...handOrderShapes(model, view, list, models)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.90.1",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.90.1",
|
|
47
|
+
"@protobase/layout": "0.90.1",
|
|
48
|
+
"@protobase/query": "0.90.1",
|
|
49
|
+
"@protobase/schema": "0.90.1",
|
|
50
|
+
"@protobase/server": "0.90.1",
|
|
51
|
+
"@protobase/ui": "0.90.1",
|
|
52
|
+
"@protobase/workflows": "0.90.1",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -16,6 +16,7 @@ Pages of your own, built from blocks in a JSX layout.
|
|
|
16
16
|
- [Row buttons](../reference/blocks.md#row-buttons): A table's rows carry a button to an address their fields name, such as a task's tab, labelled by a field of the row, such as its next step.
|
|
17
17
|
- [Record rows](../reference/blocks.md#recordrow): A sideways row of cards for a filter, favorites or saved searches, with a count and new-record marks.
|
|
18
18
|
- [Record cards](../reference/blocks.md#recordcards): Full-width cards with fields and buttons, stacked or in a carousel.
|
|
19
|
+
- [Image block](../reference/blocks.md#image): A picture one of the app's API functions draws for the reader, such as a system map, at the size and theme the client asks, refreshed on a timer; a client that draws no images shows its alt text, or nothing.
|
|
19
20
|
- [Chart block](../reference/blocks.md#chart): Counts, sums or averages by value or by date, as bars, lines or a donut, and over time split by a second field.
|
|
20
21
|
- [Conversations](../reference/blocks.md#conversation): A chat declared in the layout: a thread of a resource's messages under each sender's name and time, following new ones as they arrive, and a box that sends one as the signed-in user.
|
|
21
22
|
- [Buttons and forms](../reference/blocks.md#behaviour): Buttons for named actions, and create or edit forms in a dialog.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The page of one record, with its sections, related records, galleries, charts and editing.
|
|
6
6
|
|
|
7
|
-
- [Record page layout](../reference/ui-config.md#the-record-page): Sections, a summary sidebar, related tables, maps, charts, galleries, history, comments and your own components.
|
|
7
|
+
- [Record page layout](../reference/ui-config.md#the-record-page): Sections, a summary sidebar, related tables, maps, charts, galleries, history, comments, conversations and your own components.
|
|
8
8
|
- [Full-width record pages](../reference/ui-config.md#page-width): A view's record pages and create form fill the whole area beside the sidebar instead of a centred column, with the sidebar cards still beside the sections.
|
|
9
9
|
- [Focus pages](../reference/ui-config.md#focus-pages) (beta): A record whose page is one big surface, such as a graph or a board, fills the page under a thin bar with its Save, actions and panels, its form a link away.
|
|
10
10
|
- [A create address that opens a page](../reference/ui-config.md#focus-pages) (beta): `.createOpens(to)` sends a resource's create address to a page in place of its form, such as a record's focus page with a panel open, filled from the address's values.
|
|
@@ -27,6 +27,7 @@ The page of one record, with its sections, related records, galleries, charts an
|
|
|
27
27
|
- [Galleries](../reference/ui-config.md#galleries): A record's photos show as tiles that open a full-screen lightbox, with keyboard and swipe navigation.
|
|
28
28
|
- [Related records](../reference/ui-config.md#related-records): Every record page shows how many records point at it, and can list related records, also through a join resource, as a table, another display or cards with buttons, each row or card with a button to an address its fields name.
|
|
29
29
|
- [Record lines](../reference/ui-config.md#record-lines): The related table a record's view marks as its lines, such as an invoice's, shows all of them on its page, where you edit, add, remove and reorder them, and Save writes the record and its lines together.
|
|
30
|
+
- [Conversations](../reference/ui-config.md#conversations): A record page holds a chat about the record, such as a task's, with its messages in markdown and a box that sends one, declared in its layout with no component of the app's own.
|
|
30
31
|
- [Charts of samples](../reference/ui-config.md#charts-of-related-records): A record page graphs numeric samples over the last hour, day or week, such as a server's CPU use.
|
|
31
32
|
- [Fresh data on return](../reference/ui-config.md#the-record-page): Records and lists reload when the browser tab is focused again, keeping unsaved edits.
|
|
32
33
|
- [Safe deletes](../reference/ui-config.md#deleting-a-record): Deleting asks first, or offers Undo for a soft delete, offers a review when the record changed since it was opened, and names the records that still point at it.
|
|
@@ -351,7 +351,7 @@ export default defineUi({
|
|
|
351
351
|
})
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
-
`invoke(name, { method?, body?, path?, query?, headers? })` sends a `GET`, or a `POST` with a JSON `body
|
|
354
|
+
`invoke(name, { method?, body?, path?, query?, headers?, cache? })` sends a `GET`, or a `POST` with a JSON `body`; `cache` is the browser's fetch cache mode, such as `no-store` for an answer only its caller may see. It resolves to the parsed JSON, to text for a `text/*` answer or one without a content type, to a `Blob` of any other type, or to `undefined` for a `204`. A function sends a file, such as a PDF, as a plain `Response` with its type and name: `new Response(bytes, { headers: { 'content-type': 'application/pdf', 'content-disposition': 'attachment; filename="invoice.pdf"' } })`, and `invoke` gives the caller that `Blob`, with its `type`. A problem rejects with an `ApiError`, as any call of the client does. Outside the admin, `createClient` from `@protobase/client` gives the same `invoke`, or you can call the URL with `fetch` and an `Authorization: Bearer` header.
|
|
355
355
|
|
|
356
356
|
## Hono apps
|
|
357
357
|
|
|
@@ -332,6 +332,42 @@ A bar for `value` out of `max`, with both numbers. It turns amber from 90%.
|
|
|
332
332
|
<Progress label="Seats" value="seats_used" max="plan.seats" />
|
|
333
333
|
```
|
|
334
334
|
|
|
335
|
+
### Image
|
|
336
|
+
|
|
337
|
+
A picture an [API function](../guides/api-functions.md) draws, such as a system map: the block calls `GET /api/functions/<function>` with the reader's token, and draws the image it answers with, such as a PNG. The query says what to draw:
|
|
338
|
+
|
|
339
|
+
| Query | |
|
|
340
|
+
| --- | --- |
|
|
341
|
+
| `width` | The width the client draws it at, in CSS pixels: the block's `width`, else the width of its space, rounded up to a multiple of 100 so resizing the window asks again only now and then. |
|
|
342
|
+
| `height` | The block's `height`, when it has one. Without it the query names no height, and the picture's own proportions decide. |
|
|
343
|
+
| `theme` | `light` or `dark`, the theme the page is drawn in. |
|
|
344
|
+
|
|
345
|
+
| Prop | |
|
|
346
|
+
| --- | --- |
|
|
347
|
+
| `function` | The function's name, as in `functions/<function>.ts`. Required; the server stops at startup when the app has no such function. |
|
|
348
|
+
| `alt` | What the picture shows, for screen readers and for clients that draw no images. |
|
|
349
|
+
| `width`, `height` | The size it is drawn at, in CSS pixels. |
|
|
350
|
+
| `refresh` | Every how many seconds the client asks for the picture again, keeping the last one on screen while the next loads; once when omitted. Regaining window focus never asks again. |
|
|
351
|
+
|
|
352
|
+
```tsx
|
|
353
|
+
<Image function="system-map" alt="The servers and the links between them" height={320} refresh={60} />
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
```ts
|
|
357
|
+
// functions/system-map.ts
|
|
358
|
+
import { defineFunction } from '@protobase/server'
|
|
359
|
+
import { drawSystemMap } from './_shared/system-map'
|
|
360
|
+
|
|
361
|
+
export default defineFunction({ roles: ['admin', 'support'] }, async (request, { records }) => {
|
|
362
|
+
const query = new URL(request.url).searchParams
|
|
363
|
+
const { items } = await records.list('servers')
|
|
364
|
+
const png = await drawSystemMap(items, { width: Number(query.get('width')), height: Number(query.get('height')) || undefined, dark: query.get('theme') === 'dark' })
|
|
365
|
+
return new Response(png, { headers: { 'content-type': 'image/png' } })
|
|
366
|
+
})
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
The function reads records as the caller, so the picture shows only what they may see. A reader the function's `roles` or `capability` leave out gets the page without the block. So does a visitor without a token, unless the function is public, since only a public function takes a call without one. A client that draws no images, such as one that shows text only, shows `alt` in its place, or nothing without it; the admin app does the same when the function refuses, answers no image or one the browser cannot draw, also when a later request fails after an earlier one drew a picture. <gap>An Image cannot ask for a sharper picture on high-density screens because a scale in its query is not implemented.</gap>
|
|
370
|
+
|
|
335
371
|
### Chart
|
|
336
372
|
|
|
337
373
|
Counts, sums or averages of the records that match `filter`, per value of a field or per hour, day, week, month or year of a date field, in a card. It reads [`:aggregate`](api.md#routes), so only what the user may see is counted, and the grouped field needs an index ([scan guard](api.md#safety)).
|
|
@@ -358,7 +394,7 @@ Each value takes its colour from the view's `valueColors`, else an enum value's
|
|
|
358
394
|
|
|
359
395
|
## Conversation
|
|
360
396
|
|
|
361
|
-
A chat declared in the layout like any other block: a `Thread` lists the messages of a resource and a `Composer` beneath it sends one, so [`/meta`](api.md#meta-and-openapi-per-caller) describes the conversation and every client can draw it, with no component of the app's own.
|
|
397
|
+
A chat declared in the layout like any other block: a `Thread` lists the messages of a resource and a `Composer` beneath it sends one, so [`/meta`](api.md#meta-and-openapi-per-caller) describes the conversation and every client can draw it, with no component of the app's own. On a record page, [`l.thread` and `l.composer`](ui-config.md#conversations) hold the conversation of that record.
|
|
362
398
|
|
|
363
399
|
```tsx
|
|
364
400
|
<Card title="General">
|
|
@@ -378,8 +414,8 @@ The latest messages that match `filter`, oldest first, each under its sender's n
|
|
|
378
414
|
| `resource`, `filter` | Which messages. `resource` is required. |
|
|
379
415
|
| `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Required. |
|
|
380
416
|
| `time` | When each was sent: a date or timestamp field the API can sort by, which orders them. Required. |
|
|
381
|
-
| `text` | The message. Required. |
|
|
382
|
-
| `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds; default 50. |
|
|
417
|
+
| `text` | The message; shown rendered when the message resource's view marks it [`.markdown()`](ui-config.md#names-and-columns). Required. |
|
|
418
|
+
| `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds: 1 to 500, the API's largest page; default 50. |
|
|
383
419
|
| `title`, `description`, `actions` | The heading; no card is drawn around the thread, so it can sit in a `Card` with its composer. |
|
|
384
420
|
| `empty` | Text while there are no messages. |
|
|
385
421
|
| `span` | Width in a grid. |
|
|
@@ -17,7 +17,7 @@ const { record, etag } = await api.get(orders, id)
|
|
|
17
17
|
await api.update(orders, id, { status: 'shipped' }, etag) // 412 rejects with PreconditionFailedError
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/)), or a name for loose records. Filters are AIP-160 text or [`where`](https://docs.protobase.net/api/schema/variables/where/) results (printed with [`printFilter`](https://docs.protobase.net/api/schema/functions/printfilter/)), and a list whose query string passes 4,000 characters goes by `:search`. Errors are `ApiError` (`status`, `slug`, `errors`, `filterErrors` with spans, `blockedBy` for a delete other records point at), which `isApiError(error)` tells apart. Also: `search`, `create`, `remove`, `facets`, `series`, `histogram`, `map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? })` (the records in a map's view, or buckets of them, see [`:map`](api.md#maps)), `seek`, `reveal(resource, key, field)` (a [sensitive field](data-config.md#sensitive-fields)'s value), `generate(resource, key, action)` (runs an [AI action](ai.md#ai-actions) and resolves to the record as written), `meta(etag?, { signal? })`, `invoke(name, { body?, method?, path?, query? })` (one of the app's [API functions](../guides/api-functions.md#calling-a-function); its answer as parsed JSON, text, or a `Blob` for any other type), `history(resource, key, { pageSize?, pageToken? })` (a page of a record's [changes](history.md), newest first), `comments(resource, key, { pageSize?, pageToken? })`, `comment(resource, key, { body, mentions? })` and `mentionable(resource, key, query)` (a record's [comments](comments.md#the-endpoints), adding one, and the people it may mention), `form(name)`, `formChallenge(name)` and `submitForm(name, values, proof)` (a [public form](forms.md#routes)), `upload(resource, field, file, { onProgress?, signal? })` (a file for a [file field](files.md#uploading); its `value` goes in the next write, and `onProgress` uses XMLHttpRequest, since fetch reports no upload progress), `live({ onChanges, onResync, onRetry? })` (hears which records of the [live](live.md) resources change until the function it returns is called, connecting again by itself; every caller of one client shares one stream), `channel(resource, key)` (a record's [channel](channels.md#from-a-page), with its presence and broadcasts, every channel of the client on one socket), `bridges.open(name, target)` (a [TCP bridge](tcp-bridges.md#opening-a-bridge)'s socket, with when the server closes it).
|
|
20
|
+
Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/)), or a name for loose records. Filters are AIP-160 text or [`where`](https://docs.protobase.net/api/schema/variables/where/) results (printed with [`printFilter`](https://docs.protobase.net/api/schema/functions/printfilter/)), and a list whose query string passes 4,000 characters goes by `:search`. Errors are `ApiError` (`status`, `slug`, `errors`, `filterErrors` with spans, `blockedBy` for a delete other records point at), which `isApiError(error)` tells apart. Also: `search`, `create`, `remove`, `facets`, `series`, `histogram`, `map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? })` (the records in a map's view, or buckets of them, see [`:map`](api.md#maps)), `seek`, `reveal(resource, key, field)` (a [sensitive field](data-config.md#sensitive-fields)'s value), `generate(resource, key, action)` (runs an [AI action](ai.md#ai-actions) and resolves to the record as written), `meta(etag?, { signal? })`, `invoke(name, { body?, method?, path?, query?, cache? })` (one of the app's [API functions](../guides/api-functions.md#calling-a-function); its answer as parsed JSON, text, or a `Blob` for any other type), `history(resource, key, { pageSize?, pageToken? })` (a page of a record's [changes](history.md), newest first), `comments(resource, key, { pageSize?, pageToken? })`, `comment(resource, key, { body, mentions? })` and `mentionable(resource, key, query)` (a record's [comments](comments.md#the-endpoints), adding one, and the people it may mention), `form(name)`, `formChallenge(name)` and `submitForm(name, values, proof)` (a [public form](forms.md#routes)), `upload(resource, field, file, { onProgress?, signal? })` (a file for a [file field](files.md#uploading); its `value` goes in the next write, and `onProgress` uses XMLHttpRequest, since fetch reports no upload progress), `live({ onChanges, onResync, onRetry? })` (hears which records of the [live](live.md) resources change until the function it returns is called, connecting again by itself; every caller of one client shares one stream), `channel(resource, key)` (a record's [channel](channels.md#from-a-page), with its presence and broadcasts, every channel of the client on one socket), `bridges.open(name, target)` (a [TCP bridge](tcp-bridges.md#opening-a-bridge)'s socket, with when the server closes it).
|
|
21
21
|
|
|
22
22
|
With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/v1`, the `url` of each [file](files.md) in a record the client answers is absolute too, on that API's origin, where the API answers a path on its own origin. `routedClient(own, sourceOf)` is one client over several APIs: each call about a resource goes to the client `sourceOf(resource)` gives, else to `own`, as the admin app does for [remote resources](remote-resources.md), and `sourceMeta(meta, source)` keeps the part of another API's `/meta` an app draws.
|
|
23
23
|
|
|
@@ -82,9 +82,12 @@ A client that cannot draw a component, such as a native app without React or the
|
|
|
82
82
|
|
|
83
83
|
```tsx
|
|
84
84
|
export const SeatChart = component('SeatChart', { fallback: <Progress label="Seats" value="seats_used" max="plan.seats" /> })
|
|
85
|
+
export const SystemMap = component('SystemMap', { fallback: <Image function="system-map" /> })
|
|
85
86
|
export const Confetti = component('Confetti', { fallback: [] })
|
|
86
87
|
```
|
|
87
88
|
|
|
89
|
+
A visual component, such as a map, falls back to the [picture](blocks.md#image) an API function draws of it; with no `alt`, a client that shows text only draws nothing in its place.
|
|
90
|
+
|
|
88
91
|
The admin app draws the fallback too when the component is missing or throws while drawing; `protobase dev` also shows the warning above it. Without a fallback, the warning stands in the component's place, as above. A [record section](#record-sections) takes `fallback` in `l.custom`.
|
|
89
92
|
|
|
90
93
|
### Fields and resources in props
|
|
@@ -140,5 +140,6 @@ Every block reads the regular API with the user's token, so the access rules app
|
|
|
140
140
|
- `Field`, `Progress` and `Stat field` on a field they cannot read are left out, and table columns are narrowed;
|
|
141
141
|
- `ModalForm` needs create or update permission and keeps only the fields they may write;
|
|
142
142
|
- an `Action` missing from their view of the resource is left out, and so is a `Show` that names something they cannot see.
|
|
143
|
+
- an `Image` whose function they may not call is left out.
|
|
143
144
|
|
|
144
145
|
Custom components are kept: they get only their props, and fetch through the same API. A custom component's fallback loses what the user cannot use like the rest of the tree, and a fallback left with nothing is sent as `[]`, so a client still draws nothing in the component's place.
|
|
@@ -105,7 +105,7 @@ Field hints:
|
|
|
105
105
|
| `.confirm(question)` | Asks `question` before a person changes the value in a form or a list cell, and Cancel keeps it. See [Confirming a change](#confirming-a-change). |
|
|
106
106
|
| `.format(format)` | `badge` shows statuses as coloured badges, `code` sets identifiers in monospace, as the list's identifier column too, `percent` adds a % sign, and `signed` shows a whole number in a list with its sign, green above zero and red below, such as a stock change of `+12` or `−3`; it needs an integer field. On a text field, `email`, `phone` and `url` show the value as a link that writes to it (`mailto:`), calls it (`tel:`, its digits and a leading +) or opens it in a new tab (only an `http` or `https` address; anything else stays text), on the record page, in its sidebar and in the list's cells but the title's, which links to the record; forms edit it in an email, phone or web address input, which brings up the keyboard for it on a mobile screen and offers the browser's autofill. Another field type with one of them stops the server at startup. `relative` on a timestamp shows it as "5 minutes ago" or "in 2 hours" in lists and on the record page, with the exact time on hover; `absolute` and `compact` are accepted and carried in `/meta` for apps that render their own lists. <gap>The admin does not use the `absolute` and `compact` formats yet.</gap> |
|
|
107
107
|
| `.multiline()` | A text of several lines, such as a description: forms edit it in a box that grows with the text, so the page scrolls rather than the box, and the record page's sections, a page's field blocks and a card's subtitle keep its line breaks (a card shows the first three lines); the record's sidebar shows it on one line. On the record page and the create form it takes the whole width of its section. Only a text field takes it; the list's table shows the text on one line. |
|
|
108
|
-
| `.markdown()` | Markdown, such as a task's notes: forms edit its source in a box that grows with it, with a Write and Preview switch above it, and store it exactly as typed. The record page's sections
|
|
108
|
+
| `.markdown()` | Markdown, such as a task's notes: forms edit its source in a box that grows with it, with a Write and Preview switch above it, and store it exactly as typed. The record page's sections, a page's field blocks and a conversation's messages show it rendered as GitHub does, line breaks kept; raw HTML shows as text, links and images keep only http(s), mailto, tel and relative addresses, and links open in a new tab. A card's subtitle shows its first three lines rendered, its links as text; the list's table, the record's sidebar and a card's other lines show its text on one line without the marks. On the record page and the create form it takes the whole width of its section. Only a text field takes it, and the renderer loads with the first markdown shown. |
|
|
109
109
|
| `.prefix(text)`, `.suffix(text)`, `.decimals(n)` | Text around a number and its decimals: `€` and `2` show `€1,234.50`, `.suffix(' m²')` shows `120 m²`. They show wherever the number does: records, cards, table cells, forms and the range filter. A prefix is plain text, so a list does not show `€` as money; `.currency()` does. |
|
|
110
110
|
| `.currency(code)` | The currency a decimal is an amount of, as an ISO 4217 code such as `EUR`: the list shows it as money in that currency, in its table and its range filter. See [Value tones and currencies](#value-tones-and-currencies). |
|
|
111
111
|
| `.icon(name)` | An icon before the value on a card's meta row: one of the names [actions](layouts.md#named-actions) take, such as `bed`, `calendar` or `cpu`, and above the value in a section of [key facts](#key-facts). Nowhere else shows it. |
|
|
@@ -662,6 +662,8 @@ export const repairsView = filtered
|
|
|
662
662
|
| `l.custom(Component, { title?, props?, sidebar?, when?, fallback? })` | A [custom component](custom-components.md#record-sections) where it is listed: in the main column under `title`, or with `sidebar: true` as a sidebar card. `fallback` shows in its place where it cannot be drawn. |
|
|
663
663
|
| `l.map(title, { latitude, longitude, zoom?, sidebar?, when? })` | A map with a pin at the record's position, in the main column or with `sidebar: true` as a sidebar card. See [Maps](#maps). |
|
|
664
664
|
| `l.chart(title, { resource, field, at, series, range?, help?, when? })` | Line graphs of numbers of the records that point at this one, such as a machine's samples, over the last hour, day or week. See [Charts of related records](#charts-of-related-records). |
|
|
665
|
+
| `l.thread(title, { resource, field, sender, time, text, limit?, empty?, help?, when? })` | The record's conversation: the latest messages that point at it, oldest first, under each sender's name and time. See [Conversations](#conversations). |
|
|
666
|
+
| `l.composer({ resource, field, text, placeholder?, when? })` | A box that sends a message about the record, which the thread then shows. See [Conversations](#conversations). |
|
|
665
667
|
| `l.gallery(title, { image?, photos?, when? })` | The record's photos as tiles, opening a lightbox. See [Galleries](#galleries). |
|
|
666
668
|
| `l.history(title?, { limit?, when? })` | The record's changes, newest first, with who made each and the fields before and after; needs `.history()` on the resource, and a view without a layout shows it last by itself. See [Record history](history.md#on-the-record-page). |
|
|
667
669
|
| `l.comments(title?, { when? })` | The record's comments, oldest first, with a box to write one that @mentions people; needs `.comments()` on the resource, and a view without a layout shows it last by itself. See [Record comments](comments.md#on-the-record-page). |
|
|
@@ -1052,6 +1054,43 @@ view<typeof hosts>('hosts').layout((r) => [
|
|
|
1052
1054
|
|
|
1053
1055
|
Each series is read through [`:aggregate`](api.md), grouped by `at` with `field = <this record's key>` as its filter, so the user's access applies as on the list, and a user who cannot read `field`, `at` or any series gets no chart (one who cannot read some series gets the others). That filter and grouping need an index on `(field, at)`, such as `create index on host_samples (host_id, sampled_at)`, which [`protobase doctor`](cli.md#doctor) checks. A `field` that is no relation to this resource, an `at` that is no timestamp or not filterable, or a series that is no number or is sensitive stops the server at startup. Keeping the samples, and removing old ones, is the app's own work.
|
|
1054
1056
|
|
|
1057
|
+
### Conversations
|
|
1058
|
+
|
|
1059
|
+
`l.thread(title, options)` shows the messages that point at the record on the page, as a task's chat between the people working on it, and `l.composer(options)` below it writes one. They are the record page's form of the [Thread and Composer blocks](blocks.md#conversation) of composed pages, scoped to the record by a relation of the messages: the thread reads only the messages whose `field` holds this record's key, and each message the composer sends gets that key in `field`. [`/meta`](api.md#meta-and-openapi-per-caller) describes both as data, so every client can draw the conversation with no component of the app's own.
|
|
1060
|
+
|
|
1061
|
+
The thread shows the latest messages oldest first, each under its sender's name and the time it was sent, with a line between days, and **Load earlier messages** reads the ones before; it scrolls in a box of its own, opening at the newest and following what arrives, as the [Thread block](blocks.md#thread) does; others' new messages arrive without a reload when the message resource is [live](live.md) (`.live()`), and otherwise once the page is read again. A message whose text field the message resource's view marks [`.markdown()`](#names-and-columns) shows rendered, its raw HTML as text. The composer sends with Enter, starts a new line with Shift+Enter, and keeps a refused message in the box under the reason. A message carries its sender only when the message resource marks its author with [`.author()`](data-config.md#resource), which every create sets to the signed-in user, so the thread's `sender` names that field, such as `author_id`. It sends only `field` and `text`, so every other required field of the message, such as its time, needs a default, such as `sent_at timestamptz not null default now()`.
|
|
1062
|
+
|
|
1063
|
+
| `l.thread` option | |
|
|
1064
|
+
| --- | --- |
|
|
1065
|
+
| `resource` | The message resource, such as `task_messages`. Required. |
|
|
1066
|
+
| `field` | The filterable relation of `resource` that holds this record's key. Required. |
|
|
1067
|
+
| `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Required. |
|
|
1068
|
+
| `time` | When each was sent: a date or timestamp field the API can sort by, which orders them. Required. |
|
|
1069
|
+
| `text` | The message, a text field. Required. |
|
|
1070
|
+
| `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds: 1 to 500, the API's largest page; default 50. |
|
|
1071
|
+
| `empty` | Text while there are no messages. |
|
|
1072
|
+
| `help`, `when` | A line under the title, and whether it shows on the form, the read view or both. |
|
|
1073
|
+
|
|
1074
|
+
| `l.composer` option | |
|
|
1075
|
+
| --- | --- |
|
|
1076
|
+
| `resource` | The message resource. Required. |
|
|
1077
|
+
| `field` | The relation of `resource` each message gets this record's key in. Required. |
|
|
1078
|
+
| `text` | The text field the message goes in. Required. |
|
|
1079
|
+
| `placeholder` | The box's text while empty. |
|
|
1080
|
+
| `when` | Whether it shows on the form, the read view or both. |
|
|
1081
|
+
|
|
1082
|
+
```ts
|
|
1083
|
+
view<typeof task_messages>('task_messages').fields((r) => ({ body: r.body.markdown() }))
|
|
1084
|
+
|
|
1085
|
+
view<typeof tasks>('tasks').layout((r) => [
|
|
1086
|
+
l.section('Task', [r.title]),
|
|
1087
|
+
l.thread('Conversation', { resource: 'task_messages', field: 'task_id', sender: 'author_id', time: 'sent_at', text: 'body' }),
|
|
1088
|
+
l.composer({ resource: 'task_messages', field: 'task_id', text: 'body', placeholder: 'Message about this task' }),
|
|
1089
|
+
])
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
The messages are read with `field = <this record's key>` as the filter, newest first by `time`, so the user's access applies as on the list. That read needs an index on `(field, time)`, such as `create index on task_messages (task_id, sent_at)`, which [`protobase doctor`](cli.md#doctor) checks. A user who cannot read `field`, `sender`, `time` or `text` gets no thread, and one who may not create a message with `field` and `text` gets no composer. A `field` that is no relation to this resource, a `time` that is no date or timestamp the API can sort by, a `sender` that is no relation or text field, a thread `text` that is no text field, a sensitive field in the thread, or a composer `text` that is no writable text field stops the server at startup. As with a related section, the record page's count of the records that point at it leaves out the messages its thread shows.
|
|
1093
|
+
|
|
1055
1094
|
## Actions and views per role
|
|
1056
1095
|
|
|
1057
1096
|
```ts title="docs-examples/bike-shop/step-5.ts"
|