@ttoss/react-hooks 1.25.15 → 2.0.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/package.json +7 -7
- package/dist/index.d.mts +0 -14
- package/dist/index.js +0 -111
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-hooks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "React hooks.",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"url": "https://github.com/ttoss/ttoss.git",
|
|
12
12
|
"directory": "packages/react-hooks"
|
|
13
13
|
},
|
|
14
|
+
"type": "module",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": "./dist/esm/index.js",
|
|
17
|
-
"require": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"react": ">=16.8.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/react": "^18.3.
|
|
29
|
+
"@types/react": "^18.3.7",
|
|
30
30
|
"jest": "^29.7.0",
|
|
31
31
|
"react": "^18.3.1",
|
|
32
|
-
"tsup": "^8.
|
|
33
|
-
"@ttoss/
|
|
34
|
-
"@ttoss/
|
|
32
|
+
"tsup": "^8.3.0",
|
|
33
|
+
"@ttoss/test-utils": "^2.1.14",
|
|
34
|
+
"@ttoss/config": "^1.32.10"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"React",
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsup",
|
|
46
|
-
"test": "jest"
|
|
46
|
+
"test": "jest --projects tests/unit"
|
|
47
47
|
}
|
|
48
48
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type ScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
2
|
-
/**
|
|
3
|
-
* https://usehooks.com/useScript/
|
|
4
|
-
*
|
|
5
|
-
* @param src: string - the url of the script to load.
|
|
6
|
-
* @returns status: Status
|
|
7
|
-
*/
|
|
8
|
-
declare const useScript: (src: string) => {
|
|
9
|
-
status: ScriptStatus;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare const useDebounce: <T>(value: T, delay?: number) => T;
|
|
13
|
-
|
|
14
|
-
export { type ScriptStatus, useDebounce, useScript };
|
package/dist/index.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __export = (target, all) => {
|
|
11
|
-
for (var name in all) __defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
-
get: () => from[key],
|
|
20
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
31
|
-
value: mod,
|
|
32
|
-
enumerable: true
|
|
33
|
-
}) : target, mod));
|
|
34
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
35
|
-
value: true
|
|
36
|
-
}), mod);
|
|
37
|
-
|
|
38
|
-
// src/index.ts
|
|
39
|
-
var src_exports = {};
|
|
40
|
-
__export(src_exports, {
|
|
41
|
-
useDebounce: () => useDebounce,
|
|
42
|
-
useScript: () => useScript
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(src_exports);
|
|
45
|
-
|
|
46
|
-
// src/useScript.ts
|
|
47
|
-
var React = __toESM(require("react"));
|
|
48
|
-
var useScript = src => {
|
|
49
|
-
const [status, setStatus] = React.useState(src ? "loading" : "idle");
|
|
50
|
-
React.useEffect(() => {
|
|
51
|
-
if (!src) {
|
|
52
|
-
setStatus("idle");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
let script = document.querySelector(`script[src="${src}"]`);
|
|
56
|
-
if (!script) {
|
|
57
|
-
script = document.createElement("script");
|
|
58
|
-
script.src = src;
|
|
59
|
-
script.async = true;
|
|
60
|
-
script.setAttribute("data-status", "loading");
|
|
61
|
-
document.body.appendChild(script);
|
|
62
|
-
const setAttributeFromEvent = event => {
|
|
63
|
-
if (script) {
|
|
64
|
-
script.setAttribute("data-status", event.type === "load" ? "ready" : "error");
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
script.addEventListener("load", setAttributeFromEvent);
|
|
68
|
-
script.addEventListener("error", setAttributeFromEvent);
|
|
69
|
-
} else {
|
|
70
|
-
setStatus(script.getAttribute("data-status") || "error");
|
|
71
|
-
}
|
|
72
|
-
const setStateFromEvent = event => {
|
|
73
|
-
setStatus(event.type === "load" ? "ready" : "error");
|
|
74
|
-
};
|
|
75
|
-
script.addEventListener("load", setStateFromEvent);
|
|
76
|
-
script.addEventListener("error", setStateFromEvent);
|
|
77
|
-
return () => {
|
|
78
|
-
if (script) {
|
|
79
|
-
script.removeEventListener("load", setStateFromEvent);
|
|
80
|
-
script.removeEventListener("error", setStateFromEvent);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
/**
|
|
85
|
-
* Only re-run effect if script src changes.
|
|
86
|
-
*/
|
|
87
|
-
[src]);
|
|
88
|
-
return {
|
|
89
|
-
status
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// src/useDebounce.ts
|
|
94
|
-
var React2 = __toESM(require("react"));
|
|
95
|
-
var useDebounce = (value, delay) => {
|
|
96
|
-
const [debouncedValue, setDebouncedValue] = React2.useState(value);
|
|
97
|
-
React2.useEffect(() => {
|
|
98
|
-
const timer = setTimeout(() => {
|
|
99
|
-
return setDebouncedValue(value);
|
|
100
|
-
}, delay || 500);
|
|
101
|
-
return () => {
|
|
102
|
-
clearTimeout(timer);
|
|
103
|
-
};
|
|
104
|
-
}, [value, delay]);
|
|
105
|
-
return debouncedValue;
|
|
106
|
-
};
|
|
107
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
-
0 && (module.exports = {
|
|
109
|
-
useDebounce,
|
|
110
|
-
useScript
|
|
111
|
-
});
|