An open API service indexing awesome lists of open source software.

https://github.com/smartlabsat/directus-expandable-blocks

Advanced M2A interface for Directus with inline expandable editing, drag & drop sorting, and native save integration - no custom API calls needed
https://github.com/smartlabsat/directus-expandable-blocks

block-editor cms content-blocks content-management directus directus-extension directus-interface drag-and-drop inline-editing m2a typescript vue3 vuedraggable

Last synced: about 1 month ago
JSON representation

Advanced M2A interface for Directus with inline expandable editing, drag & drop sorting, and native save integration - no custom API calls needed

Awesome Lists containing this project

README

          

# Directus Expandable Blocks Interface

[![npm version](https://img.shields.io/npm/v/directus-extension-expandable-blocks?style=flat-square&color=blue)](https://www.npmjs.com/package/directus-extension-expandable-blocks)
[![npm downloads](https://img.shields.io/npm/dm/directus-extension-expandable-blocks?style=flat-square)](https://www.npmjs.com/package/directus-extension-expandable-blocks)
[![GitHub release](https://img.shields.io/github/release/smartlabsAT/directus-expandable-blocks?style=flat-square)](https://github.com/smartlabsAT/directus-expandable-blocks/releases)
[![license](https://img.shields.io/npm/l/directus-extension-expandable-blocks?style=flat-square)](https://github.com/smartlabsAT/directus-expandable-blocks/blob/master/LICENSE)
[![Directus 11+](https://img.shields.io/badge/Directus-11%2B-64f?style=flat-square&logo=directus)](https://directus.io)
[![Tests](https://img.shields.io/badge/tests-470%20passing-success?style=flat-square)](https://github.com/smartlabsAT/directus-expandable-blocks)
[![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)

A powerful, production-ready M2A (Many-to-Any) interface extension for Directus with inline expandable editing, advanced item selection, comprehensive permissions, and seamless integration with Directus' native save system. **Also provides reusable ItemSelector components for other extensions.**

![Directus Expandable Blocks Extension - Feature Presentation](https://raw.githubusercontent.com/wiki/smartlabsAT/directus-expandable-blocks/assets/demo.gif)

[๐Ÿ“š Documentation](https://github.com/smartlabsAT/directus-expandable-blocks/wiki) โ€ข
[๐Ÿ› Report Bug](https://github.com/smartlabsAT/directus-expandable-blocks/issues/new?template=bug_report.md) โ€ข
[โœจ Request Feature](https://github.com/smartlabsAT/directus-expandable-blocks/issues/new?template=feature_request.md) โ€ข
[๐Ÿ“ฆ NPM Package](https://www.npmjs.com/package/directus-extension-expandable-blocks)

## ๐Ÿ“– Table of Contents

- [Why Expandable Blocks?](#-why-expandable-blocks)
- [Features](#-features)
- [Installation](#-installation)
- [Usage](#-usage)
- [Configuration](#๏ธ-configuration)
- [Shared Components](#-shared-components-for-other-extensions)
- [Testing](#-testing)
- [Development](#-development)
- [Documentation](#-documentation)
- [Contributing](#-contributing)
- [License](#-license)

## ๐ŸŽฏ Why Expandable Blocks?

Unlike other block editors, this extension **works directly with Directus' native form system** and provides **unique killer features**:

### ๐Ÿš€ Killer Features
- ๐Ÿ” **Reference Tracking** - See EVERYWHERE an item is used across your entire system
- ๐Ÿ”— **Link or Copy** - Choose to reference existing items or create independent copies
- โš ๏ธ **Usage Protection** - Never accidentally delete content that's used elsewhere

### โœ… Native Integration
- **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
- **Enterprise Ready** - Production-tested with comprehensive permissions
- **100% Test Coverage** - 470 unit tests ensuring reliability

## โœจ Features

### ๐ŸŽจ Core Interface Features

#### **Block Management**
- ๐Ÿ“ **Inline Expandable Editing** - Edit content without opening separate forms
- ๐ŸŽฏ **Drag & Drop Sorting** - Intuitive block reordering with visual feedback
- ๐Ÿ†• **Visual NEW Indicator** - See unsaved blocks at a glance
- ๐Ÿ“Š **Status Management** - Quick status changes with color-coded indicators
- ๐Ÿ“‹ **Duplicate Blocks** - Clone existing blocks with one click
- ๐Ÿ—‘๏ธ **Smart Delete** - Unlink or permanently delete with confirmation
- ๐Ÿ”„ **Discard Changes** - Revert individual blocks to original state

#### **Item Selection & Search**
- ๐Ÿ” **Advanced Item Selector** - Select and link existing items from any collection
- ๐Ÿ”— **Link or Copy Mode** - Choose to reference existing items or create copies
- ๐Ÿ“Š **Table View** - Browse items in a sortable, filterable table
- ๐Ÿท๏ธ **Tag-Based Search** - Search with AND/OR operators and field-specific queries
- ๐ŸŽฏ **Smart Search** - Simple search mode with optional advanced tag search
- ๐Ÿ”Ž **Search Highlighting** - See matching terms highlighted in results
- ๐Ÿ“Œ **Search History** - Remember and reuse previous searches
- ๐Ÿ“ˆ **Result Count** - See number of matching items instantly

#### **Table Features**
- ๐Ÿ“Š **Intelligent Columns** - Auto-sizing based on field types
- ๐Ÿ“Œ **Sticky Columns** - Keep important columns visible while scrolling
- โ†•๏ธ **Sortable Headers** - Sort by any field with 3-click cycle
- ๐ŸŽจ **Field Display** - Smart rendering for all Directus field types
- ๐Ÿ–ผ๏ธ **Image Preview** - Hover to see full images
- ๐Ÿ“ **WYSIWYG Support** - Automatic HTML stripping for clean display
- โšก **Virtual Scrolling** - Handle thousands of items efficiently

### ๐ŸŒ Advanced Features

#### **Translation Support**
- ๐ŸŒ **Multi-Language** - Full support for Directus translations
- ๐Ÿ”„ **Language Switching** - Change languages on the fly
- ๐Ÿ” **Translation Search** - Search across all language versions
- ๐Ÿท๏ธ **Language Indicators** - See which fields are translatable

#### **Permissions & Security**
- ๐Ÿ” **Directus Permissions** - Respects all native permissions
- ๐Ÿ‘ฅ **Role-Based Control** - Configure per-role access
- ๐Ÿ”’ **Read-Only Mode** - Automatic for restricted items
- โš ๏ธ **Permission Indicators** - Visual feedback for restricted actions
- ๐Ÿ›ก๏ธ **Security** - Built-in validation and permission checks

#### **Usage Tracking & References** ๐Ÿš€ *(Requires API Extension)*
- ๐Ÿ” **Reference Detection** - Instantly see ALL places where an item is used across your entire Directus instance
- ๐Ÿ“ **Cross-Collection References** - Track usage across different collections and relationships
- ๐Ÿ”— **Deep Links** - Navigate directly to parent items with one click
- โš ๏ธ **Usage Warnings** - Get alerts before deleting items that are referenced elsewhere
- ๐Ÿ“Š **Usage Paths** - Visual breadcrumbs showing complete relationship chains
- ๐ŸŽฏ **Smart Prevention** - Prevents accidental deletion of referenced content

> **Note:** These features require the optional [API extension](https://www.npmjs.com/package/directus-extension-expandable-blocks-api) to be installed.

#### **Inline Editing**
- โœ๏ธ **Edit Drawer** - Edit items without leaving the interface
- ๐Ÿ’พ **Independent Saves** - Save edits without affecting main form
- ๐Ÿ”„ **Live Updates** - See changes reflected immediately
- ๐Ÿ“ **Adjustable Width** - Resize drawer to your preference

### โšก Performance & Quality

#### **Performance**
- ๐Ÿš€ **Multi-Layer Caching** - Configurable TTLs for optimal speed
- ๐Ÿ“Š **Smart Loading** - Load only what's needed
- ๐Ÿ”„ **Debounced Operations** - Prevent excessive API calls
- โšก **Optimized Re-renders** - Using Vue 3's advanced features
- ๐Ÿ’พ **Persistent Preferences** - Remember user settings

#### **Code Quality**
- โœ… **100% Test Coverage** - 470 passing unit tests
- ๐ŸŽฏ **TypeScript Strict Mode** - Zero type errors
- ๐Ÿ“ **ESLint Compliant** - Zero linting errors
- ๐Ÿ—๏ธ **Modular Architecture** - 15+ reusable components
- ๐Ÿ“š **Comprehensive Docs** - Wiki, API docs, and inline comments

### ๐Ÿ› ๏ธ Developer Features

#### **Extension Architecture**
- ๐Ÿ“ฆ **Interface Extension** - Clean, focused interface implementation
- ๐Ÿ”Œ **Composable Architecture** - Reusable Vue composables
- ๐ŸŽจ **Component Library** - Modular, tested components
- ๐Ÿ”ง **Utility Functions** - Shared helpers and validators
- ๐Ÿ“ **TypeScript Types** - Full type definitions

## ๐Ÿ“ฆ Installation

### Via NPM (Recommended)

```bash
# Install the interface extension
npm install directus-extension-expandable-blocks

# Optional: Install the API extension for advanced usage tracking
npm install directus-extension-expandable-blocks-api
```

### Via pnpm

```bash
# Install the interface extension
pnpm add directus-extension-expandable-blocks

# Optional: Install the API extension for advanced usage tracking
pnpm add directus-extension-expandable-blocks-api
```

### Manual Installation

1. Download the latest release from [GitHub Releases](https://github.com/smartlabsAT/directus-expandable-blocks/releases)
2. Extract to your Directus `extensions/` directory
3. Restart Directus
4. **Optional**: Install the [API extension](https://github.com/smartlabsAT/directus-expandable-blocks-api) for usage tracking

### Docker Installation

```dockerfile
# Install the interface extension
RUN npm install directus-extension-expandable-blocks

# Optional: Install the API extension for advanced usage tracking
RUN npm install directus-extension-expandable-blocks-api
```

### ๐Ÿ“ Important Note About the API Extension

**The API extension is now a separate, optional package.** The core Expandable Blocks interface works perfectly without it, using Directus' native API for all standard operations.

#### When to install the API extension:
- โœ… You want to see where items are used before deleting them
- โœ… You need to track references across M2A relationships
- โœ… You want protection against accidentally deleting referenced content

#### The interface works without the API extension:
- โœ… All core features (editing, sorting, adding blocks) work normally
- โœ… Uses native Directus API for all operations
- โš ๏ธ Cannot verify item usage before deletion (shows warning instead)

## ๐Ÿš€ Usage

### Basic Setup

#### 1๏ธโƒฃ Create an M2A Field

1. Navigate to **Settings โ†’ Data Model โ†’ [Your Collection]**
2. Click **"Create Field"**
3. Choose **"Many to Any Relationship (M2A)"**
4. Configure the relationship

#### 2๏ธโƒฃ Select the Expandable Blocks Interface

1. In the field configuration, go to **"Interface"** tab
2. Select **"Expandable Blocks"** from the dropdown
3. Configure your options

#### 3๏ธโƒฃ Configure Options

The interface provides extensive configuration grouped into logical sections:

- **Display Options** - Visual preferences
- **Permissions & Actions** - What users can do
- **Collections & Relations** - Available collections
- **Advanced Settings** - Caching, translations, etc.

## โš™๏ธ Configuration

### Display Settings

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `enableSorting` | boolean | `true` | Enable drag & drop reordering |
| `showItemId` | boolean | `true` | Display item IDs |
| `showCollectionName` | boolean | `true` | Show collection type |
| `startExpanded` | boolean | `false` | Start with blocks expanded |
| `accordionMode` | boolean | `false` | One block open at a time |
| `compactMode` | boolean | `false` | Condensed view |

### Permissions

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `isAllowedDelete` | boolean | `true` | Allow deletion |
| `isAllowedDuplicate` | boolean | `true` | Allow duplication |
| `allowLinkExisting` | boolean | `true` | Allow linking existing |
| `allowDuplicateExisting` | boolean | `true` | Allow duplicating linked |
| `maxBlocks` | number | `null` | Maximum blocks allowed |

### Collections

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `collection` | array | `[]` | Collections for new blocks |
| `allowedCollectionsExisting` | array | `[]` | Collections for existing items |

### Advanced

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `enableCache` | boolean | `true` | Enable API caching |
| `enableTranslations` | boolean | `true` | Support translations |
| `showUsageWarnings` | boolean | `true` | Show usage indicators |

### Environment Variables

Configure caching behavior:

```bash
# Cache TTL Settings (in minutes)
EXPANDABLE_BLOCKS_CACHE_TTL_METADATA=30
EXPANDABLE_BLOCKS_CACHE_TTL_SEARCH=5
EXPANDABLE_BLOCKS_CACHE_TTL_DETAIL=10
EXPANDABLE_BLOCKS_CACHE_TTL_PATHS=10

# Maximum cache size
EXPANDABLE_BLOCKS_CACHE_MAX_SIZE=50000
```

## ๐Ÿ”— Shared Components for Other Extensions

This extension provides **reusable ItemSelector components** that can be used in other Directus extensions, allowing you to avoid code duplication and maintain consistent UX across extensions.

### Quick Start for Extension Developers

```bash
# Add as dependency to your extension
npm install directus-extension-expandable-blocks
```

```typescript
// Import shared components in your extension
import {
useItemSelector,
ItemSelectorDrawer,
type ItemSelectorConfig
} from 'directus-extension-expandable-blocks/shared';

// Configure for your extension
const itemSelector = useItemSelector(api, ['pages', 'articles'], {
loggerPrefix: '[MyExtension]',
allowLink: true,
allowDuplicate: false,
collectionIcons: {
'pages': 'description',
'articles': 'article'
}
});
```

### Available Shared Components

- **`useItemSelector`** - Core composable with all functionality
- **`ItemSelectorDrawer`** - Main selector interface
- **`ItemSearchPanel`** - Advanced search with operators
- **`FieldDisplay`** - Field value display component
- **`UsagePopover`** - Shows item usage across collections

### Configuration Options

```typescript
interface ItemSelectorConfig {
loggerPrefix?: string; // Custom logging prefix
allowLink?: boolean; // Allow linking items
allowDuplicate?: boolean; // Allow duplicating items
defaultItemsPerPage?: number; // Pagination size
defaultLanguage?: string; // Translation language
collectionIcons?: Record; // Custom icons
fieldMappings?: Record; // Field name mappings
debug?: boolean; // Enable debug logging
}
```

### Full Documentation

๐Ÿ“– **[Complete Shared Components Documentation](SHARED_COMPONENTS.md)** - Detailed usage guide, examples, and API reference for extension developers.

### Example Usage in LayoutBlocks Extension

```vue

import { useItemSelector, ItemSelectorDrawer } from 'directus-extension-expandable-blocks/shared';

const itemSelector = useItemSelector(api, ['layouts'], {
loggerPrefix: '[LayoutBlocks]',
allowDuplicate: false
});

```

## ๐Ÿงช Testing

```bash
# Run all tests (100% coverage)
npm run test -- --run

# Test with UI
npm run test:ui

# Coverage report
npm run test:coverage

# Type checking
npm run type-check

# Linting
npm run lint
```

### Test Statistics
- โœ… **470 unit tests** - All passing
- โœ… **100% coverage** - Full test coverage
- โœ… **0 TypeScript errors** - Strict mode compliant
- โœ… **0 ESLint errors** - Clean code

## ๐Ÿ“ Development

```bash
# Install dependencies (we use pnpm)
pnpm install

# Development mode
npm run dev

# Production build
npm run build

# Type checking
npm run type-check

# Create demo videos
npm run demo:product
npm run demo:highlights
```

### Project Structure

```
expandable-blocks/
โ”œโ”€โ”€ config/ # Configuration files
โ”‚ โ”œโ”€โ”€ scripts/ # Build scripts
โ”‚ โ””โ”€โ”€ *.config.* # Various configs
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ components/ # Vue components
โ”‚ โ”œโ”€โ”€ composables/ # Vue composables
โ”‚ โ”œโ”€โ”€ types/ # TypeScript types
โ”‚ โ””โ”€โ”€ utils/ # Utilities
โ”œโ”€โ”€ test/ # Test files
โ””โ”€โ”€ wiki/ # Documentation
```

## ๐Ÿ“š Documentation

### Wiki Documentation

Visit our **[GitHub Wiki](https://github.com/smartlabsAT/directus-expandable-blocks/wiki)** for:

- ๐Ÿ  [Getting Started](https://github.com/smartlabsAT/directus-expandable-blocks/wiki)
- ๐Ÿ“ฆ [Installation Guide](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Installation)
- โš™๏ธ [Configuration](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Configuration)
- ๐Ÿ—๏ธ [Architecture](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Architecture-Overview)
- ๐Ÿ” [Security](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Security)
- ๐Ÿš€ [Advanced Features](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Advanced-Features)
- ๐ŸŽฌ [Demo Videos](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Demo-Video-Recording)
- โšก [Cache Configuration](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Cache-Configuration)

## ๐Ÿค Contributing

We welcome contributions! Please see our [Contributing Guide](https://github.com/smartlabsAT/directus-expandable-blocks/wiki/Contributing) for details.

## ๐Ÿ“„ License

MIT License - see [LICENSE](LICENSE) file for details

## ๐Ÿ™ Acknowledgments

Made with โค๏ธ for the Directus community

## ๐Ÿ† Stats

- **200+ commits** of continuous improvement
- **15+ components** for modular architecture
- **470 tests** ensuring reliability
- **0 errors** in TypeScript and ESLint
- **100% coverage** for peace of mind

---

**Ready for production use!** ๐Ÿš€