@telepath-computer/television 1.5.10 → 1.6.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/dist/THIRD-PARTY-NOTICES.txt +701 -0
- package/dist/cli.cjs +9035 -596
- package/dist/onboarding/tv-guide/welcome.html +14 -4
- package/dist/skills/television/SKILL.md +39 -33
- package/dist/skills/television/resources.md +4 -4
- package/dist/skills/television/templates.md +77 -0
- package/dist/skills/television/theming.md +31 -17
- package/dist/templates/calendar/README.md +17 -0
- package/dist/{skills/tv-tasks → templates/calendar}/THIRD-PARTY-NOTICES.txt +22 -22
- package/dist/templates/calendar/calendar-attendees.js +131 -0
- package/dist/templates/calendar/calendar-event.js +22 -0
- package/dist/templates/calendar/calendar-motion.js +273 -0
- package/dist/templates/calendar/calendar-page.js +403 -0
- package/dist/templates/calendar/calendar-time-axis.js +32 -0
- package/dist/templates/calendar/calendar-week.js +711 -0
- package/dist/templates/calendar/data.json +3 -0
- package/dist/templates/calendar/icon.svg +1 -0
- package/dist/templates/calendar/index.html +27 -0
- package/dist/templates/calendar/manifest.json +148 -0
- package/dist/templates/calendar/styles.css +771 -0
- package/dist/templates/checklist/README.md +45 -0
- package/dist/templates/checklist/THIRD-PARTY-NOTICES.txt +29 -0
- package/dist/templates/checklist/data.json +1 -0
- package/dist/templates/checklist/icon.svg +8 -0
- package/dist/templates/checklist/icons.css +61 -0
- package/dist/templates/checklist/index.html +47 -0
- package/dist/templates/checklist/manifest.json +49 -0
- package/dist/templates/checklist/model.d.ts +30 -0
- package/dist/templates/checklist/model.js +60 -0
- package/dist/templates/checklist/page.js +425 -0
- package/dist/templates/checklist/styles.css +206 -0
- package/dist/templates/document/README.md +55 -0
- package/dist/templates/document/THIRD-PARTY-NOTICES.txt +1080 -0
- package/dist/templates/document/data.json +3 -0
- package/dist/templates/document/editor.css +1 -0
- package/dist/templates/document/editor.js +37 -0
- package/dist/templates/document/icon.svg +6 -0
- package/dist/templates/document/index.html +29 -0
- package/dist/templates/document/manifest.json +22 -0
- package/dist/templates/document/page.js +190 -0
- package/dist/templates/document/styles.css +76 -0
- package/dist/templates/map/README.md +85 -0
- package/dist/templates/map/THIRD-PARTY-NOTICES.txt +84 -0
- package/dist/templates/map/data.json +1 -0
- package/dist/templates/map/icon.svg +8 -0
- package/dist/templates/map/icons.svg +43 -0
- package/dist/templates/map/index.html +95 -0
- package/dist/templates/map/manifest.json +227 -0
- package/dist/templates/map/map-model.js +18 -0
- package/dist/templates/map/map.css +202 -0
- package/dist/templates/map/map.js +728 -0
- package/dist/templates/map/vendor/LICENSE +26 -0
- package/dist/templates/map/vendor/README.md +11 -0
- package/dist/templates/map/vendor/leaflet.css +661 -0
- package/dist/templates/map/vendor/leaflet.js +6 -0
- package/dist/templates/map/vendor/lucide/LICENSE +43 -0
- package/dist/templates/map/vendor/lucide/README.md +46 -0
- package/dist/templates/map/vendor/lucide/icons.js +832 -0
- package/dist/templates/map/vendor/lucide/svg/airport.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/bar.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/beach.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/bridge.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/bus.svg +21 -0
- package/dist/templates/map/vendor/lucide/svg/church.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/coffee.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/ferry.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/flag.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/heart.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/home.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/hospital.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/hotel.svg +24 -0
- package/dist/templates/map/vendor/lucide/svg/info.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/landmark.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/mountain.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/museum.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/music.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/park.svg +18 -0
- package/dist/templates/map/vendor/lucide/svg/parking.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/pin.svg +16 -0
- package/dist/templates/map/vendor/lucide/svg/restaurant.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/school.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/shop.svg +17 -0
- package/dist/templates/map/vendor/lucide/svg/sports.svg +19 -0
- package/dist/templates/map/vendor/lucide/svg/star.svg +15 -0
- package/dist/templates/map/vendor/lucide/svg/theatre.svg +23 -0
- package/dist/templates/map/vendor/lucide/svg/train.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/viewpoint.svg +20 -0
- package/dist/templates/map/vendor/lucide/svg/work.svg +18 -0
- package/dist/templates/sticky-note/Caveat-Medium.woff2 +0 -0
- package/dist/templates/sticky-note/README.md +47 -0
- package/dist/templates/sticky-note/THIRD-PARTY-NOTICES.txt +127 -0
- package/dist/templates/sticky-note/data.json +1 -0
- package/dist/templates/sticky-note/icon.svg +16 -0
- package/dist/templates/sticky-note/icons.css +61 -0
- package/dist/templates/sticky-note/index.html +31 -0
- package/dist/templates/sticky-note/manifest.json +27 -0
- package/dist/templates/sticky-note/model.d.ts +33 -0
- package/dist/templates/sticky-note/model.js +152 -0
- package/dist/templates/sticky-note/page.js +84 -0
- package/dist/templates/sticky-note/styles.css +140 -0
- package/dist/templates/table/README.md +107 -0
- package/dist/templates/table/data.json +4 -0
- package/dist/templates/table/icon.svg +6 -0
- package/dist/templates/table/index.html +15 -0
- package/dist/templates/table/manifest.json +70 -0
- package/dist/templates/table/model.d.ts +164 -0
- package/dist/templates/table/model.js +395 -0
- package/dist/templates/table/page.js +1045 -0
- package/dist/templates/table/selection-model.d.ts +67 -0
- package/dist/templates/table/selection-model.js +163 -0
- package/dist/templates/table/styles.css +522 -0
- package/dist/views/markdown/THIRD-PARTY-NOTICES.txt +408 -0
- package/dist/views/markdown/index.html +21 -21
- package/dist/web/assets/main-CRSNodQt.js +864 -0
- package/dist/web/assets/main-DnvQkpg4.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/skills/tv-calendar/SKILL.md +0 -100
- package/dist/skills/tv-calendar/calendar.css +0 -1
- package/dist/skills/tv-calendar/calendar.js +0 -400
- package/dist/skills/tv-table/SKILL.md +0 -95
- package/dist/skills/tv-tasks/SKILL.md +0 -269
- package/dist/skills/tv-tasks/task.css +0 -180
- package/dist/skills/tv-tasks/task.js +0 -304
- package/dist/web/assets/calendar-DToAnkzj.png +0 -0
- package/dist/web/assets/main-CekDfJPz.js +0 -848
- package/dist/web/assets/main-CunC2_Nx.css +0 -1
- package/dist/web/assets/markdown-DdDrJuVK.png +0 -0
- package/dist/web/assets/table-oeG9uAN1.png +0 -0
- package/dist/web/assets/tasks-D4xqXFPl.png +0 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getStore, ref, onValue, set, push, remove, runTransaction,
|
|
3
|
+
getAccess, onAccessChanged, getConnectionStatus, onConnectionStatusChanged,
|
|
4
|
+
} from "/sdk/v1/resources.js";
|
|
5
|
+
import { isChecklistData, orderedItems, insertionOrder, createRenumberUpdate, isCompletionShortcut } from "./model.js";
|
|
6
|
+
|
|
7
|
+
// While an input method composes text, keys belong to the field. WebKit reports
|
|
8
|
+
// the key that ends composition with this code after `isComposing` is false.
|
|
9
|
+
const COMPOSITION_KEY_CODE = 229;
|
|
10
|
+
const composing = event => event.isComposing || event.keyCode === COMPOSITION_KEY_CODE;
|
|
11
|
+
|
|
12
|
+
const main = document.querySelector(".checklist-page");
|
|
13
|
+
const store = getStore();
|
|
14
|
+
const root = ref(store);
|
|
15
|
+
const itemsRef = ref(store, "items");
|
|
16
|
+
const iconStyles = new CSSStyleSheet();
|
|
17
|
+
iconStyles.replaceSync(await (await fetch("./icons.css")).text());
|
|
18
|
+
const rows = new Map();
|
|
19
|
+
let value;
|
|
20
|
+
let received = false;
|
|
21
|
+
let unavailable = false;
|
|
22
|
+
let access = null;
|
|
23
|
+
let connection = getConnectionStatus();
|
|
24
|
+
let unsubscribe = null;
|
|
25
|
+
let draft = null;
|
|
26
|
+
let retainedDraft = false;
|
|
27
|
+
let pendingFocus = null;
|
|
28
|
+
let title;
|
|
29
|
+
let list;
|
|
30
|
+
let addField;
|
|
31
|
+
let firstView = true;
|
|
32
|
+
let failureTimer;
|
|
33
|
+
let failure = false;
|
|
34
|
+
let status;
|
|
35
|
+
let statusMessage = "";
|
|
36
|
+
let statusReady = false;
|
|
37
|
+
|
|
38
|
+
function canWrite() {
|
|
39
|
+
return !unavailable && isChecklistData(value) && access === "read-write" && connection === "connected";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function singleLine(text) {
|
|
43
|
+
return text.replace(/\r\n|[\r\n]/g, " ");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function clone(name) {
|
|
47
|
+
const fragment = document.importNode(document.querySelector(`#checklist-${name}`).content, true);
|
|
48
|
+
for (const icon of fragment.querySelectorAll("tv-icon")) {
|
|
49
|
+
const template = icon.querySelector("template");
|
|
50
|
+
const shadow = icon.shadowRoot ?? icon.attachShadow({ mode: "open", clonable: true });
|
|
51
|
+
if (template) {
|
|
52
|
+
shadow.append(template.content);
|
|
53
|
+
template.remove();
|
|
54
|
+
}
|
|
55
|
+
shadow.adoptedStyleSheets = [iconStyles];
|
|
56
|
+
}
|
|
57
|
+
return fragment;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function editable(element, enabled, name) {
|
|
61
|
+
for (const [attribute, content] of Object.entries({ contenteditable: "plaintext-only", role: "textbox", "aria-label": name })) {
|
|
62
|
+
if (enabled) element.setAttribute(attribute, content);
|
|
63
|
+
else element.removeAttribute(attribute);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function currentItem(key) {
|
|
68
|
+
return isChecklistData(value) && Object.hasOwn(value.items, key) ? value.items[key] : draft?.key === key ? draft : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function focusText(element) {
|
|
72
|
+
if (!element || !canWrite()) return;
|
|
73
|
+
element.focus();
|
|
74
|
+
if (element instanceof HTMLInputElement) element.setSelectionRange(element.value.length, element.value.length);
|
|
75
|
+
else {
|
|
76
|
+
const range = document.createRange();
|
|
77
|
+
range.selectNodeContents(element);
|
|
78
|
+
range.collapse(false);
|
|
79
|
+
const selection = getSelection();
|
|
80
|
+
selection.removeAllRanges();
|
|
81
|
+
selection.addRange(range);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The SDK owns optimistic values and rollback. Only the active text draft is
|
|
86
|
+
// separate: ordinary remote updates cannot replace it, but a refused save must.
|
|
87
|
+
async function save(operation, key) {
|
|
88
|
+
try {
|
|
89
|
+
await operation;
|
|
90
|
+
return true;
|
|
91
|
+
} catch {
|
|
92
|
+
if (draft && draft.key === key) {
|
|
93
|
+
const item = isChecklistData(value) && Object.hasOwn(value.items, key) ? value.items[key] : null;
|
|
94
|
+
draft = item ? { key, order: item.order, done: item.done, text: singleLine(item.text) } : null;
|
|
95
|
+
const field = rows.get(key)?.text;
|
|
96
|
+
if (field && item) field.textContent = singleLine(item.text);
|
|
97
|
+
}
|
|
98
|
+
failure = true;
|
|
99
|
+
clearTimeout(failureTimer);
|
|
100
|
+
failureTimer = setTimeout(() => { failure = false; renderStatus(); }, 4000);
|
|
101
|
+
render();
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function saveItem(key, text, done) {
|
|
107
|
+
if (!canWrite()) return;
|
|
108
|
+
const item = currentItem(key);
|
|
109
|
+
if (!item) return;
|
|
110
|
+
const saved = { order: item.order, text, done };
|
|
111
|
+
if (draft?.key === key) Object.assign(draft, saved);
|
|
112
|
+
return save(set(ref(store, `items/${key}`), saved), key);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function focusInserted() {
|
|
116
|
+
const field = rows.get(pendingFocus)?.text;
|
|
117
|
+
if (!field) return;
|
|
118
|
+
pendingFocus = null;
|
|
119
|
+
focusText(field);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function insert(text, afterKey, focus = false) {
|
|
123
|
+
if (!canWrite()) return null;
|
|
124
|
+
const order = insertionOrder(value.items, afterKey);
|
|
125
|
+
if (order !== null) {
|
|
126
|
+
const added = push(itemsRef, { order, text, done: false });
|
|
127
|
+
if (focus) { pendingFocus = added.key; focusInserted(); }
|
|
128
|
+
return await save(added, added.key) ? added.key : null;
|
|
129
|
+
}
|
|
130
|
+
const key = push(itemsRef).key;
|
|
131
|
+
if (focus) pendingFocus = key;
|
|
132
|
+
const update = createRenumberUpdate(key, { text, done: false }, afterKey);
|
|
133
|
+
let result;
|
|
134
|
+
const success = await save(runTransaction(itemsRef, current => canWrite() ? update(current) : undefined).then(outcome => { result = outcome; }), key);
|
|
135
|
+
return success && result.committed ? key : null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function insertAndFocus(afterKey) {
|
|
139
|
+
insert("", afterKey, true);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function removeItem(key, backwards = false) {
|
|
143
|
+
if (!canWrite()) return;
|
|
144
|
+
const keys = [...list.children].map(element => [...rows].find(([, row]) => row.element === element)?.[0]);
|
|
145
|
+
const index = keys.indexOf(key);
|
|
146
|
+
const target = backwards ? keys[index - 1] : keys[index + 1] ?? keys[index - 1];
|
|
147
|
+
if (draft?.key === key) draft = null;
|
|
148
|
+
save(remove(ref(store, `items/${key}`)), key);
|
|
149
|
+
focusText(rows.get(target)?.text ?? addField);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function createRow(key) {
|
|
153
|
+
const fragment = clone("row");
|
|
154
|
+
const element = fragment.firstElementChild;
|
|
155
|
+
const text = element.querySelector(".checklist-text");
|
|
156
|
+
const checkbox = element.querySelector(".checklist-check");
|
|
157
|
+
const row = { element, text, checkbox };
|
|
158
|
+
text.addEventListener("focus", () => {
|
|
159
|
+
if (!canWrite()) return;
|
|
160
|
+
const item = currentItem(key);
|
|
161
|
+
if (item) draft = { key, order: item.order, done: item.done, text: text.textContent };
|
|
162
|
+
retainedDraft = false;
|
|
163
|
+
element.setAttribute("data-editing", "");
|
|
164
|
+
});
|
|
165
|
+
text.addEventListener("blur", () => {
|
|
166
|
+
element.removeAttribute("data-editing");
|
|
167
|
+
if (draft?.key !== key) return;
|
|
168
|
+
if (!canWrite()) { retainedDraft = true; return; }
|
|
169
|
+
const leaving = draft;
|
|
170
|
+
draft = null;
|
|
171
|
+
if (canWrite()) {
|
|
172
|
+
if (leaving.text.trim() === "") save(remove(ref(store, `items/${key}`)), key);
|
|
173
|
+
else if (!Object.hasOwn(value.items, key)) save(set(ref(store, `items/${key}`), { order: leaving.order, text: leaving.text, done: leaving.done }), key);
|
|
174
|
+
}
|
|
175
|
+
render();
|
|
176
|
+
});
|
|
177
|
+
text.addEventListener("input", () => {
|
|
178
|
+
if (canWrite()) saveItem(key, text.textContent, currentItem(key).done);
|
|
179
|
+
});
|
|
180
|
+
text.addEventListener("keydown", event => itemKey(event, key));
|
|
181
|
+
text.addEventListener("paste", event => paste(event, key));
|
|
182
|
+
checkbox.addEventListener("change", () => {
|
|
183
|
+
if (canWrite()) saveItem(key, draft?.key === key ? draft.text : currentItem(key).text, checkbox.checked);
|
|
184
|
+
});
|
|
185
|
+
return row;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function createContent() {
|
|
189
|
+
main.prepend(clone("content"));
|
|
190
|
+
title = main.querySelector(".checklist-title-text");
|
|
191
|
+
list = main.querySelector(".checklist-items");
|
|
192
|
+
title.addEventListener("input", () => {
|
|
193
|
+
if (!canWrite()) return;
|
|
194
|
+
if (title.textContent === "") title.replaceChildren();
|
|
195
|
+
save(set(ref(store, "title"), title.textContent));
|
|
196
|
+
});
|
|
197
|
+
title.addEventListener("keydown", event => {
|
|
198
|
+
if (event.key !== "Enter" || composing(event) || !canWrite()) return;
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
insertAndFocus(null);
|
|
201
|
+
});
|
|
202
|
+
title.addEventListener("paste", event => {
|
|
203
|
+
if (!canWrite()) return;
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
document.execCommand("insertText", false, singleLine(event.clipboardData.getData("text/plain")));
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function render() {
|
|
210
|
+
const valid = received && !unavailable && isChecklistData(value);
|
|
211
|
+
if (!valid) {
|
|
212
|
+
draft = null;
|
|
213
|
+
retainedDraft = false;
|
|
214
|
+
pendingFocus = null;
|
|
215
|
+
rows.clear();
|
|
216
|
+
title = list = addField = null;
|
|
217
|
+
main.removeAttribute("data-read-only");
|
|
218
|
+
for (const child of [...main.children]) if (child !== status) child.remove();
|
|
219
|
+
if (received || unavailable) main.prepend(clone("unreadable"));
|
|
220
|
+
renderStatus();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!title) {
|
|
224
|
+
main.querySelector(".checklist-unreadable")?.remove();
|
|
225
|
+
createContent();
|
|
226
|
+
}
|
|
227
|
+
const enabled = canWrite();
|
|
228
|
+
main.toggleAttribute("data-read-only", !enabled);
|
|
229
|
+
editable(title, enabled, "Title");
|
|
230
|
+
const shownTitle = singleLine(value.title);
|
|
231
|
+
if (title.textContent !== shownTitle) title.textContent = shownTitle;
|
|
232
|
+
const items = { ...value.items };
|
|
233
|
+
if (draft && !Object.hasOwn(items, draft.key)) Object.defineProperty(items, draft.key, { value: draft, enumerable: true });
|
|
234
|
+
const entries = orderedItems(items);
|
|
235
|
+
for (const [key, row] of rows) {
|
|
236
|
+
if (!Object.hasOwn(items, key)) { row.element.remove(); rows.delete(key); }
|
|
237
|
+
}
|
|
238
|
+
let cursor = list.firstElementChild;
|
|
239
|
+
entries.forEach(([key, item], index) => {
|
|
240
|
+
let row = rows.get(key);
|
|
241
|
+
if (!row) { row = createRow(key); rows.set(key, row); }
|
|
242
|
+
// Leave nodes already in their place alone, preserving native editing and undo.
|
|
243
|
+
if (row.element !== cursor) {
|
|
244
|
+
if (row.element.isConnected) list.moveBefore(row.element, cursor);
|
|
245
|
+
else list.insertBefore(row.element, cursor);
|
|
246
|
+
}
|
|
247
|
+
cursor = row.element.nextElementSibling;
|
|
248
|
+
row.element.toggleAttribute("data-done", item.done);
|
|
249
|
+
row.element.toggleAttribute("data-editing", enabled && draft?.key === key);
|
|
250
|
+
row.checkbox.checked = item.done;
|
|
251
|
+
row.checkbox.disabled = !enabled;
|
|
252
|
+
const shown = draft?.key === key ? draft.text : singleLine(item.text);
|
|
253
|
+
if (draft?.key === key) { draft.order = item.order; draft.done = item.done; }
|
|
254
|
+
if (row.text.textContent !== shown) row.text.textContent = shown;
|
|
255
|
+
const name = shown.trim() === "" ? "Empty item" : shown;
|
|
256
|
+
row.checkbox.setAttribute("aria-label", name);
|
|
257
|
+
editable(row.text, enabled, `Item ${index + 1}`);
|
|
258
|
+
let button = row.element.querySelector(".checklist-remove");
|
|
259
|
+
if (enabled && !button) {
|
|
260
|
+
row.element.append(clone("remove"));
|
|
261
|
+
button = row.element.querySelector(".checklist-remove");
|
|
262
|
+
button.addEventListener("pointerdown", event => event.preventDefault());
|
|
263
|
+
button.addEventListener("click", () => removeItem(key));
|
|
264
|
+
}
|
|
265
|
+
if (enabled) button.setAttribute("aria-label", `Remove ${name}`);
|
|
266
|
+
else button?.remove();
|
|
267
|
+
});
|
|
268
|
+
main.querySelector(".checklist-empty")?.remove();
|
|
269
|
+
if (enabled && !addField) {
|
|
270
|
+
list.after(clone("add"));
|
|
271
|
+
addField = main.querySelector(".checklist-add-input");
|
|
272
|
+
addField.addEventListener("keydown", event => {
|
|
273
|
+
if (event.key !== "Enter" || composing(event) || !canWrite() || addField.value.trim() === "") return;
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
const text = addField.value;
|
|
276
|
+
addField.value = "";
|
|
277
|
+
insert(text);
|
|
278
|
+
});
|
|
279
|
+
addField.addEventListener("paste", event => paste(event));
|
|
280
|
+
} else if (!enabled) {
|
|
281
|
+
main.querySelector(".checklist-add")?.remove();
|
|
282
|
+
addField = null;
|
|
283
|
+
if (entries.length === 0) {
|
|
284
|
+
const empty = document.createElement("p");
|
|
285
|
+
empty.className = "checklist-empty";
|
|
286
|
+
empty.textContent = "No items";
|
|
287
|
+
list.after(empty);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (firstView && enabled) {
|
|
291
|
+
firstView = false;
|
|
292
|
+
if (entries.length === 0) addField.focus();
|
|
293
|
+
}
|
|
294
|
+
focusInserted();
|
|
295
|
+
renderStatus();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function renderStatus() {
|
|
299
|
+
statusMessage = connection === "disconnected" ? "Reconnecting…" : failure ? "Couldn't save that change." : "";
|
|
300
|
+
if (!statusMessage) { status?.remove(); status = null; statusReady = false; return; }
|
|
301
|
+
if (status) {
|
|
302
|
+
if (statusReady) status.textContent = statusMessage;
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
status = document.createElement("p");
|
|
306
|
+
status.className = "checklist-status";
|
|
307
|
+
status.setAttribute("role", "status");
|
|
308
|
+
main.append(status);
|
|
309
|
+
const mounted = status;
|
|
310
|
+
// Mount the empty live region before a later render task supplies its message.
|
|
311
|
+
requestAnimationFrame(() => {
|
|
312
|
+
if (status !== mounted) return;
|
|
313
|
+
statusReady = true;
|
|
314
|
+
status.textContent = statusMessage;
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function onBoundaryLine(field, direction) {
|
|
319
|
+
const selection = getSelection();
|
|
320
|
+
if (!selection?.isCollapsed || !selection.rangeCount) return false;
|
|
321
|
+
if (!field.textContent) return true;
|
|
322
|
+
const carets = [...selection.getRangeAt(0).getClientRects()];
|
|
323
|
+
const range = document.createRange();
|
|
324
|
+
range.selectNodeContents(field);
|
|
325
|
+
const rects = [...range.getClientRects()];
|
|
326
|
+
const edge = direction === "ArrowUp" ? rects[0] : rects.at(-1);
|
|
327
|
+
if (!edge) return false;
|
|
328
|
+
// A range collapsed at the element boundary has no caret rectangle.
|
|
329
|
+
if (!carets.length && selection.anchorNode === field) {
|
|
330
|
+
if (selection.anchorOffset === 0) carets.push(rects[0]);
|
|
331
|
+
else if (selection.anchorOffset === field.childNodes.length) carets.push(rects.at(-1));
|
|
332
|
+
}
|
|
333
|
+
if (!carets.length) return false;
|
|
334
|
+
const onEdge = caret => Math.abs(caret.top - edge.top) < edge.height / 2;
|
|
335
|
+
if (carets.every(onEdge)) return true;
|
|
336
|
+
if (!carets.some(onEdge)) return false;
|
|
337
|
+
// At a soft wrap, one DOM offset has two rectangles. Native line movement
|
|
338
|
+
// distinguishes which visual line owns the caret without discarding affinity.
|
|
339
|
+
const node = selection.anchorNode;
|
|
340
|
+
const offset = selection.anchorOffset;
|
|
341
|
+
selection.modify("move", direction === "ArrowUp" ? "backward" : "forward", "lineboundary");
|
|
342
|
+
return selection.anchorNode !== node || selection.anchorOffset !== offset;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function itemKey(event, key) {
|
|
346
|
+
if (!canWrite() || composing(event)) return;
|
|
347
|
+
const row = rows.get(key);
|
|
348
|
+
if (isCompletionShortcut(event, navigator.platform)) {
|
|
349
|
+
event.preventDefault();
|
|
350
|
+
saveItem(key, row.text.textContent, !currentItem(key).done);
|
|
351
|
+
} else if (event.key === "Enter") {
|
|
352
|
+
event.preventDefault();
|
|
353
|
+
insertAndFocus(key);
|
|
354
|
+
} else if (event.key === "Backspace" && row.text.textContent.trim() === "") {
|
|
355
|
+
event.preventDefault();
|
|
356
|
+
if (row.element.previousElementSibling) removeItem(key, true);
|
|
357
|
+
} else if (["ArrowUp", "ArrowDown"].includes(event.key) && onBoundaryLine(row.text, event.key)) {
|
|
358
|
+
event.preventDefault();
|
|
359
|
+
const previous = event.key === "ArrowUp";
|
|
360
|
+
const neighbour = previous ? row.element.previousElementSibling : row.element.nextElementSibling;
|
|
361
|
+
focusText(neighbour?.querySelector(".checklist-text") ?? (previous ? title : addField));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async function paste(event, key) {
|
|
366
|
+
if (!canWrite()) return;
|
|
367
|
+
const text = event.clipboardData.getData("text/plain");
|
|
368
|
+
if (!/[\r\n]/.test(text)) return;
|
|
369
|
+
event.preventDefault();
|
|
370
|
+
const lines = text.split(/\r\n|[\r\n]/).filter(line => line.trim() !== "");
|
|
371
|
+
if (lines.length === 0) return;
|
|
372
|
+
if (key !== undefined) document.execCommand("insertText", false, lines.shift());
|
|
373
|
+
else addField.value = "";
|
|
374
|
+
let last = key;
|
|
375
|
+
for (const line of lines) {
|
|
376
|
+
if (!canWrite()) return;
|
|
377
|
+
last = await insert(line, last);
|
|
378
|
+
if (last === null) return;
|
|
379
|
+
}
|
|
380
|
+
if (key !== undefined) focusText(rows.get(last)?.text);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function subscribe() {
|
|
384
|
+
if (unsubscribe) return;
|
|
385
|
+
unsubscribe = onValue(root, snapshot => {
|
|
386
|
+
if (retainedDraft && connection === "connected" && access !== null) {
|
|
387
|
+
draft = null;
|
|
388
|
+
retainedDraft = false;
|
|
389
|
+
}
|
|
390
|
+
value = snapshot.val();
|
|
391
|
+
received = true;
|
|
392
|
+
unavailable = false;
|
|
393
|
+
render();
|
|
394
|
+
}, error => {
|
|
395
|
+
unsubscribe = null;
|
|
396
|
+
if (error.code === "unavailable") unavailable = true;
|
|
397
|
+
render();
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function updateAccess(level) {
|
|
402
|
+
access = level;
|
|
403
|
+
if (!canWrite() && draft) retainedDraft = true;
|
|
404
|
+
else if (canWrite() && retainedDraft) {
|
|
405
|
+
draft = null;
|
|
406
|
+
retainedDraft = false;
|
|
407
|
+
}
|
|
408
|
+
if (level !== null && connection === "connected") subscribe();
|
|
409
|
+
render();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
onAccessChanged(updateAccess);
|
|
413
|
+
getAccess().then(updateAccess, () => {});
|
|
414
|
+
onConnectionStatusChanged(next => {
|
|
415
|
+
connection = next;
|
|
416
|
+
if (next !== "connected") {
|
|
417
|
+
access = null;
|
|
418
|
+
if (draft) retainedDraft = true;
|
|
419
|
+
} else {
|
|
420
|
+
subscribe();
|
|
421
|
+
getAccess().then(updateAccess, () => {});
|
|
422
|
+
}
|
|
423
|
+
render();
|
|
424
|
+
});
|
|
425
|
+
subscribe();
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/* The Checklist template's page: a title, rows of items and an add field on
|
|
2
|
+
the plain surface. Built only from the foundation's tokens, so it follows
|
|
3
|
+
the active theme and appearance. */
|
|
4
|
+
|
|
5
|
+
body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
background: var(--color-surface);
|
|
8
|
+
color: var(--color-text);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* The page's content, in one centred column on the plain surface. */
|
|
12
|
+
.checklist-page {
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
max-width: 656px;
|
|
17
|
+
min-height: 100vh;
|
|
18
|
+
margin: 0 auto;
|
|
19
|
+
padding: var(--space-48) var(--space-48) var(--space-32);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* A strip along the bottom of the page, ruled off at its top. The page
|
|
23
|
+
leaves room for it, so it never covers the last row. */
|
|
24
|
+
.checklist-status {
|
|
25
|
+
position: fixed;
|
|
26
|
+
inset: auto 0 0;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: var(--space-8) var(--space-16);
|
|
29
|
+
border-top: 1px solid var(--color-border);
|
|
30
|
+
background: var(--color-surface);
|
|
31
|
+
color: var(--color-text-muted);
|
|
32
|
+
font-size: var(--text-sm);
|
|
33
|
+
text-align: center;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.checklist-page:has(.checklist-status) {
|
|
37
|
+
padding-bottom: var(--space-64);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* In a narrow artifact the margins shrink. */
|
|
41
|
+
@media (width < 480px) {
|
|
42
|
+
.checklist-page {
|
|
43
|
+
padding: var(--space-32) var(--space-24) var(--space-24);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.checklist-title {
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding-bottom: var(--space-16);
|
|
50
|
+
font-size: var(--text-4xl);
|
|
51
|
+
font-weight: var(--font-weight-semibold);
|
|
52
|
+
line-height: 1.25;
|
|
53
|
+
letter-spacing: -0.01em;
|
|
54
|
+
outline: none;
|
|
55
|
+
overflow-wrap: anywhere;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.checklist-title-text {
|
|
59
|
+
display: block;
|
|
60
|
+
outline: none;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.checklist-title-text:empty::before {
|
|
64
|
+
content: attr(data-placeholder);
|
|
65
|
+
color: var(--color-text-muted);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.checklist-items {
|
|
69
|
+
margin: 0;
|
|
70
|
+
padding: 0;
|
|
71
|
+
list-style: none;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.checklist-item,
|
|
75
|
+
.checklist-add {
|
|
76
|
+
display: grid;
|
|
77
|
+
grid-template-columns: 1.125em minmax(0, 1fr) auto;
|
|
78
|
+
align-items: baseline;
|
|
79
|
+
gap: var(--space-12);
|
|
80
|
+
min-height: 36px;
|
|
81
|
+
padding: var(--space-6) 0;
|
|
82
|
+
box-sizing: border-box;
|
|
83
|
+
font-size: var(--text-lg);
|
|
84
|
+
line-height: 1.4;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* The box, drawn like the foundation's checklist marker and seated on the
|
|
88
|
+
item's first line. */
|
|
89
|
+
.checklist-check {
|
|
90
|
+
appearance: none;
|
|
91
|
+
position: relative;
|
|
92
|
+
width: 1.125em;
|
|
93
|
+
height: 1.125em;
|
|
94
|
+
margin: 0;
|
|
95
|
+
translate: 0 0.16em;
|
|
96
|
+
border: var(--control-border);
|
|
97
|
+
border-radius: var(--control-radius);
|
|
98
|
+
background: transparent;
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.checklist-check:checked {
|
|
103
|
+
background: var(--checkbox-color);
|
|
104
|
+
border-color: var(--checkbox-color);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.checklist-check:checked::after {
|
|
108
|
+
content: "";
|
|
109
|
+
position: absolute;
|
|
110
|
+
inset: 0;
|
|
111
|
+
background: var(--color-surface);
|
|
112
|
+
mask: var(--icon-check) center / 80% no-repeat;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.checklist-check:disabled {
|
|
116
|
+
cursor: default;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.checklist-check:focus-visible {
|
|
120
|
+
outline: var(--outline-focus);
|
|
121
|
+
outline-offset: 2px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.checklist-text {
|
|
125
|
+
outline: none;
|
|
126
|
+
overflow-wrap: anywhere;
|
|
127
|
+
cursor: text;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.checklist-item[data-done] .checklist-text {
|
|
131
|
+
color: var(--color-text-muted);
|
|
132
|
+
text-decoration: line-through;
|
|
133
|
+
text-decoration-thickness: 0.08em;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.checklist-remove {
|
|
137
|
+
align-self: center;
|
|
138
|
+
color: var(--color-text-muted);
|
|
139
|
+
opacity: 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.checklist-item:hover .checklist-remove,
|
|
143
|
+
.checklist-item[data-editing] .checklist-remove,
|
|
144
|
+
.checklist-remove:focus-visible {
|
|
145
|
+
opacity: 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.checklist-add {
|
|
149
|
+
color: var(--color-text-muted);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.checklist-add tv-icon {
|
|
153
|
+
translate: 0 0.16em;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.checklist-add-input {
|
|
157
|
+
all: unset;
|
|
158
|
+
font: inherit;
|
|
159
|
+
color: var(--color-text);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.checklist-add-input::placeholder {
|
|
163
|
+
color: var(--color-text-muted);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.checklist-empty {
|
|
167
|
+
margin: 0;
|
|
168
|
+
padding: var(--space-6) 0;
|
|
169
|
+
color: var(--color-text-muted);
|
|
170
|
+
font-size: var(--text-lg);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* Data the page cannot read: an error page, centred in the page. */
|
|
174
|
+
.checklist-unreadable {
|
|
175
|
+
flex: 1;
|
|
176
|
+
display: flex;
|
|
177
|
+
flex-direction: column;
|
|
178
|
+
align-items: center;
|
|
179
|
+
justify-content: center;
|
|
180
|
+
gap: var(--space-8);
|
|
181
|
+
text-align: center;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.checklist-unreadable-icon {
|
|
185
|
+
display: grid;
|
|
186
|
+
place-items: center;
|
|
187
|
+
width: var(--space-64);
|
|
188
|
+
height: var(--space-64);
|
|
189
|
+
margin-bottom: var(--space-12);
|
|
190
|
+
border: 1px solid var(--color-border);
|
|
191
|
+
border-radius: var(--radius-pill);
|
|
192
|
+
background: var(--color-surface);
|
|
193
|
+
color: var(--color-text-muted);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.checklist-unreadable-title {
|
|
197
|
+
margin: 0;
|
|
198
|
+
font-size: var(--text-xl);
|
|
199
|
+
font-weight: var(--font-weight-semibold);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.checklist-unreadable-text {
|
|
203
|
+
max-width: 28em;
|
|
204
|
+
margin: 0;
|
|
205
|
+
color: var(--color-text-muted);
|
|
206
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Document
|
|
2
|
+
|
|
3
|
+
This document is Markdown text. The page and your agent share the JSON store
|
|
4
|
+
owned by this artifact. The root
|
|
5
|
+
object has one required `markdown` string, and a new document starts blank as
|
|
6
|
+
`{"markdown":""}`. Spaces and line breaks are kept exactly. Other root fields
|
|
7
|
+
are ignored by the page and preserved when it saves.
|
|
8
|
+
|
|
9
|
+
The commands below require `jq`. Set `ARTIFACT_ID` to the ID of the document.
|
|
10
|
+
Read the current Markdown again immediately before replacing it, even if you
|
|
11
|
+
read it earlier while preparing the change:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
tv resource json get --artifact "$ARTIFACT_ID" markdown | jq -j .value > document.md
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This keeps every line break exactly as stored. If the field is absent, the
|
|
18
|
+
command writes `null` instead; do not replace the document from that file.
|
|
19
|
+
|
|
20
|
+
To replace the complete Markdown from a file, JSON-encode it and write it to
|
|
21
|
+
the field while leaving other root fields alone:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
jq -Rs . document.md | tv resource json set --artifact "$ARTIFACT_ID" markdown --file -
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Clear the document:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
tv resource json set --artifact "$ARTIFACT_ID" markdown '""'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The page saves the complete document after a short pause in typing. Agent
|
|
34
|
+
changes appear live in an open editor, and the page's changes appear live to
|
|
35
|
+
agents and other viewers. Concurrent replacements use last-write-wins order;
|
|
36
|
+
this first version does not merge simultaneous text edits. A full-string agent
|
|
37
|
+
write replaces anything the person saved since the agent last read, as well as
|
|
38
|
+
their unsaved typing if the write arrives while they are typing. There is no
|
|
39
|
+
offline queue, so the editor becomes read-only while it reconnects.
|
|
40
|
+
|
|
41
|
+
Invalid or missing data shows an error and is not repaired by the page. Restore
|
|
42
|
+
a root object with a `markdown` string to recover it.
|
|
43
|
+
|
|
44
|
+
Each copied artifact created from Document contains `editor.js`, `editor.css`,
|
|
45
|
+
and `THIRD-PARTY-NOTICES.txt`. It keeps those exact editor files: a Television
|
|
46
|
+
update does not replace them, and a later installed template does not replace
|
|
47
|
+
them. Tables, links, task lists and the editor's other Markdown gestures remain
|
|
48
|
+
available.
|
|
49
|
+
|
|
50
|
+
`page.js` adapts the packaged Markdown editor to the artifact store. `editor.css` owns
|
|
51
|
+
the editor treatment, while `styles.css` owns the page layout and the loading,
|
|
52
|
+
status and error shell. For visual adaptations, change `styles.css` unless you
|
|
53
|
+
intend to replace the editor. Keep the `#editor` mount element. Keep `page.js`,
|
|
54
|
+
`editor.js`, `editor.css`, and `THIRD-PARTY-NOTICES.txt` together unless you
|
|
55
|
+
deliberately replace the editor and its licensing material.
|