Skip to content

Commit

Permalink
drop zone should be in core.
Browse files Browse the repository at this point in the history
  • Loading branch information
sashamilenkovic committed Jan 4, 2024
1 parent 7975e19 commit fe39b1e
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 147 deletions.
52 changes: 29 additions & 23 deletions docs/pages/playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,34 @@ dragAndDrop({
});
onMounted(() => {
dragAndDrop({
parent: secondList,
values: secondListValues,
config: {
draggable: (child: HTMLElement) => {
return child.classList.contains("item");
},
plugins: [
dropZone({
group: "test",
dropZones: [dropZoneHere, dropZoneHere2],
//dropZones: [document.getElementById("first_list_target")],
}),
//dropZones: [{ element: dropZoneHere }, { element: dropZoneHere2 }],
],
},
//config: {
// dropZoneClass: "opacity",
// draggable: (child: HTMLElement) => {
// return child.classList.contains("item");
// },
//},
});
//dragAndDrop({
// parent: secondList,
// values: secondListValues,
// config: {
// draggable: (child: HTMLElement) => {
// return child.classList.contains("item");
// },
// plugins: [
// //dropZone({
// // group: "test",
// // dropZones: [
// // { element: dropZoneHere, config: { test: "hello" } },
// // { element: dropZoneHere2, position: "bottom" },
// // document.getElementById("first_list_target"),
// // ],
// // //dropZones: [dropZoneHere, dropZoneHere2],
// // //dropZones: [document.getElementById("first_list_target")],
// //}),
// //dropZones: [{ element: dropZoneHere }, { element: dropZoneHere2 }],
// ],
// },
// //config: {
// // dropZoneClass: "opacity",
// // draggable: (child: HTMLElement) => {
// // return child.classList.contains("item");
// // },
// //},
//});
});
const testValues1 = computed(() => {
Expand Down Expand Up @@ -112,6 +117,7 @@ setTimeout(() => {
id="second_list_values"
class="values"
/>
<div id="third_list_target">Hello</div>
</div>
</main>
</template>
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ export default function initParent({

const currentPlugins = Data.parents.get(parent)?.config?.plugins;
currentPlugins?.forEach((plugin) => {
plugin(parent, config, globals()).tearDown();
console.log("tear down", plugin);
//plugin(parent, config, globals()).tearDown();
//console.log("tear down", plugin);
//plugin(parent, config, globals()).tearDown();
//if (plugin.tearDown) {
// plugin.tearDown(parent, config, globals());
//}
});
return;
const mergedConfig = { ...defaultActions, root: document, ...config };

Data.parents.set(parent, {
Expand Down
114 changes: 0 additions & 114 deletions src/plugins/dropZone/vue/index.ts

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { VueDropZoneConfig } from "./vue/types";

export function dropZone(dzConfig: VueDropZoneConfig = {}) {
export default function dropZone(dzConfig: VueDropZoneConfig = {}) {

Check failure on line 3 in src/plugins/selections/index.ts

View workflow job for this annotation

GitHub Actions / lint

'dzConfig' is assigned a value but never used
//console.log("init dropzone", parent, config, globals);
// end-user scope
console.log("dropZone plugin in index");
return () => {
return {
setup() {},
tearDown() {},
};
};
//return () => {
// return {
// setup() {},
// tearDown() {},
// };
//};
}

//function
95 changes: 95 additions & 0 deletions src/plugins/selections/vue/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//import type { DropZone } from "../../../types";
import type { VueDropZoneConfig, VueDropZone, VueElement } from "./types";

import { watch } from "vue";

import { isBrowser } from "../../../utils";

import { getEl } from "../../../vue/utils";

import initDropZone from "../index";

export function dropZone(dzConfig: VueDropZoneConfig = {}) {
console.log("hello", dzConfig);
//console.log("dropzone", setUpDropZone);

if (!isBrowser || !dzConfig.dropZones?.length) return;

const enabledDZs = [];

Check failure on line 18 in src/plugins/selections/vue/index.ts

View workflow job for this annotation

GitHub Actions / lint

'enabledDZs' is assigned a value but never used

console.log("dropZone plugin in index");

dzConfig.dropZones.forEach((dz: VueDropZone | VueElement) => {
console.log("dz", dz);
const validParent = getEl(dz.element);

console.log("validParent", validParent);

//return;

if (validParent) {
return initDropZone(validParent);
} else {
const stop = watch(dz, (newParent) => {
if (!newParent) return;

const validParent = getEl(newParent);

if (!validParent) {
console.warn("Invalid parent element", newParent);
} else {
initDropZone(validParent, dnd);
}

stop();
});
}
});
}

//setup({})(null, null, null);

// parent html element

//return (parent: HTMLElement) => {
// return {
// setup,
// teardown
// }
//}

//return {
// setup,
// tearDown,
//};

//if (dzConfig.dropZones && isBrowser) {
// const dropZones = dzConfig.dropZones;

// for (const dz of dropZones) {
// const el = getEl(dz.element);

// if (el instanceof HTMLElement) {
// enabledDZs.push(el);
// } else {
// const stop = watch(dz.element, (newEl) => {
// if (newEl instanceof HTMLElement) {
// stop();

// enabledDZs.push(newEl);

// return setUpDropZone(dzConfig, parent, globals);
// } else {
// console.warn("Invalid dropzone element", newEl);
// }
// });
// }
// }

// delete dzConfig.dropZones;
//}

//dzConfig.validDropZones = enabledDZs;

//return setUpDropZone(dzConfig, parent, globals);
//}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ export interface VueDropZone extends Omit<DropZone, "element"> {
}

export interface VueDropZoneConfig extends Omit<DropZoneConfig, "dropZones"> {
dropZones?: Array<VueDropZone>;
dropZones?: Array<VueDropZone> | Array<VueElement>;
}

//export type VueDropZone =

0 comments on commit fe39b1e

Please sign in to comment.