@ni/nimble-components 21.0.5 → 21.1.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.
@@ -16301,7 +16301,7 @@
16301
16301
 
16302
16302
  /**
16303
16303
  * Do not edit directly
16304
- * Generated on Mon, 29 Jan 2024 11:16:22 GMT
16304
+ * Generated on Wed, 31 Jan 2024 20:08:27 GMT
16305
16305
  */
16306
16306
 
16307
16307
  const Information100DarkUi = "#a46eff";
@@ -67092,6 +67092,83 @@ img.ProseMirror-separator {
67092
67092
  }
67093
67093
  }
67094
67094
 
67095
+ /**
67096
+ * Format for numbers (with optional units) in a number-text table column.
67097
+ */
67098
+ class NumberTextUnitFormat extends UnitFormat {
67099
+ constructor(locale, options) {
67100
+ super();
67101
+ this._resolvedOptions = this.resolveOptions(options);
67102
+ this.resolvedUnitFormat = this.resolveUnitFormat(locale, this._resolvedOptions);
67103
+ }
67104
+ resolvedOptions() {
67105
+ return { ...this._resolvedOptions };
67106
+ }
67107
+ optionsMatch(targetOptions) {
67108
+ const targetResolvedOptions = this.resolveOptions(targetOptions);
67109
+ return (this._resolvedOptions.decimalDigits
67110
+ === targetResolvedOptions.decimalDigits
67111
+ && this._resolvedOptions.decimalMaximumDigits
67112
+ === targetResolvedOptions.decimalMaximumDigits
67113
+ && this._resolvedOptions.numberTextFormat
67114
+ === targetResolvedOptions.numberTextFormat
67115
+ && this._resolvedOptions.unitScale === targetResolvedOptions.unitScale);
67116
+ }
67117
+ tryFormat(number) {
67118
+ return this.resolvedUnitFormat.format(number);
67119
+ }
67120
+ resolveUnitFormat(locale, options) {
67121
+ const { numberTextFormat, decimalMaximumDigits, decimalDigits, unitScale } = options;
67122
+ if (numberTextFormat === NumberTextFormat.default) {
67123
+ return new DefaultUnitFormat(locale, {
67124
+ unitScale
67125
+ });
67126
+ }
67127
+ if (typeof decimalDigits === 'number') {
67128
+ return new DecimalUnitFormat(locale, {
67129
+ minimumFractionDigits: decimalDigits,
67130
+ maximumFractionDigits: decimalDigits,
67131
+ unitScale
67132
+ });
67133
+ }
67134
+ return new DecimalUnitFormat(locale, {
67135
+ minimumFractionDigits: 0,
67136
+ maximumFractionDigits: decimalMaximumDigits,
67137
+ unitScale
67138
+ });
67139
+ }
67140
+ resolveOptions(options) {
67141
+ if (!options || options.numberTextFormat === NumberTextFormat.default) {
67142
+ return {
67143
+ numberTextFormat: NumberTextFormat.default,
67144
+ decimalDigits: undefined,
67145
+ decimalMaximumDigits: undefined,
67146
+ unitScale: options?.unitScale ?? passthroughUnitScale
67147
+ };
67148
+ }
67149
+ const hasDecimalDigits = typeof options.decimalDigits === 'number';
67150
+ const hasDecimalMaximumDigits = typeof options.decimalMaximumDigits === 'number';
67151
+ if (hasDecimalDigits && hasDecimalMaximumDigits) {
67152
+ throw new Error('decimalDigits and decimalMaximumDigits are mutually exclusive. Do not specify both.');
67153
+ }
67154
+ if (!hasDecimalDigits && !hasDecimalMaximumDigits) {
67155
+ return {
67156
+ numberTextFormat: NumberTextFormat.decimal,
67157
+ decimalDigits: NumberTextUnitFormat.defaultDecimalDigits,
67158
+ decimalMaximumDigits: undefined,
67159
+ unitScale: options.unitScale ?? passthroughUnitScale
67160
+ };
67161
+ }
67162
+ return {
67163
+ numberTextFormat: NumberTextFormat.decimal,
67164
+ decimalDigits: options.decimalDigits,
67165
+ decimalMaximumDigits: options.decimalMaximumDigits,
67166
+ unitScale: options.unitScale ?? passthroughUnitScale
67167
+ };
67168
+ }
67169
+ }
67170
+ NumberTextUnitFormat.defaultDecimalDigits = 2;
67171
+
67095
67172
  const numberTextValidityFlagNames = [
67096
67173
  'invalidDecimalDigits',
67097
67174
  'invalidDecimalMaximumDigits',
@@ -67152,7 +67229,6 @@ img.ProseMirror-separator {
67152
67229
  observable
67153
67230
  ], Unit.prototype, "resolvedUnitScale", void 0);
67154
67231
 
67155
- const defaultDecimalDigits = 2;
67156
67232
  /**
67157
67233
  * The table column for displaying numbers as text.
67158
67234
  */
@@ -67248,26 +67324,14 @@ img.ProseMirror-separator {
67248
67324
  }
67249
67325
  createFormatter() {
67250
67326
  const unitScale = this.unit?.resolvedUnitScale;
67251
- switch (this.format) {
67252
- case NumberTextFormat.decimal: {
67253
- const minimumFractionDigits = typeof this.decimalMaximumDigits === 'number'
67254
- ? 0
67255
- : this.decimalDigits ?? defaultDecimalDigits;
67256
- const maximumFractionDigits = this.decimalMaximumDigits
67257
- ?? this.decimalDigits
67258
- ?? defaultDecimalDigits;
67259
- return new DecimalUnitFormat(lang.getValueFor(this), {
67260
- minimumFractionDigits,
67261
- maximumFractionDigits,
67262
- unitScale
67263
- });
67264
- }
67265
- default: {
67266
- return new DefaultUnitFormat(lang.getValueFor(this), {
67267
- unitScale
67268
- });
67269
- }
67270
- }
67327
+ return new NumberTextUnitFormat(lang.getValueFor(this), {
67328
+ // Attribute values sometimes resolve to either null or undefined
67329
+ // See https://github.com/microsoft/fast/issues/6630
67330
+ numberTextFormat: this.format ?? undefined,
67331
+ decimalDigits: this.decimalDigits ?? undefined,
67332
+ decimalMaximumDigits: this.decimalMaximumDigits ?? undefined,
67333
+ unitScale
67334
+ });
67271
67335
  }
67272
67336
  determineCellContentAlignment() {
67273
67337
  if (this.alignment === NumberTextAlignment.left) {