Skip to content

Commit f759fef

Browse files
hqhhuangQuietMisdreavusmportiz08
authored
Highlight unique components of overloaded declarations [alternate approach] (#875) rdar://117503463
Highlight unique components of overloaded declarations [alternate approach] (#875) rdar://117503463 --------- Co-authored-by: Vera Mitchell <[email protected]> Co-authored-by: Marcus Ortiz <[email protected]>
1 parent 01b83de commit f759fef

File tree

9 files changed

+40
-102
lines changed

9 files changed

+40
-102
lines changed

src/components/DocumentationTopic/PrimaryContent/DeclarationList.vue

+8
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ export default {
180180
margin: 0;
181181
}
182182
}
183+
184+
:deep(.highlighted) {
185+
background: var(--color-syntax-highlighted, mark);
186+
font-weight: $font-weight-semibold;
187+
transition:
188+
background 0.3s linear,
189+
font-weight 0.3s linear;
190+
}
183191
}
184192

185193
@include changedStyles {

src/components/DocumentationTopic/PrimaryContent/DeclarationSource.vue

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
><CodeBlock ref="code"><Token
1717
v-for="(token, i) in formattedTokens"
1818
:key="i"
19+
:class="extraClassesFor(token)"
1920
v-bind="propsFor(token)" /></CodeBlock></pre>
2021
</template>
2122

@@ -32,6 +33,12 @@ const { TokenKind } = DeclarationToken.constants;
3233

3334
const DEFAULT_INDENTATION_WIDTH = 4;
3435

36+
const HighlightKind = {
37+
added: 'added',
38+
changed: 'changed',
39+
removed: 'removed',
40+
};
41+
3542
export default {
3643
name: 'DeclarationSource',
3744
data() {
@@ -41,6 +48,7 @@ export default {
4148
};
4249
},
4350
components: { Token: DeclarationToken, CodeBlock },
51+
constants: { HighlightKind },
4452
props: {
4553
tokens: {
4654
type: Array,
@@ -203,6 +211,11 @@ export default {
203211
handleWindowResize() {
204212
this.displaysMultipleLines = displaysMultipleLines(this.$refs.declarationGroup);
205213
},
214+
extraClassesFor(token) {
215+
return {
216+
highlighted: token.highlight === HighlightKind.changed,
217+
};
218+
},
206219
},
207220
async mounted() {
208221
window.addEventListener('resize', this.handleWindowResize);

src/components/DocumentationTopic/PrimaryContent/DeclarationToken.vue

-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import ChangedToken from './DeclarationToken/ChangedToken.vue';
1414
import LinkableToken from './DeclarationToken/LinkableToken.vue';
1515
import RawText from './DeclarationToken/RawText.vue';
1616
import SyntaxToken from './DeclarationToken/SyntaxToken.vue';
17-
import Highlighted from './DeclarationToken/Highlighted.vue';
1817

1918
const TokenKind = {
2019
attribute: 'attribute',
@@ -28,7 +27,6 @@ const TokenKind = {
2827
string: 'string',
2928
text: 'text',
3029
typeIdentifier: 'typeIdentifier',
31-
highlightDiff: 'highlightDiff',
3230
added: 'added',
3331
removed: 'removed',
3432
};
@@ -71,10 +69,6 @@ export default {
7169
case TokenKind.added:
7270
case TokenKind.removed:
7371
return createElement(ChangedToken, { props: { tokens, kind } });
74-
case TokenKind.highlightDiff:
75-
return createElement(Highlighted, {}, (tokens || []).map(token => (
76-
_render.bind(token)(createElement)
77-
)));
7872
default: {
7973
const props = {
8074
kind,

src/components/DocumentationTopic/PrimaryContent/DeclarationToken/Highlighted.vue

-23
This file was deleted.

src/components/DocumentationTopic/PrimaryContent/DeclarationToken/RawText.vue

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@
77
See https://swift.org/LICENSE.txt for license information
88
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
-->
10+
<template>
11+
<span>{{text}}</span>
12+
</template>
1013

1114
<script>
12-
// This component is an optimization that allows us to emit raw text DOM nodes
13-
// for simple text tokens that have no need for a wrapper element. This uses a
14-
// private Vue API (`this._v`) and falls back to adding an empty <span> tag if
15-
// that API goes away in the future.
1615
export default {
1716
name: 'RawText',
18-
render(createElement) {
19-
const {
20-
_v: createTextNode = str => createElement('span', str),
21-
text,
22-
} = this;
23-
return createTextNode(text);
24-
},
2517
props: {
2618
text: {
2719
type: String,

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationSource.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Language from '@/constants/Language';
1919
import { flushPromises } from '../../../../../test-utils';
2020

2121
const { Token, CodeBlock } = DeclarationSource.components;
22+
const { HighlightKind } = DeclarationSource.constants;
2223
const { TokenKind } = Token.constants;
2324

2425
jest.mock('@/utils/indentation');
@@ -193,6 +194,20 @@ describe('DeclarationSource', () => {
193194
.toHaveBeenCalledWith(wrapper.find({ ref: 'code' }).vm.$el, Language.objectiveC.key.api);
194195
expect(callStack).toEqual(['indentDeclaration', 'displaysMultipleLines']);
195196
});
197+
198+
it('adds a "highlighted" class for tokens with `highlight="changed"`', () => {
199+
expect(wrapper.findAll('.highlighted').length).toBe(0);
200+
201+
const tokensWithHighlights = [...propsData.tokens];
202+
tokensWithHighlights[0].highlight = HighlightKind.changed;
203+
tokensWithHighlights[2].highlight = HighlightKind.changed;
204+
wrapper.setProps({ tokens: tokensWithHighlights });
205+
206+
const highlightedTokens = wrapper.findAll('.highlighted');
207+
expect(highlightedTokens.length).toBe(2);
208+
expect(highlightedTokens.at(0).props('text')).toBe(propsData.tokens[0].text);
209+
expect(highlightedTokens.at(1).props('text')).toBe(propsData.tokens[2].text);
210+
});
196211
});
197212

198213
describe('Swift function/initializer formatting', () => {

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationToken.spec.js

-28
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import SyntaxToken
1818
import LinkableToken
1919
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationToken/LinkableToken.vue';
2020
import WordBreak from 'docc-render/components/WordBreak.vue';
21-
import Highlighted
22-
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationToken/Highlighted.vue';
2321

2422
const { TokenKind } = DeclarationToken.constants;
2523

@@ -60,7 +58,6 @@ describe('DeclarationToken', () => {
6058
otherKinds.delete(TokenKind.typeIdentifier);
6159
otherKinds.delete(TokenKind.removed);
6260
otherKinds.delete(TokenKind.added);
63-
otherKinds.delete(TokenKind.highlightDiff);
6461

6562
otherKinds.forEach((kind) => {
6663
const propsData = { kind, text: 'foo' };
@@ -128,29 +125,4 @@ describe('DeclarationToken', () => {
128125
expect(link.text()).toBe(propsData.text);
129126
expect(link.classes()).toContain('attribute-link');
130127
});
131-
132-
it('renders a `Highlighted` for `highlightDiff` tokens', () => {
133-
const stubs = { RawText };
134-
const propsData = {
135-
kind: TokenKind.highlightDiff,
136-
tokens: [
137-
{
138-
kind: TokenKind.text,
139-
text: 'foo',
140-
},
141-
{
142-
kind: TokenKind.text,
143-
text: 'bar',
144-
},
145-
],
146-
};
147-
const wrapper = mountToken({ propsData, stubs });
148-
const highlighted = wrapper.find(Highlighted);
149-
expect(highlighted.exists()).toBe(true);
150-
151-
const textTokens = highlighted.findAll(RawText);
152-
expect(textTokens.length).toBe(propsData.tokens.length);
153-
expect(textTokens.at(0).props('text')).toBe(propsData.tokens[0].text);
154-
expect(textTokens.at(1).props('text')).toBe(propsData.tokens[1].text);
155-
});
156128
});

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationToken/Highlighted.spec.js

-22
This file was deleted.

tests/unit/components/DocumentationTopic/PrimaryContent/DeclarationToken/RawText.spec.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,8 @@ import RawText from 'docc-render/components/DocumentationTopic/PrimaryContent/De
1414
describe('RawText', () => {
1515
const propsData = { text: 'foo' };
1616

17-
it('renders a raw text node', () => {
17+
it('renders a span', () => {
1818
const wrapper = shallowMount(RawText, { propsData });
19-
expect(wrapper.find('span').exists()).toBe(false);
20-
expect(wrapper.text()).toBe(propsData.text);
21-
});
22-
23-
it('renders a span with the text if private Vue API is not available', () => {
24-
const wrapper = shallowMount(RawText, {
25-
propsData,
26-
mocks: {
27-
_v: undefined, // `this._v` is private Vue API
28-
},
29-
});
3019
expect(wrapper.is('span')).toBe(true);
3120
expect(wrapper.text()).toBe(propsData.text);
3221
});

0 commit comments

Comments
 (0)