@arevo/plugin-pagetree
v0.1.0
Published
A hierarchical page tree plugin for Payload CMS with drag-and-drop navigation
Downloads
62
Maintainers
Readme
Payload PageTree Plugin
A hierarchical page tree plugin for Payload CMS that provides a tree-based navigation interface for managing pages with parent-child relationships.
Features
- Tree-based collection view with expandable/collapsible nodes
- Automatic full path computation based on parent hierarchy
- Support for page groups (folders) and regular pages
- Drag-and-drop functionality for reorganizing pages
- Homepage (index page) designation
- Automatic slug generation from titles
- Child deletion protection
- Sorting within siblings
- REST API endpoints for tree operations
Installation
npm install @arevo/plugin-pagetree
# or
pnpm add @arevo/plugin-pagetree
# or
yarn add @arevo/plugin-pagetreeBasic Usage
Add the plugin to your payload.config.ts:
import { PageTree } from '@arevo/plugin-pagetree'
export default buildConfig({
plugins: [
PageTree({
collections: ['pages'], // Array of collection slugs to enable page tree for
}),
],
})Configuration
Plugin Options
type PageTreePluginOptions = {
/** Collections where the page tree replaces the list view */
collections: string[]
/** Optional: customize label for the left column */
treeLabel?: string
/** Disable the plugin */
disabled?: boolean
}Example with Options
import { PageTree } from '@arevo/plugin-pagetree'
export default buildConfig({
plugins: [
PageTree({
collections: ['pages', 'docs'],
treeLabel: 'Page Navigation',
disabled: false,
}),
],
})What It Does
The PageTree plugin automatically enhances your specified collections with:
Fields Added
fullPath(text): Auto-computed full path from parent + slugparent(relationship): Parent page or group (null = root)isGroup(checkbox): Marks pages as folders vs leavesisIndex(checkbox): Marks a page as the homepagesort(number): Order among siblings
Hooks Added
beforeValidate: Auto-generates slugs from titles if not providedbeforeChange: Computes full paths and manages sortingafterChange: Cascades path changes to all childrenbeforeDelete: Prevents deletion of pages with children
API Endpoints
The plugin adds two custom endpoints:
GET /api/pagetree/:collection/tree- Returns the full page treePOST /api/pagetree/:collection/move- Moves a page to a new parent/position
Admin UI
The plugin replaces the default list view with a custom tree view that allows:
- Expanding/collapsing nodes
- Creating child pages or groups
- Quick navigation to page editor
- Visual hierarchy display
Collection Requirements
Your collection should have at minimum:
- A
titlefield (orname,label, orhero.heading) - A
slugfield (will be auto-generated if missing) - A
layoutfield for non-group pages (optional, will be initialized as empty array)
Example collection:
const Pages: CollectionConfig = {
slug: 'pages',
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
name: 'slug',
type: 'text',
required: true,
unique: true,
},
{
name: 'layout',
type: 'blocks',
blocks: [
// your blocks here
],
},
// The plugin will add: fullPath, parent, isGroup, isIndex, sort
],
}Development
This plugin uses the standard Payload plugin structure.
Setup
- Clone the repository
- Install dependencies:
pnpm install - Copy
.env.exampleto.envand configure your database - Run the dev server:
pnpm dev
Testing
Run the test suite:
pnpm testRun integration tests:
pnpm test:intRun E2E tests:
pnpm test:e2eBuilding
Build the plugin for distribution:
pnpm buildThis will:
- Copy static assets
- Generate TypeScript declarations
- Compile source files with SWC
Publishing
The plugin is configured with semantic versioning and can be published to npm:
pnpm publishMake sure to:
- Update the version in
package.json - Build the plugin before publishing
- Test the built version
License
MIT
Support
For issues and feature requests, please use the GitHub issue tracker.
