Skip to content

List parameters ​

A list holds a variable number of flat items, such as the GPX tracks of one map, each with its own colour and label:

tsx
const mapParameters = {
  tracks: p.list({
    label: 'Tracks',
    item: {
      track: p.file({ label: 'GPX track', accept: ['.gpx'] }),
      colour: p.color({ label: 'Colour', default: '#c0392b' }),
      label: p.string({ label: 'Label', default: '' }),
    },
    min: 0, max: 12,
  }),
};
// render: ctx.elements.map.params.tracks is { id: string; track: string; colour: string; label: string }[]
  • Items are flat. item declares the fields with the other p.* helpers: file, string, number, integer, colour, date, enum and boolean. There are no nested lists. id is not a field name: it is the item's own ID.
  • Saved value: a JSON array in project.json. Each item has a stable id, generated by the app when the user adds or duplicates an item, so reordering, Undo and editor drafts address the item, not its position. Use it as the React key. A missing field takes its default.
  • Default: [], or default items valid against item. p.list gives default items without an id one from their position (item1, item2, …), skipping IDs other default items already use.
  • Validation: each item is checked with the field's own rules, and min/max bound the count. In render, a field with a value it does not allow takes its default, an item without a unique valid id is left out, and a count outside min/max (or a value that is not a list) uses the list's default. Each problem is reported per item; the saved data is never rewritten. A list's file fields are checked like file parameters: a missing or unreadable file is a Book check error naming the item.
  • Generated control: a compact list with add, remove, duplicate and reordering (drag, or the arrows), where each row shows a one-line summary (the file name, the first text, a colour swatch) and opens to the item's fields on click. Every change is one Undo step. In the inline editor's toolbar the list is a Tracks (3) button that opens it in a popover, so the toolbar stays one row. controls can name the list like any parameter.
  • Custom editors receive and set the whole array; ImageFlow validates it like any other value, so items need their id. <Control parameter="tracks" /> renders the generated list control, and <Control parameter="tracks" itemId={track.id} field="track" /> renders one field of one item, such as an import per track. itemId and field go together and only lists take them; the types check field against the item fields. An itemId the list never had is an error; once the item is removed, the control renders nothing.
  • Agents set the whole array with set_parameter, or change one item with insert_list_item, update_list_item, remove_list_item and move_list_item, addressed by its id (docs/mcp.md).
  • ctx.Text, ctx.edit conditions and controls when cannot compare a list; show its items with your own markup.

The starter's Map layout draws every track of its tracks list; Fit tracks frames all of them. It replaces the map's earlier single track and trackColor; books saved with those are not migrated (no released books use them).