JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 998
  • Score
    100M100P100Q112464F
  • License MIT

A Vue renderer for the Strapi's Blocks rich text editor. Compatible with Nuxt.

Package Exports

  • vue-strapi-blocks-renderer
  • vue-strapi-blocks-renderer/src/composables/index.ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vue-strapi-blocks-renderer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Vue Strapi Blocks Renderer

npm version npm downloads License PRs Welcome

Easily render the content of Strapi's new Blocks rich text editor in your Vue frontend.

Based on @strapi/blocks-react-renderer

Installation

Install the Blocks renderer and its peer dependencies:

npm install vue-strapi-blocks-renderer vue

Basic usage

After fetching your Strapi content, you can use the BlocksRenderer component to render the data from a blocks attribute. Pass the array of blocks coming from your Strapi API to the content prop:

import {
  useStrapiBlocks,
  type BlocksContent,
} from 'strapi-blocks-vue-renderer';

// Content should come from your Strapi API
const content: BlocksContent = [
  {
    type: 'paragraph',
    children: [{ type: 'text', text: 'A simple paragraph' }],
  },
];

const VNode = useStrapiBlocks({ content: content });
<template>
  <VNode />
</template>

Or

import { useStrapiBlocks as StrapiBlocks } from 'strapi-blocks-vue-renderer';
<template>
  <StrapiBlocks :content="content" :modifiers="modifiers" :blocks="blocks" />
</template>

Custom components

You can provide your own Vue components to the renderer, both for blocks and modifier. They will be merged with the default components, so you can override only the ones you need.

  • Blocks are full-width elements, usually at the root of the content. The available options are:
    • paragraph
    • heading (receives level)
    • list (receives format)
    • quote
    • code (receives plainText)
    • image (receives image)
    • link (receives url)
  • Modifiers are inline elements, used to change the appearance of fragments of text within a block. The available options are:
    • bold
    • italic
    • underline
    • strikethrough
    • code

To provide your own components, pass an object to the blocks and modifiers props of the renderer. For each type, the value should be a React component that will receive the props of the block or modifier. Make sure to always render the children, so that the nested blocks and modifiers are rendered as well.

import { h } from 'vue';

import {
  useStrapiBlocks,
  type BlocksComponents,
  type ModifiersComponents,
} from 'strapi-blocks-vue-renderer';

const userBlocks: BlocksComponents = {
  // Will include the class "mb-4" on all paragraphs
  paragraph: (props) => h('p', { class: 'mb-4' }, props.children),
};

const userModifier: ModifiersComponents = {
  // Will include the class "text-red" on all bold text
  bold: (props) => h('strong', { class: 'text-red' }, props.children),
};

const VNode = useStrapiBlocks({
  content: content,
  modifier: userModifier,
  blocks: userBlocks,
});