Pages, panels and status
Interface Songstress draws for you, from a tree of its own components, in the places it gives your extension.
Your extension's interface fits Songstress because Songstress draws it. You say what you mean (a page, a list, a tree, a choice to make, a notice, a status in the player) as JSON, and each app draws it with its own controls: the web and desktop apps in their design, the phones natively. What happens on a tap is JSON too: an action, which the app carries out. An extension never sets a colour, never reaches the app's own screens, and never shows anything without its mark.
Places
| Place | Declared in | Web and desktop | Phones | Drawn from |
|---|---|---|---|---|
| A page | pages | The main area, and an entry in the sidebar with sidebar | A page of its own, and an entry in the Library tab's "Extensions" group with sidebar | Its renderer's screen |
| A sheet | A navigate action with present: "sheet" | A page over the screen it came from | A sheet | The page's renderer |
| A panel | panels | A section of Songstress's own screen, at its location | The same | Its renderer's blocks |
| A status item | status | The player bar | The full player | Its renderer's status |
| A menu item | menus | The menu at its location | One "Extensions" submenu in that menu | A declared command |
| The settings page | settings | The extension's own page | The extension's own page in Settings | The manifest |
| A notice | A notify action, songstress.ui.notify | Over the app, until it is closed | The same | The notice |
| A view | views | A browser tab (web), the system's browser (desktop) | The in-app browser | Your own HTML |
A renderer is a function your entry registers under the declared id, in the entry the manifest names in render:
songstress.ui.pages.register(id, render), songstress.ui.panels.register(id, render) or
songstress.ui.status.register(id, render). It is told who is looking, in which app (client), and what the screen
shows. What the server entry renders shows in every app. A page's renderer is told:
Prop
Type
Pages
A page is a screen of its own, opened by an action, or from the apps' navigation when it sets sidebar. Up to 20.
when holds back its navigation entry, never the page.
Prop
Type
import { songstress } from 'songstress/server'
songstress.ui.pages.register('recent', async (context) => {
const sent = (await songstress.storage.get<string[]>('sent', { userId: context.userId })) ?? []
return {
type: 'list',
sections: [{ title: 'Sent today', items: sent.map((songId) => ({ type: 'song' as const, songId })) }],
empty: { title: 'Nothing sent yet', text: 'Play something, and it shows here.', icon: 'music' },
}
})A page answers one of five screens:
type | What it is |
|---|---|
list | Sections of rows, with an optional search field, an empty state and more rows on demand (nextCursor) |
grid | Sections of cards, with the same |
tree | Nodes that hold nodes: folders, groups, anything that holds more of itself; with an optional search field and an empty state |
detail | Blocks, read from top to bottom |
form | Sections of fields and one button that hands them to a command |
Rows and cards. row and card are your own: a title, a subtitle, an icon or an image, an action on a tap, a
menu. song, album, artist and playlist are Songstress's own, named by library id and drawn exactly as
Songstress draws them elsewhere, with their own menus.
Trees. A tree holds nodes: each your own node or a library song. A node holds what's under it as
children, given now, or expandable, which says it has some: when the person opens it, the page is rendered again
with the node's id in context.node, and your answer's nodes are what's under it. The web and desktop apps open a
node in place (open opens it at first); the phones open a node that holds others as a page of its own.
Blocks, what a detail screen, a section and a panel are built from: stack, section, text, icon,
image, badge, progress, banner, divider, spacer, collapsible, button, menu, shelf, and the four
library types.
Fields, what a form holds: text-field, switch, checkbox, slider, picker, date-picker. The app keeps
what's typed until the form is submitted; the command then gets the values by field name in context.values.
Every component's exact shape is in the API reference.
Panels
A panel is a section inside one of Songstress's own screens. Up to 10.
Prop
Type
location | Where it is drawn | Its renderer is told |
|---|---|---|
now-playing | The player's now-playing view | The song playing |
home | Home, after Songstress's own shelves | |
artist | An artist's page | The artist |
album | An album's page | The album |
playlist | A playlist's page | The playlist's id |
A song, an artist or an album is handed over whole to an extension granted library.read, and left out for any
other. A panel's renderer is told:
Prop
Type
It answers its blocks, or null to show nothing:
import { songstress } from 'songstress/server'
songstress.ui.panels.register('plays', async ({ album }) => {
if (!album) return null
return { children: [{ type: 'text', text: `${album.songCount ?? 0} songs on ${album.name}`, style: 'caption' }] }
})Status items
A status item is your extension's state at a glance in the player: a few words and an icon ("Sent", a check), in a tone, with what a tap does. Up to 2.
Prop
Type
It is rendered for the song playing: when the player shows it, when the song changes, and when it is refreshed. Its
renderer answers what it shows, or null to show nothing now:
Prop
Type
It is told who is looking and the song playing:
Prop
Type
import { songstress } from 'songstress/server'
songstress.ui.status.register('sent', async ({ userId, song }) => {
if (!song) return null
const last = await songstress.storage.get<string>('last', { userId })
return last === song.id ? { text: 'Sent', icon: 'check', tone: 'success' } : { busy: true }
})The apps show as many status items as their player has room for, in the order of the extensions' names.
Views
A view is your own HTML file, for what Songstress's components can't draw: a visualiser, a game, a chart of your own. Up to 10. A view and a page are opened the same way, so they share their ids.
Prop
Type
An app opens a view in the browser, apart from the app: a tab on the web, the system's browser on the desktop, the
in-app browser on a phone. It gets no songstress API and nothing of the app's: no storage, no session, no player.
It is served by the member's own server at an address of its own that expires, and is handed the params it was
opened with as the address's query. Any data it needs, it fetches itself. What must react to the app, or work
offline, belongs in a declared page.
Actions
What a tap does:
type | What it does |
|---|---|
invoke | Runs one of your commands |
navigate | Opens one of your pages or views, or Songstress's page for something in the library; as a page or as a sheet |
play | Plays library songs now, as a tap on a song does |
queue | Adds library songs to the queue, at its end or next |
openUrl | Opens an http or https address in the browser |
copy | Copies text |
share | Opens the device's share sheet |
toast | Shows a short message that goes away by itself |
notify | Shows a notice that stays until it is closed, with up to two buttons |
confirm | Asks first, then carries out another action |
pick | Asks the person to choose, then hands their choice to a command |
input | Asks for a line of text, then hands it to a command |
refresh | Renders the page, panel or status item it came from again |
A command answers with an action for the app to carry out, so your extension can lead a person through steps that each run on their own: a pick hands its answer to a command, which answers with an input, whose answer goes to another command, which answers with a notice.
Asking
pickis Songstress's picker: atitle, theitemsto choose from (each anidand atitle, and optionally asubtitle, aniconor animage), a search field with an optionalplaceholder, andmanyfor a choice of several (pickedmarks those chosen at first). Then itscommandruns with the action'sinput, andcontext.answerholds the id chosen, or the ids. Up to 100 items.inputis one field: atitle, aprompt, aplaceholder, thevalueit holds at first,multiline, amaxLength(up to 2000),required, andsubmit, the word on its button. Then itscommandruns, andcontext.answeris the text. Never a password: a secret is a setting.confirmasks yes or no, then carries out itsaction.
Prop
Type
Prop
Type
context.source says which asked. A question may lead to one more question and no further: a third in a row is no
action at all. Nothing runs when the person closes what was asked.
import { songstress } from 'songstress/server'
songstress.commands.register('choose-chart', async () => ({
action: {
type: 'pick',
title: 'Which chart?',
items: [
{ id: 'week', title: 'This week' },
{ id: 'year', title: 'This year' },
],
command: 'show-chart',
},
}))
songstress.commands.register('show-chart', async (_input, context) => ({
action: { type: 'navigate', to: { page: 'chart', params: { period: String(context.answer) } } },
}))Notices
A toast goes away by itself. A notice stays until the person closes it: a title, a message, a tone (info,
success, warning or danger), and up to two buttons, each a title and an action. The app shows it with
your extension's name.
Prop
Type
Code may also tell a notice unasked, while the member has an app open, with songstress.ui.notify(notice). The
server entry names the member (songstress.ui.notify(notice, { userId })) and every app they have open shows it.
Nothing is kept for an app that is closed. At most ten an hour for one member: more reject with limit-exceeded.
Live
What you draw is rendered when it is shown, and again when the person pulls to refresh, when a refresh action asks,
and when your code asks with songstress.ui.refresh(target), where target is { page }, { panel } or
{ status } with the id. The server entry names the member: songstress.ui.refresh({ status: 'sent' }, { userId }).
Asked more often than once every five seconds for one target, an app renders it once.
Conditions
A menu item, a page's navigation entry, a panel and a status item may name a when: a condition the app holds it
to, as VS Code's when clauses do. Up to 200 characters:
- a key alone (true when its value is true, a text that isn't empty, or a number that isn't 0), or compared to a value
with
==or!=; - a value is
'text'in single quotes, a number,trueorfalse; !turns a condition round,&&and||join two, and parentheses group them, nested at most eight deep.
| Key | Its value | Known in |
|---|---|---|
platform | web, desktop, ios or android | Every place |
clientCode, views | The app's capabilities | Every place |
admin | The member is the server's admin | Every place |
signedIn | The extension's sign-in has an account: the server's, or with scope user the member's own | Every place |
playing | This device's player is playing | Every place |
setting.<key> | One of your settings, as this member and device have it (never a secret) | Every place |
favorite | The song, album or artist the menu was opened on is a favourite | The menus of a song, an album, an artist, the queue and the player |
{ "command": "send-again", "when": "signedIn && setting.mode == 'manual' && platform != 'web'" }The validator refuses a condition no app can read (WHEN_INVALID), and a key no app knows there, a setting you
didn't declare or a secret one, signedIn with no sign-in, or a platform that is none of the four
(WHEN_KEY_UNKNOWN). An app that can't read a condition leaves the item out.
What a tree can't do
By design, a tree can't run script or timers in the app, choose a colour, a font, a size or a position (colour is
said by meaning, tone, and the theme decides the rest), load an image from the device, ask for a password, draw
outside its places, or grow without bound: the apps cap a tree's size, depth and rows, and how often it is redrawn.
An app says which version of the components it draws (client.ui; this is version 2, which added trees, status
items, notices, pick and input). A component it doesn't know shows as "needs a newer app", and an action it
doesn't know does nothing: read client.ui and answer what that app draws.