@molecule/app-listing-card-angular 1.1.0 → 1.2.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/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-11-16T09:14:07.957Z
6
+ Generated: 2026-11-22T16:18:17.884Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-listing-card-angular
@@ -13,6 +13,7 @@ Angular product / property / listing card primitives.
13
13
  Exports:
14
14
 
15
15
  - `<ListingCard>` — outer Card shell (`div[mol-listing-card]`). Props:
16
+ `toggle?` (a counted server-backed action, rendered after the content),
16
17
  `onClick?`, `className?`, `dataMolId?`; children are projected content.
17
18
  - `<ListingCardMedia>` — top image slot (`div[mol-listing-card-media]`).
18
19
  Props: `src?`, `alt?`, node children (custom media node), `aspect?`
@@ -48,6 +49,14 @@ import {
48
49
  ListingGrid,
49
50
  } from '@molecule/app-listing-card-angular'
50
51
 
52
+ interface Listing {
53
+ id: string
54
+ name: string
55
+ location: string
56
+ imageUrl: string
57
+ price: number
58
+ }
59
+
51
60
  @Component({
52
61
  selector: 'app-listings',
53
62
  standalone: true,
@@ -71,8 +80,18 @@ import {
71
80
  })
72
81
  export class Listings {
73
82
  items: Listing[] = []
83
+ item: Listing = {
84
+ id: 'l1',
85
+ name: 'Sea-view loft',
86
+ location: 'Lisbon',
87
+ imageUrl: '/listings/loft.jpg',
88
+ price: 120,
89
+ }
74
90
  open(id: string): () => void {
75
- return () => this.navigate(`/listings/${id}`)
91
+ return () => console.log('open listing', id)
92
+ }
93
+ readonly save = (id: string): void => {
94
+ console.log('save listing', id)
76
95
  }
77
96
  }
78
97
  ```
@@ -91,6 +110,43 @@ npm install @molecule/app-listing-card-angular @angular/common @angular/core @an
91
110
 
92
111
  ### Interfaces
93
112
 
113
+ #### `ListingCardToggleProps`
114
+
115
+ A server-backed card action with the total number of people who selected it.
116
+
117
+ ```typescript
118
+ interface ListingCardToggleProps {
119
+ /** The pressed state and count from the same loaded record. */
120
+ value: { pressed: boolean; count: number }
121
+ /** Saves the desired state and returns the server-confirmed state and count together. */
122
+ commit: (desired: boolean) => Promise<ListingCardToggleProps['value']>
123
+ /** Label when the displayed value is true. */
124
+ activeLabel: string | number
125
+ /** Label when the displayed value is false. */
126
+ inactiveLabel: string | number
127
+ /** Receives a failed save after the toggle put the last confirmed state and count back. */
128
+ onError?: (error: unknown) => void
129
+ /** Overrides the button's default `data-mol-id`. */
130
+ dataMolId?: string
131
+ /** Button variant (defaults to `'solid'` while pressed, `'outline'` otherwise). */
132
+ variant?: ButtonVariant
133
+ /** Button color. */
134
+ color?: ColorVariant
135
+ /** Button size. */
136
+ size?: ButtonSize
137
+ /** Whether the button stretches to fill its container. */
138
+ fullWidth?: boolean
139
+ /** Disables the button (permissions, never a pending save). */
140
+ disabled?: boolean
141
+ /** Extra classes on the button. */
142
+ className?: string
143
+ /** `data-testid` for the button. */
144
+ testId?: string
145
+ /** `data-mol-id` automation id; wins over `dataMolId` (React's precedence). */
146
+ automationId?: string
147
+ }
148
+ ```
149
+
94
150
  #### `ListingCardProps`
95
151
 
96
152
  Props accepted by {@link ListingCard} — the same props
@@ -102,6 +158,8 @@ typed `unknown`: pass them in the host template, not as values.
102
158
  interface ListingCardProps {
103
159
  /** Slots — projected as the element's default content. */
104
160
  children?: unknown
161
+ /** Renders a counted native toggle after the content, outside any links in the content. */
162
+ toggle?: ListingCardToggleProps
105
163
  /** Called on any click on the card (React's `onClick`, with the click event). */
106
164
  onClick?: (event: MouseEvent) => void
107
165
  /** Extra classes on the outer Card. */
@@ -560,19 +618,27 @@ ClassMap classes (`cm.card({ variant: 'elevated' })` + `cm.cardPadding('md')`
560
618
  `data-mol-id` and the click handler live on it. The children are projected
561
619
  content, stacked vertically in the inner `div` (`cm.stack(0)`).
562
620
 
621
+ A supplied `toggle` renders the counted card action after the content,
622
+ outside any links in it — React's `<ListingCardActions><ListingCardToggle>`
623
+ pair, in the same DOM order.
624
+
563
625
  ```typescript
564
626
  @Component({
565
627
  selector: 'div[mol-listing-card]',
566
628
  standalone: true,
567
- inputs: ['onClick', 'className', 'dataMolId'],
629
+ imports: [ListingCardActions, ListingCardToggle],
630
+ inputs: ['toggle', 'onClick', 'className', 'dataMolId'],
568
631
  host: {
569
632
  '[class]': 'classes()',
570
633
  '[attr.data-mol-id]': 'dataMolId ?? null',
571
634
  '(click)': 'handleClick($event)',
572
635
  },
573
- template: `<div [class]="stackClasses()"><ng-content></ng-content></div>`,
636
+ // prettier-ignore
637
+ template: `<div [class]="stackClasses()"><ng-content></ng-content>@if (toggle) {<div mol-listing-card-actions><button mol-listing-card-toggle [value]="toggle.value" [commit]="toggle.commit" [activeLabel]="toggle.activeLabel" [inactiveLabel]="toggle.inactiveLabel" [onError]="toggle.onError" [dataMolId]="toggle.dataMolId" [variant]="toggle.variant" [color]="toggle.color" [size]="toggle.size" [fullWidth]="toggle.fullWidth ?? false" [disabled]="toggle.disabled ?? false" [className]="toggle.className" [testId]="toggle.testId" [automationId]="toggle.automationId"></button></div>}</div>`,
574
638
  })
575
639
  export class ListingCard {
640
+ /** Renders a counted native toggle after the content, outside any links in the content. */
641
+ toggle?: ListingCardProps['toggle']
576
642
  /** Click handler; receives the DOM click event (React's `onClick`). */
577
643
  onClick?: ListingCardProps['onClick']
578
644
  /** Extra classes on the outer Card. */
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Exports:
5
5
  * - `<ListingCard>` — outer Card shell (`div[mol-listing-card]`). Props:
6
+ * `toggle?` (a counted server-backed action, rendered after the content),
6
7
  * `onClick?`, `className?`, `dataMolId?`; children are projected content.
7
8
  * - `<ListingCardMedia>` — top image slot (`div[mol-listing-card-media]`).
8
9
  * Props: `src?`, `alt?`, node children (custom media node), `aspect?`
@@ -46,6 +47,14 @@
46
47
  * ListingGrid,
47
48
  * } from '@molecule/app-listing-card-angular'
48
49
  *
50
+ * interface Listing {
51
+ * id: string
52
+ * name: string
53
+ * location: string
54
+ * imageUrl: string
55
+ * price: number
56
+ * }
57
+ *
49
58
  * @Component({
50
59
  * selector: 'app-listings',
51
60
  * standalone: true,
@@ -72,8 +81,18 @@
72
81
  * })
73
82
  * export class Listings {
74
83
  * items: Listing[] = []
84
+ * item: Listing = {
85
+ * id: 'l1',
86
+ * name: 'Sea-view loft',
87
+ * location: 'Lisbon',
88
+ * imageUrl: '/listings/loft.jpg',
89
+ * price: 120,
90
+ * }
75
91
  * open(id: string): () => void {
76
- * return () => this.navigate(`/listings/${id}`)
92
+ * return () => console.log('open listing', id)
93
+ * }
94
+ * readonly save = (id: string): void => {
95
+ * console.log('save listing', id)
77
96
  * }
78
97
  * }
79
98
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qCAAqC,CAAA;AACnD,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qCAAqC,CAAA;AACnD,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Exports:
5
5
  * - `<ListingCard>` — outer Card shell (`div[mol-listing-card]`). Props:
6
+ * `toggle?` (a counted server-backed action, rendered after the content),
6
7
  * `onClick?`, `className?`, `dataMolId?`; children are projected content.
7
8
  * - `<ListingCardMedia>` — top image slot (`div[mol-listing-card-media]`).
8
9
  * Props: `src?`, `alt?`, node children (custom media node), `aspect?`
@@ -46,6 +47,14 @@
46
47
  * ListingGrid,
47
48
  * } from '@molecule/app-listing-card-angular'
48
49
  *
50
+ * interface Listing {
51
+ * id: string
52
+ * name: string
53
+ * location: string
54
+ * imageUrl: string
55
+ * price: number
56
+ * }
57
+ *
49
58
  * @Component({
50
59
  * selector: 'app-listings',
51
60
  * standalone: true,
@@ -72,8 +81,18 @@
72
81
  * })
73
82
  * export class Listings {
74
83
  * items: Listing[] = []
84
+ * item: Listing = {
85
+ * id: 'l1',
86
+ * name: 'Sea-view loft',
87
+ * location: 'Lisbon',
88
+ * imageUrl: '/listings/loft.jpg',
89
+ * price: 120,
90
+ * }
75
91
  * open(id: string): () => void {
76
- * return () => this.navigate(`/listings/${id}`)
92
+ * return () => console.log('open listing', id)
93
+ * }
94
+ * readonly save = (id: string): void => {
95
+ * console.log('save listing', id)
77
96
  * }
78
97
  * }
79
98
  * ```
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qCAAqC,CAAA;AACnD,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AAEH,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qCAAqC,CAAA;AACnD,cAAc,kCAAkC,CAAA;AAChD,cAAc,mCAAmC,CAAA;AACjD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,YAAY,CAAA"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * ListingCardToggle component (React parity): the counted native toggle of a
3
+ * listing card.
4
+ *
5
+ * @module
6
+ */
7
+ import { type DoCheck, type OnDestroy, type OnInit } from '@angular/core';
8
+ import type { UIClassMap } from '@molecule/app-ui';
9
+ import { type OptimisticValueState } from '@molecule/app-ui-angular';
10
+ import type { ListingCardToggleProps } from './types.js';
11
+ import * as i0 from "@angular/core";
12
+ /** The value a listing toggle shows and saves. */
13
+ type ToggleValue = ListingCardToggleProps['value'];
14
+ /**
15
+ * ListingCardToggle component.
16
+ *
17
+ * The host IS the `<button>` itself (`button[mol-listing-card-toggle]`),
18
+ * matching React's root exactly: the ClassMap button classes, `data-mol-id`,
19
+ * `aria-pressed`, `aria-busy` and the click handler live on it. React renders
20
+ * `{label} <span>{count}</span>`; the template renders the same text. The
21
+ * pressed state and the count come from one loaded record and are saved
22
+ * together, so a rejected save puts both back (React's `useOptimisticValue`).
23
+ *
24
+ * Private to {@link ListingCard}, like React's own non-exported
25
+ * `ListingCardToggle` — the package's export surface stays React's.
26
+ */
27
+ export declare class ListingCardToggle implements OnInit, DoCheck, OnDestroy {
28
+ /** The pressed state and count from the same loaded record. */
29
+ value?: ToggleValue;
30
+ /** Saves the desired state and returns the server-confirmed state and count together. */
31
+ commit?: ListingCardToggleProps['commit'];
32
+ /** Label when the displayed value is true. */
33
+ activeLabel?: string | number;
34
+ /** Label when the displayed value is false. */
35
+ inactiveLabel?: string | number;
36
+ /** Receives a failed save after the toggle put the last confirmed state back. */
37
+ onError?: (error: unknown) => void;
38
+ /** Overrides the button's default `data-mol-id`. */
39
+ dataMolId?: string;
40
+ /** Button variant (defaults to `solid` while pressed, `outline` otherwise). */
41
+ variant?: ListingCardToggleProps['variant'];
42
+ /** Button color. */
43
+ color?: ListingCardToggleProps['color'];
44
+ /** Button size. */
45
+ size?: ListingCardToggleProps['size'];
46
+ /** Whether the button stretches to fill its container. */
47
+ fullWidth: boolean;
48
+ /** Disables the button (permissions, never a pending save). */
49
+ disabled: boolean;
50
+ /** Extra classes. */
51
+ className?: string;
52
+ /** `data-testid`. */
53
+ testId?: string;
54
+ /** `data-mol-id` automation id (React's `automationId`). */
55
+ automationId?: string;
56
+ /** The optimistic controller. */
57
+ private controller?;
58
+ /** The controller state (a signal so the zoneless view re-checks on every publish). */
59
+ readonly state: import("@angular/core").WritableSignal<OptimisticValueState<{
60
+ pressed: boolean;
61
+ count: number;
62
+ }>>;
63
+ private unsubscribe?;
64
+ private lastReceived?;
65
+ /**
66
+ * The current class map.
67
+ * @returns The UIClassMap.
68
+ */
69
+ cm(): UIClassMap;
70
+ /** Creates the optimistic controller from the loaded value. */
71
+ ngOnInit(): void;
72
+ /**
73
+ * Takes a newer loaded value the way React's effect does (only when it
74
+ * differs from the last one received).
75
+ */
76
+ ngDoCheck(): void;
77
+ /** Stops mirroring controller state into the signal (unmount). */
78
+ ngOnDestroy(): void;
79
+ /**
80
+ * Computes the button class list (React's `Button` defaults included).
81
+ * @returns The class string.
82
+ */
83
+ classes(): string;
84
+ /**
85
+ * The `data-mol-id` value: `automationId`, else `dataMolId`, else React's
86
+ * default `listing-card-toggle`.
87
+ * @returns The attribute value.
88
+ */
89
+ molId(): string;
90
+ /**
91
+ * The displayed label (React's `{pressed ? activeLabel : inactiveLabel}`).
92
+ * @returns The label text.
93
+ */
94
+ label(): string;
95
+ /**
96
+ * The displayed count (React's `<span>{count}</span>`).
97
+ * @returns The count text.
98
+ */
99
+ count(): string;
100
+ /**
101
+ * Whether the displayed value is pressed.
102
+ * @returns The pressed state.
103
+ */
104
+ pressed(): boolean;
105
+ /**
106
+ * Whether a save is in flight (React's `toggle.pending`).
107
+ * @returns True while pending.
108
+ */
109
+ pending(): boolean;
110
+ /**
111
+ * Flips the pressed state and moves the count with it, then saves; the
112
+ * click never reaches the card's own `onClick` (React's `stopPropagation`).
113
+ * @param event - The native click event.
114
+ */
115
+ handleClick(event: MouseEvent): void;
116
+ /**
117
+ * Creates the controller on first use and mirrors its state into the signal.
118
+ * @returns True when a controller exists.
119
+ */
120
+ private attach;
121
+ static ɵfac: i0.ɵɵFactoryDeclaration<ListingCardToggle, never>;
122
+ static ɵcmp: i0.ɵɵComponentDeclaration<ListingCardToggle, "button[mol-listing-card-toggle]", never, { "value": { "alias": "value"; "required": false; }; "commit": { "alias": "commit"; "required": false; }; "activeLabel": { "alias": "activeLabel"; "required": false; }; "inactiveLabel": { "alias": "inactiveLabel"; "required": false; }; "onError": { "alias": "onError"; "required": false; }; "dataMolId": { "alias": "dataMolId"; "required": false; }; "variant": { "alias": "variant"; "required": false; }; "color": { "alias": "color"; "required": false; }; "size": { "alias": "size"; "required": false; }; "fullWidth": { "alias": "fullWidth"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "className": { "alias": "className"; "required": false; }; "testId": { "alias": "testId"; "required": false; }; "automationId": { "alias": "automationId"; "required": false; }; }, {}, never, never, true, never>;
123
+ }
124
+ export {};
125
+ //# sourceMappingURL=listing-card-toggle.component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listing-card-toggle.component.d.ts","sourceRoot":"","sources":["../src/listing-card-toggle.component.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,MAAM,EAAU,MAAM,eAAe,CAAA;AAE5F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C,KAAK;;;QAIZ;IACF,OAAO,CAAC,WAAW,CAAC,CAAY;IAChC,OAAO,CAAC,YAAY,CAAC,CAAa;IAElC;;;OAGG;IACH,EAAE,IAAI,UAAU;IAIhB,+DAA+D;IAC/D,QAAQ,IAAI,IAAI;IAIhB;;;OAGG;IACH,SAAS,IAAI,IAAI;IASjB,kEAAkE;IAClE,WAAW,IAAI,IAAI;IAInB;;;OAGG;IACH,OAAO,IAAI,MAAM;IAajB;;;;OAIG;IACH,KAAK,IAAI,MAAM;IAIf;;;OAGG;IACH,KAAK,IAAI,MAAM;IAKf;;;OAGG;IACH,KAAK,IAAI,MAAM;IAIf;;;OAGG;IACH,OAAO,IAAI,OAAO;IAIlB;;;OAGG;IACH,OAAO,IAAI,OAAO;IAIlB;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAQpC;;;OAGG;IACH,OAAO,CAAC,MAAM;yCApJH,iBAAiB;2CAAjB,iBAAiB;CAsK7B"}
@@ -0,0 +1,231 @@
1
+ /**
2
+ * ListingCardToggle component (React parity): the counted native toggle of a
3
+ * listing card.
4
+ *
5
+ * @module
6
+ */
7
+ import { Component, signal } from '@angular/core';
8
+ import { getClassMap } from '@molecule/app-ui';
9
+ import { createOptimisticValue, shallowEqual, } from '@molecule/app-ui-angular';
10
+ import * as i0 from "@angular/core";
11
+ /**
12
+ * ListingCardToggle component.
13
+ *
14
+ * The host IS the `<button>` itself (`button[mol-listing-card-toggle]`),
15
+ * matching React's root exactly: the ClassMap button classes, `data-mol-id`,
16
+ * `aria-pressed`, `aria-busy` and the click handler live on it. React renders
17
+ * `{label} <span>{count}</span>`; the template renders the same text. The
18
+ * pressed state and the count come from one loaded record and are saved
19
+ * together, so a rejected save puts both back (React's `useOptimisticValue`).
20
+ *
21
+ * Private to {@link ListingCard}, like React's own non-exported
22
+ * `ListingCardToggle` — the package's export surface stays React's.
23
+ */
24
+ export class ListingCardToggle {
25
+ /** The pressed state and count from the same loaded record. */
26
+ value;
27
+ /** Saves the desired state and returns the server-confirmed state and count together. */
28
+ commit;
29
+ /** Label when the displayed value is true. */
30
+ activeLabel;
31
+ /** Label when the displayed value is false. */
32
+ inactiveLabel;
33
+ /** Receives a failed save after the toggle put the last confirmed state back. */
34
+ onError;
35
+ /** Overrides the button's default `data-mol-id`. */
36
+ dataMolId;
37
+ /** Button variant (defaults to `solid` while pressed, `outline` otherwise). */
38
+ variant;
39
+ /** Button color. */
40
+ color;
41
+ /** Button size. */
42
+ size;
43
+ /** Whether the button stretches to fill its container. */
44
+ fullWidth = false;
45
+ /** Disables the button (permissions, never a pending save). */
46
+ disabled = false;
47
+ /** Extra classes. */
48
+ className;
49
+ /** `data-testid`. */
50
+ testId;
51
+ /** `data-mol-id` automation id (React's `automationId`). */
52
+ automationId;
53
+ /** The optimistic controller. */
54
+ controller;
55
+ /** The controller state (a signal so the zoneless view re-checks on every publish). */
56
+ state = signal({
57
+ value: { pressed: false, count: 0 },
58
+ pending: false,
59
+ error: null,
60
+ }, /* @ts-ignore */
61
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
62
+ unsubscribe;
63
+ lastReceived;
64
+ /**
65
+ * The current class map.
66
+ * @returns The UIClassMap.
67
+ */
68
+ cm() {
69
+ return getClassMap();
70
+ }
71
+ /** Creates the optimistic controller from the loaded value. */
72
+ ngOnInit() {
73
+ this.attach();
74
+ }
75
+ /**
76
+ * Takes a newer loaded value the way React's effect does (only when it
77
+ * differs from the last one received).
78
+ */
79
+ ngDoCheck() {
80
+ this.attach();
81
+ const received = this.value;
82
+ if (!received)
83
+ return;
84
+ if (this.lastReceived && shallowEqual(this.lastReceived, received))
85
+ return;
86
+ this.lastReceived = received;
87
+ this.controller?.sync(received);
88
+ }
89
+ /** Stops mirroring controller state into the signal (unmount). */
90
+ ngOnDestroy() {
91
+ this.unsubscribe?.();
92
+ }
93
+ /**
94
+ * Computes the button class list (React's `Button` defaults included).
95
+ * @returns The class string.
96
+ */
97
+ classes() {
98
+ const cm = this.cm();
99
+ return cm.cn(cm.button({
100
+ variant: this.variant ?? (this.pressed() ? 'solid' : 'outline'),
101
+ color: this.color ?? 'primary',
102
+ size: this.size ?? 'md',
103
+ fullWidth: this.fullWidth,
104
+ }), this.className);
105
+ }
106
+ /**
107
+ * The `data-mol-id` value: `automationId`, else `dataMolId`, else React's
108
+ * default `listing-card-toggle`.
109
+ * @returns The attribute value.
110
+ */
111
+ molId() {
112
+ return this.automationId ?? this.dataMolId ?? 'listing-card-toggle';
113
+ }
114
+ /**
115
+ * The displayed label (React's `{pressed ? activeLabel : inactiveLabel}`).
116
+ * @returns The label text.
117
+ */
118
+ label() {
119
+ const label = this.pressed() ? this.activeLabel : this.inactiveLabel;
120
+ return label === null || label === undefined ? '' : String(label);
121
+ }
122
+ /**
123
+ * The displayed count (React's `<span>{count}</span>`).
124
+ * @returns The count text.
125
+ */
126
+ count() {
127
+ return String(this.state().value.count);
128
+ }
129
+ /**
130
+ * Whether the displayed value is pressed.
131
+ * @returns The pressed state.
132
+ */
133
+ pressed() {
134
+ return this.state().value.pressed;
135
+ }
136
+ /**
137
+ * Whether a save is in flight (React's `toggle.pending`).
138
+ * @returns True while pending.
139
+ */
140
+ pending() {
141
+ return this.state().pending;
142
+ }
143
+ /**
144
+ * Flips the pressed state and moves the count with it, then saves; the
145
+ * click never reaches the card's own `onClick` (React's `stopPropagation`).
146
+ * @param event - The native click event.
147
+ */
148
+ handleClick(event) {
149
+ event.stopPropagation();
150
+ this.controller?.update((current) => ({
151
+ pressed: !current.pressed,
152
+ count: Math.max(0, current.count + (current.pressed ? -1 : 1)),
153
+ }));
154
+ }
155
+ /**
156
+ * Creates the controller on first use and mirrors its state into the signal.
157
+ * @returns True when a controller exists.
158
+ */
159
+ attach() {
160
+ if (this.controller)
161
+ return true;
162
+ const value = this.value ?? { pressed: false, count: 0 };
163
+ this.lastReceived = this.value;
164
+ const controller = createOptimisticValue({
165
+ value,
166
+ equals: shallowEqual,
167
+ commit: (next) => {
168
+ const toggle = this.commit;
169
+ return toggle ? toggle(next.pressed) : Promise.resolve(next);
170
+ },
171
+ onError: (error) => this.onError?.(error),
172
+ });
173
+ this.controller = controller;
174
+ this.unsubscribe = controller.subscribe((next) => this.state.set({ ...next }));
175
+ this.state.set(controller.getState());
176
+ return true;
177
+ }
178
+ static ɵfac = function ListingCardToggle_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || ListingCardToggle)(); };
179
+ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ListingCardToggle, selectors: [["button", "mol-listing-card-toggle", ""]], hostVars: 8, hostBindings: function ListingCardToggle_HostBindings(rf, ctx) { if (rf & 1) {
180
+ i0.ɵɵlistener("click", function ListingCardToggle_click_HostBindingHandler($event) { return ctx.handleClick($event); });
181
+ } if (rf & 2) {
182
+ i0.ɵɵdomProperty("disabled", ctx.disabled);
183
+ i0.ɵɵattribute("type", "button")("data-mol-id", ctx.molId())("data-testid", ctx.testId)("aria-pressed", ctx.pressed() ? "true" : "false")("aria-busy", ctx.pending() ? "true" : "false");
184
+ i0.ɵɵclassMap(ctx.classes());
185
+ } }, inputs: { value: "value", commit: "commit", activeLabel: "activeLabel", inactiveLabel: "inactiveLabel", onError: "onError", dataMolId: "dataMolId", variant: "variant", color: "color", size: "size", fullWidth: "fullWidth", disabled: "disabled", className: "className", testId: "testId", automationId: "automationId" }, decls: 3, vars: 2, template: function ListingCardToggle_Template(rf, ctx) { if (rf & 1) {
186
+ i0.ɵɵtext(0);
187
+ i0.ɵɵdomElementStart(1, "span");
188
+ i0.ɵɵtext(2);
189
+ i0.ɵɵdomElementEnd();
190
+ } if (rf & 2) {
191
+ i0.ɵɵtextInterpolate1("", ctx.label(), " ");
192
+ i0.ɵɵadvance(2);
193
+ i0.ɵɵtextInterpolate(ctx.count());
194
+ } }, encapsulation: 2 });
195
+ }
196
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ListingCardToggle, [{
197
+ type: Component,
198
+ args: [{
199
+ selector: 'button[mol-listing-card-toggle]',
200
+ standalone: true,
201
+ inputs: [
202
+ 'value',
203
+ 'commit',
204
+ 'activeLabel',
205
+ 'inactiveLabel',
206
+ 'onError',
207
+ 'dataMolId',
208
+ 'variant',
209
+ 'color',
210
+ 'size',
211
+ 'fullWidth',
212
+ 'disabled',
213
+ 'className',
214
+ 'testId',
215
+ 'automationId',
216
+ ],
217
+ host: {
218
+ '[class]': 'classes()',
219
+ '[attr.type]': '"button"',
220
+ '[attr.data-mol-id]': 'molId()',
221
+ '[attr.data-testid]': 'testId',
222
+ '[disabled]': 'disabled',
223
+ '[attr.aria-pressed]': 'pressed() ? "true" : "false"',
224
+ '[attr.aria-busy]': 'pending() ? "true" : "false"',
225
+ '(click)': 'handleClick($event)',
226
+ },
227
+ template: `{{ label() }} <span>{{ count() }}</span>`,
228
+ }]
229
+ }], null, null); })();
230
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ListingCardToggle, { className: "ListingCardToggle", filePath: "listing-card-toggle.component.ts", lineNumber: 68 }); })();
231
+ //# sourceMappingURL=listing-card-toggle.component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listing-card-toggle.component.js","sourceRoot":"","sources":["../src/listing-card-toggle.component.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAA6C,MAAM,EAAE,MAAM,eAAe,CAAA;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EACL,qBAAqB,EAGrB,YAAY,GACb,MAAM,0BAA0B,CAAA;;AAOjC;;;;;;;;;;;;GAYG;AAgCH,MAAM,OAAO,iBAAiB;IAC5B,+DAA+D;IAC/D,KAAK,CAAc;IACnB,yFAAyF;IACzF,MAAM,CAAmC;IACzC,8CAA8C;IAC9C,WAAW,CAAkB;IAC7B,+CAA+C;IAC/C,aAAa,CAAkB;IAC/B,iFAAiF;IAC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O,IAAI,CAAA;IACb,CAAC;2GArKU,iBAAiB;6DAAjB,iBAAiB;YAAjB,4FAAA,uBAAmB,IAAF;;YAAjB,0CAAiB;mCAAjB,QAAQ,iBAAR,WAAO,6CAAP,aAAS,GAAG,MAAM,GAAG,OAAO,eAA5B,aAAS,GAAG,MAAM,GAAG,OAAO;YAA5B,cAAA,aAAS,CAAQ;;YAFjB,YAAc;YAAA,+BAAM;YAAA,YAAa;YAAA,oBAAO;;YAAxC,2CAAc;YAAM,eAAa;YAAb,iCAAa;;;iFAEjC,iBAAiB;cA/B7B,SAAS;eAAC;gBACT,QAAQ,EAAE,iCAAiC;gBAC3C,UAAU,EAAE,IAAI;gBAChB,MAAM,EAAE;oBACN,OAAO;oBACP,QAAQ;oBACR,aAAa;oBACb,eAAe;oBACf,SAAS;oBACT,WAAW;oBACX,SAAS;oBACT,OAAO;oBACP,MAAM;oBACN,WAAW;oBACX,UAAU;oBACV,WAAW;oBACX,QAAQ;oBACR,cAAc;iBACf;gBACD,IAAI,EAAE;oBACJ,SAAS,EAAE,WAAW;oBACtB,aAAa,EAAE,UAAU;oBACzB,oBAAoB,EAAE,SAAS;oBAC/B,oBAAoB,EAAE,QAAQ;oBAC9B,YAAY,EAAE,UAAU;oBACxB,qBAAqB,EAAE,8BAA8B;oBACrD,kBAAkB,EAAE,8BAA8B;oBAClD,SAAS,EAAE,qBAAqB;iBACjC;gBACD,QAAQ,EAAE,0CAA0C;aACrD;;kFACY,iBAAiB"}
@@ -10,8 +10,14 @@ import * as i0 from "@angular/core";
10
10
  * + `cm.cursorPointer` when a click handler is supplied + `className`),
11
11
  * `data-mol-id` and the click handler live on it. The children are projected
12
12
  * content, stacked vertically in the inner `div` (`cm.stack(0)`).
13
+ *
14
+ * A supplied `toggle` renders the counted card action after the content,
15
+ * outside any links in it — React's `<ListingCardActions><ListingCardToggle>`
16
+ * pair, in the same DOM order.
13
17
  */
14
18
  export declare class ListingCard {
19
+ /** Renders a counted native toggle after the content, outside any links in the content. */
20
+ toggle?: ListingCardProps['toggle'];
15
21
  /** Click handler; receives the DOM click event (React's `onClick`). */
16
22
  onClick?: ListingCardProps['onClick'];
17
23
  /** Extra classes on the outer Card. */
@@ -40,6 +46,6 @@ export declare class ListingCard {
40
46
  */
41
47
  handleClick(event: MouseEvent): void;
42
48
  static ɵfac: i0.ɵɵFactoryDeclaration<ListingCard, never>;
43
- static ɵcmp: i0.ɵɵComponentDeclaration<ListingCard, "div[mol-listing-card]", never, { "onClick": { "alias": "onClick"; "required": false; }; "className": { "alias": "className"; "required": false; }; "dataMolId": { "alias": "dataMolId"; "required": false; }; }, {}, never, ["*"], true, never>;
49
+ static ɵcmp: i0.ɵɵComponentDeclaration<ListingCard, "div[mol-listing-card]", never, { "toggle": { "alias": "toggle"; "required": false; }; "onClick": { "alias": "onClick"; "required": false; }; "className": { "alias": "className"; "required": false; }; "dataMolId": { "alias": "dataMolId"; "required": false; }; }, {}, never, ["*"], true, never>;
44
50
  }
45
51
  //# sourceMappingURL=listing-card.component.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"listing-card.component.d.ts","sourceRoot":"","sources":["../src/listing-card.component.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;;AAElD;;;;;;;;;GASG;AACH,qBAWa,WAAW;IACtB,uEAAuE;IACvE,OAAO,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;IACrC,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,EAAE,IAAI,UAAU;IAIhB;;;;OAIG;IACH,OAAO,IAAI,MAAM;IASjB;;;OAGG;IACH,YAAY,IAAI,MAAM;IAItB;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;yCA1CzB,WAAW;2CAAX,WAAW;CA6CvB"}
1
+ {"version":3,"file":"listing-card.component.d.ts","sourceRoot":"","sources":["../src/listing-card.component.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAKlD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;;AAElD;;;;;;;;;;;;;GAaG;AACH,qBAaa,WAAW;IACtB,2FAA2F;IAC3F,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;IACnC,uEAAuE;IACvE,OAAO,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAA;IACrC,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,EAAE,IAAI,UAAU;IAIhB;;;;OAIG;IACH,OAAO,IAAI,MAAM;IASjB;;;OAGG;IACH,YAAY,IAAI,MAAM;IAItB;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;yCA5CzB,WAAW;2CAAX,WAAW;CA+CvB"}
@@ -5,8 +5,19 @@
5
5
  */
6
6
  import { Component } from '@angular/core';
7
7
  import { getClassMap } from '@molecule/app-ui';
8
+ import { ListingCardActions } from './listing-card-actions.component.js';
9
+ import { ListingCardToggle } from './listing-card-toggle.component.js';
8
10
  import * as i0 from "@angular/core";
9
11
  const _c0 = ["*"];
12
+ function ListingCard_Conditional_2_Template(rf, ctx) { if (rf & 1) {
13
+ i0.ɵɵelementStart(0, "div", 0);
14
+ i0.ɵɵelement(1, "button", 1);
15
+ i0.ɵɵelementEnd();
16
+ } if (rf & 2) {
17
+ const ctx_r0 = i0.ɵɵnextContext();
18
+ i0.ɵɵadvance();
19
+ i0.ɵɵproperty("value", ctx_r0.toggle.value)("commit", ctx_r0.toggle.commit)("activeLabel", ctx_r0.toggle.activeLabel)("inactiveLabel", ctx_r0.toggle.inactiveLabel)("onError", ctx_r0.toggle.onError)("dataMolId", ctx_r0.toggle.dataMolId)("variant", ctx_r0.toggle.variant)("color", ctx_r0.toggle.color)("size", ctx_r0.toggle.size)("fullWidth", ctx_r0.toggle.fullWidth ?? false)("disabled", ctx_r0.toggle.disabled ?? false)("className", ctx_r0.toggle.className)("testId", ctx_r0.toggle.testId)("automationId", ctx_r0.toggle.automationId);
20
+ } }
10
21
  /**
11
22
  * ListingCard component.
12
23
  *
@@ -16,8 +27,14 @@ const _c0 = ["*"];
16
27
  * + `cm.cursorPointer` when a click handler is supplied + `className`),
17
28
  * `data-mol-id` and the click handler live on it. The children are projected
18
29
  * content, stacked vertically in the inner `div` (`cm.stack(0)`).
30
+ *
31
+ * A supplied `toggle` renders the counted card action after the content,
32
+ * outside any links in it — React's `<ListingCardActions><ListingCardToggle>`
33
+ * pair, in the same DOM order.
19
34
  */
20
35
  export class ListingCard {
36
+ /** Renders a counted native toggle after the content, outside any links in the content. */
37
+ toggle;
21
38
  /** Click handler; receives the DOM click event (React's `onClick`). */
22
39
  onClick;
23
40
  /** Extra classes on the outer Card. */
@@ -60,28 +77,33 @@ export class ListingCard {
60
77
  } if (rf & 2) {
61
78
  i0.ɵɵattribute("data-mol-id", ctx.dataMolId ?? null);
62
79
  i0.ɵɵclassMap(ctx.classes());
63
- } }, inputs: { onClick: "onClick", className: "className", dataMolId: "dataMolId" }, ngContentSelectors: _c0, decls: 2, vars: 2, template: function ListingCard_Template(rf, ctx) { if (rf & 1) {
80
+ } }, inputs: { toggle: "toggle", onClick: "onClick", className: "className", dataMolId: "dataMolId" }, ngContentSelectors: _c0, decls: 3, vars: 3, consts: [["mol-listing-card-actions", ""], ["mol-listing-card-toggle", "", 3, "value", "commit", "activeLabel", "inactiveLabel", "onError", "dataMolId", "variant", "color", "size", "fullWidth", "disabled", "className", "testId", "automationId"]], template: function ListingCard_Template(rf, ctx) { if (rf & 1) {
64
81
  i0.ɵɵprojectionDef();
65
- i0.ɵɵdomElementStart(0, "div");
82
+ i0.ɵɵelementStart(0, "div");
66
83
  i0.ɵɵprojection(1);
67
- i0.ɵɵdomElementEnd();
84
+ i0.ɵɵconditionalCreate(2, ListingCard_Conditional_2_Template, 2, 14, "div", 0);
85
+ i0.ɵɵelementEnd();
68
86
  } if (rf & 2) {
69
87
  i0.ɵɵclassMap(ctx.stackClasses());
70
- } }, encapsulation: 2 });
88
+ i0.ɵɵadvance(2);
89
+ i0.ɵɵconditional(ctx.toggle ? 2 : -1);
90
+ } }, dependencies: [ListingCardActions, ListingCardToggle], encapsulation: 2 });
71
91
  }
72
92
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ListingCard, [{
73
93
  type: Component,
74
94
  args: [{
75
95
  selector: 'div[mol-listing-card]',
76
96
  standalone: true,
77
- inputs: ['onClick', 'className', 'dataMolId'],
97
+ imports: [ListingCardActions, ListingCardToggle],
98
+ inputs: ['toggle', 'onClick', 'className', 'dataMolId'],
78
99
  host: {
79
100
  '[class]': 'classes()',
80
101
  '[attr.data-mol-id]': 'dataMolId ?? null',
81
102
  '(click)': 'handleClick($event)',
82
103
  },
83
- template: `<div [class]="stackClasses()"><ng-content></ng-content></div>`,
104
+ // prettier-ignore
105
+ template: `<div [class]="stackClasses()"><ng-content></ng-content>@if (toggle) {<div mol-listing-card-actions><button mol-listing-card-toggle [value]="toggle.value" [commit]="toggle.commit" [activeLabel]="toggle.activeLabel" [inactiveLabel]="toggle.inactiveLabel" [onError]="toggle.onError" [dataMolId]="toggle.dataMolId" [variant]="toggle.variant" [color]="toggle.color" [size]="toggle.size" [fullWidth]="toggle.fullWidth ?? false" [disabled]="toggle.disabled ?? false" [className]="toggle.className" [testId]="toggle.testId" [automationId]="toggle.automationId"></button></div>}</div>`,
84
106
  }]
85
107
  }], null, null); })();
86
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ListingCard, { className: "ListingCard", filePath: "listing-card.component.ts", lineNumber: 35 }); })();
108
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ListingCard, { className: "ListingCard", filePath: "listing-card.component.ts", lineNumber: 43 }); })();
87
109
  //# sourceMappingURL=listing-card.component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"listing-card.component.js","sourceRoot":"","sources":["../src/listing-card.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;;;AAI9C;;;;;;;;;GASG;AAYH,MAAM,OAAO,WAAW;IACtB,uEAAuE;IACvE,OAAO,CAA8B;IACrC,uCAAuC;IACvC,SAAS,CAAS;IAClB,4CAA4C;IAC5C,SAAS,CAAS;IAElB;;;OAGG;IACH,EAAE;QACA,OAAO,WAAW,EAAE,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACH,OAAO;QACL,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,CAAA;QACpB,OAAO,EAAE,CAAC,EAAE,CACV,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,EAChC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EACpB,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CACnE,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC3B,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,KAAiB;QAC3B,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC;qGA5CU,WAAW;6DAAX,WAAW;YAAX,sFAAA,uBACR,IADmB;;2DA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.ts CHANGED
@@ -4,6 +4,41 @@
4
4
  *
5
5
  * @module
6
6
  */
7
+ import type { ButtonSize, ButtonVariant, ColorVariant } from '@molecule/app-ui';
8
+ /** A server-backed card action with the total number of people who selected it. */
9
+ export interface ListingCardToggleProps {
10
+ /** The pressed state and count from the same loaded record. */
11
+ value: {
12
+ pressed: boolean;
13
+ count: number;
14
+ };
15
+ /** Saves the desired state and returns the server-confirmed state and count together. */
16
+ commit: (desired: boolean) => Promise<ListingCardToggleProps['value']>;
17
+ /** Label when the displayed value is true. */
18
+ activeLabel: string | number;
19
+ /** Label when the displayed value is false. */
20
+ inactiveLabel: string | number;
21
+ /** Receives a failed save after the toggle put the last confirmed state and count back. */
22
+ onError?: (error: unknown) => void;
23
+ /** Overrides the button's default `data-mol-id`. */
24
+ dataMolId?: string;
25
+ /** Button variant (defaults to `'solid'` while pressed, `'outline'` otherwise). */
26
+ variant?: ButtonVariant;
27
+ /** Button color. */
28
+ color?: ColorVariant;
29
+ /** Button size. */
30
+ size?: ButtonSize;
31
+ /** Whether the button stretches to fill its container. */
32
+ fullWidth?: boolean;
33
+ /** Disables the button (permissions, never a pending save). */
34
+ disabled?: boolean;
35
+ /** Extra classes on the button. */
36
+ className?: string;
37
+ /** `data-testid` for the button. */
38
+ testId?: string;
39
+ /** `data-mol-id` automation id; wins over `dataMolId` (React's precedence). */
40
+ automationId?: string;
41
+ }
7
42
  /**
8
43
  * Props accepted by {@link ListingCard} — the same props
9
44
  * `@molecule/app-listing-card-react` accepts. Node props (`children`) are
@@ -13,6 +48,8 @@
13
48
  export interface ListingCardProps {
14
49
  /** Slots — projected as the element's default content. */
15
50
  children?: unknown;
51
+ /** Renders a counted native toggle after the content, outside any links in the content. */
52
+ toggle?: ListingCardToggleProps;
16
53
  /** Called on any click on the card (React's `onClick`, with the click event). */
17
54
  onClick?: (event: MouseEvent) => void;
18
55
  /** Extra classes on the outer Card. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources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EAAE,OAAO,CAAA;IAClB,uHAAuH;IACvH,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CAAA;IACvC,4FAA4F;IAC5F,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,kEAAkE;IAClE,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC/B,6CAA6C;IAC7C,GAAG,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;IAC/B,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-listing-card-angular",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Angular listing/product-card primitives with media, body, actions slots",
5
5
  "homepage": "https://www.molecule.dev/packages/app-listing-card-angular",
6
6
  "type": "module",
@@ -55,12 +55,12 @@
55
55
  "@angular/compiler-cli": "22.2.3",
56
56
  "@angular/core": "22.2.3",
57
57
  "@angular/platform-browser": "22.2.3",
58
- "@molecule/app-angular": "3.7.1",
58
+ "@molecule/app-angular": "3.11.0",
59
59
  "@molecule/app-framework-conformance": "0.0.0",
60
60
  "@molecule/app-i18n": "1.2.2",
61
61
  "@molecule/app-icons": "1.0.4",
62
- "@molecule/app-ui": "1.4.0",
63
- "@molecule/app-ui-angular": "1.2.0",
62
+ "@molecule/app-ui": "1.5.0",
63
+ "@molecule/app-ui-angular": "1.4.0",
64
64
  "@types/node": "26.6.5",
65
65
  "jsdom": "30.1.3",
66
66
  "rxjs": "7.8.2",