@prezly/theme-kit-nextjs 5.0.0-alpha.9 → 5.0.0
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/infinite-loading/lib/index.d.ts +1 -0
- package/build/infinite-loading/lib/index.js +6 -0
- package/build/infinite-loading/lib/index.js.map +1 -0
- package/build/infinite-loading/lib/useAsync.d.ts +44 -0
- package/build/infinite-loading/lib/useAsync.js +70 -0
- package/build/infinite-loading/lib/useAsync.js.map +1 -0
- package/build/infinite-loading/lib/useSyncedRef.d.ts +12 -0
- package/build/infinite-loading/lib/useSyncedRef.js +24 -0
- package/build/infinite-loading/lib/useSyncedRef.js.map +1 -0
- package/build/infinite-loading/useInfiniteLoading.js +2 -2
- package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
- package/package.json +4 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useAsync } from './useAsync';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAsync = void 0;
|
|
4
|
+
var useAsync_1 = require("./useAsync");
|
|
5
|
+
Object.defineProperty(exports, "useAsync", { enumerable: true, get: function () { return useAsync_1.useAsync; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/infinite-loading/lib/index.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code is ported from `@react-hookz/web` package, to avoid importing the whole package in the client bundle.
|
|
3
|
+
* @see https://github.com/react-hookz/web/blob/master/src/useAsync/index.ts
|
|
4
|
+
*/
|
|
5
|
+
export type AsyncStatus = 'loading' | 'success' | 'error' | 'not-executed';
|
|
6
|
+
export type AsyncState<Result> = {
|
|
7
|
+
status: 'not-executed';
|
|
8
|
+
error: undefined;
|
|
9
|
+
result: Result;
|
|
10
|
+
} | {
|
|
11
|
+
status: 'success';
|
|
12
|
+
error: undefined;
|
|
13
|
+
result: Result;
|
|
14
|
+
} | {
|
|
15
|
+
status: 'error';
|
|
16
|
+
error: Error;
|
|
17
|
+
result: Result;
|
|
18
|
+
} | {
|
|
19
|
+
status: AsyncStatus;
|
|
20
|
+
error: Error | undefined;
|
|
21
|
+
result: Result;
|
|
22
|
+
};
|
|
23
|
+
export interface UseAsyncActions<Result, Args extends unknown[] = unknown[]> {
|
|
24
|
+
/**
|
|
25
|
+
* Reset state to initial.
|
|
26
|
+
*/
|
|
27
|
+
reset: () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Execute the async function manually.
|
|
30
|
+
*/
|
|
31
|
+
execute: (...args: Args) => Promise<Result>;
|
|
32
|
+
}
|
|
33
|
+
export interface UseAsyncMeta<Result, Args extends unknown[] = unknown[]> {
|
|
34
|
+
/**
|
|
35
|
+
* Latest promise returned from the async function.
|
|
36
|
+
*/
|
|
37
|
+
promise: Promise<Result> | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* List of arguments applied to the latest async function invocation.
|
|
40
|
+
*/
|
|
41
|
+
lastArgs: Args | undefined;
|
|
42
|
+
}
|
|
43
|
+
export declare function useAsync<Result, Args extends unknown[] = unknown[]>(asyncFn: (...params: Args) => Promise<Result>, initialValue: Result): [AsyncState<Result>, UseAsyncActions<Result, Args>, UseAsyncMeta<Result, Args>];
|
|
44
|
+
export declare function useAsync<Result, Args extends unknown[] = unknown[]>(asyncFn: (...params: Args) => Promise<Result>, initialValue?: Result): [AsyncState<Result | undefined>, UseAsyncActions<Result, Args>, UseAsyncMeta<Result, Args>];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This code is ported from `@react-hookz/web` package, to avoid importing the whole package in the client bundle.
|
|
4
|
+
* @see https://github.com/react-hookz/web/blob/master/src/useAsync/index.ts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useAsync = void 0;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const useSyncedRef_1 = require("./useSyncedRef");
|
|
10
|
+
/**
|
|
11
|
+
* Tracks the result and errors of the provided async function and provides handles to control its execution.
|
|
12
|
+
*
|
|
13
|
+
* @param asyncFn Function that returns a promise.
|
|
14
|
+
* @param initialValue Value that will be set on initialisation before the async function is
|
|
15
|
+
* executed.
|
|
16
|
+
*/
|
|
17
|
+
function useAsync(asyncFn, initialValue) {
|
|
18
|
+
const [state, setState] = (0, react_1.useState)({
|
|
19
|
+
status: 'not-executed',
|
|
20
|
+
error: undefined,
|
|
21
|
+
result: initialValue,
|
|
22
|
+
});
|
|
23
|
+
const promiseRef = (0, react_1.useRef)();
|
|
24
|
+
const argsRef = (0, react_1.useRef)();
|
|
25
|
+
const methods = (0, useSyncedRef_1.useSyncedRef)({
|
|
26
|
+
execute: (...params) => {
|
|
27
|
+
argsRef.current = params;
|
|
28
|
+
const promise = asyncFn(...params);
|
|
29
|
+
promiseRef.current = promise;
|
|
30
|
+
setState((s) => ({ ...s, status: 'loading' }));
|
|
31
|
+
promise.then((result) => {
|
|
32
|
+
// we dont want to handle result/error of non-latest function
|
|
33
|
+
// this approach helps to avoid race conditions
|
|
34
|
+
if (promise === promiseRef.current) {
|
|
35
|
+
setState((s) => ({ ...s, status: 'success', error: undefined, result }));
|
|
36
|
+
}
|
|
37
|
+
}, (error) => {
|
|
38
|
+
// we dont want to handle result/error of non-latest function
|
|
39
|
+
// this approach helps to avoid race conditions
|
|
40
|
+
if (promise === promiseRef.current) {
|
|
41
|
+
setState((s) => ({ ...s, status: 'error', error }));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return promise;
|
|
45
|
+
},
|
|
46
|
+
reset: () => {
|
|
47
|
+
setState({
|
|
48
|
+
status: 'not-executed',
|
|
49
|
+
error: undefined,
|
|
50
|
+
result: initialValue,
|
|
51
|
+
});
|
|
52
|
+
promiseRef.current = undefined;
|
|
53
|
+
argsRef.current = undefined;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return [
|
|
57
|
+
state,
|
|
58
|
+
(0, react_1.useMemo)(() => ({
|
|
59
|
+
reset: () => {
|
|
60
|
+
methods.current.reset();
|
|
61
|
+
},
|
|
62
|
+
execute: (...params) => methods.current.execute(...params),
|
|
63
|
+
}),
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
[]),
|
|
66
|
+
{ promise: promiseRef.current, lastArgs: argsRef.current },
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
exports.useAsync = useAsync;
|
|
70
|
+
//# sourceMappingURL=useAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsync.js","sourceRoot":"","sources":["../../../src/infinite-loading/lib/useAsync.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iCAAkD;AAElD,iDAA8C;AAyD9C;;;;;;GAMG;AACH,SAAgB,QAAQ,CACpB,OAA6C,EAC7C,YAAqB;IAErB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAiC;QAC/D,MAAM,EAAE,cAAc;QACtB,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,YAAY;KACvB,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,IAAA,cAAM,GAAmB,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAA,cAAM,GAAQ,CAAC;IAE/B,MAAM,OAAO,GAAG,IAAA,2BAAY,EAAC;QACzB,OAAO,EAAE,CAAC,GAAG,MAAY,EAAE,EAAE;YACzB,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;YACzB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC;YACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;YAE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C,OAAO,CAAC,GAAG,MAAM,CAAC;SACnE,CAAC;QACF,uDAAuD;QACvD,EAAE,CACL;QACD,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE;KAC7D,CAAC;AACN,CAAC;AAhED,4BAgEC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code is ported from `@react-hookz/web` package, to avoid importing the whole package in the client bundle.
|
|
3
|
+
* @see https://github.com/react-hookz/web/blob/master/src/useSyncedRef/index.ts
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Like `useRef`, but it returns immutable ref that contains actual value.
|
|
7
|
+
*
|
|
8
|
+
* @param value
|
|
9
|
+
*/
|
|
10
|
+
export declare function useSyncedRef<T>(value: T): {
|
|
11
|
+
readonly current: T;
|
|
12
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This code is ported from `@react-hookz/web` package, to avoid importing the whole package in the client bundle.
|
|
4
|
+
* @see https://github.com/react-hookz/web/blob/master/src/useSyncedRef/index.ts
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useSyncedRef = void 0;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
/**
|
|
10
|
+
* Like `useRef`, but it returns immutable ref that contains actual value.
|
|
11
|
+
*
|
|
12
|
+
* @param value
|
|
13
|
+
*/
|
|
14
|
+
function useSyncedRef(value) {
|
|
15
|
+
const ref = (0, react_1.useRef)(value);
|
|
16
|
+
ref.current = value;
|
|
17
|
+
return (0, react_1.useMemo)(() => Object.freeze({
|
|
18
|
+
get current() {
|
|
19
|
+
return ref.current;
|
|
20
|
+
},
|
|
21
|
+
}), []);
|
|
22
|
+
}
|
|
23
|
+
exports.useSyncedRef = useSyncedRef;
|
|
24
|
+
//# sourceMappingURL=useSyncedRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSyncedRef.js","sourceRoot":"","sources":["../../../src/infinite-loading/lib/useSyncedRef.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iCAAwC;AAExC;;;;GAIG;AACH,SAAgB,YAAY,CAAI,KAAQ;IACpC,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAC;IAE1B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,IAAA,eAAO,EACV,GAAG,EAAE,CACD,MAAM,CAAC,MAAM,CAAC;QACV,IAAI,OAAO;YACP,OAAO,GAAG,CAAC,OAAO,CAAC;QACvB,CAAC;KACJ,CAAC,EACN,EAAE,CACL,CAAC;AACN,CAAC;AAdD,oCAcC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useInfiniteLoading = void 0;
|
|
4
|
-
const useAsync_1 = require("@react-hookz/web/esm/useAsync/useAsync");
|
|
5
4
|
const react_1 = require("react");
|
|
5
|
+
const lib_1 = require("./lib");
|
|
6
6
|
function useInfiniteLoading({ fetchingFn, initialData, pagination, }) {
|
|
7
7
|
const [data, setData] = (0, react_1.useState)(initialData);
|
|
8
8
|
const [currentPage, setCurrentPage] = (0, react_1.useState)(pagination.currentPage);
|
|
@@ -10,7 +10,7 @@ function useInfiniteLoading({ fetchingFn, initialData, pagination, }) {
|
|
|
10
10
|
const adjustedItemsTotal = withHighlightedStory ? itemsTotal - 1 : itemsTotal;
|
|
11
11
|
const pagesTotal = Math.ceil(adjustedItemsTotal / pageSize);
|
|
12
12
|
const canLoadMore = currentPage < pagesTotal;
|
|
13
|
-
const [{ error, status }, { execute: loadMoreFn }] = (0,
|
|
13
|
+
const [{ error, status }, { execute: loadMoreFn }] = (0, lib_1.useAsync)(async () => {
|
|
14
14
|
const nextPage = currentPage + 1;
|
|
15
15
|
const newData = await fetchingFn(nextPage, pageSize);
|
|
16
16
|
setCurrentPage(nextPage);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteLoading.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useInfiniteLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteLoading.ts"],"names":[],"mappings":";;;AAAA,iCAAyD;AAEzD,+BAAiC;AAkBjC,SAAgB,kBAAkB,CAAI,EAClC,UAAU,EACV,WAAW,EACX,UAAU,GACE;IACZ,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAM,WAAW,CAAC,CAAC;IACnD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAEvE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,UAAU,CAAC;IAClE,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAC9E,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAC,CAAC;IAC5D,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;IAE7C,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,GAAG,IAAA,cAAQ,EAAC,KAAK,IAAI,EAAE;QACrE,MAAM,QAAQ,GAAG,WAAW,GAAG,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACrD,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzB,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC9B,IAAI,WAAW,EAAE;YACb,UAAU,EAAE,CAAC;SAChB;IACL,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;IAE9B,MAAM,SAAS,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC/B,OAAO,CAAC,WAAW,CAAC,CAAC;QACrB,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,KAAK,EAAE;YACP,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACxB;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO;QACH,WAAW;QACX,WAAW;QACX,IAAI;QACJ,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,QAAQ;QACR,SAAS;KACZ,CAAC;AACN,CAAC;AA9CD,gDA8CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prezly/theme-kit-nextjs",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Data layer and utility library for developing Prezly themes with NextJS",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -52,22 +52,21 @@
|
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@prezly/sdk": ">=12 <16",
|
|
55
|
-
"@prezly/theme-kit-core": "
|
|
55
|
+
"@prezly/theme-kit-core": "5.0.0-alpha.9 || ^5.x",
|
|
56
56
|
"next": "^12.x || ^13.x",
|
|
57
57
|
"react": "^17.x || ^18.x",
|
|
58
58
|
"react-dom": "^17.x || ^18.x"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@react-hookz/web": "^16.0.0",
|
|
62
61
|
"next-seo": "^5.4.0"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"@prezly/theme-kit-core": "^5.0.0
|
|
64
|
+
"@prezly/theme-kit-core": "^5.0.0",
|
|
66
65
|
"@sentry/nextjs": "7.50.0"
|
|
67
66
|
},
|
|
68
67
|
"publishConfig": {
|
|
69
68
|
"access": "public"
|
|
70
69
|
},
|
|
71
70
|
"sideEffects": false,
|
|
72
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "b8baed6a156ff27a041c4e095825a6c31165cf90"
|
|
73
72
|
}
|