@joewinke/jatui 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -1
- package/src/lib/components/EmojiPicker.svelte +157 -0
- package/src/lib/components/LinkShortener.svelte +274 -0
- package/src/lib/components/SearchDropdown.svelte +41 -33
- package/src/lib/components/pipeline/DESIGN.md +361 -0
- package/src/lib/components/pipeline/Pipeline.svelte +391 -0
- package/src/lib/components/pipeline/PipelineCard.svelte +94 -0
- package/src/lib/components/pipeline/PipelineColumn.svelte +158 -0
- package/src/lib/data/emojis.ts +1208 -0
- package/src/lib/index.ts +37 -0
- package/src/lib/types/pipeline.ts +150 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
PipelineStage,
|
|
5
|
+
PipelineItem,
|
|
6
|
+
PipelineMetric,
|
|
7
|
+
PipelineConfig,
|
|
8
|
+
PipelineStageChangeEvent,
|
|
9
|
+
PipelineItemClickEvent,
|
|
10
|
+
PipelineViewMode,
|
|
11
|
+
StageColors,
|
|
12
|
+
PipelineTableColumn
|
|
13
|
+
} from '$lib/types/pipeline';
|
|
14
|
+
import { DEFAULT_PIPELINE_CONFIG } from '$lib/types/pipeline';
|
|
15
|
+
import PipelineColumn from './PipelineColumn.svelte';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
stages: PipelineStage[];
|
|
19
|
+
items: PipelineItem[];
|
|
20
|
+
metrics?: PipelineMetric[];
|
|
21
|
+
config?: Partial<PipelineConfig>;
|
|
22
|
+
|
|
23
|
+
viewMode?: PipelineViewMode;
|
|
24
|
+
collapsedStages?: Set<string>;
|
|
25
|
+
|
|
26
|
+
onStageChange?: (event: PipelineStageChangeEvent) => Promise<void>;
|
|
27
|
+
onItemClick?: (event: PipelineItemClickEvent) => void;
|
|
28
|
+
|
|
29
|
+
card?: Snippet<[{ item: PipelineItem; stage: PipelineStage }]>;
|
|
30
|
+
columnHeader?: Snippet<[{ stage: PipelineStage; count: number; totalValue: number }]>;
|
|
31
|
+
emptyState?: Snippet<[{ stage: PipelineStage }]>;
|
|
32
|
+
|
|
33
|
+
class?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
stages,
|
|
38
|
+
items,
|
|
39
|
+
metrics,
|
|
40
|
+
config: configOverride,
|
|
41
|
+
viewMode = $bindable('kanban'),
|
|
42
|
+
collapsedStages = $bindable(new Set()),
|
|
43
|
+
onStageChange,
|
|
44
|
+
onItemClick,
|
|
45
|
+
card,
|
|
46
|
+
columnHeader,
|
|
47
|
+
emptyState,
|
|
48
|
+
class: className = ''
|
|
49
|
+
}: Props = $props();
|
|
50
|
+
|
|
51
|
+
// ─── Config ───
|
|
52
|
+
|
|
53
|
+
const cfg = $derived({
|
|
54
|
+
...DEFAULT_PIPELINE_CONFIG,
|
|
55
|
+
...configOverride,
|
|
56
|
+
drag: { ...DEFAULT_PIPELINE_CONFIG.drag!, ...(configOverride?.drag ?? {}) }
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const hasMultipleViews = $derived((cfg.views?.length ?? 0) > 1);
|
|
60
|
+
|
|
61
|
+
// ─── Color Resolution ───
|
|
62
|
+
|
|
63
|
+
const SEMANTIC_VAR: Record<string, string> = {
|
|
64
|
+
primary: 'p',
|
|
65
|
+
secondary: 's',
|
|
66
|
+
accent: 'a',
|
|
67
|
+
neutral: 'n',
|
|
68
|
+
info: 'in',
|
|
69
|
+
success: 'su',
|
|
70
|
+
warning: 'wa',
|
|
71
|
+
error: 'er'
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function resolveColors(stage: PipelineStage): StageColors {
|
|
75
|
+
if (stage.color) {
|
|
76
|
+
return {
|
|
77
|
+
bg: `color-mix(in oklch, ${stage.color} 10%, transparent)`,
|
|
78
|
+
text: stage.color,
|
|
79
|
+
border: `color-mix(in oklch, ${stage.color} 40%, transparent)`,
|
|
80
|
+
accent: stage.color
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const v = SEMANTIC_VAR[stage.semantic || 'primary'] || 'p';
|
|
84
|
+
return {
|
|
85
|
+
bg: `oklch(var(--${v}) / 0.1)`,
|
|
86
|
+
text: `oklch(var(--${v}))`,
|
|
87
|
+
border: `oklch(var(--${v}) / 0.4)`,
|
|
88
|
+
accent: `oklch(var(--${v}))`
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const colorsMap = $derived(new Map(stages.map((s) => [s.id, resolveColors(s)])));
|
|
93
|
+
|
|
94
|
+
// ─── Sorted Stages ───
|
|
95
|
+
|
|
96
|
+
const sortedStages = $derived([...stages].sort((a, b) => a.order - b.order));
|
|
97
|
+
const stageMap = $derived(new Map(stages.map((s) => [s.id, s])));
|
|
98
|
+
|
|
99
|
+
// ─── Item Grouping (internal mutable state for drag-drop) ───
|
|
100
|
+
|
|
101
|
+
let itemsByStage = $state<Record<string, PipelineItem[]>>({});
|
|
102
|
+
|
|
103
|
+
$effect(() => {
|
|
104
|
+
const grouped: Record<string, PipelineItem[]> = {};
|
|
105
|
+
for (const stage of stages) grouped[stage.id] = [];
|
|
106
|
+
for (const item of items) {
|
|
107
|
+
if (grouped[item.stageId]) grouped[item.stageId].push(item);
|
|
108
|
+
else if (stages.length > 0) grouped[stages[0].id].push(item);
|
|
109
|
+
}
|
|
110
|
+
itemsByStage = grouped;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// ─── Drag-Drop ───
|
|
114
|
+
|
|
115
|
+
let dragSnapshot: Record<string, PipelineItem[]> | null = null;
|
|
116
|
+
|
|
117
|
+
function handleConsider(stageId: string, e: CustomEvent) {
|
|
118
|
+
if (!dragSnapshot) {
|
|
119
|
+
dragSnapshot = Object.fromEntries(
|
|
120
|
+
Object.entries(itemsByStage).map(([k, v]) => [k, [...v]])
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
itemsByStage[stageId] = e.detail.items;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function handleFinalize(stageId: string, e: CustomEvent) {
|
|
127
|
+
const snapshot = dragSnapshot;
|
|
128
|
+
dragSnapshot = null;
|
|
129
|
+
|
|
130
|
+
itemsByStage[stageId] = e.detail.items;
|
|
131
|
+
|
|
132
|
+
if (onStageChange && e.detail.info) {
|
|
133
|
+
const movedId = e.detail.info.id;
|
|
134
|
+
let fromStageId = stageId;
|
|
135
|
+
if (snapshot) {
|
|
136
|
+
for (const [sid, sitems] of Object.entries(snapshot)) {
|
|
137
|
+
if (sitems.some((i) => i.id === movedId)) {
|
|
138
|
+
fromStageId = sid;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const newIndex = e.detail.items.findIndex((i: PipelineItem) => i.id === movedId);
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
await onStageChange({ itemId: movedId, fromStageId, toStageId: stageId, newIndex });
|
|
147
|
+
} catch {
|
|
148
|
+
if (snapshot) itemsByStage = snapshot;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function handleItemClick(item: PipelineItem) {
|
|
154
|
+
onItemClick?.({ item, stageId: item.stageId });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function toggleCollapse(stageId: string) {
|
|
158
|
+
const next = new Set(collapsedStages);
|
|
159
|
+
if (next.has(stageId)) next.delete(stageId);
|
|
160
|
+
else next.add(stageId);
|
|
161
|
+
collapsedStages = next;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ─── Metrics ───
|
|
165
|
+
|
|
166
|
+
function formatMetricValue(m: PipelineMetric): string {
|
|
167
|
+
if (typeof m.value === 'string') return m.value;
|
|
168
|
+
if (m.format === 'currency') {
|
|
169
|
+
return new Intl.NumberFormat('en-US', {
|
|
170
|
+
style: 'currency',
|
|
171
|
+
currency: cfg.currency,
|
|
172
|
+
maximumFractionDigits: 0
|
|
173
|
+
}).format(m.value);
|
|
174
|
+
}
|
|
175
|
+
if (m.format === 'percent') return `${m.value}%`;
|
|
176
|
+
return m.value.toLocaleString();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ─── Table View ───
|
|
180
|
+
|
|
181
|
+
const defaultTableColumns: PipelineTableColumn[] = [
|
|
182
|
+
{ key: 'title', label: 'Name', width: 'flex', sortable: true },
|
|
183
|
+
{ key: 'stageId', label: 'Stage', width: 'md', sortable: true },
|
|
184
|
+
{ key: 'value', label: 'Value', width: 'sm', sortable: true },
|
|
185
|
+
{ key: 'assignee', label: 'Assignee', width: 'md', sortable: true },
|
|
186
|
+
{ key: 'expectedDate', label: 'Date', width: 'md', sortable: true }
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
const tableColumns = $derived(cfg.tableColumns ?? defaultTableColumns);
|
|
190
|
+
|
|
191
|
+
let sortKey = $state('');
|
|
192
|
+
let sortDir = $state<'asc' | 'desc'>('asc');
|
|
193
|
+
|
|
194
|
+
const allItems = $derived(sortedStages.flatMap((s) => itemsByStage[s.id] ?? []));
|
|
195
|
+
|
|
196
|
+
const sortedTableItems = $derived.by(() => {
|
|
197
|
+
if (!sortKey) return allItems;
|
|
198
|
+
return [...allItems].sort((a, b) => {
|
|
199
|
+
const av = (a as Record<string, unknown>)[sortKey] ?? '';
|
|
200
|
+
const bv = (b as Record<string, unknown>)[sortKey] ?? '';
|
|
201
|
+
const cmp =
|
|
202
|
+
typeof av === 'number' && typeof bv === 'number'
|
|
203
|
+
? av - bv
|
|
204
|
+
: String(av).localeCompare(String(bv));
|
|
205
|
+
return sortDir === 'asc' ? cmp : -cmp;
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
function toggleSort(key: string) {
|
|
210
|
+
if (sortKey === key) {
|
|
211
|
+
sortDir = sortDir === 'asc' ? 'desc' : 'asc';
|
|
212
|
+
} else {
|
|
213
|
+
sortKey = key;
|
|
214
|
+
sortDir = 'asc';
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const WIDTH_CLASS: Record<string, string> = {
|
|
219
|
+
sm: 'w-20',
|
|
220
|
+
md: 'w-32',
|
|
221
|
+
lg: 'w-48',
|
|
222
|
+
flex: ''
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
function formatCell(item: PipelineItem, key: string): string {
|
|
226
|
+
if (key === 'value' && item.value != null) {
|
|
227
|
+
return new Intl.NumberFormat('en-US', {
|
|
228
|
+
style: 'currency',
|
|
229
|
+
currency: cfg.currency,
|
|
230
|
+
maximumFractionDigits: 0
|
|
231
|
+
}).format(item.value);
|
|
232
|
+
}
|
|
233
|
+
if (key === 'expectedDate' && item.expectedDate) {
|
|
234
|
+
return new Date(item.expectedDate).toLocaleDateString('en-US', {
|
|
235
|
+
month: 'short',
|
|
236
|
+
day: 'numeric'
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return String((item as Record<string, unknown>)[key] ?? '');
|
|
240
|
+
}
|
|
241
|
+
</script>
|
|
242
|
+
|
|
243
|
+
<div class="flex flex-col gap-4 {className}">
|
|
244
|
+
<!-- Metrics Bar -->
|
|
245
|
+
{#if metrics && metrics.length > 0}
|
|
246
|
+
<div class="grid grid-cols-2 md:grid-cols-4 gap-3">
|
|
247
|
+
{#each metrics as m}
|
|
248
|
+
<div class="stat bg-base-100 rounded-xl border border-base-300 p-3">
|
|
249
|
+
<div class="stat-title text-xs">{m.label}</div>
|
|
250
|
+
<div class="stat-value text-lg" style:color={m.color}>
|
|
251
|
+
{formatMetricValue(m)}
|
|
252
|
+
</div>
|
|
253
|
+
{#if m.change != null}
|
|
254
|
+
<div
|
|
255
|
+
class="stat-desc text-xs {m.change >= 0 ? 'text-success' : 'text-error'}"
|
|
256
|
+
>
|
|
257
|
+
{m.change >= 0 ? '+' : ''}{m.change}{m.format === 'percent' ? 'pp' : '%'}
|
|
258
|
+
</div>
|
|
259
|
+
{/if}
|
|
260
|
+
</div>
|
|
261
|
+
{/each}
|
|
262
|
+
</div>
|
|
263
|
+
{/if}
|
|
264
|
+
|
|
265
|
+
<!-- View Toggle -->
|
|
266
|
+
{#if hasMultipleViews}
|
|
267
|
+
<div class="flex justify-end">
|
|
268
|
+
<div class="join">
|
|
269
|
+
{#each cfg.views ?? [] as view}
|
|
270
|
+
<button
|
|
271
|
+
type="button"
|
|
272
|
+
class="join-item btn btn-sm {viewMode === view ? 'btn-active' : ''}"
|
|
273
|
+
onclick={() => (viewMode = view)}
|
|
274
|
+
>
|
|
275
|
+
{#if view === 'kanban'}
|
|
276
|
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
277
|
+
<path
|
|
278
|
+
stroke-linecap="round"
|
|
279
|
+
stroke-linejoin="round"
|
|
280
|
+
stroke-width="2"
|
|
281
|
+
d="M9 17V7m0 10a2 2 0 01-2 2H5a2 2 0 01-2-2V7a2 2 0 012-2h2a2 2 0 012 2m0 10a2 2 0 002 2h2a2 2 0 002-2M9 7a2 2 0 012-2h2a2 2 0 012 2m0 10V7m0 10a2 2 0 002 2h2a2 2 0 002-2V7a2 2 0 00-2-2h-2a2 2 0 00-2 2"
|
|
282
|
+
/>
|
|
283
|
+
</svg>
|
|
284
|
+
Board
|
|
285
|
+
{:else}
|
|
286
|
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
287
|
+
<path
|
|
288
|
+
stroke-linecap="round"
|
|
289
|
+
stroke-linejoin="round"
|
|
290
|
+
stroke-width="2"
|
|
291
|
+
d="M4 6h16M4 10h16M4 14h16M4 18h16"
|
|
292
|
+
/>
|
|
293
|
+
</svg>
|
|
294
|
+
Table
|
|
295
|
+
{/if}
|
|
296
|
+
</button>
|
|
297
|
+
{/each}
|
|
298
|
+
</div>
|
|
299
|
+
</div>
|
|
300
|
+
{/if}
|
|
301
|
+
|
|
302
|
+
<!-- Kanban View -->
|
|
303
|
+
{#if viewMode === 'kanban'}
|
|
304
|
+
<div
|
|
305
|
+
class="grid grid-flow-col auto-cols-[minmax(240px,1fr)] gap-3 overflow-x-auto pb-2"
|
|
306
|
+
>
|
|
307
|
+
{#each sortedStages as stage (stage.id)}
|
|
308
|
+
<PipelineColumn
|
|
309
|
+
{stage}
|
|
310
|
+
items={itemsByStage[stage.id] ?? []}
|
|
311
|
+
colors={colorsMap.get(stage.id) ?? { bg: '', text: '', border: '', accent: '' }}
|
|
312
|
+
drag={cfg.drag}
|
|
313
|
+
collapsed={collapsedStages.has(stage.id)}
|
|
314
|
+
minHeight={cfg.columnMinHeight}
|
|
315
|
+
onToggleCollapse={() => toggleCollapse(stage.id)}
|
|
316
|
+
onDndConsider={(e) => handleConsider(stage.id, e)}
|
|
317
|
+
onDndFinalize={(e) => handleFinalize(stage.id, e)}
|
|
318
|
+
onItemClick={handleItemClick}
|
|
319
|
+
header={columnHeader}
|
|
320
|
+
{card}
|
|
321
|
+
{emptyState}
|
|
322
|
+
/>
|
|
323
|
+
{/each}
|
|
324
|
+
</div>
|
|
325
|
+
{/if}
|
|
326
|
+
|
|
327
|
+
<!-- Table View -->
|
|
328
|
+
{#if viewMode === 'table'}
|
|
329
|
+
<div class="overflow-x-auto">
|
|
330
|
+
<table class="table table-sm">
|
|
331
|
+
<thead>
|
|
332
|
+
<tr>
|
|
333
|
+
{#each tableColumns as col}
|
|
334
|
+
<th class={WIDTH_CLASS[col.width ?? 'flex']}>
|
|
335
|
+
{#if col.sortable}
|
|
336
|
+
<button
|
|
337
|
+
type="button"
|
|
338
|
+
class="flex items-center gap-1 hover:text-base-content"
|
|
339
|
+
onclick={() => toggleSort(col.key)}
|
|
340
|
+
>
|
|
341
|
+
{col.label}
|
|
342
|
+
{#if sortKey === col.key}
|
|
343
|
+
<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20">
|
|
344
|
+
{#if sortDir === 'asc'}
|
|
345
|
+
<path d="M5.293 9.707l4-4a1 1 0 011.414 0l4 4a1 1 0 01-1.414 1.414L10 7.414l-3.293 3.707a1 1 0 01-1.414-1.414z" />
|
|
346
|
+
{:else}
|
|
347
|
+
<path d="M14.707 10.293l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 111.414-1.414L10 12.586l3.293-3.707a1 1 0 011.414 1.414z" />
|
|
348
|
+
{/if}
|
|
349
|
+
</svg>
|
|
350
|
+
{/if}
|
|
351
|
+
</button>
|
|
352
|
+
{:else}
|
|
353
|
+
{col.label}
|
|
354
|
+
{/if}
|
|
355
|
+
</th>
|
|
356
|
+
{/each}
|
|
357
|
+
</tr>
|
|
358
|
+
</thead>
|
|
359
|
+
<tbody>
|
|
360
|
+
{#each sortedTableItems as item (item.id)}
|
|
361
|
+
{@const itemStage = stageMap.get(item.stageId)}
|
|
362
|
+
{@const itemColors = colorsMap.get(item.stageId)}
|
|
363
|
+
<tr
|
|
364
|
+
class="hover cursor-pointer"
|
|
365
|
+
onclick={() => handleItemClick(item)}
|
|
366
|
+
>
|
|
367
|
+
{#each tableColumns as col}
|
|
368
|
+
<td class={WIDTH_CLASS[col.width ?? 'flex']}>
|
|
369
|
+
{#if col.key === 'stageId' && itemStage}
|
|
370
|
+
<span
|
|
371
|
+
class="badge badge-sm"
|
|
372
|
+
style:background-color={itemColors?.border}
|
|
373
|
+
style:color={itemColors?.text}
|
|
374
|
+
>
|
|
375
|
+
{itemStage.label}
|
|
376
|
+
</span>
|
|
377
|
+
{:else}
|
|
378
|
+
{formatCell(item, col.key)}
|
|
379
|
+
{/if}
|
|
380
|
+
</td>
|
|
381
|
+
{/each}
|
|
382
|
+
</tr>
|
|
383
|
+
{/each}
|
|
384
|
+
</tbody>
|
|
385
|
+
</table>
|
|
386
|
+
{#if sortedTableItems.length === 0}
|
|
387
|
+
<div class="text-center text-sm opacity-40 py-8">No items</div>
|
|
388
|
+
{/if}
|
|
389
|
+
</div>
|
|
390
|
+
{/if}
|
|
391
|
+
</div>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { PipelineItem, PipelineStage, StageColors } from '$lib/types/pipeline';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
item: PipelineItem;
|
|
6
|
+
stage: PipelineStage;
|
|
7
|
+
colors: StageColors;
|
|
8
|
+
/** Whether this card is currently being dragged */
|
|
9
|
+
isDragging?: boolean;
|
|
10
|
+
onclick?: (item: PipelineItem) => void;
|
|
11
|
+
class?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
item,
|
|
16
|
+
stage,
|
|
17
|
+
colors,
|
|
18
|
+
isDragging = false,
|
|
19
|
+
onclick,
|
|
20
|
+
class: className = ''
|
|
21
|
+
}: Props = $props();
|
|
22
|
+
|
|
23
|
+
function formatValue(value: number | undefined): string {
|
|
24
|
+
if (value == null) return '';
|
|
25
|
+
if (value >= 1000) return `$${(value / 1000).toFixed(value % 1000 === 0 ? 0 : 1)}K`;
|
|
26
|
+
return `$${value}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function formatStageDuration(stageEnteredAt: string | undefined): string {
|
|
30
|
+
if (!stageEnteredAt) return '';
|
|
31
|
+
const days = Math.floor((Date.now() - new Date(stageEnteredAt).getTime()) / 86400000);
|
|
32
|
+
if (days === 0) return 'today';
|
|
33
|
+
if (days === 1) return '1 day ago';
|
|
34
|
+
return `${days} days ago`;
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
class="card card-compact bg-base-100 shadow-sm border cursor-pointer hover:shadow-md transition-shadow w-full text-left {isDragging ? 'opacity-50 rotate-2' : ''} {className}"
|
|
41
|
+
style:border-color={colors.border}
|
|
42
|
+
onclick={() => onclick?.(item)}
|
|
43
|
+
>
|
|
44
|
+
<div class="card-body gap-1 p-3">
|
|
45
|
+
<!-- Title + Value -->
|
|
46
|
+
<div class="flex items-start justify-between gap-2">
|
|
47
|
+
<span class="font-medium text-sm leading-tight">{item.title}</span>
|
|
48
|
+
{#if item.value != null}
|
|
49
|
+
<span class="text-xs font-semibold whitespace-nowrap" style:color={colors.accent}>
|
|
50
|
+
{formatValue(item.value)}
|
|
51
|
+
</span>
|
|
52
|
+
{/if}
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
<!-- Subtitle -->
|
|
56
|
+
{#if item.subtitle}
|
|
57
|
+
<span class="text-xs opacity-60">{item.subtitle}</span>
|
|
58
|
+
{/if}
|
|
59
|
+
|
|
60
|
+
<!-- Labels + Priority -->
|
|
61
|
+
{#if item.priority != null || (item.labels && item.labels.length > 0)}
|
|
62
|
+
<div class="flex flex-wrap gap-1 mt-1">
|
|
63
|
+
{#if item.priority != null}
|
|
64
|
+
<span
|
|
65
|
+
class="badge badge-xs badge-outline"
|
|
66
|
+
style:border-color={colors.accent}
|
|
67
|
+
style:color={colors.accent}
|
|
68
|
+
>
|
|
69
|
+
P{item.priority}
|
|
70
|
+
</span>
|
|
71
|
+
{/if}
|
|
72
|
+
{#if item.labels}
|
|
73
|
+
{#each item.labels as label}
|
|
74
|
+
<span class="badge badge-xs badge-ghost">{label}</span>
|
|
75
|
+
{/each}
|
|
76
|
+
{/if}
|
|
77
|
+
</div>
|
|
78
|
+
{/if}
|
|
79
|
+
|
|
80
|
+
<!-- Assignee + Stage Duration -->
|
|
81
|
+
{#if item.assignee || item.stageEnteredAt}
|
|
82
|
+
<div class="flex items-center justify-between mt-1 text-xs opacity-50">
|
|
83
|
+
{#if item.assignee}
|
|
84
|
+
<span>@{item.assignee}</span>
|
|
85
|
+
{:else}
|
|
86
|
+
<span></span>
|
|
87
|
+
{/if}
|
|
88
|
+
{#if item.stageEnteredAt}
|
|
89
|
+
<span>{formatStageDuration(item.stageEnteredAt)}</span>
|
|
90
|
+
{/if}
|
|
91
|
+
</div>
|
|
92
|
+
{/if}
|
|
93
|
+
</div>
|
|
94
|
+
</button>
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type {
|
|
4
|
+
PipelineStage,
|
|
5
|
+
PipelineItem,
|
|
6
|
+
StageColors,
|
|
7
|
+
PipelineDragConfig
|
|
8
|
+
} from '$lib/types/pipeline';
|
|
9
|
+
import { dndzone } from 'svelte-dnd-action';
|
|
10
|
+
import { flip } from 'svelte/animate';
|
|
11
|
+
import PipelineCard from './PipelineCard.svelte';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
stage: PipelineStage;
|
|
15
|
+
items: PipelineItem[];
|
|
16
|
+
colors: StageColors;
|
|
17
|
+
drag?: PipelineDragConfig;
|
|
18
|
+
collapsed?: boolean;
|
|
19
|
+
minHeight?: number;
|
|
20
|
+
onToggleCollapse?: () => void;
|
|
21
|
+
onDndConsider?: (e: CustomEvent) => void;
|
|
22
|
+
onDndFinalize?: (e: CustomEvent) => void;
|
|
23
|
+
onItemClick?: (item: PipelineItem) => void;
|
|
24
|
+
header?: Snippet<[{ stage: PipelineStage; count: number; totalValue: number }]>;
|
|
25
|
+
card?: Snippet<[{ item: PipelineItem; stage: PipelineStage }]>;
|
|
26
|
+
emptyState?: Snippet<[{ stage: PipelineStage }]>;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
stage,
|
|
32
|
+
items,
|
|
33
|
+
colors,
|
|
34
|
+
drag,
|
|
35
|
+
collapsed = false,
|
|
36
|
+
minHeight = 200,
|
|
37
|
+
onToggleCollapse,
|
|
38
|
+
onDndConsider,
|
|
39
|
+
onDndFinalize,
|
|
40
|
+
onItemClick,
|
|
41
|
+
header,
|
|
42
|
+
card,
|
|
43
|
+
emptyState,
|
|
44
|
+
class: className = ''
|
|
45
|
+
}: Props = $props();
|
|
46
|
+
|
|
47
|
+
const totalValue = $derived(items.reduce((sum, i) => sum + (i.value ?? 0), 0));
|
|
48
|
+
const count = $derived(items.length);
|
|
49
|
+
|
|
50
|
+
function formatTotal(value: number): string {
|
|
51
|
+
if (value === 0) return '';
|
|
52
|
+
if (value >= 1000) return `$${(value / 1000).toFixed(value % 1000 === 0 ? 0 : 1)}K`;
|
|
53
|
+
return `$${value}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const dragEnabled = $derived(
|
|
57
|
+
drag?.enabled !== false &&
|
|
58
|
+
!drag?.disabledStages?.includes(stage.id) &&
|
|
59
|
+
stage.droppableIn !== false
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const flipDuration = $derived(drag?.flipDurationMs ?? 200);
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<div
|
|
66
|
+
class="flex flex-col rounded-xl border {className}"
|
|
67
|
+
style:border-color={colors.border}
|
|
68
|
+
style:background-color={colors.bg}
|
|
69
|
+
>
|
|
70
|
+
<!-- Header -->
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
class="flex items-center justify-between p-3 w-full text-left select-none"
|
|
74
|
+
onclick={() => onToggleCollapse?.()}
|
|
75
|
+
>
|
|
76
|
+
{#if header}
|
|
77
|
+
{@render header({ stage, count, totalValue })}
|
|
78
|
+
{:else}
|
|
79
|
+
<div class="flex items-center gap-2">
|
|
80
|
+
<span class="font-semibold text-sm" style:color={colors.text}>{stage.label}</span>
|
|
81
|
+
<span
|
|
82
|
+
class="badge badge-sm"
|
|
83
|
+
style:background-color={colors.border}
|
|
84
|
+
style:color={colors.text}
|
|
85
|
+
>
|
|
86
|
+
{count}
|
|
87
|
+
</span>
|
|
88
|
+
</div>
|
|
89
|
+
<div class="flex items-center gap-2">
|
|
90
|
+
{#if totalValue > 0}
|
|
91
|
+
<span class="text-xs opacity-60">{formatTotal(totalValue)}</span>
|
|
92
|
+
{/if}
|
|
93
|
+
<svg
|
|
94
|
+
class="w-4 h-4 transition-transform opacity-40 {collapsed ? '-rotate-90' : ''}"
|
|
95
|
+
fill="none"
|
|
96
|
+
stroke="currentColor"
|
|
97
|
+
viewBox="0 0 24 24"
|
|
98
|
+
>
|
|
99
|
+
<path
|
|
100
|
+
stroke-linecap="round"
|
|
101
|
+
stroke-linejoin="round"
|
|
102
|
+
stroke-width="2"
|
|
103
|
+
d="M19 9l-7 7-7-7"
|
|
104
|
+
/>
|
|
105
|
+
</svg>
|
|
106
|
+
</div>
|
|
107
|
+
{/if}
|
|
108
|
+
</button>
|
|
109
|
+
|
|
110
|
+
<!-- Body -->
|
|
111
|
+
{#if !collapsed}
|
|
112
|
+
<div class="px-2 pb-2 flex flex-col gap-2" style:min-height="{minHeight}px">
|
|
113
|
+
{#if dragEnabled}
|
|
114
|
+
<div
|
|
115
|
+
use:dndzone={{
|
|
116
|
+
items,
|
|
117
|
+
flipDurationMs: flipDuration,
|
|
118
|
+
dropTargetStyle: {},
|
|
119
|
+
dropTargetClasses: drag?.dropTargetClass ? [drag.dropTargetClass] : []
|
|
120
|
+
}}
|
|
121
|
+
onconsider={(e) => onDndConsider?.(e)}
|
|
122
|
+
onfinalize={(e) => onDndFinalize?.(e)}
|
|
123
|
+
class="flex flex-col gap-2 min-h-8 flex-1"
|
|
124
|
+
>
|
|
125
|
+
{#each items as item (item.id)}
|
|
126
|
+
<div animate:flip={{ duration: flipDuration }}>
|
|
127
|
+
{#if card}
|
|
128
|
+
{@render card({ item, stage })}
|
|
129
|
+
{:else}
|
|
130
|
+
<PipelineCard {item} {stage} {colors} onclick={(i) => onItemClick?.(i)} />
|
|
131
|
+
{/if}
|
|
132
|
+
</div>
|
|
133
|
+
{/each}
|
|
134
|
+
</div>
|
|
135
|
+
{:else}
|
|
136
|
+
<div class="flex flex-col gap-2 flex-1">
|
|
137
|
+
{#each items as item (item.id)}
|
|
138
|
+
{#if card}
|
|
139
|
+
{@render card({ item, stage })}
|
|
140
|
+
{:else}
|
|
141
|
+
<PipelineCard {item} {stage} {colors} onclick={(i) => onItemClick?.(i)} />
|
|
142
|
+
{/if}
|
|
143
|
+
{/each}
|
|
144
|
+
</div>
|
|
145
|
+
{/if}
|
|
146
|
+
|
|
147
|
+
{#if items.length === 0}
|
|
148
|
+
{#if emptyState}
|
|
149
|
+
{@render emptyState({ stage })}
|
|
150
|
+
{:else}
|
|
151
|
+
<div class="flex-1 flex items-center justify-center text-xs opacity-30 p-4">
|
|
152
|
+
No items
|
|
153
|
+
</div>
|
|
154
|
+
{/if}
|
|
155
|
+
{/if}
|
|
156
|
+
</div>
|
|
157
|
+
{/if}
|
|
158
|
+
</div>
|