=============== LIBRARY RULES =============== From library maintainers: - Always import from '@thisux/sveltednd' not from internal paths - Use Svelte 5 runes ($state, $effect) not legacy stores - draggable and droppable are Svelte actions used with use: directive - For grid/flex-wrap layouts set direction: 'grid' on droppable - Import '@thisux/sveltednd/dnd.css' for drop position indicator styles ### Install @thisux/sveltednd Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Installation commands for various package managers. ```bash npm install @thisux/sveltednd # or bun add @thisux/sveltednd # or yarn add @thisux/sveltednd # or pnpm add @thisux/sveltednd ``` -------------------------------- ### Initialize Project Environment Source: https://github.com/thisuxhq/sveltednd/blob/main/CONTRIBUTING.md Clone the repository and install dependencies to begin development. ```bash git clone https://github.com/thisuxhq/sveltednd.git cd sveltednd bun install ``` -------------------------------- ### Installation Source: https://context7.com/thisuxhq/sveltednd/llms.txt Install the @thisux/sveltednd package using your preferred package manager. ```APIDOC ## Installation Install the package from npm using your preferred package manager. ```bash npm install @thisux/sveltednd # or bun add @thisux/sveltednd # or yarn add @thisux/sveltednd # or pnpm add @thisux/sveltednd ``` ``` -------------------------------- ### Kanban Board Example Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Demonstrates a Kanban board with multiple containers (columns) for different task statuses. The handleDrop function updates the card's status based on the target container. ```svelte
{#each columns as column}

{column}

{#each cards.filter((c) => c.status === column) as card (card.id)}
{card.title}
{/each}
{/each}
``` -------------------------------- ### Drag Handle Pattern Example Source: https://context7.com/thisuxhq/sveltednd/llms.txt This example demonstrates the Drag Handle pattern, where dragging is initiated only by a specific element (e.g., a grip icon), allowing other parts of the draggable item to remain interactive. ```APIDOC ## Drag Handle Pattern Use the `handle` option to restrict drag initiation to a specific element. This enables patterns where only a grip icon or handle starts the drag, keeping the rest of the content interactive (text remains selectable, buttons remain clickable). ### Svelte Component Example ```svelte {#each items as item, index (item.id)}

{item.title}

{item.description}

{/each} ``` ``` -------------------------------- ### Commit Message Examples Source: https://github.com/thisuxhq/sveltednd/blob/main/AGENTS.md Examples of valid commit messages following the specified format. These messages indicate the type of change and a brief description. ```git commit feat: add keyboard drag support ``` ```git commit fix: prevent stuck drag state on mobile ``` ```git commit docs: update README with touch examples ``` ```git commit chore: bump dependencies ``` -------------------------------- ### Implement Drag and Drop in Svelte Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md A complete example showing how to use draggable and droppable actions with Svelte 5 state. ```svelte {#each items as item, index (item)}
{item}
{/each} ``` -------------------------------- ### Svelte Draggable and Droppable Example Source: https://context7.com/thisuxhq/sveltednd/llms.txt Example of using the `draggable` and `droppable` actions in a Svelte component to manage a list of tasks. The `handleDrop` function reorders the tasks based on drop position. ```svelte {#each tasks as task, index (task.id)}
console.log('Started dragging:', state.draggedItem.title), onDragEnd: (state) => console.log('Finished dragging') } }} use:droppable={{ container: index.toString(), callbacks: { onDrop: handleDrop } }} class="task-item" >

{task.title}

{task.description}

{/each} ``` -------------------------------- ### Implement Svelte actions pattern Source: https://github.com/thisuxhq/sveltednd/blob/main/AGENTS.md Standard structure for Svelte actions, including setup, update, and destroy lifecycle methods. ```typescript export function actionName(node: HTMLElement, options: Options) { // Setup logic function handleEvent(event: Event) {} node.addEventListener('event', handleEvent); return { update(newOptions: Options) { options = newOptions; }, destroy() { node.removeEventListener('event', handleEvent); } }; } ``` -------------------------------- ### Sortable List Example Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Implements a sortable list where items can be reordered within the same container. The handleDrop function updates the tasks array based on the drop state. ```svelte
{#each tasks as task, index (task.id)}
{task.title}
{/each}
``` -------------------------------- ### Run Project Commands Source: https://github.com/thisuxhq/sveltednd/blob/main/CLAUDE.md Common CLI commands for development, building, testing, and linting the library. ```bash bun run dev # Dev server bun run build # Production build (vite build + svelte-package + publint) bun run package # Package library only bun run check # Type-check (svelte-check) bun run lint # Prettier check + ESLint bun run format # Auto-format with Prettier bun run test # Run all tests once (vitest --run) bun run test:unit # Tests in watch mode bun run test:unit -- --run src/lib/actions/draggable.spec.ts # Single test file ``` -------------------------------- ### Execute project build, lint, and test commands Source: https://github.com/thisuxhq/sveltednd/blob/main/AGENTS.md Use these Bun scripts for development, building, code quality checks, and testing. ```bash # Development bun run dev # Start dev server # Building bun run build # Build library for production (vite build + package) bun run package # Create package with svelte-package + publint # Code Quality bun run check # Type-check with svelte-check bun run check:watch # Type-check in watch mode bun run lint # Run Prettier check + ESLint bun run format # Format with Prettier (write) # Testing bun run test # Run all tests once (vitest --run) bun run test:unit # Run tests in watch mode bun run test:unit -- --run src/lib/actions/draggable.spec.ts # Single test file ``` -------------------------------- ### Run Tests Source: https://github.com/thisuxhq/sveltednd/blob/main/CONTRIBUTING.md Execute the test suite to verify changes. ```bash bun run test ``` -------------------------------- ### Format and Lint Code Source: https://github.com/thisuxhq/sveltednd/blob/main/CONTRIBUTING.md Run project-standard formatting and linting tools. ```bash bun run format bun run lint ``` -------------------------------- ### Kanban Board (Multi-Column) with sveltednd Source: https://github.com/thisuxhq/sveltednd/blob/main/static/llms.txt Create a multi-column Kanban board where tasks can be moved between columns. Each task has an ID, title, and status. ```svelte {#each columns as column}

{column}

{#each tasks.filter(t => t.status === column) as task (task.id)}
{task.title}
{/each}
{/each} ``` -------------------------------- ### Implement a Kanban Board with droppable Source: https://context7.com/thisuxhq/sveltednd/llms.txt Uses the droppable action to create drop zones and handle item movement between columns in a Kanban-style layout. ```svelte
{#each columns as status}
console.log('Entered:', status), onDragLeave: (state) => console.log('Left:', status), onDragOver: (state) => console.log('Over:', status) } }} >

{status}

{#each tasks.filter((t) => t.status === status) as task (task.id)}
{task.title}
{/each}
{/each}
``` -------------------------------- ### View project directory structure Source: https://github.com/thisuxhq/sveltednd/blob/main/AGENTS.md Overview of the source code organization for the library. ```text src/ ├── lib/ │ ├── actions/ # draggable.ts, droppable.ts, index.ts │ ├── stores/ # dnd.svelte.ts (state runes) │ ├── types/ # TypeScript interfaces │ ├── styles/ # dnd.css │ └── index.ts # Public API exports └── routes/ # Demo pages (SvelteKit) ``` -------------------------------- ### Droppable Action Options Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Configuration options for the `use:droppable` action to create drop zones. ```APIDOC ## Droppable Options (`DragDropOptions`) ### Description Options to configure the `use:droppable` Svelte action. ### Method None (This is a Svelte action configuration) ### Endpoint None ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Property | Type | Description | | ------------ | -------------------------------------- | ---------------------------------------------------------------------- | | `container` | `string` | **Required.** Container identifier | | `disabled` | `boolean` | Disable dropping for this element | | `direction` | `'vertical' | 'horizontal' | 'grid'` | Layout direction (default: `'vertical'`) | | `callbacks` | `object` | Event callbacks (`onDragEnter`, `onDragLeave`, `onDragOver`, `onDrop`) | | `attributes` | `object` | CSS class overrides (`dragOverClass`) | ### Request Example ```svelte
Drop items here
``` ### Response None (This is a Svelte action configuration) ``` -------------------------------- ### Access Global dndState Source: https://context7.com/thisuxhq/sveltednd/llms.txt Demonstrates how to use the reactive dndState object to track drag operations and update UI in real-time. ```svelte {#if dndState.isDragging}

Dragging: {dndState.draggedItem?.name}

From: {dndState.sourceContainer}

{#if dndState.targetContainer}

Over: {dndState.targetContainer}

Position: {dndState.dropPosition}

{/if} {#if dndState.invalidDrop}

Invalid drop zone!

{/if}
{/if}
{#each items as item, index (item.id)}
{item.name}
{/each}
``` -------------------------------- ### Create Feature Branch Source: https://github.com/thisuxhq/sveltednd/blob/main/CONTRIBUTING.md Create a new branch for implementing features or fixes. ```bash git checkout -b feature/my-new-feature ``` -------------------------------- ### Implement Grid Layout Sorting Source: https://context7.com/thisuxhq/sveltednd/llms.txt Uses direction: 'grid' to enable nearest-edge detection for 2D layouts. Requires CSS to style the drop indicators. ```svelte
{#each cards as card, index (card.id)}
{card.icon}
{/each}
``` -------------------------------- ### Sortable List with sveltednd Source: https://github.com/thisuxhq/sveltednd/blob/main/static/llms.txt Implement a sortable list where items can be reordered by dragging and dropping. Ensure the 'dnd.css' is imported for default styling. ```svelte {#each items as item (item)}
{item}
{/each} ``` -------------------------------- ### Importing CSS Styles Source: https://github.com/thisuxhq/sveltednd/blob/main/static/llms.txt Import the required CSS stylesheet to enable drop position indicators. ```typescript import '@thisux/sveltednd/dnd.css'; // or import '$lib/styles/dnd.css'; ``` -------------------------------- ### Push Changes Source: https://github.com/thisuxhq/sveltednd/blob/main/CONTRIBUTING.md Push the local branch to the remote repository. ```bash git push origin feature/my-new-feature ``` -------------------------------- ### Draggable Action Options Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Configuration options for the `use:draggable` action to make elements draggable. ```APIDOC ## Draggable Options (`DraggableOptions`) ### Description Options to configure the `use:draggable` Svelte action. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Property | Type | Description | | ------------- | ---------- | ------------------------------------------------------------------------- | | `container` | `string` | **Required.** Container identifier for grouping items | | `dragData` | `T` | **Required.** Data payload to transfer during drag | | `disabled` | `boolean` | Disable dragging for this element | | `handle` | `string` | CSS selector for drag handle (e.g., `'.drag-handle'`) | | `interactive` | `string[]` | Additional selectors for interactive elements that shouldn't trigger drag | | `callbacks` | `object` | Event callbacks (`onDragStart`, `onDragEnd`) | | `attributes` | `object` | CSS class overrides (`draggingClass`) | ### Request Example ```svelte
{item.name}
``` ### Response None (This is a Svelte action configuration) ``` -------------------------------- ### Using fromAction with Svelte 5 Components Source: https://context7.com/thisuxhq/sveltednd/llms.txt Demonstrates how to use `fromAction` to enable Svelte actions like `draggable` and `droppable` on components. This is necessary because native Svelte actions only work on HTML elements. Ensure the component spreads props onto its root element to receive the action. ```svelte {#each tasks as task, index (task.id)} {task.title} {/each} ``` ```svelte
{@render children?.()}
``` -------------------------------- ### Run Type Checking Source: https://github.com/thisuxhq/sveltednd/blob/main/CONTRIBUTING.md Execute TypeScript checks to identify potential errors. ```bash bun run check ``` -------------------------------- ### Define Droppable Containers Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Apply the droppable action to an element to create a valid drop zone. ```svelte
``` -------------------------------- ### Implement Horizontal Layout Sorting Source: https://context7.com/thisuxhq/sveltednd/llms.txt Uses direction: 'horizontal' to enable drop indicators as vertical lines for left-to-right lists. ```svelte
{#each tabs as tab, index (tab.id)}
{tab.label}
{/each}
``` -------------------------------- ### Apply Custom CSS Classes Source: https://context7.com/thisuxhq/sveltednd/llms.txt Use the attributes option in draggable and droppable to inject custom CSS classes for dragging and drag-over states. ```svelte {#each items as item, index (item.id)}
{item.name}
{/each} ``` -------------------------------- ### DragDropOptions Interface Source: https://context7.com/thisuxhq/sveltednd/llms.txt Defines the configuration options for both draggable and droppable actions, including layout direction, event callbacks, and CSS class overrides. ```APIDOC ## DragDropOptions Interface ### Description Interface defining the configuration for drag and drop operations. ### Parameters - **container** (string) - Required - Unique identifier for the container. - **dragData** (T) - Optional - Data payload for draggable items. - **disabled** (boolean) - Optional - Disables drag/drop functionality. - **autoScroll** (boolean) - Optional - Enables auto-scroll when dragging near edges. - **direction** ('vertical' | 'horizontal' | 'grid') - Optional - Layout direction for drop calculation. - **callbacks** (object) - Optional - Lifecycle event handlers. - **attributes** (object) - Optional - CSS class overrides for dragging and drag-over states. ``` -------------------------------- ### DraggableOptions Interface Source: https://context7.com/thisuxhq/sveltednd/llms.txt Defines the configuration options for the `draggable` action, including data transfer, drag handles, and event callbacks. ```APIDOC ## DraggableOptions Interface The `DraggableOptions` interface defines all configuration options for the draggable action. It extends the base `DragDropOptions` with additional properties for controlling drag initiation and interactive element handling. ```typescript interface DraggableOptions { // Required: Unique identifier for this container/group container: string; // Required: Data payload to transfer during drag (available in all callbacks) dragData: T; // Optional: Disable dragging for this element disabled?: boolean; // Optional: CSS selector for drag handle (e.g., '.drag-handle') // When provided, only clicks on the handle element start a drag handle?: string; // Optional: Additional selectors for interactive elements that shouldn't trigger drag // Default protected: input, textarea, select, button, [contenteditable], a[href], label, option interactive?: string[]; // Optional: Whether to auto-scroll scrollable ancestors when dragging near edges autoScroll?: boolean; // Optional: Event callbacks for drag lifecycle callbacks?: { onDragStart?: (state: DragDropState) => void; onDragEnd?: (state: DragDropState) => void; }; // Optional: CSS class customization attributes?: { draggingClass?: string; // Default: 'dragging' }; } ``` ``` -------------------------------- ### Define DragDropOptions Interface Source: https://context7.com/thisuxhq/sveltednd/llms.txt Configuration interface for customizing drag-and-drop behavior, including callbacks, layout direction, and CSS classes. ```typescript interface DragDropOptions { // Required: Unique identifier for this container container: string; // Optional: Data payload (used by draggable) dragData?: T; // Optional: Disable drag/drop functionality disabled?: boolean; // Optional: Whether to auto-scroll when dragging near edges (default: true) autoScroll?: boolean; // Optional: Layout direction for drop position calculation // 'vertical' (default): top-to-bottom, horizontal drop indicator line // 'horizontal': left-to-right, vertical drop indicator line // 'grid': 2D layout with nearest-edge detection direction?: 'vertical' | 'horizontal' | 'grid'; // Optional: Event callbacks callbacks?: { onDragStart?: (state: DragDropState) => void; onDragEnter?: (state: DragDropState) => void; onDragLeave?: (state: DragDropState) => void; onDragOver?: (state: DragDropState) => void; onDrop?: (state: DragDropState) => Promise | void; onDragEnd?: (state: DragDropState) => void; }; // Optional: CSS class overrides attributes?: { draggingClass?: string; // Default: 'dragging' dragOverClass?: string; // Default: 'drag-over' }; } ``` -------------------------------- ### Access Global Drag State Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Use the dndState store to reactively track drag operations throughout the application. ```svelte {#if dndState.isDragging}

Dragging {dndState.draggedItem?.name} from {dndState.sourceContainer}

{/if} ``` -------------------------------- ### dndState Source: https://github.com/thisuxhq/sveltednd/blob/main/static/llms.txt Global reactive state object tracking the current drag operation. ```APIDOC ## dndState ### Description A global reactive object (Svelte 5 $state rune) that tracks the current drag operation. Do not mutate manually. ### Fields - **isDragging** (boolean) - True from dragstart until dragend. - **draggedItem** (T | null) - The data payload being dragged. - **sourceContainer** (string) - Container ID where the drag started. - **targetContainer** (string | null) - Container ID currently being hovered over. - **targetElement** (HTMLElement | null) - The specific DOM element under the cursor. - **dropPosition** ('before' | 'after' | null) - Where the item will land relative to targetElement. - **invalidDrop** (boolean) - Set to true when hovering over an invalid drop zone. ``` -------------------------------- ### DragDropOptions Source: https://github.com/thisuxhq/sveltednd/blob/main/static/llms.txt Configuration options for the droppable action to define drop zone behavior and appearance. ```APIDOC ## DragDropOptions ### Description Configuration object passed to the droppable action to define container behavior, data handling, and visual feedback. ### Parameters #### Options - **container** (string) - Required - Identifier for this drop zone. - **dragData** (T) - Optional - Data payload associated with the item. - **disabled** (boolean) - Optional - When true, the element won't accept drops. - **callbacks** (DragDropCallbacks) - Optional - Lifecycle event handlers. - **attributes** (DragDropAttributes) - Optional - Custom CSS class overrides. - **direction** ('vertical' | 'horizontal' | 'grid') - Optional - Controls drop indicator direction. ``` -------------------------------- ### Implement Drag Handle Pattern Source: https://context7.com/thisuxhq/sveltednd/llms.txt Use the handle option in the draggable action to restrict drag initiation to a specific child element. This allows other parts of the component to remain interactive, such as text selection or button clicks. ```svelte {#each items as item, index (item.id)}

{item.title}

{item.description}

{/each} ``` -------------------------------- ### Global Drag and Drop State Source: https://github.com/thisuxhq/sveltednd/blob/main/README.md Access to the current drag and drop state across the application. ```APIDOC ## Global State (`dndState`) ### Description Provides real-time access to the drag and drop state of the application. ### Method None (This is a reactive store) ### Endpoint None ### Parameters None ### Request Example ```svelte {#if dndState.isDragging}

Dragging item: {dndState.draggedItem?.id}

From container: {dndState.sourceContainer}

{:else}

Not currently dragging.

{/if} ``` ### Response #### Success Response (200) `dndState` object with the following properties: - `isDragging` (boolean): Indicates if a drag operation is in progress. - `draggedItem` (any): The data of the item being dragged. - `sourceContainer` (string | null): The identifier of the container from which the item was dragged. - `currentContainer` (string | null): The identifier of the container the item is currently over. #### Response Example ```json { "isDragging": true, "draggedItem": { "id": 1, "name": "Example Item" }, "sourceContainer": "list-a", "currentContainer": "list-b" } ``` ``` -------------------------------- ### Display Real-Time Drag State in Svelte Source: https://github.com/thisuxhq/sveltednd/blob/main/static/llms.txt Use the `dndState` store to display information about the current drag operation, such as whether a drag is in progress and details about the dragged item and target container. ```svelte {#if dndState.isDragging}
Moving: {dndState.draggedItem?.title} → {dndState.targetContainer ?? 'none'}
{/if} ``` -------------------------------- ### Grid Sort with sveltednd Source: https://github.com/thisuxhq/sveltednd/blob/main/static/llms.txt Enable sorting of items within a grid layout. The `direction: 'grid'` option is used for grid-specific drop behavior. ```svelte
{#each cells as cell (cell)}
{cell}
{/each}
```