📄 useSortable¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 10 |
| 📦 Imports | 14 |
| 🟢 Vue Composition API | 1 |
| 📐 Interfaces | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/integrations/useSortable/index.ts
📦 Imports¶
| Name | Source |
|---|---|
ConfigurableDocument |
@vueuse/core |
MaybeElement |
@vueuse/core |
Options |
sortablejs |
MaybeRef |
vue |
MaybeRefOrGetter |
vue |
defaultDocument |
@vueuse/core |
tryOnMounted |
@vueuse/core |
tryOnScopeDispose |
@vueuse/core |
unrefElement |
@vueuse/core |
Sortable |
sortablejs |
isRef |
vue |
nextTick |
vue |
toValue |
vue |
watch |
vue |
Vue Composition API¶
| Name | Type | Reactive Variables | Composables |
|---|---|---|---|
watch |
watch | none | none |
Functions¶
useSortable(selector: string, list: MaybeRef<T[]>, options: UseSortableOptions): UseSortableReturn¶
Parameters:
selectorstringlistMaybeRef<T[]>optionsUseSortableOptions
Returns: UseSortableReturn
Code
insertNodeAt(parentElement: Element, element: Element, index: number): void¶
Inserts a element into the DOM at a given index.
Parameters:
parentElementany: No descriptionelementany: No descriptionindexnumber: No description
Raw JSDoc
Calls:
parentElement.insertBefore
Code
removeNode(node: Node): void¶
Removes a node from the DOM.
Parameters:
nodeNode: No description
Raw JSDoc
Calls:
node.parentNode.removeChild
Code
moveArrayElement(list: MaybeRef<T[]>, from: number, to: number, e: Sortable.SortableEvent | null): void¶
Parameters:
listMaybeRef<T[]>fromnumbertonumbereSortable.SortableEvent | null
Returns: void
Calls:
removeNodeinsertNodeAtisRef (from vue)toValue (from vue)array.splicenextTick (from vue)
Internal Comments:
// When the list is a ref, make a shallow copy of it to avoid repeatedly triggering side effects when moving elements (x2)
// When list is ref, assign array to list.value
Code
export function moveArrayElement<T>(
list: MaybeRef<T[]>,
from: number,
to: number,
e: Sortable.SortableEvent | null = null,
): void {
if (e != null) {
removeNode(e.item)
insertNodeAt(e.from, e.item, from)
}
const _valueIsRef = isRef(list)
// When the list is a ref, make a shallow copy of it to avoid repeatedly triggering side effects when moving elements
const array = _valueIsRef ? [...toValue(list)] : toValue(list)
if (to >= 0 && to < array.length) {
const element = array.splice(from, 1)[0]
nextTick(() => {
array.splice(to, 0, element)
// When list is ref, assign array to list.value
if (_valueIsRef)
(list as MaybeRef).value = array
})
}
}
Internal helpers¶
Declared inside another function in this file.
onUpdate(e: any): void¶
Parameters:
eany
Returns: void
Calls:
moveArrayElement
cleanup(): void¶
Returns: void
Calls:
sortable?.destroy
initSortable(target: Element): void¶
Parameters:
targetElement
Returns: void
Code
start(): void¶
Returns: void
Calls:
document?.querySelectorunrefElement (from @vueuse/core)initSortable
Code
option(name: K, value: Options[K]): any¶
Parameters:
nameKvalueOptions[K]
Returns: any
Calls:
sortable?.option
Code
stop(): void¶
Returns: void
Calls:
cleanup
Interfaces¶
UseSortableReturn¶
Interface Code
export interface UseSortableReturn {
/**
* start sortable instance
*/
start: () => void
/**
* destroy sortable instance
*/
stop: () => void
/**
* Options getter/setter
* @param name a Sortable.Options property.
* @param value a value.
*/
option: (<K extends keyof Sortable.Options>(name: K, value: Sortable.Options[K]) => void) & (<K extends keyof Sortable.Options>(name: K) => Sortable.Options[K])
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
start |
() => void |
✗ | not shown |
stop |
() => void |
✗ | not shown |
option |
(<K extends keyof Sortable.Options>(name: K, value: Sortable.Options[K]) => v... |
✗ | not shown |
UseSortableOptions¶
Interface Code
export interface UseSortableOptions extends Options, ConfigurableDocument {
/**
* Watch the element reference for changes and automatically reinitialize Sortable
* when the element changes.
*
* When `false` (default), Sortable is only initialized once on mount.
* You must manually call `start()` if the element reference changes.
*
* When `true`, automatically watches the element reference and reinitializes
* Sortable whenever it changes (e.g., conditional rendering with v-if).
*
* @default false
*/
watchElement?: boolean
}
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
watchElement |
boolean |
✓ | not shown |
Generated by Syntax Scribe