Skip to content

Commit 0cd10a2

Browse files
committed
combined JS and HBS
2 parents d3253bd + 71fd2d0 commit 0cd10a2

25 files changed

+369
-362
lines changed

app/components/api-index-filter.gjs

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

app/components/api-index-filter.js

-119
This file was deleted.

app/components/api-index.gjs

+50
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

-49
This file was deleted.

app/components/class-field-description.gjs

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
import { inject as service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
import { action } from '@ember/object';
4+
5+
export default class ClassFieldDescription extends Component {
6+
@service
7+
legacyModuleMappings;
8+
9+
get hasImportExample() {
10+
return this.legacyModuleMappings.hasFunctionMapping(
11+
this.args.field.name,
12+
this.args.field.class
13+
);
14+
}
15+
16+
/**
17+
* Callback for updating the anchor with the field name that was clicked by a user.
18+
*
19+
* @method updateAnchor
20+
* @method fieldName String The name representing the field that was clicked.
21+
*/
22+
@action
23+
updateAnchor(fieldName) {
24+
this.args.updateAnchor?.(fieldName);
25+
}
26+
}
27+
128
<section class='{{@type}}'>
229
{{!-- TODO: Fix this link for a11y --}}
330
<h3 class='class-field-description--link' data-anchor='{{@field.name}}' role='link' {{on 'click' (fn this.updateAnchor @field.name)}}>

0 commit comments

Comments
 (0)