@molecule/app-related-items-card-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.
- package/LICENSE +202 -0
- package/README.md +392 -2
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/related-items-card.component.d.ts +126 -0
- package/dist/related-items-card.component.d.ts.map +1 -0
- package/dist/related-items-card.component.js +308 -0
- package/dist/related-items-card.component.js.map +1 -0
- package/dist/slot-dom.d.ts +54 -0
- package/dist/slot-dom.d.ts.map +1 -0
- package/dist/slot-dom.js +87 -0
- package/dist/slot-dom.js.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular card container for cross-linked / related item lists — the
|
|
3
|
+
* counterpart of `@molecule/app-related-items-card-react`: the same props and
|
|
4
|
+
* the same DOM for the same input.
|
|
5
|
+
*
|
|
6
|
+
* Exports `<RelatedItemsCard>` — a titled Card with header + list + empty
|
|
7
|
+
* state + "View all" link, styled through the ClassMap bond. Use for
|
|
8
|
+
* "Company → Deals", "Contact → Notes", "Ticket → Related Articles" panels.
|
|
9
|
+
*
|
|
10
|
+
* Node props are projected content: `icon` and `title` render inside the
|
|
11
|
+
* header, `headerActions` inside the right-hand header row, and `emptyState`
|
|
12
|
+
* in the list's place when `items` is empty. `renderItem` is a `TemplateRef`
|
|
13
|
+
* whose context carries the item as `$implicit` (and `a0`) and the index as
|
|
14
|
+
* `a1`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Component } from '@angular/core'
|
|
19
|
+
* import { RelatedItemsCard } from '@molecule/app-related-items-card-angular'
|
|
20
|
+
*
|
|
21
|
+
* interface Article {
|
|
22
|
+
* id: string
|
|
23
|
+
* title: string
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* @Component({
|
|
27
|
+
* selector: 'app-related-articles',
|
|
28
|
+
* standalone: true,
|
|
29
|
+
* imports: [RelatedItemsCard],
|
|
30
|
+
* template: `
|
|
31
|
+
* <ng-template #row let-article>
|
|
32
|
+
* <span>{{ article.title }}</span>
|
|
33
|
+
* </ng-template>
|
|
34
|
+
* <div mol-related-items-card title="Related Articles" [items]="articles" [renderItem]="row"
|
|
35
|
+
* viewAllHref="/articles" [onItemClick]="open">
|
|
36
|
+
* <p slot="emptyState">No related articles yet.</p>
|
|
37
|
+
* </div>
|
|
38
|
+
* `,
|
|
39
|
+
* })
|
|
40
|
+
* export class RelatedArticles {
|
|
41
|
+
* articles: Article[] = []
|
|
42
|
+
*
|
|
43
|
+
* open(article: Article): void {
|
|
44
|
+
* // navigate to the article…
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* - Requires a bonded ClassMap — call `setClassMap()` (e.g. with
|
|
51
|
+
* `@molecule/app-ui-tailwind`) at startup or rendering throws.
|
|
52
|
+
* - The "View all" label is hardcoded English in the React reference (not
|
|
53
|
+
* routed through i18n) and is the same literal here; pass a translated link
|
|
54
|
+
* via `headerActions` in localized apps.
|
|
55
|
+
* - `onItemClick` rows are mouse-only `<li>` elements (no keyboard handler);
|
|
56
|
+
* render a real `<button>`/`<a>` inside the item template when keyboard
|
|
57
|
+
* access matters.
|
|
58
|
+
* - `viewAllHref` renders a plain `<a href>` (full page load in SPA routers);
|
|
59
|
+
* use `headerActions` with your router's Link for client-side navigation.
|
|
60
|
+
*
|
|
61
|
+
* @module
|
|
62
|
+
*/
|
|
63
|
+
export * from './related-items-card.component.js';
|
|
64
|
+
export * from './types.js';
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,cAAc,mCAAmC,CAAA;AACjD,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { type AfterViewInit, type DoCheck, ElementRef, type TemplateRef } from '@angular/core';
|
|
2
|
+
import type { UIClassMap } from '@molecule/app-ui';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* RelatedItemsCard component.
|
|
6
|
+
*
|
|
7
|
+
* Card container for a list of cross-linked / related items. Common usage:
|
|
8
|
+
* "Company → Deals", "Contact → Notes", "Ticket → Related Articles",
|
|
9
|
+
* "Post → Related Posts". Apps supply the item data and a renderer; the card
|
|
10
|
+
* provides consistent header + list + empty-state + view-all chrome. The host
|
|
11
|
+
* IS the Card's `<div>` (`div[mol-related-items-card]`), matching React's root
|
|
12
|
+
* exactly; the Card classes (`cm.card({ variant: 'elevated' })` +
|
|
13
|
+
* `cm.cardPadding('md')`, the UI Card's defaults) are applied through the host
|
|
14
|
+
* class binding.
|
|
15
|
+
*
|
|
16
|
+
* Node props are projected content: `icon` and `title` render inside the
|
|
17
|
+
* header (icon first, then the `<h3>`), `headerActions` inside the right-hand
|
|
18
|
+
* header row before the "View all" link, and `emptyState` in the list's place
|
|
19
|
+
* when `items` is empty — bare, as React renders it. String inputs render as
|
|
20
|
+
* text instead. `onItemClick` makes the rows clickable (React's mouse-only
|
|
21
|
+
* `<li>` rows: no button semantics, no keyboard handler).
|
|
22
|
+
*/
|
|
23
|
+
export declare class RelatedItemsCard<T = unknown> implements AfterViewInit, DoCheck {
|
|
24
|
+
/** Card heading (string/number renders as text; nodes are `[slot=title]` content). */
|
|
25
|
+
title?: unknown;
|
|
26
|
+
/** Items to render. */
|
|
27
|
+
items: readonly T[];
|
|
28
|
+
/**
|
|
29
|
+
* Render function for each item, as a `TemplateRef` whose context carries
|
|
30
|
+
* the item as `$implicit`/`a0` and its index as `a1`.
|
|
31
|
+
*/
|
|
32
|
+
renderItem?: TemplateRef<unknown>;
|
|
33
|
+
/** Called when an item row is clicked (if applicable). */
|
|
34
|
+
onItemClick?: (item: T, index: number) => void;
|
|
35
|
+
/** Rendered when `items` is empty (string/number as text; nodes are `[slot=emptyState]` content). */
|
|
36
|
+
emptyState?: unknown;
|
|
37
|
+
/** Optional "View all" link rendered in the header. */
|
|
38
|
+
viewAllHref?: string;
|
|
39
|
+
/** Extra classes on the Card. */
|
|
40
|
+
className?: string;
|
|
41
|
+
/** `data-mol-id` for AI-agent selectors. */
|
|
42
|
+
dataMolId?: string;
|
|
43
|
+
/** The empty state's capture wrapper (revealed bare, or detached). */
|
|
44
|
+
emptySlot?: ElementRef<HTMLElement>;
|
|
45
|
+
/** The wrapper sync for the empty state. */
|
|
46
|
+
private readonly bare;
|
|
47
|
+
/**
|
|
48
|
+
* The current class map.
|
|
49
|
+
* @returns The UIClassMap.
|
|
50
|
+
*/
|
|
51
|
+
cm(): UIClassMap;
|
|
52
|
+
/**
|
|
53
|
+
* Computes the Card's class list (`cm.card({ variant: 'elevated' })` +
|
|
54
|
+
* `cm.cardPadding('md')` — the UI Card's defaults — plus `className`).
|
|
55
|
+
* @returns The class string.
|
|
56
|
+
*/
|
|
57
|
+
classes(): string;
|
|
58
|
+
/**
|
|
59
|
+
* The content column's class (`cm.stack(3)`).
|
|
60
|
+
* @returns The class string.
|
|
61
|
+
*/
|
|
62
|
+
stackClasses(): string;
|
|
63
|
+
/**
|
|
64
|
+
* The header row's class (`cm.flex({ justify: 'between', align: 'center', gap: 'sm' })`).
|
|
65
|
+
* @returns The class string.
|
|
66
|
+
*/
|
|
67
|
+
headerClasses(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Both header sections' class (`cm.flex({ align: 'center', gap: 'sm' })`).
|
|
70
|
+
* @returns The class string.
|
|
71
|
+
*/
|
|
72
|
+
headerSectionClasses(): string;
|
|
73
|
+
/**
|
|
74
|
+
* The title's class (`cm.textSize('base')` + `cm.fontWeight('semibold')`).
|
|
75
|
+
* @returns The class string.
|
|
76
|
+
*/
|
|
77
|
+
titleClasses(): string;
|
|
78
|
+
/**
|
|
79
|
+
* The "View all" link's class (`cm.textSize('sm')` + `cm.link`).
|
|
80
|
+
* @returns The class string.
|
|
81
|
+
*/
|
|
82
|
+
linkClasses(): string;
|
|
83
|
+
/**
|
|
84
|
+
* The list's class (`cm.stack(2)`).
|
|
85
|
+
* @returns The class string.
|
|
86
|
+
*/
|
|
87
|
+
listClasses(): string;
|
|
88
|
+
/**
|
|
89
|
+
* The rows' class: React adds `cm.cursorPointer` only when a row is clickable.
|
|
90
|
+
* @returns The class string, or null for no class attribute.
|
|
91
|
+
*/
|
|
92
|
+
rowClasses(): string | null;
|
|
93
|
+
/**
|
|
94
|
+
* The title input's text (React's `{title}` for a text child).
|
|
95
|
+
* @returns The text, or `''` for a node title.
|
|
96
|
+
*/
|
|
97
|
+
titleText(): string;
|
|
98
|
+
/**
|
|
99
|
+
* The empty state input's text (React's `{emptyState}` for a text child).
|
|
100
|
+
* @returns The text, or `''` for a node empty state.
|
|
101
|
+
*/
|
|
102
|
+
emptyStateText(): string;
|
|
103
|
+
/**
|
|
104
|
+
* The template context for one row: the item as `$implicit`/`a0`, its index
|
|
105
|
+
* as `a1` (React calls `renderItem(item, index)`).
|
|
106
|
+
* @param item - The row's item.
|
|
107
|
+
* @param index - The row's index.
|
|
108
|
+
* @returns The template context.
|
|
109
|
+
*/
|
|
110
|
+
rowContext(item: T, index: number): Record<string, unknown>;
|
|
111
|
+
/**
|
|
112
|
+
* Runs the row's click handler the way React calls `onItemClick(item, index)`.
|
|
113
|
+
* @param item - The row's item.
|
|
114
|
+
* @param index - The row's index.
|
|
115
|
+
*/
|
|
116
|
+
clickRow(item: T, index: number): void;
|
|
117
|
+
/** Captures the empty state's wrapper once the view has resolved. */
|
|
118
|
+
ngAfterViewInit(): void;
|
|
119
|
+
/** Re-syncs the empty state when `items` changes. */
|
|
120
|
+
ngDoCheck(): void;
|
|
121
|
+
/** Renders the empty state bare exactly while the list is empty. */
|
|
122
|
+
private syncEmptySlot;
|
|
123
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RelatedItemsCard<any>, never>;
|
|
124
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<RelatedItemsCard<any>, "div[mol-related-items-card]", never, { "title": { "alias": "title"; "required": false; }; "items": { "alias": "items"; "required": false; }; "renderItem": { "alias": "renderItem"; "required": false; }; "onItemClick": { "alias": "onItemClick"; "required": false; }; "emptyState": { "alias": "emptyState"; "required": false; }; "viewAllHref": { "alias": "viewAllHref"; "required": false; }; "className": { "alias": "className"; "required": false; }; "dataMolId": { "alias": "dataMolId"; "required": false; }; }, {}, never, ["[slot=icon]", "[slot=title]", "[slot=headerActions]", "[slot=emptyState]"], true, never>;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=related-items-card.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"related-items-card.component.d.ts","sourceRoot":"","sources":["../src/related-items-card.component.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,OAAO,EACZ,UAAU,EAGV,KAAK,WAAW,EAEjB,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;;AAKlD;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAkDa,gBAAgB,CAAC,CAAC,GAAG,OAAO,CAAE,YAAW,aAAa,EAAE,OAAO;IAC1E,sFAAsF;IACtF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,uBAAuB;IACvB,KAAK,EAAE,SAAS,CAAC,EAAE,CAAK;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;IACjC,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;CAgK5B"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RelatedItemsCard component (React parity).
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
7
|
+
import { Component, ElementRef, inject, Renderer2, ViewChild, } from '@angular/core';
|
|
8
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
9
|
+
import { BareSlot } from './slot-dom.js';
|
|
10
|
+
import * as i0 from "@angular/core";
|
|
11
|
+
const _c0 = ["emptySlot"];
|
|
12
|
+
const _c1 = [[["", "slot", "icon"]], [["", "slot", "title"]], [["", "slot", "headeractions"]], [["", "slot", "emptystate"]]];
|
|
13
|
+
const _c2 = ["[slot=icon]", "[slot=title]", "[slot=headerActions]", "[slot=emptyState]"];
|
|
14
|
+
function RelatedItemsCard_Conditional_9_Template(rf, ctx) { if (rf & 1) {
|
|
15
|
+
i0.ɵɵelementStart(0, "a");
|
|
16
|
+
i0.ɵɵtext(1, "View all");
|
|
17
|
+
i0.ɵɵelementEnd();
|
|
18
|
+
} if (rf & 2) {
|
|
19
|
+
const ctx_r0 = i0.ɵɵnextContext();
|
|
20
|
+
i0.ɵɵclassMap(ctx_r0.linkClasses());
|
|
21
|
+
i0.ɵɵattribute("href", ctx_r0.viewAllHref, i0.ɵɵsanitizeUrl);
|
|
22
|
+
} }
|
|
23
|
+
function RelatedItemsCard_Conditional_10_For_2_Template(rf, ctx) { if (rf & 1) {
|
|
24
|
+
const _r2 = i0.ɵɵgetCurrentView();
|
|
25
|
+
i0.ɵɵelementStart(0, "li", 2);
|
|
26
|
+
i0.ɵɵlistener("click", function RelatedItemsCard_Conditional_10_For_2_Template_li_click_0_listener() { const ctx_r2 = i0.ɵɵrestoreView(_r2); const item_r4 = ctx_r2.$implicit; const $index_r5 = ctx_r2.$index; const ctx_r0 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r0.clickRow(item_r4, $index_r5)); });
|
|
27
|
+
i0.ɵɵelementContainer(1, 3);
|
|
28
|
+
i0.ɵɵelementEnd();
|
|
29
|
+
} if (rf & 2) {
|
|
30
|
+
const item_r4 = ctx.$implicit;
|
|
31
|
+
const $index_r5 = ctx.$index;
|
|
32
|
+
const ctx_r0 = i0.ɵɵnextContext(2);
|
|
33
|
+
i0.ɵɵclassMap(ctx_r0.rowClasses());
|
|
34
|
+
i0.ɵɵadvance();
|
|
35
|
+
i0.ɵɵproperty("ngTemplateOutlet", ctx_r0.renderItem ?? null)("ngTemplateOutletContext", ctx_r0.rowContext(item_r4, $index_r5));
|
|
36
|
+
} }
|
|
37
|
+
function RelatedItemsCard_Conditional_10_Template(rf, ctx) { if (rf & 1) {
|
|
38
|
+
i0.ɵɵelementStart(0, "ul");
|
|
39
|
+
i0.ɵɵrepeaterCreate(1, RelatedItemsCard_Conditional_10_For_2_Template, 2, 4, "li", 1, i0.ɵɵrepeaterTrackByIndex);
|
|
40
|
+
i0.ɵɵelementEnd();
|
|
41
|
+
} if (rf & 2) {
|
|
42
|
+
const ctx_r0 = i0.ɵɵnextContext();
|
|
43
|
+
i0.ɵɵclassMap(ctx_r0.listClasses());
|
|
44
|
+
i0.ɵɵadvance();
|
|
45
|
+
i0.ɵɵrepeater(ctx_r0.items);
|
|
46
|
+
} }
|
|
47
|
+
/**
|
|
48
|
+
* RelatedItemsCard component.
|
|
49
|
+
*
|
|
50
|
+
* Card container for a list of cross-linked / related items. Common usage:
|
|
51
|
+
* "Company → Deals", "Contact → Notes", "Ticket → Related Articles",
|
|
52
|
+
* "Post → Related Posts". Apps supply the item data and a renderer; the card
|
|
53
|
+
* provides consistent header + list + empty-state + view-all chrome. The host
|
|
54
|
+
* IS the Card's `<div>` (`div[mol-related-items-card]`), matching React's root
|
|
55
|
+
* exactly; the Card classes (`cm.card({ variant: 'elevated' })` +
|
|
56
|
+
* `cm.cardPadding('md')`, the UI Card's defaults) are applied through the host
|
|
57
|
+
* class binding.
|
|
58
|
+
*
|
|
59
|
+
* Node props are projected content: `icon` and `title` render inside the
|
|
60
|
+
* header (icon first, then the `<h3>`), `headerActions` inside the right-hand
|
|
61
|
+
* header row before the "View all" link, and `emptyState` in the list's place
|
|
62
|
+
* when `items` is empty — bare, as React renders it. String inputs render as
|
|
63
|
+
* text instead. `onItemClick` makes the rows clickable (React's mouse-only
|
|
64
|
+
* `<li>` rows: no button semantics, no keyboard handler).
|
|
65
|
+
*/
|
|
66
|
+
export class RelatedItemsCard {
|
|
67
|
+
/** Card heading (string/number renders as text; nodes are `[slot=title]` content). */
|
|
68
|
+
title;
|
|
69
|
+
/** Items to render. */
|
|
70
|
+
items = [];
|
|
71
|
+
/**
|
|
72
|
+
* Render function for each item, as a `TemplateRef` whose context carries
|
|
73
|
+
* the item as `$implicit`/`a0` and its index as `a1`.
|
|
74
|
+
*/
|
|
75
|
+
renderItem;
|
|
76
|
+
/** Called when an item row is clicked (if applicable). */
|
|
77
|
+
onItemClick;
|
|
78
|
+
/** Rendered when `items` is empty (string/number as text; nodes are `[slot=emptyState]` content). */
|
|
79
|
+
emptyState;
|
|
80
|
+
/** Optional "View all" link rendered in the header. */
|
|
81
|
+
viewAllHref;
|
|
82
|
+
/** Extra classes on the Card. */
|
|
83
|
+
className;
|
|
84
|
+
/** `data-mol-id` for AI-agent selectors. */
|
|
85
|
+
dataMolId;
|
|
86
|
+
/** The empty state's capture wrapper (revealed bare, or detached). */
|
|
87
|
+
emptySlot;
|
|
88
|
+
/** The wrapper sync for the empty state. */
|
|
89
|
+
bare = new BareSlot(inject(ElementRef), inject(Renderer2));
|
|
90
|
+
/**
|
|
91
|
+
* The current class map.
|
|
92
|
+
* @returns The UIClassMap.
|
|
93
|
+
*/
|
|
94
|
+
cm() {
|
|
95
|
+
return getClassMap();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Computes the Card's class list (`cm.card({ variant: 'elevated' })` +
|
|
99
|
+
* `cm.cardPadding('md')` — the UI Card's defaults — plus `className`).
|
|
100
|
+
* @returns The class string.
|
|
101
|
+
*/
|
|
102
|
+
classes() {
|
|
103
|
+
return this.cm().cn(this.cm().card({ variant: 'elevated' }), this.cm().cardPadding('md'), this.className);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The content column's class (`cm.stack(3)`).
|
|
107
|
+
* @returns The class string.
|
|
108
|
+
*/
|
|
109
|
+
stackClasses() {
|
|
110
|
+
return this.cm().stack(3);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The header row's class (`cm.flex({ justify: 'between', align: 'center', gap: 'sm' })`).
|
|
114
|
+
* @returns The class string.
|
|
115
|
+
*/
|
|
116
|
+
headerClasses() {
|
|
117
|
+
return this.cm().flex({ justify: 'between', align: 'center', gap: 'sm' });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Both header sections' class (`cm.flex({ align: 'center', gap: 'sm' })`).
|
|
121
|
+
* @returns The class string.
|
|
122
|
+
*/
|
|
123
|
+
headerSectionClasses() {
|
|
124
|
+
return this.cm().flex({ align: 'center', gap: 'sm' });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The title's class (`cm.textSize('base')` + `cm.fontWeight('semibold')`).
|
|
128
|
+
* @returns The class string.
|
|
129
|
+
*/
|
|
130
|
+
titleClasses() {
|
|
131
|
+
return this.cm().cn(this.cm().textSize('base'), this.cm().fontWeight('semibold'));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The "View all" link's class (`cm.textSize('sm')` + `cm.link`).
|
|
135
|
+
* @returns The class string.
|
|
136
|
+
*/
|
|
137
|
+
linkClasses() {
|
|
138
|
+
return this.cm().cn(this.cm().textSize('sm'), this.cm().link);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The list's class (`cm.stack(2)`).
|
|
142
|
+
* @returns The class string.
|
|
143
|
+
*/
|
|
144
|
+
listClasses() {
|
|
145
|
+
return this.cm().stack(2);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The rows' class: React adds `cm.cursorPointer` only when a row is clickable.
|
|
149
|
+
* @returns The class string, or null for no class attribute.
|
|
150
|
+
*/
|
|
151
|
+
rowClasses() {
|
|
152
|
+
return this.onItemClick ? this.cm().cn(this.cm().cursorPointer) : null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The title input's text (React's `{title}` for a text child).
|
|
156
|
+
* @returns The text, or `''` for a node title.
|
|
157
|
+
*/
|
|
158
|
+
titleText() {
|
|
159
|
+
return typeof this.title === 'string' || typeof this.title === 'number'
|
|
160
|
+
? String(this.title)
|
|
161
|
+
: '';
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The empty state input's text (React's `{emptyState}` for a text child).
|
|
165
|
+
* @returns The text, or `''` for a node empty state.
|
|
166
|
+
*/
|
|
167
|
+
emptyStateText() {
|
|
168
|
+
return typeof this.emptyState === 'string' || typeof this.emptyState === 'number'
|
|
169
|
+
? String(this.emptyState)
|
|
170
|
+
: '';
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The template context for one row: the item as `$implicit`/`a0`, its index
|
|
174
|
+
* as `a1` (React calls `renderItem(item, index)`).
|
|
175
|
+
* @param item - The row's item.
|
|
176
|
+
* @param index - The row's index.
|
|
177
|
+
* @returns The template context.
|
|
178
|
+
*/
|
|
179
|
+
rowContext(item, index) {
|
|
180
|
+
return { $implicit: item, a0: item, a1: index, a2: undefined };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Runs the row's click handler the way React calls `onItemClick(item, index)`.
|
|
184
|
+
* @param item - The row's item.
|
|
185
|
+
* @param index - The row's index.
|
|
186
|
+
*/
|
|
187
|
+
clickRow(item, index) {
|
|
188
|
+
this.onItemClick?.(item, index);
|
|
189
|
+
}
|
|
190
|
+
/** Captures the empty state's wrapper once the view has resolved. */
|
|
191
|
+
ngAfterViewInit() {
|
|
192
|
+
this.syncEmptySlot();
|
|
193
|
+
}
|
|
194
|
+
/** Re-syncs the empty state when `items` changes. */
|
|
195
|
+
ngDoCheck() {
|
|
196
|
+
this.syncEmptySlot();
|
|
197
|
+
}
|
|
198
|
+
/** Renders the empty state bare exactly while the list is empty. */
|
|
199
|
+
syncEmptySlot() {
|
|
200
|
+
const slot = this.emptySlot?.nativeElement;
|
|
201
|
+
if (!slot)
|
|
202
|
+
return;
|
|
203
|
+
this.bare.sync(slot, this.items.length === 0);
|
|
204
|
+
}
|
|
205
|
+
static ɵfac = function RelatedItemsCard_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || RelatedItemsCard)(); };
|
|
206
|
+
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: RelatedItemsCard, selectors: [["div", "mol-related-items-card", ""]], viewQuery: function RelatedItemsCard_Query(rf, ctx) { if (rf & 1) {
|
|
207
|
+
i0.ɵɵviewQuery(_c0, 5);
|
|
208
|
+
} if (rf & 2) {
|
|
209
|
+
let _t;
|
|
210
|
+
i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.emptySlot = _t.first);
|
|
211
|
+
} }, hostVars: 3, hostBindings: function RelatedItemsCard_HostBindings(rf, ctx) { if (rf & 2) {
|
|
212
|
+
i0.ɵɵattribute("data-mol-id", ctx.dataMolId ?? null);
|
|
213
|
+
i0.ɵɵclassMap(ctx.classes());
|
|
214
|
+
} }, inputs: { title: "title", items: "items", renderItem: "renderItem", onItemClick: "onItemClick", emptyState: "emptyState", viewAllHref: "viewAllHref", className: "className", dataMolId: "dataMolId" }, ngContentSelectors: _c2, decls: 15, vars: 14, consts: [["emptySlot", ""], [3, "class"], [3, "click"], [3, "ngTemplateOutlet", "ngTemplateOutletContext"]], template: function RelatedItemsCard_Template(rf, ctx) { if (rf & 1) {
|
|
215
|
+
i0.ɵɵprojectionDef(_c1);
|
|
216
|
+
i0.ɵɵelementStart(0, "div")(1, "header")(2, "div");
|
|
217
|
+
i0.ɵɵprojection(3);
|
|
218
|
+
i0.ɵɵelementStart(4, "h3");
|
|
219
|
+
i0.ɵɵtext(5);
|
|
220
|
+
i0.ɵɵprojection(6, 1);
|
|
221
|
+
i0.ɵɵelementEnd()();
|
|
222
|
+
i0.ɵɵelementStart(7, "div");
|
|
223
|
+
i0.ɵɵprojection(8, 2);
|
|
224
|
+
i0.ɵɵconditionalCreate(9, RelatedItemsCard_Conditional_9_Template, 2, 3, "a", 1);
|
|
225
|
+
i0.ɵɵelementEnd()();
|
|
226
|
+
i0.ɵɵconditionalCreate(10, RelatedItemsCard_Conditional_10_Template, 3, 2, "ul", 1);
|
|
227
|
+
i0.ɵɵelementStart(11, "span", null, 0);
|
|
228
|
+
i0.ɵɵprojection(13, 3);
|
|
229
|
+
i0.ɵɵtext(14);
|
|
230
|
+
i0.ɵɵelementEnd()();
|
|
231
|
+
} if (rf & 2) {
|
|
232
|
+
i0.ɵɵclassMap(ctx.stackClasses());
|
|
233
|
+
i0.ɵɵadvance();
|
|
234
|
+
i0.ɵɵclassMap(ctx.headerClasses());
|
|
235
|
+
i0.ɵɵadvance();
|
|
236
|
+
i0.ɵɵclassMap(ctx.headerSectionClasses());
|
|
237
|
+
i0.ɵɵadvance(2);
|
|
238
|
+
i0.ɵɵclassMap(ctx.titleClasses());
|
|
239
|
+
i0.ɵɵadvance();
|
|
240
|
+
i0.ɵɵtextInterpolate1(" ", ctx.titleText());
|
|
241
|
+
i0.ɵɵadvance(2);
|
|
242
|
+
i0.ɵɵclassMap(ctx.headerSectionClasses());
|
|
243
|
+
i0.ɵɵadvance(2);
|
|
244
|
+
i0.ɵɵconditional(ctx.viewAllHref ? 9 : -1);
|
|
245
|
+
i0.ɵɵadvance();
|
|
246
|
+
i0.ɵɵconditional(ctx.items.length > 0 ? 10 : -1);
|
|
247
|
+
i0.ɵɵadvance(4);
|
|
248
|
+
i0.ɵɵtextInterpolate(ctx.emptyStateText());
|
|
249
|
+
} }, dependencies: [NgTemplateOutlet], encapsulation: 2 });
|
|
250
|
+
}
|
|
251
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(RelatedItemsCard, [{
|
|
252
|
+
type: Component,
|
|
253
|
+
args: [{
|
|
254
|
+
selector: 'div[mol-related-items-card]',
|
|
255
|
+
standalone: true,
|
|
256
|
+
imports: [NgTemplateOutlet],
|
|
257
|
+
inputs: [
|
|
258
|
+
'title',
|
|
259
|
+
'items',
|
|
260
|
+
'renderItem',
|
|
261
|
+
'onItemClick',
|
|
262
|
+
'emptyState',
|
|
263
|
+
'viewAllHref',
|
|
264
|
+
'className',
|
|
265
|
+
'dataMolId',
|
|
266
|
+
],
|
|
267
|
+
host: {
|
|
268
|
+
'[class]': 'classes()',
|
|
269
|
+
'[attr.data-mol-id]': 'dataMolId ?? null',
|
|
270
|
+
},
|
|
271
|
+
template: `<div [class]="stackClasses()">
|
|
272
|
+
<header [class]="headerClasses()">
|
|
273
|
+
<div [class]="headerSectionClasses()">
|
|
274
|
+
<ng-content select="[slot=icon]"></ng-content>
|
|
275
|
+
<h3 [class]="titleClasses()">
|
|
276
|
+
{{ titleText() }}<ng-content select="[slot=title]"></ng-content>
|
|
277
|
+
</h3>
|
|
278
|
+
</div>
|
|
279
|
+
<div [class]="headerSectionClasses()">
|
|
280
|
+
<ng-content select="[slot=headerActions]"></ng-content>
|
|
281
|
+
@if (viewAllHref) {
|
|
282
|
+
<a [attr.href]="viewAllHref" [class]="linkClasses()">View all</a>
|
|
283
|
+
}
|
|
284
|
+
</div>
|
|
285
|
+
</header>
|
|
286
|
+
@if (items.length > 0) {
|
|
287
|
+
<ul [class]="listClasses()">
|
|
288
|
+
@for (item of items; track $index) {
|
|
289
|
+
<li [class]="rowClasses()" (click)="clickRow(item, $index)">
|
|
290
|
+
<ng-container
|
|
291
|
+
[ngTemplateOutlet]="renderItem ?? null"
|
|
292
|
+
[ngTemplateOutletContext]="rowContext(item, $index)"
|
|
293
|
+
></ng-container>
|
|
294
|
+
</li>
|
|
295
|
+
}
|
|
296
|
+
</ul>
|
|
297
|
+
}
|
|
298
|
+
<span #emptySlot
|
|
299
|
+
><ng-content select="[slot=emptyState]"></ng-content>{{ emptyStateText() }}</span
|
|
300
|
+
>
|
|
301
|
+
</div>`,
|
|
302
|
+
}]
|
|
303
|
+
}], null, { emptySlot: [{
|
|
304
|
+
type: ViewChild,
|
|
305
|
+
args: ['emptySlot']
|
|
306
|
+
}] }); })();
|
|
307
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(RelatedItemsCard, { className: "RelatedItemsCard", filePath: "related-items-card.component.ts", lineNumber: 93 }); })();
|
|
308
|
+
//# sourceMappingURL=related-items-card.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"related-items-card.component.js","sourceRoot":"","sources":["../src/related-items-card.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAEL,SAAS,EAET,UAAU,EACV,MAAM,EACN,SAAS,EAET,SAAS,GACV,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;;;;;;IAkD9B,yBAAqD;IAAA,wBAAQ;IAAA,iBAAI;;;IAApC,mCAAuB;;;;;IAOpD,6BAA4D;IAAjC,0QAAS,mCAAsB,KAAC;IACzD,2BAGgB;IAClB,iBAAK;;;;;IALD,kCAAsB;IAEtB,cAAuC;IACvC,AADA,4DAAuC,kEACa;;;IAL5D,0BAA4B;IAC1B,gHAOC;IACH,iBAAK;;;IATD,mCAAuB;IACzB,cAOC;IAPD,2BAOC;;AA7DT;;;;;;;;;;;;;;;;;;GAkBG;AAmDH,MAAM,OAAO,gBAAgB;IAC3B,sFAAsF;IACtF,KAAK,CAAU;IACf,uBAAuB;IACvB,KAAK,GAAiB,EAAE,CAAA;IACxB;;;OAGG;IACH,UAAU,CAAuB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CAAC;gBAC3B,MAAM,EAAE;oBACN,OAAO;oBACP,OAAO;oBACP,YAAY;oBACZ,aAAa;oBACb,YAAY;oBACZ,aAAa;oBACb,WAAW;oBACX,WAAW;iBACZ;gBACD,IAAI,EAAE;oBACJ,SAAS,EAAE,WAAW;oBACtB,oBAAoB,EAAE,mBAAmB;iBAC1C;gBACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA8BH;aACR;;kBAuBE,SAAS;mBAAC,WAAW;;kFAtBX,gBAAgB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM helpers for the projected-slot wrapper of {@link RelatedItemsCard}.
|
|
3
|
+
*
|
|
4
|
+
* React renders `emptyState` bare — with no element around it — when `items`
|
|
5
|
+
* is empty, and nothing at all when it is not. Angular projection needs an
|
|
6
|
+
* always-mounted `<ng-content>` capture point, so the wrapper span lives in
|
|
7
|
+
* the template unconditionally and {@link BareSlot} reconciles it against
|
|
8
|
+
* React's DOM: the projected nodes move out beside an anchor comment (React's
|
|
9
|
+
* bare render), or travel back into the detached wrapper (React renders
|
|
10
|
+
* nothing). Both directions are reversible, because `items` can change while
|
|
11
|
+
* the component stays mounted.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import type { ElementRef, Renderer2 } from '@angular/core';
|
|
16
|
+
/**
|
|
17
|
+
* Reconciles one capture wrapper against what React renders: its content
|
|
18
|
+
* bare, or nothing.
|
|
19
|
+
*/
|
|
20
|
+
export declare class BareSlot {
|
|
21
|
+
private readonly host;
|
|
22
|
+
private readonly renderer;
|
|
23
|
+
private readonly states;
|
|
24
|
+
/**
|
|
25
|
+
* Creates the wrapper helper.
|
|
26
|
+
*
|
|
27
|
+
* @param host - The component host element (fallback parent for a wrapper
|
|
28
|
+
* that has already been detached).
|
|
29
|
+
* @param renderer - The DOM renderer.
|
|
30
|
+
*/
|
|
31
|
+
constructor(host: ElementRef<HTMLElement>, renderer: Renderer2);
|
|
32
|
+
/**
|
|
33
|
+
* Shows the wrapper's content bare, or takes it out of the DOM.
|
|
34
|
+
*
|
|
35
|
+
* @param el - The capture wrapper.
|
|
36
|
+
* @param shouldShow - Whether React renders the content.
|
|
37
|
+
*/
|
|
38
|
+
sync(el: Element | undefined | null, shouldShow: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* Moves the captured nodes beside the anchor and detaches the wrapper.
|
|
41
|
+
*
|
|
42
|
+
* @param el - The capture wrapper.
|
|
43
|
+
* @param state - Its captured content.
|
|
44
|
+
*/
|
|
45
|
+
private reveal;
|
|
46
|
+
/**
|
|
47
|
+
* Moves the captured nodes back into the wrapper and detaches it with them.
|
|
48
|
+
*
|
|
49
|
+
* @param el - The capture wrapper.
|
|
50
|
+
* @param state - Its captured content.
|
|
51
|
+
*/
|
|
52
|
+
private withhold;
|
|
53
|
+
}
|
|
54
|
+
//# 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;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAc1D;;;GAGG;AACH,qBAAa,QAAQ;IAWjB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAX3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoC;IAE3D;;;;;;OAMG;gBAEgB,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,EAC7B,QAAQ,EAAE,SAAS;IAGtC;;;;;OAKG;IACH,IAAI,CAAC,EAAE,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,EAAE,UAAU,EAAE,OAAO,GAAG,IAAI;IAc/D;;;;;OAKG;IACH,OAAO,CAAC,MAAM;IAQd;;;;;OAKG;IACH,OAAO,CAAC,QAAQ;CAOjB"}
|
package/dist/slot-dom.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM helpers for the projected-slot wrapper of {@link RelatedItemsCard}.
|
|
3
|
+
*
|
|
4
|
+
* React renders `emptyState` bare — with no element around it — when `items`
|
|
5
|
+
* is empty, and nothing at all when it is not. Angular projection needs an
|
|
6
|
+
* always-mounted `<ng-content>` capture point, so the wrapper span lives in
|
|
7
|
+
* the template unconditionally and {@link BareSlot} reconciles it against
|
|
8
|
+
* React's DOM: the projected nodes move out beside an anchor comment (React's
|
|
9
|
+
* bare render), or travel back into the detached wrapper (React renders
|
|
10
|
+
* nothing). Both directions are reversible, because `items` can change while
|
|
11
|
+
* the component stays mounted.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Reconciles one capture wrapper against what React renders: its content
|
|
17
|
+
* bare, or nothing.
|
|
18
|
+
*/
|
|
19
|
+
export class BareSlot {
|
|
20
|
+
host;
|
|
21
|
+
renderer;
|
|
22
|
+
states = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* Creates the wrapper helper.
|
|
25
|
+
*
|
|
26
|
+
* @param host - The component host element (fallback parent for a wrapper
|
|
27
|
+
* that has already been detached).
|
|
28
|
+
* @param renderer - The DOM renderer.
|
|
29
|
+
*/
|
|
30
|
+
constructor(host, renderer) {
|
|
31
|
+
this.host = host;
|
|
32
|
+
this.renderer = renderer;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Shows the wrapper's content bare, or takes it out of the DOM.
|
|
36
|
+
*
|
|
37
|
+
* @param el - The capture wrapper.
|
|
38
|
+
* @param shouldShow - Whether React renders the content.
|
|
39
|
+
*/
|
|
40
|
+
sync(el, shouldShow) {
|
|
41
|
+
if (!el)
|
|
42
|
+
return;
|
|
43
|
+
let state = this.states.get(el);
|
|
44
|
+
if (!state) {
|
|
45
|
+
const parent = el.parentElement ?? this.host.nativeElement;
|
|
46
|
+
const anchor = this.renderer.createComment('empty-state');
|
|
47
|
+
parent.insertBefore(anchor, el);
|
|
48
|
+
state = { nodes: Array.from(el.childNodes), parent, anchor, revealed: false };
|
|
49
|
+
this.states.set(el, state);
|
|
50
|
+
}
|
|
51
|
+
if (shouldShow)
|
|
52
|
+
this.reveal(el, state);
|
|
53
|
+
else
|
|
54
|
+
this.withhold(el, state);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Moves the captured nodes beside the anchor and detaches the wrapper.
|
|
58
|
+
*
|
|
59
|
+
* @param el - The capture wrapper.
|
|
60
|
+
* @param state - Its captured content.
|
|
61
|
+
*/
|
|
62
|
+
reveal(el, state) {
|
|
63
|
+
if (!state.revealed) {
|
|
64
|
+
for (const node of state.nodes)
|
|
65
|
+
state.parent.insertBefore(node, state.anchor);
|
|
66
|
+
state.revealed = true;
|
|
67
|
+
}
|
|
68
|
+
if (el.isConnected)
|
|
69
|
+
this.renderer.removeChild(state.parent, el);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Moves the captured nodes back into the wrapper and detaches it with them.
|
|
73
|
+
*
|
|
74
|
+
* @param el - The capture wrapper.
|
|
75
|
+
* @param state - Its captured content.
|
|
76
|
+
*/
|
|
77
|
+
withhold(el, state) {
|
|
78
|
+
if (state.revealed) {
|
|
79
|
+
for (const node of state.nodes)
|
|
80
|
+
this.renderer.appendChild(el, node);
|
|
81
|
+
state.revealed = false;
|
|
82
|
+
}
|
|
83
|
+
if (el.isConnected)
|
|
84
|
+
this.renderer.removeChild(state.parent, el);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=slot-dom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot-dom.js","sourceRoot":"","sources":["../src/slot-dom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgBH;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAWA;IACA;IAXF,M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