@becklyn/react-usercentrics 4.0.0 → 4.0.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/dist/cjs/hook/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const useUsercentricsHook = ({ windowEvent = "ucEvent", forceReload, debug, }) =
|
|
|
7
7
|
const [cmp, setCmp] = (0, react_1.useState)(null);
|
|
8
8
|
const [consentUpdate, setConsentUpdate] = (0, react_1.useState)(0);
|
|
9
9
|
const [serviceStates, setServiceStates] = (0, react_1.useState)({});
|
|
10
|
+
const [services, setServices] = (0, react_1.useState)([]);
|
|
10
11
|
const incrementConsentUpdate = () => setConsentUpdate(prev => prev + 1);
|
|
11
12
|
const isInitialized = !!((_a = cmp === null || cmp === void 0 ? void 0 : cmp.isInitialized) === null || _a === void 0 ? void 0 : _a.call(cmp));
|
|
12
13
|
(0, react_1.useEffect)(() => {
|
|
@@ -53,6 +54,21 @@ const useUsercentricsHook = ({ windowEvent = "ucEvent", forceReload, debug, }) =
|
|
|
53
54
|
window.addEventListener(windowEvent, onUcEvent);
|
|
54
55
|
return () => window.removeEventListener(windowEvent, onUcEvent);
|
|
55
56
|
}, [debug, windowEvent, forceReload, serviceStates]);
|
|
57
|
+
(0, react_1.useEffect)(() => {
|
|
58
|
+
if (!cmp || !isInitialized) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
let cancelled = false;
|
|
62
|
+
const result = cmp.getServicesBaseInfo();
|
|
63
|
+
Promise.resolve(result).then(resolved => {
|
|
64
|
+
if (!cancelled) {
|
|
65
|
+
setServices(resolved);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return () => {
|
|
69
|
+
cancelled = true;
|
|
70
|
+
};
|
|
71
|
+
}, [cmp, isInitialized, consentUpdate]);
|
|
56
72
|
const showFirstLayer = (0, react_1.useCallback)(() => {
|
|
57
73
|
if (!cmp || !isInitialized) {
|
|
58
74
|
return;
|
|
@@ -75,12 +91,9 @@ const useUsercentricsHook = ({ windowEvent = "ucEvent", forceReload, debug, }) =
|
|
|
75
91
|
if (debug) {
|
|
76
92
|
return true;
|
|
77
93
|
}
|
|
78
|
-
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const service = cmp.getServicesBaseInfo().find(data => data.id === serviceId);
|
|
94
|
+
const service = services.find(data => data.id === serviceId);
|
|
82
95
|
return !!service && service.consent.status;
|
|
83
|
-
}, [debug,
|
|
96
|
+
}, [debug, services]);
|
|
84
97
|
return {
|
|
85
98
|
cmp,
|
|
86
99
|
consentUpdate,
|
package/dist/es/hook/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export const useUsercentricsHook = ({ windowEvent = "ucEvent", forceReload, debu
|
|
|
3
3
|
const [cmp, setCmp] = useState(null);
|
|
4
4
|
const [consentUpdate, setConsentUpdate] = useState(0);
|
|
5
5
|
const [serviceStates, setServiceStates] = useState({});
|
|
6
|
+
const [services, setServices] = useState([]);
|
|
6
7
|
const incrementConsentUpdate = () => setConsentUpdate(prev => prev + 1);
|
|
7
8
|
const isInitialized = !!cmp?.isInitialized?.();
|
|
8
9
|
useEffect(() => {
|
|
@@ -49,6 +50,21 @@ export const useUsercentricsHook = ({ windowEvent = "ucEvent", forceReload, debu
|
|
|
49
50
|
window.addEventListener(windowEvent, onUcEvent);
|
|
50
51
|
return () => window.removeEventListener(windowEvent, onUcEvent);
|
|
51
52
|
}, [debug, windowEvent, forceReload, serviceStates]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!cmp || !isInitialized) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
const result = cmp.getServicesBaseInfo();
|
|
59
|
+
Promise.resolve(result).then(resolved => {
|
|
60
|
+
if (!cancelled) {
|
|
61
|
+
setServices(resolved);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return () => {
|
|
65
|
+
cancelled = true;
|
|
66
|
+
};
|
|
67
|
+
}, [cmp, isInitialized, consentUpdate]);
|
|
52
68
|
const showFirstLayer = useCallback(() => {
|
|
53
69
|
if (!cmp || !isInitialized) {
|
|
54
70
|
return;
|
|
@@ -71,12 +87,9 @@ export const useUsercentricsHook = ({ windowEvent = "ucEvent", forceReload, debu
|
|
|
71
87
|
if (debug) {
|
|
72
88
|
return true;
|
|
73
89
|
}
|
|
74
|
-
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const service = cmp.getServicesBaseInfo().find(data => data.id === serviceId);
|
|
90
|
+
const service = services.find(data => data.id === serviceId);
|
|
78
91
|
return !!service && service.consent.status;
|
|
79
|
-
}, [debug,
|
|
92
|
+
}, [debug, services]);
|
|
80
93
|
return {
|
|
81
94
|
cmp,
|
|
82
95
|
consentUpdate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hook/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGjE,eAAO,MAAM,mBAAmB,GAAI,sCAIjC,iBAAiB,KAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hook/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGjE,eAAO,MAAM,mBAAmB,GAAI,sCAIjC,iBAAiB,KAAG,gBA2ItB,CAAC"}
|
|
@@ -12,7 +12,7 @@ export interface UC {
|
|
|
12
12
|
showFirstLayer: () => void;
|
|
13
13
|
showSecondLayer: (serviceId?: string) => void;
|
|
14
14
|
acceptService: (serviceId: string) => void;
|
|
15
|
-
getServicesBaseInfo: () => UCService[]
|
|
15
|
+
getServicesBaseInfo: () => UCService[] | Promise<UCService[]>;
|
|
16
16
|
}
|
|
17
17
|
export type UCActionType = "onUcImprintClick" | "onUcPrivacyClick" | "onInitialPageLoad" | "onAcceptAllServices" | "onDenyAllServices" | "onUpdateServices" | "onSessionRestored";
|
|
18
18
|
export type ServiceStates = Record<string, string | boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACtB,MAAM,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,EAAE;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,OAAO,CAAC;IAC7B,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,eAAe,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,mBAAmB,EAAE,MAAM,SAAS,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACtB,MAAM,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,EAAE;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,OAAO,CAAC;IAC7B,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,eAAe,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,aAAa,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,mBAAmB,EAAE,MAAM,SAAS,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CA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