@itwin/imodel-components-react 4.0.0-dev.2 → 4.0.0-dev.4

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 (348) hide show
  1. package/CHANGELOG.md +91 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/imodel-components-react/UiIModelComponents.d.ts +28 -28
  4. package/lib/cjs/imodel-components-react/UiIModelComponents.js +79 -79
  5. package/lib/cjs/imodel-components-react/UiIModelComponents.js.map +1 -1
  6. package/lib/cjs/imodel-components-react/color/AlphaSlider.d.ts +36 -36
  7. package/lib/cjs/imodel-components-react/color/AlphaSlider.js +186 -186
  8. package/lib/cjs/imodel-components-react/color/AlphaSlider.js.map +1 -1
  9. package/lib/cjs/imodel-components-react/color/AlphaSlider.scss +63 -63
  10. package/lib/cjs/imodel-components-react/color/ColorPickerButton.d.ts +37 -37
  11. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js +107 -107
  12. package/lib/cjs/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  13. package/lib/cjs/imodel-components-react/color/ColorPickerButton.scss +92 -90
  14. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.d.ts +23 -23
  15. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js +74 -74
  16. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  17. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.d.ts +21 -21
  18. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js +145 -145
  19. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  20. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.scss +93 -93
  21. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts +44 -44
  22. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js +137 -137
  23. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  24. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.scss +64 -63
  25. package/lib/cjs/imodel-components-react/color/HueSlider.d.ts +22 -22
  26. package/lib/cjs/imodel-components-react/color/HueSlider.js +199 -199
  27. package/lib/cjs/imodel-components-react/color/HueSlider.js.map +1 -1
  28. package/lib/cjs/imodel-components-react/color/HueSlider.scss +61 -61
  29. package/lib/cjs/imodel-components-react/color/SaturationPicker.d.ts +20 -20
  30. package/lib/cjs/imodel-components-react/color/SaturationPicker.js +213 -213
  31. package/lib/cjs/imodel-components-react/color/SaturationPicker.js.map +1 -1
  32. package/lib/cjs/imodel-components-react/color/SaturationPicker.scss +35 -35
  33. package/lib/cjs/imodel-components-react/color/Swatch.d.ts +22 -22
  34. package/lib/cjs/imodel-components-react/color/Swatch.js +60 -60
  35. package/lib/cjs/imodel-components-react/color/Swatch.js.map +1 -1
  36. package/lib/cjs/imodel-components-react/color/Swatch.scss +24 -23
  37. package/lib/cjs/imodel-components-react/color/getCSSColorFromDef.d.ts +6 -6
  38. package/lib/cjs/imodel-components-react/color/getCSSColorFromDef.js +23 -23
  39. package/lib/cjs/imodel-components-react/color/getCSSColorFromDef.js.map +1 -1
  40. package/lib/cjs/imodel-components-react/editors/ColorEditor.d.ts +44 -44
  41. package/lib/cjs/imodel-components-react/editors/ColorEditor.js +151 -151
  42. package/lib/cjs/imodel-components-react/editors/ColorEditor.js.map +1 -1
  43. package/lib/cjs/imodel-components-react/editors/ColorEditor.scss +19 -18
  44. package/lib/cjs/imodel-components-react/editors/WeightEditor.d.ts +47 -47
  45. package/lib/cjs/imodel-components-react/editors/WeightEditor.js +160 -160
  46. package/lib/cjs/imodel-components-react/editors/WeightEditor.js.map +1 -1
  47. package/lib/cjs/imodel-components-react/editors/WeightEditor.scss +17 -16
  48. package/lib/cjs/imodel-components-react/inputs/QuantityInput.d.ts +25 -25
  49. package/lib/cjs/imodel-components-react/inputs/QuantityInput.js +96 -96
  50. package/lib/cjs/imodel-components-react/inputs/QuantityInput.js.map +1 -1
  51. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.d.ts +44 -44
  52. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js +265 -265
  53. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  54. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.scss +107 -107
  55. package/lib/cjs/imodel-components-react/lineweight/Swatch.d.ts +33 -33
  56. package/lib/cjs/imodel-components-react/lineweight/Swatch.js +85 -85
  57. package/lib/cjs/imodel-components-react/lineweight/Swatch.js.map +1 -1
  58. package/lib/cjs/imodel-components-react/lineweight/Swatch.scss +49 -48
  59. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.d.ts +60 -60
  60. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.js +159 -159
  61. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.js.map +1 -1
  62. package/lib/cjs/imodel-components-react/lineweight/WeightPickerButton.scss +53 -52
  63. package/lib/cjs/imodel-components-react/navigationaids/Cube.d.ts +45 -45
  64. package/lib/cjs/imodel-components-react/navigationaids/Cube.js +127 -127
  65. package/lib/cjs/imodel-components-react/navigationaids/Cube.js.map +1 -1
  66. package/lib/cjs/imodel-components-react/navigationaids/Cube.scss +19 -19
  67. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.d.ts +174 -174
  68. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.d.ts.map +1 -1
  69. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js +634 -634
  70. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  71. package/lib/cjs/imodel-components-react/navigationaids/CubeNavigationAid.scss +181 -182
  72. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.d.ts +145 -145
  73. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.js +647 -647
  74. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.js.map +1 -1
  75. package/lib/cjs/imodel-components-react/navigationaids/DrawingNavigationAid.scss +134 -134
  76. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.d.ts +26 -26
  77. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js +99 -99
  78. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
  79. package/lib/cjs/imodel-components-react/quantityformat/FormatPanel.scss +65 -63
  80. package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.d.ts +17 -17
  81. package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.js +53 -53
  82. package/lib/cjs/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
  83. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.d.ts +18 -18
  84. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js +83 -83
  85. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  86. package/lib/cjs/imodel-components-react/quantityformat/FormatType.d.ts +17 -17
  87. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js +86 -86
  88. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  89. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.d.ts +17 -17
  90. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js +109 -109
  91. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  92. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.d.ts +19 -19
  93. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js +133 -133
  94. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  95. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.d.ts +21 -21
  96. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js +184 -184
  97. package/lib/cjs/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
  98. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts +22 -22
  99. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  100. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js +154 -145
  101. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  102. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.d.ts +17 -17
  103. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js +59 -59
  104. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  105. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.d.ts +17 -17
  106. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js +47 -47
  107. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  108. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.d.ts +16 -16
  109. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js +54 -54
  110. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  111. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.d.ts +18 -18
  112. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js +48 -48
  113. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  114. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.d.ts +17 -17
  115. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js +50 -50
  116. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  117. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.d.ts +17 -17
  118. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +58 -58
  119. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  120. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.d.ts +17 -17
  121. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js +47 -47
  122. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  123. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.d.ts +17 -17
  124. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js +56 -56
  125. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  126. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.d.ts +17 -17
  127. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +95 -95
  128. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  129. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.d.ts +23 -23
  130. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js +119 -119
  131. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  132. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.d.ts +52 -52
  133. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.js +143 -143
  134. package/lib/cjs/imodel-components-react/timeline/BaseSolarDataProvider.js.map +1 -1
  135. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.d.ts +31 -31
  136. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.js +69 -69
  137. package/lib/cjs/imodel-components-react/timeline/BaseTimelineDataProvider.js.map +1 -1
  138. package/lib/cjs/imodel-components-react/timeline/InlineEdit.d.ts +27 -27
  139. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js +81 -81
  140. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  141. package/lib/cjs/imodel-components-react/timeline/InlineEdit.scss +26 -26
  142. package/lib/cjs/imodel-components-react/timeline/PlayerButton.d.ts +33 -33
  143. package/lib/cjs/imodel-components-react/timeline/PlayerButton.js +91 -91
  144. package/lib/cjs/imodel-components-react/timeline/PlayerButton.js.map +1 -1
  145. package/lib/cjs/imodel-components-react/timeline/PlayerButton.scss +26 -31
  146. package/lib/cjs/imodel-components-react/timeline/Scrubber.d.ts +54 -54
  147. package/lib/cjs/imodel-components-react/timeline/Scrubber.js +191 -191
  148. package/lib/cjs/imodel-components-react/timeline/Scrubber.js.map +1 -1
  149. package/lib/cjs/imodel-components-react/timeline/Scrubber.scss +107 -112
  150. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.d.ts +77 -77
  151. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.js +424 -424
  152. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.js.map +1 -1
  153. package/lib/cjs/imodel-components-react/timeline/SolarTimeline.scss +358 -356
  154. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.d.ts +15 -15
  155. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.js +54 -54
  156. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.js.map +1 -1
  157. package/lib/cjs/imodel-components-react/timeline/SpeedTimeline.scss +39 -39
  158. package/lib/cjs/imodel-components-react/timeline/Timeline.scss +164 -164
  159. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.d.ts +133 -133
  160. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.js +358 -358
  161. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.js.map +1 -1
  162. package/lib/cjs/imodel-components-react/timeline/TimelineComponent.scss +164 -164
  163. package/lib/cjs/imodel-components-react/timeline/interfaces.d.ts +174 -174
  164. package/lib/cjs/imodel-components-react/timeline/interfaces.js +45 -45
  165. package/lib/cjs/imodel-components-react/timeline/interfaces.js.map +1 -1
  166. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts +42 -42
  167. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js +274 -274
  168. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  169. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.d.ts +106 -106
  170. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js +105 -105
  171. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  172. package/lib/cjs/imodel-components-react.d.ts +82 -82
  173. package/lib/cjs/imodel-components-react.js +101 -101
  174. package/lib/cjs/imodel-components-react.js.map +1 -1
  175. package/lib/esm/imodel-components-react/UiIModelComponents.d.ts +28 -28
  176. package/lib/esm/imodel-components-react/UiIModelComponents.js +75 -75
  177. package/lib/esm/imodel-components-react/UiIModelComponents.js.map +1 -1
  178. package/lib/esm/imodel-components-react/color/AlphaSlider.d.ts +36 -36
  179. package/lib/esm/imodel-components-react/color/AlphaSlider.js +160 -160
  180. package/lib/esm/imodel-components-react/color/AlphaSlider.js.map +1 -1
  181. package/lib/esm/imodel-components-react/color/AlphaSlider.scss +63 -63
  182. package/lib/esm/imodel-components-react/color/ColorPickerButton.d.ts +37 -37
  183. package/lib/esm/imodel-components-react/color/ColorPickerButton.js +82 -82
  184. package/lib/esm/imodel-components-react/color/ColorPickerButton.js.map +1 -1
  185. package/lib/esm/imodel-components-react/color/ColorPickerButton.scss +92 -90
  186. package/lib/esm/imodel-components-react/color/ColorPickerDialog.d.ts +23 -23
  187. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js +51 -51
  188. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  189. package/lib/esm/imodel-components-react/color/ColorPickerPanel.d.ts +21 -21
  190. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js +122 -122
  191. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  192. package/lib/esm/imodel-components-react/color/ColorPickerPanel.scss +93 -93
  193. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts +44 -44
  194. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js +112 -112
  195. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  196. package/lib/esm/imodel-components-react/color/ColorPickerPopup.scss +64 -63
  197. package/lib/esm/imodel-components-react/color/HueSlider.d.ts +22 -22
  198. package/lib/esm/imodel-components-react/color/HueSlider.js +173 -173
  199. package/lib/esm/imodel-components-react/color/HueSlider.js.map +1 -1
  200. package/lib/esm/imodel-components-react/color/HueSlider.scss +61 -61
  201. package/lib/esm/imodel-components-react/color/SaturationPicker.d.ts +20 -20
  202. package/lib/esm/imodel-components-react/color/SaturationPicker.js +187 -187
  203. package/lib/esm/imodel-components-react/color/SaturationPicker.js.map +1 -1
  204. package/lib/esm/imodel-components-react/color/SaturationPicker.scss +35 -35
  205. package/lib/esm/imodel-components-react/color/Swatch.d.ts +22 -22
  206. package/lib/esm/imodel-components-react/color/Swatch.js +34 -34
  207. package/lib/esm/imodel-components-react/color/Swatch.js.map +1 -1
  208. package/lib/esm/imodel-components-react/color/Swatch.scss +24 -23
  209. package/lib/esm/imodel-components-react/color/getCSSColorFromDef.d.ts +6 -6
  210. package/lib/esm/imodel-components-react/color/getCSSColorFromDef.js +19 -19
  211. package/lib/esm/imodel-components-react/color/getCSSColorFromDef.js.map +1 -1
  212. package/lib/esm/imodel-components-react/editors/ColorEditor.d.ts +44 -44
  213. package/lib/esm/imodel-components-react/editors/ColorEditor.js +124 -124
  214. package/lib/esm/imodel-components-react/editors/ColorEditor.js.map +1 -1
  215. package/lib/esm/imodel-components-react/editors/ColorEditor.scss +19 -18
  216. package/lib/esm/imodel-components-react/editors/WeightEditor.d.ts +47 -47
  217. package/lib/esm/imodel-components-react/editors/WeightEditor.js +133 -133
  218. package/lib/esm/imodel-components-react/editors/WeightEditor.js.map +1 -1
  219. package/lib/esm/imodel-components-react/editors/WeightEditor.scss +17 -16
  220. package/lib/esm/imodel-components-react/inputs/QuantityInput.d.ts +25 -25
  221. package/lib/esm/imodel-components-react/inputs/QuantityInput.js +70 -70
  222. package/lib/esm/imodel-components-react/inputs/QuantityInput.js.map +1 -1
  223. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.d.ts +44 -44
  224. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js +240 -240
  225. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  226. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.scss +107 -107
  227. package/lib/esm/imodel-components-react/lineweight/Swatch.d.ts +33 -33
  228. package/lib/esm/imodel-components-react/lineweight/Swatch.js +59 -59
  229. package/lib/esm/imodel-components-react/lineweight/Swatch.js.map +1 -1
  230. package/lib/esm/imodel-components-react/lineweight/Swatch.scss +49 -48
  231. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.d.ts +60 -60
  232. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.js +133 -133
  233. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.js.map +1 -1
  234. package/lib/esm/imodel-components-react/lineweight/WeightPickerButton.scss +53 -52
  235. package/lib/esm/imodel-components-react/navigationaids/Cube.d.ts +45 -45
  236. package/lib/esm/imodel-components-react/navigationaids/Cube.js +100 -100
  237. package/lib/esm/imodel-components-react/navigationaids/Cube.js.map +1 -1
  238. package/lib/esm/imodel-components-react/navigationaids/Cube.scss +19 -19
  239. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.d.ts +174 -174
  240. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.d.ts.map +1 -1
  241. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js +606 -606
  242. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.js.map +1 -1
  243. package/lib/esm/imodel-components-react/navigationaids/CubeNavigationAid.scss +181 -182
  244. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.d.ts +145 -145
  245. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.js +620 -620
  246. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.js.map +1 -1
  247. package/lib/esm/imodel-components-react/navigationaids/DrawingNavigationAid.scss +134 -134
  248. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.d.ts +26 -26
  249. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js +76 -76
  250. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.js.map +1 -1
  251. package/lib/esm/imodel-components-react/quantityformat/FormatPanel.scss +65 -63
  252. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.d.ts +17 -17
  253. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js +30 -30
  254. package/lib/esm/imodel-components-react/quantityformat/FormatPrecision.js.map +1 -1
  255. package/lib/esm/imodel-components-react/quantityformat/FormatSample.d.ts +18 -18
  256. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js +60 -60
  257. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  258. package/lib/esm/imodel-components-react/quantityformat/FormatType.d.ts +17 -17
  259. package/lib/esm/imodel-components-react/quantityformat/FormatType.js +63 -63
  260. package/lib/esm/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  261. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.d.ts +17 -17
  262. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js +83 -83
  263. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  264. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.d.ts +19 -19
  265. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js +110 -110
  266. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  267. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.d.ts +21 -21
  268. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js +158 -158
  269. package/lib/esm/imodel-components-react/quantityformat/MiscFormatOptions.js.map +1 -1
  270. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts +22 -22
  271. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  272. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js +131 -122
  273. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  274. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.d.ts +17 -17
  275. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js +36 -36
  276. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  277. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.d.ts +17 -17
  278. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js +24 -24
  279. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  280. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.d.ts +16 -16
  281. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js +31 -31
  282. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  283. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.d.ts +18 -18
  284. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js +25 -25
  285. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  286. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.d.ts +17 -17
  287. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js +27 -27
  288. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  289. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.d.ts +17 -17
  290. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +35 -35
  291. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  292. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.d.ts +17 -17
  293. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js +24 -24
  294. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  295. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.d.ts +17 -17
  296. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js +33 -33
  297. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  298. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.d.ts +17 -17
  299. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js +69 -69
  300. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSeparator.js.map +1 -1
  301. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.d.ts +23 -23
  302. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js +96 -96
  303. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  304. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.d.ts +52 -52
  305. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.js +139 -139
  306. package/lib/esm/imodel-components-react/timeline/BaseSolarDataProvider.js.map +1 -1
  307. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.d.ts +31 -31
  308. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.js +65 -65
  309. package/lib/esm/imodel-components-react/timeline/BaseTimelineDataProvider.js.map +1 -1
  310. package/lib/esm/imodel-components-react/timeline/InlineEdit.d.ts +27 -27
  311. package/lib/esm/imodel-components-react/timeline/InlineEdit.js +55 -55
  312. package/lib/esm/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  313. package/lib/esm/imodel-components-react/timeline/InlineEdit.scss +26 -26
  314. package/lib/esm/imodel-components-react/timeline/PlayerButton.d.ts +33 -33
  315. package/lib/esm/imodel-components-react/timeline/PlayerButton.js +64 -64
  316. package/lib/esm/imodel-components-react/timeline/PlayerButton.js.map +1 -1
  317. package/lib/esm/imodel-components-react/timeline/PlayerButton.scss +26 -31
  318. package/lib/esm/imodel-components-react/timeline/Scrubber.d.ts +54 -54
  319. package/lib/esm/imodel-components-react/timeline/Scrubber.js +164 -164
  320. package/lib/esm/imodel-components-react/timeline/Scrubber.js.map +1 -1
  321. package/lib/esm/imodel-components-react/timeline/Scrubber.scss +107 -112
  322. package/lib/esm/imodel-components-react/timeline/SolarTimeline.d.ts +77 -77
  323. package/lib/esm/imodel-components-react/timeline/SolarTimeline.js +398 -398
  324. package/lib/esm/imodel-components-react/timeline/SolarTimeline.js.map +1 -1
  325. package/lib/esm/imodel-components-react/timeline/SolarTimeline.scss +358 -356
  326. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.d.ts +15 -15
  327. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.js +28 -28
  328. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.js.map +1 -1
  329. package/lib/esm/imodel-components-react/timeline/SpeedTimeline.scss +39 -39
  330. package/lib/esm/imodel-components-react/timeline/Timeline.scss +164 -164
  331. package/lib/esm/imodel-components-react/timeline/TimelineComponent.d.ts +133 -133
  332. package/lib/esm/imodel-components-react/timeline/TimelineComponent.js +332 -332
  333. package/lib/esm/imodel-components-react/timeline/TimelineComponent.js.map +1 -1
  334. package/lib/esm/imodel-components-react/timeline/TimelineComponent.scss +164 -164
  335. package/lib/esm/imodel-components-react/timeline/interfaces.d.ts +174 -174
  336. package/lib/esm/imodel-components-react/timeline/interfaces.js +42 -42
  337. package/lib/esm/imodel-components-react/timeline/interfaces.js.map +1 -1
  338. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts +42 -42
  339. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js +251 -251
  340. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  341. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.d.ts +106 -106
  342. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js +95 -95
  343. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  344. package/lib/esm/imodel-components-react.d.ts +82 -82
  345. package/lib/esm/imodel-components-react.js +87 -87
  346. package/lib/esm/imodel-components-react.js.map +1 -1
  347. package/lib/public/locales/en/UiIModelComponents.json +139 -139
  348. package/package.json +34 -26
@@ -1,241 +1,241 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /** @packageDocumentation
6
- * @module Inputs
7
- */
8
- import "./QuantityNumberInput.scss";
9
- import classnames from "classnames";
10
- import * as React from "react";
11
- import { WebFontIcon } from "@itwin/core-react";
12
- import { SpecialKey } from "@itwin/appui-abstract";
13
- import { IModelApp } from "@itwin/core-frontend";
14
- import { DecimalPrecision, FormatterSpec, FormatTraits, FormatType, Parser } from "@itwin/core-quantity";
15
- import { Input } from "@itwin/itwinui-react";
16
- /** adjust formatter spec to show only primary unit without a label. */
17
- function adjustFormatterSpec(formatterSpec) {
18
- if (undefined === formatterSpec)
19
- return formatterSpec;
20
- const singleUnitConversion = [];
21
- singleUnitConversion.push(formatterSpec.unitConversions[0]);
22
- const newFormat = formatterSpec.format.clone({
23
- showOnlyPrimaryUnit: true,
24
- traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,
25
- type: FormatType.Decimal,
26
- precision: FormatType.Decimal !== formatterSpec.format.type ? DecimalPrecision.Four : formatterSpec.format.precision,
27
- });
28
- return new FormatterSpec("single-value", newFormat, singleUnitConversion, formatterSpec.persistenceUnit);
29
- }
30
- function convertValueFromDisplayToPersistence(value, unitConversions, unit) {
31
- // istanbul ignore next
32
- if (!unitConversions || 0 === unitConversions.length)
33
- return value;
34
- const unitConversion = unitConversions.find((spec) => spec.name === unit.name);
35
- // istanbul ignore next
36
- if (!unitConversion)
37
- return value;
38
- const convertedValue = (value * unitConversion.conversion.factor) + unitConversion.conversion.offset;
39
- return convertedValue;
40
- }
41
- function getUnitLabel(parserSpec) {
42
- if (undefined === parserSpec)
43
- return "";
44
- const format = parserSpec.format;
45
- // istanbul ignore else
46
- if (!format.units || !format.units[0])
47
- return parserSpec.outUnit.label;
48
- const [unit, label] = format.units[0];
49
- // istanbul ignore next
50
- return label !== null && label !== void 0 ? label : unit.label;
51
- }
52
- const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuantityNumberInput(props, ref) {
53
- const { containerClassName, persistenceValue, min, max, onChange, onBlur, onKeyDown, step, snap, showTouchButtons, quantityType, ...otherProps } = props;
54
- const rawValueRef = React.useRef(persistenceValue);
55
- const [formatterSpec, setFormatterSpec] = React.useState(() => adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
56
- const [parserSpec, setParserSpec] = React.useState(() => IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
57
- const formatValue = React.useCallback((value) => {
58
- if (undefined === value)
59
- return "";
60
- // istanbul ignore else
61
- if (formatterSpec) {
62
- return formatterSpec.applyFormatting(value);
63
- }
64
- // istanbul ignore next
65
- return value.toFixed(2);
66
- }, [formatterSpec]);
67
- const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));
68
- const [formattedValue, setFormattedValue] = React.useState(() => lastFormattedValueRef.current);
69
- React.useEffect(() => {
70
- const handleUnitSystemChanged = (() => {
71
- setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
72
- setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
73
- });
74
- IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(handleUnitSystemChanged);
75
- return () => {
76
- IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(handleUnitSystemChanged);
77
- };
78
- }, [quantityType]);
79
- React.useEffect(() => {
80
- const handleUnitSystemChanged = ((args) => {
81
- const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);
82
- // istanbul ignore else
83
- if (args.quantityType === quantityKey) {
84
- setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
85
- setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
86
- }
87
- });
88
- IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(handleUnitSystemChanged);
89
- return () => {
90
- IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(handleUnitSystemChanged);
91
- };
92
- }, [quantityType]);
93
- const unitLabel = getUnitLabel(parserSpec);
94
- // See if new initialValue props have changed since component mounted
95
- React.useEffect(() => {
96
- rawValueRef.current = persistenceValue;
97
- const currentFormattedValue = formatValue(rawValueRef.current);
98
- setFormattedValue(currentFormattedValue);
99
- }, [formatValue, persistenceValue]);
100
- // this is the unprocessed input from user, it is not processed until blur or enter key press
101
- const handleDisplayValueChange = React.useCallback((event) => {
102
- setFormattedValue(event.currentTarget.value);
103
- }, []);
104
- const updateValue = React.useCallback((newValue) => {
105
- let persistedValue = newValue;
106
- // istanbul ignore else
107
- if (parserSpec) {
108
- // convert value from display unit to persistence unit
109
- const [unit] = parserSpec.format.units ? parserSpec.format.units[0] : /* istanbul ignore next */ [parserSpec.outUnit];
110
- persistedValue = convertValueFromDisplayToPersistence(newValue, parserSpec.unitConversions, unit);
111
- rawValueRef.current = persistedValue;
112
- }
113
- const newFormattedVal = formatValue(persistedValue);
114
- onChange && onChange(persistedValue);
115
- setFormattedValue(newFormattedVal);
116
- }, [formatValue, onChange, parserSpec]);
117
- /**
118
- * Used internally to parse the argument x to it's numeric representation.
119
- * If the argument cannot be converted to finite number returns 0; If a
120
- * "precision" prop is specified uses it round the number with that
121
- * precision (no fixed precision here because the return value is float, not
122
- * string).
123
- */
124
- const parseInternal = React.useCallback((x) => {
125
- if (!x)
126
- return 0;
127
- let n = parseFloat(x);
128
- // istanbul ignore next
129
- if (isNaN(n) || !isFinite(n)) {
130
- n = 0;
131
- }
132
- const localPrecision = 6; // TODO get a reasonable value from format
133
- const q = Math.pow(10, localPrecision);
134
- const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
135
- const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
136
- n = Math.min(Math.max(n, localMin), localMax);
137
- n = Math.round(n * q) / q;
138
- return n;
139
- }, [min, max]);
140
- const updateValueFromString = React.useCallback((strValue) => {
141
- // istanbul ignore else
142
- if (parserSpec) {
143
- const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(strValue, parserSpec);
144
- // at this point we should have a string value in persistence units without a label
145
- if (Parser.isParsedQuantity(parseResult)) {
146
- const persistedValue = parseResult.value; // in persistence units
147
- // set strValue and let it go through parseInternal which will ensure min/max limits are observed
148
- strValue = formatValue(persistedValue);
149
- }
150
- else {
151
- // istanbul ignore else
152
- if (rawValueRef.current) { // restore last known good value
153
- const lastKnownFormattedVal = formatValue(rawValueRef.current);
154
- setFormattedValue(lastKnownFormattedVal);
155
- return;
156
- }
157
- }
158
- }
159
- const newValue = parseInternal(strValue);
160
- // istanbul ignore else
161
- if (undefined !== newValue)
162
- updateValue(newValue);
163
- }, [formatValue, parseInternal, parserSpec, updateValue]);
164
- const handleBlur = React.useCallback((event) => {
165
- const newVal = parseInternal(event.target.value);
166
- onBlur && onBlur(event);
167
- updateValue(newVal);
168
- }, [parseInternal, updateValue, onBlur]);
169
- const getIncrementValue = React.useCallback((increment) => {
170
- if (typeof step === "function") {
171
- const stepVal = step(increment ? "up" : "down");
172
- return stepVal ? stepVal : 1;
173
- }
174
- return !step ? 1 : step;
175
- }, [step]);
176
- /**
177
- * The internal method that actually sets the new value on the input
178
- */
179
- const applyStep = React.useCallback((increment) => {
180
- const incrementValue = getIncrementValue(increment);
181
- let num = parseInternal(formattedValue) + (increment ? incrementValue : -incrementValue);
182
- if (snap) {
183
- num = Math.round(num / incrementValue) * incrementValue;
184
- }
185
- const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
186
- const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
187
- num = Math.min(Math.max(num, localMin), localMax);
188
- updateValue(num);
189
- }, [formattedValue, getIncrementValue, max, min, parseInternal, snap, updateValue]);
190
- const handleKeyDown = React.useCallback((event) => {
191
- // istanbul ignore else
192
- if (event.key === SpecialKey.Enter) {
193
- updateValueFromString(event.currentTarget.value);
194
- event.preventDefault();
195
- }
196
- else if (event.key === SpecialKey.Escape) {
197
- setFormattedValue(formatValue(rawValueRef.current));
198
- event.preventDefault();
199
- }
200
- else if (event.key === SpecialKey.ArrowDown) {
201
- applyStep(false);
202
- event.preventDefault();
203
- }
204
- else if (event.key === SpecialKey.ArrowUp) {
205
- applyStep(true);
206
- event.preventDefault();
207
- }
208
- onKeyDown && onKeyDown(event);
209
- }, [onKeyDown, updateValueFromString, formatValue, applyStep]);
210
- const handleDownClick = React.useCallback((event) => {
211
- applyStep(false);
212
- event.preventDefault();
213
- }, [applyStep]);
214
- const handleUpClick = React.useCallback((event) => {
215
- applyStep(true);
216
- event.preventDefault();
217
- }, [applyStep]);
218
- // istanbul ignore next
219
- const handleFocus = React.useCallback((event) => {
220
- event.currentTarget.select();
221
- }, []);
222
- const isDisabled = !!otherProps.disabled;
223
- const containerClasses = classnames("component-quantity-number-input-container", containerClassName, showTouchButtons && "component-number-buttons-for-touch", isDisabled && "component-quantity-number-input-disabled");
224
- return (React.createElement("div", { className: containerClasses },
225
- React.createElement("div", { className: "component-quantity-number-input-value-and-buttons-container" },
226
- React.createElement(Input, { ref: ref, value: formattedValue, onChange: handleDisplayValueChange, onKeyDown: handleKeyDown, onBlur: handleBlur, onFocus: handleFocus, size: "small", ...otherProps }),
227
- React.createElement("div", { className: classnames("component-quantity-number-input-buttons-container", showTouchButtons && "component-number-buttons-for-touch") },
228
- React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-up", tabIndex: -1, onClick: handleUpClick },
229
- React.createElement(WebFontIcon, { iconName: "icon-caret-up" })),
230
- React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-down", tabIndex: -1, onClick: handleDownClick },
231
- React.createElement(WebFontIcon, { iconName: "icon-caret-down" })))),
232
- React.createElement("span", { className: "component-quantity-number-input-suffix" }, unitLabel)));
233
- });
234
- /** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's
235
- * "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).
236
- * The control also display buttons to increment and decrement the "displayed" value. The value reported by via the onChange function is in "persistence"
237
- * units that can be stored in the iModel.
238
- * @beta
239
- */
240
- export const QuantityNumberInput = ForwardRefQuantityNumberInput;
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Inputs
7
+ */
8
+ import "./QuantityNumberInput.scss";
9
+ import classnames from "classnames";
10
+ import * as React from "react";
11
+ import { WebFontIcon } from "@itwin/core-react";
12
+ import { SpecialKey } from "@itwin/appui-abstract";
13
+ import { IModelApp } from "@itwin/core-frontend";
14
+ import { DecimalPrecision, FormatterSpec, FormatTraits, FormatType, Parser } from "@itwin/core-quantity";
15
+ import { Input } from "@itwin/itwinui-react";
16
+ /** adjust formatter spec to show only primary unit without a label. */
17
+ function adjustFormatterSpec(formatterSpec) {
18
+ if (undefined === formatterSpec)
19
+ return formatterSpec;
20
+ const singleUnitConversion = [];
21
+ singleUnitConversion.push(formatterSpec.unitConversions[0]);
22
+ const newFormat = formatterSpec.format.clone({
23
+ showOnlyPrimaryUnit: true,
24
+ traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,
25
+ type: FormatType.Decimal,
26
+ precision: FormatType.Decimal !== formatterSpec.format.type ? DecimalPrecision.Four : formatterSpec.format.precision,
27
+ });
28
+ return new FormatterSpec("single-value", newFormat, singleUnitConversion, formatterSpec.persistenceUnit);
29
+ }
30
+ function convertValueFromDisplayToPersistence(value, unitConversions, unit) {
31
+ // istanbul ignore next
32
+ if (!unitConversions || 0 === unitConversions.length)
33
+ return value;
34
+ const unitConversion = unitConversions.find((spec) => spec.name === unit.name);
35
+ // istanbul ignore next
36
+ if (!unitConversion)
37
+ return value;
38
+ const convertedValue = (value * unitConversion.conversion.factor) + unitConversion.conversion.offset;
39
+ return convertedValue;
40
+ }
41
+ function getUnitLabel(parserSpec) {
42
+ if (undefined === parserSpec)
43
+ return "";
44
+ const format = parserSpec.format;
45
+ // istanbul ignore else
46
+ if (!format.units || !format.units[0])
47
+ return parserSpec.outUnit.label;
48
+ const [unit, label] = format.units[0];
49
+ // istanbul ignore next
50
+ return label !== null && label !== void 0 ? label : unit.label;
51
+ }
52
+ const ForwardRefQuantityNumberInput = React.forwardRef(function ForwardRefQuantityNumberInput(props, ref) {
53
+ const { containerClassName, persistenceValue, min, max, onChange, onBlur, onKeyDown, step, snap, showTouchButtons, quantityType, ...otherProps } = props;
54
+ const rawValueRef = React.useRef(persistenceValue);
55
+ const [formatterSpec, setFormatterSpec] = React.useState(() => adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
56
+ const [parserSpec, setParserSpec] = React.useState(() => IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
57
+ const formatValue = React.useCallback((value) => {
58
+ if (undefined === value)
59
+ return "";
60
+ // istanbul ignore else
61
+ if (formatterSpec) {
62
+ return formatterSpec.applyFormatting(value);
63
+ }
64
+ // istanbul ignore next
65
+ return value.toFixed(2);
66
+ }, [formatterSpec]);
67
+ const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));
68
+ const [formattedValue, setFormattedValue] = React.useState(() => lastFormattedValueRef.current);
69
+ React.useEffect(() => {
70
+ const handleUnitSystemChanged = (() => {
71
+ setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
72
+ setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
73
+ });
74
+ IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(handleUnitSystemChanged);
75
+ return () => {
76
+ IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(handleUnitSystemChanged);
77
+ };
78
+ }, [quantityType]);
79
+ React.useEffect(() => {
80
+ const handleUnitSystemChanged = ((args) => {
81
+ const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);
82
+ // istanbul ignore else
83
+ if (args.quantityType === quantityKey) {
84
+ setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));
85
+ setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));
86
+ }
87
+ });
88
+ IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(handleUnitSystemChanged);
89
+ return () => {
90
+ IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(handleUnitSystemChanged);
91
+ };
92
+ }, [quantityType]);
93
+ const unitLabel = getUnitLabel(parserSpec);
94
+ // See if new initialValue props have changed since component mounted
95
+ React.useEffect(() => {
96
+ rawValueRef.current = persistenceValue;
97
+ const currentFormattedValue = formatValue(rawValueRef.current);
98
+ setFormattedValue(currentFormattedValue);
99
+ }, [formatValue, persistenceValue]);
100
+ // this is the unprocessed input from user, it is not processed until blur or enter key press
101
+ const handleDisplayValueChange = React.useCallback((event) => {
102
+ setFormattedValue(event.currentTarget.value);
103
+ }, []);
104
+ const updateValue = React.useCallback((newValue) => {
105
+ let persistedValue = newValue;
106
+ // istanbul ignore else
107
+ if (parserSpec) {
108
+ // convert value from display unit to persistence unit
109
+ const [unit] = parserSpec.format.units ? parserSpec.format.units[0] : /* istanbul ignore next */ [parserSpec.outUnit];
110
+ persistedValue = convertValueFromDisplayToPersistence(newValue, parserSpec.unitConversions, unit);
111
+ rawValueRef.current = persistedValue;
112
+ }
113
+ const newFormattedVal = formatValue(persistedValue);
114
+ onChange && onChange(persistedValue);
115
+ setFormattedValue(newFormattedVal);
116
+ }, [formatValue, onChange, parserSpec]);
117
+ /**
118
+ * Used internally to parse the argument x to it's numeric representation.
119
+ * If the argument cannot be converted to finite number returns 0; If a
120
+ * "precision" prop is specified uses it round the number with that
121
+ * precision (no fixed precision here because the return value is float, not
122
+ * string).
123
+ */
124
+ const parseInternal = React.useCallback((x) => {
125
+ if (!x)
126
+ return 0;
127
+ let n = parseFloat(x);
128
+ // istanbul ignore next
129
+ if (isNaN(n) || !isFinite(n)) {
130
+ n = 0;
131
+ }
132
+ const localPrecision = 6; // TODO get a reasonable value from format
133
+ const q = Math.pow(10, localPrecision);
134
+ const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
135
+ const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
136
+ n = Math.min(Math.max(n, localMin), localMax);
137
+ n = Math.round(n * q) / q;
138
+ return n;
139
+ }, [min, max]);
140
+ const updateValueFromString = React.useCallback((strValue) => {
141
+ // istanbul ignore else
142
+ if (parserSpec) {
143
+ const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(strValue, parserSpec);
144
+ // at this point we should have a string value in persistence units without a label
145
+ if (Parser.isParsedQuantity(parseResult)) {
146
+ const persistedValue = parseResult.value; // in persistence units
147
+ // set strValue and let it go through parseInternal which will ensure min/max limits are observed
148
+ strValue = formatValue(persistedValue);
149
+ }
150
+ else {
151
+ // istanbul ignore else
152
+ if (rawValueRef.current) { // restore last known good value
153
+ const lastKnownFormattedVal = formatValue(rawValueRef.current);
154
+ setFormattedValue(lastKnownFormattedVal);
155
+ return;
156
+ }
157
+ }
158
+ }
159
+ const newValue = parseInternal(strValue);
160
+ // istanbul ignore else
161
+ if (undefined !== newValue)
162
+ updateValue(newValue);
163
+ }, [formatValue, parseInternal, parserSpec, updateValue]);
164
+ const handleBlur = React.useCallback((event) => {
165
+ const newVal = parseInternal(event.target.value);
166
+ onBlur && onBlur(event);
167
+ updateValue(newVal);
168
+ }, [parseInternal, updateValue, onBlur]);
169
+ const getIncrementValue = React.useCallback((increment) => {
170
+ if (typeof step === "function") {
171
+ const stepVal = step(increment ? "up" : "down");
172
+ return stepVal ? stepVal : 1;
173
+ }
174
+ return !step ? 1 : step;
175
+ }, [step]);
176
+ /**
177
+ * The internal method that actually sets the new value on the input
178
+ */
179
+ const applyStep = React.useCallback((increment) => {
180
+ const incrementValue = getIncrementValue(increment);
181
+ let num = parseInternal(formattedValue) + (increment ? incrementValue : -incrementValue);
182
+ if (snap) {
183
+ num = Math.round(num / incrementValue) * incrementValue;
184
+ }
185
+ const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;
186
+ const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;
187
+ num = Math.min(Math.max(num, localMin), localMax);
188
+ updateValue(num);
189
+ }, [formattedValue, getIncrementValue, max, min, parseInternal, snap, updateValue]);
190
+ const handleKeyDown = React.useCallback((event) => {
191
+ // istanbul ignore else
192
+ if (event.key === SpecialKey.Enter) {
193
+ updateValueFromString(event.currentTarget.value);
194
+ event.preventDefault();
195
+ }
196
+ else if (event.key === SpecialKey.Escape) {
197
+ setFormattedValue(formatValue(rawValueRef.current));
198
+ event.preventDefault();
199
+ }
200
+ else if (event.key === SpecialKey.ArrowDown) {
201
+ applyStep(false);
202
+ event.preventDefault();
203
+ }
204
+ else if (event.key === SpecialKey.ArrowUp) {
205
+ applyStep(true);
206
+ event.preventDefault();
207
+ }
208
+ onKeyDown && onKeyDown(event);
209
+ }, [onKeyDown, updateValueFromString, formatValue, applyStep]);
210
+ const handleDownClick = React.useCallback((event) => {
211
+ applyStep(false);
212
+ event.preventDefault();
213
+ }, [applyStep]);
214
+ const handleUpClick = React.useCallback((event) => {
215
+ applyStep(true);
216
+ event.preventDefault();
217
+ }, [applyStep]);
218
+ // istanbul ignore next
219
+ const handleFocus = React.useCallback((event) => {
220
+ event.currentTarget.select();
221
+ }, []);
222
+ const isDisabled = !!otherProps.disabled;
223
+ const containerClasses = classnames("component-quantity-number-input-container", containerClassName, showTouchButtons && "component-number-buttons-for-touch", isDisabled && "component-quantity-number-input-disabled");
224
+ return (React.createElement("div", { className: containerClasses },
225
+ React.createElement("div", { className: "component-quantity-number-input-value-and-buttons-container" },
226
+ React.createElement(Input, { ref: ref, value: formattedValue, onChange: handleDisplayValueChange, onKeyDown: handleKeyDown, onBlur: handleBlur, onFocus: handleFocus, size: "small", ...otherProps }),
227
+ React.createElement("div", { className: classnames("component-quantity-number-input-buttons-container", showTouchButtons && "component-number-buttons-for-touch") },
228
+ React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-up", tabIndex: -1, onClick: handleUpClick },
229
+ React.createElement(WebFontIcon, { iconName: "icon-caret-up" })),
230
+ React.createElement("div", { className: "component-quantity-number-input-button component-quantity-number-input-button-down", tabIndex: -1, onClick: handleDownClick },
231
+ React.createElement(WebFontIcon, { iconName: "icon-caret-down" })))),
232
+ React.createElement("span", { className: "component-quantity-number-input-suffix" }, unitLabel)));
233
+ });
234
+ /** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's
235
+ * "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).
236
+ * The control also display buttons to increment and decrement the "displayed" value. The value reported by via the onChange function is in "persistence"
237
+ * units that can be stored in the iModel.
238
+ * @beta
239
+ */
240
+ export const QuantityNumberInput = ForwardRefQuantityNumberInput;
241
241
  //# sourceMappingURL=QuantityNumberInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"QuantityNumberInput.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityNumberInput.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,4BAA4B,CAAC;AACpC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAA+C,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAA6C,MAAM,sBAAsB,CAAC;AACpJ,OAAO,EAAE,KAAK,EAAc,MAAM,sBAAsB,CAAC;AAkC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OAAO,EAAE,eAAe;oBACxI,oBAAC,WAAW,IAAC,QAAQ,EAAC,iBAAiB,GAAG,CACtC,CACF,CACF;QACN,8BAAM,SAAS,EAAC,wCAAwC,IAAE,SAAS,CAAQ,CACtE,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA4D,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 { WebFontIcon } from \"@itwin/core-react\";\nimport { SpecialKey } from \"@itwin/appui-abstract\";\nimport { IModelApp, QuantityFormatsChangedArgs, QuantityTypeArg } from \"@itwin/core-frontend\";\nimport { DecimalPrecision, FormatterSpec, FormatTraits, FormatType, Parser, ParserSpec, UnitConversionSpec, UnitProps } from \"@itwin/core-quantity\";\nimport { Input, InputProps } from \"@itwin/itwinui-react\";\n\n/** Step function prototype for [[QuantityNumberInput]] component\n * @beta\n */\nexport type StepFunctionProp = number | ((direction: string) => number | undefined);\n\n/** Properties for the [[QuantityNumberInput]] component\n * @beta\n */\nexport interface QuantityNumberInputProps extends Omit<InputProps, \"value\" | \"min\" | \"max\" | \"step\" | \"onFocus\" | \"onChange\"> {\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)\n 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: FormatType.Decimal !== formatterSpec.format.type ? DecimalPrecision.Four : formatterSpec.format.precision,\n });\n return new FormatterSpec(\"single-value\", newFormat, singleUnitConversion, formatterSpec.persistenceUnit);\n}\n\nfunction convertValueFromDisplayToPersistence(value: number, unitConversions: UnitConversionSpec[] | undefined, unit: UnitProps) {\n // istanbul ignore next\n if (!unitConversions || 0 === unitConversions.length)\n return value;\n\n const unitConversion = unitConversions.find((spec) => spec.name === unit.name);\n // istanbul ignore next\n if (!unitConversion)\n return value;\n\n const convertedValue = (value * unitConversion.conversion.factor) + unitConversion.conversion.offset;\n return convertedValue;\n}\n\nfunction getUnitLabel(parserSpec: ParserSpec | undefined) {\n if (undefined === parserSpec)\n return \"\";\n\n const format = parserSpec.format;\n // istanbul ignore else\n if (!format.units || !format.units[0])\n 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<HTMLInputElement, QuantityNumberInputProps>(\n function ForwardRefQuantityNumberInput(props, ref) {\n\n const { containerClassName, persistenceValue, min, max,\n onChange, onBlur, onKeyDown, step, snap, showTouchButtons, quantityType, ...otherProps } = props;\n const rawValueRef = React.useRef(persistenceValue);\n\n const [formatterSpec, setFormatterSpec] = React.useState(() => adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));\n const [parserSpec, setParserSpec] = React.useState(() => IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));\n\n const formatValue = React.useCallback((value: number | undefined) => {\n if (undefined === value)\n 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 }, [formatterSpec]);\n\n const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));\n const [formattedValue, setFormattedValue] = React.useState(() => lastFormattedValueRef.current);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = ((): void => {\n setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));\n setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));\n });\n\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(handleUnitSystemChanged);\n return () => {\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(handleUnitSystemChanged);\n };\n }, [quantityType]);\n\n React.useEffect(() => {\n const handleUnitSystemChanged = ((args: QuantityFormatsChangedArgs): void => {\n const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\n // istanbul ignore else\n if (args.quantityType === quantityKey) {\n setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));\n setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));\n }\n });\n\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(handleUnitSystemChanged);\n return () => {\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(handleUnitSystemChanged);\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((event: React.ChangeEvent<HTMLInputElement>) => {\n setFormattedValue(event.currentTarget.value);\n }, []);\n\n const updateValue = React.useCallback((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 ? parserSpec.format.units[0] : /* istanbul ignore next */[parserSpec.outUnit];\n persistedValue = convertValueFromDisplayToPersistence(newValue, parserSpec.unitConversions, unit);\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 * 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((x: string | undefined) => {\n if (!x)\n 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 }, [min, max]);\n\n const updateValueFromString = React.useCallback((strValue: string) => {\n // istanbul ignore else\n if (parserSpec) {\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(strValue, parserSpec);\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) { // 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)\n updateValue(newValue);\n }, [formatValue, parseInternal, parserSpec, updateValue]);\n\n const handleBlur = React.useCallback((event: React.FocusEvent<HTMLInputElement>) => {\n const newVal = parseInternal(event.target.value);\n onBlur && onBlur(event);\n updateValue(newVal);\n }, [parseInternal, updateValue, onBlur]);\n\n const getIncrementValue = React.useCallback((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 }, [step]);\n\n /**\n * The internal method that actually sets the new value on the input\n */\n const applyStep = React.useCallback((increment: boolean) => {\n const incrementValue = getIncrementValue(increment);\n\n let num = parseInternal(formattedValue) + (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 }, [formattedValue, getIncrementValue, max, min, parseInternal, snap, updateValue]);\n\n const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === SpecialKey.Enter) {\n updateValueFromString(event.currentTarget.value);\n event.preventDefault();\n } else if (event.key === SpecialKey.Escape) {\n setFormattedValue(formatValue(rawValueRef.current));\n event.preventDefault();\n } else if (event.key === SpecialKey.ArrowDown) {\n applyStep(false);\n event.preventDefault();\n } else if (event.key === SpecialKey.ArrowUp) {\n applyStep(true);\n event.preventDefault();\n }\n onKeyDown && onKeyDown(event);\n }, [onKeyDown, updateValueFromString, formatValue, applyStep]);\n\n const handleDownClick = React.useCallback((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(false);\n event.preventDefault();\n }, [applyStep]);\n\n const handleUpClick = React.useCallback((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\n applyStep(true);\n event.preventDefault();\n }, [applyStep]);\n\n // istanbul ignore next\n const handleFocus = React.useCallback((event: React.FocusEvent<HTMLInputElement>) => {\n event.currentTarget.select();\n }, []);\n\n const isDisabled = !!otherProps.disabled;\n const containerClasses = classnames(\"component-quantity-number-input-container\",\n containerClassName, showTouchButtons && \"component-number-buttons-for-touch\",\n isDisabled && \"component-quantity-number-input-disabled\",\n );\n return (\n <div className={containerClasses} >\n <div className=\"component-quantity-number-input-value-and-buttons-container\">\n <Input ref={ref} value={formattedValue} onChange={handleDisplayValueChange} onKeyDown={handleKeyDown}\n onBlur={handleBlur} onFocus={handleFocus} size=\"small\" {...otherProps} />\n <div className={classnames(\"component-quantity-number-input-buttons-container\", showTouchButtons && \"component-number-buttons-for-touch\")}>\n { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div className=\"component-quantity-number-input-button component-quantity-number-input-button-up\" tabIndex={-1} onClick={handleUpClick}>\n <WebFontIcon iconName=\"icon-caret-up\" />\n </div>\n { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div className=\"component-quantity-number-input-button component-quantity-number-input-button-down\" tabIndex={-1} onClick={handleDownClick}>\n <WebFontIcon iconName=\"icon-caret-down\" />\n </div>\n </div>\n </div>\n <span className=\"component-quantity-number-input-suffix\">{unitLabel}</span>\n </div >\n );\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: (props: QuantityNumberInputProps) => JSX.Element | null = ForwardRefQuantityNumberInput;\n"]}
1
+ {"version":3,"file":"QuantityNumberInput.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/inputs/QuantityNumberInput.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,4BAA4B,CAAC;AACpC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAA+C,MAAM,sBAAsB,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAA6C,MAAM,sBAAsB,CAAC;AACpJ,OAAO,EAAE,KAAK,EAAc,MAAM,sBAAsB,CAAC;AAkCzD,wEAAwE;AACxE,SAAS,mBAAmB,CAAC,aAAwC;IACnE,IAAI,SAAS,KAAK,aAAa;QAC7B,OAAO,aAAa,CAAC;IACvB,MAAM,oBAAoB,GAAyB,EAAE,CAAC;IACtD,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAG,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC;QAC3C,mBAAmB,EAAE,IAAI;QACzB,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,YAAY,GAAG,CAAC,YAAY,CAAC,aAAa;QACvE,IAAI,EAAE,UAAU,CAAC,OAAO;QACxB,SAAS,EAAE,UAAU,CAAC,OAAO,KAAK,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS;KACrH,CAA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CAAoC,EAC5E,UAAU,IAAI,0CAA0C,CACzD,CAAC;IACF,OAAO,CACL,6BAAK,SAAS,EAAE,gBAAgB;QAC9B,6BAAK,SAAS,EAAC,6DAA6D;YAC1E,oBAAC,KAAK,IAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,wBAAwB,EAAE,SAAS,EAAE,aAAa,EAClG,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAC,OAAO,KAAK,UAAU,GAAI;YAC3E,6BAAK,SAAS,EAAE,UAAU,CAAC,mDAAmD,EAAE,gBAAgB,IAAI,oCAAoC,CAAC;gBAEvI,6BAAK,SAAS,EAAC,kFAAkF,EAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa;oBACpI,oBAAC,WAAW,IAAC,QAAQ,EAAC,eAAe,GAAG,CACpC;gBAEN,6BAAK,SAAS,EAAC,oFAAoF,EAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe;oBACxI,oBAAC,WAAW,IAAC,QAAQ,EAAC,iBAAiB,GAAG,CACtC,CACF,CACF;QACN,8BAAM,SAAS,EAAC,wCAAwC,IAAE,SAAS,CAAQ,CACtE,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA4D,6BAA6B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Inputs\r\n */\r\n\r\nimport \"./QuantityNumberInput.scss\";\r\nimport classnames from \"classnames\";\r\nimport * as React from \"react\";\r\nimport { WebFontIcon } from \"@itwin/core-react\";\r\nimport { SpecialKey } from \"@itwin/appui-abstract\";\r\nimport { IModelApp, QuantityFormatsChangedArgs, QuantityTypeArg } from \"@itwin/core-frontend\";\r\nimport { DecimalPrecision, FormatterSpec, FormatTraits, FormatType, Parser, ParserSpec, UnitConversionSpec, UnitProps } from \"@itwin/core-quantity\";\r\nimport { Input, InputProps } from \"@itwin/itwinui-react\";\r\n\r\n/** Step function prototype for [[QuantityNumberInput]] component\r\n * @beta\r\n */\r\nexport type StepFunctionProp = number | ((direction: string) => number | undefined);\r\n\r\n/** Properties for the [[QuantityNumberInput]] component\r\n * @beta\r\n */\r\nexport interface QuantityNumberInputProps extends Omit<InputProps, \"value\" | \"min\" | \"max\" | \"step\" | \"onFocus\" | \"onChange\"> {\r\n /** Initial magnitude in 'persistence' units. See `getPersistenceUnitByQuantityType` in [QuantityFormatter]($core-frontend).\r\n * Set to `undefined` to show placeholder text */\r\n persistenceValue?: number;\r\n /** CSS class name for the QuantityNumberInput component container div */\r\n containerClassName?: string;\r\n /** number or function\tNumber.MIN_SAFE_INTEGER */\r\n min?: number;\r\n /** number or function\tdefaults to Number.MAX_SAFE_INTEGER */\r\n max?: number;\r\n /** increment step value used while incrementing or decrementing (up/down buttons or arrow keys) defaults to 1. */\r\n step?: StepFunctionProp;\r\n /** Set to true to \"snap\" to the closest step value while incrementing or decrementing (up/down buttons or arrow keys). */\r\n snap?: boolean;\r\n /** Function to call when the quantity value is changed. The value returned will be in 'persistence' units. */\r\n onChange?: (value: number) => void;\r\n /** if true up/down buttons are shown larger and side by side */\r\n showTouchButtons?: boolean;\r\n /** Provides ability to return reference to HTMLInputElement */\r\n ref?: React.Ref<HTMLInputElement>;\r\n /** Type of quantity being input. */\r\n quantityType: QuantityTypeArg;\r\n}\r\n\r\n/** adjust formatter spec to show only primary unit without a label. */\r\nfunction adjustFormatterSpec(formatterSpec: FormatterSpec | undefined) {\r\n if (undefined === formatterSpec)\r\n return formatterSpec;\r\n const singleUnitConversion: UnitConversionSpec[] = [];\r\n singleUnitConversion.push(formatterSpec.unitConversions[0]);\r\n const newFormat = formatterSpec.format.clone({\r\n showOnlyPrimaryUnit: true,\r\n traits: formatterSpec.format.formatTraits & ~FormatTraits.ShowUnitLabel,\r\n type: FormatType.Decimal,\r\n precision: FormatType.Decimal !== formatterSpec.format.type ? DecimalPrecision.Four : formatterSpec.format.precision,\r\n });\r\n return new FormatterSpec(\"single-value\", newFormat, singleUnitConversion, formatterSpec.persistenceUnit);\r\n}\r\n\r\nfunction convertValueFromDisplayToPersistence(value: number, unitConversions: UnitConversionSpec[] | undefined, unit: UnitProps) {\r\n // istanbul ignore next\r\n if (!unitConversions || 0 === unitConversions.length)\r\n return value;\r\n\r\n const unitConversion = unitConversions.find((spec) => spec.name === unit.name);\r\n // istanbul ignore next\r\n if (!unitConversion)\r\n return value;\r\n\r\n const convertedValue = (value * unitConversion.conversion.factor) + unitConversion.conversion.offset;\r\n return convertedValue;\r\n}\r\n\r\nfunction getUnitLabel(parserSpec: ParserSpec | undefined) {\r\n if (undefined === parserSpec)\r\n return \"\";\r\n\r\n const format = parserSpec.format;\r\n // istanbul ignore else\r\n if (!format.units || !format.units[0])\r\n return parserSpec.outUnit.label;\r\n const [unit, label] = format.units[0];\r\n // istanbul ignore next\r\n return label ?? unit.label;\r\n}\r\n\r\nconst ForwardRefQuantityNumberInput = React.forwardRef<HTMLInputElement, QuantityNumberInputProps>(\r\n function ForwardRefQuantityNumberInput(props, ref) {\r\n\r\n const { containerClassName, persistenceValue, min, max,\r\n onChange, onBlur, onKeyDown, step, snap, showTouchButtons, quantityType, ...otherProps } = props;\r\n const rawValueRef = React.useRef(persistenceValue);\r\n\r\n const [formatterSpec, setFormatterSpec] = React.useState(() => adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));\r\n const [parserSpec, setParserSpec] = React.useState(() => IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));\r\n\r\n const formatValue = React.useCallback((value: number | undefined) => {\r\n if (undefined === value)\r\n return \"\";\r\n\r\n // istanbul ignore else\r\n if (formatterSpec) {\r\n return formatterSpec.applyFormatting(value);\r\n }\r\n // istanbul ignore next\r\n return value.toFixed(2);\r\n }, [formatterSpec]);\r\n\r\n const lastFormattedValueRef = React.useRef(formatValue(persistenceValue));\r\n const [formattedValue, setFormattedValue] = React.useState(() => lastFormattedValueRef.current);\r\n\r\n React.useEffect(() => {\r\n const handleUnitSystemChanged = ((): void => {\r\n setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));\r\n setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));\r\n });\r\n\r\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.addListener(handleUnitSystemChanged);\r\n return () => {\r\n IModelApp.quantityFormatter.onActiveFormattingUnitSystemChanged.removeListener(handleUnitSystemChanged);\r\n };\r\n }, [quantityType]);\r\n\r\n React.useEffect(() => {\r\n const handleUnitSystemChanged = ((args: QuantityFormatsChangedArgs): void => {\r\n const quantityKey = IModelApp.quantityFormatter.getQuantityTypeKey(quantityType);\r\n // istanbul ignore else\r\n if (args.quantityType === quantityKey) {\r\n setFormatterSpec(adjustFormatterSpec(IModelApp.quantityFormatter.findFormatterSpecByQuantityType(quantityType)));\r\n setParserSpec(IModelApp.quantityFormatter.findParserSpecByQuantityType(quantityType));\r\n }\r\n });\r\n\r\n IModelApp.quantityFormatter.onQuantityFormatsChanged.addListener(handleUnitSystemChanged);\r\n return () => {\r\n IModelApp.quantityFormatter.onQuantityFormatsChanged.removeListener(handleUnitSystemChanged);\r\n };\r\n }, [quantityType]);\r\n\r\n const unitLabel = getUnitLabel(parserSpec);\r\n\r\n // See if new initialValue props have changed since component mounted\r\n React.useEffect(() => {\r\n rawValueRef.current = persistenceValue;\r\n const currentFormattedValue = formatValue(rawValueRef.current);\r\n setFormattedValue(currentFormattedValue);\r\n }, [formatValue, persistenceValue]);\r\n\r\n // this is the unprocessed input from user, it is not processed until blur or enter key press\r\n const handleDisplayValueChange = React.useCallback((event: React.ChangeEvent<HTMLInputElement>) => {\r\n setFormattedValue(event.currentTarget.value);\r\n }, []);\r\n\r\n const updateValue = React.useCallback((newValue: number) => {\r\n let persistedValue = newValue;\r\n // istanbul ignore else\r\n if (parserSpec) {\r\n // convert value from display unit to persistence unit\r\n const [unit] = parserSpec.format.units ? parserSpec.format.units[0] : /* istanbul ignore next */[parserSpec.outUnit];\r\n persistedValue = convertValueFromDisplayToPersistence(newValue, parserSpec.unitConversions, unit);\r\n rawValueRef.current = persistedValue;\r\n }\r\n const newFormattedVal = formatValue(persistedValue);\r\n onChange && onChange(persistedValue);\r\n setFormattedValue(newFormattedVal);\r\n\r\n }, [formatValue, onChange, parserSpec]);\r\n\r\n /**\r\n * Used internally to parse the argument x to it's numeric representation.\r\n * If the argument cannot be converted to finite number returns 0; If a\r\n * \"precision\" prop is specified uses it round the number with that\r\n * precision (no fixed precision here because the return value is float, not\r\n * string).\r\n */\r\n const parseInternal = React.useCallback((x: string | undefined) => {\r\n if (!x)\r\n return 0;\r\n\r\n let n = parseFloat(x);\r\n // istanbul ignore next\r\n if (isNaN(n) || !isFinite(n)) {\r\n n = 0;\r\n }\r\n\r\n const localPrecision = 6; // TODO get a reasonable value from format\r\n const q = Math.pow(10, localPrecision);\r\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\r\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\r\n n = Math.min(Math.max(n, localMin), localMax);\r\n n = Math.round(n * q) / q;\r\n\r\n return n;\r\n }, [min, max]);\r\n\r\n const updateValueFromString = React.useCallback((strValue: string) => {\r\n // istanbul ignore else\r\n if (parserSpec) {\r\n const parseResult = IModelApp.quantityFormatter.parseToQuantityValue(strValue, parserSpec);\r\n // at this point we should have a string value in persistence units without a label\r\n if (Parser.isParsedQuantity(parseResult)) {\r\n const persistedValue = parseResult.value; // in persistence units\r\n // set strValue and let it go through parseInternal which will ensure min/max limits are observed\r\n strValue = formatValue(persistedValue)!;\r\n } else {\r\n // istanbul ignore else\r\n if (rawValueRef.current) { // restore last known good value\r\n const lastKnownFormattedVal = formatValue(rawValueRef.current);\r\n setFormattedValue(lastKnownFormattedVal);\r\n return;\r\n }\r\n }\r\n }\r\n const newValue = parseInternal(strValue);\r\n // istanbul ignore else\r\n if (undefined !== newValue)\r\n updateValue(newValue);\r\n }, [formatValue, parseInternal, parserSpec, updateValue]);\r\n\r\n const handleBlur = React.useCallback((event: React.FocusEvent<HTMLInputElement>) => {\r\n const newVal = parseInternal(event.target.value);\r\n onBlur && onBlur(event);\r\n updateValue(newVal);\r\n }, [parseInternal, updateValue, onBlur]);\r\n\r\n const getIncrementValue = React.useCallback((increment: boolean) => {\r\n if (typeof step === \"function\") {\r\n const stepVal = step(increment ? \"up\" : \"down\");\r\n return stepVal ? stepVal : 1;\r\n }\r\n\r\n return !step ? 1 : step;\r\n }, [step]);\r\n\r\n /**\r\n * The internal method that actually sets the new value on the input\r\n */\r\n const applyStep = React.useCallback((increment: boolean) => {\r\n const incrementValue = getIncrementValue(increment);\r\n\r\n let num = parseInternal(formattedValue) + (increment ? incrementValue : -incrementValue);\r\n if (snap) {\r\n num = Math.round(num / incrementValue) * incrementValue;\r\n }\r\n\r\n const localMin = undefined === min ? Number.MIN_SAFE_INTEGER : min;\r\n const localMax = undefined === max ? Number.MAX_SAFE_INTEGER : max;\r\n num = Math.min(Math.max(num, localMin), localMax);\r\n\r\n updateValue(num);\r\n }, [formattedValue, getIncrementValue, max, min, parseInternal, snap, updateValue]);\r\n\r\n const handleKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\r\n // istanbul ignore else\r\n if (event.key === SpecialKey.Enter) {\r\n updateValueFromString(event.currentTarget.value);\r\n event.preventDefault();\r\n } else if (event.key === SpecialKey.Escape) {\r\n setFormattedValue(formatValue(rawValueRef.current));\r\n event.preventDefault();\r\n } else if (event.key === SpecialKey.ArrowDown) {\r\n applyStep(false);\r\n event.preventDefault();\r\n } else if (event.key === SpecialKey.ArrowUp) {\r\n applyStep(true);\r\n event.preventDefault();\r\n }\r\n onKeyDown && onKeyDown(event);\r\n }, [onKeyDown, updateValueFromString, formatValue, applyStep]);\r\n\r\n const handleDownClick = React.useCallback((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\r\n applyStep(false);\r\n event.preventDefault();\r\n }, [applyStep]);\r\n\r\n const handleUpClick = React.useCallback((event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {\r\n applyStep(true);\r\n event.preventDefault();\r\n }, [applyStep]);\r\n\r\n // istanbul ignore next\r\n const handleFocus = React.useCallback((event: React.FocusEvent<HTMLInputElement>) => {\r\n event.currentTarget.select();\r\n }, []);\r\n\r\n const isDisabled = !!otherProps.disabled;\r\n const containerClasses = classnames(\"component-quantity-number-input-container\",\r\n containerClassName, showTouchButtons && \"component-number-buttons-for-touch\",\r\n isDisabled && \"component-quantity-number-input-disabled\",\r\n );\r\n return (\r\n <div className={containerClasses} >\r\n <div className=\"component-quantity-number-input-value-and-buttons-container\">\r\n <Input ref={ref} value={formattedValue} onChange={handleDisplayValueChange} onKeyDown={handleKeyDown}\r\n onBlur={handleBlur} onFocus={handleFocus} size=\"small\" {...otherProps} />\r\n <div className={classnames(\"component-quantity-number-input-buttons-container\", showTouchButtons && \"component-number-buttons-for-touch\")}>\r\n { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\r\n <div className=\"component-quantity-number-input-button component-quantity-number-input-button-up\" tabIndex={-1} onClick={handleUpClick}>\r\n <WebFontIcon iconName=\"icon-caret-up\" />\r\n </div>\r\n { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\r\n <div className=\"component-quantity-number-input-button component-quantity-number-input-button-down\" tabIndex={-1} onClick={handleDownClick}>\r\n <WebFontIcon iconName=\"icon-caret-down\" />\r\n </div>\r\n </div>\r\n </div>\r\n <span className=\"component-quantity-number-input-suffix\">{unitLabel}</span>\r\n </div >\r\n );\r\n }\r\n);\r\n\r\n/** The QuantityNumberInput component accepts input for quantity values. The quantity value is shown as a single numeric value and the quantity's\r\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).\r\n * The control also display buttons to increment and decrement the \"displayed\" value. The value reported by via the onChange function is in \"persistence\"\r\n * units that can be stored in the iModel.\r\n * @beta\r\n */\r\nexport const QuantityNumberInput: (props: QuantityNumberInputProps) => JSX.Element | null = ForwardRefQuantityNumberInput;\r\n"]}