@momo-kits/slider 0.0.74-beta → 0.72.1
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/DefaultLabel.js +63 -66
- package/DefaultLabel.web.js +62 -65
- package/DefaultMarker.js +58 -63
- package/DefaultMarker.web.js +66 -63
- package/Slider.js +298 -258
- package/Slider.web.js +719 -699
- package/converters.js +56 -55
- package/package.json +14 -14
- package/publish.sh +2 -2
package/converters.js
CHANGED
|
@@ -2,78 +2,79 @@
|
|
|
2
2
|
/* eslint-disable no-else-return */
|
|
3
3
|
// Find closest index for a given value
|
|
4
4
|
const closest = (array, n) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
let minI = 0;
|
|
6
|
+
let maxI = array.length - 1;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
if (array[minI] > n) {
|
|
9
|
+
return minI;
|
|
10
|
+
} else if (array[maxI] < n) {
|
|
11
|
+
return maxI;
|
|
12
|
+
} else if (array[minI] <= n && n <= array[maxI]) {
|
|
13
|
+
let closestIndex = null;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
while (closestIndex === null) {
|
|
16
|
+
const midI = Math.round((minI + maxI) / 2);
|
|
17
|
+
const midVal = array[midI];
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
if (midVal === n) {
|
|
20
|
+
closestIndex = midI;
|
|
21
|
+
} else if (maxI === minI + 1) {
|
|
22
|
+
const minValue = array[minI];
|
|
23
|
+
const maxValue = array[maxI];
|
|
24
|
+
const deltaMin = Math.abs(minValue - n);
|
|
25
|
+
const deltaMax = Math.abs(maxValue - n);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return closestIndex;
|
|
27
|
+
closestIndex = deltaMax <= deltaMin ? maxI : minI;
|
|
28
|
+
} else if (midVal < n) {
|
|
29
|
+
minI = midI;
|
|
30
|
+
} else if (midVal > n) {
|
|
31
|
+
maxI = midI;
|
|
32
|
+
} else {
|
|
33
|
+
closestIndex = -1;
|
|
34
|
+
}
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
return
|
|
37
|
+
return closestIndex;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return -1;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export function valueToPosition(value, valuesArray, sliderLength) {
|
|
44
|
-
|
|
44
|
+
const index = closest(valuesArray, value);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const arrLength = valuesArray.length - 1;
|
|
47
|
+
const validIndex = index === -1 ? arrLength : index;
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
return (sliderLength * validIndex) / arrLength;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export function positionToValue(position, valuesArray, sliderLength) {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
let arrLength;
|
|
54
|
+
let index;
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
if (position < 0 || sliderLength < position) {
|
|
57
|
+
return null;
|
|
58
|
+
} else {
|
|
59
|
+
arrLength = valuesArray.length - 1;
|
|
60
|
+
index = (arrLength * position) / sliderLength;
|
|
61
|
+
return valuesArray[Math.round(index)];
|
|
62
|
+
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export function createArray(start, end, step) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
66
|
+
let i;
|
|
67
|
+
let length;
|
|
68
|
+
const direction = start - end > 0 ? -1 : 1;
|
|
69
|
+
const result = [];
|
|
70
|
+
if (!step) {
|
|
71
|
+
return result;
|
|
72
|
+
} else {
|
|
73
|
+
length = Math.abs((start - end) / step);
|
|
74
|
+
for (i = 0; i <= length; i++) {
|
|
75
|
+
result.push(start + i * Math.abs(step) * direction);
|
|
78
76
|
}
|
|
77
|
+
if (result[length - 1] != end) result.push(end);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
79
80
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@momo-kits/slider",
|
|
3
|
+
"version": "0.72.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@momo-kits/core-v2": ">=0.0.5-beta",
|
|
9
|
+
"lodash": "^4.17.15",
|
|
10
|
+
"prop-types": "^15.7.2",
|
|
11
|
+
"react": "16.9.0",
|
|
12
|
+
"react-native": ">=0.55"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {},
|
|
15
|
+
"license": "MoMo"
|
|
16
16
|
}
|
package/publish.sh
CHANGED
|
@@ -21,9 +21,9 @@ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type
|
|
|
21
21
|
#npm login
|
|
22
22
|
#publish dist to npm
|
|
23
23
|
cd dist
|
|
24
|
-
npm publish --access=public
|
|
24
|
+
npm publish --tag beta --access=public
|
|
25
25
|
cd ..
|
|
26
26
|
rm -rf dist
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/stepper new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/stepper"}'
|
|
29
|
+
#curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/stepper new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/stepper"}'
|