@itwin/core-frontend 5.1.0-dev.13 → 5.1.0-dev.15
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/lib/cjs/IModelApp.d.ts +15 -0
- package/lib/cjs/IModelApp.d.ts.map +1 -1
- package/lib/cjs/IModelApp.js +19 -1
- package/lib/cjs/IModelApp.js.map +1 -1
- package/lib/cjs/IpcApp.d.ts +1 -0
- package/lib/cjs/IpcApp.d.ts.map +1 -1
- package/lib/cjs/IpcApp.js +3 -1
- package/lib/cjs/IpcApp.js.map +1 -1
- package/lib/cjs/extension/providers/ExtensionLoadScript.js.map +1 -1
- package/lib/cjs/internal/tile/ClassifierTileTree.js +3 -1
- package/lib/cjs/internal/tile/ClassifierTileTree.js.map +1 -1
- package/lib/cjs/internal/tile/PrimaryTileTree.d.ts.map +1 -1
- package/lib/cjs/internal/tile/PrimaryTileTree.js +4 -3
- package/lib/cjs/internal/tile/PrimaryTileTree.js.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts +76 -7
- package/lib/cjs/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/cjs/quantity-formatting/QuantityFormatter.js +126 -23
- package/lib/cjs/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/cjs/tile/TileAdmin.d.ts +10 -0
- package/lib/cjs/tile/TileAdmin.d.ts.map +1 -1
- package/lib/cjs/tile/TileAdmin.js +3 -0
- package/lib/cjs/tile/TileAdmin.js.map +1 -1
- package/lib/cjs/tools/MeasureTool.d.ts +9 -0
- package/lib/cjs/tools/MeasureTool.d.ts.map +1 -1
- package/lib/cjs/tools/MeasureTool.js +53 -22
- package/lib/cjs/tools/MeasureTool.js.map +1 -1
- package/lib/esm/IModelApp.d.ts +15 -0
- package/lib/esm/IModelApp.d.ts.map +1 -1
- package/lib/esm/IModelApp.js +20 -2
- package/lib/esm/IModelApp.js.map +1 -1
- package/lib/esm/IpcApp.d.ts +1 -0
- package/lib/esm/IpcApp.d.ts.map +1 -1
- package/lib/esm/IpcApp.js +3 -1
- package/lib/esm/IpcApp.js.map +1 -1
- package/lib/esm/extension/providers/ExtensionLoadScript.js +1 -1
- package/lib/esm/extension/providers/ExtensionLoadScript.js.map +1 -1
- package/lib/esm/internal/tile/ClassifierTileTree.js +3 -1
- package/lib/esm/internal/tile/ClassifierTileTree.js.map +1 -1
- package/lib/esm/internal/tile/PrimaryTileTree.d.ts.map +1 -1
- package/lib/esm/internal/tile/PrimaryTileTree.js +4 -3
- package/lib/esm/internal/tile/PrimaryTileTree.js.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts +76 -7
- package/lib/esm/quantity-formatting/QuantityFormatter.d.ts.map +1 -1
- package/lib/esm/quantity-formatting/QuantityFormatter.js +124 -23
- package/lib/esm/quantity-formatting/QuantityFormatter.js.map +1 -1
- package/lib/esm/tile/TileAdmin.d.ts +10 -0
- package/lib/esm/tile/TileAdmin.d.ts.map +1 -1
- package/lib/esm/tile/TileAdmin.js +3 -0
- package/lib/esm/tile/TileAdmin.js.map +1 -1
- package/lib/esm/tools/MeasureTool.d.ts +9 -0
- package/lib/esm/tools/MeasureTool.d.ts.map +1 -1
- package/lib/esm/tools/MeasureTool.js +53 -22
- package/lib/esm/tools/MeasureTool.js.map +1 -1
- package/lib/public/scripts/parse-imdl-worker.js +1 -1
- package/lib/workers/webpack/parse-imdl-worker.js +1 -1
- package/package.json +20 -20
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module QuantityFormatting
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.QuantityFormatter = exports.AlternateUnitLabelsRegistry = exports.QuantityType = void 0;
|
|
10
|
+
exports.QuantityFormatter = exports.FormatsProviderManager = exports.QuantityTypeFormatsProvider = exports.AlternateUnitLabelsRegistry = exports.QuantityType = void 0;
|
|
11
11
|
exports.getQuantityTypeKey = getQuantityTypeKey;
|
|
12
12
|
exports.isCustomQuantityTypeDefinition = isCustomQuantityTypeDefinition;
|
|
13
13
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
@@ -141,12 +141,68 @@ class StandardQuantityTypeDefinition {
|
|
|
141
141
|
return core_quantity_1.ParserSpec.create(format, unitsProvider, this.persistenceUnit, alternateUnitLabelsProvider);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* A default formatsProvider, that provides a limited set of [[FormatDefinition]], associated to a few [[KindOfQuantity]].
|
|
146
|
+
* Maps each KindOfQuantity to a [[QuantityType]].
|
|
147
|
+
* When retrieving a valid [[KindOfQuantity]], returns the [[FormatProps]] for the associated [[QuantityType]].
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
class QuantityTypeFormatsProvider {
|
|
151
|
+
onFormatsChanged = new core_bentley_1.BeEvent();
|
|
152
|
+
constructor() {
|
|
153
|
+
IModelApp_1.IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(() => {
|
|
154
|
+
this.onFormatsChanged.raiseEvent({ formatsChanged: "all" });
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
_kindOfQuantityMap = new Map([
|
|
158
|
+
["AecUnits.LENGTH", QuantityType.Length],
|
|
159
|
+
["AecUnits.ANGLE", QuantityType.Angle],
|
|
160
|
+
["AecUnits.AREA", QuantityType.Area],
|
|
161
|
+
["AecUnits.VOLUME", QuantityType.Volume],
|
|
162
|
+
["RoadRailUnits.STATION", QuantityType.Stationing],
|
|
163
|
+
["RoadRailUnits.LENGTH", QuantityType.LengthSurvey],
|
|
164
|
+
]);
|
|
165
|
+
async getFormat(name) {
|
|
166
|
+
const quantityType = this._kindOfQuantityMap.get(name);
|
|
167
|
+
if (!quantityType)
|
|
168
|
+
return undefined;
|
|
169
|
+
return IModelApp_1.IModelApp.quantityFormatter.getFormatPropsByQuantityType(quantityType);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.QuantityTypeFormatsProvider = QuantityTypeFormatsProvider;
|
|
173
|
+
/**
|
|
174
|
+
* An implementation of the [[FormatsProvider]] interface that forwards calls to getFormats to the underlying FormatsProvider.
|
|
175
|
+
* Also fires the onFormatsChanged event when the underlying FormatsProvider fires its own onFormatsChanged event.
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
class FormatsProviderManager {
|
|
179
|
+
_formatsProvider;
|
|
180
|
+
onFormatsChanged = new core_bentley_1.BeEvent();
|
|
181
|
+
constructor(_formatsProvider) {
|
|
182
|
+
this._formatsProvider = _formatsProvider;
|
|
183
|
+
this._formatsProvider.onFormatsChanged.addListener((args) => {
|
|
184
|
+
this.onFormatsChanged.raiseEvent(args);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async getFormat(name) {
|
|
188
|
+
return this._formatsProvider.getFormat(name);
|
|
189
|
+
}
|
|
190
|
+
get formatsProvider() { return this; }
|
|
191
|
+
set formatsProvider(formatsProvider) {
|
|
192
|
+
this._formatsProvider = formatsProvider;
|
|
193
|
+
this._formatsProvider.onFormatsChanged.addListener((args) => {
|
|
194
|
+
this.onFormatsChanged.raiseEvent(args);
|
|
195
|
+
});
|
|
196
|
+
this.onFormatsChanged.raiseEvent({ formatsChanged: "all" });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.FormatsProviderManager = FormatsProviderManager;
|
|
144
200
|
/** Class that supports formatting quantity values into strings and parsing strings into quantity values. This class also maintains
|
|
145
201
|
* the "active" unit system and caches FormatterSpecs and ParserSpecs for the "active" unit system to allow synchronous access to
|
|
146
202
|
* parsing and formatting values. The support unit systems are defined by [[UnitSystemKey]] and is kept in synch with the unit systems
|
|
147
203
|
* provided by the Presentation Manager on the backend. The QuantityFormatter contains a registry of quantity type definitions. These definitions implement
|
|
148
|
-
* the [[QuantityTypeDefinition]] interface, which among other things, provide default [FormatProps]
|
|
149
|
-
* to generate both a [FormatterSpec]
|
|
204
|
+
* the [[QuantityTypeDefinition]] interface, which among other things, provide default [[FormatProps]], and provide methods
|
|
205
|
+
* to generate both a [[FormatterSpec]] and a [[ParserSpec]]. There are built-in quantity types that are
|
|
150
206
|
* identified by the [[QuantityType]] enum. [[CustomQuantityTypeDefinition]] can be registered to extend the available quantity types available
|
|
151
207
|
* by frontend tools. The QuantityFormatter also allows the default formats to be overriden.
|
|
152
208
|
*
|
|
@@ -550,26 +606,51 @@ class QuantityFormatter {
|
|
|
550
606
|
requestedSystem = isImperial ? "imperial" : "metric";
|
|
551
607
|
return this.getParserSpecByQuantityTypeAndSystem(type, requestedSystem);
|
|
552
608
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
return
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
609
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
610
|
+
formatQuantity(args, spec) {
|
|
611
|
+
if (typeof args === "number") {
|
|
612
|
+
/** Format a quantity value. Default FormatterSpec implementation uses Formatter.formatQuantity. */
|
|
613
|
+
const magnitude = args;
|
|
614
|
+
if (spec)
|
|
615
|
+
return spec.applyFormatting(magnitude);
|
|
616
|
+
return magnitude.toString();
|
|
617
|
+
}
|
|
618
|
+
return this.formatQuantityAsync(args);
|
|
619
|
+
}
|
|
620
|
+
async formatQuantityAsync(args) {
|
|
621
|
+
const { value, valueUnitName, kindOfQuantityName } = args;
|
|
622
|
+
const formatProps = await IModelApp_1.IModelApp.formatsProvider.getFormat(kindOfQuantityName);
|
|
623
|
+
if (!formatProps)
|
|
624
|
+
return value.toString();
|
|
625
|
+
const formatSpec = await this.createFormatterSpec({
|
|
626
|
+
persistenceUnitName: valueUnitName,
|
|
627
|
+
formatProps,
|
|
628
|
+
formatName: kindOfQuantityName,
|
|
629
|
+
});
|
|
630
|
+
return formatSpec.applyFormatting(value);
|
|
631
|
+
}
|
|
632
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
633
|
+
parseToQuantityValue(args, parserSpec) {
|
|
634
|
+
if (typeof args === "string") {
|
|
635
|
+
/** Parse a quantity value. Default ParserSpec implementation uses ParserSpec.parseToQuantityValue. */
|
|
636
|
+
const inString = args;
|
|
637
|
+
if (parserSpec)
|
|
638
|
+
return parserSpec.parseToQuantityValue(inString);
|
|
639
|
+
return { ok: false, error: core_quantity_1.ParseError.InvalidParserSpec };
|
|
640
|
+
}
|
|
641
|
+
return this.parseToQuantityValueAsync(args);
|
|
642
|
+
}
|
|
643
|
+
async parseToQuantityValueAsync(args) {
|
|
644
|
+
const { value, valueUnitName, kindOfQuantityName } = args;
|
|
645
|
+
const formatProps = await IModelApp_1.IModelApp.formatsProvider.getFormat(kindOfQuantityName);
|
|
646
|
+
if (!formatProps)
|
|
647
|
+
return { ok: false, error: core_quantity_1.ParseError.InvalidParserSpec };
|
|
648
|
+
const parserSpec = await this.createParserSpec({
|
|
649
|
+
persistenceUnitName: valueUnitName,
|
|
650
|
+
formatProps,
|
|
651
|
+
formatName: kindOfQuantityName,
|
|
652
|
+
});
|
|
653
|
+
return parserSpec.parseToQuantityValue(value);
|
|
573
654
|
}
|
|
574
655
|
/**
|
|
575
656
|
* Get a UnitSystemKey from a string that may have been entered via a key-in. Supports different variation of
|
|
@@ -639,6 +720,28 @@ class QuantityFormatter {
|
|
|
639
720
|
async getConversion(fromUnit, toUnit) {
|
|
640
721
|
return this._unitsProvider.getConversion(fromUnit, toUnit);
|
|
641
722
|
}
|
|
723
|
+
/**
|
|
724
|
+
* Creates a [[FormatterSpec]] for a given persistence unit name and format properties, using the [[UnitsProvider]] to resolve the persistence unit.
|
|
725
|
+
* @beta
|
|
726
|
+
* @param props - A [[CreateFormattingSpecProps]] interface.
|
|
727
|
+
*/
|
|
728
|
+
async createFormatterSpec(props) {
|
|
729
|
+
const { persistenceUnitName, formatProps, formatName } = props;
|
|
730
|
+
const persistenceUnitProps = await this._unitsProvider.findUnitByName(persistenceUnitName);
|
|
731
|
+
const format = await core_quantity_1.Format.createFromJSON(formatName ?? "temp", this._unitsProvider, formatProps);
|
|
732
|
+
return core_quantity_1.FormatterSpec.create(`${format.name}_format_spec`, format, this._unitsProvider, persistenceUnitProps);
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Creates a [[ParserSpec]] for a given persistence unit name and format properties, using the [[UnitsProvider]] to resolve the persistence unit.
|
|
736
|
+
* @beta
|
|
737
|
+
* @param props - A [[CreateFormattingSpecProps]] object.
|
|
738
|
+
*/
|
|
739
|
+
async createParserSpec(props) {
|
|
740
|
+
const { persistenceUnitName, formatProps, formatName } = props;
|
|
741
|
+
const persistenceUnitProps = await this._unitsProvider.findUnitByName(persistenceUnitName);
|
|
742
|
+
const format = await core_quantity_1.Format.createFromJSON(formatName ?? "temp", this._unitsProvider, formatProps);
|
|
743
|
+
return core_quantity_1.ParserSpec.create(format, this._unitsProvider, persistenceUnitProps);
|
|
744
|
+
}
|
|
642
745
|
}
|
|
643
746
|
exports.QuantityFormatter = QuantityFormatter;
|
|
644
747
|
// ========================================================================================================================================
|