@croct/plug-react 0.9.0 → 0.11.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/CroctProvider.cjs +81 -0
- package/CroctProvider.d.cts +11 -0
- package/CroctProvider.d.ts +8 -4
- package/CroctProvider.js +57 -46
- package/api.cjs +22 -0
- package/{src/react-app-env.d.ts → api.d.cts} +1 -0
- package/api.d.ts +1 -0
- package/api.js +1 -18
- package/components/Personalization/index.cjs +36 -0
- package/components/Personalization/index.d.cts +13 -0
- package/components/Personalization/index.d.ts +7 -4
- package/components/Personalization/index.js +10 -11
- package/components/Slot/index.cjs +36 -0
- package/components/Slot/index.d.cts +22 -0
- package/components/Slot/index.d.ts +9 -6
- package/components/Slot/index.js +10 -12
- package/components/index.cjs +24 -0
- package/components/index.d.cts +9 -0
- package/components/index.d.ts +9 -2
- package/components/index.js +2 -19
- package/global.d.cjs +1 -0
- package/{src/global.d.ts → global.d.d.cts} +1 -1
- package/global.d.d.ts +7 -0
- package/global.d.js +0 -0
- package/hash.cjs +36 -0
- package/hash.d.cts +2 -0
- package/hash.d.ts +2 -1
- package/hash.js +10 -11
- package/hooks/Cache.cjs +88 -0
- package/hooks/Cache.d.cts +9 -0
- package/hooks/Cache.d.ts +4 -17
- package/hooks/Cache.js +58 -56
- package/hooks/index.cjs +26 -0
- package/hooks/index.d.cts +8 -0
- package/hooks/index.d.ts +8 -3
- package/hooks/index.js +3 -20
- package/hooks/useContent.cjs +92 -0
- package/hooks/useContent.d.cts +20 -0
- package/hooks/useContent.d.ts +6 -5
- package/hooks/useContent.js +65 -42
- package/hooks/useCroct.cjs +38 -0
- package/hooks/useCroct.d.cts +5 -0
- package/hooks/useCroct.d.ts +4 -1
- package/hooks/useCroct.js +12 -12
- package/hooks/useEvaluation.cjs +85 -0
- package/hooks/useEvaluation.d.cts +14 -0
- package/hooks/useEvaluation.d.ts +5 -3
- package/hooks/useEvaluation.js +54 -45
- package/hooks/useLoader.cjs +82 -0
- package/hooks/useLoader.d.cts +7 -0
- package/hooks/useLoader.d.ts +5 -3
- package/hooks/useLoader.js +54 -59
- package/index.cjs +32 -0
- package/index.d.cts +13 -0
- package/index.d.ts +10 -3
- package/index.js +6 -23
- package/package.json +50 -19
- package/react-app-env.d.cjs +1 -0
- package/react-app-env.d.d.cts +2 -0
- package/react-app-env.d.d.ts +2 -0
- package/react-app-env.d.js +0 -0
- package/ssr-polyfills.cjs +86 -0
- package/ssr-polyfills.d.cts +2 -0
- package/ssr-polyfills.d.ts +2 -3
- package/ssr-polyfills.js +49 -64
- package/CroctProvider.js.map +0 -1
- package/api.js.map +0 -1
- package/components/Personalization/index.js.map +0 -1
- package/components/Slot/index.js.map +0 -1
- package/components/index.js.map +0 -1
- package/hash.js.map +0 -1
- package/hooks/Cache.js.map +0 -1
- package/hooks/index.js.map +0 -1
- package/hooks/useContent.js.map +0 -1
- package/hooks/useCroct.js.map +0 -1
- package/hooks/useEvaluation.js.map +0 -1
- package/hooks/useLoader.js.map +0 -1
- package/index.js.map +0 -1
- package/src/api.ts +0 -1
- package/src/components/index.ts +0 -2
- package/src/hash.test.ts +0 -22
- package/src/hash.ts +0 -12
- package/src/hooks/Cache.test.ts +0 -280
- package/src/hooks/Cache.ts +0 -97
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useContent.ssr.test.ts +0 -23
- package/src/hooks/useContent.test.ts +0 -183
- package/src/hooks/useContent.ts +0 -107
- package/src/hooks/useCroct.ts +0 -16
- package/src/hooks/useEvaluation.ssr.test.ts +0 -23
- package/src/hooks/useEvaluation.test.ts +0 -180
- package/src/hooks/useEvaluation.ts +0 -94
- package/src/hooks/useLoader.test.ts +0 -407
- package/src/hooks/useLoader.ts +0 -84
- package/src/index.ts +0 -6
- package/src/ssr-polyfills.ssr.test.ts +0 -46
- package/src/ssr-polyfills.test.ts +0 -65
- package/src/ssr-polyfills.ts +0 -70
- package/ssr-polyfills.js.map +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useEvaluation_exports = {};
|
|
20
|
+
__export(useEvaluation_exports, {
|
|
21
|
+
useEvaluation: () => useEvaluation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useEvaluation_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_useLoader = require('./useLoader.cjs');
|
|
26
|
+
var import_useCroct = require('./useCroct.cjs');
|
|
27
|
+
var import_ssr_polyfills = require('../ssr-polyfills.cjs');
|
|
28
|
+
var import_hash = require('../hash.cjs');
|
|
29
|
+
function useCsrEvaluation(query, options = {}) {
|
|
30
|
+
const {
|
|
31
|
+
cacheKey,
|
|
32
|
+
fallback,
|
|
33
|
+
expiration,
|
|
34
|
+
staleWhileLoading = false,
|
|
35
|
+
initial: initialValue,
|
|
36
|
+
...evaluationOptions
|
|
37
|
+
} = options;
|
|
38
|
+
const [initial, setInitial] = (0, import_react.useState)(initialValue);
|
|
39
|
+
const croct = (0, import_useCroct.useCroct)();
|
|
40
|
+
const result = (0, import_useLoader.useLoader)({
|
|
41
|
+
cacheKey: (0, import_hash.hash)(
|
|
42
|
+
`useEvaluation:${cacheKey ?? ""}:${query}:${JSON.stringify(options.attributes ?? {})}`
|
|
43
|
+
),
|
|
44
|
+
loader: () => croct.evaluate(query, cleanEvaluationOptions(evaluationOptions)),
|
|
45
|
+
initial,
|
|
46
|
+
fallback,
|
|
47
|
+
expiration
|
|
48
|
+
});
|
|
49
|
+
(0, import_react.useEffect)(
|
|
50
|
+
() => {
|
|
51
|
+
if (staleWhileLoading) {
|
|
52
|
+
setInitial((current) => {
|
|
53
|
+
if (current !== result) {
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
return current;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[result, staleWhileLoading]
|
|
61
|
+
);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function cleanEvaluationOptions(options) {
|
|
65
|
+
const result = {};
|
|
66
|
+
for (const [key, value] of Object.entries(options)) {
|
|
67
|
+
if (value !== void 0) {
|
|
68
|
+
result[key] = value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function useSsrEvaluation(_, { initial } = {}) {
|
|
74
|
+
if (initial === void 0) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"The initial value is required for server-side rendering (SSR). For help, see https://croct.help/sdk/react/missing-evaluation-result"
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return initial;
|
|
80
|
+
}
|
|
81
|
+
const useEvaluation = (0, import_ssr_polyfills.isSsr)() ? useSsrEvaluation : useCsrEvaluation;
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
useEvaluation
|
|
85
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { JsonValue } from '@croct/plug/sdk/json';
|
|
2
|
+
import { EvaluationOptions } from '@croct/sdk/facade/evaluatorFacade';
|
|
3
|
+
|
|
4
|
+
type UseEvaluationOptions<I, F> = EvaluationOptions & {
|
|
5
|
+
initial?: I;
|
|
6
|
+
fallback?: F;
|
|
7
|
+
cacheKey?: string;
|
|
8
|
+
expiration?: number;
|
|
9
|
+
staleWhileLoading?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type UseEvaluationHook = <T extends JsonValue, I = T, F = T>(query: string, options?: UseEvaluationOptions<I, F>) => T | I | F;
|
|
12
|
+
declare const useEvaluation: UseEvaluationHook;
|
|
13
|
+
|
|
14
|
+
export { type UseEvaluationOptions, useEvaluation };
|
package/hooks/useEvaluation.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { JsonValue } from '@croct/plug/sdk/json';
|
|
2
2
|
import { EvaluationOptions } from '@croct/sdk/facade/evaluatorFacade';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
type UseEvaluationOptions<I, F> = EvaluationOptions & {
|
|
4
5
|
initial?: I;
|
|
5
6
|
fallback?: F;
|
|
6
7
|
cacheKey?: string;
|
|
@@ -8,5 +9,6 @@ export type UseEvaluationOptions<I, F> = EvaluationOptions & {
|
|
|
8
9
|
staleWhileLoading?: boolean;
|
|
9
10
|
};
|
|
10
11
|
type UseEvaluationHook = <T extends JsonValue, I = T, F = T>(query: string, options?: UseEvaluationOptions<I, F>) => T | I | F;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
declare const useEvaluation: UseEvaluationHook;
|
|
13
|
+
|
|
14
|
+
export { type UseEvaluationOptions, useEvaluation };
|
package/hooks/useEvaluation.js
CHANGED
|
@@ -1,52 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const useCroct_1 = require("./useCroct");
|
|
7
|
-
const ssr_polyfills_1 = require("../ssr-polyfills");
|
|
8
|
-
const hash_1 = require("../hash");
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { useLoader } from "./useLoader.js";
|
|
3
|
+
import { useCroct } from "./useCroct.js";
|
|
4
|
+
import { isSsr } from "../ssr-polyfills.js";
|
|
5
|
+
import { hash } from "../hash.js";
|
|
9
6
|
function useCsrEvaluation(query, options = {}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
7
|
+
const {
|
|
8
|
+
cacheKey,
|
|
9
|
+
fallback,
|
|
10
|
+
expiration,
|
|
11
|
+
staleWhileLoading = false,
|
|
12
|
+
initial: initialValue,
|
|
13
|
+
...evaluationOptions
|
|
14
|
+
} = options;
|
|
15
|
+
const [initial, setInitial] = useState(initialValue);
|
|
16
|
+
const croct = useCroct();
|
|
17
|
+
const result = useLoader({
|
|
18
|
+
cacheKey: hash(
|
|
19
|
+
`useEvaluation:${cacheKey ?? ""}:${query}:${JSON.stringify(options.attributes ?? {})}`
|
|
20
|
+
),
|
|
21
|
+
loader: () => croct.evaluate(query, cleanEvaluationOptions(evaluationOptions)),
|
|
22
|
+
initial,
|
|
23
|
+
fallback,
|
|
24
|
+
expiration
|
|
25
|
+
});
|
|
26
|
+
useEffect(
|
|
27
|
+
() => {
|
|
28
|
+
if (staleWhileLoading) {
|
|
29
|
+
setInitial((current) => {
|
|
30
|
+
if (current !== result) {
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
return current;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[result, staleWhileLoading]
|
|
38
|
+
);
|
|
39
|
+
return result;
|
|
34
40
|
}
|
|
35
41
|
function cleanEvaluationOptions(options) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
42
|
+
const result = {};
|
|
43
|
+
for (const [key, value] of Object.entries(options)) {
|
|
44
|
+
if (value !== void 0) {
|
|
45
|
+
result[key] = value;
|
|
41
46
|
}
|
|
42
|
-
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
43
49
|
}
|
|
44
50
|
function useSsrEvaluation(_, { initial } = {}) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
if (initial === void 0) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
"The initial value is required for server-side rendering (SSR). For help, see https://croct.help/sdk/react/missing-evaluation-result"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return initial;
|
|
50
57
|
}
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
const useEvaluation = isSsr() ? useSsrEvaluation : useCsrEvaluation;
|
|
59
|
+
export {
|
|
60
|
+
useEvaluation
|
|
61
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useLoader_exports = {};
|
|
20
|
+
__export(useLoader_exports, {
|
|
21
|
+
useLoader: () => useLoader
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useLoader_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_Cache = require('./Cache.cjs');
|
|
26
|
+
const cache = new import_Cache.Cache(60 * 1e3);
|
|
27
|
+
function useLoader({ initial, ...currentOptions }) {
|
|
28
|
+
const optionsRef = (0, import_react.useRef)(currentOptions);
|
|
29
|
+
const [value, setValue] = (0, import_react.useState)(() => cache.get(currentOptions.cacheKey)?.result ?? initial);
|
|
30
|
+
const mountedRef = (0, import_react.useRef)(true);
|
|
31
|
+
const load = (0, import_react.useCallback)(
|
|
32
|
+
(options) => {
|
|
33
|
+
try {
|
|
34
|
+
setValue(cache.load(options));
|
|
35
|
+
} catch (result) {
|
|
36
|
+
if (result instanceof Promise) {
|
|
37
|
+
result.then((resolvedValue) => {
|
|
38
|
+
if (mountedRef.current) {
|
|
39
|
+
setValue(resolvedValue);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setValue(void 0);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[]
|
|
48
|
+
);
|
|
49
|
+
(0, import_react.useEffect)(
|
|
50
|
+
() => {
|
|
51
|
+
mountedRef.current = true;
|
|
52
|
+
if (initial !== void 0) {
|
|
53
|
+
load(currentOptions);
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
mountedRef.current = false;
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- Should run only once
|
|
60
|
+
[]
|
|
61
|
+
);
|
|
62
|
+
(0, import_react.useEffect)(
|
|
63
|
+
() => {
|
|
64
|
+
if (optionsRef.current.cacheKey !== currentOptions.cacheKey) {
|
|
65
|
+
setValue(initial);
|
|
66
|
+
optionsRef.current = currentOptions;
|
|
67
|
+
if (initial !== void 0) {
|
|
68
|
+
load(currentOptions);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
[currentOptions, initial, load]
|
|
73
|
+
);
|
|
74
|
+
if (value === void 0) {
|
|
75
|
+
return cache.load(currentOptions);
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
useLoader
|
|
82
|
+
});
|
package/hooks/useLoader.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { EntryOptions } from './Cache';
|
|
2
|
-
|
|
1
|
+
import { EntryOptions } from './Cache.js';
|
|
2
|
+
|
|
3
|
+
type CacheOptions<R> = EntryOptions<R> & {
|
|
3
4
|
initial?: R;
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
export type { CacheOptions };
|
package/hooks/useLoader.js
CHANGED
|
@@ -1,63 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
setValue(cache.load(options));
|
|
18
|
-
}
|
|
19
|
-
catch (result) {
|
|
20
|
-
if (result instanceof Promise) {
|
|
21
|
-
result.then((resolvedValue) => {
|
|
22
|
-
if (mountedRef.current) {
|
|
23
|
-
setValue(resolvedValue);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return;
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Cache } from "./Cache.js";
|
|
3
|
+
const cache = new Cache(60 * 1e3);
|
|
4
|
+
function useLoader({ initial, ...currentOptions }) {
|
|
5
|
+
const optionsRef = useRef(currentOptions);
|
|
6
|
+
const [value, setValue] = useState(() => cache.get(currentOptions.cacheKey)?.result ?? initial);
|
|
7
|
+
const mountedRef = useRef(true);
|
|
8
|
+
const load = useCallback(
|
|
9
|
+
(options) => {
|
|
10
|
+
try {
|
|
11
|
+
setValue(cache.load(options));
|
|
12
|
+
} catch (result) {
|
|
13
|
+
if (result instanceof Promise) {
|
|
14
|
+
result.then((resolvedValue) => {
|
|
15
|
+
if (mountedRef.current) {
|
|
16
|
+
setValue(resolvedValue);
|
|
27
17
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
const reset = useStableCallback(() => {
|
|
32
|
-
var _a;
|
|
33
|
-
const newLoadedValue = (_a = cache.get(cacheKey)) === null || _a === void 0 ? void 0 : _a.result;
|
|
34
|
-
setValue(newLoadedValue !== undefined ? newLoadedValue : initial);
|
|
35
|
-
load();
|
|
36
|
-
});
|
|
37
|
-
(0, react_1.useEffect)(() => {
|
|
38
|
-
if (previousCacheKey.current !== cacheKey) {
|
|
39
|
-
reset();
|
|
40
|
-
previousCacheKey.current = cacheKey;
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
41
20
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
21
|
+
setValue(void 0);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
[]
|
|
25
|
+
);
|
|
26
|
+
useEffect(
|
|
27
|
+
() => {
|
|
28
|
+
mountedRef.current = true;
|
|
29
|
+
if (initial !== void 0) {
|
|
30
|
+
load(currentOptions);
|
|
31
|
+
}
|
|
32
|
+
return () => {
|
|
33
|
+
mountedRef.current = false;
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- Should run only once
|
|
37
|
+
[]
|
|
38
|
+
);
|
|
39
|
+
useEffect(
|
|
40
|
+
() => {
|
|
41
|
+
if (optionsRef.current.cacheKey !== currentOptions.cacheKey) {
|
|
42
|
+
setValue(initial);
|
|
43
|
+
optionsRef.current = currentOptions;
|
|
44
|
+
if (initial !== void 0) {
|
|
45
|
+
load(currentOptions);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
function useStableCallback(callback) {
|
|
57
|
-
const ref = (0, react_1.useRef)();
|
|
58
|
-
(0, react_1.useEffect)(() => {
|
|
59
|
-
ref.current = callback;
|
|
60
|
-
});
|
|
61
|
-
return (0, react_1.useCallback)(() => { var _a; (_a = ref.current) === null || _a === void 0 ? void 0 : _a.call(ref); }, []);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
[currentOptions, initial, load]
|
|
50
|
+
);
|
|
51
|
+
if (value === void 0) {
|
|
52
|
+
return cache.load(currentOptions);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
62
55
|
}
|
|
63
|
-
|
|
56
|
+
export {
|
|
57
|
+
useLoader
|
|
58
|
+
};
|
package/index.cjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var index_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(index_exports);
|
|
18
|
+
__reExport(index_exports, require("@croct/plug/sdk/json"), module.exports);
|
|
19
|
+
__reExport(index_exports, require("@croct/plug/slot"), module.exports);
|
|
20
|
+
__reExport(index_exports, require("@croct/plug/component"), module.exports);
|
|
21
|
+
__reExport(index_exports, require('./CroctProvider.cjs'), module.exports);
|
|
22
|
+
__reExport(index_exports, require('./hooks/index.cjs'), module.exports);
|
|
23
|
+
__reExport(index_exports, require('./components/index.cjs'), module.exports);
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
...require("@croct/plug/sdk/json"),
|
|
27
|
+
...require("@croct/plug/slot"),
|
|
28
|
+
...require("@croct/plug/component"),
|
|
29
|
+
...require('./CroctProvider.cjs'),
|
|
30
|
+
...require('./hooks/index.cjs'),
|
|
31
|
+
...require('./components/index.cjs')
|
|
32
|
+
});
|
package/index.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from '@croct/plug/sdk/json';
|
|
2
|
+
export * from '@croct/plug/slot';
|
|
3
|
+
export * from '@croct/plug/component';
|
|
4
|
+
export { CroctContext, CroctProvider, CroctProviderProps } from './CroctProvider.cjs';
|
|
5
|
+
export { UseEvaluationOptions, useEvaluation } from './hooks/useEvaluation.cjs';
|
|
6
|
+
export { UseContentOptions, useContent } from './hooks/useContent.cjs';
|
|
7
|
+
export { useCroct } from './hooks/useCroct.cjs';
|
|
8
|
+
export { Personalization, PersonalizationProps } from './components/Personalization/index.cjs';
|
|
9
|
+
export { Slot, SlotProps } from './components/Slot/index.cjs';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@croct/plug';
|
|
12
|
+
import '@croct/sdk/facade/evaluatorFacade';
|
|
13
|
+
import '@croct/plug/plug';
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
export * from '@croct/plug/sdk/json';
|
|
2
2
|
export * from '@croct/plug/slot';
|
|
3
3
|
export * from '@croct/plug/component';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
4
|
+
export { CroctContext, CroctProvider, CroctProviderProps } from './CroctProvider.js';
|
|
5
|
+
export { UseEvaluationOptions, useEvaluation } from './hooks/useEvaluation.js';
|
|
6
|
+
export { UseContentOptions, useContent } from './hooks/useContent.js';
|
|
7
|
+
export { useCroct } from './hooks/useCroct.js';
|
|
8
|
+
export { Personalization, PersonalizationProps } from './components/Personalization/index.js';
|
|
9
|
+
export { Slot, SlotProps } from './components/Slot/index.js';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@croct/plug';
|
|
12
|
+
import '@croct/sdk/facade/evaluatorFacade';
|
|
13
|
+
import '@croct/plug/plug';
|
package/index.js
CHANGED
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("@croct/plug/sdk/json"), exports);
|
|
18
|
-
__exportStar(require("@croct/plug/slot"), exports);
|
|
19
|
-
__exportStar(require("@croct/plug/component"), exports);
|
|
20
|
-
__exportStar(require("./CroctProvider"), exports);
|
|
21
|
-
__exportStar(require("./hooks"), exports);
|
|
22
|
-
__exportStar(require("./components"), exports);
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "@croct/plug/sdk/json";
|
|
2
|
+
export * from "@croct/plug/slot";
|
|
3
|
+
export * from "@croct/plug/component";
|
|
4
|
+
export * from "./CroctProvider.js";
|
|
5
|
+
export * from "./hooks/index.js";
|
|
6
|
+
export * from "./components/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/plug-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "React components and hooks to plug your React applications into Croct.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Croct",
|
|
@@ -18,54 +18,85 @@
|
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "git+https://github.com/croct-tech/plug-react.git"
|
|
20
20
|
},
|
|
21
|
+
"type": "module",
|
|
21
22
|
"main": "./index.js",
|
|
22
23
|
"types": "./index.d.ts",
|
|
23
|
-
"
|
|
24
|
+
"exports": {
|
|
25
|
+
"./*": {
|
|
26
|
+
"import": "./*.js",
|
|
27
|
+
"require": "./*.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./components/Personalization": {
|
|
30
|
+
"import": "./components/Personalization/index.js",
|
|
31
|
+
"require": "./components/Personalization/index.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./components/Slot": {
|
|
34
|
+
"import": "./components/Slot/index.js",
|
|
35
|
+
"require": "./components/Slot/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./components": {
|
|
38
|
+
"import": "./components/index.js",
|
|
39
|
+
"require": "./components/index.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./hooks": {
|
|
42
|
+
"import": "./hooks/index.js",
|
|
43
|
+
"require": "./hooks/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
".": {
|
|
46
|
+
"import": "./index.js",
|
|
47
|
+
"require": "./index.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
24
50
|
"engines": {
|
|
25
51
|
"node": ">=10"
|
|
26
52
|
},
|
|
27
53
|
"scripts": {
|
|
28
54
|
"lint": "eslint 'src/**/*.ts' 'src/**/*.tsx'",
|
|
29
|
-
"test": "jest -c jest.config.
|
|
55
|
+
"test": "jest -c jest.config.mjs --coverage",
|
|
30
56
|
"validate": "tsc --noEmit",
|
|
31
|
-
"build": "
|
|
57
|
+
"build": "tsup",
|
|
58
|
+
"postbuild": "./post-build.mjs"
|
|
32
59
|
},
|
|
33
60
|
"peerDependencies": {
|
|
34
|
-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
35
|
-
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
61
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
62
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
36
63
|
},
|
|
37
64
|
"dependencies": {
|
|
38
|
-
"@croct/plug": "^0.
|
|
39
|
-
"@croct/sdk": "^0.
|
|
65
|
+
"@croct/plug": "^0.17.1",
|
|
66
|
+
"@croct/sdk": "^0.18.0"
|
|
40
67
|
},
|
|
41
68
|
"devDependencies": {
|
|
42
69
|
"@babel/core": "^7.25.2",
|
|
43
|
-
"@babel/preset-env": "^7.25.4",
|
|
44
70
|
"@babel/preset-react": "^7.24.7",
|
|
45
71
|
"@babel/preset-typescript": "^7.24.7",
|
|
46
72
|
"@croct/eslint-plugin": "^0.7.1",
|
|
47
|
-
"@testing-library/jest-dom": "^6.
|
|
48
|
-
"@testing-library/react": "^16.0
|
|
73
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
74
|
+
"@testing-library/react": "^16.1.0",
|
|
49
75
|
"@types/jest": "^29.5.12",
|
|
50
76
|
"@types/node": "^22.5.4",
|
|
51
|
-
"@types/react": "^
|
|
52
|
-
"@types/react-dom": "^
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
55
|
-
"
|
|
77
|
+
"@types/react": "^19.0.0",
|
|
78
|
+
"@types/react-dom": "^19.0.0",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^6.18.0",
|
|
80
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
81
|
+
"esbuild-fix-imports-plugin": "^1.0.19",
|
|
56
82
|
"eslint": "^8.57.0",
|
|
57
83
|
"jest": "^29.7.0",
|
|
58
84
|
"jest-environment-jsdom": "^29.7.0",
|
|
59
85
|
"jest-environment-node": "^29.7.0",
|
|
60
|
-
"react": "^
|
|
61
|
-
"react-dom": "^
|
|
86
|
+
"react": "^19.0.0",
|
|
87
|
+
"react-dom": "^19.0.0",
|
|
88
|
+
"ts-jest": "^29.0.3",
|
|
62
89
|
"ts-node": "^10.9.2",
|
|
90
|
+
"tsup": "^8.4.0",
|
|
63
91
|
"typescript": "^5.6.2",
|
|
64
92
|
"webpack": "^5.94.0"
|
|
65
93
|
},
|
|
66
94
|
"files": [
|
|
67
95
|
"**/*.js",
|
|
96
|
+
"**/*.cjs",
|
|
97
|
+
"**/*.mjs",
|
|
68
98
|
"**/*.ts",
|
|
99
|
+
"**/*.cts",
|
|
69
100
|
"**/*.map"
|
|
70
101
|
]
|
|
71
|
-
}
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|