@croct/plug-react 0.10.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.
Files changed (99) hide show
  1. package/CroctProvider.cjs +81 -0
  2. package/CroctProvider.d.cts +11 -0
  3. package/CroctProvider.d.ts +8 -4
  4. package/CroctProvider.js +57 -46
  5. package/api.cjs +22 -0
  6. package/{src/react-app-env.d.ts → api.d.cts} +1 -0
  7. package/api.d.ts +1 -0
  8. package/api.js +1 -18
  9. package/components/Personalization/index.cjs +36 -0
  10. package/components/Personalization/index.d.cts +13 -0
  11. package/components/Personalization/index.d.ts +7 -4
  12. package/components/Personalization/index.js +10 -11
  13. package/components/Slot/index.cjs +36 -0
  14. package/components/Slot/index.d.cts +22 -0
  15. package/components/Slot/index.d.ts +9 -6
  16. package/components/Slot/index.js +10 -12
  17. package/components/index.cjs +24 -0
  18. package/components/index.d.cts +9 -0
  19. package/components/index.d.ts +9 -2
  20. package/components/index.js +2 -19
  21. package/global.d.cjs +1 -0
  22. package/{src/global.d.ts → global.d.d.cts} +1 -1
  23. package/global.d.d.ts +7 -0
  24. package/global.d.js +0 -0
  25. package/hash.cjs +36 -0
  26. package/hash.d.cts +2 -0
  27. package/hash.d.ts +2 -1
  28. package/hash.js +10 -11
  29. package/hooks/Cache.cjs +88 -0
  30. package/hooks/Cache.d.cts +9 -0
  31. package/hooks/Cache.d.ts +4 -17
  32. package/hooks/Cache.js +58 -56
  33. package/hooks/index.cjs +26 -0
  34. package/hooks/index.d.cts +8 -0
  35. package/hooks/index.d.ts +8 -3
  36. package/hooks/index.js +3 -20
  37. package/hooks/useContent.cjs +92 -0
  38. package/hooks/useContent.d.cts +20 -0
  39. package/hooks/useContent.d.ts +6 -5
  40. package/hooks/useContent.js +65 -42
  41. package/hooks/useCroct.cjs +38 -0
  42. package/hooks/useCroct.d.cts +5 -0
  43. package/hooks/useCroct.d.ts +4 -1
  44. package/hooks/useCroct.js +12 -12
  45. package/hooks/useEvaluation.cjs +85 -0
  46. package/hooks/useEvaluation.d.cts +14 -0
  47. package/hooks/useEvaluation.d.ts +5 -3
  48. package/hooks/useEvaluation.js +54 -45
  49. package/hooks/useLoader.cjs +82 -0
  50. package/hooks/useLoader.d.cts +7 -0
  51. package/hooks/useLoader.d.ts +5 -3
  52. package/hooks/useLoader.js +54 -59
  53. package/index.cjs +32 -0
  54. package/index.d.cts +13 -0
  55. package/index.d.ts +10 -3
  56. package/index.js +6 -23
  57. package/package.json +42 -11
  58. package/react-app-env.d.cjs +1 -0
  59. package/react-app-env.d.d.cts +2 -0
  60. package/react-app-env.d.d.ts +2 -0
  61. package/react-app-env.d.js +0 -0
  62. package/ssr-polyfills.cjs +86 -0
  63. package/ssr-polyfills.d.cts +2 -0
  64. package/ssr-polyfills.d.ts +2 -3
  65. package/ssr-polyfills.js +49 -64
  66. package/CroctProvider.js.map +0 -1
  67. package/api.js.map +0 -1
  68. package/components/Personalization/index.js.map +0 -1
  69. package/components/Slot/index.js.map +0 -1
  70. package/components/index.js.map +0 -1
  71. package/hash.js.map +0 -1
  72. package/hooks/Cache.js.map +0 -1
  73. package/hooks/index.js.map +0 -1
  74. package/hooks/useContent.js.map +0 -1
  75. package/hooks/useCroct.js.map +0 -1
  76. package/hooks/useEvaluation.js.map +0 -1
  77. package/hooks/useLoader.js.map +0 -1
  78. package/index.js.map +0 -1
  79. package/src/api.ts +0 -1
  80. package/src/components/index.ts +0 -2
  81. package/src/hash.test.ts +0 -22
  82. package/src/hash.ts +0 -12
  83. package/src/hooks/Cache.test.ts +0 -280
  84. package/src/hooks/Cache.ts +0 -97
  85. package/src/hooks/index.ts +0 -3
  86. package/src/hooks/useContent.ssr.test.ts +0 -23
  87. package/src/hooks/useContent.test.ts +0 -183
  88. package/src/hooks/useContent.ts +0 -107
  89. package/src/hooks/useCroct.ts +0 -16
  90. package/src/hooks/useEvaluation.ssr.test.ts +0 -23
  91. package/src/hooks/useEvaluation.test.ts +0 -180
  92. package/src/hooks/useEvaluation.ts +0 -94
  93. package/src/hooks/useLoader.test.ts +0 -407
  94. package/src/hooks/useLoader.ts +0 -84
  95. package/src/index.ts +0 -6
  96. package/src/ssr-polyfills.ssr.test.ts +0 -46
  97. package/src/ssr-polyfills.test.ts +0 -65
  98. package/src/ssr-polyfills.ts +0 -70
  99. 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 };
@@ -1,6 +1,7 @@
1
1
  import { JsonValue } from '@croct/plug/sdk/json';
2
2
  import { EvaluationOptions } from '@croct/sdk/facade/evaluatorFacade';
3
- export type UseEvaluationOptions<I, F> = EvaluationOptions & {
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
- export declare const useEvaluation: UseEvaluationHook;
12
- export {};
12
+ declare const useEvaluation: UseEvaluationHook;
13
+
14
+ export { type UseEvaluationOptions, useEvaluation };
@@ -1,52 +1,61 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useEvaluation = void 0;
4
- const react_1 = require("react");
5
- const useLoader_1 = require("./useLoader");
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
- var _a;
11
- const { cacheKey, fallback, expiration, staleWhileLoading = false, initial: initialValue, ...evaluationOptions } = options;
12
- const [initial, setInitial] = (0, react_1.useState)(initialValue);
13
- const croct = (0, useCroct_1.useCroct)();
14
- const result = (0, useLoader_1.useLoader)({
15
- cacheKey: (0, hash_1.hash)(`useEvaluation:${cacheKey !== null && cacheKey !== void 0 ? cacheKey : ''}`
16
- + `:${query}`
17
- + `:${JSON.stringify((_a = options.attributes) !== null && _a !== void 0 ? _a : {})}`),
18
- loader: () => croct.evaluate(query, cleanEvaluationOptions(evaluationOptions)),
19
- initial: initial,
20
- fallback: fallback,
21
- expiration: expiration,
22
- });
23
- (0, react_1.useEffect)(() => {
24
- if (staleWhileLoading) {
25
- setInitial(current => {
26
- if (current !== result) {
27
- return result;
28
- }
29
- return current;
30
- });
31
- }
32
- }, [result, staleWhileLoading]);
33
- return result;
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
- const result = {};
37
- for (const [key, value] of Object.entries(options)) {
38
- if (value !== undefined) {
39
- result[key] = value;
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
- return result;
47
+ }
48
+ return result;
43
49
  }
44
50
  function useSsrEvaluation(_, { initial } = {}) {
45
- if (initial === undefined) {
46
- throw new Error('The initial value is required for server-side rendering (SSR). '
47
- + 'For help, see https://croct.help/sdk/react/missing-evaluation-result');
48
- }
49
- return initial;
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
- exports.useEvaluation = (0, ssr_polyfills_1.isSsr)() ? useSsrEvaluation : useCsrEvaluation;
52
- //# sourceMappingURL=useEvaluation.js.map
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
+ });
@@ -0,0 +1,7 @@
1
+ import { EntryOptions } from './Cache.cjs';
2
+
3
+ type CacheOptions<R> = EntryOptions<R> & {
4
+ initial?: R;
5
+ };
6
+
7
+ export type { CacheOptions };
@@ -1,5 +1,7 @@
1
- import { EntryOptions } from './Cache';
2
- export type CacheOptions<R> = EntryOptions<R> & {
1
+ import { EntryOptions } from './Cache.js';
2
+
3
+ type CacheOptions<R> = EntryOptions<R> & {
3
4
  initial?: R;
4
5
  };
5
- export declare function useLoader<R>({ initial, ...options }: CacheOptions<R>): R;
6
+
7
+ export type { CacheOptions };
@@ -1,63 +1,58 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useLoader = useLoader;
4
- const react_1 = require("react");
5
- const Cache_1 = require("./Cache");
6
- const cache = new Cache_1.Cache(60 * 1000);
7
- function useLoader({ initial, ...options }) {
8
- var _a;
9
- const { cacheKey } = options;
10
- const loadedValue = (_a = cache.get(cacheKey)) === null || _a === void 0 ? void 0 : _a.result;
11
- const [value, setValue] = (0, react_1.useState)(loadedValue !== undefined ? loadedValue : initial);
12
- const mountedRef = (0, react_1.useRef)(true);
13
- const initialRef = (0, react_1.useRef)(initial);
14
- const previousCacheKey = (0, react_1.useRef)(cacheKey);
15
- const load = useStableCallback(() => {
16
- try {
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
- setValue(undefined);
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
- }, [reset, cacheKey]);
43
- (0, react_1.useEffect)(() => {
44
- if (initialRef.current !== undefined) {
45
- load();
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
- return () => {
48
- mountedRef.current = false;
49
- };
50
- }, [load]);
51
- if (value === undefined) {
52
- return cache.load(options);
53
- }
54
- return value;
55
- }
56
- function useStableCallback(callback) {
57
- const ref = (0, react_1.useRef)(undefined);
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
- //# sourceMappingURL=useLoader.js.map
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 * from './CroctProvider';
5
- export * from './hooks';
6
- export * from './components';
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
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
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.10.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,29 +18,55 @@
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
- "source": "./index.ts",
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.js --coverage",
55
+ "test": "jest -c jest.config.mjs --coverage",
30
56
  "validate": "tsc --noEmit",
31
- "build": "tsc -p tsconfig.build.json"
57
+ "build": "tsup",
58
+ "postbuild": "./post-build.mjs"
32
59
  },
33
60
  "peerDependencies": {
34
61
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
35
62
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
36
63
  },
37
64
  "dependencies": {
38
- "@croct/plug": "^0.16.2",
39
- "@croct/sdk": "^0.17.6"
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",
@@ -50,22 +76,27 @@
50
76
  "@types/node": "^22.5.4",
51
77
  "@types/react": "^19.0.0",
52
78
  "@types/react-dom": "^19.0.0",
53
- "@typescript-eslint/eslint-plugin": "^7.18.0",
54
- "@typescript-eslint/parser": "^7.18.0",
55
- "babel-loader": "^9.1.3",
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
86
  "react": "^19.0.0",
61
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";
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
File without changes