Skip to content

Commit 529ec71

Browse files
Copilothotlong
andcommitted
Create plugin-markdown and plugin-kanban packages with lazy loading
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 5663015 commit 529ec71

14 files changed

Lines changed: 1063 additions & 0 deletions

File tree

packages/plugin-kanban/README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Plugin Kanban - Lazy-Loaded Kanban Board
2+
3+
A lazy-loaded kanban board component for Object UI based on @dnd-kit for drag-and-drop functionality.
4+
5+
## Features
6+
7+
- **Internal Lazy Loading**: @dnd-kit libraries are loaded on-demand using `React.lazy()` and `Suspense`
8+
- **Zero Configuration**: Just import the package and use `type: 'kanban'` in your schema
9+
- **Automatic Registration**: Components auto-register with the ComponentRegistry
10+
- **Skeleton Loading**: Shows a skeleton while @dnd-kit loads
11+
- **Drag and Drop**: Full drag-and-drop support for cards between columns
12+
- **Column Limits**: Set maximum card limits per column
13+
- **Customizable**: Badge support, custom styling, and callbacks
14+
15+
## Installation
16+
17+
```bash
18+
pnpm add @object-ui/plugin-kanban
19+
```
20+
21+
## Usage
22+
23+
### Automatic Registration (Side-Effect Import)
24+
25+
```typescript
26+
// In your app entry point (e.g., App.tsx or main.tsx)
27+
import '@object-ui/plugin-kanban';
28+
29+
// Now you can use kanban type in your schemas
30+
const schema = {
31+
type: 'kanban',
32+
columns: [
33+
{
34+
id: 'todo',
35+
title: 'To Do',
36+
cards: [
37+
{ id: '1', title: 'Task 1', description: 'Description' }
38+
]
39+
},
40+
{
41+
id: 'done',
42+
title: 'Done',
43+
cards: []
44+
}
45+
]
46+
};
47+
```
48+
49+
### Manual Integration
50+
51+
```typescript
52+
import { kanbanComponents } from '@object-ui/plugin-kanban';
53+
import { ComponentRegistry } from '@object-ui/core';
54+
55+
// Manually register if needed
56+
Object.entries(kanbanComponents).forEach(([type, component]) => {
57+
ComponentRegistry.register(type, component);
58+
});
59+
```
60+
61+
### TypeScript Support
62+
63+
The plugin exports TypeScript types for full type safety:
64+
65+
```typescript
66+
import type { KanbanSchema, KanbanCard, KanbanColumn } from '@object-ui/plugin-kanban';
67+
68+
const card: KanbanCard = {
69+
id: 'task-1',
70+
title: 'My Task',
71+
description: 'Task description',
72+
badges: [
73+
{ label: 'High Priority', variant: 'destructive' }
74+
]
75+
};
76+
77+
const column: KanbanColumn = {
78+
id: 'todo',
79+
title: 'To Do',
80+
cards: [card],
81+
limit: 5
82+
};
83+
84+
const schema: KanbanSchema = {
85+
type: 'kanban',
86+
columns: [column]
87+
};
88+
```
89+
90+
## Schema API
91+
92+
```typescript
93+
{
94+
type: 'kanban',
95+
columns?: KanbanColumn[], // Array of columns
96+
onCardMove?: (cardId, fromColumnId, toColumnId, newIndex) => void,
97+
className?: string // Tailwind classes
98+
}
99+
100+
// Column structure
101+
interface KanbanColumn {
102+
id: string;
103+
title: string;
104+
cards: KanbanCard[];
105+
limit?: number; // Maximum cards allowed
106+
className?: string;
107+
}
108+
109+
// Card structure
110+
interface KanbanCard {
111+
id: string;
112+
title: string;
113+
description?: string;
114+
badges?: Array<{
115+
label: string;
116+
variant?: 'default' | 'secondary' | 'destructive' | 'outline';
117+
}>;
118+
}
119+
```
120+
121+
## Features
122+
123+
- **Drag and Drop**: Drag cards between columns or reorder within a column
124+
- **Column Limits**: Set maximum card limits and get visual feedback when full
125+
- **Card Badges**: Add colored badges to cards for status/priority
126+
- **Responsive**: Horizontal scrolling for many columns
127+
- **Accessible**: Built on @dnd-kit with keyboard navigation support
128+
129+
## Lazy Loading Architecture
130+
131+
The plugin uses a two-file pattern for optimal code splitting:
132+
133+
1. **`KanbanImpl.tsx`**: Contains the actual @dnd-kit imports (heavy ~100-150 KB)
134+
2. **`index.tsx`**: Entry point with `React.lazy()` wrapper (light)
135+
136+
When bundled, Vite automatically creates separate chunks:
137+
- `index.js` (~200 bytes) - The entry point
138+
- `KanbanImpl-xxx.js` (~100-150 KB) - The lazy-loaded implementation
139+
140+
The @dnd-kit libraries are only downloaded when a `kanban` component is actually rendered, not on initial page load.
141+
142+
## Bundle Size Impact
143+
144+
By using lazy loading, the main application bundle stays lean:
145+
- Without lazy loading: +100-150 KB on initial load
146+
- With lazy loading: +0.19 KB on initial load, +100-150 KB only when kanban is rendered
147+
148+
This results in significantly faster initial page loads for applications that don't use kanban on every page.
149+
150+
## Development
151+
152+
```bash
153+
# Build the plugin
154+
pnpm build
155+
156+
# The package will generate proper ESM and UMD builds with lazy loading preserved
157+
```
158+
159+
## Example with Callbacks
160+
161+
```typescript
162+
const schema = {
163+
type: 'kanban',
164+
columns: [...],
165+
onCardMove: (cardId, fromColumnId, toColumnId, newIndex) => {
166+
console.log(`Card ${cardId} moved from ${fromColumnId} to ${toColumnId} at index ${newIndex}`);
167+
// Update your backend or state here
168+
}
169+
};
170+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@object-ui/plugin-kanban",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"license": "MIT",
6+
"main": "dist/index.umd.cjs",
7+
"module": "dist/index.js",
8+
"types": "dist/index.d.ts",
9+
"exports": {
10+
".": {
11+
"types": "./dist/index.d.ts",
12+
"import": "./dist/index.js",
13+
"require": "./dist/index.umd.cjs"
14+
}
15+
},
16+
"scripts": {
17+
"build": "vite build"
18+
},
19+
"dependencies": {
20+
"@dnd-kit/core": "^6.3.1",
21+
"@dnd-kit/sortable": "^8.0.0",
22+
"@dnd-kit/utilities": "^3.2.2",
23+
"@object-ui/components": "workspace:*",
24+
"@object-ui/core": "workspace:*",
25+
"@object-ui/react": "workspace:*",
26+
"@object-ui/types": "workspace:*"
27+
},
28+
"peerDependencies": {
29+
"react": "^18.0.0 || ^19.0.0",
30+
"react-dom": "^18.0.0 || ^19.0.0"
31+
},
32+
"devDependencies": {
33+
"@types/react": "^18.3.12",
34+
"@types/react-dom": "^18.3.1",
35+
"@vitejs/plugin-react": "^4.2.1",
36+
"typescript": "^5.0.0",
37+
"vite": "^5.0.0",
38+
"vite-plugin-dts": "^3.9.1"
39+
}
40+
}

0 commit comments

Comments
 (0)