@get-set/gs-sortable 0.0.6 → 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 "../constants/constParams";
2
- import types from "../constants/types";
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 === "function") {
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("gs-sortable-item-inmove")
10
+ (x) => !x.classList.contains('gs-sortable-item-inmove')
12
11
  );
13
12
  const itemsCount = $items.length;
14
13
 
15
- ref.grid.style.position = "relative";
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 !== "undefined" && cssGap !== null) {
24
- const cssGapYValue = cssGap.includes(" ") ? cssGap.split(" ")[0] : cssGap;
25
- const cssGapXValue = cssGap.includes(" ") ? cssGap.split(" ")[1] : cssGap;
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
- el.style.position = "absolute";
62
- if (params.type == types.column) {
63
- el.style.width = `${containerWidth}px`;
64
- } else if (params.type == types.grid) {
65
- el.style.width = `${itemWidth}px`;
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,
@@ -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
- placeholder.style.width = `${info.$el.offsetWidth}px`;
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
  //}
@@ -8,32 +8,30 @@ import defaultParams from '../constants/defaultParams';
8
8
  import initMouseMove from "../actions/initMouseMove";
9
9
  import initSortEnd from "../actions/initSortEnd";
10
10
  import initScroll from "../actions/initScroll";
11
+ import types from '../constants/types';
11
12
 
12
13
  const params = {
13
14
  reference: PropTypes.string,
15
+ handler: PropTypes.string,
14
16
  gap: PropTypes.string,
17
+ allowOutOfBox: PropTypes.bool,
15
18
  count: PropTypes.number,
16
- resetSortHandler: PropTypes.number,
17
- resetFilterHandler: PropTypes.number,
19
+ type: types.column | types.row | types.grid,
18
20
  };
19
21
 
22
+
23
+
24
+
20
25
  /**
21
26
  * GSSortable component to display a customizable sortable.
22
27
  *
23
28
  * @component
24
29
  * @param {Object} props - The props object.
25
30
  * @param {string} props.gap - Allows set gap among elements.
31
+ * @param {string} props.handler - selector of target element to move.
26
32
  * @param {number} props.count - Shows items count per row.
27
- * @param {Object} props.resetSortHandler - This is the ref of that element which should reset order.
28
- * @param {Object} props.resetFilterHandler - This is the ref of that element which should reset filter.
29
- * @param {Array<Object>} [props.sortByOptions] - Array of sort options.
30
- * @param {number} props.sortByOptions[].handler - This is the ref of that element which should change order.
31
- * @param {string} props.sortByOptions[].prop - this is the name of data attribute of element like data-[prop].
32
- * @param {'number' | 'string'} props.sortByOptions[].type - this is the type of prop.
33
- * @param {Array<Object>} [props.filterByOptions] - Array of filter options.
34
- * @param {number} props.filterByOptions[].handler - This is the ref of that element which should change filter.
35
- * @param {string} props.filterByOptions[].prop - This is the name of data attribute of element like data-[prop].
36
- * @param {'number' | 'string'} props.filterByOptions[].value - This is the value of prop for element.
33
+ * @param {'row' | 'column' | 'grid'} props.type - this is the type of prop.
34
+ * @param {Array<Object>} [props.acceptFrom] - Array of that GSSortable references which can accept element from this.
37
35
  * @param {Array<Object>} [props.responsive] - Array of responsive configurations based on window size.
38
36
  * @param {number} props.responsive[].windowSize - Minimum window size for this configuration.
39
37
  * @param {Object} props.responsive[].params - The responsive configuration for the grid.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-set/gs-sortable",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Get-Set Sortable",
5
5
  "main": "index.js",
6
6
  "author": "Get-Set",