@joewinke/jatui 0.1.0 → 0.1.1

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.
@@ -0,0 +1,361 @@
1
+ # Pipeline Component API Design
2
+
3
+ Component prop signatures for `<Pipeline>`, `<PipelineColumn>`, `<PipelineCard>`.
4
+ Types are defined in `src/lib/types/pipeline.ts`.
5
+
6
+ ## Component Hierarchy
7
+
8
+ ```
9
+ <Pipeline> ← Top-level: metrics bar, view toggle, columns layout
10
+ <PipelineColumn> ← Per-stage column: header, drop zone, card list
11
+ <PipelineCard> ← Per-item card: default layout + custom snippet
12
+ ```
13
+
14
+ Consumers typically only use `<Pipeline>` directly. The sub-components are exported
15
+ for advanced layouts but `<Pipeline>` renders them internally by default.
16
+
17
+ ---
18
+
19
+ ## `<Pipeline>`
20
+
21
+ The main entry point. Accepts items + stages, handles grouping, filtering, view toggle, and drag-drop orchestration.
22
+
23
+ ```svelte
24
+ <script lang="ts">
25
+ import type { Snippet } from 'svelte';
26
+ import type {
27
+ PipelineStage,
28
+ PipelineItem,
29
+ PipelineMetric,
30
+ PipelineConfig,
31
+ PipelineStageChangeEvent,
32
+ PipelineItemClickEvent,
33
+ PipelineViewMode
34
+ } from '$lib/types/pipeline';
35
+
36
+ interface Props {
37
+ /** Array of stage definitions (columns). Order determines display order. */
38
+ stages: PipelineStage[];
39
+ /** All items across all stages. Grouped by item.stageId internally. */
40
+ items: PipelineItem[];
41
+ /** Pipeline-wide metrics displayed above the board */
42
+ metrics?: PipelineMetric[];
43
+ /** Configuration overrides (views, drag, collapsible, etc.) */
44
+ config?: Partial<PipelineConfig>;
45
+
46
+ // ─── View State (bindable) ───
47
+ /** Current view mode. Bindable for external control. */
48
+ viewMode?: PipelineViewMode;
49
+ /** Set of collapsed stage IDs. Bindable. */
50
+ collapsedStages?: Set<string>;
51
+
52
+ // ─── Events ───
53
+ /** Fired after drag-drop completes (optimistic). Return a promise; rejection reverts. */
54
+ onStageChange?: (event: PipelineStageChangeEvent) => Promise<void>;
55
+ /** Fired when a card is clicked */
56
+ onItemClick?: (event: PipelineItemClickEvent) => void;
57
+
58
+ // ─── Snippets (card customization) ───
59
+ /** Custom card body. Receives { item, stage }. Falls back to default PipelineCard. */
60
+ card?: Snippet<[{ item: PipelineItem; stage: PipelineStage }]>;
61
+ /** Custom column header. Receives { stage, count, totalValue }. */
62
+ columnHeader?: Snippet<[{ stage: PipelineStage; count: number; totalValue: number }]>;
63
+ /** Custom empty state per column. Receives { stage }. */
64
+ emptyState?: Snippet<[{ stage: PipelineStage }]>;
65
+
66
+ // ─── Styling ───
67
+ class?: string;
68
+ }
69
+
70
+ let {
71
+ stages,
72
+ items,
73
+ metrics,
74
+ config,
75
+ viewMode = $bindable('kanban'),
76
+ collapsedStages = $bindable(new Set()),
77
+ onStageChange,
78
+ onItemClick,
79
+ card,
80
+ columnHeader,
81
+ emptyState,
82
+ class: className
83
+ }: Props = $props();
84
+ </script>
85
+ ```
86
+
87
+ ### Usage Example
88
+
89
+ ```svelte
90
+ <script>
91
+ import { Pipeline } from '@joewinke/jatui';
92
+
93
+ const stages = [
94
+ { id: 'new', label: 'New', order: 0, semantic: 'info' },
95
+ { id: 'qualified', label: 'Qualified', order: 1, color: 'oklch(0.70 0.18 240)' },
96
+ { id: 'won', label: 'Won', order: 2, semantic: 'success' },
97
+ ];
98
+
99
+ let items = $state([...]);
100
+
101
+ async function handleStageChange(e) {
102
+ await fetch(`/api/items/${e.itemId}/stage`, {
103
+ method: 'PATCH',
104
+ body: JSON.stringify({ stage: e.toStageId })
105
+ });
106
+ }
107
+ </script>
108
+
109
+ <Pipeline {stages} {items} onStageChange={handleStageChange}>
110
+ {#snippet card({ item, stage })}
111
+ <div class="font-bold">{item.title}</div>
112
+ <div class="text-sm opacity-60">{item.meta?.clientName}</div>
113
+ {/snippet}
114
+ </Pipeline>
115
+ ```
116
+
117
+ ---
118
+
119
+ ## `<PipelineColumn>`
120
+
121
+ A single stage column. Rendered by `<Pipeline>` internally but exported for custom layouts.
122
+
123
+ ```svelte
124
+ <script lang="ts">
125
+ import type { Snippet } from 'svelte';
126
+ import type { PipelineStage, PipelineItem, StageColors, PipelineDragConfig } from '$lib/types/pipeline';
127
+
128
+ interface Props {
129
+ stage: PipelineStage;
130
+ items: PipelineItem[];
131
+ colors: StageColors;
132
+ /** Drag-drop config (passed down from Pipeline) */
133
+ drag?: PipelineDragConfig;
134
+ /** Whether column is collapsed */
135
+ collapsed?: boolean;
136
+ /** Min-height in px */
137
+ minHeight?: number;
138
+
139
+ // ─── Events ───
140
+ onToggleCollapse?: () => void;
141
+ /** svelte-dnd-action consider handler */
142
+ onDndConsider?: (e: CustomEvent) => void;
143
+ /** svelte-dnd-action finalize handler */
144
+ onDndFinalize?: (e: CustomEvent) => void;
145
+ onItemClick?: (item: PipelineItem) => void;
146
+
147
+ // ─── Snippets ───
148
+ /** Custom header content */
149
+ header?: Snippet<[{ stage: PipelineStage; count: number; totalValue: number }]>;
150
+ /** Custom card rendering */
151
+ card?: Snippet<[{ item: PipelineItem; stage: PipelineStage }]>;
152
+ /** Custom empty state */
153
+ emptyState?: Snippet<[{ stage: PipelineStage }]>;
154
+
155
+ class?: string;
156
+ }
157
+ </script>
158
+ ```
159
+
160
+ ### Internal Structure
161
+
162
+ ```
163
+ ┌─────────────────────────────┐
164
+ │ [icon] Stage Label [3] ▾ │ ← Header (count badge, collapse toggle)
165
+ │ $12.5K total │ ← Aggregate value (if items have .value)
166
+ ├─────────────────────────────┤
167
+ │ │
168
+ │ ┌───────────────────────┐ │
169
+ │ │ Card 1 │ │ ← PipelineCard (draggable)
170
+ │ └───────────────────────┘ │
171
+ │ ┌───────────────────────┐ │
172
+ │ │ Card 2 │ │
173
+ │ └───────────────────────┘ │
174
+ │ │
175
+ │ - - - - - - - - - - - - - │ ← Drop zone (dashed border on drag)
176
+ │ │
177
+ └─────────────────────────────┘
178
+ ```
179
+
180
+ ---
181
+
182
+ ## `<PipelineCard>`
183
+
184
+ Default card rendered for each item. Consumers can replace entirely via the `card` snippet on `<Pipeline>`.
185
+
186
+ ```svelte
187
+ <script lang="ts">
188
+ import type { PipelineItem, PipelineStage, StageColors } from '$lib/types/pipeline';
189
+
190
+ interface Props {
191
+ item: PipelineItem;
192
+ stage: PipelineStage;
193
+ colors: StageColors;
194
+ /** Whether this card is currently being dragged */
195
+ isDragging?: boolean;
196
+
197
+ onclick?: (item: PipelineItem) => void;
198
+
199
+ class?: string;
200
+ }
201
+ </script>
202
+ ```
203
+
204
+ ### Default Card Layout
205
+
206
+ ```
207
+ ┌─────────────────────────────┐
208
+ │ Title $25K │ ← title + formatted value
209
+ │ Subtitle │ ← subtitle (if present)
210
+ │ [P0] [label1] [label2] │ ← priority badge + labels
211
+ │ @assignee 3 days ago │ ← assignee + stage duration
212
+ └─────────────────────────────┘
213
+ ```
214
+
215
+ ---
216
+
217
+ ## Data Flow
218
+
219
+ ```
220
+ Consumer provides: Pipeline computes: Sub-components receive:
221
+ ───────────────── ───────────────── ────────────────────────
222
+ stages[] ──────► stageColors: Map<id, StageColors> ──► PipelineColumn.colors
223
+ items[] ──────► itemsByStage: Map<id, Item[]> ──► PipelineColumn.items
224
+ config ──────► resolvedConfig (merged w/ defaults) ──► PipelineColumn.drag
225
+ stageMetrics: StageMetrics[] ──► column headers
226
+ ```
227
+
228
+ ### Grouping (derived)
229
+
230
+ ```typescript
231
+ const itemsByStage = $derived.by(() => {
232
+ // Pre-initialize all stages (even empty ones show as columns)
233
+ const groups = new Map<string, PipelineItem[]>();
234
+ for (const stage of stages) {
235
+ groups.set(stage.id, []);
236
+ }
237
+ for (const item of items) {
238
+ const list = groups.get(item.stageId);
239
+ if (list) list.push(item);
240
+ else groups.get(stages[0].id)?.push(item); // fallback to first stage
241
+ }
242
+ return groups;
243
+ });
244
+ ```
245
+
246
+ ### Color Resolution
247
+
248
+ ```typescript
249
+ function resolveStageColors(stage: PipelineStage): StageColors {
250
+ if (stage.color) {
251
+ // oklch: derive bg/text/border/accent from the base color
252
+ return {
253
+ bg: `color-mix(in oklch, ${stage.color} 10%, transparent)`,
254
+ text: stage.color,
255
+ border: `color-mix(in oklch, ${stage.color} 40%, transparent)`,
256
+ accent: stage.color
257
+ };
258
+ }
259
+ // DaisyUI semantic fallback
260
+ const sem = stage.semantic || 'primary';
261
+ return {
262
+ bg: `oklch(from var(--${sem === 'info' ? 'in' : sem === 'success' ? 'su' : sem === 'warning' ? 'wa' : sem === 'error' ? 'er' : 'p'}) l c h / 0.1)`,
263
+ text: `var(--${sem})`,
264
+ border: `oklch(from var(--${sem === 'info' ? 'in' : sem === 'success' ? 'su' : sem === 'warning' ? 'wa' : sem === 'error' ? 'er' : 'p'}) l c h / 0.4)`,
265
+ accent: `var(--${sem})`
266
+ };
267
+ }
268
+ ```
269
+
270
+ ---
271
+
272
+ ## Drag-Drop Integration
273
+
274
+ Uses `svelte-dnd-action` — same pattern as Steelbridge pipeline.
275
+
276
+ ```svelte
277
+ <!-- Inside PipelineColumn -->
278
+ <div
279
+ use:dndzone={{
280
+ items: columnItems,
281
+ flipDurationMs: drag.flipDurationMs,
282
+ dropTargetStyle: {},
283
+ dropTargetClasses: [drag.dropTargetClass]
284
+ }}
285
+ onconsider={handleConsider}
286
+ onfinalize={handleFinalize}
287
+ >
288
+ {#each columnItems as item (item.id)}
289
+ <div animate:flip={{ duration: drag.flipDurationMs }}>
290
+ <!-- card snippet or default PipelineCard -->
291
+ </div>
292
+ {/each}
293
+ </div>
294
+ ```
295
+
296
+ ### Optimistic Update + Rollback
297
+
298
+ ```typescript
299
+ // In Pipeline component
300
+ async function handleStageFinalize(stageId: string, e: CustomEvent) {
301
+ const prevItems = [...items]; // snapshot for rollback
302
+ // Apply optimistic update to local state
303
+ items = applyDrop(items, stageId, e.detail);
304
+
305
+ if (onStageChange) {
306
+ try {
307
+ await onStageChange({
308
+ itemId: e.detail.info.id,
309
+ fromStageId: findPreviousStage(e.detail.info.id, prevItems),
310
+ toStageId: stageId,
311
+ newIndex: e.detail.items.findIndex(i => i.id === e.detail.info.id)
312
+ });
313
+ } catch {
314
+ items = prevItems; // rollback on rejection
315
+ }
316
+ }
317
+ }
318
+ ```
319
+
320
+ ---
321
+
322
+ ## Table View
323
+
324
+ When `viewMode === 'table'`, renders a DaisyUI table using `config.tableColumns`.
325
+
326
+ ```
327
+ ┌──────────┬──────────┬─────────┬────────┬──────────┐
328
+ │ Name │ Stage │ Value │ Assign │ Date │
329
+ ├──────────┼──────────┼─────────┼────────┼──────────┤
330
+ │ Item 1 │ [badge] │ $25K │ @joe │ Mar 28 │
331
+ │ Item 2 │ [badge] │ $12K │ @sam │ Apr 02 │
332
+ └──────────┴──────────┴─────────┴────────┴──────────┘
333
+ ```
334
+
335
+ Default table columns (when `config.tableColumns` not provided):
336
+ ```typescript
337
+ const defaultTableColumns: PipelineTableColumn[] = [
338
+ { key: 'title', label: 'Name', width: 'flex', sortable: true },
339
+ { key: 'stageId', label: 'Stage', width: 'md', sortable: true },
340
+ { key: 'value', label: 'Value', width: 'sm', sortable: true },
341
+ { key: 'assignee', label: 'Assignee', width: 'md', sortable: true },
342
+ { key: 'expectedDate', label: 'Date', width: 'md', sortable: true }
343
+ ];
344
+ ```
345
+
346
+ ---
347
+
348
+ ## Responsive Behavior
349
+
350
+ ```css
351
+ /* Kanban: horizontal scroll on mobile, fixed columns on desktop */
352
+ .pipeline-board {
353
+ display: grid;
354
+ grid-auto-flow: column;
355
+ grid-auto-columns: minmax(240px, 1fr);
356
+ overflow-x: auto;
357
+ gap: 0.75rem;
358
+ }
359
+
360
+ /* Table: switches to card-based on mobile (DaisyUI responsive table) */
361
+ ```