@molecule/app-cookie-banner-angular 0.0.0-stage → 0.0.1-stage

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Angular GDPR cookie consent banner — the counterpart of
3
+ * `@molecule/app-cookie-banner-react`: the same props and the same DOM for the
4
+ * same input.
5
+ *
6
+ * Exports `<CookieBanner>` and the `CookieCategory` type. Two modes: Accept /
7
+ * Reject only, or per-category switches behind "Customize" when `categories`
8
+ * are supplied.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { Component } from '@angular/core'
13
+ * import { CookieBanner } from '@molecule/app-cookie-banner-angular'
14
+ *
15
+ * @Component({
16
+ * selector: 'app-consent',
17
+ * standalone: true,
18
+ * imports: [CookieBanner],
19
+ * template: `
20
+ * <div
21
+ * mol-cookie-banner
22
+ * [visible]="!consentGiven"
23
+ * [policyHref]="'/privacy'"
24
+ * [categories]="categories"
25
+ * [onAcceptAll]="acceptAll"
26
+ * [onRejectAll]="rejectAll"
27
+ * [onSave]="save"
28
+ * [onDismiss]="dismiss"
29
+ * ></div>
30
+ * `,
31
+ * })
32
+ * export class Consent {
33
+ * consentGiven = false
34
+ * categories = [
35
+ * { id: 'essential', label: 'Essential', required: true },
36
+ * { id: 'analytics', label: 'Analytics', defaultEnabled: false },
37
+ * ]
38
+ * acceptAll = (): void => saveConsent('all')
39
+ * rejectAll = (): void => saveConsent('essential')
40
+ * save = (enabled: Record<string, boolean>): void => saveConsent(enabled)
41
+ * dismiss = (): void => {
42
+ * this.consentGiven = true
43
+ * }
44
+ * }
45
+ * ```
46
+ *
47
+ * @remarks
48
+ * The banner is UI-only — it stores nothing. `onAcceptAll` / `onRejectAll`
49
+ * receive NO arguments (derive "all on"/"essential only" yourself); only
50
+ * `onSave` receives the per-category `Record<string, boolean>`, and the
51
+ * "Save preferences" button renders only when `categories` AND `onSave` are
52
+ * provided and the user opened "Customize". Category toggle state is
53
+ * captured from `categories` on first render — later input changes do not
54
+ * reset it. Visibility is controlled: keep `visible` false once consent is
55
+ * stored (the host element leaves the DOM, as React renders null). Text uses
56
+ * `cookieBanner.*` i18n keys (companion bond:
57
+ * `@molecule/app-locales-cookie-banner`); `title`/`description`/category
58
+ * labels you pass in should already be translated.
59
+ *
60
+ * Node props are projected content or plain text: `title` renders inside the
61
+ * `<h3>` (as `[slot=title]` content or as a string input), `description`
62
+ * inside the `<p>` (`[slot=description]`), and a category's `label` /
63
+ * `description` are strings or projected templates.
64
+ *
65
+ * @module
66
+ */
67
+ export * from './cookie-banner.component.js';
68
+ export * from './types.js';
69
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,cAAc,8BAA8B,CAAA;AAC5C,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Angular GDPR cookie consent banner — the counterpart of
3
+ * `@molecule/app-cookie-banner-react`: the same props and the same DOM for the
4
+ * same input.
5
+ *
6
+ * Exports `<CookieBanner>` and the `CookieCategory` type. Two modes: Accept /
7
+ * Reject only, or per-category switches behind "Customize" when `categories`
8
+ * are supplied.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { Component } from '@angular/core'
13
+ * import { CookieBanner } from '@molecule/app-cookie-banner-angular'
14
+ *
15
+ * @Component({
16
+ * selector: 'app-consent',
17
+ * standalone: true,
18
+ * imports: [CookieBanner],
19
+ * template: `
20
+ * <div
21
+ * mol-cookie-banner
22
+ * [visible]="!consentGiven"
23
+ * [policyHref]="'/privacy'"
24
+ * [categories]="categories"
25
+ * [onAcceptAll]="acceptAll"
26
+ * [onRejectAll]="rejectAll"
27
+ * [onSave]="save"
28
+ * [onDismiss]="dismiss"
29
+ * ></div>
30
+ * `,
31
+ * })
32
+ * export class Consent {
33
+ * consentGiven = false
34
+ * categories = [
35
+ * { id: 'essential', label: 'Essential', required: true },
36
+ * { id: 'analytics', label: 'Analytics', defaultEnabled: false },
37
+ * ]
38
+ * acceptAll = (): void => saveConsent('all')
39
+ * rejectAll = (): void => saveConsent('essential')
40
+ * save = (enabled: Record<string, boolean>): void => saveConsent(enabled)
41
+ * dismiss = (): void => {
42
+ * this.consentGiven = true
43
+ * }
44
+ * }
45
+ * ```
46
+ *
47
+ * @remarks
48
+ * The banner is UI-only — it stores nothing. `onAcceptAll` / `onRejectAll`
49
+ * receive NO arguments (derive "all on"/"essential only" yourself); only
50
+ * `onSave` receives the per-category `Record<string, boolean>`, and the
51
+ * "Save preferences" button renders only when `categories` AND `onSave` are
52
+ * provided and the user opened "Customize". Category toggle state is
53
+ * captured from `categories` on first render — later input changes do not
54
+ * reset it. Visibility is controlled: keep `visible` false once consent is
55
+ * stored (the host element leaves the DOM, as React renders null). Text uses
56
+ * `cookieBanner.*` i18n keys (companion bond:
57
+ * `@molecule/app-locales-cookie-banner`); `title`/`description`/category
58
+ * labels you pass in should already be translated.
59
+ *
60
+ * Node props are projected content or plain text: `title` renders inside the
61
+ * `<h3>` (as `[slot=title]` content or as a string input), `description`
62
+ * inside the `<p>` (`[slot=description]`), and a category's `label` /
63
+ * `description` are strings or projected templates.
64
+ *
65
+ * @module
66
+ */
67
+ export * from './cookie-banner.component.js';
68
+ export * from './types.js';
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,cAAc,8BAA8B,CAAA;AAC5C,cAAc,YAAY,CAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * DOM helpers for the projected node props of the Angular cookie-consent
3
+ * banner.
4
+ *
5
+ * React renders a node prop bare inside the element that holds it (`<h3>` for
6
+ * the title, `<p>` for the description). Angular content projection needs an
7
+ * always-mounted `<ng-content>` capture point, so each field renders through a
8
+ * pair of capture spans — one for the plain input's text and one for the
9
+ * projected nodes — and {@link applyNodeLayout} keeps whichever React would
10
+ * have rendered, unwrapping it into the parent element.
11
+ *
12
+ * @module
13
+ */
14
+ /**
15
+ * Whether an `<ng-content>` wrapper captured any element or text node.
16
+ *
17
+ * @param el - The wrapper element.
18
+ * @returns True when at least one projected node exists.
19
+ */
20
+ export declare const hasNodes: (el: Element | undefined | null) => boolean;
21
+ /**
22
+ * Reconciles a field's pair of capture spans with React's DOM: whichever of the
23
+ * two React would render is unwrapped into the parent element (so no wrapper
24
+ * element appears), and the other is removed.
25
+ *
26
+ * @param fallback - The span holding the plain input's text.
27
+ * @param slot - The span holding the projected node content.
28
+ * @param hasSlotContent - Whether the caller projected node content.
29
+ */
30
+ export declare const applyNodeLayout: (fallback: HTMLElement | undefined, slot: HTMLElement | undefined, hasSlotContent: boolean) => void;
31
+ //# sourceMappingURL=slot-dom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slot-dom.d.ts","sourceRoot":"","sources":["../src/slot-dom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,IAAI,OAAO,GAAG,SAAS,GAAG,IAAI,KAAG,OAOzD,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,WAAW,GAAG,SAAS,EACjC,MAAM,WAAW,GAAG,SAAS,EAC7B,gBAAgB,OAAO,KACtB,IAeF,CAAA"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * DOM helpers for the projected node props of the Angular cookie-consent
3
+ * banner.
4
+ *
5
+ * React renders a node prop bare inside the element that holds it (`<h3>` for
6
+ * the title, `<p>` for the description). Angular content projection needs an
7
+ * always-mounted `<ng-content>` capture point, so each field renders through a
8
+ * pair of capture spans — one for the plain input's text and one for the
9
+ * projected nodes — and {@link applyNodeLayout} keeps whichever React would
10
+ * have rendered, unwrapping it into the parent element.
11
+ *
12
+ * @module
13
+ */
14
+ /**
15
+ * Whether an `<ng-content>` wrapper captured any element or text node.
16
+ *
17
+ * @param el - The wrapper element.
18
+ * @returns True when at least one projected node exists.
19
+ */
20
+ export const hasNodes = (el) => {
21
+ if (!el)
22
+ return false;
23
+ for (const node of Array.from(el.childNodes)) {
24
+ if (node.nodeType === Node.ELEMENT_NODE)
25
+ return true;
26
+ if (node.nodeType === Node.TEXT_NODE && (node.textContent ?? '').trim())
27
+ return true;
28
+ }
29
+ return false;
30
+ };
31
+ /**
32
+ * Reconciles a field's pair of capture spans with React's DOM: whichever of the
33
+ * two React would render is unwrapped into the parent element (so no wrapper
34
+ * element appears), and the other is removed.
35
+ *
36
+ * @param fallback - The span holding the plain input's text.
37
+ * @param slot - The span holding the projected node content.
38
+ * @param hasSlotContent - Whether the caller projected node content.
39
+ */
40
+ export const applyNodeLayout = (fallback, slot, hasSlotContent) => {
41
+ if (!fallback || !slot)
42
+ return;
43
+ const parent = fallback.parentNode;
44
+ if (!parent)
45
+ return;
46
+ if (hasSlotContent) {
47
+ // React renders only the node: drop the text capture point, unwrap the node.
48
+ if (fallback.isConnected)
49
+ parent.removeChild(fallback);
50
+ while (slot.firstChild)
51
+ parent.insertBefore(slot.firstChild, slot);
52
+ if (slot.isConnected)
53
+ parent.removeChild(slot);
54
+ return;
55
+ }
56
+ // React renders only the input text: unwrap it, drop both capture points.
57
+ while (fallback.firstChild)
58
+ parent.insertBefore(fallback.firstChild, fallback);
59
+ if (fallback.isConnected)
60
+ parent.removeChild(fallback);
61
+ if (slot.isConnected)
62
+ parent.removeChild(slot);
63
+ };
64
+ //# sourceMappingURL=slot-dom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slot-dom.js","sourceRoot":"","sources":["../src/slot-dom.ts"],"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IAC9E,IAAI,QAAQ,CAAC,WAAW;QAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;IACtD,IAAI,IAAI,CAAC,WAAW;QAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;AAChD,CAAC,CAAA"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Types of `@molecule/app-cookie-banner-angular` — the Angular counterpart of
3
+ * `@molecule/app-cookie-banner-react`, same props and DOM.
4
+ *
5
+ * @module
6
+ */
7
+ import type { TemplateRef } from '@angular/core';
8
+ /**
9
+ * A React-node-valued field: plain text as it is, or a projected template (the
10
+ * Angular representation of a node value inside a data prop). Module-internal:
11
+ * React's package exports no such helper type.
12
+ */
13
+ type NodeValue = TemplateRef<unknown> | string | number | boolean | null | undefined;
14
+ /** Describes a single cookie category offered in the granular consent UI. */
15
+ export interface CookieCategory {
16
+ /** Stable category id (also the key of the consent map). */
17
+ id: string;
18
+ /** Display label — text, or a projected template. */
19
+ label: NodeValue;
20
+ /** Optional explanation — text, or a projected template. */
21
+ description?: NodeValue;
22
+ /** Whether this category is required (always on). */
23
+ required?: boolean;
24
+ /** Initial enabled state. */
25
+ defaultEnabled?: boolean;
26
+ }
27
+ /**
28
+ * Props accepted by {@link CookieBanner} — the same props
29
+ * `@molecule/app-cookie-banner-react` accepts. Node props (`title`,
30
+ * `description`) are projected content in Angular (an input cannot carry a
31
+ * node), so they are typed `unknown`: pass them in the host template, not as
32
+ * values. `visible` defaults to true at read time.
33
+ */
34
+ export interface CookieBannerProps {
35
+ /** Cookie categories to offer (omit for a simple accept/reject banner). */
36
+ categories?: CookieCategory[];
37
+ /** Called when accept-all is clicked. */
38
+ onAcceptAll?: () => void;
39
+ /** Called when reject-non-essential is clicked. */
40
+ onRejectAll?: () => void;
41
+ /** Called when "Save preferences" is clicked. */
42
+ onSave?: (enabled: Record<string, boolean>) => void;
43
+ /** Optional title, projected as `[slot=title]` content or passed as text. */
44
+ title?: unknown;
45
+ /** Optional description, projected as `[slot=description]` content or passed as text. */
46
+ description?: unknown;
47
+ /** Privacy policy link URL. */
48
+ policyHref?: string;
49
+ /** Whether the banner is visible (controlled). */
50
+ visible?: boolean;
51
+ /** Called when dismissed via Save / Accept / Reject. */
52
+ onDismiss?: () => void;
53
+ /** Extra classes. */
54
+ className?: string;
55
+ }
56
+ export {};
57
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD;;;;GAIG;AACH,KAAK,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AAEpF,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,EAAE,EAAE,MAAM,CAAA;IACV,qDAAqD;IACrD,KAAK,EAAE,SAAS,CAAA;IAChB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6BAA6B;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;IAC7B,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,iDAAiD;IACjD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IACnD,6EAA6E;IAC7E,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,yFAAyF;IACzF,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kDAAkD;IAClD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Types of `@molecule/app-cookie-banner-angular` — the Angular counterpart of
3
+ * `@molecule/app-cookie-banner-react`, same props and DOM.
4
+ *
5
+ * @module
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@molecule/app-cookie-banner-angular",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1-stage",
4
+ "description": "GDPR / cookie consent banner with accept/reject + per-category controls",
5
+ "homepage": "https://www.molecule.dev/packages/app-cookie-banner-angular",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "ngc",
21
+ "dev": "ngc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "cookie-banner",
28
+ "angular"
29
+ ],
30
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
31
+ "license": "Apache-2.0",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/molecule-dev/molecule.git",
35
+ "directory": "packages/app/features/cookie-banner-angular"
36
+ },
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "peerDependencies": {
45
+ "@angular/common": "^22.0.0",
46
+ "@angular/core": "^22.0.0",
47
+ "@angular/platform-browser": "^22.0.0",
48
+ "@molecule/app-angular": "^3.5.0",
49
+ "@molecule/app-ui": "^1.0.1",
50
+ "@molecule/app-ui-angular": "^1.1.0"
51
+ },
52
+ "devDependencies": {
53
+ "@angular/common": "22.2.3",
54
+ "@angular/compiler": "22.2.3",
55
+ "@angular/compiler-cli": "22.2.3",
56
+ "@angular/core": "22.2.3",
57
+ "@angular/platform-browser": "22.2.3",
58
+ "@molecule/app-angular": "3.7.1",
59
+ "@molecule/app-framework-conformance": "0.0.0",
60
+ "@molecule/app-i18n": "1.2.2",
61
+ "@molecule/app-icons": "1.0.4",
62
+ "@molecule/app-ui": "1.4.0",
63
+ "@molecule/app-ui-angular": "1.2.0",
64
+ "@types/node": "26.6.5",
65
+ "jsdom": "30.1.3",
66
+ "rxjs": "7.8.2",
67
+ "typescript": "6.0.3",
68
+ "vitest": "4.1.12",
69
+ "zone.js": "0.16.3"
70
+ }
71
+ }