Docs / Apps

Make an Isolink app

An app is a database your people share, with screens you write in TSX. It runs on every phone and computer, keeps working with no internet, and is end-to-end encrypted like your chats.

What an app is

An Isolink app is a database with its own screens. The database holds the app's tables, lives on people's own devices, syncs like messages and is end-to-end encrypted. The screens are written in TSX (TypeScript with JSX) against the isolink module, and run in a small sandbox (QuickJS) on each device. They draw with Isolink's own components, so an app looks at home on every phone and computer, in light and dark.

Shopping, Todo and Notes are apps from the store. Timers, Birthdays and Plans come with Isolink. Every app also opens in Isolink's own views (Table, from the app's ⋯ menu), so nothing is locked inside an app.

An app's code can only reach its own databases. Everything else, from a website to the calendar, it lists in needs, people see that list before they get it, and Isolink checks every call against it.

Your first app

An app is a folder:

apps/community/water/
  app.json        its id, name, icon, schema, starter rows and needs
  src/app.tsx     its screens
  src/app.css     its looks (optional)
  l10n/es.json    its words in other languages (optional)
  listing.json    who made it, its licence and version (store only)

app.json:

{
  "id": "water",
  "name": "Water",
  "icon": "eco",
  "accent": 4280391411,
  "version": 1,
  "main": "src/app.tsx",
  "schema": {
    "tables": {
      "plants": {
        "title": "name",
        "fields": {
          "name": { "id": 1, "type": "text", "max": 40, "required": true },
          "every": { "id": 2, "type": "number" },
          "watered": { "id": 3, "type": "date" }
        }
      }
    }
  },
  "starter": { "plants": [{ "name": "Monstera", "every": 7 }] },
  "summary": { "table": "plants", "none": "No plants yet", "one": "1 plant", "many": "{p0} plants" }
}

src/app.tsx:

import { defineApp, Screen, List, ListItem, Text, Fab, Sheet, Stack, TextField, Stepper, Button,
         useQuery, useData, useLocal, format } from 'isolink';

type Plant = { id: string; name: string; every?: number; watered?: string };

function Home() {
  const plants = useQuery('plants', { sort: ['name'] }) as Plant[];
  const data = useData();
  const [adding, setAdding] = useLocal(false);
  const [name, setName] = useLocal('');
  const [every, setEvery] = useLocal(7);

  const add = () => {
    if (!name.trim()) return;
    data.add('plants', { name: name.trim(), every });
    setName('');
    setAdding(false);
  };
  const today = format.date(Date.now(), 'iso');

  return (
    <Screen title="Water" fab={<Fab icon="add" onPress={() => setAdding(true)} />}>
      <List>
        {plants.map((p) => (
          <ListItem
            key={p.id}
            title={p.name}
            subtitle={p.watered ? `Watered ${format.date(p.watered)}` : 'Not watered yet'}
            trailing={<Text tone="muted">every {p.every ?? 7} days</Text>}
            onPress={() => data.edit('plants', p.id, { watered: today })}
          />
        ))}
      </List>
      <Sheet open={adding} onClose={() => setAdding(false)}>
        <Stack gap={3}>
          <TextField value={name} onChange={setName} placeholder="Name" onSubmit={add} autofocus />
          <Stepper value={every} min={1} max={60} onChange={setEvery} />
          <Button expand onPress={add}>Add</Button>
        </Stack>
      </Sheet>
    </Screen>
  );
}

export default defineApp({ screens: { Home } });

That's a whole app. Get makes a database from the schema with the starter rows, and it opens on Home. The bar at the top shows the database's name (a picker when there are several) and the ⋯ menu with Share, Table, Allowed and Pin to You; title shows there once you've gone a screen deeper.

app.json

KeyWhat it is
idThe folder's name: small letters, digits, _ and -, up to 32.
name1 to 40 characters.
iconAn icon name (see Icons).
accentA colour as a number, 0xAARRGGBB written in decimal. Buttons, rings and the app's tile use it.
versionA whole number from 1. Raise it when the schema changes, so databases upgrade.
apiThe isolink module's version, 1 today.
mainThe entry file, src/app.tsx (or .ts, or .iso). Without it the app opens in Isolink's own views.
schemaIts tables and fields (Schemas), or put it in schema.json beside app.json.
starterRows a new database starts with, by table. At most 200.
summaryWhat's waiting, for the app's tile when it's pinned to You: {table, where?, none?, one?, many?}, the count as {p0}.
needsWhat it reaches beyond its own databases: web, device, system, secrets, chat (Needs).
chatIts items in a message's menu, and the cards it sends into chats (In chats).
viewHow it opens on a computer: full (the default) fills the window beside the sidebar and stays open while you're in your chats, split opens beside the list like a chat. Phones always open apps full.

A built app is at most 1 MB, its code at most 200 files and 2 MB before it's bundled.

Screens and moving between them

defineApp({ screens, start, migrate, actions }) names the app's screens. Each is a function component; the first (or start) opens first. useNav() moves between them:

function Home() {
  const nav = useNav();
  return <Screen><Button onPress={() => nav.push('Plant', { id: 'abc' })}>Open</Button></Screen>;
}

function Plant() {
  const { params, pop } = useNav();
  const plant = useRecord('plants', params.id);
  return <Screen title={plant?.name ?? ''}><Button onPress={pop}>Done</Button></Screen>;
}

export default defineApp({ screens: { Home, Plant } });

push(name, params) goes deeper, pop() goes back (as does the system's back), go(name, params) starts again from that screen. screen, params and depth say where you are.

defineApp({ screens, split: ['Recipes'] }) makes a list screen a master: on a wide window a screen pushed from it opens beside it, and the next one pushed takes its place; on a phone it's pushed as ever.

Wrap each screen in <Screen>. Its title, actions (buttons for the top bar), fab (a <Fab>) and footer (a bar along the bottom, kept above the keyboard) go in the app's own bars; its children scroll. tabs, tab and onTab give the app a tab bar along the bottom, and awake keeps the display on.

Components and props

Components are Isolink's own, imported from isolink by name. They take props like any JSX: strings, numbers, booleans, lists, objects, other elements (leading={<Icon name="star" />}) and functions (onPress). Every one is in the component directory, with its props and an example.

Every component also takes:

PropWhat it does
classClass names from the app's stylesheet (className works too). A list or {name: true} object is fine.
styleOne element's own styles, style={{ background: '#fde68a', borderRadius: 12 }}. Numbers are px.
keyTells items in a list apart, so each keeps its state as the list changes.
hiddentrue draws nothing.
padSpace inside: one number, [vertical, horizontal] or [top, right, bottom, left].
width, heightA size.
disabledFaded, and taps do nothing.
growInside a Row or Stack, takes the room left (grow={2} takes twice as much).
transitionfade, slide or scale as it appears.

Space is a step from 0 to 6 (0, 4, 8, 12, 16, 24 and 32 px) or, above 6, px: gap={3} is 12 px and gap={20} is 20 px.

Text and numbers can be children anywhere: <Button>Add</Button> is the same as <Button label="Add" />. {cond && <X />}, {list.map(...)} and <>…</> work as in React.

Component directory

All the components, by what they're for, each with its props and an example: the component directory.

State

HookWhat it gives
useLocal(initial)[value, set], kept while the screen is open. useState is the same.
useStore(key, initial)[value, set], kept on this device between opens (up to 16 KB a key). Not synced.
useRef(initial){ current }, kept between draws without drawing again.
useMemo(make, deps), useCallback(f, deps)As in React.
useEffect(effect, deps)Runs after a draw when deps change; a function it returns cleans up.
useAsync(make, deps){ loading, data, error } for a promise.
useForm(fields, { onSubmit })Values and errors for a form: field(name) gives {value, error, onChange}. Fields take required, max, min, pattern, message, default.
useNow(ms)The time, drawn again every ms (at least 250). For clocks and countdowns.
useMe(){ id, name, role, lang }: who's using the app and their role in this database.
useLayout(){ width, height, dark, reduceMotion, pointer, insets } of the screen: pointer is mouse or touch, reduceMotion is the person's setting.
usePlatform(){ os, desktop, apple, form, mod }: os is mac, windows, ios, android or linux; form is desktop, tablet or phone; mod is ⌘ or Ctrl, for labels.
useFrame(cb)Calls cb(dt) about 30 times a second while the screen shows, for games and live drawing. useFrame(cb, false) pauses it.
useSafeArea(){ top, left, right, bottom }: what's in the way along each edge of a full-bleed screen (the bar, the sidebar's glass, the system's own). Keep your own controls inside it.

Data

The app's data is its database's tables, read from this device's own copy:

const open = useQuery('tasks', { where: [['done', '=', false]], sort: ['-due'], limit: 50 });
const task = useRecord('tasks', id);         // one row, or null
const data = useData();
const id = data.add('tasks', { title: 'Buy milk' });
data.edit('tasks', id, { done: true });
data.remove('tasks', id);

useQuery(table, query) is live: a screen draws again when its rows change, here or on anyone's device. A query takes where, sort ('field', '-field' for descending, or [field, 'asc' | 'desc']), limit (500 by default), search, fields, group and counts; the shape is in Queries. Rows come with their id.

Writes are checked against the schema and the person's role (Admin, Edit, Add, View). One that isn't allowed isn't written, and the person sees why. add gives the new row's id at once.

useChat() lists the database's members, {id, name, role}.

Talking to the person

const toast = useToast();
const dialog = useDialog();
toast('Saved');
useScroll().to('L');   // brings the box with mark="L" into view
if (await dialog.confirm({ title: 'Delete this note?', body: 'It goes for everyone.', ok: 'Delete', danger: true })) { … }
const name = await dialog.prompt({ title: 'New folder', placeholder: 'Name', value: '' });   // text, or null
const picked = await dialog.menu([{ id: 'pin', label: 'Pin', icon: 'push_pin' }, { divider: true },
                                  { id: 'delete', label: 'Delete', icon: 'delete', danger: true }]);

Also useHaptics() (a tap you can feel: haptic(), haptic.impact('heavy'), haptic.success(), .warning(), .error()), useClipboard().copy(text), useShare().share(text) (the system's share sheet) and useKeys({ 'mod+k': open }), the app's keyboard shortcuts on a computer. Give one a name, { 'mod+n': { run: add, label: t('New') } }, and it's listed under Shortcuts in the ⋯ menu.

useShare().share({ app: 'shopping', text }) hands words to another of the person's apps instead, one that lists share in needs.system: it opens with them as useShared(), with from set to this app's name. It answers false when they don't have that app. Use an app's id, such as shopping or recipes.

Words in other languages

Write the app's words in English and wrap them in t():

import { t } from 'isolink';
<Text>{t('Got · {n}', { n: got.length })}</Text>

Then put l10n/<lang>.json beside app.json for es, fr, de, pt, zh and ar, English to the translation: { "Got · {n}": "Comprado · {n}" }. People see their language, or the English as written. The summary words are looked up there too.

format writes numbers and dates the same on every device: format.number(1234.5, { decimals: 1 }), format.money(3.5, 'EUR'), format.date(v, 'day' | 'time' | 'full' | 'iso'), format.relative(v) ("in 3d", "2h ago") and format.duration(ms).

Looks

Import a stylesheet and use its classes:

import s from './app.css';
<Pressable class={s.card} onPress={open}>…</Pressable>
.card { background: var(--surface); border-radius: var(--radius-lg); padding: 14px; display: flex; gap: 8px; }
.card:pressed { background: var(--accent-soft); }
.list .card:last-child { margin-bottom: 0; }
@media (min-width: 600px) { .card { padding: 20px; } }
@media (prefers-color-scheme: dark) { .card { border: 1px solid var(--outline); } }

Isolink has no CSS engine on the device: the compiler turns a stylesheet into a table of properties that the components draw. So it's a subset:

Theme tokens keep an app in the person's look: var(--accent), --accent-soft, --on-accent, --surface, --bg, --ink, --muted, --outline, --success, --warning, --danger; --space-1 to --space-6; --radius-sm, -md, -lg, -xl; --shadow-1 to -3; --font-body, -display, -mono, -serif (a printed page) and -hand (handwriting).

A class's text styles beat a Text's variant, as in CSS. A stylesheet has at most 400 rules.

Your own components

A function is a component, as in React:

function Price({ value, currency }: { value: number; currency?: string }) {
  return <Text bold>{format.money(value, currency)}</Text>;
}

defineComponent makes one usable as an iso- tag, with named parts and events. In a .iso file, its <script>, <template> and <style> go together:

<script lang="ts">
  import { defineComponent } from 'isolink';
  export default defineComponent({
    slug: 'pack-list',
    props: { rows: 'list' },
    parts: { header: 'one' },
    events: ['pick'],
  });
</script>

<template>
  <Box class="list">
    <Text variant="title">{parts.header}</Text>
    {rows.map((row) => (
      <Pressable key={row.id} class="row" @press={() => emit('pick', row)}>
        <Text>{row.name}</Text>
      </Pressable>
    ))}
  </Box>
</template>

<style>
  .list { background: var(--surface); border-radius: var(--radius-lg); padding: var(--space-2); }
  .row:pressed { background: var(--accent-soft); }
</style>
import './pack-list.iso';
<iso-pack-list :rows={items} @pick={(r) => open(r.id)}>
  <iso-pack-list.header>Packing</iso-pack-list.header>
</iso-pack-list>

:name passes a value, @name a handler for an event, and <iso-slug.part> fills a part (one, or many for a list). A slug is 2 to 48 small letters, digits and hyphens. A .iso component's <style> applies to it alone.

The web and keys

fetch(url, { method, headers, body }) reaches the https hosts in needs.web (up to 16) and nothing else, with no redirects. It answers { status, ok, offline, headers, text(), json() }. Image loads pictures from the same hosts.

Apps work offline. Their code is on the device, and database edits wait and sync when it's back online. Pictures Image loads are kept on the device and asked for again with their ETag at most once a day. A plain GET's last good answer is kept too: with no connection fetch gives it back with offline: true, and online it asks with its ETag, so an unchanged answer isn't sent twice. Requests with a key are never kept.

For an API key, list it in needs.secrets: {"key": "openai", "name": "OpenAI key", "hosts": ["api.openai.com"]}, its hosts in needs.web. Write {secret:openai} in a header, body or query. Isolink asks for the key the first time, keeps it in the device's keychain and fills it in outside the app's code, only for those hosts. The code never sees it, and it never syncs. Keys, in the ⋯ menu, sets or removes it.

Needs

needs is everything an app reaches beyond its own databases. The checker refuses anything else.

"needs": {
  "web": ["api.example.com"],
  "device": ["camera"],
  "system": ["notify", { "name": "calendar.add", "optional": true }],
  "secrets": [{ "key": "example", "name": "Example key", "hosts": ["api.example.com"] }]
}

chat names take (the app's items under Apps in a message's menu, and files from chats) and send (its cards sent into chats): see In chats.

device names camera (Camera, Scanner), location (My location on Map and PlacePicker) and microphone (Recorder). Without one, those components show what they'd need instead.

The phone or computer: needs.system

Each entry in system is a name, or { "name": …, "optional": true } for one a feature uses rather than the app as a whole.

NameWhat it doesAndroidiOSMacWindows
remindReminders that follow the account and ring on every device, with Done and Lateryesyesyesyes
notifyNotifications on this device, at most 64 waitingyesyesyeswhile Isolink runs
calendar.addA new event, through the calendar's own sheetsheetsheetsaved to the default calendar.ics opened in Calendar
calendarRead eventsyesyesyes–
remindersAn item in Apple's Reminders–yesyes–
alarmsAn alarm or a timerclock appnotificationnotificationnotification
contacts.pickOne contact, from the system's pickeryesyes––
filesOpen (up to 4 MB) and save files, through the pickeryesyesyesyes
photos.saveSave a picture to Photosyesyesyessave dialog
openDirections, a call, a text or an email in the person's own appsyesyesyesyes
clipboard.pasteRead the clipboardyesyesyesyes
lockFingerprint, face or passcodeyesyesTouch ID–
shareListed when something is shared to Isolink; useShared() has ityesyesyesyes
shortcutsNot yet: has('shortcuts') is false everywhere––––

They're in isolink/system:

import { remind, notify, calendar, reminders, alarms, contacts, files, photos, open, clipboard, lock,
         useReminders, useCalendar, useShared } from 'isolink/system';

await remind.set({ key: task.id, text: 'Buy milk', at, repeat: 'weekly',
                   done: { table: 'tasks', row: task.id, set: { done: true } } });
remind.cancel(task.id);
const mine = useReminders();                                  // this app's reminders
await notify.schedule({ id: 'tea', title: 'Tea', body: 'Time’s up', at: Date.now() + 180_000 });
notify.cancel('tea');
const added = await calendar.add({ title, start, end, allDay, place, notes, alert: 15 });
const week = useCalendar({ from, to });                       // { loading, data: [{ id, title, start, end, allDay, place, calendar }] }
await reminders.add({ title, due, notes });
await alarms.set({ hour: 7, minute: 0, label: 'Up' });
await alarms.timer({ seconds: 180, label: 'Tea' });
const person = await contacts.pick();                         // { name, phones, emails } or null
const file = await files.open({ types: ['csv'] });            // { name, size, text } or null; as: 'base64'
await files.save({ name: 'export.csv', text });
await photos.save({ name: 'card.png', base64 });
open.directions('Cafe Nero'); open.call(number); open.text(number, body); open.email({ to, subject, body }); open.link('https://…');
const text = await clipboard.paste();
const ok = await lock.check();
const shared = useShared();                                   // { text, files: [{ name, size }] } or null

Times are a Date, ms since 1970 or an ISO string. remind's repeat is never, daily, weekdays, weekly, monthly or a count such as d2 (every 2 days) or m12 (every year). Its done is what the notification's Done button changes, in this app's database, under the person's role; Later rings again in an hour. Every app notification and reminder is titled with the app's name.

Bots

A bot the person chats with can do things in an app the way its buttons do, when it's asked to: start a timer, add a birthday with its reminder. Declare them as actions; the person sees each one before it runs, unless they set the bot to Always.

export default defineApp({
  screens: { Home },
  actions: {
    start: {
      title: 'Start a timer',
      params: { name: 'string', minutes: { type: 'number', optional: true } },
      run: async ({ name, minutes }, { data, store, system }) => {
        // ...the same as the Start button
        return { ends: new Date(at).toISOString() };
      },
    },
  },
});

In chats

An app can take what a person picks in a chat. Its items sit behind one Apps row in a message's menu (right-click, or hold on a phone): Save to Notes, Add task. Picking one hands the app that message, and nothing else of the chat.

Declare the items in app.json, with take in needs.chat:

"needs": { "chat": ["take"] },
"chat": {
  "actions": [
    { "id": "save", "title": "Save to Notes", "icon": "note_add",
      "takes": ["text", "link", "image", "video", "voice", "file"],
      "many": true, "max": { "items": 30, "bytes": 26214400 },
      "open": "sheet", "sheet": "Save" }
  ]
}
KeyWhat it is
idA small letter, then small letters, digits or _, up to 32.
titleWhat the row says, up to 24 characters, looked up in the app's l10n. Left out: the app's name.
iconAn icon name. The app's own icon is drawn beside the row.
takesThe kinds of message it shows on: text, link, image, video, voice, file. A message matches when it has any of them.
typesFor files, up to 16 extensions (pdf) or starts of a type (image/). Left out: any.
manytrue: it also shows for several messages picked together, and for a group of pictures.
max{ items, bytes }: the most messages (30 unless set, at most 100) and the biggest file (25 MB unless set, at most 100 MB). Past either, the item doesn't show.
opensheet (the default): the app's sheet over the chat. quiet: its code runs with no screen. app: the app opens at a screen.
sheet, run, screenWhich one, by name, for sheet, quiet and app. Left out: one named as the id.

An app has at most 6 items. Whether one shows is read from app.json alone: none of the app's code runs until the person picks it. Items never show on deleted messages, view-once and timed snaps, SOS messages, polls, cards, or files still on their way.

The first time someone picks an app's item, Isolink asks once: "Let Notes save messages you choose?", and says who else uses the database when it's shared. ⋯ › Allowed has a Message menu switch for each app, and Settings › Chats › Apps in chats turns the row off for every app. has('chat.take') is false when it's switched off or not declared.

What the app gets: a handoff

type Handoff = {
  via: 'message' | 'share' | 'drop';
  action: string;                  // the item's id
  items: {
    text: string;
    links: string[];
    files: HandoffFile[];
    by?: { name: string; me: boolean };
    at?: number;                   // ms since 1970
    ref?: ChatRef;                 // for a ChatCard or ChatChip, as dialog.chat() gives
  }[];                             // one per message picked, oldest first
  chat?: { title: string };
  ref?: ChatRef;
};
type HandoffFile = {
  name: string; mime: string; size: number;
  kind: 'image' | 'video' | 'voice' | 'file';
  keep(): Promise<FileValue>;      // makes it the app's own: the value for a `file` field
};

The app never gets a file's bytes. Image, Viewer, Audio and Video show a HandoffFile as it is (<Image src={file} />), and await file.keep() copies it into the app's files and answers with the value for a file field, as Upload does.

A sheet over the chat

Name the app's sheets in defineApp. A sheet is a component drawn inside Isolink's own frame, which has the app's icon, its name and Close; it isn't wrapped in Screen. It's a bottom sheet on a phone and a panel beside the message on a computer.

import { defineApp, Stack, TextField, Image, Button, useData, useLocal, useHandoff, useSheet, t } from 'isolink';

function Save() {
  const handoff = useHandoff();
  const sheet = useSheet();
  const data = useData();
  const first = handoff.items[0];
  const [title, setTitle] = useLocal(first.text.split('\n')[0].slice(0, 200));

  const save = async () => {
    const photo = first.files[0] ? await first.files[0].keep() : undefined;
    const id = data.add('notes', {
      title, photo,
      body: handoff.items.map((i) => i.text).filter(Boolean).join('\n\n'),
    });
    sheet.close({ toast: t('Saved'), open: { screen: 'Note', params: { id } } });
  };

  return (
    <Stack gap={3}>
      <TextField value={title} onChange={setTitle} placeholder={t('Title')} autofocus />
      {first.files[0] && <Image src={first.files[0]} height={120} />}
      <Button expand onPress={save}>{t('Save')}</Button>
    </Stack>
  );
}

export default defineApp({
  screens: { Home, Note },
  sheets: { Save },
});
What it gives
sheets in defineAppThe app's sheets by name: a component, or { view, width } to ask for a width on a computer (360 unless set, 280 to 560).
useHandoff()What this sheet or screen opened for, or null.
useSheet(){ open, close(result), setTitle(text) }. close({ toast, open }) closes it; Isolink shows toast, with an Open button when open names one of the app's screens ({ screen, params }). setTitle changes the frame's title from the app's name.

A sheet works in the app's first database, with the person's role there, and the app's own needs and limits. Someone who can only view that database isn't shown the app's items.

With no screen, or in the app

"open": "quiet" runs chat.quiet[run] with the handoff and no screen, as a bot's action runs, so toasts and dialogs do nothing there. What it returns is the same { toast, open }:

export default defineApp({
  screens: { Home, Note },
  chat: {
    quiet: {
      later: async (handoff, { data, store, system }) => {
        const id = data.add('notes', { body: handoff.items[0].text });
        return { toast: t('Saved'), open: { screen: 'Note', params: { id } } };
      },
    },
  },
});

"open": "app" opens the app itself at screen, where useHandoff() has what was picked.

Sending into a chat

An app can send one of its own cards into a chat: a note, a recipe, a ticket. Everyone in the chat sees it, with the app or without, because the card carries its own code and runs in the card sandbox like any other card. Someone who has the app also gets a button under it that takes it in.

Write the card with defineCard in a file of its own, and name it in app.json, with send in needs.chat:

"needs": { "chat": ["take", "send"] },
"chat": {
  "cards": [
    { "id": "note", "src": "src/cards/note.tsx",
      "data": { "title": "text", "body": "text" },
      "receive": "note", "button": "Save" }
  ]
}
KeyWhat it is
idA small letter, then letters, digits or _, up to 32.
srcThe card's file. The store compiles it into the app; it can be up to 48 KB compiled.
dataWhat it's sent with: up to 24 names, each text, number, bool or list (of text). Isolink checks it as it's sent and before receive runs. All of it fits in 8 KB.
receiveThe chat.receive handler that takes one in, for someone who has the app. Left out: there's no button.
buttonWhat the button says, up to 24 characters, looked up in the app's l10n. Left out: Save.

An app has at most 4 cards. The card gets its data as ctx.params in init:

// src/cards/note.tsx
import { defineCard, Stack, Text, Markdown, useCard } from 'isolink';

function View() {
  const { state } = useCard();
  return (
    <Stack gap={2}>
      {state.title ? <Text variant="headline">{state.title}</Text> : null}
      <Markdown compact text={state.body} />
    </Stack>
  );
}

export default defineCard({
  name: 'Note',
  init: (ctx) => ({ title: String(ctx.params?.title ?? ''), body: String(ctx.params?.body ?? '') }),
  View,
});

A card can't reach the app's database, the web or the device: it draws what it was sent with. It can have actions, which everyone in the chat shares, as in any card.

Send it with useSend(), from a tap:

const send = useSend();
const share = async () => {
  const sent = await send({
    card: 'note',
    data: { title: note.title, body: note.body },
    text: note.title,            // shown where the card's code can't run
  });
  if (sent) toast(t('Sent'));    // { ref, sent }: a ChatRef for a ChatChip, and how many chats; null if none
};

Isolink shows the card as it will look in its own share view, where the person ticks who gets it and taps Send. Nothing is sent by code alone: not from a timer, a bot's action, a quiet action or receive. An app can send 20 times an hour. ⋯ › Allowed has a Send to chats switch for each app, and has('chat.send') is false when it's off or not declared.

Taking one in:

export default defineApp({
  screens: { Home, Note },
  chat: {
    receive: {
      note: (sent, { data }) => {
        const id = data.add('notes', { title: sent.title, body: sent.body });
        return { toast: t('Saved'), open: { screen: 'Note', params: { id } } };
      },
    },
  },
});

receive runs with no screen, in the person's own first database with their own role, when they tap the button under the card. Treat sent as a stranger's: Isolink has checked it against data, and nothing more. The button shows only under a card whose code is exactly the card this device has for that app from the store, so a card that only says it's from Notes gets none.

Not yet: files sent along with a card, and a Get button for people who don't have the app.

Files from chats, inside the app

dialog.file() opens Isolink's own sheet over the pictures and files sent in the person's chats, newest first, with search. It works from a tap, for an app with take in needs.chat, and answers with the ones picked as HandoffFiles, or null when it's closed:

const dialog = useDialog();
const attach = async () => {
  const files = await dialog.file({ kinds: ['image', 'file'], many: true, max: { items: 10 } });
  if (!files) return;
  for (const f of files) data.add('attachments', { note: id, file: await f.keep() });
};
OptionWhat it is
kindsSome of image, video, file. Left out: all.
manytrue: several are ticked, then Add. Left out: one, picked by a tap.
max{ items, bytes }, as for an item: 30 files and 25 MB each unless set. Bigger files don't show.

The app learns nothing about the chats: only the names, types and sizes of what was picked. Check has('pick.file') first.

Files dragged in

On a computer, files dragged into Isolink's window, from Finder or Explorer or out of a chat, can be let go on an app under Apps in the drop view. An app is there when one of its items takes image, video or file. Its first item that takes what was dropped opens, with via: 'drop': files from the computer come as one item with no words, and messages dragged out of a chat come as they do from the message's menu. A DropZone inside the app takes the same drags with no change.

Shared from another app

An app that lists share in needs.system also gets what's shared to it as a handoff, with via: 'share' and one item: useHandoff().items[0].files are files it can show and keep(). useShared() still gives their names and sizes.

Upgrades

When a database is older than its app's version, the first Admin to open it upgrades it, as ordinary edits that sync like any other:

  1. The new schema is merged in. Fields and options are only ever added; one left out stays.
  2. A field with "from": "<old field>" takes over the old one's values (anything to text; text to a number, yes or no, a date, tags or a choice; one to many and back), and the old field is retired.
  3. An option with "was": ["old", "ids"] replaces those options in every row.
  4. The code's migrate runs on each row, for each version in between:
export default defineApp({
  screens: { Home },
  migrate: { 2: (row, table) => (table === 'plants' ? { ...row, every: row.every ?? 7 } : row) },
});

Publish it to the store

Apps reach people through the Isolink store, the same way theme packs and cards do.

  1. Fork the store and add your app's folder under apps/community/<id>/, with app.json, src/ and a listing.json (below).
  2. Check it. From packages/isolink_js in the Isolink repo, dart run bin/theme_store.dart check <your store folder> compiles the code and checks the app with the same rules the store uses. Errors name the file and line.
  3. Open a pull request. The store's check runs on it in a minute or two and says what to fix. A pull request may only change apps/community/<id>/.
  4. A maintainer reviews and merges it. Within the hour it's signed and published, and shows in Apps › Browse.

listing.json says who made it:

{ "version": 1, "by": "Your name", "licence": "CC-BY-4.0", "desc": "Remember when each plant was watered.",
  "tags": ["apps"], "minApp": "0.26.39" }

minApp is the oldest Isolink it runs on: 0.26.55 for chat and needs.chat (older ones refuse an app that lists a need they don't know), 0.26.37 for needs.system, and 0.26.39 for Masonry, StickyNote, a ProgressRing with children, style={{}}, dialog.menu and summary. desc is at most 200 characters and tags at most 8. The rest of the store's rules are in its README.

To change it, edit the folder and raise version in listing.json (and in app.json when the schema changes). Apps update themselves: Isolink looks once a day, and when Apps opens, for a newer version of each app it has a database for. One that asks for more than before (a new need, website or key) waits under Updates until the person taps Update, and so does every new version of an app whose Auto-update is off in its ⋯ menu. Nothing is ever downgraded.

Apps Isolink comes with

Timers, Birthdays and Plans are in the Isolink repo at app/apps/<id>/, laid out like a store app (app.json and src/app.tsx). After changing one, rebuild them:

cd packages/isolink_js
dart run tool/default_apps.dart

That writes app/assets/apps/<id>.isoapp. test/default_apps_test.dart fails while they're out of date. Shopping, Todo and Notes live in the store's apps/official/, so they change with the store, not an app update. Isolink comes with a copy of each for until the store's arrives; refresh the copies now and then by giving the tool a checkout of the store (dart run tool/default_apps.dart ../../../isolink-store). Where the code can't run they open in Isolink's own database views.

Limits and safety