@ni/nimble-components 21.6.7 → 21.6.8
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 +27 -64
- package/dist/all-components-bundle.js.map +1 -1
- package/dist/all-components-bundle.min.js +367 -372
- package/dist/all-components-bundle.min.js.map +1 -1
- package/dist/esm/dialog/index.d.ts +1 -10
- package/dist/esm/dialog/index.js.map +1 -1
- package/dist/esm/drawer/index.d.ts +1 -2
- package/dist/esm/drawer/index.js.map +1 -1
- package/dist/esm/utilities/unit-format/decimal-unit-format.d.ts +0 -2
- package/dist/esm/utilities/unit-format/decimal-unit-format.js +6 -11
- package/dist/esm/utilities/unit-format/decimal-unit-format.js.map +1 -1
- package/dist/esm/utilities/unit-format/default-unit-format.d.ts +0 -3
- package/dist/esm/utilities/unit-format/default-unit-format.js +20 -52
- package/dist/esm/utilities/unit-format/default-unit-format.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,15 +6,6 @@ declare global {
|
|
|
6
6
|
'nimble-dialog': Dialog;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
10
|
-
* This is a workaround for an incomplete definition of the native dialog element. Remove when using Typescript >=4.8.3.
|
|
11
|
-
* https://github.com/microsoft/TypeScript/issues/48267
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export interface ExtendedDialog extends HTMLDialogElement {
|
|
15
|
-
showModal(): void;
|
|
16
|
-
close(): void;
|
|
17
|
-
}
|
|
18
9
|
/**
|
|
19
10
|
* A nimble-styled dialog.
|
|
20
11
|
*/
|
|
@@ -43,7 +34,7 @@ export declare class Dialog<CloseReason = void> extends FoundationElement {
|
|
|
43
34
|
*
|
|
44
35
|
* @internal
|
|
45
36
|
*/
|
|
46
|
-
readonly dialogElement:
|
|
37
|
+
readonly dialogElement: HTMLDialogElement;
|
|
47
38
|
/** @internal */
|
|
48
39
|
footerIsEmpty: boolean;
|
|
49
40
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dialog/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACH,WAAW,EACX,6BAA6B,EAC7B,YAAY,EACZ,iBAAiB,EACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dialog/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACH,WAAW,EACX,6BAA6B,EAC7B,YAAY,EACZ,iBAAiB,EACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,CAAC;AAQzB;;GAEG;AACH,mEAAmE;AACnE,MAAM,OAAO,MAA2B,SAAQ,iBAAiB;IAAjE;;QAKI;;;;WAIG;QAEI,mBAAc,GAAG,KAAK,CAAC;QAE9B;;;;WAIG;QAEI,iBAAY,GAAG,KAAK,CAAC;QAE5B;;;;WAIG;QAEI,iBAAY,GAAG,KAAK,CAAC;QAS5B,gBAAgB;QAET,kBAAa,GAAG,IAAI,CAAC;IAqFhC,CAAC;IA/EG;;OAEG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC;IAC1C,CAAC;I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,MAAM,IAAI,KAAK,CACX,gEAAgE,CACnE,CAAC;SACL;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IACjC,CAAC;;AAzHD,uDAAuD;AACvD,gEAAgE;AACzC,oBAAa,GAAG,aAAa,CAAC;AAQrD;IADC,IAAI,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;8CAC1B;AAQ9B;IADC,IAAI,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;4CAC1B;AAQ5B;IADC,IAAI,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;4CAC1B;AAW5B;IADC,UAAU;6CACiB;AAI5B;IADC,UAAU;qDAC2C;AAqF1D,WAAW,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;AAEnD,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC;IAChC,QAAQ,EAAE,QAAQ;IAClB,QAAQ;IACR,MAAM;IACN,SAAS,EAAE,MAAM;CACpB,CAAC,CAAC;AAEH,YAAY,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;AACzE,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC","sourcesContent":["import { attr, observable } from '@microsoft/fast-element';\nimport {\n applyMixins,\n ARIAGlobalStatesAndProperties,\n DesignSystem,\n FoundationElement\n} from '@microsoft/fast-foundation';\nimport { UserDismissed } from '../patterns/dialog/types';\nimport { styles } from './styles';\nimport { template } from './template';\n\nexport { UserDismissed };\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-dialog': Dialog;\n }\n}\n\n/**\n * A nimble-styled dialog.\n */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport class Dialog<CloseReason = void> extends FoundationElement {\n // We want the member to match the name of the constant\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public static readonly UserDismissed = UserDismissed;\n\n /**\n * @public\n * @description\n * Prevents dismissing the dialog via the Escape key\n */\n @attr({ attribute: 'prevent-dismiss', mode: 'boolean' })\n public preventDismiss = false;\n\n /**\n * @public\n * @description\n * Hides the header of the dialog.\n */\n @attr({ attribute: 'header-hidden', mode: 'boolean' })\n public headerHidden = false;\n\n /**\n * @public\n * @description\n * Hides the footer of the dialog.\n */\n @attr({ attribute: 'footer-hidden', mode: 'boolean' })\n public footerHidden = false;\n\n /**\n * The ref to the internal dialog element.\n *\n * @internal\n */\n public readonly dialogElement!: HTMLDialogElement;\n\n /** @internal */\n @observable\n public footerIsEmpty = true;\n\n /** @internal */\n @observable\n public readonly slottedFooterElements?: HTMLElement[];\n\n /**\n * True if the dialog is open/showing, false otherwise\n */\n public get open(): boolean {\n return this.resolveShow !== undefined;\n }\n\n private resolveShow?: (reason: CloseReason | UserDismissed) => void;\n\n /**\n * Opens the dialog\n * @returns Promise that is resolved when the dialog is closed. The value of the resolved Promise is the reason value passed to the close() method, or UserDismissed if the dialog was closed via the ESC key.\n */\n public async show(): Promise<CloseReason | UserDismissed> {\n if (this.open) {\n throw new Error('Dialog is already open');\n }\n this.dialogElement.showModal();\n return new Promise((resolve, _reject) => {\n this.resolveShow = resolve;\n });\n }\n\n /**\n * Closes the dialog\n * @param reason An optional value indicating how/why the dialog was closed.\n */\n public close(reason: CloseReason): void {\n if (!this.open) {\n throw new Error('Dialog is not open');\n }\n this.dialogElement.close();\n this.doResolveShow(reason);\n }\n\n public slottedFooterElementsChanged(\n _prev: HTMLElement[] | undefined,\n next: HTMLElement[] | undefined\n ): void {\n this.footerIsEmpty = !next?.length;\n }\n\n /**\n * @internal\n */\n public cancelHandler(event: Event): boolean {\n if (this.preventDismiss) {\n event.preventDefault();\n } else {\n this.doResolveShow(UserDismissed);\n }\n return true;\n }\n\n /**\n * @internal\n */\n public closeHandler(event: Event): void {\n if (event.target !== this.dialogElement) {\n return;\n }\n if (this.resolveShow) {\n // If\n // - the browser implements dialogs with the CloseWatcher API, and\n // - the user presses ESC without first interacting with the dialog (e.g. clicking, scrolling),\n // the cancel event is not fired, but the close event still is, and the dialog just closes.\n this.doResolveShow(UserDismissed);\n }\n }\n\n private doResolveShow(reason: CloseReason | UserDismissed): void {\n if (!this.resolveShow) {\n throw new Error(\n 'Do not call doResolveShow unless there is a promise to resolve'\n );\n }\n this.resolveShow(reason);\n this.resolveShow = undefined;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface Dialog extends ARIAGlobalStatesAndProperties {}\napplyMixins(Dialog, ARIAGlobalStatesAndProperties);\n\nconst nimbleDialog = Dialog.compose({\n baseName: 'dialog',\n template,\n styles,\n baseClass: Dialog\n});\n\nDesignSystem.getOrCreate().withPrefix('nimble').register(nimbleDialog());\nexport const dialogTag = 'nimble-dialog';\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ARIAGlobalStatesAndProperties, FoundationElement } from '@microsoft/fast-foundation';
|
|
2
|
-
import type { ExtendedDialog } from '../dialog';
|
|
3
2
|
import { UserDismissed } from '../patterns/dialog/types';
|
|
4
3
|
import { DrawerLocation } from './types';
|
|
5
4
|
export { UserDismissed };
|
|
@@ -16,7 +15,7 @@ export declare class Drawer<CloseReason = void> extends FoundationElement {
|
|
|
16
15
|
static readonly UserDismissed: symbol;
|
|
17
16
|
location: DrawerLocation;
|
|
18
17
|
preventDismiss: boolean;
|
|
19
|
-
dialog:
|
|
18
|
+
dialog: HTMLDialogElement;
|
|
20
19
|
private closing;
|
|
21
20
|
private resolveShow?;
|
|
22
21
|
private closeReason;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/drawer/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EACH,W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,QAAQ,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC;AACzE,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC","sourcesContent":["import { attr } from '@microsoft/fast-element';\nimport {\n applyMixins,\n ARIAGlobalStatesAndProperties,\n DesignSystem,\n FoundationElement\n} from '@microsoft/fast-foundation';\nimport { eventAnimationEnd } from '@microsoft/fast-web-utilities';\nimport { UserDismissed } from '../patterns/dialog/types';\nimport { styles } from './styles';\nimport { template } from './template';\nimport { DrawerLocation } from './types';\n\nexport { UserDismissed };\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nimble-drawer': Drawer;\n }\n}\n\n/**\n * Drawer control. Shows content in a panel on the left / right side of the screen,\n * which animates to be visible with a slide-in / slide-out animation.\n */\n// eslint-disable-next-line @typescript-eslint/no-invalid-void-type\nexport class Drawer<CloseReason = void> extends FoundationElement {\n // We want the member to match the name of the constant\n // eslint-disable-next-line @typescript-eslint/naming-convention\n public static readonly UserDismissed = UserDismissed;\n\n @attr\n public location: DrawerLocation = DrawerLocation.right;\n\n @attr({ attribute: 'prevent-dismiss', mode: 'boolean' })\n public preventDismiss = false;\n\n public dialog!: HTMLDialogElement;\n private closing = false;\n\n private resolveShow?: (reason: CloseReason | UserDismissed) => void;\n private closeReason!: CloseReason | UserDismissed;\n\n /**\n * True if the drawer is open, opening, or closing. Otherwise, false.\n */\n public get open(): boolean {\n return this.resolveShow !== undefined;\n }\n\n /**\n * Opens the drawer\n * @returns Promise that is resolved when the drawer finishes closing. The value of the resolved\n * Promise is the reason value passed to the close() method, or UserDismissed if the drawer was\n * closed via the ESC key.\n */\n public async show(): Promise<CloseReason | UserDismissed> {\n if (this.open) {\n throw new Error('Drawer is already open');\n }\n this.openDialog();\n return new Promise((resolve, _reject) => {\n this.resolveShow = resolve;\n });\n }\n\n /**\n * Closes the drawer\n * @param reason An optional value indicating how/why the drawer was closed.\n */\n public close(reason: CloseReason): void {\n if (!this.open || this.closing) {\n throw new Error('Drawer is not open or already closing');\n }\n this.closeReason = reason;\n this.closeDialog();\n }\n\n /**\n * @internal\n */\n public cancelHandler(event: Event): boolean {\n // Allowing the dialog to close itself bypasses the drawer's animation logic, so we\n // should close the drawer ourselves when preventDismiss is false.\n event.preventDefault();\n\n if (!this.preventDismiss) {\n this.closeReason = UserDismissed;\n this.closeDialog();\n }\n return true;\n }\n\n /**\n * @internal\n */\n public closeHandler(event: Event): void {\n if (event.target !== this.dialog) {\n return;\n }\n if (this.resolveShow) {\n // If\n // - the browser implements dialogs with the CloseWatcher API, and\n // - the user presses ESC without first interacting with the drawer (e.g. clicking, scrolling),\n // the cancel event is not fired, but the close event still is, and the drawer just closes.\n // The animation is never started, so there is no animation end listener to clean up.\n this.doResolveShow(UserDismissed);\n }\n }\n\n private doResolveShow(reason: CloseReason | UserDismissed): void {\n if (!this.resolveShow) {\n throw new Error(\n 'Do not call doResolveShow unless there is a promise to resolve'\n );\n }\n this.resolveShow(reason);\n this.resolveShow = undefined;\n }\n\n private readonly animationEndHandlerFunction = (): void => this.animationEndHandler();\n\n private openDialog(): void {\n this.dialog.showModal();\n this.triggerAnimation();\n }\n\n private closeDialog(): void {\n this.closing = true;\n this.triggerAnimation();\n }\n\n private triggerAnimation(): void {\n this.dialog.classList.add('animating');\n if (this.closing) {\n this.dialog.classList.add('closing');\n }\n\n this.dialog.addEventListener(\n eventAnimationEnd,\n this.animationEndHandlerFunction\n );\n }\n\n private animationEndHandler(): void {\n this.dialog.removeEventListener(\n eventAnimationEnd,\n this.animationEndHandlerFunction\n );\n this.dialog.classList.remove('animating');\n if (this.closing) {\n this.dialog.classList.remove('closing');\n this.dialog.close();\n this.closing = false;\n this.doResolveShow(this.closeReason);\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface Drawer extends ARIAGlobalStatesAndProperties {}\napplyMixins(Drawer, ARIAGlobalStatesAndProperties);\n\nconst nimbleDrawer = Drawer.compose({\n baseName: 'drawer',\n template,\n styles\n});\nDesignSystem.getOrCreate().withPrefix('nimble').register(nimbleDrawer());\nexport const drawerTag = 'nimble-drawer';\n"]}
|
|
@@ -12,10 +12,8 @@ export declare class DecimalUnitFormat extends UnitFormat<DecimalUnitFormatOptio
|
|
|
12
12
|
private readonly minimumFractionDigits;
|
|
13
13
|
private readonly maximumFractionDigits;
|
|
14
14
|
private readonly scaledUnitFormatters;
|
|
15
|
-
private readonly tenPowDecimalDigits;
|
|
16
15
|
constructor(locale: string, { minimumFractionDigits, maximumFractionDigits, unitScale }?: DecimalUnitFormatOptions);
|
|
17
16
|
resolvedOptions(): ResolvedDecimalUnitFormatOptions;
|
|
18
17
|
protected tryFormat(number: number): string;
|
|
19
|
-
private willRoundToZero;
|
|
20
18
|
}
|
|
21
19
|
export {};
|
|
@@ -11,10 +11,14 @@ export class DecimalUnitFormat extends UnitFormat {
|
|
|
11
11
|
}) {
|
|
12
12
|
super();
|
|
13
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';
|
|
14
18
|
const intlNumberFormatOptions = {
|
|
15
19
|
maximumFractionDigits,
|
|
16
20
|
minimumFractionDigits,
|
|
17
|
-
|
|
21
|
+
signDisplay
|
|
18
22
|
};
|
|
19
23
|
for (const scaledUnit of unitScale.supportedScaledUnits) {
|
|
20
24
|
this.scaledUnitFormatters.set(scaledUnit.scaleFactor, scaledUnit.scaledUnitFormatFactory({
|
|
@@ -22,7 +26,6 @@ export class DecimalUnitFormat extends UnitFormat {
|
|
|
22
26
|
intlNumberFormatOptions
|
|
23
27
|
}));
|
|
24
28
|
}
|
|
25
|
-
this.tenPowDecimalDigits = 10 ** maximumFractionDigits;
|
|
26
29
|
this.unitScale = unitScale;
|
|
27
30
|
this.minimumFractionDigits = minimumFractionDigits;
|
|
28
31
|
this.maximumFractionDigits = maximumFractionDigits;
|
|
@@ -36,16 +39,8 @@ export class DecimalUnitFormat extends UnitFormat {
|
|
|
36
39
|
}
|
|
37
40
|
tryFormat(number) {
|
|
38
41
|
const { scaledValue, scaledUnit } = this.unitScale.scaleNumber(number);
|
|
39
|
-
const numberNormalized = this.willRoundToZero(scaledValue)
|
|
40
|
-
? 0
|
|
41
|
-
: scaledValue;
|
|
42
42
|
const scaledUnitFormatter = this.scaledUnitFormatters.get(scaledUnit.scaleFactor);
|
|
43
|
-
return scaledUnitFormatter.format(
|
|
44
|
-
}
|
|
45
|
-
willRoundToZero(number) {
|
|
46
|
-
// Multiply the value by 10 raised to maximumFractionDigits so that Math.round can be used to emulate rounding to
|
|
47
|
-
// maximumFractionDigits decimal places. If that rounded value is 0, then the value will be rendered with only 0s.
|
|
48
|
-
return Math.round(number * this.tenPowDecimalDigits) === 0;
|
|
43
|
+
return scaledUnitFormatter.format(scaledValue);
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
//# sourceMappingURL=decimal-unit-format.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/decimal-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAQ3E;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAoC;
|
|
1
|
+
{"version":3,"file":"decimal-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/decimal-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAQ3E;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAoC;IAOvE,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AAM,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;CACJ","sourcesContent":["import { UnitFormat, 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"]}
|
|
@@ -13,13 +13,10 @@ export declare class DefaultUnitFormat extends UnitFormat {
|
|
|
13
13
|
private readonly unitScale;
|
|
14
14
|
private readonly defaultIntlNumberFormatOptions;
|
|
15
15
|
private readonly defaultScaledUnitFormatters;
|
|
16
|
-
private readonly leadingZeroIntlNumberFormatOptions;
|
|
17
|
-
private readonly leadingZeroScaledUnitFormatters;
|
|
18
16
|
private readonly exponentialIntlNumberFormatOptions;
|
|
19
17
|
private readonly exponentialScaledUnitFormatter;
|
|
20
18
|
constructor(locale: string, { unitScale }?: DefaultUnitFormatOptions);
|
|
21
19
|
resolvedOptions(): ResolvedDefaultUnitFormatOptions;
|
|
22
20
|
protected tryFormat(number: number): string;
|
|
23
|
-
private resolveNumberStyle;
|
|
24
21
|
}
|
|
25
22
|
export {};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { UnitFormat } from './unit-format';
|
|
2
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';
|
|
3
7
|
/**
|
|
4
8
|
* Format for numbers with units to show in a tabular form.
|
|
5
9
|
* Large and tiny numbers are shown exponentially and the rest as decimal.
|
|
@@ -9,35 +13,26 @@ export class DefaultUnitFormat extends UnitFormat {
|
|
|
9
13
|
unitScale: passthroughUnitScale
|
|
10
14
|
}) {
|
|
11
15
|
super();
|
|
12
|
-
// Format options to use by default. It renders the number with a maximum of 6 signficant digits.
|
|
16
|
+
// Format options to use by default. It renders the number with a maximum of 6 signficant digits (including zero before decimal point).
|
|
13
17
|
this.defaultIntlNumberFormatOptions = {
|
|
14
18
|
maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
|
|
15
|
-
useGrouping: true
|
|
16
|
-
};
|
|
17
|
-
this.defaultScaledUnitFormatters = new Map();
|
|
18
|
-
// Format options to use for numbers that have leading zeros. It limits the number of rendered
|
|
19
|
-
// digits using 'maximumFractionDigits', which will result in less than 6 significant digits
|
|
20
|
-
// in order to render no more than 6 total digits.
|
|
21
|
-
this.leadingZeroIntlNumberFormatOptions = {
|
|
22
19
|
maximumFractionDigits: DefaultUnitFormat.maximumDigits - 1,
|
|
23
|
-
|
|
20
|
+
roundingPriority: 'lessPrecision',
|
|
21
|
+
signDisplay
|
|
24
22
|
};
|
|
25
|
-
this.
|
|
23
|
+
this.defaultScaledUnitFormatters = new Map();
|
|
26
24
|
// Format options for numbers that should be displayed in exponential notation. This should be used
|
|
27
25
|
// for numbers with magintudes over 'exponentialUpperBound' or under 'exponentialLowerBound'.
|
|
28
26
|
this.exponentialIntlNumberFormatOptions = {
|
|
29
27
|
maximumSignificantDigits: DefaultUnitFormat.maximumDigits,
|
|
30
|
-
notation: 'scientific'
|
|
28
|
+
notation: 'scientific',
|
|
29
|
+
signDisplay
|
|
31
30
|
};
|
|
32
31
|
for (const unit of unitScale.supportedScaledUnits) {
|
|
33
32
|
this.defaultScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
|
|
34
33
|
locale,
|
|
35
34
|
intlNumberFormatOptions: this.defaultIntlNumberFormatOptions
|
|
36
35
|
}));
|
|
37
|
-
this.leadingZeroScaledUnitFormatters.set(unit.scaleFactor, unit.scaledUnitFormatFactory({
|
|
38
|
-
locale,
|
|
39
|
-
intlNumberFormatOptions: this.leadingZeroIntlNumberFormatOptions
|
|
40
|
-
}));
|
|
41
36
|
}
|
|
42
37
|
this.exponentialScaledUnitFormatter = unitScale.baseScaledUnit.scaledUnitFormatFactory({
|
|
43
38
|
locale,
|
|
@@ -51,43 +46,16 @@ export class DefaultUnitFormat extends UnitFormat {
|
|
|
51
46
|
};
|
|
52
47
|
}
|
|
53
48
|
tryFormat(number) {
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const scaledUnitFormatter = this.leadingZeroScaledUnitFormatters.get(scaledUnit.scaleFactor);
|
|
65
|
-
return scaledUnitFormatter.format(scaledValue);
|
|
66
|
-
}
|
|
67
|
-
case 'exponential': {
|
|
68
|
-
const scaledUnitFormatter = this.exponentialScaledUnitFormatter;
|
|
69
|
-
return scaledUnitFormatter.format(numberNormalized);
|
|
70
|
-
}
|
|
71
|
-
default:
|
|
72
|
-
throw new Error('Unexpected number format style');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
resolveNumberStyle(number) {
|
|
76
|
-
if (number === 0) {
|
|
77
|
-
return 'default';
|
|
78
|
-
}
|
|
79
|
-
const absoluteValue = Math.abs(number);
|
|
80
|
-
if (absoluteValue >= DefaultUnitFormat.exponentialUpperBound
|
|
81
|
-
|| absoluteValue < DefaultUnitFormat.exponentialLowerBound) {
|
|
82
|
-
return 'exponential';
|
|
83
|
-
}
|
|
84
|
-
// Ideally, we could set 'roundingPriority: "lessPrecision"' with a formatter that has both 'maximumSignificantDigits' and
|
|
85
|
-
// 'maximumFractionDigits' configured instead of having two different formatters that we conditionally choose between. However,
|
|
86
|
-
// 'roundingPrioirty' is not supported yet in all browsers.
|
|
87
|
-
if (absoluteValue < 1) {
|
|
88
|
-
return 'leadingZero';
|
|
89
|
-
}
|
|
90
|
-
return 'default';
|
|
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);
|
|
91
59
|
}
|
|
92
60
|
}
|
|
93
61
|
// The maximum number of digits that should be rendered for any given value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/default-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"default-unit-format.js","sourceRoot":"","sources":["../../../../src/utilities/unit-format/default-unit-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,eAAe,CAAC;AAG9D,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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C;AAE1C,wFAAwF;AACxF,0FAA0F;AAC1F,yEAAyE;AACjD,uCAAqB,GAAG,QAAQ,CAAC;AAEzD,uFAAuF;AACvF,yBAAyB;AACD,uCAAqB,GAAG,QAAQ,CAAC","sourcesContent":["import { UnitFormat, 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-interface\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ni/nimble-components",
|
|
3
|
-
"version": "21.6.
|
|
3
|
+
"version": "21.6.8",
|
|
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",
|