@manablox/nuxt
@manablox/nuxt
Show your Manablox content in a Nuxt site, with live preview from the admin built in.
The module sets up the @manablox/public-sdk client for you, adds composables to load
content and components to render blocks, and turns a /preview page into the canvas of
the visual editor.
Install
npm install @manablox/nuxt
Usage
With a project made by manablox create running locally, the defaults already point at
it: content comes from the public API on http://localhost:3100 and the preview accepts
the admin on http://localhost:3000. Otherwise set the addresses:
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@manablox/nuxt'],
manablox: {
url: 'https://content.example.com',
preview: { editorOrigin: 'https://cms.example.com' },
},
});
<!-- pages/[...slug].vue -->
<script setup lang="ts">
const { data: page } = await useManabloxPage('... on Page { components }');
</script>
<template>
<h1>{{ page?.title }}</h1>
<ManabloxBlocks :blocks="page?.components" />
</template>
<ManabloxBlocks> renders each block with a component named after its type: a block of
type teaser renders your <BlockTeaser> component.
Options
| Option | Default | Meaning |
|---|---|---|
url |
$MANABLOX_URL, else http://localhost:3100 |
The address of your public delivery API |
spaceId |
$MANABLOX_SPACE_ID, else none |
Only needed when you read from a management API, which returns nothing without it. A public API ignores it |
locale |
en |
The language to read |
transport |
graphql |
graphql or rest. Only a public API serves rest |
apiKey |
none | An API key for server-side code you write yourself. It is never sent to the browser |
cache |
{ ttl: 1000, max: 100 } |
The client's request cache: ttl in milliseconds, max entries. false turns it off; identical requests running at the same time are still sent once |
preview.enabled |
true |
Set false and <ManabloxPreview> no longer connects to the editor |
preview.route |
/preview |
Only recorded in the runtime config. The admin always opens the space's Frontend URL plus /preview, so keep your preview page there |
preview.editorOrigin |
$MANABLOX_ADMIN_ORIGIN, else http://localhost:3000 |
The address of the admin. The preview only accepts messages from there |
The environment variables are read when Nuxt builds or starts in development. To change
an address on a built site, set NUXT_PUBLIC_MANABLOX_URL,
NUXT_PUBLIC_MANABLOX_SPACE_ID or NUXT_PUBLIC_MANABLOX_PREVIEW_EDITOR_ORIGIN when you
start it.
Composables
useManablox(): the SDK client, already configured. Every call in one app returns the same client, and on the server each request gets its own, so its cache is never shared between visitors.useManabloxPage(selection)oruseManabloxPage({ selection, expand }): loads the document for the current URL. Works with server-side rendering.selectionpicks the GraphQL fields and is ignored onrest.expandlists the image and relation fields to deliver whole onrest, for example['hero', 'author']; without it they arrive as ids. GraphQL resolves them anyway.useManabloxPreviewState(): the draft the editor is changing, set by<ManabloxPreview>while the page is open in the admin, elsenull. Read it anywhere, for example in a layout.
Components
<ManabloxBlocks :blocks="...">: renders a blocks field on its grid. Props:field,prefix(defaultBlock),grid,gap.<ManabloxPreview>: put it on your/previewpage. Its slot receives the draftdocumentand itsfields.
Requires Nuxt 4 or newer.
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 0.50.0 | ^3.0 | MIT | |
| 0.25.0 | ^3.0 | MIT | |
| 0.24.0 | ^3.0 | MIT | |
| 0.23.0 | ^3.0 | MIT | |
| 0.22.0 | ^3.0 | MIT | |
| 0.21.0 | ^3.0 | ||
| 0.20.0 | ^3.0 | ||
| 0.19.0 | ^3.0 | ||
| 0.18.0 | ^3.0 | ||
| 0.17.0 | ^3.0 | ||
| 0.16.0 | ^3.0 | ||
| 0.15.0 | ^3.0 | ||
| 0.14.0 | ^3.0 | ||
| 0.13.0 | ^3.0 | ||
| 0.12.0 | ^3.0 | ||
| 0.11.0 | ^3.0 | ||
| 0.10.0 | ^3.0 | ||
| 0.9.0 | ^3.0 | ||
| 0.8.0 | ^3.0 | ||
| 0.7.0 | ^3.0 | ||
| 0.6.0 | ^3.0 | ||
| 0.5.0 | ^3.0 | ||
| 0.4.0 | ^3.0 | ||
| 0.3.0 | ^3.0 | ||
| 0.2.0 | ^3.0 | ||
| 0.1.0 | ^3.0 |