@sewdn/slides-tools
v0.1.0
Published
Plumbing for interactive slide tools: define a tool, host it in a deck, keep what the room captures, walk views, export the minutes.
Readme
@sewdn/slides-tools
Plumbing for interactive slide tools: boards, polls, tables the room fills in during a deck. A tool declares what it is once; a deck lists it; the host does the rest — registers its MDX components, checks and seeds its definitions, keeps what the room captures in one persisted store, gives it its words in the deck's language, and collects its minutes and counts on the export slide.
@sewdn/slides-tool-lifecycle is the reference tool built on it.
Concepts
| Concept | What it is |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Tool | defineSlideTool({ id, key, definitions, components, copy, validate, seed, minutes, tiles }). Everything a deck needs to host it. |
| Definitions | What a deck gives a tool under its key (lifecycles: [...]), typed by the tool and checked by its validate when the deck is defined. |
| Deck config | defineToolDeck({ storageKey, tools, ...definitions, copy }). Typed by the tools it lists: a key no tool reads, or definitions of the wrong shape, do not compile. |
| Store | One flat map of strings per deck, in localStorage under <storageKey>:notes. A tool writes under its namespace: <namespace>:<key>. A document seeded from the deck carries seeded:<namespace>:<key>: the seed went in once, the room owns it since. A blocked or full storage never breaks the deck. Same layout as the workshop notes, so captures already in browsers keep reading. |
| Copy | A tool's words per deck language (en required, nl / fr when it has them; missing languages fall back to English). A deck overrides any of them, per tool and per language, partially: copy: { lifecycle: { nl: { states: "Fasen" } } }. The host's shared words (add, remove, undo, export buttons) are overridden under copy.tools. |
| Host | <ToolDeck deck config /> (or <SlideToolsProvider config> around your own deck): seeds once before the store is read, provides the store, the definitions and the copy, and registers every tool's components plus <ToolsExport>. |
| Minutes and tiles | Each tool returns Markdown lines and counts from its definitions and its part of the store. <ToolsExport title reset> shows a tile per tool that has something, and downloads or copies all minutes as one document. |
Write a new tool in one short file
A poll: the deck names the question and the options, the room picks one.
import {
defineSlideTool,
toolDefinitions,
ToolSurface,
Chip,
useToolCopy,
useToolDefinitions,
useToolValue,
} from "@sewdn/slides-tools";
type Poll = { id: string; question: string; options: readonly string[] };
function PollBoard({ id }: { id: string }) {
const poll = useToolDefinitions(pollTool)?.find((entry) => entry.id === id);
const words = useToolCopy(pollTool);
const [choice, setChoice] = useToolValue(pollTool, `${id}:choice`); // stored as "poll:<id>:choice"
if (!poll) return <div className="ws-empty">{words.unknown}</div>;
return (
<ToolSurface fill={false}>
<b>{poll.question}</b>
{poll.options.map((option) => (
<Chip
key={option}
onClick={() => setChoice(option === choice ? "" : option)}
pressed={option === choice}
tone="work"
>
{option}
</Chip>
))}
</ToolSurface>
);
}
export const pollTool = defineSlideTool({
id: "poll",
key: "polls",
definitions: toolDefinitions<readonly Poll[]>(),
components: { PollBoard },
copy: {
en: { polls: "Polls", open: "open", unknown: "Unknown poll" },
nl: { polls: "Peilingen", open: "open", unknown: "Onbekende peiling" },
},
validate: (polls) =>
polls.forEach((poll) => {
if (poll.options.length < 2) throw new Error(`poll ${poll.id}: two options at least`);
}),
minutes: ({ definitions = [], store, copy }) =>
definitions.length
? [
`## ${copy.polls}`,
"",
...definitions.map(
(p) => `- ${p.question}: ${store.value(`${p.id}:choice`) || copy.open}`,
),
"",
]
: [],
tiles: ({ definitions = [], store, copy }) =>
definitions.length
? [
{
key: "polls",
label: copy.polls,
tone: "time",
value: definitions.filter((p) => store.value(`${p.id}:choice`)).length,
},
]
: [],
});And the deck:
export const deckConfig = defineToolDeck({
storageKey: "kickoff",
tools: [pollTool, lifecycleTool],
polls: [{ id: "store", question: "Which store?", options: ["Postgres", "SQLite"] }],
lifecycles: [certificate],
});
export default function App() {
return <ToolDeck config={deckConfig} deck={deck} />; // slides: <PollBoard id="store" />, <ToolsExport title="Kick-off" reset />
}What the tool did not write: a provider, a store, a seeding effect, a
registration in a deck component, a branch in an export component, a section in
a shared minutes function, a field in a shared definition type, a locale
lookup. Adding the tool to a deck is one entry in tools and its definitions.
API
Defining
defineSlideTool(spec)→SlideTool. Spec fields:id— unique per deck; also the store namespace unlessnamespaceis given."tools"is reserved.key?,definitions?: toolDefinitions<D>()— the deck config property the tool reads, and its type.namespace?— store namespace (<namespace>:<key>); defaults toid. Use it to keep keys a tool wrote under another name.requires?: [otherTool]— tools this one builds on (it reads their documents, or its components use their hooks). A deck that lists the tool without them is refused; itsminutesandtilesread them withcontext.tool(otherTool)→{ definitions, store }, and reading a tool it does not require throws.components?— MDX components by the name slides use. Two tools in one deck may not register the same name.copy?: ToolCopy<C>—{ en: C, nl?: C, fr?: C }. TypeCwithToolWords<typeof EN>to widen literal strings.validate?(definitions, { storageKey })— throw to refuse a deck; runs indefineToolDeck.seed?({ definitions, storageKey, store })— once per mount, before the store is first read;store.seedOnce(key, value)writes a value and its flag the first time only. Lazy seeding (read the seed until the room changes it) needs noseed: useuseToolJsonwith a codec whoseseed()is the definition's draft.minutes?(context)→ Markdown lines;tiles?(context)→ToolTile[]({ key, value, label, tone? }). Return[]when there is nothing.context={ definitions, copy, locale, storageKey, store, tool },storea reader of the tool's namespace (value(key),json(key, codec),seeded(key)),tool(other)the same for a tool itrequires.
defineToolDeck({ storageKey, tools, copy?, ...definitions })— typed bytools; checks duplicate ids, namespaces, keys and component names, required tools, then every tool'svalidate.checkToolDeck(config)runs the same checks on a config built elsewhere.
Hosting
<ToolDeck deck config components? deckConfig? />—StructuredDeckwith the tools' components andToolsExportregistered (deckcomponentswin on a name clash).toolDeckHost(config)— the same as a host fordefineDeck({ host })in a deck on theslidesDeck()convention (see@sewdn/slides-vite):export default defineDeck({ host: toolDeckHost(deckConfig) }), noApp.tsxneeded.<SlideToolsProvider config>— the same host around any deck;toolMdxComponents(config)gives the components to register yourself.<ToolStoreProvider storageKey>— the store alone (used by slides-workshop'sNotesProvider).<ToolsExport title reset? />— tiles, Markdown download, copy, optional "clear everything".
Hooks (inside a host)
useToolDefinitions(tool)→ the deck's definitions for the tool, typed;undefinedwhen the deck has none.useToolCopy(tool)→ the tool's words in the deck's language with overrides (works outside a host, without overrides).useToolsCopy()→ the shared words.useToolValue(tool, key)→[string, set];""removes the value.useToolJson(tool, key, codec)→[value, change].codec = { parse, serialize, seed, empty? }; the seed until the room changes the document, the room's version (and theseeded:flag) after;emptyonce the room's version went missing.change(operation)applies a pure operation to the latest value, so two changes in one tick build on each other. Pass a stable codec.useToolDocuments(tool, codec)→{ read(key), change(key, operation) }— documents under keys picked at run time (one per application, per board), stored without aseeded:flag (withDocument), for a tool whoseseedputs its seed in: the flag keeps meaning "the seed went in".useToolStore()→{ storageKey, values, set, update, clear }— the raw deck store.useToolDeck()→{ config, locale };useToolsMinutes()→{ tiles, markdown(title) }.
Interaction and atoms
<ToolSurface className fill? …div props>— root of a tool:st-root ws-root(+is-fill), and the deck-safe handlers.deckSafeHandlers/useDeckSafeHandlers(onKeyDown?)— wheel, pointer and touch stay in the tool; typing, Space, Enter and a select's keys never move the slide; arrows elsewhere still navigate.<ToolViews views>{(view, step) => …}</ToolViews>+resolveViews(all, view?, views?)— one slide walks several views with the deck's next and previous; print shows the last.usePrintMode()— true under?print-pdf.useUndo()+<UndoToast undo className? />— one undo at a time:undo.offer(name, restore)right after a removal.Button(variant="quiet"),IconButton,Chip(a toggle withonClick+pressed),Field(label around an input or select),AddForm,Avatar,initials.
Pure helpers (testable without React)
readStore, writeStore, withValue, withDocument, toolKey, seededKey, storeKey, readJson, withJson, storeReader, storeWriter, newId, resolveCopy, mergeCopy, toolCopy, seedValues, seedTools, toolsMinutes, toolsTiles, toolContext, minutesDocument, minutesFileName, TOOLS_COPY.
Styles
The shared styles load with the components (ToolSurface, the atoms):
tools.css (the ws-* classes and data-tone → --st-* tokens of the kit)
and export.css. prose.css (the workshop look for Markdown tables) is
opt-in, because it restyles every Markdown table of a deck: a workshop deck
imports it (WorkshopDeck does), a presentation deck leaves it out. All three
are exported as @sewdn/slides-tools/tools.css, /prose.css and /export.css.
Tool packages that use Tailwind classes ship them as built code, which a
deck's Tailwind does not scan on its own (it skips node_modules and does not
follow symlinks). Each package therefore ships a tailwind.css with
@source "./dist": a deck imports @sewdn/<package>/tailwind.css for the
tools it uses, and @sewdn/slides-workshop/capture-panels.css imports them for
the tools it hosts. A
Tailwind deck scans node_modules/@sewdn/slides-tools/dist with @source.
