forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigator.vue
186 lines (176 loc) · 5.1 KB
/
Navigator.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!--
This source file is part of the Swift.org open source project
Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
-->
<template>
<nav
:aria-labelledby="INDEX_ROOT_KEY"
class="navigator"
>
<NavigatorCard
v-show="!isFetching"
v-bind="technologyProps"
:type="type"
:children="flatChildren"
:active-path="activePath"
:scrollLockID="scrollLockID"
:error-fetching="errorFetching"
:render-filter-on-top="renderFilterOnTop"
:api-changes="apiChanges"
:navigator-references="navigatorReferences"
@close="$emit('close')"
>
<template #filter><slot name="filter" /></template>
<template #navigator-head>
<slot name="navigator-head" className="nav-title"/>
</template>
</NavigatorCard>
<LoadingNavigatorCard
@close="$emit('close')"
v-if="isFetching"
/>
<div aria-live="polite" class="visuallyhidden">
{{ $t('navigator.navigator-is', {
state: isFetching ? $t('navigator.state.loading') : $t('navigator.state.ready')
}) }}
</div>
</nav>
</template>
<script>
import NavigatorCard from 'theme/components/Navigator/NavigatorCard.vue';
import LoadingNavigatorCard from 'theme/components/Navigator/LoadingNavigatorCard.vue';
import { INDEX_ROOT_KEY } from 'docc-render/constants/sidebar';
import { TopicTypes } from 'docc-render/constants/TopicTypes';
/**
* @typedef NavigatorFlatItem
* @property {number} uid - generated UID
* @property {string} title - title of symbol
* @property {string} type - symbol type, used for the icon
* @property {string} icon - an image reference to override the type icon
* @property {array} abstract - symbol abstract
* @property {string} path - path to page, used in navigation
* @property {number} parent - parent UID
* @property {number} groupMarkerUID - UID of the groupMarker that labels this
* @property {number} deprecatedChildrenCount - number of children that are deprecated.
* Used for filtering
* @property {number} depth - depth of symbol in original tree
* @property {number} index - index of item in siblings
* @property {number} siblingsCount - number of siblings
* @property {number[]} childUIDs - array of child UIDs
* @property {boolean} deprecated - symbol is deprecated or is not
*/
/**
* Renders a sidebar navigator component.
*/
export default {
name: 'Navigator',
components: {
NavigatorCard,
LoadingNavigatorCard,
},
data() {
return {
INDEX_ROOT_KEY,
};
},
props: {
flatChildren: {
type: Array,
required: true,
},
parentTopicIdentifiers: {
type: Array,
required: true,
},
technology: {
type: Object,
required: false,
},
isFetching: {
type: Boolean,
default: false,
},
references: {
type: Object,
default: () => {},
},
navigatorReferences: {
type: Object,
default: () => {},
},
scrollLockID: {
type: String,
default: '',
},
errorFetching: {
type: Boolean,
default: false,
},
renderFilterOnTop: {
type: Boolean,
default: false,
},
apiChanges: {
type: Object,
default: null,
},
},
computed: {
// gets the paths for each parent in the breadcrumbs
parentTopicReferences({ references, parentTopicIdentifiers }) {
return parentTopicIdentifiers
.reduce((all, identifier) => {
const reference = references[identifier];
if (reference) return all.concat(reference);
console.error(`Reference for "${identifier}" is missing`);
return all;
}, []);
},
// splits out the top-level technology crumb
activePath({ parentTopicReferences, $route: { path } }) {
// Ensure the path does not have a trailing slash
// eslint-disable-next-line no-param-reassign
path = path.replace(/\/$/, '').toLowerCase();
// route's path is activePath on root
if (!parentTopicReferences.length) return [path];
let itemsToSlice = 1;
// if the first item is a `technology`, slice off it and the technology itself
if (parentTopicReferences[0].kind === 'technologies') {
itemsToSlice = 2;
}
return parentTopicReferences.slice(itemsToSlice).map(r => r.url).concat(path);
},
/**
* The root item is always a module
*/
type: () => TopicTypes.module,
technologyProps: ({ technology }) => (
!technology ? null : {
technology: technology.title,
technologyPath: technology.path || technology.url,
isTechnologyBeta: technology.beta,
}
),
},
};
</script>
<style scoped lang='scss'>
@import 'docc-render/styles/_core.scss';
.navigator {
height: 100%;
display: flex;
flex-flow: column;
@include breakpoint(medium, nav) {
position: static;
transition: none;
}
}
:deep(.nav-title) {
font-size: inherit;
font-weight: inherit;
flex-grow: 1;
}
</style>