@get-set/gs-sortable 0.0.7 → 0.0.8
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.
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import constParams from
|
|
2
|
-
import types from
|
|
1
|
+
import constParams from '../constants/constParams';
|
|
2
|
+
import types from '../constants/types';
|
|
3
3
|
|
|
4
4
|
const calculate = (ref) => {
|
|
5
|
-
console.log("calculate");
|
|
6
5
|
const params = ref.currentParams;
|
|
7
|
-
if (typeof ref.currentParams.beforeInit ===
|
|
6
|
+
if (typeof ref.currentParams.beforeInit === 'function') {
|
|
8
7
|
ref.currentParams.beforeInit();
|
|
9
8
|
}
|
|
10
9
|
const $items = [...ref.grid.children].filter(
|
|
11
|
-
(x) => !x.classList.contains(
|
|
10
|
+
(x) => !x.classList.contains('gs-sortable-item-inmove')
|
|
12
11
|
);
|
|
13
12
|
const itemsCount = $items.length;
|
|
14
13
|
|
|
15
|
-
ref.grid.style.position =
|
|
16
|
-
if (params.gap !=
|
|
14
|
+
ref.grid.style.position = 'relative';
|
|
15
|
+
if (params.gap != '') {
|
|
17
16
|
ref.grid.style.gap = params.gap;
|
|
18
17
|
}
|
|
19
18
|
const gridStyles = getComputedStyle(ref.grid);
|
|
20
19
|
const cssGap = gridStyles.gap;
|
|
21
20
|
let gapX = 0;
|
|
22
21
|
let gapY = 0;
|
|
23
|
-
if (typeof cssGap !==
|
|
24
|
-
const cssGapYValue = cssGap.includes(
|
|
25
|
-
const cssGapXValue = cssGap.includes(
|
|
22
|
+
if (typeof cssGap !== 'undefined' && cssGap !== null) {
|
|
23
|
+
const cssGapYValue = cssGap.includes(' ') ? cssGap.split(' ')[0] : cssGap;
|
|
24
|
+
const cssGapXValue = cssGap.includes(' ') ? cssGap.split(' ')[1] : cssGap;
|
|
26
25
|
|
|
27
26
|
const gapYSize = parseInt(cssGapYValue);
|
|
28
27
|
const gapXSize = parseInt(cssGapXValue);
|
|
@@ -44,11 +43,15 @@ const calculate = (ref) => {
|
|
|
44
43
|
|
|
45
44
|
const containerWidth = ref.grid.clientWidth - containerPR - containerPL;
|
|
46
45
|
let itemWidth = 0;
|
|
46
|
+
let strItemWidth = 'max-content';
|
|
47
47
|
if (params.type == types.grid) {
|
|
48
48
|
itemWidth = (containerWidth - (params.count - 1) * gapX) / params.count;
|
|
49
|
+
strItemWidth = itemWidth + 'px';
|
|
50
|
+
} else if (params.type == types.column) {
|
|
51
|
+
itemWidth = containerWidth;
|
|
52
|
+
strItemWidth = itemWidth + 'px';
|
|
49
53
|
}
|
|
50
|
-
|
|
51
|
-
const transition = `left ${constParams.animateionSpeed}ms, top ${constParams.animateionSpeed}ms, transform ${constParams.animateionSpeed}ms`;
|
|
54
|
+
ref.itemWidth = strItemWidth;
|
|
52
55
|
|
|
53
56
|
let currentLeft = containerPL;
|
|
54
57
|
let currentTop = containerPT;
|
|
@@ -57,14 +60,14 @@ const calculate = (ref) => {
|
|
|
57
60
|
let currentWidth =
|
|
58
61
|
containerPL + containerPR + borderLeftWidth + borderRightWidth;
|
|
59
62
|
let maxHeight = 0;
|
|
63
|
+
|
|
60
64
|
$items.map((el) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
el.
|
|
64
|
-
|
|
65
|
-
el.style.width =
|
|
65
|
+
if (
|
|
66
|
+
params.type != types.row ||
|
|
67
|
+
!el.classList.contains('gs-sortable-placeholder')
|
|
68
|
+
) {
|
|
69
|
+
el.style.width = strItemWidth;
|
|
66
70
|
}
|
|
67
|
-
el.style.transition = transition;
|
|
68
71
|
});
|
|
69
72
|
ref.uiData = {
|
|
70
73
|
containerPT,
|
package/dist/actions/init.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import constParams from '../constants/constParams';
|
|
1
2
|
import calculate from './calculate';
|
|
2
3
|
import initDraggable from './initDraggable';
|
|
3
4
|
|
|
4
5
|
const init = (ref) => {
|
|
6
|
+
const transition = `left ${constParams.animateionSpeed}ms, top ${constParams.animateionSpeed}ms, transform ${constParams.animateionSpeed}ms`;
|
|
5
7
|
ref.grid.classList.add('gs-sortable-instance');
|
|
6
8
|
ref.grid.classList.add(`gs-sortable-${ref.currentParams.type}`);
|
|
7
9
|
[...ref.grid.children].map((el) => {
|
|
8
10
|
el.classList.add('gs-sortable-item');
|
|
11
|
+
el.style.transition = transition;
|
|
12
|
+
el.style.position = 'absolute';
|
|
9
13
|
|
|
10
14
|
let resizeObserver = new ResizeObserver(() => {
|
|
11
15
|
calculate(ref);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import constParams from '../constants/constParams';
|
|
2
|
+
import { getOffsetFromBody, getOffsetFromWindow } from './general';
|
|
2
3
|
|
|
3
4
|
const initDraggable = (ref) => {
|
|
4
5
|
const params = ref.currentParams;
|
|
@@ -32,6 +33,9 @@ const initDraggable = (ref) => {
|
|
|
32
33
|
placeholder.style.border = elStyles.border;
|
|
33
34
|
placeholder.style.borderRadius = elStyles.borderRadius;
|
|
34
35
|
ref.grid.append(placeholder);
|
|
36
|
+
|
|
37
|
+
const elOffsetWindow = getOffsetFromWindow($el);
|
|
38
|
+
|
|
35
39
|
let translateX = 0;
|
|
36
40
|
let translateY = 0;
|
|
37
41
|
if (!isNaN(parseFloat(top))) {
|
|
@@ -56,7 +60,10 @@ const initDraggable = (ref) => {
|
|
|
56
60
|
placeholder,
|
|
57
61
|
newLeft: left,
|
|
58
62
|
newTop: top,
|
|
63
|
+
fromLeft: (e.clientX - elOffsetWindow.left) / $el.offsetWidth,
|
|
64
|
+
fromTop: (e.clientY - elOffsetWindow.top) / $el.offsetHeight,
|
|
59
65
|
};
|
|
66
|
+
|
|
60
67
|
$el.classList.add('gs-sortable-item-inmove');
|
|
61
68
|
ref.grid.classList.add('gs-sortable-active');
|
|
62
69
|
if (ref.grid.closest('.gs-sortable-item') != null) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { getTranslateCoord } from './general';
|
|
1
|
+
import { getOffsetFromWindow, getTranslateCoord } from './general';
|
|
2
2
|
import getItemPositionToContainer from './checkItemInContainer';
|
|
3
3
|
import checkItemInContainer from './checkItemInContainer';
|
|
4
4
|
import calculate from './calculate';
|
|
5
5
|
import constParams from '../constants/constParams';
|
|
6
6
|
import calculateOnSort from './calculateOnSort';
|
|
7
|
+
import types from '../constants/types';
|
|
7
8
|
|
|
8
9
|
const initMouseMove = (event) => {
|
|
9
10
|
const info = window.GSSortableConfigue.draggableInfo;
|
|
@@ -37,24 +38,40 @@ const initMouseMove = (event) => {
|
|
|
37
38
|
document.querySelector('.gs-sortable-placeholder').remove();
|
|
38
39
|
calculate(window.GSSortableConfigue.overInItemRef);
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
const oldRef = window.GSSortableConfigue.overInItemRef;
|
|
41
42
|
window.GSSortableConfigue.overInItemRef = newRef;
|
|
43
|
+
info.$el.style.width =
|
|
44
|
+
window.GSSortableConfigue.overInItemRef.itemWidth;
|
|
45
|
+
const newWidth = info.$el.clientWidth;
|
|
46
|
+
const newHeight = info.$el.clientHeight;
|
|
47
|
+
|
|
48
|
+
const newContainerOffset = getOffsetFromWindow(
|
|
49
|
+
window.GSSortableConfigue.takeFrom.grid
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const translateY =
|
|
53
|
+
event.clientY - newContainerOffset.top - newHeight * info.fromTop;
|
|
54
|
+
const translateX =
|
|
55
|
+
event.clientX - newContainerOffset.left - newWidth * info.fromLeft;
|
|
56
|
+
|
|
42
57
|
const elStyles = getComputedStyle(info.$el);
|
|
43
58
|
const placeholder = document.createElement('div');
|
|
44
59
|
const top = parseFloat(elStyles.top);
|
|
45
60
|
const left = parseFloat(elStyles.left);
|
|
46
61
|
placeholder.classList.add('gs-sortable-placeholder');
|
|
47
62
|
placeholder.style.position = elStyles.position;
|
|
63
|
+
info.$el.style.transform = `translate(${translateX}px, ${translateY}px)`;
|
|
48
64
|
placeholder.style.transition = `left ${constParams.animateionSpeed}ms, top ${constParams.animateionSpeed}ms, transform ${constParams.animateionSpeed}ms, opacity ${constParams.animateionSpeed}ms, opacity ${constParams.animateionSpeed}ms`;
|
|
49
|
-
|
|
50
|
-
placeholder.style.height = `${info.$el.offsetHeight}px`;
|
|
65
|
+
|
|
51
66
|
placeholder.style.top = `${top}px`;
|
|
52
67
|
placeholder.style.left = `${left}px`;
|
|
53
68
|
placeholder.style.border = elStyles.border;
|
|
54
69
|
placeholder.style.borderRadius = elStyles.borderRadius;
|
|
55
|
-
newRef.grid.append(placeholder);
|
|
56
70
|
info.placeholder = placeholder;
|
|
57
71
|
info.ref = newRef;
|
|
72
|
+
placeholder.style.width = `${info.$el.offsetWidth}px`;
|
|
73
|
+
placeholder.style.height = `${info.$el.offsetHeight}px`;
|
|
74
|
+
newRef.grid.append(placeholder);
|
|
58
75
|
calculate(newRef);
|
|
59
76
|
return;
|
|
60
77
|
}
|
|
@@ -93,7 +110,6 @@ const initMouseMove = (event) => {
|
|
|
93
110
|
$el.style.transform = `translate(${tranlateX}px, ${tranlateY}px)`;
|
|
94
111
|
|
|
95
112
|
if (findedRef != '') {
|
|
96
|
-
console.log('calculateOnSort');
|
|
97
113
|
calculateOnSort(window.GSSortableConfigue.overInItemRef);
|
|
98
114
|
}
|
|
99
115
|
//}
|