@dr.pogodin/react-utils 1.40.13 → 1.40.14
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/build/development/shared/utils/time.js +2 -26
- package/build/development/shared/utils/time.js.map +1 -1
- package/build/development/web.bundle.js +1 -1
- package/build/production/shared/utils/time.js +2 -24
- package/build/production/shared/utils/time.js.map +1 -1
- package/build/production/style.css.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/shared/utils/time.d.ts +0 -22
- package/config/babel/node-ssr.js +17 -7
- package/package.json +20 -20
- package/src/shared/utils/time.ts +4 -28
|
@@ -7,18 +7,6 @@ import { timer } from '@dr.pogodin/js-utils';
|
|
|
7
7
|
* then stored in the global state to be reused in all other calls), which
|
|
8
8
|
* is also passed and used in the first client side render, and then updated
|
|
9
9
|
* with a finite precision to avoid infinite re-rendering loops.
|
|
10
|
-
* @param [options] Optional settings.
|
|
11
|
-
* @param [options.globalStatePath="currentTime"] Global state path
|
|
12
|
-
* to keep the current time value.
|
|
13
|
-
* @param [options.precision= 5 * time.SEC_MS] Current time precision.
|
|
14
|
-
* The hook won't update the current time stored in the global state unless it
|
|
15
|
-
* is different from Date.now() result by this number (in milliseconds).
|
|
16
|
-
* Default to 5 seconds.
|
|
17
|
-
* @param [options.autorefresh=false] Set `true` to automatically
|
|
18
|
-
* refresh time stored in the global state with the given `precision` (and
|
|
19
|
-
* thus automatically re-rendering components dependent on this hook, or
|
|
20
|
-
* the global state with the period equal to the `precision`.
|
|
21
|
-
* @return Unix timestamp in milliseconds.
|
|
22
10
|
*/
|
|
23
11
|
export declare function useCurrent({ autorefresh, globalStatePath, precision, }?: {
|
|
24
12
|
autorefresh?: boolean | undefined;
|
|
@@ -33,16 +21,6 @@ export declare function useCurrent({ autorefresh, globalStatePath, precision, }?
|
|
|
33
21
|
* via the global state. Prior to the value being known (in the very first
|
|
34
22
|
* request from the user, when the cookie is still missing), zero value is used
|
|
35
23
|
* as the default value.
|
|
36
|
-
*
|
|
37
|
-
* @param {object} [options] Optional settings.
|
|
38
|
-
* @param {string} [options.cookieName="timezoneOffset"] Optional. The name of
|
|
39
|
-
* cookie to use to store the timezone offset. Defaults "timezoneOffset". Set
|
|
40
|
-
* to a falsy value to forbid using cookies altogether (in that case the hook
|
|
41
|
-
* will always return zero value at the server-side, and in the first render
|
|
42
|
-
* at the client-side).
|
|
43
|
-
* @param {string} [options.timezoneOffset="timezoneOffset"] Optional.
|
|
44
|
-
* The global state path to store the offset. Defaults "timezoneOffset".
|
|
45
|
-
* @return {number} Timezone offset.
|
|
46
24
|
*/
|
|
47
25
|
export declare function useTimezoneOffset({ cookieName, globalStatePath, }?: {
|
|
48
26
|
cookieName?: string | undefined;
|
package/config/babel/node-ssr.js
CHANGED
|
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
26
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
37
|
exports.default = getConfig;
|
|
28
38
|
const lodash_1 = require("lodash");
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.40.
|
|
2
|
+
"version": "1.40.14",
|
|
3
3
|
"bin": {
|
|
4
4
|
"react-utils-build": "bin/build.js",
|
|
5
5
|
"react-utils-setup": "bin/setup.js"
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@babel/runtime": "^7.26.0",
|
|
12
12
|
"@dr.pogodin/babel-plugin-react-css-modules": "^6.13.2",
|
|
13
|
-
"@dr.pogodin/csurf": "^1.14.
|
|
13
|
+
"@dr.pogodin/csurf": "^1.14.1",
|
|
14
14
|
"@dr.pogodin/js-utils": "^0.0.12",
|
|
15
15
|
"@dr.pogodin/react-global-state": "^0.17.5",
|
|
16
16
|
"@dr.pogodin/react-themes": "^1.7.0",
|
|
17
17
|
"@jest/environment": "^29.7.0",
|
|
18
|
-
"axios": "^1.7.
|
|
18
|
+
"axios": "^1.7.9",
|
|
19
19
|
"commander": "^12.1.0",
|
|
20
20
|
"compression": "^1.7.5",
|
|
21
21
|
"config": "^3.3.12",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"cookie-parser": "^1.4.7",
|
|
24
24
|
"cross-env": "^7.0.3",
|
|
25
25
|
"dayjs": "^1.11.13",
|
|
26
|
-
"express": "^4.21.
|
|
26
|
+
"express": "^4.21.2",
|
|
27
27
|
"helmet": "^8.0.0",
|
|
28
28
|
"http-status-codes": "^2.3.0",
|
|
29
29
|
"joi": "^17.13.3",
|
|
@@ -46,27 +46,27 @@
|
|
|
46
46
|
},
|
|
47
47
|
"description": "Collection of generic ReactJS components and utils",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@babel/cli": "^7.
|
|
49
|
+
"@babel/cli": "^7.26.4",
|
|
50
50
|
"@babel/core": "^7.26.0",
|
|
51
51
|
"@babel/eslint-parser": "^7.25.9",
|
|
52
52
|
"@babel/eslint-plugin": "^7.25.9",
|
|
53
53
|
"@babel/node": "^7.26.0",
|
|
54
54
|
"@babel/plugin-transform-runtime": "^7.25.9",
|
|
55
55
|
"@babel/preset-env": "^7.26.0",
|
|
56
|
-
"@babel/preset-react": "^7.
|
|
56
|
+
"@babel/preset-react": "^7.26.3",
|
|
57
57
|
"@babel/preset-typescript": "^7.26.0",
|
|
58
58
|
"@babel/register": "^7.25.9",
|
|
59
59
|
"@dr.pogodin/babel-plugin-transform-assets": "^1.2.2",
|
|
60
60
|
"@dr.pogodin/babel-preset-svgr": "^1.8.0",
|
|
61
61
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
|
|
62
62
|
"@testing-library/dom": "^10.4.0",
|
|
63
|
-
"@testing-library/react": "^16.0
|
|
63
|
+
"@testing-library/react": "^16.1.0",
|
|
64
64
|
"@testing-library/user-event": "^14.5.2",
|
|
65
65
|
"@tsconfig/recommended": "^1.0.8",
|
|
66
66
|
"@types/compression": "^1.7.5",
|
|
67
67
|
"@types/config": "^3.3.5",
|
|
68
68
|
"@types/cookie": "^0.6.0",
|
|
69
|
-
"@types/cookie-parser": "^1.4.
|
|
69
|
+
"@types/cookie-parser": "^1.4.8",
|
|
70
70
|
"@types/csurf": "^1.11.5",
|
|
71
71
|
"@types/express": "^4.17.21",
|
|
72
72
|
"@types/jest": "^29.5.14",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"@types/morgan": "^1.9.9",
|
|
75
75
|
"@types/node-forge": "^1.3.11",
|
|
76
76
|
"@types/pretty": "^2.0.3",
|
|
77
|
-
"@types/react": "^18.3.
|
|
78
|
-
"@types/react-dom": "^18.3.
|
|
77
|
+
"@types/react": "^18.3.18",
|
|
78
|
+
"@types/react-dom": "^18.3.5",
|
|
79
79
|
"@types/react-helmet": "^6.1.11",
|
|
80
80
|
"@types/request-ip": "^0.0.41",
|
|
81
81
|
"@types/serialize-javascript": "^5.0.4",
|
|
@@ -94,14 +94,14 @@
|
|
|
94
94
|
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
95
95
|
"eslint-import-resolver-babel-module": "^5.3.2",
|
|
96
96
|
"eslint-plugin-import": "^2.31.0",
|
|
97
|
-
"eslint-plugin-jest": "^28.
|
|
97
|
+
"eslint-plugin-jest": "^28.10.0",
|
|
98
98
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
99
99
|
"eslint-plugin-react": "^7.37.2",
|
|
100
100
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
101
101
|
"identity-obj-proxy": "^3.0.0",
|
|
102
102
|
"jest": "^29.7.0",
|
|
103
103
|
"jest-environment-jsdom": "^29.7.0",
|
|
104
|
-
"memfs": "^4.
|
|
104
|
+
"memfs": "^4.15.0",
|
|
105
105
|
"mini-css-extract-plugin": "^2.9.2",
|
|
106
106
|
"mockdate": "^3.0.5",
|
|
107
107
|
"nodelist-foreach-polyfill": "^1.2.0",
|
|
@@ -112,19 +112,19 @@
|
|
|
112
112
|
"react-refresh": "^0.14.2",
|
|
113
113
|
"regenerator-runtime": "^0.14.1",
|
|
114
114
|
"resolve-url-loader": "^5.0.0",
|
|
115
|
-
"sass": "^1.
|
|
116
|
-
"sass-loader": "^16.0.
|
|
115
|
+
"sass": "^1.83.0",
|
|
116
|
+
"sass-loader": "^16.0.4",
|
|
117
117
|
"sitemap": "^8.0.0",
|
|
118
118
|
"source-map-loader": "^5.0.0",
|
|
119
|
-
"stylelint": "^16.
|
|
120
|
-
"stylelint-config-standard-scss": "^
|
|
119
|
+
"stylelint": "^16.12.0",
|
|
120
|
+
"stylelint-config-standard-scss": "^14.0.0",
|
|
121
121
|
"supertest": "^7.0.0",
|
|
122
122
|
"tsc-alias": "^1.8.10",
|
|
123
|
-
"tstyche": "^3.
|
|
123
|
+
"tstyche": "^3.1.1",
|
|
124
124
|
"typed-scss-modules": "^8.0.1",
|
|
125
|
-
"typescript": "^5.
|
|
126
|
-
"typescript-eslint": "^8.
|
|
127
|
-
"webpack": "^5.
|
|
125
|
+
"typescript": "^5.7.2",
|
|
126
|
+
"typescript-eslint": "^8.18.1",
|
|
127
|
+
"webpack": "^5.97.1",
|
|
128
128
|
"webpack-dev-middleware": "^7.4.2",
|
|
129
129
|
"webpack-hot-middleware": "^2.26.1",
|
|
130
130
|
"webpack-merge": "^6.0.1",
|
package/src/shared/utils/time.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import Cookie from 'cookie';
|
|
1
|
+
import { serialize } from 'cookie';
|
|
4
2
|
import dayjs from 'dayjs';
|
|
5
3
|
import { useEffect } from 'react';
|
|
6
4
|
|
|
@@ -24,18 +22,6 @@ import { getSsrContext } from './globalState';
|
|
|
24
22
|
* then stored in the global state to be reused in all other calls), which
|
|
25
23
|
* is also passed and used in the first client side render, and then updated
|
|
26
24
|
* with a finite precision to avoid infinite re-rendering loops.
|
|
27
|
-
* @param [options] Optional settings.
|
|
28
|
-
* @param [options.globalStatePath="currentTime"] Global state path
|
|
29
|
-
* to keep the current time value.
|
|
30
|
-
* @param [options.precision= 5 * time.SEC_MS] Current time precision.
|
|
31
|
-
* The hook won't update the current time stored in the global state unless it
|
|
32
|
-
* is different from Date.now() result by this number (in milliseconds).
|
|
33
|
-
* Default to 5 seconds.
|
|
34
|
-
* @param [options.autorefresh=false] Set `true` to automatically
|
|
35
|
-
* refresh time stored in the global state with the given `precision` (and
|
|
36
|
-
* thus automatically re-rendering components dependent on this hook, or
|
|
37
|
-
* the global state with the period equal to the `precision`.
|
|
38
|
-
* @return Unix timestamp in milliseconds.
|
|
39
25
|
*/
|
|
40
26
|
// TODO: Should we request the state type as generic parameter, to be able
|
|
41
27
|
// to verify the give globalStatePath is correct?
|
|
@@ -43,7 +29,7 @@ export function useCurrent({
|
|
|
43
29
|
autorefresh = false,
|
|
44
30
|
globalStatePath = 'currentTime',
|
|
45
31
|
precision = 5 * SEC_MS,
|
|
46
|
-
} = {}) {
|
|
32
|
+
} = {}): number {
|
|
47
33
|
const [now, setter] = useGlobalState<ForceT, number>(globalStatePath, Date.now);
|
|
48
34
|
useEffect(() => {
|
|
49
35
|
let timerId: NodeJS.Timeout;
|
|
@@ -70,23 +56,13 @@ export function useCurrent({
|
|
|
70
56
|
* via the global state. Prior to the value being known (in the very first
|
|
71
57
|
* request from the user, when the cookie is still missing), zero value is used
|
|
72
58
|
* as the default value.
|
|
73
|
-
*
|
|
74
|
-
* @param {object} [options] Optional settings.
|
|
75
|
-
* @param {string} [options.cookieName="timezoneOffset"] Optional. The name of
|
|
76
|
-
* cookie to use to store the timezone offset. Defaults "timezoneOffset". Set
|
|
77
|
-
* to a falsy value to forbid using cookies altogether (in that case the hook
|
|
78
|
-
* will always return zero value at the server-side, and in the first render
|
|
79
|
-
* at the client-side).
|
|
80
|
-
* @param {string} [options.timezoneOffset="timezoneOffset"] Optional.
|
|
81
|
-
* The global state path to store the offset. Defaults "timezoneOffset".
|
|
82
|
-
* @return {number} Timezone offset.
|
|
83
59
|
*/
|
|
84
60
|
// TODO: Should we request the state type as generic parameter, to be able
|
|
85
61
|
// to verify the give globalStatePath is correct?
|
|
86
62
|
export function useTimezoneOffset({
|
|
87
63
|
cookieName = 'timezoneOffset',
|
|
88
64
|
globalStatePath = 'timezoneOffset',
|
|
89
|
-
} = {}) {
|
|
65
|
+
} = {}): number {
|
|
90
66
|
const ssrContext = getSsrContext(false);
|
|
91
67
|
const [offset, setOffset] = useGlobalState<ForceT, number>(globalStatePath, () => {
|
|
92
68
|
const value = cookieName && ssrContext?.req?.cookies?.[cookieName];
|
|
@@ -97,7 +73,7 @@ export function useTimezoneOffset({
|
|
|
97
73
|
const value = date.getTimezoneOffset();
|
|
98
74
|
setOffset(value);
|
|
99
75
|
if (cookieName) {
|
|
100
|
-
document.cookie =
|
|
76
|
+
document.cookie = serialize(cookieName, value.toString(), { path: '/' });
|
|
101
77
|
}
|
|
102
78
|
}, [cookieName, setOffset]);
|
|
103
79
|
return offset;
|