This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.
Recipe: things dragged into the app
A node with drop takes files, text and links from other apps; a dropped file is lent, so the app copies attachments it keeps.
A drop node's DragEvent has files (doc: handles), text and
url; check url before following it. dragover says where a drag is,
to draw where it lands (grammar).
A dropped file is lent, not given. Its handle reads the source's file,
which may change or go (Mac, Windows, Linux, a browser's file handles),
or a copy (iOS, Android, a Mac promise, other browsers), and ends with the
session. Keep it one of two ways:
Use this recipe in my app
Paste this into Claude, Cursor, Codex, or another agent.
•
As the app's own: copy it into app:/data in a mutation the drop
sends, as below.
•
As the person's document, in place: declare its type
(file_handlers) and grant doc.keep and fs.write doc:/;
the reference says which
drops reopen.
contract
shape Kept
id: string
name: string
size: number
shape Reply
ok: bool
component Attachments
resource kept = loadKept() as shape Kept[] else empty()
mutation copied as shape Reply queue refreshes kept
action took(e: DragEvent)
send copied = keepDropped(e.files)
view
column testId="zone" drop=took flex=1
text "Drop files here"
for a in kept key=a.id
text `${a.name} (${a.size} B)` testId=`file-${a.id}`
In app.ts (import Storage too):
ts
const DIR = 'app:/data/attachments';
const LIST = `${DIR}/list.json`;
export const grants = `fs.read doc:/\nfs.read ${DIR}\nfs.write ${DIR}`;
const listed = (storage: Storage) =>
storage.fs.readFile(LIST).then((b) => JSON.parse(new TextDecoder().decode(b)),
(e) => (e.code === 'ENOENT' ? [] : Promise.reject(e)));
const sources: Sources = {
loadKept: async (_args, _store, storage) => {
const out = [];
for (const a of await listed(storage)) out.push({ ...a, size: (await storage.fs.stat(`${DIR}/${a.id}/${a.name}`)).size });
return out;
},
keepDropped: async ([files], _store, storage) => {
const list = await listed(storage);
for (const file of files) {
if ((await storage.fs.stat(file)).isDirectory) continue;
const name = file.split('/').pop()!;
const id = String(+(list.at(-1)?.id ?? -1) + 1);
await storage.fs.mkdir(`${DIR}/${id}`);
const path = `${DIR}/${id}/${name}`;
list.push({ id, name });
await storage.fs.copyFile(file, path)
.then(() => storage.fs.atomicWriteFile(LIST, new TextEncoder().encode(JSON.stringify(list))))
.catch((e) => storage.fs.rm(path).finally(() => { throw e; }));
}
return { ok: true };
},
};
A copy not listed is removed if it can, and throws (after a
write); copyFile passes readFile's 16 MiB limit; one
writer is assumed.
fixtures/a/notes.txt has 19 bytes, fixtures/b/notes.txt 5:
contract-test
test "two files of one name are kept"
tap "zone" drop file "fixtures/a/notes.txt"
tap "zone" drop file "fixtures/b/notes.txt"
clock settle
reload
clock settle
expect text "file-0" == "notes.txt (19 B)"
expect text "file-1" == "notes.txt (5 B)"
Is this helpful
Last updated November 28, 2026