@fluid-topics/ft-reader-breadcrumbs 1.3.12

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 ADDED
@@ -0,0 +1,19 @@
1
+ A component to display current visible topic breadcrumbs
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ft-reader-breadcrumbs
7
+ yarn add @fluid-topics/ft-reader-breadcrumbs
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ft-reader-breadcrumbs"
15
+
16
+ function render() {
17
+ return html` <ft-reader-breadcrumbs foo="bar"></ft-reader-breadcrumbs> `
18
+ }
19
+ ```
@@ -0,0 +1,7 @@
1
+ import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n/build/generator/I18nMessageContext";
2
+ export interface ReaderBreadcrumbsMessage extends I18nMessages {
3
+ navAriaLabel(): string;
4
+ menuShowMore(): string;
5
+ }
6
+ export declare const readerBreadcrumbsContext: I18nMessageContext<ReaderBreadcrumbsMessage>;
7
+ export declare const readerBreadcrumbsDefaultMessages: DefaultI18nMessages<ReaderBreadcrumbsMessage>;
@@ -0,0 +1,6 @@
1
+ import { I18nMessageContext } from "@fluid-topics/ft-i18n/build/generator/I18nMessageContext";
2
+ export const readerBreadcrumbsContext = I18nMessageContext.build("readerBreadcrumbs");
3
+ export const readerBreadcrumbsDefaultMessages = {
4
+ navAriaLabel: "Breadcrumb",
5
+ menuShowMore: "Show more",
6
+ };
@@ -0,0 +1,30 @@
1
+ import { PropertyValues } from "lit";
2
+ import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
+ import { FtReaderBreadcrumbsProperties } from "./ft-reader-breadcrumbs.properties";
4
+ import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
5
+ declare const FtReaderBreadcrumbs_base: typeof FtReaderComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
6
+ export declare class FtReaderBreadcrumbs extends FtReaderBreadcrumbs_base implements FtReaderBreadcrumbsProperties {
7
+ static elementDefinitions: ElementDefinitionsMap;
8
+ static styles: import("lit").CSSResult;
9
+ separator: string;
10
+ displayMapTitle?: boolean;
11
+ multiline?: boolean;
12
+ useFloatingMenu?: boolean;
13
+ floatingMenuThreshold?: number;
14
+ floatingMenuStartOffset?: number;
15
+ floatingMenuEndOffset?: number;
16
+ private tocId?;
17
+ private mapTitle?;
18
+ private breadcrumb;
19
+ private ftFloatingMenu?;
20
+ constructor();
21
+ protected willUpdate(props: PropertyValues): void;
22
+ protected render(): import("lit-html").TemplateResult<1>;
23
+ private renderBreadcrumbs;
24
+ private renderBreadcrumbArray;
25
+ private renderFloatingMenu;
26
+ private renderSeparator;
27
+ private renderBreadcrumbLink;
28
+ private renderBreadcrumbCurrentItem;
29
+ }
30
+ export {};
@@ -0,0 +1,171 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, nothing } from "lit";
8
+ import { property, query, state } from "lit/decorators.js";
9
+ import { repeat } from "lit/directives/repeat.js";
10
+ import { when } from "lit/directives/when.js";
11
+ import { classMap } from "lit/directives/class-map.js";
12
+ import { redux } from "@fluid-topics/ft-wc-utils";
13
+ import { styles } from "./ft-reader-breadcrumbs.styles";
14
+ import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
15
+ import { FtReaderInternalLink } from "@fluid-topics/ft-reader-internal-link";
16
+ import { FtTypography, FtTypographyVariants } from "@fluid-topics/ft-typography";
17
+ import { splitBreadcrumbForMenu } from "./helpers/FtReaderBreadcrumbsMenuHelper";
18
+ import { FtFloatingMenu, FtFloatingMenuItem } from "@fluid-topics/ft-floating-menu";
19
+ import { withI18n } from "@fluid-topics/ft-i18n";
20
+ import { readerBreadcrumbsContext, readerBreadcrumbsDefaultMessages } from "./ReaderBreadcrumbsMessage";
21
+ import { FtRipple } from "@fluid-topics/ft-ripple";
22
+ class FtReaderBreadcrumbs extends withI18n(FtReaderComponent) {
23
+ constructor() {
24
+ super();
25
+ this.separator = ">";
26
+ this.breadcrumb = [];
27
+ this.addI18nContext(readerBreadcrumbsContext, readerBreadcrumbsDefaultMessages);
28
+ }
29
+ willUpdate(props) {
30
+ var _a, _b, _c;
31
+ super.willUpdate(props);
32
+ if (props.has("tocId") && this.tocId !== undefined) {
33
+ this.breadcrumb = (_b = (_a = this.service) === null || _a === void 0 ? void 0 : _a.buildBreadcrumb(this.tocId)) !== null && _b !== void 0 ? _b : [];
34
+ }
35
+ if (props.has("breadcrumb")) {
36
+ (_c = this.ftFloatingMenu) === null || _c === void 0 ? void 0 : _c.closeMenu();
37
+ }
38
+ }
39
+ render() {
40
+ let breadcrumbs = this.breadcrumb;
41
+ if (this.displayMapTitle) {
42
+ breadcrumbs = [{ title: this.mapTitle, tocId: "root" }, ...this.breadcrumb];
43
+ }
44
+ const cssClasses = {
45
+ "ft-reader-breadcrumbs": true,
46
+ "multiline": !!this.multiline,
47
+ };
48
+ return html `
49
+ <nav part="breadcrumb-nav" class="${classMap(cssClasses)}" aria-label="${readerBreadcrumbsContext.messages.navAriaLabel()}">
50
+ <ol part="breadcrumb-list">
51
+ ${this.renderBreadcrumbs(breadcrumbs)}
52
+ </ol>
53
+ </nav>
54
+ `;
55
+ }
56
+ renderBreadcrumbs(breadcrumbs) {
57
+ var _a;
58
+ if (!this.useFloatingMenu || breadcrumbs.length < ((_a = this.floatingMenuThreshold) !== null && _a !== void 0 ? _a : 0)) {
59
+ return this.renderBreadcrumbArray(breadcrumbs, true);
60
+ }
61
+ const splitBreadcrumbs = splitBreadcrumbForMenu(breadcrumbs, this.floatingMenuStartOffset, this.floatingMenuEndOffset);
62
+ return html `
63
+ ${this.renderBreadcrumbArray(splitBreadcrumbs.beforeMenu, false)}
64
+ ${splitBreadcrumbs.beforeMenu.length > 0 ? this.renderSeparator() : nothing}
65
+ ${this.renderFloatingMenu(splitBreadcrumbs.inMenu)}
66
+ ${this.renderBreadcrumbArray(splitBreadcrumbs.afterMenu, true)}`;
67
+ }
68
+ renderBreadcrumbArray(breadcrumbs, displayLastElementAsCurrent) {
69
+ return repeat(breadcrumbs, (breadcrumb) => breadcrumb.tocId, (breadcrumb, index) => {
70
+ const isLastElement = index === breadcrumbs.length - 1;
71
+ return html `
72
+ <li>
73
+ ${when(isLastElement && displayLastElementAsCurrent, () => this.renderBreadcrumbCurrentItem(breadcrumb), () => this.renderBreadcrumbLink(breadcrumb))}
74
+ </li>
75
+ ${isLastElement ? nothing : this.renderSeparator()}`;
76
+ });
77
+ }
78
+ renderFloatingMenu(breadcrumbs) {
79
+ if (breadcrumbs.length === 0) {
80
+ return nothing;
81
+ }
82
+ return html `
83
+ <li class="menu">
84
+ <ft-floating-menu icon="" text="..." label="${readerBreadcrumbsContext.messages.menuShowMore()}">
85
+ ${repeat(breadcrumbs, (breadcrumb) => html `
86
+ <div class="menu-item">
87
+ <ft-ripple></ft-ripple>
88
+ ${this.renderBreadcrumbLink(breadcrumb)}
89
+ </div>`)}
90
+ </ft-floating-menu>
91
+ </li>
92
+ ${this.renderSeparator()}`;
93
+ }
94
+ renderSeparator() {
95
+ return html `
96
+ <li part="breadcrumb-separator" class="separator" aria-hidden="true">
97
+ <ft-typography element="span" variant="${FtTypographyVariants.body2}">
98
+ ${this.separator}
99
+ </ft-typography>
100
+ </li>`;
101
+ }
102
+ renderBreadcrumbLink(breadcrumb) {
103
+ return html `
104
+ <ft-reader-internal-link part="breadcrumb-link"
105
+ tocId="${breadcrumb.tocId}"
106
+ removeStyle>
107
+ <ft-typography title="${breadcrumb.title}" part="breadcrumb-link-label" variant="${FtTypographyVariants.body2}">
108
+ ${breadcrumb.title}
109
+ </ft-typography>
110
+ </ft-reader-internal-link>
111
+ `;
112
+ }
113
+ renderBreadcrumbCurrentItem(breadcrumb) {
114
+ return html `
115
+ <ft-typography
116
+ title="${breadcrumb.title}"
117
+ part="breadcrumb-current-item"
118
+ variant="${FtTypographyVariants.body2}"
119
+ aria-current="page">
120
+ ${breadcrumb.title}
121
+ </ft-typography>`;
122
+ }
123
+ }
124
+ FtReaderBreadcrumbs.elementDefinitions = {
125
+ "ft-typography": FtTypography,
126
+ "ft-reader-internal-link": FtReaderInternalLink,
127
+ "ft-floating-menu": FtFloatingMenu,
128
+ "ft-floating-menu-item": FtFloatingMenuItem,
129
+ "ft-ripple": FtRipple,
130
+ };
131
+ FtReaderBreadcrumbs.styles = styles;
132
+ __decorate([
133
+ property()
134
+ ], FtReaderBreadcrumbs.prototype, "separator", void 0);
135
+ __decorate([
136
+ property({ type: Boolean })
137
+ ], FtReaderBreadcrumbs.prototype, "displayMapTitle", void 0);
138
+ __decorate([
139
+ property({ type: Boolean })
140
+ ], FtReaderBreadcrumbs.prototype, "multiline", void 0);
141
+ __decorate([
142
+ property({ type: Boolean })
143
+ ], FtReaderBreadcrumbs.prototype, "useFloatingMenu", void 0);
144
+ __decorate([
145
+ property({ type: Number })
146
+ ], FtReaderBreadcrumbs.prototype, "floatingMenuThreshold", void 0);
147
+ __decorate([
148
+ property({ type: Number })
149
+ ], FtReaderBreadcrumbs.prototype, "floatingMenuStartOffset", void 0);
150
+ __decorate([
151
+ property({ type: Number })
152
+ ], FtReaderBreadcrumbs.prototype, "floatingMenuEndOffset", void 0);
153
+ __decorate([
154
+ redux({
155
+ store: "reader",
156
+ selector: (state) => state.visibleTopics[0],
157
+ })
158
+ ], FtReaderBreadcrumbs.prototype, "tocId", void 0);
159
+ __decorate([
160
+ redux({
161
+ store: "reader",
162
+ selector: (state) => { var _a; return (_a = state.map) === null || _a === void 0 ? void 0 : _a.title; },
163
+ })
164
+ ], FtReaderBreadcrumbs.prototype, "mapTitle", void 0);
165
+ __decorate([
166
+ state()
167
+ ], FtReaderBreadcrumbs.prototype, "breadcrumb", void 0);
168
+ __decorate([
169
+ query("ft-floating-menu")
170
+ ], FtReaderBreadcrumbs.prototype, "ftFloatingMenu", void 0);
171
+ export { FtReaderBreadcrumbs };