@croct/plug-react 0.4.2 → 0.5.0-next.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/CroctProvider.d.ts +7 -7
- package/CroctProvider.js +37 -0
- package/CroctProvider.js.map +1 -0
- package/README.md +245 -107
- package/api/evaluate.d.ts +7 -0
- package/api/evaluate.js +15 -0
- package/api/evaluate.js.map +1 -0
- package/api/fetchContent.d.ts +13 -0
- package/api/fetchContent.js +17 -0
- package/api/fetchContent.js.map +1 -0
- package/api/index.d.ts +2 -0
- package/api/index.js +19 -0
- package/api/index.js.map +1 -0
- package/components/Personalization/index.d.ts +10 -10
- package/components/Personalization/index.js +13 -0
- package/components/Personalization/index.js.map +1 -0
- package/components/Slot/index.d.ts +19 -19
- package/components/Slot/index.js +13 -0
- package/components/Slot/index.js.map +1 -0
- package/components/index.d.ts +2 -2
- package/components/index.js +19 -0
- package/components/index.js.map +1 -0
- package/hooks/Cache.d.ts +22 -22
- package/hooks/Cache.js +62 -0
- package/hooks/Cache.js.map +1 -0
- package/hooks/index.d.ts +3 -3
- package/hooks/index.js +20 -0
- package/hooks/index.js.map +1 -0
- package/hooks/useContent.d.ts +18 -17
- package/hooks/useContent.js +25 -0
- package/hooks/useContent.js.map +1 -0
- package/hooks/useCroct.d.ts +2 -2
- package/hooks/useCroct.js +14 -0
- package/hooks/useCroct.js.map +1 -0
- package/hooks/useEvaluation.d.ts +11 -11
- package/hooks/useEvaluation.js +35 -0
- package/hooks/useEvaluation.js.map +1 -0
- package/hooks/useLoader.d.ts +5 -5
- package/hooks/useLoader.js +41 -0
- package/hooks/useLoader.js.map +1 -0
- package/index.d.ts +5 -3
- package/index.js +20 -337
- package/index.js.map +1 -1
- package/package.json +31 -44
- package/ssr-polyfills.d.ts +3 -3
- package/ssr-polyfills.js +64 -0
- package/ssr-polyfills.js.map +1 -0
- package/CroctProvider.test.d.ts +0 -1
- package/components/Personalization/index.d.test.d.ts +0 -1
- package/components/Personalization/index.stories.d.ts +0 -7
- package/components/Personalization/index.test.d.ts +0 -1
- package/components/Slot/index.d.test.d.ts +0 -1
- package/components/Slot/index.stories.d.ts +0 -17
- package/components/Slot/index.test.d.ts +0 -1
- package/hooks/Cache.test.d.ts +0 -1
- package/hooks/useContent.d.test.d.ts +0 -1
- package/hooks/useContent.ssr.test.d.ts +0 -1
- package/hooks/useContent.stories.d.ts +0 -19
- package/hooks/useContent.test.d.ts +0 -1
- package/hooks/useCroct.ssr.test.d.ts +0 -1
- package/hooks/useCroct.test.d.ts +0 -1
- package/hooks/useEvaluation.d.test.d.ts +0 -1
- package/hooks/useEvaluation.ssr.test.d.ts +0 -1
- package/hooks/useEvaluation.stories.d.ts +0 -8
- package/hooks/useEvaluation.test.d.ts +0 -1
- package/hooks/useLoader.test.d.ts +0 -1
- package/ssr-polyfills.ssr.test.d.ts +0 -1
- package/ssr-polyfills.test.d.ts +0 -1
package/CroctProvider.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FunctionComponent, PropsWithChildren } from 'react';
|
|
2
|
-
import { Configuration, Plug } from '@croct/plug';
|
|
3
|
-
export
|
|
4
|
-
export declare const CroctContext: import("react").Context<{
|
|
5
|
-
plug: Plug;
|
|
6
|
-
} | null>;
|
|
7
|
-
export declare const CroctProvider: FunctionComponent<CroctProviderProps>;
|
|
1
|
+
import { FunctionComponent, PropsWithChildren } from 'react';
|
|
2
|
+
import { Configuration, Plug } from '@croct/plug';
|
|
3
|
+
export type CroctProviderProps = PropsWithChildren<Configuration & Required<Pick<Configuration, 'appId'>>>;
|
|
4
|
+
export declare const CroctContext: import("react").Context<{
|
|
5
|
+
plug: Plug;
|
|
6
|
+
} | null>;
|
|
7
|
+
export declare const CroctProvider: FunctionComponent<CroctProviderProps>;
|
package/CroctProvider.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CroctProvider = exports.CroctContext = void 0;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const ssr_polyfills_1 = require("./ssr-polyfills");
|
|
8
|
+
exports.CroctContext = (0, react_1.createContext)(null);
|
|
9
|
+
exports.CroctContext.displayName = 'CroctContext';
|
|
10
|
+
const CroctProvider = (props) => {
|
|
11
|
+
const { children, ...configuration } = props;
|
|
12
|
+
const parent = (0, react_1.useContext)(exports.CroctContext);
|
|
13
|
+
const initialConfiguration = (0, react_1.useRef)(configuration);
|
|
14
|
+
if (parent !== null) {
|
|
15
|
+
throw new Error('You cannot render <CroctProvider> inside another <CroctProvider>. '
|
|
16
|
+
+ 'Croct should only be initialized once in the application.');
|
|
17
|
+
}
|
|
18
|
+
const context = (0, react_1.useMemo)(() => ({
|
|
19
|
+
get plug() {
|
|
20
|
+
if (!ssr_polyfills_1.croct.initialized) {
|
|
21
|
+
ssr_polyfills_1.croct.plug(initialConfiguration.current);
|
|
22
|
+
}
|
|
23
|
+
return ssr_polyfills_1.croct;
|
|
24
|
+
},
|
|
25
|
+
}), []);
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
ssr_polyfills_1.croct.plug(initialConfiguration.current);
|
|
28
|
+
return () => {
|
|
29
|
+
ssr_polyfills_1.croct.unplug().catch(() => {
|
|
30
|
+
// Suppress errors.
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return ((0, jsx_runtime_1.jsx)(exports.CroctContext.Provider, { value: context, children: children }));
|
|
35
|
+
};
|
|
36
|
+
exports.CroctProvider = CroctProvider;
|
|
37
|
+
//# sourceMappingURL=CroctProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CroctProvider.js","sourceRoot":"","sources":["../src/CroctProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iCASe;AAEf,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