@tickboxhq/vue 0.0.5 → 0.0.7

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/index.js CHANGED
@@ -101,7 +101,7 @@ var ConsentProvider = defineComponent({
101
101
  jurisdiction: j,
102
102
  storage: props.config.storage,
103
103
  applyEffects: props.applyEffects,
104
- onApply: props.applyEffects ? applyConsent : void 0
104
+ onApply: props.applyEffects ? (state) => applyConsent(state, { consentMode: props.config.consentMode }) : void 0
105
105
  });
106
106
  provide(ConsentStoreKey, store);
107
107
  onMounted(() => {
package/dist/index.js.map CHANGED
@@ -1 +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,GAAQ,IAAA;AAAA,EACnB,CAAC,CAAA;AACD,EAAA,cAAA,CAAe,WAAW,CAAA;AAE1B,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,SAAS,MAAM,QAAA,CAAS,MAAM,SAAA,CAAU,UAAU,MAAM,IAAI,CAAA;AAAA,MACrE,QAAA,EAAU,QAAA;AAAA,QACR,MAAM,QAAA,CAAS,KAAA,CAAM,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,EA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A,YAAA,EAAc;AAAA,MACZ,IAAA,EAAM,MAAA;AAAA,MACN,OAAA,EAAS;AAAA,KACX;AAAA,IACA,YAAA,EAAc;AAAA,MACZ,IAAA,EAAM,OAAA;AAAA,MACN,OAAA,EAAS;AAAA;AACX,GACF;AAAA,EACA,KAAA,CAAM,KAAA,EAAO,EAAE,KAAA,EAAM,EAAG;AACtB,IAAA,MAAM,CAAA,GACJ,KAAA,CAAM,YAAA,KACL,OAAO,KAAA,CAAM,OAAO,YAAA,KAAiB,QAAA,GAAW,KAAA,CAAM,MAAA,CAAO,YAAA,GAAe,MAAA,CAAA;AAC/E,IAAA,IAAI,CAAC,CAAA,EAAG;AACN,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OAEF;AAAA,IACF;AAEA,IAAA,MAAM,KAAA,GAAQ,IAAI,YAAA,CAAa,KAAA,CAAM,MAAA,EAAQ;AAAA,MAC3C,YAAA,EAAc,CAAA;AAAA,MACd,OAAA,EAAS,MAAM,MAAA,CAAO,OAAA;AAAA,MACtB,cAAc,KAAA,CAAM,YAAA;AAAA,MACpB,OAAA,EAAS,KAAA,CAAM,YAAA,GAAe,YAAA,GAAe;AAAA,KAC9C,CAAA;AAED,IAAA,OAAA,CAAQ,iBAAiB,KAAK,CAAA;AAE9B,IAAA,SAAA,CAAU,MAAM;AACd,MAAA,KAAA,CAAM,OAAA,EAAQ;AAAA,IAChB,CAAC,CAAA;AAED,IAAA,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"]}
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,GAAQ,IAAA;AAAA,EACnB,CAAC,CAAA;AACD,EAAA,cAAA,CAAe,WAAW,CAAA;AAE1B,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,SAAS,MAAM,QAAA,CAAS,MAAM,SAAA,CAAU,UAAU,MAAM,IAAI,CAAA;AAAA,MACrE,QAAA,EAAU,QAAA;AAAA,QACR,MAAM,QAAA,CAAS,KAAA,CAAM,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,EAAA,KAAO,UAAU,CAAA,EAAG,QAAA,IAAY;AAAA,OAC9E;AAAA,MACA,IAAA,EAAM,QAAA;AAAA,QACJ,MAAM,QAAA,CAAS,KAAA,CAAM,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,EAAA,KAAO,UAAU,CAAA,EAAG,IAAA,IAAQ;AAAA,OAC1E;AAAA,MACA,KAAA,EAAO,MAAM,KAAA,CAAM,KAAA,CAAM,UAAU,CAAA;AAAA,MACnC,IAAA,EAAM,MA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AAW,KAAA,CAAM,MAAA,CAAO,YAAA,GAAe,MAAA,CAAA;AAC/E,IAAA,IAAI,CAAC,CAAA,EAAG;AACN,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OAEF;AAAA,IACF;AAEA,IAAA,MAAM,KAAA,GAAQ,IAAI,YAAA,CAAa,KAAA,CAAM,MAAA,EAAQ;AAAA,MAC3C,YAAA,EAAc,CAAA;AAAA,MACd,OAAA,EAAS,MAAM,MAAA,CAAO,OAAA;AAAA,MACtB,cAAc,KAAA,CAAM,YAAA;AAAA,MACpB,OAAA,EAAS,KAAA,CAAM,YAAA,GACX,CAAC,KAAA,KAAU,YAAA,CAAa,KAAA,EAAO,EAAE,WAAA,EAAa,KAAA,CAAM,MAAA,CAAO,WAAA,EAAa,CAAA,GACxE;AAAA,KACL,CAAA;AAED,IAAA,OAAA,CAAQ,iBAAiB,KAAK,CAAA;AAE9B,IAAA,SAAA,CAAU,MAAM;AACd,MAAA,KAAA,CAAM,OAAA,EAAQ;AAAA,IAChB,CAAC,CAAA;AAED,IAAA,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\n ? (state) => applyConsent(state, { consentMode: props.config.consentMode })\n : 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tickboxhq/vue",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Vue 3 bindings for Tickbox consent management",
5
5
  "license": "MIT",
6
6
  "homepage": "https://tickbox.dev",
@@ -27,7 +27,7 @@
27
27
  "access": "public"
28
28
  },
29
29
  "dependencies": {
30
- "@tickboxhq/core": "0.0.5"
30
+ "@tickboxhq/core": "0.0.7"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "vue": "^3.4.0"