@uniformdev/toolbar
v20.73.4
Published
Framework-neutral engine for the Uniform toolbar: view models, visitor simulation and label resolution over a Uniform Context instance
Keywords
Readme
@uniformdev/toolbar (experimental)
The framework-neutral engine behind the Uniform toolbar: view models,
visitor simulation and label resolution over a Uniform Context instance.
No DOM, no framework — the Angular component
(@uniformdev/toolbar-angular) and the custom element
(@uniformdev/toolbar-element) are thin adapters over this. Use it directly
if you want to build your own UI.
import { UniformToolbarStore } from '@uniformdev/toolbar';
const store = new UniformToolbarStore({
context, // a Uniform Context instance
storage: localStorage, // optional; omit on the server
quirkGroups: [{ title: 'Geo', ids: ['vc-city', 'vc-country'] }],
labels: () => fetch('/api/uniform-context-labels').then((r) => r.json()),
});
const unsubscribe = store.subscribe((state) => render(state));
store.getState();State
ToolbarState is recomputed on every change and holds everything a UI needs:
| Field | What it is |
| --------------------------------------------------- | ------------------------------------------------------------------------- |
| dimensionGroups | Scored dimensions, grouped: signals, enrichments per category, aggregates |
| inactiveDimensions | Manifest dimensions with no score yet |
| inactiveGroups | Those plus unset quirks, grouped like dimensionGroups — what Inactive renders |
| reveal | What the simulator set last and the group it landed in, so a UI can show it applying |
| quirkGroups | Quirks, in the configured groups |
| tests | A/B tests on the page, with variants and the current assignment |
| labels | Resolved display names (raw keys until something resolves them) |
| overrides, overrideCount | Simulated values, each with the value it replaced |
| controlGroup | Whether the visitor is in the personalization control group |
| connection, connectionStatus, connectionError | Uniform connection state |
Actions
Simulator — every change is a real Context storage command, so the app reacts as it would for a visitor who earned that state:
setScore / clearScore (modscoreS), setQuirk / clearQuirk (setquirk),
clearOverrides, toggleControlGroup (setcontrol), forget.
Aggregates are computed from their inputs and bare enrichment categories have no value
to attach a score to — neither is settable. Callers should not offer an editor for them;
both shipped UIs check type and the presence of _ in the key.
A/B tests — registerTest(name, variantIds) declares what a rendered placement can
show (the manifest lists test names but not their variants), and setTestVariant forces
one. Tests that never register are still listed from their testResult event, with only
the assigned variant.
Connect — connect({ projectId, apiKey }), disconnect(), refreshLabels().
Verifies Manifest Read (published manifest) and Context → Read Drafts (preview
manifest) before saving anything. Friendly names are resolved afterwards from the
definition APIs. Use a read-only key with those two permissions.
Also exported
buildDimensionRows, groupDimensions, buildActiveDimensionGroups,
buildInactiveDimensionRows, buildQuirkGroups, clampPercent,
listManifestDimensions — the pure shaping helpers, if you only want those.
ENTITY_ICON_PATHS — the css.gg icon paths the Uniform dashboard uses, keyed by entity
kind, so any UI can draw the same marks.
