cwa.admin
Controls admin edit mode and the component selection stack. Mostly used internally, but exposed for custom admin UIs.
cwa.admin.isEditing.value // boolean — whether the admin panel is open in edit mode
cwa.admin.toggleEdit(true) // open edit mode
cwa.admin.toggleEdit(false) // close edit mode
cwa.admin.toggleEdit() // toggle
cwa.admin.emptyStack() // clear the selected component stack
cwa.admin.emitRedraw() // force re-render of the component overlay
Event Bus
cwa.admin.eventBus is a global mitt emitter that the admin uses to coordinate between the resource manager, the focus overlay, and the components on the page.
const cwa = useCwa()
const onSelect = (iri: string) => console.log('selected', iri)
onMounted(() => cwa.admin.eventBus.on('selectResource', onSelect))
onBeforeUnmount(() => cwa.admin.eventBus.off('selectResource', onSelect))
The full surface is mitt's — on, off, emit, the '*' wildcard, and the raw all handler Map. There is no once, and on() returns nothing rather than an unsubscribe function, so keep a reference to your handler and pass the same function to off(). Calling off(type) with no handler removes every listener for that event, including the module's own.
Events
| Event | Payload | Fired when |
|---|---|---|
manageableComponentMounted | string — resource IRI | A component using the resource manager mounts. |
componentMounted | string — resource IRI | A component mounts with the manager disabled, a placeholder or hotspot mounts, or a parent re-emits as the mount cascades up the tree. |
selectResource | string — resource IRI | A resource should become the admin's selection — a newly added component, or an admin jumping to the component behind a page-data position. |
reorder | ReorderEvent | An admin changes a component's order, via the up/down buttons or by typing an order number. |
redrawFocus | undefined | The focus overlay needs redrawing — after mounts, on window resize, and when the manager opens or closes. Emit with no second argument. |
ReorderEvent is the one payload type the module exports:
import type { ReorderEvent } from '#cwa/admin/admin'
type ReorderEvent = {
positionIri: string
location: 'previous' | 'next' | number
}
A location of 'previous' or 'next' moves the position one step; a number sets an absolute position and is 1-based. Groups that aren't reordering ignore the event, so it is safe to broadcast.
Caveats
Beyond the "may change without notice" warning above, a few behaviours are easy to trip over:
- Mount events are admin-only.
manageableComponentMountedandcomponentMountedonly fire for signed-in admins. Don't build front-end behaviour on them — visitors will never see them. componentMountedpayloads aren't always resource IRIs. Placeholders and hotspots emit<iri>_placeholder, so don't feed the payload straight intogetResource()without checking.redrawFocusis throttled to 40ms. Emitting it in a tight loop won't produce a redraw per call.- The events map isn't exported. Handlers passed inline to
on()are still type-checked and narrowed correctly, and an unknown event name is a compile error — but to type a standalone handler you'll need to hand-write the signature ((iri: string) => void) or importReorderEvent.
Navigation Guard
The admin tracks unsaved changes and shows a confirmation dialog on navigate:
cwa.navigationDisabled.value // boolean
cwa.adminNavigationGuardFn // pass to router.beforeEach