kirbyuse
kirbyuse adds the Kirby-specific layer on top of Vue: types for window.panel, composables for common Panel tasks and prop sets for fields and blocks.
kirbyuse 2 pairs with kirbyup 4 and Kirby 6. Kirby 4 and 5 plugins use kirbyuse 1 with kirbyup 3.
Installation
pnpm add -D kirbyuse@nextnpm install -D kirbyuse@nextyarn add -D kirbyuse@nextImports
The Composition API comes from vue, everything Kirby-specific from kirbyuse:
import { usePanel } from 'kirbyuse'
import { computed, ref } from 'vue'Panel Types
usePanel returns window.panel with types for every service:
import { usePanel } from 'kirbyuse'
const panel = usePanel()
panel.notification.success('Saved')
panel.dialog.open({ /* ... */ })
panel.view.reload()To type the global directly, import the package once in the entry file:
// src/index.js
import 'kirbyuse'
window.panel.notification.success('Types work')
// ^? (property) notification: PanelNotificationNo TypeScript required, the hints work in JavaScript files as well.
Composables
useContent gives reactive access to the content of the current view:
import { useContent } from 'kirbyuse'
import { watch } from 'vue'
const { currentContent, contentChanges, hasChanges, update } = useContent()
watch(hasChanges, (changed) => {
if (changed)
console.log('Unsaved changes')
})
update({ title: 'New title' })currentContent reflects the editor state including unsaved changes, contentChanges holds only the diff and update writes into it.
The kirbyuse API documents every composable with an example, and the README covers loading plugin assets on demand.
Prop Sets
kirbyuse/props exports the props Kirby passes to a component, so you spread them instead of copying them:
import { field } from 'kirbyuse/props'
defineProps({ ...field })The individual field props such as label, disabled and required are available as well.
Kirby Minimap, Kirby Content Translator and Kirby SERP Preview are plugins built with kirbyup and kirbyuse.