Getting Started UI
A hands-on tour of window.__fluiddocs — the JavaScript interface injected on every
hosted FluidDocs page. Click Run ▶ on each card to call the API and see a visible
result. Every example runs in-place; no copy-paste required.
This page focuses only on the frontend SDK. For REST endpoints see
REST API docs; for the terminal client see the
CLI guide (fld).
window.__fluiddocs before your scripts run. Use the event bus to talk to the
dashboard, the store for reactive state, storage for per-user collections, and
floating zones for overlay UI.
Live event feed
This page registers a global listen handler on load. Every dispatch
(including from the examples below) appears here in real time.
Event bus
Publish/subscribe channel shared between your page and the surrounding FluidDocs shell.
dispatch(event)
dispatch({ type, payload })
Emit a custom event. Watch it appear in the live feed above.
listen(handler, label?)
listen(handler, label?) → unsubscribe
Subscribe to the next matching event, then auto-unsubscribe. Dispatches a trigger event immediately.
sendMessage(target, message)
sendMessage('viewer' | 'builder', message)
Shorthand for viewer.chat.send_message or builder.chat.send_message. On a published page this opens/sends to the viewer chatbot when enabled.
Store
Reactive snapshot of page context and view settings. Subscribe for live updates.
getState()
getState() → FluidDocsStore
Read the full store snapshot. Key fields: pageContext, view, libraries.
subscribe(listener)
subscribe(listener) → unsubscribe
First click starts a live subscription. Tick store patches demo data and the output updates automatically.
_patchState(partial)
_patchState(partial)
Deep-merge a partial update. Internal API — libraries and platform code use this. Demo writes to view.content.gsuiDemo.
Builder panels
Open left and right sidebar panels in the FluidDocs preview / builder shell.
From a content page pass content: null — the dashboard renders the panel chrome;
your page only controls title, width, and tab slots.
setPanel(config)
setPanel({ side, title?, width?, id?, content })
Open or update a panel on the left or right. Use id to add tabs on the same side.
closePanel(side, tabId?)
closePanel('left' | 'right', tabId?)
Close an entire side, or one tab when tabId is set.
showPanelTab(side, tabId)
showPanelTab(side, tabId)
Opens two tabs on the right, then switches to the second tab. Watch the preview sidebar tabs change.
clearPanels()
clearPanels()
Closes all panels on both sides.
showToast(message, opts?)
showToast(message, { variant?, actionLabel?, actionUrl? })
Show a toast in the dashboard chrome. In preview, look at the top of the builder window — not inside the page iframe.
Floating zones
Mount DOM elements into named overlay zones on the page canvas.
addFloatingElement · removeFloatingElement · moveFloatingElement
Adds an orange pill to the page. Move it between zones or dismiss it. Look at the page corners while running these.
Storage
Per-user collection CRUD via fd.storage. Entries are scoped to the current visitor
unless you pass { sudo: true } (doc owner / org member only).
storage.set(id, data)
storage.set(null, data) → entry
Create or update a collection entry. Pass null as id to create.
storage.list(filter?)
storage.list({ type }) → entries[]
List your entries for this page. Results render below and populate the get/delete picker.
storage.get(id)
storage.get(id) → entry
storage.delete(id)
storage.delete(id)
Frontend tools
Register tools the builder or visitor chatbot can invoke in the browser. Use registerTools("builder", …) for owner preview chat and registerTools("viewer", …) for the visitor widget.
registerTools(target, tools)
registerTools("viewer", [{ name, handler, … }])
Registers an echo visitor tool, then simulates a handler call so you see the result on the event bus.
getViewerTools()
getViewerTools() → tools[]
subscribeViewerTools(listener)
subscribeViewerTools(listener) → unsubscribe
Starts a subscription, then registers a new tool so the listener fires.
Chat channels
Register an extra builder chat tab from library code (preview iframe → parent admin panel). Frontend tools use registerTools above — not this API.
registerChatChannel(config)
registerChatChannel({ id, label, jobsBase, … })
In preview mode, forwards registration to the parent frame via postMessage. On a standalone published page the call completes without error.
getRegisteredChats()
getRegisteredChats() → configs[]
On content pages, registrations are forwarded to the parent — this list is usually empty here. Useful in standalone / dashboard contexts.
Lifecycle
onReady(callback)
onReady(callback) → unsubscribe
Register a callback that runs when the page runtime is ready. If already ready, fires immediately.
hasCreditsAvailable()
hasCreditsAvailable() → boolean
Returns whether the doc owner has AI credits. Used to gate chat features on published pages.
Scripts & libraries
addScript(libId, url)
addScript(libId, url)
Loads a script tag. Demo uses an inline blob URL that sets window.__GSUI_SCRIPT_LOADED.
loadScripts(scripts)
loadScripts({ libId: [urls] })
Batch-load scripts from the store's view.scripts shape. Demo loads the same blob script under gs-ui-demo.
onLibUpdate(name, handler)
onLibUpdate(name, handler)
Subscribe to library config changes, then fire a demo update via _dispatchLibUpdate.
Dashboard-only helpers
getListeners() and getEventLog()
are available in the dashboard DevPanel console (labeled listeners + event log). Hosted pages use
simple listeners without IDs. sendMessage is primarily a dashboard shorthand — content
pages can dispatch viewer.chat.send_message directly (as shown above).
| Method | Available on | Notes |
|---|---|---|
getListeners() | Dashboard | Snapshot of labeled listeners for debugging |
getEventLog() | Dashboard | Last 200 dispatched events |
React / ReactDOM / components | Dashboard | Injected for library config modules |