Skip to content

Commit 5372551

Browse files
committed
combined JS and HBS
2 parents 8ef7a18 + 3fff8ef commit 5372551

20 files changed

Lines changed: 187 additions & 183 deletions
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,114 @@
1+
import Component from '@glimmer/component';
2+
import sortBy from 'lodash.sortby';
3+
4+
/**
5+
* @typedef Args
6+
* @property {object} model
7+
* @property {object} filterData
8+
*/
9+
10+
/**
11+
* @typedef Blocks
12+
* @property {[ApiIndexFilter['filteredData']]} default
13+
*/
14+
15+
/**
16+
* @extends Component<{ Args: Args, Blocks: Blocks }>
17+
*/
18+
export default class ApiIndexFilter extends Component {
19+
get filteredMethods() {
20+
return this.filterItems('methods');
21+
}
22+
23+
get filteredEvents() {
24+
return this.filterItems('events');
25+
}
26+
27+
get filteredProperties() {
28+
return this.filterItems('properties');
29+
}
30+
31+
filterItems(itemType) {
32+
let items =
33+
this.args.model[itemType] === undefined
34+
? []
35+
: this.args.model[`${itemType}`];
36+
if (!this.args.filterData.showInherited) {
37+
items = items.filter((item) => item.inherited !== true);
38+
}
39+
if (!this.args.filterData.showProtected) {
40+
items = items.filter((item) => item.access !== 'protected');
41+
}
42+
if (!this.args.filterData.showPrivate) {
43+
items = items.filter((item) => item.access !== 'private');
44+
}
45+
if (!this.args.filterData.showDeprecated) {
46+
items = items.filter((item) => item.deprecated !== true);
47+
}
48+
49+
let sortedItems = sortBy(items, (item) => item.name);
50+
return this.filterMultipleInheritance(sortedItems);
51+
}
52+
53+
get filteredData() {
54+
return {
55+
methods: this.filteredMethods,
56+
properties: this.filteredProperties,
57+
events: this.filteredEvents,
58+
};
59+
}
60+
61+
/**
62+
* Returns an array where duplicate methods (by name) are removed.
63+
* The docs for the nearest inheritance are typically more helpful to users,
64+
* so in cases of duplicates, "more local" is preferred.
65+
* Without this, multiple entries for some methods will show up.
66+
* @method filterMultipleInheritance
67+
*/
68+
filterMultipleInheritance(items) {
69+
let dedupedArray = [];
70+
for (let i = 0; i < items.length; i++) {
71+
let currentItem = items[i];
72+
if (i === items.length - 1) {
73+
// if it's the last item, keep it
74+
dedupedArray.push(currentItem);
75+
} else {
76+
let nextItem = items[i + 1];
77+
if (currentItem.name === nextItem.name) {
78+
// if the method would be listed twice, find the more local documentation
79+
let mostLocal = this.findMostLocal(currentItem, nextItem);
80+
dedupedArray.push(mostLocal);
81+
i += 1; // skip the next item with duplicate name
82+
} else {
83+
dedupedArray.push(currentItem);
84+
}
85+
}
86+
}
87+
return dedupedArray;
88+
}
89+
90+
/**
91+
* Returns whichever item is most local.
92+
* What is "most local" is determined by looking at the file path for the
93+
* method, the file path for the class being viewed, and the parent if needed.
94+
* @method findMostLocal
95+
*/
96+
findMostLocal(currentItem, nextItem) {
97+
let currentScope = this.args.model.file;
98+
let parentClassScope = this.args.model.parentClass.get('file');
99+
if (currentScope === currentItem.file) {
100+
// if the item belongs to the class, keep it
101+
return currentItem;
102+
} else if (parentClassScope === currentItem.file) {
103+
// or if the item belongs to the parent class, keep it
104+
return currentItem;
105+
} else {
106+
// otherwise, the next item must be "more local"
107+
return nextItem;
108+
}
109+
}
110+
}
111+
1112
<div class="api-index-filter">
2113
{{yield this.filteredData}}
3114
</div>

app/components/api-index-filter.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

app/components/api-index.gjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
import Component from '@glimmer/component';
2+
3+
/**
4+
* @typedef ItemData
5+
* @property {Array<{ name: string }>} methods
6+
* @property {Array<{ name: string }>} properties
7+
* @property {Array<{ name: string }>} events
8+
*/
9+
10+
/**
11+
* @typedef Args
12+
* @property {ItemData} itemData
13+
*/
14+
15+
/**
16+
* @typedef Blocks
17+
* @property {[{ sections: ApiIndex['sections'] }]} default
18+
*/
19+
20+
/**
21+
* @extends Component<{ Args: Args, Blocks: Blocks }>
22+
*/
23+
export default class ApiIndex extends Component {
24+
get sections() {
25+
return [
26+
{
27+
title: 'Methods',
28+
tab: 'methods',
29+
items: this.args.itemData.methods,
30+
class: 'spec-method-list',
31+
routeSuffix: '.methods.method',
32+
},
33+
{
34+
title: 'Properties',
35+
tab: 'properties',
36+
items: this.args.itemData.properties,
37+
class: 'spec-property-list',
38+
routeSuffix: '.properties.property',
39+
},
40+
{
41+
title: 'Events',
42+
tab: 'events',
43+
items: this.args.itemData.events,
44+
class: 'spec-event-list',
45+
routeSuffix: '.events.event',
46+
},
47+
];
48+
}
49+
}
50+
151
<div>
252
{{yield (hash
353
sections=this.sections)

app/components/api-index.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

app/components/class-field-description.gjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
import { service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
4+
export default class ClassFieldDescription extends Component {
5+
@service
6+
legacyModuleMappings;
7+
8+
get hasImportExample() {
9+
return this.legacyModuleMappings.hasFunctionMapping(
10+
this.args.field.name,
11+
this.args.field.class,
12+
);
13+
}
14+
}
15+
116
{{! template-lint-disable no-invalid-interactive }}
217
<section class='class-field-description {{@type}}'>
318
<h3 id='{{@field.name}}' class="class-field-description--header">

app/components/class-field-description.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/components/import-example.gjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
import Component from '@glimmer/component';
2+
3+
export default class ImportExample extends Component {
4+
get markdown() {
5+
let md = `\`\`\`js
6+
import ${this.args.item} from '${this.args.package}';
7+
\`\`\``;
8+
return md;
9+
}
10+
}
11+
112
<MarkdownToHtml @markdown={{this.markdown}} />

app/components/import-example.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/integration/components/api-index-filter-test.js renamed to tests/integration/components/api-index-filter-test.gjs

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)