-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.tsx
More file actions
168 lines (158 loc) · 4.49 KB
/
index.tsx
File metadata and controls
168 lines (158 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import React, { Suspense } from 'react';
import { ComponentRegistry } from '@object-ui/core';
import { Skeleton } from '@object-ui/components';
// Export types for external use
export type { KanbanSchema, KanbanCard, KanbanColumn } from './types';
// 🚀 Lazy load the implementation file
// This ensures @dnd-kit is only loaded when the component is actually rendered
const LazyKanban = React.lazy(() => import('./KanbanImpl'));
export interface KanbanRendererProps {
schema: {
type: string;
id?: string;
className?: string;
columns?: Array<any>;
data?: Array<any>;
groupBy?: string;
onCardMove?: (cardId: string, fromColumnId: string, toColumnId: string, newIndex: number) => void;
};
}
/**
* KanbanRenderer - The public API for the kanban board component
* This wrapper handles lazy loading internally using React.Suspense
*/
export const KanbanRenderer: React.FC<KanbanRendererProps> = ({ schema }) => {
// ⚡️ Adapter: Map flat 'data' + 'groupBy' to nested 'cards' structure
const processedColumns = React.useMemo(() => {
const { columns = [], data, groupBy } = schema;
// If we have flat data and a grouping key, distribute items into columns
if (data && groupBy && Array.isArray(data)) {
// 1. Group data by key
const groups = data.reduce((acc, item) => {
const key = item[groupBy];
if (!acc[key]) acc[key] = [];
acc[key].push(item);
return acc;
}, {} as Record<string, any[]>);
// 2. Inject into columns
return columns.map((col: any) => ({
...col,
cards: [
...(col.cards || []), // Preserve static cards
...(groups[col.id] || []) // Add dynamic cards
]
}));
}
// Default: Return columns as-is (assuming they have 'cards' inside)
return columns;
}, [schema]);
return (
<Suspense fallback={<Skeleton className="w-full h-[600px]" />}>
<LazyKanban
columns={processedColumns}
onCardMove={schema.onCardMove}
className={schema.className}
/>
</Suspense>
);
};
// Register the component with the ComponentRegistry
ComponentRegistry.register(
'kanban',
KanbanRenderer,
{
label: 'Kanban Board',
icon: 'LayoutDashboard',
category: 'plugin',
inputs: [
{
name: 'columns',
type: 'array',
label: 'Columns',
description: 'Array of { id, title, cards, limit, className }',
required: true
},
{
name: 'onCardMove',
type: 'code',
label: 'On Card Move',
description: 'Callback when a card is moved',
advanced: true
},
{
name: 'className',
type: 'string',
label: 'CSS Class'
}
],
defaultProps: {
columns: [
{
id: 'todo',
title: 'To Do',
cards: [
{
id: 'card-1',
title: 'Task 1',
description: 'This is the first task',
badges: [
{ label: 'High Priority', variant: 'destructive' },
{ label: 'Feature', variant: 'default' }
]
},
{
id: 'card-2',
title: 'Task 2',
description: 'This is the second task',
badges: [
{ label: 'Bug', variant: 'destructive' }
]
}
]
},
{
id: 'in-progress',
title: 'In Progress',
limit: 3,
cards: [
{
id: 'card-3',
title: 'Task 3',
description: 'Currently working on this',
badges: [
{ label: 'In Progress', variant: 'default' }
]
}
]
},
{
id: 'done',
title: 'Done',
cards: [
{
id: 'card-4',
title: 'Task 4',
description: 'This task is completed',
badges: [
{ label: 'Completed', variant: 'outline' }
]
},
{
id: 'card-5',
title: 'Task 5',
description: 'Another completed task',
badges: [
{ label: 'Completed', variant: 'outline' }
]
}
]
}
],
className: 'w-full'
}
}
);
// Standard Export Protocol - for manual integration
export const kanbanComponents = {
'kanban': KanbanRenderer,
};