@micromag/core 0.3.812 → 0.3.814
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/es/hooks.js +26 -32
- package/lib/hooks.js +26 -32
- package/package.json +3 -2
package/es/hooks.js
CHANGED
|
@@ -17,6 +17,7 @@ import raf from 'raf';
|
|
|
17
17
|
import createDebug from 'debug';
|
|
18
18
|
import isString from 'lodash/isString';
|
|
19
19
|
import { useScreensManager, useFieldsManager, useTracking, useScreen } from '@micromag/core/contexts';
|
|
20
|
+
import { useWindowSize } from '@folklore/hooks';
|
|
20
21
|
import { match } from 'css-mediaquery';
|
|
21
22
|
import { useIntl } from 'react-intl';
|
|
22
23
|
import dayjs from 'dayjs';
|
|
@@ -2093,30 +2094,8 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
|
2093
2094
|
resolution: !withoutScale ? scale * devicePixelRatio : devicePixelRatio
|
|
2094
2095
|
};
|
|
2095
2096
|
};
|
|
2096
|
-
var getWindowSize = function getWindowSize() {
|
|
2097
|
-
return {
|
|
2098
|
-
width: typeof window !== 'undefined' ? window.innerWidth : null,
|
|
2099
|
-
height: typeof window !== 'undefined' ? window.innerHæeight : null
|
|
2100
|
-
};
|
|
2101
|
-
};
|
|
2102
2097
|
var useScreenSizeFromWindow = function useScreenSizeFromWindow(opts) {
|
|
2103
|
-
var
|
|
2104
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
2105
|
-
windowSize = _useState4[0],
|
|
2106
|
-
setWindowSize = _useState4[1];
|
|
2107
|
-
useEffect(function () {
|
|
2108
|
-
var onResize = function onResize() {
|
|
2109
|
-
return setWindowSize(getWindowSize());
|
|
2110
|
-
};
|
|
2111
|
-
if (typeof window !== 'undefined') {
|
|
2112
|
-
window.addEventListener('resize', onResize);
|
|
2113
|
-
}
|
|
2114
|
-
return function () {
|
|
2115
|
-
if (typeof window !== 'undefined') {
|
|
2116
|
-
window.removeEventListener('resize', onResize);
|
|
2117
|
-
}
|
|
2118
|
-
};
|
|
2119
|
-
}, [setWindowSize]);
|
|
2098
|
+
var windowSize = useWindowSize();
|
|
2120
2099
|
return useScreenSize(_objectSpread(_objectSpread({}, opts), windowSize));
|
|
2121
2100
|
};
|
|
2122
2101
|
|
|
@@ -2144,20 +2123,34 @@ function useSpringValue(wantedProgress, immediate, params) {
|
|
|
2144
2123
|
return immediate ? wantedProgress : progress;
|
|
2145
2124
|
}
|
|
2146
2125
|
|
|
2147
|
-
function
|
|
2148
|
-
|
|
2149
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
2150
|
-
supportsWebp = _useState2[0],
|
|
2151
|
-
setSupportsWebp = _useState2[1];
|
|
2152
|
-
useEffect(function () {
|
|
2126
|
+
function checkWebpSupport() {
|
|
2127
|
+
return new Promise(function (resolve) {
|
|
2153
2128
|
var img = document.createElement('img');
|
|
2154
2129
|
img.onload = function () {
|
|
2155
|
-
|
|
2130
|
+
resolve(img.width > 0 && img.height > 0);
|
|
2156
2131
|
};
|
|
2157
2132
|
img.onerror = function () {
|
|
2158
|
-
|
|
2133
|
+
resolve(false);
|
|
2159
2134
|
};
|
|
2160
2135
|
img.src = 'data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoCAAEAAQAcJaQAA3AA/v3AgAA=';
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
function useSupportsWebp() {
|
|
2139
|
+
var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
2140
|
+
var _useState = useState(defaultValue),
|
|
2141
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2142
|
+
supportsWebp = _useState2[0],
|
|
2143
|
+
setSupportsWebp = _useState2[1];
|
|
2144
|
+
useEffect(function () {
|
|
2145
|
+
var canceled = false;
|
|
2146
|
+
checkWebpSupport().then(function (newSupport) {
|
|
2147
|
+
if (!canceled && newSupport !== supportsWebp) {
|
|
2148
|
+
setSupportsWebp(newSupport);
|
|
2149
|
+
}
|
|
2150
|
+
});
|
|
2151
|
+
return function () {
|
|
2152
|
+
canceled = true;
|
|
2153
|
+
};
|
|
2161
2154
|
}, []);
|
|
2162
2155
|
return supportsWebp;
|
|
2163
2156
|
}
|
|
@@ -2190,7 +2183,8 @@ var useSwipe = function useSwipe() {
|
|
|
2190
2183
|
var index = useRef(0);
|
|
2191
2184
|
var lockedAxis = useRef(null);
|
|
2192
2185
|
var hasWidth = width !== null;
|
|
2193
|
-
var
|
|
2186
|
+
var _useWindowSize = useWindowSize(),
|
|
2187
|
+
windowWidth = _useWindowSize.width;
|
|
2194
2188
|
var currentWidth = hasWidth ? width : windowWidth;
|
|
2195
2189
|
var count = items.length;
|
|
2196
2190
|
var getItem = useCallback(function () {
|
package/lib/hooks.js
CHANGED
|
@@ -19,6 +19,7 @@ var raf = require('raf');
|
|
|
19
19
|
var createDebug = require('debug');
|
|
20
20
|
var isString = require('lodash/isString');
|
|
21
21
|
var contexts = require('@micromag/core/contexts');
|
|
22
|
+
var hooks = require('@folklore/hooks');
|
|
22
23
|
var cssMediaquery = require('css-mediaquery');
|
|
23
24
|
var reactIntl = require('react-intl');
|
|
24
25
|
var dayjs = require('dayjs');
|
|
@@ -2095,30 +2096,8 @@ var useScreenSizeFromElement = function useScreenSizeFromElement() {
|
|
|
2095
2096
|
resolution: !withoutScale ? scale * devicePixelRatio : devicePixelRatio
|
|
2096
2097
|
};
|
|
2097
2098
|
};
|
|
2098
|
-
var getWindowSize = function getWindowSize() {
|
|
2099
|
-
return {
|
|
2100
|
-
width: typeof window !== 'undefined' ? window.innerWidth : null,
|
|
2101
|
-
height: typeof window !== 'undefined' ? window.innerHæeight : null
|
|
2102
|
-
};
|
|
2103
|
-
};
|
|
2104
2099
|
var useScreenSizeFromWindow = function useScreenSizeFromWindow(opts) {
|
|
2105
|
-
var
|
|
2106
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
2107
|
-
windowSize = _useState4[0],
|
|
2108
|
-
setWindowSize = _useState4[1];
|
|
2109
|
-
react.useEffect(function () {
|
|
2110
|
-
var onResize = function onResize() {
|
|
2111
|
-
return setWindowSize(getWindowSize());
|
|
2112
|
-
};
|
|
2113
|
-
if (typeof window !== 'undefined') {
|
|
2114
|
-
window.addEventListener('resize', onResize);
|
|
2115
|
-
}
|
|
2116
|
-
return function () {
|
|
2117
|
-
if (typeof window !== 'undefined') {
|
|
2118
|
-
window.removeEventListener('resize', onResize);
|
|
2119
|
-
}
|
|
2120
|
-
};
|
|
2121
|
-
}, [setWindowSize]);
|
|
2100
|
+
var windowSize = hooks.useWindowSize();
|
|
2122
2101
|
return useScreenSize(_objectSpread(_objectSpread({}, opts), windowSize));
|
|
2123
2102
|
};
|
|
2124
2103
|
|
|
@@ -2146,20 +2125,34 @@ function useSpringValue(wantedProgress, immediate, params) {
|
|
|
2146
2125
|
return immediate ? wantedProgress : progress;
|
|
2147
2126
|
}
|
|
2148
2127
|
|
|
2149
|
-
function
|
|
2150
|
-
|
|
2151
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
2152
|
-
supportsWebp = _useState2[0],
|
|
2153
|
-
setSupportsWebp = _useState2[1];
|
|
2154
|
-
react.useEffect(function () {
|
|
2128
|
+
function checkWebpSupport() {
|
|
2129
|
+
return new Promise(function (resolve) {
|
|
2155
2130
|
var img = document.createElement('img');
|
|
2156
2131
|
img.onload = function () {
|
|
2157
|
-
|
|
2132
|
+
resolve(img.width > 0 && img.height > 0);
|
|
2158
2133
|
};
|
|
2159
2134
|
img.onerror = function () {
|
|
2160
|
-
|
|
2135
|
+
resolve(false);
|
|
2161
2136
|
};
|
|
2162
2137
|
img.src = 'data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoCAAEAAQAcJaQAA3AA/v3AgAA=';
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
function useSupportsWebp() {
|
|
2141
|
+
var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
2142
|
+
var _useState = react.useState(defaultValue),
|
|
2143
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2144
|
+
supportsWebp = _useState2[0],
|
|
2145
|
+
setSupportsWebp = _useState2[1];
|
|
2146
|
+
react.useEffect(function () {
|
|
2147
|
+
var canceled = false;
|
|
2148
|
+
checkWebpSupport().then(function (newSupport) {
|
|
2149
|
+
if (!canceled && newSupport !== supportsWebp) {
|
|
2150
|
+
setSupportsWebp(newSupport);
|
|
2151
|
+
}
|
|
2152
|
+
});
|
|
2153
|
+
return function () {
|
|
2154
|
+
canceled = true;
|
|
2155
|
+
};
|
|
2163
2156
|
}, []);
|
|
2164
2157
|
return supportsWebp;
|
|
2165
2158
|
}
|
|
@@ -2192,7 +2185,8 @@ var useSwipe = function useSwipe() {
|
|
|
2192
2185
|
var index = react.useRef(0);
|
|
2193
2186
|
var lockedAxis = react.useRef(null);
|
|
2194
2187
|
var hasWidth = width !== null;
|
|
2195
|
-
var
|
|
2188
|
+
var _useWindowSize = hooks.useWindowSize(),
|
|
2189
|
+
windowWidth = _useWindowSize.width;
|
|
2196
2190
|
var currentWidth = hasWidth ? width : windowWidth;
|
|
2197
2191
|
var count = items.length;
|
|
2198
2192
|
var getItem = react.useCallback(function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.814",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"@babel/runtime": "^7.13.10",
|
|
131
131
|
"@folklore/fetch": "^0.1.17",
|
|
132
132
|
"@folklore/forms": "~0.0.23",
|
|
133
|
+
"@folklore/hooks": "^0.0.83",
|
|
133
134
|
"@folklore/routes": "^0.2.36",
|
|
134
135
|
"@folklore/services": "^0.1.24",
|
|
135
136
|
"@folklore/size": "^0.1.20",
|
|
@@ -167,5 +168,5 @@
|
|
|
167
168
|
"access": "public",
|
|
168
169
|
"registry": "https://registry.npmjs.org/"
|
|
169
170
|
},
|
|
170
|
-
"gitHead": "
|
|
171
|
+
"gitHead": "96d19c8ede8dc2e8c051ba118975258e061a8da2"
|
|
171
172
|
}
|