Skip to content

Commit 2fd5d2c

Browse files
authored
API documentation (#9)
* docs: API documentation
1 parent c16a8dc commit 2fd5d2c

38 files changed

+1347
-441
lines changed

custom-elements.json

Lines changed: 102 additions & 46 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 755 additions & 272 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apex-grid",
3-
"version": "1.0.0-rc.1",
3+
"version": "0.0.0",
44
"description": "Web component data grid following open-wc recommendations",
55
"keywords": [
66
"lit",
@@ -22,7 +22,7 @@
2222
],
2323
"scripts": {
2424
"analyze": "cem analyze --litelement --globs \"src/**/*.{js,ts}\"",
25-
"build": "npm run build:tsc && npm run dev:vite",
25+
"build": "npm run build:tsc && npm run dev:vite && npm run typedoc",
2626
"build:tsc": "tsc",
2727
"dev:vite": "vite build",
2828
"format": "npm run format:eslint && npm run format:prettier && npm run format:stylelint",
@@ -39,6 +39,7 @@
3939
"start:wds": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"npm:sass:watch\" \"npm:wds\"",
4040
"test": "tsc && wtr --coverage",
4141
"test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\"",
42+
"typedoc": "typedoc",
4243
"vite": "vite",
4344
"wds": "web-dev-server",
4445
"prepare": "husky install"
@@ -55,35 +56,36 @@
5556
]
5657
},
5758
"dependencies": {
58-
"lit": "^2.4.1",
59-
"@lit-labs/virtualizer": "^0.7.2",
6059
"@lit-labs/context": "^0.1.3",
61-
"igniteui-theming": "^1.1.2",
62-
"igniteui-webcomponents": "^4.0.0"
60+
"@lit-labs/virtualizer": "^0.7.2",
61+
"igniteui-theming": "^1.1.4",
62+
"igniteui-webcomponents": "^4.0.0",
63+
"lit": "^2.4.1"
6364
},
6465
"devDependencies": {
6566
"@blockquote/rollup-plugin-total-bundlesize": "^1.0.0",
6667
"@blockquote/sass-style-template": "^2.1.2",
6768
"@blockquote/test-runner-mocha-style-reporter": "^1.4.1",
6869
"@custom-elements-manifest/analyzer": "^0.6.6",
69-
"@open-wc/eslint-config": "^8.0.2",
70+
"@open-wc/eslint-config": "^9.0.0",
7071
"@open-wc/testing": "^3.1.7",
71-
"@typescript-eslint/eslint-plugin": "^5.43.0",
72-
"@typescript-eslint/parser": "^5.43.0",
72+
"@typescript-eslint/eslint-plugin": "^5.44.0",
73+
"@typescript-eslint/parser": "^5.44.0",
7374
"@web/dev-server": "^0.1.35",
7475
"@web/test-runner": "^0.15.0",
7576
"@web/test-runner-playwright": "^0.9.0",
76-
"concurrently": "^7.5.0",
77-
"eslint": "^8.27.0",
77+
"concurrently": "^7.6.0",
78+
"eslint": "^8.28.0",
7879
"eslint-config-prettier": "^8.5.0",
7980
"eslint-plugin-log-filenames": "^1.0.6",
8081
"husky": "^8.0.2",
8182
"lint-staged": "^13.0.3",
82-
"prettier": "^2.7.1",
83+
"prettier": "^2.8.0",
8384
"sinon": "^14.0.2",
8485
"stylelint": "^14.15.0",
8586
"stylelint-config-standard-scss": "^6.1.0",
8687
"tslib": "^2.4.1",
88+
"typedoc": "^0.23.21",
8789
"typescript": "^4.9.3",
8890
"vite": "^3.2.4"
8991
},

src/components/cell.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { html, LitElement } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33
import { GRID_CELL_TAG } from '../internal/tags.js';
4-
import type { ApexCellContext, ColumnConfig } from '../internal/types.js';
4+
import type { ApexCellContext, ColumnConfiguration } from '../internal/types.js';
55
import styles from '../styles/body-cell/body-cell-styles.js';
66
import type ApexGridRow from './row.js';
77

@@ -17,7 +17,7 @@ export default class ApexGridCell<T extends object> extends LitElement {
1717
public value!: T[keyof T];
1818

1919
@property({ attribute: false })
20-
public column!: ColumnConfig<T>;
20+
public column!: ColumnConfiguration<T>;
2121

2222
@property({ type: Boolean, reflect: true })
2323
public active = false;

src/components/filter-row.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import styles from '../styles/filter-row/filter-row-styles.js';
1313

1414
import type { FilterExpressionTree } from '../operations/filter/tree.js';
1515
import type { FilterExpression, FilterOperation } from '../operations/filter/types.js';
16-
import type { ColumnConfig } from '../internal/types.js';
16+
import type { ColumnConfiguration } from '../internal/types.js';
1717
import {
1818
IgcInputComponent,
1919
IgcDropdownComponent,
@@ -73,7 +73,7 @@ export default class ApexFilterRow<T extends object> extends LitElement {
7373
public dropdown!: IgcDropdownComponent;
7474

7575
@property({ attribute: false })
76-
public column: ColumnConfig<T> = DEFAULT_COLUMN_CONFIG;
76+
public column: ColumnConfiguration<T> = DEFAULT_COLUMN_CONFIG;
7777

7878
@property({ attribute: false })
7979
public expression!: FilterExpression<T>;
@@ -308,7 +308,7 @@ export default class ApexFilterRow<T extends object> extends LitElement {
308308
</div> `;
309309
}
310310

311-
protected renderInactiveChips(column: ColumnConfig<T>, state: FilterExpressionTree<T>) {
311+
protected renderInactiveChips(column: ColumnConfiguration<T>, state: FilterExpressionTree<T>) {
312312
return Array.from(state).map((expression, idx) => {
313313
const props: ExpressionChipProps<T> = {
314314
expression,
@@ -326,7 +326,7 @@ export default class ApexFilterRow<T extends object> extends LitElement {
326326
});
327327
}
328328

329-
protected renderFilterState(column: ColumnConfig<T>) {
329+
protected renderFilterState(column: ColumnConfiguration<T>) {
330330
const state = this.filterController.get(column.key);
331331

332332
const partial = state && state.length < 3;

src/components/grid.ts

Lines changed: 138 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import { EventEmitterBase } from '../internal/mixins/event-emitter.js';
1111
import { watch } from '../internal/watch.js';
1212
import { DEFAULT_COLUMN_CONFIG, PIPELINE } from '../internal/constants.js';
1313
import { registerGridIcons } from '../internal/icon-registry.js';
14-
import { asArray, getFilterOperandsFor } from '../internal/utils.js';
15-
16-
import type { ColumnConfig, GridRemoteConfig, GridSortingConfig, Keys } from '../internal/types.js';
14+
import { asArray, autoGenerateColumns, getFilterOperandsFor } from '../internal/utils.js';
15+
16+
import type {
17+
ColumnConfiguration,
18+
GridRemoteConfig,
19+
GridSortConfiguration,
20+
Keys,
21+
} from '../internal/types.js';
1722
import type { FilterExpressionTree } from '../operations/filter/tree.js';
1823
import type { FilterExpression } from '../operations/filter/types.js';
1924
import type { SortExpression } from '../operations/sort/types.js';
@@ -49,18 +54,76 @@ defineComponents(
4954
IgcDropdownItemComponent,
5055
);
5156

57+
/**
58+
* Event object for the filtering event of the grid.
59+
*/
5260
export interface ApexFilteringEvent<T extends object> {
61+
/**
62+
* The filter expression to apply.
63+
*/
5364
expression: FilterExpression<T>;
65+
/**
66+
* The filter state of the column.
67+
*/
5468
state: FilterExpressionTree<T>;
5569
}
5670

5771
// TODO: Subject to change as these are way too generic names
72+
/**
73+
* Events for the apex-grid.
74+
*/
5875
export interface ApexGridEventMap<T extends object> {
76+
/**
77+
* Emitted when sorting is initiated through the UI.
78+
* Returns the sort expression which will be used for the operation.
79+
*
80+
* @remarks
81+
* The event is cancellable which prevents the operation from being applied.
82+
* The expression can be modified prior to the operation running.
83+
*
84+
* @event
85+
*/
5986
sorting: CustomEvent<SortExpression<T>>;
87+
/**
88+
* Emitted when a sort operation initiated through the UI has completed.
89+
* Returns the sort expression used for the operation.
90+
*
91+
* @event
92+
*/
6093
sorted: CustomEvent<SortExpression<T>>;
94+
/**
95+
* Emitted when filtering is initiated through the UI.
96+
*
97+
* @remarks
98+
* The event is cancellable which prevents the operation from being applied.
99+
* The expression can be modified prior to the operation running.
100+
*
101+
* @event
102+
*/
61103
filtering: CustomEvent<ApexFilteringEvent<T>>;
104+
/**
105+
* Emitted when a filter operation initiated through the UI has completed.
106+
* Returns the filter state for the affected column.
107+
*
108+
* @event
109+
*/
62110
filtered: CustomEvent<FilterExpressionTree<T>>;
63111
}
112+
113+
/**
114+
* Apex grid is a web component for displaying data in a tabular format quick and easy.
115+
*
116+
* Out of the box it provides row virtualization, sort and filter operations (client and server side),
117+
* the ability to template cells and headers and column hiding.
118+
*
119+
* @element apex-grid
120+
*
121+
* @fires sorting - Emitted when sorting is initiated through the UI.
122+
* @fires sorted - Emitted when a sort operation initiated through the UI has completed.
123+
* @fires filtering - Emitted when filtering is initiated through the UI.
124+
* @fires filtered - Emitted when a filter operation initiated through the UI has completed.
125+
*
126+
*/
64127
@themes({
65128
bootstrap,
66129
fluent,
@@ -107,31 +170,78 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
107170
@queryAll(ApexGridRow.is)
108171
protected _rows!: NodeListOf<ApexGridRow<T>>;
109172

173+
/** Column configuration for the grid. */
110174
@property({ attribute: false })
111-
public columns: Array<ColumnConfig<T>> = [];
175+
public columns: Array<ColumnConfiguration<T>> = [];
112176

177+
/** The data source for the grid. */
113178
@property({ attribute: false })
114179
public data: Array<T> = [];
115180

181+
/**
182+
* Whether the grid will try to "resolve" its column configuration based on the passed
183+
* data source.
184+
*
185+
* @remarks
186+
* This is a one-time operation which is executed when the grid is initially added to the DOM.
187+
* Passing an empty data source or having a late bound data source (such as a HTTP request) will usually
188+
* result in empty column configuration for the grid.
189+
*
190+
* This property is ignored if any existing column configuration already exists in the grid.
191+
*/
192+
@property({ type: Boolean, attribute: 'auto-generate' })
193+
public autoGenerate = false;
194+
195+
/** Sort configuration property for the grid. */
116196
@property({ attribute: false })
117-
public sortingConfig: GridSortingConfig = {
197+
public sortConfiguration: GridSortConfiguration = {
118198
multiple: true,
119199
triState: true,
120200
};
121201

202+
/**
203+
* Configuration object which controls remote data operations for the grid.
204+
*/
122205
@property({ attribute: false })
123-
public remoteConfig?: GridRemoteConfig<T>;
124-
206+
public remoteConfiguration?: GridRemoteConfig<T>;
207+
208+
/**
209+
* Set sort state for the apex grid.
210+
*
211+
* @remarks
212+
*
213+
*/
125214
@property({ attribute: false })
126215
public sortExpressions: SortExpression<T>[] = [];
127216

217+
/**
218+
* Set filter state for the apex grid.
219+
*/
128220
@property({ attribute: false })
129221
public filterExpressions: FilterExpression<T>[] = [];
130222

223+
/**
224+
* Returns the collection of rendered row elements in the grid.
225+
*
226+
* @remarks
227+
* Since the grid has virtualization, this property returns only the currently rendered
228+
* chunk of elements in the DOM.
229+
*/
131230
public get rows() {
132231
return Array.from(this._rows);
133232
}
134233

234+
/**
235+
* Returns the state of the data source after sort/filter operations
236+
* have been applied.
237+
*/
238+
public get dataView(): ReadonlyArray<T> {
239+
return this.dataState;
240+
}
241+
242+
/**
243+
* The total number of items in the {@link ApexGrid.dataView} collection.
244+
*/
135245
public get totalItems() {
136246
return this.dataState.length;
137247
}
@@ -141,6 +251,11 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
141251
registerGridIcons();
142252
}
143253

254+
public override connectedCallback() {
255+
super.connectedCallback();
256+
autoGenerateColumns(this);
257+
}
258+
144259
public override requestUpdate(
145260
name?: PropertyKey,
146261
oldValue?: unknown,
@@ -166,7 +281,7 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
166281
}
167282

168283
@watch('columns')
169-
protected watchColumns(_: ColumnConfig<T>[], newConfig: ColumnConfig<T>[] = []) {
284+
protected watchColumns(_: ColumnConfiguration<T>[], newConfig: ColumnConfiguration<T>[] = []) {
170285
this.columns = newConfig.map(config => ({ ...DEFAULT_COLUMN_CONFIG, ...config }));
171286
}
172287

@@ -186,6 +301,9 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
186301
);
187302
}
188303

304+
/**
305+
* Performs a filter operation in the grid based on the passed expression(s).
306+
*/
189307
public filter(config: FilterExpression<T> | FilterExpression<T>[]) {
190308
this.stateController.filtering.filter(
191309
asArray(config).map(each =>
@@ -198,17 +316,26 @@ export default class ApexGrid<T extends object> extends EventEmitterBase<ApexGri
198316
);
199317
}
200318

201-
public sort(expressions: Partial<SortExpression<T>> | Partial<SortExpression<T>>[]) {
202-
this.stateController.sorting.sort(expressions as SortExpression<T>[]);
319+
/**
320+
* Performs a sort operation in the grid based on the passed expression(s).
321+
*/
322+
public sort(expressions: SortExpression<T> | SortExpression<T>[]) {
323+
this.stateController.sorting.sort(expressions);
203324
}
204325

326+
/**
327+
* Returns a {@link ColumnConfiguration} for a given column.
328+
*/
205329
public getColumn(id: Keys<T> | number) {
206330
return typeof id === 'number'
207331
? this.columns.at(id)
208332
: this.columns.find(({ key }) => key === id);
209333
}
210334

211-
public updateColumn(key: Keys<T>, config: Partial<ColumnConfig<T>>) {
335+
/**
336+
* Updates the column configuration of the grid.
337+
*/
338+
public updateColumn(key: Keys<T>, config: Partial<ColumnConfiguration<T>>) {
212339
// Check and reset data operation states
213340
// TODO: Run `pipeline` updates ?
214341
if (!config.sort) {

src/components/header-row.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { GRID_HEADER_ROW_TAG } from '../internal/tags.js';
99
import ApexGridHeader from './header.js';
1010
import styles from '../styles/header-row/header-row.base-styles.js';
1111

12-
import type { ColumnConfig } from '../internal/types.js';
12+
import type { ColumnConfiguration } from '../internal/types.js';
1313

1414
@customElement(GRID_HEADER_ROW_TAG)
1515
export default class ApexGridHeaderRow<T extends object> extends LitElement {
@@ -26,7 +26,7 @@ export default class ApexGridHeaderRow<T extends object> extends LitElement {
2626
public state!: StateController<T>;
2727

2828
@property({ attribute: false })
29-
public columns: Array<ColumnConfig<T>> = [];
29+
public columns: Array<ColumnConfiguration<T>> = [];
3030

3131
public get headers() {
3232
return Array.from(this._headers);
@@ -48,7 +48,7 @@ export default class ApexGridHeaderRow<T extends object> extends LitElement {
4848
.filter(target => target instanceof ApexGridHeader)
4949
.at(0) as ApexGridHeader<T>;
5050

51-
this.state.filtering.setActiveColumn(header.column);
51+
this.state.filtering.setActiveColumn(header?.column);
5252
}
5353

5454
protected override shouldUpdate(props: PropertyValueMap<this> | Map<PropertyKey, this>): boolean {

0 commit comments

Comments
 (0)