@itwin/presentation-common 5.1.0-dev.9 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/CHANGELOG.md +91 -1
  2. package/Ruleset.schema.json +3 -3
  3. package/lib/assets/locales/en/Presentation.json +19 -19
  4. package/lib/cjs/presentation-common/AsyncTasks.js.map +1 -1
  5. package/lib/cjs/presentation-common/CommonLoggerCategory.js.map +1 -1
  6. package/lib/cjs/presentation-common/Diagnostics.js.map +1 -1
  7. package/lib/cjs/presentation-common/EC.d.ts.map +1 -1
  8. package/lib/cjs/presentation-common/EC.js +9 -2
  9. package/lib/cjs/presentation-common/EC.js.map +1 -1
  10. package/lib/cjs/presentation-common/ElementProperties.js +1 -0
  11. package/lib/cjs/presentation-common/ElementProperties.js.map +1 -1
  12. package/lib/cjs/presentation-common/Error.d.ts +1 -1
  13. package/lib/cjs/presentation-common/Error.js +1 -1
  14. package/lib/cjs/presentation-common/Error.js.map +1 -1
  15. package/lib/cjs/presentation-common/InstanceFilterDefinition.js.map +1 -1
  16. package/lib/cjs/presentation-common/KeySet.js.map +1 -1
  17. package/lib/cjs/presentation-common/KoqPropertyValueFormatter.d.ts +24 -2
  18. package/lib/cjs/presentation-common/KoqPropertyValueFormatter.d.ts.map +1 -1
  19. package/lib/cjs/presentation-common/KoqPropertyValueFormatter.js +97 -104
  20. package/lib/cjs/presentation-common/KoqPropertyValueFormatter.js.map +1 -1
  21. package/lib/cjs/presentation-common/LabelDefinition.js.map +1 -1
  22. package/lib/cjs/presentation-common/LocalizationHelper.js.map +1 -1
  23. package/lib/cjs/presentation-common/PresentationIpcInterface.js.map +1 -1
  24. package/lib/cjs/presentation-common/PresentationManagerOptions.d.ts +3 -3
  25. package/lib/cjs/presentation-common/PresentationManagerOptions.js.map +1 -1
  26. package/lib/cjs/presentation-common/PresentationRpcInterface.d.ts +19 -19
  27. package/lib/cjs/presentation-common/PresentationRpcInterface.d.ts.map +1 -1
  28. package/lib/cjs/presentation-common/PresentationRpcInterface.js +17 -17
  29. package/lib/cjs/presentation-common/PresentationRpcInterface.js.map +1 -1
  30. package/lib/cjs/presentation-common/RegisteredRuleset.d.ts +1 -1
  31. package/lib/cjs/presentation-common/RegisteredRuleset.d.ts.map +1 -1
  32. package/lib/cjs/presentation-common/RegisteredRuleset.js +1 -1
  33. package/lib/cjs/presentation-common/RegisteredRuleset.js.map +1 -1
  34. package/lib/cjs/presentation-common/RpcRequestsHandler.js.map +1 -1
  35. package/lib/cjs/presentation-common/RulesetVariables.js.map +1 -1
  36. package/lib/cjs/presentation-common/RulesetsFactory.js.map +1 -1
  37. package/lib/cjs/presentation-common/Update.js.map +1 -1
  38. package/lib/cjs/presentation-common/Utils.js.map +1 -1
  39. package/lib/cjs/presentation-common/content/Category.js.map +1 -1
  40. package/lib/cjs/presentation-common/content/Content.js.map +1 -1
  41. package/lib/cjs/presentation-common/content/ContentTraverser.js.map +1 -1
  42. package/lib/cjs/presentation-common/content/Descriptor.js.map +1 -1
  43. package/lib/cjs/presentation-common/content/DisplayTypes.js.map +1 -1
  44. package/lib/cjs/presentation-common/content/Editor.js.map +1 -1
  45. package/lib/cjs/presentation-common/content/Fields.d.ts +14 -14
  46. package/lib/cjs/presentation-common/content/Fields.js +9 -9
  47. package/lib/cjs/presentation-common/content/Fields.js.map +1 -1
  48. package/lib/cjs/presentation-common/content/Item.d.ts +2 -2
  49. package/lib/cjs/presentation-common/content/Item.d.ts.map +1 -1
  50. package/lib/cjs/presentation-common/content/Item.js.map +1 -1
  51. package/lib/cjs/presentation-common/content/Property.js.map +1 -1
  52. package/lib/cjs/presentation-common/content/PropertyValueFormatter.js.map +1 -1
  53. package/lib/cjs/presentation-common/content/Renderer.js.map +1 -1
  54. package/lib/cjs/presentation-common/content/TypeDescription.js.map +1 -1
  55. package/lib/cjs/presentation-common/content/Value.d.ts +1 -1
  56. package/lib/cjs/presentation-common/content/Value.js.map +1 -1
  57. package/lib/cjs/presentation-common/hierarchy/HierarchyLevel.js.map +1 -1
  58. package/lib/cjs/presentation-common/hierarchy/Key.js.map +1 -1
  59. package/lib/cjs/presentation-common/hierarchy/Node.d.ts +1 -1
  60. package/lib/cjs/presentation-common/hierarchy/Node.js.map +1 -1
  61. package/lib/cjs/presentation-common/hierarchy/NodePathElement.js.map +1 -1
  62. package/lib/cjs/presentation-common/rules/ClassSpecifications.js.map +1 -1
  63. package/lib/cjs/presentation-common/rules/RelatedInstanceSpecification.js.map +1 -1
  64. package/lib/cjs/presentation-common/rules/RelationshipDirection.js.map +1 -1
  65. package/lib/cjs/presentation-common/rules/RelationshipPathSpecification.js.map +1 -1
  66. package/lib/cjs/presentation-common/rules/Rule.js.map +1 -1
  67. package/lib/cjs/presentation-common/rules/Ruleset.js.map +1 -1
  68. package/lib/cjs/presentation-common/rules/SchemasSpecification.js.map +1 -1
  69. package/lib/cjs/presentation-common/rules/Variables.js.map +1 -1
  70. package/lib/cjs/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js.map +1 -1
  71. package/lib/cjs/presentation-common/rules/content/ContentRelatedInstancesSpecification.js.map +1 -1
  72. package/lib/cjs/presentation-common/rules/content/ContentRule.js.map +1 -1
  73. package/lib/cjs/presentation-common/rules/content/ContentSpecification.js.map +1 -1
  74. package/lib/cjs/presentation-common/rules/content/DefaultPropertyCategoryOverride.js.map +1 -1
  75. package/lib/cjs/presentation-common/rules/content/PropertySpecification.js.map +1 -1
  76. package/lib/cjs/presentation-common/rules/content/SelectedNodeInstancesSpecification.js.map +1 -1
  77. package/lib/cjs/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js.map +1 -1
  78. package/lib/cjs/presentation-common/rules/content/modifiers/ContentModifier.js.map +1 -1
  79. package/lib/cjs/presentation-common/rules/content/modifiers/CustomRendererSpecification.js.map +1 -1
  80. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js.map +1 -1
  81. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js.map +1 -1
  82. package/lib/cjs/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js.map +1 -1
  83. package/lib/cjs/presentation-common/rules/customization/CustomizationRule.js.map +1 -1
  84. package/lib/cjs/presentation-common/rules/customization/ExtendedDataRule.js.map +1 -1
  85. package/lib/cjs/presentation-common/rules/customization/GroupingRule.d.ts +2 -2
  86. package/lib/cjs/presentation-common/rules/customization/GroupingRule.js.map +1 -1
  87. package/lib/cjs/presentation-common/rules/customization/InstanceLabelOverride.js.map +1 -1
  88. package/lib/cjs/presentation-common/rules/customization/SortingRule.js.map +1 -1
  89. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeRule.js.map +1 -1
  90. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeSpecification.js.map +1 -1
  91. package/lib/cjs/presentation-common/rules/hierarchy/CustomNodeSpecification.d.ts +1 -1
  92. package/lib/cjs/presentation-common/rules/hierarchy/CustomNodeSpecification.js.map +1 -1
  93. package/lib/cjs/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js.map +1 -1
  94. package/lib/cjs/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js.map +1 -1
  95. package/lib/cjs/presentation-common/rules/hierarchy/NavigationRule.js.map +1 -1
  96. package/lib/cjs/presentation-common/rules/hierarchy/NodeArtifactsRule.js.map +1 -1
  97. package/lib/cjs/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js.map +1 -1
  98. package/lib/cjs/presentation-common/rules/hierarchy/RootNodeRule.js.map +1 -1
  99. package/lib/cjs/presentation-common/rules/hierarchy/SubCondition.js.map +1 -1
  100. package/lib/cjs/presentation-common/selection/SelectionScope.d.ts +3 -3
  101. package/lib/cjs/presentation-common/selection/SelectionScope.js.map +1 -1
  102. package/lib/cjs/presentation-common-internal.js.map +1 -1
  103. package/lib/cjs/presentation-common.js.map +1 -1
  104. package/lib/esm/presentation-common/AsyncTasks.js.map +1 -1
  105. package/lib/esm/presentation-common/CommonLoggerCategory.js.map +1 -1
  106. package/lib/esm/presentation-common/Diagnostics.js.map +1 -1
  107. package/lib/esm/presentation-common/EC.d.ts.map +1 -1
  108. package/lib/esm/presentation-common/EC.js +9 -2
  109. package/lib/esm/presentation-common/EC.js.map +1 -1
  110. package/lib/esm/presentation-common/ElementProperties.js +1 -0
  111. package/lib/esm/presentation-common/ElementProperties.js.map +1 -1
  112. package/lib/esm/presentation-common/Error.d.ts +1 -1
  113. package/lib/esm/presentation-common/Error.js +1 -1
  114. package/lib/esm/presentation-common/Error.js.map +1 -1
  115. package/lib/esm/presentation-common/InstanceFilterDefinition.js.map +1 -1
  116. package/lib/esm/presentation-common/KeySet.js.map +1 -1
  117. package/lib/esm/presentation-common/KoqPropertyValueFormatter.d.ts +24 -2
  118. package/lib/esm/presentation-common/KoqPropertyValueFormatter.d.ts.map +1 -1
  119. package/lib/esm/presentation-common/KoqPropertyValueFormatter.js +97 -104
  120. package/lib/esm/presentation-common/KoqPropertyValueFormatter.js.map +1 -1
  121. package/lib/esm/presentation-common/LabelDefinition.js.map +1 -1
  122. package/lib/esm/presentation-common/LocalizationHelper.js.map +1 -1
  123. package/lib/esm/presentation-common/PresentationIpcInterface.js.map +1 -1
  124. package/lib/esm/presentation-common/PresentationManagerOptions.d.ts +3 -3
  125. package/lib/esm/presentation-common/PresentationManagerOptions.js.map +1 -1
  126. package/lib/esm/presentation-common/PresentationRpcInterface.d.ts +19 -19
  127. package/lib/esm/presentation-common/PresentationRpcInterface.d.ts.map +1 -1
  128. package/lib/esm/presentation-common/PresentationRpcInterface.js +17 -17
  129. package/lib/esm/presentation-common/PresentationRpcInterface.js.map +1 -1
  130. package/lib/esm/presentation-common/RegisteredRuleset.d.ts +1 -1
  131. package/lib/esm/presentation-common/RegisteredRuleset.d.ts.map +1 -1
  132. package/lib/esm/presentation-common/RegisteredRuleset.js +1 -1
  133. package/lib/esm/presentation-common/RegisteredRuleset.js.map +1 -1
  134. package/lib/esm/presentation-common/RpcRequestsHandler.js.map +1 -1
  135. package/lib/esm/presentation-common/RulesetVariables.js.map +1 -1
  136. package/lib/esm/presentation-common/RulesetsFactory.js.map +1 -1
  137. package/lib/esm/presentation-common/Update.js.map +1 -1
  138. package/lib/esm/presentation-common/Utils.js.map +1 -1
  139. package/lib/esm/presentation-common/content/Category.js.map +1 -1
  140. package/lib/esm/presentation-common/content/Content.js.map +1 -1
  141. package/lib/esm/presentation-common/content/ContentTraverser.js.map +1 -1
  142. package/lib/esm/presentation-common/content/Descriptor.js.map +1 -1
  143. package/lib/esm/presentation-common/content/DisplayTypes.js.map +1 -1
  144. package/lib/esm/presentation-common/content/Editor.js.map +1 -1
  145. package/lib/esm/presentation-common/content/Fields.d.ts +14 -14
  146. package/lib/esm/presentation-common/content/Fields.js +9 -9
  147. package/lib/esm/presentation-common/content/Fields.js.map +1 -1
  148. package/lib/esm/presentation-common/content/Item.d.ts +2 -2
  149. package/lib/esm/presentation-common/content/Item.d.ts.map +1 -1
  150. package/lib/esm/presentation-common/content/Item.js.map +1 -1
  151. package/lib/esm/presentation-common/content/Property.js.map +1 -1
  152. package/lib/esm/presentation-common/content/PropertyValueFormatter.js.map +1 -1
  153. package/lib/esm/presentation-common/content/Renderer.js.map +1 -1
  154. package/lib/esm/presentation-common/content/TypeDescription.js.map +1 -1
  155. package/lib/esm/presentation-common/content/Value.d.ts +1 -1
  156. package/lib/esm/presentation-common/content/Value.js.map +1 -1
  157. package/lib/esm/presentation-common/hierarchy/HierarchyLevel.js.map +1 -1
  158. package/lib/esm/presentation-common/hierarchy/Key.js.map +1 -1
  159. package/lib/esm/presentation-common/hierarchy/Node.d.ts +1 -1
  160. package/lib/esm/presentation-common/hierarchy/Node.js.map +1 -1
  161. package/lib/esm/presentation-common/hierarchy/NodePathElement.js.map +1 -1
  162. package/lib/esm/presentation-common/rules/ClassSpecifications.js.map +1 -1
  163. package/lib/esm/presentation-common/rules/RelatedInstanceSpecification.js.map +1 -1
  164. package/lib/esm/presentation-common/rules/RelationshipDirection.js.map +1 -1
  165. package/lib/esm/presentation-common/rules/RelationshipPathSpecification.js.map +1 -1
  166. package/lib/esm/presentation-common/rules/Rule.js.map +1 -1
  167. package/lib/esm/presentation-common/rules/Ruleset.js.map +1 -1
  168. package/lib/esm/presentation-common/rules/SchemasSpecification.js.map +1 -1
  169. package/lib/esm/presentation-common/rules/Variables.js.map +1 -1
  170. package/lib/esm/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js.map +1 -1
  171. package/lib/esm/presentation-common/rules/content/ContentRelatedInstancesSpecification.js.map +1 -1
  172. package/lib/esm/presentation-common/rules/content/ContentRule.js.map +1 -1
  173. package/lib/esm/presentation-common/rules/content/ContentSpecification.js.map +1 -1
  174. package/lib/esm/presentation-common/rules/content/DefaultPropertyCategoryOverride.js.map +1 -1
  175. package/lib/esm/presentation-common/rules/content/PropertySpecification.js.map +1 -1
  176. package/lib/esm/presentation-common/rules/content/SelectedNodeInstancesSpecification.js.map +1 -1
  177. package/lib/esm/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js.map +1 -1
  178. package/lib/esm/presentation-common/rules/content/modifiers/ContentModifier.js.map +1 -1
  179. package/lib/esm/presentation-common/rules/content/modifiers/CustomRendererSpecification.js.map +1 -1
  180. package/lib/esm/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js.map +1 -1
  181. package/lib/esm/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js.map +1 -1
  182. package/lib/esm/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js.map +1 -1
  183. package/lib/esm/presentation-common/rules/customization/CustomizationRule.js.map +1 -1
  184. package/lib/esm/presentation-common/rules/customization/ExtendedDataRule.js.map +1 -1
  185. package/lib/esm/presentation-common/rules/customization/GroupingRule.d.ts +2 -2
  186. package/lib/esm/presentation-common/rules/customization/GroupingRule.js.map +1 -1
  187. package/lib/esm/presentation-common/rules/customization/InstanceLabelOverride.js.map +1 -1
  188. package/lib/esm/presentation-common/rules/customization/SortingRule.js.map +1 -1
  189. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeRule.js.map +1 -1
  190. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeSpecification.js.map +1 -1
  191. package/lib/esm/presentation-common/rules/hierarchy/CustomNodeSpecification.d.ts +1 -1
  192. package/lib/esm/presentation-common/rules/hierarchy/CustomNodeSpecification.js.map +1 -1
  193. package/lib/esm/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js.map +1 -1
  194. package/lib/esm/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js.map +1 -1
  195. package/lib/esm/presentation-common/rules/hierarchy/NavigationRule.js.map +1 -1
  196. package/lib/esm/presentation-common/rules/hierarchy/NodeArtifactsRule.js.map +1 -1
  197. package/lib/esm/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js.map +1 -1
  198. package/lib/esm/presentation-common/rules/hierarchy/RootNodeRule.js.map +1 -1
  199. package/lib/esm/presentation-common/rules/hierarchy/SubCondition.js.map +1 -1
  200. package/lib/esm/presentation-common/selection/SelectionScope.d.ts +3 -3
  201. package/lib/esm/presentation-common/selection/SelectionScope.js.map +1 -1
  202. package/lib/esm/presentation-common-internal.js.map +1 -1
  203. package/lib/esm/presentation-common.js.map +1 -1
  204. package/lib/public/locales/en/Presentation.json +19 -19
  205. package/package.json +19 -14
@@ -5,8 +5,9 @@
5
5
  /** @packageDocumentation
6
6
  * @module Core
7
7
  */
8
+ import { assert } from "@itwin/core-bentley";
8
9
  import { Format, FormatterSpec, ParserSpec } from "@itwin/core-quantity";
9
- import { getFormatProps, InvertedUnit, KindOfQuantity, SchemaKey, SchemaMatchType, SchemaUnitProvider, } from "@itwin/ecschema-metadata";
10
+ import { InvertedUnit, KindOfQuantity, SchemaContext, SchemaFormatsProvider, SchemaKey, SchemaMatchType, SchemaUnitProvider } from "@itwin/ecschema-metadata";
10
11
  /**
11
12
  * An utility for formatting property values based on `KindOfQuantity` and unit system.
12
13
  * @public
@@ -14,14 +15,35 @@ import { getFormatProps, InvertedUnit, KindOfQuantity, SchemaKey, SchemaMatchTyp
14
15
  export class KoqPropertyValueFormatter {
15
16
  _schemaContext;
16
17
  _unitsProvider;
18
+ _formatsProvider;
19
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
17
20
  _defaultFormats;
18
- constructor(_schemaContext, defaultFormats) {
19
- this._schemaContext = _schemaContext;
20
- this._unitsProvider = new SchemaUnitProvider(_schemaContext);
21
- this._defaultFormats = defaultFormats
22
- ? Object.entries(defaultFormats).reduce((acc, [phenomenon, unitSystemFormats]) => ({ ...acc, [phenomenon.toUpperCase()]: unitSystemFormats }), {})
23
- : /* c8 ignore next */ undefined;
21
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
22
+ constructor(schemaContextOrProps, defaultFormats, formatsProvider) {
23
+ if (schemaContextOrProps instanceof SchemaContext) {
24
+ this._schemaContext = schemaContextOrProps;
25
+ this._formatsProvider = formatsProvider;
26
+ this.defaultFormats = defaultFormats;
27
+ }
28
+ else {
29
+ this._schemaContext = schemaContextOrProps.schemaContext;
30
+ this._formatsProvider = schemaContextOrProps.formatsProvider;
31
+ }
32
+ this._unitsProvider = new SchemaUnitProvider(this._schemaContext);
33
+ }
34
+ /* c8 ignore start */
35
+ /** @internal */
36
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
37
+ get defaultFormats() {
38
+ return this._defaultFormats;
24
39
  }
40
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
41
+ set defaultFormats(value) {
42
+ this._defaultFormats = value
43
+ ? Object.entries(value).reduce((acc, [phenomenon, unitSystemFormats]) => ({ ...acc, [phenomenon.toUpperCase()]: unitSystemFormats }), {})
44
+ : undefined;
45
+ }
46
+ /* c8 ignore end */
25
47
  async format(value, options) {
26
48
  const formatterSpec = await this.getFormatterSpec(options);
27
49
  if (!formatterSpec) {
@@ -30,7 +52,7 @@ export class KoqPropertyValueFormatter {
30
52
  return formatterSpec.applyFormatting(value);
31
53
  }
32
54
  async getFormatterSpec(options) {
33
- const formattingProps = await getFormattingProps(this._schemaContext, this._defaultFormats, options);
55
+ const formattingProps = await this.#getFormattingProps(options);
34
56
  if (!formattingProps) {
35
57
  return undefined;
36
58
  }
@@ -40,7 +62,7 @@ export class KoqPropertyValueFormatter {
40
62
  return FormatterSpec.create("", format, this._unitsProvider, persistenceUnit);
41
63
  }
42
64
  async getParserSpec(options) {
43
- const formattingProps = await getFormattingProps(this._schemaContext, this._defaultFormats, options);
65
+ const formattingProps = await this.#getFormattingProps(options);
44
66
  if (!formattingProps) {
45
67
  return undefined;
46
68
  }
@@ -49,23 +71,37 @@ export class KoqPropertyValueFormatter {
49
71
  const format = await Format.createFromJSON("", this._unitsProvider, formatProps);
50
72
  return ParserSpec.create(format, this._unitsProvider, persistenceUnit);
51
73
  }
52
- }
53
- async function getFormattingProps(schemaLocater, defaultFormats, options) {
54
- const { koqName, unitSystem } = options;
55
- const koq = await getKoq(schemaLocater, koqName);
56
- if (!koq) {
57
- return undefined;
58
- }
59
- const persistenceUnit = await koq.persistenceUnit;
60
- /* c8 ignore next 3 */
61
- if (!persistenceUnit) {
62
- return undefined;
63
- }
64
- const formatProps = await getKoqFormatProps(koq, persistenceUnit, defaultFormats, unitSystem);
65
- if (!formatProps) {
74
+ async #getFormattingProps(options) {
75
+ const { koqName } = options;
76
+ const koq = await getKoq(this._schemaContext, koqName);
77
+ if (!koq) {
78
+ return undefined;
79
+ }
80
+ const persistenceUnit = await koq.persistenceUnit;
81
+ assert(!!persistenceUnit);
82
+ // default to metric as it's the persistence unit system
83
+ const unitSystem = options.unitSystem ?? "metric";
84
+ const formatsProvider = this._formatsProvider ?? new SchemaFormatsProvider(this._schemaContext, unitSystem);
85
+ const formatProps = await formatsProvider.getFormat(koqName);
86
+ // `SchemaFormatsProvider` will fall back to default presentation format, but we want to fall back
87
+ // to default formats' map first, and only then to the default presentation format. All of this can
88
+ // be removed with the removal of default formats map.
89
+ if (this._defaultFormats && (!formatProps || (await getUnitSystemKey(this._unitsProvider, formatProps)) !== unitSystem)) {
90
+ const defaultFormatProps = await getFormatPropsFromDefaultFormats({
91
+ schemaContext: this._schemaContext,
92
+ formatsMap: this._defaultFormats,
93
+ unitSystem,
94
+ koqName,
95
+ });
96
+ if (defaultFormatProps) {
97
+ return { formatProps: defaultFormatProps, persistenceUnitName: persistenceUnit.fullName };
98
+ }
99
+ }
100
+ if (formatProps) {
101
+ return { formatProps, persistenceUnitName: persistenceUnit.fullName };
102
+ }
66
103
  return undefined;
67
104
  }
68
- return { formatProps, persistenceUnitName: persistenceUnit.fullName };
69
105
  }
70
106
  async function getKoq(schemaLocater, fullName) {
71
107
  const [schemaName, propKoqName] = fullName.split(":");
@@ -75,92 +111,49 @@ async function getKoq(schemaLocater, fullName) {
75
111
  }
76
112
  return schema.getItem(propKoqName, KindOfQuantity);
77
113
  }
78
- async function getKoqFormatProps(koq, persistenceUnit, defaultFormats, unitSystem) {
79
- const unitSystemMatchers = getUnitSystemGroupMatchers(unitSystem);
80
- // use one of KOQ presentation format that matches requested unit system
81
- const presentationFormat = await getKoqPresentationFormat(koq, unitSystemMatchers);
82
- if (presentationFormat) {
83
- return getFormatProps(presentationFormat);
84
- }
85
- // use one of the formats in default formats map if there is one for matching phenomena and requested unit
86
- // system combination
87
- if (defaultFormats && unitSystem) {
88
- const actualPersistenceUnit = persistenceUnit instanceof InvertedUnit ? /* c8 ignore next */ await persistenceUnit.invertsUnit : persistenceUnit;
89
- const phenomenon = await actualPersistenceUnit?.phenomenon;
90
- if (phenomenon && defaultFormats[phenomenon.name.toUpperCase()]) {
91
- const defaultPhenomenonFormats = defaultFormats[phenomenon.name.toUpperCase()];
92
- for (const defaultUnitSystemFormat of Array.isArray(defaultPhenomenonFormats)
93
- ? /* c8 ignore next */ defaultPhenomenonFormats
94
- : [defaultPhenomenonFormats]) {
95
- if (defaultUnitSystemFormat.unitSystems.includes(unitSystem)) {
96
- return defaultUnitSystemFormat.format;
97
- }
98
- }
99
- }
114
+ async function getUnitSystemKey(unitsProvider, formatProps) {
115
+ const unitName = formatProps.composite?.units[0].name;
116
+ assert(!!unitName);
117
+ const unit = await unitsProvider.findUnitByName(unitName);
118
+ assert(!!unit);
119
+ const [_, unitSystemName] = unit.system.split(/[\.:]/);
120
+ switch (unitSystemName.toUpperCase()) {
121
+ case "METRIC":
122
+ return "metric";
123
+ case "IMPERIAL":
124
+ return "imperial";
125
+ case "USCUSTOM":
126
+ return "usCustomary";
127
+ case "USSURVEY":
128
+ return "usSurvey";
129
+ /* c8 ignore next 2 */
130
+ default:
131
+ return undefined;
100
132
  }
101
- // use persistence unit format if it matches requested unit system and matching presentation format was not found
102
- const persistenceUnitSystem = await persistenceUnit.unitSystem;
103
- if (persistenceUnitSystem && unitSystemMatchers.some((matcher) => matcher(persistenceUnitSystem))) {
104
- return getPersistenceUnitFormatProps(persistenceUnit);
133
+ }
134
+ async function getFormatPropsFromDefaultFormats({ schemaContext, formatsMap, unitSystem, koqName, }) {
135
+ const koq = await getKoq(schemaContext, koqName);
136
+ /* c8 ignore next 3 */
137
+ if (!koq) {
138
+ return undefined;
105
139
  }
106
- // use default presentation format if persistence unit does not match requested unit system
107
- if (koq.defaultPresentationFormat) {
108
- return getFormatProps(await koq.defaultPresentationFormat);
140
+ const persistenceUnit = await koq.persistenceUnit;
141
+ /* c8 ignore next 3 */
142
+ if (!persistenceUnit) {
143
+ return undefined;
109
144
  }
110
- return undefined;
111
- }
112
- async function getKoqPresentationFormat(koq, unitSystemMatchers) {
113
- const presentationFormats = koq.presentationFormats;
114
- for (const matcher of unitSystemMatchers) {
115
- for (const lazyFormat of presentationFormats) {
116
- const format = await lazyFormat;
117
- const lazyUnit = format.units && format.units[0][0];
118
- /* c8 ignore next 3 */
119
- if (!lazyUnit) {
120
- continue;
121
- }
122
- const unit = await lazyUnit;
123
- const currentUnitSystem = await unit.unitSystem;
124
- if (currentUnitSystem && matcher(currentUnitSystem)) {
125
- return format;
145
+ const actualPersistenceUnit = persistenceUnit instanceof InvertedUnit ? /* c8 ignore next */ await persistenceUnit.invertsUnit : persistenceUnit;
146
+ const phenomenon = await actualPersistenceUnit?.phenomenon;
147
+ if (phenomenon && formatsMap[phenomenon.name.toUpperCase()]) {
148
+ const defaultPhenomenonFormats = formatsMap[phenomenon.name.toUpperCase()];
149
+ for (const defaultUnitSystemFormat of Array.isArray(defaultPhenomenonFormats)
150
+ ? /* c8 ignore next */ defaultPhenomenonFormats
151
+ : [defaultPhenomenonFormats]) {
152
+ if (defaultUnitSystemFormat.unitSystems.includes(unitSystem)) {
153
+ return defaultUnitSystemFormat.format;
126
154
  }
127
155
  }
128
156
  }
129
157
  return undefined;
130
158
  }
131
- function getPersistenceUnitFormatProps(persistenceUnit) {
132
- // Same as Format "DefaultRealU" in Formats ecschema
133
- return {
134
- formatTraits: ["keepSingleZero", "keepDecimalPoint", "showUnitLabel"],
135
- precision: 6,
136
- type: "Decimal",
137
- uomSeparator: " ",
138
- decimalSeparator: ".",
139
- composite: {
140
- units: [
141
- {
142
- name: persistenceUnit.fullName,
143
- label: persistenceUnit.label,
144
- },
145
- ],
146
- },
147
- };
148
- }
149
- function getUnitSystemGroupMatchers(groupKey) {
150
- function createMatcher(name) {
151
- const names = Array.isArray(name) ? name : [name];
152
- return (unitSystem) => names.some((n) => n === unitSystem.name.toUpperCase());
153
- }
154
- switch (groupKey) {
155
- case "imperial":
156
- return ["IMPERIAL", "USCUSTOM", "INTERNATIONAL", "FINANCE"].map(createMatcher);
157
- case "metric":
158
- return [["SI", "METRIC"], "INTERNATIONAL", "FINANCE"].map(createMatcher);
159
- case "usCustomary":
160
- return ["USCUSTOM", "INTERNATIONAL", "FINANCE"].map(createMatcher);
161
- case "usSurvey":
162
- return ["USSURVEY", "USCUSTOM", "INTERNATIONAL", "FINANCE"].map(createMatcher);
163
- }
164
- return [];
165
- }
166
159
  //# sourceMappingURL=KoqPropertyValueFormatter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KoqPropertyValueFormatter.js","sourceRoot":"","sources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AsB,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,UAAU;YACb,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACjF,KAAK,QAAQ;YACX,OAAO,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC3E,KAAK,aAAa;YAChB,OAAO,CAAC,UAAU,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACrE,KAAK,UAAU;YACb,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,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 Core\n */\n\nimport { Format, FormatProps, FormatterSpec, ParserSpec, UnitsProvider, UnitSystemKey } from \"@itwin/core-quantity\";\nimport {\n getFormatProps,\n InvertedUnit,\n KindOfQuantity,\n SchemaContext,\n SchemaKey,\n SchemaMatchType,\n SchemaUnitProvider,\n Unit,\n UnitSystem,\n} from \"@itwin/ecschema-metadata\";\n\n/**\n * A data structure that associates unit systems with property value formatting props. The associations are used for\n * assigning formatting props for specific phenomenon and unit system combinations (see [[FormatsMap]]).\n *\n * @public\n */\nexport interface UnitSystemFormat {\n unitSystems: UnitSystemKey[];\n format: FormatProps;\n}\n\n/**\n * A data structure that associates specific phenomenon with one or more formatting props for specific unit system.\n *\n * Example:\n * ```json\n * {\n * length: [{\n * unitSystems: [\"metric\"],\n * format: formatForCentimeters,\n * }, {\n * unitSystems: [\"imperial\", \"usCustomary\"],\n * format: formatForInches,\n * }, {\n * unitSystems: [\"usSurvey\"],\n * format: formatForUsSurveyInches,\n * }]\n * }\n * ```\n *\n * @public\n */\nexport interface FormatsMap {\n [phenomenon: string]: UnitSystemFormat | UnitSystemFormat[];\n}\n\n/**\n * Options for finding a formatter spec to use in [[KoqPropertyValueFormatter]].\n * @public\n */\nexport interface FormatOptions {\n /** Full name of the `KindOfQuantity`, e.g. `SchemaName:KoqName`. */\n koqName: string;\n /** Unit system to use for formatting. */\n unitSystem?: UnitSystemKey;\n}\n\n/**\n * An utility for formatting property values based on `KindOfQuantity` and unit system.\n * @public\n */\nexport class KoqPropertyValueFormatter {\n private _unitsProvider: UnitsProvider;\n private _defaultFormats?: FormatsMap;\n\n constructor(\n private _schemaContext: SchemaContext,\n defaultFormats?: FormatsMap,\n ) {\n this._unitsProvider = new SchemaUnitProvider(_schemaContext);\n this._defaultFormats = defaultFormats\n ? Object.entries(defaultFormats).reduce((acc, [phenomenon, unitSystemFormats]) => ({ ...acc, [phenomenon.toUpperCase()]: unitSystemFormats }), {})\n : /* c8 ignore next */ undefined;\n }\n\n public async format(value: number, options: FormatOptions) {\n const formatterSpec = await this.getFormatterSpec(options);\n if (!formatterSpec) {\n return undefined;\n }\n return formatterSpec.applyFormatting(value);\n }\n\n public async getFormatterSpec(options: FormatOptions) {\n const formattingProps = await getFormattingProps(this._schemaContext, this._defaultFormats, options);\n if (!formattingProps) {\n return undefined;\n }\n const { formatProps, persistenceUnitName } = formattingProps;\n const persistenceUnit = await this._unitsProvider.findUnitByName(persistenceUnitName);\n const format = await Format.createFromJSON(\"\", this._unitsProvider, formatProps);\n return FormatterSpec.create(\"\", format, this._unitsProvider, persistenceUnit);\n }\n\n public async getParserSpec(options: FormatOptions) {\n const formattingProps = await getFormattingProps(this._schemaContext, this._defaultFormats, options);\n if (!formattingProps) {\n return undefined;\n }\n const { formatProps, persistenceUnitName } = formattingProps;\n const persistenceUnit = await this._unitsProvider.findUnitByName(persistenceUnitName);\n const format = await Format.createFromJSON(\"\", this._unitsProvider, formatProps);\n return ParserSpec.create(format, this._unitsProvider, persistenceUnit);\n }\n}\n\ninterface FormattingProps {\n formatProps: FormatProps;\n persistenceUnitName: string;\n}\n\nasync function getFormattingProps(\n schemaLocater: SchemaContext,\n defaultFormats: FormatsMap | undefined,\n options: FormatOptions,\n): Promise<FormattingProps | undefined> {\n const { koqName, unitSystem } = options;\n\n const koq = await getKoq(schemaLocater, koqName);\n if (!koq) {\n return undefined;\n }\n\n const persistenceUnit = await koq.persistenceUnit;\n /* c8 ignore next 3 */\n if (!persistenceUnit) {\n return undefined;\n }\n\n const formatProps = await getKoqFormatProps(koq, persistenceUnit, defaultFormats, unitSystem);\n if (!formatProps) {\n return undefined;\n }\n\n return { formatProps, persistenceUnitName: persistenceUnit.fullName };\n}\n\nasync function getKoq(schemaLocater: SchemaContext, fullName: string) {\n const [schemaName, propKoqName] = fullName.split(\":\");\n const schema = await schemaLocater.getSchema(new SchemaKey(schemaName), SchemaMatchType.Latest);\n if (!schema) {\n return undefined;\n }\n return schema.getItem(propKoqName, KindOfQuantity);\n}\n\nasync function getKoqFormatProps(\n koq: KindOfQuantity,\n persistenceUnit: Unit | InvertedUnit,\n defaultFormats: FormatsMap | undefined,\n unitSystem?: UnitSystemKey,\n) {\n const unitSystemMatchers = getUnitSystemGroupMatchers(unitSystem);\n // use one of KOQ presentation format that matches requested unit system\n const presentationFormat = await getKoqPresentationFormat(koq, unitSystemMatchers);\n if (presentationFormat) {\n return getFormatProps(presentationFormat);\n }\n\n // use one of the formats in default formats map if there is one for matching phenomena and requested unit\n // system combination\n if (defaultFormats && unitSystem) {\n const actualPersistenceUnit = persistenceUnit instanceof InvertedUnit ? /* c8 ignore next */ await persistenceUnit.invertsUnit : persistenceUnit;\n const phenomenon = await actualPersistenceUnit?.phenomenon;\n if (phenomenon && defaultFormats[phenomenon.name.toUpperCase()]) {\n const defaultPhenomenonFormats = defaultFormats[phenomenon.name.toUpperCase()];\n for (const defaultUnitSystemFormat of Array.isArray(defaultPhenomenonFormats)\n ? /* c8 ignore next */ defaultPhenomenonFormats\n : [defaultPhenomenonFormats]) {\n if (defaultUnitSystemFormat.unitSystems.includes(unitSystem)) {\n return defaultUnitSystemFormat.format;\n }\n }\n }\n }\n\n // use persistence unit format if it matches requested unit system and matching presentation format was not found\n const persistenceUnitSystem = await persistenceUnit.unitSystem;\n if (persistenceUnitSystem && unitSystemMatchers.some((matcher) => matcher(persistenceUnitSystem))) {\n return getPersistenceUnitFormatProps(persistenceUnit);\n }\n\n // use default presentation format if persistence unit does not match requested unit system\n if (koq.defaultPresentationFormat) {\n return getFormatProps(await koq.defaultPresentationFormat);\n }\n\n return undefined;\n}\n\nasync function getKoqPresentationFormat(koq: KindOfQuantity, unitSystemMatchers: Array<(unitSystem: UnitSystem) => boolean>) {\n const presentationFormats = koq.presentationFormats;\n for (const matcher of unitSystemMatchers) {\n for (const lazyFormat of presentationFormats) {\n const format = await lazyFormat;\n const lazyUnit = format.units && format.units[0][0];\n /* c8 ignore next 3 */\n if (!lazyUnit) {\n continue;\n }\n const unit = await lazyUnit;\n const currentUnitSystem = await unit.unitSystem;\n if (currentUnitSystem && matcher(currentUnitSystem)) {\n return format;\n }\n }\n }\n return undefined;\n}\n\nfunction getPersistenceUnitFormatProps(persistenceUnit: Unit | InvertedUnit): FormatProps {\n // Same as Format \"DefaultRealU\" in Formats ecschema\n return {\n formatTraits: [\"keepSingleZero\", \"keepDecimalPoint\", \"showUnitLabel\"],\n precision: 6,\n type: \"Decimal\",\n uomSeparator: \" \",\n decimalSeparator: \".\",\n composite: {\n units: [\n {\n name: persistenceUnit.fullName,\n label: persistenceUnit.label,\n },\n ],\n },\n };\n}\n\nfunction getUnitSystemGroupMatchers(groupKey?: UnitSystemKey) {\n function createMatcher(name: string | string[]) {\n const names = Array.isArray(name) ? name : [name];\n return (unitSystem: UnitSystem) => names.some((n) => n === unitSystem.name.toUpperCase());\n }\n switch (groupKey) {\n case \"imperial\":\n return [\"IMPERIAL\", \"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"].map(createMatcher);\n case \"metric\":\n return [[\"SI\", \"METRIC\"], \"INTERNATIONAL\", \"FINANCE\"].map(createMatcher);\n case \"usCustomary\":\n return [\"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"].map(createMatcher);\n case \"usSurvey\":\n return [\"USSURVEY\", \"USCUSTOM\", \"INTERNATIONAL\", \"FINANCE\"].map(createMatcher);\n }\n return [];\n}\n"]}
1
+ {"version":3,"file":"KoqPropertyValueFormatter.js","sourceRoot":"","sources":["../../../src/presentation-common/KoqPropertyValueFormatter.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAgC,aAAa,EAAE,UAAU,EAAgC,MAAM,sBAAsB,CAAC;AACrI,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,qBAAqB,EAAE,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAiE9J;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IAC5B,cAAc,CAAgB;IAC9B,cAAc,CAAgB;IAC9B,gBAAgB,CAAmB;IAC3C,4DAA4D;IACpD,eAAe,CAAc;IAMrC,4DAA4D;IAC5D,YAAY,oBAAoE,EAAE,cAA2B,EAAE,eAAiC;QAC9I,IAAI,oBAAoB,YAAY,aAAa,EAAE,CAAC;YAClD,IAAI,CAAC,cAAc,GAAG,oBAAoB,CAAC;YAC3C,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;YACxC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACvC,C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AAC,oBAAoB,CAAC,MAAM,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC;IACjJ,MAAM,UAAU,GAAG,MAAM,qBAAqB,EAAE,UAAU,CAAC;IAC3D,IAAI,UAAU,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QAC5D,MAAM,wBAAwB,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QAC3E,KAAK,MAAM,uBAAuB,IAAI,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC;YAC3E,CAAC,CAAC,oBAAoB,CAAC,wBAAwB;YAC/C,CAAC,CAAC,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAC/B,IAAI,uBAAuB,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC7D,OAAO,uBAAuB,CAAC,MAAM,CAAC;YACxC,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Format, FormatProps, FormatsProvider, FormatterSpec, ParserSpec, UnitsProvider, UnitSystemKey } from \"@itwin/core-quantity\";\r\nimport { InvertedUnit, KindOfQuantity, SchemaContext, SchemaFormatsProvider, SchemaKey, SchemaMatchType, SchemaUnitProvider } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * A data structure that associates unit systems with property value formatting props. The associations are used for\r\n * assigning formatting props for specific phenomenon and unit system combinations (see [[FormatsMap]]).\r\n *\r\n * @public\r\n *\r\n * @deprecated in 5.1 - will not be removed until after 2026-08-08. `FormatsMap` and related APIs have been deprecated in favor of [FormatsProvider]($core-quantity).\r\n */\r\nexport interface UnitSystemFormat {\r\n unitSystems: UnitSystemKey[];\r\n format: FormatProps;\r\n}\r\n\r\n/**\r\n * A data structure that associates specific phenomenon with one or more formatting props for specific unit system.\r\n *\r\n * Example:\r\n * ```json\r\n * {\r\n * length: [{\r\n * unitSystems: [\"metric\"],\r\n * format: formatForCentimeters,\r\n * }, {\r\n * unitSystems: [\"imperial\", \"usCustomary\"],\r\n * format: formatForInches,\r\n * }, {\r\n * unitSystems: [\"usSurvey\"],\r\n * format: formatForUsSurveyInches,\r\n * }]\r\n * }\r\n * ```\r\n *\r\n * @public\r\n *\r\n * @deprecated in 5.1 - will not be removed until after 2026-08-08. `FormatsMap` and related APIs have been deprecated in favor of [FormatsProvider]($core-quantity).\r\n */\r\nexport interface FormatsMap {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n [phenomenon: string]: UnitSystemFormat | UnitSystemFormat[];\r\n}\r\n\r\n/**\r\n * Options for finding a formatter spec to use in [[KoqPropertyValueFormatter]].\r\n * @public\r\n */\r\nexport interface FormatOptions {\r\n /** Full name of the `KindOfQuantity`, e.g. `SchemaName:KoqName`. */\r\n koqName: string;\r\n /** Unit system to use for formatting. */\r\n unitSystem?: UnitSystemKey;\r\n}\r\n\r\n/**\r\n * Props for creating [[KoqPropertyValueFormatter]].\r\n * @public\r\n */\r\ninterface KoqPropertyValueFormatterProps {\r\n /** Schema context to use for locating units, formats, etc. Generally retrieved through the `schemaContext` getter on an iModel. */\r\n schemaContext: SchemaContext;\r\n /** Formats provider to use for finding formatting props. Defaults to [SchemaFormatsProvider]($ecschema-metadata) when not supplied. */\r\n formatsProvider?: FormatsProvider;\r\n}\r\n\r\n/**\r\n * An utility for formatting property values based on `KindOfQuantity` and unit system.\r\n * @public\r\n */\r\nexport class KoqPropertyValueFormatter {\r\n private _schemaContext: SchemaContext;\r\n private _unitsProvider: UnitsProvider;\r\n private _formatsProvider?: FormatsProvider;\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n private _defaultFormats?: FormatsMap;\r\n\r\n /** @deprecated in 5.1 - will not be removed until after 2026-08-08. Use the overload that takes a props object. */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n constructor(schemaContext: SchemaContext, defaultFormats?: FormatsMap, formatsProvider?: FormatsProvider);\r\n constructor(props: KoqPropertyValueFormatterProps);\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n constructor(schemaContextOrProps: SchemaContext | KoqPropertyValueFormatterProps, defaultFormats?: FormatsMap, formatsProvider?: FormatsProvider) {\r\n if (schemaContextOrProps instanceof SchemaContext) {\r\n this._schemaContext = schemaContextOrProps;\r\n this._formatsProvider = formatsProvider;\r\n this.defaultFormats = defaultFormats;\r\n } else {\r\n this._schemaContext = schemaContextOrProps.schemaContext;\r\n this._formatsProvider = schemaContextOrProps.formatsProvider;\r\n }\r\n this._unitsProvider = new SchemaUnitProvider(this._schemaContext);\r\n }\r\n\r\n /* c8 ignore start */\r\n /** @internal */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public get defaultFormats(): FormatsMap | undefined {\r\n return this._defaultFormats;\r\n }\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public set defaultFormats(value: FormatsMap | undefined) {\r\n this._defaultFormats = value\r\n ? Object.entries(value).reduce((acc, [phenomenon, unitSystemFormats]) => ({ ...acc, [phenomenon.toUpperCase()]: unitSystemFormats }), {})\r\n : undefined;\r\n }\r\n /* c8 ignore end */\r\n\r\n public async format(value: number, options: FormatOptions) {\r\n const formatterSpec = await this.getFormatterSpec(options);\r\n if (!formatterSpec) {\r\n return undefined;\r\n }\r\n return formatterSpec.applyFormatting(value);\r\n }\r\n\r\n public async getFormatterSpec(options: FormatOptions) {\r\n const formattingProps = await this.#getFormattingProps(options);\r\n if (!formattingProps) {\r\n return undefined;\r\n }\r\n const { formatProps, persistenceUnitName } = formattingProps;\r\n const persistenceUnit = await this._unitsProvider.findUnitByName(persistenceUnitName);\r\n const format = await Format.createFromJSON(\"\", this._unitsProvider, formatProps);\r\n return FormatterSpec.create(\"\", format, this._unitsProvider, persistenceUnit);\r\n }\r\n\r\n public async getParserSpec(options: FormatOptions) {\r\n const formattingProps = await this.#getFormattingProps(options);\r\n if (!formattingProps) {\r\n return undefined;\r\n }\r\n const { formatProps, persistenceUnitName } = formattingProps;\r\n const persistenceUnit = await this._unitsProvider.findUnitByName(persistenceUnitName);\r\n const format = await Format.createFromJSON(\"\", this._unitsProvider, formatProps);\r\n return ParserSpec.create(format, this._unitsProvider, persistenceUnit);\r\n }\r\n\r\n async #getFormattingProps(options: FormatOptions): Promise<FormattingProps | undefined> {\r\n const { koqName } = options;\r\n const koq = await getKoq(this._schemaContext, koqName);\r\n if (!koq) {\r\n return undefined;\r\n }\r\n const persistenceUnit = await koq.persistenceUnit;\r\n assert(!!persistenceUnit);\r\n\r\n // default to metric as it's the persistence unit system\r\n const unitSystem = options.unitSystem ?? \"metric\";\r\n\r\n const formatsProvider = this._formatsProvider ?? new SchemaFormatsProvider(this._schemaContext, unitSystem);\r\n const formatProps = await formatsProvider.getFormat(koqName);\r\n\r\n // `SchemaFormatsProvider` will fall back to default presentation format, but we want to fall back\r\n // to default formats' map first, and only then to the default presentation format. All of this can\r\n // be removed with the removal of default formats map.\r\n if (this._defaultFormats && (!formatProps || (await getUnitSystemKey(this._unitsProvider, formatProps)) !== unitSystem)) {\r\n const defaultFormatProps = await getFormatPropsFromDefaultFormats({\r\n schemaContext: this._schemaContext,\r\n formatsMap: this._defaultFormats,\r\n unitSystem,\r\n koqName,\r\n });\r\n if (defaultFormatProps) {\r\n return { formatProps: defaultFormatProps, persistenceUnitName: persistenceUnit.fullName };\r\n }\r\n }\r\n\r\n if (formatProps) {\r\n return { formatProps, persistenceUnitName: persistenceUnit.fullName };\r\n }\r\n\r\n return undefined;\r\n }\r\n}\r\n\r\ninterface FormattingProps {\r\n formatProps: FormatProps;\r\n persistenceUnitName: string;\r\n}\r\n\r\nasync function getKoq(schemaLocater: SchemaContext, fullName: string) {\r\n const [schemaName, propKoqName] = fullName.split(\":\");\r\n const schema = await schemaLocater.getSchema(new SchemaKey(schemaName), SchemaMatchType.Latest);\r\n if (!schema) {\r\n return undefined;\r\n }\r\n return schema.getItem(propKoqName, KindOfQuantity);\r\n}\r\n\r\nasync function getUnitSystemKey(unitsProvider: UnitsProvider, formatProps: FormatProps): Promise<UnitSystemKey | undefined> {\r\n const unitName = formatProps.composite?.units[0].name;\r\n assert(!!unitName);\r\n const unit = await unitsProvider.findUnitByName(unitName);\r\n assert(!!unit);\r\n const [_, unitSystemName] = unit.system.split(/[\\.:]/);\r\n switch (unitSystemName.toUpperCase()) {\r\n case \"METRIC\":\r\n return \"metric\";\r\n case \"IMPERIAL\":\r\n return \"imperial\";\r\n case \"USCUSTOM\":\r\n return \"usCustomary\";\r\n case \"USSURVEY\":\r\n return \"usSurvey\";\r\n /* c8 ignore next 2 */\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\nasync function getFormatPropsFromDefaultFormats({\r\n schemaContext,\r\n formatsMap,\r\n unitSystem,\r\n koqName,\r\n}: {\r\n schemaContext: SchemaContext;\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n formatsMap: FormatsMap;\r\n unitSystem: UnitSystemKey;\r\n koqName: string;\r\n}): Promise<FormatProps | undefined> {\r\n const koq = await getKoq(schemaContext, koqName);\r\n /* c8 ignore next 3 */\r\n if (!koq) {\r\n return undefined;\r\n }\r\n\r\n const persistenceUnit = await koq.persistenceUnit;\r\n /* c8 ignore next 3 */\r\n if (!persistenceUnit) {\r\n return undefined;\r\n }\r\n const actualPersistenceUnit = persistenceUnit instanceof InvertedUnit ? /* c8 ignore next */ await persistenceUnit.invertsUnit : persistenceUnit;\r\n const phenomenon = await actualPersistenceUnit?.phenomenon;\r\n if (phenomenon && formatsMap[phenomenon.name.toUpperCase()]) {\r\n const defaultPhenomenonFormats = formatsMap[phenomenon.name.toUpperCase()];\r\n for (const defaultUnitSystemFormat of Array.isArray(defaultPhenomenonFormats)\r\n ? /* c8 ignore next */ defaultPhenomenonFormats\r\n : [defaultPhenomenonFormats]) {\r\n if (defaultUnitSystemFormat.unitSystems.includes(unitSystem)) {\r\n return defaultUnitSystemFormat.format;\r\n }\r\n }\r\n }\r\n return undefined;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"LabelDefinition.js","sourceRoot":"","sources":["../../../src/presentation-common/LabelDefinition.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AA8BH,gBAAgB;AAChB,MAAM,CAAC,MAAM,mCAAmC,GAAG,WAAW,CAAC;AAE/D,cAAc;AACd,MAAM,KAAW,eAAe,CAoB/B;AApBD,WAAiB,eAAe;IAC9B;;;OAGG;IACH,SAAgB,qBAAqB,CAAC,GAAoB;QACxD,OAAO,GAAG,CAAC,QAAQ,KAAK,mCAAmC,CAAC;IAC9D,CAAC;IAFe,qCAAqB,wBAEpC,CAAA;IAED;;;OAGG;IACH,SAAgB,eAAe,CAAC,KAAa;QAC3C,OAAO;YACL,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,QAAQ;SACnB,CAAC;IACJ,CAAC;IANe,+BAAe,kBAM9B,CAAA;AACH,CAAC,EApBgB,eAAe,KAAf,eAAe,QAoB/B","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 Hierarchies\n */\n\n/**\n * Data structure that describes raw composite label value.\n * @public\n */\nexport interface LabelCompositeValue {\n separator: string;\n values: LabelDefinition[];\n}\n\n/**\n * Type definition of label raw value.\n * @public\n */\nexport type LabelRawValue = string | number | boolean | LabelCompositeValue;\n\n/**\n * Data structure that describes label definition.\n * @public\n */\nexport interface LabelDefinition {\n /** Display value of label */\n displayValue: string;\n /** Raw value of label */\n rawValue: LabelRawValue;\n /** Type name of raw value */\n typeName: string;\n}\n\n/** @internal */\nexport const COMPOSITE_LABEL_DEFINITION_TYPENAME = \"composite\";\n\n/** @public */\nexport namespace LabelDefinition {\n /**\n * Checks if provided [[LabelDefinition]] has raw value of type [[LabelCompositeValue]].\n * @public\n */\n export function isCompositeDefinition(def: LabelDefinition): def is LabelDefinition & { rawValue: LabelCompositeValue } {\n return def.typeName === COMPOSITE_LABEL_DEFINITION_TYPENAME;\n }\n\n /**\n * Creates [[LabelDefinition]] from string value.\n * @public\n */\n export function fromLabelString(label: string): LabelDefinition {\n return {\n displayValue: label,\n rawValue: label,\n typeName: \"string\",\n };\n }\n}\n"]}
1
+ {"version":3,"file":"LabelDefinition.js","sourceRoot":"","sources":["../../../src/presentation-common/LabelDefinition.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AA8BH,gBAAgB;AAChB,MAAM,CAAC,MAAM,mCAAmC,GAAG,WAAW,CAAC;AAE/D,cAAc;AACd,MAAM,KAAW,eAAe,CAoB/B;AApBD,WAAiB,eAAe;IAC9B;;;OAGG;IACH,SAAgB,qBAAqB,CAAC,GAAoB;QACxD,OAAO,GAAG,CAAC,QAAQ,KAAK,mCAAmC,CAAC;IAC9D,CAAC;IAFe,qCAAqB,wBAEpC,CAAA;IAED;;;OAGG;IACH,SAAgB,eAAe,CAAC,KAAa;QAC3C,OAAO;YACL,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,KAAK;YACf,QAAQ,EAAE,QAAQ;SACnB,CAAC;IACJ,CAAC;IANe,+BAAe,kBAM9B,CAAA;AACH,CAAC,EApBgB,eAAe,KAAf,eAAe,QAoB/B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Hierarchies\r\n */\r\n\r\n/**\r\n * Data structure that describes raw composite label value.\r\n * @public\r\n */\r\nexport interface LabelCompositeValue {\r\n separator: string;\r\n values: LabelDefinition[];\r\n}\r\n\r\n/**\r\n * Type definition of label raw value.\r\n * @public\r\n */\r\nexport type LabelRawValue = string | number | boolean | LabelCompositeValue;\r\n\r\n/**\r\n * Data structure that describes label definition.\r\n * @public\r\n */\r\nexport interface LabelDefinition {\r\n /** Display value of label */\r\n displayValue: string;\r\n /** Raw value of label */\r\n rawValue: LabelRawValue;\r\n /** Type name of raw value */\r\n typeName: string;\r\n}\r\n\r\n/** @internal */\r\nexport const COMPOSITE_LABEL_DEFINITION_TYPENAME = \"composite\";\r\n\r\n/** @public */\r\nexport namespace LabelDefinition {\r\n /**\r\n * Checks if provided [[LabelDefinition]] has raw value of type [[LabelCompositeValue]].\r\n * @public\r\n */\r\n export function isCompositeDefinition(def: LabelDefinition): def is LabelDefinition & { rawValue: LabelCompositeValue } {\r\n return def.typeName === COMPOSITE_LABEL_DEFINITION_TYPENAME;\r\n }\r\n\r\n /**\r\n * Creates [[LabelDefinition]] from string value.\r\n * @public\r\n */\r\n export function fromLabelString(label: string): LabelDefinition {\r\n return {\r\n displayValue: label,\r\n rawValue: label,\r\n typeName: \"string\",\r\n };\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"LocalizationHelper.js","sourceRoot":"","sources":["../../../src/presentation-common/LocalizationHelper.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI5E,OAAO,EAAE,mCAAmC,EAAwC,MAAM,sBAAsB,CAAC;AAEjH,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAMlD,gBAAgB;AAChB,MAAM,OAAO,kBAAkB;IACrB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AAI,CAAC,KAAK,CAAC;YACnD,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;SAC/F,CAAC;IACJ,CAAC;IAEO,wBAAwB,CAAC,KAAmB;QAClD,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5G,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/** @packageDocumentation\n * @module Core\n */\n\nimport { CategoryDescription } from \"./content/Category.js\";\nimport { Content } from \"./content/Content.js\";\nimport { Descriptor } from \"./content/Descriptor.js\";\nimport { Field } from \"./content/Fields.js\";\nimport { Item } from \"./content/Item.js\";\nimport { DisplayValue, DisplayValueGroup, Value } from \"./content/Value.js\";\nimport { ElementProperties } from \"./ElementProperties.js\";\nimport { Node } from \"./hierarchy/Node.js\";\nimport { NodePathElement } from \"./hierarchy/NodePathElement.js\";\nimport { COMPOSITE_LABEL_DEFINITION_TYPENAME, LabelCompositeValue, LabelDefinition } from \"./LabelDefinition.js\";\n\nconst KEY_PATTERN = /@[\\w\\d\\-_]+:[\\w\\d\\-\\._]+?@/g;\n\ninterface LocalizationHelperProps {\n getLocalizedString: (key: string) => string;\n}\n\n/** @internal */\nexport class LocalizationHelper {\n private _getLocalizedString: (key: string) => string;\n\n constructor(props: LocalizationHelperProps) {\n this._getLocalizedString = props.getLocalizedString;\n }\n\n public getLocalizedString(text: string) {\n return text.replace(KEY_PATTERN, (key) => this._getLocalizedString(key.replace(/^@|@$/g, \"\")));\n }\n\n public getLocalizedNodes(nodes: Node[]): Node[] {\n return nodes.map((n) => this.getLocalizedNode(n));\n }\n\n public getLocalizedNodePathElement(npe: NodePathElement): NodePathElement {\n return {\n ...npe,\n node: this.getLocalizedNode(npe.node),\n children: npe.children.map((c) => this.getLocalizedNodePathElement(c)),\n };\n }\n\n public getLocalizedDisplayValueGroup(group: DisplayValueGroup): DisplayValueGroup {\n return {\n ...group,\n displayValue: this.getLocalizedDisplayValue(group.displayValue),\n };\n }\n\n public getLocalizedLabelDefinition(labelDefinition: LabelDefinition): LabelDefinition {\n const getLocalizedComposite = (compositeValue: LabelCompositeValue) => ({\n ...compositeValue,\n values: compositeValue.values.map((value) => this.getLocalizedLabelDefinition(value)),\n });\n\n if (labelDefinition.typeName === COMPOSITE_LABEL_DEFINITION_TYPENAME) {\n return {\n ...labelDefinition,\n rawValue: getLocalizedComposite(labelDefinition.rawValue as LabelCompositeValue),\n };\n }\n if (labelDefinition.typeName === \"string\") {\n return {\n ...labelDefinition,\n rawValue: this.getLocalizedString(labelDefinition.rawValue as string),\n displayValue: this.getLocalizedString(labelDefinition.displayValue),\n };\n }\n return labelDefinition;\n }\n\n public getLocalizedLabelDefinitions(labelDefinitions: LabelDefinition[]) {\n return labelDefinitions.map((labelDefinition) => this.getLocalizedLabelDefinition(labelDefinition));\n }\n\n public getLocalizedContentDescriptor(descriptor: Descriptor) {\n const clone = new Descriptor(descriptor);\n clone.fields.forEach((field) => this.getLocalizedContentField(field));\n clone.categories.forEach((category) => this.getLocalizedCategoryDescription(category));\n return clone;\n }\n\n public getLocalizedContentItems(items: Item[]): Item[] {\n return items.map((item) => this.getLocalizedContentItem(item));\n }\n\n public getLocalizedContent(content: Content): Content {\n return new Content(this.getLocalizedContentDescriptor(content.descriptor), this.getLocalizedContentItems(content.contentSet));\n }\n\n public getLocalizedElementProperties(elem: ElementProperties): ElementProperties {\n return {\n ...elem,\n label: this.getLocalizedString(elem.label),\n };\n }\n\n // warning: this function mutates the item\n private getLocalizedContentItem(item: Item): Item {\n item.label = this.getLocalizedLabelDefinition(item.label);\n item.values = Object.entries(item.values).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedRawValue(v) }), {});\n item.displayValues = Object.entries(item.displayValues).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedDisplayValue(v) }), {});\n return item;\n }\n\n private getLocalizedRawValue(value: Value): Value {\n if (typeof value === \"string\") {\n return this.getLocalizedString(value);\n }\n if (Value.isNavigationValue(value)) {\n return {\n ...value,\n label: this.getLocalizedLabelDefinition(value.label),\n };\n }\n if (Value.isNestedContent(value)) {\n return value.map((item) => ({\n ...item,\n values: Object.entries(item.values).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedRawValue(v) }), {}),\n displayValues: Object.entries(item.displayValues).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedDisplayValue(v) }), {}),\n }));\n }\n if (Value.isArray(value)) {\n return value.map((v) => this.getLocalizedRawValue(v));\n }\n if (Value.isMap(value)) {\n return Object.entries(value).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedRawValue(v) }), {});\n }\n return value;\n }\n\n // warning: this function mutates the field\n private getLocalizedContentField<TField extends Field>(field: TField) {\n field.label = this.getLocalizedString(field.label);\n if (field.isPropertiesField()) {\n if (field.isStructPropertiesField()) {\n field.memberFields = field.memberFields.map((m) => this.getLocalizedContentField(m));\n } else if (field.isArrayPropertiesField()) {\n field.itemsField = this.getLocalizedContentField(field.itemsField);\n }\n } else if (field.isNestedContentField()) {\n field.nestedFields = field.nestedFields.map((m) => this.getLocalizedContentField(m));\n }\n return field;\n }\n\n // warning: this function mutates the category\n private getLocalizedCategoryDescription(category: CategoryDescription) {\n category.label = this.getLocalizedString(category.label);\n category.description = this.getLocalizedString(category.description);\n return category;\n }\n\n public getLocalizedNode(node: Node): Node {\n return {\n ...node,\n label: this.getLocalizedLabelDefinition(node.label),\n ...(node.description ? { description: this.getLocalizedString(node.description) } : undefined),\n };\n }\n\n private getLocalizedDisplayValue(value: DisplayValue): DisplayValue {\n if (typeof value === \"undefined\") {\n return undefined;\n }\n if (typeof value === \"string\") {\n return this.getLocalizedString(value);\n }\n if (DisplayValue.isArray(value)) {\n return value.map((v) => this.getLocalizedDisplayValue(v));\n }\n return Object.entries(value).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedDisplayValue(v) }), {});\n }\n}\n"]}
1
+ {"version":3,"file":"LocalizationHelper.js","sourceRoot":"","sources":["../../../src/presentation-common/LocalizationHelper.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAI5E,OAAO,EAAE,mCAAmC,EAAwC,MAAM,sBAAsB,CAAC;AAEjH,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAMlD,gBAAgB;AAChB,MAAM,OAAO,kBAAkB;IACrB,mBAAmB,CAA0B;IAErD,YAAY,KAA8B;QACxC,IAAI,CAAC,mBAAmB,GAAG,KAAK,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C,EAAE,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;SAC/F,CAAC;IACJ,CAAC;IAEO,wBAAwB,CAAC,KAAmB;QAClD,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5G,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { CategoryDescription } from \"./content/Category.js\";\r\nimport { Content } from \"./content/Content.js\";\r\nimport { Descriptor } from \"./content/Descriptor.js\";\r\nimport { Field } from \"./content/Fields.js\";\r\nimport { Item } from \"./content/Item.js\";\r\nimport { DisplayValue, DisplayValueGroup, Value } from \"./content/Value.js\";\r\nimport { ElementProperties } from \"./ElementProperties.js\";\r\nimport { Node } from \"./hierarchy/Node.js\";\r\nimport { NodePathElement } from \"./hierarchy/NodePathElement.js\";\r\nimport { COMPOSITE_LABEL_DEFINITION_TYPENAME, LabelCompositeValue, LabelDefinition } from \"./LabelDefinition.js\";\r\n\r\nconst KEY_PATTERN = /@[\\w\\d\\-_]+:[\\w\\d\\-\\._]+?@/g;\r\n\r\ninterface LocalizationHelperProps {\r\n getLocalizedString: (key: string) => string;\r\n}\r\n\r\n/** @internal */\r\nexport class LocalizationHelper {\r\n private _getLocalizedString: (key: string) => string;\r\n\r\n constructor(props: LocalizationHelperProps) {\r\n this._getLocalizedString = props.getLocalizedString;\r\n }\r\n\r\n public getLocalizedString(text: string) {\r\n return text.replace(KEY_PATTERN, (key) => this._getLocalizedString(key.replace(/^@|@$/g, \"\")));\r\n }\r\n\r\n public getLocalizedNodes(nodes: Node[]): Node[] {\r\n return nodes.map((n) => this.getLocalizedNode(n));\r\n }\r\n\r\n public getLocalizedNodePathElement(npe: NodePathElement): NodePathElement {\r\n return {\r\n ...npe,\r\n node: this.getLocalizedNode(npe.node),\r\n children: npe.children.map((c) => this.getLocalizedNodePathElement(c)),\r\n };\r\n }\r\n\r\n public getLocalizedDisplayValueGroup(group: DisplayValueGroup): DisplayValueGroup {\r\n return {\r\n ...group,\r\n displayValue: this.getLocalizedDisplayValue(group.displayValue),\r\n };\r\n }\r\n\r\n public getLocalizedLabelDefinition(labelDefinition: LabelDefinition): LabelDefinition {\r\n const getLocalizedComposite = (compositeValue: LabelCompositeValue) => ({\r\n ...compositeValue,\r\n values: compositeValue.values.map((value) => this.getLocalizedLabelDefinition(value)),\r\n });\r\n\r\n if (labelDefinition.typeName === COMPOSITE_LABEL_DEFINITION_TYPENAME) {\r\n return {\r\n ...labelDefinition,\r\n rawValue: getLocalizedComposite(labelDefinition.rawValue as LabelCompositeValue),\r\n };\r\n }\r\n if (labelDefinition.typeName === \"string\") {\r\n return {\r\n ...labelDefinition,\r\n rawValue: this.getLocalizedString(labelDefinition.rawValue as string),\r\n displayValue: this.getLocalizedString(labelDefinition.displayValue),\r\n };\r\n }\r\n return labelDefinition;\r\n }\r\n\r\n public getLocalizedLabelDefinitions(labelDefinitions: LabelDefinition[]) {\r\n return labelDefinitions.map((labelDefinition) => this.getLocalizedLabelDefinition(labelDefinition));\r\n }\r\n\r\n public getLocalizedContentDescriptor(descriptor: Descriptor) {\r\n const clone = new Descriptor(descriptor);\r\n clone.fields.forEach((field) => this.getLocalizedContentField(field));\r\n clone.categories.forEach((category) => this.getLocalizedCategoryDescription(category));\r\n return clone;\r\n }\r\n\r\n public getLocalizedContentItems(items: Item[]): Item[] {\r\n return items.map((item) => this.getLocalizedContentItem(item));\r\n }\r\n\r\n public getLocalizedContent(content: Content): Content {\r\n return new Content(this.getLocalizedContentDescriptor(content.descriptor), this.getLocalizedContentItems(content.contentSet));\r\n }\r\n\r\n public getLocalizedElementProperties(elem: ElementProperties): ElementProperties {\r\n return {\r\n ...elem,\r\n label: this.getLocalizedString(elem.label),\r\n };\r\n }\r\n\r\n // warning: this function mutates the item\r\n private getLocalizedContentItem(item: Item): Item {\r\n item.label = this.getLocalizedLabelDefinition(item.label);\r\n item.values = Object.entries(item.values).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedRawValue(v) }), {});\r\n item.displayValues = Object.entries(item.displayValues).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedDisplayValue(v) }), {});\r\n return item;\r\n }\r\n\r\n private getLocalizedRawValue(value: Value): Value {\r\n if (typeof value === \"string\") {\r\n return this.getLocalizedString(value);\r\n }\r\n if (Value.isNavigationValue(value)) {\r\n return {\r\n ...value,\r\n label: this.getLocalizedLabelDefinition(value.label),\r\n };\r\n }\r\n if (Value.isNestedContent(value)) {\r\n return value.map((item) => ({\r\n ...item,\r\n values: Object.entries(item.values).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedRawValue(v) }), {}),\r\n displayValues: Object.entries(item.displayValues).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedDisplayValue(v) }), {}),\r\n }));\r\n }\r\n if (Value.isArray(value)) {\r\n return value.map((v) => this.getLocalizedRawValue(v));\r\n }\r\n if (Value.isMap(value)) {\r\n return Object.entries(value).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedRawValue(v) }), {});\r\n }\r\n return value;\r\n }\r\n\r\n // warning: this function mutates the field\r\n private getLocalizedContentField<TField extends Field>(field: TField) {\r\n field.label = this.getLocalizedString(field.label);\r\n if (field.isPropertiesField()) {\r\n if (field.isStructPropertiesField()) {\r\n field.memberFields = field.memberFields.map((m) => this.getLocalizedContentField(m));\r\n } else if (field.isArrayPropertiesField()) {\r\n field.itemsField = this.getLocalizedContentField(field.itemsField);\r\n }\r\n } else if (field.isNestedContentField()) {\r\n field.nestedFields = field.nestedFields.map((m) => this.getLocalizedContentField(m));\r\n }\r\n return field;\r\n }\r\n\r\n // warning: this function mutates the category\r\n private getLocalizedCategoryDescription(category: CategoryDescription) {\r\n category.label = this.getLocalizedString(category.label);\r\n category.description = this.getLocalizedString(category.description);\r\n return category;\r\n }\r\n\r\n public getLocalizedNode(node: Node): Node {\r\n return {\r\n ...node,\r\n label: this.getLocalizedLabelDefinition(node.label),\r\n ...(node.description ? { description: this.getLocalizedString(node.description) } : undefined),\r\n };\r\n }\r\n\r\n private getLocalizedDisplayValue(value: DisplayValue): DisplayValue {\r\n if (typeof value === \"undefined\") {\r\n return undefined;\r\n }\r\n if (typeof value === \"string\") {\r\n return this.getLocalizedString(value);\r\n }\r\n if (DisplayValue.isArray(value)) {\r\n return value.map((v) => this.getLocalizedDisplayValue(v));\r\n }\r\n return Object.entries(value).reduce((o, [k, v]) => ({ ...o, [k]: this.getLocalizedDisplayValue(v) }), {});\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PresentationIpcInterface.js","sourceRoot":"","sources":["../../../src/presentation-common/PresentationIpcInterface.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAIH,gBAAgB;AAChB,MAAM,CAAC,MAAM,6BAA6B,GAAG,oCAAoC,CAAC;AAyBlF,gBAAgB;AAChB,MAAM,CAAN,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B;;OAEG;IACH,yDAAgC,CAAA;AAClC,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC","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 Core\n */\n\nimport { RulesetVariableJSON } from \"./RulesetVariables.js\";\n\n/** @internal */\nexport const PRESENTATION_IPC_CHANNEL_NAME = \"itwinjs-presentation/ipc-interface\";\n\ninterface CommonIpcParams {\n clientId: string;\n}\n\ninterface SetRulesetVariableParams<TVariable> extends CommonIpcParams {\n rulesetId: string;\n variable: TVariable;\n}\n\ninterface UnsetRulesetVariableParams extends CommonIpcParams {\n rulesetId: string;\n variableId: string;\n}\n\n/** @internal */\nexport interface PresentationIpcInterface {\n /** Sets ruleset variable value. */\n setRulesetVariable(params: SetRulesetVariableParams<RulesetVariableJSON>): Promise<void>;\n\n /** Unsets ruleset variable value. */\n unsetRulesetVariable(params: UnsetRulesetVariableParams): Promise<void>;\n}\n\n/** @internal */\nexport enum PresentationIpcEvents {\n /**\n * ID of an event that's emitted when backend detects changes in presented data.\n */\n Update = \"presentation.onUpdate\",\n}\n"]}
1
+ {"version":3,"file":"PresentationIpcInterface.js","sourceRoot":"","sources":["../../../src/presentation-common/PresentationIpcInterface.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAIH,gBAAgB;AAChB,MAAM,CAAC,MAAM,6BAA6B,GAAG,oCAAoC,CAAC;AAyBlF,gBAAgB;AAChB,MAAM,CAAN,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B;;OAEG;IACH,yDAAgC,CAAA;AAClC,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { RulesetVariableJSON } from \"./RulesetVariables.js\";\r\n\r\n/** @internal */\r\nexport const PRESENTATION_IPC_CHANNEL_NAME = \"itwinjs-presentation/ipc-interface\";\r\n\r\ninterface CommonIpcParams {\r\n clientId: string;\r\n}\r\n\r\ninterface SetRulesetVariableParams<TVariable> extends CommonIpcParams {\r\n rulesetId: string;\r\n variable: TVariable;\r\n}\r\n\r\ninterface UnsetRulesetVariableParams extends CommonIpcParams {\r\n rulesetId: string;\r\n variableId: string;\r\n}\r\n\r\n/** @internal */\r\nexport interface PresentationIpcInterface {\r\n /** Sets ruleset variable value. */\r\n setRulesetVariable(params: SetRulesetVariableParams<RulesetVariableJSON>): Promise<void>;\r\n\r\n /** Unsets ruleset variable value. */\r\n unsetRulesetVariable(params: UnsetRulesetVariableParams): Promise<void>;\r\n}\r\n\r\n/** @internal */\r\nexport enum PresentationIpcEvents {\r\n /**\r\n * ID of an event that's emitted when backend detects changes in presented data.\r\n */\r\n Update = \"presentation.onUpdate\",\r\n}\r\n"]}
@@ -152,7 +152,7 @@ export interface DistinctValuesRequestOptions<TIModel, TDescriptor, TKeySet, TRu
152
152
  /**
153
153
  * Request type for element properties requests
154
154
  * @public
155
- * @deprecated in 4.x. Use [[SingleElementPropertiesRequestOptions]] or [[MultiElementPropertiesRequestOptions]] directly.
155
+ * @deprecated in 4.4.0 - will not be removed until after 2026-06-13. Use [[SingleElementPropertiesRequestOptions]] or [[MultiElementPropertiesRequestOptions]] directly.
156
156
  */
157
157
  export type ElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> = SingleElementPropertiesRequestOptions<TIModel> | MultiElementPropertiesRequestOptions<TIModel, TParsedContent>;
158
158
  /**
@@ -244,14 +244,14 @@ export interface DisplayLabelsRequestOptions<TIModel, TInstanceKey> extends Requ
244
244
  /**
245
245
  * Request options used for selection scope related requests
246
246
  * @public
247
- * @deprecated in 5.0. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.
247
+ * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.
248
248
  */
249
249
  export interface SelectionScopeRequestOptions<TIModel> extends RequestOptions<TIModel> {
250
250
  }
251
251
  /**
252
252
  * Request options used for calculating selection based on given instance keys and selection scope.
253
253
  * @public
254
- * @deprecated in 5.0. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.
254
+ * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.
255
255
  */
256
256
  export interface ComputeSelectionRequestOptions<TIModel> extends RequestOptions<TIModel> {
257
257
  elementIds: Id64String[];
@@ -1 +1 @@
1
- {"version":3,"file":"PresentationManagerOptions.js","sourceRoot":"","sources":["../../../src/presentation-common/PresentationManagerOptions.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAuVH;;;GAGG;AACH,MAAM,UAAU,uCAAuC,CACrD,OAAuH;IAEvH,OAAQ,OAA0D,CAAC,SAAS,KAAK,SAAS,CAAC;AAC7F,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 Core\n */\n\nimport { BeEvent, Id64String } from \"@itwin/core-bentley\";\nimport { UnitSystemKey } from \"@itwin/core-quantity\";\nimport { Descriptor, SelectionInfo } from \"./content/Descriptor.js\";\nimport { FieldDescriptor } from \"./content/Fields.js\";\nimport { Item } from \"./content/Item.js\";\nimport { InstanceKey } from \"./EC.js\";\nimport { ElementProperties } from \"./ElementProperties.js\";\nimport { InstanceFilterDefinition } from \"./InstanceFilterDefinition.js\";\nimport { Ruleset } from \"./rules/Ruleset.js\";\nimport { RulesetVariable } from \"./RulesetVariables.js\";\nimport { SelectionScopeProps } from \"./selection/SelectionScope.js\";\n\n/**\n * A generic request options type used for both hierarchy and content requests.\n * @public\n */\nexport interface RequestOptions<TIModel> {\n /** iModel to request data from */\n imodel: TIModel;\n\n /** Optional locale to use when formatting / localizing data */\n locale?: string;\n\n /**\n * Unit system to use when formatting property values with units. Default presentation\n * unit is used if unit system is not specified.\n */\n unitSystem?: UnitSystemKey;\n}\n\n/**\n * Options for requests that require presentation ruleset. Not\n * meant to be used directly, see one of the subclasses.\n *\n * @public\n */\nexport interface RequestOptionsWithRuleset<TIModel, TRulesetVariable = RulesetVariable> extends RequestOptions<TIModel> {\n /** Ruleset or id of the ruleset to use when requesting data */\n rulesetOrId: Ruleset | string;\n\n /** Ruleset variables to use when requesting data */\n rulesetVariables?: TRulesetVariable[];\n}\n\n/**\n * Request type for hierarchy requests.\n * @public\n */\nexport interface HierarchyRequestOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\n /** Key of the parent node to get children for */\n parentKey?: TNodeKey;\n\n /**\n * An instance filter that should be applied for this hierarchy level.\n *\n * **Note:** May only be used on hierarchy levels that support filtering - check [[NavNode.supportsFiltering]] before\n * requesting filtered children.\n */\n instanceFilter?: InstanceFilterDefinition;\n\n /**\n * A limit to how many instances at most should be loaded for a hierarchy level. If the limit is exceeded,\n * the request fails with [[PresentationError]] having [[PresentationStatus.ResultSetTooLarge]] error number.\n *\n * Specifying the limit is useful when creating unlimited size result sets is not meaningful - this allows the library\n * to return early as soon as the limit is reached, instead of creating a very large result that's possibly too large to\n * be useful to be displayed to end users.\n *\n * @see [Hierarchies' filtering and limiting]($docs/presentation/hierarchies/FilteringLimiting.md)\n */\n sizeLimit?: number;\n}\n\n/**\n * Params for hierarchy level descriptor requests.\n * @public\n */\nexport interface HierarchyLevelDescriptorRequestOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable>\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\n /** Key of the parent node to get hierarchy level descriptor for. */\n parentKey?: TNodeKey;\n}\n\n/**\n * Request type of filtering hierarchies by given ECInstance paths.\n * @public\n */\nexport interface FilterByInstancePathsHierarchyRequestOptions<TIModel, TRulesetVariable = RulesetVariable>\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\n /** A list of paths from root ECInstance to target ECInstance. */\n instancePaths: InstanceKey[][];\n\n /**\n * An optional index (`0 <= markedIndex < instancePaths.length`) to mark one of the instance paths. The\n * path is marked using `NodePathElement.isMarked` flag in the result.\n */\n markedIndex?: number;\n}\n\n/**\n * Request type of filtering hierarchies by given text.\n * @public\n */\nexport interface FilterByTextHierarchyRequestOptions<TIModel, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\n /** Text to filter the hierarchy by. */\n filterText: string;\n}\n\n/**\n * Request type for content sources requests.\n * @public\n */\nexport interface ContentSourcesRequestOptions<TIModel> extends RequestOptions<TIModel> {\n /** Full names of classes to get content sources for. Format for a full class name: `SchemaName:ClassName`. */\n classes: string[];\n}\n\n/**\n * Request type for content descriptor requests.\n * @public\n */\nexport interface ContentDescriptorRequestOptions<TIModel, TKeySet, TRulesetVariable = RulesetVariable>\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\n /**\n * Content display type.\n * @see [[DefaultContentDisplayTypes]]\n */\n displayType: string;\n /**\n * Content flags used for content customization.\n * @see [[ContentFlags]]\n */\n contentFlags?: number;\n /** Input keys for getting the content */\n keys: TKeySet;\n /** Information about the selection event that was the cause of this content request */\n selection?: SelectionInfo;\n}\n\n/**\n * Request type for content requests.\n * @public\n */\nexport interface ContentRequestOptions<TIModel, TDescriptor, TKeySet, TRulesetVariable = RulesetVariable>\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\n /** Content descriptor for customizing the returned content */\n descriptor: TDescriptor;\n /** Input keys for getting the content */\n keys: TKeySet;\n /**\n * Flag that specifies whether value formatting should be omitted or not.\n * Content is returned without `displayValues` when this is set to `true`.\n */\n omitFormattedValues?: boolean;\n}\n\n/**\n * Request type for distinct values' requests.\n * @public\n */\nexport interface DistinctValuesRequestOptions<TIModel, TDescriptor, TKeySet, TRulesetVariable = RulesetVariable>\n extends Paged<RequestOptionsWithRuleset<TIModel, TRulesetVariable>> {\n /** Content descriptor for customizing the returned content */\n descriptor: TDescriptor;\n /** Input keys for getting the content */\n keys: TKeySet;\n /** Descriptor for a field distinct values are requested for */\n fieldDescriptor: FieldDescriptor;\n}\n\n/**\n * Request type for element properties requests\n * @public\n * @deprecated in 4.x. Use [[SingleElementPropertiesRequestOptions]] or [[MultiElementPropertiesRequestOptions]] directly.\n */\nexport type ElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> =\n | SingleElementPropertiesRequestOptions<TIModel>\n | MultiElementPropertiesRequestOptions<TIModel, TParsedContent>;\n\n/**\n * Request type for single element properties requests.\n * @public\n */\nexport interface SingleElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> extends RequestOptions<TIModel> {\n /** ID of the element to get properties for. */\n elementId: Id64String;\n\n /**\n * Content parser that creates a result item based on given content descriptor and content item. Defaults\n * to a parser that creates [[ElementProperties]] objects.\n */\n contentParser?: (descriptor: Descriptor, item: Item) => TParsedContent;\n}\n\n/**\n * Base request type for multiple elements properties requests.\n * @public\n */\nexport interface MultiElementPropertiesBaseRequestOptions<TIModel, TParsedContent = ElementProperties> extends RequestOptions<TIModel> {\n /**\n * Content parser that creates a result item based on given content descriptor and content item. Defaults\n * to a parser that creates [[ElementProperties]] objects.\n */\n contentParser?: (descriptor: Descriptor, item: Item) => TParsedContent;\n\n /**\n * The properties of multiple elements are going to be retrieved and returned in batches. Depending on the batch\n * size load on CPU vs MEMORY load may vary, so changing this attribute allows to fine tune the performance.\n * Defaults to `1000`.\n */\n batchSize?: number;\n}\n/**\n * Request type for multiple elements properties requests, where elements are specified by class.\n * @public\n */\nexport interface MultiElementPropertiesByClassRequestOptions<TIModel, TParsedContent = ElementProperties>\n extends MultiElementPropertiesBaseRequestOptions<TIModel, TParsedContent> {\n /**\n * Classes of the elements to get properties for. If [[elementClasses]] is `undefined`, all classes\n * are used. Classes should be specified in one of these formats: \"<schema name or alias>.<class_name>\" or\n * \"<schema name or alias>:<class_name>\".\n */\n elementClasses?: string[];\n}\n/**\n * Request type for multiple elements properties requests, where elements are specified by element id.\n * @public\n */\nexport interface MultiElementPropertiesByIdsRequestOptions<TIModel, TParsedContent = ElementProperties>\n extends MultiElementPropertiesBaseRequestOptions<TIModel, TParsedContent> {\n /**\n * A list of `bis.Element` IDs to get properties for.\n */\n elementIds?: Id64String[];\n}\n/**\n * Request type for multiple elements properties requests.\n * @public\n */\nexport type MultiElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> =\n | MultiElementPropertiesByClassRequestOptions<TIModel, TParsedContent>\n | MultiElementPropertiesByIdsRequestOptions<TIModel, TParsedContent>;\n\n/**\n * Request type for content instance keys' requests.\n * @public\n */\nexport interface ContentInstanceKeysRequestOptions<TIModel, TKeySet, TRulesetVariable = RulesetVariable>\n extends Paged<RequestOptionsWithRuleset<TIModel, TRulesetVariable>> {\n /**\n * Content display type.\n * @see [[DefaultContentDisplayTypes]]\n */\n displayType?: string;\n /** Input keys for getting the content. */\n keys: TKeySet;\n}\n\n/**\n * Request type for label requests\n * @public\n */\nexport interface DisplayLabelRequestOptions<TIModel, TInstanceKey> extends RequestOptions<TIModel> {\n /** Key of ECInstance to get label for */\n key: TInstanceKey;\n}\n\n/**\n * Request type for labels requests\n * @public\n */\nexport interface DisplayLabelsRequestOptions<TIModel, TInstanceKey> extends RequestOptions<TIModel> {\n /** Keys of ECInstances to get labels for */\n keys: TInstanceKey[];\n}\n\n/**\n * Request options used for selection scope related requests\n * @public\n * @deprecated in 5.0. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.\n */\nexport interface SelectionScopeRequestOptions<TIModel> extends RequestOptions<TIModel> {} // eslint-disable-line @typescript-eslint/no-empty-object-type\n\n/**\n * Request options used for calculating selection based on given instance keys and selection scope.\n * @public\n * @deprecated in 5.0. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.\n */\nexport interface ComputeSelectionRequestOptions<TIModel> extends RequestOptions<TIModel> {\n elementIds: Id64String[];\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n scope: SelectionScopeProps;\n}\n\n/**\n * Data structure for comparing a hierarchy after ruleset or ruleset variable changes.\n * @public\n */\nexport interface HierarchyCompareOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\n prev: {\n rulesetOrId?: Ruleset | string;\n rulesetVariables?: TRulesetVariable[];\n };\n expandedNodeKeys?: TNodeKey[];\n continuationToken?: {\n prevHierarchyNode: string;\n currHierarchyNode: string;\n };\n resultSetSize?: number;\n}\n\n/**\n * Paging options\n * @public\n */\nexport interface PageOptions {\n /** Inclusive start 0-based index of the page */\n start?: number;\n /** Maximum size of the page */\n size?: number;\n}\n\n/**\n * A wrapper type that injects [[PageOptions]] into supplied type\n * @public\n */\nexport type Paged<TOptions extends object> = TOptions & {\n /** Optional paging parameters */\n paging?: PageOptions;\n};\n\n/**\n * A wrapper type that injects priority into supplied type.\n * @public\n */\nexport type Prioritized<TOptions extends object> = TOptions & {\n /** Optional priority */\n priority?: number;\n};\n\n/**\n * Checks if supplied request options are for single or multiple element properties.\n * @internal\n */\nexport function isSingleElementPropertiesRequestOptions<TIModel, TParsedContent = any>(\n options: SingleElementPropertiesRequestOptions<TIModel> | MultiElementPropertiesRequestOptions<TIModel, TParsedContent>,\n): options is SingleElementPropertiesRequestOptions<TIModel> {\n return (options as SingleElementPropertiesRequestOptions<TIModel>).elementId !== undefined;\n}\n\n/**\n * A wrapper type that injects cancelEvent into supplied type.\n * @public\n */\nexport type WithCancelEvent<TOptions extends object> = TOptions & {\n /** Event which is triggered when the request is canceled */\n cancelEvent?: BeEvent<() => void>;\n};\n"]}
1
+ {"version":3,"file":"PresentationManagerOptions.js","sourceRoot":"","sources":["../../../src/presentation-common/PresentationManagerOptions.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAuVH;;;GAGG;AACH,MAAM,UAAU,uCAAuC,CACrD,OAAuH;IAEvH,OAAQ,OAA0D,CAAC,SAAS,KAAK,SAAS,CAAC;AAC7F,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { BeEvent, Id64String } from \"@itwin/core-bentley\";\r\nimport { UnitSystemKey } from \"@itwin/core-quantity\";\r\nimport { Descriptor, SelectionInfo } from \"./content/Descriptor.js\";\r\nimport { FieldDescriptor } from \"./content/Fields.js\";\r\nimport { Item } from \"./content/Item.js\";\r\nimport { InstanceKey } from \"./EC.js\";\r\nimport { ElementProperties } from \"./ElementProperties.js\";\r\nimport { InstanceFilterDefinition } from \"./InstanceFilterDefinition.js\";\r\nimport { Ruleset } from \"./rules/Ruleset.js\";\r\nimport { RulesetVariable } from \"./RulesetVariables.js\";\r\nimport { SelectionScopeProps } from \"./selection/SelectionScope.js\";\r\n\r\n/**\r\n * A generic request options type used for both hierarchy and content requests.\r\n * @public\r\n */\r\nexport interface RequestOptions<TIModel> {\r\n /** iModel to request data from */\r\n imodel: TIModel;\r\n\r\n /** Optional locale to use when formatting / localizing data */\r\n locale?: string;\r\n\r\n /**\r\n * Unit system to use when formatting property values with units. Default presentation\r\n * unit is used if unit system is not specified.\r\n */\r\n unitSystem?: UnitSystemKey;\r\n}\r\n\r\n/**\r\n * Options for requests that require presentation ruleset. Not\r\n * meant to be used directly, see one of the subclasses.\r\n *\r\n * @public\r\n */\r\nexport interface RequestOptionsWithRuleset<TIModel, TRulesetVariable = RulesetVariable> extends RequestOptions<TIModel> {\r\n /** Ruleset or id of the ruleset to use when requesting data */\r\n rulesetOrId: Ruleset | string;\r\n\r\n /** Ruleset variables to use when requesting data */\r\n rulesetVariables?: TRulesetVariable[];\r\n}\r\n\r\n/**\r\n * Request type for hierarchy requests.\r\n * @public\r\n */\r\nexport interface HierarchyRequestOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\r\n /** Key of the parent node to get children for */\r\n parentKey?: TNodeKey;\r\n\r\n /**\r\n * An instance filter that should be applied for this hierarchy level.\r\n *\r\n * **Note:** May only be used on hierarchy levels that support filtering - check [[NavNode.supportsFiltering]] before\r\n * requesting filtered children.\r\n */\r\n instanceFilter?: InstanceFilterDefinition;\r\n\r\n /**\r\n * A limit to how many instances at most should be loaded for a hierarchy level. If the limit is exceeded,\r\n * the request fails with [[PresentationError]] having [[PresentationStatus.ResultSetTooLarge]] error number.\r\n *\r\n * Specifying the limit is useful when creating unlimited size result sets is not meaningful - this allows the library\r\n * to return early as soon as the limit is reached, instead of creating a very large result that's possibly too large to\r\n * be useful to be displayed to end users.\r\n *\r\n * @see [Hierarchies' filtering and limiting]($docs/presentation/hierarchies/FilteringLimiting.md)\r\n */\r\n sizeLimit?: number;\r\n}\r\n\r\n/**\r\n * Params for hierarchy level descriptor requests.\r\n * @public\r\n */\r\nexport interface HierarchyLevelDescriptorRequestOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable>\r\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\r\n /** Key of the parent node to get hierarchy level descriptor for. */\r\n parentKey?: TNodeKey;\r\n}\r\n\r\n/**\r\n * Request type of filtering hierarchies by given ECInstance paths.\r\n * @public\r\n */\r\nexport interface FilterByInstancePathsHierarchyRequestOptions<TIModel, TRulesetVariable = RulesetVariable>\r\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\r\n /** A list of paths from root ECInstance to target ECInstance. */\r\n instancePaths: InstanceKey[][];\r\n\r\n /**\r\n * An optional index (`0 <= markedIndex < instancePaths.length`) to mark one of the instance paths. The\r\n * path is marked using `NodePathElement.isMarked` flag in the result.\r\n */\r\n markedIndex?: number;\r\n}\r\n\r\n/**\r\n * Request type of filtering hierarchies by given text.\r\n * @public\r\n */\r\nexport interface FilterByTextHierarchyRequestOptions<TIModel, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\r\n /** Text to filter the hierarchy by. */\r\n filterText: string;\r\n}\r\n\r\n/**\r\n * Request type for content sources requests.\r\n * @public\r\n */\r\nexport interface ContentSourcesRequestOptions<TIModel> extends RequestOptions<TIModel> {\r\n /** Full names of classes to get content sources for. Format for a full class name: `SchemaName:ClassName`. */\r\n classes: string[];\r\n}\r\n\r\n/**\r\n * Request type for content descriptor requests.\r\n * @public\r\n */\r\nexport interface ContentDescriptorRequestOptions<TIModel, TKeySet, TRulesetVariable = RulesetVariable>\r\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\r\n /**\r\n * Content display type.\r\n * @see [[DefaultContentDisplayTypes]]\r\n */\r\n displayType: string;\r\n /**\r\n * Content flags used for content customization.\r\n * @see [[ContentFlags]]\r\n */\r\n contentFlags?: number;\r\n /** Input keys for getting the content */\r\n keys: TKeySet;\r\n /** Information about the selection event that was the cause of this content request */\r\n selection?: SelectionInfo;\r\n}\r\n\r\n/**\r\n * Request type for content requests.\r\n * @public\r\n */\r\nexport interface ContentRequestOptions<TIModel, TDescriptor, TKeySet, TRulesetVariable = RulesetVariable>\r\n extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\r\n /** Content descriptor for customizing the returned content */\r\n descriptor: TDescriptor;\r\n /** Input keys for getting the content */\r\n keys: TKeySet;\r\n /**\r\n * Flag that specifies whether value formatting should be omitted or not.\r\n * Content is returned without `displayValues` when this is set to `true`.\r\n */\r\n omitFormattedValues?: boolean;\r\n}\r\n\r\n/**\r\n * Request type for distinct values' requests.\r\n * @public\r\n */\r\nexport interface DistinctValuesRequestOptions<TIModel, TDescriptor, TKeySet, TRulesetVariable = RulesetVariable>\r\n extends Paged<RequestOptionsWithRuleset<TIModel, TRulesetVariable>> {\r\n /** Content descriptor for customizing the returned content */\r\n descriptor: TDescriptor;\r\n /** Input keys for getting the content */\r\n keys: TKeySet;\r\n /** Descriptor for a field distinct values are requested for */\r\n fieldDescriptor: FieldDescriptor;\r\n}\r\n\r\n/**\r\n * Request type for element properties requests\r\n * @public\r\n * @deprecated in 4.4.0 - will not be removed until after 2026-06-13. Use [[SingleElementPropertiesRequestOptions]] or [[MultiElementPropertiesRequestOptions]] directly.\r\n */\r\nexport type ElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> =\r\n | SingleElementPropertiesRequestOptions<TIModel>\r\n | MultiElementPropertiesRequestOptions<TIModel, TParsedContent>;\r\n\r\n/**\r\n * Request type for single element properties requests.\r\n * @public\r\n */\r\nexport interface SingleElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> extends RequestOptions<TIModel> {\r\n /** ID of the element to get properties for. */\r\n elementId: Id64String;\r\n\r\n /**\r\n * Content parser that creates a result item based on given content descriptor and content item. Defaults\r\n * to a parser that creates [[ElementProperties]] objects.\r\n */\r\n contentParser?: (descriptor: Descriptor, item: Item) => TParsedContent;\r\n}\r\n\r\n/**\r\n * Base request type for multiple elements properties requests.\r\n * @public\r\n */\r\nexport interface MultiElementPropertiesBaseRequestOptions<TIModel, TParsedContent = ElementProperties> extends RequestOptions<TIModel> {\r\n /**\r\n * Content parser that creates a result item based on given content descriptor and content item. Defaults\r\n * to a parser that creates [[ElementProperties]] objects.\r\n */\r\n contentParser?: (descriptor: Descriptor, item: Item) => TParsedContent;\r\n\r\n /**\r\n * The properties of multiple elements are going to be retrieved and returned in batches. Depending on the batch\r\n * size load on CPU vs MEMORY load may vary, so changing this attribute allows to fine tune the performance.\r\n * Defaults to `1000`.\r\n */\r\n batchSize?: number;\r\n}\r\n/**\r\n * Request type for multiple elements properties requests, where elements are specified by class.\r\n * @public\r\n */\r\nexport interface MultiElementPropertiesByClassRequestOptions<TIModel, TParsedContent = ElementProperties>\r\n extends MultiElementPropertiesBaseRequestOptions<TIModel, TParsedContent> {\r\n /**\r\n * Classes of the elements to get properties for. If [[elementClasses]] is `undefined`, all classes\r\n * are used. Classes should be specified in one of these formats: \"<schema name or alias>.<class_name>\" or\r\n * \"<schema name or alias>:<class_name>\".\r\n */\r\n elementClasses?: string[];\r\n}\r\n/**\r\n * Request type for multiple elements properties requests, where elements are specified by element id.\r\n * @public\r\n */\r\nexport interface MultiElementPropertiesByIdsRequestOptions<TIModel, TParsedContent = ElementProperties>\r\n extends MultiElementPropertiesBaseRequestOptions<TIModel, TParsedContent> {\r\n /**\r\n * A list of `bis.Element` IDs to get properties for.\r\n */\r\n elementIds?: Id64String[];\r\n}\r\n/**\r\n * Request type for multiple elements properties requests.\r\n * @public\r\n */\r\nexport type MultiElementPropertiesRequestOptions<TIModel, TParsedContent = ElementProperties> =\r\n | MultiElementPropertiesByClassRequestOptions<TIModel, TParsedContent>\r\n | MultiElementPropertiesByIdsRequestOptions<TIModel, TParsedContent>;\r\n\r\n/**\r\n * Request type for content instance keys' requests.\r\n * @public\r\n */\r\nexport interface ContentInstanceKeysRequestOptions<TIModel, TKeySet, TRulesetVariable = RulesetVariable>\r\n extends Paged<RequestOptionsWithRuleset<TIModel, TRulesetVariable>> {\r\n /**\r\n * Content display type.\r\n * @see [[DefaultContentDisplayTypes]]\r\n */\r\n displayType?: string;\r\n /** Input keys for getting the content. */\r\n keys: TKeySet;\r\n}\r\n\r\n/**\r\n * Request type for label requests\r\n * @public\r\n */\r\nexport interface DisplayLabelRequestOptions<TIModel, TInstanceKey> extends RequestOptions<TIModel> {\r\n /** Key of ECInstance to get label for */\r\n key: TInstanceKey;\r\n}\r\n\r\n/**\r\n * Request type for labels requests\r\n * @public\r\n */\r\nexport interface DisplayLabelsRequestOptions<TIModel, TInstanceKey> extends RequestOptions<TIModel> {\r\n /** Keys of ECInstances to get labels for */\r\n keys: TInstanceKey[];\r\n}\r\n\r\n/**\r\n * Request options used for selection scope related requests\r\n * @public\r\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.\r\n */\r\nexport interface SelectionScopeRequestOptions<TIModel> extends RequestOptions<TIModel> {} // eslint-disable-line @typescript-eslint/no-empty-object-type\r\n\r\n/**\r\n * Request options used for calculating selection based on given instance keys and selection scope.\r\n * @public\r\n * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `computeSelection` from [@itwin/unified-selection](https://github.com/iTwin/presentation/blob/master/packages/unified-selection/README.md#selection-scopes) package instead.\r\n */\r\nexport interface ComputeSelectionRequestOptions<TIModel> extends RequestOptions<TIModel> {\r\n elementIds: Id64String[];\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n scope: SelectionScopeProps;\r\n}\r\n\r\n/**\r\n * Data structure for comparing a hierarchy after ruleset or ruleset variable changes.\r\n * @public\r\n */\r\nexport interface HierarchyCompareOptions<TIModel, TNodeKey, TRulesetVariable = RulesetVariable> extends RequestOptionsWithRuleset<TIModel, TRulesetVariable> {\r\n prev: {\r\n rulesetOrId?: Ruleset | string;\r\n rulesetVariables?: TRulesetVariable[];\r\n };\r\n expandedNodeKeys?: TNodeKey[];\r\n continuationToken?: {\r\n prevHierarchyNode: string;\r\n currHierarchyNode: string;\r\n };\r\n resultSetSize?: number;\r\n}\r\n\r\n/**\r\n * Paging options\r\n * @public\r\n */\r\nexport interface PageOptions {\r\n /** Inclusive start 0-based index of the page */\r\n start?: number;\r\n /** Maximum size of the page */\r\n size?: number;\r\n}\r\n\r\n/**\r\n * A wrapper type that injects [[PageOptions]] into supplied type\r\n * @public\r\n */\r\nexport type Paged<TOptions extends object> = TOptions & {\r\n /** Optional paging parameters */\r\n paging?: PageOptions;\r\n};\r\n\r\n/**\r\n * A wrapper type that injects priority into supplied type.\r\n * @public\r\n */\r\nexport type Prioritized<TOptions extends object> = TOptions & {\r\n /** Optional priority */\r\n priority?: number;\r\n};\r\n\r\n/**\r\n * Checks if supplied request options are for single or multiple element properties.\r\n * @internal\r\n */\r\nexport function isSingleElementPropertiesRequestOptions<TIModel, TParsedContent = any>(\r\n options: SingleElementPropertiesRequestOptions<TIModel> | MultiElementPropertiesRequestOptions<TIModel, TParsedContent>,\r\n): options is SingleElementPropertiesRequestOptions<TIModel> {\r\n return (options as SingleElementPropertiesRequestOptions<TIModel>).elementId !== undefined;\r\n}\r\n\r\n/**\r\n * A wrapper type that injects cancelEvent into supplied type.\r\n * @public\r\n */\r\nexport type WithCancelEvent<TOptions extends object> = TOptions & {\r\n /** Event which is triggered when the request is canceled */\r\n cancelEvent?: BeEvent<() => void>;\r\n};\r\n"]}