@ni/nimble-components 15.5.4 → 15.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import { FoundationElement } from '@microsoft/fast-foundation';
2
+ import type { TableRecord } from './types';
2
3
  declare global {
3
4
  interface HTMLElementTagNameMap {
4
5
  'nimble-table': Table;
@@ -7,5 +8,17 @@ declare global {
7
8
  /**
8
9
  * A nimble-styled table.
9
10
  */
10
- export declare class Table extends FoundationElement {
11
+ export declare class Table<TData extends TableRecord = TableRecord> extends FoundationElement {
12
+ data: TData[];
13
+ tableData: string[][];
14
+ columnHeaders: string[];
15
+ private readonly table;
16
+ private options;
17
+ private readonly tableInitialized;
18
+ constructor();
19
+ dataChanged(prev: TData[] | undefined, next: TData[] | undefined): void;
20
+ private refreshRows;
21
+ private updateTableOptions;
22
+ private readonly update;
23
+ private generateColumns;
11
24
  }
@@ -1,11 +1,105 @@
1
+ import { __decorate } from "tslib";
2
+ import { observable } from '@microsoft/fast-element';
1
3
  import { DesignSystem, FoundationElement } from '@microsoft/fast-foundation';
4
+ import { createTable as tanStackCreateTable, getCoreRowModel as tanStackGetCoreRowModel } from '@tanstack/table-core';
2
5
  import { styles } from './styles';
3
6
  import { template } from './template';
4
7
  /**
5
8
  * A nimble-styled table.
6
9
  */
7
10
  export class Table extends FoundationElement {
11
+ constructor() {
12
+ super();
13
+ this.data = [];
14
+ // TODO: Temporarily expose the table data as arrays of strings.
15
+ this.tableData = [];
16
+ // TODO: Temporarily expose the column headers as a string array.
17
+ this.columnHeaders = [];
18
+ this.tableInitialized = false;
19
+ this.update = (state) => {
20
+ this.table.setOptions(prev => ({
21
+ ...prev,
22
+ ...this.options,
23
+ state,
24
+ onStateChange: (updater) => {
25
+ const updatedState = typeof updater === 'function'
26
+ ? updater(state)
27
+ : updater;
28
+ this.update(updatedState);
29
+ }
30
+ }));
31
+ };
32
+ this.options = {
33
+ data: [],
34
+ onStateChange: (_) => { },
35
+ getCoreRowModel: tanStackGetCoreRowModel(),
36
+ columns: [],
37
+ state: {},
38
+ renderFallbackValue: null,
39
+ autoResetAll: false
40
+ };
41
+ this.table = tanStackCreateTable(this.options);
42
+ this.tableInitialized = true;
43
+ }
44
+ dataChanged(prev, next) {
45
+ if ((!prev || prev.length === 0) && next && next.length > 0) {
46
+ this.generateColumns();
47
+ }
48
+ // Ignore any updates that occur prior to the TanStack table being initialized.
49
+ if (this.tableInitialized) {
50
+ this.updateTableOptions({ data: this.data });
51
+ this.refreshRows();
52
+ }
53
+ }
54
+ // TODO: For now, assume all cells can be rendered as strings. Ultimately, the data
55
+ // should be passed to nimble-row elements to use the view template from a column definition.
56
+ refreshRows() {
57
+ const tableData = [];
58
+ const rows = this.table.getRowModel().rows;
59
+ for (const row of rows) {
60
+ const rowArray = [];
61
+ for (const cell of row.getVisibleCells()) {
62
+ const cellValue = cell.getValue();
63
+ const stringValue = cellValue == null ? '' : cellValue.toString();
64
+ rowArray.push(stringValue);
65
+ }
66
+ tableData.push(rowArray);
67
+ }
68
+ this.tableData = tableData;
69
+ }
70
+ updateTableOptions(updatedOptions) {
71
+ this.options = { ...this.options, ...updatedOptions };
72
+ this.update(this.table.initialState);
73
+ }
74
+ // Temporarily auto-detect the keys in TData to make columns.
75
+ // TODO: Remove this logic when another way to specify columns is provided.
76
+ generateColumns() {
77
+ if (this.data.length === 0) {
78
+ return;
79
+ }
80
+ const firstItem = this.data[0];
81
+ const keys = Object.keys(firstItem);
82
+ const generatedColumns = keys.map(key => {
83
+ const columnDef = {
84
+ id: key,
85
+ accessorKey: key,
86
+ header: key
87
+ };
88
+ return columnDef;
89
+ });
90
+ this.updateTableOptions({ columns: generatedColumns });
91
+ this.columnHeaders = generatedColumns.map(x => x.header);
92
+ }
8
93
  }
94
+ __decorate([
95
+ observable
96
+ ], Table.prototype, "data", void 0);
97
+ __decorate([
98
+ observable
99
+ ], Table.prototype, "tableData", void 0);
100
+ __decorate([
101
+ observable
102
+ ], Table.prototype, "columnHeaders", void 0);
9
103
  const nimbleTable = Table.compose({
10
104
  baseName: 'table',
11
105
  template,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/table/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAQtC;;GAEG;AACH,MAAM,OAAO,KAAM,SAAQ,iBAAiB;CAAG;AAE/C,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,QAAQ,EAAE,OAAO;IACjB,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/table/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAKH,WAAW,IAAI,mBAAmB,EAClC,eAAe,IAAI,uBAAuB,EAE7C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAStC;;GAEG;AACH,MAAM,OAAO,KAEX,SAAQ,iBAAiB;IAgBvB;QACI,KAAK,EAAE,CAAC;QAfL,SAAI,GAAY,EAAE,CAAC;QAE1B,gEAAgE;QAEzD,cAAS,GAAe,EAAE,CAAC;QAElC,iEAAiE;QAE1D,kBAAa,GAAa,EAAE,CAAC;QAInB,qBAAgB,GAAY,KAAK,CAAC;QAwDlC,WA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G;gBAChB,MAAM,EAAE,GAAG;aACd,CAAC;YACF,OAAO,SAAS,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACvD,IAAI,CAAC,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAgB,CAAC,CAAC;IACvE,CAAC;CACJ;AAvGG;IADC,UAAU;mCACe;AAI1B;IADC,UAAU;wCACuB;AAIlC;IADC,UAAU;4CACyB;AAiGxC,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,QAAQ,EAAE,OAAO;IACjB,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC"}
@@ -1,6 +1,28 @@
1
1
  import { css } from '@microsoft/fast-element';
2
2
  import { display } from '@microsoft/fast-foundation';
3
+ import { bodyFont, bodyFontColor } from '../theme-provider/design-tokens';
3
4
  export const styles = css `
4
5
  ${display('flex')}
6
+
7
+ .table-container {
8
+ width: 100%;
9
+ height: 100%;
10
+ font: ${bodyFont};
11
+ color: ${bodyFontColor};
12
+ }
13
+
14
+ .table-header {
15
+ display: flex;
16
+ flex-direction: row;
17
+ }
18
+
19
+ .table-row {
20
+ display: flex;
21
+ flex-direction: row;
22
+ }
23
+
24
+ .table-cell {
25
+ flex: 1;
26
+ }
5
27
  `;
6
28
  //# sourceMappingURL=styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/table/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;MACnB,OAAO,CAAC,MAAM,CAAC;CACpB,CAAC"}
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/table/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAE1E,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;MACnB,OAAO,CAAC,MAAM,CAAC;;;;;gBAKL,QAAQ;iBACP,aAAa;;;;;;;;;;;;;;;;CAgB7B,CAAC"}
@@ -1,2 +1,2 @@
1
1
  import type { Table } from '.';
2
- export declare const template: import("@microsoft/fast-element").ViewTemplate<Table, any>;
2
+ export declare const template: import("@microsoft/fast-element").ViewTemplate<Table<import("./types").TableRecord>, any>;
@@ -1,3 +1,23 @@
1
- import { html } from '@microsoft/fast-element';
2
- export const template = html ` <template> Nimble table here </template> `;
1
+ import { html, repeat } from '@microsoft/fast-element';
2
+ // prettier-ignore
3
+ export const template = html `
4
+ <template>
5
+ <div class="table-container">
6
+ <div class="table-header">
7
+ ${repeat(x => x.columnHeaders, html `
8
+ <span class="table-cell">${x => x}</span>
9
+ `)}
10
+ </div>
11
+ <div class="table-viewport">
12
+ ${repeat(x => x.tableData, html `
13
+ <div class="table-row">
14
+ ${repeat(x => x, html `
15
+ <span class="table-cell">${x => x}</span>
16
+ `)}
17
+ </div>
18
+ `)}
19
+ </div>
20
+ </div>
21
+ </template>
22
+ `;
3
23
  //# sourceMappingURL=template.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/table/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAG/C,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAO,4CAA4C,CAAC"}
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/table/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAGvD,kBAAkB;AAClB,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAO;;;;kBAIjB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,IAAI,CAAQ;+CACZ,CAAC,CAAC,EAAE,CAAC,CAAC;iBACpC,CAAC;;;kBAGA,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,IAAI,CAAU;;0BAE/B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAQ;uDACE,CAAC,CAAC,EAAE,CAAC,CAAC;yBACpC,CAAC;;iBAET,CAAC;;;;CAIjB,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * TableFieldName describes the type associated with keys within
3
+ * a table's records.
4
+ */
5
+ export declare type TableFieldName = string;
6
+ /**
7
+ * TableFieldValue describes the type associated with values within
8
+ * a table's records.
9
+ */
10
+ export declare type TableFieldValue = string | number | boolean | Date | null | undefined;
11
+ /**
12
+ * TableRecord describes the data structure that backs a single row in a table.
13
+ * It is made up of fields, which are key/value pairs that have a key of type
14
+ * TableFieldName and a value of type TableFieldValue.
15
+ */
16
+ export interface TableRecord {
17
+ [key: TableFieldName]: TableFieldValue;
18
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/table/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ni/nimble-components",
3
- "version": "15.5.4",
3
+ "version": "15.5.5",
4
4
  "description": "Styled web components for the NI Nimble Design System",
5
5
  "scripts": {
6
6
  "build": "npm run generate-icons && npm run build-components && npm run bundle-components && npm run generate-scss && npm run build-storybook",
@@ -50,6 +50,7 @@
50
50
  "@microsoft/fast-foundation": "^2.46.11",
51
51
  "@microsoft/fast-web-utilities": "^5.4.1",
52
52
  "@ni/nimble-tokens": "^4.3.0",
53
+ "@tanstack/table-core": "^8.7.0",
53
54
  "@types/d3-scale": "^4.0.2",
54
55
  "d3-scale": "^4.0.2",
55
56
  "hex-rgb": "^5.0.0",