@ni/nimble-components 20.1.9 → 20.1.10

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.
Files changed (32) hide show
  1. package/dist/all-components-bundle.js +1 -1
  2. package/dist/all-components-bundle.js.map +1 -1
  3. package/dist/all-components-bundle.min.js.map +1 -1
  4. package/dist/esm/src/table-column/number-text/cell-view/index.d.ts +16 -0
  5. package/dist/esm/src/table-column/number-text/group-header-view/index.d.ts +17 -0
  6. package/dist/esm/src/table-column/number-text/index.d.ts +26 -0
  7. package/dist/esm/src/table-column/number-text/models/default-formatter.d.ts +14 -0
  8. package/dist/esm/src/table-column/number-text/models/number-formatter.d.ts +11 -0
  9. package/dist/esm/src/table-column/number-text/models/round-to-integer-formatter.d.ts +8 -0
  10. package/dist/esm/src/table-column/number-text/types.d.ts +8 -0
  11. package/dist/esm/table-column/number-text/cell-view/index.d.ts +16 -0
  12. package/dist/esm/table-column/number-text/cell-view/index.js +27 -0
  13. package/dist/esm/table-column/number-text/cell-view/index.js.map +1 -0
  14. package/dist/esm/table-column/number-text/group-header-view/index.d.ts +17 -0
  15. package/dist/esm/table-column/number-text/group-header-view/index.js +29 -0
  16. package/dist/esm/table-column/number-text/group-header-view/index.js.map +1 -0
  17. package/dist/esm/table-column/number-text/index.d.ts +26 -0
  18. package/dist/esm/table-column/number-text/index.js +60 -0
  19. package/dist/esm/table-column/number-text/index.js.map +1 -0
  20. package/dist/esm/table-column/number-text/models/default-formatter.d.ts +14 -0
  21. package/dist/esm/table-column/number-text/models/default-formatter.js +58 -0
  22. package/dist/esm/table-column/number-text/models/default-formatter.js.map +1 -0
  23. package/dist/esm/table-column/number-text/models/number-formatter.d.ts +11 -0
  24. package/dist/esm/table-column/number-text/models/number-formatter.js +21 -0
  25. package/dist/esm/table-column/number-text/models/number-formatter.js.map +1 -0
  26. package/dist/esm/table-column/number-text/models/round-to-integer-formatter.d.ts +8 -0
  27. package/dist/esm/table-column/number-text/models/round-to-integer-formatter.js +18 -0
  28. package/dist/esm/table-column/number-text/models/round-to-integer-formatter.js.map +1 -0
  29. package/dist/esm/table-column/number-text/types.d.ts +8 -0
  30. package/dist/esm/table-column/number-text/types.js +8 -0
  31. package/dist/esm/table-column/number-text/types.js.map +1 -0
  32. package/package.json +1 -1
@@ -0,0 +1,16 @@
1
+ import type { TableColumnNumberTextCellRecord, TableColumnNumberTextColumnConfig } from '..';
2
+ import { TableColumnTextCellViewBase } from '../../text-base/cell-view';
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ 'nimble-table-column-number-text-cell-view': TableColumnNumberTextCellView;
6
+ }
7
+ }
8
+ /**
9
+ * A cell view for displaying number fields as text
10
+ */
11
+ export declare class TableColumnNumberTextCellView extends TableColumnTextCellViewBase<TableColumnNumberTextCellRecord, TableColumnNumberTextColumnConfig> {
12
+ private columnConfigChanged;
13
+ private cellRecordChanged;
14
+ private updateText;
15
+ }
16
+ export declare const tableColumnNumberTextCellViewTag: string;
@@ -0,0 +1,17 @@
1
+ import type { TableNumberFieldValue } from '../../../table/types';
2
+ import { TableColumnTextGroupHeaderViewBase } from '../../text-base/group-header-view';
3
+ import type { TableColumnNumberTextColumnConfig } from '..';
4
+ declare global {
5
+ interface HTMLElementTagNameMap {
6
+ 'nimble-table-column-number-text-group-header': TableColumnNumberTextGroupHeaderView;
7
+ }
8
+ }
9
+ /**
10
+ * The group header view for displaying number fields as text.
11
+ */
12
+ export declare class TableColumnNumberTextGroupHeaderView extends TableColumnTextGroupHeaderViewBase<TableNumberFieldValue, TableColumnNumberTextColumnConfig> {
13
+ private columnConfigChanged;
14
+ private groupHeaderValueChanged;
15
+ private updateText;
16
+ }
17
+ export declare const tableColumnNumberTextGroupHeaderTag: string;
@@ -0,0 +1,26 @@
1
+ import type { TableNumberField } from '../../table/types';
2
+ import { TableColumnTextBase } from '../text-base';
3
+ import type { ColumnInternalsOptions } from '../base/models/column-internals';
4
+ import { NumberTextFormat } from './types';
5
+ import type { NumberFormatter } from './models/number-formatter';
6
+ export declare type TableColumnNumberTextCellRecord = TableNumberField<'value'>;
7
+ export interface TableColumnNumberTextColumnConfig {
8
+ formatter: NumberFormatter;
9
+ }
10
+ declare global {
11
+ interface HTMLElementTagNameMap {
12
+ 'nimble-table-column-number-text': TableColumnNumberText;
13
+ }
14
+ }
15
+ /**
16
+ * The table column for displaying numbers as text.
17
+ */
18
+ export declare class TableColumnNumberText extends TableColumnTextBase {
19
+ format: NumberTextFormat;
20
+ connectedCallback(): void;
21
+ protected getColumnInternalsOptions(): ColumnInternalsOptions;
22
+ private formatChanged;
23
+ private updateColumnConfig;
24
+ private createFormatter;
25
+ }
26
+ export declare const tableColumnNumberTextTag: string;
@@ -0,0 +1,14 @@
1
+ import { NumberFormatter } from './number-formatter';
2
+ /**
3
+ * The formatter for a number-text column whose format is configured to be 'default'.
4
+ */
5
+ export declare class DefaultFormatter extends NumberFormatter {
6
+ private static readonly maximumDigits;
7
+ private static readonly exponentialLowerBound;
8
+ private static readonly exponentialUpperBound;
9
+ private static readonly defaultFormatter;
10
+ private static readonly leadingZeroFormatter;
11
+ private static readonly exponentialFormatter;
12
+ protected format(number: number): string;
13
+ private getFormatterForNumber;
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The base class for number formatters used by the number-text column.
3
+ */
4
+ export declare abstract class NumberFormatter {
5
+ /**
6
+ * Tries to format the passed value using the `format()` function implemented by a concrete implementation of the class.
7
+ * Returns an empty string if the value is not a number or if `format()` throws an error.
8
+ */
9
+ formatValue(value: number | undefined | null): string;
10
+ protected abstract format(number: number): string;
11
+ }
@@ -0,0 +1,8 @@
1
+ import { NumberFormatter } from './number-formatter';
2
+ /**
3
+ * The formatter for a number-text column whose format is configured to be 'roundToInteger'.
4
+ */
5
+ export declare class RoundToIntegerFormatter extends NumberFormatter {
6
+ private static readonly formatter;
7
+ protected format(number: number): string;
8
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Formatting scheme for the number-text table column
3
+ */
4
+ export declare const NumberTextFormat: {
5
+ readonly default: undefined;
6
+ readonly roundToInteger: "round-to-integer";
7
+ };
8
+ export declare type NumberTextFormat = (typeof NumberTextFormat)[keyof typeof NumberTextFormat];
@@ -0,0 +1,16 @@
1
+ import type { TableColumnNumberTextCellRecord, TableColumnNumberTextColumnConfig } from '..';
2
+ import { TableColumnTextCellViewBase } from '../../text-base/cell-view';
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ 'nimble-table-column-number-text-cell-view': TableColumnNumberTextCellView;
6
+ }
7
+ }
8
+ /**
9
+ * A cell view for displaying number fields as text
10
+ */
11
+ export declare class TableColumnNumberTextCellView extends TableColumnTextCellViewBase<TableColumnNumberTextCellRecord, TableColumnNumberTextColumnConfig> {
12
+ private columnConfigChanged;
13
+ private cellRecordChanged;
14
+ private updateText;
15
+ }
16
+ export declare const tableColumnNumberTextCellViewTag: string;
@@ -0,0 +1,27 @@
1
+ import { DesignSystem } from '@microsoft/fast-foundation';
2
+ import { template } from '../../text-base/cell-view/template';
3
+ import { styles } from '../../text-base/cell-view/styles';
4
+ import { TableColumnTextCellViewBase } from '../../text-base/cell-view';
5
+ /**
6
+ * A cell view for displaying number fields as text
7
+ */
8
+ export class TableColumnNumberTextCellView extends TableColumnTextCellViewBase {
9
+ columnConfigChanged() {
10
+ this.updateText();
11
+ }
12
+ cellRecordChanged() {
13
+ this.updateText();
14
+ }
15
+ updateText() {
16
+ this.text = this.columnConfig?.formatter?.formatValue(this.cellRecord?.value)
17
+ ?? '';
18
+ }
19
+ }
20
+ const numberTextCellView = TableColumnNumberTextCellView.compose({
21
+ baseName: 'table-column-number-text-cell-view',
22
+ template,
23
+ styles
24
+ });
25
+ DesignSystem.getOrCreate().withPrefix('nimble').register(numberTextCellView());
26
+ export const tableColumnNumberTextCellViewTag = DesignSystem.tagFor(TableColumnNumberTextCellView);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/cell-view/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAK9D,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAQxE;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,2BAGlD;IACW,mBAAmB;QACvB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAEO,iBAAiB;QACrB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAEO,UAAU;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC;eACtE,EAAE,CAAC;IACd,CAAC;CACJ;AAED,MAAM,kBAAkB,GAAG,6BAA6B,CAAC,OAAO,CAAC;IAC7D,QAAQ,EAAE,oCAAoC;IAC9C,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AACH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;AAC/E,MAAM,CAAC,MAAM,gCAAgC,GAAG,YAAY,CAAC,MAAM,CAC/D,6BAA6B,CAChC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { TableNumberFieldValue } from '../../../table/types';
2
+ import { TableColumnTextGroupHeaderViewBase } from '../../text-base/group-header-view';
3
+ import type { TableColumnNumberTextColumnConfig } from '..';
4
+ declare global {
5
+ interface HTMLElementTagNameMap {
6
+ 'nimble-table-column-number-text-group-header': TableColumnNumberTextGroupHeaderView;
7
+ }
8
+ }
9
+ /**
10
+ * The group header view for displaying number fields as text.
11
+ */
12
+ export declare class TableColumnNumberTextGroupHeaderView extends TableColumnTextGroupHeaderViewBase<TableNumberFieldValue, TableColumnNumberTextColumnConfig> {
13
+ private columnConfigChanged;
14
+ private groupHeaderValueChanged;
15
+ private updateText;
16
+ }
17
+ export declare const tableColumnNumberTextGroupHeaderTag: string;
@@ -0,0 +1,29 @@
1
+ import { DesignSystem } from '@microsoft/fast-foundation';
2
+ import { TableColumnTextGroupHeaderViewBase } from '../../text-base/group-header-view';
3
+ import { template } from '../../text-base/group-header-view/template';
4
+ import { styles } from '../../text-base/group-header-view/styles';
5
+ /**
6
+ * The group header view for displaying number fields as text.
7
+ */
8
+ export class TableColumnNumberTextGroupHeaderView extends TableColumnTextGroupHeaderViewBase {
9
+ columnConfigChanged() {
10
+ this.updateText();
11
+ }
12
+ groupHeaderValueChanged() {
13
+ this.updateText();
14
+ }
15
+ updateText() {
16
+ this.text = this.columnConfig?.formatter?.formatValue(this.groupHeaderValue)
17
+ ?? '';
18
+ }
19
+ }
20
+ const tableColumnNumberTextGroupHeaderView = TableColumnNumberTextGroupHeaderView.compose({
21
+ baseName: 'table-column-number-text-group-header-view',
22
+ template,
23
+ styles
24
+ });
25
+ DesignSystem.getOrCreate()
26
+ .withPrefix('nimble')
27
+ .register(tableColumnNumberTextGroupHeaderView());
28
+ export const tableColumnNumberTextGroupHeaderTag = DesignSystem.tagFor(TableColumnNumberTextGroupHeaderView);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/group-header-view/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,kCAAkC,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AAQlE;;GAEG;AACH,MAAM,OAAO,oCAAqC,SAAQ,kCAGzD;IACW,mBAAmB;QACvB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAEO,uBAAuB;QAC3B,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IAEO,UAAU;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC;eACrE,EAAE,CAAC;IACd,CAAC;CACJ;AAED,MAAM,oCAAoC,GAAG,oCAAoC,CAAC,OAAO,CAAC;IACtF,QAAQ,EAAE,4CAA4C;IACtD,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AACH,YAAY,CAAC,WAAW,EAAE;KACrB,UAAU,CAAC,QAAQ,CAAC;KACpB,QAAQ,CAAC,oCAAoC,EAAE,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,mCAAmC,GAAG,YAAY,CAAC,MAAM,CAClE,oCAAoC,CACvC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { TableNumberField } from '../../table/types';
2
+ import { TableColumnTextBase } from '../text-base';
3
+ import type { ColumnInternalsOptions } from '../base/models/column-internals';
4
+ import { NumberTextFormat } from './types';
5
+ import type { NumberFormatter } from './models/number-formatter';
6
+ export declare type TableColumnNumberTextCellRecord = TableNumberField<'value'>;
7
+ export interface TableColumnNumberTextColumnConfig {
8
+ formatter: NumberFormatter;
9
+ }
10
+ declare global {
11
+ interface HTMLElementTagNameMap {
12
+ 'nimble-table-column-number-text': TableColumnNumberText;
13
+ }
14
+ }
15
+ /**
16
+ * The table column for displaying numbers as text.
17
+ */
18
+ export declare class TableColumnNumberText extends TableColumnTextBase {
19
+ format: NumberTextFormat;
20
+ connectedCallback(): void;
21
+ protected getColumnInternalsOptions(): ColumnInternalsOptions;
22
+ private formatChanged;
23
+ private updateColumnConfig;
24
+ private createFormatter;
25
+ }
26
+ export declare const tableColumnNumberTextTag: string;
@@ -0,0 +1,60 @@
1
+ import { __decorate } from "tslib";
2
+ import { DesignSystem } from '@microsoft/fast-foundation';
3
+ import { attr } from '@microsoft/fast-element';
4
+ import { styles } from '../base/styles';
5
+ import { template } from '../base/template';
6
+ import { TableColumnTextBase } from '../text-base';
7
+ import { TableColumnSortOperation } from '../base/types';
8
+ import { tableColumnNumberTextGroupHeaderTag } from './group-header-view';
9
+ import { tableColumnNumberTextCellViewTag } from './cell-view';
10
+ import { NumberTextFormat } from './types';
11
+ import { RoundToIntegerFormatter } from './models/round-to-integer-formatter';
12
+ import { DefaultFormatter } from './models/default-formatter';
13
+ /**
14
+ * The table column for displaying numbers as text.
15
+ */
16
+ export class TableColumnNumberText extends TableColumnTextBase {
17
+ connectedCallback() {
18
+ super.connectedCallback();
19
+ this.updateColumnConfig();
20
+ }
21
+ getColumnInternalsOptions() {
22
+ return {
23
+ cellRecordFieldNames: ['value'],
24
+ cellViewTag: tableColumnNumberTextCellViewTag,
25
+ groupHeaderViewTag: tableColumnNumberTextGroupHeaderTag,
26
+ delegatedEvents: [],
27
+ sortOperation: TableColumnSortOperation.basic
28
+ };
29
+ }
30
+ formatChanged() {
31
+ this.updateColumnConfig();
32
+ }
33
+ updateColumnConfig() {
34
+ const columnConfig = {
35
+ formatter: this.createFormatter()
36
+ };
37
+ this.columnInternals.columnConfig = columnConfig;
38
+ }
39
+ createFormatter() {
40
+ switch (this.format) {
41
+ case NumberTextFormat.roundToInteger:
42
+ return new RoundToIntegerFormatter();
43
+ default:
44
+ return new DefaultFormatter();
45
+ }
46
+ }
47
+ }
48
+ __decorate([
49
+ attr
50
+ ], TableColumnNumberText.prototype, "format", void 0);
51
+ const nimbleTableColumnNumberText = TableColumnNumberText.compose({
52
+ baseName: 'table-column-number-text',
53
+ template,
54
+ styles
55
+ });
56
+ DesignSystem.getOrCreate()
57
+ .withPrefix('nimble')
58
+ .register(nimbleTableColumnNumberText());
59
+ export const tableColumnNumberTextTag = DesignSystem.tagFor(TableColumnNumberText);
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/table-column/number-text/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,mCAAmC,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAa9D;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,mBAAmB;IAI1C,iBAAiB;QAC7B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;IAEkB,yBAAyB;QACxC,OAAO;YACH,oBAAoB,EAAE,CAAC,OAAO,CAAC;YAC/B,WAAW,EAAE,gCAAgC;YAC7C,kBAAkB,EAAE,mCAAmC;YACvD,eAAe,EAAE,EAAE;YACnB,aAAa,EAAE,wBAAwB,CAAC,KAAK;SAChD,CAAC;IACN,CAAC;IAEO,aAAa;QACjB,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;IAEO,kBAAkB;QACtB,MAAM,YAAY,GAAsC;YACpD,SAAS,EAAE,IAAI,CAAC,eAAe,EAAE;SACpC,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,YAAY,GAAG,YAAY,CAAC;IACrD,CAAC;IAEO,eAAe;QACnB,QAAQ,IAAI,CAAC,MAAM,EAAE;YACjB,KAAK,gBAAgB,CAAC,cAAc;gBAChC,OAAO,IAAI,uBAAuB,EAAE,CAAC;YACzC;gBACI,OAAO,IAAI,gBAAgB,EAAE,CAAC;SACrC;IACL,CAAC;CACJ;AApCG;IADC,IAAI;qDAC2B;AAsCpC,MAAM,2BAA2B,GAAG,qBAAqB,CAAC,OAAO,CAAC;IAC9D,QAAQ,EAAE,0BAA0B;IACpC,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE;KACrB,UAAU,CAAC,QAAQ,CAAC;KACpB,QAAQ,CAAC,2BAA2B,EAAE,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC,MAAM,CACvD,qBAAqB,CACxB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { NumberFormatter } from './number-formatter';
2
+ /**
3
+ * The formatter for a number-text column whose format is configured to be 'default'.
4
+ */
5
+ export declare class DefaultFormatter extends NumberFormatter {
6
+ private static readonly maximumDigits;
7
+ private static readonly exponentialLowerBound;
8
+ private static readonly exponentialUpperBound;
9
+ private static readonly defaultFormatter;
10
+ private static readonly leadingZeroFormatter;
11
+ private static readonly exponentialFormatter;
12
+ protected format(number: number): string;
13
+ private getFormatterForNumber;
14
+ }
@@ -0,0 +1,58 @@
1
+ import { NumberFormatter } from './number-formatter';
2
+ /**
3
+ * The formatter for a number-text column whose format is configured to be 'default'.
4
+ */
5
+ export class DefaultFormatter extends NumberFormatter {
6
+ format(number) {
7
+ // The NumberFormat option of `signDisplay: "negative"` is not supported in all browsers nimble supports.
8
+ // Because that option cannot be used to avoid rendering "-0", coerce the value -0 to 0 prior to formatting.
9
+ const valueToFormat = number === 0 ? 0 : number;
10
+ const formatter = this.getFormatterForNumber(valueToFormat);
11
+ return formatter.format(valueToFormat);
12
+ }
13
+ getFormatterForNumber(number) {
14
+ if (number === 0) {
15
+ return DefaultFormatter.defaultFormatter;
16
+ }
17
+ const absoluteValue = Math.abs(number);
18
+ if (absoluteValue >= DefaultFormatter.exponentialUpperBound
19
+ || absoluteValue < DefaultFormatter.exponentialLowerBound) {
20
+ return DefaultFormatter.exponentialFormatter;
21
+ }
22
+ // Ideally, we could set 'roundingPriority: "lessPrecision"' with a formatter that has both 'maximumSignificantDigits' and
23
+ // 'maximumFractionDigits' configured instead of having two different formatters that we conditionally choose between. However,
24
+ // 'roundingPrioirty' is not supported yet in all browsers nimble supports.
25
+ if (absoluteValue < 1) {
26
+ return DefaultFormatter.leadingZeroFormatter;
27
+ }
28
+ return DefaultFormatter.defaultFormatter;
29
+ }
30
+ }
31
+ // The maximum number of digits that should be rendered for any given value.
32
+ DefaultFormatter.maximumDigits = 6;
33
+ // Use exponential notation for numbers that will be rendered with 3 leading 0s or more.
34
+ // Because a maximum of 6 digits are rendered, showing more than 3 leading 0s is not ideal
35
+ // because then at least half of the displayed digits will be leading 0s.
36
+ DefaultFormatter.exponentialLowerBound = 0.000995;
37
+ // Use exponential formatting for numbers whose magnitude cannot otherwise be displayed
38
+ // with 6 digits or less.
39
+ DefaultFormatter.exponentialUpperBound = 999999.5;
40
+ // Formatter to use by default. It renders the number with a maximum of 6 signficant digits.
41
+ DefaultFormatter.defaultFormatter = new Intl.NumberFormat(undefined, {
42
+ maximumSignificantDigits: DefaultFormatter.maximumDigits,
43
+ useGrouping: true
44
+ });
45
+ // Formatter to use for numbers that have leading zeros. It limits the number of rendered
46
+ // digits using 'maximumFractionDigits', which will result in less than 6 significant digits
47
+ // in order to render no more than 6 total digits.
48
+ DefaultFormatter.leadingZeroFormatter = new Intl.NumberFormat(undefined, {
49
+ maximumFractionDigits: DefaultFormatter.maximumDigits - 1,
50
+ useGrouping: true
51
+ });
52
+ // Formatter for numbers that should be displayed in exponential notation. This should be used
53
+ // for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.
54
+ DefaultFormatter.exponentialFormatter = new Intl.NumberFormat(undefined, {
55
+ maximumSignificantDigits: DefaultFormatter.maximumDigits,
56
+ notation: 'scientific'
57
+ });
58
+ //# sourceMappingURL=default-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-formatter.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/models/default-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IA2CvC,MAAM,CAAC,MAAc;QAC3B,yGAAyG;QACzG,4GAA4G;QAC5G,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAChD,MAAM,SAAS,GAAG,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC;QAC5D,OAAO,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAC3C,CAAC;IAEO,qBAAqB,CAAC,MAAc;QACxC,IAAI,MAAM,KAAK,CAAC,EAAE;YACd,OAAO,gBAAgB,CAAC,gBAAgB,CAAC;SAC5C;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvC,IACI,aAAa,IAAI,gBAAgB,CAAC,qBAAqB;eACpD,aAAa,GAAG,gBAAgB,CAAC,qBAAqB,EAC3D;YACE,OAAO,gBAAgB,CAAC,oBAAoB,CAAC;SAChD;QACD,0HAA0H;QAC1H,+HAA+H;QAC/H,2EAA2E;QAC3E,IAAI,aAAa,GAAG,CAAC,EAAE;YACnB,OAAO,gBAAgB,CAAC,oBAAoB,CAAC;SAChD;QACD,OAAO,gBAAgB,CAAC,gBAAgB,CAAC;IAC7C,CAAC;;AArED,4EAA4E;AACpD,8BAAa,GAAG,CAAC,CAAC;AAE1C,wFAAwF;AACxF,0FAA0F;AAC1F,yEAAyE;AACjD,sCAAqB,GAAG,QAAQ,CAAC;AAEzD,uFAAuF;AACvF,yBAAyB;AACD,sCAAqB,GAAG,QAAQ,CAAC;AAEzD,4FAA4F;AACpE,iCAAgB,GAAG,IAAI,IAAI,CAAC,YAAY,CAC5D,SAAS,EACT;IACI,wBAAwB,EAAE,gBAAgB,CAAC,aAAa;IACxD,WAAW,EAAE,IAAI;CACpB,CACJ,CAAC;AAEF,yFAAyF;AACzF,4FAA4F;AAC5F,kDAAkD;AAC1B,qCAAoB,GAAG,IAAI,IAAI,CAAC,YAAY,CAChE,SAAS,EACT;IACI,qBAAqB,EAAE,gBAAgB,CAAC,aAAa,GAAG,CAAC;IACzD,WAAW,EAAE,IAAI;CACpB,CACJ,CAAC;AAEF,8FAA8F;AAC9F,6FAA6F;AACrE,qCAAoB,GAAG,IAAI,IAAI,CAAC,YAAY,CAChE,SAAS,EACT;IACI,wBAAwB,EAAE,gBAAgB,CAAC,aAAa;IACxD,QAAQ,EAAE,YAAY;CACzB,CACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The base class for number formatters used by the number-text column.
3
+ */
4
+ export declare abstract class NumberFormatter {
5
+ /**
6
+ * Tries to format the passed value using the `format()` function implemented by a concrete implementation of the class.
7
+ * Returns an empty string if the value is not a number or if `format()` throws an error.
8
+ */
9
+ formatValue(value: number | undefined | null): string;
10
+ protected abstract format(number: number): string;
11
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The base class for number formatters used by the number-text column.
3
+ */
4
+ export class NumberFormatter {
5
+ /**
6
+ * Tries to format the passed value using the `format()` function implemented by a concrete implementation of the class.
7
+ * Returns an empty string if the value is not a number or if `format()` throws an error.
8
+ */
9
+ formatValue(value) {
10
+ if (typeof value !== 'number') {
11
+ return '';
12
+ }
13
+ try {
14
+ return this.format(value);
15
+ }
16
+ catch {
17
+ return '';
18
+ }
19
+ }
20
+ }
21
+ //# sourceMappingURL=number-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-formatter.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/models/number-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAgB,eAAe;IACjC;;;OAGG;IACI,WAAW,CAAC,KAAgC;QAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC3B,OAAO,EAAE,CAAC;SACb;QAED,IAAI;YACA,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAC7B;QAAC,MAAM;YACJ,OAAO,EAAE,CAAC;SACb;IACL,CAAC;CAGJ"}
@@ -0,0 +1,8 @@
1
+ import { NumberFormatter } from './number-formatter';
2
+ /**
3
+ * The formatter for a number-text column whose format is configured to be 'roundToInteger'.
4
+ */
5
+ export declare class RoundToIntegerFormatter extends NumberFormatter {
6
+ private static readonly formatter;
7
+ protected format(number: number): string;
8
+ }
@@ -0,0 +1,18 @@
1
+ import { NumberFormatter } from './number-formatter';
2
+ /**
3
+ * The formatter for a number-text column whose format is configured to be 'roundToInteger'.
4
+ */
5
+ export class RoundToIntegerFormatter extends NumberFormatter {
6
+ format(number) {
7
+ // The NumberFormat option of `signDisplay: "negative"` is not supported in all browsers nimble supports.
8
+ // Because that option cannot be used to avoid rendering "-0", coerce the values that will round to -0 to 0
9
+ // prior to formatting.
10
+ const valueToFormat = Math.round(number) === 0 ? 0 : number;
11
+ return RoundToIntegerFormatter.formatter.format(valueToFormat);
12
+ }
13
+ }
14
+ RoundToIntegerFormatter.formatter = new Intl.NumberFormat(undefined, {
15
+ maximumFractionDigits: 0,
16
+ useGrouping: true
17
+ });
18
+ //# sourceMappingURL=round-to-integer-formatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"round-to-integer-formatter.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/models/round-to-integer-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,eAAe;IAM9C,MAAM,CAAC,MAAc;QAC3B,yGAAyG;QACzG,2GAA2G;QAC3G,uBAAuB;QACvB,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5D,OAAO,uBAAuB,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACnE,CAAC;;AAXuB,iCAAS,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE;IACjE,qBAAqB,EAAE,CAAC;IACxB,WAAW,EAAE,IAAI;CACpB,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Formatting scheme for the number-text table column
3
+ */
4
+ export declare const NumberTextFormat: {
5
+ readonly default: undefined;
6
+ readonly roundToInteger: "round-to-integer";
7
+ };
8
+ export declare type NumberTextFormat = (typeof NumberTextFormat)[keyof typeof NumberTextFormat];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Formatting scheme for the number-text table column
3
+ */
4
+ export const NumberTextFormat = {
5
+ default: undefined,
6
+ roundToInteger: 'round-to-integer'
7
+ };
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/table-column/number-text/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,kBAAkB;CAC5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ni/nimble-components",
3
- "version": "20.1.9",
3
+ "version": "20.1.10",
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",