@get-set/gs-sortable 0.0.20 → 0.0.21

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,43 +1,53 @@
1
- import calculate from "./calculate";
2
-
3
- const afterAllImagesLoad = (ref) => {
4
- const $images = [...ref.grid.querySelectorAll("img")];
5
- const count = $images.length;
6
-
7
- if (count > 0) {
8
- let alreadyLoaded = 0;
9
- $images.map((img) => {
10
- if (img.complete) {
11
- alreadyLoaded++;
12
- if (alreadyLoaded === count) {
13
- setTimeout(() => {
14
- calculate(ref);
15
- }, 500);
16
- }
17
- } else {
18
- img.onload = () => {
19
- alreadyLoaded++;
20
- if (alreadyLoaded === count) {
21
- setTimeout(() => {
22
- calculate(ref);
23
- }, 500);
24
- }
25
- };
26
- img.onerror = () => {
27
- alreadyLoaded++;
28
- if (alreadyLoaded === count) {
29
- setTimeout(() => {
30
- calculate(ref);
31
- }, 500);
32
- }
33
- };
34
- }
35
- });
36
- } else {
37
- setTimeout(() => {
38
- calculate(ref);
39
- }, 500);
40
- }
41
- };
42
-
43
- export default afterAllImagesLoad;
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _calculate = _interopRequireDefault(require("./calculate"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
10
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
13
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
+ var afterAllImagesLoad = function afterAllImagesLoad(ref) {
16
+ var $images = _toConsumableArray(ref.grid.querySelectorAll("img"));
17
+ var count = $images.length;
18
+ if (count > 0) {
19
+ var alreadyLoaded = 0;
20
+ $images.map(function (img) {
21
+ if (img.complete) {
22
+ alreadyLoaded++;
23
+ if (alreadyLoaded === count) {
24
+ setTimeout(function () {
25
+ (0, _calculate["default"])(ref);
26
+ }, 500);
27
+ }
28
+ } else {
29
+ img.onload = function () {
30
+ alreadyLoaded++;
31
+ if (alreadyLoaded === count) {
32
+ setTimeout(function () {
33
+ (0, _calculate["default"])(ref);
34
+ }, 500);
35
+ }
36
+ };
37
+ img.onerror = function () {
38
+ alreadyLoaded++;
39
+ if (alreadyLoaded === count) {
40
+ setTimeout(function () {
41
+ (0, _calculate["default"])(ref);
42
+ }, 500);
43
+ }
44
+ };
45
+ }
46
+ });
47
+ } else {
48
+ setTimeout(function () {
49
+ (0, _calculate["default"])(ref);
50
+ }, 500);
51
+ }
52
+ };
53
+ var _default = exports["default"] = afterAllImagesLoad;
@@ -1,145 +1,140 @@
1
- import constParams from '../constants/constParams';
2
- import types from '../constants/types';
3
-
4
- const calculate = (ref) => {
5
- const params = ref.currentParams;
6
- if (typeof ref.currentParams.beforeInit === 'function') {
7
- ref.currentParams.beforeInit();
8
- }
9
- const $items = [...ref.grid.children].filter(
10
- (x) => !x.classList.contains('gs-sortable-item-inmove')
11
- );
12
- const itemsCount = $items.length;
13
-
14
- ref.grid.style.position = 'relative';
15
- if (params.gap != '') {
16
- ref.grid.style.gap = params.gap;
17
- }
18
- const gridStyles = getComputedStyle(ref.grid);
19
- const cssGap = gridStyles.gap;
20
- let gapX = 0;
21
- let gapY = 0;
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;
25
-
26
- const gapYSize = parseInt(cssGapYValue);
27
- const gapXSize = parseInt(cssGapXValue);
28
- if (!Number.isNaN(gapYSize)) {
29
- gapY = gapYSize;
30
- }
31
- if (!Number.isNaN(gapXSize)) {
32
- gapX = gapXSize;
33
- }
34
- }
35
- const borderBottomWidth = parseFloat(gridStyles.borderBottomWidth);
36
- const borderTopWidth = parseFloat(gridStyles.borderTopWidth);
37
- const borderLeftWidth = parseFloat(gridStyles.borderLeftWidth);
38
- const borderRightWidth = parseFloat(gridStyles.borderRightWidth);
39
- const containerPT = parseFloat(gridStyles.paddingTop);
40
- const containerPR = parseFloat(gridStyles.paddingRight);
41
- const containerPB = parseFloat(gridStyles.paddingBottom);
42
- const containerPL = parseFloat(gridStyles.paddingLeft);
43
-
44
- const containerWidth = ref.grid.clientWidth - containerPR - containerPL;
45
- let itemWidth = 0;
46
- let strItemWidth = 'max-content';
47
- if (params.type == types.grid) {
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';
53
- }
54
- ref.itemWidth = strItemWidth;
55
-
56
- let currentLeft = containerPL;
57
- let currentTop = containerPT;
58
- let currentHeight =
59
- containerPT + containerPB + borderBottomWidth + borderTopWidth; //ref.grid.offsetHeight;
60
- let currentWidth =
61
- containerPL + containerPR + borderLeftWidth + borderRightWidth;
62
- let maxHeight = 0;
63
-
64
- $items.map((el) => {
65
- if (
66
- params.type != types.row ||
67
- !el.classList.contains('gs-sortable-placeholder')
68
- ) {
69
- el.style.width = strItemWidth;
70
- }
71
- });
72
- ref.uiData = {
73
- containerPT,
74
- containerPR,
75
- containerPB,
76
- containerPL,
77
- containerWidth,
78
- currentHeight,
79
- currentWidth,
80
- itemWidth,
81
- gapX,
82
- gapY,
83
- };
84
- let colHeight = 0;
85
- $items.map((el, index) => {
86
- const height = el.offsetHeight;
87
- const width = el.offsetWidth;
88
- if (params.type == types.column) {
89
- el.style.left = `${containerPL}px`;
90
- if (currentTop == containerPT) {
91
- el.style.top = `${containerPT}px`;
92
- currentTop = containerPT + height;
93
- currentHeight = currentHeight + height;
94
- } else {
95
- el.style.top = `${currentTop + gapY}px`;
96
- currentTop = currentTop + gapY + height;
97
- currentHeight = currentHeight + height + gapY;
98
- }
99
- } else if (params.type == types.row) {
100
- el.style.top = `${containerPT}px`;
101
- if (currentLeft == containerPL) {
102
- el.style.left = `${containerPL}px`;
103
- currentLeft = containerPL + width;
104
- currentWidth = currentWidth + width;
105
- } else {
106
- el.style.left = `${currentLeft + gapX}px`;
107
- currentLeft = currentLeft + gapX + width;
108
- currentWidth = currentWidth + width + gapX;
109
- }
110
- if (height > maxHeight) {
111
- maxHeight = height;
112
- }
113
- } else if (params.type == types.grid) {
114
- const left =
115
- index % params.count == 0
116
- ? containerPL
117
- : containerPL + (index % params.count) * (itemWidth + gapX);
118
- const top = currentTop;
119
- if (height > colHeight) {
120
- colHeight = height;
121
- }
122
- if (
123
- index % params.count === params.count - 1 ||
124
- index === itemsCount - 1
125
- ) {
126
- if (top === containerPT) {
127
- currentHeight = currentHeight + colHeight;
128
- } else {
129
- currentHeight = currentHeight + colHeight + gapY;
130
- }
131
- currentTop = currentTop + colHeight + gapY;
132
- colHeight = 0;
133
- }
134
- el.style.left = `${left}px`;
135
- el.style.top = `${top}px`;
136
- }
137
- });
138
- ref.grid.style.height = `${currentHeight}px`;
139
- if (params.type == types.row) {
140
- ref.grid.style.height = `${currentHeight + maxHeight}px`;
141
- ref.grid.style.width = `${currentWidth}px`;
142
- }
143
- };
144
-
145
- export default calculate;
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _constParams = _interopRequireDefault(require("../constants/constParams"));
8
+ var _types = _interopRequireDefault(require("../constants/types"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
10
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
11
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
13
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
14
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
15
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ var calculate = function calculate(ref) {
17
+ var params = ref.currentParams;
18
+ if (typeof ref.currentParams.beforeInit === 'function') {
19
+ ref.currentParams.beforeInit();
20
+ }
21
+ var $items = _toConsumableArray(ref.grid.children).filter(function (x) {
22
+ return !x.classList.contains('gs-sortable-item-inmove');
23
+ });
24
+ var itemsCount = $items.length;
25
+ ref.grid.style.position = 'relative';
26
+ if (params.gap != '') {
27
+ ref.grid.style.gap = params.gap;
28
+ }
29
+ var gridStyles = getComputedStyle(ref.grid);
30
+ var cssGap = gridStyles.gap;
31
+ var gapX = 0;
32
+ var gapY = 0;
33
+ if (typeof cssGap !== 'undefined' && cssGap !== null) {
34
+ var cssGapYValue = cssGap.includes(' ') ? cssGap.split(' ')[0] : cssGap;
35
+ var cssGapXValue = cssGap.includes(' ') ? cssGap.split(' ')[1] : cssGap;
36
+ var gapYSize = parseInt(cssGapYValue);
37
+ var gapXSize = parseInt(cssGapXValue);
38
+ if (!Number.isNaN(gapYSize)) {
39
+ gapY = gapYSize;
40
+ }
41
+ if (!Number.isNaN(gapXSize)) {
42
+ gapX = gapXSize;
43
+ }
44
+ }
45
+ var borderBottomWidth = parseFloat(gridStyles.borderBottomWidth);
46
+ var borderTopWidth = parseFloat(gridStyles.borderTopWidth);
47
+ var borderLeftWidth = parseFloat(gridStyles.borderLeftWidth);
48
+ var borderRightWidth = parseFloat(gridStyles.borderRightWidth);
49
+ var containerPT = parseFloat(gridStyles.paddingTop);
50
+ var containerPR = parseFloat(gridStyles.paddingRight);
51
+ var containerPB = parseFloat(gridStyles.paddingBottom);
52
+ var containerPL = parseFloat(gridStyles.paddingLeft);
53
+ var containerWidth = ref.grid.clientWidth - containerPR - containerPL;
54
+ var itemWidth = 0;
55
+ var strItemWidth = 'max-content';
56
+ if (params.type == _types["default"].grid) {
57
+ itemWidth = (containerWidth - (params.count - 1) * gapX) / params.count;
58
+ strItemWidth = itemWidth + 'px';
59
+ } else if (params.type == _types["default"].column) {
60
+ itemWidth = containerWidth;
61
+ strItemWidth = itemWidth + 'px';
62
+ }
63
+ ref.itemWidth = strItemWidth;
64
+ var currentLeft = containerPL;
65
+ var currentTop = containerPT;
66
+ var currentHeight = containerPT + containerPB + borderBottomWidth + borderTopWidth; //ref.grid.offsetHeight;
67
+ var currentWidth = containerPL + containerPR + borderLeftWidth + borderRightWidth;
68
+ var maxHeight = 0;
69
+ $items.map(function (el) {
70
+ if (params.type != _types["default"].row || !el.classList.contains('gs-sortable-placeholder')) {
71
+ el.style.width = strItemWidth;
72
+ }
73
+ });
74
+ ref.uiData = {
75
+ containerPT: containerPT,
76
+ containerPR: containerPR,
77
+ containerPB: containerPB,
78
+ containerPL: containerPL,
79
+ containerWidth: containerWidth,
80
+ currentHeight: currentHeight,
81
+ currentWidth: currentWidth,
82
+ itemWidth: itemWidth,
83
+ gapX: gapX,
84
+ gapY: gapY
85
+ };
86
+ var colHeight = 0;
87
+ $items.map(function (el, index) {
88
+ var height = el.offsetHeight;
89
+ var width = el.offsetWidth;
90
+ if (params.type == _types["default"].column) {
91
+ el.style.left = "".concat(containerPL, "px");
92
+ if (currentTop == containerPT) {
93
+ el.style.top = "".concat(containerPT, "px");
94
+ currentTop = containerPT + height;
95
+ currentHeight = currentHeight + height;
96
+ } else {
97
+ el.style.top = "".concat(currentTop + gapY, "px");
98
+ currentTop = currentTop + gapY + height;
99
+ currentHeight = currentHeight + height + gapY;
100
+ }
101
+ } else if (params.type == _types["default"].row) {
102
+ el.style.top = "".concat(containerPT, "px");
103
+ if (currentLeft == containerPL) {
104
+ el.style.left = "".concat(containerPL, "px");
105
+ currentLeft = containerPL + width;
106
+ currentWidth = currentWidth + width;
107
+ } else {
108
+ el.style.left = "".concat(currentLeft + gapX, "px");
109
+ currentLeft = currentLeft + gapX + width;
110
+ currentWidth = currentWidth + width + gapX;
111
+ }
112
+ if (height > maxHeight) {
113
+ maxHeight = height;
114
+ }
115
+ } else if (params.type == _types["default"].grid) {
116
+ var left = index % params.count == 0 ? containerPL : containerPL + index % params.count * (itemWidth + gapX);
117
+ var top = currentTop;
118
+ if (height > colHeight) {
119
+ colHeight = height;
120
+ }
121
+ if (index % params.count === params.count - 1 || index === itemsCount - 1) {
122
+ if (top === containerPT) {
123
+ currentHeight = currentHeight + colHeight;
124
+ } else {
125
+ currentHeight = currentHeight + colHeight + gapY;
126
+ }
127
+ currentTop = currentTop + colHeight + gapY;
128
+ colHeight = 0;
129
+ }
130
+ el.style.left = "".concat(left, "px");
131
+ el.style.top = "".concat(top, "px");
132
+ }
133
+ });
134
+ ref.grid.style.height = "".concat(currentHeight, "px");
135
+ if (params.type == _types["default"].row) {
136
+ ref.grid.style.height = "".concat(currentHeight + maxHeight, "px");
137
+ ref.grid.style.width = "".concat(currentWidth, "px");
138
+ }
139
+ };
140
+ var _default = exports["default"] = calculate;