@c15t/react 0.0.1-rc.22 → 0.0.1-rc.24

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.
@@ -6,7 +6,7 @@ var __webpack_modules__ = {
6
6
  "./use-focus-trap": function(module) {
7
7
  module.exports = require("./use-focus-trap.cjs");
8
8
  },
9
- "./use-theme": function(module) {
9
+ "~/hooks/use-theme": function(module) {
10
10
  module.exports = require("./use-theme.cjs");
11
11
  },
12
12
  "./use-translations": function(module) {
@@ -68,7 +68,7 @@ var __webpack_exports__ = {};
68
68
  return _use_focus_trap__WEBPACK_IMPORTED_MODULE_1__[key];
69
69
  }).bind(0, __WEBPACK_IMPORT_KEY__);
70
70
  __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
71
- var _use_theme__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./use-theme");
71
+ var _use_theme__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("~/hooks/use-theme");
72
72
  var __WEBPACK_REEXPORT_OBJECT__ = {};
73
73
  for(var __WEBPACK_IMPORT_KEY__ in _use_theme__WEBPACK_IMPORTED_MODULE_2__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
74
74
  return _use_theme__WEBPACK_IMPORTED_MODULE_2__[key];
@@ -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 isConsentDomain = (0, external_react_namespaceObject.useMemo)(()=>{
77
- if ('undefined' == typeof window) return false;
78
- const isC15tDomain = ('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
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
- return (0, external_c15t_namespaceObject.createConsentManagerStore)(consentManager, storeWithTranslations);
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)(consentStore.getState());
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((newState)=>{
105
- setState(newState);
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: contextValue,
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":"AAaA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAM5E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,EACtC,QAAQ,EACR,OAAO,GACP,EAAE,2BAA2B,2CAwL7B"}
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 isConsentDomain = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
49
- if ('undefined' == typeof window) return false;
50
- const isC15tDomain = ('c15t' === mode || 'offline' === mode) && (backendURL?.includes('c15t.dev') || window.location.hostname.includes('c15t.dev'));
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
- return (0, __WEBPACK_EXTERNAL_MODULE_c15t__.createConsentManagerStore)(consentManager, storeWithTranslations);
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)(consentStore.getState());
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((newState)=>{
77
- setState(newState);
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: contextValue,
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, 500));
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, 500));
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.22",
3
+ "version": "0.0.1-rc.24",
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.22"
68
+ "c15t": "0.0.1-rc.24"
69
69
  },
70
70
  "devDependencies": {
71
- "@c15t/vitest-config": "0.0.1-rc.22",
72
- "@c15t/typescript-config": "0.0.1-beta.1",
73
- "@c15t/backend": "0.0.1-rc.22"
71
+ "@c15t/backend": "0.0.1-rc.24",
72
+ "@c15t/vitest-config": "0.0.1-rc.24",
73
+ "@c15t/typescript-config": "0.0.1-beta.1"
74
74
  },
75
75
  "peerDependencies": {
76
76
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc",