@itwin/imodel-components-react 4.13.3 → 4.14.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 (206) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/lib/cjs/imodel-components-react/UiIModelComponents.d.ts.map +1 -1
  3. package/lib/cjs/imodel-components-react/UiIModelComponents.js +1 -2
  4. package/lib/cjs/imodel-components-react/UiIModelComponents.js.map +1 -1
  5. package/lib/cjs/imodel-components-react/color/AlphaSlider.d.ts.map +1 -1
  6. package/lib/cjs/imodel-components-react/color/AlphaSlider.js +0 -16
  7. package/lib/cjs/imodel-components-react/color/AlphaSlider.js.map +1 -1
  8. package/lib/cjs/imodel-components-react/color/ColorPickerButton.d.ts +1 -1
  9. package/lib/cjs/imodel-components-react/color/ColorPickerButton.d.ts.map +1 -1
  10. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js +0 -1
  11. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  12. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.d.ts.map +1 -1
  13. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js +0 -1
  14. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  15. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts +1 -1
  16. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts.map +1 -1
  17. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js +0 -4
  18. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  19. package/lib/cjs/imodel-components-react/color/HueSlider.d.ts.map +1 -1
  20. package/lib/cjs/imodel-components-react/color/HueSlider.js +0 -21
  21. package/lib/cjs/imodel-components-react/color/HueSlider.js.map +1 -1
  22. package/lib/cjs/imodel-components-react/color/SaturationPicker.d.ts.map +1 -1
  23. package/lib/cjs/imodel-components-react/color/SaturationPicker.js +0 -25
  24. package/lib/cjs/imodel-components-react/color/SaturationPicker.js.map +1 -1
  25. package/lib/cjs/imodel-components-react/color/Swatch.d.ts.map +1 -1
  26. package/lib/cjs/imodel-components-react/color/Swatch.js +0 -1
  27. package/lib/cjs/imodel-components-react/color/Swatch.js.map +1 -1
  28. package/lib/cjs/imodel-components-react/editors/ColorEditor.d.ts.map +1 -1
  29. package/lib/cjs/imodel-components-react/editors/ColorEditor.js +2 -13
  30. package/lib/cjs/imodel-components-react/editors/ColorEditor.js.map +1 -1
  31. package/lib/cjs/imodel-components-react/editors/WeightEditor.d.ts.map +1 -1
  32. package/lib/cjs/imodel-components-react/editors/WeightEditor.js +2 -11
  33. package/lib/cjs/imodel-components-react/editors/WeightEditor.js.map +1 -1
  34. package/lib/cjs/imodel-components-react/inputs/QuantityInput.d.ts.map +1 -1
  35. package/lib/cjs/imodel-components-react/inputs/QuantityInput.js +0 -6
  36. package/lib/cjs/imodel-components-react/inputs/QuantityInput.js.map +1 -1
  37. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.d.ts +1 -1
  38. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  39. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js +1 -15
  40. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  41. package/lib/cjs/imodel-components-react/lineweight/Swatch.d.ts.map +1 -1
  42. package/lib/cjs/imodel-components-react/lineweight/Swatch.js +0 -1
  43. package/lib/cjs/imodel-components-react/lineweight/Swatch.js.map +1 -1
  44. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.d.ts.map +1 -1
  45. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.js +0 -9
  46. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.js.map +1 -1
  47. package/lib/cjs/imodel-components-react/navigationaids/Cube.d.ts.map +1 -1
  48. package/lib/cjs/imodel-components-react/navigationaids/Cube.js +0 -1
  49. package/lib/cjs/imodel-components-react/navigationaids/Cube.js.map +1 -1
  50. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.d.ts.map +1 -1
  51. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js +1 -27
  52. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  53. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.d.ts.map +1 -1
  54. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.js +9 -34
  55. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.js.map +1 -1
  56. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.d.ts.map +1 -1
  57. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js +0 -1
  58. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  59. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.d.ts.map +1 -1
  60. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js +2 -6
  61. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  62. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.d.ts.map +1 -1
  63. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js +2 -12
  64. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  65. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.d.ts.map +1 -1
  66. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js +2 -7
  67. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
  68. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  69. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js +0 -7
  70. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  71. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.d.ts.map +1 -1
  72. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +0 -1
  73. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  74. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.d.ts.map +1 -1
  75. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js +0 -1
  76. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  77. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.d.ts.map +1 -1
  78. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +2 -5
  79. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  80. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.d.ts.map +1 -1
  81. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js +6 -12
  82. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  83. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.d.ts.map +1 -1
  84. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.js +0 -1
  85. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.js.map +1 -1
  86. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.d.ts.map +1 -1
  87. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.js +2 -10
  88. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.js.map +1 -1
  89. package/lib/cjs/imodel-components-react/timeline/InlineEdit.d.ts.map +1 -1
  90. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js +0 -2
  91. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  92. package/lib/cjs/imodel-components-react/timeline/Scrubber.d.ts.map +1 -1
  93. package/lib/cjs/imodel-components-react/timeline/Scrubber.js +0 -6
  94. package/lib/cjs/imodel-components-react/timeline/Scrubber.js.map +1 -1
  95. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.d.ts.map +1 -1
  96. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.js +0 -1
  97. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.js.map +1 -1
  98. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  99. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js +0 -17
  100. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  101. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.d.ts.map +1 -1
  102. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js +0 -1
  103. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  104. package/lib/esm/imodel-components-react/UiIModelComponents.d.ts.map +1 -1
  105. package/lib/esm/imodel-components-react/UiIModelComponents.js +1 -2
  106. package/lib/esm/imodel-components-react/UiIModelComponents.js.map +1 -1
  107. package/lib/esm/imodel-components-react/color/AlphaSlider.d.ts.map +1 -1
  108. package/lib/esm/imodel-components-react/color/AlphaSlider.js +0 -16
  109. package/lib/esm/imodel-components-react/color/AlphaSlider.js.map +1 -1
  110. package/lib/esm/imodel-components-react/color/ColorPickerButton.d.ts +1 -1
  111. package/lib/esm/imodel-components-react/color/ColorPickerButton.d.ts.map +1 -1
  112. package/lib/esm/imodel-components-react/color/ColorPickerButton.js +0 -1
  113. package/lib/esm/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  114. package/lib/esm/imodel-components-react/color/ColorPickerDialog.d.ts.map +1 -1
  115. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js +0 -1
  116. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  117. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts +1 -1
  118. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts.map +1 -1
  119. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js +0 -4
  120. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  121. package/lib/esm/imodel-components-react/color/HueSlider.d.ts.map +1 -1
  122. package/lib/esm/imodel-components-react/color/HueSlider.js +0 -21
  123. package/lib/esm/imodel-components-react/color/HueSlider.js.map +1 -1
  124. package/lib/esm/imodel-components-react/color/SaturationPicker.d.ts.map +1 -1
  125. package/lib/esm/imodel-components-react/color/SaturationPicker.js +0 -25
  126. package/lib/esm/imodel-components-react/color/SaturationPicker.js.map +1 -1
  127. package/lib/esm/imodel-components-react/color/Swatch.d.ts.map +1 -1
  128. package/lib/esm/imodel-components-react/color/Swatch.js +0 -1
  129. package/lib/esm/imodel-components-react/color/Swatch.js.map +1 -1
  130. package/lib/esm/imodel-components-react/editors/ColorEditor.d.ts.map +1 -1
  131. package/lib/esm/imodel-components-react/editors/ColorEditor.js +2 -13
  132. package/lib/esm/imodel-components-react/editors/ColorEditor.js.map +1 -1
  133. package/lib/esm/imodel-components-react/editors/WeightEditor.d.ts.map +1 -1
  134. package/lib/esm/imodel-components-react/editors/WeightEditor.js +2 -11
  135. package/lib/esm/imodel-components-react/editors/WeightEditor.js.map +1 -1
  136. package/lib/esm/imodel-components-react/inputs/QuantityInput.d.ts.map +1 -1
  137. package/lib/esm/imodel-components-react/inputs/QuantityInput.js +0 -6
  138. package/lib/esm/imodel-components-react/inputs/QuantityInput.js.map +1 -1
  139. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.d.ts +1 -1
  140. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  141. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js +1 -15
  142. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  143. package/lib/esm/imodel-components-react/lineweight/Swatch.d.ts.map +1 -1
  144. package/lib/esm/imodel-components-react/lineweight/Swatch.js +0 -1
  145. package/lib/esm/imodel-components-react/lineweight/Swatch.js.map +1 -1
  146. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.d.ts.map +1 -1
  147. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.js +0 -9
  148. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.js.map +1 -1
  149. package/lib/esm/imodel-components-react/navigationaids/Cube.d.ts.map +1 -1
  150. package/lib/esm/imodel-components-react/navigationaids/Cube.js +0 -1
  151. package/lib/esm/imodel-components-react/navigationaids/Cube.js.map +1 -1
  152. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.d.ts.map +1 -1
  153. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js +1 -27
  154. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  155. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.d.ts.map +1 -1
  156. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.js +9 -34
  157. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.js.map +1 -1
  158. package/lib/esm/imodel-components-react/quantityformat/FormatSample.d.ts.map +1 -1
  159. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js +0 -1
  160. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  161. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.d.ts.map +1 -1
  162. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js +2 -6
  163. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  164. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.d.ts.map +1 -1
  165. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js +2 -12
  166. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  167. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.d.ts.map +1 -1
  168. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js +2 -7
  169. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
  170. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  171. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js +0 -7
  172. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  173. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.d.ts.map +1 -1
  174. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +0 -1
  175. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  176. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.d.ts.map +1 -1
  177. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js +0 -1
  178. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  179. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.d.ts.map +1 -1
  180. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +2 -5
  181. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  182. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.d.ts.map +1 -1
  183. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js +6 -12
  184. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  185. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.d.ts.map +1 -1
  186. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.js +0 -1
  187. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.js.map +1 -1
  188. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.d.ts.map +1 -1
  189. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.js +2 -10
  190. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.js.map +1 -1
  191. package/lib/esm/imodel-components-react/timeline/InlineEdit.d.ts.map +1 -1
  192. package/lib/esm/imodel-components-react/timeline/InlineEdit.js +0 -2
  193. package/lib/esm/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  194. package/lib/esm/imodel-components-react/timeline/Scrubber.d.ts.map +1 -1
  195. package/lib/esm/imodel-components-react/timeline/Scrubber.js +0 -6
  196. package/lib/esm/imodel-components-react/timeline/Scrubber.js.map +1 -1
  197. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.d.ts.map +1 -1
  198. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.js +0 -1
  199. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.js.map +1 -1
  200. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  201. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js +0 -17
  202. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  203. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.d.ts.map +1 -1
  204. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js +0 -1
  205. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  206. package/package.json +13 -15
@@ -31,10 +31,8 @@ export class ColorEditor extends React.PureComponent {
31
31
  this.setState({
32
32
  colorValue: color.tbgr,
33
33
  }, async () => {
34
- // istanbul ignore else
35
34
  if (propertyRecord && this.props.onCommit) {
36
35
  const propertyValue = await this.getPropertyValue();
37
- // istanbul ignore else
38
36
  if (propertyValue !== undefined) {
39
37
  this.props.onCommit({ propertyRecord, newValue: propertyValue });
40
38
  }
@@ -45,7 +43,6 @@ export class ColorEditor extends React.PureComponent {
45
43
  async getPropertyValue() {
46
44
  const record = this.props.propertyRecord;
47
45
  let propertyValue;
48
- // istanbul ignore else
49
46
  if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
50
47
  propertyValue = {
51
48
  valueFormat: PropertyValueFormat.Primitive,
@@ -62,7 +59,6 @@ export class ColorEditor extends React.PureComponent {
62
59
  return document.activeElement === this._buttonElement.current;
63
60
  }
64
61
  setFocus() {
65
- // istanbul ignore else
66
62
  if (this._buttonElement &&
67
63
  this._buttonElement.current &&
68
64
  !this.state.isDisabled) {
@@ -81,25 +77,18 @@ export class ColorEditor extends React.PureComponent {
81
77
  }
82
78
  async setStateFromProps() {
83
79
  const record = this.props.propertyRecord;
84
- // istanbul ignore else
85
80
  if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
86
81
  const colorValue = record.value.value;
87
82
  let numColumns = 4;
88
83
  const availableColors = new Array();
89
- const readonly = record && undefined !== record.isReadonly
90
- ? record.isReadonly
91
- : /* istanbul ignore next */ false;
92
- const isDisabled = record
93
- ? record.isDisabled
94
- : /* istanbul ignore next */ undefined;
84
+ const readonly = record && undefined !== record.isReadonly ? record.isReadonly : false;
85
+ const isDisabled = record ? record.isDisabled : undefined;
95
86
  if (record.property.editor && record.property.editor.params) {
96
87
  const colorParams = record.property.editor.params.find((param) => param.type === PropertyEditorParamTypes.ColorData.valueOf());
97
- // istanbul ignore else
98
88
  if (colorParams) {
99
89
  colorParams.colorValues.forEach((colorNumber) => {
100
90
  availableColors.push(ColorDef.create(colorNumber));
101
91
  });
102
- // istanbul ignore else
103
92
  if (colorParams.numColumns)
104
93
  numColumns = colorParams.numColumns;
105
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ColorEditor.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/editors/ColorEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,oBAAoB,CAAC;AAC5B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAO9C,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAW/D;;GAEG;AACH,MAAM,OAAO,WACX,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AAiB,CAAC,8CAA8C;gBAC/D,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,YAAY,EAAE,QAAQ,EACtB,SAAS,EACP,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC;oBACnC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe;oBAC5B,CAAC,CAAC,CAAC,QAAQ,CAAC,EAEhB,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,EACjC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAC9C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,WAAW,EAAE,IAAI,CAAC,YAAY,iBAClB,yBAAyB,GACrC,CACE,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACzD,IAAW,SAAS;QAClB,OAAO,oBAAC,WAAW,OAAG,CAAC;IACzB,CAAC;CACF;AAED,qBAAqB,CAAC,cAAc,CAClC,iBAAiB,CAAC,MAAM,EACxB,mBAAmB,EACnB,mBAAmB,CAAC,WAAW,CAChC,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 PropertyEditors\n */\n\nimport \"./ColorEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { ColorDef } from \"@itwin/core-common\";\nimport type {\n ColorEditorParams,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n} from \"@itwin/appui-abstract\";\nimport type { PropertyEditorProps, TypeEditor } from \"@itwin/components-react\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"@itwin/components-react\";\nimport { ColorPickerButton } from \"../color/ColorPickerButton\";\n\n/** @internal */\ninterface ColorEditorState {\n colorValue: number;\n readonly: boolean;\n isDisabled?: boolean;\n numColumns: number;\n availableColors: ColorDef[];\n}\n\n/** ColorEditor React component that is a property editor with text input\n * @beta\n */\nexport class ColorEditor\n extends React.PureComponent<PropertyEditorProps, ColorEditorState>\n implements TypeEditor\n{\n private _buttonElement: React.RefObject<HTMLButtonElement> =\n React.createRef();\n\n /** @internal */\n public override readonly state: Readonly<ColorEditorState> = {\n colorValue: 0,\n readonly: false,\n numColumns: 4,\n availableColors: [],\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.colorValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._buttonElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._buttonElement.current;\n }\n\n private setFocus(): void {\n // istanbul ignore else\n if (\n this._buttonElement &&\n this._buttonElement.current &&\n !this.state.isDisabled\n ) {\n this._buttonElement.current.focus();\n }\n }\n\n private _onColorPick = (color: ColorDef) => {\n const propertyRecord = this.props.propertyRecord as PropertyRecord;\n\n this.setState(\n {\n colorValue: color.tbgr,\n },\n async () => {\n // istanbul ignore else\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n // istanbul ignore else\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n };\n\n /** @internal */\n public override componentDidMount() {\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const colorValue = record.value.value as number;\n let numColumns = 4;\n const availableColors = new Array<ColorDef>();\n const readonly =\n record && undefined !== record.isReadonly\n ? record.isReadonly\n : /* istanbul ignore next */ false;\n const isDisabled = record\n ? record.isDisabled\n : /* istanbul ignore next */ undefined;\n\n if (record.property.editor && record.property.editor.params) {\n const colorParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.ColorData.valueOf()\n ) as ColorEditorParams;\n // istanbul ignore else\n if (colorParams) {\n colorParams.colorValues.forEach((colorNumber: number) => {\n availableColors.push(ColorDef.create(colorNumber));\n });\n // istanbul ignore else\n if (colorParams.numColumns) numColumns = colorParams.numColumns;\n }\n }\n this.setState(\n { colorValue, readonly, isDisabled, numColumns, availableColors },\n () => {\n if (this.props.setFocus) {\n this.setFocus();\n }\n }\n );\n }\n }\n\n /** @internal */\n public override render() {\n const colorDef = ColorDef.create(this.state.colorValue);\n return (\n <div\n className={classnames(\"components-color-editor\", this.props.className)}\n style={this.props.style}\n >\n <ColorPickerButton // eslint-disable-line deprecation/deprecation\n ref={this._buttonElement}\n initialColor={colorDef}\n colorDefs={\n this.state.availableColors.length > 0\n ? this.state.availableColors\n : [colorDef]\n }\n numColumns={this.state.numColumns}\n disabled={this.state.isDisabled ? true : false}\n readonly={this.state.readonly}\n onColorPick={this._onColorPick}\n data-testid=\"components-color-editor\"\n />\n </div>\n );\n }\n}\n\n/** Color Property Editor registered for the \"number\" type name and \"color-picker\" editor name.\n * It uses the [[ColorEditor]] React component.\n * @beta\n */\nexport class ColorPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <ColorEditor />;\n }\n}\n\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n ColorPropertyEditor,\n StandardEditorNames.ColorPicker\n);\n"]}
1
+ {"version":3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E,CAAC;oBACxB,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClB,CAAC;YACH,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,gBAAgB;IACA,MAAM;QACpB,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACxD,OAAO,CACL,6BACE,SAAS,EAAE,UAAU,CAAC,yBAAyB,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EACtE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;YAEvB,oBAAC,iBAAiB,CAAC,8CAA8C;gBAC/D,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,YAAY,EAAE,QAAQ,EACtB,SAAS,EACP,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC;oBACnC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,eAAe;oBAC5B,CAAC,CAAC,CAAC,QAAQ,CAAC,EAEhB,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,EACjC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAC9C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,WAAW,EAAE,IAAI,CAAC,YAAY,iBAClB,yBAAyB,GACrC,CACE,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,kBAAkB;IACzD,IAAW,SAAS;QAClB,OAAO,oBAAC,WAAW,OAAG,CAAC;IACzB,CAAC;CACF;AAED,qBAAqB,CAAC,cAAc,CAClC,iBAAiB,CAAC,MAAM,EACxB,mBAAmB,EACnB,mBAAmB,CAAC,WAAW,CAChC,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 PropertyEditors\n */\n\nimport \"./ColorEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { ColorDef } from \"@itwin/core-common\";\nimport type {\n ColorEditorParams,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n PropertyEditorParamTypes,\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n} from \"@itwin/appui-abstract\";\nimport type { PropertyEditorProps, TypeEditor } from \"@itwin/components-react\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"@itwin/components-react\";\nimport { ColorPickerButton } from \"../color/ColorPickerButton\";\n\n/** @internal */\ninterface ColorEditorState {\n colorValue: number;\n readonly: boolean;\n isDisabled?: boolean;\n numColumns: number;\n availableColors: ColorDef[];\n}\n\n/** ColorEditor React component that is a property editor with text input\n * @beta\n */\nexport class ColorEditor\n extends React.PureComponent<PropertyEditorProps, ColorEditorState>\n implements TypeEditor\n{\n private _buttonElement: React.RefObject<HTMLButtonElement> =\n React.createRef();\n\n /** @internal */\n public override readonly state: Readonly<ColorEditorState> = {\n colorValue: 0,\n readonly: false,\n numColumns: 4,\n availableColors: [],\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.colorValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._buttonElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._buttonElement.current;\n }\n\n private setFocus(): void {\n if (\n this._buttonElement &&\n this._buttonElement.current &&\n !this.state.isDisabled\n ) {\n this._buttonElement.current.focus();\n }\n }\n\n private _onColorPick = (color: ColorDef) => {\n const propertyRecord = this.props.propertyRecord as PropertyRecord;\n\n this.setState(\n {\n colorValue: color.tbgr,\n },\n async () => {\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n };\n\n /** @internal */\n public override componentDidMount() {\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const colorValue = record.value.value as number;\n let numColumns = 4;\n const availableColors = new Array<ColorDef>();\n const readonly =\n record && undefined !== record.isReadonly ? record.isReadonly : false;\n const isDisabled = record ? record.isDisabled : undefined;\n\n if (record.property.editor && record.property.editor.params) {\n const colorParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.ColorData.valueOf()\n ) as ColorEditorParams;\n if (colorParams) {\n colorParams.colorValues.forEach((colorNumber: number) => {\n availableColors.push(ColorDef.create(colorNumber));\n });\n if (colorParams.numColumns) numColumns = colorParams.numColumns;\n }\n }\n this.setState(\n { colorValue, readonly, isDisabled, numColumns, availableColors },\n () => {\n if (this.props.setFocus) {\n this.setFocus();\n }\n }\n );\n }\n }\n\n /** @internal */\n public override render() {\n const colorDef = ColorDef.create(this.state.colorValue);\n return (\n <div\n className={classnames(\"components-color-editor\", this.props.className)}\n style={this.props.style}\n >\n <ColorPickerButton // eslint-disable-line deprecation/deprecation\n ref={this._buttonElement}\n initialColor={colorDef}\n colorDefs={\n this.state.availableColors.length > 0\n ? this.state.availableColors\n : [colorDef]\n }\n numColumns={this.state.numColumns}\n disabled={this.state.isDisabled ? true : false}\n readonly={this.state.readonly}\n onColorPick={this._onColorPick}\n data-testid=\"components-color-editor\"\n />\n </div>\n );\n }\n}\n\n/** Color Property Editor registered for the \"number\" type name and \"color-picker\" editor name.\n * It uses the [[ColorEditor]] React component.\n * @beta\n */\nexport class ColorPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <ColorEditor />;\n }\n}\n\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n ColorPropertyEditor,\n StandardEditorNames.ColorPicker\n);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"WeightEditor.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/editors/WeightEditor.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,qBAAqB,CAAC;AAE7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAM3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAEnB,MAAM,yBAAyB,CAAC;AAKjC,gBAAgB;AAChB,UAAU,iBAAiB;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,YACX,SAAQ,KAAK,CAAC,aAAa,CAAC,mBAAmB,EAAE,iBAAiB,CAClE,YAAW,UAAU;IAErB,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,WAAW,CAAqC;IAExD,gBAAgB;IAChB,SAAyB,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAGzD;gBAEU,KAAK,EAAE,mBAAmB;IAgBzB,gBAAgB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAgBnE,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,IAAW,QAAQ,IAAI,OAAO,C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E,IAAW,WAAW,IAAI,WAAW,GAAG,IAAI,CAE3C;IAED,IAAW,QAAQ,IAAI,OAAO,CAK7B;IAED,OAAO,CAAC,QAAQ;IAMhB,OAAO,CAAC,iBAAiB,CAgBvB;IAEF,gBAAgB;IACA,iBAAiB;IAKjC,gBAAgB;IACA,oBAAoB;IAIpC,gBAAgB;IACA,kBAAkB,CAAC,SAAS,EAAE,mBAAmB;YAMnD,iBAAiB;IAoB/B,gBAAgB;IACA,MAAM;CAuBvB;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,kBAAkB;IAC1D,IAAW,SAAS,IAAI,KAAK,CAAC,SAAS,CAEtC;CACF"}
@@ -31,10 +31,8 @@ export class WeightEditor extends React.PureComponent {
31
31
  this.setState({
32
32
  weightValue: weight,
33
33
  }, async () => {
34
- // istanbul ignore else
35
34
  if (propertyRecord && this.props.onCommit) {
36
35
  const propertyValue = await this.getPropertyValue();
37
- // istanbul ignore else
38
36
  if (propertyValue !== undefined) {
39
37
  this.props.onCommit({ propertyRecord, newValue: propertyValue });
40
38
  }
@@ -45,8 +43,7 @@ export class WeightEditor extends React.PureComponent {
45
43
  // const record = this.props.propertyRecord;
46
44
  // if (record && record.property && record.property.editor && record.property.editor.params) {
47
45
  // const weightParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.ColorData) as WeightEditorParams;
48
- // // istanbul ignore else
49
- // if (weightParams) {
46
+ // // if (weightParams) {
50
47
  // weightParams.weightValues.forEach((weight: number) => {
51
48
  // this._availableWeights.push(weight);
52
49
  // });
@@ -56,7 +53,6 @@ export class WeightEditor extends React.PureComponent {
56
53
  async getPropertyValue() {
57
54
  const record = this.props.propertyRecord;
58
55
  let propertyValue;
59
- // istanbul ignore else
60
56
  if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
61
57
  propertyValue = {
62
58
  valueFormat: PropertyValueFormat.Primitive,
@@ -71,13 +67,11 @@ export class WeightEditor extends React.PureComponent {
71
67
  }
72
68
  get hasFocus() {
73
69
  let containsFocus = false;
74
- // istanbul ignore else
75
70
  if (this._divElement.current)
76
71
  containsFocus = this._divElement.current.contains(document.activeElement);
77
72
  return containsFocus;
78
73
  }
79
74
  setFocus() {
80
- // istanbul ignore else
81
75
  if (this._control && !this.state.isDisabled) {
82
76
  this._control.setFocus();
83
77
  }
@@ -100,13 +94,11 @@ export class WeightEditor extends React.PureComponent {
100
94
  async setStateFromProps() {
101
95
  const record = this.props.propertyRecord;
102
96
  let initialValue = 0;
103
- // istanbul ignore else
104
97
  if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
105
98
  initialValue = record.value.value;
106
99
  }
107
100
  const readonly = record && undefined !== record.isReadonly ? record.isReadonly : false;
108
101
  const isDisabled = record ? record.isDisabled : undefined;
109
- // istanbul ignore else
110
102
  if (this._isMounted)
111
103
  this.setState({ weightValue: initialValue, readonly, isDisabled }, () => {
112
104
  if (this.props.setFocus) {
@@ -118,7 +110,7 @@ export class WeightEditor extends React.PureComponent {
118
110
  render() {
119
111
  return (React.createElement("div", { className: classnames("components-weight-editor", this.props.className), style: this.props.style, ref: this._divElement },
120
112
  React.createElement(WeightPickerButton, { ref: (control) => (this._control = control), activeWeight: this.state.weightValue, weights: this._availableWeights.length > 0
121
- ? /* istanbul ignore next */ this._availableWeights
113
+ ? this._availableWeights
122
114
  : undefined, disabled: this.state.isDisabled ? true : false, readonly: this.state.readonly, onLineWeightPick: this._onLineWeightPick, "data-testid": "components-weight-editor" })));
123
115
  }
124
116
  }
@@ -127,7 +119,6 @@ export class WeightEditor extends React.PureComponent {
127
119
  * @public
128
120
  */
129
121
  export class WeightPropertyEditor extends PropertyEditorBase {
130
- // istanbul ignore next
131
122
  get reactNode() {
132
123
  return React.createElement(WeightEditor, null);
133
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WeightEditor.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/editors/WeightEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAE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,KAAK,CAAC,KAAK,EACvB,GAAG,EAAE,IAAI,CAAC,WAAW;YAErB,oBAAC,kBAAkB,IACjB,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAC3C,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EACpC,OAAO,EACL,IAAI,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC;oBAC/B,CAAC,CAAC,0BAA0B,CAAC,IAAI,CAAC,iBAAiB;oBACnD,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAC9C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,gBAAgB,EAAE,IAAI,CAAC,iBAAiB,iBAC5B,0BAA0B,GACtC,CACE,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAC1D,uBAAuB;IACvB,IAAW,SAAS;QAClB,OAAO,oBAAC,YAAY,OAAG,CAAC;IAC1B,CAAC;CACF;AAED,qBAAqB,CAAC,cAAc,CAClC,iBAAiB,CAAC,MAAM,EACxB,oBAAoB,EACpB,mBAAmB,CAAC,YAAY,CACjC,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 PropertyEditors\n */\n\nimport \"./WeightEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { PropertyRecord, PropertyValue } from \"@itwin/appui-abstract\";\nimport {\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n} from \"@itwin/appui-abstract\";\nimport type { PropertyEditorProps, TypeEditor } from \"@itwin/components-react\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"@itwin/components-react\";\nimport { WeightPickerButton } from \"../lineweight/WeightPickerButton\";\n\n// cspell:ignore lineweight\n\n/** @internal */\ninterface WeightEditorState {\n weightValue: number;\n readonly: boolean;\n isDisabled?: boolean;\n}\n\n/** WeightEditor React component that is a property editor for picking a weight using a [[WeightPickerButton]] component\n * @public\n */\nexport class WeightEditor\n extends React.PureComponent<PropertyEditorProps, WeightEditorState>\n implements TypeEditor\n{\n private _control: any = null;\n private _isMounted = false;\n private _availableWeights: number[] = [];\n private _divElement = React.createRef<HTMLDivElement>();\n\n /** @internal */\n public override readonly state: Readonly<WeightEditorState> = {\n weightValue: 0,\n readonly: false,\n };\n\n constructor(props: PropertyEditorProps) {\n super(props);\n\n // TODO: add support for following if we need to specify set of weights to display\n // const record = this.props.propertyRecord;\n // if (record && record.property && record.property.editor && record.property.editor.params) {\n // const weightParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.ColorData) as WeightEditorParams;\n // // istanbul ignore else\n // if (weightParams) {\n // weightParams.weightValues.forEach((weight: number) => {\n // this._availableWeights.push(weight);\n // });\n // }\n // }\n }\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.weightValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n // istanbul ignore else\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n private setFocus(): void {\n // istanbul ignore else\n if (this._control && !this.state.isDisabled) {\n this._control.setFocus();\n }\n }\n\n private _onLineWeightPick = (weight: number) => {\n const propertyRecord = this.props.propertyRecord as PropertyRecord;\n\n this.setState(\n {\n weightValue: weight,\n },\n async () => {\n // istanbul ignore else\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n // istanbul ignore else\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n };\n\n /** @internal */\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n const readonly =\n record && undefined !== record.isReadonly ? record.isReadonly : false;\n const isDisabled = record ? record.isDisabled : undefined;\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({ weightValue: initialValue, readonly, isDisabled }, () => {\n if (this.props.setFocus) {\n this.setFocus();\n }\n });\n }\n\n /** @internal */\n public override render() {\n return (\n <div\n className={classnames(\"components-weight-editor\", this.props.className)}\n style={this.props.style}\n ref={this._divElement}\n >\n <WeightPickerButton\n ref={(control) => (this._control = control)}\n activeWeight={this.state.weightValue}\n weights={\n this._availableWeights.length > 0\n ? /* istanbul ignore next */ this._availableWeights\n : undefined\n }\n disabled={this.state.isDisabled ? true : false}\n readonly={this.state.readonly}\n onLineWeightPick={this._onLineWeightPick}\n data-testid=\"components-weight-editor\"\n />\n </div>\n );\n }\n}\n\n/** Weight Property Editor registered for the \"number\" type name and \"weight-picker\" editor name.\n * It uses the [[WeightEditor]] React component.\n * @public\n */\nexport class WeightPropertyEditor extends PropertyEditorBase {\n // istanbul ignore next\n public get reactNode(): React.ReactNode {\n return <WeightEditor />;\n }\n}\n\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n WeightPropertyEditor,\n StandardEditorNames.WeightPicker\n);\n"]}
1
+ {"version":3,"file":"WeightEditor.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/editors/WeightEditor.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,qBAAqB,CAAC;AAC7B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAWtE;;GAEG;AACH,MAAM,OAAO,YACX,SAAQ,KAAK,CAAC,aAAqD;IAcnE,YAAY,KAA0B;QACpC,KAAK,CAAC,KAAK,CAAC,CAAC;QAZP,aAAQ,GAAQ,IAAI,CAAC;QACrB,eAAU,GAAG,KAAK,CAAC;QACnB,sBAAiB,GAAa,EAAE,CAAC;QACjC,gBAAW,GAAG,KAAK,CAAC,SAAS,EAAkB,CAAC;QAExD,gBAAgB;QACS,UAAK,GAAgC;YAC5D,WAAW,EAAE,CAAC;YACd,QAAQ,EAAE,KAAK;SAChB,CAAC;QAiDM,sBAAiB,GAAG,CAAC,MAAc,EAAE,EAAE;YAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAgC,CAAC;YAEnE,IAAI,CAAC,QAAQ,CACX;gBACE,WAAW,EAAE,MAAM;aACpB,EACD,KAAK,IAAI,EAAE;gBACT,IAAI,cAAc,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;oBAC1C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACpD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;wBAChC,IAAI,CAAC,KA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,KAAK,CAAC,SAAS,CAAC,EACvE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,GAAG,EAAE,IAAI,CAAC,WAAW;YAErB,oBAAC,kBAAkB,IACjB,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAC3C,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EACpC,OAAO,EACL,IAAI,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC;oBAC/B,CAAC,CAAC,IAAI,CAAC,iBAAiB;oBACxB,CAAC,CAAC,SAAS,EAEf,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAC9C,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,gBAAgB,EAAE,IAAI,CAAC,iBAAiB,iBAC5B,0BAA0B,GACtC,CACE,CACP,CAAC;IACJ,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,kBAAkB;IAC1D,IAAW,SAAS;QAClB,OAAO,oBAAC,YAAY,OAAG,CAAC;IAC1B,CAAC;CACF;AAED,qBAAqB,CAAC,cAAc,CAClC,iBAAiB,CAAC,MAAM,EACxB,oBAAoB,EACpB,mBAAmB,CAAC,YAAY,CACjC,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 PropertyEditors\n */\n\nimport \"./WeightEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { PropertyRecord, PropertyValue } from \"@itwin/appui-abstract\";\nimport {\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n} from \"@itwin/appui-abstract\";\nimport type { PropertyEditorProps, TypeEditor } from \"@itwin/components-react\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"@itwin/components-react\";\nimport { WeightPickerButton } from \"../lineweight/WeightPickerButton\";\n\n// cspell:ignore lineweight\n\n/** @internal */\ninterface WeightEditorState {\n weightValue: number;\n readonly: boolean;\n isDisabled?: boolean;\n}\n\n/** WeightEditor React component that is a property editor for picking a weight using a [[WeightPickerButton]] component\n * @public\n */\nexport class WeightEditor\n extends React.PureComponent<PropertyEditorProps, WeightEditorState>\n implements TypeEditor\n{\n private _control: any = null;\n private _isMounted = false;\n private _availableWeights: number[] = [];\n private _divElement = React.createRef<HTMLDivElement>();\n\n /** @internal */\n public override readonly state: Readonly<WeightEditorState> = {\n weightValue: 0,\n readonly: false,\n };\n\n constructor(props: PropertyEditorProps) {\n super(props);\n\n // TODO: add support for following if we need to specify set of weights to display\n // const record = this.props.propertyRecord;\n // if (record && record.property && record.property.editor && record.property.editor.params) {\n // const weightParams = record.property.editor.params.find((param: PropertyEditorParams) => param.type === PropertyEditorParamTypes.ColorData) as WeightEditorParams;\n // // if (weightParams) {\n // weightParams.weightValues.forEach((weight: number) => {\n // this._availableWeights.push(weight);\n // });\n // }\n // }\n }\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: this.state.weightValue,\n displayValue: \"\",\n };\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._divElement.current;\n }\n\n public get hasFocus(): boolean {\n let containsFocus = false;\n if (this._divElement.current)\n containsFocus = this._divElement.current.contains(document.activeElement);\n return containsFocus;\n }\n\n private setFocus(): void {\n if (this._control && !this.state.isDisabled) {\n this._control.setFocus();\n }\n }\n\n private _onLineWeightPick = (weight: number) => {\n const propertyRecord = this.props.propertyRecord as PropertyRecord;\n\n this.setState(\n {\n weightValue: weight,\n },\n async () => {\n if (propertyRecord && this.props.onCommit) {\n const propertyValue = await this.getPropertyValue();\n if (propertyValue !== undefined) {\n this.props.onCommit({ propertyRecord, newValue: propertyValue });\n }\n }\n }\n );\n };\n\n /** @internal */\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n let initialValue = 0;\n\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n initialValue = record.value.value as number;\n }\n\n const readonly =\n record && undefined !== record.isReadonly ? record.isReadonly : false;\n const isDisabled = record ? record.isDisabled : undefined;\n\n if (this._isMounted)\n this.setState({ weightValue: initialValue, readonly, isDisabled }, () => {\n if (this.props.setFocus) {\n this.setFocus();\n }\n });\n }\n\n /** @internal */\n public override render() {\n return (\n <div\n className={classnames(\"components-weight-editor\", this.props.className)}\n style={this.props.style}\n ref={this._divElement}\n >\n <WeightPickerButton\n ref={(control) => (this._control = control)}\n activeWeight={this.state.weightValue}\n weights={\n this._availableWeights.length > 0\n ? this._availableWeights\n : undefined\n }\n disabled={this.state.isDisabled ? true : false}\n readonly={this.state.readonly}\n onLineWeightPick={this._onLineWeightPick}\n data-testid=\"components-weight-editor\"\n />\n </div>\n );\n }\n}\n\n/** Weight Property Editor registered for the \"number\" type name and \"weight-picker\" editor name.\n * It uses the [[WeightEditor]] React component.\n * @public\n */\nexport class WeightPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <WeightEditor />;\n }\n}\n\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n WeightPropertyEditor,\n StandardEditorNames.WeightPicker\n);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"QuantityInput.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityInput.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAEV,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,8HAA8H;IAC9H,YAAY,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,YAAY,EAAE,eAAe,CAAC;IAC9B,4GAA4G;IAC5G,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAC5B,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,GAAG,GACJ,EAAE,aAAa,qBAqHf"}
1
+ {"version":3,"file":"QuantityInput.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityInput.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAEV,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,8HAA8H;IAC9H,YAAY,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,YAAY,EAAE,eAAe,CAAC;IAC9B,4GAA4G;IAC5G,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAC5B,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,GAAG,GACJ,EAAE,aAAa,qBA+Gf"}
@@ -19,18 +19,14 @@ export function QuantityInput({ initialValue, quantityType, readonly, className,
19
19
  const [formatterSpec, setFormatterSpec] = React.useState(() => IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType));
20
20
  const [parserSpec, setParserSpec] = React.useState(() => IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
21
21
  const formatValue = React.useCallback((value) => {
22
- // istanbul ignore else
23
22
  if (formatterSpec) {
24
23
  return formatterSpec.applyFormatting(value);
25
24
  }
26
- // istanbul ignore next
27
25
  return value.toFixed(2);
28
26
  }, [formatterSpec]);
29
27
  const parseString = React.useCallback((userInput) => {
30
- // istanbul ignore else
31
28
  if (parserSpec) {
32
29
  const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(userInput, parserSpec);
33
- // istanbul ignore else
34
30
  if (Parser.isParsedQuantity(parseResult)) {
35
31
  return { value: parseResult.value };
36
32
  }
@@ -43,7 +39,6 @@ export function QuantityInput({ initialValue, quantityType, readonly, className,
43
39
  };
44
40
  }
45
41
  }
46
- // istanbul ignore next
47
42
  return {
48
43
  parseError: translate("QuantityInput.NoParserDefined"),
49
44
  };
@@ -62,7 +57,6 @@ export function QuantityInput({ initialValue, quantityType, readonly, className,
62
57
  React.useEffect(() => {
63
58
  const handleUnitSystemChanged = (args) => {
64
59
  const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);
65
- // istanbul ignore else
66
60
  if (args.quantityType === quantityKey) {
67
61
  setFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType));
68
62
  setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
@@ -1 +1 @@
1
- {"version":3,"file":"QuantityInput.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityInput.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAkBnD;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,KAAK,EACL,gBAAgB,EAChB,GAAG,GACW;IACd,MAAM,EAAE,SAAS,EAAE,GAAG,cAAc,EAAE,CAAC;IACvC,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAC5D,SAAS,CAAC,iBAAiB,CAAC,+BAA+B,CAAC,YAAY,CAAC,CAC1E,CAAC;IACF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CACtD,SAAS,CAAC,iBAAiB,CAAC,4BAA4B,CAAC,YAAY,CAAC,CACvE,CAAC;IAEF,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CACnC,CAAC,KAAa,EAAE,EAAE;QAChB,uBAAuB;QACvB,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,aAAa,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;QACD,uBAAuB;QACvB,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,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BAAuB,CACxB,CAAC;QACF,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,iBAAiB,CAAC,mCAAmC,CAAC,cAAc,CAC5E,uBAAuB,CACxB,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,uBAAuB,GAAG,CAC9B,IAAgC,EAC1B,EAAE;YACR,MAAM,WAAW,GACf,SAAS,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;YAC/D,uBAAuB;YACvB,IAAI,IAAI,CAAC,YAAY,KAAK,WAAW,EAAE,CAAC;gBACtC,gBAAgB,CACd,SAAS,CAAC,iBAAiB,CAAC,+BAA+B,CACzD,YAAY,CACb,CACF,CAAC;gBACF,aAAa,CACX,SAAS,CAAC,iBAAiB,CAAC,4BAA4B,CAAC,YAAY,CAAC,CACvE,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,SAAS,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,WAAW,CAC9D,uBAAuB,CACxB,CAAC;QACF,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,cAAc,CACjE,uBAAuB,CACxB,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,OAAO,CACL,oBAAC,WAAW,mBACE,2BAA2B,EACvC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,GACxB,CACH,CAAC;AACJ,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 Inputs\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n QuantityFormatsChangedArgs,\n QuantityTypeArg,\n} from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { Parser } from \"@itwin/core-quantity\";\nimport type { ParseResults } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { ParsedInput } from \"@itwin/components-react\";\nimport { useTranslation } from \"../useTranslation\";\n\n/** Props for [[QuantityInput]] control\n * @beta\n */\nexport interface QuantityProps extends CommonProps {\n /** Initial magnitude in 'persistence' units. See `getPersistenceUnitByQuantityType` in [QuantityFormatter]($core-frontend) */\n initialValue: number;\n /** Type of quantity being input. */\n quantityType: QuantityTypeArg;\n /** Function to call in the quantity value is changed. The value returned will be in 'persistence' units. */\n onQuantityChange: (newQuantityValue: number) => void;\n /** Set to `true` if value is for display only */\n readonly?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n}\n\n/** Input control that allows users to input a quantity and show the formatted string that represents the value.\n * @beta\n */\nexport function QuantityInput({\n initialValue,\n quantityType,\n readonly,\n className,\n style,\n onQuantityChange,\n ref,\n}: QuantityProps) {\n const { translate } = useTranslation();\n const [formatterSpec, setFormatterSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)\n );\n const [parserSpec, setParserSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n\n const formatValue = React.useCallback(\n (value: number) => {\n // istanbul ignore else\n if (formatterSpec) {\n return formatterSpec.applyFormatting(value);\n }\n // istanbul ignore next\n return value.toFixed(2);\n },\n [formatterSpec]\n );\n\n const parseString = React.useCallback(\n (userInput: string): ParseResults => {\n // istanbul ignore else\n if (parserSpec) {\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(\n userInput,\n parserSpec\n );\n // istanbul ignore else\n if (Parser.isParsedQuantity(parseResult)) {\n return { value: parseResult.value };\n } else {\n const statusId = Parser.isParseError(parseResult)\n ? parseResult.error.toString()\n : \"Unknown\";\n return {\n parseError: `${translate(\n \"QuantityInput.NoParserDefined\"\n )}${statusId}`,\n };\n }\n }\n // istanbul ignore next\n return {\n parseError: translate(\"QuantityInput.NoParserDefined\"),\n };\n },\n [parserSpec, translate]\n );\n\n const classNames = classnames(className, \"components-quantity-input\");\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (): void => {\n setFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n };\n\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (\n args: QuantityFormatsChangedArgs\n ): void => {\n const quantityKey =\n IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\n // istanbul ignore else\n if (args.quantityType === quantityKey) {\n setFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n }\n };\n\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n return (\n <ParsedInput\n data-testid=\"components-quantity-input\"\n ref={ref}\n style={style}\n className={classNames}\n onChange={onQuantityChange}\n initialValue={initialValue}\n readonly={readonly}\n formatValue={formatValue}\n parseString={parseString}\n />\n );\n}\n"]}
1
+ {"version":3,"file":"Qu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,CAAC,CAAC;IAEnB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,uBAAuB,GAAG,CAC9B,IAAgC,EAC1B,EAAE;YACR,MAAM,WAAW,GACf,SAAS,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;YAC/D,IAAI,IAAI,CAAC,YAAY,KAAK,WAAW,EAAE,CAAC;gBACtC,gBAAgB,CACd,SAAS,CAAC,iBAAiB,CAAC,+BAA+B,CACzD,YAAY,CACb,CACF,CAAC;gBACF,aAAa,CACX,SAAS,CAAC,iBAAiB,CAAC,4BAA4B,CAAC,YAAY,CAAC,CACvE,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEF,SAAS,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,WAAW,CAC9D,uBAAuB,CACxB,CAAC;QACF,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,cAAc,CACjE,uBAAuB,CACxB,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEnB,OAAO,CACL,oBAAC,WAAW,mBACE,2BAA2B,EACvC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,GACxB,CACH,CAAC;AACJ,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 Inputs\n */\n\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type {\n QuantityFormatsChangedArgs,\n QuantityTypeArg,\n} from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { Parser } from \"@itwin/core-quantity\";\nimport type { ParseResults } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { ParsedInput } from \"@itwin/components-react\";\nimport { useTranslation } from \"../useTranslation\";\n\n/** Props for [[QuantityInput]] control\n * @beta\n */\nexport interface QuantityProps extends CommonProps {\n /** Initial magnitude in 'persistence' units. See `getPersistenceUnitByQuantityType` in [QuantityFormatter]($core-frontend) */\n initialValue: number;\n /** Type of quantity being input. */\n quantityType: QuantityTypeArg;\n /** Function to call in the quantity value is changed. The value returned will be in 'persistence' units. */\n onQuantityChange: (newQuantityValue: number) => void;\n /** Set to `true` if value is for display only */\n readonly?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n}\n\n/** Input control that allows users to input a quantity and show the formatted string that represents the value.\n * @beta\n */\nexport function QuantityInput({\n initialValue,\n quantityType,\n readonly,\n className,\n style,\n onQuantityChange,\n ref,\n}: QuantityProps) {\n const { translate } = useTranslation();\n const [formatterSpec, setFormatterSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)\n );\n const [parserSpec, setParserSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n\n const formatValue = React.useCallback(\n (value: number) => {\n if (formatterSpec) {\n return formatterSpec.applyFormatting(value);\n }\n return value.toFixed(2);\n },\n [formatterSpec]\n );\n\n const parseString = React.useCallback(\n (userInput: string): ParseResults => {\n if (parserSpec) {\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(\n userInput,\n parserSpec\n );\n if (Parser.isParsedQuantity(parseResult)) {\n return { value: parseResult.value };\n } else {\n const statusId = Parser.isParseError(parseResult)\n ? parseResult.error.toString()\n : \"Unknown\";\n return {\n parseError: `${translate(\n \"QuantityInput.NoParserDefined\"\n )}${statusId}`,\n };\n }\n }\n return {\n parseError: translate(\"QuantityInput.NoParserDefined\"),\n };\n },\n [parserSpec, translate]\n );\n\n const classNames = classnames(className, \"components-quantity-input\");\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (): void => {\n setFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n };\n\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (\n args: QuantityFormatsChangedArgs\n ): void => {\n const quantityKey =\n IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\n if (args.quantityType === quantityKey) {\n setFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n }\n };\n\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n return (\n <ParsedInput\n data-testid=\"components-quantity-input\"\n ref={ref}\n style={style}\n className={classNames}\n onChange={onQuantityChange}\n initialValue={initialValue}\n readonly={readonly}\n formatValue={formatValue}\n parseString={parseString}\n />\n );\n}\n"]}
@@ -42,6 +42,6 @@ export interface QuantityNumberInputProps extends Omit<InputProps, "value" | "mi
42
42
  * units that can be stored in the iModel.
43
43
  * @beta
44
44
  */
45
- export declare const QuantityNumberInput: (props: QuantityNumberInputProps) => React.ReactElement | null;
45
+ export declare const QuantityNumberInput: (props: QuantityNumberInputProps) => React.ReactNode;
46
46
  export {};
47
47
  //# sourceMappingURL=QuantityNumberInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"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AM,mBAAmB,EAAE,CAChC,KAAK,EAAE,wBAAwB,KAC5B,KAAK,CAAC,YAAY,GAAG,IAAoC,CAAC"}
1
+ {"version":3,"file":"QuantityNumberInput.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityNumberInput.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,4BAA4B,CAAC;AAEpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAEV,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAc9B,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAQ7C,KAAK,UAAU,GAAG,KAAK,CAAC,wBAAwB,CAAC,OAAO,KAAK,CAAC,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,wBACf,SAAQ,IAAI,CACV,UAAU,EACV,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,CAC1D;IACD;qDACiD;IACjD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,yEAAyE;IACzE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kHAAkH;IAClH,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,0HAA0H;IAC1H,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,+DAA+D;IAC/D,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAClC,oCAAoC;IACpC,YAAY,EAAE,eAAe,CAAC;CAC/B;AA0YD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAChC,KAAK,EAAE,wBAAwB,KAC5B,KAAK,CAAC,SAAyC,CAAC"}
@@ -31,11 +31,9 @@ function adjustFormatterSpec(formatterSpec) {
31
31
  return new FormatterSpec("single-value", newFormat, singleUnitConversion, formatterSpec.persistenceUnit);
32
32
  }
33
33
  function convertValueFromDisplayToPersistence(value, unitConversions, unit) {
34
- // istanbul ignore next
35
34
  if (!unitConversions || 0 === unitConversions.length)
36
35
  return value;
37
36
  const unitConversion = unitConversions.find((spec) => spec.name === unit.name);
38
- // istanbul ignore next
39
37
  if (!unitConversion)
40
38
  return value;
41
39
  const convertedValue = value * unitConversion.conversion.factor + unitConversion.conversion.offset;
@@ -45,11 +43,9 @@ function getUnitLabel(parserSpec) {
45
43
  if (undefined === parserSpec)
46
44
  return "";
47
45
  const format = parserSpec.format;
48
- // istanbul ignore else
49
46
  if (!format.units || !format.units[0])
50
47
  return parserSpec.outUnit.label;
51
48
  const [unit, label] = format.units[0];
52
- // istanbul ignore next
53
49
  return label ?? unit.label;
54
50
  }
55
51
  const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuantityNumberInput(props, ref) {
@@ -60,11 +56,9 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
60
56
  const formatValue = React.useCallback((value) => {
61
57
  if (undefined === value)
62
58
  return "";
63
- // istanbul ignore else
64
59
  if (formatterSpec) {
65
60
  return formatterSpec.applyFormatting(value);
66
61
  }
67
- // istanbul ignore next
68
62
  return value.toFixed(2);
69
63
  }, [formatterSpec]);
70
64
  const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));
@@ -82,7 +76,6 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
82
76
  React.useEffect(() => {
83
77
  const handleUnitSystemChanged = (args) => {
84
78
  const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);
85
- // istanbul ignore else
86
79
  if (args.quantityType === quantityKey) {
87
80
  setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
88
81
  setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
@@ -106,12 +99,11 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
106
99
  }, []);
107
100
  const updateValue = React.useCallback((newValue) => {
108
101
  let persistedValue = newValue;
109
- // istanbul ignore else
110
102
  if (parserSpec) {
111
103
  // convert value from display unit to persistence unit
112
104
  const [unit] = parserSpec.format.units
113
105
  ? parserSpec.format.units[0]
114
- : /* istanbul ignore next */ [parserSpec.outUnit];
106
+ : [parserSpec.outUnit];
115
107
  persistedValue = convertValueFromDisplayToPersistence(newValue, parserSpec.unitConversions, unit);
116
108
  rawValueRef.current = persistedValue;
117
109
  }
@@ -130,7 +122,6 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
130
122
  if (!x)
131
123
  return 0;
132
124
  let n = parseFloat(x);
133
- // istanbul ignore next
134
125
  if (isNaN(n) || !isFinite(n)) {
135
126
  n = 0;
136
127
  }
@@ -143,7 +134,6 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
143
134
  return n;
144
135
  }, [min, max]);
145
136
  const updateValueFromString = React.useCallback((strValue) => {
146
- // istanbul ignore else
147
137
  if (parserSpec) {
148
138
  const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(strValue, parserSpec);
149
139
  // at this point we should have a string value in persistence units without a label
@@ -153,7 +143,6 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
153
143
  strValue = formatValue(persistedValue);
154
144
  }
155
145
  else {
156
- // istanbul ignore else
157
146
  if (rawValueRef.current) {
158
147
  // restore last known good value
159
148
  const lastKnownFormattedVal = formatValue(rawValueRef.current);
@@ -163,7 +152,6 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
163
152
  }
164
153
  }
165
154
  const newValue = parseInternal(strValue);
166
- // istanbul ignore else
167
155
  if (undefined !== newValue)
168
156
  updateValue(newValue);
169
157
  }, [formatValue, parseInternal, parserSpec, updateValue]);
@@ -203,7 +191,6 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
203
191
  updateValue,
204
192
  ]);
205
193
  const handleKeyDown = React.useCallback((event) => {
206
- // istanbul ignore else
207
194
  if (event.key === Key.Enter.valueOf()) {
208
195
  updateValueFromString(event.currentTarget.value);
209
196
  event.preventDefault();
@@ -230,7 +217,6 @@ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuanti
230
217
  applyStep(true);
231
218
  event.preventDefault();
232
219
  }, [applyStep]);
233
- // istanbul ignore next
234
220
  const handleFocus = React.useCallback((event) => {
235
221
  event.currentTarget.select();
236
222
  }, []);
@@ -1 +1 @@
1
- {"version":3,"file":"QuantityNumberInput.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityNumberInput.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,4BAA4B,CAAC;AACpC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAKzC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAMjD,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,MAAM,GACP,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,eAAe,GAChB,MAAM,4BAA4B,CAAC;AA0CpC,wE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,EAAC,OAAO,KACR,UAAU,GACd;YACF,6BACE,SAAS,EAAE,UAAU,CACnB,mDAAmD,EACnD,gBAAgB,IAAI,oCAAoC,CACzD;gBAGD,6BACE,SAAS,EAAC,kFAAkF,EAC5F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,aAAa;oBAEtB,oBAAC,IAAI,IAAC,QAAQ,EAAE,OAAO,GAAI,CACvB;gBAEN,6BACE,SAAS,EAAC,oFAAoF,EAC9F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,eAAe;oBAExB,oBAAC,IAAI,IAAC,QAAQ,EAAE,SAAS,GAAI,CACzB,CACF,CACF;QACN,8BAAM,SAAS,EAAC,wCAAwC,IACrD,SAAS,CACL,CACH,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAEC,6BAA6B,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 Inputs\n */\n\nimport \"./QuantityNumberInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Icon } from \"@itwin/core-react\";\nimport type {\n QuantityFormatsChangedArgs,\n QuantityTypeArg,\n} from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport type {\n ParserSpec,\n UnitConversionSpec,\n UnitProps,\n} from \"@itwin/core-quantity\";\nimport {\n DecimalPrecision,\n FormatterSpec,\n FormatTraits,\n FormatType,\n Parser,\n} from \"@itwin/core-quantity\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport {\n SvgCaretDown,\n SvgCaretDownSmall,\n SvgCaretUp,\n SvgCaretUpSmall,\n} from \"@itwin/itwinui-icons-react\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** Step function prototype for [[QuantityNumberInput]] component\n * @beta\n */\nexport type StepFunctionProp =\n | number\n | ((direction: string) => number | undefined);\n\n/** Properties for the [[QuantityNumberInput]] component\n * @beta\n */\nexport interface QuantityNumberInputProps\n extends Omit<\n InputProps,\n \"value\" | \"min\" | \"max\" | \"step\" | \"onFocus\" | \"onChange\"\n > {\n /** Initial magnitude in 'persistence' units. See `getPersistenceUnitByQuantityType` in [QuantityFormatter]($core-frontend).\n * Set to `undefined` to show placeholder text */\n persistenceValue?: number;\n /** CSS class name for the QuantityNumberInput component container div */\n containerClassName?: string;\n /** number or function\tNumber.MIN_SAFE_INTEGER */\n min?: number;\n /** number or function\tdefaults to Number.MAX_SAFE_INTEGER */\n max?: number;\n /** increment step value used while incrementing or decrementing (up/down buttons or arrow keys) defaults to 1. */\n step?: StepFunctionProp;\n /** Set to true to \"snap\" to the closest step value while incrementing or decrementing (up/down buttons or arrow keys). */\n snap?: boolean;\n /** Function to call when the quantity value is changed. The value returned will be in 'persistence' units. */\n onChange?: (value: number) => void;\n /** if true up/down buttons are shown larger and side by side */\n showTouchButtons?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n /** Type of quantity being input. */\n quantityType: QuantityTypeArg;\n}\n\n/** adjust formatter spec to show only primary unit without a label. */\nfunction adjustFormatterSpec(formatterSpec: FormatterSpec | undefined) {\n if (undefined === formatterSpec) return formatterSpec;\n const singleUnitConversion: UnitConversionSpec[] = [];\n singleUnitConversion.push(formatterSpec.unitConversions[0]);\n const newFormat = formatterSpec.format.clone({\n showOnlyPrimaryUnit: true,\n traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,\n type: FormatType.Decimal,\n precision:\n FormatType.Decimal !== formatterSpec.format.type\n ? DecimalPrecision.Four\n : formatterSpec.format.precision,\n });\n return new FormatterSpec(\n \"single-value\",\n newFormat,\n singleUnitConversion,\n formatterSpec.persistenceUnit\n );\n}\n\nfunction convertValueFromDisplayToPersistence(\n value: number,\n unitConversions: UnitConversionSpec[] | undefined,\n unit: UnitProps\n) {\n // istanbul ignore next\n if (!unitConversions || 0 === unitConversions.length) return value;\n\n const unitConversion = unitConversions.find(\n (spec) => spec.name === unit.name\n );\n // istanbul ignore next\n if (!unitConversion) return value;\n\n const convertedValue =\n value * unitConversion.conversion.factor + unitConversion.conversion.offset;\n return convertedValue;\n}\n\nfunction getUnitLabel(parserSpec: ParserSpec | undefined) {\n if (undefined === parserSpec) return \"\";\n\n const format = parserSpec.format;\n // istanbul ignore else\n if (!format.units || !format.units[0]) return parserSpec.outUnit.label;\n const [unit, label] = format.units[0];\n // istanbul ignore next\n return label ?? unit.label;\n}\n\nconst ForwardRefQuantityNumberInput = React.forwardRef<\n HTMLInputElement,\n QuantityNumberInputProps\n>(function ForwardRefQuantityNumberInput(props, ref) {\n const {\n containerClassName,\n persistenceValue,\n min,\n max,\n onChange,\n onBlur,\n onKeyDown,\n step,\n snap,\n showTouchButtons,\n quantityType,\n ...otherProps\n } = props;\n const rawValueRef = React.useRef(persistenceValue);\n\n const [formatterSpec, setFormatterSpec] = React.useState(() =>\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)\n )\n );\n const [parserSpec, setParserSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n\n const formatValue = React.useCallback(\n (value: number | undefined) => {\n if (undefined === value) return \"\";\n\n // istanbul ignore else\n if (formatterSpec) {\n return formatterSpec.applyFormatting(value);\n }\n // istanbul ignore next\n return value.toFixed(2);\n },\n [formatterSpec]\n );\n\n const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));\n const [formattedValue, setFormattedValue] = React.useState(\n () => lastFormattedValueRef.current\n );\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (): void => {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n };\n\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (\n args: QuantityFormatsChangedArgs\n ): void => {\n const quantityKey =\n IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\n // istanbul ignore else\n if (args.quantityType === quantityKey) {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n }\n };\n\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n const unitLabel = getUnitLabel(parserSpec);\n\n // See if new initialValue props have changed since component mounted\n React.useEffect(() => {\n rawValueRef.current = persistenceValue;\n const currentFormattedValue = formatValue(rawValueRef.current);\n setFormattedValue(currentFormattedValue);\n }, [formatValue, persistenceValue]);\n\n // this is the unprocessed input from user, it is not processed until blur or enter key press\n const handleDisplayValueChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setFormattedValue(event.currentTarget.value);\n },\n []\n );\n\n const updateValue = React.useCallback(\n (newValue: number) => {\n let persistedValue = newValue;\n // istanbul ignore else\n if (parserSpec) {\n // convert value from display unit to persistence unit\n const [unit] = parserSpec.format.units\n ? parserSpec.format.units[0]\n : /* istanbul ignore next */ [parserSpec.outUnit];\n persistedValue = convertValueFromDisplayToPersistence(\n newValue,\n parserSpec.unitConversions,\n unit\n );\n rawValueRef.current = persistedValue;\n }\n const newFormattedVal = formatValue(persistedValue);\n onChange && onChange(persistedValue);\n setFormattedValue(newFormattedVal);\n },\n [formatValue, onChange, parserSpec]\n );\n\n /**\n * Used internally to parse the argument x to it's numeric representation.\n * If the argument cannot be converted to finite number returns 0; If a\n * \"precision\" prop is specified uses it round the number with that\n * precision (no fixed precision here because the return value is float, not\n * string).\n */\n const parseInternal = React.useCallback(\n (x: string | undefined) => {\n if (!x) return 0;\n\n let n = parseFloat(x);\n // istanbul ignore next\n if (isNaN(n) || !isFinite(n)) {\n n = 0;\n }\n\n const localPrecision = 6; // TODO get a reasonable value from format\n const q = Math.pow(10, localPrecision);\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n n = Math.min(Math.max(n, localMin), localMax);\n n = Math.round(n * q) / q;\n\n return n;\n },\n [min, max]\n );\n\n const updateValueFromString = React.useCallback(\n (strValue: string) => {\n // istanbul ignore else\n if (parserSpec) {\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(\n strValue,\n parserSpec\n );\n // at this point we should have a string value in persistence units without a label\n if (Parser.isParsedQuantity(parseResult)) {\n const persistedValue = parseResult.value; // in persistence units\n // set strValue and let it go through parseInternal which will ensure min/max limits are observed\n strValue = formatValue(persistedValue)!;\n } else {\n // istanbul ignore else\n if (rawValueRef.current) {\n // restore last known good value\n const lastKnownFormattedVal = formatValue(rawValueRef.current);\n setFormattedValue(lastKnownFormattedVal);\n return;\n }\n }\n }\n const newValue = parseInternal(strValue);\n // istanbul ignore else\n if (undefined !== newValue) updateValue(newValue);\n },\n [formatValue, parseInternal, parserSpec, updateValue]\n );\n\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n const newVal = parseInternal(event.target.value);\n onBlur && onBlur(event);\n updateValue(newVal);\n },\n [parseInternal, updateValue, onBlur]\n );\n\n const getIncrementValue = React.useCallback(\n (increment: boolean) => {\n if (typeof step === \"function\") {\n const stepVal = step(increment ? \"up\" : \"down\");\n return stepVal ? stepVal : 1;\n }\n\n return !step ? 1 : step;\n },\n [step]\n );\n\n /**\n * The internal method that actually sets the new value on the input\n */\n const applyStep = React.useCallback(\n (increment: boolean) => {\n const incrementValue = getIncrementValue(increment);\n\n let num =\n parseInternal(formattedValue) +\n (increment ? incrementValue : -incrementValue);\n if (snap) {\n num = Math.round(num / incrementValue) * incrementValue;\n }\n\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n num = Math.min(Math.max(num, localMin), localMax);\n\n updateValue(num);\n },\n [\n formattedValue,\n getIncrementValue,\n max,\n min,\n parseInternal,\n snap,\n updateValue,\n ]\n );\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === Key.Enter.valueOf()) {\n updateValueFromString(event.currentTarget.value);\n event.preventDefault();\n } else if (event.key === Key.Escape.valueOf()) {\n setFormattedValue(formatValue(rawValueRef.current));\n event.preventDefault();\n } else if (event.key === Key.ArrowDown.valueOf()) {\n applyStep(false);\n event.preventDefault();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n applyStep(true);\n event.preventDefault();\n }\n onKeyDown && onKeyDown(event);\n },\n [onKeyDown, updateValueFromString, formatValue, applyStep]\n );\n\n const handleDownClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(false);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleUpClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(true);\n event.preventDefault();\n },\n [applyStep]\n );\n\n // istanbul ignore next\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n },\n []\n );\n\n const isDisabled = !!otherProps.disabled;\n const containerClasses = classnames(\n \"component-quantity-number-input-container\",\n containerClassName,\n showTouchButtons && \"component-number-buttons-for-touch\",\n isDisabled && \"component-quantity-number-input-disabled\"\n );\n\n const caretUp = showTouchButtons ? <SvgCaretUp /> : <SvgCaretUpSmall />;\n const caretDown = showTouchButtons ? <SvgCaretDown /> : <SvgCaretDownSmall />;\n\n return (\n <div className={containerClasses}>\n <div className=\"component-quantity-number-input-value-and-buttons-container\">\n <Input\n ref={ref}\n value={formattedValue}\n onChange={handleDisplayValueChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n onFocus={handleFocus}\n size=\"small\"\n {...otherProps}\n />\n <div\n className={classnames(\n \"component-quantity-number-input-buttons-container\",\n showTouchButtons && \"component-number-buttons-for-touch\"\n )}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-up\"\n tabIndex={-1}\n onClick={handleUpClick}\n >\n <Icon iconSpec={caretUp} />\n </div>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-down\"\n tabIndex={-1}\n onClick={handleDownClick}\n >\n <Icon iconSpec={caretDown} />\n </div>\n </div>\n </div>\n <span className=\"component-quantity-number-input-suffix\">\n {unitLabel}\n </span>\n </div>\n );\n});\n\n/** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's\n * \"display\" unit is shown next to the input control. The \"display\" unit is determined by the active unit system as defined by the [QuantityFormatter]($frontend).\n * The control also display buttons to increment and decrement the \"displayed\" value. The value reported by via the onChange function is in \"persistence\"\n * units that can be stored in the iModel.\n * @beta\n */\nexport const QuantityNumberInput: (\n props: QuantityNumberInputProps\n) => React.ReactElement | null = ForwardRefQuantityNumberInput;\n"]}
1
+ {"version":3,"file":"QuantityNumberInput.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityNumberInput.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,4BAA4B,CAAC;AACpC,OAAO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AO,CACL,6BAAK,SAAS,EAAE,gBAAgB;QAC9B,6BAAK,SAAS,EAAC,6DAA6D;YAC1E,oBAAC,KAAK,IACJ,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,cAAc,EACrB,QAAQ,EAAE,wBAAwB,EAClC,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAC,OAAO,KACR,UAAU,GACd;YACF,6BACE,SAAS,EAAE,UAAU,CACnB,mDAAmD,EACnD,gBAAgB,IAAI,oCAAoC,CACzD;gBAGD,6BACE,SAAS,EAAC,kFAAkF,EAC5F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,aAAa;oBAEtB,oBAAC,IAAI,IAAC,QAAQ,EAAE,OAAO,GAAI,CACvB;gBAEN,6BACE,SAAS,EAAC,oFAAoF,EAC9F,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,eAAe;oBAExB,oBAAC,IAAI,IAAC,QAAQ,EAAE,SAAS,GAAI,CACzB,CACF,CACF;QACN,8BAAM,SAAS,EAAC,wCAAwC,IACrD,SAAS,CACL,CACH,CACP,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAET,6BAA6B,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 Inputs\n */\n\nimport \"./QuantityNumberInput.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Icon } from \"@itwin/core-react\";\nimport type {\n QuantityFormatsChangedArgs,\n QuantityTypeArg,\n} from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport type {\n ParserSpec,\n UnitConversionSpec,\n UnitProps,\n} from \"@itwin/core-quantity\";\nimport {\n DecimalPrecision,\n FormatterSpec,\n FormatTraits,\n FormatType,\n Parser,\n} from \"@itwin/core-quantity\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport {\n SvgCaretDown,\n SvgCaretDownSmall,\n SvgCaretUp,\n SvgCaretUpSmall,\n} from \"@itwin/itwinui-icons-react\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\n/** Step function prototype for [[QuantityNumberInput]] component\n * @beta\n */\nexport type StepFunctionProp =\n | number\n | ((direction: string) => number | undefined);\n\n/** Properties for the [[QuantityNumberInput]] component\n * @beta\n */\nexport interface QuantityNumberInputProps\n extends Omit<\n InputProps,\n \"value\" | \"min\" | \"max\" | \"step\" | \"onFocus\" | \"onChange\"\n > {\n /** Initial magnitude in 'persistence' units. See `getPersistenceUnitByQuantityType` in [QuantityFormatter]($core-frontend).\n * Set to `undefined` to show placeholder text */\n persistenceValue?: number;\n /** CSS class name for the QuantityNumberInput component container div */\n containerClassName?: string;\n /** number or function\tNumber.MIN_SAFE_INTEGER */\n min?: number;\n /** number or function\tdefaults to Number.MAX_SAFE_INTEGER */\n max?: number;\n /** increment step value used while incrementing or decrementing (up/down buttons or arrow keys) defaults to 1. */\n step?: StepFunctionProp;\n /** Set to true to \"snap\" to the closest step value while incrementing or decrementing (up/down buttons or arrow keys). */\n snap?: boolean;\n /** Function to call when the quantity value is changed. The value returned will be in 'persistence' units. */\n onChange?: (value: number) => void;\n /** if true up/down buttons are shown larger and side by side */\n showTouchButtons?: boolean;\n /** Provides ability to return reference to HTMLInputElement */\n ref?: React.Ref<HTMLInputElement>;\n /** Type of quantity being input. */\n quantityType: QuantityTypeArg;\n}\n\n/** adjust formatter spec to show only primary unit without a label. */\nfunction adjustFormatterSpec(formatterSpec: FormatterSpec | undefined) {\n if (undefined === formatterSpec) return formatterSpec;\n const singleUnitConversion: UnitConversionSpec[] = [];\n singleUnitConversion.push(formatterSpec.unitConversions[0]);\n const newFormat = formatterSpec.format.clone({\n showOnlyPrimaryUnit: true,\n traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,\n type: FormatType.Decimal,\n precision:\n FormatType.Decimal !== formatterSpec.format.type\n ? DecimalPrecision.Four\n : formatterSpec.format.precision,\n });\n return new FormatterSpec(\n \"single-value\",\n newFormat,\n singleUnitConversion,\n formatterSpec.persistenceUnit\n );\n}\n\nfunction convertValueFromDisplayToPersistence(\n value: number,\n unitConversions: UnitConversionSpec[] | undefined,\n unit: UnitProps\n) {\n if (!unitConversions || 0 === unitConversions.length) return value;\n\n const unitConversion = unitConversions.find(\n (spec) => spec.name === unit.name\n );\n if (!unitConversion) return value;\n\n const convertedValue =\n value * unitConversion.conversion.factor + unitConversion.conversion.offset;\n return convertedValue;\n}\n\nfunction getUnitLabel(parserSpec: ParserSpec | undefined) {\n if (undefined === parserSpec) return \"\";\n\n const format = parserSpec.format;\n if (!format.units || !format.units[0]) return parserSpec.outUnit.label;\n const [unit, label] = format.units[0];\n return label ?? unit.label;\n}\n\nconst ForwardRefQuantityNumberInput = React.forwardRef<\n HTMLInputElement,\n QuantityNumberInputProps\n>(function ForwardRefQuantityNumberInput(props, ref) {\n const {\n containerClassName,\n persistenceValue,\n min,\n max,\n onChange,\n onBlur,\n onKeyDown,\n step,\n snap,\n showTouchButtons,\n quantityType,\n ...otherProps\n } = props;\n const rawValueRef = React.useRef(persistenceValue);\n\n const [formatterSpec, setFormatterSpec] = React.useState(() =>\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)\n )\n );\n const [parserSpec, setParserSpec] = React.useState(() =>\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n\n const formatValue = React.useCallback(\n (value: number | undefined) => {\n if (undefined === value) return \"\";\n\n if (formatterSpec) {\n return formatterSpec.applyFormatting(value);\n }\n return value.toFixed(2);\n },\n [formatterSpec]\n );\n\n const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));\n const [formattedValue, setFormattedValue] = React.useState(\n () => lastFormattedValueRef.current\n );\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (): void => {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n };\n\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = (\n args: QuantityFormatsChangedArgs\n ): void => {\n const quantityKey =\n IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\n if (args.quantityType === quantityKey) {\n setFormatterSpec(\n adjustFormatterSpec(\n IModelApp.quantityFormatter.findFormatterSpecByQuantityType(\n quantityType\n )\n )\n );\n setParserSpec(\n IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType)\n );\n }\n };\n\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(\n handleUnitSystemChanged\n );\n return () => {\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(\n handleUnitSystemChanged\n );\n };\n }, [quantityType]);\n\n const unitLabel = getUnitLabel(parserSpec);\n\n // See if new initialValue props have changed since component mounted\n React.useEffect(() => {\n rawValueRef.current = persistenceValue;\n const currentFormattedValue = formatValue(rawValueRef.current);\n setFormattedValue(currentFormattedValue);\n }, [formatValue, persistenceValue]);\n\n // this is the unprocessed input from user, it is not processed until blur or enter key press\n const handleDisplayValueChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setFormattedValue(event.currentTarget.value);\n },\n []\n );\n\n const updateValue = React.useCallback(\n (newValue: number) => {\n let persistedValue = newValue;\n if (parserSpec) {\n // convert value from display unit to persistence unit\n const [unit] = parserSpec.format.units\n ? parserSpec.format.units[0]\n : [parserSpec.outUnit];\n persistedValue = convertValueFromDisplayToPersistence(\n newValue,\n parserSpec.unitConversions,\n unit\n );\n rawValueRef.current = persistedValue;\n }\n const newFormattedVal = formatValue(persistedValue);\n onChange && onChange(persistedValue);\n setFormattedValue(newFormattedVal);\n },\n [formatValue, onChange, parserSpec]\n );\n\n /**\n * Used internally to parse the argument x to it's numeric representation.\n * If the argument cannot be converted to finite number returns 0; If a\n * \"precision\" prop is specified uses it round the number with that\n * precision (no fixed precision here because the return value is float, not\n * string).\n */\n const parseInternal = React.useCallback(\n (x: string | undefined) => {\n if (!x) return 0;\n\n let n = parseFloat(x);\n if (isNaN(n) || !isFinite(n)) {\n n = 0;\n }\n\n const localPrecision = 6; // TODO get a reasonable value from format\n const q = Math.pow(10, localPrecision);\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n n = Math.min(Math.max(n, localMin), localMax);\n n = Math.round(n * q) / q;\n\n return n;\n },\n [min, max]\n );\n\n const updateValueFromString = React.useCallback(\n (strValue: string) => {\n if (parserSpec) {\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(\n strValue,\n parserSpec\n );\n // at this point we should have a string value in persistence units without a label\n if (Parser.isParsedQuantity(parseResult)) {\n const persistedValue = parseResult.value; // in persistence units\n // set strValue and let it go through parseInternal which will ensure min/max limits are observed\n strValue = formatValue(persistedValue)!;\n } else {\n if (rawValueRef.current) {\n // restore last known good value\n const lastKnownFormattedVal = formatValue(rawValueRef.current);\n setFormattedValue(lastKnownFormattedVal);\n return;\n }\n }\n }\n const newValue = parseInternal(strValue);\n if (undefined !== newValue) updateValue(newValue);\n },\n [formatValue, parseInternal, parserSpec, updateValue]\n );\n\n const handleBlur = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n const newVal = parseInternal(event.target.value);\n onBlur && onBlur(event);\n updateValue(newVal);\n },\n [parseInternal, updateValue, onBlur]\n );\n\n const getIncrementValue = React.useCallback(\n (increment: boolean) => {\n if (typeof step === \"function\") {\n const stepVal = step(increment ? \"up\" : \"down\");\n return stepVal ? stepVal : 1;\n }\n\n return !step ? 1 : step;\n },\n [step]\n );\n\n /**\n * The internal method that actually sets the new value on the input\n */\n const applyStep = React.useCallback(\n (increment: boolean) => {\n const incrementValue = getIncrementValue(increment);\n\n let num =\n parseInternal(formattedValue) +\n (increment ? incrementValue : -incrementValue);\n if (snap) {\n num = Math.round(num / incrementValue) * incrementValue;\n }\n\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\n num = Math.min(Math.max(num, localMin), localMax);\n\n updateValue(num);\n },\n [\n formattedValue,\n getIncrementValue,\n max,\n min,\n parseInternal,\n snap,\n updateValue,\n ]\n );\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (event.key === Key.Enter.valueOf()) {\n updateValueFromString(event.currentTarget.value);\n event.preventDefault();\n } else if (event.key === Key.Escape.valueOf()) {\n setFormattedValue(formatValue(rawValueRef.current));\n event.preventDefault();\n } else if (event.key === Key.ArrowDown.valueOf()) {\n applyStep(false);\n event.preventDefault();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n applyStep(true);\n event.preventDefault();\n }\n onKeyDown && onKeyDown(event);\n },\n [onKeyDown, updateValueFromString, formatValue, applyStep]\n );\n\n const handleDownClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(false);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleUpClick = React.useCallback(\n (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(true);\n event.preventDefault();\n },\n [applyStep]\n );\n\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n },\n []\n );\n\n const isDisabled = !!otherProps.disabled;\n const containerClasses = classnames(\n \"component-quantity-number-input-container\",\n containerClassName,\n showTouchButtons && \"component-number-buttons-for-touch\",\n isDisabled && \"component-quantity-number-input-disabled\"\n );\n\n const caretUp = showTouchButtons ? <SvgCaretUp /> : <SvgCaretUpSmall />;\n const caretDown = showTouchButtons ? <SvgCaretDown /> : <SvgCaretDownSmall />;\n\n return (\n <div className={containerClasses}>\n <div className=\"component-quantity-number-input-value-and-buttons-container\">\n <Input\n ref={ref}\n value={formattedValue}\n onChange={handleDisplayValueChange}\n onKeyDown={handleKeyDown}\n onBlur={handleBlur}\n onFocus={handleFocus}\n size=\"small\"\n {...otherProps}\n />\n <div\n className={classnames(\n \"component-quantity-number-input-buttons-container\",\n showTouchButtons && \"component-number-buttons-for-touch\"\n )}\n >\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-up\"\n tabIndex={-1}\n onClick={handleUpClick}\n >\n <Icon iconSpec={caretUp} />\n </div>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n className=\"component-quantity-number-input-button component-quantity-number-input-button-down\"\n tabIndex={-1}\n onClick={handleDownClick}\n >\n <Icon iconSpec={caretDown} />\n </div>\n </div>\n </div>\n <span className=\"component-quantity-number-input-suffix\">\n {unitLabel}\n </span>\n </div>\n );\n});\n\n/** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's\n * \"display\" unit is shown next to the input control. The \"display\" unit is determined by the active unit system as defined by the [QuantityFormatter]($frontend).\n * The control also display buttons to increment and decrement the \"displayed\" value. The value reported by via the onChange function is in \"persistence\"\n * units that can be stored in the iModel.\n * @beta\n */\nexport const QuantityNumberInput: (\n props: QuantityNumberInputProps\n) => React.ReactNode = ForwardRefQuantityNumberInput;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Swatch.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/lineweight/Swatch.tsx"],"names":[],"mappings":"AAIA;;GAEG;AA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,CAAC;IACpB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC;IAC9E,gBAAgB;gBACJ,KAAK,EAAE,qBAAqB;IAIxB,iBAAiB;IAEjB,MAAM;CA4DvB"}
@@ -43,7 +43,6 @@ export class LineWeightSwatch extends React.PureComponent {
43
43
  height: `${weight}px`,
44
44
  };
45
45
  const handleClick = (_e) => {
46
- // istanbul ignore else
47
46
  if (onClick)
48
47
  onClick();
49
48
  };