@tickboxhq/vue 0.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/LICENSE +21 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.js +116 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tiny Systems Limited
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { InjectionKey, PropType, ComputedRef } from 'vue';
|
|
3
|
+
import { ConsentStore, ConsentConfig, Jurisdiction, ConsentMode, ResolvedCategory } from '@tickboxhq/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Headless banner component. Renders nothing while the store is hydrating
|
|
7
|
+
* (`!ready`) or when the banner is closed. Uses the default scoped slot to
|
|
8
|
+
* pass the consent API down.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```vue
|
|
12
|
+
* <ConsentBanner v-slot="{ resolved, grantAll, denyAll, save }">
|
|
13
|
+
* <div class="banner">
|
|
14
|
+
* <CategoryRow v-for="c in resolved" :key="c.id" :category="c" />
|
|
15
|
+
* <button @click="denyAll">Reject All</button>
|
|
16
|
+
* <button @click="grantAll">Accept All</button>
|
|
17
|
+
* </div>
|
|
18
|
+
* </ConsentBanner>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const ConsentBanner: vue.DefineComponent<{}, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}>[] | null | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
24
|
+
|
|
25
|
+
declare const ConsentStoreKey: InjectionKey<ConsentStore>;
|
|
26
|
+
|
|
27
|
+
declare const ConsentProvider: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
28
|
+
config: {
|
|
29
|
+
type: PropType<ConsentConfig>;
|
|
30
|
+
required: true;
|
|
31
|
+
};
|
|
32
|
+
jurisdiction: {
|
|
33
|
+
type: PropType<Jurisdiction>;
|
|
34
|
+
default: undefined;
|
|
35
|
+
};
|
|
36
|
+
applyEffects: {
|
|
37
|
+
type: BooleanConstructor;
|
|
38
|
+
default: boolean;
|
|
39
|
+
};
|
|
40
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}>[] | undefined, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
43
|
+
config: {
|
|
44
|
+
type: PropType<ConsentConfig>;
|
|
45
|
+
required: true;
|
|
46
|
+
};
|
|
47
|
+
jurisdiction: {
|
|
48
|
+
type: PropType<Jurisdiction>;
|
|
49
|
+
default: undefined;
|
|
50
|
+
};
|
|
51
|
+
applyEffects: {
|
|
52
|
+
type: BooleanConstructor;
|
|
53
|
+
default: boolean;
|
|
54
|
+
};
|
|
55
|
+
}>> & Readonly<{}>, {
|
|
56
|
+
jurisdiction: Jurisdiction;
|
|
57
|
+
applyEffects: boolean;
|
|
58
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
59
|
+
|
|
60
|
+
type ConsentApi = {
|
|
61
|
+
ready: ComputedRef<boolean>;
|
|
62
|
+
isOpen: ComputedRef<boolean>;
|
|
63
|
+
decisions: ComputedRef<Record<string, boolean>>;
|
|
64
|
+
resolved: ComputedRef<ResolvedCategory[]>;
|
|
65
|
+
storedAt: ComputedRef<number | null>;
|
|
66
|
+
grant: (id: string) => void;
|
|
67
|
+
deny: (id: string) => void;
|
|
68
|
+
grantAll: () => void;
|
|
69
|
+
denyAll: () => void;
|
|
70
|
+
save: () => void;
|
|
71
|
+
reset: () => void;
|
|
72
|
+
open: () => void;
|
|
73
|
+
close: () => void;
|
|
74
|
+
isGranted: (id: string) => boolean;
|
|
75
|
+
};
|
|
76
|
+
type CategoryApi = {
|
|
77
|
+
granted: ComputedRef<boolean>;
|
|
78
|
+
required: ComputedRef<boolean>;
|
|
79
|
+
mode: ComputedRef<ConsentMode>;
|
|
80
|
+
grant: () => void;
|
|
81
|
+
deny: () => void;
|
|
82
|
+
};
|
|
83
|
+
declare function useConsent(): ConsentApi;
|
|
84
|
+
declare function useConsent(categoryId: string): CategoryApi;
|
|
85
|
+
|
|
86
|
+
export { type CategoryApi, type ConsentApi, ConsentBanner, ConsentProvider, ConsentStoreKey, useConsent };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { defineComponent, provide, onMounted, inject, shallowRef, onScopeDispose, computed } from 'vue';
|
|
2
|
+
import { ConsentStore, applyConsent } from '@tickboxhq/core';
|
|
3
|
+
|
|
4
|
+
// src/banner.ts
|
|
5
|
+
|
|
6
|
+
// src/keys.ts
|
|
7
|
+
var ConsentStoreKey = /* @__PURE__ */ Symbol("TickboxConsentStore");
|
|
8
|
+
|
|
9
|
+
// src/use-consent.ts
|
|
10
|
+
function useConsent(categoryId) {
|
|
11
|
+
const store = inject(ConsentStoreKey);
|
|
12
|
+
if (!store) {
|
|
13
|
+
throw new Error("[@tickboxhq/vue] useConsent must be called inside a <ConsentProvider>.");
|
|
14
|
+
}
|
|
15
|
+
const stateRef = shallowRef(store.getState());
|
|
16
|
+
const unsubscribe = store.subscribe((next) => {
|
|
17
|
+
stateRef.value = next;
|
|
18
|
+
});
|
|
19
|
+
onScopeDispose(unsubscribe);
|
|
20
|
+
if (categoryId !== void 0) {
|
|
21
|
+
return {
|
|
22
|
+
granted: computed(() => stateRef.value.decisions[categoryId] === true),
|
|
23
|
+
required: computed(
|
|
24
|
+
() => stateRef.value.resolved.find((r) => r.id === categoryId)?.required ?? false
|
|
25
|
+
),
|
|
26
|
+
mode: computed(
|
|
27
|
+
() => stateRef.value.resolved.find((r) => r.id === categoryId)?.mode ?? "consent"
|
|
28
|
+
),
|
|
29
|
+
grant: () => store.grant(categoryId),
|
|
30
|
+
deny: () => store.deny(categoryId)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
ready: computed(() => stateRef.value.ready),
|
|
35
|
+
isOpen: computed(() => stateRef.value.isOpen),
|
|
36
|
+
decisions: computed(() => stateRef.value.decisions),
|
|
37
|
+
resolved: computed(() => stateRef.value.resolved),
|
|
38
|
+
storedAt: computed(() => stateRef.value.storedAt),
|
|
39
|
+
grant: (id) => store.grant(id),
|
|
40
|
+
deny: (id) => store.deny(id),
|
|
41
|
+
grantAll: () => store.grantAll(),
|
|
42
|
+
denyAll: () => store.denyAll(),
|
|
43
|
+
save: () => store.save(),
|
|
44
|
+
reset: () => store.reset(),
|
|
45
|
+
open: () => store.open(),
|
|
46
|
+
close: () => store.close(),
|
|
47
|
+
isGranted: (id) => stateRef.value.decisions[id] === true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/banner.ts
|
|
52
|
+
var ConsentBanner = defineComponent({
|
|
53
|
+
name: "ConsentBanner",
|
|
54
|
+
setup(_, { slots }) {
|
|
55
|
+
const api = useConsent();
|
|
56
|
+
return () => {
|
|
57
|
+
if (!api.ready.value || !api.isOpen.value) return null;
|
|
58
|
+
return slots.default?.({
|
|
59
|
+
ready: api.ready.value,
|
|
60
|
+
isOpen: api.isOpen.value,
|
|
61
|
+
decisions: api.decisions.value,
|
|
62
|
+
resolved: api.resolved.value,
|
|
63
|
+
storedAt: api.storedAt.value,
|
|
64
|
+
grant: api.grant,
|
|
65
|
+
deny: api.deny,
|
|
66
|
+
grantAll: api.grantAll,
|
|
67
|
+
denyAll: api.denyAll,
|
|
68
|
+
save: api.save,
|
|
69
|
+
reset: api.reset,
|
|
70
|
+
open: api.open,
|
|
71
|
+
close: api.close,
|
|
72
|
+
isGranted: api.isGranted
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var ConsentProvider = defineComponent({
|
|
78
|
+
name: "ConsentProvider",
|
|
79
|
+
props: {
|
|
80
|
+
config: {
|
|
81
|
+
type: Object,
|
|
82
|
+
required: true
|
|
83
|
+
},
|
|
84
|
+
jurisdiction: {
|
|
85
|
+
type: Object,
|
|
86
|
+
default: void 0
|
|
87
|
+
},
|
|
88
|
+
applyEffects: {
|
|
89
|
+
type: Boolean,
|
|
90
|
+
default: true
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
setup(props, { slots }) {
|
|
94
|
+
const j = props.jurisdiction ?? (typeof props.config.jurisdiction !== "string" ? props.config.jurisdiction : void 0);
|
|
95
|
+
if (!j) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
'[@tickboxhq/vue] jurisdiction is "auto" but no `jurisdiction` prop was passed. Resolve it (e.g. via resolveJurisdictionByCountry) and pass it explicitly.'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const store = new ConsentStore(props.config, {
|
|
101
|
+
jurisdiction: j,
|
|
102
|
+
storage: props.config.storage,
|
|
103
|
+
applyEffects: props.applyEffects,
|
|
104
|
+
onApply: props.applyEffects ? applyConsent : void 0
|
|
105
|
+
});
|
|
106
|
+
provide(ConsentStoreKey, store);
|
|
107
|
+
onMounted(() => {
|
|
108
|
+
store.hydrate();
|
|
109
|
+
});
|
|
110
|
+
return () => slots.default?.();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
export { ConsentBanner, ConsentProvider, ConsentStoreKey, useConsent };
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/keys.ts","../src/use-consent.ts","../src/banner.ts","../src/provider.ts"],"names":["defineComponent"],"mappings":";;;;;;AAGO,IAAM,eAAA,0BAAqD,qBAAqB;;;AC4BhF,SAAS,WAAW,UAAA,EAA+C;AACxE,EAAA,MAAM,KAAA,GAAQ,OAAO,eAAe,CAAA;AACpC,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,MAAM,IAAI,MAAM,wEAAwE,CAAA;AAAA,EAC1F;AAEA,EAAA,MAAM,QAAA,GAA8B,UAAA,CAAW,KAAA,CAAM,QAAA,EAAU,CAAA;AAC/D,EAAA,MAAM,WAAA,GAAc,KAAA,CAAM,SAAA,CAAU,CAAC,IAAA,KAAS;AAC5C,IAAA,QAAA,CAAS,KAAA,GA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AAA,OAAO,MAAM,MAAM,OAAA,IAAU;AAAA,EAC/B;AACF,CAAC","file":"index.js","sourcesContent":["import type { ConsentStore } from '@tickboxhq/core'\nimport type { InjectionKey } from 'vue'\n\nexport const ConsentStoreKey: InjectionKey<ConsentStore> = Symbol('TickboxConsentStore')\n","import type { ConsentMode, ConsentState, ResolvedCategory } from '@tickboxhq/core'\nimport { type ComputedRef, type Ref, computed, inject, onScopeDispose, shallowRef } from 'vue'\nimport { ConsentStoreKey } from './keys.js'\n\nexport type ConsentApi = {\n ready: ComputedRef<boolean>\n isOpen: ComputedRef<boolean>\n decisions: ComputedRef<Record<string, boolean>>\n resolved: ComputedRef<ResolvedCategory[]>\n storedAt: ComputedRef<number | null>\n grant: (id: string) => void\n deny: (id: string) => void\n grantAll: () => void\n denyAll: () => void\n save: () => void\n reset: () => void\n open: () => void\n close: () => void\n isGranted: (id: string) => boolean\n}\n\nexport type CategoryApi = {\n granted: ComputedRef<boolean>\n required: ComputedRef<boolean>\n mode: ComputedRef<ConsentMode>\n grant: () => void\n deny: () => void\n}\n\nexport function useConsent(): ConsentApi\nexport function useConsent(categoryId: string): CategoryApi\nexport function useConsent(categoryId?: string): ConsentApi | CategoryApi {\n const store = inject(ConsentStoreKey)\n if (!store) {\n throw new Error('[@tickboxhq/vue] useConsent must be called inside a <ConsentProvider>.')\n }\n\n const stateRef: Ref<ConsentState> = shallowRef(store.getState())\n const unsubscribe = store.subscribe((next) => {\n stateRef.value = next\n })\n onScopeDispose(unsubscribe)\n\n if (categoryId !== undefined) {\n return {\n granted: computed(() => stateRef.value.decisions[categoryId] === true),\n required: computed(\n () => stateRef.value.resolved.find((r) => r.id === categoryId)?.required ?? false,\n ),\n mode: computed(\n () => stateRef.value.resolved.find((r) => r.id === categoryId)?.mode ?? 'consent',\n ),\n grant: () => store.grant(categoryId),\n deny: () => store.deny(categoryId),\n }\n }\n\n return {\n ready: computed(() => stateRef.value.ready),\n isOpen: computed(() => stateRef.value.isOpen),\n decisions: computed(() => stateRef.value.decisions),\n resolved: computed(() => stateRef.value.resolved),\n storedAt: computed(() => stateRef.value.storedAt),\n grant: (id) => store.grant(id),\n deny: (id) => store.deny(id),\n grantAll: () => store.grantAll(),\n denyAll: () => store.denyAll(),\n save: () => store.save(),\n reset: () => store.reset(),\n open: () => store.open(),\n close: () => store.close(),\n isGranted: (id) => stateRef.value.decisions[id] === true,\n }\n}\n","import { defineComponent } from 'vue'\nimport { useConsent } from './use-consent.js'\n\n/**\n * Headless banner component. Renders nothing while the store is hydrating\n * (`!ready`) or when the banner is closed. Uses the default scoped slot to\n * pass the consent API down.\n *\n * @example\n * ```vue\n * <ConsentBanner v-slot=\"{ resolved, grantAll, denyAll, save }\">\n * <div class=\"banner\">\n * <CategoryRow v-for=\"c in resolved\" :key=\"c.id\" :category=\"c\" />\n * <button @click=\"denyAll\">Reject All</button>\n * <button @click=\"grantAll\">Accept All</button>\n * </div>\n * </ConsentBanner>\n * ```\n */\nexport const ConsentBanner = defineComponent({\n name: 'ConsentBanner',\n setup(_, { slots }) {\n const api = useConsent()\n return () => {\n if (!api.ready.value || !api.isOpen.value) return null\n return slots.default?.({\n ready: api.ready.value,\n isOpen: api.isOpen.value,\n decisions: api.decisions.value,\n resolved: api.resolved.value,\n storedAt: api.storedAt.value,\n grant: api.grant,\n deny: api.deny,\n grantAll: api.grantAll,\n denyAll: api.denyAll,\n save: api.save,\n reset: api.reset,\n open: api.open,\n close: api.close,\n isGranted: api.isGranted,\n })\n }\n },\n})\n\nexport default ConsentBanner\n","import { type ConsentConfig, ConsentStore, type Jurisdiction, applyConsent } from '@tickboxhq/core'\nimport { type PropType, defineComponent, onMounted, provide } from 'vue'\nimport { ConsentStoreKey } from './keys.js'\n\nexport const ConsentProvider = defineComponent({\n name: 'ConsentProvider',\n props: {\n config: {\n type: Object as PropType<ConsentConfig>,\n required: true,\n },\n jurisdiction: {\n type: Object as PropType<Jurisdiction>,\n default: undefined,\n },\n applyEffects: {\n type: Boolean,\n default: true,\n },\n },\n setup(props, { slots }) {\n const j =\n props.jurisdiction ??\n (typeof props.config.jurisdiction !== 'string' ? props.config.jurisdiction : undefined)\n if (!j) {\n throw new Error(\n '[@tickboxhq/vue] jurisdiction is \"auto\" but no `jurisdiction` prop was passed. ' +\n 'Resolve it (e.g. via resolveJurisdictionByCountry) and pass it explicitly.',\n )\n }\n\n const store = new ConsentStore(props.config, {\n jurisdiction: j,\n storage: props.config.storage,\n applyEffects: props.applyEffects,\n onApply: props.applyEffects ? applyConsent : undefined,\n })\n\n provide(ConsentStoreKey, store)\n\n onMounted(() => {\n store.hydrate()\n })\n\n return () => slots.default?.()\n },\n})\n\nexport default ConsentProvider\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tickboxhq/vue",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Vue 3 bindings for Tickbox consent management",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://tickbox.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/tickboxhq/tickbox.git",
|
|
10
|
+
"directory": "packages/vue"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@tickboxhq/core": "0.0.1"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"vue": "^3.4.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@vue/test-utils": "^2.4.6",
|
|
37
|
+
"happy-dom": "^15.11.7",
|
|
38
|
+
"tsup": "^8.3.5",
|
|
39
|
+
"typescript": "^5.7.2",
|
|
40
|
+
"vitest": "^2.1.8",
|
|
41
|
+
"vue": "^3.5.13"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:watch": "vitest",
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
48
|
+
}
|
|
49
|
+
}
|