@itwin/core-quantity 5.9.1 → 5.9.2
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/CHANGELOG.md +8 -1
- package/lib/cjs/FormatSpecHandle.d.ts +9 -10
- package/lib/cjs/FormatSpecHandle.d.ts.map +1 -1
- package/lib/cjs/FormatSpecHandle.js +17 -35
- package/lib/cjs/FormatSpecHandle.js.map +1 -1
- package/lib/cjs/Formatter/Interfaces.d.ts +1 -1
- package/lib/cjs/Formatter/Interfaces.js.map +1 -1
- package/lib/esm/FormatSpecHandle.d.ts +9 -10
- package/lib/esm/FormatSpecHandle.d.ts.map +1 -1
- package/lib/esm/FormatSpecHandle.js +17 -35
- package/lib/esm/FormatSpecHandle.js.map +1 -1
- package/lib/esm/Formatter/Interfaces.d.ts +1 -1
- package/lib/esm/Formatter/Interfaces.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Change Log - @itwin/core-quantity
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 08 May 2026 20:36:41 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.9.2
|
|
6
|
+
Fri, 08 May 2026 20:36:41 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Fix FormatSpecHandle stale state during onFormattingReady
|
|
4
11
|
|
|
5
12
|
## 5.9.1
|
|
6
13
|
Tue, 05 May 2026 17:43:30 GMT
|
|
@@ -9,22 +9,20 @@ import type { UnitSystemKey } from "./Interfaces";
|
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
export interface FormatSpecHandleArgs extends FormattingSpecArgs {
|
|
12
|
-
/** The provider that supplies spec lookups
|
|
12
|
+
/** The provider that supplies current formatting spec lookups. */
|
|
13
13
|
provider: FormattingSpecProvider;
|
|
14
14
|
}
|
|
15
|
-
/** A
|
|
16
|
-
*
|
|
15
|
+
/** A handle to formatting and parsing specs for a specific KoQ and persistence unit.
|
|
16
|
+
* Reads the current specs from the provider on access. Use [[QuantityFormatter.getFormatSpecHandle]]
|
|
17
17
|
* to create instances.
|
|
18
18
|
*
|
|
19
19
|
* When formatting is not yet ready, [[format]] returns a `value.toString()` fallback.
|
|
20
|
-
*
|
|
20
|
+
* Dispose the handle when it is no longer needed to invalidate it.
|
|
21
21
|
*
|
|
22
22
|
* @beta
|
|
23
23
|
*/
|
|
24
24
|
export declare class FormatSpecHandle implements Disposable {
|
|
25
|
-
private
|
|
26
|
-
private _parserSpec;
|
|
27
|
-
private _removeListener;
|
|
25
|
+
private _disposed;
|
|
28
26
|
private readonly _provider;
|
|
29
27
|
private readonly _koqName;
|
|
30
28
|
private readonly _persistenceUnit;
|
|
@@ -47,10 +45,11 @@ export declare class FormatSpecHandle implements Disposable {
|
|
|
47
45
|
* @returns The formatted string.
|
|
48
46
|
*/
|
|
49
47
|
format(value: number): string;
|
|
50
|
-
/**
|
|
51
|
-
* Idempotent and safe to call
|
|
48
|
+
/** Invalidate this handle.
|
|
49
|
+
* Idempotent and safe to call multiple times.
|
|
50
|
+
* No additional teardown is required because the handle owns no external resources.
|
|
52
51
|
*/
|
|
53
52
|
[Symbol.dispose](): void;
|
|
54
|
-
private
|
|
53
|
+
private _getEntry;
|
|
55
54
|
}
|
|
56
55
|
//# sourceMappingURL=FormatSpecHandle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatSpecHandle.d.ts","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAuB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,
|
|
1
|
+
{"version":3,"file":"FormatSpecHandle.d.ts","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAuB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,kEAAkE;IAClE,QAAQ,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IAEpD,gBAAgB;gBACJ,IAAI,EAAE,oBAAoB;IAOtC,4CAA4C;IAC5C,IAAW,OAAO,IAAI,MAAM,CAA0B;IAEtD,oDAAoD;IACpD,IAAW,eAAe,IAAI,MAAM,CAAkC;IAEtE,sFAAsF;IACtF,IAAW,MAAM,IAAI,aAAa,GAAG,SAAS,CAAyB;IAEvE,iEAAiE;IACjE,IAAW,aAAa,IAAI,aAAa,GAAG,SAAS,CAA4C;IAEjG,8DAA8D;IAC9D,IAAW,UAAU,IAAI,UAAU,GAAG,SAAS,CAAyC;IAExF;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAOpC;;;OAGG;IACI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;IAI/B,OAAO,CAAC,SAAS;CAUlB"}
|
|
@@ -5,19 +5,17 @@
|
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.FormatSpecHandle = void 0;
|
|
8
|
-
/** A
|
|
9
|
-
*
|
|
8
|
+
/** A handle to formatting and parsing specs for a specific KoQ and persistence unit.
|
|
9
|
+
* Reads the current specs from the provider on access. Use [[QuantityFormatter.getFormatSpecHandle]]
|
|
10
10
|
* to create instances.
|
|
11
11
|
*
|
|
12
12
|
* When formatting is not yet ready, [[format]] returns a `value.toString()` fallback.
|
|
13
|
-
*
|
|
13
|
+
* Dispose the handle when it is no longer needed to invalidate it.
|
|
14
14
|
*
|
|
15
15
|
* @beta
|
|
16
16
|
*/
|
|
17
17
|
class FormatSpecHandle {
|
|
18
|
-
|
|
19
|
-
_parserSpec;
|
|
20
|
-
_removeListener;
|
|
18
|
+
_disposed = false;
|
|
21
19
|
_provider;
|
|
22
20
|
_koqName;
|
|
23
21
|
_persistenceUnit;
|
|
@@ -28,10 +26,6 @@ class FormatSpecHandle {
|
|
|
28
26
|
this._koqName = args.name;
|
|
29
27
|
this._persistenceUnit = args.persistenceUnitName;
|
|
30
28
|
this._system = args.system;
|
|
31
|
-
this._removeListener = args.provider.onFormattingReady.addListener(() => {
|
|
32
|
-
this._refresh();
|
|
33
|
-
});
|
|
34
|
-
this._refresh();
|
|
35
29
|
}
|
|
36
30
|
/** The KoQ name this handle is keyed to. */
|
|
37
31
|
get koqName() { return this._koqName; }
|
|
@@ -40,47 +34,35 @@ class FormatSpecHandle {
|
|
|
40
34
|
/** The unit system this handle is pinned to, or `undefined` for the active system. */
|
|
41
35
|
get system() { return this._system; }
|
|
42
36
|
/** The current FormatterSpec, or undefined if not yet loaded. */
|
|
43
|
-
get formatterSpec() { return this.
|
|
37
|
+
get formatterSpec() { return this._getEntry()?.formatterSpec; }
|
|
44
38
|
/** The current ParserSpec, or undefined if not yet loaded. */
|
|
45
|
-
get parserSpec() { return this.
|
|
39
|
+
get parserSpec() { return this._getEntry()?.parserSpec; }
|
|
46
40
|
/** Format a quantity value using the current spec.
|
|
47
41
|
* If the formatter is not yet ready, returns `value.toString()` as a fallback.
|
|
48
42
|
* @param value - The numeric value to format.
|
|
49
43
|
* @returns The formatted string.
|
|
50
44
|
*/
|
|
51
45
|
format(value) {
|
|
52
|
-
|
|
46
|
+
const formatterSpec = this.formatterSpec;
|
|
47
|
+
if (!formatterSpec)
|
|
53
48
|
return value.toString();
|
|
54
|
-
return this._provider.formatQuantity(value,
|
|
49
|
+
return this._provider.formatQuantity(value, formatterSpec);
|
|
55
50
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Idempotent and safe to call
|
|
51
|
+
/** Invalidate this handle.
|
|
52
|
+
* Idempotent and safe to call multiple times.
|
|
53
|
+
* No additional teardown is required because the handle owns no external resources.
|
|
58
54
|
*/
|
|
59
55
|
[Symbol.dispose]() {
|
|
60
|
-
|
|
61
|
-
this._removeListener();
|
|
62
|
-
this._removeListener = undefined;
|
|
63
|
-
}
|
|
64
|
-
this._formatterSpec = undefined;
|
|
65
|
-
this._parserSpec = undefined;
|
|
56
|
+
this._disposed = true;
|
|
66
57
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const entry = this._provider.getSpecsByNameAndUnit({
|
|
58
|
+
_getEntry() {
|
|
59
|
+
if (this._disposed)
|
|
60
|
+
return undefined;
|
|
61
|
+
return this._provider.getSpecsByNameAndUnit({
|
|
72
62
|
name: this._koqName,
|
|
73
63
|
persistenceUnitName: this._persistenceUnit,
|
|
74
64
|
system: this._system,
|
|
75
65
|
});
|
|
76
|
-
if (entry) {
|
|
77
|
-
this._formatterSpec = entry.formatterSpec;
|
|
78
|
-
this._parserSpec = entry.parserSpec;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
this._formatterSpec = undefined;
|
|
82
|
-
this._parserSpec = undefined;
|
|
83
|
-
}
|
|
84
66
|
}
|
|
85
67
|
}
|
|
86
68
|
exports.FormatSpecHandle = FormatSpecHandle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatSpecHandle.js","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmB/F;;;;;;;;GAQG;AACH,MAAa,gBAAgB;IACnB,
|
|
1
|
+
{"version":3,"file":"FormatSpecHandle.js","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmB/F;;;;;;;;GAQG;AACH,MAAa,gBAAgB;IACnB,SAAS,GAAG,KAAK,CAAC;IACT,SAAS,CAAyB;IAClC,QAAQ,CAAS;IACjB,gBAAgB,CAAS;IACzB,OAAO,CAA4B;IAEpD,gBAAgB;IAChB,YAAY,IAA0B;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,4CAA4C;IAC5C,IAAW,OAAO,KAAa,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtD,oDAAoD;IACpD,IAAW,eAAe,KAAa,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEtE,sFAAsF;IACtF,IAAW,MAAM,KAAgC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAEvE,iEAAiE;IACjE,IAAW,aAAa,KAAgC,OAAO,IAAI,CAAC,SAAS,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;IAEjG,8DAA8D;IAC9D,IAAW,UAAU,KAA6B,OAAO,IAAI,CAAC,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;IAExF;;;;OAIG;IACI,MAAM,CAAC,KAAa;QACzB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACzC,IAAI,CAAC,aAAa;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC7D,CAAC;IAED;;;OAGG;IACI,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAEO,SAAS;QACf,IAAI,IAAI,CAAC,SAAS;YAChB,OAAO,SAAS,CAAC;QAEnB,OAAO,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC;YAC1C,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,mBAAmB,EAAE,IAAI,CAAC,gBAAgB;YAC1C,MAAM,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CAAC;IACL,CAAC;CACF;AA5DD,4CA4DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport type { FormatterSpec } from \"./Formatter/FormatterSpec\";\nimport type { FormattingSpecArgs, FormattingSpecEntry, FormattingSpecProvider } from \"./Formatter/Interfaces\";\nimport type { ParserSpec } from \"./ParserSpec\";\nimport type { UnitSystemKey } from \"./Interfaces\";\n\n/** Arguments for constructing a [[FormatSpecHandle]].\n * @internal\n */\nexport interface FormatSpecHandleArgs extends FormattingSpecArgs {\n /** The provider that supplies current formatting spec lookups. */\n provider: FormattingSpecProvider;\n}\n\n/** A handle to formatting and parsing specs for a specific KoQ and persistence unit.\n * Reads the current specs from the provider on access. Use [[QuantityFormatter.getFormatSpecHandle]]\n * to create instances.\n *\n * When formatting is not yet ready, [[format]] returns a `value.toString()` fallback.\n * Dispose the handle when it is no longer needed to invalidate it.\n *\n * @beta\n */\nexport class FormatSpecHandle implements Disposable {\n private _disposed = false;\n private readonly _provider: FormattingSpecProvider;\n private readonly _koqName: string;\n private readonly _persistenceUnit: string;\n private readonly _system: UnitSystemKey | undefined;\n\n /** @internal */\n constructor(args: FormatSpecHandleArgs) {\n this._provider = args.provider;\n this._koqName = args.name;\n this._persistenceUnit = args.persistenceUnitName;\n this._system = args.system;\n }\n\n /** The KoQ name this handle is keyed to. */\n public get koqName(): string { return this._koqName; }\n\n /** The persistence unit this handle is keyed to. */\n public get persistenceUnit(): string { return this._persistenceUnit; }\n\n /** The unit system this handle is pinned to, or `undefined` for the active system. */\n public get system(): UnitSystemKey | undefined { return this._system; }\n\n /** The current FormatterSpec, or undefined if not yet loaded. */\n public get formatterSpec(): FormatterSpec | undefined { return this._getEntry()?.formatterSpec; }\n\n /** The current ParserSpec, or undefined if not yet loaded. */\n public get parserSpec(): ParserSpec | undefined { return this._getEntry()?.parserSpec; }\n\n /** Format a quantity value using the current spec.\n * If the formatter is not yet ready, returns `value.toString()` as a fallback.\n * @param value - The numeric value to format.\n * @returns The formatted string.\n */\n public format(value: number): string {\n const formatterSpec = this.formatterSpec;\n if (!formatterSpec)\n return value.toString();\n return this._provider.formatQuantity(value, formatterSpec);\n }\n\n /** Invalidate this handle.\n * Idempotent and safe to call multiple times.\n * No additional teardown is required because the handle owns no external resources.\n */\n public [Symbol.dispose](): void {\n this._disposed = true;\n }\n\n private _getEntry(): FormattingSpecEntry | undefined {\n if (this._disposed)\n return undefined;\n\n return this._provider.getSpecsByNameAndUnit({\n name: this._koqName,\n persistenceUnitName: this._persistenceUnit,\n system: this._system,\n });\n }\n}\n"]}
|
|
@@ -213,7 +213,7 @@ export interface AddFormattingSpecArgs extends FormattingSpecArgs {
|
|
|
213
213
|
/** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */
|
|
214
214
|
formatProps?: FormatProps;
|
|
215
215
|
}
|
|
216
|
-
/** Minimal contract required by [[FormatSpecHandle]] to look up specs and
|
|
216
|
+
/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.
|
|
217
217
|
* Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.
|
|
218
218
|
* @beta
|
|
219
219
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAwHH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\nimport type { FormatterSpec } from \"./FormatterSpec\";\nimport type { ParserSpec } from \"../ParserSpec\";\n\n/** Defines a unit specification with a name and optional label override.\n * Used in composite formats and ratio unit specifications.\n * @beta\n */\nexport interface FormatUnitSpec {\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\n readonly name: string;\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\n readonly label?: string;\n}\n\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\n * @beta\n */\nexport interface ResolvedFormatUnitSpec {\n /** The resolved unit */\n readonly unit: UnitProps;\n /** Optional custom label that overrides the unit's default label */\n readonly label?: string;\n}\n\n/** Defines the units that make up a composite format and their display properties.\n * A composite format allows displaying a single quantity value across multiple units,\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\n * @beta\n */\nexport interface FormatCompositeProps {\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\n readonly spacer?: string;\n /** Whether to include unit segments with zero magnitude in the formatted output. */\n readonly includeZero?: boolean;\n /** Array of units this format is comprised of. Each unit specifies the unit name and\n * an optional custom label that will override the unit's default label when displaying values. */\n readonly units: FormatUnitSpec[];\n}\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n /** The format type. See [[FormatType]] */\n readonly type: string;\n\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\n readonly precision?: number;\n\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\n readonly roundFactor?: number;\n\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\n readonly minWidth?: number;\n\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\n readonly showSignOption?: string;\n\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\n readonly formatTraits?: string | string[];\n\n /** Character separating integer from fractional part. Must be empty or a single character. */\n readonly decimalSeparator?: string;\n\n /** Character separating thousands in the integer part. Must be empty or a single character. */\n readonly thousandSeparator?: string;\n\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\n readonly uomSeparator?: string;\n\n /** Required when type is Scientific. See [[ScientificType]] */\n readonly scientificType?: string;\n\n /** Required when type is Ratio. See [[RatioType]]*/\n readonly ratioType?: string;\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\n readonly ratioSeparator?: string;\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\n readonly ratioFormatType?: string;\n\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\n readonly stationOffsetSize?: number;\n\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\n readonly stationSeparator?: string;\n\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\n readonly allowMathematicOperations?: boolean;\n\n /** Composite format specification for multi-unit display. */\n readonly composite?: FormatCompositeProps;\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\n readonly units: ResolvedFormatUnitSpec[];\n};\n\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\n readonly azimuthBaseUnit?: UnitProps;\n readonly revolutionUnit?: UnitProps;\n readonly composite?: ResolvedFormatCompositeProps;\n readonly custom?: any;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n /** If set, indicates that the format set implies a particular unit system. The consumer\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\n * If `undefined`, the format change does not imply a unit system switch — the active\n * unit system remains unchanged.\n * @beta\n */\n impliedUnitSystem?: UnitSystemKey;\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;\n\n /**\n * Fired when formats are added, removed, or changed.\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\n */\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n /**\n * Adds a new format or updates an existing format associated with the specified name.\n */\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n /**\n * Removes the format associated with the specified name.\n * @param name The name of the format to remove.\n */\n removeFormat(name: string): Promise<void>;\n}\n\n/** Entries returned when looking up specs from the format registry.\n * @beta\n */\nexport interface FormattingSpecEntry {\n formatterSpec: FormatterSpec;\n parserSpec: ParserSpec;\n}\n\n/** Arguments for looking up a formatting spec entry.\n * @beta\n */\nexport interface FormattingSpecArgs {\n /** The KoQ name to look up. */\n name: string;\n /** The persistence unit name (e.g., `\"Units.M\"`). */\n persistenceUnitName: string;\n /** Optional unit system override. When omitted, the active system is used. */\n system?: UnitSystemKey;\n}\n\n/** Arguments for registering a formatting spec entry.\n * @beta\n */\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\n formatProps?: FormatProps;\n}\n\n/** Minimal contract required by [[FormatSpecHandle]] to look up specs and subscribe to reloads.\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\n * @beta\n */\nexport interface FormattingSpecProvider {\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\n /** Format a numeric value using the given formatter spec. */\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\n /** Event raised after the provider has finished reloading its caches.\n * Uses Set-backed event for safe concurrent add/remove during emit.\n */\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAwHH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\nimport type { FormatterSpec } from \"./FormatterSpec\";\nimport type { ParserSpec } from \"../ParserSpec\";\n\n/** Defines a unit specification with a name and optional label override.\n * Used in composite formats and ratio unit specifications.\n * @beta\n */\nexport interface FormatUnitSpec {\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\n readonly name: string;\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\n readonly label?: string;\n}\n\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\n * @beta\n */\nexport interface ResolvedFormatUnitSpec {\n /** The resolved unit */\n readonly unit: UnitProps;\n /** Optional custom label that overrides the unit's default label */\n readonly label?: string;\n}\n\n/** Defines the units that make up a composite format and their display properties.\n * A composite format allows displaying a single quantity value across multiple units,\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\n * @beta\n */\nexport interface FormatCompositeProps {\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\n readonly spacer?: string;\n /** Whether to include unit segments with zero magnitude in the formatted output. */\n readonly includeZero?: boolean;\n /** Array of units this format is comprised of. Each unit specifies the unit name and\n * an optional custom label that will override the unit's default label when displaying values. */\n readonly units: FormatUnitSpec[];\n}\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n /** The format type. See [[FormatType]] */\n readonly type: string;\n\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\n readonly precision?: number;\n\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\n readonly roundFactor?: number;\n\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\n readonly minWidth?: number;\n\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\n readonly showSignOption?: string;\n\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\n readonly formatTraits?: string | string[];\n\n /** Character separating integer from fractional part. Must be empty or a single character. */\n readonly decimalSeparator?: string;\n\n /** Character separating thousands in the integer part. Must be empty or a single character. */\n readonly thousandSeparator?: string;\n\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\n readonly uomSeparator?: string;\n\n /** Required when type is Scientific. See [[ScientificType]] */\n readonly scientificType?: string;\n\n /** Required when type is Ratio. See [[RatioType]]*/\n readonly ratioType?: string;\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\n readonly ratioSeparator?: string;\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\n readonly ratioFormatType?: string;\n\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\n readonly stationOffsetSize?: number;\n\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\n readonly stationSeparator?: string;\n\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\n readonly allowMathematicOperations?: boolean;\n\n /** Composite format specification for multi-unit display. */\n readonly composite?: FormatCompositeProps;\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\n readonly units: ResolvedFormatUnitSpec[];\n};\n\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\n readonly azimuthBaseUnit?: UnitProps;\n readonly revolutionUnit?: UnitProps;\n readonly composite?: ResolvedFormatCompositeProps;\n readonly custom?: any;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n /** If set, indicates that the format set implies a particular unit system. The consumer\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\n * If `undefined`, the format change does not imply a unit system switch — the active\n * unit system remains unchanged.\n * @beta\n */\n impliedUnitSystem?: UnitSystemKey;\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;\n\n /**\n * Fired when formats are added, removed, or changed.\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\n */\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n /**\n * Adds a new format or updates an existing format associated with the specified name.\n */\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n /**\n * Removes the format associated with the specified name.\n * @param name The name of the format to remove.\n */\n removeFormat(name: string): Promise<void>;\n}\n\n/** Entries returned when looking up specs from the format registry.\n * @beta\n */\nexport interface FormattingSpecEntry {\n formatterSpec: FormatterSpec;\n parserSpec: ParserSpec;\n}\n\n/** Arguments for looking up a formatting spec entry.\n * @beta\n */\nexport interface FormattingSpecArgs {\n /** The KoQ name to look up. */\n name: string;\n /** The persistence unit name (e.g., `\"Units.M\"`). */\n persistenceUnitName: string;\n /** Optional unit system override. When omitted, the active system is used. */\n system?: UnitSystemKey;\n}\n\n/** Arguments for registering a formatting spec entry.\n * @beta\n */\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\n formatProps?: FormatProps;\n}\n\n/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\n * @beta\n */\nexport interface FormattingSpecProvider {\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\n /** Format a numeric value using the given formatter spec. */\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\n /** Event raised after the provider has finished reloading its caches.\n * Uses Set-backed event for safe concurrent add/remove during emit.\n */\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\n}\n\n"]}
|
|
@@ -9,22 +9,20 @@ import type { UnitSystemKey } from "./Interfaces";
|
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
export interface FormatSpecHandleArgs extends FormattingSpecArgs {
|
|
12
|
-
/** The provider that supplies spec lookups
|
|
12
|
+
/** The provider that supplies current formatting spec lookups. */
|
|
13
13
|
provider: FormattingSpecProvider;
|
|
14
14
|
}
|
|
15
|
-
/** A
|
|
16
|
-
*
|
|
15
|
+
/** A handle to formatting and parsing specs for a specific KoQ and persistence unit.
|
|
16
|
+
* Reads the current specs from the provider on access. Use [[QuantityFormatter.getFormatSpecHandle]]
|
|
17
17
|
* to create instances.
|
|
18
18
|
*
|
|
19
19
|
* When formatting is not yet ready, [[format]] returns a `value.toString()` fallback.
|
|
20
|
-
*
|
|
20
|
+
* Dispose the handle when it is no longer needed to invalidate it.
|
|
21
21
|
*
|
|
22
22
|
* @beta
|
|
23
23
|
*/
|
|
24
24
|
export declare class FormatSpecHandle implements Disposable {
|
|
25
|
-
private
|
|
26
|
-
private _parserSpec;
|
|
27
|
-
private _removeListener;
|
|
25
|
+
private _disposed;
|
|
28
26
|
private readonly _provider;
|
|
29
27
|
private readonly _koqName;
|
|
30
28
|
private readonly _persistenceUnit;
|
|
@@ -47,10 +45,11 @@ export declare class FormatSpecHandle implements Disposable {
|
|
|
47
45
|
* @returns The formatted string.
|
|
48
46
|
*/
|
|
49
47
|
format(value: number): string;
|
|
50
|
-
/**
|
|
51
|
-
* Idempotent and safe to call
|
|
48
|
+
/** Invalidate this handle.
|
|
49
|
+
* Idempotent and safe to call multiple times.
|
|
50
|
+
* No additional teardown is required because the handle owns no external resources.
|
|
52
51
|
*/
|
|
53
52
|
[Symbol.dispose](): void;
|
|
54
|
-
private
|
|
53
|
+
private _getEntry;
|
|
55
54
|
}
|
|
56
55
|
//# sourceMappingURL=FormatSpecHandle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatSpecHandle.d.ts","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAuB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,
|
|
1
|
+
{"version":3,"file":"FormatSpecHandle.d.ts","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAuB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC9G,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAC9D,kEAAkE;IAClE,QAAQ,EAAE,sBAAsB,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4B;IAEpD,gBAAgB;gBACJ,IAAI,EAAE,oBAAoB;IAOtC,4CAA4C;IAC5C,IAAW,OAAO,IAAI,MAAM,CAA0B;IAEtD,oDAAoD;IACpD,IAAW,eAAe,IAAI,MAAM,CAAkC;IAEtE,sFAAsF;IACtF,IAAW,MAAM,IAAI,aAAa,GAAG,SAAS,CAAyB;IAEvE,iEAAiE;IACjE,IAAW,aAAa,IAAI,aAAa,GAAG,SAAS,CAA4C;IAEjG,8DAA8D;IAC9D,IAAW,UAAU,IAAI,UAAU,GAAG,SAAS,CAAyC;IAExF;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAOpC;;;OAGG;IACI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;IAI/B,OAAO,CAAC,SAAS;CAUlB"}
|
|
@@ -2,19 +2,17 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** A
|
|
6
|
-
*
|
|
5
|
+
/** A handle to formatting and parsing specs for a specific KoQ and persistence unit.
|
|
6
|
+
* Reads the current specs from the provider on access. Use [[QuantityFormatter.getFormatSpecHandle]]
|
|
7
7
|
* to create instances.
|
|
8
8
|
*
|
|
9
9
|
* When formatting is not yet ready, [[format]] returns a `value.toString()` fallback.
|
|
10
|
-
*
|
|
10
|
+
* Dispose the handle when it is no longer needed to invalidate it.
|
|
11
11
|
*
|
|
12
12
|
* @beta
|
|
13
13
|
*/
|
|
14
14
|
export class FormatSpecHandle {
|
|
15
|
-
|
|
16
|
-
_parserSpec;
|
|
17
|
-
_removeListener;
|
|
15
|
+
_disposed = false;
|
|
18
16
|
_provider;
|
|
19
17
|
_koqName;
|
|
20
18
|
_persistenceUnit;
|
|
@@ -25,10 +23,6 @@ export class FormatSpecHandle {
|
|
|
25
23
|
this._koqName = args.name;
|
|
26
24
|
this._persistenceUnit = args.persistenceUnitName;
|
|
27
25
|
this._system = args.system;
|
|
28
|
-
this._removeListener = args.provider.onFormattingReady.addListener(() => {
|
|
29
|
-
this._refresh();
|
|
30
|
-
});
|
|
31
|
-
this._refresh();
|
|
32
26
|
}
|
|
33
27
|
/** The KoQ name this handle is keyed to. */
|
|
34
28
|
get koqName() { return this._koqName; }
|
|
@@ -37,47 +31,35 @@ export class FormatSpecHandle {
|
|
|
37
31
|
/** The unit system this handle is pinned to, or `undefined` for the active system. */
|
|
38
32
|
get system() { return this._system; }
|
|
39
33
|
/** The current FormatterSpec, or undefined if not yet loaded. */
|
|
40
|
-
get formatterSpec() { return this.
|
|
34
|
+
get formatterSpec() { return this._getEntry()?.formatterSpec; }
|
|
41
35
|
/** The current ParserSpec, or undefined if not yet loaded. */
|
|
42
|
-
get parserSpec() { return this.
|
|
36
|
+
get parserSpec() { return this._getEntry()?.parserSpec; }
|
|
43
37
|
/** Format a quantity value using the current spec.
|
|
44
38
|
* If the formatter is not yet ready, returns `value.toString()` as a fallback.
|
|
45
39
|
* @param value - The numeric value to format.
|
|
46
40
|
* @returns The formatted string.
|
|
47
41
|
*/
|
|
48
42
|
format(value) {
|
|
49
|
-
|
|
43
|
+
const formatterSpec = this.formatterSpec;
|
|
44
|
+
if (!formatterSpec)
|
|
50
45
|
return value.toString();
|
|
51
|
-
return this._provider.formatQuantity(value,
|
|
46
|
+
return this._provider.formatQuantity(value, formatterSpec);
|
|
52
47
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Idempotent and safe to call
|
|
48
|
+
/** Invalidate this handle.
|
|
49
|
+
* Idempotent and safe to call multiple times.
|
|
50
|
+
* No additional teardown is required because the handle owns no external resources.
|
|
55
51
|
*/
|
|
56
52
|
[Symbol.dispose]() {
|
|
57
|
-
|
|
58
|
-
this._removeListener();
|
|
59
|
-
this._removeListener = undefined;
|
|
60
|
-
}
|
|
61
|
-
this._formatterSpec = undefined;
|
|
62
|
-
this._parserSpec = undefined;
|
|
53
|
+
this._disposed = true;
|
|
63
54
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const entry = this._provider.getSpecsByNameAndUnit({
|
|
55
|
+
_getEntry() {
|
|
56
|
+
if (this._disposed)
|
|
57
|
+
return undefined;
|
|
58
|
+
return this._provider.getSpecsByNameAndUnit({
|
|
69
59
|
name: this._koqName,
|
|
70
60
|
persistenceUnitName: this._persistenceUnit,
|
|
71
61
|
system: this._system,
|
|
72
62
|
});
|
|
73
|
-
if (entry) {
|
|
74
|
-
this._formatterSpec = entry.formatterSpec;
|
|
75
|
-
this._parserSpec = entry.parserSpec;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
this._formatterSpec = undefined;
|
|
79
|
-
this._parserSpec = undefined;
|
|
80
|
-
}
|
|
81
63
|
}
|
|
82
64
|
}
|
|
83
65
|
//# sourceMappingURL=FormatSpecHandle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormatSpecHandle.js","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAmB/F;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAgB;IACnB,
|
|
1
|
+
{"version":3,"file":"FormatSpecHandle.js","sourceRoot":"","sources":["../../src/FormatSpecHandle.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAmB/F;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAgB;IACnB,SAAS,GAAG,KAAK,CAAC;IACT,SAAS,CAAyB;IAClC,QAAQ,CAAS;IACjB,gBAAgB,CAAS;IACzB,OAAO,CAA4B;IAEpD,gBAAgB;IAChB,YAAY,IAA0B;QACpC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,4CAA4C;IAC5C,IAAW,OAAO,KAAa,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtD,oDAAoD;IACpD,IAAW,eAAe,KAAa,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEtE,sFAAsF;IACtF,IAAW,MAAM,KAAgC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAEvE,iEAAiE;IACjE,IAAW,aAAa,KAAgC,OAAO,IAAI,CAAC,SAAS,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;IAEjG,8DAA8D;IAC9D,IAAW,UAAU,KAA6B,OAAO,IAAI,CAAC,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;IAExF;;;;OAIG;IACI,MAAM,CAAC,KAAa;QACzB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACzC,IAAI,CAAC,aAAa;YAChB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAC7D,CAAC;IAED;;;OAGG;IACI,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAEO,SAAS;QACf,IAAI,IAAI,CAAC,SAAS;YAChB,OAAO,SAAS,CAAC;QAEnB,OAAO,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC;YAC1C,IAAI,EAAE,IAAI,CAAC,QAAQ;YACnB,mBAAmB,EAAE,IAAI,CAAC,gBAAgB;YAC1C,MAAM,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport type { FormatterSpec } from \"./Formatter/FormatterSpec\";\nimport type { FormattingSpecArgs, FormattingSpecEntry, FormattingSpecProvider } from \"./Formatter/Interfaces\";\nimport type { ParserSpec } from \"./ParserSpec\";\nimport type { UnitSystemKey } from \"./Interfaces\";\n\n/** Arguments for constructing a [[FormatSpecHandle]].\n * @internal\n */\nexport interface FormatSpecHandleArgs extends FormattingSpecArgs {\n /** The provider that supplies current formatting spec lookups. */\n provider: FormattingSpecProvider;\n}\n\n/** A handle to formatting and parsing specs for a specific KoQ and persistence unit.\n * Reads the current specs from the provider on access. Use [[QuantityFormatter.getFormatSpecHandle]]\n * to create instances.\n *\n * When formatting is not yet ready, [[format]] returns a `value.toString()` fallback.\n * Dispose the handle when it is no longer needed to invalidate it.\n *\n * @beta\n */\nexport class FormatSpecHandle implements Disposable {\n private _disposed = false;\n private readonly _provider: FormattingSpecProvider;\n private readonly _koqName: string;\n private readonly _persistenceUnit: string;\n private readonly _system: UnitSystemKey | undefined;\n\n /** @internal */\n constructor(args: FormatSpecHandleArgs) {\n this._provider = args.provider;\n this._koqName = args.name;\n this._persistenceUnit = args.persistenceUnitName;\n this._system = args.system;\n }\n\n /** The KoQ name this handle is keyed to. */\n public get koqName(): string { return this._koqName; }\n\n /** The persistence unit this handle is keyed to. */\n public get persistenceUnit(): string { return this._persistenceUnit; }\n\n /** The unit system this handle is pinned to, or `undefined` for the active system. */\n public get system(): UnitSystemKey | undefined { return this._system; }\n\n /** The current FormatterSpec, or undefined if not yet loaded. */\n public get formatterSpec(): FormatterSpec | undefined { return this._getEntry()?.formatterSpec; }\n\n /** The current ParserSpec, or undefined if not yet loaded. */\n public get parserSpec(): ParserSpec | undefined { return this._getEntry()?.parserSpec; }\n\n /** Format a quantity value using the current spec.\n * If the formatter is not yet ready, returns `value.toString()` as a fallback.\n * @param value - The numeric value to format.\n * @returns The formatted string.\n */\n public format(value: number): string {\n const formatterSpec = this.formatterSpec;\n if (!formatterSpec)\n return value.toString();\n return this._provider.formatQuantity(value, formatterSpec);\n }\n\n /** Invalidate this handle.\n * Idempotent and safe to call multiple times.\n * No additional teardown is required because the handle owns no external resources.\n */\n public [Symbol.dispose](): void {\n this._disposed = true;\n }\n\n private _getEntry(): FormattingSpecEntry | undefined {\n if (this._disposed)\n return undefined;\n\n return this._provider.getSpecsByNameAndUnit({\n name: this._koqName,\n persistenceUnitName: this._persistenceUnit,\n system: this._system,\n });\n }\n}\n"]}
|
|
@@ -213,7 +213,7 @@ export interface AddFormattingSpecArgs extends FormattingSpecArgs {
|
|
|
213
213
|
/** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */
|
|
214
214
|
formatProps?: FormatProps;
|
|
215
215
|
}
|
|
216
|
-
/** Minimal contract required by [[FormatSpecHandle]] to look up specs and
|
|
216
|
+
/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.
|
|
217
217
|
* Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.
|
|
218
218
|
* @beta
|
|
219
219
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwHH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\nimport type { FormatterSpec } from \"./FormatterSpec\";\nimport type { ParserSpec } from \"../ParserSpec\";\n\n/** Defines a unit specification with a name and optional label override.\n * Used in composite formats and ratio unit specifications.\n * @beta\n */\nexport interface FormatUnitSpec {\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\n readonly name: string;\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\n readonly label?: string;\n}\n\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\n * @beta\n */\nexport interface ResolvedFormatUnitSpec {\n /** The resolved unit */\n readonly unit: UnitProps;\n /** Optional custom label that overrides the unit's default label */\n readonly label?: string;\n}\n\n/** Defines the units that make up a composite format and their display properties.\n * A composite format allows displaying a single quantity value across multiple units,\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\n * @beta\n */\nexport interface FormatCompositeProps {\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\n readonly spacer?: string;\n /** Whether to include unit segments with zero magnitude in the formatted output. */\n readonly includeZero?: boolean;\n /** Array of units this format is comprised of. Each unit specifies the unit name and\n * an optional custom label that will override the unit's default label when displaying values. */\n readonly units: FormatUnitSpec[];\n}\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n /** The format type. See [[FormatType]] */\n readonly type: string;\n\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\n readonly precision?: number;\n\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\n readonly roundFactor?: number;\n\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\n readonly minWidth?: number;\n\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\n readonly showSignOption?: string;\n\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\n readonly formatTraits?: string | string[];\n\n /** Character separating integer from fractional part. Must be empty or a single character. */\n readonly decimalSeparator?: string;\n\n /** Character separating thousands in the integer part. Must be empty or a single character. */\n readonly thousandSeparator?: string;\n\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\n readonly uomSeparator?: string;\n\n /** Required when type is Scientific. See [[ScientificType]] */\n readonly scientificType?: string;\n\n /** Required when type is Ratio. See [[RatioType]]*/\n readonly ratioType?: string;\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\n readonly ratioSeparator?: string;\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\n readonly ratioFormatType?: string;\n\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\n readonly stationOffsetSize?: number;\n\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\n readonly stationSeparator?: string;\n\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\n readonly allowMathematicOperations?: boolean;\n\n /** Composite format specification for multi-unit display. */\n readonly composite?: FormatCompositeProps;\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\n readonly units: ResolvedFormatUnitSpec[];\n};\n\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\n readonly azimuthBaseUnit?: UnitProps;\n readonly revolutionUnit?: UnitProps;\n readonly composite?: ResolvedFormatCompositeProps;\n readonly custom?: any;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n /** If set, indicates that the format set implies a particular unit system. The consumer\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\n * If `undefined`, the format change does not imply a unit system switch — the active\n * unit system remains unchanged.\n * @beta\n */\n impliedUnitSystem?: UnitSystemKey;\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;\n\n /**\n * Fired when formats are added, removed, or changed.\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\n */\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n /**\n * Adds a new format or updates an existing format associated with the specified name.\n */\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n /**\n * Removes the format associated with the specified name.\n * @param name The name of the format to remove.\n */\n removeFormat(name: string): Promise<void>;\n}\n\n/** Entries returned when looking up specs from the format registry.\n * @beta\n */\nexport interface FormattingSpecEntry {\n formatterSpec: FormatterSpec;\n parserSpec: ParserSpec;\n}\n\n/** Arguments for looking up a formatting spec entry.\n * @beta\n */\nexport interface FormattingSpecArgs {\n /** The KoQ name to look up. */\n name: string;\n /** The persistence unit name (e.g., `\"Units.M\"`). */\n persistenceUnitName: string;\n /** Optional unit system override. When omitted, the active system is used. */\n system?: UnitSystemKey;\n}\n\n/** Arguments for registering a formatting spec entry.\n * @beta\n */\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\n formatProps?: FormatProps;\n}\n\n/** Minimal contract required by [[FormatSpecHandle]] to look up specs and subscribe to reloads.\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\n * @beta\n */\nexport interface FormattingSpecProvider {\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\n /** Format a numeric value using the given formatter spec. */\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\n /** Event raised after the provider has finished reloading its caches.\n * Uses Set-backed event for safe concurrent add/remove during emit.\n */\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAwHH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { BeEvent, BeUnorderedUiEvent } from \"@itwin/core-bentley\";\nimport { UnitProps, UnitSystemKey } from \"../Interfaces\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\nimport type { FormatterSpec } from \"./FormatterSpec\";\nimport type { ParserSpec } from \"../ParserSpec\";\n\n/** Defines a unit specification with a name and optional label override.\n * Used in composite formats and ratio unit specifications.\n * @beta\n */\nexport interface FormatUnitSpec {\n /** The name of the unit (e.g., \"Units.FT\", \"Units.IN\") */\n readonly name: string;\n /** Optional custom label that overrides the unit's default label (e.g., '\"' for inches, \"'\" for feet) */\n readonly label?: string;\n}\n\n/** A resolved [[FormatUnitSpec]] with the unit name replaced with the resolved UnitProps.\n * @beta\n */\nexport interface ResolvedFormatUnitSpec {\n /** The resolved unit */\n readonly unit: UnitProps;\n /** Optional custom label that overrides the unit's default label */\n readonly label?: string;\n}\n\n/** Defines the units that make up a composite format and their display properties.\n * A composite format allows displaying a single quantity value across multiple units,\n * such as displaying length as \"5 feet 6 inches\" or angle as \"45° 30' 15\"\".\n * @beta\n */\nexport interface FormatCompositeProps {\n /** Separator character between unit values when formatting composite strings. Must be empty or a single character. */\n readonly spacer?: string;\n /** Whether to include unit segments with zero magnitude in the formatted output. */\n readonly includeZero?: boolean;\n /** Array of units this format is comprised of. Each unit specifies the unit name and\n * an optional custom label that will override the unit's default label when displaying values. */\n readonly units: FormatUnitSpec[];\n}\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n /** The format type. See [[FormatType]] */\n readonly type: string;\n\n /** The precision for the format. Must be an integer. See [[DecimalPrecision]] and [[FractionalPrecision]] */\n readonly precision?: number;\n\n /** Value is rounded to a multiple of this factor if nonzero and the `applyRounding` trait is set, defaults to 0 */\n readonly roundFactor?: number;\n\n /** Minimum width of the formatted output including digits and separators. Must be a positive integer (≥ 0). */\n readonly minWidth?: number;\n\n /** How and when positive and negative signs are displayed. See [[ShowSignOption]] */\n readonly showSignOption?: string;\n\n /** Array of format traits controlling display behavior. See [[FormatTraits]] */\n readonly formatTraits?: string | string[];\n\n /** Character separating integer from fractional part. Must be empty or a single character. */\n readonly decimalSeparator?: string;\n\n /** Character separating thousands in the integer part. Must be empty or a single character. */\n readonly thousandSeparator?: string;\n\n /** Character separating the magnitude from the unit label. Must be empty or a single character. */\n readonly uomSeparator?: string;\n\n /** Required when type is Scientific. See [[ScientificType]] */\n readonly scientificType?: string;\n\n /** Required when type is Ratio. See [[RatioType]]*/\n readonly ratioType?: string;\n /** The separator character for ratio formatting. Defaults to ':' if not specified. */\n readonly ratioSeparator?: string;\n /** The format type for the numbers within a ratio. Defaults to \"Decimal\". */\n readonly ratioFormatType?: string;\n\n /** Required when type is Station. Number of decimal places for calculating station offset magnitude. Must be a positive integer > 0. */\n readonly stationOffsetSize?: number;\n\n /** Character separating station and offset portions of a Station formatted value. Must be empty or a single character. */\n readonly stationSeparator?: string;\n\n /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. Required if azimuthBase is set. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n /** Enables calculating mathematic operations during parsing; only addition and subtraction are supported. */\n readonly allowMathematicOperations?: boolean;\n\n /** Composite format specification for multi-unit display. */\n readonly composite?: FormatCompositeProps;\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** A [[FormatCompositeProps]] with unit names replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatCompositeProps = Omit<FormatCompositeProps, \"units\"> & {\n readonly units: ResolvedFormatUnitSpec[];\n};\n\n/** A [[FormatProps]] with all the references to units replaced with JSON representations of those units.\n * @beta\n */\nexport type ResolvedFormatProps = Omit<FormatDefinition, \"azimuthBaseUnit\" | \"revolutionUnit\" | \"composite\"> & {\n readonly azimuthBaseUnit?: UnitProps;\n readonly revolutionUnit?: UnitProps;\n readonly composite?: ResolvedFormatCompositeProps;\n readonly custom?: any;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n /** If set, indicates that the format set implies a particular unit system. The consumer\n * (e.g., QuantityFormatter) will synchronize the active unit system to match.\n * If `undefined`, the format change does not imply a unit system switch — the active\n * unit system remains unchanged.\n * @beta\n */\n impliedUnitSystem?: UnitSystemKey;\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string, system?: UnitSystemKey): Promise<FormatDefinition | undefined>;\n\n /**\n * Fired when formats are added, removed, or changed.\n * If all formats are changed, a single string \"all\" is emitted. Else, an array of changed format names is emitted.\n */\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n /**\n * Adds a new format or updates an existing format associated with the specified name.\n */\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n /**\n * Removes the format associated with the specified name.\n * @param name The name of the format to remove.\n */\n removeFormat(name: string): Promise<void>;\n}\n\n/** Entries returned when looking up specs from the format registry.\n * @beta\n */\nexport interface FormattingSpecEntry {\n formatterSpec: FormatterSpec;\n parserSpec: ParserSpec;\n}\n\n/** Arguments for looking up a formatting spec entry.\n * @beta\n */\nexport interface FormattingSpecArgs {\n /** The KoQ name to look up. */\n name: string;\n /** The persistence unit name (e.g., `\"Units.M\"`). */\n persistenceUnitName: string;\n /** Optional unit system override. When omitted, the active system is used. */\n system?: UnitSystemKey;\n}\n\n/** Arguments for registering a formatting spec entry.\n * @beta\n */\nexport interface AddFormattingSpecArgs extends FormattingSpecArgs {\n /** Format properties to use. When omitted, the provider resolves them from the KoQ schema. */\n formatProps?: FormatProps;\n}\n\n/** Minimal contract required by [[FormatSpecHandle]] to look up current specs and expose formatting readiness.\n * Implemented by [[QuantityFormatter]] in `@itwin/core-frontend`.\n * @beta\n */\nexport interface FormattingSpecProvider {\n /** Look up a formatting spec entry by KoQ name and persistence unit. */\n getSpecsByNameAndUnit(args: FormattingSpecArgs): FormattingSpecEntry | undefined;\n /** Format a numeric value using the given formatter spec. */\n formatQuantity(magnitude: number, formatSpec: FormatterSpec): string;\n /** Event raised after the provider has finished reloading its caches.\n * Uses Set-backed event for safe concurrent add/remove during emit.\n */\n readonly onFormattingReady: BeUnorderedUiEvent<void>;\n}\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-quantity",
|
|
3
|
-
"version": "5.9.
|
|
3
|
+
"version": "5.9.2",
|
|
4
4
|
"description": "Quantity parsing, formatting and conversions for iModel.js",
|
|
5
5
|
"main": "lib/cjs/core-quantity.js",
|
|
6
6
|
"module": "lib/esm/core-quantity.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"rimraf": "^6.0.1",
|
|
29
29
|
"typescript": "~5.6.2",
|
|
30
30
|
"vitest": "^3.0.6",
|
|
31
|
-
"@itwin/
|
|
32
|
-
"@itwin/
|
|
31
|
+
"@itwin/core-bentley": "5.9.2",
|
|
32
|
+
"@itwin/build-tools": "5.9.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@itwin/core-bentley": "5.9.
|
|
35
|
+
"@itwin/core-bentley": "5.9.2"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "node scripts/generateUnitsJson.js && npm run -s build:cjs && npm run -s build:esm",
|