@dnd-kit/solid 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/sortable.js ADDED
@@ -0,0 +1,98 @@
1
+ import { defaultSortableTransition, Sortable } from '@dnd-kit/dom/sortable';
2
+ export { isSortable } from '@dnd-kit/dom/sortable';
3
+ import { batch } from '@dnd-kit/state';
4
+ import { createSignal, createEffect, on } from 'solid-js';
5
+ import { useDeepSignal } from '@dnd-kit/solid/hooks';
6
+ import { useInstance } from '@dnd-kit/solid';
7
+
8
+ // src/sortable/useSortable.ts
9
+ function useSortable(input) {
10
+ const transition = {
11
+ ...defaultSortableTransition,
12
+ ...input.transition
13
+ };
14
+ const sortable = useInstance((manager) => {
15
+ return new Sortable(
16
+ {
17
+ ...input,
18
+ register: false,
19
+ transition,
20
+ element: input.element,
21
+ handle: input.handle,
22
+ target: input.target
23
+ },
24
+ manager
25
+ );
26
+ });
27
+ const trackedSortable = useDeepSignal(() => sortable);
28
+ const [element, setElement] = createSignal(
29
+ input.element
30
+ );
31
+ const [handle, setHandle] = createSignal(input.handle);
32
+ const [source, setSource] = createSignal(input.source);
33
+ const [target, setTarget] = createSignal(input.target);
34
+ createEffect(() => {
35
+ const el = element();
36
+ if (el) sortable.element = el;
37
+ const h = handle();
38
+ if (h) sortable.handle = h;
39
+ const s = source();
40
+ if (s) sortable.source = s;
41
+ const t = target();
42
+ if (t) sortable.target = t;
43
+ sortable.id = input.id;
44
+ sortable.disabled = input.disabled ?? false;
45
+ sortable.feedback = input.feedback ?? "default";
46
+ sortable.alignment = input.alignment;
47
+ sortable.modifiers = input.modifiers;
48
+ sortable.sensors = input.sensors;
49
+ sortable.accept = input.accept;
50
+ sortable.type = input.type;
51
+ sortable.collisionPriority = input.collisionPriority;
52
+ sortable.transition = input.transition ? { ...defaultSortableTransition, ...input.transition } : defaultSortableTransition;
53
+ if (input.collisionDetector) {
54
+ sortable.collisionDetector = input.collisionDetector;
55
+ }
56
+ if (input.data) {
57
+ sortable.data = input.data;
58
+ }
59
+ });
60
+ createEffect(
61
+ on(
62
+ () => [input.group, input.index],
63
+ () => {
64
+ batch(() => {
65
+ sortable.group = input.group;
66
+ sortable.index = input.index;
67
+ });
68
+ }
69
+ )
70
+ );
71
+ createEffect(
72
+ on(
73
+ () => input.index,
74
+ () => {
75
+ if (sortable.manager?.dragOperation.status.idle && sortable.transition?.idle) {
76
+ sortable.refreshShape();
77
+ }
78
+ }
79
+ )
80
+ );
81
+ return {
82
+ get sortable() {
83
+ return sortable;
84
+ },
85
+ isDragging: () => trackedSortable().isDragging,
86
+ isDropping: () => trackedSortable().isDropping,
87
+ isDragSource: () => trackedSortable().isDragSource,
88
+ isDropTarget: () => trackedSortable().isDropTarget,
89
+ ref: setElement,
90
+ handleRef: setHandle,
91
+ sourceRef: setSource,
92
+ targetRef: setTarget
93
+ };
94
+ }
95
+
96
+ export { useSortable };
97
+ //# sourceMappingURL=sortable.js.map
98
+ //# sourceMappingURL=sortable.js.map
package/utilities.cjs ADDED
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ // src/utilities/saveElementPosition.ts
4
+ function createSaveElementPosition() {
5
+ let savedPosition = null;
6
+ const savePosition = (source) => {
7
+ const element = source.element;
8
+ const id = source.id;
9
+ const prevElement = element.previousElementSibling;
10
+ const nextElement = element.nextElementSibling;
11
+ const parentElement = element.parentElement;
12
+ savedPosition = {
13
+ id,
14
+ element,
15
+ prevElement: prevElement === element ? null : prevElement,
16
+ nextElement: nextElement === element ? null : nextElement,
17
+ parentElement
18
+ };
19
+ };
20
+ const restorePosition = (element) => {
21
+ if (!savedPosition) return;
22
+ const { prevElement, nextElement, parentElement } = savedPosition;
23
+ if (prevElement && element.previousElementSibling !== prevElement) {
24
+ prevElement.insertAdjacentElement("afterend", element);
25
+ } else if (nextElement && element.nextElementSibling !== nextElement) {
26
+ nextElement.insertAdjacentElement("beforebegin", element);
27
+ } else if (!prevElement && !nextElement && parentElement) {
28
+ parentElement.appendChild(element);
29
+ }
30
+ };
31
+ const clearPosition = () => {
32
+ savedPosition = null;
33
+ };
34
+ return {
35
+ savePosition,
36
+ clearPosition,
37
+ restorePosition
38
+ };
39
+ }
40
+
41
+ exports.createSaveElementPosition = createSaveElementPosition;
42
+ //# sourceMappingURL=utilities.cjs.map
43
+ //# sourceMappingURL=utilities.cjs.map
package/utilities.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { Draggable } from '@dnd-kit/dom';
2
+
3
+ declare function createSaveElementPosition(): {
4
+ savePosition: (source: Draggable) => void;
5
+ clearPosition: () => void;
6
+ restorePosition: (element: Element) => void;
7
+ };
8
+
9
+ export { createSaveElementPosition };
package/utilities.js ADDED
@@ -0,0 +1,41 @@
1
+ // src/utilities/saveElementPosition.ts
2
+ function createSaveElementPosition() {
3
+ let savedPosition = null;
4
+ const savePosition = (source) => {
5
+ const element = source.element;
6
+ const id = source.id;
7
+ const prevElement = element.previousElementSibling;
8
+ const nextElement = element.nextElementSibling;
9
+ const parentElement = element.parentElement;
10
+ savedPosition = {
11
+ id,
12
+ element,
13
+ prevElement: prevElement === element ? null : prevElement,
14
+ nextElement: nextElement === element ? null : nextElement,
15
+ parentElement
16
+ };
17
+ };
18
+ const restorePosition = (element) => {
19
+ if (!savedPosition) return;
20
+ const { prevElement, nextElement, parentElement } = savedPosition;
21
+ if (prevElement && element.previousElementSibling !== prevElement) {
22
+ prevElement.insertAdjacentElement("afterend", element);
23
+ } else if (nextElement && element.nextElementSibling !== nextElement) {
24
+ nextElement.insertAdjacentElement("beforebegin", element);
25
+ } else if (!prevElement && !nextElement && parentElement) {
26
+ parentElement.appendChild(element);
27
+ }
28
+ };
29
+ const clearPosition = () => {
30
+ savedPosition = null;
31
+ };
32
+ return {
33
+ savePosition,
34
+ clearPosition,
35
+ restorePosition
36
+ };
37
+ }
38
+
39
+ export { createSaveElementPosition };
40
+ //# sourceMappingURL=utilities.js.map
41
+ //# sourceMappingURL=utilities.js.map