@vorlefan/react-hooks
Advanced tools
Comparing version 1.2.7 to 1.3.0
@@ -125,3 +125,3 @@ import { useMemo, useState, useEffect, useCallback } from 'react'; | ||
function useIndex(_a) { | ||
var _b = _a.value, value = _b === void 0 ? 0 : _b, _c = _a.min, min = _c === void 0 ? 0 : _c, _d = _a.max, max = _d === void 0 ? 9 : _d, _e = _a.reverse, reverse = _e === void 0 ? true : _e, _f = _a.step, step = _f === void 0 ? 1 : _f, _g = _a.format, format = _g === void 0 ? null : _g; | ||
var _b = _a.value, value = _b === void 0 ? 0 : _b, _c = _a.min, min = _c === void 0 ? 0 : _c, _d = _a.max, max = _d === void 0 ? 9 : _d, _e = _a.reverse, reverse = _e === void 0 ? true : _e, _f = _a.step, step = _f === void 0 ? 1 : _f, format = _a.format; | ||
var setup = useObject({ | ||
@@ -177,66 +177,2 @@ value: value, | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
/** | ||
@@ -268,10 +204,11 @@ * @description create a toggle object handler | ||
var state = {}; | ||
var dollarSign = {}; | ||
Object.keys(data).map(function (dataKey) { | ||
state[dataKey] = useBoolean(!!data[dataKey]); | ||
dollarSign["$" + dataKey] = state[dataKey]; | ||
}); | ||
return useMemo(function () { return (__assign({ state: state, toggle: function (key) { | ||
return useMemo(function () { return ({ | ||
state: state, | ||
toggle: function (key) { | ||
return state.hasOwnProperty(key) && state[key].toggle(); | ||
}, set: function (key, value) { | ||
}, | ||
set: function (key, value) { | ||
if (state.hasOwnProperty(key)) { | ||
@@ -283,23 +220,32 @@ state[key].set(value); | ||
} | ||
}, check: function (key) { return !!state[key].state; }, highlight: function (key) { | ||
}, | ||
check: function (key) { return !!state[key] && !!state[key].state; }, | ||
highlight: function (key) { | ||
for (var option in state) { | ||
state[option].set(key === option); | ||
} | ||
}, shadow: function (key) { | ||
}, | ||
shadow: function (key) { | ||
for (var option in state) { | ||
state[option].set(key !== option); | ||
} | ||
}, reset: function (value) { | ||
}, | ||
reset: function (value) { | ||
for (var option in state) { | ||
state[option].set(!!value); | ||
} | ||
}, enabled: function () { | ||
}, | ||
enabled: function () { | ||
return Object.keys(state).filter(function (key) { return state[key].isOn(); }); | ||
}, disabled: function () { | ||
}, | ||
disabled: function () { | ||
return Object.keys(state).filter(function (key) { return state[key].isOff(); }); | ||
}, keys: function () { return Object.keys(state); }, each: function (callback) { | ||
}, | ||
keys: function () { return Object.keys(state); }, | ||
each: function (callback) { | ||
return Object.keys(state).map(function (key, index) { | ||
return callback({ key: key, index: index, value: state[key] }); | ||
}); | ||
}, isAll: function (value, except) { | ||
}, | ||
isAll: function (value, except) { | ||
var checker = true; | ||
@@ -318,16 +264,83 @@ for (var option in state) { | ||
return checker; | ||
} }, dollarSign)); }, [state]); | ||
}, | ||
}); }, [state]); | ||
} | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
function getSize(screenSize, config, margin) { | ||
if (margin === void 0) { margin = [1, 1]; } | ||
if (typeof window === 'undefined') { | ||
return config; | ||
return __assign(__assign({}, config), { aspect: [0, 0] }); | ||
} | ||
var innerWidth = window.innerWidth, innerHeight = window.innerHeight, outerWidth = window.outerWidth, outerHeight = window.outerHeight; | ||
var aspect = [margin[0] || 1, margin[1] || 1]; | ||
innerWidth *= aspect[0] || 1; | ||
innerHeight *= aspect[1] || 1; | ||
var orientation = innerWidth > innerHeight ? 'landscape' : 'portrait'; | ||
var percentualRatio = innerHeight / innerWidth; | ||
var vw = Math.max(document.documentElement.clientWidth || 0, innerWidth || 0); | ||
var vh = Math.max(document.documentElement.clientHeight || 0, innerHeight || 0); | ||
vw *= aspect[0] || 1; | ||
vh *= aspect[1] || 1; | ||
var orientation = vw > vh ? 'landscape' : 'portrait'; | ||
var percentualRatio = vh / vw; | ||
var ratio = +parseFloat(percentualRatio.toString()).toFixed(2); | ||
@@ -348,19 +361,22 @@ var difference = 0; | ||
orientation: orientation, | ||
previous: screenSize, | ||
aspect: aspect, | ||
}; | ||
} | ||
function useScreenSize(config, margin) { | ||
if (config === void 0) { config = { | ||
innerWidth: 1360, | ||
innerHeight: 640, | ||
outerWidth: 1360, | ||
outerHeight: 640, | ||
ratio: 0.47, | ||
orientation: 'landscape', | ||
difference: 1, | ||
}; } | ||
if (margin === void 0) { margin = [1, 1]; } | ||
var _a = useState(getSize(__assign({}, config), config, margin)), screenSize = _a[0], setScreenSize = _a[1]; | ||
var handleResize = useCallback(function () { return setScreenSize(getSize(screenSize, config, margin)); }, []); | ||
/** | ||
* @description get the window size | ||
*/ | ||
var SCREEN_SIZE_DEFAULT_CONFIG = { | ||
innerWidth: 1360, | ||
innerHeight: 640, | ||
outerWidth: 1360, | ||
outerHeight: 640, | ||
ratio: 0.47, | ||
orientation: 'landscape', | ||
difference: 1, | ||
}; | ||
function useScreenSize(margin, config) { | ||
var _a = useState(getSize(!!config ? __assign({}, config) : SCREEN_SIZE_DEFAULT_CONFIG, config || SCREEN_SIZE_DEFAULT_CONFIG, margin || [1, 1])), screenSize = _a[0], setScreenSize = _a[1]; | ||
var handleResize = useCallback(function () { | ||
return setScreenSize(getSize(screenSize, config || SCREEN_SIZE_DEFAULT_CONFIG, margin)); | ||
}, []); | ||
useEffect(function () { | ||
@@ -382,8 +398,12 @@ window.addEventListener('resize', function () { | ||
outerWidth: screenSize.outerWidth, | ||
fullHD: function () { | ||
isFullHD: function () { | ||
return screenSize.innerWidth >= 1920 && screenSize.innerHeight >= 1080; | ||
}, | ||
hd: function () { | ||
isHD: function () { | ||
return screenSize.innerWidth >= 1360 && screenSize.innerHeight >= 724; | ||
}, | ||
isTablet: function () { | ||
return screenSize.innerWidth >= 768 && screenSize.innerWidth <= 1360; | ||
}, | ||
isMobile: function () { return screenSize.innerWidth < 768; }, | ||
}); }, [screenSize]); | ||
@@ -457,3 +477,3 @@ } | ||
if (!inClient) | ||
return null; | ||
return false; | ||
var _a = useState(false), pressed = _a[0], setPressed = _a[1]; | ||
@@ -467,3 +487,3 @@ var isMatching = useCallback(function (event) { | ||
if (typeof callback === 'function') { | ||
callback(); | ||
callback(event); | ||
} | ||
@@ -601,11 +621,11 @@ } | ||
var _this = this; | ||
var endpoint = _a.endpoint, body = _a.body, _b = _a.config, config = _b === void 0 ? {} : _b, token = _a.token, onSuccess = _a.onSuccess, onError = _a.onError, onData = _a.onData, _c = _a.start, start = _c === void 0 ? true : _c, _d = _a.stateInit, stateInit = _d === void 0 ? [] : _d, query = _a.query, _e = _a.format, format = _e === void 0 ? null : _e, _f = _a.generalOptions, generalOptions = _f === void 0 ? {} : _f; | ||
var endpoint = _a.endpoint, body = _a.body, _b = _a.config, config = _b === void 0 ? {} : _b, token = _a.token, onSuccess = _a.onSuccess, onError = _a.onError, onData = _a.onData, _c = _a.start, start = _c === void 0 ? true : _c, _d = _a.stateInit, stateInit = _d === void 0 ? [] : _d, query = _a.query, format = _a.format, _e = _a.generalOptions, generalOptions = _e === void 0 ? {} : _e; | ||
if (methodHTTP === void 0) { methodHTTP = 'GET'; } | ||
var _g = useState(stateInit), data = _g[0], setData = _g[1]; | ||
var _f = useState(stateInit), data = _f[0], setData = _f[1]; | ||
var loading = useBoolean(start); | ||
var _h = useState(null), error = _h[0], setError = _h[1]; | ||
var _g = useState(null), error = _g[0], setError = _g[1]; | ||
var refresh = useBoolean(start); | ||
var setup = useObject(body || {}); | ||
var _j = useState(endpoint), uri = _j[0], setUri = _j[1]; | ||
var _k = useState(methodHTTP), method = _k[0], setMethod = _k[1]; | ||
var _h = useState(endpoint), uri = _h[0], setUri = _h[1]; | ||
var _j = useState(methodHTTP), method = _j[0], setMethod = _j[1]; | ||
var success = useBoolean(false); | ||
@@ -612,0 +632,0 @@ var queries = useObject(query || {}); |
@@ -129,3 +129,3 @@ 'use strict'; | ||
function useIndex(_a) { | ||
var _b = _a.value, value = _b === void 0 ? 0 : _b, _c = _a.min, min = _c === void 0 ? 0 : _c, _d = _a.max, max = _d === void 0 ? 9 : _d, _e = _a.reverse, reverse = _e === void 0 ? true : _e, _f = _a.step, step = _f === void 0 ? 1 : _f, _g = _a.format, format = _g === void 0 ? null : _g; | ||
var _b = _a.value, value = _b === void 0 ? 0 : _b, _c = _a.min, min = _c === void 0 ? 0 : _c, _d = _a.max, max = _d === void 0 ? 9 : _d, _e = _a.reverse, reverse = _e === void 0 ? true : _e, _f = _a.step, step = _f === void 0 ? 1 : _f, format = _a.format; | ||
var setup = useObject({ | ||
@@ -181,66 +181,2 @@ value: value, | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
/** | ||
@@ -272,10 +208,11 @@ * @description create a toggle object handler | ||
var state = {}; | ||
var dollarSign = {}; | ||
Object.keys(data).map(function (dataKey) { | ||
state[dataKey] = useBoolean(!!data[dataKey]); | ||
dollarSign["$" + dataKey] = state[dataKey]; | ||
}); | ||
return react.useMemo(function () { return (__assign({ state: state, toggle: function (key) { | ||
return react.useMemo(function () { return ({ | ||
state: state, | ||
toggle: function (key) { | ||
return state.hasOwnProperty(key) && state[key].toggle(); | ||
}, set: function (key, value) { | ||
}, | ||
set: function (key, value) { | ||
if (state.hasOwnProperty(key)) { | ||
@@ -287,23 +224,32 @@ state[key].set(value); | ||
} | ||
}, check: function (key) { return !!state[key].state; }, highlight: function (key) { | ||
}, | ||
check: function (key) { return !!state[key] && !!state[key].state; }, | ||
highlight: function (key) { | ||
for (var option in state) { | ||
state[option].set(key === option); | ||
} | ||
}, shadow: function (key) { | ||
}, | ||
shadow: function (key) { | ||
for (var option in state) { | ||
state[option].set(key !== option); | ||
} | ||
}, reset: function (value) { | ||
}, | ||
reset: function (value) { | ||
for (var option in state) { | ||
state[option].set(!!value); | ||
} | ||
}, enabled: function () { | ||
}, | ||
enabled: function () { | ||
return Object.keys(state).filter(function (key) { return state[key].isOn(); }); | ||
}, disabled: function () { | ||
}, | ||
disabled: function () { | ||
return Object.keys(state).filter(function (key) { return state[key].isOff(); }); | ||
}, keys: function () { return Object.keys(state); }, each: function (callback) { | ||
}, | ||
keys: function () { return Object.keys(state); }, | ||
each: function (callback) { | ||
return Object.keys(state).map(function (key, index) { | ||
return callback({ key: key, index: index, value: state[key] }); | ||
}); | ||
}, isAll: function (value, except) { | ||
}, | ||
isAll: function (value, except) { | ||
var checker = true; | ||
@@ -322,16 +268,83 @@ for (var option in state) { | ||
return checker; | ||
} }, dollarSign)); }, [state]); | ||
}, | ||
}); }, [state]); | ||
} | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function __generator(thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
} | ||
function getSize(screenSize, config, margin) { | ||
if (margin === void 0) { margin = [1, 1]; } | ||
if (typeof window === 'undefined') { | ||
return config; | ||
return __assign(__assign({}, config), { aspect: [0, 0] }); | ||
} | ||
var innerWidth = window.innerWidth, innerHeight = window.innerHeight, outerWidth = window.outerWidth, outerHeight = window.outerHeight; | ||
var aspect = [margin[0] || 1, margin[1] || 1]; | ||
innerWidth *= aspect[0] || 1; | ||
innerHeight *= aspect[1] || 1; | ||
var orientation = innerWidth > innerHeight ? 'landscape' : 'portrait'; | ||
var percentualRatio = innerHeight / innerWidth; | ||
var vw = Math.max(document.documentElement.clientWidth || 0, innerWidth || 0); | ||
var vh = Math.max(document.documentElement.clientHeight || 0, innerHeight || 0); | ||
vw *= aspect[0] || 1; | ||
vh *= aspect[1] || 1; | ||
var orientation = vw > vh ? 'landscape' : 'portrait'; | ||
var percentualRatio = vh / vw; | ||
var ratio = +parseFloat(percentualRatio.toString()).toFixed(2); | ||
@@ -352,19 +365,22 @@ var difference = 0; | ||
orientation: orientation, | ||
previous: screenSize, | ||
aspect: aspect, | ||
}; | ||
} | ||
function useScreenSize(config, margin) { | ||
if (config === void 0) { config = { | ||
innerWidth: 1360, | ||
innerHeight: 640, | ||
outerWidth: 1360, | ||
outerHeight: 640, | ||
ratio: 0.47, | ||
orientation: 'landscape', | ||
difference: 1, | ||
}; } | ||
if (margin === void 0) { margin = [1, 1]; } | ||
var _a = react.useState(getSize(__assign({}, config), config, margin)), screenSize = _a[0], setScreenSize = _a[1]; | ||
var handleResize = react.useCallback(function () { return setScreenSize(getSize(screenSize, config, margin)); }, []); | ||
/** | ||
* @description get the window size | ||
*/ | ||
var SCREEN_SIZE_DEFAULT_CONFIG = { | ||
innerWidth: 1360, | ||
innerHeight: 640, | ||
outerWidth: 1360, | ||
outerHeight: 640, | ||
ratio: 0.47, | ||
orientation: 'landscape', | ||
difference: 1, | ||
}; | ||
function useScreenSize(margin, config) { | ||
var _a = react.useState(getSize(!!config ? __assign({}, config) : SCREEN_SIZE_DEFAULT_CONFIG, config || SCREEN_SIZE_DEFAULT_CONFIG, margin || [1, 1])), screenSize = _a[0], setScreenSize = _a[1]; | ||
var handleResize = react.useCallback(function () { | ||
return setScreenSize(getSize(screenSize, config || SCREEN_SIZE_DEFAULT_CONFIG, margin)); | ||
}, []); | ||
react.useEffect(function () { | ||
@@ -386,8 +402,12 @@ window.addEventListener('resize', function () { | ||
outerWidth: screenSize.outerWidth, | ||
fullHD: function () { | ||
isFullHD: function () { | ||
return screenSize.innerWidth >= 1920 && screenSize.innerHeight >= 1080; | ||
}, | ||
hd: function () { | ||
isHD: function () { | ||
return screenSize.innerWidth >= 1360 && screenSize.innerHeight >= 724; | ||
}, | ||
isTablet: function () { | ||
return screenSize.innerWidth >= 768 && screenSize.innerWidth <= 1360; | ||
}, | ||
isMobile: function () { return screenSize.innerWidth < 768; }, | ||
}); }, [screenSize]); | ||
@@ -461,3 +481,3 @@ } | ||
if (!inClient) | ||
return null; | ||
return false; | ||
var _a = react.useState(false), pressed = _a[0], setPressed = _a[1]; | ||
@@ -471,3 +491,3 @@ var isMatching = react.useCallback(function (event) { | ||
if (typeof callback === 'function') { | ||
callback(); | ||
callback(event); | ||
} | ||
@@ -605,11 +625,11 @@ } | ||
var _this = this; | ||
var endpoint = _a.endpoint, body = _a.body, _b = _a.config, config = _b === void 0 ? {} : _b, token = _a.token, onSuccess = _a.onSuccess, onError = _a.onError, onData = _a.onData, _c = _a.start, start = _c === void 0 ? true : _c, _d = _a.stateInit, stateInit = _d === void 0 ? [] : _d, query = _a.query, _e = _a.format, format = _e === void 0 ? null : _e, _f = _a.generalOptions, generalOptions = _f === void 0 ? {} : _f; | ||
var endpoint = _a.endpoint, body = _a.body, _b = _a.config, config = _b === void 0 ? {} : _b, token = _a.token, onSuccess = _a.onSuccess, onError = _a.onError, onData = _a.onData, _c = _a.start, start = _c === void 0 ? true : _c, _d = _a.stateInit, stateInit = _d === void 0 ? [] : _d, query = _a.query, format = _a.format, _e = _a.generalOptions, generalOptions = _e === void 0 ? {} : _e; | ||
if (methodHTTP === void 0) { methodHTTP = 'GET'; } | ||
var _g = react.useState(stateInit), data = _g[0], setData = _g[1]; | ||
var _f = react.useState(stateInit), data = _f[0], setData = _f[1]; | ||
var loading = useBoolean(start); | ||
var _h = react.useState(null), error = _h[0], setError = _h[1]; | ||
var _g = react.useState(null), error = _g[0], setError = _g[1]; | ||
var refresh = useBoolean(start); | ||
var setup = useObject(body || {}); | ||
var _j = react.useState(endpoint), uri = _j[0], setUri = _j[1]; | ||
var _k = react.useState(methodHTTP), method = _k[0], setMethod = _k[1]; | ||
var _h = react.useState(endpoint), uri = _h[0], setUri = _h[1]; | ||
var _j = react.useState(methodHTTP), method = _j[0], setMethod = _j[1]; | ||
var success = useBoolean(false); | ||
@@ -616,0 +636,0 @@ var queries = useObject(query || {}); |
@@ -1,15 +0,6 @@ | ||
export interface HooksBoolean { | ||
state: Boolean; | ||
set: Function; | ||
on: Function; | ||
off: Function; | ||
isOn: Function; | ||
isOff: Function; | ||
toggle: Function; | ||
hex: Function; | ||
} | ||
import { THooksBoolean } from '../@types/index'; | ||
/** | ||
* @description This is a complete hook to handle with Boolean values. | ||
*/ | ||
declare const useBoolean: (initialValue: Boolean) => HooksBoolean; | ||
declare const useBoolean: (initialValue: boolean) => THooksBoolean; | ||
export default useBoolean; |
@@ -1,5 +0,2 @@ | ||
export interface HooksClient { | ||
inClient: Boolean; | ||
inServer: Boolean; | ||
} | ||
import { THooksClient } from '../@types/index'; | ||
/** | ||
@@ -13,2 +10,2 @@ * @description Check out if he website is on 'server-side' or 'client-side' | ||
*/ | ||
export default function useClient(onChange?: Function): HooksClient; | ||
export default function useClient(onChange?: Function): THooksClient; |
/** | ||
* @description delays invoking a function until after wait milliseconds have elapsed since the last time | ||
*/ | ||
export default function useDebounce(callback: Function, timeout: number): Function; | ||
export default function useDebounce(callback: () => any, timeout: number): Function; |
@@ -1,38 +0,5 @@ | ||
import { HooksBoolean } from '../useBoolean'; | ||
import { HooksObject } from '../useObject'; | ||
export interface HooksFetchInit { | ||
endpoint: string; | ||
body?: object; | ||
config?: object; | ||
token?: string; | ||
onSuccess?: Function; | ||
onError?: Function; | ||
onData?: Function; | ||
start: Boolean; | ||
stateInit?: any; | ||
query?: object | null; | ||
format?: Function | null; | ||
generalOptions?: object; | ||
} | ||
export interface HeaderConfig { | ||
key: string; | ||
value: any; | ||
} | ||
export interface HooksFetch { | ||
data: any; | ||
loading: HooksBoolean; | ||
error: any; | ||
refresh: HooksBoolean; | ||
setup: HooksObject; | ||
setUri: Function; | ||
uri: string; | ||
method: string; | ||
setMethod: Function; | ||
success: HooksBoolean; | ||
queries: HooksObject; | ||
header: HooksObject; | ||
} | ||
import { THooksFetchInit, THooksFetch } from '../@types/index'; | ||
/** | ||
* @description fetch API's Rest easily | ||
*/ | ||
export default function useFetch({ endpoint, body, config, token, onSuccess, onError, onData, start, stateInit, query, format, generalOptions, }: HooksFetchInit, methodHTTP: string | undefined, fetch: any): HooksFetch; | ||
export default function useFetch({ endpoint, body, config, token, onSuccess, onError, onData, start, stateInit, query, format, generalOptions, }: THooksFetchInit, methodHTTP: "GET" | "POST" | "PUT" | "DELETE" | undefined, fetch: any): THooksFetch; |
@@ -1,23 +0,2 @@ | ||
export interface HooksIndex { | ||
setup: any; | ||
current: number; | ||
next: Function; | ||
pred: Function; | ||
set: Function; | ||
is: Function; | ||
not: Function; | ||
between: Function; | ||
among: Function; | ||
start: Function; | ||
end: Function; | ||
list: Function; | ||
} | ||
export interface IuseIndex { | ||
value: number; | ||
min: number; | ||
max: number; | ||
reverse?: boolean; | ||
step?: number; | ||
format?: Function | null; | ||
} | ||
import { THooksIndex, TIuseIndex } from '../@types/index'; | ||
/** | ||
@@ -35,2 +14,2 @@ * @function useIndex | ||
*/ | ||
export default function useIndex({ value, min, max, reverse, step, format, }: IuseIndex): HooksIndex; | ||
export default function useIndex({ value, min, max, reverse, step, format, }: TIuseIndex): THooksIndex; |
@@ -1,1 +0,1 @@ | ||
export default function useKeyboard(key: string, callback: Function): boolean | null; | ||
export default function useKeyboard(key: string, callback: (event: KeyboardEvent) => void): boolean; |
@@ -1,9 +0,9 @@ | ||
export interface HooksLocalStorage { | ||
get: Function; | ||
set: Function; | ||
state: any; | ||
} | ||
import { THooksLocalStorage } from './../@types/index'; | ||
/** | ||
* @description save up things upon local storage | ||
*/ | ||
export default function useLocalStorage(key: string, value: any): HooksLocalStorage; | ||
export default function useLocalStorage(key: string, value: Record<any, any>): THooksLocalStorage | { | ||
get: () => null; | ||
set: () => boolean; | ||
state: null; | ||
}; |
@@ -1,5 +0,2 @@ | ||
export interface HooksMiddleMouse { | ||
direction: number; | ||
setDirection: Function; | ||
} | ||
import { THooksMiddleMouse } from './../@types/index'; | ||
/** | ||
@@ -16,2 +13,2 @@ * @function useMiddleMouse | ||
*/ | ||
export default function useMiddleMouse(threshould: number): HooksMiddleMouse | undefined; | ||
export default function useMiddleMouse(threshould: number): THooksMiddleMouse | undefined; |
@@ -0,1 +1,2 @@ | ||
/// <reference types="react" /> | ||
/** | ||
@@ -13,2 +14,2 @@ * @function useMouseIn | ||
*/ | ||
export default function useMouseIn(ref: any, callback: Function): void; | ||
export default function useMouseIn(ref: React.MutableRefObject<any>, callback: (isIn: boolean) => void): void; |
@@ -1,17 +0,2 @@ | ||
export interface HooksObject { | ||
state: any; | ||
setState: Function; | ||
set: Function; | ||
handle: Function; | ||
stateAssign: Function; | ||
objectAssign: Function; | ||
isValid: Function; | ||
empty: Function; | ||
has: Function; | ||
typeof: Function; | ||
keys: Function; | ||
length: Function; | ||
each: Function; | ||
remove: Function; | ||
} | ||
import { THooksObject } from '../@types/index'; | ||
/** | ||
@@ -22,3 +7,3 @@ * @description A better way to handle with Objects | ||
*/ | ||
declare const useObject: (data: object, assign?: object | undefined) => HooksObject; | ||
declare const useObject: (data: object, assign?: object | undefined) => THooksObject; | ||
export default useObject; |
@@ -1,24 +0,6 @@ | ||
export interface Parameter_Screensize { | ||
innerWidth: number; | ||
innerHeight: number; | ||
outerWidth: number; | ||
outerHeight: number; | ||
ratio: number; | ||
orientation: string | 'landscape' | 'portrait'; | ||
difference: number; | ||
} | ||
import { IParameter_Screensize, THooksScreenSize } from './../@types/index'; | ||
/** | ||
* @description get the window size | ||
*/ | ||
export interface HooksScreenSize { | ||
innerWidth: number; | ||
innerHeight: number; | ||
outerWidth: number; | ||
outerHeight: number; | ||
ratio: number; | ||
orientation: string | 'landscape' | 'portrait'; | ||
difference: number; | ||
fullHD: Function; | ||
hd: Function; | ||
} | ||
export default function useScreenSize(config?: Parameter_Screensize, margin?: Array<number>): HooksScreenSize; | ||
export declare const SCREEN_SIZE_DEFAULT_CONFIG: IParameter_Screensize; | ||
export default function useScreenSize(margin?: number[], config?: IParameter_Screensize): THooksScreenSize; |
@@ -1,14 +0,2 @@ | ||
export interface HooksScroll { | ||
toTop: Function; | ||
x: Number; | ||
y: Number; | ||
isRight: Boolean; | ||
isLeft: Boolean; | ||
isTop: Boolean; | ||
isBottom: Boolean; | ||
bottom: Number; | ||
right: Number; | ||
offsetX: Number; | ||
offsetY: Number; | ||
} | ||
import { THooksScroll } from './../@types/index'; | ||
/** | ||
@@ -21,2 +9,2 @@ * @description provides a way to check the state of the | ||
*/ | ||
export default function useScroll(): HooksScroll; | ||
export default function useScroll(): THooksScroll; |
@@ -1,15 +0,2 @@ | ||
export interface HooksToggle { | ||
state: any; | ||
toggle: Function; | ||
set: Function; | ||
check: Function; | ||
highlight: Function; | ||
shadow: Function; | ||
reset: Function; | ||
enabled: Function; | ||
disabled: Function; | ||
keys: Function; | ||
each: Function; | ||
isAll: Function; | ||
} | ||
import { THooksToggle } from '../@types/index'; | ||
/** | ||
@@ -39,2 +26,2 @@ * @description create a toggle object handler | ||
*/ | ||
export default function useToggle(data: object): HooksToggle; | ||
export default function useToggle(data: Record<any, any>): THooksToggle; |
{ | ||
"name": "@vorlefan/react-hooks", | ||
"version": "1.2.7", | ||
"version": "1.3.0", | ||
"description": "Useful react hooks for React &amp; Next.js app", | ||
@@ -11,6 +11,2 @@ "author": "DaxSoft", | ||
"jsnext:main": "dist/index.es.js", | ||
"engines": { | ||
"node": ">=8", | ||
"npm": ">=5" | ||
}, | ||
"scripts": { | ||
@@ -27,25 +23,25 @@ "test": "cross-env CI=1 react-scripts test --env=jsdom", | ||
"peerDependencies": { | ||
"react": "^16.9.0" | ||
"react": "^17.0.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.2.2", | ||
"@babel/runtime": "^7.3.1", | ||
"@testing-library/react-hooks": "^3.2.1", | ||
"@types/jest": "^23.3.13", | ||
"@types/react": "^16.7.22", | ||
"@babel/core": "^7.12.10", | ||
"@babel/runtime": "^7.12.5", | ||
"@testing-library/react-hooks": "^3.7.0", | ||
"@types/jest": "^26.0.19", | ||
"@types/react": "^17.0.0", | ||
"bundlesize": "^0.18.0", | ||
"cross-env": "^5.2.0", | ||
"gh-pages": "^2.0.1", | ||
"react": "^16.9.0", | ||
"react-scripts": "^3.4.0", | ||
"react-test-renderer": "^16.9.0", | ||
"rollup": "^1.1.2", | ||
"cross-env": "^7.0.3", | ||
"gh-pages": "^3.1.0", | ||
"react": "^17.0.1", | ||
"react-scripts": "^4.0.1", | ||
"react-test-renderer": "^17.0.1", | ||
"rollup": "^2.35.1", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"rollup-plugin-peer-deps-external": "^2.2.0", | ||
"rollup-plugin-typescript2": "^0.19.2", | ||
"rollup-plugin-peer-deps-external": "^2.2.4", | ||
"rollup-plugin-typescript2": "^0.29.0", | ||
"rollup-plugin-url": "^2.1.0", | ||
"typescript": "^3.2.4" | ||
"typescript": "^4.1.3" | ||
} | ||
} |
{ | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"module": "esnext", | ||
"target": "es5", | ||
"lib": [ | ||
"es6", | ||
"dom", | ||
"es2016", | ||
"es2017" | ||
], | ||
"sourceMap": true, | ||
"allowJs": false, | ||
"jsx": "preserve", | ||
"declaration": true, | ||
"moduleResolution": "node", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"build", | ||
"dist", | ||
"example", | ||
"rollup.config.js" | ||
] | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"module": "esnext", | ||
"target": "es5", | ||
"lib": ["es6", "dom", "es2016", "es2017"], | ||
"sourceMap": true, | ||
"allowJs": false, | ||
"jsx": "react-jsx", | ||
"declaration": true, | ||
"moduleResolution": "node", | ||
"forceConsistentCasingInFileNames": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"removeComments": false | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", "build", "dist", "example", "rollup.config.js"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
189920
38
1774