@ideacrafters/puck-vue
v0.1.0
Published
Vue 3 wrapper for Puck visual editor
Readme
@ideacrafters/puck-vue
Vue 3 wrapper for Puck - The visual editor for React
Features
- 🎯 Full TypeScript support
- 🔄 Two-way data binding with v-model
- 🎨 All Puck features available
- 📦 Composables for state management
- 🚀 Optimized React-Vue bridge
- 📱 Responsive viewport support
Installation
npm install @ideacrafters/puck-vue
# or
yarn add @ideacrafters/puck-vue
# or
pnpm add @ideacrafters/puck-vueQuick Start
<template>
<PuckEditor :config="config" :data="data" @change="handleChange" />
</template>
<script setup>
import { ref } from 'vue'
import { PuckEditor } from '@ideacrafters/puck-vue'
import '@ideacrafters/puck-vue/style.css'
const data = ref({ content: [], root: {} })
const config = {
components: {
HeadingBlock: {
render: ({ title }) => h('h1', title),
fields: {
title: { type: 'text' }
}
}
}
}
const handleChange = (newData) => {
data.value = newData
}
</script>Components
PuckEditor
The main editor component with full Puck functionality.
<template>
<PuckEditor
:config="config"
:data="data"
@change="handleChange"
@publish="handlePublish"
header-title="My Page Builder"
:viewports="viewports"
:height="600"
/>
</template>Props
config(Config) - Required. Puck configuration objectdata(Partial) - Initial data for the editoronChange(function) - Callback when data changesonPublish(function) - Callback when data is publishedonAction(function) - Callback for custom actionsheaderTitle(string) - Title for the editor headerheaderPath(string) - Path displayed in headerviewports(Array) - Responsive viewport configurationsheight(string | number) - Editor height (default: '100vh')width(string | number) - Editor width (default: '100%')plugins(Array) - Puck pluginsoverrides(Object) - Component overridesiframe(Object) - Iframe configurationdnd(Object) - Drag and drop configuration
Events
@change- Emitted when data changes@publish- Emitted when publish button is clicked@action- Emitted for custom actions
PuckPreview
Read-only component for rendering Puck data.
<template>
<PuckPreview :config="config" :data="data" />
</template>Props
config(Config) - Required. Puck configuration objectdata(Data) - Required. Data to render
Composables
usePuck
State management composable with history support.
import { usePuck } from '@ideacrafters/puck-vue'
const { data, isDirty, handleChange, handlePublish, undo, redo, reset, canUndo, canRedo } = usePuck(config, {
initialData: { content: [], root: {} },
onChange: (data) => console.log('Changed:', data),
onPublish: (data) => console.log('Published:', data)
})Options
initialData(Partial) - Initial dataonChange(function) - Change callbackonPublish(function) - Publish callback
Returns
data(Ref) - Current dataisDirty(Ref) - Whether data has unsaved changeshandleChange(function) - Handle data changeshandlePublish(function) - Handle publish actionundo(function) - Undo last changeredo(function) - Redo last undone changereset(function) - Reset to initial datacanUndo(Ref) - Whether undo is availablecanRedo(Ref) - Whether redo is available
Configuration
Create a Puck configuration object:
import type { Config } from '@ideacrafters/puck-vue'
const config: Config = {
components: {
HeadingBlock: {
render: ({ title, level = 1 }) => {
return h(`h${level}`, title)
},
fields: {
title: { type: 'text', label: 'Title' },
level: {
type: 'select',
label: 'Heading Level',
options: [
{ label: 'H1', value: 1 },
{ label: 'H2', value: 2 },
{ label: 'H3', value: 3 }
]
}
}
},
TextBlock: {
render: ({ text }) => h('p', text),
fields: {
text: { type: 'textarea', label: 'Text' }
}
}
}
}Viewports
Configure responsive viewports:
const viewports = [
{ width: 360, label: 'Mobile' },
{ width: 768, label: 'Tablet' },
{ width: 1280, label: 'Desktop' }
]Global Plugin Installation
import { createApp } from 'vue'
import PuckVue from '@ideacrafters/puck-vue'
const app = createApp(App)
app.use(PuckVue)After installation, components are available globally:
<template>
<div>
<puck-editor :config="config" :data="data" />
<puck-preview :config="config" :data="data" />
</div>
</template>Development
# Install dependencies
npm install
# Start playground
npm run dev
# Build library
npm run build
# Run tests
npm test
# Type check
npm run type-check
# Lint
npm run lintExamples
Check out the playground in the playground/ directory for a complete example.
Requirements
- Vue 3.3+
- Node.js 16+
License
MIT © Idea Crafters
Contributing
Contributions are welcome! Please read our Contributing Guide.
Support
- 📧 Email: [email protected]
- 🐛 Issues: GitHub Issues
- 📖 Documentation: GitHub Repository
