@ni/nimble-components 34.10.2 → 35.0.0
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.
- package/dist/all-components-bundle.js +80 -73
- package/dist/all-components-bundle.js.map +1 -1
- package/dist/all-components-bundle.min.js +10 -11
- package/dist/all-components-bundle.min.js.map +1 -1
- package/dist/esm/table-column/number-text/index.d.ts +1 -1
- package/dist/esm/table-column/number-text/index.js +2 -2
- package/dist/esm/table-column/number-text/index.js.map +1 -1
- package/dist/esm/table-column/number-text/models/{number-text-unit-format.d.ts → unit-format-number-text.d.ts} +7 -7
- package/dist/esm/table-column/number-text/models/{number-text-unit-format.js → unit-format-number-text.js} +14 -14
- package/dist/esm/table-column/number-text/models/unit-format-number-text.js.map +1 -0
- package/dist/esm/unit/base/unit.d.ts +1 -1
- package/dist/esm/unit/base/unit.js.map +1 -1
- package/dist/esm/unit/byte/index.js +5 -5
- package/dist/esm/unit/byte/index.js.map +1 -1
- package/dist/esm/unit/celsius/index.js +2 -2
- package/dist/esm/unit/celsius/index.js.map +1 -1
- package/dist/esm/unit/fahrenheit/index.js +2 -2
- package/dist/esm/unit/fahrenheit/index.js.map +1 -1
- package/dist/esm/unit/volt/index.js +2 -2
- package/dist/esm/unit/volt/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/esm/table-column/number-text/models/number-text-unit-format.js.map +0 -1
- package/dist/esm/utilities/unit-format/decimal-unit-format.d.ts +0 -19
- package/dist/esm/utilities/unit-format/decimal-unit-format.js +0 -46
- package/dist/esm/utilities/unit-format/decimal-unit-format.js.map +0 -1
- package/dist/esm/utilities/unit-format/default-unit-format.d.ts +0 -22
- package/dist/esm/utilities/unit-format/default-unit-format.js +0 -70
- package/dist/esm/utilities/unit-format/default-unit-format.js.map +0 -1
- package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.d.ts +0 -16
- package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.js +0 -13
- package/dist/esm/utilities/unit-format/scaled-unit/scaled-unit.js.map +0 -1
- package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.d.ts +0 -11
- package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.js +0 -21
- package/dist/esm/utilities/unit-format/scaled-unit-format/intl-number-format-scaled-unit-format.js.map +0 -1
- package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.d.ts +0 -43
- package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.js +0 -63
- package/dist/esm/utilities/unit-format/scaled-unit-format/manually-translated-scaled-unit-format.js.map +0 -1
- package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.d.ts +0 -10
- package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.js +0 -10
- package/dist/esm/utilities/unit-format/scaled-unit-format/scaled-unit-format.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-format.d.ts +0 -16
- package/dist/esm/utilities/unit-format/unit-format.js +0 -21
- package/dist/esm/utilities/unit-format/unit-format.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.d.ts +0 -9
- package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.js +0 -31
- package/dist/esm/utilities/unit-format/unit-scale/byte-1024-unit-scale.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.d.ts +0 -9
- package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js +0 -25
- package/dist/esm/utilities/unit-format/unit-scale/byte-unit-scale.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/celsius-unit-scale.d.ts +0 -9
- package/dist/esm/utilities/unit-format/unit-scale/celsius-unit-scale.js +0 -18
- package/dist/esm/utilities/unit-format/unit-scale/celsius-unit-scale.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/fahrenheit-unit-scale.d.ts +0 -9
- package/dist/esm/utilities/unit-format/unit-scale/fahrenheit-unit-scale.js +0 -18
- package/dist/esm/utilities/unit-format/unit-scale/fahrenheit-unit-scale.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.d.ts +0 -9
- package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js +0 -15
- package/dist/esm/utilities/unit-format/unit-scale/passthrough-unit-scale.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/unit-scale.d.ts +0 -15
- package/dist/esm/utilities/unit-format/unit-scale/unit-scale.js +0 -49
- package/dist/esm/utilities/unit-format/unit-scale/unit-scale.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.d.ts +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.js +0 -17
- package/dist/esm/utilities/unit-format/unit-scale/utilities/metrix-prefixes.js.map +0 -1
- package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.d.ts +0 -9
- package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.js +0 -24
- package/dist/esm/utilities/unit-format/unit-scale/volt-unit-scale.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { UnitFormat } from '@ni/unit-format';
|
|
1
2
|
import { TableColumnAlignment, type TableNumberField } from '../../table/types';
|
|
2
3
|
import { TableColumnTextBase } from '../text-base';
|
|
3
4
|
import type { ColumnInternalsOptions } from '../base/models/column-internals';
|
|
4
5
|
import { NumberTextAlignment, NumberTextFormat } from './types';
|
|
5
|
-
import type { UnitFormat } from '../../utilities/unit-format/unit-format';
|
|
6
6
|
import { TableColumnNumberTextValidator } from './models/table-column-number-text-validator';
|
|
7
7
|
import type { TableColumnTextBaseColumnConfig } from '../text-base/cell-view';
|
|
8
8
|
export type TableColumnNumberTextCellRecord = TableNumberField<'value'>;
|
|
@@ -9,7 +9,7 @@ import { TableColumnSortOperation } from '../base/types';
|
|
|
9
9
|
import { tableColumnNumberTextGroupHeaderTag } from './group-header-view';
|
|
10
10
|
import { tableColumnNumberTextCellViewTag } from './cell-view';
|
|
11
11
|
import { NumberTextAlignment, NumberTextFormat } from './types';
|
|
12
|
-
import {
|
|
12
|
+
import { UnitFormatNumberText } from './models/unit-format-number-text';
|
|
13
13
|
import { TableColumnNumberTextValidator } from './models/table-column-number-text-validator';
|
|
14
14
|
import { lang } from '../../theme-provider';
|
|
15
15
|
import { Unit } from '../../unit/base/unit';
|
|
@@ -111,7 +111,7 @@ export class TableColumnNumberText extends mixinTextBase((TableColumnTextBase))
|
|
|
111
111
|
}
|
|
112
112
|
createFormatter() {
|
|
113
113
|
const unitScale = this.unit?.resolvedUnitScale;
|
|
114
|
-
return new
|
|
114
|
+
return new UnitFormatNumberText(lang.getValueFor(this), {
|
|
115
115
|
// Attribute values sometimes resolve to either null or undefined
|
|
116
116
|
// See https://github.com/microsoft/fast/issues/6630
|
|
117
117
|
numberTextFormat: this.format ?? undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/table-column/number-text/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAA8B,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACH,IAAI,EAEJ,uBAAuB,EACvB,UAAU,EACV,UAAU,EAEb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAyB,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClE,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,mBAAmB,EAAE,gBAAgB,EAAE,MAA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,6BAA6B;QACjC,IAAI,IAAI,CAAC,SAAS,KAAK,mBAAmB,CAAC,IAAI,EAAE,CAAC;YAC9C,OAAO,oBAAoB,CAAC,IAAI,CAAC;QACrC,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,KAAK,mBAAmB,CAAC,KAAK,EAAE,CAAC;YAC/C,OAAO,oBAAoB,CAAC,KAAK,CAAC;QACtC,CAAC;QAED,oFAAoF;QACpF,IACI,IAAI,CAAC,MAAM,KAAK,gBAAgB,CAAC,OAAO;eACrC,OAAO,IAAI,CAAC,oBAAoB,KAAK,QAAQ;eAC7C,CAAC,IAAI,CAAC,IAAI,EACf,CAAC;YACC,OAAO,oBAAoB,CAAC,KAAK,CAAC;QACtC,CAAC;QACD,OAAO,oBAAoB,CAAC,IAAI,CAAC;IACrC,CAAC;CACJ;AAvKU;IADN,IAAI;qDAC2B;AAGzB;IADN,IAAI;wDACiC;AAG/B;IADN,IAAI,CAAC,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;4DAC5C;AAMvB;IAJN,IAAI,CAAC;QACF,SAAS,EAAE,wBAAwB;QACnC,SAAS,EAAE,uBAAuB;KACrC,CAAC;mEACmC;AAI9B;IADN,UAAU;2DACqB;AAGxB;IADP,UAAU;mDACS;AAsJxB,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,iCAAiC,CAAC","sourcesContent":["import { DesignSystem, type DesignTokenSubscriber } from '@ni/fast-foundation';\nimport {\n attr,\n type Notifier,\n nullableNumberConverter,\n Observable,\n observable,\n type Subscriber\n} from '@ni/fast-element';\nimport { styles } from '../base/styles';\nimport { template } from './template';\nimport { TableColumnAlignment, type TableNumberField } from '../../table/types';\nimport { TableColumnTextBase, mixinTextBase } from '../text-base';\nimport { TableColumnSortOperation } from '../base/types';\nimport { tableColumnNumberTextGroupHeaderTag } from './group-header-view';\nimport { tableColumnNumberTextCellViewTag } from './cell-view';\nimport type { ColumnInternalsOptions } from '../base/models/column-internals';\nimport { NumberTextAlignment, NumberTextFormat } from './types';\nimport type { UnitFormat } from '../../utilities/unit-format/unit-format';\nimport { NumberTextUnitFormat } from './models/number-text-unit-format';\nimport { TableColumnNumberTextValidator } from './models/table-column-number-text-validator';\nimport { lang } from '../../theme-provider';\nimport { Unit } from '../../unit/base/unit';\nimport { waitUntilCustomElementsDefinedAsync } from '../../utilities/wait-until-custom-elements-defined-async';\nimport type { TableColumnTextBaseColumnConfig } from '../text-base/cell-view';\n\nexport type TableColumnNumberTextCellRecord = TableNumberField<'value'>;\nexport interface TableColumnNumberTextColumnConfig extends TableColumnTextBaseColumnConfig {\n formatter: UnitFormat;\n alignment: TableColumnAlignment;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-table-column-number-text': TableColumnNumberText;\n }\n}\n\n/**\n * The table column for displaying numbers as text.\n */\nexport class TableColumnNumberText extends mixinTextBase(\n TableColumnTextBase<\n TableColumnNumberTextColumnConfig,\n TableColumnNumberTextValidator\n >\n) {\n @attr\n public format: NumberTextFormat;\n\n @attr\n public alignment: NumberTextAlignment;\n\n @attr({ attribute: 'decimal-digits', converter: nullableNumberConverter })\n public decimalDigits?: number;\n\n @attr({\n attribute: 'decimal-maximum-digits',\n converter: nullableNumberConverter\n })\n public decimalMaximumDigits?: number;\n\n /** @internal */\n @observable\n public unitElements?: Element[];\n\n @observable\n private unit?: Unit;\n\n private unitNotifier?: Notifier;\n\n private readonly langSubscriber: DesignTokenSubscriber<typeof lang> = {\n handleChange: () => {\n this.updateColumnConfig();\n }\n };\n\n private readonly unitSubscriber: Subscriber = {\n handleChange: () => {\n this.updateColumnConfig();\n }\n };\n\n public override connectedCallback(): void {\n super.connectedCallback();\n lang.subscribe(this.langSubscriber, this);\n this.updateColumnConfig();\n }\n\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n lang.unsubscribe(this.langSubscriber, this);\n }\n\n public placeholderChanged(): void {\n this.updateColumnConfig();\n }\n\n protected override getColumnInternalsOptions(): ColumnInternalsOptions<TableColumnNumberTextValidator> {\n return {\n cellRecordFieldNames: ['value'],\n cellViewTag: tableColumnNumberTextCellViewTag,\n groupHeaderViewTag: tableColumnNumberTextGroupHeaderTag,\n delegatedEvents: [],\n sortOperation: TableColumnSortOperation.basic,\n validator: new TableColumnNumberTextValidator()\n };\n }\n\n private updateUnitNotifier(): void {\n if (this.unitNotifier) {\n this.unitNotifier.unsubscribe(this.unitSubscriber);\n this.unitNotifier = undefined;\n }\n\n if (this.unit) {\n const notifier = Observable.getNotifier(this.unit);\n notifier.subscribe(this.unitSubscriber, 'resolvedUnitScale');\n this.unitNotifier = notifier;\n }\n }\n\n private formatChanged(): void {\n this.updateColumnConfig();\n }\n\n private alignmentChanged(): void {\n this.updateColumnConfig();\n }\n\n private decimalDigitsChanged(): void {\n this.updateColumnConfig();\n }\n\n private decimalMaximumDigitsChanged(): void {\n this.updateColumnConfig();\n }\n\n private unitElementsChanged(): void {\n void this.updateUnit();\n }\n\n private async updateUnit(): Promise<void> {\n this.unit = undefined;\n if (this.unitElements) {\n await waitUntilCustomElementsDefinedAsync(this.unitElements);\n this.unit = this.unitElements.find(\n (x): x is Unit => x instanceof Unit\n );\n }\n this.updateUnitNotifier();\n }\n\n private unitChanged(): void {\n this.updateColumnConfig();\n }\n\n private updateColumnConfig(): void {\n const validator = this.columnInternals.validator;\n validator.validateDecimalDigits(this.format, this.decimalDigits);\n validator.validateDecimalMaximumDigits(\n this.format,\n this.decimalMaximumDigits\n );\n validator.validateNoMutuallyExclusiveProperties(\n this.format,\n this.decimalDigits,\n this.decimalMaximumDigits\n );\n validator.validateAtMostOneUnit(this.unitElements ?? []);\n\n if (validator.isValid()) {\n const columnConfig: TableColumnNumberTextColumnConfig = {\n formatter: this.createFormatter(),\n alignment: this.determineCellContentAlignment(),\n placeholder: this.placeholder\n };\n this.columnInternals.headerAlignment = columnConfig.alignment;\n this.columnInternals.columnConfig = columnConfig;\n } else {\n this.columnInternals.columnConfig = undefined;\n }\n }\n\n private createFormatter(): UnitFormat {\n const unitScale = this.unit?.resolvedUnitScale;\n return new NumberTextUnitFormat(lang.getValueFor(this), {\n // Attribute values sometimes resolve to either null or undefined\n // See https://github.com/microsoft/fast/issues/6630\n numberTextFormat: this.format ?? undefined,\n decimalDigits: this.decimalDigits ?? undefined,\n decimalMaximumDigits: this.decimalMaximumDigits ?? undefined,\n unitScale\n });\n }\n\n private determineCellContentAlignment(): TableColumnAlignment {\n if (this.alignment === NumberTextAlignment.left) {\n return TableColumnAlignment.left;\n }\n\n if (this.alignment === NumberTextAlignment.right) {\n return TableColumnAlignment.right;\n }\n\n // Look at format and decimal max digits and unit to determine the default alignment\n if (\n this.format === NumberTextFormat.decimal\n && typeof this.decimalMaximumDigits !== 'number'\n && !this.unit\n ) {\n return TableColumnAlignment.right;\n }\n return TableColumnAlignment.left;\n }\n}\n\nconst nimbleTableColumnNumberText = TableColumnNumberText.compose({\n baseName: 'table-column-number-text',\n template,\n styles\n});\n\nDesignSystem.getOrCreate()\n .withPrefix('nimble')\n .register(nimbleTableColumnNumberText());\nexport const tableColumnNumberTextTag = 'nimble-table-column-number-text';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/table-column/number-text/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAA8B,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EACH,IAAI,EAEJ,uBAAuB,EACvB,UAAU,EACV,UAAU,EAEb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,E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B;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,iCAAiC,CAAC","sourcesContent":["import { DesignSystem, type DesignTokenSubscriber } from '@ni/fast-foundation';\nimport {\n attr,\n type Notifier,\n nullableNumberConverter,\n Observable,\n observable,\n type Subscriber\n} from '@ni/fast-element';\nimport type { UnitFormat } from '@ni/unit-format';\nimport { styles } from '../base/styles';\nimport { template } from './template';\nimport { TableColumnAlignment, type TableNumberField } from '../../table/types';\nimport { TableColumnTextBase, mixinTextBase } from '../text-base';\nimport { TableColumnSortOperation } from '../base/types';\nimport { tableColumnNumberTextGroupHeaderTag } from './group-header-view';\nimport { tableColumnNumberTextCellViewTag } from './cell-view';\nimport type { ColumnInternalsOptions } from '../base/models/column-internals';\nimport { NumberTextAlignment, NumberTextFormat } from './types';\nimport { UnitFormatNumberText } from './models/unit-format-number-text';\nimport { TableColumnNumberTextValidator } from './models/table-column-number-text-validator';\nimport { lang } from '../../theme-provider';\nimport { Unit } from '../../unit/base/unit';\nimport { waitUntilCustomElementsDefinedAsync } from '../../utilities/wait-until-custom-elements-defined-async';\nimport type { TableColumnTextBaseColumnConfig } from '../text-base/cell-view';\n\nexport type TableColumnNumberTextCellRecord = TableNumberField<'value'>;\nexport interface TableColumnNumberTextColumnConfig extends TableColumnTextBaseColumnConfig {\n formatter: UnitFormat;\n alignment: TableColumnAlignment;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-table-column-number-text': TableColumnNumberText;\n }\n}\n\n/**\n * The table column for displaying numbers as text.\n */\nexport class TableColumnNumberText extends mixinTextBase(\n TableColumnTextBase<\n TableColumnNumberTextColumnConfig,\n TableColumnNumberTextValidator\n >\n) {\n @attr\n public format: NumberTextFormat;\n\n @attr\n public alignment: NumberTextAlignment;\n\n @attr({ attribute: 'decimal-digits', converter: nullableNumberConverter })\n public decimalDigits?: number;\n\n @attr({\n attribute: 'decimal-maximum-digits',\n converter: nullableNumberConverter\n })\n public decimalMaximumDigits?: number;\n\n /** @internal */\n @observable\n public unitElements?: Element[];\n\n @observable\n private unit?: Unit;\n\n private unitNotifier?: Notifier;\n\n private readonly langSubscriber: DesignTokenSubscriber<typeof lang> = {\n handleChange: () => {\n this.updateColumnConfig();\n }\n };\n\n private readonly unitSubscriber: Subscriber = {\n handleChange: () => {\n this.updateColumnConfig();\n }\n };\n\n public override connectedCallback(): void {\n super.connectedCallback();\n lang.subscribe(this.langSubscriber, this);\n this.updateColumnConfig();\n }\n\n public override disconnectedCallback(): void {\n super.disconnectedCallback();\n lang.unsubscribe(this.langSubscriber, this);\n }\n\n public placeholderChanged(): void {\n this.updateColumnConfig();\n }\n\n protected override getColumnInternalsOptions(): ColumnInternalsOptions<TableColumnNumberTextValidator> {\n return {\n cellRecordFieldNames: ['value'],\n cellViewTag: tableColumnNumberTextCellViewTag,\n groupHeaderViewTag: tableColumnNumberTextGroupHeaderTag,\n delegatedEvents: [],\n sortOperation: TableColumnSortOperation.basic,\n validator: new TableColumnNumberTextValidator()\n };\n }\n\n private updateUnitNotifier(): void {\n if (this.unitNotifier) {\n this.unitNotifier.unsubscribe(this.unitSubscriber);\n this.unitNotifier = undefined;\n }\n\n if (this.unit) {\n const notifier = Observable.getNotifier(this.unit);\n notifier.subscribe(this.unitSubscriber, 'resolvedUnitScale');\n this.unitNotifier = notifier;\n }\n }\n\n private formatChanged(): void {\n this.updateColumnConfig();\n }\n\n private alignmentChanged(): void {\n this.updateColumnConfig();\n }\n\n private decimalDigitsChanged(): void {\n this.updateColumnConfig();\n }\n\n private decimalMaximumDigitsChanged(): void {\n this.updateColumnConfig();\n }\n\n private unitElementsChanged(): void {\n void this.updateUnit();\n }\n\n private async updateUnit(): Promise<void> {\n this.unit = undefined;\n if (this.unitElements) {\n await waitUntilCustomElementsDefinedAsync(this.unitElements);\n this.unit = this.unitElements.find(\n (x): x is Unit => x instanceof Unit\n );\n }\n this.updateUnitNotifier();\n }\n\n private unitChanged(): void {\n this.updateColumnConfig();\n }\n\n private updateColumnConfig(): void {\n const validator = this.columnInternals.validator;\n validator.validateDecimalDigits(this.format, this.decimalDigits);\n validator.validateDecimalMaximumDigits(\n this.format,\n this.decimalMaximumDigits\n );\n validator.validateNoMutuallyExclusiveProperties(\n this.format,\n this.decimalDigits,\n this.decimalMaximumDigits\n );\n validator.validateAtMostOneUnit(this.unitElements ?? []);\n\n if (validator.isValid()) {\n const columnConfig: TableColumnNumberTextColumnConfig = {\n formatter: this.createFormatter(),\n alignment: this.determineCellContentAlignment(),\n placeholder: this.placeholder\n };\n this.columnInternals.headerAlignment = columnConfig.alignment;\n this.columnInternals.columnConfig = columnConfig;\n } else {\n this.columnInternals.columnConfig = undefined;\n }\n }\n\n private createFormatter(): UnitFormat {\n const unitScale = this.unit?.resolvedUnitScale;\n return new UnitFormatNumberText(lang.getValueFor(this), {\n // Attribute values sometimes resolve to either null or undefined\n // See https://github.com/microsoft/fast/issues/6630\n numberTextFormat: this.format ?? undefined,\n decimalDigits: this.decimalDigits ?? undefined,\n decimalMaximumDigits: this.decimalMaximumDigits ?? undefined,\n unitScale\n });\n }\n\n private determineCellContentAlignment(): TableColumnAlignment {\n if (this.alignment === NumberTextAlignment.left) {\n return TableColumnAlignment.left;\n }\n\n if (this.alignment === NumberTextAlignment.right) {\n return TableColumnAlignment.right;\n }\n\n // Look at format and decimal max digits and unit to determine the default alignment\n if (\n this.format === NumberTextFormat.decimal\n && typeof this.decimalMaximumDigits !== 'number'\n && !this.unit\n ) {\n return TableColumnAlignment.right;\n }\n return TableColumnAlignment.left;\n }\n}\n\nconst nimbleTableColumnNumberText = TableColumnNumberText.compose({\n baseName: 'table-column-number-text',\n template,\n styles\n});\n\nDesignSystem.getOrCreate()\n .withPrefix('nimble')\n .register(nimbleTableColumnNumberText());\nexport const tableColumnNumberTextTag = 'nimble-table-column-number-text';\n"]}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { UnitFormat, type UnitFormatOptions } from '
|
|
1
|
+
import { UnitFormat, type UnitFormatOptions } from '@ni/unit-format';
|
|
2
2
|
import { NumberTextFormat } from '../types';
|
|
3
|
-
export interface
|
|
3
|
+
export interface UnitFormatNumberTextOptions extends UnitFormatOptions {
|
|
4
4
|
numberTextFormat?: NumberTextFormat;
|
|
5
5
|
decimalDigits?: number;
|
|
6
6
|
decimalMaximumDigits?: number;
|
|
7
7
|
}
|
|
8
|
-
type
|
|
8
|
+
type UnitFormatNumberTextResolvedOptions = UnitFormatNumberTextOptions & Required<UnitFormatOptions>;
|
|
9
9
|
/**
|
|
10
10
|
* Format for numbers (with optional units) in a number-text table column.
|
|
11
11
|
*/
|
|
12
|
-
export declare class
|
|
12
|
+
export declare class UnitFormatNumberText extends UnitFormat {
|
|
13
13
|
private static readonly defaultDecimalDigits;
|
|
14
14
|
private readonly resolvedUnitFormat;
|
|
15
15
|
private readonly _resolvedOptions;
|
|
16
|
-
constructor(locale: string, options?:
|
|
17
|
-
resolvedOptions():
|
|
18
|
-
optionsMatch(targetOptions?:
|
|
16
|
+
constructor(locale: string, options?: UnitFormatNumberTextOptions);
|
|
17
|
+
resolvedOptions(): UnitFormatNumberTextResolvedOptions;
|
|
18
|
+
optionsMatch(targetOptions?: UnitFormatNumberTextOptions): boolean;
|
|
19
19
|
protected tryFormat(number: number): string;
|
|
20
20
|
private resolveUnitFormat;
|
|
21
21
|
private resolveOptions;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { UnitFormat } from '
|
|
2
|
-
import {
|
|
1
|
+
import { UnitFormat } from '@ni/unit-format';
|
|
2
|
+
import { unitScalePassthrough } from '@ni/unit-format/unit-scale/passthrough';
|
|
3
|
+
import { UnitFormatDefault } from '@ni/unit-format/default';
|
|
4
|
+
import { UnitFormatDecimal } from '@ni/unit-format/decimal';
|
|
3
5
|
import { NumberTextFormat } from '../types';
|
|
4
|
-
import { DefaultUnitFormat } from '../../../utilities/unit-format/default-unit-format';
|
|
5
|
-
import { DecimalUnitFormat } from '../../../utilities/unit-format/decimal-unit-format';
|
|
6
6
|
/**
|
|
7
7
|
* Format for numbers (with optional units) in a number-text table column.
|
|
8
8
|
*/
|
|
9
|
-
export class
|
|
9
|
+
export class UnitFormatNumberText extends UnitFormat {
|
|
10
10
|
constructor(locale, options) {
|
|
11
11
|
super();
|
|
12
12
|
this._resolvedOptions = this.resolveOptions(options);
|
|
@@ -31,18 +31,18 @@ export class NumberTextUnitFormat extends UnitFormat {
|
|
|
31
31
|
resolveUnitFormat(locale, options) {
|
|
32
32
|
const { numberTextFormat, decimalMaximumDigits, decimalDigits, unitScale } = options;
|
|
33
33
|
if (numberTextFormat === NumberTextFormat.default) {
|
|
34
|
-
return new
|
|
34
|
+
return new UnitFormatDefault(locale, {
|
|
35
35
|
unitScale
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
if (typeof decimalDigits === 'number') {
|
|
39
|
-
return new
|
|
39
|
+
return new UnitFormatDecimal(locale, {
|
|
40
40
|
minimumFractionDigits: decimalDigits,
|
|
41
41
|
maximumFractionDigits: decimalDigits,
|
|
42
42
|
unitScale
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
return new
|
|
45
|
+
return new UnitFormatDecimal(locale, {
|
|
46
46
|
minimumFractionDigits: 0,
|
|
47
47
|
maximumFractionDigits: decimalMaximumDigits,
|
|
48
48
|
unitScale
|
|
@@ -54,7 +54,7 @@ export class NumberTextUnitFormat extends UnitFormat {
|
|
|
54
54
|
numberTextFormat: NumberTextFormat.default,
|
|
55
55
|
decimalDigits: undefined,
|
|
56
56
|
decimalMaximumDigits: undefined,
|
|
57
|
-
unitScale: options?.unitScale ??
|
|
57
|
+
unitScale: options?.unitScale ?? unitScalePassthrough
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
const hasDecimalDigits = typeof options.decimalDigits === 'number';
|
|
@@ -65,18 +65,18 @@ export class NumberTextUnitFormat extends UnitFormat {
|
|
|
65
65
|
if (!hasDecimalDigits && !hasDecimalMaximumDigits) {
|
|
66
66
|
return {
|
|
67
67
|
numberTextFormat: NumberTextFormat.decimal,
|
|
68
|
-
decimalDigits:
|
|
68
|
+
decimalDigits: UnitFormatNumberText.defaultDecimalDigits,
|
|
69
69
|
decimalMaximumDigits: undefined,
|
|
70
|
-
unitScale: options.unitScale ??
|
|
70
|
+
unitScale: options.unitScale ?? unitScalePassthrough
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
return {
|
|
74
74
|
numberTextFormat: NumberTextFormat.decimal,
|
|
75
75
|
decimalDigits: options.decimalDigits,
|
|
76
76
|
decimalMaximumDigits: options.decimalMaximumDigits,
|
|
77
|
-
unitScale: options.unitScale ??
|
|
77
|
+
unitScale: options.unitScale ?? unitScalePassthrough
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
//# sourceMappingURL=number-text
|
|
81
|
+
UnitFormatNumberText.defaultDecimalDigits = 2;
|
|
82
|
+
//# sourceMappingURL=unit-format-number-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-format-number-text.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/models/unit-format-number-text.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EAEb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAU5C;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAKhD,YAAmB,MAAc,EAAE,OAAqC;QACpE,KAAK,EAAE,CAAC;QACR,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'@ni/unit-format';\nimport { unitScalePassthrough } from '@ni/unit-format/unit-scale/passthrough';\nimport { UnitFormatDefault } from '@ni/unit-format/default';\nimport { UnitFormatDecimal } from '@ni/unit-format/decimal';\nimport { NumberTextFormat } from '../types';\n\nexport interface UnitFormatNumberTextOptions extends UnitFormatOptions {\n numberTextFormat?: NumberTextFormat;\n decimalDigits?: number;\n decimalMaximumDigits?: number;\n}\ntype UnitFormatNumberTextResolvedOptions = UnitFormatNumberTextOptions\n & Required<UnitFormatOptions>;\n\n/**\n * Format for numbers (with optional units) in a number-text table column.\n */\nexport class UnitFormatNumberText extends UnitFormat {\n private static readonly defaultDecimalDigits = 2;\n private readonly resolvedUnitFormat: UnitFormatDefault | UnitFormatDecimal;\n private readonly _resolvedOptions: UnitFormatNumberTextResolvedOptions;\n\n public constructor(locale: string, options?: UnitFormatNumberTextOptions) {\n super();\n this._resolvedOptions = this.resolveOptions(options);\n this.resolvedUnitFormat = this.resolveUnitFormat(\n locale,\n this._resolvedOptions\n );\n }\n\n public override resolvedOptions(): UnitFormatNumberTextResolvedOptions {\n return { ...this._resolvedOptions };\n }\n\n public optionsMatch(targetOptions?: UnitFormatNumberTextOptions): boolean {\n const targetResolvedOptions = this.resolveOptions(targetOptions);\n return (\n this._resolvedOptions.decimalDigits\n === targetResolvedOptions.decimalDigits\n && this._resolvedOptions.decimalMaximumDigits\n === targetResolvedOptions.decimalMaximumDigits\n && this._resolvedOptions.numberTextFormat\n === targetResolvedOptions.numberTextFormat\n && this._resolvedOptions.unitScale === targetResolvedOptions.unitScale\n );\n }\n\n protected override tryFormat(number: number): string {\n return this.resolvedUnitFormat.format(number);\n }\n\n private resolveUnitFormat(\n locale: string,\n options: UnitFormatNumberTextResolvedOptions\n ): UnitFormatDefault | UnitFormatDecimal {\n const {\n numberTextFormat,\n decimalMaximumDigits,\n decimalDigits,\n unitScale\n } = options;\n\n if (numberTextFormat === NumberTextFormat.default) {\n return new UnitFormatDefault(locale, {\n unitScale\n });\n }\n if (typeof decimalDigits === 'number') {\n return new UnitFormatDecimal(locale, {\n minimumFractionDigits: decimalDigits,\n maximumFractionDigits: decimalDigits,\n unitScale\n });\n }\n return new UnitFormatDecimal(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: decimalMaximumDigits,\n unitScale\n });\n }\n\n private resolveOptions(\n options?: UnitFormatNumberTextOptions\n ): UnitFormatNumberTextResolvedOptions {\n if (!options || options.numberTextFormat === NumberTextFormat.default) {\n return {\n numberTextFormat: NumberTextFormat.default,\n decimalDigits: undefined,\n decimalMaximumDigits: undefined,\n unitScale: options?.unitScale ?? unitScalePassthrough\n };\n }\n const hasDecimalDigits = typeof options.decimalDigits === 'number';\n const hasDecimalMaximumDigits = typeof options.decimalMaximumDigits === 'number';\n if (hasDecimalDigits && hasDecimalMaximumDigits) {\n throw new Error(\n 'decimalDigits and decimalMaximumDigits are mutually exclusive. Do not specify both.'\n );\n }\n if (!hasDecimalDigits && !hasDecimalMaximumDigits) {\n return {\n numberTextFormat: NumberTextFormat.decimal,\n decimalDigits: UnitFormatNumberText.defaultDecimalDigits,\n decimalMaximumDigits: undefined,\n unitScale: options.unitScale ?? unitScalePassthrough\n };\n }\n return {\n numberTextFormat: NumberTextFormat.decimal,\n decimalDigits: options.decimalDigits,\n decimalMaximumDigits: options.decimalMaximumDigits,\n unitScale: options.unitScale ?? unitScalePassthrough\n };\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FoundationElement } from '@ni/fast-foundation';
|
|
2
|
-
import type { UnitScale } from '
|
|
2
|
+
import type { UnitScale } from '@ni/unit-format/unit-scale';
|
|
3
3
|
/**
|
|
4
4
|
* The base class for an element that provides a unit scale for scaled unit conversions
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit.js","sourceRoot":"","sources":["../../../../src/unit/base/unit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,OAAgB,IAAK,SAAQ,iBAAiB;CAInD;AADU;IADN,UAAU;+CAC0B","sourcesContent":["import { observable } from '@ni/fast-element';\nimport { FoundationElement } from '@ni/fast-foundation';\nimport type { UnitScale } from '
|
|
1
|
+
{"version":3,"file":"unit.js","sourceRoot":"","sources":["../../../../src/unit/base/unit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,OAAgB,IAAK,SAAQ,iBAAiB;CAInD;AADU;IADN,UAAU;+CAC0B","sourcesContent":["import { observable } from '@ni/fast-element';\nimport { FoundationElement } from '@ni/fast-foundation';\nimport type { UnitScale } from '@ni/unit-format/unit-scale';\n\n/**\n * The base class for an element that provides a unit scale for scaled unit conversions\n */\nexport abstract class Unit extends FoundationElement {\n /** @internal */\n @observable\n public resolvedUnitScale?: UnitScale;\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { attr } from '@ni/fast-element';
|
|
3
3
|
import { DesignSystem } from '@ni/fast-foundation';
|
|
4
|
+
import { unitScaleByte1024 } from '@ni/unit-format/unit-scale/byte-1024';
|
|
5
|
+
import { unitScaleByte } from '@ni/unit-format/unit-scale/byte';
|
|
4
6
|
import { template } from '../base/template';
|
|
5
|
-
import { byte1024UnitScale } from '../../utilities/unit-format/unit-scale/byte-1024-unit-scale';
|
|
6
|
-
import { byteUnitScale } from '../../utilities/unit-format/unit-scale/byte-unit-scale';
|
|
7
7
|
import { Unit } from '../base/unit';
|
|
8
8
|
import { styles } from '../base/styles';
|
|
9
9
|
/**
|
|
@@ -17,12 +17,12 @@ export class UnitByte extends Unit {
|
|
|
17
17
|
* the default of decimal (base 1000 scale with metric prefixes)
|
|
18
18
|
*/
|
|
19
19
|
this.binary = false;
|
|
20
|
-
this.resolvedUnitScale =
|
|
20
|
+
this.resolvedUnitScale = unitScaleByte;
|
|
21
21
|
}
|
|
22
22
|
binaryChanged() {
|
|
23
23
|
this.resolvedUnitScale = this.binary
|
|
24
|
-
?
|
|
25
|
-
:
|
|
24
|
+
? unitScaleByte1024
|
|
25
|
+
: unitScaleByte;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/byte/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/byte/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAQxC;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,IAAI;IAQ9B;QACI,KAAK,EAAE,CAAC;QARZ;;;WAGG;QAEI,WAAM,GAAG,KAAK,CAAC;QAIlB,IAAI,CAAC,iBAAiB,GAAG,aAAa,CAAC;IAC3C,CAAC;IAEO,aAAa;QACjB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,MAAM;YAChC,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAC,aAAa,CAAC;IACxB,CAAC;CACJ;AAZU;IADN,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;wCACJ;AAc1B,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC;IACpC,QAAQ,EAAE,WAAW;IACrB,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC","sourcesContent":["import { attr } from '@ni/fast-element';\nimport { DesignSystem } from '@ni/fast-foundation';\nimport { unitScaleByte1024 } from '@ni/unit-format/unit-scale/byte-1024';\nimport { unitScaleByte } from '@ni/unit-format/unit-scale/byte';\nimport { template } from '../base/template';\nimport { Unit } from '../base/unit';\nimport { styles } from '../base/styles';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-unit-byte': UnitByte;\n }\n}\n\n/**\n * Element that provides a unit scale for conversion of bytes\n */\nexport class UnitByte extends Unit {\n /**\n * Use binary (base 1024 scale with binary prefixes) instead of\n * the default of decimal (base 1000 scale with metric prefixes)\n */\n @attr({ mode: 'boolean' })\n public binary = false;\n\n public constructor() {\n super();\n this.resolvedUnitScale = unitScaleByte;\n }\n\n private binaryChanged(): void {\n this.resolvedUnitScale = this.binary\n ? unitScaleByte1024\n : unitScaleByte;\n }\n}\n\nconst nimbleUnitByte = UnitByte.compose({\n baseName: 'unit-byte',\n template,\n styles\n});\n\nDesignSystem.getOrCreate().withPrefix('nimble').register(nimbleUnitByte());\nexport const unitByteTag = 'nimble-unit-byte';\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DesignSystem } from '@ni/fast-foundation';
|
|
2
|
+
import { unitScaleCelsius } from '@ni/unit-format/unit-scale/celsius';
|
|
2
3
|
import { template } from '../base/template';
|
|
3
4
|
import { Unit } from '../base/unit';
|
|
4
|
-
import { celsiusUnitScale } from '../../utilities/unit-format/unit-scale/celsius-unit-scale';
|
|
5
5
|
import { styles } from '../base/styles';
|
|
6
6
|
/**
|
|
7
7
|
* Element representing degrees Celsius unit
|
|
@@ -9,7 +9,7 @@ import { styles } from '../base/styles';
|
|
|
9
9
|
export class UnitCelsius extends Unit {
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
-
this.resolvedUnitScale =
|
|
12
|
+
this.resolvedUnitScale = unitScaleCelsius;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
const nimbleUnitCelsius = UnitCelsius.compose({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/celsius/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/celsius/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAQxC;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,IAAI;IACjC;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,CAAC;IAC9C,CAAC;CACJ;AAED,MAAM,iBAAiB,GAAG,WAAW,CAAC,OAAO,CAAC;IAC1C,QAAQ,EAAE,cAAc;IACxB,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAC;AAC9E,MAAM,CAAC,MAAM,cAAc,GAAG,qBAAqB,CAAC","sourcesContent":["import { DesignSystem } from '@ni/fast-foundation';\nimport { unitScaleCelsius } from '@ni/unit-format/unit-scale/celsius';\nimport { template } from '../base/template';\nimport { Unit } from '../base/unit';\nimport { styles } from '../base/styles';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-unit-celsius': UnitCelsius;\n }\n}\n\n/**\n * Element representing degrees Celsius unit\n */\nexport class UnitCelsius extends Unit {\n public constructor() {\n super();\n this.resolvedUnitScale = unitScaleCelsius;\n }\n}\n\nconst nimbleUnitCelsius = UnitCelsius.compose({\n baseName: 'unit-celsius',\n template,\n styles\n});\n\nDesignSystem.getOrCreate().withPrefix('nimble').register(nimbleUnitCelsius());\nexport const unitCelsiusTag = 'nimble-unit-celsius';\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DesignSystem } from '@ni/fast-foundation';
|
|
2
|
+
import { unitScaleFahrenheit } from '@ni/unit-format/unit-scale/fahrenheit';
|
|
2
3
|
import { template } from '../base/template';
|
|
3
4
|
import { Unit } from '../base/unit';
|
|
4
|
-
import { fahrenheitUnitScale } from '../../utilities/unit-format/unit-scale/fahrenheit-unit-scale';
|
|
5
5
|
import { styles } from '../base/styles';
|
|
6
6
|
/**
|
|
7
7
|
* Element representing degrees Fahrenheit unit
|
|
@@ -9,7 +9,7 @@ import { styles } from '../base/styles';
|
|
|
9
9
|
export class UnitFahrenheit extends Unit {
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
-
this.resolvedUnitScale =
|
|
12
|
+
this.resolvedUnitScale = unitScaleFahrenheit;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
const nimbleUnitFahrenheit = UnitFahrenheit.compose({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/fahrenheit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/fahrenheit/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAQxC;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,IAAI;IACpC;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,iBAAiB,GAAG,mBAAmB,CAAC;IACjD,CAAC;CACJ;AAED,MAAM,oBAAoB,GAAG,cAAc,CAAC,OAAO,CAAC;IAChD,QAAQ,EAAE,iBAAiB;IAC3B,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE;KACrB,UAAU,CAAC,QAAQ,CAAC;KACpB,QAAQ,CAAC,oBAAoB,EAAE,CAAC,CAAC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC","sourcesContent":["import { DesignSystem } from '@ni/fast-foundation';\nimport { unitScaleFahrenheit } from '@ni/unit-format/unit-scale/fahrenheit';\nimport { template } from '../base/template';\nimport { Unit } from '../base/unit';\nimport { styles } from '../base/styles';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-unit-fahrenheit': UnitFahrenheit;\n }\n}\n\n/**\n * Element representing degrees Fahrenheit unit\n */\nexport class UnitFahrenheit extends Unit {\n public constructor() {\n super();\n this.resolvedUnitScale = unitScaleFahrenheit;\n }\n}\n\nconst nimbleUnitFahrenheit = UnitFahrenheit.compose({\n baseName: 'unit-fahrenheit',\n template,\n styles\n});\n\nDesignSystem.getOrCreate()\n .withPrefix('nimble')\n .register(nimbleUnitFahrenheit());\nexport const unitFahrenheitTag = 'nimble-unit-fahrenheit';\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DesignSystem } from '@ni/fast-foundation';
|
|
2
|
+
import { unitScaleVolt } from '@ni/unit-format/unit-scale/volt';
|
|
2
3
|
import { template } from '../base/template';
|
|
3
4
|
import { Unit } from '../base/unit';
|
|
4
|
-
import { voltUnitScale } from '../../utilities/unit-format/unit-scale/volt-unit-scale';
|
|
5
5
|
import { styles } from '../base/styles';
|
|
6
6
|
/**
|
|
7
7
|
* Element representing units for volts
|
|
@@ -9,7 +9,7 @@ import { styles } from '../base/styles';
|
|
|
9
9
|
export class UnitVolt extends Unit {
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
-
this.resolvedUnitScale =
|
|
12
|
+
this.resolvedUnitScale = unitScaleVolt;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
const nimbleUnitVolt = UnitVolt.compose({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/volt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/unit/volt/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAQxC;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,IAAI;IAC9B;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,iBAAiB,GAAG,aAAa,CAAC;IAC3C,CAAC;CACJ;AAED,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC;IACpC,QAAQ,EAAE,WAAW;IACrB,QAAQ;IACR,MAAM;CACT,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC","sourcesContent":["import { DesignSystem } from '@ni/fast-foundation';\nimport { unitScaleVolt } from '@ni/unit-format/unit-scale/volt';\nimport { template } from '../base/template';\nimport { Unit } from '../base/unit';\nimport { styles } from '../base/styles';\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-unit-volt': UnitVolt;\n }\n}\n\n/**\n * Element representing units for volts\n */\nexport class UnitVolt extends Unit {\n public constructor() {\n super();\n this.resolvedUnitScale = unitScaleVolt;\n }\n}\n\nconst nimbleUnitVolt = UnitVolt.compose({\n baseName: 'unit-volt',\n template,\n styles\n});\n\nDesignSystem.getOrCreate().withPrefix('nimble').register(nimbleUnitVolt());\nexport const unitVoltTag = 'nimble-unit-volt';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ni/nimble-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "35.0.0",
|
|
4
4
|
"description": "Styled web components for the NI Nimble Design System",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run generate-icons && npm run generate-workers && npm run build-components && npm run generate-scss",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"@ni/fast-foundation": "^10.1.2",
|
|
50
50
|
"@ni/fast-web-utilities": "^10.0.0",
|
|
51
51
|
"@ni/nimble-tokens": "^8.13.6",
|
|
52
|
+
"@ni/unit-format": "^1.0.0",
|
|
52
53
|
"@tanstack/table-core": "^8.19.3",
|
|
53
54
|
"@tanstack/virtual-core": "^3.10.6",
|
|
54
55
|
"@tiptap/core": "^3.10.1",
|
|
@@ -81,8 +82,7 @@
|
|
|
81
82
|
"tslib": "^2.2.0"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
|
-
"apache-arrow": "21.1.0"
|
|
85
|
-
"flatbuffers": "25.2.10"
|
|
85
|
+
"apache-arrow": "21.1.0"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@ni-private/eslint-config-nimble": "*",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"number-text-unit-format.js","sourceRoot":"","sources":["../../../../../src/table-column/number-text/models/number-text-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EAEb,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kEAAkE,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AAUvF;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAKhD,YAAmB,MAAc,EAAE,OAAqC;QACpE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,CAC5C,MAAM,EACN,IAAI,CAAC,gBAAgB,CACxB,CAAC;IACN,CAAC;IAEe,eAAe;QAC3B,OAAO,EAAE,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACxC,CAAC;IAEM,YAAY,CAAC,aAA2C;QAC3D,MAAM,qBAAqB,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACjE,OA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;gBAC/B,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,oBAAoB;aACxD,CAAC;QACN,CAAC;QACD,MAAM,gBAAgB,GAAG,OAAO,OAAO,CAAC,aAAa,KAAK,QAAQ,CAAC;QACnE,MAAM,uBAAuB,GAAG,OAAO,OAAO,CAAC,oBAAoB,KAAK,QAAQ,CAAC;QACjF,IAAI,gBAAgB,IAAI,uBAAuB,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CACX,qFAAqF,CACxF,CAAC;QACN,CAAC;QACD,IAAI,CAAC,gBAAgB,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAChD,OAAO;gBACH,gBAAgB,EAAE,gBAAgB,CAAC,OAAO;gBAC1C,aAAa,EAAE,oBAAoB,CAAC,oBAAoB;gBACxD,oBAAoB,EAAE,SAAS;gBAC/B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,oBAAoB;aACvD,CAAC;QACN,CAAC;QACD,OAAO;YACH,gBAAgB,EAAE,gBAAgB,CAAC,OAAO;YAC1C,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;YAClD,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,oBAAoB;SACvD,CAAC;IACN,CAAC;;AAhGuB,yCAAoB,GAAG,CAAC,CAAC","sourcesContent":["import {\n UnitFormat,\n type UnitFormatOptions\n} from '../../../utilities/unit-format/unit-format';\nimport { passthroughUnitScale } from '../../../utilities/unit-format/unit-scale/passthrough-unit-scale';\nimport { NumberTextFormat } from '../types';\nimport { DefaultUnitFormat } from '../../../utilities/unit-format/default-unit-format';\nimport { DecimalUnitFormat } from '../../../utilities/unit-format/decimal-unit-format';\n\nexport interface NumberTextUnitFormatOptions extends UnitFormatOptions {\n numberTextFormat?: NumberTextFormat;\n decimalDigits?: number;\n decimalMaximumDigits?: number;\n}\ntype ResolvedNumberTextUnitFormatOptions = NumberTextUnitFormatOptions\n & Required<UnitFormatOptions>;\n\n/**\n * Format for numbers (with optional units) in a number-text table column.\n */\nexport class NumberTextUnitFormat extends UnitFormat {\n private static readonly defaultDecimalDigits = 2;\n private readonly resolvedUnitFormat: DefaultUnitFormat | DecimalUnitFormat;\n private readonly _resolvedOptions: ResolvedNumberTextUnitFormatOptions;\n\n public constructor(locale: string, options?: NumberTextUnitFormatOptions) {\n super();\n this._resolvedOptions = this.resolveOptions(options);\n this.resolvedUnitFormat = this.resolveUnitFormat(\n locale,\n this._resolvedOptions\n );\n }\n\n public override resolvedOptions(): ResolvedNumberTextUnitFormatOptions {\n return { ...this._resolvedOptions };\n }\n\n public optionsMatch(targetOptions?: NumberTextUnitFormatOptions): boolean {\n const targetResolvedOptions = this.resolveOptions(targetOptions);\n return (\n this._resolvedOptions.decimalDigits\n === targetResolvedOptions.decimalDigits\n && this._resolvedOptions.decimalMaximumDigits\n === targetResolvedOptions.decimalMaximumDigits\n && this._resolvedOptions.numberTextFormat\n === targetResolvedOptions.numberTextFormat\n && this._resolvedOptions.unitScale === targetResolvedOptions.unitScale\n );\n }\n\n protected override tryFormat(number: number): string {\n return this.resolvedUnitFormat.format(number);\n }\n\n private resolveUnitFormat(\n locale: string,\n options: ResolvedNumberTextUnitFormatOptions\n ): DefaultUnitFormat | DecimalUnitFormat {\n const {\n numberTextFormat,\n decimalMaximumDigits,\n decimalDigits,\n unitScale\n } = options;\n\n if (numberTextFormat === NumberTextFormat.default) {\n return new DefaultUnitFormat(locale, {\n unitScale\n });\n }\n if (typeof decimalDigits === 'number') {\n return new DecimalUnitFormat(locale, {\n minimumFractionDigits: decimalDigits,\n maximumFractionDigits: decimalDigits,\n unitScale\n });\n }\n return new DecimalUnitFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: decimalMaximumDigits,\n unitScale\n });\n }\n\n private resolveOptions(\n options?: NumberTextUnitFormatOptions\n ): ResolvedNumberTextUnitFormatOptions {\n if (!options || options.numberTextFormat === NumberTextFormat.default) {\n return {\n numberTextFormat: NumberTextFormat.default,\n decimalDigits: undefined,\n decimalMaximumDigits: undefined,\n unitScale: options?.unitScale ?? passthroughUnitScale\n };\n }\n const hasDecimalDigits = typeof options.decimalDigits === 'number';\n const hasDecimalMaximumDigits = typeof options.decimalMaximumDigits === 'number';\n if (hasDecimalDigits && hasDecimalMaximumDigits) {\n throw new Error(\n 'decimalDigits and decimalMaximumDigits are mutually exclusive. Do not specify both.'\n );\n }\n if (!hasDecimalDigits && !hasDecimalMaximumDigits) {\n return {\n numberTextFormat: NumberTextFormat.decimal,\n decimalDigits: NumberTextUnitFormat.defaultDecimalDigits,\n decimalMaximumDigits: undefined,\n unitScale: options.unitScale ?? passthroughUnitScale\n };\n }\n return {\n numberTextFormat: NumberTextFormat.decimal,\n decimalDigits: options.decimalDigits,\n decimalMaximumDigits: options.decimalMaximumDigits,\n unitScale: options.unitScale ?? passthroughUnitScale\n };\n }\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { UnitFormat, type UnitFormatOptions } from './unit-format';
|
|
2
|
-
interface DecimalUnitFormatOptions extends UnitFormatOptions {
|
|
3
|
-
minimumFractionDigits?: number;
|
|
4
|
-
maximumFractionDigits?: number;
|
|
5
|
-
}
|
|
6
|
-
type ResolvedDecimalUnitFormatOptions = Required<DecimalUnitFormatOptions>;
|
|
7
|
-
/**
|
|
8
|
-
* Format for decimal numbers with units.
|
|
9
|
-
*/
|
|
10
|
-
export declare class DecimalUnitFormat extends UnitFormat<DecimalUnitFormatOptions> {
|
|
11
|
-
private readonly unitScale;
|
|
12
|
-
private readonly minimumFractionDigits;
|
|
13
|
-
private readonly maximumFractionDigits;
|
|
14
|
-
private readonly scaledUnitFormatters;
|
|
15
|
-
constructor(locale: string, { minimumFractionDigits, maximumFractionDigits, unitScale }?: DecimalUnitFormatOptions);
|
|
16
|
-
resolvedOptions(): ResolvedDecimalUnitFormatOptions;
|
|
17
|
-
protected tryFormat(number: number): string;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { UnitFormat } from './unit-format';
|
|
2
|
-
import { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';
|
|
3
|
-
/**
|
|
4
|
-
* Format for decimal numbers with units.
|
|
5
|
-
*/
|
|
6
|
-
export class DecimalUnitFormat extends UnitFormat {
|
|
7
|
-
constructor(locale, { minimumFractionDigits = 0, maximumFractionDigits = Math.max(3, minimumFractionDigits), unitScale = passthroughUnitScale } = {
|
|
8
|
-
minimumFractionDigits: 0,
|
|
9
|
-
maximumFractionDigits: 3,
|
|
10
|
-
unitScale: passthroughUnitScale
|
|
11
|
-
}) {
|
|
12
|
-
super();
|
|
13
|
-
this.scaledUnitFormatters = new Map();
|
|
14
|
-
// Workaround to avoid a ts error about signDisplay not accepting the value 'negative'.
|
|
15
|
-
// It has been supported by browsers since 8/23, but TypeScript still hasn't
|
|
16
|
-
// added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269
|
|
17
|
-
const signDisplay = 'negative';
|
|
18
|
-
const intlNumberFormatOptions = {
|
|
19
|
-
maximumFractionDigits,
|
|
20
|
-
minimumFractionDigits,
|
|
21
|
-
signDisplay
|
|
22
|
-
};
|
|
23
|
-
for (const scaledUnit of unitScale.supportedScaledUnits) {
|
|
24
|
-
this.scaledUnitFormatters.set(scaledUnit.scaleFactor, scaledUnit.scaledUnitFormatFactory({
|
|
25
|
-
locale,
|
|
26
|
-
intlNumberFormatOptions
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
this.unitScale = unitScale;
|
|
30
|
-
this.minimumFractionDigits = minimumFractionDigits;
|
|
31
|
-
this.maximumFractionDigits = maximumFractionDigits;
|
|
32
|
-
}
|
|
33
|
-
resolvedOptions() {
|
|
34
|
-
return {
|
|
35
|
-
unitScale: this.unitScale,
|
|
36
|
-
maximumFractionDigits: this.maximumFractionDigits,
|
|
37
|
-
minimumFractionDigits: this.minimumFractionDigits
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
tryFormat(number) {
|
|
41
|
-
const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);
|
|
42
|
-
const scaledUnitFormatter = this.scaledUnitFormatters.get(scaledUnit.scaleFactor);
|
|
43
|
-
return scaledUnitFormatter.format(scaledValue);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=decimal-unit-format.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decimal-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/decimal-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,eAAe,CAAC;AAGnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAQ3E;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAoC;IAOvE,YACI,MAAc,EACd,EACI,qBAAqB,GAAG,CAAC,EACzB,qBAAqB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC,EAC1D,SAAS,GAAG,oBAAoB,KACN;QAC1B,qBAAqB,EAAE,CAAC;QACxB,qBAAqB,EAAE,CAAC;QACxB,SAAS,EAAE,oBAAoB;KAClC;QAED,KAAK,EAAE,CAAC;QAdK,yBAAoB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAexE,uFAAuF;QACvF,4EAA4E;QAC5E,6FAA6F;QAC7F,MAAM,WAAW,GAAG,UAAqD,CAAC;QAC1E,MAAM,uBAAuB,GAAG;YAC5B,qBAAqB;YACrB,qBAAqB;YACrB,WAAW;SACd,CAAC;QACF,KAAK,MAAM,UAAU,IAAI,SAAS,CAAC,oBAAoB,EAAE,CAAC;YACtD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACzB,UAAU,CAAC,WAAW,EACtB,UAAU,CAAC,uBAAuB,CAAC;gBAC/B,MAAM;gBACN,uBAAuB;aAC1B,CAAC,CACL,CAAC;QACN,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACvD,CAAC;IAEe,eAAe;QAC3B,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;YACjD,qBAAqB,EAAE,IAAI,CAAC,qBAAqB;SACpD,CAAC;IACN,CAAC;IAES,SAAS,CAAC,MAAc;QAC9B,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACvE,MAAM,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CACrD,UAAU,CAAC,WAAW,CACxB,CAAC;QACH,OAAO,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;CACJ","sourcesContent":["import { UnitFormat, type UnitFormatOptions } from './unit-format';\nimport type { ScaledUnitFormat } from './scaled-unit-format/scaled-unit-format';\nimport type { UnitScale } from './unit-scale/unit-scale';\nimport { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';\n\ninterface DecimalUnitFormatOptions extends UnitFormatOptions {\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n}\ntype ResolvedDecimalUnitFormatOptions = Required<DecimalUnitFormatOptions>;\n\n/**\n * Format for decimal numbers with units.\n */\nexport class DecimalUnitFormat extends UnitFormat<DecimalUnitFormatOptions> {\n private readonly unitScale: UnitScale;\n private readonly minimumFractionDigits: number;\n private readonly maximumFractionDigits: number;\n\n private readonly scaledUnitFormatters = new Map<number, ScaledUnitFormat>();\n\n public constructor(\n locale: string,\n {\n minimumFractionDigits = 0,\n maximumFractionDigits = Math.max(3, minimumFractionDigits),\n unitScale = passthroughUnitScale\n }: DecimalUnitFormatOptions = {\n minimumFractionDigits: 0,\n maximumFractionDigits: 3,\n unitScale: passthroughUnitScale\n }\n ) {\n super();\n // Workaround to avoid a ts error about signDisplay not accepting the value 'negative'.\n // It has been supported by browsers since 8/23, but TypeScript still hasn't\n // added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269\n const signDisplay = 'negative' as Intl.NumberFormatOptions['signDisplay'];\n const intlNumberFormatOptions = {\n maximumFractionDigits,\n minimumFractionDigits,\n signDisplay\n };\n for (const scaledUnit of unitScale.supportedScaledUnits) {\n this.scaledUnitFormatters.set(\n scaledUnit.scaleFactor,\n scaledUnit.scaledUnitFormatFactory({\n locale,\n intlNumberFormatOptions\n })\n );\n }\n this.unitScale = unitScale;\n this.minimumFractionDigits = minimumFractionDigits;\n this.maximumFractionDigits = maximumFractionDigits;\n }\n\n public override resolvedOptions(): ResolvedDecimalUnitFormatOptions {\n return {\n unitScale: this.unitScale,\n maximumFractionDigits: this.maximumFractionDigits,\n minimumFractionDigits: this.minimumFractionDigits\n };\n }\n\n protected tryFormat(number: number): string {\n const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);\n const scaledUnitFormatter = this.scaledUnitFormatters.get(\n scaledUnit.scaleFactor\n )!;\n return scaledUnitFormatter.format(scaledValue);\n }\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { UnitFormat, type UnitFormatOptions } from './unit-format';
|
|
2
|
-
interface DefaultUnitFormatOptions extends UnitFormatOptions {
|
|
3
|
-
}
|
|
4
|
-
type ResolvedDefaultUnitFormatOptions = Required<DefaultUnitFormatOptions>;
|
|
5
|
-
/**
|
|
6
|
-
* Format for numbers with units to show in a tabular form.
|
|
7
|
-
* Large and tiny numbers are shown exponentially and the rest as decimal.
|
|
8
|
-
*/
|
|
9
|
-
export declare class DefaultUnitFormat extends UnitFormat {
|
|
10
|
-
private static readonly maximumDigits;
|
|
11
|
-
private static readonly exponentialLowerBound;
|
|
12
|
-
private static readonly exponentialUpperBound;
|
|
13
|
-
private readonly unitScale;
|
|
14
|
-
private readonly defaultIntlNumberFormatOptions;
|
|
15
|
-
private readonly defaultScaledUnitFormatters;
|
|
16
|
-
private readonly exponentialIntlNumberFormatOptions;
|
|
17
|
-
private readonly exponentialScaledUnitFormatter;
|
|
18
|
-
constructor(locale: string, { unitScale }?: DefaultUnitFormatOptions);
|
|
19
|
-
resolvedOptions(): ResolvedDefaultUnitFormatOptions;
|
|
20
|
-
protected tryFormat(number: number): string;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { UnitFormat } from './unit-format';
|
|
2
|
-
import { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';
|
|
3
|
-
// Workaround to avoid ts errors about signDisplay not accepting the value 'negative'.
|
|
4
|
-
// It has been supported by browsers since 8/23, but TypeScript still hasn't
|
|
5
|
-
// added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269
|
|
6
|
-
const signDisplay = 'negative';
|
|
7
|
-
/**
|
|
8
|
-
* Format for numbers with units to show in a tabular form.
|
|
9
|
-
* Large and tiny numbers are shown exponentially and the rest as decimal.
|
|
10
|
-
*/
|
|
11
|
-
export class DefaultUnitFormat extends UnitFormat {
|
|
12
|
-
constructor(locale, { unitScale = passthroughUnitScale } = {
|
|
13
|
-
unitScale: passthroughUnitScale
|
|
14
|
-
}) {
|
|
15
|
-
super();
|
|
16
|
-
// Format options to use by default. It renders the number with a maximum of 6 signficant digits (including zero before decimal point).
|
|
17
|
-
this.defaultIntlNumberFormatOptions = {
|
|
18
|
-
maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
|
|
19
|
-
maximumFractionDigits: DefaultUnitFormat.maximumDigits - 1,
|
|
20
|
-
roundingPriority: 'lessPrecision',
|
|
21
|
-
signDisplay
|
|
22
|
-
};
|
|
23
|
-
this.defaultScaledUnitFormatters = new Map();
|
|
24
|
-
// Format options for numbers that should be displayed in exponential notation. This should be used
|
|
25
|
-
// for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.
|
|
26
|
-
this.exponentialIntlNumberFormatOptions = {
|
|
27
|
-
maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
|
|
28
|
-
notation: 'scientific',
|
|
29
|
-
signDisplay
|
|
30
|
-
};
|
|
31
|
-
for (const unit of unitScale.supportedScaledUnits) {
|
|
32
|
-
this.defaultScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
|
|
33
|
-
locale,
|
|
34
|
-
intlNumberFormatOptions: this.defaultIntlNumberFormatOptions
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
this.exponentialScaledUnitFormatter = unitScale.baseScaledUnit.scaledUnitFormatFactory({
|
|
38
|
-
locale,
|
|
39
|
-
intlNumberFormatOptions: this.exponentialIntlNumberFormatOptions
|
|
40
|
-
});
|
|
41
|
-
this.unitScale = unitScale;
|
|
42
|
-
}
|
|
43
|
-
resolvedOptions() {
|
|
44
|
-
return {
|
|
45
|
-
unitScale: this.unitScale
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
tryFormat(number) {
|
|
49
|
-
const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);
|
|
50
|
-
const absoluteValue = Math.abs(scaledValue);
|
|
51
|
-
const useExponential = absoluteValue !== 0
|
|
52
|
-
&& (absoluteValue >= DefaultUnitFormat.exponentialUpperBound
|
|
53
|
-
|| absoluteValue < DefaultUnitFormat.exponentialLowerBound);
|
|
54
|
-
return useExponential
|
|
55
|
-
? this.exponentialScaledUnitFormatter.format(number)
|
|
56
|
-
: this.defaultScaledUnitFormatters
|
|
57
|
-
.get(scaledUnit.scaleFactor)
|
|
58
|
-
.format(scaledValue);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// The maximum number of digits that should be rendered for any given value.
|
|
62
|
-
DefaultUnitFormat.maximumDigits = 6;
|
|
63
|
-
// Use exponential notation for numbers that will be rendered with 3 leading 0s or more.
|
|
64
|
-
// Because a maximum of 6 digits are rendered, showing more than 3 leading 0s is not ideal
|
|
65
|
-
// because then at least half of the displayed digits will be leading 0s.
|
|
66
|
-
DefaultUnitFormat.exponentialLowerBound = 0.000995;
|
|
67
|
-
// Use exponential formatting for numbers whose magnitude cannot otherwise be displayed
|
|
68
|
-
// with 6 digits or less.
|
|
69
|
-
DefaultUnitFormat.exponentialUpperBound = 999999.5;
|
|
70
|
-
//# sourceMappingURL=default-unit-format.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/default-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,eAAe,CAAC;AAGnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,sFAAsF;AACtF,4EAA4E;AAC5E,6FAA6F;AAC7F,MAAM,WAAW,GAAG,UAAqD,CAAC;AAO1E;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAqC7C,YACI,MAAc,EACd,EAAE,SAAS,GAAG,oBAAoB,KAA+B;QAC7D,SAAS,EAAE,oBAAoB;KAClC;QAED,KAAK,EAAE,CAAC;QA7BZ,uIAAuI;QACtH,mCAA8B,GAA6B;YACxE,wBAAwB,EAAE,iBAAiB,CAAC,aAAa;YACzD,qBAAqB,EAAE,iBAAiB,CAAC,aAAa,GAAG,CAAC;YAC1D,gBAAgB,EAAE,eAAe;YACjC,WAAW;SACd,CAAC;QAEe,gCAA2B,GAAG,IAAI,GAAG,EAGnD,CAAC;QAEJ,mGAAmG;QACnG,6FAA6F;QAC5E,uCAAkC,GAA6B;YAC5E,wBAAwB,EAAE,iBAAiB,CAAC,aAAa;YACzD,QAAQ,EAAE,YAAY;YACtB,WAAW;SACd,CAAC;QAWE,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,oBAAoB,EAAE,CAAC;YAChD,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAChC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,uBAAuB,CAAC;gBACzB,MAAM;gBACN,uBAAuB,EAAE,IAAI,CAAC,8BAA8B;aAC/D,CAAC,CACL,CAAC;QACN,CAAC;QACD,IAAI,CAAC,8BAA8B,GAAG,SAAS,CAAC,cAAc,CAAC,uBAAuB,CAAC;YACnF,MAAM;YACN,uBAAuB,EAAE,IAAI,CAAC,kCAAkC;SACnE,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAEe,eAAe;QAC3B,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,SAAS;SAC5B,CAAC;IACN,CAAC;IAES,SAAS,CAAC,MAAc;QAC9B,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAEvE,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAC5C,MAAM,cAAc,GAAG,aAAa,KAAK,CAAC;eACnC,CAAC,aAAa,IAAI,iBAAiB,CAAC,qBAAqB;mBACrD,aAAa,GAAG,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;QACpE,OAAO,cAAc;YACjB,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,MAAM,CAAC,MAAM,CAAC;YACpD,CAAC,CAAC,IAAI,CAAC,2BAA2B;iBAC7B,GAAG,CAAC,UAAU,CAAC,WAAW,CAAE;iBAC5B,MAAM,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;;AA7ED,4EAA4E;AACpD,+BAAa,GAAG,CAAC,AAAJ,CAAK;AAE1C,wFAAwF;AACxF,0FAA0F;AAC1F,yEAAyE;AACjD,uCAAqB,GAAG,QAAQ,AAAX,CAAY;AAEzD,uFAAuF;AACvF,yBAAyB;AACD,uCAAqB,GAAG,QAAQ,AAAX,CAAY","sourcesContent":["import { UnitFormat, type UnitFormatOptions } from './unit-format';\nimport type { ScaledUnitFormat } from './scaled-unit-format/scaled-unit-format';\nimport type { UnitScale } from './unit-scale/unit-scale';\nimport { passthroughUnitScale } from './unit-scale/passthrough-unit-scale';\n\n// Workaround to avoid ts errors about signDisplay not accepting the value 'negative'.\n// It has been supported by browsers since 8/23, but TypeScript still hasn't\n// added it to the type definitions. See https://github.com/microsoft/TypeScript/issues/56269\nconst signDisplay = 'negative' as Intl.NumberFormatOptions['signDisplay'];\n\n// Allow consistent pattern for defining Options and ResolvedOptions\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\ninterface DefaultUnitFormatOptions extends UnitFormatOptions {}\ntype ResolvedDefaultUnitFormatOptions = Required<DefaultUnitFormatOptions>;\n\n/**\n * Format for numbers with units to show in a tabular form.\n * Large and tiny numbers are shown exponentially and the rest as decimal.\n */\nexport class DefaultUnitFormat extends UnitFormat {\n // The maximum number of digits that should be rendered for any given value.\n private static readonly maximumDigits = 6;\n\n // Use exponential notation for numbers that will be rendered with 3 leading 0s or more.\n // Because a maximum of 6 digits are rendered, showing more than 3 leading 0s is not ideal\n // because then at least half of the displayed digits will be leading 0s.\n private static readonly exponentialLowerBound = 0.000995;\n\n // Use exponential formatting for numbers whose magnitude cannot otherwise be displayed\n // with 6 digits or less.\n private static readonly exponentialUpperBound = 999999.5;\n\n private readonly unitScale: UnitScale;\n // Format options to use by default. It renders the number with a maximum of 6 signficant digits (including zero before decimal point).\n private readonly defaultIntlNumberFormatOptions: Intl.NumberFormatOptions = {\n maximumSignificantDigits: DefaultUnitFormat.maximumDigits,\n maximumFractionDigits: DefaultUnitFormat.maximumDigits - 1,\n roundingPriority: 'lessPrecision',\n signDisplay\n };\n\n private readonly defaultScaledUnitFormatters = new Map<\n number,\n ScaledUnitFormat\n >();\n\n // Format options for numbers that should be displayed in exponential notation. This should be used\n // for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.\n private readonly exponentialIntlNumberFormatOptions: Intl.NumberFormatOptions = {\n maximumSignificantDigits: DefaultUnitFormat.maximumDigits,\n notation: 'scientific',\n signDisplay\n };\n\n private readonly exponentialScaledUnitFormatter: ScaledUnitFormat;\n\n public constructor(\n locale: string,\n { unitScale = passthroughUnitScale }: DefaultUnitFormatOptions = {\n unitScale: passthroughUnitScale\n }\n ) {\n super();\n for (const unit of unitScale.supportedScaledUnits) {\n this.defaultScaledUnitFormatters.set(\n unit.scaleFactor,\n unit.scaledUnitFormatFactory({\n locale,\n intlNumberFormatOptions: this.defaultIntlNumberFormatOptions\n })\n );\n }\n this.exponentialScaledUnitFormatter = unitScale.baseScaledUnit.scaledUnitFormatFactory({\n locale,\n intlNumberFormatOptions: this.exponentialIntlNumberFormatOptions\n });\n this.unitScale = unitScale;\n }\n\n public override resolvedOptions(): ResolvedDefaultUnitFormatOptions {\n return {\n unitScale: this.unitScale\n };\n }\n\n protected tryFormat(number: number): string {\n const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);\n\n const absoluteValue = Math.abs(scaledValue);\n const useExponential = absoluteValue !== 0\n && (absoluteValue >= DefaultUnitFormat.exponentialUpperBound\n || absoluteValue < DefaultUnitFormat.exponentialLowerBound);\n return useExponential\n ? this.exponentialScaledUnitFormatter.format(number)\n : this.defaultScaledUnitFormatters\n .get(scaledUnit.scaleFactor)!\n .format(scaledValue);\n }\n}\n"]}
|