horizon-design 0.0.3 → 0.0.4
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/README.md +39 -0
- package/dist/components/inspector-panel/InspectorPanel.svelte +297 -0
- package/dist/components/inspector-panel/InspectorPanel.svelte.d.ts +18 -0
- package/dist/components/inspector-panel/index.d.ts +1 -0
- package/dist/components/inspector-panel/index.js +1 -0
- package/dist/components/toggle-group/ToggleGroup.svelte +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2286,6 +2286,45 @@ All nodes default to `mingcute:file-line`. Supply an `icon` snippet to different
|
|
|
2286
2286
|
|
|
2287
2287
|
---
|
|
2288
2288
|
|
|
2289
|
+
### InspectorPanel
|
|
2290
|
+
|
|
2291
|
+
An accordion-style panel of cards with drag-to-reorder and full keyboard navigation. Each card has a title, an optional subtitle, and collapsible content rendered via a `content` snippet.
|
|
2292
|
+
|
|
2293
|
+
```svelte
|
|
2294
|
+
<script>
|
|
2295
|
+
import { InspectorPanel } from 'horizon-design';
|
|
2296
|
+
|
|
2297
|
+
let cards = $state([
|
|
2298
|
+
{ id: 'fill', title: 'Fill', subtitle: 'Solid' },
|
|
2299
|
+
{ id: 'stroke', title: 'Stroke', subtitle: '2px' },
|
|
2300
|
+
{ id: 'shadow', title: 'Shadow' }
|
|
2301
|
+
]);
|
|
2302
|
+
|
|
2303
|
+
let expandedIds = $state(['fill']);
|
|
2304
|
+
</script>
|
|
2305
|
+
|
|
2306
|
+
<InspectorPanel bind:cards bind:expandedIds>
|
|
2307
|
+
{#snippet content(card)}
|
|
2308
|
+
<p>Content for {card.title}</p>
|
|
2309
|
+
{/snippet}
|
|
2310
|
+
</InspectorPanel>
|
|
2311
|
+
```
|
|
2312
|
+
|
|
2313
|
+
| Prop | Type | Default | Description |
|
|
2314
|
+
| ------------------ | ---------------------------------- | ------- | ------------------------------------------ |
|
|
2315
|
+
| `cards` | `InspectorCard[]` | `[]` | List of cards (bindable) |
|
|
2316
|
+
| `expandedIds` | `string[]` | `[]` | IDs of currently expanded cards (bindable) |
|
|
2317
|
+
| `content` | `Snippet<[InspectorCard]>` | — | Snippet rendered inside each card body |
|
|
2318
|
+
| `onCardsChange` | `(cards: InspectorCard[]) => void` | — | Fired when card order changes |
|
|
2319
|
+
| `onExpandedChange` | `(ids: string[]) => void` | — | Fired when expanded state changes |
|
|
2320
|
+
| `class` | `string` | `''` | Extra classes on the root element |
|
|
2321
|
+
|
|
2322
|
+
`InspectorCard` requires an `id: string` and `title: string`; any additional properties are passed through to the `content` snippet.
|
|
2323
|
+
|
|
2324
|
+
**Keyboard navigation** (focus the panel first): `↑`/`↓` move the cursor, `Enter`/`Space` toggle expansion, `Shift+↑`/`Shift+↓` reorder, `Home`/`End` jump to first/last, `Escape` clears the cursor. `Tab` moves focus into the expanded card's content (inputs, buttons, etc.); `Escape` from inside card content returns focus to the panel.
|
|
2325
|
+
|
|
2326
|
+
---
|
|
2327
|
+
|
|
2289
2328
|
### HorizonLayout
|
|
2290
2329
|
|
|
2291
2330
|
A resizable, drag-to-reorder tabbed layout engine. Wrapper around [horizon-layout](https://github.com/horizon-engine/horizon-layout).
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../../utils';
|
|
4
|
+
import MingcuteRightLine from '~icons/mingcute/right-line';
|
|
5
|
+
|
|
6
|
+
type InspectorCard = {
|
|
7
|
+
id: string;
|
|
8
|
+
title: string;
|
|
9
|
+
subtitle?: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
class: className = '',
|
|
15
|
+
cards = $bindable<InspectorCard[]>([]),
|
|
16
|
+
expandedIds = $bindable<string[]>([]),
|
|
17
|
+
content,
|
|
18
|
+
onCardsChange,
|
|
19
|
+
onExpandedChange
|
|
20
|
+
}: {
|
|
21
|
+
class?: string;
|
|
22
|
+
cards?: InspectorCard[];
|
|
23
|
+
expandedIds?: string[];
|
|
24
|
+
content?: Snippet<[InspectorCard]>;
|
|
25
|
+
onCardsChange?: (cards: InspectorCard[]) => void;
|
|
26
|
+
onExpandedChange?: (expandedIds: string[]) => void;
|
|
27
|
+
} = $props();
|
|
28
|
+
|
|
29
|
+
let containerEl = $state<HTMLElement | null>(null);
|
|
30
|
+
let cursorId = $state<string | null>(null);
|
|
31
|
+
let isKeyboardMode = $state(false);
|
|
32
|
+
|
|
33
|
+
let isDragging = $state(false);
|
|
34
|
+
let draggingId = $state<string | null>(null);
|
|
35
|
+
let dragOverIndex = $state<number | null>(null);
|
|
36
|
+
let ghostPos = $state({ x: 0, y: 0 });
|
|
37
|
+
|
|
38
|
+
function portal(node: HTMLElement) {
|
|
39
|
+
document.body.appendChild(node);
|
|
40
|
+
return {
|
|
41
|
+
destroy() {
|
|
42
|
+
node.remove();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function toggleExpanded(id: string) {
|
|
48
|
+
const next = expandedIds.includes(id)
|
|
49
|
+
? expandedIds.filter((v) => v !== id)
|
|
50
|
+
: [...expandedIds, id];
|
|
51
|
+
expandedIds = next;
|
|
52
|
+
onExpandedChange?.(next);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function moveCard(id: string, delta: number) {
|
|
56
|
+
const idx = cards.findIndex((c) => c.id === id);
|
|
57
|
+
const toIdx = idx + delta;
|
|
58
|
+
if (toIdx < 0 || toIdx >= cards.length) return;
|
|
59
|
+
const next = [...cards];
|
|
60
|
+
[next[idx], next[toIdx]] = [next[toIdx], next[idx]];
|
|
61
|
+
cards = next;
|
|
62
|
+
onCardsChange?.(next);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
66
|
+
// If a child element (card content) has focus, only handle Escape to return to the panel
|
|
67
|
+
if (e.target !== containerEl) {
|
|
68
|
+
if (e.key === 'Escape') {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
containerEl?.focus();
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
isKeyboardMode = true;
|
|
76
|
+
const ids = cards.map((c) => c.id);
|
|
77
|
+
const idx = cursorId ? ids.indexOf(cursorId) : -1;
|
|
78
|
+
|
|
79
|
+
if (e.shiftKey && cursorId) {
|
|
80
|
+
if (e.key === 'ArrowUp') {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
moveCard(cursorId, -1);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (e.key === 'ArrowDown') {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
moveCard(cursorId, 1);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (e.key === 'ArrowDown') {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
cursorId = idx < ids.length - 1 ? ids[idx + 1] : ids[0];
|
|
95
|
+
} else if (e.key === 'ArrowUp') {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
cursorId = idx > 0 ? ids[idx - 1] : ids[ids.length - 1];
|
|
98
|
+
} else if (e.key === 'Enter' || e.key === ' ') {
|
|
99
|
+
if (!cursorId) return;
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
toggleExpanded(cursorId);
|
|
102
|
+
} else if (e.key === 'Home') {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
cursorId = ids[0] ?? null;
|
|
105
|
+
} else if (e.key === 'End') {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
cursorId = ids[ids.length - 1] ?? null;
|
|
108
|
+
} else if (e.key === 'Escape') {
|
|
109
|
+
cursorId = null;
|
|
110
|
+
isKeyboardMode = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function startDrag(e: PointerEvent, id: string) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
isDragging = true;
|
|
117
|
+
draggingId = id;
|
|
118
|
+
ghostPos = { x: e.clientX + 12, y: e.clientY - 8 };
|
|
119
|
+
window.addEventListener('pointermove', onDragMove);
|
|
120
|
+
window.addEventListener('pointerup', onDragEnd);
|
|
121
|
+
window.addEventListener('pointercancel', onDragEnd);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function onDragMove(e: PointerEvent) {
|
|
125
|
+
ghostPos = { x: e.clientX + 12, y: e.clientY - 8 };
|
|
126
|
+
if (!containerEl) return;
|
|
127
|
+
const rows = Array.from(containerEl.querySelectorAll<HTMLElement>('[data-inspector-row]'));
|
|
128
|
+
let found = rows.length;
|
|
129
|
+
for (let i = 0; i < rows.length; i++) {
|
|
130
|
+
const rect = rows[i].getBoundingClientRect();
|
|
131
|
+
if (e.clientY < rect.top + rect.height / 2) {
|
|
132
|
+
found = i;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
dragOverIndex = found;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function onDragEnd() {
|
|
140
|
+
window.removeEventListener('pointermove', onDragMove);
|
|
141
|
+
window.removeEventListener('pointerup', onDragEnd);
|
|
142
|
+
window.removeEventListener('pointercancel', onDragEnd);
|
|
143
|
+
|
|
144
|
+
if (draggingId !== null && dragOverIndex !== null) {
|
|
145
|
+
const fromIndex = cards.findIndex((c) => c.id === draggingId);
|
|
146
|
+
if (fromIndex !== -1) {
|
|
147
|
+
const next = [...cards];
|
|
148
|
+
const [item] = next.splice(fromIndex, 1);
|
|
149
|
+
const insertAt = dragOverIndex > fromIndex ? dragOverIndex - 1 : dragOverIndex;
|
|
150
|
+
next.splice(insertAt, 0, item);
|
|
151
|
+
cards = next;
|
|
152
|
+
onCardsChange?.(next);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
isDragging = false;
|
|
157
|
+
draggingId = null;
|
|
158
|
+
dragOverIndex = null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
$effect(() => {
|
|
162
|
+
if (!isDragging) return;
|
|
163
|
+
document.body.style.cursor = 'grabbing';
|
|
164
|
+
return () => {
|
|
165
|
+
document.body.style.cursor = '';
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
{#if isDragging}
|
|
171
|
+
<div
|
|
172
|
+
use:portal
|
|
173
|
+
style="position:fixed;z-index:9999;left:{ghostPos.x}px;top:{ghostPos.y}px;pointer-events:none"
|
|
174
|
+
class="bg-background border-border text-foreground max-w-48 truncate rounded-md border px-2 py-1 text-sm shadow-lg"
|
|
175
|
+
>
|
|
176
|
+
{cards.find((c) => c.id === draggingId)?.title ?? ''}
|
|
177
|
+
</div>
|
|
178
|
+
{/if}
|
|
179
|
+
|
|
180
|
+
<div
|
|
181
|
+
bind:this={containerEl}
|
|
182
|
+
role="tree"
|
|
183
|
+
tabindex="0"
|
|
184
|
+
data-slot="inspector-panel"
|
|
185
|
+
class={cn('flex flex-col gap-1 text-sm outline-none select-none', className)}
|
|
186
|
+
onkeydown={handleKeyDown}
|
|
187
|
+
onpointerdown={() => {
|
|
188
|
+
isKeyboardMode = false;
|
|
189
|
+
}}
|
|
190
|
+
onfocus={() => {
|
|
191
|
+
if (containerEl?.matches(':focus-visible')) {
|
|
192
|
+
isKeyboardMode = true;
|
|
193
|
+
if (!cursorId) cursorId = cards[0]?.id ?? null;
|
|
194
|
+
}
|
|
195
|
+
}}
|
|
196
|
+
onfocusin={(e) => {
|
|
197
|
+
if (e.target !== containerEl) {
|
|
198
|
+
isKeyboardMode = false;
|
|
199
|
+
cursorId = null;
|
|
200
|
+
}
|
|
201
|
+
}}
|
|
202
|
+
ondragstart={(e) => e.preventDefault()}
|
|
203
|
+
>
|
|
204
|
+
{#each cards as card, i (card.id)}
|
|
205
|
+
{@const isExpanded = expandedIds.includes(card.id)}
|
|
206
|
+
{@const isCursor = cursorId === card.id && isKeyboardMode}
|
|
207
|
+
{@const isDraggingThis = draggingId === card.id}
|
|
208
|
+
{@const showDropAbove = isDragging && dragOverIndex === i && draggingId !== card.id}
|
|
209
|
+
{@const showDropBelow =
|
|
210
|
+
isDragging &&
|
|
211
|
+
dragOverIndex === cards.length &&
|
|
212
|
+
i === cards.length - 1 &&
|
|
213
|
+
draggingId !== card.id}
|
|
214
|
+
|
|
215
|
+
<div
|
|
216
|
+
role="treeitem"
|
|
217
|
+
aria-expanded={isExpanded}
|
|
218
|
+
aria-selected={false}
|
|
219
|
+
data-inspector-row
|
|
220
|
+
data-id={card.id}
|
|
221
|
+
class={cn(
|
|
222
|
+
'border-border relative flex flex-col rounded-md border transition-opacity duration-150',
|
|
223
|
+
isDraggingThis && 'opacity-30',
|
|
224
|
+
isCursor && 'ring-primary ring-1 ring-inset'
|
|
225
|
+
)}
|
|
226
|
+
>
|
|
227
|
+
{#if showDropAbove}
|
|
228
|
+
<div
|
|
229
|
+
class="bg-primary pointer-events-none absolute inset-x-1 h-px rounded-full"
|
|
230
|
+
style="top: -2.5px"
|
|
231
|
+
></div>
|
|
232
|
+
{/if}
|
|
233
|
+
{#if showDropBelow}
|
|
234
|
+
<div
|
|
235
|
+
class="bg-primary pointer-events-none absolute inset-x-1 h-px rounded-full"
|
|
236
|
+
style="bottom: -2.5px"
|
|
237
|
+
></div>
|
|
238
|
+
{/if}
|
|
239
|
+
<!-- Header -->
|
|
240
|
+
<div class="hover:bg-muted/50 flex items-center rounded-sm px-2 py-1.5 transition-colors">
|
|
241
|
+
<button
|
|
242
|
+
tabindex="-1"
|
|
243
|
+
aria-expanded={isExpanded}
|
|
244
|
+
class="flex flex-1 cursor-default items-center gap-1.5 text-left"
|
|
245
|
+
onclick={() => {
|
|
246
|
+
cursorId = card.id;
|
|
247
|
+
isKeyboardMode = false;
|
|
248
|
+
toggleExpanded(card.id);
|
|
249
|
+
}}
|
|
250
|
+
>
|
|
251
|
+
<MingcuteRightLine
|
|
252
|
+
class={cn(
|
|
253
|
+
'text-muted-foreground size-3.5 shrink-0 transition-transform duration-200',
|
|
254
|
+
isExpanded && 'rotate-90'
|
|
255
|
+
)}
|
|
256
|
+
/>
|
|
257
|
+
<span class="flex-1 font-medium leading-none">{card.title}</span>
|
|
258
|
+
{#if card.subtitle}
|
|
259
|
+
<span class="text-muted-foreground text-xs">{card.subtitle}</span>
|
|
260
|
+
{/if}
|
|
261
|
+
</button>
|
|
262
|
+
<button
|
|
263
|
+
tabindex="-1"
|
|
264
|
+
aria-label="Drag to reorder {card.title}"
|
|
265
|
+
class="text-muted-foreground hover:text-foreground ml-1 flex shrink-0 cursor-grab items-center rounded transition-colors active:cursor-grabbing"
|
|
266
|
+
onpointerdown={(e) => {
|
|
267
|
+
e.stopPropagation();
|
|
268
|
+
startDrag(e, card.id);
|
|
269
|
+
}}
|
|
270
|
+
onclick={(e) => e.stopPropagation()}
|
|
271
|
+
>
|
|
272
|
+
<span class="grid grid-cols-2 gap-0.75 p-0.5">
|
|
273
|
+
{#each [0, 1, 2, 3, 4, 5] as dot (dot)}
|
|
274
|
+
<span class="bg-current size-0.75 rounded-full"></span>
|
|
275
|
+
{/each}
|
|
276
|
+
</span>
|
|
277
|
+
</button>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<!-- Content -->
|
|
281
|
+
<div
|
|
282
|
+
class={cn(
|
|
283
|
+
'grid transition-[grid-template-rows] duration-200 ease-out',
|
|
284
|
+
isExpanded ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]'
|
|
285
|
+
)}
|
|
286
|
+
>
|
|
287
|
+
<div class="overflow-hidden">
|
|
288
|
+
<div class="border-border border-t px-3 py-2.5">
|
|
289
|
+
{#if content}
|
|
290
|
+
{@render content(card)}
|
|
291
|
+
{/if}
|
|
292
|
+
</div>
|
|
293
|
+
</div>
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
{/each}
|
|
297
|
+
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
type InspectorCard = {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
subtitle?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
type $$ComponentProps = {
|
|
9
|
+
class?: string;
|
|
10
|
+
cards?: InspectorCard[];
|
|
11
|
+
expandedIds?: string[];
|
|
12
|
+
content?: Snippet<[InspectorCard]>;
|
|
13
|
+
onCardsChange?: (cards: InspectorCard[]) => void;
|
|
14
|
+
onExpandedChange?: (expandedIds: string[]) => void;
|
|
15
|
+
};
|
|
16
|
+
declare const InspectorPanel: import("svelte").Component<$$ComponentProps, {}, "cards" | "expandedIds">;
|
|
17
|
+
type InspectorPanel = ReturnType<typeof InspectorPanel>;
|
|
18
|
+
export default InspectorPanel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as InspectorPanel } from './InspectorPanel.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as InspectorPanel } from './InspectorPanel.svelte';
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
{#each items as item (item.value)}
|
|
35
35
|
<ToggleGroup.Item
|
|
36
36
|
value={item.value}
|
|
37
|
-
class="text-muted-foreground hover:text-foreground data-[state=on]:bg-background data-[state=on]:text-foreground inline-flex h-7 items-center justify-center rounded-md px-3 text-sm font-medium transition-colors data-[state=on]:shadow-sm"
|
|
37
|
+
class="text-muted-foreground hover:text-foreground data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:border-border inline-flex h-7 items-center justify-center rounded-md border border-transparent px-3 text-sm font-medium transition-colors data-[state=on]:shadow-sm"
|
|
38
38
|
data-slot="toggle-group-item"
|
|
39
39
|
>
|
|
40
40
|
{@render item.content()}
|
package/dist/index.d.ts
CHANGED
|
@@ -85,5 +85,6 @@ export * from './components/circular-slider';
|
|
|
85
85
|
export * from './components/calendar';
|
|
86
86
|
export * from './components/tour';
|
|
87
87
|
export * from './components/theme-switch';
|
|
88
|
+
export * from './components/inspector-panel';
|
|
88
89
|
export * from './components/horizon-layout';
|
|
89
90
|
export { createMonacoTheme } from './monaco-theme';
|
package/dist/index.js
CHANGED
|
@@ -87,5 +87,6 @@ export * from './components/circular-slider';
|
|
|
87
87
|
export * from './components/calendar';
|
|
88
88
|
export * from './components/tour';
|
|
89
89
|
export * from './components/theme-switch';
|
|
90
|
+
export * from './components/inspector-panel';
|
|
90
91
|
export * from './components/horizon-layout';
|
|
91
92
|
export { createMonacoTheme } from './monaco-theme';
|