1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | 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;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var TocPlugin_1;
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const index_1 = require("../../models/reflections/index");
|
11 | const components_1 = require("../components");
|
12 | const events_1 = require("../events");
|
13 | const NavigationItem_1 = require("../models/NavigationItem");
|
14 | let TocPlugin = TocPlugin_1 = class TocPlugin extends components_1.RendererComponent {
|
15 | initialize() {
|
16 | this.listenTo(this.owner, {
|
17 | [events_1.PageEvent.BEGIN]: this.onRendererBeginPage
|
18 | });
|
19 | }
|
20 | onRendererBeginPage(page) {
|
21 | let model = page.model;
|
22 | if (!(model instanceof index_1.Reflection)) {
|
23 | return;
|
24 | }
|
25 | const trail = [];
|
26 | while (!(model instanceof index_1.ProjectReflection) && !model.kindOf(index_1.ReflectionKind.SomeModule)) {
|
27 | trail.unshift(model);
|
28 | model = model.parent;
|
29 | }
|
30 | const tocRestriction = this.owner.toc;
|
31 | page.toc = new NavigationItem_1.NavigationItem();
|
32 | TocPlugin_1.buildToc(model, trail, page.toc, tocRestriction);
|
33 | }
|
34 | static buildToc(model, trail, parent, restriction) {
|
35 | const index = trail.indexOf(model);
|
36 | const children = model['children'] || [];
|
37 | if (index < trail.length - 1 && children.length > 40) {
|
38 | const child = trail[index + 1];
|
39 | const item = NavigationItem_1.NavigationItem.create(child, parent, true);
|
40 | item.isInPath = true;
|
41 | item.isCurrent = false;
|
42 | TocPlugin_1.buildToc(child, trail, item);
|
43 | }
|
44 | else {
|
45 | children.forEach((child) => {
|
46 | if (restriction && restriction.length > 0 && !restriction.includes(child.name)) {
|
47 | return;
|
48 | }
|
49 | if (child.kindOf(index_1.ReflectionKind.SomeModule)) {
|
50 | return;
|
51 | }
|
52 | const item = NavigationItem_1.NavigationItem.create(child, parent, true);
|
53 | if (trail.includes(child)) {
|
54 | item.isInPath = true;
|
55 | item.isCurrent = (trail[trail.length - 1] === child);
|
56 | TocPlugin_1.buildToc(child, trail, item);
|
57 | }
|
58 | });
|
59 | }
|
60 | }
|
61 | };
|
62 | TocPlugin = TocPlugin_1 = __decorate([
|
63 | components_1.Component({ name: 'toc' })
|
64 | ], TocPlugin);
|
65 | exports.TocPlugin = TocPlugin;
|
66 |
|
\ | No newline at end of file |