@get-set/gs-sortable 0.0.18 → 0.0.20
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/dist/actions/calculateOnSort.js +207 -211
- package/dist/actions/initDraggable.js +33 -26
- package/dist/actions/initMouseMove.js +30 -34
- package/dist/actions/initSortEnd.js +33 -24
- package/dist/components/GSSortable.js +2 -0
- package/dist/constants/defaultParams.js +2 -0
- package/package.json +1 -1
|
@@ -3,152 +3,15 @@ import { getOffsetFromWindow, getTranslateCoord } from "./general";
|
|
|
3
3
|
|
|
4
4
|
const calculateOnSort = (ref) => {
|
|
5
5
|
const params = ref.currentParams;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
containerPT,
|
|
13
|
-
containerPR,
|
|
14
|
-
containerPB,
|
|
15
|
-
containerPL,
|
|
16
|
-
containerWidth,
|
|
17
|
-
currentHeight,
|
|
18
|
-
currentWidth,
|
|
19
|
-
itemWidth,
|
|
20
|
-
gapX,
|
|
21
|
-
gapY,
|
|
22
|
-
} = ref.uiData;
|
|
23
|
-
|
|
24
|
-
let currentLeft = containerPL;
|
|
25
|
-
let currentTop = containerPT;
|
|
26
|
-
let maxHeight = 0;
|
|
27
|
-
let maxWidth = 0;
|
|
28
|
-
|
|
29
|
-
let placeholderSeted = info === undefined;
|
|
30
|
-
let inProcessEl = undefined;
|
|
31
|
-
const containerCoord = getOffsetFromWindow(info.ref.grid);
|
|
32
|
-
if (info !== undefined) {
|
|
33
|
-
const $el = info.$el;
|
|
34
|
-
const elCoord = getOffsetFromWindow($el);
|
|
35
|
-
//const coord = getTranslateCoord($el);
|
|
36
|
-
inProcessEl = {
|
|
37
|
-
height: $el.offsetHeight,
|
|
38
|
-
width: $el.offsetWidth,
|
|
39
|
-
top: elCoord.top - containerCoord.top,
|
|
40
|
-
left: elCoord.left - containerCoord.left,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
let plIndex = info.index;
|
|
44
|
-
let colHeight = 0;
|
|
45
|
-
|
|
46
|
-
let itIndex = 0;
|
|
47
|
-
|
|
48
|
-
$items.map((el) => {
|
|
49
|
-
if (!el.classList.contains("gs-sortable-item-inmove")) {
|
|
50
|
-
const height = el.offsetHeight;
|
|
51
|
-
const width = el.offsetWidth;
|
|
52
|
-
if (params.type == types.column) {
|
|
53
|
-
if (!placeholderSeted) {
|
|
54
|
-
let placeholderTop =
|
|
55
|
-
currentTop == containerPT ? containerPT : currentTop + gapY;
|
|
56
|
-
let placeholderLeft = containerPL;
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
Math.abs(placeholderTop - inProcessEl.top) <
|
|
60
|
-
inProcessEl.height / 2 &&
|
|
61
|
-
Math.abs(placeholderLeft - inProcessEl.left) < inProcessEl.width / 2
|
|
62
|
-
) {
|
|
63
|
-
info.newTop = placeholderTop;
|
|
64
|
-
info.newLeft = placeholderLeft;
|
|
65
|
-
placeholderSeted = true;
|
|
66
|
-
plIndex = itIndex;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
70
|
-
if (currentTop == containerPT) {
|
|
71
|
-
currentTop = containerPT + height;
|
|
72
|
-
currentHeight = currentHeight + height;
|
|
73
|
-
} else {
|
|
74
|
-
currentTop = currentTop + gapY + height;
|
|
75
|
-
currentHeight = currentHeight + height + gapY;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} else if (params.type == types.row) {
|
|
79
|
-
if (!placeholderSeted) {
|
|
80
|
-
let placeholderLeft =
|
|
81
|
-
currentLeft == containerPL ? containerPL : currentLeft + gapX;
|
|
82
|
-
let placeholderTop = containerPT;
|
|
83
|
-
if (
|
|
84
|
-
Math.abs(placeholderTop - inProcessEl.top) <
|
|
85
|
-
inProcessEl.height / 2 &&
|
|
86
|
-
Math.abs(placeholderLeft - inProcessEl.left) < inProcessEl.width / 2
|
|
87
|
-
) {
|
|
88
|
-
info.newTop = placeholderTop;
|
|
89
|
-
info.newLeft = placeholderLeft;
|
|
90
|
-
placeholderSeted = true;
|
|
91
|
-
plIndex = itIndex;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
95
|
-
if (currentLeft == containerPL) {
|
|
96
|
-
currentLeft = containerPL + width;
|
|
97
|
-
currentWidth = currentWidth + width;
|
|
98
|
-
} else {
|
|
99
|
-
currentLeft = currentLeft + gapX + width;
|
|
100
|
-
currentWidth = currentWidth + width + gapX;
|
|
101
|
-
}
|
|
102
|
-
if (height > maxHeight) {
|
|
103
|
-
maxHeight = height;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
} else if (params.type == types.grid) {
|
|
107
|
-
const placeholderLeft =
|
|
108
|
-
itIndex % params.count == 0
|
|
109
|
-
? containerPL
|
|
110
|
-
: containerPL + (itIndex % params.count) * (itemWidth + gapX);
|
|
111
|
-
const placeholderTop = currentTop;
|
|
112
|
-
if (
|
|
113
|
-
Math.abs(placeholderTop - inProcessEl.top) < inProcessEl.height / 2 &&
|
|
114
|
-
Math.abs(placeholderLeft - inProcessEl.left) < inProcessEl.width / 2
|
|
115
|
-
) {
|
|
116
|
-
info.newTop = placeholderTop;
|
|
117
|
-
info.newLeft = placeholderLeft;
|
|
118
|
-
placeholderSeted = true;
|
|
119
|
-
plIndex = itIndex;
|
|
120
|
-
}
|
|
121
|
-
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
122
|
-
const top = currentTop;
|
|
123
|
-
if (height > colHeight) {
|
|
124
|
-
colHeight = height;
|
|
125
|
-
}
|
|
126
|
-
if (
|
|
127
|
-
itIndex % params.count === params.count - 1 ||
|
|
128
|
-
itIndex === itemsCount - 1
|
|
129
|
-
) {
|
|
130
|
-
if (top === containerPT) {
|
|
131
|
-
currentHeight = currentHeight + colHeight;
|
|
132
|
-
} else {
|
|
133
|
-
currentHeight = currentHeight + colHeight + gapY;
|
|
134
|
-
}
|
|
135
|
-
currentTop = currentTop + colHeight + gapY;
|
|
136
|
-
colHeight = 0;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
itIndex += 1;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
//'if (plIndex != info.index) {
|
|
144
|
-
if (true) {
|
|
145
|
-
info.index = plIndex;
|
|
6
|
+
if (!params.takeClone) {
|
|
7
|
+
const $items = [...ref.grid.children];
|
|
8
|
+
const itemsCount = $items.filter(
|
|
9
|
+
(x) => !x.classList.contains("gs-sortable-item-inmove")
|
|
10
|
+
).length;
|
|
11
|
+
const info = window.GSSortableConfigue.draggableInfo;
|
|
146
12
|
let {
|
|
147
13
|
containerPT,
|
|
148
|
-
containerPR,
|
|
149
|
-
containerPB,
|
|
150
14
|
containerPL,
|
|
151
|
-
containerWidth,
|
|
152
15
|
currentHeight,
|
|
153
16
|
currentWidth,
|
|
154
17
|
itemWidth,
|
|
@@ -156,102 +19,105 @@ const calculateOnSort = (ref) => {
|
|
|
156
19
|
gapY,
|
|
157
20
|
} = ref.uiData;
|
|
158
21
|
|
|
159
|
-
currentLeft = containerPL;
|
|
160
|
-
currentTop = containerPT;
|
|
161
|
-
|
|
22
|
+
let currentLeft = containerPL;
|
|
23
|
+
let currentTop = containerPT;
|
|
24
|
+
let maxHeight = 0;
|
|
25
|
+
|
|
26
|
+
let placeholderSeted = info === undefined;
|
|
27
|
+
let inProcessEl = undefined;
|
|
28
|
+
const containerCoord = getOffsetFromWindow(info.ref.grid);
|
|
29
|
+
if (info !== undefined) {
|
|
30
|
+
const $el = info.$el;
|
|
31
|
+
const elCoord = getOffsetFromWindow($el);
|
|
32
|
+
inProcessEl = {
|
|
33
|
+
height: $el.offsetHeight,
|
|
34
|
+
width: $el.offsetWidth,
|
|
35
|
+
top: elCoord.top - containerCoord.top,
|
|
36
|
+
left: elCoord.left - containerCoord.left,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
let plIndex = info.index;
|
|
40
|
+
let colHeight = 0;
|
|
41
|
+
|
|
42
|
+
let itIndex = 0;
|
|
43
|
+
|
|
162
44
|
$items.map((el) => {
|
|
163
45
|
if (!el.classList.contains("gs-sortable-item-inmove")) {
|
|
164
46
|
const height = el.offsetHeight;
|
|
165
47
|
const width = el.offsetWidth;
|
|
166
48
|
if (params.type == types.column) {
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
49
|
+
if (!placeholderSeted) {
|
|
50
|
+
let placeholderTop =
|
|
51
|
+
currentTop == containerPT ? containerPT : currentTop + gapY;
|
|
52
|
+
let placeholderLeft = containerPL;
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
Math.abs(placeholderTop - inProcessEl.top) <
|
|
56
|
+
inProcessEl.height / 2 &&
|
|
57
|
+
Math.abs(placeholderLeft - inProcessEl.left) <
|
|
58
|
+
inProcessEl.width / 2
|
|
59
|
+
) {
|
|
60
|
+
info.newTop = placeholderTop;
|
|
61
|
+
info.newLeft = placeholderLeft;
|
|
62
|
+
placeholderSeted = true;
|
|
63
|
+
plIndex = itIndex;
|
|
178
64
|
}
|
|
179
65
|
}
|
|
180
66
|
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
181
|
-
el.style.left = `${containerPL}px`;
|
|
182
67
|
if (currentTop == containerPT) {
|
|
183
|
-
el.style.top = `${containerPT}px`;
|
|
184
68
|
currentTop = containerPT + height;
|
|
185
69
|
currentHeight = currentHeight + height;
|
|
186
70
|
} else {
|
|
187
|
-
el.style.top = `${currentTop + gapY}px`;
|
|
188
71
|
currentTop = currentTop + gapY + height;
|
|
189
72
|
currentHeight = currentHeight + height + gapY;
|
|
190
73
|
}
|
|
191
74
|
}
|
|
192
75
|
} else if (params.type == types.row) {
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
76
|
+
if (!placeholderSeted) {
|
|
77
|
+
let placeholderLeft =
|
|
78
|
+
currentLeft == containerPL ? containerPL : currentLeft + gapX;
|
|
79
|
+
let placeholderTop = containerPT;
|
|
80
|
+
if (
|
|
81
|
+
Math.abs(placeholderTop - inProcessEl.top) <
|
|
82
|
+
inProcessEl.height / 2 &&
|
|
83
|
+
Math.abs(placeholderLeft - inProcessEl.left) <
|
|
84
|
+
inProcessEl.width / 2
|
|
85
|
+
) {
|
|
86
|
+
info.newTop = placeholderTop;
|
|
87
|
+
info.newLeft = placeholderLeft;
|
|
88
|
+
placeholderSeted = true;
|
|
89
|
+
plIndex = itIndex;
|
|
204
90
|
}
|
|
205
91
|
}
|
|
206
92
|
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
207
|
-
el.style.top = `${containerPT}px`;
|
|
208
93
|
if (currentLeft == containerPL) {
|
|
209
|
-
el.style.left = `${containerPL}px`;
|
|
210
94
|
currentLeft = containerPL + width;
|
|
211
95
|
currentWidth = currentWidth + width;
|
|
212
96
|
} else {
|
|
213
|
-
el.style.left = `${currentLeft + gapX}px`;
|
|
214
97
|
currentLeft = currentLeft + gapX + width;
|
|
215
98
|
currentWidth = currentWidth + width + gapX;
|
|
216
99
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
100
|
+
if (height > maxHeight) {
|
|
101
|
+
maxHeight = height;
|
|
102
|
+
}
|
|
220
103
|
}
|
|
221
104
|
} else if (params.type == types.grid) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
currentHeight = currentHeight + colHeight;
|
|
237
|
-
} else {
|
|
238
|
-
currentHeight = currentHeight + colHeight + gapY;
|
|
239
|
-
}
|
|
240
|
-
currentTop = currentTop + colHeight + gapY;
|
|
241
|
-
colHeight = 0;
|
|
242
|
-
ref.grid.style.height = `${currentHeight}px`;
|
|
243
|
-
}
|
|
244
|
-
itIndex += 1;
|
|
245
|
-
info.newTop = top;
|
|
246
|
-
info.newLeft = left;
|
|
247
|
-
info.placeholder.style.left = `${left}px`;
|
|
248
|
-
info.placeholder.style.top = `${top}px`;
|
|
105
|
+
const placeholderLeft =
|
|
106
|
+
itIndex % params.count == 0
|
|
107
|
+
? containerPL
|
|
108
|
+
: containerPL + (itIndex % params.count) * (itemWidth + gapX);
|
|
109
|
+
const placeholderTop = currentTop;
|
|
110
|
+
if (
|
|
111
|
+
Math.abs(placeholderTop - inProcessEl.top) <
|
|
112
|
+
inProcessEl.height / 2 &&
|
|
113
|
+
Math.abs(placeholderLeft - inProcessEl.left) < inProcessEl.width / 2
|
|
114
|
+
) {
|
|
115
|
+
info.newTop = placeholderTop;
|
|
116
|
+
info.newLeft = placeholderLeft;
|
|
117
|
+
placeholderSeted = true;
|
|
118
|
+
plIndex = itIndex;
|
|
249
119
|
}
|
|
250
120
|
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
251
|
-
const left =
|
|
252
|
-
itIndex % params.count == 0
|
|
253
|
-
? containerPL
|
|
254
|
-
: containerPL + (itIndex % params.count) * (itemWidth + gapX);
|
|
255
121
|
const top = currentTop;
|
|
256
122
|
if (height > colHeight) {
|
|
257
123
|
colHeight = height;
|
|
@@ -267,15 +133,145 @@ const calculateOnSort = (ref) => {
|
|
|
267
133
|
}
|
|
268
134
|
currentTop = currentTop + colHeight + gapY;
|
|
269
135
|
colHeight = 0;
|
|
270
|
-
ref.grid.style.height = `${currentHeight}px`;
|
|
271
136
|
}
|
|
272
|
-
el.style.left = `${left}px`;
|
|
273
|
-
el.style.top = `${top}px`;
|
|
274
137
|
}
|
|
275
138
|
}
|
|
276
139
|
itIndex += 1;
|
|
277
140
|
}
|
|
278
141
|
});
|
|
142
|
+
{
|
|
143
|
+
info.index = plIndex;
|
|
144
|
+
let {
|
|
145
|
+
containerPT,
|
|
146
|
+
containerPL,
|
|
147
|
+
currentHeight,
|
|
148
|
+
currentWidth,
|
|
149
|
+
itemWidth,
|
|
150
|
+
gapX,
|
|
151
|
+
gapY,
|
|
152
|
+
} = ref.uiData;
|
|
153
|
+
|
|
154
|
+
currentLeft = containerPL;
|
|
155
|
+
currentTop = containerPT;
|
|
156
|
+
itIndex = 0;
|
|
157
|
+
$items.map((el) => {
|
|
158
|
+
if (!el.classList.contains("gs-sortable-item-inmove")) {
|
|
159
|
+
const height = el.offsetHeight;
|
|
160
|
+
const width = el.offsetWidth;
|
|
161
|
+
if (params.type == types.column) {
|
|
162
|
+
if (itIndex == plIndex) {
|
|
163
|
+
info.placeholder.style.left = `${containerPL}px`;
|
|
164
|
+
info.newLeft = containerPL;
|
|
165
|
+
if (currentTop == containerPT) {
|
|
166
|
+
info.newTop = containerPT;
|
|
167
|
+
info.placeholder.style.top = `${containerPT}px`;
|
|
168
|
+
currentTop = containerPT + inProcessEl.height;
|
|
169
|
+
} else {
|
|
170
|
+
info.newTop = currentTop + gapY;
|
|
171
|
+
info.placeholder.style.top = `${currentTop + gapY}px`;
|
|
172
|
+
currentTop = currentTop + gapY + inProcessEl.height;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
176
|
+
el.style.left = `${containerPL}px`;
|
|
177
|
+
if (currentTop == containerPT) {
|
|
178
|
+
el.style.top = `${containerPT}px`;
|
|
179
|
+
currentTop = containerPT + height;
|
|
180
|
+
currentHeight = currentHeight + height;
|
|
181
|
+
} else {
|
|
182
|
+
el.style.top = `${currentTop + gapY}px`;
|
|
183
|
+
currentTop = currentTop + gapY + height;
|
|
184
|
+
currentHeight = currentHeight + height + gapY;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} else if (params.type == types.row) {
|
|
188
|
+
if (itIndex == plIndex) {
|
|
189
|
+
info.placeholder.style.top = `${containerPT}px`;
|
|
190
|
+
info.newTop = containerPT;
|
|
191
|
+
if (currentLeft == containerPL) {
|
|
192
|
+
info.newLeft = containerPL;
|
|
193
|
+
info.placeholder.style.left = `${containerPL}px`;
|
|
194
|
+
currentLeft = containerPL + inProcessEl.width;
|
|
195
|
+
} else {
|
|
196
|
+
info.newLeft = currentLeft + gapX;
|
|
197
|
+
info.placeholder.style.left = `${currentLeft + gapX}px`;
|
|
198
|
+
currentLeft = currentLeft + gapX + inProcessEl.width;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
202
|
+
el.style.top = `${containerPT}px`;
|
|
203
|
+
if (currentLeft == containerPL) {
|
|
204
|
+
el.style.left = `${containerPL}px`;
|
|
205
|
+
currentLeft = containerPL + width;
|
|
206
|
+
currentWidth = currentWidth + width;
|
|
207
|
+
} else {
|
|
208
|
+
el.style.left = `${currentLeft + gapX}px`;
|
|
209
|
+
currentLeft = currentLeft + gapX + width;
|
|
210
|
+
currentWidth = currentWidth + width + gapX;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (height > maxHeight) {
|
|
214
|
+
maxHeight = height;
|
|
215
|
+
}
|
|
216
|
+
} else if (params.type == types.grid) {
|
|
217
|
+
if (itIndex == plIndex) {
|
|
218
|
+
const left =
|
|
219
|
+
itIndex % params.count == 0
|
|
220
|
+
? containerPL
|
|
221
|
+
: containerPL + (itIndex % params.count) * (itemWidth + gapX);
|
|
222
|
+
const top = currentTop;
|
|
223
|
+
if (inProcessEl.height > colHeight) {
|
|
224
|
+
colHeight = inProcessEl.height;
|
|
225
|
+
}
|
|
226
|
+
if (
|
|
227
|
+
itIndex % params.count === params.count - 1 ||
|
|
228
|
+
itIndex === itemsCount - 1
|
|
229
|
+
) {
|
|
230
|
+
if (top === containerPT) {
|
|
231
|
+
currentHeight = currentHeight + colHeight;
|
|
232
|
+
} else {
|
|
233
|
+
currentHeight = currentHeight + colHeight + gapY;
|
|
234
|
+
}
|
|
235
|
+
currentTop = currentTop + colHeight + gapY;
|
|
236
|
+
colHeight = 0;
|
|
237
|
+
ref.grid.style.height = `${currentHeight}px`;
|
|
238
|
+
}
|
|
239
|
+
itIndex += 1;
|
|
240
|
+
info.newTop = top;
|
|
241
|
+
info.newLeft = left;
|
|
242
|
+
info.placeholder.style.left = `${left}px`;
|
|
243
|
+
info.placeholder.style.top = `${top}px`;
|
|
244
|
+
}
|
|
245
|
+
if (!el.classList.contains("gs-sortable-placeholder")) {
|
|
246
|
+
const left =
|
|
247
|
+
itIndex % params.count == 0
|
|
248
|
+
? containerPL
|
|
249
|
+
: containerPL + (itIndex % params.count) * (itemWidth + gapX);
|
|
250
|
+
const top = currentTop;
|
|
251
|
+
if (height > colHeight) {
|
|
252
|
+
colHeight = height;
|
|
253
|
+
}
|
|
254
|
+
if (
|
|
255
|
+
itIndex % params.count === params.count - 1 ||
|
|
256
|
+
itIndex === itemsCount - 1
|
|
257
|
+
) {
|
|
258
|
+
if (top === containerPT) {
|
|
259
|
+
currentHeight = currentHeight + colHeight;
|
|
260
|
+
} else {
|
|
261
|
+
currentHeight = currentHeight + colHeight + gapY;
|
|
262
|
+
}
|
|
263
|
+
currentTop = currentTop + colHeight + gapY;
|
|
264
|
+
colHeight = 0;
|
|
265
|
+
ref.grid.style.height = `${currentHeight}px`;
|
|
266
|
+
}
|
|
267
|
+
el.style.left = `${left}px`;
|
|
268
|
+
el.style.top = `${top}px`;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
itIndex += 1;
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
279
275
|
}
|
|
280
276
|
};
|
|
281
277
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import constParams from
|
|
2
|
-
import { getOffsetFromBody, getOffsetFromWindow } from
|
|
1
|
+
import constParams from "../constants/constParams";
|
|
2
|
+
import { getOffsetFromBody, getOffsetFromWindow } from "./general";
|
|
3
3
|
|
|
4
4
|
const initDraggable = (ref) => {
|
|
5
5
|
const params = ref.currentParams;
|
|
@@ -8,9 +8,9 @@ const initDraggable = (ref) => {
|
|
|
8
8
|
$items.map(($el, index) => {
|
|
9
9
|
$el.onmousedown = null;
|
|
10
10
|
const handler =
|
|
11
|
-
params.handler !=
|
|
11
|
+
params.handler != "" ? $el.querySelector(params.handler) : $el;
|
|
12
12
|
if (handler != null) {
|
|
13
|
-
handler.style.cursor =
|
|
13
|
+
handler.style.cursor = "move";
|
|
14
14
|
handler.onmousedown = (e) => {
|
|
15
15
|
if (!ref.isAddjusting) {
|
|
16
16
|
window.GSSortableConfigue.overInItemRef = ref;
|
|
@@ -20,19 +20,26 @@ const initDraggable = (ref) => {
|
|
|
20
20
|
const containerStyles = getComputedStyle(container);
|
|
21
21
|
const paddingTop = parseFloat(containerStyles.paddingTop);
|
|
22
22
|
const paddingLeft = parseFloat(containerStyles.paddingLeft);
|
|
23
|
-
const placeholder = document.createElement('div');
|
|
24
23
|
const top = parseFloat(elStyles.top);
|
|
25
24
|
const left = parseFloat(elStyles.left);
|
|
26
|
-
|
|
27
|
-
placeholder
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
let $draggaleEl = $el;
|
|
26
|
+
const placeholder = document.createElement("div");
|
|
27
|
+
if (!params.takeClone) {
|
|
28
|
+
placeholder.classList.add("gs-sortable-placeholder");
|
|
29
|
+
placeholder.style.position = elStyles.position;
|
|
30
|
+
placeholder.style.transition = `left ${constParams.animateionSpeed}ms, top ${constParams.animateionSpeed}ms, transform ${constParams.animateionSpeed}ms, opacity ${constParams.animateionSpeed}ms, opacity ${constParams.animateionSpeed}ms`;
|
|
31
|
+
placeholder.style.width = `${$el.offsetWidth}px`;
|
|
32
|
+
placeholder.style.height = `${$el.offsetHeight}px`;
|
|
33
|
+
placeholder.style.top = `${top}px`;
|
|
34
|
+
placeholder.style.left = `${left}px`;
|
|
35
|
+
placeholder.style.border = elStyles.border;
|
|
36
|
+
placeholder.style.borderRadius = elStyles.borderRadius;
|
|
37
|
+
ref.grid.append(placeholder);
|
|
38
|
+
} else {
|
|
39
|
+
const $cloneEl = $el.cloneNode(true);
|
|
40
|
+
ref.grid.append($cloneEl);
|
|
41
|
+
$draggaleEl = $cloneEl;
|
|
42
|
+
}
|
|
36
43
|
|
|
37
44
|
const elOffsetWindow = getOffsetFromWindow($el);
|
|
38
45
|
|
|
@@ -44,17 +51,17 @@ const initDraggable = (ref) => {
|
|
|
44
51
|
if (!isNaN(parseFloat(left))) {
|
|
45
52
|
translateX = parseFloat(left);
|
|
46
53
|
}
|
|
47
|
-
$
|
|
48
|
-
|
|
49
|
-
}px)`;
|
|
50
|
-
$
|
|
51
|
-
$
|
|
54
|
+
$draggaleEl.style.transform = ` translate(${
|
|
55
|
+
translateX - paddingLeft
|
|
56
|
+
}px, ${translateY - paddingTop}px)`;
|
|
57
|
+
$draggaleEl.style.top = `${paddingTop}px`;
|
|
58
|
+
$draggaleEl.style.left = `${paddingLeft}px`;
|
|
52
59
|
|
|
53
60
|
window.GSSortableConfigue.draggableInfo = {
|
|
54
61
|
moved: false,
|
|
55
62
|
ref: ref,
|
|
56
63
|
index,
|
|
57
|
-
$el,
|
|
64
|
+
$el: $draggaleEl,
|
|
58
65
|
clientX: e.clientX,
|
|
59
66
|
clientY: e.clientY,
|
|
60
67
|
placeholder,
|
|
@@ -64,12 +71,12 @@ const initDraggable = (ref) => {
|
|
|
64
71
|
fromTop: (e.clientY - elOffsetWindow.top) / $el.offsetHeight,
|
|
65
72
|
};
|
|
66
73
|
|
|
67
|
-
$
|
|
68
|
-
ref.grid.classList.add(
|
|
69
|
-
if (ref.grid.closest(
|
|
74
|
+
$draggaleEl.classList.add("gs-sortable-item-inmove");
|
|
75
|
+
ref.grid.classList.add("gs-sortable-active");
|
|
76
|
+
if (ref.grid.closest(".gs-sortable-item") != null) {
|
|
70
77
|
ref.grid
|
|
71
|
-
.closest(
|
|
72
|
-
.classList.add(
|
|
78
|
+
.closest(".gs-sortable-item")
|
|
79
|
+
.classList.add("gs-sortable-item-active-parent");
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { getOffsetFromWindow, getTranslateCoord } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import calculateOnSort from './calculateOnSort';
|
|
7
|
-
import types from '../constants/types';
|
|
1
|
+
import { getOffsetFromWindow, getTranslateCoord } from "./general";
|
|
2
|
+
import checkItemInContainer from "./checkItemInContainer";
|
|
3
|
+
import calculate from "./calculate";
|
|
4
|
+
import constParams from "../constants/constParams";
|
|
5
|
+
import calculateOnSort from "./calculateOnSort";
|
|
8
6
|
|
|
9
7
|
const initMouseMove = (event) => {
|
|
10
8
|
const info = window.GSSortableConfigue.draggableInfo;
|
|
@@ -21,24 +19,22 @@ const initMouseMove = (event) => {
|
|
|
21
19
|
allRefs.push(item.ref);
|
|
22
20
|
}
|
|
23
21
|
});
|
|
24
|
-
let findedRef =
|
|
22
|
+
let findedRef = "";
|
|
25
23
|
allRefs.map((item) => {
|
|
26
24
|
if (checkItemInContainer(item.grid, info.$el)) {
|
|
27
25
|
findedRef = item.currentParams.reference;
|
|
28
26
|
}
|
|
29
27
|
});
|
|
30
|
-
if (findedRef !==
|
|
31
|
-
//if (window.GSSortableConfigue.overInItemRef == undefined) {
|
|
28
|
+
if (findedRef !== "") {
|
|
32
29
|
const newRef = window.GSSortableConfigue.instance(findedRef);
|
|
33
30
|
if (
|
|
34
31
|
newRef != undefined &&
|
|
35
32
|
info.ref.currentParams.reference !== newRef.currentParams.reference
|
|
36
33
|
) {
|
|
37
|
-
if (document.querySelector(
|
|
38
|
-
document.querySelector(
|
|
34
|
+
if (document.querySelector(".gs-sortable-placeholder") != null) {
|
|
35
|
+
document.querySelector(".gs-sortable-placeholder").remove();
|
|
39
36
|
calculate(window.GSSortableConfigue.overInItemRef);
|
|
40
37
|
}
|
|
41
|
-
const oldRef = window.GSSortableConfigue.overInItemRef;
|
|
42
38
|
window.GSSortableConfigue.overInItemRef = newRef;
|
|
43
39
|
info.$el.style.width =
|
|
44
40
|
window.GSSortableConfigue.overInItemRef.itemWidth;
|
|
@@ -55,30 +51,31 @@ const initMouseMove = (event) => {
|
|
|
55
51
|
event.clientX - newContainerOffset.left - newWidth * info.fromLeft;
|
|
56
52
|
|
|
57
53
|
const elStyles = getComputedStyle(info.$el);
|
|
58
|
-
const placeholder = document.createElement('div');
|
|
59
54
|
const top = parseFloat(elStyles.top);
|
|
60
55
|
const left = parseFloat(elStyles.left);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
if (!window.GSSortableConfigue.overInItemRef.currentParams.takeClone) {
|
|
57
|
+
const placeholder = document.createElement("div");
|
|
58
|
+
placeholder.classList.add("gs-sortable-placeholder");
|
|
59
|
+
placeholder.style.position = elStyles.position;
|
|
60
|
+
info.$el.style.transform = `translate(${translateX}px, ${translateY}px)`;
|
|
61
|
+
placeholder.style.transition = `left ${constParams.animateionSpeed}ms, top ${constParams.animateionSpeed}ms, transform ${constParams.animateionSpeed}ms, opacity ${constParams.animateionSpeed}ms, opacity ${constParams.animateionSpeed}ms`;
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
placeholder.style.top = `${top}px`;
|
|
64
|
+
placeholder.style.left = `${left}px`;
|
|
65
|
+
placeholder.style.border = elStyles.border;
|
|
66
|
+
placeholder.style.borderRadius = elStyles.borderRadius;
|
|
67
|
+
info.placeholder = placeholder;
|
|
68
|
+
info.ref = newRef;
|
|
69
|
+
placeholder.style.width = `${info.$el.offsetWidth}px`;
|
|
70
|
+
placeholder.style.height = `${info.$el.offsetHeight}px`;
|
|
71
|
+
newRef.grid.append(placeholder);
|
|
72
|
+
calculate(newRef);
|
|
73
|
+
return;
|
|
74
|
+
} else {
|
|
75
|
+
info.ref = newRef;
|
|
76
|
+
}
|
|
77
77
|
}
|
|
78
|
-
// } else {
|
|
79
|
-
// }
|
|
80
78
|
}
|
|
81
|
-
//if (window.GSSortableConfigue.overInItemRef != undefined) {
|
|
82
79
|
const params = info.ref.currentParams;
|
|
83
80
|
const clientX = event.clientX;
|
|
84
81
|
const clientY = event.clientY;
|
|
@@ -109,10 +106,9 @@ const initMouseMove = (event) => {
|
|
|
109
106
|
}
|
|
110
107
|
$el.style.transform = `translate(${tranlateX}px, ${tranlateY}px)`;
|
|
111
108
|
|
|
112
|
-
if (findedRef !=
|
|
109
|
+
if (findedRef != "") {
|
|
113
110
|
calculateOnSort(window.GSSortableConfigue.overInItemRef);
|
|
114
111
|
}
|
|
115
|
-
//}
|
|
116
112
|
}
|
|
117
113
|
window.scrollY = document.documentElement.scrollTop;
|
|
118
114
|
window.scrollX = document.documentElement.scrollLeft;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import constParams from
|
|
2
|
-
import calculate from
|
|
3
|
-
import { getOffsetFromBody, moveChildToIndex } from
|
|
1
|
+
import constParams from "../constants/constParams";
|
|
2
|
+
import calculate from "./calculate";
|
|
3
|
+
import { getOffsetFromBody, moveChildToIndex } from "./general";
|
|
4
4
|
|
|
5
5
|
const initSortEnd = (event) => {
|
|
6
6
|
const info = { ...window.GSSortableConfigue.draggableInfo };
|
|
@@ -22,42 +22,51 @@ const initSortEnd = (event) => {
|
|
|
22
22
|
info.ref.isAddjusting = true;
|
|
23
23
|
const $el = info.$el;
|
|
24
24
|
const placeholder = info.placeholder;
|
|
25
|
-
info.$el.classList.remove(
|
|
26
|
-
info.ref.grid.classList.remove(
|
|
27
|
-
if (info.ref.grid.closest(
|
|
25
|
+
info.$el.classList.remove("gs-sortable-item-inmove");
|
|
26
|
+
info.ref.grid.classList.remove("gs-sortable-active");
|
|
27
|
+
if (info.ref.grid.closest(".gs-sortable-item-active-parent") != null) {
|
|
28
28
|
info.ref.grid
|
|
29
|
-
.closest(
|
|
30
|
-
.classList.remove(
|
|
29
|
+
.closest(".gs-sortable-item-active-parent")
|
|
30
|
+
.classList.remove("gs-sortable-item-active-parent");
|
|
31
31
|
}
|
|
32
|
-
info.$el.classList.add(
|
|
32
|
+
info.$el.classList.add("gs-sortable-item-addjusting");
|
|
33
33
|
window.GSSortableConfigue.draggableInfo = undefined;
|
|
34
34
|
info.$el.style.top = `${info.newTop + containerDifY}px`;
|
|
35
35
|
info.$el.style.left = `${info.newLeft + containerDifX}px`;
|
|
36
|
-
info.$el.style.removeProperty(
|
|
36
|
+
info.$el.style.removeProperty("transform");
|
|
37
37
|
setTimeout(() => {
|
|
38
|
-
$el.classList.remove(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
$el.classList.remove("gs-sortable-item-addjusting");
|
|
39
|
+
if (
|
|
40
|
+
info.ref.currentParams.reference ===
|
|
41
|
+
window.GSSortableConfigue.takeFrom.currentParams.reference &&
|
|
42
|
+
window.GSSortableConfigue.takeFrom.currentParams.takeClone
|
|
43
|
+
) {
|
|
44
|
+
info.$el.remove();
|
|
45
|
+
} else {
|
|
46
|
+
if (info.index != undefined) {
|
|
47
|
+
moveChildToIndex(info.ref.grid, info.$el, info.index);
|
|
48
|
+
}
|
|
45
49
|
}
|
|
46
|
-
// }
|
|
47
|
-
// else{
|
|
48
|
-
// if (info.index != undefined) {
|
|
49
|
-
// moveChildToIndex(info.ref.grid, info.$el, info.index);
|
|
50
|
-
// }
|
|
51
|
-
// }
|
|
52
50
|
placeholder.remove();
|
|
53
51
|
if (
|
|
54
52
|
info.ref.currentParams.reference !==
|
|
55
53
|
window.GSSortableConfigue.takeFrom.currentParams.reference
|
|
56
54
|
) {
|
|
55
|
+
window.GSSortableConfigue.takeFrom.currentParams.afterSort(
|
|
56
|
+
window.GSSortableConfigue.takeFrom.grid.querySelectorAll(
|
|
57
|
+
".gs-sortable-item"
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
info.ref.currentParams.afterSort(
|
|
61
|
+
info.ref.grid.querySelectorAll(".gs-sortable-item")
|
|
62
|
+
);
|
|
57
63
|
window.GSSortableConfigue.takeFrom.refresh();
|
|
58
64
|
info.ref.refresh();
|
|
59
65
|
} else {
|
|
60
66
|
calculate(info.ref);
|
|
67
|
+
info.ref.currentParams.afterSort(
|
|
68
|
+
info.ref.grid.querySelectorAll(".gs-sortable-item")
|
|
69
|
+
);
|
|
61
70
|
}
|
|
62
71
|
info.ref.isAddjusting = false;
|
|
63
72
|
}, constParams.animateionSpeed);
|
|
@@ -65,7 +74,7 @@ const initSortEnd = (event) => {
|
|
|
65
74
|
const placeholder = info.placeholder;
|
|
66
75
|
info.$el.style.top = `${info.newTop}px`;
|
|
67
76
|
info.$el.style.left = `${info.newLeft}px`;
|
|
68
|
-
info.$el.style.removeProperty(
|
|
77
|
+
info.$el.style.removeProperty("transform");
|
|
69
78
|
placeholder.remove();
|
|
70
79
|
window.GSSortableConfigue.draggableInfo = undefined;
|
|
71
80
|
}
|
|
@@ -20,6 +20,7 @@ const params = {
|
|
|
20
20
|
reference: PropTypes.string,
|
|
21
21
|
handler: PropTypes.string,
|
|
22
22
|
className: PropTypes.string,
|
|
23
|
+
afterSort: PropTypes.func,
|
|
23
24
|
gsx: PropTypes.object,
|
|
24
25
|
gap: PropTypes.string,
|
|
25
26
|
allowOutOfBox: PropTypes.bool,
|
|
@@ -36,6 +37,7 @@ const params = {
|
|
|
36
37
|
* @param {boolean} props.className - Enable add classes.
|
|
37
38
|
* @param {React.CSSProperties & Record<string, React.CSSProperties | Record<string, React.CSSProperties | Record<string, React.CSSProperties | Record<string, React.CSSProperties>>>} props.gsx
|
|
38
39
|
* @param {string} props.gap - Allows set gap among elements.
|
|
40
|
+
* @param {func} props.afterSort - this is callback function which called after sort.
|
|
39
41
|
* @param {string} props.handler - selector of target element to move.
|
|
40
42
|
* @param {number} props.count - Shows items count per row.
|
|
41
43
|
* @param {'row' | 'column' | 'grid'} props.type - this is the type of prop.
|
|
@@ -3,6 +3,7 @@ import types from './types';
|
|
|
3
3
|
const defaultParams = {
|
|
4
4
|
acceptFrom: [],
|
|
5
5
|
className: '',
|
|
6
|
+
takeClone: false,
|
|
6
7
|
reference: '',
|
|
7
8
|
count: 3,
|
|
8
9
|
gap: '',
|
|
@@ -12,6 +13,7 @@ const defaultParams = {
|
|
|
12
13
|
type: types.column,
|
|
13
14
|
allowOutOfBox: true,
|
|
14
15
|
responsive: [],
|
|
16
|
+
afterSort: () => {},
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export default Object.freeze(defaultParams);
|