@fluid-topics/ft-reader-toc 2.2.5 → 2.2.7

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.
@@ -1,55 +1,13 @@
1
- import { PropertyValues, TemplateResult } from "lit";
1
+ import { TemplateResult } from "lit";
2
2
  import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
- import { FtReaderComponent, FtReaderPage, FtReaderTocNode } from "@fluid-topics/ft-reader-context/build/registration";
4
- import { FtIconVariants } from "@fluid-topics/ft-icon";
5
- import { FtSizeCategory } from "@fluid-topics/ft-size-watcher";
6
- import { FtReaderTocProperties } from "./ft-reader-toc.properties";
3
+ import { FtReaderTocNode } from "@fluid-topics/ft-reader-context/build/registration";
7
4
  import { FtPagesTocNode } from "@fluid-topics/ft-reader-context/build/store/model";
5
+ import { FtReaderBaseToc } from "./ft-reader-base-toc";
8
6
  type TocNode = FtReaderTocNode | FtPagesTocNode;
9
- declare const FtReaderToc_base: typeof FtReaderComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
10
- export declare class FtReaderToc extends FtReaderToc_base implements FtReaderTocProperties {
7
+ export declare class FtReaderToc extends FtReaderBaseToc {
11
8
  static elementDefinitions: ElementDefinitionsMap;
12
9
  static styles: import("lit").CSSResult;
13
- expanded: boolean;
14
- iconVariant: FtIconVariants;
15
- collapseIcon: string;
16
- expandIcon: string;
17
- leafNodeIconVariant: FtIconVariants;
18
- leafNodeIcon: string;
19
- expandCollapseAll: boolean;
20
- expandCollapseAllHideLabel: boolean;
21
- expandCollapseAllTrailingIcon: boolean;
22
- expandCollapseAllAlignment: "left" | "right" | "center" | "justify";
23
- expandCollapseAllHideIcon: boolean;
24
- expandCollapseAllIconVariant?: FtIconVariants;
25
- collapseAllIcon: string;
26
- expandAllIcon: string;
27
- autoCollapse: boolean;
28
- scrollCurrentTopicIntoView: boolean;
29
- scope: FtReaderTocProperties["scope"];
30
- empty: boolean;
31
- toc?: Array<TocNode>;
32
- currentPage?: FtReaderPage;
33
- highlightedTocIds?: string[];
34
- private translationLoading?;
35
- automaticallyExpandedNodes: Set<string>;
36
- manuallyExpandedNodes: Set<string>;
37
- manuallyCollapsedNodes: Set<string>;
38
- expandAll: boolean;
39
- viewportSize: FtSizeCategory;
40
- nodesToExpandExist: boolean;
41
- get isCurrentPageToc(): boolean;
42
- constructor();
43
- protected update(changedProperties: PropertyValues<FtReaderToc>): void;
44
- protected contentAvailableCallback(props: PropertyValues<FtReaderToc>): void;
45
10
  protected render(): TemplateResult<1>;
46
- private renderExpandCollapseAll;
47
- private renderNode;
48
- private buildAutomaticallyExpandedNodes;
49
- private manuallyToggle;
50
- private onViewportSizeChange;
51
- private toggleExpandCollapseAll;
52
- private getExpandCollapseAllTooltipPosition;
53
- private getLeafNodeIcon;
11
+ protected renderNode(node: TocNode): TemplateResult;
54
12
  }
55
13
  export {};
@@ -1,118 +1,31 @@
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
1
  import { html, nothing, } from "lit";
8
2
  import { map } from "lit/directives/map.js";
9
- import { classMap } from "lit/directives/class-map.js";
10
3
  import { styleMap } from "lit/directives/style-map.js";
11
4
  import { ifDefined } from "lit/directives/if-defined.js";
12
- import { property, state, } from "lit/decorators.js";
13
- import { hasChanged, redux, scrollHelper, } from "@fluid-topics/ft-wc-utils";
14
- import { FtReaderComponent, } from "@fluid-topics/ft-reader-context/build/registration";
15
5
  import { FtTypography } from "@fluid-topics/ft-typography";
16
6
  import { FtReaderInternalLink } from "@fluid-topics/ft-reader-internal-link";
17
- import { FtIcon, FtIconVariants, } from "@fluid-topics/ft-icon";
18
7
  import { FtButton } from "@fluid-topics/ft-button";
19
- import { FtSizeCategory, FtSizeWatcher, } from "@fluid-topics/ft-size-watcher";
8
+ import { FtSizeCategory } from "@fluid-topics/ft-size-watcher";
20
9
  import { FtReaderTocCssVariables, styles, } from "./ft-reader-toc.styles";
21
10
  import { FtSkeleton } from "@fluid-topics/ft-skeleton";
22
- import { withI18n } from "@fluid-topics/ft-i18n";
23
- import { readerToc, readerTocDefaultMessages, } from "./FtReaderTocMessages";
24
- export class FtReaderToc extends withI18n(FtReaderComponent) {
25
- get isCurrentPageToc() {
26
- return this.scope === "current-page";
27
- }
28
- constructor() {
29
- super();
30
- this.expanded = false;
31
- this.iconVariant = FtIconVariants.fluid_topics;
32
- this.collapseIcon = "MINUS";
33
- this.expandIcon = "PLUS";
34
- this.leafNodeIconVariant = FtIconVariants.fluid_topics;
35
- this.leafNodeIcon = "DOT";
36
- this.expandCollapseAll = false;
37
- this.expandCollapseAllHideLabel = false;
38
- this.expandCollapseAllTrailingIcon = false;
39
- this.expandCollapseAllAlignment = "left";
40
- this.expandCollapseAllHideIcon = false;
41
- this.collapseAllIcon = "ICON_COLLAPSE";
42
- this.expandAllIcon = "ICON_EXPAND";
43
- this.autoCollapse = false;
44
- this.scrollCurrentTopicIntoView = false;
45
- this.scope = "pages";
46
- this.empty = true;
47
- this.automaticallyExpandedNodes = new Set();
48
- this.manuallyExpandedNodes = new Set();
49
- this.manuallyCollapsedNodes = new Set();
50
- this.expandAll = false;
51
- this.viewportSize = FtSizeCategory.M;
52
- this.nodesToExpandExist = false;
53
- this.addI18nContext(readerToc, readerTocDefaultMessages);
54
- }
55
- update(changedProperties) {
56
- var _a, _b, _c;
57
- super.update(changedProperties);
58
- if (changedProperties.has("toc")) {
59
- this.nodesToExpandExist = ((_a = this.toc) !== null && _a !== void 0 ? _a : []).some((n) => n.children.length > 0);
60
- }
61
- if (changedProperties.has("highlightedTocIds") && !this.expanded) {
62
- this.automaticallyExpandedNodes = this.buildAutomaticallyExpandedNodes((_b = this.highlightedTocIds) !== null && _b !== void 0 ? _b : []);
63
- }
64
- this.empty = ((_c = this.toc) !== null && _c !== void 0 ? _c : []).length === 0;
65
- }
66
- contentAvailableCallback(props) {
67
- var _a, _b;
68
- super.contentAvailableCallback(props);
69
- if (this.scrollCurrentTopicIntoView && props.has("highlightedTocIds") && this.highlightedTocIds && ((_a = this.highlightedTocIds) === null || _a === void 0 ? void 0 : _a.length) > 0) {
70
- const target = (_b = this.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector(`[tocId="${this.highlightedTocIds[0]}"]`);
71
- if (target) {
72
- scrollHelper.scrollIntoViewIfPossible(target, { behavior: "instant", position: 0.25 });
73
- }
74
- }
75
- }
11
+ import { readerToc } from "./FtReaderTocMessages";
12
+ import { FtReaderBaseToc } from "./ft-reader-base-toc";
13
+ import { classMap } from "lit/directives/class-map.js";
14
+ export class FtReaderToc extends FtReaderBaseToc {
76
15
  render() {
77
- var _a;
78
- const classes = {
79
- "ft-reader-toc": true,
80
- "ft-reader-toc-mobile": this.viewportSize === FtSizeCategory.S,
81
- "ft-reader-toc-desktop": this.viewportSize !== FtSizeCategory.S,
82
- "ft-reader-toc-loaded": this.currentPage != null,
83
- "ft-reader-toc-expanded": this.expanded,
84
- };
16
+ var _a, _b;
85
17
  return html `
86
- <div class="${classMap(classes)}">
18
+ <div class="${classMap(this.tocClasses)}" role="tree" aria-label="${(_a = this.currentPage) === null || _a === void 0 ? void 0 : _a.title}">
87
19
  <ft-size-watcher @change=${this.onViewportSizeChange}></ft-size-watcher>
88
20
  ${this.renderExpandCollapseAll()}
89
- ${map((_a = this.toc) !== null && _a !== void 0 ? _a : [], (node) => this.renderNode(node))}
21
+ ${map((_b = this.toc) !== null && _b !== void 0 ? _b : [], (node) => this.renderNode(node))}
90
22
  </div>
91
23
  `;
92
24
  }
93
- renderExpandCollapseAll() {
94
- return this.expandCollapseAll && !this.expanded && this.nodesToExpandExist ? html `
95
- <div part="expand-collapse-all-container"
96
- class="ft-reader-toc-expand-collapse-all-container ft-reader-toc-expand-collapse-all-${this.expandCollapseAllAlignment}">
97
- <ft-button part="expand-collapse-all"
98
- class="ft-reader-toc--expand-collapse-all-button"
99
- iconVariant="${this.expandCollapseAllIconVariant}"
100
- icon="${this.expandCollapseAllHideIcon ? "" : (this.expandAll
101
- ? (this.collapseAllIcon || "ICON_COLLAPSE")
102
- : (this.expandAllIcon || "ICON_EXPAND"))}"
103
- label="${this.expandAll ? readerToc.messages.collapseAllLong() : readerToc.messages.expandAllLong()}"
104
- tooltipPosition="${this.getExpandCollapseAllTooltipPosition()}"
105
- ?trailingIcon=${this.expandCollapseAllTrailingIcon}
106
- @click=${() => this.toggleExpandCollapseAll()}>
107
- ${this.expandCollapseAllHideLabel ? "" : this.expandAll ? readerToc.messages.collapseAll() : readerToc.messages.expandAll()}
108
- </ft-button>
109
- </div>
110
- ` : nothing;
111
- }
112
25
  renderNode(node) {
113
26
  var _a, _b, _c;
114
27
  const isHighlighted = (_a = this.highlightedTocIds) === null || _a === void 0 ? void 0 : _a.includes(node.tocId);
115
- const isExpanded = this.expanded || this.manuallyExpandedNodes.has(node.tocId) || ((this.expandAll || this.automaticallyExpandedNodes.has(node.tocId)) && !this.manuallyCollapsedNodes.has(node.tocId));
28
+ const isExpanded = this.nodeIsExpanded(node);
116
29
  const canDisplayChildren = node.children.length > 0;
117
30
  const currentPageDepth = this.isCurrentPageToc ? ((_c = (_b = this.currentPage) === null || _b === void 0 ? void 0 : _b.breadcrumb.length) !== null && _c !== void 0 ? _c : 0) + 1 : 0;
118
31
  const tabNumber = node.depth - 1 - currentPageDepth;
@@ -164,161 +77,12 @@ export class FtReaderToc extends withI18n(FtReaderComponent) {
164
77
  </div>
165
78
  `;
166
79
  }
167
- buildAutomaticallyExpandedNodes(tocIdsToShow) {
168
- var _a, _b;
169
- const topicsToExpand = new Set(this.autoCollapse ? [] : this.automaticallyExpandedNodes);
170
- for (const tocIdToShow of tocIdsToShow) {
171
- let tocIdToExpand = tocIdToShow;
172
- while (tocIdToExpand && !topicsToExpand.has(tocIdToExpand)) {
173
- topicsToExpand.add(tocIdToExpand);
174
- this.manuallyCollapsedNodes.delete(tocIdToExpand);
175
- tocIdToExpand = (_b = (_a = this.service) === null || _a === void 0 ? void 0 : _a.getTocNodeNow(tocIdToExpand)) === null || _b === void 0 ? void 0 : _b.parentTocId;
176
- }
177
- }
178
- return topicsToExpand;
179
- }
180
- manuallyToggle(tocId, isExpanded) {
181
- if (isExpanded) {
182
- this.manuallyCollapsedNodes.add(tocId);
183
- this.manuallyExpandedNodes.delete(tocId);
184
- }
185
- else {
186
- this.manuallyExpandedNodes.add(tocId);
187
- this.manuallyCollapsedNodes.delete(tocId);
188
- }
189
- this.requestUpdate();
190
- }
191
- onViewportSizeChange(event) {
192
- this.viewportSize = event.detail.category;
193
- }
194
- toggleExpandCollapseAll() {
195
- this.expandAll = !this.expandAll;
196
- this.automaticallyExpandedNodes = new Set();
197
- this.manuallyExpandedNodes = new Set();
198
- this.manuallyCollapsedNodes = new Set();
199
- }
200
- getExpandCollapseAllTooltipPosition() {
201
- switch (this.expandCollapseAllAlignment) {
202
- case "right":
203
- return "left";
204
- case "left":
205
- return "right";
206
- default:
207
- return "bottom";
208
- }
209
- }
210
- getLeafNodeIcon() {
211
- return html `
212
- <ft-icon class="ft-reader-toc--leaf-node-icon"
213
- part="leaf-node-icon"
214
- .variant=${this.leafNodeIconVariant}
215
- .value=${this.leafNodeIcon}></ft-icon>
216
- `;
217
- }
218
80
  }
219
81
  FtReaderToc.elementDefinitions = {
82
+ ...FtReaderBaseToc.elementDefinitions,
220
83
  "ft-button": FtButton,
221
- "ft-icon": FtIcon,
222
84
  "ft-reader-internal-link": FtReaderInternalLink,
223
- "ft-size-watcher": FtSizeWatcher,
224
85
  "ft-typography": FtTypography,
225
86
  "ft-skeleton": FtSkeleton,
226
87
  };
227
- // language=CSS
228
88
  FtReaderToc.styles = styles;
229
- __decorate([
230
- property({ type: Boolean })
231
- ], FtReaderToc.prototype, "expanded", void 0);
232
- __decorate([
233
- property()
234
- ], FtReaderToc.prototype, "iconVariant", void 0);
235
- __decorate([
236
- property()
237
- ], FtReaderToc.prototype, "collapseIcon", void 0);
238
- __decorate([
239
- property()
240
- ], FtReaderToc.prototype, "expandIcon", void 0);
241
- __decorate([
242
- property()
243
- ], FtReaderToc.prototype, "leafNodeIconVariant", void 0);
244
- __decorate([
245
- property()
246
- ], FtReaderToc.prototype, "leafNodeIcon", void 0);
247
- __decorate([
248
- property({ type: Boolean })
249
- ], FtReaderToc.prototype, "expandCollapseAll", void 0);
250
- __decorate([
251
- property({ type: Boolean })
252
- ], FtReaderToc.prototype, "expandCollapseAllHideLabel", void 0);
253
- __decorate([
254
- property({ type: Boolean })
255
- ], FtReaderToc.prototype, "expandCollapseAllTrailingIcon", void 0);
256
- __decorate([
257
- property()
258
- ], FtReaderToc.prototype, "expandCollapseAllAlignment", void 0);
259
- __decorate([
260
- property({ type: Boolean })
261
- ], FtReaderToc.prototype, "expandCollapseAllHideIcon", void 0);
262
- __decorate([
263
- property()
264
- ], FtReaderToc.prototype, "expandCollapseAllIconVariant", void 0);
265
- __decorate([
266
- property()
267
- ], FtReaderToc.prototype, "collapseAllIcon", void 0);
268
- __decorate([
269
- property()
270
- ], FtReaderToc.prototype, "expandAllIcon", void 0);
271
- __decorate([
272
- property({ type: Boolean })
273
- ], FtReaderToc.prototype, "autoCollapse", void 0);
274
- __decorate([
275
- property({ type: Boolean })
276
- ], FtReaderToc.prototype, "scrollCurrentTopicIntoView", void 0);
277
- __decorate([
278
- property()
279
- ], FtReaderToc.prototype, "scope", void 0);
280
- __decorate([
281
- property({ type: Boolean, reflect: true })
282
- ], FtReaderToc.prototype, "empty", void 0);
283
- __decorate([
284
- redux({
285
- selector: (s, self) => {
286
- var _a, _b, _c;
287
- if (self.isCurrentPageToc) {
288
- return ((_a = s.paginationConfiguration) === null || _a === void 0 ? void 0 : _a.splitCurrentPageToc) ? (_b = s.currentPage) === null || _b === void 0 ? void 0 : _b.toc : undefined;
289
- }
290
- return ((_c = s.paginationConfiguration) === null || _c === void 0 ? void 0 : _c.splitCurrentPageToc) ? s.pagesToc : s.toc;
291
- },
292
- })
293
- ], FtReaderToc.prototype, "toc", void 0);
294
- __decorate([
295
- redux()
296
- ], FtReaderToc.prototype, "currentPage", void 0);
297
- __decorate([
298
- redux({
299
- selector: (s, self) => {
300
- var _a, _b;
301
- return ((_a = s.paginationConfiguration) === null || _a === void 0 ? void 0 : _a.splitCurrentPageToc) && !self.isCurrentPageToc
302
- ? (((_b = s.currentPage) === null || _b === void 0 ? void 0 : _b.rootTocId) ? [s.currentPage.rootTocId] : [])
303
- : s.visibleTopics;
304
- },
305
- })
306
- ], FtReaderToc.prototype, "highlightedTocIds", void 0);
307
- __decorate([
308
- redux({ selector: (s) => s.translation.isLoading })
309
- ], FtReaderToc.prototype, "translationLoading", void 0);
310
- __decorate([
311
- state({ hasChanged })
312
- ], FtReaderToc.prototype, "automaticallyExpandedNodes", void 0);
313
- __decorate([
314
- state({ hasChanged })
315
- ], FtReaderToc.prototype, "manuallyExpandedNodes", void 0);
316
- __decorate([
317
- state({ hasChanged })
318
- ], FtReaderToc.prototype, "manuallyCollapsedNodes", void 0);
319
- __decorate([
320
- state()
321
- ], FtReaderToc.prototype, "expandAll", void 0);
322
- __decorate([
323
- state()
324
- ], FtReaderToc.prototype, "viewportSize", void 0);