362 lines
8.1 KiB
Vue
362 lines
8.1 KiB
Vue
<template>
|
|
<div class="panel">
|
|
<div class="panel-header">
|
|
<div class="panel-title-row">
|
|
<h2 class="panel-title">Selected items</h2>
|
|
<span v-if="items.length" class="item-count">{{ items.length }}</span>
|
|
</div>
|
|
<div class="search-wrap">
|
|
<span class="search-icon" aria-hidden="true">
|
|
<svg width="13" height="13" viewBox="0 0 13 13" fill="none">
|
|
<circle cx="5.5" cy="5.5" r="4" stroke="currentColor" stroke-width="1.4" />
|
|
<path d="M8.5 8.5L11.5 11.5" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
|
|
</svg>
|
|
</span>
|
|
<input
|
|
class="search-input"
|
|
type="text"
|
|
placeholder="Search by ID..."
|
|
:value="search"
|
|
@input="onSearchInput"
|
|
>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel-body">
|
|
<VueDraggableNext
|
|
v-model="localItems"
|
|
tag="ul"
|
|
class="item-list"
|
|
handle=".drag-handle"
|
|
@end="onDragEnd"
|
|
>
|
|
<li
|
|
v-for="(item, index) in localItems"
|
|
:key="item.id"
|
|
class="item-row"
|
|
:style="{ '--i': Math.min(index, 14) }"
|
|
>
|
|
<span class="drag-handle" title="Drag to reorder" aria-hidden="true">
|
|
<svg width="8" height="12" viewBox="0 0 8 12" fill="currentColor">
|
|
<circle cx="2" cy="2" r="1.2" />
|
|
<circle cx="6" cy="2" r="1.2" />
|
|
<circle cx="2" cy="6" r="1.2" />
|
|
<circle cx="6" cy="6" r="1.2" />
|
|
<circle cx="2" cy="10" r="1.2" />
|
|
<circle cx="6" cy="10" r="1.2" />
|
|
</svg>
|
|
</span>
|
|
<span class="item-order">{{ index + 1 }}</span>
|
|
<span class="item-id">{{ item.id }}</span>
|
|
<button class="action-btn" title="Remove from selected" @click="emit('deselect', item.id!)">
|
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
|
<path d="M11.5 7H2.5M5.5 3.5L2 7L5.5 10.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
|
|
</svg>
|
|
</button>
|
|
</li>
|
|
</VueDraggableNext>
|
|
|
|
<div v-if="loading" class="status-row">
|
|
<span class="status-dots">
|
|
<span /><span /><span />
|
|
</span>
|
|
</div>
|
|
<div v-if="hasMore && !loading" ref="sentinel" class="sentinel" />
|
|
<div v-if="!loading && !hasMore && items.length === 0" class="empty-state">
|
|
<span class="empty-label">No items selected</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type { Item } from '~/services/api'
|
|
import { onUnmounted, ref, watch } from 'vue'
|
|
import { VueDraggableNext } from 'vue-draggable-next'
|
|
|
|
const props = defineProps<{
|
|
items: Item[]
|
|
loading: boolean
|
|
hasMore: boolean
|
|
search: string
|
|
}>()
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'update:search', val: string): void
|
|
(e: 'loadMore'): void
|
|
(e: 'deselect', id: number): void
|
|
(e: 'reorder', ids: number[]): void
|
|
}>()
|
|
|
|
const sentinel = ref<HTMLElement | null>(null)
|
|
let observer: IntersectionObserver | null = null
|
|
|
|
watch(sentinel, (el) => {
|
|
if (observer) {
|
|
observer.disconnect()
|
|
observer = null
|
|
}
|
|
if (el) {
|
|
observer = new IntersectionObserver((entries) => {
|
|
if (entries[0]?.isIntersecting && props.hasMore && !props.loading) {
|
|
emit('loadMore')
|
|
}
|
|
}, { threshold: 0.1 })
|
|
observer.observe(el)
|
|
}
|
|
})
|
|
|
|
onUnmounted(() => {
|
|
observer?.disconnect()
|
|
})
|
|
|
|
let debounceTimer: ReturnType<typeof setTimeout> | null = null
|
|
|
|
function onSearchInput(e: Event) {
|
|
const val = (e.target as HTMLInputElement).value
|
|
if (debounceTimer)
|
|
clearTimeout(debounceTimer)
|
|
debounceTimer = setTimeout(() => {
|
|
emit('update:search', val)
|
|
}, 300)
|
|
}
|
|
|
|
const localItems = ref([...props.items])
|
|
|
|
watch(() => props.items, (val) => {
|
|
localItems.value = [...val]
|
|
}, { deep: true })
|
|
|
|
function onDragEnd(): void {
|
|
const ids = localItems.value.map(i => i.id!)
|
|
emit('reorder', ids)
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.panel {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
background: var(--canvas);
|
|
}
|
|
|
|
/* ── Header ── */
|
|
.panel-header {
|
|
padding: 18px 20px 16px;
|
|
border-bottom: 1px solid var(--border);
|
|
background: var(--surface);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.panel-title-row {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.panel-title {
|
|
margin: 0;
|
|
font-size: 0.72rem;
|
|
font-weight: 500;
|
|
letter-spacing: 0.06em;
|
|
text-transform: uppercase;
|
|
color: var(--text-secondary);
|
|
font-family: var(--font-sans);
|
|
}
|
|
|
|
.item-count {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
min-width: 18px;
|
|
height: 18px;
|
|
padding: 0 5px;
|
|
background: var(--surface-subtle);
|
|
border: 1px solid var(--border);
|
|
border-radius: 9999px;
|
|
font-family: var(--font-mono);
|
|
font-size: 0.65rem;
|
|
color: var(--text-secondary);
|
|
}
|
|
|
|
.search-wrap {
|
|
position: relative;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
|
|
.search-icon {
|
|
position: absolute;
|
|
left: 10px;
|
|
display: flex;
|
|
align-items: center;
|
|
color: var(--text-muted);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.search-input {
|
|
width: 100%;
|
|
padding: 7px 12px 7px 30px;
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-sm);
|
|
background: var(--surface-subtle);
|
|
font-family: var(--font-sans);
|
|
font-size: 0.825rem;
|
|
color: var(--text-primary);
|
|
outline: none;
|
|
transition: border-color 150ms ease, background 150ms ease;
|
|
|
|
&::placeholder {
|
|
color: var(--text-muted);
|
|
}
|
|
|
|
&:focus {
|
|
border-color: var(--text-primary);
|
|
background: var(--surface);
|
|
}
|
|
}
|
|
|
|
/* ── Body & list ── */
|
|
.panel-body {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
|
|
&::-webkit-scrollbar { width: 3px; }
|
|
&::-webkit-scrollbar-track { background: transparent; }
|
|
&::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
|
|
}
|
|
|
|
.item-list {
|
|
list-style: none;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
@keyframes item-in {
|
|
from { opacity: 0; transform: translateY(6px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
|
|
.item-row {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
padding: 9px 12px 9px 14px;
|
|
border-bottom: 1px solid var(--border);
|
|
animation: item-in 350ms cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
animation-delay: calc(var(--i, 0) * 25ms);
|
|
transition: background 120ms ease;
|
|
|
|
&:hover {
|
|
background: var(--surface-subtle);
|
|
|
|
.action-btn { opacity: 1; }
|
|
.drag-handle { color: var(--text-secondary); }
|
|
}
|
|
}
|
|
|
|
.drag-handle {
|
|
cursor: grab;
|
|
color: var(--text-muted);
|
|
display: flex;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
padding: 2px;
|
|
transition: color 120ms ease;
|
|
user-select: none;
|
|
|
|
&:active { cursor: grabbing; }
|
|
}
|
|
|
|
.item-order {
|
|
font-family: var(--font-mono);
|
|
font-size: 0.68rem;
|
|
color: var(--text-muted);
|
|
min-width: 18px;
|
|
text-align: right;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.item-id {
|
|
flex: 1;
|
|
font-family: var(--font-mono);
|
|
font-size: 0.8rem;
|
|
color: var(--text-primary);
|
|
|
|
&::before {
|
|
content: '#';
|
|
color: var(--text-muted);
|
|
margin-right: 1px;
|
|
}
|
|
}
|
|
|
|
.action-btn {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 28px;
|
|
height: 28px;
|
|
background: none;
|
|
border: none;
|
|
border-radius: var(--radius-sm);
|
|
color: var(--text-secondary);
|
|
cursor: pointer;
|
|
opacity: 0;
|
|
flex-shrink: 0;
|
|
transition: color 120ms ease, background 120ms ease, opacity 120ms ease;
|
|
|
|
&:hover {
|
|
color: var(--text-primary);
|
|
background: var(--border);
|
|
}
|
|
}
|
|
|
|
/* ── States ── */
|
|
.status-row {
|
|
display: flex;
|
|
justify-content: center;
|
|
padding: 24px;
|
|
}
|
|
|
|
.status-dots {
|
|
display: flex;
|
|
gap: 5px;
|
|
align-items: center;
|
|
|
|
span {
|
|
width: 4px;
|
|
height: 4px;
|
|
border-radius: 50%;
|
|
background: var(--text-muted);
|
|
animation: dot-blink 1.2s ease-in-out infinite;
|
|
|
|
&:nth-child(2) { animation-delay: 0.2s; }
|
|
&:nth-child(3) { animation-delay: 0.4s; }
|
|
}
|
|
}
|
|
|
|
@keyframes dot-blink {
|
|
0%, 80%, 100% { opacity: 0.25; }
|
|
40% { opacity: 1; }
|
|
}
|
|
|
|
.empty-state {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 56px 24px;
|
|
}
|
|
|
|
.empty-label {
|
|
font-size: 0.8rem;
|
|
color: var(--text-muted);
|
|
letter-spacing: 0.02em;
|
|
}
|
|
|
|
.sentinel {
|
|
height: 1px;
|
|
}
|
|
</style>
|