@uibit/consent-guard 0.1.1 → 0.2.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.
- package/dist/frameworks/angular/index.ts +16 -19
- package/dist/frameworks/astro/index.d.ts +4 -1
- package/dist/frameworks/preact/index.d.ts +2 -0
- package/dist/frameworks/react/index.ts +66 -0
- package/dist/frameworks/solid/index.d.ts +1 -1
- package/dist/frameworks/stencil/index.d.ts +2 -0
- package/dist/frameworks/svelte/index.svelte +37 -14
- package/dist/frameworks/vue/index.ts +51 -20
- package/package.json +3 -3
- package/dist/frameworks/react/index.d.ts +0 -18
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { Component, ChangeDetectionStrategy, ElementRef, input, effect, output } from '@angular/core';
|
|
2
2
|
import '@uibit/consent-guard';
|
|
3
3
|
import type { ConsentGuard as HTMLElementClass } from '@uibit/consent-guard';
|
|
4
|
-
|
|
5
4
|
@Component({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
selector: 'uibit-consent-guard',
|
|
6
|
+
template: '<ng-content></ng-content>',
|
|
7
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
8
|
+
standalone: true,
|
|
9
|
+
host: {
|
|
10
|
+
'(consent-accepted)': 'consentAccepted.emit($event)'
|
|
11
|
+
}
|
|
13
12
|
})
|
|
14
13
|
export class NgxConsentGuard {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
readonly consentAccepted = output<CustomEvent<any>>();
|
|
14
|
+
constructor(private el: ElementRef<HTMLElementClass>){
|
|
15
|
+
effect(()=>{
|
|
16
|
+
if (this.el.nativeElement) {
|
|
17
|
+
this.el.nativeElement.locale = this.locale();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
readonly locale = input<string>('');
|
|
22
|
+
readonly consentAccepted = output<CustomEvent<any>>();
|
|
26
23
|
}
|
|
@@ -4,7 +4,10 @@ import '@uibit/consent-guard';
|
|
|
4
4
|
declare global {
|
|
5
5
|
namespace astroHTML.JSX {
|
|
6
6
|
interface IntrinsicElements {
|
|
7
|
-
'uibit-consent-guard': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes
|
|
7
|
+
'uibit-consent-guard': Partial<HTMLElementClass> & astroHTML.JSX.HTMLAttributes & {
|
|
8
|
+
locale?: string;
|
|
9
|
+
"on:consent-accepted"?: (event: Event) => void;
|
|
10
|
+
};
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
13
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
|
|
2
|
+
import type { ConsentGuard as HTMLElementClass } from '@uibit/consent-guard';
|
|
3
|
+
import '@uibit/consent-guard';
|
|
4
|
+
const useTypeOfLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
5
|
+
export interface ConsentGuardProps extends Omit<React.HTMLAttributes<HTMLElementClass>, 'locale' | 'onConsentAccepted'> {
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
locale?: string;
|
|
8
|
+
onConsentAccepted?: (event: Event) => void;
|
|
9
|
+
}
|
|
10
|
+
export const ConsentGuard = ({ ref, children, ...props }: ConsentGuardProps & {
|
|
11
|
+
ref?: React.Ref<HTMLElementClass>;
|
|
12
|
+
})=>{
|
|
13
|
+
const innerRef = useRef<HTMLElementClass>(null);
|
|
14
|
+
const propsRef = useRef(props);
|
|
15
|
+
propsRef.current = props;
|
|
16
|
+
useImperativeHandle(ref, ()=>innerRef.current!);
|
|
17
|
+
useTypeOfLayoutEffect(()=>{
|
|
18
|
+
const element = innerRef.current;
|
|
19
|
+
if (element && props.locale !== undefined) {
|
|
20
|
+
(element as any).locale = props.locale;
|
|
21
|
+
}
|
|
22
|
+
}, [
|
|
23
|
+
props.locale
|
|
24
|
+
]);
|
|
25
|
+
useTypeOfLayoutEffect(()=>{
|
|
26
|
+
const element = innerRef.current;
|
|
27
|
+
if (!element) return;
|
|
28
|
+
const handleEvent = (event: Event)=>{
|
|
29
|
+
if (propsRef.current.onConsentAccepted) {
|
|
30
|
+
propsRef.current.onConsentAccepted(event as any);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
element.addEventListener('consent-accepted', handleEvent);
|
|
34
|
+
return ()=>{
|
|
35
|
+
element.removeEventListener('consent-accepted', handleEvent);
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
const domProps = {
|
|
39
|
+
...props
|
|
40
|
+
};
|
|
41
|
+
const customPropNames = [
|
|
42
|
+
'locale',
|
|
43
|
+
'onConsentAccepted'
|
|
44
|
+
];
|
|
45
|
+
for (const key of customPropNames){
|
|
46
|
+
delete (domProps as any)[key];
|
|
47
|
+
}
|
|
48
|
+
return React.createElement('uibit-consent-guard', {
|
|
49
|
+
ref: innerRef,
|
|
50
|
+
...domProps
|
|
51
|
+
}, children);
|
|
52
|
+
};
|
|
53
|
+
declare global {
|
|
54
|
+
namespace React {
|
|
55
|
+
namespace JSX {
|
|
56
|
+
interface IntrinsicElements {
|
|
57
|
+
'uibit-consent-guard': React.ClassAttributes<HTMLElementClass> & React.HTMLAttributes<HTMLElementClass> & {
|
|
58
|
+
children?: React.ReactNode;
|
|
59
|
+
class?: string;
|
|
60
|
+
locale?: string;
|
|
61
|
+
onConsentAccepted?: (event: CustomEvent<any>) => void;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -7,7 +7,7 @@ declare module 'solid-js' {
|
|
|
7
7
|
interface IntrinsicElements {
|
|
8
8
|
'uibit-consent-guard': Partial<HTMLElementClass> & JSX.HTMLAttributes<HTMLElementClass> & {
|
|
9
9
|
locale?: string;
|
|
10
|
-
"on:consent-accepted"?: (event:
|
|
10
|
+
"on:consent-accepted"?: (event: Event) => void;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,30 +1,53 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import '@uibit/consent-guard';
|
|
3
3
|
import type { ConsentGuard as HTMLElementClass } from '@uibit/consent-guard';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
locale =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
locale = $bindable(),
|
|
7
|
+
placeholder = undefined,
|
|
8
|
+
(default) = undefined,
|
|
9
|
+
children,
|
|
10
|
+
...restProps
|
|
10
11
|
} = $props<{
|
|
11
|
-
children?:
|
|
12
|
+
children?: import('svelte').Snippet;
|
|
12
13
|
locale?: string;
|
|
13
14
|
placeholder?: import('svelte').Snippet;
|
|
14
15
|
(default)?: import('svelte').Snippet;
|
|
16
|
+
[key: string]: any;
|
|
15
17
|
}>();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (elementRef && locale !== undefined) {
|
|
18
|
+
|
|
19
|
+
let elementRef: HTMLElementClass | null = $state(null);
|
|
20
|
+
|
|
21
|
+
$effect(() => {
|
|
22
|
+
if (elementRef && locale !== undefined && elementRef.locale !== locale) {
|
|
21
23
|
elementRef.locale = locale;
|
|
22
24
|
}
|
|
23
25
|
});
|
|
24
|
-
|
|
26
|
+
|
|
27
|
+
$effect(() => {
|
|
28
|
+
const element = elementRef;
|
|
29
|
+
if (!element) return;
|
|
30
|
+
|
|
31
|
+
const handleEvent = () => {
|
|
32
|
+
if (locale !== element.locale) {
|
|
33
|
+
locale = element.locale as any;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const events = ['change', 'input', 'consent-accepted'];
|
|
38
|
+
for (const event of events) {
|
|
39
|
+
element.addEventListener(event, handleEvent);
|
|
40
|
+
}
|
|
41
|
+
return () => {
|
|
42
|
+
for (const event of events) {
|
|
43
|
+
element.removeEventListener(event, handleEvent);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
25
48
|
</script>
|
|
26
49
|
|
|
27
|
-
<uibit-consent-guard bind:this={elementRef} {
|
|
50
|
+
<uibit-consent-guard bind:this={elementRef} {...restProps}>
|
|
28
51
|
{#if placeholder}
|
|
29
52
|
<div slot="placeholder">
|
|
30
53
|
{@render placeholder()}
|
|
@@ -1,24 +1,55 @@
|
|
|
1
|
-
import { defineComponent, h } from 'vue';
|
|
1
|
+
import { defineComponent, h, ref, watch } from 'vue';
|
|
2
2
|
import type { ConsentGuard as HTMLElementClass } from '@uibit/consent-guard';
|
|
3
3
|
import '@uibit/consent-guard';
|
|
4
|
-
|
|
5
4
|
export const ConsentGuard = defineComponent({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
name: 'ConsentGuard',
|
|
6
|
+
props: {
|
|
7
|
+
locale: {
|
|
8
|
+
type: [
|
|
9
|
+
String,
|
|
10
|
+
Number,
|
|
11
|
+
Boolean,
|
|
12
|
+
Array,
|
|
13
|
+
Object
|
|
14
|
+
] as any
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
emits: [
|
|
18
|
+
'consent-accepted'
|
|
19
|
+
],
|
|
20
|
+
setup (props, { slots, emit }) {
|
|
21
|
+
const elementRef = ref<HTMLElementClass | null>(null);
|
|
22
|
+
if (false) {
|
|
23
|
+
watch(()=>props.modelValue, (newVal)=>{
|
|
24
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
25
|
+
elementRef.value.value = newVal;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
watch(()=>props.value, (newVal)=>{
|
|
29
|
+
if (elementRef.value && newVal !== undefined && elementRef.value.value !== newVal) {
|
|
30
|
+
elementRef.value.value = newVal;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
watch(()=>props.locale, (newVal)=>{
|
|
35
|
+
if (elementRef.value && newVal !== undefined) {
|
|
36
|
+
(elementRef.value as any).locale = newVal;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return ()=>{
|
|
40
|
+
const eventListeners: Record<string, any> = {};
|
|
41
|
+
eventListeners['onConsent-accepted'] = (event: Event)=>{
|
|
42
|
+
emit('consent-accepted', event);
|
|
43
|
+
};
|
|
44
|
+
const mergedProps = {
|
|
45
|
+
...props,
|
|
46
|
+
...eventListeners,
|
|
47
|
+
ref: elementRef
|
|
48
|
+
};
|
|
49
|
+
if (false && props.modelValue !== undefined) {
|
|
50
|
+
(mergedProps as any).value = props.modelValue;
|
|
51
|
+
}
|
|
52
|
+
return h('uibit-consent-guard', mergedProps, slots.default?.());
|
|
53
|
+
};
|
|
54
|
+
}
|
|
24
55
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uibit/consent-guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Gate any third-party content behind a consent prompt. The component manages show/hide state only — you provide both the placeholder UI and the content, keeping it composable and unbiased.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"./consent-guard.css": "./dist/consent-guard.css",
|
|
14
14
|
"./custom-elements.json": "./custom-elements.json",
|
|
15
|
-
"./react": "./dist/frameworks/react/index.
|
|
15
|
+
"./react": "./dist/frameworks/react/index.ts",
|
|
16
16
|
"./vue": "./dist/frameworks/vue/index.ts",
|
|
17
17
|
"./svelte": "./dist/frameworks/svelte/index.svelte",
|
|
18
18
|
"./angular": "./dist/frameworks/angular/index.ts",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/node": "^20.19.43",
|
|
54
54
|
"lit": "^3.3.3",
|
|
55
55
|
"typescript": "7.0.2",
|
|
56
|
-
"@uibit/codegen": "0.
|
|
56
|
+
"@uibit/codegen": "0.2.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"lit": "^3.0.0",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { HTMLAttributes, ClassAttributes } from 'react';
|
|
2
|
-
import type { ConsentGuard as HTMLElementClass } from '@uibit/consent-guard';
|
|
3
|
-
import '@uibit/consent-guard';
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
namespace React {
|
|
7
|
-
namespace JSX {
|
|
8
|
-
interface IntrinsicElements {
|
|
9
|
-
'uibit-consent-guard': ClassAttributes<HTMLElementClass> & HTMLAttributes<HTMLElementClass> & {
|
|
10
|
-
children?: React.ReactNode;
|
|
11
|
-
class?: string;
|
|
12
|
-
locale?: string;
|
|
13
|
-
onConsentAccepted?: (event: any) => void;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|