On this page

Editor field

The editor field contains a rich text editor that stores text content in HTML format.

Editor field

Examples

Here's an example of using the editor field in a block:

# blocks/Product.vue

<template>
  <PruviousHTML :html="description" />
</template>

<script lang="ts" setup>
import { editorField } from '#pruvious'

defineProps({
  description: editorField({
    label: 'Product description',
    placeholder: 'Enter a description',
    blockFormats: [{ className: 'p-6 border rounded', label: 'Boxed', tags: ['div'] }],
    inlineFormats: [{ className: 'text-red-500', label: 'Red' }],
    toolbar: ['bold', 'italic', 'heading2', 'heading3', 'paragraph', 'link', 'blockFormats', 'inlineFormats', 'clear'],
    required: true,
  }),
})
</script>

Here is another example of how to use it in a collection definition:

# collections/products.ts

import { defineCollection } from '#pruvious'

export default defineCollection({
  name: 'products',
  mode: 'multi',
  fields: {
    description: {
      type: 'editor',
      options: {
        label: 'Product description',
        placeholder: 'Enter a description',
        blockFormats: [{ className: 'p-6 border rounded', label: 'Boxed', tags: ['div'] }],
        inlineFormats: [{ className: 'text-red-500', label: 'Red' }],
        toolbar: [
          'bold',
          'italic',
          'heading2',
          'heading3',
          'paragraph',
          'link',
          'blockFormats',
          'inlineFormats',
          'clear',
        ],
        required: true,
      },
    },
    // ...
  },
})

Options

You can specify the following options in the editor field:

OptionDescription

allowFullscreen

Specifies whether to allow the editor to enter fullscreen mode. Defaults to true.

blockFormats

An array of objects that specifies the block formats to display in the toolbar. Block formats are used to specify CSS classes to be applied to the block element. They are displayed as a dropdown list in the toolbar.

default

The default field value (<p></p> if not defined).

description

A brief descriptive text displayed in code comments and in a tooltip at the upper right corner of the field.

inlineFormats

An array of objects that specifies the inline formats to display in the toolbar. Inline formats are used to specify CSS classes to be applied to the inline element. They are displayed as a dropdown list in the toolbar.

label

The field label displayed in the UI. By default, it is automatically generated based on the property name assigned to the field. For example, heroContent becomes Hero content.

placeholder

Text that appears in the input element when it has no value set.

required

Specifies that the field input is mandatory during creation, and the field value cannot be empty.

toolbar

An array of strings that specifies the toolbar buttons to display. The available buttons are as follows:

  • blockFormats

  • blockquote

  • bold

  • bulletList

  • center

  • clear

  • code

  • codeBlock

  • heading1

  • heading2

  • heading3

  • heading4

  • heading5

  • heading6

  • hardBreak

  • highlight

  • horizontalRule

  • inlineFormats

  • italic

  • justify

  • left

  • link

  • normalize

  • orderedList

  • paragraph

  • redo

  • right

  • strike

  • subscript

  • superscript

  • underline

  • undo

Last updated on January 7, 2024 at 16:17