@telepath-computer/television 1.4.26 → 1.4.27
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/THIRD-PARTY-NOTICES.txt +208 -0
- package/dist/cli.cjs +3971 -702
- package/dist/onboarding/README.md +9 -3
- package/dist/onboarding/onboarding-channels.json +52 -0
- package/dist/onboarding/productivity/company-todos/index.html +6 -97
- package/dist/onboarding/productivity/company-todos/onboarding-company-todos.js +220 -0
- package/dist/onboarding/productivity/company-todos/task.css +20 -43
- package/dist/onboarding/productivity/company-todos/task.js +1 -1
- package/dist/onboarding/productivity/todays-calendar/onboarding-relative-dates.js +3 -12
- package/dist/sdk/v1/THIRD-PARTY-NOTICES.txt +211 -0
- package/dist/sdk/v1/resources.js +1413 -0
- package/dist/skills/television/SKILL.md +14 -11
- package/dist/skills/television/resources.md +286 -0
- package/dist/skills/tv-tasks/SKILL.md +30 -7
- package/dist/skills/tv-tasks/task.css +18 -19
- package/dist/web/assets/main-BFYjHkxN.js +848 -0
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/onboarding/productivity/company-todos/onboarding-relative-dates.js +0 -40
- package/dist/web/assets/main-C1ANF-FD.js +0 -826
|
@@ -12,6 +12,8 @@ Load this skill when you need to create, update, inspect, focus, delete, or othe
|
|
|
12
12
|
|
|
13
13
|
Read the [theming guidance](./theming.md) when creating, revising, or bringing an installed theme up to date.
|
|
14
14
|
|
|
15
|
+
An artifact can keep data in a *JSON store*, a small database that Television keeps on its server, inspired by Firebase's Realtime Database. It keeps the data durably, shares it live with every client viewing the artifact, and lets you read and write it through the `tv` CLI. localStorage is also available to an artifact's page, but it is highly discouraged, because a future version of Television may remove it. A Markdown artifact can also act as shared, synchronized, editable state, but only within Television: through a share link it is read-only, unlike a JSON store, and it lacks the presentational flexibility and interactivity of HTML. An artifact's state can also live in a third-party API or another external service it integrates with. Which fits depends on the artifact's design, its use and the person, so you decide; for a to-do list, the standard choice is a JSON store. Read the [resource guidance](./resources.md) when an artifact needs to keep state, or when the person mentions JSON stores or resources.
|
|
16
|
+
|
|
15
17
|
Re-read this skill only if it is not already in your context or you know it changed.
|
|
16
18
|
|
|
17
19
|
## When to use Television
|
|
@@ -470,29 +472,30 @@ Rules:
|
|
|
470
472
|
- Browser clients render Television artifact proxy URLs (`http://<host>:<port>/artifact/<id>/...`) inline and live-reload them when the producer's ETag changes.
|
|
471
473
|
- Television does not fetch or watch ordinary remote pages from the consumer server.
|
|
472
474
|
|
|
473
|
-
### Sharing Television artifacts
|
|
475
|
+
### Sharing Television artifacts
|
|
474
476
|
|
|
475
|
-
To share a path artifact from one Television server
|
|
477
|
+
To share a path artifact from one Television server with someone else, create its share link on the producer:
|
|
476
478
|
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
+
```bash
|
|
480
|
+
tv share-artifact --id <artifact-id>
|
|
479
481
|
```
|
|
480
482
|
|
|
481
|
-
|
|
483
|
+
It prints the link once for each address the server can be reached at, in the form `http://<host>:<port>/artifact/<share-id>/`. A server listening on every interface (`0.0.0.0`) gives each of the machine's addresses, never `0.0.0.0` itself. Never share the artifact's own address, `/artifact/<artifact-id>/`: anyone who can load it can read and write the artifact's store. The share link reaches the artifact without revealing its ID, at `read` unless you give `--access read-write`. Run the command again with `--access` and the other level to change the link's level, and revoke the link with `tv unshare-artifact --id <artifact-id>`.
|
|
484
|
+
|
|
485
|
+
**CRITICAL — the share link carries NO token.** Do not append the server's main `tv` bearer token (or any `?token=`/`Authorization` value) to a share link, and never include it when telling the recipient how to reach the artifact. The `/artifact/<id>/*` proxy is bearerless: the unguessable share ID in the path *is* the capability. Leaking the main token would hand over full read/write control of the entire producer server. A correct share link is exactly the form above and nothing else.
|
|
482
486
|
|
|
483
|
-
|
|
487
|
+
Choose the line whose host the recipient can actually reach:
|
|
484
488
|
|
|
485
489
|
- Prefer a Tailscale CGNAT address (`100.64.0.0/10`) when one is present.
|
|
486
490
|
- Otherwise use a non-loopback bind address.
|
|
487
491
|
- Never emit a loopback host (`127.0.0.1` or `localhost`) for sharing; that points at the recipient's own machine.
|
|
488
|
-
- If
|
|
489
|
-
- If you cannot determine an externally reachable IP, tell the user and explain that the server is only reporting loopback or wildcard bind information instead of inventing a localhost share URL.
|
|
492
|
+
- If no line has a host the recipient can reach, tell the user so instead of inventing a share link.
|
|
490
493
|
|
|
491
|
-
|
|
494
|
+
The recipient adds the link with `tv create-url-artifact`; Television recognizes the `/artifact/<id>/...` shape, renders it inline, and reloads it from the producer when the producer content changes.
|
|
492
495
|
|
|
493
|
-
Markdown artifacts shared this way render as read-only HTML. Anyone with the
|
|
496
|
+
Markdown artifacts shared this way render as read-only HTML. Anyone with the share link can read the artifact's content with no token at all, because the share ID alone authorizes the read.
|
|
494
497
|
|
|
495
|
-
|
|
498
|
+
A URL artifact has no share link. To "share" one, pass along the underlying URL and let the recipient create their own URL artifact.
|
|
496
499
|
|
|
497
500
|
If the browser placeholder for an ordinary non-Television URL is not sufficient, create a markdown or HTML path artifact that links to the page and summarizes what the user needs from it.
|
|
498
501
|
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# JSON stores: data every viewer and the agent share
|
|
2
|
+
|
|
3
|
+
A *JSON store* is a small database that Television keeps on its server, inspired by Firebase's Realtime Database. It keeps an artifact's data durably, shares it live with every client viewing the artifact, and lets you read and write it through the `tv` CLI while the person uses the page.
|
|
4
|
+
|
|
5
|
+
An artifact's state can live elsewhere too. localStorage is also available to an artifact's page, but it is highly discouraged, because a future version of Television may remove it. A Markdown artifact can also act as shared, synchronized, editable state, which the person edits in Television and you edit on disk, but it is editable only within Television: shared through a share link, it is read-only, unlike a JSON store. It also lacks the presentational flexibility and interactivity of an HTML page. State can also live in a third-party API or another external service the artifact integrates with. Which fits depends on the artifact's design, its use and the person, so you decide; for a to-do list, the standard choice is a JSON store.
|
|
6
|
+
|
|
7
|
+
A JSON store is Television's first type of *resource*: data the server keeps for artifacts. Every HTML artifact has its own JSON store, which its page uses from the resource SDK and you use from the shell with `tv resource json`.
|
|
8
|
+
|
|
9
|
+
## Every artifact has its own store
|
|
10
|
+
|
|
11
|
+
Every HTML artifact has its own JSON store, with nothing to create or bind. Its page gets the store from the resource SDK that the server serves:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { getStore, ref, onValue } from "/sdk/v1/resources.js";
|
|
15
|
+
|
|
16
|
+
// The store holds: { tasks: { <key>: { title: string, required; done: boolean, required } } }.
|
|
17
|
+
// The page checks tasks off; an agent adds tasks.
|
|
18
|
+
const db = getStore();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Document the store's data in a comment next to that call, as above and as the example below does: each field's type and whether it is required, what the page writes and what agents write. The comment travels with the artifact's files and changes with the code that defines the data, so read it before you write to an artifact's store.
|
|
22
|
+
|
|
23
|
+
The SDK finds the artifact from the page's own address, so the page needs no setup and no ID, and the call makes no request. Until something writes to the store it has no value: a snapshot of its root has `exists()` false, and the first write creates it. Only artifacts this server serves from its own files have a store; on the page of an artifact that has none, the store's first operation fails with the code `no-store`. SDK errors are `Error` objects with a string `code`, such as `read-only`, `no-store`, `disconnected`, `invalid-path` or `invalid-value`, and a message for people.
|
|
24
|
+
|
|
25
|
+
## Use the store from the page
|
|
26
|
+
|
|
27
|
+
The store's functions are inspired by Firebase's Realtime Database, so they will look familiar if you know that API. What they do is described here, and the store keeps your data in its own ways, which [the differences below](#where-the-store-differs-from-firebase) list:
|
|
28
|
+
|
|
29
|
+
- `ref(db, path)` and `child(ref, path)` make references to paths such as `items/abc/done`.
|
|
30
|
+
- `get(ref)` reads once. `onValue(ref, callback)` delivers the current value first, then again after every change. `onChildAdded`, `onChildChanged` and `onChildRemoved` report an object's children in key order, so pushed children arrive in the order they were created. Each listener function takes an optional error callback, which hears when the page loses access, and returns a function that stops listening.
|
|
31
|
+
- `set(ref, value)` replaces a value. `update(ref, values)` applies several paths at once, all or nothing. `push(ref, value)` adds a child under a new key and returns its reference at once. That reference is also a promise that settles when the write is confirmed or refused, so `await` it, which gives the new child's reference, or chain `.catch(...)` onto it. `remove(ref)` deletes. `runTransaction(ref, fn)` writes what `fn` returns only if the value has not changed since `fn` saw it, and otherwise calls `fn` again with the current value, up to a limit after which it fails with `max-retries`.
|
|
32
|
+
- `serverTimestamp()` and `increment(n)` can stand anywhere in a value you pass to `set`, `push` or `update`, even nested inside objects; the server fills them in. A transaction's function must return plain JSON, so they cannot appear in its result.
|
|
33
|
+
- A snapshot has `val()`, `exists()`, `key`, `child(path)`, `forEach(fn)`, `size` and `metadata.hasPendingWrites`.
|
|
34
|
+
|
|
35
|
+
Use `push` for lists that several clients edit, so additions never collide.
|
|
36
|
+
|
|
37
|
+
## A complete example
|
|
38
|
+
|
|
39
|
+
A chores list that the people at 14 Maple Street and their agent share, on its artifact's own store. It renders the list live, adds chores with `push`, saves checkboxes with `set`, clears done chores in a transaction, shows a saving state, says when it is disconnected and disables its controls until the connection returns, and turns read-only when it is opened through a `read` share link. The `tv-tasks` skill exists for building to-do lists for a person; this example leaves it out to keep its focus on using the JSON store.
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<!doctype html>
|
|
43
|
+
<html lang="en">
|
|
44
|
+
<head>
|
|
45
|
+
<meta charset="utf-8">
|
|
46
|
+
<title>Maple Street chores</title>
|
|
47
|
+
<link rel="stylesheet" href="/canonical/v2/styles.css">
|
|
48
|
+
<script type="module" src="/canonical/v2/components.js"></script>
|
|
49
|
+
<style>
|
|
50
|
+
body { padding: 32px 32px 64px; }
|
|
51
|
+
ul { list-style: none; padding: 0; }
|
|
52
|
+
.done span { text-decoration: line-through; }
|
|
53
|
+
/* The canonical styles give buttons a display, which would show them while hidden. */
|
|
54
|
+
[hidden] { display: none !important; }
|
|
55
|
+
</style>
|
|
56
|
+
</head>
|
|
57
|
+
<body>
|
|
58
|
+
<header>
|
|
59
|
+
<h1>Maple Street chores</h1>
|
|
60
|
+
<p id="status">Loading…</p>
|
|
61
|
+
</header>
|
|
62
|
+
<form id="add">
|
|
63
|
+
<input name="task" aria-label="New task" placeholder="New task" required>
|
|
64
|
+
<button type="submit">Add</button>
|
|
65
|
+
</form>
|
|
66
|
+
<ul id="items"></ul>
|
|
67
|
+
<button id="clear" type="button">Clear done</button>
|
|
68
|
+
<p id="error" role="alert"></p>
|
|
69
|
+
<script type="module">
|
|
70
|
+
import {
|
|
71
|
+
getStore, onAccessChanged, onConnectionStatusChanged,
|
|
72
|
+
ref, onValue, push, set, runTransaction, serverTimestamp,
|
|
73
|
+
} from "/sdk/v1/resources.js";
|
|
74
|
+
|
|
75
|
+
// The store holds the list: { items: { <key>: chore } }, each chore under the key that push made.
|
|
76
|
+
// A chore has these fields:
|
|
77
|
+
// - title: string, required. The chore, as one short line.
|
|
78
|
+
// - done: boolean, required. true once the chore is done, false until then.
|
|
79
|
+
// - createdAt: number, optional. When the page added the chore, in milliseconds since 1970; the server fills it in.
|
|
80
|
+
// The page adds chores with push, checks them off, and clears done ones in a transaction.
|
|
81
|
+
// An agent adds chores with push, and marks one done by setting items/<key>/done to true.
|
|
82
|
+
const db = getStore();
|
|
83
|
+
const items = ref(db, "items");
|
|
84
|
+
const form = document.querySelector("#add");
|
|
85
|
+
const list = document.querySelector("#items");
|
|
86
|
+
const clear = document.querySelector("#clear");
|
|
87
|
+
const status = document.querySelector("#status");
|
|
88
|
+
const error = document.querySelector("#error");
|
|
89
|
+
let readOnly = false;
|
|
90
|
+
let noAccess = false;
|
|
91
|
+
let disconnected = false;
|
|
92
|
+
let saved = "Loading…";
|
|
93
|
+
|
|
94
|
+
function report(failure) {
|
|
95
|
+
// A write cut off by a lost connection may still have been saved.
|
|
96
|
+
error.textContent = failure.code === "disconnected"
|
|
97
|
+
? "A change may not have been saved: the connection was lost before the server confirmed it."
|
|
98
|
+
: `${failure.code}: ${failure.message}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function showStatus() {
|
|
102
|
+
status.textContent = noAccess
|
|
103
|
+
? "This page no longer has access to the list."
|
|
104
|
+
: disconnected ? "Disconnected: changes are not saved until the connection returns." : saved;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// The controls that write: hidden while the page can only read, which
|
|
108
|
+
// refuses writes, and disabled while disconnected, when writes fail at once.
|
|
109
|
+
function applyControls() {
|
|
110
|
+
form.hidden = readOnly;
|
|
111
|
+
clear.hidden = readOnly;
|
|
112
|
+
for (const control of [...form.elements, clear, ...list.querySelectorAll("input")]) {
|
|
113
|
+
control.disabled = readOnly || disconnected;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// "read" through a read-only share link, and null once the page has no
|
|
118
|
+
// access at all, as after the link it was opened through is revoked.
|
|
119
|
+
onAccessChanged((access) => {
|
|
120
|
+
readOnly = access !== "read-write";
|
|
121
|
+
noAccess = access === null;
|
|
122
|
+
showStatus();
|
|
123
|
+
applyControls();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
onConnectionStatusChanged((current) => {
|
|
127
|
+
disconnected = current === "disconnected";
|
|
128
|
+
showStatus();
|
|
129
|
+
applyControls();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// The current value first, then every change, this page's own writes at once.
|
|
133
|
+
onValue(items, (snap) => {
|
|
134
|
+
saved = snap.metadata.hasPendingWrites ? "Saving…" : "Saved";
|
|
135
|
+
showStatus();
|
|
136
|
+
list.replaceChildren();
|
|
137
|
+
snap.forEach((item) => {
|
|
138
|
+
const { title = "", done = false } = item.val() ?? {};
|
|
139
|
+
const row = document.createElement("li");
|
|
140
|
+
const label = document.createElement("label");
|
|
141
|
+
const box = document.createElement("input");
|
|
142
|
+
const text = document.createElement("span");
|
|
143
|
+
box.type = "checkbox";
|
|
144
|
+
box.checked = done === true;
|
|
145
|
+
box.disabled = readOnly || disconnected;
|
|
146
|
+
box.addEventListener("change", () => {
|
|
147
|
+
set(ref(db, `items/${item.key}/done`), box.checked).catch(report);
|
|
148
|
+
});
|
|
149
|
+
text.textContent = title;
|
|
150
|
+
row.className = done === true ? "done" : "";
|
|
151
|
+
label.append(box, " ", text);
|
|
152
|
+
row.append(label);
|
|
153
|
+
list.append(row);
|
|
154
|
+
});
|
|
155
|
+
}, report);
|
|
156
|
+
|
|
157
|
+
form.addEventListener("submit", (event) => {
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
const title = form.elements.task.value.trim();
|
|
160
|
+
if (title === "") return;
|
|
161
|
+
// The new chore shows at once; the server fills in createdAt.
|
|
162
|
+
push(items, { title, done: false, createdAt: serverTimestamp() }).catch(report);
|
|
163
|
+
form.reset();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
clear.addEventListener("click", () => {
|
|
167
|
+
// Rewrites the list only if nobody changed it meanwhile; returning undefined aborts.
|
|
168
|
+
runTransaction(items, (current) => {
|
|
169
|
+
if (current === undefined || current === null) return undefined;
|
|
170
|
+
return Object.fromEntries(Object.entries(current).filter(([, chore]) => chore.done !== true));
|
|
171
|
+
}).catch(report);
|
|
172
|
+
});
|
|
173
|
+
</script>
|
|
174
|
+
</body>
|
|
175
|
+
</html>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Add `?authoredForAppVersion=<version>` to the stylesheet link as the HTML artifact style section describes.
|
|
179
|
+
|
|
180
|
+
## Work on the list as the agent
|
|
181
|
+
|
|
182
|
+
You work on the same list from the shell, addressing the artifact's store by the artifact's ID and following the comment beside `getStore()`, and the page shows each change at once:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
tv resource json push --artifact <artifact-id> items '{"title":"Take out the recycling","done":false}'
|
|
186
|
+
tv resource json set --artifact <artifact-id> items/<key>/done true
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`<artifact-id>` is the ID that `tv create-path-artifact` printed; `tv list-artifacts` lists them. `push` prints the new chore's key as `{"key":"<key>"}`, and the second command marks that chore done. Values from the shell are plain JSON, so a chore you add has no `createdAt`; the page sets it only for the chores it adds.
|
|
190
|
+
|
|
191
|
+
## Read and change the store from the shell
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
tv resource json get --artifact <artifact-id> [<path>]
|
|
195
|
+
tv resource json set --artifact <artifact-id> [<path>] <value>
|
|
196
|
+
tv resource json update --artifact <artifact-id> [<path>] <values>
|
|
197
|
+
tv resource json push --artifact <artifact-id> <path> <value>
|
|
198
|
+
tv resource json remove --artifact <artifact-id> <path>
|
|
199
|
+
tv resource json watch --artifact <artifact-id> [<path>]
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
`get` prints `{"exists":true,"value":…}`, or `{"exists":false}` when the path has no value, as for the store of an artifact nothing has written yet. `set`, `update` and `remove` print `JSON store of artifact <artifact-id> updated.` A value is JSON text given as one argument, or read from the file `--file <path>` names, where `-` reads standard input; values given on the command line are plain JSON. `update` takes an object whose keys are paths relative to `<path>`. `watch` prints the current value, then the latest value whenever it changes, until interrupted. When changes come faster than it reads them, it skips the values in between, so once they stop its last line is what the store holds; use it to follow the current state, not to record every step.
|
|
203
|
+
|
|
204
|
+
## Do not edit a store's files directly
|
|
205
|
+
|
|
206
|
+
The server keeps each store's data in a `content.json` file under its home. Do not edit a store's files directly; change the store with `tv resource json`. A command changes only the paths it names, is validated, takes its place in order with the page's writes, and reaches every client viewing the artifact. An edit of the files replaces the whole value, can silently drop a write that a page makes meanwhile, and is overwritten by the server's next write to the store. Reading a store's `content.json` directly is fine. Editing its files is a recovery step, taken only while the server is stopped.
|
|
207
|
+
|
|
208
|
+
## A page sees its own writes at once
|
|
209
|
+
|
|
210
|
+
The SDK shows a page's write to the page's listeners at once, then sends it to the server. Listeners see the server's value with the page's unconfirmed writes applied in order. When the server refuses a write, for example because the share link the page was opened through became `read`, the write is rolled back and its promise rejects, so catch the rejection and tell the person.
|
|
211
|
+
|
|
212
|
+
A snapshot's `metadata.hasPendingWrites` is true while it includes unconfirmed writes. When the last one is confirmed, `onValue` listeners receive a snapshot with `hasPendingWrites` false even when the value did not change, so read it in an `onValue` listener to show a saving state:
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
onValue(ref(db, "items"), (snap) => {
|
|
216
|
+
status.textContent = snap.metadata.hasPendingWrites ? "Saving…" : "Saved";
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Child-event callbacks are not called for a confirmation that changes no child, so watch the saving state with `onValue`. Values from `serverTimestamp()` and `increment()` are estimated at once and replaced by the server's values when it confirms.
|
|
221
|
+
|
|
222
|
+
## When the connection is lost
|
|
223
|
+
|
|
224
|
+
There is no offline mode. While the page is disconnected from its server, `get`, `set`, `update`, `remove`, `runTransaction`, `push` with a value and `getAccess` fail at once with the code `disconnected`, and a write that fails this way is never shown. When the connection is lost, the SDK rolls back the page's unconfirmed writes and rejects their promises with `disconnected`. Such a write may still have been applied, because the server may have received it before the loss, so tell the person it may not have been saved, as the example does, rather than that it was lost. Listeners stay registered, including ones added while disconnected, and the SDK reconnects on its own; each listener then hears the current value, which includes any write the server applied.
|
|
225
|
+
|
|
226
|
+
Show the person when their changes cannot be saved, and disable the controls that write until the connection returns, as the example does:
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
onConnectionStatusChanged((current) => {
|
|
230
|
+
disconnected = current === "disconnected";
|
|
231
|
+
showStatus();
|
|
232
|
+
applyControls();
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The status is `connecting` while a connection opens, when reads and writes wait for it rather than fail; `connected` once it is open; `disconnected` from a loss until the SDK reconnects; and `idle` while the page uses nothing that needs a connection. `getConnectionStatus()` reads it without opening a connection. A status callback hears the status soon after you register it, then each change, and keeps the connection open.
|
|
237
|
+
|
|
238
|
+
## Where the store differs from Firebase
|
|
239
|
+
|
|
240
|
+
The store keeps plain JSON exactly as written:
|
|
241
|
+
|
|
242
|
+
- `set(ref, null)` stores `null`; it does not delete. Delete with `remove(ref)`, or with `deleteValue()` as an entry in `update`.
|
|
243
|
+
- A path with no value is different from `null`: its snapshot's `exists()` is false and its `val()` is `undefined`.
|
|
244
|
+
- Arrays stay arrays. You can read into one and `set` an existing element, but you insert, delete or reorder elements by writing the whole array, directly or in a transaction.
|
|
245
|
+
- `{}` and `[]` are stored as written. Object keys must be non-empty and contain no `/`.
|
|
246
|
+
|
|
247
|
+
## What does not exist
|
|
248
|
+
|
|
249
|
+
Some Firebase APIs that agents reach for have no counterpart here:
|
|
250
|
+
|
|
251
|
+
- Queries do not exist: there is no `orderByChild`, `orderByKey`, `orderByValue`, `limitToFirst`, `limitToLast`, `startAt`, `endAt` or `equalTo`. Read the location and sort or filter in the page.
|
|
252
|
+
- `onDisconnect` does not exist.
|
|
253
|
+
- Offline persistence does not exist, and there is no offline queue.
|
|
254
|
+
- There is no `initializeApp` or `getDatabase`: `getStore()` is the whole setup.
|
|
255
|
+
|
|
256
|
+
## Check the access level
|
|
257
|
+
|
|
258
|
+
A page opened through a `read` share link can read its artifact's store but not write it: the server refuses its writes with the code `read-only`, and once the page knows its level the SDK refuses them before showing them. Check the level and render a read-only view, without the controls that edit, as the example does:
|
|
259
|
+
|
|
260
|
+
```js
|
|
261
|
+
onAccessChanged((access) => {
|
|
262
|
+
form.hidden = access !== "read-write";
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Keep the example's `[hidden]` rule when you hide controls this way: the canonical styles give buttons a `display`, which overrides the `hidden` attribute, so without the rule a hidden button still shows.
|
|
267
|
+
|
|
268
|
+
`onAccessChanged` calls back with the level once the page's connection has opened, then with each change, since a share link's level can change while the page is open. The level is `"read-write"` at the artifact's own address and the link's level through a share link. It is `null` when the page's address reaches no artifact that has a store, as after the share link it was opened through is revoked, and the page then has no access at all. `getAccess()` resolves with the level once, and rejects with the code `no-store` instead of resolving with `null`.
|
|
269
|
+
|
|
270
|
+
## Share an artifact
|
|
271
|
+
|
|
272
|
+
When the person asks to share an artifact with someone, give them its share link, never the artifact's own address: anyone who can load the artifact's own address can read and write its store.
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
tv share-artifact --id <artifact-id>
|
|
276
|
+
tv share-artifact --id <artifact-id> --access read-write
|
|
277
|
+
tv unshare-artifact --id <artifact-id>
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
`tv share-artifact` creates the artifact's share link and prints it once for each address the server can be reached at, each of the machine's addresses when it listens on every interface, in the form `http://<host>:<port>/artifact/<share-id>/`; give the person the one whose host the people they share with can reach. A page opened through the link reaches the artifact's store at the link's level. Without `--access` the link is `read`, so share at `read-write` only when the person wants the people they share with to change the data. A Markdown artifact is shared only at `read`: its shared page is a static rendered page that no one can edit through the link, so `--access read-write` is refused for it. Running the command again with the other level changes the link's level without changing the link, and pages already open through it hear the change. Leaving out `--access` never changes a link's level: when the link is already `read-write`, the command refuses, and you give `--access read-write` to keep it or `--access read` to make it read-only. `tv unshare-artifact` revokes the link: it stops working for everyone who holds it, the pages open through it lose their access, and sharing again later gives a different link. Only artifacts this server serves from its own files can be shared, and only while the server requires its auth token.
|
|
281
|
+
|
|
282
|
+
The link never reveals the artifact's ID, as long as the artifact does not reveal it either. Keep the artifact's own links relative, such as `href="notes.html"` or `href="sub/"`, so that its ID never appears in what a share viewer receives; an absolute link to `/artifact/<artifact-id>/…` would hand it to them.
|
|
283
|
+
|
|
284
|
+
## Keep IDs and secrets out of source and data
|
|
285
|
+
|
|
286
|
+
Never put an artifact ID, share ID, token or other secret in artifact source or in the data its store holds: a share viewer's page receives the store's data as it receives the source. The SDK finds the artifact from the page's own address, so the page needs no ID, and you address the store from the shell with `--artifact`.
|
|
@@ -34,9 +34,12 @@ For a single-file artifact, inline `task.css`/`task.js` into `<style>` and
|
|
|
34
34
|
`<script type="module">` tags instead. `components.js` gives you `<tv-icon>`;
|
|
35
35
|
`task.js` registers `<tv-task-checkbox>` and `<tv-task-meta-due>`.
|
|
36
36
|
|
|
37
|
-
A task list is not a prose document
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
A task list is not a prose document, and `task.css` lays out its page: one
|
|
38
|
+
inset around the whole page, shared by the page header, the list and anything
|
|
39
|
+
you place between them, such as an add form or a toolbar, and one gap between
|
|
40
|
+
each of them. Don't add `body` padding (the house style doc suggests it for
|
|
41
|
+
prose), and don't give those blocks side padding or margins of their own to
|
|
42
|
+
line them up: they already line up.
|
|
40
43
|
|
|
41
44
|
Television manages light and dark appearance. Live canonical v2 supplies the
|
|
42
45
|
selected theme and shared defaults; the task kit inherits its surface, text,
|
|
@@ -89,8 +92,8 @@ a bare list is fine. Add one when the list benefits from its own masthead: a
|
|
|
89
92
|
date line ("Today" lists usually carry the date), a person, or context the
|
|
90
93
|
frame title doesn't say. When you do, use the house header idiom *above*
|
|
91
94
|
`<tv-task-list>` (not inside it): a `<header>` with an `<h1>` and optionally
|
|
92
|
-
a `<p>` subtitle. House styles own its look; the skill
|
|
93
|
-
the list. Title each section with an `<h2>` inside the section's own
|
|
95
|
+
a `<p>` subtitle. House styles own its look; the skill's page layout aligns it
|
|
96
|
+
with the list and spaces it from what follows. Title each section with an `<h2>` inside the section's own
|
|
94
97
|
`<header>`. Keep these as real HTML headings, not `tv-task-*`, so the
|
|
95
98
|
document outline stays navigable.
|
|
96
99
|
|
|
@@ -182,8 +185,9 @@ it, or an interactive list empties itself and the space must not collapse.
|
|
|
182
185
|
the attribute (completes/uncompletes the row) but emits nothing.
|
|
183
186
|
- Listen once on the list and delegate. Give each `<tv-task>` a plain `id` and
|
|
184
187
|
identify the toggled task with `e.target.closest("tv-task").id`.
|
|
185
|
-
- Nothing is persisted — wire the handler to
|
|
186
|
-
|
|
188
|
+
- Nothing is persisted for you — wire the handler to where the list's data
|
|
189
|
+
lives ([below](#where-the-tasks-come-from)). On load, restore state by
|
|
190
|
+
setting `el.checked`.
|
|
187
191
|
|
|
188
192
|
```js
|
|
189
193
|
const list = document.querySelector("tv-task-list");
|
|
@@ -193,6 +197,25 @@ list.addEventListener("toggle", (e) => {
|
|
|
193
197
|
});
|
|
194
198
|
```
|
|
195
199
|
|
|
200
|
+
## Where the tasks come from
|
|
201
|
+
|
|
202
|
+
This skill renders tasks once you have them; where they come from, and where
|
|
203
|
+
their state lives, is up to the artifact's author and depends on the artifact's
|
|
204
|
+
design, its use and the person. Data can come from a JSON store, from a
|
|
205
|
+
third-party API such as the person's productivity app when it has an HTTP API,
|
|
206
|
+
or from the HTML itself, written into the artifact. A JSON store keeps a list's
|
|
207
|
+
data durably, shares it live with every client viewing the artifact and lets
|
|
208
|
+
you read and write it; it is the standard choice for a to-do list's data, and
|
|
209
|
+
the `television` skill's `resources.md` describes it. localStorage is also
|
|
210
|
+
available, but it is highly discouraged, because a future version of
|
|
211
|
+
Television may remove it.
|
|
212
|
+
|
|
213
|
+
When the tasks arrive or change while the page is open, as when you render
|
|
214
|
+
them from a JSON store, put the list's status or error message in the page
|
|
215
|
+
header, after its title and any subtitle, as a `<p class="tv-error">`. A list
|
|
216
|
+
that shows such a message has a page header to hold it, even when the artifact
|
|
217
|
+
frame's title would otherwise do.
|
|
218
|
+
|
|
196
219
|
## Example variations
|
|
197
220
|
|
|
198
221
|
Completed and disabled rows:
|
|
@@ -104,31 +104,30 @@ tv-task:has(tv-task-checkbox[disabled]) tv-task-title {
|
|
|
104
104
|
color: var(--color-text-muted);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/* ---- The page ----
|
|
108
|
+
One default inset for the whole page, at zero specificity so an
|
|
109
|
+
artifact's own body rule replaces it. The page header, the list and
|
|
110
|
+
anything placed between them, such as an add form or a toolbar, share its
|
|
111
|
+
gutters, and each stands one gap below the one before it; a script or
|
|
112
|
+
style element is no block, so the first block shown gets no gap above it.
|
|
113
|
+
The artifact's own heading is the house page-header idiom (header > h1 +
|
|
114
|
+
p), which house typography styles. Its last line shown has no margin
|
|
115
|
+
outside a prose region and one no larger than the gap inside one, which
|
|
116
|
+
collapses into the gap, so the gap below the header is the same whatever
|
|
117
|
+
it ends with. */
|
|
118
|
+
:where(body) {
|
|
119
|
+
padding: var(--space-16, 16px);
|
|
120
|
+
}
|
|
121
|
+
:where(body > :not(script, style, template) ~ *) {
|
|
122
|
+
margin-top: var(--space-12, 12px);
|
|
123
|
+
}
|
|
124
|
+
|
|
107
125
|
/* ---- List container ----
|
|
108
126
|
No frame of its own: the artifact page is the surface, and Television's
|
|
109
127
|
artifact frame supplies the chrome around the document. */
|
|
110
128
|
|
|
111
129
|
tv-task-list {
|
|
112
130
|
display: block;
|
|
113
|
-
padding: 0 var(--space-16, 16px) var(--space-16, 16px);
|
|
114
|
-
}
|
|
115
|
-
/* Nothing above the list (no page heading): give it its own top breathing
|
|
116
|
-
room. When a header precedes it, the gap is the subtitle's house margin —
|
|
117
|
-
or the h1 rule below when there is no subtitle. */
|
|
118
|
-
tv-task-list:first-child {
|
|
119
|
-
padding-top: var(--space-16, 16px);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/* The artifact's own heading lives on the page, above the list, as the house
|
|
123
|
-
page-header idiom (header > h1 + p) — house typography styles it; the
|
|
124
|
-
skill only aligns it with the list's interior padding. */
|
|
125
|
-
header:has(+ tv-task-list) {
|
|
126
|
-
padding: var(--space-16, 16px) var(--space-16, 16px) 0;
|
|
127
|
-
}
|
|
128
|
-
/* A header whose last child is the h1 (no subtitle) has no house margin
|
|
129
|
-
below it — supply the gap the subtitle's margin would have given. */
|
|
130
|
-
header:has(+ tv-task-list) > h1:last-child {
|
|
131
|
-
margin-bottom: var(--space-12, 12px);
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/* Section headers lay their title out inline. */
|