Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/vue/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { Ref } from "vue";
import type { MaybeRef, Ref } from "vue";
import type { VueDragAndDropData, VueParentConfig } from "./types";
import { dragAndDrop as initParent, isBrowser, tearDown } from "../index";
import { onUnmounted, ref } from "vue";
import { isRef, onUnmounted, ref, unref } from "vue";
import { handleVueElements } from "./utils";
export * from "./types";

/**
* Global store for parent els to values.
*/
const parentValues: WeakMap<HTMLElement, Ref<Array<any>> | Array<any>> =
new WeakMap();
const parentValues: WeakMap<HTMLElement, MaybeRef<Array<any>>> = new WeakMap();

/**
* Returns the values of the parent element.
Expand All @@ -27,7 +26,7 @@ function getValues(parent: HTMLElement): Array<any> {
return [];
}

return "value" in values ? values.value : values;
return unref(values);
}

/**
Expand All @@ -43,8 +42,7 @@ function setValues(newValues: Array<any>, parent: HTMLElement): void {
const currentValues = parentValues.get(parent);

// Only update reactive values. If static, let's not update.
if (currentValues && "value" in currentValues)
currentValues.value = newValues;
if (currentValues && isRef(currentValues)) currentValues.value = newValues;
//else if (currentValues) parentValues.set(parent, newValues);
}
/**
Expand Down Expand Up @@ -110,7 +108,7 @@ export function useDragAndDrop<T>(
*/
function handleParent<T>(
config: Partial<VueParentConfig<T>>,
values: Ref<Array<T>> | Array<T>
values: MaybeRef<Array<T>>
) {
return (parent: HTMLElement) => {
parentValues.set(parent, values);
Expand Down
4 changes: 2 additions & 2 deletions src/vue/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Ref } from "vue";
import type { MaybeRef, Ref } from "vue";
import type { ParentConfig } from "../types";

export type VueElement = HTMLElement | Ref<HTMLElement | undefined>;

export interface VueDragAndDropData<T> extends VueParentConfig<T> {
parent: HTMLElement | Ref<HTMLElement | undefined>;
values: Ref<Array<T>> | Array<T>;
values: MaybeRef<Array<T>>;
}

export type VueParentConfig<T> = Partial<ParentConfig<T>>;