Your own interface
Catalogue supplies catalogue behaviour without generating HTML. This is appropriate for an existing design system, a virtualized list or application-specific navigation. It retains the same search and filtering rules as the ready components while leaving rendering, selection and accessible status messages to the host. No card template extension is required for this approach.
Configure state before requesting data
Create new Catalogue(name) for independently owned state or use catalogueNamed(name) to join the state used by named blocks. configure accepts origin, kinds, size and per; the first supplied option values are retained. setKind changes shelf, setQuery changes search, and setFilter merges filter fields. Each changes the question and clears loaded rows. resetFilters resets the current shelf while retaining sort order; filters otherwise remain separate for each shelf.
import { Catalogue } from 'mosaicary/catalog';
const shelf = new Catalogue('custom');
shelf.configure({ kinds: ['skins', 'builds'], size: '64', per: 12 });
shelf.setKind('skins');
shelf.setQuery('hoodie');
shelf.setFilter({ arms: 'slim', tags: ['blue'], tagsAll: false });Render typed events in plain JavaScript
Subscribe before configuring or loading. items carries only the new page in detail.items, whereas items on the store contains all loaded rows. reset announces cleared results, filters a changed question, and state changes to loading, totals or failure. These events are declared by CatalogueEventMap; the last three have no useful detail. Read total, loading and failure from the store, render the state explicitly, and remove listeners when disposing the view.
const list = document.querySelector('#results');
const draw = () => {
list.replaceChildren(
...shelf.items.map((item) => {
const link = document.createElement('a');
link.textContent = item.name;
link.href = item.page;
return link;
}),
);
};
const state = () => console.log(shelf.loading, shelf.total, shelf.failure);
for (const name of ['items', 'reset']) shelf.addEventListener(name, draw);
shelf.addEventListener('state', state);
await shelf.more();
// On disposal, remove the same listeners.Control pagination and retry timing
more() requests the next page when wanting allows it. The guard excludes an active request, an exhausted list and a failed request still waiting for retry. page and pages expose pagination progress. failure is structured error information; failed remains its message for compatibility. Automatic waiting honours retryAfter in seconds. retry() skips the growing pause and calls more() at once, but still waits for a retryAfter interval set by the service.
if (shelf.wanting) await shelf.more();
// Explicit user request after a failure:
await shelf.retry();
// Clear this shelf's filters, retaining its sort order:
shelf.resetFilters();Keep one store across React renders
A ref keeps the store stable while React renders. Copy items when updating component state because the store appends to the same array. The example attaches listeners inside an effect and removes those exact functions during cleanup, including the additional setup cycle in StrictMode. A production interface should replace the sample paging button with its own viewport observer and provide resource attribution. Frameworks covers the alternative ready React components and their element refs.
import { useEffect, useRef, useState } from 'react';
import { Catalogue, type CatalogItem } from 'mosaicary/catalog';
export function Results() {
const ref = useRef<Catalogue | null>(null);
if (!ref.current) ref.current = new Catalogue('react-results');
const shelf = ref.current;
const [rows, setRows] = useState<CatalogItem[]>([]);
const [status, setStatus] = useState('');
useEffect(() => {
const draw = () => setRows([...shelf.items]);
const state = () =>
setStatus(
shelf.failure?.message ??
(shelf.loading ? 'Loading' : String(shelf.total ?? '')),
);
shelf.addEventListener('items', draw);
shelf.addEventListener('reset', draw);
shelf.addEventListener('state', state);
shelf.configure({ kinds: ['skins'], size: '64', per: 12 });
void shelf.more();
draw();
state();
return () => {
shelf.removeEventListener('items', draw);
shelf.removeEventListener('reset', draw);
shelf.removeEventListener('state', state);
};
}, [shelf]);
return (
<section>
<p role="status">{status}</p>
{rows.map((item) => (
<a key={item.id} href={item.page}>
{item.name}
</a>
))}
<button onClick={() => void shelf.more()} disabled={!shelf.wanting}>
Next page
</button>
</section>
);
}