@c15t/react 0.0.1-rc.22 → 0.0.1-rc.23
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/dist/hooks/index.js +1 -17
- package/dist/providers/consent-manager-provider.cjs +41 -42
- package/dist/providers/consent-manager-provider.d.ts.map +1 -1
- package/dist/providers/consent-manager-provider.js +41 -42
- package/dist/utils/test-helpers.cjs +1 -1
- package/dist/utils/test-helpers.js +1 -1
- package/package.json +4 -4
package/dist/hooks/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE__use_theme_js_d12716c7__ from "./use-theme.js";
|
|
2
1
|
export * from "./use-consent-manager.js";
|
|
3
2
|
export * from "./use-focus-trap.js";
|
|
3
|
+
export * from "./use-theme.js";
|
|
4
4
|
export * from "./use-translations.js";
|
|
5
|
-
var __webpack_modules__ = {
|
|
6
|
-
"~/hooks/use-theme": function(module) {
|
|
7
|
-
module.exports = __WEBPACK_EXTERNAL_MODULE__use_theme_js_d12716c7__;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var __webpack_module_cache__ = {};
|
|
11
|
-
function __webpack_require__(moduleId) {
|
|
12
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
-
exports: {}
|
|
16
|
-
};
|
|
17
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
-
return module.exports;
|
|
19
|
-
}
|
|
20
|
-
__webpack_require__("~/hooks/use-theme");
|
|
@@ -48,6 +48,13 @@ function ConsentManagerProvider({ children, options }) {
|
|
|
48
48
|
}, [
|
|
49
49
|
translationConfig
|
|
50
50
|
]);
|
|
51
|
+
const isConsentDomain = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
52
|
+
if ('undefined' == typeof window) return false;
|
|
53
|
+
return Boolean(('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev')));
|
|
54
|
+
}, [
|
|
55
|
+
mode,
|
|
56
|
+
backendURL
|
|
57
|
+
]);
|
|
51
58
|
const consentManager = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
52
59
|
if ('offline' === mode) return (0, external_c15t_namespaceObject.configureConsentManager)({
|
|
53
60
|
mode: 'offline',
|
|
@@ -73,67 +80,46 @@ function ConsentManagerProvider({ children, options }) {
|
|
|
73
80
|
store,
|
|
74
81
|
options
|
|
75
82
|
]);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return Boolean(isC15tDomain);
|
|
80
|
-
}, [
|
|
81
|
-
mode,
|
|
82
|
-
backendURL
|
|
83
|
-
]);
|
|
83
|
+
const storeRef = (0, external_react_namespaceObject.useRef)(null);
|
|
84
|
+
const prevBackendURLRef = (0, external_react_namespaceObject.useRef)(backendURL);
|
|
85
|
+
const prevModeRef = (0, external_react_namespaceObject.useRef)(mode);
|
|
84
86
|
const consentStore = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
85
87
|
const storeWithTranslations = {
|
|
86
88
|
...store,
|
|
87
89
|
translationConfig: preparedTranslationConfig,
|
|
88
90
|
isConsentDomain
|
|
89
91
|
};
|
|
90
|
-
|
|
92
|
+
const shouldRecreateStore = !storeRef.current || prevBackendURLRef.current !== backendURL || prevModeRef.current !== mode;
|
|
93
|
+
prevBackendURLRef.current = backendURL;
|
|
94
|
+
prevModeRef.current = mode;
|
|
95
|
+
if (shouldRecreateStore) storeRef.current = (0, external_c15t_namespaceObject.createConsentManagerStore)(consentManager, storeWithTranslations);
|
|
96
|
+
return storeRef.current;
|
|
91
97
|
}, [
|
|
92
|
-
store,
|
|
93
|
-
preparedTranslationConfig,
|
|
94
98
|
consentManager,
|
|
95
|
-
isConsentDomain
|
|
99
|
+
isConsentDomain,
|
|
100
|
+
preparedTranslationConfig,
|
|
101
|
+
store,
|
|
102
|
+
backendURL,
|
|
103
|
+
mode
|
|
96
104
|
]);
|
|
97
|
-
const [state, setState] = (0, external_react_namespaceObject.useState)(
|
|
105
|
+
const [state, setState] = (0, external_react_namespaceObject.useState)(()=>{
|
|
106
|
+
if (!consentStore) return {};
|
|
107
|
+
return consentStore.getState();
|
|
108
|
+
});
|
|
98
109
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
110
|
+
if (!consentStore) return;
|
|
99
111
|
const { setGdprTypes, setComplianceSetting, setDetectedCountry } = consentStore.getState();
|
|
100
112
|
if (initialGdprTypes) setGdprTypes(initialGdprTypes);
|
|
101
113
|
if (initialComplianceSettings) for (const [region, settings] of Object.entries(initialComplianceSettings))setComplianceSetting(region, settings);
|
|
102
114
|
const country = document.querySelector('meta[name="user-country"]')?.getAttribute('content') || 'US';
|
|
103
115
|
setDetectedCountry(country);
|
|
104
|
-
const unsubscribe = consentStore.subscribe(
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
return ()=>{
|
|
108
|
-
unsubscribe();
|
|
109
|
-
};
|
|
116
|
+
const unsubscribe = consentStore.subscribe(setState);
|
|
117
|
+
return unsubscribe;
|
|
110
118
|
}, [
|
|
111
119
|
consentStore,
|
|
112
120
|
initialGdprTypes,
|
|
113
121
|
initialComplianceSettings
|
|
114
122
|
]);
|
|
115
|
-
(0, use_color_scheme_cjs_namespaceObject.useColorScheme)(colorScheme);
|
|
116
|
-
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>({
|
|
117
|
-
state,
|
|
118
|
-
store: consentStore,
|
|
119
|
-
manager: consentManager,
|
|
120
|
-
theme,
|
|
121
|
-
disableAnimation,
|
|
122
|
-
scrollLock,
|
|
123
|
-
trapFocus,
|
|
124
|
-
colorScheme,
|
|
125
|
-
noStyle
|
|
126
|
-
}), [
|
|
127
|
-
state,
|
|
128
|
-
consentStore,
|
|
129
|
-
consentManager,
|
|
130
|
-
theme,
|
|
131
|
-
disableAnimation,
|
|
132
|
-
scrollLock,
|
|
133
|
-
trapFocus,
|
|
134
|
-
colorScheme,
|
|
135
|
-
noStyle
|
|
136
|
-
]);
|
|
137
123
|
const themeContextValue = (0, external_react_namespaceObject.useMemo)(()=>({
|
|
138
124
|
theme,
|
|
139
125
|
noStyle,
|
|
@@ -147,8 +133,21 @@ function ConsentManagerProvider({ children, options }) {
|
|
|
147
133
|
scrollLock,
|
|
148
134
|
trapFocus
|
|
149
135
|
]);
|
|
136
|
+
(0, use_color_scheme_cjs_namespaceObject.useColorScheme)(colorScheme);
|
|
137
|
+
const consentContextValue = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
138
|
+
if (!consentStore) throw new Error('Consent store must be initialized before creating context value');
|
|
139
|
+
return {
|
|
140
|
+
state,
|
|
141
|
+
store: consentStore,
|
|
142
|
+
manager: consentManager
|
|
143
|
+
};
|
|
144
|
+
}, [
|
|
145
|
+
state,
|
|
146
|
+
consentStore,
|
|
147
|
+
consentManager
|
|
148
|
+
]);
|
|
150
149
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(consent_manager_context_cjs_namespaceObject.ConsentStateContext.Provider, {
|
|
151
|
-
value:
|
|
150
|
+
value: consentContextValue,
|
|
152
151
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(theme_context_cjs_namespaceObject.GlobalThemeContext.Provider, {
|
|
153
152
|
value: themeContextValue,
|
|
154
153
|
children: children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consent-manager-provider.d.ts","sourceRoot":"","sources":["../../src/providers/consent-manager-provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"consent-manager-provider.d.ts","sourceRoot":"","sources":["../../src/providers/consent-manager-provider.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAM5E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,EACtC,QAAQ,EACR,OAAO,GACP,EAAE,2BAA2B,2CAwM7B"}
|
|
@@ -20,6 +20,13 @@ function ConsentManagerProvider({ children, options }) {
|
|
|
20
20
|
}, [
|
|
21
21
|
translationConfig
|
|
22
22
|
]);
|
|
23
|
+
const isConsentDomain = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
24
|
+
if ('undefined' == typeof window) return false;
|
|
25
|
+
return Boolean(('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev')));
|
|
26
|
+
}, [
|
|
27
|
+
mode,
|
|
28
|
+
backendURL
|
|
29
|
+
]);
|
|
23
30
|
const consentManager = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
24
31
|
if ('offline' === mode) return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.configureConsentManager)({
|
|
25
32
|
mode: 'offline',
|
|
@@ -45,67 +52,46 @@ function ConsentManagerProvider({ children, options }) {
|
|
|
45
52
|
store,
|
|
46
53
|
options
|
|
47
54
|
]);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return Boolean(isC15tDomain);
|
|
52
|
-
}, [
|
|
53
|
-
mode,
|
|
54
|
-
backendURL
|
|
55
|
-
]);
|
|
55
|
+
const storeRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
|
|
56
|
+
const prevBackendURLRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(backendURL);
|
|
57
|
+
const prevModeRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(mode);
|
|
56
58
|
const consentStore = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
57
59
|
const storeWithTranslations = {
|
|
58
60
|
...store,
|
|
59
61
|
translationConfig: preparedTranslationConfig,
|
|
60
62
|
isConsentDomain
|
|
61
63
|
};
|
|
62
|
-
|
|
64
|
+
const shouldRecreateStore = !storeRef.current || prevBackendURLRef.current !== backendURL || prevModeRef.current !== mode;
|
|
65
|
+
prevBackendURLRef.current = backendURL;
|
|
66
|
+
prevModeRef.current = mode;
|
|
67
|
+
if (shouldRecreateStore) storeRef.current = (0, __WEBPACK_EXTERNAL_MODULE_c15t__.createConsentManagerStore)(consentManager, storeWithTranslations);
|
|
68
|
+
return storeRef.current;
|
|
63
69
|
}, [
|
|
64
|
-
store,
|
|
65
|
-
preparedTranslationConfig,
|
|
66
70
|
consentManager,
|
|
67
|
-
isConsentDomain
|
|
71
|
+
isConsentDomain,
|
|
72
|
+
preparedTranslationConfig,
|
|
73
|
+
store,
|
|
74
|
+
backendURL,
|
|
75
|
+
mode
|
|
68
76
|
]);
|
|
69
|
-
const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(
|
|
77
|
+
const [state, setState] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(()=>{
|
|
78
|
+
if (!consentStore) return {};
|
|
79
|
+
return consentStore.getState();
|
|
80
|
+
});
|
|
70
81
|
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
82
|
+
if (!consentStore) return;
|
|
71
83
|
const { setGdprTypes, setComplianceSetting, setDetectedCountry } = consentStore.getState();
|
|
72
84
|
if (initialGdprTypes) setGdprTypes(initialGdprTypes);
|
|
73
85
|
if (initialComplianceSettings) for (const [region, settings] of Object.entries(initialComplianceSettings))setComplianceSetting(region, settings);
|
|
74
86
|
const country = document.querySelector('meta[name="user-country"]')?.getAttribute('content') || 'US';
|
|
75
87
|
setDetectedCountry(country);
|
|
76
|
-
const unsubscribe = consentStore.subscribe(
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
return ()=>{
|
|
80
|
-
unsubscribe();
|
|
81
|
-
};
|
|
88
|
+
const unsubscribe = consentStore.subscribe(setState);
|
|
89
|
+
return unsubscribe;
|
|
82
90
|
}, [
|
|
83
91
|
consentStore,
|
|
84
92
|
initialGdprTypes,
|
|
85
93
|
initialComplianceSettings
|
|
86
94
|
]);
|
|
87
|
-
(0, __WEBPACK_EXTERNAL_MODULE__hooks_use_color_scheme_js_939e374b__.useColorScheme)(colorScheme);
|
|
88
|
-
const contextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
89
|
-
state,
|
|
90
|
-
store: consentStore,
|
|
91
|
-
manager: consentManager,
|
|
92
|
-
theme,
|
|
93
|
-
disableAnimation,
|
|
94
|
-
scrollLock,
|
|
95
|
-
trapFocus,
|
|
96
|
-
colorScheme,
|
|
97
|
-
noStyle
|
|
98
|
-
}), [
|
|
99
|
-
state,
|
|
100
|
-
consentStore,
|
|
101
|
-
consentManager,
|
|
102
|
-
theme,
|
|
103
|
-
disableAnimation,
|
|
104
|
-
scrollLock,
|
|
105
|
-
trapFocus,
|
|
106
|
-
colorScheme,
|
|
107
|
-
noStyle
|
|
108
|
-
]);
|
|
109
95
|
const themeContextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
|
|
110
96
|
theme,
|
|
111
97
|
noStyle,
|
|
@@ -119,8 +105,21 @@ function ConsentManagerProvider({ children, options }) {
|
|
|
119
105
|
scrollLock,
|
|
120
106
|
trapFocus
|
|
121
107
|
]);
|
|
108
|
+
(0, __WEBPACK_EXTERNAL_MODULE__hooks_use_color_scheme_js_939e374b__.useColorScheme)(colorScheme);
|
|
109
|
+
const consentContextValue = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
|
|
110
|
+
if (!consentStore) throw new Error('Consent store must be initialized before creating context value');
|
|
111
|
+
return {
|
|
112
|
+
state,
|
|
113
|
+
store: consentStore,
|
|
114
|
+
manager: consentManager
|
|
115
|
+
};
|
|
116
|
+
}, [
|
|
117
|
+
state,
|
|
118
|
+
consentStore,
|
|
119
|
+
consentManager
|
|
120
|
+
]);
|
|
122
121
|
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_consent_manager_context_js_ee8f06d2__.ConsentStateContext.Provider, {
|
|
123
|
-
value:
|
|
122
|
+
value: consentContextValue,
|
|
124
123
|
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_theme_context_js_fbb05439__.GlobalThemeContext.Provider, {
|
|
125
124
|
value: themeContextValue,
|
|
126
125
|
children: children
|
|
@@ -41,7 +41,7 @@ async function testComponentStyles({ component, testCases, noStyle = false }) {
|
|
|
41
41
|
},
|
|
42
42
|
children: component
|
|
43
43
|
}));
|
|
44
|
-
await new Promise((resolve)=>setTimeout(resolve,
|
|
44
|
+
await new Promise((resolve)=>setTimeout(resolve, 50));
|
|
45
45
|
for (const { testId, styles } of testCases){
|
|
46
46
|
const elementInContainer = container.querySelector(`[data-testid="${testId}"]`);
|
|
47
47
|
const elementInBody = document.body.querySelector(`[data-testid="${testId}"]`);
|
|
@@ -12,7 +12,7 @@ async function testComponentStyles({ component, testCases, noStyle = false }) {
|
|
|
12
12
|
},
|
|
13
13
|
children: component
|
|
14
14
|
}));
|
|
15
|
-
await new Promise((resolve)=>setTimeout(resolve,
|
|
15
|
+
await new Promise((resolve)=>setTimeout(resolve, 50));
|
|
16
16
|
for (const { testId, styles } of testCases){
|
|
17
17
|
const elementInContainer = container.querySelector(`[data-testid="${testId}"]`);
|
|
18
18
|
const elementInBody = document.body.querySelector(`[data-testid="${testId}"]`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c15t/react",
|
|
3
|
-
"version": "0.0.1-rc.
|
|
3
|
+
"version": "0.0.1-rc.23",
|
|
4
4
|
"license": "GPL-3.0-only",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
"motion": "^12.6.5",
|
|
66
66
|
"tailwind-variants": "^1.0.0",
|
|
67
67
|
"zustand": "^5.0.3",
|
|
68
|
-
"c15t": "0.0.1-rc.
|
|
68
|
+
"c15t": "0.0.1-rc.23"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@c15t/
|
|
71
|
+
"@c15t/backend": "0.0.1-rc.23",
|
|
72
72
|
"@c15t/typescript-config": "0.0.1-beta.1",
|
|
73
|
-
"@c15t/
|
|
73
|
+
"@c15t/vitest-config": "0.0.1-rc.23"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc",
|