@cookiemunch/react 0.2.1 → 0.3.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/CHANGELOG.md +5 -0
- package/README.md +4 -0
- package/dist/client.d.ts +28 -1
- package/dist/client.js +26 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Every published release, newest first. Dates are the day the version was cut.
|
|
4
4
|
|
|
5
|
+
## 0.3.0 (2026-10-24)
|
|
6
|
+
|
|
7
|
+
- Added: `<CookieSettingsLink>`, the "Cookie settings" link that reopens the visitor's choices. Plain markup the embed handles, so it renders the same on the server and needs no provider.
|
|
8
|
+
- Added: `useBannerInset()` — the bar's covered edge in pixels, live, for lifting floating buttons.
|
|
9
|
+
|
|
5
10
|
## 0.2.1 (2026-10-22)
|
|
6
11
|
|
|
7
12
|
- The package now ships this changelog and a README.
|
package/README.md
CHANGED
|
@@ -239,6 +239,10 @@ const stop = consentCookie('ab_bucket', 'statistics', () => pickBucket(), { maxA
|
|
|
239
239
|
|
|
240
240
|
To read the same decision on your server, see [the consent cookie](https://cookiemunch.net/docs/consent-cookie).
|
|
241
241
|
|
|
242
|
+
## A "Cookie settings" link
|
|
243
|
+
|
|
244
|
+
`<CookieSettingsLink className="footer-link" />` renders `<a href="#cookie-settings" data-cc="show-settings">Cookie settings</a>`. The embed opens the visitor's settings when it is clicked. Plain markup, so it renders the same on the server and needs no provider.
|
|
245
|
+
|
|
242
246
|
## Notes
|
|
243
247
|
|
|
244
248
|
- There is no `<ConsentBanner>` export in `@cookiemunch/react` — banner UI is rendered by the embed script itself (configured from your Cookie Munch dashboard), not by React. `ConsentProvider` only bridges its state into your component tree. If you want a fully custom banner, hide the stock one in your config and drive `submitCustomConsent`/`acceptAll`/`declineAll` from your own UI as shown above.
|
package/dist/client.d.ts
CHANGED
|
@@ -115,4 +115,31 @@ interface CookieDeclarationProps {
|
|
|
115
115
|
*/
|
|
116
116
|
declare function CookieDeclaration({ emptyText, className, id }: CookieDeclarationProps): react.JSX.Element;
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
/**
|
|
119
|
+
* How many pixels of the viewport's bottom (or top) edge the consent bar covers right now — 0
|
|
120
|
+
* when no bar shows — re-rendering on every change. For floating UI the CSS variable
|
|
121
|
+
* `--cookiemunch-inset-bottom` (or the vendor-neutral `--fd-safe-bottom`) does the same job
|
|
122
|
+
* without a render; use this when the offset is computed in JavaScript.
|
|
123
|
+
*
|
|
124
|
+
* const inset = useBannerInset();
|
|
125
|
+
* <ChatButton style={{ bottom: 20 + inset }} />
|
|
126
|
+
*
|
|
127
|
+
* 0 during SSR. Works with or without `<ConsentProvider>`.
|
|
128
|
+
*/
|
|
129
|
+
declare function useBannerInset(edge?: 'bottom' | 'top'): number;
|
|
130
|
+
|
|
131
|
+
interface CookieSettingsLinkProps {
|
|
132
|
+
children?: ReactNode;
|
|
133
|
+
className?: string;
|
|
134
|
+
/** Where the link points before the embed has loaded (or with scripts off). Default `#cookie-settings`. */
|
|
135
|
+
href?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* "Cookie settings": reopens the visitor's consent choices. It is plain markup — an anchor with
|
|
139
|
+
* `data-cc="show-settings"`, which the embed's own click listener turns into
|
|
140
|
+
* `CookieMunch.showSettings()` — so it renders identically on the server and the client, needs no
|
|
141
|
+
* `<ConsentProvider>`, and opens the panel exactly once (no second handler of its own).
|
|
142
|
+
*/
|
|
143
|
+
declare function CookieSettingsLink({ children, className, href }: CookieSettingsLinkProps): react.JSX.Element;
|
|
144
|
+
|
|
145
|
+
export { type ConsentContextValue, ConsentGate, type ConsentGateProps, ConsentProvider, type ConsentProviderProps, CookieDeclaration, type CookieDeclarationProps, CookieSettingsLink, type CookieSettingsLinkProps, type MintedRightsLink, RightsLink, type RightsLinkProps, useBannerInset, useConsent, useConsentCookie, useConsentValue };
|
package/dist/client.js
CHANGED
|
@@ -199,11 +199,37 @@ function CookieDeclaration({ emptyText, className, id }) {
|
|
|
199
199
|
}
|
|
200
200
|
);
|
|
201
201
|
}
|
|
202
|
+
|
|
203
|
+
// src/useBannerInset.ts
|
|
204
|
+
import { useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
205
|
+
function subscribe2(onStoreChange) {
|
|
206
|
+
if (typeof window === "undefined") return () => {
|
|
207
|
+
};
|
|
208
|
+
window.addEventListener("fd:layout", onStoreChange);
|
|
209
|
+
return () => window.removeEventListener("fd:layout", onStoreChange);
|
|
210
|
+
}
|
|
211
|
+
function read(edge) {
|
|
212
|
+
if (typeof document === "undefined") return 0;
|
|
213
|
+
const v = document.documentElement.style.getPropertyValue(`--cookiemunch-inset-${edge}`);
|
|
214
|
+
const n = parseFloat(v);
|
|
215
|
+
return Number.isFinite(n) ? n : 0;
|
|
216
|
+
}
|
|
217
|
+
function useBannerInset(edge = "bottom") {
|
|
218
|
+
return useSyncExternalStore2(subscribe2, () => read(edge), () => 0);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/CookieSettingsLink.tsx
|
|
222
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
223
|
+
function CookieSettingsLink({ children = "Cookie settings", className, href = "#cookie-settings" }) {
|
|
224
|
+
return /* @__PURE__ */ jsx5("a", { href, className, "data-cc": "show-settings", children });
|
|
225
|
+
}
|
|
202
226
|
export {
|
|
203
227
|
ConsentGate,
|
|
204
228
|
ConsentProvider,
|
|
205
229
|
CookieDeclaration,
|
|
230
|
+
CookieSettingsLink,
|
|
206
231
|
RightsLink,
|
|
232
|
+
useBannerInset,
|
|
207
233
|
useConsent,
|
|
208
234
|
useConsentCookie,
|
|
209
235
|
useConsentValue
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ConsentProvider.tsx","../src/context.ts","../src/useConsent.ts","../src/ConsentGate.tsx","../src/useConsentValue.ts","../src/RightsLink.tsx","../src/CookieDeclaration.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type ReactNode } from 'react';\nimport { ConsentContext, EMPTY_CONSENT, type ConsentContextValue } from './context.js';\nimport type { CookieMunchGlobal, PublicConsent } from './helpers.js';\n\n/** Default CDN location of the base browser embed. */\nconst DEFAULT_SRC = 'https://cdn.cookiemunch.net/consent.js';\n/** The <script> id the embed's bootstrap reads via getElementById. */\nconst SCRIPT_ID = 'CookieMunch';\n\nexport interface ConsentProviderProps {\n /** The Cookie Munch site id (required). Injected as `data-cbid` on the embed. */\n cbid: string;\n /** Embed URL. Defaults to the public CDN. */\n src?: string;\n /** Override the API base the embed beacons to (injected as `data-api`). */\n apiBase?: string;\n children: ReactNode;\n}\n\ninterface Snapshot {\n ready: boolean;\n consent: PublicConsent;\n hasResponse: boolean;\n consented: boolean;\n}\n\nconst INITIAL_SNAPSHOT: Snapshot = {\n ready: false,\n consent: EMPTY_CONSENT,\n hasResponse: false,\n consented: false,\n};\n\n/**\n * Locate the embed's <script> tag, injecting it if it isn't already present.\n * The embed self-bootstraps from the tag's `data-*` attributes and, once ready,\n * assigns `window.CookieMunch`.\n */\nfunction ensureEmbedScript(cbid: string, src: string, apiBase: string | undefined): void {\n const existing = document.getElementById(SCRIPT_ID);\n if (existing) return;\n const script = document.createElement('script');\n script.id = SCRIPT_ID;\n script.async = true;\n script.src = src;\n script.setAttribute('data-cbid', cbid);\n if (apiBase) script.setAttribute('data-api', apiBase);\n (document.head || document.documentElement).appendChild(script);\n}\n\n/**\n * Loads the Cookie Munch browser embed from the CDN at runtime and exposes\n * reactive consent state to descendants — a standalone script-tag SDK wrapper\n * that does NOT bundle the proprietary engine.\n *\n * SSR-safe: no `window`/`document` access during render; the script is injected\n * and the global API resolved only inside an effect. Descendants see an\n * all-denied, not-ready snapshot until the embed reports in.\n */\nexport function ConsentProvider({ cbid, src = DEFAULT_SRC, apiBase, children }: ConsentProviderProps) {\n const apiRef = useRef<CookieMunchGlobal | null>(null);\n const [snap, setSnap] = useState<Snapshot>(INITIAL_SNAPSHOT);\n\n useEffect(() => {\n if (typeof window === 'undefined' || typeof document === 'undefined') return;\n\n let disposed = false;\n let offConsentChange: (() => void) | null = null;\n let pollTimer: ReturnType<typeof setInterval> | null = null;\n\n const sync = (api: CookieMunchGlobal) => {\n if (disposed) return;\n setSnap({\n ready: true,\n consent: api.consent,\n hasResponse: api.hasResponse,\n consented: api.consented,\n });\n };\n\n const bind = (api: CookieMunchGlobal) => {\n if (disposed) return;\n apiRef.current = api;\n sync(api);\n offConsentChange = api.onConsentChange(() => sync(api));\n };\n\n // If the embed is already on the page, reuse it immediately.\n if (window.CookieMunch) {\n bind(window.CookieMunch);\n } else {\n ensureEmbedScript(cbid, src, apiBase);\n // The embed sets window.CookieMunch asynchronously (after its remote-config\n // fetch), so poll until it appears, then bind once.\n pollTimer = setInterval(() => {\n if (window.CookieMunch) {\n if (pollTimer) clearInterval(pollTimer);\n pollTimer = null;\n bind(window.CookieMunch);\n }\n }, 50);\n }\n\n return () => {\n disposed = true;\n if (pollTimer) clearInterval(pollTimer);\n offConsentChange?.();\n apiRef.current = null;\n };\n // Re-bind if the site id / source changes.\n }, [cbid, src, apiBase]);\n\n const api = apiRef.current;\n const value: ConsentContextValue = {\n ready: snap.ready,\n consent: snap.consent,\n hasResponse: snap.hasResponse,\n consented: snap.consented,\n acceptAll: () => api?.submitCustomConsent(true, true, true),\n declineAll: () => api?.submitCustomConsent(false, false, false),\n submitCustomConsent: (p, s, m) => api?.submitCustomConsent(p, s, m),\n withdraw: () => api?.withdraw(),\n show: () => api?.show(),\n renew: () => api?.renew(),\n };\n\n return <ConsentContext.Provider value={value}>{children}</ConsentContext.Provider>;\n}\n","import { createContext } from 'react';\nimport type { PublicConsent } from './helpers.js';\n\nexport interface ConsentContextValue {\n ready: boolean;\n consent: PublicConsent;\n hasResponse: boolean;\n consented: boolean;\n acceptAll(): void;\n declineAll(): void;\n submitCustomConsent(preferences: boolean, statistics: boolean, marketing: boolean): void;\n withdraw(): void;\n show(): void;\n renew(): void;\n}\n\nexport const EMPTY_CONSENT: PublicConsent = {\n necessary: true,\n preferences: false,\n statistics: false,\n marketing: false,\n personalizedAds: false,\n basicAds: false,\n adProfiling: false,\n adMeasurement: false,\n stamp: '',\n};\n\n/** null sentinel => used to detect \"called outside a ConsentProvider\". */\nexport const ConsentContext = createContext<ConsentContextValue | null>(null);\n","import { useContext } from 'react';\nimport { ConsentContext, type ConsentContextValue } from './context.js';\n\nexport type { ConsentContextValue };\n\n/** Access reactive consent state + actions. Must be used within a ConsentProvider. */\nexport function useConsent(): ConsentContextValue {\n const ctx = useContext(ConsentContext);\n if (!ctx) {\n throw new Error('useConsent must be used within a <ConsentProvider>.');\n }\n return ctx;\n}\n","import type { ReactNode } from 'react';\nimport type { Category } from './helpers.js';\nimport { useConsent } from './useConsent.js';\n\nexport interface ConsentGateProps {\n category: Exclude<Category, 'necessary'>;\n children: ReactNode;\n fallback?: ReactNode;\n}\n\n/** Renders children only when the given category is granted (else `fallback`). */\nexport function ConsentGate({ category, children, fallback = null }: ConsentGateProps) {\n const { consent } = useConsent();\n return <>{consent[category] ? children : fallback}</>;\n}\n","import { useContext, useEffect, useSyncExternalStore } from 'react';\nimport { ConsentContext } from './context.js';\nimport { consentCookie, isGranted, type ConsentCookieOptions } from './helpers.js';\n\n/** Window events after which the embed's consent may differ. */\nconst CHANGE_EVENTS = ['CookieMunchOnChange', 'CookieMunchOnAccept', 'CookieMunchOnDecline'];\n\nfunction subscribe(onStoreChange: () => void): () => void {\n if (typeof window === 'undefined') return () => {};\n for (const e of CHANGE_EVENTS) window.addEventListener(e, onStoreChange);\n return () => {\n for (const e of CHANGE_EVENTS) window.removeEventListener(e, onStoreChange);\n };\n}\n\n/**\n * Whether `category` is granted right now — `'preferences'`, `'statistics'`,\n * `'marketing'`, `'necessary'` (always true) or one of your custom category ids — and\n * re-renders when that changes, whatever changed it.\n *\n * `false` until the embed has reported (and during SSR), so gated content never renders\n * ahead of consent. Works inside `<ConsentProvider>` and, when the embed is on the page\n * some other way, without one.\n *\n * const analytics = useConsentValue('statistics');\n */\nexport function useConsentValue(category: string): boolean {\n const ctx = useContext(ConsentContext);\n const standalone = useSyncExternalStore(\n subscribe,\n () => (typeof window === 'undefined' ? false : isGranted(window.CookieMunch?.consent, category)),\n () => false,\n );\n if (ctx) return ctx.ready ? isGranted(ctx.consent, category) : category === 'necessary';\n return standalone;\n}\n\n/**\n * {@link consentCookie} for a component's lifetime: the cookie is written while `category`\n * is granted and removed when it is not. Pass a stable `value` (or a lazy function); the\n * subscription is re-created when `name`, `category`, `value` or an option changes.\n *\n * useConsentCookie('affiliate_id', 'marketing', ref, { maxAgeDays: 30 });\n */\nexport function useConsentCookie(\n name: string,\n category: string,\n value: string | (() => string),\n opts: ConsentCookieOptions = {},\n): void {\n const { maxAgeDays, path, domain, sameSite, secure } = opts;\n useEffect(\n () => consentCookie(name, category, value, { maxAgeDays, path, domain, sameSite, secure }),\n [name, category, value, maxAgeDays, path, domain, sameSite, secure],\n );\n}\n","import { useCallback, useState, type MouseEvent, type ReactNode } from 'react';\nimport { isRightsLinkUrl } from './helpers.js';\n\n/** What `mint` may resolve to: the mint response from `POST /v1/sites/{cbid}/rights-links`, or just its `url`. */\nexport type MintedRightsLink = string | { url: string; customDomain?: string | null };\n\nexport interface RightsLinkProps {\n /**\n * Mints a single-use account link for the signed-in person — a server action (or an endpoint\n * you call) that holds a `dsar:rights-links` key and calls `POST /v1/sites/{cbid}/rights-links`.\n * Never put the key in the browser. Called on click, not on render: links are single-use and\n * expire (15 minutes by default), so one minted per page view would mostly go to waste.\n */\n mint: () => Promise<MintedRightsLink>;\n /** Where the link goes before a mint, and when one fails: the plain hosted form (the email-code flow), e.g. `https://cookiemunch.net/r/<cbid>`. */\n fallbackHref?: string;\n children?: ReactNode;\n className?: string;\n /** Called when a mint fails or returns a URL that is not a rights link, before falling back. */\n onError?: (error: Error) => void;\n}\n\n/**\n * \"Your privacy rights\" for a signed-in person: on click it mints an account link (their email is\n * filled in and locked, the email-code step skipped) and opens it. Plain anchor markup, so it\n * renders the same on the server and the client.\n */\nexport function RightsLink({ mint, fallbackHref, children = 'Your privacy rights', className, onError }: RightsLinkProps) {\n const [busy, setBusy] = useState(false);\n const onClick = useCallback(\n async (e: MouseEvent<HTMLAnchorElement>) => {\n // A modified click (new tab, download) keeps the fallback: a minted link is for this tab.\n if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;\n e.preventDefault();\n if (busy) return;\n setBusy(true);\n try {\n const got = await mint();\n const url = typeof got === 'string' ? got : got.url;\n const customDomain = typeof got === 'string' ? undefined : got.customDomain;\n if (!isRightsLinkUrl(url, customDomain)) throw new Error(`not a rights link: ${url}`);\n window.location.assign(url);\n } catch (err) {\n onError?.(err instanceof Error ? err : new Error(String(err)));\n if (fallbackHref) window.location.assign(fallbackHref);\n } finally {\n setBusy(false);\n }\n },\n [busy, mint, fallbackHref, onError],\n );\n return (\n <a href={fallbackHref ?? '#'} className={className} onClick={onClick} aria-busy={busy || undefined}>\n {children}\n </a>\n );\n}\n","import { useEffect, useRef } from 'react';\n\nexport interface CookieDeclarationProps {\n /** Shown when the site has no cookies to list yet (the mount's `data-empty`). */\n emptyText?: string;\n className?: string;\n id?: string;\n}\n\n/**\n * Stable across renders: React rewrites `innerHTML` only when the `__html` string changes,\n * so an empty string that never changes means React never touches what the embed drew.\n */\nconst EMPTY = { __html: '' };\n\n/**\n * The live cookie declaration, for a privacy page in a React / Next.js app (CKM-S-10).\n *\n * Renders `<div data-cc=\"declaration\">` and lets the embed draw the table into it. The\n * embed fills the element whenever it appears — on first load, after a client-side\n * navigation, or before hydration on a server-rendered page — so the element's children\n * belong to the embed, not to React:\n * - `dangerouslySetInnerHTML` with a constant empty string tells React it does not own\n * the children, so it neither hydrates nor replaces them;\n * - `suppressHydrationWarning` covers the one difference React would otherwise report:\n * the server sent an empty element and the embed may already have filled it.\n * After mount it asks the embed to draw this element, in case it was added after load.\n */\nexport function CookieDeclaration({ emptyText, className, id }: CookieDeclarationProps) {\n const ref = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const el = ref.current;\n const api = typeof window !== 'undefined' ? window.CookieMunch : undefined;\n if (el && !el.hasChildNodes()) void api?.renderDeclaration?.(el)?.catch?.(() => {});\n }, []);\n return (\n <div\n ref={ref}\n id={id}\n className={className}\n data-cc=\"declaration\"\n {...(emptyText !== undefined ? { 'data-empty': emptyText } : {})}\n suppressHydrationWarning\n dangerouslySetInnerHTML={EMPTY}\n />\n );\n}\n"],"mappings":";;;AAAA,SAAS,WAAW,QAAQ,gBAAgC;;;ACA5D,SAAS,qBAAqB;AAgBvB,IAAM,gBAA+B;AAAA,EAC1C,WAAW;AAAA,EACX,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,aAAa;AAAA,EACb,eAAe;AAAA,EACf,OAAO;AACT;AAGO,IAAM,iBAAiB,cAA0C,IAAI;;;ADiGnE;AAzHT,IAAM,cAAc;AAEpB,IAAM,YAAY;AAmBlB,IAAM,mBAA6B;AAAA,EACjC,OAAO;AAAA,EACP,SAAS;AAAA,EACT,aAAa;AAAA,EACb,WAAW;AACb;AAOA,SAAS,kBAAkB,MAAc,KAAa,SAAmC;AACvF,QAAM,WAAW,SAAS,eAAe,SAAS;AAClD,MAAI,SAAU;AACd,QAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,SAAO,KAAK;AACZ,SAAO,QAAQ;AACf,SAAO,MAAM;AACb,SAAO,aAAa,aAAa,IAAI;AACrC,MAAI,QAAS,QAAO,aAAa,YAAY,OAAO;AACpD,GAAC,SAAS,QAAQ,SAAS,iBAAiB,YAAY,MAAM;AAChE;AAWO,SAAS,gBAAgB,EAAE,MAAM,MAAM,aAAa,SAAS,SAAS,GAAyB;AACpG,QAAM,S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ACxDA,SAAS,aAAAC,YAAW,UAAAC,eAAc;AAoC9B,gBAAAC,YAAA;AAvBJ,IAAM,QAAQ,EAAE,QAAQ,GAAG;AAepB,SAAS,kBAAkB,EAAE,WAAW,WAAW,GAAG,GAA2B;AACtF,QAAM,MAAMD,QAAuB,IAAI;AACvC,EAAAD,WAAU,MAAM;AACd,UAAM,KAAK,IAAI;AACf,UAAM,MAAM,OAAO,WAAW,cAAc,OAAO,cAAc;AACjE,QAAI,MAAM,CAAC,GAAG,cAAc,EAAG,MAAK,KAAK,oBAAoB,EAAE,GAAG,QAAQ,MAAM;AAAA,IAAC,CAAC;AAAA,EACpF,GAAG,CAAC,CAAC;AACL,SACE,gBAAAE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAQ;AAAA,MACP,GAAI,cAAc,SAAY,EAAE,cAAc,UAAU,IAAI,CAAC;AAAA,MAC9D,0BAAwB;AAAA,MACxB,yBAAyB;AAAA;AAAA,EAC3B;AAEJ;","names":["api","jsx","useContext","useEffect","useContext","useEffect","useState","jsx","useEffect","useRef","jsx"]}
|
|
1
|
+
{"version":3,"sources":["../src/ConsentProvider.tsx","../src/context.ts","../src/useConsent.ts","../src/ConsentGate.tsx","../src/useConsentValue.ts","../src/RightsLink.tsx","../src/CookieDeclaration.tsx","../src/useBannerInset.ts","../src/CookieSettingsLink.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type ReactNode } from 'react';\nimport { ConsentContext, EMPTY_CONSENT, type ConsentContextValue } from './context.js';\nimport type { CookieMunchGlobal, PublicConsent } from './helpers.js';\n\n/** Default CDN location of the base browser embed. */\nconst DEFAULT_SRC = 'https://cdn.cookiemunch.net/consent.js';\n/** The <script> id the embed's bootstrap reads via getElementById. */\nconst SCRIPT_ID = 'CookieMunch';\n\nexport interface ConsentProviderProps {\n /** The Cookie Munch site id (required). Injected as `data-cbid` on the embed. */\n cbid: string;\n /** Embed URL. Defaults to the public CDN. */\n src?: string;\n /** Override the API base the embed beacons to (injected as `data-api`). */\n apiBase?: string;\n children: ReactNode;\n}\n\ninterface Snapshot {\n ready: boolean;\n consent: PublicConsent;\n hasResponse: boolean;\n consented: boolean;\n}\n\nconst INITIAL_SNAPSHOT: Snapshot = {\n ready: false,\n consent: EMPTY_CONSENT,\n hasResponse: false,\n consented: false,\n};\n\n/**\n * Locate the embed's <script> tag, injecting it if it isn't already present.\n * The embed self-bootstraps from the tag's `data-*` attributes and, once ready,\n * assigns `window.CookieMunch`.\n */\nfunction ensureEmbedScript(cbid: string, src: string, apiBase: string | undefined): void {\n const existing = document.getElementById(SCRIPT_ID);\n if (existing) return;\n const script = document.createElement('script');\n script.id = SCRIPT_ID;\n script.async = true;\n script.src = src;\n script.setAttribute('data-cbid', cbid);\n if (apiBase) script.setAttribute('data-api', apiBase);\n (document.head || document.documentElement).appendChild(script);\n}\n\n/**\n * Loads the Cookie Munch browser embed from the CDN at runtime and exposes\n * reactive consent state to descendants — a standalone script-tag SDK wrapper\n * that does NOT bundle the proprietary engine.\n *\n * SSR-safe: no `window`/`document` access during render; the script is injected\n * and the global API resolved only inside an effect. Descendants see an\n * all-denied, not-ready snapshot until the embed reports in.\n */\nexport function ConsentProvider({ cbid, src = DEFAULT_SRC, apiBase, children }: ConsentProviderProps) {\n const apiRef = useRef<CookieMunchGlobal | null>(null);\n const [snap, setSnap] = useState<Snapshot>(INITIAL_SNAPSHOT);\n\n useEffect(() => {\n if (typeof window === 'undefined' || typeof document === 'undefined') return;\n\n let disposed = false;\n let offConsentChange: (() => void) | null = null;\n let pollTimer: ReturnType<typeof setInterval> | null = null;\n\n const sync = (api: CookieMunchGlobal) => {\n if (disposed) return;\n setSnap({\n ready: true,\n consent: api.consent,\n hasResponse: api.hasResponse,\n consented: api.consented,\n });\n };\n\n const bind = (api: CookieMunchGlobal) => {\n if (disposed) return;\n apiRef.current = api;\n sync(api);\n offConsentChange = api.onConsentChange(() => sync(api));\n };\n\n // If the embed is already on the page, reuse it immediately.\n if (window.CookieMunch) {\n bind(window.CookieMunch);\n } else {\n ensureEmbedScript(cbid, src, apiBase);\n // The embed sets window.CookieMunch asynchronously (after its remote-config\n // fetch), so poll until it appears, then bind once.\n pollTimer = setInterval(() => {\n if (window.CookieMunch) {\n if (pollTimer) clearInterval(pollTimer);\n pollTimer = null;\n bind(window.CookieMunch);\n }\n }, 50);\n }\n\n return () => {\n disposed = true;\n if (pollTimer) clearInterval(pollTimer);\n offConsentChange?.();\n apiRef.current = null;\n };\n // Re-bind if the site id / source changes.\n }, [cbid, src, apiBase]);\n\n const api = apiRef.current;\n const value: ConsentContextValue = {\n ready: snap.ready,\n consent: snap.consent,\n hasResponse: snap.hasResponse,\n consented: snap.consented,\n acceptAll: () => api?.submitCustomConsent(true, true, true),\n declineAll: () => api?.submitCustomConsent(false, false, false),\n submitCustomConsent: (p, s, m) => api?.submitCustomConsent(p, s, m),\n withdraw: () => api?.withdraw(),\n show: () => api?.show(),\n renew: () => api?.renew(),\n };\n\n return <ConsentContext.Provider value={value}>{children}</ConsentContext.Provider>;\n}\n","import { createContext } from 'react';\nimport type { PublicConsent } from './helpers.js';\n\nexport interface ConsentContextValue {\n ready: boolean;\n consent: PublicConsent;\n hasResponse: boolean;\n consented: boolean;\n acceptAll(): void;\n declineAll(): void;\n submitCustomConsent(preferences: boolean, statistics: boolean, marketing: boolean): void;\n withdraw(): void;\n show(): void;\n renew(): void;\n}\n\nexport const EMPTY_CONSENT: PublicConsent = {\n necessary: true,\n preferences: false,\n statistics: false,\n marketing: false,\n personalizedAds: false,\n basicAds: false,\n adProfiling: false,\n adMeasurement: false,\n stamp: '',\n};\n\n/** null sentinel => used to detect \"called outside a ConsentProvider\". */\nexport const ConsentContext = createContext<ConsentContextValue | null>(null);\n","import { useContext } from 'react';\nimport { ConsentContext, type ConsentContextValue } from './context.js';\n\nexport type { ConsentContextValue };\n\n/** Access reactive consent state + actions. Must be used within a ConsentProvider. */\nexport function useConsent(): ConsentContextValue {\n const ctx = useContext(ConsentContext);\n if (!ctx) {\n throw new Error('useConsent must be used within a <ConsentProvider>.');\n }\n return ctx;\n}\n","import type { ReactNode } from 'react';\nimport type { Category } from './helpers.js';\nimport { useConsent } from './useConsent.js';\n\nexport interface ConsentGateProps {\n category: Exclude<Category, 'necessary'>;\n children: ReactNode;\n fallback?: ReactNode;\n}\n\n/** Renders children only when the given category is granted (else `fallback`). */\nexport function ConsentGate({ category, children, fallback = null }: ConsentGateProps) {\n const { consent } = useConsent();\n return <>{consent[category] ? children : fallback}</>;\n}\n","import { useContext, useEffect, useSyncExternalStore } from 'react';\nimport { ConsentContext } from './context.js';\nimport { consentCookie, isGranted, type ConsentCookieOptions } from './helpers.js';\n\n/** Window events after which the embed's consent may differ. */\nconst CHANGE_EVENTS = ['CookieMunchOnChange', 'CookieMunchOnAccept', 'CookieMunchOnDecline'];\n\nfunction subscribe(onStoreChange: () => void): () => void {\n if (typeof window === 'undefined') return () => {};\n for (const e of CHANGE_EVENTS) window.addEventListener(e, onStoreChange);\n return () => {\n for (const e of CHANGE_EVENTS) window.removeEventListener(e, onStoreChange);\n };\n}\n\n/**\n * Whether `category` is granted right now — `'preferences'`, `'statistics'`,\n * `'marketing'`, `'necessary'` (always true) or one of your custom category ids — and\n * re-renders when that changes, whatever changed it.\n *\n * `false` until the embed has reported (and during SSR), so gated content never renders\n * ahead of consent. Works inside `<ConsentProvider>` and, when the embed is on the page\n * some other way, without one.\n *\n * const analytics = useConsentValue('statistics');\n */\nexport function useConsentValue(category: string): boolean {\n const ctx = useContext(ConsentContext);\n const standalone = useSyncExternalStore(\n subscribe,\n () => (typeof window === 'undefined' ? false : isGranted(window.CookieMunch?.consent, category)),\n () => false,\n );\n if (ctx) return ctx.ready ? isGranted(ctx.consent, category) : category === 'necessary';\n return standalone;\n}\n\n/**\n * {@link consentCookie} for a component's lifetime: the cookie is written while `category`\n * is granted and removed when it is not. Pass a stable `value` (or a lazy function); the\n * subscription is re-created when `name`, `category`, `value` or an option changes.\n *\n * useConsentCookie('affiliate_id', 'marketing', ref, { maxAgeDays: 30 });\n */\nexport function useConsentCookie(\n name: string,\n category: string,\n value: string | (() => string),\n opts: ConsentCookieOptions = {},\n): void {\n const { maxAgeDays, path, domain, sameSite, secure } = opts;\n useEffect(\n () => consentCookie(name, category, value, { maxAgeDays, path, domain, sameSite, secure }),\n [name, category, value, maxAgeDays, path, domain, sameSite, secure],\n );\n}\n","import { useCallback, useState, type MouseEvent, type ReactNode } from 'react';\nimport { isRightsLinkUrl } from './helpers.js';\n\n/** What `mint` may resolve to: the mint response from `POST /v1/sites/{cbid}/rights-links`, or just its `url`. */\nexport type MintedRightsLink = string | { url: string; customDomain?: string | null };\n\nexport interface RightsLinkProps {\n /**\n * Mints a single-use account link for the signed-in person — a server action (or an endpoint\n * you call) that holds a `dsar:rights-links` key and calls `POST /v1/sites/{cbid}/rights-links`.\n * Never put the key in the browser. Called on click, not on render: links are single-use and\n * expire (15 minutes by default), so one minted per page view would mostly go to waste.\n */\n mint: () => Promise<MintedRightsLink>;\n /** Where the link goes before a mint, and when one fails: the plain hosted form (the email-code flow), e.g. `https://cookiemunch.net/r/<cbid>`. */\n fallbackHref?: string;\n children?: ReactNode;\n className?: string;\n /** Called when a mint fails or returns a URL that is not a rights link, before falling back. */\n onError?: (error: Error) => void;\n}\n\n/**\n * \"Your privacy rights\" for a signed-in person: on click it mints an account link (their email is\n * filled in and locked, the email-code step skipped) and opens it. Plain anchor markup, so it\n * renders the same on the server and the client.\n */\nexport function RightsLink({ mint, fallbackHref, children = 'Your privacy rights', className, onError }: RightsLinkProps) {\n const [busy, setBusy] = useState(false);\n const onClick = useCallback(\n async (e: MouseEvent<HTMLAnchorElement>) => {\n // A modified click (new tab, download) keeps the fallback: a minted link is for this tab.\n if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;\n e.preventDefault();\n if (busy) return;\n setBusy(true);\n try {\n const got = await mint();\n const url = typeof got === 'string' ? got : got.url;\n const customDomain = typeof got === 'string' ? undefined : got.customDomain;\n if (!isRightsLinkUrl(url, customDomain)) throw new Error(`not a rights link: ${url}`);\n window.location.assign(url);\n } catch (err) {\n onError?.(err instanceof Error ? err : new Error(String(err)));\n if (fallbackHref) window.location.assign(fallbackHref);\n } finally {\n setBusy(false);\n }\n },\n [busy, mint, fallbackHref, onError],\n );\n return (\n <a href={fallbackHref ?? '#'} className={className} onClick={onClick} aria-busy={busy || undefined}>\n {children}\n </a>\n );\n}\n","import { useEffect, useRef } from 'react';\n\nexport interface CookieDeclarationProps {\n /** Shown when the site has no cookies to list yet (the mount's `data-empty`). */\n emptyText?: string;\n className?: string;\n id?: string;\n}\n\n/**\n * Stable across renders: React rewrites `innerHTML` only when the `__html` string changes,\n * so an empty string that never changes means React never touches what the embed drew.\n */\nconst EMPTY = { __html: '' };\n\n/**\n * The live cookie declaration, for a privacy page in a React / Next.js app (CKM-S-10).\n *\n * Renders `<div data-cc=\"declaration\">` and lets the embed draw the table into it. The\n * embed fills the element whenever it appears — on first load, after a client-side\n * navigation, or before hydration on a server-rendered page — so the element's children\n * belong to the embed, not to React:\n * - `dangerouslySetInnerHTML` with a constant empty string tells React it does not own\n * the children, so it neither hydrates nor replaces them;\n * - `suppressHydrationWarning` covers the one difference React would otherwise report:\n * the server sent an empty element and the embed may already have filled it.\n * After mount it asks the embed to draw this element, in case it was added after load.\n */\nexport function CookieDeclaration({ emptyText, className, id }: CookieDeclarationProps) {\n const ref = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const el = ref.current;\n const api = typeof window !== 'undefined' ? window.CookieMunch : undefined;\n if (el && !el.hasChildNodes()) void api?.renderDeclaration?.(el)?.catch?.(() => {});\n }, []);\n return (\n <div\n ref={ref}\n id={id}\n className={className}\n data-cc=\"declaration\"\n {...(emptyText !== undefined ? { 'data-empty': emptyText } : {})}\n suppressHydrationWarning\n dangerouslySetInnerHTML={EMPTY}\n />\n );\n}\n","import { useSyncExternalStore } from 'react';\n\nfunction subscribe(onStoreChange: () => void): () => void {\n if (typeof window === 'undefined') return () => {};\n window.addEventListener('fd:layout', onStoreChange);\n return () => window.removeEventListener('fd:layout', onStoreChange);\n}\n\nfunction read(edge: 'bottom' | 'top'): number {\n if (typeof document === 'undefined') return 0;\n const v = document.documentElement.style.getPropertyValue(`--cookiemunch-inset-${edge}`);\n const n = parseFloat(v);\n return Number.isFinite(n) ? n : 0;\n}\n\n/**\n * How many pixels of the viewport's bottom (or top) edge the consent bar covers right now — 0\n * when no bar shows — re-rendering on every change. For floating UI the CSS variable\n * `--cookiemunch-inset-bottom` (or the vendor-neutral `--fd-safe-bottom`) does the same job\n * without a render; use this when the offset is computed in JavaScript.\n *\n * const inset = useBannerInset();\n * <ChatButton style={{ bottom: 20 + inset }} />\n *\n * 0 during SSR. Works with or without `<ConsentProvider>`.\n */\nexport function useBannerInset(edge: 'bottom' | 'top' = 'bottom'): number {\n return useSyncExternalStore(subscribe, () => read(edge), () => 0);\n}\n","import type { ReactNode } from 'react';\n\nexport interface CookieSettingsLinkProps {\n children?: ReactNode;\n className?: string;\n /** Where the link points before the embed has loaded (or with scripts off). Default `#cookie-settings`. */\n href?: string;\n}\n\n/**\n * \"Cookie settings\": reopens the visitor's consent choices. It is plain markup — an anchor with\n * `data-cc=\"show-settings\"`, which the embed's own click listener turns into\n * `CookieMunch.showSettings()` — so it renders identically on the server and the client, needs no\n * `<ConsentProvider>`, and opens the panel exactly once (no second handler of its own).\n */\nexport function CookieSettingsLink({ children = 'Cookie settings', className, href = '#cookie-settings' }: CookieSettingsLinkProps) {\n return (\n <a href={href} className={className} data-cc=\"show-settings\">\n {children}\n </a>\n );\n}\n"],"mappings":";;;AAAA,SAAS,WAAW,QAAQ,gBAAgC;;;ACA5D,SAAS,qBAAqB;AAgBvB,IAAM,gBAA+B;AAAA,EAC1C,WAAW;AAAA,EACX,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,aAAa;AAAA,EACb,e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AC9CA,SAAS,wBAAAC,6BAA4B;AAErC,SAASC,WAAU,eAAuC;AACxD,MAAI,OAAO,WAAW,YAAa,QAAO,MAAM;AAAA,EAAC;AACjD,SAAO,iBAAiB,aAAa,aAAa;AAClD,SAAO,MAAM,OAAO,oBAAoB,aAAa,aAAa;AACpE;AAEA,SAAS,KAAK,MAAgC;AAC5C,MAAI,OAAO,aAAa,YAAa,QAAO;AAC5C,QAAM,IAAI,SAAS,gBAAgB,MAAM,iBAAiB,uBAAuB,IAAI,EAAE;AACvF,QAAM,IAAI,WAAW,CAAC;AACtB,SAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AAaO,SAAS,eAAe,OAAyB,UAAkB;AACxE,SAAOD,sBAAqBC,YAAW,MAAM,KAAK,IAAI,GAAG,MAAM,CAAC;AAClE;;;ACXI,gBAAAC,YAAA;AAFG,SAAS,mBAAmB,EAAE,WAAW,mBAAmB,WAAW,OAAO,mBAAmB,GAA4B;AAClI,SACE,gBAAAA,KAAC,OAAE,MAAY,WAAsB,WAAQ,iBAC1C,UACH;AAEJ;","names":["api","jsx","useContext","useEffect","useContext","useEffect","useState","jsx","useEffect","useRef","jsx","useSyncExternalStore","subscribe","jsx"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ConsentContextValue, ConsentGate, ConsentGateProps, ConsentProvider, ConsentProviderProps, CookieDeclaration, CookieDeclarationProps, MintedRightsLink, RightsLink, RightsLinkProps, useConsent, useConsentCookie, useConsentValue } from './client.js';
|
|
1
|
+
export { ConsentContextValue, ConsentGate, ConsentGateProps, ConsentProvider, ConsentProviderProps, CookieDeclaration, CookieDeclarationProps, CookieSettingsLink, CookieSettingsLinkProps, MintedRightsLink, RightsLink, RightsLinkProps, useBannerInset, useConsent, useConsentCookie, useConsentValue } from './client.js';
|
|
2
2
|
export { CONSENT_COOKIE_NAME, Category, ConsentCookieOptions, ConsentCookieState, CookieMunchGlobal, PublicConsent, consentCookie, isGranted, isRightsLinkUrl, parseConsentCookie } from './helpers.js';
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
ConsentGate,
|
|
6
6
|
useConsentValue,
|
|
7
7
|
useConsentCookie,
|
|
8
|
+
useBannerInset,
|
|
8
9
|
RightsLink,
|
|
9
|
-
CookieDeclaration
|
|
10
|
+
CookieDeclaration,
|
|
11
|
+
CookieSettingsLink
|
|
10
12
|
} from "./client.js";
|
|
11
13
|
import {
|
|
12
14
|
consentCookie,
|
|
@@ -20,11 +22,13 @@ export {
|
|
|
20
22
|
ConsentGate,
|
|
21
23
|
ConsentProvider,
|
|
22
24
|
CookieDeclaration,
|
|
25
|
+
CookieSettingsLink,
|
|
23
26
|
RightsLink,
|
|
24
27
|
consentCookie,
|
|
25
28
|
isGranted,
|
|
26
29
|
isRightsLinkUrl,
|
|
27
30
|
parseConsentCookie,
|
|
31
|
+
useBannerInset,
|
|
28
32
|
useConsent,
|
|
29
33
|
useConsentCookie,
|
|
30
34
|
useConsentValue
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// No directive here, only re-exports. On the React Server layer Next turns the client.js names\n// into client references and leaves the helpers as plain functions, so one root import —\n// `import { ConsentProvider, isGranted } from '@cookiemunch/react'` — works in a Server Component.\nexport {\n ConsentProvider,\n type ConsentProviderProps,\n useConsent,\n type ConsentContextValue,\n ConsentGate,\n type ConsentGateProps,\n useConsentValue,\n useConsentCookie,\n RightsLink,\n type RightsLinkProps,\n type MintedRightsLink,\n CookieDeclaration,\n type CookieDeclarationProps,\n} from './client.js';\nexport {\n consentCookie,\n isGranted,\n type ConsentCookieOptions,\n CONSENT_COOKIE_NAME,\n parseConsentCookie,\n isRightsLinkUrl,\n type ConsentCookieState,\n type Category,\n type PublicConsent,\n type CookieMunchGlobal,\n} from './helpers.js';\n"],"mappings":";AAGA;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// No directive here, only re-exports. On the React Server layer Next turns the client.js names\n// into client references and leaves the helpers as plain functions, so one root import —\n// `import { ConsentProvider, isGranted } from '@cookiemunch/react'` — works in a Server Component.\nexport {\n ConsentProvider,\n type ConsentProviderProps,\n useConsent,\n type ConsentContextValue,\n ConsentGate,\n type ConsentGateProps,\n useConsentValue,\n useConsentCookie,\n useBannerInset,\n RightsLink,\n type RightsLinkProps,\n type MintedRightsLink,\n CookieDeclaration,\n type CookieDeclarationProps,\n CookieSettingsLink,\n type CookieSettingsLinkProps,\n} from './client.js';\nexport {\n consentCookie,\n isGranted,\n type ConsentCookieOptions,\n CONSENT_COOKIE_NAME,\n parseConsentCookie,\n isRightsLinkUrl,\n type ConsentCookieState,\n type Category,\n type PublicConsent,\n type CookieMunchGlobal,\n} from './helpers.js';\n"],"mappings":";AAGA;AAAA,EACE;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EAEA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;","names":[]}
|