Directus Expandable Blocks Interface
A powerful M2A (Many-to-Any) interface for Directus with inline expandable editing that seamlessly integrates with Directus’ native save system.
π Documentation
For comprehensive documentation, visit our GitHub Wiki which includes:
- Detailed installation guide
- Configuration options
- Architecture overview
- API integration guide
- Development & debugging
- Security best practices
- Migration guide
- And much more!
π― Why Expandable Blocks?
Unlike other block editors, this extension works directly with Directus’ native form system:
- β No custom API calls - Uses Directus’ built-in save/revert functionality
- β Native Save & Stay - Works perfectly with Directus’ save options
- β Global Discard - Integrates with Directus’ “Discard Changes” button
- β Proper Dirty State - Save button only appears when changes exist
- β No Data Loss - All changes tracked through Directus’ form state
This means you get all the benefits of a sophisticated block editor while maintaining full compatibility with Directus’ workflow!
β¨ Features
Core Interface
- Inline Expandable Editing: Edit block content directly without opening separate forms
- Drag & Drop Sorting: Reorder blocks with intuitive drag-and-drop
- Native Integration: Uses Directus’ save system - no custom API calls
- Smart Dirty State: Only sends changed blocks to the server
- Status Management: Quick status changes with visual indicators
- Visual Feedback: See which blocks have unsaved changes
- Compact & Full View Modes: Adaptive display options
- Keyboard Navigation: Full keyboard support
Advanced Functionality
- Nested M2A Support: Handle complex nested relationships
- Custom Field Filtering: Show only specific fields in edit mode
- Template System: Pre-configured content templates
- Status Management: Built-in content status workflows
π Coming Soon: AI-Powered Features
We’re actively developing AI integration features that will include:
- AI Content Generation: Generate content using OpenAI GPT, Claude, or custom APIs
- Smart Content Improvement: Grammar, style, clarity, and SEO optimization
- Multi-Language Translation: Instant translation to multiple languages
- Context-Aware Suggestions: AI that understands your page structure
- Field-Specific Targeting: Generate content for specific fields only
π‘ Early Access: AI features are currently in development on the
feature/ai-assistant
branch. Follow our GitHub repository for updates!
Configuration Options
- Enable/disable sorting
- Show/hide item IDs
- Accordion mode (one block expanded at a time)
- Compact display mode
- Maximum block limits
- Custom field filtering
π¦ Installation
Via NPM (Recommended)
Install directly from the npm registry:
npm install directus-extension-expandable-blocks
The extension will be automatically loaded by Directus when you restart your instance.
Manual Installation
- Download the latest release from GitHub Releases
- Extract to your Directus
extensions/interfaces/
directory - Restart Directus
Docker Installation
For Docker setups, install via npm in your Dockerfile or mount the extension directory:
RUN npm install directus-extension-expandable-blocks
# or mount volume: -v ./extensions:/directus/extensions
π Usage
Basic Setup
1οΈβ£ Create an M2A (Many-to-Any) Field
- Navigate to Settings β Data Model β [Your Collection]
- Click “Create Field” button
- Choose “Many to Any Relationship (M2A)” field type
- Configure the relationship:
- Field Key: e.g.,
content_blocks
- Related Collections: Select which collections can be used as blocks
- Field Key: e.g.,
2οΈβ£ Select the Expandable Blocks Interface
- In the field configuration, go to the “Interface” tab
- Click on the interface dropdown (default is “Many to Any”)
- Select “Expandable Blocks” from the list
- The interface will change to show expandable blocks options
3οΈβ£ Configure Interface Options
In the interface configuration panel, you can set:
-
Display Options
- β Enable Sorting - Allow drag & drop reordering
- π Start Expanded - Blocks open by default
- π― Accordion Mode - Only one block open at a time
- π± Compact Mode - Condensed view for many blocks
-
Permissions
- ποΈ Allow Delete - Users can remove blocks
- π Allow Duplicate - Users can copy blocks
- π’ Max Blocks - Limit number of blocks (empty = unlimited)
4οΈβ£ Save and Use
- Click “Save” to apply the configuration
- Navigate to your collection items
- The M2A field will now use the Expandable Blocks interface!
Example M2A Structure
# Main Collection (e.g., "pages")
Page Collection:
- id: primary key
- title: string
- slug: string
- content_blocks: M2A field β Uses "Expandable Blocks" interface
- status: string
- date_created: timestamp
# Junction Collection (auto-created by Directus)
pages_blocks:
- id: primary key
- pages_id: foreign key β pages.id
- collection: string (which block type)
- item: foreign key β block item id
- sort: integer (for ordering)
# Block Collections (your content types)
content_text:
- id: primary key
- headline: string
- subheadline: string
- content: text (rich text editor)
- alignment: string
content_hero:
- id: primary key
- headline: string
- subheadline: string
- button_text: string
- button_link: string
- image: file (image)
- overlay: boolean
content_gallery:
- id: primary key
- title: string
- images: O2M β gallery_images
- columns: integer
- spacing: string
Visual Guide
-
Creating M2A Field
- Select M2A relationship type
- Configure related collections
-
Selecting Interface
- Change from default “Many to Any”
- Select “Expandable Blocks”
-
Interface in Action
- Inline editing capability
- Drag & drop sorting
- Visual status indicators
π§ How It Works
Native Save Integration
The extension integrates seamlessly with Directus’ form system:
// Traditional approach (what we DON'T do):
async function saveBlock(block) {
await api.post('/items/content_blocks', block) // β Custom API call
await refreshData() // β Manual sync
updateUI() // β Manual UI update
}
// Our approach (native integration):
function handleBlockChange(blocks) {
emit('input', blocks) // β
Let Directus handle everything
}
Smart Change Detection
Only modified blocks are sent to the server:
// Example: 3 blocks, only middle one edited
[
"block-1-id", // β
Unchanged - send ID only
{ id: "block-2-id", title: "New" }, // β
Changed - send full object
"block-3-id" // β
Unchanged - send ID only
]
This means:
- π Faster saves - Less data transmitted
- π‘οΈ Conflict prevention - Unchanged blocks aren’t touched
- π Better performance - Server processes only what changed
βοΈ Configuration Options
Option | Type | Default | Description |
---|---|---|---|
enableSorting |
boolean | true |
Allow drag & drop reordering |
showItemId |
boolean | true |
Display item IDs in headers |
startExpanded |
boolean | false |
Start with all blocks expanded |
accordionMode |
boolean | false |
Only one block expanded at a time |
compactMode |
boolean | false |
Use compact display |
maxBlocks |
number | null |
Maximum number of blocks |
isAllowedDelete |
boolean | true |
Allow block deletion |
isAllowedDuplicate |
boolean | true |
Allow block duplication |
π§ͺ Testing
The extension includes comprehensive test coverage:
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:coverage
# Watch mode
npm run dev
π Development
# Install dependencies
npm install
# Development build with watching
npm run dev
# Production build
npm run build
# Link for local development
npm run link
π Architecture Documentation
For detailed information about the data flow, state management, and debugging techniques, see our comprehensive Architecture Documentation. This includes:
- Complete data flow lifecycle with visual diagrams
- Detailed state management explanations
- Store interactions and timing
- Debugging techniques and helpers
- Common issues and solutions
- Performance optimization tips
π€ Contributing
We welcome contributions! Please see our Contributing Guide for details on:
- Development setup
- Testing procedures
- Pull request process
- Code standards
- Issue templates
π License
MIT License - see LICENSE file for details
π Issues & Support
Report issues on GitHub Issues
π Changelog
See CHANGELOG.md for detailed version history.
πΊοΈ Roadmap
Check out our Development Roadmap to see what’s coming next:
- π€ AI-Powered Content Generation (v1.1.0)
- π¨ Enhanced UI/UX Features
- π§ Developer Tools & CLI
- π Performance Optimizations
π Documentation
π Wiki Documentation
For comprehensive documentation, visit our GitHub Wiki:
- π Getting Started - Overview and quick start
- π¦ Installation Guide - Detailed setup instructions
- βοΈ Configuration - All configuration options
- ποΈ Architecture - Technical deep dive
- πΎ Data Flow - State management explained
- π API Integration - Working with Directus APIs
- π οΈ Development - Developer guide
- π‘ Examples - Practical use cases
π Quick Links
- π€ Contributing - How to contribute
- πΊοΈ Roadmap - Future plans
- π Changelog - Version history
π Issue Templates
Made with β€οΈ for the Directus community