forked from swiftlang/swift-docc-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDestinationDataProvider.vue
98 lines (90 loc) · 2.53 KB
/
DestinationDataProvider.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
<!--
This source file is part of the Swift.org open source project
Copyright (c) 2021 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
-->
<script>
import referencesProvider from 'docc-render/mixins/referencesProvider';
const DestinationType = {
link: 'link',
reference: 'reference',
text: 'text',
};
/**
* Transparent Data provider for `destination` type.
* Returns a single default scoped slot
* with `url` and `title`
*/
export default {
name: 'DestinationDataProvider',
mixins: [referencesProvider],
props: {
destination: {
type: Object,
required: true,
default: () => ({}),
},
},
inject: {
isTargetIDE: {
default: () => false,
},
},
constants: {
DestinationType,
},
computed: {
/**
* Whether the link is an external type or not.
* Backwards compatible with deprecated Destination.link
* @returns {boolean}
*/
isExternal: ({ reference, destination }) => (
// current
reference.type === DestinationType.link
// deprecated fallback
|| destination.type === DestinationType.link
),
/**
* Whether `(opens in browser)` should be appended to the aria-label
* @returns {boolean}
*/
shouldAppendOpensInBrowser: ({ isExternal, isTargetIDE }) => isExternal && isTargetIDE,
reference: ({ references, destination }) => (references[destination.identifier] || {}),
linkUrl: ({
destination,
reference,
}) => ({
[DestinationType.link]: destination.destination,
[DestinationType.reference]: reference.url,
[DestinationType.text]: destination.text,
}[destination.type]),
linkTitle: ({ reference, destination }) => ({
[DestinationType.link]: destination.title,
[DestinationType.reference]: destination.overridingTitle || reference.title,
[DestinationType.text]: '',
}[destination.type]),
},
methods: {
/**
* Format the passed label
* Passed via `scope-slot`
* @param {string} title
* @returns {string}
*/
formatAriaLabel(title) {
return this.shouldAppendOpensInBrowser ? `${title} (opens in browser)` : title;
},
},
render() {
return this.$scopedSlots.default({
url: this.linkUrl || '',
title: this.linkTitle || '',
formatAriaLabel: this.formatAriaLabel,
isExternal: this.isExternal,
});
},
};
</script>